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);
260 /* Ignore the non-executable opcodes */
262 if (RuntimeArgTypes == ARGI_INVALID_OPCODE)
269 case AML_CLASS_EXECUTE:
270 case AML_CLASS_CREATE:
271 case AML_CLASS_CONTROL:
272 case AML_CLASS_RETURN_VALUE:
274 /* TBD: Change class or fix typechecking for these */
276 if ((Op->Asl.AmlOpcode == AML_BUFFER_OP) ||
277 (Op->Asl.AmlOpcode == AML_PACKAGE_OP) ||
278 (Op->Asl.AmlOpcode == AML_VAR_PACKAGE_OP))
283 /* Reverse the runtime argument list */
285 RuntimeArgTypes2 = 0;
286 while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes)))
288 RuntimeArgTypes2 <<= ARG_TYPE_WIDTH;
289 RuntimeArgTypes2 |= ArgType;
290 INCREMENT_ARG_LIST (RuntimeArgTypes);
293 while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes2)))
295 RequiredBtypes = AnMapArgTypeToBtype (ArgType);
299 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
300 "Null ArgOp in argument loop");
304 ThisNodeBtype = AnGetBtype (ArgOp);
305 if (ThisNodeBtype == ACPI_UINT32_MAX)
310 /* Examine the arg based on the required type of the arg */
316 if (ArgOp->Asl.ParseOpcode == PARSEOP_ZERO)
318 /* ZERO is the placeholder for "don't store result" */
320 ThisNodeBtype = RequiredBtypes;
324 if (ArgOp->Asl.ParseOpcode == PARSEOP_INTEGER)
327 * This is the case where an original reference to a resource
328 * descriptor field has been replaced by an (Integer) offset.
329 * These named fields are supported at compile-time only;
330 * the names are not passed to the interpreter (via the AML).
332 if ((ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
333 (ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
335 AslError (ASL_ERROR, ASL_MSG_RESOURCE_FIELD, ArgOp, NULL);
339 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, NULL);
344 if ((ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL) ||
345 (ArgOp->Asl.ParseOpcode == PARSEOP_DEREFOF))
350 ThisNodeBtype = RequiredBtypes;
354 case ARGI_REFERENCE: /* References */
355 case ARGI_INTEGER_REF:
356 case ARGI_OBJECT_REF:
357 case ARGI_DEVICE_REF:
359 switch (ArgOp->Asl.ParseOpcode)
370 /* TBD: implement analysis of current value (type) of the local */
371 /* For now, just treat any local as a typematch */
373 /*ThisNodeBtype = RequiredBtypes;*/
384 /* Hard to analyze argument types, sow we won't */
385 /* For now, just treat any arg as a typematch */
387 /* ThisNodeBtype = RequiredBtypes; */
410 CommonBtypes = ThisNodeBtype & RequiredBtypes;
412 if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL)
414 if (AnIsInternalMethod (ArgOp))
419 /* Check a method call for a valid return value */
421 AnCheckMethodReturnValue (Op, OpInfo, ArgOp,
422 RequiredBtypes, ThisNodeBtype);
426 * Now check if the actual type(s) match at least one
427 * bit to the required type
429 else if (!CommonBtypes)
431 /* No match -- this is a type mismatch error */
433 AnFormatBtype (StringBuffer, ThisNodeBtype);
434 AnFormatBtype (StringBuffer2, RequiredBtypes);
436 sprintf (MsgBuffer, "[%s] found, %s operator requires [%s]",
437 StringBuffer, OpInfo->Name, StringBuffer2);
439 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, MsgBuffer);
443 ArgOp = ArgOp->Asl.Next;
444 INCREMENT_ARG_LIST (RuntimeArgTypes2);
457 /*******************************************************************************
459 * FUNCTION: AnOtherSemanticAnalysisWalkBegin
461 * PARAMETERS: ASL_WALK_CALLBACK
465 * DESCRIPTION: Descending callback for the analysis walk. Checks for
466 * miscellaneous issues in the code.
468 ******************************************************************************/
471 AnOtherSemanticAnalysisWalkBegin (
472 ACPI_PARSE_OBJECT *Op,
476 ACPI_PARSE_OBJECT *ArgNode;
477 ACPI_PARSE_OBJECT *PrevArgNode = NULL;
478 const ACPI_OPCODE_INFO *OpInfo;
479 ACPI_NAMESPACE_NODE *Node;
482 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
485 * Determine if an execution class operator actually does something by
486 * checking if it has a target and/or the function return value is used.
487 * (Target is optional, so a standalone statement can actually do nothing.)
489 if ((OpInfo->Class == AML_CLASS_EXECUTE) &&
490 (OpInfo->Flags & AML_HAS_RETVAL) &&
491 (!AnIsResultUsed (Op)))
493 if (OpInfo->Flags & AML_HAS_TARGET)
496 * Find the target node, it is always the last child. If the traget
497 * is not specified in the ASL, a default node of type Zero was
498 * created by the parser.
500 ArgNode = Op->Asl.Child;
501 while (ArgNode->Asl.Next)
503 PrevArgNode = ArgNode;
504 ArgNode = ArgNode->Asl.Next;
507 /* Divide() is the only weird case, it has two targets */
509 if (Op->Asl.AmlOpcode == AML_DIVIDE_OP)
511 if ((ArgNode->Asl.ParseOpcode == PARSEOP_ZERO) &&
513 (PrevArgNode->Asl.ParseOpcode == PARSEOP_ZERO))
515 AslError (ASL_ERROR, ASL_MSG_RESULT_NOT_USED,
516 Op, Op->Asl.ExternalName);
519 else if (ArgNode->Asl.ParseOpcode == PARSEOP_ZERO)
521 AslError (ASL_ERROR, ASL_MSG_RESULT_NOT_USED,
522 Op, Op->Asl.ExternalName);
528 * Has no target and the result is not used. Only a couple opcodes
529 * can have this combination.
531 switch (Op->Asl.ParseOpcode)
533 case PARSEOP_ACQUIRE:
535 case PARSEOP_LOADTABLE:
541 AslError (ASL_ERROR, ASL_MSG_RESULT_NOT_USED,
542 Op, Op->Asl.ExternalName);
550 * Semantic checks for individual ASL operators
552 switch (Op->Asl.ParseOpcode)
554 case PARSEOP_ACQUIRE:
557 * Emit a warning if the timeout parameter for these operators is not
558 * ACPI_WAIT_FOREVER, and the result value from the operator is not
559 * checked, meaning that a timeout could happen, but the code
560 * would not know about it.
563 /* First child is the namepath, 2nd child is timeout */
565 ArgNode = Op->Asl.Child;
566 ArgNode = ArgNode->Asl.Next;
569 * Check for the WAIT_FOREVER case - defined by the ACPI spec to be
572 if (((ArgNode->Asl.ParseOpcode == PARSEOP_WORDCONST) ||
573 (ArgNode->Asl.ParseOpcode == PARSEOP_INTEGER)) &&
574 (ArgNode->Asl.Value.Integer >= (UINT64) ACPI_WAIT_FOREVER))
580 * The operation could timeout. If the return value is not used
581 * (indicates timeout occurred), issue a warning
583 if (!AnIsResultUsed (Op))
585 AslError (ASL_WARNING, ASL_MSG_TIMEOUT, ArgNode,
586 Op->Asl.ExternalName);
590 case PARSEOP_CREATEFIELD:
592 * Check for a zero Length (NumBits) operand. NumBits is the 3rd operand
594 ArgNode = Op->Asl.Child;
595 ArgNode = ArgNode->Asl.Next;
596 ArgNode = ArgNode->Asl.Next;
598 if ((ArgNode->Asl.ParseOpcode == PARSEOP_ZERO) ||
599 ((ArgNode->Asl.ParseOpcode == PARSEOP_INTEGER) &&
600 (ArgNode->Asl.Value.Integer == 0)))
602 AslError (ASL_ERROR, ASL_MSG_NON_ZERO, ArgNode, NULL);
606 case PARSEOP_CONNECTION:
608 * Ensure that the referenced operation region has the correct SPACE_ID.
609 * From the grammar/parser, we know the parent is a FIELD definition.
611 ArgNode = Op->Asl.Parent; /* Field definition */
612 ArgNode = ArgNode->Asl.Child; /* First child is the OpRegion Name */
613 Node = ArgNode->Asl.Node; /* OpRegion namespace node */
619 ArgNode = Node->Op; /* OpRegion definition */
620 ArgNode = ArgNode->Asl.Child; /* First child is the OpRegion Name */
621 ArgNode = ArgNode->Asl.Next; /* Next peer is the SPACE_ID (what we want) */
624 * The Connection() operator is only valid for the following operation
625 * region SpaceIds: GeneralPurposeIo and GenericSerialBus.
627 if ((ArgNode->Asl.Value.Integer != ACPI_ADR_SPACE_GPIO) &&
628 (ArgNode->Asl.Value.Integer != ACPI_ADR_SPACE_GSBUS))
630 AslError (ASL_ERROR, ASL_MSG_CONNECTION_INVALID, Op, NULL);
636 * Ensure that fields for GeneralPurposeIo and GenericSerialBus
637 * contain at least one Connection() operator
639 ArgNode = Op->Asl.Child; /* 1st child is the OpRegion Name */
640 Node = ArgNode->Asl.Node; /* OpRegion namespace node */
646 ArgNode = Node->Op; /* OpRegion definition */
647 ArgNode = ArgNode->Asl.Child; /* First child is the OpRegion Name */
648 ArgNode = ArgNode->Asl.Next; /* Next peer is the SPACE_ID (what we want) */
650 /* We are only interested in GeneralPurposeIo and GenericSerialBus */
652 if ((ArgNode->Asl.Value.Integer != ACPI_ADR_SPACE_GPIO) &&
653 (ArgNode->Asl.Value.Integer != ACPI_ADR_SPACE_GSBUS))
658 ArgNode = Op->Asl.Child; /* 1st child is the OpRegion Name */
659 ArgNode = ArgNode->Asl.Next; /* AccessType */
660 ArgNode = ArgNode->Asl.Next; /* LockRule */
661 ArgNode = ArgNode->Asl.Next; /* UpdateRule */
662 ArgNode = ArgNode->Asl.Next; /* Start of FieldUnitList */
664 /* Walk the FieldUnitList */
668 if (ArgNode->Asl.ParseOpcode == PARSEOP_CONNECTION)
672 else if (ArgNode->Asl.ParseOpcode == PARSEOP_NAMESEG)
674 AslError (ASL_ERROR, ASL_MSG_CONNECTION_MISSING, ArgNode, NULL);
678 ArgNode = ArgNode->Asl.Next;