From e134202611a50b358c147c92bfb8a7f443030b8b Mon Sep 17 00:00:00 2001 From: Kimplul Date: Mon, 8 Jul 2024 17:43:59 +0300 Subject: 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? --- arch/riscv64/kernel/start.S | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'arch/riscv64/kernel/start.S') 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 -- cgit v1.3