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