Merge from vendor branch OPENSSL:
[dragonfly.git] / sys / contrib / dev / acpica-unix-20040527 / debugger / dbinput.c
1 /*******************************************************************************
2  *
3  * Module Name: dbinput - user front-end to the AML debugger
4  *              $Revision: 100 $
5  *
6  ******************************************************************************/
7
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
17  * 2.1. This is your license from Intel Corp. under its intellectual property
18  * rights.  You may have additional license terms from the party that provided
19  * you this software, covering your right to use that party's intellectual
20  * property rights.
21  *
22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23  * copy of the source code appearing in this file ("Covered Code") an
24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25  * base code distributed originally by Intel ("Original Intel Code") to copy,
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code.  No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision.  In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change.  Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee.  Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution.  In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government.  In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************/
116
117
118 #include "acpi.h"
119 #include "acdebug.h"
120
121
122 #ifdef ACPI_DEBUGGER
123
124 #define _COMPONENT          ACPI_CA_DEBUGGER
125         ACPI_MODULE_NAME    ("dbinput")
126
127
128 /*
129  * Top-level debugger commands.
130  *
131  * This list of commands must match the string table below it
132  */
133 enum AcpiExDebuggerCommands
134 {
135     CMD_NOT_FOUND = 0,
136     CMD_NULL,
137     CMD_ALLOCATIONS,
138     CMD_ARGS,
139     CMD_ARGUMENTS,
140     CMD_BREAKPOINT,
141     CMD_CALL,
142     CMD_CLOSE,
143     CMD_DEBUG,
144     CMD_DUMP,
145     CMD_ENABLEACPI,
146     CMD_EVENT,
147     CMD_EXECUTE,
148     CMD_EXIT,
149     CMD_FIND,
150     CMD_GO,
151     CMD_GPE,
152     CMD_GPES,
153     CMD_HELP,
154     CMD_HELP2,
155     CMD_HISTORY,
156     CMD_HISTORY_EXE,
157     CMD_HISTORY_LAST,
158     CMD_INFORMATION,
159     CMD_INTEGRITY,
160     CMD_INTO,
161     CMD_LEVEL,
162     CMD_LIST,
163     CMD_LOAD,
164     CMD_LOCALS,
165     CMD_LOCKS,
166     CMD_METHODS,
167     CMD_NAMESPACE,
168     CMD_NOTIFY,
169     CMD_OBJECT,
170     CMD_OPEN,
171     CMD_OWNER,
172     CMD_PREFIX,
173     CMD_QUIT,
174     CMD_REFERENCES,
175     CMD_RESOURCES,
176     CMD_RESULTS,
177     CMD_SET,
178     CMD_SLEEP,
179     CMD_STATS,
180     CMD_STOP,
181     CMD_TABLES,
182     CMD_TERMINATE,
183     CMD_THREADS,
184     CMD_TREE,
185     CMD_TYPE,
186     CMD_UNLOAD
187 };
188
189 #define CMD_FIRST_VALID     2
190
191
192 static const COMMAND_INFO       AcpiGbl_DbCommands[] =
193 {
194     {"<NOT FOUND>",  0},
195     {"<NULL>",       0},
196     {"ALLOCATIONS",  0},
197     {"ARGS",         0},
198     {"ARGUMENTS",    0},
199     {"BREAKPOINT",   1},
200     {"CALL",         0},
201     {"CLOSE",        0},
202     {"DEBUG",        1},
203     {"DUMP",         1},
204     {"ENABLEACPI",   0},
205     {"EVENT",        1},
206     {"EXECUTE",      1},
207     {"EXIT",         0},
208     {"FIND",         1},
209     {"GO",           0},
210     {"GPE",          2},
211     {"GPES",         0},
212     {"HELP",         0},
213     {"?",            0},
214     {"HISTORY",      0},
215     {"!",            1},
216     {"!!",           0},
217     {"INFORMATION",  0},
218     {"INTEGRITY",    0},
219     {"INTO",         0},
220     {"LEVEL",        0},
221     {"LIST",         0},
222     {"LOAD",         1},
223     {"LOCALS",       0},
224     {"LOCKS",        0},
225     {"METHODS",      0},
226     {"NAMESPACE",    0},
227     {"NOTIFY",       2},
228     {"OBJECT",       1},
229     {"OPEN",         1},
230     {"OWNER",        1},
231     {"PREFIX",       0},
232     {"QUIT",         0},
233     {"REFERENCES",   1},
234     {"RESOURCES",    1},
235     {"RESULTS",      0},
236     {"SET",          3},
237     {"SLEEP",        1},
238     {"STATS",        0},
239     {"STOP",         0},
240     {"TABLES",       0},
241     {"TERMINATE",    0},
242     {"THREADS",      3},
243     {"TREE",         0},
244     {"TYPE",         1},
245     {"UNLOAD",       1},
246     {NULL,           0}
247 };
248
249
250 /*******************************************************************************
251  *
252  * FUNCTION:    AcpiDbDisplayHelp
253  *
254  * PARAMETERS:  HelpType        - Subcommand (optional)
255  *
256  * RETURN:      None
257  *
258  * DESCRIPTION: Print a usage message.
259  *
260  ******************************************************************************/
261
262 void
263 AcpiDbDisplayHelp (
264     char                    *HelpType)
265 {
266
267
268     /* No parameter, just give the overview */
269
270     if (!HelpType)
271     {
272         AcpiOsPrintf ("ACPI CA Debugger Commands\n\n");
273         AcpiOsPrintf ("The following classes of commands are available.  Help is available for\n");
274         AcpiOsPrintf ("each class by entering \"Help <ClassName>\"\n\n");
275         AcpiOsPrintf ("    [GENERAL]       General-Purpose Commands\n");
276         AcpiOsPrintf ("    [NAMESPACE]     Namespace Access Commands\n");
277         AcpiOsPrintf ("    [METHOD]        Control Method Execution Commands\n");
278         AcpiOsPrintf ("    [FILE]          File I/O Commands\n");
279         return;
280     }
281
282     /*
283      * Parameter is the command class
284      *
285      * The idea here is to keep each class of commands smaller than a screenful
286      */
287     switch (HelpType[0])
288     {
289     case 'G':
290         AcpiOsPrintf ("\nGeneral-Purpose Commands\n\n");
291         AcpiOsPrintf ("Allocations                         Display list of current memory allocations\n");
292         AcpiOsPrintf ("Dump <Address>|<Namepath>\n");
293         AcpiOsPrintf ("     [Byte|Word|Dword|Qword]        Display ACPI objects or memory\n");
294         AcpiOsPrintf ("EnableAcpi                          Enable ACPI (hardware) mode\n");
295         AcpiOsPrintf ("Help                                This help screen\n");
296         AcpiOsPrintf ("History                             Display command history buffer\n");
297         AcpiOsPrintf ("Level [<DebugLevel>] [console]      Get/Set debug level for file or console\n");
298         AcpiOsPrintf ("Locks                               Current status of internal mutexes\n");
299         AcpiOsPrintf ("Quit or Exit                        Exit this command\n");
300         AcpiOsPrintf ("Stats [Allocations|Memory|Misc\n");
301         AcpiOsPrintf ("       |Objects|Tables]             Display namespace and memory statistics\n");
302         AcpiOsPrintf ("Tables                              Display info about loaded ACPI tables\n");
303         AcpiOsPrintf ("Unload <TableSig> [Instance]        Unload an ACPI table\n");
304         AcpiOsPrintf ("! <CommandNumber>                   Execute command from history buffer\n");
305         AcpiOsPrintf ("!!                                  Execute last command again\n");
306         return;
307
308     case 'N':
309         AcpiOsPrintf ("\nNamespace Access Commands\n\n");
310         AcpiOsPrintf ("Event <F|G> <Value>                 Generate AcpiEvent (Fixed/GPE)\n");
311         AcpiOsPrintf ("Find <Name>   (? is wildcard)       Find ACPI name(s) with wildcards\n");
312         AcpiOsPrintf ("Method                              Display list of loaded control methods\n");
313         AcpiOsPrintf ("Namespace [<Addr>|<Path>] [Depth]   Display loaded namespace tree/subtree\n");
314         AcpiOsPrintf ("Notify <NamePath> <Value>           Send a notification\n");
315         AcpiOsPrintf ("Objects <ObjectType>                Display all objects of the given type\n");
316         AcpiOsPrintf ("Owner <OwnerId> [Depth]             Display loaded namespace by object owner\n");
317         AcpiOsPrintf ("Prefix [<NamePath>]                 Set or Get current execution prefix\n");
318         AcpiOsPrintf ("References <Addr>                   Find all references to object at addr\n");
319         AcpiOsPrintf ("Resources xxx                       Get and display resources\n");
320         AcpiOsPrintf ("Terminate                           Delete namespace and all internal objects\n");
321         AcpiOsPrintf ("Thread <Threads><Loops><NamePath>   Spawn threads to execute method(s)\n");
322         return;
323
324     case 'M':
325         AcpiOsPrintf ("\nControl Method Execution Commands\n\n");
326         AcpiOsPrintf ("Arguments (or Args)                 Display method arguments\n");
327         AcpiOsPrintf ("Breakpoint <AmlOffset>              Set an AML execution breakpoint\n");
328         AcpiOsPrintf ("Call                                Run to next control method invocation\n");
329         AcpiOsPrintf ("Debug <Namepath> [Arguments]        Single Step a control method\n");
330         AcpiOsPrintf ("Execute <Namepath> [Arguments]      Execute control method\n");
331         AcpiOsPrintf ("Go                                  Allow method to run to completion\n");
332         AcpiOsPrintf ("Information                         Display info about the current method\n");
333         AcpiOsPrintf ("Into                                Step into (not over) a method call\n");
334         AcpiOsPrintf ("List [# of Aml Opcodes]             Display method ASL statements\n");
335         AcpiOsPrintf ("Locals                              Display method local variables\n");
336         AcpiOsPrintf ("Results                             Display method result stack\n");
337         AcpiOsPrintf ("Set <A|L> <#> <Value>               Set method data (Arguments/Locals)\n");
338         AcpiOsPrintf ("Stop                                Terminate control method\n");
339         AcpiOsPrintf ("Tree                                Display control method calling tree\n");
340         AcpiOsPrintf ("<Enter>                             Single step next AML opcode (over calls)\n");
341         return;
342
343     case 'F':
344         AcpiOsPrintf ("\nFile I/O Commands\n\n");
345         AcpiOsPrintf ("Close                               Close debug output file\n");
346         AcpiOsPrintf ("Open <Output Filename>              Open a file for debug output\n");
347         AcpiOsPrintf ("Load <Input Filename>               Load ACPI table from a file\n");
348         return;
349
350     default:
351         AcpiOsPrintf ("Unrecognized Command Class: %s\n", HelpType);
352         return;
353     }
354 }
355
356
357 /*******************************************************************************
358  *
359  * FUNCTION:    AcpiDbGetNextToken
360  *
361  * PARAMETERS:  String          - Command buffer
362  *              Next            - Return value, end of next token
363  *
364  * RETURN:      Pointer to the start of the next token.
365  *
366  * DESCRIPTION: Command line parsing.  Get the next token on the command line
367  *
368  ******************************************************************************/
369
370 char *
371 AcpiDbGetNextToken (
372     char                    *String,
373     char                    **Next)
374 {
375     char                    *Start;
376
377
378     /* At end of buffer? */
379
380     if (!String || !(*String))
381     {
382         return (NULL);
383     }
384
385     /* Get rid of any spaces at the beginning */
386
387     if (*String == ' ')
388     {
389         while (*String && (*String == ' '))
390         {
391             String++;
392         }
393
394         if (!(*String))
395         {
396             return (NULL);
397         }
398     }
399
400     Start = String;
401
402     /* Find end of token */
403
404     while (*String && (*String != ' '))
405     {
406         String++;
407     }
408
409     if (!(*String))
410     {
411         *Next = NULL;
412     }
413     else
414     {
415         *String = 0;
416         *Next = String + 1;
417     }
418
419     return (Start);
420 }
421
422
423 /*******************************************************************************
424  *
425  * FUNCTION:    AcpiDbGetLine
426  *
427  * PARAMETERS:  InputBuffer         - Command line buffer
428  *
429  * RETURN:      None
430  *
431  * DESCRIPTION: Get the next command line from the user.  Gets entire line
432  *              up to the next newline
433  *
434  ******************************************************************************/
435
436 UINT32
437 AcpiDbGetLine (
438     char                    *InputBuffer)
439 {
440     UINT32                  i;
441     UINT32                  Count;
442     char                    *Next;
443     char                    *This;
444
445
446     ACPI_STRCPY (AcpiGbl_DbParsedBuf, InputBuffer);
447     ACPI_STRUPR (AcpiGbl_DbParsedBuf);
448
449     This = AcpiGbl_DbParsedBuf;
450     for (i = 0; i < ACPI_DEBUGGER_MAX_ARGS; i++)
451     {
452         AcpiGbl_DbArgs[i] = AcpiDbGetNextToken (This, &Next);
453         if (!AcpiGbl_DbArgs[i])
454         {
455             break;
456         }
457
458         This = Next;
459     }
460
461     /* Uppercase the actual command */
462
463     if (AcpiGbl_DbArgs[0])
464     {
465         ACPI_STRUPR (AcpiGbl_DbArgs[0]);
466     }
467
468     Count = i;
469     if (Count)
470     {
471         Count--;  /* Number of args only */
472     }
473
474     return (Count);
475 }
476
477
478 /*******************************************************************************
479  *
480  * FUNCTION:    AcpiDbMatchCommand
481  *
482  * PARAMETERS:  UserCommand             - User command line
483  *
484  * RETURN:      Index into command array, -1 if not found
485  *
486  * DESCRIPTION: Search command array for a command match
487  *
488  ******************************************************************************/
489
490 UINT32
491 AcpiDbMatchCommand (
492     char                    *UserCommand)
493 {
494     UINT32                  i;
495
496
497     if (!UserCommand || UserCommand[0] == 0)
498     {
499         return (CMD_NULL);
500     }
501
502     for (i = CMD_FIRST_VALID; AcpiGbl_DbCommands[i].Name; i++)
503     {
504         if (ACPI_STRSTR (AcpiGbl_DbCommands[i].Name, UserCommand) ==
505                          AcpiGbl_DbCommands[i].Name)
506         {
507             return (i);
508         }
509     }
510
511     /* Command not recognized */
512
513     return (CMD_NOT_FOUND);
514 }
515
516
517 /*******************************************************************************
518  *
519  * FUNCTION:    AcpiDbCommandDispatch
520  *
521  * PARAMETERS:  InputBuffer         - Command line buffer
522  *              WalkState           - Current walk
523  *              Op                  - Current (executing) parse op
524  *
525  * RETURN:      Status
526  *
527  * DESCRIPTION: Command dispatcher.  Called from two places:
528  *
529  ******************************************************************************/
530
531 ACPI_STATUS
532 AcpiDbCommandDispatch (
533     char                    *InputBuffer,
534     ACPI_WALK_STATE         *WalkState,
535     ACPI_PARSE_OBJECT       *Op)
536 {
537     UINT32                  Temp;
538     UINT32                  CommandIndex;
539     UINT32                  ParamCount;
540     char                    *CommandLine;
541     ACPI_STATUS             Status = AE_CTRL_TRUE;
542
543
544     /* If AcpiTerminate has been called, terminate this thread */
545
546     if (AcpiGbl_DbTerminateThreads)
547     {
548         return (AE_CTRL_TERMINATE);
549     }
550
551     ParamCount = AcpiDbGetLine (InputBuffer);
552     CommandIndex = AcpiDbMatchCommand (AcpiGbl_DbArgs[0]);
553     Temp = 0;
554
555     /* Verify that we have the minimum number of params */
556
557     if (ParamCount < AcpiGbl_DbCommands[CommandIndex].MinArgs)
558     {
559         AcpiOsPrintf ("%d parameters entered, [%s] requires %d parameters\n",
560                         ParamCount, AcpiGbl_DbCommands[CommandIndex].Name, AcpiGbl_DbCommands[CommandIndex].MinArgs);
561         return (AE_CTRL_TRUE);
562     }
563
564     /* Decode and dispatch the command */
565
566     switch (CommandIndex)
567     {
568     case CMD_NULL:
569         if (Op)
570         {
571             return (AE_OK);
572         }
573         break;
574
575     case CMD_ALLOCATIONS:
576
577 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
578         AcpiUtDumpAllocations ((UINT32) -1, NULL);
579 #endif
580         break;
581
582     case CMD_ARGS:
583     case CMD_ARGUMENTS:
584         AcpiDbDisplayArguments ();
585         break;
586
587     case CMD_BREAKPOINT:
588         AcpiDbSetMethodBreakpoint (AcpiGbl_DbArgs[1], WalkState, Op);
589         break;
590
591     case CMD_CALL:
592         AcpiDbSetMethodCallBreakpoint (Op);
593         Status = AE_OK;
594         break;
595
596     case CMD_CLOSE:
597         AcpiDbCloseDebugFile ();
598         break;
599
600     case CMD_DEBUG:
601         AcpiDbExecute (AcpiGbl_DbArgs[1], &AcpiGbl_DbArgs[2], EX_SINGLE_STEP);
602         break;
603
604     case CMD_DUMP:
605         AcpiDbDecodeAndDisplayObject (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
606         break;
607
608     case CMD_ENABLEACPI:
609         Status = AcpiEnable();
610         if (ACPI_FAILURE(Status))
611         {
612             AcpiOsPrintf("AcpiEnable failed (Status=%X)\n", Status);
613             return (Status);
614         }
615         break;
616
617     case CMD_EVENT:
618         AcpiOsPrintf ("Event command not implemented\n");
619         break;
620
621     case CMD_EXECUTE:
622         AcpiDbExecute (AcpiGbl_DbArgs[1], &AcpiGbl_DbArgs[2], EX_NO_SINGLE_STEP);
623         break;
624
625     case CMD_FIND:
626         Status = AcpiDbFindNameInNamespace (AcpiGbl_DbArgs[1]);
627         break;
628
629     case CMD_GO:
630         AcpiGbl_CmSingleStep = FALSE;
631         return (AE_OK);
632
633     case CMD_GPE:
634         AcpiDbGenerateGpe (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
635         break;
636
637     case CMD_GPES:
638         AcpiDbDisplayGpes ();
639         break;
640
641     case CMD_HELP:
642     case CMD_HELP2:
643         AcpiDbDisplayHelp (AcpiGbl_DbArgs[1]);
644         break;
645
646     case CMD_HISTORY:
647         AcpiDbDisplayHistory ();
648         break;
649
650     case CMD_HISTORY_EXE:
651         CommandLine = AcpiDbGetFromHistory (AcpiGbl_DbArgs[1]);
652         if (!CommandLine)
653         {
654             return (AE_CTRL_TRUE);
655         }
656
657         Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
658         if (ACPI_SUCCESS (Status))
659         {
660             Status = AE_CTRL_TRUE;
661         }
662         return (Status);
663
664     case CMD_HISTORY_LAST:
665         CommandLine = AcpiDbGetFromHistory (NULL);
666         if (!CommandLine)
667         {
668             return (AE_CTRL_TRUE);
669         }
670
671         Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
672         if (ACPI_SUCCESS (Status))
673         {
674             Status = AE_CTRL_TRUE;
675         }
676         return (Status);
677
678     case CMD_INFORMATION:
679         AcpiDbDisplayMethodInfo (Op);
680         break;
681
682     case CMD_INTEGRITY:
683         AcpiDbCheckIntegrity ();
684         break;
685
686     case CMD_INTO:
687         if (Op)
688         {
689             AcpiGbl_CmSingleStep = TRUE;
690             return (AE_OK);
691         }
692         break;
693
694     case CMD_LEVEL:
695         if (ParamCount == 0)
696         {
697             AcpiOsPrintf ("Current debug level for file output is:    %8.8lX\n", AcpiGbl_DbDebugLevel);
698             AcpiOsPrintf ("Current debug level for console output is: %8.8lX\n", AcpiGbl_DbConsoleDebugLevel);
699         }
700         else if (ParamCount == 2)
701         {
702             Temp = AcpiGbl_DbConsoleDebugLevel;
703             AcpiGbl_DbConsoleDebugLevel = ACPI_STRTOUL (AcpiGbl_DbArgs[1], NULL, 16);
704             AcpiOsPrintf ("Debug Level for console output was %8.8lX, now %8.8lX\n", Temp, AcpiGbl_DbConsoleDebugLevel);
705         }
706         else
707         {
708             Temp = AcpiGbl_DbDebugLevel;
709             AcpiGbl_DbDebugLevel = ACPI_STRTOUL (AcpiGbl_DbArgs[1], NULL, 16);
710             AcpiOsPrintf ("Debug Level for file output was %8.8lX, now %8.8lX\n", Temp, AcpiGbl_DbDebugLevel);
711         }
712         break;
713
714     case CMD_LIST:
715         AcpiDbDisassembleAml (AcpiGbl_DbArgs[1], Op);
716         break;
717
718     case CMD_LOAD:
719         Status = AcpiDbGetTableFromFile (AcpiGbl_DbArgs[1], NULL);
720         if (ACPI_FAILURE (Status))
721         {
722             return (Status);
723         }
724         break;
725
726     case CMD_LOCKS:
727         AcpiDbDisplayLocks ();
728         break;
729
730     case CMD_LOCALS:
731         AcpiDbDisplayLocals ();
732         break;
733
734     case CMD_METHODS:
735         Status = AcpiDbDisplayObjects ("METHOD", AcpiGbl_DbArgs[1]);
736         break;
737
738     case CMD_NAMESPACE:
739         AcpiDbDumpNamespace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
740         break;
741
742     case CMD_NOTIFY:
743         Temp = ACPI_STRTOUL (AcpiGbl_DbArgs[2], NULL, 0);
744         AcpiDbSendNotify (AcpiGbl_DbArgs[1], Temp);
745         break;
746
747     case CMD_OBJECT:
748         ACPI_STRUPR (AcpiGbl_DbArgs[1]);
749         Status = AcpiDbDisplayObjects (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
750         break;
751
752     case CMD_OPEN:
753         AcpiDbOpenDebugFile (AcpiGbl_DbArgs[1]);
754         break;
755
756     case CMD_OWNER:
757         AcpiDbDumpNamespaceByOwner (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
758         break;
759
760     case CMD_PREFIX:
761         AcpiDbSetScope (AcpiGbl_DbArgs[1]);
762         break;
763
764     case CMD_REFERENCES:
765         AcpiDbFindReferences (AcpiGbl_DbArgs[1]);
766         break;
767
768     case CMD_RESOURCES:
769         AcpiDbDisplayResources (AcpiGbl_DbArgs[1]);
770         break;
771
772     case CMD_RESULTS:
773         AcpiDbDisplayResults ();
774         break;
775
776     case CMD_SET:
777         AcpiDbSetMethodData (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], AcpiGbl_DbArgs[3]);
778         break;
779
780     case CMD_SLEEP:
781         Status = AcpiDbSleep (AcpiGbl_DbArgs[1]);
782         break;
783
784     case CMD_STATS:
785         Status = AcpiDbDisplayStatistics (AcpiGbl_DbArgs[1]);
786         break;
787
788     case CMD_STOP:
789         return (AE_NOT_IMPLEMENTED);
790
791     case CMD_TABLES:
792         AcpiDbDisplayTableInfo (AcpiGbl_DbArgs[1]);
793         break;
794
795     case CMD_TERMINATE:
796         AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
797         AcpiUtSubsystemShutdown ();
798
799         /* TBD: [Restructure] Need some way to re-initialize without re-creating the semaphores! */
800
801         /*  AcpiInitialize (NULL);  */
802         break;
803
804     case CMD_THREADS:
805         AcpiDbCreateExecutionThreads (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], AcpiGbl_DbArgs[3]);
806         break;
807
808     case CMD_TREE:
809         AcpiDbDisplayCallingTree ();
810         break;
811
812     case CMD_TYPE:
813         AcpiDbDisplayObjectType (AcpiGbl_DbArgs[1]);
814         break;
815
816     case CMD_UNLOAD:
817         AcpiDbUnloadAcpiTable (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
818         break;
819
820     case CMD_EXIT:
821     case CMD_QUIT:
822         if (Op)
823         {
824             AcpiOsPrintf ("Method execution terminated\n");
825             return (AE_CTRL_TERMINATE);
826         }
827
828         if (!AcpiGbl_DbOutputToFile)
829         {
830             AcpiDbgLevel = ACPI_DEBUG_DEFAULT;
831         }
832
833         /* Shutdown */
834
835         /* AcpiUtSubsystemShutdown (); */
836         AcpiDbCloseDebugFile ();
837
838         AcpiGbl_DbTerminateThreads = TRUE;
839
840         return (AE_CTRL_TERMINATE);
841
842     case CMD_NOT_FOUND:
843     default:
844         AcpiOsPrintf ("Unknown Command\n");
845         return (AE_CTRL_TRUE);
846     }
847
848
849     /* Add all commands that come here to the history buffer */
850
851     AcpiDbAddToHistory (InputBuffer);
852     return (Status);
853 }
854
855
856 /*******************************************************************************
857  *
858  * FUNCTION:    AcpiDbExecuteThread
859  *
860  * PARAMETERS:  Context         - Not used
861  *
862  * RETURN:      None
863  *
864  * DESCRIPTION: Debugger execute thread.  Waits for a command line, then
865  *              simply dispatches it.
866  *
867  ******************************************************************************/
868
869 void ACPI_SYSTEM_XFACE
870 AcpiDbExecuteThread (
871     void                    *Context)
872 {
873     ACPI_STATUS             Status = AE_OK;
874     ACPI_STATUS             MStatus;
875
876
877     while (Status != AE_CTRL_TERMINATE)
878     {
879         AcpiGbl_MethodExecuting = FALSE;
880         AcpiGbl_StepToNextCall = FALSE;
881
882         MStatus = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY);
883         if (ACPI_FAILURE (MStatus))
884         {
885             return;
886         }
887
888         Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
889
890         MStatus = AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
891         if (ACPI_FAILURE (MStatus))
892         {
893             return;
894         }
895     }
896 }
897
898
899 /*******************************************************************************
900  *
901  * FUNCTION:    AcpiDbSingleThread
902  *
903  * PARAMETERS:  None
904  *
905  * RETURN:      None
906  *
907  * DESCRIPTION: Debugger execute thread.  Waits for a command line, then
908  *              simply dispatches it.
909  *
910  ******************************************************************************/
911
912 void
913 AcpiDbSingleThread (
914     void)
915 {
916
917     AcpiGbl_MethodExecuting = FALSE;
918     AcpiGbl_StepToNextCall = FALSE;
919
920     (void) AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
921 }
922
923
924 /*******************************************************************************
925  *
926  * FUNCTION:    AcpiDbUserCommands
927  *
928  * PARAMETERS:  Prompt              - User prompt (depends on mode)
929  *              Op                  - Current executing parse op
930  *
931  * RETURN:      None
932  *
933  * DESCRIPTION: Command line execution for the AML debugger.  Commands are
934  *              matched and dispatched here.
935  *
936  ******************************************************************************/
937
938 ACPI_STATUS
939 AcpiDbUserCommands (
940     char                    Prompt,
941     ACPI_PARSE_OBJECT       *Op)
942 {
943     ACPI_STATUS             Status = AE_OK;
944
945
946     /* TBD: [Restructure] Need a separate command line buffer for step mode */
947
948     while (!AcpiGbl_DbTerminateThreads)
949     {
950         /* Force output to console until a command is entered */
951
952         AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
953
954         /* Different prompt if method is executing */
955
956         if (!AcpiGbl_MethodExecuting)
957         {
958             AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
959         }
960         else
961         {
962             AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
963         }
964
965         /* Get the user input line */
966
967         (void) AcpiOsGetLine (AcpiGbl_DbLineBuf);
968
969         /* Check for single or multithreaded debug */
970
971         if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
972         {
973             /*
974              * Signal the debug thread that we have a command to execute,
975              * and wait for the command to complete.
976              */
977             Status = AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_READY);
978             if (ACPI_FAILURE (Status))
979             {
980                 return (Status);
981             }
982
983             Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
984             if (ACPI_FAILURE (Status))
985             {
986                 return (Status);
987             }
988         }
989         else
990         {
991             /* Just call to the command line interpreter */
992
993             AcpiDbSingleThread ();
994         }
995     }
996
997     /*
998      * Only this thread (the original thread) should actually terminate the subsystem,
999      * because all the semaphores are deleted during termination
1000      */
1001     Status = AcpiTerminate ();
1002     return (Status);
1003 }
1004
1005
1006 #endif  /* ACPI_DEBUGGER */
1007