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