xref: /onnv-gate/usr/src/uts/intel/io/acpica/debugger/dbinput.c (revision 7851:e828bbb1689c)
13446Smrj /*******************************************************************************
23446Smrj  *
33446Smrj  * Module Name: dbinput - user front-end to the AML debugger
4*7851SDana.Myers@Sun.COM  *              $Revision: 1.116 $
53446Smrj  *
63446Smrj  ******************************************************************************/
73446Smrj 
83446Smrj /******************************************************************************
93446Smrj  *
103446Smrj  * 1. Copyright Notice
113446Smrj  *
12*7851SDana.Myers@Sun.COM  * Some or all of this work - Copyright (c) 1999 - 2008, Intel Corp.
133446Smrj  * All rights reserved.
143446Smrj  *
153446Smrj  * 2. License
163446Smrj  *
173446Smrj  * 2.1. This is your license from Intel Corp. under its intellectual property
183446Smrj  * rights.  You may have additional license terms from the party that provided
193446Smrj  * you this software, covering your right to use that party's intellectual
203446Smrj  * property rights.
213446Smrj  *
223446Smrj  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
233446Smrj  * copy of the source code appearing in this file ("Covered Code") an
243446Smrj  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
253446Smrj  * base code distributed originally by Intel ("Original Intel Code") to copy,
263446Smrj  * make derivatives, distribute, use and display any portion of the Covered
273446Smrj  * Code in any form, with the right to sublicense such rights; and
283446Smrj  *
293446Smrj  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
303446Smrj  * license (with the right to sublicense), under only those claims of Intel
313446Smrj  * patents that are infringed by the Original Intel Code, to make, use, sell,
323446Smrj  * offer to sell, and import the Covered Code and derivative works thereof
333446Smrj  * solely to the minimum extent necessary to exercise the above copyright
343446Smrj  * license, and in no event shall the patent license extend to any additions
353446Smrj  * to or modifications of the Original Intel Code.  No other license or right
363446Smrj  * is granted directly or by implication, estoppel or otherwise;
373446Smrj  *
383446Smrj  * The above copyright and patent license is granted only if the following
393446Smrj  * conditions are met:
403446Smrj  *
413446Smrj  * 3. Conditions
423446Smrj  *
433446Smrj  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
443446Smrj  * Redistribution of source code of any substantial portion of the Covered
453446Smrj  * Code or modification with rights to further distribute source must include
463446Smrj  * the above Copyright Notice, the above License, this list of Conditions,
473446Smrj  * and the following Disclaimer and Export Compliance provision.  In addition,
483446Smrj  * Licensee must cause all Covered Code to which Licensee contributes to
493446Smrj  * contain a file documenting the changes Licensee made to create that Covered
503446Smrj  * Code and the date of any change.  Licensee must include in that file the
513446Smrj  * documentation of any changes made by any predecessor Licensee.  Licensee
523446Smrj  * must include a prominent statement that the modification is derived,
533446Smrj  * directly or indirectly, from Original Intel Code.
543446Smrj  *
553446Smrj  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
563446Smrj  * Redistribution of source code of any substantial portion of the Covered
573446Smrj  * Code or modification without rights to further distribute source must
583446Smrj  * include the following Disclaimer and Export Compliance provision in the
593446Smrj  * documentation and/or other materials provided with distribution.  In
603446Smrj  * addition, Licensee may not authorize further sublicense of source of any
613446Smrj  * portion of the Covered Code, and must include terms to the effect that the
623446Smrj  * license from Licensee to its licensee is limited to the intellectual
633446Smrj  * property embodied in the software Licensee provides to its licensee, and
643446Smrj  * not to intellectual property embodied in modifications its licensee may
653446Smrj  * make.
663446Smrj  *
673446Smrj  * 3.3. Redistribution of Executable. Redistribution in executable form of any
683446Smrj  * substantial portion of the Covered Code or modification must reproduce the
693446Smrj  * above Copyright Notice, and the following Disclaimer and Export Compliance
703446Smrj  * provision in the documentation and/or other materials provided with the
713446Smrj  * distribution.
723446Smrj  *
733446Smrj  * 3.4. Intel retains all right, title, and interest in and to the Original
743446Smrj  * Intel Code.
753446Smrj  *
763446Smrj  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
773446Smrj  * Intel shall be used in advertising or otherwise to promote the sale, use or
783446Smrj  * other dealings in products derived from or relating to the Covered Code
793446Smrj  * without prior written authorization from Intel.
803446Smrj  *
813446Smrj  * 4. Disclaimer and Export Compliance
823446Smrj  *
833446Smrj  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
843446Smrj  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
853446Smrj  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
863446Smrj  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
873446Smrj  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
883446Smrj  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
893446Smrj  * PARTICULAR PURPOSE.
903446Smrj  *
913446Smrj  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
923446Smrj  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
933446Smrj  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
943446Smrj  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
953446Smrj  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
963446Smrj  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
973446Smrj  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
983446Smrj  * LIMITED REMEDY.
993446Smrj  *
1003446Smrj  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1013446Smrj  * software or system incorporating such software without first obtaining any
1023446Smrj  * required license or other approval from the U. S. Department of Commerce or
1033446Smrj  * any other agency or department of the United States Government.  In the
1043446Smrj  * event Licensee exports any such software from the United States or
1053446Smrj  * re-exports any such software from a foreign destination, Licensee shall
1063446Smrj  * ensure that the distribution and export/re-export of the software is in
1073446Smrj  * compliance with all laws, regulations, orders, or other restrictions of the
1083446Smrj  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1093446Smrj  * any of its subsidiaries will export/re-export any technical data, process,
1103446Smrj  * software, or service, directly or indirectly, to any country for which the
1113446Smrj  * United States government or any agency thereof requires an export license,
1123446Smrj  * other governmental approval, or letter of assurance, without first obtaining
1133446Smrj  * such license, approval or letter.
1143446Smrj  *
1153446Smrj  *****************************************************************************/
1163446Smrj 
1173446Smrj 
1183446Smrj #include "acpi.h"
1193446Smrj #include "acdebug.h"
1203446Smrj 
1213446Smrj 
1223446Smrj #ifdef ACPI_DEBUGGER
1233446Smrj 
1243446Smrj #define _COMPONENT          ACPI_CA_DEBUGGER
1253446Smrj         ACPI_MODULE_NAME    ("dbinput")
1263446Smrj 
1273446Smrj /* Local prototypes */
1283446Smrj 
1293446Smrj static char *
1303446Smrj AcpiDbGetNextToken (
1313446Smrj     char                    *String,
1323446Smrj     char                    **Next);
1333446Smrj 
1343446Smrj static UINT32
1353446Smrj AcpiDbGetLine (
1363446Smrj     char                    *InputBuffer);
1373446Smrj 
1383446Smrj static UINT32
1393446Smrj AcpiDbMatchCommand (
1403446Smrj     char                    *UserCommand);
1413446Smrj 
1423446Smrj static void
1433446Smrj AcpiDbSingleThread (
1443446Smrj     void);
1453446Smrj 
1463446Smrj static void
1473446Smrj AcpiDbDisplayHelp (
1483446Smrj     char                    *HelpType);
1493446Smrj 
1503446Smrj 
1513446Smrj /*
1523446Smrj  * Top-level debugger commands.
1533446Smrj  *
1543446Smrj  * This list of commands must match the string table below it
1553446Smrj  */
1563446Smrj enum AcpiExDebuggerCommands
1573446Smrj {
1583446Smrj     CMD_NOT_FOUND = 0,
1593446Smrj     CMD_NULL,
1603446Smrj     CMD_ALLOCATIONS,
1613446Smrj     CMD_ARGS,
1623446Smrj     CMD_ARGUMENTS,
1633446Smrj     CMD_BREAKPOINT,
1643446Smrj     CMD_BUSINFO,
1653446Smrj     CMD_CALL,
1663446Smrj     CMD_CLOSE,
1673446Smrj     CMD_DEBUG,
1683446Smrj     CMD_DISASSEMBLE,
1693446Smrj     CMD_DUMP,
1703446Smrj     CMD_ENABLEACPI,
1713446Smrj     CMD_EVENT,
1723446Smrj     CMD_EXECUTE,
1733446Smrj     CMD_EXIT,
1743446Smrj     CMD_FIND,
1753446Smrj     CMD_GO,
1763446Smrj     CMD_GPE,
1773446Smrj     CMD_GPES,
1783446Smrj     CMD_HELP,
1793446Smrj     CMD_HELP2,
1803446Smrj     CMD_HISTORY,
1813446Smrj     CMD_HISTORY_EXE,
1823446Smrj     CMD_HISTORY_LAST,
1833446Smrj     CMD_INFORMATION,
1843446Smrj     CMD_INTEGRITY,
1853446Smrj     CMD_INTO,
1863446Smrj     CMD_LEVEL,
1873446Smrj     CMD_LIST,
1883446Smrj     CMD_LOAD,
1893446Smrj     CMD_LOCALS,
1903446Smrj     CMD_LOCKS,
1913446Smrj     CMD_METHODS,
1923446Smrj     CMD_NAMESPACE,
1933446Smrj     CMD_NOTIFY,
1943446Smrj     CMD_OBJECT,
1953446Smrj     CMD_OPEN,
1963446Smrj     CMD_OWNER,
1973446Smrj     CMD_PREFIX,
1983446Smrj     CMD_QUIT,
1993446Smrj     CMD_REFERENCES,
2003446Smrj     CMD_RESOURCES,
2013446Smrj     CMD_RESULTS,
2023446Smrj     CMD_SET,
2033446Smrj     CMD_SLEEP,
2043446Smrj     CMD_STATS,
2053446Smrj     CMD_STOP,
2063446Smrj     CMD_TABLES,
2073446Smrj     CMD_TERMINATE,
2083446Smrj     CMD_THREADS,
2093446Smrj     CMD_TRACE,
2103446Smrj     CMD_TREE,
2113446Smrj     CMD_TYPE,
2123446Smrj     CMD_UNLOAD
2133446Smrj };
2143446Smrj 
2153446Smrj #define CMD_FIRST_VALID     2
2163446Smrj 
2173446Smrj static const COMMAND_INFO       AcpiGbl_DbCommands[] =
2183446Smrj {
2193446Smrj     {"<NOT FOUND>",  0},
2203446Smrj     {"<NULL>",       0},
2213446Smrj     {"ALLOCATIONS",  0},
2223446Smrj     {"ARGS",         0},
2233446Smrj     {"ARGUMENTS",    0},
2243446Smrj     {"BREAKPOINT",   1},
2253446Smrj     {"BUSINFO",      0},
2263446Smrj     {"CALL",         0},
2273446Smrj     {"CLOSE",        0},
2283446Smrj     {"DEBUG",        1},
2293446Smrj     {"DISASSEMBLE",  1},
2303446Smrj     {"DUMP",         1},
2313446Smrj     {"ENABLEACPI",   0},
2323446Smrj     {"EVENT",        1},
2333446Smrj     {"EXECUTE",      1},
2343446Smrj     {"EXIT",         0},
2353446Smrj     {"FIND",         1},
2363446Smrj     {"GO",           0},
2373446Smrj     {"GPE",          2},
2383446Smrj     {"GPES",         0},
2393446Smrj     {"HELP",         0},
2403446Smrj     {"?",            0},
2413446Smrj     {"HISTORY",      0},
2423446Smrj     {"!",            1},
2433446Smrj     {"!!",           0},
2443446Smrj     {"INFORMATION",  0},
2453446Smrj     {"INTEGRITY",    0},
2463446Smrj     {"INTO",         0},
2473446Smrj     {"LEVEL",        0},
2483446Smrj     {"LIST",         0},
2493446Smrj     {"LOAD",         1},
2503446Smrj     {"LOCALS",       0},
2513446Smrj     {"LOCKS",        0},
2523446Smrj     {"METHODS",      0},
2533446Smrj     {"NAMESPACE",    0},
2543446Smrj     {"NOTIFY",       2},
2553446Smrj     {"OBJECT",       1},
2563446Smrj     {"OPEN",         1},
2573446Smrj     {"OWNER",        1},
2583446Smrj     {"PREFIX",       0},
2593446Smrj     {"QUIT",         0},
2603446Smrj     {"REFERENCES",   1},
2613446Smrj     {"RESOURCES",    1},
2623446Smrj     {"RESULTS",      0},
2633446Smrj     {"SET",          3},
2643446Smrj     {"SLEEP",        1},
2653446Smrj     {"STATS",        0},
2663446Smrj     {"STOP",         0},
2673446Smrj     {"TABLES",       0},
2683446Smrj     {"TERMINATE",    0},
2693446Smrj     {"THREADS",      3},
2703446Smrj     {"TRACE",        1},
2713446Smrj     {"TREE",         0},
2723446Smrj     {"TYPE",         1},
2733446Smrj     {"UNLOAD",       1},
2743446Smrj     {NULL,           0}
2753446Smrj };
2763446Smrj 
2773446Smrj 
2783446Smrj /*******************************************************************************
2793446Smrj  *
2803446Smrj  * FUNCTION:    AcpiDbDisplayHelp
2813446Smrj  *
2823446Smrj  * PARAMETERS:  HelpType        - Subcommand (optional)
2833446Smrj  *
2843446Smrj  * RETURN:      None
2853446Smrj  *
2863446Smrj  * DESCRIPTION: Print a usage message.
2873446Smrj  *
2883446Smrj  ******************************************************************************/
2893446Smrj 
2903446Smrj static void
2913446Smrj AcpiDbDisplayHelp (
2923446Smrj     char                    *HelpType)
2933446Smrj {
2943446Smrj 
2953446Smrj     AcpiUtStrupr (HelpType);
2963446Smrj 
2973446Smrj     /* No parameter, just give the overview */
2983446Smrj 
2993446Smrj     if (!HelpType)
3003446Smrj     {
3013446Smrj         AcpiOsPrintf ("ACPI CA Debugger Commands\n\n");
3023446Smrj         AcpiOsPrintf ("The following classes of commands are available.  Help is available for\n");
3033446Smrj         AcpiOsPrintf ("each class by entering \"Help <ClassName>\"\n\n");
3043446Smrj         AcpiOsPrintf ("    [GENERAL]       General-Purpose Commands\n");
3053446Smrj         AcpiOsPrintf ("    [NAMESPACE]     Namespace Access Commands\n");
3063446Smrj         AcpiOsPrintf ("    [METHOD]        Control Method Execution Commands\n");
3073446Smrj         AcpiOsPrintf ("    [STATISTICS]    Statistical Information\n");
3083446Smrj         AcpiOsPrintf ("    [FILE]          File I/O Commands\n");
3093446Smrj         return;
3103446Smrj     }
3113446Smrj 
3123446Smrj     /*
3133446Smrj      * Parameter is the command class
3143446Smrj      *
3153446Smrj      * The idea here is to keep each class of commands smaller than a screenful
3163446Smrj      */
3173446Smrj     switch (HelpType[0])
3183446Smrj     {
3193446Smrj     case 'G':
3203446Smrj         AcpiOsPrintf ("\nGeneral-Purpose Commands\n\n");
3213446Smrj         AcpiOsPrintf ("Allocations                         Display list of current memory allocations\n");
3223446Smrj         AcpiOsPrintf ("Dump <Address>|<Namepath>\n");
3233446Smrj         AcpiOsPrintf ("     [Byte|Word|Dword|Qword]        Display ACPI objects or memory\n");
3243446Smrj         AcpiOsPrintf ("EnableAcpi                          Enable ACPI (hardware) mode\n");
3253446Smrj         AcpiOsPrintf ("Help                                This help screen\n");
3263446Smrj         AcpiOsPrintf ("History                             Display command history buffer\n");
3273446Smrj         AcpiOsPrintf ("Level [<DebugLevel>] [console]      Get/Set debug level for file or console\n");
3283446Smrj         AcpiOsPrintf ("Locks                               Current status of internal mutexes\n");
3293446Smrj         AcpiOsPrintf ("Quit or Exit                        Exit this command\n");
3303446Smrj         AcpiOsPrintf ("Stats [Allocations|Memory|Misc\n");
3313446Smrj         AcpiOsPrintf ("      |Objects|Sizes|Stack|Tables]  Display namespace and memory statistics\n");
3323446Smrj         AcpiOsPrintf ("Tables                              Display info about loaded ACPI tables\n");
3333446Smrj         AcpiOsPrintf ("Unload <TableSig> [Instance]        Unload an ACPI table\n");
3343446Smrj         AcpiOsPrintf ("! <CommandNumber>                   Execute command from history buffer\n");
3353446Smrj         AcpiOsPrintf ("!!                                  Execute last command again\n");
3363446Smrj         return;
3373446Smrj 
3383446Smrj     case 'S':
3393446Smrj         AcpiOsPrintf ("\nStats Subcommands\n\n");
3403446Smrj         AcpiOsPrintf ("Allocations                         Display list of current memory allocations\n");
3413446Smrj         AcpiOsPrintf ("Memory                              Dump internal memory lists\n");
3423446Smrj         AcpiOsPrintf ("Misc                                Namespace search and mutex stats\n");
3433446Smrj         AcpiOsPrintf ("Objects                             Summary of namespace objects\n");
3443446Smrj         AcpiOsPrintf ("Sizes                               Sizes for each of the internal objects\n");
3453446Smrj         AcpiOsPrintf ("Stack                               Display CPU stack usage\n");
3463446Smrj         AcpiOsPrintf ("Tables                              Info about current ACPI table(s)\n");
3473446Smrj         return;
3483446Smrj 
3493446Smrj     case 'N':
3503446Smrj         AcpiOsPrintf ("\nNamespace Access Commands\n\n");
3513446Smrj         AcpiOsPrintf ("Businfo                             Display system bus info\n");
3523446Smrj         AcpiOsPrintf ("Disassemble <Method>                Disassemble a control method\n");
3533446Smrj         AcpiOsPrintf ("Event <F|G> <Value>                 Generate AcpiEvent (Fixed/GPE)\n");
3543446Smrj         AcpiOsPrintf ("Find <AcpiName>  (? is wildcard)    Find ACPI name(s) with wildcards\n");
3553446Smrj         AcpiOsPrintf ("Gpe <GpeNum> <GpeBlock>             Simulate a GPE\n");
3563446Smrj         AcpiOsPrintf ("Gpes                                Display info on all GPEs\n");
3573446Smrj         AcpiOsPrintf ("Integrity                           Validate namespace integrity\n");
3583446Smrj         AcpiOsPrintf ("Methods                             Display list of loaded control methods\n");
3593446Smrj         AcpiOsPrintf ("Namespace [Object] [Depth]          Display loaded namespace tree/subtree\n");
3603446Smrj         AcpiOsPrintf ("Notify <Object> <Value>             Send a notification on Object\n");
3613446Smrj         AcpiOsPrintf ("Objects <ObjectType>                Display all objects of the given type\n");
3623446Smrj         AcpiOsPrintf ("Owner <OwnerId> [Depth]             Display loaded namespace by object owner\n");
3633446Smrj         AcpiOsPrintf ("Prefix [<NamePath>]                 Set or Get current execution prefix\n");
3643446Smrj         AcpiOsPrintf ("References <Addr>                   Find all references to object at addr\n");
3653446Smrj         AcpiOsPrintf ("Resources <Device>                  Get and display Device resources\n");
3663446Smrj         AcpiOsPrintf ("Set N <NamedObject> <Value>         Set value for named integer\n");
3673446Smrj         AcpiOsPrintf ("Sleep <SleepState>                  Simulate sleep/wake sequence\n");
3683446Smrj         AcpiOsPrintf ("Terminate                           Delete namespace and all internal objects\n");
3693446Smrj         AcpiOsPrintf ("Type <Object>                       Display object type\n");
3703446Smrj         return;
3713446Smrj 
3723446Smrj     case 'M':
3733446Smrj         AcpiOsPrintf ("\nControl Method Execution Commands\n\n");
3743446Smrj         AcpiOsPrintf ("Arguments (or Args)                 Display method arguments\n");
3753446Smrj         AcpiOsPrintf ("Breakpoint <AmlOffset>              Set an AML execution breakpoint\n");
3763446Smrj         AcpiOsPrintf ("Call                                Run to next control method invocation\n");
3773446Smrj         AcpiOsPrintf ("Debug <Namepath> [Arguments]        Single Step a control method\n");
3783446Smrj         AcpiOsPrintf ("Execute <Namepath> [Arguments]      Execute control method\n");
3793446Smrj         AcpiOsPrintf ("Go                                  Allow method to run to completion\n");
3803446Smrj         AcpiOsPrintf ("Information                         Display info about the current method\n");
3813446Smrj         AcpiOsPrintf ("Into                                Step into (not over) a method call\n");
3823446Smrj         AcpiOsPrintf ("List [# of Aml Opcodes]             Display method ASL statements\n");
3833446Smrj         AcpiOsPrintf ("Locals                              Display method local variables\n");
3843446Smrj         AcpiOsPrintf ("Results                             Display method result stack\n");
3853446Smrj         AcpiOsPrintf ("Set <A|L> <#> <Value>               Set method data (Arguments/Locals)\n");
3863446Smrj         AcpiOsPrintf ("Stop                                Terminate control method\n");
3873446Smrj         AcpiOsPrintf ("Thread <Threads><Loops><NamePath>   Spawn threads to execute method(s)\n");
3883446Smrj         AcpiOsPrintf ("Trace <method name>                 Trace method execution\n");
3893446Smrj         AcpiOsPrintf ("Tree                                Display control method calling tree\n");
3903446Smrj         AcpiOsPrintf ("<Enter>                             Single step next AML opcode (over calls)\n");
3913446Smrj         return;
3923446Smrj 
3933446Smrj     case 'F':
3943446Smrj         AcpiOsPrintf ("\nFile I/O Commands\n\n");
3953446Smrj         AcpiOsPrintf ("Close                               Close debug output file\n");
3963446Smrj         AcpiOsPrintf ("Open <Output Filename>              Open a file for debug output\n");
3973446Smrj         AcpiOsPrintf ("Load <Input Filename>               Load ACPI table from a file\n");
3983446Smrj         return;
3993446Smrj 
4003446Smrj     default:
4013446Smrj         AcpiOsPrintf ("Unrecognized Command Class: %s\n", HelpType);
4023446Smrj         return;
4033446Smrj     }
4043446Smrj }
4053446Smrj 
4063446Smrj 
4073446Smrj /*******************************************************************************
4083446Smrj  *
4093446Smrj  * FUNCTION:    AcpiDbGetNextToken
4103446Smrj  *
4113446Smrj  * PARAMETERS:  String          - Command buffer
4123446Smrj  *              Next            - Return value, end of next token
4133446Smrj  *
4143446Smrj  * RETURN:      Pointer to the start of the next token.
4153446Smrj  *
4163446Smrj  * DESCRIPTION: Command line parsing.  Get the next token on the command line
4173446Smrj  *
4183446Smrj  ******************************************************************************/
4193446Smrj 
4203446Smrj static char *
4213446Smrj AcpiDbGetNextToken (
4223446Smrj     char                    *String,
4233446Smrj     char                    **Next)
4243446Smrj {
4253446Smrj     char                    *Start;
4263446Smrj 
4273446Smrj 
4283446Smrj     /* At end of buffer? */
4293446Smrj 
4303446Smrj     if (!String || !(*String))
4313446Smrj     {
4323446Smrj         return (NULL);
4333446Smrj     }
4343446Smrj 
4353446Smrj     /* Get rid of any spaces at the beginning */
4363446Smrj 
4373446Smrj     if (*String == ' ')
4383446Smrj     {
4393446Smrj         while (*String && (*String == ' '))
4403446Smrj         {
4413446Smrj             String++;
4423446Smrj         }
4433446Smrj 
4443446Smrj         if (!(*String))
4453446Smrj         {
4463446Smrj             return (NULL);
4473446Smrj         }
4483446Smrj     }
4493446Smrj 
4503446Smrj     Start = String;
4513446Smrj 
4523446Smrj     /* Find end of token */
4533446Smrj 
4543446Smrj     while (*String && (*String != ' '))
4553446Smrj     {
4563446Smrj         String++;
4573446Smrj     }
4583446Smrj 
4593446Smrj     if (!(*String))
4603446Smrj     {
4613446Smrj         *Next = NULL;
4623446Smrj     }
4633446Smrj     else
4643446Smrj     {
4653446Smrj         *String = 0;
4663446Smrj         *Next = String + 1;
4673446Smrj     }
4683446Smrj 
4693446Smrj     return (Start);
4703446Smrj }
4713446Smrj 
4723446Smrj 
4733446Smrj /*******************************************************************************
4743446Smrj  *
4753446Smrj  * FUNCTION:    AcpiDbGetLine
4763446Smrj  *
4773446Smrj  * PARAMETERS:  InputBuffer         - Command line buffer
4783446Smrj  *
4793446Smrj  * RETURN:      Count of arguments to the command
4803446Smrj  *
4813446Smrj  * DESCRIPTION: Get the next command line from the user.  Gets entire line
4823446Smrj  *              up to the next newline
4833446Smrj  *
4843446Smrj  ******************************************************************************/
4853446Smrj 
4863446Smrj static UINT32
4873446Smrj AcpiDbGetLine (
4883446Smrj     char                    *InputBuffer)
4893446Smrj {
4903446Smrj     UINT32                  i;
4913446Smrj     UINT32                  Count;
4923446Smrj     char                    *Next;
4933446Smrj     char                    *This;
4943446Smrj 
4953446Smrj 
4963446Smrj     ACPI_STRCPY (AcpiGbl_DbParsedBuf, InputBuffer);
4973446Smrj 
4983446Smrj     This = AcpiGbl_DbParsedBuf;
4993446Smrj     for (i = 0; i < ACPI_DEBUGGER_MAX_ARGS; i++)
5003446Smrj     {
5013446Smrj         AcpiGbl_DbArgs[i] = AcpiDbGetNextToken (This, &Next);
5023446Smrj         if (!AcpiGbl_DbArgs[i])
5033446Smrj         {
5043446Smrj             break;
5053446Smrj         }
5063446Smrj 
5073446Smrj         This = Next;
5083446Smrj     }
5093446Smrj 
5103446Smrj     /* Uppercase the actual command */
5113446Smrj 
5123446Smrj     if (AcpiGbl_DbArgs[0])
5133446Smrj     {
5143446Smrj         AcpiUtStrupr (AcpiGbl_DbArgs[0]);
5153446Smrj     }
5163446Smrj 
5173446Smrj     Count = i;
5183446Smrj     if (Count)
5193446Smrj     {
5203446Smrj         Count--;  /* Number of args only */
5213446Smrj     }
5223446Smrj 
5233446Smrj     return (Count);
5243446Smrj }
5253446Smrj 
5263446Smrj 
5273446Smrj /*******************************************************************************
5283446Smrj  *
5293446Smrj  * FUNCTION:    AcpiDbMatchCommand
5303446Smrj  *
5313446Smrj  * PARAMETERS:  UserCommand             - User command line
5323446Smrj  *
5333446Smrj  * RETURN:      Index into command array, -1 if not found
5343446Smrj  *
5353446Smrj  * DESCRIPTION: Search command array for a command match
5363446Smrj  *
5373446Smrj  ******************************************************************************/
5383446Smrj 
5393446Smrj static UINT32
5403446Smrj AcpiDbMatchCommand (
5413446Smrj     char                    *UserCommand)
5423446Smrj {
5433446Smrj     UINT32                  i;
5443446Smrj 
5453446Smrj 
5463446Smrj     if (!UserCommand || UserCommand[0] == 0)
5473446Smrj     {
5483446Smrj         return (CMD_NULL);
5493446Smrj     }
5503446Smrj 
5513446Smrj     for (i = CMD_FIRST_VALID; AcpiGbl_DbCommands[i].Name; i++)
5523446Smrj     {
5533446Smrj         if (ACPI_STRSTR (AcpiGbl_DbCommands[i].Name, UserCommand) ==
5543446Smrj                          AcpiGbl_DbCommands[i].Name)
5553446Smrj         {
5563446Smrj             return (i);
5573446Smrj         }
5583446Smrj     }
5593446Smrj 
5603446Smrj     /* Command not recognized */
5613446Smrj 
5623446Smrj     return (CMD_NOT_FOUND);
5633446Smrj }
5643446Smrj 
5653446Smrj 
5663446Smrj /*******************************************************************************
5673446Smrj  *
5683446Smrj  * FUNCTION:    AcpiDbCommandDispatch
5693446Smrj  *
5703446Smrj  * PARAMETERS:  InputBuffer         - Command line buffer
5713446Smrj  *              WalkState           - Current walk
5723446Smrj  *              Op                  - Current (executing) parse op
5733446Smrj  *
5743446Smrj  * RETURN:      Status
5753446Smrj  *
5763446Smrj  * DESCRIPTION: Command dispatcher.
5773446Smrj  *
5783446Smrj  ******************************************************************************/
5793446Smrj 
5803446Smrj ACPI_STATUS
5813446Smrj AcpiDbCommandDispatch (
5823446Smrj     char                    *InputBuffer,
5833446Smrj     ACPI_WALK_STATE         *WalkState,
5843446Smrj     ACPI_PARSE_OBJECT       *Op)
5853446Smrj {
5863446Smrj     UINT32                  Temp;
5873446Smrj     UINT32                  CommandIndex;
5883446Smrj     UINT32                  ParamCount;
5893446Smrj     char                    *CommandLine;
5903446Smrj     ACPI_STATUS             Status = AE_CTRL_TRUE;
5913446Smrj 
5923446Smrj 
5933446Smrj     /* If AcpiTerminate has been called, terminate this thread */
5943446Smrj 
5953446Smrj     if (AcpiGbl_DbTerminateThreads)
5963446Smrj     {
5973446Smrj         return (AE_CTRL_TERMINATE);
5983446Smrj     }
5993446Smrj 
6003446Smrj     ParamCount = AcpiDbGetLine (InputBuffer);
6013446Smrj     CommandIndex = AcpiDbMatchCommand (AcpiGbl_DbArgs[0]);
6023446Smrj     Temp = 0;
6033446Smrj 
6043446Smrj     /* Verify that we have the minimum number of params */
6053446Smrj 
6063446Smrj     if (ParamCount < AcpiGbl_DbCommands[CommandIndex].MinArgs)
6073446Smrj     {
6083446Smrj         AcpiOsPrintf ("%d parameters entered, [%s] requires %d parameters\n",
6093446Smrj             ParamCount, AcpiGbl_DbCommands[CommandIndex].Name,
6103446Smrj             AcpiGbl_DbCommands[CommandIndex].MinArgs);
6113446Smrj 
6123446Smrj         return (AE_CTRL_TRUE);
6133446Smrj     }
6143446Smrj 
6153446Smrj     /* Decode and dispatch the command */
6163446Smrj 
6173446Smrj     switch (CommandIndex)
6183446Smrj     {
6193446Smrj     case CMD_NULL:
6203446Smrj         if (Op)
6213446Smrj         {
6223446Smrj             return (AE_OK);
6233446Smrj         }
6243446Smrj         break;
6253446Smrj 
6263446Smrj     case CMD_ALLOCATIONS:
6273446Smrj 
6283446Smrj #ifdef ACPI_DBG_TRACK_ALLOCATIONS
6293446Smrj         AcpiUtDumpAllocations ((UINT32) -1, NULL);
6303446Smrj #endif
6313446Smrj         break;
6323446Smrj 
6333446Smrj     case CMD_ARGS:
6343446Smrj     case CMD_ARGUMENTS:
6353446Smrj         AcpiDbDisplayArguments ();
6363446Smrj         break;
6373446Smrj 
6383446Smrj     case CMD_BREAKPOINT:
6393446Smrj         AcpiDbSetMethodBreakpoint (AcpiGbl_DbArgs[1], WalkState, Op);
6403446Smrj         break;
6413446Smrj 
6423446Smrj     case CMD_BUSINFO:
6433446Smrj         AcpiDbGetBusInfo ();
6443446Smrj         break;
6453446Smrj 
6463446Smrj     case CMD_CALL:
6473446Smrj         AcpiDbSetMethodCallBreakpoint (Op);
6483446Smrj         Status = AE_OK;
6493446Smrj         break;
6503446Smrj 
6513446Smrj     case CMD_CLOSE:
6523446Smrj         AcpiDbCloseDebugFile ();
6533446Smrj         break;
6543446Smrj 
6553446Smrj     case CMD_DEBUG:
6563446Smrj         AcpiDbExecute (AcpiGbl_DbArgs[1], &AcpiGbl_DbArgs[2], EX_SINGLE_STEP);
6573446Smrj         break;
6583446Smrj 
6593446Smrj     case CMD_DISASSEMBLE:
6603446Smrj         (void) AcpiDbDisassembleMethod (AcpiGbl_DbArgs[1]);
6613446Smrj         break;
6623446Smrj 
6633446Smrj     case CMD_DUMP:
6643446Smrj         AcpiDbDecodeAndDisplayObject (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
6653446Smrj         break;
6663446Smrj 
6673446Smrj     case CMD_ENABLEACPI:
6683446Smrj         Status = AcpiEnable();
6693446Smrj         if (ACPI_FAILURE(Status))
6703446Smrj         {
6713446Smrj             AcpiOsPrintf("AcpiEnable failed (Status=%X)\n", Status);
6723446Smrj             return (Status);
6733446Smrj         }
6743446Smrj         break;
6753446Smrj 
6763446Smrj     case CMD_EVENT:
6773446Smrj         AcpiOsPrintf ("Event command not implemented\n");
6783446Smrj         break;
6793446Smrj 
6803446Smrj     case CMD_EXECUTE:
6813446Smrj         AcpiDbExecute (AcpiGbl_DbArgs[1],
6823446Smrj             &AcpiGbl_DbArgs[2], EX_NO_SINGLE_STEP);
6833446Smrj         break;
6843446Smrj 
6853446Smrj     case CMD_FIND:
6863446Smrj         Status = AcpiDbFindNameInNamespace (AcpiGbl_DbArgs[1]);
6873446Smrj         break;
6883446Smrj 
6893446Smrj     case CMD_GO:
6903446Smrj         AcpiGbl_CmSingleStep = FALSE;
6913446Smrj         return (AE_OK);
6923446Smrj 
6933446Smrj     case CMD_GPE:
6943446Smrj         AcpiDbGenerateGpe (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
6953446Smrj         break;
6963446Smrj 
6973446Smrj     case CMD_GPES:
6983446Smrj         AcpiDbDisplayGpes ();
6993446Smrj         break;
7003446Smrj 
7013446Smrj     case CMD_HELP:
7023446Smrj     case CMD_HELP2:
7033446Smrj         AcpiDbDisplayHelp (AcpiGbl_DbArgs[1]);
7043446Smrj         break;
7053446Smrj 
7063446Smrj     case CMD_HISTORY:
7073446Smrj         AcpiDbDisplayHistory ();
7083446Smrj         break;
7093446Smrj 
7103446Smrj     case CMD_HISTORY_EXE:
7113446Smrj         CommandLine = AcpiDbGetFromHistory (AcpiGbl_DbArgs[1]);
7123446Smrj         if (!CommandLine)
7133446Smrj         {
7143446Smrj             return (AE_CTRL_TRUE);
7153446Smrj         }
7163446Smrj 
7173446Smrj         Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
7183446Smrj         return (Status);
7193446Smrj 
7203446Smrj     case CMD_HISTORY_LAST:
7213446Smrj         CommandLine = AcpiDbGetFromHistory (NULL);
7223446Smrj         if (!CommandLine)
7233446Smrj         {
7243446Smrj             return (AE_CTRL_TRUE);
7253446Smrj         }
7263446Smrj 
7273446Smrj         Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
7283446Smrj         return (Status);
7293446Smrj 
7303446Smrj     case CMD_INFORMATION:
7313446Smrj         AcpiDbDisplayMethodInfo (Op);
7323446Smrj         break;
7333446Smrj 
7343446Smrj     case CMD_INTEGRITY:
7353446Smrj         AcpiDbCheckIntegrity ();
7363446Smrj         break;
7373446Smrj 
7383446Smrj     case CMD_INTO:
7393446Smrj         if (Op)
7403446Smrj         {
7413446Smrj             AcpiGbl_CmSingleStep = TRUE;
7423446Smrj             return (AE_OK);
7433446Smrj         }
7443446Smrj         break;
7453446Smrj 
7463446Smrj     case CMD_LEVEL:
7473446Smrj         if (ParamCount == 0)
7483446Smrj         {
7493446Smrj             AcpiOsPrintf ("Current debug level for file output is:    %8.8lX\n",
7503446Smrj                 AcpiGbl_DbDebugLevel);
7513446Smrj             AcpiOsPrintf ("Current debug level for console output is: %8.8lX\n",
7523446Smrj                 AcpiGbl_DbConsoleDebugLevel);
7533446Smrj         }
7543446Smrj         else if (ParamCount == 2)
7553446Smrj         {
7563446Smrj             Temp = AcpiGbl_DbConsoleDebugLevel;
7573446Smrj             AcpiGbl_DbConsoleDebugLevel = ACPI_STRTOUL (AcpiGbl_DbArgs[1],
7583446Smrj                                             NULL, 16);
7593446Smrj             AcpiOsPrintf (
7603446Smrj                 "Debug Level for console output was %8.8lX, now %8.8lX\n",
7613446Smrj                 Temp, AcpiGbl_DbConsoleDebugLevel);
7623446Smrj         }
7633446Smrj         else
7643446Smrj         {
7653446Smrj             Temp = AcpiGbl_DbDebugLevel;
7663446Smrj             AcpiGbl_DbDebugLevel = ACPI_STRTOUL (AcpiGbl_DbArgs[1], NULL, 16);
7673446Smrj             AcpiOsPrintf (
7683446Smrj                 "Debug Level for file output was %8.8lX, now %8.8lX\n",
7693446Smrj                 Temp, AcpiGbl_DbDebugLevel);
7703446Smrj         }
7713446Smrj         break;
7723446Smrj 
7733446Smrj     case CMD_LIST:
7743446Smrj         AcpiDbDisassembleAml (AcpiGbl_DbArgs[1], Op);
7753446Smrj         break;
7763446Smrj 
7773446Smrj     case CMD_LOAD:
7783446Smrj         Status = AcpiDbGetTableFromFile (AcpiGbl_DbArgs[1], NULL);
7793446Smrj         break;
7803446Smrj 
7813446Smrj     case CMD_LOCKS:
7823446Smrj         AcpiDbDisplayLocks ();
7833446Smrj         break;
7843446Smrj 
7853446Smrj     case CMD_LOCALS:
7863446Smrj         AcpiDbDisplayLocals ();
7873446Smrj         break;
7883446Smrj 
7893446Smrj     case CMD_METHODS:
7903446Smrj         Status = AcpiDbDisplayObjects ("METHOD", AcpiGbl_DbArgs[1]);
7913446Smrj         break;
7923446Smrj 
7933446Smrj     case CMD_NAMESPACE:
7943446Smrj         AcpiDbDumpNamespace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
7953446Smrj         break;
7963446Smrj 
7973446Smrj     case CMD_NOTIFY:
7983446Smrj         Temp = ACPI_STRTOUL (AcpiGbl_DbArgs[2], NULL, 0);
7993446Smrj         AcpiDbSendNotify (AcpiGbl_DbArgs[1], Temp);
8003446Smrj         break;
8013446Smrj 
8023446Smrj     case CMD_OBJECT:
8033446Smrj         AcpiUtStrupr (AcpiGbl_DbArgs[1]);
8043446Smrj         Status = AcpiDbDisplayObjects (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
8053446Smrj         break;
8063446Smrj 
8073446Smrj     case CMD_OPEN:
8083446Smrj         AcpiDbOpenDebugFile (AcpiGbl_DbArgs[1]);
8093446Smrj         break;
8103446Smrj 
8113446Smrj     case CMD_OWNER:
8123446Smrj         AcpiDbDumpNamespaceByOwner (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
8133446Smrj         break;
8143446Smrj 
8153446Smrj     case CMD_PREFIX:
8163446Smrj         AcpiDbSetScope (AcpiGbl_DbArgs[1]);
8173446Smrj         break;
8183446Smrj 
8193446Smrj     case CMD_REFERENCES:
8203446Smrj         AcpiDbFindReferences (AcpiGbl_DbArgs[1]);
8213446Smrj         break;
8223446Smrj 
8233446Smrj     case CMD_RESOURCES:
8243446Smrj         AcpiDbDisplayResources (AcpiGbl_DbArgs[1]);
8253446Smrj         break;
8263446Smrj 
8273446Smrj     case CMD_RESULTS:
8283446Smrj         AcpiDbDisplayResults ();
8293446Smrj         break;
8303446Smrj 
8313446Smrj     case CMD_SET:
8323446Smrj         AcpiDbSetMethodData (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],
8333446Smrj             AcpiGbl_DbArgs[3]);
8343446Smrj         break;
8353446Smrj 
8363446Smrj     case CMD_SLEEP:
8373446Smrj         Status = AcpiDbSleep (AcpiGbl_DbArgs[1]);
8383446Smrj         break;
8393446Smrj 
8403446Smrj     case CMD_STATS:
8413446Smrj         Status = AcpiDbDisplayStatistics (AcpiGbl_DbArgs[1]);
8423446Smrj         break;
8433446Smrj 
8443446Smrj     case CMD_STOP:
8453446Smrj         return (AE_NOT_IMPLEMENTED);
8463446Smrj 
8473446Smrj     case CMD_TABLES:
8483446Smrj         AcpiDbDisplayTableInfo (AcpiGbl_DbArgs[1]);
8493446Smrj         break;
8503446Smrj 
8513446Smrj     case CMD_TERMINATE:
8523446Smrj         AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
8533446Smrj         AcpiUtSubsystemShutdown ();
8543446Smrj 
8553446Smrj         /*
8563446Smrj          * TBD: [Restructure] Need some way to re-initialize without
8573446Smrj          * re-creating the semaphores!
8583446Smrj          */
8593446Smrj 
8603446Smrj         /*  AcpiInitialize (NULL);  */
8613446Smrj         break;
8623446Smrj 
8633446Smrj     case CMD_THREADS:
8643446Smrj         AcpiDbCreateExecutionThreads (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],
8653446Smrj             AcpiGbl_DbArgs[3]);
8663446Smrj         break;
8673446Smrj 
8683446Smrj     case CMD_TRACE:
869*7851SDana.Myers@Sun.COM         (void) AcpiDebugTrace (AcpiGbl_DbArgs[1],0,0,1);
8703446Smrj         break;
8713446Smrj 
8723446Smrj     case CMD_TREE:
8733446Smrj         AcpiDbDisplayCallingTree ();
8743446Smrj         break;
8753446Smrj 
8763446Smrj     case CMD_TYPE:
8773446Smrj         AcpiDbDisplayObjectType (AcpiGbl_DbArgs[1]);
8783446Smrj         break;
8793446Smrj 
8803446Smrj     case CMD_UNLOAD:
8813446Smrj         AcpiDbUnloadAcpiTable (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
8823446Smrj         break;
8833446Smrj 
8843446Smrj     case CMD_EXIT:
8853446Smrj     case CMD_QUIT:
8863446Smrj         if (Op)
8873446Smrj         {
8883446Smrj             AcpiOsPrintf ("Method execution terminated\n");
8893446Smrj             return (AE_CTRL_TERMINATE);
8903446Smrj         }
8913446Smrj 
8923446Smrj         if (!AcpiGbl_DbOutputToFile)
8933446Smrj         {
8943446Smrj             AcpiDbgLevel = ACPI_DEBUG_DEFAULT;
8953446Smrj         }
8963446Smrj 
8973446Smrj         AcpiDbCloseDebugFile ();
8983446Smrj         AcpiGbl_DbTerminateThreads = TRUE;
8993446Smrj         return (AE_CTRL_TERMINATE);
9003446Smrj 
9013446Smrj     case CMD_NOT_FOUND:
9023446Smrj     default:
9033446Smrj         AcpiOsPrintf ("Unknown Command\n");
9043446Smrj         return (AE_CTRL_TRUE);
9053446Smrj     }
9063446Smrj 
9073446Smrj     if (ACPI_SUCCESS (Status))
9083446Smrj     {
9093446Smrj         Status = AE_CTRL_TRUE;
9103446Smrj     }
9113446Smrj 
9123446Smrj     /* Add all commands that come here to the history buffer */
9133446Smrj 
9143446Smrj     AcpiDbAddToHistory (InputBuffer);
9153446Smrj     return (Status);
9163446Smrj }
9173446Smrj 
9183446Smrj 
9193446Smrj /*******************************************************************************
9203446Smrj  *
9213446Smrj  * FUNCTION:    AcpiDbExecuteThread
9223446Smrj  *
9233446Smrj  * PARAMETERS:  Context         - Not used
9243446Smrj  *
9253446Smrj  * RETURN:      None
9263446Smrj  *
9273446Smrj  * DESCRIPTION: Debugger execute thread.  Waits for a command line, then
9283446Smrj  *              simply dispatches it.
9293446Smrj  *
9303446Smrj  ******************************************************************************/
9313446Smrj 
9323446Smrj void ACPI_SYSTEM_XFACE
9333446Smrj AcpiDbExecuteThread (
9343446Smrj     void                    *Context)
9353446Smrj {
9363446Smrj     ACPI_STATUS             Status = AE_OK;
9373446Smrj     ACPI_STATUS             MStatus;
9383446Smrj 
9393446Smrj 
9403446Smrj     while (Status != AE_CTRL_TERMINATE)
9413446Smrj     {
9423446Smrj         AcpiGbl_MethodExecuting = FALSE;
9433446Smrj         AcpiGbl_StepToNextCall = FALSE;
9443446Smrj 
9453446Smrj         MStatus = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY);
9463446Smrj         if (ACPI_FAILURE (MStatus))
9473446Smrj         {
9483446Smrj             return;
9493446Smrj         }
9503446Smrj 
9513446Smrj         Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
9523446Smrj 
9533446Smrj         MStatus = AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
9543446Smrj         if (ACPI_FAILURE (MStatus))
9553446Smrj         {
9563446Smrj             return;
9573446Smrj         }
9583446Smrj     }
9593446Smrj }
9603446Smrj 
9613446Smrj 
9623446Smrj /*******************************************************************************
9633446Smrj  *
9643446Smrj  * FUNCTION:    AcpiDbSingleThread
9653446Smrj  *
9663446Smrj  * PARAMETERS:  None
9673446Smrj  *
9683446Smrj  * RETURN:      None
9693446Smrj  *
9703446Smrj  * DESCRIPTION: Debugger execute thread.  Waits for a command line, then
9713446Smrj  *              simply dispatches it.
9723446Smrj  *
9733446Smrj  ******************************************************************************/
9743446Smrj 
9753446Smrj static void
9763446Smrj AcpiDbSingleThread (
9773446Smrj     void)
9783446Smrj {
9793446Smrj 
9803446Smrj     AcpiGbl_MethodExecuting = FALSE;
9813446Smrj     AcpiGbl_StepToNextCall = FALSE;
9823446Smrj 
9833446Smrj     (void) AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
9843446Smrj }
9853446Smrj 
9863446Smrj 
9873446Smrj /*******************************************************************************
9883446Smrj  *
9893446Smrj  * FUNCTION:    AcpiDbUserCommands
9903446Smrj  *
9913446Smrj  * PARAMETERS:  Prompt              - User prompt (depends on mode)
9923446Smrj  *              Op                  - Current executing parse op
9933446Smrj  *
9943446Smrj  * RETURN:      None
9953446Smrj  *
9963446Smrj  * DESCRIPTION: Command line execution for the AML debugger.  Commands are
9973446Smrj  *              matched and dispatched here.
9983446Smrj  *
9993446Smrj  ******************************************************************************/
10003446Smrj 
10013446Smrj ACPI_STATUS
10023446Smrj AcpiDbUserCommands (
10033446Smrj     char                    Prompt,
10043446Smrj     ACPI_PARSE_OBJECT       *Op)
10053446Smrj {
10063446Smrj     ACPI_STATUS             Status = AE_OK;
10073446Smrj 
10083446Smrj 
10093446Smrj     /* TBD: [Restructure] Need a separate command line buffer for step mode */
10103446Smrj 
10113446Smrj     while (!AcpiGbl_DbTerminateThreads)
10123446Smrj     {
10133446Smrj         /* Force output to console until a command is entered */
10143446Smrj 
10153446Smrj         AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
10163446Smrj 
10173446Smrj         /* Different prompt if method is executing */
10183446Smrj 
10193446Smrj         if (!AcpiGbl_MethodExecuting)
10203446Smrj         {
10213446Smrj             AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
10223446Smrj         }
10233446Smrj         else
10243446Smrj         {
10253446Smrj             AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
10263446Smrj         }
10273446Smrj 
10283446Smrj         /* Get the user input line */
10293446Smrj 
10303446Smrj         (void) AcpiOsGetLine (AcpiGbl_DbLineBuf);
10313446Smrj 
10323446Smrj         /* Check for single or multithreaded debug */
10333446Smrj 
10343446Smrj         if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
10353446Smrj         {
10363446Smrj             /*
10373446Smrj              * Signal the debug thread that we have a command to execute,
10383446Smrj              * and wait for the command to complete.
10393446Smrj              */
10403446Smrj             Status = AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_READY);
10413446Smrj             if (ACPI_FAILURE (Status))
10423446Smrj             {
10433446Smrj                 return (Status);
10443446Smrj             }
10453446Smrj 
10463446Smrj             Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
10473446Smrj             if (ACPI_FAILURE (Status))
10483446Smrj             {
10493446Smrj                 return (Status);
10503446Smrj             }
10513446Smrj         }
10523446Smrj         else
10533446Smrj         {
10543446Smrj             /* Just call to the command line interpreter */
10553446Smrj 
10563446Smrj             AcpiDbSingleThread ();
10573446Smrj         }
10583446Smrj     }
10593446Smrj 
10603446Smrj     /*
10613446Smrj      * Only this thread (the original thread) should actually terminate the
10623446Smrj      * subsystem, because all the semaphores are deleted during termination
10633446Smrj      */
10643446Smrj     Status = AcpiTerminate ();
10653446Smrj     return (Status);
10663446Smrj }
10673446Smrj 
10683446Smrj #endif  /* ACPI_DEBUGGER */
10693446Smrj 
1070