Sync usage with man page.
[netbsd-mini2440.git] / sys / external / intel-public / acpica / dist / debugger / dbinput.c
blobab373e81cebfb22945889858148e6b4a933fc5bc
1 /*******************************************************************************
3 * Module Name: dbinput - user front-end to the AML debugger
5 ******************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12 * All rights reserved.
14 * 2. License
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
117 #include "acpi.h"
118 #include "accommon.h"
119 #include "acdebug.h"
122 #ifdef ACPI_DEBUGGER
124 #define _COMPONENT ACPI_CA_DEBUGGER
125 ACPI_MODULE_NAME ("dbinput")
127 /* Local prototypes */
129 static char *
130 AcpiDbGetNextToken (
131 char *String,
132 char **Next);
134 static UINT32
135 AcpiDbGetLine (
136 char *InputBuffer);
138 static UINT32
139 AcpiDbMatchCommand (
140 char *UserCommand);
142 static void
143 AcpiDbSingleThread (
144 void);
146 static void
147 AcpiDbDisplayHelp (
148 char *HelpType);
152 * Top-level debugger commands.
154 * This list of commands must match the string table below it
156 enum AcpiExDebuggerCommands
158 CMD_NOT_FOUND = 0,
159 CMD_NULL,
160 CMD_ALLOCATIONS,
161 CMD_ARGS,
162 CMD_ARGUMENTS,
163 CMD_BATCH,
164 CMD_BREAKPOINT,
165 CMD_BUSINFO,
166 CMD_CALL,
167 CMD_CLOSE,
168 CMD_DEBUG,
169 CMD_DISASSEMBLE,
170 CMD_DUMP,
171 CMD_ENABLEACPI,
172 CMD_EVENT,
173 CMD_EXECUTE,
174 CMD_EXIT,
175 CMD_FIND,
176 CMD_GO,
177 CMD_GPE,
178 CMD_GPES,
179 CMD_HELP,
180 CMD_HELP2,
181 CMD_HISTORY,
182 CMD_HISTORY_EXE,
183 CMD_HISTORY_LAST,
184 CMD_INFORMATION,
185 CMD_INTEGRITY,
186 CMD_INTO,
187 CMD_LEVEL,
188 CMD_LIST,
189 CMD_LOAD,
190 CMD_LOCALS,
191 CMD_LOCKS,
192 CMD_METHODS,
193 CMD_NAMESPACE,
194 CMD_NOTIFY,
195 CMD_OBJECT,
196 CMD_OPEN,
197 CMD_OWNER,
198 CMD_PREDEFINED,
199 CMD_PREFIX,
200 CMD_QUIT,
201 CMD_REFERENCES,
202 CMD_RESOURCES,
203 CMD_RESULTS,
204 CMD_SET,
205 CMD_SLEEP,
206 CMD_STATS,
207 CMD_STOP,
208 CMD_TABLES,
209 CMD_TERMINATE,
210 CMD_THREADS,
211 CMD_TRACE,
212 CMD_TREE,
213 CMD_TYPE,
214 CMD_UNLOAD
217 #define CMD_FIRST_VALID 2
220 /* Second parameter is the required argument count */
222 static const COMMAND_INFO AcpiGbl_DbCommands[] =
224 {"<NOT FOUND>", 0},
225 {"<NULL>", 0},
226 {"ALLOCATIONS", 0},
227 {"ARGS", 0},
228 {"ARGUMENTS", 0},
229 {"BATCH", 0},
230 {"BREAKPOINT", 1},
231 {"BUSINFO", 0},
232 {"CALL", 0},
233 {"CLOSE", 0},
234 {"DEBUG", 1},
235 {"DISASSEMBLE", 1},
236 {"DUMP", 1},
237 {"ENABLEACPI", 0},
238 {"EVENT", 1},
239 {"EXECUTE", 1},
240 {"EXIT", 0},
241 {"FIND", 1},
242 {"GO", 0},
243 {"GPE", 2},
244 {"GPES", 0},
245 {"HELP", 0},
246 {"?", 0},
247 {"HISTORY", 0},
248 {"!", 1},
249 {"!!", 0},
250 {"INFORMATION", 0},
251 {"INTEGRITY", 0},
252 {"INTO", 0},
253 {"LEVEL", 0},
254 {"LIST", 0},
255 {"LOAD", 1},
256 {"LOCALS", 0},
257 {"LOCKS", 0},
258 {"METHODS", 0},
259 {"NAMESPACE", 0},
260 {"NOTIFY", 2},
261 {"OBJECT", 1},
262 {"OPEN", 1},
263 {"OWNER", 1},
264 {"PREDEFINED", 0},
265 {"PREFIX", 0},
266 {"QUIT", 0},
267 {"REFERENCES", 1},
268 {"RESOURCES", 1},
269 {"RESULTS", 0},
270 {"SET", 3},
271 {"SLEEP", 1},
272 {"STATS", 0},
273 {"STOP", 0},
274 {"TABLES", 0},
275 {"TERMINATE", 0},
276 {"THREADS", 3},
277 {"TRACE", 1},
278 {"TREE", 0},
279 {"TYPE", 1},
280 {"UNLOAD", 1},
281 {NULL, 0}
285 /*******************************************************************************
287 * FUNCTION: AcpiDbDisplayHelp
289 * PARAMETERS: HelpType - Subcommand (optional)
291 * RETURN: None
293 * DESCRIPTION: Print a usage message.
295 ******************************************************************************/
297 static void
298 AcpiDbDisplayHelp (
299 char *HelpType)
302 AcpiUtStrupr (HelpType);
304 /* No parameter, just give the overview */
306 if (!HelpType)
308 AcpiOsPrintf ("ACPI CA Debugger Commands\n\n");
309 AcpiOsPrintf ("The following classes of commands are available. Help is available for\n");
310 AcpiOsPrintf ("each class by entering \"Help <ClassName>\"\n\n");
311 AcpiOsPrintf (" [GENERAL] General-Purpose Commands\n");
312 AcpiOsPrintf (" [NAMESPACE] Namespace Access Commands\n");
313 AcpiOsPrintf (" [METHOD] Control Method Execution Commands\n");
314 AcpiOsPrintf (" [STATISTICS] Statistical Information\n");
315 AcpiOsPrintf (" [FILE] File I/O Commands\n");
316 return;
320 * Parameter is the command class
322 * The idea here is to keep each class of commands smaller than a screenful
324 switch (HelpType[0])
326 case 'G':
327 AcpiOsPrintf ("\nGeneral-Purpose Commands\n\n");
328 AcpiOsPrintf ("Allocations Display list of current memory allocations\n");
329 AcpiOsPrintf ("Dump <Address>|<Namepath>\n");
330 AcpiOsPrintf (" [Byte|Word|Dword|Qword] Display ACPI objects or memory\n");
331 AcpiOsPrintf ("EnableAcpi Enable ACPI (hardware) mode\n");
332 AcpiOsPrintf ("Help This help screen\n");
333 AcpiOsPrintf ("History Display command history buffer\n");
334 AcpiOsPrintf ("Level [<DebugLevel>] [console] Get/Set debug level for file or console\n");
335 AcpiOsPrintf ("Locks Current status of internal mutexes\n");
336 AcpiOsPrintf ("Quit or Exit Exit this command\n");
337 AcpiOsPrintf ("Stats [Allocations|Memory|Misc\n");
338 AcpiOsPrintf (" |Objects|Sizes|Stack|Tables] Display namespace and memory statistics\n");
339 AcpiOsPrintf ("Tables Display info about loaded ACPI tables\n");
340 AcpiOsPrintf ("Unload <TableSig> [Instance] Unload an ACPI table\n");
341 AcpiOsPrintf ("! <CommandNumber> Execute command from history buffer\n");
342 AcpiOsPrintf ("!! Execute last command again\n");
343 return;
345 case 'S':
346 AcpiOsPrintf ("\nStats Subcommands\n\n");
347 AcpiOsPrintf ("Allocations Display list of current memory allocations\n");
348 AcpiOsPrintf ("Memory Dump internal memory lists\n");
349 AcpiOsPrintf ("Misc Namespace search and mutex stats\n");
350 AcpiOsPrintf ("Objects Summary of namespace objects\n");
351 AcpiOsPrintf ("Sizes Sizes for each of the internal objects\n");
352 AcpiOsPrintf ("Stack Display CPU stack usage\n");
353 AcpiOsPrintf ("Tables Info about current ACPI table(s)\n");
354 return;
356 case 'N':
357 AcpiOsPrintf ("\nNamespace Access Commands\n\n");
358 AcpiOsPrintf ("Businfo Display system bus info\n");
359 AcpiOsPrintf ("Disassemble <Method> Disassemble a control method\n");
360 AcpiOsPrintf ("Event <F|G> <Value> Generate AcpiEvent (Fixed/GPE)\n");
361 AcpiOsPrintf ("Find <AcpiName> (? is wildcard) Find ACPI name(s) with wildcards\n");
362 AcpiOsPrintf ("Gpe <GpeNum> <GpeBlock> Simulate a GPE\n");
363 AcpiOsPrintf ("Gpes Display info on all GPEs\n");
364 AcpiOsPrintf ("Integrity Validate namespace integrity\n");
365 AcpiOsPrintf ("Methods Display list of loaded control methods\n");
366 AcpiOsPrintf ("Namespace [Object] [Depth] Display loaded namespace tree/subtree\n");
367 AcpiOsPrintf ("Notify <Object> <Value> Send a notification on Object\n");
368 AcpiOsPrintf ("Objects <ObjectType> Display all objects of the given type\n");
369 AcpiOsPrintf ("Owner <OwnerId> [Depth] Display loaded namespace by object owner\n");
370 AcpiOsPrintf ("Predefined Check all predefined names\n");
371 AcpiOsPrintf ("Prefix [<NamePath>] Set or Get current execution prefix\n");
372 AcpiOsPrintf ("References <Addr> Find all references to object at addr\n");
373 AcpiOsPrintf ("Resources <Device> Get and display Device resources\n");
374 AcpiOsPrintf ("Set N <NamedObject> <Value> Set value for named integer\n");
375 AcpiOsPrintf ("Sleep <SleepState> Simulate sleep/wake sequence\n");
376 AcpiOsPrintf ("Terminate Delete namespace and all internal objects\n");
377 AcpiOsPrintf ("Type <Object> Display object type\n");
378 return;
380 case 'M':
381 AcpiOsPrintf ("\nControl Method Execution Commands\n\n");
382 AcpiOsPrintf ("Arguments (or Args) Display method arguments\n");
383 AcpiOsPrintf ("Breakpoint <AmlOffset> Set an AML execution breakpoint\n");
384 AcpiOsPrintf ("Call Run to next control method invocation\n");
385 AcpiOsPrintf ("Debug <Namepath> [Arguments] Single Step a control method\n");
386 AcpiOsPrintf ("Execute <Namepath> [Arguments] Execute control method\n");
387 AcpiOsPrintf ("Go Allow method to run to completion\n");
388 AcpiOsPrintf ("Information Display info about the current method\n");
389 AcpiOsPrintf ("Into Step into (not over) a method call\n");
390 AcpiOsPrintf ("List [# of Aml Opcodes] Display method ASL statements\n");
391 AcpiOsPrintf ("Locals Display method local variables\n");
392 AcpiOsPrintf ("Results Display method result stack\n");
393 AcpiOsPrintf ("Set <A|L> <#> <Value> Set method data (Arguments/Locals)\n");
394 AcpiOsPrintf ("Stop Terminate control method\n");
395 AcpiOsPrintf ("Thread <Threads><Loops><NamePath> Spawn threads to execute method(s)\n");
396 AcpiOsPrintf ("Trace <method name> Trace method execution\n");
397 AcpiOsPrintf ("Tree Display control method calling tree\n");
398 AcpiOsPrintf ("<Enter> Single step next AML opcode (over calls)\n");
399 return;
401 case 'F':
402 AcpiOsPrintf ("\nFile I/O Commands\n\n");
403 AcpiOsPrintf ("Close Close debug output file\n");
404 AcpiOsPrintf ("Open <Output Filename> Open a file for debug output\n");
405 AcpiOsPrintf ("Load <Input Filename> Load ACPI table from a file\n");
406 return;
408 default:
409 AcpiOsPrintf ("Unrecognized Command Class: %s\n", HelpType);
410 return;
415 /*******************************************************************************
417 * FUNCTION: AcpiDbGetNextToken
419 * PARAMETERS: String - Command buffer
420 * Next - Return value, end of next token
422 * RETURN: Pointer to the start of the next token.
424 * DESCRIPTION: Command line parsing. Get the next token on the command line
426 ******************************************************************************/
428 static char *
429 AcpiDbGetNextToken (
430 char *String,
431 char **Next)
433 char *Start;
436 /* At end of buffer? */
438 if (!String || !(*String))
440 return (NULL);
443 /* Get rid of any spaces at the beginning */
445 if (*String == ' ')
447 while (*String && (*String == ' '))
449 String++;
452 if (!(*String))
454 return (NULL);
458 Start = String;
460 /* Find end of token */
462 while (*String && (*String != ' '))
464 String++;
467 if (!(*String))
469 *Next = NULL;
471 else
473 *String = 0;
474 *Next = String + 1;
477 return (Start);
481 /*******************************************************************************
483 * FUNCTION: AcpiDbGetLine
485 * PARAMETERS: InputBuffer - Command line buffer
487 * RETURN: Count of arguments to the command
489 * DESCRIPTION: Get the next command line from the user. Gets entire line
490 * up to the next newline
492 ******************************************************************************/
494 static UINT32
495 AcpiDbGetLine (
496 char *InputBuffer)
498 UINT32 i;
499 UINT32 Count;
500 char *Next;
501 char *This;
504 ACPI_STRCPY (AcpiGbl_DbParsedBuf, InputBuffer);
506 This = AcpiGbl_DbParsedBuf;
507 for (i = 0; i < ACPI_DEBUGGER_MAX_ARGS; i++)
509 AcpiGbl_DbArgs[i] = AcpiDbGetNextToken (This, &Next);
510 if (!AcpiGbl_DbArgs[i])
512 break;
515 This = Next;
518 /* Uppercase the actual command */
520 if (AcpiGbl_DbArgs[0])
522 AcpiUtStrupr (AcpiGbl_DbArgs[0]);
525 Count = i;
526 if (Count)
528 Count--; /* Number of args only */
531 return (Count);
535 /*******************************************************************************
537 * FUNCTION: AcpiDbMatchCommand
539 * PARAMETERS: UserCommand - User command line
541 * RETURN: Index into command array, -1 if not found
543 * DESCRIPTION: Search command array for a command match
545 ******************************************************************************/
547 static UINT32
548 AcpiDbMatchCommand (
549 char *UserCommand)
551 UINT32 i;
554 if (!UserCommand || UserCommand[0] == 0)
556 return (CMD_NULL);
559 for (i = CMD_FIRST_VALID; AcpiGbl_DbCommands[i].Name; i++)
561 if (ACPI_STRSTR (AcpiGbl_DbCommands[i].Name, UserCommand) ==
562 AcpiGbl_DbCommands[i].Name)
564 return (i);
568 /* Command not recognized */
570 return (CMD_NOT_FOUND);
574 /*******************************************************************************
576 * FUNCTION: AcpiDbCommandDispatch
578 * PARAMETERS: InputBuffer - Command line buffer
579 * WalkState - Current walk
580 * Op - Current (executing) parse op
582 * RETURN: Status
584 * DESCRIPTION: Command dispatcher.
586 ******************************************************************************/
588 ACPI_STATUS
589 AcpiDbCommandDispatch (
590 char *InputBuffer,
591 ACPI_WALK_STATE *WalkState,
592 ACPI_PARSE_OBJECT *Op)
594 UINT32 Temp;
595 UINT32 CommandIndex;
596 UINT32 ParamCount;
597 char *CommandLine;
598 ACPI_STATUS Status = AE_CTRL_TRUE;
601 /* If AcpiTerminate has been called, terminate this thread */
603 if (AcpiGbl_DbTerminateThreads)
605 return (AE_CTRL_TERMINATE);
608 ParamCount = AcpiDbGetLine (InputBuffer);
609 CommandIndex = AcpiDbMatchCommand (AcpiGbl_DbArgs[0]);
610 Temp = 0;
612 /* Verify that we have the minimum number of params */
614 if (ParamCount < AcpiGbl_DbCommands[CommandIndex].MinArgs)
616 AcpiOsPrintf ("%d parameters entered, [%s] requires %d parameters\n",
617 ParamCount, AcpiGbl_DbCommands[CommandIndex].Name,
618 AcpiGbl_DbCommands[CommandIndex].MinArgs);
620 return (AE_CTRL_TRUE);
623 /* Decode and dispatch the command */
625 switch (CommandIndex)
627 case CMD_NULL:
628 if (Op)
630 return (AE_OK);
632 break;
634 case CMD_ALLOCATIONS:
636 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
637 AcpiUtDumpAllocations ((UINT32) -1, NULL);
638 #endif
639 break;
641 case CMD_ARGS:
642 case CMD_ARGUMENTS:
643 AcpiDbDisplayArguments ();
644 break;
646 case CMD_BATCH:
647 AcpiDbBatchExecute ();
648 break;
650 case CMD_BREAKPOINT:
651 AcpiDbSetMethodBreakpoint (AcpiGbl_DbArgs[1], WalkState, Op);
652 break;
654 case CMD_BUSINFO:
655 AcpiDbGetBusInfo ();
656 break;
658 case CMD_CALL:
659 AcpiDbSetMethodCallBreakpoint (Op);
660 Status = AE_OK;
661 break;
663 case CMD_CLOSE:
664 AcpiDbCloseDebugFile ();
665 break;
667 case CMD_DEBUG:
668 AcpiDbExecute (AcpiGbl_DbArgs[1], &AcpiGbl_DbArgs[2], EX_SINGLE_STEP);
669 break;
671 case CMD_DISASSEMBLE:
672 (void) AcpiDbDisassembleMethod (AcpiGbl_DbArgs[1]);
673 break;
675 case CMD_DUMP:
676 AcpiDbDecodeAndDisplayObject (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
677 break;
679 case CMD_ENABLEACPI:
680 Status = AcpiEnable();
681 if (ACPI_FAILURE(Status))
683 AcpiOsPrintf("AcpiEnable failed (Status=%X)\n", Status);
684 return (Status);
686 break;
688 case CMD_EVENT:
689 AcpiOsPrintf ("Event command not implemented\n");
690 break;
692 case CMD_EXECUTE:
693 AcpiDbExecute (AcpiGbl_DbArgs[1],
694 &AcpiGbl_DbArgs[2], EX_NO_SINGLE_STEP);
695 break;
697 case CMD_FIND:
698 Status = AcpiDbFindNameInNamespace (AcpiGbl_DbArgs[1]);
699 break;
701 case CMD_GO:
702 AcpiGbl_CmSingleStep = FALSE;
703 return (AE_OK);
705 case CMD_GPE:
706 AcpiDbGenerateGpe (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
707 break;
709 case CMD_GPES:
710 AcpiDbDisplayGpes ();
711 break;
713 case CMD_HELP:
714 case CMD_HELP2:
715 AcpiDbDisplayHelp (AcpiGbl_DbArgs[1]);
716 break;
718 case CMD_HISTORY:
719 AcpiDbDisplayHistory ();
720 break;
722 case CMD_HISTORY_EXE:
723 CommandLine = AcpiDbGetFromHistory (AcpiGbl_DbArgs[1]);
724 if (!CommandLine)
726 return (AE_CTRL_TRUE);
729 Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
730 return (Status);
732 case CMD_HISTORY_LAST:
733 CommandLine = AcpiDbGetFromHistory (NULL);
734 if (!CommandLine)
736 return (AE_CTRL_TRUE);
739 Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
740 return (Status);
742 case CMD_INFORMATION:
743 AcpiDbDisplayMethodInfo (Op);
744 break;
746 case CMD_INTEGRITY:
747 AcpiDbCheckIntegrity ();
748 break;
750 case CMD_INTO:
751 if (Op)
753 AcpiGbl_CmSingleStep = TRUE;
754 return (AE_OK);
756 break;
758 case CMD_LEVEL:
759 if (ParamCount == 0)
761 AcpiOsPrintf ("Current debug level for file output is: %8.8lX\n",
762 AcpiGbl_DbDebugLevel);
763 AcpiOsPrintf ("Current debug level for console output is: %8.8lX\n",
764 AcpiGbl_DbConsoleDebugLevel);
766 else if (ParamCount == 2)
768 Temp = AcpiGbl_DbConsoleDebugLevel;
769 AcpiGbl_DbConsoleDebugLevel = ACPI_STRTOUL (AcpiGbl_DbArgs[1],
770 NULL, 16);
771 AcpiOsPrintf (
772 "Debug Level for console output was %8.8lX, now %8.8lX\n",
773 Temp, AcpiGbl_DbConsoleDebugLevel);
775 else
777 Temp = AcpiGbl_DbDebugLevel;
778 AcpiGbl_DbDebugLevel = ACPI_STRTOUL (AcpiGbl_DbArgs[1], NULL, 16);
779 AcpiOsPrintf (
780 "Debug Level for file output was %8.8lX, now %8.8lX\n",
781 Temp, AcpiGbl_DbDebugLevel);
783 break;
785 case CMD_LIST:
786 AcpiDbDisassembleAml (AcpiGbl_DbArgs[1], Op);
787 break;
789 case CMD_LOAD:
790 Status = AcpiDbGetTableFromFile (AcpiGbl_DbArgs[1], NULL);
791 break;
793 case CMD_LOCKS:
794 AcpiDbDisplayLocks ();
795 break;
797 case CMD_LOCALS:
798 AcpiDbDisplayLocals ();
799 break;
801 case CMD_METHODS:
802 Status = AcpiDbDisplayObjects (__UNCONST("METHOD"), AcpiGbl_DbArgs[1]);
803 break;
805 case CMD_NAMESPACE:
806 AcpiDbDumpNamespace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
807 break;
809 case CMD_NOTIFY:
810 Temp = ACPI_STRTOUL (AcpiGbl_DbArgs[2], NULL, 0);
811 AcpiDbSendNotify (AcpiGbl_DbArgs[1], Temp);
812 break;
814 case CMD_OBJECT:
815 AcpiUtStrupr (AcpiGbl_DbArgs[1]);
816 Status = AcpiDbDisplayObjects (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
817 break;
819 case CMD_OPEN:
820 AcpiDbOpenDebugFile (AcpiGbl_DbArgs[1]);
821 break;
823 case CMD_OWNER:
824 AcpiDbDumpNamespaceByOwner (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
825 break;
827 case CMD_PREDEFINED:
828 AcpiDbCheckPredefinedNames ();
829 break;
831 case CMD_PREFIX:
832 AcpiDbSetScope (AcpiGbl_DbArgs[1]);
833 break;
835 case CMD_REFERENCES:
836 AcpiDbFindReferences (AcpiGbl_DbArgs[1]);
837 break;
839 case CMD_RESOURCES:
840 AcpiDbDisplayResources (AcpiGbl_DbArgs[1]);
841 break;
843 case CMD_RESULTS:
844 AcpiDbDisplayResults ();
845 break;
847 case CMD_SET:
848 AcpiDbSetMethodData (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],
849 AcpiGbl_DbArgs[3]);
850 break;
852 case CMD_SLEEP:
853 Status = AcpiDbSleep (AcpiGbl_DbArgs[1]);
854 break;
856 case CMD_STATS:
857 Status = AcpiDbDisplayStatistics (AcpiGbl_DbArgs[1]);
858 break;
860 case CMD_STOP:
861 return (AE_NOT_IMPLEMENTED);
863 case CMD_TABLES:
864 AcpiDbDisplayTableInfo (AcpiGbl_DbArgs[1]);
865 break;
867 case CMD_TERMINATE:
868 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
869 AcpiUtSubsystemShutdown ();
872 * TBD: [Restructure] Need some way to re-initialize without
873 * re-creating the semaphores!
876 /* AcpiInitialize (NULL); */
877 break;
879 case CMD_THREADS:
880 AcpiDbCreateExecutionThreads (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],
881 AcpiGbl_DbArgs[3]);
882 break;
884 case CMD_TRACE:
885 (void) AcpiDebugTrace (AcpiGbl_DbArgs[1],0,0,1);
886 break;
888 case CMD_TREE:
889 AcpiDbDisplayCallingTree ();
890 break;
892 case CMD_TYPE:
893 AcpiDbDisplayObjectType (AcpiGbl_DbArgs[1]);
894 break;
896 case CMD_UNLOAD:
897 AcpiDbUnloadAcpiTable (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
898 break;
900 case CMD_EXIT:
901 case CMD_QUIT:
902 if (Op)
904 AcpiOsPrintf ("Method execution terminated\n");
905 return (AE_CTRL_TERMINATE);
908 if (!AcpiGbl_DbOutputToFile)
910 AcpiDbgLevel = ACPI_DEBUG_DEFAULT;
913 AcpiDbCloseDebugFile ();
914 AcpiGbl_DbTerminateThreads = TRUE;
915 return (AE_CTRL_TERMINATE);
917 case CMD_NOT_FOUND:
918 default:
919 AcpiOsPrintf ("Unknown Command\n");
920 return (AE_CTRL_TRUE);
923 if (ACPI_SUCCESS (Status))
925 Status = AE_CTRL_TRUE;
928 /* Add all commands that come here to the history buffer */
930 AcpiDbAddToHistory (InputBuffer);
931 return (Status);
935 /*******************************************************************************
937 * FUNCTION: AcpiDbExecuteThread
939 * PARAMETERS: Context - Not used
941 * RETURN: None
943 * DESCRIPTION: Debugger execute thread. Waits for a command line, then
944 * simply dispatches it.
946 ******************************************************************************/
948 void ACPI_SYSTEM_XFACE
949 AcpiDbExecuteThread (
950 void *Context)
952 ACPI_STATUS Status = AE_OK;
953 ACPI_STATUS MStatus;
956 while (Status != AE_CTRL_TERMINATE)
958 AcpiGbl_MethodExecuting = FALSE;
959 AcpiGbl_StepToNextCall = FALSE;
961 MStatus = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY);
962 if (ACPI_FAILURE (MStatus))
964 return;
967 Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
969 MStatus = AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
970 if (ACPI_FAILURE (MStatus))
972 return;
978 /*******************************************************************************
980 * FUNCTION: AcpiDbSingleThread
982 * PARAMETERS: None
984 * RETURN: None
986 * DESCRIPTION: Debugger execute thread. Waits for a command line, then
987 * simply dispatches it.
989 ******************************************************************************/
991 static void
992 AcpiDbSingleThread (
993 void)
996 AcpiGbl_MethodExecuting = FALSE;
997 AcpiGbl_StepToNextCall = FALSE;
999 (void) AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
1003 /*******************************************************************************
1005 * FUNCTION: AcpiDbUserCommands
1007 * PARAMETERS: Prompt - User prompt (depends on mode)
1008 * Op - Current executing parse op
1010 * RETURN: None
1012 * DESCRIPTION: Command line execution for the AML debugger. Commands are
1013 * matched and dispatched here.
1015 ******************************************************************************/
1017 ACPI_STATUS
1018 AcpiDbUserCommands (
1019 char Prompt,
1020 ACPI_PARSE_OBJECT *Op)
1022 ACPI_STATUS Status = AE_OK;
1025 /* TBD: [Restructure] Need a separate command line buffer for step mode */
1027 while (!AcpiGbl_DbTerminateThreads)
1029 /* Force output to console until a command is entered */
1031 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
1033 /* Different prompt if method is executing */
1035 if (!AcpiGbl_MethodExecuting)
1037 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
1039 else
1041 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
1044 /* Get the user input line */
1046 (void) AcpiOsGetLine (AcpiGbl_DbLineBuf);
1048 /* Check for single or multithreaded debug */
1050 if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
1053 * Signal the debug thread that we have a command to execute,
1054 * and wait for the command to complete.
1056 Status = AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_READY);
1057 if (ACPI_FAILURE (Status))
1059 return (Status);
1062 Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
1063 if (ACPI_FAILURE (Status))
1065 return (Status);
1068 else
1070 /* Just call to the command line interpreter */
1072 AcpiDbSingleThread ();
1077 * Only this thread (the original thread) should actually terminate the
1078 * subsystem, because all the semaphores are deleted during termination
1080 Status = AcpiTerminate ();
1081 return (Status);
1084 #endif /* ACPI_DEBUGGER */