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