1 /******************************************************************************
3 * Module Name: aslstartup - Compiler startup routines, called from main
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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.
45 #include "aslcompiler.h"
50 #define _COMPONENT ACPI_COMPILER
51 ACPI_MODULE_NAME ("aslstartup")
54 /* Local prototypes */
57 AslDetectSourceFileType (
67 static BOOLEAN AslToFile
= TRUE
;
70 /*******************************************************************************
72 * FUNCTION: AslInitializeGlobals
78 * DESCRIPTION: Re-initialize globals needed to restart the compiler. This
79 * allows multiple files to be disassembled and/or compiled.
81 ******************************************************************************/
84 AslInitializeGlobals (
90 /* Init compiler globals */
92 Gbl_CurrentColumn
= 0;
93 Gbl_CurrentLineNumber
= 1;
94 Gbl_LogicalLineNumber
= 1;
95 Gbl_CurrentLineOffset
= 0;
96 Gbl_InputFieldCount
= 0;
97 Gbl_InputByteCount
= 0;
98 Gbl_NsLookupCount
= 0;
99 Gbl_LineBufPtr
= Gbl_CurrentLineBuffer
;
102 Gbl_NextError
= NULL
;
103 Gbl_Signature
= NULL
;
106 TotalExecutableOpcodes
= 0;
107 TotalNamedObjects
= 0;
111 TotalAllocations
= 0;
115 AslGbl_NextEvent
= 0;
116 for (i
= 0; i
< ASL_NUM_REPORT_LEVELS
; i
++)
118 Gbl_ExceptionCount
[i
] = 0;
121 for (i
= ASL_FILE_INPUT
; i
<= ASL_MAX_FILE_TYPE
; i
++)
123 Gbl_Files
[i
].Handle
= NULL
;
124 Gbl_Files
[i
].Filename
= NULL
;
129 /*******************************************************************************
131 * FUNCTION: AslDetectSourceFileType
133 * PARAMETERS: Info - Name/Handle for the file (must be open)
137 * DESCRIPTION: Determine the type of the input file. Either binary (contains
138 * non-ASCII characters), ASL file, or an ACPI Data Table file.
140 ******************************************************************************/
143 AslDetectSourceFileType (
151 /* Check for a valid binary ACPI table */
153 Status
= FlCheckForAcpiTable (Info
->Handle
);
154 if (ACPI_SUCCESS (Status
))
156 Type
= ASL_INPUT_TYPE_ACPI_TABLE
;
160 /* Check for 100% ASCII source file (comments are ignored) */
162 Status
= FlCheckForAscii (Info
->Handle
, Info
->Filename
, TRUE
);
163 if (ACPI_FAILURE (Status
))
165 printf ("Non-ascii input file - %s\n", Info
->Filename
);
167 if (!Gbl_IgnoreErrors
)
169 Type
= ASL_INPUT_TYPE_BINARY
;
175 * File is ASCII. Determine if this is an ASL file or an ACPI data
178 while (fgets (Gbl_CurrentLineBuffer
, Gbl_LineBufferSize
, Info
->Handle
))
180 /* Uppercase the buffer for caseless compare */
182 FileChar
= Gbl_CurrentLineBuffer
;
185 *FileChar
= (char) toupper ((int) *FileChar
);
189 /* Presence of "DefinitionBlock" indicates actual ASL code */
191 if (strstr (Gbl_CurrentLineBuffer
, "DEFINITIONBLOCK"))
193 /* Appears to be an ASL file */
195 Type
= ASL_INPUT_TYPE_ASCII_ASL
;
200 /* Not an ASL source file, default to a data table source file */
202 Type
= ASL_INPUT_TYPE_ASCII_DATA
;
206 /* Must seek back to the start of the file */
208 fseek (Info
->Handle
, 0, SEEK_SET
);
213 /*******************************************************************************
215 * FUNCTION: AslDoDisassembly
221 * DESCRIPTION: Initiate AML file disassembly. Uses ACPICA subsystem to build
224 ******************************************************************************/
233 /* ACPICA subsystem initialization */
235 Status
= AdInitialize ();
236 if (ACPI_FAILURE (Status
))
241 Status
= AcpiAllocateRootTable (4);
242 if (ACPI_FAILURE (Status
))
244 AcpiOsPrintf ("Could not initialize ACPI Table Manager, %s\n",
245 AcpiFormatException (Status
));
249 /* This is where the disassembly happens */
251 AcpiGbl_DbOpt_disasm
= TRUE
;
252 Status
= AdAmlDisassemble (AslToFile
,
253 Gbl_Files
[ASL_FILE_INPUT
].Filename
, Gbl_OutputFilenamePrefix
,
254 &Gbl_Files
[ASL_FILE_INPUT
].Filename
, Gbl_GetAllTables
);
255 if (ACPI_FAILURE (Status
))
260 /* Check if any control methods were unresolved */
262 AcpiDmUnresolvedWarning (0);
265 /* TBD: Handle additional output files for disassembler */
267 Status
= FlOpenMiscOutputFiles (Gbl_OutputFilenamePrefix
);
268 NsDisplayNamespace ();
271 /* Shutdown compiler and ACPICA subsystem */
274 (void) AcpiTerminate ();
277 * Gbl_Files[ASL_FILE_INPUT].Filename was replaced with the
278 * .DSL disassembly file, which can now be compiled if requested
282 AcpiOsPrintf ("\nCompiling \"%s\"\n",
283 Gbl_Files
[ASL_FILE_INPUT
].Filename
);
284 return (AE_CTRL_CONTINUE
);
287 ACPI_FREE (Gbl_Files
[ASL_FILE_INPUT
].Filename
);
288 Gbl_Files
[ASL_FILE_INPUT
].Filename
= NULL
;
293 /*******************************************************************************
295 * FUNCTION: AslDoOneFile
297 * PARAMETERS: Filename - Name of the file
301 * DESCRIPTION: Process a single file - either disassemble, compile, or both
303 ******************************************************************************/
312 /* Re-initialize "some" compiler/preprocessor globals */
314 AslInitializeGlobals ();
315 PrInitializeGlobals ();
318 * Extract the directory path. This path is used for possible include
319 * files and the optional AML filename embedded in the input file
320 * DefinitionBlock declaration.
322 Status
= FlSplitInputPathname (Filename
, &Gbl_DirectoryPath
, NULL
);
323 if (ACPI_FAILURE (Status
))
328 Gbl_Files
[ASL_FILE_INPUT
].Filename
= Filename
;
331 * AML Disassembly (Optional)
333 if (Gbl_DisasmFlag
|| Gbl_GetAllTables
)
335 Status
= AslDoDisassembly ();
336 if (Status
!= AE_CTRL_CONTINUE
)
343 * Open the input file. Here, this should be an ASCII source file,
344 * either an ASL file or a Data Table file
346 Status
= FlOpenInputFile (Gbl_Files
[ASL_FILE_INPUT
].Filename
);
347 if (ACPI_FAILURE (Status
))
349 AePrintErrorLog (ASL_FILE_STDERR
);
353 /* Determine input file type */
355 Gbl_FileType
= AslDetectSourceFileType (&Gbl_Files
[ASL_FILE_INPUT
]);
356 if (Gbl_FileType
== ASL_INPUT_TYPE_BINARY
)
362 * If -p not specified, we will use the input filename as the
363 * output filename prefix
365 if (Gbl_UseDefaultAmlFilename
)
367 Gbl_OutputFilenamePrefix
= Gbl_Files
[ASL_FILE_INPUT
].Filename
;
370 /* Open the optional output files (listings, etc.) */
372 Status
= FlOpenMiscOutputFiles (Gbl_OutputFilenamePrefix
);
373 if (ACPI_FAILURE (Status
))
375 AePrintErrorLog (ASL_FILE_STDERR
);
380 * Compilation of ASL source versus DataTable source uses different
381 * compiler subsystems
383 switch (Gbl_FileType
)
386 * Data Table Compilation
388 case ASL_INPUT_TYPE_ASCII_DATA
:
390 Status
= DtDoCompile ();
391 if (ACPI_FAILURE (Status
))
398 ACPI_FREE (Gbl_Signature
);
399 Gbl_Signature
= NULL
;
402 /* Check if any errors occurred during compile */
404 Status
= AslCheckForErrorExit ();
405 if (ACPI_FAILURE (Status
))
410 /* Cleanup (for next source file) and exit */
413 PrTerminatePreprocessor ();
419 case ASL_INPUT_TYPE_ASCII_ASL
:
421 /* ACPICA subsystem initialization */
423 Status
= AdInitialize ();
424 if (ACPI_FAILURE (Status
))
429 (void) CmDoCompile ();
430 (void) AcpiTerminate ();
432 /* Check if any errors occurred during compile */
434 Status
= AslCheckForErrorExit ();
435 if (ACPI_FAILURE (Status
))
440 /* Cleanup (for next source file) and exit */
443 PrTerminatePreprocessor ();
447 * Binary ACPI table was auto-detected, disassemble it
449 case ASL_INPUT_TYPE_ACPI_TABLE
:
451 /* We have what appears to be an ACPI table, disassemble it */
453 FlCloseFile (ASL_FILE_INPUT
);
454 Gbl_DoCompile
= FALSE
;
455 Gbl_DisasmFlag
= TRUE
;
456 Status
= AslDoDisassembly ();
459 /* Unknown binary table */
461 case ASL_INPUT_TYPE_BINARY
:
463 AePrintErrorLog (ASL_FILE_STDERR
);
468 printf ("Unknown file type %X\n", Gbl_FileType
);
474 /*******************************************************************************
476 * FUNCTION: AslCheckForErrorExit
478 * PARAMETERS: None. Examines global exception count array
482 * DESCRIPTION: Determine if compiler should abort with error status
484 ******************************************************************************/
487 AslCheckForErrorExit (
492 * Return non-zero exit code if there have been errors, unless the
493 * global ignore error flag has been set
495 if (!Gbl_IgnoreErrors
)
497 if (Gbl_ExceptionCount
[ASL_ERROR
] > 0)
502 /* Optionally treat warnings as errors */
504 if (Gbl_WarningsAsErrors
)
506 if ((Gbl_ExceptionCount
[ASL_WARNING
] > 0) ||
507 (Gbl_ExceptionCount
[ASL_WARNING2
] > 0) ||
508 (Gbl_ExceptionCount
[ASL_WARNING3
] > 0))