]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | CPU Exception Handler Library common functions.\r | |
3 | \r | |
4 | Copyright (c) 2012 - 2019, Intel Corporation. All rights reserved.<BR>\r | |
5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
6 | \r | |
7 | **/\r | |
8 | \r | |
9 | #include "CpuExceptionCommon.h"\r | |
10 | \r | |
11 | //\r | |
12 | // Error code flag indicating whether or not an error code will be\r | |
13 | // pushed on the stack if an exception occurs.\r | |
14 | //\r | |
15 | // 1 means an error code will be pushed, otherwise 0\r | |
16 | //\r | |
17 | CONST UINT32 mErrorCodeFlag = 0x20227d00;\r | |
18 | \r | |
19 | //\r | |
20 | // Define the maximum message length\r | |
21 | //\r | |
22 | #define MAX_DEBUG_MESSAGE_LENGTH 0x100\r | |
23 | \r | |
24 | CONST CHAR8 mExceptionReservedStr[] = "Reserved";\r | |
25 | CONST CHAR8 *mExceptionNameStr[] = {\r | |
26 | "#DE - Divide Error",\r | |
27 | "#DB - Debug",\r | |
28 | "NMI Interrupt",\r | |
29 | "#BP - Breakpoint",\r | |
30 | "#OF - Overflow",\r | |
31 | "#BR - BOUND Range Exceeded",\r | |
32 | "#UD - Invalid Opcode",\r | |
33 | "#NM - Device Not Available",\r | |
34 | "#DF - Double Fault",\r | |
35 | "Coprocessor Segment Overrun",\r | |
36 | "#TS - Invalid TSS",\r | |
37 | "#NP - Segment Not Present",\r | |
38 | "#SS - Stack Fault Fault",\r | |
39 | "#GP - General Protection",\r | |
40 | "#PF - Page-Fault",\r | |
41 | "Reserved",\r | |
42 | "#MF - x87 FPU Floating-Point Error",\r | |
43 | "#AC - Alignment Check",\r | |
44 | "#MC - Machine-Check",\r | |
45 | "#XM - SIMD floating-point",\r | |
46 | "#VE - Virtualization",\r | |
47 | "#CP - Control Protection",\r | |
48 | "Reserved",\r | |
49 | "Reserved",\r | |
50 | "Reserved",\r | |
51 | "Reserved",\r | |
52 | "Reserved",\r | |
53 | "Reserved",\r | |
54 | "Reserved",\r | |
55 | "#VC - VMM Communication",\r | |
56 | };\r | |
57 | \r | |
58 | #define EXCEPTION_KNOWN_NAME_NUM (sizeof (mExceptionNameStr) / sizeof (CHAR8 *))\r | |
59 | \r | |
60 | /**\r | |
61 | Get ASCII format string exception name by exception type.\r | |
62 | \r | |
63 | @param ExceptionType Exception type.\r | |
64 | \r | |
65 | @return ASCII format string exception name.\r | |
66 | **/\r | |
67 | CONST CHAR8 *\r | |
68 | GetExceptionNameStr (\r | |
69 | IN EFI_EXCEPTION_TYPE ExceptionType\r | |
70 | )\r | |
71 | {\r | |
72 | if ((UINTN)ExceptionType < EXCEPTION_KNOWN_NAME_NUM) {\r | |
73 | return mExceptionNameStr[ExceptionType];\r | |
74 | } else {\r | |
75 | return mExceptionReservedStr;\r | |
76 | }\r | |
77 | }\r | |
78 | \r | |
79 | /**\r | |
80 | Prints a message to the serial port.\r | |
81 | \r | |
82 | @param Format Format string for the message to print.\r | |
83 | @param ... Variable argument list whose contents are accessed\r | |
84 | based on the format string specified by Format.\r | |
85 | \r | |
86 | **/\r | |
87 | VOID\r | |
88 | EFIAPI\r | |
89 | InternalPrintMessage (\r | |
90 | IN CONST CHAR8 *Format,\r | |
91 | ...\r | |
92 | )\r | |
93 | {\r | |
94 | CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r | |
95 | VA_LIST Marker;\r | |
96 | \r | |
97 | //\r | |
98 | // Convert the message to an ASCII String\r | |
99 | //\r | |
100 | VA_START (Marker, Format);\r | |
101 | AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);\r | |
102 | VA_END (Marker);\r | |
103 | \r | |
104 | //\r | |
105 | // Send the print string to a Serial Port\r | |
106 | //\r | |
107 | SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));\r | |
108 | }\r | |
109 | \r | |
110 | /**\r | |
111 | Find and display image base address and return image base and its entry point.\r | |
112 | \r | |
113 | @param CurrentEip Current instruction pointer.\r | |
114 | \r | |
115 | **/\r | |
116 | VOID\r | |
117 | DumpModuleImageInfo (\r | |
118 | IN UINTN CurrentEip\r | |
119 | )\r | |
120 | {\r | |
121 | EFI_STATUS Status;\r | |
122 | UINTN Pe32Data;\r | |
123 | VOID *PdbPointer;\r | |
124 | VOID *EntryPoint;\r | |
125 | \r | |
126 | Pe32Data = PeCoffSearchImageBase (CurrentEip);\r | |
127 | if (Pe32Data == 0) {\r | |
128 | InternalPrintMessage ("!!!! Can't find image information. !!!!\n");\r | |
129 | } else {\r | |
130 | //\r | |
131 | // Find Image Base entry point\r | |
132 | //\r | |
133 | Status = PeCoffLoaderGetEntryPoint ((VOID *)Pe32Data, &EntryPoint);\r | |
134 | if (EFI_ERROR (Status)) {\r | |
135 | EntryPoint = NULL;\r | |
136 | }\r | |
137 | \r | |
138 | InternalPrintMessage ("!!!! Find image based on IP(0x%x) ", CurrentEip);\r | |
139 | PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)Pe32Data);\r | |
140 | if (PdbPointer != NULL) {\r | |
141 | InternalPrintMessage ("%a", PdbPointer);\r | |
142 | } else {\r | |
143 | InternalPrintMessage ("(No PDB) ");\r | |
144 | }\r | |
145 | \r | |
146 | InternalPrintMessage (\r | |
147 | " (ImageBase=%016lp, EntryPoint=%016p) !!!!\n",\r | |
148 | (VOID *)Pe32Data,\r | |
149 | EntryPoint\r | |
150 | );\r | |
151 | }\r | |
152 | }\r | |
153 | \r | |
154 | /**\r | |
155 | Read and save reserved vector information\r | |
156 | \r | |
157 | @param[in] VectorInfo Pointer to reserved vector list.\r | |
158 | @param[out] ReservedVector Pointer to reserved vector data buffer.\r | |
159 | @param[in] VectorCount Vector number to be updated.\r | |
160 | \r | |
161 | @return EFI_SUCCESS Read and save vector info successfully.\r | |
162 | @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r | |
163 | \r | |
164 | **/\r | |
165 | EFI_STATUS\r | |
166 | ReadAndVerifyVectorInfo (\r | |
167 | IN EFI_VECTOR_HANDOFF_INFO *VectorInfo,\r | |
168 | OUT RESERVED_VECTORS_DATA *ReservedVector,\r | |
169 | IN UINTN VectorCount\r | |
170 | )\r | |
171 | {\r | |
172 | while (VectorInfo->Attribute != EFI_VECTOR_HANDOFF_LAST_ENTRY) {\r | |
173 | if (VectorInfo->Attribute > EFI_VECTOR_HANDOFF_HOOK_AFTER) {\r | |
174 | //\r | |
175 | // If vector attrubute is invalid\r | |
176 | //\r | |
177 | return EFI_INVALID_PARAMETER;\r | |
178 | }\r | |
179 | \r | |
180 | if (VectorInfo->VectorNumber < VectorCount) {\r | |
181 | ReservedVector[VectorInfo->VectorNumber].Attribute = VectorInfo->Attribute;\r | |
182 | }\r | |
183 | \r | |
184 | VectorInfo++;\r | |
185 | }\r | |
186 | \r | |
187 | return EFI_SUCCESS;\r | |
188 | }\r |