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