1 /******************************************************************************
3 * Module Name: aemain - Main routine for the AcpiExec utility
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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")
50 /* Local prototypes */
67 char *DirectoryPathname,
71 #define AE_BUFFER_SIZE 1024
72 #define ASL_MAX_FILES 256
76 #define AE_MODE_COMMAND_LOOP 0 /* Normal command execution loop */
77 #define AE_MODE_BATCH_MULTIPLE 1 /* -b option to execute a command line */
78 #define AE_MODE_BATCH_SINGLE 2 /* -m option to execute a single control method */
83 UINT8 AcpiGbl_RegionFillValue = 0;
84 BOOLEAN AcpiGbl_IgnoreErrors = FALSE;
85 BOOLEAN AcpiGbl_DbOpt_NoRegionSupport = FALSE;
86 BOOLEAN AcpiGbl_DebugTimeout = FALSE;
87 UINT8 AcpiGbl_UseHwReducedFadt = FALSE;
88 BOOLEAN AcpiGbl_DoInterfaceTests = FALSE;
89 static UINT8 AcpiGbl_ExecutionMode = AE_MODE_COMMAND_LOOP;
90 static char BatchBuffer[AE_BUFFER_SIZE]; /* Batch command buffer */
91 static char *FileList[ASL_MAX_FILES];
92 static AE_TABLE_DESC *AeTableListHead = NULL;
94 #define AE_SUPPORTED_OPTIONS "?b:d:e:f:ghm^orv:x:"
97 /******************************************************************************
105 * DESCRIPTION: Print a usage message
107 *****************************************************************************/
114 ACPI_USAGE_HEADER ("acpiexec [options] AMLfile1 AMLfile2 ...");
116 ACPI_OPTION ("-b \"CommandLine\"", "Batch mode command line execution (cmd1;cmd2;...)");
117 ACPI_OPTION ("-h -?", "Display this help message");
118 ACPI_OPTION ("-m [Method]", "Batch mode method execution. Default=MAIN");
121 ACPI_OPTION ("-da", "Disable method abort on error");
122 ACPI_OPTION ("-di", "Disable execution of STA/INI methods during init");
123 ACPI_OPTION ("-do", "Disable Operation Region address simulation");
124 ACPI_OPTION ("-dr", "Disable repair of method return values");
125 ACPI_OPTION ("-dt", "Disable allocation tracking (performance)");
128 ACPI_OPTION ("-ef", "Enable display of final memory statistics");
129 ACPI_OPTION ("-ei", "Enable additional tests for ACPICA interfaces");
130 ACPI_OPTION ("-em", "Enable Interpreter Serialized Mode");
131 ACPI_OPTION ("-es", "Enable Interpreter Slack Mode");
132 ACPI_OPTION ("-et", "Enable debug semaphore timeout");
135 ACPI_OPTION ("-f <Value>", "Operation Region initialization fill value");
136 ACPI_OPTION ("-r", "Use hardware-reduced FADT V5");
137 ACPI_OPTION ("-vi", "Verbose initialization output");
138 ACPI_OPTION ("-vr", "Verbose region handler output");
139 ACPI_OPTION ("-x <DebugLevel>", "Debug output level");
143 /******************************************************************************
145 * FUNCTION: AeDoOptions
147 * PARAMETERS: argc/argv - Standard argc/argv
151 * DESCRIPTION: Command line option processing
153 *****************************************************************************/
163 while ((j = AcpiGetopt (argc, argv, AE_SUPPORTED_OPTIONS)) != EOF) switch (j)
167 if (strlen (AcpiGbl_Optarg) > (AE_BUFFER_SIZE -1))
169 printf ("**** The length of command line (%u) exceeded maximum (%u)\n",
170 (UINT32) strlen (AcpiGbl_Optarg), (AE_BUFFER_SIZE -1));
173 AcpiGbl_ExecutionMode = AE_MODE_BATCH_MULTIPLE;
174 strcpy (BatchBuffer, AcpiGbl_Optarg);
179 switch (AcpiGbl_Optarg[0])
183 AcpiGbl_IgnoreErrors = TRUE;
188 AcpiGbl_DbOpt_ini_methods = FALSE;
193 AcpiGbl_DbOpt_NoRegionSupport = TRUE;
198 AcpiGbl_DisableAutoRepair = TRUE;
203 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
204 AcpiGbl_DisableMemTracking = TRUE;
210 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
217 switch (AcpiGbl_Optarg[0])
221 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
222 AcpiGbl_DisplayFinalMemStats = TRUE;
228 AcpiGbl_DoInterfaceTests = TRUE;
233 AcpiGbl_AllMethodsSerialized = TRUE;
234 printf ("Enabling AML Interpreter serialized mode\n");
239 AcpiGbl_EnableInterpreterSlack = TRUE;
240 printf ("Enabling AML Interpreter slack mode\n");
245 AcpiGbl_DebugTimeout = TRUE;
250 printf ("Unknown option: -e%s\n", AcpiGbl_Optarg);
257 AcpiGbl_RegionFillValue = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
262 AcpiGbl_DbOpt_tables = TRUE;
263 AcpiGbl_DbFilename = NULL;
274 AcpiGbl_ExecutionMode = AE_MODE_BATCH_SINGLE;
275 switch (AcpiGbl_Optarg[0])
279 strcpy (BatchBuffer, "MAIN");
284 strcpy (BatchBuffer, AcpiGbl_Optarg);
291 AcpiGbl_DbOpt_disasm = TRUE;
292 AcpiGbl_DbOpt_stats = TRUE;
297 AcpiGbl_UseHwReducedFadt = TRUE;
298 printf ("Using ACPI 5.0 Hardware Reduced Mode via version 5 FADT\n");
303 switch (AcpiGbl_Optarg[0])
307 AcpiDbgLevel |= ACPI_LV_INIT_NAMES;
312 AcpiGbl_DisplayRegionAccess = TRUE;
317 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
324 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 0);
325 AcpiGbl_DbConsoleDebugLevel = AcpiDbgLevel;
326 printf ("Debug Level: 0x%8.8X\n", AcpiDbgLevel);
339 /******************************************************************************
343 * PARAMETERS: argc, argv
347 * DESCRIPTION: Main routine for AcpiExec utility
349 *****************************************************************************/
351 int ACPI_SYSTEM_XFACE
358 ACPI_TABLE_HEADER *Table = NULL;
360 AE_TABLE_DESC *TableDesc;
367 ACPI_DEBUG_INITIALIZE (); /* For debug version only */
369 printf (ACPI_COMMON_SIGNON ("AML Execution/Debug Utility"));
376 signal (SIGINT, AeCtrlCHandler);
380 AcpiDbgLevel = ACPI_NORMAL_DEFAULT;
381 AcpiDbgLayer = 0xFFFFFFFF;
383 /* Init ACPI and start debugger thread */
385 Status = AcpiInitializeSubsystem ();
386 AE_CHECK_OK (AcpiInitializeSubsystem, Status);
387 if (ACPI_FAILURE (Status))
392 /* Get the command line options */
394 if (AeDoOptions (argc, argv))
399 /* The remaining arguments are filenames for ACPI tables */
401 if (argv[AcpiGbl_Optind])
403 AcpiGbl_DbOpt_tables = TRUE;
406 /* Get each of the ACPI table files on the command line */
408 while (argv[AcpiGbl_Optind])
410 /* Split incoming path into a directory/filename combo */
412 Status = FlSplitInputPathname (argv[AcpiGbl_Optind],
413 &Directory, &Filename);
414 if (ACPI_FAILURE (Status))
419 /* Expand wildcards (Windows only) */
421 WildcardList = AsDoWildcard (Directory, Filename);
427 while (*WildcardList)
429 FullPathname = AcpiOsAllocate (
430 strlen (Directory) + strlen (*WildcardList) + 1);
432 /* Construct a full path to the file */
434 strcpy (FullPathname, Directory);
435 strcat (FullPathname, *WildcardList);
439 Status = AcpiDbReadTableFromFile (FullPathname, &Table);
440 if (ACPI_FAILURE (Status))
442 printf ("**** Could not get input table %s, %s\n",
443 FullPathname, AcpiFormatException (Status));
447 AcpiOsFree (FullPathname);
448 AcpiOsFree (*WildcardList);
449 *WildcardList = NULL;
452 /* Ignore non-AML tables, we can't use them. Except for an FADT */
454 if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_FADT) &&
455 !AcpiUtIsAmlTable (Table))
457 ACPI_WARNING ((AE_INFO,
458 "Table %4.4s is not an AML table, ignoring",
464 /* Allocate and link a table descriptor */
466 TableDesc = AcpiOsAllocate (sizeof (AE_TABLE_DESC));
467 TableDesc->Table = Table;
468 TableDesc->Next = AeTableListHead;
469 AeTableListHead = TableDesc;
477 /* Build a local RSDT with all tables and let ACPICA process the RSDT */
479 Status = AeBuildLocalTables (TableCount, AeTableListHead);
480 if (ACPI_FAILURE (Status))
485 Status = AeInstallTables ();
486 if (ACPI_FAILURE (Status))
488 printf ("**** Could not load ACPI tables, %s\n",
489 AcpiFormatException (Status));
494 * Install most of the handlers.
495 * Override some default region handlers, especially SystemMemory
497 Status = AeInstallEarlyHandlers ();
498 if (ACPI_FAILURE (Status))
503 /* Setup initialization flags for ACPICA */
505 InitFlags = (ACPI_NO_HANDLER_INIT | ACPI_NO_ACPI_ENABLE);
506 if (!AcpiGbl_DbOpt_ini_methods)
508 InitFlags |= (ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT);
512 * Main initialization for ACPICA subsystem
513 * TBD: Need a way to call this after the ACPI table "LOAD" command
515 Status = AcpiEnableSubsystem (InitFlags);
516 if (ACPI_FAILURE (Status))
518 printf ("**** Could not EnableSubsystem, %s\n",
519 AcpiFormatException (Status));
524 * Install handlers for "device driver" space IDs (EC,SMBus, etc.)
525 * and fixed event handlers
527 AeInstallLateHandlers ();
529 /* Finish the ACPICA initialization */
531 Status = AcpiInitializeObjects (InitFlags);
532 if (ACPI_FAILURE (Status))
534 printf ("**** Could not InitializeObjects, %s\n",
535 AcpiFormatException (Status));
539 AeMiscellaneousTests ();
544 /* Exit if error above and we are in one of the batch modes */
546 if (ACPI_FAILURE (Status) && (AcpiGbl_ExecutionMode > 0))
551 /* Run a batch command or enter the command loop */
553 switch (AcpiGbl_ExecutionMode)
556 case AE_MODE_COMMAND_LOOP:
558 AcpiDbUserCommands (ACPI_DEBUGGER_COMMAND_PROMPT, NULL);
561 case AE_MODE_BATCH_MULTIPLE:
563 AcpiDbRunBatchMode ();
566 case AE_MODE_BATCH_SINGLE:
568 AcpiDbExecute (BatchBuffer, NULL, NULL, EX_NO_SINGLE_STEP);
576 /******************************************************************************
578 * FUNCTION: AcpiDbRunBatchMode
580 * PARAMETERS: BatchCommandLine - A semicolon separated list of commands
582 * Use only commas to separate elements of
583 * particular command.
586 * DESCRIPTION: For each command of list separated by ';' prepare the command
587 * buffer and pass it to AcpiDbCommandDispatch.
589 *****************************************************************************/
596 char *Ptr = BatchBuffer;
601 AcpiGbl_MethodExecuting = FALSE;
602 AcpiGbl_StepToNextCall = FALSE;
608 /* Convert commas to spaces */
611 else if (*Ptr == ';')
619 if (Run || (*Ptr == '\0'))
621 (void) AcpiDbCommandDispatch (Cmd, NULL, NULL);
627 Status = AcpiTerminate ();
632 /******************************************************************************
636 * DESCRIPTION: Local strdup function
638 *****************************************************************************/
647 NewString = AcpiOsAllocate (strlen (String) + 1);
653 strcpy (NewString, String);
658 /******************************************************************************
660 * FUNCTION: FlSplitInputPathname
662 * PARAMETERS: InputFilename - The user-specified ASL source file to be
664 * OutDirectoryPath - Where the directory path prefix is
666 * OutFilename - Where the filename part is returned
670 * DESCRIPTION: Split the input path into a directory and filename part
671 * 1) Directory part used to open include files
672 * 2) Filename part used to generate output filenames
674 *****************************************************************************/
677 FlSplitInputPathname (
679 char **OutDirectoryPath,
687 *OutDirectoryPath = NULL;
695 /* Get the path to the input filename's directory */
697 DirectoryPath = FlStrdup (InputPath);
700 return (AE_NO_MEMORY);
703 /* Convert backslashes to slashes in the entire path */
705 UtConvertBackslashes (DirectoryPath);
707 /* Backup to last slash or colon */
709 Substring = strrchr (DirectoryPath, '/');
712 Substring = strrchr (DirectoryPath, ':');
715 /* Extract the simple filename */
719 DirectoryPath[0] = 0;
720 Filename = FlStrdup (InputPath);
724 Filename = FlStrdup (Substring + 1);
725 *(Substring + 1) = 0;
730 return (AE_NO_MEMORY);
733 *OutDirectoryPath = DirectoryPath;
734 *OutFilename = Filename;
739 /******************************************************************************
741 * FUNCTION: AsDoWildcard
743 * PARAMETERS: DirectoryPathname - Path to parent directory
744 * FileSpecifier - the wildcard specification (*.c, etc.)
746 * RETURN: Pointer to a list of filenames
748 * DESCRIPTION: Process files via wildcards. This function is for the Windows
751 *****************************************************************************/
755 char *DirectoryPathname,
766 /* Open parent directory */
768 DirInfo = AcpiOsOpenDirectory (DirectoryPathname, FileSpecifier,
772 /* Either the directory or file does not exist */
774 printf ("File or directory \"%s%s\" does not exist\n",
775 DirectoryPathname, FileSpecifier);
779 /* Process each file that matches the wildcard specification */
781 while ((Filename = AcpiOsGetNextFilename (DirInfo)))
783 /* Add the filename to the file list */
785 FileList[FileCount] = AcpiOsAllocate (strlen (Filename) + 1);
786 strcpy (FileList[FileCount], Filename);
789 if (FileCount >= ASL_MAX_FILES)
791 printf ("Max files reached\n");
799 AcpiOsCloseDirectory (DirInfo);
800 FileList[FileCount] = NULL;
810 * Linux/Unix cases - Wildcards are expanded by the shell automatically.
811 * Just return the filename in a null terminated list
813 FileList[0] = AcpiOsAllocate (strlen (FileSpecifier) + 1);
814 strcpy (FileList[0], FileSpecifier);