dbinput.c revision 1.9 1 /*******************************************************************************
2 *
3 * Module Name: dbinput - user front-end to the AML debugger
4 *
5 ******************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2015, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44 #include "acpi.h"
45 #include "accommon.h"
46 #include "acdebug.h"
47
48
49 #ifdef ACPI_DEBUGGER
50
51 #define _COMPONENT ACPI_CA_DEBUGGER
52 ACPI_MODULE_NAME ("dbinput")
53
54 /* Local prototypes */
55
56 static UINT32
57 AcpiDbGetLine (
58 char *InputBuffer);
59
60 static UINT32
61 AcpiDbMatchCommand (
62 char *UserCommand);
63
64 static void
65 AcpiDbSingleThread (
66 void);
67
68 static void
69 AcpiDbDisplayCommandInfo (
70 const char *Command,
71 BOOLEAN DisplayAll);
72
73 static void
74 AcpiDbDisplayHelp (
75 char *Command);
76
77 static BOOLEAN
78 AcpiDbMatchCommandHelp (
79 const char *Command,
80 const ACPI_DB_COMMAND_HELP *Help);
81
82
83 /*
84 * Top-level debugger commands.
85 *
86 * This list of commands must match the string table below it
87 */
88 enum AcpiExDebuggerCommands
89 {
90 CMD_NOT_FOUND = 0,
91 CMD_NULL,
92 CMD_ALLOCATIONS,
93 CMD_ARGS,
94 CMD_ARGUMENTS,
95 CMD_BREAKPOINT,
96 CMD_BUSINFO,
97 CMD_CALL,
98 CMD_CLOSE,
99 CMD_DEBUG,
100 CMD_DISASSEMBLE,
101 CMD_DISASM,
102 CMD_DUMP,
103 CMD_ENABLEACPI,
104 CMD_EVALUATE,
105 CMD_EVENT,
106 CMD_EXECUTE,
107 CMD_EXIT,
108 CMD_FIND,
109 CMD_GO,
110 CMD_GPE,
111 CMD_GPES,
112 CMD_HANDLERS,
113 CMD_HELP,
114 CMD_HELP2,
115 CMD_HISTORY,
116 CMD_HISTORY_EXE,
117 CMD_HISTORY_LAST,
118 CMD_INFORMATION,
119 CMD_INTEGRITY,
120 CMD_INTO,
121 CMD_LEVEL,
122 CMD_LIST,
123 CMD_LOAD,
124 CMD_LOCALS,
125 CMD_LOCKS,
126 CMD_METHODS,
127 CMD_NAMESPACE,
128 CMD_NOTIFY,
129 CMD_OBJECTS,
130 CMD_OPEN,
131 CMD_OSI,
132 CMD_OWNER,
133 CMD_PATHS,
134 CMD_PREDEFINED,
135 CMD_PREFIX,
136 CMD_QUIT,
137 CMD_REFERENCES,
138 CMD_RESOURCES,
139 CMD_RESULTS,
140 CMD_SCI,
141 CMD_SET,
142 CMD_SLEEP,
143 CMD_STATS,
144 CMD_STOP,
145 CMD_TABLES,
146 CMD_TEMPLATE,
147 CMD_TERMINATE,
148 CMD_TEST,
149 CMD_THREADS,
150 CMD_TRACE,
151 CMD_TREE,
152 CMD_TYPE,
153 CMD_UNLOAD
154 };
155
156 #define CMD_FIRST_VALID 2
157
158
159 /* Second parameter is the required argument count */
160
161 static const ACPI_DB_COMMAND_INFO AcpiGbl_DbCommands[] =
162 {
163 {"<NOT FOUND>", 0},
164 {"<NULL>", 0},
165 {"ALLOCATIONS", 0},
166 {"ARGS", 0},
167 {"ARGUMENTS", 0},
168 {"BREAKPOINT", 1},
169 {"BUSINFO", 0},
170 {"CALL", 0},
171 {"CLOSE", 0},
172 {"DEBUG", 1},
173 {"DISASSEMBLE", 1},
174 {"DISASM", 1},
175 {"DUMP", 1},
176 {"ENABLEACPI", 0},
177 {"EVALUATE", 1},
178 {"EVENT", 1},
179 {"EXECUTE", 1},
180 {"EXIT", 0},
181 {"FIND", 1},
182 {"GO", 0},
183 {"GPE", 1},
184 {"GPES", 0},
185 {"HANDLERS", 0},
186 {"HELP", 0},
187 {"?", 0},
188 {"HISTORY", 0},
189 {"!", 1},
190 {"!!", 0},
191 {"INFORMATION", 0},
192 {"INTEGRITY", 0},
193 {"INTO", 0},
194 {"LEVEL", 0},
195 {"LIST", 0},
196 {"LOAD", 1},
197 {"LOCALS", 0},
198 {"LOCKS", 0},
199 {"METHODS", 0},
200 {"NAMESPACE", 0},
201 {"NOTIFY", 2},
202 {"OBJECTS", 1},
203 {"OPEN", 1},
204 {"OSI", 0},
205 {"OWNER", 1},
206 {"PATHS", 0},
207 {"PREDEFINED", 0},
208 {"PREFIX", 0},
209 {"QUIT", 0},
210 {"REFERENCES", 1},
211 {"RESOURCES", 0},
212 {"RESULTS", 0},
213 {"SCI", 0},
214 {"SET", 3},
215 {"SLEEP", 0},
216 {"STATS", 1},
217 {"STOP", 0},
218 {"TABLES", 0},
219 {"TEMPLATE", 1},
220 {"TERMINATE", 0},
221 {"TEST", 1},
222 {"THREADS", 3},
223 {"TRACE", 1},
224 {"TREE", 0},
225 {"TYPE", 1},
226 {"UNLOAD", 1},
227 {NULL, 0}
228 };
229
230 /*
231 * Help for all debugger commands. First argument is the number of lines
232 * of help to output for the command.
233 */
234 static const ACPI_DB_COMMAND_HELP AcpiGbl_DbCommandHelp[] =
235 {
236 {0, "\nGeneral-Purpose Commands:", "\n"},
237 {1, " Allocations", "Display list of current memory allocations\n"},
238 {2, " Dump <Address>|<Namepath>", "\n"},
239 {0, " [Byte|Word|Dword|Qword]", "Display ACPI objects or memory\n"},
240 {1, " EnableAcpi", "Enable ACPI (hardware) mode\n"},
241 {1, " Handlers", "Info about global handlers\n"},
242 {1, " Help [Command]", "This help screen or individual command\n"},
243 {1, " History", "Display command history buffer\n"},
244 {1, " Level <DebugLevel>] [console]", "Get/Set debug level for file or console\n"},
245 {1, " Locks", "Current status of internal mutexes\n"},
246 {1, " Osi [Install|Remove <name>]", "Display or modify global _OSI list\n"},
247 {1, " Quit or Exit", "Exit this command\n"},
248 {8, " Stats <SubCommand>", "Display namespace and memory statistics\n"},
249 {1, " Allocations", "Display list of current memory allocations\n"},
250 {1, " Memory", "Dump internal memory lists\n"},
251 {1, " Misc", "Namespace search and mutex stats\n"},
252 {1, " Objects", "Summary of namespace objects\n"},
253 {1, " Sizes", "Sizes for each of the internal objects\n"},
254 {1, " Stack", "Display CPU stack usage\n"},
255 {1, " Tables", "Info about current ACPI table(s)\n"},
256 {1, " Tables", "Display info about loaded ACPI tables\n"},
257 {1, " Unload <Namepath>", "Unload an ACPI table via namespace object\n"},
258 {1, " ! <CommandNumber>", "Execute command from history buffer\n"},
259 {1, " !!", "Execute last command again\n"},
260
261 {0, "\nNamespace Access Commands:", "\n"},
262 {1, " Businfo", "Display system bus info\n"},
263 {1, " Disassemble <Method>", "Disassemble a control method\n"},
264 {1, " Find <AcpiName> (? is wildcard)", "Find ACPI name(s) with wildcards\n"},
265 {1, " Integrity", "Validate namespace integrity\n"},
266 {1, " Methods", "Display list of loaded control methods\n"},
267 {1, " Namespace [Object] [Depth]", "Display loaded namespace tree/subtree\n"},
268 {1, " Notify <Object> <Value>", "Send a notification on Object\n"},
269 {1, " Objects <ObjectType>", "Display all objects of the given type\n"},
270 {1, " Owner <OwnerId> [Depth]", "Display loaded namespace by object owner\n"},
271 {1, " Paths", "Display full pathnames of namespace objects\n"},
272 {1, " Predefined", "Check all predefined names\n"},
273 {1, " Prefix [<Namepath>]", "Set or Get current execution prefix\n"},
274 {1, " References <Addr>", "Find all references to object at addr\n"},
275 {1, " Resources [DeviceName]", "Display Device resources (no arg = all devices)\n"},
276 {1, " Set N <NamedObject> <Value>", "Set value for named integer\n"},
277 {1, " Template <Object>", "Format/dump a Buffer/ResourceTemplate\n"},
278 {1, " Terminate", "Delete namespace and all internal objects\n"},
279 {1, " Type <Object>", "Display object type\n"},
280
281 {0, "\nControl Method Execution Commands:","\n"},
282 {1, " Arguments (or Args)", "Display method arguments\n"},
283 {1, " Breakpoint <AmlOffset>", "Set an AML execution breakpoint\n"},
284 {1, " Call", "Run to next control method invocation\n"},
285 {1, " Debug <Namepath> [Arguments]", "Single Step a control method\n"},
286 {6, " Evaluate", "Synonym for Execute\n"},
287 {5, " Execute <Namepath> [Arguments]", "Execute control method\n"},
288 {1, " Hex Integer", "Integer method argument\n"},
289 {1, " \"Ascii String\"", "String method argument\n"},
290 {1, " (Hex Byte List)", "Buffer method argument\n"},
291 {1, " [Package Element List]", "Package method argument\n"},
292 {1, " Go", "Allow method to run to completion\n"},
293 {1, " Information", "Display info about the current method\n"},
294 {1, " Into", "Step into (not over) a method call\n"},
295 {1, " List [# of Aml Opcodes]", "Display method ASL statements\n"},
296 {1, " Locals", "Display method local variables\n"},
297 {1, " Results", "Display method result stack\n"},
298 {1, " Set <A|L> <#> <Value>", "Set method data (Arguments/Locals)\n"},
299 {1, " Stop", "Terminate control method\n"},
300 {1, " Thread <Threads><Loops><Namepath>", "Spawn threads to execute method(s)\n"},
301 {5, " Trace <State> [<Namepath>] [Once]", "Trace control method execution\n"},
302 {1, " Enable", "Enable all messages\n"},
303 {1, " Disable", "Disable tracing\n"},
304 {1, " Method", "Enable method execution messages\n"},
305 {1, " Opcode", "Enable opcode execution messages\n"},
306 {1, " Tree", "Display control method calling tree\n"},
307 {1, " <Enter>", "Single step next AML opcode (over calls)\n"},
308
309 {0, "\nHardware Related Commands:", "\n"},
310 {1, " Event <F|G> <Value>", "Generate AcpiEvent (Fixed/GPE)\n"},
311 {1, " Gpe <GpeNum> [GpeBlockDevice]", "Simulate a GPE\n"},
312 {1, " Gpes", "Display info on all GPEs\n"},
313 {1, " Sci", "Generate an SCI\n"},
314 {1, " Sleep [SleepState]", "Simulate sleep/wake sequence(s) (0-5)\n"},
315
316 {0, "\nFile I/O Commands:", "\n"},
317 {1, " Close", "Close debug output file\n"},
318 {1, " Load <Input Filename>", "Load ACPI table from a file\n"},
319 {1, " Open <Output Filename>", "Open a file for debug output\n"},
320
321 {0, "\nDebug Test Commands:", "\n"},
322 {3, " Test <TestName>", "Invoke a debug test\n"},
323 {1, " Objects", "Read/write/compare all namespace data objects\n"},
324 {1, " Predefined", "Execute all ACPI predefined names (_STA, etc.)\n"},
325 {0, NULL, NULL}
326 };
327
328
329 /*******************************************************************************
330 *
331 * FUNCTION: AcpiDbMatchCommandHelp
332 *
333 * PARAMETERS: Command - Command string to match
334 * Help - Help table entry to attempt match
335 *
336 * RETURN: TRUE if command matched, FALSE otherwise
337 *
338 * DESCRIPTION: Attempt to match a command in the help table in order to
339 * print help information for a single command.
340 *
341 ******************************************************************************/
342
343 static BOOLEAN
344 AcpiDbMatchCommandHelp (
345 const char *Command,
346 const ACPI_DB_COMMAND_HELP *Help)
347 {
348 const char *Invocation = Help->Invocation;
349 UINT32 LineCount;
350
351
352 /* Valid commands in the help table begin with a couple of spaces */
353
354 if (*Invocation != ' ')
355 {
356 return (FALSE);
357 }
358
359 while (*Invocation == ' ')
360 {
361 Invocation++;
362 }
363
364 /* Match command name (full command or substring) */
365
366 while ((*Command) && (*Invocation) && (*Invocation != ' '))
367 {
368 if (tolower ((int) *Command) != tolower ((int) *Invocation))
369 {
370 return (FALSE);
371 }
372
373 Invocation++;
374 Command++;
375 }
376
377 /* Print the appropriate number of help lines */
378
379 LineCount = Help->LineCount;
380 while (LineCount)
381 {
382 AcpiOsPrintf ("%-38s : %s", Help->Invocation, Help->Description);
383 Help++;
384 LineCount--;
385 }
386
387 return (TRUE);
388 }
389
390
391 /*******************************************************************************
392 *
393 * FUNCTION: AcpiDbDisplayCommandInfo
394 *
395 * PARAMETERS: Command - Command string to match
396 * DisplayAll - Display all matching commands, or just
397 * the first one (substring match)
398 *
399 * RETURN: None
400 *
401 * DESCRIPTION: Display help information for a Debugger command.
402 *
403 ******************************************************************************/
404
405 static void
406 AcpiDbDisplayCommandInfo (
407 const char *Command,
408 BOOLEAN DisplayAll)
409 {
410 const ACPI_DB_COMMAND_HELP *Next;
411 BOOLEAN Matched;
412
413
414 Next = AcpiGbl_DbCommandHelp;
415 while (Next->Invocation)
416 {
417 Matched = AcpiDbMatchCommandHelp (Command, Next);
418 if (!DisplayAll && Matched)
419 {
420 return;
421 }
422
423 Next++;
424 }
425 }
426
427
428 /*******************************************************************************
429 *
430 * FUNCTION: AcpiDbDisplayHelp
431 *
432 * PARAMETERS: Command - Optional command string to display help.
433 * if not specified, all debugger command
434 * help strings are displayed
435 *
436 * RETURN: None
437 *
438 * DESCRIPTION: Display help for a single debugger command, or all of them.
439 *
440 ******************************************************************************/
441
442 static void
443 AcpiDbDisplayHelp (
444 char *Command)
445 {
446 const ACPI_DB_COMMAND_HELP *Next = AcpiGbl_DbCommandHelp;
447
448
449 if (!Command)
450 {
451 /* No argument to help, display help for all commands */
452
453 while (Next->Invocation)
454 {
455 AcpiOsPrintf ("%-38s%s", Next->Invocation, Next->Description);
456 Next++;
457 }
458 }
459 else
460 {
461 /* Display help for all commands that match the subtring */
462
463 AcpiDbDisplayCommandInfo (Command, TRUE);
464 }
465 }
466
467
468 /*******************************************************************************
469 *
470 * FUNCTION: AcpiDbGetNextToken
471 *
472 * PARAMETERS: String - Command buffer
473 * Next - Return value, end of next token
474 *
475 * RETURN: Pointer to the start of the next token.
476 *
477 * DESCRIPTION: Command line parsing. Get the next token on the command line
478 *
479 ******************************************************************************/
480
481 char *
482 AcpiDbGetNextToken (
483 char *String,
484 char **Next,
485 ACPI_OBJECT_TYPE *ReturnType)
486 {
487 char *Start;
488 UINT32 Depth;
489 ACPI_OBJECT_TYPE Type = ACPI_TYPE_INTEGER;
490
491
492 /* At end of buffer? */
493
494 if (!String || !(*String))
495 {
496 return (NULL);
497 }
498
499 /* Remove any spaces at the beginning */
500
501 if (*String == ' ')
502 {
503 while (*String && (*String == ' '))
504 {
505 String++;
506 }
507
508 if (!(*String))
509 {
510 return (NULL);
511 }
512 }
513
514 switch (*String)
515 {
516 case '"':
517
518 /* This is a quoted string, scan until closing quote */
519
520 String++;
521 Start = String;
522 Type = ACPI_TYPE_STRING;
523
524 /* Find end of string */
525
526 while (*String && (*String != '"'))
527 {
528 String++;
529 }
530 break;
531
532 case '(':
533
534 /* This is the start of a buffer, scan until closing paren */
535
536 String++;
537 Start = String;
538 Type = ACPI_TYPE_BUFFER;
539
540 /* Find end of buffer */
541
542 while (*String && (*String != ')'))
543 {
544 String++;
545 }
546 break;
547
548 case '[':
549
550 /* This is the start of a package, scan until closing bracket */
551
552 String++;
553 Depth = 1;
554 Start = String;
555 Type = ACPI_TYPE_PACKAGE;
556
557 /* Find end of package (closing bracket) */
558
559 while (*String)
560 {
561 /* Handle String package elements */
562
563 if (*String == '"')
564 {
565 /* Find end of string */
566
567 String++;
568 while (*String && (*String != '"'))
569 {
570 String++;
571 }
572 if (!(*String))
573 {
574 break;
575 }
576 }
577 else if (*String == '[')
578 {
579 Depth++; /* A nested package declaration */
580 }
581 else if (*String == ']')
582 {
583 Depth--;
584 if (Depth == 0) /* Found final package closing bracket */
585 {
586 break;
587 }
588 }
589
590 String++;
591 }
592 break;
593
594 default:
595
596 Start = String;
597
598 /* Find end of token */
599
600 while (*String && (*String != ' '))
601 {
602 String++;
603 }
604 break;
605 }
606
607 if (!(*String))
608 {
609 *Next = NULL;
610 }
611 else
612 {
613 *String = 0;
614 *Next = String + 1;
615 }
616
617 *ReturnType = Type;
618 return (Start);
619 }
620
621
622 /*******************************************************************************
623 *
624 * FUNCTION: AcpiDbGetLine
625 *
626 * PARAMETERS: InputBuffer - Command line buffer
627 *
628 * RETURN: Count of arguments to the command
629 *
630 * DESCRIPTION: Get the next command line from the user. Gets entire line
631 * up to the next newline
632 *
633 ******************************************************************************/
634
635 static UINT32
636 AcpiDbGetLine (
637 char *InputBuffer)
638 {
639 UINT32 i;
640 UINT32 Count;
641 char *Next;
642 char *This;
643
644
645 if (AcpiUtSafeStrcpy (AcpiGbl_DbParsedBuf, sizeof (AcpiGbl_DbParsedBuf),
646 InputBuffer))
647 {
648 AcpiOsPrintf ("Buffer overflow while parsing input line (max %u characters)\n",
649 sizeof (AcpiGbl_DbParsedBuf));
650 return (0);
651 }
652
653 This = AcpiGbl_DbParsedBuf;
654 for (i = 0; i < ACPI_DEBUGGER_MAX_ARGS; i++)
655 {
656 AcpiGbl_DbArgs[i] = AcpiDbGetNextToken (This, &Next,
657 &AcpiGbl_DbArgTypes[i]);
658 if (!AcpiGbl_DbArgs[i])
659 {
660 break;
661 }
662
663 This = Next;
664 }
665
666 /* Uppercase the actual command */
667
668 if (AcpiGbl_DbArgs[0])
669 {
670 AcpiUtStrupr (AcpiGbl_DbArgs[0]);
671 }
672
673 Count = i;
674 if (Count)
675 {
676 Count--; /* Number of args only */
677 }
678
679 return (Count);
680 }
681
682
683 /*******************************************************************************
684 *
685 * FUNCTION: AcpiDbMatchCommand
686 *
687 * PARAMETERS: UserCommand - User command line
688 *
689 * RETURN: Index into command array, -1 if not found
690 *
691 * DESCRIPTION: Search command array for a command match
692 *
693 ******************************************************************************/
694
695 static UINT32
696 AcpiDbMatchCommand (
697 char *UserCommand)
698 {
699 UINT32 i;
700
701
702 if (!UserCommand || UserCommand[0] == 0)
703 {
704 return (CMD_NULL);
705 }
706
707 for (i = CMD_FIRST_VALID; AcpiGbl_DbCommands[i].Name; i++)
708 {
709 if (strstr (AcpiGbl_DbCommands[i].Name, UserCommand) ==
710 AcpiGbl_DbCommands[i].Name)
711 {
712 return (i);
713 }
714 }
715
716 /* Command not recognized */
717
718 return (CMD_NOT_FOUND);
719 }
720
721
722 /*******************************************************************************
723 *
724 * FUNCTION: AcpiDbCommandDispatch
725 *
726 * PARAMETERS: InputBuffer - Command line buffer
727 * WalkState - Current walk
728 * Op - Current (executing) parse op
729 *
730 * RETURN: Status
731 *
732 * DESCRIPTION: Command dispatcher.
733 *
734 ******************************************************************************/
735
736 ACPI_STATUS
737 AcpiDbCommandDispatch (
738 char *InputBuffer,
739 ACPI_WALK_STATE *WalkState,
740 ACPI_PARSE_OBJECT *Op)
741 {
742 UINT32 Temp;
743 UINT32 CommandIndex;
744 UINT32 ParamCount;
745 char *CommandLine;
746 ACPI_STATUS Status = AE_CTRL_TRUE;
747
748
749 /* If AcpiTerminate has been called, terminate this thread */
750
751 if (AcpiGbl_DbTerminateThreads)
752 {
753 return (AE_CTRL_TERMINATE);
754 }
755
756 /* Find command and add to the history buffer */
757
758 ParamCount = AcpiDbGetLine (InputBuffer);
759 CommandIndex = AcpiDbMatchCommand (AcpiGbl_DbArgs[0]);
760 Temp = 0;
761
762 /*
763 * We don't want to add the !! command to the history buffer. It
764 * would cause an infinite loop because it would always be the
765 * previous command.
766 */
767 if (CommandIndex != CMD_HISTORY_LAST)
768 {
769 AcpiDbAddToHistory (InputBuffer);
770 }
771
772 /* Verify that we have the minimum number of params */
773
774 if (ParamCount < AcpiGbl_DbCommands[CommandIndex].MinArgs)
775 {
776 AcpiOsPrintf ("%u parameters entered, [%s] requires %u parameters\n",
777 ParamCount, AcpiGbl_DbCommands[CommandIndex].Name,
778 AcpiGbl_DbCommands[CommandIndex].MinArgs);
779
780 AcpiDbDisplayCommandInfo (AcpiGbl_DbCommands[CommandIndex].Name, FALSE);
781 return (AE_CTRL_TRUE);
782 }
783
784 /* Decode and dispatch the command */
785
786 switch (CommandIndex)
787 {
788 case CMD_NULL:
789
790 if (Op)
791 {
792 return (AE_OK);
793 }
794 break;
795
796 case CMD_ALLOCATIONS:
797
798 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
799 AcpiUtDumpAllocations ((UINT32) -1, NULL);
800 #endif
801 break;
802
803 case CMD_ARGS:
804 case CMD_ARGUMENTS:
805
806 AcpiDbDisplayArguments ();
807 break;
808
809 case CMD_BREAKPOINT:
810
811 AcpiDbSetMethodBreakpoint (AcpiGbl_DbArgs[1], WalkState, Op);
812 break;
813
814 case CMD_BUSINFO:
815
816 AcpiDbGetBusInfo ();
817 break;
818
819 case CMD_CALL:
820
821 AcpiDbSetMethodCallBreakpoint (Op);
822 Status = AE_OK;
823 break;
824
825 case CMD_CLOSE:
826
827 AcpiDbCloseDebugFile ();
828 break;
829
830 case CMD_DEBUG:
831
832 AcpiDbExecute (AcpiGbl_DbArgs[1],
833 &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_SINGLE_STEP);
834 break;
835
836 case CMD_DISASSEMBLE:
837 case CMD_DISASM:
838
839 (void) AcpiDbDisassembleMethod (AcpiGbl_DbArgs[1]);
840 break;
841
842 case CMD_DUMP:
843
844 AcpiDbDecodeAndDisplayObject (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
845 break;
846
847 case CMD_ENABLEACPI:
848 #if (!ACPI_REDUCED_HARDWARE)
849
850 Status = AcpiEnable();
851 if (ACPI_FAILURE(Status))
852 {
853 AcpiOsPrintf("AcpiEnable failed (Status=%X)\n", Status);
854 return (Status);
855 }
856 #endif /* !ACPI_REDUCED_HARDWARE */
857 break;
858
859 case CMD_EVENT:
860
861 AcpiOsPrintf ("Event command not implemented\n");
862 break;
863
864 case CMD_EVALUATE:
865 case CMD_EXECUTE:
866
867 AcpiDbExecute (AcpiGbl_DbArgs[1],
868 &AcpiGbl_DbArgs[2], &AcpiGbl_DbArgTypes[2], EX_NO_SINGLE_STEP);
869 break;
870
871 case CMD_FIND:
872
873 Status = AcpiDbFindNameInNamespace (AcpiGbl_DbArgs[1]);
874 break;
875
876 case CMD_GO:
877
878 AcpiGbl_CmSingleStep = FALSE;
879 return (AE_OK);
880
881 case CMD_GPE:
882
883 AcpiDbGenerateGpe (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
884 break;
885
886 case CMD_GPES:
887
888 AcpiDbDisplayGpes ();
889 break;
890
891 case CMD_HANDLERS:
892
893 AcpiDbDisplayHandlers ();
894 break;
895
896 case CMD_HELP:
897 case CMD_HELP2:
898
899 AcpiDbDisplayHelp (AcpiGbl_DbArgs[1]);
900 break;
901
902 case CMD_HISTORY:
903
904 AcpiDbDisplayHistory ();
905 break;
906
907 case CMD_HISTORY_EXE: /* ! command */
908
909 CommandLine = AcpiDbGetFromHistory (AcpiGbl_DbArgs[1]);
910 if (!CommandLine)
911 {
912 return (AE_CTRL_TRUE);
913 }
914
915 Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
916 return (Status);
917
918 case CMD_HISTORY_LAST: /* !! command */
919
920 CommandLine = AcpiDbGetFromHistory (NULL);
921 if (!CommandLine)
922 {
923 return (AE_CTRL_TRUE);
924 }
925
926 Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op);
927 return (Status);
928
929 case CMD_INFORMATION:
930
931 AcpiDbDisplayMethodInfo (Op);
932 break;
933
934 case CMD_INTEGRITY:
935
936 AcpiDbCheckIntegrity ();
937 break;
938
939 case CMD_INTO:
940
941 if (Op)
942 {
943 AcpiGbl_CmSingleStep = TRUE;
944 return (AE_OK);
945 }
946 break;
947
948 case CMD_LEVEL:
949
950 if (ParamCount == 0)
951 {
952 AcpiOsPrintf ("Current debug level for file output is: %8.8lX\n",
953 AcpiGbl_DbDebugLevel);
954 AcpiOsPrintf ("Current debug level for console output is: %8.8lX\n",
955 AcpiGbl_DbConsoleDebugLevel);
956 }
957 else if (ParamCount == 2)
958 {
959 Temp = AcpiGbl_DbConsoleDebugLevel;
960 AcpiGbl_DbConsoleDebugLevel = strtoul (AcpiGbl_DbArgs[1],
961 NULL, 16);
962 AcpiOsPrintf (
963 "Debug Level for console output was %8.8lX, now %8.8lX\n",
964 Temp, AcpiGbl_DbConsoleDebugLevel);
965 }
966 else
967 {
968 Temp = AcpiGbl_DbDebugLevel;
969 AcpiGbl_DbDebugLevel = strtoul (AcpiGbl_DbArgs[1], NULL, 16);
970 AcpiOsPrintf (
971 "Debug Level for file output was %8.8lX, now %8.8lX\n",
972 Temp, AcpiGbl_DbDebugLevel);
973 }
974 break;
975
976 case CMD_LIST:
977
978 AcpiDbDisassembleAml (AcpiGbl_DbArgs[1], Op);
979 break;
980
981 case CMD_LOAD:
982
983 Status = AcpiDbGetTableFromFile (AcpiGbl_DbArgs[1], NULL, FALSE);
984 break;
985
986 case CMD_LOCKS:
987
988 AcpiDbDisplayLocks ();
989 break;
990
991 case CMD_LOCALS:
992
993 AcpiDbDisplayLocals ();
994 break;
995
996 case CMD_METHODS:
997 Status = AcpiDbDisplayObjects (__UNCONST("METHOD"), AcpiGbl_DbArgs[1]);
998 break;
999
1000 case CMD_NAMESPACE:
1001
1002 AcpiDbDumpNamespace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1003 break;
1004
1005 case CMD_NOTIFY:
1006
1007 Temp = strtoul (AcpiGbl_DbArgs[2], NULL, 0);
1008 AcpiDbSendNotify (AcpiGbl_DbArgs[1], Temp);
1009 break;
1010
1011 case CMD_OBJECTS:
1012
1013 AcpiUtStrupr (AcpiGbl_DbArgs[1]);
1014 Status = AcpiDbDisplayObjects (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1015 break;
1016
1017 case CMD_OPEN:
1018
1019 AcpiDbOpenDebugFile (AcpiGbl_DbArgs[1]);
1020 break;
1021
1022 case CMD_OSI:
1023
1024 AcpiDbDisplayInterfaces (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1025 break;
1026
1027 case CMD_OWNER:
1028
1029 AcpiDbDumpNamespaceByOwner (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2]);
1030 break;
1031
1032 case CMD_PATHS:
1033
1034 AcpiDbDumpNamespacePaths ();
1035 break;
1036
1037 case CMD_PREDEFINED:
1038
1039 AcpiDbCheckPredefinedNames ();
1040 break;
1041
1042 case CMD_PREFIX:
1043
1044 AcpiDbSetScope (AcpiGbl_DbArgs[1]);
1045 break;
1046
1047 case CMD_REFERENCES:
1048
1049 AcpiDbFindReferences (AcpiGbl_DbArgs[1]);
1050 break;
1051
1052 case CMD_RESOURCES:
1053
1054 AcpiDbDisplayResources (AcpiGbl_DbArgs[1]);
1055 break;
1056
1057 case CMD_RESULTS:
1058
1059 AcpiDbDisplayResults ();
1060 break;
1061
1062 case CMD_SCI:
1063
1064 AcpiDbGenerateSci ();
1065 break;
1066
1067 case CMD_SET:
1068
1069 AcpiDbSetMethodData (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],
1070 AcpiGbl_DbArgs[3]);
1071 break;
1072
1073 case CMD_SLEEP:
1074
1075 Status = AcpiDbSleep (AcpiGbl_DbArgs[1]);
1076 break;
1077
1078 case CMD_STATS:
1079
1080 Status = AcpiDbDisplayStatistics (AcpiGbl_DbArgs[1]);
1081 break;
1082
1083 case CMD_STOP:
1084
1085 return (AE_NOT_IMPLEMENTED);
1086
1087 case CMD_TABLES:
1088
1089 AcpiDbDisplayTableInfo (AcpiGbl_DbArgs[1]);
1090 break;
1091
1092 case CMD_TEMPLATE:
1093
1094 AcpiDbDisplayTemplate (AcpiGbl_DbArgs[1]);
1095 break;
1096
1097 case CMD_TERMINATE:
1098
1099 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
1100 AcpiUtSubsystemShutdown ();
1101
1102 /*
1103 * TBD: [Restructure] Need some way to re-initialize without
1104 * re-creating the semaphores!
1105 */
1106
1107 /* AcpiInitialize (NULL); */
1108 break;
1109
1110 case CMD_TEST:
1111
1112 AcpiDbExecuteTest (AcpiGbl_DbArgs[1]);
1113 break;
1114
1115 case CMD_THREADS:
1116
1117 AcpiDbCreateExecutionThreads (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2],
1118 AcpiGbl_DbArgs[3]);
1119 break;
1120
1121 case CMD_TRACE:
1122
1123 AcpiDbTrace (AcpiGbl_DbArgs[1], AcpiGbl_DbArgs[2], AcpiGbl_DbArgs[3]);
1124 break;
1125
1126 case CMD_TREE:
1127
1128 AcpiDbDisplayCallingTree ();
1129 break;
1130
1131 case CMD_TYPE:
1132
1133 AcpiDbDisplayObjectType (AcpiGbl_DbArgs[1]);
1134 break;
1135
1136 case CMD_UNLOAD:
1137
1138 AcpiDbUnloadAcpiTable (AcpiGbl_DbArgs[1]);
1139 break;
1140
1141 case CMD_EXIT:
1142 case CMD_QUIT:
1143
1144 if (Op)
1145 {
1146 AcpiOsPrintf ("Method execution terminated\n");
1147 return (AE_CTRL_TERMINATE);
1148 }
1149
1150 if (!AcpiGbl_DbOutputToFile)
1151 {
1152 AcpiDbgLevel = ACPI_DEBUG_DEFAULT;
1153 }
1154
1155 AcpiDbCloseDebugFile ();
1156 AcpiGbl_DbTerminateThreads = TRUE;
1157 return (AE_CTRL_TERMINATE);
1158
1159 case CMD_NOT_FOUND:
1160 default:
1161
1162 AcpiOsPrintf ("%s: unknown command\n", AcpiGbl_DbArgs[0]);
1163 return (AE_CTRL_TRUE);
1164 }
1165
1166 if (ACPI_SUCCESS (Status))
1167 {
1168 Status = AE_CTRL_TRUE;
1169 }
1170
1171 return (Status);
1172 }
1173
1174
1175 /*******************************************************************************
1176 *
1177 * FUNCTION: AcpiDbExecuteThread
1178 *
1179 * PARAMETERS: Context - Not used
1180 *
1181 * RETURN: None
1182 *
1183 * DESCRIPTION: Debugger execute thread. Waits for a command line, then
1184 * simply dispatches it.
1185 *
1186 ******************************************************************************/
1187
1188 void ACPI_SYSTEM_XFACE
1189 AcpiDbExecuteThread (
1190 void *Context)
1191 {
1192 ACPI_STATUS Status = AE_OK;
1193 ACPI_STATUS MStatus;
1194
1195
1196 while (Status != AE_CTRL_TERMINATE)
1197 {
1198 AcpiGbl_MethodExecuting = FALSE;
1199 AcpiGbl_StepToNextCall = FALSE;
1200
1201 MStatus = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY);
1202 if (ACPI_FAILURE (MStatus))
1203 {
1204 return;
1205 }
1206
1207 Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
1208
1209 MStatus = AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
1210 if (ACPI_FAILURE (MStatus))
1211 {
1212 return;
1213 }
1214 }
1215 }
1216
1217
1218 /*******************************************************************************
1219 *
1220 * FUNCTION: AcpiDbSingleThread
1221 *
1222 * PARAMETERS: None
1223 *
1224 * RETURN: None
1225 *
1226 * DESCRIPTION: Debugger execute thread. Waits for a command line, then
1227 * simply dispatches it.
1228 *
1229 ******************************************************************************/
1230
1231 static void
1232 AcpiDbSingleThread (
1233 void)
1234 {
1235
1236 AcpiGbl_MethodExecuting = FALSE;
1237 AcpiGbl_StepToNextCall = FALSE;
1238
1239 (void) AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, NULL, NULL);
1240 }
1241
1242
1243 /*******************************************************************************
1244 *
1245 * FUNCTION: AcpiDbUserCommands
1246 *
1247 * PARAMETERS: Prompt - User prompt (depends on mode)
1248 * Op - Current executing parse op
1249 *
1250 * RETURN: None
1251 *
1252 * DESCRIPTION: Command line execution for the AML debugger. Commands are
1253 * matched and dispatched here.
1254 *
1255 ******************************************************************************/
1256
1257 ACPI_STATUS
1258 AcpiDbUserCommands (
1259 char Prompt,
1260 ACPI_PARSE_OBJECT *Op)
1261 {
1262 ACPI_STATUS Status = AE_OK;
1263
1264
1265 AcpiOsPrintf ("\n");
1266
1267 /* TBD: [Restructure] Need a separate command line buffer for step mode */
1268
1269 while (!AcpiGbl_DbTerminateThreads)
1270 {
1271 /* Force output to console until a command is entered */
1272
1273 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
1274
1275 /* Different prompt if method is executing */
1276
1277 if (!AcpiGbl_MethodExecuting)
1278 {
1279 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
1280 }
1281 else
1282 {
1283 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
1284 }
1285
1286 /* Get the user input line */
1287
1288 Status = AcpiOsGetLine (AcpiGbl_DbLineBuf,
1289 ACPI_DB_LINE_BUFFER_SIZE, NULL);
1290 if (ACPI_FAILURE (Status))
1291 {
1292 ACPI_EXCEPTION ((AE_INFO, Status, "While parsing command line"));
1293 return (Status);
1294 }
1295
1296 /* Check for single or multithreaded debug */
1297
1298 if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)
1299 {
1300 /*
1301 * Signal the debug thread that we have a command to execute,
1302 * and wait for the command to complete.
1303 */
1304 Status = AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_READY);
1305 if (ACPI_FAILURE (Status))
1306 {
1307 return (Status);
1308 }
1309
1310 Status = AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_COMPLETE);
1311 if (ACPI_FAILURE (Status))
1312 {
1313 return (Status);
1314 }
1315 }
1316 else
1317 {
1318 /* Just call to the command line interpreter */
1319
1320 AcpiDbSingleThread ();
1321 }
1322 }
1323
1324 /*
1325 * Only this thread (the original thread) should actually terminate the
1326 * subsystem, because all the semaphores are deleted during termination
1327 */
1328 Status = AcpiTerminate ();
1329 return (Status);
1330 }
1331
1332 #endif /* ACPI_DEBUGGER */
1333