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