]>
Commit | Line | Data |
---|---|---|
6e8a984e | 1 | /** @file\r |
2 | Generic debug support macros, typedefs and prototypes for IA32/x64.\r | |
3 | \r | |
4 | Copyright (c) 2006 - 2008, Intel Corporation \r | |
5 | All rights reserved. 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 _DEBUG_SUPPORT_H_\r | |
16 | #define _DEBUG_SUPPORT_H_\r | |
17 | \r | |
18 | \r | |
19 | #include <Uefi.h>\r | |
20 | \r | |
21 | #include <Protocol/DebugSupport.h>\r | |
22 | #include <Protocol/LoadedImage.h>\r | |
23 | \r | |
24 | #include <Library/DebugLib.h>\r | |
25 | #include <Library/UefiDriverEntryPoint.h>\r | |
26 | #include <Library/BaseMemoryLib.h>\r | |
27 | #include <Library/MemoryAllocationLib.h>\r | |
28 | #include <Library/UefiBootServicesTableLib.h>\r | |
29 | #include <Library/BaseLib.h>\r | |
30 | #include <Library/PcdLib.h>\r | |
31 | \r | |
32 | #define NUM_IDT_ENTRIES 0x78\r | |
33 | #define SYSTEM_TIMER_VECTOR 0x68\r | |
34 | #define VECTOR_ENTRY_PAGES 1\r | |
35 | \r | |
36 | #define FF_FXSR (1 << 24)\r | |
37 | \r | |
38 | typedef\r | |
39 | VOID\r | |
40 | (*DEBUG_PROC) (\r | |
41 | VOID\r | |
42 | );\r | |
43 | \r | |
44 | typedef struct {\r | |
45 | IA32_IDT_GATE_DESCRIPTOR OrigDesc;\r | |
46 | DEBUG_PROC OrigVector;\r | |
47 | IA32_IDT_GATE_DESCRIPTOR NewDesc;\r | |
48 | DEBUG_PROC StubEntry;\r | |
49 | VOID (*RegisteredCallback) ();\r | |
50 | } IDT_ENTRY;\r | |
51 | \r | |
52 | extern EFI_SYSTEM_CONTEXT SystemContext;\r | |
53 | extern UINT8 InterruptEntryStub[];\r | |
54 | extern UINT32 StubSize;\r | |
55 | extern VOID (*OrigVector) (VOID);\r | |
56 | extern IDT_ENTRY *IdtEntryTable;\r | |
57 | extern IA32_IDT_GATE_DESCRIPTOR NullDesc;\r | |
58 | \r | |
59 | /**\r | |
60 | Generic IDT entry.\r | |
61 | \r | |
62 | **/\r | |
63 | VOID\r | |
64 | CommonIdtEntry (\r | |
65 | VOID\r | |
66 | );\r | |
67 | \r | |
68 | /**\r | |
69 | Check whether FXSTOR is supported\r | |
70 | \r | |
71 | @retval TRUE FXSTOR is supported.\r | |
72 | @retval FALSE FXSTOR is not supported.\r | |
73 | \r | |
74 | **/\r | |
75 | BOOLEAN\r | |
76 | FxStorSupport (\r | |
77 | VOID\r | |
78 | );\r | |
79 | \r | |
80 | /**\r | |
81 | Encodes an IDT descriptor with the given physical address.\r | |
82 | \r | |
83 | @param DestDesc The IDT descriptor address.\r | |
84 | @param Vecotr The interrupt vector entry.\r | |
85 | \r | |
86 | **/\r | |
87 | VOID\r | |
88 | Vect2Desc (\r | |
89 | IA32_IDT_GATE_DESCRIPTOR * DestDesc,\r | |
90 | VOID (*Vector) (VOID)\r | |
91 | );\r | |
92 | \r | |
93 | /**\r | |
94 | Programs interrupt flag to the requested state and returns previous\r | |
95 | state.\r | |
96 | \r | |
97 | @param NewState New interrupt status.\r | |
98 | \r | |
99 | @retval TRUE Old interrupt status is TRUE.\r | |
100 | @retval FALSE Old interrupt status is FALSE\r | |
101 | \r | |
102 | **/\r | |
103 | BOOLEAN\r | |
104 | WriteInterruptFlag (\r | |
105 | BOOLEAN NewState\r | |
106 | );\r | |
107 | \r | |
108 | /**\r | |
109 | Initializes driver's handler registration databas. \r | |
110 | \r | |
111 | This code executes in boot services context\r | |
112 | Must be public because it's referenced from DebugSupport.c\r | |
113 | \r | |
114 | @retval EFI_UNSUPPORTED If IA32 processor does not support FXSTOR/FXRSTOR instructions,\r | |
115 | the context save will fail, so these processor's are not supported.\r | |
116 | @retval EFI_OUT_OF_RESOURCES Fails to allocate memory.\r | |
117 | @retval EFI_SUCCESS Initializes successfully.\r | |
118 | \r | |
119 | **/\r | |
120 | EFI_STATUS\r | |
121 | PlInitializeDebugSupportDriver (\r | |
122 | VOID\r | |
123 | );\r | |
124 | \r | |
125 | /**\r | |
126 | This is the callback that is written to the LoadedImage protocol instance\r | |
127 | on the image handle. It uninstalls all registered handlers and frees all entry\r | |
128 | stub memory.\r | |
129 | \r | |
130 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
131 | \r | |
132 | @retval EFI_SUCCESS Always.\r | |
133 | \r | |
134 | **/\r | |
135 | EFI_STATUS\r | |
136 | EFIAPI\r | |
137 | PlUnloadDebugSupportDriver (\r | |
138 | IN EFI_HANDLE ImageHandle\r | |
139 | );\r | |
140 | \r | |
141 | /**\r | |
142 | This is a DebugSupport protocol member function, hard\r | |
143 | coded to support only 1 processor for now.\r | |
144 | \r | |
145 | @param This The DebugSupport instance\r | |
146 | @param MaxProcessorIndex The maximuim supported processor index\r | |
147 | \r | |
148 | @retval EFI_SUCCESS Always returned with **MaxProcessorIndex set to 0.\r | |
149 | \r | |
150 | **/\r | |
151 | EFI_STATUS\r | |
152 | EFIAPI\r | |
153 | GetMaximumProcessorIndex (\r | |
154 | IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r | |
155 | OUT UINTN *MaxProcessorIndex\r | |
156 | );\r | |
157 | \r | |
158 | /**\r | |
159 | DebugSupport protocol member function.\r | |
160 | \r | |
161 | @param This The DebugSupport instance\r | |
162 | @param ProcessorIndex Which processor the callback applies to.\r | |
163 | @param PeriodicCallback Callback function\r | |
164 | \r | |
165 | @retval EFI_SUCCESS Indicates the callback was registered.\r | |
166 | @retval others Callback was not registered.\r | |
167 | \r | |
168 | **/\r | |
169 | EFI_STATUS\r | |
170 | EFIAPI\r | |
171 | RegisterPeriodicCallback (\r | |
172 | IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r | |
173 | IN UINTN ProcessorIndex,\r | |
174 | IN EFI_PERIODIC_CALLBACK PeriodicCallback\r | |
175 | );\r | |
176 | \r | |
177 | /**\r | |
178 | DebugSupport protocol member function.\r | |
179 | \r | |
180 | This code executes in boot services context.\r | |
181 | \r | |
182 | @param This The DebugSupport instance\r | |
183 | @param ProcessorIndex Which processor the callback applies to.\r | |
184 | @param NewCallback Callback function\r | |
185 | @param ExceptionType Which exception to hook\r | |
186 | \r | |
187 | @retval EFI_SUCCESS Indicates the callback was registered.\r | |
188 | @retval others Callback was not registered.\r | |
189 | \r | |
190 | **/\r | |
191 | EFI_STATUS\r | |
192 | EFIAPI\r | |
193 | RegisterExceptionCallback (\r | |
194 | IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r | |
195 | IN UINTN ProcessorIndex,\r | |
196 | IN EFI_EXCEPTION_CALLBACK NewCallback,\r | |
197 | IN EFI_EXCEPTION_TYPE ExceptionType\r | |
198 | );\r | |
199 | \r | |
200 | /**\r | |
201 | DebugSupport protocol member function. Calls assembly routine to flush cache.\r | |
202 | \r | |
203 | @param This The DebugSupport instance\r | |
204 | @param ProcessorIndex Which processor the callback applies to.\r | |
205 | @param Start Physical base of the memory range to be invalidated\r | |
206 | @param Length mininum number of bytes in instruction cache to invalidate\r | |
207 | \r | |
208 | @retval EFI_SUCCESS Always returned.\r | |
209 | \r | |
210 | **/\r | |
211 | EFI_STATUS\r | |
212 | EFIAPI\r | |
213 | InvalidateInstructionCache (\r | |
214 | IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r | |
215 | IN UINTN ProcessorIndex,\r | |
216 | IN VOID *Start,\r | |
217 | IN UINT64 Length\r | |
218 | );\r | |
219 | \r | |
220 | /**\r | |
221 | Allocate pool for a new IDT entry stub.\r | |
222 | \r | |
223 | Copy the generic stub into the new buffer and fixup the vector number\r | |
224 | and jump target address.\r | |
225 | \r | |
226 | @param ExceptionType This is the exception type that the new stub will be created\r | |
227 | for.\r | |
228 | @param Stub On successful exit, *Stub contains the newly allocated entry stub.\r | |
229 | \r | |
230 | @retval EFI_SUCCESS Always.\r | |
231 | \r | |
232 | **/\r | |
233 | EFI_STATUS\r | |
234 | CreateEntryStub (\r | |
235 | IN EFI_EXCEPTION_TYPE ExceptionType,\r | |
236 | OUT VOID **Stub\r | |
237 | );\r | |
238 | \r | |
239 | /**\r | |
240 | Get Procedure Entry Point from IDT Gate Descriptor.\r | |
241 | \r | |
242 | @param IdtGateDecriptor IDT Gate Descriptor.\r | |
243 | \r | |
244 | @return Procedure Entry Point located in IDT Gate Descriptor.\r | |
245 | \r | |
246 | **/\r | |
247 | UINTN GetProcedureEntryPoint (\r | |
248 | IN IA32_IDT_GATE_DESCRIPTOR *IdtGateDecriptor\r | |
249 | );\r | |
250 | \r | |
251 | /**\r | |
252 | This is the main worker function that manages the state of the interrupt\r | |
253 | handlers. It both installs and uninstalls interrupt handlers based on the\r | |
254 | value of NewCallback. If NewCallback is NULL, then uninstall is indicated.\r | |
255 | If NewCallback is non-NULL, then install is indicated.\r | |
256 | \r | |
257 | @param NewCallback If non-NULL, NewCallback specifies the new handler to register.\r | |
258 | If NULL, specifies that the previously registered handler should\r | |
259 | be uninstalled.\r | |
260 | @param ExceptionType Indicates which entry to manage.\r | |
261 | \r | |
262 | @retval EFI_SUCCESS Process is ok.\r | |
263 | @retval EFI_INVALID_PARAMETER Requested uninstalling a handler from a vector that has\r | |
264 | no handler registered for it\r | |
265 | @retval EFI_ALREADY_STARTED Requested install to a vector that already has a handler registered.\r | |
266 | @retval others Possible return values are passed through from UnHookEntry and HookEntry.\r | |
267 | \r | |
268 | **/\r | |
269 | EFI_STATUS\r | |
270 | ManageIdtEntryTable (\r | |
271 | VOID (*NewCallback)(),\r | |
272 | EFI_EXCEPTION_TYPE ExceptionType\r | |
273 | );\r | |
274 | \r | |
275 | /**\r | |
276 | Creates a nes entry stub. Then saves the current IDT entry and replaces it\r | |
277 | with an interrupt gate for the new entry point. The IdtEntryTable is updated\r | |
278 | with the new registered function.\r | |
279 | \r | |
280 | This code executes in boot services context. The stub entry executes in interrupt\r | |
281 | context.\r | |
282 | \r | |
283 | @param ExceptionType Specifies which vector to hook.\r | |
284 | @param NewCallback A pointer to the new function to be registered.\r | |
285 | \r | |
286 | @retval EFI_SUCCESS Always.\r | |
287 | \r | |
288 | **/\r | |
289 | EFI_STATUS\r | |
290 | HookEntry (\r | |
291 | IN EFI_EXCEPTION_TYPE ExceptionType,\r | |
292 | IN VOID (*NewCallback) ()\r | |
293 | );\r | |
294 | \r | |
295 | /**\r | |
296 | Undoes HookEntry. This code executes in boot services context.\r | |
297 | \r | |
298 | @param ExceptionType Specifies which entry to unhook\r | |
299 | \r | |
300 | @retval EFI_SUCCESS Always.\r | |
301 | \r | |
302 | **/\r | |
303 | EFI_STATUS\r | |
304 | UnhookEntry (\r | |
305 | IN EFI_EXCEPTION_TYPE ExceptionType\r | |
306 | );\r | |
307 | \r | |
308 | #endif\r |