diff options
Diffstat (limited to 'common/panic_output.c')
-rw-r--r-- | common/panic_output.c | 66 |
1 files changed, 58 insertions, 8 deletions
diff --git a/common/panic_output.c b/common/panic_output.c index 4f0f22d00d..af98c5953d 100644 --- a/common/panic_output.c +++ b/common/panic_output.c @@ -6,6 +6,7 @@ #include "common.h" #include "console.h" #include "cpu.h" +#include "hooks.h" #include "host_command.h" #include "panic.h" #include "printf.h" @@ -82,8 +83,11 @@ void panic_reboot(void) void panic_assert_fail(const char *fname, int linenum) { panic_printf("\nASSERTION FAILURE at %s:%d\n", fname, linenum); - +#ifdef CONFIG_SOFTWARE_PANIC + software_panic(PANIC_SW_ASSERT, linenum); +#else panic_reboot(); +#endif } #else void panic_assert_fail(const char *msg, const char *func, const char *fname, @@ -91,8 +95,11 @@ void panic_assert_fail(const char *msg, const char *func, const char *fname, { panic_printf("\nASSERTION FAILURE '%s' in %s() at %s:%d\n", msg, func, fname, linenum); - +#ifdef CONFIG_SOFTWARE_PANIC + software_panic(PANIC_SW_ASSERT, linenum); +#else panic_reboot(); +#endif } #endif #endif @@ -108,6 +115,37 @@ struct panic_data *panic_get_data(void) return pdata_ptr->magic == PANIC_DATA_MAGIC ? pdata_ptr : NULL; } +#ifdef CONFIG_SOFTWARE_PANIC +static void panic_init(void) +{ + /* Log panic cause if watchdog caused reset */ + if (system_get_reset_flags() & RESET_FLAG_WATCHDOG) + panic_log_watchdog(); +} +DECLARE_HOOK(HOOK_INIT, panic_init, HOOK_PRIO_DEFAULT); +#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); +} +#endif /* CONFIG_CMD_STACKOVERFLOW */ + /*****************************************************************************/ /* Console commands */ @@ -116,14 +154,26 @@ static int command_crash(int argc, char **argv) if (argc < 2) return EC_ERROR_PARAM1; - if (!strcasecmp(argv[1], "divzero")) { - int a = 1, b = 0; + if (!strcasecmp(argv[1], "assert")) { + ASSERT(0); + } else if (!strcasecmp(argv[1], "divzero")) { + int zero = 0; cflush(); - ccprintf("%08x", a / b); + if (argc >= 3 && !strcasecmp(argv[2], "unsigned")) + ccprintf("%08x", (unsigned long)1 / zero); + else + ccprintf("%08x", (long)1 / zero); +#ifdef CONFIG_CMD_STACKOVERFLOW + } else if (!strcasecmp(argv[1], "stack")) { + stack_overflow_recurse(1); +#endif } else if (!strcasecmp(argv[1], "unaligned")) { cflush(); ccprintf("%08x", *(int *)0xcdef); + } else if (!strcasecmp(argv[1], "watchdog")) { + while (1) + ; } else { return EC_ERROR_PARAM1; } @@ -132,9 +182,9 @@ static int command_crash(int argc, char **argv) return EC_ERROR_UNKNOWN; } DECLARE_CONSOLE_COMMAND(crash, command_crash, - "[divzero | unaligned]", - "Crash the system (for testing)", - NULL); + "[assert | divzero | stack | unaligned | watchdog] [options]", + "Crash the system (for testing)", + NULL); static int command_panicinfo(int argc, char **argv) { |