Home | History | Annotate | Line # | Download | only in debugger
dbinput.c revision 1.23
      1 /*******************************************************************************
      2  *
      3  * Module Name: dbinput - user front-end to the AML debugger
      4  *
      5  ******************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2020, Intel Corp.
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions, and the following disclaimer,
     16  *    without modification.
     17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  *    including a substantially similar Disclaimer requirement for further
     21  *    binary redistribution.
     22  * 3. Neither the names of the above-listed copyright holders nor the names
     23  *    of any contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * Alternatively, this software may be distributed under the terms of the
     27  * GNU General Public License ("GPL") version 2 as published by the Free
     28  * Software Foundation.
     29  *
     30  * NO WARRANTY
     31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  * POSSIBILITY OF SUCH DAMAGES.
     42  */
     43 
     44 #include "acpi.h"
     45 #include "accommon.h"
     46 #include "acdebug.h"
     47 
     48 #ifdef ACPI_APPLICATION
     49 #include "acapps.h"
     50 #endif
     51 
     52 #define _COMPONENT          ACPI_CA_DEBUGGER
     53         ACPI_MODULE_NAME    ("dbinput")
     54 
     55 
     56 /* Local prototypes */
     57 
     58 static UINT32
     59 AcpiDbGetLine (
     60     char                    *InputBuffer);
     61 
     62 static UINT32
     63 AcpiDbMatchCommand (
     64     char                    *UserCommand);
     65 
     66 static void
     67 AcpiDbDisplayCommandInfo (
     68     const char              *Command,
     69     BOOLEAN                 DisplayAll);
     70 
     71 static void
     72 AcpiDbDisplayHelp (
     73     char                    *Command);
     74 
     75 static BOOLEAN
     76 AcpiDbMatchCommandHelp (
     77     const char                  *Command,
     78     const ACPI_DB_COMMAND_HELP  *Help);
     79 
     80 
     81 /*
     82  * Top-level debugger commands.
     83  *
     84  * This list of commands must match the string table below it
     85  */
     86 enum AcpiExDebuggerCommands
     87 {
     88     CMD_NOT_FOUND = 0,
     89     CMD_NULL,
     90     CMD_ALL,
     91     CMD_ALLOCATIONS,
     92     CMD_ARGS,
     93     CMD_ARGUMENTS,
     94     CMD_BREAKPOINT,
     95     CMD_BUSINFO,
     96     CMD_CALL,
     97     CMD_DEBUG,
     98     CMD_DISASSEMBLE,
     99     CMD_DISASM,
    100     CMD_DUMP,
    101     CMD_EVALUATE,
    102     CMD_EXECUTE,
    103     CMD_EXIT,
    104     CMD_FIELDS,
    105     CMD_FIND,
    106     CMD_GO,
    107     CMD_HANDLERS,
    108     CMD_HELP,
    109     CMD_HELP2,
    110     CMD_HISTORY,
    111     CMD_HISTORY_EXE,
    112     CMD_HISTORY_LAST,
    113     CMD_INFORMATION,
    114     CMD_INTEGRITY,
    115     CMD_INTO,
    116     CMD_LEVEL,
    117     CMD_LIST,
    118     CMD_LOCALS,
    119     CMD_LOCKS,
    120     CMD_METHODS,
    121     CMD_NAMESPACE,
    122     CMD_NOTIFY,
    123     CMD_OBJECTS,
    124     CMD_OSI,
    125     CMD_OWNER,
    126     CMD_PATHS,
    127     CMD_PREDEFINED,
    128     CMD_PREFIX,
    129     CMD_QUIT,
    130     CMD_REFERENCES,
    131     CMD_RESOURCES,
    132     CMD_RESULTS,
    133     CMD_SET,
    134     CMD_STATS,
    135     CMD_STOP,
    136     CMD_TABLES,
    137     CMD_TEMPLATE,
    138     CMD_TRACE,
    139     CMD_TREE,
    140     CMD_TYPE,
    141 #ifdef ACPI_APPLICATION
    142     CMD_ENABLEACPI,
    143     CMD_EVENT,
    144     CMD_GPE,
    145     CMD_GPES,
    146     CMD_SCI,
    147     CMD_SLEEP,
    148 
    149     CMD_CLOSE,
    150     CMD_LOAD,
    151     CMD_OPEN,
    152     CMD_UNLOAD,
    153 
    154     CMD_TERMINATE,
    155     CMD_BACKGROUND,
    156     CMD_THREADS,
    157 
    158     CMD_TEST,
    159 #endif
    160 };
    161 
    162 #define CMD_FIRST_VALID     2
    163 
    164 
    165 /* Second parameter is the required argument count */
    166 
    167 static const ACPI_DB_COMMAND_INFO   AcpiGbl_DbCommands[] =
    168 {
    169     {"<NOT FOUND>",  0},
    170     {"<NULL>",       0},
    171     {"ALL",          1},
    172     {"ALLOCATIONS",  0},
    173     {"ARGS",         0},
    174     {"ARGUMENTS",    0},
    175     {"BREAKPOINT",   1},
    176     {"BUSINFO",      0},
    177     {"CALL",         0},
    178     {"DEBUG",        1},
    179     {"DISASSEMBLE",  1},
    180     {"DISASM",       1},
    181     {"DUMP",         1},
    182     {"EVALUATE",     1},
    183     {"EXECUTE",      1},
    184     {"EXIT",         0},
    185     {"FIELDS",       1},
    186     {"FIND",         1},
    187     {"GO",           0},
    188     {"HANDLERS",     0},
    189     {"HELP",         0},
    190     {"?",            0},
    191     {"HISTORY",      0},
    192     {"!",            1},
    193     {"!!",           0},
    194     {"INFORMATION",  0},
    195     {"INTEGRITY",    0},
    196     {"INTO",         0},
    197     {"LEVEL",        0},
    198     {"LIST",         0},
    199     {"LOCALS",       0},
    200     {"LOCKS",        0},
    201     {"METHODS",      0},
    202     {"NAMESPACE",    0},
    203     {"NOTIFY",       2},
    204     {"OBJECTS",      0},
    205     {"OSI",          0},
    206     {"OWNER",        1},
    207     {"PATHS",        0},
    208     {"PREDEFINED",   0},
    209     {"PREFIX",       0},
    210     {"QUIT",         0},
    211     {"REFERENCES",   1},
    212     {"RESOURCES",    0},
    213     {"RESULTS",      0},
    214     {"SET",          3},
    215     {"STATS",        1},
    216     {"STOP",         0},
    217     {"TABLES",       0},
    218     {"TEMPLATE",     1},
    219     {"TRACE",        1},
    220     {"TREE",         0},
    221     {"TYPE",         1},
    222 #ifdef ACPI_APPLICATION
    223     {"ENABLEACPI",   0},
    224     {"EVENT",        1},
    225     {"GPE",          1},
    226     {"GPES",         0},
    227     {"SCI",          0},
    228     {"SLEEP",        0},
    229 
    230     {"CLOSE",        0},
    231     {"LOAD",         1},
    232     {"OPEN",         1},
    233     {"UNLOAD",       1},
    234 
    235     {"TERMINATE",    0},
    236     {"BACKGROUND",   1},
    237     {"THREADS",      3},
    238 
    239     {"TEST",         1},
    240 #endif
    241     {NULL,           0}
    242 };
    243 
    244 /*
    245  * Help for all debugger commands. First argument is the number of lines
    246  * of help to output for the command.
    247  *
    248  * Note: Some commands are not supported by the kernel-level version of
    249  * the debugger.
    250  */
    251 static const ACPI_DB_COMMAND_HELP   AcpiGbl_DbCommandHelp[] =
    252 {
    253     {0, "\nNamespace Access:",                  "\n"},
    254     {1, "  Businfo",                            "Display system bus info\n"},
    255     {1, "  Disassemble <Method>",               "Disassemble a control method\n"},
    256     {1, "  Find <AcpiName> (? is wildcard)",    "Find ACPI name(s) with wildcards\n"},
    257     {1, "  Integrity",                          "Validate namespace integrity\n"},
    258     {1, "  Methods",                            "Display list of loaded control methods\n"},
    259     {1, "  Fields <AddressSpaceId>",            "Display list of loaded field units by space ID\n"},
    260     {1, "  Namespace [Object] [Depth]",         "Display loaded namespace tree/subtree\n"},
    261     {1, "  Notify <Object> <Value>",            "Send a notification on Object\n"},
    262     {1, "  Objects [ObjectType]",               "Display summary of all objects or just given type\n"},
    263     {1, "  Owner <OwnerId> [Depth]",            "Display loaded namespace by object owner\n"},
    264     {1, "  Paths",                              "Display full pathnames of namespace objects\n"},
    265     {1, "  Predefined",                         "Check all predefined names\n"},
    266     {1, "  Prefix [<Namepath>]",                "Set or Get current execution prefix\n"},
    267     {1, "  References <Addr>",                  "Find all references to object at addr\n"},
    268     {1, "  Resources [DeviceName]",             "Display Device resources (no arg = all devices)\n"},
    269     {1, "  Set N <NamedObject> <Value>",        "Set value for named integer\n"},
    270     {1, "  Template <Object>",                  "Format/dump a Buffer/ResourceTemplate\n"},
    271     {1, "  Type <Object>",                      "Display object type\n"},
    272 
    273     {0, "\nControl Method Execution:",          "\n"},
    274     {1, "  All <NameSeg>",                      "Evaluate all objects named NameSeg\n"},
    275     {1, "  Evaluate <Namepath> [Arguments]",    "Evaluate object or control method\n"},
    276     {1, "  Execute <Namepath> [Arguments]",     "Synonym for Evaluate\n"},
    277 #ifdef ACPI_APPLICATION
    278     {1, "  Background <Namepath> [Arguments]",  "Evaluate object/method in a separate thread\n"},
    279     {1, "  Thread <Threads><Loops><NamePath>",  "Spawn threads to execute method(s)\n"},
    280 #endif
    281     {1, "  Debug <Namepath> [Arguments]",       "Single-Step a control method\n"},
    282     {7, "  [Arguments] formats:",               "Control method argument formats\n"},
    283     {1, "     Hex Integer",                     "Integer\n"},
    284     {1, "     \"Ascii String\"",                "String\n"},
    285     {1, "     (Hex Byte List)",                 "Buffer\n"},
    286     {1, "         (01 42 7A BF)",               "Buffer example (4 bytes)\n"},
    287     {1, "     [Package Element List]",          "Package\n"},
    288     {1, "         [0x01 0x1234 \"string\"]",    "Package example (3 elements)\n"},
    289 
    290     {0, "\nMiscellaneous:",                     "\n"},
    291     {1, "  Allocations",                        "Display list of current memory allocations\n"},
    292     {2, "  Dump <Address>|<Namepath>",          "\n"},
    293     {0, "       [Byte|Word|Dword|Qword]",       "Display ACPI objects or memory\n"},
    294     {1, "  Handlers",                           "Info about global handlers\n"},
    295     {1, "  Help [Command]",                     "This help screen or individual command\n"},
    296     {1, "  History",                            "Display command history buffer\n"},
    297     {1, "  Level <DebugLevel>] [console]",      "Get/Set debug level for file or console\n"},
    298     {1, "  Locks",                              "Current status of internal mutexes\n"},
    299     {1, "  Osi [Install|Remove <name>]",        "Display or modify global _OSI list\n"},
    300     {1, "  Quit or Exit",                       "Exit this command\n"},
    301     {8, "  Stats <SubCommand>",                 "Display namespace and memory statistics\n"},
    302     {1, "     Allocations",                     "Display list of current memory allocations\n"},
    303     {1, "     Memory",                          "Dump internal memory lists\n"},
    304     {1, "     Misc",                            "Namespace search and mutex stats\n"},
    305     {1, "     Objects",                         "Summary of namespace objects\n"},
    306     {1, "     Sizes",                           "Sizes for each of the internal objects\n"},
    307     {1, "     Stack",                           "Display CPU stack usage\n"},
    308     {1, "     Tables",                          "Info about current ACPI table(s)\n"},
    309     {1, "  Tables",                             "Display info about loaded ACPI tables\n"},
    310 #ifdef ACPI_APPLICATION
    311     {1, "  Terminate",                          "Delete namespace and all internal objects\n"},
    312 #endif
    313     {1, "  ! <CommandNumber>",                  "Execute command from history buffer\n"},
    314     {1, "  !!",                                 "Execute last command again\n"},
    315 
    316     {0, "\nMethod and Namespace Debugging:",    "\n"},
    317     {5, "  Trace <State> [<Namepath>] [Once]",  "Trace control method execution\n"},
    318     {1, "     Enable",                          "Enable all messages\n"},
    319     {1, "     Disable",                         "Disable tracing\n"},
    320     {1, "     Method",                          "Enable method execution messages\n"},
    321     {1, "     Opcode",                          "Enable opcode execution messages\n"},
    322     {3, "  Test <TestName>",                    "Invoke a debug test\n"},
    323     {1, "     Objects",                         "Read/write/compare all namespace data objects\n"},
    324     {1, "     Predefined",                      "Validate all ACPI predefined names (_STA, etc.)\n"},
    325     {1, "  Execute predefined",                 "Execute all predefined (public) methods\n"},
    326 
    327     {0, "\nControl Method Single-Step Execution:","\n"},
    328     {1, "  Arguments (or Args)",                "Display method arguments\n"},
    329     {1, "  Breakpoint <AmlOffset>",             "Set an AML execution breakpoint\n"},
    330     {1, "  Call",                               "Run to next control method invocation\n"},
    331     {1, "  Go",                                 "Allow method to run to completion\n"},
    332     {1, "  Information",                        "Display info about the current method\n"},
    333     {1, "  Into",                               "Step into (not over) a method call\n"},
    334     {1, "  List [# of Aml Opcodes]",            "Display method ASL statements\n"},
    335     {1, "  Locals",                             "Display method local variables\n"},
    336     {1, "  Results",                            "Display method result stack\n"},
    337     {1, "  Set <A|L> <#> <Value>",              "Set method data (Arguments/Locals)\n"},
    338     {1, "  Stop",                               "Terminate control method\n"},
    339     {1, "  Tree",                               "Display control method calling tree\n"},
    340     {1, "  <Enter>",                            "Single step next AML opcode (over calls)\n"},
    341 
    342 #ifdef ACPI_APPLICATION
    343     {0, "\nFile Operations:",                   "\n"},
    344     {1, "  Close",                              "Close debug output file\n"},
    345     {1, "  Load <Input Filename>",              "Load ACPI table from a file\n"},
    346     {1, "  Open <Output Filename>",             "Open a file for debug output\n"},
    347     {1, "  Unload <Namepath>",                  "Unload an ACPI table via namespace object\n"},
    348 
    349     {0, "\nHardware Simulation:",               "\n"},
    350     {1, "  EnableAcpi",                         "Enable ACPI (hardware) mode\n"},
    351     {1, "  Event <F|G> <Value>",                "Generate AcpiEvent (Fixed/GPE)\n"},
    352     {1, "  Gpe <GpeNum> [GpeBlockDevice]",      "Simulate a GPE\n"},
    353     {1, "  Gpes",                               "Display info on all GPE devices\n"},
    354     {1, "  Sci",                                "Generate an SCI\n"},
    355     {1, "  Sleep [SleepState]",                 "Simulate sleep/wake sequence(s) (0-5)\n"},
    356 #endif
    357     {0, NULL, NULL}
    358 };
    359 
    360 
    361 /*******************************************************************************
    362  *
    363  * FUNCTION:    AcpiDbMatchCommandHelp
    364  *
    365  * PARAMETERS:  Command             - Command string to match
    366  *              Help                - Help table entry to attempt match
    367  *
    368  * RETURN:      TRUE if command matched, FALSE otherwise
    369  *
    370  * DESCRIPTION: Attempt to match a command in the help table in order to
    371  *              print help information for a single command.
    372  *
    373  ******************************************************************************/
    374 
    375 static BOOLEAN
    376 AcpiDbMatchCommandHelp (
    377     const char                  *Command,
    378     const ACPI_DB_COMMAND_HELP  *Help)
    379 {
    380     const char              *Invocation = Help->Invocation;
    381     UINT32                  LineCount;
    382 
    383 
    384     /* Valid commands in the help table begin with a couple of spaces */
    385 
    386     if (*Invocation != ' ')
    387     {
    388         return (FALSE);
    389     }
    390 
    391     while (*Invocation == ' ')
    392     {
    393         Invocation++;
    394     }
    395 
    396     /* Match command name (full command or substring) */
    397 
    398     while ((*Command) && (*Invocation) && (*Invocation != ' '))
    399     {
    400         if (tolower ((int) *Command) != tolower ((int) *Invocation))
    401         {
    402             return (FALSE);
    403         }
    404 
    405         Invocation++;
    406         Command++;
    407     }
    408 
    409     /* Print the appropriate number of help lines */
    410 
    411     LineCount = Help->LineCount;
    412     while (LineCount)
    413     {
    414         AcpiOsPrintf ("%-38s : %s", Help->Invocation, Help->Description);
    415         Help++;
    416         LineCount--;
    417     }
    418 
    419     return (TRUE);
    420 }
    421 
    422 
    423 /*******************************************************************************
    424  *
    425  * FUNCTION:    AcpiDbDisplayCommandInfo
    426  *
    427  * PARAMETERS:  Command             - Command string to match
    428  *              DisplayAll          - Display all matching commands, or just
    429  *                                    the first one (substring match)
    430  *
    431  * RETURN:      None
    432  *
    433  * DESCRIPTION: Display help information for a Debugger command.
    434  *
    435  ******************************************************************************/
    436 
    437 static void
    438 AcpiDbDisplayCommandInfo (
    439     const char              *Command,
    440     BOOLEAN                 DisplayAll)
    441 {
    442     const ACPI_DB_COMMAND_HELP  *Next;
    443     BOOLEAN                     Matched;
    444 
    445 
    446     Next = AcpiGbl_DbCommandHelp;
    447     while (Next->Invocation)
    448     {
    449         Matched = AcpiDbMatchCommandHelp (Command, Next);
    450         if (!DisplayAll && Matched)
    451         {
    452             return;
    453         }
    454 
    455         Next++;
    456     }
    457 }
    458 
    459 
    460 /*******************************************************************************
    461  *
    462  * FUNCTION:    AcpiDbDisplayHelp
    463  *
    464  * PARAMETERS:  Command             - Optional command string to display help.
    465  *                                    if not specified, all debugger command
    466  *                                    help strings are displayed
    467  *
    468  * RETURN:      None
    469  *
    470  * DESCRIPTION: Display help for a single debugger command, or all of them.
    471  *
    472  ******************************************************************************/
    473 
    474 static void
    475 AcpiDbDisplayHelp (
    476     char                    *Command)
    477 {
    478     const ACPI_DB_COMMAND_HELP  *Next = AcpiGbl_DbCommandHelp;
    479 
    480 
    481     if (!Command)
    482     {
    483         /* No argument to help, display help for all commands */
    484 
    485         AcpiOsPrintf ("\nSummary of AML Debugger Commands\n\n");
    486 
    487         while (Next->Invocation)
    488         {
    489             AcpiOsPrintf ("%-38s%s", Next->Invocation, Next->Description);
    490             Next++;
    491         }
    492         AcpiOsPrintf ("\n");
    493 
    494     }
    495     else
    496     {
    497         /* Display help for all commands that match the substring */
    498 
    499         AcpiDbDisplayCommandInfo (Command, TRUE);
    500     }
    501 }
    502 
    503 
    504 /*******************************************************************************
    505  *
    506  * FUNCTION:    AcpiDbGetNextToken
    507  *
    508  * PARAMETERS:  String          - Command buffer
    509  *              Next            - Return value, end of next token
    510  *
    511  * RETURN:      Pointer to the start of the next token.
    512  *
    513  * DESCRIPTION: Command line parsing. Get the next token on the command line
    514  *
    515  ******************************************************************************/
    516 
    517 char *
    518 AcpiDbGetNextToken (
    519     char                    *String,
    520     char                    **Next,
    521     ACPI_OBJECT_TYPE        *ReturnType)
    522 {
    523     char                    *Start;
    524     UINT32                  Depth;
    525     ACPI_OBJECT_TYPE        Type = ACPI_TYPE_INTEGER;
    526 
    527 
    528     /* At end of buffer? */
    529 
    530     if (!String || !(*String))
    531     {
    532         return (NULL);
    533     }
    534 
    535     /* Remove any spaces at the beginning, ignore blank lines */
    536 
    537     while (*String && isspace (*String))
    538     {
    539         String++;
    540     }
    541 
    542     if (!(*String))
    543     {
    544         return (NULL);
    545     }
    546 
    547     switch (*String)
    548     {
    549     case '"':
    550 
    551         /* This is a quoted string, scan until closing quote */
    552 
    553         String++;
    554         Start = String;
    555         Type = ACPI_TYPE_STRING;
    556 
    557         /* Find end of string */
    558 
    559         while (*String && (*String != '"'))
    560         {
    561             String++;
    562         }
    563         break;
    564 
    565     case '(':
    566 
    567         /* This is the start of a buffer, scan until closing paren */
    568 
    569         String++;
    570         Start = String;
    571         Type = ACPI_TYPE_BUFFER;
    572 
    573         /* Find end of buffer */
    574 
    575         while (*String && (*String != ')'))
    576         {
    577             String++;
    578         }
    579         break;
    580 
    581     case '{':
    582 
    583         /* This is the start of a field unit, scan until closing brace */
    584 
    585         String++;
    586         Start = String;
    587         Type = ACPI_TYPE_FIELD_UNIT;
    588 
    589         /* Find end of buffer */
    590 
    591         while (*String && (*String != '}'))
    592         {
    593             String++;
    594         }
    595         break;
    596 
    597     case '[':
    598 
    599         /* This is the start of a package, scan until closing bracket */
    600 
    601         String++;
    602         Depth = 1;
    603         Start = String;
    604         Type = ACPI_TYPE_PACKAGE;
    605 
    606         /* Find end of package (closing bracket) */
    607 
    608         while (*String)
    609         {
    610             /* Handle String package elements */
    611 
    612             if (*String == '"')
    613             {
    614                 /* Find end of string */
    615 
    616                 String++;
    617                 while (*String && (*String != '"'))
    618                 {
    619                     String++;
    620                 }
    621                 if (!(*String))
    622                 {
    623                     break;
    624                 }
    625             }
    626             else if (*String == '[')
    627             {
    628                 Depth++;         /* A nested package declaration */
    629             }
    630             else if (*String == ']')
    631             {
    632                 Depth--;
    633                 if (Depth == 0) /* Found final package closing bracket */
    634                 {
    635                     break;
    636                 }
    637             }
    638 
    639             String++;
    640         }
    641         break;
    642 
    643     default:
    644 
    645         Start = String;
    646 
    647         /* Find end of token */
    648 
    649         while (*String && !isspace (*String))
    650         {
    651             String++;
    652         }
    653         break;
    654     }
    655 
    656     if (!(*String))
    657     {
    658         *Next = NULL;
    659     }
    660     else
    661     {
    662         *String = 0;
    663         *Next = String + 1;
    664     }
    665 
    666     *ReturnType = Type;
    667     return (Start);
    668 }
    669 
    670 
    671 /*******************************************************************************
    672  *
    673  * FUNCTION:    AcpiDbGetLine
    674  *
    675  * PARAMETERS:  InputBuffer         - Command line buffer
    676  *
    677  * RETURN:      Count of arguments to the command
    678  *
    679  * DESCRIPTION: Get the next command line from the user. Gets entire line
    680  *              up to the next newline
    681  *
    682  ******************************************************************************/
    683 
    684 static UINT32
    685 AcpiDbGetLine (
    686     char                    *InputBuffer)
    687 {
    688     UINT32                  i;
    689     UINT32                  Count;
    690     char                    *Next;
    691     char                    *This;
    692 
    693 
    694     if (AcpiUtSafeStrcpy (AcpiGbl_DbParsedBuf, sizeof (AcpiGbl_DbParsedBuf),
    695         InputBuffer))
    696     {
    697         AcpiOsPrintf (
    698             "Buffer overflow while parsing input line (max %u characters)\n",
    699             (UINT32) sizeof (AcpiGbl_DbParsedBuf));
    700         return (0);
    701     }
    702 
    703     This = AcpiGbl_DbParsedBuf;
    704     for (i = 0; i < ACPI_DEBUGGER_MAX_ARGS; i++)
    705     {
    706         AcpiGbl_DbArgs[i] = AcpiDbGetNextToken (This, &Next,
    707             &AcpiGbl_DbArgTypes[i]);
    708         if (!AcpiGbl_DbArgs[i])
    709         {
    710             break;
    711         }
    712 
    713         This = Next;
    714     }
    715 
    716     /* Uppercase the actual command */
    717 
    718     AcpiUtStrupr (AcpiGbl_DbArgs[0]);
    719 
    720     Count = i;
    721     if (Count)
    722     {
    723         Count--;  /* Number of args only */
    724     }
    725 
    726     return (Count);
    727 }
    728 
    729 
    730 /*******************************************************************************
    731  *
    732  * FUNCTION:    AcpiDbMatchCommand
    733  *
    734  * PARAMETERS:  UserCommand             - User command line
    735  *
    736  * RETURN:      Index into command array, -1 if not found
    737  *
    738  * DESCRIPTION: Search command array for a command match
    739  *
    740  ******************************************************************************/
    741 
    742 static UINT32
    743 AcpiDbMatchCommand (
    744     char                    *UserCommand)
    745 {
    746     UINT32                  i;
    747 
    748 
    749     if (!UserCommand || UserCommand[0] == 0)
    750     {
    751         return (CMD_NULL);
    752     }
    753 
    754     for (i = CMD_FIRST_VALID; AcpiGbl_DbCommands[i].Name; i++)
    755     {
    756         if (strstr (
    757             ACPI_CAST_PTR (char, AcpiGbl_DbCommands[i].Name), UserCommand) ==
    758             AcpiGbl_DbCommands[i].Name)
    759         {
    760             return (i);
    761         }
    762     }
    763 
    764     /* Command not recognized */
    765 
    766     return (CMD_NOT_FOUND);
    767 }
    768 
    769 
    770 /*******************************************************************************
    771  *
    772  * FUNCTION:    AcpiDbCommandDispatch
    773  *
    774  * PARAMETERS:  InputBuffer         - Command line buffer
    775  *              WalkState           - Current walk
    776  *              Op                  - Current (executing) parse op
    777  *
    778  * RETURN:      Status
    779  *
    780  * DESCRIPTION: Command dispatcher.
    781  *
    782  ******************************************************************************/
    783 
    784 ACPI_STATUS
    785 AcpiDbCommandDispatch (
    786     char                    *InputBuffer,
    787     ACPI_WALK_STATE         *WalkState,
    788     ACPI_PARSE_OBJECT       *Op)
    789 {
    790     UINT32                  Temp;
    791     UINT64                  Temp64;
    792     UINT32                  CommandIndex;
    793     UINT32                  ParamCount;
    794     char                    *CommandLine;
    795     ACPI_STATUS             Status = AE_CTRL_TRUE;
    796 
    797 
    798     /* If AcpiTerminate has been called, terminate this thread */
    799 
    800     if (AcpiGbl_DbTerminateLoop)
    801     {
    802         return (AE_CTRL_TERMINATE);
    803     }
    804 
    805     /* Find command and add to the history buffer */
    806 
    807     ParamCount = AcpiDbGetLine (InputBuffer);
    808     CommandIndex = AcpiDbMatchCommand (AcpiGbl_DbArgs[0]);
    809 
    810     /*
    811      * We don't want to add the !! command to the history buffer. It
    812      * would cause an infinite loop because it would always be the
    813      * previous command.
    814      */
    815     if (CommandIndex != CMD_HISTORY_LAST)
    816     {
    817         AcpiDbAddToHistory (InputBuffer);
    818     }
    819 
    820     /* Verify that we have the minimum number of params */
    821 
    822     if (ParamCount < AcpiGbl_DbCommands[CommandIndex].MinArgs)
    823     {
    824         AcpiOsPrintf ("%u parameters entered, [%s] requires %u parameters\n",
    825             ParamCount, AcpiGbl_DbCommands[CommandIndex].Name,
    826             AcpiGbl_DbCommands[CommandIndex].MinArgs);
    827 
    828         AcpiDbDisplayCommandInfo (
    829             AcpiGbl_DbCommands[CommandIndex].Name, FALSE);
    830         return (AE_CTRL_TRUE);
    831     }
    832 
    833     /* Decode and dispatch the command */
    834 
    835     switch (CommandIndex)
    836     {
    837     case CMD_NULL:
    838 
    839         if (Op)
    840         {
    841             return (AE_OK);
    842         }
    843         break;
    844 
    845     case CMD_ALL:
    846 
    847         AcpiOsPrintf ("Executing all objects with NameSeg: %s\n", AcpiGbl_DbArgs[1]);
    848         AcpiDbExecute (AcpiGbl_DbArgs[1],
    849             &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_NO_SINGLE_STEP | EX_ALL);
    850         break;
    851 
    852     case CMD_ALLOCATIONS:
    853 
    854 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
    855         AcpiUtDumpAllocations ((UINT32) -1, NULL);
    856 #endif
    857         break;
    858 
    859     case CMD_ARGS:
    860     case CMD_ARGUMENTS:
    861 
    862         AcpiDbDisplayArguments ();
    863         break;
    864 
    865     case CMD_BREAKPOINT:
    866 
    867         AcpiDbSetMethodBreakpoint (AcpiGbl_DbArgs[1], WalkState, Op);
    868         break;
    869 
    870     case CMD_BUSINFO:
    871 
    872         AcpiDbGetBusInfo ();
    873         break;
    874 
    875     case CMD_CALL:
    876 
    877         AcpiDbSetMethodCallBreakpoint (Op);
    878         Status = AE_OK;
    879         break;
    880 
    881     case CMD_DEBUG:
    882 
    883         AcpiDbExecute (AcpiGbl_DbArgs[1],
    884             &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_SINGLE_STEP);
    885         break;
    886 
    887     case CMD_DISASSEMBLE:
    888     case CMD_DISASM:
    889 
    890 #ifdef ACPI_DISASSEMBLER
    891         (void) AcpiDbDisassembleMethod (AcpiGbl_DbArgs[1]);
    892 #else
    893         AcpiOsPrintf ("The AML Disassembler is not configured/present\n");
    894 #endif
    895         break;
    896 
    897     case CMD_DUMP:
    898 
    899         AcpiDbDecodeAndDisplayObject (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
    900         break;
    901 
    902     case CMD_EVALUATE:
    903     case CMD_EXECUTE:
    904 
    905         AcpiDbExecute (AcpiGbl_DbArgs[1],
    906             &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_NO_SINGLE_STEP);
    907         break;
    908 
    909     case CMD_FIND:
    910 
    911         Status = AcpiDbFindNameInNamespace (AcpiGbl_DbArgs[1]);
    912         break;
    913 
    914     case CMD_FIELDS:
    915 
    916         Status = AcpiUtStrtoul64 (AcpiGbl_DbArgs[1], &Temp64);
    917 
    918         if (ACPI_FAILURE (Status) || Temp64 >= ACPI_NUM_PREDEFINED_REGIONS)
    919         {
    920             AcpiOsPrintf (
    921                 "Invalid address space ID: must be between 0 and %u inclusive\n",
    922                 ACPI_NUM_PREDEFINED_REGIONS - 1);
    923             return (AE_OK);
    924         }
    925 
    926         Status = AcpiDbDisplayFields ((UINT32) Temp64);
    927         break;
    928 
    929     case CMD_GO:
    930 
    931         AcpiGbl_CmSingleStep = FALSE;
    932         return (AE_OK);
    933 
    934     case CMD_HANDLERS:
    935 
    936         AcpiDbDisplayHandlers ();
    937         break;
    938 
    939     case CMD_HELP:
    940     case CMD_HELP2:
    941 
    942         AcpiDbDisplayHelp (AcpiGbl_DbArgs[1]);
    943         break;
    944 
    945     case CMD_HISTORY:
    946 
    947         AcpiDbDisplayHistory ();
    948         break;
    949 
    950     case CMD_HISTORY_EXE: /* ! command */
    951 
    952         CommandLine = AcpiDbGetFromHistory (AcpiGbl_DbArgs[1]);
    953         if (!CommandLine)
    954         {
    955             return (AE_CTRL_TRUE);
    956         }
    957 
    958         Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
    959         return (Status);
    960 
    961     case CMD_HISTORY_LAST: /* !! command */
    962 
    963         CommandLine = AcpiDbGetFromHistory (NULL);
    964         if (!CommandLine)
    965         {
    966             return (AE_CTRL_TRUE);
    967         }
    968 
    969         Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
    970         return (Status);
    971 
    972     case CMD_INFORMATION:
    973 
    974         AcpiDbDisplayMethodInfo (Op);
    975         break;
    976 
    977     case CMD_INTEGRITY:
    978 
    979         AcpiDbCheckIntegrity ();
    980         break;
    981 
    982     case CMD_INTO:
    983 
    984         if (Op)
    985         {
    986             AcpiGbl_CmSingleStep = TRUE;
    987             return (AE_OK);
    988         }
    989         break;
    990 
    991     case CMD_LEVEL:
    992 
    993         if (ParamCount == 0)
    994         {
    995             AcpiOsPrintf (
    996                 "Current debug level for file output is:    %8.8X\n",
    997                 AcpiGbl_DbDebugLevel);
    998             AcpiOsPrintf (
    999                 "Current debug level for console output is: %8.8X\n",
   1000                 AcpiGbl_DbConsoleDebugLevel);
   1001         }
   1002         else if (ParamCount == 2)
   1003         {
   1004             Temp = AcpiGbl_DbConsoleDebugLevel;
   1005             AcpiGbl_DbConsoleDebugLevel =
   1006                 strtoul (AcpiGbl_DbArgs[1], NULL, 16);
   1007             AcpiOsPrintf (
   1008                 "Debug Level for console output was %8.8X, now %8.8X\n",
   1009                 Temp, AcpiGbl_DbConsoleDebugLevel);
   1010         }
   1011         else
   1012         {
   1013             Temp = AcpiGbl_DbDebugLevel;
   1014             AcpiGbl_DbDebugLevel = strtoul (AcpiGbl_DbArgs[1], NULL, 16);
   1015             AcpiOsPrintf (
   1016                 "Debug Level for file output was %8.8X, now %8.8X\n",
   1017                 Temp, AcpiGbl_DbDebugLevel);
   1018         }
   1019         break;
   1020 
   1021     case CMD_LIST:
   1022 
   1023 #ifdef ACPI_DISASSEMBLER
   1024         AcpiDbDisassembleAml (AcpiGbl_DbArgs[1], Op);
   1025 #else
   1026         AcpiOsPrintf ("The AML Disassembler is not configured/present\n");
   1027 #endif
   1028         break;
   1029 
   1030     case CMD_LOCKS:
   1031 
   1032         AcpiDbDisplayLocks ();
   1033         break;
   1034 
   1035     case CMD_LOCALS:
   1036 
   1037         AcpiDbDisplayLocals ();
   1038         break;
   1039 
   1040     case CMD_METHODS:
   1041 
   1042         Status = AcpiDbDisplayObjects (__UNCONST("METHOD"), AcpiGbl_DbArgs[1]);
   1043         break;
   1044 
   1045     case CMD_NAMESPACE:
   1046 
   1047         AcpiDbDumpNamespace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
   1048         break;
   1049 
   1050     case CMD_NOTIFY:
   1051 
   1052         Temp = strtoul (AcpiGbl_DbArgs[2], NULL, 0);
   1053         AcpiDbSendNotify (AcpiGbl_DbArgs[1], Temp);
   1054         break;
   1055 
   1056     case CMD_OBJECTS:
   1057 
   1058         AcpiUtStrupr (AcpiGbl_DbArgs[1]);
   1059         Status = AcpiDbDisplayObjects (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
   1060         break;
   1061 
   1062     case CMD_OSI:
   1063 
   1064         AcpiDbDisplayInterfaces (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
   1065         break;
   1066 
   1067     case CMD_OWNER:
   1068 
   1069         AcpiDbDumpNamespaceByOwner (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
   1070         break;
   1071 
   1072     case CMD_PATHS:
   1073 
   1074         AcpiDbDumpNamespacePaths ();
   1075         break;
   1076 
   1077     case CMD_PREFIX:
   1078 
   1079         AcpiDbSetScope (AcpiGbl_DbArgs[1]);
   1080         break;
   1081 
   1082     case CMD_REFERENCES:
   1083 
   1084         AcpiDbFindReferences (AcpiGbl_DbArgs[1]);
   1085         break;
   1086 
   1087     case CMD_RESOURCES:
   1088 
   1089         AcpiDbDisplayResources (AcpiGbl_DbArgs[1]);
   1090         break;
   1091 
   1092     case CMD_RESULTS:
   1093 
   1094         AcpiDbDisplayResults ();
   1095         break;
   1096 
   1097     case CMD_SET:
   1098 
   1099         AcpiDbSetMethodData (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],
   1100             AcpiGbl_DbArgs[3]);
   1101         break;
   1102 
   1103     case CMD_STATS:
   1104 
   1105         Status = AcpiDbDisplayStatistics (AcpiGbl_DbArgs[1]);
   1106         break;
   1107 
   1108     case CMD_STOP:
   1109 
   1110         return (AE_NOT_IMPLEMENTED);
   1111 
   1112     case CMD_TABLES:
   1113 
   1114         AcpiDbDisplayTableInfo (AcpiGbl_DbArgs[1]);
   1115         break;
   1116 
   1117     case CMD_TEMPLATE:
   1118 
   1119         AcpiDbDisplayTemplate (AcpiGbl_DbArgs[1]);
   1120         break;
   1121 
   1122     case CMD_TRACE:
   1123 
   1124         AcpiDbTrace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], AcpiGbl_DbArgs[3]);
   1125         break;
   1126 
   1127     case CMD_TREE:
   1128 
   1129         AcpiDbDisplayCallingTree ();
   1130         break;
   1131 
   1132     case CMD_TYPE:
   1133 
   1134         AcpiDbDisplayObjectType (AcpiGbl_DbArgs[1]);
   1135         break;
   1136 
   1137 #ifdef ACPI_APPLICATION
   1138 
   1139     /* Hardware simulation commands. */
   1140 
   1141     case CMD_ENABLEACPI:
   1142 #if (!ACPI_REDUCED_HARDWARE)
   1143 
   1144         Status = AcpiEnable();
   1145         if (ACPI_FAILURE(Status))
   1146         {
   1147             AcpiOsPrintf("AcpiEnable failed (Status=%X)\n", Status);
   1148             return (Status);
   1149         }
   1150 #endif /* !ACPI_REDUCED_HARDWARE */
   1151         break;
   1152 
   1153     case CMD_EVENT:
   1154 
   1155         AcpiOsPrintf ("Event command not implemented\n");
   1156         break;
   1157 
   1158     case CMD_GPE:
   1159 
   1160         AcpiDbGenerateGpe (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
   1161         break;
   1162 
   1163     case CMD_GPES:
   1164 
   1165         AcpiDbDisplayGpes ();
   1166         break;
   1167 
   1168     case CMD_SCI:
   1169 
   1170         AcpiDbGenerateSci ();
   1171         break;
   1172 
   1173     case CMD_SLEEP:
   1174 
   1175         Status = AcpiDbSleep (AcpiGbl_DbArgs[1]);
   1176         break;
   1177 
   1178     /* File I/O commands. */
   1179 
   1180     case CMD_CLOSE:
   1181 
   1182         AcpiDbCloseDebugFile ();
   1183         break;
   1184 
   1185     case CMD_LOAD:
   1186         {
   1187             ACPI_NEW_TABLE_DESC     *ListHead = NULL;
   1188 
   1189             Status = AcGetAllTablesFromFile (AcpiGbl_DbArgs[1],
   1190                 ACPI_GET_ALL_TABLES, &ListHead);
   1191             if (ACPI_SUCCESS (Status))
   1192             {
   1193                 AcpiDbLoadTables (ListHead);
   1194             }
   1195         }
   1196         break;
   1197 
   1198     case CMD_OPEN:
   1199 
   1200         AcpiDbOpenDebugFile (AcpiGbl_DbArgs[1]);
   1201         break;
   1202 
   1203     /* User space commands. */
   1204 
   1205     case CMD_TERMINATE:
   1206 
   1207         AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
   1208         AcpiUtSubsystemShutdown ();
   1209 
   1210         /*
   1211          * TBD: [Restructure] Need some way to re-initialize without
   1212          * re-creating the semaphores!
   1213          */
   1214 
   1215         AcpiGbl_DbTerminateLoop = TRUE;
   1216         /*  AcpiInitialize (NULL);  */
   1217         break;
   1218 
   1219     case CMD_BACKGROUND:
   1220 
   1221         AcpiDbCreateExecutionThread (AcpiGbl_DbArgs[1], &AcpiGbl_DbArgs[2],
   1222             &AcpiGbl_DbArgTypes[2]);
   1223         break;
   1224 
   1225     case CMD_THREADS:
   1226 
   1227         AcpiDbCreateExecutionThreads (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],
   1228             AcpiGbl_DbArgs[3]);
   1229         break;
   1230 
   1231     /* Debug test commands. */
   1232 
   1233     case CMD_PREDEFINED:
   1234 
   1235         AcpiDbCheckPredefinedNames ();
   1236         break;
   1237 
   1238     case CMD_TEST:
   1239 
   1240         AcpiDbExecuteTest (AcpiGbl_DbArgs[1]);
   1241         break;
   1242 
   1243     case CMD_UNLOAD:
   1244 
   1245         AcpiDbUnloadAcpiTable (AcpiGbl_DbArgs[1]);
   1246         break;
   1247 #endif
   1248 
   1249     case CMD_EXIT:
   1250     case CMD_QUIT:
   1251 
   1252         if (Op)
   1253         {
   1254             AcpiOsPrintf ("Method execution terminated\n");
   1255             return (AE_CTRL_TERMINATE);
   1256         }
   1257 
   1258         if (!AcpiGbl_DbOutputToFile)
   1259         {
   1260             AcpiDbgLevel = ACPI_DEBUG_DEFAULT;
   1261         }
   1262 
   1263 #ifdef ACPI_APPLICATION
   1264         AcpiDbCloseDebugFile ();
   1265 #endif
   1266         AcpiGbl_DbTerminateLoop = TRUE;
   1267         return (AE_CTRL_TERMINATE);
   1268 
   1269     case CMD_NOT_FOUND:
   1270     default:
   1271 
   1272         AcpiOsPrintf ("%s: unknown command\n", AcpiGbl_DbArgs[0]);
   1273         return (AE_CTRL_TRUE);
   1274     }
   1275 
   1276     if (ACPI_SUCCESS (Status))
   1277     {
   1278         Status = AE_CTRL_TRUE;
   1279     }
   1280 
   1281     return (Status);
   1282 }
   1283 
   1284 
   1285 /*******************************************************************************
   1286  *
   1287  * FUNCTION:    AcpiDbExecuteThread
   1288  *
   1289  * PARAMETERS:  Context         - Not used
   1290  *
   1291  * RETURN:      None
   1292  *
   1293  * DESCRIPTION: Debugger execute thread. Waits for a command line, then
   1294  *              simply dispatches it.
   1295  *
   1296  ******************************************************************************/
   1297 
   1298 void ACPI_SYSTEM_XFACE
   1299 AcpiDbExecuteThread (
   1300     void                    *Context)
   1301 {
   1302 
   1303     (void) AcpiDbUserCommands ();
   1304     AcpiGbl_DbThreadsTerminated = TRUE;
   1305 }
   1306 
   1307 
   1308 /*******************************************************************************
   1309  *
   1310  * FUNCTION:    AcpiDbUserCommands
   1311  *
   1312  * PARAMETERS:  None
   1313  *
   1314  * RETURN:      None
   1315  *
   1316  * DESCRIPTION: Command line execution for the AML debugger. Commands are
   1317  *              matched and dispatched here.
   1318  *
   1319  ******************************************************************************/
   1320 
   1321 ACPI_STATUS
   1322 AcpiDbUserCommands (
   1323     void)
   1324 {
   1325     ACPI_STATUS             Status = AE_OK;
   1326 
   1327 
   1328     AcpiOsPrintf ("\n");
   1329 
   1330     /* TBD: [Restructure] Need a separate command line buffer for step mode */
   1331 
   1332     while (!AcpiGbl_DbTerminateLoop)
   1333     {
   1334         /* Wait the readiness of the command */
   1335 
   1336         Status = AcpiOsWaitCommandReady ();
   1337         if (ACPI_FAILURE (Status))
   1338         {
   1339             break;
   1340         }
   1341 
   1342         /* Just call to the command line interpreter */
   1343 
   1344         AcpiGbl_MethodExecuting = FALSE;
   1345         AcpiGbl_StepToNextCall = FALSE;
   1346 
   1347         (void) AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
   1348 
   1349         /* Notify the completion of the command */
   1350 
   1351         Status = AcpiOsNotifyCommandComplete ();
   1352         if (ACPI_FAILURE (Status))
   1353         {
   1354             break;
   1355         }
   1356     }
   1357 
   1358     if (ACPI_FAILURE (Status) && Status != AE_CTRL_TERMINATE)
   1359     {
   1360         ACPI_EXCEPTION ((AE_INFO, Status, "While parsing command line"));
   1361     }
   1362     return (Status);
   1363 }
   1364