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