/******************************************************************************
*
* Module Name: psparse - Parser top level AML parse routines
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2005, R. Byron Moore
* 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 aml_op_info[]
*/
#include <acpi/acpi.h>
#include <acpi/acparser.h>
#include <acpi/acdispat.h>
#include <acpi/amlcode.h>
#include <acpi/acnamesp.h>
#include <acpi/acinterp.h>
#define _COMPONENT ACPI_PARSER
ACPI_MODULE_NAME ("psparse")
static u32 acpi_gbl_depth = 0;
/*******************************************************************************
*
* FUNCTION: acpi_ps_get_opcode_size
*
* PARAMETERS: Opcode - An AML opcode
*
* RETURN: Size of the opcode, in bytes (1 or 2)
*
* DESCRIPTION: Get the size of the current opcode.
*
******************************************************************************/
u32
acpi_ps_get_opcode_size (
u32 opcode)
{
/* Extended (2-byte) opcode if > 255 */
if (opcode > 0x00FF) {
return (2);
}
/* Otherwise, just a single byte opcode */
return (1);
}
/*******************************************************************************
*
* FUNCTION: acpi_ps_peek_opcode
*
* PARAMETERS: parser_state - A parser state object
*
* RETURN: Status
*
* DESCRIPTION: Get next AML opcode (without incrementing AML pointer)
*
******************************************************************************/
u16
acpi_ps_peek_opcode (
struct acpi_parse_state *parser_state)
{
u8 *aml;
u16 opcode;
aml = parser_state->aml;
opcode = (u16) ACPI_GET8 (aml);
if (opcode == AML_EXTOP) {
/* Extended opcode */
aml++;
opcode = (u16) ((opcode << 8) | ACPI_GET8 (aml));
}
return (opcode);
}
/*******************************************************************************
*
* FUNCTION: acpi_ps_complete_this_op
*
* PARAMETERS: walk_state - Current State
* Op - Op to complete
*
* RETURN: None.
*
* DESCRIPTION: Perform any cleanup at the completion of an Op.
*
******************************************************************************/
void
acpi_ps_complete_this_op (
struct acpi_walk_state *walk_state,
union acpi_parse_object *op)
{
union acpi_parse_object *prev;
union acpi_parse_object *next;
const struct acpi_opcode_info *parent_info;
union acpi_parse_object *replacement_op = NULL;
ACPI_FUNCTION_TRACE_PTR ("ps_complete_this_op", op);
/* Check for null Op, can happen if AML code is corrupt */
if (!op) {
return_VOID;
}
/* Delete this op and the subtree below it if asked to */
if (((