xref: /freebsd/sys/contrib/dev/acpica/components/debugger/dbinput.c (revision 07c64d74917e7c8ca61c77413dbd533390e7dca7)
1 /*******************************************************************************
2  *
3  * Module Name: dbinput - user front-end to the AML debugger
4  *
5  ******************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2023, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
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.
20  *
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
27  *
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;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
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.
53  *
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.
65  *
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.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
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.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
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.
89  *
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.
98  *
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.
113  *
114  *****************************************************************************
115  *
116  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
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.
133  *
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.
145  *
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.
149  *
150  *****************************************************************************/
151 
152 #include <contrib/dev/acpica/include/acpi.h>
153 #include <contrib/dev/acpica/include/accommon.h>
154 #include <contrib/dev/acpica/include/acdebug.h>
155 
156 #ifdef ACPI_APPLICATION
157 #include <contrib/dev/acpica/include/acapps.h>
158 #endif
159 
160 #define _COMPONENT          ACPI_CA_DEBUGGER
161         ACPI_MODULE_NAME    ("dbinput")
162 
163 
164 /* Local prototypes */
165 
166 static UINT32
167 AcpiDbGetLine (
168     char                    *InputBuffer);
169 
170 static UINT32
171 AcpiDbMatchCommand (
172     char                    *UserCommand);
173 
174 static void
175 AcpiDbDisplayCommandInfo (
176     const char              *Command,
177     BOOLEAN                 DisplayAll);
178 
179 static void
180 AcpiDbDisplayHelp (
181     char                    *Command);
182 
183 static BOOLEAN
184 AcpiDbMatchCommandHelp (
185     const char                  *Command,
186     const ACPI_DB_COMMAND_HELP  *Help);
187 
188 
189 /*
190  * Top-level debugger commands.
191  *
192  * This list of commands must match the string table below it
193  */
194 enum AcpiExDebuggerCommands
195 {
196     CMD_NOT_FOUND = 0,
197     CMD_NULL,
198     CMD_ALL,
199     CMD_ALLOCATIONS,
200     CMD_ARGS,
201     CMD_ARGUMENTS,
202     CMD_BREAKPOINT,
203     CMD_BUSINFO,
204     CMD_CALL,
205     CMD_DEBUG,
206     CMD_DISASSEMBLE,
207     CMD_DISASM,
208     CMD_DUMP,
209     CMD_EVALUATE,
210     CMD_EXECUTE,
211     CMD_EXIT,
212     CMD_FIELDS,
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,
256 
257     CMD_CLOSE,
258     CMD_LOAD,
259     CMD_OPEN,
260     CMD_UNLOAD,
261 
262     CMD_TERMINATE,
263     CMD_BACKGROUND,
264     CMD_THREADS,
265 
266     CMD_TEST,
267 	CMD_INTERRUPT,
268 #endif
269 };
270 
271 #define CMD_FIRST_VALID     2
272 
273 
274 /* Second parameter is the required argument count */
275 
276 static const ACPI_DB_COMMAND_INFO   AcpiGbl_DbCommands[] =
277 {
278     {"<NOT FOUND>",  0},
279     {"<NULL>",       0},
280     {"ALL",          1},
281     {"ALLOCATIONS",  0},
282     {"ARGS",         0},
283     {"ARGUMENTS",    0},
284     {"BREAKPOINT",   1},
285     {"BUSINFO",      0},
286     {"CALL",         0},
287     {"DEBUG",        1},
288     {"DISASSEMBLE",  1},
289     {"DISASM",       1},
290     {"DUMP",         1},
291     {"EVALUATE",     1},
292     {"EXECUTE",      1},
293     {"EXIT",         0},
294     {"FIELDS",       1},
295     {"FIND",         1},
296     {"GO",           0},
297     {"HANDLERS",     0},
298     {"HELP",         0},
299     {"?",            0},
300     {"HISTORY",      0},
301     {"!",            1},
302     {"!!",           0},
303     {"INFORMATION",  0},
304     {"INTEGRITY",    0},
305     {"INTO",         0},
306     {"LEVEL",        0},
307     {"LIST",         0},
308     {"LOCALS",       0},
309     {"LOCKS",        0},
310     {"METHODS",      0},
311     {"NAMESPACE",    0},
312     {"NOTIFY",       2},
313     {"OBJECTS",      0},
314     {"OSI",          0},
315     {"OWNER",        1},
316     {"PATHS",        0},
317     {"PREDEFINED",   0},
318     {"PREFIX",       0},
319     {"QUIT",         0},
320     {"REFERENCES",   1},
321     {"RESOURCES",    0},
322     {"RESULTS",      0},
323     {"SET",          3},
324     {"STATS",        1},
325     {"STOP",         0},
326     {"TABLES",       0},
327     {"TEMPLATE",     1},
328     {"TRACE",        1},
329     {"TREE",         0},
330     {"TYPE",         1},
331 #ifdef ACPI_APPLICATION
332     {"ENABLEACPI",   0},
333     {"EVENT",        1},
334     {"GPE",          1},
335     {"GPES",         0},
336     {"SCI",          0},
337     {"SLEEP",        0},
338 
339     {"CLOSE",        0},
340     {"LOAD",         1},
341     {"OPEN",         1},
342     {"UNLOAD",       1},
343 
344     {"TERMINATE",    0},
345     {"BACKGROUND",   1},
346     {"THREADS",      3},
347 
348     {"TEST",         1},
349     {"INTERRUPT",    1},
350 #endif
351     {NULL,           0}
352 };
353 
354 /*
355  * Help for all debugger commands. First argument is the number of lines
356  * of help to output for the command.
357  *
358  * Note: Some commands are not supported by the kernel-level version of
359  * the debugger.
360  */
361 static const ACPI_DB_COMMAND_HELP   AcpiGbl_DbCommandHelp[] =
362 {
363     {0, "\nNamespace Access:",                  "\n"},
364     {1, "  Businfo",                            "Display system bus info\n"},
365     {1, "  Disassemble <Method>",               "Disassemble a control method\n"},
366     {1, "  Find <AcpiName> (? is wildcard)",    "Find ACPI name(s) with wildcards\n"},
367     {1, "  Integrity",                          "Validate namespace integrity\n"},
368     {1, "  Methods",                            "Display list of loaded control methods\n"},
369     {1, "  Fields <AddressSpaceId>",            "Display list of loaded field units by space ID\n"},
370     {1, "  Namespace [Object] [Depth]",         "Display loaded namespace tree/subtree\n"},
371     {1, "  Notify <Object> <Value>",            "Send a notification on Object\n"},
372     {1, "  Objects [ObjectType]",               "Display summary of all objects or just given type\n"},
373     {1, "  Owner <OwnerId> [Depth]",            "Display loaded namespace by object owner\n"},
374     {1, "  Paths",                              "Display full pathnames of namespace objects\n"},
375     {1, "  Predefined",                         "Check all predefined names\n"},
376     {1, "  Prefix [<Namepath>]",                "Set or Get current execution prefix\n"},
377     {1, "  References <Addr>",                  "Find all references to object at addr\n"},
378     {1, "  Resources [DeviceName]",             "Display Device resources (no arg = all devices)\n"},
379     {1, "  Set N <NamedObject> <Value>",        "Set value for named integer\n"},
380     {1, "  Template <Object>",                  "Format/dump a Buffer/ResourceTemplate\n"},
381     {1, "  Type <Object>",                      "Display object type\n"},
382 
383     {0, "\nControl Method Execution:",          "\n"},
384     {1, "  All <NameSeg>",                      "Evaluate all objects named NameSeg\n"},
385     {1, "  Evaluate <Namepath> [Arguments]",    "Evaluate object or control method\n"},
386     {1, "  Execute <Namepath> [Arguments]",     "Synonym for Evaluate\n"},
387 #ifdef ACPI_APPLICATION
388     {1, "  Background <Namepath> [Arguments]",  "Evaluate object/method in a separate thread\n"},
389     {1, "  Thread <Threads><Loops><NamePath>",  "Spawn threads to execute method(s)\n"},
390 #endif
391     {1, "  Debug <Namepath> [Arguments]",       "Single-Step a control method\n"},
392     {7, "  [Arguments] formats:",               "Control method argument formats\n"},
393     {1, "     Hex Integer",                     "Integer\n"},
394     {1, "     \"Ascii String\"",                "String\n"},
395     {1, "     (Hex Byte List)",                 "Buffer\n"},
396     {1, "         (01 42 7A BF)",               "Buffer example (4 bytes)\n"},
397     {1, "     [Package Element List]",          "Package\n"},
398     {1, "         [0x01 0x1234 \"string\"]",    "Package example (3 elements)\n"},
399 
400     {0, "\nMiscellaneous:",                     "\n"},
401     {1, "  Allocations",                        "Display list of current memory allocations\n"},
402     {2, "  Dump <Address>|<Namepath>",          "\n"},
403     {0, "       [Byte|Word|Dword|Qword]",       "Display ACPI objects or memory\n"},
404     {1, "  Handlers",                           "Info about global handlers\n"},
405     {1, "  Help [Command]",                     "This help screen or individual command\n"},
406     {1, "  History",                            "Display command history buffer\n"},
407     {1, "  Level <DebugLevel>] [console]",      "Get/Set debug level for file or console\n"},
408     {1, "  Locks",                              "Current status of internal mutexes\n"},
409     {1, "  Osi [Install|Remove <name>]",        "Display or modify global _OSI list\n"},
410     {1, "  Quit or Exit",                       "Exit this command\n"},
411     {8, "  Stats <SubCommand>",                 "Display namespace and memory statistics\n"},
412     {1, "     Allocations",                     "Display list of current memory allocations\n"},
413     {1, "     Memory",                          "Dump internal memory lists\n"},
414     {1, "     Misc",                            "Namespace search and mutex stats\n"},
415     {1, "     Objects",                         "Summary of namespace objects\n"},
416     {1, "     Sizes",                           "Sizes for each of the internal objects\n"},
417     {1, "     Stack",                           "Display CPU stack usage\n"},
418     {1, "     Tables",                          "Info about current ACPI table(s)\n"},
419     {1, "  Tables",                             "Display info about loaded ACPI tables\n"},
420 #ifdef ACPI_APPLICATION
421     {1, "  Terminate",                          "Delete namespace and all internal objects\n"},
422 #endif
423     {1, "  ! <CommandNumber>",                  "Execute command from history buffer\n"},
424     {1, "  !!",                                 "Execute last command again\n"},
425 
426     {0, "\nMethod and Namespace Debugging:",    "\n"},
427     {5, "  Trace <State> [<Namepath>] [Once]",  "Trace control method execution\n"},
428     {1, "     Enable",                          "Enable all messages\n"},
429     {1, "     Disable",                         "Disable tracing\n"},
430     {1, "     Method",                          "Enable method execution messages\n"},
431     {1, "     Opcode",                          "Enable opcode execution messages\n"},
432     {3, "  Test <TestName>",                    "Invoke a debug test\n"},
433     {1, "     Objects",                         "Read/write/compare all namespace data objects\n"},
434     {1, "     Predefined",                      "Validate all ACPI predefined names (_STA, etc.)\n"},
435     {1, "  Execute predefined",                 "Execute all predefined (public) methods\n"},
436 
437     {0, "\nControl Method Single-Step Execution:","\n"},
438     {1, "  Arguments (or Args)",                "Display method arguments\n"},
439     {1, "  Breakpoint <AmlOffset>",             "Set an AML execution breakpoint\n"},
440     {1, "  Call",                               "Run to next control method invocation\n"},
441     {1, "  Go",                                 "Allow method to run to completion\n"},
442     {1, "  Information",                        "Display info about the current method\n"},
443     {1, "  Into",                               "Step into (not over) a method call\n"},
444     {1, "  List [# of Aml Opcodes]",            "Display method ASL statements\n"},
445     {1, "  Locals",                             "Display method local variables\n"},
446     {1, "  Results",                            "Display method result stack\n"},
447     {1, "  Set <A|L> <#> <Value>",              "Set method data (Arguments/Locals)\n"},
448     {1, "  Stop",                               "Terminate control method\n"},
449     {1, "  Tree",                               "Display control method calling tree\n"},
450     {1, "  <Enter>",                            "Single step next AML opcode (over calls)\n"},
451 
452 #ifdef ACPI_APPLICATION
453     {0, "\nFile Operations:",                   "\n"},
454     {1, "  Close",                              "Close debug output file\n"},
455     {1, "  Load <Input Filename>",              "Load ACPI table from a file\n"},
456     {1, "  Open <Output Filename>",             "Open a file for debug output\n"},
457     {1, "  Unload <Namepath>",                  "Unload an ACPI table via namespace object\n"},
458 
459     {0, "\nHardware Simulation:",               "\n"},
460     {1, "  EnableAcpi",                         "Enable ACPI (hardware) mode\n"},
461     {1, "  Event <F|G> <Value>",                "Generate AcpiEvent (Fixed/GPE)\n"},
462     {1, "  Gpe <GpeNum> [GpeBlockDevice]",      "Simulate a GPE\n"},
463     {1, "  Gpes",                               "Display info on all GPE devices\n"},
464     {1, "  Sci",                                "Generate an SCI\n"},
465     {1, "  Sleep [SleepState]",                 "Simulate sleep/wake sequence(s) (0-5)\n"},
466     {1, "  Interrupt <GSIV>",                   "Simulate an interrupt\n"},
467 #endif
468     {0, NULL, NULL}
469 };
470 
471 
472 /*******************************************************************************
473  *
474  * FUNCTION:    AcpiDbMatchCommandHelp
475  *
476  * PARAMETERS:  Command             - Command string to match
477  *              Help                - Help table entry to attempt match
478  *
479  * RETURN:      TRUE if command matched, FALSE otherwise
480  *
481  * DESCRIPTION: Attempt to match a command in the help table in order to
482  *              print help information for a single command.
483  *
484  ******************************************************************************/
485 
486 static BOOLEAN
AcpiDbMatchCommandHelp(const char * Command,const ACPI_DB_COMMAND_HELP * Help)487 AcpiDbMatchCommandHelp (
488     const char                  *Command,
489     const ACPI_DB_COMMAND_HELP  *Help)
490 {
491     char                    *Invocation = Help->Invocation;
492     UINT32                  LineCount;
493 
494 
495     /* Valid commands in the help table begin with a couple of spaces */
496 
497     if (*Invocation != ' ')
498     {
499         return (FALSE);
500     }
501 
502     while (*Invocation == ' ')
503     {
504         Invocation++;
505     }
506 
507     /* Match command name (full command or substring) */
508 
509     while ((*Command) && (*Invocation) && (*Invocation != ' '))
510     {
511         if (tolower ((int) *Command) != tolower ((int) *Invocation))
512         {
513             return (FALSE);
514         }
515 
516         Invocation++;
517         Command++;
518     }
519 
520     /* Print the appropriate number of help lines */
521 
522     LineCount = Help->LineCount;
523     while (LineCount)
524     {
525         AcpiOsPrintf ("%-38s : %s", Help->Invocation, Help->Description);
526         Help++;
527         LineCount--;
528     }
529 
530     return (TRUE);
531 }
532 
533 
534 /*******************************************************************************
535  *
536  * FUNCTION:    AcpiDbDisplayCommandInfo
537  *
538  * PARAMETERS:  Command             - Command string to match
539  *              DisplayAll          - Display all matching commands, or just
540  *                                    the first one (substring match)
541  *
542  * RETURN:      None
543  *
544  * DESCRIPTION: Display help information for a Debugger command.
545  *
546  ******************************************************************************/
547 
548 static void
AcpiDbDisplayCommandInfo(const char * Command,BOOLEAN DisplayAll)549 AcpiDbDisplayCommandInfo (
550     const char              *Command,
551     BOOLEAN                 DisplayAll)
552 {
553     const ACPI_DB_COMMAND_HELP  *Next;
554     BOOLEAN                     Matched;
555 
556 
557     Next = AcpiGbl_DbCommandHelp;
558     while (Next->Invocation)
559     {
560         Matched = AcpiDbMatchCommandHelp (Command, Next);
561         if (!DisplayAll && Matched)
562         {
563             return;
564         }
565 
566         Next++;
567     }
568 }
569 
570 
571 /*******************************************************************************
572  *
573  * FUNCTION:    AcpiDbDisplayHelp
574  *
575  * PARAMETERS:  Command             - Optional command string to display help.
576  *                                    if not specified, all debugger command
577  *                                    help strings are displayed
578  *
579  * RETURN:      None
580  *
581  * DESCRIPTION: Display help for a single debugger command, or all of them.
582  *
583  ******************************************************************************/
584 
585 static void
AcpiDbDisplayHelp(char * Command)586 AcpiDbDisplayHelp (
587     char                    *Command)
588 {
589     const ACPI_DB_COMMAND_HELP  *Next = AcpiGbl_DbCommandHelp;
590 
591 
592     if (!Command)
593     {
594         /* No argument to help, display help for all commands */
595 
596         AcpiOsPrintf ("\nSummary of AML Debugger Commands\n\n");
597 
598         while (Next->Invocation)
599         {
600             AcpiOsPrintf ("%-38s%s", Next->Invocation, Next->Description);
601             Next++;
602         }
603         AcpiOsPrintf ("\n");
604 
605     }
606     else
607     {
608         /* Display help for all commands that match the substring */
609 
610         AcpiDbDisplayCommandInfo (Command, TRUE);
611     }
612 }
613 
614 
615 /*******************************************************************************
616  *
617  * FUNCTION:    AcpiDbGetNextToken
618  *
619  * PARAMETERS:  String          - Command buffer
620  *              Next            - Return value, end of next token
621  *
622  * RETURN:      Pointer to the start of the next token.
623  *
624  * DESCRIPTION: Command line parsing. Get the next token on the command line
625  *
626  ******************************************************************************/
627 
628 char *
AcpiDbGetNextToken(char * String,char ** Next,ACPI_OBJECT_TYPE * ReturnType)629 AcpiDbGetNextToken (
630     char                    *String,
631     char                    **Next,
632     ACPI_OBJECT_TYPE        *ReturnType)
633 {
634     char                    *Start;
635     UINT32                  Depth;
636     ACPI_OBJECT_TYPE        Type = ACPI_TYPE_INTEGER;
637 
638 
639     /* At end of buffer? */
640 
641     if (!String || !(*String))
642     {
643         return (NULL);
644     }
645 
646     /* Remove any spaces at the beginning, ignore blank lines */
647 
648     while (*String && isspace ((int) *String))
649     {
650         String++;
651     }
652 
653     if (!(*String))
654     {
655         return (NULL);
656     }
657 
658     switch (*String)
659     {
660     case '"':
661 
662         /* This is a quoted string, scan until closing quote */
663 
664         String++;
665         Start = String;
666         Type = ACPI_TYPE_STRING;
667 
668         /* Find end of string */
669 
670         while (*String && (*String != '"'))
671         {
672             String++;
673         }
674         break;
675 
676     case '(':
677 
678         /* This is the start of a buffer, scan until closing paren */
679 
680         String++;
681         Start = String;
682         Type = ACPI_TYPE_BUFFER;
683 
684         /* Find end of buffer */
685 
686         while (*String && (*String != ')'))
687         {
688             String++;
689         }
690         break;
691 
692     case '{':
693 
694         /* This is the start of a field unit, scan until closing brace */
695 
696         String++;
697         Start = String;
698         Type = ACPI_TYPE_FIELD_UNIT;
699 
700         /* Find end of buffer */
701 
702         while (*String && (*String != '}'))
703         {
704             String++;
705         }
706         break;
707 
708     case '[':
709 
710         /* This is the start of a package, scan until closing bracket */
711 
712         String++;
713         Depth = 1;
714         Start = String;
715         Type = ACPI_TYPE_PACKAGE;
716 
717         /* Find end of package (closing bracket) */
718 
719         while (*String)
720         {
721             /* Handle String package elements */
722 
723             if (*String == '"')
724             {
725                 /* Find end of string */
726 
727                 String++;
728                 while (*String && (*String != '"'))
729                 {
730                     String++;
731                 }
732                 if (!(*String))
733                 {
734                     break;
735                 }
736             }
737             else if (*String == '[')
738             {
739                 Depth++;         /* A nested package declaration */
740             }
741             else if (*String == ']')
742             {
743                 Depth--;
744                 if (Depth == 0) /* Found final package closing bracket */
745                 {
746                     break;
747                 }
748             }
749 
750             String++;
751         }
752         break;
753 
754     default:
755 
756         Start = String;
757 
758         /* Find end of token */
759 
760         while (*String && !isspace ((int) *String))
761         {
762             String++;
763         }
764         break;
765     }
766 
767     if (!(*String))
768     {
769         *Next = NULL;
770     }
771     else
772     {
773         *String = 0;
774         *Next = String + 1;
775     }
776 
777     *ReturnType = Type;
778     return (Start);
779 }
780 
781 
782 /*******************************************************************************
783  *
784  * FUNCTION:    AcpiDbGetLine
785  *
786  * PARAMETERS:  InputBuffer         - Command line buffer
787  *
788  * RETURN:      Count of arguments to the command
789  *
790  * DESCRIPTION: Get the next command line from the user. Gets entire line
791  *              up to the next newline
792  *
793  ******************************************************************************/
794 
795 static UINT32
AcpiDbGetLine(char * InputBuffer)796 AcpiDbGetLine (
797     char                    *InputBuffer)
798 {
799     UINT32                  i;
800     UINT32                  Count;
801     char                    *Next;
802     char                    *This;
803 
804 
805     if (AcpiUtSafeStrcpy (AcpiGbl_DbParsedBuf, sizeof (AcpiGbl_DbParsedBuf),
806         InputBuffer))
807     {
808         AcpiOsPrintf (
809             "Buffer overflow while parsing input line (max %u characters)\n",
810             (UINT32) sizeof (AcpiGbl_DbParsedBuf));
811         return (0);
812     }
813 
814     This = AcpiGbl_DbParsedBuf;
815     for (i = 0; i < ACPI_DEBUGGER_MAX_ARGS; i++)
816     {
817         AcpiGbl_DbArgs[i] = AcpiDbGetNextToken (This, &Next,
818             &AcpiGbl_DbArgTypes[i]);
819         if (!AcpiGbl_DbArgs[i])
820         {
821             break;
822         }
823 
824         This = Next;
825     }
826 
827     /* Uppercase the actual command */
828 
829     AcpiUtStrupr (AcpiGbl_DbArgs[0]);
830 
831     Count = i;
832     if (Count)
833     {
834         Count--;  /* Number of args only */
835     }
836 
837     return (Count);
838 }
839 
840 
841 /*******************************************************************************
842  *
843  * FUNCTION:    AcpiDbMatchCommand
844  *
845  * PARAMETERS:  UserCommand             - User command line
846  *
847  * RETURN:      Index into command array, -1 if not found
848  *
849  * DESCRIPTION: Search command array for a command match
850  *
851  ******************************************************************************/
852 
853 static UINT32
AcpiDbMatchCommand(char * UserCommand)854 AcpiDbMatchCommand (
855     char                    *UserCommand)
856 {
857     UINT32                  i;
858 
859 
860     if (!UserCommand || UserCommand[0] == 0)
861     {
862         return (CMD_NULL);
863     }
864 
865     for (i = CMD_FIRST_VALID; AcpiGbl_DbCommands[i].Name; i++)
866     {
867         if (strstr (
868             ACPI_CAST_PTR (char, AcpiGbl_DbCommands[i].Name), UserCommand) ==
869             AcpiGbl_DbCommands[i].Name)
870         {
871             return (i);
872         }
873     }
874 
875     /* Command not recognized */
876 
877     return (CMD_NOT_FOUND);
878 }
879 
880 
881 /*******************************************************************************
882  *
883  * FUNCTION:    AcpiDbCommandDispatch
884  *
885  * PARAMETERS:  InputBuffer         - Command line buffer
886  *              WalkState           - Current walk
887  *              Op                  - Current (executing) parse op
888  *
889  * RETURN:      Status
890  *
891  * DESCRIPTION: Command dispatcher.
892  *
893  ******************************************************************************/
894 
895 ACPI_STATUS
AcpiDbCommandDispatch(char * InputBuffer,ACPI_WALK_STATE * WalkState,ACPI_PARSE_OBJECT * Op)896 AcpiDbCommandDispatch (
897     char                    *InputBuffer,
898     ACPI_WALK_STATE         *WalkState,
899     ACPI_PARSE_OBJECT       *Op)
900 {
901     UINT32                  Temp;
902     UINT64                  Temp64;
903     UINT32                  CommandIndex;
904     UINT32                  ParamCount;
905     char                    *CommandLine;
906     ACPI_STATUS             Status = AE_CTRL_TRUE;
907 
908 
909     /* If AcpiTerminate has been called, terminate this thread */
910 
911     if (AcpiGbl_DbTerminateLoop)
912     {
913         return (AE_CTRL_TERMINATE);
914     }
915 
916     /* Find command and add to the history buffer */
917 
918     ParamCount = AcpiDbGetLine (InputBuffer);
919     CommandIndex = AcpiDbMatchCommand (AcpiGbl_DbArgs[0]);
920 
921     /*
922      * We don't want to add the !! command to the history buffer. It
923      * would cause an infinite loop because it would always be the
924      * previous command.
925      */
926     if (CommandIndex != CMD_HISTORY_LAST)
927     {
928         AcpiDbAddToHistory (InputBuffer);
929     }
930 
931     /* Verify that we have the minimum number of params */
932 
933     if (ParamCount < AcpiGbl_DbCommands[CommandIndex].MinArgs)
934     {
935         AcpiOsPrintf ("%u parameters entered, [%s] requires %u parameters\n",
936             ParamCount, AcpiGbl_DbCommands[CommandIndex].Name,
937             AcpiGbl_DbCommands[CommandIndex].MinArgs);
938 
939         AcpiDbDisplayCommandInfo (
940             AcpiGbl_DbCommands[CommandIndex].Name, FALSE);
941         return (AE_CTRL_TRUE);
942     }
943 
944     /* Decode and dispatch the command */
945 
946     switch (CommandIndex)
947     {
948     case CMD_NULL:
949 
950         if (Op)
951         {
952             return (AE_OK);
953         }
954         break;
955 
956     case CMD_ALL:
957 
958         AcpiOsPrintf ("Executing all objects with NameSeg: %s\n", AcpiGbl_DbArgs[1]);
959         AcpiDbExecute (AcpiGbl_DbArgs[1],
960             &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_NO_SINGLE_STEP | EX_ALL);
961         break;
962 
963     case CMD_ALLOCATIONS:
964 
965 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
966         AcpiUtDumpAllocations ((UINT32) -1, NULL);
967 #endif
968         break;
969 
970     case CMD_ARGS:
971     case CMD_ARGUMENTS:
972 
973         AcpiDbDisplayArguments ();
974         break;
975 
976     case CMD_BREAKPOINT:
977 
978         AcpiDbSetMethodBreakpoint (AcpiGbl_DbArgs[1], WalkState, Op);
979         break;
980 
981     case CMD_BUSINFO:
982 
983         AcpiDbGetBusInfo ();
984         break;
985 
986     case CMD_CALL:
987 
988         AcpiDbSetMethodCallBreakpoint (Op);
989         Status = AE_OK;
990         break;
991 
992     case CMD_DEBUG:
993 
994         AcpiDbExecute (AcpiGbl_DbArgs[1],
995             &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_SINGLE_STEP);
996         break;
997 
998     case CMD_DISASSEMBLE:
999     case CMD_DISASM:
1000 
1001 #ifdef ACPI_DISASSEMBLER
1002         (void) AcpiDbDisassembleMethod (AcpiGbl_DbArgs[1]);
1003 #else
1004         AcpiOsPrintf ("The AML Disassembler is not configured/present\n");
1005 #endif
1006         break;
1007 
1008     case CMD_DUMP:
1009 
1010         AcpiDbDecodeAndDisplayObject (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1011         break;
1012 
1013     case CMD_EVALUATE:
1014     case CMD_EXECUTE:
1015 
1016         AcpiDbExecute (AcpiGbl_DbArgs[1],
1017             &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_NO_SINGLE_STEP);
1018         break;
1019 
1020     case CMD_FIND:
1021 
1022         Status = AcpiDbFindNameInNamespace (AcpiGbl_DbArgs[1]);
1023         break;
1024 
1025     case CMD_FIELDS:
1026 
1027         Status = AcpiUtStrtoul64 (AcpiGbl_DbArgs[1], &Temp64);
1028 
1029         if (ACPI_FAILURE (Status) || Temp64 >= ACPI_NUM_PREDEFINED_REGIONS)
1030         {
1031             AcpiOsPrintf (
1032                 "Invalid address space ID: must be between 0 and %u inclusive\n",
1033                 ACPI_NUM_PREDEFINED_REGIONS - 1);
1034             return (AE_OK);
1035         }
1036 
1037         Status = AcpiDbDisplayFields ((UINT32) Temp64);
1038         break;
1039 
1040     case CMD_GO:
1041 
1042         AcpiGbl_CmSingleStep = FALSE;
1043         return (AE_OK);
1044 
1045     case CMD_HANDLERS:
1046 
1047         AcpiDbDisplayHandlers ();
1048         break;
1049 
1050     case CMD_HELP:
1051     case CMD_HELP2:
1052 
1053         AcpiDbDisplayHelp (AcpiGbl_DbArgs[1]);
1054         break;
1055 
1056     case CMD_HISTORY:
1057 
1058         AcpiDbDisplayHistory ();
1059         break;
1060 
1061     case CMD_HISTORY_EXE: /* ! command */
1062 
1063         CommandLine = AcpiDbGetFromHistory (AcpiGbl_DbArgs[1]);
1064         if (!CommandLine)
1065         {
1066             return (AE_CTRL_TRUE);
1067         }
1068 
1069         Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
1070         return (Status);
1071 
1072     case CMD_HISTORY_LAST: /* !! command */
1073 
1074         CommandLine = AcpiDbGetFromHistory (NULL);
1075         if (!CommandLine)
1076         {
1077             return (AE_CTRL_TRUE);
1078         }
1079 
1080         Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
1081         return (Status);
1082 
1083     case CMD_INFORMATION:
1084 
1085         AcpiDbDisplayMethodInfo (Op);
1086         break;
1087 
1088     case CMD_INTEGRITY:
1089 
1090         AcpiDbCheckIntegrity ();
1091         break;
1092 
1093     case CMD_INTO:
1094 
1095         if (Op)
1096         {
1097             AcpiGbl_CmSingleStep = TRUE;
1098             return (AE_OK);
1099         }
1100         break;
1101 
1102     case CMD_LEVEL:
1103 
1104         if (ParamCount == 0)
1105         {
1106             AcpiOsPrintf (
1107                 "Current debug level for file output is:    %8.8X\n",
1108                 AcpiGbl_DbDebugLevel);
1109             AcpiOsPrintf (
1110                 "Current debug level for console output is: %8.8X\n",
1111                 AcpiGbl_DbConsoleDebugLevel);
1112         }
1113         else if (ParamCount == 2)
1114         {
1115             Temp = AcpiGbl_DbConsoleDebugLevel;
1116             AcpiGbl_DbConsoleDebugLevel =
1117                 strtoul (AcpiGbl_DbArgs[1], NULL, 16);
1118             AcpiOsPrintf (
1119                 "Debug Level for console output was %8.8X, now %8.8X\n",
1120                 Temp, AcpiGbl_DbConsoleDebugLevel);
1121         }
1122         else
1123         {
1124             Temp = AcpiGbl_DbDebugLevel;
1125             AcpiGbl_DbDebugLevel = strtoul (AcpiGbl_DbArgs[1], NULL, 16);
1126             AcpiOsPrintf (
1127                 "Debug Level for file output was %8.8X, now %8.8X\n",
1128                 Temp, AcpiGbl_DbDebugLevel);
1129         }
1130         break;
1131 
1132     case CMD_LIST:
1133 
1134 #ifdef ACPI_DISASSEMBLER
1135         AcpiDbDisassembleAml (AcpiGbl_DbArgs[1], Op);
1136 #else
1137         AcpiOsPrintf ("The AML Disassembler is not configured/present\n");
1138 #endif
1139         break;
1140 
1141     case CMD_LOCKS:
1142 
1143         AcpiDbDisplayLocks ();
1144         break;
1145 
1146     case CMD_LOCALS:
1147 
1148         AcpiDbDisplayLocals ();
1149         break;
1150 
1151     case CMD_METHODS:
1152 
1153         Status = AcpiDbDisplayObjects ("METHOD", AcpiGbl_DbArgs[1]);
1154         break;
1155 
1156     case CMD_NAMESPACE:
1157 
1158         AcpiDbDumpNamespace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1159         break;
1160 
1161     case CMD_NOTIFY:
1162 
1163         Temp = strtoul (AcpiGbl_DbArgs[2], NULL, 0);
1164         AcpiDbSendNotify (AcpiGbl_DbArgs[1], Temp);
1165         break;
1166 
1167     case CMD_OBJECTS:
1168 
1169         AcpiUtStrupr (AcpiGbl_DbArgs[1]);
1170         Status = AcpiDbDisplayObjects (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1171         break;
1172 
1173     case CMD_OSI:
1174 
1175         AcpiDbDisplayInterfaces (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1176         break;
1177 
1178     case CMD_OWNER:
1179 
1180         AcpiDbDumpNamespaceByOwner (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1181         break;
1182 
1183     case CMD_PATHS:
1184 
1185         AcpiDbDumpNamespacePaths ();
1186         break;
1187 
1188     case CMD_PREFIX:
1189 
1190         AcpiDbSetScope (AcpiGbl_DbArgs[1]);
1191         break;
1192 
1193     case CMD_REFERENCES:
1194 
1195         AcpiDbFindReferences (AcpiGbl_DbArgs[1]);
1196         break;
1197 
1198     case CMD_RESOURCES:
1199 
1200         AcpiDbDisplayResources (AcpiGbl_DbArgs[1]);
1201         break;
1202 
1203     case CMD_RESULTS:
1204 
1205         AcpiDbDisplayResults ();
1206         break;
1207 
1208     case CMD_SET:
1209 
1210         AcpiDbSetMethodData (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],
1211             AcpiGbl_DbArgs[3]);
1212         break;
1213 
1214     case CMD_STATS:
1215 
1216         Status = AcpiDbDisplayStatistics (AcpiGbl_DbArgs[1]);
1217         break;
1218 
1219     case CMD_STOP:
1220 
1221         return (AE_NOT_IMPLEMENTED);
1222 
1223     case CMD_TABLES:
1224 
1225         AcpiDbDisplayTableInfo (AcpiGbl_DbArgs[1]);
1226         break;
1227 
1228     case CMD_TEMPLATE:
1229 
1230         AcpiDbDisplayTemplate (AcpiGbl_DbArgs[1]);
1231         break;
1232 
1233     case CMD_TRACE:
1234 
1235         AcpiDbTrace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], AcpiGbl_DbArgs[3]);
1236         break;
1237 
1238     case CMD_TREE:
1239 
1240         AcpiDbDisplayCallingTree ();
1241         break;
1242 
1243     case CMD_TYPE:
1244 
1245         AcpiDbDisplayObjectType (AcpiGbl_DbArgs[1]);
1246         break;
1247 
1248 #ifdef ACPI_APPLICATION
1249 
1250     /* Hardware simulation commands. */
1251 
1252     case CMD_ENABLEACPI:
1253 #if (!ACPI_REDUCED_HARDWARE)
1254 
1255         Status = AcpiEnable();
1256         if (ACPI_FAILURE(Status))
1257         {
1258             AcpiOsPrintf("AcpiEnable failed (Status=%X)\n", Status);
1259             return (Status);
1260         }
1261 #endif /* !ACPI_REDUCED_HARDWARE */
1262         break;
1263 
1264     case CMD_EVENT:
1265 
1266         AcpiOsPrintf ("Event command not implemented\n");
1267         break;
1268 
1269 	case CMD_INTERRUPT:
1270 
1271 		AcpiDbGenerateInterrupt (AcpiGbl_DbArgs[1]);
1272 		break;
1273 
1274     case CMD_GPE:
1275 
1276         AcpiDbGenerateGpe (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1277         break;
1278 
1279     case CMD_GPES:
1280 
1281         AcpiDbDisplayGpes ();
1282         break;
1283 
1284     case CMD_SCI:
1285 
1286         AcpiDbGenerateSci ();
1287         break;
1288 
1289     case CMD_SLEEP:
1290 
1291         Status = AcpiDbSleep (AcpiGbl_DbArgs[1]);
1292         break;
1293 
1294     /* File I/O commands. */
1295 
1296     case CMD_CLOSE:
1297 
1298         AcpiDbCloseDebugFile ();
1299         break;
1300 
1301     case CMD_LOAD:
1302         {
1303             ACPI_NEW_TABLE_DESC     *ListHead = NULL;
1304 
1305             Status = AcGetAllTablesFromFile (AcpiGbl_DbArgs[1],
1306                 ACPI_GET_ALL_TABLES, &ListHead);
1307             if (ACPI_SUCCESS (Status))
1308             {
1309                 AcpiDbLoadTables (ListHead);
1310             }
1311         }
1312         break;
1313 
1314     case CMD_OPEN:
1315 
1316         AcpiDbOpenDebugFile (AcpiGbl_DbArgs[1]);
1317         break;
1318 
1319     /* User space commands. */
1320 
1321     case CMD_TERMINATE:
1322 
1323         AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
1324         AcpiUtSubsystemShutdown ();
1325 
1326         /*
1327          * TBD: [Restructure] Need some way to re-initialize without
1328          * re-creating the semaphores!
1329          */
1330 
1331         AcpiGbl_DbTerminateLoop = TRUE;
1332         /*  AcpiInitialize (NULL);  */
1333         break;
1334 
1335     case CMD_BACKGROUND:
1336 
1337         AcpiDbCreateExecutionThread (AcpiGbl_DbArgs[1], &AcpiGbl_DbArgs[2],
1338             &AcpiGbl_DbArgTypes[2]);
1339         break;
1340 
1341     case CMD_THREADS:
1342 
1343         AcpiDbCreateExecutionThreads (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],
1344             AcpiGbl_DbArgs[3]);
1345         break;
1346 
1347     /* Debug test commands. */
1348 
1349     case CMD_PREDEFINED:
1350 
1351         AcpiDbCheckPredefinedNames ();
1352         break;
1353 
1354     case CMD_TEST:
1355 
1356         AcpiDbExecuteTest (AcpiGbl_DbArgs[1]);
1357         break;
1358 
1359     case CMD_UNLOAD:
1360 
1361         AcpiDbUnloadAcpiTable (AcpiGbl_DbArgs[1]);
1362         break;
1363 #endif
1364 
1365     case CMD_EXIT:
1366     case CMD_QUIT:
1367 
1368         if (Op)
1369         {
1370             AcpiOsPrintf ("Method execution terminated\n");
1371             return (AE_CTRL_TERMINATE);
1372         }
1373 
1374         if (!AcpiGbl_DbOutputToFile)
1375         {
1376             AcpiDbgLevel = ACPI_DEBUG_DEFAULT;
1377         }
1378 
1379 #ifdef ACPI_APPLICATION
1380         AcpiDbCloseDebugFile ();
1381 #endif
1382         AcpiGbl_DbTerminateLoop = TRUE;
1383         return (AE_CTRL_TERMINATE);
1384 
1385     case CMD_NOT_FOUND:
1386     default:
1387 
1388         AcpiOsPrintf ("%s: unknown command\n", AcpiGbl_DbArgs[0]);
1389         return (AE_CTRL_TRUE);
1390     }
1391 
1392     if (ACPI_SUCCESS (Status))
1393     {
1394         Status = AE_CTRL_TRUE;
1395     }
1396 
1397     return (Status);
1398 }
1399 
1400 
1401 /*******************************************************************************
1402  *
1403  * FUNCTION:    AcpiDbExecuteThread
1404  *
1405  * PARAMETERS:  Context         - Not used
1406  *
1407  * RETURN:      None
1408  *
1409  * DESCRIPTION: Debugger execute thread. Waits for a command line, then
1410  *              simply dispatches it.
1411  *
1412  ******************************************************************************/
1413 
1414 void ACPI_SYSTEM_XFACE
AcpiDbExecuteThread(void * Context)1415 AcpiDbExecuteThread (
1416     void                    *Context)
1417 {
1418 
1419     (void) AcpiDbUserCommands ();
1420     AcpiGbl_DbThreadsTerminated = TRUE;
1421 }
1422 
1423 
1424 /*******************************************************************************
1425  *
1426  * FUNCTION:    AcpiDbUserCommands
1427  *
1428  * PARAMETERS:  None
1429  *
1430  * RETURN:      None
1431  *
1432  * DESCRIPTION: Command line execution for the AML debugger. Commands are
1433  *              matched and dispatched here.
1434  *
1435  ******************************************************************************/
1436 
1437 ACPI_STATUS
AcpiDbUserCommands(void)1438 AcpiDbUserCommands (
1439     void)
1440 {
1441     ACPI_STATUS             Status = AE_OK;
1442 
1443 
1444     AcpiOsPrintf ("\n");
1445 
1446     /* TBD: [Restructure] Need a separate command line buffer for step mode */
1447 
1448     while (!AcpiGbl_DbTerminateLoop)
1449     {
1450         /* Wait the readiness of the command */
1451 
1452         Status = AcpiOsWaitCommandReady ();
1453         if (ACPI_FAILURE (Status))
1454         {
1455             break;
1456         }
1457 
1458         /* Just call to the command line interpreter */
1459 
1460         AcpiGbl_MethodExecuting = FALSE;
1461         AcpiGbl_StepToNextCall = FALSE;
1462 
1463         (void) AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
1464 
1465         /* Notify the completion of the command */
1466 
1467         Status = AcpiOsNotifyCommandComplete ();
1468         if (ACPI_FAILURE (Status))
1469         {
1470             break;
1471         }
1472     }
1473 
1474     if (ACPI_FAILURE (Status) && Status != AE_CTRL_TERMINATE)
1475     {
1476         ACPI_EXCEPTION ((AE_INFO, Status, "While parsing command line"));
1477     }
1478     return (Status);
1479 }
1480