/******************************************************************************
*
* Module Name: axutils - Utility functions for acpixtract tool.
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2016, Intel Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
* 3. Neither the names of the above-listed copyright holders nor the names
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*/
#include "acpixtract.h"
/*******************************************************************************
*
* FUNCTION: AxCheckAscii
*
* PARAMETERS: Name - Ascii string, at least as long as Count
* Count - Number of characters to check
*
* RETURN: None
*
* DESCRIPTION: Ensure that the requested number of characters are printable
* Ascii characters. Sets non-printable and null chars to <space>.
*
******************************************************************************/
void
char *Name,
int Count)
{
int i;
for (i = 0; i < Count; i++)
{
{
Name[i] = ' ';
}
}
}
/******************************************************************************
*
* FUNCTION: AxIsEmptyLine
*
* PARAMETERS: Buffer - Line from input file
*
* RETURN: TRUE if line is empty (zero or more blanks only)
*
* DESCRIPTION: Determine if an input line is empty.
*
******************************************************************************/
int
char *Buffer)
{
/* Skip all spaces */
while (*Buffer == ' ')
{
Buffer++;
}
/* If end-of-line, this line is empty */
if (*Buffer == '\n')
{
return (1);
}
return (0);
}
/*******************************************************************************
*
* FUNCTION: AxNormalizeSignature
*
* PARAMETERS: Name - Ascii string containing an ACPI signature
*
* RETURN: None
*
* DESCRIPTION: Change "RSD PTR" to "RSDP"
*
******************************************************************************/
void
char *Signature)
{
{
}
}
/******************************************************************************
*
* FUNCTION: AxConvertLine
*
* PARAMETERS: InputLine - One line from the input acpidump file
* OutputData - Where the converted data is returned
*
* RETURN: The number of bytes actually converted
*
* DESCRIPTION: Convert one line of ascii text binary (up to 16 bytes)
*
******************************************************************************/
char *InputLine,
unsigned char *OutputData)
{
char *End;
int BytesConverted;
int i;
/* Terminate the input line at the end of the actual data (for sscanf) */
if (!End)
{
return (0); /* Don't understand the format */
}
*End = 0;
/*
* Convert one line of table data, of the form:
* <offset>: <up to 16 bytes of hex data> <ASCII representation> <newline>
*
* Example:
* 02C0: 5F 53 42 5F 4C 4E 4B 44 00 12 13 04 0C FF FF 08 _SB_LNKD........
*/
"%*s %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x",
/* Pack converted data into a byte array */
for (i = 0; i < BytesConverted; i++)
{
OutputData[i] = (unsigned char) Converted[i];
}
return ((size_t) BytesConverted);
}
/******************************************************************************
*
* FUNCTION: AxGetTableHeader
*
* PARAMETERS: InputFile - Handle for the input acpidump file
* OutputData - Where the table header is returned
*
* RETURN: The actual number of bytes converted
*
* DESCRIPTION: Extract and convert an ACPI table header
*
******************************************************************************/
unsigned char *OutputData)
{
int i;
/* Get the full 36 byte ACPI table header, requires 3 input text lines */
for (i = 0; i < 3; i++)
{
{
return (TotalConverted);
}
OutputData += 16;
if (BytesConverted != 16)
{
return (TotalConverted);
}
}
return (TotalConverted);
}
/******************************************************************************
*
* FUNCTION: AxCountTableInstances
*
* PARAMETERS: InputPathname - Filename for acpidump file
* Signature - Requested signature to count
*
* RETURN: The number of instances of the signature
*
* DESCRIPTION: Count the instances of tables with the given signature within
* the input acpidump file.
*
******************************************************************************/
unsigned int
char *InputPathname,
char *Signature)
{
unsigned int Instances = 0;
if (!InputFile)
{
return (0);
}
/* Count the number of instances of this signature */
{
/* Ignore empty lines and lines that start with a space */
if (AxIsEmptyLine (Gbl_InstanceBuffer) ||
(Gbl_InstanceBuffer[0] == ' '))
{
continue;
}
{
Instances++;
}
}
return (Instances);
}
/******************************************************************************
*
* FUNCTION: AxGetNextInstance
*
* PARAMETERS: InputPathname - Filename for acpidump file
* Signature - Requested ACPI signature
*
* RETURN: The next instance number for this signature. Zero if this
* is the first instance of this signature.
*
* DESCRIPTION: Get the next instance number of the specified table. If this
* is the first instance of the table, create a new instance
* block. Note: only SSDT and PSDT tables can have multiple
* instances.
*
******************************************************************************/
unsigned int
char *InputPathname,
char *Signature)
{
while (Info)
{
{
break;
}
}
if (!Info)
{
/* Signature not found, create new table info block */
if (!Info)
{
printf ("Could not allocate memory (0x%X bytes)\n",
(unsigned int) sizeof (AX_TABLE_INFO));
exit (0);
}
}
{
return (Info->NextInstance++);
}
return (0);
}
/******************************************************************************
*
* FUNCTION: AxIsDataBlockHeader
*
* PARAMETERS: None
*
* RETURN: Status. 1 if the table header is valid, 0 otherwise.
*
* DESCRIPTION: Check if the ACPI table identifier in the input acpidump text
* file is valid (of the form: <sig> @ <addr>).
*
******************************************************************************/
int
void)
{
/* Ignore lines that are too short to be header lines */
{
return (0);
}
/* Ignore empty lines and lines that start with a space */
if (AxIsEmptyLine (Gbl_LineBuffer) ||
(Gbl_LineBuffer[0] == ' '))
{
return (0);
}
/*
* Ignore lines that are not headers of the form <sig> @ <addr>.
* Basically, just look for the '@' symbol, surrounded by spaces.
*
* Examples of headers that must be supported:
*
* DSDT @ 0x737e4000
* XSDT @ 0x737f2fff
* RSD PTR @ 0xf6cd0
* SSDT @ (nil)
*/
{
return (0);
}
return (1);
}
/******************************************************************************
*
* FUNCTION: AxProcessOneTextLine
*
* PARAMETERS: OutputFile - Where to write the binary data
* ThisSignature - Signature of current ACPI table
* ThisTableBytesWritten - Total count of data written
*
* RETURN: Length of the converted line
*
* DESCRIPTION: Convert one line of input hex ascii text to binary, and write
* the binary data to the table output file.
*
******************************************************************************/
long
char *ThisSignature,
unsigned int ThisTableBytesWritten)
{
/* Check for the end of this table data block */
if (AxIsEmptyLine (Gbl_LineBuffer) ||
(Gbl_LineBuffer[0] != ' '))
{
return (0);
}
/* Convert one line of ascii hex data to binary */
/* Write the binary data */
if (BytesWritten != BytesConverted)
{
return (-1);
}
return (BytesWritten);
}