aslwalks.c revision 199767f8919635c4928607450d9e0abb932109ce
/******************************************************************************
*
* Module Name: aslwalks.c - Miscellaneous analytical parse tree walks
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2015, Intel Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
* 3. Neither the names of the above-listed copyright holders nor the names
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*/
#include "aslcompiler.y.h"
#define _COMPONENT ACPI_COMPILER
ACPI_MODULE_NAME ("aslwalks")
/*******************************************************************************
*
* FUNCTION: AnMethodTypingWalkEnd
*
* PARAMETERS: ASL_WALK_CALLBACK
*
* RETURN: Status
*
* DESCRIPTION: Ascending callback for typing walk. Complete the method
* return analysis. Check methods for:
* 1) Initialized local variables
* 2) Valid arguments
* 3) Return types
*
******************************************************************************/
void *Context)
{
{
case PARSEOP_METHOD:
break;
case PARSEOP_RETURN:
{
{
/*
* The called method is untyped at this time (typically a
* forward reference).
*
* Check for a recursive method call first.
*/
{
/* We must type the method here */
}
}
/* Returns a value, save the value type */
{
}
}
break;
default:
break;
}
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AnOperandTypecheckWalkEnd
*
* PARAMETERS: ASL_WALK_CALLBACK
*
* RETURN: Status
*
* DESCRIPTION: Ascending callback for analysis walk. Complete method
* return analysis.
*
******************************************************************************/
void *Context)
{
const ACPI_OPCODE_INFO *OpInfo;
{
case AML_RAW_DATA_BYTE:
case AML_RAW_DATA_WORD:
case AML_RAW_DATA_DWORD:
case AML_RAW_DATA_QWORD:
case AML_RAW_DATA_BUFFER:
case AML_RAW_DATA_CHAIN:
case AML_PACKAGE_LENGTH:
case AML_UNASSIGNED_OPCODE:
case AML_DEFAULT_ARG_OP:
/* Ignore the internal (compiler-only) AML opcodes */
return (AE_OK);
default:
break;
}
if (!OpInfo)
{
return (AE_OK);
}
/*
* Update 11/2008: In practice, we can't perform this check. A simple
* analysis is not sufficient. Also, it can cause errors when compiling
* disassembled code because of the way Switch operators are implemented
* (a While(One) loop with a named temp variable created within.)
*/
/*
* If we are creating a named object, check if we are within a while loop
* by checking if the parent is a WHILE op. This is a simple analysis, but
* probably sufficient for many cases.
*
* Allow Scope(), Buffer(), and Package().
*/
{
{
}
}
#endif
/*
* have no runtime arg list (at this time)
*/
{
case AML_IF_OP:
case AML_WHILE_OP:
case AML_RETURN_OP:
{
/* Check for an internal method */
if (AnIsInternalMethod (ArgOp))
{
return (AE_OK);
}
/* The lone arg is a method call, check it */
{
RequiredBtypes = 0xFFFFFFFF;
}
if (ThisNodeBtype == ACPI_UINT32_MAX)
{
return (AE_OK);
}
}
return (AE_OK);
case AML_EXTERNAL_OP:
/*
* Not really a "runtime" opcode since it used by disassembler only.
* The parser will find any issues with the operands.
*/
return (AE_OK);
default:
break;
}
/* Ignore the non-executable opcodes */
if (RuntimeArgTypes == ARGI_INVALID_OPCODE)
{
return (AE_OK);
}
switch (OpcodeClass)
{
case AML_CLASS_EXECUTE:
case AML_CLASS_CREATE:
case AML_CLASS_CONTROL:
case AML_CLASS_RETURN_VALUE:
/* TBD: Change class or fix typechecking for these */
{
break;
}
/* Reverse the runtime argument list */
RuntimeArgTypes2 = 0;
{
}
{
if (!ArgOp)
{
"Null ArgOp in argument loop");
AslAbort ();
}
if (ThisNodeBtype == ACPI_UINT32_MAX)
{
goto NextArgument;
}
/* Examine the arg based on the required type of the arg */
switch (ArgType)
{
case ARGI_TARGETREF:
{
/* ZERO is the placeholder for "don't store result" */
break;
}
{
/*
* This is the case where an original reference to a resource
* descriptor field has been replaced by an (Integer) offset.
* These named fields are supported at compile-time only;
* the names are not passed to the interpreter (via the AML).
*/
{
}
else
{
}
break;
}
{
break;
}
break;
case ARGI_REFERENCE: /* References */
case ARGI_INTEGER_REF:
case ARGI_OBJECT_REF:
case ARGI_DEVICE_REF:
{
case PARSEOP_LOCAL0:
case PARSEOP_LOCAL1:
case PARSEOP_LOCAL2:
case PARSEOP_LOCAL3:
case PARSEOP_LOCAL4:
case PARSEOP_LOCAL5:
case PARSEOP_LOCAL6:
case PARSEOP_LOCAL7:
/* TBD: implement analysis of current value (type) of the local */
/* For now, just treat any local as a typematch */
/*ThisNodeBtype = RequiredBtypes;*/
break;
case PARSEOP_ARG0:
case PARSEOP_ARG1:
case PARSEOP_ARG2:
case PARSEOP_ARG3:
case PARSEOP_ARG4:
case PARSEOP_ARG5:
case PARSEOP_ARG6:
/* Hard to analyze argument types, sow we won't */
/* For now, just treat any arg as a typematch */
/* ThisNodeBtype = RequiredBtypes; */
break;
case PARSEOP_DEBUG:
case PARSEOP_REFOF:
case PARSEOP_INDEX:
default:
break;
}
break;
case ARGI_INTEGER:
default:
break;
}
{
if (AnIsInternalMethod (ArgOp))
{
return (AE_OK);
}
/* Check a method call for a valid return value */
}
/*
* Now check if the actual type(s) match at least one
* bit to the required type
*/
else if (!CommonBtypes)
{
/* No match -- this is a type mismatch error */
}
}
break;
default:
break;
}
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AnOtherSemanticAnalysisWalkBegin
*
* PARAMETERS: ASL_WALK_CALLBACK
*
* RETURN: Status
*
* DESCRIPTION: Descending callback for the analysis walk. Checks for
* miscellaneous issues in the code.
*
******************************************************************************/
void *Context)
{
const ACPI_OPCODE_INFO *OpInfo;
/*
* Determine if an execution class operator actually does something by
* (Target is optional, so a standalone statement can actually do nothing.)
*/
(!AnIsResultUsed (Op)))
{
{
/*
* Find the target node, it is always the last child. If the traget
* is not specified in the ASL, a default node of type Zero was
* created by the parser.
*/
{
}
/* Divide() is the only weird case, it has two targets */
{
(PrevArgNode) &&
{
}
}
{
}
}
else
{
/*
* Has no target and the result is not used. Only a couple opcodes
* can have this combination.
*/
{
case PARSEOP_ACQUIRE:
case PARSEOP_WAIT:
case PARSEOP_LOADTABLE:
break;
default:
break;
}
}
}
/*
* Semantic checks for individual ASL operators
*/
{
case PARSEOP_ACQUIRE:
case PARSEOP_WAIT:
/*
* Emit a warning if the timeout parameter for these operators is not
* ACPI_WAIT_FOREVER, and the result value from the operator is not
* checked, meaning that a timeout could happen, but the code
* would not know about it.
*/
/* First child is the namepath, 2nd child is timeout */
/*
* Check for the WAIT_FOREVER case - defined by the ACPI spec to be
* 0xFFFF or greater
*/
{
break;
}
/*
* The operation could timeout. If the return value is not used
* (indicates timeout occurred), issue a warning
*/
if (!AnIsResultUsed (Op))
{
}
break;
case PARSEOP_CREATEFIELD:
/*
* Check for a zero Length (NumBits) operand. NumBits is the 3rd operand
*/
{
}
break;
case PARSEOP_CONNECTION:
/*
* Ensure that the referenced operation region has the correct SPACE_ID.
*/
if (!Node)
{
break;
}
/*
* The Connection() operator is only valid for the following operation
* region SpaceIds: GeneralPurposeIo and GenericSerialBus.
*/
{
}
break;
case PARSEOP_FIELD:
/*
* Ensure that fields for GeneralPurposeIo and GenericSerialBus
* contain at least one Connection() operator
*/
if (!Node)
{
break;
}
/* We are only interested in GeneralPurposeIo and GenericSerialBus */
{
break;
}
/* Walk the FieldUnitList */
while (ArgNode)
{
{
break;
}
{
break;
}
}
break;
default:
break;
}
return (AE_OK);
}