adwalk.c revision 199767f8919635c4928607450d9e0abb932109ce
/******************************************************************************
*
* Module Name: adwalk - Application-level disassembler parse tree walk routines
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2015, 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.
*/
#define _COMPONENT ACPI_TOOLS
ACPI_MODULE_NAME ("adwalk")
/*
* aslmap - opcode mappings and reserved method names
*/
/* Local prototypes */
static ACPI_STATUS
void *Context);
static ACPI_STATUS
void *Context);
static ACPI_STATUS
void *Context);
static ACPI_STATUS
void *Context);
static ACPI_STATUS
void *Context);
static UINT32
static ACPI_STATUS
void *Context);
/*******************************************************************************
*
* FUNCTION: AcpiDmDumpTree
*
* PARAMETERS: Origin - Starting object
*
* RETURN: None
*
* DESCRIPTION: Parse tree walk to format and output the nodes
*
******************************************************************************/
void
{
if (!Origin)
{
return;
}
AcpiOsPrintf ("/*\nAML Parse Tree\n\n");
AcpiOsPrintf ("*/\n\n");
}
/*******************************************************************************
*
* FUNCTION: AcpiDmFindOrphanMethods
*
* PARAMETERS: Origin - Starting object
*
* RETURN: None
*
* DESCRIPTION: Parse tree walk to find "orphaned" method invocations -- methods
* that are not resolved in the namespace
*
******************************************************************************/
void
{
if (!Origin)
{
return;
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmFinishNamespaceLoad
*
* PARAMETERS: ParseTreeRoot - Root of the parse tree
* NamespaceRoot - Root of the internal namespace
* OwnerId - OwnerId of the table to be disassembled
*
* RETURN: None
*
* DESCRIPTION: Load all namespace items that are created within control
* methods. Used before namespace cross reference
*
******************************************************************************/
void
{
if (!ParseTreeRoot)
{
return;
}
/* Create and initialize a new walk state */
if (!WalkState)
{
return;
}
if (ACPI_FAILURE (Status))
{
return;
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmCrossReferenceNamespace
*
* PARAMETERS: ParseTreeRoot - Root of the parse tree
* NamespaceRoot - Root of the internal namespace
* OwnerId - OwnerId of the table to be disassembled
*
* RETURN: None
*
* DESCRIPTION: Cross reference the namespace to create externals
*
******************************************************************************/
void
{
if (!ParseTreeRoot)
{
return;
}
/* Create and initialize a new walk state */
if (!WalkState)
{
return;
}
if (ACPI_FAILURE (Status))
{
return;
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmConvertResourceIndexes
*
* PARAMETERS: ParseTreeRoot - Root of the parse tree
* NamespaceRoot - Root of the internal namespace
*
* RETURN: None
*
* DESCRIPTION: Convert fixed-offset references to resource descriptors to
* symbolic references. Should only be called after namespace has
* been cross referenced.
*
******************************************************************************/
void
{
if (!ParseTreeRoot)
{
return;
}
/* Create and initialize a new walk state */
if (!WalkState)
{
return;
}
if (ACPI_FAILURE (Status))
{
return;
}
return;
}
/*******************************************************************************
*
* FUNCTION: AcpiDmDumpDescending
*
* PARAMETERS: ASL_WALK_CALLBACK
*
* RETURN: Status
*
* DESCRIPTION: Format and print contents of one parse Op.
*
******************************************************************************/
static ACPI_STATUS
void *Context)
{
char *Path;
if (!Op)
{
return (AE_OK);
}
/* Most of the information (count, level, name) here */
/* Extra info is helpful */
{
case AML_BYTE_OP:
break;
case AML_WORD_OP:
break;
case AML_DWORD_OP:
break;
case AML_QWORD_OP:
break;
case AML_INT_NAMEPATH_OP:
{
}
else
{
AcpiOsPrintf ("[NULL]");
}
break;
case AML_NAME_OP:
case AML_METHOD_OP:
case AML_DEVICE_OP:
case AML_INT_NAMEDFIELD_OP:
break;
default:
break;
}
AcpiOsPrintf ("\n");
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiDmFindOrphanDescending
*
* PARAMETERS: ASL_WALK_CALLBACK
*
* RETURN: Status
*
* DESCRIPTION: Check namepath Ops for orphaned method invocations
*
* Note: Experimental.
*
******************************************************************************/
static ACPI_STATUS
void *Context)
{
const ACPI_OPCODE_INFO *OpInfo;
if (!Op)
{
return (AE_OK);
}
{
#ifdef ACPI_UNDER_DEVELOPMENT
case AML_ADD_OP:
{
AcpiOsPrintf ("/* %-16s A-NAMEPATH: %s */\n",
if (!NextOp)
{
/* This NamePath has no args, assume it is an integer */
return (AE_OK);
}
AcpiOsPrintf ("/* A-CHILDREN: %u Actual %u */\n",
if (ArgCount < 1)
{
/* One Arg means this is just a Store(Name,Target) */
return (AE_OK);
}
}
break;
#endif
case AML_STORE_OP:
{
if (!NextOp)
{
/* This NamePath has no args, assume it is an integer */
return (AE_OK);
}
if (ArgCount <= 1)
{
/* One Arg means this is just a Store(Name,Target) */
return (AE_OK);
}
}
break;
case AML_INT_NAMEPATH_OP:
/* Must examine parent to see if this namepath is an argument */
{
/*
* a return.
*/
if (ArgCount == 0)
{
/* And namepath is the first argument */
{
break;
}
}
/*
* This is a standalone namestring (not a parameter to another
* operator) - it *must* be a method invocation, nothing else is
* grammatically possible.
*/
}
break;
default:
break;
}
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiDmLoadDescendingOp
*
* PARAMETERS: ASL_WALK_CALLBACK
*
* RETURN: Status
*
* DESCRIPTION: Descending handler for namespace control method object load
*
******************************************************************************/
static ACPI_STATUS
void *Context)
{
const ACPI_OPCODE_INFO *OpInfo;
char FieldPath[5];
UINT8 PreDefineIndex = 0;
/* Only interested in operators that create new names */
{
goto Exit;
}
/* Get the NamePath from the appropriate place */
{
/* For all named operators, get the new name */
{
FieldPath[4] = 0;
}
}
{
/* New name is the last child */
{
}
}
if (!Path)
{
goto Exit;
}
/* Insert the name into the namespace */
if (ACPI_SUCCESS (Status))
{
/* Check if it's a predefined node */
{
{
PreDefined = TRUE;
break;
}
}
/*
* Set node owner id if it satisfies all the following conditions:
* 1) Not a predefined node, _SB_ etc
* 2) Not the root node
* 3) Not a node created by Scope
*/
{
}
}
Exit:
if (AcpiNsOpensScope (ObjectType))
{
{
if (ACPI_FAILURE (Status))
{
return (Status);
}
}
}
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiDmXrefDescendingOp
*
* PARAMETERS: ASL_WALK_CALLBACK
*
* RETURN: Status
*
* DESCRIPTION: Descending handler for namespace cross reference
*
******************************************************************************/
static ACPI_STATUS
void *Context)
{
const ACPI_OPCODE_INFO *OpInfo;
UINT32 ParamCount = 0;
char *Pathname;
{
goto Exit;
}
/* Get the NamePath from the appropriate place */
{
/*
* Only these two operators (Alias, Scope) refer to an existing
* name, it is the first argument
*/
{
{
}
}
{
}
}
{
/* Referenced Buffer Name is the first child */
{
}
}
{
}
else
{
}
if (!Path)
{
goto Exit;
}
/*
* Lookup the name in the namespace. Name must exist at this point, or it
* is an invalid reference.
*
* The namespace is also used as a lookup table for references to resource
* descriptors and the fields within them.
*/
{
/* Node was created by an External() statement */
}
if (ACPI_FAILURE (Status))
{
if (Status == AE_NOT_FOUND)
{
/*
* Add this symbol as an external declaration, except if the
* parent is a CondRefOf operator. For this operator, we do not
* need an external, nor do we want one, since this can cause
* disassembly problems if the symbol is actually a control
* method.
*/
{
if (Node)
{
(UINT8) ObjectType, 0, 0);
}
else
{
(UINT8) ObjectType, 0, 0);
}
}
}
}
/*
* Found the node, but check if it came from an external table.
* Add it to external list. Note: Node->OwnerId == 0 indicates
* one of the built-in ACPI Names (_OS_ etc.) which can safely
* be ignored.
*/
{
if (Object)
{
if (ObjectType2 == ACPI_TYPE_METHOD)
{
}
}
if (!Pathname)
{
return (AE_NO_MEMORY);
}
}
else
{
}
Exit:
/* Open new scope if necessary */
if (AcpiNsOpensScope (ObjectType))
{
{
if (ACPI_FAILURE (Status))
{
return (Status);
}
}
}
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiDmResourceDescendingOp
*
* PARAMETERS: ASL_WALK_CALLBACK
*
* RETURN: None
*
* DESCRIPTION: Process one parse op during symbolic resource index conversion.
*
******************************************************************************/
static ACPI_STATUS
void *Context)
{
const ACPI_OPCODE_INFO *OpInfo;
/* Open new scope if necessary */
if (AcpiNsOpensScope (ObjectType))
{
{
if (ACPI_FAILURE (Status))
{
return (Status);
}
}
}
/*
* Check if this operator contains a reference to a resource descriptor.
* If so, convert the reference into a symbolic reference.
*/
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiDmCommonAscendingOp
*
* PARAMETERS: ASL_WALK_CALLBACK
*
* RETURN: None
*
* scope if necessary.
*
******************************************************************************/
static ACPI_STATUS
void *Context)
{
const ACPI_OPCODE_INFO *OpInfo;
/* Close scope if necessary */
if (AcpiNsOpensScope (ObjectType))
{
}
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiDmInspectPossibleArgs
*
* PARAMETERS: CurrentOpArgCount - Which arg of the current op was the
* possible method invocation found
* TargetCount - Number of targets (0,1,2) for this op
* Op - Parse op
*
* RETURN: Status
*
* DESCRIPTION: Examine following args and next ops for possible arguments
* for an unrecognized method invocation.
*
******************************************************************************/
static UINT32
{
const ACPI_OPCODE_INFO *OpInfo;
UINT32 i;
/* Lookahead for the maximum number of possible arguments */
for (i = 0; i < Lookahead; i++)
{
if (!Op)
{
break;
}
/*
* Any one of these operators is "very probably" not a method arg
*/
{
break;
}
{
Last = i+1;
}
}
return (Last);
}