Sync ACPICA with Intel's version 20160831.
[dragonfly.git] / sys / contrib / dev / acpica / source / compiler / aslmain.c
blob6041658c1c23a8131a11a5879089c58ab848bc99
1 /******************************************************************************
3 * Module Name: aslmain - compiler main and utilities
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, Intel Corp.
9 * All rights reserved.
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.
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.
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.
44 #define _DECLARE_GLOBALS
46 #include "aslcompiler.h"
47 #include "acapps.h"
48 #include "acdisasm.h"
49 #include <signal.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
63 * expand wildcards.
66 /* Local prototypes */
68 static void ACPI_SYSTEM_XFACE
69 AslSignalHandler (
70 int Sig);
72 static void
73 AslInitialize (
74 void);
77 /*******************************************************************************
79 * FUNCTION: main
81 * PARAMETERS: Standard argc/argv
83 * RETURN: Program termination code
85 * DESCRIPTION: C main routine for the iASL Compiler/Disassembler. Process
86 * command line options and begin the compile/disassembly for each file on
87 * the command line (wildcards supported).
89 ******************************************************************************/
91 int ACPI_SYSTEM_XFACE
92 main (
93 int argc,
94 char **argv)
96 ACPI_STATUS Status;
97 int Index1;
98 int Index2;
99 int ReturnStatus = 0;
103 * Big-endian machines are not currently supported. ACPI tables must
104 * be little-endian, and support for big-endian machines needs to
105 * be implemented.
107 if (UtIsBigEndianMachine ())
109 fprintf (stderr,
110 "iASL is not currently supported on big-endian machines.\n");
111 return (-1);
114 AcpiOsInitialize ();
115 ACPI_DEBUG_INITIALIZE (); /* For debug version only */
117 /* Initialize preprocessor and compiler before command line processing */
119 signal (SIGINT, AslSignalHandler);
120 AcpiGbl_ExternalFileList = NULL;
121 AcpiDbgLevel = 0;
122 PrInitializePreprocessor ();
123 AslInitialize ();
125 Index1 = Index2 =
126 AslCommandLine (argc, argv);
128 /* Allocate the line buffer(s), must be after command line */
130 Gbl_LineBufferSize /= 2;
131 UtExpandLineBuffers ();
133 /* Perform global actions first/only */
135 if (Gbl_DisassembleAll)
137 while (argv[Index1])
139 Status = AcpiDmAddToExternalFileList (argv[Index1]);
140 if (ACPI_FAILURE (Status))
142 return (-1);
145 Index1++;
149 /* Process each pathname/filename in the list, with possible wildcards */
151 while (argv[Index2])
154 * If -p not specified, we will use the input filename as the
155 * output filename prefix
157 if (Gbl_UseDefaultAmlFilename)
159 Gbl_OutputFilenamePrefix = argv[Index2];
160 UtConvertBackslashes (Gbl_OutputFilenamePrefix);
163 Status = AslDoOneFile (argv[Index2]);
164 if (ACPI_FAILURE (Status))
166 ReturnStatus = -1;
167 goto CleanupAndExit;
170 Index2++;
174 CleanupAndExit:
176 UtFreeLineBuffers ();
177 AslParserCleanup ();
179 if (AcpiGbl_ExternalFileList)
181 AcpiDmClearExternalFileList();
184 return (ReturnStatus);
188 /******************************************************************************
190 * FUNCTION: AslSignalHandler
192 * PARAMETERS: Sig - Signal that invoked this handler
194 * RETURN: None
196 * DESCRIPTION: Control-C handler. Delete any intermediate files and any
197 * output files that may be left in an indeterminate state.
199 *****************************************************************************/
201 static void ACPI_SYSTEM_XFACE
202 AslSignalHandler (
203 int Sig)
205 UINT32 i;
208 signal (Sig, SIG_IGN);
209 printf ("Aborting\n\n");
211 /* Close all open files */
213 Gbl_Files[ASL_FILE_PREPROCESSOR].Handle = NULL; /* the .pre file is same as source file */
215 for (i = ASL_FILE_INPUT; i < ASL_MAX_FILE_TYPE; i++)
217 FlCloseFile (i);
220 /* Delete any output files */
222 for (i = ASL_FILE_AML_OUTPUT; i < ASL_MAX_FILE_TYPE; i++)
224 FlDeleteFile (i);
227 exit (0);
231 /*******************************************************************************
233 * FUNCTION: AslInitialize
235 * PARAMETERS: None
237 * RETURN: None
239 * DESCRIPTION: Initialize compiler globals
241 ******************************************************************************/
243 static void
244 AslInitialize (
245 void)
247 UINT32 i;
250 AcpiGbl_DmOpt_Verbose = FALSE;
252 /* Default integer width is 64 bits */
254 AcpiGbl_IntegerBitWidth = 64;
255 AcpiGbl_IntegerNybbleWidth = 16;
256 AcpiGbl_IntegerByteWidth = 8;
258 for (i = 0; i < ASL_NUM_FILES; i++)
260 Gbl_Files[i].Handle = NULL;
261 Gbl_Files[i].Filename = NULL;
264 Gbl_Files[ASL_FILE_STDOUT].Handle = stdout;
265 Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
267 Gbl_Files[ASL_FILE_STDERR].Handle = stderr;
268 Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR";