aslmain.c revision 234623
11590Srgrimes
21590Srgrimes/******************************************************************************
31590Srgrimes *
41590Srgrimes * Module Name: aslmain - compiler main and utilities
51590Srgrimes *
61590Srgrimes *****************************************************************************/
71590Srgrimes
81590Srgrimes/*
91590Srgrimes * Copyright (C) 2000 - 2012, Intel Corp.
101590Srgrimes * All rights reserved.
111590Srgrimes *
121590Srgrimes * Redistribution and use in source and binary forms, with or without
131590Srgrimes * modification, are permitted provided that the following conditions
141590Srgrimes * are met:
151590Srgrimes * 1. Redistributions of source code must retain the above copyright
161590Srgrimes *    notice, this list of conditions, and the following disclaimer,
171590Srgrimes *    without modification.
181590Srgrimes * 2. Redistributions in binary form must reproduce at minimum a disclaimer
191590Srgrimes *    substantially similar to the "NO WARRANTY" disclaimer below
201590Srgrimes *    ("Disclaimer") and any redistribution must be conditioned upon
211590Srgrimes *    including a substantially similar Disclaimer requirement for further
221590Srgrimes *    binary redistribution.
231590Srgrimes * 3. Neither the names of the above-listed copyright holders nor the names
241590Srgrimes *    of any contributors may be used to endorse or promote products derived
251590Srgrimes *    from this software without specific prior written permission.
261590Srgrimes *
271590Srgrimes * Alternatively, this software may be distributed under the terms of the
281590Srgrimes * GNU General Public License ("GPL") version 2 as published by the Free
291590Srgrimes * Software Foundation.
301590Srgrimes *
3187693Smarkm * NO WARRANTY
3287693Smarkm * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3387693Smarkm * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3487693Smarkm * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
351590Srgrimes * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3687693Smarkm * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
371590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
381590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3987693Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
401590Srgrimes * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
411590Srgrimes * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4287693Smarkm * POSSIBILITY OF SUCH DAMAGES.
4387693Smarkm */
441590Srgrimes
451590Srgrimes
461590Srgrimes#define _DECLARE_GLOBALS
47282457Sbapt
481590Srgrimes#include <contrib/dev/acpica/compiler/aslcompiler.h>
4987693Smarkm#include <contrib/dev/acpica/include/acapps.h>
501590Srgrimes#include <contrib/dev/acpica/include/acdisasm.h>
511590Srgrimes
521590Srgrimes#ifdef _DEBUG
531590Srgrimes#include <crtdbg.h>
5492922Simp#endif
551590Srgrimes
56282457Sbapt#define _COMPONENT          ACPI_COMPILER
5736053Sjb        ACPI_MODULE_NAME    ("aslmain")
58282457Sbapt
591590Srgrimes/* Local prototypes */
601590Srgrimes
611590Srgrimesstatic void
621590SrgrimesOptions (
631590Srgrimes    void);
641590Srgrimes
651590Srgrimesstatic void
661590SrgrimesHelpMessage (
671590Srgrimes    void);
68282449Sbapt
691590Srgrimesstatic void
701590SrgrimesUsage (
711590Srgrimes    void);
721590Srgrimes
731590Srgrimesstatic void
741590SrgrimesAslInitialize (
751590Srgrimes    void);
761590Srgrimes
771590Srgrimesstatic int
781590SrgrimesAslCommandLine (
791590Srgrimes    int                     argc,
801590Srgrimes    char                    **argv);
811590Srgrimes
821590Srgrimesstatic int
831590SrgrimesAslDoOptions (
841590Srgrimes    int                     argc,
851590Srgrimes    char                    **argv,
861590Srgrimes    BOOLEAN                 IsResponseFile);
871590Srgrimes
881590Srgrimesstatic void
891590SrgrimesAslMergeOptionTokens (
901590Srgrimes    char                    *InBuffer,
911590Srgrimes    char                    *OutBuffer);
921590Srgrimes
931590Srgrimesstatic int
941590SrgrimesAslDoResponseFile (
951590Srgrimes    char                    *Filename);
961590Srgrimes
971590Srgrimes
981590Srgrimes#define ASL_TOKEN_SEPARATORS    " \t\n"
991590Srgrimes#define ASL_SUPPORTED_OPTIONS   "@:2b|c|d^D:e:fgh^i|I:l^mno|p:P^r:s|t|T:G^v|w|x:z"
1001590Srgrimes
1011590Srgrimes
1021590Srgrimes/*******************************************************************************
1031590Srgrimes *
1041590Srgrimes * FUNCTION:    Options
1051590Srgrimes *
1061590Srgrimes * PARAMETERS:  None
1071590Srgrimes *
1081590Srgrimes * RETURN:      None
1091590Srgrimes *
1101590Srgrimes * DESCRIPTION: Display option help message
1111590Srgrimes *
1121590Srgrimes ******************************************************************************/
1131590Srgrimes
1141590Srgrimesstatic void
1151590SrgrimesOptions (
1161590Srgrimes    void)
1171590Srgrimes{
1181590Srgrimes
1191590Srgrimes    printf ("\nGlobal:\n");
1201590Srgrimes    ACPI_OPTION ("-@ <file>",       "Specify command file");
1211590Srgrimes    ACPI_OPTION ("-I <dir>",        "Specify additional include directory");
1221590Srgrimes
1231590Srgrimes    printf ("\nPreprocessor:\n");
1241590Srgrimes    ACPI_OPTION ("-D <symbol>",     "Define symbol for preprocessor use");
1251590Srgrimes    ACPI_OPTION ("-li",             "Create preprocessed output file (*.i)");
1261590Srgrimes    ACPI_OPTION ("-P",              "Preprocess only and create preprocessor output file (*.i)");
1271590Srgrimes    ACPI_OPTION ("-Pn",             "Disable preprocessor");
1281590Srgrimes
1291590Srgrimes    printf ("\nGeneral Output:\n");
1301590Srgrimes    ACPI_OPTION ("-p <prefix>",     "Specify path/filename prefix for all output files");
1311590Srgrimes    ACPI_OPTION ("-va",             "Disable all errors and warnings (summary only)");
1321590Srgrimes    ACPI_OPTION ("-vi",             "Less verbose errors and warnings for use with IDEs");
1331590Srgrimes    ACPI_OPTION ("-vo",             "Enable optimization comments");
1341590Srgrimes    ACPI_OPTION ("-vr",             "Disable remarks");
1351590Srgrimes    ACPI_OPTION ("-vs",             "Disable signon");
1368874Srgrimes    ACPI_OPTION ("-w1 -w2 -w3",     "Set warning reporting level");
1371590Srgrimes    ACPI_OPTION ("-we",             "Report warnings as errors");
1381590Srgrimes
1391590Srgrimes    printf ("\nAML Output Files:\n");
1401590Srgrimes    ACPI_OPTION ("-sa -sc",         "Create AML in assembler or C source file (*.asm or *.c)");
1411590Srgrimes    ACPI_OPTION ("-ia -ic",         "Create assembler or C include file (*.inc or *.h)");
1421590Srgrimes    ACPI_OPTION ("-ta -tc -ts",     "Create AML in assembler, C, or ASL hex table (*.hex)");
1431590Srgrimes
1441590Srgrimes    printf ("\nAML Code Generation:\n");
1451590Srgrimes    ACPI_OPTION ("-oa",             "Disable all optimizations (compatibility mode)");
1461590Srgrimes    ACPI_OPTION ("-of",             "Disable constant folding");
147282449Sbapt    ACPI_OPTION ("-oi",             "Disable integer optimization to Zero/One/Ones");
1481590Srgrimes    ACPI_OPTION ("-on",             "Disable named reference string optimization");
149282449Sbapt    ACPI_OPTION ("-cr",             "Disable Resource Descriptor error checking");
1501590Srgrimes    ACPI_OPTION ("-r <revision>",   "Override table header Revision (1-255)");
1511590Srgrimes
1521590Srgrimes    printf ("\nASL Listing Files:\n");
1531590Srgrimes    ACPI_OPTION ("-l",              "Create mixed listing file (ASL source and AML) (*.lst)");
1541590Srgrimes    ACPI_OPTION ("-ln",             "Create namespace file (*.nsp)");
1551590Srgrimes    ACPI_OPTION ("-ls",             "Create combined source file (expanded includes) (*.src)");
1561590Srgrimes
1571590Srgrimes    printf ("\nACPI Data Tables:\n");
1581590Srgrimes    ACPI_OPTION ("-G",              "Compile custom table containing generic operators");
1591590Srgrimes    ACPI_OPTION ("-T <sig>|ALL|*",  "Create table template file(s) for <Sig>");
1601590Srgrimes    ACPI_OPTION ("-vt",             "Create verbose templates (full disassembly)");
1611590Srgrimes
1621590Srgrimes    printf ("\nAML Disassembler:\n");
1631590Srgrimes    ACPI_OPTION ("-d  [file]",      "Disassemble or decode binary ACPI table to file (*.dsl)");
1641590Srgrimes    ACPI_OPTION ("-da [f1,f2]",     "Disassemble multiple tables from single namespace");
1651590Srgrimes    ACPI_OPTION ("-dc [file]",      "Disassemble AML and immediately compile it");
1661590Srgrimes    ACPI_OPTION ("",                "(Obtain DSDT from current system if no input file)");
1671590Srgrimes    ACPI_OPTION ("-e  [f1,f2]",     "Include ACPI table(s) for external symbol resolution");
1681590Srgrimes    ACPI_OPTION ("-m",              "Do not translate Buffers to Resource Templates");
1691590Srgrimes    ACPI_OPTION ("-2",              "Emit ACPI 2.0 compatible ASL code");
1701590Srgrimes    ACPI_OPTION ("-g",              "Get ACPI tables and write to files (*.dat)");
1711590Srgrimes
1721590Srgrimes    printf ("\nHelp:\n");
1731590Srgrimes    ACPI_OPTION ("-h",              "Additional help and compiler debug options");
1741590Srgrimes    ACPI_OPTION ("-hc",             "Display operators allowed in constant expressions");
1751590Srgrimes    ACPI_OPTION ("-hr",             "Display ACPI reserved method names");
1761590Srgrimes    ACPI_OPTION ("-ht",             "Display currently supported ACPI table names");
1771590Srgrimes}
1781590Srgrimes
1791590Srgrimes
1801590Srgrimes/*******************************************************************************
1811590Srgrimes *
1821590Srgrimes * FUNCTION:    HelpMessage
1831590Srgrimes *
1841590Srgrimes * PARAMETERS:  None
1851590Srgrimes *
1861590Srgrimes * RETURN:      None
1871590Srgrimes *
1881590Srgrimes * DESCRIPTION: Display help message
1891590Srgrimes *
1901590Srgrimes ******************************************************************************/
1911590Srgrimes
1921590Srgrimesstatic void
1931590SrgrimesHelpMessage (
1941590Srgrimes    void)
1951590Srgrimes{
1961590Srgrimes
1978874Srgrimes    printf ("\nAML output filename generation:\n");
1981590Srgrimes    printf ("  Output filenames are generated by appending an extension to a common\n");
1991590Srgrimes    printf ("  filename prefix.  The filename prefix is obtained via one of the\n");
2001590Srgrimes    printf ("  following methods (in priority order):\n");
2011590Srgrimes    printf ("    1) The -p option specifies the prefix\n");
2021590Srgrimes    printf ("    2) The prefix of the AMLFileName in the ASL Definition Block\n");
2031590Srgrimes    printf ("    3) The prefix of the input filename\n");
2041590Srgrimes    printf ("\n");
2051590Srgrimes
2061590Srgrimes    Options ();
2071590Srgrimes
2081590Srgrimes    printf ("\nCompiler/Disassembler Debug Options:\n");
2091590Srgrimes    ACPI_OPTION ("-bb -bp -bt",     "Create compiler debug/trace file (*.txt)");
2108874Srgrimes    ACPI_OPTION ("",                "Types: Parse/Tree/Both");
2111590Srgrimes    ACPI_OPTION ("-f",              "Ignore errors, force creation of AML output file(s)");
2121590Srgrimes    ACPI_OPTION ("-n",              "Parse only, no output generation");
2131590Srgrimes    ACPI_OPTION ("-ot",             "Display compile times");
2141590Srgrimes    ACPI_OPTION ("-x <level>",      "Set debug level for trace output");
2151590Srgrimes    ACPI_OPTION ("-z",              "Do not insert new compiler ID for DataTables");
2161590Srgrimes}
2171590Srgrimes
2181590Srgrimes
2191590Srgrimes/*******************************************************************************
2201590Srgrimes *
2211590Srgrimes * FUNCTION:    Usage
2228874Srgrimes *
2231590Srgrimes * PARAMETERS:  None
2241590Srgrimes *
2251590Srgrimes * RETURN:      None
2261590Srgrimes *
2271590Srgrimes * DESCRIPTION: Display usage and option message
2281590Srgrimes *
2291590Srgrimes ******************************************************************************/
2301590Srgrimes
2311590Srgrimesstatic void
2321590SrgrimesUsage (
2331590Srgrimes    void)
2341590Srgrimes{
2351590Srgrimes
2361590Srgrimes    printf ("%s\n\n", ASL_COMPLIANCE);
2371590Srgrimes    ACPI_USAGE_HEADER ("iasl [Options] [Files]");
2381590Srgrimes    Options ();
2391590Srgrimes}
2401590Srgrimes
2411590Srgrimes
2421590Srgrimes/*******************************************************************************
2431590Srgrimes *
2441590Srgrimes * FUNCTION:    AslInitialize
2451590Srgrimes *
2461590Srgrimes * PARAMETERS:  None
2471590Srgrimes *
2481590Srgrimes * RETURN:      None
2491590Srgrimes *
2501590Srgrimes * DESCRIPTION: Initialize compiler globals
2511590Srgrimes *
2521590Srgrimes ******************************************************************************/
2531590Srgrimes
2541590Srgrimesstatic void
2551590SrgrimesAslInitialize (
2561590Srgrimes    void)
2571590Srgrimes{
2581590Srgrimes    UINT32                  i;
2591590Srgrimes
2601590Srgrimes
2611590Srgrimes#ifdef _DEBUG
2621590Srgrimes    _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0));
2631590Srgrimes#endif
26419012Sjoerg
2651590Srgrimes    AcpiDbgLevel = 0;
2661590Srgrimes
2671590Srgrimes    for (i = 0; i < ASL_NUM_FILES; i++)
2681590Srgrimes    {
2691590Srgrimes        Gbl_Files[i].Handle = NULL;
2701590Srgrimes        Gbl_Files[i].Filename = NULL;
2711590Srgrimes    }
2721590Srgrimes
2731590Srgrimes    Gbl_Files[ASL_FILE_STDOUT].Handle   = stdout;
2741590Srgrimes    Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
2751590Srgrimes
2761590Srgrimes    Gbl_Files[ASL_FILE_STDERR].Handle   = stderr;
2771590Srgrimes    Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
2781590Srgrimes}
2791590Srgrimes
2801590Srgrimes
2811590Srgrimes/*******************************************************************************
2821590Srgrimes *
2831590Srgrimes * FUNCTION:    AslMergeOptionTokens
2841590Srgrimes *
2851590Srgrimes * PARAMETERS:  InBuffer            - Input containing an option string
2861590Srgrimes *              OutBuffer           - Merged output buffer
2871590Srgrimes *
2881590Srgrimes * RETURN:      None
2891590Srgrimes *
2901590Srgrimes * DESCRIPTION: Remove all whitespace from an option string.
2911590Srgrimes *
2921590Srgrimes ******************************************************************************/
2931590Srgrimes
2941590Srgrimesstatic void
2951590SrgrimesAslMergeOptionTokens (
2961590Srgrimes    char                    *InBuffer,
2971590Srgrimes    char                    *OutBuffer)
2981590Srgrimes{
2991590Srgrimes    char                    *Token;
3001590Srgrimes
3011590Srgrimes
3021590Srgrimes    *OutBuffer = 0;
3031590Srgrimes
3041590Srgrimes    Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
3051590Srgrimes    while (Token)
3061590Srgrimes    {
3071590Srgrimes        strcat (OutBuffer, Token);
3081590Srgrimes        Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
3091590Srgrimes    }
3101590Srgrimes}
3111590Srgrimes
3121590Srgrimes
3131590Srgrimes/*******************************************************************************
3141590Srgrimes *
3151590Srgrimes * FUNCTION:    AslDoResponseFile
3161590Srgrimes *
3171590Srgrimes * PARAMETERS:  Filename        - Name of the response file
3181590Srgrimes *
3191590Srgrimes * RETURN:      Status
3201590Srgrimes *
3211590Srgrimes * DESCRIPTION: Open a response file and process all options within.
3221590Srgrimes *
3231590Srgrimes ******************************************************************************/
3241590Srgrimes
3251590Srgrimesstatic int
3261590SrgrimesAslDoResponseFile (
3271590Srgrimes    char                    *Filename)
3281590Srgrimes{
3291590Srgrimes    char                    *argv = StringBuffer2;
3301590Srgrimes    FILE                    *ResponseFile;
3311590Srgrimes    int                     OptStatus = 0;
3321590Srgrimes    int                     Opterr;
3331590Srgrimes    int                     Optind;
3341590Srgrimes
3351590Srgrimes
3361590Srgrimes    ResponseFile = fopen (Filename, "r");
3371590Srgrimes    if (!ResponseFile)
3381590Srgrimes    {
3391590Srgrimes        printf ("Could not open command file %s, %s\n",
3408874Srgrimes            Filename, strerror (errno));
3411590Srgrimes        return -1;
3421590Srgrimes    }
3431590Srgrimes
344282449Sbapt    /* Must save the current GetOpt globals */
345282449Sbapt
346282449Sbapt    Opterr = AcpiGbl_Opterr;
347282449Sbapt    Optind = AcpiGbl_Optind;
348282449Sbapt
3491590Srgrimes    /*
350282449Sbapt     * Process all lines in the response file. There must be one complete
3511590Srgrimes     * option per line
3521590Srgrimes     */
3531590Srgrimes    while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile))
354282457Sbapt    {
3551590Srgrimes        /* Compress all tokens, allowing us to use a single argv entry */
3561590Srgrimes
3571590Srgrimes        AslMergeOptionTokens (StringBuffer, StringBuffer2);
3581590Srgrimes
3591590Srgrimes        /* Process the option */
360282457Sbapt
3611590Srgrimes        AcpiGbl_Opterr = 0;
3621590Srgrimes        AcpiGbl_Optind = 0;
3631590Srgrimes
3641590Srgrimes        OptStatus = AslDoOptions (1, &argv, TRUE);
3651590Srgrimes        if (OptStatus)
3661590Srgrimes        {
3671590Srgrimes            printf ("Invalid option in command file %s: %s\n",
3681590Srgrimes                Filename, StringBuffer);
3691590Srgrimes            break;
3701590Srgrimes        }
3711590Srgrimes    }
3721590Srgrimes
3731590Srgrimes    /* Restore the GetOpt globals */
3741590Srgrimes
3751590Srgrimes    AcpiGbl_Opterr = Opterr;
3761590Srgrimes    AcpiGbl_Optind = Optind;
3771590Srgrimes
3781590Srgrimes    fclose (ResponseFile);
3791590Srgrimes    return (OptStatus);
3801590Srgrimes}
3811590Srgrimes
3821590Srgrimes
3831590Srgrimes/*******************************************************************************
3841590Srgrimes *
3851590Srgrimes * FUNCTION:    AslDoOptions
3861590Srgrimes *
3871590Srgrimes * PARAMETERS:  argc/argv           - Standard argc/argv
3881590Srgrimes *              IsResponseFile      - TRUE if executing a response file.
3891590Srgrimes *
3901590Srgrimes * RETURN:      Status
3911590Srgrimes *
3921590Srgrimes * DESCRIPTION: Command line option processing
3931590Srgrimes *
3941590Srgrimes ******************************************************************************/
3951590Srgrimes
3961590Srgrimesstatic int
3971590SrgrimesAslDoOptions (
3981590Srgrimes    int                     argc,
3991590Srgrimes    char                    **argv,
4001590Srgrimes    BOOLEAN                 IsResponseFile)
4011590Srgrimes{
4021590Srgrimes    int                     j;
4031590Srgrimes    ACPI_STATUS             Status;
4041590Srgrimes
4051590Srgrimes
4061590Srgrimes    /* Get the command line options */
4071590Srgrimes
4081590Srgrimes    while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j)
4091590Srgrimes    {
4101590Srgrimes    case '@':   /* Begin a response file */
4111590Srgrimes
4121590Srgrimes        if (IsResponseFile)
4131590Srgrimes        {
4141590Srgrimes            printf ("Nested command files are not supported\n");
4151590Srgrimes            return (-1);
4161590Srgrimes        }
4171590Srgrimes
4181590Srgrimes        if (AslDoResponseFile (AcpiGbl_Optarg))
4191590Srgrimes        {
4201590Srgrimes            return (-1);
4211590Srgrimes        }
4221590Srgrimes        break;
4231590Srgrimes
4241590Srgrimes
4251590Srgrimes    case '2':   /* ACPI 2.0 compatibility mode */
4261590Srgrimes        Gbl_Acpi2 = TRUE;
4271590Srgrimes        break;
4281590Srgrimes
4291590Srgrimes
4301590Srgrimes    case 'b':   /* Debug output options */
4311590Srgrimes        switch (AcpiGbl_Optarg[0])
4321590Srgrimes        {
4331590Srgrimes        case 'b':
4341590Srgrimes            AslCompilerdebug = 1; /* same as yydebug */
4351590Srgrimes            DtParserdebug = 1;
4361590Srgrimes            PrParserdebug = 1;
4371590Srgrimes            break;
4381590Srgrimes
4391590Srgrimes        case 'p':
4401590Srgrimes            AslCompilerdebug = 1; /* same as yydebug */
4411590Srgrimes            DtParserdebug = 1;
4421590Srgrimes            PrParserdebug = 1;
4431590Srgrimes            break;
4441590Srgrimes
4451590Srgrimes        case 't':
4461590Srgrimes            break;
4471590Srgrimes
4481590Srgrimes        default:
4491590Srgrimes            printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
4501590Srgrimes            return (-1);
4511590Srgrimes        }
4521590Srgrimes
4531590Srgrimes        /* Produce debug output file */
4541590Srgrimes
4551590Srgrimes        Gbl_DebugFlag = TRUE;
4561590Srgrimes        break;
4571590Srgrimes
4581590Srgrimes
4591590Srgrimes    case 'c':
4601590Srgrimes        switch (AcpiGbl_Optarg[0])
46119019Sjoerg        {
46219019Sjoerg        case 'r':
46319019Sjoerg            Gbl_NoResourceChecking = TRUE;
46419019Sjoerg            break;
46519019Sjoerg
466282457Sbapt        default:
4671590Srgrimes            printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
4681590Srgrimes            return (-1);
469282457Sbapt        }
4701590Srgrimes        break;
471282457Sbapt
4721590Srgrimes
4731590Srgrimes    case 'd':   /* Disassembler */
4741590Srgrimes        switch (AcpiGbl_Optarg[0])
4751590Srgrimes        {
4761590Srgrimes        case '^':
4771590Srgrimes            Gbl_DoCompile = FALSE;
4781590Srgrimes            break;
4791590Srgrimes
4801590Srgrimes        case 'a':
4811590Srgrimes            Gbl_DoCompile = FALSE;
4821590Srgrimes            Gbl_DisassembleAll = TRUE;
4831590Srgrimes            break;
4841590Srgrimes
4851590Srgrimes        case 'c':
4861590Srgrimes            break;
4871590Srgrimes
4881590Srgrimes        default:
4891590Srgrimes            printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
4901590Srgrimes            return (-1);
4911590Srgrimes        }
4921590Srgrimes
4931590Srgrimes        Gbl_DisasmFlag = TRUE;
4941590Srgrimes        break;
4951590Srgrimes
4961590Srgrimes
4971590Srgrimes    case 'D':   /* Define a symbol */
4981590Srgrimes        PrAddDefine (AcpiGbl_Optarg, NULL, TRUE);
499282457Sbapt        break;
5001590Srgrimes
501282457Sbapt
5021590Srgrimes    case 'e':   /* External files for disassembler */
5031590Srgrimes        Status = AcpiDmAddToExternalFileList (AcpiGbl_Optarg);
5041590Srgrimes        if (ACPI_FAILURE (Status))
5051590Srgrimes        {
5061590Srgrimes            printf ("Could not add %s to external list\n", AcpiGbl_Optarg);
5071590Srgrimes            return (-1);
5081590Srgrimes        }
5098874Srgrimes        break;
5101590Srgrimes
5111590Srgrimes
5121590Srgrimes    case 'f':   /* Ignore errors and force creation of aml file */
5131590Srgrimes        Gbl_IgnoreErrors = TRUE;
5141590Srgrimes        break;
5151590Srgrimes
5161590Srgrimes
51736053Sjb    case 'G':
5181590Srgrimes        Gbl_CompileGeneric = TRUE;
5191590Srgrimes        break;
5201590Srgrimes
5218874Srgrimes
5221590Srgrimes    case 'g':   /* Get all ACPI tables */
5231590Srgrimes
5241590Srgrimes        Gbl_GetAllTables = TRUE;
5251590Srgrimes        Gbl_DoCompile = FALSE;
5268874Srgrimes        break;
5271590Srgrimes
5281590Srgrimes
5291590Srgrimes    case 'h':
5301590Srgrimes        switch (AcpiGbl_Optarg[0])
5311590Srgrimes        {
5321590Srgrimes        case '^':
5331590Srgrimes            HelpMessage ();
5341590Srgrimes            exit (0);
5351590Srgrimes
5361590Srgrimes        case 'c':
5371590Srgrimes            UtDisplayConstantOpcodes ();
5381590Srgrimes            exit (0);
5391590Srgrimes
5401590Srgrimes        case 'r':
5411590Srgrimes            /* reserved names */
5421590Srgrimes
5431590Srgrimes            ApDisplayReservedNames ();
5441590Srgrimes            exit (0);
5451590Srgrimes
5461590Srgrimes        case 't':
5471590Srgrimes            UtDisplaySupportedTables ();
5481590Srgrimes            exit (0);
5491590Srgrimes
5501590Srgrimes        default:
5511590Srgrimes            printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
5521590Srgrimes            return (-1);
5531590Srgrimes        }
5541590Srgrimes
5551590Srgrimes
5561590Srgrimes    case 'I':   /* Add an include file search directory */
5571590Srgrimes        FlAddIncludeDirectory (AcpiGbl_Optarg);
5581590Srgrimes        break;
5591590Srgrimes
5601590Srgrimes
5611590Srgrimes    case 'i':   /* Output AML as an include file */
5621590Srgrimes        switch (AcpiGbl_Optarg[0])
5631590Srgrimes        {
5641590Srgrimes        case 'a':
5651590Srgrimes
5661590Srgrimes            /* Produce assembly code include file */
5671590Srgrimes
5681590Srgrimes            Gbl_AsmIncludeOutputFlag = TRUE;
56936053Sjb            break;
5701590Srgrimes
5711590Srgrimes        case 'c':
5721590Srgrimes
5731590Srgrimes            /* Produce C include file */
5741590Srgrimes
5751590Srgrimes            Gbl_C_IncludeOutputFlag = TRUE;
5761590Srgrimes            break;
5771590Srgrimes
5781590Srgrimes        default:
5791590Srgrimes            printf ("Unknown option: -i%s\n", AcpiGbl_Optarg);
5801590Srgrimes            return (-1);
5811590Srgrimes        }
5821590Srgrimes        break;
5831590Srgrimes
5841590Srgrimes
5851590Srgrimes    case 'l':   /* Listing files */
5861590Srgrimes        switch (AcpiGbl_Optarg[0])
5871590Srgrimes        {
5881590Srgrimes        case '^':
5891590Srgrimes            /* Produce listing file (Mixed source/aml) */
5901590Srgrimes
5911590Srgrimes            Gbl_ListingFlag = TRUE;
5921590Srgrimes            break;
5931590Srgrimes
5941590Srgrimes        case 'i':
5951590Srgrimes            /* Produce preprocessor output file */
5961590Srgrimes
5971590Srgrimes            Gbl_PreprocessorOutputFlag = TRUE;
5981590Srgrimes            break;
599
600        case 'n':
601            /* Produce namespace file */
602
603            Gbl_NsOutputFlag = TRUE;
604            break;
605
606        case 's':
607            /* Produce combined source file */
608
609            Gbl_SourceOutputFlag = TRUE;
610            break;
611
612        default:
613            printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
614            return (-1);
615        }
616        break;
617
618
619    case 'm':   /* Do not convert buffers to resource descriptors */
620        AcpiGbl_NoResourceDisassembly = TRUE;
621        break;
622
623
624    case 'n':   /* Parse only */
625        Gbl_ParseOnlyFlag = TRUE;
626        break;
627
628
629    case 'o':   /* Control compiler AML optimizations */
630        switch (AcpiGbl_Optarg[0])
631        {
632        case 'a':
633
634            /* Disable all optimizations */
635
636            Gbl_FoldConstants = FALSE;
637            Gbl_IntegerOptimizationFlag = FALSE;
638            Gbl_ReferenceOptimizationFlag = FALSE;
639            break;
640
641        case 'f':
642
643            /* Disable folding on "normal" expressions */
644
645            Gbl_FoldConstants = FALSE;
646            break;
647
648        case 'i':
649
650            /* Disable integer optimization to constants */
651
652            Gbl_IntegerOptimizationFlag = FALSE;
653            break;
654
655        case 'n':
656
657            /* Disable named reference optimization */
658
659            Gbl_ReferenceOptimizationFlag = FALSE;
660            break;
661
662        case 't':
663
664            /* Display compile time(s) */
665
666            Gbl_CompileTimesFlag = TRUE;
667            break;
668
669        default:
670            printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
671            return (-1);
672        }
673        break;
674
675
676    case 'P':   /* Preprocessor options */
677        switch (AcpiGbl_Optarg[0])
678        {
679        case '^':   /* Proprocess only, emit (.i) file */
680            Gbl_PreprocessOnly = TRUE;
681            Gbl_PreprocessorOutputFlag = TRUE;
682            break;
683
684        case 'n':   /* Disable preprocessor */
685            Gbl_PreprocessFlag = FALSE;
686            break;
687
688        default:
689            printf ("Unknown option: -P%s\n", AcpiGbl_Optarg);
690            return (-1);
691        }
692        break;
693
694
695    case 'p':   /* Override default AML output filename */
696        Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
697        Gbl_UseDefaultAmlFilename = FALSE;
698        break;
699
700
701    case 'r':   /* Override revision found in table header */
702        Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
703        break;
704
705
706    case 's':   /* Create AML in a source code file */
707        switch (AcpiGbl_Optarg[0])
708        {
709        case 'a':
710
711            /* Produce assembly code output file */
712
713            Gbl_AsmOutputFlag = TRUE;
714            break;
715
716        case 'c':
717
718            /* Produce C hex output file */
719
720            Gbl_C_OutputFlag = TRUE;
721            break;
722
723        default:
724            printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
725            return (-1);
726        }
727        break;
728
729
730    case 't':   /* Produce hex table output file */
731        switch (AcpiGbl_Optarg[0])
732        {
733        case 'a':
734            Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
735            break;
736
737        case 'c':
738            Gbl_HexOutputFlag = HEX_OUTPUT_C;
739            break;
740
741        case 's':
742            Gbl_HexOutputFlag = HEX_OUTPUT_ASL;
743            break;
744
745        default:
746            printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
747            return (-1);
748        }
749        break;
750
751
752    case 'T':   /* Create a ACPI table template file */
753        Gbl_DoTemplates = TRUE;
754        Gbl_TemplateSignature = AcpiGbl_Optarg;
755        break;
756
757
758    case 'v':   /* Verbosity settings */
759        switch (AcpiGbl_Optarg[0])
760        {
761        case 'a':
762            /* Disable All error/warning messages */
763
764            Gbl_NoErrors = TRUE;
765            break;
766
767        case 'i':
768            /* Less verbose error messages */
769
770            Gbl_VerboseErrors = FALSE;
771            break;
772
773        case 'o':
774            Gbl_DisplayOptimizations = TRUE;
775            break;
776
777        case 'r':
778            Gbl_DisplayRemarks = FALSE;
779            break;
780
781        case 's':
782            Gbl_DoSignon = FALSE;
783            break;
784
785        case 't':
786            Gbl_VerboseTemplates = TRUE;
787            break;
788
789        default:
790            printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
791            return (-1);
792        }
793        break;
794
795
796    case 'w': /* Set warning levels */
797        switch (AcpiGbl_Optarg[0])
798        {
799        case '1':
800            Gbl_WarningLevel = ASL_WARNING;
801            break;
802
803        case '2':
804            Gbl_WarningLevel = ASL_WARNING2;
805            break;
806
807        case '3':
808            Gbl_WarningLevel = ASL_WARNING3;
809            break;
810
811        case 'e':
812            Gbl_WarningsAsErrors = TRUE;
813            break;
814
815        default:
816            printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
817            return (-1);
818        }
819        break;
820
821
822    case 'x':   /* Set debug print output level */
823        AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
824        break;
825
826
827    case 'z':
828        Gbl_UseOriginalCompilerId = TRUE;
829        break;
830
831
832    default:
833        return (-1);
834    }
835
836    return (0);
837}
838
839
840/*******************************************************************************
841 *
842 * FUNCTION:    AslCommandLine
843 *
844 * PARAMETERS:  argc/argv
845 *
846 * RETURN:      Last argv index
847 *
848 * DESCRIPTION: Command line processing
849 *
850 ******************************************************************************/
851
852static int
853AslCommandLine (
854    int                     argc,
855    char                    **argv)
856{
857    int                     BadCommandLine = 0;
858    ACPI_STATUS             Status;
859
860
861    /* Minimum command line contains at least the command and an input file */
862
863    if (argc < 2)
864    {
865        printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
866        Usage ();
867        exit (1);
868    }
869
870    /* Process all command line options */
871
872    BadCommandLine = AslDoOptions (argc, argv, FALSE);
873
874    if (Gbl_DoTemplates)
875    {
876        Status = DtCreateTemplates (Gbl_TemplateSignature);
877        if (ACPI_FAILURE (Status))
878        {
879            exit (-1);
880        }
881        exit (1);
882    }
883
884    /* Next parameter must be the input filename */
885
886    if (!argv[AcpiGbl_Optind] &&
887        !Gbl_DisasmFlag &&
888        !Gbl_GetAllTables)
889    {
890        printf ("Missing input filename\n");
891        BadCommandLine = TRUE;
892    }
893
894    if (Gbl_DoSignon)
895    {
896        printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
897        if (Gbl_IgnoreErrors)
898        {
899            printf ("Ignoring all errors, forcing AML file generation\n\n");
900        }
901    }
902
903    /* Abort if anything went wrong on the command line */
904
905    if (BadCommandLine)
906    {
907        printf ("\n");
908        Usage ();
909        exit (1);
910    }
911
912    return (AcpiGbl_Optind);
913}
914
915
916/*******************************************************************************
917 *
918 * FUNCTION:    main
919 *
920 * PARAMETERS:  Standard argc/argv
921 *
922 * RETURN:      Program termination code
923 *
924 * DESCRIPTION: C main routine for the Asl Compiler. Handle command line
925 *              options and begin the compile for each file on the command line
926 *
927 ******************************************************************************/
928
929int ACPI_SYSTEM_XFACE
930main (
931    int                     argc,
932    char                    **argv)
933{
934    ACPI_STATUS             Status;
935    int                     Index1;
936    int                     Index2;
937
938
939    AcpiGbl_ExternalFileList = NULL;
940
941#ifdef _DEBUG
942    _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF |
943                    _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
944#endif
945
946    /* Init and command line */
947
948    AslInitialize ();
949    PrInitializePreprocessor ();
950    Index1 = Index2 = AslCommandLine (argc, argv);
951
952    /* Options that have no additional parameters or pathnames */
953
954    if (Gbl_GetAllTables)
955    {
956        Status = AslDoOneFile (NULL);
957        if (ACPI_FAILURE (Status))
958        {
959            return (-1);
960        }
961        return (0);
962    }
963
964    if (Gbl_DisassembleAll)
965    {
966        while (argv[Index1])
967        {
968            Status = AslDoOnePathname (argv[Index1], AcpiDmAddToExternalFileList);
969            if (ACPI_FAILURE (Status))
970            {
971                return (-1);
972            }
973
974            Index1++;
975        }
976    }
977
978    /* Process each pathname/filename in the list, with possible wildcards */
979
980    while (argv[Index2])
981    {
982        Status = AslDoOnePathname (argv[Index2], AslDoOneFile);
983        if (ACPI_FAILURE (Status))
984        {
985            return (-1);
986        }
987
988        Index2++;
989    }
990
991    if (AcpiGbl_ExternalFileList)
992    {
993        AcpiDmClearExternalFileList();
994    }
995
996    return (0);
997}
998
999
1000