Skip to content

Commit

Permalink
[nrf fromlist] arch: riscv: option to init custom hw stacked esf memb…
Browse files Browse the repository at this point in the history
…ers.

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]>
  • Loading branch information
lstnl committed Jan 16, 2025
1 parent 868f0e1 commit 5f9ec20
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions arch/riscv/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ config RISCV_SOC_HAS_ISR_STACKING
saved on the stack by the hardware, and the registers saved by the
software macros. The structure must be called 'struct arch_esf'.

- SOC_ISR_STACKING_ESR_INIT: macro guarded by !_ASMLANGUAGE.
Some hardware stacked registers should be initialized on init
stack with proper values. This prevents from incorrect behavior
on entry context switch when initial stack is restored.

config RISCV_SOC_HAS_CUSTOM_IRQ_HANDLING
bool
help
Expand Down
4 changes: 4 additions & 0 deletions arch/riscv/core/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
stack_init->soc_context = soc_esf_init;
#endif

#ifdef CONFIG_RISCV_SOC_HAS_ISR_STACKING
SOC_ISR_STACKING_ESR_INIT;
#endif

thread->callee_saved.sp = (unsigned long)stack_init;

/* where to go when returning from z_riscv_switch() */
Expand Down
7 changes: 7 additions & 0 deletions soc/nordic/common/vpr/soc_isr_stacking.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@

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

/*
* VPR stacked mcause needs to have proper value on initial stack.
* Initial mret will restore this value.
*/
#define SOC_ISR_STACKING_ESR_INIT \
stack_init->_mcause = 0;

Check notice on line 71 in soc/nordic/common/vpr/soc_isr_stacking.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

soc/nordic/common/vpr/soc_isr_stacking.h:71 -#define SOC_ISR_STACKING_ESR_INIT \ - stack_init->_mcause = 0; +#define SOC_ISR_STACKING_ESR_INIT stack_init->_mcause = 0;
#else /* _ASMLANGUAGE */

/*
Expand Down

0 comments on commit 5f9ec20

Please sign in to comment.