2 /******************************************************************************
4 * Module Name: aslstartup - Compiler startup routines, called from main
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2012, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
46 #include <contrib/dev/acpica/compiler/aslcompiler.h>
47 #include <contrib/dev/acpica/include/actables.h>
48 #include <contrib/dev/acpica/include/acapps.h>
50 #define _COMPONENT ACPI_COMPILER
51 ACPI_MODULE_NAME ("aslstartup")
54 #define ASL_MAX_FILES 256
55 static char *FileList[ASL_MAX_FILES];
56 static BOOLEAN AslToFile = TRUE;
59 /* Local prototypes */
63 char *DirectoryPathname,
67 AslDetectSourceFileType (
71 /*******************************************************************************
73 * FUNCTION: AslInitializeGlobals
79 * DESCRIPTION: Re-initialize globals needed to restart the compiler. This
80 * allows multiple files to be disassembled and/or compiled.
82 ******************************************************************************/
85 AslInitializeGlobals (
91 /* Init compiler globals */
93 Gbl_CurrentColumn = 0;
94 Gbl_CurrentLineNumber = 1;
95 Gbl_LogicalLineNumber = 1;
96 Gbl_CurrentLineOffset = 0;
97 Gbl_InputFieldCount = 0;
98 Gbl_InputByteCount = 0;
99 Gbl_NsLookupCount = 0;
100 Gbl_LineBufPtr = Gbl_CurrentLineBuffer;
103 Gbl_NextError = NULL;
104 Gbl_Signature = NULL;
107 TotalExecutableOpcodes = 0;
108 TotalNamedObjects = 0;
112 TotalAllocations = 0;
116 AslGbl_NextEvent = 0;
117 for (i = 0; i < ASL_NUM_REPORT_LEVELS; i++)
119 Gbl_ExceptionCount[i] = 0;
122 for (i = ASL_FILE_INPUT; i <= ASL_MAX_FILE_TYPE; i++)
124 Gbl_Files[i].Handle = NULL;
125 Gbl_Files[i].Filename = NULL;
130 /******************************************************************************
132 * FUNCTION: AsDoWildcard
138 * DESCRIPTION: Process files via wildcards. This function is for the Windows
141 ******************************************************************************/
145 char *DirectoryPathname,
156 /* Open parent directory */
158 DirInfo = AcpiOsOpenDirectory (DirectoryPathname, FileSpecifier, REQUEST_FILE_ONLY);
161 /* Either the directory of file does not exist */
163 Gbl_Files[ASL_FILE_INPUT].Filename = FileSpecifier;
164 FlFileError (ASL_FILE_INPUT, ASL_MSG_OPEN);
168 /* Process each file that matches the wildcard specification */
170 while ((Filename = AcpiOsGetNextFilename (DirInfo)))
172 /* Add the filename to the file list */
174 FileList[FileCount] = AcpiOsAllocate (strlen (Filename) + 1);
175 strcpy (FileList[FileCount], Filename);
178 if (FileCount >= ASL_MAX_FILES)
180 printf ("Max files reached\n");
188 AcpiOsCloseDirectory (DirInfo);
189 FileList[FileCount] = NULL;
194 * Linux/Unix cases - Wildcards are expanded by the shell automatically.
195 * Just return the filename in a null terminated list
197 FileList[0] = AcpiOsAllocate (strlen (FileSpecifier) + 1);
198 strcpy (FileList[0], FileSpecifier);
206 /*******************************************************************************
208 * FUNCTION: AslDetectSourceFileType
210 * PARAMETERS: Info - Name/Handle for the file (must be open)
214 * DESCRIPTION: Determine the type of the input file. Either binary (contains
215 * non-ASCII characters), ASL file, or an ACPI Data Table file.
217 ******************************************************************************/
220 AslDetectSourceFileType (
228 /* Check for 100% ASCII source file (comments are ignored) */
230 Status = FlCheckForAscii (Info);
231 if (ACPI_FAILURE (Status))
233 printf ("Non-ascii input file - %s\n", Info->Filename);
234 Type = ASL_INPUT_TYPE_BINARY;
239 * File is ASCII. Determine if this is an ASL file or an ACPI data
242 while (fgets (Gbl_CurrentLineBuffer, ASL_LINE_BUFFER_SIZE, Info->Handle))
244 /* Uppercase the buffer for caseless compare */
246 FileChar = Gbl_CurrentLineBuffer;
249 *FileChar = (char) toupper ((int) *FileChar);
253 /* Presence of "DefinitionBlock" indicates actual ASL code */
255 if (strstr (Gbl_CurrentLineBuffer, "DEFINITIONBLOCK"))
257 /* Appears to be an ASL file */
259 Type = ASL_INPUT_TYPE_ASCII_ASL;
264 /* Not an ASL source file, default to a data table source file */
266 Type = ASL_INPUT_TYPE_ASCII_DATA;
270 /* Must seek back to the start of the file */
272 fseek (Info->Handle, 0, SEEK_SET);
277 /*******************************************************************************
279 * FUNCTION: AslDoOneFile
281 * PARAMETERS: Filename - Name of the file
285 * DESCRIPTION: Process a single file - either disassemble, compile, or both
287 ******************************************************************************/
296 /* Re-initialize "some" compiler/preprocessor globals */
298 AslInitializeGlobals ();
299 PrInitializeGlobals ();
301 Gbl_Files[ASL_FILE_INPUT].Filename = Filename;
304 * AML Disassembly (Optional)
306 if (Gbl_DisasmFlag || Gbl_GetAllTables)
308 /* ACPICA subsystem initialization */
310 Status = AdInitialize ();
311 if (ACPI_FAILURE (Status))
316 Status = AcpiAllocateRootTable (4);
317 if (ACPI_FAILURE (Status))
319 AcpiOsPrintf ("Could not initialize ACPI Table Manager, %s\n",
320 AcpiFormatException (Status));
324 /* This is where the disassembly happens */
326 AcpiGbl_DbOpt_disasm = TRUE;
327 Status = AdAmlDisassemble (AslToFile,
328 Gbl_Files[ASL_FILE_INPUT].Filename,
329 Gbl_OutputFilenamePrefix,
330 &Gbl_Files[ASL_FILE_INPUT].Filename,
332 if (ACPI_FAILURE (Status))
337 /* Shutdown compiler and ACPICA subsystem */
340 (void) AcpiTerminate ();
343 * Gbl_Files[ASL_FILE_INPUT].Filename was replaced with the
344 * .DSL disassembly file, which can now be compiled if requested
348 AcpiOsPrintf ("\nCompiling \"%s\"\n",
349 Gbl_Files[ASL_FILE_INPUT].Filename);
353 Gbl_Files[ASL_FILE_INPUT].Filename = NULL;
359 * Open the input file. Here, this should be an ASCII source file,
360 * either an ASL file or a Data Table file
362 Status = FlOpenInputFile (Gbl_Files[ASL_FILE_INPUT].Filename);
363 if (ACPI_FAILURE (Status))
365 AePrintErrorLog (ASL_FILE_STDERR);
369 /* Determine input file type */
371 Gbl_FileType = AslDetectSourceFileType (&Gbl_Files[ASL_FILE_INPUT]);
372 if (Gbl_FileType == ASL_INPUT_TYPE_BINARY)
378 * If -p not specified, we will use the input filename as the
379 * output filename prefix
381 if (Gbl_UseDefaultAmlFilename)
383 Gbl_OutputFilenamePrefix = Gbl_Files[ASL_FILE_INPUT].Filename;
386 /* Open the optional output files (listings, etc.) */
388 Status = FlOpenMiscOutputFiles (Gbl_OutputFilenamePrefix);
389 if (ACPI_FAILURE (Status))
391 AePrintErrorLog (ASL_FILE_STDERR);
396 * Compilation of ASL source versus DataTable source uses different
397 * compiler subsystems
399 switch (Gbl_FileType)
402 * Data Table Compilation
404 case ASL_INPUT_TYPE_ASCII_DATA:
406 Status = DtDoCompile ();
407 if (ACPI_FAILURE (Status))
414 ACPI_FREE (Gbl_Signature);
415 Gbl_Signature = NULL;
418 /* Check if any errors occurred during compile */
420 Status = AslCheckForErrorExit ();
421 if (ACPI_FAILURE (Status))
426 /* Cleanup (for next source file) and exit */
429 PrTerminatePreprocessor ();
435 case ASL_INPUT_TYPE_ASCII_ASL:
437 /* ACPICA subsystem initialization */
439 Status = AdInitialize ();
440 if (ACPI_FAILURE (Status))
445 (void) CmDoCompile ();
446 (void) AcpiTerminate ();
448 /* Check if any errors occurred during compile */
450 Status = AslCheckForErrorExit ();
451 if (ACPI_FAILURE (Status))
456 /* Cleanup (for next source file) and exit */
459 PrTerminatePreprocessor ();
462 case ASL_INPUT_TYPE_BINARY:
464 AePrintErrorLog (ASL_FILE_STDERR);
468 printf ("Unknown file type %X\n", Gbl_FileType);
474 /*******************************************************************************
476 * FUNCTION: AslDoOnePathname
478 * PARAMETERS: Pathname - Full pathname, possibly with wildcards
482 * DESCRIPTION: Process one pathname, possible terminated with a wildcard
483 * specification. If a wildcard, it is expanded and the multiple
484 * files are processed.
486 ******************************************************************************/
491 ASL_PATHNAME_CALLBACK PathCallback)
493 ACPI_STATUS Status = AE_OK;
499 /* Split incoming path into a directory/filename combo */
501 Status = FlSplitInputPathname (Pathname, &Gbl_DirectoryPath, &Filename);
502 if (ACPI_FAILURE (Status))
507 /* Expand possible wildcard into a file list (Windows/DOS only) */
509 WildcardList = AsDoWildcard (Gbl_DirectoryPath, Filename);
510 while (*WildcardList)
512 FullPathname = ACPI_ALLOCATE (
513 strlen (Gbl_DirectoryPath) + strlen (*WildcardList) + 1);
515 /* Construct a full path to the file */
517 strcpy (FullPathname, Gbl_DirectoryPath);
518 strcat (FullPathname, *WildcardList);
521 * If -p not specified, we will use the input filename as the
522 * output filename prefix
524 if (Gbl_UseDefaultAmlFilename)
526 Gbl_OutputFilenamePrefix = FullPathname;
529 /* Save status from all compiles */
531 Status |= (*PathCallback) (FullPathname);
533 ACPI_FREE (FullPathname);
534 ACPI_FREE (*WildcardList);
535 *WildcardList = NULL;
539 ACPI_FREE (Gbl_DirectoryPath);
540 ACPI_FREE (Filename);
545 /*******************************************************************************
547 * FUNCTION: AslCheckForErrorExit
549 * PARAMETERS: None. Examines global exception count array
553 * DESCRIPTION: Determine if compiler should abort with error status
555 ******************************************************************************/
558 AslCheckForErrorExit (
563 * Return non-zero exit code if there have been errors, unless the
564 * global ignore error flag has been set
566 if (!Gbl_IgnoreErrors)
568 if (Gbl_ExceptionCount[ASL_ERROR] > 0)
573 /* Optionally treat warnings as errors */
575 if (Gbl_WarningsAsErrors)
577 if ((Gbl_ExceptionCount[ASL_WARNING] > 0) ||
578 (Gbl_ExceptionCount[ASL_WARNING2] > 0) ||
579 (Gbl_ExceptionCount[ASL_WARNING3] > 0))