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/arch.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'arch/riscv64/kernel/arch.c') diff --git a/arch/riscv64/kernel/arch.c b/arch/riscv64/kernel/arch.c index 4561d8b..5dc50cf 100644 --- a/arch/riscv64/kernel/arch.c +++ b/arch/riscv64/kernel/arch.c @@ -13,7 +13,18 @@ #include "csr.h" #include "arch.h" -id_t __cpuid_to_hartid[MAX_CPUS]; +/** Array where indexing is done with CPU IDs, giving the corresponding hart ID. */ +static id_t __cpuid_to_hartid[MAX_CPUS]; + +id_t cpuid_to_hartid(id_t cpu) +{ + return __cpuid_to_hartid[cpu]; +} + +void set_hartid(id_t cpu, id_t hartid) +{ + __cpuid_to_hartid[cpu] = hartid; +} id_t hartid_to_cpuid(id_t hart) { -- cgit v1.3