blob: 2bf8e6b90d5ba2961a0889116af6711e11a6d796 [file] [log] [blame]
Lv Zheng99575102015-10-19 10:25:20 +08001/*******************************************************************************
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/acpi.h>
45#include "accommon.h"
46#include "acdebug.h"
47
48#define _COMPONENT ACPI_CA_DEBUGGER
49ACPI_MODULE_NAME("dbinput")
50
51/* Local prototypes */
52static u32 acpi_db_get_line(char *input_buffer);
53
54static u32 acpi_db_match_command(char *user_command);
55
Lv Zheng99575102015-10-19 10:25:20 +080056static void acpi_db_display_command_info(char *command, u8 display_all);
57
58static void acpi_db_display_help(char *command);
59
60static u8
61acpi_db_match_command_help(char *command,
62 const struct acpi_db_command_help *help);
63
64/*
65 * Top-level debugger commands.
66 *
67 * This list of commands must match the string table below it
68 */
69enum acpi_ex_debugger_commands {
70 CMD_NOT_FOUND = 0,
71 CMD_NULL,
72 CMD_ALLOCATIONS,
73 CMD_ARGS,
74 CMD_ARGUMENTS,
75 CMD_BREAKPOINT,
76 CMD_BUSINFO,
77 CMD_CALL,
78 CMD_DEBUG,
79 CMD_DISASSEMBLE,
80 CMD_DISASM,
81 CMD_DUMP,
82 CMD_EVALUATE,
83 CMD_EXECUTE,
84 CMD_EXIT,
85 CMD_FIND,
86 CMD_GO,
87 CMD_HANDLERS,
88 CMD_HELP,
89 CMD_HELP2,
90 CMD_HISTORY,
91 CMD_HISTORY_EXE,
92 CMD_HISTORY_LAST,
93 CMD_INFORMATION,
94 CMD_INTEGRITY,
95 CMD_INTO,
96 CMD_LEVEL,
97 CMD_LIST,
98 CMD_LOCALS,
99 CMD_LOCKS,
100 CMD_METHODS,
101 CMD_NAMESPACE,
102 CMD_NOTIFY,
103 CMD_OBJECTS,
104 CMD_OSI,
105 CMD_OWNER,
106 CMD_PATHS,
107 CMD_PREDEFINED,
108 CMD_PREFIX,
109 CMD_QUIT,
110 CMD_REFERENCES,
111 CMD_RESOURCES,
112 CMD_RESULTS,
113 CMD_SET,
114 CMD_STATS,
115 CMD_STOP,
116 CMD_TABLES,
117 CMD_TEMPLATE,
118 CMD_TRACE,
119 CMD_TREE,
120 CMD_TYPE,
121#ifdef ACPI_APPLICATION
122 CMD_ENABLEACPI,
123 CMD_EVENT,
124 CMD_GPE,
125 CMD_GPES,
126 CMD_SCI,
127 CMD_SLEEP,
128
129 CMD_CLOSE,
130 CMD_LOAD,
131 CMD_OPEN,
132 CMD_UNLOAD,
133
134 CMD_TERMINATE,
135 CMD_THREADS,
136
137 CMD_TEST,
138#endif
139};
140
141#define CMD_FIRST_VALID 2
142
143/* Second parameter is the required argument count */
144
145static const struct acpi_db_command_info acpi_gbl_db_commands[] = {
146 {"<NOT FOUND>", 0},
147 {"<NULL>", 0},
148 {"ALLOCATIONS", 0},
149 {"ARGS", 0},
150 {"ARGUMENTS", 0},
151 {"BREAKPOINT", 1},
152 {"BUSINFO", 0},
153 {"CALL", 0},
154 {"DEBUG", 1},
155 {"DISASSEMBLE", 1},
156 {"DISASM", 1},
157 {"DUMP", 1},
158 {"EVALUATE", 1},
159 {"EXECUTE", 1},
160 {"EXIT", 0},
161 {"FIND", 1},
162 {"GO", 0},
163 {"HANDLERS", 0},
164 {"HELP", 0},
165 {"?", 0},
166 {"HISTORY", 0},
167 {"!", 1},
168 {"!!", 0},
169 {"INFORMATION", 0},
170 {"INTEGRITY", 0},
171 {"INTO", 0},
172 {"LEVEL", 0},
173 {"LIST", 0},
174 {"LOCALS", 0},
175 {"LOCKS", 0},
176 {"METHODS", 0},
177 {"NAMESPACE", 0},
178 {"NOTIFY", 2},
179 {"OBJECTS", 0},
180 {"OSI", 0},
181 {"OWNER", 1},
182 {"PATHS", 0},
183 {"PREDEFINED", 0},
184 {"PREFIX", 0},
185 {"QUIT", 0},
186 {"REFERENCES", 1},
187 {"RESOURCES", 0},
188 {"RESULTS", 0},
189 {"SET", 3},
190 {"STATS", 1},
191 {"STOP", 0},
192 {"TABLES", 0},
193 {"TEMPLATE", 1},
194 {"TRACE", 1},
195 {"TREE", 0},
196 {"TYPE", 1},
197#ifdef ACPI_APPLICATION
198 {"ENABLEACPI", 0},
199 {"EVENT", 1},
200 {"GPE", 1},
201 {"GPES", 0},
202 {"SCI", 0},
203 {"SLEEP", 0},
204
205 {"CLOSE", 0},
206 {"LOAD", 1},
207 {"OPEN", 1},
208 {"UNLOAD", 1},
209
210 {"TERMINATE", 0},
211 {"THREADS", 3},
212
213 {"TEST", 1},
214#endif
215 {NULL, 0}
216};
217
218/*
219 * Help for all debugger commands. First argument is the number of lines
220 * of help to output for the command.
221 */
222static const struct acpi_db_command_help acpi_gbl_db_command_help[] = {
223 {0, "\nGeneral-Purpose Commands:", "\n"},
224 {1, " Allocations", "Display list of current memory allocations\n"},
225 {2, " Dump <Address>|<Namepath>", "\n"},
226 {0, " [Byte|Word|Dword|Qword]",
227 "Display ACPI objects or memory\n"},
228 {1, " Handlers", "Info about global handlers\n"},
229 {1, " Help [Command]", "This help screen or individual command\n"},
230 {1, " History", "Display command history buffer\n"},
231 {1, " Level <DebugLevel>] [console]",
232 "Get/Set debug level for file or console\n"},
233 {1, " Locks", "Current status of internal mutexes\n"},
234 {1, " Osi [Install|Remove <name>]",
235 "Display or modify global _OSI list\n"},
236 {1, " Quit or Exit", "Exit this command\n"},
237 {8, " Stats <SubCommand>",
238 "Display namespace and memory statistics\n"},
239 {1, " Allocations", "Display list of current memory allocations\n"},
240 {1, " Memory", "Dump internal memory lists\n"},
241 {1, " Misc", "Namespace search and mutex stats\n"},
242 {1, " Objects", "Summary of namespace objects\n"},
243 {1, " Sizes", "Sizes for each of the internal objects\n"},
244 {1, " Stack", "Display CPU stack usage\n"},
245 {1, " Tables", "Info about current ACPI table(s)\n"},
246 {1, " Tables", "Display info about loaded ACPI tables\n"},
247 {1, " ! <CommandNumber>", "Execute command from history buffer\n"},
248 {1, " !!", "Execute last command again\n"},
249
250 {0, "\nNamespace Access Commands:", "\n"},
251 {1, " Businfo", "Display system bus info\n"},
252 {1, " Disassemble <Method>", "Disassemble a control method\n"},
253 {1, " Find <AcpiName> (? is wildcard)",
254 "Find ACPI name(s) with wildcards\n"},
255 {1, " Integrity", "Validate namespace integrity\n"},
256 {1, " Methods", "Display list of loaded control methods\n"},
257 {1, " Namespace [Object] [Depth]",
258 "Display loaded namespace tree/subtree\n"},
259 {1, " Notify <Object> <Value>", "Send a notification on Object\n"},
260 {1, " Objects [ObjectType]",
261 "Display summary of all objects or just given type\n"},
262 {1, " Owner <OwnerId> [Depth]",
263 "Display loaded namespace by object owner\n"},
264 {1, " Paths", "Display full pathnames of namespace objects\n"},
265 {1, " Predefined", "Check all predefined names\n"},
266 {1, " Prefix [<Namepath>]", "Set or Get current execution prefix\n"},
267 {1, " References <Addr>", "Find all references to object at addr\n"},
268 {1, " Resources [DeviceName]",
269 "Display Device resources (no arg = all devices)\n"},
270 {1, " Set N <NamedObject> <Value>", "Set value for named integer\n"},
271 {1, " Template <Object>", "Format/dump a Buffer/ResourceTemplate\n"},
272 {1, " Type <Object>", "Display object type\n"},
273
274 {0, "\nControl Method Execution Commands:", "\n"},
275 {1, " Arguments (or Args)", "Display method arguments\n"},
276 {1, " Breakpoint <AmlOffset>", "Set an AML execution breakpoint\n"},
277 {1, " Call", "Run to next control method invocation\n"},
278 {1, " Debug <Namepath> [Arguments]", "Single Step a control method\n"},
279 {6, " Evaluate", "Synonym for Execute\n"},
280 {5, " Execute <Namepath> [Arguments]", "Execute control method\n"},
281 {1, " Hex Integer", "Integer method argument\n"},
282 {1, " \"Ascii String\"", "String method argument\n"},
283 {1, " (Hex Byte List)", "Buffer method argument\n"},
284 {1, " [Package Element List]", "Package method argument\n"},
285 {1, " Go", "Allow method to run to completion\n"},
286 {1, " Information", "Display info about the current method\n"},
287 {1, " Into", "Step into (not over) a method call\n"},
288 {1, " List [# of Aml Opcodes]", "Display method ASL statements\n"},
289 {1, " Locals", "Display method local variables\n"},
290 {1, " Results", "Display method result stack\n"},
291 {1, " Set <A|L> <#> <Value>", "Set method data (Arguments/Locals)\n"},
292 {1, " Stop", "Terminate control method\n"},
293 {5, " Trace <State> [<Namepath>] [Once]",
294 "Trace control method execution\n"},
295 {1, " Enable", "Enable all messages\n"},
296 {1, " Disable", "Disable tracing\n"},
297 {1, " Method", "Enable method execution messages\n"},
298 {1, " Opcode", "Enable opcode execution messages\n"},
299 {1, " Tree", "Display control method calling tree\n"},
300 {1, " <Enter>", "Single step next AML opcode (over calls)\n"},
301
302#ifdef ACPI_APPLICATION
303 {0, "\nHardware Simulation Commands:", "\n"},
304 {1, " EnableAcpi", "Enable ACPI (hardware) mode\n"},
305 {1, " Event <F|G> <Value>", "Generate AcpiEvent (Fixed/GPE)\n"},
306 {1, " Gpe <GpeNum> [GpeBlockDevice]", "Simulate a GPE\n"},
307 {1, " Gpes", "Display info on all GPE devices\n"},
308 {1, " Sci", "Generate an SCI\n"},
309 {1, " Sleep [SleepState]", "Simulate sleep/wake sequence(s) (0-5)\n"},
310
311 {0, "\nFile I/O Commands:", "\n"},
312 {1, " Close", "Close debug output file\n"},
313 {1, " Load <Input Filename>", "Load ACPI table from a file\n"},
314 {1, " Open <Output Filename>", "Open a file for debug output\n"},
315 {1, " Unload <Namepath>",
316 "Unload an ACPI table via namespace object\n"},
317
318 {0, "\nUser Space Commands:", "\n"},
319 {1, " Terminate", "Delete namespace and all internal objects\n"},
320 {1, " Thread <Threads><Loops><NamePath>",
321 "Spawn threads to execute method(s)\n"},
322
323 {0, "\nDebug Test Commands:", "\n"},
324 {3, " Test <TestName>", "Invoke a debug test\n"},
325 {1, " Objects", "Read/write/compare all namespace data objects\n"},
326 {1, " Predefined",
327 "Execute all ACPI predefined names (_STA, etc.)\n"},
328#endif
329 {0, NULL, NULL}
330};
331
332/*******************************************************************************
333 *
334 * FUNCTION: acpi_db_match_command_help
335 *
336 * PARAMETERS: command - Command string to match
337 * help - Help table entry to attempt match
338 *
339 * RETURN: TRUE if command matched, FALSE otherwise
340 *
341 * DESCRIPTION: Attempt to match a command in the help table in order to
342 * print help information for a single command.
343 *
344 ******************************************************************************/
345
346static u8
347acpi_db_match_command_help(char *command,
348 const struct acpi_db_command_help *help)
349{
350 char *invocation = help->invocation;
351 u32 line_count;
352
353 /* Valid commands in the help table begin with a couple of spaces */
354
355 if (*invocation != ' ') {
356 return (FALSE);
357 }
358
359 while (*invocation == ' ') {
360 invocation++;
361 }
362
363 /* Match command name (full command or substring) */
364
365 while ((*command) && (*invocation) && (*invocation != ' ')) {
366 if (tolower((int)*command) != tolower((int)*invocation)) {
367 return (FALSE);
368 }
369
370 invocation++;
371 command++;
372 }
373
374 /* Print the appropriate number of help lines */
375
376 line_count = help->line_count;
377 while (line_count) {
378 acpi_os_printf("%-38s : %s", help->invocation,
379 help->description);
380 help++;
381 line_count--;
382 }
383
384 return (TRUE);
385}
386
387/*******************************************************************************
388 *
389 * FUNCTION: acpi_db_display_command_info
390 *
391 * PARAMETERS: command - Command string to match
392 * display_all - Display all matching commands, or just
393 * the first one (substring match)
394 *
395 * RETURN: None
396 *
397 * DESCRIPTION: Display help information for a Debugger command.
398 *
399 ******************************************************************************/
400
401static void acpi_db_display_command_info(char *command, u8 display_all)
402{
403 const struct acpi_db_command_help *next;
404 u8 matched;
405
406 next = acpi_gbl_db_command_help;
407 while (next->invocation) {
408 matched = acpi_db_match_command_help(command, next);
409 if (!display_all && matched) {
410 return;
411 }
412
413 next++;
414 }
415}
416
417/*******************************************************************************
418 *
419 * FUNCTION: acpi_db_display_help
420 *
421 * PARAMETERS: command - Optional command string to display help.
422 * if not specified, all debugger command
423 * help strings are displayed
424 *
425 * RETURN: None
426 *
427 * DESCRIPTION: Display help for a single debugger command, or all of them.
428 *
429 ******************************************************************************/
430
431static void acpi_db_display_help(char *command)
432{
433 const struct acpi_db_command_help *next = acpi_gbl_db_command_help;
434
435 if (!command) {
436
437 /* No argument to help, display help for all commands */
438
439 while (next->invocation) {
440 acpi_os_printf("%-38s%s", next->invocation,
441 next->description);
442 next++;
443 }
444 } else {
445 /* Display help for all commands that match the subtring */
446
447 acpi_db_display_command_info(command, TRUE);
448 }
449}
450
451/*******************************************************************************
452 *
453 * FUNCTION: acpi_db_get_next_token
454 *
455 * PARAMETERS: string - Command buffer
456 * next - Return value, end of next token
457 *
458 * RETURN: Pointer to the start of the next token.
459 *
460 * DESCRIPTION: Command line parsing. Get the next token on the command line
461 *
462 ******************************************************************************/
463
464char *acpi_db_get_next_token(char *string,
465 char **next, acpi_object_type * return_type)
466{
467 char *start;
468 u32 depth;
469 acpi_object_type type = ACPI_TYPE_INTEGER;
470
471 /* At end of buffer? */
472
473 if (!string || !(*string)) {
474 return (NULL);
475 }
476
477 /* Remove any spaces at the beginning */
478
479 if (*string == ' ') {
480 while (*string && (*string == ' ')) {
481 string++;
482 }
483
484 if (!(*string)) {
485 return (NULL);
486 }
487 }
488
489 switch (*string) {
490 case '"':
491
492 /* This is a quoted string, scan until closing quote */
493
494 string++;
495 start = string;
496 type = ACPI_TYPE_STRING;
497
498 /* Find end of string */
499
500 while (*string && (*string != '"')) {
501 string++;
502 }
503 break;
504
505 case '(':
506
507 /* This is the start of a buffer, scan until closing paren */
508
509 string++;
510 start = string;
511 type = ACPI_TYPE_BUFFER;
512
513 /* Find end of buffer */
514
515 while (*string && (*string != ')')) {
516 string++;
517 }
518 break;
519
520 case '[':
521
522 /* This is the start of a package, scan until closing bracket */
523
524 string++;
525 depth = 1;
526 start = string;
527 type = ACPI_TYPE_PACKAGE;
528
529 /* Find end of package (closing bracket) */
530
531 while (*string) {
532
533 /* Handle String package elements */
534
535 if (*string == '"') {
536 /* Find end of string */
537
538 string++;
539 while (*string && (*string != '"')) {
540 string++;
541 }
542 if (!(*string)) {
543 break;
544 }
545 } else if (*string == '[') {
546 depth++; /* A nested package declaration */
547 } else if (*string == ']') {
548 depth--;
549 if (depth == 0) { /* Found final package closing bracket */
550 break;
551 }
552 }
553
554 string++;
555 }
556 break;
557
558 default:
559
560 start = string;
561
562 /* Find end of token */
563
564 while (*string && (*string != ' ')) {
565 string++;
566 }
567 break;
568 }
569
570 if (!(*string)) {
571 *next = NULL;
572 } else {
573 *string = 0;
574 *next = string + 1;
575 }
576
577 *return_type = type;
578 return (start);
579}
580
581/*******************************************************************************
582 *
583 * FUNCTION: acpi_db_get_line
584 *
585 * PARAMETERS: input_buffer - Command line buffer
586 *
587 * RETURN: Count of arguments to the command
588 *
589 * DESCRIPTION: Get the next command line from the user. Gets entire line
590 * up to the next newline
591 *
592 ******************************************************************************/
593
594static u32 acpi_db_get_line(char *input_buffer)
595{
596 u32 i;
597 u32 count;
598 char *next;
599 char *this;
600
601 if (acpi_ut_safe_strcpy
602 (acpi_gbl_db_parsed_buf, sizeof(acpi_gbl_db_parsed_buf),
603 input_buffer)) {
604 acpi_os_printf
605 ("Buffer overflow while parsing input line (max %u characters)\n",
606 sizeof(acpi_gbl_db_parsed_buf));
607 return (0);
608 }
609
610 this = acpi_gbl_db_parsed_buf;
611 for (i = 0; i < ACPI_DEBUGGER_MAX_ARGS; i++) {
612 acpi_gbl_db_args[i] = acpi_db_get_next_token(this, &next,
613 &acpi_gbl_db_arg_types
614 [i]);
615 if (!acpi_gbl_db_args[i]) {
616 break;
617 }
618
619 this = next;
620 }
621
622 /* Uppercase the actual command */
623
624 if (acpi_gbl_db_args[0]) {
625 acpi_ut_strupr(acpi_gbl_db_args[0]);
626 }
627
628 count = i;
629 if (count) {
630 count--; /* Number of args only */
631 }
632
633 return (count);
634}
635
636/*******************************************************************************
637 *
638 * FUNCTION: acpi_db_match_command
639 *
640 * PARAMETERS: user_command - User command line
641 *
642 * RETURN: Index into command array, -1 if not found
643 *
644 * DESCRIPTION: Search command array for a command match
645 *
646 ******************************************************************************/
647
648static u32 acpi_db_match_command(char *user_command)
649{
650 u32 i;
651
652 if (!user_command || user_command[0] == 0) {
653 return (CMD_NULL);
654 }
655
656 for (i = CMD_FIRST_VALID; acpi_gbl_db_commands[i].name; i++) {
657 if (strstr(acpi_gbl_db_commands[i].name, user_command) ==
658 acpi_gbl_db_commands[i].name) {
659 return (i);
660 }
661 }
662
663 /* Command not recognized */
664
665 return (CMD_NOT_FOUND);
666}
667
668/*******************************************************************************
669 *
670 * FUNCTION: acpi_db_command_dispatch
671 *
672 * PARAMETERS: input_buffer - Command line buffer
673 * walk_state - Current walk
674 * op - Current (executing) parse op
675 *
676 * RETURN: Status
677 *
678 * DESCRIPTION: Command dispatcher.
679 *
680 ******************************************************************************/
681
682acpi_status
683acpi_db_command_dispatch(char *input_buffer,
684 struct acpi_walk_state * walk_state,
685 union acpi_parse_object * op)
686{
687 u32 temp;
688 u32 command_index;
689 u32 param_count;
690 char *command_line;
691 acpi_status status = AE_CTRL_TRUE;
692
693 /* If acpi_terminate has been called, terminate this thread */
694
Lv Zhengaf08f9c2015-10-19 10:25:32 +0800695 if (acpi_gbl_db_terminate_loop) {
Lv Zheng99575102015-10-19 10:25:20 +0800696 return (AE_CTRL_TERMINATE);
697 }
698
699 /* Find command and add to the history buffer */
700
701 param_count = acpi_db_get_line(input_buffer);
702 command_index = acpi_db_match_command(acpi_gbl_db_args[0]);
703 temp = 0;
704
705 /*
706 * We don't want to add the !! command to the history buffer. It
707 * would cause an infinite loop because it would always be the
708 * previous command.
709 */
710 if (command_index != CMD_HISTORY_LAST) {
711 acpi_db_add_to_history(input_buffer);
712 }
713
714 /* Verify that we have the minimum number of params */
715
716 if (param_count < acpi_gbl_db_commands[command_index].min_args) {
717 acpi_os_printf
718 ("%u parameters entered, [%s] requires %u parameters\n",
719 param_count, acpi_gbl_db_commands[command_index].name,
720 acpi_gbl_db_commands[command_index].min_args);
721
722 acpi_db_display_command_info(acpi_gbl_db_commands
723 [command_index].name, FALSE);
724 return (AE_CTRL_TRUE);
725 }
726
727 /* Decode and dispatch the command */
728
729 switch (command_index) {
730 case CMD_NULL:
731
732 if (op) {
733 return (AE_OK);
734 }
735 break;
736
737 case CMD_ALLOCATIONS:
738
739#ifdef ACPI_DBG_TRACK_ALLOCATIONS
740 acpi_ut_dump_allocations((u32)-1, NULL);
741#endif
742 break;
743
744 case CMD_ARGS:
745 case CMD_ARGUMENTS:
746
747 acpi_db_display_arguments();
748 break;
749
750 case CMD_BREAKPOINT:
751
752 acpi_db_set_method_breakpoint(acpi_gbl_db_args[1], walk_state,
753 op);
754 break;
755
756 case CMD_BUSINFO:
757
758 acpi_db_get_bus_info();
759 break;
760
761 case CMD_CALL:
762
763 acpi_db_set_method_call_breakpoint(op);
764 status = AE_OK;
765 break;
766
767 case CMD_DEBUG:
768
769 acpi_db_execute(acpi_gbl_db_args[1],
770 &acpi_gbl_db_args[2], &acpi_gbl_db_arg_types[2],
771 EX_SINGLE_STEP);
772 break;
773
774 case CMD_DISASSEMBLE:
775 case CMD_DISASM:
776
777 (void)acpi_db_disassemble_method(acpi_gbl_db_args[1]);
778 break;
779
780 case CMD_DUMP:
781
782 acpi_db_decode_and_display_object(acpi_gbl_db_args[1],
783 acpi_gbl_db_args[2]);
784 break;
785
786 case CMD_EVALUATE:
787 case CMD_EXECUTE:
788
789 acpi_db_execute(acpi_gbl_db_args[1],
790 &acpi_gbl_db_args[2], &acpi_gbl_db_arg_types[2],
791 EX_NO_SINGLE_STEP);
792 break;
793
794 case CMD_FIND:
795
796 status = acpi_db_find_name_in_namespace(acpi_gbl_db_args[1]);
797 break;
798
799 case CMD_GO:
800
801 acpi_gbl_cm_single_step = FALSE;
802 return (AE_OK);
803
804 case CMD_HANDLERS:
805
806 acpi_db_display_handlers();
807 break;
808
809 case CMD_HELP:
810 case CMD_HELP2:
811
812 acpi_db_display_help(acpi_gbl_db_args[1]);
813 break;
814
815 case CMD_HISTORY:
816
817 acpi_db_display_history();
818 break;
819
820 case CMD_HISTORY_EXE: /* ! command */
821
822 command_line = acpi_db_get_from_history(acpi_gbl_db_args[1]);
823 if (!command_line) {
824 return (AE_CTRL_TRUE);
825 }
826
827 status = acpi_db_command_dispatch(command_line, walk_state, op);
828 return (status);
829
830 case CMD_HISTORY_LAST: /* !! command */
831
832 command_line = acpi_db_get_from_history(NULL);
833 if (!command_line) {
834 return (AE_CTRL_TRUE);
835 }
836
837 status = acpi_db_command_dispatch(command_line, walk_state, op);
838 return (status);
839
840 case CMD_INFORMATION:
841
842 acpi_db_display_method_info(op);
843 break;
844
845 case CMD_INTEGRITY:
846
847 acpi_db_check_integrity();
848 break;
849
850 case CMD_INTO:
851
852 if (op) {
853 acpi_gbl_cm_single_step = TRUE;
854 return (AE_OK);
855 }
856 break;
857
858 case CMD_LEVEL:
859
860 if (param_count == 0) {
861 acpi_os_printf
862 ("Current debug level for file output is: %8.8lX\n",
863 acpi_gbl_db_debug_level);
864 acpi_os_printf
865 ("Current debug level for console output is: %8.8lX\n",
866 acpi_gbl_db_console_debug_level);
867 } else if (param_count == 2) {
868 temp = acpi_gbl_db_console_debug_level;
869 acpi_gbl_db_console_debug_level =
870 strtoul(acpi_gbl_db_args[1], NULL, 16);
871 acpi_os_printf
872 ("Debug Level for console output was %8.8lX, now %8.8lX\n",
873 temp, acpi_gbl_db_console_debug_level);
874 } else {
875 temp = acpi_gbl_db_debug_level;
876 acpi_gbl_db_debug_level =
877 strtoul(acpi_gbl_db_args[1], NULL, 16);
878 acpi_os_printf
879 ("Debug Level for file output was %8.8lX, now %8.8lX\n",
880 temp, acpi_gbl_db_debug_level);
881 }
882 break;
883
884 case CMD_LIST:
885
886 acpi_db_disassemble_aml(acpi_gbl_db_args[1], op);
887 break;
888
889 case CMD_LOCKS:
890
891 acpi_db_display_locks();
892 break;
893
894 case CMD_LOCALS:
895
896 acpi_db_display_locals();
897 break;
898
899 case CMD_METHODS:
900
901 status = acpi_db_display_objects("METHOD", acpi_gbl_db_args[1]);
902 break;
903
904 case CMD_NAMESPACE:
905
906 acpi_db_dump_namespace(acpi_gbl_db_args[1],
907 acpi_gbl_db_args[2]);
908 break;
909
910 case CMD_NOTIFY:
911
912 temp = strtoul(acpi_gbl_db_args[2], NULL, 0);
913 acpi_db_send_notify(acpi_gbl_db_args[1], temp);
914 break;
915
916 case CMD_OBJECTS:
917
918 acpi_ut_strupr(acpi_gbl_db_args[1]);
919 status =
920 acpi_db_display_objects(acpi_gbl_db_args[1],
921 acpi_gbl_db_args[2]);
922 break;
923
924 case CMD_OSI:
925
926 acpi_db_display_interfaces(acpi_gbl_db_args[1],
927 acpi_gbl_db_args[2]);
928 break;
929
930 case CMD_OWNER:
931
932 acpi_db_dump_namespace_by_owner(acpi_gbl_db_args[1],
933 acpi_gbl_db_args[2]);
934 break;
935
936 case CMD_PATHS:
937
938 acpi_db_dump_namespace_paths();
939 break;
940
941 case CMD_PREFIX:
942
943 acpi_db_set_scope(acpi_gbl_db_args[1]);
944 break;
945
946 case CMD_REFERENCES:
947
948 acpi_db_find_references(acpi_gbl_db_args[1]);
949 break;
950
951 case CMD_RESOURCES:
952
953 acpi_db_display_resources(acpi_gbl_db_args[1]);
954 break;
955
956 case CMD_RESULTS:
957
958 acpi_db_display_results();
959 break;
960
961 case CMD_SET:
962
963 acpi_db_set_method_data(acpi_gbl_db_args[1],
964 acpi_gbl_db_args[2],
965 acpi_gbl_db_args[3]);
966 break;
967
968 case CMD_STATS:
969
970 status = acpi_db_display_statistics(acpi_gbl_db_args[1]);
971 break;
972
973 case CMD_STOP:
974
975 return (AE_NOT_IMPLEMENTED);
976
977 case CMD_TABLES:
978
979 acpi_db_display_table_info(acpi_gbl_db_args[1]);
980 break;
981
982 case CMD_TEMPLATE:
983
984 acpi_db_display_template(acpi_gbl_db_args[1]);
985 break;
986
987 case CMD_TRACE:
988
989 acpi_db_trace(acpi_gbl_db_args[1], acpi_gbl_db_args[2],
990 acpi_gbl_db_args[3]);
991 break;
992
993 case CMD_TREE:
994
995 acpi_db_display_calling_tree();
996 break;
997
998 case CMD_TYPE:
999
1000 acpi_db_display_object_type(acpi_gbl_db_args[1]);
1001 break;
1002
1003#ifdef ACPI_APPLICATION
1004
1005 /* Hardware simulation commands. */
1006
1007 case CMD_ENABLEACPI:
1008#if (!ACPI_REDUCED_HARDWARE)
1009
1010 status = acpi_enable();
1011 if (ACPI_FAILURE(status)) {
1012 acpi_os_printf("AcpiEnable failed (Status=%X)\n",
1013 status);
1014 return (status);
1015 }
1016#endif /* !ACPI_REDUCED_HARDWARE */
1017 break;
1018
1019 case CMD_EVENT:
1020
1021 acpi_os_printf("Event command not implemented\n");
1022 break;
1023
1024 case CMD_GPE:
1025
1026 acpi_db_generate_gpe(acpi_gbl_db_args[1], acpi_gbl_db_args[2]);
1027 break;
1028
1029 case CMD_GPES:
1030
1031 acpi_db_display_gpes();
1032 break;
1033
1034 case CMD_SCI:
1035
1036 acpi_db_generate_sci();
1037 break;
1038
1039 case CMD_SLEEP:
1040
1041 status = acpi_db_sleep(acpi_gbl_db_args[1]);
1042 break;
1043
1044 /* File I/O commands. */
1045
1046 case CMD_CLOSE:
1047
1048 acpi_db_close_debug_file();
1049 break;
1050
1051 case CMD_LOAD:
1052
1053 status =
1054 acpi_db_get_table_from_file(acpi_gbl_db_args[1], NULL,
1055 FALSE);
1056 break;
1057
1058 case CMD_OPEN:
1059
1060 acpi_db_open_debug_file(acpi_gbl_db_args[1]);
1061 break;
1062
1063 /* User space commands. */
1064
1065 case CMD_TERMINATE:
1066
1067 acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT);
1068 acpi_ut_subsystem_shutdown();
1069
1070 /*
1071 * TBD: [Restructure] Need some way to re-initialize without
1072 * re-creating the semaphores!
1073 */
1074
Lv Zheng086ab742015-10-19 10:25:42 +08001075 acpi_gbl_db_terminate_loop = TRUE;
Lv Zheng99575102015-10-19 10:25:20 +08001076 /* acpi_initialize (NULL); */
1077 break;
1078
1079 case CMD_THREADS:
1080
1081 acpi_db_create_execution_threads(acpi_gbl_db_args[1],
1082 acpi_gbl_db_args[2],
1083 acpi_gbl_db_args[3]);
1084 break;
1085
1086 /* Debug test commands. */
1087
1088 case CMD_PREDEFINED:
1089
1090 acpi_db_check_predefined_names();
1091 break;
1092
1093 case CMD_TEST:
1094
1095 acpi_db_execute_test(acpi_gbl_db_args[1]);
1096 break;
1097
1098 case CMD_UNLOAD:
1099
1100 acpi_db_unload_acpi_table(acpi_gbl_db_args[1]);
1101 break;
1102#endif
1103
1104 case CMD_EXIT:
1105 case CMD_QUIT:
1106
1107 if (op) {
1108 acpi_os_printf("Method execution terminated\n");
1109 return (AE_CTRL_TERMINATE);
1110 }
1111
1112 if (!acpi_gbl_db_output_to_file) {
1113 acpi_dbg_level = ACPI_DEBUG_DEFAULT;
1114 }
1115#ifdef ACPI_APPLICATION
1116 acpi_db_close_debug_file();
1117#endif
Lv Zhengaf08f9c2015-10-19 10:25:32 +08001118 acpi_gbl_db_terminate_loop = TRUE;
Lv Zheng99575102015-10-19 10:25:20 +08001119 return (AE_CTRL_TERMINATE);
1120
1121 case CMD_NOT_FOUND:
1122 default:
1123
1124 acpi_os_printf("%s: unknown command\n", acpi_gbl_db_args[0]);
1125 return (AE_CTRL_TRUE);
1126 }
1127
1128 if (ACPI_SUCCESS(status)) {
1129 status = AE_CTRL_TRUE;
1130 }
1131
1132 return (status);
1133}
1134
1135/*******************************************************************************
1136 *
1137 * FUNCTION: acpi_db_execute_thread
1138 *
1139 * PARAMETERS: context - Not used
1140 *
1141 * RETURN: None
1142 *
1143 * DESCRIPTION: Debugger execute thread. Waits for a command line, then
1144 * simply dispatches it.
1145 *
1146 ******************************************************************************/
1147
1148void ACPI_SYSTEM_XFACE acpi_db_execute_thread(void *context)
1149{
Lv Zheng99575102015-10-19 10:25:20 +08001150
Lv Zhengf8d31482015-12-03 10:42:46 +08001151 (void)acpi_db_user_commands();
Lv Zhengaf08f9c2015-10-19 10:25:32 +08001152 acpi_gbl_db_threads_terminated = TRUE;
Lv Zheng99575102015-10-19 10:25:20 +08001153}
1154
1155/*******************************************************************************
1156 *
Lv Zheng99575102015-10-19 10:25:20 +08001157 * FUNCTION: acpi_db_user_commands
1158 *
Lv Zhengf8d31482015-12-03 10:42:46 +08001159 * PARAMETERS: None
Lv Zheng99575102015-10-19 10:25:20 +08001160 *
1161 * RETURN: None
1162 *
1163 * DESCRIPTION: Command line execution for the AML debugger. Commands are
1164 * matched and dispatched here.
1165 *
1166 ******************************************************************************/
1167
Lv Zhengf8d31482015-12-03 10:42:46 +08001168acpi_status acpi_db_user_commands(void)
Lv Zheng99575102015-10-19 10:25:20 +08001169{
1170 acpi_status status = AE_OK;
1171
1172 acpi_os_printf("\n");
1173
1174 /* TBD: [Restructure] Need a separate command line buffer for step mode */
1175
Lv Zhengaf08f9c2015-10-19 10:25:32 +08001176 while (!acpi_gbl_db_terminate_loop) {
Lv Zheng99575102015-10-19 10:25:20 +08001177
Lv Zhengf8d31482015-12-03 10:42:46 +08001178 /* Wait the readiness of the command */
Lv Zheng99575102015-10-19 10:25:20 +08001179
Lv Zhengf8d31482015-12-03 10:42:46 +08001180 status = acpi_os_wait_command_ready();
Lv Zheng99575102015-10-19 10:25:20 +08001181 if (ACPI_FAILURE(status)) {
Lv Zhengf8d31482015-12-03 10:42:46 +08001182 break;
Lv Zheng99575102015-10-19 10:25:20 +08001183 }
1184
Lv Zhengf8d31482015-12-03 10:42:46 +08001185 /* Just call to the command line interpreter */
Lv Zheng99575102015-10-19 10:25:20 +08001186
Lv Zhengf8d31482015-12-03 10:42:46 +08001187 acpi_gbl_method_executing = FALSE;
1188 acpi_gbl_step_to_next_call = FALSE;
Lv Zheng99575102015-10-19 10:25:20 +08001189
Lv Zhengf8d31482015-12-03 10:42:46 +08001190 (void)acpi_db_command_dispatch(acpi_gbl_db_line_buf, NULL,
1191 NULL);
Lv Zheng99575102015-10-19 10:25:20 +08001192
Lv Zhengf8d31482015-12-03 10:42:46 +08001193 /* Notify the completion of the command */
1194
1195 status = acpi_os_notify_command_complete();
1196 if (ACPI_FAILURE(status)) {
1197 break;
Lv Zheng99575102015-10-19 10:25:20 +08001198 }
1199 }
1200
Lv Zhengf8d31482015-12-03 10:42:46 +08001201 if (ACPI_FAILURE(status) && status != AE_CTRL_TERMINATE) {
1202 ACPI_EXCEPTION((AE_INFO, status, "While parsing command line"));
1203 }
Lv Zheng99575102015-10-19 10:25:20 +08001204 return (status);
1205}