1 /******************************************************************************
3 * Module Name: aslwalks.c - Miscellaneous analytical parse tree walks
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2015, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
116 #include "aslcompiler.h"
117 #include "aslcompiler.y.h"
118 #include "acparser.h"
122 #define _COMPONENT ACPI_COMPILER
123 ACPI_MODULE_NAME ("aslwalks")
126 /*******************************************************************************
128 * FUNCTION: AnMethodTypingWalkEnd
130 * PARAMETERS: ASL_WALK_CALLBACK
134 * DESCRIPTION: Ascending callback for typing walk. Complete the method
135 * return analysis. Check methods for:
136 * 1) Initialized local variables
140 ******************************************************************************/
143 AnMethodTypingWalkEnd (
144 ACPI_PARSE_OBJECT *Op,
148 UINT32 ThisNodeBtype;
151 switch (Op->Asl.ParseOpcode)
155 Op->Asl.CompileFlags |= NODE_METHOD_TYPED;
160 if ((Op->Asl.Child) &&
161 (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG))
163 ThisNodeBtype = AnGetBtype (Op->Asl.Child);
165 if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_METHODCALL) &&
166 (ThisNodeBtype == (ACPI_UINT32_MAX -1)))
169 * The called method is untyped at this time (typically a
170 * forward reference).
172 * Check for a recursive method call first.
174 if (Op->Asl.ParentMethod != Op->Asl.Child->Asl.Node->Op)
176 /* We must type the method here */
178 TrWalkParseTree (Op->Asl.Child->Asl.Node->Op,
179 ASL_WALK_VISIT_UPWARD, NULL,
180 AnMethodTypingWalkEnd, NULL);
182 ThisNodeBtype = AnGetBtype (Op->Asl.Child);
186 /* Returns a value, save the value type */
188 if (Op->Asl.ParentMethod)
190 Op->Asl.ParentMethod->Asl.AcpiBtype |= ThisNodeBtype;
204 /*******************************************************************************
206 * FUNCTION: AnOperandTypecheckWalkEnd
208 * PARAMETERS: ASL_WALK_CALLBACK
212 * DESCRIPTION: Ascending callback for analysis walk. Complete method
215 ******************************************************************************/
218 AnOperandTypecheckWalkEnd (
219 ACPI_PARSE_OBJECT *Op,
223 const ACPI_OPCODE_INFO *OpInfo;
224 UINT32 RuntimeArgTypes;
225 UINT32 RuntimeArgTypes2;
226 UINT32 RequiredBtypes;
227 UINT32 ThisNodeBtype;
230 ACPI_PARSE_OBJECT *ArgOp;
234 switch (Op->Asl.AmlOpcode)
236 case AML_RAW_DATA_BYTE:
237 case AML_RAW_DATA_WORD:
238 case AML_RAW_DATA_DWORD:
239 case AML_RAW_DATA_QWORD:
240 case AML_RAW_DATA_BUFFER:
241 case AML_RAW_DATA_CHAIN:
242 case AML_PACKAGE_LENGTH:
243 case AML_UNASSIGNED_OPCODE:
244 case AML_DEFAULT_ARG_OP:
246 /* Ignore the internal (compiler-only) AML opcodes */
255 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
261 ArgOp = Op->Asl.Child;
262 RuntimeArgTypes = OpInfo->RuntimeArgs;
263 OpcodeClass = OpInfo->Class;
265 #ifdef ASL_ERROR_NAMED_OBJECT_IN_WHILE
267 * Update 11/2008: In practice, we can't perform this check. A simple
268 * analysis is not sufficient. Also, it can cause errors when compiling
269 * disassembled code because of the way Switch operators are implemented
270 * (a While(One) loop with a named temp variable created within.)
274 * If we are creating a named object, check if we are within a while loop
275 * by checking if the parent is a WHILE op. This is a simple analysis, but
276 * probably sufficient for many cases.
278 * Allow Scope(), Buffer(), and Package().
280 if (((OpcodeClass == AML_CLASS_NAMED_OBJECT) && (Op->Asl.AmlOpcode != AML_SCOPE_OP)) ||
281 ((OpcodeClass == AML_CLASS_CREATE) && (OpInfo->Flags & AML_NSNODE)))
283 if (Op->Asl.Parent->Asl.AmlOpcode == AML_WHILE_OP)
285 AslError (ASL_ERROR, ASL_MSG_NAMED_OBJECT_IN_WHILE, Op, NULL);
291 * Special case for control opcodes IF/RETURN/WHILE since they
292 * have no runtime arg list (at this time)
294 switch (Op->Asl.AmlOpcode)
300 if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL)
302 /* Check for an internal method */
304 if (AnIsInternalMethod (ArgOp))
309 /* The lone arg is a method call, check it */
311 RequiredBtypes = AnMapArgTypeToBtype (ARGI_INTEGER);
312 if (Op->Asl.AmlOpcode == AML_RETURN_OP)
314 RequiredBtypes = 0xFFFFFFFF;
317 ThisNodeBtype = AnGetBtype (ArgOp);
318 if (ThisNodeBtype == ACPI_UINT32_MAX)
322 AnCheckMethodReturnValue (Op, OpInfo, ArgOp,
323 RequiredBtypes, ThisNodeBtype);
327 case AML_EXTERNAL_OP:
329 * Not really a "runtime" opcode since it used by disassembler only.
330 * The parser will find any issues with the operands.
339 /* Ignore the non-executable opcodes */
341 if (RuntimeArgTypes == ARGI_INVALID_OPCODE)
348 case AML_CLASS_EXECUTE:
349 case AML_CLASS_CREATE:
350 case AML_CLASS_CONTROL:
351 case AML_CLASS_RETURN_VALUE:
353 /* TBD: Change class or fix typechecking for these */
355 if ((Op->Asl.AmlOpcode == AML_BUFFER_OP) ||
356 (Op->Asl.AmlOpcode == AML_PACKAGE_OP) ||
357 (Op->Asl.AmlOpcode == AML_VAR_PACKAGE_OP))
362 /* Reverse the runtime argument list */
364 RuntimeArgTypes2 = 0;
365 while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes)))
367 RuntimeArgTypes2 <<= ARG_TYPE_WIDTH;
368 RuntimeArgTypes2 |= ArgType;
369 INCREMENT_ARG_LIST (RuntimeArgTypes);
372 while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes2)))
374 RequiredBtypes = AnMapArgTypeToBtype (ArgType);
378 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
379 "Null ArgOp in argument loop");
383 ThisNodeBtype = AnGetBtype (ArgOp);
384 if (ThisNodeBtype == ACPI_UINT32_MAX)
389 /* Examine the arg based on the required type of the arg */
395 if (ArgOp->Asl.ParseOpcode == PARSEOP_ZERO)
397 /* ZERO is the placeholder for "don't store result" */
399 ThisNodeBtype = RequiredBtypes;
403 if (ArgOp->Asl.ParseOpcode == PARSEOP_INTEGER)
406 * This is the case where an original reference to a resource
407 * descriptor field has been replaced by an (Integer) offset.
408 * These named fields are supported at compile-time only;
409 * the names are not passed to the interpreter (via the AML).
411 if ((ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
412 (ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
414 AslError (ASL_ERROR, ASL_MSG_RESOURCE_FIELD, ArgOp, NULL);
418 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, NULL);
423 if ((ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL) ||
424 (ArgOp->Asl.ParseOpcode == PARSEOP_DEREFOF))
429 ThisNodeBtype = RequiredBtypes;
433 case ARGI_REFERENCE: /* References */
434 case ARGI_INTEGER_REF:
435 case ARGI_OBJECT_REF:
436 case ARGI_DEVICE_REF:
438 switch (ArgOp->Asl.ParseOpcode)
449 /* TBD: implement analysis of current value (type) of the local */
450 /* For now, just treat any local as a typematch */
452 /*ThisNodeBtype = RequiredBtypes;*/
463 /* Hard to analyze argument types, sow we won't */
464 /* For now, just treat any arg as a typematch */
466 /* ThisNodeBtype = RequiredBtypes; */
486 CommonBtypes = ThisNodeBtype & RequiredBtypes;
488 if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL)
490 if (AnIsInternalMethod (ArgOp))
495 /* Check a method call for a valid return value */
497 AnCheckMethodReturnValue (Op, OpInfo, ArgOp,
498 RequiredBtypes, ThisNodeBtype);
502 * Now check if the actual type(s) match at least one
503 * bit to the required type
505 else if (!CommonBtypes)
507 /* No match -- this is a type mismatch error */
509 AnFormatBtype (StringBuffer, ThisNodeBtype);
510 AnFormatBtype (StringBuffer2, RequiredBtypes);
512 sprintf (MsgBuffer, "[%s] found, %s operator requires [%s]",
513 StringBuffer, OpInfo->Name, StringBuffer2);
515 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, MsgBuffer);
519 ArgOp = ArgOp->Asl.Next;
520 INCREMENT_ARG_LIST (RuntimeArgTypes2);
533 /*******************************************************************************
535 * FUNCTION: AnOtherSemanticAnalysisWalkBegin
537 * PARAMETERS: ASL_WALK_CALLBACK
541 * DESCRIPTION: Descending callback for the analysis walk. Checks for
542 * miscellaneous issues in the code.
544 ******************************************************************************/
547 AnOtherSemanticAnalysisWalkBegin (
548 ACPI_PARSE_OBJECT *Op,
552 ACPI_PARSE_OBJECT *ArgNode;
553 ACPI_PARSE_OBJECT *PrevArgNode = NULL;
554 const ACPI_OPCODE_INFO *OpInfo;
555 ACPI_NAMESPACE_NODE *Node;
558 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
561 * Determine if an execution class operator actually does something by
562 * checking if it has a target and/or the function return value is used.
563 * (Target is optional, so a standalone statement can actually do nothing.)
565 if ((OpInfo->Class == AML_CLASS_EXECUTE) &&
566 (OpInfo->Flags & AML_HAS_RETVAL) &&
567 (!AnIsResultUsed (Op)))
569 if (OpInfo->Flags & AML_HAS_TARGET)
572 * Find the target node, it is always the last child. If the traget
573 * is not specified in the ASL, a default node of type Zero was
574 * created by the parser.
576 ArgNode = Op->Asl.Child;
577 while (ArgNode->Asl.Next)
579 PrevArgNode = ArgNode;
580 ArgNode = ArgNode->Asl.Next;
583 /* Divide() is the only weird case, it has two targets */
585 if (Op->Asl.AmlOpcode == AML_DIVIDE_OP)
587 if ((ArgNode->Asl.ParseOpcode == PARSEOP_ZERO) &&
589 (PrevArgNode->Asl.ParseOpcode == PARSEOP_ZERO))
591 AslError (ASL_ERROR, ASL_MSG_RESULT_NOT_USED,
592 Op, Op->Asl.ExternalName);
595 else if (ArgNode->Asl.ParseOpcode == PARSEOP_ZERO)
597 AslError (ASL_ERROR, ASL_MSG_RESULT_NOT_USED,
598 Op, Op->Asl.ExternalName);
604 * Has no target and the result is not used. Only a couple opcodes
605 * can have this combination.
607 switch (Op->Asl.ParseOpcode)
609 case PARSEOP_ACQUIRE:
611 case PARSEOP_LOADTABLE:
617 AslError (ASL_ERROR, ASL_MSG_RESULT_NOT_USED,
618 Op, Op->Asl.ExternalName);
626 * Semantic checks for individual ASL operators
628 switch (Op->Asl.ParseOpcode)
630 case PARSEOP_ACQUIRE:
633 * Emit a warning if the timeout parameter for these operators is not
634 * ACPI_WAIT_FOREVER, and the result value from the operator is not
635 * checked, meaning that a timeout could happen, but the code
636 * would not know about it.
639 /* First child is the namepath, 2nd child is timeout */
641 ArgNode = Op->Asl.Child;
642 ArgNode = ArgNode->Asl.Next;
645 * Check for the WAIT_FOREVER case - defined by the ACPI spec to be
648 if (((ArgNode->Asl.ParseOpcode == PARSEOP_WORDCONST) ||
649 (ArgNode->Asl.ParseOpcode == PARSEOP_INTEGER)) &&
650 (ArgNode->Asl.Value.Integer >= (UINT64) ACPI_WAIT_FOREVER))
656 * The operation could timeout. If the return value is not used
657 * (indicates timeout occurred), issue a warning
659 if (!AnIsResultUsed (Op))
661 AslError (ASL_WARNING, ASL_MSG_TIMEOUT, ArgNode,
662 Op->Asl.ExternalName);
666 case PARSEOP_CREATEFIELD:
668 * Check for a zero Length (NumBits) operand. NumBits is the 3rd operand
670 ArgNode = Op->Asl.Child;
671 ArgNode = ArgNode->Asl.Next;
672 ArgNode = ArgNode->Asl.Next;
674 if ((ArgNode->Asl.ParseOpcode == PARSEOP_ZERO) ||
675 ((ArgNode->Asl.ParseOpcode == PARSEOP_INTEGER) &&
676 (ArgNode->Asl.Value.Integer == 0)))
678 AslError (ASL_ERROR, ASL_MSG_NON_ZERO, ArgNode, NULL);
682 case PARSEOP_CONNECTION:
684 * Ensure that the referenced operation region has the correct SPACE_ID.
685 * From the grammar/parser, we know the parent is a FIELD definition.
687 ArgNode = Op->Asl.Parent; /* Field definition */
688 ArgNode = ArgNode->Asl.Child; /* First child is the OpRegion Name */
689 Node = ArgNode->Asl.Node; /* OpRegion namespace node */
695 ArgNode = Node->Op; /* OpRegion definition */
696 ArgNode = ArgNode->Asl.Child; /* First child is the OpRegion Name */
697 ArgNode = ArgNode->Asl.Next; /* Next peer is the SPACE_ID (what we want) */
700 * The Connection() operator is only valid for the following operation
701 * region SpaceIds: GeneralPurposeIo and GenericSerialBus.
703 if ((ArgNode->Asl.Value.Integer != ACPI_ADR_SPACE_GPIO) &&
704 (ArgNode->Asl.Value.Integer != ACPI_ADR_SPACE_GSBUS))
706 AslError (ASL_ERROR, ASL_MSG_CONNECTION_INVALID, Op, NULL);
712 * Ensure that fields for GeneralPurposeIo and GenericSerialBus
713 * contain at least one Connection() operator
715 ArgNode = Op->Asl.Child; /* 1st child is the OpRegion Name */
716 Node = ArgNode->Asl.Node; /* OpRegion namespace node */
722 ArgNode = Node->Op; /* OpRegion definition */
723 ArgNode = ArgNode->Asl.Child; /* First child is the OpRegion Name */
724 ArgNode = ArgNode->Asl.Next; /* Next peer is the SPACE_ID (what we want) */
726 /* We are only interested in GeneralPurposeIo and GenericSerialBus */
728 if ((ArgNode->Asl.Value.Integer != ACPI_ADR_SPACE_GPIO) &&
729 (ArgNode->Asl.Value.Integer != ACPI_ADR_SPACE_GSBUS))
734 ArgNode = Op->Asl.Child; /* 1st child is the OpRegion Name */
735 ArgNode = ArgNode->Asl.Next; /* AccessType */
736 ArgNode = ArgNode->Asl.Next; /* LockRule */
737 ArgNode = ArgNode->Asl.Next; /* UpdateRule */
738 ArgNode = ArgNode->Asl.Next; /* Start of FieldUnitList */
740 /* Walk the FieldUnitList */
744 if (ArgNode->Asl.ParseOpcode == PARSEOP_CONNECTION)
748 else if (ArgNode->Asl.ParseOpcode == PARSEOP_NAMESEG)
750 AslError (ASL_ERROR, ASL_MSG_CONNECTION_MISSING, ArgNode, NULL);
754 ArgNode = ArgNode->Asl.Next;