1 /******************************************************************************
3 * Module Name: aemain - Main routine for the AcpiExec utility
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
46 #define _COMPONENT ACPI_TOOLS
47 ACPI_MODULE_NAME ("aemain")
51 * Main routine for the ACPI user-space execution utility.
53 * Portability note: The utility depends upon the host for command-line
54 * wildcard support - it is not implemented locally. For example:
56 * Linux/Unix systems: Shell expands wildcards automatically.
58 * Windows: The setargv.obj module must be linked in to automatically
61 extern BOOLEAN AcpiGbl_DebugTimeout;
63 /* Local prototypes */
75 #define AE_BUFFER_SIZE 1024
76 #define ASL_MAX_FILES 256
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 */
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;
97 #define ACPIEXEC_NAME "AML Execution/Debug Utility"
98 #define AE_SUPPORTED_OPTIONS "?b:d:e:f:ghm^orv^:x:"
101 /******************************************************************************
109 * DESCRIPTION: Print a usage message
111 *****************************************************************************/
118 ACPI_USAGE_HEADER ("acpiexec [options] AMLfile1 AMLfile2 ...");
120 ACPI_OPTION ("-b \"CommandLine\"", "Batch mode command line execution (cmd1;cmd2;...)");
121 ACPI_OPTION ("-h -?", "Display this help message");
122 ACPI_OPTION ("-m [Method]", "Batch mode method execution. Default=MAIN");
125 ACPI_OPTION ("-da", "Disable method abort on error");
126 ACPI_OPTION ("-di", "Disable execution of STA/INI methods during init");
127 ACPI_OPTION ("-do", "Disable Operation Region address simulation");
128 ACPI_OPTION ("-dr", "Disable repair of method return values");
129 ACPI_OPTION ("-ds", "Disable method auto-serialization");
130 ACPI_OPTION ("-dt", "Disable allocation tracking (performance)");
133 ACPI_OPTION ("-ef", "Enable display of final memory statistics");
134 ACPI_OPTION ("-ei", "Enable additional tests for ACPICA interfaces");
135 ACPI_OPTION ("-el", "Enable loading of additional test tables");
136 ACPI_OPTION ("-es", "Enable Interpreter Slack Mode");
137 ACPI_OPTION ("-et", "Enable debug semaphore timeout");
140 ACPI_OPTION ("-f <Value>", "Operation Region initialization fill value");
141 ACPI_OPTION ("-r", "Use hardware-reduced FADT V5");
142 ACPI_OPTION ("-v", "Display version information");
143 ACPI_OPTION ("-vi", "Verbose initialization output");
144 ACPI_OPTION ("-vr", "Verbose region handler output");
145 ACPI_OPTION ("-x <DebugLevel>", "Debug output level");
149 /******************************************************************************
151 * FUNCTION: AeDoOptions
153 * PARAMETERS: argc/argv - Standard argc/argv
157 * DESCRIPTION: Command line option processing
159 *****************************************************************************/
169 while ((j = AcpiGetopt (argc, argv, AE_SUPPORTED_OPTIONS)) != EOF) switch (j)
173 if (strlen (AcpiGbl_Optarg) > (AE_BUFFER_SIZE -1))
175 printf ("**** The length of command line (%u) exceeded maximum (%u)\n",
176 (UINT32) strlen (AcpiGbl_Optarg), (AE_BUFFER_SIZE -1));
179 AcpiGbl_ExecutionMode = AE_MODE_BATCH_MULTIPLE;
180 strcpy (BatchBuffer, AcpiGbl_Optarg);
185 switch (AcpiGbl_Optarg[0])
189 AcpiGbl_IgnoreErrors = TRUE;
194 AcpiGbl_DbOpt_ini_methods = FALSE;
199 AcpiGbl_DbOpt_NoRegionSupport = TRUE;
204 AcpiGbl_DisableAutoRepair = TRUE;
209 AcpiGbl_AutoSerializeMethods = FALSE;
214 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
215 AcpiGbl_DisableMemTracking = TRUE;
221 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
228 switch (AcpiGbl_Optarg[0])
232 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
233 AcpiGbl_DisplayFinalMemStats = TRUE;
239 AcpiGbl_DoInterfaceTests = TRUE;
244 AcpiGbl_LoadTestTables = TRUE;
249 AcpiGbl_EnableInterpreterSlack = TRUE;
250 printf ("Enabling AML Interpreter slack mode\n");
255 AcpiGbl_DebugTimeout = TRUE;
260 printf ("Unknown option: -e%s\n", AcpiGbl_Optarg);
267 AcpiGbl_RegionFillValue = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
272 AcpiGbl_DbOpt_tables = TRUE;
273 AcpiGbl_DbFilename = NULL;
284 AcpiGbl_ExecutionMode = AE_MODE_BATCH_SINGLE;
285 switch (AcpiGbl_Optarg[0])
289 strcpy (BatchBuffer, "MAIN");
294 strcpy (BatchBuffer, AcpiGbl_Optarg);
301 AcpiGbl_DbOpt_disasm = TRUE;
302 AcpiGbl_DbOpt_stats = TRUE;
307 AcpiGbl_UseHwReducedFadt = TRUE;
308 printf ("Using ACPI 5.0 Hardware Reduced Mode via version 5 FADT\n");
313 switch (AcpiGbl_Optarg[0])
315 case '^': /* -v: (Version): signon already emitted, just exit */
321 AcpiDbgLevel |= ACPI_LV_INIT_NAMES;
326 AcpiGbl_DisplayRegionAccess = TRUE;
331 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
338 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 0);
339 AcpiGbl_DbConsoleDebugLevel = AcpiDbgLevel;
340 printf ("Debug Level: 0x%8.8X\n", AcpiDbgLevel);
353 /******************************************************************************
357 * PARAMETERS: argc, argv
361 * DESCRIPTION: Main routine for AcpiExec utility
363 *****************************************************************************/
365 int ACPI_SYSTEM_XFACE
372 ACPI_TABLE_HEADER *Table = NULL;
374 AE_TABLE_DESC *TableDesc;
377 ACPI_DEBUG_INITIALIZE (); /* For debug version only */
379 printf (ACPI_COMMON_SIGNON (ACPIEXEC_NAME));
386 signal (SIGINT, AeCtrlCHandler);
390 AcpiDbgLevel = ACPI_NORMAL_DEFAULT;
391 AcpiDbgLayer = 0xFFFFFFFF;
393 /* Init ACPI and start debugger thread */
395 Status = AcpiInitializeSubsystem ();
396 AE_CHECK_OK (AcpiInitializeSubsystem, Status);
397 if (ACPI_FAILURE (Status))
402 /* Get the command line options */
404 if (AeDoOptions (argc, argv))
409 /* The remaining arguments are filenames for ACPI tables */
411 if (!argv[AcpiGbl_Optind])
416 AcpiGbl_DbOpt_tables = TRUE;
419 /* Get each of the ACPI table files on the command line */
421 while (argv[AcpiGbl_Optind])
423 /* Get one entire table */
425 Status = AcpiDbReadTableFromFile (argv[AcpiGbl_Optind], &Table);
426 if (ACPI_FAILURE (Status))
428 printf ("**** Could not get table from file %s, %s\n",
429 argv[AcpiGbl_Optind], AcpiFormatException (Status));
433 /* Ignore non-AML tables, we can't use them. Except for an FADT */
435 if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_FADT) &&
436 !AcpiUtIsAmlTable (Table))
439 "Table [%4.4s] is not an AML table, ignoring",
445 /* Allocate and link a table descriptor */
447 TableDesc = AcpiOsAllocate (sizeof (AE_TABLE_DESC));
448 TableDesc->Table = Table;
449 TableDesc->Next = AeTableListHead;
450 AeTableListHead = TableDesc;
460 /* Build a local RSDT with all tables and let ACPICA process the RSDT */
462 Status = AeBuildLocalTables (TableCount, AeTableListHead);
463 if (ACPI_FAILURE (Status))
468 Status = AeInstallTables ();
469 if (ACPI_FAILURE (Status))
471 printf ("**** Could not load ACPI tables, %s\n",
472 AcpiFormatException (Status));
477 * Install most of the handlers.
478 * Override some default region handlers, especially SystemMemory
480 Status = AeInstallEarlyHandlers ();
481 if (ACPI_FAILURE (Status))
486 /* Setup initialization flags for ACPICA */
488 InitFlags = (ACPI_NO_HANDLER_INIT | ACPI_NO_ACPI_ENABLE);
489 if (!AcpiGbl_DbOpt_ini_methods)
491 InitFlags |= (ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT);
495 * Main initialization for ACPICA subsystem
496 * TBD: Need a way to call this after the ACPI table "LOAD" command
498 Status = AcpiEnableSubsystem (InitFlags);
499 if (ACPI_FAILURE (Status))
501 printf ("**** Could not EnableSubsystem, %s\n",
502 AcpiFormatException (Status));
507 * Install handlers for "device driver" space IDs (EC,SMBus, etc.)
508 * and fixed event handlers
510 AeInstallLateHandlers ();
512 /* Finish the ACPICA initialization */
514 Status = AcpiInitializeObjects (InitFlags);
515 if (ACPI_FAILURE (Status))
517 printf ("**** Could not InitializeObjects, %s\n",
518 AcpiFormatException (Status));
522 AeMiscellaneousTests ();
527 /* Exit if error above and we are in one of the batch modes */
529 if (ACPI_FAILURE (Status) && (AcpiGbl_ExecutionMode > 0))
534 /* Run a batch command or enter the command loop */
536 switch (AcpiGbl_ExecutionMode)
539 case AE_MODE_COMMAND_LOOP:
541 AcpiDbUserCommands (ACPI_DEBUGGER_COMMAND_PROMPT, NULL);
544 case AE_MODE_BATCH_MULTIPLE:
546 AcpiDbRunBatchMode ();
549 case AE_MODE_BATCH_SINGLE:
551 AcpiDbExecute (BatchBuffer, NULL, NULL, EX_NO_SINGLE_STEP);
552 Status = AcpiTerminate ();
561 (void) AcpiOsTerminate ();
566 /******************************************************************************
568 * FUNCTION: AcpiDbRunBatchMode
570 * PARAMETERS: BatchCommandLine - A semicolon separated list of commands
572 * Use only commas to separate elements of
573 * particular command.
576 * DESCRIPTION: For each command of list separated by ';' prepare the command
577 * buffer and pass it to AcpiDbCommandDispatch.
579 *****************************************************************************/
586 char *Ptr = BatchBuffer;
591 AcpiGbl_MethodExecuting = FALSE;
592 AcpiGbl_StepToNextCall = FALSE;
598 /* Convert commas to spaces */
601 else if (*Ptr == ';')
609 if (Run || (*Ptr == '\0'))
611 (void) AcpiDbCommandDispatch (Cmd, NULL, NULL);
617 Status = AcpiTerminate ();