dmopcode.c revision 7b1019a6d29ccb7999dc76cba3dde1c627e8e609
/*******************************************************************************
*
* Module Name: dmopcode - AML disassembler, specific AML opcodes
*
******************************************************************************/
/*
* 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 "acinterp.h"
#include "acnamesp.h"
#include "acdebug.h"
#define _COMPONENT ACPI_CA_DEBUGGER
ACPI_MODULE_NAME ("dmopcode")
/* Local prototypes */
static void
static void
/*******************************************************************************
*
* FUNCTION: AcpiDmDisplayTargetPathname
*
* PARAMETERS: Op - Parse object
*
* RETURN: None
*
* DESCRIPTION: For AML opcodes that have a target operand, display the full
* pathname for the target, in a comment field. Handles Return()
* statements also.
*
******************************************************************************/
void
{
char *Pathname;
const ACPI_OPCODE_INFO *OpInfo;
{
}
else
{
{
return;
}
/* Target is the last Op in the arg list */
while (NextOp)
{
}
}
if (!PrevOp)
{
return;
}
/* We must have a namepath AML opcode */
{
return;
}
/* A null string is the "no target specified" case */
{
return;
}
/* No node means "unresolved external reference" */
{
AcpiOsPrintf (" /* External reference */");
return;
}
/* Ignore if path is already from the root */
{
return;
}
/* Now: we can get the full pathname */
if (!Pathname)
{
return;
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmNotifyDescription
*
* PARAMETERS: Op - Name() parse object
*
* RETURN: None
*
* DESCRIPTION: Emit a description comment for the value associated with a
* Notify() operator.
*
******************************************************************************/
void
{
/* The notify value is the second argument */
{
case AML_ZERO_OP:
case AML_ONE_OP:
break;
case AML_BYTE_OP:
break;
default:
return;
}
/*
* Attempt to get the namespace node so we can determine the object type.
* Some notify values are dependent on the object type (Device, Thermal,
* or Processor).
*/
if (Node)
{
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmPredefinedDescription
*
* PARAMETERS: Op - Name() parse object
*
* RETURN: None
*
* DESCRIPTION: Emit a description comment for a predefined ACPI name.
* Used for iASL compiler only.
*
******************************************************************************/
void
{
#ifdef ACPI_ASL_COMPILER
const AH_PREDEFINED_NAME *Info;
char *NameString;
int LastCharIsDigit;
int LastCharsAreHex;
if (!Op)
{
return;
}
/* Ensure that the comment field is emitted only once */
{
return;
}
/* Predefined name must start with an underscore */
if (NameString[0] != '_')
{
return;
}
/*
* Check for the special ACPI names:
* _ACd, _ALd, _EJd, _Exx, _Lxx, _Qxx, _Wxx, _T_a
* (where d=decimal_digit, x=hex_digit, a=anything)
*
* Convert these to the generic name for table lookup.
* Note: NameString is guaranteed to be upper case here.
*/
switch (NameString[1])
{
case 'A':
{
NameString = "_ACx";
}
{
NameString = "_ALx";
}
break;
case 'E':
{
NameString = "_EJx";
}
else if (LastCharsAreHex)
{
NameString = "_Exx";
}
break;
case 'L':
if (LastCharsAreHex)
{
NameString = "_Lxx";
}
break;
case 'Q':
if (LastCharsAreHex)
{
NameString = "_Qxx";
}
break;
case 'T':
{
NameString = "_T_x";
}
break;
case 'W':
if (LastCharsAreHex)
{
NameString = "_Wxx";
}
break;
default:
break;
}
/* Match the name in the info table */
if (Info)
{
AcpiOsPrintf (" // %4.4s: %s",
}
#endif
return;
}
/*******************************************************************************
*
* FUNCTION: AcpiDmFieldPredefinedDescription
*
* PARAMETERS: Op - Parse object
*
* RETURN: None
*
* DESCRIPTION: Emit a description comment for a resource descriptor tag
* (which is a predefined ACPI name.) Used for iASL compiler only.
*
******************************************************************************/
void
{
#ifdef ACPI_ASL_COMPILER
char *Tag;
const ACPI_OPCODE_INFO *OpInfo;
const AH_PREDEFINED_NAME *Info;
if (!Op)
{
return;
}
/* Ensure that the comment field is emitted only once */
{
return;
}
/*
* Op must be one of the Create* operators: CreateField, CreateBitField,
* CreateByteField, CreateWordField, CreateDwordField, CreateQwordField
*/
{
return;
}
/* Second argument is the Index argument */
/* Index argument must be a namepath */
{
return;
}
/* Major cheat: We previously put the Tag ptr in the Node field */
if (!Tag)
{
return;
}
/* Match the name in the info table */
if (Info)
{
}
#endif
return;
}
/*******************************************************************************
*
* FUNCTION: AcpiDmMethodFlags
*
* PARAMETERS: Op - Method Object to be examined
*
* RETURN: None
*
* DESCRIPTION: Decode control method flags
*
******************************************************************************/
void
{
/* The next Op contains the flags */
/* Mark the Op as completed */
/* 1) Method argument count */
/* 2) Serialize rule */
if (!(Flags & 0x08))
{
AcpiOsPrintf ("Not");
}
AcpiOsPrintf ("Serialized");
/* 3) SyncLevel */
if (Flags & 0xF0)
{
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmFieldFlags
*
* PARAMETERS: Op - Field Object to be examined
*
* RETURN: None
*
* DESCRIPTION: Decode Field definition flags
*
******************************************************************************/
void
{
/* Mark the Op as completed */
}
/*******************************************************************************
*
* FUNCTION: AcpiDmAddressSpace
*
* PARAMETERS: SpaceId - ID to be translated
*
* RETURN: None
*
* DESCRIPTION: Decode a SpaceId to an AddressSpaceKeyword
*
******************************************************************************/
void
{
if (SpaceId >= ACPI_NUM_PREDEFINED_REGIONS)
{
if (SpaceId == 0x7F)
{
AcpiOsPrintf ("FFixedHW, ");
}
else
{
}
}
else
{
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmRegionFlags
*
* PARAMETERS: Op - Object to be examined
*
* RETURN: None
*
* DESCRIPTION: Decode OperationRegion flags
*
******************************************************************************/
void
{
/* The next Op contains the SpaceId */
/* Mark the Op as completed */
AcpiOsPrintf (", ");
}
/*******************************************************************************
*
* FUNCTION: AcpiDmMatchOp
*
* PARAMETERS: Op - Match Object to be examined
*
* RETURN: None
*
* DESCRIPTION: Decode Match opcode operands
*
******************************************************************************/
void
{
if (!NextOp)
{
/* Handle partial tree during single-step */
return;
}
/* Mark the two nodes that contain the encoding for the match keywords */
}
/*******************************************************************************
*
* FUNCTION: AcpiDmMatchKeyword
*
* PARAMETERS: Op - Match Object to be examined
*
* RETURN: None
*
* DESCRIPTION: Decode Match opcode operands
*
******************************************************************************/
static void
{
{
AcpiOsPrintf ("/* Unknown Match Keyword encoding */");
}
else
{
AcpiOsPrintf ("%s",
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmDisassembleOneOp
*
* PARAMETERS: WalkState - Current walk info
* Info - Parse tree walk info
* Op - Op that is to be printed
*
* RETURN: None
*
* DESCRIPTION: Disassemble a single AML opcode
*
******************************************************************************/
void
{
const AH_DEVICE_ID *IdInfo;
if (!Op)
{
AcpiOsPrintf ("<NULL OP PTR>");
return;
}
{
return; /* ElseIf macro was already emitted */
}
{
case ACPI_DASM_MATCHOP:
return;
case ACPI_DASM_LNOT_SUFFIX:
{
{
case AML_LEQUAL_OP:
AcpiOsPrintf ("LNotEqual");
break;
case AML_LGREATER_OP:
AcpiOsPrintf ("LLessEqual");
break;
case AML_LLESS_OP:
AcpiOsPrintf ("LGreaterEqual");
break;
default:
break;
}
}
return;
default:
break;
}
/* The op and arguments */
{
case AML_LNOT_OP:
{
}
else
{
}
break;
case AML_BYTE_OP:
break;
case AML_WORD_OP:
{
}
else
{
}
break;
case AML_DWORD_OP:
{
}
else
{
}
break;
case AML_QWORD_OP:
AcpiOsPrintf ("0x%8.8X%8.8X",
break;
case AML_STRING_OP:
/* For _HID/_CID strings, attempt to output a descriptive comment */
{
/* If we know about the ID, emit the description */
if (IdInfo)
{
}
}
break;
case AML_BUFFER_OP:
/*
* Determine the type of buffer. We can have one of the following:
*
* 1) ResourceTemplate containing Resource Descriptors.
* 2) Unicode String buffer
* 3) ASCII String buffer
* 4) Raw data buffer (if none of the above)
*
* Since there are no special AML opcodes to differentiate these
* types of buffers, we have to closely look at the data in the
* buffer to determine the type.
*/
{
if (ACPI_SUCCESS (Status))
{
AcpiOsPrintf ("ResourceTemplate");
break;
}
else if (Status == AE_AML_NO_RESOURCE_END_TAG)
{
"/**** Is ResourceTemplate, "
"but EndTag not at buffer end ****/ ");
}
}
if (AcpiDmIsUuidBuffer (Op))
{
AcpiOsPrintf ("ToUUID (");
}
else if (AcpiDmIsUnicodeBuffer (Op))
{
AcpiOsPrintf ("Unicode (");
}
else if (AcpiDmIsStringBuffer (Op))
{
AcpiOsPrintf ("Buffer");
}
else if (AcpiDmIsPldBuffer (Op))
{
AcpiOsPrintf ("ToPLD (");
}
else
{
AcpiOsPrintf ("Buffer");
}
break;
case AML_INT_NAMEPATH_OP:
break;
case AML_INT_NAMEDFIELD_OP:
break;
case AML_INT_RESERVEDFIELD_OP:
/* Offset() -- Must account for previous offsets */
{
}
else
{
}
break;
case AML_INT_ACCESSFIELD_OP:
AcpiOsPrintf ("AccessAs (%s, ",
{
AcpiOsPrintf (" (0x%2.2X)", (unsigned)
}
AcpiOsPrintf (")");
break;
case AML_INT_CONNECTION_OP:
/*
* Two types of Connection() - one with a buffer object, the
* other with a namestring that points to a buffer object.
*/
AcpiOsPrintf ("Connection (");
{
AcpiOsPrintf ("\n");
}
else
{
}
AcpiOsPrintf (")");
AcpiOsPrintf ("\n");
break;
case AML_INT_BYTELIST_OP:
break;
case AML_INT_METHODCALL_OP:
break;
case AML_ELSE_OP:
break;
case AML_EXTERNAL_OP:
{
AcpiOsPrintf ("/* Opcode 0x15 */ ");
/* Fallthrough */
}
else
{
break;
}
default:
/* Just get the opcode name and print it */
#ifdef ACPI_DEBUGGER
(WalkState) &&
(WalkState->ResultCount))
{
}
#endif
break;
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmConvertToElseIf
*
* PARAMETERS: OriginalElseOp - ELSE Object to be examined
*
* RETURN: None. Emits either an "Else" or an "ElseIf" ASL operator.
*
* DESCRIPTION: Detect and convert an If..Else..If sequence to If..ElseIf
*
* EXAMPLE:
*
* This If..Else..If nested sequence:
*
* If (Arg0 == 1)
* {
* Local0 = 4
* }
* Else
* {
* If (Arg0 == 2)
* {
* Local0 = 5
* }
* }
*
* Is converted to this simpler If..ElseIf sequence:
*
* If (Arg0 == 1)
* {
* Local0 = 4
* }
* ElseIf (Arg0 == 2)
* {
* Local0 = 5
* }
*
* NOTE: There is no actual ElseIf AML opcode. ElseIf is essentially an ASL
* macro that emits an Else opcode followed by an If opcode. This function
* reverses these AML sequences back to an ElseIf macro where possible. This
* can make the disassembled ASL code simpler and more like the original code.
*
******************************************************************************/
static void
{
/*
* To be able to perform the conversion, two conditions must be satisfied:
* 1) The first child of the Else must be an If statement.
* 2) The If block can only be followed by an Else block and these must
* be the only blocks under the original Else.
*/
if (!IfOp ||
{
/* Not an Else..If sequence, cannot convert to ElseIf */
return;
}
/* Emit ElseIf, mark the IF as now an ELSEIF */
/* The IF parent will now be the same as the original ELSE parent */
/*
* Update the NEXT pointers to restructure the parse tree, essentially
* promoting an If..Else block up to the same level as the original
* Else.
*
* Check if the IF has a corresponding ELSE peer
*/
if (ElseOp &&
{
/* If an ELSE matches the IF, promote it also */
}
else
{
/* Otherwise, set the IF NEXT to the original ELSE NEXT */
}
/* Detach the child IF block from the original ELSE */
/* Ignore the original ELSE from now on */
/* Insert IF (now ELSEIF) as next peer of the original ELSE */
}