1 /*******************************************************************************
3 * Module Name: dbinput - user front-end to the AML debugger
6 ******************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
116 /* $DragonFly: src/sys/contrib/dev/acpica/Attic/dbinput.c,v 1.1 2003/09/24 03:32:15 drhodus Exp $ */
124 #define _COMPONENT ACPI_CA_DEBUGGER
125 ACPI_MODULE_NAME ("dbinput")
129 * Top-level debugger commands.
131 * This list of commands must match the string table below it
133 enum AcpiExDebuggerCommands
187 #define CMD_FIRST_VALID 2
190 static const COMMAND_INFO AcpiGbl_DbCommands[] =
246 /*******************************************************************************
248 * FUNCTION: AcpiDbDisplayHelp
250 * PARAMETERS: HelpType - Subcommand (optional)
254 * DESCRIPTION: Print a usage message.
256 ******************************************************************************/
264 /* No parameter, just give the overview */
268 AcpiOsPrintf ("ACPI CA Debugger Commands\n\n");
269 AcpiOsPrintf ("The following classes of commands are available. Help is available for\n");
270 AcpiOsPrintf ("each class by entering \"Help <ClassName>\"\n\n");
271 AcpiOsPrintf (" [GENERAL] General-Purpose Commands\n");
272 AcpiOsPrintf (" [NAMESPACE] Namespace Access Commands\n");
273 AcpiOsPrintf (" [METHOD] Control Method Execution Commands\n");
274 AcpiOsPrintf (" [FILE] File I/O Commands\n");
279 * Parameter is the command class
281 * The idea here is to keep each class of commands smaller than a screenful
286 AcpiOsPrintf ("\nGeneral-Purpose Commands\n\n");
287 AcpiOsPrintf ("Allocations Display list of current memory allocations\n");
288 AcpiOsPrintf ("Dump <Address>|<Namepath>\n");
289 AcpiOsPrintf (" [Byte|Word|Dword|Qword] Display ACPI objects or memory\n");
290 AcpiOsPrintf ("EnableAcpi Enable ACPI (hardware) mode\n");
291 AcpiOsPrintf ("Help This help screen\n");
292 AcpiOsPrintf ("History Display command history buffer\n");
293 AcpiOsPrintf ("Level [<DebugLevel>] [console] Get/Set debug level for file or console\n");
294 AcpiOsPrintf ("Locks Current status of internal mutexes\n");
295 AcpiOsPrintf ("Quit or Exit Exit this command\n");
296 AcpiOsPrintf ("Stats [Allocations|Memory|Misc\n");
297 AcpiOsPrintf (" |Objects|Tables] Display namespace and memory statistics\n");
298 AcpiOsPrintf ("Tables Display info about loaded ACPI tables\n");
299 AcpiOsPrintf ("Unload <TableSig> [Instance] Unload an ACPI table\n");
300 AcpiOsPrintf ("! <CommandNumber> Execute command from history buffer\n");
301 AcpiOsPrintf ("!! Execute last command again\n");
305 AcpiOsPrintf ("\nNamespace Access Commands\n\n");
306 AcpiOsPrintf ("Event <F|G> <Value> Generate AcpiEvent (Fixed/GPE)\n");
307 AcpiOsPrintf ("Find <Name> (? is wildcard) Find ACPI name(s) with wildcards\n");
308 AcpiOsPrintf ("Method Display list of loaded control methods\n");
309 AcpiOsPrintf ("Namespace [<Addr>|<Path>] [Depth] Display loaded namespace tree/subtree\n");
310 AcpiOsPrintf ("Notify <NamePath> <Value> Send a notification\n");
311 AcpiOsPrintf ("Objects <ObjectType> Display all objects of the given type\n");
312 AcpiOsPrintf ("Owner <OwnerId> [Depth] Display loaded namespace by object owner\n");
313 AcpiOsPrintf ("Prefix [<NamePath>] Set or Get current execution prefix\n");
314 AcpiOsPrintf ("References <Addr> Find all references to object at addr\n");
315 AcpiOsPrintf ("Resources xxx Get and display resources\n");
316 AcpiOsPrintf ("Terminate Delete namespace and all internal objects\n");
317 AcpiOsPrintf ("Thread <Threads><Loops><NamePath> Spawn threads to execute method(s)\n");
321 AcpiOsPrintf ("\nControl Method Execution Commands\n\n");
322 AcpiOsPrintf ("Arguments (or Args) Display method arguments\n");
323 AcpiOsPrintf ("Breakpoint <AmlOffset> Set an AML execution breakpoint\n");
324 AcpiOsPrintf ("Call Run to next control method invocation\n");
325 AcpiOsPrintf ("Debug <Namepath> [Arguments] Single Step a control method\n");
326 AcpiOsPrintf ("Execute <Namepath> [Arguments] Execute control method\n");
327 AcpiOsPrintf ("Go Allow method to run to completion\n");
328 AcpiOsPrintf ("Information Display info about the current method\n");
329 AcpiOsPrintf ("Into Step into (not over) a method call\n");
330 AcpiOsPrintf ("List [# of Aml Opcodes] Display method ASL statements\n");
331 AcpiOsPrintf ("Locals Display method local variables\n");
332 AcpiOsPrintf ("Results Display method result stack\n");
333 AcpiOsPrintf ("Set <A|L> <#> <Value> Set method data (Arguments/Locals)\n");
334 AcpiOsPrintf ("Stop Terminate control method\n");
335 AcpiOsPrintf ("Tree Display control method calling tree\n");
336 AcpiOsPrintf ("<Enter> Single step next AML opcode (over calls)\n");
340 AcpiOsPrintf ("\nFile I/O Commands\n\n");
341 AcpiOsPrintf ("Close Close debug output file\n");
342 AcpiOsPrintf ("Open <Output Filename> Open a file for debug output\n");
343 AcpiOsPrintf ("Load <Input Filename> Load ACPI table from a file\n");
347 AcpiOsPrintf ("Unrecognized Command Class: %s\n", HelpType);
353 /*******************************************************************************
355 * FUNCTION: AcpiDbGetNextToken
357 * PARAMETERS: String - Command buffer
358 * Next - Return value, end of next token
360 * RETURN: Pointer to the start of the next token.
362 * DESCRIPTION: Command line parsing. Get the next token on the command line
364 ******************************************************************************/
374 /* At end of buffer? */
376 if (!String || !(*String))
381 /* Get rid of any spaces at the beginning */
385 while (*String && (*String == ' '))
398 /* Find end of token */
400 while (*String && (*String != ' '))
419 /*******************************************************************************
421 * FUNCTION: AcpiDbGetLine
423 * PARAMETERS: InputBuffer - Command line buffer
427 * DESCRIPTION: Get the next command line from the user. Gets entire line
428 * up to the next newline
430 ******************************************************************************/
442 ACPI_STRCPY (AcpiGbl_DbParsedBuf, InputBuffer);
443 ACPI_STRUPR (AcpiGbl_DbParsedBuf);
445 This = AcpiGbl_DbParsedBuf;
446 for (i = 0; i < ACPI_DEBUGGER_MAX_ARGS; i++)
448 AcpiGbl_DbArgs[i] = AcpiDbGetNextToken (This, &Next);
449 if (!AcpiGbl_DbArgs[i])
457 /* Uppercase the actual command */
459 if (AcpiGbl_DbArgs[0])
461 ACPI_STRUPR (AcpiGbl_DbArgs[0]);
467 Count--; /* Number of args only */
474 /*******************************************************************************
476 * FUNCTION: AcpiDbMatchCommand
478 * PARAMETERS: UserCommand - User command line
480 * RETURN: Index into command array, -1 if not found
482 * DESCRIPTION: Search command array for a command match
484 ******************************************************************************/
493 if (!UserCommand || UserCommand[0] == 0)
498 for (i = CMD_FIRST_VALID; AcpiGbl_DbCommands[i].Name; i++)
500 if (ACPI_STRSTR (AcpiGbl_DbCommands[i].Name, UserCommand) ==
501 AcpiGbl_DbCommands[i].Name)
507 /* Command not recognized */
509 return (CMD_NOT_FOUND);
513 /*******************************************************************************
515 * FUNCTION: AcpiDbCommandDispatch
517 * PARAMETERS: InputBuffer - Command line buffer
518 * WalkState - Current walk
519 * Op - Current (executing) parse op
523 * DESCRIPTION: Command dispatcher. Called from two places:
525 ******************************************************************************/
528 AcpiDbCommandDispatch (
530 ACPI_WALK_STATE *WalkState,
531 ACPI_PARSE_OBJECT *Op)
537 ACPI_STATUS Status = AE_CTRL_TRUE;
540 /* If AcpiTerminate has been called, terminate this thread */
542 if (AcpiGbl_DbTerminateThreads)
544 return (AE_CTRL_TERMINATE);
547 ParamCount = AcpiDbGetLine (InputBuffer);
548 CommandIndex = AcpiDbMatchCommand (AcpiGbl_DbArgs[0]);
551 /* Verify that we have the minimum number of params */
553 if (ParamCount < AcpiGbl_DbCommands[CommandIndex].MinArgs)
555 AcpiOsPrintf ("%d parameters entered, [%s] requires %d parameters\n",
556 ParamCount, AcpiGbl_DbCommands[CommandIndex].Name, AcpiGbl_DbCommands[CommandIndex].MinArgs);
557 return (AE_CTRL_TRUE);
560 /* Decode and dispatch the command */
562 switch (CommandIndex)
571 case CMD_ALLOCATIONS:
573 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
574 AcpiUtDumpAllocations ((UINT32) -1, NULL);
580 AcpiDbDisplayArguments ();
584 AcpiDbSetMethodBreakpoint (AcpiGbl_DbArgs[1], WalkState, Op);
588 AcpiDbSetMethodCallBreakpoint (Op);
593 AcpiDbCloseDebugFile ();
597 AcpiDbExecute (AcpiGbl_DbArgs[1], &AcpiGbl_DbArgs[2], EX_SINGLE_STEP);
601 AcpiDbDecodeAndDisplayObject (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
605 Status = AcpiEnable();
606 if (ACPI_FAILURE(Status))
608 AcpiOsPrintf("AcpiEnable failed (Status=%X)\n", Status);
614 AcpiOsPrintf ("Event command not implemented\n");
618 AcpiDbExecute (AcpiGbl_DbArgs[1], &AcpiGbl_DbArgs[2], EX_NO_SINGLE_STEP);
622 AcpiDbFindNameInNamespace (AcpiGbl_DbArgs[1]);
626 AcpiGbl_CmSingleStep = FALSE;
630 AcpiDbGenerateGpe (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
634 AcpiDbDisplayGpes ();
639 AcpiDbDisplayHelp (AcpiGbl_DbArgs[1]);
643 AcpiDbDisplayHistory ();
646 case CMD_HISTORY_EXE:
647 CommandLine = AcpiDbGetFromHistory (AcpiGbl_DbArgs[1]);
650 return (AE_CTRL_TRUE);
653 Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
654 if (ACPI_SUCCESS (Status))
656 Status = AE_CTRL_TRUE;
660 case CMD_HISTORY_LAST:
661 CommandLine = AcpiDbGetFromHistory (NULL);
664 return (AE_CTRL_TRUE);
667 Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
668 if (ACPI_SUCCESS (Status))
670 Status = AE_CTRL_TRUE;
674 case CMD_INFORMATION:
675 AcpiDbDisplayMethodInfo (Op);
679 AcpiDbCheckIntegrity ();
685 AcpiGbl_CmSingleStep = TRUE;
693 AcpiOsPrintf ("Current debug level for file output is: %8.8lX\n", AcpiGbl_DbDebugLevel);
694 AcpiOsPrintf ("Current debug level for console output is: %8.8lX\n", AcpiGbl_DbConsoleDebugLevel);
696 else if (ParamCount == 2)
698 Temp = AcpiGbl_DbConsoleDebugLevel;
699 AcpiGbl_DbConsoleDebugLevel = ACPI_STRTOUL (AcpiGbl_DbArgs[1], NULL, 16);
700 AcpiOsPrintf ("Debug Level for console output was %8.8lX, now %8.8lX\n", Temp, AcpiGbl_DbConsoleDebugLevel);
704 Temp = AcpiGbl_DbDebugLevel;
705 AcpiGbl_DbDebugLevel = ACPI_STRTOUL (AcpiGbl_DbArgs[1], NULL, 16);
706 AcpiOsPrintf ("Debug Level for file output was %8.8lX, now %8.8lX\n", Temp, AcpiGbl_DbDebugLevel);
711 AcpiDbDisassembleAml (AcpiGbl_DbArgs[1], Op);
715 Status = AcpiDbGetTableFromFile (AcpiGbl_DbArgs[1], NULL);
716 if (ACPI_FAILURE (Status))
723 AcpiDbDisplayLocks ();
727 AcpiDbDisplayLocals ();
731 AcpiDbDisplayObjects ("METHOD", AcpiGbl_DbArgs[1]);
735 AcpiDbDumpNamespace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
739 Temp = ACPI_STRTOUL (AcpiGbl_DbArgs[2], NULL, 0);
740 AcpiDbSendNotify (AcpiGbl_DbArgs[1], Temp);
744 ACPI_STRUPR (AcpiGbl_DbArgs[1]);
745 AcpiDbDisplayObjects (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
749 AcpiDbOpenDebugFile (AcpiGbl_DbArgs[1]);
753 AcpiDbDumpNamespaceByOwner (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
757 AcpiDbSetScope (AcpiGbl_DbArgs[1]);
761 AcpiDbFindReferences (AcpiGbl_DbArgs[1]);
765 AcpiDbDisplayResources (AcpiGbl_DbArgs[1]);
769 AcpiDbDisplayResults ();
773 AcpiDbSetMethodData (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], AcpiGbl_DbArgs[3]);
777 AcpiDbDisplayStatistics (AcpiGbl_DbArgs[1]);
781 return (AE_NOT_IMPLEMENTED);
784 AcpiDbDisplayTableInfo (AcpiGbl_DbArgs[1]);
788 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
789 AcpiUtSubsystemShutdown ();
791 /* TBD: [Restructure] Need some way to re-initialize without re-creating the semaphores! */
793 /* AcpiInitialize (NULL); */
797 AcpiDbCreateExecutionThreads (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], AcpiGbl_DbArgs[3]);
801 AcpiDbDisplayCallingTree ();
805 AcpiDbUnloadAcpiTable (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
812 AcpiOsPrintf ("Method execution terminated\n");
813 return (AE_CTRL_TERMINATE);
816 if (!AcpiGbl_DbOutputToFile)
818 AcpiDbgLevel = ACPI_DEBUG_DEFAULT;
823 /* AcpiUtSubsystemShutdown (); */
824 AcpiDbCloseDebugFile ();
826 AcpiGbl_DbTerminateThreads = TRUE;
828 return (AE_CTRL_TERMINATE);
832 AcpiOsPrintf ("Unknown Command\n");
833 return (AE_CTRL_TRUE);
837 /* Add all commands that come here to the history buffer */
839 AcpiDbAddToHistory (InputBuffer);
844 /*******************************************************************************
846 * FUNCTION: AcpiDbExecuteThread
848 * PARAMETERS: Context - Not used
852 * DESCRIPTION: Debugger execute thread. Waits for a command line, then
853 * simply dispatches it.
855 ******************************************************************************/
857 void ACPI_SYSTEM_XFACE
858 AcpiDbExecuteThread (
861 ACPI_STATUS Status = AE_OK;
865 while (Status != AE_CTRL_TERMINATE)
867 AcpiGbl_MethodExecuting = FALSE;
868 AcpiGbl_StepToNextCall = FALSE;
870 MStatus = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY);
871 if (ACPI_FAILURE (MStatus))
876 Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
878 MStatus = AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
879 if (ACPI_FAILURE (MStatus))
887 /*******************************************************************************
889 * FUNCTION: AcpiDbSingleThread
895 * DESCRIPTION: Debugger execute thread. Waits for a command line, then
896 * simply dispatches it.
898 ******************************************************************************/
905 AcpiGbl_MethodExecuting = FALSE;
906 AcpiGbl_StepToNextCall = FALSE;
908 (void) AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
912 /*******************************************************************************
914 * FUNCTION: AcpiDbUserCommands
916 * PARAMETERS: Prompt - User prompt (depends on mode)
917 * Op - Current executing parse op
921 * DESCRIPTION: Command line execution for the AML debugger. Commands are
922 * matched and dispatched here.
924 ******************************************************************************/
929 ACPI_PARSE_OBJECT *Op)
931 ACPI_STATUS Status = AE_OK;
934 /* TBD: [Restructure] Need a separate command line buffer for step mode */
936 while (!AcpiGbl_DbTerminateThreads)
938 /* Force output to console until a command is entered */
940 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
942 /* Different prompt if method is executing */
944 if (!AcpiGbl_MethodExecuting)
946 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
950 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
953 /* Get the user input line */
955 (void) AcpiOsGetLine (AcpiGbl_DbLineBuf);
957 /* Check for single or multithreaded debug */
959 if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
962 * Signal the debug thread that we have a command to execute,
963 * and wait for the command to complete.
965 Status = AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_READY);
966 if (ACPI_FAILURE (Status))
971 Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
972 if (ACPI_FAILURE (Status))
979 /* Just call to the command line interpreter */
981 AcpiDbSingleThread ();
986 * Only this thread (the original thread) should actually terminate the subsystem,
987 * because all the semaphores are deleted during termination
989 Status = AcpiTerminate ();
994 #endif /* ACPI_DEBUGGER */