2 /******************************************************************************
4 * Module Name: aslmain - compiler main and utilities
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2012, 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 #define _DECLARE_GLOBALS
48 #include <contrib/dev/acpica/compiler/aslcompiler.h>
49 #include <contrib/dev/acpica/include/acapps.h>
50 #include <contrib/dev/acpica/include/acdisasm.h>
56 #define _COMPONENT ACPI_COMPILER
57 ACPI_MODULE_NAME ("aslmain")
59 /* Local prototypes */
86 BOOLEAN IsResponseFile);
89 AslMergeOptionTokens (
98 #define ASL_TOKEN_SEPARATORS " \t\n"
99 #define ASL_SUPPORTED_OPTIONS "@:2b|c|d^D:e:fgh^i|I:l^mno|p:P^r:s|t|T:G^v|w|x:z"
102 /*******************************************************************************
110 * DESCRIPTION: Display option help message
112 ******************************************************************************/
119 printf ("\nGlobal:\n");
120 ACPI_OPTION ("-@ <file>", "Specify command file");
121 ACPI_OPTION ("-I <dir>", "Specify additional include directory");
123 printf ("\nPreprocessor:\n");
124 ACPI_OPTION ("-D <symbol>", "Define symbol for preprocessor use");
125 ACPI_OPTION ("-li", "Create preprocessed output file (*.i)");
126 ACPI_OPTION ("-P", "Preprocess only and create preprocessor output file (*.i)");
127 ACPI_OPTION ("-Pn", "Disable preprocessor");
129 printf ("\nGeneral Output:\n");
130 ACPI_OPTION ("-p <prefix>", "Specify path/filename prefix for all output files");
131 ACPI_OPTION ("-va", "Disable all errors and warnings (summary only)");
132 ACPI_OPTION ("-vi", "Less verbose errors and warnings for use with IDEs");
133 ACPI_OPTION ("-vo", "Enable optimization comments");
134 ACPI_OPTION ("-vr", "Disable remarks");
135 ACPI_OPTION ("-vs", "Disable signon");
136 ACPI_OPTION ("-w1 -w2 -w3", "Set warning reporting level");
137 ACPI_OPTION ("-we", "Report warnings as errors");
139 printf ("\nAML Output Files:\n");
140 ACPI_OPTION ("-sa -sc", "Create AML in assembler or C source file (*.asm or *.c)");
141 ACPI_OPTION ("-ia -ic", "Create assembler or C include file (*.inc or *.h)");
142 ACPI_OPTION ("-ta -tc -ts", "Create AML in assembler, C, or ASL hex table (*.hex)");
144 printf ("\nAML Code Generation:\n");
145 ACPI_OPTION ("-oa", "Disable all optimizations (compatibility mode)");
146 ACPI_OPTION ("-of", "Disable constant folding");
147 ACPI_OPTION ("-oi", "Disable integer optimization to Zero/One/Ones");
148 ACPI_OPTION ("-on", "Disable named reference string optimization");
149 ACPI_OPTION ("-cr", "Disable Resource Descriptor error checking");
150 ACPI_OPTION ("-r <revision>", "Override table header Revision (1-255)");
152 printf ("\nASL Listing Files:\n");
153 ACPI_OPTION ("-l", "Create mixed listing file (ASL source and AML) (*.lst)");
154 ACPI_OPTION ("-ln", "Create namespace file (*.nsp)");
155 ACPI_OPTION ("-ls", "Create combined source file (expanded includes) (*.src)");
157 printf ("\nACPI Data Tables:\n");
158 ACPI_OPTION ("-G", "Compile custom table containing generic operators");
159 ACPI_OPTION ("-T <sig>|ALL|*", "Create table template file(s) for <Sig>");
160 ACPI_OPTION ("-vt", "Create verbose templates (full disassembly)");
162 printf ("\nAML Disassembler:\n");
163 ACPI_OPTION ("-d [file]", "Disassemble or decode binary ACPI table to file (*.dsl)");
164 ACPI_OPTION ("-da [f1,f2]", "Disassemble multiple tables from single namespace");
165 ACPI_OPTION ("-dc [file]", "Disassemble AML and immediately compile it");
166 ACPI_OPTION ("", "(Obtain DSDT from current system if no input file)");
167 ACPI_OPTION ("-e [f1,f2]", "Include ACPI table(s) for external symbol resolution");
168 ACPI_OPTION ("-m", "Do not translate Buffers to Resource Templates");
169 ACPI_OPTION ("-2", "Emit ACPI 2.0 compatible ASL code");
170 ACPI_OPTION ("-g", "Get ACPI tables and write to files (*.dat)");
172 printf ("\nHelp:\n");
173 ACPI_OPTION ("-h", "This message");
174 ACPI_OPTION ("-hc", "Display operators allowed in constant expressions");
175 ACPI_OPTION ("-hf", "Display help for output filename generation");
176 ACPI_OPTION ("-hr", "Display ACPI reserved method names");
177 ACPI_OPTION ("-ht", "Display currently supported ACPI table names");
179 printf ("\nDebug Options:\n");
180 ACPI_OPTION ("-bf -bt", "Create debug file (full or parse tree only) (*.txt)");
181 ACPI_OPTION ("-f", "Ignore errors, force creation of AML output file(s)");
182 ACPI_OPTION ("-n", "Parse only, no output generation");
183 ACPI_OPTION ("-ot", "Display compile times and statistics");
184 ACPI_OPTION ("-x <level>", "Set debug level for trace output");
185 ACPI_OPTION ("-z", "Do not insert new compiler ID for DataTables");
189 /*******************************************************************************
191 * FUNCTION: FilenameHelp
197 * DESCRIPTION: Display help message for output filename generation
199 ******************************************************************************/
206 printf ("\nAML output filename generation:\n");
207 printf (" Output filenames are generated by appending an extension to a common\n");
208 printf (" filename prefix. The filename prefix is obtained via one of the\n");
209 printf (" following methods (in priority order):\n");
210 printf (" 1) The -p option specifies the prefix\n");
211 printf (" 2) The prefix of the AMLFileName in the ASL Definition Block\n");
212 printf (" 3) The prefix of the input filename\n");
217 /*******************************************************************************
225 * DESCRIPTION: Display usage and option message
227 ******************************************************************************/
234 printf ("%s\n\n", ASL_COMPLIANCE);
235 ACPI_USAGE_HEADER ("iasl [Options] [Files]");
240 /*******************************************************************************
242 * FUNCTION: AslInitialize
248 * DESCRIPTION: Initialize compiler globals
250 ******************************************************************************/
260 _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0));
265 for (i = 0; i < ASL_NUM_FILES; i++)
267 Gbl_Files[i].Handle = NULL;
268 Gbl_Files[i].Filename = NULL;
271 Gbl_Files[ASL_FILE_STDOUT].Handle = stdout;
272 Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
274 Gbl_Files[ASL_FILE_STDERR].Handle = stderr;
275 Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
279 /*******************************************************************************
281 * FUNCTION: AslMergeOptionTokens
283 * PARAMETERS: InBuffer - Input containing an option string
284 * OutBuffer - Merged output buffer
288 * DESCRIPTION: Remove all whitespace from an option string.
290 ******************************************************************************/
293 AslMergeOptionTokens (
302 Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
305 strcat (OutBuffer, Token);
306 Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
311 /*******************************************************************************
313 * FUNCTION: AslDoResponseFile
315 * PARAMETERS: Filename - Name of the response file
319 * DESCRIPTION: Open a response file and process all options within.
321 ******************************************************************************/
327 char *argv = StringBuffer2;
334 ResponseFile = fopen (Filename, "r");
337 printf ("Could not open command file %s, %s\n",
338 Filename, strerror (errno));
342 /* Must save the current GetOpt globals */
344 Opterr = AcpiGbl_Opterr;
345 Optind = AcpiGbl_Optind;
348 * Process all lines in the response file. There must be one complete
351 while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile))
353 /* Compress all tokens, allowing us to use a single argv entry */
355 AslMergeOptionTokens (StringBuffer, StringBuffer2);
357 /* Process the option */
362 OptStatus = AslDoOptions (1, &argv, TRUE);
365 printf ("Invalid option in command file %s: %s\n",
366 Filename, StringBuffer);
371 /* Restore the GetOpt globals */
373 AcpiGbl_Opterr = Opterr;
374 AcpiGbl_Optind = Optind;
376 fclose (ResponseFile);
381 /*******************************************************************************
383 * FUNCTION: AslDoOptions
385 * PARAMETERS: argc/argv - Standard argc/argv
386 * IsResponseFile - TRUE if executing a response file.
390 * DESCRIPTION: Command line option processing
392 ******************************************************************************/
398 BOOLEAN IsResponseFile)
404 /* Get the command line options */
406 while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j)
408 case '@': /* Begin a response file */
412 printf ("Nested command files are not supported\n");
416 if (AslDoResponseFile (AcpiGbl_Optarg))
423 case '2': /* ACPI 2.0 compatibility mode */
428 case 'b': /* Debug output options */
429 switch (AcpiGbl_Optarg[0])
432 AslCompilerdebug = 1; /* same as yydebug */
441 printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
445 /* Produce debug output file */
447 Gbl_DebugFlag = TRUE;
452 switch (AcpiGbl_Optarg[0])
455 Gbl_NoResourceChecking = TRUE;
459 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
465 case 'd': /* Disassembler */
466 switch (AcpiGbl_Optarg[0])
469 Gbl_DoCompile = FALSE;
473 Gbl_DoCompile = FALSE;
474 Gbl_DisassembleAll = TRUE;
481 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
485 Gbl_DisasmFlag = TRUE;
489 case 'D': /* Define a symbol */
490 PrAddDefine (AcpiGbl_Optarg, NULL, TRUE);
494 case 'e': /* External files for disassembler */
495 Status = AcpiDmAddToExternalFileList (AcpiGbl_Optarg);
496 if (ACPI_FAILURE (Status))
498 printf ("Could not add %s to external list\n", AcpiGbl_Optarg);
504 case 'f': /* Ignore errors and force creation of aml file */
505 Gbl_IgnoreErrors = TRUE;
510 Gbl_CompileGeneric = TRUE;
514 case 'g': /* Get all ACPI tables */
516 Gbl_GetAllTables = TRUE;
517 Gbl_DoCompile = FALSE;
522 switch (AcpiGbl_Optarg[0])
529 UtDisplayConstantOpcodes ();
539 ApDisplayReservedNames ();
543 UtDisplaySupportedTables ();
547 printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
552 case 'I': /* Add an include file search directory */
553 FlAddIncludeDirectory (AcpiGbl_Optarg);
557 case 'i': /* Output AML as an include file */
558 switch (AcpiGbl_Optarg[0])
562 /* Produce assembly code include file */
564 Gbl_AsmIncludeOutputFlag = TRUE;
569 /* Produce C include file */
571 Gbl_C_IncludeOutputFlag = TRUE;
575 printf ("Unknown option: -i%s\n", AcpiGbl_Optarg);
581 case 'l': /* Listing files */
582 switch (AcpiGbl_Optarg[0])
585 /* Produce listing file (Mixed source/aml) */
587 Gbl_ListingFlag = TRUE;
591 /* Produce preprocessor output file */
593 Gbl_PreprocessorOutputFlag = TRUE;
597 /* Produce namespace file */
599 Gbl_NsOutputFlag = TRUE;
603 /* Produce combined source file */
605 Gbl_SourceOutputFlag = TRUE;
609 printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
615 case 'm': /* Do not convert buffers to resource descriptors */
616 AcpiGbl_NoResourceDisassembly = TRUE;
620 case 'n': /* Parse only */
621 Gbl_ParseOnlyFlag = TRUE;
625 case 'o': /* Control compiler AML optimizations */
626 switch (AcpiGbl_Optarg[0])
630 /* Disable all optimizations */
632 Gbl_FoldConstants = FALSE;
633 Gbl_IntegerOptimizationFlag = FALSE;
634 Gbl_ReferenceOptimizationFlag = FALSE;
639 /* Disable folding on "normal" expressions */
641 Gbl_FoldConstants = FALSE;
646 /* Disable integer optimization to constants */
648 Gbl_IntegerOptimizationFlag = FALSE;
653 /* Disable named reference optimization */
655 Gbl_ReferenceOptimizationFlag = FALSE;
660 /* Display compile time(s) */
662 Gbl_CompileTimesFlag = TRUE;
666 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
672 case 'P': /* Preprocessor options */
673 switch (AcpiGbl_Optarg[0])
675 case '^': /* Proprocess only, emit (.i) file */
676 Gbl_PreprocessOnly = TRUE;
677 Gbl_PreprocessorOutputFlag = TRUE;
680 case 'n': /* Disable preprocessor */
681 Gbl_PreprocessFlag = FALSE;
685 printf ("Unknown option: -P%s\n", AcpiGbl_Optarg);
691 case 'p': /* Override default AML output filename */
692 Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
693 Gbl_UseDefaultAmlFilename = FALSE;
697 case 'r': /* Override revision found in table header */
698 Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
702 case 's': /* Create AML in a source code file */
703 switch (AcpiGbl_Optarg[0])
707 /* Produce assembly code output file */
709 Gbl_AsmOutputFlag = TRUE;
714 /* Produce C hex output file */
716 Gbl_C_OutputFlag = TRUE;
720 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
726 case 't': /* Produce hex table output file */
727 switch (AcpiGbl_Optarg[0])
730 Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
734 Gbl_HexOutputFlag = HEX_OUTPUT_C;
738 Gbl_HexOutputFlag = HEX_OUTPUT_ASL;
742 printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
748 case 'T': /* Create a ACPI table template file */
749 Gbl_DoTemplates = TRUE;
750 Gbl_TemplateSignature = AcpiGbl_Optarg;
754 case 'v': /* Verbosity settings */
755 switch (AcpiGbl_Optarg[0])
758 /* Disable All error/warning messages */
765 * Support for integrated development environment(s).
767 * 1) No compiler signon
768 * 2) Send stderr messages to stdout
769 * 3) Less verbose error messages (single line only for each)
770 * 4) Error/warning messages are formatted appropriately to
771 * be recognized by MS Visual Studio
773 Gbl_VerboseErrors = FALSE;
774 Gbl_DoSignon = FALSE;
775 Gbl_Files[ASL_FILE_STDERR].Handle = stdout;
779 Gbl_DisplayOptimizations = TRUE;
783 Gbl_DisplayRemarks = FALSE;
787 Gbl_DoSignon = FALSE;
791 Gbl_VerboseTemplates = TRUE;
795 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
801 case 'w': /* Set warning levels */
802 switch (AcpiGbl_Optarg[0])
805 Gbl_WarningLevel = ASL_WARNING;
809 Gbl_WarningLevel = ASL_WARNING2;
813 Gbl_WarningLevel = ASL_WARNING3;
817 Gbl_WarningsAsErrors = TRUE;
821 printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
827 case 'x': /* Set debug print output level */
828 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
833 Gbl_UseOriginalCompilerId = TRUE;
845 /*******************************************************************************
847 * FUNCTION: AslCommandLine
849 * PARAMETERS: argc/argv
851 * RETURN: Last argv index
853 * DESCRIPTION: Command line processing
855 ******************************************************************************/
862 int BadCommandLine = 0;
866 /* Minimum command line contains at least the command and an input file */
870 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
875 /* Process all command line options */
877 BadCommandLine = AslDoOptions (argc, argv, FALSE);
881 Status = DtCreateTemplates (Gbl_TemplateSignature);
882 if (ACPI_FAILURE (Status))
889 /* Next parameter must be the input filename */
891 if (!argv[AcpiGbl_Optind] &&
895 printf ("Missing input filename\n");
896 BadCommandLine = TRUE;
901 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
902 if (Gbl_IgnoreErrors)
904 printf ("Ignoring all errors, forcing AML file generation\n\n");
908 /* Abort if anything went wrong on the command line */
917 return (AcpiGbl_Optind);
921 /*******************************************************************************
925 * PARAMETERS: Standard argc/argv
927 * RETURN: Program termination code
929 * DESCRIPTION: C main routine for the Asl Compiler. Handle command line
930 * options and begin the compile for each file on the command line
932 ******************************************************************************/
934 int ACPI_SYSTEM_XFACE
944 AcpiGbl_ExternalFileList = NULL;
947 _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF |
948 _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
951 /* Init and command line */
954 PrInitializePreprocessor ();
955 Index1 = Index2 = AslCommandLine (argc, argv);
957 /* Options that have no additional parameters or pathnames */
959 if (Gbl_GetAllTables)
961 Status = AslDoOneFile (NULL);
962 if (ACPI_FAILURE (Status))
969 if (Gbl_DisassembleAll)
973 Status = AslDoOnePathname (argv[Index1], AcpiDmAddToExternalFileList);
974 if (ACPI_FAILURE (Status))
983 /* Process each pathname/filename in the list, with possible wildcards */
987 Status = AslDoOnePathname (argv[Index2], AslDoOneFile);
988 if (ACPI_FAILURE (Status))
996 if (AcpiGbl_ExternalFileList)
998 AcpiDmClearExternalFileList();