1 /******************************************************************************
3 * Module Name: aslwalks.c - major analytical parse tree walks
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2011, 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 "aslcompiler.h"
118 #include "aslcompiler.y.h"
119 #include "acparser.h"
123 #define _COMPONENT ACPI_COMPILER
124 ACPI_MODULE_NAME ("aslwalks")
127 /*******************************************************************************
129 * FUNCTION: AnMethodAnalysisWalkBegin
131 * PARAMETERS: ASL_WALK_CALLBACK
135 * DESCRIPTION: Descending callback for the analysis walk. Check methods for:
136 * 1) Initialized local variables
140 ******************************************************************************/
143 AnMethodAnalysisWalkBegin (
144 ACPI_PARSE_OBJECT *Op,
148 ASL_ANALYSIS_WALK_INFO *WalkInfo = (ASL_ANALYSIS_WALK_INFO *) Context;
149 ASL_METHOD_INFO *MethodInfo = WalkInfo->MethodStack;
150 ACPI_PARSE_OBJECT *Next;
151 UINT32 RegisterNumber;
153 char LocalName[] = "Local0";
154 char ArgName[] = "Arg0";
155 ACPI_PARSE_OBJECT *ArgNode;
156 ACPI_PARSE_OBJECT *NextType;
157 ACPI_PARSE_OBJECT *NextParamType;
158 UINT8 ActualArgs = 0;
161 switch (Op->Asl.ParseOpcode)
167 /* Create and init method info */
169 MethodInfo = UtLocalCalloc (sizeof (ASL_METHOD_INFO));
170 MethodInfo->Next = WalkInfo->MethodStack;
173 WalkInfo->MethodStack = MethodInfo;
175 /* Get the name node, ignored here */
177 Next = Op->Asl.Child;
179 /* Get the NumArguments node */
181 Next = Next->Asl.Next;
182 MethodInfo->NumArguments = (UINT8)
183 (((UINT8) Next->Asl.Value.Integer) & 0x07);
185 /* Get the SerializeRule and SyncLevel nodes, ignored here */
187 Next = Next->Asl.Next;
188 Next = Next->Asl.Next;
191 /* Get the ReturnType node */
193 Next = Next->Asl.Next;
195 NextType = Next->Asl.Child;
198 /* Get and map each of the ReturnTypes */
200 MethodInfo->ValidReturnTypes |= AnMapObjTypeToBtype (NextType);
201 NextType->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
202 NextType = NextType->Asl.Next;
205 /* Get the ParameterType node */
207 Next = Next->Asl.Next;
209 NextType = Next->Asl.Child;
212 if (NextType->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
214 NextParamType = NextType->Asl.Child;
215 while (NextParamType)
217 MethodInfo->ValidArgTypes[ActualArgs] |= AnMapObjTypeToBtype (NextParamType);
218 NextParamType->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
219 NextParamType = NextParamType->Asl.Next;
224 MethodInfo->ValidArgTypes[ActualArgs] =
225 AnMapObjTypeToBtype (NextType);
226 NextType->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
230 NextType = NextType->Asl.Next;
233 if ((MethodInfo->NumArguments) &&
234 (MethodInfo->NumArguments != ActualArgs))
236 /* error: Param list did not match number of args */
239 /* Allow numarguments == 0 for Function() */
241 if ((!MethodInfo->NumArguments) && (ActualArgs))
243 MethodInfo->NumArguments = ActualArgs;
244 ArgNode->Asl.Value.Integer |= ActualArgs;
248 * Actual arguments are initialized at method entry.
249 * All other ArgX "registers" can be used as locals, so we
250 * track their initialization.
252 for (i = 0; i < MethodInfo->NumArguments; i++)
254 MethodInfo->ArgInitialized[i] = TRUE;
259 case PARSEOP_METHODCALL:
262 (Op->Asl.Node == MethodInfo->Op->Asl.Node))
264 AslError (ASL_REMARK, ASL_MSG_RECURSION, Op, Op->Asl.ExternalName);
281 * Local was used outside a control method, or there was an error
282 * in the method declaration.
284 AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD, Op, Op->Asl.ExternalName);
288 RegisterNumber = (Op->Asl.AmlOpcode & 0x000F);
291 * If the local is being used as a target, mark the local
294 if (Op->Asl.CompileFlags & NODE_IS_TARGET)
296 MethodInfo->LocalInitialized[RegisterNumber] = TRUE;
300 * Otherwise, this is a reference, check if the local
301 * has been previously initialized.
303 * The only operator that accepts an uninitialized value is ObjectType()
305 else if ((!MethodInfo->LocalInitialized[RegisterNumber]) &&
306 (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE))
308 LocalName[strlen (LocalName) -1] = (char) (RegisterNumber + 0x30);
309 AslError (ASL_ERROR, ASL_MSG_LOCAL_INIT, Op, LocalName);
325 * Arg was used outside a control method, or there was an error
326 * in the method declaration.
328 AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD, Op, Op->Asl.ExternalName);
332 RegisterNumber = (Op->Asl.AmlOpcode & 0x000F) - 8;
333 ArgName[strlen (ArgName) -1] = (char) (RegisterNumber + 0x30);
336 * If the Arg is being used as a target, mark the local
339 if (Op->Asl.CompileFlags & NODE_IS_TARGET)
341 MethodInfo->ArgInitialized[RegisterNumber] = TRUE;
345 * Otherwise, this is a reference, check if the Arg
346 * has been previously initialized.
348 * The only operator that accepts an uninitialized value is ObjectType()
350 else if ((!MethodInfo->ArgInitialized[RegisterNumber]) &&
351 (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE))
353 AslError (ASL_ERROR, ASL_MSG_ARG_INIT, Op, ArgName);
356 /* Flag this arg if it is not a "real" argument to the method */
358 if (RegisterNumber >= MethodInfo->NumArguments)
360 AslError (ASL_REMARK, ASL_MSG_NOT_PARAMETER, Op, ArgName);
370 * Probably was an error in the method declaration,
371 * no additional error here
373 ACPI_WARNING ((AE_INFO, "%p, No parent method", Op));
377 /* Child indicates a return value */
379 if ((Op->Asl.Child) &&
380 (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG))
382 MethodInfo->NumReturnWithValue++;
386 MethodInfo->NumReturnNoValue++;
392 case PARSEOP_CONTINUE:
394 Next = Op->Asl.Parent;
397 if (Next->Asl.ParseOpcode == PARSEOP_WHILE)
401 Next = Next->Asl.Parent;
406 AslError (ASL_ERROR, ASL_MSG_NO_WHILE, Op, NULL);
413 /* We can range check if the argument is an integer */
415 if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_INTEGER) &&
416 (Op->Asl.Child->Asl.Value.Integer > ACPI_UINT8_MAX))
418 AslError (ASL_ERROR, ASL_MSG_INVALID_TIME, Op, NULL);
426 case PARSEOP_OPERATIONREGION:
427 case PARSEOP_POWERRESOURCE:
428 case PARSEOP_PROCESSOR:
429 case PARSEOP_THERMALZONE:
432 * The first operand is a name to be created in the namespace.
433 * Check against the reserved list.
435 i = ApCheckForPredefinedName (Op, Op->Asl.NameSeg);
436 if (i < ACPI_VALID_RESERVED_NAME_MAX)
438 AslError (ASL_ERROR, ASL_MSG_RESERVED_USE, Op, Op->Asl.ExternalName);
445 /* Typecheck any predefined names statically defined with Name() */
447 ApCheckForPredefinedObject (Op, Op->Asl.NameSeg);
449 /* Special typechecking for _HID */
451 if (!ACPI_STRCMP (METHOD_NAME__HID, Op->Asl.NameSeg))
453 Next = Op->Asl.Child->Asl.Next;
454 AnCheckId (Next, ASL_TYPE_HID);
457 /* Special typechecking for _CID */
459 else if (!ACPI_STRCMP (METHOD_NAME__CID, Op->Asl.NameSeg))
461 Next = Op->Asl.Child->Asl.Next;
463 if ((Next->Asl.ParseOpcode == PARSEOP_PACKAGE) ||
464 (Next->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE))
466 Next = Next->Asl.Child;
469 AnCheckId (Next, ASL_TYPE_CID);
470 Next = Next->Asl.Next;
475 AnCheckId (Next, ASL_TYPE_CID);
489 /*******************************************************************************
491 * FUNCTION: AnMethodAnalysisWalkEnd
493 * PARAMETERS: ASL_WALK_CALLBACK
497 * DESCRIPTION: Ascending callback for analysis walk. Complete method
500 ******************************************************************************/
503 AnMethodAnalysisWalkEnd (
504 ACPI_PARSE_OBJECT *Op,
508 ASL_ANALYSIS_WALK_INFO *WalkInfo = (ASL_ANALYSIS_WALK_INFO *) Context;
509 ASL_METHOD_INFO *MethodInfo = WalkInfo->MethodStack;
512 switch (Op->Asl.ParseOpcode)
518 printf ("No method info for method! [%s]\n", Op->Asl.Namepath);
519 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
520 "No method info for this method");
523 return (AE_AML_INTERNAL);
531 switch (Op->Asl.ParseOpcode)
535 WalkInfo->MethodStack = MethodInfo->Next;
538 * Check if there is no return statement at the end of the
539 * method AND we can actually get there -- i.e., the execution
540 * of the method can possibly terminate without a return statement.
542 if ((!AnLastStatementIsReturn (Op)) &&
543 (!(Op->Asl.CompileFlags & NODE_HAS_NO_EXIT)))
546 * No return statement, and execution can possibly exit
547 * via this path. This is equivalent to Return ()
549 MethodInfo->NumReturnNoValue++;
553 * Check for case where some return statements have a return value
554 * and some do not. Exit without a return statement is a return with
557 if (MethodInfo->NumReturnNoValue &&
558 MethodInfo->NumReturnWithValue)
560 AslError (ASL_WARNING, ASL_MSG_RETURN_TYPES, Op,
561 Op->Asl.ExternalName);
565 * If there are any RETURN() statements with no value, or there is a
566 * control path that allows the method to exit without a return value,
567 * we mark the method as a method that does not return a value. This
568 * knowledge can be used to check method invocations that expect a
571 if (MethodInfo->NumReturnNoValue)
573 if (MethodInfo->NumReturnWithValue)
575 Op->Asl.CompileFlags |= NODE_METHOD_SOME_NO_RETVAL;
579 Op->Asl.CompileFlags |= NODE_METHOD_NO_RETVAL;
584 * Check predefined method names for correct return behavior
585 * and correct number of arguments
587 ApCheckForPredefinedMethod (Op, MethodInfo);
589 /* Special check for two names like _L01 and _E01 in same scope */
591 ApCheckForGpeNameConflict (Op);
592 ACPI_FREE (MethodInfo);
598 /* Special check for two names like _L01 and _E01 in same scope */
600 ApCheckForGpeNameConflict (Op);
607 * If the parent is a predefined method name, attempt to typecheck
608 * the return value. Only static types can be validated.
610 ApCheckPredefinedReturnValue (Op, MethodInfo);
613 * The parent block does not "exit" and continue execution -- the
614 * method is terminated here with the Return() statement.
616 Op->Asl.Parent->Asl.CompileFlags |= NODE_HAS_NO_EXIT;
618 /* Used in the "typing" pass later */
620 Op->Asl.ParentMethod = MethodInfo->Op;
623 * If there is a peer node after the return statement, then this
624 * node is unreachable code -- i.e., it won't be executed because of
625 * the preceeding Return() statement.
629 AslError (ASL_WARNING, ASL_MSG_UNREACHABLE_CODE, Op->Asl.Next, NULL);
636 if ((Op->Asl.CompileFlags & NODE_HAS_NO_EXIT) &&
638 (Op->Asl.Next->Asl.ParseOpcode == PARSEOP_ELSE))
641 * This IF has a corresponding ELSE. The IF block has no exit,
642 * (it contains an unconditional Return)
643 * mark the ELSE block to remember this fact.
645 Op->Asl.Next->Asl.CompileFlags |= NODE_IF_HAS_NO_EXIT;
652 if ((Op->Asl.CompileFlags & NODE_HAS_NO_EXIT) &&
653 (Op->Asl.CompileFlags & NODE_IF_HAS_NO_EXIT))
656 * This ELSE block has no exit and the corresponding IF block
657 * has no exit either. Therefore, the parent node has no exit.
659 Op->Asl.Parent->Asl.CompileFlags |= NODE_HAS_NO_EXIT;
666 if ((Op->Asl.CompileFlags & NODE_HAS_NO_EXIT) &&
669 /* If this node has no exit, then the parent has no exit either */
671 Op->Asl.Parent->Asl.CompileFlags |= NODE_HAS_NO_EXIT;
680 /*******************************************************************************
682 * FUNCTION: AnMethodTypingWalkEnd
684 * PARAMETERS: ASL_WALK_CALLBACK
688 * DESCRIPTION: Ascending callback for typing walk. Complete the method
689 * return analysis. Check methods for:
690 * 1) Initialized local variables
694 ******************************************************************************/
697 AnMethodTypingWalkEnd (
698 ACPI_PARSE_OBJECT *Op,
702 UINT32 ThisNodeBtype;
705 switch (Op->Asl.ParseOpcode)
709 Op->Asl.CompileFlags |= NODE_METHOD_TYPED;
714 if ((Op->Asl.Child) &&
715 (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG))
717 ThisNodeBtype = AnGetBtype (Op->Asl.Child);
719 if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_METHODCALL) &&
720 (ThisNodeBtype == (ACPI_UINT32_MAX -1)))
723 * The called method is untyped at this time (typically a
724 * forward reference).
726 * Check for a recursive method call first.
728 if (Op->Asl.ParentMethod != Op->Asl.Child->Asl.Node->Op)
730 /* We must type the method here */
732 TrWalkParseTree (Op->Asl.Child->Asl.Node->Op,
733 ASL_WALK_VISIT_UPWARD, NULL,
734 AnMethodTypingWalkEnd, NULL);
736 ThisNodeBtype = AnGetBtype (Op->Asl.Child);
740 /* Returns a value, save the value type */
742 if (Op->Asl.ParentMethod)
744 Op->Asl.ParentMethod->Asl.AcpiBtype |= ThisNodeBtype;
757 /*******************************************************************************
759 * FUNCTION: AnOperandTypecheckWalkEnd
761 * PARAMETERS: ASL_WALK_CALLBACK
765 * DESCRIPTION: Ascending callback for analysis walk. Complete method
768 ******************************************************************************/
771 AnOperandTypecheckWalkEnd (
772 ACPI_PARSE_OBJECT *Op,
776 const ACPI_OPCODE_INFO *OpInfo;
777 UINT32 RuntimeArgTypes;
778 UINT32 RuntimeArgTypes2;
779 UINT32 RequiredBtypes;
780 UINT32 ThisNodeBtype;
783 ACPI_PARSE_OBJECT *ArgOp;
787 switch (Op->Asl.AmlOpcode)
789 case AML_RAW_DATA_BYTE:
790 case AML_RAW_DATA_WORD:
791 case AML_RAW_DATA_DWORD:
792 case AML_RAW_DATA_QWORD:
793 case AML_RAW_DATA_BUFFER:
794 case AML_RAW_DATA_CHAIN:
795 case AML_PACKAGE_LENGTH:
796 case AML_UNASSIGNED_OPCODE:
797 case AML_DEFAULT_ARG_OP:
799 /* Ignore the internal (compiler-only) AML opcodes */
807 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
813 ArgOp = Op->Asl.Child;
814 RuntimeArgTypes = OpInfo->RuntimeArgs;
815 OpcodeClass = OpInfo->Class;
817 #ifdef ASL_ERROR_NAMED_OBJECT_IN_WHILE
819 * Update 11/2008: In practice, we can't perform this check. A simple
820 * analysis is not sufficient. Also, it can cause errors when compiling
821 * disassembled code because of the way Switch operators are implemented
822 * (a While(One) loop with a named temp variable created within.)
826 * If we are creating a named object, check if we are within a while loop
827 * by checking if the parent is a WHILE op. This is a simple analysis, but
828 * probably sufficient for many cases.
830 * Allow Scope(), Buffer(), and Package().
832 if (((OpcodeClass == AML_CLASS_NAMED_OBJECT) && (Op->Asl.AmlOpcode != AML_SCOPE_OP)) ||
833 ((OpcodeClass == AML_CLASS_CREATE) && (OpInfo->Flags & AML_NSNODE)))
835 if (Op->Asl.Parent->Asl.AmlOpcode == AML_WHILE_OP)
837 AslError (ASL_ERROR, ASL_MSG_NAMED_OBJECT_IN_WHILE, Op, NULL);
843 * Special case for control opcodes IF/RETURN/WHILE since they
844 * have no runtime arg list (at this time)
846 switch (Op->Asl.AmlOpcode)
852 if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL)
854 /* Check for an internal method */
856 if (AnIsInternalMethod (ArgOp))
861 /* The lone arg is a method call, check it */
863 RequiredBtypes = AnMapArgTypeToBtype (ARGI_INTEGER);
864 if (Op->Asl.AmlOpcode == AML_RETURN_OP)
866 RequiredBtypes = 0xFFFFFFFF;
869 ThisNodeBtype = AnGetBtype (ArgOp);
870 if (ThisNodeBtype == ACPI_UINT32_MAX)
874 AnCheckMethodReturnValue (Op, OpInfo, ArgOp,
875 RequiredBtypes, ThisNodeBtype);
883 /* Ignore the non-executable opcodes */
885 if (RuntimeArgTypes == ARGI_INVALID_OPCODE)
892 case AML_CLASS_EXECUTE:
893 case AML_CLASS_CREATE:
894 case AML_CLASS_CONTROL:
895 case AML_CLASS_RETURN_VALUE:
897 /* TBD: Change class or fix typechecking for these */
899 if ((Op->Asl.AmlOpcode == AML_BUFFER_OP) ||
900 (Op->Asl.AmlOpcode == AML_PACKAGE_OP) ||
901 (Op->Asl.AmlOpcode == AML_VAR_PACKAGE_OP))
906 /* Reverse the runtime argument list */
908 RuntimeArgTypes2 = 0;
909 while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes)))
911 RuntimeArgTypes2 <<= ARG_TYPE_WIDTH;
912 RuntimeArgTypes2 |= ArgType;
913 INCREMENT_ARG_LIST (RuntimeArgTypes);
916 while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes2)))
918 RequiredBtypes = AnMapArgTypeToBtype (ArgType);
920 ThisNodeBtype = AnGetBtype (ArgOp);
921 if (ThisNodeBtype == ACPI_UINT32_MAX)
926 /* Examine the arg based on the required type of the arg */
932 if (ArgOp->Asl.ParseOpcode == PARSEOP_ZERO)
934 /* ZERO is the placeholder for "don't store result" */
936 ThisNodeBtype = RequiredBtypes;
940 if (ArgOp->Asl.ParseOpcode == PARSEOP_INTEGER)
943 * This is the case where an original reference to a resource
944 * descriptor field has been replaced by an (Integer) offset.
945 * These named fields are supported at compile-time only;
946 * the names are not passed to the interpreter (via the AML).
948 if ((ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
949 (ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
951 AslError (ASL_ERROR, ASL_MSG_RESOURCE_FIELD, ArgOp, NULL);
955 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, NULL);
960 if ((ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL) ||
961 (ArgOp->Asl.ParseOpcode == PARSEOP_DEREFOF))
966 ThisNodeBtype = RequiredBtypes;
970 case ARGI_REFERENCE: /* References */
971 case ARGI_INTEGER_REF:
972 case ARGI_OBJECT_REF:
973 case ARGI_DEVICE_REF:
975 switch (ArgOp->Asl.ParseOpcode)
986 /* TBD: implement analysis of current value (type) of the local */
987 /* For now, just treat any local as a typematch */
989 /*ThisNodeBtype = RequiredBtypes;*/
1000 /* Hard to analyze argument types, sow we won't */
1001 /* For now, just treat any arg as a typematch */
1003 /* ThisNodeBtype = RequiredBtypes; */
1023 CommonBtypes = ThisNodeBtype & RequiredBtypes;
1025 if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL)
1027 if (AnIsInternalMethod (ArgOp))
1032 /* Check a method call for a valid return value */
1034 AnCheckMethodReturnValue (Op, OpInfo, ArgOp,
1035 RequiredBtypes, ThisNodeBtype);
1039 * Now check if the actual type(s) match at least one
1040 * bit to the required type
1042 else if (!CommonBtypes)
1044 /* No match -- this is a type mismatch error */
1046 AnFormatBtype (StringBuffer, ThisNodeBtype);
1047 AnFormatBtype (StringBuffer2, RequiredBtypes);
1049 sprintf (MsgBuffer, "[%s] found, %s operator requires [%s]",
1050 StringBuffer, OpInfo->Name, StringBuffer2);
1052 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, MsgBuffer);
1056 ArgOp = ArgOp->Asl.Next;
1057 INCREMENT_ARG_LIST (RuntimeArgTypes2);
1069 /*******************************************************************************
1071 * FUNCTION: AnOtherSemanticAnalysisWalkBegin
1073 * PARAMETERS: ASL_WALK_CALLBACK
1077 * DESCRIPTION: Descending callback for the analysis walk. Checks for
1078 * miscellaneous issues in the code.
1080 ******************************************************************************/
1083 AnOtherSemanticAnalysisWalkBegin (
1084 ACPI_PARSE_OBJECT *Op,
1088 ACPI_PARSE_OBJECT *ArgNode;
1089 ACPI_PARSE_OBJECT *PrevArgNode = NULL;
1090 const ACPI_OPCODE_INFO *OpInfo;
1093 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
1096 * Determine if an execution class operator actually does something by
1097 * checking if it has a target and/or the function return value is used.
1098 * (Target is optional, so a standalone statement can actually do nothing.)
1100 if ((OpInfo->Class == AML_CLASS_EXECUTE) &&
1101 (OpInfo->Flags & AML_HAS_RETVAL) &&
1102 (!AnIsResultUsed (Op)))
1104 if (OpInfo->Flags & AML_HAS_TARGET)
1107 * Find the target node, it is always the last child. If the traget
1108 * is not specified in the ASL, a default node of type Zero was
1109 * created by the parser.
1111 ArgNode = Op->Asl.Child;
1112 while (ArgNode->Asl.Next)
1114 PrevArgNode = ArgNode;
1115 ArgNode = ArgNode->Asl.Next;
1118 /* Divide() is the only weird case, it has two targets */
1120 if (Op->Asl.AmlOpcode == AML_DIVIDE_OP)
1122 if ((ArgNode->Asl.ParseOpcode == PARSEOP_ZERO) &&
1124 (PrevArgNode->Asl.ParseOpcode == PARSEOP_ZERO))
1126 AslError (ASL_WARNING, ASL_MSG_RESULT_NOT_USED,
1127 Op, Op->Asl.ExternalName);
1130 else if (ArgNode->Asl.ParseOpcode == PARSEOP_ZERO)
1132 AslError (ASL_WARNING, ASL_MSG_RESULT_NOT_USED,
1133 Op, Op->Asl.ExternalName);
1139 * Has no target and the result is not used. Only a couple opcodes
1140 * can have this combination.
1142 switch (Op->Asl.ParseOpcode)
1144 case PARSEOP_ACQUIRE:
1146 case PARSEOP_LOADTABLE:
1150 AslError (ASL_WARNING, ASL_MSG_RESULT_NOT_USED,
1151 Op, Op->Asl.ExternalName);
1159 * Semantic checks for individual ASL operators
1161 switch (Op->Asl.ParseOpcode)
1163 case PARSEOP_ACQUIRE:
1166 * Emit a warning if the timeout parameter for these operators is not
1167 * ACPI_WAIT_FOREVER, and the result value from the operator is not
1168 * checked, meaning that a timeout could happen, but the code
1169 * would not know about it.
1172 /* First child is the namepath, 2nd child is timeout */
1174 ArgNode = Op->Asl.Child;
1175 ArgNode = ArgNode->Asl.Next;
1178 * Check for the WAIT_FOREVER case - defined by the ACPI spec to be
1181 if (((ArgNode->Asl.ParseOpcode == PARSEOP_WORDCONST) ||
1182 (ArgNode->Asl.ParseOpcode == PARSEOP_INTEGER)) &&
1183 (ArgNode->Asl.Value.Integer >= (UINT64) ACPI_WAIT_FOREVER))
1189 * The operation could timeout. If the return value is not used
1190 * (indicates timeout occurred), issue a warning
1192 if (!AnIsResultUsed (Op))
1194 AslError (ASL_WARNING, ASL_MSG_TIMEOUT, ArgNode,
1195 Op->Asl.ExternalName);
1199 case PARSEOP_CREATEFIELD:
1201 * Check for a zero Length (NumBits) operand. NumBits is the 3rd operand
1203 ArgNode = Op->Asl.Child;
1204 ArgNode = ArgNode->Asl.Next;
1205 ArgNode = ArgNode->Asl.Next;
1207 if ((ArgNode->Asl.ParseOpcode == PARSEOP_ZERO) ||
1208 ((ArgNode->Asl.ParseOpcode == PARSEOP_INTEGER) &&
1209 (ArgNode->Asl.Value.Integer == 0)))
1211 AslError (ASL_ERROR, ASL_MSG_NON_ZERO, ArgNode, NULL);