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
= 0x20227d00;
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",
55 "#VC - VMM Communication",
58 #define EXCEPTION_KNOWN_NAME_NUM (sizeof (mExceptionNameStr) / sizeof (CHAR8 *))
61 Get ASCII format string exception name by exception type.
63 @param ExceptionType Exception type.
65 @return ASCII format string exception name.
69 IN EFI_EXCEPTION_TYPE ExceptionType
72 if ((UINTN
)ExceptionType
< EXCEPTION_KNOWN_NAME_NUM
) {
73 return mExceptionNameStr
[ExceptionType
];
75 return mExceptionReservedStr
;
80 Prints a message to the serial port.
82 @param Format Format string for the message to print.
83 @param ... Variable argument list whose contents are accessed
84 based on the format string specified by Format.
89 InternalPrintMessage (
90 IN CONST CHAR8
*Format
,
94 CHAR8 Buffer
[MAX_DEBUG_MESSAGE_LENGTH
];
98 // Convert the message to an ASCII String
100 VA_START (Marker
, Format
);
101 AsciiVSPrint (Buffer
, sizeof (Buffer
), Format
, Marker
);
105 // Send the print string to a Serial Port
107 SerialPortWrite ((UINT8
*)Buffer
, AsciiStrLen (Buffer
));
111 Find and display image base address and return image base and its entry point.
113 @param CurrentEip Current instruction pointer.
117 DumpModuleImageInfo (
126 Pe32Data
= PeCoffSearchImageBase (CurrentEip
);
128 InternalPrintMessage ("!!!! Can't find image information. !!!!\n");
131 // Find Image Base entry point
133 Status
= PeCoffLoaderGetEntryPoint ((VOID
*)Pe32Data
, &EntryPoint
);
134 if (EFI_ERROR (Status
)) {
138 InternalPrintMessage ("!!!! Find image based on IP(0x%x) ", CurrentEip
);
139 PdbPointer
= PeCoffLoaderGetPdbPointer ((VOID
*)Pe32Data
);
140 if (PdbPointer
!= NULL
) {
141 InternalPrintMessage ("%a", PdbPointer
);
143 InternalPrintMessage ("(No PDB) ");
146 InternalPrintMessage (
147 " (ImageBase=%016lp, EntryPoint=%016p) !!!!\n",
155 Read and save reserved vector information
157 @param[in] VectorInfo Pointer to reserved vector list.
158 @param[out] ReservedVector Pointer to reserved vector data buffer.
159 @param[in] VectorCount Vector number to be updated.
161 @return EFI_SUCCESS Read and save vector info successfully.
162 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
166 ReadAndVerifyVectorInfo (
167 IN EFI_VECTOR_HANDOFF_INFO
*VectorInfo
,
168 OUT RESERVED_VECTORS_DATA
*ReservedVector
,
172 while (VectorInfo
->Attribute
!= EFI_VECTOR_HANDOFF_LAST_ENTRY
) {
173 if (VectorInfo
->Attribute
> EFI_VECTOR_HANDOFF_HOOK_AFTER
) {
175 // If vector attrubute is invalid
177 return EFI_INVALID_PARAMETER
;
180 if (VectorInfo
->VectorNumber
< VectorCount
) {
181 ReservedVector
[VectorInfo
->VectorNumber
].Attribute
= VectorInfo
->Attribute
;