]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandler.c
Move ARM disassembler into a library.
[mirror_edk2.git] / ArmPkg / Library / DefaultExceptionHandlerLib / DefaultExceptionHandler.c
index 8180c42cabdce4b5840a19b34f6e3639e9c44c73..b6fbb19f46837a06dbfda7f5b2873a1715a61753 100644 (file)
 #include <Library/BaseLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/PeCoffGetEntryPointLib.h>\r
+#include <Library/ArmDisassemblerLib.h>\r
 \r
 #include <Guid/DebugImageInfoTable.h>\r
 #include <Protocol/DebugSupport.h>\r
 #include <Protocol/LoadedImage.h>\r
 \r
 \r
-VOID\r
-DisassembleArmInstruction (\r
-  IN  UINT32    *OpCodePtr,\r
-  OUT CHAR8     *Buf,\r
-  OUT UINTN     Size\r
-  );\r
-\r
-VOID\r
-DisassembleThumbInstruction (\r
-  IN  UINT16    *OpCodePtr,\r
-  OUT CHAR8     *Buf,\r
-  OUT UINTN     Size\r
-  );\r
-\r
-\r
 EFI_DEBUG_IMAGE_INFO_TABLE_HEADER *gDebugImageTableHeader = NULL;\r
 \r
 \r
@@ -248,6 +234,7 @@ DefaultExceptionHandler (
     UINT32  Offset;\r
     CHAR8   CpsrStr[32];  // char per bit. Lower 5-bits are mode that is a 3 char string\r
     CHAR8   Buffer[80];\r
+    UINT8   *DisAsm;\r
     \r
     CpsrString (SystemContext.SystemContextArm->CPSR, CpsrStr);\r
     DEBUG ((EFI_D_ERROR, "%a\n", CpsrStr));\r
@@ -268,15 +255,10 @@ DefaultExceptionHandler (
       DEBUG ((EFI_D_ERROR, "loaded at 0x%08x (PE/COFF offset) 0x%x (ELF or Mach-O offset) 0x%x", ImageBase, Offset, Offset - PeCoffSizeOfHeader));\r
       \r
       // If we come from an image it is safe to show the instruction. We know it should not fault\r
-      if ((SystemContext.SystemContextArm->CPSR & 0x20) == 0) {\r
-        // ARM\r
-        DisassembleArmInstruction ((UINT32 *)(UINTN)SystemContext.SystemContextArm->PC, Buffer, sizeof (Buffer));\r
-        DEBUG ((EFI_D_ERROR, "\n%a", Buffer));\r
-      } else {\r
-        // Thumb\r
-        DisassembleThumbInstruction ((UINT16 *)(UINTN)SystemContext.SystemContextArm->PC, Buffer, sizeof (Buffer));\r
-        DEBUG ((EFI_D_ERROR, "\n%a", Buffer));\r
-      }\r
+      DisAsm = (UINT8 *)(UINTN)SystemContext.SystemContextArm->PC;\r
+      DisassembleInstruction (&DisAsm, (SystemContext.SystemContextArm->CPSR & BIT5) == BIT5, Buffer, sizeof (Buffer));\r
+      DEBUG ((EFI_D_ERROR, "\n%a", Buffer));\r
+\r
     }\r
   DEBUG_CODE_END ();\r
   DEBUG ((EFI_D_ERROR, "\n  R0 0x%08x   R1 0x%08x   R2 0x%08x   R3 0x%08x\n", SystemContext.SystemContextArm->R0, SystemContext.SystemContextArm->R1, SystemContext.SystemContextArm->R2, SystemContext.SystemContextArm->R3));\r