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