167754Smsmith/*******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: dbinput - user front-end to the AML debugger
467754Smsmith *
567754Smsmith ******************************************************************************/
667754Smsmith
7316303Sjkim/******************************************************************************
8316303Sjkim *
9316303Sjkim * 1. Copyright Notice
10316303Sjkim *
11316303Sjkim * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
1270243Smsmith * All rights reserved.
1367754Smsmith *
14316303Sjkim * 2. License
15316303Sjkim *
16316303Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property
17316303Sjkim * rights. You may have additional license terms from the party that provided
18316303Sjkim * you this software, covering your right to use that party's intellectual
19316303Sjkim * property rights.
20316303Sjkim *
21316303Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22316303Sjkim * copy of the source code appearing in this file ("Covered Code") an
23316303Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24316303Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy,
25316303Sjkim * make derivatives, distribute, use and display any portion of the Covered
26316303Sjkim * Code in any form, with the right to sublicense such rights; and
27316303Sjkim *
28316303Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29316303Sjkim * license (with the right to sublicense), under only those claims of Intel
30316303Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell,
31316303Sjkim * offer to sell, and import the Covered Code and derivative works thereof
32316303Sjkim * solely to the minimum extent necessary to exercise the above copyright
33316303Sjkim * license, and in no event shall the patent license extend to any additions
34316303Sjkim * to or modifications of the Original Intel Code. No other license or right
35316303Sjkim * is granted directly or by implication, estoppel or otherwise;
36316303Sjkim *
37316303Sjkim * The above copyright and patent license is granted only if the following
38316303Sjkim * conditions are met:
39316303Sjkim *
40316303Sjkim * 3. Conditions
41316303Sjkim *
42316303Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43316303Sjkim * Redistribution of source code of any substantial portion of the Covered
44316303Sjkim * Code or modification with rights to further distribute source must include
45316303Sjkim * the above Copyright Notice, the above License, this list of Conditions,
46316303Sjkim * and the following Disclaimer and Export Compliance provision. In addition,
47316303Sjkim * Licensee must cause all Covered Code to which Licensee contributes to
48316303Sjkim * contain a file documenting the changes Licensee made to create that Covered
49316303Sjkim * Code and the date of any change. Licensee must include in that file the
50316303Sjkim * documentation of any changes made by any predecessor Licensee. Licensee
51316303Sjkim * must include a prominent statement that the modification is derived,
52316303Sjkim * directly or indirectly, from Original Intel Code.
53316303Sjkim *
54316303Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55316303Sjkim * Redistribution of source code of any substantial portion of the Covered
56316303Sjkim * Code or modification without rights to further distribute source must
57316303Sjkim * include the following Disclaimer and Export Compliance provision in the
58316303Sjkim * documentation and/or other materials provided with distribution. In
59316303Sjkim * addition, Licensee may not authorize further sublicense of source of any
60316303Sjkim * portion of the Covered Code, and must include terms to the effect that the
61316303Sjkim * license from Licensee to its licensee is limited to the intellectual
62316303Sjkim * property embodied in the software Licensee provides to its licensee, and
63316303Sjkim * not to intellectual property embodied in modifications its licensee may
64316303Sjkim * make.
65316303Sjkim *
66316303Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any
67316303Sjkim * substantial portion of the Covered Code or modification must reproduce the
68316303Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance
69316303Sjkim * provision in the documentation and/or other materials provided with the
70316303Sjkim * distribution.
71316303Sjkim *
72316303Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original
73316303Sjkim * Intel Code.
74316303Sjkim *
75316303Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76316303Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or
77316303Sjkim * other dealings in products derived from or relating to the Covered Code
78316303Sjkim * without prior written authorization from Intel.
79316303Sjkim *
80316303Sjkim * 4. Disclaimer and Export Compliance
81316303Sjkim *
82316303Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83316303Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84316303Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85316303Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86316303Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87316303Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88316303Sjkim * PARTICULAR PURPOSE.
89316303Sjkim *
90316303Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91316303Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92316303Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93316303Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94316303Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95316303Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96316303Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97316303Sjkim * LIMITED REMEDY.
98316303Sjkim *
99316303Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this
100316303Sjkim * software or system incorporating such software without first obtaining any
101316303Sjkim * required license or other approval from the U. S. Department of Commerce or
102316303Sjkim * any other agency or department of the United States Government. In the
103316303Sjkim * event Licensee exports any such software from the United States or
104316303Sjkim * re-exports any such software from a foreign destination, Licensee shall
105316303Sjkim * ensure that the distribution and export/re-export of the software is in
106316303Sjkim * compliance with all laws, regulations, orders, or other restrictions of the
107316303Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108316303Sjkim * any of its subsidiaries will export/re-export any technical data, process,
109316303Sjkim * software, or service, directly or indirectly, to any country for which the
110316303Sjkim * United States government or any agency thereof requires an export license,
111316303Sjkim * other governmental approval, or letter of assurance, without first obtaining
112316303Sjkim * such license, approval or letter.
113316303Sjkim *
114316303Sjkim *****************************************************************************
115316303Sjkim *
116316303Sjkim * Alternatively, you may choose to be licensed under the terms of the
117316303Sjkim * following license:
118316303Sjkim *
119217365Sjkim * Redistribution and use in source and binary forms, with or without
120217365Sjkim * modification, are permitted provided that the following conditions
121217365Sjkim * are met:
122217365Sjkim * 1. Redistributions of source code must retain the above copyright
123217365Sjkim *    notice, this list of conditions, and the following disclaimer,
124217365Sjkim *    without modification.
125217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126217365Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
127217365Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
128217365Sjkim *    including a substantially similar Disclaimer requirement for further
129217365Sjkim *    binary redistribution.
130217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
131217365Sjkim *    of any contributors may be used to endorse or promote products derived
132217365Sjkim *    from this software without specific prior written permission.
13367754Smsmith *
134316303Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135316303Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136316303Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137316303Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138316303Sjkim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139316303Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140316303Sjkim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141316303Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142316303Sjkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143316303Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144316303Sjkim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145316303Sjkim *
146316303Sjkim * Alternatively, you may choose to be licensed under the terms of the
147217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
148217365Sjkim * Software Foundation.
14967754Smsmith *
150316303Sjkim *****************************************************************************/
15167754Smsmith
152193341Sjkim#include <contrib/dev/acpica/include/acpi.h>
153193341Sjkim#include <contrib/dev/acpica/include/accommon.h>
154193341Sjkim#include <contrib/dev/acpica/include/acdebug.h>
15567754Smsmith
156298714Sjkim#ifdef ACPI_APPLICATION
157298714Sjkim#include <contrib/dev/acpica/include/acapps.h>
158298714Sjkim#endif
15967754Smsmith
160102550Siwasaki#define _COMPONENT          ACPI_CA_DEBUGGER
16191116Smsmith        ACPI_MODULE_NAME    ("dbinput")
16267754Smsmith
163287168Sjkim
164151937Sjkim/* Local prototypes */
16567754Smsmith
166151937Sjkimstatic UINT32
167151937SjkimAcpiDbGetLine (
168151937Sjkim    char                    *InputBuffer);
169151937Sjkim
170151937Sjkimstatic UINT32
171151937SjkimAcpiDbMatchCommand (
172151937Sjkim    char                    *UserCommand);
173151937Sjkim
174151937Sjkimstatic void
175240716SjkimAcpiDbDisplayCommandInfo (
176298714Sjkim    const char              *Command,
177240716Sjkim    BOOLEAN                 DisplayAll);
178240716Sjkim
179240716Sjkimstatic void
180151937SjkimAcpiDbDisplayHelp (
181240716Sjkim    char                    *Command);
182151937Sjkim
183240716Sjkimstatic BOOLEAN
184240716SjkimAcpiDbMatchCommandHelp (
185298714Sjkim    const char                  *Command,
186240716Sjkim    const ACPI_DB_COMMAND_HELP  *Help);
187151937Sjkim
188240716Sjkim
18967754Smsmith/*
19067754Smsmith * Top-level debugger commands.
19167754Smsmith *
19267754Smsmith * This list of commands must match the string table below it
19367754Smsmith */
19477424Smsmithenum AcpiExDebuggerCommands
19567754Smsmith{
19667754Smsmith    CMD_NOT_FOUND = 0,
19767754Smsmith    CMD_NULL,
19867754Smsmith    CMD_ALLOCATIONS,
19967754Smsmith    CMD_ARGS,
20067754Smsmith    CMD_ARGUMENTS,
20167754Smsmith    CMD_BREAKPOINT,
202151937Sjkim    CMD_BUSINFO,
20367754Smsmith    CMD_CALL,
20467754Smsmith    CMD_DEBUG,
205138287Smarks    CMD_DISASSEMBLE,
206243347Sjkim    CMD_DISASM,
20767754Smsmith    CMD_DUMP,
208240716Sjkim    CMD_EVALUATE,
20967754Smsmith    CMD_EXECUTE,
21067754Smsmith    CMD_EXIT,
21167754Smsmith    CMD_FIND,
21267754Smsmith    CMD_GO,
213218590Sjkim    CMD_HANDLERS,
21467754Smsmith    CMD_HELP,
21567754Smsmith    CMD_HELP2,
21667754Smsmith    CMD_HISTORY,
21767754Smsmith    CMD_HISTORY_EXE,
21867754Smsmith    CMD_HISTORY_LAST,
21967754Smsmith    CMD_INFORMATION,
22099679Siwasaki    CMD_INTEGRITY,
22167754Smsmith    CMD_INTO,
22267754Smsmith    CMD_LEVEL,
22367754Smsmith    CMD_LIST,
22467754Smsmith    CMD_LOCALS,
22577424Smsmith    CMD_LOCKS,
22667754Smsmith    CMD_METHODS,
22767754Smsmith    CMD_NAMESPACE,
22867754Smsmith    CMD_NOTIFY,
229272444Sjkim    CMD_OBJECTS,
230210976Sjkim    CMD_OSI,
23167754Smsmith    CMD_OWNER,
232254745Sjkim    CMD_PATHS,
233298714Sjkim    CMD_PREDEFINED,
23467754Smsmith    CMD_PREFIX,
23567754Smsmith    CMD_QUIT,
23667754Smsmith    CMD_REFERENCES,
23773561Smsmith    CMD_RESOURCES,
23867754Smsmith    CMD_RESULTS,
23967754Smsmith    CMD_SET,
24067754Smsmith    CMD_STATS,
24167754Smsmith    CMD_STOP,
24267754Smsmith    CMD_TABLES,
243228110Sjkim    CMD_TEMPLATE,
244151937Sjkim    CMD_TRACE,
24567754Smsmith    CMD_TREE,
246117521Snjl    CMD_TYPE,
247287168Sjkim#ifdef ACPI_APPLICATION
248287168Sjkim    CMD_ENABLEACPI,
249287168Sjkim    CMD_EVENT,
250287168Sjkim    CMD_GPE,
251287168Sjkim    CMD_GPES,
252287168Sjkim    CMD_SCI,
253287168Sjkim    CMD_SLEEP,
254287168Sjkim
255287168Sjkim    CMD_CLOSE,
256287168Sjkim    CMD_LOAD,
257287168Sjkim    CMD_OPEN,
258287168Sjkim    CMD_UNLOAD,
259287168Sjkim
260287168Sjkim    CMD_TERMINATE,
261327557Sjkim    CMD_BACKGROUND,
262287168Sjkim    CMD_THREADS,
263287168Sjkim
264287168Sjkim    CMD_TEST,
265287168Sjkim#endif
26667754Smsmith};
26767754Smsmith
26867754Smsmith#define CMD_FIRST_VALID     2
26967754Smsmith
270193267Sjkim
271193267Sjkim/* Second parameter is the required argument count */
272193267Sjkim
273240716Sjkimstatic const ACPI_DB_COMMAND_INFO   AcpiGbl_DbCommands[] =
27467754Smsmith{
27567754Smsmith    {"<NOT FOUND>",  0},
27667754Smsmith    {"<NULL>",       0},
27767754Smsmith    {"ALLOCATIONS",  0},
27867754Smsmith    {"ARGS",         0},
27967754Smsmith    {"ARGUMENTS",    0},
28067754Smsmith    {"BREAKPOINT",   1},
281151937Sjkim    {"BUSINFO",      0},
28267754Smsmith    {"CALL",         0},
28367754Smsmith    {"DEBUG",        1},
284138287Smarks    {"DISASSEMBLE",  1},
285243347Sjkim    {"DISASM",       1},
28667754Smsmith    {"DUMP",         1},
287240716Sjkim    {"EVALUATE",     1},
28867754Smsmith    {"EXECUTE",      1},
28967754Smsmith    {"EXIT",         0},
29067754Smsmith    {"FIND",         1},
29167754Smsmith    {"GO",           0},
292218590Sjkim    {"HANDLERS",     0},
29367754Smsmith    {"HELP",         0},
29467754Smsmith    {"?",            0},
29567754Smsmith    {"HISTORY",      0},
29667754Smsmith    {"!",            1},
29767754Smsmith    {"!!",           0},
29867754Smsmith    {"INFORMATION",  0},
29999679Siwasaki    {"INTEGRITY",    0},
30067754Smsmith    {"INTO",         0},
30167754Smsmith    {"LEVEL",        0},
30267754Smsmith    {"LIST",         0},
30367754Smsmith    {"LOCALS",       0},
30477424Smsmith    {"LOCKS",        0},
30567754Smsmith    {"METHODS",      0},
30667754Smsmith    {"NAMESPACE",    0},
30767754Smsmith    {"NOTIFY",       2},
308287168Sjkim    {"OBJECTS",      0},
309210976Sjkim    {"OSI",          0},
31067754Smsmith    {"OWNER",        1},
311254745Sjkim    {"PATHS",        0},
312298714Sjkim    {"PREDEFINED",   0},
31367754Smsmith    {"PREFIX",       0},
31467754Smsmith    {"QUIT",         0},
31567754Smsmith    {"REFERENCES",   1},
316246849Sjkim    {"RESOURCES",    0},
31767754Smsmith    {"RESULTS",      0},
31867754Smsmith    {"SET",          3},
319240716Sjkim    {"STATS",        1},
32067754Smsmith    {"STOP",         0},
32167754Smsmith    {"TABLES",       0},
322228110Sjkim    {"TEMPLATE",     1},
323151937Sjkim    {"TRACE",        1},
32467754Smsmith    {"TREE",         0},
325117521Snjl    {"TYPE",         1},
326287168Sjkim#ifdef ACPI_APPLICATION
327287168Sjkim    {"ENABLEACPI",   0},
328287168Sjkim    {"EVENT",        1},
329287168Sjkim    {"GPE",          1},
330287168Sjkim    {"GPES",         0},
331287168Sjkim    {"SCI",          0},
332287168Sjkim    {"SLEEP",        0},
333287168Sjkim
334287168Sjkim    {"CLOSE",        0},
335287168Sjkim    {"LOAD",         1},
336287168Sjkim    {"OPEN",         1},
33782367Smsmith    {"UNLOAD",       1},
338287168Sjkim
339287168Sjkim    {"TERMINATE",    0},
340327557Sjkim    {"BACKGROUND",   1},
341287168Sjkim    {"THREADS",      3},
342287168Sjkim
343287168Sjkim    {"TEST",         1},
344287168Sjkim#endif
34567754Smsmith    {NULL,           0}
34667754Smsmith};
34767754Smsmith
348240716Sjkim/*
349240716Sjkim * Help for all debugger commands. First argument is the number of lines
350240716Sjkim * of help to output for the command.
351327557Sjkim *
352327557Sjkim * Note: Some commands are not supported by the kernel-level version of
353327557Sjkim * the debugger.
354240716Sjkim */
355240716Sjkimstatic const ACPI_DB_COMMAND_HELP   AcpiGbl_DbCommandHelp[] =
356240716Sjkim{
357327557Sjkim    {0, "\nNamespace Access:",                  "\n"},
358327557Sjkim    {1, "  Businfo",                            "Display system bus info\n"},
359327557Sjkim    {1, "  Disassemble <Method>",               "Disassemble a control method\n"},
360327557Sjkim    {1, "  Find <AcpiName> (? is wildcard)",    "Find ACPI name(s) with wildcards\n"},
361327557Sjkim    {1, "  Integrity",                          "Validate namespace integrity\n"},
362327557Sjkim    {1, "  Methods",                            "Display list of loaded control methods\n"},
363327557Sjkim    {1, "  Namespace [Object] [Depth]",         "Display loaded namespace tree/subtree\n"},
364327557Sjkim    {1, "  Notify <Object> <Value>",            "Send a notification on Object\n"},
365327557Sjkim    {1, "  Objects [ObjectType]",               "Display summary of all objects or just given type\n"},
366327557Sjkim    {1, "  Owner <OwnerId> [Depth]",            "Display loaded namespace by object owner\n"},
367327557Sjkim    {1, "  Paths",                              "Display full pathnames of namespace objects\n"},
368327557Sjkim    {1, "  Predefined",                         "Check all predefined names\n"},
369327557Sjkim    {1, "  Prefix [<Namepath>]",                "Set or Get current execution prefix\n"},
370327557Sjkim    {1, "  References <Addr>",                  "Find all references to object at addr\n"},
371327557Sjkim    {1, "  Resources [DeviceName]",             "Display Device resources (no arg = all devices)\n"},
372327557Sjkim    {1, "  Set N <NamedObject> <Value>",        "Set value for named integer\n"},
373327557Sjkim    {1, "  Template <Object>",                  "Format/dump a Buffer/ResourceTemplate\n"},
374327557Sjkim    {1, "  Type <Object>",                      "Display object type\n"},
37567754Smsmith
376327557Sjkim    {0, "\nControl Method Execution:",          "\n"},
377327557Sjkim    {1, "  Evaluate <Namepath> [Arguments]",    "Evaluate object or control method\n"},
378327557Sjkim    {1, "  Execute <Namepath> [Arguments]",     "Synonym for Evaluate\n"},
379327557Sjkim#ifdef ACPI_APPLICATION
380327557Sjkim    {1, "  Background <Namepath> [Arguments]",  "Evaluate object/method in a separate thread\n"},
381327557Sjkim    {1, "  Thread <Threads><Loops><NamePath>",  "Spawn threads to execute method(s)\n"},
382327557Sjkim#endif
383327557Sjkim    {1, "  Debug <Namepath> [Arguments]",       "Single-Step a control method\n"},
384327557Sjkim    {7, "  [Arguments] formats:",               "Control method argument formats\n"},
385327557Sjkim    {1, "     Hex Integer",                     "Integer\n"},
386327557Sjkim    {1, "     \"Ascii String\"",                "String\n"},
387327557Sjkim    {1, "     (Hex Byte List)",                 "Buffer\n"},
388327557Sjkim    {1, "         (01 42 7A BF)",               "Buffer example (4 bytes)\n"},
389327557Sjkim    {1, "     [Package Element List]",          "Package\n"},
390327557Sjkim    {1, "         [0x01 0x1234 \"string\"]",    "Package example (3 elements)\n"},
391240716Sjkim
392327557Sjkim    {0, "\nMiscellaneous:",                     "\n"},
393327557Sjkim    {1, "  Allocations",                        "Display list of current memory allocations\n"},
394327557Sjkim    {2, "  Dump <Address>|<Namepath>",          "\n"},
395327557Sjkim    {0, "       [Byte|Word|Dword|Qword]",       "Display ACPI objects or memory\n"},
396327557Sjkim    {1, "  Handlers",                           "Info about global handlers\n"},
397327557Sjkim    {1, "  Help [Command]",                     "This help screen or individual command\n"},
398327557Sjkim    {1, "  History",                            "Display command history buffer\n"},
399327557Sjkim    {1, "  Level <DebugLevel>] [console]",      "Get/Set debug level for file or console\n"},
400327557Sjkim    {1, "  Locks",                              "Current status of internal mutexes\n"},
401327557Sjkim    {1, "  Osi [Install|Remove <name>]",        "Display or modify global _OSI list\n"},
402327557Sjkim    {1, "  Quit or Exit",                       "Exit this command\n"},
403327557Sjkim    {8, "  Stats <SubCommand>",                 "Display namespace and memory statistics\n"},
404327557Sjkim    {1, "     Allocations",                     "Display list of current memory allocations\n"},
405327557Sjkim    {1, "     Memory",                          "Dump internal memory lists\n"},
406327557Sjkim    {1, "     Misc",                            "Namespace search and mutex stats\n"},
407327557Sjkim    {1, "     Objects",                         "Summary of namespace objects\n"},
408327557Sjkim    {1, "     Sizes",                           "Sizes for each of the internal objects\n"},
409327557Sjkim    {1, "     Stack",                           "Display CPU stack usage\n"},
410327557Sjkim    {1, "     Tables",                          "Info about current ACPI table(s)\n"},
411327557Sjkim    {1, "  Tables",                             "Display info about loaded ACPI tables\n"},
412287168Sjkim#ifdef ACPI_APPLICATION
413327557Sjkim    {1, "  Terminate",                          "Delete namespace and all internal objects\n"},
414327557Sjkim#endif
415327557Sjkim    {1, "  ! <CommandNumber>",                  "Execute command from history buffer\n"},
416327557Sjkim    {1, "  !!",                                 "Execute last command again\n"},
417254745Sjkim
418327557Sjkim    {0, "\nMethod and Namespace Debugging:",    "\n"},
419327557Sjkim    {5, "  Trace <State> [<Namepath>] [Once]",  "Trace control method execution\n"},
420327557Sjkim    {1, "     Enable",                          "Enable all messages\n"},
421327557Sjkim    {1, "     Disable",                         "Disable tracing\n"},
422327557Sjkim    {1, "     Method",                          "Enable method execution messages\n"},
423327557Sjkim    {1, "     Opcode",                          "Enable opcode execution messages\n"},
424327557Sjkim    {3, "  Test <TestName>",                    "Invoke a debug test\n"},
425327557Sjkim    {1, "     Objects",                         "Read/write/compare all namespace data objects\n"},
426327557Sjkim    {1, "     Predefined",                      "Validate all ACPI predefined names (_STA, etc.)\n"},
427327557Sjkim    {1, "  Execute predefined",                 "Execute all predefined (public) methods\n"},
428272444Sjkim
429327557Sjkim    {0, "\nControl Method Single-Step Execution:","\n"},
430327557Sjkim    {1, "  Arguments (or Args)",                "Display method arguments\n"},
431327557Sjkim    {1, "  Breakpoint <AmlOffset>",             "Set an AML execution breakpoint\n"},
432327557Sjkim    {1, "  Call",                               "Run to next control method invocation\n"},
433327557Sjkim    {1, "  Go",                                 "Allow method to run to completion\n"},
434327557Sjkim    {1, "  Information",                        "Display info about the current method\n"},
435327557Sjkim    {1, "  Into",                               "Step into (not over) a method call\n"},
436327557Sjkim    {1, "  List [# of Aml Opcodes]",            "Display method ASL statements\n"},
437327557Sjkim    {1, "  Locals",                             "Display method local variables\n"},
438327557Sjkim    {1, "  Results",                            "Display method result stack\n"},
439327557Sjkim    {1, "  Set <A|L> <#> <Value>",              "Set method data (Arguments/Locals)\n"},
440327557Sjkim    {1, "  Stop",                               "Terminate control method\n"},
441327557Sjkim    {1, "  Tree",                               "Display control method calling tree\n"},
442327557Sjkim    {1, "  <Enter>",                            "Single step next AML opcode (over calls)\n"},
443287168Sjkim
444327557Sjkim#ifdef ACPI_APPLICATION
445327557Sjkim    {0, "\nFile Operations:",                   "\n"},
446327557Sjkim    {1, "  Close",                              "Close debug output file\n"},
447327557Sjkim    {1, "  Load <Input Filename>",              "Load ACPI table from a file\n"},
448327557Sjkim    {1, "  Open <Output Filename>",             "Open a file for debug output\n"},
449327557Sjkim    {1, "  Unload <Namepath>",                  "Unload an ACPI table via namespace object\n"},
450327557Sjkim
451327557Sjkim    {0, "\nHardware Simulation:",               "\n"},
452327557Sjkim    {1, "  EnableAcpi",                         "Enable ACPI (hardware) mode\n"},
453327557Sjkim    {1, "  Event <F|G> <Value>",                "Generate AcpiEvent (Fixed/GPE)\n"},
454327557Sjkim    {1, "  Gpe <GpeNum> [GpeBlockDevice]",      "Simulate a GPE\n"},
455327557Sjkim    {1, "  Gpes",                               "Display info on all GPE devices\n"},
456327557Sjkim    {1, "  Sci",                                "Generate an SCI\n"},
457327557Sjkim    {1, "  Sleep [SleepState]",                 "Simulate sleep/wake sequence(s) (0-5)\n"},
458287168Sjkim#endif
459240716Sjkim    {0, NULL, NULL}
460240716Sjkim};
461240716Sjkim
462240716Sjkim
46367754Smsmith/*******************************************************************************
46467754Smsmith *
465240716Sjkim * FUNCTION:    AcpiDbMatchCommandHelp
466240716Sjkim *
467240716Sjkim * PARAMETERS:  Command             - Command string to match
468240716Sjkim *              Help                - Help table entry to attempt match
469240716Sjkim *
470240716Sjkim * RETURN:      TRUE if command matched, FALSE otherwise
471240716Sjkim *
472240716Sjkim * DESCRIPTION: Attempt to match a command in the help table in order to
473240716Sjkim *              print help information for a single command.
474240716Sjkim *
475240716Sjkim ******************************************************************************/
476240716Sjkim
477240716Sjkimstatic BOOLEAN
478240716SjkimAcpiDbMatchCommandHelp (
479298714Sjkim    const char                  *Command,
480240716Sjkim    const ACPI_DB_COMMAND_HELP  *Help)
481240716Sjkim{
482240716Sjkim    char                    *Invocation = Help->Invocation;
483240716Sjkim    UINT32                  LineCount;
484240716Sjkim
485240716Sjkim
486240716Sjkim    /* Valid commands in the help table begin with a couple of spaces */
487240716Sjkim
488240716Sjkim    if (*Invocation != ' ')
489240716Sjkim    {
490240716Sjkim        return (FALSE);
491240716Sjkim    }
492240716Sjkim
493240716Sjkim    while (*Invocation == ' ')
494240716Sjkim    {
495240716Sjkim        Invocation++;
496240716Sjkim    }
497240716Sjkim
498240716Sjkim    /* Match command name (full command or substring) */
499240716Sjkim
500240716Sjkim    while ((*Command) && (*Invocation) && (*Invocation != ' '))
501240716Sjkim    {
502284583Sjkim        if (tolower ((int) *Command) != tolower ((int) *Invocation))
503240716Sjkim        {
504240716Sjkim            return (FALSE);
505240716Sjkim        }
506240716Sjkim
507240716Sjkim        Invocation++;
508240716Sjkim        Command++;
509240716Sjkim    }
510240716Sjkim
511240716Sjkim    /* Print the appropriate number of help lines */
512240716Sjkim
513240716Sjkim    LineCount = Help->LineCount;
514240716Sjkim    while (LineCount)
515240716Sjkim    {
516240716Sjkim        AcpiOsPrintf ("%-38s : %s", Help->Invocation, Help->Description);
517240716Sjkim        Help++;
518240716Sjkim        LineCount--;
519240716Sjkim    }
520240716Sjkim
521240716Sjkim    return (TRUE);
522240716Sjkim}
523240716Sjkim
524240716Sjkim
525240716Sjkim/*******************************************************************************
526240716Sjkim *
527240716Sjkim * FUNCTION:    AcpiDbDisplayCommandInfo
528240716Sjkim *
529240716Sjkim * PARAMETERS:  Command             - Command string to match
530240716Sjkim *              DisplayAll          - Display all matching commands, or just
531240716Sjkim *                                    the first one (substring match)
532240716Sjkim *
533240716Sjkim * RETURN:      None
534240716Sjkim *
535240716Sjkim * DESCRIPTION: Display help information for a Debugger command.
536240716Sjkim *
537240716Sjkim ******************************************************************************/
538240716Sjkim
539240716Sjkimstatic void
540240716SjkimAcpiDbDisplayCommandInfo (
541298714Sjkim    const char              *Command,
542240716Sjkim    BOOLEAN                 DisplayAll)
543240716Sjkim{
544240716Sjkim    const ACPI_DB_COMMAND_HELP  *Next;
545240716Sjkim    BOOLEAN                     Matched;
546240716Sjkim
547240716Sjkim
548240716Sjkim    Next = AcpiGbl_DbCommandHelp;
549240716Sjkim    while (Next->Invocation)
550240716Sjkim    {
551240716Sjkim        Matched = AcpiDbMatchCommandHelp (Command, Next);
552240716Sjkim        if (!DisplayAll && Matched)
553240716Sjkim        {
554240716Sjkim            return;
555240716Sjkim        }
556240716Sjkim
557240716Sjkim        Next++;
558240716Sjkim    }
559240716Sjkim}
560240716Sjkim
561240716Sjkim
562240716Sjkim/*******************************************************************************
563240716Sjkim *
56467754Smsmith * FUNCTION:    AcpiDbDisplayHelp
56567754Smsmith *
566240716Sjkim * PARAMETERS:  Command             - Optional command string to display help.
567240716Sjkim *                                    if not specified, all debugger command
568240716Sjkim *                                    help strings are displayed
56967754Smsmith *
57067754Smsmith * RETURN:      None
57167754Smsmith *
572240716Sjkim * DESCRIPTION: Display help for a single debugger command, or all of them.
57367754Smsmith *
57467754Smsmith ******************************************************************************/
57567754Smsmith
576151937Sjkimstatic void
57767754SmsmithAcpiDbDisplayHelp (
578240716Sjkim    char                    *Command)
57967754Smsmith{
580240716Sjkim    const ACPI_DB_COMMAND_HELP  *Next = AcpiGbl_DbCommandHelp;
58167754Smsmith
58267754Smsmith
583240716Sjkim    if (!Command)
584240716Sjkim    {
585240716Sjkim        /* No argument to help, display help for all commands */
58667754Smsmith
587327557Sjkim        AcpiOsPrintf ("\nSummary of AML Debugger Commands\n\n");
588327557Sjkim
589240716Sjkim        while (Next->Invocation)
590240716Sjkim        {
591240716Sjkim            AcpiOsPrintf ("%-38s%s", Next->Invocation, Next->Description);
592240716Sjkim            Next++;
593240716Sjkim        }
594327557Sjkim        AcpiOsPrintf ("\n");
595327557Sjkim
596240716Sjkim    }
597240716Sjkim    else
598240716Sjkim    {
599240716Sjkim        /* Display help for all commands that match the subtring */
60067754Smsmith
601240716Sjkim        AcpiDbDisplayCommandInfo (Command, TRUE);
602240716Sjkim    }
60367754Smsmith}
60467754Smsmith
60567754Smsmith
60667754Smsmith/*******************************************************************************
60767754Smsmith *
60867754Smsmith * FUNCTION:    AcpiDbGetNextToken
60967754Smsmith *
61067754Smsmith * PARAMETERS:  String          - Command buffer
61167754Smsmith *              Next            - Return value, end of next token
61267754Smsmith *
61367754Smsmith * RETURN:      Pointer to the start of the next token.
61467754Smsmith *
615241973Sjkim * DESCRIPTION: Command line parsing. Get the next token on the command line
61667754Smsmith *
61767754Smsmith ******************************************************************************/
61867754Smsmith
619222544Sjkimchar *
62067754SmsmithAcpiDbGetNextToken (
621114237Snjl    char                    *String,
622222544Sjkim    char                    **Next,
623222544Sjkim    ACPI_OBJECT_TYPE        *ReturnType)
62467754Smsmith{
625114237Snjl    char                    *Start;
626222544Sjkim    UINT32                  Depth;
627222544Sjkim    ACPI_OBJECT_TYPE        Type = ACPI_TYPE_INTEGER;
62867754Smsmith
62991116Smsmith
63067754Smsmith    /* At end of buffer? */
63167754Smsmith
63267754Smsmith    if (!String || !(*String))
63367754Smsmith    {
63467754Smsmith        return (NULL);
63567754Smsmith    }
63667754Smsmith
637222544Sjkim    /* Remove any spaces at the beginning */
63867754Smsmith
63967754Smsmith    if (*String == ' ')
64067754Smsmith    {
64167754Smsmith        while (*String && (*String == ' '))
64267754Smsmith        {
64367754Smsmith            String++;
64467754Smsmith        }
64567754Smsmith
64667754Smsmith        if (!(*String))
64767754Smsmith        {
64867754Smsmith            return (NULL);
64967754Smsmith        }
65067754Smsmith    }
65167754Smsmith
652222544Sjkim    switch (*String)
653210976Sjkim    {
654222544Sjkim    case '"':
655222544Sjkim
656210976Sjkim        /* This is a quoted string, scan until closing quote */
65767754Smsmith
658210976Sjkim        String++;
659210976Sjkim        Start = String;
660222544Sjkim        Type = ACPI_TYPE_STRING;
66167754Smsmith
662222544Sjkim        /* Find end of string */
663210976Sjkim
664210976Sjkim        while (*String && (*String != '"'))
665210976Sjkim        {
666210976Sjkim            String++;
667210976Sjkim        }
668222544Sjkim        break;
669222544Sjkim
670222544Sjkim    case '(':
671222544Sjkim
672222544Sjkim        /* This is the start of a buffer, scan until closing paren */
673222544Sjkim
674222544Sjkim        String++;
675210976Sjkim        Start = String;
676222544Sjkim        Type = ACPI_TYPE_BUFFER;
677210976Sjkim
678222544Sjkim        /* Find end of buffer */
679222544Sjkim
680222544Sjkim        while (*String && (*String != ')'))
681222544Sjkim        {
682222544Sjkim            String++;
683222544Sjkim        }
684222544Sjkim        break;
685222544Sjkim
686222544Sjkim    case '[':
687222544Sjkim
688222544Sjkim        /* This is the start of a package, scan until closing bracket */
689222544Sjkim
690222544Sjkim        String++;
691222544Sjkim        Depth = 1;
692222544Sjkim        Start = String;
693222544Sjkim        Type = ACPI_TYPE_PACKAGE;
694222544Sjkim
695222544Sjkim        /* Find end of package (closing bracket) */
696222544Sjkim
697222544Sjkim        while (*String)
698222544Sjkim        {
699222544Sjkim            /* Handle String package elements */
700222544Sjkim
701222544Sjkim            if (*String == '"')
702222544Sjkim            {
703222544Sjkim                /* Find end of string */
704222544Sjkim
705222544Sjkim                String++;
706222544Sjkim                while (*String && (*String != '"'))
707222544Sjkim                {
708222544Sjkim                    String++;
709222544Sjkim                }
710222544Sjkim                if (!(*String))
711222544Sjkim                {
712222544Sjkim                    break;
713222544Sjkim                }
714222544Sjkim            }
715222544Sjkim            else if (*String == '[')
716222544Sjkim            {
717222544Sjkim                Depth++;         /* A nested package declaration */
718222544Sjkim            }
719222544Sjkim            else if (*String == ']')
720222544Sjkim            {
721222544Sjkim                Depth--;
722222544Sjkim                if (Depth == 0) /* Found final package closing bracket */
723222544Sjkim                {
724222544Sjkim                    break;
725222544Sjkim                }
726222544Sjkim            }
727222544Sjkim
728222544Sjkim            String++;
729222544Sjkim        }
730222544Sjkim        break;
731222544Sjkim
732222544Sjkim    default:
733222544Sjkim
734222544Sjkim        Start = String;
735222544Sjkim
736210976Sjkim        /* Find end of token */
737210976Sjkim
738210976Sjkim        while (*String && (*String != ' '))
739210976Sjkim        {
740210976Sjkim            String++;
741210976Sjkim        }
742222544Sjkim        break;
74367754Smsmith    }
74467754Smsmith
74567754Smsmith    if (!(*String))
74667754Smsmith    {
74767754Smsmith        *Next = NULL;
74867754Smsmith    }
74967754Smsmith    else
75067754Smsmith    {
75167754Smsmith        *String = 0;
75267754Smsmith        *Next = String + 1;
75367754Smsmith    }
75467754Smsmith
755222544Sjkim    *ReturnType = Type;
75667754Smsmith    return (Start);
75767754Smsmith}
75867754Smsmith
75967754Smsmith
76067754Smsmith/*******************************************************************************
76167754Smsmith *
76267754Smsmith * FUNCTION:    AcpiDbGetLine
76367754Smsmith *
76467754Smsmith * PARAMETERS:  InputBuffer         - Command line buffer
76567754Smsmith *
766151937Sjkim * RETURN:      Count of arguments to the command
76767754Smsmith *
768241973Sjkim * DESCRIPTION: Get the next command line from the user. Gets entire line
76967754Smsmith *              up to the next newline
77067754Smsmith *
77167754Smsmith ******************************************************************************/
77267754Smsmith
773151937Sjkimstatic UINT32
77467754SmsmithAcpiDbGetLine (
775114237Snjl    char                    *InputBuffer)
77667754Smsmith{
77767754Smsmith    UINT32                  i;
77867754Smsmith    UINT32                  Count;
779114237Snjl    char                    *Next;
780114237Snjl    char                    *This;
78167754Smsmith
78267754Smsmith
783272444Sjkim    if (AcpiUtSafeStrcpy (AcpiGbl_DbParsedBuf, sizeof (AcpiGbl_DbParsedBuf),
784272444Sjkim        InputBuffer))
785272444Sjkim    {
786287168Sjkim        AcpiOsPrintf (
787287168Sjkim            "Buffer overflow while parsing input line (max %u characters)\n",
788272444Sjkim            sizeof (AcpiGbl_DbParsedBuf));
789272444Sjkim        return (0);
790272444Sjkim    }
79167754Smsmith
79283174Smsmith    This = AcpiGbl_DbParsedBuf;
79391116Smsmith    for (i = 0; i < ACPI_DEBUGGER_MAX_ARGS; i++)
79467754Smsmith    {
795222544Sjkim        AcpiGbl_DbArgs[i] = AcpiDbGetNextToken (This, &Next,
796222544Sjkim            &AcpiGbl_DbArgTypes[i]);
79783174Smsmith        if (!AcpiGbl_DbArgs[i])
79867754Smsmith        {
79967754Smsmith            break;
80067754Smsmith        }
80167754Smsmith
80267754Smsmith        This = Next;
80367754Smsmith    }
80467754Smsmith
80567754Smsmith    /* Uppercase the actual command */
80667754Smsmith
807298714Sjkim    AcpiUtStrupr (AcpiGbl_DbArgs[0]);
80867754Smsmith
80967754Smsmith    Count = i;
81067754Smsmith    if (Count)
81167754Smsmith    {
81267754Smsmith        Count--;  /* Number of args only */
81367754Smsmith    }
81467754Smsmith
81567754Smsmith    return (Count);
81667754Smsmith}
81767754Smsmith
81867754Smsmith
81967754Smsmith/*******************************************************************************
82067754Smsmith *
82167754Smsmith * FUNCTION:    AcpiDbMatchCommand
82267754Smsmith *
82367754Smsmith * PARAMETERS:  UserCommand             - User command line
82467754Smsmith *
82567754Smsmith * RETURN:      Index into command array, -1 if not found
82667754Smsmith *
82767754Smsmith * DESCRIPTION: Search command array for a command match
82867754Smsmith *
82967754Smsmith ******************************************************************************/
83067754Smsmith
831151937Sjkimstatic UINT32
83267754SmsmithAcpiDbMatchCommand (
833114237Snjl    char                    *UserCommand)
83467754Smsmith{
83567754Smsmith    UINT32                  i;
83667754Smsmith
83767754Smsmith
83867754Smsmith    if (!UserCommand || UserCommand[0] == 0)
83967754Smsmith    {
84067754Smsmith        return (CMD_NULL);
84167754Smsmith    }
84267754Smsmith
84383174Smsmith    for (i = CMD_FIRST_VALID; AcpiGbl_DbCommands[i].Name; i++)
84467754Smsmith    {
845298714Sjkim        if (strstr (
846298714Sjkim            ACPI_CAST_PTR (char, AcpiGbl_DbCommands[i].Name), UserCommand) ==
847287168Sjkim            AcpiGbl_DbCommands[i].Name)
84867754Smsmith        {
84967754Smsmith            return (i);
85067754Smsmith        }
85167754Smsmith    }
85267754Smsmith
85367754Smsmith    /* Command not recognized */
85467754Smsmith
85567754Smsmith    return (CMD_NOT_FOUND);
85667754Smsmith}
85767754Smsmith
85867754Smsmith
85967754Smsmith/*******************************************************************************
86067754Smsmith *
86167754Smsmith * FUNCTION:    AcpiDbCommandDispatch
86267754Smsmith *
86367754Smsmith * PARAMETERS:  InputBuffer         - Command line buffer
86467754Smsmith *              WalkState           - Current walk
86567754Smsmith *              Op                  - Current (executing) parse op
86667754Smsmith *
86767754Smsmith * RETURN:      Status
86867754Smsmith *
869151937Sjkim * DESCRIPTION: Command dispatcher.
87067754Smsmith *
87167754Smsmith ******************************************************************************/
87267754Smsmith
87367754SmsmithACPI_STATUS
87467754SmsmithAcpiDbCommandDispatch (
875114237Snjl    char                    *InputBuffer,
87667754Smsmith    ACPI_WALK_STATE         *WalkState,
87767754Smsmith    ACPI_PARSE_OBJECT       *Op)
87867754Smsmith{
87967754Smsmith    UINT32                  Temp;
88067754Smsmith    UINT32                  CommandIndex;
88167754Smsmith    UINT32                  ParamCount;
882114237Snjl    char                    *CommandLine;
88367754Smsmith    ACPI_STATUS             Status = AE_CTRL_TRUE;
88467754Smsmith
88567754Smsmith
88667754Smsmith    /* If AcpiTerminate has been called, terminate this thread */
88767754Smsmith
888298714Sjkim    if (AcpiGbl_DbTerminateLoop)
88967754Smsmith    {
89067754Smsmith        return (AE_CTRL_TERMINATE);
89167754Smsmith    }
89267754Smsmith
893285797Sjkim    /* Find command and add to the history buffer */
894272444Sjkim
89567754Smsmith    ParamCount = AcpiDbGetLine (InputBuffer);
89683174Smsmith    CommandIndex = AcpiDbMatchCommand (AcpiGbl_DbArgs[0]);
89767754Smsmith    Temp = 0;
89867754Smsmith
899285797Sjkim    /*
900285797Sjkim     * We don't want to add the !! command to the history buffer. It
901285797Sjkim     * would cause an infinite loop because it would always be the
902285797Sjkim     * previous command.
903285797Sjkim     */
904285797Sjkim    if (CommandIndex != CMD_HISTORY_LAST)
905285797Sjkim    {
906285797Sjkim        AcpiDbAddToHistory (InputBuffer);
907285797Sjkim    }
908285797Sjkim
90967754Smsmith    /* Verify that we have the minimum number of params */
91067754Smsmith
91183174Smsmith    if (ParamCount < AcpiGbl_DbCommands[CommandIndex].MinArgs)
91267754Smsmith    {
913209746Sjkim        AcpiOsPrintf ("%u parameters entered, [%s] requires %u parameters\n",
914151937Sjkim            ParamCount, AcpiGbl_DbCommands[CommandIndex].Name,
915151937Sjkim            AcpiGbl_DbCommands[CommandIndex].MinArgs);
916151937Sjkim
917287168Sjkim        AcpiDbDisplayCommandInfo (
918287168Sjkim            AcpiGbl_DbCommands[CommandIndex].Name, FALSE);
91967754Smsmith        return (AE_CTRL_TRUE);
92067754Smsmith    }
92167754Smsmith
92267754Smsmith    /* Decode and dispatch the command */
92367754Smsmith
92467754Smsmith    switch (CommandIndex)
92567754Smsmith    {
92667754Smsmith    case CMD_NULL:
927250838Sjkim
92867754Smsmith        if (Op)
92967754Smsmith        {
93067754Smsmith            return (AE_OK);
93167754Smsmith        }
93267754Smsmith        break;
93367754Smsmith
93467754Smsmith    case CMD_ALLOCATIONS:
93583174Smsmith
93680062Smsmith#ifdef ACPI_DBG_TRACK_ALLOCATIONS
93784491Smsmith        AcpiUtDumpAllocations ((UINT32) -1, NULL);
93880062Smsmith#endif
93967754Smsmith        break;
94067754Smsmith
94167754Smsmith    case CMD_ARGS:
94267754Smsmith    case CMD_ARGUMENTS:
943250838Sjkim
94467754Smsmith        AcpiDbDisplayArguments ();
94567754Smsmith        break;
94667754Smsmith
94767754Smsmith    case CMD_BREAKPOINT:
948250838Sjkim
94983174Smsmith        AcpiDbSetMethodBreakpoint (AcpiGbl_DbArgs[1], WalkState, Op);
95067754Smsmith        break;
95167754Smsmith
952151937Sjkim    case CMD_BUSINFO:
953250838Sjkim
954151937Sjkim        AcpiDbGetBusInfo ();
955151937Sjkim        break;
956151937Sjkim
95767754Smsmith    case CMD_CALL:
958250838Sjkim
95967754Smsmith        AcpiDbSetMethodCallBreakpoint (Op);
96067754Smsmith        Status = AE_OK;
96167754Smsmith        break;
96267754Smsmith
96367754Smsmith    case CMD_DEBUG:
964250838Sjkim
965222544Sjkim        AcpiDbExecute (AcpiGbl_DbArgs[1],
966222544Sjkim            &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_SINGLE_STEP);
96767754Smsmith        break;
96867754Smsmith
969138287Smarks    case CMD_DISASSEMBLE:
970243347Sjkim    case CMD_DISASM:
971250838Sjkim
972151937Sjkim        (void) AcpiDbDisassembleMethod (AcpiGbl_DbArgs[1]);
973138287Smarks        break;
974138287Smarks
97567754Smsmith    case CMD_DUMP:
976250838Sjkim
97783174Smsmith        AcpiDbDecodeAndDisplayObject (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
97867754Smsmith        break;
97967754Smsmith
980240716Sjkim    case CMD_EVALUATE:
98167754Smsmith    case CMD_EXECUTE:
982250838Sjkim
983151937Sjkim        AcpiDbExecute (AcpiGbl_DbArgs[1],
984222544Sjkim            &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_NO_SINGLE_STEP);
98567754Smsmith        break;
98667754Smsmith
98767754Smsmith    case CMD_FIND:
988250838Sjkim
989129684Snjl        Status = AcpiDbFindNameInNamespace (AcpiGbl_DbArgs[1]);
99067754Smsmith        break;
99167754Smsmith
99267754Smsmith    case CMD_GO:
993250838Sjkim
99467754Smsmith        AcpiGbl_CmSingleStep = FALSE;
99567754Smsmith        return (AE_OK);
99667754Smsmith
997218590Sjkim    case CMD_HANDLERS:
998250838Sjkim
999218590Sjkim        AcpiDbDisplayHandlers ();
1000218590Sjkim        break;
1001218590Sjkim
100267754Smsmith    case CMD_HELP:
100367754Smsmith    case CMD_HELP2:
1004250838Sjkim
1005240716Sjkim        AcpiDbDisplayHelp (AcpiGbl_DbArgs[1]);
100667754Smsmith        break;
100767754Smsmith
100867754Smsmith    case CMD_HISTORY:
1009250838Sjkim
101067754Smsmith        AcpiDbDisplayHistory ();
101167754Smsmith        break;
101267754Smsmith
1013250838Sjkim    case CMD_HISTORY_EXE: /* ! command */
1014250838Sjkim
101583174Smsmith        CommandLine = AcpiDbGetFromHistory (AcpiGbl_DbArgs[1]);
101667754Smsmith        if (!CommandLine)
101767754Smsmith        {
101867754Smsmith            return (AE_CTRL_TRUE);
101967754Smsmith        }
102067754Smsmith
102167754Smsmith        Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
102267754Smsmith        return (Status);
102367754Smsmith
1024250838Sjkim    case CMD_HISTORY_LAST: /* !! command */
1025252279Sjkim
102667754Smsmith        CommandLine = AcpiDbGetFromHistory (NULL);
102767754Smsmith        if (!CommandLine)
102867754Smsmith        {
102967754Smsmith            return (AE_CTRL_TRUE);
103067754Smsmith        }
103167754Smsmith
103267754Smsmith        Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
103367754Smsmith        return (Status);
103467754Smsmith
103567754Smsmith    case CMD_INFORMATION:
1036252279Sjkim
103767754Smsmith        AcpiDbDisplayMethodInfo (Op);
103867754Smsmith        break;
103967754Smsmith
104099679Siwasaki    case CMD_INTEGRITY:
1041252279Sjkim
104299679Siwasaki        AcpiDbCheckIntegrity ();
104399679Siwasaki        break;
104499679Siwasaki
104567754Smsmith    case CMD_INTO:
1046250838Sjkim
104767754Smsmith        if (Op)
104867754Smsmith        {
104967754Smsmith            AcpiGbl_CmSingleStep = TRUE;
105067754Smsmith            return (AE_OK);
105167754Smsmith        }
105267754Smsmith        break;
105367754Smsmith
105467754Smsmith    case CMD_LEVEL:
1055250838Sjkim
105667754Smsmith        if (ParamCount == 0)
105767754Smsmith        {
1058287168Sjkim            AcpiOsPrintf (
1059287168Sjkim                "Current debug level for file output is:    %8.8lX\n",
1060151937Sjkim                AcpiGbl_DbDebugLevel);
1061287168Sjkim            AcpiOsPrintf (
1062287168Sjkim                "Current debug level for console output is: %8.8lX\n",
1063151937Sjkim                AcpiGbl_DbConsoleDebugLevel);
106467754Smsmith        }
106567754Smsmith        else if (ParamCount == 2)
106667754Smsmith        {
106767754Smsmith            Temp = AcpiGbl_DbConsoleDebugLevel;
1068298714Sjkim            AcpiGbl_DbConsoleDebugLevel =
1069298714Sjkim                strtoul (AcpiGbl_DbArgs[1], NULL, 16);
1070151937Sjkim            AcpiOsPrintf (
1071151937Sjkim                "Debug Level for console output was %8.8lX, now %8.8lX\n",
1072151937Sjkim                Temp, AcpiGbl_DbConsoleDebugLevel);
107367754Smsmith        }
107467754Smsmith        else
107567754Smsmith        {
107667754Smsmith            Temp = AcpiGbl_DbDebugLevel;
1077284583Sjkim            AcpiGbl_DbDebugLevel = strtoul (AcpiGbl_DbArgs[1], NULL, 16);
1078151937Sjkim            AcpiOsPrintf (
1079151937Sjkim                "Debug Level for file output was %8.8lX, now %8.8lX\n",
1080151937Sjkim                Temp, AcpiGbl_DbDebugLevel);
108167754Smsmith        }
108267754Smsmith        break;
108367754Smsmith
108467754Smsmith    case CMD_LIST:
1085250838Sjkim
108683174Smsmith        AcpiDbDisassembleAml (AcpiGbl_DbArgs[1], Op);
108767754Smsmith        break;
108867754Smsmith
108977424Smsmith    case CMD_LOCKS:
1090250838Sjkim
109177424Smsmith        AcpiDbDisplayLocks ();
109277424Smsmith        break;
109377424Smsmith
109467754Smsmith    case CMD_LOCALS:
1095250838Sjkim
109667754Smsmith        AcpiDbDisplayLocals ();
109767754Smsmith        break;
109867754Smsmith
109967754Smsmith    case CMD_METHODS:
1100250838Sjkim
1101129684Snjl        Status = AcpiDbDisplayObjects ("METHOD", AcpiGbl_DbArgs[1]);
110267754Smsmith        break;
110367754Smsmith
110467754Smsmith    case CMD_NAMESPACE:
1105250838Sjkim
110683174Smsmith        AcpiDbDumpNamespace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
110767754Smsmith        break;
110867754Smsmith
110967754Smsmith    case CMD_NOTIFY:
1110250838Sjkim
1111284583Sjkim        Temp = strtoul (AcpiGbl_DbArgs[2], NULL, 0);
111283174Smsmith        AcpiDbSendNotify (AcpiGbl_DbArgs[1], Temp);
111367754Smsmith        break;
111467754Smsmith
1115272444Sjkim    case CMD_OBJECTS:
1116250838Sjkim
1117151937Sjkim        AcpiUtStrupr (AcpiGbl_DbArgs[1]);
1118129684Snjl        Status = AcpiDbDisplayObjects (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
111967754Smsmith        break;
112067754Smsmith
1121210976Sjkim    case CMD_OSI:
1122250838Sjkim
1123210976Sjkim        AcpiDbDisplayInterfaces (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1124210976Sjkim        break;
1125210976Sjkim
112667754Smsmith    case CMD_OWNER:
1127252279Sjkim
112883174Smsmith        AcpiDbDumpNamespaceByOwner (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
112967754Smsmith        break;
113067754Smsmith
1131254745Sjkim    case CMD_PATHS:
1132254745Sjkim
1133254745Sjkim        AcpiDbDumpNamespacePaths ();
1134254745Sjkim        break;
1135254745Sjkim
113667754Smsmith    case CMD_PREFIX:
1137250838Sjkim
113883174Smsmith        AcpiDbSetScope (AcpiGbl_DbArgs[1]);
113967754Smsmith        break;
114067754Smsmith
114167754Smsmith    case CMD_REFERENCES:
1142250838Sjkim
114383174Smsmith        AcpiDbFindReferences (AcpiGbl_DbArgs[1]);
114467754Smsmith        break;
114567754Smsmith
114673561Smsmith    case CMD_RESOURCES:
1147250838Sjkim
114883174Smsmith        AcpiDbDisplayResources (AcpiGbl_DbArgs[1]);
114973561Smsmith        break;
115073561Smsmith
115167754Smsmith    case CMD_RESULTS:
1152250838Sjkim
115367754Smsmith        AcpiDbDisplayResults ();
115467754Smsmith        break;
115567754Smsmith
115667754Smsmith    case CMD_SET:
1157250838Sjkim
1158151937Sjkim        AcpiDbSetMethodData (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],
1159151937Sjkim            AcpiGbl_DbArgs[3]);
116067754Smsmith        break;
116167754Smsmith
116267754Smsmith    case CMD_STATS:
1163250838Sjkim
1164129684Snjl        Status = AcpiDbDisplayStatistics (AcpiGbl_DbArgs[1]);
116567754Smsmith        break;
116667754Smsmith
116767754Smsmith    case CMD_STOP:
1168250838Sjkim
116999679Siwasaki        return (AE_NOT_IMPLEMENTED);
117067754Smsmith
117167754Smsmith    case CMD_TABLES:
1172250838Sjkim
117383174Smsmith        AcpiDbDisplayTableInfo (AcpiGbl_DbArgs[1]);
117467754Smsmith        break;
117567754Smsmith
1176228110Sjkim    case CMD_TEMPLATE:
1177250838Sjkim
1178228110Sjkim        AcpiDbDisplayTemplate (AcpiGbl_DbArgs[1]);
1179228110Sjkim        break;
1180228110Sjkim
1181287168Sjkim    case CMD_TRACE:
1182287168Sjkim
1183287168Sjkim        AcpiDbTrace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], AcpiGbl_DbArgs[3]);
1184287168Sjkim        break;
1185287168Sjkim
1186287168Sjkim    case CMD_TREE:
1187287168Sjkim
1188287168Sjkim        AcpiDbDisplayCallingTree ();
1189287168Sjkim        break;
1190287168Sjkim
1191287168Sjkim    case CMD_TYPE:
1192287168Sjkim
1193287168Sjkim        AcpiDbDisplayObjectType (AcpiGbl_DbArgs[1]);
1194287168Sjkim        break;
1195287168Sjkim
1196287168Sjkim#ifdef ACPI_APPLICATION
1197287168Sjkim
1198287168Sjkim    /* Hardware simulation commands. */
1199287168Sjkim
1200287168Sjkim    case CMD_ENABLEACPI:
1201287168Sjkim#if (!ACPI_REDUCED_HARDWARE)
1202287168Sjkim
1203287168Sjkim        Status = AcpiEnable();
1204287168Sjkim        if (ACPI_FAILURE(Status))
1205287168Sjkim        {
1206287168Sjkim            AcpiOsPrintf("AcpiEnable failed (Status=%X)\n", Status);
1207287168Sjkim            return (Status);
1208287168Sjkim        }
1209287168Sjkim#endif /* !ACPI_REDUCED_HARDWARE */
1210287168Sjkim        break;
1211287168Sjkim
1212287168Sjkim    case CMD_EVENT:
1213287168Sjkim
1214287168Sjkim        AcpiOsPrintf ("Event command not implemented\n");
1215287168Sjkim        break;
1216287168Sjkim
1217287168Sjkim    case CMD_GPE:
1218287168Sjkim
1219287168Sjkim        AcpiDbGenerateGpe (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1220287168Sjkim        break;
1221287168Sjkim
1222287168Sjkim    case CMD_GPES:
1223287168Sjkim
1224287168Sjkim        AcpiDbDisplayGpes ();
1225287168Sjkim        break;
1226287168Sjkim
1227287168Sjkim    case CMD_SCI:
1228287168Sjkim
1229287168Sjkim        AcpiDbGenerateSci ();
1230287168Sjkim        break;
1231287168Sjkim
1232287168Sjkim    case CMD_SLEEP:
1233287168Sjkim
1234287168Sjkim        Status = AcpiDbSleep (AcpiGbl_DbArgs[1]);
1235287168Sjkim        break;
1236287168Sjkim
1237287168Sjkim    /* File I/O commands. */
1238287168Sjkim
1239287168Sjkim    case CMD_CLOSE:
1240287168Sjkim
1241287168Sjkim        AcpiDbCloseDebugFile ();
1242287168Sjkim        break;
1243287168Sjkim
1244287168Sjkim    case CMD_LOAD:
1245298714Sjkim        {
1246298714Sjkim            ACPI_NEW_TABLE_DESC     *ListHead = NULL;
1247287168Sjkim
1248298714Sjkim            Status = AcGetAllTablesFromFile (AcpiGbl_DbArgs[1],
1249298714Sjkim                ACPI_GET_ALL_TABLES, &ListHead);
1250298714Sjkim            if (ACPI_SUCCESS (Status))
1251298714Sjkim            {
1252298714Sjkim                AcpiDbLoadTables (ListHead);
1253298714Sjkim            }
1254298714Sjkim        }
1255287168Sjkim        break;
1256287168Sjkim
1257287168Sjkim    case CMD_OPEN:
1258287168Sjkim
1259287168Sjkim        AcpiDbOpenDebugFile (AcpiGbl_DbArgs[1]);
1260287168Sjkim        break;
1261287168Sjkim
1262287168Sjkim    /* User space commands. */
1263287168Sjkim
126467754Smsmith    case CMD_TERMINATE:
1265250838Sjkim
126691116Smsmith        AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
126777424Smsmith        AcpiUtSubsystemShutdown ();
126867754Smsmith
1269151937Sjkim        /*
1270151937Sjkim         * TBD: [Restructure] Need some way to re-initialize without
1271151937Sjkim         * re-creating the semaphores!
1272151937Sjkim         */
127367754Smsmith
1274298714Sjkim        AcpiGbl_DbTerminateLoop = TRUE;
127567754Smsmith        /*  AcpiInitialize (NULL);  */
127667754Smsmith        break;
127767754Smsmith
1278327557Sjkim    case CMD_BACKGROUND:
1279327557Sjkim
1280327557Sjkim        AcpiDbCreateExecutionThread (AcpiGbl_DbArgs[1], &AcpiGbl_DbArgs[2],
1281327557Sjkim            &AcpiGbl_DbArgTypes[2]);
1282327557Sjkim        break;
1283327557Sjkim
128467754Smsmith    case CMD_THREADS:
1285250838Sjkim
1286151937Sjkim        AcpiDbCreateExecutionThreads (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],
1287151937Sjkim            AcpiGbl_DbArgs[3]);
128867754Smsmith        break;
128967754Smsmith
1290287168Sjkim    /* Debug test commands. */
1291250838Sjkim
1292287168Sjkim    case CMD_PREDEFINED:
1293151937Sjkim
1294287168Sjkim        AcpiDbCheckPredefinedNames ();
129567754Smsmith        break;
129667754Smsmith
1297287168Sjkim    case CMD_TEST:
1298250838Sjkim
1299287168Sjkim        AcpiDbExecuteTest (AcpiGbl_DbArgs[1]);
1300117521Snjl        break;
1301117521Snjl
130267754Smsmith    case CMD_UNLOAD:
1303250838Sjkim
1304238381Sjkim        AcpiDbUnloadAcpiTable (AcpiGbl_DbArgs[1]);
130567754Smsmith        break;
1306287168Sjkim#endif
130767754Smsmith
130867754Smsmith    case CMD_EXIT:
130967754Smsmith    case CMD_QUIT:
1310250838Sjkim
131167754Smsmith        if (Op)
131267754Smsmith        {
131377424Smsmith            AcpiOsPrintf ("Method execution terminated\n");
131477424Smsmith            return (AE_CTRL_TERMINATE);
131567754Smsmith        }
131667754Smsmith
131783174Smsmith        if (!AcpiGbl_DbOutputToFile)
131867754Smsmith        {
1319114237Snjl            AcpiDbgLevel = ACPI_DEBUG_DEFAULT;
132067754Smsmith        }
132167754Smsmith
1322287168Sjkim#ifdef ACPI_APPLICATION
132367754Smsmith        AcpiDbCloseDebugFile ();
1324287168Sjkim#endif
1325298714Sjkim        AcpiGbl_DbTerminateLoop = TRUE;
132667754Smsmith        return (AE_CTRL_TERMINATE);
132767754Smsmith
132867754Smsmith    case CMD_NOT_FOUND:
132999679Siwasaki    default:
1330250838Sjkim
1331272444Sjkim        AcpiOsPrintf ("%s: unknown command\n", AcpiGbl_DbArgs[0]);
133267754Smsmith        return (AE_CTRL_TRUE);
133367754Smsmith    }
133467754Smsmith
1335151937Sjkim    if (ACPI_SUCCESS (Status))
1336151937Sjkim    {
1337151937Sjkim        Status = AE_CTRL_TRUE;
1338151937Sjkim    }
133967754Smsmith
134067754Smsmith    return (Status);
134167754Smsmith}
134267754Smsmith
134367754Smsmith
134467754Smsmith/*******************************************************************************
134567754Smsmith *
134667754Smsmith * FUNCTION:    AcpiDbExecuteThread
134767754Smsmith *
134867754Smsmith * PARAMETERS:  Context         - Not used
134967754Smsmith *
135067754Smsmith * RETURN:      None
135167754Smsmith *
1352241973Sjkim * DESCRIPTION: Debugger execute thread. Waits for a command line, then
135367754Smsmith *              simply dispatches it.
135467754Smsmith *
135567754Smsmith ******************************************************************************/
135667754Smsmith
135792388Smsmithvoid ACPI_SYSTEM_XFACE
135867754SmsmithAcpiDbExecuteThread (
135967754Smsmith    void                    *Context)
136067754Smsmith{
136167754Smsmith
1362316303Sjkim    (void) AcpiDbUserCommands ();
1363298714Sjkim    AcpiGbl_DbThreadsTerminated = TRUE;
136467754Smsmith}
136567754Smsmith
136667754Smsmith
136767754Smsmith/*******************************************************************************
136867754Smsmith *
1369316303Sjkim * FUNCTION:    AcpiDbUserCommands
137067754Smsmith *
137167754Smsmith * PARAMETERS:  None
137267754Smsmith *
137367754Smsmith * RETURN:      None
137467754Smsmith *
1375241973Sjkim * DESCRIPTION: Command line execution for the AML debugger. Commands are
137667754Smsmith *              matched and dispatched here.
137767754Smsmith *
137867754Smsmith ******************************************************************************/
137967754Smsmith
138067754SmsmithACPI_STATUS
138167754SmsmithAcpiDbUserCommands (
1382316303Sjkim    void)
138367754Smsmith{
138467754Smsmith    ACPI_STATUS             Status = AE_OK;
138567754Smsmith
138667754Smsmith
1387245582Sjkim    AcpiOsPrintf ("\n");
1388245582Sjkim
138967754Smsmith    /* TBD: [Restructure] Need a separate command line buffer for step mode */
139067754Smsmith
1391298714Sjkim    while (!AcpiGbl_DbTerminateLoop)
139267754Smsmith    {
1393316303Sjkim        /* Wait the readiness of the command */
139467754Smsmith
1395316303Sjkim        Status = AcpiOsWaitCommandReady ();
1396316303Sjkim        if (ACPI_FAILURE (Status))
139767754Smsmith        {
1398316303Sjkim            break;
139967754Smsmith        }
140067754Smsmith
1401316303Sjkim        /* Just call to the command line interpreter */
140267754Smsmith
1403316303Sjkim        AcpiGbl_MethodExecuting = FALSE;
1404316303Sjkim        AcpiGbl_StepToNextCall = FALSE;
140567754Smsmith
1406316303Sjkim        (void) AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
140767754Smsmith
1408316303Sjkim        /* Notify the completion of the command */
140991116Smsmith
1410316303Sjkim        Status = AcpiOsNotifyCommandComplete ();
1411316303Sjkim        if (ACPI_FAILURE (Status))
141267754Smsmith        {
1413316303Sjkim            break;
141467754Smsmith        }
141567754Smsmith    }
141667754Smsmith
1417316303Sjkim    if (ACPI_FAILURE (Status) && Status != AE_CTRL_TERMINATE)
1418316303Sjkim    {
1419316303Sjkim        ACPI_EXCEPTION ((AE_INFO, Status, "While parsing command line"));
1420316303Sjkim    }
142167754Smsmith    return (Status);
142267754Smsmith}
1423