static ACPI_STATUS DtCreateOneTemplate ( char *Signature, ACPI_DMTABLE_DATA *TableData) { char *DisasmFilename; FILE *File; ACPI_STATUS Status = AE_OK; ACPI_SIZE Actual; /* New file will have a .asl suffix */ DisasmFilename = FlGenerateFilename ( Signature, FILE_SUFFIX_ASL_CODE); if (!DisasmFilename) { fprintf (stderr, "Could not generate output filename\n"); return (AE_ERROR); } /* Probably should prompt to overwrite the file */ AcpiUtStrlwr (DisasmFilename); File = fopen (DisasmFilename, "w+"); if (!File) { fprintf (stderr, "Could not open output file %s\n", DisasmFilename); return (AE_ERROR); } /* Emit the common file header */ AcpiOsRedirectOutput (File); AcpiOsPrintf ("/*\n"); AcpiOsPrintf (ACPI_COMMON_HEADER ("iASL Compiler/Disassembler", " * ")); AcpiOsPrintf (" * Template for [%4.4s] ACPI Table\n", Signature); /* Dump the actual ACPI table */ if (TableData) { /* Normal case, tables that appear in AcpiDmTableData */ 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)); } else { /* Special ACPI tables - DSDT, SSDT, FADT, RSDP */ AcpiOsPrintf (" */\n\n"); if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_DSDT)) { Actual = fwrite (TemplateDsdt, 1, sizeof (TemplateDsdt) -1, File); if (Actual != sizeof (TemplateDsdt) -1) { fprintf (stderr, "Could not write to output file %s\n", DisasmFilename); Status = AE_ERROR; goto Cleanup; } } else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_SSDT)) { Actual = fwrite (TemplateSsdt, 1, sizeof (TemplateSsdt) -1, File); if (Actual != sizeof (TemplateSsdt) -1) { fprintf (stderr, "Could not write to output file %s\n", DisasmFilename); Status = AE_ERROR; goto Cleanup; } } else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_FACS)) /* FADT */ { AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER, TemplateFacs)); } else if (ACPI_COMPARE_NAME (Signature, ACPI_RSDP_NAME)) { AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER, TemplateRsdp)); } else { fprintf (stderr, "%4.4s, Unrecognized ACPI table signature\n", Signature); Status = AE_ERROR; goto Cleanup; } } fprintf (stderr, "Created ACPI table template for [%4.4s], written to \"%s\"\n", Signature, DisasmFilename); Cleanup: fclose (File); AcpiOsRedirectOutput (stdout); ACPI_FREE (DisasmFilename); return (Status); }
static ACPI_STATUS DtCreateOneTemplate ( char *Signature, UINT32 TableCount, const ACPI_DMTABLE_DATA *TableData) { char *DisasmFilename; FILE *File; ACPI_STATUS Status = AE_OK; int Actual; UINT32 i; /* New file will have a .asl suffix */ DisasmFilename = FlGenerateFilename ( Signature, FILE_SUFFIX_ASL_CODE); if (!DisasmFilename) { fprintf (stderr, "Could not generate output filename\n"); return (AE_ERROR); } AcpiUtStrlwr (DisasmFilename); if (!UtQueryForOverwrite (DisasmFilename)) { return (AE_ERROR); } File = fopen (DisasmFilename, "w+"); if (!File) { fprintf (stderr, "Could not open output file %s\n", DisasmFilename); return (AE_ERROR); } /* Emit the common file header */ AcpiOsRedirectOutput (File); AcpiOsPrintf ("/*\n"); AcpiOsPrintf (ACPI_COMMON_HEADER ("iASL Compiler/Disassembler", " * ")); if (TableCount == 0) { AcpiOsPrintf (" * Template for [%4.4s] ACPI Table", Signature); } else { AcpiOsPrintf (" * Template for [%4.4s] and %u [SSDT] ACPI Tables", Signature, TableCount); } /* Dump the actual ACPI table */ if (TableData) { /* Normal case, tables that appear in AcpiDmTableData */ AcpiOsPrintf (" (static data table)\n"); if (AslGbl_VerboseTemplates) { AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength]" " FieldName : HexFieldValue\n */\n\n"); } else { AcpiOsPrintf (" * Format: [ByteLength]" " FieldName : HexFieldValue\n */\n"); } AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER, TableData->Template)); } else { /* Special ACPI tables - DSDT, SSDT, OSDT, FACS, RSDP */ AcpiOsPrintf (" (AML byte code table)\n"); AcpiOsPrintf (" */\n"); if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_DSDT)) { Actual = DtEmitDefinitionBlock ( File, DisasmFilename, ACPI_SIG_DSDT, 1); if (Actual < 0) { Status = AE_ERROR; goto Cleanup; } /* Emit any requested SSDTs into the same file */ for (i = 1; i <= TableCount; i++) { Actual = DtEmitDefinitionBlock ( File, DisasmFilename, ACPI_SIG_SSDT, i + 1); if (Actual < 0) { Status = AE_ERROR; goto Cleanup; } } } else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_SSDT)) { Actual = DtEmitDefinitionBlock ( File, DisasmFilename, ACPI_SIG_SSDT, 1); if (Actual < 0) { Status = AE_ERROR; goto Cleanup; } } else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_OSDT)) { Actual = DtEmitDefinitionBlock ( File, DisasmFilename, ACPI_SIG_OSDT, 1); if (Actual < 0) { Status = AE_ERROR; goto Cleanup; } } else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_FACS)) { AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER, TemplateFacs)); } else if (ACPI_COMPARE_NAME (Signature, ACPI_RSDP_NAME)) { AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER, TemplateRsdp)); } else { fprintf (stderr, "%4.4s, Unrecognized ACPI table signature\n", Signature); Status = AE_ERROR; goto Cleanup; } } if (TableCount == 0) { fprintf (stderr, "Created ACPI table template for [%4.4s], " "written to \"%s\"\n", Signature, DisasmFilename); } else { fprintf (stderr, "Created ACPI table templates for [%4.4s] " "and %u [SSDT], written to \"%s\"\n", Signature, TableCount, DisasmFilename); } Cleanup: fclose (File); AcpiOsRedirectOutput (stdout); return (Status); }
void AsInsertPrefix ( char *Buffer, char *Keyword, UINT8 Type) { char *SubString; char *SubBuffer; char *EndKeyword; int InsertLength; char *InsertString; int TrailingSpaces; char LowerKeyword[128]; int KeywordLength; switch (Type) { case SRC_TYPE_STRUCT: InsertString = "struct "; break; case SRC_TYPE_UNION: InsertString = "union "; break; default: return; } strcpy (LowerKeyword, Keyword); AcpiUtStrlwr (LowerKeyword); SubBuffer = Buffer; SubString = Buffer; InsertLength = strlen (InsertString); KeywordLength = strlen (Keyword); while (SubString) { /* Find an instance of the keyword */ SubString = strstr (SubBuffer, LowerKeyword); if (!SubString) { return; } SubBuffer = SubString; /* Must be standalone word, not a substring */ if (AsMatchExactWord (SubString, KeywordLength)) { /* Make sure the keyword isn't already prefixed with the insert */ if (!strncmp (SubString - InsertLength, InsertString, InsertLength)) { /* Add spaces if not already at the end-of-line */ if (*(SubBuffer + KeywordLength) != '\n') { /* Already present, add spaces after to align structure members */ #if 0 /* ONLY FOR C FILES */ AsInsertData (SubBuffer + KeywordLength, " ", 8); #endif } goto Next; } /* Make sure the keyword isn't at the end of a struct/union */ /* Note: This code depends on a single space after the brace */ if (*(SubString - 2) == '}') { goto Next; } /* Prefix the keyword with the insert string */ Gbl_MadeChanges = TRUE; /* Is there room for insertion */ EndKeyword = SubString + strlen (LowerKeyword); TrailingSpaces = 0; while (EndKeyword[TrailingSpaces] == ' ') { TrailingSpaces++; } /* * Use "if (TrailingSpaces > 1)" if we want to ignore casts */ SubBuffer = SubString + InsertLength; if (TrailingSpaces > InsertLength) { /* Insert the keyword */ memmove (SubBuffer, SubString, KeywordLength); /* Insert the keyword */ memmove (SubString, InsertString, InsertLength); } else { AsInsertData (SubString, InsertString, InsertLength); } } Next: SubBuffer += KeywordLength; } }
int AxExtractTables ( char *InputPathname, char *Signature, unsigned int MinimumInstances) { FILE *InputFile; FILE *OutputFile = NULL; unsigned int BytesConverted; unsigned int ThisTableBytesWritten = 0; unsigned int FoundTable = 0; unsigned int Instances = 0; unsigned int ThisInstance; char ThisSignature[5]; char UpperSignature[5]; int Status = 0; unsigned int State = AX_STATE_FIND_HEADER; /* Open input in text mode, output is in binary mode */ InputFile = fopen (InputPathname, "rt"); if (!InputFile) { printf ("Could not open input file %s\n", InputPathname); return (-1); } if (!AxIsFileAscii (InputFile)) { fclose (InputFile); return (-1); } if (Signature) { strncpy (UpperSignature, Signature, 4); UpperSignature[4] = 0; AcpiUtStrupr (UpperSignature); /* Are there enough instances of the table to continue? */ AxNormalizeSignature (UpperSignature); Instances = AxCountTableInstances (InputPathname, UpperSignature); if (Instances < MinimumInstances) { printf ("Table [%s] was not found in %s\n", UpperSignature, InputPathname); fclose (InputFile); return (-1); } if (Instances == 0) { fclose (InputFile); return (-1); } } /* Convert all instances of the table to binary */ while (fgets (Gbl_LineBuffer, AX_LINE_BUFFER_SIZE, InputFile)) { switch (State) { case AX_STATE_FIND_HEADER: if (!AxIsDataBlockHeader ()) { continue; } ACPI_MOVE_NAME (ThisSignature, Gbl_LineBuffer); if (Signature) { /* Ignore signatures that don't match */ if (!ACPI_COMPARE_NAME (ThisSignature, UpperSignature)) { continue; } } /* * Get the instance number for this signature. Only the * SSDT and PSDT tables can have multiple instances. */ ThisInstance = AxGetNextInstance (InputPathname, ThisSignature); /* Build an output filename and create/open the output file */ if (ThisInstance > 0) { /* Add instance number to the output filename */ sprintf (Gbl_OutputFilename, "%4.4s%u.dat", ThisSignature, ThisInstance); } else { sprintf (Gbl_OutputFilename, "%4.4s.dat", ThisSignature); } AcpiUtStrlwr (Gbl_OutputFilename); OutputFile = fopen (Gbl_OutputFilename, "w+b"); if (!OutputFile) { printf ("Could not open output file %s\n", Gbl_OutputFilename); fclose (InputFile); return (-1); } /* * Toss this block header of the form "<sig> @ <addr>" line * and move on to the actual data block */ Gbl_TableCount++; FoundTable = 1; ThisTableBytesWritten = 0; State = AX_STATE_EXTRACT_DATA; continue; case AX_STATE_EXTRACT_DATA: /* Empty line or non-data line terminates the data block */ BytesConverted = AxProcessOneTextLine ( OutputFile, ThisSignature, ThisTableBytesWritten); switch (BytesConverted) { case 0: State = AX_STATE_FIND_HEADER; /* No more data block lines */ continue; case -1: goto CleanupAndExit; /* There was a write error */ default: /* Normal case, get next line */ ThisTableBytesWritten += BytesConverted; continue; } default: Status = -1; goto CleanupAndExit; } } if (!FoundTable) { printf ("No ACPI tables were found in %s\n", InputPathname); } CleanupAndExit: if (State == AX_STATE_EXTRACT_DATA) { /* Received an input file EOF while extracting data */ printf (AX_TABLE_INFO_FORMAT, ThisSignature, ThisTableBytesWritten, Gbl_OutputFilename); } if (Gbl_TableCount > 1) { printf ("\n%u binary ACPI tables extracted\n", Gbl_TableCount); } if (OutputFile) { fclose (OutputFile); } fclose (InputFile); return (Status); }