Skip to content

Commit

Permalink
elfloader/risc-v: improve comments
Browse files Browse the repository at this point in the history
Signed-off-by: Axel Heider <[email protected]>
  • Loading branch information
axel-h committed Feb 15, 2024
1 parent 740bc9b commit 003dd16
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
19 changes: 11 additions & 8 deletions elfloader-tool/src/arch-riscv/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ uint64_t vm_mode = 0x9llu << 60;
#error "Wrong PT level"
#endif

int hsm_exists = 0;
int hsm_exists = 0; /* assembly startup code will initialise this */

#if CONFIG_MAX_NUM_NODES > 1

extern void secondary_harts(word_t hart_id, word_t core_id);

int secondary_go = 0;
int next_logical_core_id = 1;
int next_logical_core_id = 1; /* incremented by assembly code */
int mutex = 0;
int core_ready[CONFIG_MAX_NUM_NODES] = { 0 };
static void set_and_wait_for_ready(word_t hart_id, word_t core_id)
Expand All @@ -162,12 +162,15 @@ static void set_and_wait_for_ready(word_t hart_id, word_t core_id)
core_ready[core_id] = 1;
__atomic_store_n(&mutex, 0, __ATOMIC_RELEASE);

/* Wait untill all cores are go */
/* Wait until all cores are go */
for (int i = 0; i < CONFIG_MAX_NUM_NODES; i++) {
while (__atomic_load_n(&core_ready[i], __ATOMIC_RELAXED) == 0) ;
while (__atomic_load_n(&core_ready[i], __ATOMIC_RELAXED) == 0) {
/* busy waiting loop */
}
}
}
#endif

#endif /* CONFIG_MAX_NUM_NODES > 1 */

static inline void sfence_vma(void)
{
Expand Down Expand Up @@ -234,7 +237,7 @@ static int run_elfloader(UNUSED word_t hart_id, void *bootloader_dtb)
}

set_and_wait_for_ready(hart_id, 0);
#endif
#endif /* CONFIG_MAX_NUM_NODES > 1 */

printf("Enabling MMU and paging\n");
enable_virtual_memory();
Expand All @@ -250,7 +253,7 @@ static int run_elfloader(UNUSED word_t hart_id, void *bootloader_dtb)
,
hart_id,
0
#endif
#endif /* CONFIG_MAX_NUM_NODES > 1 */
);

/* We should never get here. */
Expand Down Expand Up @@ -287,7 +290,7 @@ void secondary_entry(word_t hart_id, word_t core_id)
);
}

#endif
#endif /* CONFIG_MAX_NUM_NODES > 1 */

void main(word_t hart_id, void *bootloader_dtb)
{
Expand Down
26 changes: 13 additions & 13 deletions elfloader-tool/src/arch-riscv/crt0.S
Original file line number Diff line number Diff line change
Expand Up @@ -107,28 +107,28 @@ hsm_switch_hart:
mv a0, s0 /* restore a0 to hold hart ID passed by OpenSBI */
j secondary_harts


_start1: /* a0 must hold current hard ID passed by bootloader */
/* a1 must hold dtb address passed by bootloader */
/*----------------------------------------------------------------------------*/
_start1:
/* This is basically an asm wrapper to jump to the C code at main(). The
* registers are already set up with the perameters for the C code:
* a0 holds current hard ID passed by bootloader
* a1 holds dtb address passed by bootloader
* All that is left to be done here is setting up the registers gp and sp to
* have a proper C environment. The hart we are running on now could be a
* different HART to the one that we have been on in _start. The original hart
* we came from will get a different stack in secondary_harts.
*/
.option push
.option norelax
1:auipc gp, %pcrel_hi(__global_pointer$)
addi gp, gp, %pcrel_lo(1b)
.option pop

/* Attach the stack to sp before calling any C functions */
/* 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 + BIT(CONFIG_KERNEL_STACK_BITS))
/* The C code expects the registers to be set up as:
* a0 = hart id
* a1 = dtb
*/
/* Jump via a register, as this can cover a bigger range. */
la s0, main
jr s0


/*----------------------------------------------------------------------------*/
.global secondary_harts
secondary_harts:

Expand Down

0 comments on commit 003dd16

Please sign in to comment.