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