Home | History | Annotate | Line # | Download | only in acpiexec
aemain.c revision 1.1.1.10
      1 /******************************************************************************
      2  *
      3  * Module Name: aemain - Main routine for the AcpiExec utility
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2017, 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 #include "aecommon.h"
     45 
     46 #define _COMPONENT          ACPI_TOOLS
     47         ACPI_MODULE_NAME    ("aemain")
     48 
     49 
     50 /*
     51  * Main routine for the ACPI user-space execution utility.
     52  *
     53  * Portability note: The utility depends upon the host for command-line
     54  * wildcard support - it is not implemented locally. For example:
     55  *
     56  * Linux/Unix systems: Shell expands wildcards automatically.
     57  *
     58  * Windows: The setargv.obj module must be linked in to automatically
     59  * expand wildcards.
     60  */
     61 
     62 /* Local prototypes */
     63 
     64 static int
     65 AeDoOptions (
     66     int                     argc,
     67     char                    **argv);
     68 
     69 
     70 #define AE_BUFFER_SIZE              1024
     71 #define ASL_MAX_FILES               256
     72 
     73 /* Execution modes */
     74 
     75 #define AE_MODE_COMMAND_LOOP        0   /* Normal command execution loop */
     76 #define AE_MODE_BATCH_MULTIPLE      1   /* -b option to execute a command line */
     77 #define AE_MODE_BATCH_SINGLE        2   /* -m option to execute a single control method */
     78 
     79 
     80 /* Globals */
     81 
     82 UINT8                       AcpiGbl_RegionFillValue = 0;
     83 BOOLEAN                     AcpiGbl_IgnoreErrors = FALSE;
     84 BOOLEAN                     AcpiGbl_DbOpt_NoRegionSupport = FALSE;
     85 UINT8                       AcpiGbl_UseHwReducedFadt = FALSE;
     86 BOOLEAN                     AcpiGbl_DoInterfaceTests = FALSE;
     87 BOOLEAN                     AcpiGbl_LoadTestTables = FALSE;
     88 BOOLEAN                     AcpiGbl_AeLoadOnly = FALSE;
     89 static UINT8                AcpiGbl_ExecutionMode = AE_MODE_COMMAND_LOOP;
     90 static char                 BatchBuffer[AE_BUFFER_SIZE];    /* Batch command buffer */
     91 static char                 AeBuildDate[] = __DATE__;
     92 static char                 AeBuildTime[] = __TIME__;
     93 
     94 #define ACPIEXEC_NAME               "AML Execution/Debug Utility"
     95 #define AE_SUPPORTED_OPTIONS        "?b:d:e:f^ghi:lm^rv^:x:"
     96 
     97 
     98 /* Stubs for the disassembler */
     99 
    100 void
    101 MpSaveGpioInfo (
    102     ACPI_PARSE_OBJECT       *Op,
    103     AML_RESOURCE            *Resource,
    104     UINT32                  PinCount,
    105     UINT16                  *PinList,
    106     char                    *DeviceName)
    107 {
    108 }
    109 
    110 void
    111 MpSaveSerialInfo (
    112     ACPI_PARSE_OBJECT       *Op,
    113     AML_RESOURCE            *Resource,
    114     char                    *DeviceName)
    115 {
    116 }
    117 
    118 
    119 /******************************************************************************
    120  *
    121  * FUNCTION:    usage
    122  *
    123  * PARAMETERS:  None
    124  *
    125  * RETURN:      None
    126  *
    127  * DESCRIPTION: Print a usage message
    128  *
    129  *****************************************************************************/
    130 
    131 static void
    132 usage (
    133     void)
    134 {
    135 
    136     ACPI_USAGE_HEADER ("acpiexec [options] AMLfile1 AMLfile2 ...");
    137 
    138     ACPI_OPTION ("-b \"CommandLine\"",  "Batch mode command line execution (cmd1;cmd2;...)");
    139     ACPI_OPTION ("-h -?",               "Display this help message");
    140     ACPI_OPTION ("-m [Method]",         "Batch mode method execution. Default=MAIN");
    141     printf ("\n");
    142 
    143     ACPI_OPTION ("-da",                 "Disable method abort on error");
    144     ACPI_OPTION ("-di",                 "Disable execution of STA/INI methods during init");
    145     ACPI_OPTION ("-do",                 "Disable Operation Region address simulation");
    146     ACPI_OPTION ("-dr",                 "Disable repair of method return values");
    147     ACPI_OPTION ("-ds",                 "Disable method auto-serialization");
    148     ACPI_OPTION ("-dt",                 "Disable allocation tracking (performance)");
    149     printf ("\n");
    150 
    151     ACPI_OPTION ("-ed",                 "Enable timer output for Debug Object");
    152     ACPI_OPTION ("-ef",                 "Enable display of final memory statistics");
    153     ACPI_OPTION ("-ei",                 "Enable additional tests for ACPICA interfaces");
    154     ACPI_OPTION ("-el",                 "Enable loading of additional test tables");
    155     ACPI_OPTION ("-em",                 "Enable grouping of module-level code");
    156     ACPI_OPTION ("-ep",                 "Enable TermList parsing for scope objects");
    157     ACPI_OPTION ("-es",                 "Enable Interpreter Slack Mode");
    158     ACPI_OPTION ("-et",                 "Enable debug semaphore timeout");
    159     printf ("\n");
    160 
    161     ACPI_OPTION ("-fi <File>",          "Specify namespace initialization file");
    162     ACPI_OPTION ("-fv <Value>",         "Operation Region initialization fill value");
    163     printf ("\n");
    164 
    165     ACPI_OPTION ("-i <Count>",          "Maximum iterations for AML while loops");
    166     ACPI_OPTION ("-l",                  "Load tables and namespace only");
    167     ACPI_OPTION ("-r",                  "Use hardware-reduced FADT V5");
    168     ACPI_OPTION ("-v",                  "Display version information");
    169     ACPI_OPTION ("-vd",                 "Display build date and time");
    170     ACPI_OPTION ("-vi",                 "Verbose initialization output");
    171     ACPI_OPTION ("-vr",                 "Verbose region handler output");
    172     ACPI_OPTION ("-x <DebugLevel>",     "Debug output level");
    173 
    174     printf ("\n  From within the interactive mode, use '?' or \"help\" to see\n"
    175         "  a list of available AML Debugger commands\n");
    176 }
    177 
    178 
    179 /******************************************************************************
    180  *
    181  * FUNCTION:    AeDoOptions
    182  *
    183  * PARAMETERS:  argc/argv           - Standard argc/argv
    184  *
    185  * RETURN:      Status
    186  *
    187  * DESCRIPTION: Command line option processing
    188  *
    189  *****************************************************************************/
    190 
    191 static int
    192 AeDoOptions (
    193     int                     argc,
    194     char                    **argv)
    195 {
    196     int                     j;
    197     UINT32                  Temp;
    198 
    199 
    200     while ((j = AcpiGetopt (argc, argv, AE_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j)
    201     {
    202     case 'b':
    203 
    204         if (strlen (AcpiGbl_Optarg) > (AE_BUFFER_SIZE -1))
    205         {
    206             printf ("**** The length of command line (%u) exceeded maximum (%u)\n",
    207                 (UINT32) strlen (AcpiGbl_Optarg), (AE_BUFFER_SIZE -1));
    208             return (-1);
    209         }
    210         AcpiGbl_ExecutionMode = AE_MODE_BATCH_MULTIPLE;
    211         strcpy (BatchBuffer, AcpiGbl_Optarg);
    212         break;
    213 
    214     case 'd':
    215 
    216         switch (AcpiGbl_Optarg[0])
    217         {
    218         case 'a':
    219 
    220             AcpiGbl_IgnoreErrors = TRUE;
    221             break;
    222 
    223         case 'i':
    224 
    225             AcpiGbl_DbOpt_NoIniMethods = TRUE;
    226             break;
    227 
    228         case 'o':
    229 
    230             AcpiGbl_DbOpt_NoRegionSupport = TRUE;
    231             break;
    232 
    233         case 'r':
    234 
    235             AcpiGbl_DisableAutoRepair = TRUE;
    236             break;
    237 
    238         case 's':
    239 
    240             AcpiGbl_AutoSerializeMethods = FALSE;
    241             break;
    242 
    243         case 't':
    244 
    245             #ifdef ACPI_DBG_TRACK_ALLOCATIONS
    246                 AcpiGbl_DisableMemTracking = TRUE;
    247             #endif
    248             break;
    249 
    250         default:
    251 
    252             printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
    253             return (-1);
    254         }
    255         break;
    256 
    257     case 'e':
    258 
    259         switch (AcpiGbl_Optarg[0])
    260         {
    261         case 'd':
    262 
    263             AcpiGbl_DisplayDebugTimer = TRUE;
    264             break;
    265 
    266         case 'f':
    267 
    268             #ifdef ACPI_DBG_TRACK_ALLOCATIONS
    269                 AcpiGbl_DisplayFinalMemStats = TRUE;
    270             #endif
    271             break;
    272 
    273         case 'i':
    274 
    275             AcpiGbl_DoInterfaceTests = TRUE;
    276             break;
    277 
    278         case 'l':
    279 
    280             AcpiGbl_LoadTestTables = TRUE;
    281             break;
    282 
    283         case 'm':
    284 
    285             AcpiGbl_GroupModuleLevelCode = TRUE;
    286             break;
    287 
    288         case 'p':
    289 
    290             AcpiGbl_ParseTableAsTermList = TRUE;
    291             break;
    292 
    293         case 's':
    294 
    295             AcpiGbl_EnableInterpreterSlack = TRUE;
    296             printf ("Enabling AML Interpreter slack mode\n");
    297             break;
    298 
    299         case 't':
    300 
    301             AcpiGbl_DebugTimeout = TRUE;
    302             break;
    303 
    304         default:
    305 
    306             printf ("Unknown option: -e%s\n", AcpiGbl_Optarg);
    307             return (-1);
    308         }
    309         break;
    310 
    311     case 'f':
    312 
    313         switch (AcpiGbl_Optarg[0])
    314         {
    315         case 'v':   /* -fv: region fill value */
    316 
    317             if (AcpiGetoptArgument (argc, argv))
    318             {
    319                 return (-1);
    320             }
    321 
    322             AcpiGbl_RegionFillValue = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
    323             break;
    324 
    325         case 'i':   /* -fi: specify initialization file */
    326 
    327             if (AcpiGetoptArgument (argc, argv))
    328             {
    329                 return (-1);
    330             }
    331 
    332             if (AeOpenInitializationFile (AcpiGbl_Optarg))
    333             {
    334                 return (-1);
    335             }
    336             break;
    337 
    338         default:
    339 
    340             printf ("Unknown option: -f%s\n", AcpiGbl_Optarg);
    341             return (-1);
    342         }
    343         break;
    344 
    345     case 'g':
    346 
    347         AcpiGbl_DbFilename = NULL;
    348         break;
    349 
    350     case 'h':
    351     case '?':
    352 
    353         usage();
    354         return (1);
    355 
    356     case 'i':
    357 
    358         Temp = strtoul (AcpiGbl_Optarg, NULL, 0);
    359         if (!Temp || (Temp > ACPI_UINT16_MAX))
    360         {
    361             printf ("%s: Invalid max loops value\n", AcpiGbl_Optarg);
    362             return (-1);
    363         }
    364 
    365         AcpiGbl_MaxLoopIterations = (UINT16) Temp;
    366         printf ("Max Loop Iterations is %u (0x%X)\n",
    367             AcpiGbl_MaxLoopIterations, AcpiGbl_MaxLoopIterations);
    368         break;
    369 
    370     case 'l':
    371 
    372         AcpiGbl_AeLoadOnly = TRUE;
    373         break;
    374 
    375     case 'm':
    376 
    377         AcpiGbl_ExecutionMode = AE_MODE_BATCH_SINGLE;
    378         switch (AcpiGbl_Optarg[0])
    379         {
    380         case '^':
    381 
    382             strcpy (BatchBuffer, "MAIN");
    383             break;
    384 
    385         default:
    386 
    387             strcpy (BatchBuffer, AcpiGbl_Optarg);
    388             break;
    389         }
    390         break;
    391 
    392     case 'r':
    393 
    394         AcpiGbl_UseHwReducedFadt = TRUE;
    395         printf ("Using ACPI 5.0 Hardware Reduced Mode via version 5 FADT\n");
    396         break;
    397 
    398     case 'v':
    399 
    400         switch (AcpiGbl_Optarg[0])
    401         {
    402         case '^':  /* -v: (Version): signon already emitted, just exit */
    403 
    404             (void) AcpiOsTerminate ();
    405             return (1);
    406 
    407         case 'd':
    408 
    409             printf ("Build date/time: %s %s\n", AeBuildDate, AeBuildTime);
    410             return (1);
    411 
    412         case 'i':
    413 
    414             AcpiDbgLevel |= ACPI_LV_INIT_NAMES;
    415             break;
    416 
    417         case 'r':
    418 
    419             AcpiGbl_DisplayRegionAccess = TRUE;
    420             break;
    421 
    422         default:
    423 
    424             printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
    425             return (-1);
    426         }
    427         break;
    428 
    429     case 'x':
    430 
    431         AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 0);
    432         AcpiGbl_DbConsoleDebugLevel = AcpiDbgLevel;
    433         printf ("Debug Level: 0x%8.8X\n", AcpiDbgLevel);
    434         break;
    435 
    436     default:
    437 
    438         usage();
    439         return (-1);
    440     }
    441 
    442     return (0);
    443 }
    444 
    445 
    446 /******************************************************************************
    447  *
    448  * FUNCTION:    main
    449  *
    450  * PARAMETERS:  argc, argv
    451  *
    452  * RETURN:      Status
    453  *
    454  * DESCRIPTION: Main routine for AcpiExec utility
    455  *
    456  *****************************************************************************/
    457 
    458 int ACPI_SYSTEM_XFACE
    459 main (
    460     int                     argc,
    461     char                    **argv)
    462 {
    463     ACPI_NEW_TABLE_DESC     *ListHead = NULL;
    464     ACPI_STATUS             Status;
    465     UINT32                  InitFlags;
    466     int                     ExitCode = 0;
    467 
    468 
    469     ACPI_DEBUG_INITIALIZE (); /* For debug version only */
    470     signal (SIGINT, AeCtrlCHandler);
    471 
    472     /* Init debug globals */
    473 
    474     AcpiDbgLevel = ACPI_NORMAL_DEFAULT;
    475     AcpiDbgLayer = 0xFFFFFFFF;
    476 
    477     /*
    478      * Initialize ACPICA and start debugger thread.
    479      *
    480      * NOTE: After ACPICA initialization, AcpiTerminate MUST be called
    481      * before this procedure exits -- otherwise, the console may be
    482      * left in an incorrect state.
    483      */
    484     Status = AcpiInitializeSubsystem ();
    485     ACPI_CHECK_OK (AcpiInitializeSubsystem, Status);
    486     if (ACPI_FAILURE (Status))
    487     {
    488         goto ErrorExit;
    489     }
    490 
    491     /* ACPICA runtime configuration */
    492 
    493     AcpiGbl_MaxLoopIterations = 400;
    494 
    495 
    496     /* Initialize the AML debugger */
    497 
    498     Status = AcpiInitializeDebugger ();
    499     ACPI_CHECK_OK (AcpiInitializeDebugger, Status);
    500     if (ACPI_FAILURE (Status))
    501     {
    502         goto ErrorExit;
    503     }
    504 
    505     printf (ACPI_COMMON_SIGNON (ACPIEXEC_NAME));
    506     if (argc < 2)
    507     {
    508         usage ();
    509         goto NormalExit;
    510     }
    511 
    512     /* Get the command line options */
    513 
    514     ExitCode = AeDoOptions (argc, argv);
    515     if (ExitCode)
    516     {
    517         if (ExitCode > 0)
    518         {
    519             ExitCode = 0;
    520         }
    521 
    522         goto ErrorExit;
    523     }
    524 
    525     /* The remaining arguments are filenames for ACPI tables */
    526 
    527     if (!argv[AcpiGbl_Optind])
    528     {
    529         goto EnterDebugger;
    530     }
    531 
    532     AcpiGbl_CstyleDisassembly = FALSE; /* Not supported for AcpiExec */
    533 
    534     /* Get each of the ACPI table files on the command line */
    535 
    536     while (argv[AcpiGbl_Optind])
    537     {
    538         /* Get all ACPI AML tables in this file */
    539 
    540         Status = AcGetAllTablesFromFile (argv[AcpiGbl_Optind],
    541             ACPI_GET_ALL_TABLES, &ListHead);
    542         if (ACPI_FAILURE (Status))
    543         {
    544             ExitCode = -1;
    545             goto ErrorExit;
    546         }
    547 
    548         AcpiGbl_Optind++;
    549     }
    550 
    551     printf ("\n");
    552 
    553     /* Build a local RSDT with all tables and let ACPICA process the RSDT */
    554 
    555     Status = AeBuildLocalTables (ListHead);
    556     if (ACPI_FAILURE (Status))
    557     {
    558         goto ErrorExit;
    559     }
    560 
    561     /* Install all of the ACPI tables */
    562 
    563     Status = AeInstallTables ();
    564     if (ACPI_FAILURE (Status))
    565     {
    566         printf ("**** Could not install ACPI tables, %s\n",
    567             AcpiFormatException (Status));
    568         goto EnterDebugger;
    569     }
    570 
    571     /*
    572      * Install most of the handlers (Regions, Notify, Table, etc.)
    573      * Override the default region handlers, especially SystemMemory,
    574      * which is simulated in this utility.
    575      */
    576     Status = AeInstallEarlyHandlers ();
    577     if (ACPI_FAILURE (Status))
    578     {
    579         goto EnterDebugger;
    580     }
    581 
    582     /* Setup initialization flags for ACPICA */
    583 
    584     InitFlags = (ACPI_NO_HANDLER_INIT | ACPI_NO_ACPI_ENABLE);
    585     if (AcpiGbl_DbOpt_NoIniMethods)
    586     {
    587         InitFlags |= (ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT);
    588     }
    589 
    590     /*
    591      * Main initialization for ACPICA subsystem
    592      * TBD: Need a way to call this after the ACPI table "LOAD" command?
    593      *
    594      * NOTE: This initialization does not match the _Lxx and _Exx methods
    595      * to individual GPEs, as there are no real GPEs when the hardware
    596      * is simulated - because there is no namespace until AeLoadTables is
    597      * executed. This may have to change if AcpiExec is ever run natively
    598      * on actual hardware (such as under UEFI).
    599      */
    600     Status = AcpiEnableSubsystem (InitFlags);
    601     if (ACPI_FAILURE (Status))
    602     {
    603         printf ("**** Could not EnableSubsystem, %s\n",
    604             AcpiFormatException (Status));
    605         goto EnterDebugger;
    606     }
    607 
    608     Status = AeLoadTables ();
    609 
    610     /*
    611      * Exit namespace initialization for the "load namespace only" option.
    612      * No control methods will be executed. However, still enter the
    613      * the debugger.
    614      */
    615     if (AcpiGbl_AeLoadOnly)
    616     {
    617         goto EnterDebugger;
    618     }
    619 
    620     if (ACPI_FAILURE (Status))
    621     {
    622         printf ("**** Could not load ACPI tables, %s\n",
    623             AcpiFormatException (Status));
    624         goto EnterDebugger;
    625     }
    626 
    627     /*
    628      * Install handlers for "device driver" space IDs (EC,SMBus, etc.)
    629      * and fixed event handlers
    630      */
    631     AeInstallLateHandlers ();
    632 
    633     /* Finish the ACPICA initialization */
    634 
    635     Status = AcpiInitializeObjects (InitFlags);
    636     if (ACPI_FAILURE (Status))
    637     {
    638         printf ("**** Could not InitializeObjects, %s\n",
    639             AcpiFormatException (Status));
    640         goto EnterDebugger;
    641     }
    642 
    643     AeMiscellaneousTests ();
    644 
    645 
    646 EnterDebugger:
    647 
    648     /* Exit if error above and we are in one of the batch modes */
    649 
    650     if (ACPI_FAILURE (Status) && (AcpiGbl_ExecutionMode > 0))
    651     {
    652         goto ErrorExit;
    653     }
    654 
    655     /* Run a batch command or enter the command loop */
    656 
    657     switch (AcpiGbl_ExecutionMode)
    658     {
    659     default:
    660     case AE_MODE_COMMAND_LOOP:
    661 
    662         AcpiRunDebugger (NULL);
    663         break;
    664 
    665     case AE_MODE_BATCH_MULTIPLE:
    666 
    667         AcpiRunDebugger (BatchBuffer);
    668         break;
    669 
    670     case AE_MODE_BATCH_SINGLE:
    671 
    672         AcpiDbExecute (BatchBuffer, NULL, NULL, EX_NO_SINGLE_STEP);
    673         break;
    674     }
    675 
    676     /* Shut down the debugger and ACPICA */
    677 
    678     AcpiTerminateDebugger ();
    679 
    680 NormalExit:
    681     ExitCode = 0;
    682 
    683 ErrorExit:
    684     (void) AcpiOsTerminate ();
    685     return (ExitCode);
    686 }
    687