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