From 6a3e9d392a0c3194ad66935afa8814571899351f Mon Sep 17 00:00:00 2001 From: Axel Heider Date: Sun, 6 Feb 2022 21:17:31 +0100 Subject: [PATCH] elfloader/risc-v: unify multicore stacks - declare stack fully in C code - use one array that holds all stack - use CONFIG_KERNEL_STACK_BITS for size Signed-off-by: Axel Heider --- elfloader-tool/src/arch-riscv/boot.c | 3 ++- elfloader-tool/src/arch-riscv/crt0.S | 25 ++++++++++--------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/elfloader-tool/src/arch-riscv/boot.c b/elfloader-tool/src/arch-riscv/boot.c index 7edac2a37..48085b8e8 100644 --- a/elfloader-tool/src/arch-riscv/boot.c +++ b/elfloader-tool/src/arch-riscv/boot.c @@ -57,7 +57,8 @@ unsigned long l2pt[PTES_PER_PT] __attribute__((aligned(4096))); unsigned long l2pt_elf[PTES_PER_PT] __attribute__((aligned(4096))); #endif -char elfloader_stack_alloc[BIT(CONFIG_KERNEL_STACK_BITS)]; +/* Stacks for each core are set up in the assembly startup code. */ +char elfloader_stack[CONFIG_MAX_NUM_NODES * BIT(CONFIG_KERNEL_STACK_BITS)] __attribute__((aligned(4096))); /* first HART will initialise these */ void const *dtb = NULL; diff --git a/elfloader-tool/src/arch-riscv/crt0.S b/elfloader-tool/src/arch-riscv/crt0.S index 69e8808e3..74e39a6e8 100644 --- a/elfloader-tool/src/arch-riscv/crt0.S +++ b/elfloader-tool/src/arch-riscv/crt0.S @@ -9,8 +9,11 @@ .extern main .extern __global_pointer$ -.extern elfloader_stack_alloc +.extern elfloader_stack .extern hsm_exists +#if CONFIG_MAX_NUM_NODES > 1 +.extern next_logical_core_id +#endif #define BIT(n) (1 << (n)) @@ -56,7 +59,7 @@ _start: mv s2, a1 /* preserve a1 (dtb) in s2 */ /* Attach the stack to sp before calling any C functions */ - la sp, (elfloader_stack_alloc + BIT(12)) + la sp, (elfloader_stack + BIT(CONFIG_KERNEL_STACK_BITS)) #ifdef CONFIG_IMAGE_BINARY /* Clear the BSS before we get to do anything more specific */ @@ -117,7 +120,7 @@ _start1: /* a0 must hold current hard ID passed by bootloader */ /* This HART may be a different HART to the one that started at _start * If we've switched HARTs then the other HART will get a different stack * region in secondary_harts. */ - la sp, (elfloader_stack_alloc + BIT(12)) + la sp, (elfloader_stack + BIT(CONFIG_KERNEL_STACK_BITS)) /* The C code expects the registers to be set up as: * a0 = hart id * a1 = dtb @@ -125,15 +128,6 @@ _start1: /* a0 must hold current hard ID passed by bootloader */ la s0, main jr s0 -#if CONFIG_MAX_NUM_NODES > 1 -.extern next_logical_core_id -.data -bootstack_secondary_cores: -.align 12 -.space 4096 * (CONFIG_MAX_NUM_NODES - 1) -#endif - -.text .global secondary_harts secondary_harts: @@ -153,9 +147,10 @@ secondary_harts: amoadd.w a1, t2, (a1) li t2, CONFIG_MAX_NUM_NODES bge a1, t2, hsm_suspend_hart - - slli t0, a1, 12 - la sp, bootstack_secondary_cores + /* setup the hart specific stack pointer */ + la sp, elfloader_stack + addi t0, a1, 1 /* increment by one because we need to set sp to the end */ + slli t0, t0, CONFIG_KERNEL_STACK_BITS /* t0 = t0 * BIT(CONFIG_KERNEL_STACK_BITS) */ add sp, sp, t0 la s0, secondary_entry jr s0