1 /******************************************************************************
3 * Module Name: aslwalks.c - major analytical parse tree walks
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, 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.
45 #include <contrib/dev/acpica/compiler/aslcompiler.h>
46 #include "aslcompiler.y.h"
47 #include <contrib/dev/acpica/include/acparser.h>
48 #include <contrib/dev/acpica/include/amlcode.h>
51 #define _COMPONENT ACPI_COMPILER
52 ACPI_MODULE_NAME ("aslwalks")
55 /*******************************************************************************
57 * FUNCTION: AnMethodAnalysisWalkBegin
59 * PARAMETERS: ASL_WALK_CALLBACK
63 * DESCRIPTION: Descending callback for the analysis walk. Check methods for:
64 * 1) Initialized local variables
68 ******************************************************************************/
71 AnMethodAnalysisWalkBegin (
72 ACPI_PARSE_OBJECT *Op,
76 ASL_ANALYSIS_WALK_INFO *WalkInfo = (ASL_ANALYSIS_WALK_INFO *) Context;
77 ASL_METHOD_INFO *MethodInfo = WalkInfo->MethodStack;
78 ACPI_PARSE_OBJECT *Next;
79 UINT32 RegisterNumber;
81 char LocalName[] = "Local0";
82 char ArgName[] = "Arg0";
83 ACPI_PARSE_OBJECT *ArgNode;
84 ACPI_PARSE_OBJECT *NextType;
85 ACPI_PARSE_OBJECT *NextParamType;
89 switch (Op->Asl.ParseOpcode)
95 /* Create and init method info */
97 MethodInfo = UtLocalCalloc (sizeof (ASL_METHOD_INFO));
98 MethodInfo->Next = WalkInfo->MethodStack;
101 WalkInfo->MethodStack = MethodInfo;
103 /* Get the name node, ignored here */
105 Next = Op->Asl.Child;
107 /* Get the NumArguments node */
109 Next = Next->Asl.Next;
110 MethodInfo->NumArguments = (UINT8)
111 (((UINT8) Next->Asl.Value.Integer) & 0x07);
113 /* Get the SerializeRule and SyncLevel nodes, ignored here */
115 Next = Next->Asl.Next;
116 Next = Next->Asl.Next;
119 /* Get the ReturnType node */
121 Next = Next->Asl.Next;
123 NextType = Next->Asl.Child;
126 /* Get and map each of the ReturnTypes */
128 MethodInfo->ValidReturnTypes |= AnMapObjTypeToBtype (NextType);
129 NextType->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
130 NextType = NextType->Asl.Next;
133 /* Get the ParameterType node */
135 Next = Next->Asl.Next;
137 NextType = Next->Asl.Child;
140 if (NextType->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
142 NextParamType = NextType->Asl.Child;
143 while (NextParamType)
145 MethodInfo->ValidArgTypes[ActualArgs] |= AnMapObjTypeToBtype (NextParamType);
146 NextParamType->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
147 NextParamType = NextParamType->Asl.Next;
152 MethodInfo->ValidArgTypes[ActualArgs] =
153 AnMapObjTypeToBtype (NextType);
154 NextType->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
158 NextType = NextType->Asl.Next;
161 if ((MethodInfo->NumArguments) &&
162 (MethodInfo->NumArguments != ActualArgs))
164 /* error: Param list did not match number of args */
167 /* Allow numarguments == 0 for Function() */
169 if ((!MethodInfo->NumArguments) && (ActualArgs))
171 MethodInfo->NumArguments = ActualArgs;
172 ArgNode->Asl.Value.Integer |= ActualArgs;
176 * Actual arguments are initialized at method entry.
177 * All other ArgX "registers" can be used as locals, so we
178 * track their initialization.
180 for (i = 0; i < MethodInfo->NumArguments; i++)
182 MethodInfo->ArgInitialized[i] = TRUE;
187 case PARSEOP_METHODCALL:
190 (Op->Asl.Node == MethodInfo->Op->Asl.Node))
192 AslError (ASL_REMARK, ASL_MSG_RECURSION, Op, Op->Asl.ExternalName);
209 * Local was used outside a control method, or there was an error
210 * in the method declaration.
212 AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD, Op, Op->Asl.ExternalName);
216 RegisterNumber = (Op->Asl.AmlOpcode & 0x000F);
219 * If the local is being used as a target, mark the local
222 if (Op->Asl.CompileFlags & NODE_IS_TARGET)
224 MethodInfo->LocalInitialized[RegisterNumber] = TRUE;
228 * Otherwise, this is a reference, check if the local
229 * has been previously initialized.
231 * The only operator that accepts an uninitialized value is ObjectType()
233 else if ((!MethodInfo->LocalInitialized[RegisterNumber]) &&
234 (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE))
236 LocalName[strlen (LocalName) -1] = (char) (RegisterNumber + 0x30);
237 AslError (ASL_ERROR, ASL_MSG_LOCAL_INIT, Op, LocalName);
253 * Arg was used outside a control method, or there was an error
254 * in the method declaration.
256 AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD, Op, Op->Asl.ExternalName);
260 RegisterNumber = (Op->Asl.AmlOpcode & 0x000F) - 8;
261 ArgName[strlen (ArgName) -1] = (char) (RegisterNumber + 0x30);
264 * If the Arg is being used as a target, mark the local
267 if (Op->Asl.CompileFlags & NODE_IS_TARGET)
269 MethodInfo->ArgInitialized[RegisterNumber] = TRUE;
273 * Otherwise, this is a reference, check if the Arg
274 * has been previously initialized.
276 * The only operator that accepts an uninitialized value is ObjectType()
278 else if ((!MethodInfo->ArgInitialized[RegisterNumber]) &&
279 (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE))
281 AslError (ASL_ERROR, ASL_MSG_ARG_INIT, Op, ArgName);
284 /* Flag this arg if it is not a "real" argument to the method */
286 if (RegisterNumber >= MethodInfo->NumArguments)
288 AslError (ASL_REMARK, ASL_MSG_NOT_PARAMETER, Op, ArgName);
298 * Probably was an error in the method declaration,
299 * no additional error here
301 ACPI_WARNING ((AE_INFO, "%p, No parent method", Op));
306 * A child indicates a possible return value. A simple Return or
307 * Return() is marked with NODE_IS_NULL_RETURN by the parser so
308 * that it is not counted as a "real" return-with-value, although
309 * the AML code that is actually emitted is Return(0). The AML
310 * definition of Return has a required parameter, so we are
311 * forced to convert a null return to Return(0).
313 if ((Op->Asl.Child) &&
314 (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) &&
315 (!(Op->Asl.Child->Asl.CompileFlags & NODE_IS_NULL_RETURN)))
317 MethodInfo->NumReturnWithValue++;
321 MethodInfo->NumReturnNoValue++;
327 case PARSEOP_CONTINUE:
329 Next = Op->Asl.Parent;
332 if (Next->Asl.ParseOpcode == PARSEOP_WHILE)
336 Next = Next->Asl.Parent;
341 AslError (ASL_ERROR, ASL_MSG_NO_WHILE, Op, NULL);
348 /* We can range check if the argument is an integer */
350 if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_INTEGER) &&
351 (Op->Asl.Child->Asl.Value.Integer > ACPI_UINT8_MAX))
353 AslError (ASL_ERROR, ASL_MSG_INVALID_TIME, Op, NULL);
361 case PARSEOP_OPERATIONREGION:
362 case PARSEOP_POWERRESOURCE:
363 case PARSEOP_PROCESSOR:
364 case PARSEOP_THERMALZONE:
367 * The first operand is a name to be created in the namespace.
368 * Check against the reserved list.
370 i = ApCheckForPredefinedName (Op, Op->Asl.NameSeg);
371 if (i < ACPI_VALID_RESERVED_NAME_MAX)
373 AslError (ASL_ERROR, ASL_MSG_RESERVED_USE, Op, Op->Asl.ExternalName);
380 /* Typecheck any predefined names statically defined with Name() */
382 ApCheckForPredefinedObject (Op, Op->Asl.NameSeg);
384 /* Special typechecking for _HID */
386 if (!ACPI_STRCMP (METHOD_NAME__HID, Op->Asl.NameSeg))
388 Next = Op->Asl.Child->Asl.Next;
389 AnCheckId (Next, ASL_TYPE_HID);
392 /* Special typechecking for _CID */
394 else if (!ACPI_STRCMP (METHOD_NAME__CID, Op->Asl.NameSeg))
396 Next = Op->Asl.Child->Asl.Next;
398 if ((Next->Asl.ParseOpcode == PARSEOP_PACKAGE) ||
399 (Next->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE))
401 Next = Next->Asl.Child;
404 AnCheckId (Next, ASL_TYPE_CID);
405 Next = Next->Asl.Next;
410 AnCheckId (Next, ASL_TYPE_CID);
424 /*******************************************************************************
426 * FUNCTION: AnMethodAnalysisWalkEnd
428 * PARAMETERS: ASL_WALK_CALLBACK
432 * DESCRIPTION: Ascending callback for analysis walk. Complete method
435 ******************************************************************************/
438 AnMethodAnalysisWalkEnd (
439 ACPI_PARSE_OBJECT *Op,
443 ASL_ANALYSIS_WALK_INFO *WalkInfo = (ASL_ANALYSIS_WALK_INFO *) Context;
444 ASL_METHOD_INFO *MethodInfo = WalkInfo->MethodStack;
447 switch (Op->Asl.ParseOpcode)
453 printf ("No method info for method! [%s]\n", Op->Asl.Namepath);
454 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
455 "No method info for this method");
458 return (AE_AML_INTERNAL);
466 switch (Op->Asl.ParseOpcode)
470 WalkInfo->MethodStack = MethodInfo->Next;
473 * Check if there is no return statement at the end of the
474 * method AND we can actually get there -- i.e., the execution
475 * of the method can possibly terminate without a return statement.
477 if ((!AnLastStatementIsReturn (Op)) &&
478 (!(Op->Asl.CompileFlags & NODE_HAS_NO_EXIT)))
481 * No return statement, and execution can possibly exit
482 * via this path. This is equivalent to Return ()
484 MethodInfo->NumReturnNoValue++;
488 * Check for case where some return statements have a return value
489 * and some do not. Exit without a return statement is a return with
492 if (MethodInfo->NumReturnNoValue &&
493 MethodInfo->NumReturnWithValue)
495 AslError (ASL_WARNING, ASL_MSG_RETURN_TYPES, Op,
496 Op->Asl.ExternalName);
500 * If there are any RETURN() statements with no value, or there is a
501 * control path that allows the method to exit without a return value,
502 * we mark the method as a method that does not return a value. This
503 * knowledge can be used to check method invocations that expect a
506 if (MethodInfo->NumReturnNoValue)
508 if (MethodInfo->NumReturnWithValue)
510 Op->Asl.CompileFlags |= NODE_METHOD_SOME_NO_RETVAL;
514 Op->Asl.CompileFlags |= NODE_METHOD_NO_RETVAL;
519 * Check predefined method names for correct return behavior
520 * and correct number of arguments. Also, some special checks
521 * For GPE and _REG methods.
523 if (ApCheckForPredefinedMethod (Op, MethodInfo))
525 /* Special check for two names like _L01 and _E01 in same scope */
527 ApCheckForGpeNameConflict (Op);
530 * Special check for _REG: Must have an operation region definition
531 * within the same scope!
533 ApCheckRegMethod (Op);
536 ACPI_FREE (MethodInfo);
542 /* Special check for two names like _L01 and _E01 in same scope */
544 ApCheckForGpeNameConflict (Op);
551 * If the parent is a predefined method name, attempt to typecheck
552 * the return value. Only static types can be validated.
554 ApCheckPredefinedReturnValue (Op, MethodInfo);
557 * The parent block does not "exit" and continue execution -- the
558 * method is terminated here with the Return() statement.
560 Op->Asl.Parent->Asl.CompileFlags |= NODE_HAS_NO_EXIT;
562 /* Used in the "typing" pass later */
564 Op->Asl.ParentMethod = MethodInfo->Op;
567 * If there is a peer node after the return statement, then this
568 * node is unreachable code -- i.e., it won't be executed because of
569 * the preceeding Return() statement.
573 AslError (ASL_WARNING, ASL_MSG_UNREACHABLE_CODE, Op->Asl.Next, NULL);
580 if ((Op->Asl.CompileFlags & NODE_HAS_NO_EXIT) &&
582 (Op->Asl.Next->Asl.ParseOpcode == PARSEOP_ELSE))
585 * This IF has a corresponding ELSE. The IF block has no exit,
586 * (it contains an unconditional Return)
587 * mark the ELSE block to remember this fact.
589 Op->Asl.Next->Asl.CompileFlags |= NODE_IF_HAS_NO_EXIT;
596 if ((Op->Asl.CompileFlags & NODE_HAS_NO_EXIT) &&
597 (Op->Asl.CompileFlags & NODE_IF_HAS_NO_EXIT))
600 * This ELSE block has no exit and the corresponding IF block
601 * has no exit either. Therefore, the parent node has no exit.
603 Op->Asl.Parent->Asl.CompileFlags |= NODE_HAS_NO_EXIT;
610 if ((Op->Asl.CompileFlags & NODE_HAS_NO_EXIT) &&
613 /* If this node has no exit, then the parent has no exit either */
615 Op->Asl.Parent->Asl.CompileFlags |= NODE_HAS_NO_EXIT;
624 /*******************************************************************************
626 * FUNCTION: AnMethodTypingWalkEnd
628 * PARAMETERS: ASL_WALK_CALLBACK
632 * DESCRIPTION: Ascending callback for typing walk. Complete the method
633 * return analysis. Check methods for:
634 * 1) Initialized local variables
638 ******************************************************************************/
641 AnMethodTypingWalkEnd (
642 ACPI_PARSE_OBJECT *Op,
646 UINT32 ThisNodeBtype;
649 switch (Op->Asl.ParseOpcode)
653 Op->Asl.CompileFlags |= NODE_METHOD_TYPED;
658 if ((Op->Asl.Child) &&
659 (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG))
661 ThisNodeBtype = AnGetBtype (Op->Asl.Child);
663 if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_METHODCALL) &&
664 (ThisNodeBtype == (ACPI_UINT32_MAX -1)))
667 * The called method is untyped at this time (typically a
668 * forward reference).
670 * Check for a recursive method call first.
672 if (Op->Asl.ParentMethod != Op->Asl.Child->Asl.Node->Op)
674 /* We must type the method here */
676 TrWalkParseTree (Op->Asl.Child->Asl.Node->Op,
677 ASL_WALK_VISIT_UPWARD, NULL,
678 AnMethodTypingWalkEnd, NULL);
680 ThisNodeBtype = AnGetBtype (Op->Asl.Child);
684 /* Returns a value, save the value type */
686 if (Op->Asl.ParentMethod)
688 Op->Asl.ParentMethod->Asl.AcpiBtype |= ThisNodeBtype;
701 /*******************************************************************************
703 * FUNCTION: AnOperandTypecheckWalkEnd
705 * PARAMETERS: ASL_WALK_CALLBACK
709 * DESCRIPTION: Ascending callback for analysis walk. Complete method
712 ******************************************************************************/
715 AnOperandTypecheckWalkEnd (
716 ACPI_PARSE_OBJECT *Op,
720 const ACPI_OPCODE_INFO *OpInfo;
721 UINT32 RuntimeArgTypes;
722 UINT32 RuntimeArgTypes2;
723 UINT32 RequiredBtypes;
724 UINT32 ThisNodeBtype;
727 ACPI_PARSE_OBJECT *ArgOp;
731 switch (Op->Asl.AmlOpcode)
733 case AML_RAW_DATA_BYTE:
734 case AML_RAW_DATA_WORD:
735 case AML_RAW_DATA_DWORD:
736 case AML_RAW_DATA_QWORD:
737 case AML_RAW_DATA_BUFFER:
738 case AML_RAW_DATA_CHAIN:
739 case AML_PACKAGE_LENGTH:
740 case AML_UNASSIGNED_OPCODE:
741 case AML_DEFAULT_ARG_OP:
743 /* Ignore the internal (compiler-only) AML opcodes */
751 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
757 ArgOp = Op->Asl.Child;
758 RuntimeArgTypes = OpInfo->RuntimeArgs;
759 OpcodeClass = OpInfo->Class;
761 #ifdef ASL_ERROR_NAMED_OBJECT_IN_WHILE
763 * Update 11/2008: In practice, we can't perform this check. A simple
764 * analysis is not sufficient. Also, it can cause errors when compiling
765 * disassembled code because of the way Switch operators are implemented
766 * (a While(One) loop with a named temp variable created within.)
770 * If we are creating a named object, check if we are within a while loop
771 * by checking if the parent is a WHILE op. This is a simple analysis, but
772 * probably sufficient for many cases.
774 * Allow Scope(), Buffer(), and Package().
776 if (((OpcodeClass == AML_CLASS_NAMED_OBJECT) && (Op->Asl.AmlOpcode != AML_SCOPE_OP)) ||
777 ((OpcodeClass == AML_CLASS_CREATE) && (OpInfo->Flags & AML_NSNODE)))
779 if (Op->Asl.Parent->Asl.AmlOpcode == AML_WHILE_OP)
781 AslError (ASL_ERROR, ASL_MSG_NAMED_OBJECT_IN_WHILE, Op, NULL);
787 * Special case for control opcodes IF/RETURN/WHILE since they
788 * have no runtime arg list (at this time)
790 switch (Op->Asl.AmlOpcode)
796 if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL)
798 /* Check for an internal method */
800 if (AnIsInternalMethod (ArgOp))
805 /* The lone arg is a method call, check it */
807 RequiredBtypes = AnMapArgTypeToBtype (ARGI_INTEGER);
808 if (Op->Asl.AmlOpcode == AML_RETURN_OP)
810 RequiredBtypes = 0xFFFFFFFF;
813 ThisNodeBtype = AnGetBtype (ArgOp);
814 if (ThisNodeBtype == ACPI_UINT32_MAX)
818 AnCheckMethodReturnValue (Op, OpInfo, ArgOp,
819 RequiredBtypes, ThisNodeBtype);
827 /* Ignore the non-executable opcodes */
829 if (RuntimeArgTypes == ARGI_INVALID_OPCODE)
836 case AML_CLASS_EXECUTE:
837 case AML_CLASS_CREATE:
838 case AML_CLASS_CONTROL:
839 case AML_CLASS_RETURN_VALUE:
841 /* TBD: Change class or fix typechecking for these */
843 if ((Op->Asl.AmlOpcode == AML_BUFFER_OP) ||
844 (Op->Asl.AmlOpcode == AML_PACKAGE_OP) ||
845 (Op->Asl.AmlOpcode == AML_VAR_PACKAGE_OP))
850 /* Reverse the runtime argument list */
852 RuntimeArgTypes2 = 0;
853 while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes)))
855 RuntimeArgTypes2 <<= ARG_TYPE_WIDTH;
856 RuntimeArgTypes2 |= ArgType;
857 INCREMENT_ARG_LIST (RuntimeArgTypes);
860 while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes2)))
862 RequiredBtypes = AnMapArgTypeToBtype (ArgType);
864 ThisNodeBtype = AnGetBtype (ArgOp);
865 if (ThisNodeBtype == ACPI_UINT32_MAX)
870 /* Examine the arg based on the required type of the arg */
876 if (ArgOp->Asl.ParseOpcode == PARSEOP_ZERO)
878 /* ZERO is the placeholder for "don't store result" */
880 ThisNodeBtype = RequiredBtypes;
884 if (ArgOp->Asl.ParseOpcode == PARSEOP_INTEGER)
887 * This is the case where an original reference to a resource
888 * descriptor field has been replaced by an (Integer) offset.
889 * These named fields are supported at compile-time only;
890 * the names are not passed to the interpreter (via the AML).
892 if ((ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
893 (ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
895 AslError (ASL_ERROR, ASL_MSG_RESOURCE_FIELD, ArgOp, NULL);
899 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, NULL);
904 if ((ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL) ||
905 (ArgOp->Asl.ParseOpcode == PARSEOP_DEREFOF))
910 ThisNodeBtype = RequiredBtypes;
914 case ARGI_REFERENCE: /* References */
915 case ARGI_INTEGER_REF:
916 case ARGI_OBJECT_REF:
917 case ARGI_DEVICE_REF:
919 switch (ArgOp->Asl.ParseOpcode)
930 /* TBD: implement analysis of current value (type) of the local */
931 /* For now, just treat any local as a typematch */
933 /*ThisNodeBtype = RequiredBtypes;*/
944 /* Hard to analyze argument types, sow we won't */
945 /* For now, just treat any arg as a typematch */
947 /* ThisNodeBtype = RequiredBtypes; */
967 CommonBtypes = ThisNodeBtype & RequiredBtypes;
969 if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL)
971 if (AnIsInternalMethod (ArgOp))
976 /* Check a method call for a valid return value */
978 AnCheckMethodReturnValue (Op, OpInfo, ArgOp,
979 RequiredBtypes, ThisNodeBtype);
983 * Now check if the actual type(s) match at least one
984 * bit to the required type
986 else if (!CommonBtypes)
988 /* No match -- this is a type mismatch error */
990 AnFormatBtype (StringBuffer, ThisNodeBtype);
991 AnFormatBtype (StringBuffer2, RequiredBtypes);
993 sprintf (MsgBuffer, "[%s] found, %s operator requires [%s]",
994 StringBuffer, OpInfo->Name, StringBuffer2);
996 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, MsgBuffer);
1000 ArgOp = ArgOp->Asl.Next;
1001 INCREMENT_ARG_LIST (RuntimeArgTypes2);
1013 /*******************************************************************************
1015 * FUNCTION: AnOtherSemanticAnalysisWalkBegin
1017 * PARAMETERS: ASL_WALK_CALLBACK
1021 * DESCRIPTION: Descending callback for the analysis walk. Checks for
1022 * miscellaneous issues in the code.
1024 ******************************************************************************/
1027 AnOtherSemanticAnalysisWalkBegin (
1028 ACPI_PARSE_OBJECT *Op,
1032 ACPI_PARSE_OBJECT *ArgNode;
1033 ACPI_PARSE_OBJECT *PrevArgNode = NULL;
1034 const ACPI_OPCODE_INFO *OpInfo;
1037 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
1040 * Determine if an execution class operator actually does something by
1041 * checking if it has a target and/or the function return value is used.
1042 * (Target is optional, so a standalone statement can actually do nothing.)
1044 if ((OpInfo->Class == AML_CLASS_EXECUTE) &&
1045 (OpInfo->Flags & AML_HAS_RETVAL) &&
1046 (!AnIsResultUsed (Op)))
1048 if (OpInfo->Flags & AML_HAS_TARGET)
1051 * Find the target node, it is always the last child. If the traget
1052 * is not specified in the ASL, a default node of type Zero was
1053 * created by the parser.
1055 ArgNode = Op->Asl.Child;
1056 while (ArgNode->Asl.Next)
1058 PrevArgNode = ArgNode;
1059 ArgNode = ArgNode->Asl.Next;
1062 /* Divide() is the only weird case, it has two targets */
1064 if (Op->Asl.AmlOpcode == AML_DIVIDE_OP)
1066 if ((ArgNode->Asl.ParseOpcode == PARSEOP_ZERO) &&
1068 (PrevArgNode->Asl.ParseOpcode == PARSEOP_ZERO))
1070 AslError (ASL_WARNING, ASL_MSG_RESULT_NOT_USED,
1071 Op, Op->Asl.ExternalName);
1074 else if (ArgNode->Asl.ParseOpcode == PARSEOP_ZERO)
1076 AslError (ASL_WARNING, ASL_MSG_RESULT_NOT_USED,
1077 Op, Op->Asl.ExternalName);
1083 * Has no target and the result is not used. Only a couple opcodes
1084 * can have this combination.
1086 switch (Op->Asl.ParseOpcode)
1088 case PARSEOP_ACQUIRE:
1090 case PARSEOP_LOADTABLE:
1094 AslError (ASL_WARNING, ASL_MSG_RESULT_NOT_USED,
1095 Op, Op->Asl.ExternalName);
1103 * Semantic checks for individual ASL operators
1105 switch (Op->Asl.ParseOpcode)
1107 case PARSEOP_ACQUIRE:
1110 * Emit a warning if the timeout parameter for these operators is not
1111 * ACPI_WAIT_FOREVER, and the result value from the operator is not
1112 * checked, meaning that a timeout could happen, but the code
1113 * would not know about it.
1116 /* First child is the namepath, 2nd child is timeout */
1118 ArgNode = Op->Asl.Child;
1119 ArgNode = ArgNode->Asl.Next;
1122 * Check for the WAIT_FOREVER case - defined by the ACPI spec to be
1125 if (((ArgNode->Asl.ParseOpcode == PARSEOP_WORDCONST) ||
1126 (ArgNode->Asl.ParseOpcode == PARSEOP_INTEGER)) &&
1127 (ArgNode->Asl.Value.Integer >= (UINT64) ACPI_WAIT_FOREVER))
1133 * The operation could timeout. If the return value is not used
1134 * (indicates timeout occurred), issue a warning
1136 if (!AnIsResultUsed (Op))
1138 AslError (ASL_WARNING, ASL_MSG_TIMEOUT, ArgNode,
1139 Op->Asl.ExternalName);
1143 case PARSEOP_CREATEFIELD:
1145 * Check for a zero Length (NumBits) operand. NumBits is the 3rd operand
1147 ArgNode = Op->Asl.Child;
1148 ArgNode = ArgNode->Asl.Next;
1149 ArgNode = ArgNode->Asl.Next;
1151 if ((ArgNode->Asl.ParseOpcode == PARSEOP_ZERO) ||
1152 ((ArgNode->Asl.ParseOpcode == PARSEOP_INTEGER) &&
1153 (ArgNode->Asl.Value.Integer == 0)))
1155 AslError (ASL_ERROR, ASL_MSG_NON_ZERO, ArgNode, NULL);