2 /******************************************************************************
4 * Module Name: aslstartup - Compiler startup routines, called from main
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2011, 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_LineBufPtr = Gbl_CurrentLineBuffer;
101 Gbl_NextError = NULL;
102 Gbl_Signature = NULL;
105 AslGbl_NextEvent = 0;
106 for (i = 0; i < ASL_NUM_REPORT_LEVELS; i++)
108 Gbl_ExceptionCount[i] = 0;
111 Gbl_Files[ASL_FILE_AML_OUTPUT].Filename = NULL;
112 Gbl_Files[ASL_FILE_AML_OUTPUT].Handle = NULL;
114 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename = NULL;
115 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle = NULL;
119 /******************************************************************************
121 * FUNCTION: AsDoWildcard
127 * DESCRIPTION: Process files via wildcards. This function is for the Windows
130 ******************************************************************************/
134 char *DirectoryPathname,
145 /* Open parent directory */
147 DirInfo = AcpiOsOpenDirectory (DirectoryPathname, FileSpecifier, REQUEST_FILE_ONLY);
150 /* Either the directory of file does not exist */
152 Gbl_Files[ASL_FILE_INPUT].Filename = FileSpecifier;
153 FlFileError (ASL_FILE_INPUT, ASL_MSG_OPEN);
157 /* Process each file that matches the wildcard specification */
159 while ((Filename = AcpiOsGetNextFilename (DirInfo)))
161 /* Add the filename to the file list */
163 FileList[FileCount] = AcpiOsAllocate (strlen (Filename) + 1);
164 strcpy (FileList[FileCount], Filename);
167 if (FileCount >= ASL_MAX_FILES)
169 printf ("Max files reached\n");
177 AcpiOsCloseDirectory (DirInfo);
178 FileList[FileCount] = NULL;
183 * Linux/Unix cases - Wildcards are expanded by the shell automatically.
184 * Just return the filename in a null terminated list
186 FileList[0] = AcpiOsAllocate (strlen (FileSpecifier) + 1);
187 strcpy (FileList[0], FileSpecifier);
195 /*******************************************************************************
197 * FUNCTION: AslDetectSourceFileType
199 * PARAMETERS: Info - Name/Handle for the file (must be open)
203 * DESCRIPTION: Determine the type of the input file. Either binary (contains
204 * non-ASCII characters), ASL file, or an ACPI Data Table file.
206 ******************************************************************************/
209 AslDetectSourceFileType (
217 /* Check for 100% ASCII source file (comments are ignored) */
219 Status = FlCheckForAscii (Info);
220 if (ACPI_FAILURE (Status))
222 printf ("Non-ascii input file - %s\n", Info->Filename);
223 Type = ASL_INPUT_TYPE_BINARY;
228 * File is ASCII. Determine if this is an ASL file or an ACPI data
231 while (fgets (Gbl_CurrentLineBuffer, ASL_LINE_BUFFER_SIZE, Info->Handle))
233 /* Uppercase the buffer for caseless compare */
235 FileChar = Gbl_CurrentLineBuffer;
238 *FileChar = (char) toupper ((int) *FileChar);
242 /* Presence of "DefinitionBlock" indicates actual ASL code */
244 if (strstr (Gbl_CurrentLineBuffer, "DEFINITIONBLOCK"))
246 /* Appears to be an ASL file */
248 Type = ASL_INPUT_TYPE_ASCII_ASL;
253 /* Not an ASL source file, default to a data table source file */
255 Type = ASL_INPUT_TYPE_ASCII_DATA;
259 /* Must seek back to the start of the file */
261 fseek (Info->Handle, 0, SEEK_SET);
266 /*******************************************************************************
268 * FUNCTION: AslDoOneFile
270 * PARAMETERS: Filename - Name of the file
274 * DESCRIPTION: Process a single file - either disassemble, compile, or both
276 ******************************************************************************/
285 Gbl_Files[ASL_FILE_INPUT].Filename = Filename;
287 /* Re-initialize "some" compiler globals */
289 AslInitializeGlobals ();
292 * AML Disassembly (Optional)
294 if (Gbl_DisasmFlag || Gbl_GetAllTables)
296 /* ACPICA subsystem initialization */
298 Status = AdInitialize ();
299 if (ACPI_FAILURE (Status))
304 Status = AcpiAllocateRootTable (4);
305 if (ACPI_FAILURE (Status))
307 AcpiOsPrintf ("Could not initialize ACPI Table Manager, %s\n",
308 AcpiFormatException (Status));
312 /* This is where the disassembly happens */
314 AcpiGbl_DbOpt_disasm = TRUE;
315 Status = AdAmlDisassemble (AslToFile,
316 Gbl_Files[ASL_FILE_INPUT].Filename,
317 Gbl_OutputFilenamePrefix,
318 &Gbl_Files[ASL_FILE_INPUT].Filename,
320 if (ACPI_FAILURE (Status))
325 /* Shutdown compiler and ACPICA subsystem */
328 (void) AcpiTerminate ();
331 * Gbl_Files[ASL_FILE_INPUT].Filename was replaced with the
332 * .DSL disassembly file, which can now be compiled if requested
336 AcpiOsPrintf ("\nCompiling \"%s\"\n",
337 Gbl_Files[ASL_FILE_INPUT].Filename);
341 Gbl_Files[ASL_FILE_INPUT].Filename = NULL;
347 * Open the input file. Here, this should be an ASCII source file,
348 * either an ASL file or a Data Table file
350 Status = FlOpenInputFile (Gbl_Files[ASL_FILE_INPUT].Filename);
351 if (ACPI_FAILURE (Status))
353 AePrintErrorLog (ASL_FILE_STDERR);
357 /* Determine input file type */
359 Gbl_FileType = AslDetectSourceFileType (&Gbl_Files[ASL_FILE_INPUT]);
360 if (Gbl_FileType == ASL_INPUT_TYPE_BINARY)
366 * If -p not specified, we will use the input filename as the
367 * output filename prefix
369 if (Gbl_UseDefaultAmlFilename)
371 Gbl_OutputFilenamePrefix = Gbl_Files[ASL_FILE_INPUT].Filename;
374 /* Open the optional output files (listings, etc.) */
376 Status = FlOpenMiscOutputFiles (Gbl_OutputFilenamePrefix);
377 if (ACPI_FAILURE (Status))
379 AePrintErrorLog (ASL_FILE_STDERR);
384 * Compilation of ASL source versus DataTable source uses different
385 * compiler subsystems
387 switch (Gbl_FileType)
390 * Data Table Compilation
392 case ASL_INPUT_TYPE_ASCII_DATA:
394 Status = DtDoCompile ();
398 ACPI_FREE (Gbl_Signature);
399 Gbl_Signature = NULL;
405 * ASL Compilation (Optional)
407 case ASL_INPUT_TYPE_ASCII_ASL:
409 /* ACPICA subsystem initialization */
411 Status = AdInitialize ();
412 if (ACPI_FAILURE (Status))
417 Status = CmDoCompile ();
418 (void) AcpiTerminate ();
421 * Return non-zero exit code if there have been errors, unless the
422 * global ignore error flag has been set
424 if ((Gbl_ExceptionCount[ASL_ERROR] > 0) && (!Gbl_IgnoreErrors))
432 case ASL_INPUT_TYPE_BINARY:
434 AePrintErrorLog (ASL_FILE_STDERR);
438 printf ("Unknown file type %X\n", Gbl_FileType);
444 /*******************************************************************************
446 * FUNCTION: AslDoOnePathname
448 * PARAMETERS: Pathname - Full pathname, possibly with wildcards
452 * DESCRIPTION: Process one pathname, possible terminated with a wildcard
453 * specification. If a wildcard, it is expanded and the multiple
454 * files are processed.
456 ******************************************************************************/
461 ASL_PATHNAME_CALLBACK PathCallback)
463 ACPI_STATUS Status = AE_OK;
469 /* Split incoming path into a directory/filename combo */
471 Status = FlSplitInputPathname (Pathname, &Gbl_DirectoryPath, &Filename);
472 if (ACPI_FAILURE (Status))
477 /* Expand possible wildcard into a file list (Windows/DOS only) */
479 WildcardList = AsDoWildcard (Gbl_DirectoryPath, Filename);
480 while (*WildcardList)
482 FullPathname = ACPI_ALLOCATE (
483 strlen (Gbl_DirectoryPath) + strlen (*WildcardList) + 1);
485 /* Construct a full path to the file */
487 strcpy (FullPathname, Gbl_DirectoryPath);
488 strcat (FullPathname, *WildcardList);
491 * If -p not specified, we will use the input filename as the
492 * output filename prefix
494 if (Gbl_UseDefaultAmlFilename)
496 Gbl_OutputFilenamePrefix = FullPathname;
499 /* Save status from all compiles */
501 Status |= (*PathCallback) (FullPathname);
503 ACPI_FREE (FullPathname);
504 ACPI_FREE (*WildcardList);
505 *WildcardList = NULL;
509 ACPI_FREE (Gbl_DirectoryPath);
510 ACPI_FREE (Filename);