]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
UefiCpuPkg: Fix typos in comments
[mirror_edk2.git] / UefiCpuPkg / Library / CpuExceptionHandlerLib / CpuExceptionCommon.h
1 /** @file
2 Common header file for CPU Exception Handler Library.
3
4 Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #ifndef _CPU_EXCEPTION_COMMON_H_
16 #define _CPU_EXCEPTION_COMMON_H_
17
18 #include <Ppi/VectorHandoffInfo.h>
19 #include <Protocol/Cpu.h>
20 #include <Library/BaseLib.h>
21 #include <Library/SerialPortLib.h>
22 #include <Library/PrintLib.h>
23 #include <Library/LocalApicLib.h>
24 #include <Library/PeCoffGetEntryPointLib.h>
25 #include <Library/BaseMemoryLib.h>
26 #include <Library/SynchronizationLib.h>
27
28 #define CPU_EXCEPTION_NUM 32
29 #define CPU_INTERRUPT_NUM 256
30 #define HOOKAFTER_STUB_SIZE 16
31
32 #include "ArchInterruptDefs.h"
33
34 #define CPU_EXCEPTION_HANDLER_LIB_HOB_GUID \
35 { \
36 0xb21d9148, 0x9211, 0x4d8f, { 0xad, 0xd3, 0x66, 0xb1, 0x89, 0xc9, 0x2c, 0x83 } \
37 }
38
39 //
40 // Record exception handler information
41 //
42 typedef struct {
43 UINTN ExceptionStart;
44 UINTN ExceptionStubHeaderSize;
45 UINTN HookAfterStubHeaderStart;
46 } EXCEPTION_HANDLER_TEMPLATE_MAP;
47
48 typedef struct {
49 UINTN IdtEntryCount;
50 SPIN_LOCK DisplayMessageSpinLock;
51 RESERVED_VECTORS_DATA *ReservedVectors;
52 EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;
53 } EXCEPTION_HANDLER_DATA;
54
55 extern CONST UINT32 mErrorCodeFlag;
56 extern CONST UINTN mImageAlignSize;
57 extern CONST UINTN mDoFarReturnFlag;
58 extern RESERVED_VECTORS_DATA *mReservedVectors;
59
60 /**
61 Return address map of exception handler template so that C code can generate
62 exception tables.
63
64 @param AddressMap Pointer to a buffer where the address map is returned.
65 **/
66 VOID
67 EFIAPI
68 AsmGetTemplateAddressMap (
69 OUT EXCEPTION_HANDLER_TEMPLATE_MAP *AddressMap
70 );
71
72 /**
73 Return address map of exception handler template so that C code can generate
74 exception tables.
75
76 @param IdtEntry Pointer to IDT entry to be updated.
77 @param InterruptHandler IDT handler value.
78
79 **/
80 VOID
81 ArchUpdateIdtEntry (
82 IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry,
83 IN UINTN InterruptHandler
84 );
85
86 /**
87 Read IDT handler value from IDT entry.
88
89 @param IdtEntry Pointer to IDT entry to be read.
90
91 **/
92 UINTN
93 ArchGetIdtHandler (
94 IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry
95 );
96
97 /**
98 Prints a message to the serial port.
99
100 @param Format Format string for the message to print.
101 @param ... Variable argument list whose contents are accessed
102 based on the format string specified by Format.
103
104 **/
105 VOID
106 EFIAPI
107 InternalPrintMessage (
108 IN CONST CHAR8 *Format,
109 ...
110 );
111
112 /**
113 Find and display image base address and return image base and its entry point.
114
115 @param CurrentEip Current instruction pointer.
116 @param EntryPoint Return module entry point if module header is found.
117
118 @return !0 Image base address.
119 @return 0 Image header cannot be found.
120 **/
121 UINTN
122 FindModuleImageBase (
123 IN UINTN CurrentEip,
124 OUT UINTN *EntryPoint
125 );
126
127 /**
128 Display CPU information.
129
130 @param ExceptionType Exception type.
131 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
132 **/
133 VOID
134 DumpCpuContent (
135 IN EFI_EXCEPTION_TYPE ExceptionType,
136 IN EFI_SYSTEM_CONTEXT SystemContext
137 );
138
139 /**
140 Internal worker function to initialize exception handler.
141
142 @param[in] VectorInfo Pointer to reserved vector list.
143 @param[in, out] ExceptionHandlerData Pointer to exception handler data.
144
145 @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized
146 with default exception handlers.
147 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
148 @retval EFI_UNSUPPORTED This function is not supported.
149
150 **/
151 EFI_STATUS
152 InitializeCpuExceptionHandlersWorker (
153 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
154 IN OUT EXCEPTION_HANDLER_DATA *ExceptionHandlerData
155 );
156
157 /**
158 Registers a function to be called from the processor interrupt handler.
159
160 @param[in] InterruptType Defines which interrupt or exception to hook.
161 @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called
162 when a processor interrupt occurs. If this parameter is NULL, then the handler
163 will be uninstalled
164 @param[in] ExceptionHandlerData Pointer to exception handler data.
165
166 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.
167 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was
168 previously installed.
169 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not
170 previously installed.
171 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,
172 or this function is not supported.
173 **/
174 EFI_STATUS
175 RegisterCpuInterruptHandlerWorker (
176 IN EFI_EXCEPTION_TYPE InterruptType,
177 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler,
178 IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
179 );
180
181 /**
182 Internal worker function to update IDT entries accordling to vector attributes.
183
184 @param[in] IdtTable Pointer to IDT table.
185 @param[in] TemplateMap Pointer to a buffer where the address map is
186 returned.
187 @param[in] ExceptionHandlerData Pointer to exception handler data.
188
189 **/
190 VOID
191 UpdateIdtTable (
192 IN IA32_IDT_GATE_DESCRIPTOR *IdtTable,
193 IN EXCEPTION_HANDLER_TEMPLATE_MAP *TemplateMap,
194 IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
195 );
196
197 /**
198 Save CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.
199
200 @param[in] ExceptionType Exception type.
201 @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.
202
203 **/
204 VOID
205 ArchSaveExceptionContext (
206 IN UINTN ExceptionType,
207 IN EFI_SYSTEM_CONTEXT SystemContext
208 );
209
210 /**
211 Restore CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.
212
213 @param[in] ExceptionType Exception type.
214 @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.
215
216 **/
217 VOID
218 ArchRestoreExceptionContext (
219 IN UINTN ExceptionType,
220 IN EFI_SYSTEM_CONTEXT SystemContext
221 );
222
223 /**
224 Fix up the vector number and function address in the vector code.
225
226 @param[in] NewVectorAddr New vector handler address.
227 @param[in] VectorNum Index of vector.
228 @param[in] OldVectorAddr Old vector handler address.
229
230 **/
231 VOID
232 EFIAPI
233 AsmVectorNumFixup (
234 IN VOID *NewVectorAddr,
235 IN UINT8 VectorNum,
236 IN VOID *OldVectorAddr
237 );
238
239 /**
240 Read and save reserved vector information
241
242 @param[in] VectorInfo Pointer to reserved vector list.
243 @param[out] ReservedVector Pointer to reserved vector data buffer.
244 @param[in] VectorCount Vector number to be updated.
245
246 @return EFI_SUCCESS Read and save vector info successfully.
247 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
248
249 **/
250 EFI_STATUS
251 ReadAndVerifyVectorInfo (
252 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo,
253 OUT RESERVED_VECTORS_DATA *ReservedVector,
254 IN UINTN VectorCount
255 );
256
257 /**
258 Get ASCII format string exception name by exception type.
259
260 @param ExceptionType Exception type.
261
262 @return ASCII format string exception name.
263 **/
264 CONST CHAR8 *
265 GetExceptionNameStr (
266 IN EFI_EXCEPTION_TYPE ExceptionType
267 );
268
269 /**
270 Internal worker function for common exception handler.
271
272 @param ExceptionType Exception type.
273 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
274 @param ExceptionHandlerData Pointer to exception handler data.
275 **/
276 VOID
277 CommonExceptionHandlerWorker (
278 IN EFI_EXCEPTION_TYPE ExceptionType,
279 IN EFI_SYSTEM_CONTEXT SystemContext,
280 IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
281 );
282
283 #endif
284