From 122374c362ba8bb9082385da3c82e264ab594f15 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sun, 7 Jul 2024 07:00:43 +0300 Subject: smp now seems to work + Had some minor issues with a wraparound of size_t that effectively meant that some regions were allocated twice. Also, booting should be a bit more reliable now, turned out that the previous iteration of the booting was just accidentally working due to the kernel being placed 'close enough' in RAM to where it was linked to. Fixed by allocating a vmem of O1 that maps the kernel to a 2MiB boundary at boot, pretty nifty. --- arch/riscv64/kernel/proc.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'arch/riscv64/kernel/proc.c') diff --git a/arch/riscv64/kernel/proc.c b/arch/riscv64/kernel/proc.c index a4746b4..af4b2f3 100644 --- a/arch/riscv64/kernel/proc.c +++ b/arch/riscv64/kernel/proc.c @@ -18,9 +18,8 @@ void run_init(struct tcb *t, vm_t fdt, vm_t initrd) { - /** \todo actually map fdt and initrd into the target address space */ csr_write(CSR_SSCRATCH, t); - csr_write(CSR_SEPC, t->exec); + csr_write(CSR_SEPC, t->callback); /* gcc gives a warning 'the value of the stack pointer after an asm * statement must be the same as it was before the statement', so this * is technically speaking undefined behavior, I think. @@ -31,13 +30,16 @@ void run_init(struct tcb *t, vm_t fdt, vm_t initrd) vm_t stack_top = t->thread_stack + t->thread_stack_size; bkl_unlock(); __asm__ volatile ("mv sp, %0\n" - "mv a0, %1\n" - "mv a1, %2\n" + "li a0, %1\n" + "li a1, %2\n" "mv a2, %3\n" + "mv a3, %4\n" + "mv a4, %5\n" "sret\n" : - : "r" (stack_top), "r" (t->tid), "r" (fdt), - "r" (initrd) + : "r" (stack_top), + "K"(0), "K"(SYS_USER_BOOTED), + "r" (t->tid), "r" (fdt), "r" (initrd) : "memory"); /* we should never reach this */ unreachable(); -- cgit v1.3