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