1 /******************************************************************************* 2 * 3 * Module Name: dmwalk - AML disassembly tree walk 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 "acparser.h" 155 #include "amlcode.h" 156 #include "acdebug.h" 157 #include "acconvert.h" 158 159 160 #ifdef ACPI_DISASSEMBLER 161 162 #define _COMPONENT ACPI_CA_DEBUGGER 163 ACPI_MODULE_NAME ("dmwalk") 164 165 166 /* Stub for non-compiler code */ 167 168 #ifndef ACPI_ASL_COMPILER 169 void 170 AcpiDmEmitExternals ( 171 void) 172 { 173 return; 174 } 175 176 void 177 AcpiDmEmitExternal ( 178 ACPI_PARSE_OBJECT *NameOp, 179 ACPI_PARSE_OBJECT *TypeOp) 180 { 181 return; 182 } 183 #endif 184 185 /* Local prototypes */ 186 187 static ACPI_STATUS 188 AcpiDmDescendingOp ( 189 ACPI_PARSE_OBJECT *Op, 190 UINT32 Level, 191 void *Context); 192 193 static ACPI_STATUS 194 AcpiDmAscendingOp ( 195 ACPI_PARSE_OBJECT *Op, 196 UINT32 Level, 197 void *Context); 198 199 200 /******************************************************************************* 201 * 202 * FUNCTION: AcpiDmDisassemble 203 * 204 * PARAMETERS: WalkState - Current state 205 * Origin - Starting object 206 * NumOpcodes - Max number of opcodes to be displayed 207 * 208 * RETURN: None 209 * 210 * DESCRIPTION: Disassemble parser object and its children. This is the 211 * main entry point of the disassembler. 212 * 213 ******************************************************************************/ 214 215 void 216 AcpiDmDisassemble ( 217 ACPI_WALK_STATE *WalkState, 218 ACPI_PARSE_OBJECT *Origin, 219 UINT32 NumOpcodes) 220 { 221 ACPI_PARSE_OBJECT *Op = Origin; 222 ACPI_OP_WALK_INFO Info; 223 224 225 if (!Op) 226 { 227 return; 228 } 229 230 memset (&Info, 0, sizeof (ACPI_OP_WALK_INFO)); 231 Info.WalkState = WalkState; 232 Info.StartAml = Op->Common.Aml - sizeof (ACPI_TABLE_HEADER); 233 Info.AmlOffset = Op->Common.Aml - Info.StartAml; 234 235 AcpiDmWalkParseTree (Op, AcpiDmDescendingOp, AcpiDmAscendingOp, &Info); 236 return; 237 } 238 239 240 /******************************************************************************* 241 * 242 * FUNCTION: AcpiDmWalkParseTree 243 * 244 * PARAMETERS: Op - Root Op object 245 * DescendingCallback - Called during tree descent 246 * AscendingCallback - Called during tree ascent 247 * Context - To be passed to the callbacks 248 * 249 * RETURN: Status from callback(s) 250 * 251 * DESCRIPTION: Walk the entire parse tree. 252 * 253 ******************************************************************************/ 254 255 void 256 AcpiDmWalkParseTree ( 257 ACPI_PARSE_OBJECT *Op, 258 ASL_WALK_CALLBACK DescendingCallback, 259 ASL_WALK_CALLBACK AscendingCallback, 260 void *Context) 261 { 262 BOOLEAN NodePreviouslyVisited; 263 ACPI_PARSE_OBJECT *StartOp = Op; 264 ACPI_STATUS Status; 265 ACPI_PARSE_OBJECT *Next; 266 ACPI_OP_WALK_INFO *Info = Context; 267 268 269 Info->Level = 0; 270 NodePreviouslyVisited = FALSE; 271 272 while (Op) 273 { 274 if (NodePreviouslyVisited) 275 { 276 if (AscendingCallback) 277 { 278 Status = AscendingCallback (Op, Info->Level, Context); 279 if (ACPI_FAILURE (Status)) 280 { 281 return; 282 } 283 } 284 } 285 else 286 { 287 /* Let the callback process the node */ 288 289 Status = DescendingCallback (Op, Info->Level, Context); 290 if (ACPI_SUCCESS (Status)) 291 { 292 /* Visit children first, once */ 293 294 Next = AcpiPsGetArg (Op, 0); 295 if (Next) 296 { 297 Info->Level++; 298 Op = Next; 299 continue; 300 } 301 } 302 else if (Status != AE_CTRL_DEPTH) 303 { 304 /* Exit immediately on any error */ 305 306 return; 307 } 308 } 309 310 /* Terminate walk at start op */ 311 312 if (Op == StartOp) 313 { 314 break; 315 } 316 317 /* No more children, re-visit this node */ 318 319 if (!NodePreviouslyVisited) 320 { 321 NodePreviouslyVisited = TRUE; 322 continue; 323 } 324 325 /* No more children, visit peers */ 326 327 if (Op->Common.Next) 328 { 329 Op = Op->Common.Next; 330 NodePreviouslyVisited = FALSE; 331 } 332 else 333 { 334 /* No peers, re-visit parent */ 335 336 if (Info->Level != 0 ) 337 { 338 Info->Level--; 339 } 340 341 Op = Op->Common.Parent; 342 NodePreviouslyVisited = TRUE; 343 } 344 } 345 346 /* If we get here, the walk completed with no errors */ 347 348 return; 349 } 350 351 352 /******************************************************************************* 353 * 354 * FUNCTION: AcpiDmBlockType 355 * 356 * PARAMETERS: Op - Object to be examined 357 * 358 * RETURN: BlockType - not a block, parens, braces, or even both. 359 * 360 * DESCRIPTION: Type of block for this op (parens or braces) 361 * 362 ******************************************************************************/ 363 364 UINT32 365 AcpiDmBlockType ( 366 ACPI_PARSE_OBJECT *Op) 367 { 368 const ACPI_OPCODE_INFO *OpInfo; 369 370 371 if (!Op) 372 { 373 return (BLOCK_NONE); 374 } 375 376 switch (Op->Common.AmlOpcode) 377 { 378 case AML_ELSE_OP: 379 380 return (BLOCK_BRACE); 381 382 case AML_METHOD_OP: 383 case AML_DEVICE_OP: 384 case AML_SCOPE_OP: 385 case AML_PROCESSOR_OP: 386 case AML_POWER_RESOURCE_OP: 387 case AML_THERMAL_ZONE_OP: 388 case AML_IF_OP: 389 case AML_WHILE_OP: 390 case AML_FIELD_OP: 391 case AML_INDEX_FIELD_OP: 392 case AML_BANK_FIELD_OP: 393 394 return (BLOCK_PAREN | BLOCK_BRACE); 395 396 case AML_BUFFER_OP: 397 398 if ((Op->Common.DisasmOpcode == ACPI_DASM_UNICODE) || 399 (Op->Common.DisasmOpcode == ACPI_DASM_UUID) || 400 (Op->Common.DisasmOpcode == ACPI_DASM_PLD_METHOD)) 401 { 402 return (BLOCK_NONE); 403 } 404 405 /*lint -fallthrough */ 406 407 case AML_PACKAGE_OP: 408 case AML_VARIABLE_PACKAGE_OP: 409 410 return (BLOCK_PAREN | BLOCK_BRACE); 411 412 case AML_EVENT_OP: 413 414 return (BLOCK_PAREN); 415 416 case AML_INT_METHODCALL_OP: 417 418 if (Op->Common.Parent && 419 ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) || 420 (Op->Common.Parent->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP))) 421 { 422 /* This is a reference to a method, not an invocation */ 423 424 return (BLOCK_NONE); 425 } 426 427 /*lint -fallthrough */ 428 429 default: 430 431 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode); 432 if (OpInfo->Flags & AML_HAS_ARGS) 433 { 434 return (BLOCK_PAREN); 435 } 436 437 return (BLOCK_NONE); 438 } 439 } 440 441 442 /******************************************************************************* 443 * 444 * FUNCTION: AcpiDmListType 445 * 446 * PARAMETERS: Op - Object to be examined 447 * 448 * RETURN: ListType - has commas or not. 449 * 450 * DESCRIPTION: Type of block for this op (parens or braces) 451 * 452 ******************************************************************************/ 453 454 UINT32 455 AcpiDmListType ( 456 ACPI_PARSE_OBJECT *Op) 457 { 458 const ACPI_OPCODE_INFO *OpInfo; 459 460 461 if (!Op) 462 { 463 return (BLOCK_NONE); 464 } 465 466 switch (Op->Common.AmlOpcode) 467 { 468 469 case AML_ELSE_OP: 470 case AML_METHOD_OP: 471 case AML_DEVICE_OP: 472 case AML_SCOPE_OP: 473 case AML_POWER_RESOURCE_OP: 474 case AML_PROCESSOR_OP: 475 case AML_THERMAL_ZONE_OP: 476 case AML_IF_OP: 477 case AML_WHILE_OP: 478 case AML_FIELD_OP: 479 case AML_INDEX_FIELD_OP: 480 case AML_BANK_FIELD_OP: 481 482 return (BLOCK_NONE); 483 484 case AML_BUFFER_OP: 485 case AML_PACKAGE_OP: 486 case AML_VARIABLE_PACKAGE_OP: 487 488 return (BLOCK_COMMA_LIST); 489 490 default: 491 492 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode); 493 if (OpInfo->Flags & AML_HAS_ARGS) 494 { 495 return (BLOCK_COMMA_LIST); 496 } 497 498 return (BLOCK_NONE); 499 } 500 } 501 502 503 /******************************************************************************* 504 * 505 * FUNCTION: AcpiDmDescendingOp 506 * 507 * PARAMETERS: ASL_WALK_CALLBACK 508 * 509 * RETURN: Status 510 * 511 * DESCRIPTION: First visitation of a parse object during tree descent. 512 * Decode opcode name and begin parameter list(s), if any. 513 * 514 ******************************************************************************/ 515 516 static ACPI_STATUS 517 AcpiDmDescendingOp ( 518 ACPI_PARSE_OBJECT *Op, 519 UINT32 Level, 520 void *Context) 521 { 522 ACPI_OP_WALK_INFO *Info = Context; 523 const ACPI_OPCODE_INFO *OpInfo; 524 UINT32 Name; 525 ACPI_PARSE_OBJECT *NextOp; 526 ACPI_PARSE_OBJECT *NextOp2; 527 UINT32 AmlOffset; 528 529 530 /* Determine which file this parse node is contained in. */ 531 532 if (AcpiGbl_CaptureComments) 533 { 534 ASL_CV_LABEL_FILENODE (Op); 535 536 if (Level != 0 && ASL_CV_FILE_HAS_SWITCHED (Op)) 537 { 538 ASL_CV_SWITCH_FILES (Level, Op); 539 } 540 541 /* If this parse node has regular comments, print them here. */ 542 543 ASL_CV_PRINT_ONE_COMMENT (Op, AML_COMMENT_STANDARD, NULL, Level); 544 } 545 546 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode); 547 548 /* Listing support to dump the AML code after the ASL statement */ 549 550 if (AcpiGbl_DmOpt_Listing) 551 { 552 /* We only care about these classes of objects */ 553 554 if ((OpInfo->Class == AML_CLASS_NAMED_OBJECT) || 555 (OpInfo->Class == AML_CLASS_CONTROL) || 556 (OpInfo->Class == AML_CLASS_CREATE) || 557 ((OpInfo->Class == AML_CLASS_EXECUTE) && (!Op->Common.Next))) 558 { 559 if (AcpiGbl_DmOpt_Listing && Info->PreviousAml) 560 { 561 /* Dump the AML byte code for the previous Op */ 562 563 if (Op->Common.Aml > Info->PreviousAml) 564 { 565 AcpiOsPrintf ("\n"); 566 AcpiUtDumpBuffer ( 567 (Info->StartAml + Info->AmlOffset), 568 (Op->Common.Aml - Info->PreviousAml), 569 DB_BYTE_DISPLAY, Info->AmlOffset); 570 AcpiOsPrintf ("\n"); 571 } 572 573 Info->AmlOffset = (Op->Common.Aml - Info->StartAml); 574 } 575 576 Info->PreviousAml = Op->Common.Aml; 577 } 578 } 579 580 if (Op->Common.DisasmFlags & ACPI_PARSEOP_IGNORE) 581 { 582 /* Ignore this op -- it was handled elsewhere */ 583 584 return (AE_CTRL_DEPTH); 585 } 586 587 if (Op->Common.DisasmOpcode == ACPI_DASM_IGNORE_SINGLE) 588 { 589 /* Ignore this op, but not it's children */ 590 591 return (AE_OK); 592 } 593 594 if (Op->Common.AmlOpcode == AML_IF_OP) 595 { 596 NextOp = AcpiPsGetDepthNext (NULL, Op); 597 if (NextOp) 598 { 599 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST; 600 601 /* Don't emit the actual embedded externals unless asked */ 602 603 if (!AcpiGbl_DmEmitExternalOpcodes) 604 { 605 /* 606 * A Zero predicate indicates the possibility of one or more 607 * External() opcodes within the If() block. 608 */ 609 if (NextOp->Common.AmlOpcode == AML_ZERO_OP) 610 { 611 NextOp2 = NextOp->Common.Next; 612 613 if (NextOp2 && 614 (NextOp2->Common.AmlOpcode == AML_EXTERNAL_OP)) 615 { 616 /* Ignore the If 0 block and all children */ 617 618 Op->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE; 619 return (AE_CTRL_DEPTH); 620 } 621 } 622 } 623 } 624 } 625 626 /* Level 0 is at the Definition Block level */ 627 628 if (Level == 0) 629 { 630 /* In verbose mode, print the AML offset, opcode and depth count */ 631 632 if (Info->WalkState) 633 { 634 AmlOffset = (UINT32) ACPI_PTR_DIFF (Op->Common.Aml, 635 Info->WalkState->ParserState.AmlStart); 636 if (AcpiGbl_DmOpt_Verbose) 637 { 638 if (AcpiGbl_CmSingleStep) 639 { 640 AcpiOsPrintf ("%5.5X/%4.4X: ", 641 AmlOffset, (UINT32) Op->Common.AmlOpcode); 642 } 643 else 644 { 645 AcpiOsPrintf ("AML Offset %5.5X, Opcode %4.4X: ", 646 AmlOffset, (UINT32) Op->Common.AmlOpcode); 647 } 648 } 649 } 650 651 if (Op->Common.AmlOpcode == AML_SCOPE_OP) 652 { 653 /* This is the beginning of the Definition Block */ 654 655 AcpiOsPrintf ("{\n"); 656 657 /* Emit all External() declarations here */ 658 659 if (!AcpiGbl_DmEmitExternalOpcodes) 660 { 661 AcpiDmEmitExternals (); 662 } 663 664 return (AE_OK); 665 } 666 } 667 else if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) && 668 (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST)) && 669 (!(Op->Common.DisasmFlags & ACPI_PARSEOP_ELSEIF)) && 670 (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP)) 671 { 672 /* 673 * This is a first-level element of a term list, 674 * indent a new line 675 */ 676 switch (Op->Common.AmlOpcode) 677 { 678 case AML_NOOP_OP: 679 /* 680 * Optionally just ignore this opcode. Some tables use 681 * NoOp opcodes for "padding" out packages that the BIOS 682 * changes dynamically. This can leave hundreds or 683 * thousands of NoOp opcodes that if disassembled, 684 * cannot be compiled because they are syntactically 685 * incorrect. 686 */ 687 if (AcpiGbl_IgnoreNoopOperator) 688 { 689 Op->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE; 690 return (AE_OK); 691 } 692 693 /* Fallthrough */ 694 695 default: 696 697 AcpiDmIndent (Level); 698 break; 699 } 700 701 Info->LastLevel = Level; 702 Info->Count = 0; 703 } 704 705 /* 706 * This is an inexpensive mechanism to try and keep lines from getting 707 * too long. When the limit is hit, start a new line at the previous 708 * indent plus one. A better but more expensive mechanism would be to 709 * keep track of the current column. 710 */ 711 Info->Count++; 712 if (Info->Count /* +Info->LastLevel */ > 12) 713 { 714 Info->Count = 0; 715 AcpiOsPrintf ("\n"); 716 AcpiDmIndent (Info->LastLevel + 1); 717 } 718 719 /* If ASL+ is enabled, check for a C-style operator */ 720 721 if (AcpiDmCheckForSymbolicOpcode (Op, Info)) 722 { 723 return (AE_OK); 724 } 725 726 /* Print the opcode name */ 727 728 AcpiDmDisassembleOneOp (NULL, Info, Op); 729 730 if ((Op->Common.DisasmOpcode == ACPI_DASM_LNOT_PREFIX) || 731 (Op->Common.AmlOpcode == AML_INT_CONNECTION_OP)) 732 { 733 return (AE_OK); 734 } 735 736 if ((Op->Common.AmlOpcode == AML_NAME_OP) || 737 (Op->Common.AmlOpcode == AML_RETURN_OP)) 738 { 739 Info->Level--; 740 } 741 742 if (Op->Common.AmlOpcode == AML_EXTERNAL_OP) 743 { 744 Op->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE; 745 return (AE_CTRL_DEPTH); 746 } 747 748 /* Start the opcode argument list if necessary */ 749 750 if ((OpInfo->Flags & AML_HAS_ARGS) || 751 (Op->Common.AmlOpcode == AML_EVENT_OP)) 752 { 753 /* This opcode has an argument list */ 754 755 if (AcpiDmBlockType (Op) & BLOCK_PAREN) 756 { 757 AcpiOsPrintf (" ("); 758 if (!(AcpiDmBlockType (Op) & BLOCK_BRACE)) 759 { 760 ASL_CV_PRINT_ONE_COMMENT (Op, AMLCOMMENT_INLINE, " ", 0); 761 } 762 } 763 764 /* If this is a named opcode, print the associated name value */ 765 766 if (OpInfo->Flags & AML_NAMED) 767 { 768 switch (Op->Common.AmlOpcode) 769 { 770 case AML_ALIAS_OP: 771 772 NextOp = AcpiPsGetDepthNext (NULL, Op); 773 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE; 774 AcpiDmNamestring (NextOp->Common.Value.Name); 775 AcpiOsPrintf (", "); 776 777 /*lint -fallthrough */ 778 779 default: 780 781 Name = AcpiPsGetName (Op); 782 if (Op->Named.Path) 783 { 784 AcpiDmNamestring (Op->Named.Path); 785 } 786 else 787 { 788 AcpiDmDumpName (Name); 789 } 790 791 if (Op->Common.AmlOpcode != AML_INT_NAMEDFIELD_OP) 792 { 793 if (AcpiGbl_DmOpt_Verbose) 794 { 795 (void) AcpiPsDisplayObjectPathname (NULL, Op); 796 } 797 } 798 break; 799 } 800 801 switch (Op->Common.AmlOpcode) 802 { 803 case AML_METHOD_OP: 804 805 AcpiDmMethodFlags (Op); 806 ASL_CV_CLOSE_PAREN (Op, Level); 807 808 /* Emit description comment for Method() with a predefined ACPI name */ 809 810 AcpiDmPredefinedDescription (Op); 811 break; 812 813 case AML_NAME_OP: 814 815 /* Check for _HID and related EISAID() */ 816 817 AcpiDmCheckForHardwareId (Op); 818 AcpiOsPrintf (", "); 819 ASL_CV_PRINT_ONE_COMMENT (Op, AML_NAMECOMMENT, NULL, 0); 820 break; 821 822 case AML_REGION_OP: 823 824 AcpiDmRegionFlags (Op); 825 break; 826 827 case AML_POWER_RESOURCE_OP: 828 829 /* Mark the next two Ops as part of the parameter list */ 830 831 AcpiOsPrintf (", "); 832 NextOp = AcpiPsGetDepthNext (NULL, Op); 833 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST; 834 835 NextOp = NextOp->Common.Next; 836 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST; 837 return (AE_OK); 838 839 case AML_PROCESSOR_OP: 840 841 /* Mark the next three Ops as part of the parameter list */ 842 843 AcpiOsPrintf (", "); 844 NextOp = AcpiPsGetDepthNext (NULL, Op); 845 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST; 846 847 NextOp = NextOp->Common.Next; 848 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST; 849 850 NextOp = NextOp->Common.Next; 851 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST; 852 return (AE_OK); 853 854 case AML_MUTEX_OP: 855 case AML_DATA_REGION_OP: 856 857 AcpiOsPrintf (", "); 858 return (AE_OK); 859 860 case AML_EVENT_OP: 861 case AML_ALIAS_OP: 862 863 return (AE_OK); 864 865 case AML_SCOPE_OP: 866 case AML_DEVICE_OP: 867 case AML_THERMAL_ZONE_OP: 868 869 ASL_CV_CLOSE_PAREN (Op, Level); 870 break; 871 872 default: 873 874 AcpiOsPrintf ("*** Unhandled named opcode %X\n", 875 Op->Common.AmlOpcode); 876 break; 877 } 878 } 879 880 else switch (Op->Common.AmlOpcode) 881 { 882 case AML_FIELD_OP: 883 case AML_BANK_FIELD_OP: 884 case AML_INDEX_FIELD_OP: 885 886 Info->BitOffset = 0; 887 888 /* Name of the parent OperationRegion */ 889 890 NextOp = AcpiPsGetDepthNext (NULL, Op); 891 AcpiDmNamestring (NextOp->Common.Value.Name); 892 AcpiOsPrintf (", "); 893 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE; 894 895 switch (Op->Common.AmlOpcode) 896 { 897 case AML_BANK_FIELD_OP: 898 899 /* Namestring - Bank Name */ 900 901 NextOp = AcpiPsGetDepthNext (NULL, NextOp); 902 AcpiDmNamestring (NextOp->Common.Value.Name); 903 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE; 904 AcpiOsPrintf (", "); 905 906 /* 907 * Bank Value. This is a TermArg in the middle of the parameter 908 * list, must handle it here. 909 * 910 * Disassemble the TermArg parse tree. ACPI_PARSEOP_PARAMETER_LIST 911 * eliminates newline in the output. 912 */ 913 NextOp = NextOp->Common.Next; 914 915 Info->Flags = ACPI_PARSEOP_PARAMETER_LIST; 916 AcpiDmWalkParseTree (NextOp, AcpiDmDescendingOp, 917 AcpiDmAscendingOp, Info); 918 Info->Flags = 0; 919 Info->Level = Level; 920 921 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE; 922 AcpiOsPrintf (", "); 923 break; 924 925 case AML_INDEX_FIELD_OP: 926 927 /* Namestring - Data Name */ 928 929 NextOp = AcpiPsGetDepthNext (NULL, NextOp); 930 AcpiDmNamestring (NextOp->Common.Value.Name); 931 AcpiOsPrintf (", "); 932 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE; 933 break; 934 935 default: 936 937 break; 938 } 939 940 AcpiDmFieldFlags (NextOp); 941 break; 942 943 case AML_BUFFER_OP: 944 945 /* The next op is the size parameter */ 946 947 NextOp = AcpiPsGetDepthNext (NULL, Op); 948 if (!NextOp) 949 { 950 /* Single-step support */ 951 952 return (AE_OK); 953 } 954 955 if (Op->Common.DisasmOpcode == ACPI_DASM_RESOURCE) 956 { 957 /* 958 * We have a resource list. Don't need to output 959 * the buffer size Op. Open up a new block 960 */ 961 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE; 962 NextOp = NextOp->Common.Next; 963 ASL_CV_CLOSE_PAREN (Op, Level); 964 965 /* Emit description comment for Name() with a predefined ACPI name */ 966 967 AcpiDmPredefinedDescription (Op->Asl.Parent); 968 969 AcpiOsPrintf ("\n"); 970 AcpiDmIndent (Info->Level); 971 AcpiOsPrintf ("{\n"); 972 return (AE_OK); 973 } 974 975 /* Normal Buffer, mark size as in the parameter list */ 976 977 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST; 978 return (AE_OK); 979 980 case AML_IF_OP: 981 case AML_VARIABLE_PACKAGE_OP: 982 case AML_WHILE_OP: 983 984 /* The next op is the size or predicate parameter */ 985 986 NextOp = AcpiPsGetDepthNext (NULL, Op); 987 if (NextOp) 988 { 989 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST; 990 } 991 return (AE_OK); 992 993 case AML_PACKAGE_OP: 994 995 /* The next op is the size parameter */ 996 997 NextOp = AcpiPsGetDepthNext (NULL, Op); 998 if (NextOp) 999 { 1000 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST; 1001 } 1002 return (AE_OK); 1003 1004 case AML_MATCH_OP: 1005 1006 AcpiDmMatchOp (Op); 1007 break; 1008 1009 default: 1010 1011 break; 1012 } 1013 1014 if (AcpiDmBlockType (Op) & BLOCK_BRACE) 1015 { 1016 AcpiOsPrintf ("\n"); 1017 AcpiDmIndent (Level); 1018 AcpiOsPrintf ("{\n"); 1019 } 1020 } 1021 1022 return (AE_OK); 1023 } 1024 1025 1026 /******************************************************************************* 1027 * 1028 * FUNCTION: AcpiDmAscendingOp 1029 * 1030 * PARAMETERS: ASL_WALK_CALLBACK 1031 * 1032 * RETURN: Status 1033 * 1034 * DESCRIPTION: Second visitation of a parse object, during ascent of parse 1035 * tree. Close out any parameter lists and complete the opcode. 1036 * 1037 ******************************************************************************/ 1038 1039 static ACPI_STATUS 1040 AcpiDmAscendingOp ( 1041 ACPI_PARSE_OBJECT *Op, 1042 UINT32 Level, 1043 void *Context) 1044 { 1045 ACPI_OP_WALK_INFO *Info = Context; 1046 ACPI_PARSE_OBJECT *ParentOp; 1047 1048 1049 /* Point the Op's filename pointer to the proper file */ 1050 1051 if (AcpiGbl_CaptureComments) 1052 { 1053 ASL_CV_LABEL_FILENODE (Op); 1054 1055 /* Switch the output of these files if necessary */ 1056 1057 if (ASL_CV_FILE_HAS_SWITCHED (Op)) 1058 { 1059 ASL_CV_SWITCH_FILES (Level, Op); 1060 } 1061 } 1062 1063 if (Op->Common.DisasmFlags & ACPI_PARSEOP_IGNORE || 1064 Op->Common.DisasmOpcode == ACPI_DASM_IGNORE_SINGLE) 1065 { 1066 /* Ignore this op -- it was handled elsewhere */ 1067 1068 return (AE_OK); 1069 } 1070 1071 if ((Level == 0) && (Op->Common.AmlOpcode == AML_SCOPE_OP)) 1072 { 1073 /* Indicates the end of the current descriptor block (table) */ 1074 1075 ASL_CV_CLOSE_BRACE (Op, Level); 1076 1077 /* Print any comments that are at the end of the file here */ 1078 1079 if (AcpiGbl_CaptureComments && AcpiGbl_LastListHead) 1080 { 1081 AcpiOsPrintf ("\n"); 1082 ASL_CV_PRINT_ONE_COMMENT_LIST (AcpiGbl_LastListHead, 0); 1083 } 1084 AcpiOsPrintf ("\n\n"); 1085 1086 return (AE_OK); 1087 } 1088 1089 switch (AcpiDmBlockType (Op)) 1090 { 1091 case BLOCK_PAREN: 1092 1093 /* Completed an op that has arguments, add closing paren if needed */ 1094 1095 AcpiDmCloseOperator (Op); 1096 1097 if (Op->Common.AmlOpcode == AML_NAME_OP) 1098 { 1099 /* Emit description comment for Name() with a predefined ACPI name */ 1100 1101 AcpiDmPredefinedDescription (Op); 1102 } 1103 else 1104 { 1105 /* For Create* operators, attempt to emit resource tag description */ 1106 1107 AcpiDmFieldPredefinedDescription (Op); 1108 } 1109 1110 /* Decode Notify() values */ 1111 1112 if (Op->Common.AmlOpcode == AML_NOTIFY_OP) 1113 { 1114 AcpiDmNotifyDescription (Op); 1115 } 1116 1117 AcpiDmDisplayTargetPathname (Op); 1118 1119 /* Could be a nested operator, check if comma required */ 1120 1121 if (!AcpiDmCommaIfListMember (Op)) 1122 { 1123 if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) && 1124 (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST)) && 1125 (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP)) 1126 { 1127 /* 1128 * This is a first-level element of a term list 1129 * start a new line 1130 */ 1131 if (!(Info->Flags & ACPI_PARSEOP_PARAMETER_LIST)) 1132 { 1133 AcpiOsPrintf ("\n"); 1134 } 1135 } 1136 } 1137 break; 1138 1139 case BLOCK_BRACE: 1140 case (BLOCK_BRACE | BLOCK_PAREN): 1141 1142 /* Completed an op that has a term list, add closing brace */ 1143 1144 if (Op->Common.DisasmFlags & ACPI_PARSEOP_EMPTY_TERMLIST) 1145 { 1146 ASL_CV_CLOSE_BRACE (Op, Level); 1147 } 1148 else 1149 { 1150 AcpiDmIndent (Level); 1151 ASL_CV_CLOSE_BRACE (Op, Level); 1152 } 1153 1154 AcpiDmCommaIfListMember (Op); 1155 1156 if (AcpiDmBlockType (Op->Common.Parent) != BLOCK_PAREN) 1157 { 1158 AcpiOsPrintf ("\n"); 1159 if (!(Op->Common.DisasmFlags & ACPI_PARSEOP_EMPTY_TERMLIST)) 1160 { 1161 if ((Op->Common.AmlOpcode == AML_IF_OP) && 1162 (Op->Common.Next) && 1163 (Op->Common.Next->Common.AmlOpcode == AML_ELSE_OP)) 1164 { 1165 break; 1166 } 1167 1168 if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) && 1169 (!Op->Common.Next)) 1170 { 1171 break; 1172 } 1173 AcpiOsPrintf ("\n"); 1174 } 1175 } 1176 break; 1177 1178 case BLOCK_NONE: 1179 default: 1180 1181 /* Could be a nested operator, check if comma required */ 1182 1183 if (!AcpiDmCommaIfListMember (Op)) 1184 { 1185 if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) && 1186 (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST)) && 1187 (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP)) 1188 { 1189 /* 1190 * This is a first-level element of a term list 1191 * start a new line 1192 */ 1193 AcpiOsPrintf ("\n"); 1194 } 1195 } 1196 else if (Op->Common.Parent) 1197 { 1198 switch (Op->Common.Parent->Common.AmlOpcode) 1199 { 1200 case AML_PACKAGE_OP: 1201 case AML_VARIABLE_PACKAGE_OP: 1202 1203 if (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST)) 1204 { 1205 AcpiOsPrintf ("\n"); 1206 } 1207 break; 1208 1209 default: 1210 1211 break; 1212 } 1213 } 1214 break; 1215 } 1216 1217 if (Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST) 1218 { 1219 if ((Op->Common.Next) && 1220 (Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST)) 1221 { 1222 return (AE_OK); 1223 } 1224 1225 /* 1226 * The parent Op is guaranteed to be valid because of the flag 1227 * ACPI_PARSEOP_PARAMETER_LIST -- which means that this op is part of 1228 * a parameter list and thus has a valid parent. 1229 */ 1230 ParentOp = Op->Common.Parent; 1231 1232 /* 1233 * Just completed a parameter node for something like "Buffer (param)". 1234 * Close the paren and open up the term list block with a brace. 1235 * 1236 * Switch predicates don't have a Next node but require a closing paren 1237 * and opening brace. 1238 */ 1239 if (Op->Common.Next || Op->Common.DisasmOpcode == ACPI_DASM_SWITCH_PREDICATE) 1240 { 1241 ASL_CV_CLOSE_PAREN (Op, Level); 1242 1243 /* 1244 * Emit a description comment for a Name() operator that is a 1245 * predefined ACPI name. Must check the grandparent. 1246 */ 1247 ParentOp = ParentOp->Common.Parent; 1248 if (ParentOp && 1249 (ParentOp->Asl.AmlOpcode == AML_NAME_OP)) 1250 { 1251 AcpiDmPredefinedDescription (ParentOp); 1252 } 1253 1254 /* Correct the indentation level for Switch and Case predicates */ 1255 1256 if (Op->Common.DisasmOpcode == ACPI_DASM_SWITCH_PREDICATE) 1257 { 1258 --Level; 1259 } 1260 1261 AcpiOsPrintf ("\n"); 1262 AcpiDmIndent (Level - 1); 1263 AcpiOsPrintf ("{\n"); 1264 } 1265 else 1266 { 1267 ParentOp->Common.DisasmFlags |= ACPI_PARSEOP_EMPTY_TERMLIST; 1268 ASL_CV_CLOSE_PAREN (Op, Level); 1269 AcpiOsPrintf ("{"); 1270 } 1271 } 1272 1273 if ((Op->Common.AmlOpcode == AML_NAME_OP) || 1274 (Op->Common.AmlOpcode == AML_RETURN_OP)) 1275 { 1276 Info->Level++; 1277 } 1278 1279 /* 1280 * For ASL+, check for and emit a C-style symbol. If valid, the 1281 * symbol string has been deferred until after the first operand 1282 */ 1283 if (AcpiGbl_CstyleDisassembly) 1284 { 1285 if (Op->Asl.OperatorSymbol) 1286 { 1287 AcpiOsPrintf ("%s", Op->Asl.OperatorSymbol); 1288 Op->Asl.OperatorSymbol = NULL; 1289 } 1290 } 1291 1292 return (AE_OK); 1293 } 1294 1295 #endif /* ACPI_DISASSEMBLER */ 1296