Home | History | Annotate | Line # | Download | only in compiler
aslmain.c revision 1.1.1.5.2.6
      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.5.2.6     skrll  * 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.5.2.5     skrll  * DESCRIPTION: C main routine for the iASL Compiler/Disassembler. Process
     86  1.1.1.5.2.5     skrll  *  command line options and begin the compile/disassembly for each file on
     87  1.1.1.5.2.5     skrll  *  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.5  christos     /*
    103      1.1.1.5  christos      * Big-endian machines are not currently supported. ACPI tables must
    104      1.1.1.5  christos      * be little-endian, and support for big-endian machines needs to
    105      1.1.1.5  christos      * be implemented.
    106      1.1.1.5  christos      */
    107  1.1.1.5.2.4     skrll     if (UtIsBigEndianMachine ())
    108      1.1.1.5  christos     {
    109      1.1.1.5  christos         fprintf (stderr,
    110      1.1.1.5  christos             "iASL is not currently supported on big-endian machines.\n");
    111      1.1.1.5  christos         return (-1);
    112      1.1.1.5  christos     }
    113      1.1.1.5  christos 
    114      1.1.1.5  christos     AcpiOsInitialize ();
    115      1.1.1.4  christos     ACPI_DEBUG_INITIALIZE (); /* For debug version only */
    116          1.1    jruoho 
    117      1.1.1.4  christos     /* Initialize preprocessor and compiler before command line processing */
    118          1.1    jruoho 
    119      1.1.1.4  christos     signal (SIGINT, AslSignalHandler);
    120      1.1.1.4  christos     AcpiGbl_ExternalFileList = NULL;
    121      1.1.1.4  christos     AcpiDbgLevel = 0;
    122      1.1.1.4  christos     PrInitializePreprocessor ();
    123          1.1    jruoho     AslInitialize ();
    124      1.1.1.4  christos 
    125  1.1.1.5.2.5     skrll     Index1 = Index2 =
    126  1.1.1.5.2.5     skrll         AslCommandLine (argc, argv);
    127          1.1    jruoho 
    128      1.1.1.4  christos     /* Allocate the line buffer(s), must be after command line */
    129      1.1.1.4  christos 
    130      1.1.1.4  christos     Gbl_LineBufferSize /= 2;
    131      1.1.1.4  christos     UtExpandLineBuffers ();
    132      1.1.1.4  christos 
    133      1.1.1.4  christos     /* Perform global actions first/only */
    134          1.1    jruoho 
    135      1.1.1.2    jruoho     if (Gbl_DisassembleAll)
    136      1.1.1.2    jruoho     {
    137      1.1.1.2    jruoho         while (argv[Index1])
    138      1.1.1.2    jruoho         {
    139      1.1.1.4  christos             Status = AcpiDmAddToExternalFileList (argv[Index1]);
    140      1.1.1.2    jruoho             if (ACPI_FAILURE (Status))
    141      1.1.1.2    jruoho             {
    142      1.1.1.2    jruoho                 return (-1);
    143      1.1.1.2    jruoho             }
    144      1.1.1.2    jruoho 
    145      1.1.1.2    jruoho             Index1++;
    146      1.1.1.2    jruoho         }
    147      1.1.1.2    jruoho     }
    148      1.1.1.2    jruoho 
    149          1.1    jruoho     /* Process each pathname/filename in the list, with possible wildcards */
    150          1.1    jruoho 
    151      1.1.1.2    jruoho     while (argv[Index2])
    152          1.1    jruoho     {
    153      1.1.1.4  christos         /*
    154      1.1.1.4  christos          * If -p not specified, we will use the input filename as the
    155      1.1.1.4  christos          * output filename prefix
    156      1.1.1.4  christos          */
    157      1.1.1.4  christos         if (Gbl_UseDefaultAmlFilename)
    158      1.1.1.4  christos         {
    159      1.1.1.4  christos             Gbl_OutputFilenamePrefix = argv[Index2];
    160      1.1.1.4  christos             UtConvertBackslashes (Gbl_OutputFilenamePrefix);
    161      1.1.1.4  christos         }
    162      1.1.1.4  christos 
    163      1.1.1.4  christos         Status = AslDoOneFile (argv[Index2]);
    164          1.1    jruoho         if (ACPI_FAILURE (Status))
    165          1.1    jruoho         {
    166      1.1.1.5  christos             ReturnStatus = -1;
    167      1.1.1.5  christos             goto CleanupAndExit;
    168          1.1    jruoho         }
    169          1.1    jruoho 
    170      1.1.1.2    jruoho         Index2++;
    171      1.1.1.2    jruoho     }
    172      1.1.1.2    jruoho 
    173      1.1.1.5  christos 
    174      1.1.1.5  christos CleanupAndExit:
    175      1.1.1.5  christos 
    176      1.1.1.5  christos     UtFreeLineBuffers ();
    177      1.1.1.5  christos     AslParserCleanup ();
    178      1.1.1.5  christos 
    179      1.1.1.2    jruoho     if (AcpiGbl_ExternalFileList)
    180      1.1.1.2    jruoho     {
    181      1.1.1.2    jruoho         AcpiDmClearExternalFileList();
    182          1.1    jruoho     }
    183          1.1    jruoho 
    184      1.1.1.5  christos     return (ReturnStatus);
    185          1.1    jruoho }
    186  1.1.1.5.2.5     skrll 
    187  1.1.1.5.2.5     skrll 
    188  1.1.1.5.2.5     skrll /******************************************************************************
    189  1.1.1.5.2.5     skrll  *
    190  1.1.1.5.2.5     skrll  * FUNCTION:    AslSignalHandler
    191  1.1.1.5.2.5     skrll  *
    192  1.1.1.5.2.5     skrll  * PARAMETERS:  Sig                 - Signal that invoked this handler
    193  1.1.1.5.2.5     skrll  *
    194  1.1.1.5.2.5     skrll  * RETURN:      None
    195  1.1.1.5.2.5     skrll  *
    196  1.1.1.5.2.5     skrll  * DESCRIPTION: Control-C handler. Delete any intermediate files and any
    197  1.1.1.5.2.5     skrll  *              output files that may be left in an indeterminate state.
    198  1.1.1.5.2.5     skrll  *
    199  1.1.1.5.2.5     skrll  *****************************************************************************/
    200  1.1.1.5.2.5     skrll 
    201  1.1.1.5.2.5     skrll static void ACPI_SYSTEM_XFACE
    202  1.1.1.5.2.5     skrll AslSignalHandler (
    203  1.1.1.5.2.5     skrll     int                     Sig)
    204  1.1.1.5.2.5     skrll {
    205  1.1.1.5.2.5     skrll     UINT32                  i;
    206  1.1.1.5.2.5     skrll 
    207  1.1.1.5.2.5     skrll 
    208  1.1.1.5.2.5     skrll     signal (Sig, SIG_IGN);
    209  1.1.1.5.2.5     skrll     printf ("Aborting\n\n");
    210  1.1.1.5.2.5     skrll 
    211  1.1.1.5.2.5     skrll     /* Close all open files */
    212  1.1.1.5.2.5     skrll 
    213  1.1.1.5.2.5     skrll     Gbl_Files[ASL_FILE_PREPROCESSOR].Handle = NULL; /* the .pre file is same as source file */
    214  1.1.1.5.2.5     skrll 
    215  1.1.1.5.2.5     skrll     for (i = ASL_FILE_INPUT; i < ASL_MAX_FILE_TYPE; i++)
    216  1.1.1.5.2.5     skrll     {
    217  1.1.1.5.2.5     skrll         FlCloseFile (i);
    218  1.1.1.5.2.5     skrll     }
    219  1.1.1.5.2.5     skrll 
    220  1.1.1.5.2.5     skrll     /* Delete any output files */
    221  1.1.1.5.2.5     skrll 
    222  1.1.1.5.2.5     skrll     for (i = ASL_FILE_AML_OUTPUT; i < ASL_MAX_FILE_TYPE; i++)
    223  1.1.1.5.2.5     skrll     {
    224  1.1.1.5.2.5     skrll         FlDeleteFile (i);
    225  1.1.1.5.2.5     skrll     }
    226  1.1.1.5.2.5     skrll 
    227  1.1.1.5.2.5     skrll     exit (0);
    228  1.1.1.5.2.5     skrll }
    229  1.1.1.5.2.5     skrll 
    230  1.1.1.5.2.5     skrll 
    231  1.1.1.5.2.5     skrll /*******************************************************************************
    232  1.1.1.5.2.5     skrll  *
    233  1.1.1.5.2.5     skrll  * FUNCTION:    AslInitialize
    234  1.1.1.5.2.5     skrll  *
    235  1.1.1.5.2.5     skrll  * PARAMETERS:  None
    236  1.1.1.5.2.5     skrll  *
    237  1.1.1.5.2.5     skrll  * RETURN:      None
    238  1.1.1.5.2.5     skrll  *
    239  1.1.1.5.2.5     skrll  * DESCRIPTION: Initialize compiler globals
    240  1.1.1.5.2.5     skrll  *
    241  1.1.1.5.2.5     skrll  ******************************************************************************/
    242  1.1.1.5.2.5     skrll 
    243  1.1.1.5.2.5     skrll static void
    244  1.1.1.5.2.5     skrll AslInitialize (
    245  1.1.1.5.2.5     skrll     void)
    246  1.1.1.5.2.5     skrll {
    247  1.1.1.5.2.5     skrll     UINT32                  i;
    248  1.1.1.5.2.5     skrll 
    249  1.1.1.5.2.5     skrll 
    250  1.1.1.5.2.5     skrll     AcpiGbl_DmOpt_Verbose = FALSE;
    251  1.1.1.5.2.5     skrll 
    252  1.1.1.5.2.5     skrll     /* Default integer width is 64 bits */
    253  1.1.1.5.2.5     skrll 
    254  1.1.1.5.2.5     skrll     AcpiGbl_IntegerBitWidth = 64;
    255  1.1.1.5.2.5     skrll     AcpiGbl_IntegerNybbleWidth = 16;
    256  1.1.1.5.2.5     skrll     AcpiGbl_IntegerByteWidth = 8;
    257  1.1.1.5.2.5     skrll 
    258  1.1.1.5.2.5     skrll     for (i = 0; i < ASL_NUM_FILES; i++)
    259  1.1.1.5.2.5     skrll     {
    260  1.1.1.5.2.5     skrll         Gbl_Files[i].Handle = NULL;
    261  1.1.1.5.2.5     skrll         Gbl_Files[i].Filename = NULL;
    262  1.1.1.5.2.5     skrll     }
    263  1.1.1.5.2.5     skrll 
    264  1.1.1.5.2.5     skrll     Gbl_Files[ASL_FILE_STDOUT].Handle   = stdout;
    265  1.1.1.5.2.5     skrll     Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
    266  1.1.1.5.2.5     skrll 
    267  1.1.1.5.2.5     skrll     Gbl_Files[ASL_FILE_STDERR].Handle   = stderr;
    268  1.1.1.5.2.5     skrll     Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
    269  1.1.1.5.2.5     skrll }
    270