aslmain.c revision 1.1.1.12 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: aslmain - compiler main and utilities
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1.1.2 jruoho /*
8 1.1.1.11 christos * Copyright (C) 2000 - 2017, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without
12 1.1.1.2 jruoho * modification, are permitted provided that the following conditions
13 1.1.1.2 jruoho * are met:
14 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2 jruoho * without modification.
17 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further
21 1.1.1.2 jruoho * binary redistribution.
22 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived
24 1.1.1.2 jruoho * from this software without specific prior written permission.
25 1.1.1.2 jruoho *
26 1.1.1.2 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2 jruoho * Software Foundation.
29 1.1.1.2 jruoho *
30 1.1.1.2 jruoho * NO WARRANTY
31 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2 jruoho */
43 1.1 jruoho
44 1.1 jruoho #define _DECLARE_GLOBALS
45 1.1 jruoho
46 1.1 jruoho #include "aslcompiler.h"
47 1.1 jruoho #include "acapps.h"
48 1.1.1.2 jruoho #include "acdisasm.h"
49 1.1.1.4 christos #include <signal.h>
50 1.1 jruoho
51 1.1 jruoho #define _COMPONENT ACPI_COMPILER
52 1.1 jruoho ACPI_MODULE_NAME ("aslmain")
53 1.1 jruoho
54 1.1.1.4 christos /*
55 1.1.1.4 christos * Main routine for the iASL compiler.
56 1.1.1.4 christos *
57 1.1.1.4 christos * Portability note: The compiler depends upon the host for command-line
58 1.1.1.4 christos * wildcard support - it is not implemented locally. For example:
59 1.1.1.4 christos *
60 1.1.1.4 christos * Linux/Unix systems: Shell expands wildcards automatically.
61 1.1.1.4 christos *
62 1.1.1.4 christos * Windows: The setargv.obj module must be linked in to automatically
63 1.1.1.4 christos * expand wildcards.
64 1.1.1.4 christos */
65 1.1 jruoho
66 1.1.1.4 christos /* Local prototypes */
67 1.1 jruoho
68 1.1.1.4 christos static void ACPI_SYSTEM_XFACE
69 1.1.1.4 christos AslSignalHandler (
70 1.1.1.4 christos int Sig);
71 1.1 jruoho
72 1.1 jruoho static void
73 1.1 jruoho AslInitialize (
74 1.1 jruoho void);
75 1.1 jruoho
76 1.1 jruoho
77 1.1 jruoho /*******************************************************************************
78 1.1 jruoho *
79 1.1 jruoho * FUNCTION: main
80 1.1 jruoho *
81 1.1 jruoho * PARAMETERS: Standard argc/argv
82 1.1 jruoho *
83 1.1 jruoho * RETURN: Program termination code
84 1.1 jruoho *
85 1.1.1.10 christos * DESCRIPTION: C main routine for the iASL Compiler/Disassembler. Process
86 1.1.1.10 christos * command line options and begin the compile/disassembly for each file on
87 1.1.1.10 christos * the command line (wildcards supported).
88 1.1 jruoho *
89 1.1 jruoho ******************************************************************************/
90 1.1 jruoho
91 1.1 jruoho int ACPI_SYSTEM_XFACE
92 1.1 jruoho main (
93 1.1 jruoho int argc,
94 1.1 jruoho char **argv)
95 1.1 jruoho {
96 1.1 jruoho ACPI_STATUS Status;
97 1.1.1.2 jruoho int Index1;
98 1.1.1.2 jruoho int Index2;
99 1.1.1.5 christos int ReturnStatus = 0;
100 1.1.1.2 jruoho
101 1.1 jruoho
102 1.1.1.12 christos signal (SIGINT, AslSignalHandler);
103 1.1.1.12 christos signal (SIGSEGV, AslSignalHandler);
104 1.1.1.12 christos
105 1.1.1.5 christos /*
106 1.1.1.5 christos * Big-endian machines are not currently supported. ACPI tables must
107 1.1.1.5 christos * be little-endian, and support for big-endian machines needs to
108 1.1.1.5 christos * be implemented.
109 1.1.1.5 christos */
110 1.1.1.9 christos if (UtIsBigEndianMachine ())
111 1.1.1.5 christos {
112 1.1.1.5 christos fprintf (stderr,
113 1.1.1.5 christos "iASL is not currently supported on big-endian machines.\n");
114 1.1.1.5 christos return (-1);
115 1.1.1.5 christos }
116 1.1.1.5 christos
117 1.1.1.5 christos AcpiOsInitialize ();
118 1.1.1.4 christos ACPI_DEBUG_INITIALIZE (); /* For debug version only */
119 1.1 jruoho
120 1.1.1.4 christos /* Initialize preprocessor and compiler before command line processing */
121 1.1 jruoho
122 1.1.1.4 christos AcpiGbl_ExternalFileList = NULL;
123 1.1.1.4 christos AcpiDbgLevel = 0;
124 1.1.1.4 christos PrInitializePreprocessor ();
125 1.1 jruoho AslInitialize ();
126 1.1.1.4 christos
127 1.1.1.10 christos Index1 = Index2 =
128 1.1.1.10 christos AslCommandLine (argc, argv);
129 1.1 jruoho
130 1.1.1.4 christos /* Allocate the line buffer(s), must be after command line */
131 1.1.1.4 christos
132 1.1.1.4 christos Gbl_LineBufferSize /= 2;
133 1.1.1.4 christos UtExpandLineBuffers ();
134 1.1.1.4 christos
135 1.1.1.4 christos /* Perform global actions first/only */
136 1.1 jruoho
137 1.1.1.2 jruoho if (Gbl_DisassembleAll)
138 1.1.1.2 jruoho {
139 1.1.1.2 jruoho while (argv[Index1])
140 1.1.1.2 jruoho {
141 1.1.1.4 christos Status = AcpiDmAddToExternalFileList (argv[Index1]);
142 1.1.1.2 jruoho if (ACPI_FAILURE (Status))
143 1.1.1.2 jruoho {
144 1.1.1.2 jruoho return (-1);
145 1.1.1.2 jruoho }
146 1.1.1.2 jruoho
147 1.1.1.2 jruoho Index1++;
148 1.1.1.2 jruoho }
149 1.1.1.2 jruoho }
150 1.1.1.2 jruoho
151 1.1.1.12 christos
152 1.1 jruoho /* Process each pathname/filename in the list, with possible wildcards */
153 1.1 jruoho
154 1.1.1.2 jruoho while (argv[Index2])
155 1.1 jruoho {
156 1.1.1.4 christos /*
157 1.1.1.4 christos * If -p not specified, we will use the input filename as the
158 1.1.1.4 christos * output filename prefix
159 1.1.1.4 christos */
160 1.1.1.4 christos if (Gbl_UseDefaultAmlFilename)
161 1.1.1.4 christos {
162 1.1.1.4 christos Gbl_OutputFilenamePrefix = argv[Index2];
163 1.1.1.4 christos UtConvertBackslashes (Gbl_OutputFilenamePrefix);
164 1.1.1.4 christos }
165 1.1.1.4 christos
166 1.1.1.4 christos Status = AslDoOneFile (argv[Index2]);
167 1.1 jruoho if (ACPI_FAILURE (Status))
168 1.1 jruoho {
169 1.1.1.5 christos ReturnStatus = -1;
170 1.1.1.5 christos goto CleanupAndExit;
171 1.1 jruoho }
172 1.1 jruoho
173 1.1.1.2 jruoho Index2++;
174 1.1.1.2 jruoho }
175 1.1.1.2 jruoho
176 1.1.1.5 christos
177 1.1.1.5 christos CleanupAndExit:
178 1.1.1.5 christos
179 1.1.1.5 christos UtFreeLineBuffers ();
180 1.1.1.5 christos AslParserCleanup ();
181 1.1.1.5 christos
182 1.1.1.2 jruoho if (AcpiGbl_ExternalFileList)
183 1.1.1.2 jruoho {
184 1.1.1.2 jruoho AcpiDmClearExternalFileList();
185 1.1 jruoho }
186 1.1 jruoho
187 1.1.1.5 christos return (ReturnStatus);
188 1.1 jruoho }
189 1.1.1.10 christos
190 1.1.1.10 christos
191 1.1.1.10 christos /******************************************************************************
192 1.1.1.10 christos *
193 1.1.1.10 christos * FUNCTION: AslSignalHandler
194 1.1.1.10 christos *
195 1.1.1.10 christos * PARAMETERS: Sig - Signal that invoked this handler
196 1.1.1.10 christos *
197 1.1.1.10 christos * RETURN: None
198 1.1.1.10 christos *
199 1.1.1.12 christos * DESCRIPTION: Signal interrupt handler. Delete any intermediate files and
200 1.1.1.12 christos * any output files that may be left in an indeterminate state.
201 1.1.1.12 christos * Currently handles SIGINT (control-c) and SIGSEGV (segmentation
202 1.1.1.12 christos * fault).
203 1.1.1.10 christos *
204 1.1.1.10 christos *****************************************************************************/
205 1.1.1.10 christos
206 1.1.1.10 christos static void ACPI_SYSTEM_XFACE
207 1.1.1.10 christos AslSignalHandler (
208 1.1.1.10 christos int Sig)
209 1.1.1.10 christos {
210 1.1.1.10 christos UINT32 i;
211 1.1.1.10 christos
212 1.1.1.10 christos
213 1.1.1.10 christos signal (Sig, SIG_IGN);
214 1.1.1.12 christos fflush (stdout);
215 1.1.1.12 christos fflush (stderr);
216 1.1.1.12 christos
217 1.1.1.12 christos switch (Sig)
218 1.1.1.12 christos {
219 1.1.1.12 christos case SIGINT:
220 1.1.1.12 christos
221 1.1.1.12 christos printf ("\n" ASL_PREFIX "<Control-C>\n");
222 1.1.1.12 christos break;
223 1.1.1.10 christos
224 1.1.1.12 christos case SIGSEGV:
225 1.1.1.10 christos
226 1.1.1.12 christos /* Even on a seg fault, we will try to delete any partial files */
227 1.1.1.12 christos
228 1.1.1.12 christos printf (ASL_PREFIX "Segmentation Fault\n");
229 1.1.1.12 christos break;
230 1.1.1.12 christos
231 1.1.1.12 christos default:
232 1.1.1.12 christos
233 1.1.1.12 christos printf (ASL_PREFIX "Unknown interrupt signal (%u), ignoring\n", Sig);
234 1.1.1.12 christos return;
235 1.1.1.12 christos }
236 1.1.1.12 christos
237 1.1.1.12 christos /*
238 1.1.1.12 christos * Close all open files
239 1.1.1.12 christos * Note: the .pre file is the same as the input source file
240 1.1.1.12 christos */
241 1.1.1.12 christos Gbl_Files[ASL_FILE_PREPROCESSOR].Handle = NULL;
242 1.1.1.10 christos
243 1.1.1.10 christos for (i = ASL_FILE_INPUT; i < ASL_MAX_FILE_TYPE; i++)
244 1.1.1.10 christos {
245 1.1.1.10 christos FlCloseFile (i);
246 1.1.1.10 christos }
247 1.1.1.10 christos
248 1.1.1.10 christos /* Delete any output files */
249 1.1.1.10 christos
250 1.1.1.10 christos for (i = ASL_FILE_AML_OUTPUT; i < ASL_MAX_FILE_TYPE; i++)
251 1.1.1.10 christos {
252 1.1.1.10 christos FlDeleteFile (i);
253 1.1.1.10 christos }
254 1.1.1.10 christos
255 1.1.1.12 christos printf (ASL_PREFIX "Terminating\n");
256 1.1.1.10 christos exit (0);
257 1.1.1.10 christos }
258 1.1.1.10 christos
259 1.1.1.10 christos
260 1.1.1.10 christos /*******************************************************************************
261 1.1.1.10 christos *
262 1.1.1.10 christos * FUNCTION: AslInitialize
263 1.1.1.10 christos *
264 1.1.1.10 christos * PARAMETERS: None
265 1.1.1.10 christos *
266 1.1.1.10 christos * RETURN: None
267 1.1.1.10 christos *
268 1.1.1.10 christos * DESCRIPTION: Initialize compiler globals
269 1.1.1.10 christos *
270 1.1.1.10 christos ******************************************************************************/
271 1.1.1.10 christos
272 1.1.1.10 christos static void
273 1.1.1.10 christos AslInitialize (
274 1.1.1.10 christos void)
275 1.1.1.10 christos {
276 1.1.1.10 christos UINT32 i;
277 1.1.1.10 christos
278 1.1.1.10 christos
279 1.1.1.10 christos AcpiGbl_DmOpt_Verbose = FALSE;
280 1.1.1.10 christos
281 1.1.1.12 christos /* Default integer width is 32 bits */
282 1.1.1.10 christos
283 1.1.1.12 christos AcpiGbl_IntegerBitWidth = 32;
284 1.1.1.12 christos AcpiGbl_IntegerNybbleWidth = 8;
285 1.1.1.12 christos AcpiGbl_IntegerByteWidth = 4;
286 1.1.1.10 christos
287 1.1.1.10 christos for (i = 0; i < ASL_NUM_FILES; i++)
288 1.1.1.10 christos {
289 1.1.1.10 christos Gbl_Files[i].Handle = NULL;
290 1.1.1.10 christos Gbl_Files[i].Filename = NULL;
291 1.1.1.10 christos }
292 1.1.1.10 christos
293 1.1.1.10 christos Gbl_Files[ASL_FILE_STDOUT].Handle = stdout;
294 1.1.1.10 christos Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
295 1.1.1.10 christos
296 1.1.1.10 christos Gbl_Files[ASL_FILE_STDERR].Handle = stderr;
297 1.1.1.10 christos Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
298 1.1.1.10 christos }
299