No empty .Rs/.Re
[netbsd-mini2440.git] / sys / external / intel-public / acpica / dist / compiler / aslanalyze.c
blobd44adda8ff006620a316738a8d4eb978adc4282b
2 /******************************************************************************
4 * Module Name: aslanalyze.c - check for semantic errors
6 *****************************************************************************/
8 /******************************************************************************
10 * 1. Copyright Notice
12 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
13 * All rights reserved.
15 * 2. License
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
20 * property rights.
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
39 * conditions are met:
41 * 3. Conditions
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
65 * make.
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
71 * distribution.
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
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
89 * PARTICULAR PURPOSE.
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
98 * LIMITED REMEDY.
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 "aslcompiler.h"
119 #include "aslcompiler.y.h"
120 #include "acparser.h"
121 #include "amlcode.h"
123 #define _COMPONENT ACPI_COMPILER
124 ACPI_MODULE_NAME ("aslanalyze")
126 /* Local prototypes */
128 static UINT32
129 AnMapArgTypeToBtype (
130 UINT32 ArgType);
132 static UINT32
133 AnMapEtypeToBtype (
134 UINT32 Etype);
136 static void
137 AnFormatBtype (
138 char *Buffer,
139 UINT32 Btype);
141 static UINT32
142 AnGetBtype (
143 ACPI_PARSE_OBJECT *Op);
145 static UINT32
146 AnCheckForReservedName (
147 ACPI_PARSE_OBJECT *Op,
148 char *Name);
150 static void
151 AnCheckForReservedMethod (
152 ACPI_PARSE_OBJECT *Op,
153 ASL_METHOD_INFO *MethodInfo);
155 static UINT32
156 AnMapObjTypeToBtype (
157 ACPI_PARSE_OBJECT *Op);
159 static BOOLEAN
160 AnLastStatementIsReturn (
161 ACPI_PARSE_OBJECT *Op);
163 static void
164 AnCheckMethodReturnValue (
165 ACPI_PARSE_OBJECT *Op,
166 const ACPI_OPCODE_INFO *OpInfo,
167 ACPI_PARSE_OBJECT *ArgOp,
168 UINT32 RequiredBtypes,
169 UINT32 ThisNodeBtype);
171 static BOOLEAN
172 AnIsInternalMethod (
173 ACPI_PARSE_OBJECT *Op);
175 static UINT32
176 AnGetInternalMethodReturnType (
177 ACPI_PARSE_OBJECT *Op);
179 BOOLEAN
180 AnIsResultUsed (
181 ACPI_PARSE_OBJECT *Op);
184 /*******************************************************************************
186 * FUNCTION: AnIsInternalMethod
188 * PARAMETERS: Op - Current op
190 * RETURN: Boolean
192 * DESCRIPTION: Check for an internal control method.
194 ******************************************************************************/
196 static BOOLEAN
197 AnIsInternalMethod (
198 ACPI_PARSE_OBJECT *Op)
201 if ((!ACPI_STRCMP (Op->Asl.ExternalName, "\\_OSI")) ||
202 (!ACPI_STRCMP (Op->Asl.ExternalName, "_OSI")))
204 return (TRUE);
207 return (FALSE);
211 /*******************************************************************************
213 * FUNCTION: AnGetInternalMethodReturnType
215 * PARAMETERS: Op - Current op
217 * RETURN: Btype
219 * DESCRIPTION: Get the return type of an internal method
221 ******************************************************************************/
223 static UINT32
224 AnGetInternalMethodReturnType (
225 ACPI_PARSE_OBJECT *Op)
228 if ((!ACPI_STRCMP (Op->Asl.ExternalName, "\\_OSI")) ||
229 (!ACPI_STRCMP (Op->Asl.ExternalName, "_OSI")))
231 return (ACPI_BTYPE_STRING);
234 return (0);
238 /*******************************************************************************
240 * FUNCTION: AnMapArgTypeToBtype
242 * PARAMETERS: ArgType - The ARGI required type(s) for this argument,
243 * from the opcode info table
245 * RETURN: The corresponding Bit-encoded types
247 * DESCRIPTION: Convert an encoded ARGI required argument type code into a
248 * bitfield type code. Implements the implicit source conversion
249 * rules.
251 ******************************************************************************/
253 static UINT32
254 AnMapArgTypeToBtype (
255 UINT32 ArgType)
258 switch (ArgType)
261 /* Simple types */
263 case ARGI_ANYTYPE:
264 return (ACPI_BTYPE_OBJECTS_AND_REFS);
266 case ARGI_PACKAGE:
267 return (ACPI_BTYPE_PACKAGE);
269 case ARGI_EVENT:
270 return (ACPI_BTYPE_EVENT);
272 case ARGI_MUTEX:
273 return (ACPI_BTYPE_MUTEX);
275 case ARGI_DDBHANDLE:
277 * DDBHandleObject := SuperName
278 * ACPI_BTYPE_REFERENCE: Index reference as parameter of Load/Unload
280 return (ACPI_BTYPE_DDB_HANDLE | ACPI_BTYPE_REFERENCE);
282 /* Interchangeable types */
284 * Source conversion rules:
285 * Integer, String, and Buffer are all interchangeable
287 case ARGI_INTEGER:
288 case ARGI_STRING:
289 case ARGI_BUFFER:
290 case ARGI_BUFFER_OR_STRING:
291 case ARGI_COMPUTEDATA:
292 return (ACPI_BTYPE_COMPUTE_DATA);
294 /* References */
296 case ARGI_INTEGER_REF:
297 return (ACPI_BTYPE_INTEGER);
299 case ARGI_OBJECT_REF:
300 return (ACPI_BTYPE_ALL_OBJECTS);
302 case ARGI_DEVICE_REF:
303 return (ACPI_BTYPE_DEVICE_OBJECTS);
305 case ARGI_REFERENCE:
306 return (ACPI_BTYPE_REFERENCE);
308 case ARGI_TARGETREF:
309 case ARGI_FIXED_TARGET:
310 case ARGI_SIMPLE_TARGET:
311 return (ACPI_BTYPE_OBJECTS_AND_REFS);
313 /* Complex types */
315 case ARGI_DATAOBJECT:
318 * Buffer, string, package or reference to a Op -
319 * Used only by SizeOf operator
321 return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER |
322 ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE);
324 case ARGI_COMPLEXOBJ:
326 /* Buffer, String, or package */
328 return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER | ACPI_BTYPE_PACKAGE);
330 case ARGI_REF_OR_STRING:
331 return (ACPI_BTYPE_STRING | ACPI_BTYPE_REFERENCE);
333 case ARGI_REGION_OR_BUFFER:
335 /* Used by Load() only. Allow buffers in addition to regions/fields */
337 return (ACPI_BTYPE_REGION | ACPI_BTYPE_BUFFER | ACPI_BTYPE_FIELD_UNIT);
339 case ARGI_DATAREFOBJ:
340 return (ACPI_BTYPE_INTEGER |ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER |
341 ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE | ACPI_BTYPE_DDB_HANDLE);
343 default:
344 break;
347 return (ACPI_BTYPE_OBJECTS_AND_REFS);
351 /*******************************************************************************
353 * FUNCTION: AnMapEtypeToBtype
355 * PARAMETERS: Etype - Encoded ACPI Type
357 * RETURN: Btype corresponding to the Etype
359 * DESCRIPTION: Convert an encoded ACPI type to a bitfield type applying the
360 * operand conversion rules. In other words, returns the type(s)
361 * this Etype is implicitly converted to during interpretation.
363 ******************************************************************************/
365 static UINT32
366 AnMapEtypeToBtype (
367 UINT32 Etype)
371 if (Etype == ACPI_TYPE_ANY)
373 return ACPI_BTYPE_OBJECTS_AND_REFS;
376 /* Try the standard ACPI data types */
378 if (Etype <= ACPI_TYPE_EXTERNAL_MAX)
381 * This switch statement implements the allowed operand conversion
382 * rules as per the "ASL Data Types" section of the ACPI
383 * specification.
385 switch (Etype)
387 case ACPI_TYPE_INTEGER:
388 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_DDB_HANDLE);
390 case ACPI_TYPE_STRING:
391 case ACPI_TYPE_BUFFER:
392 return (ACPI_BTYPE_COMPUTE_DATA);
394 case ACPI_TYPE_PACKAGE:
395 return (ACPI_BTYPE_PACKAGE);
397 case ACPI_TYPE_FIELD_UNIT:
398 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_FIELD_UNIT);
400 case ACPI_TYPE_BUFFER_FIELD:
401 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_BUFFER_FIELD);
403 case ACPI_TYPE_DDB_HANDLE:
404 return (ACPI_BTYPE_INTEGER | ACPI_BTYPE_DDB_HANDLE);
406 case ACPI_BTYPE_DEBUG_OBJECT:
408 /* Cannot be used as a source operand */
410 return (0);
412 default:
413 return (1 << (Etype - 1));
417 /* Try the internal data types */
419 switch (Etype)
421 case ACPI_TYPE_LOCAL_REGION_FIELD:
422 case ACPI_TYPE_LOCAL_BANK_FIELD:
423 case ACPI_TYPE_LOCAL_INDEX_FIELD:
425 /* Named fields can be either Integer/Buffer/String */
427 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_FIELD_UNIT);
429 case ACPI_TYPE_LOCAL_ALIAS:
431 return (ACPI_BTYPE_INTEGER);
434 case ACPI_TYPE_LOCAL_RESOURCE:
435 case ACPI_TYPE_LOCAL_RESOURCE_FIELD:
437 return (ACPI_BTYPE_REFERENCE);
439 default:
440 printf ("Unhandled encoded type: %X\n", Etype);
441 return (0);
446 /*******************************************************************************
448 * FUNCTION: AnFormatBtype
450 * PARAMETERS: Btype - Bitfield of ACPI types
451 * Buffer - Where to put the ascii string
453 * RETURN: None.
455 * DESCRIPTION: Convert a Btype to a string of ACPI types
457 ******************************************************************************/
459 static void
460 AnFormatBtype (
461 char *Buffer,
462 UINT32 Btype)
464 UINT32 Type;
465 BOOLEAN First = TRUE;
468 *Buffer = 0;
470 if (Btype == 0)
472 strcat (Buffer, "NoReturnValue");
473 return;
476 for (Type = 1; Type <= ACPI_TYPE_EXTERNAL_MAX; Type++)
478 if (Btype & 0x00000001)
480 if (!First)
482 strcat (Buffer, "|");
484 First = FALSE;
485 strcat (Buffer, AcpiUtGetTypeName (Type));
487 Btype >>= 1;
490 if (Btype & 0x00000001)
492 if (!First)
494 strcat (Buffer, "|");
496 First = FALSE;
497 strcat (Buffer, "Reference");
500 Btype >>= 1;
501 if (Btype & 0x00000001)
503 if (!First)
505 strcat (Buffer, "|");
507 First = FALSE;
508 strcat (Buffer, "Resource");
513 /*******************************************************************************
515 * FUNCTION: AnGetBtype
517 * PARAMETERS: Op - Parse node whose type will be returned.
519 * RETURN: The Btype associated with the Op.
521 * DESCRIPTION: Get the (bitfield) ACPI type associated with the parse node.
522 * Handles the case where the node is a name or method call and
523 * the actual type must be obtained from the namespace node.
525 ******************************************************************************/
527 static UINT32
528 AnGetBtype (
529 ACPI_PARSE_OBJECT *Op)
531 ACPI_NAMESPACE_NODE *Node;
532 ACPI_PARSE_OBJECT *ReferencedNode;
533 UINT32 ThisNodeBtype = 0;
536 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
537 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
538 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
540 Node = Op->Asl.Node;
541 if (!Node)
543 DbgPrint (ASL_DEBUG_OUTPUT,
544 "No attached Nsnode: [%s] at line %d name [%s], ignoring typecheck\n",
545 Op->Asl.ParseOpName, Op->Asl.LineNumber,
546 Op->Asl.ExternalName);
547 return ACPI_UINT32_MAX;
550 ThisNodeBtype = AnMapEtypeToBtype (Node->Type);
551 if (!ThisNodeBtype)
553 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
554 "could not map type");
558 * Since it was a named reference, enable the
559 * reference bit also
561 ThisNodeBtype |= ACPI_BTYPE_REFERENCE;
563 if (Op->Asl.ParseOpcode == PARSEOP_METHODCALL)
565 ReferencedNode = Node->Op;
566 if (!ReferencedNode)
568 /* Check for an internal method */
570 if (AnIsInternalMethod (Op))
572 return (AnGetInternalMethodReturnType (Op));
575 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
576 "null Op pointer");
577 return ACPI_UINT32_MAX;
580 if (ReferencedNode->Asl.CompileFlags & NODE_METHOD_TYPED)
582 ThisNodeBtype = ReferencedNode->Asl.AcpiBtype;
584 else
586 return (ACPI_UINT32_MAX -1);
590 else
592 ThisNodeBtype = Op->Asl.AcpiBtype;
595 return (ThisNodeBtype);
599 /*******************************************************************************
601 * FUNCTION: AnCheckForReservedName
603 * PARAMETERS: Op - A parse node
604 * Name - NameSeg to check
606 * RETURN: None
608 * DESCRIPTION: Check a NameSeg against the reserved list.
610 ******************************************************************************/
612 static UINT32
613 AnCheckForReservedName (
614 ACPI_PARSE_OBJECT *Op,
615 char *Name)
617 UINT32 i;
620 if (Name[0] == 0)
622 AcpiOsPrintf ("Found a null name, external = %s\n",
623 Op->Asl.ExternalName);
626 /* All reserved names are prefixed with a single underscore */
628 if (Name[0] != '_')
630 return (ACPI_NOT_RESERVED_NAME);
633 /* Check for a standard reserved method name */
635 for (i = 0; ReservedMethods[i].Name; i++)
637 if (ACPI_COMPARE_NAME (Name, ReservedMethods[i].Name))
639 if (ReservedMethods[i].Flags & ASL_RSVD_SCOPE)
641 AslError (ASL_ERROR, ASL_MSG_RESERVED_WORD, Op,
642 Op->Asl.ExternalName);
643 return (ACPI_PREDEFINED_NAME);
645 else if (ReservedMethods[i].Flags & ASL_RSVD_RESOURCE_NAME)
647 AslError (ASL_ERROR, ASL_MSG_RESERVED_WORD, Op,
648 Op->Asl.ExternalName);
649 return (ACPI_PREDEFINED_NAME);
652 /* Return index into reserved array */
654 return i;
659 * Now check for the "special" reserved names --
660 * GPE: _Lxx
661 * GPE: _Exx
662 * EC: _Qxx
664 if ((Name[1] == 'L') ||
665 (Name[1] == 'E') ||
666 (Name[1] == 'Q'))
668 /* The next two characters must be hex digits */
670 if ((isxdigit (Name[2])) &&
671 (isxdigit (Name[3])))
673 return (ACPI_EVENT_RESERVED_NAME);
678 /* Check for the names reserved for the compiler itself: _T_x */
680 else if ((Op->Asl.ExternalName[1] == 'T') &&
681 (Op->Asl.ExternalName[2] == '_'))
683 /* Ignore if actually emitted by the compiler */
685 if (Op->Asl.CompileFlags & NODE_COMPILER_EMITTED)
687 return (ACPI_NOT_RESERVED_NAME);
691 * Was not actually emitted by the compiler. This is a special case,
692 * however. If the ASL code being compiled was the result of a
693 * dissasembly, it may possibly contain valid compiler-emitted names
694 * of the form "_T_x". We don't want to issue an error or even a
695 * warning and force the user to manually change the names. So, we
696 * will issue a remark instead.
698 AslError (ASL_REMARK, ASL_MSG_COMPILER_RESERVED, Op, Op->Asl.ExternalName);
699 return (ACPI_COMPILER_RESERVED_NAME);
703 * The name didn't match any of the known reserved names. Flag it as a
704 * warning, since the entire namespace starting with an underscore is
705 * reserved by the ACPI spec.
707 AslError (ASL_WARNING, ASL_MSG_UNKNOWN_RESERVED_NAME, Op,
708 Op->Asl.ExternalName);
710 return (ACPI_NOT_RESERVED_NAME);
714 /*******************************************************************************
716 * FUNCTION: AnCheckForReservedMethod
718 * PARAMETERS: Op - A parse node of type "METHOD".
719 * MethodInfo - Saved info about this method
721 * RETURN: None
723 * DESCRIPTION: If method is a reserved name, check that the number of arguments
724 * and the return type (returns a value or not) is correct.
726 ******************************************************************************/
728 static void
729 AnCheckForReservedMethod (
730 ACPI_PARSE_OBJECT *Op,
731 ASL_METHOD_INFO *MethodInfo)
733 UINT32 Index;
734 UINT32 RequiredArgsCurrent;
735 UINT32 RequiredArgsOld;
738 /* Check for a match against the reserved name list */
740 Index = AnCheckForReservedName (Op, Op->Asl.NameSeg);
742 switch (Index)
744 case ACPI_NOT_RESERVED_NAME:
745 case ACPI_PREDEFINED_NAME:
746 case ACPI_COMPILER_RESERVED_NAME:
748 /* Just return, nothing to do */
749 break;
752 case ACPI_EVENT_RESERVED_NAME:
754 Gbl_ReservedMethods++;
756 /* NumArguments must be zero for all _Lxx, _Exx, and _Qxx methods */
758 if (MethodInfo->NumArguments != 0)
760 sprintf (MsgBuffer, "%s requires %d",
761 Op->Asl.ExternalName, 0);
763 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op, MsgBuffer);
765 break;
768 default:
770 Gbl_ReservedMethods++;
773 * Matched a reserved method name
775 * Validate the ASL-defined argument count. Allow two different legal
776 * arg counts.
778 RequiredArgsCurrent = ReservedMethods[Index].NumArguments & 0x0F;
779 RequiredArgsOld = ReservedMethods[Index].NumArguments >> 4;
781 if ((MethodInfo->NumArguments != RequiredArgsCurrent) &&
782 (MethodInfo->NumArguments != RequiredArgsOld))
784 sprintf (MsgBuffer, "%s requires %d",
785 ReservedMethods[Index].Name,
786 RequiredArgsCurrent);
788 if (MethodInfo->NumArguments > RequiredArgsCurrent)
790 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
791 MsgBuffer);
793 else
795 AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_LO, Op,
796 MsgBuffer);
800 if (MethodInfo->NumReturnNoValue &&
801 ReservedMethods[Index].Flags & ASL_RSVD_RETURN_VALUE)
803 sprintf (MsgBuffer, "%s", ReservedMethods[Index].Name);
805 AslError (ASL_WARNING, ASL_MSG_RESERVED_RETURN_VALUE, Op, MsgBuffer);
807 break;
812 /*******************************************************************************
814 * FUNCTION: AnMapObjTypeToBtype
816 * PARAMETERS: Op - A parse node
818 * RETURN: A Btype
820 * DESCRIPTION: Map object to the associated "Btype"
822 ******************************************************************************/
824 static UINT32
825 AnMapObjTypeToBtype (
826 ACPI_PARSE_OBJECT *Op)
829 switch (Op->Asl.ParseOpcode)
831 case PARSEOP_OBJECTTYPE_BFF: /* "BuffFieldObj" */
832 return (ACPI_BTYPE_BUFFER_FIELD);
834 case PARSEOP_OBJECTTYPE_BUF: /* "BuffObj" */
835 return (ACPI_BTYPE_BUFFER);
837 case PARSEOP_OBJECTTYPE_DDB: /* "DDBHandleObj" */
838 return (ACPI_BTYPE_DDB_HANDLE);
840 case PARSEOP_OBJECTTYPE_DEV: /* "DeviceObj" */
841 return (ACPI_BTYPE_DEVICE);
843 case PARSEOP_OBJECTTYPE_EVT: /* "EventObj" */
844 return (ACPI_BTYPE_EVENT);
846 case PARSEOP_OBJECTTYPE_FLD: /* "FieldUnitObj" */
847 return (ACPI_BTYPE_FIELD_UNIT);
849 case PARSEOP_OBJECTTYPE_INT: /* "IntObj" */
850 return (ACPI_BTYPE_INTEGER);
852 case PARSEOP_OBJECTTYPE_MTH: /* "MethodObj" */
853 return (ACPI_BTYPE_METHOD);
855 case PARSEOP_OBJECTTYPE_MTX: /* "MutexObj" */
856 return (ACPI_BTYPE_MUTEX);
858 case PARSEOP_OBJECTTYPE_OPR: /* "OpRegionObj" */
859 return (ACPI_BTYPE_REGION);
861 case PARSEOP_OBJECTTYPE_PKG: /* "PkgObj" */
862 return (ACPI_BTYPE_PACKAGE);
864 case PARSEOP_OBJECTTYPE_POW: /* "PowerResObj" */
865 return (ACPI_BTYPE_POWER);
867 case PARSEOP_OBJECTTYPE_STR: /* "StrObj" */
868 return (ACPI_BTYPE_STRING);
870 case PARSEOP_OBJECTTYPE_THZ: /* "ThermalZoneObj" */
871 return (ACPI_BTYPE_THERMAL);
873 case PARSEOP_OBJECTTYPE_UNK: /* "UnknownObj" */
874 return (ACPI_BTYPE_OBJECTS_AND_REFS);
876 default:
877 return (0);
882 /*******************************************************************************
884 * FUNCTION: AnMethodAnalysisWalkBegin
886 * PARAMETERS: ASL_WALK_CALLBACK
888 * RETURN: Status
890 * DESCRIPTION: Descending callback for the analysis walk. Check methods for:
891 * 1) Initialized local variables
892 * 2) Valid arguments
893 * 3) Return types
895 ******************************************************************************/
897 ACPI_STATUS
898 AnMethodAnalysisWalkBegin (
899 ACPI_PARSE_OBJECT *Op,
900 UINT32 Level,
901 void *Context)
903 ASL_ANALYSIS_WALK_INFO *WalkInfo = (ASL_ANALYSIS_WALK_INFO *) Context;
904 ASL_METHOD_INFO *MethodInfo = WalkInfo->MethodStack;
905 ACPI_PARSE_OBJECT *Next;
906 UINT32 RegisterNumber;
907 UINT32 i;
908 char LocalName[] = "Local0";
909 char ArgName[] = "Arg0";
910 ACPI_PARSE_OBJECT *ArgNode;
911 ACPI_PARSE_OBJECT *NextType;
912 ACPI_PARSE_OBJECT *NextParamType;
913 UINT8 ActualArgs = 0;
916 switch (Op->Asl.ParseOpcode)
918 case PARSEOP_METHOD:
920 TotalMethods++;
922 /* Create and init method info */
924 MethodInfo = UtLocalCalloc (sizeof (ASL_METHOD_INFO));
925 MethodInfo->Next = WalkInfo->MethodStack;
926 MethodInfo->Op = Op;
928 WalkInfo->MethodStack = MethodInfo;
930 /* Get the name node, ignored here */
932 Next = Op->Asl.Child;
934 /* Get the NumArguments node */
936 Next = Next->Asl.Next;
937 MethodInfo->NumArguments = (UINT8)
938 (((UINT8) Next->Asl.Value.Integer) & 0x07);
940 /* Get the SerializeRule and SyncLevel nodes, ignored here */
942 Next = Next->Asl.Next;
943 Next = Next->Asl.Next;
944 ArgNode = Next;
946 /* Get the ReturnType node */
948 Next = Next->Asl.Next;
950 NextType = Next->Asl.Child;
951 while (NextType)
953 /* Get and map each of the ReturnTypes */
955 MethodInfo->ValidReturnTypes |= AnMapObjTypeToBtype (NextType);
956 NextType->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
957 NextType = NextType->Asl.Next;
960 /* Get the ParameterType node */
962 Next = Next->Asl.Next;
964 NextType = Next->Asl.Child;
965 while (NextType)
967 if (NextType->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
969 NextParamType = NextType->Asl.Child;
970 while (NextParamType)
972 MethodInfo->ValidArgTypes[ActualArgs] |= AnMapObjTypeToBtype (NextParamType);
973 NextParamType->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
974 NextParamType = NextParamType->Asl.Next;
977 else
979 MethodInfo->ValidArgTypes[ActualArgs] =
980 AnMapObjTypeToBtype (NextType);
981 NextType->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
982 ActualArgs++;
985 NextType = NextType->Asl.Next;
988 if ((MethodInfo->NumArguments) &&
989 (MethodInfo->NumArguments != ActualArgs))
991 /* error: Param list did not match number of args */
994 /* Allow numarguments == 0 for Function() */
996 if ((!MethodInfo->NumArguments) && (ActualArgs))
998 MethodInfo->NumArguments = ActualArgs;
999 ArgNode->Asl.Value.Integer |= ActualArgs;
1003 * Actual arguments are initialized at method entry.
1004 * All other ArgX "registers" can be used as locals, so we
1005 * track their initialization.
1007 for (i = 0; i < MethodInfo->NumArguments; i++)
1009 MethodInfo->ArgInitialized[i] = TRUE;
1011 break;
1014 case PARSEOP_METHODCALL:
1016 if (MethodInfo &&
1017 (Op->Asl.Node == MethodInfo->Op->Asl.Node))
1019 AslError (ASL_REMARK, ASL_MSG_RECURSION, Op, Op->Asl.ExternalName);
1021 break;
1024 case PARSEOP_LOCAL0:
1025 case PARSEOP_LOCAL1:
1026 case PARSEOP_LOCAL2:
1027 case PARSEOP_LOCAL3:
1028 case PARSEOP_LOCAL4:
1029 case PARSEOP_LOCAL5:
1030 case PARSEOP_LOCAL6:
1031 case PARSEOP_LOCAL7:
1033 if (!MethodInfo)
1036 * Local was used outside a control method, or there was an error
1037 * in the method declaration.
1039 AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD, Op, Op->Asl.ExternalName);
1040 return (AE_ERROR);
1043 RegisterNumber = (Op->Asl.AmlOpcode & 0x000F);
1046 * If the local is being used as a target, mark the local
1047 * initialized
1049 if (Op->Asl.CompileFlags & NODE_IS_TARGET)
1051 MethodInfo->LocalInitialized[RegisterNumber] = TRUE;
1055 * Otherwise, this is a reference, check if the local
1056 * has been previously initialized.
1058 * The only operator that accepts an uninitialized value is ObjectType()
1060 else if ((!MethodInfo->LocalInitialized[RegisterNumber]) &&
1061 (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE))
1063 LocalName[strlen (LocalName) -1] = (char) (RegisterNumber + 0x30);
1064 AslError (ASL_ERROR, ASL_MSG_LOCAL_INIT, Op, LocalName);
1066 break;
1069 case PARSEOP_ARG0:
1070 case PARSEOP_ARG1:
1071 case PARSEOP_ARG2:
1072 case PARSEOP_ARG3:
1073 case PARSEOP_ARG4:
1074 case PARSEOP_ARG5:
1075 case PARSEOP_ARG6:
1077 if (!MethodInfo)
1080 * Arg was used outside a control method, or there was an error
1081 * in the method declaration.
1083 AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD, Op, Op->Asl.ExternalName);
1084 return (AE_ERROR);
1087 RegisterNumber = (Op->Asl.AmlOpcode & 0x000F) - 8;
1088 ArgName[strlen (ArgName) -1] = (char) (RegisterNumber + 0x30);
1091 * If the Arg is being used as a target, mark the local
1092 * initialized
1094 if (Op->Asl.CompileFlags & NODE_IS_TARGET)
1096 MethodInfo->ArgInitialized[RegisterNumber] = TRUE;
1100 * Otherwise, this is a reference, check if the Arg
1101 * has been previously initialized.
1103 * The only operator that accepts an uninitialized value is ObjectType()
1105 else if ((!MethodInfo->ArgInitialized[RegisterNumber]) &&
1106 (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE))
1108 AslError (ASL_ERROR, ASL_MSG_ARG_INIT, Op, ArgName);
1111 /* Flag this arg if it is not a "real" argument to the method */
1113 if (RegisterNumber >= MethodInfo->NumArguments)
1115 AslError (ASL_REMARK, ASL_MSG_NOT_PARAMETER, Op, ArgName);
1117 break;
1120 case PARSEOP_RETURN:
1122 if (!MethodInfo)
1125 * Probably was an error in the method declaration,
1126 * no additional error here
1128 ACPI_WARNING ((AE_INFO, "%p, No parent method", Op));
1129 return (AE_ERROR);
1132 /* Child indicates a return value */
1134 if ((Op->Asl.Child) &&
1135 (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG))
1137 MethodInfo->NumReturnWithValue++;
1139 else
1141 MethodInfo->NumReturnNoValue++;
1143 break;
1146 case PARSEOP_BREAK:
1147 case PARSEOP_CONTINUE:
1149 Next = Op->Asl.Parent;
1150 while (Next)
1152 if (Next->Asl.ParseOpcode == PARSEOP_WHILE)
1154 break;
1156 Next = Next->Asl.Parent;
1159 if (!Next)
1161 AslError (ASL_ERROR, ASL_MSG_NO_WHILE, Op, NULL);
1163 break;
1166 case PARSEOP_STALL:
1168 /* We can range check if the argument is an integer */
1170 if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_INTEGER) &&
1171 (Op->Asl.Child->Asl.Value.Integer > ACPI_UINT8_MAX))
1173 AslError (ASL_ERROR, ASL_MSG_INVALID_TIME, Op, NULL);
1175 break;
1178 case PARSEOP_DEVICE:
1179 case PARSEOP_EVENT:
1180 case PARSEOP_MUTEX:
1181 case PARSEOP_OPERATIONREGION:
1182 case PARSEOP_POWERRESOURCE:
1183 case PARSEOP_PROCESSOR:
1184 case PARSEOP_THERMALZONE:
1187 * The first operand is a name to be created in the namespace.
1188 * Check against the reserved list.
1190 i = AnCheckForReservedName (Op, Op->Asl.NameSeg);
1191 if (i < ACPI_VALID_RESERVED_NAME_MAX)
1193 AslError (ASL_ERROR, ASL_MSG_RESERVED_USE, Op, Op->Asl.ExternalName);
1195 break;
1198 case PARSEOP_NAME:
1200 i = AnCheckForReservedName (Op, Op->Asl.NameSeg);
1201 if (i < ACPI_VALID_RESERVED_NAME_MAX)
1203 if (ReservedMethods[i].NumArguments > 0)
1206 * This reserved name must be a control method because
1207 * it must have arguments
1209 AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
1210 "with arguments");
1213 /* Typechecking for _HID */
1215 else if (!ACPI_STRCMP (METHOD_NAME__HID, ReservedMethods[i].Name))
1217 /* Examine the second operand to typecheck it */
1219 Next = Op->Asl.Child->Asl.Next;
1221 if ((Next->Asl.ParseOpcode != PARSEOP_INTEGER) &&
1222 (Next->Asl.ParseOpcode != PARSEOP_STRING_LITERAL))
1224 /* _HID must be a string or an integer */
1226 AslError (ASL_ERROR, ASL_MSG_RESERVED_OPERAND_TYPE, Next,
1227 "String or Integer");
1230 if (Next->Asl.ParseOpcode == PARSEOP_STRING_LITERAL)
1233 * _HID is a string, all characters must be alphanumeric.
1234 * One of the things we want to catch here is the use of
1235 * a leading asterisk in the string.
1237 for (i = 0; Next->Asl.Value.String[i]; i++)
1239 if (!isalnum (Next->Asl.Value.String[i]))
1241 AslError (ASL_ERROR, ASL_MSG_ALPHANUMERIC_STRING,
1242 Next, Next->Asl.Value.String);
1243 break;
1249 break;
1252 default:
1253 break;
1256 return AE_OK;
1260 /*******************************************************************************
1262 * FUNCTION: AnLastStatementIsReturn
1264 * PARAMETERS: Op - A method parse node
1266 * RETURN: TRUE if last statement is an ASL RETURN. False otherwise
1268 * DESCRIPTION: Walk down the list of top level statements within a method
1269 * to find the last one. Check if that last statement is in
1270 * fact a RETURN statement.
1272 ******************************************************************************/
1274 static BOOLEAN
1275 AnLastStatementIsReturn (
1276 ACPI_PARSE_OBJECT *Op)
1278 ACPI_PARSE_OBJECT *Next;
1282 * Check if last statement is a return
1284 Next = ASL_GET_CHILD_NODE (Op);
1285 while (Next)
1287 if ((!Next->Asl.Next) &&
1288 (Next->Asl.ParseOpcode == PARSEOP_RETURN))
1290 return TRUE;
1293 Next = ASL_GET_PEER_NODE (Next);
1296 return FALSE;
1300 /*******************************************************************************
1302 * FUNCTION: AnMethodAnalysisWalkEnd
1304 * PARAMETERS: ASL_WALK_CALLBACK
1306 * RETURN: Status
1308 * DESCRIPTION: Ascending callback for analysis walk. Complete method
1309 * return analysis.
1311 ******************************************************************************/
1313 ACPI_STATUS
1314 AnMethodAnalysisWalkEnd (
1315 ACPI_PARSE_OBJECT *Op,
1316 UINT32 Level,
1317 void *Context)
1319 ASL_ANALYSIS_WALK_INFO *WalkInfo = (ASL_ANALYSIS_WALK_INFO *) Context;
1320 ASL_METHOD_INFO *MethodInfo = WalkInfo->MethodStack;
1323 switch (Op->Asl.ParseOpcode)
1325 case PARSEOP_METHOD:
1326 case PARSEOP_RETURN:
1327 if (!MethodInfo)
1329 printf ("No method info for method! [%s]\n", Op->Asl.Namepath);
1330 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
1331 "No method info for this method");
1332 CmCleanupAndExit ();
1333 return (AE_AML_INTERNAL);
1335 break;
1337 default:
1338 break;
1341 switch (Op->Asl.ParseOpcode)
1343 case PARSEOP_METHOD:
1345 WalkInfo->MethodStack = MethodInfo->Next;
1348 * Check if there is no return statement at the end of the
1349 * method AND we can actually get there -- i.e., the execution
1350 * of the method can possibly terminate without a return statement.
1352 if ((!AnLastStatementIsReturn (Op)) &&
1353 (!(Op->Asl.CompileFlags & NODE_HAS_NO_EXIT)))
1356 * No return statement, and execution can possibly exit
1357 * via this path. This is equivalent to Return ()
1359 MethodInfo->NumReturnNoValue++;
1363 * Check for case where some return statements have a return value
1364 * and some do not. Exit without a return statement is a return with
1365 * no value
1367 if (MethodInfo->NumReturnNoValue &&
1368 MethodInfo->NumReturnWithValue)
1370 AslError (ASL_WARNING, ASL_MSG_RETURN_TYPES, Op,
1371 Op->Asl.ExternalName);
1375 * If there are any RETURN() statements with no value, or there is a
1376 * control path that allows the method to exit without a return value,
1377 * we mark the method as a method that does not return a value. This
1378 * knowledge can be used to check method invocations that expect a
1379 * returned value.
1381 if (MethodInfo->NumReturnNoValue)
1383 if (MethodInfo->NumReturnWithValue)
1385 Op->Asl.CompileFlags |= NODE_METHOD_SOME_NO_RETVAL;
1387 else
1389 Op->Asl.CompileFlags |= NODE_METHOD_NO_RETVAL;
1394 * Check predefined method names for correct return behavior
1395 * and correct number of arguments
1397 AnCheckForReservedMethod (Op, MethodInfo);
1398 ACPI_FREE (MethodInfo);
1399 break;
1402 case PARSEOP_RETURN:
1405 * The parent block does not "exit" and continue execution -- the
1406 * method is terminated here with the Return() statement.
1408 Op->Asl.Parent->Asl.CompileFlags |= NODE_HAS_NO_EXIT;
1410 /* Used in the "typing" pass later */
1412 Op->Asl.ParentMethod = MethodInfo->Op;
1415 * If there is a peer node after the return statement, then this
1416 * node is unreachable code -- i.e., it won't be executed because of
1417 * the preceeding Return() statement.
1419 if (Op->Asl.Next)
1421 AslError (ASL_WARNING, ASL_MSG_UNREACHABLE_CODE, Op->Asl.Next, NULL);
1423 break;
1426 case PARSEOP_IF:
1428 if ((Op->Asl.CompileFlags & NODE_HAS_NO_EXIT) &&
1429 (Op->Asl.Next) &&
1430 (Op->Asl.Next->Asl.ParseOpcode == PARSEOP_ELSE))
1433 * This IF has a corresponding ELSE. The IF block has no exit,
1434 * (it contains an unconditional Return)
1435 * mark the ELSE block to remember this fact.
1437 Op->Asl.Next->Asl.CompileFlags |= NODE_IF_HAS_NO_EXIT;
1439 break;
1442 case PARSEOP_ELSE:
1444 if ((Op->Asl.CompileFlags & NODE_HAS_NO_EXIT) &&
1445 (Op->Asl.CompileFlags & NODE_IF_HAS_NO_EXIT))
1448 * This ELSE block has no exit and the corresponding IF block
1449 * has no exit either. Therefore, the parent node has no exit.
1451 Op->Asl.Parent->Asl.CompileFlags |= NODE_HAS_NO_EXIT;
1453 break;
1456 default:
1458 if ((Op->Asl.CompileFlags & NODE_HAS_NO_EXIT) &&
1459 (Op->Asl.Parent))
1461 /* If this node has no exit, then the parent has no exit either */
1463 Op->Asl.Parent->Asl.CompileFlags |= NODE_HAS_NO_EXIT;
1465 break;
1468 return AE_OK;
1472 /*******************************************************************************
1474 * FUNCTION: AnMethodTypingWalkBegin
1476 * PARAMETERS: ASL_WALK_CALLBACK
1478 * RETURN: Status
1480 * DESCRIPTION: Descending callback for the typing walk.
1482 ******************************************************************************/
1484 ACPI_STATUS
1485 AnMethodTypingWalkBegin (
1486 ACPI_PARSE_OBJECT *Op,
1487 UINT32 Level,
1488 void *Context)
1491 return AE_OK;
1495 /*******************************************************************************
1497 * FUNCTION: AnMethodTypingWalkEnd
1499 * PARAMETERS: ASL_WALK_CALLBACK
1501 * RETURN: Status
1503 * DESCRIPTION: Ascending callback for typing walk. Complete the method
1504 * return analysis. Check methods for:
1505 * 1) Initialized local variables
1506 * 2) Valid arguments
1507 * 3) Return types
1509 ******************************************************************************/
1511 ACPI_STATUS
1512 AnMethodTypingWalkEnd (
1513 ACPI_PARSE_OBJECT *Op,
1514 UINT32 Level,
1515 void *Context)
1517 UINT32 ThisNodeBtype;
1520 switch (Op->Asl.ParseOpcode)
1522 case PARSEOP_METHOD:
1524 Op->Asl.CompileFlags |= NODE_METHOD_TYPED;
1525 break;
1527 case PARSEOP_RETURN:
1529 if ((Op->Asl.Child) &&
1530 (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG))
1532 ThisNodeBtype = AnGetBtype (Op->Asl.Child);
1534 if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_METHODCALL) &&
1535 (ThisNodeBtype == (ACPI_UINT32_MAX -1)))
1538 * The called method is untyped at this time (typically a
1539 * forward reference).
1541 * Check for a recursive method call first.
1543 if (Op->Asl.ParentMethod != Op->Asl.Child->Asl.Node->Op)
1545 /* We must type the method here */
1547 TrWalkParseTree (Op->Asl.Child->Asl.Node->Op,
1548 ASL_WALK_VISIT_TWICE, AnMethodTypingWalkBegin,
1549 AnMethodTypingWalkEnd, NULL);
1551 ThisNodeBtype = AnGetBtype (Op->Asl.Child);
1555 /* Returns a value, save the value type */
1557 if (Op->Asl.ParentMethod)
1559 Op->Asl.ParentMethod->Asl.AcpiBtype |= ThisNodeBtype;
1562 break;
1564 default:
1565 break;
1568 return AE_OK;
1572 /*******************************************************************************
1574 * FUNCTION: AnCheckMethodReturnValue
1576 * PARAMETERS: Op - Parent
1577 * OpInfo - Parent info
1578 * ArgOp - Method invocation op
1579 * RequiredBtypes - What caller requires
1580 * ThisNodeBtype - What this node returns (if anything)
1582 * RETURN: None
1584 * DESCRIPTION: Check a method invocation for 1) A return value and if it does
1585 * in fact return a value, 2) check the type of the return value.
1587 ******************************************************************************/
1589 static void
1590 AnCheckMethodReturnValue (
1591 ACPI_PARSE_OBJECT *Op,
1592 const ACPI_OPCODE_INFO *OpInfo,
1593 ACPI_PARSE_OBJECT *ArgOp,
1594 UINT32 RequiredBtypes,
1595 UINT32 ThisNodeBtype)
1597 ACPI_PARSE_OBJECT *OwningOp;
1598 ACPI_NAMESPACE_NODE *Node;
1601 Node = ArgOp->Asl.Node;
1604 /* Examine the parent op of this method */
1606 OwningOp = Node->Op;
1607 if (OwningOp->Asl.CompileFlags & NODE_METHOD_NO_RETVAL)
1609 /* Method NEVER returns a value */
1611 AslError (ASL_ERROR, ASL_MSG_NO_RETVAL, Op, Op->Asl.ExternalName);
1613 else if (OwningOp->Asl.CompileFlags & NODE_METHOD_SOME_NO_RETVAL)
1615 /* Method SOMETIMES returns a value, SOMETIMES not */
1617 AslError (ASL_WARNING, ASL_MSG_SOME_NO_RETVAL, Op, Op->Asl.ExternalName);
1619 else if (!(ThisNodeBtype & RequiredBtypes))
1621 /* Method returns a value, but the type is wrong */
1623 AnFormatBtype (StringBuffer, ThisNodeBtype);
1624 AnFormatBtype (StringBuffer2, RequiredBtypes);
1628 * The case where the method does not return any value at all
1629 * was already handled in the namespace cross reference
1630 * -- Only issue an error if the method in fact returns a value,
1631 * but it is of the wrong type
1633 if (ThisNodeBtype != 0)
1635 sprintf (MsgBuffer,
1636 "Method returns [%s], %s operator requires [%s]",
1637 StringBuffer, OpInfo->Name, StringBuffer2);
1639 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, MsgBuffer);
1645 /*******************************************************************************
1647 * FUNCTION: AnOperandTypecheckWalkBegin
1649 * PARAMETERS: ASL_WALK_CALLBACK
1651 * RETURN: Status
1653 * DESCRIPTION: Descending callback for the analysis walk. Check methods for:
1654 * 1) Initialized local variables
1655 * 2) Valid arguments
1656 * 3) Return types
1658 ******************************************************************************/
1660 ACPI_STATUS
1661 AnOperandTypecheckWalkBegin (
1662 ACPI_PARSE_OBJECT *Op,
1663 UINT32 Level,
1664 void *Context)
1667 return AE_OK;
1671 /*******************************************************************************
1673 * FUNCTION: AnOperandTypecheckWalkEnd
1675 * PARAMETERS: ASL_WALK_CALLBACK
1677 * RETURN: Status
1679 * DESCRIPTION: Ascending callback for analysis walk. Complete method
1680 * return analysis.
1682 ******************************************************************************/
1684 ACPI_STATUS
1685 AnOperandTypecheckWalkEnd (
1686 ACPI_PARSE_OBJECT *Op,
1687 UINT32 Level,
1688 void *Context)
1690 const ACPI_OPCODE_INFO *OpInfo;
1691 UINT32 RuntimeArgTypes;
1692 UINT32 RuntimeArgTypes2;
1693 UINT32 RequiredBtypes;
1694 UINT32 ThisNodeBtype;
1695 UINT32 CommonBtypes;
1696 UINT32 OpcodeClass;
1697 ACPI_PARSE_OBJECT *ArgOp;
1698 UINT32 ArgType;
1701 switch (Op->Asl.AmlOpcode)
1703 case AML_RAW_DATA_BYTE:
1704 case AML_RAW_DATA_WORD:
1705 case AML_RAW_DATA_DWORD:
1706 case AML_RAW_DATA_QWORD:
1707 case AML_RAW_DATA_BUFFER:
1708 case AML_RAW_DATA_CHAIN:
1709 case AML_PACKAGE_LENGTH:
1710 case AML_UNASSIGNED_OPCODE:
1711 case AML_DEFAULT_ARG_OP:
1713 /* Ignore the internal (compiler-only) AML opcodes */
1715 return (AE_OK);
1717 default:
1718 break;
1721 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
1722 if (!OpInfo)
1724 return (AE_OK);
1727 ArgOp = Op->Asl.Child;
1728 RuntimeArgTypes = OpInfo->RuntimeArgs;
1729 OpcodeClass = OpInfo->Class;
1731 #ifdef ASL_ERROR_NAMED_OBJECT_IN_WHILE
1733 * Update 11/2008: In practice, we can't perform this check. A simple
1734 * analysis is not sufficient. Also, it can cause errors when compiling
1735 * disassembled code because of the way Switch operators are implemented
1736 * (a While(One) loop with a named temp variable created within.)
1740 * If we are creating a named object, check if we are within a while loop
1741 * by checking if the parent is a WHILE op. This is a simple analysis, but
1742 * probably sufficient for many cases.
1744 * Allow Scope(), Buffer(), and Package().
1746 if (((OpcodeClass == AML_CLASS_NAMED_OBJECT) && (Op->Asl.AmlOpcode != AML_SCOPE_OP)) ||
1747 ((OpcodeClass == AML_CLASS_CREATE) && (OpInfo->Flags & AML_NSNODE)))
1749 if (Op->Asl.Parent->Asl.AmlOpcode == AML_WHILE_OP)
1751 AslError (ASL_ERROR, ASL_MSG_NAMED_OBJECT_IN_WHILE, Op, NULL);
1754 #endif
1757 * Special case for control opcodes IF/RETURN/WHILE since they
1758 * have no runtime arg list (at this time)
1760 switch (Op->Asl.AmlOpcode)
1762 case AML_IF_OP:
1763 case AML_WHILE_OP:
1764 case AML_RETURN_OP:
1766 if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL)
1768 /* Check for an internal method */
1770 if (AnIsInternalMethod (ArgOp))
1772 return (AE_OK);
1775 /* The lone arg is a method call, check it */
1777 RequiredBtypes = AnMapArgTypeToBtype (ARGI_INTEGER);
1778 if (Op->Asl.AmlOpcode == AML_RETURN_OP)
1780 RequiredBtypes = 0xFFFFFFFF;
1783 ThisNodeBtype = AnGetBtype (ArgOp);
1784 if (ThisNodeBtype == ACPI_UINT32_MAX)
1786 return (AE_OK);
1788 AnCheckMethodReturnValue (Op, OpInfo, ArgOp,
1789 RequiredBtypes, ThisNodeBtype);
1791 return (AE_OK);
1793 default:
1794 break;
1797 /* Ignore the non-executable opcodes */
1799 if (RuntimeArgTypes == ARGI_INVALID_OPCODE)
1801 return (AE_OK);
1804 switch (OpcodeClass)
1806 case AML_CLASS_EXECUTE:
1807 case AML_CLASS_CREATE:
1808 case AML_CLASS_CONTROL:
1809 case AML_CLASS_RETURN_VALUE:
1811 /* TBD: Change class or fix typechecking for these */
1813 if ((Op->Asl.AmlOpcode == AML_BUFFER_OP) ||
1814 (Op->Asl.AmlOpcode == AML_PACKAGE_OP) ||
1815 (Op->Asl.AmlOpcode == AML_VAR_PACKAGE_OP))
1817 break;
1820 /* Reverse the runtime argument list */
1822 RuntimeArgTypes2 = 0;
1823 while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes)))
1825 RuntimeArgTypes2 <<= ARG_TYPE_WIDTH;
1826 RuntimeArgTypes2 |= ArgType;
1827 INCREMENT_ARG_LIST (RuntimeArgTypes);
1830 while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes2)))
1832 RequiredBtypes = AnMapArgTypeToBtype (ArgType);
1834 ThisNodeBtype = AnGetBtype (ArgOp);
1835 if (ThisNodeBtype == ACPI_UINT32_MAX)
1837 goto NextArgument;
1840 /* Examine the arg based on the required type of the arg */
1842 switch (ArgType)
1844 case ARGI_TARGETREF:
1846 if (ArgOp->Asl.ParseOpcode == PARSEOP_ZERO)
1848 /* ZERO is the placeholder for "don't store result" */
1850 ThisNodeBtype = RequiredBtypes;
1851 break;
1854 if (ArgOp->Asl.ParseOpcode == PARSEOP_INTEGER)
1857 * This is the case where an original reference to a resource
1858 * descriptor field has been replaced by an (Integer) offset.
1859 * These named fields are supported at compile-time only;
1860 * the names are not passed to the interpreter (via the AML).
1862 if ((ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
1863 (ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
1865 AslError (ASL_ERROR, ASL_MSG_RESOURCE_FIELD, ArgOp, NULL);
1867 else
1869 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, NULL);
1871 break;
1874 if ((ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL) ||
1875 (ArgOp->Asl.ParseOpcode == PARSEOP_DEREFOF))
1877 break;
1880 ThisNodeBtype = RequiredBtypes;
1881 break;
1884 case ARGI_REFERENCE: /* References */
1885 case ARGI_INTEGER_REF:
1886 case ARGI_OBJECT_REF:
1887 case ARGI_DEVICE_REF:
1889 switch (ArgOp->Asl.ParseOpcode)
1891 case PARSEOP_LOCAL0:
1892 case PARSEOP_LOCAL1:
1893 case PARSEOP_LOCAL2:
1894 case PARSEOP_LOCAL3:
1895 case PARSEOP_LOCAL4:
1896 case PARSEOP_LOCAL5:
1897 case PARSEOP_LOCAL6:
1898 case PARSEOP_LOCAL7:
1900 /* TBD: implement analysis of current value (type) of the local */
1901 /* For now, just treat any local as a typematch */
1903 /*ThisNodeBtype = RequiredBtypes;*/
1904 break;
1906 case PARSEOP_ARG0:
1907 case PARSEOP_ARG1:
1908 case PARSEOP_ARG2:
1909 case PARSEOP_ARG3:
1910 case PARSEOP_ARG4:
1911 case PARSEOP_ARG5:
1912 case PARSEOP_ARG6:
1914 /* Hard to analyze argument types, sow we won't */
1915 /* For now, just treat any arg as a typematch */
1917 /* ThisNodeBtype = RequiredBtypes; */
1918 break;
1920 case PARSEOP_DEBUG:
1921 break;
1923 case PARSEOP_REFOF:
1924 case PARSEOP_INDEX:
1925 default:
1926 break;
1929 break;
1931 case ARGI_INTEGER:
1932 default:
1933 break;
1937 CommonBtypes = ThisNodeBtype & RequiredBtypes;
1939 if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL)
1941 if (AnIsInternalMethod (ArgOp))
1943 return (AE_OK);
1946 /* Check a method call for a valid return value */
1948 AnCheckMethodReturnValue (Op, OpInfo, ArgOp,
1949 RequiredBtypes, ThisNodeBtype);
1953 * Now check if the actual type(s) match at least one
1954 * bit to the required type
1956 else if (!CommonBtypes)
1958 /* No match -- this is a type mismatch error */
1960 AnFormatBtype (StringBuffer, ThisNodeBtype);
1961 AnFormatBtype (StringBuffer2, RequiredBtypes);
1963 sprintf (MsgBuffer, "[%s] found, %s operator requires [%s]",
1964 StringBuffer, OpInfo->Name, StringBuffer2);
1966 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, MsgBuffer);
1969 NextArgument:
1970 ArgOp = ArgOp->Asl.Next;
1971 INCREMENT_ARG_LIST (RuntimeArgTypes2);
1973 break;
1975 default:
1976 break;
1979 return (AE_OK);
1983 /*******************************************************************************
1985 * FUNCTION: AnIsResultUsed
1987 * PARAMETERS: Op - Parent op for the operator
1989 * RETURN: TRUE if result from this operation is actually consumed
1991 * DESCRIPTION: Determine if the function result value from an operator is
1992 * used.
1994 ******************************************************************************/
1996 BOOLEAN
1997 AnIsResultUsed (
1998 ACPI_PARSE_OBJECT *Op)
2000 ACPI_PARSE_OBJECT *Parent;
2003 switch (Op->Asl.ParseOpcode)
2005 case PARSEOP_INCREMENT:
2006 case PARSEOP_DECREMENT:
2008 /* These are standalone operators, no return value */
2010 return (TRUE);
2012 default:
2013 break;
2016 /* Examine parent to determine if the return value is used */
2018 Parent = Op->Asl.Parent;
2019 switch (Parent->Asl.ParseOpcode)
2021 /* If/While - check if the operator is the predicate */
2023 case PARSEOP_IF:
2024 case PARSEOP_WHILE:
2026 /* First child is the predicate */
2028 if (Parent->Asl.Child == Op)
2030 return (TRUE);
2032 return (FALSE);
2034 /* Not used if one of these is the parent */
2036 case PARSEOP_METHOD:
2037 case PARSEOP_DEFINITIONBLOCK:
2038 case PARSEOP_ELSE:
2040 return (FALSE);
2042 default:
2043 /* Any other type of parent means that the result is used */
2045 return (TRUE);
2050 /*******************************************************************************
2052 * FUNCTION: AnOtherSemanticAnalysisWalkBegin
2054 * PARAMETERS: ASL_WALK_CALLBACK
2056 * RETURN: Status
2058 * DESCRIPTION: Descending callback for the analysis walk. Checks for
2059 * miscellaneous issues in the code.
2061 ******************************************************************************/
2063 ACPI_STATUS
2064 AnOtherSemanticAnalysisWalkBegin (
2065 ACPI_PARSE_OBJECT *Op,
2066 UINT32 Level,
2067 void *Context)
2069 ACPI_PARSE_OBJECT *ArgNode;
2070 ACPI_PARSE_OBJECT *PrevArgNode = NULL;
2071 const ACPI_OPCODE_INFO *OpInfo;
2074 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
2077 * Determine if an execution class operator actually does something by
2078 * checking if it has a target and/or the function return value is used.
2079 * (Target is optional, so a standalone statement can actually do nothing.)
2081 if ((OpInfo->Class == AML_CLASS_EXECUTE) &&
2082 (OpInfo->Flags & AML_HAS_RETVAL) &&
2083 (!AnIsResultUsed (Op)))
2085 if (OpInfo->Flags & AML_HAS_TARGET)
2088 * Find the target node, it is always the last child. If the traget
2089 * is not specified in the ASL, a default node of type Zero was
2090 * created by the parser.
2092 ArgNode = Op->Asl.Child;
2093 while (ArgNode->Asl.Next)
2095 PrevArgNode = ArgNode;
2096 ArgNode = ArgNode->Asl.Next;
2099 /* Divide() is the only weird case, it has two targets */
2101 if (Op->Asl.AmlOpcode == AML_DIVIDE_OP)
2103 if ((ArgNode->Asl.ParseOpcode == PARSEOP_ZERO) &&
2104 (PrevArgNode->Asl.ParseOpcode == PARSEOP_ZERO))
2106 AslError (ASL_WARNING, ASL_MSG_RESULT_NOT_USED, Op, Op->Asl.ExternalName);
2109 else if (ArgNode->Asl.ParseOpcode == PARSEOP_ZERO)
2111 AslError (ASL_WARNING, ASL_MSG_RESULT_NOT_USED, Op, Op->Asl.ExternalName);
2114 else
2117 * Has no target and the result is not used. Only a couple opcodes
2118 * can have this combination.
2120 switch (Op->Asl.ParseOpcode)
2122 case PARSEOP_ACQUIRE:
2123 case PARSEOP_WAIT:
2124 case PARSEOP_LOADTABLE:
2125 break;
2127 default:
2128 AslError (ASL_WARNING, ASL_MSG_RESULT_NOT_USED, Op, Op->Asl.ExternalName);
2129 break;
2136 * Semantic checks for individual ASL operators
2138 switch (Op->Asl.ParseOpcode)
2140 case PARSEOP_ACQUIRE:
2141 case PARSEOP_WAIT:
2143 * Emit a warning if the timeout parameter for these operators is not
2144 * ACPI_WAIT_FOREVER, and the result value from the operator is not
2145 * checked, meaning that a timeout could happen, but the code
2146 * would not know about it.
2149 /* First child is the namepath, 2nd child is timeout */
2151 ArgNode = Op->Asl.Child;
2152 ArgNode = ArgNode->Asl.Next;
2155 * Check for the WAIT_FOREVER case - defined by the ACPI spec to be
2156 * 0xFFFF or greater
2158 if (((ArgNode->Asl.ParseOpcode == PARSEOP_WORDCONST) ||
2159 (ArgNode->Asl.ParseOpcode == PARSEOP_INTEGER)) &&
2160 (ArgNode->Asl.Value.Integer >= (ACPI_INTEGER) ACPI_WAIT_FOREVER))
2162 break;
2166 * The operation could timeout. If the return value is not used
2167 * (indicates timeout occurred), issue a warning
2169 if (!AnIsResultUsed (Op))
2171 AslError (ASL_WARNING, ASL_MSG_TIMEOUT, ArgNode, Op->Asl.ExternalName);
2173 break;
2175 case PARSEOP_CREATEFIELD:
2177 * Check for a zero Length (NumBits) operand. NumBits is the 3rd operand
2179 ArgNode = Op->Asl.Child;
2180 ArgNode = ArgNode->Asl.Next;
2181 ArgNode = ArgNode->Asl.Next;
2183 if ((ArgNode->Asl.ParseOpcode == PARSEOP_ZERO) ||
2184 ((ArgNode->Asl.ParseOpcode == PARSEOP_INTEGER) &&
2185 (ArgNode->Asl.Value.Integer == 0)))
2187 AslError (ASL_ERROR, ASL_MSG_NON_ZERO, ArgNode, NULL);
2189 break;
2191 default:
2192 break;
2195 return AE_OK;
2199 /*******************************************************************************
2201 * FUNCTION: AnOtherSemanticAnalysisWalkEnd
2203 * PARAMETERS: ASL_WALK_CALLBACK
2205 * RETURN: Status
2207 * DESCRIPTION: Ascending callback for analysis walk. Complete method
2208 * return analysis.
2210 ******************************************************************************/
2212 ACPI_STATUS
2213 AnOtherSemanticAnalysisWalkEnd (
2214 ACPI_PARSE_OBJECT *Op,
2215 UINT32 Level,
2216 void *Context)
2219 return AE_OK;
2224 #ifdef ACPI_OBSOLETE_FUNCTIONS
2225 /*******************************************************************************
2227 * FUNCTION: AnMapBtypeToEtype
2229 * PARAMETERS: Btype - Bitfield of ACPI types
2231 * RETURN: The Etype corresponding the the Btype
2233 * DESCRIPTION: Convert a bitfield type to an encoded type
2235 ******************************************************************************/
2237 UINT32
2238 AnMapBtypeToEtype (
2239 UINT32 Btype)
2241 UINT32 i;
2242 UINT32 Etype;
2245 if (Btype == 0)
2247 return 0;
2250 Etype = 1;
2251 for (i = 1; i < Btype; i *= 2)
2253 Etype++;
2256 return (Etype);
2258 #endif