dmwalk.c revision 199767f8919635c4928607450d9e0abb932109ce
/*******************************************************************************
*
* Module Name: dmwalk - AML disassembly tree walk
*
******************************************************************************/
/*
* 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_CA_DEBUGGER
ACPI_MODULE_NAME ("dmwalk")
#define DB_FULL_OP_INFO "[%4.4s] @%5.5X #%4.4X: "
/* Stub for non-compiler code */
#ifndef ACPI_ASL_COMPILER
void
void)
{
return;
}
#endif
/* Local prototypes */
static ACPI_STATUS
void *Context);
static ACPI_STATUS
void *Context);
static UINT32
/*******************************************************************************
*
* FUNCTION: AcpiDmDisassemble
*
* PARAMETERS: WalkState - Current state
* Origin - Starting object
* NumOpcodes - Max number of opcodes to be displayed
*
* RETURN: None
*
* DESCRIPTION: Disassemble parser object and its children. This is the
* main entry point of the disassembler.
*
******************************************************************************/
void
{
if (!Op)
{
return;
}
return;
}
/*******************************************************************************
*
* FUNCTION: AcpiDmWalkParseTree
*
* PARAMETERS: Op - Root Op object
* DescendingCallback - Called during tree descent
* AscendingCallback - Called during tree ascent
* Context - To be passed to the callbacks
*
* RETURN: Status from callback(s)
*
* DESCRIPTION: Walk the entire parse tree.
*
******************************************************************************/
void
void *Context)
{
while (Op)
{
{
if (AscendingCallback)
{
if (ACPI_FAILURE (Status))
{
return;
}
}
}
else
{
/* Let the callback process the node */
if (ACPI_SUCCESS (Status))
{
/* Visit children first, once */
if (Next)
{
continue;
}
}
else if (Status != AE_CTRL_DEPTH)
{
/* Exit immediately on any error */
return;
}
}
/* Terminate walk at start op */
{
break;
}
/* No more children, re-visit this node */
if (!NodePreviouslyVisited)
{
continue;
}
/* No more children, visit peers */
{
}
else
{
/* No peers, re-visit parent */
{
}
}
}
/* If we get here, the walk completed with no errors */
return;
}
/*******************************************************************************
*
* FUNCTION: AcpiDmBlockType
*
* PARAMETERS: Op - Object to be examined
*
* RETURN: BlockType - not a block, parens, braces, or even both.
*
* DESCRIPTION: Type of block for this op (parens or braces)
*
******************************************************************************/
static UINT32
{
const ACPI_OPCODE_INFO *OpInfo;
if (!Op)
{
return (BLOCK_NONE);
}
{
case AML_ELSE_OP:
return (BLOCK_BRACE);
case AML_METHOD_OP:
case AML_DEVICE_OP:
case AML_SCOPE_OP:
case AML_PROCESSOR_OP:
case AML_POWER_RES_OP:
case AML_THERMAL_ZONE_OP:
case AML_IF_OP:
case AML_WHILE_OP:
case AML_FIELD_OP:
case AML_INDEX_FIELD_OP:
case AML_BANK_FIELD_OP:
return (BLOCK_PAREN | BLOCK_BRACE);
case AML_BUFFER_OP:
{
return (BLOCK_NONE);
}
/*lint -fallthrough */
case AML_PACKAGE_OP:
case AML_VAR_PACKAGE_OP:
return (BLOCK_PAREN | BLOCK_BRACE);
case AML_EVENT_OP:
return (BLOCK_PAREN);
case AML_INT_METHODCALL_OP:
{
/* This is a reference to a method, not an invocation */
return (BLOCK_NONE);
}
/*lint -fallthrough */
default:
{
return (BLOCK_PAREN);
}
return (BLOCK_NONE);
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmListType
*
* PARAMETERS: Op - Object to be examined
*
* RETURN: ListType - has commas or not.
*
* DESCRIPTION: Type of block for this op (parens or braces)
*
******************************************************************************/
{
const ACPI_OPCODE_INFO *OpInfo;
if (!Op)
{
return (BLOCK_NONE);
}
{
case AML_ELSE_OP:
case AML_METHOD_OP:
case AML_DEVICE_OP:
case AML_SCOPE_OP:
case AML_POWER_RES_OP:
case AML_PROCESSOR_OP:
case AML_THERMAL_ZONE_OP:
case AML_IF_OP:
case AML_WHILE_OP:
case AML_FIELD_OP:
case AML_INDEX_FIELD_OP:
case AML_BANK_FIELD_OP:
return (BLOCK_NONE);
case AML_BUFFER_OP:
case AML_PACKAGE_OP:
case AML_VAR_PACKAGE_OP:
return (BLOCK_COMMA_LIST);
default:
{
return (BLOCK_COMMA_LIST);
}
return (BLOCK_NONE);
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmDescendingOp
*
* PARAMETERS: ASL_WALK_CALLBACK
*
* RETURN: Status
*
* DESCRIPTION: First visitation of a parse object during tree descent.
* Decode opcode name and begin parameter list(s), if any.
*
******************************************************************************/
static ACPI_STATUS
void *Context)
{
const ACPI_OPCODE_INFO *OpInfo;
/* Listing support to dump the AML code after the ASL statement */
{
/* We only care about these classes of objects */
{
{
/* Dump the AML byte code for the previous Op */
{
AcpiOsPrintf ("\n");
AcpiOsPrintf ("\n");
}
}
}
}
{
/* Ignore this op -- it was handled elsewhere */
return (AE_CTRL_DEPTH);
}
/* Level 0 is at the Definition Block level */
if (Level == 0)
{
/* In verbose mode, print the AML offset, opcode and depth count */
{
{
}
}
{
/* This is the beginning of the Definition Block */
AcpiOsPrintf ("{\n");
/* Emit all External() declarations here */
return (AE_OK);
}
}
{
/*
* This is a first-level element of a term list,
* indent a new line
*/
{
case AML_NOOP_OP:
/*
* Optionally just ignore this opcode. Some tables use
* NoOp opcodes for "padding" out packages that the BIOS
* changes dynamically. This can leave hundreds or
* thousands of NoOp opcodes that if disassembled,
* cannot be compiled because they are syntactically
* incorrect.
*/
{
return (AE_OK);
}
/* Fallthrough */
default:
break;
}
}
/*
* This is an inexpensive mechanism to try and keep lines from getting
* too long. When the limit is hit, start a new line at the previous
* indent plus one. A better but more expensive mechanism would be to
* keep track of the current column.
*/
{
AcpiOsPrintf ("\n");
}
/* If ASL+ is enabled, check for a C-style operator */
{
return (AE_OK);
}
/* Print the opcode name */
{
return (AE_OK);
}
{
}
/* Start the opcode argument list if necessary */
{
/* This opcode has an argument list */
{
AcpiOsPrintf (" (");
}
/* If this is a named opcode, print the associated name value */
{
{
case AML_ALIAS_OP:
AcpiOsPrintf (", ");
/*lint -fallthrough */
default:
{
}
else
{
}
{
{
}
}
break;
}
{
case AML_METHOD_OP:
AcpiOsPrintf (")");
/* Emit description comment for Method() with a predefined ACPI name */
break;
case AML_NAME_OP:
/* Check for _HID and related EISAID() */
AcpiOsPrintf (", ");
break;
case AML_REGION_OP:
break;
case AML_POWER_RES_OP:
/* Mark the next two Ops as part of the parameter list */
AcpiOsPrintf (", ");
return (AE_OK);
case AML_PROCESSOR_OP:
/* Mark the next three Ops as part of the parameter list */
AcpiOsPrintf (", ");
return (AE_OK);
case AML_MUTEX_OP:
case AML_DATA_REGION_OP:
AcpiOsPrintf (", ");
return (AE_OK);
case AML_EVENT_OP:
case AML_ALIAS_OP:
return (AE_OK);
case AML_SCOPE_OP:
case AML_DEVICE_OP:
case AML_THERMAL_ZONE_OP:
AcpiOsPrintf (")");
break;
default:
AcpiOsPrintf ("*** Unhandled named opcode %X\n",
break;
}
}
{
case AML_FIELD_OP:
case AML_BANK_FIELD_OP:
case AML_INDEX_FIELD_OP:
/* Name of the parent OperationRegion */
AcpiOsPrintf (", ");
{
case AML_BANK_FIELD_OP:
/* Namestring - Bank Name */
AcpiOsPrintf (", ");
/*
* Bank Value. This is a TermArg in the middle of the parameter
* list, must handle it here.
*
* Disassemble the TermArg parse tree. ACPI_PARSEOP_PARAMLIST
* eliminates newline in the output.
*/
AcpiOsPrintf (", ");
break;
case AML_INDEX_FIELD_OP:
/* Namestring - Data Name */
AcpiOsPrintf (", ");
break;
default:
break;
}
break;
case AML_BUFFER_OP:
/* The next op is the size parameter */
if (!NextOp)
{
/* Single-step support */
return (AE_OK);
}
{
/*
* We have a resource list. Don't need to output
* the buffer size Op. Open up a new block
*/
AcpiOsPrintf (")");
/* Emit description comment for Name() with a predefined ACPI name */
AcpiOsPrintf ("\n");
AcpiOsPrintf ("{\n");
return (AE_OK);
}
/* Normal Buffer, mark size as in the parameter list */
return (AE_OK);
case AML_VAR_PACKAGE_OP:
case AML_IF_OP:
case AML_WHILE_OP:
/* The next op is the size or predicate parameter */
if (NextOp)
{
}
return (AE_OK);
case AML_PACKAGE_OP:
/* The next op is the size parameter */
if (NextOp)
{
}
return (AE_OK);
case AML_MATCH_OP:
AcpiDmMatchOp (Op);
break;
default:
break;
}
{
AcpiOsPrintf ("\n");
AcpiOsPrintf ("{\n");
}
}
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiDmAscendingOp
*
* PARAMETERS: ASL_WALK_CALLBACK
*
* RETURN: Status
*
* DESCRIPTION: Second visitation of a parse object, during ascent of parse
* tree. Close out any parameter lists and complete the opcode.
*
******************************************************************************/
static ACPI_STATUS
void *Context)
{
{
/* Ignore this op -- it was handled elsewhere */
return (AE_OK);
}
{
/* Indicates the end of the current descriptor block (table) */
AcpiOsPrintf ("}\n\n");
return (AE_OK);
}
switch (AcpiDmBlockType (Op))
{
case BLOCK_PAREN:
/* Completed an op that has arguments, add closing paren if needed */
{
/* Emit description comment for Name() with a predefined ACPI name */
}
else
{
/* For Create* operators, attempt to emit resource tag description */
}
/* Decode Notify() values */
{
}
/* Could be a nested operator, check if comma required */
if (!AcpiDmCommaIfListMember (Op))
{
{
/*
* This is a first-level element of a term list
* start a new line
*/
{
AcpiOsPrintf ("\n");
}
}
}
break;
case BLOCK_BRACE:
case (BLOCK_BRACE | BLOCK_PAREN):
/* Completed an op that has a term list, add closing brace */
{
AcpiOsPrintf ("}");
}
else
{
AcpiOsPrintf ("}");
}
{
AcpiOsPrintf ("\n");
{
{
break;
}
{
break;
}
AcpiOsPrintf ("\n");
}
}
break;
case BLOCK_NONE:
default:
/* Could be a nested operator, check if comma required */
if (!AcpiDmCommaIfListMember (Op))
{
{
/*
* This is a first-level element of a term list
* start a new line
*/
AcpiOsPrintf ("\n");
}
}
{
{
case AML_PACKAGE_OP:
case AML_VAR_PACKAGE_OP:
{
AcpiOsPrintf ("\n");
}
break;
default:
break;
}
}
break;
}
{
{
return (AE_OK);
}
/*
* The parent Op is guaranteed to be valid because of the flag
* ACPI_PARSEOP_PARAMLIST -- which means that this op is part of
* a parameter list and thus has a valid parent.
*/
/*
* Just completed a parameter node for something like "Buffer (param)".
* Close the paren and open up the term list block with a brace
*/
{
AcpiOsPrintf (")");
/*
* Emit a description comment for a Name() operator that is a
* predefined ACPI name. Must check the grandparent.
*/
if (ParentOp &&
{
}
AcpiOsPrintf ("\n");
AcpiOsPrintf ("{\n");
}
else
{
AcpiOsPrintf (") {");
}
}
{
}
/*
* For ASL+, check for and emit a C-style symbol. If valid, the
* symbol string has been deferred until after the first operand
*/
{
{
}
}
return (AE_OK);
}