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