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 - 2019, 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 #ifdef ACPI_DISASSEMBLER 975 (void) AcpiDbDisassembleMethod (AcpiGbl_DbArgs[1]); 976 #else 977 AcpiOsPrintf ("The AML Disassembler is not configured/present\n"); 978 #endif 979 break; 980 981 case CMD_DUMP: 982 983 AcpiDbDecodeAndDisplayObject (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]); 984 break; 985 986 case CMD_EVALUATE: 987 case CMD_EXECUTE: 988 989 AcpiDbExecute (AcpiGbl_DbArgs[1], 990 &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_NO_SINGLE_STEP); 991 break; 992 993 case CMD_FIND: 994 995 Status = AcpiDbFindNameInNamespace (AcpiGbl_DbArgs[1]); 996 break; 997 998 case CMD_GO: 999 1000 AcpiGbl_CmSingleStep = FALSE; 1001 return (AE_OK); 1002 1003 case CMD_HANDLERS: 1004 1005 AcpiDbDisplayHandlers (); 1006 break; 1007 1008 case CMD_HELP: 1009 case CMD_HELP2: 1010 1011 AcpiDbDisplayHelp (AcpiGbl_DbArgs[1]); 1012 break; 1013 1014 case CMD_HISTORY: 1015 1016 AcpiDbDisplayHistory (); 1017 break; 1018 1019 case CMD_HISTORY_EXE: /* ! command */ 1020 1021 CommandLine = AcpiDbGetFromHistory (AcpiGbl_DbArgs[1]); 1022 if (!CommandLine) 1023 { 1024 return (AE_CTRL_TRUE); 1025 } 1026 1027 Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op); 1028 return (Status); 1029 1030 case CMD_HISTORY_LAST: /* !! command */ 1031 1032 CommandLine = AcpiDbGetFromHistory (NULL); 1033 if (!CommandLine) 1034 { 1035 return (AE_CTRL_TRUE); 1036 } 1037 1038 Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op); 1039 return (Status); 1040 1041 case CMD_INFORMATION: 1042 1043 AcpiDbDisplayMethodInfo (Op); 1044 break; 1045 1046 case CMD_INTEGRITY: 1047 1048 AcpiDbCheckIntegrity (); 1049 break; 1050 1051 case CMD_INTO: 1052 1053 if (Op) 1054 { 1055 AcpiGbl_CmSingleStep = TRUE; 1056 return (AE_OK); 1057 } 1058 break; 1059 1060 case CMD_LEVEL: 1061 1062 if (ParamCount == 0) 1063 { 1064 AcpiOsPrintf ( 1065 "Current debug level for file output is: %8.8lX\n", 1066 AcpiGbl_DbDebugLevel); 1067 AcpiOsPrintf ( 1068 "Current debug level for console output is: %8.8lX\n", 1069 AcpiGbl_DbConsoleDebugLevel); 1070 } 1071 else if (ParamCount == 2) 1072 { 1073 Temp = AcpiGbl_DbConsoleDebugLevel; 1074 AcpiGbl_DbConsoleDebugLevel = 1075 strtoul (AcpiGbl_DbArgs[1], NULL, 16); 1076 AcpiOsPrintf ( 1077 "Debug Level for console output was %8.8lX, now %8.8lX\n", 1078 Temp, AcpiGbl_DbConsoleDebugLevel); 1079 } 1080 else 1081 { 1082 Temp = AcpiGbl_DbDebugLevel; 1083 AcpiGbl_DbDebugLevel = strtoul (AcpiGbl_DbArgs[1], NULL, 16); 1084 AcpiOsPrintf ( 1085 "Debug Level for file output was %8.8lX, now %8.8lX\n", 1086 Temp, AcpiGbl_DbDebugLevel); 1087 } 1088 break; 1089 1090 case CMD_LIST: 1091 1092 #ifdef ACPI_DISASSEMBLER 1093 AcpiDbDisassembleAml (AcpiGbl_DbArgs[1], Op); 1094 #else 1095 AcpiOsPrintf ("The AML Disassembler is not configured/present\n"); 1096 #endif 1097 break; 1098 1099 case CMD_LOCKS: 1100 1101 AcpiDbDisplayLocks (); 1102 break; 1103 1104 case CMD_LOCALS: 1105 1106 AcpiDbDisplayLocals (); 1107 break; 1108 1109 case CMD_METHODS: 1110 1111 Status = AcpiDbDisplayObjects ("METHOD", AcpiGbl_DbArgs[1]); 1112 break; 1113 1114 case CMD_NAMESPACE: 1115 1116 AcpiDbDumpNamespace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]); 1117 break; 1118 1119 case CMD_NOTIFY: 1120 1121 Temp = strtoul (AcpiGbl_DbArgs[2], NULL, 0); 1122 AcpiDbSendNotify (AcpiGbl_DbArgs[1], Temp); 1123 break; 1124 1125 case CMD_OBJECTS: 1126 1127 AcpiUtStrupr (AcpiGbl_DbArgs[1]); 1128 Status = AcpiDbDisplayObjects (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]); 1129 break; 1130 1131 case CMD_OSI: 1132 1133 AcpiDbDisplayInterfaces (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]); 1134 break; 1135 1136 case CMD_OWNER: 1137 1138 AcpiDbDumpNamespaceByOwner (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]); 1139 break; 1140 1141 case CMD_PATHS: 1142 1143 AcpiDbDumpNamespacePaths (); 1144 break; 1145 1146 case CMD_PREFIX: 1147 1148 AcpiDbSetScope (AcpiGbl_DbArgs[1]); 1149 break; 1150 1151 case CMD_REFERENCES: 1152 1153 AcpiDbFindReferences (AcpiGbl_DbArgs[1]); 1154 break; 1155 1156 case CMD_RESOURCES: 1157 1158 AcpiDbDisplayResources (AcpiGbl_DbArgs[1]); 1159 break; 1160 1161 case CMD_RESULTS: 1162 1163 AcpiDbDisplayResults (); 1164 break; 1165 1166 case CMD_SET: 1167 1168 AcpiDbSetMethodData (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], 1169 AcpiGbl_DbArgs[3]); 1170 break; 1171 1172 case CMD_STATS: 1173 1174 Status = AcpiDbDisplayStatistics (AcpiGbl_DbArgs[1]); 1175 break; 1176 1177 case CMD_STOP: 1178 1179 return (AE_NOT_IMPLEMENTED); 1180 1181 case CMD_TABLES: 1182 1183 AcpiDbDisplayTableInfo (AcpiGbl_DbArgs[1]); 1184 break; 1185 1186 case CMD_TEMPLATE: 1187 1188 AcpiDbDisplayTemplate (AcpiGbl_DbArgs[1]); 1189 break; 1190 1191 case CMD_TRACE: 1192 1193 AcpiDbTrace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], AcpiGbl_DbArgs[3]); 1194 break; 1195 1196 case CMD_TREE: 1197 1198 AcpiDbDisplayCallingTree (); 1199 break; 1200 1201 case CMD_TYPE: 1202 1203 AcpiDbDisplayObjectType (AcpiGbl_DbArgs[1]); 1204 break; 1205 1206 #ifdef ACPI_APPLICATION 1207 1208 /* Hardware simulation commands. */ 1209 1210 case CMD_ENABLEACPI: 1211 #if (!ACPI_REDUCED_HARDWARE) 1212 1213 Status = AcpiEnable(); 1214 if (ACPI_FAILURE(Status)) 1215 { 1216 AcpiOsPrintf("AcpiEnable failed (Status=%X)\n", Status); 1217 return (Status); 1218 } 1219 #endif /* !ACPI_REDUCED_HARDWARE */ 1220 break; 1221 1222 case CMD_EVENT: 1223 1224 AcpiOsPrintf ("Event command not implemented\n"); 1225 break; 1226 1227 case CMD_GPE: 1228 1229 AcpiDbGenerateGpe (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]); 1230 break; 1231 1232 case CMD_GPES: 1233 1234 AcpiDbDisplayGpes (); 1235 break; 1236 1237 case CMD_SCI: 1238 1239 AcpiDbGenerateSci (); 1240 break; 1241 1242 case CMD_SLEEP: 1243 1244 Status = AcpiDbSleep (AcpiGbl_DbArgs[1]); 1245 break; 1246 1247 /* File I/O commands. */ 1248 1249 case CMD_CLOSE: 1250 1251 AcpiDbCloseDebugFile (); 1252 break; 1253 1254 case CMD_LOAD: 1255 { 1256 ACPI_NEW_TABLE_DESC *ListHead = NULL; 1257 1258 Status = AcGetAllTablesFromFile (AcpiGbl_DbArgs[1], 1259 ACPI_GET_ALL_TABLES, &ListHead); 1260 if (ACPI_SUCCESS (Status)) 1261 { 1262 AcpiDbLoadTables (ListHead); 1263 } 1264 } 1265 break; 1266 1267 case CMD_OPEN: 1268 1269 AcpiDbOpenDebugFile (AcpiGbl_DbArgs[1]); 1270 break; 1271 1272 /* User space commands. */ 1273 1274 case CMD_TERMINATE: 1275 1276 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT); 1277 AcpiUtSubsystemShutdown (); 1278 1279 /* 1280 * TBD: [Restructure] Need some way to re-initialize without 1281 * re-creating the semaphores! 1282 */ 1283 1284 AcpiGbl_DbTerminateLoop = TRUE; 1285 /* AcpiInitialize (NULL); */ 1286 break; 1287 1288 case CMD_BACKGROUND: 1289 1290 AcpiDbCreateExecutionThread (AcpiGbl_DbArgs[1], &AcpiGbl_DbArgs[2], 1291 &AcpiGbl_DbArgTypes[2]); 1292 break; 1293 1294 case CMD_THREADS: 1295 1296 AcpiDbCreateExecutionThreads (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], 1297 AcpiGbl_DbArgs[3]); 1298 break; 1299 1300 /* Debug test commands. */ 1301 1302 case CMD_PREDEFINED: 1303 1304 AcpiDbCheckPredefinedNames (); 1305 break; 1306 1307 case CMD_TEST: 1308 1309 AcpiDbExecuteTest (AcpiGbl_DbArgs[1]); 1310 break; 1311 1312 case CMD_UNLOAD: 1313 1314 AcpiDbUnloadAcpiTable (AcpiGbl_DbArgs[1]); 1315 break; 1316 #endif 1317 1318 case CMD_EXIT: 1319 case CMD_QUIT: 1320 1321 if (Op) 1322 { 1323 AcpiOsPrintf ("Method execution terminated\n"); 1324 return (AE_CTRL_TERMINATE); 1325 } 1326 1327 if (!AcpiGbl_DbOutputToFile) 1328 { 1329 AcpiDbgLevel = ACPI_DEBUG_DEFAULT; 1330 } 1331 1332 #ifdef ACPI_APPLICATION 1333 AcpiDbCloseDebugFile (); 1334 #endif 1335 AcpiGbl_DbTerminateLoop = TRUE; 1336 return (AE_CTRL_TERMINATE); 1337 1338 case CMD_NOT_FOUND: 1339 default: 1340 1341 AcpiOsPrintf ("%s: unknown command\n", AcpiGbl_DbArgs[0]); 1342 return (AE_CTRL_TRUE); 1343 } 1344 1345 if (ACPI_SUCCESS (Status)) 1346 { 1347 Status = AE_CTRL_TRUE; 1348 } 1349 1350 return (Status); 1351 } 1352 1353 1354 /******************************************************************************* 1355 * 1356 * FUNCTION: AcpiDbExecuteThread 1357 * 1358 * PARAMETERS: Context - Not used 1359 * 1360 * RETURN: None 1361 * 1362 * DESCRIPTION: Debugger execute thread. Waits for a command line, then 1363 * simply dispatches it. 1364 * 1365 ******************************************************************************/ 1366 1367 void ACPI_SYSTEM_XFACE 1368 AcpiDbExecuteThread ( 1369 void *Context) 1370 { 1371 1372 (void) AcpiDbUserCommands (); 1373 AcpiGbl_DbThreadsTerminated = TRUE; 1374 } 1375 1376 1377 /******************************************************************************* 1378 * 1379 * FUNCTION: AcpiDbUserCommands 1380 * 1381 * PARAMETERS: None 1382 * 1383 * RETURN: None 1384 * 1385 * DESCRIPTION: Command line execution for the AML debugger. Commands are 1386 * matched and dispatched here. 1387 * 1388 ******************************************************************************/ 1389 1390 ACPI_STATUS 1391 AcpiDbUserCommands ( 1392 void) 1393 { 1394 ACPI_STATUS Status = AE_OK; 1395 1396 1397 AcpiOsPrintf ("\n"); 1398 1399 /* TBD: [Restructure] Need a separate command line buffer for step mode */ 1400 1401 while (!AcpiGbl_DbTerminateLoop) 1402 { 1403 /* Wait the readiness of the command */ 1404 1405 Status = AcpiOsWaitCommandReady (); 1406 if (ACPI_FAILURE (Status)) 1407 { 1408 break; 1409 } 1410 1411 /* Just call to the command line interpreter */ 1412 1413 AcpiGbl_MethodExecuting = FALSE; 1414 AcpiGbl_StepToNextCall = FALSE; 1415 1416 (void) AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL); 1417 1418 /* Notify the completion of the command */ 1419 1420 Status = AcpiOsNotifyCommandComplete (); 1421 if (ACPI_FAILURE (Status)) 1422 { 1423 break; 1424 } 1425 } 1426 1427 if (ACPI_FAILURE (Status) && Status != AE_CTRL_TERMINATE) 1428 { 1429 ACPI_EXCEPTION ((AE_INFO, Status, "While parsing command line")); 1430 } 1431 return (Status); 1432 } 1433 1434 #endif /* ACPI_DEBUGGER */ 1435