summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2015-02-13 15:29:33 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-02-18 04:53:51 +0000
commitd00847782480e492401ba3bc5a8a8e6f026b08ba (patch)
tree01c42b77ba518cf57e7512affcb833f0df61056f /core
parent9cb03971f6852fa03df3290e44a8451e01774755 (diff)
downloadchrome-ec-d00847782480e492401ba3bc5a8a8e6f026b08ba.tar.gz
cortex-m*: Save panicinfo on non-exception panics
Make non-exception "software" panics such as stack overflow and assert failure save a panic log. Log the panic type in r4, and misc. panic data in r5 so that panic reasons can be distinguished. BUG=chrome-os-partner:36744 TEST=Manual on samus_pd. Run 'crash divzero' then 'panicinfo' after reboot. Verify that panic info is printed with "r4 :dead6660". Trigger stack overflow, verify that panic info is printed with "r4 :dead6661". BRANCH=Samus Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: I5f7a8eb0a5c2ac5799d29bb241deb24fabf38f68 Reviewed-on: https://chromium-review.googlesource.com/249912 Tested-by: Alec Berg <alecaberg@chromium.org> Reviewed-by: Alec Berg <alecaberg@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/cortex-m/config_core.h2
-rw-r--r--core/cortex-m/panic.c22
-rw-r--r--core/cortex-m/task.c35
-rw-r--r--core/cortex-m/uldivmod.S4
-rw-r--r--core/cortex-m0/config_core.h1
-rw-r--r--core/cortex-m0/div.S4
-rw-r--r--core/cortex-m0/panic.c22
-rw-r--r--core/cortex-m0/task.c35
-rw-r--r--core/cortex-m0/uldivmod.S4
9 files changed, 60 insertions, 69 deletions
diff --git a/core/cortex-m/config_core.h b/core/cortex-m/config_core.h
index 7f3d253427..e72f4e58bb 100644
--- a/core/cortex-m/config_core.h
+++ b/core/cortex-m/config_core.h
@@ -10,4 +10,6 @@
#define BFD_ARCH arm
#define BFD_FORMAT "elf32-littlearm"
+#define CONFIG_SOFTWARE_PANIC
+
#endif /* __CONFIG_CORE_H */
diff --git a/core/cortex-m/panic.c b/core/cortex-m/panic.c
index d63a5e3d9a..64fd5b8db1 100644
--- a/core/cortex-m/panic.c
+++ b/core/cortex-m/panic.c
@@ -373,6 +373,28 @@ void exception_panic(void)
);
}
+void software_panic(uint32_t panic_reason, uint32_t panic_info)
+{
+ __asm__("mov " STRINGIFY(SOFTWARE_PANIC_INFO_REG) ", %0\n"
+ "mov " STRINGIFY(SOFTWARE_PANIC_REASON_REG) ", %1\n"
+ "bl exception_panic\n"
+ : : "r"(panic_info), "r"(panic_reason));
+}
+
+void panic_log_watchdog(void)
+{
+ uint32_t *lregs = pdata_ptr->cm.regs;
+
+ /* Watchdog reset, log panic cause */
+ memset(pdata_ptr, 0, sizeof(*pdata_ptr));
+ pdata_ptr->magic = PANIC_DATA_MAGIC;
+ pdata_ptr->struct_size = sizeof(*pdata_ptr);
+ pdata_ptr->struct_version = 2;
+ pdata_ptr->arch = PANIC_ARCH_CORTEX_M;
+
+ lregs[3] = PANIC_SW_WATCHDOG;
+}
+
void bus_fault_handler(void)
{
if (!bus_fault_ignored)
diff --git a/core/cortex-m/task.c b/core/cortex-m/task.c
index 69e93457cb..f7fda67374 100644
--- a/core/cortex-m/task.c
+++ b/core/cortex-m/task.c
@@ -10,6 +10,7 @@
#include "console.h"
#include "cpu.h"
#include "link_defs.h"
+#include "panic.h"
#include "task.h"
#include "timer.h"
#include "uart.h"
@@ -225,7 +226,7 @@ void svc_handler(int desched, task_id_t resched)
if (*current->stack != STACK_UNUSED_VALUE) {
panic_printf("\n\nStack overflow in %s task!\n",
task_names[current - tasks]);
- panic_reboot();
+ software_panic(PANIC_SW_STACK_OVERFLOW, current - tasks);
}
#endif
@@ -590,38 +591,6 @@ DECLARE_CONSOLE_COMMAND(taskready, command_task_ready,
NULL);
#endif
-#ifdef CONFIG_CMD_STACKOVERFLOW
-static void stack_overflow_recurse(int n)
-{
- ccprintf("+%d", n);
-
- /*
- * Force task context switch, since that's where we do stack overflow
- * checking.
- */
- msleep(10);
-
- stack_overflow_recurse(n+1);
-
- /*
- * Do work after the recursion, or else the compiler uses tail-chaining
- * and we don't actually consume additional stack.
- */
- ccprintf("-%d", n);
-}
-
-static int command_stackoverflow(int argc, char **argv)
-{
- ccprintf("Recursing 0,");
- stack_overflow_recurse(1);
- return EC_SUCCESS;
-}
-DECLARE_CONSOLE_COMMAND(stackoverflow, command_stackoverflow,
- NULL,
- "Recurse until stack overflow",
- NULL);
-#endif /* CONFIG_CMD_STACKOVERFLOW */
-
void task_pre_init(void)
{
uint32_t *stack_next = (uint32_t *)task_stacks;
diff --git a/core/cortex-m/uldivmod.S b/core/cortex-m/uldivmod.S
index a14bdb203f..256023e9cc 100644
--- a/core/cortex-m/uldivmod.S
+++ b/core/cortex-m/uldivmod.S
@@ -16,6 +16,7 @@
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "software_panic.h"
.syntax unified
@@ -174,4 +175,5 @@ L_dont_sub4:
pop {r4, r5, r6, r7, pc}
__aeabi_ldiv0:
- bl panic_reboot
+ ldr SOFTWARE_PANIC_REASON_REG, =PANIC_SW_DIV_ZERO
+ bl exception_panic
diff --git a/core/cortex-m0/config_core.h b/core/cortex-m0/config_core.h
index 11c209c66a..9c04d467e3 100644
--- a/core/cortex-m0/config_core.h
+++ b/core/cortex-m0/config_core.h
@@ -12,5 +12,6 @@
/* Emulate the CLZ instruction since the CPU core is lacking support */
#define CONFIG_SOFTWARE_CLZ
+#define CONFIG_SOFTWARE_PANIC
#endif /* __CONFIG_CORE_H */
diff --git a/core/cortex-m0/div.S b/core/cortex-m0/div.S
index 833465a59e..898ecafe83 100644
--- a/core/cortex-m0/div.S
+++ b/core/cortex-m0/div.S
@@ -18,6 +18,7 @@
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "software_panic.h"
.syntax unified
@@ -161,4 +162,5 @@ L_dont_sub0:
bx lr
__aeabi_idiv0:
- bl panic_reboot
+ ldr SOFTWARE_PANIC_REASON_REG, =PANIC_SW_DIV_ZERO
+ bl exception_panic
diff --git a/core/cortex-m0/panic.c b/core/cortex-m0/panic.c
index 7857fb55dd..2b17a1bd73 100644
--- a/core/cortex-m0/panic.c
+++ b/core/cortex-m0/panic.c
@@ -166,6 +166,28 @@ void exception_panic(void)
);
}
+void software_panic(uint32_t panic_reason, uint32_t panic_info)
+{
+ __asm__("mov " STRINGIFY(SOFTWARE_PANIC_INFO_REG) ", %0\n"
+ "mov " STRINGIFY(SOFTWARE_PANIC_REASON_REG) ", %1\n"
+ "bl exception_panic\n"
+ : : "r"(panic_info), "r"(panic_reason));
+}
+
+void panic_log_watchdog(void)
+{
+ uint32_t *lregs = pdata_ptr->cm.regs;
+
+ /* Watchdog reset, log panic cause */
+ memset(pdata_ptr, 0, sizeof(*pdata_ptr));
+ pdata_ptr->magic = PANIC_DATA_MAGIC;
+ pdata_ptr->struct_size = sizeof(*pdata_ptr);
+ pdata_ptr->struct_version = 2;
+ pdata_ptr->arch = PANIC_ARCH_CORTEX_M;
+
+ lregs[3] = PANIC_SW_WATCHDOG;
+}
+
void bus_fault_handler(void)
{
if (!bus_fault_ignored)
diff --git a/core/cortex-m0/task.c b/core/cortex-m0/task.c
index e51621b41e..86fb7071d5 100644
--- a/core/cortex-m0/task.c
+++ b/core/cortex-m0/task.c
@@ -10,6 +10,7 @@
#include "console.h"
#include "cpu.h"
#include "link_defs.h"
+#include "panic.h"
#include "task.h"
#include "timer.h"
#include "uart.h"
@@ -209,7 +210,7 @@ task_ *__svc_handler(int desched, task_id_t resched)
if (*current->stack != STACK_UNUSED_VALUE) {
panic_printf("\n\nStack overflow in %s task!\n",
task_names[current - tasks]);
- panic_reboot();
+ software_panic(PANIC_SW_STACK_OVERFLOW, current - tasks);
}
#endif
@@ -574,38 +575,6 @@ DECLARE_CONSOLE_COMMAND(taskready, command_task_ready,
NULL);
#endif
-#ifdef CONFIG_CMD_STACKOVERFLOW
-static void stack_overflow_recurse(int n)
-{
- ccprintf("+%d", n);
-
- /*
- * Force task context switch, since that's where we do stack overflow
- * checking.
- */
- msleep(10);
-
- stack_overflow_recurse(n+1);
-
- /*
- * Do work after the recursion, or else the compiler uses tail-chaining
- * and we don't actually consume additional stack.
- */
- ccprintf("-%d", n);
-}
-
-static int command_stackoverflow(int argc, char **argv)
-{
- ccprintf("Recursing 0,");
- stack_overflow_recurse(1);
- return EC_SUCCESS;
-}
-DECLARE_CONSOLE_COMMAND(stackoverflow, command_stackoverflow,
- NULL,
- "Recurse until stack overflow",
- NULL);
-#endif /* CONFIG_CMD_STACKOVERFLOW */
-
void task_pre_init(void)
{
uint32_t *stack_next = (uint32_t *)task_stacks;
diff --git a/core/cortex-m0/uldivmod.S b/core/cortex-m0/uldivmod.S
index b8855023ad..6909c6f242 100644
--- a/core/cortex-m0/uldivmod.S
+++ b/core/cortex-m0/uldivmod.S
@@ -16,6 +16,7 @@
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "software_panic.h"
.syntax unified
@@ -172,4 +173,5 @@ L_dont_sub4:
pop {r4, r5, r6, r7, pc}
__aeabi_ldiv0:
- bl panic_reboot
+ ldr SOFTWARE_PANIC_REASON_REG, =DIV_ZERO_PANIC
+ bl exception_panic