dmextern.c revision 199767f8919635c4928607450d9e0abb932109ce
/******************************************************************************
*
* Module Name: dmextern - Support for External() ASL statements
*
*****************************************************************************/
/*
* 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 <errno.h>
/*
* This module is used for application-level code (iASL disassembler) only.
*
* It contains the code to create and emit any necessary External() ASL
* statements for the module being disassembled.
*/
#define _COMPONENT ACPI_CA_DISASSEMBLER
ACPI_MODULE_NAME ("dmextern")
/*
* This table maps ACPI_OBJECT_TYPEs to the corresponding ASL
* ObjectTypeKeyword. Used to generate typed external declarations
*/
static const char *AcpiGbl_DmTypeNames[] =
{
/* 00 */ ", UnknownObj", /* Type ANY */
/* 01 */ ", IntObj",
/* 02 */ ", StrObj",
/* 03 */ ", BuffObj",
/* 04 */ ", PkgObj",
/* 05 */ ", FieldUnitObj",
/* 06 */ ", DeviceObj",
/* 07 */ ", EventObj",
/* 08 */ ", MethodObj",
/* 09 */ ", MutexObj",
/* 10 */ ", OpRegionObj",
/* 11 */ ", PowerResObj",
/* 12 */ ", ProcessorObj",
/* 13 */ ", ThermalZoneObj",
/* 14 */ ", BuffFieldObj",
/* 15 */ ", DDBHandleObj",
/* 16 */ "", /* Debug object */
/* 17 */ ", FieldUnitObj",
/* 18 */ ", FieldUnitObj",
/* 19 */ ", FieldUnitObj"
};
#define METHOD_SEPARATORS " \t,()\n"
/* Local prototypes */
static const char *
static char *
char *Path);
static void
char *Path,
static ACPI_STATUS
char *ExternalPath,
char *InternalPath,
/*******************************************************************************
*
* FUNCTION: AcpiDmGetObjectTypeName
*
* PARAMETERS: Type - An ACPI_OBJECT_TYPE
*
* RETURN: Pointer to a string
*
* DESCRIPTION: Map an object type to the ASL object type string.
*
******************************************************************************/
static const char *
{
if (Type == ACPI_TYPE_LOCAL_SCOPE)
{
}
else if (Type > ACPI_TYPE_LOCAL_INDEX_FIELD)
{
return ("");
}
return (AcpiGbl_DmTypeNames[Type]);
}
/*******************************************************************************
*
* FUNCTION: AcpiDmNormalizeParentPrefix
*
* PARAMETERS: Op - Parse op
* Path - Path with parent prefix
*
* RETURN: The full pathname to the object (from the namespace root)
*
* DESCRIPTION: Returns the full pathname of a path with parent prefix
* The caller must free the fullpath returned.
*
******************************************************************************/
static char *
char *Path)
{
char *Fullpath;
char *ParentPath;
if (!Op)
{
return (NULL);
}
/* Search upwards in the parse tree until we reach the next namespace node */
while (Op)
{
{
break;
}
}
if (!Op)
{
return (NULL);
}
/*
* Find the actual parent node for the reference:
* Remove all carat prefixes from the input path.
* There may be multiple parent prefixes (For example, ^^^M000)
*/
{
Path++;
}
if (!Node)
{
return (NULL);
}
/* Get the full pathname for the parent node */
if (!ParentPath)
{
return (NULL);
}
if (ParentPath[1])
{
/*
* If ParentPath is not just a simple '\', increment the length
* for the required dot separator (ParentPath.Path)
*/
Length++;
/* For External() statements, we do not want a leading '\' */
if (*ParentPath == AML_ROOT_PREFIX)
{
Index = 1;
}
}
if (!Fullpath)
{
goto Cleanup;
}
/*
* Concatenate parent fullpath and path. For example,
* parent fullpath "\_SB_", Path "^INIT", Fullpath "\_SB_.INIT"
*
* Copy the parent path
*/
/*
* Add dot separator
* (don't need dot if parent fullpath is a single backslash)
*/
if (ParentPath[1])
{
}
/* Copy child path (carat parent prefix(es) were skipped above) */
return (Fullpath);
}
/*******************************************************************************
*
* FUNCTION: AcpiDmAddToExternalFileList
*
* PARAMETERS: PathList - Single path or list separated by comma
*
* RETURN: None
*
* DESCRIPTION: Add external files to global list
*
******************************************************************************/
char *Pathname)
{
char *LocalPathname;
if (!Pathname)
{
return (AE_OK);
}
if (!LocalPathname)
{
return (AE_NO_MEMORY);
}
if (!ExternalFile)
{
return (AE_NO_MEMORY);
}
/* Take a copy of the file pathname */
{
}
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiDmClearExternalFileList
*
* PARAMETERS: None
*
* RETURN: None
*
* DESCRIPTION: Clear the external file list
*
******************************************************************************/
void
void)
{
while (AcpiGbl_ExternalFileList)
{
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmGetExternalsFromFile
*
* PARAMETERS: None
*
* RETURN: None
*
* DESCRIPTION: Process the optional external reference file.
*
* Each line in the file should be of the form:
* External (<Method namepath>, MethodObj, <ArgCount>)
*
* Example:
* External (_SB_.PCI0.XHC_.PS0X, MethodObj, 4)
*
******************************************************************************/
void
void)
{
char *Token;
char *MethodName;
UINT32 ImportCount = 0;
if (!Gbl_ExternalRefFilename)
{
return;
}
/* Open the file */
if (!ExternalRefFile)
{
AslAbort ();
return;
}
/* Each line defines a method */
{
if (!Token)
{
continue;
}
{
continue;
}
if (!MethodName)
{
continue;
}
if (!Token)
{
continue;
}
{
continue;
}
if (!Token)
{
continue;
}
/* Convert arg count string to an integer */
errno = 0;
if (errno)
{
continue;
}
if (ArgCount > 7)
{
continue;
}
/* Add this external to the global list */
AcpiOsPrintf ("%s: Importing method external (%u arguments) %s\n",
ImportCount++;
}
if (!ImportCount)
{
}
else
{
/* Add the external(s) to the namespace */
AcpiOsPrintf ("%s: Imported %u external method definitions\n",
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmAddOpToExternalList
*
* PARAMETERS: Op - Current parser Op
* Path - Internal (AML) path to the object
* Type - ACPI object type to be added
* Value - Arg count if adding a Method object
* Flags - To be passed to the external object
*
* RETURN: None
*
* DESCRIPTION: Insert a new name into the global list of Externals which
* will in turn be later emitted as an External() declaration
* in the disassembled output.
*
* This function handles the most common case where the referenced
* name is simply not found in the constructed namespace.
*
******************************************************************************/
void
char *Path,
{
char *ExternalPath;
char *InternalPath = Path;
char *Temp;
if (!Path)
{
}
/* Remove a root backslash if present */
{
Path++;
}
/* Externalize the pathname */
NULL, &ExternalPath);
if (ACPI_FAILURE (Status))
{
}
/*
* Get the full pathname from the root if "Path" has one or more
* parent prefixes (^). Note: path will not contain a leading '\'.
*/
{
/* Set new external path */
ExternalPath = Temp;
if (!Temp)
{
}
/* Create the new internal pathname */
if (ACPI_FAILURE (Status))
{
}
}
/* Create the new External() declaration node */
if (ACPI_FAILURE (Status))
{
{
}
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmAddNodeToExternalList
*
* PARAMETERS: Node - Namespace node for object to be added
* Type - ACPI object type to be added
* Value - Arg count if adding a Method object
* Flags - To be passed to the external object
*
* RETURN: None
*
* DESCRIPTION: Insert a new name into the global list of Externals which
* will in turn be later emitted as an External() declaration
* in the disassembled output.
*
* This function handles the case where the referenced name has
* been found in the namespace, but the name originated in a
* table other than the one that is being disassembled (such
* as a table that is added via the iASL -e option).
*
******************************************************************************/
void
{
char *ExternalPath;
char *InternalPath;
char *Temp;
if (!Node)
{
}
/* Get the full external and internal pathnames to the node */
if (!ExternalPath)
{
}
if (ACPI_FAILURE (Status))
{
}
/* Remove the root backslash */
{
if (!Temp)
{
}
ExternalPath = Temp;
}
/* Create the new External() declaration node */
if (ACPI_FAILURE (Status))
{
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmAddPathToExternalList
*
* PARAMETERS: Path - External name of the object to be added
* Type - ACPI object type to be added
* Value - Arg count if adding a Method object
* Flags - To be passed to the external object
*
* RETURN: None
*
* DESCRIPTION: Insert a new name into the global list of Externals which
* will in turn be later emitted as an External() declaration
* in the disassembled output.
*
* This function currently is used to add externals via a
* reference file (via the -fe iASL option).
*
******************************************************************************/
static void
char *Path,
{
char *InternalPath;
char *ExternalPath;
if (!Path)
{
}
/* Remove a root backslash if present */
{
Path++;
}
/* Create the internal and external pathnames */
if (ACPI_FAILURE (Status))
{
}
NULL, &ExternalPath);
if (ACPI_FAILURE (Status))
{
}
/* Create the new External() declaration node */
if (ACPI_FAILURE (Status))
{
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmCreateNewExternal
*
* PARAMETERS: ExternalPath - External path to the object
* InternalPath - Internal (AML) path to the object
* Type - ACPI object type to be added
* Value - Arg count if adding a Method object
* Flags - To be passed to the external object
*
* RETURN: Status
*
* DESCRIPTION: Common low-level function to insert a new name into the global
* list of Externals which will in turn be later emitted as
* External() declarations in the disassembled output.
*
* Note: The external name should not include a root prefix
* (backslash). We do not want External() statements to contain
* a leading '\', as this prevents duplicate external statements
* of the form:
*
* External (\ABCD)
* External (ABCD)
*
* This would cause a compile time error when the disassembled
* output file is recompiled.
*
* There are two cases that are handled here. For both, we emit
* an External() statement:
* 1) The name was simply not found in the namespace.
* 2) The name was found, but it originated in a table other than
* the table that is being disassembled.
*
******************************************************************************/
static ACPI_STATUS
char *ExternalPath,
char *InternalPath,
{
/* Check all existing externals to ensure no duplicates */
while (NextExternal)
{
{
/* Duplicate method, check that the Value (ArgCount) is the same */
(Value > 0))
{
"External method arg count mismatch %s: Current %u, attempted %u",
}
/* Allow upgrade of type from ANY */
{
}
}
}
/* Allocate and init a new External() descriptor */
if (!NewExternal)
{
}
"Adding external reference node (%s) type [%s]\n",
/* Link the new descriptor into the global list, alphabetically ordered */
while (NextExternal)
{
{
if (PrevExternal)
{
}
else
{
}
}
}
if (PrevExternal)
{
}
else
{
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmAddExternalsToNamespace
*
* PARAMETERS: None
*
* RETURN: None
*
* DESCRIPTION: Add all externals to the namespace. Allows externals to be
* "resolved".
*
******************************************************************************/
void
void)
{
while (External)
{
/* Add the external name (object) into the namespace */
if (ACPI_FAILURE (Status))
{
"while adding external to namespace [%s]",
}
{
case ACPI_TYPE_METHOD:
/* For methods, we need to save the argument count */
break;
case ACPI_TYPE_REGION:
/* Regions require a region sub-object */
break;
default:
break;
}
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmGetExternalMethodCount
*
* PARAMETERS: None
*
* RETURN: The number of control method externals in the external list
*
* DESCRIPTION: Return the number of method externals that have been generated.
* If any control method externals have been found, we must
* re-parse the entire definition block with the new information
* (number of arguments for the methods.) This is limitation of
* AML, we don't know the number of arguments from the control
* method invocation itself.
*
******************************************************************************/
void)
{
while (External)
{
{
Count++;
}
}
return (Count);
}
/*******************************************************************************
*
* FUNCTION: AcpiDmClearExternalList
*
* PARAMETERS: None
*
* RETURN: None
*
* DESCRIPTION: Free the entire External info list
*
******************************************************************************/
void
void)
{
while (AcpiGbl_ExternalList)
{
}
}
/*******************************************************************************
*
* FUNCTION: AcpiDmEmitExternals
*
* PARAMETERS: None
*
* RETURN: None
*
* DESCRIPTION: Emit an External() ASL statement for each of the externals in
* the global external info list.
*
******************************************************************************/
void
void)
{
if (!AcpiGbl_ExternalList)
{
return;
}
/*
* Determine the number of control methods in the external list, and
* also how many of those externals were resolved via the namespace.
*/
while (NextExternal)
{
{
{
}
}
}
/* Check if any control methods were unresolved */
/* Emit any unresolved method externals in a single text block */
while (NextExternal)
{
{
AcpiOsPrintf (" External (%s%s",
AcpiOsPrintf (") // Warning: Unresolved method, "
"guessing %u arguments\n",
}
}
AcpiOsPrintf ("\n");
/* Emit externals that were imported from a file */
{
" /*\n * External declarations that were imported from\n"
" * the reference file [%s]\n */\n",
while (NextExternal)
{
{
AcpiOsPrintf (" External (%s%s",
{
AcpiOsPrintf (") // %u Arguments\n",
}
else
{
AcpiOsPrintf (")\n");
}
}
}
AcpiOsPrintf ("\n");
}
/*
* Walk the list of externals found during the AML parsing
*/
while (AcpiGbl_ExternalList)
{
{
AcpiOsPrintf (" External (%s%s",
/* For methods, add a comment with the number of arguments */
{
AcpiOsPrintf (") // %u Arguments\n",
}
else
{
AcpiOsPrintf (")\n");
}
}
/* Free this external info block and move on to next external */
{
}
}
AcpiOsPrintf ("\n");
}
/*******************************************************************************
*
* FUNCTION: AcpiDmUnresolvedWarning
*
* PARAMETERS: Type - Where to output the warning.
* 0 means write to stderr
* 1 means write to AcpiOsPrintf
*
* RETURN: None
*
* DESCRIPTION: Issue warning message if there are unresolved external control
* methods within the disassembly.
*
******************************************************************************/
#if 0
{
}
{
}
{
}
{
EFGH ()
}
0000034C: 14 10 54 31 5F 5F 00 ... "..T1__."
186: {
00000353: 41 42 43 44 ............ "ABCD"
00000357: 72 0A 02 0A 07 60 ...... "r....`"
188: }
0000035D: 14 10 54 32 5F 5F 00 ... "..T2__."
191: {
192: EFGH ()
00000364: 45 46 47 48 ............ "EFGH"
00000368: 72 0A 02 0A 07 60 ...... "r....`"
194: }
#endif
void
{
{
return;
}
if (Type)
{
if (!AcpiGbl_ExternalFileList)
{
/* The -e option was not specified */
AcpiOsPrintf (" /*\n"
" * iASL Warning: There were %u external control methods found during\n"
" * disassembly, but additional ACPI tables to resolve these externals\n"
" * were not specified. This resulting disassembler output file may not\n"
" * compile because the disassembler did not know how many arguments\n"
" * to assign to these methods. To specify the tables needed to resolve\n"
" * external control method references, the -e option can be used to\n"
" * specify the filenames. Note: SSDTs can be dynamically loaded at\n"
" * runtime and may or may not be available via the host OS.\n"
" * Example iASL invocations:\n"
" * iasl -e ssdt1.aml ssdt2.aml ssdt3.aml -d dsdt.aml\n"
" * iasl -e dsdt.aml ssdt2.aml -d ssdt1.aml\n"
" * iasl -e ssdt*.aml -d dsdt.aml\n"
" *\n"
" * In addition, the -fe option can be used to specify a file containing\n"
" * control method external declarations with the associated method\n"
" * argument counts. Each line of the file must be of the form:\n"
" * External (<method pathname>, MethodObj, <argument count>)\n"
" * Invocation:\n"
" * iasl -fe refs.txt -d dsdt.aml\n"
" *\n"
" * The following methods were unresolved and many not compile properly\n"
" * because the disassembler had to guess at the number of arguments\n"
" * required for each:\n"
" */\n",
}
{
/* The -e option was specified, but there are still some unresolved externals */
AcpiOsPrintf (" /*\n"
" * iASL Warning: There were %u external control methods found during\n"
" * disassembly, but only %u %s resolved (%u unresolved). Additional\n"
" * ACPI tables may be required to properly disassemble the code. This\n"
" * resulting disassembler output file may not compile because the\n"
" * disassembler did not know how many arguments to assign to the\n"
" * unresolved methods. Note: SSDTs can be dynamically loaded at\n"
" * runtime and may or may not be available via the host OS.\n"
" *\n"
" * If necessary, the -fe option can be used to specify a file containing\n"
" * control method external declarations with the associated method\n"
" * argument counts. Each line of the file must be of the form:\n"
" * External (<method pathname>, MethodObj, <argument count>)\n"
" * Invocation:\n"
" * iasl -fe refs.txt -d dsdt.aml\n"
" *\n"
" * The following methods were unresolved and many not compile properly\n"
" * because the disassembler had to guess at the number of arguments\n"
" * required for each:\n"
" */\n",
}
}
else
{
if (!AcpiGbl_ExternalFileList)
{
/* The -e option was not specified */
"iASL Warning: There were %u external control methods found during\n"
"disassembly, but additional ACPI tables to resolve these externals\n"
"were not specified. The resulting disassembler output file may not\n"
"compile because the disassembler did not know how many arguments\n"
"to assign to these methods. To specify the tables needed to resolve\n"
"external control method references, the -e option can be used to\n"
"specify the filenames. Note: SSDTs can be dynamically loaded at\n"
"runtime and may or may not be available via the host OS.\n"
"Example iASL invocations:\n"
" iasl -e ssdt1.aml ssdt2.aml ssdt3.aml -d dsdt.aml\n"
" iasl -e dsdt.aml ssdt2.aml -d ssdt1.aml\n"
" iasl -e ssdt*.aml -d dsdt.aml\n"
"\n"
"In addition, the -fe option can be used to specify a file containing\n"
"control method external declarations with the associated method\n"
"argument counts. Each line of the file must be of the form:\n"
" External (<method pathname>, MethodObj, <argument count>)\n"
"Invocation:\n"
" iasl -fe refs.txt -d dsdt.aml\n",
}
{
/* The -e option was specified, but there are still some unresolved externals */
"iASL Warning: There were %u external control methods found during\n"
"disassembly, but only %u %s resolved (%u unresolved). Additional\n"
"ACPI tables may be required to properly disassemble the code. The\n"
"resulting disassembler output file may not compile because the\n"
"disassembler did not know how many arguments to assign to the\n"
"unresolved methods. Note: SSDTs can be dynamically loaded at\n"
"runtime and may or may not be available via the host OS.\n"
"\n"
"If necessary, the -fe option can be used to specify a file containing\n"
"control method external declarations with the associated method\n"
"argument counts. Each line of the file must be of the form:\n"
" External (<method pathname>, MethodObj, <argument count>)\n"
"Invocation:\n"
" iasl -fe refs.txt -d dsdt.aml\n",
}
}
}