dbinput.c 27 KB

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