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