Skip to content

Commit b1cf5f9

Browse files
lstnl57300
authored andcommitted
[nrf fromtree] soc: nordic: vpr: fix soc isr sw stacking.
Fixed order of mepc and _mcause in esf for 32bit stacking. Added missing stack pointer alignement bit support.' Signed-off-by: Lukasz Stepnicki <[email protected]> (cherry picked from commit 37e3449)
1 parent 5119abc commit b1cf5f9

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

soc/riscv/nordic_nrf/common/vpr/soc_context.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@
66
#ifndef SOC_RISCV_NORDIC_NRF_COMMON_VPR_SOC_CONTEXT_H_
77
#define SOC_RISCV_NORDIC_NRF_COMMON_VPR_SOC_CONTEXT_H_
88

9-
#define SOC_ESF_MEMBERS unsigned long minttresh
10-
#define SOC_ESF_INIT 0
9+
#define SOC_ESF_MEMBERS \
10+
unsigned long minttresh; \
11+
unsigned long sp_align; \
12+
unsigned long padding0; \
13+
unsigned long padding1; \
14+
unsigned long padding2
15+
16+
#define SOC_ESF_INIT \
17+
0, \
18+
0, \
19+
0, \
20+
0
1121

1222
#endif /* SOC_RISCV_NORDIC_NRF_COMMON_VPR_SOC_CONTEXT_H_ */

soc/riscv/nordic_nrf/common/vpr/soc_isr_stacking.h

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
unsigned long a2; \
5757
unsigned long a1; \
5858
unsigned long a0; \
59-
unsigned long mepc; \
6059
unsigned long _mcause; \
60+
unsigned long mepc; \
6161
} __aligned(16);
6262

6363
#endif /* DT_PROP(VPR_CPU, nordic_bus_width) == 64 */
@@ -79,7 +79,28 @@
7979
* Size of the SW managed part of the ESF in case of interrupt
8080
* sizeof(__padding) + ... + sizeof(soc_context)
8181
*/
82-
#define ESF_SW_IRQ_SIZEOF (0x10)
82+
#define ESF_SW_IRQ_SIZEOF (0x20)
83+
84+
/*
85+
* VPR needs aligned(8) SP when doing HW stacking, if this condition is not fulfilled it will move
86+
* SP by additional 4 bytes when HW stacking is done. This will be indicated by LSB bit in stacked
87+
* MEPC. This bit needs to be saved and then restored because zephyr is managing MEPC and doesn't
88+
* know anything about this additional offset.
89+
*/
90+
#define MEPC_SP_ALIGN_BIT_MASK (0x1UL)
91+
92+
#define STORE_SP_ALIGN_BIT_FROM_MEPC \
93+
addi t1, sp, __z_arch_esf_t_soc_context_OFFSET; \
94+
lr t0, __z_arch_esf_t_mepc_OFFSET(sp); \
95+
andi t0, t0, MEPC_SP_ALIGN_BIT_MASK; \
96+
sr t0, __soc_esf_t_sp_align_OFFSET(t1)
97+
98+
#define RESTORE_SP_ALIGN_BIT_TO_MEPC \
99+
addi t1, sp, __z_arch_esf_t_soc_context_OFFSET; \
100+
lr t0, __soc_esf_t_sp_align_OFFSET(t1); \
101+
lr t1, __z_arch_esf_t_mepc_OFFSET(sp); \
102+
or t2, t1, t0; \
103+
sr t2, __z_arch_esf_t_mepc_OFFSET(sp)
83104

84105
#define SOC_ISR_SW_STACKING \
85106
csrw mscratch, t0; \
@@ -97,9 +118,11 @@
97118
stacking_is_interrupt: \
98119
addi sp, sp, -ESF_SW_IRQ_SIZEOF; \
99120
\
100-
stacking_keep_going:
121+
stacking_keep_going: \
122+
STORE_SP_ALIGN_BIT_FROM_MEPC
101123

102124
#define SOC_ISR_SW_UNSTACKING \
125+
RESTORE_SP_ALIGN_BIT_TO_MEPC; \
103126
csrr t0, mcause; \
104127
srli t0, t0, RISCV_MCAUSE_IRQ_POS; \
105128
bnez t0, unstacking_is_interrupt; \

soc/riscv/nordic_nrf/common/vpr/soc_offsets.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#ifndef SOC_RISCV_NORDIC_NRF_COMMON_VPR_SOC_OFFSETS_H_
77
#define SOC_RISCV_NORDIC_NRF_COMMON_VPR_SOC_OFFSETS_H_
88

9-
#define GEN_SOC_OFFSET_SYMS() GEN_OFFSET_SYM(soc_esf_t, minttresh)
9+
#define GEN_SOC_OFFSET_SYMS() \
10+
GEN_OFFSET_SYM(soc_esf_t, minttresh); \
11+
GEN_OFFSET_SYM(soc_esf_t, sp_align)
1012

1113
#endif /* SOC_RISCV_NORDIC_NRF_COMMON_VPR_SOC_OFFSETS_H_ */

0 commit comments

Comments
 (0)