2 /******************************************************************************
4 * Module Name: aslmain - compiler main and utilities
7 *****************************************************************************/
9 /******************************************************************************
13 * Some or all of this work - Copyright (c) 1999 - 2007, 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 <contrib/dev/acpica/compiler/aslcompiler.h>
122 #include <contrib/dev/acpica/acnamesp.h>
123 #include <contrib/dev/acpica/actables.h>
124 #include <contrib/dev/acpica/acapps.h>
130 #define _COMPONENT ACPI_COMPILER
131 ACPI_MODULE_NAME ("aslmain")
133 BOOLEAN AslToFile = TRUE;
134 BOOLEAN DoCompile = TRUE;
135 BOOLEAN DoSignon = TRUE;
139 '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
142 /* Local prototypes */
169 /*******************************************************************************
177 * DESCRIPTION: Display option help message
179 ******************************************************************************/
186 printf ("General Output:\n");
187 printf (" -p <prefix> Specify filename prefix for all output files (including .aml)\n");
188 printf (" -vi Less verbose errors and warnings for use with IDEs\n");
189 printf (" -vo Enable optimization comments\n");
190 printf (" -vr Disable remarks\n");
191 printf (" -vs Disable signon\n");
192 printf (" -w<1|2|3> Set warning reporting level\n");
194 printf ("\nAML Output Files:\n");
195 printf (" -s<a|c> Create AML in assembler or C source file (*.asm or *.c)\n");
196 printf (" -i<a|c> Create assembler or C include file (*.inc or *.h)\n");
197 printf (" -t<a|c> Create AML in assembler or C hex table (*.hex)\n");
199 printf ("\nAML Code Generation:\n");
200 printf (" -oa Disable all optimizations (compatibility mode)\n");
201 printf (" -of Disable constant folding\n");
202 printf (" -oi Disable integer optimization to Zero/One/Ones\n");
203 printf (" -on Disable named reference string optimization\n");
204 printf (" -r<Revision> Override table header Revision (1-255)\n");
206 printf ("\nListings:\n");
207 printf (" -l Create mixed listing file (ASL source and AML) (*.lst)\n");
208 printf (" -ln Create namespace file (*.nsp)\n");
209 printf (" -ls Create combined source file (expanded includes) (*.src)\n");
211 printf ("\nAML Disassembler:\n");
212 printf (" -d [file] Disassemble or decode binary ACPI table to file (*.dsl)\n");
213 printf (" -dc [file] Disassemble AML and immediately compile it\n");
214 printf (" (Obtain DSDT from current system if no input file)\n");
215 printf (" -e [file] Include ACPI table for external symbol resolution\n");
216 printf (" -2 Emit ACPI 2.0 compatible ASL code\n");
217 printf (" -g Get ACPI tables and write to files (*.dat)\n");
219 printf ("\nHelp:\n");
220 printf (" -h Additional help and compiler debug options\n");
221 printf (" -hc Display operators allowed in constant expressions\n");
222 printf (" -hr Display ACPI reserved method names\n");
226 /*******************************************************************************
228 * FUNCTION: HelpMessage
234 * DESCRIPTION: Display help message
236 ******************************************************************************/
243 printf ("AML output filename generation:\n");
244 printf (" Output filenames are generated by appending an extension to a common\n");
245 printf (" filename prefix. The filename prefix is obtained via one of the\n");
246 printf (" following methods (in priority order):\n");
247 printf (" 1) The -p option specifies the prefix\n");
248 printf (" 2) The prefix of the AMLFileName in the ASL Definition Block\n");
249 printf (" 3) The prefix of the input filename\n");
254 printf ("\nCompiler/Disassembler Debug Options:\n");
255 printf (" -b<p|t|b> Create compiler debug/trace file (*.txt)\n");
256 printf (" Types: Parse/Tree/Both\n");
257 printf (" -f Ignore errors, force creation of AML output file(s)\n");
258 printf (" -c Parse only, no output generation\n");
259 printf (" -ot Display compile times\n");
260 printf (" -x<level> Set debug level for trace output\n");
264 /*******************************************************************************
272 * DESCRIPTION: Display usage and option message
274 ******************************************************************************/
281 printf ("Usage: %s [Options] [InputFile]\n\n", CompilerName);
286 /*******************************************************************************
288 * FUNCTION: AslInitialize
294 * DESCRIPTION: Initialize compiler globals
296 ******************************************************************************/
306 _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0));
311 for (i = 0; i < ASL_NUM_FILES; i++)
313 Gbl_Files[i].Handle = NULL;
314 Gbl_Files[i].Filename = NULL;
317 Gbl_Files[ASL_FILE_STDOUT].Handle = stdout;
318 Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
320 Gbl_Files[ASL_FILE_STDERR].Handle = stderr;
321 Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
325 /*******************************************************************************
327 * FUNCTION: AslCommandLine
329 * PARAMETERS: argc/argv
333 * DESCRIPTION: Command line processing
335 ******************************************************************************/
342 BOOLEAN BadCommandLine = FALSE;
346 /* Minimum command line contains at least one option or an input file */
350 AslCompilerSignon (ASL_FILE_STDOUT);
355 /* Get the command line options */
357 while ((j = AcpiGetopt (argc, argv, "2b:cd^e:fgh^i^l^o:p:r:s:t:v:w:x:")) != EOF) switch (j)
366 switch (AcpiGbl_Optarg[0])
369 AslCompilerdebug = 1; /* same as yydebug */
373 AslCompilerdebug = 1; /* same as yydebug */
380 printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
381 BadCommandLine = TRUE;
385 /* Produce debug output file */
387 Gbl_DebugFlag = TRUE;
395 Gbl_ParseOnlyFlag = TRUE;
400 switch (AcpiGbl_Optarg[0])
410 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
411 BadCommandLine = TRUE;
415 Gbl_DisasmFlag = TRUE;
420 Gbl_ExternalFilename = AcpiGbl_Optarg;
426 /* Ignore errors and force creation of aml file */
428 Gbl_IgnoreErrors = TRUE;
434 /* Get all ACPI tables */
436 Gbl_GetAllTables = TRUE;
443 switch (AcpiGbl_Optarg[0])
450 UtDisplayConstantOpcodes ();
456 MpDisplayReservedNames ();
460 printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
461 BadCommandLine = TRUE;
469 switch (AcpiGbl_Optarg[0])
473 /* Produce assembly code include file */
475 Gbl_AsmIncludeOutputFlag = TRUE;
480 /* Produce C include file */
482 Gbl_C_IncludeOutputFlag = TRUE;
486 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
487 BadCommandLine = TRUE;
495 switch (AcpiGbl_Optarg[0])
498 /* Produce listing file (Mixed source/aml) */
500 Gbl_ListingFlag = TRUE;
504 /* Produce namespace file */
506 Gbl_NsOutputFlag = TRUE;
510 /* Produce combined source file */
512 Gbl_SourceOutputFlag = TRUE;
516 printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
517 BadCommandLine = TRUE;
525 switch (AcpiGbl_Optarg[0])
529 /* Disable all optimizations */
531 Gbl_FoldConstants = FALSE;
532 Gbl_IntegerOptimizationFlag = FALSE;
533 Gbl_ReferenceOptimizationFlag = FALSE;
538 /* Disable folding on "normal" expressions */
540 Gbl_FoldConstants = FALSE;
545 /* Disable integer optimization to constants */
547 Gbl_IntegerOptimizationFlag = FALSE;
552 /* Disable named reference optimization */
554 Gbl_ReferenceOptimizationFlag = FALSE;
559 /* Display compile time(s) */
561 Gbl_CompileTimesFlag = TRUE;
565 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
566 BadCommandLine = TRUE;
574 /* Override default AML output filename */
576 Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
577 Gbl_UseDefaultAmlFilename = FALSE;
582 Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
588 switch (AcpiGbl_Optarg[0])
592 /* Produce assembly code output file */
594 Gbl_AsmOutputFlag = TRUE;
599 /* Produce C hex output file */
601 Gbl_C_OutputFlag = TRUE;
605 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
606 BadCommandLine = TRUE;
614 /* Produce hex table output file */
616 switch (AcpiGbl_Optarg[0])
619 Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
623 Gbl_HexOutputFlag = HEX_OUTPUT_C;
627 printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
628 BadCommandLine = TRUE;
636 switch (AcpiGbl_Optarg[0])
639 /* Less verbose error messages */
641 Gbl_VerboseErrors = FALSE;
645 Gbl_DisplayOptimizations = TRUE;
649 Gbl_DisplayRemarks = FALSE;
657 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
658 BadCommandLine = TRUE;
664 case 'w': /* Set warning levels */
666 switch (AcpiGbl_Optarg[0])
669 Gbl_WarningLevel = ASL_WARNING;
673 Gbl_WarningLevel = ASL_WARNING2;
677 Gbl_WarningLevel = ASL_WARNING3;
681 printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
682 BadCommandLine = TRUE;
690 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
696 BadCommandLine = TRUE;
700 /* Next parameter must be the input filename */
702 Gbl_Files[ASL_FILE_INPUT].Filename = argv[AcpiGbl_Optind];
704 if (!Gbl_Files[ASL_FILE_INPUT].Filename &&
708 printf ("Missing input filename\n");
709 BadCommandLine = TRUE;
714 AslCompilerSignon (ASL_FILE_STDOUT);
717 /* Abort if anything went wrong on the command line */
726 if ((AcpiGbl_Optind + 1) < argc)
728 printf ("Warning: extra arguments (%d) after input filename are ignored\n\n",
729 argc - AcpiGbl_Optind - 1);
734 /*******************************************************************************
738 * PARAMETERS: Standard argc/argv
740 * RETURN: Program termination code
742 * DESCRIPTION: C main routine for the Asl Compiler. Handle command line
743 * options and begin the compile.
745 ******************************************************************************/
747 int ACPI_SYSTEM_XFACE
757 _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF |
758 _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
761 /* Init and command line */
764 AslCommandLine (argc, argv);
767 * If -p not specified, we will use the input filename as the
768 * output filename prefix
770 Status = FlSplitInputPathname (Gbl_Files[ASL_FILE_INPUT].Filename,
771 &Gbl_DirectoryPath, &Prefix);
772 if (ACPI_FAILURE (Status))
777 if (Gbl_UseDefaultAmlFilename)
779 Gbl_OutputFilenamePrefix = Prefix;
782 /* AML Disassembly (Optional) */
784 if (Gbl_DisasmFlag || Gbl_GetAllTables)
786 /* ACPI CA subsystem initialization */
788 Status = AdInitialize ();
789 if (ACPI_FAILURE (Status))
794 Status = AcpiAllocateRootTable (4);
795 if (ACPI_FAILURE (Status))
797 AcpiOsPrintf ("Could not initialize ACPI Table Manager, %s\n",
798 AcpiFormatException (Status));
802 /* This is where the disassembly happens */
804 AcpiGbl_DbOpt_disasm = TRUE;
805 Status = AdAmlDisassemble (AslToFile,
806 Gbl_Files[ASL_FILE_INPUT].Filename,
807 Gbl_OutputFilenamePrefix,
808 &Gbl_Files[ASL_FILE_INPUT].Filename,
810 if (ACPI_FAILURE (Status))
816 * Gbl_Files[ASL_FILE_INPUT].Filename was replaced with the
817 * .DSL disassembly file, which can now be compiled if requested
821 AcpiOsPrintf ("\nCompiling \"%s\"\n",
822 Gbl_Files[ASL_FILE_INPUT].Filename);
827 * ASL Compilation (Optional)
832 * If -p not specified, we will use the input filename as the
833 * output filename prefix
835 Status = FlSplitInputPathname (Gbl_Files[ASL_FILE_INPUT].Filename,
836 &Gbl_DirectoryPath, &Prefix);
837 if (ACPI_FAILURE (Status))
842 if (Gbl_UseDefaultAmlFilename)
844 Gbl_OutputFilenamePrefix = Prefix;
847 /* ACPI CA subsystem initialization (Must be re-initialized) */
849 Status = AcpiOsInitialize ();
850 AcpiUtInitGlobals ();
851 Status = AcpiUtMutexInitialize ();
852 if (ACPI_FAILURE (Status))
857 Status = AcpiNsRootInitialize ();
858 if (ACPI_FAILURE (Status))
862 Status = CmDoCompile ();