2 /******************************************************************************
4 * Module Name: aslstartup - Compiler startup routines, called from main
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
118 #include "aslcompiler.h"
119 #include "actables.h"
122 #define _COMPONENT ACPI_COMPILER
123 ACPI_MODULE_NAME ("aslstartup")
126 #define ASL_MAX_FILES 256
127 char *FileList[ASL_MAX_FILES];
129 BOOLEAN AslToFile = TRUE;
132 /* Local prototypes */
135 AslInitializeGlobals (
140 char *DirectoryPathname,
141 char *FileSpecifier);
144 AslDetectSourceFileType (
145 ASL_FILE_INFO *Info);
148 /*******************************************************************************
150 * FUNCTION: AslInitializeGlobals
156 * DESCRIPTION: Re-initialize globals needed to restart the compiler. This
157 * allows multiple files to be disassembled and/or compiled.
159 ******************************************************************************/
162 AslInitializeGlobals (
168 /* Init compiler globals */
170 Gbl_CurrentColumn = 0;
171 Gbl_CurrentLineNumber = 1;
172 Gbl_LogicalLineNumber = 1;
173 Gbl_CurrentLineOffset = 0;
174 Gbl_InputFieldCount = 0;
175 Gbl_LineBufPtr = Gbl_CurrentLineBuffer;
178 Gbl_NextError = NULL;
179 Gbl_Signature = NULL;
182 AslGbl_NextEvent = 0;
183 for (i = 0; i < ASL_NUM_REPORT_LEVELS; i++)
185 Gbl_ExceptionCount[i] = 0;
188 Gbl_Files[ASL_FILE_AML_OUTPUT].Filename = NULL;
189 Gbl_Files[ASL_FILE_AML_OUTPUT].Handle = NULL;
193 /******************************************************************************
195 * FUNCTION: AsDoWildcard
201 * DESCRIPTION: Process files via wildcards. This function is for the Windows
204 ******************************************************************************/
208 char *DirectoryPathname,
218 /* Open parent directory */
220 DirInfo = AcpiOsOpenDirectory (DirectoryPathname, FileSpecifier, REQUEST_FILE_ONLY);
223 /* Either the directory of file does not exist */
225 Gbl_Files[ASL_FILE_INPUT].Filename = FileSpecifier;
226 FlFileError (ASL_FILE_INPUT, ASL_MSG_OPEN);
230 /* Process each file that matches the wildcard specification */
232 while ((Filename = AcpiOsGetNextFilename (DirInfo)))
234 /* Add the filename to the file list */
236 FileList[FileCount] = AcpiOsAllocate (strlen (Filename) + 1);
237 strcpy (FileList[FileCount], Filename);
240 if (FileCount >= ASL_MAX_FILES)
242 printf ("Max files reached\n");
250 AcpiOsCloseDirectory (DirInfo);
251 FileList[FileCount] = NULL;
256 * Linux/Unix cases - Wildcards are expanded by the shell automatically.
257 * Just return the filename in a null terminated list
259 FileList[0] = AcpiOsAllocate (strlen (FileSpecifier) + 1);
260 strcpy (FileList[0], FileSpecifier);
268 /*******************************************************************************
270 * FUNCTION: AslDetectSourceFileType
272 * PARAMETERS: Info - Name/Handle for the file (must be open)
276 * DESCRIPTION: Determine the type of the input file. Either binary (contains
277 * non-ASCII characters), ASL file, or an ACPI Data Table file.
279 ******************************************************************************/
282 AslDetectSourceFileType (
290 /* Check for 100% ASCII source file (comments are ignored) */
292 Status = FlCheckForAscii (Info);
293 if (ACPI_FAILURE (Status))
295 printf ("Non-ascii input file - %s\n", Info->Filename);
296 Type = ASL_INPUT_TYPE_BINARY;
301 * File is ASCII. Determine if this is an ASL file or an ACPI data
304 while (fgets (Gbl_CurrentLineBuffer, ASL_LINE_BUFFER_SIZE, Info->Handle))
306 /* Uppercase the buffer for caseless compare */
308 FileChar = Gbl_CurrentLineBuffer;
311 *FileChar = (char) toupper ((int) *FileChar);
315 /* Presence of "DefinitionBlock" indicates actual ASL code */
317 if (strstr (Gbl_CurrentLineBuffer, "DEFINITIONBLOCK"))
319 /* Appears to be an ASL file */
321 Type = ASL_INPUT_TYPE_ASCII_ASL;
326 /* Not an ASL source file, default to a data table source file */
328 Type = ASL_INPUT_TYPE_ASCII_DATA;
332 /* Must seek back to the start of the file */
334 fseek (Info->Handle, 0, SEEK_SET);
339 /*******************************************************************************
341 * FUNCTION: AslDoOneFile
343 * PARAMETERS: Filename - Name of the file
347 * DESCRIPTION: Process a single file - either disassemble, compile, or both
349 ******************************************************************************/
358 Gbl_Files[ASL_FILE_INPUT].Filename = Filename;
360 /* Re-initialize "some" compiler globals */
362 AslInitializeGlobals ();
365 * AML Disassembly (Optional)
367 if (Gbl_DisasmFlag || Gbl_GetAllTables)
369 /* ACPICA subsystem initialization */
371 Status = AdInitialize ();
372 if (ACPI_FAILURE (Status))
377 Status = AcpiAllocateRootTable (4);
378 if (ACPI_FAILURE (Status))
380 AcpiOsPrintf ("Could not initialize ACPI Table Manager, %s\n",
381 AcpiFormatException (Status));
385 /* This is where the disassembly happens */
387 AcpiGbl_DbOpt_disasm = TRUE;
388 Status = AdAmlDisassemble (AslToFile,
389 Gbl_Files[ASL_FILE_INPUT].Filename,
390 Gbl_OutputFilenamePrefix,
391 &Gbl_Files[ASL_FILE_INPUT].Filename,
393 if (ACPI_FAILURE (Status))
398 /* Shutdown compiler and ACPICA subsystem */
404 * Gbl_Files[ASL_FILE_INPUT].Filename was replaced with the
405 * .DSL disassembly file, which can now be compiled if requested
409 AcpiOsPrintf ("\nCompiling \"%s\"\n",
410 Gbl_Files[ASL_FILE_INPUT].Filename);
414 Gbl_Files[ASL_FILE_INPUT].Filename = NULL;
420 * Open the input file. Here, this should be an ASCII source file,
421 * either an ASL file or a Data Table file
423 Status = FlOpenInputFile (Gbl_Files[ASL_FILE_INPUT].Filename);
424 if (ACPI_FAILURE (Status))
426 AePrintErrorLog (ASL_FILE_STDERR);
430 /* Determine input file type */
432 Gbl_FileType = AslDetectSourceFileType (&Gbl_Files[ASL_FILE_INPUT]);
433 if (Gbl_FileType == ASL_INPUT_TYPE_BINARY)
439 * If -p not specified, we will use the input filename as the
440 * output filename prefix
442 if (Gbl_UseDefaultAmlFilename)
444 Gbl_OutputFilenamePrefix = Gbl_Files[ASL_FILE_INPUT].Filename;
447 /* Open the optional output files (listings, etc.) */
449 Status = FlOpenMiscOutputFiles (Gbl_OutputFilenamePrefix);
450 if (ACPI_FAILURE (Status))
452 AePrintErrorLog (ASL_FILE_STDERR);
457 * Compilation of ASL source versus DataTable source uses different
458 * compiler subsystems
460 switch (Gbl_FileType)
463 * Data Table Compilation
465 case ASL_INPUT_TYPE_ASCII_DATA:
468 * Require use of command-line option to enable the data table
469 * compiler -- for now, until development of the compiler is
472 if (!Gbl_DataTableCompilerAvailable)
474 printf ("Data Table Compiler is not available yet\n");
478 Status = DtDoCompile ();
482 ACPI_FREE (Gbl_Signature);
483 Gbl_Signature = NULL;
489 * ASL Compilation (Optional)
491 case ASL_INPUT_TYPE_ASCII_ASL:
494 /* ACPICA subsystem initialization */
496 Status = AdInitialize ();
497 if (ACPI_FAILURE (Status))
502 Status = CmDoCompile ();
506 * Return non-zero exit code if there have been errors, unless the
507 * global ignore error flag has been set
509 if ((Gbl_ExceptionCount[ASL_ERROR] > 0) && (!Gbl_IgnoreErrors))
517 case ASL_INPUT_TYPE_BINARY:
519 AePrintErrorLog (ASL_FILE_STDERR);
523 printf ("Unknown file type %X\n", Gbl_FileType);
529 /*******************************************************************************
531 * FUNCTION: AslDoOnePathname
533 * PARAMETERS: Pathname - Full pathname, possibly with wildcards
537 * DESCRIPTION: Process one pathname, possible terminated with a wildcard
538 * specification. If a wildcard, it is expanded and the multiple
539 * files are processed.
541 ******************************************************************************/
547 ACPI_STATUS Status = AE_OK;
553 /* Split incoming path into a directory/filename combo */
555 Status = FlSplitInputPathname (Pathname, &Gbl_DirectoryPath, &Filename);
556 if (ACPI_FAILURE (Status))
561 /* Expand possible wildcard into a file list (Windows/DOS only) */
563 FileList = AsDoWildcard (Gbl_DirectoryPath, Filename);
566 FullPathname = ACPI_ALLOCATE (
567 strlen (Gbl_DirectoryPath) + strlen (*FileList) + 1);
569 /* Construct a full path to the file */
571 strcpy (FullPathname, Gbl_DirectoryPath);
572 strcat (FullPathname, *FileList);
575 * If -p not specified, we will use the input filename as the
576 * output filename prefix
578 if (Gbl_UseDefaultAmlFilename)
580 Gbl_OutputFilenamePrefix = FullPathname;
583 /* Save status from all compiles */
585 Status |= AslDoOneFile (FullPathname);
587 ACPI_FREE (FullPathname);
588 ACPI_FREE (*FileList);
593 ACPI_FREE (Gbl_DirectoryPath);
594 ACPI_FREE (Filename);