dbinput.c 28 KB

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