/** @file\r
CPU Exception Handler Library common functions.\r
\r
- Copyright (c) 2012 - 2014, 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
- 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
+ Copyright (c) 2012 - 2019, Intel Corporation. All rights reserved.<BR>\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
//\r
// 1 means an error code will be pushed, otherwise 0\r
//\r
-CONST UINT32 mErrorCodeFlag = 0x00027d00;\r
-RESERVED_VECTORS_DATA *mReservedVectors = NULL;\r
+CONST UINT32 mErrorCodeFlag = 0x00227d00;\r
\r
//\r
-// Define the maximum message length \r
+// Define the maximum message length\r
//\r
#define MAX_DEBUG_MESSAGE_LENGTH 0x100\r
\r
+CONST CHAR8 mExceptionReservedStr[] = "Reserved";\r
+CONST CHAR8 *mExceptionNameStr[] = {\r
+ "#DE - Divide Error",\r
+ "#DB - Debug",\r
+ "NMI Interrupt",\r
+ "#BP - Breakpoint",\r
+ "#OF - Overflow",\r
+ "#BR - BOUND Range Exceeded",\r
+ "#UD - Invalid Opcode",\r
+ "#NM - Device Not Available",\r
+ "#DF - Double Fault",\r
+ "Coprocessor Segment Overrun",\r
+ "#TS - Invalid TSS",\r
+ "#NP - Segment Not Present",\r
+ "#SS - Stack Fault Fault",\r
+ "#GP - General Protection",\r
+ "#PF - Page-Fault",\r
+ "Reserved",\r
+ "#MF - x87 FPU Floating-Point Error",\r
+ "#AC - Alignment Check",\r
+ "#MC - Machine-Check",\r
+ "#XM - SIMD floating-point",\r
+ "#VE - Virtualization",\r
+ "#CP - Control Protection"\r
+};\r
+\r
+#define EXCEPTION_KNOWN_NAME_NUM (sizeof (mExceptionNameStr) / sizeof (CHAR8 *))\r
+\r
+/**\r
+ Get ASCII format string exception name by exception type.\r
+\r
+ @param ExceptionType Exception type.\r
+\r
+ @return ASCII format string exception name.\r
+**/\r
+CONST CHAR8 *\r
+GetExceptionNameStr (\r
+ IN EFI_EXCEPTION_TYPE ExceptionType\r
+ )\r
+{\r
+ if ((UINTN) ExceptionType < EXCEPTION_KNOWN_NAME_NUM) {\r
+ return mExceptionNameStr[ExceptionType];\r
+ } else {\r
+ return mExceptionReservedStr;\r
+ }\r
+}\r
+\r
/**\r
Prints a message to the serial port.\r
\r
@param Format Format string for the message to print.\r
- @param ... Variable argument list whose contents are accessed \r
+ @param ... Variable argument list whose contents are accessed\r
based on the format string specified by Format.\r
\r
**/\r
VA_END (Marker);\r
\r
//\r
- // Send the print string to a Serial Port \r
+ // Send the print string to a Serial Port\r
//\r
SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));\r
}\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 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 = PeCoffSearchImageBase (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
- // \r
- Pe32Data -= mImageAlignSize;\r
- }\r
-\r
- if (Pe32Data != 0) {\r
+ // Find Image Base entry point\r
+ //\r
+ Status = PeCoffLoaderGetEntryPoint ((VOID *) Pe32Data, &EntryPoint);\r
+ if (EFI_ERROR (Status)) {\r
+ EntryPoint = NULL;\r
+ }\r
+ InternalPrintMessage ("!!!! Find image based on IP(0x%x) ", CurrentEip);\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
Read and save reserved vector information\r
- \r
+\r
@param[in] VectorInfo Pointer to reserved vector list.\r
@param[out] ReservedVector Pointer to reserved vector data buffer.\r
@param[in] VectorCount Vector number to be updated.\r
- \r
+\r
@return EFI_SUCCESS Read and save vector info successfully.\r
@retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
\r
VectorInfo ++;\r
}\r
return EFI_SUCCESS;\r
-}
\ No newline at end of file
+}\r