From 3ed68f15afe5a858c539d5f1ac891db0c78ac876 Mon Sep 17 00:00:00 2001 From: Paul Olaru Date: Wed, 31 Jul 2019 14:45:38 +0300 Subject: [PATCH] panic: Distinguish exceptions from other panics On exceptions and panics, the code will reach panic_rewind. That function will, among the other things it needs to do to dump the info, will also dump the exception cause (exccause register). This means that normally coredumps from panics and those from exceptions are indistinguishable. In this commit I reserve the maximum value for exccause (63) to signify that the dump actually came from a panic instead of a hardware exception. The easiest way I could see that would not duplicate code is to simply set the exccause register to this reserved value (otherwise it could be undefined, as it's not initialized at boot). I also update the core dumper tool to use 63 as the value reserved for panics instead of 0 (which is IllegalInstructionCause, a valid hardware exception). Signed-off-by: Paul Olaru --- src/debug/panic.c | 9 +++++++++ tools/coredumper/sof-coredump-reader.py | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/debug/panic.c b/src/debug/panic.c index 5708010df..e809473a6 100644 --- a/src/debug/panic.c +++ b/src/debug/panic.c @@ -88,5 +88,14 @@ void __panic(uint32_t p, char *filename, uint32_t linenum) filename, strlen + 1)); } + /* To distinguish regular panic() calls from exceptions, we will + * set a reserved value for the exception cause (63) so the + * coredumper tool could distinguish between the situations. + */ + __asm__ __volatile__("movi a3, 63\n\t" + "wsr.exccause a3\n\t" + "esync" : : : + "a3", "memory"); + panic_rewind(p, 0, &panicinfo, NULL); } diff --git a/tools/coredumper/sof-coredump-reader.py b/tools/coredumper/sof-coredump-reader.py index 03b338fb5..55445a1a7 100755 --- a/tools/coredumper/sof-coredump-reader.py +++ b/tools/coredumper/sof-coredump-reader.py @@ -729,7 +729,9 @@ class CoreDumpReader(object): stdoutPrint("set *0x{:08x}=0x{:08x}\n" .format(addr, dw)) - if self.core_dump.exccause: + # Exccause 63 is reserved for panics; the other causes come + # from actual exceptions + if self.core_dump.exccause != 63: verbosePrint("\n# *EXCEPTION*\n") verbosePrint("# exccause: " + EXCCAUSE_CODE[self.core_dump.exccause][0]) if EXCCAUSE_CODE[self.core_dump.exccause][1]: