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