1 /*******************************************************************************
3 * Module Name: dmwalk - AML disassembly tree walk
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2012, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
53 #ifdef ACPI_DISASSEMBLER
55 #define _COMPONENT ACPI_CA_DEBUGGER
56 ACPI_MODULE_NAME ("dmwalk")
59 #define DB_FULL_OP_INFO "[%4.4s] @%5.5X #%4.4X: "
61 /* Stub for non-compiler code */
63 #ifndef ACPI_ASL_COMPILER
72 /* Local prototypes */
76 ACPI_PARSE_OBJECT *Op,
82 ACPI_PARSE_OBJECT *Op,
88 ACPI_PARSE_OBJECT *Op);
91 /*******************************************************************************
93 * FUNCTION: AcpiDmDisassemble
95 * PARAMETERS: WalkState - Current state
96 * Origin - Starting object
97 * NumOpcodes - Max number of opcodes to be displayed
101 * DESCRIPTION: Disassemble parser object and its children. This is the
102 * main entry point of the disassembler.
104 ******************************************************************************/
108 ACPI_WALK_STATE *WalkState,
109 ACPI_PARSE_OBJECT *Origin,
112 ACPI_PARSE_OBJECT *Op = Origin;
113 ACPI_OP_WALK_INFO Info;
124 Info.WalkState = WalkState;
125 AcpiDmWalkParseTree (Op, AcpiDmDescendingOp, AcpiDmAscendingOp, &Info);
130 /*******************************************************************************
132 * FUNCTION: AcpiDmWalkParseTree
134 * PARAMETERS: Op - Root Op object
135 * DescendingCallback - Called during tree descent
136 * AscendingCallback - Called during tree ascent
137 * Context - To be passed to the callbacks
139 * RETURN: Status from callback(s)
141 * DESCRIPTION: Walk the entire parse tree.
143 ******************************************************************************/
146 AcpiDmWalkParseTree (
147 ACPI_PARSE_OBJECT *Op,
148 ASL_WALK_CALLBACK DescendingCallback,
149 ASL_WALK_CALLBACK AscendingCallback,
152 BOOLEAN NodePreviouslyVisited;
153 ACPI_PARSE_OBJECT *StartOp = Op;
155 ACPI_PARSE_OBJECT *Next;
156 ACPI_OP_WALK_INFO *Info = Context;
160 NodePreviouslyVisited = FALSE;
164 if (NodePreviouslyVisited)
166 if (AscendingCallback)
168 Status = AscendingCallback (Op, Info->Level, Context);
169 if (ACPI_FAILURE (Status))
177 /* Let the callback process the node */
179 Status = DescendingCallback (Op, Info->Level, Context);
180 if (ACPI_SUCCESS (Status))
182 /* Visit children first, once */
184 Next = AcpiPsGetArg (Op, 0);
192 else if (Status != AE_CTRL_DEPTH)
194 /* Exit immediately on any error */
200 /* Terminate walk at start op */
207 /* No more children, re-visit this node */
209 if (!NodePreviouslyVisited)
211 NodePreviouslyVisited = TRUE;
215 /* No more children, visit peers */
219 Op = Op->Common.Next;
220 NodePreviouslyVisited = FALSE;
224 /* No peers, re-visit parent */
226 if (Info->Level != 0 )
231 Op = Op->Common.Parent;
232 NodePreviouslyVisited = TRUE;
236 /* If we get here, the walk completed with no errors */
242 /*******************************************************************************
244 * FUNCTION: AcpiDmBlockType
246 * PARAMETERS: Op - Object to be examined
248 * RETURN: BlockType - not a block, parens, braces, or even both.
250 * DESCRIPTION: Type of block for this op (parens or braces)
252 ******************************************************************************/
256 ACPI_PARSE_OBJECT *Op)
258 const ACPI_OPCODE_INFO *OpInfo;
266 switch (Op->Common.AmlOpcode)
270 return (BLOCK_BRACE);
275 case AML_PROCESSOR_OP:
276 case AML_POWER_RES_OP:
277 case AML_THERMAL_ZONE_OP:
281 case AML_INDEX_FIELD_OP:
282 case AML_BANK_FIELD_OP:
284 return (BLOCK_PAREN | BLOCK_BRACE);
288 if (Op->Common.DisasmOpcode == ACPI_DASM_UNICODE)
293 /*lint -fallthrough */
296 case AML_VAR_PACKAGE_OP:
298 return (BLOCK_PAREN | BLOCK_BRACE);
302 return (BLOCK_PAREN);
306 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
307 if (OpInfo->Flags & AML_HAS_ARGS)
309 return (BLOCK_PAREN);
317 /*******************************************************************************
319 * FUNCTION: AcpiDmListType
321 * PARAMETERS: Op - Object to be examined
323 * RETURN: ListType - has commas or not.
325 * DESCRIPTION: Type of block for this op (parens or braces)
327 ******************************************************************************/
331 ACPI_PARSE_OBJECT *Op)
333 const ACPI_OPCODE_INFO *OpInfo;
341 switch (Op->Common.AmlOpcode)
348 case AML_POWER_RES_OP:
349 case AML_PROCESSOR_OP:
350 case AML_THERMAL_ZONE_OP:
354 case AML_INDEX_FIELD_OP:
355 case AML_BANK_FIELD_OP:
361 case AML_VAR_PACKAGE_OP:
363 return (BLOCK_COMMA_LIST);
367 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
368 if (OpInfo->Flags & AML_HAS_ARGS)
370 return (BLOCK_COMMA_LIST);
378 /*******************************************************************************
380 * FUNCTION: AcpiDmDescendingOp
382 * PARAMETERS: ASL_WALK_CALLBACK
386 * DESCRIPTION: First visitation of a parse object during tree descent.
387 * Decode opcode name and begin parameter list(s), if any.
389 ******************************************************************************/
393 ACPI_PARSE_OBJECT *Op,
397 ACPI_OP_WALK_INFO *Info = Context;
398 const ACPI_OPCODE_INFO *OpInfo;
400 ACPI_PARSE_OBJECT *NextOp;
403 if (Op->Common.DisasmFlags & ACPI_PARSEOP_IGNORE)
405 /* Ignore this op -- it was handled elsewhere */
407 return (AE_CTRL_DEPTH);
410 /* Level 0 is at the Definition Block level */
414 /* In verbose mode, print the AML offset, opcode and depth count */
418 VERBOSE_PRINT ((DB_FULL_OP_INFO,
419 (Info->WalkState->MethodNode ?
420 Info->WalkState->MethodNode->Name.Ascii : " "),
421 Op->Common.AmlOffset, (UINT32) Op->Common.AmlOpcode));
424 if (Op->Common.AmlOpcode == AML_SCOPE_OP)
426 /* This is the beginning of the Definition Block */
428 AcpiOsPrintf ("{\n");
430 /* Emit all External() declarations here */
432 AcpiDmEmitExternals ();
436 else if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
437 (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)) &&
438 (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP))
441 * This is a first-level element of a term list,
444 AcpiDmIndent (Level);
445 Info->LastLevel = Level;
450 * This is an inexpensive mechanism to try and keep lines from getting
451 * too long. When the limit is hit, start a new line at the previous
452 * indent plus one. A better but more expensive mechanism would be to
453 * keep track of the current column.
456 if (Info->Count /* +Info->LastLevel */ > 10)
460 AcpiDmIndent (Info->LastLevel + 1);
463 /* Print the opcode name */
465 AcpiDmDisassembleOneOp (NULL, Info, Op);
467 if ((Op->Common.DisasmOpcode == ACPI_DASM_LNOT_PREFIX) ||
468 (Op->Common.AmlOpcode == AML_INT_CONNECTION_OP))
473 if ((Op->Common.AmlOpcode == AML_NAME_OP) ||
474 (Op->Common.AmlOpcode == AML_RETURN_OP))
479 /* Start the opcode argument list if necessary */
481 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
483 if ((OpInfo->Flags & AML_HAS_ARGS) ||
484 (Op->Common.AmlOpcode == AML_EVENT_OP))
486 /* This opcode has an argument list */
488 if (AcpiDmBlockType (Op) & BLOCK_PAREN)
493 /* If this is a named opcode, print the associated name value */
495 if (OpInfo->Flags & AML_NAMED)
497 switch (Op->Common.AmlOpcode)
501 NextOp = AcpiPsGetDepthNext (NULL, Op);
502 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
503 AcpiDmNamestring (NextOp->Common.Value.Name);
506 /*lint -fallthrough */
510 Name = AcpiPsGetName (Op);
513 AcpiDmNamestring ((char *) Op->Named.Path);
517 AcpiDmDumpName (Name);
520 if (Op->Common.AmlOpcode != AML_INT_NAMEDFIELD_OP)
522 if (AcpiGbl_DbOpt_verbose)
524 (void) AcpiPsDisplayObjectPathname (NULL, Op);
530 switch (Op->Common.AmlOpcode)
534 AcpiDmMethodFlags (Op);
537 /* Emit description comment for Method() with a predefined ACPI name */
539 AcpiDmPredefinedDescription (Op);
545 /* Check for _HID and related EISAID() */
554 AcpiDmRegionFlags (Op);
558 case AML_POWER_RES_OP:
560 /* Mark the next two Ops as part of the parameter list */
563 NextOp = AcpiPsGetDepthNext (NULL, Op);
564 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
566 NextOp = NextOp->Common.Next;
567 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
571 case AML_PROCESSOR_OP:
573 /* Mark the next three Ops as part of the parameter list */
576 NextOp = AcpiPsGetDepthNext (NULL, Op);
577 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
579 NextOp = NextOp->Common.Next;
580 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
582 NextOp = NextOp->Common.Next;
583 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
588 case AML_DATA_REGION_OP:
602 case AML_THERMAL_ZONE_OP:
610 AcpiOsPrintf ("*** Unhandled named opcode %X\n",
611 Op->Common.AmlOpcode);
616 else switch (Op->Common.AmlOpcode)
619 case AML_BANK_FIELD_OP:
620 case AML_INDEX_FIELD_OP:
624 /* Name of the parent OperationRegion */
626 NextOp = AcpiPsGetDepthNext (NULL, Op);
627 AcpiDmNamestring (NextOp->Common.Value.Name);
629 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
631 switch (Op->Common.AmlOpcode)
633 case AML_BANK_FIELD_OP:
635 /* Namestring - Bank Name */
637 NextOp = AcpiPsGetDepthNext (NULL, NextOp);
638 AcpiDmNamestring (NextOp->Common.Value.Name);
639 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
643 * Bank Value. This is a TermArg in the middle of the parameter
644 * list, must handle it here.
646 * Disassemble the TermArg parse tree. ACPI_PARSEOP_PARAMLIST
647 * eliminates newline in the output.
649 NextOp = NextOp->Common.Next;
651 Info->Flags = ACPI_PARSEOP_PARAMLIST;
652 AcpiDmWalkParseTree (NextOp, AcpiDmDescendingOp,
653 AcpiDmAscendingOp, Info);
657 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
661 case AML_INDEX_FIELD_OP:
663 /* Namestring - Data Name */
665 NextOp = AcpiPsGetDepthNext (NULL, NextOp);
666 AcpiDmNamestring (NextOp->Common.Value.Name);
668 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
676 AcpiDmFieldFlags (NextOp);
682 /* The next op is the size parameter */
684 NextOp = AcpiPsGetDepthNext (NULL, Op);
687 /* Single-step support */
692 if (Op->Common.DisasmOpcode == ACPI_DASM_RESOURCE)
695 * We have a resource list. Don't need to output
696 * the buffer size Op. Open up a new block
698 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
699 NextOp = NextOp->Common.Next;
702 /* Emit description comment for Name() with a predefined ACPI name */
704 AcpiDmPredefinedDescription (Op->Asl.Parent);
707 AcpiDmIndent (Info->Level);
708 AcpiOsPrintf ("{\n");
712 /* Normal Buffer, mark size as in the parameter list */
714 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
718 case AML_VAR_PACKAGE_OP:
722 /* The next op is the size or predicate parameter */
724 NextOp = AcpiPsGetDepthNext (NULL, Op);
727 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
734 /* The next op is the size parameter */
736 NextOp = AcpiPsGetDepthNext (NULL, Op);
739 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
755 if (AcpiDmBlockType (Op) & BLOCK_BRACE)
758 AcpiDmIndent (Level);
759 AcpiOsPrintf ("{\n");
767 /*******************************************************************************
769 * FUNCTION: AcpiDmAscendingOp
771 * PARAMETERS: ASL_WALK_CALLBACK
775 * DESCRIPTION: Second visitation of a parse object, during ascent of parse
776 * tree. Close out any parameter lists and complete the opcode.
778 ******************************************************************************/
782 ACPI_PARSE_OBJECT *Op,
786 ACPI_OP_WALK_INFO *Info = Context;
787 ACPI_PARSE_OBJECT *ParentOp;
790 if (Op->Common.DisasmFlags & ACPI_PARSEOP_IGNORE)
792 /* Ignore this op -- it was handled elsewhere */
797 if ((Level == 0) && (Op->Common.AmlOpcode == AML_SCOPE_OP))
799 /* Indicates the end of the current descriptor block (table) */
801 AcpiOsPrintf ("}\n\n");
805 switch (AcpiDmBlockType (Op))
809 /* Completed an op that has arguments, add closing paren */
813 if (Op->Common.AmlOpcode == AML_NAME_OP)
815 /* Emit description comment for Name() with a predefined ACPI name */
817 AcpiDmPredefinedDescription (Op);
821 /* For Create* operators, attempt to emit resource tag description */
823 AcpiDmFieldPredefinedDescription (Op);
826 /* Could be a nested operator, check if comma required */
828 if (!AcpiDmCommaIfListMember (Op))
830 if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
831 (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)) &&
832 (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP))
835 * This is a first-level element of a term list
838 if (!(Info->Flags & ACPI_PARSEOP_PARAMLIST))
848 case (BLOCK_BRACE | BLOCK_PAREN):
850 /* Completed an op that has a term list, add closing brace */
852 if (Op->Common.DisasmFlags & ACPI_PARSEOP_EMPTY_TERMLIST)
858 AcpiDmIndent (Level);
862 AcpiDmCommaIfListMember (Op);
864 if (AcpiDmBlockType (Op->Common.Parent) != BLOCK_PAREN)
867 if (!(Op->Common.DisasmFlags & ACPI_PARSEOP_EMPTY_TERMLIST))
869 if ((Op->Common.AmlOpcode == AML_IF_OP) &&
871 (Op->Common.Next->Common.AmlOpcode == AML_ELSE_OP))
876 if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
890 /* Could be a nested operator, check if comma required */
892 if (!AcpiDmCommaIfListMember (Op))
894 if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
895 (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)) &&
896 (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP))
899 * This is a first-level element of a term list
905 else if (Op->Common.Parent)
907 switch (Op->Common.Parent->Common.AmlOpcode)
910 case AML_VAR_PACKAGE_OP:
912 if (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST))
926 if (Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)
928 if ((Op->Common.Next) &&
929 (Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST))
935 * Just completed a parameter node for something like "Buffer (param)".
936 * Close the paren and open up the term list block with a brace
942 /* Emit description comment for Name() with a predefined ACPI name */
944 ParentOp = Op->Common.Parent;
947 ParentOp = ParentOp->Common.Parent;
948 if (ParentOp && ParentOp->Asl.AmlOpcode == AML_NAME_OP)
950 AcpiDmPredefinedDescription (ParentOp);
954 AcpiDmIndent (Level - 1);
955 AcpiOsPrintf ("{\n");
959 Op->Common.Parent->Common.DisasmFlags |=
960 ACPI_PARSEOP_EMPTY_TERMLIST;
961 AcpiOsPrintf (") {");
965 if ((Op->Common.AmlOpcode == AML_NAME_OP) ||
966 (Op->Common.AmlOpcode == AML_RETURN_OP))
974 #endif /* ACPI_DISASSEMBLER */