]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
UefiCpuPkg/ExceptionLib: Import PeiCpuExceptionHandlerLib module
[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
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
42typedef 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
48typedef 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
55extern CONST UINT32 mErrorCodeFlag;\r
56extern CONST UINTN mImageAlignSize;\r
57extern CONST UINTN mDoFarReturnFlag;\r
58extern 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
66VOID\r
67EFIAPI\r
e41aad15 68AsmGetTemplateAddressMap (\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
80VOID\r
e41aad15
JF
81ArchUpdateIdtEntry (\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
92UINTN\r
93ArchGetIdtHandler (\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
105VOID\r
106EFIAPI\r
107InternalPrintMessage (\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
121UINTN \r
122FindModuleImageBase (\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
133VOID\r
134DumpCpuContent (\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
151EFI_STATUS\r
152InitializeCpuExceptionHandlersWorker (\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
174EFI_STATUS\r
175RegisterCpuInterruptHandlerWorker (\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
190VOID\r
191UpdateIdtTable (\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
200 @param[in] ExceptionType Exception type.\r
201 @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r
202\r
203**/\r
204VOID\r
205ArchSaveExceptionContext (\r
206 IN UINTN ExceptionType,\r
207 IN EFI_SYSTEM_CONTEXT SystemContext \r
208 );\r
209\r
210/**\r
211 Restore CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.\r
212\r
213 @param[in] ExceptionType Exception type.\r
214 @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r
215\r
216**/\r
217VOID\r
218ArchRestoreExceptionContext (\r
219 IN UINTN ExceptionType,\r
220 IN EFI_SYSTEM_CONTEXT SystemContext \r
221 );\r
222\r
223/**\r
07da1ac8 224 Fix up the vector number and function address in the vector code.\r
e41aad15 225 \r
07da1ac8
AF
226 @param[in] NewVectorAddr New vector handler address.\r
227 @param[in] VectorNum Index of vector.\r
228 @param[in] OldVectorAddr Old vector handler address.\r
e41aad15
JF
229\r
230**/\r
231VOID\r
232EFIAPI\r
233AsmVectorNumFixup (\r
07da1ac8
AF
234 IN VOID *NewVectorAddr,\r
235 IN UINT8 VectorNum,\r
236 IN VOID *OldVectorAddr\r
e41aad15
JF
237 );\r
238\r
239/**\r
240 Read and save reserved vector information\r
241 \r
242 @param[in] VectorInfo Pointer to reserved vector list.\r
243 @param[out] ReservedVector Pointer to reserved vector data buffer.\r
244 @param[in] VectorCount Vector number to be updated.\r
245 \r
246 @return EFI_SUCCESS Read and save vector info successfully.\r
247 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
248\r
249**/\r
250EFI_STATUS\r
251ReadAndVerifyVectorInfo (\r
252 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo,\r
253 OUT RESERVED_VECTORS_DATA *ReservedVector,\r
254 IN UINTN VectorCount\r
255 );\r
256\r
a51ee144
JF
257/**\r
258 Get ASCII format string exception name by exception type.\r
259\r
260 @param ExceptionType Exception type.\r
261\r
262 @return ASCII format string exception name.\r
263**/\r
264CONST CHAR8 *\r
265GetExceptionNameStr (\r
266 IN EFI_EXCEPTION_TYPE ExceptionType\r
267 );\r
268\r
44ecbc28
JF
269/**\r
270 Internal worker function for common exception handler.\r
271\r
272 @param ExceptionType Exception type.\r
273 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r
274 @param ExceptionHandlerData Pointer to exception handler data.\r
275**/\r
276VOID\r
277CommonExceptionHandlerWorker (\r
278 IN EFI_EXCEPTION_TYPE ExceptionType, \r
279 IN EFI_SYSTEM_CONTEXT SystemContext,\r
280 IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData\r
281 );\r
282\r
8f07f895 283#endif\r
e41aad15 284\r