Path: blob/main/sys/contrib/dev/acpica/components/debugger/dbinput.c
48406 views
/*******************************************************************************1*2* Module Name: dbinput - user front-end to the AML debugger3*4******************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#include <contrib/dev/acpica/include/acpi.h>152#include <contrib/dev/acpica/include/accommon.h>153#include <contrib/dev/acpica/include/acdebug.h>154155#ifdef ACPI_APPLICATION156#include <contrib/dev/acpica/include/acapps.h>157#endif158159#define _COMPONENT ACPI_CA_DEBUGGER160ACPI_MODULE_NAME ("dbinput")161162163/* Local prototypes */164165static UINT32166AcpiDbGetLine (167char *InputBuffer);168169static UINT32170AcpiDbMatchCommand (171char *UserCommand);172173static void174AcpiDbDisplayCommandInfo (175const char *Command,176BOOLEAN DisplayAll);177178static void179AcpiDbDisplayHelp (180char *Command);181182static BOOLEAN183AcpiDbMatchCommandHelp (184const char *Command,185const ACPI_DB_COMMAND_HELP *Help);186187188/*189* Top-level debugger commands.190*191* This list of commands must match the string table below it192*/193enum AcpiExDebuggerCommands194{195CMD_NOT_FOUND = 0,196CMD_NULL,197CMD_ALL,198CMD_ALLOCATIONS,199CMD_ARGS,200CMD_ARGUMENTS,201CMD_BREAKPOINT,202CMD_BUSINFO,203CMD_CALL,204CMD_DEBUG,205CMD_DISASSEMBLE,206CMD_DISASM,207CMD_DUMP,208CMD_EVALUATE,209CMD_EXECUTE,210CMD_EXIT,211CMD_FIELDS,212CMD_FIND,213CMD_GO,214CMD_HANDLERS,215CMD_HELP,216CMD_HELP2,217CMD_HISTORY,218CMD_HISTORY_EXE,219CMD_HISTORY_LAST,220CMD_INFORMATION,221CMD_INTEGRITY,222CMD_INTO,223CMD_LEVEL,224CMD_LIST,225CMD_LOCALS,226CMD_LOCKS,227CMD_METHODS,228CMD_NAMESPACE,229CMD_NOTIFY,230CMD_OBJECTS,231CMD_OSI,232CMD_OWNER,233CMD_PATHS,234CMD_PREDEFINED,235CMD_PREFIX,236CMD_QUIT,237CMD_REFERENCES,238CMD_RESOURCES,239CMD_RESULTS,240CMD_SET,241CMD_STATS,242CMD_STOP,243CMD_TABLES,244CMD_TEMPLATE,245CMD_TRACE,246CMD_TREE,247CMD_TYPE,248#ifdef ACPI_APPLICATION249CMD_ENABLEACPI,250CMD_EVENT,251CMD_GPE,252CMD_GPES,253CMD_SCI,254CMD_SLEEP,255256CMD_CLOSE,257CMD_LOAD,258CMD_OPEN,259CMD_UNLOAD,260261CMD_TERMINATE,262CMD_BACKGROUND,263CMD_THREADS,264265CMD_TEST,266CMD_INTERRUPT,267#endif268};269270#define CMD_FIRST_VALID 2271272273/* Second parameter is the required argument count */274275static const ACPI_DB_COMMAND_INFO AcpiGbl_DbCommands[] =276{277{"<NOT FOUND>", 0},278{"<NULL>", 0},279{"ALL", 1},280{"ALLOCATIONS", 0},281{"ARGS", 0},282{"ARGUMENTS", 0},283{"BREAKPOINT", 1},284{"BUSINFO", 0},285{"CALL", 0},286{"DEBUG", 1},287{"DISASSEMBLE", 1},288{"DISASM", 1},289{"DUMP", 1},290{"EVALUATE", 1},291{"EXECUTE", 1},292{"EXIT", 0},293{"FIELDS", 1},294{"FIND", 1},295{"GO", 0},296{"HANDLERS", 0},297{"HELP", 0},298{"?", 0},299{"HISTORY", 0},300{"!", 1},301{"!!", 0},302{"INFORMATION", 0},303{"INTEGRITY", 0},304{"INTO", 0},305{"LEVEL", 0},306{"LIST", 0},307{"LOCALS", 0},308{"LOCKS", 0},309{"METHODS", 0},310{"NAMESPACE", 0},311{"NOTIFY", 2},312{"OBJECTS", 0},313{"OSI", 0},314{"OWNER", 1},315{"PATHS", 0},316{"PREDEFINED", 0},317{"PREFIX", 0},318{"QUIT", 0},319{"REFERENCES", 1},320{"RESOURCES", 0},321{"RESULTS", 0},322{"SET", 3},323{"STATS", 1},324{"STOP", 0},325{"TABLES", 0},326{"TEMPLATE", 1},327{"TRACE", 1},328{"TREE", 0},329{"TYPE", 1},330#ifdef ACPI_APPLICATION331{"ENABLEACPI", 0},332{"EVENT", 1},333{"GPE", 1},334{"GPES", 0},335{"SCI", 0},336{"SLEEP", 0},337338{"CLOSE", 0},339{"LOAD", 1},340{"OPEN", 1},341{"UNLOAD", 1},342343{"TERMINATE", 0},344{"BACKGROUND", 1},345{"THREADS", 3},346347{"TEST", 1},348{"INTERRUPT", 1},349#endif350{NULL, 0}351};352353/*354* Help for all debugger commands. First argument is the number of lines355* of help to output for the command.356*357* Note: Some commands are not supported by the kernel-level version of358* the debugger.359*/360static const ACPI_DB_COMMAND_HELP AcpiGbl_DbCommandHelp[] =361{362{0, "\nNamespace Access:", "\n"},363{1, " Businfo", "Display system bus info\n"},364{1, " Disassemble <Method>", "Disassemble a control method\n"},365{1, " Find <AcpiName> (? is wildcard)", "Find ACPI name(s) with wildcards\n"},366{1, " Integrity", "Validate namespace integrity\n"},367{1, " Methods", "Display list of loaded control methods\n"},368{1, " Fields <AddressSpaceId>", "Display list of loaded field units by space ID\n"},369{1, " Namespace [Object] [Depth]", "Display loaded namespace tree/subtree\n"},370{1, " Notify <Object> <Value>", "Send a notification on Object\n"},371{1, " Objects [ObjectType]", "Display summary of all objects or just given type\n"},372{1, " Owner <OwnerId> [Depth]", "Display loaded namespace by object owner\n"},373{1, " Paths", "Display full pathnames of namespace objects\n"},374{1, " Predefined", "Check all predefined names\n"},375{1, " Prefix [<Namepath>]", "Set or Get current execution prefix\n"},376{1, " References <Addr>", "Find all references to object at addr\n"},377{1, " Resources [DeviceName]", "Display Device resources (no arg = all devices)\n"},378{1, " Set N <NamedObject> <Value>", "Set value for named integer\n"},379{1, " Template <Object>", "Format/dump a Buffer/ResourceTemplate\n"},380{1, " Type <Object>", "Display object type\n"},381382{0, "\nControl Method Execution:", "\n"},383{1, " All <NameSeg>", "Evaluate all objects named NameSeg\n"},384{1, " Evaluate <Namepath> [Arguments]", "Evaluate object or control method\n"},385{1, " Execute <Namepath> [Arguments]", "Synonym for Evaluate\n"},386#ifdef ACPI_APPLICATION387{1, " Background <Namepath> [Arguments]", "Evaluate object/method in a separate thread\n"},388{1, " Thread <Threads><Loops><NamePath>", "Spawn threads to execute method(s)\n"},389#endif390{1, " Debug <Namepath> [Arguments]", "Single-Step a control method\n"},391{7, " [Arguments] formats:", "Control method argument formats\n"},392{1, " Hex Integer", "Integer\n"},393{1, " \"Ascii String\"", "String\n"},394{1, " (Hex Byte List)", "Buffer\n"},395{1, " (01 42 7A BF)", "Buffer example (4 bytes)\n"},396{1, " [Package Element List]", "Package\n"},397{1, " [0x01 0x1234 \"string\"]", "Package example (3 elements)\n"},398399{0, "\nMiscellaneous:", "\n"},400{1, " Allocations", "Display list of current memory allocations\n"},401{2, " Dump <Address>|<Namepath>", "\n"},402{0, " [Byte|Word|Dword|Qword]", "Display ACPI objects or memory\n"},403{1, " Handlers", "Info about global handlers\n"},404{1, " Help [Command]", "This help screen or individual command\n"},405{1, " History", "Display command history buffer\n"},406{1, " Level <DebugLevel>] [console]", "Get/Set debug level for file or console\n"},407{1, " Locks", "Current status of internal mutexes\n"},408{1, " Osi [Install|Remove <name>]", "Display or modify global _OSI list\n"},409{1, " Quit or Exit", "Exit this command\n"},410{8, " Stats <SubCommand>", "Display namespace and memory statistics\n"},411{1, " Allocations", "Display list of current memory allocations\n"},412{1, " Memory", "Dump internal memory lists\n"},413{1, " Misc", "Namespace search and mutex stats\n"},414{1, " Objects", "Summary of namespace objects\n"},415{1, " Sizes", "Sizes for each of the internal objects\n"},416{1, " Stack", "Display CPU stack usage\n"},417{1, " Tables", "Info about current ACPI table(s)\n"},418{1, " Tables", "Display info about loaded ACPI tables\n"},419#ifdef ACPI_APPLICATION420{1, " Terminate", "Delete namespace and all internal objects\n"},421#endif422{1, " ! <CommandNumber>", "Execute command from history buffer\n"},423{1, " !!", "Execute last command again\n"},424425{0, "\nMethod and Namespace Debugging:", "\n"},426{5, " Trace <State> [<Namepath>] [Once]", "Trace control method execution\n"},427{1, " Enable", "Enable all messages\n"},428{1, " Disable", "Disable tracing\n"},429{1, " Method", "Enable method execution messages\n"},430{1, " Opcode", "Enable opcode execution messages\n"},431{3, " Test <TestName>", "Invoke a debug test\n"},432{1, " Objects", "Read/write/compare all namespace data objects\n"},433{1, " Predefined", "Validate all ACPI predefined names (_STA, etc.)\n"},434{1, " Execute predefined", "Execute all predefined (public) methods\n"},435436{0, "\nControl Method Single-Step Execution:","\n"},437{1, " Arguments (or Args)", "Display method arguments\n"},438{1, " Breakpoint <AmlOffset>", "Set an AML execution breakpoint\n"},439{1, " Call", "Run to next control method invocation\n"},440{1, " Go", "Allow method to run to completion\n"},441{1, " Information", "Display info about the current method\n"},442{1, " Into", "Step into (not over) a method call\n"},443{1, " List [# of Aml Opcodes]", "Display method ASL statements\n"},444{1, " Locals", "Display method local variables\n"},445{1, " Results", "Display method result stack\n"},446{1, " Set <A|L> <#> <Value>", "Set method data (Arguments/Locals)\n"},447{1, " Stop", "Terminate control method\n"},448{1, " Tree", "Display control method calling tree\n"},449{1, " <Enter>", "Single step next AML opcode (over calls)\n"},450451#ifdef ACPI_APPLICATION452{0, "\nFile Operations:", "\n"},453{1, " Close", "Close debug output file\n"},454{1, " Load <Input Filename>", "Load ACPI table from a file\n"},455{1, " Open <Output Filename>", "Open a file for debug output\n"},456{1, " Unload <Namepath>", "Unload an ACPI table via namespace object\n"},457458{0, "\nHardware Simulation:", "\n"},459{1, " EnableAcpi", "Enable ACPI (hardware) mode\n"},460{1, " Event <F|G> <Value>", "Generate AcpiEvent (Fixed/GPE)\n"},461{1, " Gpe <GpeNum> [GpeBlockDevice]", "Simulate a GPE\n"},462{1, " Gpes", "Display info on all GPE devices\n"},463{1, " Sci", "Generate an SCI\n"},464{1, " Sleep [SleepState]", "Simulate sleep/wake sequence(s) (0-5)\n"},465{1, " Interrupt <GSIV>", "Simulate an interrupt\n"},466#endif467{0, NULL, NULL}468};469470471/*******************************************************************************472*473* FUNCTION: AcpiDbMatchCommandHelp474*475* PARAMETERS: Command - Command string to match476* Help - Help table entry to attempt match477*478* RETURN: TRUE if command matched, FALSE otherwise479*480* DESCRIPTION: Attempt to match a command in the help table in order to481* print help information for a single command.482*483******************************************************************************/484485static BOOLEAN486AcpiDbMatchCommandHelp (487const char *Command,488const ACPI_DB_COMMAND_HELP *Help)489{490char *Invocation = Help->Invocation;491UINT32 LineCount;492493494/* Valid commands in the help table begin with a couple of spaces */495496if (*Invocation != ' ')497{498return (FALSE);499}500501while (*Invocation == ' ')502{503Invocation++;504}505506/* Match command name (full command or substring) */507508while ((*Command) && (*Invocation) && (*Invocation != ' '))509{510if (tolower ((int) *Command) != tolower ((int) *Invocation))511{512return (FALSE);513}514515Invocation++;516Command++;517}518519/* Print the appropriate number of help lines */520521LineCount = Help->LineCount;522while (LineCount)523{524AcpiOsPrintf ("%-38s : %s", Help->Invocation, Help->Description);525Help++;526LineCount--;527}528529return (TRUE);530}531532533/*******************************************************************************534*535* FUNCTION: AcpiDbDisplayCommandInfo536*537* PARAMETERS: Command - Command string to match538* DisplayAll - Display all matching commands, or just539* the first one (substring match)540*541* RETURN: None542*543* DESCRIPTION: Display help information for a Debugger command.544*545******************************************************************************/546547static void548AcpiDbDisplayCommandInfo (549const char *Command,550BOOLEAN DisplayAll)551{552const ACPI_DB_COMMAND_HELP *Next;553BOOLEAN Matched;554555556Next = AcpiGbl_DbCommandHelp;557while (Next->Invocation)558{559Matched = AcpiDbMatchCommandHelp (Command, Next);560if (!DisplayAll && Matched)561{562return;563}564565Next++;566}567}568569570/*******************************************************************************571*572* FUNCTION: AcpiDbDisplayHelp573*574* PARAMETERS: Command - Optional command string to display help.575* if not specified, all debugger command576* help strings are displayed577*578* RETURN: None579*580* DESCRIPTION: Display help for a single debugger command, or all of them.581*582******************************************************************************/583584static void585AcpiDbDisplayHelp (586char *Command)587{588const ACPI_DB_COMMAND_HELP *Next = AcpiGbl_DbCommandHelp;589590591if (!Command)592{593/* No argument to help, display help for all commands */594595AcpiOsPrintf ("\nSummary of AML Debugger Commands\n\n");596597while (Next->Invocation)598{599AcpiOsPrintf ("%-38s%s", Next->Invocation, Next->Description);600Next++;601}602AcpiOsPrintf ("\n");603604}605else606{607/* Display help for all commands that match the substring */608609AcpiDbDisplayCommandInfo (Command, TRUE);610}611}612613614/*******************************************************************************615*616* FUNCTION: AcpiDbGetNextToken617*618* PARAMETERS: String - Command buffer619* Next - Return value, end of next token620*621* RETURN: Pointer to the start of the next token.622*623* DESCRIPTION: Command line parsing. Get the next token on the command line624*625******************************************************************************/626627char *628AcpiDbGetNextToken (629char *String,630char **Next,631ACPI_OBJECT_TYPE *ReturnType)632{633char *Start;634UINT32 Depth;635ACPI_OBJECT_TYPE Type = ACPI_TYPE_INTEGER;636637638/* At end of buffer? */639640if (!String || !(*String))641{642return (NULL);643}644645/* Remove any spaces at the beginning, ignore blank lines */646647while (*String && isspace ((int) *String))648{649String++;650}651652if (!(*String))653{654return (NULL);655}656657switch (*String)658{659case '"':660661/* This is a quoted string, scan until closing quote */662663String++;664Start = String;665Type = ACPI_TYPE_STRING;666667/* Find end of string */668669while (*String && (*String != '"'))670{671String++;672}673break;674675case '(':676677/* This is the start of a buffer, scan until closing paren */678679String++;680Start = String;681Type = ACPI_TYPE_BUFFER;682683/* Find end of buffer */684685while (*String && (*String != ')'))686{687String++;688}689break;690691case '{':692693/* This is the start of a field unit, scan until closing brace */694695String++;696Start = String;697Type = ACPI_TYPE_FIELD_UNIT;698699/* Find end of buffer */700701while (*String && (*String != '}'))702{703String++;704}705break;706707case '[':708709/* This is the start of a package, scan until closing bracket */710711String++;712Depth = 1;713Start = String;714Type = ACPI_TYPE_PACKAGE;715716/* Find end of package (closing bracket) */717718while (*String)719{720/* Handle String package elements */721722if (*String == '"')723{724/* Find end of string */725726String++;727while (*String && (*String != '"'))728{729String++;730}731if (!(*String))732{733break;734}735}736else if (*String == '[')737{738Depth++; /* A nested package declaration */739}740else if (*String == ']')741{742Depth--;743if (Depth == 0) /* Found final package closing bracket */744{745break;746}747}748749String++;750}751break;752753default:754755Start = String;756757/* Find end of token */758759while (*String && !isspace ((int) *String))760{761String++;762}763break;764}765766if (!(*String))767{768*Next = NULL;769}770else771{772*String = 0;773*Next = String + 1;774}775776*ReturnType = Type;777return (Start);778}779780781/*******************************************************************************782*783* FUNCTION: AcpiDbGetLine784*785* PARAMETERS: InputBuffer - Command line buffer786*787* RETURN: Count of arguments to the command788*789* DESCRIPTION: Get the next command line from the user. Gets entire line790* up to the next newline791*792******************************************************************************/793794static UINT32795AcpiDbGetLine (796char *InputBuffer)797{798UINT32 i;799UINT32 Count;800char *Next;801char *This;802803804if (AcpiUtSafeStrcpy (AcpiGbl_DbParsedBuf, sizeof (AcpiGbl_DbParsedBuf),805InputBuffer))806{807AcpiOsPrintf (808"Buffer overflow while parsing input line (max %u characters)\n",809(UINT32) sizeof (AcpiGbl_DbParsedBuf));810return (0);811}812813This = AcpiGbl_DbParsedBuf;814for (i = 0; i < ACPI_DEBUGGER_MAX_ARGS; i++)815{816AcpiGbl_DbArgs[i] = AcpiDbGetNextToken (This, &Next,817&AcpiGbl_DbArgTypes[i]);818if (!AcpiGbl_DbArgs[i])819{820break;821}822823This = Next;824}825826/* Uppercase the actual command */827828AcpiUtStrupr (AcpiGbl_DbArgs[0]);829830Count = i;831if (Count)832{833Count--; /* Number of args only */834}835836return (Count);837}838839840/*******************************************************************************841*842* FUNCTION: AcpiDbMatchCommand843*844* PARAMETERS: UserCommand - User command line845*846* RETURN: Index into command array, -1 if not found847*848* DESCRIPTION: Search command array for a command match849*850******************************************************************************/851852static UINT32853AcpiDbMatchCommand (854char *UserCommand)855{856UINT32 i;857858859if (!UserCommand || UserCommand[0] == 0)860{861return (CMD_NULL);862}863864for (i = CMD_FIRST_VALID; AcpiGbl_DbCommands[i].Name; i++)865{866if (strstr (867ACPI_CAST_PTR (char, AcpiGbl_DbCommands[i].Name), UserCommand) ==868AcpiGbl_DbCommands[i].Name)869{870return (i);871}872}873874/* Command not recognized */875876return (CMD_NOT_FOUND);877}878879880/*******************************************************************************881*882* FUNCTION: AcpiDbCommandDispatch883*884* PARAMETERS: InputBuffer - Command line buffer885* WalkState - Current walk886* Op - Current (executing) parse op887*888* RETURN: Status889*890* DESCRIPTION: Command dispatcher.891*892******************************************************************************/893894ACPI_STATUS895AcpiDbCommandDispatch (896char *InputBuffer,897ACPI_WALK_STATE *WalkState,898ACPI_PARSE_OBJECT *Op)899{900UINT32 Temp;901UINT64 Temp64;902UINT32 CommandIndex;903UINT32 ParamCount;904char *CommandLine;905ACPI_STATUS Status = AE_CTRL_TRUE;906907908/* If AcpiTerminate has been called, terminate this thread */909910if (AcpiGbl_DbTerminateLoop)911{912return (AE_CTRL_TERMINATE);913}914915/* Find command and add to the history buffer */916917ParamCount = AcpiDbGetLine (InputBuffer);918CommandIndex = AcpiDbMatchCommand (AcpiGbl_DbArgs[0]);919920/*921* We don't want to add the !! command to the history buffer. It922* would cause an infinite loop because it would always be the923* previous command.924*/925if (CommandIndex != CMD_HISTORY_LAST)926{927AcpiDbAddToHistory (InputBuffer);928}929930/* Verify that we have the minimum number of params */931932if (ParamCount < AcpiGbl_DbCommands[CommandIndex].MinArgs)933{934AcpiOsPrintf ("%u parameters entered, [%s] requires %u parameters\n",935ParamCount, AcpiGbl_DbCommands[CommandIndex].Name,936AcpiGbl_DbCommands[CommandIndex].MinArgs);937938AcpiDbDisplayCommandInfo (939AcpiGbl_DbCommands[CommandIndex].Name, FALSE);940return (AE_CTRL_TRUE);941}942943/* Decode and dispatch the command */944945switch (CommandIndex)946{947case CMD_NULL:948949if (Op)950{951return (AE_OK);952}953break;954955case CMD_ALL:956957AcpiOsPrintf ("Executing all objects with NameSeg: %s\n", AcpiGbl_DbArgs[1]);958AcpiDbExecute (AcpiGbl_DbArgs[1],959&AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_NO_SINGLE_STEP | EX_ALL);960break;961962case CMD_ALLOCATIONS:963964#ifdef ACPI_DBG_TRACK_ALLOCATIONS965AcpiUtDumpAllocations ((UINT32) -1, NULL);966#endif967break;968969case CMD_ARGS:970case CMD_ARGUMENTS:971972AcpiDbDisplayArguments ();973break;974975case CMD_BREAKPOINT:976977AcpiDbSetMethodBreakpoint (AcpiGbl_DbArgs[1], WalkState, Op);978break;979980case CMD_BUSINFO:981982AcpiDbGetBusInfo ();983break;984985case CMD_CALL:986987AcpiDbSetMethodCallBreakpoint (Op);988Status = AE_OK;989break;990991case CMD_DEBUG:992993AcpiDbExecute (AcpiGbl_DbArgs[1],994&AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_SINGLE_STEP);995break;996997case CMD_DISASSEMBLE:998case CMD_DISASM:9991000#ifdef ACPI_DISASSEMBLER1001(void) AcpiDbDisassembleMethod (AcpiGbl_DbArgs[1]);1002#else1003AcpiOsPrintf ("The AML Disassembler is not configured/present\n");1004#endif1005break;10061007case CMD_DUMP:10081009AcpiDbDecodeAndDisplayObject (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);1010break;10111012case CMD_EVALUATE:1013case CMD_EXECUTE:10141015AcpiDbExecute (AcpiGbl_DbArgs[1],1016&AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_NO_SINGLE_STEP);1017break;10181019case CMD_FIND:10201021Status = AcpiDbFindNameInNamespace (AcpiGbl_DbArgs[1]);1022break;10231024case CMD_FIELDS:10251026Status = AcpiUtStrtoul64 (AcpiGbl_DbArgs[1], &Temp64);10271028if (ACPI_FAILURE (Status) || Temp64 >= ACPI_NUM_PREDEFINED_REGIONS)1029{1030AcpiOsPrintf (1031"Invalid address space ID: must be between 0 and %u inclusive\n",1032ACPI_NUM_PREDEFINED_REGIONS - 1);1033return (AE_OK);1034}10351036Status = AcpiDbDisplayFields ((UINT32) Temp64);1037break;10381039case CMD_GO:10401041AcpiGbl_CmSingleStep = FALSE;1042return (AE_OK);10431044case CMD_HANDLERS:10451046AcpiDbDisplayHandlers ();1047break;10481049case CMD_HELP:1050case CMD_HELP2:10511052AcpiDbDisplayHelp (AcpiGbl_DbArgs[1]);1053break;10541055case CMD_HISTORY:10561057AcpiDbDisplayHistory ();1058break;10591060case CMD_HISTORY_EXE: /* ! command */10611062CommandLine = AcpiDbGetFromHistory (AcpiGbl_DbArgs[1]);1063if (!CommandLine)1064{1065return (AE_CTRL_TRUE);1066}10671068Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);1069return (Status);10701071case CMD_HISTORY_LAST: /* !! command */10721073CommandLine = AcpiDbGetFromHistory (NULL);1074if (!CommandLine)1075{1076return (AE_CTRL_TRUE);1077}10781079Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);1080return (Status);10811082case CMD_INFORMATION:10831084AcpiDbDisplayMethodInfo (Op);1085break;10861087case CMD_INTEGRITY:10881089AcpiDbCheckIntegrity ();1090break;10911092case CMD_INTO:10931094if (Op)1095{1096AcpiGbl_CmSingleStep = TRUE;1097return (AE_OK);1098}1099break;11001101case CMD_LEVEL:11021103if (ParamCount == 0)1104{1105AcpiOsPrintf (1106"Current debug level for file output is: %8.8X\n",1107AcpiGbl_DbDebugLevel);1108AcpiOsPrintf (1109"Current debug level for console output is: %8.8X\n",1110AcpiGbl_DbConsoleDebugLevel);1111}1112else if (ParamCount == 2)1113{1114Temp = AcpiGbl_DbConsoleDebugLevel;1115AcpiGbl_DbConsoleDebugLevel =1116strtoul (AcpiGbl_DbArgs[1], NULL, 16);1117AcpiOsPrintf (1118"Debug Level for console output was %8.8X, now %8.8X\n",1119Temp, AcpiGbl_DbConsoleDebugLevel);1120}1121else1122{1123Temp = AcpiGbl_DbDebugLevel;1124AcpiGbl_DbDebugLevel = strtoul (AcpiGbl_DbArgs[1], NULL, 16);1125AcpiOsPrintf (1126"Debug Level for file output was %8.8X, now %8.8X\n",1127Temp, AcpiGbl_DbDebugLevel);1128}1129break;11301131case CMD_LIST:11321133#ifdef ACPI_DISASSEMBLER1134AcpiDbDisassembleAml (AcpiGbl_DbArgs[1], Op);1135#else1136AcpiOsPrintf ("The AML Disassembler is not configured/present\n");1137#endif1138break;11391140case CMD_LOCKS:11411142AcpiDbDisplayLocks ();1143break;11441145case CMD_LOCALS:11461147AcpiDbDisplayLocals ();1148break;11491150case CMD_METHODS:11511152Status = AcpiDbDisplayObjects ("METHOD", AcpiGbl_DbArgs[1]);1153break;11541155case CMD_NAMESPACE:11561157AcpiDbDumpNamespace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);1158break;11591160case CMD_NOTIFY:11611162Temp = strtoul (AcpiGbl_DbArgs[2], NULL, 0);1163AcpiDbSendNotify (AcpiGbl_DbArgs[1], Temp);1164break;11651166case CMD_OBJECTS:11671168AcpiUtStrupr (AcpiGbl_DbArgs[1]);1169Status = AcpiDbDisplayObjects (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);1170break;11711172case CMD_OSI:11731174AcpiDbDisplayInterfaces (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);1175break;11761177case CMD_OWNER:11781179AcpiDbDumpNamespaceByOwner (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);1180break;11811182case CMD_PATHS:11831184AcpiDbDumpNamespacePaths ();1185break;11861187case CMD_PREFIX:11881189AcpiDbSetScope (AcpiGbl_DbArgs[1]);1190break;11911192case CMD_REFERENCES:11931194AcpiDbFindReferences (AcpiGbl_DbArgs[1]);1195break;11961197case CMD_RESOURCES:11981199AcpiDbDisplayResources (AcpiGbl_DbArgs[1]);1200break;12011202case CMD_RESULTS:12031204AcpiDbDisplayResults ();1205break;12061207case CMD_SET:12081209AcpiDbSetMethodData (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],1210AcpiGbl_DbArgs[3]);1211break;12121213case CMD_STATS:12141215Status = AcpiDbDisplayStatistics (AcpiGbl_DbArgs[1]);1216break;12171218case CMD_STOP:12191220return (AE_NOT_IMPLEMENTED);12211222case CMD_TABLES:12231224AcpiDbDisplayTableInfo (AcpiGbl_DbArgs[1]);1225break;12261227case CMD_TEMPLATE:12281229AcpiDbDisplayTemplate (AcpiGbl_DbArgs[1]);1230break;12311232case CMD_TRACE:12331234AcpiDbTrace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], AcpiGbl_DbArgs[3]);1235break;12361237case CMD_TREE:12381239AcpiDbDisplayCallingTree ();1240break;12411242case CMD_TYPE:12431244AcpiDbDisplayObjectType (AcpiGbl_DbArgs[1]);1245break;12461247#ifdef ACPI_APPLICATION12481249/* Hardware simulation commands. */12501251case CMD_ENABLEACPI:1252#if (!ACPI_REDUCED_HARDWARE)12531254Status = AcpiEnable();1255if (ACPI_FAILURE(Status))1256{1257AcpiOsPrintf("AcpiEnable failed (Status=%X)\n", Status);1258return (Status);1259}1260#endif /* !ACPI_REDUCED_HARDWARE */1261break;12621263case CMD_EVENT:12641265AcpiOsPrintf ("Event command not implemented\n");1266break;12671268case CMD_INTERRUPT:12691270AcpiDbGenerateInterrupt (AcpiGbl_DbArgs[1]);1271break;12721273case CMD_GPE:12741275AcpiDbGenerateGpe (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);1276break;12771278case CMD_GPES:12791280AcpiDbDisplayGpes ();1281break;12821283case CMD_SCI:12841285AcpiDbGenerateSci ();1286break;12871288case CMD_SLEEP:12891290Status = AcpiDbSleep (AcpiGbl_DbArgs[1]);1291break;12921293/* File I/O commands. */12941295case CMD_CLOSE:12961297AcpiDbCloseDebugFile ();1298break;12991300case CMD_LOAD:1301{1302ACPI_NEW_TABLE_DESC *ListHead = NULL;13031304Status = AcGetAllTablesFromFile (AcpiGbl_DbArgs[1],1305ACPI_GET_ALL_TABLES, &ListHead);1306if (ACPI_SUCCESS (Status))1307{1308AcpiDbLoadTables (ListHead);1309}1310}1311break;13121313case CMD_OPEN:13141315AcpiDbOpenDebugFile (AcpiGbl_DbArgs[1]);1316break;13171318/* User space commands. */13191320case CMD_TERMINATE:13211322AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);1323AcpiUtSubsystemShutdown ();13241325/*1326* TBD: [Restructure] Need some way to re-initialize without1327* re-creating the semaphores!1328*/13291330AcpiGbl_DbTerminateLoop = TRUE;1331/* AcpiInitialize (NULL); */1332break;13331334case CMD_BACKGROUND:13351336AcpiDbCreateExecutionThread (AcpiGbl_DbArgs[1], &AcpiGbl_DbArgs[2],1337&AcpiGbl_DbArgTypes[2]);1338break;13391340case CMD_THREADS:13411342AcpiDbCreateExecutionThreads (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],1343AcpiGbl_DbArgs[3]);1344break;13451346/* Debug test commands. */13471348case CMD_PREDEFINED:13491350AcpiDbCheckPredefinedNames ();1351break;13521353case CMD_TEST:13541355AcpiDbExecuteTest (AcpiGbl_DbArgs[1]);1356break;13571358case CMD_UNLOAD:13591360AcpiDbUnloadAcpiTable (AcpiGbl_DbArgs[1]);1361break;1362#endif13631364case CMD_EXIT:1365case CMD_QUIT:13661367if (Op)1368{1369AcpiOsPrintf ("Method execution terminated\n");1370return (AE_CTRL_TERMINATE);1371}13721373if (!AcpiGbl_DbOutputToFile)1374{1375AcpiDbgLevel = ACPI_DEBUG_DEFAULT;1376}13771378#ifdef ACPI_APPLICATION1379AcpiDbCloseDebugFile ();1380#endif1381AcpiGbl_DbTerminateLoop = TRUE;1382return (AE_CTRL_TERMINATE);13831384case CMD_NOT_FOUND:1385default:13861387AcpiOsPrintf ("%s: unknown command\n", AcpiGbl_DbArgs[0]);1388return (AE_CTRL_TRUE);1389}13901391if (ACPI_SUCCESS (Status))1392{1393Status = AE_CTRL_TRUE;1394}13951396return (Status);1397}139813991400/*******************************************************************************1401*1402* FUNCTION: AcpiDbExecuteThread1403*1404* PARAMETERS: Context - Not used1405*1406* RETURN: None1407*1408* DESCRIPTION: Debugger execute thread. Waits for a command line, then1409* simply dispatches it.1410*1411******************************************************************************/14121413void ACPI_SYSTEM_XFACE1414AcpiDbExecuteThread (1415void *Context)1416{14171418(void) AcpiDbUserCommands ();1419AcpiGbl_DbThreadsTerminated = TRUE;1420}142114221423/*******************************************************************************1424*1425* FUNCTION: AcpiDbUserCommands1426*1427* PARAMETERS: None1428*1429* RETURN: None1430*1431* DESCRIPTION: Command line execution for the AML debugger. Commands are1432* matched and dispatched here.1433*1434******************************************************************************/14351436ACPI_STATUS1437AcpiDbUserCommands (1438void)1439{1440ACPI_STATUS Status = AE_OK;144114421443AcpiOsPrintf ("\n");14441445/* TBD: [Restructure] Need a separate command line buffer for step mode */14461447while (!AcpiGbl_DbTerminateLoop)1448{1449/* Wait the readiness of the command */14501451Status = AcpiOsWaitCommandReady ();1452if (ACPI_FAILURE (Status))1453{1454break;1455}14561457/* Just call to the command line interpreter */14581459AcpiGbl_MethodExecuting = FALSE;1460AcpiGbl_StepToNextCall = FALSE;14611462(void) AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);14631464/* Notify the completion of the command */14651466Status = AcpiOsNotifyCommandComplete ();1467if (ACPI_FAILURE (Status))1468{1469break;1470}1471}14721473if (ACPI_FAILURE (Status) && Status != AE_CTRL_TERMINATE)1474{1475ACPI_EXCEPTION ((AE_INFO, Status, "While parsing command line"));1476}1477return (Status);1478}147914801481