diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-07-05 19:38:11 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-07-05 19:38:11 +0300 |
| commit | e09edb5d54e39bd9509a1dc450df5ab320759f97 (patch) | |
| tree | 78e050b0db87df3a3ddfbb6570d44513ac34e02a /arch/riscv64/kernel/start.S | |
| parent | 98f21e694a6b0964d6d08196cb6bfbc1c2ae2ff4 (diff) | |
| download | kmi-e09edb5d54e39bd9509a1dc450df5ab320759f97.tar.gz kmi-e09edb5d54e39bd9509a1dc450df5ab320759f97.zip | |
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.
Diffstat (limited to 'arch/riscv64/kernel/start.S')
| -rw-r--r-- | arch/riscv64/kernel/start.S | 36 |
1 files changed, 36 insertions, 0 deletions
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 |
