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