/******************************************************************************
*
* Module Name: psargs - Parse AML opcode arguments
*
*****************************************************************************/
/*
* 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.
*/
#include "acpi.h"
#include "accommon.h"
#include "acparser.h"
#include "amlcode.h"
#include "acnamesp.h"
#include "acdispat.h"
ACPI_MODULE_NAME ("psargs")
/* Local prototypes */
static UINT32
static ACPI_PARSE_OBJECT *
/*******************************************************************************
*
* FUNCTION: AcpiPsGetNextPackageLength
*
* PARAMETERS: ParserState - Current parser state object
*
* RETURN: Decoded package length. On completion, the AML pointer points
* past the length byte or bytes.
*
* DESCRIPTION: Decode and return a package length field.
* Note: Largest package length is 28 bits, from ACPI specification
*
******************************************************************************/
static UINT32
{
/*
* Byte 0 bits [6:7] contain the number of additional bytes
* used to encode the package length, either 0,1,2, or 3
*/
/* Get bytes 3, 2, 1 as needed */
while (ByteCount)
{
/*
* Final bit positions for the package length bytes:
* Byte3->[20:27]
* Byte2->[12:19]
* Byte1->[04:11]
* Byte0->[00:03]
*/
ByteCount--;
}
/* Byte 0 is a special case, either bits [0:3] or [0:5] are used */
}
/*******************************************************************************
*
* FUNCTION: AcpiPsGetNextPackageEnd
*
* PARAMETERS: ParserState - Current parser state object
*
* RETURN: Pointer to end-of-package +1
*
* DESCRIPTION: Get next package length and return a pointer past the end of
* the package. Consumes the package length field
*
******************************************************************************/
UINT8 *
{
/* Function below updates ParserState->Aml */
}
/*******************************************************************************
*
* FUNCTION: AcpiPsGetNextNamestring
*
* PARAMETERS: ParserState - Current parser state object
*
* RETURN: Pointer to the start of the name string (pointer points into
* the AML.
*
* DESCRIPTION: Get next raw namestring within the AML stream. Handles all name
* prefix characters. Set parser state to point past the string.
* (Name is consumed from the AML.)
*
******************************************************************************/
char *
{
/* Point past any namestring prefix characters (backslash or carat) */
while (ACPI_IS_ROOT_PREFIX (*End) ||
{
End++;
}
/* Decode the path prefix character */
switch (*End)
{
case 0:
/* NullName */
{
}
End++;
break;
case AML_DUAL_NAME_PREFIX:
/* Two name segments */
break;
case AML_MULTI_NAME_PREFIX_OP:
/* Multiple name segments, 4 chars each, count in next byte */
break;
default:
/* Single name segment */
End += ACPI_NAME_SIZE;
break;
}
return_PTR ((char *) Start);
}
/*******************************************************************************
*
* FUNCTION: AcpiPsGetNextNamepath
*
* PARAMETERS: ParserState - Current parser state object
* Arg - Where the namepath will be stored
* ArgCount - If the namepath points to a control method
* the method's argument is returned here.
* PossibleMethodCall - Whether the namepath can possibly be the
* start of a method call
*
* RETURN: Status
*
* DESCRIPTION: Get next name (if method call, return # of required args).
* Names are looked up in the internal namespace to determine
* if the name represents a control method. If a method
* is found, the number of arguments to the method is returned.
* This information is critical for parsing to continue correctly.
*
******************************************************************************/
{
char *Path;
/* Null path case is allowed, just exit */
if (!Path)
{
}
/*
* Lookup the name in the internal namespace, starting with the current
* scope. We don't want to add anything new to the namespace here,
* however, so we use MODE_EXECUTE.
* Allow searching of the parent tree, but don't open a new scope -
* we just want to lookup the object (must be mode EXECUTE to perform
* the upsearch)
*/
/*
* If this name is a control method invocation, we must
* setup the method call
*/
if (ACPI_SUCCESS (Status) &&
{
{
/*
* AcpiPsGetNextNamestring has increased the AML pointer,
* so we need to restore the saved AML pointer for method call.
*/
}
/* This name is actually a control method invocation */
if (!NameOp)
{
}
/* Change Arg into a METHOD CALL and attach name to it */
/* Point METHODCALL/NAME to the METHOD Node */
if (!MethodDesc)
{
"Control Method %p has no attached object",
Node));
}
"Control Method - %p Args %X\n",
/* Get the number of arguments to expect */
}
/*
* Special handling if the name was not found during the lookup -
* some NotFound cases are allowed
*/
if (Status == AE_NOT_FOUND)
{
/* 1) NotFound is ok during load pass 1/2 (allow forward references) */
{
}
/* 2) NotFound during a CondRefOf(x) is ok by definition */
{
}
/*
* 3) NotFound while building a Package is ok at this point, we
* may flag as an error later if slack mode is not enabled.
* (Some ASL code depends on allowing this behavior)
*/
{
}
}
/* Final exception check (may have been changed from code above) */
if (ACPI_FAILURE (Status))
{
{
/* Report a control method execution error */
}
}
/* Save the namepath */
}
/*******************************************************************************
*
* FUNCTION: AcpiPsGetNextSimpleArg
*
* PARAMETERS: ParserState - Current parser state object
* ArgType - The argument type (AML_*_ARG)
* Arg - Where the argument is returned
*
* RETURN: None
*
* DESCRIPTION: Get the next simple argument (constant, string, or namestring)
*
******************************************************************************/
void
{
switch (ArgType)
{
case ARGP_BYTEDATA:
/* Get 1 byte from the AML stream */
Length = 1;
break;
case ARGP_WORDDATA:
/* Get 2 bytes from the AML stream */
Length = 2;
break;
case ARGP_DWORDDATA:
/* Get 4 bytes from the AML stream */
Length = 4;
break;
case ARGP_QWORDDATA:
/* Get 8 bytes from the AML stream */
Length = 8;
break;
case ARGP_CHARLIST:
/* Get a pointer to the string, point past the string */
/* Find the null terminator */
Length = 0;
{
Length++;
}
Length++;
break;
case ARGP_NAME:
case ARGP_NAMESTRING:
default:
}
}
/*******************************************************************************
*
* FUNCTION: AcpiPsGetNextField
*
* PARAMETERS: ParserState - Current parser state object
*
* RETURN: A newly allocated FIELD op
*
* DESCRIPTION: Get next field (NamedField, ReservedField, or AccessField)
*
******************************************************************************/
static ACPI_PARSE_OBJECT *
{
/* Determine field type */
{
case AML_FIELD_OFFSET_OP:
ParserState->Aml++;
break;
case AML_FIELD_ACCESS_OP:
ParserState->Aml++;
break;
case AML_FIELD_CONNECTION_OP:
ParserState->Aml++;
break;
case AML_FIELD_EXT_ACCESS_OP:
ParserState->Aml++;
break;
default:
break;
}
/* Allocate a new field op */
if (!Field)
{
return_PTR (NULL);
}
/* Decode the field type */
switch (Opcode)
{
case AML_INT_NAMEDFIELD_OP:
/* Get the 4-character name */
/* Get the length which is encoded as a package length */
break;
case AML_INT_RESERVEDFIELD_OP:
/* Get the length which is encoded as a package length */
break;
case AML_INT_ACCESSFIELD_OP:
/*
* Get AccessType and AccessAttrib and merge into the field Op
* AccessType is first operand, AccessAttribute is second. stuff
* these bytes into the node integer value for convenience.
*/
ParserState->Aml++;
ParserState->Aml++;
/* This opcode has a third byte, AccessLength */
if (Opcode == AML_INT_EXTACCESSFIELD_OP)
{
ParserState->Aml++;
}
break;
case AML_INT_CONNECTION_OP:
/*
* Argument for Connection operator can be either a Buffer
* (resource descriptor), or a NameString.
*/
{
ParserState->Aml++;
{
/* Non-empty list */
if (!Arg)
{
return_PTR (NULL);
}
/* Get the actual buffer length argument */
ParserState->Aml++;
switch (Opcode)
{
case AML_BYTE_OP: /* AML_BYTEDATA_ARG */
break;
case AML_WORD_OP: /* AML_WORDDATA_ARG */
break;
case AML_DWORD_OP: /* AML_DWORDATA_ARG */
break;
default:
BufferLength = 0;
break;
}
/* Fill in bytelist data */
}
/* Skip to End of byte data */
}
else
{
if (!Arg)
{
return_PTR (NULL);
}
/* Get the Namestring argument */
}
/* Link the buffer/namestring to parent (CONNECTION_OP) */
break;
default:
/* Opcode was set in previous switch */
break;
}
return_PTR (Field);
}
/*******************************************************************************
*
* FUNCTION: AcpiPsGetNextArg
*
* PARAMETERS: WalkState - Current state
* ParserState - Current parser state object
* ArgType - The argument type (AML_*_ARG)
* ReturnArg - Where the next arg is returned
*
* RETURN: Status, and an op object containing the next argument.
*
* DESCRIPTION: Get next argument (including complex list arguments that require
* pushing the parser stack)
*
******************************************************************************/
{
switch (ArgType)
{
case ARGP_BYTEDATA:
case ARGP_WORDDATA:
case ARGP_DWORDDATA:
case ARGP_CHARLIST:
case ARGP_NAME:
case ARGP_NAMESTRING:
/* Constants, strings, and namestrings are all the same size */
if (!Arg)
{
}
break;
case ARGP_PKGLENGTH:
/* Package length, nothing returned */
break;
case ARGP_FIELDLIST:
{
/* Non-empty list */
{
if (!Field)
{
}
if (Prev)
{
}
else
{
}
}
/* Skip to End of byte data */
}
break;
case ARGP_BYTELIST:
{
/* Non-empty list */
ParserState->Aml);
if (!Arg)
{
}
/* Fill in bytelist data */
/* Skip to End of byte data */
}
break;
case ARGP_TARGET:
case ARGP_SUPERNAME:
case ARGP_SIMPLENAME:
case ARGP_NAME_OR_REF:
if (Subop == 0 ||
AcpiPsIsLeadingChar (Subop) ||
ACPI_IS_ROOT_PREFIX (Subop) ||
{
/* NullName or NameString */
if (!Arg)
{
}
/* To support SuperName arg of Unload */
{
/*
* If the SuperName argument is a method call, we have
* already restored the AML pointer, just free this Arg
*/
{
AcpiPsFreeOp (Arg);
}
}
else
{
}
}
else
{
/* Single complex argument, nothing returned */
}
break;
case ARGP_DATAOBJ:
case ARGP_TERMARG:
/* Single complex argument, nothing returned */
break;
case ARGP_DATAOBJLIST:
case ARGP_TERMLIST:
case ARGP_OBJLIST:
{
/* Non-empty list of variable arguments, nothing returned */
}
break;
default:
break;
}
}