]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
UefiCpuPkg/CpuExceptionHandlerLib: remove un-used mReservedVectors
[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
8f07f895 58\r
59/**\r
60 Return address map of exception handler template so that C code can generate\r
61 exception tables.\r
62\r
63 @param AddressMap Pointer to a buffer where the address map is returned.\r
64**/\r
65VOID\r
66EFIAPI\r
e41aad15 67AsmGetTemplateAddressMap (\r
8f07f895 68 OUT EXCEPTION_HANDLER_TEMPLATE_MAP *AddressMap\r
69 );\r
70\r
71/**\r
e41aad15
JF
72 Return address map of exception handler template so that C code can generate\r
73 exception tables.\r
74\r
75 @param IdtEntry Pointer to IDT entry to be updated.\r
76 @param InterruptHandler IDT handler value.\r
8f07f895 77\r
78**/\r
79VOID\r
e41aad15
JF
80ArchUpdateIdtEntry (\r
81 IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry,\r
82 IN UINTN InterruptHandler\r
83 );\r
84\r
85/**\r
86 Read IDT handler value from IDT entry.\r
87\r
88 @param IdtEntry Pointer to IDT entry to be read.\r
89\r
90**/\r
91UINTN\r
92ArchGetIdtHandler (\r
93 IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry\r
8f07f895 94 );\r
95\r
96/**\r
97 Prints a message to the serial port.\r
98\r
99 @param Format Format string for the message to print.\r
100 @param ... Variable argument list whose contents are accessed \r
101 based on the format string specified by Format.\r
102\r
103**/\r
104VOID\r
105EFIAPI\r
106InternalPrintMessage (\r
107 IN CONST CHAR8 *Format,\r
108 ...\r
109 );\r
110\r
111/**\r
112 Find and display image base address and return image base and its entry point.\r
113 \r
a9c7ab95 114 @param CurrentEip Current instruction pointer.\r
115 @param EntryPoint Return module entry point if module header is found.\r
116 \r
117 @return !0 Image base address.\r
118 @return 0 Image header cannot be found.\r
8f07f895 119**/\r
120UINTN \r
121FindModuleImageBase (\r
122 IN UINTN CurrentEip,\r
123 OUT UINTN *EntryPoint\r
124 );\r
125\r
126/**\r
127 Display CPU information.\r
128\r
3f25e6ea 129 @param ExceptionType Exception type.\r
8f07f895 130 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r
131**/\r
132VOID\r
133DumpCpuContent (\r
e41aad15 134 IN EFI_EXCEPTION_TYPE ExceptionType,\r
8f07f895 135 IN EFI_SYSTEM_CONTEXT SystemContext\r
136 );\r
137\r
e41aad15
JF
138/**\r
139 Internal worker function to initialize exception handler.\r
140\r
ab95e54d
JF
141 @param[in] VectorInfo Pointer to reserved vector list.\r
142 @param[in, out] ExceptionHandlerData Pointer to exception handler data.\r
e41aad15
JF
143 \r
144 @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized \r
145 with default exception handlers.\r
146 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
147 @retval EFI_UNSUPPORTED This function is not supported.\r
148\r
149**/\r
150EFI_STATUS\r
151InitializeCpuExceptionHandlersWorker (\r
ab95e54d
JF
152 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,\r
153 IN OUT EXCEPTION_HANDLER_DATA *ExceptionHandlerData\r
e41aad15
JF
154 );\r
155\r
156/**\r
157 Registers a function to be called from the processor interrupt handler.\r
158\r
670f13af
JF
159 @param[in] InterruptType Defines which interrupt or exception to hook.\r
160 @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called\r
161 when a processor interrupt occurs. If this parameter is NULL, then the handler\r
162 will be uninstalled\r
163 @param[in] ExceptionHandlerData Pointer to exception handler data.\r
e41aad15
JF
164\r
165 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.\r
166 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was\r
167 previously installed.\r
168 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not\r
169 previously installed.\r
170 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,\r
171 or this function is not supported.\r
3f25e6ea 172**/\r
e41aad15
JF
173EFI_STATUS\r
174RegisterCpuInterruptHandlerWorker (\r
175 IN EFI_EXCEPTION_TYPE InterruptType,\r
670f13af
JF
176 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler,\r
177 IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData\r
e41aad15
JF
178 );\r
179\r
180/**\r
181 Internal worker function to update IDT entries accordling to vector attributes.\r
182\r
9db15f81
JF
183 @param[in] IdtTable Pointer to IDT table.\r
184 @param[in] TemplateMap Pointer to a buffer where the address map is\r
185 returned.\r
186 @param[in] ExceptionHandlerData Pointer to exception handler data.\r
e41aad15
JF
187\r
188**/\r
189VOID\r
190UpdateIdtTable (\r
191 IN IA32_IDT_GATE_DESCRIPTOR *IdtTable,\r
192 IN EXCEPTION_HANDLER_TEMPLATE_MAP *TemplateMap,\r
9db15f81 193 IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData\r
e41aad15
JF
194 );\r
195\r
196/**\r
197 Save CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.\r
198\r
81b21fc2
JF
199 @param[in] ExceptionType Exception type.\r
200 @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r
201 @param[in] ExceptionHandlerData Pointer to exception handler data.\r
e41aad15
JF
202**/\r
203VOID\r
204ArchSaveExceptionContext (\r
81b21fc2
JF
205 IN UINTN ExceptionType,\r
206 IN EFI_SYSTEM_CONTEXT SystemContext,\r
207 IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData\r
e41aad15
JF
208 );\r
209\r
210/**\r
211 Restore CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.\r
212\r
368c54e7
JF
213 @param[in] ExceptionType Exception type.\r
214 @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r
215 @param[in] ExceptionHandlerData Pointer to exception handler data.\r
e41aad15
JF
216**/\r
217VOID\r
218ArchRestoreExceptionContext (\r
368c54e7
JF
219 IN UINTN ExceptionType,\r
220 IN EFI_SYSTEM_CONTEXT SystemContext,\r
221 IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData\r
e41aad15
JF
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
232VOID\r
233EFIAPI\r
234AsmVectorNumFixup (\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
251EFI_STATUS\r
252ReadAndVerifyVectorInfo (\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
265CONST CHAR8 *\r
266GetExceptionNameStr (\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
277VOID\r
278CommonExceptionHandlerWorker (\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