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