Skip to content

Commit 3f7162f

Browse files
Bradley Bolenstephanosio
authored andcommitted
arch: arm: aarch32: Rearrange exception stack frame
Cortex-A/R use a descending stack frame and the hardware does not help with the stacking. This led to some less than desirable workarounds in the exception code where the basic stack frame was saved twice. Rearranging the order of the exception stack frame removes that problem and provides a clearer path to saving CPU context in a fully descending manner. Signed-off-by: Bradley Bolen <[email protected]>
1 parent 1839894 commit 3f7162f

File tree

2 files changed

+43
-31
lines changed
  • arch/arm/core/aarch32/cortex_a_r
  • include/zephyr/arch/arm/aarch32

2 files changed

+43
-31
lines changed

arch/arm/core/aarch32/cortex_a_r/exc.S

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,49 +47,34 @@ GTEXT(z_arm_data_abort)
4747
stmfd sp, {r0-r3, r12, lr}^
4848
sub sp, #24
4949

50-
/*
51-
* Create new esf struct for exception handler debug. The first
52-
* time the basic stack frame is saved is for getting in and out
53-
* of the exception.
54-
*/
55-
#if defined(CONFIG_EXTRA_EXCEPTION_INFO)
56-
sub sp, #___callee_saved_t_SIZEOF
57-
sub sp, #___extra_esf_info_t_SIZEOF
58-
#endif
59-
60-
srsdb sp!, #\mode
61-
stmfd sp, {r0-r3, r12, lr}^
62-
sub sp, #24
63-
64-
/* Increment exception nesting count */
65-
ldr r2, =_kernel
66-
ldr r0, [r2, #_kernel_offset_to_nested]
67-
add r0, r0, #1
68-
str r0, [r2, #_kernel_offset_to_nested]
69-
7050
#if defined(CONFIG_EXTRA_EXCEPTION_INFO)
7151
/* Pointer to extra esf info */
72-
add r0, sp, #___basic_sf_t_SIZEOF
73-
mov r1, #0
74-
str r1, [r0, #4]
75-
str r1, [r0, #8]
76-
77-
/* Pointer to callee saved registers */
78-
add r1, r0, #___extra_esf_info_t_SIZEOF
79-
str r1, [r0]
52+
sub sp, #___extra_esf_info_t_SIZEOF
53+
mov r0, #0
54+
str r0, [sp, #4]
55+
str r0, [sp, #8]
8056

57+
sub r1, sp, #___callee_saved_t_SIZEOF
58+
str r1, [sp]
8159
cps #MODE_SYS
8260
stm r1, {r4-r11, sp}
8361
cps #\mode
84-
#endif
8562

86-
/* Invoke fault handler */
8763
mov r0, sp
64+
mov sp, r1
65+
#else
66+
mov r0, sp
67+
#endif
68+
69+
/* Increment exception nesting count */
70+
ldr r2, =_kernel
71+
ldr r1, [r2, #_kernel_offset_to_nested]
72+
add r1, r1, #1
73+
str r1, [r2, #_kernel_offset_to_nested]
8874
.endm
8975

9076
.macro exception_exit
9177
/* Exit exception */
92-
add sp, sp, #___basic_sf_t_SIZEOF
9378
#if defined(CONFIG_EXTRA_EXCEPTION_INFO)
9479
add sp, #___extra_esf_info_t_SIZEOF
9580
add sp, #___callee_saved_t_SIZEOF

include/zephyr/arch/arm/aarch32/exc.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ struct __extra_esf_info {
8383
};
8484
#endif /* CONFIG_EXTRA_EXCEPTION_INFO */
8585

86+
#if defined(CONFIG_CPU_CORTEX_M)
87+
8688
struct __esf {
8789
struct __basic_sf {
8890
sys_define_gpr_with_alias(a1, r0);
@@ -104,6 +106,31 @@ struct __esf {
104106
#endif
105107
};
106108

109+
#else
110+
111+
struct __esf {
112+
#if defined(CONFIG_EXTRA_EXCEPTION_INFO)
113+
struct __extra_esf_info extra_info;
114+
#endif
115+
#if defined(CONFIG_FPU) && defined(CONFIG_FPU_SHARING)
116+
float s[16];
117+
uint32_t fpscr;
118+
uint32_t undefined;
119+
#endif
120+
struct __basic_sf {
121+
sys_define_gpr_with_alias(a1, r0);
122+
sys_define_gpr_with_alias(a2, r1);
123+
sys_define_gpr_with_alias(a3, r2);
124+
sys_define_gpr_with_alias(a4, r3);
125+
sys_define_gpr_with_alias(ip, r12);
126+
sys_define_gpr_with_alias(lr, r14);
127+
sys_define_gpr_with_alias(pc, r15);
128+
uint32_t xpsr;
129+
} basic;
130+
};
131+
132+
#endif
133+
107134
extern uint32_t z_arm_coredump_fault_sp;
108135

109136
typedef struct __esf z_arch_esf_t;

0 commit comments

Comments
 (0)