]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
UefiCpuPkg/ExceptionLib: Update InitializeCpuExceptionHandlersWorker
[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
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\r
160 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.\r
161 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was\r
162 previously installed.\r
163 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not\r
164 previously installed.\r
165 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,\r
166 or this function is not supported.\r
3f25e6ea 167**/\r
e41aad15
JF
168EFI_STATUS\r
169RegisterCpuInterruptHandlerWorker (\r
170 IN EFI_EXCEPTION_TYPE InterruptType,\r
171 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r
172 );\r
173\r
174/**\r
175 Internal worker function to update IDT entries accordling to vector attributes.\r
176\r
177 @param[in] IdtTable Pointer to IDT table.\r
178 @param[in] TemplateMap Pointer to a buffer where the address map is returned.\r
179 @param[in] IdtEntryCount IDT entries number to be updated.\r
180\r
181**/\r
182VOID\r
183UpdateIdtTable (\r
184 IN IA32_IDT_GATE_DESCRIPTOR *IdtTable,\r
185 IN EXCEPTION_HANDLER_TEMPLATE_MAP *TemplateMap,\r
186 IN UINTN IdtEntryCount\r
187 );\r
188\r
189/**\r
190 Save CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.\r
191\r
192 @param[in] ExceptionType Exception type.\r
193 @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r
194\r
195**/\r
196VOID\r
197ArchSaveExceptionContext (\r
198 IN UINTN ExceptionType,\r
199 IN EFI_SYSTEM_CONTEXT SystemContext \r
200 );\r
201\r
202/**\r
203 Restore CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.\r
204\r
205 @param[in] ExceptionType Exception type.\r
206 @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r
207\r
208**/\r
209VOID\r
210ArchRestoreExceptionContext (\r
211 IN UINTN ExceptionType,\r
212 IN EFI_SYSTEM_CONTEXT SystemContext \r
213 );\r
214\r
215/**\r
07da1ac8 216 Fix up the vector number and function address in the vector code.\r
e41aad15 217 \r
07da1ac8
AF
218 @param[in] NewVectorAddr New vector handler address.\r
219 @param[in] VectorNum Index of vector.\r
220 @param[in] OldVectorAddr Old vector handler address.\r
e41aad15
JF
221\r
222**/\r
223VOID\r
224EFIAPI\r
225AsmVectorNumFixup (\r
07da1ac8
AF
226 IN VOID *NewVectorAddr,\r
227 IN UINT8 VectorNum,\r
228 IN VOID *OldVectorAddr\r
e41aad15
JF
229 );\r
230\r
231/**\r
232 Read and save reserved vector information\r
233 \r
234 @param[in] VectorInfo Pointer to reserved vector list.\r
235 @param[out] ReservedVector Pointer to reserved vector data buffer.\r
236 @param[in] VectorCount Vector number to be updated.\r
237 \r
238 @return EFI_SUCCESS Read and save vector info successfully.\r
239 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
240\r
241**/\r
242EFI_STATUS\r
243ReadAndVerifyVectorInfo (\r
244 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo,\r
245 OUT RESERVED_VECTORS_DATA *ReservedVector,\r
246 IN UINTN VectorCount\r
247 );\r
248\r
a51ee144
JF
249/**\r
250 Get ASCII format string exception name by exception type.\r
251\r
252 @param ExceptionType Exception type.\r
253\r
254 @return ASCII format string exception name.\r
255**/\r
256CONST CHAR8 *\r
257GetExceptionNameStr (\r
258 IN EFI_EXCEPTION_TYPE ExceptionType\r
259 );\r
260\r
8f07f895 261#endif\r
e41aad15 262\r