2 /******************************************************************************
4 * Module Name: aslmain - compiler main and utilities
7 *****************************************************************************/
9 /******************************************************************************
13 * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
14 * All rights reserved.
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
39 * The above copyright and patent license is granted only if the following
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
74 * 3.4. Intel retains all right, title, and interest in and to the Original
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
82 * 4. Disclaimer and Export Compliance
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
116 *****************************************************************************/
119 #define _DECLARE_GLOBALS
121 #include "aslcompiler.h"
122 #include "acnamesp.h"
129 #define _COMPONENT ACPI_COMPILER
130 ACPI_MODULE_NAME ("aslmain")
132 BOOLEAN AslToFile = TRUE;
133 BOOLEAN DoCompile = TRUE;
134 BOOLEAN DoSignon = TRUE;
136 char hex[] = {'0','1','2','3','4','5','6','7',
137 '8','9','A','B','C','D','E','F'};
140 /*******************************************************************************
148 * DESCRIPTION: Display option help message
150 ******************************************************************************/
157 printf ("General Output:\n");
158 printf (" -p <prefix> Specify filename prefix for all output files (including .aml)\n");
159 printf (" -vi Less verbose errors and warnings for use with IDEs\n");
160 printf (" -vo Enable optimization comments\n");
161 printf (" -vr Disable remarks\n");
162 printf (" -vs Disable signon\n");
164 printf ("\nAML Output:\n");
165 printf (" -s<a|c> Create AML in assembler or C source file (*.asm or *.c)\n");
166 printf (" -i<a|c> Create assembler or C include file (*.inc or *.h)\n");
167 printf (" -t<a|c> Create AML in assembler or C hex table (*.hex)\n");
169 printf ("\nAML Optimization:\n");
170 printf (" -oa Disable all optimizations (compatibility mode)\n");
171 printf (" -of Disable constant folding\n");
172 printf (" -oi Disable integer optimization to Zero/One/Ones\n");
173 printf (" -on Disable named reference string optimization\n");
175 printf ("\nListings:\n");
176 printf (" -l Create mixed listing file (ASL source and AML) (*.lst)\n");
177 printf (" -ln Create namespace file (*.nsp)\n");
178 printf (" -ls Create combined source file (expanded includes) (*.src)\n");
180 printf ("\nAML Disassembler:\n");
181 printf (" -d [file] Disassemble AML to ASL source code file (*.dsl)\n");
182 printf (" -dc [file] Disassemble AML and immediately compile it\n");
183 printf (" (Obtain DSDT from current system if no input file)\n");
184 printf (" -e Generate External() statements for unresolved symbols\n");
185 printf (" -g Get ACPI tables and write to files (*.dat)\n");
187 printf ("\nHelp:\n");
188 printf (" -h Additional help and compiler debug options\n");
189 printf (" -hc Display operators allowed in constant expressions\n");
190 printf (" -hr Display ACPI reserved method names\n");
194 /*******************************************************************************
202 * DESCRIPTION: Display help message
204 ******************************************************************************/
211 printf ("AML output filename generation:\n");
212 printf (" Output filenames are generated by appending an extension to a common\n");
213 printf (" filename prefix. The filename prefix is obtained via one of the\n");
214 printf (" following methods (in priority order):\n");
215 printf (" 1) The -p option specifies the prefix\n");
216 printf (" 2) The prefix of the AMLFileName in the ASL Definition Block\n");
217 printf (" 3) The prefix of the input filename\n");
222 printf ("\nCompiler Debug Options:\n");
223 printf (" -b<p|t|b> Create compiler debug/trace file (*.txt)\n");
224 printf (" Types: Parse/Tree/Both\n");
225 printf (" -f Ignore errors, force creation of AML output file(s)\n");
226 printf (" -c Parse only, no output generation\n");
227 printf (" -ot Display compile times\n");
228 printf (" -x<level> Set debug level for trace output\n");
232 /*******************************************************************************
240 * DESCRIPTION: Display usage and option message
242 ******************************************************************************/
249 printf ("Usage: %s [Options] [InputFile]\n\n", CompilerName);
254 /*******************************************************************************
256 * FUNCTION: AslInitialize
262 * DESCRIPTION: Initialize compiler globals
264 ******************************************************************************/
273 _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0));
278 for (i = 0; i < ASL_NUM_FILES; i++)
280 Gbl_Files[i].Handle = NULL;
281 Gbl_Files[i].Filename = NULL;
284 Gbl_Files[ASL_FILE_STDOUT].Handle = stdout;
285 Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
287 Gbl_Files[ASL_FILE_STDERR].Handle = stderr;
288 Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
292 /*******************************************************************************
294 * FUNCTION: AslCommandLine
296 * PARAMETERS: argc/argv
300 * DESCRIPTION: Command line processing
302 ******************************************************************************/
309 BOOLEAN BadCommandLine = FALSE;
313 /* Minimum command line contains at least one option or an input file */
317 AslCompilerSignon (ASL_FILE_STDOUT);
322 /* Get the command line options */
324 while ((j = AcpiGetopt (argc, argv, "b:cd^efgh^i^l^o:p:rs:t:v:x:")) != EOF) switch (j)
328 switch (AcpiGbl_Optarg[0])
331 AslCompilerdebug = 1; /* same as yydebug */
335 AslCompilerdebug = 1; /* same as yydebug */
342 printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
343 BadCommandLine = TRUE;
347 /* Produce debug output file */
349 Gbl_DebugFlag = TRUE;
357 Gbl_ParseOnlyFlag = TRUE;
362 switch (AcpiGbl_Optarg[0])
372 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
373 BadCommandLine = TRUE;
377 Gbl_DisasmFlag = TRUE;
383 /* Generate external statements for unresolved symbols */
385 Gbl_GenerateExternals = TRUE;
391 /* Ignore errors and force creation of aml file */
393 Gbl_IgnoreErrors = TRUE;
399 /* Get all ACPI tables */
401 Gbl_GetAllTables = TRUE;
408 switch (AcpiGbl_Optarg[0])
415 UtDisplayConstantOpcodes ();
421 MpDisplayReservedNames ();
425 printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
426 BadCommandLine = TRUE;
434 switch (AcpiGbl_Optarg[0])
438 /* Produce assembly code include file */
440 Gbl_AsmIncludeOutputFlag = TRUE;
445 /* Produce C include file */
447 Gbl_C_IncludeOutputFlag = TRUE;
451 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
452 BadCommandLine = TRUE;
460 switch (AcpiGbl_Optarg[0])
463 /* Produce listing file (Mixed source/aml) */
465 Gbl_ListingFlag = TRUE;
469 /* Produce namespace file */
471 Gbl_NsOutputFlag = TRUE;
475 /* Produce combined source file */
477 Gbl_SourceOutputFlag = TRUE;
481 printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
482 BadCommandLine = TRUE;
490 switch (AcpiGbl_Optarg[0])
494 /* Disable all optimizations */
496 Gbl_FoldConstants = FALSE;
497 Gbl_IntegerOptimizationFlag = FALSE;
498 Gbl_ReferenceOptimizationFlag = FALSE;
503 /* Disable folding on "normal" expressions */
505 Gbl_FoldConstants = FALSE;
510 /* Disable integer optimization to constants */
512 Gbl_IntegerOptimizationFlag = FALSE;
517 /* Disable named reference optimization */
519 Gbl_ReferenceOptimizationFlag = FALSE;
524 /* Display compile time(s) */
526 Gbl_CompileTimesFlag = TRUE;
530 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
531 BadCommandLine = TRUE;
539 /* Override default AML output filename */
541 Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
542 Gbl_UseDefaultAmlFilename = FALSE;
553 switch (AcpiGbl_Optarg[0])
557 /* Produce assembly code output file */
559 Gbl_AsmOutputFlag = TRUE;
564 /* Produce C hex output file */
566 Gbl_C_OutputFlag = TRUE;
570 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
571 BadCommandLine = TRUE;
579 /* Produce hex table output file */
581 switch (AcpiGbl_Optarg[0])
584 Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
588 Gbl_HexOutputFlag = HEX_OUTPUT_C;
592 printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
593 BadCommandLine = TRUE;
601 switch (AcpiGbl_Optarg[0])
604 /* Less verbose error messages */
606 Gbl_VerboseErrors = FALSE;
610 Gbl_DisplayOptimizations = TRUE;
614 Gbl_DisplayRemarks = FALSE;
622 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
623 BadCommandLine = TRUE;
631 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
637 BadCommandLine = TRUE;
641 /* Next parameter must be the input filename */
643 Gbl_Files[ASL_FILE_INPUT].Filename = argv[AcpiGbl_Optind];
644 if (!Gbl_Files[ASL_FILE_INPUT].Filename && !Gbl_DisasmFlag && !Gbl_GetAllTables)
646 printf ("Missing input filename\n");
647 BadCommandLine = TRUE;
652 AslCompilerSignon (ASL_FILE_STDOUT);
655 /* Abort if anything went wrong on the command line */
664 if ((AcpiGbl_Optind + 1) < argc)
666 printf ("Warning: extra arguments (%d) after input filename are ignored\n\n",
667 argc - AcpiGbl_Optind - 1);
672 /*******************************************************************************
676 * PARAMETERS: Standard argc/argv
678 * RETURN: Program termination code
680 * DESCRIPTION: C main routine for the Asl Compiler. Handle command line
681 * options and begin the compile.
683 ******************************************************************************/
685 int ACPI_SYSTEM_XFACE
694 /* Init and command line */
697 AslCommandLine (argc, argv);
700 * If -p not specified, we will use the input filename as the
701 * output filename prefix
703 FlSplitInputPathname (Gbl_Files[ASL_FILE_INPUT].Filename,
704 &Gbl_DirectoryPath, &Prefix);
706 if (Gbl_UseDefaultAmlFilename)
708 Gbl_OutputFilenamePrefix = Prefix;
712 * AML Disassembly (Optional)
714 if (Gbl_DisasmFlag || Gbl_GetAllTables)
716 /* ACPI CA subsystem initialization */
718 Status = AcpiOsInitialize ();
719 AcpiUtInitGlobals ();
720 Status = AcpiUtMutexInitialize ();
721 if (ACPI_FAILURE (Status))
726 Status = AcpiNsRootInitialize ();
727 if (ACPI_FAILURE (Status))
732 /* This is where the disassembly happens */
734 AcpiGbl_DbOpt_disasm = TRUE;
735 Status = AdAmlDisassemble (AslToFile,
736 Gbl_Files[ASL_FILE_INPUT].Filename,
737 Gbl_OutputFilenamePrefix,
738 &Gbl_Files[ASL_FILE_INPUT].Filename,
740 if (ACPI_FAILURE (Status))
746 * Gbl_Files[ASL_FILE_INPUT].Filename was replaced with the
747 * .DSL disassembly file, which can now be compiled if requested
751 AcpiOsPrintf ("\nCompiling \"%s\"\n",
752 Gbl_Files[ASL_FILE_INPUT].Filename);
757 * ASL Compilation (Optional)
762 * If -p not specified, we will use the input filename as the
763 * output filename prefix
765 FlSplitInputPathname (Gbl_Files[ASL_FILE_INPUT].Filename,
766 &Gbl_DirectoryPath, &Prefix);
768 if (Gbl_UseDefaultAmlFilename)
770 Gbl_OutputFilenamePrefix = Prefix;
773 /* ACPI CA subsystem initialization (Must be re-initialized) */
775 Status = AcpiOsInitialize ();
776 AcpiUtInitGlobals ();
777 Status = AcpiUtMutexInitialize ();
778 if (ACPI_FAILURE (Status))
783 Status = AcpiNsRootInitialize ();
784 if (ACPI_FAILURE (Status))
788 Status = CmDoCompile ();