Subversion Repositories Kolibri OS

Rev

Rev 1498 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1498 serge 1
/*******************************************************************************
2
 *
3
 * Module Name: dbinput - user front-end to the AML debugger
4
 *
5
 ******************************************************************************/
6
 
7
/******************************************************************************
8
 *
9
 * 1. Copyright Notice
10
 *
2216 Serge 11
 * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
1498 serge 12
 * All rights reserved.
13
 *
14
 * 2. License
15
 *
16
 * 2.1. This is your license from Intel Corp. under its intellectual property
17
 * rights.  You may have additional license terms from the party that provided
18
 * you this software, covering your right to use that party's intellectual
19
 * property rights.
20
 *
21
 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22
 * copy of the source code appearing in this file ("Covered Code") an
23
 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24
 * base code distributed originally by Intel ("Original Intel Code") to copy,
25
 * make derivatives, distribute, use and display any portion of the Covered
26
 * Code in any form, with the right to sublicense such rights; and
27
 *
28
 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29
 * license (with the right to sublicense), under only those claims of Intel
30
 * patents that are infringed by the Original Intel Code, to make, use, sell,
31
 * offer to sell, and import the Covered Code and derivative works thereof
32
 * solely to the minimum extent necessary to exercise the above copyright
33
 * license, and in no event shall the patent license extend to any additions
34
 * to or modifications of the Original Intel Code.  No other license or right
35
 * is granted directly or by implication, estoppel or otherwise;
36
 *
37
 * The above copyright and patent license is granted only if the following
38
 * conditions are met:
39
 *
40
 * 3. Conditions
41
 *
42
 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43
 * Redistribution of source code of any substantial portion of the Covered
44
 * Code or modification with rights to further distribute source must include
45
 * the above Copyright Notice, the above License, this list of Conditions,
46
 * and the following Disclaimer and Export Compliance provision.  In addition,
47
 * Licensee must cause all Covered Code to which Licensee contributes to
48
 * contain a file documenting the changes Licensee made to create that Covered
49
 * Code and the date of any change.  Licensee must include in that file the
50
 * documentation of any changes made by any predecessor Licensee.  Licensee
51
 * must include a prominent statement that the modification is derived,
52
 * directly or indirectly, from Original Intel Code.
53
 *
54
 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55
 * Redistribution of source code of any substantial portion of the Covered
56
 * Code or modification without rights to further distribute source must
57
 * include the following Disclaimer and Export Compliance provision in the
58
 * documentation and/or other materials provided with distribution.  In
59
 * addition, Licensee may not authorize further sublicense of source of any
60
 * portion of the Covered Code, and must include terms to the effect that the
61
 * license from Licensee to its licensee is limited to the intellectual
62
 * property embodied in the software Licensee provides to its licensee, and
63
 * not to intellectual property embodied in modifications its licensee may
64
 * make.
65
 *
66
 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67
 * substantial portion of the Covered Code or modification must reproduce the
68
 * above Copyright Notice, and the following Disclaimer and Export Compliance
69
 * provision in the documentation and/or other materials provided with the
70
 * distribution.
71
 *
72
 * 3.4. Intel retains all right, title, and interest in and to the Original
73
 * Intel Code.
74
 *
75
 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76
 * Intel shall be used in advertising or otherwise to promote the sale, use or
77
 * other dealings in products derived from or relating to the Covered Code
78
 * without prior written authorization from Intel.
79
 *
80
 * 4. Disclaimer and Export Compliance
81
 *
82
 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83
 * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84
 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
85
 * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
86
 * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
87
 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88
 * PARTICULAR PURPOSE.
89
 *
90
 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91
 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92
 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93
 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94
 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95
 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
96
 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97
 * LIMITED REMEDY.
98
 *
99
 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100
 * software or system incorporating such software without first obtaining any
101
 * required license or other approval from the U. S. Department of Commerce or
102
 * any other agency or department of the United States Government.  In the
103
 * event Licensee exports any such software from the United States or
104
 * re-exports any such software from a foreign destination, Licensee shall
105
 * ensure that the distribution and export/re-export of the software is in
106
 * compliance with all laws, regulations, orders, or other restrictions of the
107
 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108
 * any of its subsidiaries will export/re-export any technical data, process,
109
 * software, or service, directly or indirectly, to any country for which the
110
 * United States government or any agency thereof requires an export license,
111
 * other governmental approval, or letter of assurance, without first obtaining
112
 * such license, approval or letter.
113
 *
114
 *****************************************************************************/
115
 
116
 
117
#include "acpi.h"
118
#include "accommon.h"
119
#include "acdebug.h"
120
 
121
 
122
#ifdef ACPI_DEBUGGER
123
 
124
#define _COMPONENT          ACPI_CA_DEBUGGER
125
        ACPI_MODULE_NAME    ("dbinput")
126
 
127
/* Local prototypes */
128
 
129
static UINT32
130
AcpiDbGetLine (
131
    char                    *InputBuffer);
132
 
133
static UINT32
134
AcpiDbMatchCommand (
135
    char                    *UserCommand);
136
 
137
static void
138
AcpiDbSingleThread (
139
    void);
140
 
141
static void
142
AcpiDbDisplayHelp (
2216 Serge 143
    void);
1498 serge 144
 
145
 
146
/*
147
 * Top-level debugger commands.
148
 *
149
 * This list of commands must match the string table below it
150
 */
151
enum AcpiExDebuggerCommands
152
{
153
    CMD_NOT_FOUND = 0,
154
    CMD_NULL,
155
    CMD_ALLOCATIONS,
156
    CMD_ARGS,
157
    CMD_ARGUMENTS,
158
    CMD_BATCH,
159
    CMD_BREAKPOINT,
160
    CMD_BUSINFO,
161
    CMD_CALL,
162
    CMD_CLOSE,
163
    CMD_DEBUG,
164
    CMD_DISASSEMBLE,
165
    CMD_DUMP,
166
    CMD_ENABLEACPI,
167
    CMD_EVENT,
168
    CMD_EXECUTE,
169
    CMD_EXIT,
170
    CMD_FIND,
171
    CMD_GO,
172
    CMD_GPE,
173
    CMD_GPES,
2216 Serge 174
    CMD_HANDLERS,
1498 serge 175
    CMD_HELP,
176
    CMD_HELP2,
177
    CMD_HISTORY,
178
    CMD_HISTORY_EXE,
179
    CMD_HISTORY_LAST,
180
    CMD_INFORMATION,
181
    CMD_INTEGRITY,
182
    CMD_INTO,
183
    CMD_LEVEL,
184
    CMD_LIST,
185
    CMD_LOAD,
186
    CMD_LOCALS,
187
    CMD_LOCKS,
188
    CMD_METHODS,
189
    CMD_NAMESPACE,
190
    CMD_NOTIFY,
191
    CMD_OBJECT,
192
    CMD_OPEN,
2216 Serge 193
    CMD_OSI,
1498 serge 194
    CMD_OWNER,
195
    CMD_PREDEFINED,
196
    CMD_PREFIX,
197
    CMD_QUIT,
198
    CMD_REFERENCES,
199
    CMD_RESOURCES,
200
    CMD_RESULTS,
201
    CMD_SET,
202
    CMD_SLEEP,
203
    CMD_STATS,
204
    CMD_STOP,
205
    CMD_TABLES,
206
    CMD_TERMINATE,
207
    CMD_THREADS,
208
    CMD_TRACE,
209
    CMD_TREE,
210
    CMD_TYPE,
211
    CMD_UNLOAD
212
};
213
 
214
#define CMD_FIRST_VALID     2
215
 
216
 
217
/* Second parameter is the required argument count */
218
 
219
static const COMMAND_INFO       AcpiGbl_DbCommands[] =
220
{
221
    {"",  0},
222
    {"",       0},
223
    {"ALLOCATIONS",  0},
224
    {"ARGS",         0},
225
    {"ARGUMENTS",    0},
226
    {"BATCH",        0},
227
    {"BREAKPOINT",   1},
228
    {"BUSINFO",      0},
229
    {"CALL",         0},
230
    {"CLOSE",        0},
231
    {"DEBUG",        1},
232
    {"DISASSEMBLE",  1},
233
    {"DUMP",         1},
234
    {"ENABLEACPI",   0},
235
    {"EVENT",        1},
236
    {"EXECUTE",      1},
237
    {"EXIT",         0},
238
    {"FIND",         1},
239
    {"GO",           0},
240
    {"GPE",          2},
241
    {"GPES",         0},
2216 Serge 242
    {"HANDLERS",     0},
1498 serge 243
    {"HELP",         0},
244
    {"?",            0},
245
    {"HISTORY",      0},
246
    {"!",            1},
247
    {"!!",           0},
248
    {"INFORMATION",  0},
249
    {"INTEGRITY",    0},
250
    {"INTO",         0},
251
    {"LEVEL",        0},
252
    {"LIST",         0},
253
    {"LOAD",         1},
254
    {"LOCALS",       0},
255
    {"LOCKS",        0},
256
    {"METHODS",      0},
257
    {"NAMESPACE",    0},
258
    {"NOTIFY",       2},
259
    {"OBJECT",       1},
260
    {"OPEN",         1},
2216 Serge 261
    {"OSI",          0},
1498 serge 262
    {"OWNER",        1},
263
    {"PREDEFINED",   0},
264
    {"PREFIX",       0},
265
    {"QUIT",         0},
266
    {"REFERENCES",   1},
267
    {"RESOURCES",    1},
268
    {"RESULTS",      0},
269
    {"SET",          3},
270
    {"SLEEP",        1},
271
    {"STATS",        0},
272
    {"STOP",         0},
273
    {"TABLES",       0},
274
    {"TERMINATE",    0},
275
    {"THREADS",      3},
276
    {"TRACE",        1},
277
    {"TREE",         0},
278
    {"TYPE",         1},
279
    {"UNLOAD",       1},
280
    {NULL,           0}
281
};
282
 
283
 
284
/*******************************************************************************
285
 *
286
 * FUNCTION:    AcpiDbDisplayHelp
287
 *
2216 Serge 288
 * PARAMETERS:  None
1498 serge 289
 *
290
 * RETURN:      None
291
 *
292
 * DESCRIPTION: Print a usage message.
293
 *
294
 ******************************************************************************/
295
 
296
static void
297
AcpiDbDisplayHelp (
2216 Serge 298
    void)
1498 serge 299
{
300
 
2216 Serge 301
    AcpiOsPrintf ("\nGeneral-Purpose Commands:\n");
302
    AcpiOsPrintf ("  Allocations                         Display list of current memory allocations\n");
303
    AcpiOsPrintf ("  Dump 
|\n");
304
    AcpiOsPrintf ("       [Byte|Word|Dword|Qword]        Display ACPI objects or memory\n");
305
    AcpiOsPrintf ("  EnableAcpi                          Enable ACPI (hardware) mode\n");
306
    AcpiOsPrintf ("  Handlers                            Info about global handlers\n");
307
    AcpiOsPrintf ("  Help                                This help screen\n");
308
    AcpiOsPrintf ("  History                             Display command history buffer\n");
309
    AcpiOsPrintf ("  Level [] [console]      Get/Set debug level for file or console\n");
310
    AcpiOsPrintf ("  Locks                               Current status of internal mutexes\n");
311
    AcpiOsPrintf ("  Osi [Install|Remove ]         Display or modify global _OSI list\n");
312
    AcpiOsPrintf ("  Quit or Exit                        Exit this command\n");
313
    AcpiOsPrintf ("  Stats [Allocations|Memory|Misc|\n");
314
    AcpiOsPrintf ("        Objects|Sizes|Stack|Tables]   Display namespace and memory statistics\n");
315
    AcpiOsPrintf ("     Allocations                      Display list of current memory allocations\n");
316
    AcpiOsPrintf ("     Memory                           Dump internal memory lists\n");
317
    AcpiOsPrintf ("     Misc                             Namespace search and mutex stats\n");
318
    AcpiOsPrintf ("     Objects                          Summary of namespace objects\n");
319
    AcpiOsPrintf ("     Sizes                            Sizes for each of the internal objects\n");
320
    AcpiOsPrintf ("     Stack                            Display CPU stack usage\n");
321
    AcpiOsPrintf ("     Tables                           Info about current ACPI table(s)\n");
322
    AcpiOsPrintf ("  Tables                              Display info about loaded ACPI tables\n");
323
    AcpiOsPrintf ("  Unload  [Instance]        Unload an ACPI table\n");
324
    AcpiOsPrintf ("  !                    Execute command from history buffer\n");
325
    AcpiOsPrintf ("  !!                                  Execute last command again\n");
1498 serge 326
 
2216 Serge 327
    AcpiOsPrintf ("\nNamespace Access Commands:\n");
328
    AcpiOsPrintf ("  Businfo                             Display system bus info\n");
329
    AcpiOsPrintf ("  Disassemble                 Disassemble a control method\n");
330
    AcpiOsPrintf ("  Event                   Generate AcpiEvent (Fixed/GPE)\n");
331
    AcpiOsPrintf ("  Find   (? is wildcard)    Find ACPI name(s) with wildcards\n");
332
    AcpiOsPrintf ("  Gpe               Simulate a GPE\n");
333
    AcpiOsPrintf ("  Gpes                                Display info on all GPEs\n");
334
    AcpiOsPrintf ("  Integrity                           Validate namespace integrity\n");
335
    AcpiOsPrintf ("  Methods                             Display list of loaded control methods\n");
336
    AcpiOsPrintf ("  Namespace [Object] [Depth]          Display loaded namespace tree/subtree\n");
337
    AcpiOsPrintf ("  Notify               Send a notification on Object\n");
338
    AcpiOsPrintf ("  Objects                 Display all objects of the given type\n");
339
    AcpiOsPrintf ("  Owner  [Depth]             Display loaded namespace by object owner\n");
340
    AcpiOsPrintf ("  Predefined                          Check all predefined names\n");
341
    AcpiOsPrintf ("  Prefix []                 Set or Get current execution prefix\n");
342
    AcpiOsPrintf ("  References                    Find all references to object at addr\n");
343
    AcpiOsPrintf ("  Resources                   Get and display Device resources\n");
344
    AcpiOsPrintf ("  Set N           Set value for named integer\n");
345
    AcpiOsPrintf ("  Sleep                   Simulate sleep/wake sequence\n");
346
    AcpiOsPrintf ("  Terminate                           Delete namespace and all internal objects\n");
347
    AcpiOsPrintf ("  Type                        Display object type\n");
1498 serge 348
 
2216 Serge 349
    AcpiOsPrintf ("\nControl Method Execution Commands:\n");
350
    AcpiOsPrintf ("  Arguments (or Args)                 Display method arguments\n");
351
    AcpiOsPrintf ("  Breakpoint               Set an AML execution breakpoint\n");
352
    AcpiOsPrintf ("  Call                                Run to next control method invocation\n");
353
    AcpiOsPrintf ("  Debug  [Arguments]        Single Step a control method\n");
354
    AcpiOsPrintf ("  Execute  [Arguments]      Execute control method\n");
355
    AcpiOsPrintf ("     Hex Integer                      Integer method argument\n");
356
    AcpiOsPrintf ("     \"Ascii String\"                   String method argument\n");
357
    AcpiOsPrintf ("     (Byte List)                      Buffer method argument\n");
358
    AcpiOsPrintf ("     [Package Element List]           Package method argument\n");
359
    AcpiOsPrintf ("  Go                                  Allow method to run to completion\n");
360
    AcpiOsPrintf ("  Information                         Display info about the current method\n");
361
    AcpiOsPrintf ("  Into                                Step into (not over) a method call\n");
362
    AcpiOsPrintf ("  List [# of Aml Opcodes]             Display method ASL statements\n");
363
    AcpiOsPrintf ("  Locals                              Display method local variables\n");
364
    AcpiOsPrintf ("  Results                             Display method result stack\n");
365
    AcpiOsPrintf ("  Set  <#>                Set method data (Arguments/Locals)\n");
366
    AcpiOsPrintf ("  Stop                                Terminate control method\n");
367
    AcpiOsPrintf ("  Thread    Spawn threads to execute method(s)\n");
368
    AcpiOsPrintf ("  Trace                  Trace method execution\n");
369
    AcpiOsPrintf ("  Tree                                Display control method calling tree\n");
370
    AcpiOsPrintf ("                               Single step next AML opcode (over calls)\n");
1498 serge 371
 
2216 Serge 372
    AcpiOsPrintf ("\nFile I/O Commands:\n");
373
    AcpiOsPrintf ("  Close                               Close debug output file\n");
374
    AcpiOsPrintf ("  Load                Load ACPI table from a file\n");
375
    AcpiOsPrintf ("  Open               Open a file for debug output\n");
1498 serge 376
}
377
 
378
 
379
/*******************************************************************************
380
 *
381
 * FUNCTION:    AcpiDbGetNextToken
382
 *
383
 * PARAMETERS:  String          - Command buffer
384
 *              Next            - Return value, end of next token
385
 *
386
 * RETURN:      Pointer to the start of the next token.
387
 *
388
 * DESCRIPTION: Command line parsing.  Get the next token on the command line
389
 *
390
 ******************************************************************************/
391
 
2216 Serge 392
char *
1498 serge 393
AcpiDbGetNextToken (
394
    char                    *String,
2216 Serge 395
    char                    **Next,
396
    ACPI_OBJECT_TYPE        *ReturnType)
1498 serge 397
{
398
    char                    *Start;
2216 Serge 399
    UINT32                  Depth;
400
    ACPI_OBJECT_TYPE        Type = ACPI_TYPE_INTEGER;
1498 serge 401
 
402
 
403
    /* At end of buffer? */
404
 
405
    if (!String || !(*String))
406
    {
407
        return (NULL);
408
    }
409
 
2216 Serge 410
    /* Remove any spaces at the beginning */
1498 serge 411
 
412
    if (*String == ' ')
413
    {
414
        while (*String && (*String == ' '))
415
        {
416
            String++;
417
        }
418
 
419
        if (!(*String))
420
        {
421
            return (NULL);
422
        }
423
    }
424
 
2216 Serge 425
    switch (*String)
426
    {
427
    case '"':
1498 serge 428
 
2216 Serge 429
        /* This is a quoted string, scan until closing quote */
1498 serge 430
 
431
        String++;
2216 Serge 432
        Start = String;
433
        Type = ACPI_TYPE_STRING;
434
 
435
        /* Find end of string */
436
 
437
        while (*String && (*String != '"'))
438
        {
439
            String++;
440
        }
441
        break;
442
 
443
    case '(':
444
 
445
        /* This is the start of a buffer, scan until closing paren */
446
 
447
        String++;
448
        Start = String;
449
        Type = ACPI_TYPE_BUFFER;
450
 
451
        /* Find end of buffer */
452
 
453
        while (*String && (*String != ')'))
454
        {
455
            String++;
456
        }
457
        break;
458
 
459
    case '[':
460
 
461
        /* This is the start of a package, scan until closing bracket */
462
 
463
        String++;
464
        Depth = 1;
465
        Start = String;
466
        Type = ACPI_TYPE_PACKAGE;
467
 
468
        /* Find end of package (closing bracket) */
469
 
470
        while (*String)
471
        {
472
            /* Handle String package elements */
473
 
474
            if (*String == '"')
475
            {
476
                /* Find end of string */
477
 
478
                String++;
479
                while (*String && (*String != '"'))
480
                {
481
                    String++;
482
                }
483
                if (!(*String))
484
                {
485
                    break;
486
                }
487
            }
488
            else if (*String == '[')
489
            {
490
                Depth++;         /* A nested package declaration */
491
            }
492
            else if (*String == ']')
493
            {
494
                Depth--;
495
                if (Depth == 0) /* Found final package closing bracket */
496
                {
497
                    break;
498
                }
499
            }
500
 
501
            String++;
502
        }
503
        break;
504
 
505
    default:
506
 
507
        Start = String;
508
 
509
        /* Find end of token */
510
 
511
        while (*String && (*String != ' '))
512
        {
513
            String++;
514
        }
515
        break;
1498 serge 516
    }
517
 
518
    if (!(*String))
519
    {
520
        *Next = NULL;
521
    }
522
    else
523
    {
524
        *String = 0;
525
        *Next = String + 1;
526
    }
527
 
2216 Serge 528
    *ReturnType = Type;
1498 serge 529
    return (Start);
530
}
531
 
532
 
533
/*******************************************************************************
534
 *
535
 * FUNCTION:    AcpiDbGetLine
536
 *
537
 * PARAMETERS:  InputBuffer         - Command line buffer
538
 *
539
 * RETURN:      Count of arguments to the command
540
 *
541
 * DESCRIPTION: Get the next command line from the user.  Gets entire line
542
 *              up to the next newline
543
 *
544
 ******************************************************************************/
545
 
546
static UINT32
547
AcpiDbGetLine (
548
    char                    *InputBuffer)
549
{
550
    UINT32                  i;
551
    UINT32                  Count;
552
    char                    *Next;
553
    char                    *This;
554
 
555
 
556
    ACPI_STRCPY (AcpiGbl_DbParsedBuf, InputBuffer);
557
 
558
    This = AcpiGbl_DbParsedBuf;
559
    for (i = 0; i < ACPI_DEBUGGER_MAX_ARGS; i++)
560
    {
2216 Serge 561
        AcpiGbl_DbArgs[i] = AcpiDbGetNextToken (This, &Next,
562
            &AcpiGbl_DbArgTypes[i]);
1498 serge 563
        if (!AcpiGbl_DbArgs[i])
564
        {
565
            break;
566
        }
567
 
568
        This = Next;
569
    }
570
 
571
    /* Uppercase the actual command */
572
 
573
    if (AcpiGbl_DbArgs[0])
574
    {
575
        AcpiUtStrupr (AcpiGbl_DbArgs[0]);
576
    }
577
 
578
    Count = i;
579
    if (Count)
580
    {
581
        Count--;  /* Number of args only */
582
    }
583
 
584
    return (Count);
585
}
586
 
587
 
588
/*******************************************************************************
589
 *
590
 * FUNCTION:    AcpiDbMatchCommand
591
 *
592
 * PARAMETERS:  UserCommand             - User command line
593
 *
594
 * RETURN:      Index into command array, -1 if not found
595
 *
596
 * DESCRIPTION: Search command array for a command match
597
 *
598
 ******************************************************************************/
599
 
600
static UINT32
601
AcpiDbMatchCommand (
602
    char                    *UserCommand)
603
{
604
    UINT32                  i;
605
 
606
 
607
    if (!UserCommand || UserCommand[0] == 0)
608
    {
609
        return (CMD_NULL);
610
    }
611
 
612
    for (i = CMD_FIRST_VALID; AcpiGbl_DbCommands[i].Name; i++)
613
    {
614
        if (ACPI_STRSTR (AcpiGbl_DbCommands[i].Name, UserCommand) ==
615
                         AcpiGbl_DbCommands[i].Name)
616
        {
617
            return (i);
618
        }
619
    }
620
 
621
    /* Command not recognized */
622
 
623
    return (CMD_NOT_FOUND);
624
}
625
 
626
 
627
/*******************************************************************************
628
 *
629
 * FUNCTION:    AcpiDbCommandDispatch
630
 *
631
 * PARAMETERS:  InputBuffer         - Command line buffer
632
 *              WalkState           - Current walk
633
 *              Op                  - Current (executing) parse op
634
 *
635
 * RETURN:      Status
636
 *
637
 * DESCRIPTION: Command dispatcher.
638
 *
639
 ******************************************************************************/
640
 
641
ACPI_STATUS
642
AcpiDbCommandDispatch (
643
    char                    *InputBuffer,
644
    ACPI_WALK_STATE         *WalkState,
645
    ACPI_PARSE_OBJECT       *Op)
646
{
647
    UINT32                  Temp;
648
    UINT32                  CommandIndex;
649
    UINT32                  ParamCount;
650
    char                    *CommandLine;
651
    ACPI_STATUS             Status = AE_CTRL_TRUE;
652
 
653
 
654
    /* If AcpiTerminate has been called, terminate this thread */
655
 
656
    if (AcpiGbl_DbTerminateThreads)
657
    {
658
        return (AE_CTRL_TERMINATE);
659
    }
660
 
661
    ParamCount = AcpiDbGetLine (InputBuffer);
662
    CommandIndex = AcpiDbMatchCommand (AcpiGbl_DbArgs[0]);
663
    Temp = 0;
664
 
665
    /* Verify that we have the minimum number of params */
666
 
667
    if (ParamCount < AcpiGbl_DbCommands[CommandIndex].MinArgs)
668
    {
669
        AcpiOsPrintf ("%u parameters entered, [%s] requires %u parameters\n",
670
            ParamCount, AcpiGbl_DbCommands[CommandIndex].Name,
671
            AcpiGbl_DbCommands[CommandIndex].MinArgs);
672
 
673
        return (AE_CTRL_TRUE);
674
    }
675
 
676
    /* Decode and dispatch the command */
677
 
678
    switch (CommandIndex)
679
    {
680
    case CMD_NULL:
681
        if (Op)
682
        {
683
            return (AE_OK);
684
        }
685
        break;
686
 
687
    case CMD_ALLOCATIONS:
688
 
689
#ifdef ACPI_DBG_TRACK_ALLOCATIONS
690
        AcpiUtDumpAllocations ((UINT32) -1, NULL);
691
#endif
692
        break;
693
 
694
    case CMD_ARGS:
695
    case CMD_ARGUMENTS:
696
        AcpiDbDisplayArguments ();
697
        break;
698
 
699
    case CMD_BATCH:
700
        AcpiDbBatchExecute (AcpiGbl_DbArgs[1]);
701
        break;
702
 
703
    case CMD_BREAKPOINT:
704
        AcpiDbSetMethodBreakpoint (AcpiGbl_DbArgs[1], WalkState, Op);
705
        break;
706
 
707
    case CMD_BUSINFO:
708
        AcpiDbGetBusInfo ();
709
        break;
710
 
711
    case CMD_CALL:
712
        AcpiDbSetMethodCallBreakpoint (Op);
713
        Status = AE_OK;
714
        break;
715
 
716
    case CMD_CLOSE:
717
        AcpiDbCloseDebugFile ();
718
        break;
719
 
720
    case CMD_DEBUG:
2216 Serge 721
        AcpiDbExecute (AcpiGbl_DbArgs[1],
722
            &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_SINGLE_STEP);
1498 serge 723
        break;
724
 
725
    case CMD_DISASSEMBLE:
726
        (void) AcpiDbDisassembleMethod (AcpiGbl_DbArgs[1]);
727
        break;
728
 
729
    case CMD_DUMP:
730
        AcpiDbDecodeAndDisplayObject (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
731
        break;
732
 
733
    case CMD_ENABLEACPI:
734
        Status = AcpiEnable();
735
        if (ACPI_FAILURE(Status))
736
        {
737
            AcpiOsPrintf("AcpiEnable failed (Status=%X)\n", Status);
738
            return (Status);
739
        }
740
        break;
741
 
742
    case CMD_EVENT:
743
        AcpiOsPrintf ("Event command not implemented\n");
744
        break;
745
 
746
    case CMD_EXECUTE:
747
        AcpiDbExecute (AcpiGbl_DbArgs[1],
2216 Serge 748
            &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_NO_SINGLE_STEP);
1498 serge 749
        break;
750
 
751
    case CMD_FIND:
752
        Status = AcpiDbFindNameInNamespace (AcpiGbl_DbArgs[1]);
753
        break;
754
 
755
    case CMD_GO:
756
        AcpiGbl_CmSingleStep = FALSE;
757
        return (AE_OK);
758
 
759
    case CMD_GPE:
760
        AcpiDbGenerateGpe (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
761
        break;
762
 
763
    case CMD_GPES:
764
        AcpiDbDisplayGpes ();
765
        break;
766
 
2216 Serge 767
    case CMD_HANDLERS:
768
        AcpiDbDisplayHandlers ();
769
        break;
770
 
1498 serge 771
    case CMD_HELP:
772
    case CMD_HELP2:
2216 Serge 773
        AcpiDbDisplayHelp ();
1498 serge 774
        break;
775
 
776
    case CMD_HISTORY:
777
        AcpiDbDisplayHistory ();
778
        break;
779
 
780
    case CMD_HISTORY_EXE:
781
        CommandLine = AcpiDbGetFromHistory (AcpiGbl_DbArgs[1]);
782
        if (!CommandLine)
783
        {
784
            return (AE_CTRL_TRUE);
785
        }
786
 
787
        Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
788
        return (Status);
789
 
790
    case CMD_HISTORY_LAST:
791
        CommandLine = AcpiDbGetFromHistory (NULL);
792
        if (!CommandLine)
793
        {
794
            return (AE_CTRL_TRUE);
795
        }
796
 
797
        Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
798
        return (Status);
799
 
800
    case CMD_INFORMATION:
801
        AcpiDbDisplayMethodInfo (Op);
802
        break;
803
 
804
    case CMD_INTEGRITY:
805
        AcpiDbCheckIntegrity ();
806
        break;
807
 
808
    case CMD_INTO:
809
        if (Op)
810
        {
811
            AcpiGbl_CmSingleStep = TRUE;
812
            return (AE_OK);
813
        }
814
        break;
815
 
816
    case CMD_LEVEL:
817
        if (ParamCount == 0)
818
        {
819
            AcpiOsPrintf ("Current debug level for file output is:    %8.8lX\n",
820
                AcpiGbl_DbDebugLevel);
821
            AcpiOsPrintf ("Current debug level for console output is: %8.8lX\n",
822
                AcpiGbl_DbConsoleDebugLevel);
823
        }
824
        else if (ParamCount == 2)
825
        {
826
            Temp = AcpiGbl_DbConsoleDebugLevel;
827
            AcpiGbl_DbConsoleDebugLevel = ACPI_STRTOUL (AcpiGbl_DbArgs[1],
828
                                            NULL, 16);
829
            AcpiOsPrintf (
830
                "Debug Level for console output was %8.8lX, now %8.8lX\n",
831
                Temp, AcpiGbl_DbConsoleDebugLevel);
832
        }
833
        else
834
        {
835
            Temp = AcpiGbl_DbDebugLevel;
836
            AcpiGbl_DbDebugLevel = ACPI_STRTOUL (AcpiGbl_DbArgs[1], NULL, 16);
837
            AcpiOsPrintf (
838
                "Debug Level for file output was %8.8lX, now %8.8lX\n",
839
                Temp, AcpiGbl_DbDebugLevel);
840
        }
841
        break;
842
 
843
    case CMD_LIST:
844
        AcpiDbDisassembleAml (AcpiGbl_DbArgs[1], Op);
845
        break;
846
 
847
    case CMD_LOAD:
848
        Status = AcpiDbGetTableFromFile (AcpiGbl_DbArgs[1], NULL);
849
        break;
850
 
851
    case CMD_LOCKS:
852
        AcpiDbDisplayLocks ();
853
        break;
854
 
855
    case CMD_LOCALS:
856
        AcpiDbDisplayLocals ();
857
        break;
858
 
859
    case CMD_METHODS:
860
        Status = AcpiDbDisplayObjects ("METHOD", AcpiGbl_DbArgs[1]);
861
        break;
862
 
863
    case CMD_NAMESPACE:
864
        AcpiDbDumpNamespace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
865
        break;
866
 
867
    case CMD_NOTIFY:
868
        Temp = ACPI_STRTOUL (AcpiGbl_DbArgs[2], NULL, 0);
869
        AcpiDbSendNotify (AcpiGbl_DbArgs[1], Temp);
870
        break;
871
 
872
    case CMD_OBJECT:
873
        AcpiUtStrupr (AcpiGbl_DbArgs[1]);
874
        Status = AcpiDbDisplayObjects (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
875
        break;
876
 
877
    case CMD_OPEN:
878
        AcpiDbOpenDebugFile (AcpiGbl_DbArgs[1]);
879
        break;
880
 
2216 Serge 881
    case CMD_OSI:
882
        AcpiDbDisplayInterfaces (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
883
        break;
884
 
1498 serge 885
    case CMD_OWNER:
886
        AcpiDbDumpNamespaceByOwner (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
887
        break;
888
 
889
    case CMD_PREDEFINED:
890
        AcpiDbCheckPredefinedNames ();
891
        break;
892
 
893
    case CMD_PREFIX:
894
        AcpiDbSetScope (AcpiGbl_DbArgs[1]);
895
        break;
896
 
897
    case CMD_REFERENCES:
898
        AcpiDbFindReferences (AcpiGbl_DbArgs[1]);
899
        break;
900
 
901
    case CMD_RESOURCES:
902
        AcpiDbDisplayResources (AcpiGbl_DbArgs[1]);
903
        break;
904
 
905
    case CMD_RESULTS:
906
        AcpiDbDisplayResults ();
907
        break;
908
 
909
    case CMD_SET:
910
        AcpiDbSetMethodData (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],
911
            AcpiGbl_DbArgs[3]);
912
        break;
913
 
914
    case CMD_SLEEP:
915
        Status = AcpiDbSleep (AcpiGbl_DbArgs[1]);
916
        break;
917
 
918
    case CMD_STATS:
919
        Status = AcpiDbDisplayStatistics (AcpiGbl_DbArgs[1]);
920
        break;
921
 
922
    case CMD_STOP:
923
        return (AE_NOT_IMPLEMENTED);
924
 
925
    case CMD_TABLES:
926
        AcpiDbDisplayTableInfo (AcpiGbl_DbArgs[1]);
927
        break;
928
 
929
    case CMD_TERMINATE:
930
        AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
931
        AcpiUtSubsystemShutdown ();
932
 
933
        /*
934
         * TBD: [Restructure] Need some way to re-initialize without
935
         * re-creating the semaphores!
936
         */
937
 
938
        /*  AcpiInitialize (NULL);  */
939
        break;
940
 
941
    case CMD_THREADS:
942
        AcpiDbCreateExecutionThreads (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],
943
            AcpiGbl_DbArgs[3]);
944
        break;
945
 
946
    case CMD_TRACE:
947
        (void) AcpiDebugTrace (AcpiGbl_DbArgs[1],0,0,1);
948
        break;
949
 
950
    case CMD_TREE:
951
        AcpiDbDisplayCallingTree ();
952
        break;
953
 
954
    case CMD_TYPE:
955
        AcpiDbDisplayObjectType (AcpiGbl_DbArgs[1]);
956
        break;
957
 
958
    case CMD_UNLOAD:
959
        AcpiDbUnloadAcpiTable (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
960
        break;
961
 
962
    case CMD_EXIT:
963
    case CMD_QUIT:
964
        if (Op)
965
        {
966
            AcpiOsPrintf ("Method execution terminated\n");
967
            return (AE_CTRL_TERMINATE);
968
        }
969
 
970
        if (!AcpiGbl_DbOutputToFile)
971
        {
972
            AcpiDbgLevel = ACPI_DEBUG_DEFAULT;
973
        }
974
 
975
        AcpiDbCloseDebugFile ();
976
        AcpiGbl_DbTerminateThreads = TRUE;
977
        return (AE_CTRL_TERMINATE);
978
 
979
    case CMD_NOT_FOUND:
980
    default:
981
        AcpiOsPrintf ("Unknown Command\n");
982
        return (AE_CTRL_TRUE);
983
    }
984
 
985
    if (ACPI_SUCCESS (Status))
986
    {
987
        Status = AE_CTRL_TRUE;
988
    }
989
 
990
    /* Add all commands that come here to the history buffer */
991
 
992
    AcpiDbAddToHistory (InputBuffer);
993
    return (Status);
994
}
995
 
996
 
997
/*******************************************************************************
998
 *
999
 * FUNCTION:    AcpiDbExecuteThread
1000
 *
1001
 * PARAMETERS:  Context         - Not used
1002
 *
1003
 * RETURN:      None
1004
 *
1005
 * DESCRIPTION: Debugger execute thread.  Waits for a command line, then
1006
 *              simply dispatches it.
1007
 *
1008
 ******************************************************************************/
1009
 
1010
void ACPI_SYSTEM_XFACE
1011
AcpiDbExecuteThread (
1012
    void                    *Context)
1013
{
1014
    ACPI_STATUS             Status = AE_OK;
1015
    ACPI_STATUS             MStatus;
1016
 
1017
 
1018
    while (Status != AE_CTRL_TERMINATE)
1019
    {
1020
        AcpiGbl_MethodExecuting = FALSE;
1021
        AcpiGbl_StepToNextCall = FALSE;
1022
 
1023
        MStatus = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY);
1024
        if (ACPI_FAILURE (MStatus))
1025
        {
1026
            return;
1027
        }
1028
 
1029
        Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
1030
 
1031
        MStatus = AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
1032
        if (ACPI_FAILURE (MStatus))
1033
        {
1034
            return;
1035
        }
1036
    }
1037
}
1038
 
1039
 
1040
/*******************************************************************************
1041
 *
1042
 * FUNCTION:    AcpiDbSingleThread
1043
 *
1044
 * PARAMETERS:  None
1045
 *
1046
 * RETURN:      None
1047
 *
1048
 * DESCRIPTION: Debugger execute thread.  Waits for a command line, then
1049
 *              simply dispatches it.
1050
 *
1051
 ******************************************************************************/
1052
 
1053
static void
1054
AcpiDbSingleThread (
1055
    void)
1056
{
1057
 
1058
    AcpiGbl_MethodExecuting = FALSE;
1059
    AcpiGbl_StepToNextCall = FALSE;
1060
 
1061
    (void) AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
1062
}
1063
 
1064
 
1065
/*******************************************************************************
1066
 *
1067
 * FUNCTION:    AcpiDbUserCommands
1068
 *
1069
 * PARAMETERS:  Prompt              - User prompt (depends on mode)
1070
 *              Op                  - Current executing parse op
1071
 *
1072
 * RETURN:      None
1073
 *
1074
 * DESCRIPTION: Command line execution for the AML debugger.  Commands are
1075
 *              matched and dispatched here.
1076
 *
1077
 ******************************************************************************/
1078
 
1079
ACPI_STATUS
1080
AcpiDbUserCommands (
1081
    char                    Prompt,
1082
    ACPI_PARSE_OBJECT       *Op)
1083
{
1084
    ACPI_STATUS             Status = AE_OK;
1085
 
1086
 
1087
    /* TBD: [Restructure] Need a separate command line buffer for step mode */
1088
 
1089
    while (!AcpiGbl_DbTerminateThreads)
1090
    {
1091
        /* Force output to console until a command is entered */
1092
 
1093
        AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
1094
 
1095
        /* Different prompt if method is executing */
1096
 
1097
        if (!AcpiGbl_MethodExecuting)
1098
        {
1099
            AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
1100
        }
1101
        else
1102
        {
1103
            AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
1104
        }
1105
 
1106
        /* Get the user input line */
1107
 
2216 Serge 1108
        Status = AcpiOsGetLine (AcpiGbl_DbLineBuf,
1109
            ACPI_DB_LINE_BUFFER_SIZE, NULL);
1110
        if (ACPI_FAILURE (Status))
1111
        {
1112
            ACPI_EXCEPTION ((AE_INFO, Status, "While parsing command line"));
1113
            return (Status);
1114
        }
1498 serge 1115
 
1116
        /* Check for single or multithreaded debug */
1117
 
1118
        if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
1119
        {
1120
            /*
1121
             * Signal the debug thread that we have a command to execute,
1122
             * and wait for the command to complete.
1123
             */
1124
            Status = AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_READY);
1125
            if (ACPI_FAILURE (Status))
1126
            {
1127
                return (Status);
1128
            }
1129
 
1130
            Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
1131
            if (ACPI_FAILURE (Status))
1132
            {
1133
                return (Status);
1134
            }
1135
        }
1136
        else
1137
        {
1138
            /* Just call to the command line interpreter */
1139
 
1140
            AcpiDbSingleThread ();
1141
        }
1142
    }
1143
 
1144
    /*
1145
     * Only this thread (the original thread) should actually terminate the
1146
     * subsystem, because all the semaphores are deleted during termination
1147
     */
1148
    Status = AcpiTerminate ();
1149
    return (Status);
1150
}
1151
 
1152
#endif  /* ACPI_DEBUGGER */
1153