1 /******************************************************************************
3 * Module Name: adwalk - Application-level disassembler parse tree walk routines
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2019, 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 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
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.
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.
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.
150 *****************************************************************************/
152 #include <contrib/dev/acpica/include/acpi.h>
153 #include <contrib/dev/acpica/include/accommon.h>
154 #include <contrib/dev/acpica/include/acparser.h>
155 #include <contrib/dev/acpica/include/amlcode.h>
156 #include <contrib/dev/acpica/include/acdisasm.h>
157 #include <contrib/dev/acpica/include/acdispat.h>
158 #include <contrib/dev/acpica/include/acnamesp.h>
159 #include <contrib/dev/acpica/include/acapps.h>
162 #define _COMPONENT ACPI_TOOLS
163 ACPI_MODULE_NAME ("adwalk")
166 * aslmap - opcode mappings and reserved method names
169 AslMapNamedOpcodeToDataType (
172 /* Local prototypes */
175 AcpiDmFindOrphanDescending (
176 ACPI_PARSE_OBJECT *Op,
181 AcpiDmDumpDescending (
182 ACPI_PARSE_OBJECT *Op,
187 AcpiDmXrefDescendingOp (
188 ACPI_PARSE_OBJECT *Op,
193 AcpiDmCommonAscendingOp (
194 ACPI_PARSE_OBJECT *Op,
199 AcpiDmLoadDescendingOp (
200 ACPI_PARSE_OBJECT *Op,
205 AcpiDmInspectPossibleArgs (
206 UINT32 CurrentOpArgCount,
208 ACPI_PARSE_OBJECT *Op);
211 AcpiDmCommonDescendingOp (
212 ACPI_PARSE_OBJECT *Op,
217 AcpiDmProcessResourceDescriptors (
218 ACPI_PARSE_OBJECT *Op,
222 /*******************************************************************************
224 * FUNCTION: AcpiDmDumpTree
226 * PARAMETERS: Origin - Starting object
230 * DESCRIPTION: Parse tree walk to format and output the nodes
232 ******************************************************************************/
236 ACPI_PARSE_OBJECT *Origin)
238 ACPI_OP_WALK_INFO Info;
246 AcpiOsPrintf ("/*\nAML Parse Tree\n\n");
250 Info.WalkState = NULL;
252 AcpiDmWalkParseTree (Origin, AcpiDmDumpDescending, NULL, &Info);
253 AcpiOsPrintf ("*/\n\n");
257 /*******************************************************************************
259 * FUNCTION: AcpiDmFindOrphanMethods
261 * PARAMETERS: Origin - Starting object
265 * DESCRIPTION: Parse tree walk to find "orphaned" method invocations -- methods
266 * that are not resolved in the namespace
268 ******************************************************************************/
271 AcpiDmFindOrphanMethods (
272 ACPI_PARSE_OBJECT *Origin)
274 ACPI_OP_WALK_INFO Info;
284 Info.WalkState = NULL;
286 AcpiDmWalkParseTree (Origin, AcpiDmFindOrphanDescending, NULL, &Info);
290 /*******************************************************************************
292 * FUNCTION: AcpiDmFinishNamespaceLoad
294 * PARAMETERS: ParseTreeRoot - Root of the parse tree
295 * NamespaceRoot - Root of the internal namespace
296 * OwnerId - OwnerId of the table to be disassembled
300 * DESCRIPTION: Load all namespace items that are created within control
301 * methods. Used before namespace cross reference
303 ******************************************************************************/
306 AcpiDmFinishNamespaceLoad (
307 ACPI_PARSE_OBJECT *ParseTreeRoot,
308 ACPI_NAMESPACE_NODE *NamespaceRoot,
309 ACPI_OWNER_ID OwnerId)
312 ACPI_OP_WALK_INFO Info;
313 ACPI_WALK_STATE *WalkState;
321 /* Create and initialize a new walk state */
323 WalkState = AcpiDsCreateWalkState (OwnerId, ParseTreeRoot, NULL, NULL);
329 Status = AcpiDsScopeStackPush (NamespaceRoot, NamespaceRoot->Type,
331 if (ACPI_FAILURE (Status))
338 Info.WalkState = WalkState;
340 AcpiDmWalkParseTree (ParseTreeRoot, AcpiDmLoadDescendingOp,
341 AcpiDmCommonAscendingOp, &Info);
342 ACPI_FREE (WalkState);
346 /*******************************************************************************
348 * FUNCTION: AcpiDmCrossReferenceNamespace
350 * PARAMETERS: ParseTreeRoot - Root of the parse tree
351 * NamespaceRoot - Root of the internal namespace
352 * OwnerId - OwnerId of the table to be disassembled
356 * DESCRIPTION: Cross reference the namespace to create externals
358 ******************************************************************************/
361 AcpiDmCrossReferenceNamespace (
362 ACPI_PARSE_OBJECT *ParseTreeRoot,
363 ACPI_NAMESPACE_NODE *NamespaceRoot,
364 ACPI_OWNER_ID OwnerId)
367 ACPI_OP_WALK_INFO Info;
368 ACPI_WALK_STATE *WalkState;
376 /* Create and initialize a new walk state */
378 WalkState = AcpiDsCreateWalkState (OwnerId, ParseTreeRoot, NULL, NULL);
384 Status = AcpiDsScopeStackPush (NamespaceRoot, NamespaceRoot->Type,
386 if (ACPI_FAILURE (Status))
393 Info.WalkState = WalkState;
395 AcpiDmWalkParseTree (ParseTreeRoot, AcpiDmXrefDescendingOp,
396 AcpiDmCommonAscendingOp, &Info);
397 ACPI_FREE (WalkState);
401 /*******************************************************************************
403 * FUNCTION: AcpiDmConvertParseObjects
405 * PARAMETERS: ParseTreeRoot - Root of the parse tree
406 * NamespaceRoot - Root of the internal namespace
410 * DESCRIPTION: Begin parse tree walk to perform conversions needed for
411 * disassembly. These include resource descriptors and switch/case
414 ******************************************************************************/
417 AcpiDmConvertParseObjects (
418 ACPI_PARSE_OBJECT *ParseTreeRoot,
419 ACPI_NAMESPACE_NODE *NamespaceRoot)
422 ACPI_OP_WALK_INFO Info;
423 ACPI_WALK_STATE *WalkState;
431 /* Create and initialize a new walk state */
433 WalkState = AcpiDsCreateWalkState (0, ParseTreeRoot, NULL, NULL);
439 Status = AcpiDsScopeStackPush (NamespaceRoot, NamespaceRoot->Type,
441 if (ACPI_FAILURE (Status))
443 ACPI_FREE (WalkState);
449 Info.WalkState = WalkState;
451 AcpiDmWalkParseTree (ParseTreeRoot, AcpiDmCommonDescendingOp,
452 AcpiDmCommonAscendingOp, &Info);
453 ACPI_FREE (WalkState);
455 if (AcpiGbl_TempListHead) {
456 AcpiDmClearTempList();
463 /*******************************************************************************
465 * FUNCTION: AcpiDmDumpDescending
467 * PARAMETERS: ASL_WALK_CALLBACK
471 * DESCRIPTION: Format and print contents of one parse Op.
473 ******************************************************************************/
476 AcpiDmDumpDescending (
477 ACPI_PARSE_OBJECT *Op,
481 ACPI_OP_WALK_INFO *Info = Context;
490 /* Most of the information (count, level, name) here */
493 AcpiOsPrintf ("% 5d [%2.2d] ", Info->Count, Level);
494 AcpiDmIndent (Level);
495 AcpiOsPrintf ("%-28s", AcpiPsGetOpcodeName (Op->Common.AmlOpcode));
497 /* Extra info is helpful */
499 switch (Op->Common.AmlOpcode)
503 AcpiOsPrintf ("%2.2X", (UINT32) Op->Common.Value.Integer);
508 AcpiOsPrintf ("%4.4X", (UINT32) Op->Common.Value.Integer);
513 AcpiOsPrintf ("%8.8X", (UINT32) Op->Common.Value.Integer);
518 AcpiOsPrintf ("%8.8X%8.8X", ACPI_FORMAT_UINT64 (Op->Common.Value.Integer));
521 case AML_INT_NAMEPATH_OP:
523 if (Op->Common.Value.String)
525 AcpiNsExternalizeName (ACPI_UINT32_MAX, Op->Common.Value.String,
527 AcpiOsPrintf ("%s %p", Path, Op->Common.Node);
532 AcpiOsPrintf ("[NULL]");
540 AcpiOsPrintf ("%4.4s",
541 ACPI_CAST_PTR (char, &Op->Named.Name));
544 case AML_INT_NAMEDFIELD_OP:
546 AcpiOsPrintf ("%4.4s Length: (bits) %8.8X%8.8X (bytes) %8.8X%8.8X",
547 ACPI_CAST_PTR (char, &Op->Named.Name),
548 ACPI_FORMAT_UINT64 (Op->Common.Value.Integer),
549 ACPI_FORMAT_UINT64 (Op->Common.Value.Integer / 8));
563 /*******************************************************************************
565 * FUNCTION: AcpiDmFindOrphanDescending
567 * PARAMETERS: ASL_WALK_CALLBACK
571 * DESCRIPTION: Check namepath Ops for orphaned method invocations
573 * Note: Parts of this are experimental, under possible further development.
575 ******************************************************************************/
578 AcpiDmFindOrphanDescending (
579 ACPI_PARSE_OBJECT *Op,
583 const ACPI_OPCODE_INFO *OpInfo;
584 ACPI_PARSE_OBJECT *ChildOp;
585 ACPI_PARSE_OBJECT *NextOp;
586 ACPI_PARSE_OBJECT *ParentOp;
595 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
597 switch (Op->Common.AmlOpcode)
599 #ifdef ACPI_UNDER_DEVELOPMENT
602 ChildOp = Op->Common.Value.Arg;
603 if ((ChildOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
604 !ChildOp->Common.Node)
606 AcpiNsExternalizeName (ACPI_UINT32_MAX, ChildOp->Common.Value.String,
608 AcpiOsPrintf ("/* %-16s A-NAMEPATH: %s */\n",
609 Op->Common.AmlOpName, Path);
612 NextOp = Op->Common.Next;
615 /* This NamePath has no args, assume it is an integer */
617 AcpiDmAddOpToExternalList (ChildOp,
618 ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0, 0);
622 ArgCount = AcpiDmInspectPossibleArgs (3, 1, NextOp);
623 AcpiOsPrintf ("/* A-CHILDREN: %u Actual %u */\n",
624 ArgCount, AcpiDmCountChildren (Op));
628 /* One Arg means this is just a Store(Name,Target) */
630 AcpiDmAddOpToExternalList (ChildOp,
631 ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0, 0);
635 AcpiDmAddOpToExternalList (ChildOp,
636 ChildOp->Common.Value.String, ACPI_TYPE_METHOD, ArgCount, 0);
644 ChildOp = Op->Common.Value.Arg;
645 if ((ChildOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
646 !ChildOp->Common.Node)
648 NextOp = Op->Common.Next;
651 /* This NamePath has no args, assume it is an integer */
653 AcpiDmAddOpToExternalList (ChildOp,
654 ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0, 0);
658 ArgCount = AcpiDmInspectPossibleArgs (2, 1, NextOp);
661 /* One Arg means this is just a Store(Name,Target) */
663 AcpiDmAddOpToExternalList (ChildOp,
664 ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, ArgCount, 0);
668 AcpiDmAddOpToExternalList (ChildOp,
669 ChildOp->Common.Value.String, ACPI_TYPE_METHOD, ArgCount, 0);
673 case AML_INT_NAMEPATH_OP:
675 /* Must examine parent to see if this namepath is an argument */
677 ParentOp = Op->Common.Parent;
678 OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Common.AmlOpcode);
680 if ((OpInfo->Class != AML_CLASS_EXECUTE) &&
681 (OpInfo->Class != AML_CLASS_CREATE) &&
682 (OpInfo->ObjectType != ACPI_TYPE_LOCAL_ALIAS) &&
683 (ParentOp->Common.AmlOpcode != AML_INT_METHODCALL_OP) &&
686 ArgCount = AcpiDmInspectPossibleArgs (0, 0, Op);
689 * Check if namepath is a predicate for if/while or lone parameter to
694 if (((ParentOp->Common.AmlOpcode == AML_IF_OP) ||
695 (ParentOp->Common.AmlOpcode == AML_WHILE_OP) ||
696 (ParentOp->Common.AmlOpcode == AML_RETURN_OP)) &&
698 /* And namepath is the first argument */
699 (ParentOp->Common.Value.Arg == Op))
701 AcpiDmAddOpToExternalList (Op,
702 Op->Common.Value.String, ACPI_TYPE_INTEGER, 0, 0);
708 * This is a standalone namestring (not a parameter to another
709 * operator) - it *must* be a method invocation, nothing else is
710 * grammatically possible.
712 AcpiDmAddOpToExternalList (Op,
713 Op->Common.Value.String, ACPI_TYPE_METHOD, ArgCount, 0);
726 /*******************************************************************************
728 * FUNCTION: AcpiDmLoadDescendingOp
730 * PARAMETERS: ASL_WALK_CALLBACK
734 * DESCRIPTION: Descending handler for namespace control method object load
736 ******************************************************************************/
739 AcpiDmLoadDescendingOp (
740 ACPI_PARSE_OBJECT *Op,
744 ACPI_OP_WALK_INFO *Info = Context;
745 const ACPI_OPCODE_INFO *OpInfo;
746 ACPI_WALK_STATE *WalkState;
747 ACPI_OBJECT_TYPE ObjectType;
750 ACPI_PARSE_OBJECT *NextOp;
751 ACPI_NAMESPACE_NODE *Node;
753 BOOLEAN PreDefined = FALSE;
754 UINT8 PreDefineIndex = 0;
757 WalkState = Info->WalkState;
758 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
759 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
761 /* Only interested in operators that create new names */
763 if (!(OpInfo->Flags & AML_NAMED) &&
764 !(OpInfo->Flags & AML_CREATE))
769 /* Get the NamePath from the appropriate place */
771 if (OpInfo->Flags & AML_NAMED)
773 /* For all named operators, get the new name */
775 Path = Op->Named.Path;
777 if (!Path && Op->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
779 *ACPI_CAST_PTR (UINT32, &FieldPath[0]) = Op->Named.Name;
784 else if (OpInfo->Flags & AML_CREATE)
786 /* New name is the last child */
788 NextOp = Op->Common.Value.Arg;
790 while (NextOp->Common.Next)
792 NextOp = NextOp->Common.Next;
795 Path = NextOp->Common.Value.String;
803 /* Insert the name into the namespace */
805 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
806 ACPI_IMODE_LOAD_PASS2, ACPI_NS_DONT_OPEN_SCOPE,
809 Op->Common.Node = Node;
811 if (ACPI_SUCCESS (Status))
813 /* Check if it's a predefined node */
815 while (AcpiGbl_PreDefinedNames[PreDefineIndex].Name)
817 if (ACPI_COMPARE_NAMESEG (Node->Name.Ascii,
818 AcpiGbl_PreDefinedNames[PreDefineIndex].Name))
828 * Set node owner id if it satisfies all the following conditions:
829 * 1) Not a predefined node, _SB_ etc
830 * 2) Not the root node
831 * 3) Not a node created by Scope
834 if (!PreDefined && Node != AcpiGbl_RootNode &&
835 Op->Common.AmlOpcode != AML_SCOPE_OP)
837 Node->OwnerId = WalkState->OwnerId;
844 if (AcpiNsOpensScope (ObjectType))
848 Status = AcpiDsScopeStackPush (Op->Common.Node, ObjectType,
850 if (ACPI_FAILURE (Status))
861 /*******************************************************************************
863 * FUNCTION: AcpiDmXrefDescendingOp
865 * PARAMETERS: ASL_WALK_CALLBACK
869 * DESCRIPTION: Descending handler for namespace cross reference
871 ******************************************************************************/
874 AcpiDmXrefDescendingOp (
875 ACPI_PARSE_OBJECT *Op,
879 ACPI_OP_WALK_INFO *Info = Context;
880 const ACPI_OPCODE_INFO *OpInfo;
881 ACPI_WALK_STATE *WalkState;
882 ACPI_OBJECT_TYPE ObjectType;
883 ACPI_OBJECT_TYPE ObjectType2;
886 ACPI_PARSE_OBJECT *NextOp;
887 ACPI_NAMESPACE_NODE *Node;
888 ACPI_OPERAND_OBJECT *Object;
889 UINT32 ParamCount = 0;
894 WalkState = Info->WalkState;
895 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
896 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
898 if ((!(OpInfo->Flags & AML_NAMED)) &&
899 (!(OpInfo->Flags & AML_CREATE)) &&
900 (Op->Common.AmlOpcode != AML_INT_NAMEPATH_OP) &&
901 (Op->Common.AmlOpcode != AML_NOTIFY_OP))
906 /* Get the NamePath from the appropriate place */
908 if (OpInfo->Flags & AML_NAMED)
911 * Only these two operators (Alias, Scope) refer to an existing
912 * name, it is the first argument
914 if (Op->Common.AmlOpcode == AML_ALIAS_OP)
916 ObjectType = ACPI_TYPE_ANY;
918 NextOp = Op->Common.Value.Arg;
919 NextOp = NextOp->Common.Value.Arg;
920 if (NextOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
922 Path = NextOp->Common.Value.String;
925 else if (Op->Common.AmlOpcode == AML_SCOPE_OP ||
926 Op->Common.AmlOpcode == AML_EXTERNAL_OP)
928 Path = Op->Named.Path;
931 else if (OpInfo->Flags & AML_CREATE)
933 /* Referenced Buffer Name is the first child */
935 ObjectType = ACPI_TYPE_BUFFER; /* Change from TYPE_BUFFER_FIELD */
937 NextOp = Op->Common.Value.Arg;
938 if (NextOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
940 Path = NextOp->Common.Value.String;
943 else if (Op->Common.AmlOpcode == AML_NOTIFY_OP)
945 Path = Op->Common.Value.Arg->Asl.Value.String;
949 Path = Op->Common.Value.String;
958 * Lookup the name in the namespace. Name must exist at this point, or it
959 * is an invalid reference.
961 * The namespace is also used as a lookup table for references to resource
962 * descriptors and the fields within them.
965 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,
966 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
969 if (ACPI_SUCCESS (Status) && (Node->Flags & ANOBJ_IS_EXTERNAL))
971 /* Node was created by an External() statement */
973 Status = AE_NOT_FOUND;
976 if (ACPI_FAILURE (Status))
978 if (Status == AE_NOT_FOUND)
981 * Add this symbol as an external declaration, except if the
982 * parent is a CondRefOf operator. For this operator, we do not
983 * need an external, nor do we want one, since this can cause
984 * disassembly problems if the symbol is actually a control
987 if (!(Op->Asl.Parent &&
988 (Op->Asl.Parent->Asl.AmlOpcode == AML_CONDITIONAL_REF_OF_OP)))
992 AcpiDmAddNodeToExternalList (Node,
993 (UINT8) ObjectType, 7, Flags);
997 AcpiDmAddOpToExternalList (Op, Path,
998 (UINT8) ObjectType, 7, Flags);
1005 * Found the node, but check if it came from an external table.
1006 * Add it to external list. Note: Node->OwnerId == 0 indicates
1007 * one of the built-in ACPI Names (_OS_ etc.) which can safely
1010 else if (Node->OwnerId &&
1011 (WalkState->OwnerId != Node->OwnerId))
1013 ObjectType2 = ObjectType;
1015 Object = AcpiNsGetAttachedObject (Node);
1018 ObjectType2 = Object->Common.Type;
1019 if (ObjectType2 == ACPI_TYPE_METHOD)
1021 ParamCount = Object->Method.ParamCount;
1025 Pathname = AcpiNsGetExternalPathname (Node);
1028 return (AE_NO_MEMORY);
1031 AcpiDmAddNodeToExternalList (Node, (UINT8) ObjectType2,
1032 ParamCount, ACPI_EXT_RESOLVED_REFERENCE);
1034 ACPI_FREE (Pathname);
1035 Op->Common.Node = Node;
1039 Op->Common.Node = Node;
1044 /* Open new scope if necessary */
1046 if (AcpiNsOpensScope (ObjectType))
1048 if (Op->Common.Node)
1050 Status = AcpiDsScopeStackPush (Op->Common.Node, ObjectType,
1052 if (ACPI_FAILURE (Status))
1062 /*******************************************************************************
1064 * FUNCTION: AcpiDmCommonDescendingOp
1066 * PARAMETERS: ASL_WALK_CALLBACK
1068 * RETURN: ACPI_STATUS
1070 * DESCRIPTION: Perform parse tree preprocessing before main disassembly walk.
1072 ******************************************************************************/
1075 AcpiDmCommonDescendingOp (
1076 ACPI_PARSE_OBJECT *Op,
1083 /* Resource descriptor conversion */
1085 Status = AcpiDmProcessResourceDescriptors (Op, Level, Context);
1086 if (ACPI_FAILURE (Status))
1091 /* Switch/Case conversion */
1093 Status = AcpiDmProcessSwitch (Op);
1098 /*******************************************************************************
1100 * FUNCTION: AcpiDmProcessResourceDescriptors
1102 * PARAMETERS: ASL_WALK_CALLBACK
1104 * RETURN: ACPI_STATUS
1106 * DESCRIPTION: Convert fixed-offset references to resource descriptors to
1107 * symbolic references. Should only be called after namespace has
1108 * been cross referenced.
1110 ******************************************************************************/
1113 AcpiDmProcessResourceDescriptors (
1114 ACPI_PARSE_OBJECT *Op,
1118 ACPI_OP_WALK_INFO *Info = Context;
1119 const ACPI_OPCODE_INFO *OpInfo;
1120 ACPI_WALK_STATE *WalkState;
1121 ACPI_OBJECT_TYPE ObjectType;
1125 WalkState = Info->WalkState;
1126 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
1128 /* Open new scope if necessary */
1130 ObjectType = OpInfo->ObjectType;
1131 if (AcpiNsOpensScope (ObjectType))
1133 if (Op->Common.Node)
1136 Status = AcpiDsScopeStackPush (Op->Common.Node, ObjectType,
1138 if (ACPI_FAILURE (Status))
1146 * Check if this operator contains a reference to a resource descriptor.
1147 * If so, convert the reference into a symbolic reference.
1149 AcpiDmCheckResourceReference (Op, WalkState);
1153 /*******************************************************************************
1155 * FUNCTION: AcpiDmCommonAscendingOp
1157 * PARAMETERS: ASL_WALK_CALLBACK
1161 * DESCRIPTION: Ascending handler for combined parse/namespace walks. Closes
1162 * scope if necessary.
1164 ******************************************************************************/
1167 AcpiDmCommonAscendingOp (
1168 ACPI_PARSE_OBJECT *Op,
1172 ACPI_OP_WALK_INFO *Info = Context;
1173 ACPI_OBJECT_TYPE ObjectType;
1176 /* Close scope if necessary */
1178 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
1180 if (AcpiNsOpensScope (ObjectType))
1182 (void) AcpiDsScopeStackPop (Info->WalkState);
1188 /*******************************************************************************
1190 * FUNCTION: AcpiDmInspectPossibleArgs
1192 * PARAMETERS: CurrentOpArgCount - Which arg of the current op was the
1193 * possible method invocation found
1194 * TargetCount - Number of targets (0,1,2) for this op
1199 * DESCRIPTION: Examine following args and next ops for possible arguments
1200 * for an unrecognized method invocation.
1202 ******************************************************************************/
1205 AcpiDmInspectPossibleArgs (
1206 UINT32 CurrentOpArgCount,
1208 ACPI_PARSE_OBJECT *Op)
1210 const ACPI_OPCODE_INFO *OpInfo;
1212 UINT32 ArgumentCount = 0;
1213 ACPI_PARSE_OBJECT *NextOp;
1214 ACPI_PARSE_OBJECT *ExecuteOp;
1222 /* Lookahead for the maximum number of possible arguments */
1224 NextOp = Op->Common.Next;
1226 for (i = 0; (i < ACPI_METHOD_NUM_ARGS) && NextOp; i++)
1228 OpInfo = AcpiPsGetOpcodeInfo (NextOp->Common.AmlOpcode);
1230 /* Any one of these operators is "very probably" not a method arg */
1232 if ((NextOp->Common.AmlOpcode == AML_STORE_OP) ||
1233 (NextOp->Common.AmlOpcode == AML_NOTIFY_OP) ||
1234 (OpInfo->Class == AML_CLASS_CONTROL) ||
1235 (OpInfo->Class == AML_CLASS_CREATE) ||
1236 (OpInfo->Class == AML_CLASS_NAMED_OBJECT))
1241 if (OpInfo->Class == AML_CLASS_EXECUTE)
1243 /* Probable that this is method arg if there is no target */
1245 ExecuteOp = NextOp->Common.Value.Arg;
1248 if ((ExecuteOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
1249 (ExecuteOp->Common.Value.Arg == NULL))
1251 /* No target, could be a method arg */
1256 if (NextOp->Common.AmlOpcode == AML_REF_OF_OP)
1261 ExecuteOp = ExecuteOp->Common.Next;
1266 /* Has a target, not method arg */
1268 return (ArgumentCount);
1273 NextOp = NextOp->Common.Next;
1276 return (ArgumentCount);