initial commit

This commit is contained in:
2025-03-11 05:17:34 +08:00
parent d1f60e7c82
commit 9238177ad6
27 changed files with 924 additions and 0 deletions

56
bootloader/Start.S Normal file
View File

@@ -0,0 +1,56 @@
.section ".text.boot"
.global _start
_start:
mrs x1, mpidr_el1
and x1, x1, #3
cbz x1, run
wait:
wfe
b wait
run:
mov x20, x0
adr x0, _start
mov sp, x0
adr x0, __text_start
ldr x1, =__new_text_start
cmp x0, x1
b.gt relocate
adr x0, __bss_start
adr x1, __bss_end
bl memzero
mov x0, x20
bl main
b wait
relocate:
// move text section
ldr x0, =__new_text_start
adr x1, __text_start
adr x2, __text_end
sub x2, x2, x1
bl memcpy
mov x19, x0
// move rodata section
ldr x0, =__new_ro_start
adr x1, __rodata_start
adr x2, __rodata_end
sub x2, x2, x1
bl memcpy
// move data section
ldr x0, =__new_data_start
adr x1, __data_start
adr x2, __data_end
sub x2, x2, x1
bl memcpy
br x19
b wait

50
bootloader/linker.ld Normal file
View File

@@ -0,0 +1,50 @@
ENTRY(_start)
MEMORY
{
NEWTEXT (rx) : ORIGIN = 0x10000, LENGTH = 128K
NEWRO (r) : ORIGIN = 0x30000, LENGTH = 128K
NEWDATA (rw) : ORIGIN = 0x50000, LENGTH = 64K
NEWBSS (rw) : ORIGIN = 0x60000, LENGTH = 64K
TEXT (rx) : ORIGIN = 0x80000, LENGTH = 128K
RO (r) : ORIGIN = 0xa0000, LENGTH = 128K
DATA (rw) : ORIGIN = 0xc0000, LENGTH = 64K
BSS (rw) : ORIGIN = 0xd0000, LENGTH = 64K
RAM (rw) : ORIGIN = 0xf0000, LENGTH = 8M
}
SECTIONS
{
.text : {
__text_start = .;
KEEP(*(.text.boot))
*(.text)
__text_end = .;
} >TEXT
.rodata : {
__rodata_start = .;
*(.rodata)
__rodata_end = .;
} >RO
.data : {
__data_start = .;
*(.data)
__data_end = .;
} >DATA
.bss : {
__bss_start = .;
*(.bss)
__bss_end = .;
} >BSS
__stack_end = ORIGIN(RAM) + LENGTH(RAM);
__new_text_start = ORIGIN(NEWTEXT);
__new_ro_start = ORIGIN(NEWRO);
__new_data_start = ORIGIN(NEWDATA);
__new_bss_start = ORIGIN(NEWBSS);
}
__kernel = 0x80000;
__heap_start = ORIGIN(RAM);
__heap_end = ORIGIN(RAM) + LENGTH(RAM) - 2M;
__bss_size = (__bss_end - __bss_start)>>3;

21
bootloader/main.c Normal file
View File

@@ -0,0 +1,21 @@
#include <stddef.h>
#include <shell.h>
#include <uart.h>
extern byte_t __kernel[];
byte_t *kernel = __kernel;
void main()
{
uart_init();
uart_getc();
uart_puts("loaded addr: ");
uart_hex((unsigned int)(unsigned long)main);
uart_puts(ENDL);
int shell_cont = 1;
while (shell_cont) {
shell_cont = shell();
}
}