]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/contrib/dev/acpica/compiler/aslmain.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / contrib / dev / acpica / compiler / aslmain.c
1 /******************************************************************************
2  *
3  * Module Name: aslmain - compiler main and utilities
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2013, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
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.
25  *
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.
29  *
30  * NO WARRANTY
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.
42  */
43
44 #define _DECLARE_GLOBALS
45
46 #include <contrib/dev/acpica/compiler/aslcompiler.h>
47 #include <contrib/dev/acpica/include/acapps.h>
48 #include <contrib/dev/acpica/include/acdisasm.h>
49 #include <signal.h>
50
51 #define _COMPONENT          ACPI_COMPILER
52         ACPI_MODULE_NAME    ("aslmain")
53
54
55 /* Local prototypes */
56
57 static void ACPI_SYSTEM_XFACE
58 AslSignalHandler (
59     int                     Sig);
60
61 static void
62 AslInitialize (
63     void);
64
65
66 /*******************************************************************************
67  *
68  * FUNCTION:    Usage
69  *
70  * PARAMETERS:  None
71  *
72  * RETURN:      None
73  *
74  * DESCRIPTION: Display option help message.
75  *              Optional items in square brackets.
76  *
77  ******************************************************************************/
78
79 void
80 Usage (
81     void)
82 {
83     printf ("%s\n\n", ASL_COMPLIANCE);
84     ACPI_USAGE_HEADER ("iasl [Options] [Files]");
85
86     printf ("\nGlobal:\n");
87     ACPI_OPTION ("-@ <file>",       "Specify command file");
88     ACPI_OPTION ("-I <dir>",        "Specify additional include directory");
89     ACPI_OPTION ("-T <sig>|ALL|*",  "Create table template file for ACPI <Sig>");
90     ACPI_OPTION ("-v",              "Display compiler version");
91
92     printf ("\nPreprocessor:\n");
93     ACPI_OPTION ("-D <symbol>",     "Define symbol for preprocessor use");
94     ACPI_OPTION ("-li",             "Create preprocessed output file (*.i)");
95     ACPI_OPTION ("-P",              "Preprocess only and create preprocessor output file (*.i)");
96     ACPI_OPTION ("-Pn",             "Disable preprocessor");
97
98     printf ("\nGeneral Processing:\n");
99     ACPI_OPTION ("-p <prefix>",     "Specify path/filename prefix for all output files");
100     ACPI_OPTION ("-va",             "Disable all errors and warnings (summary only)");
101     ACPI_OPTION ("-vi",             "Less verbose errors and warnings for use with IDEs");
102     ACPI_OPTION ("-vo",             "Enable optimization comments");
103     ACPI_OPTION ("-vr",             "Disable remarks");
104     ACPI_OPTION ("-vs",             "Disable signon");
105     ACPI_OPTION ("-vw <messageid>", "Disable specific warning or remark");
106     ACPI_OPTION ("-w1 -w2 -w3",     "Set warning reporting level");
107     ACPI_OPTION ("-we",             "Report warnings as errors");
108
109     printf ("\nAML Code Generation (*.aml):\n");
110     ACPI_OPTION ("-oa",             "Disable all optimizations (compatibility mode)");
111     ACPI_OPTION ("-of",             "Disable constant folding");
112     ACPI_OPTION ("-oi",             "Disable integer optimization to Zero/One/Ones");
113     ACPI_OPTION ("-on",             "Disable named reference string optimization");
114     ACPI_OPTION ("-cr",             "Disable Resource Descriptor error checking");
115     ACPI_OPTION ("-in",             "Ignore NoOp operators");
116     ACPI_OPTION ("-r <revision>",   "Override table header Revision (1-255)");
117
118     printf ("\nOptional Source Code Output Files:\n");
119     ACPI_OPTION ("-sc -sa",         "Create source file in C or assembler (*.c or *.asm)");
120     ACPI_OPTION ("-ic -ia",         "Create include file in C or assembler (*.h or *.inc)");
121     ACPI_OPTION ("-tc -ta -ts",     "Create hex AML table in C, assembler, or ASL (*.hex)");
122     ACPI_OPTION ("-so",             "Create offset table in C (*.offset.h)");
123
124     printf ("\nOptional Listing Files:\n");
125     ACPI_OPTION ("-l",              "Create mixed listing file (ASL source and AML) (*.lst)");
126     ACPI_OPTION ("-ln",             "Create namespace file (*.nsp)");
127     ACPI_OPTION ("-ls",             "Create combined source file (expanded includes) (*.src)");
128
129     printf ("\nData Table Compiler:\n");
130     ACPI_OPTION ("-G",              "Compile custom table that contains generic operators");
131     ACPI_OPTION ("-vt",             "Create verbose template files (full disassembly)");
132
133     printf ("\nAML Disassembler:\n");
134     ACPI_OPTION ("-d  <f1,f2>",     "Disassemble or decode binary ACPI tables to file (*.dsl)");
135     ACPI_OPTION ("",                "  (Optional, file type is automatically detected)");
136     ACPI_OPTION ("-da <f1,f2>",     "Disassemble multiple tables from single namespace");
137     ACPI_OPTION ("-db",             "Do not translate Buffers to Resource Templates");
138     ACPI_OPTION ("-dc <f1,f2>",     "Disassemble AML and immediately compile it");
139     ACPI_OPTION ("",                "  (Obtain DSDT from current system if no input file)");
140     ACPI_OPTION ("-e  <f1,f2>",     "Include ACPI table(s) for external symbol resolution");
141     ACPI_OPTION ("-fe <file>",      "Specify external symbol declaration file");
142     ACPI_OPTION ("-g",              "Get ACPI tables and write to files (*.dat)");
143     ACPI_OPTION ("-in",             "Ignore NoOp opcodes");
144     ACPI_OPTION ("-vt",             "Dump binary table data in hex format within output file");
145
146     printf ("\nHelp:\n");
147     ACPI_OPTION ("-h",              "This message");
148     ACPI_OPTION ("-hc",             "Display operators allowed in constant expressions");
149     ACPI_OPTION ("-hf",             "Display help for output filename generation");
150     ACPI_OPTION ("-hr",             "Display ACPI reserved method names");
151     ACPI_OPTION ("-ht",             "Display currently supported ACPI table names");
152
153     printf ("\nDebug Options:\n");
154     ACPI_OPTION ("-bf -bt",         "Create debug file (full or parse tree only) (*.txt)");
155     ACPI_OPTION ("-f",              "Ignore errors, force creation of AML output file(s)");
156     ACPI_OPTION ("-m <size>",       "Set internal line buffer size (in Kbytes)");
157     ACPI_OPTION ("-n",              "Parse only, no output generation");
158     ACPI_OPTION ("-ot",             "Display compile times and statistics");
159     ACPI_OPTION ("-x <level>",      "Set debug level for trace output");
160     ACPI_OPTION ("-z",              "Do not insert new compiler ID for DataTables");
161 }
162
163
164 /*******************************************************************************
165  *
166  * FUNCTION:    FilenameHelp
167  *
168  * PARAMETERS:  None
169  *
170  * RETURN:      None
171  *
172  * DESCRIPTION: Display help message for output filename generation
173  *
174  ******************************************************************************/
175
176 void
177 AslFilenameHelp (
178     void)
179 {
180
181     printf ("\nAML output filename generation:\n");
182     printf ("  Output filenames are generated by appending an extension to a common\n");
183     printf ("  filename prefix. The filename prefix is obtained via one of the\n");
184     printf ("  following methods (in priority order):\n");
185     printf ("    1) The -p option specifies the prefix\n");
186     printf ("    2) The prefix of the AMLFileName in the ASL Definition Block\n");
187     printf ("    3) The prefix of the input filename\n");
188     printf ("\n");
189 }
190
191
192 /******************************************************************************
193  *
194  * FUNCTION:    AslSignalHandler
195  *
196  * PARAMETERS:  Sig                 - Signal that invoked this handler
197  *
198  * RETURN:      None
199  *
200  * DESCRIPTION: Control-C handler. Delete any intermediate files and any
201  *              output files that may be left in an indeterminate state.
202  *
203  *****************************************************************************/
204
205 static void ACPI_SYSTEM_XFACE
206 AslSignalHandler (
207     int                     Sig)
208 {
209     UINT32                  i;
210
211
212     signal (Sig, SIG_IGN);
213     printf ("Aborting\n\n");
214
215     /* Close all open files */
216
217     Gbl_Files[ASL_FILE_PREPROCESSOR].Handle = NULL; /* the .i file is same as source file */
218
219     for (i = ASL_FILE_INPUT; i < ASL_MAX_FILE_TYPE; i++)
220     {
221         FlCloseFile (i);
222     }
223
224     /* Delete any output files */
225
226     for (i = ASL_FILE_AML_OUTPUT; i < ASL_MAX_FILE_TYPE; i++)
227     {
228         FlDeleteFile (i);
229     }
230
231     exit (0);
232 }
233
234
235 /*******************************************************************************
236  *
237  * FUNCTION:    AslInitialize
238  *
239  * PARAMETERS:  None
240  *
241  * RETURN:      None
242  *
243  * DESCRIPTION: Initialize compiler globals
244  *
245  ******************************************************************************/
246
247 static void
248 AslInitialize (
249     void)
250 {
251     UINT32                  i;
252
253
254     for (i = 0; i < ASL_NUM_FILES; i++)
255     {
256         Gbl_Files[i].Handle = NULL;
257         Gbl_Files[i].Filename = NULL;
258     }
259
260     Gbl_Files[ASL_FILE_STDOUT].Handle   = stdout;
261     Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
262
263     Gbl_Files[ASL_FILE_STDERR].Handle   = stderr;
264     Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
265 }
266
267
268 /*******************************************************************************
269  *
270  * FUNCTION:    main
271  *
272  * PARAMETERS:  Standard argc/argv
273  *
274  * RETURN:      Program termination code
275  *
276  * DESCRIPTION: C main routine for the Asl Compiler. Handle command line
277  *              options and begin the compile for each file on the command line
278  *
279  ******************************************************************************/
280
281 int ACPI_SYSTEM_XFACE
282 main (
283     int                     argc,
284     char                    **argv)
285 {
286     ACPI_STATUS             Status;
287     int                     Index1;
288     int                     Index2;
289
290
291     ACPI_DEBUG_INITIALIZE (); /* For debug version only */
292
293     /* Initialize preprocessor and compiler before command line processing */
294
295     signal (SIGINT, AslSignalHandler);
296     AcpiGbl_ExternalFileList = NULL;
297     AcpiDbgLevel = 0;
298     PrInitializePreprocessor ();
299     AslInitialize ();
300
301     Index1 = Index2 = AslCommandLine (argc, argv);
302
303     /* Allocate the line buffer(s), must be after command line */
304
305     Gbl_LineBufferSize /= 2;
306     UtExpandLineBuffers ();
307
308     /* Perform global actions first/only */
309
310     if (Gbl_GetAllTables)
311     {
312         Status = AslDoOneFile (NULL);
313         if (ACPI_FAILURE (Status))
314         {
315             return (-1);
316         }
317         return (0);
318     }
319
320     if (Gbl_DisassembleAll)
321     {
322         while (argv[Index1])
323         {
324             Status = AslDoOnePathname (argv[Index1], AcpiDmAddToExternalFileList);
325             if (ACPI_FAILURE (Status))
326             {
327                 return (-1);
328             }
329
330             Index1++;
331         }
332     }
333
334     /* Process each pathname/filename in the list, with possible wildcards */
335
336     while (argv[Index2])
337     {
338         Status = AslDoOnePathname (argv[Index2], AslDoOneFile);
339         if (ACPI_FAILURE (Status))
340         {
341             return (-1);
342         }
343
344         Index2++;
345     }
346
347     if (AcpiGbl_ExternalFileList)
348     {
349         AcpiDmClearExternalFileList();
350     }
351
352     return (0);
353 }