TianoCore EDK2 master
Loading...
Searching...
No Matches
CpuExceptionCommon.c
Go to the documentation of this file.
1
10
11//
12// Error code flag indicating whether or not an error code will be
13// pushed on the stack if an exception occurs.
14//
15// 1 means an error code will be pushed, otherwise 0
16//
17CONST UINT32 mErrorCodeFlag = 0x20227d00;
18
19//
20// Define the maximum message length
21//
22#define MAX_DEBUG_MESSAGE_LENGTH 0x100
23
24CONST CHAR8 mExceptionReservedStr[] = "Reserved";
25CONST CHAR8 *mExceptionNameStr[] = {
26 "#DE - Divide Error",
27 "#DB - Debug",
28 "NMI Interrupt",
29 "#BP - Breakpoint",
30 "#OF - Overflow",
31 "#BR - BOUND Range Exceeded",
32 "#UD - Invalid Opcode",
33 "#NM - Device Not Available",
34 "#DF - Double Fault",
35 "Coprocessor Segment Overrun",
36 "#TS - Invalid TSS",
37 "#NP - Segment Not Present",
38 "#SS - Stack Fault Fault",
39 "#GP - General Protection",
40 "#PF - Page-Fault",
41 "Reserved",
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",
48 "Reserved",
49 "Reserved",
50 "Reserved",
51 "Reserved",
52 "Reserved",
53 "Reserved",
54 "Reserved",
55 "#VC - VMM Communication",
56};
57
58#define EXCEPTION_KNOWN_NAME_NUM (sizeof (mExceptionNameStr) / sizeof (CHAR8 *))
59
67CONST CHAR8 *
69 IN EFI_EXCEPTION_TYPE ExceptionType
70 )
71{
72 if ((UINTN)ExceptionType < EXCEPTION_KNOWN_NAME_NUM) {
73 return mExceptionNameStr[ExceptionType];
74 } else {
75 return mExceptionReservedStr;
76 }
77}
78
87VOID
88EFIAPI
90 IN CONST CHAR8 *Format,
91 ...
92 )
93{
94 CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];
95 VA_LIST Marker;
96
97 //
98 // Convert the message to an ASCII String
99 //
100 VA_START (Marker, Format);
101 AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);
102 VA_END (Marker);
103
104 //
105 // Send the print string to a Serial Port
106 //
107 SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));
108}
109
116VOID
118 IN UINTN CurrentEip
119 )
120{
121 EFI_STATUS Status;
122 UINTN Pe32Data;
123 VOID *PdbPointer;
124 VOID *EntryPoint;
125
126 Pe32Data = PeCoffSearchImageBase (CurrentEip);
127 if (Pe32Data == 0) {
128 InternalPrintMessage ("!!!! Can't find image information. !!!!\n");
129 } else {
130 //
131 // Find Image Base entry point
132 //
133 Status = PeCoffLoaderGetEntryPoint ((VOID *)Pe32Data, &EntryPoint);
134 if (EFI_ERROR (Status)) {
135 EntryPoint = NULL;
136 }
137
138 InternalPrintMessage ("!!!! Find image based on IP(0x%x) ", CurrentEip);
139 PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)Pe32Data);
140 if (PdbPointer != NULL) {
141 InternalPrintMessage ("%a", PdbPointer);
142 } else {
143 InternalPrintMessage ("(No PDB) ");
144 }
145
147 " (ImageBase=%016lp, EntryPoint=%016p) !!!!\n",
148 (VOID *)Pe32Data,
149 EntryPoint
150 );
151 }
152}
153
167 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo,
168 OUT RESERVED_VECTORS_DATA *ReservedVector,
169 IN UINTN VectorCount
170 )
171{
172 while (VectorInfo->Attribute != EFI_VECTOR_HANDOFF_LAST_ENTRY) {
173 if (VectorInfo->Attribute > EFI_VECTOR_HANDOFF_HOOK_AFTER) {
174 //
175 // If vector attrubute is invalid
176 //
177 return EFI_INVALID_PARAMETER;
178 }
179
180 if (VectorInfo->VectorNumber < VectorCount) {
181 ReservedVector[VectorInfo->VectorNumber].Attribute = VectorInfo->Attribute;
182 }
183
184 VectorInfo++;
185 }
186
187 return EFI_SUCCESS;
188}
UINT64 UINTN
UINTN EFIAPI SerialPortWrite(IN UINT8 *Buffer, IN UINTN NumberOfBytes)
Definition: SerialPortLib.c:52
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define VA_START(Marker, Parameter)
Definition: Base.h:661
CHAR8 * VA_LIST
Definition: Base.h:643
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define VA_END(Marker)
Definition: Base.h:691
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
Definition: String.c:633
VOID DumpModuleImageInfo(IN UINTN CurrentEip)
EFI_STATUS ReadAndVerifyVectorInfo(IN EFI_VECTOR_HANDOFF_INFO *VectorInfo, OUT RESERVED_VECTORS_DATA *ReservedVector, IN UINTN VectorCount)
CONST CHAR8 * GetExceptionNameStr(IN EFI_EXCEPTION_TYPE ExceptionType)
VOID EFIAPI InternalPrintMessage(IN CONST CHAR8 *Format,...)
UINTN EFIAPI AsciiVSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString, IN VA_LIST Marker)
Definition: PrintLib.c:702
INTN EFI_EXCEPTION_TYPE
Definition: DebugSupport.h:35
UINTN EFIAPI PeCoffSearchImageBase(IN UINTN Address)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112