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