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