2 CPU Exception Handler Library common functions.
4 Copyright (c) 2012 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "CpuExceptionCommon.h"
12 // Error code flag indicating whether or not an error code will be
13 // pushed on the stack if an exception occurs.
15 // 1 means an error code will be pushed, otherwise 0
17 CONST UINT32 mErrorCodeFlag
= 0x00227d00;
20 // Define the maximum message length
22 #define MAX_DEBUG_MESSAGE_LENGTH 0x100
24 CONST CHAR8 mExceptionReservedStr
[] = "Reserved";
25 CONST CHAR8
*mExceptionNameStr
[] = {
31 "#BR - BOUND Range Exceeded",
32 "#UD - Invalid Opcode",
33 "#NM - Device Not Available",
35 "Coprocessor Segment Overrun",
37 "#NP - Segment Not Present",
38 "#SS - Stack Fault Fault",
39 "#GP - General Protection",
42 "#MF - x87 FPU Floating-Point Error",
43 "#AC - Alignment Check",
44 "#MC - Machine-Check",
45 "#XM - SIMD floating-point",
46 "#VE - Virtualization",
47 "#CP - Control Protection"
50 #define EXCEPTION_KNOWN_NAME_NUM (sizeof (mExceptionNameStr) / sizeof (CHAR8 *))
53 Get ASCII format string exception name by exception type.
55 @param ExceptionType Exception type.
57 @return ASCII format string exception name.
61 IN EFI_EXCEPTION_TYPE ExceptionType
64 if ((UINTN
) ExceptionType
< EXCEPTION_KNOWN_NAME_NUM
) {
65 return mExceptionNameStr
[ExceptionType
];
67 return mExceptionReservedStr
;
72 Prints a message to the serial port.
74 @param Format Format string for the message to print.
75 @param ... Variable argument list whose contents are accessed
76 based on the format string specified by Format.
81 InternalPrintMessage (
82 IN CONST CHAR8
*Format
,
86 CHAR8 Buffer
[MAX_DEBUG_MESSAGE_LENGTH
];
90 // Convert the message to an ASCII String
92 VA_START (Marker
, Format
);
93 AsciiVSPrint (Buffer
, sizeof (Buffer
), Format
, Marker
);
97 // Send the print string to a Serial Port
99 SerialPortWrite ((UINT8
*)Buffer
, AsciiStrLen (Buffer
));
103 Find and display image base address and return image base and its entry point.
105 @param CurrentEip Current instruction pointer.
109 DumpModuleImageInfo (
118 Pe32Data
= PeCoffSearchImageBase (CurrentEip
);
120 InternalPrintMessage ("!!!! Can't find image information. !!!!\n");
123 // Find Image Base entry point
125 Status
= PeCoffLoaderGetEntryPoint ((VOID
*) Pe32Data
, &EntryPoint
);
126 if (EFI_ERROR (Status
)) {
129 InternalPrintMessage ("!!!! Find image based on IP(0x%x) ", CurrentEip
);
130 PdbPointer
= PeCoffLoaderGetPdbPointer ((VOID
*) Pe32Data
);
131 if (PdbPointer
!= NULL
) {
132 InternalPrintMessage ("%a", PdbPointer
);
134 InternalPrintMessage ("(No PDB) " );
136 InternalPrintMessage (
137 " (ImageBase=%016lp, EntryPoint=%016p) !!!!\n",
145 Read and save reserved vector information
147 @param[in] VectorInfo Pointer to reserved vector list.
148 @param[out] ReservedVector Pointer to reserved vector data buffer.
149 @param[in] VectorCount Vector number to be updated.
151 @return EFI_SUCCESS Read and save vector info successfully.
152 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
156 ReadAndVerifyVectorInfo (
157 IN EFI_VECTOR_HANDOFF_INFO
*VectorInfo
,
158 OUT RESERVED_VECTORS_DATA
*ReservedVector
,
162 while (VectorInfo
->Attribute
!= EFI_VECTOR_HANDOFF_LAST_ENTRY
) {
163 if (VectorInfo
->Attribute
> EFI_VECTOR_HANDOFF_HOOK_AFTER
) {
165 // If vector attrubute is invalid
167 return EFI_INVALID_PARAMETER
;
169 if (VectorInfo
->VectorNumber
< VectorCount
) {
170 ReservedVector
[VectorInfo
->VectorNumber
].Attribute
= VectorInfo
->Attribute
;