dbinput.c 29 KB

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