Skip to content

Commit f499ed0

Browse files
committed
[nrf fromlist] 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. Upstream PR #: 84076 Signed-off-by: Łukasz Stępnicki <[email protected]>
1 parent 52a1cee commit f499ed0

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
@@ -83,6 +83,11 @@ config RISCV_SOC_HAS_ISR_STACKING
8383
saved on the stack by the hardware, and the registers saved by the
8484
software macros. The structure must be called 'struct arch_esf'.
8585

86+
- SOC_ISR_STACKING_ESR_INIT: macro guarded by !_ASMLANGUAGE.
87+
Some hardware stacked registers should be initialized on init
88+
stack with proper values. This prevents from incorrect behavior
89+
on entry context switch when initial stack is restored.
90+
8691
config RISCV_SOC_HAS_CUSTOM_IRQ_HANDLING
8792
bool
8893
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
@@ -62,6 +62,13 @@
6262

6363
#endif /* DT_PROP(VPR_CPU, nordic_bus_width) == 64 */
6464

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

6774
/*

0 commit comments

Comments
 (0)