diff options
-rw-r--r-- | core/cortex-m/watchdog.c | 12 | ||||
-rw-r--r-- | core/cortex-m0/watchdog.c | 12 |
2 files changed, 20 insertions, 4 deletions
diff --git a/core/cortex-m/watchdog.c b/core/cortex-m/watchdog.c index 9e4a82c7b0..c9faf54b2b 100644 --- a/core/cortex-m/watchdog.c +++ b/core/cortex-m/watchdog.c @@ -12,6 +12,14 @@ #include "timer.h" #include "watchdog.h" +/* + * As defined by Armv7-M Reference Manual B1.5.6 "Exception Entry Behavior", + * the structure of the saved context on the stack is: + * r0, r1, r2, r3, r12, lr, pc, psr, ... + */ +#define STACK_IDX_REG_LR 5 +#define STACK_IDX_REG_PC 6 + void __keep watchdog_trace(uint32_t excep_lr, uint32_t excep_sp) { uint32_t psp; @@ -26,7 +34,7 @@ void __keep watchdog_trace(uint32_t excep_lr, uint32_t excep_sp) stack = (uint32_t *)psp; } - panic_set_reason(PANIC_SW_WATCHDOG, stack[6], + panic_set_reason(PANIC_SW_WATCHDOG, stack[STACK_IDX_REG_PC], (excep_lr & 0xf) == 1 ? 0xff : task_get_current()); /* @@ -37,7 +45,7 @@ void __keep watchdog_trace(uint32_t excep_lr, uint32_t excep_sp) cpu_clean_invalidate_dcache(); panic_printf("### WATCHDOG PC=%08x / LR=%08x / pSP=%08x ", - stack[6], stack[5], psp); + stack[STACK_IDX_REG_PC], stack[STACK_IDX_REG_LR], psp); if ((excep_lr & 0xf) == 1) panic_puts("(exc) ###\n"); else diff --git a/core/cortex-m0/watchdog.c b/core/cortex-m0/watchdog.c index 20fcc2ab35..9961922ee5 100644 --- a/core/cortex-m0/watchdog.c +++ b/core/cortex-m0/watchdog.c @@ -11,6 +11,14 @@ #include "timer.h" #include "watchdog.h" +/* + * As defined by Armv7-M Reference Manual B1.5.6 "Exception Entry Behavior", + * the structure of the saved context on the stack is: + * r0, r1, r2, r3, r12, lr, pc, psr, ... + */ +#define STACK_IDX_REG_LR 5 +#define STACK_IDX_REG_PC 6 + void watchdog_trace(uint32_t excep_lr, uint32_t excep_sp) { uint32_t psp; @@ -27,12 +35,12 @@ void watchdog_trace(uint32_t excep_lr, uint32_t excep_sp) /* Log PC. If we were in task context, log task id too. */ #ifdef CONFIG_SOFTWARE_PANIC - panic_set_reason(PANIC_SW_WATCHDOG, stack[6], + panic_set_reason(PANIC_SW_WATCHDOG, stack[STACK_IDX_REG_PC], (excep_lr & 0xf) == 1 ? 0xff : task_get_current()); #endif panic_printf("### WATCHDOG PC=%08x / LR=%08x / pSP=%08x ", - stack[6], stack[5], psp); + stack[STACK_IDX_REG_PC], stack[STACK_IDX_REG_LR], psp); if ((excep_lr & 0xf) == 1) panic_puts("(exc) ###\n"); else |