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