From 8c55761613bd5f0b2bcac6c769256842218d96c1 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 3 Jun 2012 10:09:55 -0700 Subject: Add an option to report panics in a new stack For particularly nasty errors the stack or stack pointer may be corrupt, or in a place that we do not want overwritten. Provide and option to place the stack in a fresh place, assuming you can reach exception_panic(). Note that exception_panic() does not write anything to stack itself. BUG=chrome-os-partner:10146 TEST=manual: build for all boards On snow, cause a panic and see that it is reported correctly. Change-Id: I21d8b9bb12455758309d54ef20de66640d8a2df6 Signed-off-by: Simon Glass Reviewed-on: https://gerrit.chromium.org/gerrit/24504 --- README | 7 ++++++- core/cortex-m/panic.c | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README b/README index 00aa6662b1..e87846bf7d 100644 --- a/README +++ b/README @@ -25,7 +25,6 @@ by Google. See below diagram for architecture. +--------------------+ - Build Options ============= @@ -34,3 +33,9 @@ Build Options Try to detect a watchdog that is about to fire, and print a trace. This is needed on STM32, where the independent watchdog has no early warning feature and the windowed watchdog has a very short period. + +- CONFIG_PANIC_NEW_STACK + + When reporting a panic, change to a completely new stack. This might + help get a useful trace out a situation where the stack or stack + pointer has been corrupted. diff --git a/core/cortex-m/panic.c b/core/cortex-m/panic.c index cbdef6a96f..8e022857ef 100644 --- a/core/cortex-m/panic.c +++ b/core/cortex-m/panic.c @@ -16,9 +16,15 @@ #include "watchdog.h" +/* This is the size of our private panic stack, if we have one */ +#define STACK_SIZE_WORDS 64 + /* We save registers here for display by report_panic() */ static struct save_area { +#ifdef CONFIG_PANIC_NEW_STACK + uint32_t stack[STACK_SIZE_WORDS]; +#endif uint32_t saved_regs[11]; /* psp, ipsr, lr, r4-r11 */ } save_area __attribute__((aligned(8))); @@ -207,6 +213,9 @@ void exception_panic(void) "mrs r2, ipsr\n" "mov r3, lr\n" "stmia r0, {r1-r11}\n" +#ifdef CONFIG_PANIC_NEW_STACK + "mov sp, r0\n" +#endif "mov r1, r0\n" "mov r0, #0\n" "b report_panic" : : -- cgit v1.2.1