dbinput.c 28 KB

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