From da9b951a892d96e0521abeec09d4345ddf04ab8d Mon Sep 17 00:00:00 2001 From: jkim Date: Fri, 14 Sep 2012 22:53:11 +0000 Subject: Import ACPICA 20120913. --- source/tools/acpiexec/aemain.c | 1000 ++++++++++++++++++++++------------------ 1 file changed, 541 insertions(+), 459 deletions(-) (limited to 'source/tools/acpiexec/aemain.c') diff --git a/source/tools/acpiexec/aemain.c b/source/tools/acpiexec/aemain.c index 11d91a6..38061d2 100644 --- a/source/tools/acpiexec/aemain.c +++ b/source/tools/acpiexec/aemain.c @@ -47,26 +47,54 @@ #include #endif -#define _COMPONENT PARSER +#define _COMPONENT ACPI_TOOLS ACPI_MODULE_NAME ("aemain") +/* Local prototypes */ + +static int +AeDoOptions ( + int argc, + char **argv); + +static ACPI_STATUS +AcpiDbRunBatchMode ( + void); + +static char * +FlStrdup ( + char *String); + +static char ** +AsDoWildcard ( + char *DirectoryPathname, + char *FileSpecifier); -UINT8 AcpiGbl_RegionFillValue = 0; -BOOLEAN AcpiGbl_IgnoreErrors = FALSE; -BOOLEAN AcpiGbl_DbOpt_NoRegionSupport = FALSE; -BOOLEAN AcpiGbl_DebugTimeout = FALSE; -UINT8 AcpiGbl_UseHwReducedFadt = FALSE; -BOOLEAN AcpiGbl_DoInterfaceTests = FALSE; -static UINT8 AcpiGbl_BatchMode = 0; -static char BatchBuffer[128]; -static AE_TABLE_DESC *AeTableListHead = NULL; +#define AE_BUFFER_SIZE 1024 +#define ASL_MAX_FILES 256 -#define ASL_MAX_FILES 256 -static char *FileList[ASL_MAX_FILES]; +/* Execution modes */ +#define AE_MODE_COMMAND_LOOP 0 /* Normal command execution loop */ +#define AE_MODE_BATCH_MULTIPLE 1 /* -b option to execute a command line */ +#define AE_MODE_BATCH_SINGLE 2 /* -m option to execute a single control method */ -#define AE_SUPPORTED_OPTIONS "?b:d:e:f:gm^orv:x:" + +/* Globals */ + +UINT8 AcpiGbl_RegionFillValue = 0; +BOOLEAN AcpiGbl_IgnoreErrors = FALSE; +BOOLEAN AcpiGbl_DbOpt_NoRegionSupport = FALSE; +BOOLEAN AcpiGbl_DebugTimeout = FALSE; +UINT8 AcpiGbl_UseHwReducedFadt = FALSE; +BOOLEAN AcpiGbl_DoInterfaceTests = FALSE; +static UINT8 AcpiGbl_ExecutionMode = AE_MODE_COMMAND_LOOP; +static char BatchBuffer[AE_BUFFER_SIZE]; /* Batch command buffer */ +static char *FileList[ASL_MAX_FILES]; +static AE_TABLE_DESC *AeTableListHead = NULL; + +#define AE_SUPPORTED_OPTIONS "?b:d:e:f:gm^orv:x:" /****************************************************************************** @@ -82,13 +110,14 @@ static char *FileList[ASL_MAX_FILES]; *****************************************************************************/ static void -usage (void) +usage ( + void) { ACPI_USAGE_HEADER ("acpiexec [options] AMLfile1 AMLfile2 ..."); ACPI_OPTION ("-?", "Display this message"); - ACPI_OPTION ("-b ", "Batch mode command execution"); + ACPI_OPTION ("-b \"CommandLine\"", "Batch mode command line execution (cmd1;cmd2;...)"); ACPI_OPTION ("-m [Method]", "Batch mode method execution. Default=MAIN"); printf ("\n"); @@ -116,594 +145,647 @@ usage (void) /****************************************************************************** * - * FUNCTION: AcpiDbRunBatchMode + * FUNCTION: AeDoOptions + * + * PARAMETERS: argc/argv - Standard argc/argv * - * PARAMETERS: BatchCommandLine - A semicolon separated list of commands - * to be executed. - * Use only commas to separate elements of - * particular command. * RETURN: Status * - * DESCRIPTION: For each command of list separated by ';' prepare the command - * buffer and pass it to AcpiDbCommandDispatch. + * DESCRIPTION: Command line option processing * *****************************************************************************/ -static ACPI_STATUS -AcpiDbRunBatchMode ( - void) +static int +AeDoOptions ( + int argc, + char **argv) { - ACPI_STATUS Status; - char *Ptr = BatchBuffer; - char *Cmd = Ptr; - UINT8 Run = 0; - + int j; - AcpiGbl_MethodExecuting = FALSE; - AcpiGbl_StepToNextCall = FALSE; - while (*Ptr) + while ((j = AcpiGetopt (argc, argv, AE_SUPPORTED_OPTIONS)) != EOF) switch (j) { - if (*Ptr == ',') + case 'b': + if (strlen (AcpiGbl_Optarg) > (AE_BUFFER_SIZE -1)) { - /* Convert commas to spaces */ - *Ptr = ' '; + printf ("**** The length of command line (%u) exceeded maximum (%u)\n", + (UINT32) strlen (AcpiGbl_Optarg), (AE_BUFFER_SIZE -1)); + return (-1); } - else if (*Ptr == ';') + AcpiGbl_ExecutionMode = AE_MODE_BATCH_MULTIPLE; + strcpy (BatchBuffer, AcpiGbl_Optarg); + break; + + case 'd': + switch (AcpiGbl_Optarg[0]) { - *Ptr = '\0'; - Run = 1; + case 'a': + AcpiGbl_IgnoreErrors = TRUE; + break; + + case 'i': + AcpiGbl_DbOpt_ini_methods = FALSE; + break; + + case 'o': + AcpiGbl_DbOpt_NoRegionSupport = TRUE; + break; + + case 'r': + AcpiGbl_DisableAutoRepair = TRUE; + break; + + case 't': + #ifdef ACPI_DBG_TRACK_ALLOCATIONS + AcpiGbl_DisableMemTracking = TRUE; + #endif + break; + + default: + printf ("Unknown option: -d%s\n", AcpiGbl_Optarg); + return (-1); } + break; - Ptr++; + case 'e': + switch (AcpiGbl_Optarg[0]) + { + case 'f': + #ifdef ACPI_DBG_TRACK_ALLOCATIONS + AcpiGbl_DisplayFinalMemStats = TRUE; + #endif + break; - if (Run || (*Ptr == '\0')) + case 'i': + AcpiGbl_DoInterfaceTests = TRUE; + break; + + case 'm': + AcpiGbl_AllMethodsSerialized = TRUE; + printf ("Enabling AML Interpreter serialized mode\n"); + break; + + case 's': + AcpiGbl_EnableInterpreterSlack = TRUE; + printf ("Enabling AML Interpreter slack mode\n"); + break; + + case 't': + AcpiGbl_DebugTimeout = TRUE; + break; + + default: + printf ("Unknown option: -e%s\n", AcpiGbl_Optarg); + return (-1); + } + break; + + case 'f': + AcpiGbl_RegionFillValue = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0); + break; + + case 'g': + AcpiGbl_DbOpt_tables = TRUE; + AcpiGbl_DbFilename = NULL; + break; + + case 'm': + AcpiGbl_ExecutionMode = AE_MODE_BATCH_SINGLE; + switch (AcpiGbl_Optarg[0]) { - (void) AcpiDbCommandDispatch (Cmd, NULL, NULL); - Run = 0; - Cmd = Ptr; + case '^': + strcpy (BatchBuffer, "MAIN"); + break; + + default: + strcpy (BatchBuffer, AcpiGbl_Optarg); + break; } - } + break; - Status = AcpiTerminate (); - return (Status); -} + case 'o': + AcpiGbl_DbOpt_disasm = TRUE; + AcpiGbl_DbOpt_stats = TRUE; + break; + case 'r': + AcpiGbl_UseHwReducedFadt = TRUE; + printf ("Using ACPI 5.0 Hardware Reduced Mode via version 5 FADT\n"); + break; -/******************************************************************************* - * - * FUNCTION: FlStrdup - * - * DESCRIPTION: Local strdup function - * - ******************************************************************************/ + case 'v': + switch (AcpiGbl_Optarg[0]) + { + case 'i': + AcpiDbgLevel |= ACPI_LV_INIT_NAMES; + break; -static char * -FlStrdup ( - char *String) -{ - char *NewString; + case 'r': + AcpiGbl_DisplayRegionAccess = TRUE; + break; + default: + printf ("Unknown option: -v%s\n", AcpiGbl_Optarg); + return (-1); + } + break; - NewString = AcpiOsAllocate (strlen (String) + 1); - if (!NewString) - { - return (NULL); + case 'x': + AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 0); + AcpiGbl_DbConsoleDebugLevel = AcpiDbgLevel; + printf ("Debug Level: 0x%8.8X\n", AcpiDbgLevel); + break; + + case '?': + case 'h': + default: + usage(); + return (-1); } - strcpy (NewString, String); - return (NewString); + return (0); } -/******************************************************************************* +/****************************************************************************** * - * FUNCTION: FlSplitInputPathname + * FUNCTION: main * - * PARAMETERS: InputFilename - The user-specified ASL source file to be - * compiled - * OutDirectoryPath - Where the directory path prefix is - * returned - * OutFilename - Where the filename part is returned + * PARAMETERS: argc, argv * * RETURN: Status * - * DESCRIPTION: Split the input path into a directory and filename part - * 1) Directory part used to open include files - * 2) Filename part used to generate output filenames + * DESCRIPTION: Main routine for AcpiExec utility * - ******************************************************************************/ + *****************************************************************************/ -ACPI_STATUS -FlSplitInputPathname ( - char *InputPath, - char **OutDirectoryPath, - char **OutFilename) +int ACPI_SYSTEM_XFACE +main ( + int argc, + char **argv) { - char *Substring; - char *DirectoryPath; + ACPI_STATUS Status; + UINT32 InitFlags; + ACPI_TABLE_HEADER *Table = NULL; + UINT32 TableCount; + AE_TABLE_DESC *TableDesc; + char **WildcardList; char *Filename; + char *Directory; + char *FullPathname; - *OutDirectoryPath = NULL; - *OutFilename = NULL; - - if (!InputPath) - { - return (AE_OK); - } +#ifdef _DEBUG + _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF | + _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG)); +#endif - /* Get the path to the input filename's directory */ + printf (ACPI_COMMON_SIGNON ("AML Execution/Debug Utility")); - DirectoryPath = FlStrdup (InputPath); - if (!DirectoryPath) + if (argc < 2) { - return (AE_NO_MEMORY); + usage (); + return (0); } - /* Convert backslashes to slashes in the entire path */ + signal (SIGINT, AeCtrlCHandler); - UtConvertBackslashes (DirectoryPath); + /* Init globals */ - /* Backup to last slash or colon */ + AcpiDbgLevel = ACPI_NORMAL_DEFAULT; + AcpiDbgLayer = 0xFFFFFFFF; - Substring = strrchr (DirectoryPath, '/'); - if (!Substring) + /* Init ACPI and start debugger thread */ + + Status = AcpiInitializeSubsystem (); + AE_CHECK_OK (AcpiInitializeSubsystem, Status); + if (ACPI_FAILURE (Status)) { - Substring = strrchr (DirectoryPath, ':'); + return (-1); } - /* Extract the simple filename */ + /* Get the command line options */ - if (!Substring) + if (AeDoOptions (argc, argv)) { - DirectoryPath[0] = 0; - Filename = FlStrdup (InputPath); - } - else - { - Filename = FlStrdup (Substring + 1); - *(Substring+1) = 0; + return (-1); } - if (!Filename) + /* The remaining arguments are filenames for ACPI tables */ + + if (argv[AcpiGbl_Optind]) { - return (AE_NO_MEMORY); - } + AcpiGbl_DbOpt_tables = TRUE; + TableCount = 0; - *OutDirectoryPath = DirectoryPath; - *OutFilename = Filename; - return (AE_OK); -} + /* Get each of the ACPI table files on the command line */ + while (argv[AcpiGbl_Optind]) + { + /* Split incoming path into a directory/filename combo */ -/****************************************************************************** - * - * FUNCTION: AsDoWildcard - * - * PARAMETERS: DirectoryPathname - Path to parent directory - * FileSpecifier - the wildcard specification (*.c, etc.) - * - * RETURN: Pointer to a list of filenames - * - * DESCRIPTION: Process files via wildcards. This function is for the Windows - * case only. - * - ******************************************************************************/ + Status = FlSplitInputPathname (argv[AcpiGbl_Optind], + &Directory, &Filename); + if (ACPI_FAILURE (Status)) + { + return (-1); + } -static char ** -AsDoWildcard ( - char *DirectoryPathname, - char *FileSpecifier) -{ -#ifdef WIN32 - void *DirInfo; - char *Filename; - int FileCount; + /* Expand wildcards (Windows only) */ + WildcardList = AsDoWildcard (Directory, Filename); + if (!WildcardList) + { + return (-1); + } - FileCount = 0; + while (*WildcardList) + { + FullPathname = AcpiOsAllocate ( + strlen (Directory) + strlen (*WildcardList) + 1); - /* Open parent directory */ + /* Construct a full path to the file */ - DirInfo = AcpiOsOpenDirectory (DirectoryPathname, FileSpecifier, REQUEST_FILE_ONLY); - if (!DirInfo) - { - /* Either the directory or file does not exist */ + strcpy (FullPathname, Directory); + strcat (FullPathname, *WildcardList); - printf ("File or directory %s%s does not exist\n", DirectoryPathname, FileSpecifier); - return (NULL); - } + /* Get one table */ - /* Process each file that matches the wildcard specification */ + Status = AcpiDbReadTableFromFile (FullPathname, &Table); + if (ACPI_FAILURE (Status)) + { + printf ("**** Could not get input table %s, %s\n", + FullPathname, AcpiFormatException (Status)); + goto EnterDebugger; + } - while ((Filename = AcpiOsGetNextFilename (DirInfo))) - { - /* Add the filename to the file list */ + AcpiOsFree (FullPathname); + AcpiOsFree (*WildcardList); + *WildcardList = NULL; + WildcardList++; - FileList[FileCount] = AcpiOsAllocate (strlen (Filename) + 1); - strcpy (FileList[FileCount], Filename); - FileCount++; + /* Ignore non-AML tables, we can't use them. Except for an FADT */ - if (FileCount >= ASL_MAX_FILES) + if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_FADT) && + !AcpiUtIsAmlTable (Table)) + { + ACPI_WARNING ((AE_INFO, + "Table %4.4s is not an AML table, ignoring", + Table->Signature)); + AcpiOsFree (Table); + continue; + } + + /* Allocate and link a table descriptor */ + + TableDesc = AcpiOsAllocate (sizeof (AE_TABLE_DESC)); + TableDesc->Table = Table; + TableDesc->Next = AeTableListHead; + AeTableListHead = TableDesc; + + TableCount++; + } + + AcpiGbl_Optind++; + } + + /* Build a local RSDT with all tables and let ACPICA process the RSDT */ + + Status = AeBuildLocalTables (TableCount, AeTableListHead); + if (ACPI_FAILURE (Status)) { - printf ("Max files reached\n"); - FileList[0] = NULL; - return (FileList); + return (-1); + } + + Status = AeInstallTables (); + if (ACPI_FAILURE (Status)) + { + printf ("**** Could not load ACPI tables, %s\n", + AcpiFormatException (Status)); + goto EnterDebugger; + } + + /* + * Install most of the handlers. + * Override some default region handlers, especially SystemMemory + */ + Status = AeInstallEarlyHandlers (); + if (ACPI_FAILURE (Status)) + { + goto EnterDebugger; + } + + /* Setup initialization flags for ACPICA */ + + InitFlags = (ACPI_NO_HANDLER_INIT | ACPI_NO_ACPI_ENABLE); + if (!AcpiGbl_DbOpt_ini_methods) + { + InitFlags |= (ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT); + } + + /* + * Main initialization for ACPICA subsystem + * TBD: Need a way to call this after the ACPI table "LOAD" command + */ + Status = AcpiEnableSubsystem (InitFlags); + if (ACPI_FAILURE (Status)) + { + printf ("**** Could not EnableSubsystem, %s\n", + AcpiFormatException (Status)); + goto EnterDebugger; } + + Status = AcpiInitializeObjects (InitFlags); + if (ACPI_FAILURE (Status)) + { + printf ("**** Could not InitializeObjects, %s\n", + AcpiFormatException (Status)); + goto EnterDebugger; + } + + /* + * Install handlers for "device driver" space IDs (EC,SMBus, etc.) + * and fixed event handlers + */ + AeInstallLateHandlers (); + AeMiscellaneousTests (); } - /* Cleanup */ +EnterDebugger: - AcpiOsCloseDirectory (DirInfo); - FileList[FileCount] = NULL; - return (FileList); + /* Exit if error above and we are in one of the batch modes */ -#else - if (!FileSpecifier) + if (ACPI_FAILURE (Status) && (AcpiGbl_ExecutionMode > 0)) { - return (NULL); + return (-1); } - /* - * Linux/Unix cases - Wildcards are expanded by the shell automatically. - * Just return the filename in a null terminated list - */ - FileList[0] = AcpiOsAllocate (strlen (FileSpecifier) + 1); - strcpy (FileList[0], FileSpecifier); - FileList[1] = NULL; + /* Run a batch command or enter the command loop */ - return (FileList); -#endif + switch (AcpiGbl_ExecutionMode) + { + default: + case AE_MODE_COMMAND_LOOP: + + AcpiDbUserCommands (ACPI_DEBUGGER_COMMAND_PROMPT, NULL); + break; + + case AE_MODE_BATCH_MULTIPLE: + + AcpiDbRunBatchMode (); + break; + + case AE_MODE_BATCH_SINGLE: + + AcpiDbExecute (BatchBuffer, NULL, NULL, EX_NO_SINGLE_STEP); + break; + } + + return (0); } /****************************************************************************** * - * FUNCTION: main - * - * PARAMETERS: argc, argv + * FUNCTION: AcpiDbRunBatchMode * + * PARAMETERS: BatchCommandLine - A semicolon separated list of commands + * to be executed. + * Use only commas to separate elements of + * particular command. * RETURN: Status * - * DESCRIPTION: Main routine for AcpiDump utility + * DESCRIPTION: For each command of list separated by ';' prepare the command + * buffer and pass it to AcpiDbCommandDispatch. * *****************************************************************************/ -int ACPI_SYSTEM_XFACE -main ( - int argc, - char **argv) +static ACPI_STATUS +AcpiDbRunBatchMode ( + void) { - int j; ACPI_STATUS Status; - UINT32 InitFlags; - ACPI_TABLE_HEADER *Table = NULL; - UINT32 TableCount; - AE_TABLE_DESC *TableDesc; - char **WildcardList; - char *Filename; - char *Directory; - char *FullPathname; - + char *Ptr = BatchBuffer; + char *Cmd = Ptr; + UINT8 Run = 0; -#ifdef _DEBUG - _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF | - _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG)); -#endif - printf (ACPI_COMMON_SIGNON ("AML Execution/Debug Utility")); + AcpiGbl_MethodExecuting = FALSE; + AcpiGbl_StepToNextCall = FALSE; - if (argc < 2) + while (*Ptr) { - usage (); - return (0); - } - - signal (SIGINT, AeCtrlCHandler); - - /* Init globals */ + if (*Ptr == ',') + { + /* Convert commas to spaces */ + *Ptr = ' '; + } + else if (*Ptr == ';') + { + *Ptr = '\0'; + Run = 1; + } - AcpiDbgLevel = ACPI_NORMAL_DEFAULT; - AcpiDbgLayer = 0xFFFFFFFF; + Ptr++; - /* Init ACPI and start debugger thread */ + if (Run || (*Ptr == '\0')) + { + (void) AcpiDbCommandDispatch (Cmd, NULL, NULL); + Run = 0; + Cmd = Ptr; + } + } - Status = AcpiInitializeSubsystem (); - AE_CHECK_OK (AcpiInitializeSubsystem, Status); + Status = AcpiTerminate (); + return (Status); +} - /* Get the command line options */ - while ((j = AcpiGetopt (argc, argv, AE_SUPPORTED_OPTIONS)) != EOF) switch(j) - { - case 'b': - if (strlen (AcpiGbl_Optarg) > 127) - { - printf ("**** The length of command line (%u) exceeded maximum (127)\n", - (UINT32) strlen (AcpiGbl_Optarg)); - return (-1); - } - AcpiGbl_BatchMode = 1; - strcpy (BatchBuffer, AcpiGbl_Optarg); - break; - - case 'd': - switch (AcpiGbl_Optarg[0]) - { - case 'a': - AcpiGbl_IgnoreErrors = TRUE; - break; - - case 'i': - AcpiGbl_DbOpt_ini_methods = FALSE; - break; - - case 'o': - AcpiGbl_DbOpt_NoRegionSupport = TRUE; - break; - - case 'r': - AcpiGbl_DisableAutoRepair = TRUE; - break; - - case 't': - #ifdef ACPI_DBG_TRACK_ALLOCATIONS - AcpiGbl_DisableMemTracking = TRUE; - #endif - break; - - default: - printf ("Unknown option: -d%s\n", AcpiGbl_Optarg); - return (-1); - } - break; - - case 'e': - switch (AcpiGbl_Optarg[0]) - { - case 'f': - #ifdef ACPI_DBG_TRACK_ALLOCATIONS - AcpiGbl_DisplayFinalMemStats = TRUE; - #endif - break; +/****************************************************************************** + * + * FUNCTION: FlStrdup + * + * DESCRIPTION: Local strdup function + * + *****************************************************************************/ - case 'i': - AcpiGbl_DoInterfaceTests = TRUE; - break; +static char * +FlStrdup ( + char *String) +{ + char *NewString; - case 'm': - AcpiGbl_AllMethodsSerialized = TRUE; - printf ("Enabling AML Interpreter serialized mode\n"); - break; - case 's': - AcpiGbl_EnableInterpreterSlack = TRUE; - printf ("Enabling AML Interpreter slack mode\n"); - break; + NewString = AcpiOsAllocate (strlen (String) + 1); + if (!NewString) + { + return (NULL); + } - case 't': - AcpiGbl_DebugTimeout = TRUE; - break; + strcpy (NewString, String); + return (NewString); +} - default: - printf ("Unknown option: -e%s\n", AcpiGbl_Optarg); - return (-1); - } - break; - case 'f': - AcpiGbl_RegionFillValue = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0); - break; +/****************************************************************************** + * + * FUNCTION: FlSplitInputPathname + * + * PARAMETERS: InputFilename - The user-specified ASL source file to be + * compiled + * OutDirectoryPath - Where the directory path prefix is + * returned + * OutFilename - Where the filename part is returned + * + * RETURN: Status + * + * DESCRIPTION: Split the input path into a directory and filename part + * 1) Directory part used to open include files + * 2) Filename part used to generate output filenames + * + *****************************************************************************/ - case 'g': - AcpiGbl_DbOpt_tables = TRUE; - AcpiGbl_DbFilename = NULL; - break; +ACPI_STATUS +FlSplitInputPathname ( + char *InputPath, + char **OutDirectoryPath, + char **OutFilename) +{ + char *Substring; + char *DirectoryPath; + char *Filename; - case 'm': - AcpiGbl_BatchMode = 2; - switch (AcpiGbl_Optarg[0]) - { - case '^': - strcpy (BatchBuffer, "MAIN"); - break; - default: - strcpy (BatchBuffer, AcpiGbl_Optarg); - break; - } - break; + *OutDirectoryPath = NULL; + *OutFilename = NULL; - case 'o': - AcpiGbl_DbOpt_disasm = TRUE; - AcpiGbl_DbOpt_stats = TRUE; - break; + if (!InputPath) + { + return (AE_OK); + } - case 'r': - AcpiGbl_UseHwReducedFadt = TRUE; - printf ("Using ACPI 5.0 Hardware Reduced Mode via version 5 FADT\n"); - break; + /* Get the path to the input filename's directory */ - case 'v': - switch (AcpiGbl_Optarg[0]) - { - case 'i': - AcpiDbgLevel |= ACPI_LV_INIT_NAMES; - break; + DirectoryPath = FlStrdup (InputPath); + if (!DirectoryPath) + { + return (AE_NO_MEMORY); + } - case 'r': - AcpiGbl_DisplayRegionAccess = TRUE; - break; + /* Convert backslashes to slashes in the entire path */ - default: - printf ("Unknown option: -v%s\n", AcpiGbl_Optarg); - return (-1); - } - break; + UtConvertBackslashes (DirectoryPath); - case 'x': - AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 0); - AcpiGbl_DbConsoleDebugLevel = AcpiDbgLevel; - printf ("Debug Level: 0x%8.8X\n", AcpiDbgLevel); - break; + /* Backup to last slash or colon */ - case '?': - case 'h': - default: - usage(); - return (-1); + Substring = strrchr (DirectoryPath, '/'); + if (!Substring) + { + Substring = strrchr (DirectoryPath, ':'); } + /* Extract the simple filename */ - InitFlags = (ACPI_NO_HANDLER_INIT | ACPI_NO_ACPI_ENABLE); - if (!AcpiGbl_DbOpt_ini_methods) + if (!Substring) { - InitFlags |= (ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT); + DirectoryPath[0] = 0; + Filename = FlStrdup (InputPath); } - - /* The remaining arguments are filenames for ACPI tables */ - - if (argv[AcpiGbl_Optind]) + else { - AcpiGbl_DbOpt_tables = TRUE; - TableCount = 0; - - /* Get each of the ACPI table files on the command line */ - - while (argv[AcpiGbl_Optind]) - { - /* Split incoming path into a directory/filename combo */ - - Status = FlSplitInputPathname (argv[AcpiGbl_Optind], &Directory, &Filename); - if (ACPI_FAILURE (Status)) - { - return (Status); - } - - /* Expand wildcards (Windows only) */ - - WildcardList = AsDoWildcard (Directory, Filename); - if (!WildcardList) - { - return (-1); - } - - while (*WildcardList) - { - FullPathname = AcpiOsAllocate ( - strlen (Directory) + strlen (*WildcardList) + 1); - - /* Construct a full path to the file */ - - strcpy (FullPathname, Directory); - strcat (FullPathname, *WildcardList); - - /* Get one table */ + Filename = FlStrdup (Substring + 1); + *(Substring + 1) = 0; + } - Status = AcpiDbReadTableFromFile (FullPathname, &Table); - if (ACPI_FAILURE (Status)) - { - printf ("**** Could not get input table %s, %s\n", FullPathname, - AcpiFormatException (Status)); - goto enterloop; - } + if (!Filename) + { + return (AE_NO_MEMORY); + } - AcpiOsFree (FullPathname); - AcpiOsFree (*WildcardList); - *WildcardList = NULL; - WildcardList++; + *OutDirectoryPath = DirectoryPath; + *OutFilename = Filename; + return (AE_OK); +} - /* Ignore non-AML tables, we can't use them. Except for an FADT */ - if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_FADT) && - !AcpiUtIsAmlTable (Table)) - { - ACPI_WARNING ((AE_INFO,"Table %4.4s is not an AML table, ignoring", - Table->Signature)); - AcpiOsFree (Table); - continue; - } +/****************************************************************************** + * + * FUNCTION: AsDoWildcard + * + * PARAMETERS: DirectoryPathname - Path to parent directory + * FileSpecifier - the wildcard specification (*.c, etc.) + * + * RETURN: Pointer to a list of filenames + * + * DESCRIPTION: Process files via wildcards. This function is for the Windows + * case only. + * + *****************************************************************************/ - /* Allocate and link a table descriptor */ +static char ** +AsDoWildcard ( + char *DirectoryPathname, + char *FileSpecifier) +{ +#ifdef WIN32 + void *DirInfo; + char *Filename; + int FileCount; - TableDesc = AcpiOsAllocate (sizeof (AE_TABLE_DESC)); - TableDesc->Table = Table; - TableDesc->Next = AeTableListHead; - AeTableListHead = TableDesc; - TableCount++; - } + FileCount = 0; - AcpiGbl_Optind++; - } + /* Open parent directory */ - /* Build a local RSDT with all tables and let ACPICA process the RSDT */ + DirInfo = AcpiOsOpenDirectory (DirectoryPathname, FileSpecifier, + REQUEST_FILE_ONLY); + if (!DirInfo) + { + /* Either the directory or file does not exist */ - Status = AeBuildLocalTables (TableCount, AeTableListHead); - if (ACPI_FAILURE (Status)) - { - return (-1); - } + printf ("File or directory \"%s%s\" does not exist\n", + DirectoryPathname, FileSpecifier); + return (NULL); + } - Status = AeInstallTables (); - if (ACPI_FAILURE (Status)) - { - printf ("**** Could not load ACPI tables, %s\n", AcpiFormatException (Status)); - goto enterloop; - } + /* Process each file that matches the wildcard specification */ - /* - * Install most of the handlers. - * Override some default region handlers, especially SystemMemory - */ - Status = AeInstallEarlyHandlers (); - if (ACPI_FAILURE (Status)) - { - goto enterloop; - } + while ((Filename = AcpiOsGetNextFilename (DirInfo))) + { + /* Add the filename to the file list */ - /* - * TBD: Need a way to call this after the "LOAD" command - */ - Status = AcpiEnableSubsystem (InitFlags); - if (ACPI_FAILURE (Status)) - { - printf ("**** Could not EnableSubsystem, %s\n", AcpiFormatException (Status)); - goto enterloop; - } + FileList[FileCount] = AcpiOsAllocate (strlen (Filename) + 1); + strcpy (FileList[FileCount], Filename); + FileCount++; - Status = AcpiInitializeObjects (InitFlags); - if (ACPI_FAILURE (Status)) + if (FileCount >= ASL_MAX_FILES) { - printf ("**** Could not InitializeObjects, %s\n", AcpiFormatException (Status)); - goto enterloop; + printf ("Max files reached\n"); + FileList[0] = NULL; + return (FileList); } - - /* - * Install handlers for "device driver" space IDs (EC,SMBus, etc.) - * and fixed event handlers - */ - AeInstallLateHandlers (); - AeMiscellaneousTests (); } -enterloop: + /* Cleanup */ - if (AcpiGbl_BatchMode == 1) - { - AcpiDbRunBatchMode (); - } - else if (AcpiGbl_BatchMode == 2) + AcpiOsCloseDirectory (DirInfo); + FileList[FileCount] = NULL; + return (FileList); + +#else + if (!FileSpecifier) { - AcpiDbExecute (BatchBuffer, NULL, NULL, EX_NO_SINGLE_STEP); + return (NULL); } - else - { - /* Enter the debugger command loop */ - AcpiDbUserCommands (ACPI_DEBUGGER_COMMAND_PROMPT, NULL); - } + /* + * Linux/Unix cases - Wildcards are expanded by the shell automatically. + * Just return the filename in a null terminated list + */ + FileList[0] = AcpiOsAllocate (strlen (FileSpecifier) + 1); + strcpy (FileList[0], FileSpecifier); + FileList[1] = NULL; - return (0); + return (FileList); +#endif } - -- cgit v1.1