Skip to content

Commit fb271d2

Browse files
committed
Merge branch 'fix/ulp_riscv_interrupt_bug_v5.4' into 'release/v5.4'
fix(ulp): fix ULP RISC-V interrupt handler corrupting the stack (backport v5.4) See merge request espressif/esp-idf!35225
2 parents e767502 + ab4fa65 commit fb271d2

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

components/ulp/ulp_riscv/ulp_core/ulp_riscv_vectors.S

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "sdkconfig.h"
88
#include "ulp_riscv_interrupt_ops.h"
9-
#include "riscv/rvruntime-frames.h"
9+
1010
.equ SAVE_REGS, 17
1111
.equ CONTEXT_SIZE, (SAVE_REGS * 4)
1212

@@ -19,46 +19,46 @@
1919
*/
2020
.macro save_general_regs cxt_size=CONTEXT_SIZE
2121
addi sp, sp, -\cxt_size
22-
sw ra, RV_STK_RA(sp)
23-
sw tp, RV_STK_TP(sp)
24-
sw t0, RV_STK_T0(sp)
25-
sw t1, RV_STK_T1(sp)
26-
sw t2, RV_STK_T2(sp)
27-
sw a0, RV_STK_A0(sp)
28-
sw a1, RV_STK_A1(sp)
29-
sw a2, RV_STK_A2(sp)
30-
sw a3, RV_STK_A3(sp)
31-
sw a4, RV_STK_A4(sp)
32-
sw a5, RV_STK_A5(sp)
33-
sw a6, RV_STK_A6(sp)
34-
sw a7, RV_STK_A7(sp)
35-
sw t3, RV_STK_T3(sp)
36-
sw t4, RV_STK_T4(sp)
37-
sw t5, RV_STK_T5(sp)
38-
sw t6, RV_STK_T6(sp)
22+
sw ra, 0(sp)
23+
sw tp, 4(sp)
24+
sw t0, 8(sp)
25+
sw t1, 12(sp)
26+
sw t2, 16(sp)
27+
sw a0, 20(sp)
28+
sw a1, 24(sp)
29+
sw a2, 28(sp)
30+
sw a3, 32(sp)
31+
sw a4, 36(sp)
32+
sw a5, 40(sp)
33+
sw a6, 44(sp)
34+
sw a7, 48(sp)
35+
sw t3, 52(sp)
36+
sw t4, 56(sp)
37+
sw t5, 60(sp)
38+
sw t6, 64(sp)
3939
.endm
4040

4141
/* Restore the general purpose registers (excluding gp) from the context on
4242
* the stack. The context is then deallocated. The default size is CONTEXT_SIZE
4343
* but it can be overridden. */
4444
.macro restore_general_regs cxt_size=CONTEXT_SIZE
45-
lw ra, RV_STK_RA(sp)
46-
lw tp, RV_STK_TP(sp)
47-
lw t0, RV_STK_T0(sp)
48-
lw t1, RV_STK_T1(sp)
49-
lw t2, RV_STK_T2(sp)
50-
lw a0, RV_STK_A0(sp)
51-
lw a1, RV_STK_A1(sp)
52-
lw a2, RV_STK_A2(sp)
53-
lw a3, RV_STK_A3(sp)
54-
lw a4, RV_STK_A4(sp)
55-
lw a5, RV_STK_A5(sp)
56-
lw a6, RV_STK_A6(sp)
57-
lw a7, RV_STK_A7(sp)
58-
lw t3, RV_STK_T3(sp)
59-
lw t4, RV_STK_T4(sp)
60-
lw t5, RV_STK_T5(sp)
61-
lw t6, RV_STK_T6(sp)
45+
lw ra, 0(sp)
46+
lw tp, 4(sp)
47+
lw t0, 8(sp)
48+
lw t1, 12(sp)
49+
lw t2, 16(sp)
50+
lw a0, 20(sp)
51+
lw a1, 24(sp)
52+
lw a2, 28(sp)
53+
lw a3, 32(sp)
54+
lw a4, 36(sp)
55+
lw a5, 40(sp)
56+
lw a6, 44(sp)
57+
lw a7, 48(sp)
58+
lw t3, 52(sp)
59+
lw t4, 56(sp)
60+
lw t5, 60(sp)
61+
lw t6, 64(sp)
6262
addi sp,sp, \cxt_size
6363
.endm
6464

@@ -89,7 +89,7 @@ irq_vector:
8989
/* Restore the register context after returning from the C interrupt handler */
9090
restore_general_regs
9191

92-
/* Exit interrupt handler by executing the custom retirq instruction which will retore pc and re-enable interrupts */
92+
/* Exit interrupt handler by executing the custom retirq instruction which will restore pc and re-enable interrupts */
9393
retirq_insn()
9494

9595
#endif /* CONFIG_ULP_RISCV_INTERRUPT_ENABLE */

0 commit comments

Comments
 (0)