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