195857638SErik Schmauss // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
299575102SLv Zheng /*******************************************************************************
399575102SLv Zheng *
499575102SLv Zheng * Module Name: dbinput - user front-end to the AML debugger
599575102SLv Zheng *
699575102SLv Zheng ******************************************************************************/
799575102SLv Zheng
899575102SLv Zheng #include <acpi/acpi.h>
999575102SLv Zheng #include "accommon.h"
1099575102SLv Zheng #include "acdebug.h"
1199575102SLv Zheng
122ba7379bSBob Moore #ifdef ACPI_APPLICATION
132ba7379bSBob Moore #include "acapps.h"
142ba7379bSBob Moore #endif
152ba7379bSBob Moore
1699575102SLv Zheng #define _COMPONENT ACPI_CA_DEBUGGER
1799575102SLv Zheng ACPI_MODULE_NAME("dbinput")
1899575102SLv Zheng
1999575102SLv Zheng /* Local prototypes */
2099575102SLv Zheng static u32 acpi_db_get_line(char *input_buffer);
2199575102SLv Zheng
2299575102SLv Zheng static u32 acpi_db_match_command(char *user_command);
2399575102SLv Zheng
240dfaaa3dSBob Moore static void acpi_db_display_command_info(const char *command, u8 display_all);
2599575102SLv Zheng
2699575102SLv Zheng static void acpi_db_display_help(char *command);
2799575102SLv Zheng
2899575102SLv Zheng static u8
290dfaaa3dSBob Moore acpi_db_match_command_help(const char *command,
3099575102SLv Zheng const struct acpi_db_command_help *help);
3199575102SLv Zheng
3299575102SLv Zheng /*
3399575102SLv Zheng * Top-level debugger commands.
3499575102SLv Zheng *
3599575102SLv Zheng * This list of commands must match the string table below it
3699575102SLv Zheng */
3799575102SLv Zheng enum acpi_ex_debugger_commands {
3899575102SLv Zheng CMD_NOT_FOUND = 0,
3999575102SLv Zheng CMD_NULL,
406218ab30SBob Moore CMD_ALL,
4199575102SLv Zheng CMD_ALLOCATIONS,
4299575102SLv Zheng CMD_ARGS,
4399575102SLv Zheng CMD_ARGUMENTS,
4499575102SLv Zheng CMD_BREAKPOINT,
4599575102SLv Zheng CMD_BUSINFO,
4699575102SLv Zheng CMD_CALL,
4799575102SLv Zheng CMD_DEBUG,
4899575102SLv Zheng CMD_DISASSEMBLE,
4999575102SLv Zheng CMD_DISASM,
5099575102SLv Zheng CMD_DUMP,
5199575102SLv Zheng CMD_EVALUATE,
5299575102SLv Zheng CMD_EXECUTE,
5399575102SLv Zheng CMD_EXIT,
545fd03328SErik Schmauss CMD_FIELDS,
5599575102SLv Zheng CMD_FIND,
5699575102SLv Zheng CMD_GO,
5799575102SLv Zheng CMD_HANDLERS,
5899575102SLv Zheng CMD_HELP,
5999575102SLv Zheng CMD_HELP2,
6099575102SLv Zheng CMD_HISTORY,
6199575102SLv Zheng CMD_HISTORY_EXE,
6299575102SLv Zheng CMD_HISTORY_LAST,
6399575102SLv Zheng CMD_INFORMATION,
6499575102SLv Zheng CMD_INTEGRITY,
6599575102SLv Zheng CMD_INTO,
6699575102SLv Zheng CMD_LEVEL,
6799575102SLv Zheng CMD_LIST,
6899575102SLv Zheng CMD_LOCALS,
6999575102SLv Zheng CMD_LOCKS,
7099575102SLv Zheng CMD_METHODS,
7199575102SLv Zheng CMD_NAMESPACE,
7299575102SLv Zheng CMD_NOTIFY,
7399575102SLv Zheng CMD_OBJECTS,
7499575102SLv Zheng CMD_OSI,
7599575102SLv Zheng CMD_OWNER,
7699575102SLv Zheng CMD_PATHS,
7799575102SLv Zheng CMD_PREDEFINED,
7899575102SLv Zheng CMD_PREFIX,
7999575102SLv Zheng CMD_QUIT,
8099575102SLv Zheng CMD_REFERENCES,
8199575102SLv Zheng CMD_RESOURCES,
8299575102SLv Zheng CMD_RESULTS,
8399575102SLv Zheng CMD_SET,
8499575102SLv Zheng CMD_STATS,
8599575102SLv Zheng CMD_STOP,
8699575102SLv Zheng CMD_TABLES,
8799575102SLv Zheng CMD_TEMPLATE,
8899575102SLv Zheng CMD_TRACE,
8999575102SLv Zheng CMD_TREE,
9099575102SLv Zheng CMD_TYPE,
9199575102SLv Zheng #ifdef ACPI_APPLICATION
9299575102SLv Zheng CMD_ENABLEACPI,
9399575102SLv Zheng CMD_EVENT,
9499575102SLv Zheng CMD_GPE,
9599575102SLv Zheng CMD_GPES,
9699575102SLv Zheng CMD_SCI,
9799575102SLv Zheng CMD_SLEEP,
9899575102SLv Zheng
9999575102SLv Zheng CMD_CLOSE,
10099575102SLv Zheng CMD_LOAD,
10199575102SLv Zheng CMD_OPEN,
10299575102SLv Zheng CMD_UNLOAD,
10399575102SLv Zheng
10499575102SLv Zheng CMD_TERMINATE,
105060c859dSBob Moore CMD_BACKGROUND,
10699575102SLv Zheng CMD_THREADS,
10799575102SLv Zheng
10899575102SLv Zheng CMD_TEST,
109*b0f2e7d7SJose Marinho CMD_INTERRUPT,
11099575102SLv Zheng #endif
11199575102SLv Zheng };
11299575102SLv Zheng
11399575102SLv Zheng #define CMD_FIRST_VALID 2
11499575102SLv Zheng
11599575102SLv Zheng /* Second parameter is the required argument count */
11699575102SLv Zheng
11799575102SLv Zheng static const struct acpi_db_command_info acpi_gbl_db_commands[] = {
11899575102SLv Zheng {"<NOT FOUND>", 0},
11999575102SLv Zheng {"<NULL>", 0},
1206218ab30SBob Moore {"ALL", 1},
12199575102SLv Zheng {"ALLOCATIONS", 0},
12299575102SLv Zheng {"ARGS", 0},
12399575102SLv Zheng {"ARGUMENTS", 0},
12499575102SLv Zheng {"BREAKPOINT", 1},
12599575102SLv Zheng {"BUSINFO", 0},
12699575102SLv Zheng {"CALL", 0},
12799575102SLv Zheng {"DEBUG", 1},
12899575102SLv Zheng {"DISASSEMBLE", 1},
12999575102SLv Zheng {"DISASM", 1},
13099575102SLv Zheng {"DUMP", 1},
13199575102SLv Zheng {"EVALUATE", 1},
13299575102SLv Zheng {"EXECUTE", 1},
13399575102SLv Zheng {"EXIT", 0},
1345fd03328SErik Schmauss {"FIELDS", 1},
13599575102SLv Zheng {"FIND", 1},
13699575102SLv Zheng {"GO", 0},
13799575102SLv Zheng {"HANDLERS", 0},
13899575102SLv Zheng {"HELP", 0},
13999575102SLv Zheng {"?", 0},
14099575102SLv Zheng {"HISTORY", 0},
14199575102SLv Zheng {"!", 1},
14299575102SLv Zheng {"!!", 0},
14399575102SLv Zheng {"INFORMATION", 0},
14499575102SLv Zheng {"INTEGRITY", 0},
14599575102SLv Zheng {"INTO", 0},
14699575102SLv Zheng {"LEVEL", 0},
14799575102SLv Zheng {"LIST", 0},
14899575102SLv Zheng {"LOCALS", 0},
14999575102SLv Zheng {"LOCKS", 0},
15099575102SLv Zheng {"METHODS", 0},
15199575102SLv Zheng {"NAMESPACE", 0},
15299575102SLv Zheng {"NOTIFY", 2},
15399575102SLv Zheng {"OBJECTS", 0},
15499575102SLv Zheng {"OSI", 0},
15599575102SLv Zheng {"OWNER", 1},
15699575102SLv Zheng {"PATHS", 0},
15799575102SLv Zheng {"PREDEFINED", 0},
15899575102SLv Zheng {"PREFIX", 0},
15999575102SLv Zheng {"QUIT", 0},
16099575102SLv Zheng {"REFERENCES", 1},
16199575102SLv Zheng {"RESOURCES", 0},
16299575102SLv Zheng {"RESULTS", 0},
16399575102SLv Zheng {"SET", 3},
16499575102SLv Zheng {"STATS", 1},
16599575102SLv Zheng {"STOP", 0},
16699575102SLv Zheng {"TABLES", 0},
16799575102SLv Zheng {"TEMPLATE", 1},
16899575102SLv Zheng {"TRACE", 1},
16999575102SLv Zheng {"TREE", 0},
17099575102SLv Zheng {"TYPE", 1},
17199575102SLv Zheng #ifdef ACPI_APPLICATION
17299575102SLv Zheng {"ENABLEACPI", 0},
17399575102SLv Zheng {"EVENT", 1},
17499575102SLv Zheng {"GPE", 1},
17599575102SLv Zheng {"GPES", 0},
17699575102SLv Zheng {"SCI", 0},
17799575102SLv Zheng {"SLEEP", 0},
17899575102SLv Zheng
17999575102SLv Zheng {"CLOSE", 0},
18099575102SLv Zheng {"LOAD", 1},
18199575102SLv Zheng {"OPEN", 1},
18299575102SLv Zheng {"UNLOAD", 1},
18399575102SLv Zheng
18499575102SLv Zheng {"TERMINATE", 0},
185060c859dSBob Moore {"BACKGROUND", 1},
18699575102SLv Zheng {"THREADS", 3},
18799575102SLv Zheng
18899575102SLv Zheng {"TEST", 1},
189*b0f2e7d7SJose Marinho {"INTERRUPT", 1},
19099575102SLv Zheng #endif
19199575102SLv Zheng {NULL, 0}
19299575102SLv Zheng };
19399575102SLv Zheng
19499575102SLv Zheng /*
19599575102SLv Zheng * Help for all debugger commands. First argument is the number of lines
19699575102SLv Zheng * of help to output for the command.
197060c859dSBob Moore *
198060c859dSBob Moore * Note: Some commands are not supported by the kernel-level version of
199060c859dSBob Moore * the debugger.
20099575102SLv Zheng */
20199575102SLv Zheng static const struct acpi_db_command_help acpi_gbl_db_command_help[] = {
202060c859dSBob Moore {0, "\nNamespace Access:", "\n"},
20399575102SLv Zheng {1, " Businfo", "Display system bus info\n"},
20499575102SLv Zheng {1, " Disassemble <Method>", "Disassemble a control method\n"},
20599575102SLv Zheng {1, " Find <AcpiName> (? is wildcard)",
20699575102SLv Zheng "Find ACPI name(s) with wildcards\n"},
20799575102SLv Zheng {1, " Integrity", "Validate namespace integrity\n"},
20899575102SLv Zheng {1, " Methods", "Display list of loaded control methods\n"},
2095fd03328SErik Schmauss {1, " Fields <AddressSpaceId>",
2105fd03328SErik Schmauss "Display list of loaded field units by space ID\n"},
21199575102SLv Zheng {1, " Namespace [Object] [Depth]",
21299575102SLv Zheng "Display loaded namespace tree/subtree\n"},
21399575102SLv Zheng {1, " Notify <Object> <Value>", "Send a notification on Object\n"},
21499575102SLv Zheng {1, " Objects [ObjectType]",
21599575102SLv Zheng "Display summary of all objects or just given type\n"},
21699575102SLv Zheng {1, " Owner <OwnerId> [Depth]",
21799575102SLv Zheng "Display loaded namespace by object owner\n"},
21899575102SLv Zheng {1, " Paths", "Display full pathnames of namespace objects\n"},
21999575102SLv Zheng {1, " Predefined", "Check all predefined names\n"},
22099575102SLv Zheng {1, " Prefix [<Namepath>]", "Set or Get current execution prefix\n"},
22199575102SLv Zheng {1, " References <Addr>", "Find all references to object at addr\n"},
22299575102SLv Zheng {1, " Resources [DeviceName]",
22399575102SLv Zheng "Display Device resources (no arg = all devices)\n"},
22499575102SLv Zheng {1, " Set N <NamedObject> <Value>", "Set value for named integer\n"},
22599575102SLv Zheng {1, " Template <Object>", "Format/dump a Buffer/ResourceTemplate\n"},
22699575102SLv Zheng {1, " Type <Object>", "Display object type\n"},
22799575102SLv Zheng
228060c859dSBob Moore {0, "\nControl Method Execution:", "\n"},
2296218ab30SBob Moore {1, " All <NameSeg>", "Evaluate all objects named NameSeg\n"},
230060c859dSBob Moore {1, " Evaluate <Namepath> [Arguments]",
231060c859dSBob Moore "Evaluate object or control method\n"},
232060c859dSBob Moore {1, " Execute <Namepath> [Arguments]", "Synonym for Evaluate\n"},
233060c859dSBob Moore #ifdef ACPI_APPLICATION
234060c859dSBob Moore {1, " Background <Namepath> [Arguments]",
235060c859dSBob Moore "Evaluate object/method in a separate thread\n"},
236060c859dSBob Moore {1, " Thread <Threads><Loops><NamePath>",
237060c859dSBob Moore "Spawn threads to execute method(s)\n"},
238060c859dSBob Moore #endif
239060c859dSBob Moore {1, " Debug <Namepath> [Arguments]", "Single-Step a control method\n"},
240060c859dSBob Moore {7, " [Arguments] formats:", "Control method argument formats\n"},
241060c859dSBob Moore {1, " Hex Integer", "Integer\n"},
242060c859dSBob Moore {1, " \"Ascii String\"", "String\n"},
243060c859dSBob Moore {1, " (Hex Byte List)", "Buffer\n"},
244060c859dSBob Moore {1, " (01 42 7A BF)", "Buffer example (4 bytes)\n"},
245060c859dSBob Moore {1, " [Package Element List]", "Package\n"},
246060c859dSBob Moore {1, " [0x01 0x1234 \"string\"]",
247060c859dSBob Moore "Package example (3 elements)\n"},
248060c859dSBob Moore
249060c859dSBob Moore {0, "\nMiscellaneous:", "\n"},
250060c859dSBob Moore {1, " Allocations", "Display list of current memory allocations\n"},
251060c859dSBob Moore {2, " Dump <Address>|<Namepath>", "\n"},
252060c859dSBob Moore {0, " [Byte|Word|Dword|Qword]",
253060c859dSBob Moore "Display ACPI objects or memory\n"},
254060c859dSBob Moore {1, " Handlers", "Info about global handlers\n"},
255060c859dSBob Moore {1, " Help [Command]", "This help screen or individual command\n"},
256060c859dSBob Moore {1, " History", "Display command history buffer\n"},
257060c859dSBob Moore {1, " Level <DebugLevel>] [console]",
258060c859dSBob Moore "Get/Set debug level for file or console\n"},
259060c859dSBob Moore {1, " Locks", "Current status of internal mutexes\n"},
260060c859dSBob Moore {1, " Osi [Install|Remove <name>]",
261060c859dSBob Moore "Display or modify global _OSI list\n"},
262060c859dSBob Moore {1, " Quit or Exit", "Exit this command\n"},
263060c859dSBob Moore {8, " Stats <SubCommand>",
264060c859dSBob Moore "Display namespace and memory statistics\n"},
265060c859dSBob Moore {1, " Allocations", "Display list of current memory allocations\n"},
266060c859dSBob Moore {1, " Memory", "Dump internal memory lists\n"},
267060c859dSBob Moore {1, " Misc", "Namespace search and mutex stats\n"},
268060c859dSBob Moore {1, " Objects", "Summary of namespace objects\n"},
269060c859dSBob Moore {1, " Sizes", "Sizes for each of the internal objects\n"},
270060c859dSBob Moore {1, " Stack", "Display CPU stack usage\n"},
271060c859dSBob Moore {1, " Tables", "Info about current ACPI table(s)\n"},
272060c859dSBob Moore {1, " Tables", "Display info about loaded ACPI tables\n"},
273060c859dSBob Moore #ifdef ACPI_APPLICATION
274060c859dSBob Moore {1, " Terminate", "Delete namespace and all internal objects\n"},
275060c859dSBob Moore #endif
276060c859dSBob Moore {1, " ! <CommandNumber>", "Execute command from history buffer\n"},
277060c859dSBob Moore {1, " !!", "Execute last command again\n"},
278060c859dSBob Moore
279060c859dSBob Moore {0, "\nMethod and Namespace Debugging:", "\n"},
280060c859dSBob Moore {5, " Trace <State> [<Namepath>] [Once]",
281060c859dSBob Moore "Trace control method execution\n"},
282060c859dSBob Moore {1, " Enable", "Enable all messages\n"},
283060c859dSBob Moore {1, " Disable", "Disable tracing\n"},
284060c859dSBob Moore {1, " Method", "Enable method execution messages\n"},
285060c859dSBob Moore {1, " Opcode", "Enable opcode execution messages\n"},
286060c859dSBob Moore {3, " Test <TestName>", "Invoke a debug test\n"},
287060c859dSBob Moore {1, " Objects", "Read/write/compare all namespace data objects\n"},
288060c859dSBob Moore {1, " Predefined",
289060c859dSBob Moore "Validate all ACPI predefined names (_STA, etc.)\n"},
290060c859dSBob Moore {1, " Execute predefined",
291060c859dSBob Moore "Execute all predefined (public) methods\n"},
292060c859dSBob Moore
293060c859dSBob Moore {0, "\nControl Method Single-Step Execution:", "\n"},
29499575102SLv Zheng {1, " Arguments (or Args)", "Display method arguments\n"},
29599575102SLv Zheng {1, " Breakpoint <AmlOffset>", "Set an AML execution breakpoint\n"},
29699575102SLv Zheng {1, " Call", "Run to next control method invocation\n"},
29799575102SLv Zheng {1, " Go", "Allow method to run to completion\n"},
29899575102SLv Zheng {1, " Information", "Display info about the current method\n"},
29999575102SLv Zheng {1, " Into", "Step into (not over) a method call\n"},
30099575102SLv Zheng {1, " List [# of Aml Opcodes]", "Display method ASL statements\n"},
30199575102SLv Zheng {1, " Locals", "Display method local variables\n"},
30299575102SLv Zheng {1, " Results", "Display method result stack\n"},
30399575102SLv Zheng {1, " Set <A|L> <#> <Value>", "Set method data (Arguments/Locals)\n"},
30499575102SLv Zheng {1, " Stop", "Terminate control method\n"},
30599575102SLv Zheng {1, " Tree", "Display control method calling tree\n"},
30699575102SLv Zheng {1, " <Enter>", "Single step next AML opcode (over calls)\n"},
30799575102SLv Zheng
30899575102SLv Zheng #ifdef ACPI_APPLICATION
309060c859dSBob Moore {0, "\nFile Operations:", "\n"},
31099575102SLv Zheng {1, " Close", "Close debug output file\n"},
31199575102SLv Zheng {1, " Load <Input Filename>", "Load ACPI table from a file\n"},
31299575102SLv Zheng {1, " Open <Output Filename>", "Open a file for debug output\n"},
31399575102SLv Zheng {1, " Unload <Namepath>",
31499575102SLv Zheng "Unload an ACPI table via namespace object\n"},
31599575102SLv Zheng
316060c859dSBob Moore {0, "\nHardware Simulation:", "\n"},
317060c859dSBob Moore {1, " EnableAcpi", "Enable ACPI (hardware) mode\n"},
318060c859dSBob Moore {1, " Event <F|G> <Value>", "Generate AcpiEvent (Fixed/GPE)\n"},
319060c859dSBob Moore {1, " Gpe <GpeNum> [GpeBlockDevice]", "Simulate a GPE\n"},
320060c859dSBob Moore {1, " Gpes", "Display info on all GPE devices\n"},
321060c859dSBob Moore {1, " Sci", "Generate an SCI\n"},
322060c859dSBob Moore {1, " Sleep [SleepState]", "Simulate sleep/wake sequence(s) (0-5)\n"},
323*b0f2e7d7SJose Marinho {1, " Interrupt <GSIV>", "Simulate an interrupt\n"},
32499575102SLv Zheng #endif
32599575102SLv Zheng {0, NULL, NULL}
32699575102SLv Zheng };
32799575102SLv Zheng
32899575102SLv Zheng /*******************************************************************************
32999575102SLv Zheng *
33099575102SLv Zheng * FUNCTION: acpi_db_match_command_help
33199575102SLv Zheng *
33299575102SLv Zheng * PARAMETERS: command - Command string to match
33399575102SLv Zheng * help - Help table entry to attempt match
33499575102SLv Zheng *
33599575102SLv Zheng * RETURN: TRUE if command matched, FALSE otherwise
33699575102SLv Zheng *
33799575102SLv Zheng * DESCRIPTION: Attempt to match a command in the help table in order to
33899575102SLv Zheng * print help information for a single command.
33999575102SLv Zheng *
34099575102SLv Zheng ******************************************************************************/
34199575102SLv Zheng
34299575102SLv Zheng static u8
acpi_db_match_command_help(const char * command,const struct acpi_db_command_help * help)3430dfaaa3dSBob Moore acpi_db_match_command_help(const char *command,
34499575102SLv Zheng const struct acpi_db_command_help *help)
34599575102SLv Zheng {
34699575102SLv Zheng char *invocation = help->invocation;
34799575102SLv Zheng u32 line_count;
34899575102SLv Zheng
34999575102SLv Zheng /* Valid commands in the help table begin with a couple of spaces */
35099575102SLv Zheng
35199575102SLv Zheng if (*invocation != ' ') {
35299575102SLv Zheng return (FALSE);
35399575102SLv Zheng }
35499575102SLv Zheng
35599575102SLv Zheng while (*invocation == ' ') {
35699575102SLv Zheng invocation++;
35799575102SLv Zheng }
35899575102SLv Zheng
35999575102SLv Zheng /* Match command name (full command or substring) */
36099575102SLv Zheng
36199575102SLv Zheng while ((*command) && (*invocation) && (*invocation != ' ')) {
36299575102SLv Zheng if (tolower((int)*command) != tolower((int)*invocation)) {
36399575102SLv Zheng return (FALSE);
36499575102SLv Zheng }
36599575102SLv Zheng
36699575102SLv Zheng invocation++;
36799575102SLv Zheng command++;
36899575102SLv Zheng }
36999575102SLv Zheng
37099575102SLv Zheng /* Print the appropriate number of help lines */
37199575102SLv Zheng
37299575102SLv Zheng line_count = help->line_count;
37399575102SLv Zheng while (line_count) {
37499575102SLv Zheng acpi_os_printf("%-38s : %s", help->invocation,
37599575102SLv Zheng help->description);
37699575102SLv Zheng help++;
37799575102SLv Zheng line_count--;
37899575102SLv Zheng }
37999575102SLv Zheng
38099575102SLv Zheng return (TRUE);
38199575102SLv Zheng }
38299575102SLv Zheng
38399575102SLv Zheng /*******************************************************************************
38499575102SLv Zheng *
38599575102SLv Zheng * FUNCTION: acpi_db_display_command_info
38699575102SLv Zheng *
38799575102SLv Zheng * PARAMETERS: command - Command string to match
38899575102SLv Zheng * display_all - Display all matching commands, or just
38999575102SLv Zheng * the first one (substring match)
39099575102SLv Zheng *
39199575102SLv Zheng * RETURN: None
39299575102SLv Zheng *
39399575102SLv Zheng * DESCRIPTION: Display help information for a Debugger command.
39499575102SLv Zheng *
39599575102SLv Zheng ******************************************************************************/
39699575102SLv Zheng
acpi_db_display_command_info(const char * command,u8 display_all)3970dfaaa3dSBob Moore static void acpi_db_display_command_info(const char *command, u8 display_all)
39899575102SLv Zheng {
39999575102SLv Zheng const struct acpi_db_command_help *next;
40099575102SLv Zheng u8 matched;
40199575102SLv Zheng
40299575102SLv Zheng next = acpi_gbl_db_command_help;
40399575102SLv Zheng while (next->invocation) {
40499575102SLv Zheng matched = acpi_db_match_command_help(command, next);
40599575102SLv Zheng if (!display_all && matched) {
40699575102SLv Zheng return;
40799575102SLv Zheng }
40899575102SLv Zheng
40999575102SLv Zheng next++;
41099575102SLv Zheng }
41199575102SLv Zheng }
41299575102SLv Zheng
41399575102SLv Zheng /*******************************************************************************
41499575102SLv Zheng *
41599575102SLv Zheng * FUNCTION: acpi_db_display_help
41699575102SLv Zheng *
41799575102SLv Zheng * PARAMETERS: command - Optional command string to display help.
41899575102SLv Zheng * if not specified, all debugger command
41999575102SLv Zheng * help strings are displayed
42099575102SLv Zheng *
42199575102SLv Zheng * RETURN: None
42299575102SLv Zheng *
42399575102SLv Zheng * DESCRIPTION: Display help for a single debugger command, or all of them.
42499575102SLv Zheng *
42599575102SLv Zheng ******************************************************************************/
42699575102SLv Zheng
acpi_db_display_help(char * command)42799575102SLv Zheng static void acpi_db_display_help(char *command)
42899575102SLv Zheng {
42999575102SLv Zheng const struct acpi_db_command_help *next = acpi_gbl_db_command_help;
43099575102SLv Zheng
43199575102SLv Zheng if (!command) {
43299575102SLv Zheng
43399575102SLv Zheng /* No argument to help, display help for all commands */
43499575102SLv Zheng
435060c859dSBob Moore acpi_os_printf("\nSummary of AML Debugger Commands\n\n");
436060c859dSBob Moore
43799575102SLv Zheng while (next->invocation) {
43899575102SLv Zheng acpi_os_printf("%-38s%s", next->invocation,
43999575102SLv Zheng next->description);
44099575102SLv Zheng next++;
44199575102SLv Zheng }
442060c859dSBob Moore acpi_os_printf("\n");
443060c859dSBob Moore
44499575102SLv Zheng } else {
445465e490dSColin Ian King /* Display help for all commands that match the substring */
44699575102SLv Zheng
44799575102SLv Zheng acpi_db_display_command_info(command, TRUE);
44899575102SLv Zheng }
44999575102SLv Zheng }
45099575102SLv Zheng
45199575102SLv Zheng /*******************************************************************************
45299575102SLv Zheng *
45399575102SLv Zheng * FUNCTION: acpi_db_get_next_token
45499575102SLv Zheng *
45599575102SLv Zheng * PARAMETERS: string - Command buffer
45699575102SLv Zheng * next - Return value, end of next token
45799575102SLv Zheng *
45899575102SLv Zheng * RETURN: Pointer to the start of the next token.
45999575102SLv Zheng *
46099575102SLv Zheng * DESCRIPTION: Command line parsing. Get the next token on the command line
46199575102SLv Zheng *
46299575102SLv Zheng ******************************************************************************/
46399575102SLv Zheng
acpi_db_get_next_token(char * string,char ** next,acpi_object_type * return_type)46499575102SLv Zheng char *acpi_db_get_next_token(char *string,
46599575102SLv Zheng char **next, acpi_object_type *return_type)
46699575102SLv Zheng {
46799575102SLv Zheng char *start;
46899575102SLv Zheng u32 depth;
46999575102SLv Zheng acpi_object_type type = ACPI_TYPE_INTEGER;
47099575102SLv Zheng
47199575102SLv Zheng /* At end of buffer? */
47299575102SLv Zheng
47399575102SLv Zheng if (!string || !(*string)) {
47499575102SLv Zheng return (NULL);
47599575102SLv Zheng }
47699575102SLv Zheng
4779a1ae804SBob Moore /* Remove any spaces at the beginning, ignore blank lines */
47899575102SLv Zheng
479c01df543SBob Moore while (*string && isspace((int)*string)) {
48099575102SLv Zheng string++;
48199575102SLv Zheng }
48299575102SLv Zheng
48399575102SLv Zheng if (!(*string)) {
48499575102SLv Zheng return (NULL);
48599575102SLv Zheng }
48699575102SLv Zheng
48799575102SLv Zheng switch (*string) {
48899575102SLv Zheng case '"':
48999575102SLv Zheng
49099575102SLv Zheng /* This is a quoted string, scan until closing quote */
49199575102SLv Zheng
49299575102SLv Zheng string++;
49399575102SLv Zheng start = string;
49499575102SLv Zheng type = ACPI_TYPE_STRING;
49599575102SLv Zheng
49699575102SLv Zheng /* Find end of string */
49799575102SLv Zheng
49899575102SLv Zheng while (*string && (*string != '"')) {
49999575102SLv Zheng string++;
50099575102SLv Zheng }
50199575102SLv Zheng break;
50299575102SLv Zheng
50399575102SLv Zheng case '(':
50499575102SLv Zheng
50599575102SLv Zheng /* This is the start of a buffer, scan until closing paren */
50699575102SLv Zheng
50799575102SLv Zheng string++;
50899575102SLv Zheng start = string;
50999575102SLv Zheng type = ACPI_TYPE_BUFFER;
51099575102SLv Zheng
51199575102SLv Zheng /* Find end of buffer */
51299575102SLv Zheng
51399575102SLv Zheng while (*string && (*string != ')')) {
51499575102SLv Zheng string++;
51599575102SLv Zheng }
51699575102SLv Zheng break;
51799575102SLv Zheng
51876093506SErik Schmauss case '{':
51976093506SErik Schmauss
52076093506SErik Schmauss /* This is the start of a field unit, scan until closing brace */
52176093506SErik Schmauss
52276093506SErik Schmauss string++;
52376093506SErik Schmauss start = string;
52476093506SErik Schmauss type = ACPI_TYPE_FIELD_UNIT;
52576093506SErik Schmauss
52676093506SErik Schmauss /* Find end of buffer */
52776093506SErik Schmauss
52876093506SErik Schmauss while (*string && (*string != '}')) {
52976093506SErik Schmauss string++;
53076093506SErik Schmauss }
53176093506SErik Schmauss break;
53276093506SErik Schmauss
53399575102SLv Zheng case '[':
53499575102SLv Zheng
53599575102SLv Zheng /* This is the start of a package, scan until closing bracket */
53699575102SLv Zheng
53799575102SLv Zheng string++;
53899575102SLv Zheng depth = 1;
53999575102SLv Zheng start = string;
54099575102SLv Zheng type = ACPI_TYPE_PACKAGE;
54199575102SLv Zheng
54299575102SLv Zheng /* Find end of package (closing bracket) */
54399575102SLv Zheng
54499575102SLv Zheng while (*string) {
54599575102SLv Zheng
54699575102SLv Zheng /* Handle String package elements */
54799575102SLv Zheng
54899575102SLv Zheng if (*string == '"') {
54999575102SLv Zheng /* Find end of string */
55099575102SLv Zheng
55199575102SLv Zheng string++;
55299575102SLv Zheng while (*string && (*string != '"')) {
55399575102SLv Zheng string++;
55499575102SLv Zheng }
55599575102SLv Zheng if (!(*string)) {
55699575102SLv Zheng break;
55799575102SLv Zheng }
55899575102SLv Zheng } else if (*string == '[') {
55999575102SLv Zheng depth++; /* A nested package declaration */
56099575102SLv Zheng } else if (*string == ']') {
56199575102SLv Zheng depth--;
56299575102SLv Zheng if (depth == 0) { /* Found final package closing bracket */
56399575102SLv Zheng break;
56499575102SLv Zheng }
56599575102SLv Zheng }
56699575102SLv Zheng
56799575102SLv Zheng string++;
56899575102SLv Zheng }
56999575102SLv Zheng break;
57099575102SLv Zheng
57199575102SLv Zheng default:
57299575102SLv Zheng
57399575102SLv Zheng start = string;
57499575102SLv Zheng
57599575102SLv Zheng /* Find end of token */
57699575102SLv Zheng
577c01df543SBob Moore while (*string && !isspace((int)*string)) {
57899575102SLv Zheng string++;
57999575102SLv Zheng }
58099575102SLv Zheng break;
58199575102SLv Zheng }
58299575102SLv Zheng
58399575102SLv Zheng if (!(*string)) {
58499575102SLv Zheng *next = NULL;
58599575102SLv Zheng } else {
58699575102SLv Zheng *string = 0;
58799575102SLv Zheng *next = string + 1;
58899575102SLv Zheng }
58999575102SLv Zheng
59099575102SLv Zheng *return_type = type;
59199575102SLv Zheng return (start);
59299575102SLv Zheng }
59399575102SLv Zheng
59499575102SLv Zheng /*******************************************************************************
59599575102SLv Zheng *
59699575102SLv Zheng * FUNCTION: acpi_db_get_line
59799575102SLv Zheng *
59899575102SLv Zheng * PARAMETERS: input_buffer - Command line buffer
59999575102SLv Zheng *
60099575102SLv Zheng * RETURN: Count of arguments to the command
60199575102SLv Zheng *
60299575102SLv Zheng * DESCRIPTION: Get the next command line from the user. Gets entire line
60399575102SLv Zheng * up to the next newline
60499575102SLv Zheng *
60599575102SLv Zheng ******************************************************************************/
60699575102SLv Zheng
acpi_db_get_line(char * input_buffer)60799575102SLv Zheng static u32 acpi_db_get_line(char *input_buffer)
60899575102SLv Zheng {
60999575102SLv Zheng u32 i;
61099575102SLv Zheng u32 count;
61199575102SLv Zheng char *next;
61299575102SLv Zheng char *this;
61399575102SLv Zheng
61499575102SLv Zheng if (acpi_ut_safe_strcpy
61599575102SLv Zheng (acpi_gbl_db_parsed_buf, sizeof(acpi_gbl_db_parsed_buf),
61699575102SLv Zheng input_buffer)) {
61799575102SLv Zheng acpi_os_printf
61899575102SLv Zheng ("Buffer overflow while parsing input line (max %u characters)\n",
619231ec06eSBob Moore (u32)sizeof(acpi_gbl_db_parsed_buf));
62099575102SLv Zheng return (0);
62199575102SLv Zheng }
62299575102SLv Zheng
62399575102SLv Zheng this = acpi_gbl_db_parsed_buf;
62499575102SLv Zheng for (i = 0; i < ACPI_DEBUGGER_MAX_ARGS; i++) {
62599575102SLv Zheng acpi_gbl_db_args[i] = acpi_db_get_next_token(this, &next,
62699575102SLv Zheng &acpi_gbl_db_arg_types
62799575102SLv Zheng [i]);
62899575102SLv Zheng if (!acpi_gbl_db_args[i]) {
62999575102SLv Zheng break;
63099575102SLv Zheng }
63199575102SLv Zheng
63299575102SLv Zheng this = next;
63399575102SLv Zheng }
63499575102SLv Zheng
63599575102SLv Zheng /* Uppercase the actual command */
63699575102SLv Zheng
63799575102SLv Zheng acpi_ut_strupr(acpi_gbl_db_args[0]);
63899575102SLv Zheng
63999575102SLv Zheng count = i;
64099575102SLv Zheng if (count) {
64199575102SLv Zheng count--; /* Number of args only */
64299575102SLv Zheng }
64399575102SLv Zheng
64499575102SLv Zheng return (count);
64599575102SLv Zheng }
64699575102SLv Zheng
64799575102SLv Zheng /*******************************************************************************
64899575102SLv Zheng *
64999575102SLv Zheng * FUNCTION: acpi_db_match_command
65099575102SLv Zheng *
65199575102SLv Zheng * PARAMETERS: user_command - User command line
65299575102SLv Zheng *
65399575102SLv Zheng * RETURN: Index into command array, -1 if not found
65499575102SLv Zheng *
65599575102SLv Zheng * DESCRIPTION: Search command array for a command match
65699575102SLv Zheng *
65799575102SLv Zheng ******************************************************************************/
65899575102SLv Zheng
acpi_db_match_command(char * user_command)65999575102SLv Zheng static u32 acpi_db_match_command(char *user_command)
66099575102SLv Zheng {
66199575102SLv Zheng u32 i;
66299575102SLv Zheng
66399575102SLv Zheng if (!user_command || user_command[0] == 0) {
66499575102SLv Zheng return (CMD_NULL);
66599575102SLv Zheng }
66699575102SLv Zheng
66799575102SLv Zheng for (i = CMD_FIRST_VALID; acpi_gbl_db_commands[i].name; i++) {
6680dfaaa3dSBob Moore if (strstr
6690dfaaa3dSBob Moore (ACPI_CAST_PTR(char, acpi_gbl_db_commands[i].name),
6700dfaaa3dSBob Moore user_command) == acpi_gbl_db_commands[i].name) {
67199575102SLv Zheng return (i);
67299575102SLv Zheng }
67399575102SLv Zheng }
67499575102SLv Zheng
67599575102SLv Zheng /* Command not recognized */
67699575102SLv Zheng
67799575102SLv Zheng return (CMD_NOT_FOUND);
67899575102SLv Zheng }
67999575102SLv Zheng
68099575102SLv Zheng /*******************************************************************************
68199575102SLv Zheng *
68299575102SLv Zheng * FUNCTION: acpi_db_command_dispatch
68399575102SLv Zheng *
68499575102SLv Zheng * PARAMETERS: input_buffer - Command line buffer
68599575102SLv Zheng * walk_state - Current walk
68699575102SLv Zheng * op - Current (executing) parse op
68799575102SLv Zheng *
68899575102SLv Zheng * RETURN: Status
68999575102SLv Zheng *
69099575102SLv Zheng * DESCRIPTION: Command dispatcher.
69199575102SLv Zheng *
69299575102SLv Zheng ******************************************************************************/
69399575102SLv Zheng
69499575102SLv Zheng acpi_status
acpi_db_command_dispatch(char * input_buffer,struct acpi_walk_state * walk_state,union acpi_parse_object * op)69599575102SLv Zheng acpi_db_command_dispatch(char *input_buffer,
69699575102SLv Zheng struct acpi_walk_state *walk_state,
69799575102SLv Zheng union acpi_parse_object *op)
69899575102SLv Zheng {
69999575102SLv Zheng u32 temp;
7005fd03328SErik Schmauss u64 temp64;
70199575102SLv Zheng u32 command_index;
70299575102SLv Zheng u32 param_count;
70399575102SLv Zheng char *command_line;
70499575102SLv Zheng acpi_status status = AE_CTRL_TRUE;
70599575102SLv Zheng
70699575102SLv Zheng /* If acpi_terminate has been called, terminate this thread */
70799575102SLv Zheng
708af08f9ccSLv Zheng if (acpi_gbl_db_terminate_loop) {
70999575102SLv Zheng return (AE_CTRL_TERMINATE);
71099575102SLv Zheng }
71199575102SLv Zheng
71299575102SLv Zheng /* Find command and add to the history buffer */
71399575102SLv Zheng
71499575102SLv Zheng param_count = acpi_db_get_line(input_buffer);
71599575102SLv Zheng command_index = acpi_db_match_command(acpi_gbl_db_args[0]);
71699575102SLv Zheng
71799575102SLv Zheng /*
71899575102SLv Zheng * We don't want to add the !! command to the history buffer. It
71999575102SLv Zheng * would cause an infinite loop because it would always be the
72099575102SLv Zheng * previous command.
72199575102SLv Zheng */
72299575102SLv Zheng if (command_index != CMD_HISTORY_LAST) {
72399575102SLv Zheng acpi_db_add_to_history(input_buffer);
72499575102SLv Zheng }
72599575102SLv Zheng
72699575102SLv Zheng /* Verify that we have the minimum number of params */
72799575102SLv Zheng
72899575102SLv Zheng if (param_count < acpi_gbl_db_commands[command_index].min_args) {
72999575102SLv Zheng acpi_os_printf
73099575102SLv Zheng ("%u parameters entered, [%s] requires %u parameters\n",
73199575102SLv Zheng param_count, acpi_gbl_db_commands[command_index].name,
73299575102SLv Zheng acpi_gbl_db_commands[command_index].min_args);
73399575102SLv Zheng
73499575102SLv Zheng acpi_db_display_command_info(acpi_gbl_db_commands
73599575102SLv Zheng [command_index].name, FALSE);
73699575102SLv Zheng return (AE_CTRL_TRUE);
73799575102SLv Zheng }
73899575102SLv Zheng
73999575102SLv Zheng /* Decode and dispatch the command */
74099575102SLv Zheng
74199575102SLv Zheng switch (command_index) {
74299575102SLv Zheng case CMD_NULL:
74399575102SLv Zheng
74499575102SLv Zheng if (op) {
74599575102SLv Zheng return (AE_OK);
74699575102SLv Zheng }
74799575102SLv Zheng break;
74899575102SLv Zheng
7496218ab30SBob Moore case CMD_ALL:
7506218ab30SBob Moore
7516218ab30SBob Moore acpi_os_printf("Executing all objects with NameSeg: %s\n",
7526218ab30SBob Moore acpi_gbl_db_args[1]);
7536218ab30SBob Moore acpi_db_execute(acpi_gbl_db_args[1], &acpi_gbl_db_args[2],
7546218ab30SBob Moore &acpi_gbl_db_arg_types[2],
7556218ab30SBob Moore EX_NO_SINGLE_STEP | EX_ALL);
7566218ab30SBob Moore break;
7576218ab30SBob Moore
75899575102SLv Zheng case CMD_ALLOCATIONS:
75999575102SLv Zheng
76099575102SLv Zheng #ifdef ACPI_DBG_TRACK_ALLOCATIONS
76199575102SLv Zheng acpi_ut_dump_allocations((u32)-1, NULL);
76299575102SLv Zheng #endif
76399575102SLv Zheng break;
76499575102SLv Zheng
76599575102SLv Zheng case CMD_ARGS:
76699575102SLv Zheng case CMD_ARGUMENTS:
76799575102SLv Zheng
76899575102SLv Zheng acpi_db_display_arguments();
76999575102SLv Zheng break;
77099575102SLv Zheng
77199575102SLv Zheng case CMD_BREAKPOINT:
77299575102SLv Zheng
77399575102SLv Zheng acpi_db_set_method_breakpoint(acpi_gbl_db_args[1], walk_state,
77499575102SLv Zheng op);
77599575102SLv Zheng break;
77699575102SLv Zheng
77799575102SLv Zheng case CMD_BUSINFO:
77899575102SLv Zheng
77999575102SLv Zheng acpi_db_get_bus_info();
78099575102SLv Zheng break;
78199575102SLv Zheng
78299575102SLv Zheng case CMD_CALL:
78399575102SLv Zheng
78499575102SLv Zheng acpi_db_set_method_call_breakpoint(op);
78599575102SLv Zheng status = AE_OK;
78699575102SLv Zheng break;
78799575102SLv Zheng
78899575102SLv Zheng case CMD_DEBUG:
78999575102SLv Zheng
79099575102SLv Zheng acpi_db_execute(acpi_gbl_db_args[1],
79199575102SLv Zheng &acpi_gbl_db_args[2], &acpi_gbl_db_arg_types[2],
79299575102SLv Zheng EX_SINGLE_STEP);
79399575102SLv Zheng break;
79499575102SLv Zheng
79599575102SLv Zheng case CMD_DISASSEMBLE:
79699575102SLv Zheng case CMD_DISASM:
79799575102SLv Zheng
798fb2ef998SBob Moore #ifdef ACPI_DISASSEMBLER
79999575102SLv Zheng (void)acpi_db_disassemble_method(acpi_gbl_db_args[1]);
800fb2ef998SBob Moore #else
801fb2ef998SBob Moore acpi_os_printf
802fb2ef998SBob Moore ("The AML Disassembler is not configured/present\n");
803fb2ef998SBob Moore #endif
80499575102SLv Zheng break;
80599575102SLv Zheng
80699575102SLv Zheng case CMD_DUMP:
80799575102SLv Zheng
80899575102SLv Zheng acpi_db_decode_and_display_object(acpi_gbl_db_args[1],
80999575102SLv Zheng acpi_gbl_db_args[2]);
81099575102SLv Zheng break;
81199575102SLv Zheng
81299575102SLv Zheng case CMD_EVALUATE:
81399575102SLv Zheng case CMD_EXECUTE:
81499575102SLv Zheng
81599575102SLv Zheng acpi_db_execute(acpi_gbl_db_args[1],
81699575102SLv Zheng &acpi_gbl_db_args[2], &acpi_gbl_db_arg_types[2],
81799575102SLv Zheng EX_NO_SINGLE_STEP);
81899575102SLv Zheng break;
81999575102SLv Zheng
82099575102SLv Zheng case CMD_FIND:
82199575102SLv Zheng
82299575102SLv Zheng status = acpi_db_find_name_in_namespace(acpi_gbl_db_args[1]);
82399575102SLv Zheng break;
82499575102SLv Zheng
8255fd03328SErik Schmauss case CMD_FIELDS:
8265fd03328SErik Schmauss
8275fd03328SErik Schmauss status = acpi_ut_strtoul64(acpi_gbl_db_args[1], &temp64);
8285fd03328SErik Schmauss
8295fd03328SErik Schmauss if (ACPI_FAILURE(status)
8305fd03328SErik Schmauss || temp64 >= ACPI_NUM_PREDEFINED_REGIONS) {
8315fd03328SErik Schmauss acpi_os_printf
83222e38ca7SColin Ian King ("Invalid address space ID: must be between 0 and %u inclusive\n",
8335fd03328SErik Schmauss ACPI_NUM_PREDEFINED_REGIONS - 1);
8345fd03328SErik Schmauss return (AE_OK);
8355fd03328SErik Schmauss }
8365fd03328SErik Schmauss
8375fd03328SErik Schmauss status = acpi_db_display_fields((u32)temp64);
8385fd03328SErik Schmauss break;
8395fd03328SErik Schmauss
84099575102SLv Zheng case CMD_GO:
84199575102SLv Zheng
84299575102SLv Zheng acpi_gbl_cm_single_step = FALSE;
84399575102SLv Zheng return (AE_OK);
84499575102SLv Zheng
84599575102SLv Zheng case CMD_HANDLERS:
84699575102SLv Zheng
84799575102SLv Zheng acpi_db_display_handlers();
84899575102SLv Zheng break;
84999575102SLv Zheng
85099575102SLv Zheng case CMD_HELP:
85199575102SLv Zheng case CMD_HELP2:
85299575102SLv Zheng
85399575102SLv Zheng acpi_db_display_help(acpi_gbl_db_args[1]);
85499575102SLv Zheng break;
85599575102SLv Zheng
85699575102SLv Zheng case CMD_HISTORY:
85799575102SLv Zheng
85899575102SLv Zheng acpi_db_display_history();
85999575102SLv Zheng break;
86099575102SLv Zheng
86199575102SLv Zheng case CMD_HISTORY_EXE: /* ! command */
86299575102SLv Zheng
86399575102SLv Zheng command_line = acpi_db_get_from_history(acpi_gbl_db_args[1]);
86499575102SLv Zheng if (!command_line) {
86599575102SLv Zheng return (AE_CTRL_TRUE);
86699575102SLv Zheng }
86799575102SLv Zheng
86899575102SLv Zheng status = acpi_db_command_dispatch(command_line, walk_state, op);
86999575102SLv Zheng return (status);
87099575102SLv Zheng
87199575102SLv Zheng case CMD_HISTORY_LAST: /* !! command */
87299575102SLv Zheng
87399575102SLv Zheng command_line = acpi_db_get_from_history(NULL);
87499575102SLv Zheng if (!command_line) {
87599575102SLv Zheng return (AE_CTRL_TRUE);
87699575102SLv Zheng }
87799575102SLv Zheng
87899575102SLv Zheng status = acpi_db_command_dispatch(command_line, walk_state, op);
87999575102SLv Zheng return (status);
88099575102SLv Zheng
88199575102SLv Zheng case CMD_INFORMATION:
88299575102SLv Zheng
88399575102SLv Zheng acpi_db_display_method_info(op);
88499575102SLv Zheng break;
88599575102SLv Zheng
88699575102SLv Zheng case CMD_INTEGRITY:
88799575102SLv Zheng
88899575102SLv Zheng acpi_db_check_integrity();
88999575102SLv Zheng break;
89099575102SLv Zheng
89199575102SLv Zheng case CMD_INTO:
89299575102SLv Zheng
89399575102SLv Zheng if (op) {
89499575102SLv Zheng acpi_gbl_cm_single_step = TRUE;
89599575102SLv Zheng return (AE_OK);
89699575102SLv Zheng }
89799575102SLv Zheng break;
89899575102SLv Zheng
89999575102SLv Zheng case CMD_LEVEL:
90099575102SLv Zheng
90199575102SLv Zheng if (param_count == 0) {
90299575102SLv Zheng acpi_os_printf
90336056d0cSBob Moore ("Current debug level for file output is: %8.8X\n",
90499575102SLv Zheng acpi_gbl_db_debug_level);
90599575102SLv Zheng acpi_os_printf
90636056d0cSBob Moore ("Current debug level for console output is: %8.8X\n",
90799575102SLv Zheng acpi_gbl_db_console_debug_level);
90899575102SLv Zheng } else if (param_count == 2) {
90999575102SLv Zheng temp = acpi_gbl_db_console_debug_level;
91099575102SLv Zheng acpi_gbl_db_console_debug_level =
91199575102SLv Zheng strtoul(acpi_gbl_db_args[1], NULL, 16);
91299575102SLv Zheng acpi_os_printf
91336056d0cSBob Moore ("Debug Level for console output was %8.8X, now %8.8X\n",
91499575102SLv Zheng temp, acpi_gbl_db_console_debug_level);
91599575102SLv Zheng } else {
91699575102SLv Zheng temp = acpi_gbl_db_debug_level;
91799575102SLv Zheng acpi_gbl_db_debug_level =
91899575102SLv Zheng strtoul(acpi_gbl_db_args[1], NULL, 16);
91999575102SLv Zheng acpi_os_printf
92036056d0cSBob Moore ("Debug Level for file output was %8.8X, now %8.8X\n",
92199575102SLv Zheng temp, acpi_gbl_db_debug_level);
92299575102SLv Zheng }
92399575102SLv Zheng break;
92499575102SLv Zheng
92599575102SLv Zheng case CMD_LIST:
92699575102SLv Zheng
927fb2ef998SBob Moore #ifdef ACPI_DISASSEMBLER
92899575102SLv Zheng acpi_db_disassemble_aml(acpi_gbl_db_args[1], op);
929fb2ef998SBob Moore #else
930fb2ef998SBob Moore acpi_os_printf
931fb2ef998SBob Moore ("The AML Disassembler is not configured/present\n");
932fb2ef998SBob Moore #endif
93399575102SLv Zheng break;
93499575102SLv Zheng
93599575102SLv Zheng case CMD_LOCKS:
93699575102SLv Zheng
93799575102SLv Zheng acpi_db_display_locks();
93899575102SLv Zheng break;
93999575102SLv Zheng
94099575102SLv Zheng case CMD_LOCALS:
94199575102SLv Zheng
94299575102SLv Zheng acpi_db_display_locals();
94399575102SLv Zheng break;
94499575102SLv Zheng
94599575102SLv Zheng case CMD_METHODS:
94699575102SLv Zheng
94799575102SLv Zheng status = acpi_db_display_objects("METHOD", acpi_gbl_db_args[1]);
94899575102SLv Zheng break;
94999575102SLv Zheng
95099575102SLv Zheng case CMD_NAMESPACE:
95199575102SLv Zheng
95299575102SLv Zheng acpi_db_dump_namespace(acpi_gbl_db_args[1],
95399575102SLv Zheng acpi_gbl_db_args[2]);
95499575102SLv Zheng break;
95599575102SLv Zheng
95699575102SLv Zheng case CMD_NOTIFY:
95799575102SLv Zheng
95899575102SLv Zheng temp = strtoul(acpi_gbl_db_args[2], NULL, 0);
95999575102SLv Zheng acpi_db_send_notify(acpi_gbl_db_args[1], temp);
96099575102SLv Zheng break;
96199575102SLv Zheng
96299575102SLv Zheng case CMD_OBJECTS:
96399575102SLv Zheng
96499575102SLv Zheng acpi_ut_strupr(acpi_gbl_db_args[1]);
96599575102SLv Zheng status =
96699575102SLv Zheng acpi_db_display_objects(acpi_gbl_db_args[1],
96799575102SLv Zheng acpi_gbl_db_args[2]);
96899575102SLv Zheng break;
96999575102SLv Zheng
97099575102SLv Zheng case CMD_OSI:
97199575102SLv Zheng
97299575102SLv Zheng acpi_db_display_interfaces(acpi_gbl_db_args[1],
97399575102SLv Zheng acpi_gbl_db_args[2]);
97499575102SLv Zheng break;
97599575102SLv Zheng
97699575102SLv Zheng case CMD_OWNER:
97799575102SLv Zheng
97899575102SLv Zheng acpi_db_dump_namespace_by_owner(acpi_gbl_db_args[1],
97999575102SLv Zheng acpi_gbl_db_args[2]);
98099575102SLv Zheng break;
98199575102SLv Zheng
98299575102SLv Zheng case CMD_PATHS:
98399575102SLv Zheng
98499575102SLv Zheng acpi_db_dump_namespace_paths();
98599575102SLv Zheng break;
98699575102SLv Zheng
98799575102SLv Zheng case CMD_PREFIX:
98899575102SLv Zheng
98999575102SLv Zheng acpi_db_set_scope(acpi_gbl_db_args[1]);
99099575102SLv Zheng break;
99199575102SLv Zheng
99299575102SLv Zheng case CMD_REFERENCES:
99399575102SLv Zheng
99499575102SLv Zheng acpi_db_find_references(acpi_gbl_db_args[1]);
99599575102SLv Zheng break;
99699575102SLv Zheng
99799575102SLv Zheng case CMD_RESOURCES:
99899575102SLv Zheng
99999575102SLv Zheng acpi_db_display_resources(acpi_gbl_db_args[1]);
100099575102SLv Zheng break;
100199575102SLv Zheng
100299575102SLv Zheng case CMD_RESULTS:
100399575102SLv Zheng
100499575102SLv Zheng acpi_db_display_results();
100599575102SLv Zheng break;
100699575102SLv Zheng
100799575102SLv Zheng case CMD_SET:
100899575102SLv Zheng
100999575102SLv Zheng acpi_db_set_method_data(acpi_gbl_db_args[1],
101099575102SLv Zheng acpi_gbl_db_args[2],
101199575102SLv Zheng acpi_gbl_db_args[3]);
101299575102SLv Zheng break;
101399575102SLv Zheng
101499575102SLv Zheng case CMD_STATS:
101599575102SLv Zheng
101699575102SLv Zheng status = acpi_db_display_statistics(acpi_gbl_db_args[1]);
101799575102SLv Zheng break;
101899575102SLv Zheng
101999575102SLv Zheng case CMD_STOP:
102099575102SLv Zheng
102199575102SLv Zheng return (AE_NOT_IMPLEMENTED);
102299575102SLv Zheng
102399575102SLv Zheng case CMD_TABLES:
102499575102SLv Zheng
102599575102SLv Zheng acpi_db_display_table_info(acpi_gbl_db_args[1]);
102699575102SLv Zheng break;
102799575102SLv Zheng
102899575102SLv Zheng case CMD_TEMPLATE:
102999575102SLv Zheng
103099575102SLv Zheng acpi_db_display_template(acpi_gbl_db_args[1]);
103199575102SLv Zheng break;
103299575102SLv Zheng
103399575102SLv Zheng case CMD_TRACE:
103499575102SLv Zheng
103599575102SLv Zheng acpi_db_trace(acpi_gbl_db_args[1], acpi_gbl_db_args[2],
103699575102SLv Zheng acpi_gbl_db_args[3]);
103799575102SLv Zheng break;
103899575102SLv Zheng
103999575102SLv Zheng case CMD_TREE:
104099575102SLv Zheng
104199575102SLv Zheng acpi_db_display_calling_tree();
104299575102SLv Zheng break;
104399575102SLv Zheng
104499575102SLv Zheng case CMD_TYPE:
104599575102SLv Zheng
104699575102SLv Zheng acpi_db_display_object_type(acpi_gbl_db_args[1]);
104799575102SLv Zheng break;
104899575102SLv Zheng
104999575102SLv Zheng #ifdef ACPI_APPLICATION
105099575102SLv Zheng
105199575102SLv Zheng /* Hardware simulation commands. */
105299575102SLv Zheng
105399575102SLv Zheng case CMD_ENABLEACPI:
105499575102SLv Zheng #if (!ACPI_REDUCED_HARDWARE)
105599575102SLv Zheng
105699575102SLv Zheng status = acpi_enable();
105799575102SLv Zheng if (ACPI_FAILURE(status)) {
105899575102SLv Zheng acpi_os_printf("AcpiEnable failed (Status=%X)\n",
105999575102SLv Zheng status);
106099575102SLv Zheng return (status);
106199575102SLv Zheng }
106299575102SLv Zheng #endif /* !ACPI_REDUCED_HARDWARE */
106399575102SLv Zheng break;
106499575102SLv Zheng
106599575102SLv Zheng case CMD_EVENT:
106699575102SLv Zheng
106799575102SLv Zheng acpi_os_printf("Event command not implemented\n");
106899575102SLv Zheng break;
106999575102SLv Zheng
1070*b0f2e7d7SJose Marinho case CMD_INTERRUPT:
1071*b0f2e7d7SJose Marinho
1072*b0f2e7d7SJose Marinho acpi_db_generate_interrupt(acpi_gbl_db_args[1]);
1073*b0f2e7d7SJose Marinho break;
1074*b0f2e7d7SJose Marinho
107599575102SLv Zheng case CMD_GPE:
107699575102SLv Zheng
107799575102SLv Zheng acpi_db_generate_gpe(acpi_gbl_db_args[1], acpi_gbl_db_args[2]);
107899575102SLv Zheng break;
107999575102SLv Zheng
108099575102SLv Zheng case CMD_GPES:
108199575102SLv Zheng
108299575102SLv Zheng acpi_db_display_gpes();
108399575102SLv Zheng break;
108499575102SLv Zheng
108599575102SLv Zheng case CMD_SCI:
108699575102SLv Zheng
108799575102SLv Zheng acpi_db_generate_sci();
108899575102SLv Zheng break;
108999575102SLv Zheng
109099575102SLv Zheng case CMD_SLEEP:
109199575102SLv Zheng
109299575102SLv Zheng status = acpi_db_sleep(acpi_gbl_db_args[1]);
109399575102SLv Zheng break;
109499575102SLv Zheng
109599575102SLv Zheng /* File I/O commands. */
109699575102SLv Zheng
109799575102SLv Zheng case CMD_CLOSE:
109899575102SLv Zheng
109999575102SLv Zheng acpi_db_close_debug_file();
110099575102SLv Zheng break;
110199575102SLv Zheng
11022ba7379bSBob Moore case CMD_LOAD:{
11032ba7379bSBob Moore struct acpi_new_table_desc *list_head = NULL;
110499575102SLv Zheng
110599575102SLv Zheng status =
1106395ec731SBob Moore ac_get_all_tables_from_file(acpi_gbl_db_args[1],
11072ba7379bSBob Moore ACPI_GET_ALL_TABLES,
11082ba7379bSBob Moore &list_head);
11092ba7379bSBob Moore if (ACPI_SUCCESS(status)) {
11102ba7379bSBob Moore acpi_db_load_tables(list_head);
11112ba7379bSBob Moore }
11122ba7379bSBob Moore }
111399575102SLv Zheng break;
111499575102SLv Zheng
111599575102SLv Zheng case CMD_OPEN:
111699575102SLv Zheng
111799575102SLv Zheng acpi_db_open_debug_file(acpi_gbl_db_args[1]);
111899575102SLv Zheng break;
111999575102SLv Zheng
112099575102SLv Zheng /* User space commands. */
112199575102SLv Zheng
112299575102SLv Zheng case CMD_TERMINATE:
112399575102SLv Zheng
112499575102SLv Zheng acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT);
112599575102SLv Zheng acpi_ut_subsystem_shutdown();
112699575102SLv Zheng
112799575102SLv Zheng /*
112899575102SLv Zheng * TBD: [Restructure] Need some way to re-initialize without
112999575102SLv Zheng * re-creating the semaphores!
113099575102SLv Zheng */
113199575102SLv Zheng
1132086ab742SLv Zheng acpi_gbl_db_terminate_loop = TRUE;
113399575102SLv Zheng /* acpi_initialize (NULL); */
113499575102SLv Zheng break;
113599575102SLv Zheng
1136060c859dSBob Moore case CMD_BACKGROUND:
1137060c859dSBob Moore
1138060c859dSBob Moore acpi_db_create_execution_thread(acpi_gbl_db_args[1],
1139060c859dSBob Moore &acpi_gbl_db_args[2],
1140060c859dSBob Moore &acpi_gbl_db_arg_types[2]);
1141060c859dSBob Moore break;
1142060c859dSBob Moore
114399575102SLv Zheng case CMD_THREADS:
114499575102SLv Zheng
114599575102SLv Zheng acpi_db_create_execution_threads(acpi_gbl_db_args[1],
114699575102SLv Zheng acpi_gbl_db_args[2],
114799575102SLv Zheng acpi_gbl_db_args[3]);
114899575102SLv Zheng break;
114999575102SLv Zheng
115099575102SLv Zheng /* Debug test commands. */
115199575102SLv Zheng
115299575102SLv Zheng case CMD_PREDEFINED:
115399575102SLv Zheng
115499575102SLv Zheng acpi_db_check_predefined_names();
115599575102SLv Zheng break;
115699575102SLv Zheng
115799575102SLv Zheng case CMD_TEST:
115899575102SLv Zheng
115999575102SLv Zheng acpi_db_execute_test(acpi_gbl_db_args[1]);
116099575102SLv Zheng break;
116199575102SLv Zheng
116299575102SLv Zheng case CMD_UNLOAD:
116399575102SLv Zheng
116499575102SLv Zheng acpi_db_unload_acpi_table(acpi_gbl_db_args[1]);
116599575102SLv Zheng break;
116699575102SLv Zheng #endif
116799575102SLv Zheng
116899575102SLv Zheng case CMD_EXIT:
116999575102SLv Zheng case CMD_QUIT:
117099575102SLv Zheng
117199575102SLv Zheng if (op) {
117299575102SLv Zheng acpi_os_printf("Method execution terminated\n");
117399575102SLv Zheng return (AE_CTRL_TERMINATE);
117499575102SLv Zheng }
117599575102SLv Zheng
117699575102SLv Zheng if (!acpi_gbl_db_output_to_file) {
117799575102SLv Zheng acpi_dbg_level = ACPI_DEBUG_DEFAULT;
117899575102SLv Zheng }
117999575102SLv Zheng #ifdef ACPI_APPLICATION
118099575102SLv Zheng acpi_db_close_debug_file();
118199575102SLv Zheng #endif
1182af08f9ccSLv Zheng acpi_gbl_db_terminate_loop = TRUE;
118399575102SLv Zheng return (AE_CTRL_TERMINATE);
118499575102SLv Zheng
118599575102SLv Zheng case CMD_NOT_FOUND:
118699575102SLv Zheng default:
118799575102SLv Zheng
118899575102SLv Zheng acpi_os_printf("%s: unknown command\n", acpi_gbl_db_args[0]);
118999575102SLv Zheng return (AE_CTRL_TRUE);
119099575102SLv Zheng }
119199575102SLv Zheng
119299575102SLv Zheng if (ACPI_SUCCESS(status)) {
119399575102SLv Zheng status = AE_CTRL_TRUE;
119499575102SLv Zheng }
119599575102SLv Zheng
119699575102SLv Zheng return (status);
119799575102SLv Zheng }
119899575102SLv Zheng
119999575102SLv Zheng /*******************************************************************************
120099575102SLv Zheng *
120199575102SLv Zheng * FUNCTION: acpi_db_execute_thread
120299575102SLv Zheng *
120399575102SLv Zheng * PARAMETERS: context - Not used
120499575102SLv Zheng *
120599575102SLv Zheng * RETURN: None
120699575102SLv Zheng *
120799575102SLv Zheng * DESCRIPTION: Debugger execute thread. Waits for a command line, then
120899575102SLv Zheng * simply dispatches it.
120999575102SLv Zheng *
121099575102SLv Zheng ******************************************************************************/
121199575102SLv Zheng
acpi_db_execute_thread(void * context)121299575102SLv Zheng void ACPI_SYSTEM_XFACE acpi_db_execute_thread(void *context)
121399575102SLv Zheng {
121499575102SLv Zheng
1215f8d31489SLv Zheng (void)acpi_db_user_commands();
1216af08f9ccSLv Zheng acpi_gbl_db_threads_terminated = TRUE;
121799575102SLv Zheng }
121899575102SLv Zheng
121999575102SLv Zheng /*******************************************************************************
122099575102SLv Zheng *
122199575102SLv Zheng * FUNCTION: acpi_db_user_commands
122299575102SLv Zheng *
1223f8d31489SLv Zheng * PARAMETERS: None
122499575102SLv Zheng *
122599575102SLv Zheng * RETURN: None
122699575102SLv Zheng *
122799575102SLv Zheng * DESCRIPTION: Command line execution for the AML debugger. Commands are
122899575102SLv Zheng * matched and dispatched here.
122999575102SLv Zheng *
123099575102SLv Zheng ******************************************************************************/
123199575102SLv Zheng
acpi_db_user_commands(void)1232f8d31489SLv Zheng acpi_status acpi_db_user_commands(void)
123399575102SLv Zheng {
123499575102SLv Zheng acpi_status status = AE_OK;
123599575102SLv Zheng
123699575102SLv Zheng acpi_os_printf("\n");
123799575102SLv Zheng
123899575102SLv Zheng /* TBD: [Restructure] Need a separate command line buffer for step mode */
123999575102SLv Zheng
1240af08f9ccSLv Zheng while (!acpi_gbl_db_terminate_loop) {
124199575102SLv Zheng
1242f8d31489SLv Zheng /* Wait the readiness of the command */
124399575102SLv Zheng
1244f8d31489SLv Zheng status = acpi_os_wait_command_ready();
124599575102SLv Zheng if (ACPI_FAILURE(status)) {
1246f8d31489SLv Zheng break;
124799575102SLv Zheng }
124899575102SLv Zheng
124999575102SLv Zheng /* Just call to the command line interpreter */
125099575102SLv Zheng
1251f8d31489SLv Zheng acpi_gbl_method_executing = FALSE;
1252f8d31489SLv Zheng acpi_gbl_step_to_next_call = FALSE;
1253f8d31489SLv Zheng
1254f8d31489SLv Zheng (void)acpi_db_command_dispatch(acpi_gbl_db_line_buf, NULL,
1255f8d31489SLv Zheng NULL);
1256f8d31489SLv Zheng
1257f8d31489SLv Zheng /* Notify the completion of the command */
1258f8d31489SLv Zheng
1259f8d31489SLv Zheng status = acpi_os_notify_command_complete();
1260f8d31489SLv Zheng if (ACPI_FAILURE(status)) {
1261f8d31489SLv Zheng break;
126299575102SLv Zheng }
126399575102SLv Zheng }
126499575102SLv Zheng
1265f8d31489SLv Zheng if (ACPI_FAILURE(status) && status != AE_CTRL_TERMINATE) {
1266f8d31489SLv Zheng ACPI_EXCEPTION((AE_INFO, status, "While parsing command line"));
1267f8d31489SLv Zheng }
126899575102SLv Zheng return (status);
126999575102SLv Zheng }
1270