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