2 CPU Exception Handler Library common functions.
4 Copyright (c) 2012 - 2017, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "CpuExceptionCommon.h"
18 // Error code flag indicating whether or not an error code will be
19 // pushed on the stack if an exception occurs.
21 // 1 means an error code will be pushed, otherwise 0
23 CONST UINT32 mErrorCodeFlag
= 0x00027d00;
26 // Define the maximum message length
28 #define MAX_DEBUG_MESSAGE_LENGTH 0x100
30 CONST CHAR8 mExceptionReservedStr
[] = "Reserved";
31 CONST CHAR8
*mExceptionNameStr
[] = {
37 "#BR - BOUND Range Exceeded",
38 "#UD - Invalid Opcode",
39 "#NM - Device Not Available",
41 "Coprocessor Segment Overrun",
43 "#NP - Segment Not Present",
44 "#SS - Stack Fault Fault",
45 "#GP - General Protection",
48 "#MF - x87 FPU Floating-Point Error",
49 "#AC - Alignment Check",
50 "#MC - Machine-Check",
51 "#XM - SIMD floating-point",
52 "#VE - Virtualization"
55 #define EXCEPTION_KNOWN_NAME_NUM (sizeof (mExceptionNameStr) / sizeof (CHAR8 *))
58 Get ASCII format string exception name by exception type.
60 @param ExceptionType Exception type.
62 @return ASCII format string exception name.
66 IN EFI_EXCEPTION_TYPE ExceptionType
69 if ((UINTN
) ExceptionType
< EXCEPTION_KNOWN_NAME_NUM
) {
70 return mExceptionNameStr
[ExceptionType
];
72 return mExceptionReservedStr
;
77 Prints a message to the serial port.
79 @param Format Format string for the message to print.
80 @param ... Variable argument list whose contents are accessed
81 based on the format string specified by Format.
86 InternalPrintMessage (
87 IN CONST CHAR8
*Format
,
91 CHAR8 Buffer
[MAX_DEBUG_MESSAGE_LENGTH
];
95 // Convert the message to an ASCII String
97 VA_START (Marker
, Format
);
98 AsciiVSPrint (Buffer
, sizeof (Buffer
), Format
, Marker
);
102 // Send the print string to a Serial Port
104 SerialPortWrite ((UINT8
*)Buffer
, AsciiStrLen (Buffer
));
108 Find and display image base address and return image base and its entry point.
110 @param CurrentEip Current instruction pointer.
114 DumpModuleImageInfo (
123 Pe32Data
= PeCoffSearchImageBase (CurrentEip
);
125 InternalPrintMessage ("!!!! Can't find image information. !!!!\n");
128 // Find Image Base entry point
130 Status
= PeCoffLoaderGetEntryPoint ((VOID
*) Pe32Data
, &EntryPoint
);
131 if (EFI_ERROR (Status
)) {
134 InternalPrintMessage ("!!!! Find image based on IP(0x%x) ", CurrentEip
);
135 PdbPointer
= PeCoffLoaderGetPdbPointer ((VOID
*) Pe32Data
);
136 if (PdbPointer
!= NULL
) {
137 InternalPrintMessage ("%a", PdbPointer
);
139 InternalPrintMessage ("(No PDB) " );
141 InternalPrintMessage (
142 " (ImageBase=%016lp, EntryPoint=%016p) !!!!\n",
150 Read and save reserved vector information
152 @param[in] VectorInfo Pointer to reserved vector list.
153 @param[out] ReservedVector Pointer to reserved vector data buffer.
154 @param[in] VectorCount Vector number to be updated.
156 @return EFI_SUCCESS Read and save vector info successfully.
157 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
161 ReadAndVerifyVectorInfo (
162 IN EFI_VECTOR_HANDOFF_INFO
*VectorInfo
,
163 OUT RESERVED_VECTORS_DATA
*ReservedVector
,
167 while (VectorInfo
->Attribute
!= EFI_VECTOR_HANDOFF_LAST_ENTRY
) {
168 if (VectorInfo
->Attribute
> EFI_VECTOR_HANDOFF_HOOK_AFTER
) {
170 // If vector attrubute is invalid
172 return EFI_INVALID_PARAMETER
;
174 if (VectorInfo
->VectorNumber
< VectorCount
) {
175 ReservedVector
[VectorInfo
->VectorNumber
].Attribute
= VectorInfo
->Attribute
;