dbinput.c revision 256281
121308Sache/*******************************************************************************
221308Sache *
321308Sache * Module Name: dbinput - user front-end to the AML debugger
4119610Sache *
521308Sache ******************************************************************************/
621308Sache
721308Sache/*
821308Sache * Copyright (C) 2000 - 2013, Intel Corp.
921308Sache * All rights reserved.
1021308Sache *
1158310Sache * Redistribution and use in source and binary forms, with or without
1221308Sache * modification, are permitted provided that the following conditions
1321308Sache * are met:
1421308Sache * 1. Redistributions of source code must retain the above copyright
1521308Sache *    notice, this list of conditions, and the following disclaimer,
1621308Sache *    without modification.
1721308Sache * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1821308Sache *    substantially similar to the "NO WARRANTY" disclaimer below
1921308Sache *    ("Disclaimer") and any redistribution must be conditioned upon
2021308Sache *    including a substantially similar Disclaimer requirement for further
2121308Sache *    binary redistribution.
2258310Sache * 3. Neither the names of the above-listed copyright holders nor the names
2321308Sache *    of any contributors may be used to endorse or promote products derived
2421308Sache *    from this software without specific prior written permission.
2521308Sache *
2621308Sache * Alternatively, this software may be distributed under the terms of the
2721308Sache * GNU General Public License ("GPL") version 2 as published by the Free
2821308Sache * Software Foundation.
2921308Sache *
3021308Sache * NO WARRANTY
3121308Sache * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3221308Sache * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3321308Sache * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3421308Sache * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3521308Sache * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3621308Sache * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3721308Sache * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3821308Sache * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3921308Sache * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4021308Sache * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4121308Sache * POSSIBILITY OF SUCH DAMAGES.
4221308Sache */
4321308Sache
4421308Sache
4521308Sache#include <contrib/dev/acpica/include/acpi.h>
4621308Sache#include <contrib/dev/acpica/include/accommon.h>
4721308Sache#include <contrib/dev/acpica/include/acdebug.h>
4821308Sache
4921308Sache
5021308Sache#ifdef ACPI_DEBUGGER
5126497Sache
5221308Sache#define _COMPONENT          ACPI_CA_DEBUGGER
5321308Sache        ACPI_MODULE_NAME    ("dbinput")
5421308Sache
55119610Sache/* Local prototypes */
5621308Sache
5726497Sachestatic UINT32
5826497SacheAcpiDbGetLine (
5926497Sache    char                    *InputBuffer);
6026497Sache
6121308Sachestatic UINT32
6221308SacheAcpiDbMatchCommand (
6321308Sache    char                    *UserCommand);
6421308Sache
6521308Sachestatic void
6658310SacheAcpiDbSingleThread (
6758310Sache    void);
6858310Sache
6958310Sachestatic void
7026497SacheAcpiDbDisplayCommandInfo (
71136644Sache    char                    *Command,
7226497Sache    BOOLEAN                 DisplayAll);
7326497Sache
74119610Sachestatic void
75136644SacheAcpiDbDisplayHelp (
76119610Sache    char                    *Command);
7721308Sache
78119610Sachestatic BOOLEAN
79119610SacheAcpiDbMatchCommandHelp (
8021308Sache    char                        *Command,
81119610Sache    const ACPI_DB_COMMAND_HELP  *Help);
82119610Sache
8321308Sache
84119610Sache/*
85119610Sache * Top-level debugger commands.
8621308Sache *
87119610Sache * This list of commands must match the string table below it
88136644Sache */
8921308Sacheenum AcpiExDebuggerCommands
9021308Sache{
9121308Sache    CMD_NOT_FOUND = 0,
9221308Sache    CMD_NULL,
9321308Sache    CMD_ALLOCATIONS,
9421308Sache    CMD_ARGS,
9521308Sache    CMD_ARGUMENTS,
9675406Sache    CMD_BATCH,
9721308Sache    CMD_BREAKPOINT,
98119610Sache    CMD_BUSINFO,
99119610Sache    CMD_CALL,
10075406Sache    CMD_CLOSE,
10158310Sache    CMD_DEBUG,
10258310Sache    CMD_DISASSEMBLE,
10321308Sache    CMD_DISASM,
10421308Sache    CMD_DUMP,
10521308Sache    CMD_ENABLEACPI,
10621308Sache    CMD_EVALUATE,
10721308Sache    CMD_EVENT,
10821308Sache    CMD_EXECUTE,
10921308Sache    CMD_EXIT,
110119610Sache    CMD_FIND,
111119610Sache    CMD_GO,
112119610Sache    CMD_GPE,
11326497Sache    CMD_GPES,
11426497Sache    CMD_HANDLERS,
11526497Sache    CMD_HELP,
11626497Sache    CMD_HELP2,
11726497Sache    CMD_HISTORY,
11821308Sache    CMD_HISTORY_EXE,
11921308Sache    CMD_HISTORY_LAST,
12021308Sache    CMD_INFORMATION,
12121308Sache    CMD_INTEGRITY,
12221308Sache    CMD_INTO,
12321308Sache    CMD_LEVEL,
12421308Sache    CMD_LIST,
12521308Sache    CMD_LOAD,
12621308Sache    CMD_LOCALS,
12721308Sache    CMD_LOCKS,
12821308Sache    CMD_METHODS,
12921308Sache    CMD_NAMESPACE,
13021308Sache    CMD_NOTIFY,
13121308Sache    CMD_OBJECT,
13221308Sache    CMD_OPEN,
13375406Sache    CMD_OSI,
13421308Sache    CMD_OWNER,
13521308Sache    CMD_PATHS,
13675406Sache    CMD_PREDEFINED,
13721308Sache    CMD_PREFIX,
13875406Sache    CMD_QUIT,
13975406Sache    CMD_REFERENCES,
14075406Sache    CMD_RESOURCES,
14121308Sache    CMD_RESULTS,
14221308Sache    CMD_SCI,
14321308Sache    CMD_SET,
14421308Sache    CMD_SLEEP,
14521308Sache    CMD_STATS,
14621308Sache    CMD_STOP,
14721308Sache    CMD_TABLES,
14821308Sache    CMD_TEMPLATE,
14921308Sache    CMD_TERMINATE,
15021308Sache    CMD_THREADS,
15121308Sache    CMD_TRACE,
15221308Sache    CMD_TREE,
15321308Sache    CMD_TYPE,
15475406Sache    CMD_UNLOAD
15521308Sache};
15621308Sache
15726497Sache#define CMD_FIRST_VALID     2
15821308Sache
15921308Sache
16021308Sache/* Second parameter is the required argument count */
16121308Sache
16221308Sachestatic const ACPI_DB_COMMAND_INFO   AcpiGbl_DbCommands[] =
16321308Sache{
16421308Sache    {"<NOT FOUND>",  0},
16521308Sache    {"<NULL>",       0},
166119610Sache    {"ALLOCATIONS",  0},
167119610Sache    {"ARGS",         0},
168119610Sache    {"ARGUMENTS",    0},
169119610Sache    {"BATCH",        0},
170119610Sache    {"BREAKPOINT",   1},
17121308Sache    {"BUSINFO",      0},
17221308Sache    {"CALL",         0},
17375406Sache    {"CLOSE",        0},
17421308Sache    {"DEBUG",        1},
17521308Sache    {"DISASSEMBLE",  1},
17658310Sache    {"DISASM",       1},
17758310Sache    {"DUMP",         1},
17858310Sache    {"ENABLEACPI",   0},
17958310Sache    {"EVALUATE",     1},
18021308Sache    {"EVENT",        1},
18121308Sache    {"EXECUTE",      1},
18221308Sache    {"EXIT",         0},
18321308Sache    {"FIND",         1},
18447558Sache    {"GO",           0},
18575406Sache    {"GPE",          2},
18621308Sache    {"GPES",         0},
18747558Sache    {"HANDLERS",     0},
18847558Sache    {"HELP",         0},
18947558Sache    {"?",            0},
19075406Sache    {"HISTORY",      0},
19147558Sache    {"!",            1},
19221308Sache    {"!!",           0},
19321308Sache    {"INFORMATION",  0},
19421308Sache    {"INTEGRITY",    0},
19521308Sache    {"INTO",         0},
19621308Sache    {"LEVEL",        0},
19721308Sache    {"LIST",         0},
19821308Sache    {"LOAD",         1},
19921308Sache    {"LOCALS",       0},
20021308Sache    {"LOCKS",        0},
20121308Sache    {"METHODS",      0},
20221308Sache    {"NAMESPACE",    0},
20375406Sache    {"NOTIFY",       2},
20421308Sache    {"OBJECT",       1},
20521308Sache    {"OPEN",         1},
20621308Sache    {"OSI",          0},
20721308Sache    {"OWNER",        1},
20821308Sache    {"PATHS",        0},
20921308Sache    {"PREDEFINED",   0},
21021308Sache    {"PREFIX",       0},
21121308Sache    {"QUIT",         0},
21221308Sache    {"REFERENCES",   1},
21321308Sache    {"RESOURCES",    0},
21421308Sache    {"RESULTS",      0},
21521308Sache    {"SCI",          0},
21621308Sache    {"SET",          3},
21721308Sache    {"SLEEP",        0},
21821308Sache    {"STATS",        1},
21921308Sache    {"STOP",         0},
22021308Sache    {"TABLES",       0},
22121308Sache    {"TEMPLATE",     1},
22247558Sache    {"TERMINATE",    0},
22347558Sache    {"THREADS",      3},
22447558Sache    {"TRACE",        1},
22558310Sache    {"TREE",         0},
22658310Sache    {"TYPE",         1},
22758310Sache    {"UNLOAD",       1},
22858310Sache    {NULL,           0}
22921308Sache};
23021308Sache
23121308Sache/*
23221308Sache * Help for all debugger commands. First argument is the number of lines
233119610Sache * of help to output for the command.
23421308Sache */
23521308Sachestatic const ACPI_DB_COMMAND_HELP   AcpiGbl_DbCommandHelp[] =
23621308Sache{
23721308Sache    {0, "\nGeneral-Purpose Commands:",         "\n"},
23821308Sache    {1, "  Allocations",                       "Display list of current memory allocations\n"},
23921308Sache    {2, "  Dump <Address>|<Namepath>",         "\n"},
24021308Sache    {0, "       [Byte|Word|Dword|Qword]",      "Display ACPI objects or memory\n"},
24121308Sache    {1, "  EnableAcpi",                        "Enable ACPI (hardware) mode\n"},
24221308Sache    {1, "  Handlers",                          "Info about global handlers\n"},
24321308Sache    {1, "  Help [Command]",                    "This help screen or individual command\n"},
24421308Sache    {1, "  History",                           "Display command history buffer\n"},
24521308Sache    {1, "  Level <DebugLevel>] [console]",     "Get/Set debug level for file or console\n"},
24621308Sache    {1, "  Locks",                             "Current status of internal mutexes\n"},
24721308Sache    {1, "  Osi [Install|Remove <name>]",       "Display or modify global _OSI list\n"},
24821308Sache    {1, "  Quit or Exit",                      "Exit this command\n"},
24921308Sache    {9, "  Stats [Allocations|Memory|Misc|",   "\n"},
25021308Sache    {1, "      Objects|Sizes|Stack|Tables]",   "Display namespace and memory statistics\n"},
25121308Sache    {1, "     Allocations",                    "Display list of current memory allocations\n"},
25221308Sache    {1, "     Memory",                         "Dump internal memory lists\n"},
25321308Sache    {1, "     Misc",                           "Namespace search and mutex stats\n"},
25421308Sache    {1, "     Objects",                        "Summary of namespace objects\n"},
25521308Sache    {1, "     Sizes",                          "Sizes for each of the internal objects\n"},
25621308Sache    {1, "     Stack",                          "Display CPU stack usage\n"},
25721308Sache    {1, "     Tables",                         "Info about current ACPI table(s)\n"},
25821308Sache    {1, "  Tables",                            "Display info about loaded ACPI tables\n"},
25921308Sache    {1, "  Unload <Namepath>",                 "Unload an ACPI table via namespace object\n"},
26021308Sache    {1, "  ! <CommandNumber>",                 "Execute command from history buffer\n"},
26121308Sache    {1, "  !!",                                "Execute last command again\n"},
26221308Sache
26375406Sache    {0, "\nNamespace Access Commands:",        "\n"},
26475406Sache    {1, "  Businfo",                           "Display system bus info\n"},
26575406Sache    {1, "  Disassemble <Method>",              "Disassemble a control method\n"},
26675406Sache    {1, "  Find <AcpiName> (? is wildcard)",   "Find ACPI name(s) with wildcards\n"},
26775406Sache    {1, "  Integrity",                         "Validate namespace integrity\n"},
26875406Sache    {1, "  Methods",                           "Display list of loaded control methods\n"},
26975406Sache    {1, "  Namespace [Object] [Depth]",        "Display loaded namespace tree/subtree\n"},
27075406Sache    {1, "  Notify <Object> <Value>",           "Send a notification on Object\n"},
27175406Sache    {1, "  Objects <ObjectType>",              "Display all objects of the given type\n"},
272119610Sache    {1, "  Owner <OwnerId> [Depth]",           "Display loaded namespace by object owner\n"},
27375406Sache    {1, "  Paths",                             "Display full pathnames of namespace objects\n"},
27475406Sache    {1, "  Predefined",                        "Check all predefined names\n"},
27575406Sache    {1, "  Prefix [<NamePath>]",               "Set or Get current execution prefix\n"},
27621308Sache    {1, "  References <Addr>",                 "Find all references to object at addr\n"},
27721308Sache    {1, "  Resources [DeviceName]",            "Display Device resources (no arg = all devices)\n"},
27821308Sache    {1, "  Set N <NamedObject> <Value>",       "Set value for named integer\n"},
27921308Sache    {1, "  Template <Object>",                 "Format/dump a Buffer/ResourceTemplate\n"},
28075406Sache    {1, "  Terminate",                         "Delete namespace and all internal objects\n"},
28121308Sache    {1, "  Type <Object>",                     "Display object type\n"},
28221308Sache
28321308Sache    {0, "\nControl Method Execution Commands:","\n"},
28421308Sache    {1, "  Arguments (or Args)",               "Display method arguments\n"},
28521308Sache    {1, "  Breakpoint <AmlOffset>",            "Set an AML execution breakpoint\n"},
28621308Sache    {1, "  Call",                              "Run to next control method invocation\n"},
28775406Sache    {1, "  Debug <Namepath> [Arguments]",      "Single Step a control method\n"},
28821308Sache    {6, "  Evaluate",                          "Synonym for Execute\n"},
28921308Sache    {5, "  Execute <Namepath> [Arguments]",    "Execute control method\n"},
29021308Sache    {1, "     Hex Integer",                    "Integer method argument\n"},
29175406Sache    {1, "     \"Ascii String\"",               "String method argument\n"},
29221308Sache    {1, "     (Hex Byte List)",                "Buffer method argument\n"},
29321308Sache    {1, "     [Package Element List]",         "Package method argument\n"},
29421308Sache    {1, "  Go",                                "Allow method to run to completion\n"},
29521308Sache    {1, "  Information",                       "Display info about the current method\n"},
29621308Sache    {1, "  Into",                              "Step into (not over) a method call\n"},
29721308Sache    {1, "  List [# of Aml Opcodes]",           "Display method ASL statements\n"},
29821308Sache    {1, "  Locals",                            "Display method local variables\n"},
29921308Sache    {1, "  Results",                           "Display method result stack\n"},
30021308Sache    {1, "  Set <A|L> <#> <Value>",             "Set method data (Arguments/Locals)\n"},
30121308Sache    {1, "  Stop",                              "Terminate control method\n"},
30221308Sache    {1, "  Thread <Threads><Loops><NamePath>", "Spawn threads to execute method(s)\n"},
30321308Sache    {1, "  Trace <method name>",               "Trace method execution\n"},
30421308Sache    {1, "  Tree",                              "Display control method calling tree\n"},
30521308Sache    {1, "  <Enter>",                           "Single step next AML opcode (over calls)\n"},
30621308Sache
30721308Sache    {0, "\nHardware Related Commands:",         "\n"},
30821308Sache    {1, "  Event <F|G> <Value>",               "Generate AcpiEvent (Fixed/GPE)\n"},
30921308Sache    {1, "  Gpe <GpeNum> <GpeBlock>",           "Simulate a GPE\n"},
31021308Sache    {1, "  Gpes",                              "Display info on all GPEs\n"},
31121308Sache    {1, "  Sci",                               "Generate an SCI\n"},
31221308Sache    {1, "  Sleep [SleepState]",                "Simulate sleep/wake sequence(s) (0-5)\n"},
31321308Sache
31421308Sache    {0, "\nFile I/O Commands:",                "\n"},
31521308Sache    {1, "  Close",                             "Close debug output file\n"},
31621308Sache    {1, "  Load <Input Filename>",             "Load ACPI table from a file\n"},
31721308Sache    {1, "  Open <Output Filename>",            "Open a file for debug output\n"},
31821308Sache    {0, NULL, NULL}
31958310Sache};
32058310Sache
32121308Sache
32221308Sache/*******************************************************************************
32321308Sache *
32421308Sache * FUNCTION:    AcpiDbMatchCommandHelp
32521308Sache *
32621308Sache * PARAMETERS:  Command             - Command string to match
327119610Sache *              Help                - Help table entry to attempt match
328119610Sache *
329119610Sache * RETURN:      TRUE if command matched, FALSE otherwise
330119610Sache *
33121308Sache * DESCRIPTION: Attempt to match a command in the help table in order to
33258310Sache *              print help information for a single command.
33321308Sache *
33458310Sache ******************************************************************************/
33558310Sache
33621308Sachestatic BOOLEAN
33758310SacheAcpiDbMatchCommandHelp (
33821308Sache    char                        *Command,
33921308Sache    const ACPI_DB_COMMAND_HELP  *Help)
34021308Sache{
34121308Sache    char                    *Invocation = Help->Invocation;
34258310Sache    UINT32                  LineCount;
34358310Sache
34458310Sache
34558310Sache    /* Valid commands in the help table begin with a couple of spaces */
34621308Sache
347119610Sache    if (*Invocation != ' ')
348119610Sache    {
34921308Sache        return (FALSE);
350119610Sache    }
351136644Sache
35221308Sache    while (*Invocation == ' ')
35347558Sache    {
35447558Sache        Invocation++;
35547558Sache    }
35621308Sache
35721308Sache    /* Match command name (full command or substring) */
35821308Sache
35921308Sache    while ((*Command) && (*Invocation) && (*Invocation != ' '))
36021308Sache    {
36121308Sache        if (ACPI_TOLOWER (*Command) != ACPI_TOLOWER (*Invocation))
36221308Sache        {
36321308Sache            return (FALSE);
36421308Sache        }
36521308Sache
36621308Sache        Invocation++;
36721308Sache        Command++;
36821308Sache    }
36921308Sache
37021308Sache    /* Print the appropriate number of help lines */
37121308Sache
37221308Sache    LineCount = Help->LineCount;
37347558Sache    while (LineCount)
37421308Sache    {
37521308Sache        AcpiOsPrintf ("%-38s : %s", Help->Invocation, Help->Description);
37621308Sache        Help++;
37721308Sache        LineCount--;
37821308Sache    }
37921308Sache
38021308Sache    return (TRUE);
38121308Sache}
38221308Sache
38375406Sache
38421308Sache/*******************************************************************************
385119610Sache *
386119610Sache * FUNCTION:    AcpiDbDisplayCommandInfo
387119610Sache *
38821308Sache * PARAMETERS:  Command             - Command string to match
38921308Sache *              DisplayAll          - Display all matching commands, or just
39021308Sache *                                    the first one (substring match)
39121308Sache *
39221308Sache * RETURN:      None
39321308Sache *
39421308Sache * DESCRIPTION: Display help information for a Debugger command.
39521308Sache *
39621308Sache ******************************************************************************/
39721308Sache
39821308Sachestatic void
39921308SacheAcpiDbDisplayCommandInfo (
40021308Sache    char                    *Command,
40121308Sache    BOOLEAN                 DisplayAll)
40221308Sache{
40321308Sache    const ACPI_DB_COMMAND_HELP  *Next;
40421308Sache    BOOLEAN                     Matched;
40521308Sache
40621308Sache
40721308Sache    Next = AcpiGbl_DbCommandHelp;
40821308Sache    while (Next->Invocation)
40921308Sache    {
41021308Sache        Matched = AcpiDbMatchCommandHelp (Command, Next);
41121308Sache        if (!DisplayAll && Matched)
41221308Sache        {
41321308Sache            return;
41421308Sache        }
41521308Sache
41621308Sache        Next++;
41721308Sache    }
41821308Sache}
41921308Sache
42021308Sache
42121308Sache/*******************************************************************************
42275406Sache *
42321308Sache * FUNCTION:    AcpiDbDisplayHelp
42475406Sache *
42521308Sache * PARAMETERS:  Command             - Optional command string to display help.
42621308Sache *                                    if not specified, all debugger command
42721308Sache *                                    help strings are displayed
42821308Sache *
42921308Sache * RETURN:      None
43021308Sache *
43121308Sache * DESCRIPTION: Display help for a single debugger command, or all of them.
43221308Sache *
43321308Sache ******************************************************************************/
43421308Sache
43575406Sachestatic void
43621308SacheAcpiDbDisplayHelp (
43721308Sache    char                    *Command)
43821308Sache{
43921308Sache    const ACPI_DB_COMMAND_HELP  *Next = AcpiGbl_DbCommandHelp;
44021308Sache
44121308Sache
44221308Sache    if (!Command)
44321308Sache    {
44458310Sache        /* No argument to help, display help for all commands */
44521308Sache
44621308Sache        while (Next->Invocation)
44721308Sache        {
44821308Sache            AcpiOsPrintf ("%-38s%s", Next->Invocation, Next->Description);
44921308Sache            Next++;
45021308Sache        }
45121308Sache    }
45221308Sache    else
45321308Sache    {
45421308Sache        /* Display help for all commands that match the subtring */
45521308Sache
45621308Sache        AcpiDbDisplayCommandInfo (Command, TRUE);
45721308Sache    }
45821308Sache}
45958310Sache
46058310Sache
46158310Sache/*******************************************************************************
46258310Sache *
46358310Sache * FUNCTION:    AcpiDbGetNextToken
46458310Sache *
46521308Sache * PARAMETERS:  String          - Command buffer
46621308Sache *              Next            - Return value, end of next token
46721308Sache *
46847558Sache * RETURN:      Pointer to the start of the next token.
46947558Sache *
47047558Sache * DESCRIPTION: Command line parsing. Get the next token on the command line
47147558Sache *
47247558Sache ******************************************************************************/
47347558Sache
47421308Sachechar *
47521308SacheAcpiDbGetNextToken (
47621308Sache    char                    *String,
47721308Sache    char                    **Next,
47821308Sache    ACPI_OBJECT_TYPE        *ReturnType)
47921308Sache{
48021308Sache    char                    *Start;
48121308Sache    UINT32                  Depth;
48221308Sache    ACPI_OBJECT_TYPE        Type = ACPI_TYPE_INTEGER;
48321308Sache
48421308Sache
48521308Sache    /* At end of buffer? */
48621308Sache
48747558Sache    if (!String || !(*String))
48821308Sache    {
48921308Sache        return (NULL);
49021308Sache    }
49121308Sache
49221308Sache    /* Remove any spaces at the beginning */
49321308Sache
49421308Sache    if (*String == ' ')
49521308Sache    {
49621308Sache        while (*String && (*String == ' '))
49721308Sache        {
49821308Sache            String++;
49921308Sache        }
50021308Sache
50121308Sache        if (!(*String))
50221308Sache        {
50321308Sache            return (NULL);
50421308Sache        }
50521308Sache    }
50621308Sache
50721308Sache    switch (*String)
50821308Sache    {
50926497Sache    case '"':
51026497Sache
511119610Sache        /* This is a quoted string, scan until closing quote */
51226497Sache
51326497Sache        String++;
51426497Sache        Start = String;
51526497Sache        Type = ACPI_TYPE_STRING;
51626497Sache
51721308Sache        /* Find end of string */
51821308Sache
51921308Sache        while (*String && (*String != '"'))
52021308Sache        {
52121308Sache            String++;
52221308Sache        }
52321308Sache        break;
52421308Sache
52521308Sache    case '(':
52621308Sache
52721308Sache        /* This is the start of a buffer, scan until closing paren */
52821308Sache
52921308Sache        String++;
530119610Sache        Start = String;
531119610Sache        Type = ACPI_TYPE_BUFFER;
532119610Sache
533119610Sache        /* Find end of buffer */
534119610Sache
535119610Sache        while (*String && (*String != ')'))
536119610Sache        {
537119610Sache            String++;
538119610Sache        }
53921308Sache        break;
54021308Sache
54175406Sache    case '[':
54221308Sache
54321308Sache        /* This is the start of a package, scan until closing bracket */
54421308Sache
54521308Sache        String++;
54621308Sache        Depth = 1;
547119610Sache        Start = String;
54821308Sache        Type = ACPI_TYPE_PACKAGE;
54921308Sache
55021308Sache        /* Find end of package (closing bracket) */
55121308Sache
55221308Sache        while (*String)
55321308Sache        {
55421308Sache            /* Handle String package elements */
55575406Sache
55621308Sache            if (*String == '"')
55721308Sache            {
55821308Sache                /* Find end of string */
559119610Sache
56021308Sache                String++;
56121308Sache                while (*String && (*String != '"'))
56221308Sache                {
56321308Sache                    String++;
56421308Sache                }
56521308Sache                if (!(*String))
56621308Sache                {
56775406Sache                    break;
56821308Sache                }
56921308Sache            }
57021308Sache            else if (*String == '[')
57121308Sache            {
57221308Sache                Depth++;         /* A nested package declaration */
57321308Sache            }
57421308Sache            else if (*String == ']')
57521308Sache            {
57621308Sache                Depth--;
57721308Sache                if (Depth == 0) /* Found final package closing bracket */
57821308Sache                {
57926497Sache                    break;
58075406Sache                }
58121308Sache            }
58275406Sache
58326497Sache            String++;
58421308Sache        }
58521308Sache        break;
58621308Sache
58721308Sache    default:
58875406Sache
58921308Sache        Start = String;
59021308Sache
591119610Sache        /* Find end of token */
592119610Sache
593119610Sache        while (*String && (*String != ' '))
594119610Sache        {
595119610Sache            String++;
596119610Sache        }
597119610Sache        break;
598119610Sache    }
599119610Sache
600119610Sache    if (!(*String))
601119610Sache    {
602119610Sache        *Next = NULL;
603119610Sache    }
604119610Sache    else
605119610Sache    {
606119610Sache        *String = 0;
607119610Sache        *Next = String + 1;
60821308Sache    }
60921308Sache
61021308Sache    *ReturnType = Type;
61121308Sache    return (Start);
61221308Sache}
61321308Sache
61421308Sache
61521308Sache/*******************************************************************************
61675406Sache *
61721308Sache * FUNCTION:    AcpiDbGetLine
618119610Sache *
619119610Sache * PARAMETERS:  InputBuffer         - Command line buffer
620119610Sache *
621119610Sache * RETURN:      Count of arguments to the command
622119610Sache *
623119610Sache * DESCRIPTION: Get the next command line from the user. Gets entire line
624119610Sache *              up to the next newline
625119610Sache *
626119610Sache ******************************************************************************/
627119610Sache
628119610Sachestatic UINT32
629119610SacheAcpiDbGetLine (
63021308Sache    char                    *InputBuffer)
63175406Sache{
63275406Sache    UINT32                  i;
63375406Sache    UINT32                  Count;
63475406Sache    char                    *Next;
63521308Sache    char                    *This;
63675406Sache
63775406Sache
63875406Sache    ACPI_STRCPY (AcpiGbl_DbParsedBuf, InputBuffer);
63975406Sache
640119610Sache    This = AcpiGbl_DbParsedBuf;
641119610Sache    for (i = 0; i < ACPI_DEBUGGER_MAX_ARGS; i++)
642119610Sache    {
643119610Sache        AcpiGbl_DbArgs[i] = AcpiDbGetNextToken (This, &Next,
644119610Sache            &AcpiGbl_DbArgTypes[i]);
645119610Sache        if (!AcpiGbl_DbArgs[i])
646119610Sache        {
647119610Sache            break;
648119610Sache        }
649119610Sache
650119610Sache        This = Next;
651119610Sache    }
652119610Sache
653119610Sache    /* Uppercase the actual command */
654136644Sache
655136644Sache    if (AcpiGbl_DbArgs[0])
656136644Sache    {
657136644Sache        AcpiUtStrupr (AcpiGbl_DbArgs[0]);
658136644Sache    }
659136644Sache
660136644Sache    Count = i;
661136644Sache    if (Count)
662136644Sache    {
663136644Sache        Count--;  /* Number of args only */
664136644Sache    }
665136644Sache
666136644Sache    return (Count);
667136644Sache}
668136644Sache
669119610Sache
670119610Sache/*******************************************************************************
671119610Sache *
672119610Sache * FUNCTION:    AcpiDbMatchCommand
673119610Sache *
674119610Sache * PARAMETERS:  UserCommand             - User command line
675119610Sache *
676119610Sache * RETURN:      Index into command array, -1 if not found
677119610Sache *
678119610Sache * DESCRIPTION: Search command array for a command match
679119610Sache *
680119610Sache ******************************************************************************/
681119610Sache
682119610Sachestatic UINT32
68321308SacheAcpiDbMatchCommand (
68421308Sache    char                    *UserCommand)
68521308Sache{
68621308Sache    UINT32                  i;
68721308Sache
68821308Sache
68921308Sache    if (!UserCommand || UserCommand[0] == 0)
69021308Sache    {
69121308Sache        return (CMD_NULL);
69275406Sache    }
69321308Sache
69421308Sache    for (i = CMD_FIRST_VALID; AcpiGbl_DbCommands[i].Name; i++)
69521308Sache    {
69621308Sache        if (ACPI_STRSTR (AcpiGbl_DbCommands[i].Name, UserCommand) ==
69721308Sache                         AcpiGbl_DbCommands[i].Name)
69821308Sache        {
69921308Sache            return (i);
70021308Sache        }
70121308Sache    }
702125759Sache
70321308Sache    /* Command not recognized */
70421308Sache
70521308Sache    return (CMD_NOT_FOUND);
70621308Sache}
70721308Sache
70821308Sache
70921308Sache/*******************************************************************************
71021308Sache *
71121308Sache * FUNCTION:    AcpiDbCommandDispatch
71221308Sache *
71321308Sache * PARAMETERS:  InputBuffer         - Command line buffer
71421308Sache *              WalkState           - Current walk
71526497Sache *              Op                  - Current (executing) parse op
71621308Sache *
71721308Sache * RETURN:      Status
71821308Sache *
71921308Sache * DESCRIPTION: Command dispatcher.
72021308Sache *
72121308Sache ******************************************************************************/
72221308Sache
72375406SacheACPI_STATUS
72421308SacheAcpiDbCommandDispatch (
72575406Sache    char                    *InputBuffer,
72621308Sache    ACPI_WALK_STATE         *WalkState,
72775406Sache    ACPI_PARSE_OBJECT       *Op)
72821308Sache{
72921308Sache    UINT32                  Temp;
73021308Sache    UINT32                  CommandIndex;
73126497Sache    UINT32                  ParamCount;
73221308Sache    char                    *CommandLine;
73321308Sache    ACPI_STATUS             Status = AE_CTRL_TRUE;
73421308Sache
73575406Sache
73621308Sache    /* If AcpiTerminate has been called, terminate this thread */
73721308Sache
738119610Sache    if (AcpiGbl_DbTerminateThreads)
73921308Sache    {
74021308Sache        return (AE_CTRL_TERMINATE);
74121308Sache    }
74221308Sache
74321308Sache    ParamCount = AcpiDbGetLine (InputBuffer);
74475406Sache    CommandIndex = AcpiDbMatchCommand (AcpiGbl_DbArgs[0]);
74521308Sache    Temp = 0;
74621308Sache
74721308Sache    /* Verify that we have the minimum number of params */
74821308Sache
74921308Sache    if (ParamCount < AcpiGbl_DbCommands[CommandIndex].MinArgs)
75021308Sache    {
75121308Sache        AcpiOsPrintf ("%u parameters entered, [%s] requires %u parameters\n",
75221308Sache            ParamCount, AcpiGbl_DbCommands[CommandIndex].Name,
75321308Sache            AcpiGbl_DbCommands[CommandIndex].MinArgs);
754119610Sache
755119610Sache        AcpiDbDisplayCommandInfo (AcpiGbl_DbCommands[CommandIndex].Name, FALSE);
756119610Sache        return (AE_CTRL_TRUE);
75721308Sache    }
75821308Sache
75921308Sache    /* Decode and dispatch the command */
76058310Sache
76126497Sache    switch (CommandIndex)
76226497Sache    {
76326497Sache    case CMD_NULL:
76426497Sache
76526497Sache        if (Op)
76626497Sache        {
76726497Sache            return (AE_OK);
76826497Sache        }
76926497Sache        break;
77026497Sache
77126497Sache    case CMD_ALLOCATIONS:
77226497Sache
77326497Sache#ifdef ACPI_DBG_TRACK_ALLOCATIONS
77426497Sache        AcpiUtDumpAllocations ((UINT32) -1, NULL);
77526497Sache#endif
77626497Sache        break;
77726497Sache
77826497Sache    case CMD_ARGS:
77926497Sache    case CMD_ARGUMENTS:
78026497Sache
78126497Sache        AcpiDbDisplayArguments ();
78226497Sache        break;
78326497Sache
78458310Sache    case CMD_BATCH:
78526497Sache
78621308Sache        AcpiDbBatchExecute (AcpiGbl_DbArgs[1]);
78721308Sache        break;
78821308Sache
78921308Sache    case CMD_BREAKPOINT:
79058310Sache
79126497Sache        AcpiDbSetMethodBreakpoint (AcpiGbl_DbArgs[1], WalkState, Op);
79226497Sache        break;
79326497Sache
79426497Sache    case CMD_BUSINFO:
79558310Sache
79626497Sache        AcpiDbGetBusInfo ();
79775406Sache        break;
79875406Sache
79975406Sache    case CMD_CALL:
80075406Sache
80121308Sache        AcpiDbSetMethodCallBreakpoint (Op);
80221308Sache        Status = AE_OK;
80321308Sache        break;
80421308Sache
80521308Sache    case CMD_CLOSE:
80621308Sache
80721308Sache        AcpiDbCloseDebugFile ();
80821308Sache        break;
80921308Sache
81021308Sache    case CMD_DEBUG:
81121308Sache
81221308Sache        AcpiDbExecute (AcpiGbl_DbArgs[1],
81321308Sache            &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_SINGLE_STEP);
81421308Sache        break;
81521308Sache
81626497Sache    case CMD_DISASSEMBLE:
817119610Sache    case CMD_DISASM:
81821308Sache
81921308Sache        (void) AcpiDbDisassembleMethod (AcpiGbl_DbArgs[1]);
82075406Sache        break;
82175406Sache
82275406Sache    case CMD_DUMP:
82321308Sache
82421308Sache        AcpiDbDecodeAndDisplayObject (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
82521308Sache        break;
82621308Sache
82721308Sache    case CMD_ENABLEACPI:
82821308Sache#if (!ACPI_REDUCED_HARDWARE)
82921308Sache
83021308Sache        Status = AcpiEnable();
83121308Sache        if (ACPI_FAILURE(Status))
83221308Sache        {
83321308Sache            AcpiOsPrintf("AcpiEnable failed (Status=%X)\n", Status);
83421308Sache            return (Status);
83521308Sache        }
83621308Sache#endif /* !ACPI_REDUCED_HARDWARE */
83721308Sache        break;
83821308Sache
83975406Sache    case CMD_EVENT:
84075406Sache
84121308Sache        AcpiOsPrintf ("Event command not implemented\n");
84221308Sache        break;
84321308Sache
84421308Sache    case CMD_EVALUATE:
84521308Sache    case CMD_EXECUTE:
84621308Sache
84721308Sache        AcpiDbExecute (AcpiGbl_DbArgs[1],
84821308Sache            &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_NO_SINGLE_STEP);
84921308Sache        break;
85021308Sache
85121308Sache    case CMD_FIND:
85221308Sache
85321308Sache        Status = AcpiDbFindNameInNamespace (AcpiGbl_DbArgs[1]);
85421308Sache        break;
85521308Sache
85621308Sache    case CMD_GO:
857136644Sache
85821308Sache        AcpiGbl_CmSingleStep = FALSE;
85921308Sache        return (AE_OK);
86021308Sache
86121308Sache    case CMD_GPE:
86221308Sache
86321308Sache        AcpiDbGenerateGpe (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
86421308Sache        break;
86521308Sache
86675406Sache    case CMD_GPES:
86721308Sache
86821308Sache        AcpiDbDisplayGpes ();
869136644Sache        break;
870136644Sache
871136644Sache    case CMD_HANDLERS:
872136644Sache
873136644Sache        AcpiDbDisplayHandlers ();
874136644Sache        break;
875136644Sache
876136644Sache    case CMD_HELP:
877136644Sache    case CMD_HELP2:
878119610Sache
87921308Sache        AcpiDbDisplayHelp (AcpiGbl_DbArgs[1]);
880119610Sache        break;
881119610Sache
88221308Sache    case CMD_HISTORY:
883119610Sache
88421308Sache        AcpiDbDisplayHistory ();
885119610Sache        break;
886119610Sache
887119610Sache    case CMD_HISTORY_EXE: /* ! command */
88858310Sache
889136644Sache        CommandLine = AcpiDbGetFromHistory (AcpiGbl_DbArgs[1]);
890136644Sache        if (!CommandLine)
891136644Sache        {
892136644Sache            return (AE_CTRL_TRUE);
89358310Sache        }
89421308Sache
895136644Sache        Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
896136644Sache        return (Status);
897136644Sache
898136644Sache    case CMD_HISTORY_LAST: /* !! command */
899136644Sache
900136644Sache        CommandLine = AcpiDbGetFromHistory (NULL);
901119610Sache        if (!CommandLine)
902136644Sache        {
903136644Sache            return (AE_CTRL_TRUE);
904136644Sache        }
905136644Sache
906136644Sache        Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
907136644Sache        return (Status);
908119610Sache
909119610Sache    case CMD_INFORMATION:
91021308Sache
91121308Sache        AcpiDbDisplayMethodInfo (Op);
912119610Sache        break;
91321308Sache
91421308Sache    case CMD_INTEGRITY:
91521308Sache
91621308Sache        AcpiDbCheckIntegrity ();
91721308Sache        break;
918119610Sache
91921308Sache    case CMD_INTO:
92021308Sache
921119610Sache        if (Op)
922119610Sache        {
92321308Sache            AcpiGbl_CmSingleStep = TRUE;
92421308Sache            return (AE_OK);
92521308Sache        }
92621308Sache        break;
92721308Sache
928119610Sache    case CMD_LEVEL:
92921308Sache
93021308Sache        if (ParamCount == 0)
93121308Sache        {
93221308Sache            AcpiOsPrintf ("Current debug level for file output is:    %8.8lX\n",
933119610Sache                AcpiGbl_DbDebugLevel);
934119610Sache            AcpiOsPrintf ("Current debug level for console output is: %8.8lX\n",
93521308Sache                AcpiGbl_DbConsoleDebugLevel);
936119610Sache        }
937119610Sache        else if (ParamCount == 2)
93821308Sache        {
939119610Sache            Temp = AcpiGbl_DbConsoleDebugLevel;
940119610Sache            AcpiGbl_DbConsoleDebugLevel = ACPI_STRTOUL (AcpiGbl_DbArgs[1],
941119610Sache                                            NULL, 16);
942119610Sache            AcpiOsPrintf (
943119610Sache                "Debug Level for console output was %8.8lX, now %8.8lX\n",
944119610Sache                Temp, AcpiGbl_DbConsoleDebugLevel);
945119610Sache        }
94621308Sache        else
947119610Sache        {
948119610Sache            Temp = AcpiGbl_DbDebugLevel;
949119610Sache            AcpiGbl_DbDebugLevel = ACPI_STRTOUL (AcpiGbl_DbArgs[1], NULL, 16);
95021308Sache            AcpiOsPrintf (
951119610Sache                "Debug Level for file output was %8.8lX, now %8.8lX\n",
952119610Sache                Temp, AcpiGbl_DbDebugLevel);
953119610Sache        }
954119610Sache        break;
955119610Sache
956119610Sache    case CMD_LIST:
957119610Sache
958119610Sache        AcpiDbDisassembleAml (AcpiGbl_DbArgs[1], Op);
95921308Sache        break;
960119610Sache
961119610Sache    case CMD_LOAD:
96221308Sache
96321308Sache        Status = AcpiDbGetTableFromFile (AcpiGbl_DbArgs[1], NULL);
96421308Sache        break;
96521308Sache
96621308Sache    case CMD_LOCKS:
967119610Sache
968119610Sache        AcpiDbDisplayLocks ();
96921308Sache        break;
970119610Sache
971119610Sache    case CMD_LOCALS:
97221308Sache
973119610Sache        AcpiDbDisplayLocals ();
974119610Sache        break;
975119610Sache
976119610Sache    case CMD_METHODS:
977119610Sache
978119610Sache        Status = AcpiDbDisplayObjects ("METHOD", AcpiGbl_DbArgs[1]);
979119610Sache        break;
98021308Sache
981119610Sache    case CMD_NAMESPACE:
982119610Sache
983119610Sache        AcpiDbDumpNamespace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
98421308Sache        break;
985119610Sache
986119610Sache    case CMD_NOTIFY:
987119610Sache
988119610Sache        Temp = ACPI_STRTOUL (AcpiGbl_DbArgs[2], NULL, 0);
989119610Sache        AcpiDbSendNotify (AcpiGbl_DbArgs[1], Temp);
990119610Sache        break;
991119610Sache
992119610Sache    case CMD_OBJECT:
99321308Sache
994119610Sache        AcpiUtStrupr (AcpiGbl_DbArgs[1]);
995119610Sache        Status = AcpiDbDisplayObjects (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
99621308Sache        break;
99721308Sache
99821308Sache    case CMD_OPEN:
999
1000        AcpiDbOpenDebugFile (AcpiGbl_DbArgs[1]);
1001        break;
1002
1003    case CMD_OSI:
1004
1005        AcpiDbDisplayInterfaces (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1006        break;
1007
1008    case CMD_OWNER:
1009
1010        AcpiDbDumpNamespaceByOwner (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1011        break;
1012
1013    case CMD_PATHS:
1014
1015        AcpiDbDumpNamespacePaths ();
1016        break;
1017
1018    case CMD_PREDEFINED:
1019
1020        AcpiDbCheckPredefinedNames ();
1021        break;
1022
1023    case CMD_PREFIX:
1024
1025        AcpiDbSetScope (AcpiGbl_DbArgs[1]);
1026        break;
1027
1028    case CMD_REFERENCES:
1029
1030        AcpiDbFindReferences (AcpiGbl_DbArgs[1]);
1031        break;
1032
1033    case CMD_RESOURCES:
1034
1035        AcpiDbDisplayResources (AcpiGbl_DbArgs[1]);
1036        break;
1037
1038    case CMD_RESULTS:
1039
1040        AcpiDbDisplayResults ();
1041        break;
1042
1043    case CMD_SCI:
1044
1045        AcpiDbGenerateSci ();
1046        break;
1047
1048    case CMD_SET:
1049
1050        AcpiDbSetMethodData (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],
1051            AcpiGbl_DbArgs[3]);
1052        break;
1053
1054    case CMD_SLEEP:
1055
1056        Status = AcpiDbSleep (AcpiGbl_DbArgs[1]);
1057        break;
1058
1059    case CMD_STATS:
1060
1061        Status = AcpiDbDisplayStatistics (AcpiGbl_DbArgs[1]);
1062        break;
1063
1064    case CMD_STOP:
1065
1066        return (AE_NOT_IMPLEMENTED);
1067
1068    case CMD_TABLES:
1069
1070        AcpiDbDisplayTableInfo (AcpiGbl_DbArgs[1]);
1071        break;
1072
1073    case CMD_TEMPLATE:
1074
1075        AcpiDbDisplayTemplate (AcpiGbl_DbArgs[1]);
1076        break;
1077
1078    case CMD_TERMINATE:
1079
1080        AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
1081        AcpiUtSubsystemShutdown ();
1082
1083        /*
1084         * TBD: [Restructure] Need some way to re-initialize without
1085         * re-creating the semaphores!
1086         */
1087
1088        /*  AcpiInitialize (NULL);  */
1089        break;
1090
1091    case CMD_THREADS:
1092
1093        AcpiDbCreateExecutionThreads (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],
1094            AcpiGbl_DbArgs[3]);
1095        break;
1096
1097    case CMD_TRACE:
1098
1099        (void) AcpiDebugTrace (AcpiGbl_DbArgs[1],0,0,1);
1100        break;
1101
1102    case CMD_TREE:
1103
1104        AcpiDbDisplayCallingTree ();
1105        break;
1106
1107    case CMD_TYPE:
1108
1109        AcpiDbDisplayObjectType (AcpiGbl_DbArgs[1]);
1110        break;
1111
1112    case CMD_UNLOAD:
1113
1114        AcpiDbUnloadAcpiTable (AcpiGbl_DbArgs[1]);
1115        break;
1116
1117    case CMD_EXIT:
1118    case CMD_QUIT:
1119
1120        if (Op)
1121        {
1122            AcpiOsPrintf ("Method execution terminated\n");
1123            return (AE_CTRL_TERMINATE);
1124        }
1125
1126        if (!AcpiGbl_DbOutputToFile)
1127        {
1128            AcpiDbgLevel = ACPI_DEBUG_DEFAULT;
1129        }
1130
1131        AcpiDbCloseDebugFile ();
1132        AcpiGbl_DbTerminateThreads = TRUE;
1133        return (AE_CTRL_TERMINATE);
1134
1135    case CMD_NOT_FOUND:
1136    default:
1137
1138        AcpiOsPrintf ("Unknown Command\n");
1139        return (AE_CTRL_TRUE);
1140    }
1141
1142    if (ACPI_SUCCESS (Status))
1143    {
1144        Status = AE_CTRL_TRUE;
1145    }
1146
1147    /* Add all commands that come here to the history buffer */
1148
1149    AcpiDbAddToHistory (InputBuffer);
1150    return (Status);
1151}
1152
1153
1154/*******************************************************************************
1155 *
1156 * FUNCTION:    AcpiDbExecuteThread
1157 *
1158 * PARAMETERS:  Context         - Not used
1159 *
1160 * RETURN:      None
1161 *
1162 * DESCRIPTION: Debugger execute thread. Waits for a command line, then
1163 *              simply dispatches it.
1164 *
1165 ******************************************************************************/
1166
1167void ACPI_SYSTEM_XFACE
1168AcpiDbExecuteThread (
1169    void                    *Context)
1170{
1171    ACPI_STATUS             Status = AE_OK;
1172    ACPI_STATUS             MStatus;
1173
1174
1175    while (Status != AE_CTRL_TERMINATE)
1176    {
1177        AcpiGbl_MethodExecuting = FALSE;
1178        AcpiGbl_StepToNextCall = FALSE;
1179
1180        MStatus = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY);
1181        if (ACPI_FAILURE (MStatus))
1182        {
1183            return;
1184        }
1185
1186        Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
1187
1188        MStatus = AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
1189        if (ACPI_FAILURE (MStatus))
1190        {
1191            return;
1192        }
1193    }
1194}
1195
1196
1197/*******************************************************************************
1198 *
1199 * FUNCTION:    AcpiDbSingleThread
1200 *
1201 * PARAMETERS:  None
1202 *
1203 * RETURN:      None
1204 *
1205 * DESCRIPTION: Debugger execute thread. Waits for a command line, then
1206 *              simply dispatches it.
1207 *
1208 ******************************************************************************/
1209
1210static void
1211AcpiDbSingleThread (
1212    void)
1213{
1214
1215    AcpiGbl_MethodExecuting = FALSE;
1216    AcpiGbl_StepToNextCall = FALSE;
1217
1218    (void) AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
1219}
1220
1221
1222/*******************************************************************************
1223 *
1224 * FUNCTION:    AcpiDbUserCommands
1225 *
1226 * PARAMETERS:  Prompt              - User prompt (depends on mode)
1227 *              Op                  - Current executing parse op
1228 *
1229 * RETURN:      None
1230 *
1231 * DESCRIPTION: Command line execution for the AML debugger. Commands are
1232 *              matched and dispatched here.
1233 *
1234 ******************************************************************************/
1235
1236ACPI_STATUS
1237AcpiDbUserCommands (
1238    char                    Prompt,
1239    ACPI_PARSE_OBJECT       *Op)
1240{
1241    ACPI_STATUS             Status = AE_OK;
1242
1243
1244    AcpiOsPrintf ("\n");
1245
1246    /* TBD: [Restructure] Need a separate command line buffer for step mode */
1247
1248    while (!AcpiGbl_DbTerminateThreads)
1249    {
1250        /* Force output to console until a command is entered */
1251
1252        AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
1253
1254        /* Different prompt if method is executing */
1255
1256        if (!AcpiGbl_MethodExecuting)
1257        {
1258            AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
1259        }
1260        else
1261        {
1262            AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
1263        }
1264
1265        /* Get the user input line */
1266
1267        Status = AcpiOsGetLine (AcpiGbl_DbLineBuf,
1268            ACPI_DB_LINE_BUFFER_SIZE, NULL);
1269        if (ACPI_FAILURE (Status))
1270        {
1271            ACPI_EXCEPTION ((AE_INFO, Status, "While parsing command line"));
1272            return (Status);
1273        }
1274
1275        /* Check for single or multithreaded debug */
1276
1277        if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
1278        {
1279            /*
1280             * Signal the debug thread that we have a command to execute,
1281             * and wait for the command to complete.
1282             */
1283            Status = AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_READY);
1284            if (ACPI_FAILURE (Status))
1285            {
1286                return (Status);
1287            }
1288
1289            Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
1290            if (ACPI_FAILURE (Status))
1291            {
1292                return (Status);
1293            }
1294        }
1295        else
1296        {
1297            /* Just call to the command line interpreter */
1298
1299            AcpiDbSingleThread ();
1300        }
1301    }
1302
1303    /*
1304     * Only this thread (the original thread) should actually terminate the
1305     * subsystem, because all the semaphores are deleted during termination
1306     */
1307    Status = AcpiTerminate ();
1308    return (Status);
1309}
1310
1311#endif  /* ACPI_DEBUGGER */
1312