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