Initial Commit
This commit is contained in:
commit
4d9c67831b
18
Makefile
Normal file
18
Makefile
Normal file
@ -0,0 +1,18 @@
|
||||
CC := $(PREFIX)gcc
|
||||
AS := $(PREFIX)as
|
||||
OBJCPY := $(PREFIX)objcopy
|
||||
|
||||
boot.o: boot.S
|
||||
$(AS) -c boot.S -o boot.o
|
||||
|
||||
kernel.o: kernel.c
|
||||
$(CC) -ffreestanding -c kernel.c -o kernel.o -O2 -Wall -Wextra
|
||||
|
||||
os.elf: boot.o kernel.o linker.ld
|
||||
$(CC) -T linker.ld -o os.elf -ffreestanding -O2 -nostdlib boot.o kernel.o -lgcc
|
||||
|
||||
kernel8.img: os.elf
|
||||
$(OBJCPY) os.elf -O binary kernel8.img
|
||||
|
||||
clean:
|
||||
rm boot.o kernel.o os.elf kernel8.img
|
34
boot.S
Normal file
34
boot.S
Normal file
@ -0,0 +1,34 @@
|
||||
// AArch64 mode
|
||||
|
||||
// To keep this in the first portion of the binary.
|
||||
.section ".text.boot"
|
||||
|
||||
// Make _start global.
|
||||
.globl _start
|
||||
|
||||
.org 0x80000
|
||||
// Entry point for the kernel. Registers:
|
||||
// x0 -> 32 bit pointer to DTB in memory (primary core only) / 0 (secondary cores)
|
||||
// x1 -> 0
|
||||
// x2 -> 0
|
||||
// x3 -> 0
|
||||
// x4 -> 32 bit kernel entry point, _start location
|
||||
_start:
|
||||
// set stack before our code
|
||||
ldr x5, =_start
|
||||
mov sp, x5
|
||||
|
||||
// clear bss
|
||||
ldr x5, =__bss_start
|
||||
ldr w6, =__bss_size
|
||||
1: cbz w6, 2f
|
||||
str xzr, [x5], #8
|
||||
sub w6, w6, #1
|
||||
cbnz w6, 1b
|
||||
|
||||
// jump to C code, should not return
|
||||
2: bl kernel_main
|
||||
// for failsafe, halt this core
|
||||
halt:
|
||||
wfe
|
||||
b halt
|
26
kernel.c
Normal file
26
kernel.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
volatile uint32_t** core_1 = (void*)0xE0;
|
||||
volatile uint32_t** core_2 = (void*)0xE0;
|
||||
volatile uint32_t** core_3 = (void*)0xE0;
|
||||
|
||||
|
||||
void _start_core_1(void* addr) {
|
||||
*core_1 = (uint32_t*)addr;
|
||||
}
|
||||
|
||||
|
||||
void _start_core_2(void* addr) {
|
||||
*core_2 = (uint32_t*)addr;
|
||||
}
|
||||
|
||||
|
||||
void _start_core_3(void* addr) {
|
||||
*core_3 = (uint32_t*)addr;
|
||||
}
|
||||
|
||||
|
||||
void kernel_main(uint64_t dtb_ptr32, uint64_t x1, uint64_t x2, uint64_t x3) {
|
||||
return;
|
||||
}
|
44
linker.ld
Normal file
44
linker.ld
Normal file
@ -0,0 +1,44 @@
|
||||
ENTRY(_start)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
/* Starts at LOADER_ADDR. */
|
||||
. = 0x80000;
|
||||
/* For AArch64, use . = 0x80000; */
|
||||
__start = .;
|
||||
__text_start = .;
|
||||
.text :
|
||||
{
|
||||
KEEP(*(.text.boot))
|
||||
*(.text)
|
||||
}
|
||||
. = ALIGN(4096); /* align to page size */
|
||||
__text_end = .;
|
||||
|
||||
__rodata_start = .;
|
||||
.rodata :
|
||||
{
|
||||
*(.rodata)
|
||||
}
|
||||
. = ALIGN(4096); /* align to page size */
|
||||
__rodata_end = .;
|
||||
|
||||
__data_start = .;
|
||||
.data :
|
||||
{
|
||||
*(.data)
|
||||
}
|
||||
. = ALIGN(4096); /* align to page size */
|
||||
__data_end = .;
|
||||
|
||||
__bss_start = .;
|
||||
.bss :
|
||||
{
|
||||
bss = .;
|
||||
*(.bss)
|
||||
}
|
||||
. = ALIGN(4096); /* align to page size */
|
||||
__bss_end = .;
|
||||
__bss_size = __bss_end - __bss_start;
|
||||
__end = .;
|
||||
}
|
Loading…
Reference in New Issue
Block a user