ACPI_STATUS AcpiDbCommandDispatch ( char *InputBuffer, ACPI_WALK_STATE *WalkState, ACPI_PARSE_OBJECT *Op) { UINT32 Temp; UINT32 CommandIndex; UINT32 ParamCount; char *CommandLine; ACPI_STATUS Status = AE_CTRL_TRUE; /* If AcpiTerminate has been called, terminate this thread */ if (AcpiGbl_DbTerminateLoop) { return (AE_CTRL_TERMINATE); } /* Find command and add to the history buffer */ ParamCount = AcpiDbGetLine (InputBuffer); CommandIndex = AcpiDbMatchCommand (AcpiGbl_DbArgs[0]); Temp = 0; /* * We don't want to add the !! command to the history buffer. It * would cause an infinite loop because it would always be the * previous command. */ if (CommandIndex != CMD_HISTORY_LAST) { AcpiDbAddToHistory (InputBuffer); } /* Verify that we have the minimum number of params */ if (ParamCount < AcpiGbl_DbCommands[CommandIndex].MinArgs) { AcpiOsPrintf ("%u parameters entered, [%s] requires %u parameters\n", ParamCount, AcpiGbl_DbCommands[CommandIndex].Name, AcpiGbl_DbCommands[CommandIndex].MinArgs); AcpiDbDisplayCommandInfo ( AcpiGbl_DbCommands[CommandIndex].Name, FALSE); return (AE_CTRL_TRUE); } /* Decode and dispatch the command */ switch (CommandIndex) { case CMD_NULL: if (Op) { return (AE_OK); } break; case CMD_ALLOCATIONS: #ifdef ACPI_DBG_TRACK_ALLOCATIONS AcpiUtDumpAllocations ((UINT32) -1, NULL); #endif break; case CMD_ARGS: case CMD_ARGUMENTS: AcpiDbDisplayArguments (); break; case CMD_BREAKPOINT: AcpiDbSetMethodBreakpoint (AcpiGbl_DbArgs[1], WalkState, Op); break; case CMD_BUSINFO: AcpiDbGetBusInfo (); break; case CMD_CALL: AcpiDbSetMethodCallBreakpoint (Op); Status = AE_OK; break; case CMD_DEBUG: AcpiDbExecute (AcpiGbl_DbArgs[1], &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_SINGLE_STEP); break; case CMD_DISASSEMBLE: case CMD_DISASM: (void) AcpiDbDisassembleMethod (AcpiGbl_DbArgs[1]); break; case CMD_DUMP: AcpiDbDecodeAndDisplayObject (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]); break; case CMD_EVALUATE: case CMD_EXECUTE: AcpiDbExecute (AcpiGbl_DbArgs[1], &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_NO_SINGLE_STEP); break; case CMD_FIND: Status = AcpiDbFindNameInNamespace (AcpiGbl_DbArgs[1]); break; case CMD_GO: AcpiGbl_CmSingleStep = FALSE; return (AE_OK); case CMD_HANDLERS: AcpiDbDisplayHandlers (); break; case CMD_HELP: case CMD_HELP2: AcpiDbDisplayHelp (AcpiGbl_DbArgs[1]); break; case CMD_HISTORY: AcpiDbDisplayHistory (); break; case CMD_HISTORY_EXE: /* ! command */ CommandLine = AcpiDbGetFromHistory (AcpiGbl_DbArgs[1]); if (!CommandLine) { return (AE_CTRL_TRUE); } Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op); return (Status); case CMD_HISTORY_LAST: /* !! command */ CommandLine = AcpiDbGetFromHistory (NULL); if (!CommandLine) { return (AE_CTRL_TRUE); } Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op); return (Status); case CMD_INFORMATION: AcpiDbDisplayMethodInfo (Op); break; case CMD_INTEGRITY: AcpiDbCheckIntegrity (); break; case CMD_INTO: if (Op) { AcpiGbl_CmSingleStep = TRUE; return (AE_OK); } break; case CMD_LEVEL: if (ParamCount == 0) { AcpiOsPrintf ( "Current debug level for file output is: %8.8lX\n", AcpiGbl_DbDebugLevel); AcpiOsPrintf ( "Current debug level for console output is: %8.8lX\n", AcpiGbl_DbConsoleDebugLevel); } else if (ParamCount == 2) { Temp = AcpiGbl_DbConsoleDebugLevel; AcpiGbl_DbConsoleDebugLevel = strtoul (AcpiGbl_DbArgs[1], NULL, 16); AcpiOsPrintf ( "Debug Level for console output was %8.8lX, now %8.8lX\n", Temp, AcpiGbl_DbConsoleDebugLevel); } else { Temp = AcpiGbl_DbDebugLevel; AcpiGbl_DbDebugLevel = strtoul (AcpiGbl_DbArgs[1], NULL, 16); AcpiOsPrintf ( "Debug Level for file output was %8.8lX, now %8.8lX\n", Temp, AcpiGbl_DbDebugLevel); } break; case CMD_LIST: AcpiDbDisassembleAml (AcpiGbl_DbArgs[1], Op); break; case CMD_LOCKS: AcpiDbDisplayLocks (); break; case CMD_LOCALS: AcpiDbDisplayLocals (); break; case CMD_METHODS: Status = AcpiDbDisplayObjects ("METHOD", AcpiGbl_DbArgs[1]); break; case CMD_NAMESPACE: AcpiDbDumpNamespace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]); break; case CMD_NOTIFY: Temp = strtoul (AcpiGbl_DbArgs[2], NULL, 0); AcpiDbSendNotify (AcpiGbl_DbArgs[1], Temp); break; case CMD_OBJECTS: AcpiUtStrupr (AcpiGbl_DbArgs[1]); Status = AcpiDbDisplayObjects (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]); break; case CMD_OSI: AcpiDbDisplayInterfaces (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]); break; case CMD_OWNER: AcpiDbDumpNamespaceByOwner (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]); break; case CMD_PATHS: AcpiDbDumpNamespacePaths (); break; case CMD_PREFIX: AcpiDbSetScope (AcpiGbl_DbArgs[1]); break; case CMD_REFERENCES: AcpiDbFindReferences (AcpiGbl_DbArgs[1]); break; case CMD_RESOURCES: AcpiDbDisplayResources (AcpiGbl_DbArgs[1]); break; case CMD_RESULTS: AcpiDbDisplayResults (); break; case CMD_SET: AcpiDbSetMethodData (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], AcpiGbl_DbArgs[3]); break; case CMD_STATS: Status = AcpiDbDisplayStatistics (AcpiGbl_DbArgs[1]); break; case CMD_STOP: return (AE_NOT_IMPLEMENTED); case CMD_TABLES: AcpiDbDisplayTableInfo (AcpiGbl_DbArgs[1]); break; case CMD_TEMPLATE: AcpiDbDisplayTemplate (AcpiGbl_DbArgs[1]); break; case CMD_TRACE: AcpiDbTrace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], AcpiGbl_DbArgs[3]); break; case CMD_TREE: AcpiDbDisplayCallingTree (); break; case CMD_TYPE: AcpiDbDisplayObjectType (AcpiGbl_DbArgs[1]); break; #ifdef ACPI_APPLICATION /* Hardware simulation commands. */ case CMD_ENABLEACPI: #if (!ACPI_REDUCED_HARDWARE) Status = AcpiEnable(); if (ACPI_FAILURE(Status)) { AcpiOsPrintf("AcpiEnable failed (Status=%X)\n", Status); return (Status); } #endif /* !ACPI_REDUCED_HARDWARE */ break; case CMD_EVENT: AcpiOsPrintf ("Event command not implemented\n"); break; case CMD_GPE: AcpiDbGenerateGpe (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]); break; case CMD_GPES: AcpiDbDisplayGpes (); break; case CMD_SCI: AcpiDbGenerateSci (); break; case CMD_SLEEP: Status = AcpiDbSleep (AcpiGbl_DbArgs[1]); break; /* File I/O commands. */ case CMD_CLOSE: AcpiDbCloseDebugFile (); break; case CMD_LOAD: { ACPI_NEW_TABLE_DESC *ListHead = NULL; Status = AcGetAllTablesFromFile (AcpiGbl_DbArgs[1], ACPI_GET_ALL_TABLES, &ListHead); if (ACPI_SUCCESS (Status)) { AcpiDbLoadTables (ListHead); } } break; case CMD_OPEN: AcpiDbOpenDebugFile (AcpiGbl_DbArgs[1]); break; /* User space commands. */ case CMD_TERMINATE: AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT); AcpiUtSubsystemShutdown (); /* * TBD: [Restructure] Need some way to re-initialize without * re-creating the semaphores! */ AcpiGbl_DbTerminateLoop = TRUE; /* AcpiInitialize (NULL); */ break; case CMD_BACKGROUND: AcpiDbCreateExecutionThread (AcpiGbl_DbArgs[1], &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2]); break; case CMD_THREADS: AcpiDbCreateExecutionThreads (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], AcpiGbl_DbArgs[3]); break; /* Debug test commands. */ case CMD_PREDEFINED: AcpiDbCheckPredefinedNames (); break; case CMD_TEST: AcpiDbExecuteTest (AcpiGbl_DbArgs[1]); break; case CMD_UNLOAD: AcpiDbUnloadAcpiTable (AcpiGbl_DbArgs[1]); break; #endif case CMD_EXIT: case CMD_QUIT: if (Op) { AcpiOsPrintf ("Method execution terminated\n"); return (AE_CTRL_TERMINATE); } if (!AcpiGbl_DbOutputToFile) { AcpiDbgLevel = ACPI_DEBUG_DEFAULT; } #ifdef ACPI_APPLICATION AcpiDbCloseDebugFile (); #endif AcpiGbl_DbTerminateLoop = TRUE; return (AE_CTRL_TERMINATE); case CMD_NOT_FOUND: default: AcpiOsPrintf ("%s: unknown command\n", AcpiGbl_DbArgs[0]); return (AE_CTRL_TRUE); } if (ACPI_SUCCESS (Status)) { Status = AE_CTRL_TRUE; } return (Status); }
static ACPI_STATUS AdDoExternalFileList ( char *Filename) { ACPI_EXTERNAL_FILE *ExternalFileList; char *ExternalFilename; ACPI_NEW_TABLE_DESC *ExternalListHead = NULL; ACPI_STATUS Status; ACPI_STATUS GlobalStatus = AE_OK; ACPI_OWNER_ID OwnerId; /* * External filenames are specified on the command line like this: * Example: iasl -e file1,file2,file3 -d xxx.aml */ ExternalFileList = AcpiGbl_ExternalFileList; /* Process each external file */ while (ExternalFileList) { ExternalFilename = ExternalFileList->Path; if (!strcmp (ExternalFilename, Filename)) { /* Next external file */ ExternalFileList = ExternalFileList->Next; continue; } AcpiOsPrintf ("External object resolution file %16s\n", ExternalFilename); Status = AcGetAllTablesFromFile ( ExternalFilename, ACPI_GET_ONLY_AML_TABLES, &ExternalListHead); if (ACPI_FAILURE (Status)) { if (Status == AE_TYPE) { ExternalFileList = ExternalFileList->Next; GlobalStatus = AE_TYPE; Status = AE_OK; continue; } return (Status); } /* Load external tables for symbol resolution */ while (ExternalListHead) { Status = AdParseTable ( ExternalListHead->Table, &OwnerId, TRUE, TRUE); if (ACPI_FAILURE (Status)) { AcpiOsPrintf ("Could not parse external ACPI tables, %s\n", AcpiFormatException (Status)); return (Status); } /* * Load namespace from names created within control methods * Set owner id of nodes in external table */ AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode, OwnerId); AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot); ExternalListHead = ExternalListHead->Next; } /* Next external file */ ExternalFileList = ExternalFileList->Next; } if (ACPI_FAILURE (GlobalStatus)) { return (GlobalStatus); } /* Clear external list generated by Scope in external tables */ if (AcpiGbl_ExternalFileList) { AcpiDmClearExternalList (); } /* Load any externals defined in the optional external ref file */ AcpiDmGetExternalsFromFile (); return (AE_OK); }
int ACPI_SYSTEM_XFACE main ( int argc, char **argv) { ACPI_NEW_TABLE_DESC *ListHead = NULL; ACPI_STATUS Status; int j; ACPI_DEBUG_INITIALIZE (); /* For debug version only */ /* Init debug globals and ACPICA */ AcpiDbgLevel = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES; AcpiDbgLayer = 0xFFFFFFFF; /* Set flags so that the interpreter is not used */ Status = AcpiInitializeSubsystem (); ACPI_CHECK_OK (AcpiInitializeSubsystem, Status); if (ACPI_FAILURE (Status)) { return (-1); } printf (ACPI_COMMON_SIGNON (AN_UTILITY_NAME)); if (argc < 2) { usage (); return (0); } /* Get the command line options */ while ((j = AcpiGetopt (argc, argv, AN_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch(j) { case 'l': AcpiGbl_NsLoadOnly = TRUE; break; case 'v': switch (AcpiGbl_Optarg[0]) { case '^': /* -v: (Version): signon already emitted, just exit */ exit (0); case 'd': printf (ACPI_COMMON_BUILD_TIME); return (0); default: printf ("Unknown option: -v%s\n", AcpiGbl_Optarg); return (-1); } break; case 'x': AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 0); printf ("Debug Level: 0x%8.8X\n", AcpiDbgLevel); break; case '?': case 'h': default: usage(); return (0); } /* Get each of the ACPI table files on the command line */ while (argv[AcpiGbl_Optind]) { /* Get all ACPI AML tables in this file */ Status = AcGetAllTablesFromFile (argv[AcpiGbl_Optind], ACPI_GET_ALL_TABLES, &ListHead); if (ACPI_FAILURE (Status)) { return (-1); } AcpiGbl_Optind++; } printf ("\n"); /* * The next argument is the filename for the DSDT or SSDT. * Open the file, build namespace and dump it. */ return (AnDumpEntireNamespace (ListHead)); }
ACPI_STATUS AdAmlDisassemble ( BOOLEAN OutToFile, char *Filename, char *Prefix, char **OutFilename) { ACPI_STATUS Status; char *DisasmFilename = NULL; FILE *File = NULL; ACPI_TABLE_HEADER *Table = NULL; ACPI_NEW_TABLE_DESC *ListHead = NULL; /* * Input: AML code from either a file or via GetTables (memory or * registry) */ if (Filename) { /* Get the list of all AML tables in the file */ Status = AcGetAllTablesFromFile (Filename, ACPI_GET_ALL_TABLES, &ListHead); if (ACPI_FAILURE (Status)) { AcpiOsPrintf ("Could not get ACPI tables from %s, %s\n", Filename, AcpiFormatException (Status)); return (Status); } /* Process any user-specified files for external objects */ Status = AdDoExternalFileList (Filename); if (ACPI_FAILURE (Status)) { return (Status); } } else { Status = AdGetLocalTables (); if (ACPI_FAILURE (Status)) { AcpiOsPrintf ("Could not get ACPI tables, %s\n", AcpiFormatException (Status)); return (Status); } if (!AcpiGbl_DmOpt_Disasm) { return (AE_OK); } /* Obtained the local tables, just disassemble the DSDT */ Status = AcpiGetTable (ACPI_SIG_DSDT, 0, &Table); if (ACPI_FAILURE (Status)) { AcpiOsPrintf ("Could not get DSDT, %s\n", AcpiFormatException (Status)); return (Status); } AcpiOsPrintf ("\nDisassembly of DSDT\n"); Prefix = AdGenerateFilename ("dsdt", Table->OemTableId); } /* * Output: ASL code. Redirect to a file if requested */ if (OutToFile) { /* Create/Open a disassembly output file */ DisasmFilename = FlGenerateFilename (Prefix, FILE_SUFFIX_DISASSEMBLY); if (!DisasmFilename) { fprintf (stderr, "Could not generate output filename\n"); Status = AE_ERROR; goto Cleanup; } File = fopen (DisasmFilename, "w+"); if (!File) { fprintf (stderr, "Could not open output file %s\n", DisasmFilename); Status = AE_ERROR; goto Cleanup; } AcpiOsRedirectOutput (File); } *OutFilename = DisasmFilename; /* Disassemble all AML tables within the file */ while (ListHead) { Status = AdDisassembleOneTable (ListHead->Table, File, Filename, DisasmFilename); if (ACPI_FAILURE (Status)) { break; } ListHead = ListHead->Next; } Cleanup: if (Table && !AcpiGbl_ForceAmlDisassembly && !AcpiUtIsAmlTable (Table)) { ACPI_FREE (Table); } if (File) { fclose (File); AcpiOsRedirectOutput (stdout); } AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot); AcpiGbl_ParseOpRoot = NULL; return (Status); }
int ACPI_SYSTEM_XFACE main ( int argc, char **argv) { ACPI_NEW_TABLE_DESC *ListHead = NULL; ACPI_STATUS Status; UINT32 InitFlags; int ExitCode = 0; ACPI_DEBUG_INITIALIZE (); /* For debug version only */ signal (SIGINT, AeCtrlCHandler); /* Init debug globals */ AcpiDbgLevel = ACPI_NORMAL_DEFAULT; AcpiDbgLayer = 0xFFFFFFFF; /* * Initialize ACPICA and start debugger thread. * * NOTE: After ACPICA initialization, AcpiTerminate MUST be called * before this procedure exits -- otherwise, the console may be * left in an incorrect state. */ Status = AcpiInitializeSubsystem (); ACPI_CHECK_OK (AcpiInitializeSubsystem, Status); if (ACPI_FAILURE (Status)) { goto ErrorExit; } /* ACPICA runtime configuration */ AcpiGbl_MaxLoopIterations = 400; /* Initialize the AML debugger */ Status = AcpiInitializeDebugger (); ACPI_CHECK_OK (AcpiInitializeDebugger, Status); if (ACPI_FAILURE (Status)) { goto ErrorExit; } printf (ACPI_COMMON_SIGNON (ACPIEXEC_NAME)); if (argc < 2) { usage (); goto NormalExit; } /* Get the command line options */ ExitCode = AeDoOptions (argc, argv); if (ExitCode) { if (ExitCode > 0) { ExitCode = 0; } goto ErrorExit; } /* The remaining arguments are filenames for ACPI tables */ if (!argv[AcpiGbl_Optind]) { goto EnterDebugger; } AcpiGbl_CstyleDisassembly = FALSE; /* Not supported for AcpiExec */ /* Get each of the ACPI table files on the command line */ while (argv[AcpiGbl_Optind]) { /* Get all ACPI AML tables in this file */ Status = AcGetAllTablesFromFile (argv[AcpiGbl_Optind], ACPI_GET_ALL_TABLES, &ListHead); if (ACPI_FAILURE (Status)) { ExitCode = -1; goto ErrorExit; } AcpiGbl_Optind++; } printf ("\n"); /* Build a local RSDT with all tables and let ACPICA process the RSDT */ Status = AeBuildLocalTables (ListHead); if (ACPI_FAILURE (Status)) { goto ErrorExit; } /* Install all of the ACPI tables */ Status = AeInstallTables (); if (ACPI_FAILURE (Status)) { printf ("**** Could not install ACPI tables, %s\n", AcpiFormatException (Status)); goto EnterDebugger; } /* * Install most of the handlers (Regions, Notify, Table, etc.) * Override the default region handlers, especially SystemMemory, * which is simulated in this utility. */ 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_NoIniMethods) { 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? * * NOTE: This initialization does not match the _Lxx and _Exx methods * to individual GPEs, as there are no real GPEs when the hardware * is simulated - because there is no namespace until AeLoadTables is * executed. This may have to change if AcpiExec is ever run natively * on actual hardware (such as under UEFI). */ Status = AcpiEnableSubsystem (InitFlags); if (ACPI_FAILURE (Status)) { printf ("**** Could not EnableSubsystem, %s\n", AcpiFormatException (Status)); goto EnterDebugger; } Status = AeLoadTables (); /* * Exit namespace initialization for the "load namespace only" option. * No control methods will be executed. However, still enter the * the debugger. */ if (AcpiGbl_AeLoadOnly) { goto EnterDebugger; } if (ACPI_FAILURE (Status)) { printf ("**** Could not load ACPI tables, %s\n", AcpiFormatException (Status)); goto EnterDebugger; } /* * Install handlers for "device driver" space IDs (EC,SMBus, etc.) * and fixed event handlers */ AeInstallLateHandlers (); /* Finish the ACPICA initialization */ Status = AcpiInitializeObjects (InitFlags); if (ACPI_FAILURE (Status)) { printf ("**** Could not InitializeObjects, %s\n", AcpiFormatException (Status)); goto EnterDebugger; } AeMiscellaneousTests (); EnterDebugger: /* Exit if error above and we are in one of the batch modes */ if (ACPI_FAILURE (Status) && (AcpiGbl_ExecutionMode > 0)) { goto ErrorExit; } /* Run a batch command or enter the command loop */ switch (AcpiGbl_ExecutionMode) { default: case AE_MODE_COMMAND_LOOP: AcpiRunDebugger (NULL); break; case AE_MODE_BATCH_MULTIPLE: AcpiRunDebugger (BatchBuffer); break; case AE_MODE_BATCH_SINGLE: AcpiDbExecute (BatchBuffer, NULL, NULL, EX_NO_SINGLE_STEP); break; } /* Shut down the debugger and ACPICA */ AcpiTerminateDebugger (); NormalExit: ExitCode = 0; ErrorExit: (void) AcpiOsTerminate (); return (ExitCode); }