dbinput.c 28 KB

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