1 /******************************************************************************
3 * Module Name: dtcompile.c - Front-end for data table compiler
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, 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 #define __DTCOMPILE_C__
45 #define _DECLARE_DT_GLOBALS
47 #include <contrib/dev/acpica/compiler/aslcompiler.h>
48 #include <contrib/dev/acpica/compiler/dtcompiler.h>
50 #define _COMPONENT DT_COMPILER
51 ACPI_MODULE_NAME ("dtcompile")
53 static char VersionString[9];
56 /* Local prototypes */
71 /******************************************************************************
73 * FUNCTION: DtDoCompile
79 * DESCRIPTION: Main entry point for the data table compiler.
81 * Note: Assumes Gbl_Files[ASL_FILE_INPUT] is initialized and the file is
82 * open at seek offset zero.
84 *****************************************************************************/
95 /* Initialize globals */
97 Status = DtInitialize ();
98 if (ACPI_FAILURE (Status))
100 printf ("Error during compiler initialization, 0x%X\n", Status);
105 * Scan the input file (file is already open) and
106 * build the parse tree
108 Event = UtBeginEvent ("Scan and parse input file");
109 FieldList = DtScanFile (Gbl_Files[ASL_FILE_INPUT].Handle);
112 /* Did the parse tree get successfully constructed? */
116 /* TBD: temporary error message. Msgs should come from function above */
118 DtError (ASL_ERROR, ASL_MSG_SYNTAX, NULL,
119 "Input file does not appear to be an ASL or data table source file");
125 Event = UtBeginEvent ("Compile parse tree");
128 * Compile the parse tree
130 Status = DtCompileDataTable (&FieldList);
135 if (ACPI_FAILURE (Status))
137 /* TBD: temporary error message. Msgs should come from function above */
139 DtError (ASL_ERROR, ASL_MSG_SYNTAX, NULL,
140 "Could not compile input file");
145 /* Create/open the binary output file */
147 Gbl_Files[ASL_FILE_AML_OUTPUT].Filename = NULL;
148 Status = FlOpenAmlOutputFile (Gbl_OutputFilenamePrefix);
149 if (ACPI_FAILURE (Status))
154 /* Write the binary, then the optional hex file */
156 DtOutputBinary (Gbl_RootTable);
158 DtWriteTableToListing ();
167 /******************************************************************************
169 * FUNCTION: DtInitialize
175 * DESCRIPTION: Initialize data table compiler globals. Enables multiple
176 * compiles per invocation.
178 *****************************************************************************/
187 Status = AcpiOsInitialize ();
188 if (ACPI_FAILURE (Status))
193 Status = AcpiUtInitGlobals ();
194 if (ACPI_FAILURE (Status))
199 Gbl_FieldList = NULL;
200 Gbl_RootTable = NULL;
201 Gbl_SubtableStack = NULL;
203 sprintf (VersionString, "%X", (UINT32) ACPI_CA_VERSION);
208 /******************************************************************************
210 * FUNCTION: DtInsertCompilerIds
212 * PARAMETERS: FieldList - Current field list pointer
216 * DESCRIPTION: Insert the IDs (Name, Version) of the current compiler into
217 * the original ACPI table header.
219 *****************************************************************************/
222 DtInsertCompilerIds (
230 * Don't insert current compiler ID if requested. Used for compiler
231 * debug/validation only.
233 if (Gbl_UseOriginalCompilerId)
238 /* Walk to the Compiler fields at the end of the header */
241 for (i = 0; i < 7; i++)
246 Next->Value = ASL_CREATOR_ID;
247 Next->Flags = DT_FIELD_NOT_ALLOCATED;
250 Next->Value = VersionString;
251 Next->Flags = DT_FIELD_NOT_ALLOCATED;
255 /******************************************************************************
257 * FUNCTION: DtCompileDataTable
259 * PARAMETERS: FieldList - Current field list pointer
263 * DESCRIPTION: Entry point to compile one data table
265 *****************************************************************************/
269 DT_FIELD **FieldList)
271 ACPI_DMTABLE_DATA *TableData;
272 DT_SUBTABLE *Subtable;
274 ACPI_TABLE_HEADER *AcpiTableHeader;
278 /* Verify that we at least have a table signature and save it */
280 Signature = DtGetFieldValue (*FieldList);
283 sprintf (MsgBuffer, "Expected \"%s\"", "Signature");
284 DtNameError (ASL_ERROR, ASL_MSG_INVALID_FIELD_NAME,
285 *FieldList, MsgBuffer);
289 Gbl_Signature = UtLocalCalloc (ACPI_STRLEN (Signature) + 1);
290 strcpy (Gbl_Signature, Signature);
293 * Handle tables that don't use the common ACPI table header structure.
294 * Currently, these are the FACS and RSDP. Also check for an OEMx table,
295 * these tables have user-defined contents.
297 if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_FACS))
299 Status = DtCompileFacs (FieldList);
300 if (ACPI_FAILURE (Status))
308 else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_RSDP))
310 Status = DtCompileRsdp (FieldList);
315 * All other tables must use the common ACPI table header. Insert the
316 * current iASL IDs (name, version), and compile the header now.
318 DtInsertCompilerIds (*FieldList);
320 Status = DtCompileTable (FieldList, AcpiDmTableInfoHeader,
321 &Gbl_RootTable, TRUE);
322 if (ACPI_FAILURE (Status))
327 DtPushSubtable (Gbl_RootTable);
329 /* Validate the signature via the ACPI table list */
331 TableData = AcpiDmGetTableData (Signature);
334 DtCompileGeneric ((void **) FieldList);
338 /* Dispatch to per-table compile */
340 if (TableData->CmTableHandler)
342 /* Complex table, has a handler */
344 Status = TableData->CmTableHandler ((void **) FieldList);
345 if (ACPI_FAILURE (Status))
350 else if (TableData->TableInfo)
352 /* Simple table, just walk the info table */
355 Status = DtCompileTable (FieldList, TableData->TableInfo,
357 if (ACPI_FAILURE (Status))
362 DtInsertSubtable (Gbl_RootTable, Subtable);
367 DtFatal (ASL_MSG_COMPILER_INTERNAL, *FieldList,
368 "Missing table dispatch info");
373 /* Set the final table length and then the checksum */
376 AcpiTableHeader = ACPI_CAST_PTR (
377 ACPI_TABLE_HEADER, Gbl_RootTable->Buffer);
378 DtSetTableChecksum (&AcpiTableHeader->Checksum);
384 /******************************************************************************
386 * FUNCTION: DtCompileTable
388 * PARAMETERS: Field - Current field list pointer
389 * Info - Info table for this ACPI table
390 * RetSubtable - Compile result of table
391 * Required - If this subtable must exist
395 * DESCRIPTION: Compile a subtable
397 *****************************************************************************/
402 ACPI_DMTABLE_INFO *Info,
403 DT_SUBTABLE **RetSubtable,
406 DT_FIELD *LocalField;
408 DT_SUBTABLE *Subtable;
409 DT_SUBTABLE *InlineSubtable;
410 UINT32 FieldLength = 0;
413 UINT8 *FlagBuffer = NULL;
417 if (!Field || !*Field)
419 return (AE_BAD_PARAMETER);
422 Length = DtGetSubtableLength (*Field, Info);
423 if (Length == ASL_EOF)
428 Subtable = UtLocalCalloc (sizeof (DT_SUBTABLE));
432 Subtable->Buffer = UtLocalCalloc (Length);
434 Subtable->Length = Length;
435 Subtable->TotalLength = Length;
436 Buffer = Subtable->Buffer;
441 * Main loop walks the info table for this ACPI table or subtable
443 for (; Info->Name; Info++)
447 sprintf (MsgBuffer, "Found NULL field - Field name \"%s\" needed",
449 DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer);
450 Status = AE_BAD_DATA;
454 /* Maintain table offsets */
456 LocalField->TableOffset = Gbl_CurrentTableOffset;
457 FieldLength = DtGetFieldLength (LocalField, Info);
458 Gbl_CurrentTableOffset += FieldLength;
460 FieldType = DtGetFieldType (Info);
461 Gbl_InputFieldCount++;
465 case DT_FIELD_TYPE_FLAGS_INTEGER:
467 * Start of the definition of a flags field.
468 * This master flags integer starts at value zero, in preparation
469 * to compile and insert the flag fields from the individual bits
471 LocalField = LocalField->Next;
477 case DT_FIELD_TYPE_FLAG:
479 /* Individual Flag field, can be multiple bits */
483 DtCompileFlag (FlagBuffer, LocalField, Info);
487 /* TBD - this is an internal error */
490 LocalField = LocalField->Next;
494 case DT_FIELD_TYPE_INLINE_SUBTABLE:
496 * Recursion (one level max): compile GAS (Generic Address)
497 * or Notify in-line subtable
501 if (Info->Opcode == ACPI_DMT_GAS)
503 Status = DtCompileTable (Field, AcpiDmTableInfoGas,
504 &InlineSubtable, TRUE);
508 Status = DtCompileTable (Field, AcpiDmTableInfoHestNotify,
509 &InlineSubtable, TRUE);
512 if (ACPI_FAILURE (Status))
517 DtSetSubtableLength (InlineSubtable);
519 ACPI_MEMCPY (Buffer, InlineSubtable->Buffer, FieldLength);
520 ACPI_FREE (InlineSubtable->Buffer);
521 ACPI_FREE (InlineSubtable);
525 case DT_FIELD_TYPE_LABEL:
527 DtWriteFieldToListing (Buffer, LocalField, 0);
528 LocalField = LocalField->Next;
533 /* Normal case for most field types (Integer, String, etc.) */
535 DtCompileOneField (Buffer, LocalField,
536 FieldLength, FieldType, Info->Flags);
538 DtWriteFieldToListing (Buffer, LocalField, FieldLength);
539 LocalField = LocalField->Next;
541 if (Info->Flags & DT_LENGTH)
543 /* Field is an Integer that will contain a subtable length */
545 Subtable->LengthField = Buffer;
546 Subtable->SizeOfLengthField = FieldLength;
552 Buffer += FieldLength;
556 *RetSubtable = Subtable;
560 ACPI_FREE (Subtable->Buffer);
561 ACPI_FREE (Subtable);