diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-07-08 17:43:59 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-07-08 18:04:03 +0300 |
| commit | e134202611a50b358c147c92bfb8a7f443030b8b (patch) | |
| tree | ac7c31824adcf41a63e4d2c5e141f5149cc55b1a /arch/riscv64/kernel/start.S | |
| parent | 7e828ec1e1479ff9a8afe845539d08ca0dfada5f (diff) | |
| download | kmi-e134202611a50b358c147c92bfb8a7f443030b8b.tar.gz kmi-e134202611a50b358c147c92bfb8a7f443030b8b.zip | |
fix LLVM
+ Anything extern is right out as LLVM doesn't produce correct code for
them. Maybe if I added some extra attributes but I'm skeptical.
Replaced with static variables and getters/setters.
+ Inline ASM is apparently a bit buggy, so use an assembly stub when jumping to init.
+ Minimize work done in main() to minimize chance of LLVM doing something silly.
Still not 100% certain that I shouldn't just write the main() as an assembly stub
in arch/riscv64 to be absolutely sure everything works as intended.
+ Make .kernel.start section SHF_ALLOC, otherwise lld complains about
pc-relative addressing
Probably some other stuff as well that I'm forgetting right now. But at least with
LLVM14 LTO seems to work, which is pretty cool?
Diffstat (limited to 'arch/riscv64/kernel/start.S')
| -rw-r--r-- | arch/riscv64/kernel/start.S | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/arch/riscv64/kernel/start.S b/arch/riscv64/kernel/start.S index 5a2ed61..3f2b3cb 100644 --- a/arch/riscv64/kernel/start.S +++ b/arch/riscv64/kernel/start.S @@ -1,10 +1,12 @@ +#include "asm.h" + #if GENERIC_UBOOT # define MAIN main_go #else # define MAIN main #endif -.section .kernel.start +.section ".kernel.start", "ax" .global _start _start: /* get load address */ @@ -15,6 +17,12 @@ lla sp, riscv_init_stack li t0, 4096 add sp, sp, t0 +lla t0, __kernel_start +lla t1, __kernel_end +lla t2, kernel_size +sub t0, t1, t0 +sr t0, 0(t2) + /* set thread pointer to zero so we don't accidentally try to use a tcb */ li tp, 0 @@ -32,3 +40,8 @@ add sp, sp, t1 lui t0, %hi(kernel) addi t0, t0, %lo(kernel) jr t0 + +.global riscv_run_init +riscv_run_init: +mv sp, a6 +sret |
