From 7cf32434361d096a77b56136ecf4557443612245 Mon Sep 17 00:00:00 2001 From: Robert Moore Date: Fri, 11 Jun 2010 10:05:28 -0700 Subject: [PATCH] iASL-DTC: Add comment support, fix error messages. Adds full support for comments within input source files. Fixed a couple error messages one for unknown table signature, another for unrecognized source file (not asl or data table source.) Also, reduced verbosity of the standard templates, but added option (-vt) to make the output look exactly like the disassembler. --- source/common/dmtable.c | 66 ++++++--- source/compiler/aslglobal.h | 4 +- source/compiler/aslmain.c | 16 ++- source/compiler/dtcompile.c | 32 +++-- source/compiler/dtio.c | 250 ++++++++++++++++++++++++++++++----- source/compiler/dttemplate.c | 26 +++- source/include/acoutput.h | 3 +- 7 files changed, 333 insertions(+), 64 deletions(-) diff --git a/source/common/dmtable.c b/source/common/dmtable.c index 9d4609328..1c8acd89d 100644 --- a/source/common/dmtable.c +++ b/source/common/dmtable.c @@ -117,6 +117,7 @@ #include "accommon.h" #include "acdisasm.h" #include "actables.h" +#include "aslcompiler.h" #include "dtcompiler.h" /* This module used for application-level code only */ @@ -498,10 +499,13 @@ AcpiDmDumpDataTable ( } } - /* Always dump the raw table data */ + if (!Gbl_DoTemplates || Gbl_VerboseTemplates) + { + /* Dump the raw table data */ - AcpiOsPrintf ("\nRaw Table Data\n\n"); - AcpiUtDumpBuffer2 (ACPI_CAST_PTR (UINT8, Table), Length, DB_BYTE_DISPLAY); + AcpiOsPrintf ("\nRaw Table Data\n\n"); + AcpiUtDumpBuffer2 (ACPI_CAST_PTR (UINT8, Table), Length, DB_BYTE_DISPLAY); + } } @@ -529,15 +533,31 @@ AcpiDmLineHeader ( char *Name) { - if (ByteLength) + if (Gbl_DoTemplates && !Gbl_VerboseTemplates) /* Terse template */ { - AcpiOsPrintf ("[%3.3Xh %4.4d% 3d] %28s : ", - Offset, Offset, ByteLength, Name); + if (ByteLength) + { + AcpiOsPrintf ("[%.3d] %34s : ", + ByteLength, Name); + } + else + { + AcpiOsPrintf ("%40s : ", + Name); + } } - else + else /* Normal disassembler or verbose template */ { - AcpiOsPrintf ("%43s : ", - Name); + if (ByteLength) + { + AcpiOsPrintf ("[%3.3Xh %4.4d% 3d] %28s : ", + Offset, Offset, ByteLength, Name); + } + else + { + AcpiOsPrintf ("%43s : ", + Name); + } } } @@ -549,15 +569,31 @@ AcpiDmLineHeader2 ( UINT32 Value) { - if (ByteLength) + if (Gbl_DoTemplates && !Gbl_VerboseTemplates) /* Terse template */ { - AcpiOsPrintf ("[%3.3Xh %4.4d% 3d] %24s % 3d : ", - Offset, Offset, ByteLength, Name, Value); + if (ByteLength) + { + AcpiOsPrintf ("[%.3d] %30s % 3d : ", + ByteLength, Name, Value); + } + else + { + AcpiOsPrintf ("%36s % 3d : ", + Name, Value); + } } - else + else /* Normal disassembler or verbose template */ { - AcpiOsPrintf ("[%3.3Xh %4.4d ] %24s % 3d : ", - Offset, Offset, Name, Value); + if (ByteLength) + { + AcpiOsPrintf ("[%3.3Xh %4.4d% 3d] %24s % 3d : ", + Offset, Offset, ByteLength, Name, Value); + } + else + { + AcpiOsPrintf ("[%3.3Xh %4.4d ] %24s % 3d : ", + Offset, Offset, Name, Value); + } } } diff --git a/source/compiler/aslglobal.h b/source/compiler/aslglobal.h index 6df7466af..9e3dbac63 100644 --- a/source/compiler/aslglobal.h +++ b/source/compiler/aslglobal.h @@ -198,6 +198,8 @@ ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_DisplayOptimizations, F ASL_EXTERN UINT8 ASL_INIT_GLOBAL (Gbl_WarningLevel, ASL_WARNING); ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_UseOriginalCompilerId, FALSE); ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_DataTableCompilerAvailable, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_VerboseTemplates, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_DoTemplates, FALSE); #define HEX_OUTPUT_NONE 0 @@ -252,7 +254,7 @@ ASL_EXTERN char ASL_INIT_GLOBAL (*Gbl_StringCacheLast, NULL) ASL_EXTERN ACPI_PARSE_OBJECT *Gbl_FirstLevelInsertionNode; ASL_EXTERN UINT8 ASL_INIT_GLOBAL (Gbl_FileType, 0); ASL_EXTERN char ASL_INIT_GLOBAL (*Gbl_Signature, NULL); - +ASL_EXTERN char *Gbl_TemplateSignature; ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_CurrentHexColumn, 0); ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_CurrentAmlOffset, 0); diff --git a/source/compiler/aslmain.c b/source/compiler/aslmain.c index 3ad999d6a..dae880813 100644 --- a/source/compiler/aslmain.c +++ b/source/compiler/aslmain.c @@ -220,6 +220,7 @@ Options ( printf ("\nACPI Data Tables:\n"); printf (" -T [Sig] Create table template for Sig (or \"ALL\")\n"); + printf (" -vt Create verbose templates (full disassembly)\n"); printf ("\nAML Disassembler:\n"); printf (" -d [file] Disassemble or decode binary ACPI table to file (*.dsl)\n"); @@ -773,8 +774,9 @@ AslDoOptions ( case 'T': - DtCreateTemplates (AcpiGbl_Optarg); - exit (1); + Gbl_DoTemplates = TRUE; + Gbl_TemplateSignature = AcpiGbl_Optarg; + break; case 'v': @@ -805,6 +807,10 @@ AslDoOptions ( Gbl_DoSignon = FALSE; break; + case 't': + Gbl_VerboseTemplates = TRUE; + break; + default: printf ("Unknown option: -v%s\n", AcpiGbl_Optarg); return (-1); @@ -895,6 +901,12 @@ AslCommandLine ( BadCommandLine = AslDoOptions (argc, argv, FALSE); + if (Gbl_DoTemplates) + { + DtCreateTemplates (Gbl_TemplateSignature); + exit (1); + } + /* Next parameter must be the input filename */ if (!argv[AcpiGbl_Optind] && diff --git a/source/compiler/dtcompile.c b/source/compiler/dtcompile.c index 43b48c937..7de14f7e6 100644 --- a/source/compiler/dtcompile.c +++ b/source/compiler/dtcompile.c @@ -183,8 +183,10 @@ DtDoCompile ( /* TBD: temporary error message. Msgs should come from function above */ DtError (ASL_ERROR, ASL_MSG_SYNTAX, NULL, - "Could not parse input file"); - return (AE_ERROR); + "Input file does not appear to be an ASL or data table source file"); + + Status = AE_ERROR; + goto CleanupAndExit; } Event = UtBeginEvent ("Compile parse tree"); @@ -203,6 +205,7 @@ DtDoCompile ( DtError (ASL_ERROR, ASL_MSG_SYNTAX, NULL, "Could not compile input file"); + goto CleanupAndExit; } @@ -245,6 +248,9 @@ DtInitialize ( void) { + AcpiOsInitialize (); + AcpiUtInitGlobals (); + Gbl_FieldList = NULL; Gbl_RootTable = NULL; Gbl_SubtableStack = NULL; @@ -328,7 +334,9 @@ DtCompileDataTable ( Signature = DtGetFieldValue (*FieldList, "Signature"); if (!Signature) { - DtError (ASL_ERROR, ASL_MSG_TABLE_SIGNATURE, *FieldList, NULL); + sprintf (MsgBuffer, "Expected \"%s\"", "Signature"); + DtNameError (ASL_ERROR, ASL_MSG_INVALID_FIELD_NAME, + *FieldList, MsgBuffer); return (AE_ERROR); } @@ -362,6 +370,15 @@ DtCompileDataTable ( return (AE_ERROR); } + /* Validate the signature via the ACPI table list */ + + TableData = AcpiDmGetTableData (Signature); + if (!TableData) + { + DtFatal (ASL_MSG_UNKNOWN_TABLE, *FieldList, Signature); + return (AE_ERROR); + } + /* * All other tables must use the common ACPI table header. Insert the * current iASL IDs (name, version), and compile the header now. @@ -377,14 +394,7 @@ DtCompileDataTable ( DtPushSubtable (Gbl_RootTable); - /* Match signature and dispatch appropriately */ - - TableData = AcpiDmGetTableData (Signature); - if (!TableData) - { - DtFatal (ASL_MSG_UNKNOWN_TABLE, *FieldList, Signature); - return (AE_ERROR); - } + /* Dispatch to per-table compile */ if (TableData->CmTableHandler) { diff --git a/source/compiler/dtio.c b/source/compiler/dtio.c index 469cea609..4c19ad0b0 100644 --- a/source/compiler/dtio.c +++ b/source/compiler/dtio.c @@ -122,33 +122,43 @@ ACPI_MODULE_NAME ("dtio") -/****************************************************************************** - * - * FUNCTION: DtIsComment - * - * PARAMETERS: Line - Current source code line - * - * RETURN: TRUE if comment, FALSE otherwise - * - * DESCRIPTION: Detect a comment in the source module - * - *****************************************************************************/ +/* Local prototypes */ -/* TBD: Temporary: very simple code to detect comments */ +static char * +DtTrim ( + char *String); -static int -DtIsComment( - char *Line) -{ +static void +DtLinkField ( + DT_FIELD *Field); - if (!ACPI_STRNCMP (Line, "/*", 2) || - !ACPI_STRNCMP (Line, " *", 2)) - { - return 1; - } +static void +DtParseLine ( + char *LineBuffer, + UINT32 Line, + UINT32 Offset); - return 0; -} +static UINT32 +DtGetNextLine ( + FILE *Handle); + +static void +DtWriteBinary ( + DT_SUBTABLE *Subtable, + 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 + +UINT32 Gbl_NextLineOffset; /****************************************************************************** @@ -308,7 +318,7 @@ DtParseLine ( UINT32 NameColumn; - if (!LineBuffer || DtIsComment (LineBuffer)) + if (!LineBuffer) { return; } @@ -415,6 +425,177 @@ DtParseLine ( } +/****************************************************************************** + * + * FUNCTION: DtGetNextLine + * + * PARAMETERS: Handle - Open file handle for the source file + * + * RETURN: Filled line buffer and offset of start-of-line (zero 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. + * + *****************************************************************************/ + +static UINT32 +DtGetNextLine ( + FILE *Handle) +{ + UINT32 State = DT_NORMAL_TEXT; + UINT32 CurrentLineOffset; + UINT32 i; + char c; + + + for (i = 0; i < ASL_LINE_BUFFER_SIZE;) + { + c = (char) getc (Handle); + if (c == EOF) + { + return (0); + } + + switch (State) + { + case DT_NORMAL_TEXT: + + /* Normal text, insert char into line buffer */ + + Gbl_CurrentLineBuffer[i] = c; + switch (c) + { + case '/': + State = DT_START_COMMENT; + break; + + case '"': + State = DT_START_QUOTED_STRING; + i++; + break; + + case '\n': + CurrentLineOffset = Gbl_NextLineOffset; + Gbl_NextLineOffset = (UINT32) ftell (Handle); + Gbl_CurrentLineNumber++; + + /* Exit if line is complete. Ignore blank lines */ + + if (i != 0) + { + Gbl_CurrentLineBuffer[i+1] = 0; /* Terminate line */ + return (CurrentLineOffset); + } + break; + + default: + i++; + break; + } + break; + + case DT_START_QUOTED_STRING: + + /* Insert raw chars until end of quoted string */ + + Gbl_CurrentLineBuffer[i] = c; + i++; + + if (c == '"') + { + State = DT_NORMAL_TEXT; + } + break; + + case DT_START_COMMENT: + + /* Open comment if this character is an asterisk or slash */ + + switch (c) + { + case '*': + State = DT_SLASH_ASTERISK_COMMENT; + break; + + case '/': + State = DT_SLASH_SLASH_COMMENT; + break; + + default: /* Not a comment */ + i++; /* Save the preceeding slash */ + Gbl_CurrentLineBuffer[i] = c; + i++; + State = DT_NORMAL_TEXT; + break; + } + break; + + case DT_SLASH_ASTERISK_COMMENT: + + /* Ignore chars until an asterisk-slash is found */ + + switch (c) + { + case '\n': + Gbl_NextLineOffset = (UINT32) ftell (Handle); + Gbl_CurrentLineNumber++; + break; + + case '*': + State = DT_END_COMMENT; + 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 */ + + ungetc (c, Handle); + State = DT_NORMAL_TEXT; + } + break; + + case DT_END_COMMENT: + + /* End comment if this char is a slash */ + + switch (c) + { + case '/': + State = DT_NORMAL_TEXT; + break; + + default: + State = DT_SLASH_ASTERISK_COMMENT; + break; + } + break; + + default: + DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, "Unknown input state"); + return (0); + } + } + + printf ("ERROR - Input line is too long (max %u)\n", ASL_LINE_BUFFER_SIZE); + return (0); +} + + /****************************************************************************** * * FUNCTION: DtScanFile @@ -423,7 +604,7 @@ DtParseLine ( * * RETURN: Pointer to start of the constructed parse tree. * - * DESCRIPTION: Scan source file, link all field name and value + * DESCRIPTION: Scan source file, link all field names and values * to the global parse tree: Gbl_FieldList * *****************************************************************************/ @@ -432,23 +613,28 @@ DT_FIELD * DtScanFile ( FILE *Handle) { - UINT32 Line = 0; - UINT32 Offset = 0; + UINT32 Offset; + + + ACPI_FUNCTION_NAME (DtScanFile); /* Get the file size */ Gbl_InputByteCount = DtGetFileSize (Handle); + Gbl_CurrentLineNumber = 0; + Gbl_CurrentLineOffset = 0; + Gbl_NextLineOffset = 0; + /* Scan line-by-line */ - while (fgets (Gbl_CurrentLineBuffer, ASL_LINE_BUFFER_SIZE, Handle)) + while ((Offset = DtGetNextLine (Handle))) { - Line++; - Gbl_CurrentLineNumber++; - DtParseLine (Gbl_CurrentLineBuffer, Line, Offset); + ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Line %2.2u/%4.4X - %s", + Gbl_CurrentLineNumber, Offset, Gbl_CurrentLineBuffer)); - Offset = (UINT32) ftell (Handle); + DtParseLine (Gbl_CurrentLineBuffer, Gbl_CurrentLineNumber, Offset); } return (Gbl_FieldList); diff --git a/source/compiler/dttemplate.c b/source/compiler/dttemplate.c index 2a5c65941..ad69a14c2 100644 --- a/source/compiler/dttemplate.c +++ b/source/compiler/dttemplate.c @@ -211,6 +211,19 @@ DtCreateTemplates ( return (AE_ERROR); } + /* + * Some slack for the two strange tables whose name is different than + * their signatures: MADT->APIC and FADT->FACP. + */ + if (!strcmp (Signature, "MADT")) + { + Signature = "APIC"; + } + else if (!strcmp (Signature, "FADT")) + { + Signature = "FACP"; + } + TableData = AcpiDmGetTableData (Signature); if (TableData) { @@ -376,8 +389,17 @@ DtCreateOneTemplate ( { /* Normal case, tables that appear in AcpiDmTableData */ - AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength]" - " FieldName : FieldValue\n */\n\n"); + if (Gbl_VerboseTemplates) + { + AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength]" + " FieldName : HexFieldValue\n */\n\n"); + } + else + { + AcpiOsPrintf (" * Format: [ByteLength]" + " FieldName : HexFieldValue\n */\n\n"); + } + AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER, TableData->Template)); } diff --git a/source/include/acoutput.h b/source/include/acoutput.h index 8fca0de33..61884f14d 100644 --- a/source/include/acoutput.h +++ b/source/include/acoutput.h @@ -143,8 +143,9 @@ #define ACPI_TOOLS 0x00002000 #define ACPI_EXAMPLE 0x00004000 #define ACPI_DRIVER 0x00008000 +#define DT_COMPILER 0x00010000 -#define ACPI_ALL_COMPONENTS 0x0000FFFF +#define ACPI_ALL_COMPONENTS 0x0001FFFF #define ACPI_COMPONENT_DEFAULT (ACPI_ALL_COMPONENTS) /* Component IDs reserved for ACPI drivers */