]>
Commit | Line | Data |
---|---|---|
8f07f895 | 1 | /** @file\r |
2 | Common header file for CPU Exception Handler Library.\r | |
3 | \r | |
2c5873fe | 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 | #ifndef _CPU_EXCEPTION_COMMON_H_\r | |
16 | #define _CPU_EXCEPTION_COMMON_H_\r | |
17 | \r | |
e41aad15 JF |
18 | #include <Ppi/VectorHandoffInfo.h>\r |
19 | #include <Protocol/Cpu.h>\r | |
8f07f895 | 20 | #include <Library/BaseLib.h>\r |
21 | #include <Library/SerialPortLib.h>\r | |
22 | #include <Library/PrintLib.h>\r | |
23 | #include <Library/LocalApicLib.h>\r | |
24 | #include <Library/PeCoffGetEntryPointLib.h>\r | |
e41aad15 JF |
25 | #include <Library/BaseMemoryLib.h>\r |
26 | #include <Library/SynchronizationLib.h>\r | |
27 | \r | |
28 | #define CPU_EXCEPTION_NUM 32\r | |
29 | #define CPU_INTERRUPT_NUM 256\r | |
30 | #define HOOKAFTER_STUB_SIZE 16\r | |
31 | \r | |
32 | #include "ArchInterruptDefs.h"\r | |
8f07f895 | 33 | \r |
a81abf16 JF |
34 | #define CPU_EXCEPTION_HANDLER_LIB_HOB_GUID \\r |
35 | { \\r | |
36 | 0xb21d9148, 0x9211, 0x4d8f, { 0xad, 0xd3, 0x66, 0xb1, 0x89, 0xc9, 0x2c, 0x83 } \\r | |
37 | }\r | |
38 | \r | |
8f07f895 | 39 | //\r |
40 | // Record exception handler information\r | |
41 | //\r | |
42 | typedef struct {\r | |
43 | UINTN ExceptionStart;\r | |
44 | UINTN ExceptionStubHeaderSize;\r | |
e41aad15 | 45 | UINTN HookAfterStubHeaderStart;\r |
8f07f895 | 46 | } EXCEPTION_HANDLER_TEMPLATE_MAP;\r |
47 | \r | |
2c5873fe JF |
48 | typedef struct {\r |
49 | UINTN IdtEntryCount;\r | |
50 | SPIN_LOCK DisplayMessageSpinLock;\r | |
51 | RESERVED_VECTORS_DATA *ReservedVectors;\r | |
52 | EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;\r | |
53 | } EXCEPTION_HANDLER_DATA;\r | |
54 | \r | |
e41aad15 JF |
55 | extern CONST UINT32 mErrorCodeFlag;\r |
56 | extern CONST UINTN mImageAlignSize;\r | |
57 | extern CONST UINTN mDoFarReturnFlag;\r | |
58 | extern RESERVED_VECTORS_DATA *mReservedVectors;\r | |
8f07f895 | 59 | \r |
60 | /**\r | |
61 | Return address map of exception handler template so that C code can generate\r | |
62 | exception tables.\r | |
63 | \r | |
64 | @param AddressMap Pointer to a buffer where the address map is returned.\r | |
65 | **/\r | |
66 | VOID\r | |
67 | EFIAPI\r | |
e41aad15 | 68 | AsmGetTemplateAddressMap (\r |
8f07f895 | 69 | OUT EXCEPTION_HANDLER_TEMPLATE_MAP *AddressMap\r |
70 | );\r | |
71 | \r | |
72 | /**\r | |
e41aad15 JF |
73 | Return address map of exception handler template so that C code can generate\r |
74 | exception tables.\r | |
75 | \r | |
76 | @param IdtEntry Pointer to IDT entry to be updated.\r | |
77 | @param InterruptHandler IDT handler value.\r | |
8f07f895 | 78 | \r |
79 | **/\r | |
80 | VOID\r | |
e41aad15 JF |
81 | ArchUpdateIdtEntry (\r |
82 | IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry,\r | |
83 | IN UINTN InterruptHandler\r | |
84 | );\r | |
85 | \r | |
86 | /**\r | |
87 | Read IDT handler value from IDT entry.\r | |
88 | \r | |
89 | @param IdtEntry Pointer to IDT entry to be read.\r | |
90 | \r | |
91 | **/\r | |
92 | UINTN\r | |
93 | ArchGetIdtHandler (\r | |
94 | IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry\r | |
8f07f895 | 95 | );\r |
96 | \r | |
97 | /**\r | |
98 | Prints a message to the serial port.\r | |
99 | \r | |
100 | @param Format Format string for the message to print.\r | |
101 | @param ... Variable argument list whose contents are accessed \r | |
102 | based on the format string specified by Format.\r | |
103 | \r | |
104 | **/\r | |
105 | VOID\r | |
106 | EFIAPI\r | |
107 | InternalPrintMessage (\r | |
108 | IN CONST CHAR8 *Format,\r | |
109 | ...\r | |
110 | );\r | |
111 | \r | |
112 | /**\r | |
113 | Find and display image base address and return image base and its entry point.\r | |
114 | \r | |
a9c7ab95 | 115 | @param CurrentEip Current instruction pointer.\r |
116 | @param EntryPoint Return module entry point if module header is found.\r | |
117 | \r | |
118 | @return !0 Image base address.\r | |
119 | @return 0 Image header cannot be found.\r | |
8f07f895 | 120 | **/\r |
121 | UINTN \r | |
122 | FindModuleImageBase (\r | |
123 | IN UINTN CurrentEip,\r | |
124 | OUT UINTN *EntryPoint\r | |
125 | );\r | |
126 | \r | |
127 | /**\r | |
128 | Display CPU information.\r | |
129 | \r | |
3f25e6ea | 130 | @param ExceptionType Exception type.\r |
8f07f895 | 131 | @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r |
132 | **/\r | |
133 | VOID\r | |
134 | DumpCpuContent (\r | |
e41aad15 | 135 | IN EFI_EXCEPTION_TYPE ExceptionType,\r |
8f07f895 | 136 | IN EFI_SYSTEM_CONTEXT SystemContext\r |
137 | );\r | |
138 | \r | |
e41aad15 JF |
139 | /**\r |
140 | Internal worker function to initialize exception handler.\r | |
141 | \r | |
ab95e54d JF |
142 | @param[in] VectorInfo Pointer to reserved vector list.\r |
143 | @param[in, out] ExceptionHandlerData Pointer to exception handler data.\r | |
e41aad15 JF |
144 | \r |
145 | @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized \r | |
146 | with default exception handlers.\r | |
147 | @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r | |
148 | @retval EFI_UNSUPPORTED This function is not supported.\r | |
149 | \r | |
150 | **/\r | |
151 | EFI_STATUS\r | |
152 | InitializeCpuExceptionHandlersWorker (\r | |
ab95e54d JF |
153 | IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,\r |
154 | IN OUT EXCEPTION_HANDLER_DATA *ExceptionHandlerData\r | |
e41aad15 JF |
155 | );\r |
156 | \r | |
157 | /**\r | |
158 | Registers a function to be called from the processor interrupt handler.\r | |
159 | \r | |
670f13af JF |
160 | @param[in] InterruptType Defines which interrupt or exception to hook.\r |
161 | @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called\r | |
162 | when a processor interrupt occurs. If this parameter is NULL, then the handler\r | |
163 | will be uninstalled\r | |
164 | @param[in] ExceptionHandlerData Pointer to exception handler data.\r | |
e41aad15 JF |
165 | \r |
166 | @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.\r | |
167 | @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was\r | |
168 | previously installed.\r | |
169 | @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not\r | |
170 | previously installed.\r | |
171 | @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,\r | |
172 | or this function is not supported.\r | |
3f25e6ea | 173 | **/\r |
e41aad15 JF |
174 | EFI_STATUS\r |
175 | RegisterCpuInterruptHandlerWorker (\r | |
176 | IN EFI_EXCEPTION_TYPE InterruptType,\r | |
670f13af JF |
177 | IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler,\r |
178 | IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData\r | |
e41aad15 JF |
179 | );\r |
180 | \r | |
181 | /**\r | |
182 | Internal worker function to update IDT entries accordling to vector attributes.\r | |
183 | \r | |
9db15f81 JF |
184 | @param[in] IdtTable Pointer to IDT table.\r |
185 | @param[in] TemplateMap Pointer to a buffer where the address map is\r | |
186 | returned.\r | |
187 | @param[in] ExceptionHandlerData Pointer to exception handler data.\r | |
e41aad15 JF |
188 | \r |
189 | **/\r | |
190 | VOID\r | |
191 | UpdateIdtTable (\r | |
192 | IN IA32_IDT_GATE_DESCRIPTOR *IdtTable,\r | |
193 | IN EXCEPTION_HANDLER_TEMPLATE_MAP *TemplateMap,\r | |
9db15f81 | 194 | IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData\r |
e41aad15 JF |
195 | );\r |
196 | \r | |
197 | /**\r | |
198 | Save CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.\r | |
199 | \r | |
81b21fc2 JF |
200 | @param[in] ExceptionType Exception type.\r |
201 | @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r | |
202 | @param[in] ExceptionHandlerData Pointer to exception handler data.\r | |
e41aad15 JF |
203 | **/\r |
204 | VOID\r | |
205 | ArchSaveExceptionContext (\r | |
81b21fc2 JF |
206 | IN UINTN ExceptionType,\r |
207 | IN EFI_SYSTEM_CONTEXT SystemContext,\r | |
208 | IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData\r | |
e41aad15 JF |
209 | );\r |
210 | \r | |
211 | /**\r | |
212 | Restore CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.\r | |
213 | \r | |
214 | @param[in] ExceptionType Exception type.\r | |
215 | @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r | |
216 | \r | |
217 | **/\r | |
218 | VOID\r | |
219 | ArchRestoreExceptionContext (\r | |
220 | IN UINTN ExceptionType,\r | |
221 | IN EFI_SYSTEM_CONTEXT SystemContext \r | |
222 | );\r | |
223 | \r | |
224 | /**\r | |
07da1ac8 | 225 | Fix up the vector number and function address in the vector code.\r |
e41aad15 | 226 | \r |
07da1ac8 AF |
227 | @param[in] NewVectorAddr New vector handler address.\r |
228 | @param[in] VectorNum Index of vector.\r | |
229 | @param[in] OldVectorAddr Old vector handler address.\r | |
e41aad15 JF |
230 | \r |
231 | **/\r | |
232 | VOID\r | |
233 | EFIAPI\r | |
234 | AsmVectorNumFixup (\r | |
07da1ac8 AF |
235 | IN VOID *NewVectorAddr,\r |
236 | IN UINT8 VectorNum,\r | |
237 | IN VOID *OldVectorAddr\r | |
e41aad15 JF |
238 | );\r |
239 | \r | |
240 | /**\r | |
241 | Read and save reserved vector information\r | |
242 | \r | |
243 | @param[in] VectorInfo Pointer to reserved vector list.\r | |
244 | @param[out] ReservedVector Pointer to reserved vector data buffer.\r | |
245 | @param[in] VectorCount Vector number to be updated.\r | |
246 | \r | |
247 | @return EFI_SUCCESS Read and save vector info successfully.\r | |
248 | @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r | |
249 | \r | |
250 | **/\r | |
251 | EFI_STATUS\r | |
252 | ReadAndVerifyVectorInfo (\r | |
253 | IN EFI_VECTOR_HANDOFF_INFO *VectorInfo,\r | |
254 | OUT RESERVED_VECTORS_DATA *ReservedVector,\r | |
255 | IN UINTN VectorCount\r | |
256 | );\r | |
257 | \r | |
a51ee144 JF |
258 | /**\r |
259 | Get ASCII format string exception name by exception type.\r | |
260 | \r | |
261 | @param ExceptionType Exception type.\r | |
262 | \r | |
263 | @return ASCII format string exception name.\r | |
264 | **/\r | |
265 | CONST CHAR8 *\r | |
266 | GetExceptionNameStr (\r | |
267 | IN EFI_EXCEPTION_TYPE ExceptionType\r | |
268 | );\r | |
269 | \r | |
44ecbc28 JF |
270 | /**\r |
271 | Internal worker function for common exception handler.\r | |
272 | \r | |
273 | @param ExceptionType Exception type.\r | |
274 | @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r | |
275 | @param ExceptionHandlerData Pointer to exception handler data.\r | |
276 | **/\r | |
277 | VOID\r | |
278 | CommonExceptionHandlerWorker (\r | |
279 | IN EFI_EXCEPTION_TYPE ExceptionType, \r | |
280 | IN EFI_SYSTEM_CONTEXT SystemContext,\r | |
281 | IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData\r | |
282 | );\r | |
283 | \r | |
8f07f895 | 284 | #endif\r |
e41aad15 | 285 | \r |