New: Portable acpidump utility (get system ACPI tables).

This utility dumps the system ACPI tables in an ascii format suitable
for extraction via the acpixtract utility.

The main code is portable across environments and hosts. To port the
code, only 3 functions need to be written specifically to obtain
the binary tables from the system.

In this version, Windows is supported. Linux support will be
added later.

ACPICA bugzilla 859.
This commit is contained in:
Robert Moore 2013-05-02 09:27:35 -07:00
parent bc5dceb5a9
commit 15215bf87d
14 changed files with 4639 additions and 74 deletions

View File

@ -180,6 +180,7 @@ extern int AcpiGbl_Opterr;
extern char *AcpiGbl_Optarg;
#ifndef ACPI_DUMP_APP
/*
* adisasm
*/
@ -284,5 +285,6 @@ AdWriteTable (
UINT32 Length,
char *TableName,
char *OemTableId);
#endif
#endif /* _ACAPPS */

View File

@ -463,6 +463,28 @@ AcpiOsGetLine (
UINT32 *BytesRead);
/*
* Obtain ACPI table(s)
*/
ACPI_STATUS
AcpiOsGetTableByName (
char *Signature,
UINT32 Instance,
ACPI_TABLE_HEADER **Table,
ACPI_PHYSICAL_ADDRESS *Address);
ACPI_STATUS
AcpiOsGetTableByIndex (
UINT32 Index,
ACPI_TABLE_HEADER **Table,
ACPI_PHYSICAL_ADDRESS *Address);
ACPI_STATUS
AcpiOsGetTableByAddress (
ACPI_PHYSICAL_ADDRESS Address,
ACPI_TABLE_HEADER **Table);
/*
* Directory manipulation
*/

View File

@ -382,6 +382,14 @@ typedef UINT32 ACPI_PHYSICAL_ADDRESS;
#define ACPI_EXPORT_SYMBOL(Symbol)
#endif
/*
* Compiler/Clibrary-dependent debug initialization. Used for ACPICA
* utilities only.
*/
#ifndef ACPI_DEBUG_INITIALIZE
#define ACPI_DEBUG_INITIALIZE()
#endif
/******************************************************************************
*

View File

@ -169,10 +169,11 @@
#endif
/*
* AcpiBin/AcpiHelp/AcpiSrc configuration. All single threaded, with
* no debug output.
* AcpiBin/AcpiDump/AcpiSrc/AcpiXtract configuration. All single
* threaded, with no debug output.
*/
#if (defined ACPI_BIN_APP) || \
(defined ACPI_DUMP_APP) || \
(defined ACPI_SRC_APP) || \
(defined ACPI_XTRACT_APP)
#define ACPI_APPLICATION

View File

@ -218,4 +218,16 @@
#pragma warning( disable : 4295 ) /* needed for acpredef.h array */
#endif
/* Debug support. Must be last in this file, do not move. */
#ifdef _DEBUG
#include <crtdbg.h>
#define ACPI_DEBUG_INITIALIZE() \
_CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | \
_CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_CRT_DF | \
_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
#endif
#endif /* __ACMSVC_H__ */

View File

@ -0,0 +1,209 @@
/******************************************************************************
*
* Module Name: oslinuxtbl - Linux OSL for obtaining ACPI tables
*
*****************************************************************************/
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2013, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
#include "acpi.h"
#include <stdio.h>
#include <stdlib.h>
#define _COMPONENT ACPI_OS_SERVICES
ACPI_MODULE_NAME ("oslinuxtbl")
/******************************************************************************
*
* FUNCTION: AcpiOsGetTableByAddress
*
* PARAMETERS: Address - Physical address of the ACPI table
* Table - Where a pointer to the table is returned
*
* RETURN: Status; Table buffer is returned if AE_OK.
* AE_NOT_FOUND: A valid table was not found at the address
*
* DESCRIPTION: Get an ACPI table via a physical memory address.
*
*****************************************************************************/
ACPI_STATUS
AcpiOsGetTableByAddress (
ACPI_PHYSICAL_ADDRESS Address,
ACPI_TABLE_HEADER **Table)
{
fprintf (stderr, "Linux version not implemented yet\n");
return (AE_SUPPORT);
}
/******************************************************************************
*
* FUNCTION: AcpiOsGetTableByIndex
*
* PARAMETERS: Index - Which table to get
* Table - Where a pointer to the table is returned
* Address - Where the table physical address is returned
*
* RETURN: Status; Table buffer and physical address returned if AE_OK.
* AE_LIMIT: Index is beyond valid limit
*
* DESCRIPTION: Get an ACPI table via an index value (0 through n). Returns
* AE_LIMIT when an invalid index is reached. Index is not
* necessarily an index into the RSDT/XSDT.
*
*****************************************************************************/
ACPI_STATUS
AcpiOsGetTableByIndex (
UINT32 Index,
ACPI_TABLE_HEADER **Table,
ACPI_PHYSICAL_ADDRESS *Address)
{
fprintf (stderr, "Linux version not implemented yet\n");
return (AE_SUPPORT);
}
/******************************************************************************
*
* FUNCTION: AcpiOsGetTableByName
*
* PARAMETERS: Signature - ACPI Signature for desired table. Must be
* a null terminated 4-character string.
* Instance - For SSDTs (0...n)
* Table - Where a pointer to the table is returned
* Address - Where the table physical address is returned
*
* RETURN: Status; Table buffer and physical address returned if AE_OK.
*
* RETURN: Status; Table buffer and physical address returned if AE_OK.
* AE_LIMIT: Instance is beyond valid limit
* AE_NOT_FOUND: A table with the signature was not found
*
* NOTE: Assumes the input signature is uppercase.
*
*****************************************************************************/
ACPI_STATUS
AcpiOsGetTableByName (
char *Signature,
UINT32 Instance,
ACPI_TABLE_HEADER **Table,
ACPI_PHYSICAL_ADDRESS *Address)
{
fprintf (stderr, "Linux version not implemented yet\n");
return (AE_SUPPORT);
}

View File

@ -113,8 +113,8 @@
*
*****************************************************************************/
#include "acpi.h"
#include <stdio.h>
#ifdef WIN32
#pragma warning(disable:4115) /* warning C4115: (caused by rpcasync.h) */
@ -127,21 +127,57 @@
#define _COMPONENT ACPI_OS_SERVICES
ACPI_MODULE_NAME ("oswintbl")
/* Local prototypes */
static char KeyBuffer[64];
static char ErrorBuffer[64];
static char *
WindowsFormatException (
LONG WinStatus);
/* Globals */
#define LOCAL_BUFFER_SIZE 64
static char KeyBuffer[LOCAL_BUFFER_SIZE];
static char ErrorBuffer[LOCAL_BUFFER_SIZE];
/*
* Tables supported in the Windows registry. SSDTs are not placed into
* the registry, a limitation.
*/
static char *SupportedTables[] =
{
"DSDT",
"RSDT",
"FACS",
"FACP"
};
/* Max index for table above */
#define ACPI_OS_MAX_TABLE_INDEX 3
/* Little front-end to win FormatMessage */
/******************************************************************************
*
* FUNCTION: WindowsFormatException
*
* PARAMETERS: WinStatus - Status from a Windows system call
*
* RETURN: Formatted (ascii) exception code. Front-end to Windows
* FormatMessage interface.
*
* DESCRIPTION: Decode a windows exception
*
*****************************************************************************/
char *
OsFormatException (
LONG Status)
static char *
WindowsFormatException (
LONG WinStatus)
{
ErrorBuffer[0] = 0;
FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, Status, 0,
ErrorBuffer, 64, NULL);
FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, WinStatus, 0,
ErrorBuffer, LOCAL_BUFFER_SIZE, NULL);
return (ErrorBuffer);
}
@ -149,30 +185,120 @@ OsFormatException (
/******************************************************************************
*
* FUNCTION: OsGetTable
* FUNCTION: AcpiOsGetTableByAddress
*
* PARAMETERS: Signature - ACPI Signature for desired table. must be
* a null terminated string.
* PARAMETERS: Address - Physical address of the ACPI table
* Table - Where a pointer to the table is returned
*
* RETURN: Pointer to the table. NULL if failure.
* RETURN: Status; Table buffer is returned if AE_OK.
* AE_NOT_FOUND: A valid table was not found at the address
*
* DESCRIPTION: Get an ACPI table from the Windows registry.
* DESCRIPTION: Get an ACPI table via a physical memory address.
*
* NOTE: Cannot be implemented without a Windows device driver.
*
*****************************************************************************/
ACPI_TABLE_HEADER *
OsGetTable (
char *Signature)
ACPI_STATUS
AcpiOsGetTableByAddress (
ACPI_PHYSICAL_ADDRESS Address,
ACPI_TABLE_HEADER **Table)
{
HKEY Handle = NULL;
ULONG i;
LONG Status;
ULONG Type;
ULONG NameSize;
ULONG DataSize;
HKEY SubKey;
ACPI_TABLE_HEADER *ReturnTable;
fprintf (stderr, "Get table by address is not supported on Windows\n");
return (AE_SUPPORT);
}
/******************************************************************************
*
* FUNCTION: AcpiOsGetTableByIndex
*
* PARAMETERS: Index - Which table to get
* Table - Where a pointer to the table is returned
* Address - Where the table physical address is returned
*
* RETURN: Status; Table buffer and physical address returned if AE_OK.
* AE_LIMIT: Index is beyond valid limit
*
* DESCRIPTION: Get an ACPI table via an index value (0 through n). Returns
* AE_LIMIT when an invalid index is reached. Index is not
* necessarily an index into the RSDT/XSDT.
* Table is obtained from the Windows registry.
*
* NOTE: Cannot get the physical address from the windows registry;
* zero is returned instead.
*
*****************************************************************************/
ACPI_STATUS
AcpiOsGetTableByIndex (
UINT32 Index,
ACPI_TABLE_HEADER **Table,
ACPI_PHYSICAL_ADDRESS *Address)
{
ACPI_STATUS Status;
if (Index > ACPI_OS_MAX_TABLE_INDEX)
{
return (AE_LIMIT);
}
Status = AcpiOsGetTableByName (SupportedTables[Index], 0, Table, Address);
return (Status);
}
/******************************************************************************
*
* FUNCTION: AcpiOsGetTableByName
*
* PARAMETERS: Signature - ACPI Signature for desired table. Must be
* a null terminated 4-character string.
* Instance - For SSDTs (0...n). Use 0 otherwise.
* Table - Where a pointer to the table is returned
* Address - Where the table physical address is returned
*
* RETURN: Status; Table buffer and physical address returned if AE_OK.
* AE_LIMIT: Instance is beyond valid limit
* AE_NOT_FOUND: A table with the signature was not found
*
* DESCRIPTION: Get an ACPI table via a table signature (4 ASCII characters).
* Returns AE_LIMIT when an invalid instance is reached.
* Table is obtained from the Windows registry.
*
* NOTE: Assumes the input signature is uppercase.
* Cannot get the physical address from the windows registry;
* zero is returned instead.
*
*****************************************************************************/
ACPI_STATUS
AcpiOsGetTableByName (
char *Signature,
UINT32 Instance,
ACPI_TABLE_HEADER **Table,
ACPI_PHYSICAL_ADDRESS *Address)
{
HKEY Handle = NULL;
LONG WinStatus;
ULONG Type;
ULONG NameSize;
ULONG DataSize;
HKEY SubKey;
ULONG i;
ACPI_TABLE_HEADER *ReturnTable;
/*
* Windows has no SSDTs in the registry, so multiple instances are
* not supported.
*/
if (Instance > 0)
{
return (AE_LIMIT);
}
/* Get a handle to the table key */
@ -181,10 +307,10 @@ OsGetTable (
ACPI_STRCPY (KeyBuffer, "HARDWARE\\ACPI\\");
ACPI_STRCAT (KeyBuffer, Signature);
Status = RegOpenKeyEx (HKEY_LOCAL_MACHINE, KeyBuffer,
0L, KEY_READ, &Handle);
WinStatus = RegOpenKeyEx (HKEY_LOCAL_MACHINE, KeyBuffer,
0L, KEY_READ, &Handle);
if (Status != ERROR_SUCCESS)
if (WinStatus != ERROR_SUCCESS)
{
/*
* Somewhere along the way, MS changed the registry entry for
@ -198,12 +324,16 @@ OsGetTable (
{
Signature = "FADT";
}
else if (ACPI_COMPARE_NAME (Signature, "XSDT"))
{
Signature = "RSDT";
}
else
{
AcpiOsPrintf (
"Could not find %s in registry at %s: %s (Status=0x%X)\n",
Signature, KeyBuffer, OsFormatException (Status), Status);
return (NULL);
fprintf (stderr,
"Could not find %s in registry at %s: %s (WinStatus=0x%X)\n",
Signature, KeyBuffer, WindowsFormatException (WinStatus), WinStatus);
return (AE_NOT_FOUND);
}
}
else
@ -212,23 +342,23 @@ OsGetTable (
}
}
/* Actual data for table is down a couple levels */
/* Actual data for the table is down a couple levels */
for (i = 0; ;)
{
Status = RegEnumKey (Handle, i, KeyBuffer, sizeof (KeyBuffer));
i += 1;
if (Status == ERROR_NO_MORE_ITEMS)
WinStatus = RegEnumKey (Handle, i, KeyBuffer, sizeof (KeyBuffer));
i++;
if (WinStatus == ERROR_NO_MORE_ITEMS)
{
break;
}
Status = RegOpenKey (Handle, KeyBuffer, &SubKey);
if (Status != ERROR_SUCCESS)
WinStatus = RegOpenKey (Handle, KeyBuffer, &SubKey);
if (WinStatus != ERROR_SUCCESS)
{
AcpiOsPrintf ("Could not open %s entry: %s\n",
Signature, OsFormatException (Status));
return (NULL);
fprintf (stderr, "Could not open %s entry: %s\n",
Signature, WindowsFormatException (WinStatus));
return (AE_ERROR);
}
RegCloseKey (Handle);
@ -238,38 +368,38 @@ OsGetTable (
/* Find the (binary) table entry */
for (i = 0; ;)
for (i = 0; ; i++)
{
NameSize = sizeof (KeyBuffer);
Status = RegEnumValue (Handle, i, KeyBuffer, &NameSize,
NULL, &Type, NULL, 0);
if (Status != ERROR_SUCCESS)
WinStatus = RegEnumValue (Handle, i, KeyBuffer, &NameSize, NULL,
&Type, NULL, 0);
if (WinStatus != ERROR_SUCCESS)
{
AcpiOsPrintf ("Could not get %s registry entry: %s\n",
Signature, OsFormatException (Status));
return (NULL);
fprintf (stderr, "Could not get %s registry entry: %s\n",
Signature, WindowsFormatException (WinStatus));
return (AE_ERROR);
}
if (Type == REG_BINARY)
{
break;
}
i += 1;
}
/* Get the size of the table */
Status = RegQueryValueEx (Handle, KeyBuffer, NULL, NULL, NULL, &DataSize);
if (Status != ERROR_SUCCESS)
WinStatus = RegQueryValueEx (Handle, KeyBuffer, NULL, NULL,
NULL, &DataSize);
if (WinStatus != ERROR_SUCCESS)
{
AcpiOsPrintf ("Could not read the %s table size: %s\n",
Signature, OsFormatException (Status));
return (NULL);
fprintf (stderr, "Could not read the %s table size: %s\n",
Signature, WindowsFormatException (WinStatus));
return (AE_ERROR);
}
/* Allocate a new buffer for the table */
ReturnTable = AcpiOsAllocate (DataSize);
ReturnTable = malloc (DataSize);
if (!ReturnTable)
{
goto Cleanup;
@ -277,17 +407,20 @@ OsGetTable (
/* Get the actual table from the registry */
Status = RegQueryValueEx (Handle, KeyBuffer, NULL, NULL,
(UCHAR *) ReturnTable, &DataSize);
if (Status != ERROR_SUCCESS)
WinStatus = RegQueryValueEx (Handle, KeyBuffer, NULL, NULL,
(UCHAR *) ReturnTable, &DataSize);
if (WinStatus != ERROR_SUCCESS)
{
AcpiOsPrintf ("Could not read %s data: %s\n",
Signature, OsFormatException (Status));
AcpiOsFree (ReturnTable);
return (NULL);
fprintf (stderr, "Could not read %s data: %s\n",
Signature, WindowsFormatException (WinStatus));
free (ReturnTable);
return (AE_ERROR);
}
Cleanup:
RegCloseKey (Handle);
return (ReturnTable);
*Table = ReturnTable;
*Address = 0;
return (AE_OK);
}

View File

@ -146,7 +146,7 @@ char TableName[ACPI_NAME_SIZE + 1];
#define ACPI_OS_DEBUG_TIMEOUT 30000 /* 30 seconds */
/* Upcalls to application */
/* Upcalls to AcpiExec application */
ACPI_PHYSICAL_ADDRESS
AeLocalGetRootPointer (
@ -157,11 +157,6 @@ AeTableOverride (
ACPI_TABLE_HEADER *ExistingTable,
ACPI_TABLE_HEADER **NewTable);
ACPI_TABLE_HEADER *
OsGetTable (
char *Signature);
/*
* Real semaphores are only used for a multi-threaded application
*/
@ -317,6 +312,10 @@ AcpiOsTableOverride (
ACPI_TABLE_HEADER *ExistingTable,
ACPI_TABLE_HEADER **NewTable)
{
#ifdef ACPI_ASL_COMPILER
ACPI_STATUS Status;
ACPI_PHYSICAL_ADDRESS Address;
#endif
if (!ExistingTable || !NewTable)
{
@ -343,15 +342,16 @@ AcpiOsTableOverride (
ACPI_MOVE_NAME (TableName, ExistingTable->Signature);
TableName[ACPI_NAME_SIZE] = 0;
*NewTable = OsGetTable (TableName);
if (*NewTable)
Status = AcpiOsGetTableByName (TableName, 0, NewTable, &Address);
if (ACPI_SUCCESS (Status))
{
AcpiOsPrintf ("Table [%s] obtained from registry, %u bytes\n",
TableName, (*NewTable)->Length);
}
else
{
AcpiOsPrintf ("Could not read table %s from registry\n", TableName);
AcpiOsPrintf ("Could not read table %s from registry (%s)\n",
TableName, AcpiFormatException (Status));
}
#endif

View File

@ -0,0 +1,211 @@
/******************************************************************************
*
* Module Name: acpidump.h - Include file for AcpiDump utility
*
*****************************************************************************/
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2013, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
#include "acpi.h"
#include "accommon.h"
#include "actables.h"
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/stat.h>
/*
* Global variables. Defined in main.c only, externed in all other files
*/
#ifdef _DECLARE_GLOBALS
#define EXTERN
#define INIT_GLOBAL(a,b) a=b
#else
#define EXTERN extern
#define INIT_GLOBAL(a,b) a
#endif
/* Globals */
EXTERN BOOLEAN INIT_GLOBAL (Gbl_SummaryMode, FALSE);
EXTERN BOOLEAN INIT_GLOBAL (Gbl_VerboseMode, FALSE);
EXTERN BOOLEAN INIT_GLOBAL (Gbl_BinaryMode, FALSE);
EXTERN UINT32 INIT_GLOBAL (Gbl_SsdtCount, 0);
EXTERN FILE INIT_GLOBAL (*Gbl_OutputFile, NULL);
EXTERN char INIT_GLOBAL (*Gbl_OutputFilename, NULL);
/* Globals required for use with ACPICA modules */
#ifdef _DECLARE_GLOBALS
UINT8 AcpiGbl_EnableInterpreterSlack = FALSE;
UINT8 AcpiGbl_IntegerByteWidth = 8;
UINT32 AcpiDbgLevel = 0;
UINT32 AcpiDbgLayer = 0;
#endif
/* Action table used to defer requested options */
typedef struct ap_dump_action
{
char *Argument;
UINT32 ToBeDone;
} AP_DUMP_ACTION;
#define AP_MAX_ACTIONS 32
#define AP_DUMP_ALL_TABLES 0
#define AP_DUMP_TABLE_BY_ADDRESS 1
#define AP_DUMP_TABLE_BY_NAME 2
#define AP_DUMP_TABLE_BY_FILE 3
#define AP_MAX_ACPI_FILES 256 /* Prevent infinite loops */
/*
* apdump - Table get/dump routines
*/
int
ApDumpTableFromFile (
char *Pathname);
int
ApDumpTableByName (
char *Signature);
int
ApDumpTableByAddress (
char *AsciiAddress);
int
ApDumpAllTables (
void);
/*
* apfiles - File I/O utilities
*/
UINT32
ApGetFileSize (
FILE *File);
int
ApOpenOutputFile (
char *Pathname);
int
ApWriteToBinaryFile (
ACPI_TABLE_HEADER *Table);
ACPI_TABLE_HEADER *
ApGetTableFromFile (
char *Pathname,
UINT32 *FileSize);

View File

@ -0,0 +1,495 @@
/******************************************************************************
*
* Module Name: apdump - Dump routines for ACPI tables (acpidump)
*
*****************************************************************************/
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2013, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
#include "acpidump.h"
/* Local prototypes */
static BOOLEAN
ApIsValidHeader (
ACPI_TABLE_HEADER *Table);
static int
ApDumpTableBuffer (
ACPI_TABLE_HEADER *Table,
ACPI_PHYSICAL_ADDRESS Address);
/******************************************************************************
*
* FUNCTION: ApIsValidHeader
*
* PARAMETERS: Table - Pointer to table to be validated
*
* RETURN: TRUE if the header appears to be valid. FALSE otherwise
*
* DESCRIPTION: Check for a valid ACPI table header
*
******************************************************************************/
static BOOLEAN
ApIsValidHeader (
ACPI_TABLE_HEADER *Table)
{
/* Make sure signature is all ASCII and a valid ACPI name */
if (!AcpiUtValidAcpiName (*(UINT32 *) Table->Signature))
{
fprintf (stderr, "Table signature (0x%X) is invalid\n",
*(UINT32 *) Table->Signature);
return (FALSE);
}
/* Check for minimum table length */
if (Table->Length <= sizeof (ACPI_TABLE_HEADER))
{
fprintf (stderr, "Table length (0x%X) is invalid\n",
Table->Length);
return (FALSE);
}
return (TRUE);
}
/******************************************************************************
*
* FUNCTION: ApDumpTableBuffer
*
* PARAMETERS: Table - ACPI table to be dumped
* Address - Physical address of the table
*
* RETURN: None
*
* DESCRIPTION: Dump an ACPI table in standard ASCII hex format, with a
* header that is compatible with the AcpiXtract utility.
*
******************************************************************************/
static int
ApDumpTableBuffer (
ACPI_TABLE_HEADER *Table,
ACPI_PHYSICAL_ADDRESS Address)
{
/* Check if the table header appears to be valid */
if (!ApIsValidHeader (Table))
{
return (-1);
}
/* Validate the table checksum (except FACS - has no checksum) */
if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_FACS))
{
(void) AcpiTbVerifyChecksum (Table, Table->Length);
}
/* Print only the header if requested */
if (Gbl_SummaryMode)
{
AcpiTbPrintTableHeader (Address, Table);
return (0);
}
/* Dump to binary file if requested */
if (Gbl_BinaryMode)
{
return (ApWriteToBinaryFile (Table));
}
/*
* Dump the table with header for use with acpixtract utility
* Note: simplest to just always emit a 64-bit address. AcpiXtract
* utility can handle this.
*/
printf ("%4.4s @ 0x%8.8X%8.8X\n", Table->Signature,
ACPI_FORMAT_UINT64 (Address));
AcpiUtDumpBuffer (ACPI_CAST_PTR (UINT8, Table), Table->Length,
DB_BYTE_DISPLAY, 0);
printf ("\n");
return (0);
}
/******************************************************************************
*
* FUNCTION: ApDumpAllTables
*
* PARAMETERS: None
*
* RETURN: Status
*
* DESCRIPTION: Get all tables from the RSDT/XSDT (or at least all of the
* tables that we can possibly get).
*
******************************************************************************/
int
ApDumpAllTables (
void)
{
ACPI_TABLE_HEADER *Table;
ACPI_PHYSICAL_ADDRESS Address;
ACPI_STATUS Status;
UINT32 i;
/* Get and dump all available ACPI tables */
for (i = 0; i < AP_MAX_ACPI_FILES; i++)
{
Status = AcpiOsGetTableByIndex (i, &Table, &Address);
if (ACPI_FAILURE (Status))
{
/* AE_LIMIT means that no more tables are available */
if (Status == AE_LIMIT)
{
return (0);
}
else if (i == 0)
{
fprintf (stderr, "Could not get ACPI tables, %s\n",
AcpiFormatException (Status));
return (-1);
}
else
{
fprintf (stderr, "Could not get ACPI table at index %u, %s\n",
i, AcpiFormatException (Status));
continue;
}
}
if (ApDumpTableBuffer (Table, Address))
{
return (-1);
}
free (Table);
}
/* Something seriously bad happened if the loop terminates here */
return (-1);
}
/******************************************************************************
*
* FUNCTION: ApDumpTableByAddress
*
* PARAMETERS: AsciiAddress - Address for requested ACPI table
*
* RETURN: Status
*
* DESCRIPTION: Get an ACPI table via a physical address and dump it.
*
******************************************************************************/
int
ApDumpTableByAddress (
char *AsciiAddress)
{
ACPI_PHYSICAL_ADDRESS Address;
ACPI_TABLE_HEADER *Table;
ACPI_STATUS Status;
int TableStatus;
UINT64 LongAddress;
/* Convert argument to an integer physical address */
Status = AcpiUtStrtoul64 (AsciiAddress, 0, &LongAddress);
if (ACPI_FAILURE (Status))
{
fprintf (stderr, "%s: Could not convert to a physical address\n",
AsciiAddress);
return (-1);
}
Address = (ACPI_PHYSICAL_ADDRESS) LongAddress;
Status = AcpiOsGetTableByAddress (Address, &Table);
if (ACPI_FAILURE (Status))
{
fprintf (stderr, "Could not get table at 0x%8.8X%8.8X, %s\n",
ACPI_FORMAT_UINT64 (Address),
AcpiFormatException (Status));
return (-1);
}
TableStatus = ApDumpTableBuffer (Table, Address);
free (Table);
return (TableStatus);
}
/******************************************************************************
*
* FUNCTION: ApDumpTableByName
*
* PARAMETERS: Signature - Requested ACPI table signature
*
* RETURN: Status
*
* DESCRIPTION: Get an ACPI table via a signature and dump it. Handles
* multiple tables with the same signature (SSDTs).
*
******************************************************************************/
int
ApDumpTableByName (
char *Signature)
{
char LocalSignature [ACPI_NAME_SIZE + 1];
UINT32 Instance;
ACPI_TABLE_HEADER *Table;
ACPI_PHYSICAL_ADDRESS Address;
ACPI_STATUS Status;
if (strlen (Signature) > ACPI_NAME_SIZE)
{
fprintf (stderr,
"Invalid table signature [%s]: too long (4 chars max)\n",
Signature);
return (-1);
}
/* Table signatures are expected to be uppercase */
strcpy (LocalSignature, Signature);
AcpiUtStrupr (LocalSignature);
/* Dump all instances of this signature (to handle multiple SSDTs) */
for (Instance = 0; Instance < AP_MAX_ACPI_FILES; Instance++)
{
Status = AcpiOsGetTableByName (LocalSignature, Instance,
&Table, &Address);
if (ACPI_FAILURE (Status))
{
/* AE_LIMIT means that no more tables are available */
if (Status == AE_LIMIT)
{
return (0);
}
fprintf (stderr,
"Could not get ACPI table with signature [%s], %s\n",
LocalSignature, AcpiFormatException (Status));
return (-1);
}
if (ApDumpTableBuffer (Table, Address))
{
return (-1);
}
free (Table);
}
/* Something seriously bad happened if the loop terminates here */
return (-1);
}
/******************************************************************************
*
* FUNCTION: ApDumpTableFromFile
*
* PARAMETERS: Pathname - File containing the binary ACPI table
*
* RETURN: Status
*
* DESCRIPTION: Dump an ACPI table from a binary file
*
******************************************************************************/
int
ApDumpTableFromFile (
char *Pathname)
{
ACPI_TABLE_HEADER *Table;
UINT32 FileSize = 0;
int TableStatus;
/* Get the entire ACPI table from the file */
Table = ApGetTableFromFile (Pathname, &FileSize);
if (!Table)
{
return (-1);
}
/* File must be at least as long as the table length */
if (Table->Length > FileSize)
{
fprintf (stderr,
"Table length (0x%X) is too large for input file (0x%X) %s\n",
Table->Length, FileSize, Pathname);
return (-1);
}
if (Gbl_VerboseMode)
{
fprintf (stderr,
"Input file: %s contains table [%4.4s], 0x%X (%u) bytes\n",
Pathname, Table->Signature, FileSize, FileSize);
}
TableStatus = ApDumpTableBuffer (Table, 0);
free (Table);
return (TableStatus);
}
/******************************************************************************
*
* FUNCTION: AcpiOs* print functions
*
* DESCRIPTION: Used for linkage with ACPICA modules
*
******************************************************************************/
void ACPI_INTERNAL_VAR_XFACE
AcpiOsPrintf (
const char *Fmt,
...)
{
va_list Args;
va_start (Args, Fmt);
vfprintf (stdout, Fmt, Args);
va_end (Args);
}
void
AcpiOsVprintf (
const char *Fmt,
va_list Args)
{
vfprintf (stdout, Fmt, Args);
}

View File

@ -0,0 +1,349 @@
/******************************************************************************
*
* Module Name: apfiles - File-related functions for acpidump utility
*
*****************************************************************************/
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2013, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
#include "acpidump.h"
#include "acapps.h"
/******************************************************************************
*
* FUNCTION: ApOpenOutputFile
*
* PARAMETERS: Pathname - Output filename
*
* RETURN: Open file handle
*
* DESCRIPTION: Open a text output file for acpidump. Checks if file already
* exists.
*
******************************************************************************/
int
ApOpenOutputFile (
char *Pathname)
{
struct stat StatInfo;
FILE *File;
/* If file exists, prompt for overwrite */
if (!stat (Pathname, &StatInfo))
{
fprintf (stderr, "Target path already exists, overwrite? [y|n] ");
if (getchar () != 'y')
{
return (-1);
}
}
/* Point stdout to the file */
File = freopen (Pathname, "w", stdout);
if (!File)
{
perror ("Could not open output file");
return (-1);
}
/* Save the file and path */
Gbl_OutputFile = File;
Gbl_OutputFilename = Pathname;
return (0);
}
/******************************************************************************
*
* FUNCTION: ApWriteToBinaryFile
*
* PARAMETERS: Table - ACPI table to be written
*
* RETURN: Status
*
* DESCRIPTION: Write an ACPI table to a binary file. Builds the output
* filename from the table signature.
*
******************************************************************************/
int
ApWriteToBinaryFile (
ACPI_TABLE_HEADER *Table)
{
char Filename[ACPI_NAME_SIZE + 16];
char SsdtInstance [16];
FILE *File;
size_t Actual;
/* Construct lower-case filename from the table signature */
Filename[0] = (char) ACPI_TOLOWER (Table->Signature[0]);
Filename[1] = (char) ACPI_TOLOWER (Table->Signature[1]);
Filename[2] = (char) ACPI_TOLOWER (Table->Signature[2]);
Filename[3] = (char) ACPI_TOLOWER (Table->Signature[3]);
Filename[ACPI_NAME_SIZE] = 0;
/* Handle multiple SSDTs - create different filenames for each */
if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_SSDT))
{
sprintf (SsdtInstance, "%u", Gbl_SsdtCount);
strcat (Filename, SsdtInstance);
Gbl_SsdtCount++;
}
strcat (Filename, ACPI_TABLE_FILE_SUFFIX);
if (Gbl_VerboseMode)
{
fprintf (stderr,
"Writing [%4.4s] to binary file: %s 0x%X (%u) bytes\n",
Table->Signature, Filename, Table->Length, Table->Length);
}
/* Open the file and dump the entire table in binary mode */
File = fopen (Filename, "wb");
if (!File)
{
perror ("Could not open output file");
return (-1);
}
Actual = fwrite (Table, 1, Table->Length, File);
if (Actual != Table->Length)
{
perror ("Error writing binary output file");
fclose (File);
return (-1);
}
fclose (File);
return (0);
}
/******************************************************************************
*
* FUNCTION: ApGetTableFromFile
*
* PARAMETERS: Pathname - File containing the binary ACPI table
* OutFileSize - Where the file size is returned
*
* RETURN: Buffer containing the ACPI table. NULL on error.
*
* DESCRIPTION: Open a file and read it entirely into a new buffer
*
******************************************************************************/
ACPI_TABLE_HEADER *
ApGetTableFromFile (
char *Pathname,
UINT32 *OutFileSize)
{
ACPI_TABLE_HEADER *Buffer = NULL;
FILE *File;
UINT32 FileSize;
size_t Actual;
/* Must use binary mode */
File = fopen (Pathname, "rb");
if (!File)
{
perror ("Could not open input file");
return (NULL);
}
/* Need file size to allocate a buffer */
FileSize = ApGetFileSize (File);
if (!FileSize)
{
fprintf (stderr,
"Could not get input file size: %s\n", Pathname);
goto Cleanup;
}
/* Allocate a buffer for the entire file */
Buffer = calloc (1, FileSize);
if (!Buffer)
{
fprintf (stderr,
"Could not allocate file buffer of size: %u\n", FileSize);
goto Cleanup;
}
/* Read the entire file */
Actual = fread (Buffer, 1, FileSize, File);
if (Actual != FileSize)
{
fprintf (stderr,
"Could not read input file: %s\n", Pathname);
free (Buffer);
Buffer = NULL;
goto Cleanup;
}
*OutFileSize = FileSize;
Cleanup:
fclose (File);
return (Buffer);
}
/******************************************************************************
*
* FUNCTION: ApGetFileSize
*
* PARAMETERS: File - Open file descriptor
*
* RETURN: File size in bytes
*
* DESCRIPTION: Get the size of an open file
*
******************************************************************************/
UINT32
ApGetFileSize (
FILE *File)
{
UINT32 FileSize;
long Offset;
Offset = ftell (File);
if (fseek (File, 0, SEEK_END))
{
return (0);
}
/* Get size and restore file pointer */
FileSize = (UINT32) ftell (File);
if (fseek (File, Offset, SEEK_SET))
{
return (0);
}
return (FileSize);
}

View File

@ -0,0 +1,400 @@
/******************************************************************************
*
* Module Name: apmain - Main module for the acpidump utility
*
*****************************************************************************/
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2013, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
#define _DECLARE_GLOBALS
#include "acpidump.h"
#include "acapps.h"
/* Local prototypes */
static void
ApDisplayUsage (
void);
static int
ApDoOptions (
int argc,
char **argv);
static void
ApInsertAction (
char *Argument,
UINT32 ToBeDone);
/* Table for deferred actions from command line options */
AP_DUMP_ACTION ActionTable [AP_MAX_ACTIONS];
UINT32 CurrentAction = 0;
#define AP_UTILITY_NAME "ACPI Binary Table Dump Utility"
#define AP_SUPPORTED_OPTIONS "?a:bf:hn:o:rsv"
/******************************************************************************
*
* FUNCTION: ApDisplayUsage
*
* DESCRIPTION: Usage message for the AcpiDump utility
*
******************************************************************************/
static void
ApDisplayUsage (
void)
{
ACPI_USAGE_HEADER ("acpidump [options]");
ACPI_OPTION ("-b", "Dump tables to binary files");
ACPI_OPTION ("-h -?", "This help message");
ACPI_OPTION ("-o <File>", "Redirect output to file");
ACPI_OPTION ("-r", "Revision (version)");
ACPI_OPTION ("-s", "Print table summaries only");
ACPI_OPTION ("-v", "Verbose mode");
printf ("\nTable Options:\n");
ACPI_OPTION ("-a <Address>", "Get table via physical address");
ACPI_OPTION ("-f <BinaryFile>", "Get table via binary file");
ACPI_OPTION ("-n <Signature>", "Get table via name/signature");
printf (
"\n"
"Invocation without parameters dumps all available tables\n"
"Multiple mixed instances of -a, -f, and -n are supported\n\n");
}
/******************************************************************************
*
* FUNCTION: ApInsertAction
*
* PARAMETERS: Argument - Pointer to the argument for this action
* ToBeDone - What to do to process this action
*
* RETURN: None. Exits program if action table becomes full.
*
* DESCRIPTION: Add an action item to the action table
*
******************************************************************************/
static void
ApInsertAction (
char *Argument,
UINT32 ToBeDone)
{
/* Insert action and check for table overflow */
ActionTable [CurrentAction].Argument = Argument;
ActionTable [CurrentAction].ToBeDone = ToBeDone;
CurrentAction++;
if (CurrentAction > AP_MAX_ACTIONS)
{
fprintf (stderr, "Too many table options (max %u)\n", AP_MAX_ACTIONS);
exit (-1);
}
}
/******************************************************************************
*
* FUNCTION: ApDoOptions
*
* PARAMETERS: argc/argv - Standard argc/argv
*
* RETURN: Status
*
* DESCRIPTION: Command line option processing. The main actions for getting
* and dumping tables are deferred via the action table.
*
*****************************************************************************/
static int
ApDoOptions (
int argc,
char **argv)
{
int j;
/* Command line options */
while ((j = AcpiGetopt (argc, argv, AP_SUPPORTED_OPTIONS)) != EOF) switch (j)
{
/*
* Global options
*/
case 'b': /* Dump all input tables to binary files */
Gbl_BinaryMode = TRUE;
continue;
case 'h':
case '?':
ApDisplayUsage ();
exit (0);
case 'o': /* Redirect output to a single file */
if (ApOpenOutputFile (AcpiGbl_Optarg))
{
exit (-1);
}
continue;
case 'r': /* Revision/version */
printf (ACPI_COMMON_SIGNON (AP_UTILITY_NAME));
exit (0);
case 's': /* Print table summaries only */
Gbl_SummaryMode = TRUE;
continue;
case 'v': /* Verbose mode */
Gbl_VerboseMode = TRUE;
fprintf (stderr, ACPI_COMMON_SIGNON (AP_UTILITY_NAME));
continue;
/*
* Table options
*/
case 'a': /* Get table by physical address */
ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_ADDRESS);
break;
case 'f': /* Get table from a file */
ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_FILE);
break;
case 'n': /* Get table by input name (signature) */
ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_NAME);
break;
default:
ApDisplayUsage ();
exit (-1);
}
/* If there are no actions, this means "get/dump all tables" */
if (CurrentAction == 0)
{
ApInsertAction (NULL, AP_DUMP_ALL_TABLES);
}
return (0);
}
/******************************************************************************
*
* FUNCTION: main
*
* PARAMETERS: argc/argv - Standard argc/argv
*
* RETURN: Status
*
* DESCRIPTION: C main function for acpidump utility
*
******************************************************************************/
int ACPI_SYSTEM_XFACE
main (
int argc,
char *argv[])
{
int Status = 0;
AP_DUMP_ACTION *Action;
UINT32 FileSize;
UINT32 i;
ACPI_DEBUG_INITIALIZE (); /* For debug version only */
/* Process command line options */
if (ApDoOptions (argc, argv))
{
return (-1);
}
/* Get/dump ACPI table(s) as requested */
for (i = 0; i < CurrentAction; i++)
{
Action = &ActionTable[i];
switch (Action->ToBeDone)
{
case AP_DUMP_ALL_TABLES:
Status = ApDumpAllTables ();
break;
case AP_DUMP_TABLE_BY_ADDRESS:
Status = ApDumpTableByAddress (Action->Argument);
break;
case AP_DUMP_TABLE_BY_NAME:
Status = ApDumpTableByName (Action->Argument);
break;
case AP_DUMP_TABLE_BY_FILE:
Status = ApDumpTableFromFile (Action->Argument);
break;
default:
fprintf (stderr, "Internal error, invalid action: 0x%X\n",
Action->ToBeDone);
return (-1);
}
if (Status)
{
return (Status);
}
}
if (Gbl_OutputFile)
{
if (Gbl_VerboseMode)
{
/* Summary for the output file */
FileSize = ApGetFileSize (Gbl_OutputFile);
fprintf (stderr, "Output file %s contains 0x%X (%u) bytes\n\n",
Gbl_OutputFilename, FileSize, FileSize);
}
fclose (Gbl_OutputFile);
}
return (Status);
}

2713
source/tools/acpidump/dump.txt Executable file

File diff suppressed because it is too large Load Diff

10
source/tools/acpidump/facp.txt Executable file
View File

@ -0,0 +1,10 @@
FACP @ 0x0000000000000000
0000: 46 41 43 50 74 00 00 00 01 B8 43 4F 4D 50 41 51 FACPt.....COMPAQ
0010: 45 41 47 4C 4C 41 4B 45 01 00 00 00 00 00 00 00 EAGLLAKE........
0020: 00 00 00 00 00 54 7C DD 27 5A 7C DD 01 00 09 00 .....T|.'Z|.....
0030: B2 00 00 00 02 03 00 00 00 F8 00 00 00 00 00 00 ................
0040: 04 F8 00 00 02 04 00 00 50 00 00 00 08 F8 00 00 ........P.......
0050: 20 F8 00 00 00 00 00 00 04 02 00 04 10 00 00 00 ...............
0060: 01 00 E9 03 00 00 20 00 01 03 0D 00 32 00 00 00 ...... .....2...
0070: AD 00 00 00 ....