]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/CpuExceptionHandlerLib: Add DumpCpuContext() implementation
authorJeff Fan <jeff.fan@intel.com>
Sat, 1 Apr 2017 06:16:41 +0000 (14:16 +0800)
committerJeff Fan <jeff.fan@intel.com>
Fri, 7 Apr 2017 01:43:44 +0000 (09:43 +0800)
Export DumpCpuCotext() to display CPU Context. We will invoke
PeCoffGetEntrypointLib's PeCoffSerachImageBase() to get PE/COFF image base.
Display exception data bit value for page fault exception.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c
UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c
UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c
UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c

index 3d85b0c415ae984196d9e4e864453fc523a140e1..05372083b36db4990963aab2e6bb62705761c08c 100644 (file)
@@ -106,82 +106,44 @@ InternalPrintMessage (
 \r
 /**\r
   Find and display image base address and return image base and its entry point.\r
 \r
 /**\r
   Find and display image base address and return image base and its entry point.\r
-\r
+  \r
   @param CurrentEip      Current instruction pointer.\r
   @param CurrentEip      Current instruction pointer.\r
-  @param EntryPoint      Return module entry point if module header is found.\r
-\r
-  @return !0     Image base address.\r
-  @return 0      Image header cannot be found.\r
+  \r
 **/\r
 **/\r
-UINTN\r
-FindModuleImageBase (\r
-  IN  UINTN              CurrentEip,\r
-  OUT UINTN              *EntryPoint\r
+VOID \r
+DumpModuleImageInfo (\r
+  IN  UINTN              CurrentEip\r
   )\r
 {\r
   )\r
 {\r
+  EFI_STATUS                           Status;\r
   UINTN                                Pe32Data;\r
   UINTN                                Pe32Data;\r
-  EFI_IMAGE_DOS_HEADER                 *DosHdr;\r
-  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION  Hdr;\r
   VOID                                 *PdbPointer;\r
   VOID                                 *PdbPointer;\r
+  VOID                                 *EntryPoint;\r
 \r
 \r
-  //\r
-  // Find Image Base\r
-  //\r
-  Pe32Data = CurrentEip & ~(mImageAlignSize - 1);\r
-  while (Pe32Data != 0) {\r
-    DosHdr = (EFI_IMAGE_DOS_HEADER *) Pe32Data;\r
-    if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
-      //\r
-      // DOS image header is present, so read the PE header after the DOS image header.\r
-      //\r
-      Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)(Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
-      //\r
-      // Make sure PE header address does not overflow and is less than the initial address.\r
-      //\r
-      if (((UINTN)Hdr.Pe32 > Pe32Data) && ((UINTN)Hdr.Pe32 < CurrentEip)) {\r
-        if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
-          //\r
-          // It's PE image.\r
-          //\r
-          InternalPrintMessage ("!!!! Find PE image ");\r
-          *EntryPoint = (UINTN)Pe32Data + (UINTN)(Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff);\r
-          break;\r
-        }\r
-      }\r
-    } else {\r
-      //\r
-      // DOS image header is not present, TE header is at the image base.\r
-      //\r
-      Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;\r
-      if ((Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) &&\r
-          ((Hdr.Te->Machine == IMAGE_FILE_MACHINE_I386) || Hdr.Te->Machine == IMAGE_FILE_MACHINE_X64)) {\r
-        //\r
-        // It's TE image, it TE header and Machine type match\r
-        //\r
-        InternalPrintMessage ("!!!! Find TE image ");\r
-        *EntryPoint = (UINTN)Pe32Data + (UINTN)(Hdr.Te->AddressOfEntryPoint & 0x0ffffffff) + sizeof(EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize;\r
-        break;\r
-      }\r
-    }\r
-\r
+  Pe32Data = PeCoffSerachImageBase (CurrentEip);\r
+  if (Pe32Data == 0) {\r
+    InternalPrintMessage ("!!!! Can't find image information. !!!!\n");\r
+  } else {\r
     //\r
     //\r
-    // Not found the image base, check the previous aligned address\r
+    // Find Image Base entry point\r
     //\r
     //\r
-    Pe32Data -= mImageAlignSize;\r
-  }\r
-\r
-  if (Pe32Data != 0) {\r
+    Status = PeCoffLoaderGetEntryPoint ((VOID *) Pe32Data, &EntryPoint);\r
+    if (EFI_ERROR (Status)) {\r
+      EntryPoint = NULL;\r
+    }\r
+    InternalPrintMessage ("!!!! Find image ");\r
     PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *) Pe32Data);\r
     if (PdbPointer != NULL) {\r
       InternalPrintMessage ("%a", PdbPointer);\r
     } else {\r
       InternalPrintMessage ("(No PDB) " );\r
     }\r
     PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *) Pe32Data);\r
     if (PdbPointer != NULL) {\r
       InternalPrintMessage ("%a", PdbPointer);\r
     } else {\r
       InternalPrintMessage ("(No PDB) " );\r
     }\r
-  } else {\r
-    InternalPrintMessage ("!!!! Can't find image information. !!!!\n");\r
+    InternalPrintMessage (\r
+      " (ImageBase=%016lp, EntryPoint=%016p) !!!!\n",\r
+      (VOID *) Pe32Data,\r
+      EntryPoint\r
+      );\r
   }\r
   }\r
-\r
-  return Pe32Data;\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
index 4639ed2d9073758d062211659b3607798d5e5df3..e66a5df86423365df055225a015c0f8edf8415f8 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Common header file for CPU Exception Handler Library.\r
 \r
 /** @file\r
   Common header file for CPU Exception Handler Library.\r
 \r
-  Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2012 - 2017, Intel Corporation. All rights reserved.<BR>\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
   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
 #include <Library/PeCoffGetEntryPointLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/SynchronizationLib.h>\r
 #include <Library/PeCoffGetEntryPointLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/SynchronizationLib.h>\r
+#include <Library/CpuExceptionHandlerLib.h>\r
 \r
 #define  CPU_EXCEPTION_NUM          32\r
 #define  CPU_INTERRUPT_NUM         256\r
 #define  HOOKAFTER_STUB_SIZE        16\r
 \r
 \r
 #define  CPU_EXCEPTION_NUM          32\r
 #define  CPU_INTERRUPT_NUM         256\r
 #define  HOOKAFTER_STUB_SIZE        16\r
 \r
+//\r
+// Exception Error Code of Page-Fault Exception\r
+//\r
+#define IA32_PF_EC_P                BIT0\r
+#define IA32_PF_EC_WR               BIT1\r
+#define IA32_PF_EC_US               BIT2\r
+#define IA32_PF_EC_RSVD             BIT3\r
+#define IA32_PF_EC_ID               BIT4\r
+#define IA32_PF_EC_PK               BIT5\r
+#define IA32_PF_EC_SGX              BIT15\r
+\r
 #include "ArchInterruptDefs.h"\r
 \r
 #define CPU_EXCEPTION_HANDLER_LIB_HOB_GUID \\r
 #include "ArchInterruptDefs.h"\r
 \r
 #define CPU_EXCEPTION_HANDLER_LIB_HOB_GUID \\r
@@ -53,7 +65,6 @@ typedef struct {
 } EXCEPTION_HANDLER_DATA;\r
 \r
 extern CONST UINT32                mErrorCodeFlag;\r
 } EXCEPTION_HANDLER_DATA;\r
 \r
 extern CONST UINT32                mErrorCodeFlag;\r
-extern CONST UINTN                 mImageAlignSize;\r
 extern CONST UINTN                 mDoFarReturnFlag;\r
 \r
 /**\r
 extern CONST UINTN                 mDoFarReturnFlag;\r
 \r
 /**\r
@@ -112,15 +123,11 @@ InternalPrintMessage (
   Find and display image base address and return image base and its entry point.\r
   \r
   @param CurrentEip      Current instruction pointer.\r
   Find and display image base address and return image base and its entry point.\r
   \r
   @param CurrentEip      Current instruction pointer.\r
-  @param EntryPoint      Return module entry point if module header is found.\r
   \r
   \r
-  @return !0     Image base address.\r
-  @return 0      Image header cannot be found.\r
 **/\r
 **/\r
-UINTN \r
-FindModuleImageBase (\r
-  IN  UINTN              CurrentEip,\r
-  OUT UINTN              *EntryPoint\r
+VOID \r
+DumpModuleImageInfo (\r
+  IN  UINTN              CurrentEip\r
   );\r
 \r
 /**\r
   );\r
 \r
 /**\r
@@ -130,7 +137,7 @@ FindModuleImageBase (
   @param SystemContext  Pointer to EFI_SYSTEM_CONTEXT.\r
 **/\r
 VOID\r
   @param SystemContext  Pointer to EFI_SYSTEM_CONTEXT.\r
 **/\r
 VOID\r
-DumpCpuContent (\r
+DumpImageAndCpuContent (\r
   IN EFI_EXCEPTION_TYPE   ExceptionType,\r
   IN EFI_SYSTEM_CONTEXT   SystemContext\r
   );\r
   IN EFI_EXCEPTION_TYPE   ExceptionType,\r
   IN EFI_SYSTEM_CONTEXT   SystemContext\r
   );\r
index a61a52b19ab0ce526122190314a4aca304148b58..ab13e5e870e54ff09931cad89c16a30c44d02357 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   CPU exception handler library implemenation for DXE modules.\r
 \r
 /** @file\r
   CPU exception handler library implemenation for DXE modules.\r
 \r
-  Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved.<BR>\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
   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
 \r
 CONST UINTN    mDoFarReturnFlag  = 0;\r
 \r
 \r
 CONST UINTN    mDoFarReturnFlag  = 0;\r
 \r
-//\r
-// Image align size for DXE/SMM\r
-//\r
-CONST UINTN      mImageAlignSize = SIZE_4KB;\r
-\r
 RESERVED_VECTORS_DATA       mReservedVectorsData[CPU_EXCEPTION_NUM];\r
 EFI_CPU_INTERRUPT_HANDLER   mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];\r
 UINTN                       mEnabledInterruptNum = 0;\r
 RESERVED_VECTORS_DATA       mReservedVectorsData[CPU_EXCEPTION_NUM];\r
 EFI_CPU_INTERRUPT_HANDLER   mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];\r
 UINTN                       mEnabledInterruptNum = 0;\r
index 7ab2438daeb0f394b7a10dd131055ec83c42ca7d..52b0e76cd24bec56e40474971bee7f25a184a231 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   IA32 CPU Exception Handler functons.\r
 \r
 /** @file\r
   IA32 CPU Exception Handler functons.\r
 \r
-  Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2012 - 2017, Intel Corporation. All rights reserved.<BR>\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
   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
@@ -108,39 +108,49 @@ ArchRestoreExceptionContext (
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
-  Display CPU information.\r
+  Display processor context.\r
 \r
 \r
-  @param ExceptionType  Exception type.\r
-  @param SystemContext  Pointer to EFI_SYSTEM_CONTEXT.\r
+  @param[in] ExceptionType  Exception type.\r
+  @param[in] SystemContext  Processor context to be display.\r
 **/\r
 VOID\r
 **/\r
 VOID\r
-DumpCpuContent (\r
+EFIAPI\r
+DumpCpuContext (\r
   IN EFI_EXCEPTION_TYPE   ExceptionType,\r
   IN EFI_SYSTEM_CONTEXT   SystemContext\r
   )\r
 {\r
   IN EFI_EXCEPTION_TYPE   ExceptionType,\r
   IN EFI_SYSTEM_CONTEXT   SystemContext\r
   )\r
 {\r
-  UINTN                   ImageBase;\r
-  UINTN                   EntryPoint;\r
-\r
   InternalPrintMessage (\r
     "!!!! IA32 Exception Type - %02x(%a)  CPU Apic ID - %08x !!!!\n",\r
     ExceptionType,\r
     GetExceptionNameStr (ExceptionType),\r
     GetApicId ()\r
     );\r
   InternalPrintMessage (\r
     "!!!! IA32 Exception Type - %02x(%a)  CPU Apic ID - %08x !!!!\n",\r
     ExceptionType,\r
     GetExceptionNameStr (ExceptionType),\r
     GetApicId ()\r
     );\r
-\r
+  if ((mErrorCodeFlag & (1 << ExceptionType)) != 0) {\r
+    InternalPrintMessage (\r
+      "ExceptionData - %08x",\r
+      SystemContext.SystemContextIa32->ExceptionData\r
+      );\r
+    if (ExceptionType == EXCEPT_IA32_PAGE_FAULT) {\r
+      InternalPrintMessage (\r
+        "  I:%x R:%x U:%x W:%x P:%x PK:%x S:%x",\r
+        (SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_ID)   != 0,\r
+        (SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_RSVD) != 0,\r
+        (SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_US)   != 0,\r
+        (SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_WR)   != 0,\r
+        (SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_P)    != 0,\r
+        (SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_PK)   != 0,\r
+        (SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_SGX)  != 0\r
+        );\r
+    }\r
+    InternalPrintMessage ("\n");\r
+  }\r
   InternalPrintMessage (\r
     "EIP  - %08x, CS  - %08x, EFLAGS - %08x\n",\r
     SystemContext.SystemContextIa32->Eip,\r
     SystemContext.SystemContextIa32->Cs,\r
     SystemContext.SystemContextIa32->Eflags\r
     );\r
   InternalPrintMessage (\r
     "EIP  - %08x, CS  - %08x, EFLAGS - %08x\n",\r
     SystemContext.SystemContextIa32->Eip,\r
     SystemContext.SystemContextIa32->Cs,\r
     SystemContext.SystemContextIa32->Eflags\r
     );\r
-  if ((mErrorCodeFlag & (1 << ExceptionType)) != 0) {\r
-    InternalPrintMessage (\r
-      "ExceptionData - %08x\n",\r
-      SystemContext.SystemContextIa32->ExceptionData\r
-      );\r
-  }\r
   InternalPrintMessage (\r
     "EAX  - %08x, ECX - %08x, EDX - %08x, EBX - %08x\n",\r
     SystemContext.SystemContextIa32->Eax,\r
   InternalPrintMessage (\r
     "EAX  - %08x, ECX - %08x, EDX - %08x, EBX - %08x\n",\r
     SystemContext.SystemContextIa32->Eax,\r
@@ -198,16 +208,23 @@ DumpCpuContent (
     "FXSAVE_STATE - %08x\n",\r
     &SystemContext.SystemContextIa32->FxSaveState\r
     );\r
     "FXSAVE_STATE - %08x\n",\r
     &SystemContext.SystemContextIa32->FxSaveState\r
     );\r
+}\r
+\r
+/**\r
+  Display CPU information.\r
 \r
 \r
+  @param ExceptionType  Exception type.\r
+  @param SystemContext  Pointer to EFI_SYSTEM_CONTEXT.\r
+**/\r
+VOID\r
+DumpImageAndCpuContent (\r
+  IN EFI_EXCEPTION_TYPE   ExceptionType,\r
+  IN EFI_SYSTEM_CONTEXT   SystemContext\r
+  )\r
+{\r
+  DumpCpuContext (ExceptionType, SystemContext);\r
   //\r
   //\r
-  // Find module image base and module entry point by RIP\r
+  // Dump module image base and module entry point by EIP\r
   //\r
   //\r
-  ImageBase = FindModuleImageBase (SystemContext.SystemContextIa32->Eip, &EntryPoint);\r
-  if (ImageBase != 0) {\r
-    InternalPrintMessage (\r
-      " (ImageBase=%08x, EntryPoint=%08x) !!!!\n",\r
-      ImageBase,\r
-      EntryPoint\r
-      );\r
-  }\r
+  DumpModuleImageInfo (SystemContext.SystemContextIa32->Eip);\r
 }\r
 }\r
index c3fd8ae196bc2375211ec01d104335a182c67692..53fa3c611e2f9776169ee5d1feeece2fc61cafbf 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   CPU exception handler library implementation for PEIM module.\r
 \r
 /** @file\r
   CPU exception handler library implementation for PEIM module.\r
 \r
-Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials are licensed and made available under\r
 the terms and conditions of the BSD License that accompanies this distribution.\r
 The full text of the license may be found at\r
 This program and the accompanying materials are licensed and made available under\r
 the terms and conditions of the BSD License that accompanies this distribution.\r
 The full text of the license may be found at\r
@@ -18,10 +18,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/HobLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 \r
 #include <Library/HobLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 \r
-//\r
-// Image Alignment size for PEI phase\r
-//\r
-CONST UINTN    mImageAlignSize   = 4;\r
 CONST UINTN    mDoFarReturnFlag  = 0;\r
 \r
 EFI_GUID mCpuExceptrionHandlerLibHobGuid = CPU_EXCEPTION_HANDLER_LIB_HOB_GUID;\r
 CONST UINTN    mDoFarReturnFlag  = 0;\r
 \r
 EFI_GUID mCpuExceptrionHandlerLibHobGuid = CPU_EXCEPTION_HANDLER_LIB_HOB_GUID;\r
index c0fc9a65cad9bb568d25dcc8da372a5e9382c094..fb679b5782dce29981afe705d8cc8ffefa1fe818 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   CPU Exception Library provides PEI/DXE/SMM CPU common exception handler.\r
 \r
 /** @file\r
   CPU Exception Library provides PEI/DXE/SMM CPU common exception handler.\r
 \r
-Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2012 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials are licensed and made available under\r
 the terms and conditions of the BSD License that accompanies this distribution.\r
 The full text of the license may be found at\r
 This program and the accompanying materials are licensed and made available under\r
 the terms and conditions of the BSD License that accompanies this distribution.\r
 The full text of the license may be found at\r
@@ -101,7 +101,7 @@ CommonExceptionHandlerWorker (
     //\r
     // Display ExceptionType, CPU information and Image information\r
     //  \r
     //\r
     // Display ExceptionType, CPU information and Image information\r
     //  \r
-    DumpCpuContent (ExceptionType, SystemContext);\r
+    DumpImageAndCpuContent (ExceptionType, SystemContext);\r
     //\r
     // Release Spinlock of output message\r
     //\r
     //\r
     // Release Spinlock of output message\r
     //\r
index 7e94e38ae1f50e30da355056d89e0616f5fb5584..5d6807b367100060e887cf8905983cb6157f6310 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   CPU exception handler library implemenation for SEC/PEIM modules.\r
 \r
 /** @file\r
   CPU exception handler library implemenation for SEC/PEIM modules.\r
 \r
-Copyright (c) 2012 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2012 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials are licensed and made available under\r
 the terms and conditions of the BSD License that accompanies this distribution.\r
 The full text of the license may be found at\r
 This program and the accompanying materials are licensed and made available under\r
 the terms and conditions of the BSD License that accompanies this distribution.\r
 The full text of the license may be found at\r
@@ -15,10 +15,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <PiPei.h>\r
 #include "CpuExceptionCommon.h"\r
 \r
 #include <PiPei.h>\r
 #include "CpuExceptionCommon.h"\r
 \r
-//\r
-// Image Aglinment size for SEC/PEI phase\r
-//\r
-CONST UINTN    mImageAlignSize   = 4;\r
 CONST UINTN    mDoFarReturnFlag  = 0;\r
 \r
 /**\r
 CONST UINTN    mDoFarReturnFlag  = 0;\r
 \r
 /**\r
@@ -37,7 +33,7 @@ CommonExceptionHandler (
   //\r
   // Display ExceptionType, CPU information and Image information\r
   //  \r
   //\r
   // Display ExceptionType, CPU information and Image information\r
   //  \r
-  DumpCpuContent (ExceptionType, SystemContext);\r
+  DumpImageAndCpuContent (ExceptionType, SystemContext);\r
   \r
   //\r
   // Enter a dead loop.\r
   \r
   //\r
   // Enter a dead loop.\r
index 7ad228c806ad83bc29f8f37a672273aa835891a4..5a3d4160250219591be5903bf0cb26aa9023744b 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   CPU exception handler library implemenation for SMM modules.\r
 \r
 /** @file\r
   CPU exception handler library implemenation for SMM modules.\r
 \r
-  Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved.<BR>\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
   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
@@ -22,11 +22,6 @@ CONST UINTN   mDoFarReturnFlag   = 1;
 //\r
 SPIN_LOCK        mDisplayMessageSpinLock;\r
 \r
 //\r
 SPIN_LOCK        mDisplayMessageSpinLock;\r
 \r
-//\r
-// Image align size for DXE/SMM\r
-//\r
-CONST UINTN      mImageAlignSize = SIZE_4KB;\r
-\r
 RESERVED_VECTORS_DATA       mReservedVectorsData[CPU_EXCEPTION_NUM];\r
 EFI_CPU_INTERRUPT_HANDLER   mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];\r
 EXCEPTION_HANDLER_DATA      mExceptionHandlerData;\r
 RESERVED_VECTORS_DATA       mReservedVectorsData[CPU_EXCEPTION_NUM];\r
 EFI_CPU_INTERRUPT_HANDLER   mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];\r
 EXCEPTION_HANDLER_DATA      mExceptionHandlerData;\r
index 7495b14530865d315e8a219ecaeedfaf7491bbe3..c0d19b9fc50708047787b05274f9ce721bd36428 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   x64 CPU Exception Handler.\r
 \r
 /** @file\r
   x64 CPU Exception Handler.\r
 \r
-  Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2012 - 2017, Intel Corporation. All rights reserved.<BR>\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
   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
@@ -119,33 +119,43 @@ ArchRestoreExceptionContext (
   @param SystemContext  Pointer to EFI_SYSTEM_CONTEXT.\r
 **/\r
 VOID\r
   @param SystemContext  Pointer to EFI_SYSTEM_CONTEXT.\r
 **/\r
 VOID\r
-DumpCpuContent (\r
+EFIAPI\r
+DumpCpuContext (\r
   IN EFI_EXCEPTION_TYPE   ExceptionType,\r
   IN EFI_SYSTEM_CONTEXT   SystemContext\r
   )\r
 {\r
   IN EFI_EXCEPTION_TYPE   ExceptionType,\r
   IN EFI_SYSTEM_CONTEXT   SystemContext\r
   )\r
 {\r
-  UINTN                   ImageBase;\r
-  UINTN                   EntryPoint;\r
-\r
   InternalPrintMessage (\r
     "!!!! X64 Exception Type - %02x(%a)  CPU Apic ID - %08x !!!!\n",\r
     ExceptionType,\r
     GetExceptionNameStr (ExceptionType),\r
     GetApicId ()\r
     );\r
   InternalPrintMessage (\r
     "!!!! X64 Exception Type - %02x(%a)  CPU Apic ID - %08x !!!!\n",\r
     ExceptionType,\r
     GetExceptionNameStr (ExceptionType),\r
     GetApicId ()\r
     );\r
-\r
+  if ((mErrorCodeFlag & (1 << ExceptionType)) != 0) {\r
+    InternalPrintMessage (\r
+      "ExceptionData - %016lx",\r
+      SystemContext.SystemContextX64->ExceptionData\r
+      );\r
+    if (ExceptionType == EXCEPT_IA32_PAGE_FAULT) {\r
+      InternalPrintMessage (\r
+        "  I:%x R:%x U:%x W:%x P:%x PK:%x S:%x",\r
+        (SystemContext.SystemContextX64->ExceptionData & IA32_PF_EC_ID)   != 0,\r
+        (SystemContext.SystemContextX64->ExceptionData & IA32_PF_EC_RSVD) != 0,\r
+        (SystemContext.SystemContextX64->ExceptionData & IA32_PF_EC_US)   != 0,\r
+        (SystemContext.SystemContextX64->ExceptionData & IA32_PF_EC_WR)   != 0,\r
+        (SystemContext.SystemContextX64->ExceptionData & IA32_PF_EC_P)    != 0,\r
+        (SystemContext.SystemContextX64->ExceptionData & IA32_PF_EC_PK)   != 0,\r
+        (SystemContext.SystemContextX64->ExceptionData & IA32_PF_EC_SGX)  != 0\r
+        );\r
+    }\r
+    InternalPrintMessage ("\n");\r
+  }\r
   InternalPrintMessage (\r
     "RIP  - %016lx, CS  - %016lx, RFLAGS - %016lx\n",\r
     SystemContext.SystemContextX64->Rip,\r
     SystemContext.SystemContextX64->Cs,\r
     SystemContext.SystemContextX64->Rflags\r
     );\r
   InternalPrintMessage (\r
     "RIP  - %016lx, CS  - %016lx, RFLAGS - %016lx\n",\r
     SystemContext.SystemContextX64->Rip,\r
     SystemContext.SystemContextX64->Cs,\r
     SystemContext.SystemContextX64->Rflags\r
     );\r
-  if (mErrorCodeFlag & (1 << ExceptionType)) {\r
-    InternalPrintMessage (\r
-      "ExceptionData - %016lx\n",\r
-      SystemContext.SystemContextX64->ExceptionData\r
-      );\r
-  }\r
   InternalPrintMessage (\r
     "RAX  - %016lx, RCX - %016lx, RDX - %016lx\n",\r
     SystemContext.SystemContextX64->Rax,\r
   InternalPrintMessage (\r
     "RAX  - %016lx, RCX - %016lx, RDX - %016lx\n",\r
     SystemContext.SystemContextX64->Rax,\r
@@ -230,16 +240,23 @@ DumpCpuContent (
     "FXSAVE_STATE - %016lx\n",\r
     &SystemContext.SystemContextX64->FxSaveState\r
     );\r
     "FXSAVE_STATE - %016lx\n",\r
     &SystemContext.SystemContextX64->FxSaveState\r
     );\r
+}\r
 \r
 \r
+/**\r
+  Display CPU information.\r
+\r
+  @param ExceptionType  Exception type.\r
+  @param SystemContext  Pointer to EFI_SYSTEM_CONTEXT.\r
+**/\r
+VOID\r
+DumpImageAndCpuContent (\r
+  IN EFI_EXCEPTION_TYPE   ExceptionType,\r
+  IN EFI_SYSTEM_CONTEXT   SystemContext\r
+  )\r
+{\r
+  DumpCpuContext (ExceptionType, SystemContext);\r
   //\r
   //\r
-  // Find module image base and module entry point by RIP\r
+  // Dump module image base and module entry point by RIP\r
   //\r
   //\r
-  ImageBase = FindModuleImageBase (SystemContext.SystemContextX64->Rip, &EntryPoint);\r
-  if (ImageBase != 0) {\r
-    InternalPrintMessage (\r
-      " (ImageBase=%016lx, EntryPoint=%016lx) !!!!\n",\r
-      ImageBase,\r
-      EntryPoint\r
-      );\r
-  }\r
+  DumpModuleImageInfo (SystemContext.SystemContextX64->Rip);\r
 }\r
 }\r