From e09edb5d54e39bd9509a1dc450df5ab320759f97 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Fri, 5 Jul 2024 19:38:11 +0300 Subject: allow booting with Qemu's -kernel flag directly + Took some fairly significant changes, for one the kernel is no longer relocated at the start of a boot, instead it sits wherever the user decides the kernel should sit. Similarly, the initial kernel stack and page table are stored within the binary, slightly bloating the size but making it much safer to boot since there's really no chance of us overwriting the fdt or initrd in memory. --- arch/riscv64/kernel/start.S | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 arch/riscv64/kernel/start.S (limited to 'arch/riscv64/kernel/start.S') diff --git a/arch/riscv64/kernel/start.S b/arch/riscv64/kernel/start.S new file mode 100644 index 0000000..4978cc0 --- /dev/null +++ b/arch/riscv64/kernel/start.S @@ -0,0 +1,36 @@ +#if GENERIC_UBOOT +# define MAIN main_go +#else +# define LOAD_REG a1 +# define MAIN main +#endif + +.section .kernel.start +.global _start +_start: +/* get load address */ +auipc a2, 0 + +/* load initial stack */ +lla sp, riscv_init_stack +li t0, 4096 +add sp, sp, t0 + +/* set thread pointer to zero so we don't accidentally try to use a tcb */ +li tp, 0 + +/* call main, whichever one is relevant */ +call MAIN +ret + +.section .text + +/* a0 is fdt, a1 is load_addr, a2 is d, a3 is ram_base, a4 is DMAP */ +.global to_kernelspace +to_kernelspace: +lla t0, kernel +add t0, t0, a4 +sub t0, t0, a3 +add sp, sp, a4 +sub sp, sp, a3 +jr t0 -- cgit v1.3