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