1 /******************************************************************************
3 * Module Name: aemain - Main routine for the AcpiExec utility
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, 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 /* Stubs for the disassembler */
105 ACPI_PARSE_OBJECT *Op,
106 AML_RESOURCE *Resource,
115 ACPI_PARSE_OBJECT *Op,
116 AML_RESOURCE *Resource,
122 /******************************************************************************
130 * DESCRIPTION: Print a usage message
132 *****************************************************************************/
139 ACPI_USAGE_HEADER ("acpiexec [options] AMLfile1 AMLfile2 ...");
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");
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)");
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");
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");
169 printf ("\n From within the interactive mode, use '?' or \"help\" to see\n"
170 " a list of available AML Debugger commands\n");
174 /******************************************************************************
176 * FUNCTION: AeDoOptions
178 * PARAMETERS: argc/argv - Standard argc/argv
182 * DESCRIPTION: Command line option processing
184 *****************************************************************************/
194 while ((j = AcpiGetopt (argc, argv, AE_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j)
198 if (strlen (AcpiGbl_Optarg) > (AE_BUFFER_SIZE -1))
200 printf ("**** The length of command line (%u) exceeded maximum (%u)\n",
201 (UINT32) strlen (AcpiGbl_Optarg), (AE_BUFFER_SIZE -1));
204 AcpiGbl_ExecutionMode = AE_MODE_BATCH_MULTIPLE;
205 strcpy (BatchBuffer, AcpiGbl_Optarg);
210 switch (AcpiGbl_Optarg[0])
214 AcpiGbl_IgnoreErrors = TRUE;
219 AcpiGbl_DbOpt_NoIniMethods = TRUE;
224 AcpiGbl_DbOpt_NoRegionSupport = TRUE;
229 AcpiGbl_DisableAutoRepair = TRUE;
234 AcpiGbl_AutoSerializeMethods = FALSE;
239 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
240 AcpiGbl_DisableMemTracking = TRUE;
246 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
253 switch (AcpiGbl_Optarg[0])
257 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
258 AcpiGbl_DisplayFinalMemStats = TRUE;
264 AcpiGbl_DoInterfaceTests = TRUE;
269 AcpiGbl_LoadTestTables = TRUE;
274 AcpiGbl_EnableInterpreterSlack = TRUE;
275 printf ("Enabling AML Interpreter slack mode\n");
280 AcpiGbl_DebugTimeout = TRUE;
285 printf ("Unknown option: -e%s\n", AcpiGbl_Optarg);
292 switch (AcpiGbl_Optarg[0])
294 case 'v': /* -fv: region fill value */
296 if (AcpiGetoptArgument (argc, argv))
301 AcpiGbl_RegionFillValue = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
304 case 'i': /* -fi: specify initialization file */
306 if (AcpiGetoptArgument (argc, argv))
311 if (AeOpenInitializationFile (AcpiGbl_Optarg))
319 printf ("Unknown option: -f%s\n", AcpiGbl_Optarg);
326 AcpiGbl_DbFilename = NULL;
337 AcpiGbl_ExecutionMode = AE_MODE_BATCH_SINGLE;
338 switch (AcpiGbl_Optarg[0])
342 strcpy (BatchBuffer, "MAIN");
347 strcpy (BatchBuffer, AcpiGbl_Optarg);
354 AcpiGbl_DbOpt_Disasm = TRUE;
359 AcpiGbl_UseHwReducedFadt = TRUE;
360 printf ("Using ACPI 5.0 Hardware Reduced Mode via version 5 FADT\n");
365 switch (AcpiGbl_Optarg[0])
367 case '^': /* -v: (Version): signon already emitted, just exit */
369 (void) AcpiOsTerminate ();
374 AcpiDbgLevel |= ACPI_LV_INIT_NAMES;
379 AcpiGbl_DisplayRegionAccess = TRUE;
384 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
391 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 0);
392 AcpiGbl_DbConsoleDebugLevel = AcpiDbgLevel;
393 printf ("Debug Level: 0x%8.8X\n", AcpiDbgLevel);
406 /******************************************************************************
410 * PARAMETERS: argc, argv
414 * DESCRIPTION: Main routine for AcpiExec utility
416 *****************************************************************************/
418 int ACPI_SYSTEM_XFACE
425 ACPI_TABLE_HEADER *Table = NULL;
427 AE_TABLE_DESC *TableDesc;
430 ACPI_DEBUG_INITIALIZE (); /* For debug version only */
431 signal (SIGINT, AeCtrlCHandler);
433 /* Init debug globals */
435 AcpiDbgLevel = ACPI_NORMAL_DEFAULT;
436 AcpiDbgLayer = 0xFFFFFFFF;
438 /* Init ACPICA and start debugger thread */
440 Status = AcpiInitializeSubsystem ();
441 AE_CHECK_OK (AcpiInitializeSubsystem, Status);
442 if (ACPI_FAILURE (Status))
447 printf (ACPI_COMMON_SIGNON (ACPIEXEC_NAME));
451 (void) AcpiOsTerminate ();
455 /* Get the command line options */
457 if (AeDoOptions (argc, argv))
462 /* The remaining arguments are filenames for ACPI tables */
464 if (!argv[AcpiGbl_Optind])
469 AcpiGbl_CstyleDisassembly = FALSE; /* Not supported for AcpiExec */
472 /* Get each of the ACPI table files on the command line */
474 while (argv[AcpiGbl_Optind])
476 /* Get one entire table */
478 Status = AcpiUtReadTableFromFile (argv[AcpiGbl_Optind], &Table);
479 if (ACPI_FAILURE (Status))
481 printf ("**** Could not get table from file %s, %s\n",
482 argv[AcpiGbl_Optind], AcpiFormatException (Status));
486 /* Ignore non-AML tables, we can't use them. Except for an FADT */
488 if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_FADT) &&
489 !AcpiUtIsAmlTable (Table))
492 "Table [%4.4s] is not an AML table, ignoring",
498 /* Allocate and link a table descriptor */
500 TableDesc = AcpiOsAllocate (sizeof (AE_TABLE_DESC));
501 TableDesc->Table = Table;
502 TableDesc->Next = AeTableListHead;
503 AeTableListHead = TableDesc;
513 /* Build a local RSDT with all tables and let ACPICA process the RSDT */
515 Status = AeBuildLocalTables (TableCount, AeTableListHead);
516 if (ACPI_FAILURE (Status))
521 Status = AeInstallTables ();
522 if (ACPI_FAILURE (Status))
524 printf ("**** Could not load ACPI tables, %s\n",
525 AcpiFormatException (Status));
530 * Install most of the handlers.
531 * Override some default region handlers, especially SystemMemory
533 Status = AeInstallEarlyHandlers ();
534 if (ACPI_FAILURE (Status))
539 /* Setup initialization flags for ACPICA */
541 InitFlags = (ACPI_NO_HANDLER_INIT | ACPI_NO_ACPI_ENABLE);
542 if (AcpiGbl_DbOpt_NoIniMethods)
544 InitFlags |= (ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT);
548 * Main initialization for ACPICA subsystem
549 * TBD: Need a way to call this after the ACPI table "LOAD" command
551 Status = AcpiEnableSubsystem (InitFlags);
552 if (ACPI_FAILURE (Status))
554 printf ("**** Could not EnableSubsystem, %s\n",
555 AcpiFormatException (Status));
560 * Install handlers for "device driver" space IDs (EC,SMBus, etc.)
561 * and fixed event handlers
563 AeInstallLateHandlers ();
565 /* Finish the ACPICA initialization */
567 Status = AcpiInitializeObjects (InitFlags);
568 if (ACPI_FAILURE (Status))
570 printf ("**** Could not InitializeObjects, %s\n",
571 AcpiFormatException (Status));
575 AeMiscellaneousTests ();
580 /* Exit if error above and we are in one of the batch modes */
582 if (ACPI_FAILURE (Status) && (AcpiGbl_ExecutionMode > 0))
587 /* Run a batch command or enter the command loop */
589 switch (AcpiGbl_ExecutionMode)
592 case AE_MODE_COMMAND_LOOP:
594 AcpiDbUserCommands (ACPI_DEBUGGER_COMMAND_PROMPT, NULL);
597 case AE_MODE_BATCH_MULTIPLE:
599 AcpiDbRunBatchMode ();
602 case AE_MODE_BATCH_SINGLE:
604 AcpiDbExecute (BatchBuffer, NULL, NULL, EX_NO_SINGLE_STEP);
605 Status = AcpiTerminate ();
613 (void) AcpiOsTerminate ();
618 /******************************************************************************
620 * FUNCTION: AcpiDbRunBatchMode
622 * PARAMETERS: BatchCommandLine - A semicolon separated list of commands
624 * Use only commas to separate elements of
625 * particular command.
628 * DESCRIPTION: For each command of list separated by ';' prepare the command
629 * buffer and pass it to AcpiDbCommandDispatch.
631 *****************************************************************************/
638 char *Ptr = BatchBuffer;
643 AcpiGbl_MethodExecuting = FALSE;
644 AcpiGbl_StepToNextCall = FALSE;
650 /* Convert commas to spaces */
653 else if (*Ptr == ';')
661 if (Run || (*Ptr == '\0'))
663 (void) AcpiDbCommandDispatch (Cmd, NULL, NULL);
669 Status = AcpiTerminate ();