dbinput.c 29 KB

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