1 /******************************************************************************
3 * Module Name: aslwalks.c - Miscellaneous analytical parse tree walks
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include "aslcompiler.h"
45 #include "aslcompiler.y.h"
50 #define _COMPONENT ACPI_COMPILER
51 ACPI_MODULE_NAME ("aslwalks")
54 /*******************************************************************************
56 * FUNCTION: AnMethodTypingWalkEnd
58 * PARAMETERS: ASL_WALK_CALLBACK
62 * DESCRIPTION: Ascending callback for typing walk. Complete the method
63 * return analysis. Check methods for:
64 * 1) Initialized local variables
68 ******************************************************************************/
71 AnMethodTypingWalkEnd (
72 ACPI_PARSE_OBJECT *Op,
79 switch (Op->Asl.ParseOpcode)
83 Op->Asl.CompileFlags |= NODE_METHOD_TYPED;
88 if ((Op->Asl.Child) &&
89 (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG))
91 ThisNodeBtype = AnGetBtype (Op->Asl.Child);
93 if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_METHODCALL) &&
94 (ThisNodeBtype == (ACPI_UINT32_MAX -1)))
97 * The called method is untyped at this time (typically a
100 * Check for a recursive method call first.
102 if (Op->Asl.ParentMethod != Op->Asl.Child->Asl.Node->Op)
104 /* We must type the method here */
106 TrWalkParseTree (Op->Asl.Child->Asl.Node->Op,
107 ASL_WALK_VISIT_UPWARD, NULL,
108 AnMethodTypingWalkEnd, NULL);
110 ThisNodeBtype = AnGetBtype (Op->Asl.Child);
114 /* Returns a value, save the value type */
116 if (Op->Asl.ParentMethod)
118 Op->Asl.ParentMethod->Asl.AcpiBtype |= ThisNodeBtype;
132 /*******************************************************************************
134 * FUNCTION: AnOperandTypecheckWalkEnd
136 * PARAMETERS: ASL_WALK_CALLBACK
140 * DESCRIPTION: Ascending callback for analysis walk. Complete method
143 ******************************************************************************/
146 AnOperandTypecheckWalkEnd (
147 ACPI_PARSE_OBJECT *Op,
151 const ACPI_OPCODE_INFO *OpInfo;
152 UINT32 RuntimeArgTypes;
153 UINT32 RuntimeArgTypes2;
154 UINT32 RequiredBtypes;
155 UINT32 ThisNodeBtype;
158 ACPI_PARSE_OBJECT *ArgOp;
162 switch (Op->Asl.AmlOpcode)
164 case AML_RAW_DATA_BYTE:
165 case AML_RAW_DATA_WORD:
166 case AML_RAW_DATA_DWORD:
167 case AML_RAW_DATA_QWORD:
168 case AML_RAW_DATA_BUFFER:
169 case AML_RAW_DATA_CHAIN:
170 case AML_PACKAGE_LENGTH:
171 case AML_UNASSIGNED_OPCODE:
172 case AML_DEFAULT_ARG_OP:
174 /* Ignore the internal (compiler-only) AML opcodes */
183 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
189 ArgOp = Op->Asl.Child;
190 RuntimeArgTypes = OpInfo->RuntimeArgs;
191 OpcodeClass = OpInfo->Class;
193 #ifdef ASL_ERROR_NAMED_OBJECT_IN_WHILE
195 * Update 11/2008: In practice, we can't perform this check. A simple
196 * analysis is not sufficient. Also, it can cause errors when compiling
197 * disassembled code because of the way Switch operators are implemented
198 * (a While(One) loop with a named temp variable created within.)
202 * If we are creating a named object, check if we are within a while loop
203 * by checking if the parent is a WHILE op. This is a simple analysis, but
204 * probably sufficient for many cases.
206 * Allow Scope(), Buffer(), and Package().
208 if (((OpcodeClass == AML_CLASS_NAMED_OBJECT) && (Op->Asl.AmlOpcode != AML_SCOPE_OP)) ||
209 ((OpcodeClass == AML_CLASS_CREATE) && (OpInfo->Flags & AML_NSNODE)))
211 if (Op->Asl.Parent->Asl.AmlOpcode == AML_WHILE_OP)
213 AslError (ASL_ERROR, ASL_MSG_NAMED_OBJECT_IN_WHILE, Op, NULL);
219 * Special case for control opcodes IF/RETURN/WHILE since they
220 * have no runtime arg list (at this time)
222 switch (Op->Asl.AmlOpcode)
228 if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL)
230 /* Check for an internal method */
232 if (AnIsInternalMethod (ArgOp))
237 /* The lone arg is a method call, check it */
239 RequiredBtypes = AnMapArgTypeToBtype (ARGI_INTEGER);
240 if (Op->Asl.AmlOpcode == AML_RETURN_OP)
242 RequiredBtypes = 0xFFFFFFFF;
245 ThisNodeBtype = AnGetBtype (ArgOp);
246 if (ThisNodeBtype == ACPI_UINT32_MAX)
250 AnCheckMethodReturnValue (Op, OpInfo, ArgOp,
251 RequiredBtypes, ThisNodeBtype);
255 case AML_EXTERNAL_OP:
257 * Not really a "runtime" opcode since it used by disassembler only.
258 * The parser will find any issues with the operands.
267 /* Ignore the non-executable opcodes */
269 if (RuntimeArgTypes == ARGI_INVALID_OPCODE)
276 case AML_CLASS_EXECUTE:
277 case AML_CLASS_CREATE:
278 case AML_CLASS_CONTROL:
279 case AML_CLASS_RETURN_VALUE:
281 /* TBD: Change class or fix typechecking for these */
283 if ((Op->Asl.AmlOpcode == AML_BUFFER_OP) ||
284 (Op->Asl.AmlOpcode == AML_PACKAGE_OP) ||
285 (Op->Asl.AmlOpcode == AML_VAR_PACKAGE_OP))
290 /* Reverse the runtime argument list */
292 RuntimeArgTypes2 = 0;
293 while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes)))
295 RuntimeArgTypes2 <<= ARG_TYPE_WIDTH;
296 RuntimeArgTypes2 |= ArgType;
297 INCREMENT_ARG_LIST (RuntimeArgTypes);
300 while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes2)))
302 RequiredBtypes = AnMapArgTypeToBtype (ArgType);
306 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
307 "Null ArgOp in argument loop");
311 ThisNodeBtype = AnGetBtype (ArgOp);
312 if (ThisNodeBtype == ACPI_UINT32_MAX)
317 /* Examine the arg based on the required type of the arg */
323 if (ArgOp->Asl.ParseOpcode == PARSEOP_ZERO)
325 /* ZERO is the placeholder for "don't store result" */
327 ThisNodeBtype = RequiredBtypes;
331 if (ArgOp->Asl.ParseOpcode == PARSEOP_INTEGER)
334 * This is the case where an original reference to a resource
335 * descriptor field has been replaced by an (Integer) offset.
336 * These named fields are supported at compile-time only;
337 * the names are not passed to the interpreter (via the AML).
339 if ((ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
340 (ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
342 AslError (ASL_ERROR, ASL_MSG_RESOURCE_FIELD, ArgOp, NULL);
346 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, NULL);
351 if ((ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL) ||
352 (ArgOp->Asl.ParseOpcode == PARSEOP_DEREFOF))
357 ThisNodeBtype = RequiredBtypes;
361 case ARGI_REFERENCE: /* References */
362 case ARGI_INTEGER_REF:
363 case ARGI_OBJECT_REF:
364 case ARGI_DEVICE_REF:
366 switch (ArgOp->Asl.ParseOpcode)
377 /* TBD: implement analysis of current value (type) of the local */
378 /* For now, just treat any local as a typematch */
380 /*ThisNodeBtype = RequiredBtypes;*/
391 /* Hard to analyze argument types, sow we won't */
392 /* For now, just treat any arg as a typematch */
394 /* ThisNodeBtype = RequiredBtypes; */
414 CommonBtypes = ThisNodeBtype & RequiredBtypes;
416 if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL)
418 if (AnIsInternalMethod (ArgOp))
423 /* Check a method call for a valid return value */
425 AnCheckMethodReturnValue (Op, OpInfo, ArgOp,
426 RequiredBtypes, ThisNodeBtype);
430 * Now check if the actual type(s) match at least one
431 * bit to the required type
433 else if (!CommonBtypes)
435 /* No match -- this is a type mismatch error */
437 AnFormatBtype (StringBuffer, ThisNodeBtype);
438 AnFormatBtype (StringBuffer2, RequiredBtypes);
440 sprintf (MsgBuffer, "[%s] found, %s operator requires [%s]",
441 StringBuffer, OpInfo->Name, StringBuffer2);
443 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, MsgBuffer);
447 ArgOp = ArgOp->Asl.Next;
448 INCREMENT_ARG_LIST (RuntimeArgTypes2);
461 /*******************************************************************************
463 * FUNCTION: AnOtherSemanticAnalysisWalkBegin
465 * PARAMETERS: ASL_WALK_CALLBACK
469 * DESCRIPTION: Descending callback for the analysis walk. Checks for
470 * miscellaneous issues in the code.
472 ******************************************************************************/
475 AnOtherSemanticAnalysisWalkBegin (
476 ACPI_PARSE_OBJECT *Op,
480 ACPI_PARSE_OBJECT *ArgNode;
481 ACPI_PARSE_OBJECT *PrevArgNode = NULL;
482 const ACPI_OPCODE_INFO *OpInfo;
483 ACPI_NAMESPACE_NODE *Node;
486 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
489 * Determine if an execution class operator actually does something by
490 * checking if it has a target and/or the function return value is used.
491 * (Target is optional, so a standalone statement can actually do nothing.)
493 if ((OpInfo->Class == AML_CLASS_EXECUTE) &&
494 (OpInfo->Flags & AML_HAS_RETVAL) &&
495 (!AnIsResultUsed (Op)))
497 if (OpInfo->Flags & AML_HAS_TARGET)
500 * Find the target node, it is always the last child. If the traget
501 * is not specified in the ASL, a default node of type Zero was
502 * created by the parser.
504 ArgNode = Op->Asl.Child;
505 while (ArgNode->Asl.Next)
507 PrevArgNode = ArgNode;
508 ArgNode = ArgNode->Asl.Next;
511 /* Divide() is the only weird case, it has two targets */
513 if (Op->Asl.AmlOpcode == AML_DIVIDE_OP)
515 if ((ArgNode->Asl.ParseOpcode == PARSEOP_ZERO) &&
517 (PrevArgNode->Asl.ParseOpcode == PARSEOP_ZERO))
519 AslError (ASL_ERROR, ASL_MSG_RESULT_NOT_USED,
520 Op, Op->Asl.ExternalName);
523 else if (ArgNode->Asl.ParseOpcode == PARSEOP_ZERO)
525 AslError (ASL_ERROR, ASL_MSG_RESULT_NOT_USED,
526 Op, Op->Asl.ExternalName);
532 * Has no target and the result is not used. Only a couple opcodes
533 * can have this combination.
535 switch (Op->Asl.ParseOpcode)
537 case PARSEOP_ACQUIRE:
539 case PARSEOP_LOADTABLE:
545 AslError (ASL_ERROR, ASL_MSG_RESULT_NOT_USED,
546 Op, Op->Asl.ExternalName);
554 * Semantic checks for individual ASL operators
556 switch (Op->Asl.ParseOpcode)
558 case PARSEOP_ACQUIRE:
561 * Emit a warning if the timeout parameter for these operators is not
562 * ACPI_WAIT_FOREVER, and the result value from the operator is not
563 * checked, meaning that a timeout could happen, but the code
564 * would not know about it.
567 /* First child is the namepath, 2nd child is timeout */
569 ArgNode = Op->Asl.Child;
570 ArgNode = ArgNode->Asl.Next;
573 * Check for the WAIT_FOREVER case - defined by the ACPI spec to be
576 if (((ArgNode->Asl.ParseOpcode == PARSEOP_WORDCONST) ||
577 (ArgNode->Asl.ParseOpcode == PARSEOP_INTEGER)) &&
578 (ArgNode->Asl.Value.Integer >= (UINT64) ACPI_WAIT_FOREVER))
584 * The operation could timeout. If the return value is not used
585 * (indicates timeout occurred), issue a warning
587 if (!AnIsResultUsed (Op))
589 AslError (ASL_WARNING, ASL_MSG_TIMEOUT, ArgNode,
590 Op->Asl.ExternalName);
594 case PARSEOP_CREATEFIELD:
596 * Check for a zero Length (NumBits) operand. NumBits is the 3rd operand
598 ArgNode = Op->Asl.Child;
599 ArgNode = ArgNode->Asl.Next;
600 ArgNode = ArgNode->Asl.Next;
602 if ((ArgNode->Asl.ParseOpcode == PARSEOP_ZERO) ||
603 ((ArgNode->Asl.ParseOpcode == PARSEOP_INTEGER) &&
604 (ArgNode->Asl.Value.Integer == 0)))
606 AslError (ASL_ERROR, ASL_MSG_NON_ZERO, ArgNode, NULL);
610 case PARSEOP_CONNECTION:
612 * Ensure that the referenced operation region has the correct SPACE_ID.
613 * From the grammar/parser, we know the parent is a FIELD definition.
615 ArgNode = Op->Asl.Parent; /* Field definition */
616 ArgNode = ArgNode->Asl.Child; /* First child is the OpRegion Name */
617 Node = ArgNode->Asl.Node; /* OpRegion namespace node */
623 ArgNode = Node->Op; /* OpRegion definition */
624 ArgNode = ArgNode->Asl.Child; /* First child is the OpRegion Name */
625 ArgNode = ArgNode->Asl.Next; /* Next peer is the SPACE_ID (what we want) */
628 * The Connection() operator is only valid for the following operation
629 * region SpaceIds: GeneralPurposeIo and GenericSerialBus.
631 if ((ArgNode->Asl.Value.Integer != ACPI_ADR_SPACE_GPIO) &&
632 (ArgNode->Asl.Value.Integer != ACPI_ADR_SPACE_GSBUS))
634 AslError (ASL_ERROR, ASL_MSG_CONNECTION_INVALID, Op, NULL);
640 * Ensure that fields for GeneralPurposeIo and GenericSerialBus
641 * contain at least one Connection() operator
643 ArgNode = Op->Asl.Child; /* 1st child is the OpRegion Name */
644 Node = ArgNode->Asl.Node; /* OpRegion namespace node */
650 ArgNode = Node->Op; /* OpRegion definition */
651 ArgNode = ArgNode->Asl.Child; /* First child is the OpRegion Name */
652 ArgNode = ArgNode->Asl.Next; /* Next peer is the SPACE_ID (what we want) */
654 /* We are only interested in GeneralPurposeIo and GenericSerialBus */
656 if ((ArgNode->Asl.Value.Integer != ACPI_ADR_SPACE_GPIO) &&
657 (ArgNode->Asl.Value.Integer != ACPI_ADR_SPACE_GSBUS))
662 ArgNode = Op->Asl.Child; /* 1st child is the OpRegion Name */
663 ArgNode = ArgNode->Asl.Next; /* AccessType */
664 ArgNode = ArgNode->Asl.Next; /* LockRule */
665 ArgNode = ArgNode->Asl.Next; /* UpdateRule */
666 ArgNode = ArgNode->Asl.Next; /* Start of FieldUnitList */
668 /* Walk the FieldUnitList */
672 if (ArgNode->Asl.ParseOpcode == PARSEOP_CONNECTION)
676 else if (ArgNode->Asl.ParseOpcode == PARSEOP_NAMESEG)
678 AslError (ASL_ERROR, ASL_MSG_CONNECTION_MISSING, ArgNode, NULL);
682 ArgNode = ArgNode->Asl.Next;