riscv: decouple the Zephyr CPU number from the hart ID
Currently it is assumed that Zephyr CPU numbers match their hartid value one for one. This assumption was relied upon to efficiently retrieve the current CPU's `struct _cpu` pointer. People are starting to have systems with a mix of different usage for each CPU and such assumption may no longer be true. Let's completely decouple the hartid from the Zephyr CPU number by stuffing each CPU's `struct _cpu` pointer in their respective scratch register instead. `arch_curr_cpu()` becomes more efficient as well. Since the scratch register was previously used to store userspace's exception stack pointer, that is now moved into `struct _cpu_arch` which implied minor user space entry code cleanup and rationalization. Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
parent
96a65e2fc0
commit
26d7bd47a0
9 changed files with 106 additions and 75 deletions
|
@ -80,9 +80,6 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
|
|||
/* Clear user thread context */
|
||||
z_riscv_pmp_usermode_init(thread);
|
||||
thread->arch.priv_stack_start = 0;
|
||||
|
||||
/* the unwound stack pointer upon exiting exception */
|
||||
stack_init->sp = (unsigned long)(stack_init + 1);
|
||||
#endif /* CONFIG_USERSPACE */
|
||||
|
||||
/* Assign thread entry point and mstatus.MPRV mode. */
|
||||
|
@ -242,8 +239,8 @@ FUNC_NORETURN void arch_user_mode_enter(k_thread_entry_t user_entry,
|
|||
z_riscv_pmp_usermode_prepare(_current);
|
||||
z_riscv_pmp_usermode_enable(_current);
|
||||
|
||||
/* exception stack has to be in mscratch */
|
||||
csr_write(mscratch, top_of_priv_stack);
|
||||
/* preserve stack pointer for next exception entry */
|
||||
arch_curr_cpu()->arch.user_exc_sp = top_of_priv_stack;
|
||||
|
||||
is_user_mode = true;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue