2000-10-28 05:01:06 +00:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Module Name: psparse - Parser top level AML parse routines
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2011-01-13 16:12:34 +00:00
|
|
|
/*
|
2012-01-11 21:25:42 +00:00
|
|
|
* Copyright (C) 2000 - 2012, Intel Corp.
|
2000-12-21 06:56:46 +00:00
|
|
|
* All rights reserved.
|
2000-10-28 05:01:06 +00:00
|
|
|
*
|
2011-01-13 16:12:34 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2000-12-01 09:36:25 +00:00
|
|
|
* templates in AmlOpInfo[]
|
2000-10-28 05:01:06 +00:00
|
|
|
*/
|
|
|
|
|
2009-06-01 19:24:26 +00:00
|
|
|
#include "acpi.h"
|
2009-06-01 21:02:40 +00:00
|
|
|
#include "accommon.h"
|
2009-06-01 19:24:26 +00:00
|
|
|
#include "acparser.h"
|
|
|
|
#include "acdispat.h"
|
|
|
|
#include "amlcode.h"
|
|
|
|
#include "acinterp.h"
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2001-05-29 19:52:40 +00:00
|
|
|
#define _COMPONENT ACPI_PARSER
|
2002-02-23 05:10:40 +00:00
|
|
|
ACPI_MODULE_NAME ("psparse")
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
2001-09-07 01:22:25 +00:00
|
|
|
* FUNCTION: AcpiPsGetOpcodeSize
|
2000-10-28 05:01:06 +00:00
|
|
|
*
|
2001-09-07 01:22:25 +00:00
|
|
|
* PARAMETERS: Opcode - An AML opcode
|
2000-10-28 05:01:06 +00:00
|
|
|
*
|
2001-09-07 01:22:25 +00:00
|
|
|
* RETURN: Size of the opcode, in bytes (1 or 2)
|
2000-10-28 05:01:06 +00:00
|
|
|
*
|
2001-09-07 01:22:25 +00:00
|
|
|
* DESCRIPTION: Get the size of the current opcode.
|
2000-10-28 05:01:06 +00:00
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
2001-11-28 04:29:40 +00:00
|
|
|
UINT32
|
2000-10-28 05:01:06 +00:00
|
|
|
AcpiPsGetOpcodeSize (
|
|
|
|
UINT32 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
|
|
|
|
*
|
2005-11-01 22:11:18 +00:00
|
|
|
* RETURN: Next AML opcode
|
2000-10-28 05:01:06 +00:00
|
|
|
*
|
|
|
|
* DESCRIPTION: Get next AML opcode (without incrementing AML pointer)
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
UINT16
|
|
|
|
AcpiPsPeekOpcode (
|
|
|
|
ACPI_PARSE_STATE *ParserState)
|
|
|
|
{
|
|
|
|
UINT8 *Aml;
|
|
|
|
UINT16 Opcode;
|
|
|
|
|
|
|
|
|
|
|
|
Aml = ParserState->Aml;
|
2002-02-23 05:10:40 +00:00
|
|
|
Opcode = (UINT16) ACPI_GET8 (Aml);
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
if (Opcode == AML_EXTENDED_OP_PREFIX)
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
2005-11-01 22:11:18 +00:00
|
|
|
/* Extended opcode, get the second opcode byte */
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2001-11-28 04:29:40 +00:00
|
|
|
Aml++;
|
2002-02-23 05:10:40 +00:00
|
|
|
Opcode = (UINT16) ((Opcode << 8) | ACPI_GET8 (Aml));
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (Opcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: AcpiPsCompleteThisOp
|
|
|
|
*
|
|
|
|
* PARAMETERS: WalkState - Current State
|
|
|
|
* Op - Op to complete
|
|
|
|
*
|
2005-11-01 22:11:18 +00:00
|
|
|
* RETURN: Status
|
2000-10-28 05:01:06 +00:00
|
|
|
*
|
|
|
|
* DESCRIPTION: Perform any cleanup at the completion of an Op.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
ACPI_STATUS
|
2000-10-28 05:01:06 +00:00
|
|
|
AcpiPsCompleteThisOp (
|
|
|
|
ACPI_WALK_STATE *WalkState,
|
|
|
|
ACPI_PARSE_OBJECT *Op)
|
|
|
|
{
|
|
|
|
ACPI_PARSE_OBJECT *Prev;
|
|
|
|
ACPI_PARSE_OBJECT *Next;
|
2001-09-07 01:22:25 +00:00
|
|
|
const ACPI_OPCODE_INFO *ParentInfo;
|
2000-10-28 05:01:06 +00:00
|
|
|
ACPI_PARSE_OBJECT *ReplacementOp = NULL;
|
2009-06-01 21:02:40 +00:00
|
|
|
ACPI_STATUS Status = AE_OK;
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
|
2007-03-22 17:24:05 +00:00
|
|
|
ACPI_FUNCTION_TRACE_PTR (PsCompleteThisOp, Op);
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
|
2002-02-23 05:10:40 +00:00
|
|
|
/* Check for null Op, can happen if AML code is corrupt */
|
|
|
|
|
|
|
|
if (!Op)
|
|
|
|
{
|
2005-11-01 22:11:18 +00:00
|
|
|
return_ACPI_STATUS (AE_OK); /* OK for now */
|
2002-02-23 05:10:40 +00:00
|
|
|
}
|
|
|
|
|
2000-10-28 05:01:06 +00:00
|
|
|
/* Delete this op and the subtree below it if asked to */
|
|
|
|
|
2004-12-01 23:14:10 +00:00
|
|
|
if (((WalkState->ParseFlags & ACPI_PARSE_TREE_MASK) != ACPI_PARSE_DELETE_TREE) ||
|
|
|
|
(WalkState->OpInfo->Class == AML_CLASS_ARGUMENT))
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
2005-11-01 22:11:18 +00:00
|
|
|
return_ACPI_STATUS (AE_OK);
|
2004-12-01 23:14:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure that we only delete this subtree */
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2004-12-01 23:14:10 +00:00
|
|
|
if (Op->Common.Parent)
|
|
|
|
{
|
2005-11-01 22:11:18 +00:00
|
|
|
Prev = Op->Common.Parent->Common.Value.Arg;
|
|
|
|
if (!Prev)
|
|
|
|
{
|
|
|
|
/* Nothing more to do */
|
|
|
|
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2004-12-01 23:14:10 +00:00
|
|
|
/*
|
|
|
|
* Check if we need to replace the operator and its subtree
|
|
|
|
* with a return value op (placeholder op)
|
|
|
|
*/
|
2005-11-01 22:11:18 +00:00
|
|
|
ParentInfo = AcpiPsGetOpcodeInfo (Op->Common.Parent->Common.AmlOpcode);
|
2004-12-01 23:14:10 +00:00
|
|
|
|
|
|
|
switch (ParentInfo->Class)
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
2004-12-01 23:14:10 +00:00
|
|
|
case AML_CLASS_CONTROL:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AML_CLASS_CREATE:
|
|
|
|
|
2000-10-28 05:01:06 +00:00
|
|
|
/*
|
2004-12-01 23:14:10 +00:00
|
|
|
* These opcodes contain TermArg operands. The current
|
|
|
|
* op must be replaced by a placeholder return op
|
2000-10-28 05:01:06 +00:00
|
|
|
*/
|
2004-12-01 23:14:10 +00:00
|
|
|
ReplacementOp = AcpiPsAllocOp (AML_INT_RETURN_VALUE_OP);
|
|
|
|
if (!ReplacementOp)
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
2009-06-01 21:02:40 +00:00
|
|
|
Status = AE_NO_MEMORY;
|
2004-12-01 23:14:10 +00:00
|
|
|
}
|
|
|
|
break;
|
2000-12-08 09:20:40 +00:00
|
|
|
|
2004-12-01 23:14:10 +00:00
|
|
|
case AML_CLASS_NAMED_OBJECT:
|
2000-12-21 06:56:46 +00:00
|
|
|
|
2004-12-01 23:14:10 +00:00
|
|
|
/*
|
|
|
|
* These opcodes contain TermArg operands. The current
|
|
|
|
* op must be replaced by a placeholder return op
|
|
|
|
*/
|
|
|
|
if ((Op->Common.Parent->Common.AmlOpcode == AML_REGION_OP) ||
|
|
|
|
(Op->Common.Parent->Common.AmlOpcode == AML_DATA_REGION_OP) ||
|
|
|
|
(Op->Common.Parent->Common.AmlOpcode == AML_BUFFER_OP) ||
|
|
|
|
(Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
|
2009-06-01 21:02:40 +00:00
|
|
|
(Op->Common.Parent->Common.AmlOpcode == AML_BANK_FIELD_OP) ||
|
2004-12-01 23:14:10 +00:00
|
|
|
(Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP))
|
|
|
|
{
|
2001-11-28 04:29:40 +00:00
|
|
|
ReplacementOp = AcpiPsAllocOp (AML_INT_RETURN_VALUE_OP);
|
|
|
|
if (!ReplacementOp)
|
|
|
|
{
|
2009-06-01 21:02:40 +00:00
|
|
|
Status = AE_NO_MEMORY;
|
2001-11-28 04:29:40 +00:00
|
|
|
}
|
2004-12-01 23:14:10 +00:00
|
|
|
}
|
2005-11-01 22:11:18 +00:00
|
|
|
else if ((Op->Common.Parent->Common.AmlOpcode == AML_NAME_OP) &&
|
|
|
|
(WalkState->PassNumber <= ACPI_IMODE_LOAD_PASS2))
|
2004-12-01 23:14:10 +00:00
|
|
|
{
|
|
|
|
if ((Op->Common.AmlOpcode == AML_BUFFER_OP) ||
|
|
|
|
(Op->Common.AmlOpcode == AML_PACKAGE_OP) ||
|
|
|
|
(Op->Common.AmlOpcode == AML_VAR_PACKAGE_OP))
|
2000-12-08 09:20:40 +00:00
|
|
|
{
|
2004-12-01 23:14:10 +00:00
|
|
|
ReplacementOp = AcpiPsAllocOp (Op->Common.AmlOpcode);
|
2000-12-08 09:20:40 +00:00
|
|
|
if (!ReplacementOp)
|
|
|
|
{
|
2009-06-01 21:02:40 +00:00
|
|
|
Status = AE_NO_MEMORY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ReplacementOp->Named.Data = Op->Named.Data;
|
|
|
|
ReplacementOp->Named.Length = Op->Named.Length;
|
2000-12-08 09:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
2004-12-01 23:14:10 +00:00
|
|
|
}
|
|
|
|
break;
|
2002-06-30 17:50:46 +00:00
|
|
|
|
2004-12-01 23:14:10 +00:00
|
|
|
default:
|
2005-11-01 22:11:18 +00:00
|
|
|
|
2004-12-01 23:14:10 +00:00
|
|
|
ReplacementOp = AcpiPsAllocOp (AML_INT_RETURN_VALUE_OP);
|
|
|
|
if (!ReplacementOp)
|
|
|
|
{
|
2009-06-01 21:02:40 +00:00
|
|
|
Status = AE_NO_MEMORY;
|
2004-12-01 23:14:10 +00:00
|
|
|
}
|
|
|
|
}
|
2002-06-30 17:50:46 +00:00
|
|
|
|
2004-12-01 23:14:10 +00:00
|
|
|
/* We must unlink this op from the parent tree */
|
2002-06-30 17:50:46 +00:00
|
|
|
|
2004-12-01 23:14:10 +00:00
|
|
|
if (Prev == Op)
|
|
|
|
{
|
|
|
|
/* This op is the first in the list */
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2004-12-01 23:14:10 +00:00
|
|
|
if (ReplacementOp)
|
|
|
|
{
|
|
|
|
ReplacementOp->Common.Parent = Op->Common.Parent;
|
|
|
|
ReplacementOp->Common.Value.Arg = NULL;
|
|
|
|
ReplacementOp->Common.Node = Op->Common.Node;
|
|
|
|
Op->Common.Parent->Common.Value.Arg = ReplacementOp;
|
|
|
|
ReplacementOp->Common.Next = Op->Common.Next;
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
2004-12-01 23:14:10 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Op->Common.Parent->Common.Value.Arg = Op->Common.Next;
|
|
|
|
}
|
|
|
|
}
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2004-12-01 23:14:10 +00:00
|
|
|
/* Search the parent list */
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2004-12-01 23:14:10 +00:00
|
|
|
else while (Prev)
|
|
|
|
{
|
|
|
|
/* Traverse all siblings in the parent's argument list */
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2004-12-01 23:14:10 +00:00
|
|
|
Next = Prev->Common.Next;
|
|
|
|
if (Next == Op)
|
|
|
|
{
|
2000-10-28 05:01:06 +00:00
|
|
|
if (ReplacementOp)
|
|
|
|
{
|
2004-12-01 23:14:10 +00:00
|
|
|
ReplacementOp->Common.Parent = Op->Common.Parent;
|
|
|
|
ReplacementOp->Common.Value.Arg = NULL;
|
|
|
|
ReplacementOp->Common.Node = Op->Common.Node;
|
|
|
|
Prev->Common.Next = ReplacementOp;
|
|
|
|
ReplacementOp->Common.Next = Op->Common.Next;
|
|
|
|
Next = NULL;
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-12-01 23:14:10 +00:00
|
|
|
Prev->Common.Next = Op->Common.Next;
|
|
|
|
Next = NULL;
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
}
|
2004-12-01 23:14:10 +00:00
|
|
|
Prev = Next;
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
2004-12-01 23:14:10 +00:00
|
|
|
}
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
|
2004-12-01 23:14:10 +00:00
|
|
|
Cleanup:
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
/* Now we can actually delete the subtree rooted at Op */
|
|
|
|
|
|
|
|
AcpiPsDeleteParseTree (Op);
|
2009-06-01 21:02:40 +00:00
|
|
|
return_ACPI_STATUS (Status);
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: AcpiPsNextParseState
|
|
|
|
*
|
2005-11-01 22:11:18 +00:00
|
|
|
* PARAMETERS: WalkState - Current state
|
|
|
|
* Op - Current parse op
|
|
|
|
* CallbackStatus - Status from previous operation
|
2000-10-28 05:01:06 +00:00
|
|
|
*
|
2002-06-30 17:50:46 +00:00
|
|
|
* RETURN: Status
|
2000-10-28 05:01:06 +00:00
|
|
|
*
|
2002-06-30 17:50:46 +00:00
|
|
|
* DESCRIPTION: Update the parser state based upon the return exception from
|
|
|
|
* the parser callback.
|
2000-10-28 05:01:06 +00:00
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
2001-11-28 04:29:40 +00:00
|
|
|
ACPI_STATUS
|
2000-10-28 05:01:06 +00:00
|
|
|
AcpiPsNextParseState (
|
|
|
|
ACPI_WALK_STATE *WalkState,
|
|
|
|
ACPI_PARSE_OBJECT *Op,
|
|
|
|
ACPI_STATUS CallbackStatus)
|
|
|
|
{
|
2001-10-04 23:12:13 +00:00
|
|
|
ACPI_PARSE_STATE *ParserState = &WalkState->ParserState;
|
2000-10-28 05:01:06 +00:00
|
|
|
ACPI_STATUS Status = AE_CTRL_PENDING;
|
|
|
|
|
|
|
|
|
2007-03-22 17:24:05 +00:00
|
|
|
ACPI_FUNCTION_TRACE_PTR (PsNextParseState, Op);
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
switch (CallbackStatus)
|
|
|
|
{
|
|
|
|
case AE_CTRL_TERMINATE:
|
|
|
|
/*
|
|
|
|
* A control method was terminated via a RETURN statement.
|
|
|
|
* The walk of this method is complete.
|
|
|
|
*/
|
|
|
|
ParserState->Aml = ParserState->AmlEnd;
|
|
|
|
Status = AE_CTRL_TERMINATE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
2002-02-23 05:10:40 +00:00
|
|
|
case AE_CTRL_BREAK:
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2002-02-23 05:10:40 +00:00
|
|
|
ParserState->Aml = WalkState->AmlLastWhile;
|
|
|
|
WalkState->ControlState->Common.Value = FALSE;
|
|
|
|
Status = AE_CTRL_BREAK;
|
|
|
|
break;
|
|
|
|
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2007-03-22 17:24:05 +00:00
|
|
|
case AE_CTRL_CONTINUE:
|
2002-02-23 05:10:40 +00:00
|
|
|
|
|
|
|
ParserState->Aml = WalkState->AmlLastWhile;
|
|
|
|
Status = AE_CTRL_CONTINUE;
|
|
|
|
break;
|
|
|
|
|
2007-03-22 17:24:05 +00:00
|
|
|
|
2002-02-23 05:10:40 +00:00
|
|
|
case AE_CTRL_PENDING:
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
ParserState->Aml = WalkState->AmlLastWhile;
|
|
|
|
break;
|
|
|
|
|
2002-08-29 01:51:24 +00:00
|
|
|
#if 0
|
|
|
|
case AE_CTRL_SKIP:
|
|
|
|
|
|
|
|
ParserState->Aml = ParserState->Scope->ParseScope.PkgEnd;
|
|
|
|
Status = AE_OK;
|
|
|
|
break;
|
|
|
|
#endif
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
case AE_CTRL_TRUE:
|
2001-09-07 01:22:25 +00:00
|
|
|
/*
|
|
|
|
* Predicate of an IF was true, and we are at the matching ELSE.
|
|
|
|
* Just close out this package
|
|
|
|
*/
|
2002-02-23 05:10:40 +00:00
|
|
|
ParserState->Aml = AcpiPsGetNextPackageEnd (ParserState);
|
2007-03-22 17:24:05 +00:00
|
|
|
Status = AE_CTRL_PENDING;
|
2000-10-28 05:01:06 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case AE_CTRL_FALSE:
|
|
|
|
/*
|
|
|
|
* Either an IF/WHILE Predicate was false or we encountered a BREAK
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
ParserState->Aml = ParserState->Scope->ParseScope.PkgEnd;
|
|
|
|
|
|
|
|
/* In the case of a BREAK, just force a predicate (if any) to FALSE */
|
|
|
|
|
|
|
|
WalkState->ControlState->Common.Value = FALSE;
|
|
|
|
Status = AE_CTRL_END;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case AE_CTRL_TRANSFER:
|
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
/* A method call (invocation) -- transfer control */
|
|
|
|
|
2000-10-28 05:01:06 +00:00
|
|
|
Status = AE_CTRL_TRANSFER;
|
|
|
|
WalkState->PrevOp = Op;
|
|
|
|
WalkState->MethodCallOp = Op;
|
2002-07-09 17:51:31 +00:00
|
|
|
WalkState->MethodCallNode = (Op->Common.Value.Arg)->Common.Node;
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
/* Will return value (if any) be used by the caller? */
|
|
|
|
|
|
|
|
WalkState->ReturnUsed = AcpiDsIsResultUsed (Op, WalkState);
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
2005-11-01 22:11:18 +00:00
|
|
|
|
2000-10-28 05:01:06 +00:00
|
|
|
Status = CallbackStatus;
|
|
|
|
if ((CallbackStatus & AE_CODE_MASK) == AE_CODE_CONTROL)
|
|
|
|
{
|
|
|
|
Status = AE_OK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return_ACPI_STATUS (Status);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: AcpiPsParseAml
|
|
|
|
*
|
2005-11-01 22:11:18 +00:00
|
|
|
* PARAMETERS: WalkState - Current state
|
2000-10-28 05:01:06 +00:00
|
|
|
*
|
2001-09-07 01:22:25 +00:00
|
|
|
*
|
2000-10-28 05:01:06 +00:00
|
|
|
* RETURN: Status
|
|
|
|
*
|
|
|
|
* DESCRIPTION: Parse raw AML and return a tree of ops
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
ACPI_STATUS
|
|
|
|
AcpiPsParseAml (
|
2001-10-04 23:12:13 +00:00
|
|
|
ACPI_WALK_STATE *WalkState)
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
|
|
|
ACPI_STATUS Status;
|
2001-11-28 04:29:40 +00:00
|
|
|
ACPI_THREAD_STATE *Thread;
|
|
|
|
ACPI_THREAD_STATE *PrevWalkList = AcpiGbl_CurrentWalkList;
|
2001-10-04 23:12:13 +00:00
|
|
|
ACPI_WALK_STATE *PreviousWalkState;
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
|
2007-03-22 17:24:05 +00:00
|
|
|
ACPI_FUNCTION_TRACE (PsParseAml);
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
|
|
|
|
"Entered with WalkState=%p Aml=%p size=%X\n",
|
|
|
|
WalkState, WalkState->ParserState.Aml,
|
|
|
|
WalkState->ParserState.AmlSize));
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2009-06-01 21:02:40 +00:00
|
|
|
if (!WalkState->ParserState.Aml)
|
|
|
|
{
|
|
|
|
return_ACPI_STATUS (AE_NULL_OBJECT);
|
|
|
|
}
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2001-11-28 04:29:40 +00:00
|
|
|
/* Create and initialize a new thread state */
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2001-11-28 04:29:40 +00:00
|
|
|
Thread = AcpiUtCreateThreadState ();
|
|
|
|
if (!Thread)
|
|
|
|
{
|
2009-06-01 21:02:40 +00:00
|
|
|
if (WalkState->MethodDesc)
|
|
|
|
{
|
|
|
|
/* Executing a control method - additional cleanup */
|
|
|
|
|
|
|
|
AcpiDsTerminateControlMethod (WalkState->MethodDesc, WalkState);
|
|
|
|
}
|
|
|
|
|
2007-03-22 17:24:05 +00:00
|
|
|
AcpiDsDeleteWalkState (WalkState);
|
2001-11-28 04:29:40 +00:00
|
|
|
return_ACPI_STATUS (AE_NO_MEMORY);
|
|
|
|
}
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2001-11-28 04:29:40 +00:00
|
|
|
WalkState->Thread = Thread;
|
2007-03-22 17:24:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If executing a method, the starting SyncLevel is this method's
|
|
|
|
* SyncLevel
|
|
|
|
*/
|
|
|
|
if (WalkState->MethodDesc)
|
|
|
|
{
|
|
|
|
WalkState->Thread->CurrentSyncLevel = WalkState->MethodDesc->Method.SyncLevel;
|
|
|
|
}
|
|
|
|
|
2001-11-28 04:29:40 +00:00
|
|
|
AcpiDsPushWalkState (WalkState, Thread);
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2002-02-23 05:10:40 +00:00
|
|
|
/*
|
|
|
|
* This global allows the AML debugger to get a handle to the currently
|
|
|
|
* executing control method.
|
2000-10-28 05:01:06 +00:00
|
|
|
*/
|
2001-11-28 04:29:40 +00:00
|
|
|
AcpiGbl_CurrentWalkList = Thread;
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Execute the walk loop as long as there is a valid Walk State. This
|
|
|
|
* handles nested control method invocations without recursion.
|
|
|
|
*/
|
2001-08-26 22:28:18 +00:00
|
|
|
ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "State=%p\n", WalkState));
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2001-09-07 01:22:25 +00:00
|
|
|
Status = AE_OK;
|
2000-10-28 05:01:06 +00:00
|
|
|
while (WalkState)
|
|
|
|
{
|
|
|
|
if (ACPI_SUCCESS (Status))
|
|
|
|
{
|
2001-10-04 23:12:13 +00:00
|
|
|
/*
|
|
|
|
* The ParseLoop executes AML until the method terminates
|
|
|
|
* or calls another method.
|
|
|
|
*/
|
2000-10-28 05:01:06 +00:00
|
|
|
Status = AcpiPsParseLoop (WalkState);
|
|
|
|
}
|
|
|
|
|
2001-09-07 01:22:25 +00:00
|
|
|
ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
|
2003-04-29 18:39:29 +00:00
|
|
|
"Completed one call to walk loop, %s State=%p\n",
|
2002-11-27 18:07:48 +00:00
|
|
|
AcpiFormatException (Status), WalkState));
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
if (Status == AE_CTRL_TRANSFER)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* A method call was detected.
|
|
|
|
* Transfer control to the called control method
|
|
|
|
*/
|
2001-11-28 04:29:40 +00:00
|
|
|
Status = AcpiDsCallControlMethod (Thread, WalkState, NULL);
|
2007-03-22 17:24:05 +00:00
|
|
|
if (ACPI_FAILURE (Status))
|
|
|
|
{
|
|
|
|
Status = AcpiDsMethodError (Status, WalkState);
|
|
|
|
}
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the transfer to the new method method call worked, a new walk
|
|
|
|
* state was created -- get it
|
|
|
|
*/
|
2001-11-28 04:29:40 +00:00
|
|
|
WalkState = AcpiDsGetCurrentWalkState (Thread);
|
2000-10-28 05:01:06 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (Status == AE_CTRL_TERMINATE)
|
|
|
|
{
|
|
|
|
Status = AE_OK;
|
|
|
|
}
|
2004-12-01 23:14:10 +00:00
|
|
|
else if ((Status != AE_OK) && (WalkState->MethodDesc))
|
2002-11-27 18:07:48 +00:00
|
|
|
{
|
2007-03-22 17:24:05 +00:00
|
|
|
/* Either the method parse or actual execution failed */
|
2004-03-18 17:42:14 +00:00
|
|
|
|
2007-03-22 17:24:05 +00:00
|
|
|
ACPI_ERROR_METHOD ("Method parse/execution failed",
|
|
|
|
WalkState->MethodNode, NULL, Status);
|
2005-11-01 22:11:18 +00:00
|
|
|
|
2004-03-18 17:42:14 +00:00
|
|
|
/* Check for possible multi-thread reentrancy problem */
|
|
|
|
|
|
|
|
if ((Status == AE_ALREADY_EXISTS) &&
|
2011-01-13 16:12:34 +00:00
|
|
|
(!(WalkState->MethodDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED)))
|
2004-03-18 17:42:14 +00:00
|
|
|
{
|
|
|
|
/*
|
2011-01-13 16:12:34 +00:00
|
|
|
* 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.
|
2004-03-18 17:42:14 +00:00
|
|
|
*/
|
2011-01-13 16:12:34 +00:00
|
|
|
WalkState->MethodDesc->Method.InfoFlags |=
|
|
|
|
ACPI_METHOD_SERIALIZED_PENDING;
|
2004-03-18 17:42:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-28 05:01:06 +00:00
|
|
|
/* We are done with this walk, move on to the parent if any */
|
|
|
|
|
2001-11-28 04:29:40 +00:00
|
|
|
WalkState = AcpiDsPopWalkState (Thread);
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
/* Reset the current scope to the beginning of scope stack */
|
|
|
|
|
|
|
|
AcpiDsScopeStackClear (WalkState);
|
|
|
|
|
|
|
|
/*
|
2007-03-22 17:24:05 +00:00
|
|
|
* 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
|
2000-10-28 05:01:06 +00:00
|
|
|
*/
|
2007-03-22 17:24:05 +00:00
|
|
|
if (((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) == ACPI_PARSE_EXECUTE) ||
|
|
|
|
(ACPI_FAILURE (Status)))
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
2007-03-22 17:24:05 +00:00
|
|
|
AcpiDsTerminateControlMethod (WalkState->MethodDesc, WalkState);
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
2001-09-07 01:22:25 +00:00
|
|
|
/* Delete this walk state and all linked control states */
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2001-10-04 23:12:13 +00:00
|
|
|
AcpiPsCleanupScope (&WalkState->ParserState);
|
|
|
|
PreviousWalkState = WalkState;
|
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
|
|
|
|
"ReturnValue=%p, ImplicitValue=%p State=%p\n",
|
|
|
|
WalkState->ReturnDesc, WalkState->ImplicitReturnObj, WalkState));
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2001-09-07 01:22:25 +00:00
|
|
|
/* Check if we have restarted a preempted walk */
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2001-11-28 04:29:40 +00:00
|
|
|
WalkState = AcpiDsGetCurrentWalkState (Thread);
|
2001-10-04 23:12:13 +00:00
|
|
|
if (WalkState)
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
2001-10-04 23:12:13 +00:00
|
|
|
if (ACPI_SUCCESS (Status))
|
|
|
|
{
|
|
|
|
/*
|
2002-02-23 05:10:40 +00:00
|
|
|
* There is another walk state, restart it.
|
|
|
|
* If the method return value is not used by the parent,
|
2001-10-04 23:12:13 +00:00
|
|
|
* The object is deleted
|
|
|
|
*/
|
2005-11-01 22:11:18 +00:00
|
|
|
if (!PreviousWalkState->ReturnDesc)
|
|
|
|
{
|
2009-06-01 21:02:40 +00:00
|
|
|
/*
|
|
|
|
* In slack mode execution, if there is no return value
|
|
|
|
* we should implicitly return zero (0) as a default value.
|
|
|
|
*/
|
|
|
|
if (AcpiGbl_EnableInterpreterSlack &&
|
|
|
|
!PreviousWalkState->ImplicitReturnObj)
|
|
|
|
{
|
|
|
|
PreviousWalkState->ImplicitReturnObj =
|
2009-11-16 18:28:41 +00:00
|
|
|
AcpiUtCreateIntegerObject ((UINT64) 0);
|
2009-06-01 21:02:40 +00:00
|
|
|
if (!PreviousWalkState->ImplicitReturnObj)
|
|
|
|
{
|
|
|
|
return_ACPI_STATUS (AE_NO_MEMORY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Restart the calling control method */
|
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
Status = AcpiDsRestartControlMethod (WalkState,
|
|
|
|
PreviousWalkState->ImplicitReturnObj);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We have a valid return value, delete any implicit
|
|
|
|
* return value.
|
|
|
|
*/
|
|
|
|
AcpiDsClearImplicitReturn (PreviousWalkState);
|
|
|
|
|
|
|
|
Status = AcpiDsRestartControlMethod (WalkState,
|
|
|
|
PreviousWalkState->ReturnDesc);
|
|
|
|
}
|
2002-07-09 17:51:31 +00:00
|
|
|
if (ACPI_SUCCESS (Status))
|
|
|
|
{
|
|
|
|
WalkState->WalkType |= ACPI_WALK_METHOD_RESTART;
|
|
|
|
}
|
2002-02-23 05:10:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-06-01 21:02:40 +00:00
|
|
|
/* On error, delete any return object or implicit return */
|
2002-02-23 05:10:40 +00:00
|
|
|
|
|
|
|
AcpiUtRemoveReference (PreviousWalkState->ReturnDesc);
|
2009-06-01 21:02:40 +00:00
|
|
|
AcpiDsClearImplicitReturn (PreviousWalkState);
|
2001-10-04 23:12:13 +00:00
|
|
|
}
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Just completed a 1st-level method, save the final internal return
|
|
|
|
* value (if any)
|
|
|
|
*/
|
2001-10-04 23:12:13 +00:00
|
|
|
else if (PreviousWalkState->CallerReturnDesc)
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
2005-11-01 22:11:18 +00:00
|
|
|
if (PreviousWalkState->ImplicitReturnObj)
|
|
|
|
{
|
|
|
|
*(PreviousWalkState->CallerReturnDesc) =
|
|
|
|
PreviousWalkState->ImplicitReturnObj;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* NULL if no return value */
|
|
|
|
|
|
|
|
*(PreviousWalkState->CallerReturnDesc) =
|
|
|
|
PreviousWalkState->ReturnDesc;
|
|
|
|
}
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
2005-11-01 22:11:18 +00:00
|
|
|
else
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
2005-11-01 22:11:18 +00:00
|
|
|
if (PreviousWalkState->ReturnDesc)
|
|
|
|
{
|
|
|
|
/* Caller doesn't want it, must delete it */
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
AcpiUtRemoveReference (PreviousWalkState->ReturnDesc);
|
|
|
|
}
|
|
|
|
if (PreviousWalkState->ImplicitReturnObj)
|
|
|
|
{
|
|
|
|
/* Caller doesn't want it, must delete it */
|
|
|
|
|
|
|
|
AcpiUtRemoveReference (PreviousWalkState->ImplicitReturnObj);
|
|
|
|
}
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
2001-10-04 23:12:13 +00:00
|
|
|
|
|
|
|
AcpiDsDeleteWalkState (PreviousWalkState);
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Normal exit */
|
|
|
|
|
2001-11-28 04:29:40 +00:00
|
|
|
AcpiExReleaseAllMutexes (Thread);
|
2002-07-09 17:51:31 +00:00
|
|
|
AcpiUtDeleteGenericState (ACPI_CAST_PTR (ACPI_GENERIC_STATE, Thread));
|
2000-10-28 05:01:06 +00:00
|
|
|
AcpiGbl_CurrentWalkList = PrevWalkList;
|
|
|
|
return_ACPI_STATUS (Status);
|
|
|
|
}
|
|
|
|
|
|
|
|
|