xref: /freebsd/sys/contrib/dev/acpica/compiler/aslmain.c (revision a9f12690a1c5018ef2676597bbcdfb5a7f692b80)
153289f6aSNate Lawson 
253289f6aSNate Lawson /******************************************************************************
353289f6aSNate Lawson  *
453289f6aSNate Lawson  * Module Name: aslmain - compiler main and utilities
553289f6aSNate Lawson  *
653289f6aSNate Lawson  *****************************************************************************/
753289f6aSNate Lawson 
853289f6aSNate Lawson /******************************************************************************
953289f6aSNate Lawson  *
1053289f6aSNate Lawson  * 1. Copyright Notice
1153289f6aSNate Lawson  *
12a9f12690SJung-uk Kim  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
1353289f6aSNate Lawson  * All rights reserved.
1453289f6aSNate Lawson  *
1553289f6aSNate Lawson  * 2. License
1653289f6aSNate Lawson  *
1753289f6aSNate Lawson  * 2.1. This is your license from Intel Corp. under its intellectual property
1853289f6aSNate Lawson  * rights.  You may have additional license terms from the party that provided
1953289f6aSNate Lawson  * you this software, covering your right to use that party's intellectual
2053289f6aSNate Lawson  * property rights.
2153289f6aSNate Lawson  *
2253289f6aSNate Lawson  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2353289f6aSNate Lawson  * copy of the source code appearing in this file ("Covered Code") an
2453289f6aSNate Lawson  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2553289f6aSNate Lawson  * base code distributed originally by Intel ("Original Intel Code") to copy,
2653289f6aSNate Lawson  * make derivatives, distribute, use and display any portion of the Covered
2753289f6aSNate Lawson  * Code in any form, with the right to sublicense such rights; and
2853289f6aSNate Lawson  *
2953289f6aSNate Lawson  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3053289f6aSNate Lawson  * license (with the right to sublicense), under only those claims of Intel
3153289f6aSNate Lawson  * patents that are infringed by the Original Intel Code, to make, use, sell,
3253289f6aSNate Lawson  * offer to sell, and import the Covered Code and derivative works thereof
3353289f6aSNate Lawson  * solely to the minimum extent necessary to exercise the above copyright
3453289f6aSNate Lawson  * license, and in no event shall the patent license extend to any additions
3553289f6aSNate Lawson  * to or modifications of the Original Intel Code.  No other license or right
3653289f6aSNate Lawson  * is granted directly or by implication, estoppel or otherwise;
3753289f6aSNate Lawson  *
3853289f6aSNate Lawson  * The above copyright and patent license is granted only if the following
3953289f6aSNate Lawson  * conditions are met:
4053289f6aSNate Lawson  *
4153289f6aSNate Lawson  * 3. Conditions
4253289f6aSNate Lawson  *
4353289f6aSNate Lawson  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4453289f6aSNate Lawson  * Redistribution of source code of any substantial portion of the Covered
4553289f6aSNate Lawson  * Code or modification with rights to further distribute source must include
4653289f6aSNate Lawson  * the above Copyright Notice, the above License, this list of Conditions,
4753289f6aSNate Lawson  * and the following Disclaimer and Export Compliance provision.  In addition,
4853289f6aSNate Lawson  * Licensee must cause all Covered Code to which Licensee contributes to
4953289f6aSNate Lawson  * contain a file documenting the changes Licensee made to create that Covered
5053289f6aSNate Lawson  * Code and the date of any change.  Licensee must include in that file the
5153289f6aSNate Lawson  * documentation of any changes made by any predecessor Licensee.  Licensee
5253289f6aSNate Lawson  * must include a prominent statement that the modification is derived,
5353289f6aSNate Lawson  * directly or indirectly, from Original Intel Code.
5453289f6aSNate Lawson  *
5553289f6aSNate Lawson  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5653289f6aSNate Lawson  * Redistribution of source code of any substantial portion of the Covered
5753289f6aSNate Lawson  * Code or modification without rights to further distribute source must
5853289f6aSNate Lawson  * include the following Disclaimer and Export Compliance provision in the
5953289f6aSNate Lawson  * documentation and/or other materials provided with distribution.  In
6053289f6aSNate Lawson  * addition, Licensee may not authorize further sublicense of source of any
6153289f6aSNate Lawson  * portion of the Covered Code, and must include terms to the effect that the
6253289f6aSNate Lawson  * license from Licensee to its licensee is limited to the intellectual
6353289f6aSNate Lawson  * property embodied in the software Licensee provides to its licensee, and
6453289f6aSNate Lawson  * not to intellectual property embodied in modifications its licensee may
6553289f6aSNate Lawson  * make.
6653289f6aSNate Lawson  *
6753289f6aSNate Lawson  * 3.3. Redistribution of Executable. Redistribution in executable form of any
6853289f6aSNate Lawson  * substantial portion of the Covered Code or modification must reproduce the
6953289f6aSNate Lawson  * above Copyright Notice, and the following Disclaimer and Export Compliance
7053289f6aSNate Lawson  * provision in the documentation and/or other materials provided with the
7153289f6aSNate Lawson  * distribution.
7253289f6aSNate Lawson  *
7353289f6aSNate Lawson  * 3.4. Intel retains all right, title, and interest in and to the Original
7453289f6aSNate Lawson  * Intel Code.
7553289f6aSNate Lawson  *
7653289f6aSNate Lawson  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7753289f6aSNate Lawson  * Intel shall be used in advertising or otherwise to promote the sale, use or
7853289f6aSNate Lawson  * other dealings in products derived from or relating to the Covered Code
7953289f6aSNate Lawson  * without prior written authorization from Intel.
8053289f6aSNate Lawson  *
8153289f6aSNate Lawson  * 4. Disclaimer and Export Compliance
8253289f6aSNate Lawson  *
8353289f6aSNate Lawson  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8453289f6aSNate Lawson  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8553289f6aSNate Lawson  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8653289f6aSNate Lawson  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8753289f6aSNate Lawson  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8853289f6aSNate Lawson  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
8953289f6aSNate Lawson  * PARTICULAR PURPOSE.
9053289f6aSNate Lawson  *
9153289f6aSNate Lawson  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9253289f6aSNate Lawson  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9353289f6aSNate Lawson  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9453289f6aSNate Lawson  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9553289f6aSNate Lawson  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9653289f6aSNate Lawson  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9753289f6aSNate Lawson  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9853289f6aSNate Lawson  * LIMITED REMEDY.
9953289f6aSNate Lawson  *
10053289f6aSNate Lawson  * 4.3. Licensee shall not export, either directly or indirectly, any of this
10153289f6aSNate Lawson  * software or system incorporating such software without first obtaining any
10253289f6aSNate Lawson  * required license or other approval from the U. S. Department of Commerce or
10353289f6aSNate Lawson  * any other agency or department of the United States Government.  In the
10453289f6aSNate Lawson  * event Licensee exports any such software from the United States or
10553289f6aSNate Lawson  * re-exports any such software from a foreign destination, Licensee shall
10653289f6aSNate Lawson  * ensure that the distribution and export/re-export of the software is in
10753289f6aSNate Lawson  * compliance with all laws, regulations, orders, or other restrictions of the
10853289f6aSNate Lawson  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
10953289f6aSNate Lawson  * any of its subsidiaries will export/re-export any technical data, process,
11053289f6aSNate Lawson  * software, or service, directly or indirectly, to any country for which the
11153289f6aSNate Lawson  * United States government or any agency thereof requires an export license,
11253289f6aSNate Lawson  * other governmental approval, or letter of assurance, without first obtaining
11353289f6aSNate Lawson  * such license, approval or letter.
11453289f6aSNate Lawson  *
11553289f6aSNate Lawson  *****************************************************************************/
11653289f6aSNate Lawson 
11753289f6aSNate Lawson 
11853289f6aSNate Lawson #define _DECLARE_GLOBALS
11953289f6aSNate Lawson 
120a9f12690SJung-uk Kim #include "aslcompiler.h"
121a9f12690SJung-uk Kim #include "acapps.h"
12253289f6aSNate Lawson 
12353289f6aSNate Lawson #ifdef _DEBUG
12453289f6aSNate Lawson #include <crtdbg.h>
12553289f6aSNate Lawson #endif
12653289f6aSNate Lawson 
12753289f6aSNate Lawson #define _COMPONENT          ACPI_COMPILER
12853289f6aSNate Lawson         ACPI_MODULE_NAME    ("aslmain")
12953289f6aSNate Lawson 
130fba7fc7eSJung-uk Kim /* Local prototypes */
131fba7fc7eSJung-uk Kim 
132fba7fc7eSJung-uk Kim static void
133fba7fc7eSJung-uk Kim Options (
134fba7fc7eSJung-uk Kim     void);
135fba7fc7eSJung-uk Kim 
136fba7fc7eSJung-uk Kim static void
137fba7fc7eSJung-uk Kim HelpMessage (
138fba7fc7eSJung-uk Kim     void);
139fba7fc7eSJung-uk Kim 
140fba7fc7eSJung-uk Kim static void
141fba7fc7eSJung-uk Kim Usage (
142fba7fc7eSJung-uk Kim     void);
143fba7fc7eSJung-uk Kim 
144fba7fc7eSJung-uk Kim static void
145fba7fc7eSJung-uk Kim AslInitialize (
146fba7fc7eSJung-uk Kim     void);
147fba7fc7eSJung-uk Kim 
148a9f12690SJung-uk Kim static int
149fba7fc7eSJung-uk Kim AslCommandLine (
150fba7fc7eSJung-uk Kim     int                     argc,
151fba7fc7eSJung-uk Kim     char                    **argv);
152fba7fc7eSJung-uk Kim 
15353289f6aSNate Lawson 
15453289f6aSNate Lawson /*******************************************************************************
15553289f6aSNate Lawson  *
15653289f6aSNate Lawson  * FUNCTION:    Options
15753289f6aSNate Lawson  *
15853289f6aSNate Lawson  * PARAMETERS:  None
15953289f6aSNate Lawson  *
16053289f6aSNate Lawson  * RETURN:      None
16153289f6aSNate Lawson  *
16253289f6aSNate Lawson  * DESCRIPTION: Display option help message
16353289f6aSNate Lawson  *
16453289f6aSNate Lawson  ******************************************************************************/
16553289f6aSNate Lawson 
166fba7fc7eSJung-uk Kim static void
16753289f6aSNate Lawson Options (
16853289f6aSNate Lawson     void)
16953289f6aSNate Lawson {
17053289f6aSNate Lawson 
17153289f6aSNate Lawson     printf ("General Output:\n");
172a9f12690SJung-uk Kim     printf ("  -p <prefix>    Specify path/filename prefix for all output files\n");
173a9f12690SJung-uk Kim     printf ("  -va            Disable all errors and warnings (summary only)\n");
17453289f6aSNate Lawson     printf ("  -vi            Less verbose errors and warnings for use with IDEs\n");
17553289f6aSNate Lawson     printf ("  -vo            Enable optimization comments\n");
17653289f6aSNate Lawson     printf ("  -vr            Disable remarks\n");
17753289f6aSNate Lawson     printf ("  -vs            Disable signon\n");
1781a39cfb0SJung-uk Kim     printf ("  -w<1|2|3>      Set warning reporting level\n");
17953289f6aSNate Lawson 
180c8466860SMark Santcroos     printf ("\nAML Output Files:\n");
18153289f6aSNate Lawson     printf ("  -s<a|c>        Create AML in assembler or C source file (*.asm or *.c)\n");
18253289f6aSNate Lawson     printf ("  -i<a|c>        Create assembler or C include file (*.inc or *.h)\n");
18353289f6aSNate Lawson     printf ("  -t<a|c>        Create AML in assembler or C hex table (*.hex)\n");
18453289f6aSNate Lawson 
185c8466860SMark Santcroos     printf ("\nAML Code Generation:\n");
18653289f6aSNate Lawson     printf ("  -oa            Disable all optimizations (compatibility mode)\n");
18753289f6aSNate Lawson     printf ("  -of            Disable constant folding\n");
18853289f6aSNate Lawson     printf ("  -oi            Disable integer optimization to Zero/One/Ones\n");
18953289f6aSNate Lawson     printf ("  -on            Disable named reference string optimization\n");
190c8466860SMark Santcroos     printf ("  -r<Revision>   Override table header Revision (1-255)\n");
19153289f6aSNate Lawson 
19253289f6aSNate Lawson     printf ("\nListings:\n");
19353289f6aSNate Lawson     printf ("  -l             Create mixed listing file (ASL source and AML) (*.lst)\n");
19453289f6aSNate Lawson     printf ("  -ln            Create namespace file (*.nsp)\n");
19553289f6aSNate Lawson     printf ("  -ls            Create combined source file (expanded includes) (*.src)\n");
19653289f6aSNate Lawson 
19753289f6aSNate Lawson     printf ("\nAML Disassembler:\n");
1981a39cfb0SJung-uk Kim     printf ("  -d  [file]     Disassemble or decode binary ACPI table to file (*.dsl)\n");
19953289f6aSNate Lawson     printf ("  -dc [file]     Disassemble AML and immediately compile it\n");
20053289f6aSNate Lawson     printf ("                 (Obtain DSDT from current system if no input file)\n");
201a9f12690SJung-uk Kim     printf ("  -e  [f1,f2]    Include ACPI table(s) for external symbol resolution\n");
202fba7fc7eSJung-uk Kim     printf ("  -2             Emit ACPI 2.0 compatible ASL code\n");
20353289f6aSNate Lawson     printf ("  -g             Get ACPI tables and write to files (*.dat)\n");
20453289f6aSNate Lawson 
20553289f6aSNate Lawson     printf ("\nHelp:\n");
20653289f6aSNate Lawson     printf ("  -h             Additional help and compiler debug options\n");
20753289f6aSNate Lawson     printf ("  -hc            Display operators allowed in constant expressions\n");
20853289f6aSNate Lawson     printf ("  -hr            Display ACPI reserved method names\n");
20953289f6aSNate Lawson }
21053289f6aSNate Lawson 
21153289f6aSNate Lawson 
21253289f6aSNate Lawson /*******************************************************************************
21353289f6aSNate Lawson  *
214fba7fc7eSJung-uk Kim  * FUNCTION:    HelpMessage
21553289f6aSNate Lawson  *
21653289f6aSNate Lawson  * PARAMETERS:  None
21753289f6aSNate Lawson  *
21853289f6aSNate Lawson  * RETURN:      None
21953289f6aSNate Lawson  *
22053289f6aSNate Lawson  * DESCRIPTION: Display help message
22153289f6aSNate Lawson  *
22253289f6aSNate Lawson  ******************************************************************************/
22353289f6aSNate Lawson 
224fba7fc7eSJung-uk Kim static void
22553289f6aSNate Lawson HelpMessage (
22653289f6aSNate Lawson     void)
22753289f6aSNate Lawson {
22853289f6aSNate Lawson 
22953289f6aSNate Lawson     printf ("AML output filename generation:\n");
23053289f6aSNate Lawson     printf ("  Output filenames are generated by appending an extension to a common\n");
23153289f6aSNate Lawson     printf ("  filename prefix.  The filename prefix is obtained via one of the\n");
23253289f6aSNate Lawson     printf ("  following methods (in priority order):\n");
23353289f6aSNate Lawson     printf ("    1) The -p option specifies the prefix\n");
23453289f6aSNate Lawson     printf ("    2) The prefix of the AMLFileName in the ASL Definition Block\n");
23553289f6aSNate Lawson     printf ("    3) The prefix of the input filename\n");
23653289f6aSNate Lawson     printf ("\n");
23753289f6aSNate Lawson 
23853289f6aSNate Lawson     Options ();
23953289f6aSNate Lawson 
2401a39cfb0SJung-uk Kim     printf ("\nCompiler/Disassembler Debug Options:\n");
24153289f6aSNate Lawson     printf ("  -b<p|t|b>      Create compiler debug/trace file (*.txt)\n");
24253289f6aSNate Lawson     printf ("                   Types: Parse/Tree/Both\n");
24353289f6aSNate Lawson     printf ("  -f             Ignore errors, force creation of AML output file(s)\n");
24453289f6aSNate Lawson     printf ("  -c             Parse only, no output generation\n");
24553289f6aSNate Lawson     printf ("  -ot            Display compile times\n");
24653289f6aSNate Lawson     printf ("  -x<level>      Set debug level for trace output\n");
24753289f6aSNate Lawson }
24853289f6aSNate Lawson 
24953289f6aSNate Lawson 
25053289f6aSNate Lawson /*******************************************************************************
25153289f6aSNate Lawson  *
25253289f6aSNate Lawson  * FUNCTION:    Usage
25353289f6aSNate Lawson  *
25453289f6aSNate Lawson  * PARAMETERS:  None
25553289f6aSNate Lawson  *
25653289f6aSNate Lawson  * RETURN:      None
25753289f6aSNate Lawson  *
25853289f6aSNate Lawson  * DESCRIPTION: Display usage and option message
25953289f6aSNate Lawson  *
26053289f6aSNate Lawson  ******************************************************************************/
26153289f6aSNate Lawson 
262fba7fc7eSJung-uk Kim static void
26353289f6aSNate Lawson Usage (
26453289f6aSNate Lawson     void)
26553289f6aSNate Lawson {
26653289f6aSNate Lawson 
267a9f12690SJung-uk Kim     printf ("Usage:    %s [Options] [Files]\n\n", CompilerName);
26853289f6aSNate Lawson     Options ();
26953289f6aSNate Lawson }
27053289f6aSNate Lawson 
27153289f6aSNate Lawson 
27253289f6aSNate Lawson /*******************************************************************************
27353289f6aSNate Lawson  *
27453289f6aSNate Lawson  * FUNCTION:    AslInitialize
27553289f6aSNate Lawson  *
27653289f6aSNate Lawson  * PARAMETERS:  None
27753289f6aSNate Lawson  *
27853289f6aSNate Lawson  * RETURN:      None
27953289f6aSNate Lawson  *
28053289f6aSNate Lawson  * DESCRIPTION: Initialize compiler globals
28153289f6aSNate Lawson  *
28253289f6aSNate Lawson  ******************************************************************************/
28353289f6aSNate Lawson 
284fba7fc7eSJung-uk Kim static void
285fba7fc7eSJung-uk Kim AslInitialize (
286fba7fc7eSJung-uk Kim     void)
28753289f6aSNate Lawson {
28853289f6aSNate Lawson     UINT32                  i;
28953289f6aSNate Lawson 
29053289f6aSNate Lawson 
29153289f6aSNate Lawson #ifdef _DEBUG
29253289f6aSNate Lawson     _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0));
29353289f6aSNate Lawson #endif
29453289f6aSNate Lawson 
29553289f6aSNate Lawson     AcpiDbgLevel = 0;
29653289f6aSNate Lawson 
29753289f6aSNate Lawson     for (i = 0; i < ASL_NUM_FILES; i++)
29853289f6aSNate Lawson     {
29953289f6aSNate Lawson         Gbl_Files[i].Handle = NULL;
30053289f6aSNate Lawson         Gbl_Files[i].Filename = NULL;
30153289f6aSNate Lawson     }
30253289f6aSNate Lawson 
30353289f6aSNate Lawson     Gbl_Files[ASL_FILE_STDOUT].Handle   = stdout;
30453289f6aSNate Lawson     Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
30553289f6aSNate Lawson 
30653289f6aSNate Lawson     Gbl_Files[ASL_FILE_STDERR].Handle   = stderr;
30753289f6aSNate Lawson     Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
30853289f6aSNate Lawson }
30953289f6aSNate Lawson 
31053289f6aSNate Lawson 
31153289f6aSNate Lawson /*******************************************************************************
31253289f6aSNate Lawson  *
31353289f6aSNate Lawson  * FUNCTION:    AslCommandLine
31453289f6aSNate Lawson  *
31553289f6aSNate Lawson  * PARAMETERS:  argc/argv
31653289f6aSNate Lawson  *
31753289f6aSNate Lawson  * RETURN:      None
31853289f6aSNate Lawson  *
31953289f6aSNate Lawson  * DESCRIPTION: Command line processing
32053289f6aSNate Lawson  *
32153289f6aSNate Lawson  ******************************************************************************/
32253289f6aSNate Lawson 
323a9f12690SJung-uk Kim static int
32453289f6aSNate Lawson AslCommandLine (
32553289f6aSNate Lawson     int                     argc,
32653289f6aSNate Lawson     char                    **argv)
32753289f6aSNate Lawson {
32853289f6aSNate Lawson     BOOLEAN                 BadCommandLine = FALSE;
329a9f12690SJung-uk Kim     int                     j;
33053289f6aSNate Lawson 
33153289f6aSNate Lawson 
33253289f6aSNate Lawson     /* Minimum command line contains at least one option or an input file */
33353289f6aSNate Lawson 
33453289f6aSNate Lawson     if (argc < 2)
33553289f6aSNate Lawson     {
33653289f6aSNate Lawson         AslCompilerSignon (ASL_FILE_STDOUT);
33753289f6aSNate Lawson         Usage ();
33853289f6aSNate Lawson         exit (1);
33953289f6aSNate Lawson     }
34053289f6aSNate Lawson 
34153289f6aSNate Lawson     /* Get the command line options */
34253289f6aSNate Lawson 
3431a39cfb0SJung-uk Kim     while ((j = AcpiGetopt (argc, argv, "2b:cd^e:fgh^i^l^o:p:r:s:t:v:w:x:")) != EOF) switch (j)
34453289f6aSNate Lawson     {
345fba7fc7eSJung-uk Kim     case '2':
346fba7fc7eSJung-uk Kim         Gbl_Acpi2 = TRUE;
347fba7fc7eSJung-uk Kim         break;
348fba7fc7eSJung-uk Kim 
349fba7fc7eSJung-uk Kim 
35053289f6aSNate Lawson     case 'b':
35153289f6aSNate Lawson 
35253289f6aSNate Lawson         switch (AcpiGbl_Optarg[0])
35353289f6aSNate Lawson         {
35453289f6aSNate Lawson         case 'b':
35553289f6aSNate Lawson             AslCompilerdebug = 1; /* same as yydebug */
35653289f6aSNate Lawson             break;
35753289f6aSNate Lawson 
35853289f6aSNate Lawson         case 'p':
35953289f6aSNate Lawson             AslCompilerdebug = 1; /* same as yydebug */
36053289f6aSNate Lawson             break;
36153289f6aSNate Lawson 
36253289f6aSNate Lawson         case 't':
36353289f6aSNate Lawson             break;
36453289f6aSNate Lawson 
36553289f6aSNate Lawson         default:
36653289f6aSNate Lawson             printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
36753289f6aSNate Lawson             BadCommandLine = TRUE;
36853289f6aSNate Lawson             break;
36953289f6aSNate Lawson         }
37053289f6aSNate Lawson 
37153289f6aSNate Lawson         /* Produce debug output file */
37253289f6aSNate Lawson 
37353289f6aSNate Lawson         Gbl_DebugFlag = TRUE;
37453289f6aSNate Lawson         break;
37553289f6aSNate Lawson 
37653289f6aSNate Lawson 
37753289f6aSNate Lawson     case 'c':
37853289f6aSNate Lawson 
37953289f6aSNate Lawson         /* Parse only */
38053289f6aSNate Lawson 
38153289f6aSNate Lawson         Gbl_ParseOnlyFlag = TRUE;
38253289f6aSNate Lawson         break;
38353289f6aSNate Lawson 
38453289f6aSNate Lawson 
38553289f6aSNate Lawson     case 'd':
38653289f6aSNate Lawson         switch (AcpiGbl_Optarg[0])
38753289f6aSNate Lawson         {
38853289f6aSNate Lawson         case '^':
389a9f12690SJung-uk Kim             Gbl_DoCompile = FALSE;
39053289f6aSNate Lawson             break;
39153289f6aSNate Lawson 
39253289f6aSNate Lawson         case 'c':
39353289f6aSNate Lawson             break;
39453289f6aSNate Lawson 
39553289f6aSNate Lawson         default:
39653289f6aSNate Lawson             printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
39753289f6aSNate Lawson             BadCommandLine = TRUE;
39853289f6aSNate Lawson             break;
39953289f6aSNate Lawson         }
40053289f6aSNate Lawson 
40153289f6aSNate Lawson         Gbl_DisasmFlag = TRUE;
40253289f6aSNate Lawson         break;
40353289f6aSNate Lawson 
40453289f6aSNate Lawson 
40553289f6aSNate Lawson     case 'e':
4061a39cfb0SJung-uk Kim         Gbl_ExternalFilename = AcpiGbl_Optarg;
40753289f6aSNate Lawson         break;
40853289f6aSNate Lawson 
40953289f6aSNate Lawson 
41053289f6aSNate Lawson     case 'f':
41153289f6aSNate Lawson 
41253289f6aSNate Lawson         /* Ignore errors and force creation of aml file */
41353289f6aSNate Lawson 
41453289f6aSNate Lawson         Gbl_IgnoreErrors = TRUE;
41553289f6aSNate Lawson         break;
41653289f6aSNate Lawson 
41753289f6aSNate Lawson 
41853289f6aSNate Lawson     case 'g':
41953289f6aSNate Lawson 
42053289f6aSNate Lawson         /* Get all ACPI tables */
42153289f6aSNate Lawson 
42253289f6aSNate Lawson         Gbl_GetAllTables = TRUE;
423a9f12690SJung-uk Kim         Gbl_DoCompile = FALSE;
42453289f6aSNate Lawson         break;
42553289f6aSNate Lawson 
42653289f6aSNate Lawson 
42753289f6aSNate Lawson     case 'h':
42853289f6aSNate Lawson 
42953289f6aSNate Lawson         switch (AcpiGbl_Optarg[0])
43053289f6aSNate Lawson         {
43153289f6aSNate Lawson         case '^':
43253289f6aSNate Lawson             HelpMessage ();
43353289f6aSNate Lawson             exit (0);
43453289f6aSNate Lawson 
43553289f6aSNate Lawson         case 'c':
43653289f6aSNate Lawson             UtDisplayConstantOpcodes ();
43753289f6aSNate Lawson             exit (0);
43853289f6aSNate Lawson 
43953289f6aSNate Lawson         case 'r':
44053289f6aSNate Lawson             /* reserved names */
44153289f6aSNate Lawson 
44253289f6aSNate Lawson             MpDisplayReservedNames ();
44353289f6aSNate Lawson             exit (0);
44453289f6aSNate Lawson 
44553289f6aSNate Lawson         default:
44653289f6aSNate Lawson             printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
44753289f6aSNate Lawson             BadCommandLine = TRUE;
44853289f6aSNate Lawson             break;
44953289f6aSNate Lawson         }
45053289f6aSNate Lawson         break;
45153289f6aSNate Lawson 
45253289f6aSNate Lawson 
45353289f6aSNate Lawson     case 'i':
45453289f6aSNate Lawson 
45553289f6aSNate Lawson         switch (AcpiGbl_Optarg[0])
45653289f6aSNate Lawson         {
45753289f6aSNate Lawson         case 'a':
45853289f6aSNate Lawson 
45953289f6aSNate Lawson             /* Produce assembly code include file */
46053289f6aSNate Lawson 
46153289f6aSNate Lawson             Gbl_AsmIncludeOutputFlag = TRUE;
46253289f6aSNate Lawson             break;
46353289f6aSNate Lawson 
46453289f6aSNate Lawson         case 'c':
46553289f6aSNate Lawson 
46653289f6aSNate Lawson             /* Produce C include file */
46753289f6aSNate Lawson 
46853289f6aSNate Lawson             Gbl_C_IncludeOutputFlag = TRUE;
46953289f6aSNate Lawson             break;
47053289f6aSNate Lawson 
47153289f6aSNate Lawson         default:
47253289f6aSNate Lawson             printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
47353289f6aSNate Lawson             BadCommandLine = TRUE;
47453289f6aSNate Lawson             break;
47553289f6aSNate Lawson         }
47653289f6aSNate Lawson         break;
47753289f6aSNate Lawson 
47853289f6aSNate Lawson 
47953289f6aSNate Lawson     case 'l':
48053289f6aSNate Lawson 
48153289f6aSNate Lawson         switch (AcpiGbl_Optarg[0])
48253289f6aSNate Lawson         {
48353289f6aSNate Lawson         case '^':
48453289f6aSNate Lawson             /* Produce listing file (Mixed source/aml) */
48553289f6aSNate Lawson 
48653289f6aSNate Lawson             Gbl_ListingFlag = TRUE;
48753289f6aSNate Lawson             break;
48853289f6aSNate Lawson 
48953289f6aSNate Lawson         case 'n':
49053289f6aSNate Lawson             /* Produce namespace file */
49153289f6aSNate Lawson 
49253289f6aSNate Lawson             Gbl_NsOutputFlag = TRUE;
49353289f6aSNate Lawson             break;
49453289f6aSNate Lawson 
49553289f6aSNate Lawson         case 's':
49653289f6aSNate Lawson             /* Produce combined source file */
49753289f6aSNate Lawson 
49853289f6aSNate Lawson             Gbl_SourceOutputFlag = TRUE;
49953289f6aSNate Lawson             break;
50053289f6aSNate Lawson 
50153289f6aSNate Lawson         default:
50253289f6aSNate Lawson             printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
50353289f6aSNate Lawson             BadCommandLine = TRUE;
50453289f6aSNate Lawson             break;
50553289f6aSNate Lawson         }
50653289f6aSNate Lawson         break;
50753289f6aSNate Lawson 
50853289f6aSNate Lawson 
50953289f6aSNate Lawson     case 'o':
51053289f6aSNate Lawson 
51153289f6aSNate Lawson         switch (AcpiGbl_Optarg[0])
51253289f6aSNate Lawson         {
51353289f6aSNate Lawson         case 'a':
51453289f6aSNate Lawson 
51553289f6aSNate Lawson             /* Disable all optimizations */
51653289f6aSNate Lawson 
51753289f6aSNate Lawson             Gbl_FoldConstants = FALSE;
51853289f6aSNate Lawson             Gbl_IntegerOptimizationFlag = FALSE;
51953289f6aSNate Lawson             Gbl_ReferenceOptimizationFlag = FALSE;
52053289f6aSNate Lawson             break;
52153289f6aSNate Lawson 
52253289f6aSNate Lawson         case 'f':
52353289f6aSNate Lawson 
52453289f6aSNate Lawson             /* Disable folding on "normal" expressions */
52553289f6aSNate Lawson 
52653289f6aSNate Lawson             Gbl_FoldConstants = FALSE;
52753289f6aSNate Lawson             break;
52853289f6aSNate Lawson 
52953289f6aSNate Lawson         case 'i':
53053289f6aSNate Lawson 
53153289f6aSNate Lawson             /* Disable integer optimization to constants */
53253289f6aSNate Lawson 
53353289f6aSNate Lawson             Gbl_IntegerOptimizationFlag = FALSE;
53453289f6aSNate Lawson             break;
53553289f6aSNate Lawson 
53653289f6aSNate Lawson         case 'n':
53753289f6aSNate Lawson 
53853289f6aSNate Lawson             /* Disable named reference optimization */
53953289f6aSNate Lawson 
54053289f6aSNate Lawson             Gbl_ReferenceOptimizationFlag = FALSE;
54153289f6aSNate Lawson             break;
54253289f6aSNate Lawson 
54353289f6aSNate Lawson         case 't':
54453289f6aSNate Lawson 
54553289f6aSNate Lawson             /* Display compile time(s) */
54653289f6aSNate Lawson 
54753289f6aSNate Lawson             Gbl_CompileTimesFlag = TRUE;
54853289f6aSNate Lawson             break;
54953289f6aSNate Lawson 
55053289f6aSNate Lawson         default:
55153289f6aSNate Lawson             printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
55253289f6aSNate Lawson             BadCommandLine = TRUE;
55353289f6aSNate Lawson             break;
55453289f6aSNate Lawson         }
55553289f6aSNate Lawson         break;
55653289f6aSNate Lawson 
55753289f6aSNate Lawson 
55853289f6aSNate Lawson     case 'p':
55953289f6aSNate Lawson 
56053289f6aSNate Lawson         /* Override default AML output filename */
56153289f6aSNate Lawson 
56253289f6aSNate Lawson         Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
56353289f6aSNate Lawson         Gbl_UseDefaultAmlFilename = FALSE;
56453289f6aSNate Lawson         break;
56553289f6aSNate Lawson 
56653289f6aSNate Lawson 
56753289f6aSNate Lawson     case 'r':
568c8466860SMark Santcroos         Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
56953289f6aSNate Lawson         break;
57053289f6aSNate Lawson 
57153289f6aSNate Lawson 
57253289f6aSNate Lawson     case 's':
57353289f6aSNate Lawson 
57453289f6aSNate Lawson         switch (AcpiGbl_Optarg[0])
57553289f6aSNate Lawson         {
57653289f6aSNate Lawson         case 'a':
57753289f6aSNate Lawson 
57853289f6aSNate Lawson             /* Produce assembly code output file */
57953289f6aSNate Lawson 
58053289f6aSNate Lawson             Gbl_AsmOutputFlag = TRUE;
58153289f6aSNate Lawson             break;
58253289f6aSNate Lawson 
58353289f6aSNate Lawson         case 'c':
58453289f6aSNate Lawson 
58553289f6aSNate Lawson             /* Produce C hex output file */
58653289f6aSNate Lawson 
58753289f6aSNate Lawson             Gbl_C_OutputFlag = TRUE;
58853289f6aSNate Lawson             break;
58953289f6aSNate Lawson 
59053289f6aSNate Lawson         default:
59153289f6aSNate Lawson             printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
59253289f6aSNate Lawson             BadCommandLine = TRUE;
59353289f6aSNate Lawson             break;
59453289f6aSNate Lawson         }
59553289f6aSNate Lawson         break;
59653289f6aSNate Lawson 
59753289f6aSNate Lawson 
59853289f6aSNate Lawson     case 't':
59953289f6aSNate Lawson 
60053289f6aSNate Lawson         /* Produce hex table output file */
60153289f6aSNate Lawson 
60253289f6aSNate Lawson         switch (AcpiGbl_Optarg[0])
60353289f6aSNate Lawson         {
60453289f6aSNate Lawson         case 'a':
60553289f6aSNate Lawson             Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
60653289f6aSNate Lawson             break;
60753289f6aSNate Lawson 
60853289f6aSNate Lawson         case 'c':
60953289f6aSNate Lawson             Gbl_HexOutputFlag = HEX_OUTPUT_C;
61053289f6aSNate Lawson             break;
61153289f6aSNate Lawson 
61253289f6aSNate Lawson         default:
61353289f6aSNate Lawson             printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
61453289f6aSNate Lawson             BadCommandLine = TRUE;
61553289f6aSNate Lawson             break;
61653289f6aSNate Lawson         }
61753289f6aSNate Lawson         break;
61853289f6aSNate Lawson 
61953289f6aSNate Lawson 
62053289f6aSNate Lawson     case 'v':
62153289f6aSNate Lawson 
62253289f6aSNate Lawson         switch (AcpiGbl_Optarg[0])
62353289f6aSNate Lawson         {
624a9f12690SJung-uk Kim         case 'a':
625a9f12690SJung-uk Kim             /* Disable All error/warning messages */
626a9f12690SJung-uk Kim 
627a9f12690SJung-uk Kim             Gbl_NoErrors = TRUE;
628a9f12690SJung-uk Kim             break;
629a9f12690SJung-uk Kim 
63053289f6aSNate Lawson         case 'i':
63153289f6aSNate Lawson             /* Less verbose error messages */
63253289f6aSNate Lawson 
63353289f6aSNate Lawson             Gbl_VerboseErrors = FALSE;
63453289f6aSNate Lawson             break;
63553289f6aSNate Lawson 
63653289f6aSNate Lawson         case 'o':
63753289f6aSNate Lawson             Gbl_DisplayOptimizations = TRUE;
63853289f6aSNate Lawson             break;
63953289f6aSNate Lawson 
64053289f6aSNate Lawson         case 'r':
64153289f6aSNate Lawson             Gbl_DisplayRemarks = FALSE;
64253289f6aSNate Lawson             break;
64353289f6aSNate Lawson 
64453289f6aSNate Lawson         case 's':
645a9f12690SJung-uk Kim             Gbl_DoSignon = FALSE;
64653289f6aSNate Lawson             break;
64753289f6aSNate Lawson 
64853289f6aSNate Lawson         default:
64953289f6aSNate Lawson             printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
65053289f6aSNate Lawson             BadCommandLine = TRUE;
65153289f6aSNate Lawson             break;
65253289f6aSNate Lawson         }
65353289f6aSNate Lawson         break;
65453289f6aSNate Lawson 
65553289f6aSNate Lawson 
6561a39cfb0SJung-uk Kim     case 'w': /* Set warning levels */
6571a39cfb0SJung-uk Kim 
6581a39cfb0SJung-uk Kim         switch (AcpiGbl_Optarg[0])
6591a39cfb0SJung-uk Kim         {
6601a39cfb0SJung-uk Kim         case '1':
6611a39cfb0SJung-uk Kim             Gbl_WarningLevel = ASL_WARNING;
6621a39cfb0SJung-uk Kim             break;
6631a39cfb0SJung-uk Kim 
6641a39cfb0SJung-uk Kim         case '2':
6651a39cfb0SJung-uk Kim             Gbl_WarningLevel = ASL_WARNING2;
6661a39cfb0SJung-uk Kim             break;
6671a39cfb0SJung-uk Kim 
6681a39cfb0SJung-uk Kim         case '3':
6691a39cfb0SJung-uk Kim             Gbl_WarningLevel = ASL_WARNING3;
6701a39cfb0SJung-uk Kim             break;
6711a39cfb0SJung-uk Kim 
6721a39cfb0SJung-uk Kim         default:
6731a39cfb0SJung-uk Kim             printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
6741a39cfb0SJung-uk Kim             BadCommandLine = TRUE;
6751a39cfb0SJung-uk Kim             break;
6761a39cfb0SJung-uk Kim         }
6771a39cfb0SJung-uk Kim         break;
6781a39cfb0SJung-uk Kim 
6791a39cfb0SJung-uk Kim 
68053289f6aSNate Lawson     case 'x':
68153289f6aSNate Lawson 
68253289f6aSNate Lawson         AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
68353289f6aSNate Lawson         break;
68453289f6aSNate Lawson 
68553289f6aSNate Lawson 
68653289f6aSNate Lawson     default:
68753289f6aSNate Lawson 
68853289f6aSNate Lawson         BadCommandLine = TRUE;
68953289f6aSNate Lawson         break;
69053289f6aSNate Lawson     }
69153289f6aSNate Lawson 
69253289f6aSNate Lawson     /* Next parameter must be the input filename */
69353289f6aSNate Lawson 
694a9f12690SJung-uk Kim     if (!argv[AcpiGbl_Optind] &&
695fba7fc7eSJung-uk Kim         !Gbl_DisasmFlag &&
696fba7fc7eSJung-uk Kim         !Gbl_GetAllTables)
69753289f6aSNate Lawson     {
69853289f6aSNate Lawson         printf ("Missing input filename\n");
69953289f6aSNate Lawson         BadCommandLine = TRUE;
70053289f6aSNate Lawson     }
70153289f6aSNate Lawson 
702a9f12690SJung-uk Kim     if (Gbl_DoSignon)
70353289f6aSNate Lawson     {
70453289f6aSNate Lawson         AslCompilerSignon (ASL_FILE_STDOUT);
70553289f6aSNate Lawson     }
70653289f6aSNate Lawson 
70753289f6aSNate Lawson     /* Abort if anything went wrong on the command line */
70853289f6aSNate Lawson 
70953289f6aSNate Lawson     if (BadCommandLine)
71053289f6aSNate Lawson     {
71153289f6aSNate Lawson         printf ("\n");
71253289f6aSNate Lawson         Usage ();
71353289f6aSNate Lawson         exit (1);
71453289f6aSNate Lawson     }
71553289f6aSNate Lawson 
716a9f12690SJung-uk Kim     return (AcpiGbl_Optind);
71753289f6aSNate Lawson }
71853289f6aSNate Lawson 
71953289f6aSNate Lawson 
72053289f6aSNate Lawson /*******************************************************************************
72153289f6aSNate Lawson  *
72253289f6aSNate Lawson  * FUNCTION:    main
72353289f6aSNate Lawson  *
72453289f6aSNate Lawson  * PARAMETERS:  Standard argc/argv
72553289f6aSNate Lawson  *
72653289f6aSNate Lawson  * RETURN:      Program termination code
72753289f6aSNate Lawson  *
72853289f6aSNate Lawson  * DESCRIPTION: C main routine for the Asl Compiler. Handle command line
729a9f12690SJung-uk Kim  *              options and begin the compile for each file on the command line
73053289f6aSNate Lawson  *
73153289f6aSNate Lawson  ******************************************************************************/
73253289f6aSNate Lawson 
73353289f6aSNate Lawson int ACPI_SYSTEM_XFACE
73453289f6aSNate Lawson main (
73553289f6aSNate Lawson     int                     argc,
73653289f6aSNate Lawson     char                    **argv)
73753289f6aSNate Lawson {
73853289f6aSNate Lawson     ACPI_STATUS             Status;
739a9f12690SJung-uk Kim     int                     Index;
74053289f6aSNate Lawson 
74153289f6aSNate Lawson 
742fba7fc7eSJung-uk Kim #ifdef _DEBUG
743fba7fc7eSJung-uk Kim     _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF |
744fba7fc7eSJung-uk Kim                     _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
745fba7fc7eSJung-uk Kim #endif
746fba7fc7eSJung-uk Kim 
74753289f6aSNate Lawson     /* Init and command line */
74853289f6aSNate Lawson 
74953289f6aSNate Lawson     AslInitialize ();
750a9f12690SJung-uk Kim     Index = AslCommandLine (argc, argv);
75153289f6aSNate Lawson 
752a9f12690SJung-uk Kim     /* Options that have no additional parameters or pathnames */
753a9f12690SJung-uk Kim 
754a9f12690SJung-uk Kim     if (Gbl_GetAllTables)
755a9f12690SJung-uk Kim     {
756a9f12690SJung-uk Kim         Status = AslDoOneFile (NULL);
757fba7fc7eSJung-uk Kim         if (ACPI_FAILURE (Status))
758fba7fc7eSJung-uk Kim         {
759a9f12690SJung-uk Kim             return (-1);
760a9f12690SJung-uk Kim         }
761a9f12690SJung-uk Kim         return (0);
762fba7fc7eSJung-uk Kim     }
76353289f6aSNate Lawson 
764a9f12690SJung-uk Kim     /* Process each pathname/filename in the list, with possible wildcards */
765a9f12690SJung-uk Kim 
766a9f12690SJung-uk Kim     while (argv[Index])
76753289f6aSNate Lawson     {
768a9f12690SJung-uk Kim         Status = AslDoOnePathname (argv[Index]);
76953289f6aSNate Lawson         if (ACPI_FAILURE (Status))
77053289f6aSNate Lawson         {
771a9f12690SJung-uk Kim             return (-1);
77253289f6aSNate Lawson         }
77353289f6aSNate Lawson 
774a9f12690SJung-uk Kim         Index++;
77553289f6aSNate Lawson     }
77653289f6aSNate Lawson 
77753289f6aSNate Lawson     return (0);
77853289f6aSNate Lawson }
77953289f6aSNate Lawson 
78053289f6aSNate Lawson 
781