1 /*******************************************************************************
3 * Module Name: dmwalk - AML disassembly tree walk
6 ******************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
119 #include "acparser.h"
121 #include "acdisasm.h"
125 #ifdef ACPI_DISASSEMBLER
127 #define _COMPONENT ACPI_CA_DEBUGGER
128 ACPI_MODULE_NAME ("dmwalk")
131 #define DB_FULL_OP_INFO "%5.5X #%4.4hX "
134 /*******************************************************************************
136 * FUNCTION: AcpiDmDisassemble
138 * PARAMETERS: Origin - Starting object
139 * NumOpcodes - Max number of opcodes to be displayed
143 * DESCRIPTION: Disassemble parser object and its children. This is the
144 * main entry point of the disassembler.
146 ******************************************************************************/
150 ACPI_WALK_STATE *WalkState,
151 ACPI_PARSE_OBJECT *Origin,
154 ACPI_PARSE_OBJECT *Op = Origin;
155 ACPI_OP_WALK_INFO Info;
164 AcpiDmWalkParseTree (Op, AcpiDmDescendingOp, AcpiDmAscendingOp, &Info);
170 /*******************************************************************************
172 * FUNCTION: AcpiDmWalkParseTree
174 * PARAMETERS: DescendingCallback - Called during tree descent
175 * AscendingCallback - Called during tree ascent
176 * Context - To be passed to the callbacks
178 * RETURN: Status from callback(s)
180 * DESCRIPTION: Walk the entire parse tree.
182 ******************************************************************************/
185 AcpiDmWalkParseTree (
186 ACPI_PARSE_OBJECT *Op,
187 ASL_WALK_CALLBACK DescendingCallback,
188 ASL_WALK_CALLBACK AscendingCallback,
191 BOOLEAN NodePreviouslyVisited;
192 ACPI_PARSE_OBJECT *StartOp = Op;
194 ACPI_PARSE_OBJECT *Next;
195 ACPI_OP_WALK_INFO *Info = Context;
199 NodePreviouslyVisited = FALSE;
203 if (NodePreviouslyVisited)
205 Status = AscendingCallback (Op, Info->Level, Context);
206 if (ACPI_FAILURE (Status))
213 /* Let the callback process the node */
215 Status = DescendingCallback (Op, Info->Level, Context);
216 if (ACPI_SUCCESS (Status))
218 /* Visit children first, once */
220 Next = AcpiPsGetArg (Op, 0);
228 else if (Status != AE_CTRL_DEPTH)
230 /* Exit immediately on any error */
236 /* Terminate walk at start op */
243 /* No more children, re-visit this node */
245 if (!NodePreviouslyVisited)
247 NodePreviouslyVisited = TRUE;
251 /* No more children, visit peers */
255 Op = Op->Common.Next;
256 NodePreviouslyVisited = FALSE;
260 /* No peers, re-visit parent */
262 if (Info->Level != 0 )
267 Op = Op->Common.Parent;
268 NodePreviouslyVisited = TRUE;
272 /* If we get here, the walk completed with no errors */
278 /*******************************************************************************
280 * FUNCTION: AcpiDmBlockType
282 * PARAMETERS: Op - Object to be examined
286 * DESCRIPTION: Type of block for this op (parens or braces)
288 ******************************************************************************/
292 ACPI_PARSE_OBJECT *Op)
294 const ACPI_OPCODE_INFO *OpInfo;
302 switch (Op->Common.AmlOpcode)
306 return (BLOCK_BRACE);
311 case AML_PROCESSOR_OP:
312 case AML_POWER_RES_OP:
313 case AML_THERMAL_ZONE_OP:
317 case AML_INDEX_FIELD_OP:
318 case AML_BANK_FIELD_OP:
320 return (BLOCK_PAREN | BLOCK_BRACE);
324 if (Op->Common.DisasmOpcode == ACPI_DASM_UNICODE)
329 /*lint -fallthrough */
332 case AML_VAR_PACKAGE_OP:
334 return (BLOCK_PAREN | BLOCK_BRACE);
338 return (BLOCK_PAREN);
342 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
343 if (OpInfo->Flags & AML_HAS_ARGS)
345 return (BLOCK_PAREN);
353 /*******************************************************************************
355 * FUNCTION: AcpiDmListType
357 * PARAMETERS: Op - Object to be examined
361 * DESCRIPTION: Type of block for this op (parens or braces)
363 ******************************************************************************/
367 ACPI_PARSE_OBJECT *Op)
369 const ACPI_OPCODE_INFO *OpInfo;
377 switch (Op->Common.AmlOpcode)
384 case AML_POWER_RES_OP:
385 case AML_PROCESSOR_OP:
386 case AML_THERMAL_ZONE_OP:
390 case AML_INDEX_FIELD_OP:
391 case AML_BANK_FIELD_OP:
397 case AML_VAR_PACKAGE_OP:
399 return (BLOCK_COMMA_LIST);
403 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
404 if (OpInfo->Flags & AML_HAS_ARGS)
406 return (BLOCK_COMMA_LIST);
414 /*******************************************************************************
416 * FUNCTION: AcpiDmDescendingOp
418 * PARAMETERS: ASL_WALK_CALLBACK
422 * DESCRIPTION: First visitation of a parse object during tree descent.
423 * Decode opcode name and begin parameter list(s), if any.
425 ******************************************************************************/
429 ACPI_PARSE_OBJECT *Op,
433 ACPI_OP_WALK_INFO *Info = Context;
434 const ACPI_OPCODE_INFO *OpInfo;
436 ACPI_PARSE_OBJECT *NextOp;
437 ACPI_EXTERNAL_LIST *NextExternal;
440 if (Op->Common.DisasmFlags & ACPI_PARSEOP_IGNORE)
442 /* Ignore this op -- it was handled elsewhere */
444 return (AE_CTRL_DEPTH);
447 /* Level 0 is at the Definition Block level */
451 /* In verbose mode, print the AML offset, opcode and depth count */
453 VERBOSE_PRINT ((DB_FULL_OP_INFO, (UINT32) Op->Common.AmlOffset,
454 Op->Common.AmlOpcode));
456 if (Op->Common.AmlOpcode == AML_SCOPE_OP)
458 /* This is the beginning of the Definition Block */
460 AcpiOsPrintf ("{\n");
462 /* Emit all External() declarations here */
464 if (AcpiGbl_ExternalList)
466 AcpiOsPrintf (" /*\n * These objects were referenced but not defined in this table\n */\n");
468 /* Walk the list of externals (unresolved references) found during parsing */
470 while (AcpiGbl_ExternalList)
472 AcpiOsPrintf (" External (%s)\n", AcpiGbl_ExternalList->Path);
474 NextExternal = AcpiGbl_ExternalList->Next;
475 ACPI_MEM_FREE (AcpiGbl_ExternalList->Path);
476 ACPI_MEM_FREE (AcpiGbl_ExternalList);
477 AcpiGbl_ExternalList = NextExternal;
485 else if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
486 (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)) &&
487 (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP))
489 /* This is a first-level element of a term list, indent a new line */
491 AcpiDmIndent (Level);
494 /* Print the opcode name */
496 AcpiDmDisassembleOneOp (NULL, Info, 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 ((char *) &Name);
546 if (Op->Common.AmlOpcode != AML_INT_NAMEDFIELD_OP)
548 AcpiDmValidateName ((char *) &Name, Op);
549 if (AcpiGbl_DbOpt_verbose)
551 (void) AcpiPsDisplayObjectPathname (NULL, Op);
557 switch (Op->Common.AmlOpcode)
561 AcpiDmMethodFlags (Op);
568 /* Check for _HID and related EISAID() */
577 AcpiDmRegionFlags (Op);
581 case AML_POWER_RES_OP:
583 /* Mark the next two Ops as part of the parameter list */
586 NextOp = AcpiPsGetDepthNext (NULL, Op);
587 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
589 NextOp = NextOp->Common.Next;
590 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
594 case AML_PROCESSOR_OP:
596 /* Mark the next three Ops as part of the parameter list */
599 NextOp = AcpiPsGetDepthNext (NULL, Op);
600 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
602 NextOp = NextOp->Common.Next;
603 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
605 NextOp = NextOp->Common.Next;
606 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
624 case AML_THERMAL_ZONE_OP:
632 AcpiOsPrintf ("*** Unhandled named opcode\n");
637 else switch (Op->Common.AmlOpcode)
640 case AML_BANK_FIELD_OP:
641 case AML_INDEX_FIELD_OP:
645 /* Name of the parent OperationRegion */
647 NextOp = AcpiPsGetDepthNext (NULL, Op);
648 AcpiDmNamestring (NextOp->Common.Value.Name);
650 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
652 switch (Op->Common.AmlOpcode)
654 case AML_BANK_FIELD_OP:
658 NextOp = AcpiPsGetDepthNext (NULL, NextOp);
659 AcpiDmNamestring (NextOp->Common.Value.Name);
660 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
664 NextOp = NextOp->Common.Next;
665 AcpiDmDisassembleOneOp (NULL, Info, NextOp);
666 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
670 case AML_INDEX_FIELD_OP:
674 NextOp = AcpiPsGetDepthNext (NULL, NextOp);
675 AcpiDmNamestring (NextOp->Common.Value.Name);
677 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
685 AcpiDmFieldFlags (NextOp);
691 /* The next op is the size parameter */
693 NextOp = AcpiPsGetDepthNext (NULL, Op);
696 /* Single-step support */
701 if (Op->Common.DisasmOpcode == ACPI_DASM_RESOURCE)
704 * We have a resource list. Don't need to output
705 * the buffer size Op. Open up a new block
707 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
708 NextOp = NextOp->Common.Next;
709 AcpiOsPrintf (")\n");
710 AcpiDmIndent (Info->Level);
711 AcpiOsPrintf ("{\n");
715 /* Normal Buffer, mark size as in the parameter list */
717 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
721 case AML_VAR_PACKAGE_OP:
725 /* The next op is the size or predicate parameter */
727 NextOp = AcpiPsGetDepthNext (NULL, Op);
730 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
737 /* The next op is the size or predicate parameter */
739 NextOp = AcpiPsGetDepthNext (NULL, Op);
742 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
758 if (AcpiDmBlockType (Op) & BLOCK_BRACE)
761 AcpiDmIndent (Level);
762 AcpiOsPrintf ("{\n");
770 /*******************************************************************************
772 * FUNCTION: AcpiDmAscendingOp
774 * PARAMETERS: ASL_WALK_CALLBACK
778 * DESCRIPTION: Second visitation of a parse object, during ascent of parse
779 * tree. Close out any parameter lists and complete the opcode.
781 ******************************************************************************/
785 ACPI_PARSE_OBJECT *Op,
789 ACPI_OP_WALK_INFO *Info = Context;
792 if (Op->Common.DisasmFlags & ACPI_PARSEOP_IGNORE)
794 /* Ignore this op -- it was handled elsewhere */
799 if ((Level == 0) && (Op->Common.AmlOpcode == AML_SCOPE_OP))
801 /* Indicates the end of the current descriptor block (table) */
803 AcpiOsPrintf ("}\n\n");
807 switch (AcpiDmBlockType (Op))
811 /* Completed an op that has arguments, add closing paren */
815 /* Could be a nested operator, check if comma required */
817 if (!AcpiDmCommaIfListMember (Op))
819 if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
820 (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)) &&
821 (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP))
823 /* This is a first-level element of a term list, start a new line */
832 case (BLOCK_BRACE | BLOCK_PAREN):
834 /* Completed an op that has a term list, add closing brace */
836 if (Op->Common.DisasmFlags & ACPI_PARSEOP_EMPTY_TERMLIST)
842 AcpiDmIndent (Level);
846 AcpiDmCommaIfListMember (Op);
848 if (AcpiDmBlockType (Op->Common.Parent) != BLOCK_PAREN)
851 if (!(Op->Common.DisasmFlags & ACPI_PARSEOP_EMPTY_TERMLIST))
853 if ((Op->Common.AmlOpcode == AML_IF_OP) &&
855 (Op->Common.Next->Common.AmlOpcode == AML_ELSE_OP))
860 if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
874 /* Could be a nested operator, check if comma required */
876 if (!AcpiDmCommaIfListMember (Op))
878 if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
879 (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)) &&
880 (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP))
882 /* This is a first-level element of a term list, start a new line */
887 else if (Op->Common.Parent)
889 switch (Op->Common.Parent->Common.AmlOpcode)
892 case AML_VAR_PACKAGE_OP:
894 if (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST))
908 if (Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)
910 if ((Op->Common.Next) &&
911 (Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST))
917 * Just completed a parameter node for something like "Buffer (param)".
918 * Close the paren and open up the term list block with a brace
922 AcpiOsPrintf (")\n");
923 AcpiDmIndent (Level - 1);
924 AcpiOsPrintf ("{\n");
928 Op->Common.Parent->Common.DisasmFlags |= ACPI_PARSEOP_EMPTY_TERMLIST;
929 AcpiOsPrintf (") {");
933 if ((Op->Common.AmlOpcode == AML_NAME_OP) ||
934 (Op->Common.AmlOpcode == AML_RETURN_OP))
942 #endif /* ACPI_DISASSEMBLER */