/******************************************************************************
*
* Module Name: psparse - Parser top level AML parse routines
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2016, 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.
*/
/*
* Parse the AML and build an operation tree as most interpreters,
* like Perl, do. Parsing is done by hand rather than with a YACC
* generated parser to tightly constrain stack and dynamic memory
* usage. At the same time, parsing is kept flexible and the code
* fairly compact by parsing based on a list of AML opcode
* templates in AmlOpInfo[]
*/
#include "acpi.h"
#include "accommon.h"
#include "acparser.h"
#include "acdispat.h"
#include "amlcode.h"
#include "acinterp.h"
ACPI_MODULE_NAME ("psparse")
/*******************************************************************************
*
* FUNCTION: AcpiPsGetOpcodeSize
*
* PARAMETERS: Opcode - An AML opcode
*
* RETURN: Size of the opcode, in bytes (1 or 2)
*
* DESCRIPTION: Get the size of the current opcode.
*
******************************************************************************/
{
/* Extended (2-byte) opcode if > 255 */
if (Opcode > 0x00FF)
{
return (2);
}
/* Otherwise, just a single byte opcode */
return (1);
}
/*******************************************************************************
*
* FUNCTION: AcpiPsPeekOpcode
*
* PARAMETERS: ParserState - A parser state object
*
* RETURN: Next AML opcode
*
* DESCRIPTION: Get next AML opcode (without incrementing AML pointer)
*
******************************************************************************/
{
if (Opcode == AML_EXTENDED_OP_PREFIX)
{
/* Extended opcode, get the second opcode byte */
Aml++;
}
return (Opcode);
}
/*******************************************************************************
*
* FUNCTION: AcpiPsCompleteThisOp
*
* PARAMETERS: WalkState - Current State
* Op - Op to complete
*
* RETURN: Status
*
* DESCRIPTION: Perform any cleanup at the completion of an Op.
*
******************************************************************************/
{
/* Check for null Op, can happen if AML code is corrupt */
if (!Op)
{
}
/* Delete this op and the subtree below it if asked to */
{
}
/* Make sure that we only delete this subtree */
{
if (!Prev)
{
/* Nothing more to do */
goto Cleanup;
}
/*
* Check if we need to replace the operator and its subtree
* with a return value op (placeholder op)
*/
switch (ParentInfo->Class)
{
case AML_CLASS_CONTROL:
break;
case AML_CLASS_CREATE:
/*
* These opcodes contain TermArg operands. The current
* op must be replaced by a placeholder return op
*/
if (!ReplacementOp)
{
}
break;
case AML_CLASS_NAMED_OBJECT:
/*
* These opcodes contain TermArg operands. The current
* op must be replaced by a placeholder return op
*/
{
if (!ReplacementOp)
{
}
}
{
{
if (!ReplacementOp)
{
}
else
{
}
}
}
break;
default:
if (!ReplacementOp)
{
}
}
/* We must unlink this op from the parent tree */
{
/* This op is the first in the list */
if (ReplacementOp)
{
}
else
{
}
}
/* Search the parent list */
else while (Prev)
{
/* Traverse all siblings in the parent's argument list */
{
if (ReplacementOp)
{
}
else
{
}
}
}
}
/* Now we can actually delete the subtree rooted at Op */
}
/*******************************************************************************
*
* FUNCTION: AcpiPsNextParseState
*
* PARAMETERS: WalkState - Current state
* Op - Current parse op
* CallbackStatus - Status from previous operation
*
* RETURN: Status
*
* DESCRIPTION: Update the parser state based upon the return exception from
* the parser callback.
*
******************************************************************************/
{
switch (CallbackStatus)
{
case AE_CTRL_TERMINATE:
/*
* A control method was terminated via a RETURN statement.
* The walk of this method is complete.
*/
break;
case AE_CTRL_BREAK:
break;
case AE_CTRL_CONTINUE:
break;
case AE_CTRL_PENDING:
break;
#if 0
case AE_CTRL_SKIP:
break;
#endif
case AE_CTRL_TRUE:
/*
* Predicate of an IF was true, and we are at the matching ELSE.
* Just close out this package
*/
break;
case AE_CTRL_FALSE:
/*
* opcode. In both cases, we do not execute the rest of the
* package; We simply close out the parent (finishing the walk of
* this branch of the tree) and continue execution at the parent
* level.
*/
/* In the case of a BREAK, just force a predicate (if any) to FALSE */
break;
case AE_CTRL_TRANSFER:
/* A method call (invocation) -- transfer control */
/* Will return value (if any) be used by the caller? */
break;
default:
{
}
break;
}
}
/*******************************************************************************
*
* FUNCTION: AcpiPsParseAml
*
* PARAMETERS: WalkState - Current state
*
*
* RETURN: Status
*
* DESCRIPTION: Parse raw AML and return a tree of ops
*
******************************************************************************/
{
"Entered with WalkState=%p Aml=%p size=%X\n",
{
}
/* Create and initialize a new thread state */
if (!Thread)
{
if (WalkState->MethodDesc)
{
/* Executing a control method - additional cleanup */
}
}
/*
* If executing a method, the starting SyncLevel is this method's
* SyncLevel
*/
if (WalkState->MethodDesc)
{
}
/*
* This global allows the AML debugger to get a handle to the currently
* executing control method.
*/
/*
* Execute the walk loop as long as there is a valid Walk State. This
* handles nested control method invocations without recursion.
*/
while (WalkState)
{
if (ACPI_SUCCESS (Status))
{
/*
* The ParseLoop executes AML until the method terminates
* or calls another method.
*/
}
"Completed one call to walk loop, %s State=%p\n",
if (Status == AE_CTRL_TRANSFER)
{
/*
* A method call was detected.
* Transfer control to the called control method
*/
if (ACPI_FAILURE (Status))
{
}
/*
* If the transfer to the new method method call worked
*, a new walk state was created -- get it
*/
continue;
}
else if (Status == AE_CTRL_TERMINATE)
{
}
{
/* Either the method parse or actual execution failed */
ACPI_ERROR_METHOD ("Method parse/execution failed",
/* Check for possible multi-thread reentrancy problem */
if ((Status == AE_ALREADY_EXISTS) &&
{
/*
* Method is not serialized and tried to create an object
* twice. The probable cause is that the method cannot
* handle reentrancy. Mark as "pending serialized" now, and
* then mark "serialized" when the last thread exits.
*/
}
}
/* We are done with this walk, move on to the parent if any */
/* Reset the current scope to the beginning of scope stack */
/*
* If we just returned from the execution of a control method or if we
* encountered an error during the method parse phase, there's lots of
* cleanup to do
*/
(ACPI_FAILURE (Status)))
{
}
/* Delete this walk state and all linked control states */
"ReturnValue=%p, ImplicitValue=%p State=%p\n",
/* Check if we have restarted a preempted walk */
if (WalkState)
{
if (ACPI_SUCCESS (Status))
{
/*
* There is another walk state, restart it.
* If the method return value is not used by the parent,
* The object is deleted
*/
if (!PreviousWalkState->ReturnDesc)
{
/*
* In slack mode execution, if there is no return value
* we should implicitly return zero (0) as a default value.
*/
{
AcpiUtCreateIntegerObject ((UINT64) 0);
{
}
}
/* Restart the calling control method */
}
else
{
/*
* We have a valid return value, delete any implicit
* return value.
*/
}
if (ACPI_SUCCESS (Status))
{
}
}
else
{
/* On error, delete any return object or implicit return */
}
}
/*
* Just completed a 1st-level method, save the final internal return
* value (if any)
*/
else if (PreviousWalkState->CallerReturnDesc)
{
{
}
else
{
/* NULL if no return value */
}
}
else
{
if (PreviousWalkState->ReturnDesc)
{
/* Caller doesn't want it, must delete it */
}
{
/* Caller doesn't want it, must delete it */
}
}
}
/* Normal exit */
}