2 /******************************************************************************
4 * Module Name: aslanalyze.c - check for semantic errors
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2010, 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 *****************************************************************************/
118 #include <contrib/dev/acpica/compiler/aslcompiler.h>
119 #include "aslcompiler.y.h"
120 #include <contrib/dev/acpica/include/acparser.h>
121 #include <contrib/dev/acpica/include/amlcode.h>
123 #define _COMPONENT ACPI_COMPILER
124 ACPI_MODULE_NAME ("aslanalyze")
126 /* Local prototypes */
129 AnMapArgTypeToBtype (
143 ACPI_PARSE_OBJECT *Op);
146 AnMapObjTypeToBtype (
147 ACPI_PARSE_OBJECT *Op);
150 AnLastStatementIsReturn (
151 ACPI_PARSE_OBJECT *Op);
154 AnCheckMethodReturnValue (
155 ACPI_PARSE_OBJECT *Op,
156 const ACPI_OPCODE_INFO *OpInfo,
157 ACPI_PARSE_OBJECT *ArgOp,
158 UINT32 RequiredBtypes,
159 UINT32 ThisNodeBtype);
163 ACPI_PARSE_OBJECT *Op);
166 AnGetInternalMethodReturnType (
167 ACPI_PARSE_OBJECT *Op);
171 ACPI_PARSE_OBJECT *Op);
174 /*******************************************************************************
176 * FUNCTION: AnIsInternalMethod
178 * PARAMETERS: Op - Current op
182 * DESCRIPTION: Check for an internal control method.
184 ******************************************************************************/
188 ACPI_PARSE_OBJECT *Op)
191 if ((!ACPI_STRCMP (Op->Asl.ExternalName, "\\_OSI")) ||
192 (!ACPI_STRCMP (Op->Asl.ExternalName, "_OSI")))
201 /*******************************************************************************
203 * FUNCTION: AnGetInternalMethodReturnType
205 * PARAMETERS: Op - Current op
209 * DESCRIPTION: Get the return type of an internal method
211 ******************************************************************************/
214 AnGetInternalMethodReturnType (
215 ACPI_PARSE_OBJECT *Op)
218 if ((!ACPI_STRCMP (Op->Asl.ExternalName, "\\_OSI")) ||
219 (!ACPI_STRCMP (Op->Asl.ExternalName, "_OSI")))
221 return (ACPI_BTYPE_STRING);
228 /*******************************************************************************
230 * FUNCTION: AnMapArgTypeToBtype
232 * PARAMETERS: ArgType - The ARGI required type(s) for this argument,
233 * from the opcode info table
235 * RETURN: The corresponding Bit-encoded types
237 * DESCRIPTION: Convert an encoded ARGI required argument type code into a
238 * bitfield type code. Implements the implicit source conversion
241 ******************************************************************************/
244 AnMapArgTypeToBtype (
254 return (ACPI_BTYPE_OBJECTS_AND_REFS);
257 return (ACPI_BTYPE_PACKAGE);
260 return (ACPI_BTYPE_EVENT);
263 return (ACPI_BTYPE_MUTEX);
267 * DDBHandleObject := SuperName
268 * ACPI_BTYPE_REFERENCE: Index reference as parameter of Load/Unload
270 return (ACPI_BTYPE_DDB_HANDLE | ACPI_BTYPE_REFERENCE);
272 /* Interchangeable types */
274 * Source conversion rules:
275 * Integer, String, and Buffer are all interchangeable
280 case ARGI_BUFFER_OR_STRING:
281 case ARGI_COMPUTEDATA:
282 return (ACPI_BTYPE_COMPUTE_DATA);
286 case ARGI_INTEGER_REF:
287 return (ACPI_BTYPE_INTEGER);
289 case ARGI_OBJECT_REF:
290 return (ACPI_BTYPE_ALL_OBJECTS);
292 case ARGI_DEVICE_REF:
293 return (ACPI_BTYPE_DEVICE_OBJECTS);
296 return (ACPI_BTYPE_REFERENCE);
299 case ARGI_FIXED_TARGET:
300 case ARGI_SIMPLE_TARGET:
301 return (ACPI_BTYPE_OBJECTS_AND_REFS);
305 case ARGI_DATAOBJECT:
308 * Buffer, string, package or reference to a Op -
309 * Used only by SizeOf operator
311 return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER |
312 ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE);
314 case ARGI_COMPLEXOBJ:
316 /* Buffer, String, or package */
318 return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER | ACPI_BTYPE_PACKAGE);
320 case ARGI_REF_OR_STRING:
321 return (ACPI_BTYPE_STRING | ACPI_BTYPE_REFERENCE);
323 case ARGI_REGION_OR_BUFFER:
325 /* Used by Load() only. Allow buffers in addition to regions/fields */
327 return (ACPI_BTYPE_REGION | ACPI_BTYPE_BUFFER | ACPI_BTYPE_FIELD_UNIT);
329 case ARGI_DATAREFOBJ:
330 return (ACPI_BTYPE_INTEGER |ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER |
331 ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE | ACPI_BTYPE_DDB_HANDLE);
337 return (ACPI_BTYPE_OBJECTS_AND_REFS);
341 /*******************************************************************************
343 * FUNCTION: AnMapEtypeToBtype
345 * PARAMETERS: Etype - Encoded ACPI Type
347 * RETURN: Btype corresponding to the Etype
349 * DESCRIPTION: Convert an encoded ACPI type to a bitfield type applying the
350 * operand conversion rules. In other words, returns the type(s)
351 * this Etype is implicitly converted to during interpretation.
353 ******************************************************************************/
361 if (Etype == ACPI_TYPE_ANY)
363 return ACPI_BTYPE_OBJECTS_AND_REFS;
366 /* Try the standard ACPI data types */
368 if (Etype <= ACPI_TYPE_EXTERNAL_MAX)
371 * This switch statement implements the allowed operand conversion
372 * rules as per the "ASL Data Types" section of the ACPI
377 case ACPI_TYPE_INTEGER:
378 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_DDB_HANDLE);
380 case ACPI_TYPE_STRING:
381 case ACPI_TYPE_BUFFER:
382 return (ACPI_BTYPE_COMPUTE_DATA);
384 case ACPI_TYPE_PACKAGE:
385 return (ACPI_BTYPE_PACKAGE);
387 case ACPI_TYPE_FIELD_UNIT:
388 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_FIELD_UNIT);
390 case ACPI_TYPE_BUFFER_FIELD:
391 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_BUFFER_FIELD);
393 case ACPI_TYPE_DDB_HANDLE:
394 return (ACPI_BTYPE_INTEGER | ACPI_BTYPE_DDB_HANDLE);
396 case ACPI_BTYPE_DEBUG_OBJECT:
398 /* Cannot be used as a source operand */
403 return (1 << (Etype - 1));
407 /* Try the internal data types */
411 case ACPI_TYPE_LOCAL_REGION_FIELD:
412 case ACPI_TYPE_LOCAL_BANK_FIELD:
413 case ACPI_TYPE_LOCAL_INDEX_FIELD:
415 /* Named fields can be either Integer/Buffer/String */
417 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_FIELD_UNIT);
419 case ACPI_TYPE_LOCAL_ALIAS:
421 return (ACPI_BTYPE_INTEGER);
424 case ACPI_TYPE_LOCAL_RESOURCE:
425 case ACPI_TYPE_LOCAL_RESOURCE_FIELD:
427 return (ACPI_BTYPE_REFERENCE);
430 printf ("Unhandled encoded type: %X\n", Etype);
436 /*******************************************************************************
438 * FUNCTION: AnFormatBtype
440 * PARAMETERS: Btype - Bitfield of ACPI types
441 * Buffer - Where to put the ascii string
445 * DESCRIPTION: Convert a Btype to a string of ACPI types
447 ******************************************************************************/
455 BOOLEAN First = TRUE;
462 strcat (Buffer, "NoReturnValue");
466 for (Type = 1; Type <= ACPI_TYPE_EXTERNAL_MAX; Type++)
468 if (Btype & 0x00000001)
472 strcat (Buffer, "|");
475 strcat (Buffer, AcpiUtGetTypeName (Type));
480 if (Btype & 0x00000001)
484 strcat (Buffer, "|");
487 strcat (Buffer, "Reference");
491 if (Btype & 0x00000001)
495 strcat (Buffer, "|");
498 strcat (Buffer, "Resource");
503 /*******************************************************************************
505 * FUNCTION: AnGetBtype
507 * PARAMETERS: Op - Parse node whose type will be returned.
509 * RETURN: The Btype associated with the Op.
511 * DESCRIPTION: Get the (bitfield) ACPI type associated with the parse node.
512 * Handles the case where the node is a name or method call and
513 * the actual type must be obtained from the namespace node.
515 ******************************************************************************/
519 ACPI_PARSE_OBJECT *Op)
521 ACPI_NAMESPACE_NODE *Node;
522 ACPI_PARSE_OBJECT *ReferencedNode;
523 UINT32 ThisNodeBtype = 0;
526 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
527 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
528 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
533 DbgPrint (ASL_DEBUG_OUTPUT,
534 "No attached Nsnode: [%s] at line %u name [%s], ignoring typecheck\n",
535 Op->Asl.ParseOpName, Op->Asl.LineNumber,
536 Op->Asl.ExternalName);
537 return ACPI_UINT32_MAX;
540 ThisNodeBtype = AnMapEtypeToBtype (Node->Type);
543 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
544 "could not map type");
548 * Since it was a named reference, enable the
551 ThisNodeBtype |= ACPI_BTYPE_REFERENCE;
553 if (Op->Asl.ParseOpcode == PARSEOP_METHODCALL)
555 ReferencedNode = Node->Op;
558 /* Check for an internal method */
560 if (AnIsInternalMethod (Op))
562 return (AnGetInternalMethodReturnType (Op));
565 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
567 return ACPI_UINT32_MAX;
570 if (ReferencedNode->Asl.CompileFlags & NODE_METHOD_TYPED)
572 ThisNodeBtype = ReferencedNode->Asl.AcpiBtype;
576 return (ACPI_UINT32_MAX -1);
582 ThisNodeBtype = Op->Asl.AcpiBtype;
585 return (ThisNodeBtype);
589 /*******************************************************************************
591 * FUNCTION: AnMapObjTypeToBtype
593 * PARAMETERS: Op - A parse node
597 * DESCRIPTION: Map object to the associated "Btype"
599 ******************************************************************************/
602 AnMapObjTypeToBtype (
603 ACPI_PARSE_OBJECT *Op)
606 switch (Op->Asl.ParseOpcode)
608 case PARSEOP_OBJECTTYPE_BFF: /* "BuffFieldObj" */
609 return (ACPI_BTYPE_BUFFER_FIELD);
611 case PARSEOP_OBJECTTYPE_BUF: /* "BuffObj" */
612 return (ACPI_BTYPE_BUFFER);
614 case PARSEOP_OBJECTTYPE_DDB: /* "DDBHandleObj" */
615 return (ACPI_BTYPE_DDB_HANDLE);
617 case PARSEOP_OBJECTTYPE_DEV: /* "DeviceObj" */
618 return (ACPI_BTYPE_DEVICE);
620 case PARSEOP_OBJECTTYPE_EVT: /* "EventObj" */
621 return (ACPI_BTYPE_EVENT);
623 case PARSEOP_OBJECTTYPE_FLD: /* "FieldUnitObj" */
624 return (ACPI_BTYPE_FIELD_UNIT);
626 case PARSEOP_OBJECTTYPE_INT: /* "IntObj" */
627 return (ACPI_BTYPE_INTEGER);
629 case PARSEOP_OBJECTTYPE_MTH: /* "MethodObj" */
630 return (ACPI_BTYPE_METHOD);
632 case PARSEOP_OBJECTTYPE_MTX: /* "MutexObj" */
633 return (ACPI_BTYPE_MUTEX);
635 case PARSEOP_OBJECTTYPE_OPR: /* "OpRegionObj" */
636 return (ACPI_BTYPE_REGION);
638 case PARSEOP_OBJECTTYPE_PKG: /* "PkgObj" */
639 return (ACPI_BTYPE_PACKAGE);
641 case PARSEOP_OBJECTTYPE_POW: /* "PowerResObj" */
642 return (ACPI_BTYPE_POWER);
644 case PARSEOP_OBJECTTYPE_STR: /* "StrObj" */
645 return (ACPI_BTYPE_STRING);
647 case PARSEOP_OBJECTTYPE_THZ: /* "ThermalZoneObj" */
648 return (ACPI_BTYPE_THERMAL);
650 case PARSEOP_OBJECTTYPE_UNK: /* "UnknownObj" */
651 return (ACPI_BTYPE_OBJECTS_AND_REFS);
659 /*******************************************************************************
661 * FUNCTION: AnCheckId
663 * PARAMETERS: Op - Current parse op
668 * DESCRIPTION: Perform various checks on _HID and _CID strings. Only limited
669 * checks can be performed on _CID strings.
671 ******************************************************************************/
673 #define ASL_TYPE_HID 0
674 #define ASL_TYPE_CID 1
679 ACPI_PARSE_OBJECT *Op,
684 UINT32 AlphaPrefixLength;
687 if (Op->Asl.ParseOpcode != PARSEOP_STRING_LITERAL)
692 Length = strlen (Op->Asl.Value.String);
695 * If _HID/_CID is a string, all characters must be alphanumeric.
696 * One of the things we want to catch here is the use of
697 * a leading asterisk in the string -- an odd construct
698 * that certain platform manufacturers are fond of.
700 for (i = 0; Op->Asl.Value.String[i]; i++)
702 if (!isalnum ((int) Op->Asl.Value.String[i]))
704 AslError (ASL_ERROR, ASL_MSG_ALPHANUMERIC_STRING,
705 Op, Op->Asl.Value.String);
710 if (Type == ASL_TYPE_CID)
712 /* _CID strings are bus-specific, no more checks can be performed */
717 /* _HID String must be of the form "XXX####" or "ACPI####" */
719 if ((Length < 7) || (Length > 8))
721 AslError (ASL_ERROR, ASL_MSG_HID_LENGTH,
722 Op, Op->Asl.Value.String);
726 /* _HID Length is valid, now check for uppercase (first 3 or 4 chars) */
728 AlphaPrefixLength = 3;
731 AlphaPrefixLength = 4;
734 /* Ensure the alphabetic prefix is all uppercase */
736 for (i = 0; (i < AlphaPrefixLength) && Op->Asl.Value.String[i]; i++)
738 if (!isupper ((int) Op->Asl.Value.String[i]))
740 AslError (ASL_ERROR, ASL_MSG_UPPER_CASE,
741 Op, &Op->Asl.Value.String[i]);
748 /*******************************************************************************
750 * FUNCTION: AnMethodAnalysisWalkBegin
752 * PARAMETERS: ASL_WALK_CALLBACK
756 * DESCRIPTION: Descending callback for the analysis walk. Check methods for:
757 * 1) Initialized local variables
761 ******************************************************************************/
764 AnMethodAnalysisWalkBegin (
765 ACPI_PARSE_OBJECT *Op,
769 ASL_ANALYSIS_WALK_INFO *WalkInfo = (ASL_ANALYSIS_WALK_INFO *) Context;
770 ASL_METHOD_INFO *MethodInfo = WalkInfo->MethodStack;
771 ACPI_PARSE_OBJECT *Next;
772 UINT32 RegisterNumber;
774 char LocalName[] = "Local0";
775 char ArgName[] = "Arg0";
776 ACPI_PARSE_OBJECT *ArgNode;
777 ACPI_PARSE_OBJECT *NextType;
778 ACPI_PARSE_OBJECT *NextParamType;
779 UINT8 ActualArgs = 0;
782 switch (Op->Asl.ParseOpcode)
788 /* Create and init method info */
790 MethodInfo = UtLocalCalloc (sizeof (ASL_METHOD_INFO));
791 MethodInfo->Next = WalkInfo->MethodStack;
794 WalkInfo->MethodStack = MethodInfo;
796 /* Get the name node, ignored here */
798 Next = Op->Asl.Child;
800 /* Get the NumArguments node */
802 Next = Next->Asl.Next;
803 MethodInfo->NumArguments = (UINT8)
804 (((UINT8) Next->Asl.Value.Integer) & 0x07);
806 /* Get the SerializeRule and SyncLevel nodes, ignored here */
808 Next = Next->Asl.Next;
809 Next = Next->Asl.Next;
812 /* Get the ReturnType node */
814 Next = Next->Asl.Next;
816 NextType = Next->Asl.Child;
819 /* Get and map each of the ReturnTypes */
821 MethodInfo->ValidReturnTypes |= AnMapObjTypeToBtype (NextType);
822 NextType->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
823 NextType = NextType->Asl.Next;
826 /* Get the ParameterType node */
828 Next = Next->Asl.Next;
830 NextType = Next->Asl.Child;
833 if (NextType->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
835 NextParamType = NextType->Asl.Child;
836 while (NextParamType)
838 MethodInfo->ValidArgTypes[ActualArgs] |= AnMapObjTypeToBtype (NextParamType);
839 NextParamType->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
840 NextParamType = NextParamType->Asl.Next;
845 MethodInfo->ValidArgTypes[ActualArgs] =
846 AnMapObjTypeToBtype (NextType);
847 NextType->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
851 NextType = NextType->Asl.Next;
854 if ((MethodInfo->NumArguments) &&
855 (MethodInfo->NumArguments != ActualArgs))
857 /* error: Param list did not match number of args */
860 /* Allow numarguments == 0 for Function() */
862 if ((!MethodInfo->NumArguments) && (ActualArgs))
864 MethodInfo->NumArguments = ActualArgs;
865 ArgNode->Asl.Value.Integer |= ActualArgs;
869 * Actual arguments are initialized at method entry.
870 * All other ArgX "registers" can be used as locals, so we
871 * track their initialization.
873 for (i = 0; i < MethodInfo->NumArguments; i++)
875 MethodInfo->ArgInitialized[i] = TRUE;
880 case PARSEOP_METHODCALL:
883 (Op->Asl.Node == MethodInfo->Op->Asl.Node))
885 AslError (ASL_REMARK, ASL_MSG_RECURSION, Op, Op->Asl.ExternalName);
902 * Local was used outside a control method, or there was an error
903 * in the method declaration.
905 AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD, Op, Op->Asl.ExternalName);
909 RegisterNumber = (Op->Asl.AmlOpcode & 0x000F);
912 * If the local is being used as a target, mark the local
915 if (Op->Asl.CompileFlags & NODE_IS_TARGET)
917 MethodInfo->LocalInitialized[RegisterNumber] = TRUE;
921 * Otherwise, this is a reference, check if the local
922 * has been previously initialized.
924 * The only operator that accepts an uninitialized value is ObjectType()
926 else if ((!MethodInfo->LocalInitialized[RegisterNumber]) &&
927 (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE))
929 LocalName[strlen (LocalName) -1] = (char) (RegisterNumber + 0x30);
930 AslError (ASL_ERROR, ASL_MSG_LOCAL_INIT, Op, LocalName);
946 * Arg was used outside a control method, or there was an error
947 * in the method declaration.
949 AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD, Op, Op->Asl.ExternalName);
953 RegisterNumber = (Op->Asl.AmlOpcode & 0x000F) - 8;
954 ArgName[strlen (ArgName) -1] = (char) (RegisterNumber + 0x30);
957 * If the Arg is being used as a target, mark the local
960 if (Op->Asl.CompileFlags & NODE_IS_TARGET)
962 MethodInfo->ArgInitialized[RegisterNumber] = TRUE;
966 * Otherwise, this is a reference, check if the Arg
967 * has been previously initialized.
969 * The only operator that accepts an uninitialized value is ObjectType()
971 else if ((!MethodInfo->ArgInitialized[RegisterNumber]) &&
972 (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE))
974 AslError (ASL_ERROR, ASL_MSG_ARG_INIT, Op, ArgName);
977 /* Flag this arg if it is not a "real" argument to the method */
979 if (RegisterNumber >= MethodInfo->NumArguments)
981 AslError (ASL_REMARK, ASL_MSG_NOT_PARAMETER, Op, ArgName);
991 * Probably was an error in the method declaration,
992 * no additional error here
994 ACPI_WARNING ((AE_INFO, "%p, No parent method", Op));
998 /* Child indicates a return value */
1000 if ((Op->Asl.Child) &&
1001 (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG))
1003 MethodInfo->NumReturnWithValue++;
1007 MethodInfo->NumReturnNoValue++;
1013 case PARSEOP_CONTINUE:
1015 Next = Op->Asl.Parent;
1018 if (Next->Asl.ParseOpcode == PARSEOP_WHILE)
1022 Next = Next->Asl.Parent;
1027 AslError (ASL_ERROR, ASL_MSG_NO_WHILE, Op, NULL);
1034 /* We can range check if the argument is an integer */
1036 if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_INTEGER) &&
1037 (Op->Asl.Child->Asl.Value.Integer > ACPI_UINT8_MAX))
1039 AslError (ASL_ERROR, ASL_MSG_INVALID_TIME, Op, NULL);
1044 case PARSEOP_DEVICE:
1047 case PARSEOP_OPERATIONREGION:
1048 case PARSEOP_POWERRESOURCE:
1049 case PARSEOP_PROCESSOR:
1050 case PARSEOP_THERMALZONE:
1053 * The first operand is a name to be created in the namespace.
1054 * Check against the reserved list.
1056 i = ApCheckForPredefinedName (Op, Op->Asl.NameSeg);
1057 if (i < ACPI_VALID_RESERVED_NAME_MAX)
1059 AslError (ASL_ERROR, ASL_MSG_RESERVED_USE, Op, Op->Asl.ExternalName);
1066 /* Typecheck any predefined names statically defined with Name() */
1068 ApCheckForPredefinedObject (Op, Op->Asl.NameSeg);
1070 /* Special typechecking for _HID */
1072 if (!ACPI_STRCMP (METHOD_NAME__HID, Op->Asl.NameSeg))
1074 Next = Op->Asl.Child->Asl.Next;
1075 AnCheckId (Next, ASL_TYPE_HID);
1078 /* Special typechecking for _CID */
1080 else if (!ACPI_STRCMP (METHOD_NAME__CID, Op->Asl.NameSeg))
1082 Next = Op->Asl.Child->Asl.Next;
1084 if ((Next->Asl.ParseOpcode == PARSEOP_PACKAGE) ||
1085 (Next->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE))
1087 Next = Next->Asl.Child;
1090 AnCheckId (Next, ASL_TYPE_CID);
1091 Next = Next->Asl.Next;
1096 AnCheckId (Next, ASL_TYPE_CID);
1110 /*******************************************************************************
1112 * FUNCTION: AnLastStatementIsReturn
1114 * PARAMETERS: Op - A method parse node
1116 * RETURN: TRUE if last statement is an ASL RETURN. False otherwise
1118 * DESCRIPTION: Walk down the list of top level statements within a method
1119 * to find the last one. Check if that last statement is in
1120 * fact a RETURN statement.
1122 ******************************************************************************/
1125 AnLastStatementIsReturn (
1126 ACPI_PARSE_OBJECT *Op)
1128 ACPI_PARSE_OBJECT *Next;
1132 * Check if last statement is a return
1134 Next = ASL_GET_CHILD_NODE (Op);
1137 if ((!Next->Asl.Next) &&
1138 (Next->Asl.ParseOpcode == PARSEOP_RETURN))
1143 Next = ASL_GET_PEER_NODE (Next);
1150 /*******************************************************************************
1152 * FUNCTION: AnMethodAnalysisWalkEnd
1154 * PARAMETERS: ASL_WALK_CALLBACK
1158 * DESCRIPTION: Ascending callback for analysis walk. Complete method
1161 ******************************************************************************/
1164 AnMethodAnalysisWalkEnd (
1165 ACPI_PARSE_OBJECT *Op,
1169 ASL_ANALYSIS_WALK_INFO *WalkInfo = (ASL_ANALYSIS_WALK_INFO *) Context;
1170 ASL_METHOD_INFO *MethodInfo = WalkInfo->MethodStack;
1173 switch (Op->Asl.ParseOpcode)
1175 case PARSEOP_METHOD:
1176 case PARSEOP_RETURN:
1179 printf ("No method info for method! [%s]\n", Op->Asl.Namepath);
1180 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
1181 "No method info for this method");
1182 CmCleanupAndExit ();
1183 return (AE_AML_INTERNAL);
1191 switch (Op->Asl.ParseOpcode)
1193 case PARSEOP_METHOD:
1195 WalkInfo->MethodStack = MethodInfo->Next;
1198 * Check if there is no return statement at the end of the
1199 * method AND we can actually get there -- i.e., the execution
1200 * of the method can possibly terminate without a return statement.
1202 if ((!AnLastStatementIsReturn (Op)) &&
1203 (!(Op->Asl.CompileFlags & NODE_HAS_NO_EXIT)))
1206 * No return statement, and execution can possibly exit
1207 * via this path. This is equivalent to Return ()
1209 MethodInfo->NumReturnNoValue++;
1213 * Check for case where some return statements have a return value
1214 * and some do not. Exit without a return statement is a return with
1217 if (MethodInfo->NumReturnNoValue &&
1218 MethodInfo->NumReturnWithValue)
1220 AslError (ASL_WARNING, ASL_MSG_RETURN_TYPES, Op,
1221 Op->Asl.ExternalName);
1225 * If there are any RETURN() statements with no value, or there is a
1226 * control path that allows the method to exit without a return value,
1227 * we mark the method as a method that does not return a value. This
1228 * knowledge can be used to check method invocations that expect a
1231 if (MethodInfo->NumReturnNoValue)
1233 if (MethodInfo->NumReturnWithValue)
1235 Op->Asl.CompileFlags |= NODE_METHOD_SOME_NO_RETVAL;
1239 Op->Asl.CompileFlags |= NODE_METHOD_NO_RETVAL;
1244 * Check predefined method names for correct return behavior
1245 * and correct number of arguments
1247 ApCheckForPredefinedMethod (Op, MethodInfo);
1248 ACPI_FREE (MethodInfo);
1252 case PARSEOP_RETURN:
1255 * If the parent is a predefined method name, attempt to typecheck
1256 * the return value. Only static types can be validated.
1258 ApCheckPredefinedReturnValue (Op, MethodInfo);
1261 * The parent block does not "exit" and continue execution -- the
1262 * method is terminated here with the Return() statement.
1264 Op->Asl.Parent->Asl.CompileFlags |= NODE_HAS_NO_EXIT;
1266 /* Used in the "typing" pass later */
1268 Op->Asl.ParentMethod = MethodInfo->Op;
1271 * If there is a peer node after the return statement, then this
1272 * node is unreachable code -- i.e., it won't be executed because of
1273 * the preceeding Return() statement.
1277 AslError (ASL_WARNING, ASL_MSG_UNREACHABLE_CODE, Op->Asl.Next, NULL);
1284 if ((Op->Asl.CompileFlags & NODE_HAS_NO_EXIT) &&
1286 (Op->Asl.Next->Asl.ParseOpcode == PARSEOP_ELSE))
1289 * This IF has a corresponding ELSE. The IF block has no exit,
1290 * (it contains an unconditional Return)
1291 * mark the ELSE block to remember this fact.
1293 Op->Asl.Next->Asl.CompileFlags |= NODE_IF_HAS_NO_EXIT;
1300 if ((Op->Asl.CompileFlags & NODE_HAS_NO_EXIT) &&
1301 (Op->Asl.CompileFlags & NODE_IF_HAS_NO_EXIT))
1304 * This ELSE block has no exit and the corresponding IF block
1305 * has no exit either. Therefore, the parent node has no exit.
1307 Op->Asl.Parent->Asl.CompileFlags |= NODE_HAS_NO_EXIT;
1314 if ((Op->Asl.CompileFlags & NODE_HAS_NO_EXIT) &&
1317 /* If this node has no exit, then the parent has no exit either */
1319 Op->Asl.Parent->Asl.CompileFlags |= NODE_HAS_NO_EXIT;
1328 /*******************************************************************************
1330 * FUNCTION: AnMethodTypingWalkBegin
1332 * PARAMETERS: ASL_WALK_CALLBACK
1336 * DESCRIPTION: Descending callback for the typing walk.
1338 ******************************************************************************/
1341 AnMethodTypingWalkBegin (
1342 ACPI_PARSE_OBJECT *Op,
1351 /*******************************************************************************
1353 * FUNCTION: AnMethodTypingWalkEnd
1355 * PARAMETERS: ASL_WALK_CALLBACK
1359 * DESCRIPTION: Ascending callback for typing walk. Complete the method
1360 * return analysis. Check methods for:
1361 * 1) Initialized local variables
1362 * 2) Valid arguments
1365 ******************************************************************************/
1368 AnMethodTypingWalkEnd (
1369 ACPI_PARSE_OBJECT *Op,
1373 UINT32 ThisNodeBtype;
1376 switch (Op->Asl.ParseOpcode)
1378 case PARSEOP_METHOD:
1380 Op->Asl.CompileFlags |= NODE_METHOD_TYPED;
1383 case PARSEOP_RETURN:
1385 if ((Op->Asl.Child) &&
1386 (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG))
1388 ThisNodeBtype = AnGetBtype (Op->Asl.Child);
1390 if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_METHODCALL) &&
1391 (ThisNodeBtype == (ACPI_UINT32_MAX -1)))
1394 * The called method is untyped at this time (typically a
1395 * forward reference).
1397 * Check for a recursive method call first.
1399 if (Op->Asl.ParentMethod != Op->Asl.Child->Asl.Node->Op)
1401 /* We must type the method here */
1403 TrWalkParseTree (Op->Asl.Child->Asl.Node->Op,
1404 ASL_WALK_VISIT_TWICE, AnMethodTypingWalkBegin,
1405 AnMethodTypingWalkEnd, NULL);
1407 ThisNodeBtype = AnGetBtype (Op->Asl.Child);
1411 /* Returns a value, save the value type */
1413 if (Op->Asl.ParentMethod)
1415 Op->Asl.ParentMethod->Asl.AcpiBtype |= ThisNodeBtype;
1428 /*******************************************************************************
1430 * FUNCTION: AnCheckMethodReturnValue
1432 * PARAMETERS: Op - Parent
1433 * OpInfo - Parent info
1434 * ArgOp - Method invocation op
1435 * RequiredBtypes - What caller requires
1436 * ThisNodeBtype - What this node returns (if anything)
1440 * DESCRIPTION: Check a method invocation for 1) A return value and if it does
1441 * in fact return a value, 2) check the type of the return value.
1443 ******************************************************************************/
1446 AnCheckMethodReturnValue (
1447 ACPI_PARSE_OBJECT *Op,
1448 const ACPI_OPCODE_INFO *OpInfo,
1449 ACPI_PARSE_OBJECT *ArgOp,
1450 UINT32 RequiredBtypes,
1451 UINT32 ThisNodeBtype)
1453 ACPI_PARSE_OBJECT *OwningOp;
1454 ACPI_NAMESPACE_NODE *Node;
1457 Node = ArgOp->Asl.Node;
1460 /* Examine the parent op of this method */
1462 OwningOp = Node->Op;
1463 if (OwningOp->Asl.CompileFlags & NODE_METHOD_NO_RETVAL)
1465 /* Method NEVER returns a value */
1467 AslError (ASL_ERROR, ASL_MSG_NO_RETVAL, Op, Op->Asl.ExternalName);
1469 else if (OwningOp->Asl.CompileFlags & NODE_METHOD_SOME_NO_RETVAL)
1471 /* Method SOMETIMES returns a value, SOMETIMES not */
1473 AslError (ASL_WARNING, ASL_MSG_SOME_NO_RETVAL, Op, Op->Asl.ExternalName);
1475 else if (!(ThisNodeBtype & RequiredBtypes))
1477 /* Method returns a value, but the type is wrong */
1479 AnFormatBtype (StringBuffer, ThisNodeBtype);
1480 AnFormatBtype (StringBuffer2, RequiredBtypes);
1484 * The case where the method does not return any value at all
1485 * was already handled in the namespace cross reference
1486 * -- Only issue an error if the method in fact returns a value,
1487 * but it is of the wrong type
1489 if (ThisNodeBtype != 0)
1492 "Method returns [%s], %s operator requires [%s]",
1493 StringBuffer, OpInfo->Name, StringBuffer2);
1495 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, MsgBuffer);
1501 /*******************************************************************************
1503 * FUNCTION: AnOperandTypecheckWalkBegin
1505 * PARAMETERS: ASL_WALK_CALLBACK
1509 * DESCRIPTION: Descending callback for the analysis walk. Check methods for:
1510 * 1) Initialized local variables
1511 * 2) Valid arguments
1514 ******************************************************************************/
1517 AnOperandTypecheckWalkBegin (
1518 ACPI_PARSE_OBJECT *Op,
1527 /*******************************************************************************
1529 * FUNCTION: AnOperandTypecheckWalkEnd
1531 * PARAMETERS: ASL_WALK_CALLBACK
1535 * DESCRIPTION: Ascending callback for analysis walk. Complete method
1538 ******************************************************************************/
1541 AnOperandTypecheckWalkEnd (
1542 ACPI_PARSE_OBJECT *Op,
1546 const ACPI_OPCODE_INFO *OpInfo;
1547 UINT32 RuntimeArgTypes;
1548 UINT32 RuntimeArgTypes2;
1549 UINT32 RequiredBtypes;
1550 UINT32 ThisNodeBtype;
1551 UINT32 CommonBtypes;
1553 ACPI_PARSE_OBJECT *ArgOp;
1557 switch (Op->Asl.AmlOpcode)
1559 case AML_RAW_DATA_BYTE:
1560 case AML_RAW_DATA_WORD:
1561 case AML_RAW_DATA_DWORD:
1562 case AML_RAW_DATA_QWORD:
1563 case AML_RAW_DATA_BUFFER:
1564 case AML_RAW_DATA_CHAIN:
1565 case AML_PACKAGE_LENGTH:
1566 case AML_UNASSIGNED_OPCODE:
1567 case AML_DEFAULT_ARG_OP:
1569 /* Ignore the internal (compiler-only) AML opcodes */
1577 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
1583 ArgOp = Op->Asl.Child;
1584 RuntimeArgTypes = OpInfo->RuntimeArgs;
1585 OpcodeClass = OpInfo->Class;
1587 #ifdef ASL_ERROR_NAMED_OBJECT_IN_WHILE
1589 * Update 11/2008: In practice, we can't perform this check. A simple
1590 * analysis is not sufficient. Also, it can cause errors when compiling
1591 * disassembled code because of the way Switch operators are implemented
1592 * (a While(One) loop with a named temp variable created within.)
1596 * If we are creating a named object, check if we are within a while loop
1597 * by checking if the parent is a WHILE op. This is a simple analysis, but
1598 * probably sufficient for many cases.
1600 * Allow Scope(), Buffer(), and Package().
1602 if (((OpcodeClass == AML_CLASS_NAMED_OBJECT) && (Op->Asl.AmlOpcode != AML_SCOPE_OP)) ||
1603 ((OpcodeClass == AML_CLASS_CREATE) && (OpInfo->Flags & AML_NSNODE)))
1605 if (Op->Asl.Parent->Asl.AmlOpcode == AML_WHILE_OP)
1607 AslError (ASL_ERROR, ASL_MSG_NAMED_OBJECT_IN_WHILE, Op, NULL);
1613 * Special case for control opcodes IF/RETURN/WHILE since they
1614 * have no runtime arg list (at this time)
1616 switch (Op->Asl.AmlOpcode)
1622 if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL)
1624 /* Check for an internal method */
1626 if (AnIsInternalMethod (ArgOp))
1631 /* The lone arg is a method call, check it */
1633 RequiredBtypes = AnMapArgTypeToBtype (ARGI_INTEGER);
1634 if (Op->Asl.AmlOpcode == AML_RETURN_OP)
1636 RequiredBtypes = 0xFFFFFFFF;
1639 ThisNodeBtype = AnGetBtype (ArgOp);
1640 if (ThisNodeBtype == ACPI_UINT32_MAX)
1644 AnCheckMethodReturnValue (Op, OpInfo, ArgOp,
1645 RequiredBtypes, ThisNodeBtype);
1653 /* Ignore the non-executable opcodes */
1655 if (RuntimeArgTypes == ARGI_INVALID_OPCODE)
1660 switch (OpcodeClass)
1662 case AML_CLASS_EXECUTE:
1663 case AML_CLASS_CREATE:
1664 case AML_CLASS_CONTROL:
1665 case AML_CLASS_RETURN_VALUE:
1667 /* TBD: Change class or fix typechecking for these */
1669 if ((Op->Asl.AmlOpcode == AML_BUFFER_OP) ||
1670 (Op->Asl.AmlOpcode == AML_PACKAGE_OP) ||
1671 (Op->Asl.AmlOpcode == AML_VAR_PACKAGE_OP))
1676 /* Reverse the runtime argument list */
1678 RuntimeArgTypes2 = 0;
1679 while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes)))
1681 RuntimeArgTypes2 <<= ARG_TYPE_WIDTH;
1682 RuntimeArgTypes2 |= ArgType;
1683 INCREMENT_ARG_LIST (RuntimeArgTypes);
1686 while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes2)))
1688 RequiredBtypes = AnMapArgTypeToBtype (ArgType);
1690 ThisNodeBtype = AnGetBtype (ArgOp);
1691 if (ThisNodeBtype == ACPI_UINT32_MAX)
1696 /* Examine the arg based on the required type of the arg */
1700 case ARGI_TARGETREF:
1702 if (ArgOp->Asl.ParseOpcode == PARSEOP_ZERO)
1704 /* ZERO is the placeholder for "don't store result" */
1706 ThisNodeBtype = RequiredBtypes;
1710 if (ArgOp->Asl.ParseOpcode == PARSEOP_INTEGER)
1713 * This is the case where an original reference to a resource
1714 * descriptor field has been replaced by an (Integer) offset.
1715 * These named fields are supported at compile-time only;
1716 * the names are not passed to the interpreter (via the AML).
1718 if ((ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
1719 (ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
1721 AslError (ASL_ERROR, ASL_MSG_RESOURCE_FIELD, ArgOp, NULL);
1725 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, NULL);
1730 if ((ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL) ||
1731 (ArgOp->Asl.ParseOpcode == PARSEOP_DEREFOF))
1736 ThisNodeBtype = RequiredBtypes;
1740 case ARGI_REFERENCE: /* References */
1741 case ARGI_INTEGER_REF:
1742 case ARGI_OBJECT_REF:
1743 case ARGI_DEVICE_REF:
1745 switch (ArgOp->Asl.ParseOpcode)
1747 case PARSEOP_LOCAL0:
1748 case PARSEOP_LOCAL1:
1749 case PARSEOP_LOCAL2:
1750 case PARSEOP_LOCAL3:
1751 case PARSEOP_LOCAL4:
1752 case PARSEOP_LOCAL5:
1753 case PARSEOP_LOCAL6:
1754 case PARSEOP_LOCAL7:
1756 /* TBD: implement analysis of current value (type) of the local */
1757 /* For now, just treat any local as a typematch */
1759 /*ThisNodeBtype = RequiredBtypes;*/
1770 /* Hard to analyze argument types, sow we won't */
1771 /* For now, just treat any arg as a typematch */
1773 /* ThisNodeBtype = RequiredBtypes; */
1793 CommonBtypes = ThisNodeBtype & RequiredBtypes;
1795 if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL)
1797 if (AnIsInternalMethod (ArgOp))
1802 /* Check a method call for a valid return value */
1804 AnCheckMethodReturnValue (Op, OpInfo, ArgOp,
1805 RequiredBtypes, ThisNodeBtype);
1809 * Now check if the actual type(s) match at least one
1810 * bit to the required type
1812 else if (!CommonBtypes)
1814 /* No match -- this is a type mismatch error */
1816 AnFormatBtype (StringBuffer, ThisNodeBtype);
1817 AnFormatBtype (StringBuffer2, RequiredBtypes);
1819 sprintf (MsgBuffer, "[%s] found, %s operator requires [%s]",
1820 StringBuffer, OpInfo->Name, StringBuffer2);
1822 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, MsgBuffer);
1826 ArgOp = ArgOp->Asl.Next;
1827 INCREMENT_ARG_LIST (RuntimeArgTypes2);
1839 /*******************************************************************************
1841 * FUNCTION: AnIsResultUsed
1843 * PARAMETERS: Op - Parent op for the operator
1845 * RETURN: TRUE if result from this operation is actually consumed
1847 * DESCRIPTION: Determine if the function result value from an operator is
1850 ******************************************************************************/
1854 ACPI_PARSE_OBJECT *Op)
1856 ACPI_PARSE_OBJECT *Parent;
1859 switch (Op->Asl.ParseOpcode)
1861 case PARSEOP_INCREMENT:
1862 case PARSEOP_DECREMENT:
1864 /* These are standalone operators, no return value */
1872 /* Examine parent to determine if the return value is used */
1874 Parent = Op->Asl.Parent;
1875 switch (Parent->Asl.ParseOpcode)
1877 /* If/While - check if the operator is the predicate */
1882 /* First child is the predicate */
1884 if (Parent->Asl.Child == Op)
1890 /* Not used if one of these is the parent */
1892 case PARSEOP_METHOD:
1893 case PARSEOP_DEFINITIONBLOCK:
1899 /* Any other type of parent means that the result is used */
1906 /*******************************************************************************
1908 * FUNCTION: AnOtherSemanticAnalysisWalkBegin
1910 * PARAMETERS: ASL_WALK_CALLBACK
1914 * DESCRIPTION: Descending callback for the analysis walk. Checks for
1915 * miscellaneous issues in the code.
1917 ******************************************************************************/
1920 AnOtherSemanticAnalysisWalkBegin (
1921 ACPI_PARSE_OBJECT *Op,
1925 ACPI_PARSE_OBJECT *ArgNode;
1926 ACPI_PARSE_OBJECT *PrevArgNode = NULL;
1927 const ACPI_OPCODE_INFO *OpInfo;
1930 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
1933 * Determine if an execution class operator actually does something by
1934 * checking if it has a target and/or the function return value is used.
1935 * (Target is optional, so a standalone statement can actually do nothing.)
1937 if ((OpInfo->Class == AML_CLASS_EXECUTE) &&
1938 (OpInfo->Flags & AML_HAS_RETVAL) &&
1939 (!AnIsResultUsed (Op)))
1941 if (OpInfo->Flags & AML_HAS_TARGET)
1944 * Find the target node, it is always the last child. If the traget
1945 * is not specified in the ASL, a default node of type Zero was
1946 * created by the parser.
1948 ArgNode = Op->Asl.Child;
1949 while (ArgNode->Asl.Next)
1951 PrevArgNode = ArgNode;
1952 ArgNode = ArgNode->Asl.Next;
1955 /* Divide() is the only weird case, it has two targets */
1957 if (Op->Asl.AmlOpcode == AML_DIVIDE_OP)
1959 if ((ArgNode->Asl.ParseOpcode == PARSEOP_ZERO) &&
1961 (PrevArgNode->Asl.ParseOpcode == PARSEOP_ZERO))
1963 AslError (ASL_WARNING, ASL_MSG_RESULT_NOT_USED, Op, Op->Asl.ExternalName);
1966 else if (ArgNode->Asl.ParseOpcode == PARSEOP_ZERO)
1968 AslError (ASL_WARNING, ASL_MSG_RESULT_NOT_USED, Op, Op->Asl.ExternalName);
1974 * Has no target and the result is not used. Only a couple opcodes
1975 * can have this combination.
1977 switch (Op->Asl.ParseOpcode)
1979 case PARSEOP_ACQUIRE:
1981 case PARSEOP_LOADTABLE:
1985 AslError (ASL_WARNING, ASL_MSG_RESULT_NOT_USED, Op, Op->Asl.ExternalName);
1993 * Semantic checks for individual ASL operators
1995 switch (Op->Asl.ParseOpcode)
1997 case PARSEOP_ACQUIRE:
2000 * Emit a warning if the timeout parameter for these operators is not
2001 * ACPI_WAIT_FOREVER, and the result value from the operator is not
2002 * checked, meaning that a timeout could happen, but the code
2003 * would not know about it.
2006 /* First child is the namepath, 2nd child is timeout */
2008 ArgNode = Op->Asl.Child;
2009 ArgNode = ArgNode->Asl.Next;
2012 * Check for the WAIT_FOREVER case - defined by the ACPI spec to be
2015 if (((ArgNode->Asl.ParseOpcode == PARSEOP_WORDCONST) ||
2016 (ArgNode->Asl.ParseOpcode == PARSEOP_INTEGER)) &&
2017 (ArgNode->Asl.Value.Integer >= (UINT64) ACPI_WAIT_FOREVER))
2023 * The operation could timeout. If the return value is not used
2024 * (indicates timeout occurred), issue a warning
2026 if (!AnIsResultUsed (Op))
2028 AslError (ASL_WARNING, ASL_MSG_TIMEOUT, ArgNode, Op->Asl.ExternalName);
2032 case PARSEOP_CREATEFIELD:
2034 * Check for a zero Length (NumBits) operand. NumBits is the 3rd operand
2036 ArgNode = Op->Asl.Child;
2037 ArgNode = ArgNode->Asl.Next;
2038 ArgNode = ArgNode->Asl.Next;
2040 if ((ArgNode->Asl.ParseOpcode == PARSEOP_ZERO) ||
2041 ((ArgNode->Asl.ParseOpcode == PARSEOP_INTEGER) &&
2042 (ArgNode->Asl.Value.Integer == 0)))
2044 AslError (ASL_ERROR, ASL_MSG_NON_ZERO, ArgNode, NULL);
2056 /*******************************************************************************
2058 * FUNCTION: AnOtherSemanticAnalysisWalkEnd
2060 * PARAMETERS: ASL_WALK_CALLBACK
2064 * DESCRIPTION: Ascending callback for analysis walk. Complete method
2067 ******************************************************************************/
2070 AnOtherSemanticAnalysisWalkEnd (
2071 ACPI_PARSE_OBJECT *Op,
2081 #ifdef ACPI_OBSOLETE_FUNCTIONS
2082 /*******************************************************************************
2084 * FUNCTION: AnMapBtypeToEtype
2086 * PARAMETERS: Btype - Bitfield of ACPI types
2088 * RETURN: The Etype corresponding the the Btype
2090 * DESCRIPTION: Convert a bitfield type to an encoded type
2092 ******************************************************************************/
2108 for (i = 1; i < Btype; i *= 2)