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