dtio.c revision 199767f8919635c4928607450d9e0abb932109ce
/******************************************************************************
*
* Module Name: dtio.c - File I/O support for data table compiler
*
*****************************************************************************/
/*
* 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.
*/
#define _COMPONENT DT_COMPILER
ACPI_MODULE_NAME ("dtio")
/* Local prototypes */
static char *
DtTrim (
char *String);
static void
static ACPI_STATUS
char *LineBuffer,
static void
void *Context,
void *ReturnValue);
static void
static void
void *Context,
void *ReturnValue);
static void
void *Context,
void *ReturnValue);
/* States for DtGetNextLine */
#define DT_NORMAL_TEXT 0
#define DT_START_QUOTED_STRING 1
#define DT_START_COMMENT 2
#define DT_SLASH_ASTERISK_COMMENT 3
#define DT_SLASH_SLASH_COMMENT 4
#define DT_END_COMMENT 5
#define DT_MERGE_LINES 6
#define DT_ESCAPE_SEQUENCE 7
static UINT32 Gbl_NextLineOffset;
/******************************************************************************
*
* FUNCTION: DtTrim
*
* PARAMETERS: String - Current source code line to trim
*
* RETURN: Trimmed line. Must be freed by caller.
*
* DESCRIPTION: Trim left and right spaces
*
*****************************************************************************/
static char *
DtTrim (
char *String)
{
char *Start;
char *End;
char *ReturnString;
/* Skip lines that start with a space */
{
return (ReturnString);
}
/* Setup pointers to start and end of input string */
/* Find first non-whitespace character */
{
Start++;
}
/* Find last non-space character */
{
{
End--;
continue;
}
if (*End != ' ')
{
break;
}
End--;
}
/* Remove any quotes around the string */
if (*Start == '\"')
{
Start++;
}
if (*End == '\"')
{
End--;
}
/* Create the trimmed return string */
{
}
ReturnString[Length] = 0;
return (ReturnString);
}
/******************************************************************************
*
* FUNCTION: DtLinkField
*
* PARAMETERS: Field - New field object to link
*
* RETURN: None
*
* DESCRIPTION: Link one field name and value to the list
*
*****************************************************************************/
static void
{
while (Next)
{
}
if (Prev)
{
}
else
{
}
}
/******************************************************************************
*
* FUNCTION: DtParseLine
*
* PARAMETERS: LineBuffer - Current source code line
* Line - Current line number in the source
* Offset - Current byte offset of the line
*
* RETURN: Status
*
* DESCRIPTION: Parse one source line
*
*****************************************************************************/
static ACPI_STATUS
char *LineBuffer,
{
char *Start;
char *End;
char *TmpName;
char *TmpValue;
char *Name;
char *Value;
char *Colon;
if (!LineBuffer)
{
return (AE_OK);
}
/* All lines after "Raw Table Data" are ingored */
{
return (AE_NOT_FOUND);
}
if (!Colon)
{
return (AE_OK);
}
Start = LineBuffer;
{
if (*Start == '[')
{
/* Found left bracket, go to the right bracket */
{
Start++;
}
}
else if (*Start != ' ')
{
break;
}
Start++;
}
/*
* There are two column values. One for the field name,
* and one for the field value.
*/
while (*End)
{
/* Found left quotation, go to the right quotation and break */
if (*End == '"')
{
End++;
/* Check for an explicit null string */
if (*End == '"')
{
IsNullString = TRUE;
}
{
End++;
}
End++;
break;
}
/*
* Special "comment" fields at line end, ignore them.
* Note: normal slash-slash and slash-asterisk comments are
* stripped already by the DtGetNextLine parser.
*
* TBD: Perhaps DtGetNextLine should parse the following type
* of comments also.
*/
if (*End == '[')
{
End--;
break;
}
End++;
}
/* Create a new field object only if we have a valid value field */
{
Field = UtFieldCacheCalloc ();
DtLinkField (Field);
}
/* Else -- Ignore this field, it has no valid data */
return (AE_OK);
}
/******************************************************************************
*
* FUNCTION: DtGetNextLine
*
* PARAMETERS: Handle - Open file handle for the source file
*
* RETURN: Filled line buffer and offset of start-of-line (ASL_EOF on EOF)
*
* DESCRIPTION: Get the next valid source line. Removes all comments.
* Ignores empty lines.
*
* Handles both slash-asterisk and slash-slash comments.
* Also, quoted strings, but no escapes within.
*
* Line is returned in Gbl_CurrentLineBuffer.
* Line number in original file is returned in Gbl_CurrentLineNumber.
*
*****************************************************************************/
{
UINT32 i;
int c;
for (i = 0; ;)
{
/*
* If line is too long, expand the line buffers. Also increases
* Gbl_LineBufferSize.
*/
if (i >= Gbl_LineBufferSize)
{
}
if (c == EOF)
{
switch (State)
{
case DT_START_QUOTED_STRING:
break;
default:
break;
}
/* Standalone EOF is OK */
if (i == 0)
{
return (ASL_EOF);
}
/*
* Received an EOF in the middle of a line. Terminate the
* line with a newline. The next call to this function will
* return a standalone EOF. Thus, the upper parsing software
* never has to deal with an EOF within a valid line (or
* the last line does not get tossed on the floor.)
*/
c = '\n';
}
switch (State)
{
case DT_NORMAL_TEXT:
/* Normal text, insert char into line buffer */
Gbl_CurrentLineBuffer[i] = (char) c;
switch (c)
{
case '/':
break;
case '"':
i++;
break;
case '\\':
/*
* The continuation char MUST be last char on this line.
* Otherwise, it will be assumed to be a valid ASL char.
*/
break;
case '\n':
/*
* Exit if line is complete. Ignore empty lines (only \n)
* or lines that contain nothing but blanks.
*/
if ((i != 0) && LineNotAllBlanks)
{
if ((i + 1) >= Gbl_LineBufferSize)
{
}
return (CurrentLineOffset);
}
/* Toss this line and start a new one */
i = 0;
break;
default:
if (c != ' ')
{
}
i++;
break;
}
break;
case DT_START_QUOTED_STRING:
/* Insert raw chars until end of quoted string */
Gbl_CurrentLineBuffer[i] = (char) c;
i++;
switch (c)
{
case '"':
break;
case '\\':
break;
case '\n':
if (!(Flags & DT_ALLOW_MULTILINE_QUOTES))
{
AcpiOsPrintf ("ERROR at line %u: Unterminated quoted string\n",
}
break;
default: /* Get next character */
break;
}
break;
case DT_ESCAPE_SEQUENCE:
/* Just copy the escaped character. TBD: sufficient for table compiler? */
Gbl_CurrentLineBuffer[i] = (char) c;
i++;
break;
case DT_START_COMMENT:
/* Open comment if this character is an asterisk or slash */
switch (c)
{
case '*':
break;
case '/':
break;
default: /* Not a comment */
i++; /* Save the preceding slash */
if (i >= Gbl_LineBufferSize)
{
}
Gbl_CurrentLineBuffer[i] = (char) c;
i++;
break;
}
break;
/* Ignore chars until an asterisk-slash is found */
switch (c)
{
case '\n':
break;
case '*':
break;
default:
break;
}
break;
case DT_SLASH_SLASH_COMMENT:
/* Ignore chars until end-of-line */
if (c == '\n')
{
/* We will exit via the NORMAL_TEXT path */
}
break;
case DT_END_COMMENT:
/* End comment if this char is a slash */
switch (c)
{
case '/':
break;
case '\n':
break;
case '*':
/* Consume all adjacent asterisks */
break;
default:
break;
}
break;
case DT_MERGE_LINES:
if (c != '\n')
{
/*
* This is not a continuation backslash, it is a normal
* normal ASL backslash - for example: Scope(\_SB_)
*/
i++; /* Keep the backslash that is already in the buffer */
}
else
{
/*
* This is a continuation line -- a backlash followed
* immediately by a newline. Insert a space between the
* lines (overwrite the backslash)
*/
Gbl_CurrentLineBuffer[i] = ' ';
i++;
/* Ignore newline, this will merge the lines */
}
break;
default:
return (ASL_EOF);
}
}
}
/******************************************************************************
*
* FUNCTION: DtScanFile
*
* PARAMETERS: Handle - Open file handle for the source file
*
* RETURN: Pointer to start of the constructed parse tree.
*
* DESCRIPTION: Scan source file, link all field names and values
* to the global parse tree: Gbl_FieldList
*
*****************************************************************************/
DT_FIELD *
{
/* Get the file size */
if (Gbl_InputByteCount == ACPI_UINT32_MAX)
{
AslAbort ();
}
Gbl_NextLineOffset = 0;
/* Scan line-by-line */
{
if (Status == AE_NOT_FOUND)
{
break;
}
}
/* Dump the parse tree if debug enabled */
return (Gbl_FieldList);
}
/*
* Output functions
*/
/******************************************************************************
*
* FUNCTION: DtWriteBinary
*
* PARAMETERS: DT_WALK_CALLBACK
*
* RETURN: Status
*
* DESCRIPTION: Write one subtable of a binary ACPI table
*
*****************************************************************************/
static void
void *Context,
void *ReturnValue)
{
}
/******************************************************************************
*
* FUNCTION: DtOutputBinary
*
* PARAMETERS:
*
* RETURN: Status
*
* DESCRIPTION: Write entire binary ACPI table (result of compilation)
*
*****************************************************************************/
void
{
if (!RootTable)
{
return;
}
/* Walk the entire parse tree, emitting the binary data */
if (Gbl_TableLength == ACPI_UINT32_MAX)
{
AslAbort ();
}
}
/*
* Listing support
*/
/******************************************************************************
*
* FUNCTION: DtDumpBuffer
*
* PARAMETERS: FileID - Where to write buffer data
* Buffer - Buffer to dump
* Offset - Offset in current table
* Length - Buffer Length
*
* RETURN: None
*
* DESCRIPTION: Another copy of DumpBuffer routine (unfortunately).
*
* TBD: merge dump buffer routines
*
*****************************************************************************/
static void
{
UINT32 i;
UINT32 j;
i = 0;
while (i < Length)
{
if (i >= 16)
{
}
/* Print 16 hex chars */
for (j = 0; j < 16;)
{
if (i + j >= Length)
{
/* Dump fill spaces */
j++;
continue;
}
j++;
}
for (j = 0; j < 16; j++)
{
if (i + j >= Length)
{
return;
}
{
}
else
{
}
}
/* Done with that line. */
i += 16;
}
}
/******************************************************************************
*
* FUNCTION: DtDumpFieldList
*
* PARAMETERS: Field - Root field
*
* RETURN: None
*
* DESCRIPTION: Dump the entire field list
*
*****************************************************************************/
void
{
if (!Gbl_DebugFlag || !Field)
{
return;
}
"LineNo ByteOff NameCol Column TableOff "
"Flags %32s : %s\n\n", "Name", "Value");
while (Field)
{
"%.08X %.08X %.08X %.08X %.08X %2.2X %32s : %s\n",
}
}
/******************************************************************************
*
* FUNCTION: DtDumpSubtableInfo, DtDumpSubtableTree
*
* PARAMETERS: DT_WALK_CALLBACK
*
* RETURN: None
*
* DESCRIPTION: Info - dump a subtable tree entry with extra information.
* Tree - dump a subtable tree formatted by depth indentation.
*
*****************************************************************************/
static void
void *Context,
void *ReturnValue)
{
"[%.04X] %24s %.08X %.08X %.08X %.08X %.08X %p %p %p\n",
}
static void
void *Context,
void *ReturnValue)
{
"[%.04X] %24s %*s%08X (%.02X) - (%.02X)\n",
}
/******************************************************************************
*
* FUNCTION: DtDumpSubtableList
*
* PARAMETERS: None
*
* RETURN: None
*
* DESCRIPTION: Dump the raw list of subtables with information, and also
* dump the subtable list in formatted tree format. Assists with
* the development of new table code.
*
*****************************************************************************/
void
void)
{
if (!Gbl_DebugFlag || !Gbl_RootTable)
{
return;
}
"Subtable Info:\n"
"Depth Name Length TotalLen LenSize Flags "
"This Parent Child Peer\n\n");
"\nSubtable Tree: (Depth, Name, Subtable, Length, TotalLength)\n\n");
}
/******************************************************************************
*
* FUNCTION: DtWriteFieldToListing
*
* PARAMETERS: Buffer - Contains the compiled data
* Field - Field node for the input line
* Length - Length of the output data
*
* RETURN: None
*
* DESCRIPTION: Write one field to the listing file (if listing is enabled).
*
*****************************************************************************/
void
{
if (!Gbl_ListingFlag || !Field)
{
return;
}
/* Dump the original source line */
{
if (FileByte == '\n')
{
break;
}
}
/* Dump the line as parsed and represented internally */
{
}
/* Dump the hex data that will be output for this field */
}
/******************************************************************************
*
* FUNCTION: DtWriteTableToListing
*
* PARAMETERS: None
*
* RETURN: None
*
* DESCRIPTION: Write the entire compiled table to the listing file
* in hex format
*
*****************************************************************************/
void
void)
{
if (!Gbl_ListingFlag)
{
return;
}
/* Read the entire table from the output file */
/* Dump the raw table data */
AcpiOsPrintf ("\n%s: Length %d (0x%X)\n\n",
}