Skip to content

Commit

Permalink
elfloader/risc-v: unify multicore stacks
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
axel-h committed Feb 7, 2022
1 parent ae6a587 commit 6a3e9d3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
3 changes: 2 additions & 1 deletion elfloader-tool/src/arch-riscv/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 10 additions & 15 deletions elfloader-tool/src/arch-riscv/crt0.S
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -117,23 +120,14 @@ _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
*/
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:
Expand All @@ -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
Expand Down

0 comments on commit 6a3e9d3

Please sign in to comment.