Skip to content

Commit 9c574ed

Browse files
lstnlkartben
authored andcommitted
arch: riscv: option to init custom hw stacked esf members.
When RISCV_SOC_HAS_ISR_STACKING is used, it may be needed to initialize custom hw stacked esf members. Some initial values may need to be aligned with hw stacking mechanism to avoid any side effects. Signed-off-by: Łukasz Stępnicki <[email protected]>
1 parent 8133f47 commit 9c574ed

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

arch/riscv/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ config RISCV_SOC_HAS_ISR_STACKING
124124
saved on the stack by the hardware, and the registers saved by the
125125
software macros. The structure must be called 'struct arch_esf'.
126126

127+
- SOC_ISR_STACKING_ESR_INIT: macro guarded by !_ASMLANGUAGE.
128+
Some hardware stacked registers should be initialized on init
129+
stack with proper values. This prevents from incorrect behavior
130+
on entry context switch when initial stack is restored.
131+
127132
config RISCV_SOC_HAS_CUSTOM_IRQ_HANDLING
128133
bool
129134
help

arch/riscv/core/thread.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
106106
stack_init->soc_context = soc_esf_init;
107107
#endif
108108

109+
#ifdef CONFIG_RISCV_SOC_HAS_ISR_STACKING
110+
SOC_ISR_STACKING_ESR_INIT;
111+
#endif
112+
109113
thread->callee_saved.sp = (unsigned long)stack_init;
110114

111115
/* where to go when returning from z_riscv_switch() */

soc/nordic/common/vpr/soc_isr_stacking.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@
6060

6161
#endif /* DT_PROP(VPR_CPU, nordic_bus_width) == 64 */
6262

63+
/*
64+
* VPR stacked mcause needs to have proper value on initial stack.
65+
* Initial mret will restore this value.
66+
*/
67+
#define SOC_ISR_STACKING_ESR_INIT \
68+
stack_init->_mcause = 0;
69+
6370
#else /* _ASMLANGUAGE */
6471

6572
/*

0 commit comments

Comments
 (0)