arch: riscv: thread: Init soc context on stack
The optional SOC_CONTEXT carries processor state registers that need to be initialized properly to avoid uninitialized memory read as processor state. In particular on the RV32M1 the extra soc context stores a state for special loop instructions, and loading non zero values will have the core assume it is in a loop. Signed-off-by: Karsten Koenig <karsten.koenig.030@gmail.com>
This commit is contained in:
parent
dc725b7451
commit
2e61137cc9
2 changed files with 14 additions and 6 deletions
|
@ -21,6 +21,10 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
|
|||
|
||||
struct __esf *stack_init;
|
||||
|
||||
#ifdef CONFIG_RISCV_SOC_CONTEXT_SAVE
|
||||
const struct soc_esf soc_esf_init = {SOC_ESF_INIT};
|
||||
#endif
|
||||
|
||||
z_new_thread_init(thread, stack_memory, stack_size);
|
||||
|
||||
/* Initial stack frame for thread */
|
||||
|
@ -65,6 +69,10 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
|
|||
#endif
|
||||
stack_init->mepc = (ulong_t)z_thread_entry_wrapper;
|
||||
|
||||
#ifdef CONFIG_RISCV_SOC_CONTEXT_SAVE
|
||||
stack_init->soc_context = soc_esf_init;
|
||||
#endif
|
||||
|
||||
thread->callee_saved.sp = (ulong_t)stack_init;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue