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