summaryrefslogtreecommitdiff
path: root/source/tools/acpixtract/axutils.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/tools/acpixtract/axutils.c')
-rw-r--r--source/tools/acpixtract/axutils.c396
1 files changed, 278 insertions, 118 deletions
diff --git a/source/tools/acpixtract/axutils.c b/source/tools/acpixtract/axutils.c
index 00882c6fed91..6f887668426e 100644
--- a/source/tools/acpixtract/axutils.c
+++ b/source/tools/acpixtract/axutils.c
@@ -184,6 +184,70 @@ AxCheckAscii (
}
+/*******************************************************************************
+ *
+ * FUNCTION: AxIsFileAscii
+ *
+ * PARAMETERS: Handle - To open input file
+ *
+ * RETURN: TRUE if file is entirely ASCII and printable
+ *
+ * DESCRIPTION: Verify that the input file is entirely ASCII.
+ *
+ ******************************************************************************/
+
+BOOLEAN
+AxIsFileAscii (
+ FILE *Handle)
+{
+ UINT8 Byte;
+
+
+ /* Read the entire file */
+
+ fseek (Handle, 0, SEEK_SET);
+ while (fread (&Byte, 1, 1, Handle) == 1)
+ {
+ /*
+ * Ignore null characters. Some acpidump-type utilities insert
+ * a few of these, probably a bug in the utility. As long as these
+ * characters are in lines that are tossed (non-data), they
+ * won't cause a problem.
+ */
+ if (!Byte)
+ {
+ continue;
+ }
+
+ /* Check for an ASCII character */
+
+ if (!ACPI_IS_ASCII (Byte))
+ {
+ goto ErrorExit;
+ }
+
+ /* Ensure character is either printable or a "space" char */
+
+ else if (!isprint (Byte) && !isspace (Byte))
+ {
+ goto ErrorExit;
+ }
+ }
+
+ /* File is OK (100% ASCII) */
+
+ fseek (Handle, 0, SEEK_SET);
+ return (TRUE);
+
+ErrorExit:
+
+ printf ("File appears to be binary "
+ "(contains non-text or non-ascii characters)\n");
+ fseek (Handle, 0, SEEK_SET);
+ return (FALSE);
+}
+
+
/******************************************************************************
*
* FUNCTION: AxIsEmptyLine
@@ -196,7 +260,7 @@ AxCheckAscii (
*
******************************************************************************/
-int
+BOOLEAN
AxIsEmptyLine (
char *Buffer)
{
@@ -219,6 +283,96 @@ AxIsEmptyLine (
}
+/******************************************************************************
+ *
+ * FUNCTION: AxIsHexDataLine
+ *
+ * PARAMETERS: None
+ *
+ * RETURN: Status. 1 if the table header is valid, 0 otherwise.
+ *
+ * DESCRIPTION: Check for a valid line of hex data of the form:
+ *
+ * 00a0: 0c 00 00 00 03 00 00 00 43 48 41 35 0c 00 00 00 ........CHA5....
+ *
+ ******************************************************************************/
+
+BOOLEAN
+AxIsHexDataLine (
+ void)
+{
+
+ if (AxIsEmptyLine (Gbl_LineBuffer) ||
+ (Gbl_LineBuffer[0] != ' '))
+ {
+ return (FALSE);
+ }
+
+ if (!strstr (Gbl_LineBuffer, ": "))
+ {
+ /* Not valid data line */
+
+ return (FALSE);
+ }
+
+ return (TRUE);
+}
+
+
+/******************************************************************************
+ *
+ * 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>).
+ *
+ ******************************************************************************/
+
+BOOLEAN
+AxIsDataBlockHeader (
+ void)
+{
+
+ /* Ignore lines that are too short to be header lines */
+
+ if (strlen (Gbl_LineBuffer) < AX_MIN_BLOCK_HEADER_LENGTH)
+ {
+ return (FALSE);
+ }
+
+ /* Ignore empty lines and lines that start with a space */
+
+ if (AxIsEmptyLine (Gbl_LineBuffer) ||
+ (Gbl_LineBuffer[0] == ' '))
+ {
+ return (FALSE);
+ }
+
+ /*
+ * 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)
+ */
+ if (!AX_IS_TABLE_BLOCK_HEADER)
+ {
+ return (FALSE);
+ }
+
+ AxNormalizeSignature (Gbl_LineBuffer);
+ return (TRUE);
+}
+
+
/*******************************************************************************
*
* FUNCTION: AxNormalizeSignature
@@ -245,7 +399,7 @@ AxNormalizeSignature (
/******************************************************************************
*
- * FUNCTION: AxConvertLine
+ * FUNCTION: AxConvertToBinary
*
* PARAMETERS: InputLine - One line from the input acpidump file
* OutputData - Where the converted data is returned
@@ -254,27 +408,30 @@ AxNormalizeSignature (
*
* DESCRIPTION: Convert one line of ascii text binary (up to 16 bytes)
*
+ * NOTE: Assumes the input data line has been validated to be of the form:
+ *
+ * 0010: 48 53 57 55 4c 54 2d 52 01 00 00 00 49 4e 54 4c HSWULT-R....INTL
+ *
******************************************************************************/
size_t
-AxConvertLine (
+AxConvertToBinary (
char *InputLine,
unsigned char *OutputData)
{
- char *End;
int BytesConverted;
int Converted[16];
int i;
- /* Terminate the input line at the end of the actual data (for sscanf) */
-
- End = strstr (InputLine + 2, " ");
- if (!End)
- {
- return (0); /* Don't understand the format */
- }
- *End = 0;
+ /*
+ * Terminate input line immediately after the data. Otherwise, the
+ * second line below will not scan correctly.
+ *
+ * 00b0: 03 00 00 00 43 48 41 36 0c 00 00 00 03 00 00 00 ....CHA6........
+ * 00c0: 43 48 41 37 CHA7
+ */
+ InputLine [AX_END_OF_HEX_DATA] = 0;
/*
* Convert one line of table data, of the form:
@@ -284,7 +441,7 @@ AxConvertLine (
* 02C0: 5F 53 42 5F 4C 4E 4B 44 00 12 13 04 0C FF FF 08 _SB_LNKD........
*/
BytesConverted = sscanf (InputLine,
- "%*s %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x",
+ "%*s %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X",
&Converted[0], &Converted[1], &Converted[2], &Converted[3],
&Converted[4], &Converted[5], &Converted[6], &Converted[7],
&Converted[8], &Converted[9], &Converted[10], &Converted[11],
@@ -303,52 +460,6 @@ AxConvertLine (
/******************************************************************************
*
- * 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
- *
- ******************************************************************************/
-
-size_t
-AxGetTableHeader (
- FILE *InputFile,
- unsigned char *OutputData)
-{
- size_t BytesConverted;
- size_t TotalConverted = 0;
- int i;
-
-
- /* Get the full 36 byte ACPI table header, requires 3 input text lines */
-
- for (i = 0; i < 3; i++)
- {
- if (!fgets (Gbl_HeaderBuffer, AX_LINE_BUFFER_SIZE, InputFile))
- {
- return (TotalConverted);
- }
-
- BytesConverted = AxConvertLine (Gbl_HeaderBuffer, OutputData);
- TotalConverted += BytesConverted;
- OutputData += 16;
-
- if (BytesConverted != 16)
- {
- return (TotalConverted);
- }
- }
-
- return (TotalConverted);
-}
-
-
-/******************************************************************************
- *
* FUNCTION: AxCountTableInstances
*
* PARAMETERS: InputPathname - Filename for acpidump file
@@ -467,105 +578,154 @@ AxGetNextInstance (
/******************************************************************************
*
- * FUNCTION: AxIsDataBlockHeader
+ * FUNCTION: AxConvertAndWrite
*
- * PARAMETERS: None
+ * PARAMETERS: OutputFile - Where to write the binary data
+ * ThisSignature - Signature of current ACPI table
+ * ThisTableBytesWritten - Total count of data written
*
- * RETURN: Status. 1 if the table header is valid, 0 otherwise.
+ * RETURN: Length of the converted line
*
- * DESCRIPTION: Check if the ACPI table identifier in the input acpidump text
- * file is valid (of the form: <sig> @ <addr>).
+ * DESCRIPTION: Convert one line of input hex ascii text to binary, and write
+ * the binary data to the table output file.
+ *
+ * NOTE: Assumes the input data line has been validated to be of the form:
+ *
+ * 0010: 48 53 57 55 4c 54 2d 52 01 00 00 00 49 4e 54 4c HSWULT-R....INTL
*
******************************************************************************/
-int
-AxIsDataBlockHeader (
- void)
+long
+AxConvertAndWrite (
+ FILE *OutputFile,
+ char *ThisSignature,
+ unsigned int ThisTableBytesWritten)
{
+ size_t BytesWritten;
+ size_t BytesConverted;
- /* Ignore lines that are too short to be header lines */
- if (strlen (Gbl_LineBuffer) < AX_MIN_BLOCK_HEADER_LENGTH)
- {
- return (0);
- }
+ /* Convert one line of ascii hex data to binary */
- /* Ignore empty lines and lines that start with a space */
+ BytesConverted = AxConvertToBinary (Gbl_LineBuffer, Gbl_BinaryData);
- if (AxIsEmptyLine (Gbl_LineBuffer) ||
- (Gbl_LineBuffer[0] == ' '))
+ /* Write the binary data */
+
+ if (!BytesConverted)
{
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)
- */
- if (!strstr (Gbl_LineBuffer, " @ "))
+ BytesWritten = fwrite (Gbl_BinaryData, 1, BytesConverted, OutputFile);
+ if (BytesWritten != BytesConverted)
{
- return (0);
+ printf ("Error while writing file %s\n", Gbl_OutputFilename);
+ return (-1);
}
- AxNormalizeSignature (Gbl_LineBuffer);
- return (1);
+ return (BytesWritten);
}
/******************************************************************************
*
- * FUNCTION: AxProcessOneTextLine
+ * FUNCTION: AxDumpTableHeader
*
- * PARAMETERS: OutputFile - Where to write the binary data
- * ThisSignature - Signature of current ACPI table
- * ThisTableBytesWritten - Total count of data written
+ * PARAMETERS: Header - A binary ACPI table header
*
- * RETURN: Length of the converted line
+ * RETURN: None
*
- * DESCRIPTION: Convert one line of input hex ascii text to binary, and write
- * the binary data to the table output file.
+ * DESCRIPTION: Display the contents of a standard ACPI table header
*
******************************************************************************/
-long
-AxProcessOneTextLine (
- FILE *OutputFile,
- char *ThisSignature,
- unsigned int ThisTableBytesWritten)
+void
+AxDumpTableHeader (
+ unsigned char *Header)
{
- size_t BytesWritten;
- size_t BytesConverted;
+ ACPI_TABLE_HEADER *TableHeader = (ACPI_TABLE_HEADER *) (void *) Header;
+ ACPI_TABLE_RSDP *Rsdp = (ACPI_TABLE_RSDP *) (void *) Header;
+ ACPI_TABLE_FACS *Facs = (ACPI_TABLE_FACS *) (void *) Header;
- /* Check for the end of this table data block */
+ /* RSDP has an oddball signature and header */
- if (AxIsEmptyLine (Gbl_LineBuffer) ||
- (Gbl_LineBuffer[0] != ' '))
+ if (!strncmp (TableHeader->Signature, "RSD PTR ", 8))
{
- printf (AX_TABLE_INFO_FORMAT,
- ThisSignature, ThisTableBytesWritten, Gbl_OutputFilename);
- return (0);
+ AxCheckAscii ((char *) &Header[9], 6);
+
+ Gbl_TableCount++;
+ printf (" %.2u) %5.4s 0x%8.8X 0x%2.2X \"%6.6s\"\n",
+ Gbl_TableCount, "RSDP", Rsdp->Length, Rsdp->Revision, Rsdp->OemId);
+ return;
}
- /* Convert one line of ascii hex data to binary */
+ if (!AcpiUtValidNameseg (TableHeader->Signature))
+ {
+ return;
+ }
- BytesConverted = AxConvertLine (Gbl_LineBuffer, Gbl_BinaryData);
+ /* Signature and Table length */
- /* Write the binary data */
+ Gbl_TableCount++;
+ printf (" %.2u) %5.4s 0x%8.8X", Gbl_TableCount, TableHeader->Signature,
+ TableHeader->Length);
- BytesWritten = fwrite (Gbl_BinaryData, 1, BytesConverted, OutputFile);
- if (BytesWritten != BytesConverted)
+ /* FACS has only signature and length */
+
+ if (ACPI_COMPARE_NAME (TableHeader->Signature, "FACS"))
{
- printf ("Error while writing file %s\n", Gbl_OutputFilename);
- return (-1);
+ printf (" 0x%2.2X\n", Facs->Version);
+ return;
}
- return (BytesWritten);
+ /* OEM IDs and Compiler IDs */
+
+ AxCheckAscii (TableHeader->OemId, 6);
+ AxCheckAscii (TableHeader->OemTableId, 8);
+ AxCheckAscii (TableHeader->AslCompilerId, 4);
+
+ printf (
+ " 0x%2.2X \"%6.6s\" \"%8.8s\" 0x%8.8X"
+ " \"%4.4s\" 0x%8.8X\n",
+ TableHeader->Revision, TableHeader->OemId,
+ TableHeader->OemTableId, TableHeader->OemRevision,
+ TableHeader->AslCompilerId, TableHeader->AslCompilerRevision);
+}
+
+
+#ifdef _AX_FUTURE_ENHANCEMENTS
+
+/* Possible enhancement to validate table lengths */
+
+void
+AxCheckTableLengths (
+ UINT32 ByteCount,
+ UINT32 AmlByteCount)
+{
+
+ if (AmlByteCount == 0)
+ {
+ return;
+ }
+
+ if (ByteCount == 0)
+ {
+ return;
+ }
+
+ if ((ByteCount < sizeof (ACPI_TABLE_HEADER)) &&
+ (ByteCount >= ACPI_NAME_SIZE))
+ {
+ printf (" : (Table too short for an ACPI table)");
+ }
+
+ else if (ByteCount != AmlByteCount)
+ {
+ printf (" : (Hex data length mismatch with AML length 0x%X)",
+ AmlByteCount);
+ }
+
+ printf ("\n");
}
+#endif