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