adisasm.c revision 199767f8919635c4928607450d9e0abb932109ce
/******************************************************************************
*
* Module Name: adisasm - Application-level disassembler 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.
*/
#include <stdio.h>
#include <time.h>
#define _COMPONENT ACPI_TOOLS
ACPI_MODULE_NAME ("adisasm")
/* Local prototypes */
static void
char *Filename,
static ACPI_STATUS
UINT32 *TableIndex);
/* Stubs for ASL compiler */
#ifndef ACPI_ASL_COMPILER
{
return TRUE;
}
{
return (Status);
}
#endif
{
return (AE_NOT_IMPLEMENTED);
}
{
return (AE_OK);
}
void
{
return;
}
{
return (AE_OK);
}
{
return (AE_OK);
}
static ACPI_PARSE_OBJECT *AcpiGbl_ParseOpRoot;
/*******************************************************************************
*
* FUNCTION: AdInitialize
*
* PARAMETERS: None
*
* RETURN: Status
*
* DESCRIPTION: ACPICA and local initialization
*
******************************************************************************/
void)
{
/* ACPICA subsystem initialization */
Status = AcpiOsInitialize ();
if (ACPI_FAILURE (Status))
{
return (Status);
}
Status = AcpiUtInitGlobals ();
if (ACPI_FAILURE (Status))
{
return (Status);
}
Status = AcpiUtMutexInitialize ();
if (ACPI_FAILURE (Status))
{
return (Status);
}
Status = AcpiNsRootInitialize ();
if (ACPI_FAILURE (Status))
{
return (Status);
}
/* Setup the Table Manager (cheat - there is no RSDT) */
return (Status);
}
/******************************************************************************
*
* FUNCTION: AdAmlDisassemble
*
* PARAMETERS: Filename - AML input filename
* OutToFile - TRUE if output should go to a file
* Prefix - Path prefix for output
* OutFilename - where the filename is returned
*
* RETURN: Status
*
* DESCRIPTION: Disassemble an entire ACPI table
*
*****************************************************************************/
char *Filename,
char *Prefix,
char **OutFilename)
{
char *DisasmFilename = NULL;
char *ExternalFilename;
/*
* Input: AML code from either a file or via GetTables (memory or
* registry)
*/
if (Filename)
{
if (ACPI_FAILURE (Status))
{
return (Status);
}
/*
* External filenames separated by commas
* Example: iasl -e file1,file2,file3 -d xxx.aml
*/
while (ExternalFileList)
{
{
/* Next external file */
continue;
}
if (ACPI_FAILURE (Status))
{
{
continue;
}
return (Status);
}
/* Load external table for symbol resolution */
if (ExternalTable)
{
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("Could not parse external ACPI tables, %s\n",
return (Status);
}
/*
* Load namespace from names created within control methods
* Set owner id of nodes in external table
*/
}
/* Next external file */
}
if (ACPI_FAILURE (GlobalStatus))
{
return (GlobalStatus);
}
/* Clear external list generated by Scope in external tables */
{
}
/* Load any externals defined in the optional external ref file */
}
else
{
Status = AdGetLocalTables ();
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("Could not get ACPI tables, %s\n",
return (Status);
}
if (!AcpiGbl_DmOpt_Disasm)
{
return (AE_OK);
}
/* Obtained the local tables, just disassemble the DSDT */
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("Could not get DSDT, %s\n",
return (Status);
}
AcpiOsPrintf ("\nDisassembly of DSDT\n");
}
/*
* Output: ASL code. Redirect to a file if requested
*/
if (OutToFile)
{
if (!DisasmFilename)
{
goto Cleanup;
}
if (!File)
{
goto Cleanup;
}
}
/* ForceAmlDisassembly means to assume the table contains valid AML */
{
AcpiOsPrintf (" * ACPI Data Table [%4.4s]\n *\n",
AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength] "
"FieldName : FieldValue\n */\n\n");
if (File)
{
}
}
else
{
/* Always parse the tables, only option is what to display */
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
goto Cleanup;
}
if (AslCompilerdebug)
{
AcpiOsPrintf ("/**** Before second load\n");
if (File)
{
}
AcpiOsPrintf ("*****/\n");
}
/* Load namespace from names created within control methods */
/*
* Cross reference the namespace here, in order to
* generate External() statements
*/
if (AslCompilerdebug)
{
}
/* Find possible calls to external control methods */
/*
* If we found any external control methods, we must reparse
* the entire tree with the new information (namely, the
* number of arguments per method)
*/
if (AcpiDmGetExternalMethodCount ())
{
"\nFound %u external control methods, "
"reparsing with new information\n",
/* Reparse, rebuild namespace */
Status = AcpiNsRootInitialize ();
/* New namespace, add the external definitions first */
/* Parse the table again. No need to reload it, however */
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
goto Cleanup;
}
/* Cross reference the namespace again */
if (AslCompilerdebug)
{
AcpiOsPrintf ("/**** After second load and resource conversion\n");
if (File)
{
}
AcpiOsPrintf ("*****/\n");
}
}
/*
* Now that the namespace is finalized, we can perform namespace
* transforms.
*
* 1) Convert fixed-offset references to resource descriptors
* to symbolic references (Note: modifies namespace)
*/
/* Optional displays */
if (AcpiGbl_DmOpt_Disasm)
{
/* This is the real disassembly */
/* Dump hex table if requested (-vt) */
if (File)
{
}
if (Gbl_MapfileFlag)
{
}
}
}
{
}
if (File)
{
if (AslCompilerdebug) /* Display final namespace, with transforms */
{
}
}
return (Status);
}
/******************************************************************************
*
* FUNCTION: AdDisassemblerHeader
*
* PARAMETERS: Filename - Input file for the table
* TableType - Either AML or DataTable
*
* RETURN: None
*
* DESCRIPTION: Create the disassembler header, including ACPICA signon with
* current time and date.
*
*****************************************************************************/
void
char *Filename,
{
/* Header and input table info */
AcpiOsPrintf ("/*\n");
if (TableType == ACPI_IS_AML_TABLE)
{
{
" * Disassembling to symbolic ASL+ operators\n"
" *\n");
}
else
{
" * Disassembling to non-symbolic legacy ASL operators\n"
" *\n");
}
}
AcpiOsPrintf (" *\n");
}
/******************************************************************************
*
* FUNCTION: AdCreateTableHeader
*
* PARAMETERS: Filename - Input file for the table
* Table - Pointer to the raw table
*
* RETURN: None
*
* DESCRIPTION: Create the ASL table header, including ACPICA signon with
* current time and date.
*
*****************************************************************************/
static void
char *Filename,
{
char *NewFilename;
/*
* Print file header and dump original table header
*/
AcpiOsPrintf (" * Original Table Header:\n");
/* Print and validate the revision */
{
case 0:
AcpiOsPrintf (" **** Invalid Revision");
break;
case 1:
/* Revision of DSDT controls the ACPI integer width */
{
AcpiOsPrintf (" **** 32-bit table (V1), no 64-bit math support");
}
break;
default:
break;
}
AcpiOsPrintf ("\n");
/* Print and validate the table checksum */
if (Checksum)
{
AcpiOsPrintf (" **** Incorrect checksum, should be 0x%2.2X",
}
AcpiOsPrintf ("\n");
AcpiOsPrintf (" * Compiler Version 0x%8.8X (%u)\n", Table->AslCompilerRevision, Table->AslCompilerRevision);
AcpiOsPrintf (" */\n");
/* Create AML output filename based on input filename */
if (Filename)
{
}
else
{
if (NewFilename)
{
}
}
if (!NewFilename)
{
AcpiOsPrintf (" **** Could not generate AML output filename\n");
return;
}
/* Open the ASL definition block */
"DefinitionBlock (\"%s\", \"%4.4s\", %hu, \"%.6s\", \"%.8s\", 0x%8.8X)\n",
}
/******************************************************************************
*
* FUNCTION: AdDisplayTables
*
* PARAMETERS: Filename - Input file for the table
* Table - Pointer to the raw table
*
* RETURN: Status
*
* DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
*
*****************************************************************************/
char *Filename,
{
if (!AcpiGbl_ParseOpRoot)
{
return (AE_NOT_EXIST);
}
if (!AcpiGbl_DmOpt_Listing)
{
}
{
AcpiOsPrintf ("\n\nTable Header:\n");
}
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AdStoreTable
*
* PARAMETERS: Table - Table header
* TableIndex - Where the table index is returned
*
* RETURN: Status and table index.
*
* DESCRIPTION: Add an ACPI table to the global table list
*
******************************************************************************/
static ACPI_STATUS
{
if (ACPI_FAILURE (Status))
{
return (Status);
}
/* Initialize added table */
return (Status);
}
/******************************************************************************
*
* FUNCTION: AdGetLocalTables
*
* PARAMETERS: None
*
* RETURN: Status
*
* DESCRIPTION: Get the ACPI tables from either memory or a file
*
*****************************************************************************/
void)
{
/* Get the DSDT via table override */
if (!NewTable)
{
return (AE_NO_ACPI_TABLES);
}
/* Store DSDT in the Table Manager */
if (ACPI_FAILURE (Status))
{
return (AE_NO_ACPI_TABLES);
}
return (AE_OK);
}
/******************************************************************************
*
* FUNCTION: AdParseTable
*
* PARAMETERS: Table - Pointer to the raw table
* OwnerId - Returned OwnerId of the table
* LoadTable - If add table to the global table list
* External - If this is an external table
*
* RETURN: Status
*
* DESCRIPTION: Parse the DSDT.
*
*****************************************************************************/
{
if (!Table)
{
return (AE_NOT_EXIST);
}
/* Pass 1: Parse everything except control method bodies */
/* Create the root object */
if (!AcpiGbl_ParseOpRoot)
{
return (AE_NO_MEMORY);
}
/* Create and initialize a new walk state */
if (!WalkState)
{
return (AE_NO_MEMORY);
}
if (ACPI_FAILURE (Status))
{
return (Status);
}
if (ACPI_FAILURE (Status))
{
return (Status);
}
/* If LoadTable is FALSE, we are parsing the last loaded table */
/* Pass 2 */
if (LoadTable)
{
if (ACPI_FAILURE (Status))
{
return (Status);
}
if (ACPI_FAILURE (Status))
{
return (Status);
}
if (OwnerId)
{
if (ACPI_FAILURE (Status))
{
return (Status);
}
}
}
if (ACPI_FAILURE (Status))
{
return (Status);
}
/* No need to parse control methods of external table */
if (External)
{
return (AE_OK);
}
/*
* Pass 3: Parse control methods and link their parse trees
* into the main parse tree
*/
/* Process Resource Templates */
return (AE_OK);
}