1 /******************************************************************************
3 * Module Name: dtcompile.c - Front-end for data table compiler
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 #define _DECLARE_DT_GLOBALS
46 #include "aslcompiler.h"
47 #include "dtcompiler.h"
49 #define _COMPONENT DT_COMPILER
50 ACPI_MODULE_NAME ("dtcompile")
52 static char VersionString[9];
55 /* Local prototypes */
70 /******************************************************************************
72 * FUNCTION: DtDoCompile
78 * DESCRIPTION: Main entry point for the data table compiler.
80 * Note: Assumes Gbl_Files[ASL_FILE_INPUT] is initialized and the file is
81 * open at seek offset zero.
83 *****************************************************************************/
94 /* Initialize globals */
96 Status = DtInitialize ();
97 if (ACPI_FAILURE (Status))
99 printf ("Error during compiler initialization, 0x%X\n", Status);
105 if (Gbl_PreprocessFlag)
109 Event = UtBeginEvent ("Preprocess input file");
113 if (Gbl_PreprocessOnly)
120 * Scan the input file (file is already open) and
121 * build the parse tree
123 Event = UtBeginEvent ("Scan and parse input file");
124 FieldList = DtScanFile (Gbl_Files[ASL_FILE_INPUT].Handle);
127 /* Did the parse tree get successfully constructed? */
131 /* TBD: temporary error message. Msgs should come from function above */
133 DtError (ASL_ERROR, ASL_MSG_SYNTAX, NULL,
134 "Input file does not appear to be an ASL or data table source file");
140 Event = UtBeginEvent ("Compile parse tree");
143 * Compile the parse tree
145 Status = DtCompileDataTable (&FieldList);
148 if (ACPI_FAILURE (Status))
150 /* TBD: temporary error message. Msgs should come from function above */
152 DtError (ASL_ERROR, ASL_MSG_SYNTAX, NULL,
153 "Could not compile input file");
158 /* Create/open the binary output file */
160 Gbl_Files[ASL_FILE_AML_OUTPUT].Filename = NULL;
161 Status = FlOpenAmlOutputFile (Gbl_OutputFilenamePrefix);
162 if (ACPI_FAILURE (Status))
167 /* Write the binary, then the optional hex file */
169 DtOutputBinary (Gbl_RootTable);
171 DtWriteTableToListing ();
175 AcpiUtDeleteCaches ();
182 /******************************************************************************
184 * FUNCTION: DtInitialize
190 * DESCRIPTION: Initialize data table compiler globals. Enables multiple
191 * compiles per invocation.
193 *****************************************************************************/
202 Status = AcpiOsInitialize ();
203 if (ACPI_FAILURE (Status))
208 Status = AcpiUtInitGlobals ();
209 if (ACPI_FAILURE (Status))
214 Gbl_FieldList = NULL;
215 Gbl_RootTable = NULL;
216 Gbl_SubtableStack = NULL;
218 sprintf (VersionString, "%X", (UINT32) ACPI_CA_VERSION);
223 /******************************************************************************
225 * FUNCTION: DtInsertCompilerIds
227 * PARAMETERS: FieldList - Current field list pointer
231 * DESCRIPTION: Insert the IDs (Name, Version) of the current compiler into
232 * the original ACPI table header.
234 *****************************************************************************/
237 DtInsertCompilerIds (
245 * Don't insert current compiler ID if requested. Used for compiler
246 * debug/validation only.
248 if (Gbl_UseOriginalCompilerId)
253 /* Walk to the Compiler fields at the end of the header */
256 for (i = 0; i < 7; i++)
261 Next->Value = ASL_CREATOR_ID;
262 Next->Flags = DT_FIELD_NOT_ALLOCATED;
265 Next->Value = VersionString;
266 Next->Flags = DT_FIELD_NOT_ALLOCATED;
270 /******************************************************************************
272 * FUNCTION: DtCompileDataTable
274 * PARAMETERS: FieldList - Current field list pointer
278 * DESCRIPTION: Entry point to compile one data table
280 *****************************************************************************/
284 DT_FIELD **FieldList)
286 const ACPI_DMTABLE_DATA *TableData;
287 DT_SUBTABLE *Subtable;
289 ACPI_TABLE_HEADER *AcpiTableHeader;
291 DT_FIELD *RootField = *FieldList;
294 /* Verify that we at least have a table signature and save it */
296 Signature = DtGetFieldValue (*FieldList);
299 sprintf (MsgBuffer, "Expected \"%s\"", "Signature");
300 DtNameError (ASL_ERROR, ASL_MSG_INVALID_FIELD_NAME,
301 *FieldList, MsgBuffer);
305 Gbl_Signature = UtStringCacheCalloc (ACPI_STRLEN (Signature) + 1);
306 strcpy (Gbl_Signature, Signature);
309 * Handle tables that don't use the common ACPI table header structure.
310 * Currently, these are the FACS and RSDP. Also check for an OEMx table,
311 * these tables have user-defined contents.
313 if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_FACS))
315 Status = DtCompileFacs (FieldList);
316 if (ACPI_FAILURE (Status))
324 else if (ACPI_VALIDATE_RSDP_SIG (Signature))
326 Status = DtCompileRsdp (FieldList);
329 else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_S3PT))
331 Status = DtCompileS3pt (FieldList);
332 if (ACPI_FAILURE (Status))
342 * All other tables must use the common ACPI table header. Insert the
343 * current iASL IDs (name, version), and compile the header now.
345 DtInsertCompilerIds (*FieldList);
347 Status = DtCompileTable (FieldList, AcpiDmTableInfoHeader,
348 &Gbl_RootTable, TRUE);
349 if (ACPI_FAILURE (Status))
354 DtPushSubtable (Gbl_RootTable);
356 /* Validate the signature via the ACPI table list */
358 TableData = AcpiDmGetTableData (Signature);
359 if (!TableData || Gbl_CompileGeneric)
361 DtCompileGeneric ((void **) FieldList, NULL, NULL);
365 /* Dispatch to per-table compile */
367 if (TableData->CmTableHandler)
369 /* Complex table, has a handler */
371 Status = TableData->CmTableHandler ((void **) FieldList);
372 if (ACPI_FAILURE (Status))
377 else if (TableData->TableInfo)
379 /* Simple table, just walk the info table */
382 Status = DtCompileTable (FieldList, TableData->TableInfo,
384 if (ACPI_FAILURE (Status))
389 DtInsertSubtable (Gbl_RootTable, Subtable);
394 DtFatal (ASL_MSG_COMPILER_INTERNAL, *FieldList,
395 "Missing table dispatch info");
401 /* Set the final table length and then the checksum */
404 AcpiTableHeader = ACPI_CAST_PTR (
405 ACPI_TABLE_HEADER, Gbl_RootTable->Buffer);
406 DtSetTableChecksum (&AcpiTableHeader->Checksum);
408 DtDumpFieldList (RootField);
409 DtDumpSubtableList ();
414 /******************************************************************************
416 * FUNCTION: DtCompileTable
418 * PARAMETERS: Field - Current field list pointer
419 * Info - Info table for this ACPI table
420 * RetSubtable - Compile result of table
421 * Required - If this subtable must exist
425 * DESCRIPTION: Compile a subtable
427 *****************************************************************************/
432 ACPI_DMTABLE_INFO *Info,
433 DT_SUBTABLE **RetSubtable,
436 DT_FIELD *LocalField;
438 DT_SUBTABLE *Subtable;
439 DT_SUBTABLE *InlineSubtable = NULL;
440 UINT32 FieldLength = 0;
443 UINT8 *FlagBuffer = NULL;
445 UINT32 CurrentFlagByteOffset = 0;
446 ACPI_STATUS Status = AE_OK;
449 if (!Field || !*Field)
451 return (AE_BAD_PARAMETER);
454 /* Ignore optional subtable if name does not match */
456 if ((Info->Flags & DT_OPTIONAL) &&
457 ACPI_STRCMP ((*Field)->Name, Info->Name))
463 Length = DtGetSubtableLength (*Field, Info);
464 if (Length == ASL_EOF)
469 Subtable = UtSubtableCacheCalloc ();
473 String = UtStringCacheCalloc (Length);
474 Subtable->Buffer = ACPI_CAST_PTR (UINT8, String);
477 Subtable->Length = Length;
478 Subtable->TotalLength = Length;
479 Buffer = Subtable->Buffer;
482 Subtable->Name = LocalField->Name;
485 * Main loop walks the info table for this ACPI table or subtable
487 for (; Info->Name; Info++)
489 if (Info->Opcode == ACPI_DMT_EXTRA_TEXT)
496 sprintf (MsgBuffer, "Found NULL field - Field name \"%s\" needed",
498 DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer);
499 Status = AE_BAD_DATA;
503 /* Maintain table offsets */
505 LocalField->TableOffset = Gbl_CurrentTableOffset;
506 FieldLength = DtGetFieldLength (LocalField, Info);
507 Gbl_CurrentTableOffset += FieldLength;
509 FieldType = DtGetFieldType (Info);
510 Gbl_InputFieldCount++;
514 case DT_FIELD_TYPE_FLAGS_INTEGER:
516 * Start of the definition of a flags field.
517 * This master flags integer starts at value zero, in preparation
518 * to compile and insert the flag fields from the individual bits
520 LocalField = LocalField->Next;
524 CurrentFlagByteOffset = Info->Offset;
527 case DT_FIELD_TYPE_FLAG:
529 /* Individual Flag field, can be multiple bits */
534 * We must increment the FlagBuffer when we have crossed
535 * into the next flags byte within the flags field
536 * of type DT_FIELD_TYPE_FLAGS_INTEGER.
538 FlagBuffer += (Info->Offset - CurrentFlagByteOffset);
539 CurrentFlagByteOffset = Info->Offset;
541 DtCompileFlag (FlagBuffer, LocalField, Info);
545 /* TBD - this is an internal error */
548 LocalField = LocalField->Next;
552 case DT_FIELD_TYPE_INLINE_SUBTABLE:
554 * Recursion (one level max): compile GAS (Generic Address)
555 * or Notify in-line subtable
559 switch (Info->Opcode)
563 Status = DtCompileTable (Field, AcpiDmTableInfoGas,
564 &InlineSubtable, TRUE);
567 case ACPI_DMT_HESTNTFY:
569 Status = DtCompileTable (Field, AcpiDmTableInfoHestNotify,
570 &InlineSubtable, TRUE);
573 case ACPI_DMT_IORTMEM:
575 Status = DtCompileTable (Field, AcpiDmTableInfoIortAcc,
576 &InlineSubtable, TRUE);
580 sprintf (MsgBuffer, "Invalid DMT opcode: 0x%.2X",
582 DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer);
583 Status = AE_BAD_DATA;
587 if (ACPI_FAILURE (Status))
592 DtSetSubtableLength (InlineSubtable);
594 ACPI_MEMCPY (Buffer, InlineSubtable->Buffer, FieldLength);
598 case DT_FIELD_TYPE_LABEL:
600 DtWriteFieldToListing (Buffer, LocalField, 0);
601 LocalField = LocalField->Next;
606 /* Normal case for most field types (Integer, String, etc.) */
608 DtCompileOneField (Buffer, LocalField,
609 FieldLength, FieldType, Info->Flags);
611 DtWriteFieldToListing (Buffer, LocalField, FieldLength);
612 LocalField = LocalField->Next;
614 if (Info->Flags & DT_LENGTH)
616 /* Field is an Integer that will contain a subtable length */
618 Subtable->LengthField = Buffer;
619 Subtable->SizeOfLengthField = FieldLength;
624 Buffer += FieldLength;
628 *RetSubtable = Subtable;
632 ACPI_FREE (Subtable->Buffer);
633 ACPI_FREE (Subtable);
638 /******************************************************************************
640 * FUNCTION: DtCompilePadding
642 * PARAMETERS: Length - Padding field size
643 * RetSubtable - Compile result of table
647 * DESCRIPTION: Compile a subtable for padding purpose
649 *****************************************************************************/
654 DT_SUBTABLE **RetSubtable)
656 DT_SUBTABLE *Subtable;
661 Subtable = UtSubtableCacheCalloc ();
665 String = UtStringCacheCalloc (Length);
666 Subtable->Buffer = ACPI_CAST_PTR (UINT8, String);
669 Subtable->Length = Length;
670 Subtable->TotalLength = Length;
671 /* Buffer = Subtable->Buffer; */
673 *RetSubtable = Subtable;