1 /******************************************************************************
3 * Module Name: aslmain - compiler main and utilities
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #define _DECLARE_GLOBALS
46 #include <contrib/dev/acpica/compiler/aslcompiler.h>
47 #include <contrib/dev/acpica/include/acapps.h>
48 #include <contrib/dev/acpica/include/acdisasm.h>
51 #define _COMPONENT ACPI_COMPILER
52 ACPI_MODULE_NAME ("aslmain")
55 * Main routine for the iASL compiler.
57 * Portability note: The compiler depends upon the host for command-line
58 * wildcard support - it is not implemented locally. For example:
60 * Linux/Unix systems: Shell expands wildcards automatically.
62 * Windows: The setargv.obj module must be linked in to automatically
66 /* Local prototypes */
68 static void ACPI_SYSTEM_XFACE
77 /*******************************************************************************
85 * DESCRIPTION: Display option help message.
86 * Optional items in square brackets.
88 ******************************************************************************/
94 printf ("%s\n\n", ASL_COMPLIANCE);
95 ACPI_USAGE_HEADER ("iasl [Options] [Files]");
97 printf ("\nGeneral:\n");
98 ACPI_OPTION ("-@ <file>", "Specify command file");
99 ACPI_OPTION ("-I <dir>", "Specify additional include directory");
100 ACPI_OPTION ("-T <sig list>|ALL", "Create ACPI table template/example files");
101 ACPI_OPTION ("-T <count>", "Emit DSDT and <count> SSDTs to same file");
102 ACPI_OPTION ("-p <prefix>", "Specify path/filename prefix for all output files");
103 ACPI_OPTION ("-v", "Display compiler version");
104 ACPI_OPTION ("-vo", "Enable optimization comments");
105 ACPI_OPTION ("-vs", "Disable signon");
107 printf ("\nHelp:\n");
108 ACPI_OPTION ("-h", "This message");
109 ACPI_OPTION ("-hc", "Display operators allowed in constant expressions");
110 ACPI_OPTION ("-hf", "Display help for output filename generation");
111 ACPI_OPTION ("-hr", "Display ACPI reserved method names");
112 ACPI_OPTION ("-ht", "Display currently supported ACPI table names");
114 printf ("\nPreprocessor:\n");
115 ACPI_OPTION ("-D <symbol>", "Define symbol for preprocessor use");
116 ACPI_OPTION ("-li", "Create preprocessed output file (*.i)");
117 ACPI_OPTION ("-P", "Preprocess only and create preprocessor output file (*.i)");
118 ACPI_OPTION ("-Pn", "Disable preprocessor");
120 printf ("\nErrors, Warnings, and Remarks:\n");
121 ACPI_OPTION ("-va", "Disable all errors/warnings/remarks");
122 ACPI_OPTION ("-ve", "Report only errors (ignore warnings and remarks)");
123 ACPI_OPTION ("-vi", "Less verbose errors and warnings for use with IDEs");
124 ACPI_OPTION ("-vr", "Disable remarks");
125 ACPI_OPTION ("-vw <messageid>", "Disable specific warning or remark");
126 ACPI_OPTION ("-w1 -w2 -w3", "Set warning reporting level");
127 ACPI_OPTION ("-we", "Report warnings as errors");
129 printf ("\nAML Code Generation (*.aml):\n");
130 ACPI_OPTION ("-oa", "Disable all optimizations (compatibility mode)");
131 ACPI_OPTION ("-of", "Disable constant folding");
132 ACPI_OPTION ("-oi", "Disable integer optimization to Zero/One/Ones");
133 ACPI_OPTION ("-on", "Disable named reference string optimization");
134 ACPI_OPTION ("-ot", "Disable typechecking");
135 ACPI_OPTION ("-cr", "Disable Resource Descriptor error checking");
136 ACPI_OPTION ("-in", "Ignore NoOp operators");
137 ACPI_OPTION ("-r <revision>", "Override table header Revision (1-255)");
139 printf ("\nOptional Source Code Output Files:\n");
140 ACPI_OPTION ("-sc -sa", "Create source file in C or assembler (*.c or *.asm)");
141 ACPI_OPTION ("-ic -ia", "Create include file in C or assembler (*.h or *.inc)");
142 ACPI_OPTION ("-tc -ta -ts", "Create hex AML table in C, assembler, or ASL (*.hex)");
143 ACPI_OPTION ("-so", "Create offset table in C (*.offset.h)");
145 printf ("\nOptional Listing Files:\n");
146 ACPI_OPTION ("-l", "Create mixed listing file (ASL source and AML) (*.lst)");
147 ACPI_OPTION ("-lm", "Create hardware summary map file (*.map)");
148 ACPI_OPTION ("-ln", "Create namespace file (*.nsp)");
149 ACPI_OPTION ("-ls", "Create combined source file (expanded includes) (*.src)");
150 ACPI_OPTION ("-lx", "Create cross-reference file (*.xrf)");
152 printf ("\nData Table Compiler:\n");
153 ACPI_OPTION ("-G", "Compile custom table that contains generic operators");
154 ACPI_OPTION ("-vt", "Create verbose template files (full disassembly)");
156 printf ("\nAML Disassembler:\n");
157 ACPI_OPTION ("-d <f1 f2 ...>", "Disassemble or decode binary ACPI tables to file (*.dsl)");
158 ACPI_OPTION ("", " (Optional, file type is automatically detected)");
159 ACPI_OPTION ("-da <f1 f2 ...>", "Disassemble multiple tables from single namespace");
160 ACPI_OPTION ("-db", "Do not translate Buffers to Resource Templates");
161 ACPI_OPTION ("-dc <f1 f2 ...>", "Disassemble AML and immediately compile it");
162 ACPI_OPTION ("", " (Obtain DSDT from current system if no input file)");
163 ACPI_OPTION ("-df", "Force disassembler to assume table contains valid AML");
164 ACPI_OPTION ("-dl", "Emit legacy ASL code only (no C-style operators)");
165 ACPI_OPTION ("-e <f1 f2 ...>", "Include ACPI table(s) for external symbol resolution");
166 ACPI_OPTION ("-fe <file>", "Specify external symbol declaration file");
167 ACPI_OPTION ("-in", "Ignore NoOp opcodes");
168 ACPI_OPTION ("-l", "Disassemble to mixed ASL and AML code");
169 ACPI_OPTION ("-vt", "Dump binary table data in hex format within output file");
171 printf ("\nDebug Options:\n");
172 ACPI_OPTION ("-bf", "Create debug file (full output) (*.txt)");
173 ACPI_OPTION ("-bs", "Create debug file (parse tree only) (*.txt)");
174 ACPI_OPTION ("-bp <depth>", "Prune ASL parse tree");
175 ACPI_OPTION ("-bt <type>", "Object type to be pruned from the parse tree");
176 ACPI_OPTION ("-f", "Ignore errors, force creation of AML output file(s)");
177 ACPI_OPTION ("-m <size>", "Set internal line buffer size (in Kbytes)");
178 ACPI_OPTION ("-n", "Parse only, no output generation");
179 ACPI_OPTION ("-oc", "Display compile times and statistics");
180 ACPI_OPTION ("-x <level>", "Set debug level for trace output");
181 ACPI_OPTION ("-z", "Do not insert new compiler ID for DataTables");
185 /*******************************************************************************
187 * FUNCTION: FilenameHelp
193 * DESCRIPTION: Display help message for output filename generation
195 ******************************************************************************/
202 printf ("\nAML output filename generation:\n");
203 printf (" Output filenames are generated by appending an extension to a common\n");
204 printf (" filename prefix. The filename prefix is obtained via one of the\n");
205 printf (" following methods (in priority order):\n");
206 printf (" 1) The -p option specifies the prefix\n");
207 printf (" 2) The prefix of the AMLFileName in the ASL Definition Block\n");
208 printf (" 3) The prefix of the input filename\n");
213 /******************************************************************************
215 * FUNCTION: AslSignalHandler
217 * PARAMETERS: Sig - Signal that invoked this handler
221 * DESCRIPTION: Control-C handler. Delete any intermediate files and any
222 * output files that may be left in an indeterminate state.
224 *****************************************************************************/
226 static void ACPI_SYSTEM_XFACE
233 signal (Sig, SIG_IGN);
234 printf ("Aborting\n\n");
236 /* Close all open files */
238 Gbl_Files[ASL_FILE_PREPROCESSOR].Handle = NULL; /* the .pre file is same as source file */
240 for (i = ASL_FILE_INPUT; i < ASL_MAX_FILE_TYPE; i++)
245 /* Delete any output files */
247 for (i = ASL_FILE_AML_OUTPUT; i < ASL_MAX_FILE_TYPE; i++)
256 /*******************************************************************************
258 * FUNCTION: AslInitialize
264 * DESCRIPTION: Initialize compiler globals
266 ******************************************************************************/
275 AcpiGbl_DmOpt_Verbose = FALSE;
277 /* Default integer width is 64 bits */
279 AcpiGbl_IntegerBitWidth = 64;
280 AcpiGbl_IntegerNybbleWidth = 16;
281 AcpiGbl_IntegerByteWidth = 8;
283 for (i = 0; i < ASL_NUM_FILES; i++)
285 Gbl_Files[i].Handle = NULL;
286 Gbl_Files[i].Filename = NULL;
289 Gbl_Files[ASL_FILE_STDOUT].Handle = stdout;
290 Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
292 Gbl_Files[ASL_FILE_STDERR].Handle = stderr;
293 Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
297 /*******************************************************************************
301 * PARAMETERS: Standard argc/argv
303 * RETURN: Program termination code
305 * DESCRIPTION: C main routine for the Asl Compiler. Handle command line
306 * options and begin the compile for each file on the command line
308 ******************************************************************************/
310 int ACPI_SYSTEM_XFACE
318 int ReturnStatus = 0;
322 * Big-endian machines are not currently supported. ACPI tables must
323 * be little-endian, and support for big-endian machines needs to
326 if (UtIsBigEndianMachine ())
329 "iASL is not currently supported on big-endian machines.\n");
334 ACPI_DEBUG_INITIALIZE (); /* For debug version only */
336 /* Initialize preprocessor and compiler before command line processing */
338 signal (SIGINT, AslSignalHandler);
339 AcpiGbl_ExternalFileList = NULL;
341 PrInitializePreprocessor ();
344 Index1 = Index2 = AslCommandLine (argc, argv);
346 /* Allocate the line buffer(s), must be after command line */
348 Gbl_LineBufferSize /= 2;
349 UtExpandLineBuffers ();
351 /* Perform global actions first/only */
353 if (Gbl_DisassembleAll)
357 Status = AcpiDmAddToExternalFileList (argv[Index1]);
358 if (ACPI_FAILURE (Status))
367 /* Process each pathname/filename in the list, with possible wildcards */
372 * If -p not specified, we will use the input filename as the
373 * output filename prefix
375 if (Gbl_UseDefaultAmlFilename)
377 Gbl_OutputFilenamePrefix = argv[Index2];
378 UtConvertBackslashes (Gbl_OutputFilenamePrefix);
381 Status = AslDoOneFile (argv[Index2]);
382 if (ACPI_FAILURE (Status))
394 UtFreeLineBuffers ();
397 if (AcpiGbl_ExternalFileList)
399 AcpiDmClearExternalFileList();
402 return (ReturnStatus);