Sync ACPICA with Intel's version 20180927:
[dragonfly.git] / sys / contrib / dev / acpica / source / components / debugger / dbinput.c
blob0dfd952f4876fe39ec8f8c52542147e85d1c20bc
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 - 2018, 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 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
117 * following license:
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
121 * are met:
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include "acpi.h"
153 #include "accommon.h"
154 #include "acdebug.h"
156 #ifdef ACPI_APPLICATION
157 #include "acapps.h"
158 #endif
160 #ifdef ACPI_DEBUGGER
162 #define _COMPONENT ACPI_CA_DEBUGGER
163 ACPI_MODULE_NAME ("dbinput")
166 /* Local prototypes */
168 static UINT32
169 AcpiDbGetLine (
170 char *InputBuffer);
172 static UINT32
173 AcpiDbMatchCommand (
174 char *UserCommand);
176 static void
177 AcpiDbDisplayCommandInfo (
178 const char *Command,
179 BOOLEAN DisplayAll);
181 static void
182 AcpiDbDisplayHelp (
183 char *Command);
185 static BOOLEAN
186 AcpiDbMatchCommandHelp (
187 const char *Command,
188 const ACPI_DB_COMMAND_HELP *Help);
192 * Top-level debugger commands.
194 * This list of commands must match the string table below it
196 enum AcpiExDebuggerCommands
198 CMD_NOT_FOUND = 0,
199 CMD_NULL,
200 CMD_ALLOCATIONS,
201 CMD_ARGS,
202 CMD_ARGUMENTS,
203 CMD_BREAKPOINT,
204 CMD_BUSINFO,
205 CMD_CALL,
206 CMD_DEBUG,
207 CMD_DISASSEMBLE,
208 CMD_DISASM,
209 CMD_DUMP,
210 CMD_EVALUATE,
211 CMD_EXECUTE,
212 CMD_EXIT,
213 CMD_FIND,
214 CMD_GO,
215 CMD_HANDLERS,
216 CMD_HELP,
217 CMD_HELP2,
218 CMD_HISTORY,
219 CMD_HISTORY_EXE,
220 CMD_HISTORY_LAST,
221 CMD_INFORMATION,
222 CMD_INTEGRITY,
223 CMD_INTO,
224 CMD_LEVEL,
225 CMD_LIST,
226 CMD_LOCALS,
227 CMD_LOCKS,
228 CMD_METHODS,
229 CMD_NAMESPACE,
230 CMD_NOTIFY,
231 CMD_OBJECTS,
232 CMD_OSI,
233 CMD_OWNER,
234 CMD_PATHS,
235 CMD_PREDEFINED,
236 CMD_PREFIX,
237 CMD_QUIT,
238 CMD_REFERENCES,
239 CMD_RESOURCES,
240 CMD_RESULTS,
241 CMD_SET,
242 CMD_STATS,
243 CMD_STOP,
244 CMD_TABLES,
245 CMD_TEMPLATE,
246 CMD_TRACE,
247 CMD_TREE,
248 CMD_TYPE,
249 #ifdef ACPI_APPLICATION
250 CMD_ENABLEACPI,
251 CMD_EVENT,
252 CMD_GPE,
253 CMD_GPES,
254 CMD_SCI,
255 CMD_SLEEP,
257 CMD_CLOSE,
258 CMD_LOAD,
259 CMD_OPEN,
260 CMD_UNLOAD,
262 CMD_TERMINATE,
263 CMD_BACKGROUND,
264 CMD_THREADS,
266 CMD_TEST,
267 #endif
270 #define CMD_FIRST_VALID 2
273 /* Second parameter is the required argument count */
275 static const ACPI_DB_COMMAND_INFO AcpiGbl_DbCommands[] =
277 {"<NOT FOUND>", 0},
278 {"<NULL>", 0},
279 {"ALLOCATIONS", 0},
280 {"ARGS", 0},
281 {"ARGUMENTS", 0},
282 {"BREAKPOINT", 1},
283 {"BUSINFO", 0},
284 {"CALL", 0},
285 {"DEBUG", 1},
286 {"DISASSEMBLE", 1},
287 {"DISASM", 1},
288 {"DUMP", 1},
289 {"EVALUATE", 1},
290 {"EXECUTE", 1},
291 {"EXIT", 0},
292 {"FIND", 1},
293 {"GO", 0},
294 {"HANDLERS", 0},
295 {"HELP", 0},
296 {"?", 0},
297 {"HISTORY", 0},
298 {"!", 1},
299 {"!!", 0},
300 {"INFORMATION", 0},
301 {"INTEGRITY", 0},
302 {"INTO", 0},
303 {"LEVEL", 0},
304 {"LIST", 0},
305 {"LOCALS", 0},
306 {"LOCKS", 0},
307 {"METHODS", 0},
308 {"NAMESPACE", 0},
309 {"NOTIFY", 2},
310 {"OBJECTS", 0},
311 {"OSI", 0},
312 {"OWNER", 1},
313 {"PATHS", 0},
314 {"PREDEFINED", 0},
315 {"PREFIX", 0},
316 {"QUIT", 0},
317 {"REFERENCES", 1},
318 {"RESOURCES", 0},
319 {"RESULTS", 0},
320 {"SET", 3},
321 {"STATS", 1},
322 {"STOP", 0},
323 {"TABLES", 0},
324 {"TEMPLATE", 1},
325 {"TRACE", 1},
326 {"TREE", 0},
327 {"TYPE", 1},
328 #ifdef ACPI_APPLICATION
329 {"ENABLEACPI", 0},
330 {"EVENT", 1},
331 {"GPE", 1},
332 {"GPES", 0},
333 {"SCI", 0},
334 {"SLEEP", 0},
336 {"CLOSE", 0},
337 {"LOAD", 1},
338 {"OPEN", 1},
339 {"UNLOAD", 1},
341 {"TERMINATE", 0},
342 {"BACKGROUND", 1},
343 {"THREADS", 3},
345 {"TEST", 1},
346 #endif
347 {NULL, 0}
351 * Help for all debugger commands. First argument is the number of lines
352 * of help to output for the command.
354 * Note: Some commands are not supported by the kernel-level version of
355 * the debugger.
357 static const ACPI_DB_COMMAND_HELP AcpiGbl_DbCommandHelp[] =
359 {0, "\nNamespace Access:", "\n"},
360 {1, " Businfo", "Display system bus info\n"},
361 {1, " Disassemble <Method>", "Disassemble a control method\n"},
362 {1, " Find <AcpiName> (? is wildcard)", "Find ACPI name(s) with wildcards\n"},
363 {1, " Integrity", "Validate namespace integrity\n"},
364 {1, " Methods", "Display list of loaded control methods\n"},
365 {1, " Namespace [Object] [Depth]", "Display loaded namespace tree/subtree\n"},
366 {1, " Notify <Object> <Value>", "Send a notification on Object\n"},
367 {1, " Objects [ObjectType]", "Display summary of all objects or just given type\n"},
368 {1, " Owner <OwnerId> [Depth]", "Display loaded namespace by object owner\n"},
369 {1, " Paths", "Display full pathnames of namespace objects\n"},
370 {1, " Predefined", "Check all predefined names\n"},
371 {1, " Prefix [<Namepath>]", "Set or Get current execution prefix\n"},
372 {1, " References <Addr>", "Find all references to object at addr\n"},
373 {1, " Resources [DeviceName]", "Display Device resources (no arg = all devices)\n"},
374 {1, " Set N <NamedObject> <Value>", "Set value for named integer\n"},
375 {1, " Template <Object>", "Format/dump a Buffer/ResourceTemplate\n"},
376 {1, " Type <Object>", "Display object type\n"},
378 {0, "\nControl Method Execution:", "\n"},
379 {1, " Evaluate <Namepath> [Arguments]", "Evaluate object or control method\n"},
380 {1, " Execute <Namepath> [Arguments]", "Synonym for Evaluate\n"},
381 #ifdef ACPI_APPLICATION
382 {1, " Background <Namepath> [Arguments]", "Evaluate object/method in a separate thread\n"},
383 {1, " Thread <Threads><Loops><NamePath>", "Spawn threads to execute method(s)\n"},
384 #endif
385 {1, " Debug <Namepath> [Arguments]", "Single-Step a control method\n"},
386 {7, " [Arguments] formats:", "Control method argument formats\n"},
387 {1, " Hex Integer", "Integer\n"},
388 {1, " \"Ascii String\"", "String\n"},
389 {1, " (Hex Byte List)", "Buffer\n"},
390 {1, " (01 42 7A BF)", "Buffer example (4 bytes)\n"},
391 {1, " [Package Element List]", "Package\n"},
392 {1, " [0x01 0x1234 \"string\"]", "Package example (3 elements)\n"},
394 {0, "\nMiscellaneous:", "\n"},
395 {1, " Allocations", "Display list of current memory allocations\n"},
396 {2, " Dump <Address>|<Namepath>", "\n"},
397 {0, " [Byte|Word|Dword|Qword]", "Display ACPI objects or memory\n"},
398 {1, " Handlers", "Info about global handlers\n"},
399 {1, " Help [Command]", "This help screen or individual command\n"},
400 {1, " History", "Display command history buffer\n"},
401 {1, " Level <DebugLevel>] [console]", "Get/Set debug level for file or console\n"},
402 {1, " Locks", "Current status of internal mutexes\n"},
403 {1, " Osi [Install|Remove <name>]", "Display or modify global _OSI list\n"},
404 {1, " Quit or Exit", "Exit this command\n"},
405 {8, " Stats <SubCommand>", "Display namespace and memory statistics\n"},
406 {1, " Allocations", "Display list of current memory allocations\n"},
407 {1, " Memory", "Dump internal memory lists\n"},
408 {1, " Misc", "Namespace search and mutex stats\n"},
409 {1, " Objects", "Summary of namespace objects\n"},
410 {1, " Sizes", "Sizes for each of the internal objects\n"},
411 {1, " Stack", "Display CPU stack usage\n"},
412 {1, " Tables", "Info about current ACPI table(s)\n"},
413 {1, " Tables", "Display info about loaded ACPI tables\n"},
414 #ifdef ACPI_APPLICATION
415 {1, " Terminate", "Delete namespace and all internal objects\n"},
416 #endif
417 {1, " ! <CommandNumber>", "Execute command from history buffer\n"},
418 {1, " !!", "Execute last command again\n"},
420 {0, "\nMethod and Namespace Debugging:", "\n"},
421 {5, " Trace <State> [<Namepath>] [Once]", "Trace control method execution\n"},
422 {1, " Enable", "Enable all messages\n"},
423 {1, " Disable", "Disable tracing\n"},
424 {1, " Method", "Enable method execution messages\n"},
425 {1, " Opcode", "Enable opcode execution messages\n"},
426 {3, " Test <TestName>", "Invoke a debug test\n"},
427 {1, " Objects", "Read/write/compare all namespace data objects\n"},
428 {1, " Predefined", "Validate all ACPI predefined names (_STA, etc.)\n"},
429 {1, " Execute predefined", "Execute all predefined (public) methods\n"},
431 {0, "\nControl Method Single-Step Execution:","\n"},
432 {1, " Arguments (or Args)", "Display method arguments\n"},
433 {1, " Breakpoint <AmlOffset>", "Set an AML execution breakpoint\n"},
434 {1, " Call", "Run to next control method invocation\n"},
435 {1, " Go", "Allow method to run to completion\n"},
436 {1, " Information", "Display info about the current method\n"},
437 {1, " Into", "Step into (not over) a method call\n"},
438 {1, " List [# of Aml Opcodes]", "Display method ASL statements\n"},
439 {1, " Locals", "Display method local variables\n"},
440 {1, " Results", "Display method result stack\n"},
441 {1, " Set <A|L> <#> <Value>", "Set method data (Arguments/Locals)\n"},
442 {1, " Stop", "Terminate control method\n"},
443 {1, " Tree", "Display control method calling tree\n"},
444 {1, " <Enter>", "Single step next AML opcode (over calls)\n"},
446 #ifdef ACPI_APPLICATION
447 {0, "\nFile Operations:", "\n"},
448 {1, " Close", "Close debug output file\n"},
449 {1, " Load <Input Filename>", "Load ACPI table from a file\n"},
450 {1, " Open <Output Filename>", "Open a file for debug output\n"},
451 {1, " Unload <Namepath>", "Unload an ACPI table via namespace object\n"},
453 {0, "\nHardware Simulation:", "\n"},
454 {1, " EnableAcpi", "Enable ACPI (hardware) mode\n"},
455 {1, " Event <F|G> <Value>", "Generate AcpiEvent (Fixed/GPE)\n"},
456 {1, " Gpe <GpeNum> [GpeBlockDevice]", "Simulate a GPE\n"},
457 {1, " Gpes", "Display info on all GPE devices\n"},
458 {1, " Sci", "Generate an SCI\n"},
459 {1, " Sleep [SleepState]", "Simulate sleep/wake sequence(s) (0-5)\n"},
460 #endif
461 {0, NULL, NULL}
465 /*******************************************************************************
467 * FUNCTION: AcpiDbMatchCommandHelp
469 * PARAMETERS: Command - Command string to match
470 * Help - Help table entry to attempt match
472 * RETURN: TRUE if command matched, FALSE otherwise
474 * DESCRIPTION: Attempt to match a command in the help table in order to
475 * print help information for a single command.
477 ******************************************************************************/
479 static BOOLEAN
480 AcpiDbMatchCommandHelp (
481 const char *Command,
482 const ACPI_DB_COMMAND_HELP *Help)
484 char *Invocation = Help->Invocation;
485 UINT32 LineCount;
488 /* Valid commands in the help table begin with a couple of spaces */
490 if (*Invocation != ' ')
492 return (FALSE);
495 while (*Invocation == ' ')
497 Invocation++;
500 /* Match command name (full command or substring) */
502 while ((*Command) && (*Invocation) && (*Invocation != ' '))
504 if (tolower ((int) *Command) != tolower ((int) *Invocation))
506 return (FALSE);
509 Invocation++;
510 Command++;
513 /* Print the appropriate number of help lines */
515 LineCount = Help->LineCount;
516 while (LineCount)
518 AcpiOsPrintf ("%-38s : %s", Help->Invocation, Help->Description);
519 Help++;
520 LineCount--;
523 return (TRUE);
527 /*******************************************************************************
529 * FUNCTION: AcpiDbDisplayCommandInfo
531 * PARAMETERS: Command - Command string to match
532 * DisplayAll - Display all matching commands, or just
533 * the first one (substring match)
535 * RETURN: None
537 * DESCRIPTION: Display help information for a Debugger command.
539 ******************************************************************************/
541 static void
542 AcpiDbDisplayCommandInfo (
543 const char *Command,
544 BOOLEAN DisplayAll)
546 const ACPI_DB_COMMAND_HELP *Next;
547 BOOLEAN Matched;
550 Next = AcpiGbl_DbCommandHelp;
551 while (Next->Invocation)
553 Matched = AcpiDbMatchCommandHelp (Command, Next);
554 if (!DisplayAll && Matched)
556 return;
559 Next++;
564 /*******************************************************************************
566 * FUNCTION: AcpiDbDisplayHelp
568 * PARAMETERS: Command - Optional command string to display help.
569 * if not specified, all debugger command
570 * help strings are displayed
572 * RETURN: None
574 * DESCRIPTION: Display help for a single debugger command, or all of them.
576 ******************************************************************************/
578 static void
579 AcpiDbDisplayHelp (
580 char *Command)
582 const ACPI_DB_COMMAND_HELP *Next = AcpiGbl_DbCommandHelp;
585 if (!Command)
587 /* No argument to help, display help for all commands */
589 AcpiOsPrintf ("\nSummary of AML Debugger Commands\n\n");
591 while (Next->Invocation)
593 AcpiOsPrintf ("%-38s%s", Next->Invocation, Next->Description);
594 Next++;
596 AcpiOsPrintf ("\n");
599 else
601 /* Display help for all commands that match the subtring */
603 AcpiDbDisplayCommandInfo (Command, TRUE);
608 /*******************************************************************************
610 * FUNCTION: AcpiDbGetNextToken
612 * PARAMETERS: String - Command buffer
613 * Next - Return value, end of next token
615 * RETURN: Pointer to the start of the next token.
617 * DESCRIPTION: Command line parsing. Get the next token on the command line
619 ******************************************************************************/
621 char *
622 AcpiDbGetNextToken (
623 char *String,
624 char **Next,
625 ACPI_OBJECT_TYPE *ReturnType)
627 char *Start;
628 UINT32 Depth;
629 ACPI_OBJECT_TYPE Type = ACPI_TYPE_INTEGER;
632 /* At end of buffer? */
634 if (!String || !(*String))
636 return (NULL);
639 /* Remove any spaces at the beginning */
641 if (*String == ' ')
643 while (*String && (*String == ' '))
645 String++;
648 if (!(*String))
650 return (NULL);
654 switch (*String)
656 case '"':
658 /* This is a quoted string, scan until closing quote */
660 String++;
661 Start = String;
662 Type = ACPI_TYPE_STRING;
664 /* Find end of string */
666 while (*String && (*String != '"'))
668 String++;
670 break;
672 case '(':
674 /* This is the start of a buffer, scan until closing paren */
676 String++;
677 Start = String;
678 Type = ACPI_TYPE_BUFFER;
680 /* Find end of buffer */
682 while (*String && (*String != ')'))
684 String++;
686 break;
688 case '[':
690 /* This is the start of a package, scan until closing bracket */
692 String++;
693 Depth = 1;
694 Start = String;
695 Type = ACPI_TYPE_PACKAGE;
697 /* Find end of package (closing bracket) */
699 while (*String)
701 /* Handle String package elements */
703 if (*String == '"')
705 /* Find end of string */
707 String++;
708 while (*String && (*String != '"'))
710 String++;
712 if (!(*String))
714 break;
717 else if (*String == '[')
719 Depth++; /* A nested package declaration */
721 else if (*String == ']')
723 Depth--;
724 if (Depth == 0) /* Found final package closing bracket */
726 break;
730 String++;
732 break;
734 default:
736 Start = String;
738 /* Find end of token */
740 while (*String && (*String != ' '))
742 String++;
744 break;
747 if (!(*String))
749 *Next = NULL;
751 else
753 *String = 0;
754 *Next = String + 1;
757 *ReturnType = Type;
758 return (Start);
762 /*******************************************************************************
764 * FUNCTION: AcpiDbGetLine
766 * PARAMETERS: InputBuffer - Command line buffer
768 * RETURN: Count of arguments to the command
770 * DESCRIPTION: Get the next command line from the user. Gets entire line
771 * up to the next newline
773 ******************************************************************************/
775 static UINT32
776 AcpiDbGetLine (
777 char *InputBuffer)
779 UINT32 i;
780 UINT32 Count;
781 char *Next;
782 char *This;
785 if (AcpiUtSafeStrcpy (AcpiGbl_DbParsedBuf, sizeof (AcpiGbl_DbParsedBuf),
786 InputBuffer))
788 AcpiOsPrintf (
789 "Buffer overflow while parsing input line (max %u characters)\n",
790 sizeof (AcpiGbl_DbParsedBuf));
791 return (0);
794 This = AcpiGbl_DbParsedBuf;
795 for (i = 0; i < ACPI_DEBUGGER_MAX_ARGS; i++)
797 AcpiGbl_DbArgs[i] = AcpiDbGetNextToken (This, &Next,
798 &AcpiGbl_DbArgTypes[i]);
799 if (!AcpiGbl_DbArgs[i])
801 break;
804 This = Next;
807 /* Uppercase the actual command */
809 AcpiUtStrupr (AcpiGbl_DbArgs[0]);
811 Count = i;
812 if (Count)
814 Count--; /* Number of args only */
817 return (Count);
821 /*******************************************************************************
823 * FUNCTION: AcpiDbMatchCommand
825 * PARAMETERS: UserCommand - User command line
827 * RETURN: Index into command array, -1 if not found
829 * DESCRIPTION: Search command array for a command match
831 ******************************************************************************/
833 static UINT32
834 AcpiDbMatchCommand (
835 char *UserCommand)
837 UINT32 i;
840 if (!UserCommand || UserCommand[0] == 0)
842 return (CMD_NULL);
845 for (i = CMD_FIRST_VALID; AcpiGbl_DbCommands[i].Name; i++)
847 if (strstr (
848 ACPI_CAST_PTR (char, AcpiGbl_DbCommands[i].Name), UserCommand) ==
849 AcpiGbl_DbCommands[i].Name)
851 return (i);
855 /* Command not recognized */
857 return (CMD_NOT_FOUND);
861 /*******************************************************************************
863 * FUNCTION: AcpiDbCommandDispatch
865 * PARAMETERS: InputBuffer - Command line buffer
866 * WalkState - Current walk
867 * Op - Current (executing) parse op
869 * RETURN: Status
871 * DESCRIPTION: Command dispatcher.
873 ******************************************************************************/
875 ACPI_STATUS
876 AcpiDbCommandDispatch (
877 char *InputBuffer,
878 ACPI_WALK_STATE *WalkState,
879 ACPI_PARSE_OBJECT *Op)
881 UINT32 Temp;
882 UINT32 CommandIndex;
883 UINT32 ParamCount;
884 char *CommandLine;
885 ACPI_STATUS Status = AE_CTRL_TRUE;
888 /* If AcpiTerminate has been called, terminate this thread */
890 if (AcpiGbl_DbTerminateLoop)
892 return (AE_CTRL_TERMINATE);
895 /* Find command and add to the history buffer */
897 ParamCount = AcpiDbGetLine (InputBuffer);
898 CommandIndex = AcpiDbMatchCommand (AcpiGbl_DbArgs[0]);
899 Temp = 0;
902 * We don't want to add the !! command to the history buffer. It
903 * would cause an infinite loop because it would always be the
904 * previous command.
906 if (CommandIndex != CMD_HISTORY_LAST)
908 AcpiDbAddToHistory (InputBuffer);
911 /* Verify that we have the minimum number of params */
913 if (ParamCount < AcpiGbl_DbCommands[CommandIndex].MinArgs)
915 AcpiOsPrintf ("%u parameters entered, [%s] requires %u parameters\n",
916 ParamCount, AcpiGbl_DbCommands[CommandIndex].Name,
917 AcpiGbl_DbCommands[CommandIndex].MinArgs);
919 AcpiDbDisplayCommandInfo (
920 AcpiGbl_DbCommands[CommandIndex].Name, FALSE);
921 return (AE_CTRL_TRUE);
924 /* Decode and dispatch the command */
926 switch (CommandIndex)
928 case CMD_NULL:
930 if (Op)
932 return (AE_OK);
934 break;
936 case CMD_ALLOCATIONS:
938 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
939 AcpiUtDumpAllocations ((UINT32) -1, NULL);
940 #endif
941 break;
943 case CMD_ARGS:
944 case CMD_ARGUMENTS:
946 AcpiDbDisplayArguments ();
947 break;
949 case CMD_BREAKPOINT:
951 AcpiDbSetMethodBreakpoint (AcpiGbl_DbArgs[1], WalkState, Op);
952 break;
954 case CMD_BUSINFO:
956 AcpiDbGetBusInfo ();
957 break;
959 case CMD_CALL:
961 AcpiDbSetMethodCallBreakpoint (Op);
962 Status = AE_OK;
963 break;
965 case CMD_DEBUG:
967 AcpiDbExecute (AcpiGbl_DbArgs[1],
968 &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_SINGLE_STEP);
969 break;
971 case CMD_DISASSEMBLE:
972 case CMD_DISASM:
974 #ifdef ACPI_DISASSEMBLER
975 (void) AcpiDbDisassembleMethod (AcpiGbl_DbArgs[1]);
976 #else
977 AcpiOsPrintf ("The AML Disassembler is not configured/present\n");
978 #endif
979 break;
981 case CMD_DUMP:
983 AcpiDbDecodeAndDisplayObject (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
984 break;
986 case CMD_EVALUATE:
987 case CMD_EXECUTE:
989 AcpiDbExecute (AcpiGbl_DbArgs[1],
990 &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_NO_SINGLE_STEP);
991 break;
993 case CMD_FIND:
995 Status = AcpiDbFindNameInNamespace (AcpiGbl_DbArgs[1]);
996 break;
998 case CMD_GO:
1000 AcpiGbl_CmSingleStep = FALSE;
1001 return (AE_OK);
1003 case CMD_HANDLERS:
1005 AcpiDbDisplayHandlers ();
1006 break;
1008 case CMD_HELP:
1009 case CMD_HELP2:
1011 AcpiDbDisplayHelp (AcpiGbl_DbArgs[1]);
1012 break;
1014 case CMD_HISTORY:
1016 AcpiDbDisplayHistory ();
1017 break;
1019 case CMD_HISTORY_EXE: /* ! command */
1021 CommandLine = AcpiDbGetFromHistory (AcpiGbl_DbArgs[1]);
1022 if (!CommandLine)
1024 return (AE_CTRL_TRUE);
1027 Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
1028 return (Status);
1030 case CMD_HISTORY_LAST: /* !! command */
1032 CommandLine = AcpiDbGetFromHistory (NULL);
1033 if (!CommandLine)
1035 return (AE_CTRL_TRUE);
1038 Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
1039 return (Status);
1041 case CMD_INFORMATION:
1043 AcpiDbDisplayMethodInfo (Op);
1044 break;
1046 case CMD_INTEGRITY:
1048 AcpiDbCheckIntegrity ();
1049 break;
1051 case CMD_INTO:
1053 if (Op)
1055 AcpiGbl_CmSingleStep = TRUE;
1056 return (AE_OK);
1058 break;
1060 case CMD_LEVEL:
1062 if (ParamCount == 0)
1064 AcpiOsPrintf (
1065 "Current debug level for file output is: %8.8lX\n",
1066 AcpiGbl_DbDebugLevel);
1067 AcpiOsPrintf (
1068 "Current debug level for console output is: %8.8lX\n",
1069 AcpiGbl_DbConsoleDebugLevel);
1071 else if (ParamCount == 2)
1073 Temp = AcpiGbl_DbConsoleDebugLevel;
1074 AcpiGbl_DbConsoleDebugLevel =
1075 strtoul (AcpiGbl_DbArgs[1], NULL, 16);
1076 AcpiOsPrintf (
1077 "Debug Level for console output was %8.8lX, now %8.8lX\n",
1078 Temp, AcpiGbl_DbConsoleDebugLevel);
1080 else
1082 Temp = AcpiGbl_DbDebugLevel;
1083 AcpiGbl_DbDebugLevel = strtoul (AcpiGbl_DbArgs[1], NULL, 16);
1084 AcpiOsPrintf (
1085 "Debug Level for file output was %8.8lX, now %8.8lX\n",
1086 Temp, AcpiGbl_DbDebugLevel);
1088 break;
1090 case CMD_LIST:
1092 #ifdef ACPI_DISASSEMBLER
1093 AcpiDbDisassembleAml (AcpiGbl_DbArgs[1], Op);
1094 #else
1095 AcpiOsPrintf ("The AML Disassembler is not configured/present\n");
1096 #endif
1097 break;
1099 case CMD_LOCKS:
1101 AcpiDbDisplayLocks ();
1102 break;
1104 case CMD_LOCALS:
1106 AcpiDbDisplayLocals ();
1107 break;
1109 case CMD_METHODS:
1111 Status = AcpiDbDisplayObjects ("METHOD", AcpiGbl_DbArgs[1]);
1112 break;
1114 case CMD_NAMESPACE:
1116 AcpiDbDumpNamespace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1117 break;
1119 case CMD_NOTIFY:
1121 Temp = strtoul (AcpiGbl_DbArgs[2], NULL, 0);
1122 AcpiDbSendNotify (AcpiGbl_DbArgs[1], Temp);
1123 break;
1125 case CMD_OBJECTS:
1127 AcpiUtStrupr (AcpiGbl_DbArgs[1]);
1128 Status = AcpiDbDisplayObjects (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1129 break;
1131 case CMD_OSI:
1133 AcpiDbDisplayInterfaces (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1134 break;
1136 case CMD_OWNER:
1138 AcpiDbDumpNamespaceByOwner (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1139 break;
1141 case CMD_PATHS:
1143 AcpiDbDumpNamespacePaths ();
1144 break;
1146 case CMD_PREFIX:
1148 AcpiDbSetScope (AcpiGbl_DbArgs[1]);
1149 break;
1151 case CMD_REFERENCES:
1153 AcpiDbFindReferences (AcpiGbl_DbArgs[1]);
1154 break;
1156 case CMD_RESOURCES:
1158 AcpiDbDisplayResources (AcpiGbl_DbArgs[1]);
1159 break;
1161 case CMD_RESULTS:
1163 AcpiDbDisplayResults ();
1164 break;
1166 case CMD_SET:
1168 AcpiDbSetMethodData (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],
1169 AcpiGbl_DbArgs[3]);
1170 break;
1172 case CMD_STATS:
1174 Status = AcpiDbDisplayStatistics (AcpiGbl_DbArgs[1]);
1175 break;
1177 case CMD_STOP:
1179 return (AE_NOT_IMPLEMENTED);
1181 case CMD_TABLES:
1183 AcpiDbDisplayTableInfo (AcpiGbl_DbArgs[1]);
1184 break;
1186 case CMD_TEMPLATE:
1188 AcpiDbDisplayTemplate (AcpiGbl_DbArgs[1]);
1189 break;
1191 case CMD_TRACE:
1193 AcpiDbTrace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], AcpiGbl_DbArgs[3]);
1194 break;
1196 case CMD_TREE:
1198 AcpiDbDisplayCallingTree ();
1199 break;
1201 case CMD_TYPE:
1203 AcpiDbDisplayObjectType (AcpiGbl_DbArgs[1]);
1204 break;
1206 #ifdef ACPI_APPLICATION
1208 /* Hardware simulation commands. */
1210 case CMD_ENABLEACPI:
1211 #if (!ACPI_REDUCED_HARDWARE)
1213 Status = AcpiEnable();
1214 if (ACPI_FAILURE(Status))
1216 AcpiOsPrintf("AcpiEnable failed (Status=%X)\n", Status);
1217 return (Status);
1219 #endif /* !ACPI_REDUCED_HARDWARE */
1220 break;
1222 case CMD_EVENT:
1224 AcpiOsPrintf ("Event command not implemented\n");
1225 break;
1227 case CMD_GPE:
1229 AcpiDbGenerateGpe (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1230 break;
1232 case CMD_GPES:
1234 AcpiDbDisplayGpes ();
1235 break;
1237 case CMD_SCI:
1239 AcpiDbGenerateSci ();
1240 break;
1242 case CMD_SLEEP:
1244 Status = AcpiDbSleep (AcpiGbl_DbArgs[1]);
1245 break;
1247 /* File I/O commands. */
1249 case CMD_CLOSE:
1251 AcpiDbCloseDebugFile ();
1252 break;
1254 case CMD_LOAD:
1256 ACPI_NEW_TABLE_DESC *ListHead = NULL;
1258 Status = AcGetAllTablesFromFile (AcpiGbl_DbArgs[1],
1259 ACPI_GET_ALL_TABLES, &ListHead);
1260 if (ACPI_SUCCESS (Status))
1262 AcpiDbLoadTables (ListHead);
1265 break;
1267 case CMD_OPEN:
1269 AcpiDbOpenDebugFile (AcpiGbl_DbArgs[1]);
1270 break;
1272 /* User space commands. */
1274 case CMD_TERMINATE:
1276 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
1277 AcpiUtSubsystemShutdown ();
1280 * TBD: [Restructure] Need some way to re-initialize without
1281 * re-creating the semaphores!
1284 AcpiGbl_DbTerminateLoop = TRUE;
1285 /* AcpiInitialize (NULL); */
1286 break;
1288 case CMD_BACKGROUND:
1290 AcpiDbCreateExecutionThread (AcpiGbl_DbArgs[1], &AcpiGbl_DbArgs[2],
1291 &AcpiGbl_DbArgTypes[2]);
1292 break;
1294 case CMD_THREADS:
1296 AcpiDbCreateExecutionThreads (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],
1297 AcpiGbl_DbArgs[3]);
1298 break;
1300 /* Debug test commands. */
1302 case CMD_PREDEFINED:
1304 AcpiDbCheckPredefinedNames ();
1305 break;
1307 case CMD_TEST:
1309 AcpiDbExecuteTest (AcpiGbl_DbArgs[1]);
1310 break;
1312 case CMD_UNLOAD:
1314 AcpiDbUnloadAcpiTable (AcpiGbl_DbArgs[1]);
1315 break;
1316 #endif
1318 case CMD_EXIT:
1319 case CMD_QUIT:
1321 if (Op)
1323 AcpiOsPrintf ("Method execution terminated\n");
1324 return (AE_CTRL_TERMINATE);
1327 if (!AcpiGbl_DbOutputToFile)
1329 AcpiDbgLevel = ACPI_DEBUG_DEFAULT;
1332 #ifdef ACPI_APPLICATION
1333 AcpiDbCloseDebugFile ();
1334 #endif
1335 AcpiGbl_DbTerminateLoop = TRUE;
1336 return (AE_CTRL_TERMINATE);
1338 case CMD_NOT_FOUND:
1339 default:
1341 AcpiOsPrintf ("%s: unknown command\n", AcpiGbl_DbArgs[0]);
1342 return (AE_CTRL_TRUE);
1345 if (ACPI_SUCCESS (Status))
1347 Status = AE_CTRL_TRUE;
1350 return (Status);
1354 /*******************************************************************************
1356 * FUNCTION: AcpiDbExecuteThread
1358 * PARAMETERS: Context - Not used
1360 * RETURN: None
1362 * DESCRIPTION: Debugger execute thread. Waits for a command line, then
1363 * simply dispatches it.
1365 ******************************************************************************/
1367 void ACPI_SYSTEM_XFACE
1368 AcpiDbExecuteThread (
1369 void *Context)
1372 (void) AcpiDbUserCommands ();
1373 AcpiGbl_DbThreadsTerminated = TRUE;
1377 /*******************************************************************************
1379 * FUNCTION: AcpiDbUserCommands
1381 * PARAMETERS: None
1383 * RETURN: None
1385 * DESCRIPTION: Command line execution for the AML debugger. Commands are
1386 * matched and dispatched here.
1388 ******************************************************************************/
1390 ACPI_STATUS
1391 AcpiDbUserCommands (
1392 void)
1394 ACPI_STATUS Status = AE_OK;
1397 AcpiOsPrintf ("\n");
1399 /* TBD: [Restructure] Need a separate command line buffer for step mode */
1401 while (!AcpiGbl_DbTerminateLoop)
1403 /* Wait the readiness of the command */
1405 Status = AcpiOsWaitCommandReady ();
1406 if (ACPI_FAILURE (Status))
1408 break;
1411 /* Just call to the command line interpreter */
1413 AcpiGbl_MethodExecuting = FALSE;
1414 AcpiGbl_StepToNextCall = FALSE;
1416 (void) AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
1418 /* Notify the completion of the command */
1420 Status = AcpiOsNotifyCommandComplete ();
1421 if (ACPI_FAILURE (Status))
1423 break;
1427 if (ACPI_FAILURE (Status) && Status != AE_CTRL_TERMINATE)
1429 ACPI_EXCEPTION ((AE_INFO, Status, "While parsing command line"));
1431 return (Status);
1434 #endif /* ACPI_DEBUGGER */