From af1ce4b2e637ceb418ea72d51c49a3eee276a938 Mon Sep 17 00:00:00 2001 From: stefan Date: Sat, 15 Apr 2023 05:02:02 +0000 Subject: added multiprocessor support --- sys/kern/entry.S | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'sys/kern/entry.S') diff --git a/sys/kern/entry.S b/sys/kern/entry.S index 03ff76c..9bf72ea 100644 --- a/sys/kern/entry.S +++ b/sys/kern/entry.S @@ -1,8 +1,14 @@ .section ".text.init" +// entrypoint for boot hart(s). a0: hartid, a1: *fdt .globl _start -_start: - /* disable interrupts and poging */ + + +// entrypoint for other harts. a0: hartid, a1: unused for now +.global _mpentry + +_start: + /* disable interrupts and paging */ csrw satp, zero csrw sie, zero csrw sip, zero @@ -12,7 +18,9 @@ _start: la gp, __global_pointer$ .option pop - /* setup stack */ + /* setup stack. + * stack grows toward lower address so sp will mark end of frame. + */ addi t0, a0, 1 li t1, PAGE_SIZE la sp, __stack_start @@ -22,11 +30,11 @@ _start: /* setup thread pointer */ mv tp, a0 - /* the label _boot_hart is shared between threads. only one hart will branch before it is no longer 0 */ + /* the label _boot_hart is shared between threads. after the first atomic swap, all other harts will branch to mpentry */ li a2, 1 lla a3, _boot_hart amoswap.w a3, a2, (a3) - bnez a3, 2f + bnez a3, _mpentry /* clear the bss section */ la a2, __bss_start @@ -39,9 +47,16 @@ _start: call init j _spin +_mpentry: + /* satp = 0, sstatus.sie = 0, a0 = hartid, a1 = opaque */ + + call mpinit + /* shouldn't reach this point */ + j _spin + _spin: wfi - j _spin + j _spin .section ".data" _boot_hart: @@ -51,3 +66,4 @@ _boot_hart: /* linker imports */ .globl HEAP_START HEAP_START: .dword __heap_start + -- cgit v1.2.3