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