1 /*******************************************************************************
3 * Module Name: dmwalk - AML disassembly tree walk
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2014, 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) ||
289 (Op->Common.DisasmOpcode == ACPI_DASM_UUID))
294 /*lint -fallthrough */
297 case AML_VAR_PACKAGE_OP:
299 return (BLOCK_PAREN | BLOCK_BRACE);
303 return (BLOCK_PAREN);
307 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
308 if (OpInfo->Flags & AML_HAS_ARGS)
310 return (BLOCK_PAREN);
318 /*******************************************************************************
320 * FUNCTION: AcpiDmListType
322 * PARAMETERS: Op - Object to be examined
324 * RETURN: ListType - has commas or not.
326 * DESCRIPTION: Type of block for this op (parens or braces)
328 ******************************************************************************/
332 ACPI_PARSE_OBJECT *Op)
334 const ACPI_OPCODE_INFO *OpInfo;
342 switch (Op->Common.AmlOpcode)
349 case AML_POWER_RES_OP:
350 case AML_PROCESSOR_OP:
351 case AML_THERMAL_ZONE_OP:
355 case AML_INDEX_FIELD_OP:
356 case AML_BANK_FIELD_OP:
362 case AML_VAR_PACKAGE_OP:
364 return (BLOCK_COMMA_LIST);
368 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
369 if (OpInfo->Flags & AML_HAS_ARGS)
371 return (BLOCK_COMMA_LIST);
379 /*******************************************************************************
381 * FUNCTION: AcpiDmDescendingOp
383 * PARAMETERS: ASL_WALK_CALLBACK
387 * DESCRIPTION: First visitation of a parse object during tree descent.
388 * Decode opcode name and begin parameter list(s), if any.
390 ******************************************************************************/
394 ACPI_PARSE_OBJECT *Op,
398 ACPI_OP_WALK_INFO *Info = Context;
399 const ACPI_OPCODE_INFO *OpInfo;
401 ACPI_PARSE_OBJECT *NextOp;
404 if (Op->Common.DisasmFlags & ACPI_PARSEOP_IGNORE)
406 /* Ignore this op -- it was handled elsewhere */
408 return (AE_CTRL_DEPTH);
411 /* Level 0 is at the Definition Block level */
415 /* In verbose mode, print the AML offset, opcode and depth count */
419 VERBOSE_PRINT ((DB_FULL_OP_INFO,
420 (Info->WalkState->MethodNode ?
421 Info->WalkState->MethodNode->Name.Ascii : " "),
422 Op->Common.AmlOffset, (UINT32) Op->Common.AmlOpcode));
425 if (Op->Common.AmlOpcode == AML_SCOPE_OP)
427 /* This is the beginning of the Definition Block */
429 AcpiOsPrintf ("{\n");
431 /* Emit all External() declarations here */
433 AcpiDmEmitExternals ();
437 else if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
438 (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)) &&
439 (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP))
442 * This is a first-level element of a term list,
445 switch (Op->Common.AmlOpcode)
449 * Optionally just ignore this opcode. Some tables use
450 * NoOp opcodes for "padding" out packages that the BIOS
451 * changes dynamically. This can leave hundreds or
452 * thousands of NoOp opcodes that if disassembled,
453 * cannot be compiled because they are syntactically
456 if (AcpiGbl_IgnoreNoopOperator)
458 Op->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
466 AcpiDmIndent (Level);
470 Info->LastLevel = Level;
475 * This is an inexpensive mechanism to try and keep lines from getting
476 * too long. When the limit is hit, start a new line at the previous
477 * indent plus one. A better but more expensive mechanism would be to
478 * keep track of the current column.
481 if (Info->Count /* +Info->LastLevel */ > 10)
485 AcpiDmIndent (Info->LastLevel + 1);
488 /* Print the opcode name */
490 AcpiDmDisassembleOneOp (NULL, Info, Op);
492 if ((Op->Common.DisasmOpcode == ACPI_DASM_LNOT_PREFIX) ||
493 (Op->Common.AmlOpcode == AML_INT_CONNECTION_OP))
498 if ((Op->Common.AmlOpcode == AML_NAME_OP) ||
499 (Op->Common.AmlOpcode == AML_RETURN_OP))
504 /* Start the opcode argument list if necessary */
506 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
508 if ((OpInfo->Flags & AML_HAS_ARGS) ||
509 (Op->Common.AmlOpcode == AML_EVENT_OP))
511 /* This opcode has an argument list */
513 if (AcpiDmBlockType (Op) & BLOCK_PAREN)
518 /* If this is a named opcode, print the associated name value */
520 if (OpInfo->Flags & AML_NAMED)
522 switch (Op->Common.AmlOpcode)
526 NextOp = AcpiPsGetDepthNext (NULL, Op);
527 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
528 AcpiDmNamestring (NextOp->Common.Value.Name);
531 /*lint -fallthrough */
535 Name = AcpiPsGetName (Op);
538 AcpiDmNamestring ((char *) Op->Named.Path);
542 AcpiDmDumpName (Name);
545 if (Op->Common.AmlOpcode != AML_INT_NAMEDFIELD_OP)
547 if (AcpiGbl_DbOpt_verbose)
549 (void) AcpiPsDisplayObjectPathname (NULL, Op);
555 switch (Op->Common.AmlOpcode)
559 AcpiDmMethodFlags (Op);
562 /* Emit description comment for Method() with a predefined ACPI name */
564 AcpiDmPredefinedDescription (Op);
570 /* Check for _HID and related EISAID() */
572 AcpiDmCheckForHardwareId (Op);
579 AcpiDmRegionFlags (Op);
583 case AML_POWER_RES_OP:
585 /* Mark the next two Ops as part of the parameter list */
588 NextOp = AcpiPsGetDepthNext (NULL, Op);
589 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
591 NextOp = NextOp->Common.Next;
592 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
596 case AML_PROCESSOR_OP:
598 /* Mark the next three Ops as part of the parameter list */
601 NextOp = AcpiPsGetDepthNext (NULL, Op);
602 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
604 NextOp = NextOp->Common.Next;
605 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
607 NextOp = NextOp->Common.Next;
608 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
613 case AML_DATA_REGION_OP:
627 case AML_THERMAL_ZONE_OP:
635 AcpiOsPrintf ("*** Unhandled named opcode %X\n",
636 Op->Common.AmlOpcode);
641 else switch (Op->Common.AmlOpcode)
644 case AML_BANK_FIELD_OP:
645 case AML_INDEX_FIELD_OP:
649 /* Name of the parent OperationRegion */
651 NextOp = AcpiPsGetDepthNext (NULL, Op);
652 AcpiDmNamestring (NextOp->Common.Value.Name);
654 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
656 switch (Op->Common.AmlOpcode)
658 case AML_BANK_FIELD_OP:
660 /* Namestring - Bank Name */
662 NextOp = AcpiPsGetDepthNext (NULL, NextOp);
663 AcpiDmNamestring (NextOp->Common.Value.Name);
664 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
668 * Bank Value. This is a TermArg in the middle of the parameter
669 * list, must handle it here.
671 * Disassemble the TermArg parse tree. ACPI_PARSEOP_PARAMLIST
672 * eliminates newline in the output.
674 NextOp = NextOp->Common.Next;
676 Info->Flags = ACPI_PARSEOP_PARAMLIST;
677 AcpiDmWalkParseTree (NextOp, AcpiDmDescendingOp,
678 AcpiDmAscendingOp, Info);
682 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
686 case AML_INDEX_FIELD_OP:
688 /* Namestring - Data Name */
690 NextOp = AcpiPsGetDepthNext (NULL, NextOp);
691 AcpiDmNamestring (NextOp->Common.Value.Name);
693 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
701 AcpiDmFieldFlags (NextOp);
706 /* The next op is the size parameter */
708 NextOp = AcpiPsGetDepthNext (NULL, Op);
711 /* Single-step support */
716 if (Op->Common.DisasmOpcode == ACPI_DASM_RESOURCE)
719 * We have a resource list. Don't need to output
720 * the buffer size Op. Open up a new block
722 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
723 NextOp = NextOp->Common.Next;
726 /* Emit description comment for Name() with a predefined ACPI name */
728 AcpiDmPredefinedDescription (Op->Asl.Parent);
731 AcpiDmIndent (Info->Level);
732 AcpiOsPrintf ("{\n");
736 /* Normal Buffer, mark size as in the parameter list */
738 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
741 case AML_VAR_PACKAGE_OP:
745 /* The next op is the size or predicate parameter */
747 NextOp = AcpiPsGetDepthNext (NULL, Op);
750 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
756 /* The next op is the size parameter */
758 NextOp = AcpiPsGetDepthNext (NULL, Op);
761 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
775 if (AcpiDmBlockType (Op) & BLOCK_BRACE)
778 AcpiDmIndent (Level);
779 AcpiOsPrintf ("{\n");
787 /*******************************************************************************
789 * FUNCTION: AcpiDmAscendingOp
791 * PARAMETERS: ASL_WALK_CALLBACK
795 * DESCRIPTION: Second visitation of a parse object, during ascent of parse
796 * tree. Close out any parameter lists and complete the opcode.
798 ******************************************************************************/
802 ACPI_PARSE_OBJECT *Op,
806 ACPI_OP_WALK_INFO *Info = Context;
807 ACPI_PARSE_OBJECT *ParentOp;
810 if (Op->Common.DisasmFlags & ACPI_PARSEOP_IGNORE)
812 /* Ignore this op -- it was handled elsewhere */
817 if ((Level == 0) && (Op->Common.AmlOpcode == AML_SCOPE_OP))
819 /* Indicates the end of the current descriptor block (table) */
821 AcpiOsPrintf ("}\n\n");
825 switch (AcpiDmBlockType (Op))
829 /* Completed an op that has arguments, add closing paren */
833 if (Op->Common.AmlOpcode == AML_NAME_OP)
835 /* Emit description comment for Name() with a predefined ACPI name */
837 AcpiDmPredefinedDescription (Op);
841 /* For Create* operators, attempt to emit resource tag description */
843 AcpiDmFieldPredefinedDescription (Op);
846 /* Decode Notify() values */
848 if (Op->Common.AmlOpcode == AML_NOTIFY_OP)
850 AcpiDmNotifyDescription (Op);
853 AcpiDmDisplayTargetPathname (Op);
855 /* Could be a nested operator, check if comma required */
857 if (!AcpiDmCommaIfListMember (Op))
859 if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
860 (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)) &&
861 (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP))
864 * This is a first-level element of a term list
867 if (!(Info->Flags & ACPI_PARSEOP_PARAMLIST))
876 case (BLOCK_BRACE | BLOCK_PAREN):
878 /* Completed an op that has a term list, add closing brace */
880 if (Op->Common.DisasmFlags & ACPI_PARSEOP_EMPTY_TERMLIST)
886 AcpiDmIndent (Level);
890 AcpiDmCommaIfListMember (Op);
892 if (AcpiDmBlockType (Op->Common.Parent) != BLOCK_PAREN)
895 if (!(Op->Common.DisasmFlags & ACPI_PARSEOP_EMPTY_TERMLIST))
897 if ((Op->Common.AmlOpcode == AML_IF_OP) &&
899 (Op->Common.Next->Common.AmlOpcode == AML_ELSE_OP))
904 if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
917 /* Could be a nested operator, check if comma required */
919 if (!AcpiDmCommaIfListMember (Op))
921 if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
922 (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)) &&
923 (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP))
926 * This is a first-level element of a term list
932 else if (Op->Common.Parent)
934 switch (Op->Common.Parent->Common.AmlOpcode)
937 case AML_VAR_PACKAGE_OP:
939 if (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST))
953 if (Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)
955 if ((Op->Common.Next) &&
956 (Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST))
962 * The parent Op is guaranteed to be valid because of the flag
963 * ACPI_PARSEOP_PARAMLIST -- which means that this op is part of
964 * a parameter list and thus has a valid parent.
966 ParentOp = Op->Common.Parent;
969 * Just completed a parameter node for something like "Buffer (param)".
970 * Close the paren and open up the term list block with a brace
977 * Emit a description comment for a Name() operator that is a
978 * predefined ACPI name. Must check the grandparent.
980 ParentOp = ParentOp->Common.Parent;
982 (ParentOp->Asl.AmlOpcode == AML_NAME_OP))
984 AcpiDmPredefinedDescription (ParentOp);
988 AcpiDmIndent (Level - 1);
989 AcpiOsPrintf ("{\n");
993 ParentOp->Common.DisasmFlags |= ACPI_PARSEOP_EMPTY_TERMLIST;
994 AcpiOsPrintf (") {");
998 if ((Op->Common.AmlOpcode == AML_NAME_OP) ||
999 (Op->Common.AmlOpcode == AML_RETURN_OP))
1007 #endif /* ACPI_DISASSEMBLER */