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 "aslcompiler.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^e:fgh^i^I:l^mno: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 ("\nGeneral Output:\n");
124 ACPI_OPTION ("-p <prefix>", "Specify path/filename prefix for all output files");
125 ACPI_OPTION ("-va", "Disable all errors and warnings (summary only)");
126 ACPI_OPTION ("-vi", "Less verbose errors and warnings for use with IDEs");
127 ACPI_OPTION ("-vo", "Enable optimization comments");
128 ACPI_OPTION ("-vr", "Disable remarks");
129 ACPI_OPTION ("-vs", "Disable signon");
130 ACPI_OPTION ("-w <1|2|3>", "Set warning reporting level");
132 printf ("\nAML Output Files:\n");
133 ACPI_OPTION ("-s <a|c>", "Create AML in assembler or C source file (*.asm or *.c)");
134 ACPI_OPTION ("-i <a|c>", "Create assembler or C include file (*.inc or *.h)");
135 ACPI_OPTION ("-t <a|c|s>", "Create AML in assembler, C, or ASL hex table (*.hex)");
137 printf ("\nAML Code Generation:\n");
138 ACPI_OPTION ("-oa", "Disable all optimizations (compatibility mode)");
139 ACPI_OPTION ("-of", "Disable constant folding");
140 ACPI_OPTION ("-oi", "Disable integer optimization to Zero/One/Ones");
141 ACPI_OPTION ("-on", "Disable named reference string optimization");
142 ACPI_OPTION ("-cr", "Disable Resource Descriptor error checking");
143 ACPI_OPTION ("-r <revision>", "Override table header Revision (1-255)");
145 printf ("\nASL Listing Files:\n");
146 ACPI_OPTION ("-l", "Create mixed listing file (ASL source and AML) (*.lst)");
147 ACPI_OPTION ("-ln", "Create namespace file (*.nsp)");
148 ACPI_OPTION ("-ls", "Create combined source file (expanded includes) (*.src)");
150 printf ("\nACPI Data Tables:\n");
151 ACPI_OPTION ("-G", "Compile custom table containing generic operators");
152 ACPI_OPTION ("-T <sig>|ALL|*", "Create table template file(s) for <Sig>");
153 ACPI_OPTION ("-vt", "Create verbose templates (full disassembly)");
155 printf ("\nAML Disassembler:\n");
156 ACPI_OPTION ("-d [file]", "Disassemble or decode binary ACPI table to file (*.dsl)");
157 ACPI_OPTION ("-da [f1,f2]", "Disassemble multiple tables from single namespace");
158 ACPI_OPTION ("-dc [file]", "Disassemble AML and immediately compile it");
159 ACPI_OPTION ("", "(Obtain DSDT from current system if no input file)");
160 ACPI_OPTION ("-e [f1,f2]", "Include ACPI table(s) for external symbol resolution");
161 ACPI_OPTION ("-m", "Do not translate Buffers to Resource Templates");
162 ACPI_OPTION ("-2", "Emit ACPI 2.0 compatible ASL code");
163 ACPI_OPTION ("-g", "Get ACPI tables and write to files (*.dat)");
165 printf ("\nHelp:\n");
166 ACPI_OPTION ("-h", "Additional help and compiler debug options");
167 ACPI_OPTION ("-hc", "Display operators allowed in constant expressions");
168 ACPI_OPTION ("-hr", "Display ACPI reserved method names");
169 ACPI_OPTION ("-ht", "Display currently supported ACPI table names");
173 /*******************************************************************************
175 * FUNCTION: HelpMessage
181 * DESCRIPTION: Display help message
183 ******************************************************************************/
190 printf ("\nAML output filename generation:\n");
191 printf (" Output filenames are generated by appending an extension to a common\n");
192 printf (" filename prefix. The filename prefix is obtained via one of the\n");
193 printf (" following methods (in priority order):\n");
194 printf (" 1) The -p option specifies the prefix\n");
195 printf (" 2) The prefix of the AMLFileName in the ASL Definition Block\n");
196 printf (" 3) The prefix of the input filename\n");
201 printf ("\nCompiler/Disassembler Debug Options:\n");
202 ACPI_OPTION ("-b<p|t|b>", "Create compiler debug/trace file (*.txt)");
203 ACPI_OPTION ("", "Types: Parse/Tree/Both");
204 ACPI_OPTION ("-f", "Ignore errors, force creation of AML output file(s)");
205 ACPI_OPTION ("-n", "Parse only, no output generation");
206 ACPI_OPTION ("-ot", "Display compile times");
207 ACPI_OPTION ("-x<level>", "Set debug level for trace output");
208 ACPI_OPTION ("-z", "Do not insert new compiler ID for DataTables");
212 /*******************************************************************************
220 * DESCRIPTION: Display usage and option message
222 ******************************************************************************/
229 printf ("%s\n\n", ASL_COMPLIANCE);
230 ACPI_USAGE_HEADER ("iasl [Options] [Files]");
235 /*******************************************************************************
237 * FUNCTION: AslInitialize
243 * DESCRIPTION: Initialize compiler globals
245 ******************************************************************************/
255 _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0));
260 for (i = 0; i < ASL_NUM_FILES; i++)
262 Gbl_Files[i].Handle = NULL;
263 Gbl_Files[i].Filename = NULL;
266 Gbl_Files[ASL_FILE_STDOUT].Handle = stdout;
267 Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
269 Gbl_Files[ASL_FILE_STDERR].Handle = stderr;
270 Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
274 /*******************************************************************************
276 * FUNCTION: AslMergeOptionTokens
278 * PARAMETERS: InBuffer - Input containing an option string
279 * OutBuffer - Merged output buffer
283 * DESCRIPTION: Remove all whitespace from an option string.
285 ******************************************************************************/
288 AslMergeOptionTokens (
297 Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
300 strcat (OutBuffer, Token);
301 Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
306 /*******************************************************************************
308 * FUNCTION: AslDoResponseFile
310 * PARAMETERS: Filename - Name of the response file
314 * DESCRIPTION: Open a response file and process all options within.
316 ******************************************************************************/
322 char *argv = StringBuffer2;
329 ResponseFile = fopen (Filename, "r");
332 printf ("Could not open command file %s, %s\n",
333 Filename, strerror (errno));
337 /* Must save the current GetOpt globals */
339 Opterr = AcpiGbl_Opterr;
340 Optind = AcpiGbl_Optind;
343 * Process all lines in the response file. There must be one complete
346 while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile))
348 /* Compress all tokens, allowing us to use a single argv entry */
350 AslMergeOptionTokens (StringBuffer, StringBuffer2);
352 /* Process the option */
357 OptStatus = AslDoOptions (1, &argv, TRUE);
360 printf ("Invalid option in command file %s: %s\n",
361 Filename, StringBuffer);
366 /* Restore the GetOpt globals */
368 AcpiGbl_Opterr = Opterr;
369 AcpiGbl_Optind = Optind;
371 fclose (ResponseFile);
376 /*******************************************************************************
378 * FUNCTION: AslDoOptions
380 * PARAMETERS: argc/argv - Standard argc/argv
381 * IsResponseFile - TRUE if executing a response file.
385 * DESCRIPTION: Command line option processing
387 ******************************************************************************/
393 BOOLEAN IsResponseFile)
399 /* Get the command line options */
401 while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j)
403 case '@': /* Begin a response file */
407 printf ("Nested command files are not supported\n");
411 if (AslDoResponseFile (AcpiGbl_Optarg))
426 switch (AcpiGbl_Optarg[0])
429 AslCompilerdebug = 1; /* same as yydebug */
434 AslCompilerdebug = 1; /* same as yydebug */
442 printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
446 /* Produce debug output file */
448 Gbl_DebugFlag = TRUE;
453 switch (AcpiGbl_Optarg[0])
456 Gbl_NoResourceChecking = TRUE;
460 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
467 switch (AcpiGbl_Optarg[0])
470 Gbl_DoCompile = FALSE;
474 Gbl_DoCompile = FALSE;
475 Gbl_DisassembleAll = TRUE;
482 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
486 Gbl_DisasmFlag = TRUE;
491 Status = AcpiDmAddToExternalFileList (AcpiGbl_Optarg);
492 if (ACPI_FAILURE (Status))
494 printf ("Could not add %s to external list\n", AcpiGbl_Optarg);
502 /* Ignore errors and force creation of aml file */
504 Gbl_IgnoreErrors = TRUE;
510 /* Get all ACPI tables */
512 Gbl_GetAllTables = TRUE;
513 Gbl_DoCompile = FALSE;
519 switch (AcpiGbl_Optarg[0])
526 UtDisplayConstantOpcodes ();
532 ApDisplayReservedNames ();
536 UtDisplaySupportedTables ();
540 printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
545 case 'I': /* Add an include file search directory */
547 FlAddIncludeDirectory (AcpiGbl_Optarg);
553 switch (AcpiGbl_Optarg[0])
557 /* Produce assembly code include file */
559 Gbl_AsmIncludeOutputFlag = TRUE;
564 /* Produce C include file */
566 Gbl_C_IncludeOutputFlag = TRUE;
570 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
578 switch (AcpiGbl_Optarg[0])
581 /* Produce listing file (Mixed source/aml) */
583 Gbl_ListingFlag = TRUE;
587 /* Produce namespace file */
589 Gbl_NsOutputFlag = TRUE;
593 /* Produce combined source file */
595 Gbl_SourceOutputFlag = TRUE;
599 printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
607 AcpiGbl_NoResourceDisassembly = TRUE;
615 Gbl_ParseOnlyFlag = TRUE;
621 switch (AcpiGbl_Optarg[0])
625 /* Disable all optimizations */
627 Gbl_FoldConstants = FALSE;
628 Gbl_IntegerOptimizationFlag = FALSE;
629 Gbl_ReferenceOptimizationFlag = FALSE;
634 /* Disable folding on "normal" expressions */
636 Gbl_FoldConstants = FALSE;
641 /* Disable integer optimization to constants */
643 Gbl_IntegerOptimizationFlag = FALSE;
648 /* Disable named reference optimization */
650 Gbl_ReferenceOptimizationFlag = FALSE;
655 /* Display compile time(s) */
657 Gbl_CompileTimesFlag = TRUE;
661 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
669 /* Override default AML output filename */
671 Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
672 Gbl_UseDefaultAmlFilename = FALSE;
677 Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
683 switch (AcpiGbl_Optarg[0])
687 /* Produce assembly code output file */
689 Gbl_AsmOutputFlag = TRUE;
694 /* Produce C hex output file */
696 Gbl_C_OutputFlag = TRUE;
700 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
708 /* Produce hex table output file */
710 switch (AcpiGbl_Optarg[0])
713 Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
717 Gbl_HexOutputFlag = HEX_OUTPUT_C;
721 Gbl_HexOutputFlag = HEX_OUTPUT_ASL;
725 printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
732 Gbl_CompileGeneric = TRUE;
737 Gbl_DoTemplates = TRUE;
738 Gbl_TemplateSignature = AcpiGbl_Optarg;
744 switch (AcpiGbl_Optarg[0])
747 /* Disable All error/warning messages */
753 /* Less verbose error messages */
755 Gbl_VerboseErrors = FALSE;
759 Gbl_DisplayOptimizations = TRUE;
763 Gbl_DisplayRemarks = FALSE;
767 Gbl_DoSignon = FALSE;
771 Gbl_VerboseTemplates = TRUE;
775 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
781 case 'w': /* Set warning levels */
783 switch (AcpiGbl_Optarg[0])
786 Gbl_WarningLevel = ASL_WARNING;
790 Gbl_WarningLevel = ASL_WARNING2;
794 Gbl_WarningLevel = ASL_WARNING3;
798 printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
806 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
812 Gbl_UseOriginalCompilerId = TRUE;
825 /*******************************************************************************
827 * FUNCTION: AslCommandLine
829 * PARAMETERS: argc/argv
831 * RETURN: Last argv index
833 * DESCRIPTION: Command line processing
835 ******************************************************************************/
842 int BadCommandLine = 0;
846 /* Minimum command line contains at least the command and an input file */
850 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
855 /* Process all command line options */
857 BadCommandLine = AslDoOptions (argc, argv, FALSE);
861 Status = DtCreateTemplates (Gbl_TemplateSignature);
862 if (ACPI_FAILURE (Status))
869 /* Next parameter must be the input filename */
871 if (!argv[AcpiGbl_Optind] &&
875 printf ("Missing input filename\n");
876 BadCommandLine = TRUE;
881 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
882 if (Gbl_IgnoreErrors)
884 printf ("Ignoring all errors, forcing AML file generation\n\n");
888 /* Abort if anything went wrong on the command line */
897 return (AcpiGbl_Optind);
901 /*******************************************************************************
905 * PARAMETERS: Standard argc/argv
907 * RETURN: Program termination code
909 * DESCRIPTION: C main routine for the Asl Compiler. Handle command line
910 * options and begin the compile for each file on the command line
912 ******************************************************************************/
914 int ACPI_SYSTEM_XFACE
924 AcpiGbl_ExternalFileList = NULL;
927 _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF |
928 _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
931 /* Init and command line */
934 Index1 = Index2 = AslCommandLine (argc, argv);
936 /* Options that have no additional parameters or pathnames */
938 if (Gbl_GetAllTables)
940 Status = AslDoOneFile (NULL);
941 if (ACPI_FAILURE (Status))
948 if (Gbl_DisassembleAll)
952 Status = AslDoOnePathname (argv[Index1], AcpiDmAddToExternalFileList);
953 if (ACPI_FAILURE (Status))
962 /* Process each pathname/filename in the list, with possible wildcards */
966 Status = AslDoOnePathname (argv[Index2], AslDoOneFile);
967 if (ACPI_FAILURE (Status))
975 if (AcpiGbl_ExternalFileList)
977 AcpiDmClearExternalFileList();