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