]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
UefiCpuPkg/ExceptionLib: Update UpdateIdtTable()
[mirror_edk2.git] / UefiCpuPkg / Library / CpuExceptionHandlerLib / CpuExceptionCommon.h
... / ...
CommitLineData
1/** @file\r
2 Common header file for CPU Exception Handler Library.\r
3\r
4 Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.<BR>\r
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
18#include <Ppi/VectorHandoffInfo.h>\r
19#include <Protocol/Cpu.h>\r
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
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
33\r
34//\r
35// Record exception handler information\r
36//\r
37typedef struct {\r
38 UINTN ExceptionStart;\r
39 UINTN ExceptionStubHeaderSize;\r
40 UINTN HookAfterStubHeaderStart;\r
41} EXCEPTION_HANDLER_TEMPLATE_MAP;\r
42\r
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
50extern CONST UINT32 mErrorCodeFlag;\r
51extern CONST UINTN mImageAlignSize;\r
52extern CONST UINTN mDoFarReturnFlag;\r
53extern RESERVED_VECTORS_DATA *mReservedVectors;\r
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
63AsmGetTemplateAddressMap (\r
64 OUT EXCEPTION_HANDLER_TEMPLATE_MAP *AddressMap\r
65 );\r
66\r
67/**\r
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
73\r
74**/\r
75VOID\r
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
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
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
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
125 @param ExceptionType Exception type.\r
126 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r
127**/\r
128VOID\r
129DumpCpuContent (\r
130 IN EFI_EXCEPTION_TYPE ExceptionType,\r
131 IN EFI_SYSTEM_CONTEXT SystemContext\r
132 );\r
133\r
134/**\r
135 Internal worker function to initialize exception handler.\r
136\r
137 @param[in] VectorInfo Pointer to reserved vector list.\r
138 @param[in, out] ExceptionHandlerData Pointer to exception handler data.\r
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
148 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,\r
149 IN OUT EXCEPTION_HANDLER_DATA *ExceptionHandlerData\r
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
167**/\r
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\r
179 returned.\r
180 @param[in] ExceptionHandlerData Pointer to exception handler data.\r
181\r
182**/\r
183VOID\r
184UpdateIdtTable (\r
185 IN IA32_IDT_GATE_DESCRIPTOR *IdtTable,\r
186 IN EXCEPTION_HANDLER_TEMPLATE_MAP *TemplateMap,\r
187 IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData\r
188 );\r
189\r
190/**\r
191 Save CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.\r
192\r
193 @param[in] ExceptionType Exception type.\r
194 @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r
195\r
196**/\r
197VOID\r
198ArchSaveExceptionContext (\r
199 IN UINTN ExceptionType,\r
200 IN EFI_SYSTEM_CONTEXT SystemContext \r
201 );\r
202\r
203/**\r
204 Restore CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.\r
205\r
206 @param[in] ExceptionType Exception type.\r
207 @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r
208\r
209**/\r
210VOID\r
211ArchRestoreExceptionContext (\r
212 IN UINTN ExceptionType,\r
213 IN EFI_SYSTEM_CONTEXT SystemContext \r
214 );\r
215\r
216/**\r
217 Fix up the vector number and function address in the vector code.\r
218 \r
219 @param[in] NewVectorAddr New vector handler address.\r
220 @param[in] VectorNum Index of vector.\r
221 @param[in] OldVectorAddr Old vector handler address.\r
222\r
223**/\r
224VOID\r
225EFIAPI\r
226AsmVectorNumFixup (\r
227 IN VOID *NewVectorAddr,\r
228 IN UINT8 VectorNum,\r
229 IN VOID *OldVectorAddr\r
230 );\r
231\r
232/**\r
233 Read and save reserved vector information\r
234 \r
235 @param[in] VectorInfo Pointer to reserved vector list.\r
236 @param[out] ReservedVector Pointer to reserved vector data buffer.\r
237 @param[in] VectorCount Vector number to be updated.\r
238 \r
239 @return EFI_SUCCESS Read and save vector info successfully.\r
240 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
241\r
242**/\r
243EFI_STATUS\r
244ReadAndVerifyVectorInfo (\r
245 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo,\r
246 OUT RESERVED_VECTORS_DATA *ReservedVector,\r
247 IN UINTN VectorCount\r
248 );\r
249\r
250/**\r
251 Get ASCII format string exception name by exception type.\r
252\r
253 @param ExceptionType Exception type.\r
254\r
255 @return ASCII format string exception name.\r
256**/\r
257CONST CHAR8 *\r
258GetExceptionNameStr (\r
259 IN EFI_EXCEPTION_TYPE ExceptionType\r
260 );\r
261\r
262#endif\r
263\r