static void DtWriteBinary ( DT_SUBTABLE *Subtable, void *Context, void *ReturnValue) { FlWriteFile (ASL_FILE_AML_OUTPUT, Subtable->Buffer, Subtable->Length); }
void DtWriteFieldToListing ( UINT8 *Buffer, DT_FIELD *Field, UINT32 Length) { UINT8 FileByte; if (!Gbl_ListingFlag || !Field) { return; } /* Dump the original source line */ FlPrintFile (ASL_FILE_LISTING_OUTPUT, "Input: "); FlSeekFile (ASL_FILE_INPUT, Field->ByteOffset); while (FlReadFile (ASL_FILE_INPUT, &FileByte, 1) == AE_OK) { FlWriteFile (ASL_FILE_LISTING_OUTPUT, &FileByte, 1); if (FileByte == '\n') { break; } } /* Dump the line as parsed and represented internally */ FlPrintFile (ASL_FILE_LISTING_OUTPUT, "Parsed: %*s : %.64s", Field->Column-4, Field->Name, Field->Value); if (strlen (Field->Value) > 64) { FlPrintFile (ASL_FILE_LISTING_OUTPUT, "...Additional data, length 0x%X\n", strlen (Field->Value)); } FlPrintFile (ASL_FILE_LISTING_OUTPUT, "\n"); /* Dump the hex data that will be output for this field */ DtDumpBuffer (ASL_FILE_LISTING_OUTPUT, Buffer, Field->TableOffset, Length); }
static void CgLocalWriteAmlData ( ACPI_PARSE_OBJECT *Op, void *Buffer, UINT32 Length) { /* Write the raw data to the AML file */ FlWriteFile (ASL_FILE_AML_OUTPUT, Buffer, Length); /* Update the final AML length for this node (used for listings) */ if (Op) { Op->Asl.FinalAmlLength += Length; } }
static void PrPreprocessInputFile ( void) { UINT32 Status; char *Token; char *ReplaceString; PR_DEFINE_INFO *DefineInfo; ACPI_SIZE TokenOffset; char *Next; int OffsetAdjust; PrGetNextLineInit (); /* Scan source line-by-line and process directives. Then write the .i file */ while ((Status = PrGetNextLine (Gbl_Files[ASL_FILE_INPUT].Handle)) != ASL_EOF) { Gbl_CurrentLineNumber++; Gbl_LogicalLineNumber++; if (Status == ASL_IGNORE_LINE) { goto WriteEntireLine; } /* Need a copy of the input line for strok() */ strcpy (Gbl_MainTokenBuffer, Gbl_CurrentLineBuffer); Token = PrGetNextToken (Gbl_MainTokenBuffer, PR_TOKEN_SEPARATORS, &Next); OffsetAdjust = 0; /* All preprocessor directives must begin with '#' */ if (Token && (*Token == '#')) { if (strlen (Token) == 1) { Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next); } else { Token++; /* Skip leading # */ } /* Execute the directive, do not write line to output file */ PrDoDirective (Token, &Next); continue; } /* * If we are currently within the part of an IF/ELSE block that is * FALSE, ignore the line and do not write it to the output file. * This continues until an #else or #endif is encountered. */ if (Gbl_IgnoringThisCodeBlock) { continue; } /* Match and replace all #defined names within this source line */ while (Token) { DefineInfo = PrMatchDefine (Token); if (DefineInfo) { if (DefineInfo->Body) { /* This is a macro */ DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "Matched Macro: %s->%s\n", Gbl_CurrentLineNumber, DefineInfo->Identifier, DefineInfo->Replacement); PrDoMacroInvocation (Gbl_MainTokenBuffer, Token, DefineInfo, &Next); } else { ReplaceString = DefineInfo->Replacement; /* Replace the name in the original line buffer */ TokenOffset = Token - Gbl_MainTokenBuffer + OffsetAdjust; PrReplaceData ( &Gbl_CurrentLineBuffer[TokenOffset], strlen (Token), ReplaceString, strlen (ReplaceString)); /* Adjust for length difference between old and new name length */ OffsetAdjust += strlen (ReplaceString) - strlen (Token); DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "Matched #define: %s->%s\n", Gbl_CurrentLineNumber, Token, *ReplaceString ? ReplaceString : "(NULL STRING)"); } } Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next); } Gbl_PreprocessorLineNumber++; WriteEntireLine: /* * Now we can write the possibly modified source line to the * preprocessor file(s). */ FlWriteFile (ASL_FILE_PREPROCESSOR, Gbl_CurrentLineBuffer, strlen (Gbl_CurrentLineBuffer)); } }
static void PrPreprocessInputFile ( void) { UINT32 Offset; char *Token; char *ReplaceString; PR_DEFINE_INFO *DefineInfo; ACPI_SIZE TokenOffset; BOOLEAN IgnoringThisCodeBlock = FALSE; char *Next; int OffsetAdjust; /* Scan line-by-line. Comments and blank lines are skipped by this function */ while ((Offset = DtGetNextLine (Gbl_Files[ASL_FILE_INPUT].Handle)) != ASL_EOF) { /* Need a copy of the input line for strok() */ strcpy (Gbl_MainTokenBuffer, Gbl_CurrentLineBuffer); Token = PrGetNextToken (Gbl_MainTokenBuffer, PR_TOKEN_SEPARATORS, &Next); OffsetAdjust = 0; /* All preprocessor directives must begin with '#' */ if (Token && (*Token == '#')) { if (strlen (Token) == 1) { Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next); } else { Token++; /* Skip leading # */ } /* Execute the directive, do not write line to output file */ PrDoDirective (Token, &Next, &IgnoringThisCodeBlock); continue; } /* * If we are currently within the part of an IF/ELSE block that is * FALSE, ignore the line and do not write it to the output file. * This continues until an #else or #endif is encountered. */ if (IgnoringThisCodeBlock == TRUE) { continue; } /* Match and replace all #defined names within this source line */ while (Token) { DefineInfo = PrMatchDefine (Token); if (DefineInfo) { if (DefineInfo->Body) { /* This is a macro */ DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "Matched Macro: %s->%s\n", Gbl_CurrentLineNumber, DefineInfo->Identifier, DefineInfo->Replacement); PrDoMacroInvocation (Gbl_MainTokenBuffer, Token, DefineInfo, &Next); } else { ReplaceString = DefineInfo->Replacement; /* Replace the name in the original line buffer */ TokenOffset = Token - Gbl_MainTokenBuffer + OffsetAdjust; PrReplaceData ( &Gbl_CurrentLineBuffer[TokenOffset], strlen (Token), ReplaceString, strlen (ReplaceString)); /* Adjust for length difference between old and new name length */ OffsetAdjust += strlen (ReplaceString) - strlen (Token); DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "Matched #define: %s->%s\n", Gbl_CurrentLineNumber, Token, *ReplaceString ? ReplaceString : "(NULL STRING)"); } } Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next); } #if 0 /* Line prefix */ FlPrintFile (ASL_FILE_PREPROCESSOR, "/* %14s %.5u i:%.5u */ ", Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_CurrentLineNumber, Gbl_PreprocessorLineNumber); #endif /* * Emit a #line directive if necessary, to keep the line numbers in * the (.i) file synchronized with the original source code file, so * that the correct line number appears in any error messages * generated by the actual compiler. */ if (Gbl_CurrentLineNumber > (Gbl_PreviousLineNumber + 1)) { FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u\n", Gbl_CurrentLineNumber); } Gbl_PreviousLineNumber = Gbl_CurrentLineNumber; Gbl_PreprocessorLineNumber++; /* * Now we can write the possibly modified source line to the * preprocessor (.i) file */ FlWriteFile (ASL_FILE_PREPROCESSOR, Gbl_CurrentLineBuffer, strlen (Gbl_CurrentLineBuffer)); } }
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; }
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); }
static UINT32 LsWriteOneSourceLine ( UINT32 FileId) { UINT8 FileByte; Gbl_SourceLine++; Gbl_ListingNode->LineNumber++; 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....", Gbl_ListingNode->Filename, Gbl_ListingNode->LineNumber); } else { /* No include files, just print the line number */ FlPrintFile (FileId, "%8d....", Gbl_SourceLine); } /* Read one line (up to a newline or EOF) */ while (FlReadFile (ASL_FILE_SOURCE_OUTPUT, &FileByte, 1) == AE_OK) { if (FileId == ASL_FILE_C_SOURCE_OUTPUT) { if (FileByte == '/') { FileByte = '*'; } } FlWriteFile (FileId, &FileByte, 1); if (FileByte == '\n') { /* * 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); } } /* EOF on the input file was reached */ return (0); }
static void LsDoHexOutputAsm ( void) { UINT32 j; UINT8 FileByte[HEX_TABLE_LINE_SIZE]; UINT8 Buffer[4]; UINT32 Offset = 0; BOOLEAN DoComma = FALSE; FlPrintFile (ASL_FILE_HEX_OUTPUT, "; Assembly code source output\n;\n"); /* Start at the beginning of the AML file */ FlSeekFile (ASL_FILE_AML_OUTPUT, 0); /* Process all AML bytes in the AML file */ j = 0; while (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte[j], 1) == AE_OK) { if (j == 0) { FlPrintFile (ASL_FILE_HEX_OUTPUT, " db "); } else if (DoComma) { FlPrintFile (ASL_FILE_HEX_OUTPUT, ","); DoComma = FALSE; } /* Convert each AML byte to hex */ UtConvertByteToAsmHex (FileByte[j], Buffer); FlWriteFile (ASL_FILE_HEX_OUTPUT, Buffer, 4); /* An occasional linefeed improves readability */ Offset++; j++; if (j >= HEX_TABLE_LINE_SIZE) { FlPrintFile (ASL_FILE_HEX_OUTPUT, " ;%8.8X", Offset - HEX_TABLE_LINE_SIZE); /* Write the ASCII character associated with each of the bytes */ LsDumpAscii (ASL_FILE_HEX_OUTPUT, HEX_TABLE_LINE_SIZE, FileByte); FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n"); j = 0; } else { DoComma = TRUE; } } FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n"); FlCloseFile (ASL_FILE_HEX_OUTPUT); }