1 /******************************************************************************
3 * Module Name: aslstartup - Compiler startup routines, called from main
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2012, 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 <contrib/dev/acpica/compiler/aslcompiler.h>
46 #include <contrib/dev/acpica/include/actables.h>
47 #include <contrib/dev/acpica/include/acapps.h>
49 #define _COMPONENT ACPI_COMPILER
50 ACPI_MODULE_NAME ("aslstartup")
53 #define ASL_MAX_FILES 256
54 static char *FileList[ASL_MAX_FILES];
55 static BOOLEAN AslToFile = TRUE;
58 /* Local prototypes */
62 char *DirectoryPathname,
66 AslDetectSourceFileType (
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: AsDoWildcard
137 * DESCRIPTION: Process files via wildcards. This function is for the Windows
140 ******************************************************************************/
144 char *DirectoryPathname,
155 /* Open parent directory */
157 DirInfo = AcpiOsOpenDirectory (DirectoryPathname, FileSpecifier, REQUEST_FILE_ONLY);
160 /* Either the directory of file does not exist */
162 Gbl_Files[ASL_FILE_INPUT].Filename = FileSpecifier;
163 FlFileError (ASL_FILE_INPUT, ASL_MSG_OPEN);
167 /* Process each file that matches the wildcard specification */
169 while ((Filename = AcpiOsGetNextFilename (DirInfo)))
171 /* Add the filename to the file list */
173 FileList[FileCount] = AcpiOsAllocate (strlen (Filename) + 1);
174 strcpy (FileList[FileCount], Filename);
177 if (FileCount >= ASL_MAX_FILES)
179 printf ("Max files reached\n");
187 AcpiOsCloseDirectory (DirInfo);
188 FileList[FileCount] = NULL;
193 * Linux/Unix cases - Wildcards are expanded by the shell automatically.
194 * Just return the filename in a null terminated list
196 FileList[0] = AcpiOsAllocate (strlen (FileSpecifier) + 1);
197 strcpy (FileList[0], FileSpecifier);
205 /*******************************************************************************
207 * FUNCTION: AslDetectSourceFileType
209 * PARAMETERS: Info - Name/Handle for the file (must be open)
213 * DESCRIPTION: Determine the type of the input file. Either binary (contains
214 * non-ASCII characters), ASL file, or an ACPI Data Table file.
216 ******************************************************************************/
219 AslDetectSourceFileType (
227 /* Check for 100% ASCII source file (comments are ignored) */
229 Status = FlCheckForAscii (Info->Handle, Info->Filename, TRUE);
230 if (ACPI_FAILURE (Status))
232 printf ("Non-ascii input file - %s\n", Info->Filename);
234 if (!Gbl_IgnoreErrors)
236 Type = ASL_INPUT_TYPE_BINARY;
242 * File is ASCII. Determine if this is an ASL file or an ACPI data
245 while (fgets (Gbl_CurrentLineBuffer, Gbl_LineBufferSize, Info->Handle))
247 /* Uppercase the buffer for caseless compare */
249 FileChar = Gbl_CurrentLineBuffer;
252 *FileChar = (char) toupper ((int) *FileChar);
256 /* Presence of "DefinitionBlock" indicates actual ASL code */
258 if (strstr (Gbl_CurrentLineBuffer, "DEFINITIONBLOCK"))
260 /* Appears to be an ASL file */
262 Type = ASL_INPUT_TYPE_ASCII_ASL;
267 /* Not an ASL source file, default to a data table source file */
269 Type = ASL_INPUT_TYPE_ASCII_DATA;
273 /* Must seek back to the start of the file */
275 fseek (Info->Handle, 0, SEEK_SET);
280 /*******************************************************************************
282 * FUNCTION: AslDoOneFile
284 * PARAMETERS: Filename - Name of the file
288 * DESCRIPTION: Process a single file - either disassemble, compile, or both
290 ******************************************************************************/
299 /* Re-initialize "some" compiler/preprocessor globals */
301 AslInitializeGlobals ();
302 PrInitializeGlobals ();
304 Gbl_Files[ASL_FILE_INPUT].Filename = Filename;
307 * AML Disassembly (Optional)
309 if (Gbl_DisasmFlag || Gbl_GetAllTables)
311 /* ACPICA subsystem initialization */
313 Status = AdInitialize ();
314 if (ACPI_FAILURE (Status))
319 Status = AcpiAllocateRootTable (4);
320 if (ACPI_FAILURE (Status))
322 AcpiOsPrintf ("Could not initialize ACPI Table Manager, %s\n",
323 AcpiFormatException (Status));
327 /* This is where the disassembly happens */
329 AcpiGbl_DbOpt_disasm = TRUE;
330 Status = AdAmlDisassemble (AslToFile,
331 Gbl_Files[ASL_FILE_INPUT].Filename,
332 Gbl_OutputFilenamePrefix,
333 &Gbl_Files[ASL_FILE_INPUT].Filename,
335 if (ACPI_FAILURE (Status))
341 /* TBD: Handle additional output files for disassembler */
343 Status = FlOpenMiscOutputFiles (Gbl_OutputFilenamePrefix);
344 LsDisplayNamespace ();
347 /* Shutdown compiler and ACPICA subsystem */
350 (void) AcpiTerminate ();
353 * Gbl_Files[ASL_FILE_INPUT].Filename was replaced with the
354 * .DSL disassembly file, which can now be compiled if requested
358 AcpiOsPrintf ("\nCompiling \"%s\"\n",
359 Gbl_Files[ASL_FILE_INPUT].Filename);
363 Gbl_Files[ASL_FILE_INPUT].Filename = NULL;
369 * Open the input file. Here, this should be an ASCII source file,
370 * either an ASL file or a Data Table file
372 Status = FlOpenInputFile (Gbl_Files[ASL_FILE_INPUT].Filename);
373 if (ACPI_FAILURE (Status))
375 AePrintErrorLog (ASL_FILE_STDERR);
379 /* Determine input file type */
381 Gbl_FileType = AslDetectSourceFileType (&Gbl_Files[ASL_FILE_INPUT]);
382 if (Gbl_FileType == ASL_INPUT_TYPE_BINARY)
388 * If -p not specified, we will use the input filename as the
389 * output filename prefix
391 if (Gbl_UseDefaultAmlFilename)
393 Gbl_OutputFilenamePrefix = Gbl_Files[ASL_FILE_INPUT].Filename;
396 /* Open the optional output files (listings, etc.) */
398 Status = FlOpenMiscOutputFiles (Gbl_OutputFilenamePrefix);
399 if (ACPI_FAILURE (Status))
401 AePrintErrorLog (ASL_FILE_STDERR);
406 * Compilation of ASL source versus DataTable source uses different
407 * compiler subsystems
409 switch (Gbl_FileType)
412 * Data Table Compilation
414 case ASL_INPUT_TYPE_ASCII_DATA:
416 Status = DtDoCompile ();
417 if (ACPI_FAILURE (Status))
424 ACPI_FREE (Gbl_Signature);
425 Gbl_Signature = NULL;
428 /* Check if any errors occurred during compile */
430 Status = AslCheckForErrorExit ();
431 if (ACPI_FAILURE (Status))
436 /* Cleanup (for next source file) and exit */
439 PrTerminatePreprocessor ();
445 case ASL_INPUT_TYPE_ASCII_ASL:
447 /* ACPICA subsystem initialization */
449 Status = AdInitialize ();
450 if (ACPI_FAILURE (Status))
455 (void) CmDoCompile ();
456 (void) AcpiTerminate ();
458 /* Check if any errors occurred during compile */
460 Status = AslCheckForErrorExit ();
461 if (ACPI_FAILURE (Status))
466 /* Cleanup (for next source file) and exit */
469 PrTerminatePreprocessor ();
472 case ASL_INPUT_TYPE_BINARY:
474 AePrintErrorLog (ASL_FILE_STDERR);
478 printf ("Unknown file type %X\n", Gbl_FileType);
484 /*******************************************************************************
486 * FUNCTION: AslDoOnePathname
488 * PARAMETERS: Pathname - Full pathname, possibly with wildcards
492 * DESCRIPTION: Process one pathname, possible terminated with a wildcard
493 * specification. If a wildcard, it is expanded and the multiple
494 * files are processed.
496 ******************************************************************************/
501 ASL_PATHNAME_CALLBACK PathCallback)
503 ACPI_STATUS Status = AE_OK;
509 /* Split incoming path into a directory/filename combo */
511 Status = FlSplitInputPathname (Pathname, &Gbl_DirectoryPath, &Filename);
512 if (ACPI_FAILURE (Status))
517 /* Expand possible wildcard into a file list (Windows/DOS only) */
519 WildcardList = AsDoWildcard (Gbl_DirectoryPath, Filename);
520 while (*WildcardList)
522 FullPathname = ACPI_ALLOCATE (
523 strlen (Gbl_DirectoryPath) + strlen (*WildcardList) + 1);
525 /* Construct a full path to the file */
527 strcpy (FullPathname, Gbl_DirectoryPath);
528 strcat (FullPathname, *WildcardList);
531 * If -p not specified, we will use the input filename as the
532 * output filename prefix
534 if (Gbl_UseDefaultAmlFilename)
536 Gbl_OutputFilenamePrefix = FullPathname;
539 /* Save status from all compiles */
541 Status |= (*PathCallback) (FullPathname);
543 ACPI_FREE (FullPathname);
544 ACPI_FREE (*WildcardList);
545 *WildcardList = NULL;
549 ACPI_FREE (Gbl_DirectoryPath);
550 ACPI_FREE (Filename);
555 /*******************************************************************************
557 * FUNCTION: AslCheckForErrorExit
559 * PARAMETERS: None. Examines global exception count array
563 * DESCRIPTION: Determine if compiler should abort with error status
565 ******************************************************************************/
568 AslCheckForErrorExit (
573 * Return non-zero exit code if there have been errors, unless the
574 * global ignore error flag has been set
576 if (!Gbl_IgnoreErrors)
578 if (Gbl_ExceptionCount[ASL_ERROR] > 0)
583 /* Optionally treat warnings as errors */
585 if (Gbl_WarningsAsErrors)
587 if ((Gbl_ExceptionCount[ASL_WARNING] > 0) ||
588 (Gbl_ExceptionCount[ASL_WARNING2] > 0) ||
589 (Gbl_ExceptionCount[ASL_WARNING3] > 0))