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 #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 char *Command, 75 BOOLEAN DisplayAll); 76 77 static void 78 AcpiDbDisplayHelp ( 79 char *Command); 80 81 static BOOLEAN 82 AcpiDbMatchCommandHelp ( 83 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 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 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 (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_DbTerminateLoop) 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 = 948 strtoul (AcpiGbl_DbArgs[1], 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 ACPI_NEW_TABLE_DESC *ListHead = NULL; 1126 1127 Status = AcpiAcGetAllTablesFromFile (AcpiGbl_DbArgs[1], 1128 ACPI_GET_ALL_TABLES, &ListHead); 1129 if (ACPI_SUCCESS (Status)) 1130 { 1131 AcpiDbLoadTables (ListHead); 1132 } 1133 } 1134 break; 1135 1136 case CMD_OPEN: 1137 1138 AcpiDbOpenDebugFile (AcpiGbl_DbArgs[1]); 1139 break; 1140 1141 /* User space commands. */ 1142 1143 case CMD_TERMINATE: 1144 1145 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT); 1146 AcpiUtSubsystemShutdown (); 1147 1148 /* 1149 * TBD: [Restructure] Need some way to re-initialize without 1150 * re-creating the semaphores! 1151 */ 1152 1153 AcpiGbl_DbTerminateLoop = TRUE; 1154 /* AcpiInitialize (NULL); */ 1155 break; 1156 1157 case CMD_THREADS: 1158 1159 AcpiDbCreateExecutionThreads (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], 1160 AcpiGbl_DbArgs[3]); 1161 break; 1162 1163 /* Debug test commands. */ 1164 1165 case CMD_PREDEFINED: 1166 1167 AcpiDbCheckPredefinedNames (); 1168 break; 1169 1170 case CMD_TEST: 1171 1172 AcpiDbExecuteTest (AcpiGbl_DbArgs[1]); 1173 break; 1174 1175 case CMD_UNLOAD: 1176 1177 AcpiDbUnloadAcpiTable (AcpiGbl_DbArgs[1]); 1178 break; 1179 #endif 1180 1181 case CMD_EXIT: 1182 case CMD_QUIT: 1183 1184 if (Op) 1185 { 1186 AcpiOsPrintf ("Method execution terminated\n"); 1187 return (AE_CTRL_TERMINATE); 1188 } 1189 1190 if (!AcpiGbl_DbOutputToFile) 1191 { 1192 AcpiDbgLevel = ACPI_DEBUG_DEFAULT; 1193 } 1194 1195 #ifdef ACPI_APPLICATION 1196 AcpiDbCloseDebugFile (); 1197 #endif 1198 AcpiGbl_DbTerminateLoop = TRUE; 1199 return (AE_CTRL_TERMINATE); 1200 1201 case CMD_NOT_FOUND: 1202 default: 1203 1204 AcpiOsPrintf ("%s: unknown command\n", AcpiGbl_DbArgs[0]); 1205 return (AE_CTRL_TRUE); 1206 } 1207 1208 if (ACPI_SUCCESS (Status)) 1209 { 1210 Status = AE_CTRL_TRUE; 1211 } 1212 1213 return (Status); 1214 } 1215 1216 1217 /******************************************************************************* 1218 * 1219 * FUNCTION: AcpiDbExecuteThread 1220 * 1221 * PARAMETERS: Context - Not used 1222 * 1223 * RETURN: None 1224 * 1225 * DESCRIPTION: Debugger execute thread. Waits for a command line, then 1226 * simply dispatches it. 1227 * 1228 ******************************************************************************/ 1229 1230 void ACPI_SYSTEM_XFACE 1231 AcpiDbExecuteThread ( 1232 void *Context) 1233 { 1234 ACPI_STATUS Status = AE_OK; 1235 ACPI_STATUS MStatus; 1236 1237 1238 while (Status != AE_CTRL_TERMINATE && !AcpiGbl_DbTerminateLoop) 1239 { 1240 AcpiGbl_MethodExecuting = FALSE; 1241 AcpiGbl_StepToNextCall = FALSE; 1242 1243 MStatus = AcpiOsAcquireMutex (AcpiGbl_DbCommandReady, 1244 ACPI_WAIT_FOREVER); 1245 if (ACPI_FAILURE (MStatus)) 1246 { 1247 return; 1248 } 1249 1250 Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL); 1251 1252 AcpiOsReleaseMutex (AcpiGbl_DbCommandComplete); 1253 } 1254 AcpiGbl_DbThreadsTerminated = TRUE; 1255 } 1256 1257 1258 /******************************************************************************* 1259 * 1260 * FUNCTION: AcpiDbSingleThread 1261 * 1262 * PARAMETERS: None 1263 * 1264 * RETURN: None 1265 * 1266 * DESCRIPTION: Debugger execute thread. Waits for a command line, then 1267 * simply dispatches it. 1268 * 1269 ******************************************************************************/ 1270 1271 static void 1272 AcpiDbSingleThread ( 1273 void) 1274 { 1275 1276 AcpiGbl_MethodExecuting = FALSE; 1277 AcpiGbl_StepToNextCall = FALSE; 1278 1279 (void) AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL); 1280 } 1281 1282 1283 /******************************************************************************* 1284 * 1285 * FUNCTION: AcpiDbUserCommands 1286 * 1287 * PARAMETERS: Prompt - User prompt (depends on mode) 1288 * Op - Current executing parse op 1289 * 1290 * RETURN: None 1291 * 1292 * DESCRIPTION: Command line execution for the AML debugger. Commands are 1293 * matched and dispatched here. 1294 * 1295 ******************************************************************************/ 1296 1297 ACPI_STATUS 1298 AcpiDbUserCommands ( 1299 char Prompt, 1300 ACPI_PARSE_OBJECT *Op) 1301 { 1302 ACPI_STATUS Status = AE_OK; 1303 1304 1305 AcpiOsPrintf ("\n"); 1306 1307 /* TBD: [Restructure] Need a separate command line buffer for step mode */ 1308 1309 while (!AcpiGbl_DbTerminateLoop) 1310 { 1311 /* Force output to console until a command is entered */ 1312 1313 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT); 1314 1315 /* Different prompt if method is executing */ 1316 1317 if (!AcpiGbl_MethodExecuting) 1318 { 1319 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT); 1320 } 1321 else 1322 { 1323 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT); 1324 } 1325 1326 /* Get the user input line */ 1327 1328 Status = AcpiOsGetLine (AcpiGbl_DbLineBuf, 1329 ACPI_DB_LINE_BUFFER_SIZE, NULL); 1330 if (ACPI_FAILURE (Status)) 1331 { 1332 ACPI_EXCEPTION ((AE_INFO, Status, "While parsing command line")); 1333 return (Status); 1334 } 1335 1336 /* Check for single or multithreaded debug */ 1337 1338 if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED) 1339 { 1340 /* 1341 * Signal the debug thread that we have a command to execute, 1342 * and wait for the command to complete. 1343 */ 1344 AcpiOsReleaseMutex (AcpiGbl_DbCommandReady); 1345 1346 Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandComplete, 1347 ACPI_WAIT_FOREVER); 1348 if (ACPI_FAILURE (Status)) 1349 { 1350 return (Status); 1351 } 1352 } 1353 else 1354 { 1355 /* Just call to the command line interpreter */ 1356 1357 AcpiDbSingleThread (); 1358 } 1359 } 1360 1361 return (Status); 1362 } 1363 1364 #endif /* ACPI_DEBUGGER */ 1365