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