]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCommand.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / EbcDebugger / EdbCommand.c
1 /** @file
2
3 Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
4 SPDX-License-Identifier: BSD-2-Clause-Patent
5
6
7 **/
8
9 #include "Edb.h"
10
11 //
12 // Debugger Command Table
13 //
14 EFI_DEBUGGER_COMMAND_SET mDebuggerCommandSet[] = {
15 //
16 // Execution
17 //
18 {
19 L"G",
20 L"G/[F5] - continue to run the program\n",
21 L"The go command is used to cause the debugger to not interrupt execution of the EBC image. The debugger will only break execution of the interpreter if an exception is encountered (including an EBC breakpoint).\n\n",
22 L"G [til <Address|Symbol>]\n"
23 L" (No Argument) - It means continue run the program.\n"
24 L" til - It means continuing run the program till IP is the Address.\n"
25 L" <Address> - The hexical address user want to break at.\n"
26 L" <Symbol> - The symbol name for target address user want to break at. It has following format [MapFileName:]SymbolName\n",
27 L"Execution:\n",
28 { SCAN_F5, CHAR_NULL },
29 DebuggerGo
30 },
31 {
32 L"T",
33 L"T/[F8] - step into\n",
34 L"The step into command will cause the EBC debugger to step a single instruction. If the instruction is a call to internal code (CALL), then the debugger will break at the new function CALL.\n\n",
35 L"T\n"
36 L" (No Argument)\n",
37 L"",
38 { SCAN_F8, CHAR_NULL },
39 DebuggerStepInto
40 },
41 {
42 L"P",
43 L"P/[F10] - step over\n",
44 L"The step over command will cause the EBC debugger to step a single instruction. If the instruction is a call to internal code (CALL), then the external call will be made and the debugger will break at the instruction following the CALL.\n\n",
45 L"P\n"
46 L" (No Argument)\n",
47 L"",
48 { SCAN_F10, CHAR_NULL },
49 DebuggerStepOver
50 },
51 {
52 L"O",
53 L"O/[F11] - step out\n",
54 L"The step out command causes the EBC debugger to step out function calls. The function will be executed, but the debugger will stop after the called function returns.\n\n",
55 L"O\n"
56 L" (No Argument)\n",
57 L"",
58 { SCAN_F11, CHAR_NULL },
59 DebuggerStepOut
60 },
61 {
62 L"Q",
63 L"Q - reset the debugger to default value and go\n",
64 L"The quit command will reset the debugger to default value and go.\n\n",
65 L"Q\n"
66 L" (No Argument)\n",
67 L"",
68 { SCAN_NULL, CHAR_NULL },
69 DebuggerQuit
70 },
71 //
72 // Break
73 //
74 {
75 L"BOC",
76 L"BO[C|CX|R|E|T|K] - break on CALL/CALLEX/RET/Entrypoint/Native Thunk/Key\n",
77 L"Enabling break-on-call will cause the debugger to halt execution and display the debugger prompt prior to executing any EBC CALL (to EBC) instructions.\n\n",
78 L"BOC [on|off]\n"
79 L" (No Argument) - show current state\n"
80 L" on - enable break-on-call\n"
81 L" off - disable break-on-call\n",
82 L"Break:\n",
83 { SCAN_NULL, CHAR_NULL },
84 DebuggerBreakOnCALL
85 },
86 {
87 L"BOCX",
88 L"",
89 L"Enabling break-on-callex will cause the debugger to halt execution and display the debugger prompt prior to executing EBC CALLEX (thunk out) instructions.\n\n",
90 L"BOCX [on|off]\n"
91 L" (No Argument) - show current state\n"
92 L" on - enable break-on-callex\n"
93 L" off - disable break-on-callex\n",
94 L"",
95 { SCAN_NULL, CHAR_NULL },
96 DebuggerBreakOnCALLEX
97 },
98 {
99 L"BOR",
100 L"",
101 L"Enabling break-on-return will cause the debugger to halt execution and display the debugger prompt prior to executing EBC RET instructions.\n\n",
102 L"BOR [on|off]\n"
103 L" (No Argument) - show current state\n"
104 L" on - enable break-on-return\n"
105 L" off - disable break-on-return\n",
106 L"",
107 { SCAN_NULL, CHAR_NULL },
108 DebuggerBreakOnRET
109 },
110 {
111 L"BOE",
112 L"",
113 L"Enabling break-on-entrypoint will cause the debugger to halt execution and display the debugger prompt prior to start a driver entry point. (Default is on)\n\n",
114 L"BOE [on|off]\n"
115 L" (No Argument) - show current state\n"
116 L" on - enable break-on-entrypoint\n"
117 L" off - disable break-on-entrypoint\n",
118 L"",
119 { SCAN_NULL, CHAR_NULL },
120 DebuggerBreakOnEntrypoint
121 },
122 {
123 L"BOT",
124 L"",
125 L"Enabling break-on-thunk will cause the debugger to halt execution and display the debugger prompt prior to start native call EBC thunk. (Default is on)\n\n",
126 L"BOT [on|off]\n"
127 L" (No Argument) - show current state\n"
128 L" on - enable break-on-thunk\n"
129 L" off - disable break-on-thunk\n",
130 L"",
131 { SCAN_NULL, CHAR_NULL },
132 DebuggerBreakOnThunk
133 },
134 {
135 L"BOK",
136 L"",
137 L"Enabling break-on-key will cause the debugger to halt execution and display the debugger prompt after press any key.\n\n",
138 L"BOK [on|off]\n"
139 L" (No Argument) - show current state\n"
140 L" on - enable break-on-key\n"
141 L" off - disable break-on-key\n",
142 L"",
143 { SCAN_NULL, CHAR_NULL },
144 DebuggerBreakOnKey
145 },
146 {
147 L"BL",
148 L"B[L|P|C|D|E] - breakpoint list/set/clear/disable/enable\n",
149 L"List Breakpoint\n\n",
150 L"BL\n"
151 L" (No Argument) - show the state for current breakpoint\n",
152 L"",
153 { SCAN_NULL, CHAR_NULL },
154 DebuggerBreakpointList
155 },
156 {
157 L"BP",
158 L"",
159 L"Set Breakpoint\n\n",
160 L"BP <Address|Symbol>\n"
161 L" <Address> - Hexical breakpoint address\n"
162 L" <Symbol> - Symbol name for breakpoint address. It has following format [MapFileName:]SymbolName.\n",
163 L"",
164 { SCAN_NULL, CHAR_NULL },
165 DebuggerBreakpointSet
166 },
167 {
168 L"BC",
169 L"",
170 L"Clear Breakpoint\n\n",
171 L"BC <Index>|*\n"
172 L" <Index> - Decimal breakpoint index, which can be got from BL command\n"
173 L" * - For all the breakpoint\n",
174 L"",
175 { SCAN_NULL, CHAR_NULL },
176 DebuggerBreakpointClear
177 },
178 {
179 L"BD",
180 L"",
181 L"Disable Breakpoint\n\n",
182 L"BD <Index>|*\n"
183 L" <Index> - Decimal breakpoint index, which can be got from BL command\n"
184 L" * - For all the breakpoint\n",
185 L"",
186 { SCAN_NULL, CHAR_NULL },
187 DebuggerBreakpointDisable
188 },
189 {
190 L"BE",
191 L"",
192 L"Enable Breakpoint\n\n",
193 L"BE <Index>|*\n"
194 L" <Index> - Decimal breakpoint index, which can be got from BL command\n"
195 L" * - For all the breakpoint\n",
196 L"",
197 { SCAN_NULL, CHAR_NULL },
198 DebuggerBreakpointEnable
199 },
200 //
201 // Information
202 //
203 {
204 L"K",
205 L"K - show/clear call-stack\n",
206 L"The call-stack command will show or clear the current call-stack.\n\n",
207 L"K [p [<ParameterNum>]|c]\n"
208 L" (No Argument) - Show current call-stack\n"
209 L" p - Show current call-stack with parameters\n"
210 L" ParameterNum - Decimal call-stack parameters number, 8 by default, 16 as max\n"
211 L" c - Clear current call-stack\n",
212 L"Information:\n",
213 { SCAN_NULL, CHAR_NULL },
214 DebuggerCallStack
215 },
216 {
217 L"TRACE",
218 L"TRACE - show/clear trace instruction branch\n",
219 L"The trace command will show or clear the latest instruction branch.\n\n",
220 L"TRACE [c]\n"
221 L" (No Argument) - Show current instruction branch\n"
222 L" c - Clear current instruction branch\n",
223 L"",
224 { SCAN_NULL, CHAR_NULL },
225 DebuggerInstructionBranch
226 },
227 {
228 L"R",
229 L"R/[F2] - display/modify register\n",
230 L"The register command is used to display or modify the contents of EBC VM registers. (R0~R7, Flags, IP)\n\n",
231 L"R [<Register> <Value>]\n"
232 L" (No Argument) - Display all registers\n"
233 L" <Register> - EBC VM register name (R0~R7, Flags, ControlFlags, and IP\n"
234 L" <Value> - The Hexical value of register\n",
235 L"",
236 { SCAN_F2, CHAR_NULL },
237 DebuggerRegister
238 },
239 {
240 L"L",
241 L"L/[F4] - show/load instruction assembly count\n",
242 L"The list assembly command will disassemble instructions starting with the current EBC VM instruction pointer. (by default 5 instructions)\n\n",
243 L"L [<Count>]\n"
244 L" (No Argument) - List current assembly code\n"
245 L" Count - The decimal instruction assembly count\n",
246 L"",
247 { SCAN_F4, CHAR_NULL },
248 DebuggerList
249 },
250 {
251 L"SCOPE",
252 L"SCOPE - load scope address\n",
253 L"The scope command will disassemble instructions starting with the Scope. (by default current EBC VM IP)\n\n",
254 L"SCOPE <Address|Symbol>\n"
255 L" <Address> - The Hexical address where user wants to see the assembly code\n"
256 L" <Symbol> - Symbol name for scope address. It has following format [MapFileName:]SymbolName.\n",
257 L"",
258 { SCAN_NULL, CHAR_NULL },
259 DebuggerScope
260 },
261 {
262 L"DB",
263 L"[D|E][B|W|D|Q] - display/modify memory\n",
264 L"Display BYTES Memory\n\n",
265 L"DB <Address|Symbol> [<Count>]\n"
266 L" <Address> - The hexical memory address\n"
267 L" <Symbol> - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"
268 L" <Count> - The hexical memory count (not set means 1)\n",
269 L"",
270 { SCAN_NULL, CHAR_NULL },
271 DebuggerMemoryDB
272 },
273 {
274 L"DW",
275 L"",
276 L"Display WORDS Memory\n\n",
277 L"DW <Address|Symbol> [<Count>]\n"
278 L" <Address> - The hexical memory address\n"
279 L" <Symbol> - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"
280 L" <Count> - The hexical memory count (not set means 1)\n",
281 L"",
282 { SCAN_NULL, CHAR_NULL },
283 DebuggerMemoryDW
284 },
285 {
286 L"DD",
287 L"",
288 L"Display DWORDS Memory\n\n",
289 L"DD <Address|Symbol> [<Count>]\n"
290 L" <Address> - The hexical memory address\n"
291 L" <Symbol> - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"
292 L" <Count> - The hexical memory count (not set means 1)\n",
293 L"",
294 { SCAN_NULL, CHAR_NULL },
295 DebuggerMemoryDD
296 },
297 {
298 L"DQ",
299 L"",
300 L"Display QWORDS Memory\n\n",
301 L"DQ <Address|Symbol> [<Count>]\n"
302 L" <Address> - The hexical memory address\n"
303 L" <Symbol> - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"
304 L" <Count> - The hexical memory count (not set means 1)\n",
305 L"",
306 { SCAN_NULL, CHAR_NULL },
307 DebuggerMemoryDQ
308 },
309 {
310 L"EB",
311 L"",
312 L"Enter BYTES Memory\n\n",
313 L"EB <Address|Symbol> <Value>\n"
314 L" <Address> - The hexical memory address\n"
315 L" <Symbol> - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"
316 L" <Value> - The hexical memory value\n",
317 L"",
318 { SCAN_NULL, CHAR_NULL },
319 DebuggerMemoryEB
320 },
321 {
322 L"EW",
323 L"",
324 L"Enter WORDS Memory\n\n",
325 L"EW <Address|Symbol> <Value>\n"
326 L" <Address> - The hexical memory address\n"
327 L" <Symbol> - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"
328 L" <Value> - The hexical memory value\n",
329 L"",
330 { SCAN_NULL, CHAR_NULL },
331 DebuggerMemoryEW
332 },
333 {
334 L"ED",
335 L"",
336 L"Enter DWORDS Memory\n\n",
337 L"ED <Address|Symbol> <Value>\n"
338 L" <Address> - The hexical memory address\n"
339 L" <Symbol> - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"
340 L" <Value> - The hexical memory value\n",
341 L"",
342 { SCAN_NULL, CHAR_NULL },
343 DebuggerMemoryED
344 },
345 {
346 L"EQ",
347 L"",
348 L"Enter QWORDS Memory\n\n",
349 L"EQ <Address|Symbol> <Value>\n"
350 L" <Address> - The hexical memory address\n"
351 L" <Symbol> - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"
352 L" <Value> - The hexical memory value\n",
353 L"",
354 { SCAN_NULL, CHAR_NULL },
355 DebuggerMemoryEQ
356 },
357 //
358 // Symbol
359 //
360 {
361 L"LN",
362 L"LN - list the symbol\n",
363 L"The show symbol command will list all the current symbol. It can list the symbol in one symbol file, or list the same symbol in all the files. It can also list the symbol according to nearest address.\n\n",
364 L"LN [[F <SymbolFile>] [S <Symbol>]] | <Address>\n"
365 L" (No Argument) - List all the symbol\n"
366 L" F <SymbolFile> - List the symbol in this symbol file only\n"
367 L" S <Symbol> - List this symbol only\n"
368 L" <Address> - The hexical memory address, which user want to find the symbol for.\n",
369 L"Symbol:\n",
370 { SCAN_NULL, CHAR_NULL },
371 DebuggerListSymbol
372 },
373 {
374 L"LOADSYMBOL",
375 L"[UN]LOADSYMBOL - load/unload the symbol file\n",
376 L"The load symbol command will load the ebc map file. Then it parses the function name and global variable, and the print real name when do the disassembly. (Symbol file name should be XXX.MAP)\n\n",
377 L"LOADSYMBOL <SymbolFile> [a]\n"
378 L" SymbolFile - The EBC symbol file (Its name should be XXX.MAP)\n"
379 L" a - Automatically load code files in the same dir\n",
380 L"",
381 { SCAN_NULL, CHAR_NULL },
382 DebuggerLoadSymbol
383 },
384 {
385 L"UNLOADSYMBOL",
386 L"",
387 L"The unload symbol command will unload the ebc map and cod file. After that the name will not be print.\n\n",
388 L"UNLOADSYMBOL <SymbolFile>\n"
389 L" SymbolFile - The EBC symbol file (Its name should be XXX.MAP)\n",
390 L"",
391 { SCAN_NULL, CHAR_NULL },
392 DebuggerUnloadSymbol
393 },
394 {
395 L"LOADCODE",
396 L"[UN]LOADCODE - load/unload the code file\n",
397 L"The load code command will load the ebc cod file. Then it parses the cod file, and the print source code when do the disassembly. (Code file name should be XXX.COD)\n\n",
398 L"LOADCODE <CodeFile> <SymbolFile>\n"
399 L" CodeFile - The EBC code file (Its name should be XXX.COD)\n"
400 L" SymbolFile - The EBC symbol file (Its name should be XXX.MAP)\n",
401 L"",
402 { SCAN_NULL, CHAR_NULL },
403 DebuggerLoadCode
404 },
405 {
406 L"UNLOADCODE",
407 L"",
408 L"The unload code command will unload the ebc cod file. After that the source code will not be print.\n\n",
409 L"UNLOADCODE <CodeFile> <SymbolFile>\n"
410 L" CodeFile - The EBC code file (Its name should be XXX.COD)\n"
411 L" SymbolFile - The EBC symbol file (Its name should be XXX.MAP)\n",
412 L"",
413 { SCAN_NULL, CHAR_NULL },
414 DebuggerUnloadCode
415 },
416 {
417 L"DISPLAYSYMBOL",
418 L"DISPLAYSYMBOL/[F3] - disable/enable the symbol output\n",
419 L"",
420 L"The display symbol command will configure the symbol show or not-show when disassembly.\n\n"
421 L"DISPLAYSYMBOL [on|off]\n"
422 L" (No Argument) - swtich symbol output state to another one\n"
423 L" on - enable symbol output\n"
424 L" off - disable symbol output\n",
425 L"",
426 { SCAN_F3, CHAR_NULL },
427 DebuggerDisplaySymbol
428 },
429 {
430 L"DISPLAYCODE",
431 L"DISPLAYCODE/[F6] - disable/enable the source code only output\n",
432 L"",
433 L"The display code command will configure the source code only show or misc source code with assembly.\n\n"
434 L"DISPLAYCODE [on|off]\n"
435 L" (No Argument) - swtich source only output state to another one\n"
436 L" on - enable source only output\n"
437 L" off - disable source only output\n",
438 L"",
439 { SCAN_F6, CHAR_NULL },
440 DebuggerDisplayCode
441 },
442 //
443 // Other
444 //
445 {
446 L"H",
447 L"",
448 L"The help command will print help information for each command\n\n",
449 L"H [<Command>]\n",
450 L"",
451 { SCAN_F1, CHAR_NULL },
452 DebuggerHelp
453 },
454
455 /*
456 //
457 // Extended
458 //
459 {
460 L"!IB",
461 L"![I|O][B|W|D] - display/modify IO\n",
462 L"",
463 L"!IB <Address>\n",
464 L"Extended:\n",
465 {SCAN_NULL, CHAR_NULL},
466 DebuggerExtIoIB
467 },
468 {
469 L"!IW",
470 L"",
471 L"",
472 L"!IW <Address>\n",
473 L"",
474 {SCAN_NULL, CHAR_NULL},
475 DebuggerExtIoIW
476 },
477 {
478 L"!ID",
479 L"",
480 L"",
481 L"!ID <Address>\n",
482 L"",
483 {SCAN_NULL, CHAR_NULL},
484 DebuggerExtIoID
485 },
486 {
487 L"!OB",
488 L"",
489 L"",
490 L"!OB <Address> <Value>\n",
491 L"",
492 {SCAN_NULL, CHAR_NULL},
493 DebuggerExtIoOB
494 },
495 {
496 L"!OW",
497 L"",
498 L"",
499 L"!OW <Address> <Value>\n",
500 L"",
501 {SCAN_NULL, CHAR_NULL},
502 DebuggerExtIoOW
503 },
504 {
505 L"!OD",
506 L"",
507 L"",
508 L"!OD <Address> <Value>\n",
509 L"",
510 {SCAN_NULL, CHAR_NULL},
511 DebuggerExtIoOD
512 },
513 {
514 L"!PCIL",
515 L"!PCIL - list PCI device, with BAR\n",
516 L"",
517 L"!PCIL [B]\n",
518 L"",
519 {SCAN_NULL, CHAR_NULL},
520 DebuggerExtPciPCIL
521 },
522 {
523 L"!PCID",
524 L"!PCID - show PCI space\n",
525 L"",
526 L"!PCID Bus Device Function [H|B|E]\n",
527 L"",
528 {SCAN_NULL, CHAR_NULL},
529 DebuggerExtPciPCID
530 },
531 {
532 L"!CFGB",
533 L"!CFG[B|W|D] - show/modify PCI space",
534 L"",
535 L"!CFGB <Address> [<Value>]\n",
536 L"",
537 {SCAN_NULL, CHAR_NULL},
538 DebuggerExtPciCFGB
539 },
540 {
541 L"!CFGW",
542 L"",
543 L"",
544 L"!CFGW <Address> [<Value>]\n",
545 L"",
546 {SCAN_NULL, CHAR_NULL},
547 DebuggerExtPciCFGW
548 },
549 {
550 L"!CFGD",
551 L"",
552 L"",
553 L"!CFGD <Address> [<Value>]\n",
554 L"",
555 {SCAN_NULL, CHAR_NULL},
556 DebuggerExtPciCFGD
557 },
558 */
559 {
560 NULL,
561 NULL,
562 NULL,
563 NULL,
564 NULL,
565 { SCAN_NULL, CHAR_NULL },
566 NULL
567 },
568 };
569
570 /**
571
572 Find the command according to name.
573
574 @param CommandName - Command Name
575 @param CommandArg - Command Argument
576
577 @return Not NULL - The DebuggerCommand is found successfully
578 @return NULL - not found
579
580 **/
581 EFI_DEBUGGER_COMMAND
582 MatchDebuggerCommand (
583 IN CHAR16 *CommandName,
584 IN CHAR16 **CommandArg
585 )
586 {
587 UINTN Index;
588 CHAR16 *Temp;
589
590 //
591 // Get Command Name
592 //
593 Temp = StrGetNewTokenLine (CommandName, L" ");
594 CommandName = Temp;
595 //
596 // Get Command Argument
597 //
598 Temp = StrGetNextTokenLine (L" ");
599 *CommandArg = Temp;
600
601 if (CommandName == NULL) {
602 return NULL;
603 }
604
605 //
606 // Go through each command, check the CommandName
607 //
608 for (Index = 0; mDebuggerCommandSet[Index].CommandName != NULL; Index++) {
609 if (StriCmp (CommandName, mDebuggerCommandSet[Index].CommandName) == 0) {
610 //
611 // Found
612 //
613 return mDebuggerCommandSet[Index].CommandFunc;
614 }
615 }
616
617 //
618 // Not found
619 //
620 return NULL;
621 }
622
623 /**
624
625 Find the command name according to the function key.
626
627 @param CommandKey - Command Function Key
628
629 @return Not NULL - The DebuggerName is found successfully
630 @return NULL - not found
631
632 **/
633 CHAR16 *
634 GetCommandNameByKey (
635 IN EFI_INPUT_KEY CommandKey
636 )
637 {
638 UINTN Index;
639
640 //
641 // Go through each command, check the CommandKey
642 //
643 for (Index = 0; mDebuggerCommandSet[Index].CommandName != NULL; Index++) {
644 if ((mDebuggerCommandSet[Index].CommandKey.UnicodeChar == CommandKey.UnicodeChar) &&
645 (mDebuggerCommandSet[Index].CommandKey.ScanCode == CommandKey.ScanCode))
646 {
647 //
648 // Found
649 //
650 return mDebuggerCommandSet[Index].CommandName;
651 }
652 }
653
654 //
655 // Not found
656 //
657 return NULL;
658 }