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 ACPIEXEC_NAME "AML Execution/Debug Utility"
95 #define AE_SUPPORTED_OPTIONS "?b:d:e:f:ghm^orv^:x:"
98 /******************************************************************************
106 * DESCRIPTION: Print a usage message
108 *****************************************************************************/
115 ACPI_USAGE_HEADER ("acpiexec [options] AMLfile1 AMLfile2 ...");
117 ACPI_OPTION ("-b \"CommandLine\"", "Batch mode command line execution (cmd1;cmd2;...)");
118 ACPI_OPTION ("-h -?", "Display this help message");
119 ACPI_OPTION ("-m [Method]", "Batch mode method execution. Default=MAIN");
122 ACPI_OPTION ("-da", "Disable method abort on error");
123 ACPI_OPTION ("-di", "Disable execution of STA/INI methods during init");
124 ACPI_OPTION ("-do", "Disable Operation Region address simulation");
125 ACPI_OPTION ("-dr", "Disable repair of method return values");
126 ACPI_OPTION ("-dt", "Disable allocation tracking (performance)");
129 ACPI_OPTION ("-ef", "Enable display of final memory statistics");
130 ACPI_OPTION ("-ei", "Enable additional tests for ACPICA interfaces");
131 ACPI_OPTION ("-em", "Enable Interpreter Serialized Mode");
132 ACPI_OPTION ("-es", "Enable Interpreter Slack Mode");
133 ACPI_OPTION ("-et", "Enable debug semaphore timeout");
136 ACPI_OPTION ("-f <Value>", "Operation Region initialization fill value");
137 ACPI_OPTION ("-r", "Use hardware-reduced FADT V5");
138 ACPI_OPTION ("-v", "Display version information");
139 ACPI_OPTION ("-vi", "Verbose initialization output");
140 ACPI_OPTION ("-vr", "Verbose region handler output");
141 ACPI_OPTION ("-x <DebugLevel>", "Debug output level");
145 /******************************************************************************
147 * FUNCTION: AeDoOptions
149 * PARAMETERS: argc/argv - Standard argc/argv
153 * DESCRIPTION: Command line option processing
155 *****************************************************************************/
165 while ((j = AcpiGetopt (argc, argv, AE_SUPPORTED_OPTIONS)) != EOF) switch (j)
169 if (strlen (AcpiGbl_Optarg) > (AE_BUFFER_SIZE -1))
171 printf ("**** The length of command line (%u) exceeded maximum (%u)\n",
172 (UINT32) strlen (AcpiGbl_Optarg), (AE_BUFFER_SIZE -1));
175 AcpiGbl_ExecutionMode = AE_MODE_BATCH_MULTIPLE;
176 strcpy (BatchBuffer, AcpiGbl_Optarg);
181 switch (AcpiGbl_Optarg[0])
185 AcpiGbl_IgnoreErrors = TRUE;
190 AcpiGbl_DbOpt_ini_methods = FALSE;
195 AcpiGbl_DbOpt_NoRegionSupport = TRUE;
200 AcpiGbl_DisableAutoRepair = TRUE;
205 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
206 AcpiGbl_DisableMemTracking = TRUE;
212 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
219 switch (AcpiGbl_Optarg[0])
223 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
224 AcpiGbl_DisplayFinalMemStats = TRUE;
230 AcpiGbl_DoInterfaceTests = TRUE;
235 AcpiGbl_AllMethodsSerialized = TRUE;
236 printf ("Enabling AML Interpreter serialized mode\n");
241 AcpiGbl_EnableInterpreterSlack = TRUE;
242 printf ("Enabling AML Interpreter slack mode\n");
247 AcpiGbl_DebugTimeout = TRUE;
252 printf ("Unknown option: -e%s\n", AcpiGbl_Optarg);
259 AcpiGbl_RegionFillValue = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
264 AcpiGbl_DbOpt_tables = TRUE;
265 AcpiGbl_DbFilename = NULL;
276 AcpiGbl_ExecutionMode = AE_MODE_BATCH_SINGLE;
277 switch (AcpiGbl_Optarg[0])
281 strcpy (BatchBuffer, "MAIN");
286 strcpy (BatchBuffer, AcpiGbl_Optarg);
293 AcpiGbl_DbOpt_disasm = TRUE;
294 AcpiGbl_DbOpt_stats = TRUE;
299 AcpiGbl_UseHwReducedFadt = TRUE;
300 printf ("Using ACPI 5.0 Hardware Reduced Mode via version 5 FADT\n");
305 switch (AcpiGbl_Optarg[0])
307 case '^': /* -v: (Version): signon already emitted, just exit */
313 AcpiDbgLevel |= ACPI_LV_INIT_NAMES;
318 AcpiGbl_DisplayRegionAccess = TRUE;
323 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
330 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 0);
331 AcpiGbl_DbConsoleDebugLevel = AcpiDbgLevel;
332 printf ("Debug Level: 0x%8.8X\n", AcpiDbgLevel);
345 /******************************************************************************
349 * PARAMETERS: argc, argv
353 * DESCRIPTION: Main routine for AcpiExec utility
355 *****************************************************************************/
357 int ACPI_SYSTEM_XFACE
364 ACPI_TABLE_HEADER *Table = NULL;
366 AE_TABLE_DESC *TableDesc;
373 ACPI_DEBUG_INITIALIZE (); /* For debug version only */
375 printf (ACPI_COMMON_SIGNON (ACPIEXEC_NAME));
382 signal (SIGINT, AeCtrlCHandler);
386 AcpiDbgLevel = ACPI_NORMAL_DEFAULT;
387 AcpiDbgLayer = 0xFFFFFFFF;
389 /* Init ACPI and start debugger thread */
391 Status = AcpiInitializeSubsystem ();
392 AE_CHECK_OK (AcpiInitializeSubsystem, Status);
393 if (ACPI_FAILURE (Status))
398 /* Get the command line options */
400 if (AeDoOptions (argc, argv))
405 /* The remaining arguments are filenames for ACPI tables */
407 if (argv[AcpiGbl_Optind])
409 AcpiGbl_DbOpt_tables = TRUE;
412 /* Get each of the ACPI table files on the command line */
414 while (argv[AcpiGbl_Optind])
416 /* Split incoming path into a directory/filename combo */
418 Status = FlSplitInputPathname (argv[AcpiGbl_Optind],
419 &Directory, &Filename);
420 if (ACPI_FAILURE (Status))
425 /* Expand wildcards (Windows only) */
427 WildcardList = AsDoWildcard (Directory, Filename);
433 while (*WildcardList)
435 FullPathname = AcpiOsAllocate (
436 strlen (Directory) + strlen (*WildcardList) + 1);
438 /* Construct a full path to the file */
440 strcpy (FullPathname, Directory);
441 strcat (FullPathname, *WildcardList);
445 Status = AcpiDbReadTableFromFile (FullPathname, &Table);
446 if (ACPI_FAILURE (Status))
448 printf ("**** Could not get input table %s, %s\n",
449 FullPathname, AcpiFormatException (Status));
453 AcpiOsFree (FullPathname);
454 AcpiOsFree (*WildcardList);
455 *WildcardList = NULL;
458 /* Ignore non-AML tables, we can't use them. Except for an FADT */
460 if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_FADT) &&
461 !AcpiUtIsAmlTable (Table))
463 ACPI_WARNING ((AE_INFO,
464 "Table %4.4s is not an AML table, ignoring",
470 /* Allocate and link a table descriptor */
472 TableDesc = AcpiOsAllocate (sizeof (AE_TABLE_DESC));
473 TableDesc->Table = Table;
474 TableDesc->Next = AeTableListHead;
475 AeTableListHead = TableDesc;
483 /* Build a local RSDT with all tables and let ACPICA process the RSDT */
485 Status = AeBuildLocalTables (TableCount, AeTableListHead);
486 if (ACPI_FAILURE (Status))
491 Status = AeInstallTables ();
492 if (ACPI_FAILURE (Status))
494 printf ("**** Could not load ACPI tables, %s\n",
495 AcpiFormatException (Status));
500 * Install most of the handlers.
501 * Override some default region handlers, especially SystemMemory
503 Status = AeInstallEarlyHandlers ();
504 if (ACPI_FAILURE (Status))
509 /* Setup initialization flags for ACPICA */
511 InitFlags = (ACPI_NO_HANDLER_INIT | ACPI_NO_ACPI_ENABLE);
512 if (!AcpiGbl_DbOpt_ini_methods)
514 InitFlags |= (ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT);
518 * Main initialization for ACPICA subsystem
519 * TBD: Need a way to call this after the ACPI table "LOAD" command
521 Status = AcpiEnableSubsystem (InitFlags);
522 if (ACPI_FAILURE (Status))
524 printf ("**** Could not EnableSubsystem, %s\n",
525 AcpiFormatException (Status));
530 * Install handlers for "device driver" space IDs (EC,SMBus, etc.)
531 * and fixed event handlers
533 AeInstallLateHandlers ();
535 /* Finish the ACPICA initialization */
537 Status = AcpiInitializeObjects (InitFlags);
538 if (ACPI_FAILURE (Status))
540 printf ("**** Could not InitializeObjects, %s\n",
541 AcpiFormatException (Status));
545 AeMiscellaneousTests ();
550 /* Exit if error above and we are in one of the batch modes */
552 if (ACPI_FAILURE (Status) && (AcpiGbl_ExecutionMode > 0))
557 /* Run a batch command or enter the command loop */
559 switch (AcpiGbl_ExecutionMode)
562 case AE_MODE_COMMAND_LOOP:
564 AcpiDbUserCommands (ACPI_DEBUGGER_COMMAND_PROMPT, NULL);
567 case AE_MODE_BATCH_MULTIPLE:
569 AcpiDbRunBatchMode ();
572 case AE_MODE_BATCH_SINGLE:
574 AcpiDbExecute (BatchBuffer, NULL, NULL, EX_NO_SINGLE_STEP);
582 /******************************************************************************
584 * FUNCTION: AcpiDbRunBatchMode
586 * PARAMETERS: BatchCommandLine - A semicolon separated list of commands
588 * Use only commas to separate elements of
589 * particular command.
592 * DESCRIPTION: For each command of list separated by ';' prepare the command
593 * buffer and pass it to AcpiDbCommandDispatch.
595 *****************************************************************************/
602 char *Ptr = BatchBuffer;
607 AcpiGbl_MethodExecuting = FALSE;
608 AcpiGbl_StepToNextCall = FALSE;
614 /* Convert commas to spaces */
617 else if (*Ptr == ';')
625 if (Run || (*Ptr == '\0'))
627 (void) AcpiDbCommandDispatch (Cmd, NULL, NULL);
633 Status = AcpiTerminate ();
638 /******************************************************************************
642 * DESCRIPTION: Local strdup function
644 *****************************************************************************/
653 NewString = AcpiOsAllocate (strlen (String) + 1);
659 strcpy (NewString, String);
664 /******************************************************************************
666 * FUNCTION: FlSplitInputPathname
668 * PARAMETERS: InputFilename - The user-specified ASL source file to be
670 * OutDirectoryPath - Where the directory path prefix is
672 * OutFilename - Where the filename part is returned
676 * DESCRIPTION: Split the input path into a directory and filename part
677 * 1) Directory part used to open include files
678 * 2) Filename part used to generate output filenames
680 *****************************************************************************/
683 FlSplitInputPathname (
685 char **OutDirectoryPath,
693 *OutDirectoryPath = NULL;
701 /* Get the path to the input filename's directory */
703 DirectoryPath = FlStrdup (InputPath);
706 return (AE_NO_MEMORY);
709 /* Convert backslashes to slashes in the entire path */
711 UtConvertBackslashes (DirectoryPath);
713 /* Backup to last slash or colon */
715 Substring = strrchr (DirectoryPath, '/');
718 Substring = strrchr (DirectoryPath, ':');
721 /* Extract the simple filename */
725 DirectoryPath[0] = 0;
726 Filename = FlStrdup (InputPath);
730 Filename = FlStrdup (Substring + 1);
731 *(Substring + 1) = 0;
736 return (AE_NO_MEMORY);
739 *OutDirectoryPath = DirectoryPath;
740 *OutFilename = Filename;
745 /******************************************************************************
747 * FUNCTION: AsDoWildcard
749 * PARAMETERS: DirectoryPathname - Path to parent directory
750 * FileSpecifier - the wildcard specification (*.c, etc.)
752 * RETURN: Pointer to a list of filenames
754 * DESCRIPTION: Process files via wildcards. This function is for the Windows
757 *****************************************************************************/
761 char *DirectoryPathname,
772 /* Open parent directory */
774 DirInfo = AcpiOsOpenDirectory (DirectoryPathname, FileSpecifier,
778 /* Either the directory or file does not exist */
780 printf ("File or directory \"%s%s\" does not exist\n",
781 DirectoryPathname, FileSpecifier);
785 /* Process each file that matches the wildcard specification */
787 while ((Filename = AcpiOsGetNextFilename (DirInfo)))
789 /* Add the filename to the file list */
791 FileList[FileCount] = AcpiOsAllocate (strlen (Filename) + 1);
792 strcpy (FileList[FileCount], Filename);
795 if (FileCount >= ASL_MAX_FILES)
797 printf ("Max files reached\n");
805 AcpiOsCloseDirectory (DirInfo);
806 FileList[FileCount] = NULL;
816 * Linux/Unix cases - Wildcards are expanded by the shell automatically.
817 * Just return the filename in a null terminated list
819 FileList[0] = AcpiOsAllocate (strlen (FileSpecifier) + 1);
820 strcpy (FileList[0], FileSpecifier);