1 /*******************************************************************************
3 * Module Name: dmwalk - AML disassembly tree walk
5 ******************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12 * All rights reserved.
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
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
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;
37 * The above copyright and patent license is granted only if the following
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.
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
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
72 * 3.4. Intel retains all right, title, and interest in and to the Original
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.
80 * 4. Disclaimer and Export Compliance
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
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
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.
114 *****************************************************************************/
117 #include <contrib/dev/acpica/include/acpi.h>
118 #include <contrib/dev/acpica/include/accommon.h>
119 #include <contrib/dev/acpica/include/acparser.h>
120 #include <contrib/dev/acpica/include/amlcode.h>
121 #include <contrib/dev/acpica/include/acdisasm.h>
122 #include <contrib/dev/acpica/include/acdebug.h>
125 #ifdef ACPI_DISASSEMBLER
127 #define _COMPONENT ACPI_CA_DEBUGGER
128 ACPI_MODULE_NAME ("dmwalk")
131 #define DB_FULL_OP_INFO "[%4.4s] @%5.5X #%4.4X: "
133 /* Stub for non-compiler code */
135 #ifndef ACPI_ASL_COMPILER
137 AcpiDmEmitExternals (
144 /* Local prototypes */
148 ACPI_PARSE_OBJECT *Op,
154 ACPI_PARSE_OBJECT *Op,
160 ACPI_PARSE_OBJECT *Op);
163 /*******************************************************************************
165 * FUNCTION: AcpiDmDisassemble
167 * PARAMETERS: WalkState - Current state
168 * Origin - Starting object
169 * NumOpcodes - Max number of opcodes to be displayed
173 * DESCRIPTION: Disassemble parser object and its children. This is the
174 * main entry point of the disassembler.
176 ******************************************************************************/
180 ACPI_WALK_STATE *WalkState,
181 ACPI_PARSE_OBJECT *Origin,
184 ACPI_PARSE_OBJECT *Op = Origin;
185 ACPI_OP_WALK_INFO Info;
196 Info.WalkState = WalkState;
197 AcpiDmWalkParseTree (Op, AcpiDmDescendingOp, AcpiDmAscendingOp, &Info);
202 /*******************************************************************************
204 * FUNCTION: AcpiDmWalkParseTree
206 * PARAMETERS: Op - Root Op object
207 * DescendingCallback - Called during tree descent
208 * AscendingCallback - Called during tree ascent
209 * Context - To be passed to the callbacks
211 * RETURN: Status from callback(s)
213 * DESCRIPTION: Walk the entire parse tree.
215 ******************************************************************************/
218 AcpiDmWalkParseTree (
219 ACPI_PARSE_OBJECT *Op,
220 ASL_WALK_CALLBACK DescendingCallback,
221 ASL_WALK_CALLBACK AscendingCallback,
224 BOOLEAN NodePreviouslyVisited;
225 ACPI_PARSE_OBJECT *StartOp = Op;
227 ACPI_PARSE_OBJECT *Next;
228 ACPI_OP_WALK_INFO *Info = Context;
232 NodePreviouslyVisited = FALSE;
236 if (NodePreviouslyVisited)
238 if (AscendingCallback)
240 Status = AscendingCallback (Op, Info->Level, Context);
241 if (ACPI_FAILURE (Status))
249 /* Let the callback process the node */
251 Status = DescendingCallback (Op, Info->Level, Context);
252 if (ACPI_SUCCESS (Status))
254 /* Visit children first, once */
256 Next = AcpiPsGetArg (Op, 0);
264 else if (Status != AE_CTRL_DEPTH)
266 /* Exit immediately on any error */
272 /* Terminate walk at start op */
279 /* No more children, re-visit this node */
281 if (!NodePreviouslyVisited)
283 NodePreviouslyVisited = TRUE;
287 /* No more children, visit peers */
291 Op = Op->Common.Next;
292 NodePreviouslyVisited = FALSE;
296 /* No peers, re-visit parent */
298 if (Info->Level != 0 )
303 Op = Op->Common.Parent;
304 NodePreviouslyVisited = TRUE;
308 /* If we get here, the walk completed with no errors */
314 /*******************************************************************************
316 * FUNCTION: AcpiDmBlockType
318 * PARAMETERS: Op - Object to be examined
320 * RETURN: BlockType - not a block, parens, braces, or even both.
322 * DESCRIPTION: Type of block for this op (parens or braces)
324 ******************************************************************************/
328 ACPI_PARSE_OBJECT *Op)
330 const ACPI_OPCODE_INFO *OpInfo;
338 switch (Op->Common.AmlOpcode)
342 return (BLOCK_BRACE);
347 case AML_PROCESSOR_OP:
348 case AML_POWER_RES_OP:
349 case AML_THERMAL_ZONE_OP:
353 case AML_INDEX_FIELD_OP:
354 case AML_BANK_FIELD_OP:
356 return (BLOCK_PAREN | BLOCK_BRACE);
360 if (Op->Common.DisasmOpcode == ACPI_DASM_UNICODE)
365 /*lint -fallthrough */
368 case AML_VAR_PACKAGE_OP:
370 return (BLOCK_PAREN | BLOCK_BRACE);
374 return (BLOCK_PAREN);
378 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
379 if (OpInfo->Flags & AML_HAS_ARGS)
381 return (BLOCK_PAREN);
389 /*******************************************************************************
391 * FUNCTION: AcpiDmListType
393 * PARAMETERS: Op - Object to be examined
395 * RETURN: ListType - has commas or not.
397 * DESCRIPTION: Type of block for this op (parens or braces)
399 ******************************************************************************/
403 ACPI_PARSE_OBJECT *Op)
405 const ACPI_OPCODE_INFO *OpInfo;
413 switch (Op->Common.AmlOpcode)
420 case AML_POWER_RES_OP:
421 case AML_PROCESSOR_OP:
422 case AML_THERMAL_ZONE_OP:
426 case AML_INDEX_FIELD_OP:
427 case AML_BANK_FIELD_OP:
433 case AML_VAR_PACKAGE_OP:
435 return (BLOCK_COMMA_LIST);
439 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
440 if (OpInfo->Flags & AML_HAS_ARGS)
442 return (BLOCK_COMMA_LIST);
450 /*******************************************************************************
452 * FUNCTION: AcpiDmDescendingOp
454 * PARAMETERS: ASL_WALK_CALLBACK
458 * DESCRIPTION: First visitation of a parse object during tree descent.
459 * Decode opcode name and begin parameter list(s), if any.
461 ******************************************************************************/
465 ACPI_PARSE_OBJECT *Op,
469 ACPI_OP_WALK_INFO *Info = Context;
470 const ACPI_OPCODE_INFO *OpInfo;
472 ACPI_PARSE_OBJECT *NextOp;
475 if (Op->Common.DisasmFlags & ACPI_PARSEOP_IGNORE)
477 /* Ignore this op -- it was handled elsewhere */
479 return (AE_CTRL_DEPTH);
482 /* Level 0 is at the Definition Block level */
486 /* In verbose mode, print the AML offset, opcode and depth count */
490 VERBOSE_PRINT ((DB_FULL_OP_INFO,
491 (Info->WalkState->MethodNode ?
492 Info->WalkState->MethodNode->Name.Ascii : " "),
493 Op->Common.AmlOffset, (UINT32) Op->Common.AmlOpcode));
496 if (Op->Common.AmlOpcode == AML_SCOPE_OP)
498 /* This is the beginning of the Definition Block */
500 AcpiOsPrintf ("{\n");
502 /* Emit all External() declarations here */
504 AcpiDmEmitExternals ();
508 else if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
509 (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)) &&
510 (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP))
513 * This is a first-level element of a term list,
516 AcpiDmIndent (Level);
517 Info->LastLevel = Level;
522 * This is an inexpensive mechanism to try and keep lines from getting
523 * too long. When the limit is hit, start a new line at the previous
524 * indent plus one. A better but more expensive mechanism would be to
525 * keep track of the current column.
528 if (Info->Count /*+Info->LastLevel*/ > 10)
532 AcpiDmIndent (Info->LastLevel + 1);
535 /* Print the opcode name */
537 AcpiDmDisassembleOneOp (NULL, Info, Op);
539 if (Op->Common.DisasmOpcode == ACPI_DASM_LNOT_PREFIX)
544 if ((Op->Common.AmlOpcode == AML_NAME_OP) ||
545 (Op->Common.AmlOpcode == AML_RETURN_OP))
550 /* Start the opcode argument list if necessary */
552 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
554 if ((OpInfo->Flags & AML_HAS_ARGS) ||
555 (Op->Common.AmlOpcode == AML_EVENT_OP))
557 /* This opcode has an argument list */
559 if (AcpiDmBlockType (Op) & BLOCK_PAREN)
564 /* If this is a named opcode, print the associated name value */
566 if (OpInfo->Flags & AML_NAMED)
568 switch (Op->Common.AmlOpcode)
572 NextOp = AcpiPsGetDepthNext (NULL, Op);
573 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
574 AcpiDmNamestring (NextOp->Common.Value.Name);
577 /*lint -fallthrough */
581 Name = AcpiPsGetName (Op);
584 AcpiDmNamestring ((char *) Op->Named.Path);
588 AcpiDmDumpName (Name);
591 if (Op->Common.AmlOpcode != AML_INT_NAMEDFIELD_OP)
593 if (AcpiGbl_DbOpt_verbose)
595 (void) AcpiPsDisplayObjectPathname (NULL, Op);
601 switch (Op->Common.AmlOpcode)
605 AcpiDmMethodFlags (Op);
612 /* Check for _HID and related EISAID() */
621 AcpiDmRegionFlags (Op);
625 case AML_POWER_RES_OP:
627 /* Mark the next two Ops as part of the parameter list */
630 NextOp = AcpiPsGetDepthNext (NULL, Op);
631 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
633 NextOp = NextOp->Common.Next;
634 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
638 case AML_PROCESSOR_OP:
640 /* Mark the next three Ops as part of the parameter list */
643 NextOp = AcpiPsGetDepthNext (NULL, Op);
644 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
646 NextOp = NextOp->Common.Next;
647 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
649 NextOp = NextOp->Common.Next;
650 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
655 case AML_DATA_REGION_OP:
669 case AML_THERMAL_ZONE_OP:
677 AcpiOsPrintf ("*** Unhandled named opcode %X\n", Op->Common.AmlOpcode);
682 else switch (Op->Common.AmlOpcode)
685 case AML_BANK_FIELD_OP:
686 case AML_INDEX_FIELD_OP:
690 /* Name of the parent OperationRegion */
692 NextOp = AcpiPsGetDepthNext (NULL, Op);
693 AcpiDmNamestring (NextOp->Common.Value.Name);
695 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
697 switch (Op->Common.AmlOpcode)
699 case AML_BANK_FIELD_OP:
701 /* Namestring - Bank Name */
703 NextOp = AcpiPsGetDepthNext (NULL, NextOp);
704 AcpiDmNamestring (NextOp->Common.Value.Name);
705 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
709 * Bank Value. This is a TermArg in the middle of the parameter
710 * list, must handle it here.
712 * Disassemble the TermArg parse tree. ACPI_PARSEOP_PARAMLIST
713 * eliminates newline in the output.
715 NextOp = NextOp->Common.Next;
717 Info->Flags = ACPI_PARSEOP_PARAMLIST;
718 AcpiDmWalkParseTree (NextOp, AcpiDmDescendingOp, AcpiDmAscendingOp, Info);
722 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
726 case AML_INDEX_FIELD_OP:
728 /* Namestring - Data Name */
730 NextOp = AcpiPsGetDepthNext (NULL, NextOp);
731 AcpiDmNamestring (NextOp->Common.Value.Name);
733 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
741 AcpiDmFieldFlags (NextOp);
747 /* The next op is the size parameter */
749 NextOp = AcpiPsGetDepthNext (NULL, Op);
752 /* Single-step support */
757 if (Op->Common.DisasmOpcode == ACPI_DASM_RESOURCE)
760 * We have a resource list. Don't need to output
761 * the buffer size Op. Open up a new block
763 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
764 NextOp = NextOp->Common.Next;
765 AcpiOsPrintf (")\n");
766 AcpiDmIndent (Info->Level);
767 AcpiOsPrintf ("{\n");
771 /* Normal Buffer, mark size as in the parameter list */
773 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
777 case AML_VAR_PACKAGE_OP:
781 /* The next op is the size or predicate parameter */
783 NextOp = AcpiPsGetDepthNext (NULL, Op);
786 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
793 /* The next op is the size or predicate parameter */
795 NextOp = AcpiPsGetDepthNext (NULL, Op);
798 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
814 if (AcpiDmBlockType (Op) & BLOCK_BRACE)
817 AcpiDmIndent (Level);
818 AcpiOsPrintf ("{\n");
826 /*******************************************************************************
828 * FUNCTION: AcpiDmAscendingOp
830 * PARAMETERS: ASL_WALK_CALLBACK
834 * DESCRIPTION: Second visitation of a parse object, during ascent of parse
835 * tree. Close out any parameter lists and complete the opcode.
837 ******************************************************************************/
841 ACPI_PARSE_OBJECT *Op,
845 ACPI_OP_WALK_INFO *Info = Context;
848 if (Op->Common.DisasmFlags & ACPI_PARSEOP_IGNORE)
850 /* Ignore this op -- it was handled elsewhere */
855 if ((Level == 0) && (Op->Common.AmlOpcode == AML_SCOPE_OP))
857 /* Indicates the end of the current descriptor block (table) */
859 AcpiOsPrintf ("}\n\n");
863 switch (AcpiDmBlockType (Op))
867 /* Completed an op that has arguments, add closing paren */
871 /* Could be a nested operator, check if comma required */
873 if (!AcpiDmCommaIfListMember (Op))
875 if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
876 (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)) &&
877 (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP))
880 * This is a first-level element of a term list
883 if (!(Info->Flags & ACPI_PARSEOP_PARAMLIST))
893 case (BLOCK_BRACE | BLOCK_PAREN):
895 /* Completed an op that has a term list, add closing brace */
897 if (Op->Common.DisasmFlags & ACPI_PARSEOP_EMPTY_TERMLIST)
903 AcpiDmIndent (Level);
907 AcpiDmCommaIfListMember (Op);
909 if (AcpiDmBlockType (Op->Common.Parent) != BLOCK_PAREN)
912 if (!(Op->Common.DisasmFlags & ACPI_PARSEOP_EMPTY_TERMLIST))
914 if ((Op->Common.AmlOpcode == AML_IF_OP) &&
916 (Op->Common.Next->Common.AmlOpcode == AML_ELSE_OP))
921 if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
935 /* Could be a nested operator, check if comma required */
937 if (!AcpiDmCommaIfListMember (Op))
939 if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
940 (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)) &&
941 (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP))
944 * This is a first-level element of a term list
950 else if (Op->Common.Parent)
952 switch (Op->Common.Parent->Common.AmlOpcode)
955 case AML_VAR_PACKAGE_OP:
957 if (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST))
971 if (Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)
973 if ((Op->Common.Next) &&
974 (Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST))
980 * Just completed a parameter node for something like "Buffer (param)".
981 * Close the paren and open up the term list block with a brace
985 AcpiOsPrintf (")\n");
986 AcpiDmIndent (Level - 1);
987 AcpiOsPrintf ("{\n");
991 Op->Common.Parent->Common.DisasmFlags |=
992 ACPI_PARSEOP_EMPTY_TERMLIST;
993 AcpiOsPrintf (") {");
997 if ((Op->Common.AmlOpcode == AML_NAME_OP) ||
998 (Op->Common.AmlOpcode == AML_RETURN_OP))
1006 #endif /* ACPI_DISASSEMBLER */