1 /******************************************************************************* 2 * 3 * Module Name: dbinput - user front-end to the AML debugger 4 * 5 ******************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2015, 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 49 #ifdef ACPI_DEBUGGER 50 51 #define _COMPONENT ACPI_CA_DEBUGGER 52 ACPI_MODULE_NAME ("dbinput") 53 54 55 /* Local prototypes */ 56 57 static UINT32 58 AcpiDbGetLine ( 59 char *InputBuffer); 60 61 static UINT32 62 AcpiDbMatchCommand ( 63 char *UserCommand); 64 65 static void 66 AcpiDbSingleThread ( 67 void); 68 69 static void 70 AcpiDbDisplayCommandInfo ( 71 char *Command, 72 BOOLEAN DisplayAll); 73 74 static void 75 AcpiDbDisplayHelp ( 76 char *Command); 77 78 static BOOLEAN 79 AcpiDbMatchCommandHelp ( 80 char *Command, 81 const ACPI_DB_COMMAND_HELP *Help); 82 83 84 /* 85 * Top-level debugger commands. 86 * 87 * This list of commands must match the string table below it 88 */ 89 enum AcpiExDebuggerCommands 90 { 91 CMD_NOT_FOUND = 0, 92 CMD_NULL, 93 CMD_ALLOCATIONS, 94 CMD_ARGS, 95 CMD_ARGUMENTS, 96 CMD_BREAKPOINT, 97 CMD_BUSINFO, 98 CMD_CALL, 99 CMD_DEBUG, 100 CMD_DISASSEMBLE, 101 CMD_DISASM, 102 CMD_DUMP, 103 CMD_EVALUATE, 104 CMD_EXECUTE, 105 CMD_EXIT, 106 CMD_FIND, 107 CMD_GO, 108 CMD_HANDLERS, 109 CMD_HELP, 110 CMD_HELP2, 111 CMD_HISTORY, 112 CMD_HISTORY_EXE, 113 CMD_HISTORY_LAST, 114 CMD_INFORMATION, 115 CMD_INTEGRITY, 116 CMD_INTO, 117 CMD_LEVEL, 118 CMD_LIST, 119 CMD_LOCALS, 120 CMD_LOCKS, 121 CMD_METHODS, 122 CMD_NAMESPACE, 123 CMD_NOTIFY, 124 CMD_OBJECTS, 125 CMD_OSI, 126 CMD_OWNER, 127 CMD_PATHS, 128 CMD_PREDEFINED, 129 CMD_PREFIX, 130 CMD_QUIT, 131 CMD_REFERENCES, 132 CMD_RESOURCES, 133 CMD_RESULTS, 134 CMD_SET, 135 CMD_STATS, 136 CMD_STOP, 137 CMD_TABLES, 138 CMD_TEMPLATE, 139 CMD_TRACE, 140 CMD_TREE, 141 CMD_TYPE, 142 #ifdef ACPI_APPLICATION 143 CMD_ENABLEACPI, 144 CMD_EVENT, 145 CMD_GPE, 146 CMD_GPES, 147 CMD_SCI, 148 CMD_SLEEP, 149 150 CMD_CLOSE, 151 CMD_LOAD, 152 CMD_OPEN, 153 CMD_UNLOAD, 154 155 CMD_TERMINATE, 156 CMD_THREADS, 157 158 CMD_TEST, 159 #endif 160 }; 161 162 #define CMD_FIRST_VALID 2 163 164 165 /* Second parameter is the required argument count */ 166 167 static const ACPI_DB_COMMAND_INFO AcpiGbl_DbCommands[] = 168 { 169 {"<NOT FOUND>", 0}, 170 {"<NULL>", 0}, 171 {"ALLOCATIONS", 0}, 172 {"ARGS", 0}, 173 {"ARGUMENTS", 0}, 174 {"BREAKPOINT", 1}, 175 {"BUSINFO", 0}, 176 {"CALL", 0}, 177 {"DEBUG", 1}, 178 {"DISASSEMBLE", 1}, 179 {"DISASM", 1}, 180 {"DUMP", 1}, 181 {"EVALUATE", 1}, 182 {"EXECUTE", 1}, 183 {"EXIT", 0}, 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 {"THREADS", 3}, 235 236 {"TEST", 1}, 237 #endif 238 {NULL, 0} 239 }; 240 241 /* 242 * Help for all debugger commands. First argument is the number of lines 243 * of help to output for the command. 244 */ 245 static const ACPI_DB_COMMAND_HELP AcpiGbl_DbCommandHelp[] = 246 { 247 {0, "\nGeneral-Purpose Commands:", "\n"}, 248 {1, " Allocations", "Display list of current memory allocations\n"}, 249 {2, " Dump <Address>|<Namepath>", "\n"}, 250 {0, " [Byte|Word|Dword|Qword]", "Display ACPI objects or memory\n"}, 251 {1, " Handlers", "Info about global handlers\n"}, 252 {1, " Help [Command]", "This help screen or individual command\n"}, 253 {1, " History", "Display command history buffer\n"}, 254 {1, " Level <DebugLevel>] [console]", "Get/Set debug level for file or console\n"}, 255 {1, " Locks", "Current status of internal mutexes\n"}, 256 {1, " Osi [Install|Remove <name>]", "Display or modify global _OSI list\n"}, 257 {1, " Quit or Exit", "Exit this command\n"}, 258 {8, " Stats <SubCommand>", "Display namespace and memory statistics\n"}, 259 {1, " Allocations", "Display list of current memory allocations\n"}, 260 {1, " Memory", "Dump internal memory lists\n"}, 261 {1, " Misc", "Namespace search and mutex stats\n"}, 262 {1, " Objects", "Summary of namespace objects\n"}, 263 {1, " Sizes", "Sizes for each of the internal objects\n"}, 264 {1, " Stack", "Display CPU stack usage\n"}, 265 {1, " Tables", "Info about current ACPI table(s)\n"}, 266 {1, " Tables", "Display info about loaded ACPI tables\n"}, 267 {1, " ! <CommandNumber>", "Execute command from history buffer\n"}, 268 {1, " !!", "Execute last command again\n"}, 269 270 {0, "\nNamespace Access Commands:", "\n"}, 271 {1, " Businfo", "Display system bus info\n"}, 272 {1, " Disassemble <Method>", "Disassemble a control method\n"}, 273 {1, " Find <AcpiName> (? is wildcard)", "Find ACPI name(s) with wildcards\n"}, 274 {1, " Integrity", "Validate namespace integrity\n"}, 275 {1, " Methods", "Display list of loaded control methods\n"}, 276 {1, " Namespace [Object] [Depth]", "Display loaded namespace tree/subtree\n"}, 277 {1, " Notify <Object> <Value>", "Send a notification on Object\n"}, 278 {1, " Objects [ObjectType]", "Display summary of all objects or just given type\n"}, 279 {1, " Owner <OwnerId> [Depth]", "Display loaded namespace by object owner\n"}, 280 {1, " Paths", "Display full pathnames of namespace objects\n"}, 281 {1, " Predefined", "Check all predefined names\n"}, 282 {1, " Prefix [<Namepath>]", "Set or Get current execution prefix\n"}, 283 {1, " References <Addr>", "Find all references to object at addr\n"}, 284 {1, " Resources [DeviceName]", "Display Device resources (no arg = all devices)\n"}, 285 {1, " Set N <NamedObject> <Value>", "Set value for named integer\n"}, 286 {1, " Template <Object>", "Format/dump a Buffer/ResourceTemplate\n"}, 287 {1, " Type <Object>", "Display object type\n"}, 288 289 {0, "\nControl Method Execution Commands:","\n"}, 290 {1, " Arguments (or Args)", "Display method arguments\n"}, 291 {1, " Breakpoint <AmlOffset>", "Set an AML execution breakpoint\n"}, 292 {1, " Call", "Run to next control method invocation\n"}, 293 {1, " Debug <Namepath> [Arguments]", "Single Step a control method\n"}, 294 {6, " Evaluate", "Synonym for Execute\n"}, 295 {5, " Execute <Namepath> [Arguments]", "Execute control method\n"}, 296 {1, " Hex Integer", "Integer method argument\n"}, 297 {1, " \"Ascii String\"", "String method argument\n"}, 298 {1, " (Hex Byte List)", "Buffer method argument\n"}, 299 {1, " [Package Element List]", "Package method argument\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 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 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 if (AcpiGbl_DbArgs[0]) 685 { 686 AcpiUtStrupr (AcpiGbl_DbArgs[0]); 687 } 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 (AcpiGbl_DbCommands[i].Name, UserCommand) == 726 AcpiGbl_DbCommands[i].Name) 727 { 728 return (i); 729 } 730 } 731 732 /* Command not recognized */ 733 734 return (CMD_NOT_FOUND); 735 } 736 737 738 /******************************************************************************* 739 * 740 * FUNCTION: AcpiDbCommandDispatch 741 * 742 * PARAMETERS: InputBuffer - Command line buffer 743 * WalkState - Current walk 744 * Op - Current (executing) parse op 745 * 746 * RETURN: Status 747 * 748 * DESCRIPTION: Command dispatcher. 749 * 750 ******************************************************************************/ 751 752 ACPI_STATUS 753 AcpiDbCommandDispatch ( 754 char *InputBuffer, 755 ACPI_WALK_STATE *WalkState, 756 ACPI_PARSE_OBJECT *Op) 757 { 758 UINT32 Temp; 759 UINT32 CommandIndex; 760 UINT32 ParamCount; 761 char *CommandLine; 762 ACPI_STATUS Status = AE_CTRL_TRUE; 763 764 765 /* If AcpiTerminate has been called, terminate this thread */ 766 767 if (AcpiGbl_DbTerminateThreads) 768 { 769 return (AE_CTRL_TERMINATE); 770 } 771 772 /* Find command and add to the history buffer */ 773 774 ParamCount = AcpiDbGetLine (InputBuffer); 775 CommandIndex = AcpiDbMatchCommand (AcpiGbl_DbArgs[0]); 776 Temp = 0; 777 778 /* 779 * We don't want to add the !! command to the history buffer. It 780 * would cause an infinite loop because it would always be the 781 * previous command. 782 */ 783 if (CommandIndex != CMD_HISTORY_LAST) 784 { 785 AcpiDbAddToHistory (InputBuffer); 786 } 787 788 /* Verify that we have the minimum number of params */ 789 790 if (ParamCount < AcpiGbl_DbCommands[CommandIndex].MinArgs) 791 { 792 AcpiOsPrintf ("%u parameters entered, [%s] requires %u parameters\n", 793 ParamCount, AcpiGbl_DbCommands[CommandIndex].Name, 794 AcpiGbl_DbCommands[CommandIndex].MinArgs); 795 796 AcpiDbDisplayCommandInfo ( 797 AcpiGbl_DbCommands[CommandIndex].Name, FALSE); 798 return (AE_CTRL_TRUE); 799 } 800 801 /* Decode and dispatch the command */ 802 803 switch (CommandIndex) 804 { 805 case CMD_NULL: 806 807 if (Op) 808 { 809 return (AE_OK); 810 } 811 break; 812 813 case CMD_ALLOCATIONS: 814 815 #ifdef ACPI_DBG_TRACK_ALLOCATIONS 816 AcpiUtDumpAllocations ((UINT32) -1, NULL); 817 #endif 818 break; 819 820 case CMD_ARGS: 821 case CMD_ARGUMENTS: 822 823 AcpiDbDisplayArguments (); 824 break; 825 826 case CMD_BREAKPOINT: 827 828 AcpiDbSetMethodBreakpoint (AcpiGbl_DbArgs[1], WalkState, Op); 829 break; 830 831 case CMD_BUSINFO: 832 833 AcpiDbGetBusInfo (); 834 break; 835 836 case CMD_CALL: 837 838 AcpiDbSetMethodCallBreakpoint (Op); 839 Status = AE_OK; 840 break; 841 842 case CMD_DEBUG: 843 844 AcpiDbExecute (AcpiGbl_DbArgs[1], 845 &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_SINGLE_STEP); 846 break; 847 848 case CMD_DISASSEMBLE: 849 case CMD_DISASM: 850 851 (void) AcpiDbDisassembleMethod (AcpiGbl_DbArgs[1]); 852 break; 853 854 case CMD_DUMP: 855 856 AcpiDbDecodeAndDisplayObject (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]); 857 break; 858 859 case CMD_EVALUATE: 860 case CMD_EXECUTE: 861 862 AcpiDbExecute (AcpiGbl_DbArgs[1], 863 &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_NO_SINGLE_STEP); 864 break; 865 866 case CMD_FIND: 867 868 Status = AcpiDbFindNameInNamespace (AcpiGbl_DbArgs[1]); 869 break; 870 871 case CMD_GO: 872 873 AcpiGbl_CmSingleStep = FALSE; 874 return (AE_OK); 875 876 case CMD_HANDLERS: 877 878 AcpiDbDisplayHandlers (); 879 break; 880 881 case CMD_HELP: 882 case CMD_HELP2: 883 884 AcpiDbDisplayHelp (AcpiGbl_DbArgs[1]); 885 break; 886 887 case CMD_HISTORY: 888 889 AcpiDbDisplayHistory (); 890 break; 891 892 case CMD_HISTORY_EXE: /* ! command */ 893 894 CommandLine = AcpiDbGetFromHistory (AcpiGbl_DbArgs[1]); 895 if (!CommandLine) 896 { 897 return (AE_CTRL_TRUE); 898 } 899 900 Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op); 901 return (Status); 902 903 case CMD_HISTORY_LAST: /* !! command */ 904 905 CommandLine = AcpiDbGetFromHistory (NULL); 906 if (!CommandLine) 907 { 908 return (AE_CTRL_TRUE); 909 } 910 911 Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op); 912 return (Status); 913 914 case CMD_INFORMATION: 915 916 AcpiDbDisplayMethodInfo (Op); 917 break; 918 919 case CMD_INTEGRITY: 920 921 AcpiDbCheckIntegrity (); 922 break; 923 924 case CMD_INTO: 925 926 if (Op) 927 { 928 AcpiGbl_CmSingleStep = TRUE; 929 return (AE_OK); 930 } 931 break; 932 933 case CMD_LEVEL: 934 935 if (ParamCount == 0) 936 { 937 AcpiOsPrintf ( 938 "Current debug level for file output is: %8.8lX\n", 939 AcpiGbl_DbDebugLevel); 940 AcpiOsPrintf ( 941 "Current debug level for console output is: %8.8lX\n", 942 AcpiGbl_DbConsoleDebugLevel); 943 } 944 else if (ParamCount == 2) 945 { 946 Temp = AcpiGbl_DbConsoleDebugLevel; 947 AcpiGbl_DbConsoleDebugLevel = strtoul (AcpiGbl_DbArgs[1], 948 NULL, 16); 949 AcpiOsPrintf ( 950 "Debug Level for console output was %8.8lX, now %8.8lX\n", 951 Temp, AcpiGbl_DbConsoleDebugLevel); 952 } 953 else 954 { 955 Temp = AcpiGbl_DbDebugLevel; 956 AcpiGbl_DbDebugLevel = strtoul (AcpiGbl_DbArgs[1], NULL, 16); 957 AcpiOsPrintf ( 958 "Debug Level for file output was %8.8lX, now %8.8lX\n", 959 Temp, AcpiGbl_DbDebugLevel); 960 } 961 break; 962 963 case CMD_LIST: 964 965 AcpiDbDisassembleAml (AcpiGbl_DbArgs[1], Op); 966 break; 967 968 case CMD_LOCKS: 969 970 AcpiDbDisplayLocks (); 971 break; 972 973 case CMD_LOCALS: 974 975 AcpiDbDisplayLocals (); 976 break; 977 978 case CMD_METHODS: 979 980 Status = AcpiDbDisplayObjects ("METHOD", AcpiGbl_DbArgs[1]); 981 break; 982 983 case CMD_NAMESPACE: 984 985 AcpiDbDumpNamespace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]); 986 break; 987 988 case CMD_NOTIFY: 989 990 Temp = strtoul (AcpiGbl_DbArgs[2], NULL, 0); 991 AcpiDbSendNotify (AcpiGbl_DbArgs[1], Temp); 992 break; 993 994 case CMD_OBJECTS: 995 996 AcpiUtStrupr (AcpiGbl_DbArgs[1]); 997 Status = AcpiDbDisplayObjects (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]); 998 break; 999 1000 case CMD_OSI: 1001 1002 AcpiDbDisplayInterfaces (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]); 1003 break; 1004 1005 case CMD_OWNER: 1006 1007 AcpiDbDumpNamespaceByOwner (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]); 1008 break; 1009 1010 case CMD_PATHS: 1011 1012 AcpiDbDumpNamespacePaths (); 1013 break; 1014 1015 case CMD_PREFIX: 1016 1017 AcpiDbSetScope (AcpiGbl_DbArgs[1]); 1018 break; 1019 1020 case CMD_REFERENCES: 1021 1022 AcpiDbFindReferences (AcpiGbl_DbArgs[1]); 1023 break; 1024 1025 case CMD_RESOURCES: 1026 1027 AcpiDbDisplayResources (AcpiGbl_DbArgs[1]); 1028 break; 1029 1030 case CMD_RESULTS: 1031 1032 AcpiDbDisplayResults (); 1033 break; 1034 1035 case CMD_SET: 1036 1037 AcpiDbSetMethodData (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], 1038 AcpiGbl_DbArgs[3]); 1039 break; 1040 1041 case CMD_STATS: 1042 1043 Status = AcpiDbDisplayStatistics (AcpiGbl_DbArgs[1]); 1044 break; 1045 1046 case CMD_STOP: 1047 1048 return (AE_NOT_IMPLEMENTED); 1049 1050 case CMD_TABLES: 1051 1052 AcpiDbDisplayTableInfo (AcpiGbl_DbArgs[1]); 1053 break; 1054 1055 case CMD_TEMPLATE: 1056 1057 AcpiDbDisplayTemplate (AcpiGbl_DbArgs[1]); 1058 break; 1059 1060 case CMD_TRACE: 1061 1062 AcpiDbTrace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], AcpiGbl_DbArgs[3]); 1063 break; 1064 1065 case CMD_TREE: 1066 1067 AcpiDbDisplayCallingTree (); 1068 break; 1069 1070 case CMD_TYPE: 1071 1072 AcpiDbDisplayObjectType (AcpiGbl_DbArgs[1]); 1073 break; 1074 1075 #ifdef ACPI_APPLICATION 1076 1077 /* Hardware simulation commands. */ 1078 1079 case CMD_ENABLEACPI: 1080 #if (!ACPI_REDUCED_HARDWARE) 1081 1082 Status = AcpiEnable(); 1083 if (ACPI_FAILURE(Status)) 1084 { 1085 AcpiOsPrintf("AcpiEnable failed (Status=%X)\n", Status); 1086 return (Status); 1087 } 1088 #endif /* !ACPI_REDUCED_HARDWARE */ 1089 break; 1090 1091 case CMD_EVENT: 1092 1093 AcpiOsPrintf ("Event command not implemented\n"); 1094 break; 1095 1096 case CMD_GPE: 1097 1098 AcpiDbGenerateGpe (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]); 1099 break; 1100 1101 case CMD_GPES: 1102 1103 AcpiDbDisplayGpes (); 1104 break; 1105 1106 case CMD_SCI: 1107 1108 AcpiDbGenerateSci (); 1109 break; 1110 1111 case CMD_SLEEP: 1112 1113 Status = AcpiDbSleep (AcpiGbl_DbArgs[1]); 1114 break; 1115 1116 /* File I/O commands. */ 1117 1118 case CMD_CLOSE: 1119 1120 AcpiDbCloseDebugFile (); 1121 break; 1122 1123 case CMD_LOAD: 1124 1125 Status = AcpiDbGetTableFromFile (AcpiGbl_DbArgs[1], NULL, FALSE); 1126 break; 1127 1128 case CMD_OPEN: 1129 1130 AcpiDbOpenDebugFile (AcpiGbl_DbArgs[1]); 1131 break; 1132 1133 /* User space commands. */ 1134 1135 case CMD_TERMINATE: 1136 1137 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT); 1138 AcpiUtSubsystemShutdown (); 1139 1140 /* 1141 * TBD: [Restructure] Need some way to re-initialize without 1142 * re-creating the semaphores! 1143 */ 1144 1145 /* AcpiInitialize (NULL); */ 1146 break; 1147 1148 case CMD_THREADS: 1149 1150 AcpiDbCreateExecutionThreads (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], 1151 AcpiGbl_DbArgs[3]); 1152 break; 1153 1154 /* Debug test commands. */ 1155 1156 case CMD_PREDEFINED: 1157 1158 AcpiDbCheckPredefinedNames (); 1159 break; 1160 1161 case CMD_TEST: 1162 1163 AcpiDbExecuteTest (AcpiGbl_DbArgs[1]); 1164 break; 1165 1166 case CMD_UNLOAD: 1167 1168 AcpiDbUnloadAcpiTable (AcpiGbl_DbArgs[1]); 1169 break; 1170 #endif 1171 1172 case CMD_EXIT: 1173 case CMD_QUIT: 1174 1175 if (Op) 1176 { 1177 AcpiOsPrintf ("Method execution terminated\n"); 1178 return (AE_CTRL_TERMINATE); 1179 } 1180 1181 if (!AcpiGbl_DbOutputToFile) 1182 { 1183 AcpiDbgLevel = ACPI_DEBUG_DEFAULT; 1184 } 1185 1186 #ifdef ACPI_APPLICATION 1187 AcpiDbCloseDebugFile (); 1188 #endif 1189 AcpiGbl_DbTerminateThreads = TRUE; 1190 return (AE_CTRL_TERMINATE); 1191 1192 case CMD_NOT_FOUND: 1193 default: 1194 1195 AcpiOsPrintf ("%s: unknown command\n", AcpiGbl_DbArgs[0]); 1196 return (AE_CTRL_TRUE); 1197 } 1198 1199 if (ACPI_SUCCESS (Status)) 1200 { 1201 Status = AE_CTRL_TRUE; 1202 } 1203 1204 return (Status); 1205 } 1206 1207 1208 /******************************************************************************* 1209 * 1210 * FUNCTION: AcpiDbExecuteThread 1211 * 1212 * PARAMETERS: Context - Not used 1213 * 1214 * RETURN: None 1215 * 1216 * DESCRIPTION: Debugger execute thread. Waits for a command line, then 1217 * simply dispatches it. 1218 * 1219 ******************************************************************************/ 1220 1221 void ACPI_SYSTEM_XFACE 1222 AcpiDbExecuteThread ( 1223 void *Context) 1224 { 1225 ACPI_STATUS Status = AE_OK; 1226 ACPI_STATUS MStatus; 1227 1228 1229 while (Status != AE_CTRL_TERMINATE) 1230 { 1231 AcpiGbl_MethodExecuting = FALSE; 1232 AcpiGbl_StepToNextCall = FALSE; 1233 1234 MStatus = AcpiOsAcquireMutex (AcpiGbl_DbCommandReady, 1235 ACPI_WAIT_FOREVER); 1236 if (ACPI_FAILURE (MStatus)) 1237 { 1238 return; 1239 } 1240 1241 Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL); 1242 1243 AcpiOsReleaseMutex (AcpiGbl_DbCommandComplete); 1244 } 1245 } 1246 1247 1248 /******************************************************************************* 1249 * 1250 * FUNCTION: AcpiDbSingleThread 1251 * 1252 * PARAMETERS: None 1253 * 1254 * RETURN: None 1255 * 1256 * DESCRIPTION: Debugger execute thread. Waits for a command line, then 1257 * simply dispatches it. 1258 * 1259 ******************************************************************************/ 1260 1261 static void 1262 AcpiDbSingleThread ( 1263 void) 1264 { 1265 1266 AcpiGbl_MethodExecuting = FALSE; 1267 AcpiGbl_StepToNextCall = FALSE; 1268 1269 (void) AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL); 1270 } 1271 1272 1273 /******************************************************************************* 1274 * 1275 * FUNCTION: AcpiDbUserCommands 1276 * 1277 * PARAMETERS: Prompt - User prompt (depends on mode) 1278 * Op - Current executing parse op 1279 * 1280 * RETURN: None 1281 * 1282 * DESCRIPTION: Command line execution for the AML debugger. Commands are 1283 * matched and dispatched here. 1284 * 1285 ******************************************************************************/ 1286 1287 ACPI_STATUS 1288 AcpiDbUserCommands ( 1289 char Prompt, 1290 ACPI_PARSE_OBJECT *Op) 1291 { 1292 ACPI_STATUS Status = AE_OK; 1293 1294 1295 AcpiOsPrintf ("\n"); 1296 1297 /* TBD: [Restructure] Need a separate command line buffer for step mode */ 1298 1299 while (!AcpiGbl_DbTerminateThreads) 1300 { 1301 /* Force output to console until a command is entered */ 1302 1303 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT); 1304 1305 /* Different prompt if method is executing */ 1306 1307 if (!AcpiGbl_MethodExecuting) 1308 { 1309 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT); 1310 } 1311 else 1312 { 1313 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT); 1314 } 1315 1316 /* Get the user input line */ 1317 1318 Status = AcpiOsGetLine (AcpiGbl_DbLineBuf, 1319 ACPI_DB_LINE_BUFFER_SIZE, NULL); 1320 if (ACPI_FAILURE (Status)) 1321 { 1322 ACPI_EXCEPTION ((AE_INFO, Status, "While parsing command line")); 1323 return (Status); 1324 } 1325 1326 /* Check for single or multithreaded debug */ 1327 1328 if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED) 1329 { 1330 /* 1331 * Signal the debug thread that we have a command to execute, 1332 * and wait for the command to complete. 1333 */ 1334 AcpiOsReleaseMutex (AcpiGbl_DbCommandReady); 1335 if (ACPI_FAILURE (Status)) 1336 { 1337 return (Status); 1338 } 1339 1340 Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandComplete, 1341 ACPI_WAIT_FOREVER); 1342 if (ACPI_FAILURE (Status)) 1343 { 1344 return (Status); 1345 } 1346 } 1347 else 1348 { 1349 /* Just call to the command line interpreter */ 1350 1351 AcpiDbSingleThread (); 1352 } 1353 } 1354 1355 /* Shut down the debugger */ 1356 1357 AcpiTerminateDebugger (); 1358 1359 /* 1360 * Only this thread (the original thread) should actually terminate the 1361 * subsystem, because all the semaphores are deleted during termination 1362 */ 1363 Status = AcpiTerminate (); 1364 return (Status); 1365 } 1366 1367 #endif /* ACPI_DEBUGGER */ 1368