dbinput.c revision 1.1.1.18 1 /*******************************************************************************
2 *
3 * Module Name: dbinput - user front-end to the AML debugger
4 *
5 ******************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2019, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44 #include "acpi.h"
45 #include "accommon.h"
46 #include "acdebug.h"
47
48 #ifdef ACPI_APPLICATION
49 #include "acapps.h"
50 #endif
51
52 #define _COMPONENT ACPI_CA_DEBUGGER
53 ACPI_MODULE_NAME ("dbinput")
54
55
56 /* Local prototypes */
57
58 static UINT32
59 AcpiDbGetLine (
60 char *InputBuffer);
61
62 static UINT32
63 AcpiDbMatchCommand (
64 char *UserCommand);
65
66 static void
67 AcpiDbDisplayCommandInfo (
68 const char *Command,
69 BOOLEAN DisplayAll);
70
71 static void
72 AcpiDbDisplayHelp (
73 char *Command);
74
75 static BOOLEAN
76 AcpiDbMatchCommandHelp (
77 const char *Command,
78 const ACPI_DB_COMMAND_HELP *Help);
79
80
81 /*
82 * Top-level debugger commands.
83 *
84 * This list of commands must match the string table below it
85 */
86 enum AcpiExDebuggerCommands
87 {
88 CMD_NOT_FOUND = 0,
89 CMD_NULL,
90 CMD_ALLOCATIONS,
91 CMD_ARGS,
92 CMD_ARGUMENTS,
93 CMD_BREAKPOINT,
94 CMD_BUSINFO,
95 CMD_CALL,
96 CMD_DEBUG,
97 CMD_DISASSEMBLE,
98 CMD_DISASM,
99 CMD_DUMP,
100 CMD_EVALUATE,
101 CMD_EXECUTE,
102 CMD_EXIT,
103 CMD_FIELDS,
104 CMD_FIND,
105 CMD_GO,
106 CMD_HANDLERS,
107 CMD_HELP,
108 CMD_HELP2,
109 CMD_HISTORY,
110 CMD_HISTORY_EXE,
111 CMD_HISTORY_LAST,
112 CMD_INFORMATION,
113 CMD_INTEGRITY,
114 CMD_INTO,
115 CMD_LEVEL,
116 CMD_LIST,
117 CMD_LOCALS,
118 CMD_LOCKS,
119 CMD_METHODS,
120 CMD_NAMESPACE,
121 CMD_NOTIFY,
122 CMD_OBJECTS,
123 CMD_OSI,
124 CMD_OWNER,
125 CMD_PATHS,
126 CMD_PREDEFINED,
127 CMD_PREFIX,
128 CMD_QUIT,
129 CMD_REFERENCES,
130 CMD_RESOURCES,
131 CMD_RESULTS,
132 CMD_SET,
133 CMD_STATS,
134 CMD_STOP,
135 CMD_TABLES,
136 CMD_TEMPLATE,
137 CMD_TRACE,
138 CMD_TREE,
139 CMD_TYPE,
140 #ifdef ACPI_APPLICATION
141 CMD_ENABLEACPI,
142 CMD_EVENT,
143 CMD_GPE,
144 CMD_GPES,
145 CMD_SCI,
146 CMD_SLEEP,
147
148 CMD_CLOSE,
149 CMD_LOAD,
150 CMD_OPEN,
151 CMD_UNLOAD,
152
153 CMD_TERMINATE,
154 CMD_BACKGROUND,
155 CMD_THREADS,
156
157 CMD_TEST,
158 #endif
159 };
160
161 #define CMD_FIRST_VALID 2
162
163
164 /* Second parameter is the required argument count */
165
166 static const ACPI_DB_COMMAND_INFO AcpiGbl_DbCommands[] =
167 {
168 {"<NOT FOUND>", 0},
169 {"<NULL>", 0},
170 {"ALLOCATIONS", 0},
171 {"ARGS", 0},
172 {"ARGUMENTS", 0},
173 {"BREAKPOINT", 1},
174 {"BUSINFO", 0},
175 {"CALL", 0},
176 {"DEBUG", 1},
177 {"DISASSEMBLE", 1},
178 {"DISASM", 1},
179 {"DUMP", 1},
180 {"EVALUATE", 1},
181 {"EXECUTE", 1},
182 {"EXIT", 0},
183 {"FIELDS", 1},
184 {"FIND", 1},
185 {"GO", 0},
186 {"HANDLERS", 0},
187 {"HELP", 0},
188 {"?", 0},
189 {"HISTORY", 0},
190 {"!", 1},
191 {"!!", 0},
192 {"INFORMATION", 0},
193 {"INTEGRITY", 0},
194 {"INTO", 0},
195 {"LEVEL", 0},
196 {"LIST", 0},
197 {"LOCALS", 0},
198 {"LOCKS", 0},
199 {"METHODS", 0},
200 {"NAMESPACE", 0},
201 {"NOTIFY", 2},
202 {"OBJECTS", 0},
203 {"OSI", 0},
204 {"OWNER", 1},
205 {"PATHS", 0},
206 {"PREDEFINED", 0},
207 {"PREFIX", 0},
208 {"QUIT", 0},
209 {"REFERENCES", 1},
210 {"RESOURCES", 0},
211 {"RESULTS", 0},
212 {"SET", 3},
213 {"STATS", 1},
214 {"STOP", 0},
215 {"TABLES", 0},
216 {"TEMPLATE", 1},
217 {"TRACE", 1},
218 {"TREE", 0},
219 {"TYPE", 1},
220 #ifdef ACPI_APPLICATION
221 {"ENABLEACPI", 0},
222 {"EVENT", 1},
223 {"GPE", 1},
224 {"GPES", 0},
225 {"SCI", 0},
226 {"SLEEP", 0},
227
228 {"CLOSE", 0},
229 {"LOAD", 1},
230 {"OPEN", 1},
231 {"UNLOAD", 1},
232
233 {"TERMINATE", 0},
234 {"BACKGROUND", 1},
235 {"THREADS", 3},
236
237 {"TEST", 1},
238 #endif
239 {NULL, 0}
240 };
241
242 /*
243 * Help for all debugger commands. First argument is the number of lines
244 * of help to output for the command.
245 *
246 * Note: Some commands are not supported by the kernel-level version of
247 * the debugger.
248 */
249 static const ACPI_DB_COMMAND_HELP AcpiGbl_DbCommandHelp[] =
250 {
251 {0, "\nNamespace Access:", "\n"},
252 {1, " Businfo", "Display system bus info\n"},
253 {1, " Disassemble <Method>", "Disassemble a control method\n"},
254 {1, " Find <AcpiName> (? is wildcard)", "Find ACPI name(s) with wildcards\n"},
255 {1, " Integrity", "Validate namespace integrity\n"},
256 {1, " Methods", "Display list of loaded control methods\n"},
257 {1, " Fields <AddressSpaceId>", "Display list of loaded field units by space ID\n"},
258 {1, " Namespace [Object] [Depth]", "Display loaded namespace tree/subtree\n"},
259 {1, " Notify <Object> <Value>", "Send a notification on Object\n"},
260 {1, " Objects [ObjectType]", "Display summary of all objects or just given type\n"},
261 {1, " Owner <OwnerId> [Depth]", "Display loaded namespace by object owner\n"},
262 {1, " Paths", "Display full pathnames of namespace objects\n"},
263 {1, " Predefined", "Check all predefined names\n"},
264 {1, " Prefix [<Namepath>]", "Set or Get current execution prefix\n"},
265 {1, " References <Addr>", "Find all references to object at addr\n"},
266 {1, " Resources [DeviceName]", "Display Device resources (no arg = all devices)\n"},
267 {1, " Set N <NamedObject> <Value>", "Set value for named integer\n"},
268 {1, " Template <Object>", "Format/dump a Buffer/ResourceTemplate\n"},
269 {1, " Type <Object>", "Display object type\n"},
270
271 {0, "\nControl Method Execution:", "\n"},
272 {1, " Evaluate <Namepath> [Arguments]", "Evaluate object or control method\n"},
273 {1, " Execute <Namepath> [Arguments]", "Synonym for Evaluate\n"},
274 #ifdef ACPI_APPLICATION
275 {1, " Background <Namepath> [Arguments]", "Evaluate object/method in a separate thread\n"},
276 {1, " Thread <Threads><Loops><NamePath>", "Spawn threads to execute method(s)\n"},
277 #endif
278 {1, " Debug <Namepath> [Arguments]", "Single-Step a control method\n"},
279 {7, " [Arguments] formats:", "Control method argument formats\n"},
280 {1, " Hex Integer", "Integer\n"},
281 {1, " \"Ascii String\"", "String\n"},
282 {1, " (Hex Byte List)", "Buffer\n"},
283 {1, " (01 42 7A BF)", "Buffer example (4 bytes)\n"},
284 {1, " [Package Element List]", "Package\n"},
285 {1, " [0x01 0x1234 \"string\"]", "Package example (3 elements)\n"},
286
287 {0, "\nMiscellaneous:", "\n"},
288 {1, " Allocations", "Display list of current memory allocations\n"},
289 {2, " Dump <Address>|<Namepath>", "\n"},
290 {0, " [Byte|Word|Dword|Qword]", "Display ACPI objects or memory\n"},
291 {1, " Handlers", "Info about global handlers\n"},
292 {1, " Help [Command]", "This help screen or individual command\n"},
293 {1, " History", "Display command history buffer\n"},
294 {1, " Level <DebugLevel>] [console]", "Get/Set debug level for file or console\n"},
295 {1, " Locks", "Current status of internal mutexes\n"},
296 {1, " Osi [Install|Remove <name>]", "Display or modify global _OSI list\n"},
297 {1, " Quit or Exit", "Exit this command\n"},
298 {8, " Stats <SubCommand>", "Display namespace and memory statistics\n"},
299 {1, " Allocations", "Display list of current memory allocations\n"},
300 {1, " Memory", "Dump internal memory lists\n"},
301 {1, " Misc", "Namespace search and mutex stats\n"},
302 {1, " Objects", "Summary of namespace objects\n"},
303 {1, " Sizes", "Sizes for each of the internal objects\n"},
304 {1, " Stack", "Display CPU stack usage\n"},
305 {1, " Tables", "Info about current ACPI table(s)\n"},
306 {1, " Tables", "Display info about loaded ACPI tables\n"},
307 #ifdef ACPI_APPLICATION
308 {1, " Terminate", "Delete namespace and all internal objects\n"},
309 #endif
310 {1, " ! <CommandNumber>", "Execute command from history buffer\n"},
311 {1, " !!", "Execute last command again\n"},
312
313 {0, "\nMethod and Namespace Debugging:", "\n"},
314 {5, " Trace <State> [<Namepath>] [Once]", "Trace control method execution\n"},
315 {1, " Enable", "Enable all messages\n"},
316 {1, " Disable", "Disable tracing\n"},
317 {1, " Method", "Enable method execution messages\n"},
318 {1, " Opcode", "Enable opcode execution messages\n"},
319 {3, " Test <TestName>", "Invoke a debug test\n"},
320 {1, " Objects", "Read/write/compare all namespace data objects\n"},
321 {1, " Predefined", "Validate all ACPI predefined names (_STA, etc.)\n"},
322 {1, " Execute predefined", "Execute all predefined (public) methods\n"},
323
324 {0, "\nControl Method Single-Step Execution:","\n"},
325 {1, " Arguments (or Args)", "Display method arguments\n"},
326 {1, " Breakpoint <AmlOffset>", "Set an AML execution breakpoint\n"},
327 {1, " Call", "Run to next control method invocation\n"},
328 {1, " Go", "Allow method to run to completion\n"},
329 {1, " Information", "Display info about the current method\n"},
330 {1, " Into", "Step into (not over) a method call\n"},
331 {1, " List [# of Aml Opcodes]", "Display method ASL statements\n"},
332 {1, " Locals", "Display method local variables\n"},
333 {1, " Results", "Display method result stack\n"},
334 {1, " Set <A|L> <#> <Value>", "Set method data (Arguments/Locals)\n"},
335 {1, " Stop", "Terminate control method\n"},
336 {1, " Tree", "Display control method calling tree\n"},
337 {1, " <Enter>", "Single step next AML opcode (over calls)\n"},
338
339 #ifdef ACPI_APPLICATION
340 {0, "\nFile Operations:", "\n"},
341 {1, " Close", "Close debug output file\n"},
342 {1, " Load <Input Filename>", "Load ACPI table from a file\n"},
343 {1, " Open <Output Filename>", "Open a file for debug output\n"},
344 {1, " Unload <Namepath>", "Unload an ACPI table via namespace object\n"},
345
346 {0, "\nHardware Simulation:", "\n"},
347 {1, " EnableAcpi", "Enable ACPI (hardware) mode\n"},
348 {1, " Event <F|G> <Value>", "Generate AcpiEvent (Fixed/GPE)\n"},
349 {1, " Gpe <GpeNum> [GpeBlockDevice]", "Simulate a GPE\n"},
350 {1, " Gpes", "Display info on all GPE devices\n"},
351 {1, " Sci", "Generate an SCI\n"},
352 {1, " Sleep [SleepState]", "Simulate sleep/wake sequence(s) (0-5)\n"},
353 #endif
354 {0, NULL, NULL}
355 };
356
357
358 /*******************************************************************************
359 *
360 * FUNCTION: AcpiDbMatchCommandHelp
361 *
362 * PARAMETERS: Command - Command string to match
363 * Help - Help table entry to attempt match
364 *
365 * RETURN: TRUE if command matched, FALSE otherwise
366 *
367 * DESCRIPTION: Attempt to match a command in the help table in order to
368 * print help information for a single command.
369 *
370 ******************************************************************************/
371
372 static BOOLEAN
373 AcpiDbMatchCommandHelp (
374 const char *Command,
375 const ACPI_DB_COMMAND_HELP *Help)
376 {
377 char *Invocation = Help->Invocation;
378 UINT32 LineCount;
379
380
381 /* Valid commands in the help table begin with a couple of spaces */
382
383 if (*Invocation != ' ')
384 {
385 return (FALSE);
386 }
387
388 while (*Invocation == ' ')
389 {
390 Invocation++;
391 }
392
393 /* Match command name (full command or substring) */
394
395 while ((*Command) && (*Invocation) && (*Invocation != ' '))
396 {
397 if (tolower ((int) *Command) != tolower ((int) *Invocation))
398 {
399 return (FALSE);
400 }
401
402 Invocation++;
403 Command++;
404 }
405
406 /* Print the appropriate number of help lines */
407
408 LineCount = Help->LineCount;
409 while (LineCount)
410 {
411 AcpiOsPrintf ("%-38s : %s", Help->Invocation, Help->Description);
412 Help++;
413 LineCount--;
414 }
415
416 return (TRUE);
417 }
418
419
420 /*******************************************************************************
421 *
422 * FUNCTION: AcpiDbDisplayCommandInfo
423 *
424 * PARAMETERS: Command - Command string to match
425 * DisplayAll - Display all matching commands, or just
426 * the first one (substring match)
427 *
428 * RETURN: None
429 *
430 * DESCRIPTION: Display help information for a Debugger command.
431 *
432 ******************************************************************************/
433
434 static void
435 AcpiDbDisplayCommandInfo (
436 const char *Command,
437 BOOLEAN DisplayAll)
438 {
439 const ACPI_DB_COMMAND_HELP *Next;
440 BOOLEAN Matched;
441
442
443 Next = AcpiGbl_DbCommandHelp;
444 while (Next->Invocation)
445 {
446 Matched = AcpiDbMatchCommandHelp (Command, Next);
447 if (!DisplayAll && Matched)
448 {
449 return;
450 }
451
452 Next++;
453 }
454 }
455
456
457 /*******************************************************************************
458 *
459 * FUNCTION: AcpiDbDisplayHelp
460 *
461 * PARAMETERS: Command - Optional command string to display help.
462 * if not specified, all debugger command
463 * help strings are displayed
464 *
465 * RETURN: None
466 *
467 * DESCRIPTION: Display help for a single debugger command, or all of them.
468 *
469 ******************************************************************************/
470
471 static void
472 AcpiDbDisplayHelp (
473 char *Command)
474 {
475 const ACPI_DB_COMMAND_HELP *Next = AcpiGbl_DbCommandHelp;
476
477
478 if (!Command)
479 {
480 /* No argument to help, display help for all commands */
481
482 AcpiOsPrintf ("\nSummary of AML Debugger Commands\n\n");
483
484 while (Next->Invocation)
485 {
486 AcpiOsPrintf ("%-38s%s", Next->Invocation, Next->Description);
487 Next++;
488 }
489 AcpiOsPrintf ("\n");
490
491 }
492 else
493 {
494 /* Display help for all commands that match the subtring */
495
496 AcpiDbDisplayCommandInfo (Command, TRUE);
497 }
498 }
499
500
501 /*******************************************************************************
502 *
503 * FUNCTION: AcpiDbGetNextToken
504 *
505 * PARAMETERS: String - Command buffer
506 * Next - Return value, end of next token
507 *
508 * RETURN: Pointer to the start of the next token.
509 *
510 * DESCRIPTION: Command line parsing. Get the next token on the command line
511 *
512 ******************************************************************************/
513
514 char *
515 AcpiDbGetNextToken (
516 char *String,
517 char **Next,
518 ACPI_OBJECT_TYPE *ReturnType)
519 {
520 char *Start;
521 UINT32 Depth;
522 ACPI_OBJECT_TYPE Type = ACPI_TYPE_INTEGER;
523
524
525 /* At end of buffer? */
526
527 if (!String || !(*String))
528 {
529 return (NULL);
530 }
531
532 /* Remove any spaces at the beginning */
533
534 if (*String == ' ')
535 {
536 while (*String && (*String == ' '))
537 {
538 String++;
539 }
540
541 if (!(*String))
542 {
543 return (NULL);
544 }
545 }
546
547 switch (*String)
548 {
549 case '"':
550
551 /* This is a quoted string, scan until closing quote */
552
553 String++;
554 Start = String;
555 Type = ACPI_TYPE_STRING;
556
557 /* Find end of string */
558
559 while (*String && (*String != '"'))
560 {
561 String++;
562 }
563 break;
564
565 case '(':
566
567 /* This is the start of a buffer, scan until closing paren */
568
569 String++;
570 Start = String;
571 Type = ACPI_TYPE_BUFFER;
572
573 /* Find end of buffer */
574
575 while (*String && (*String != ')'))
576 {
577 String++;
578 }
579 break;
580
581 case '{':
582
583 /* This is the start of a field unit, scan until closing brace */
584
585 String++;
586 Start = String;
587 Type = ACPI_TYPE_FIELD_UNIT;
588
589 /* Find end of buffer */
590
591 while (*String && (*String != '}'))
592 {
593 String++;
594 }
595 break;
596
597 case '[':
598
599 /* This is the start of a package, scan until closing bracket */
600
601 String++;
602 Depth = 1;
603 Start = String;
604 Type = ACPI_TYPE_PACKAGE;
605
606 /* Find end of package (closing bracket) */
607
608 while (*String)
609 {
610 /* Handle String package elements */
611
612 if (*String == '"')
613 {
614 /* Find end of string */
615
616 String++;
617 while (*String && (*String != '"'))
618 {
619 String++;
620 }
621 if (!(*String))
622 {
623 break;
624 }
625 }
626 else if (*String == '[')
627 {
628 Depth++; /* A nested package declaration */
629 }
630 else if (*String == ']')
631 {
632 Depth--;
633 if (Depth == 0) /* Found final package closing bracket */
634 {
635 break;
636 }
637 }
638
639 String++;
640 }
641 break;
642
643 default:
644
645 Start = String;
646
647 /* Find end of token */
648
649 while (*String && (*String != ' '))
650 {
651 String++;
652 }
653 break;
654 }
655
656 if (!(*String))
657 {
658 *Next = NULL;
659 }
660 else
661 {
662 *String = 0;
663 *Next = String + 1;
664 }
665
666 *ReturnType = Type;
667 return (Start);
668 }
669
670
671 /*******************************************************************************
672 *
673 * FUNCTION: AcpiDbGetLine
674 *
675 * PARAMETERS: InputBuffer - Command line buffer
676 *
677 * RETURN: Count of arguments to the command
678 *
679 * DESCRIPTION: Get the next command line from the user. Gets entire line
680 * up to the next newline
681 *
682 ******************************************************************************/
683
684 static UINT32
685 AcpiDbGetLine (
686 char *InputBuffer)
687 {
688 UINT32 i;
689 UINT32 Count;
690 char *Next;
691 char *This;
692
693
694 if (AcpiUtSafeStrcpy (AcpiGbl_DbParsedBuf, sizeof (AcpiGbl_DbParsedBuf),
695 InputBuffer))
696 {
697 AcpiOsPrintf (
698 "Buffer overflow while parsing input line (max %u characters)\n",
699 (UINT32) sizeof (AcpiGbl_DbParsedBuf));
700 return (0);
701 }
702
703 This = AcpiGbl_DbParsedBuf;
704 for (i = 0; i < ACPI_DEBUGGER_MAX_ARGS; i++)
705 {
706 AcpiGbl_DbArgs[i] = AcpiDbGetNextToken (This, &Next,
707 &AcpiGbl_DbArgTypes[i]);
708 if (!AcpiGbl_DbArgs[i])
709 {
710 break;
711 }
712
713 This = Next;
714 }
715
716 /* Uppercase the actual command */
717
718 AcpiUtStrupr (AcpiGbl_DbArgs[0]);
719
720 Count = i;
721 if (Count)
722 {
723 Count--; /* Number of args only */
724 }
725
726 return (Count);
727 }
728
729
730 /*******************************************************************************
731 *
732 * FUNCTION: AcpiDbMatchCommand
733 *
734 * PARAMETERS: UserCommand - User command line
735 *
736 * RETURN: Index into command array, -1 if not found
737 *
738 * DESCRIPTION: Search command array for a command match
739 *
740 ******************************************************************************/
741
742 static UINT32
743 AcpiDbMatchCommand (
744 char *UserCommand)
745 {
746 UINT32 i;
747
748
749 if (!UserCommand || UserCommand[0] == 0)
750 {
751 return (CMD_NULL);
752 }
753
754 for (i = CMD_FIRST_VALID; AcpiGbl_DbCommands[i].Name; i++)
755 {
756 if (strstr (
757 ACPI_CAST_PTR (char, AcpiGbl_DbCommands[i].Name), UserCommand) ==
758 AcpiGbl_DbCommands[i].Name)
759 {
760 return (i);
761 }
762 }
763
764 /* Command not recognized */
765
766 return (CMD_NOT_FOUND);
767 }
768
769
770 /*******************************************************************************
771 *
772 * FUNCTION: AcpiDbCommandDispatch
773 *
774 * PARAMETERS: InputBuffer - Command line buffer
775 * WalkState - Current walk
776 * Op - Current (executing) parse op
777 *
778 * RETURN: Status
779 *
780 * DESCRIPTION: Command dispatcher.
781 *
782 ******************************************************************************/
783
784 ACPI_STATUS
785 AcpiDbCommandDispatch (
786 char *InputBuffer,
787 ACPI_WALK_STATE *WalkState,
788 ACPI_PARSE_OBJECT *Op)
789 {
790 UINT32 Temp;
791 UINT64 Temp64;
792 UINT32 CommandIndex;
793 UINT32 ParamCount;
794 char *CommandLine;
795 ACPI_STATUS Status = AE_CTRL_TRUE;
796
797
798 /* If AcpiTerminate has been called, terminate this thread */
799
800 if (AcpiGbl_DbTerminateLoop)
801 {
802 return (AE_CTRL_TERMINATE);
803 }
804
805 /* Find command and add to the history buffer */
806
807 ParamCount = AcpiDbGetLine (InputBuffer);
808 CommandIndex = AcpiDbMatchCommand (AcpiGbl_DbArgs[0]);
809
810 /*
811 * We don't want to add the !! command to the history buffer. It
812 * would cause an infinite loop because it would always be the
813 * previous command.
814 */
815 if (CommandIndex != CMD_HISTORY_LAST)
816 {
817 AcpiDbAddToHistory (InputBuffer);
818 }
819
820 /* Verify that we have the minimum number of params */
821
822 if (ParamCount < AcpiGbl_DbCommands[CommandIndex].MinArgs)
823 {
824 AcpiOsPrintf ("%u parameters entered, [%s] requires %u parameters\n",
825 ParamCount, AcpiGbl_DbCommands[CommandIndex].Name,
826 AcpiGbl_DbCommands[CommandIndex].MinArgs);
827
828 AcpiDbDisplayCommandInfo (
829 AcpiGbl_DbCommands[CommandIndex].Name, FALSE);
830 return (AE_CTRL_TRUE);
831 }
832
833 /* Decode and dispatch the command */
834
835 switch (CommandIndex)
836 {
837 case CMD_NULL:
838
839 if (Op)
840 {
841 return (AE_OK);
842 }
843 break;
844
845 case CMD_ALLOCATIONS:
846
847 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
848 AcpiUtDumpAllocations ((UINT32) -1, NULL);
849 #endif
850 break;
851
852 case CMD_ARGS:
853 case CMD_ARGUMENTS:
854
855 AcpiDbDisplayArguments ();
856 break;
857
858 case CMD_BREAKPOINT:
859
860 AcpiDbSetMethodBreakpoint (AcpiGbl_DbArgs[1], WalkState, Op);
861 break;
862
863 case CMD_BUSINFO:
864
865 AcpiDbGetBusInfo ();
866 break;
867
868 case CMD_CALL:
869
870 AcpiDbSetMethodCallBreakpoint (Op);
871 Status = AE_OK;
872 break;
873
874 case CMD_DEBUG:
875
876 AcpiDbExecute (AcpiGbl_DbArgs[1],
877 &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_SINGLE_STEP);
878 break;
879
880 case CMD_DISASSEMBLE:
881 case CMD_DISASM:
882
883 #ifdef ACPI_DISASSEMBLER
884 (void) AcpiDbDisassembleMethod (AcpiGbl_DbArgs[1]);
885 #else
886 AcpiOsPrintf ("The AML Disassembler is not configured/present\n");
887 #endif
888 break;
889
890 case CMD_DUMP:
891
892 AcpiDbDecodeAndDisplayObject (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
893 break;
894
895 case CMD_EVALUATE:
896 case CMD_EXECUTE:
897
898 AcpiDbExecute (AcpiGbl_DbArgs[1],
899 &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_NO_SINGLE_STEP);
900 break;
901
902 case CMD_FIND:
903
904 Status = AcpiDbFindNameInNamespace (AcpiGbl_DbArgs[1]);
905 break;
906
907 case CMD_FIELDS:
908
909 Status = AcpiUtStrtoul64 (AcpiGbl_DbArgs[1], &Temp64);
910
911 if (ACPI_FAILURE (Status) || Temp64 >= ACPI_NUM_PREDEFINED_REGIONS)
912 {
913 AcpiOsPrintf (
914 "Invalid address space ID: must be between 0 and %u inclusive\n",
915 ACPI_NUM_PREDEFINED_REGIONS - 1);
916 return (AE_OK);
917 }
918
919 Status = AcpiDbDisplayFields ((UINT32) Temp64);
920 break;
921
922 case CMD_GO:
923
924 AcpiGbl_CmSingleStep = FALSE;
925 return (AE_OK);
926
927 case CMD_HANDLERS:
928
929 AcpiDbDisplayHandlers ();
930 break;
931
932 case CMD_HELP:
933 case CMD_HELP2:
934
935 AcpiDbDisplayHelp (AcpiGbl_DbArgs[1]);
936 break;
937
938 case CMD_HISTORY:
939
940 AcpiDbDisplayHistory ();
941 break;
942
943 case CMD_HISTORY_EXE: /* ! command */
944
945 CommandLine = AcpiDbGetFromHistory (AcpiGbl_DbArgs[1]);
946 if (!CommandLine)
947 {
948 return (AE_CTRL_TRUE);
949 }
950
951 Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
952 return (Status);
953
954 case CMD_HISTORY_LAST: /* !! command */
955
956 CommandLine = AcpiDbGetFromHistory (NULL);
957 if (!CommandLine)
958 {
959 return (AE_CTRL_TRUE);
960 }
961
962 Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
963 return (Status);
964
965 case CMD_INFORMATION:
966
967 AcpiDbDisplayMethodInfo (Op);
968 break;
969
970 case CMD_INTEGRITY:
971
972 AcpiDbCheckIntegrity ();
973 break;
974
975 case CMD_INTO:
976
977 if (Op)
978 {
979 AcpiGbl_CmSingleStep = TRUE;
980 return (AE_OK);
981 }
982 break;
983
984 case CMD_LEVEL:
985
986 if (ParamCount == 0)
987 {
988 AcpiOsPrintf (
989 "Current debug level for file output is: %8.8X\n",
990 AcpiGbl_DbDebugLevel);
991 AcpiOsPrintf (
992 "Current debug level for console output is: %8.8X\n",
993 AcpiGbl_DbConsoleDebugLevel);
994 }
995 else if (ParamCount == 2)
996 {
997 Temp = AcpiGbl_DbConsoleDebugLevel;
998 AcpiGbl_DbConsoleDebugLevel =
999 strtoul (AcpiGbl_DbArgs[1], NULL, 16);
1000 AcpiOsPrintf (
1001 "Debug Level for console output was %8.8X, now %8.8X\n",
1002 Temp, AcpiGbl_DbConsoleDebugLevel);
1003 }
1004 else
1005 {
1006 Temp = AcpiGbl_DbDebugLevel;
1007 AcpiGbl_DbDebugLevel = strtoul (AcpiGbl_DbArgs[1], NULL, 16);
1008 AcpiOsPrintf (
1009 "Debug Level for file output was %8.8X, now %8.8X\n",
1010 Temp, AcpiGbl_DbDebugLevel);
1011 }
1012 break;
1013
1014 case CMD_LIST:
1015
1016 #ifdef ACPI_DISASSEMBLER
1017 AcpiDbDisassembleAml (AcpiGbl_DbArgs[1], Op);
1018 #else
1019 AcpiOsPrintf ("The AML Disassembler is not configured/present\n");
1020 #endif
1021 break;
1022
1023 case CMD_LOCKS:
1024
1025 AcpiDbDisplayLocks ();
1026 break;
1027
1028 case CMD_LOCALS:
1029
1030 AcpiDbDisplayLocals ();
1031 break;
1032
1033 case CMD_METHODS:
1034
1035 Status = AcpiDbDisplayObjects ("METHOD", AcpiGbl_DbArgs[1]);
1036 break;
1037
1038 case CMD_NAMESPACE:
1039
1040 AcpiDbDumpNamespace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1041 break;
1042
1043 case CMD_NOTIFY:
1044
1045 Temp = strtoul (AcpiGbl_DbArgs[2], NULL, 0);
1046 AcpiDbSendNotify (AcpiGbl_DbArgs[1], Temp);
1047 break;
1048
1049 case CMD_OBJECTS:
1050
1051 AcpiUtStrupr (AcpiGbl_DbArgs[1]);
1052 Status = AcpiDbDisplayObjects (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1053 break;
1054
1055 case CMD_OSI:
1056
1057 AcpiDbDisplayInterfaces (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1058 break;
1059
1060 case CMD_OWNER:
1061
1062 AcpiDbDumpNamespaceByOwner (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1063 break;
1064
1065 case CMD_PATHS:
1066
1067 AcpiDbDumpNamespacePaths ();
1068 break;
1069
1070 case CMD_PREFIX:
1071
1072 AcpiDbSetScope (AcpiGbl_DbArgs[1]);
1073 break;
1074
1075 case CMD_REFERENCES:
1076
1077 AcpiDbFindReferences (AcpiGbl_DbArgs[1]);
1078 break;
1079
1080 case CMD_RESOURCES:
1081
1082 AcpiDbDisplayResources (AcpiGbl_DbArgs[1]);
1083 break;
1084
1085 case CMD_RESULTS:
1086
1087 AcpiDbDisplayResults ();
1088 break;
1089
1090 case CMD_SET:
1091
1092 AcpiDbSetMethodData (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],
1093 AcpiGbl_DbArgs[3]);
1094 break;
1095
1096 case CMD_STATS:
1097
1098 Status = AcpiDbDisplayStatistics (AcpiGbl_DbArgs[1]);
1099 break;
1100
1101 case CMD_STOP:
1102
1103 return (AE_NOT_IMPLEMENTED);
1104
1105 case CMD_TABLES:
1106
1107 AcpiDbDisplayTableInfo (AcpiGbl_DbArgs[1]);
1108 break;
1109
1110 case CMD_TEMPLATE:
1111
1112 AcpiDbDisplayTemplate (AcpiGbl_DbArgs[1]);
1113 break;
1114
1115 case CMD_TRACE:
1116
1117 AcpiDbTrace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], AcpiGbl_DbArgs[3]);
1118 break;
1119
1120 case CMD_TREE:
1121
1122 AcpiDbDisplayCallingTree ();
1123 break;
1124
1125 case CMD_TYPE:
1126
1127 AcpiDbDisplayObjectType (AcpiGbl_DbArgs[1]);
1128 break;
1129
1130 #ifdef ACPI_APPLICATION
1131
1132 /* Hardware simulation commands. */
1133
1134 case CMD_ENABLEACPI:
1135 #if (!ACPI_REDUCED_HARDWARE)
1136
1137 Status = AcpiEnable();
1138 if (ACPI_FAILURE(Status))
1139 {
1140 AcpiOsPrintf("AcpiEnable failed (Status=%X)\n", Status);
1141 return (Status);
1142 }
1143 #endif /* !ACPI_REDUCED_HARDWARE */
1144 break;
1145
1146 case CMD_EVENT:
1147
1148 AcpiOsPrintf ("Event command not implemented\n");
1149 break;
1150
1151 case CMD_GPE:
1152
1153 AcpiDbGenerateGpe (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1154 break;
1155
1156 case CMD_GPES:
1157
1158 AcpiDbDisplayGpes ();
1159 break;
1160
1161 case CMD_SCI:
1162
1163 AcpiDbGenerateSci ();
1164 break;
1165
1166 case CMD_SLEEP:
1167
1168 Status = AcpiDbSleep (AcpiGbl_DbArgs[1]);
1169 break;
1170
1171 /* File I/O commands. */
1172
1173 case CMD_CLOSE:
1174
1175 AcpiDbCloseDebugFile ();
1176 break;
1177
1178 case CMD_LOAD:
1179 {
1180 ACPI_NEW_TABLE_DESC *ListHead = NULL;
1181
1182 Status = AcGetAllTablesFromFile (AcpiGbl_DbArgs[1],
1183 ACPI_GET_ALL_TABLES, &ListHead);
1184 if (ACPI_SUCCESS (Status))
1185 {
1186 AcpiDbLoadTables (ListHead);
1187 }
1188 }
1189 break;
1190
1191 case CMD_OPEN:
1192
1193 AcpiDbOpenDebugFile (AcpiGbl_DbArgs[1]);
1194 break;
1195
1196 /* User space commands. */
1197
1198 case CMD_TERMINATE:
1199
1200 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
1201 AcpiUtSubsystemShutdown ();
1202
1203 /*
1204 * TBD: [Restructure] Need some way to re-initialize without
1205 * re-creating the semaphores!
1206 */
1207
1208 AcpiGbl_DbTerminateLoop = TRUE;
1209 /* AcpiInitialize (NULL); */
1210 break;
1211
1212 case CMD_BACKGROUND:
1213
1214 AcpiDbCreateExecutionThread (AcpiGbl_DbArgs[1], &AcpiGbl_DbArgs[2],
1215 &AcpiGbl_DbArgTypes[2]);
1216 break;
1217
1218 case CMD_THREADS:
1219
1220 AcpiDbCreateExecutionThreads (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],
1221 AcpiGbl_DbArgs[3]);
1222 break;
1223
1224 /* Debug test commands. */
1225
1226 case CMD_PREDEFINED:
1227
1228 AcpiDbCheckPredefinedNames ();
1229 break;
1230
1231 case CMD_TEST:
1232
1233 AcpiDbExecuteTest (AcpiGbl_DbArgs[1]);
1234 break;
1235
1236 case CMD_UNLOAD:
1237
1238 AcpiDbUnloadAcpiTable (AcpiGbl_DbArgs[1]);
1239 break;
1240 #endif
1241
1242 case CMD_EXIT:
1243 case CMD_QUIT:
1244
1245 if (Op)
1246 {
1247 AcpiOsPrintf ("Method execution terminated\n");
1248 return (AE_CTRL_TERMINATE);
1249 }
1250
1251 if (!AcpiGbl_DbOutputToFile)
1252 {
1253 AcpiDbgLevel = ACPI_DEBUG_DEFAULT;
1254 }
1255
1256 #ifdef ACPI_APPLICATION
1257 AcpiDbCloseDebugFile ();
1258 #endif
1259 AcpiGbl_DbTerminateLoop = TRUE;
1260 return (AE_CTRL_TERMINATE);
1261
1262 case CMD_NOT_FOUND:
1263 default:
1264
1265 AcpiOsPrintf ("%s: unknown command\n", AcpiGbl_DbArgs[0]);
1266 return (AE_CTRL_TRUE);
1267 }
1268
1269 if (ACPI_SUCCESS (Status))
1270 {
1271 Status = AE_CTRL_TRUE;
1272 }
1273
1274 return (Status);
1275 }
1276
1277
1278 /*******************************************************************************
1279 *
1280 * FUNCTION: AcpiDbExecuteThread
1281 *
1282 * PARAMETERS: Context - Not used
1283 *
1284 * RETURN: None
1285 *
1286 * DESCRIPTION: Debugger execute thread. Waits for a command line, then
1287 * simply dispatches it.
1288 *
1289 ******************************************************************************/
1290
1291 void ACPI_SYSTEM_XFACE
1292 AcpiDbExecuteThread (
1293 void *Context)
1294 {
1295
1296 (void) AcpiDbUserCommands ();
1297 AcpiGbl_DbThreadsTerminated = TRUE;
1298 }
1299
1300
1301 /*******************************************************************************
1302 *
1303 * FUNCTION: AcpiDbUserCommands
1304 *
1305 * PARAMETERS: None
1306 *
1307 * RETURN: None
1308 *
1309 * DESCRIPTION: Command line execution for the AML debugger. Commands are
1310 * matched and dispatched here.
1311 *
1312 ******************************************************************************/
1313
1314 ACPI_STATUS
1315 AcpiDbUserCommands (
1316 void)
1317 {
1318 ACPI_STATUS Status = AE_OK;
1319
1320
1321 AcpiOsPrintf ("\n");
1322
1323 /* TBD: [Restructure] Need a separate command line buffer for step mode */
1324
1325 while (!AcpiGbl_DbTerminateLoop)
1326 {
1327 /* Wait the readiness of the command */
1328
1329 Status = AcpiOsWaitCommandReady ();
1330 if (ACPI_FAILURE (Status))
1331 {
1332 break;
1333 }
1334
1335 /* Just call to the command line interpreter */
1336
1337 AcpiGbl_MethodExecuting = FALSE;
1338 AcpiGbl_StepToNextCall = FALSE;
1339
1340 (void) AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
1341
1342 /* Notify the completion of the command */
1343
1344 Status = AcpiOsNotifyCommandComplete ();
1345 if (ACPI_FAILURE (Status))
1346 {
1347 break;
1348 }
1349 }
1350
1351 if (ACPI_FAILURE (Status) && Status != AE_CTRL_TERMINATE)
1352 {
1353 ACPI_EXCEPTION ((AE_INFO, Status, "While parsing command line"));
1354 }
1355 return (Status);
1356 }
1357