Home | History | Annotate | Line # | Download | only in compiler
aslmain.c revision 1.1.1.21
      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.21  christos  * Copyright (C) 2000 - 2023, 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.19  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 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.15  christos     AslGbl_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.15  christos     if (AslGbl_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.16  christos     /* ACPICA subsystem initialization */
    151  1.1.1.16  christos 
    152  1.1.1.16  christos     Status = AdInitialize ();
    153  1.1.1.16  christos     if (ACPI_FAILURE (Status))
    154  1.1.1.16  christos     {
    155  1.1.1.16  christos         return (Status);
    156  1.1.1.16  christos     }
    157  1.1.1.16  christos 
    158  1.1.1.12  christos 
    159       1.1    jruoho     /* Process each pathname/filename in the list, with possible wildcards */
    160       1.1    jruoho 
    161   1.1.1.2    jruoho     while (argv[Index2])
    162       1.1    jruoho     {
    163   1.1.1.4  christos         /*
    164   1.1.1.4  christos          * If -p not specified, we will use the input filename as the
    165   1.1.1.4  christos          * output filename prefix
    166   1.1.1.4  christos          */
    167  1.1.1.15  christos         if (AslGbl_UseDefaultAmlFilename)
    168   1.1.1.4  christos         {
    169  1.1.1.15  christos             AslGbl_OutputFilenamePrefix = argv[Index2];
    170  1.1.1.15  christos             UtConvertBackslashes (AslGbl_OutputFilenamePrefix);
    171   1.1.1.4  christos         }
    172   1.1.1.4  christos 
    173   1.1.1.4  christos         Status = AslDoOneFile (argv[Index2]);
    174       1.1    jruoho         if (ACPI_FAILURE (Status))
    175       1.1    jruoho         {
    176   1.1.1.5  christos             ReturnStatus = -1;
    177       1.1    jruoho         }
    178       1.1    jruoho 
    179   1.1.1.2    jruoho         Index2++;
    180   1.1.1.2    jruoho     }
    181   1.1.1.2    jruoho 
    182  1.1.1.16  christos     /*
    183  1.1.1.16  christos      * At this point, compilation of a data table or disassembly is complete.
    184  1.1.1.17  christos      * However, if there is a parse tree, perform compiler analysis and
    185  1.1.1.17  christos      * generate AML.
    186  1.1.1.16  christos      */
    187  1.1.1.17  christos     if (AslGbl_PreprocessOnly || AcpiGbl_DisasmFlag || !AslGbl_ParseTreeRoot)
    188  1.1.1.16  christos     {
    189  1.1.1.16  christos         goto CleanupAndExit;
    190  1.1.1.16  christos     }
    191  1.1.1.16  christos 
    192  1.1.1.16  christos     CmDoAslMiddleAndBackEnd ();
    193  1.1.1.16  christos 
    194  1.1.1.16  christos     /*
    195  1.1.1.16  christos      * At this point, all semantic analysis has been completed. Check
    196  1.1.1.16  christos      * expected error messages before cleanup or conversion.
    197  1.1.1.16  christos      */
    198  1.1.1.16  christos     AslCheckExpectedExceptions ();
    199  1.1.1.16  christos 
    200  1.1.1.16  christos     /* ASL-to-ASL+ conversion - Perform immediate disassembly */
    201  1.1.1.16  christos 
    202  1.1.1.16  christos     if (AslGbl_DoAslConversion)
    203  1.1.1.16  christos     {
    204  1.1.1.16  christos         /* re-initialize ACPICA subsystem for disassembler */
    205  1.1.1.16  christos 
    206  1.1.1.16  christos         Status = AdInitialize ();
    207  1.1.1.16  christos         if (ACPI_FAILURE (Status))
    208  1.1.1.16  christos         {
    209  1.1.1.16  christos             return (Status);
    210  1.1.1.16  christos         }
    211  1.1.1.16  christos 
    212  1.1.1.16  christos         /*
    213  1.1.1.16  christos          * New input file is the output AML file from above.
    214  1.1.1.16  christos          * New output is from the input ASL file from above.
    215  1.1.1.16  christos          */
    216  1.1.1.16  christos         AslGbl_OutputFilenamePrefix = AslGbl_Files[ASL_FILE_INPUT].Filename;
    217  1.1.1.16  christos         AslGbl_Files[ASL_FILE_INPUT].Filename =
    218  1.1.1.16  christos             AslGbl_Files[ASL_FILE_AML_OUTPUT].Filename;
    219  1.1.1.16  christos 
    220  1.1.1.16  christos         CvDbgPrint ("Output filename: %s\n", AslGbl_OutputFilenamePrefix);
    221  1.1.1.16  christos         fprintf (stderr, "\n");
    222  1.1.1.16  christos 
    223  1.1.1.16  christos         AcpiGbl_DisasmFlag = TRUE;
    224  1.1.1.16  christos         AslDoDisassembly ();
    225  1.1.1.16  christos         AcpiGbl_DisasmFlag = FALSE;
    226  1.1.1.16  christos 
    227  1.1.1.16  christos         /* delete the AML file. This AML file should never be utilized by AML interpreters. */
    228  1.1.1.16  christos 
    229  1.1.1.16  christos         FlDeleteFile (ASL_FILE_AML_OUTPUT);
    230  1.1.1.16  christos     }
    231  1.1.1.16  christos 
    232  1.1.1.16  christos 
    233   1.1.1.5  christos CleanupAndExit:
    234   1.1.1.5  christos 
    235   1.1.1.5  christos     UtFreeLineBuffers ();
    236   1.1.1.5  christos     AslParserCleanup ();
    237  1.1.1.16  christos     AcpiDmClearExternalFileList();
    238  1.1.1.16  christos     (void) AcpiTerminate ();
    239  1.1.1.16  christos 
    240  1.1.1.16  christos     /* CmCleanupAndExit is intended for the compiler only */
    241   1.1.1.5  christos 
    242  1.1.1.16  christos     if (!AcpiGbl_DisasmFlag)
    243   1.1.1.2    jruoho     {
    244  1.1.1.17  christos         ReturnStatus = CmCleanupAndExit ();
    245       1.1    jruoho     }
    246       1.1    jruoho 
    247  1.1.1.16  christos 
    248   1.1.1.5  christos     return (ReturnStatus);
    249       1.1    jruoho }
    250  1.1.1.10  christos 
    251  1.1.1.10  christos 
    252  1.1.1.10  christos /******************************************************************************
    253  1.1.1.10  christos  *
    254  1.1.1.10  christos  * FUNCTION:    AslSignalHandler
    255  1.1.1.10  christos  *
    256  1.1.1.10  christos  * PARAMETERS:  Sig                 - Signal that invoked this handler
    257  1.1.1.10  christos  *
    258  1.1.1.10  christos  * RETURN:      None
    259  1.1.1.10  christos  *
    260  1.1.1.12  christos  * DESCRIPTION: Signal interrupt handler. Delete any intermediate files and
    261  1.1.1.12  christos  *              any output files that may be left in an indeterminate state.
    262  1.1.1.14  christos  *              Currently handles SIGINT (control-c).
    263  1.1.1.10  christos  *
    264  1.1.1.10  christos  *****************************************************************************/
    265  1.1.1.10  christos 
    266  1.1.1.10  christos static void ACPI_SYSTEM_XFACE
    267  1.1.1.10  christos AslSignalHandler (
    268  1.1.1.10  christos     int                     Sig)
    269  1.1.1.10  christos {
    270  1.1.1.10  christos     UINT32                  i;
    271  1.1.1.10  christos 
    272  1.1.1.10  christos 
    273  1.1.1.10  christos     signal (Sig, SIG_IGN);
    274  1.1.1.12  christos     fflush (stdout);
    275  1.1.1.12  christos     fflush (stderr);
    276  1.1.1.12  christos 
    277  1.1.1.12  christos     switch (Sig)
    278  1.1.1.12  christos     {
    279  1.1.1.12  christos     case SIGINT:
    280  1.1.1.12  christos 
    281  1.1.1.12  christos         printf ("\n" ASL_PREFIX "<Control-C>\n");
    282  1.1.1.12  christos         break;
    283  1.1.1.10  christos 
    284  1.1.1.12  christos     default:
    285  1.1.1.12  christos 
    286  1.1.1.15  christos         printf (ASL_PREFIX "Unknown interrupt signal (%d)\n", Sig);
    287  1.1.1.14  christos         break;
    288  1.1.1.12  christos     }
    289  1.1.1.12  christos 
    290  1.1.1.12  christos     /*
    291  1.1.1.12  christos      * Close all open files
    292  1.1.1.12  christos      * Note: the .pre file is the same as the input source file
    293  1.1.1.12  christos      */
    294  1.1.1.17  christos     if (AslGbl_Files)
    295  1.1.1.10  christos     {
    296  1.1.1.17  christos         AslGbl_Files[ASL_FILE_PREPROCESSOR].Handle = NULL;
    297  1.1.1.10  christos 
    298  1.1.1.17  christos         for (i = ASL_FILE_INPUT; i < ASL_MAX_FILE_TYPE; i++)
    299  1.1.1.17  christos         {
    300  1.1.1.17  christos             FlCloseFile (i);
    301  1.1.1.17  christos         }
    302  1.1.1.10  christos 
    303  1.1.1.17  christos         /* Delete any output files */
    304  1.1.1.17  christos 
    305  1.1.1.17  christos         for (i = ASL_FILE_AML_OUTPUT; i < ASL_MAX_FILE_TYPE; i++)
    306  1.1.1.17  christos         {
    307  1.1.1.17  christos             FlDeleteFile (i);
    308  1.1.1.17  christos         }
    309  1.1.1.10  christos     }
    310  1.1.1.10  christos 
    311  1.1.1.12  christos     printf (ASL_PREFIX "Terminating\n");
    312  1.1.1.20  christos     _exit (0);
    313  1.1.1.10  christos }
    314  1.1.1.10  christos 
    315  1.1.1.10  christos 
    316  1.1.1.10  christos /*******************************************************************************
    317  1.1.1.10  christos  *
    318  1.1.1.10  christos  * FUNCTION:    AslInitialize
    319  1.1.1.10  christos  *
    320  1.1.1.10  christos  * PARAMETERS:  None
    321  1.1.1.10  christos  *
    322  1.1.1.10  christos  * RETURN:      None
    323  1.1.1.10  christos  *
    324  1.1.1.10  christos  * DESCRIPTION: Initialize compiler globals
    325  1.1.1.10  christos  *
    326  1.1.1.10  christos  ******************************************************************************/
    327  1.1.1.10  christos 
    328  1.1.1.10  christos static void
    329  1.1.1.10  christos AslInitialize (
    330  1.1.1.10  christos     void)
    331  1.1.1.10  christos {
    332  1.1.1.10  christos     AcpiGbl_DmOpt_Verbose = FALSE;
    333  1.1.1.10  christos 
    334  1.1.1.12  christos     /* Default integer width is 32 bits */
    335  1.1.1.10  christos 
    336  1.1.1.12  christos     AcpiGbl_IntegerBitWidth = 32;
    337  1.1.1.12  christos     AcpiGbl_IntegerNybbleWidth = 8;
    338  1.1.1.12  christos     AcpiGbl_IntegerByteWidth = 4;
    339  1.1.1.10  christos }
    340