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 (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 /* Unknown table signature and/or force generic compile */
363 DtCompileGeneric ((void **) FieldList, NULL, NULL);
367 /* Dispatch to per-table compile */
369 if (TableData->CmTableHandler)
371 /* Complex table, has a handler */
373 Status = TableData->CmTableHandler ((void **) FieldList);
374 if (ACPI_FAILURE (Status))
379 else if (TableData->TableInfo)
381 /* Simple table, just walk the info table */
384 Status = DtCompileTable (FieldList, TableData->TableInfo,
386 if (ACPI_FAILURE (Status))
391 DtInsertSubtable (Gbl_RootTable, Subtable);
396 DtFatal (ASL_MSG_COMPILER_INTERNAL, *FieldList,
397 "Missing table dispatch info");
403 /* Set the final table length and then the checksum */
406 AcpiTableHeader = ACPI_CAST_PTR (
407 ACPI_TABLE_HEADER, Gbl_RootTable->Buffer);
408 DtSetTableChecksum (&AcpiTableHeader->Checksum);
410 DtDumpFieldList (RootField);
411 DtDumpSubtableList ();
416 /******************************************************************************
418 * FUNCTION: DtCompileTable
420 * PARAMETERS: Field - Current field list pointer
421 * Info - Info table for this ACPI table
422 * RetSubtable - Compile result of table
423 * Required - If this subtable must exist
427 * DESCRIPTION: Compile a subtable
429 *****************************************************************************/
434 ACPI_DMTABLE_INFO *Info,
435 DT_SUBTABLE **RetSubtable,
438 DT_FIELD *LocalField;
440 DT_SUBTABLE *Subtable;
441 DT_SUBTABLE *InlineSubtable = NULL;
442 UINT32 FieldLength = 0;
445 UINT8 *FlagBuffer = NULL;
447 UINT32 CurrentFlagByteOffset = 0;
448 ACPI_STATUS Status = AE_OK;
451 if (!Field || !*Field)
453 return (AE_BAD_PARAMETER);
456 /* Ignore optional subtable if name does not match */
458 if ((Info->Flags & DT_OPTIONAL) &&
459 strcmp ((*Field)->Name, Info->Name))
465 Length = DtGetSubtableLength (*Field, Info);
466 if (Length == ASL_EOF)
471 Subtable = UtSubtableCacheCalloc ();
475 String = UtStringCacheCalloc (Length);
476 Subtable->Buffer = ACPI_CAST_PTR (UINT8, String);
479 Subtable->Length = Length;
480 Subtable->TotalLength = Length;
481 Buffer = Subtable->Buffer;
484 Subtable->Name = LocalField->Name;
487 * Main loop walks the info table for this ACPI table or subtable
489 for (; Info->Name; Info++)
491 if (Info->Opcode == ACPI_DMT_EXTRA_TEXT)
498 sprintf (MsgBuffer, "Found NULL field - Field name \"%s\" needed",
500 DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer);
501 Status = AE_BAD_DATA;
505 /* Maintain table offsets */
507 LocalField->TableOffset = Gbl_CurrentTableOffset;
508 FieldLength = DtGetFieldLength (LocalField, Info);
509 Gbl_CurrentTableOffset += FieldLength;
511 FieldType = DtGetFieldType (Info);
512 Gbl_InputFieldCount++;
516 case DT_FIELD_TYPE_FLAGS_INTEGER:
518 * Start of the definition of a flags field.
519 * This master flags integer starts at value zero, in preparation
520 * to compile and insert the flag fields from the individual bits
522 LocalField = LocalField->Next;
526 CurrentFlagByteOffset = Info->Offset;
529 case DT_FIELD_TYPE_FLAG:
531 /* Individual Flag field, can be multiple bits */
536 * We must increment the FlagBuffer when we have crossed
537 * into the next flags byte within the flags field
538 * of type DT_FIELD_TYPE_FLAGS_INTEGER.
540 FlagBuffer += (Info->Offset - CurrentFlagByteOffset);
541 CurrentFlagByteOffset = Info->Offset;
543 DtCompileFlag (FlagBuffer, LocalField, Info);
547 /* TBD - this is an internal error */
550 LocalField = LocalField->Next;
554 case DT_FIELD_TYPE_INLINE_SUBTABLE:
556 * Recursion (one level max): compile GAS (Generic Address)
557 * or Notify in-line subtable
561 switch (Info->Opcode)
565 Status = DtCompileTable (Field, AcpiDmTableInfoGas,
566 &InlineSubtable, TRUE);
569 case ACPI_DMT_HESTNTFY:
571 Status = DtCompileTable (Field, AcpiDmTableInfoHestNotify,
572 &InlineSubtable, TRUE);
575 case ACPI_DMT_IORTMEM:
577 Status = DtCompileTable (Field, AcpiDmTableInfoIortAcc,
578 &InlineSubtable, TRUE);
582 sprintf (MsgBuffer, "Invalid DMT opcode: 0x%.2X",
584 DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer);
585 Status = AE_BAD_DATA;
589 if (ACPI_FAILURE (Status))
594 DtSetSubtableLength (InlineSubtable);
596 memcpy (Buffer, InlineSubtable->Buffer, FieldLength);
600 case DT_FIELD_TYPE_LABEL:
602 DtWriteFieldToListing (Buffer, LocalField, 0);
603 LocalField = LocalField->Next;
608 /* Normal case for most field types (Integer, String, etc.) */
610 DtCompileOneField (Buffer, LocalField,
611 FieldLength, FieldType, Info->Flags);
613 DtWriteFieldToListing (Buffer, LocalField, FieldLength);
614 LocalField = LocalField->Next;
616 if (Info->Flags & DT_LENGTH)
618 /* Field is an Integer that will contain a subtable length */
620 Subtable->LengthField = Buffer;
621 Subtable->SizeOfLengthField = FieldLength;
626 Buffer += FieldLength;
630 *RetSubtable = Subtable;
634 ACPI_FREE (Subtable->Buffer);
635 ACPI_FREE (Subtable);
640 /******************************************************************************
642 * FUNCTION: DtCompilePadding
644 * PARAMETERS: Length - Padding field size
645 * RetSubtable - Compile result of table
649 * DESCRIPTION: Compile a subtable for padding purpose
651 *****************************************************************************/
656 DT_SUBTABLE **RetSubtable)
658 DT_SUBTABLE *Subtable;
663 Subtable = UtSubtableCacheCalloc ();
667 String = UtStringCacheCalloc (Length);
668 Subtable->Buffer = ACPI_CAST_PTR (UINT8, String);
671 Subtable->Length = Length;
672 Subtable->TotalLength = Length;
673 /* Buffer = Subtable->Buffer; */
675 *RetSubtable = Subtable;