]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/DefaultExceptionHandlerLib: add stack dump to exception handling code
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Mon, 9 May 2016 14:24:18 +0000 (16:24 +0200)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Mon, 9 May 2016 15:25:52 +0000 (17:25 +0200)
This adds a partial stack dump (256 bytes at either side of the stack
pointer) to the CPU state dumping routine that is invoked when taking an
unexpected exception. Since dereferencing the stack pointer may itself
fault, ensure that we don't enter the dumping routine recursively.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Acked-by: Leif Lindholm <leif.lindholm@linaro.org>
ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c

index df30c4f125dbc09f18e18a8db71c9cdf2807dee7..ca2c48c82824169a47072361863680d6a6c824ac 100644 (file)
@@ -34,6 +34,8 @@ STATIC CHAR8 *gExceptionTypeString[] = {
   "SError"\r
 };\r
 \r
+STATIC BOOLEAN mRecursiveException;\r
+\r
 CHAR8 *\r
 GetImageName (\r
   IN  UINTN  FaultAddress,\r
@@ -134,6 +136,14 @@ DefaultExceptionHandler (
 {\r
   CHAR8  Buffer[100];\r
   UINTN  CharCount;\r
+  INT32  Offset;\r
+\r
+  if (mRecursiveException) {\r
+    CharCount = AsciiSPrint (Buffer, sizeof (Buffer),"\nRecursive exception occurred while dumping the CPU state\n");\r
+    SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
+    CpuDeadLoop ();\r
+  }\r
+  mRecursiveException = TRUE;\r
 \r
   CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"\n\n%a Exception at 0x%016lx\n", gExceptionTypeString[ExceptionType], SystemContext.SystemContextAArch64->ELR);\r
   SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
@@ -183,5 +193,16 @@ DefaultExceptionHandler (
   DescribeExceptionSyndrome (SystemContext.SystemContextAArch64->ESR);\r
   ASSERT (FALSE):\r
 \r
+  DEBUG ((EFI_D_ERROR, "\nStack dump:\n"));\r
+  for (Offset = -256; Offset < 256; Offset += 32) {\r
+    DEBUG  ((EFI_D_ERROR, "%c %013lx: %016lx %016lx %016lx %016lx\n",\r
+      Offset == 0 ? '>' : ' ',\r
+      SystemContext.SystemContextAArch64->SP + Offset,\r
+      *(UINT64 *)(SystemContext.SystemContextAArch64->SP + Offset),\r
+      *(UINT64 *)(SystemContext.SystemContextAArch64->SP + Offset + 8),\r
+      *(UINT64 *)(SystemContext.SystemContextAArch64->SP + Offset + 16),\r
+      *(UINT64 *)(SystemContext.SystemContextAArch64->SP + Offset + 24)));\r
+  }\r
+\r
   CpuDeadLoop ();\r
 }\r