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