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 <contrib/dev/acpica/include/acpi.h> 45 #include <contrib/dev/acpica/include/accommon.h> 46 #include <contrib/dev/acpica/include/acdebug.h> 47 48 #ifdef ACPI_APPLICATION 49 #include <contrib/dev/acpica/include/acapps.h> 50 #endif 51 52 #define _COMPONENT ACPI_CA_DEBUGGER 53 ACPI_MODULE_NAME ("dbinput") 54 55 56 /* Local prototypes */ 57 58 static UINT32 59 AcpiDbGetLine ( 60 char *InputBuffer); 61 62 static UINT32 63 AcpiDbMatchCommand ( 64 char *UserCommand); 65 66 static void 67 AcpiDbSingleThread ( 68 void); 69 70 static void 71 AcpiDbDisplayCommandInfo ( 72 const char *Command, 73 BOOLEAN DisplayAll); 74 75 static void 76 AcpiDbDisplayHelp ( 77 char *Command); 78 79 static BOOLEAN 80 AcpiDbMatchCommandHelp ( 81 const char *Command, 82 const ACPI_DB_COMMAND_HELP *Help); 83 84 85 /* 86 * Top-level debugger commands. 87 * 88 * This list of commands must match the string table below it 89 */ 90 enum AcpiExDebuggerCommands 91 { 92 CMD_NOT_FOUND = 0, 93 CMD_NULL, 94 CMD_ALLOCATIONS, 95 CMD_ARGS, 96 CMD_ARGUMENTS, 97 CMD_BREAKPOINT, 98 CMD_BUSINFO, 99 CMD_CALL, 100 CMD_DEBUG, 101 CMD_DISASSEMBLE, 102 CMD_DISASM, 103 CMD_DUMP, 104 CMD_EVALUATE, 105 CMD_EXECUTE, 106 CMD_EXIT, 107 CMD_FIND, 108 CMD_GO, 109 CMD_HANDLERS, 110 CMD_HELP, 111 CMD_HELP2, 112 CMD_HISTORY, 113 CMD_HISTORY_EXE, 114 CMD_HISTORY_LAST, 115 CMD_INFORMATION, 116 CMD_INTEGRITY, 117 CMD_INTO, 118 CMD_LEVEL, 119 CMD_LIST, 120 CMD_LOCALS, 121 CMD_LOCKS, 122 CMD_METHODS, 123 CMD_NAMESPACE, 124 CMD_NOTIFY, 125 CMD_OBJECTS, 126 CMD_OSI, 127 CMD_OWNER, 128 CMD_PATHS, 129 CMD_PREDEFINED, 130 CMD_PREFIX, 131 CMD_QUIT, 132 CMD_REFERENCES, 133 CMD_RESOURCES, 134 CMD_RESULTS, 135 CMD_SET, 136 CMD_STATS, 137 CMD_STOP, 138 CMD_TABLES, 139 CMD_TEMPLATE, 140 CMD_TRACE, 141 CMD_TREE, 142 CMD_TYPE, 143 #ifdef ACPI_APPLICATION 144 CMD_ENABLEACPI, 145 CMD_EVENT, 146 CMD_GPE, 147 CMD_GPES, 148 CMD_SCI, 149 CMD_SLEEP, 150 151 CMD_CLOSE, 152 CMD_LOAD, 153 CMD_OPEN, 154 CMD_UNLOAD, 155 156 CMD_TERMINATE, 157 CMD_THREADS, 158 159 CMD_TEST, 160 #endif 161 }; 162 163 #define CMD_FIRST_VALID 2 164 165 166 /* Second parameter is the required argument count */ 167 168 static const ACPI_DB_COMMAND_INFO AcpiGbl_DbCommands[] = 169 { 170 {"<NOT FOUND>", 0}, 171 {"<NULL>", 0}, 172 {"ALLOCATIONS", 0}, 173 {"ARGS", 0}, 174 {"ARGUMENTS", 0}, 175 {"BREAKPOINT", 1}, 176 {"BUSINFO", 0}, 177 {"CALL", 0}, 178 {"DEBUG", 1}, 179 {"DISASSEMBLE", 1}, 180 {"DISASM", 1}, 181 {"DUMP", 1}, 182 {"EVALUATE", 1}, 183 {"EXECUTE", 1}, 184 {"EXIT", 0}, 185 {"FIND", 1}, 186 {"GO", 0}, 187 {"HANDLERS", 0}, 188 {"HELP", 0}, 189 {"?", 0}, 190 {"HISTORY", 0}, 191 {"!", 1}, 192 {"!!", 0}, 193 {"INFORMATION", 0}, 194 {"INTEGRITY", 0}, 195 {"INTO", 0}, 196 {"LEVEL", 0}, 197 {"LIST", 0}, 198 {"LOCALS", 0}, 199 {"LOCKS", 0}, 200 {"METHODS", 0}, 201 {"NAMESPACE", 0}, 202 {"NOTIFY", 2}, 203 {"OBJECTS", 0}, 204 {"OSI", 0}, 205 {"OWNER", 1}, 206 {"PATHS", 0}, 207 {"PREDEFINED", 0}, 208 {"PREFIX", 0}, 209 {"QUIT", 0}, 210 {"REFERENCES", 1}, 211 {"RESOURCES", 0}, 212 {"RESULTS", 0}, 213 {"SET", 3}, 214 {"STATS", 1}, 215 {"STOP", 0}, 216 {"TABLES", 0}, 217 {"TEMPLATE", 1}, 218 {"TRACE", 1}, 219 {"TREE", 0}, 220 {"TYPE", 1}, 221 #ifdef ACPI_APPLICATION 222 {"ENABLEACPI", 0}, 223 {"EVENT", 1}, 224 {"GPE", 1}, 225 {"GPES", 0}, 226 {"SCI", 0}, 227 {"SLEEP", 0}, 228 229 {"CLOSE", 0}, 230 {"LOAD", 1}, 231 {"OPEN", 1}, 232 {"UNLOAD", 1}, 233 234 {"TERMINATE", 0}, 235 {"THREADS", 3}, 236 237 {"TEST", 1}, 238 #endif 239 {NULL, 0} 240 }; 241 242 /* 243 * Help for all debugger commands. First argument is the number of lines 244 * of help to output for the command. 245 */ 246 static const ACPI_DB_COMMAND_HELP AcpiGbl_DbCommandHelp[] = 247 { 248 {0, "\nGeneral-Purpose Commands:", "\n"}, 249 {1, " Allocations", "Display list of current memory allocations\n"}, 250 {2, " Dump <Address>|<Namepath>", "\n"}, 251 {0, " [Byte|Word|Dword|Qword]", "Display ACPI objects or memory\n"}, 252 {1, " Handlers", "Info about global handlers\n"}, 253 {1, " Help [Command]", "This help screen or individual command\n"}, 254 {1, " History", "Display command history buffer\n"}, 255 {1, " Level <DebugLevel>] [console]", "Get/Set debug level for file or console\n"}, 256 {1, " Locks", "Current status of internal mutexes\n"}, 257 {1, " Osi [Install|Remove <name>]", "Display or modify global _OSI list\n"}, 258 {1, " Quit or Exit", "Exit this command\n"}, 259 {8, " Stats <SubCommand>", "Display namespace and memory statistics\n"}, 260 {1, " Allocations", "Display list of current memory allocations\n"}, 261 {1, " Memory", "Dump internal memory lists\n"}, 262 {1, " Misc", "Namespace search and mutex stats\n"}, 263 {1, " Objects", "Summary of namespace objects\n"}, 264 {1, " Sizes", "Sizes for each of the internal objects\n"}, 265 {1, " Stack", "Display CPU stack usage\n"}, 266 {1, " Tables", "Info about current ACPI table(s)\n"}, 267 {1, " Tables", "Display info about loaded ACPI tables\n"}, 268 {1, " ! <CommandNumber>", "Execute command from history buffer\n"}, 269 {1, " !!", "Execute last command again\n"}, 270 271 {0, "\nNamespace Access Commands:", "\n"}, 272 {1, " Businfo", "Display system bus info\n"}, 273 {1, " Disassemble <Method>", "Disassemble a control method\n"}, 274 {1, " Find <AcpiName> (? is wildcard)", "Find ACPI name(s) with wildcards\n"}, 275 {1, " Integrity", "Validate namespace integrity\n"}, 276 {1, " Methods", "Display list of loaded control methods\n"}, 277 {1, " Namespace [Object] [Depth]", "Display loaded namespace tree/subtree\n"}, 278 {1, " Notify <Object> <Value>", "Send a notification on Object\n"}, 279 {1, " Objects [ObjectType]", "Display summary of all objects or just given type\n"}, 280 {1, " Owner <OwnerId> [Depth]", "Display loaded namespace by object owner\n"}, 281 {1, " Paths", "Display full pathnames of namespace objects\n"}, 282 {1, " Predefined", "Check all predefined names\n"}, 283 {1, " Prefix [<Namepath>]", "Set or Get current execution prefix\n"}, 284 {1, " References <Addr>", "Find all references to object at addr\n"}, 285 {1, " Resources [DeviceName]", "Display Device resources (no arg = all devices)\n"}, 286 {1, " Set N <NamedObject> <Value>", "Set value for named integer\n"}, 287 {1, " Template <Object>", "Format/dump a Buffer/ResourceTemplate\n"}, 288 {1, " Type <Object>", "Display object type\n"}, 289 290 {0, "\nControl Method Execution Commands:","\n"}, 291 {1, " Arguments (or Args)", "Display method arguments\n"}, 292 {1, " Breakpoint <AmlOffset>", "Set an AML execution breakpoint\n"}, 293 {1, " Call", "Run to next control method invocation\n"}, 294 {1, " Debug <Namepath> [Arguments]", "Single Step a control method\n"}, 295 {6, " Evaluate", "Synonym for Execute\n"}, 296 {5, " Execute <Namepath> [Arguments]", "Execute control method\n"}, 297 {1, " Hex Integer", "Integer method argument\n"}, 298 {1, " \"Ascii String\"", "String method argument\n"}, 299 {1, " (Hex Byte List)", "Buffer method argument\n"}, 300 {1, " [Package Element List]", "Package method argument\n"}, 301 {5, " Execute predefined", "Execute all predefined (public) methods\n"}, 302 {1, " Go", "Allow method to run to completion\n"}, 303 {1, " Information", "Display info about the current method\n"}, 304 {1, " Into", "Step into (not over) a method call\n"}, 305 {1, " List [# of Aml Opcodes]", "Display method ASL statements\n"}, 306 {1, " Locals", "Display method local variables\n"}, 307 {1, " Results", "Display method result stack\n"}, 308 {1, " Set <A|L> <#> <Value>", "Set method data (Arguments/Locals)\n"}, 309 {1, " Stop", "Terminate control method\n"}, 310 {5, " Trace <State> [<Namepath>] [Once]", "Trace control method execution\n"}, 311 {1, " Enable", "Enable all messages\n"}, 312 {1, " Disable", "Disable tracing\n"}, 313 {1, " Method", "Enable method execution messages\n"}, 314 {1, " Opcode", "Enable opcode execution messages\n"}, 315 {1, " Tree", "Display control method calling tree\n"}, 316 {1, " <Enter>", "Single step next AML opcode (over calls)\n"}, 317 318 #ifdef ACPI_APPLICATION 319 {0, "\nHardware Simulation Commands:", "\n"}, 320 {1, " EnableAcpi", "Enable ACPI (hardware) mode\n"}, 321 {1, " Event <F|G> <Value>", "Generate AcpiEvent (Fixed/GPE)\n"}, 322 {1, " Gpe <GpeNum> [GpeBlockDevice]", "Simulate a GPE\n"}, 323 {1, " Gpes", "Display info on all GPE devices\n"}, 324 {1, " Sci", "Generate an SCI\n"}, 325 {1, " Sleep [SleepState]", "Simulate sleep/wake sequence(s) (0-5)\n"}, 326 327 {0, "\nFile I/O Commands:", "\n"}, 328 {1, " Close", "Close debug output file\n"}, 329 {1, " Load <Input Filename>", "Load ACPI table from a file\n"}, 330 {1, " Open <Output Filename>", "Open a file for debug output\n"}, 331 {1, " Unload <Namepath>", "Unload an ACPI table via namespace object\n"}, 332 333 {0, "\nUser Space Commands:", "\n"}, 334 {1, " Terminate", "Delete namespace and all internal objects\n"}, 335 {1, " Thread <Threads><Loops><NamePath>", "Spawn threads to execute method(s)\n"}, 336 337 {0, "\nDebug Test Commands:", "\n"}, 338 {3, " Test <TestName>", "Invoke a debug test\n"}, 339 {1, " Objects", "Read/write/compare all namespace data objects\n"}, 340 {1, " Predefined", "Execute all ACPI predefined names (_STA, etc.)\n"}, 341 #endif 342 {0, NULL, NULL} 343 }; 344 345 346 /******************************************************************************* 347 * 348 * FUNCTION: AcpiDbMatchCommandHelp 349 * 350 * PARAMETERS: Command - Command string to match 351 * Help - Help table entry to attempt match 352 * 353 * RETURN: TRUE if command matched, FALSE otherwise 354 * 355 * DESCRIPTION: Attempt to match a command in the help table in order to 356 * print help information for a single command. 357 * 358 ******************************************************************************/ 359 360 static BOOLEAN 361 AcpiDbMatchCommandHelp ( 362 const char *Command, 363 const ACPI_DB_COMMAND_HELP *Help) 364 { 365 char *Invocation = Help->Invocation; 366 UINT32 LineCount; 367 368 369 /* Valid commands in the help table begin with a couple of spaces */ 370 371 if (*Invocation != ' ') 372 { 373 return (FALSE); 374 } 375 376 while (*Invocation == ' ') 377 { 378 Invocation++; 379 } 380 381 /* Match command name (full command or substring) */ 382 383 while ((*Command) && (*Invocation) && (*Invocation != ' ')) 384 { 385 if (tolower ((int) *Command) != tolower ((int) *Invocation)) 386 { 387 return (FALSE); 388 } 389 390 Invocation++; 391 Command++; 392 } 393 394 /* Print the appropriate number of help lines */ 395 396 LineCount = Help->LineCount; 397 while (LineCount) 398 { 399 AcpiOsPrintf ("%-38s : %s", Help->Invocation, Help->Description); 400 Help++; 401 LineCount--; 402 } 403 404 return (TRUE); 405 } 406 407 408 /******************************************************************************* 409 * 410 * FUNCTION: AcpiDbDisplayCommandInfo 411 * 412 * PARAMETERS: Command - Command string to match 413 * DisplayAll - Display all matching commands, or just 414 * the first one (substring match) 415 * 416 * RETURN: None 417 * 418 * DESCRIPTION: Display help information for a Debugger command. 419 * 420 ******************************************************************************/ 421 422 static void 423 AcpiDbDisplayCommandInfo ( 424 const char *Command, 425 BOOLEAN DisplayAll) 426 { 427 const ACPI_DB_COMMAND_HELP *Next; 428 BOOLEAN Matched; 429 430 431 Next = AcpiGbl_DbCommandHelp; 432 while (Next->Invocation) 433 { 434 Matched = AcpiDbMatchCommandHelp (Command, Next); 435 if (!DisplayAll && Matched) 436 { 437 return; 438 } 439 440 Next++; 441 } 442 } 443 444 445 /******************************************************************************* 446 * 447 * FUNCTION: AcpiDbDisplayHelp 448 * 449 * PARAMETERS: Command - Optional command string to display help. 450 * if not specified, all debugger command 451 * help strings are displayed 452 * 453 * RETURN: None 454 * 455 * DESCRIPTION: Display help for a single debugger command, or all of them. 456 * 457 ******************************************************************************/ 458 459 static void 460 AcpiDbDisplayHelp ( 461 char *Command) 462 { 463 const ACPI_DB_COMMAND_HELP *Next = AcpiGbl_DbCommandHelp; 464 465 466 if (!Command) 467 { 468 /* No argument to help, display help for all commands */ 469 470 while (Next->Invocation) 471 { 472 AcpiOsPrintf ("%-38s%s", Next->Invocation, Next->Description); 473 Next++; 474 } 475 } 476 else 477 { 478 /* Display help for all commands that match the subtring */ 479 480 AcpiDbDisplayCommandInfo (Command, TRUE); 481 } 482 } 483 484 485 /******************************************************************************* 486 * 487 * FUNCTION: AcpiDbGetNextToken 488 * 489 * PARAMETERS: String - Command buffer 490 * Next - Return value, end of next token 491 * 492 * RETURN: Pointer to the start of the next token. 493 * 494 * DESCRIPTION: Command line parsing. Get the next token on the command line 495 * 496 ******************************************************************************/ 497 498 char * 499 AcpiDbGetNextToken ( 500 char *String, 501 char **Next, 502 ACPI_OBJECT_TYPE *ReturnType) 503 { 504 char *Start; 505 UINT32 Depth; 506 ACPI_OBJECT_TYPE Type = ACPI_TYPE_INTEGER; 507 508 509 /* At end of buffer? */ 510 511 if (!String || !(*String)) 512 { 513 return (NULL); 514 } 515 516 /* Remove any spaces at the beginning */ 517 518 if (*String == ' ') 519 { 520 while (*String && (*String == ' ')) 521 { 522 String++; 523 } 524 525 if (!(*String)) 526 { 527 return (NULL); 528 } 529 } 530 531 switch (*String) 532 { 533 case '"': 534 535 /* This is a quoted string, scan until closing quote */ 536 537 String++; 538 Start = String; 539 Type = ACPI_TYPE_STRING; 540 541 /* Find end of string */ 542 543 while (*String && (*String != '"')) 544 { 545 String++; 546 } 547 break; 548 549 case '(': 550 551 /* This is the start of a buffer, scan until closing paren */ 552 553 String++; 554 Start = String; 555 Type = ACPI_TYPE_BUFFER; 556 557 /* Find end of buffer */ 558 559 while (*String && (*String != ')')) 560 { 561 String++; 562 } 563 break; 564 565 case '[': 566 567 /* This is the start of a package, scan until closing bracket */ 568 569 String++; 570 Depth = 1; 571 Start = String; 572 Type = ACPI_TYPE_PACKAGE; 573 574 /* Find end of package (closing bracket) */ 575 576 while (*String) 577 { 578 /* Handle String package elements */ 579 580 if (*String == '"') 581 { 582 /* Find end of string */ 583 584 String++; 585 while (*String && (*String != '"')) 586 { 587 String++; 588 } 589 if (!(*String)) 590 { 591 break; 592 } 593 } 594 else if (*String == '[') 595 { 596 Depth++; /* A nested package declaration */ 597 } 598 else if (*String == ']') 599 { 600 Depth--; 601 if (Depth == 0) /* Found final package closing bracket */ 602 { 603 break; 604 } 605 } 606 607 String++; 608 } 609 break; 610 611 default: 612 613 Start = String; 614 615 /* Find end of token */ 616 617 while (*String && (*String != ' ')) 618 { 619 String++; 620 } 621 break; 622 } 623 624 if (!(*String)) 625 { 626 *Next = NULL; 627 } 628 else 629 { 630 *String = 0; 631 *Next = String + 1; 632 } 633 634 *ReturnType = Type; 635 return (Start); 636 } 637 638 639 /******************************************************************************* 640 * 641 * FUNCTION: AcpiDbGetLine 642 * 643 * PARAMETERS: InputBuffer - Command line buffer 644 * 645 * RETURN: Count of arguments to the command 646 * 647 * DESCRIPTION: Get the next command line from the user. Gets entire line 648 * up to the next newline 649 * 650 ******************************************************************************/ 651 652 static UINT32 653 AcpiDbGetLine ( 654 char *InputBuffer) 655 { 656 UINT32 i; 657 UINT32 Count; 658 char *Next; 659 char *This; 660 661 662 if (AcpiUtSafeStrcpy (AcpiGbl_DbParsedBuf, sizeof (AcpiGbl_DbParsedBuf), 663 InputBuffer)) 664 { 665 AcpiOsPrintf ( 666 "Buffer overflow while parsing input line (max %u characters)\n", 667 sizeof (AcpiGbl_DbParsedBuf)); 668 return (0); 669 } 670 671 This = AcpiGbl_DbParsedBuf; 672 for (i = 0; i < ACPI_DEBUGGER_MAX_ARGS; i++) 673 { 674 AcpiGbl_DbArgs[i] = AcpiDbGetNextToken (This, &Next, 675 &AcpiGbl_DbArgTypes[i]); 676 if (!AcpiGbl_DbArgs[i]) 677 { 678 break; 679 } 680 681 This = Next; 682 } 683 684 /* Uppercase the actual command */ 685 686 AcpiUtStrupr (AcpiGbl_DbArgs[0]); 687 688 Count = i; 689 if (Count) 690 { 691 Count--; /* Number of args only */ 692 } 693 694 return (Count); 695 } 696 697 698 /******************************************************************************* 699 * 700 * FUNCTION: AcpiDbMatchCommand 701 * 702 * PARAMETERS: UserCommand - User command line 703 * 704 * RETURN: Index into command array, -1 if not found 705 * 706 * DESCRIPTION: Search command array for a command match 707 * 708 ******************************************************************************/ 709 710 static UINT32 711 AcpiDbMatchCommand ( 712 char *UserCommand) 713 { 714 UINT32 i; 715 716 717 if (!UserCommand || UserCommand[0] == 0) 718 { 719 return (CMD_NULL); 720 } 721 722 for (i = CMD_FIRST_VALID; AcpiGbl_DbCommands[i].Name; i++) 723 { 724 if (strstr ( 725 ACPI_CAST_PTR (char, 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 = AcGetAllTablesFromFile (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