\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 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
-UINTN\r
-FindModuleImageBase (\r
- IN UINTN CurrentEip,\r
- OUT UINTN *EntryPoint\r
+VOID \r
+DumpModuleImageInfo (\r
+ IN UINTN CurrentEip\r
)\r
{\r
+ EFI_STATUS Status;\r
UINTN Pe32Data;\r
- EFI_IMAGE_DOS_HEADER *DosHdr;\r
- EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;\r
VOID *PdbPointer;\r
+ VOID *EntryPoint;\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
- // Not found the image base, check the previous aligned address\r
+ // Find Image Base entry point\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
- } 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
- return Pe32Data;\r
}\r
\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
#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
+// 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
} EXCEPTION_HANDLER_DATA;\r
\r
extern CONST UINT32 mErrorCodeFlag;\r
-extern CONST UINTN mImageAlignSize;\r
extern CONST UINTN mDoFarReturnFlag;\r
\r
/**\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
- @return !0 Image base address.\r
- @return 0 Image header cannot be found.\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
@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
/** @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
\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
/** @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
}\r
\r
/**\r
- Display CPU information.\r
+ Display processor context.\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
-DumpCpuContent (\r
+EFIAPI\r
+DumpCpuContext (\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
-\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
- 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
"FXSAVE_STATE - %08x\n",\r
&SystemContext.SystemContextIa32->FxSaveState\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
- // Find module image base and module entry point by RIP\r
+ // Dump module image base and module entry point by EIP\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
/** @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
#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
/** @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
//\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
/** @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
#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
//\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
/** @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
//\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
/** @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
@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
- 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
-\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
- 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
"FXSAVE_STATE - %016lx\n",\r
&SystemContext.SystemContextX64->FxSaveState\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
- // Find module image base and module entry point by RIP\r
+ // Dump module image base and module entry point by RIP\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