Skip to content

Commit df6b8c3

Browse files
Mark Holdennashif
authored andcommitted
coredump: arm: Capture callee registers during k_panic() / k_oops
Ensure callee registers included in coredump. Push callee registers onto stack and pass as param to z_do_kernel_oops for CONFIG_ARMV7_M_ARMV8_M_MAINLINE when CONFIG_EXTRA_EXCEPTION_INFO enabled. Signed-off-by: Mark Holden <[email protected]>
1 parent b6377cc commit df6b8c3

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

arch/arm/core/aarch32/fatal.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,13 @@ void z_arm_fatal_error(unsigned int reason, const z_arch_esf_t *esf)
7777
* fault handler will executed instead of the SVC.
7878
*
7979
* @param esf exception frame
80+
* @param callee_regs Callee-saved registers (R4-R11)
8081
*/
81-
void z_do_kernel_oops(const z_arch_esf_t *esf)
82+
void z_do_kernel_oops(const z_arch_esf_t *esf, _callee_saved_t *callee_regs)
8283
{
84+
#if !(defined(CONFIG_EXTRA_EXCEPTION_INFO) && defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE))
85+
ARG_UNUSED(callee_regs);
86+
#endif
8387
/* Stacked R0 holds the exception reason. */
8488
unsigned int reason = esf->basic.r0;
8589

@@ -102,15 +106,26 @@ void z_do_kernel_oops(const z_arch_esf_t *esf)
102106

103107
#if !defined(CONFIG_EXTRA_EXCEPTION_INFO)
104108
z_arm_fatal_error(reason, esf);
109+
#else
110+
z_arch_esf_t esf_copy;
111+
112+
memcpy(&esf_copy, esf, offsetof(z_arch_esf_t, extra_info));
113+
#if defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE)
114+
/* extra exception info is collected in callee_reg param
115+
* on CONFIG_ARMV7_M_ARMV8_M_MAINLINE
116+
*/
117+
118+
esf_copy.extra_info = (struct __extra_esf_info) {
119+
.callee = callee_regs,
120+
};
105121
#else
106122
/* extra exception info is not collected for kernel oops
107123
* path today so we make a copy of the ESF and zero out
108124
* that information
109125
*/
110-
z_arch_esf_t esf_copy;
111-
112-
memcpy(&esf_copy, esf, offsetof(z_arch_esf_t, extra_info));
113126
esf_copy.extra_info = (struct __extra_esf_info) { 0 };
127+
#endif /* CONFIG_ARMV7_M_ARMV8_M_MAINLINE */
128+
114129
z_arm_fatal_error(reason, &esf_copy);
115130
#endif /* CONFIG_EXTRA_EXCEPTION_INFO */
116131
}

arch/arm/core/aarch32/swap_helper.S

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,29 @@ _stack_frame_endif:
556556

557557
_oops:
558558
push {r0, lr}
559+
#if defined(CONFIG_EXTRA_EXCEPTION_INFO)
560+
#if defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE)
561+
/* Build _callee_saved_t. To match the struct
562+
* definition we push the psp & then r11-r4
563+
*/
564+
mrs r1, PSP
565+
push {r1, r2}
566+
push {r4-r11}
567+
mov r1, sp /* pointer to _callee_saved_t */
568+
#endif /* CONFIG_ARMV7_M_ARMV8_M_MAINLINE */
569+
#endif /* CONFIG_EXTRA_EXCEPTION_INFO */
559570
bl z_do_kernel_oops
560571
/* return from SVC exception is done here */
572+
#if defined(CONFIG_EXTRA_EXCEPTION_INFO)
573+
#if defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE)
574+
/* We do not need to restore any register state here
575+
* because we did not use any callee-saved registers
576+
* in this routine. Therefore, we can just reset
577+
* the MSP to its value prior to entering the function
578+
*/
579+
add sp, #40
580+
#endif /* CONFIG_ARMV7_M_ARMV8_M_MAINLINE */
581+
#endif /* CONFIG_EXTRA_EXCEPTION_INFO */
561582
pop {r0, pc}
562583

563584
#if defined(CONFIG_USERSPACE)

0 commit comments

Comments
 (0)