dsutils.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*******************************************************************************
*
* Module Name: dsutils - Dispatcher utilities
* $Revision: 113 $
*
******************************************************************************/
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
#define __DSUTILS_C__
#include "acpi.h"
#include "acparser.h"
#include "amlcode.h"
#include "acdispat.h"
#include "acinterp.h"
#include "acnamesp.h"
#include "acdebug.h"
#define _COMPONENT ACPI_DISPATCHER
ACPI_MODULE_NAME ("dsutils")
/*******************************************************************************
*
* FUNCTION: AcpiDsClearImplicitReturn
*
* PARAMETERS: WalkState - Current State
*
* RETURN: None.
*
* DESCRIPTION: Clear and remove a reference on an implicit return value. Used
* to delete "stale" return values (if enabled, the return value
* from every operator is saved at least momentarily, in case the
* parent method exits.)
*
******************************************************************************/
void
{
ACPI_FUNCTION_NAME ("DsClearImplicitReturn");
/*
* Slack must be enabled for this feature
*/
{
return;
}
if (WalkState->ImplicitReturnObj)
{
/*
* Delete any "stale" implicit return. However, in
* complex statements, the implicit return value can be
* bubbled up several levels.
*/
"Removing reference on stale implicit return obj %p\n",
}
}
#ifndef ACPI_NO_METHOD_EXECUTION
/*******************************************************************************
*
* FUNCTION: AcpiDsDoImplicitReturn
*
* PARAMETERS: ReturnDesc - The return value
* WalkState - Current State
* AddReference - True if a reference should be added to the
* return object
*
* RETURN: TRUE if implicit return enabled, FALSE otherwise
*
* DESCRIPTION: Implements the optional "implicit return". We save the result
* of every ASL operator and control method invocation in case the
* parent method exit. Before storing a new return value, we
* delete the previous return value.
*
******************************************************************************/
{
ACPI_FUNCTION_NAME ("DsDoImplicitReturn");
/*
* Slack must be enabled for this feature, and we must
* have a valid return object
*/
if ((!AcpiGbl_EnableInterpreterSlack) ||
(!ReturnDesc))
{
return (FALSE);
}
"Result %p will be implicitly returned; Prev=%p\n",
/*
* Delete any "stale" implicit return value first. However, in
* complex statements, the implicit return value can be
* bubbled up several levels, so we don't clear the value if it
* is the same as the ReturnDesc.
*/
if (WalkState->ImplicitReturnObj)
{
{
return (TRUE);
}
}
/* Save the implicit return value, add a reference if requested */
if (AddReference)
{
}
return (TRUE);
}
/*******************************************************************************
*
* FUNCTION: AcpiDsIsResultUsed
*
* PARAMETERS: Op - Current Op
* WalkState - Current State
*
* RETURN: TRUE if result is used, FALSE otherwise
*
* DESCRIPTION: Check if a result object will be used by the parent
*
******************************************************************************/
{
const ACPI_OPCODE_INFO *ParentInfo;
/* Must have both an Op and a Result Object */
if (!Op)
{
return_VALUE (TRUE);
}
/*
* We know that this operator is not a
* Return() operator (would not come here.) The following code is the
* optional support for a so-called "implicit return". Some AML code
* assumes that the last value of the method is "implicitly" returned
* to the caller. Just save the last result as the return value.
* NOTE: this is optional because the ASL language does not actually
* support this behavior.
*/
/*
* Now determine if the parent will use the result
*
* If there is no parent, or the parent is a ScopeOp, we are executing
* at the method level. An executing method typically has no parent,
* since each method is parsed separately. A method invoked externally
* via ExecuteControlMethod has a ScopeOp as the parent.
*/
{
/* No parent, the return value cannot possibly be used */
"At Method level, result of [%s] not used\n",
}
/* Get info on the parent. The RootOp is AML_SCOPE */
{
"Unknown parent opcode. Op=%p\n", Op));
}
/*
* Decide what to do with the result based on the parent. If
* the parent opcode will not use the result, delete the object.
* Otherwise leave it as is, it will be deleted when it is used
* as an operand later.
*/
switch (ParentInfo->Class)
{
case AML_CLASS_CONTROL:
{
case AML_RETURN_OP:
/* Never delete the return value associated with a return opcode */
goto ResultUsed;
case AML_IF_OP:
case AML_WHILE_OP:
/*
* If we are executing the predicate AND this is the predicate op,
* we will use the return value
*/
{
goto ResultUsed;
}
break;
default:
/* Ignore other control opcodes */
break;
}
/* The general control opcode returns no result */
goto ResultNotUsed;
case AML_CLASS_CREATE:
/*
* These opcodes allow TermArg(s) as operands and therefore
* the operands can be method calls. The result is used.
*/
goto ResultUsed;
case AML_CLASS_NAMED_OBJECT:
{
/*
* These opcodes allow TermArg(s) as operands and therefore
* the operands can be method calls. The result is used.
*/
goto ResultUsed;
}
goto ResultNotUsed;
default:
/*
* In all other cases. the parent will actually use the return
* object, so keep it.
*/
goto ResultUsed;
}
"Result of [%s] used by Parent [%s] Op=%p\n",
return_VALUE (TRUE);
"Result of [%s] not used by Parent [%s] Op=%p\n",
}
/*******************************************************************************
*
* FUNCTION: AcpiDsDeleteResultIfNotUsed
*
* PARAMETERS: Op - Current parse Op
* ResultObj - Result of the operation
* WalkState - Current state
*
* RETURN: Status
*
* DESCRIPTION: Used after interpretation of an opcode. If there is an internal
* result descriptor, check if the parent opcode will actually use
* this result. If not, delete the result now so that it will
* not become orphaned.
*
******************************************************************************/
void
{
if (!Op)
{
}
if (!ResultObj)
{
}
{
/* Must pop the result stack (ObjDesc should be equal to ResultObj) */
if (ACPI_SUCCESS (Status))
{
}
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDsResolveOperands
*
* PARAMETERS: WalkState - Current walk state with operands on stack
*
* RETURN: Status
*
* DESCRIPTION: Resolve all operands to their values. Used to prepare
* arguments to a control method invocation (a call from one
* method to another.)
*
******************************************************************************/
{
UINT32 i;
/*
* Attempt to resolve each of the valid operands
* Method arguments are passed by reference, not by value. This means
* that the actual objects are passed, not copies of the objects.
*/
for (i = 0; i < WalkState->NumOperands; i++)
{
if (ACPI_FAILURE (Status))
{
break;
}
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDsClearOperands
*
* PARAMETERS: WalkState - Current walk state with operands on stack
*
* RETURN: None
*
* DESCRIPTION: Clear all operands on the current walk state operand stack.
*
******************************************************************************/
void
{
UINT32 i;
/* Remove a reference on each operand on the stack */
for (i = 0; i < WalkState->NumOperands; i++)
{
/*
* Remove a reference to all operands, including both
* "Arguments" and "Targets".
*/
}
WalkState->NumOperands = 0;
}
#endif
/*******************************************************************************
*
* FUNCTION: AcpiDsCreateOperand
*
* PARAMETERS: WalkState - Current walk state
* Arg - Parse object for the argument
* ArgIndex - Which argument (zero based)
*
* RETURN: Status
*
* DESCRIPTION: Translate a parse tree object that is an argument to an AML
* opcode to the equivalent interpreter object. This may include
* looking up a name or entering a new name into the internal
* namespace.
*
******************************************************************************/
{
char *NameString;
const ACPI_OPCODE_INFO *OpInfo;
/* A valid name must be looked up in the namespace */
{
/* Get the entire name string from the AML stream */
&NameString, &NameLength);
if (ACPI_FAILURE (Status))
{
}
/* All prefixes have been handled, and the name is in NameString */
/*
* Special handling for BufferField declarations. This is a deferred
* opcode that unfortunately defines the field name as the last
* parameter instead of the first. We get here when we are performing
* the deferred execution, so the actual name of the field is already
* in the namespace. We don't want to attempt to look it up again
* because we may be executing in a different scope than where the
* actual opcode exists.
*/
if ((WalkState->DeferredNode) &&
(ArgIndex != 0))
{
ObjDesc = ACPI_CAST_PTR (
}
else /* All other opcodes */
{
/*
* Differentiate between a namespace "create" operation
* versus a "lookup" operation (IMODE_LOAD_PASS2 vs.
* IMODE_EXECUTE) in order to support the creation of
* namespace objects during the execution of control methods.
*/
{
/* Enter name into namespace if not found */
}
else
{
/* Return a failure if name not found */
}
/*
* The only case where we pass through (ignore) a NOT_FOUND
* error is for the CondRefOf opcode.
*/
if (Status == AE_NOT_FOUND)
{
{
/*
* For the Conditional Reference op, it's OK if
* the name is not found; We just need a way to
* indicate this to the interpreter, set the
* object to the root
*/
ObjDesc = ACPI_CAST_PTR (
}
else
{
/*
* We just plain didn't find it -- which is a
* very serious error at this point
*/
}
}
if (ACPI_FAILURE (Status))
{
}
}
/* Free the namestring created above */
/* Check status from the lookup */
if (ACPI_FAILURE (Status))
{
}
/* Put the resulting object onto the current object stack */
if (ACPI_FAILURE (Status))
{
}
}
else
{
/* Check for null name case */
{
/*
* If the name is null, this means that this is an
* optional result parameter that was not specified
* in the original ASL. Create a Zero Constant for a
* placeholder. (Store to a constant is a Noop.)
*/
"Null namepath: Arg=%p\n", Arg));
}
else
{
}
/* Get the object type of the argument */
{
}
{
"Argument previously created, already stacked \n"));
/*
* Use value that was already previously returned
* by the evaluation of this argument
*/
if (ACPI_FAILURE (Status))
{
/*
* Only error is underflow, and this indicates
* a missing or null operand!
*/
"Missing or null operand, %s\n",
}
}
else
{
/* Create an ACPI_INTERNAL_OBJECT for the argument */
if (!ObjDesc)
{
}
/* Initialize the new object */
if (ACPI_FAILURE (Status))
{
}
}
/* Put the operand object on the object stack */
if (ACPI_FAILURE (Status))
{
}
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDsCreateOperands
*
* PARAMETERS: WalkState - Current state
* FirstArg - First argument of a parser argument tree
*
* RETURN: Status
*
* DESCRIPTION: Convert an operator's arguments from a parse tree format to
* namespace objects and place those argument object on the object
* stack in preparation for evaluation by the interpreter.
*
******************************************************************************/
{
/* For all arguments in the list... */
while (Arg)
{
if (ACPI_FAILURE (Status))
{
goto Cleanup;
}
/* Move on to next argument, if any */
ArgCount++;
}
/*
* We must undo everything done above; meaning that we must
* pop everything off of the operand stack and delete those
* objects
*/
}