1 /******************************************************************************
3 * Module Name: dttemplate - ACPI table template generation
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include "aslcompiler.h"
46 #include "dtcompiler.h"
47 #include "dttemplate.h" /* Contains the hex ACPI table templates */
49 #define _COMPONENT DT_COMPILER
50 ACPI_MODULE_NAME ("dttemplate")
53 /* Local prototypes */
56 AcpiUtIsSpecialTable (
62 const ACPI_DMTABLE_DATA *TableData);
65 DtCreateAllTemplates (
69 /*******************************************************************************
71 * FUNCTION: AcpiUtIsSpecialTable
73 * PARAMETERS: Signature - ACPI table signature
75 * RETURN: TRUE if signature is a special ACPI table
77 * DESCRIPTION: Check for valid ACPI tables that are not in the main ACPI
78 * table data structure (AcpiDmTableData).
80 ******************************************************************************/
83 AcpiUtIsSpecialTable (
87 if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_DSDT) ||
88 ACPI_COMPARE_NAME (Signature, ACPI_SIG_OSDT) ||
89 ACPI_COMPARE_NAME (Signature, ACPI_SIG_SSDT) ||
90 ACPI_COMPARE_NAME (Signature, ACPI_SIG_FACS) ||
91 ACPI_COMPARE_NAME (Signature, ACPI_RSDP_NAME))
100 /*******************************************************************************
102 * FUNCTION: DtCreateTemplates
104 * PARAMETERS: Signature - ACPI table signature
108 * DESCRIPTION: Create one or more template files.
110 ******************************************************************************/
116 const ACPI_DMTABLE_DATA *TableData;
120 AslInitializeGlobals ();
122 /* Default (no signature) is DSDT */
130 AcpiUtStrupr (Signature);
131 if (!strcmp (Signature, "ALL") ||
132 !strcmp (Signature, "*"))
134 /* Create all available/known templates */
136 Status = DtCreateAllTemplates ();
141 * Validate signature and get the template data:
142 * 1) Signature must be 4 characters
143 * 2) Signature must be a recognized ACPI table
144 * 3) There must be a template associated with the signature
146 if (strlen (Signature) != ACPI_NAME_SIZE)
149 "%s: Invalid ACPI table signature (length must be 4 characters)\n",
155 * Some slack for the two strange tables whose name is different than
156 * their signatures: MADT->APIC and FADT->FACP.
158 if (!strcmp (Signature, "MADT"))
162 else if (!strcmp (Signature, "FADT"))
168 TableData = AcpiDmGetTableData (Signature);
171 if (!TableData->Template)
173 fprintf (stderr, "%4.4s: No template available\n", Signature);
177 else if (!AcpiUtIsSpecialTable (Signature))
180 "%4.4s: Unrecognized ACPI table signature\n", Signature);
184 Status = AdInitialize ();
185 if (ACPI_FAILURE (Status))
190 Status = DtCreateOneTemplate (Signature, TableData);
193 /* Shutdown ACPICA subsystem */
195 (void) AcpiTerminate ();
201 /*******************************************************************************
203 * FUNCTION: DtCreateAllTemplates
209 * DESCRIPTION: Create all currently defined template files
211 ******************************************************************************/
214 DtCreateAllTemplates (
217 const ACPI_DMTABLE_DATA *TableData;
221 Status = AdInitialize ();
222 if (ACPI_FAILURE (Status))
227 fprintf (stderr, "Creating all supported Template files\n");
229 /* Walk entire ACPI table data structure */
231 for (TableData = AcpiDmTableData; TableData->Signature; TableData++)
233 /* If table has a template, create the template file */
235 if (TableData->Template)
237 Status = DtCreateOneTemplate (TableData->Signature,
239 if (ACPI_FAILURE (Status))
247 * Create the special ACPI tables:
248 * 1) DSDT/SSDT are AML tables, not data tables
249 * 2) FACS and RSDP have non-standard headers
251 Status = DtCreateOneTemplate (ACPI_SIG_DSDT, NULL);
252 if (ACPI_FAILURE (Status))
257 Status = DtCreateOneTemplate (ACPI_SIG_SSDT, NULL);
258 if (ACPI_FAILURE (Status))
263 Status = DtCreateOneTemplate (ACPI_SIG_FACS, NULL);
264 if (ACPI_FAILURE (Status))
269 Status = DtCreateOneTemplate (ACPI_RSDP_NAME, NULL);
270 if (ACPI_FAILURE (Status))
279 /*******************************************************************************
281 * FUNCTION: DtCreateOneTemplate
283 * PARAMETERS: Signature - ACPI signature, NULL terminated.
284 * TableData - Entry in ACPI table data structure.
285 * NULL if a special ACPI table.
289 * DESCRIPTION: Create one template source file for the requested ACPI table.
291 ******************************************************************************/
294 DtCreateOneTemplate (
296 const ACPI_DMTABLE_DATA *TableData)
298 char *DisasmFilename;
300 ACPI_STATUS Status = AE_OK;
304 /* New file will have a .asl suffix */
306 DisasmFilename = FlGenerateFilename (
307 Signature, FILE_SUFFIX_ASL_CODE);
310 fprintf (stderr, "Could not generate output filename\n");
314 /* Probably should prompt to overwrite the file */
316 AcpiUtStrlwr (DisasmFilename);
317 File = fopen (DisasmFilename, "w+");
320 fprintf (stderr, "Could not open output file %s\n", DisasmFilename);
324 /* Emit the common file header */
326 AcpiOsRedirectOutput (File);
328 AcpiOsPrintf ("/*\n");
329 AcpiOsPrintf (ACPI_COMMON_HEADER ("iASL Compiler/Disassembler", " * "));
331 AcpiOsPrintf (" * Template for [%4.4s] ACPI Table",
334 /* Dump the actual ACPI table */
338 /* Normal case, tables that appear in AcpiDmTableData */
340 AcpiOsPrintf (" (static data table)\n");
342 if (Gbl_VerboseTemplates)
344 AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength]"
345 " FieldName : HexFieldValue\n */\n\n");
349 AcpiOsPrintf (" * Format: [ByteLength]"
350 " FieldName : HexFieldValue\n */\n");
353 AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER,
354 TableData->Template));
358 /* Special ACPI tables - DSDT, SSDT, OSDT, FADT, RSDP */
360 AcpiOsPrintf (" (AML byte code table)\n");
362 AcpiOsPrintf (" */\n");
363 if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_DSDT))
365 Actual = fwrite (TemplateDsdt, 1, sizeof (TemplateDsdt) -1, File);
366 if (Actual != sizeof (TemplateDsdt) -1)
369 "Could not write to output file %s\n", DisasmFilename);
374 else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_SSDT))
376 Actual = fwrite (TemplateSsdt, 1, sizeof (TemplateSsdt) -1, File);
377 if (Actual != sizeof (TemplateSsdt) -1)
380 "Could not write to output file %s\n", DisasmFilename);
385 else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_OSDT))
387 Actual = fwrite (TemplateOsdt, 1, sizeof (TemplateOsdt) -1, File);
388 if (Actual != sizeof (TemplateOsdt) -1)
391 "Could not write to output file %s\n", DisasmFilename);
396 else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_FACS)) /* FADT */
398 AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER,
401 else if (ACPI_COMPARE_NAME (Signature, ACPI_RSDP_NAME))
403 AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER,
409 "%4.4s, Unrecognized ACPI table signature\n", Signature);
416 "Created ACPI table template for [%4.4s], written to \"%s\"\n",
417 Signature, DisasmFilename);
421 AcpiOsRedirectOutput (stdout);