]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c
ArmPkg: Fix various typos
[mirror_edk2.git] / ArmPkg / Library / DefaultExceptionHandlerLib / AArch64 / DefaultExceptionHandler.c
index 1251bb8bd6fa9617f4b52e2124d11b4a217fefa0..ba3c0e0cc467096f52828ec1a5c39f7654554053 100644 (file)
@@ -4,13 +4,7 @@
   Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
   Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>\r
 \r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -22,6 +16,7 @@
 #include <Library/PrintLib.h>\r
 #include <Library/ArmDisassemblerLib.h>\r
 #include <Library/SerialPortLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
 \r
 #include <Guid/DebugImageInfoTable.h>\r
 #include <Protocol/DebugSupport.h>\r
@@ -142,7 +137,7 @@ BaseName (
 /**\r
   This is the default action to take on an unexpected exception\r
 \r
-  Since this is exception context don't do anything crazy like try to allcoate memory.\r
+  Since this is exception context don't do anything crazy like try to allocate memory.\r
 \r
   @param  ExceptionType    Type of the exception\r
   @param  SystemContext    Register state at the time of the Exception\r
@@ -159,41 +154,72 @@ DefaultExceptionHandler (
   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
+    STATIC CHAR8 CONST Message[] = "\nRecursive exception occurred while dumping the CPU state\n";\r
+\r
+    SerialPortWrite ((UINT8 *)Message, sizeof Message - 1);\r
+    if (gST->ConOut != NULL) {\r
+      AsciiPrint (Message);\r
+    }\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
+  if (gST->ConOut != NULL) {\r
+    AsciiPrint (Buffer);\r
+  }\r
 \r
   DEBUG_CODE_BEGIN ();\r
-    CHAR8  *Pdb;\r
+    CHAR8  *Pdb, *PrevPdb;\r
     UINTN  ImageBase;\r
     UINTN  PeCoffSizeOfHeader;\r
     UINT64 *Fp;\r
+    UINT64 RootFp[2];\r
+    UINTN  Idx;\r
 \r
-    Pdb = GetImageName (SystemContext.SystemContextAArch64->ELR, &ImageBase, &PeCoffSizeOfHeader);\r
+    PrevPdb = Pdb = GetImageName (SystemContext.SystemContextAArch64->ELR, &ImageBase, &PeCoffSizeOfHeader);\r
     if (Pdb != NULL) {\r
-      DEBUG ((EFI_D_ERROR, "%a loaded at 0x%016lx \n", BaseName (Pdb), ImageBase));\r
+      DEBUG ((EFI_D_ERROR, "PC 0x%012lx (0x%012lx+0x%08x) [ 0] %a\n",\r
+        SystemContext.SystemContextAArch64->ELR, ImageBase,\r
+        SystemContext.SystemContextAArch64->ELR - ImageBase, BaseName (Pdb)));\r
+    } else {\r
+      DEBUG ((EFI_D_ERROR, "PC 0x%012lx\n", SystemContext.SystemContextAArch64->ELR));\r
+    }\r
 \r
-      Pdb = GetImageName (SystemContext.SystemContextAArch64->LR, &ImageBase,\r
-              &PeCoffSizeOfHeader);\r
-      if (Pdb != NULL) {\r
-        DEBUG ((EFI_D_ERROR, "called from %a (0x%016lx) loaded at 0x%016lx \n",\r
-          BaseName (Pdb), SystemContext.SystemContextAArch64->LR, ImageBase));\r
+    if ((UINT64 *)SystemContext.SystemContextAArch64->FP != 0) {\r
+      Idx = 0;\r
+\r
+      RootFp[0] = ((UINT64 *)SystemContext.SystemContextAArch64->FP)[0];\r
+      RootFp[1] = ((UINT64 *)SystemContext.SystemContextAArch64->FP)[1];\r
+      if (RootFp[1] != SystemContext.SystemContextAArch64->LR) {\r
+        RootFp[0] = SystemContext.SystemContextAArch64->FP;\r
+        RootFp[1] = SystemContext.SystemContextAArch64->LR;\r
       }\r
-      for (Fp = (UINT64 *)SystemContext.SystemContextAArch64->FP;\r
-           *Fp != 0;\r
-           Fp = (UINT64 *)Fp[0]) {\r
-        if (Fp[1] == SystemContext.SystemContextAArch64->LR) {\r
-         continue;\r
-        }\r
+      for (Fp = RootFp; Fp[0] != 0; Fp = (UINT64 *)Fp[0]) {\r
         Pdb = GetImageName (Fp[1], &ImageBase, &PeCoffSizeOfHeader);\r
         if (Pdb != NULL) {\r
-          DEBUG ((EFI_D_ERROR, "called from %a (0x%016lx) loaded at 0x%016lx \n",\r
-            BaseName (Pdb), Fp[1], ImageBase));\r
+          if (Pdb != PrevPdb) {\r
+            Idx++;\r
+            PrevPdb = Pdb;\r
+          }\r
+          DEBUG ((EFI_D_ERROR, "PC 0x%012lx (0x%012lx+0x%08x) [% 2d] %a\n",\r
+            Fp[1], ImageBase, Fp[1] - ImageBase, Idx, BaseName (Pdb)));\r
+        } else {\r
+          DEBUG ((EFI_D_ERROR, "PC 0x%012lx\n", Fp[1]));\r
+        }\r
+      }\r
+      PrevPdb = Pdb = GetImageName (SystemContext.SystemContextAArch64->ELR, &ImageBase, &PeCoffSizeOfHeader);\r
+      if (Pdb != NULL) {\r
+        DEBUG ((EFI_D_ERROR, "\n[ 0] %a\n", Pdb));\r
+      }\r
+\r
+      Idx = 0;\r
+      for (Fp = RootFp; Fp[0] != 0; Fp = (UINT64 *)Fp[0]) {\r
+        Pdb = GetImageName (Fp[1], &ImageBase, &PeCoffSizeOfHeader);\r
+        if (Pdb != NULL && Pdb != PrevPdb) {\r
+          DEBUG ((EFI_D_ERROR, "[% 2d] %a\n", ++Idx, Pdb));\r
+          PrevPdb = Pdb;\r
         }\r
       }\r
     }\r