Use __DECONST to silence GCC. Make some private routines static.
[dragonfly.git] / sys / contrib / dev / acpica / dbinput.c
1 /*******************************************************************************
2  *
3  * Module Name: dbinput - user front-end to the AML debugger
4  *              $Revision: 96 $
5  *
6  ******************************************************************************/
7
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2003, 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 /* $DragonFly: src/sys/contrib/dev/acpica/Attic/dbinput.c,v 1.1 2003/09/24 03:32:15 drhodus Exp $                                                               */
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_STATS,
179     CMD_STOP,
180     CMD_TABLES,
181     CMD_TERMINATE,
182     CMD_THREADS,
183     CMD_TREE,
184     CMD_UNLOAD
185 };
186
187 #define CMD_FIRST_VALID     2
188
189
190 static const COMMAND_INFO       AcpiGbl_DbCommands[] =
191 {
192     {"<NOT FOUND>",  0},
193     {"<NULL>",       0},
194     {"ALLOCATIONS",  0},
195     {"ARGS",         0},
196     {"ARGUMENTS",    0},
197     {"BREAKPOINT",   1},
198     {"CALL",         0},
199     {"CLOSE",        0},
200     {"DEBUG",        1},
201     {"DUMP",         1},
202     {"ENABLEACPI",   0},
203     {"EVENT",        1},
204     {"EXECUTE",      1},
205     {"EXIT",         0},
206     {"FIND",         1},
207     {"GO",           0},
208     {"GPE",          2},
209     {"GPES",         0},
210     {"HELP",         0},
211     {"?",            0},
212     {"HISTORY",      0},
213     {"!",            1},
214     {"!!",           0},
215     {"INFORMATION",  0},
216     {"INTEGRITY",    0},
217     {"INTO",         0},
218     {"LEVEL",        0},
219     {"LIST",         0},
220     {"LOAD",         1},
221     {"LOCALS",       0},
222     {"LOCKS",        0},
223     {"METHODS",      0},
224     {"NAMESPACE",    0},
225     {"NOTIFY",       2},
226     {"OBJECT",       1},
227     {"OPEN",         1},
228     {"OWNER",        1},
229     {"PREFIX",       0},
230     {"QUIT",         0},
231     {"REFERENCES",   1},
232     {"RESOURCES",    1},
233     {"RESULTS",      0},
234     {"SET",          3},
235     {"STATS",        0},
236     {"STOP",         0},
237     {"TABLES",       0},
238     {"TERMINATE",    0},
239     {"THREADS",      3},
240     {"TREE",         0},
241     {"UNLOAD",       1},
242     {NULL,           0}
243 };
244
245
246 /*******************************************************************************
247  *
248  * FUNCTION:    AcpiDbDisplayHelp
249  *
250  * PARAMETERS:  HelpType        - Subcommand (optional)
251  *
252  * RETURN:      None
253  *
254  * DESCRIPTION: Print a usage message.
255  *
256  ******************************************************************************/
257
258 void
259 AcpiDbDisplayHelp (
260     char                    *HelpType)
261 {
262
263
264     /* No parameter, just give the overview */
265
266     if (!HelpType)
267     {
268         AcpiOsPrintf ("ACPI CA Debugger Commands\n\n");
269         AcpiOsPrintf ("The following classes of commands are available.  Help is available for\n");
270         AcpiOsPrintf ("each class by entering \"Help <ClassName>\"\n\n");
271         AcpiOsPrintf ("    [GENERAL]       General-Purpose Commands\n");
272         AcpiOsPrintf ("    [NAMESPACE]     Namespace Access Commands\n");
273         AcpiOsPrintf ("    [METHOD]        Control Method Execution Commands\n");
274         AcpiOsPrintf ("    [FILE]          File I/O Commands\n");
275         return;
276     }
277
278     /*
279      * Parameter is the command class
280      *
281      * The idea here is to keep each class of commands smaller than a screenful
282      */
283     switch (HelpType[0])
284     {
285     case 'G':
286         AcpiOsPrintf ("\nGeneral-Purpose Commands\n\n");
287         AcpiOsPrintf ("Allocations                         Display list of current memory allocations\n");
288         AcpiOsPrintf ("Dump <Address>|<Namepath>\n");
289         AcpiOsPrintf ("     [Byte|Word|Dword|Qword]        Display ACPI objects or memory\n");
290         AcpiOsPrintf ("EnableAcpi                          Enable ACPI (hardware) mode\n");
291         AcpiOsPrintf ("Help                                This help screen\n");
292         AcpiOsPrintf ("History                             Display command history buffer\n");
293         AcpiOsPrintf ("Level [<DebugLevel>] [console]      Get/Set debug level for file or console\n");
294         AcpiOsPrintf ("Locks                               Current status of internal mutexes\n");
295         AcpiOsPrintf ("Quit or Exit                        Exit this command\n");
296         AcpiOsPrintf ("Stats [Allocations|Memory|Misc\n");
297         AcpiOsPrintf ("       |Objects|Tables]             Display namespace and memory statistics\n");
298         AcpiOsPrintf ("Tables                              Display info about loaded ACPI tables\n");
299         AcpiOsPrintf ("Unload <TableSig> [Instance]        Unload an ACPI table\n");
300         AcpiOsPrintf ("! <CommandNumber>                   Execute command from history buffer\n");
301         AcpiOsPrintf ("!!                                  Execute last command again\n");
302         return;
303
304     case 'N':
305         AcpiOsPrintf ("\nNamespace Access Commands\n\n");
306         AcpiOsPrintf ("Event <F|G> <Value>                 Generate AcpiEvent (Fixed/GPE)\n");
307         AcpiOsPrintf ("Find <Name>   (? is wildcard)       Find ACPI name(s) with wildcards\n");
308         AcpiOsPrintf ("Method                              Display list of loaded control methods\n");
309         AcpiOsPrintf ("Namespace [<Addr>|<Path>] [Depth]   Display loaded namespace tree/subtree\n");
310         AcpiOsPrintf ("Notify <NamePath> <Value>           Send a notification\n");
311         AcpiOsPrintf ("Objects <ObjectType>                Display all objects of the given type\n");
312         AcpiOsPrintf ("Owner <OwnerId> [Depth]             Display loaded namespace by object owner\n");
313         AcpiOsPrintf ("Prefix [<NamePath>]                 Set or Get current execution prefix\n");
314         AcpiOsPrintf ("References <Addr>                   Find all references to object at addr\n");
315         AcpiOsPrintf ("Resources xxx                       Get and display resources\n");
316         AcpiOsPrintf ("Terminate                           Delete namespace and all internal objects\n");
317         AcpiOsPrintf ("Thread <Threads><Loops><NamePath>   Spawn threads to execute method(s)\n");
318         return;
319
320     case 'M':
321         AcpiOsPrintf ("\nControl Method Execution Commands\n\n");
322         AcpiOsPrintf ("Arguments (or Args)                 Display method arguments\n");
323         AcpiOsPrintf ("Breakpoint <AmlOffset>              Set an AML execution breakpoint\n");
324         AcpiOsPrintf ("Call                                Run to next control method invocation\n");
325         AcpiOsPrintf ("Debug <Namepath> [Arguments]        Single Step a control method\n");
326         AcpiOsPrintf ("Execute <Namepath> [Arguments]      Execute control method\n");
327         AcpiOsPrintf ("Go                                  Allow method to run to completion\n");
328         AcpiOsPrintf ("Information                         Display info about the current method\n");
329         AcpiOsPrintf ("Into                                Step into (not over) a method call\n");
330         AcpiOsPrintf ("List [# of Aml Opcodes]             Display method ASL statements\n");
331         AcpiOsPrintf ("Locals                              Display method local variables\n");
332         AcpiOsPrintf ("Results                             Display method result stack\n");
333         AcpiOsPrintf ("Set <A|L> <#> <Value>               Set method data (Arguments/Locals)\n");
334         AcpiOsPrintf ("Stop                                Terminate control method\n");
335         AcpiOsPrintf ("Tree                                Display control method calling tree\n");
336         AcpiOsPrintf ("<Enter>                             Single step next AML opcode (over calls)\n");
337         return;
338
339     case 'F':
340         AcpiOsPrintf ("\nFile I/O Commands\n\n");
341         AcpiOsPrintf ("Close                               Close debug output file\n");
342         AcpiOsPrintf ("Open <Output Filename>              Open a file for debug output\n");
343         AcpiOsPrintf ("Load <Input Filename>               Load ACPI table from a file\n");
344         return;
345
346     default:
347         AcpiOsPrintf ("Unrecognized Command Class: %s\n", HelpType);
348         return;
349     }
350 }
351
352
353 /*******************************************************************************
354  *
355  * FUNCTION:    AcpiDbGetNextToken
356  *
357  * PARAMETERS:  String          - Command buffer
358  *              Next            - Return value, end of next token
359  *
360  * RETURN:      Pointer to the start of the next token.
361  *
362  * DESCRIPTION: Command line parsing.  Get the next token on the command line
363  *
364  ******************************************************************************/
365
366 char *
367 AcpiDbGetNextToken (
368     char                    *String,
369     char                    **Next)
370 {
371     char                    *Start;
372
373
374     /* At end of buffer? */
375
376     if (!String || !(*String))
377     {
378         return (NULL);
379     }
380
381     /* Get rid of any spaces at the beginning */
382
383     if (*String == ' ')
384     {
385         while (*String && (*String == ' '))
386         {
387             String++;
388         }
389
390         if (!(*String))
391         {
392             return (NULL);
393         }
394     }
395
396     Start = String;
397
398     /* Find end of token */
399
400     while (*String && (*String != ' '))
401     {
402         String++;
403     }
404
405     if (!(*String))
406     {
407         *Next = NULL;
408     }
409     else
410     {
411         *String = 0;
412         *Next = String + 1;
413     }
414
415     return (Start);
416 }
417
418
419 /*******************************************************************************
420  *
421  * FUNCTION:    AcpiDbGetLine
422  *
423  * PARAMETERS:  InputBuffer         - Command line buffer
424  *
425  * RETURN:      None
426  *
427  * DESCRIPTION: Get the next command line from the user.  Gets entire line
428  *              up to the next newline
429  *
430  ******************************************************************************/
431
432 UINT32
433 AcpiDbGetLine (
434     char                    *InputBuffer)
435 {
436     UINT32                  i;
437     UINT32                  Count;
438     char                    *Next;
439     char                    *This;
440
441
442     ACPI_STRCPY (AcpiGbl_DbParsedBuf, InputBuffer);
443     ACPI_STRUPR (AcpiGbl_DbParsedBuf);
444
445     This = AcpiGbl_DbParsedBuf;
446     for (i = 0; i < ACPI_DEBUGGER_MAX_ARGS; i++)
447     {
448         AcpiGbl_DbArgs[i] = AcpiDbGetNextToken (This, &Next);
449         if (!AcpiGbl_DbArgs[i])
450         {
451             break;
452         }
453
454         This = Next;
455     }
456
457     /* Uppercase the actual command */
458
459     if (AcpiGbl_DbArgs[0])
460     {
461         ACPI_STRUPR (AcpiGbl_DbArgs[0]);
462     }
463
464     Count = i;
465     if (Count)
466     {
467         Count--;  /* Number of args only */
468     }
469
470     return (Count);
471 }
472
473
474 /*******************************************************************************
475  *
476  * FUNCTION:    AcpiDbMatchCommand
477  *
478  * PARAMETERS:  UserCommand             - User command line
479  *
480  * RETURN:      Index into command array, -1 if not found
481  *
482  * DESCRIPTION: Search command array for a command match
483  *
484  ******************************************************************************/
485
486 UINT32
487 AcpiDbMatchCommand (
488     char                    *UserCommand)
489 {
490     UINT32                  i;
491
492
493     if (!UserCommand || UserCommand[0] == 0)
494     {
495         return (CMD_NULL);
496     }
497
498     for (i = CMD_FIRST_VALID; AcpiGbl_DbCommands[i].Name; i++)
499     {
500         if (ACPI_STRSTR (AcpiGbl_DbCommands[i].Name, UserCommand) ==
501                          AcpiGbl_DbCommands[i].Name)
502         {
503             return (i);
504         }
505     }
506
507     /* Command not recognized */
508
509     return (CMD_NOT_FOUND);
510 }
511
512
513 /*******************************************************************************
514  *
515  * FUNCTION:    AcpiDbCommandDispatch
516  *
517  * PARAMETERS:  InputBuffer         - Command line buffer
518  *              WalkState           - Current walk
519  *              Op                  - Current (executing) parse op
520  *
521  * RETURN:      Status
522  *
523  * DESCRIPTION: Command dispatcher.  Called from two places:
524  *
525  ******************************************************************************/
526
527 ACPI_STATUS
528 AcpiDbCommandDispatch (
529     char                    *InputBuffer,
530     ACPI_WALK_STATE         *WalkState,
531     ACPI_PARSE_OBJECT       *Op)
532 {
533     UINT32                  Temp;
534     UINT32                  CommandIndex;
535     UINT32                  ParamCount;
536     char                    *CommandLine;
537     ACPI_STATUS             Status = AE_CTRL_TRUE;
538
539
540     /* If AcpiTerminate has been called, terminate this thread */
541
542     if (AcpiGbl_DbTerminateThreads)
543     {
544         return (AE_CTRL_TERMINATE);
545     }
546
547     ParamCount = AcpiDbGetLine (InputBuffer);
548     CommandIndex = AcpiDbMatchCommand (AcpiGbl_DbArgs[0]);
549     Temp = 0;
550
551     /* Verify that we have the minimum number of params */
552
553     if (ParamCount < AcpiGbl_DbCommands[CommandIndex].MinArgs)
554     {
555         AcpiOsPrintf ("%d parameters entered, [%s] requires %d parameters\n",
556                         ParamCount, AcpiGbl_DbCommands[CommandIndex].Name, AcpiGbl_DbCommands[CommandIndex].MinArgs);
557         return (AE_CTRL_TRUE);
558     }
559
560     /* Decode and dispatch the command */
561
562     switch (CommandIndex)
563     {
564     case CMD_NULL:
565         if (Op)
566         {
567             return (AE_OK);
568         }
569         break;
570
571     case CMD_ALLOCATIONS:
572
573 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
574         AcpiUtDumpAllocations ((UINT32) -1, NULL);
575 #endif
576         break;
577
578     case CMD_ARGS:
579     case CMD_ARGUMENTS:
580         AcpiDbDisplayArguments ();
581         break;
582
583     case CMD_BREAKPOINT:
584         AcpiDbSetMethodBreakpoint (AcpiGbl_DbArgs[1], WalkState, Op);
585         break;
586
587     case CMD_CALL:
588         AcpiDbSetMethodCallBreakpoint (Op);
589         Status = AE_OK;
590         break;
591
592     case CMD_CLOSE:
593         AcpiDbCloseDebugFile ();
594         break;
595
596     case CMD_DEBUG:
597         AcpiDbExecute (AcpiGbl_DbArgs[1], &AcpiGbl_DbArgs[2], EX_SINGLE_STEP);
598         break;
599
600     case CMD_DUMP:
601         AcpiDbDecodeAndDisplayObject (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
602         break;
603
604     case CMD_ENABLEACPI:
605         Status = AcpiEnable();
606         if (ACPI_FAILURE(Status))
607         {
608             AcpiOsPrintf("AcpiEnable failed (Status=%X)\n", Status);
609             return (Status);
610         }
611         break;
612
613     case CMD_EVENT:
614         AcpiOsPrintf ("Event command not implemented\n");
615         break;
616
617     case CMD_EXECUTE:
618         AcpiDbExecute (AcpiGbl_DbArgs[1], &AcpiGbl_DbArgs[2], EX_NO_SINGLE_STEP);
619         break;
620
621     case CMD_FIND:
622         AcpiDbFindNameInNamespace (AcpiGbl_DbArgs[1]);
623         break;
624
625     case CMD_GO:
626         AcpiGbl_CmSingleStep = FALSE;
627         return (AE_OK);
628
629     case CMD_GPE:
630         AcpiDbGenerateGpe (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
631         break;
632
633     case CMD_GPES:
634         AcpiDbDisplayGpes ();
635         break;
636
637     case CMD_HELP:
638     case CMD_HELP2:
639         AcpiDbDisplayHelp (AcpiGbl_DbArgs[1]);
640         break;
641
642     case CMD_HISTORY:
643         AcpiDbDisplayHistory ();
644         break;
645
646     case CMD_HISTORY_EXE:
647         CommandLine = AcpiDbGetFromHistory (AcpiGbl_DbArgs[1]);
648         if (!CommandLine)
649         {
650             return (AE_CTRL_TRUE);
651         }
652
653         Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
654         if (ACPI_SUCCESS (Status))
655         {
656             Status = AE_CTRL_TRUE;
657         }
658         return (Status);
659
660     case CMD_HISTORY_LAST:
661         CommandLine = AcpiDbGetFromHistory (NULL);
662         if (!CommandLine)
663         {
664             return (AE_CTRL_TRUE);
665         }
666
667         Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
668         if (ACPI_SUCCESS (Status))
669         {
670             Status = AE_CTRL_TRUE;
671         }
672         return (Status);
673
674     case CMD_INFORMATION:
675         AcpiDbDisplayMethodInfo (Op);
676         break;
677
678     case CMD_INTEGRITY:
679         AcpiDbCheckIntegrity ();
680         break;
681
682     case CMD_INTO:
683         if (Op)
684         {
685             AcpiGbl_CmSingleStep = TRUE;
686             return (AE_OK);
687         }
688         break;
689
690     case CMD_LEVEL:
691         if (ParamCount == 0)
692         {
693             AcpiOsPrintf ("Current debug level for file output is:    %8.8lX\n", AcpiGbl_DbDebugLevel);
694             AcpiOsPrintf ("Current debug level for console output is: %8.8lX\n", AcpiGbl_DbConsoleDebugLevel);
695         }
696         else if (ParamCount == 2)
697         {
698             Temp = AcpiGbl_DbConsoleDebugLevel;
699             AcpiGbl_DbConsoleDebugLevel = ACPI_STRTOUL (AcpiGbl_DbArgs[1], NULL, 16);
700             AcpiOsPrintf ("Debug Level for console output was %8.8lX, now %8.8lX\n", Temp, AcpiGbl_DbConsoleDebugLevel);
701         }
702         else
703         {
704             Temp = AcpiGbl_DbDebugLevel;
705             AcpiGbl_DbDebugLevel = ACPI_STRTOUL (AcpiGbl_DbArgs[1], NULL, 16);
706             AcpiOsPrintf ("Debug Level for file output was %8.8lX, now %8.8lX\n", Temp, AcpiGbl_DbDebugLevel);
707         }
708         break;
709
710     case CMD_LIST:
711         AcpiDbDisassembleAml (AcpiGbl_DbArgs[1], Op);
712         break;
713
714     case CMD_LOAD:
715         Status = AcpiDbGetTableFromFile (AcpiGbl_DbArgs[1], NULL);
716         if (ACPI_FAILURE (Status))
717         {
718             return (Status);
719         }
720         break;
721
722     case CMD_LOCKS:
723         AcpiDbDisplayLocks ();
724         break;
725
726     case CMD_LOCALS:
727         AcpiDbDisplayLocals ();
728         break;
729
730     case CMD_METHODS:
731         AcpiDbDisplayObjects ("METHOD", AcpiGbl_DbArgs[1]);
732         break;
733
734     case CMD_NAMESPACE:
735         AcpiDbDumpNamespace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
736         break;
737
738     case CMD_NOTIFY:
739         Temp = ACPI_STRTOUL (AcpiGbl_DbArgs[2], NULL, 0);
740         AcpiDbSendNotify (AcpiGbl_DbArgs[1], Temp);
741         break;
742
743     case CMD_OBJECT:
744         ACPI_STRUPR (AcpiGbl_DbArgs[1]);
745         AcpiDbDisplayObjects (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
746         break;
747
748     case CMD_OPEN:
749         AcpiDbOpenDebugFile (AcpiGbl_DbArgs[1]);
750         break;
751
752     case CMD_OWNER:
753         AcpiDbDumpNamespaceByOwner (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
754         break;
755
756     case CMD_PREFIX:
757         AcpiDbSetScope (AcpiGbl_DbArgs[1]);
758         break;
759
760     case CMD_REFERENCES:
761         AcpiDbFindReferences (AcpiGbl_DbArgs[1]);
762         break;
763
764     case CMD_RESOURCES:
765         AcpiDbDisplayResources (AcpiGbl_DbArgs[1]);
766         break;
767
768     case CMD_RESULTS:
769         AcpiDbDisplayResults ();
770         break;
771
772     case CMD_SET:
773         AcpiDbSetMethodData (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], AcpiGbl_DbArgs[3]);
774         break;
775
776     case CMD_STATS:
777         AcpiDbDisplayStatistics (AcpiGbl_DbArgs[1]);
778         break;
779
780     case CMD_STOP:
781         return (AE_NOT_IMPLEMENTED);
782
783     case CMD_TABLES:
784         AcpiDbDisplayTableInfo (AcpiGbl_DbArgs[1]);
785         break;
786
787     case CMD_TERMINATE:
788         AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
789         AcpiUtSubsystemShutdown ();
790
791         /* TBD: [Restructure] Need some way to re-initialize without re-creating the semaphores! */
792
793         /*  AcpiInitialize (NULL);  */
794         break;
795
796     case CMD_THREADS:
797         AcpiDbCreateExecutionThreads (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], AcpiGbl_DbArgs[3]);
798         break;
799
800     case CMD_TREE:
801         AcpiDbDisplayCallingTree ();
802         break;
803
804     case CMD_UNLOAD:
805         AcpiDbUnloadAcpiTable (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
806         break;
807
808     case CMD_EXIT:
809     case CMD_QUIT:
810         if (Op)
811         {
812             AcpiOsPrintf ("Method execution terminated\n");
813             return (AE_CTRL_TERMINATE);
814         }
815
816         if (!AcpiGbl_DbOutputToFile)
817         {
818             AcpiDbgLevel = ACPI_DEBUG_DEFAULT;
819         }
820
821         /* Shutdown */
822
823         /* AcpiUtSubsystemShutdown (); */
824         AcpiDbCloseDebugFile ();
825
826         AcpiGbl_DbTerminateThreads = TRUE;
827
828         return (AE_CTRL_TERMINATE);
829
830     case CMD_NOT_FOUND:
831     default:
832         AcpiOsPrintf ("Unknown Command\n");
833         return (AE_CTRL_TRUE);
834     }
835
836
837     /* Add all commands that come here to the history buffer */
838
839     AcpiDbAddToHistory (InputBuffer);
840     return (Status);
841 }
842
843
844 /*******************************************************************************
845  *
846  * FUNCTION:    AcpiDbExecuteThread
847  *
848  * PARAMETERS:  Context         - Not used
849  *
850  * RETURN:      None
851  *
852  * DESCRIPTION: Debugger execute thread.  Waits for a command line, then
853  *              simply dispatches it.
854  *
855  ******************************************************************************/
856
857 void ACPI_SYSTEM_XFACE
858 AcpiDbExecuteThread (
859     void                    *Context)
860 {
861     ACPI_STATUS             Status = AE_OK;
862     ACPI_STATUS             MStatus;
863
864
865     while (Status != AE_CTRL_TERMINATE)
866     {
867         AcpiGbl_MethodExecuting = FALSE;
868         AcpiGbl_StepToNextCall = FALSE;
869
870         MStatus = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY);
871         if (ACPI_FAILURE (MStatus))
872         {
873             return;
874         }
875
876         Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
877
878         MStatus = AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
879         if (ACPI_FAILURE (MStatus))
880         {
881             return;
882         }
883     }
884 }
885
886
887 /*******************************************************************************
888  *
889  * FUNCTION:    AcpiDbSingleThread
890  *
891  * PARAMETERS:  None
892  *
893  * RETURN:      None
894  *
895  * DESCRIPTION: Debugger execute thread.  Waits for a command line, then
896  *              simply dispatches it.
897  *
898  ******************************************************************************/
899
900 void
901 AcpiDbSingleThread (
902     void)
903 {
904
905     AcpiGbl_MethodExecuting = FALSE;
906     AcpiGbl_StepToNextCall = FALSE;
907
908     (void) AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
909 }
910
911
912 /*******************************************************************************
913  *
914  * FUNCTION:    AcpiDbUserCommands
915  *
916  * PARAMETERS:  Prompt              - User prompt (depends on mode)
917  *              Op                  - Current executing parse op
918  *
919  * RETURN:      None
920  *
921  * DESCRIPTION: Command line execution for the AML debugger.  Commands are
922  *              matched and dispatched here.
923  *
924  ******************************************************************************/
925
926 ACPI_STATUS
927 AcpiDbUserCommands (
928     char                    Prompt,
929     ACPI_PARSE_OBJECT       *Op)
930 {
931     ACPI_STATUS             Status = AE_OK;
932
933
934     /* TBD: [Restructure] Need a separate command line buffer for step mode */
935
936     while (!AcpiGbl_DbTerminateThreads)
937     {
938         /* Force output to console until a command is entered */
939
940         AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
941
942         /* Different prompt if method is executing */
943
944         if (!AcpiGbl_MethodExecuting)
945         {
946             AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
947         }
948         else
949         {
950             AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
951         }
952
953         /* Get the user input line */
954
955         (void) AcpiOsGetLine (AcpiGbl_DbLineBuf);
956
957         /* Check for single or multithreaded debug */
958
959         if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
960         {
961             /*
962              * Signal the debug thread that we have a command to execute,
963              * and wait for the command to complete.
964              */
965             Status = AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_READY);
966             if (ACPI_FAILURE (Status))
967             {
968                 return (Status);
969             }
970
971             Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
972             if (ACPI_FAILURE (Status))
973             {
974                 return (Status);
975             }
976         }
977         else
978         {
979             /* Just call to the command line interpreter */
980
981             AcpiDbSingleThread ();
982         }
983     }
984
985     /*
986      * Only this thread (the original thread) should actually terminate the subsystem,
987      * because all the semaphores are deleted during termination
988      */
989     Status = AcpiTerminate ();
990     return (Status);
991 }
992
993
994 #endif  /* ACPI_DEBUGGER */
995