]>
Commit | Line | Data |
---|---|---|
748edcd5 PB |
1 | /*++\r |
2 | \r | |
0978bd0d | 3 | Copyright (c) 2007 - 2016, Intel Corporation\r |
748edcd5 PB |
4 | All rights reserved. This program and the accompanying materials\r |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | Ebc.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | --*/\r | |
19 | \r | |
20 | #include <Uefi.h>\r | |
21 | #include "Edb.h"\r | |
22 | \r | |
23 | EFI_DEBUGGER_PRIVATE_DATA mDebuggerPrivate = {\r | |
24 | EFI_DEBUGGER_SIGNATURE, // Signature\r | |
25 | IsaEbc, // Isa\r | |
26 | (EBC_DEBUGGER_MAJOR_VERSION << 16) |\r | |
27 | EBC_DEBUGGER_MINOR_VERSION, // EfiDebuggerRevision\r | |
28 | (VM_MAJOR_VERSION << 16) |\r | |
29 | VM_MINOR_VERSION, // EbcVmRevision\r | |
30 | NULL, // DebugImageInfoTableHeader\r | |
31 | NULL, // Vol\r | |
32 | NULL, // PciRootBridgeIo\r | |
33 | mDebuggerCommandSet, // DebuggerCommandSet\r | |
34 | {0}, // DebuggerSymbolContext\r | |
35 | 0, // DebuggerBreakpointCount\r | |
36 | {{0}}, // DebuggerBreakpointContext\r | |
37 | 0, // CallStackEntryCount\r | |
38 | {{0}}, // CallStackEntry\r | |
39 | 0, // TraceEntryCount\r | |
40 | {{0}}, // TraceEntry\r | |
41 | {0}, // StepContext\r | |
42 | {0}, // GoTilContext\r | |
43 | 0, // InstructionScope\r | |
44 | EFI_DEBUG_DEFAULT_INSTRUCTION_NUMBER, // InstructionNumber\r | |
45 | EFI_DEBUG_FLAG_EBC_BOE | EFI_DEBUG_FLAG_EBC_BOT, // FeatureFlags\r | |
46 | 0, // StatusFlags\r | |
47 | FALSE, // EnablePageBreak\r | |
48 | NULL // BreakEvent\r | |
49 | };\r | |
50 | \r | |
51 | CHAR16 *mExceptionStr[] = {\r | |
52 | L"EXCEPT_EBC_UNDEFINED",\r | |
53 | L"EXCEPT_EBC_DIVIDE_ERROR",\r | |
54 | L"EXCEPT_EBC_DEBUG",\r | |
55 | L"EXCEPT_EBC_BREAKPOINT",\r | |
56 | L"EXCEPT_EBC_OVERFLOW",\r | |
57 | L"EXCEPT_EBC_INVALID_OPCODE",\r | |
58 | L"EXCEPT_EBC_STACK_FAULT",\r | |
59 | L"EXCEPT_EBC_ALIGNMENT_CHECK",\r | |
60 | L"EXCEPT_EBC_INSTRUCTION_ENCODING",\r | |
61 | L"EXCEPT_EBC_BAD_BREAK",\r | |
62 | L"EXCEPT_EBC_SINGLE_STEP",\r | |
63 | };\r | |
64 | \r | |
65 | VOID\r | |
66 | EdbClearAllBreakpoint (\r | |
67 | IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r | |
68 | IN BOOLEAN NeedRemove\r | |
69 | )\r | |
70 | /*++\r | |
71 | \r | |
72 | Routine Description:\r | |
73 | \r | |
74 | Clear all the breakpoint\r | |
75 | \r | |
76 | Arguments:\r | |
77 | \r | |
78 | DebuggerPrivate - EBC Debugger private data structure\r | |
79 | NeedRemove - Whether need to remove all the breakpoint\r | |
80 | \r | |
81 | Returns:\r | |
82 | \r | |
83 | None\r | |
84 | \r | |
85 | --*/\r | |
86 | {\r | |
87 | UINTN Index;\r | |
88 | \r | |
89 | //\r | |
90 | // Patch all the breakpoint\r | |
91 | //\r | |
92 | for (Index = 0; (Index < DebuggerPrivate->DebuggerBreakpointCount) && (Index < EFI_DEBUGGER_BREAKPOINT_MAX); Index++) {\r | |
93 | if (DebuggerPrivate->DebuggerBreakpointContext[Index].State) {\r | |
94 | CopyMem (\r | |
95 | (VOID *)(UINTN)DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress,\r | |
96 | &DebuggerPrivate->DebuggerBreakpointContext[Index].OldInstruction,\r | |
97 | sizeof(UINT16)\r | |
98 | );\r | |
99 | }\r | |
100 | }\r | |
101 | \r | |
102 | //\r | |
103 | // Zero Breakpoint context, if need to remove all breakpoint\r | |
104 | //\r | |
105 | if (NeedRemove) {\r | |
106 | DebuggerPrivate->DebuggerBreakpointCount = 0;\r | |
107 | ZeroMem (DebuggerPrivate->DebuggerBreakpointContext, sizeof(DebuggerPrivate->DebuggerBreakpointContext));\r | |
108 | }\r | |
109 | \r | |
110 | //\r | |
111 | // Done\r | |
112 | //\r | |
113 | return ;\r | |
114 | }\r | |
115 | \r | |
116 | VOID\r | |
117 | EdbSetAllBreakpoint (\r | |
118 | IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate\r | |
119 | )\r | |
120 | /*++\r | |
121 | \r | |
122 | Routine Description:\r | |
123 | \r | |
124 | Set all the breakpoint\r | |
125 | \r | |
126 | Arguments:\r | |
127 | \r | |
128 | DebuggerPrivate - EBC Debugger private data structure\r | |
129 | \r | |
130 | Returns:\r | |
131 | \r | |
132 | None\r | |
133 | \r | |
134 | --*/\r | |
135 | {\r | |
136 | UINTN Index;\r | |
137 | UINT16 Data16;\r | |
138 | \r | |
139 | //\r | |
140 | // Set all the breakpoint (BREAK(3) : 0x0300)\r | |
141 | //\r | |
142 | Data16 = 0x0300;\r | |
143 | for (Index = 0; (Index < DebuggerPrivate->DebuggerBreakpointCount) && (Index < EFI_DEBUGGER_BREAKPOINT_MAX); Index++) {\r | |
144 | if (DebuggerPrivate->DebuggerBreakpointContext[Index].State) {\r | |
145 | CopyMem (\r | |
146 | (VOID *)(UINTN)DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress,\r | |
147 | &Data16,\r | |
148 | sizeof(UINT16)\r | |
149 | );\r | |
150 | }\r | |
151 | }\r | |
152 | \r | |
153 | //\r | |
154 | // Check if current break is caused by breakpoint set.\r | |
155 | // If so, we need to patch memory back to let user see the real memory.\r | |
156 | //\r | |
157 | if (DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].BreakpointAddress != 0) {\r | |
158 | CopyMem (\r | |
159 | (VOID *)(UINTN)DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].BreakpointAddress,\r | |
160 | &DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].OldInstruction,\r | |
161 | sizeof(UINT16)\r | |
162 | );\r | |
163 | DebuggerPrivate->StatusFlags &= ~EFI_DEBUG_FLAG_EBC_B_BP;\r | |
164 | }\r | |
165 | \r | |
166 | //\r | |
167 | // Done\r | |
168 | //\r | |
169 | return ;\r | |
170 | }\r | |
171 | \r | |
172 | VOID\r | |
173 | EdbCheckBreakpoint (\r | |
174 | IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r | |
175 | IN EFI_SYSTEM_CONTEXT SystemContext\r | |
176 | )\r | |
177 | /*++\r | |
178 | \r | |
179 | Routine Description:\r | |
180 | \r | |
181 | Check all the breakpoint, if match, then set status flag, and record current breakpoint.\r | |
182 | Then clear all breakpoint to let user see a clean memory\r | |
183 | \r | |
184 | Arguments:\r | |
185 | \r | |
186 | DebuggerPrivate - EBC Debugger private data structure\r | |
187 | SystemContext - EBC system context.\r | |
188 | \r | |
189 | Returns:\r | |
190 | \r | |
191 | None\r | |
192 | \r | |
193 | --*/\r | |
194 | {\r | |
195 | UINT64 Address;\r | |
196 | UINTN Index;\r | |
197 | UINT16 OldInstruction;\r | |
198 | BOOLEAN IsHitBreakpoint;\r | |
199 | \r | |
200 | //\r | |
201 | // Roll back IP for breakpoint instruction (BREAK(3) : 0x0300)\r | |
202 | //\r | |
203 | Address = SystemContext.SystemContextEbc->Ip - sizeof(UINT16);\r | |
204 | \r | |
205 | //\r | |
206 | // Check if the breakpoint is hit\r | |
207 | //\r | |
208 | IsHitBreakpoint = FALSE;\r | |
209 | for (Index = 0; (Index < DebuggerPrivate->DebuggerBreakpointCount) && (Index < EFI_DEBUGGER_BREAKPOINT_MAX); Index++) {\r | |
210 | if ((DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress == Address) &&\r | |
211 | (DebuggerPrivate->DebuggerBreakpointContext[Index].State)) {\r | |
212 | OldInstruction = (UINT16)DebuggerPrivate->DebuggerBreakpointContext[Index].OldInstruction;\r | |
213 | IsHitBreakpoint = TRUE;\r | |
214 | break;\r | |
215 | }\r | |
216 | }\r | |
217 | \r | |
218 | if (IsHitBreakpoint) {\r | |
219 | //\r | |
220 | // If hit, record current breakpoint\r | |
221 | //\r | |
222 | DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX] = DebuggerPrivate->DebuggerBreakpointContext[Index];\r | |
223 | DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].State = TRUE;\r | |
224 | //\r | |
225 | // Update: IP and Instruction (NOTE: Since we not allow set breakpoint to BREAK 3, this update is safe)\r | |
226 | //\r | |
227 | SystemContext.SystemContextEbc->Ip = Address;\r | |
228 | //\r | |
229 | // Set Flags\r | |
230 | //\r | |
231 | DebuggerPrivate->StatusFlags |= EFI_DEBUG_FLAG_EBC_BP;\r | |
232 | } else {\r | |
233 | //\r | |
234 | // If not hit, check whether current IP is in breakpoint list,\r | |
235 | // because STEP will be triggered before execute the instruction.\r | |
236 | // We should not patch it in de-init.\r | |
237 | //\r | |
238 | Address = SystemContext.SystemContextEbc->Ip;\r | |
239 | \r | |
240 | //\r | |
241 | // Check if the breakpoint is hit\r | |
242 | //\r | |
243 | IsHitBreakpoint = FALSE;\r | |
244 | for (Index = 0; (Index < DebuggerPrivate->DebuggerBreakpointCount) && (Index < EFI_DEBUGGER_BREAKPOINT_MAX); Index++) {\r | |
245 | if ((DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress == Address) &&\r | |
246 | (DebuggerPrivate->DebuggerBreakpointContext[Index].State)) {\r | |
247 | OldInstruction = (UINT16)DebuggerPrivate->DebuggerBreakpointContext[Index].OldInstruction;\r | |
248 | IsHitBreakpoint = TRUE;\r | |
249 | break;\r | |
250 | }\r | |
251 | }\r | |
252 | \r | |
253 | if (IsHitBreakpoint) {\r | |
254 | //\r | |
255 | // If hit, record current breakpoint\r | |
256 | //\r | |
257 | DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX] = DebuggerPrivate->DebuggerBreakpointContext[Index];\r | |
258 | DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].State = TRUE;\r | |
259 | //\r | |
260 | // Do not set Breakpoint flag. We record the address here just let it not patch breakpoint address when de-init.\r | |
261 | //\r | |
262 | } else {\r | |
263 | //\r | |
264 | // Zero current breakpoint\r | |
265 | //\r | |
266 | ZeroMem (\r | |
267 | &DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX],\r | |
268 | sizeof(DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX])\r | |
269 | );\r | |
270 | }\r | |
271 | }\r | |
272 | \r | |
273 | //\r | |
274 | // Done\r | |
275 | //\r | |
276 | return ;\r | |
277 | }\r | |
278 | \r | |
279 | VOID\r | |
280 | EdbClearSymbol (\r | |
281 | IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate\r | |
282 | )\r | |
283 | /*++\r | |
284 | \r | |
285 | Routine Description:\r | |
286 | \r | |
287 | clear all the symbol\r | |
288 | \r | |
289 | Arguments:\r | |
290 | \r | |
291 | DebuggerPrivate - EBC Debugger private data structure\r | |
292 | \r | |
293 | Returns:\r | |
294 | \r | |
295 | None\r | |
296 | \r | |
297 | --*/\r | |
298 | {\r | |
299 | EFI_DEBUGGER_SYMBOL_CONTEXT *DebuggerSymbolContext;\r | |
300 | EFI_DEBUGGER_SYMBOL_OBJECT *Object;\r | |
301 | UINTN ObjectIndex;\r | |
302 | UINTN Index;\r | |
303 | \r | |
304 | //\r | |
305 | // Go throuth each object\r | |
306 | //\r | |
307 | DebuggerSymbolContext = &DebuggerPrivate->DebuggerSymbolContext;\r | |
308 | for (ObjectIndex = 0; ObjectIndex < DebuggerSymbolContext->ObjectCount; ObjectIndex++) {\r | |
309 | Object = &DebuggerSymbolContext->Object[ObjectIndex];\r | |
310 | //\r | |
311 | // Go throuth each entry\r | |
312 | //\r | |
313 | for (Index = 0; Index < Object->EntryCount; Index++) {\r | |
314 | ZeroMem (&Object->Entry[Index], sizeof(Object->Entry[Index]));\r | |
315 | }\r | |
316 | ZeroMem (Object->Name, sizeof(Object->Name));\r | |
317 | Object->EntryCount = 0;\r | |
318 | Object->BaseAddress = 0;\r | |
319 | Object->StartEntrypointRVA = 0;\r | |
320 | Object->MainEntrypointRVA = 0;\r | |
321 | //\r | |
322 | // Free source buffer\r | |
323 | //\r | |
324 | for (Index = 0; Object->SourceBuffer[Index] != NULL; Index++) {\r | |
325 | gBS->FreePool (Object->SourceBuffer[Index]);\r | |
326 | Object->SourceBuffer[Index] = NULL;\r | |
327 | }\r | |
328 | }\r | |
329 | DebuggerSymbolContext->ObjectCount = 0;\r | |
330 | \r | |
331 | return ;\r | |
332 | }\r | |
333 | \r | |
334 | EFI_STATUS\r | |
335 | InitDebuggerPrivateData (\r | |
336 | IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r | |
337 | IN EFI_EXCEPTION_TYPE ExceptionType,\r | |
338 | IN EFI_SYSTEM_CONTEXT SystemContext,\r | |
339 | IN BOOLEAN Initialized\r | |
340 | )\r | |
341 | /*++\r | |
342 | \r | |
343 | Routine Description:\r | |
344 | \r | |
345 | Initialize Debugger private data structure\r | |
346 | \r | |
347 | Arguments:\r | |
348 | \r | |
349 | DebuggerPrivate - EBC Debugger private data structure\r | |
350 | InterruptType - Interrupt type.\r | |
351 | SystemContext - EBC system context.\r | |
352 | Initialized - Whether the DebuggerPrivate data is initialized.\r | |
353 | \r | |
354 | Returns:\r | |
355 | \r | |
356 | None\r | |
357 | \r | |
358 | --*/\r | |
359 | {\r | |
360 | //\r | |
361 | // clear STEP flag in any condition.\r | |
362 | //\r | |
0978bd0d HW |
363 | if (SystemContext.SystemContextEbc->Flags & ((UINT64) VMFLAGS_STEP)) {\r |
364 | SystemContext.SystemContextEbc->Flags &= ~((UINT64) VMFLAGS_STEP);\r | |
748edcd5 PB |
365 | }\r |
366 | \r | |
367 | if (!Initialized) {\r | |
368 | //\r | |
369 | // Initialize everything\r | |
370 | //\r | |
371 | DebuggerPrivate->InstructionNumber = EFI_DEBUG_DEFAULT_INSTRUCTION_NUMBER;\r | |
372 | \r | |
373 | DebuggerPrivate->DebuggerBreakpointCount = 0;\r | |
374 | ZeroMem (DebuggerPrivate->DebuggerBreakpointContext, sizeof(DebuggerPrivate->DebuggerBreakpointContext));\r | |
375 | \r | |
376 | // DebuggerPrivate->StatusFlags = 0;\r | |
377 | \r | |
378 | DebuggerPrivate->DebuggerSymbolContext.DisplaySymbol = TRUE;\r | |
379 | DebuggerPrivate->DebuggerSymbolContext.DisplayCodeOnly = FALSE;\r | |
380 | DebuggerPrivate->DebuggerSymbolContext.ObjectCount = 0;\r | |
381 | } else {\r | |
382 | //\r | |
383 | // Already initialized, just check Breakpoint here.\r | |
384 | //\r | |
385 | if (ExceptionType == EXCEPT_EBC_BREAKPOINT) {\r | |
386 | EdbCheckBreakpoint (DebuggerPrivate, SystemContext);\r | |
387 | }\r | |
388 | \r | |
389 | //\r | |
390 | // Clear all breakpoint\r | |
391 | //\r | |
392 | EdbClearAllBreakpoint (DebuggerPrivate, FALSE);\r | |
393 | }\r | |
394 | \r | |
395 | //\r | |
396 | // Set Scope to currentl IP. (Note: Check Breakpoint may change Ip)\r | |
397 | //\r | |
398 | DebuggerPrivate->InstructionScope = SystemContext.SystemContextEbc->Ip;\r | |
399 | \r | |
400 | //\r | |
401 | // Done\r | |
402 | //\r | |
403 | return EFI_SUCCESS;\r | |
404 | }\r | |
405 | \r | |
406 | EFI_STATUS\r | |
407 | DeinitDebuggerPrivateData (\r | |
408 | IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r | |
409 | IN EFI_EXCEPTION_TYPE ExceptionType,\r | |
410 | IN EFI_SYSTEM_CONTEXT SystemContext,\r | |
411 | IN BOOLEAN Initialized\r | |
412 | )\r | |
413 | /*++\r | |
414 | \r | |
415 | Routine Description:\r | |
416 | \r | |
417 | De-initialize Debugger private data structure\r | |
418 | \r | |
419 | Arguments:\r | |
420 | \r | |
421 | DebuggerPrivate - EBC Debugger private data structure\r | |
422 | InterruptType - Interrupt type.\r | |
423 | SystemContext - EBC system context.\r | |
424 | Initialized - Whether the DebuggerPrivate data is initialized.\r | |
425 | \r | |
426 | Returns:\r | |
427 | \r | |
428 | None\r | |
429 | \r | |
430 | --*/\r | |
431 | {\r | |
432 | if (!Initialized) {\r | |
433 | //\r | |
434 | // If it does not want initialized state, de-init everything\r | |
435 | //\r | |
436 | DebuggerPrivate->FeatureFlags = EFI_DEBUG_FLAG_EBC_BOE | EFI_DEBUG_FLAG_EBC_BOT;\r | |
437 | DebuggerPrivate->CallStackEntryCount = 0;\r | |
438 | DebuggerPrivate->TraceEntryCount = 0;\r | |
439 | ZeroMem (DebuggerPrivate->CallStackEntry, sizeof(DebuggerPrivate->CallStackEntry));\r | |
440 | ZeroMem (DebuggerPrivate->TraceEntry, sizeof(DebuggerPrivate->TraceEntry));\r | |
441 | \r | |
442 | //\r | |
443 | // Clear all breakpoint\r | |
444 | //\r | |
445 | EdbClearAllBreakpoint (DebuggerPrivate, TRUE);\r | |
446 | \r | |
447 | //\r | |
448 | // Clear symbol\r | |
449 | //\r | |
450 | EdbClearSymbol (DebuggerPrivate);\r | |
451 | } else {\r | |
452 | //\r | |
453 | // If it wants to keep initialized state, just set breakpoint.\r | |
454 | //\r | |
455 | EdbSetAllBreakpoint (DebuggerPrivate);\r | |
456 | }\r | |
457 | \r | |
458 | //\r | |
459 | // Clear Step context\r | |
460 | //\r | |
461 | ZeroMem (&mDebuggerPrivate.StepContext, sizeof(mDebuggerPrivate.StepContext));\r | |
462 | DebuggerPrivate->StatusFlags = 0;\r | |
463 | \r | |
464 | //\r | |
465 | // Done\r | |
466 | //\r | |
467 | return EFI_SUCCESS;\r | |
468 | }\r | |
469 | \r | |
470 | VOID\r | |
471 | PrintExceptionReason (\r | |
472 | IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r | |
473 | IN EFI_EXCEPTION_TYPE ExceptionType,\r | |
474 | IN EFI_SYSTEM_CONTEXT SystemContext,\r | |
475 | IN BOOLEAN Initialized\r | |
476 | )\r | |
477 | /*++\r | |
478 | \r | |
479 | Routine Description:\r | |
480 | \r | |
481 | Print the reason of current break to EbcDebugger.\r | |
482 | \r | |
483 | Arguments:\r | |
484 | \r | |
485 | DebuggerPrivate - EBC Debugger private data structure\r | |
486 | InterruptType - Interrupt type.\r | |
487 | SystemContext - EBC system context.\r | |
488 | Initialized - Whether the DebuggerPrivate data is initialized.\r | |
489 | \r | |
490 | Returns:\r | |
491 | \r | |
492 | None\r | |
493 | \r | |
494 | --*/\r | |
495 | {\r | |
496 | //\r | |
497 | // Print break status\r | |
498 | //\r | |
499 | if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_GT) == EFI_DEBUG_FLAG_EBC_GT) {\r | |
500 | EDBPrint (L"Break on GoTil\n");\r | |
501 | } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOC) == EFI_DEBUG_FLAG_EBC_BOC) {\r | |
502 | EDBPrint (L"Break on CALL\n");\r | |
503 | } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOCX) == EFI_DEBUG_FLAG_EBC_BOCX) {\r | |
504 | EDBPrint (L"Break on CALLEX\n");\r | |
505 | } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOR) == EFI_DEBUG_FLAG_EBC_BOR) {\r | |
506 | EDBPrint (L"Break on RET\n");\r | |
507 | } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOE) == EFI_DEBUG_FLAG_EBC_BOE) {\r | |
508 | EDBPrint (L"Break on Entrypoint\n");\r | |
509 | } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOT) == EFI_DEBUG_FLAG_EBC_BOT) {\r | |
510 | EDBPrint (L"Break on Thunk\n");\r | |
511 | } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_STEPOVER) == EFI_DEBUG_FLAG_EBC_STEPOVER) {\r | |
512 | EDBPrint (L"Break on StepOver\n");\r | |
513 | } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_STEPOUT) == EFI_DEBUG_FLAG_EBC_STEPOUT) {\r | |
514 | EDBPrint (L"Break on StepOut\n");\r | |
515 | } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BP) == EFI_DEBUG_FLAG_EBC_BP) {\r | |
516 | EDBPrint (L"Break on Breakpoint\n");\r | |
517 | } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOK) == EFI_DEBUG_FLAG_EBC_BOK) {\r | |
518 | EDBPrint (L"Break on Key\n");\r | |
519 | } else {\r | |
520 | EDBPrint (L"Exception Type - %x", (UINTN)ExceptionType);\r | |
521 | if ((ExceptionType >= EXCEPT_EBC_UNDEFINED) && (ExceptionType <= EXCEPT_EBC_STEP)) {\r | |
522 | EDBPrint (L" (%s)\n", mExceptionStr[ExceptionType]);\r | |
523 | } else {\r | |
524 | EDBPrint (L"\n");\r | |
525 | }\r | |
526 | }\r | |
527 | \r | |
528 | return ;\r | |
529 | }\r | |
530 | \r | |
531 | VOID\r | |
532 | EFIAPI\r | |
533 | EdbExceptionHandler (\r | |
534 | IN EFI_EXCEPTION_TYPE ExceptionType,\r | |
535 | IN OUT EFI_SYSTEM_CONTEXT SystemContext\r | |
536 | )\r | |
537 | /*++\r | |
538 | \r | |
539 | Routine Description:\r | |
540 | \r | |
541 | The default Exception Callback for the VM interpreter.\r | |
542 | In this function, we report status code, and print debug information\r | |
543 | about EBC_CONTEXT, then dead loop.\r | |
544 | \r | |
545 | Arguments:\r | |
546 | \r | |
547 | InterruptType - Interrupt type.\r | |
548 | SystemContext - EBC system context.\r | |
549 | \r | |
550 | Returns:\r | |
551 | \r | |
552 | None\r | |
553 | \r | |
554 | --*/\r | |
555 | {\r | |
556 | CHAR16 InputBuffer[EFI_DEBUG_INPUS_BUFFER_SIZE];\r | |
557 | CHAR16 *CommandArg;\r | |
558 | EFI_DEBUGGER_COMMAND DebuggerCommand;\r | |
559 | EFI_DEBUG_STATUS DebugStatus;\r | |
560 | STATIC BOOLEAN mInitialized = FALSE;\r | |
561 | \r | |
562 | DEBUG ((DEBUG_ERROR, "Hello EBC Debugger!\n"));\r | |
563 | \r | |
564 | if (!mInitialized) {\r | |
565 | //\r | |
566 | // Print version\r | |
567 | //\r | |
568 | EDBPrint (\r | |
569 | L"EBC Interpreter Version - %d.%d\n",\r | |
570 | (UINTN)VM_MAJOR_VERSION,\r | |
571 | (UINTN)VM_MINOR_VERSION\r | |
572 | );\r | |
573 | EDBPrint (\r | |
574 | L"EBC Debugger Version - %d.%d\n",\r | |
575 | (UINTN)EBC_DEBUGGER_MAJOR_VERSION,\r | |
576 | (UINTN)EBC_DEBUGGER_MINOR_VERSION\r | |
577 | );\r | |
578 | }\r | |
579 | //\r | |
580 | // Init Private Data\r | |
581 | //\r | |
582 | InitDebuggerPrivateData (&mDebuggerPrivate, ExceptionType, SystemContext, mInitialized);\r | |
583 | \r | |
584 | //\r | |
585 | // EDBPrint basic info\r | |
586 | //\r | |
587 | PrintExceptionReason (&mDebuggerPrivate, ExceptionType, SystemContext, mInitialized);\r | |
588 | \r | |
589 | EdbShowDisasm (&mDebuggerPrivate, SystemContext);\r | |
590 | // EFI_BREAKPOINT ();\r | |
591 | \r | |
592 | if (!mInitialized) {\r | |
593 | //\r | |
594 | // Interactive with user\r | |
595 | //\r | |
596 | EDBPrint (L"\nPlease enter command now, \'h\' for help.\n");\r | |
597 | EDBPrint (L"(Using <Command> -b <...> to enable page break.)\n");\r | |
598 | }\r | |
599 | mInitialized = TRUE;\r | |
600 | \r | |
601 | //\r | |
602 | // Dispatch each command\r | |
603 | //\r | |
604 | while (TRUE) {\r | |
605 | //\r | |
606 | // Get user input\r | |
607 | //\r | |
608 | Input (L"\n\r" EFI_DEBUG_PROMPT_STRING, InputBuffer, EFI_DEBUG_INPUS_BUFFER_SIZE);\r | |
609 | EDBPrint (L"\n");\r | |
610 | \r | |
611 | //\r | |
612 | // Get command\r | |
613 | //\r | |
614 | DebuggerCommand = MatchDebuggerCommand (InputBuffer, &CommandArg);\r | |
615 | if (DebuggerCommand == NULL) {\r | |
616 | EDBPrint (L"ERROR: Command not found!\n");\r | |
617 | continue;\r | |
618 | }\r | |
619 | \r | |
620 | //\r | |
621 | // Check PageBreak;\r | |
622 | //\r | |
623 | if (CommandArg != NULL) {\r | |
624 | if (StriCmp (CommandArg, L"-b") == 0) {\r | |
625 | CommandArg = StrGetNextTokenLine (L" ");\r | |
626 | mDebuggerPrivate.EnablePageBreak = TRUE;\r | |
627 | }\r | |
628 | }\r | |
629 | \r | |
630 | //\r | |
631 | // Dispatch command\r | |
632 | //\r | |
633 | DebugStatus = DebuggerCommand (CommandArg, &mDebuggerPrivate, ExceptionType, SystemContext);\r | |
634 | mDebuggerPrivate.EnablePageBreak = FALSE;\r | |
635 | \r | |
636 | //\r | |
637 | // Check command return status\r | |
638 | //\r | |
639 | if (DebugStatus == EFI_DEBUG_RETURN) {\r | |
640 | mInitialized = FALSE;\r | |
641 | break;\r | |
642 | } else if (DebugStatus == EFI_DEBUG_BREAK) {\r | |
643 | break;\r | |
644 | } else if (DebugStatus == EFI_DEBUG_CONTINUE) {\r | |
645 | continue;\r | |
646 | } else {\r | |
647 | ASSERT (FALSE);\r | |
648 | }\r | |
649 | }\r | |
650 | \r | |
651 | //\r | |
652 | // Deinit Private Data\r | |
653 | //\r | |
654 | DeinitDebuggerPrivateData (&mDebuggerPrivate, ExceptionType, SystemContext, mInitialized);\r | |
655 | \r | |
656 | DEBUG ((DEBUG_ERROR, "Goodbye EBC Debugger!\n"));\r | |
657 | \r | |
658 | return;\r | |
659 | }\r |