diff options
author | Robert Moore <Robert.Moore@intel.com> | 2013-03-15 09:27:23 -0700 |
---|---|---|
committer | Robert Moore <Robert.Moore@intel.com> | 2013-03-15 09:27:23 -0700 |
commit | c79891a16a598cfeb1358fc3b3a84b760dfbfd88 (patch) | |
tree | 0498bf1d0fdbee380175993ba019436d2ae0c3c0 | |
parent | b8cdd5211cb6af3690ddcfabb33bfc4a83f3d96d (diff) |
iASL: Add support for an "offset table" output file.
The -so option will create a C table containing offsets of various
named objects so that BIOS code can modifiy them easily at boot
time. Simplifies BIOS code and provides greater reliability.
-rwxr-xr-x | generate/msvc9/AslCompiler.vcproj | 8 | ||||
-rw-r--r-- | generate/unix/iasl/Makefile | 2 | ||||
-rw-r--r-- | source/compiler/aslcompile.c | 3 | ||||
-rw-r--r-- | source/compiler/aslcompiler.h | 71 | ||||
-rw-r--r-- | source/compiler/asldefine.h | 6 | ||||
-rw-r--r-- | source/compiler/aslerror.c | 28 | ||||
-rw-r--r-- | source/compiler/aslfiles.c | 21 | ||||
-rw-r--r-- | source/compiler/aslglobal.h | 4 | ||||
-rw-r--r-- | source/compiler/asllisting.c | 844 | ||||
-rw-r--r-- | source/compiler/asllistsup.c | 778 | ||||
-rw-r--r-- | source/compiler/aslmain.c | 8 | ||||
-rw-r--r-- | source/compiler/asloffset.c | 398 | ||||
-rw-r--r-- | source/compiler/aslresource.c | 1 | ||||
-rw-r--r-- | source/compiler/asltypes.h | 5 |
14 files changed, 1434 insertions, 743 deletions
diff --git a/generate/msvc9/AslCompiler.vcproj b/generate/msvc9/AslCompiler.vcproj index acb263593..d3485a285 100755 --- a/generate/msvc9/AslCompiler.vcproj +++ b/generate/msvc9/AslCompiler.vcproj @@ -1068,6 +1068,10 @@ </FileConfiguration> </File> <File + RelativePath="..\..\source\compiler\asllistsup.c" + > + </File> + <File RelativePath="..\..\source\compiler\aslload.c" > <FileConfiguration @@ -1164,6 +1168,10 @@ > </File> <File + RelativePath="..\..\source\compiler\asloffset.c" + > + </File> + <File RelativePath="..\..\source\compiler\aslopcodes.c" > <FileConfiguration diff --git a/generate/unix/iasl/Makefile b/generate/unix/iasl/Makefile index 3f347f80f..e7761c276 100644 --- a/generate/unix/iasl/Makefile +++ b/generate/unix/iasl/Makefile @@ -58,12 +58,14 @@ OBJECTS = \ $(OBJDIR)/aslhex.o\ $(OBJDIR)/asllength.o\ $(OBJDIR)/asllisting.o\ + $(OBJDIR)/asllistsup.o\ $(OBJDIR)/aslload.o\ $(OBJDIR)/asllookup.o\ $(OBJDIR)/aslmain.o\ $(OBJDIR)/aslmap.o\ $(OBJDIR)/aslmethod.o\ $(OBJDIR)/aslnamesp.o\ + $(OBJDIR)/asloffset.o\ $(OBJDIR)/aslopcodes.o\ $(OBJDIR)/asloperands.o\ $(OBJDIR)/aslopt.o\ diff --git a/source/compiler/aslcompile.c b/source/compiler/aslcompile.c index eae5e9fd8..436a392c5 100644 --- a/source/compiler/aslcompile.c +++ b/source/compiler/aslcompile.c @@ -198,6 +198,7 @@ AslCompilerSignon ( break; case ASL_FILE_C_SOURCE_OUTPUT: + case ASL_FILE_C_OFFSET_OUTPUT: case ASL_FILE_C_INCLUDE_OUTPUT: Prefix = " * "; @@ -271,6 +272,7 @@ AslCompilerFileHeader ( break; case ASL_FILE_C_SOURCE_OUTPUT: + case ASL_FILE_C_OFFSET_OUTPUT: case ASL_FILE_C_INCLUDE_OUTPUT: Prefix = " * "; @@ -294,6 +296,7 @@ AslCompilerFileHeader ( switch (FileId) { case ASL_FILE_C_SOURCE_OUTPUT: + case ASL_FILE_C_OFFSET_OUTPUT: case ASL_FILE_C_INCLUDE_OUTPUT: FlPrintFile (FileId, " */\n"); break; diff --git a/source/compiler/aslcompiler.h b/source/compiler/aslcompiler.h index 2b774f1b4..4c2bfcb87 100644 --- a/source/compiler/aslcompiler.h +++ b/source/compiler/aslcompiler.h @@ -422,22 +422,65 @@ LsDoListings ( void); void +LsWriteNodeToAsmListing ( + ACPI_PARSE_OBJECT *Op); + +void +LsWriteNode ( + ACPI_PARSE_OBJECT *Op, + UINT32 FileId); + +void +LsDumpParseTree ( + void); + + +/* + * asllistsup - Listing file support utilities + */ +void +LsDumpAscii ( + UINT32 FileId, + UINT32 Count, + UINT8 *Buffer); + +void LsDumpAsciiInComment ( UINT32 FileId, UINT32 Count, UINT8 *Buffer); void -LsWriteNodeToAsmListing ( - ACPI_PARSE_OBJECT *Op); +LsCheckException ( + UINT32 LineNumber, + UINT32 FileId); void -LsWriteNode ( - ACPI_PARSE_OBJECT *Op, +LsFlushListingBuffer ( UINT32 FileId); void -LsDumpParseTree ( +LsWriteListingHexBytes ( + UINT8 *Buffer, + UINT32 Length, + UINT32 FileId); + +void +LsWriteSourceLines ( + UINT32 ToLineNumber, + UINT32 ToLogicalLineNumber, + UINT32 FileId); + +UINT32 +LsWriteOneSourceLine ( + UINT32 FileId); + +void +LsPushNode ( + char *Filename); + +ASL_LISTING_NODE * +LsPopNode ( void); @@ -460,6 +503,24 @@ OpcAmlConstantWalk ( /* + * asloffset - generate C offset file for BIOS support + */ +ACPI_STATUS +LsAmlOffsetWalk ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + +void +LsDoOffsetTableHeader ( + UINT32 FileId); + +void +LsDoOffsetTableFooter ( + UINT32 FileId); + + +/* * aslopcodes - generate AML opcodes */ ACPI_STATUS diff --git a/source/compiler/asldefine.h b/source/compiler/asldefine.h index d3aae3046..4920f002e 100644 --- a/source/compiler/asldefine.h +++ b/source/compiler/asldefine.h @@ -192,6 +192,7 @@ #define FILE_SUFFIX_ASM_INCLUDE "inc" #define FILE_SUFFIX_C_INCLUDE "h" #define FILE_SUFFIX_ASL_CODE "asl" +#define FILE_SUFFIX_C_OFFSET "offset.h" /* Types for input files */ @@ -210,6 +211,11 @@ #define ASL_EOF ACPI_UINT32_MAX +/* Listings */ + +#define ASL_LISTING_LINE_PREFIX ": " + + /* Support for reserved method names */ #define ACPI_VALID_RESERVED_NAME_MAX 0x80000000 diff --git a/source/compiler/aslerror.c b/source/compiler/aslerror.c index e515fda58..01a201354 100644 --- a/source/compiler/aslerror.c +++ b/source/compiler/aslerror.c @@ -374,12 +374,25 @@ AePrintException ( } else { - while (RActual && SourceByte && (SourceByte != '\n') && (Total < 256)) + /* Read/write the source line, up to the maximum line length */ + + while (RActual && SourceByte && (SourceByte != '\n')) { - if (fwrite (&SourceByte, 1, 1, OutputFile) != 1) + if (Total < 256) { - printf ("[*** iASL: Write error on output file ***]\n"); - return; + /* After the max line length, we will just read the line, no write */ + + if (fwrite (&SourceByte, 1, 1, OutputFile) != 1) + { + printf ("[*** iASL: Write error on output file ***]\n"); + return; + } + } + else if (Total == 256) + { + fprintf (OutputFile, + "\n[*** iASL: Very long input line, message below refers to column %u ***]", + Enode->Column); } RActual = fread (&SourceByte, 1, 1, SourceFile); @@ -392,13 +405,6 @@ AePrintException ( } Total++; } - - if (Total >= 256) - { - fprintf (OutputFile, - "\n[*** iASL: Long input line, an error occurred at column %u ***]", - Enode->Column); - } } } } diff --git a/source/compiler/aslfiles.c b/source/compiler/aslfiles.c index f7a2a4d42..df3d3684f 100644 --- a/source/compiler/aslfiles.c +++ b/source/compiler/aslfiles.c @@ -747,6 +747,27 @@ FlOpenMiscOutputFiles ( AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT); } + /* Create/Open a C code source output file for the offset table if asked */ + + if (Gbl_C_OffsetTableFlag) + { + Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_OFFSET); + if (!Filename) + { + AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, + 0, 0, 0, 0, NULL, NULL); + return (AE_ERROR); + } + + /* Open the C code source file, text mode */ + + FlOpenFile (ASL_FILE_C_OFFSET_OUTPUT, Filename, "w+t"); + + FlPrintFile (ASL_FILE_C_OFFSET_OUTPUT, "/*\n"); + AslCompilerSignon (ASL_FILE_C_OFFSET_OUTPUT); + AslCompilerFileHeader (ASL_FILE_C_OFFSET_OUTPUT); + } + /* Create/Open a assembly include output file if asked */ if (Gbl_AsmIncludeOutputFlag) diff --git a/source/compiler/aslglobal.h b/source/compiler/aslglobal.h index 2a14eab0a..9d285eb23 100644 --- a/source/compiler/aslglobal.h +++ b/source/compiler/aslglobal.h @@ -158,7 +158,8 @@ ASL_FILE_INFO Gbl_Files [ASL_NUM_FILES] = {NULL, NULL, "ASM Source: ", "Assembly Code Output"}, {NULL, NULL, "C Source: ", "C Code Output"}, {NULL, NULL, "ASM Include: ", "Assembly Header Output"}, - {NULL, NULL, "C Include: ", "C Header Output"} + {NULL, NULL, "C Include: ", "C Header Output"}, + {NULL, NULL, "Offset Table: ", "C Offset Table Output"} }; #else @@ -215,6 +216,7 @@ ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_PreprocessorOutputFlag, ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_DebugFlag, FALSE); ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_AsmOutputFlag, FALSE); ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_C_OutputFlag, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_C_OffsetTableFlag, FALSE); ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_AsmIncludeOutputFlag, FALSE); ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_C_IncludeOutputFlag, FALSE); ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_ListingFlag, FALSE); diff --git a/source/compiler/asllisting.c b/source/compiler/asllisting.c index 024704014..ba73b28f9 100644 --- a/source/compiler/asllisting.c +++ b/source/compiler/asllisting.c @@ -113,23 +113,22 @@ * *****************************************************************************/ - #include "aslcompiler.h" #include "aslcompiler.y.h" #include "amlcode.h" #include "acparser.h" #include "acnamesp.h" + #define _COMPONENT ACPI_COMPILER - ACPI_MODULE_NAME ("aslisting") + ACPI_MODULE_NAME ("asllisting") + /* Local prototypes */ static void -LsDumpAscii ( - UINT32 FileId, - UINT32 Count, - UINT8 *Buffer); +LsGenerateListing ( + UINT32 FileId); static ACPI_STATUS LsAmlListingWalk ( @@ -137,66 +136,27 @@ LsAmlListingWalk ( UINT32 Level, void *Context); -static void -LsGenerateListing ( - UINT32 FileId); - -static void -LsPushNode ( - char *Filename); - -static ASL_LISTING_NODE * -LsPopNode ( - void); - -static void -LsCheckException ( - UINT32 LineNumber, - UINT32 FileId); - -static void -LsFlushListingBuffer ( - UINT32 FileId); +static ACPI_STATUS +LsTreeWriteWalk ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); static void -LsWriteListingHexBytes ( - UINT8 *Buffer, - UINT32 Length, - UINT32 FileId); - -static UINT32 -LsWriteOneSourceLine ( +LsWriteNodeToListing ( + ACPI_PARSE_OBJECT *Op, UINT32 FileId); static void LsFinishSourceListing ( UINT32 FileId); -static void -LsWriteSourceLines ( - UINT32 ToLineNumber, - UINT32 ToLogicalLineNumber, - UINT32 FileId); - -static void -LsWriteNodeToListing ( - ACPI_PARSE_OBJECT *Op, - UINT32 FileId); - -static ACPI_STATUS -LsTreeWriteWalk ( - ACPI_PARSE_OBJECT *Op, - UINT32 Level, - void *Context); - -#define ASL_LISTING_LINE_PREFIX ": " - /******************************************************************************* * * FUNCTION: LsDoListings * - * PARAMETERS: None + * PARAMETERS: None. Examines the various output file global flags. * * RETURN: None * @@ -233,153 +193,60 @@ LsDoListings ( { LsGenerateListing (ASL_FILE_ASM_INCLUDE_OUTPUT); } -} - - -/******************************************************************************* - * - * FUNCTION: LsTreeWriteWalk - * - * PARAMETERS: ASL_WALK_CALLBACK - * - * - * RETURN: None - * - * DESCRIPTION: Dump entire parse tree, for compiler debug only - * - ******************************************************************************/ - -static ACPI_STATUS -LsTreeWriteWalk ( - ACPI_PARSE_OBJECT *Op, - UINT32 Level, - void *Context) -{ - - /* Debug output */ - - DbgPrint (ASL_TREE_OUTPUT, - "%5.5d [%2d]", Op->Asl.LogicalLineNumber, Level); - UtPrintFormattedName (Op->Asl.ParseOpcode, Level); - - - DbgPrint (ASL_TREE_OUTPUT, "\n"); - return (AE_OK); -} - - -void -LsDumpParseTree ( - void) -{ - if (!Gbl_DebugFlag) + if (Gbl_C_OffsetTableFlag) { - return; + LsGenerateListing (ASL_FILE_C_OFFSET_OUTPUT); } - - DbgPrint (ASL_TREE_OUTPUT, "\nOriginal parse tree from parser:\n\n"); - TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, - LsTreeWriteWalk, NULL, NULL); } /******************************************************************************* * - * FUNCTION: LsDumpAscii + * FUNCTION: LsGenerateListing * - * PARAMETERS: FileId - ID of current listing file - * Count - Number of bytes to convert - * Buffer - Buffer of bytes to convert + * PARAMETERS: FileId - ID of listing file * * RETURN: None * - * DESCRIPTION: Convert hex bytes to ascii + * DESCRIPTION: Generate a listing file. This can be one of the several types + * of "listings" supported. * ******************************************************************************/ static void -LsDumpAscii ( - UINT32 FileId, - UINT32 Count, - UINT8 *Buffer) +LsGenerateListing ( + UINT32 FileId) { - UINT8 BufChar; - UINT32 i; - - - FlPrintFile (FileId, " \""); - for (i = 0; i < Count; i++) - { - BufChar = Buffer[i]; - if (isprint (BufChar)) - { - FlPrintFile (FileId, "%c", BufChar); - } - else - { - /* Not a printable character, just put out a dot */ - - FlPrintFile (FileId, "."); - } - } - FlPrintFile (FileId, "\""); -} + /* Start at the beginning of both the source and AML files */ -/******************************************************************************* - * - * FUNCTION: LsDumpAsciiInComment - * - * PARAMETERS: FileId - ID of current listing file - * Count - Number of bytes to convert - * Buffer - Buffer of bytes to convert - * - * RETURN: None - * - * DESCRIPTION: Convert hex bytes to ascii - * - ******************************************************************************/ - -void -LsDumpAsciiInComment ( - UINT32 FileId, - UINT32 Count, - UINT8 *Buffer) -{ - UINT8 BufChar = 0; - UINT8 LastChar; - UINT32 i; - + FlSeekFile (ASL_FILE_SOURCE_OUTPUT, 0); + FlSeekFile (ASL_FILE_AML_OUTPUT, 0); + Gbl_SourceLine = 0; + Gbl_CurrentHexColumn = 0; + LsPushNode (Gbl_Files[ASL_FILE_INPUT].Filename); - FlPrintFile (FileId, " \""); - for (i = 0; i < Count; i++) + if (FileId == ASL_FILE_C_OFFSET_OUTPUT) { - LastChar = BufChar; - BufChar = Buffer[i]; + /* Offset table file has a special header and footer */ - if (isprint (BufChar)) - { - /* Handle embedded C comment sequences */ + LsDoOffsetTableHeader (FileId); - if (((LastChar == '*') && (BufChar == '/')) || - ((LastChar == '/') && (BufChar == '*'))) - { - /* Insert a space to break the sequence */ + TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, LsAmlOffsetWalk, + NULL, (void *) ACPI_TO_POINTER (FileId)); + LsDoOffsetTableFooter (FileId); + return; + } - FlPrintFile (FileId, ".", BufChar); - } + /* Process all parse nodes */ - FlPrintFile (FileId, "%c", BufChar); - } - else - { - /* Not a printable character, just put out a dot */ + TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, LsAmlListingWalk, + NULL, (void *) ACPI_TO_POINTER (FileId)); - FlPrintFile (FileId, "."); - } - } - FlPrintFile (FileId, "\""); + /* Final processing */ + + LsFinishSourceListing (FileId); } @@ -433,576 +300,47 @@ LsAmlListingWalk ( /******************************************************************************* * - * FUNCTION: LsGenerateListing - * - * PARAMETERS: FileId - ID of listing file - * - * RETURN: None - * - * DESCRIPTION: Generate a listing file. This can be one of the several types - * of "listings" supported. - * - ******************************************************************************/ - -static void -LsGenerateListing ( - UINT32 FileId) -{ - - /* Start at the beginning of both the source and AML files */ - - FlSeekFile (ASL_FILE_SOURCE_OUTPUT, 0); - FlSeekFile (ASL_FILE_AML_OUTPUT, 0); - Gbl_SourceLine = 0; - Gbl_CurrentHexColumn = 0; - LsPushNode (Gbl_Files[ASL_FILE_INPUT].Filename); - - /* Process all parse nodes */ - - TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, LsAmlListingWalk, - NULL, (void *) ACPI_TO_POINTER (FileId)); - - /* Final processing */ - - LsFinishSourceListing (FileId); -} - - -/******************************************************************************* - * - * FUNCTION: LsPushNode - * - * PARAMETERS: Filename - Pointer to the include filename - * - * RETURN: None - * - * DESCRIPTION: Push a listing node on the listing/include file stack. This - * stack enables tracking of include files (infinitely nested) - * and resumption of the listing of the parent file when the - * include file is finished. - * - ******************************************************************************/ - -static void -LsPushNode ( - char *Filename) -{ - ASL_LISTING_NODE *Lnode; - - - /* Create a new node */ - - Lnode = UtLocalCalloc (sizeof (ASL_LISTING_NODE)); - - /* Initialize */ - - Lnode->Filename = Filename; - Lnode->LineNumber = 0; - - /* Link (push) */ - - Lnode->Next = Gbl_ListingNode; - Gbl_ListingNode = Lnode; -} - - -/******************************************************************************* - * - * FUNCTION: LsPopNode + * FUNCTION: LsDumpParseTree, LsTreeWriteWalk * * PARAMETERS: None * - * RETURN: List head after current head is popped off - * - * DESCRIPTION: Pop the current head of the list, free it, and return the - * next node on the stack (the new current node). - * - ******************************************************************************/ - -static ASL_LISTING_NODE * -LsPopNode ( - void) -{ - ASL_LISTING_NODE *Lnode; - - - /* Just grab the node at the head of the list */ - - Lnode = Gbl_ListingNode; - if ((!Lnode) || - (!Lnode->Next)) - { - AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, NULL, - "Could not pop empty listing stack"); - return (Gbl_ListingNode); - } - - Gbl_ListingNode = Lnode->Next; - ACPI_FREE (Lnode); - - /* New "Current" node is the new head */ - - return (Gbl_ListingNode); -} - - -/******************************************************************************* - * - * FUNCTION: LsCheckException - * - * PARAMETERS: LineNumber - Current logical (cumulative) line # - * FileId - ID of output listing file - * * RETURN: None * - * DESCRIPTION: Check if there is an exception for this line, and if there is, - * put it in the listing immediately. Handles multiple errors - * per line. Gbl_NextError points to the next error in the - * sorted (by line #) list of compile errors/warnings. - * - ******************************************************************************/ - -static void -LsCheckException ( - UINT32 LineNumber, - UINT32 FileId) -{ - - if ((!Gbl_NextError) || - (LineNumber < Gbl_NextError->LogicalLineNumber )) - { - return; - } - - /* Handle multiple errors per line */ - - if (FileId == ASL_FILE_LISTING_OUTPUT) - { - while (Gbl_NextError && - (LineNumber >= Gbl_NextError->LogicalLineNumber)) - { - AePrintException (FileId, Gbl_NextError, "\n[****iasl****]\n"); - - Gbl_NextError = Gbl_NextError->Next; - } - - FlPrintFile (FileId, "\n"); - } -} - - -/******************************************************************************* - * - * FUNCTION: LsFlushListingBuffer - * - * PARAMETERS: FileId - ID of the listing file - * - * RETURN: None - * - * DESCRIPTION: Flush out the current contents of the 16-byte hex AML code - * buffer. Usually called at the termination of a single line - * of source code or when the buffer is full. - * - ******************************************************************************/ - -static void -LsFlushListingBuffer ( - UINT32 FileId) -{ - UINT32 i; - - - if (Gbl_CurrentHexColumn == 0) - { - return; - } - - /* Write the hex bytes */ - - switch (FileId) - { - case ASL_FILE_LISTING_OUTPUT: - - for (i = 0; i < Gbl_CurrentHexColumn; i++) - { - FlPrintFile (FileId, "%2.2X ", Gbl_AmlBuffer[i]); - } - - for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 3); i++) - { - FlWriteFile (FileId, ".", 1); - } - - /* Write the ASCII character associated with each of the bytes */ - - LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer); - break; - - - case ASL_FILE_ASM_SOURCE_OUTPUT: - - for (i = 0; i < Gbl_CurrentHexColumn; i++) - { - if (i > 0) - { - FlPrintFile (FileId, ","); - } - FlPrintFile (FileId, "0%2.2Xh", Gbl_AmlBuffer[i]); - } - - for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++) - { - FlWriteFile (FileId, " ", 1); - } - - FlPrintFile (FileId, " ;%8.8X", - Gbl_CurrentAmlOffset - HEX_LISTING_LINE_SIZE); - - /* Write the ASCII character associated with each of the bytes */ - - LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer); - break; - - - case ASL_FILE_C_SOURCE_OUTPUT: - - for (i = 0; i < Gbl_CurrentHexColumn; i++) - { - FlPrintFile (FileId, "0x%2.2X,", Gbl_AmlBuffer[i]); - } - - for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++) - { - FlWriteFile (FileId, " ", 1); - } - - FlPrintFile (FileId, " /* %8.8X", - Gbl_CurrentAmlOffset - HEX_LISTING_LINE_SIZE); - - /* Write the ASCII character associated with each of the bytes */ - - LsDumpAsciiInComment (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer); - FlPrintFile (FileId, " */"); - break; - - default: - /* No other types supported */ - return; - } - - FlPrintFile (FileId, "\n"); - - Gbl_CurrentHexColumn = 0; - Gbl_HexBytesWereWritten = TRUE; -} - - -/******************************************************************************* - * - * FUNCTION: LsWriteListingHexBytes - * - * PARAMETERS: Buffer - AML code buffer - * Length - Number of AML bytes to write - * FileId - ID of current listing file. - * - * RETURN: None - * - * DESCRIPTION: Write the contents of the AML buffer to the listing file via - * the listing buffer. The listing buffer is flushed every 16 - * AML bytes. - * - ******************************************************************************/ - -static void -LsWriteListingHexBytes ( - UINT8 *Buffer, - UINT32 Length, - UINT32 FileId) -{ - UINT32 i; - - - /* Transfer all requested bytes */ - - for (i = 0; i < Length; i++) - { - /* Print line header when buffer is empty */ - - if (Gbl_CurrentHexColumn == 0) - { - if (Gbl_HasIncludeFiles) - { - FlPrintFile (FileId, "%*s", 10, " "); - } - - switch (FileId) - { - case ASL_FILE_LISTING_OUTPUT: - - FlPrintFile (FileId, "%8.8X%s", Gbl_CurrentAmlOffset, - ASL_LISTING_LINE_PREFIX); - break; - - case ASL_FILE_ASM_SOURCE_OUTPUT: - - FlPrintFile (FileId, " db "); - break; - - case ASL_FILE_C_SOURCE_OUTPUT: - - FlPrintFile (FileId, " "); - break; - - default: - /* No other types supported */ - return; - } - } - - /* Transfer AML byte and update counts */ - - Gbl_AmlBuffer[Gbl_CurrentHexColumn] = Buffer[i]; - - Gbl_CurrentHexColumn++; - Gbl_CurrentAmlOffset++; - - /* Flush buffer when it is full */ - - if (Gbl_CurrentHexColumn >= HEX_LISTING_LINE_SIZE) - { - LsFlushListingBuffer (FileId); - } - } -} - - -/******************************************************************************* - * - * FUNCTION: LsWriteOneSourceLine - * - * PARAMETERS: FileID - ID of current listing file - * - * RETURN: FALSE on EOF (input source file), TRUE otherwise - * - * DESCRIPTION: Read one line from the input source file and echo it to the - * listing file, prefixed with the line number, and if the source - * file contains include files, prefixed with the current filename - * - ******************************************************************************/ - -static UINT32 -LsWriteOneSourceLine ( - UINT32 FileId) -{ - UINT8 FileByte; - - - Gbl_SourceLine++; - Gbl_ListingNode->LineNumber++; - - /* Ignore lines that are completely blank (but count the line above) */ - - if (FlReadFile (ASL_FILE_SOURCE_OUTPUT, &FileByte, 1) != AE_OK) - { - return (0); - } - if (FileByte == '\n') - { - return (1); - } - - /* - * This is a non-empty line, we will print the entire line with - * the line number and possibly other prefixes and transforms. - */ - - /* Line prefixes for special files, C and ASM output */ - - if (FileId == ASL_FILE_C_SOURCE_OUTPUT) - { - FlPrintFile (FileId, " *"); - } - if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT) - { - FlPrintFile (FileId, "; "); - } - - if (Gbl_HasIncludeFiles) - { - /* - * This file contains "include" statements, print the current - * filename and line number within the current file - */ - FlPrintFile (FileId, "%12s %5d%s", - Gbl_ListingNode->Filename, Gbl_ListingNode->LineNumber, - ASL_LISTING_LINE_PREFIX); - } - else - { - /* No include files, just print the line number */ - - FlPrintFile (FileId, "%8u%s", Gbl_SourceLine, - ASL_LISTING_LINE_PREFIX); - } - - /* Read the rest of this line (up to a newline or EOF) */ - - do - { - if (FileId == ASL_FILE_C_SOURCE_OUTPUT) - { - if (FileByte == '/') - { - FileByte = '*'; - } - } - - FlWriteFile (FileId, &FileByte, 1); - if (FileByte == '\n') - { - /* - * This line has been completed. - * Check if an error occurred on this source line during the compile. - * If so, we print the error message after the source line. - */ - LsCheckException (Gbl_SourceLine, FileId); - return (1); - } - - } while (FlReadFile (ASL_FILE_SOURCE_OUTPUT, &FileByte, 1) == AE_OK); - - /* EOF on the input file was reached */ - - return (0); -} - - -/******************************************************************************* - * - * FUNCTION: LsFinishSourceListing - * - * PARAMETERS: FileId - ID of current listing file. - * - * RETURN: None - * - * DESCRIPTION: Cleanup routine for the listing file. Flush the hex AML - * listing buffer, and flush out any remaining lines in the - * source input file. + * DESCRIPTION: Dump entire parse tree, for compiler debug only * ******************************************************************************/ -static void -LsFinishSourceListing ( - UINT32 FileId) +void +LsDumpParseTree ( + void) { - if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) || - (FileId == ASL_FILE_C_INCLUDE_OUTPUT)) + if (!Gbl_DebugFlag) { return; } - LsFlushListingBuffer (FileId); - Gbl_CurrentAmlOffset = 0; - - /* Flush any remaining text in the source file */ - - if (FileId == ASL_FILE_C_SOURCE_OUTPUT) - { - FlPrintFile (FileId, " /*\n"); - } - - while (LsWriteOneSourceLine (FileId)) - { ; } - - if (FileId == ASL_FILE_C_SOURCE_OUTPUT) - { - FlPrintFile (FileId, "\n */\n };\n"); - } - - FlPrintFile (FileId, "\n"); - - if (FileId == ASL_FILE_LISTING_OUTPUT) - { - /* Print a summary of the compile exceptions */ - - FlPrintFile (FileId, "\n\nSummary of errors and warnings\n\n"); - AePrintErrorLog (FileId); - FlPrintFile (FileId, "\n"); - UtDisplaySummary (FileId); - FlPrintFile (FileId, "\n"); - } + DbgPrint (ASL_TREE_OUTPUT, "\nOriginal parse tree from parser:\n\n"); + TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, + LsTreeWriteWalk, NULL, NULL); } -/******************************************************************************* - * - * FUNCTION: LsWriteSourceLines - * - * PARAMETERS: ToLineNumber - - * ToLogicalLineNumber - Write up to this source line number - * FileId - ID of current listing file - * - * RETURN: None - * - * DESCRIPTION: Read then write source lines to the listing file until we have - * reached the specified logical (cumulative) line number. This - * automatically echos out comment blocks and other non-AML - * generating text until we get to the actual AML-generating line - * of ASL code specified by the logical line number. - * - ******************************************************************************/ - -static void -LsWriteSourceLines ( - UINT32 ToLineNumber, - UINT32 ToLogicalLineNumber, - UINT32 FileId) +static ACPI_STATUS +LsTreeWriteWalk ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) { - if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) || - (FileId == ASL_FILE_C_INCLUDE_OUTPUT)) - { - return; - } - - Gbl_CurrentLine = ToLogicalLineNumber; - - /* Flush any hex bytes remaining from the last opcode */ - - LsFlushListingBuffer (FileId); - - /* Read lines and write them as long as we are not caught up */ - - if (Gbl_SourceLine < Gbl_CurrentLine) - { - /* - * If we just completed writing some AML hex bytes, output a linefeed - * to add some whitespace for readability. - */ - if (Gbl_HexBytesWereWritten) - { - FlPrintFile (FileId, "\n"); - Gbl_HexBytesWereWritten = FALSE; - } - - if (FileId == ASL_FILE_C_SOURCE_OUTPUT) - { - FlPrintFile (FileId, " /*\n"); - } - - /* Write one line at a time until we have reached the target line # */ + /* Debug output */ - while ((Gbl_SourceLine < Gbl_CurrentLine) && - LsWriteOneSourceLine (FileId)) - { ; } + DbgPrint (ASL_TREE_OUTPUT, + "%5.5d [%2d]", Op->Asl.LogicalLineNumber, Level); + UtPrintFormattedName (Op->Asl.ParseOpcode, Level); - if (FileId == ASL_FILE_C_SOURCE_OUTPUT) - { - FlPrintFile (FileId, " */"); - } - FlPrintFile (FileId, "\n"); - } + DbgPrint (ASL_TREE_OUTPUT, "\n"); + return (AE_OK); } @@ -1010,7 +348,7 @@ LsWriteSourceLines ( * * FUNCTION: LsWriteNodeToListing * - * PARAMETERS: Op - Parse node to write to the listing file. + * PARAMETERS: Op - Parse node to write to the listing file. * FileId - ID of current listing file * * RETURN: None. @@ -1316,3 +654,61 @@ LsWriteNodeToListing ( break; } } + + +/******************************************************************************* + * + * FUNCTION: LsFinishSourceListing + * + * PARAMETERS: FileId - ID of current listing file. + * + * RETURN: None + * + * DESCRIPTION: Cleanup routine for the listing file. Flush the hex AML + * listing buffer, and flush out any remaining lines in the + * source input file. + * + ******************************************************************************/ + +static void +LsFinishSourceListing ( + UINT32 FileId) +{ + + if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) || + (FileId == ASL_FILE_C_INCLUDE_OUTPUT)) + { + return; + } + + LsFlushListingBuffer (FileId); + Gbl_CurrentAmlOffset = 0; + + /* Flush any remaining text in the source file */ + + if (FileId == ASL_FILE_C_SOURCE_OUTPUT) + { + FlPrintFile (FileId, " /*\n"); + } + + while (LsWriteOneSourceLine (FileId)) + { ; } + + if (FileId == ASL_FILE_C_SOURCE_OUTPUT) + { + FlPrintFile (FileId, "\n */\n };\n"); + } + + FlPrintFile (FileId, "\n"); + + if (FileId == ASL_FILE_LISTING_OUTPUT) + { + /* Print a summary of the compile exceptions */ + + FlPrintFile (FileId, "\n\nSummary of errors and warnings\n\n"); + AePrintErrorLog (FileId); + FlPrintFile (FileId, "\n"); + UtDisplaySummary (FileId); + FlPrintFile (FileId, "\n"); + } +} diff --git a/source/compiler/asllistsup.c b/source/compiler/asllistsup.c new file mode 100644 index 000000000..a3dd3d0bc --- /dev/null +++ b/source/compiler/asllistsup.c @@ -0,0 +1,778 @@ +/****************************************************************************** + * + * Module Name: asllistsup - Listing file support utilities + * + *****************************************************************************/ + +/****************************************************************************** + * + * 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 "aslcompiler.h" +#include "aslcompiler.y.h" + + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslistsup") + + +/******************************************************************************* + * + * FUNCTION: LsDumpAscii + * + * PARAMETERS: FileId - ID of current listing file + * Count - Number of bytes to convert + * Buffer - Buffer of bytes to convert + * + * RETURN: None + * + * DESCRIPTION: Convert hex bytes to ascii + * + ******************************************************************************/ + +void +LsDumpAscii ( + UINT32 FileId, + UINT32 Count, + UINT8 *Buffer) +{ + UINT8 BufChar; + UINT32 i; + + + FlPrintFile (FileId, " \""); + for (i = 0; i < Count; i++) + { + BufChar = Buffer[i]; + if (isprint (BufChar)) + { + FlPrintFile (FileId, "%c", BufChar); + } + else + { + /* Not a printable character, just put out a dot */ + + FlPrintFile (FileId, "."); + } + } + FlPrintFile (FileId, "\""); +} + + +/******************************************************************************* + * + * FUNCTION: LsDumpAsciiInComment + * + * PARAMETERS: FileId - ID of current listing file + * Count - Number of bytes to convert + * Buffer - Buffer of bytes to convert + * + * RETURN: None + * + * DESCRIPTION: Convert hex bytes to ascii + * + ******************************************************************************/ + +void +LsDumpAsciiInComment ( + UINT32 FileId, + UINT32 Count, + UINT8 *Buffer) +{ + UINT8 BufChar = 0; + UINT8 LastChar; + UINT32 i; + + + FlPrintFile (FileId, " \""); + for (i = 0; i < Count; i++) + { + LastChar = BufChar; + BufChar = Buffer[i]; + + if (isprint (BufChar)) + { + /* Handle embedded C comment sequences */ + + if (((LastChar == '*') && (BufChar == '/')) || + ((LastChar == '/') && (BufChar == '*'))) + { + /* Insert a space to break the sequence */ + + FlPrintFile (FileId, ".", BufChar); + } + + FlPrintFile (FileId, "%c", BufChar); + } + else + { + /* Not a printable character, just put out a dot */ + + FlPrintFile (FileId, "."); + } + } + + FlPrintFile (FileId, "\""); +} + + +/******************************************************************************* + * + * FUNCTION: LsCheckException + * + * PARAMETERS: LineNumber - Current logical (cumulative) line # + * FileId - ID of output listing file + * + * RETURN: None + * + * DESCRIPTION: Check if there is an exception for this line, and if there is, + * put it in the listing immediately. Handles multiple errors + * per line. Gbl_NextError points to the next error in the + * sorted (by line #) list of compile errors/warnings. + * + ******************************************************************************/ + +void +LsCheckException ( + UINT32 LineNumber, + UINT32 FileId) +{ + + if ((!Gbl_NextError) || + (LineNumber < Gbl_NextError->LogicalLineNumber )) + { + return; + } + + /* Handle multiple errors per line */ + + if (FileId == ASL_FILE_LISTING_OUTPUT) + { + while (Gbl_NextError && + (LineNumber >= Gbl_NextError->LogicalLineNumber)) + { + AePrintException (FileId, Gbl_NextError, "\n[****iasl****]\n"); + + Gbl_NextError = Gbl_NextError->Next; + } + + FlPrintFile (FileId, "\n"); + } +} + + +/******************************************************************************* + * + * FUNCTION: LsWriteListingHexBytes + * + * PARAMETERS: Buffer - AML code buffer + * Length - Number of AML bytes to write + * FileId - ID of current listing file. + * + * RETURN: None + * + * DESCRIPTION: Write the contents of the AML buffer to the listing file via + * the listing buffer. The listing buffer is flushed every 16 + * AML bytes. + * + ******************************************************************************/ + +void +LsWriteListingHexBytes ( + UINT8 *Buffer, + UINT32 Length, + UINT32 FileId) +{ + UINT32 i; + + + /* Transfer all requested bytes */ + + for (i = 0; i < Length; i++) + { + /* Print line header when buffer is empty */ + + if (Gbl_CurrentHexColumn == 0) + { + if (Gbl_HasIncludeFiles) + { + FlPrintFile (FileId, "%*s", 10, " "); + } + + switch (FileId) + { + case ASL_FILE_LISTING_OUTPUT: + + FlPrintFile (FileId, "%8.8X%s", Gbl_CurrentAmlOffset, + ASL_LISTING_LINE_PREFIX); + break; + + case ASL_FILE_ASM_SOURCE_OUTPUT: + + FlPrintFile (FileId, " db "); + break; + + case ASL_FILE_C_SOURCE_OUTPUT: + + FlPrintFile (FileId, " "); + break; + + default: + /* No other types supported */ + return; + } + } + + /* Transfer AML byte and update counts */ + + Gbl_AmlBuffer[Gbl_CurrentHexColumn] = Buffer[i]; + + Gbl_CurrentHexColumn++; + Gbl_CurrentAmlOffset++; + + /* Flush buffer when it is full */ + + if (Gbl_CurrentHexColumn >= HEX_LISTING_LINE_SIZE) + { + LsFlushListingBuffer (FileId); + } + } +} + + +/******************************************************************************* + * + * FUNCTION: LsWriteSourceLines + * + * PARAMETERS: ToLineNumber - + * ToLogicalLineNumber - Write up to this source line number + * FileId - ID of current listing file + * + * RETURN: None + * + * DESCRIPTION: Read then write source lines to the listing file until we have + * reached the specified logical (cumulative) line number. This + * automatically echos out comment blocks and other non-AML + * generating text until we get to the actual AML-generating line + * of ASL code specified by the logical line number. + * + ******************************************************************************/ + +void +LsWriteSourceLines ( + UINT32 ToLineNumber, + UINT32 ToLogicalLineNumber, + UINT32 FileId) +{ + + /* Nothing to do for these file types */ + + if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) || + (FileId == ASL_FILE_C_INCLUDE_OUTPUT)) + { + return; + } + + Gbl_CurrentLine = ToLogicalLineNumber; + + /* Flush any hex bytes remaining from the last opcode */ + + LsFlushListingBuffer (FileId); + + /* Read lines and write them as long as we are not caught up */ + + if (Gbl_SourceLine < Gbl_CurrentLine) + { + /* + * If we just completed writing some AML hex bytes, output a linefeed + * to add some whitespace for readability. + */ + if (Gbl_HexBytesWereWritten) + { + FlPrintFile (FileId, "\n"); + Gbl_HexBytesWereWritten = FALSE; + } + + if (FileId == ASL_FILE_C_SOURCE_OUTPUT) + { + FlPrintFile (FileId, " /*\n"); + } + + /* Write one line at a time until we have reached the target line # */ + + while ((Gbl_SourceLine < Gbl_CurrentLine) && + LsWriteOneSourceLine (FileId)) + { ; } + + if (FileId == ASL_FILE_C_SOURCE_OUTPUT) + { + FlPrintFile (FileId, " */"); + } + + FlPrintFile (FileId, "\n"); + } +} + + +/******************************************************************************* + * + * FUNCTION: LsWriteOneSourceLine + * + * PARAMETERS: FileId - ID of current listing file + * + * RETURN: FALSE on EOF (input source file), TRUE otherwise + * + * DESCRIPTION: Read one line from the input source file and echo it to the + * listing file, prefixed with the line number, and if the source + * file contains include files, prefixed with the current filename + * + ******************************************************************************/ + +UINT32 +LsWriteOneSourceLine ( + UINT32 FileId) +{ + UINT8 FileByte; + UINT32 Column = 0; + UINT32 Index = 16; + BOOLEAN StartOfLine = FALSE; + BOOLEAN ProcessLongLine = FALSE; + + + Gbl_SourceLine++; + Gbl_ListingNode->LineNumber++; + + /* Ignore lines that are completely blank (but count the line above) */ + + if (FlReadFile (ASL_FILE_SOURCE_OUTPUT, &FileByte, 1) != AE_OK) + { + return (0); + } + if (FileByte == '\n') + { + return (1); + } + + /* + * This is a non-empty line, we will print the entire line with + * the line number and possibly other prefixes and transforms. + */ + + /* Line prefixes for special files, C and ASM output */ + + if (FileId == ASL_FILE_C_SOURCE_OUTPUT) + { + FlPrintFile (FileId, " *"); + } + if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT) + { + FlPrintFile (FileId, "; "); + } + + if (Gbl_HasIncludeFiles) + { + /* + * This file contains "include" statements, print the current + * filename and line number within the current file + */ + FlPrintFile (FileId, "%12s %5d%s", + Gbl_ListingNode->Filename, Gbl_ListingNode->LineNumber, + ASL_LISTING_LINE_PREFIX); + } + else + { + /* No include files, just print the line number */ + + FlPrintFile (FileId, "%8u%s", Gbl_SourceLine, + ASL_LISTING_LINE_PREFIX); + } + + /* Read the rest of this line (up to a newline or EOF) */ + + do + { + if (FileId == ASL_FILE_C_SOURCE_OUTPUT) + { + if (FileByte == '/') + { + FileByte = '*'; + } + } + + /* Split long input lines for readability in the listing */ + + Column++; + if (Column >= 128) + { + if (!ProcessLongLine) + { + if ((FileByte != '}') && + (FileByte != '{')) + { + goto WriteByte; + } + + ProcessLongLine = TRUE; + } + + if (FileByte == '{') + { + FlPrintFile (FileId, "\n%*s{\n", Index, " "); + StartOfLine = TRUE; + Index += 4; + continue; + } + + else if (FileByte == '}') + { + if (!StartOfLine) + { + FlPrintFile (FileId, "\n"); + } + + StartOfLine = TRUE; + Index -= 4; + FlPrintFile (FileId, "%*s}\n", Index, " "); + continue; + } + + /* Ignore spaces/tabs at the start of line */ + + else if ((FileByte == ' ') && StartOfLine) + { + continue; + } + + else if (StartOfLine) + { + StartOfLine = FALSE; + FlPrintFile (FileId, "%*s", Index, " "); + } + +WriteByte: + FlWriteFile (FileId, &FileByte, 1); + if (FileByte == '\n') + { + /* + * This line has been completed. + * Check if an error occurred on this source line during the compile. + * If so, we print the error message after the source line. + */ + LsCheckException (Gbl_SourceLine, FileId); + return (1); + } + } + else + { + FlWriteFile (FileId, &FileByte, 1); + if (FileByte == '\n') + { + /* + * This line has been completed. + * Check if an error occurred on this source line during the compile. + * If so, we print the error message after the source line. + */ + LsCheckException (Gbl_SourceLine, FileId); + return (1); + } + } + + } while (FlReadFile (ASL_FILE_SOURCE_OUTPUT, &FileByte, 1) == AE_OK); + + /* EOF on the input file was reached */ + + return (0); +} + + +/******************************************************************************* + * + * FUNCTION: LsFlushListingBuffer + * + * PARAMETERS: FileId - ID of the listing file + * + * RETURN: None + * + * DESCRIPTION: Flush out the current contents of the 16-byte hex AML code + * buffer. Usually called at the termination of a single line + * of source code or when the buffer is full. + * + ******************************************************************************/ + +void +LsFlushListingBuffer ( + UINT32 FileId) +{ + UINT32 i; + + + if (Gbl_CurrentHexColumn == 0) + { + return; + } + + /* Write the hex bytes */ + + switch (FileId) + { + case ASL_FILE_LISTING_OUTPUT: + + for (i = 0; i < Gbl_CurrentHexColumn; i++) + { + FlPrintFile (FileId, "%2.2X ", Gbl_AmlBuffer[i]); + } + + for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 3); i++) + { + FlWriteFile (FileId, ".", 1); + } + + /* Write the ASCII character associated with each of the bytes */ + + LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer); + break; + + + case ASL_FILE_ASM_SOURCE_OUTPUT: + + for (i = 0; i < Gbl_CurrentHexColumn; i++) + { + if (i > 0) + { + FlPrintFile (FileId, ","); + } + FlPrintFile (FileId, "0%2.2Xh", Gbl_AmlBuffer[i]); + } + + for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++) + { + FlWriteFile (FileId, " ", 1); + } + + FlPrintFile (FileId, " ;%8.8X", + Gbl_CurrentAmlOffset - HEX_LISTING_LINE_SIZE); + + /* Write the ASCII character associated with each of the bytes */ + + LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer); + break; + + + case ASL_FILE_C_SOURCE_OUTPUT: + + for (i = 0; i < Gbl_CurrentHexColumn; i++) + { + FlPrintFile (FileId, "0x%2.2X,", Gbl_AmlBuffer[i]); + } + + /* Pad hex output with spaces if line is shorter than max line size */ + + for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++) + { + FlWriteFile (FileId, " ", 1); + } + + /* AML offset for the start of the line */ + + FlPrintFile (FileId, " /* %8.8X", + Gbl_CurrentAmlOffset - Gbl_CurrentHexColumn); + + /* Write the ASCII character associated with each of the bytes */ + + LsDumpAsciiInComment (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer); + FlPrintFile (FileId, " */"); + break; + + default: + /* No other types supported */ + return; + } + + FlPrintFile (FileId, "\n"); + + Gbl_CurrentHexColumn = 0; + Gbl_HexBytesWereWritten = TRUE; +} + + +/******************************************************************************* + * + * FUNCTION: LsPushNode + * + * PARAMETERS: Filename - Pointer to the include filename + * + * RETURN: None + * + * DESCRIPTION: Push a listing node on the listing/include file stack. This + * stack enables tracking of include files (infinitely nested) + * and resumption of the listing of the parent file when the + * include file is finished. + * + ******************************************************************************/ + +void +LsPushNode ( + char *Filename) +{ + ASL_LISTING_NODE *Lnode; + + + /* Create a new node */ + + Lnode = UtLocalCalloc (sizeof (ASL_LISTING_NODE)); + + /* Initialize */ + + Lnode->Filename = Filename; + Lnode->LineNumber = 0; + + /* Link (push) */ + + Lnode->Next = Gbl_ListingNode; + Gbl_ListingNode = Lnode; +} + + +/******************************************************************************* + * + * FUNCTION: LsPopNode + * + * PARAMETERS: None + * + * RETURN: List head after current head is popped off + * + * DESCRIPTION: Pop the current head of the list, free it, and return the + * next node on the stack (the new current node). + * + ******************************************************************************/ + +ASL_LISTING_NODE * +LsPopNode ( + void) +{ + ASL_LISTING_NODE *Lnode; + + + /* Just grab the node at the head of the list */ + + Lnode = Gbl_ListingNode; + if ((!Lnode) || + (!Lnode->Next)) + { + AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, NULL, + "Could not pop empty listing stack"); + return (Gbl_ListingNode); + } + + Gbl_ListingNode = Lnode->Next; + ACPI_FREE (Lnode); + + /* New "Current" node is the new head */ + + return (Gbl_ListingNode); +} diff --git a/source/compiler/aslmain.c b/source/compiler/aslmain.c index 4c02c7074..921da42d9 100644 --- a/source/compiler/aslmain.c +++ b/source/compiler/aslmain.c @@ -228,6 +228,7 @@ Options ( ACPI_OPTION ("-sc -sa", "Create source file in C or assembler (*.c or *.asm)"); ACPI_OPTION ("-ic -ia", "Create include file in C or assembler (*.h or *.inc)"); ACPI_OPTION ("-tc -ta -ts", "Create hex AML table in C, assembler, or ASL (*.hex)"); + ACPI_OPTION ("-so", "Create offset table in C (*.offset.h)"); printf ("\nOptional Listing Files:\n"); ACPI_OPTION ("-l", "Create mixed listing file (ASL source and AML) (*.lst)"); @@ -856,6 +857,13 @@ AslDoOptions ( Gbl_C_OutputFlag = TRUE; break; + case 'o': + + /* Produce AML offset table in C */ + + Gbl_C_OffsetTableFlag = TRUE; + break; + default: printf ("Unknown option: -s%s\n", AcpiGbl_Optarg); return (-1); diff --git a/source/compiler/asloffset.c b/source/compiler/asloffset.c new file mode 100644 index 000000000..22c9ff08a --- /dev/null +++ b/source/compiler/asloffset.c @@ -0,0 +1,398 @@ +/****************************************************************************** + * + * Module Name: asloffset - Generate a C "offset table" for BIOS use. + * + *****************************************************************************/ + +/****************************************************************************** + * + * 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 "aslcompiler.h" +#include "aslcompiler.y.h" +#include "amlcode.h" +#include "acnamesp.h" + + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("asloffset") + + +/* Local prototypes */ + +static void +LsEmitOffsetTableEntry ( + UINT32 FileId, + ACPI_NAMESPACE_NODE *Node, + UINT32 Offset, + UINT32 Length, + char *OpName, + UINT64 Value, + UINT8 AmlOpcode); + + +/******************************************************************************* + * + * FUNCTION: LsAmlOffsetWalk + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Process one node during a offset table file generation. + * + * Three types of objects are currently emitted to the offset table: + * 1) Tagged (named) resource descriptors + * 2) Named integer objects with constant integer values + * 3) Operation Regions that have constant Offset (address) parameters + * + * The offset table allows the BIOS to dynamically update the values of these + * objects at boot time. + * + ******************************************************************************/ + +ACPI_STATUS +LsAmlOffsetWalk ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + UINT32 FileId = (UINT32) ACPI_TO_INTEGER (Context); + ACPI_NAMESPACE_NODE *Node; + UINT32 Length; + UINT32 OffsetOfOpcode; + ACPI_PARSE_OBJECT *AddressOp; + + + /* Ignore actual data blocks for resource descriptors */ + + if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DATA) + { + return (AE_OK); /* Do NOT update the global AML offset */ + } + + /* We are only interested in named objects (have a namespace node) */ + + Node = Op->Asl.Node; + if (!Node) + { + Gbl_CurrentAmlOffset += Op->Asl.FinalAmlLength; + return (AE_OK); + } + + /* Named resource descriptor (has a descriptor tag) */ + + if ((Node->Type == ACPI_TYPE_LOCAL_RESOURCE) && + (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)) + { + LsEmitOffsetTableEntry (FileId, Node, Gbl_CurrentAmlOffset, + Op->Asl.FinalAmlLength, Op->Asl.ParseOpName, 0, Op->Asl.Extra); + } + + /* Named object -- Name (NameString, DataRefObject) */ + + else if (Op->Asl.AmlOpcode == AML_NAME_OP) + { + if (!Op->Asl.Child) + { + FlPrintFile (FileId, "%s NO CHILD!\n", MsgBuffer); + return (AE_OK); + } + + Length = Op->Asl.FinalAmlLength; + + /* Get to the NameSeg/NamePath Op (and length of the name) */ + + Op = Op->Asl.Child; + OffsetOfOpcode = Length + Op->Asl.FinalAmlLength; + + /* Get actual value associated with the name */ + + Op = Op->Asl.Next; + switch (Op->Asl.AmlOpcode) + { + /* + * We are only interested in integer constants that can be changed + * at boot time. Note, the One/Ones/Zero opcodes are considered + * non-changeable, so we ignore them here. + */ + case AML_BYTE_OP: + case AML_WORD_OP: + case AML_DWORD_OP: + case AML_QWORD_OP: + + /* The +1/-1 is to handle the integer size prefix (opcode) */ + + LsEmitOffsetTableEntry (FileId, Node, + (Gbl_CurrentAmlOffset + OffsetOfOpcode + 1), + (Op->Asl.FinalAmlLength - 1), Op->Asl.ParseOpName, + Op->Asl.Value.Integer, (UINT8) Op->Asl.AmlOpcode); + break; + + default: + break; + } + + Gbl_CurrentAmlOffset += Length; + return (AE_OK); + } + + /* OperationRegion (NameString, RegionSpace, RegionOffset, RegionLength) */ + + else if (Op->Asl.AmlOpcode == AML_REGION_OP) + { + Length = Op->Asl.FinalAmlLength; + + /* Get the name/namepath node */ + + AddressOp = Op->Asl.Child; + OffsetOfOpcode = Length + AddressOp->Asl.FinalAmlLength + 1; + + /* Get the SpaceId node, then the Offset (address) node */ + + AddressOp = AddressOp->Asl.Next; + AddressOp = AddressOp->Asl.Next; + + switch (AddressOp->Asl.AmlOpcode) + { + /* + * We are only interested in integer constants that can be changed + * at boot time. Note, the One/Ones/Zero opcodes are considered + * non-changeable, so we ignore them here. + */ + case AML_BYTE_OP: + case AML_WORD_OP: + case AML_DWORD_OP: + case AML_QWORD_OP: + + /* The +1/-1 is to handle the integer size prefix (opcode) */ + + LsEmitOffsetTableEntry (FileId, Node, + (Gbl_CurrentAmlOffset + OffsetOfOpcode + 1), + (AddressOp->Asl.FinalAmlLength - 1), Op->Asl.ParseOpName, + AddressOp->Asl.Value.Integer, (UINT8) AddressOp->Asl.AmlOpcode); + + Gbl_CurrentAmlOffset += Length; + return (AE_OK); + + default: + break; + } + } + + Gbl_CurrentAmlOffset += Op->Asl.FinalAmlLength; + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: LsEmitOffsetTableEntry + * + * PARAMETERS: FileId - ID of current listing file + * Node - Namespace node associated with the name + * Offset - Offset of the value within the AML table + * Length - Length in bytes of the value + * OpName - Name of the AML opcode + * Value - Current value of the AML field + * AmlOpcode - Opcode associated with the field + * + * RETURN: None + * + * DESCRIPTION: Emit a line of the offset table (-so option) + * + ******************************************************************************/ + +static void +LsEmitOffsetTableEntry ( + UINT32 FileId, + ACPI_NAMESPACE_NODE *Node, + UINT32 Offset, + UINT32 Length, + char *OpName, + UINT64 Value, + UINT8 AmlOpcode) +{ + ACPI_BUFFER TargetPath; + ACPI_STATUS Status; + + + /* Get the full pathname to the namespace node */ + + TargetPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER; + Status = AcpiNsHandleToPathname (Node, &TargetPath); + if (ACPI_FAILURE (Status)) + { + return; + } + + /* [1] - Skip the opening backslash for the path */ + + strcpy (MsgBuffer, "\""); + strcat (MsgBuffer, &((char *) TargetPath.Pointer)[1]); + strcat (MsgBuffer, "\","); + ACPI_FREE (TargetPath.Pointer); + + /* + * Max offset is 4G, constrained by 32-bit ACPI table length. + * Max Length for Integers is 8 bytes. + */ + FlPrintFile (FileId, + " {%-29s 0x%8.8X, 0x%2.2X, 0x%8.8X%8.8X}, /* %s */\n", + MsgBuffer, Offset, AmlOpcode, ACPI_FORMAT_UINT64 (Value), OpName); +} + + +/******************************************************************************* + * + * FUNCTION: LsDoOffsetTableHeader, LsDoOffsetTableFooter + * + * PARAMETERS: FileId - ID of current listing file + * + * RETURN: None + * + * DESCRIPTION: Header and footer for the offset table file. + * + ******************************************************************************/ + +void +LsDoOffsetTableHeader ( + UINT32 FileId) +{ + + Gbl_CurrentAmlOffset = 0; + + FlPrintFile (FileId, + "#ifndef __AML_OFFSET_TABLE_H\n" + "#define __AML_OFFSET_TABLE_H\n\n"); + + FlPrintFile (FileId, "typedef struct {\n" + " char *Pathname;\n" + " unsigned long Offset;\n" + " unsigned char AmlOpcode;\n" + " unsigned long long AmlValue;\n" + "} AML_OFFSET_TABLE_ENTRY;\n\n"); + + FlPrintFile (FileId, + "#endif /* __AML_OFFSET_TABLE_H */\n\n"); + + FlPrintFile (FileId, + "AML_OFFSET_TABLE_ENTRY %s_%s_OffsetTable[] =\n{\n", + Gbl_TableSignature, Gbl_TableId); +} + + +void +LsDoOffsetTableFooter ( + UINT32 FileId) +{ + + FlPrintFile (FileId, + " {0,0,0,0} /* Table terminator */\n};\n\n"); + Gbl_CurrentAmlOffset = 0; +} diff --git a/source/compiler/aslresource.c b/source/compiler/aslresource.c index 0593ec272..9e919e78a 100644 --- a/source/compiler/aslresource.c +++ b/source/compiler/aslresource.c @@ -966,6 +966,7 @@ RsDoOneResourceDescriptor ( if (Rnode) { DescriptorTypeOp->Asl.FinalAmlLength = Rnode->BufferLength; + DescriptorTypeOp->Asl.Extra = ((AML_RESOURCE *) Rnode->Buffer)->DescriptorType; } return (Rnode); diff --git a/source/compiler/asltypes.h b/source/compiler/asltypes.h index b44b385ed..cd556bbae 100644 --- a/source/compiler/asltypes.h +++ b/source/compiler/asltypes.h @@ -236,12 +236,13 @@ typedef enum ASL_FILE_ASM_SOURCE_OUTPUT, ASL_FILE_C_SOURCE_OUTPUT, ASL_FILE_ASM_INCLUDE_OUTPUT, - ASL_FILE_C_INCLUDE_OUTPUT + ASL_FILE_C_INCLUDE_OUTPUT, + ASL_FILE_C_OFFSET_OUTPUT } ASL_FILE_TYPES; -#define ASL_MAX_FILE_TYPE 13 +#define ASL_MAX_FILE_TYPE 14 #define ASL_NUM_FILES (ASL_MAX_FILE_TYPE + 1) |