dbinput.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214
  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. {1, " Go", "Allow method to run to completion\n"},
  268. {1, " Information", "Display info about the current method\n"},
  269. {1, " Into", "Step into (not over) a method call\n"},
  270. {1, " List [# of Aml Opcodes]", "Display method ASL statements\n"},
  271. {1, " Locals", "Display method local variables\n"},
  272. {1, " Results", "Display method result stack\n"},
  273. {1, " Set <A|L> <#> <Value>", "Set method data (Arguments/Locals)\n"},
  274. {1, " Stop", "Terminate control method\n"},
  275. {5, " Trace <State> [<Namepath>] [Once]",
  276. "Trace control method execution\n"},
  277. {1, " Enable", "Enable all messages\n"},
  278. {1, " Disable", "Disable tracing\n"},
  279. {1, " Method", "Enable method execution messages\n"},
  280. {1, " Opcode", "Enable opcode execution messages\n"},
  281. {1, " Tree", "Display control method calling tree\n"},
  282. {1, " <Enter>", "Single step next AML opcode (over calls)\n"},
  283. #ifdef ACPI_APPLICATION
  284. {0, "\nHardware Simulation Commands:", "\n"},
  285. {1, " EnableAcpi", "Enable ACPI (hardware) mode\n"},
  286. {1, " Event <F|G> <Value>", "Generate AcpiEvent (Fixed/GPE)\n"},
  287. {1, " Gpe <GpeNum> [GpeBlockDevice]", "Simulate a GPE\n"},
  288. {1, " Gpes", "Display info on all GPE devices\n"},
  289. {1, " Sci", "Generate an SCI\n"},
  290. {1, " Sleep [SleepState]", "Simulate sleep/wake sequence(s) (0-5)\n"},
  291. {0, "\nFile I/O Commands:", "\n"},
  292. {1, " Close", "Close debug output file\n"},
  293. {1, " Load <Input Filename>", "Load ACPI table from a file\n"},
  294. {1, " Open <Output Filename>", "Open a file for debug output\n"},
  295. {1, " Unload <Namepath>",
  296. "Unload an ACPI table via namespace object\n"},
  297. {0, "\nUser Space Commands:", "\n"},
  298. {1, " Terminate", "Delete namespace and all internal objects\n"},
  299. {1, " Thread <Threads><Loops><NamePath>",
  300. "Spawn threads to execute method(s)\n"},
  301. {0, "\nDebug Test Commands:", "\n"},
  302. {3, " Test <TestName>", "Invoke a debug test\n"},
  303. {1, " Objects", "Read/write/compare all namespace data objects\n"},
  304. {1, " Predefined",
  305. "Execute all ACPI predefined names (_STA, etc.)\n"},
  306. #endif
  307. {0, NULL, NULL}
  308. };
  309. /*******************************************************************************
  310. *
  311. * FUNCTION: acpi_db_match_command_help
  312. *
  313. * PARAMETERS: command - Command string to match
  314. * help - Help table entry to attempt match
  315. *
  316. * RETURN: TRUE if command matched, FALSE otherwise
  317. *
  318. * DESCRIPTION: Attempt to match a command in the help table in order to
  319. * print help information for a single command.
  320. *
  321. ******************************************************************************/
  322. static u8
  323. acpi_db_match_command_help(const char *command,
  324. const struct acpi_db_command_help *help)
  325. {
  326. char *invocation = help->invocation;
  327. u32 line_count;
  328. /* Valid commands in the help table begin with a couple of spaces */
  329. if (*invocation != ' ') {
  330. return (FALSE);
  331. }
  332. while (*invocation == ' ') {
  333. invocation++;
  334. }
  335. /* Match command name (full command or substring) */
  336. while ((*command) && (*invocation) && (*invocation != ' ')) {
  337. if (tolower((int)*command) != tolower((int)*invocation)) {
  338. return (FALSE);
  339. }
  340. invocation++;
  341. command++;
  342. }
  343. /* Print the appropriate number of help lines */
  344. line_count = help->line_count;
  345. while (line_count) {
  346. acpi_os_printf("%-38s : %s", help->invocation,
  347. help->description);
  348. help++;
  349. line_count--;
  350. }
  351. return (TRUE);
  352. }
  353. /*******************************************************************************
  354. *
  355. * FUNCTION: acpi_db_display_command_info
  356. *
  357. * PARAMETERS: command - Command string to match
  358. * display_all - Display all matching commands, or just
  359. * the first one (substring match)
  360. *
  361. * RETURN: None
  362. *
  363. * DESCRIPTION: Display help information for a Debugger command.
  364. *
  365. ******************************************************************************/
  366. static void acpi_db_display_command_info(const char *command, u8 display_all)
  367. {
  368. const struct acpi_db_command_help *next;
  369. u8 matched;
  370. next = acpi_gbl_db_command_help;
  371. while (next->invocation) {
  372. matched = acpi_db_match_command_help(command, next);
  373. if (!display_all && matched) {
  374. return;
  375. }
  376. next++;
  377. }
  378. }
  379. /*******************************************************************************
  380. *
  381. * FUNCTION: acpi_db_display_help
  382. *
  383. * PARAMETERS: command - Optional command string to display help.
  384. * if not specified, all debugger command
  385. * help strings are displayed
  386. *
  387. * RETURN: None
  388. *
  389. * DESCRIPTION: Display help for a single debugger command, or all of them.
  390. *
  391. ******************************************************************************/
  392. static void acpi_db_display_help(char *command)
  393. {
  394. const struct acpi_db_command_help *next = acpi_gbl_db_command_help;
  395. if (!command) {
  396. /* No argument to help, display help for all commands */
  397. while (next->invocation) {
  398. acpi_os_printf("%-38s%s", next->invocation,
  399. next->description);
  400. next++;
  401. }
  402. } else {
  403. /* Display help for all commands that match the subtring */
  404. acpi_db_display_command_info(command, TRUE);
  405. }
  406. }
  407. /*******************************************************************************
  408. *
  409. * FUNCTION: acpi_db_get_next_token
  410. *
  411. * PARAMETERS: string - Command buffer
  412. * next - Return value, end of next token
  413. *
  414. * RETURN: Pointer to the start of the next token.
  415. *
  416. * DESCRIPTION: Command line parsing. Get the next token on the command line
  417. *
  418. ******************************************************************************/
  419. char *acpi_db_get_next_token(char *string,
  420. char **next, acpi_object_type *return_type)
  421. {
  422. char *start;
  423. u32 depth;
  424. acpi_object_type type = ACPI_TYPE_INTEGER;
  425. /* At end of buffer? */
  426. if (!string || !(*string)) {
  427. return (NULL);
  428. }
  429. /* Remove any spaces at the beginning */
  430. if (*string == ' ') {
  431. while (*string && (*string == ' ')) {
  432. string++;
  433. }
  434. if (!(*string)) {
  435. return (NULL);
  436. }
  437. }
  438. switch (*string) {
  439. case '"':
  440. /* This is a quoted string, scan until closing quote */
  441. string++;
  442. start = string;
  443. type = ACPI_TYPE_STRING;
  444. /* Find end of string */
  445. while (*string && (*string != '"')) {
  446. string++;
  447. }
  448. break;
  449. case '(':
  450. /* This is the start of a buffer, scan until closing paren */
  451. string++;
  452. start = string;
  453. type = ACPI_TYPE_BUFFER;
  454. /* Find end of buffer */
  455. while (*string && (*string != ')')) {
  456. string++;
  457. }
  458. break;
  459. case '[':
  460. /* This is the start of a package, scan until closing bracket */
  461. string++;
  462. depth = 1;
  463. start = string;
  464. type = ACPI_TYPE_PACKAGE;
  465. /* Find end of package (closing bracket) */
  466. while (*string) {
  467. /* Handle String package elements */
  468. if (*string == '"') {
  469. /* Find end of string */
  470. string++;
  471. while (*string && (*string != '"')) {
  472. string++;
  473. }
  474. if (!(*string)) {
  475. break;
  476. }
  477. } else if (*string == '[') {
  478. depth++; /* A nested package declaration */
  479. } else if (*string == ']') {
  480. depth--;
  481. if (depth == 0) { /* Found final package closing bracket */
  482. break;
  483. }
  484. }
  485. string++;
  486. }
  487. break;
  488. default:
  489. start = string;
  490. /* Find end of token */
  491. while (*string && (*string != ' ')) {
  492. string++;
  493. }
  494. break;
  495. }
  496. if (!(*string)) {
  497. *next = NULL;
  498. } else {
  499. *string = 0;
  500. *next = string + 1;
  501. }
  502. *return_type = type;
  503. return (start);
  504. }
  505. /*******************************************************************************
  506. *
  507. * FUNCTION: acpi_db_get_line
  508. *
  509. * PARAMETERS: input_buffer - Command line buffer
  510. *
  511. * RETURN: Count of arguments to the command
  512. *
  513. * DESCRIPTION: Get the next command line from the user. Gets entire line
  514. * up to the next newline
  515. *
  516. ******************************************************************************/
  517. static u32 acpi_db_get_line(char *input_buffer)
  518. {
  519. u32 i;
  520. u32 count;
  521. char *next;
  522. char *this;
  523. if (acpi_ut_safe_strcpy
  524. (acpi_gbl_db_parsed_buf, sizeof(acpi_gbl_db_parsed_buf),
  525. input_buffer)) {
  526. acpi_os_printf
  527. ("Buffer overflow while parsing input line (max %u characters)\n",
  528. sizeof(acpi_gbl_db_parsed_buf));
  529. return (0);
  530. }
  531. this = acpi_gbl_db_parsed_buf;
  532. for (i = 0; i < ACPI_DEBUGGER_MAX_ARGS; i++) {
  533. acpi_gbl_db_args[i] = acpi_db_get_next_token(this, &next,
  534. &acpi_gbl_db_arg_types
  535. [i]);
  536. if (!acpi_gbl_db_args[i]) {
  537. break;
  538. }
  539. this = next;
  540. }
  541. /* Uppercase the actual command */
  542. acpi_ut_strupr(acpi_gbl_db_args[0]);
  543. count = i;
  544. if (count) {
  545. count--; /* Number of args only */
  546. }
  547. return (count);
  548. }
  549. /*******************************************************************************
  550. *
  551. * FUNCTION: acpi_db_match_command
  552. *
  553. * PARAMETERS: user_command - User command line
  554. *
  555. * RETURN: Index into command array, -1 if not found
  556. *
  557. * DESCRIPTION: Search command array for a command match
  558. *
  559. ******************************************************************************/
  560. static u32 acpi_db_match_command(char *user_command)
  561. {
  562. u32 i;
  563. if (!user_command || user_command[0] == 0) {
  564. return (CMD_NULL);
  565. }
  566. for (i = CMD_FIRST_VALID; acpi_gbl_db_commands[i].name; i++) {
  567. if (strstr
  568. (ACPI_CAST_PTR(char, acpi_gbl_db_commands[i].name),
  569. user_command) == acpi_gbl_db_commands[i].name) {
  570. return (i);
  571. }
  572. }
  573. /* Command not recognized */
  574. return (CMD_NOT_FOUND);
  575. }
  576. /*******************************************************************************
  577. *
  578. * FUNCTION: acpi_db_command_dispatch
  579. *
  580. * PARAMETERS: input_buffer - Command line buffer
  581. * walk_state - Current walk
  582. * op - Current (executing) parse op
  583. *
  584. * RETURN: Status
  585. *
  586. * DESCRIPTION: Command dispatcher.
  587. *
  588. ******************************************************************************/
  589. acpi_status
  590. acpi_db_command_dispatch(char *input_buffer,
  591. struct acpi_walk_state *walk_state,
  592. union acpi_parse_object *op)
  593. {
  594. u32 temp;
  595. u32 command_index;
  596. u32 param_count;
  597. char *command_line;
  598. acpi_status status = AE_CTRL_TRUE;
  599. /* If acpi_terminate has been called, terminate this thread */
  600. if (acpi_gbl_db_terminate_loop) {
  601. return (AE_CTRL_TERMINATE);
  602. }
  603. /* Find command and add to the history buffer */
  604. param_count = acpi_db_get_line(input_buffer);
  605. command_index = acpi_db_match_command(acpi_gbl_db_args[0]);
  606. temp = 0;
  607. /*
  608. * We don't want to add the !! command to the history buffer. It
  609. * would cause an infinite loop because it would always be the
  610. * previous command.
  611. */
  612. if (command_index != CMD_HISTORY_LAST) {
  613. acpi_db_add_to_history(input_buffer);
  614. }
  615. /* Verify that we have the minimum number of params */
  616. if (param_count < acpi_gbl_db_commands[command_index].min_args) {
  617. acpi_os_printf
  618. ("%u parameters entered, [%s] requires %u parameters\n",
  619. param_count, acpi_gbl_db_commands[command_index].name,
  620. acpi_gbl_db_commands[command_index].min_args);
  621. acpi_db_display_command_info(acpi_gbl_db_commands
  622. [command_index].name, FALSE);
  623. return (AE_CTRL_TRUE);
  624. }
  625. /* Decode and dispatch the command */
  626. switch (command_index) {
  627. case CMD_NULL:
  628. if (op) {
  629. return (AE_OK);
  630. }
  631. break;
  632. case CMD_ALLOCATIONS:
  633. #ifdef ACPI_DBG_TRACK_ALLOCATIONS
  634. acpi_ut_dump_allocations((u32)-1, NULL);
  635. #endif
  636. break;
  637. case CMD_ARGS:
  638. case CMD_ARGUMENTS:
  639. acpi_db_display_arguments();
  640. break;
  641. case CMD_BREAKPOINT:
  642. acpi_db_set_method_breakpoint(acpi_gbl_db_args[1], walk_state,
  643. op);
  644. break;
  645. case CMD_BUSINFO:
  646. acpi_db_get_bus_info();
  647. break;
  648. case CMD_CALL:
  649. acpi_db_set_method_call_breakpoint(op);
  650. status = AE_OK;
  651. break;
  652. case CMD_DEBUG:
  653. acpi_db_execute(acpi_gbl_db_args[1],
  654. &acpi_gbl_db_args[2], &acpi_gbl_db_arg_types[2],
  655. EX_SINGLE_STEP);
  656. break;
  657. case CMD_DISASSEMBLE:
  658. case CMD_DISASM:
  659. (void)acpi_db_disassemble_method(acpi_gbl_db_args[1]);
  660. break;
  661. case CMD_DUMP:
  662. acpi_db_decode_and_display_object(acpi_gbl_db_args[1],
  663. acpi_gbl_db_args[2]);
  664. break;
  665. case CMD_EVALUATE:
  666. case CMD_EXECUTE:
  667. acpi_db_execute(acpi_gbl_db_args[1],
  668. &acpi_gbl_db_args[2], &acpi_gbl_db_arg_types[2],
  669. EX_NO_SINGLE_STEP);
  670. break;
  671. case CMD_FIND:
  672. status = acpi_db_find_name_in_namespace(acpi_gbl_db_args[1]);
  673. break;
  674. case CMD_GO:
  675. acpi_gbl_cm_single_step = FALSE;
  676. return (AE_OK);
  677. case CMD_HANDLERS:
  678. acpi_db_display_handlers();
  679. break;
  680. case CMD_HELP:
  681. case CMD_HELP2:
  682. acpi_db_display_help(acpi_gbl_db_args[1]);
  683. break;
  684. case CMD_HISTORY:
  685. acpi_db_display_history();
  686. break;
  687. case CMD_HISTORY_EXE: /* ! command */
  688. command_line = acpi_db_get_from_history(acpi_gbl_db_args[1]);
  689. if (!command_line) {
  690. return (AE_CTRL_TRUE);
  691. }
  692. status = acpi_db_command_dispatch(command_line, walk_state, op);
  693. return (status);
  694. case CMD_HISTORY_LAST: /* !! command */
  695. command_line = acpi_db_get_from_history(NULL);
  696. if (!command_line) {
  697. return (AE_CTRL_TRUE);
  698. }
  699. status = acpi_db_command_dispatch(command_line, walk_state, op);
  700. return (status);
  701. case CMD_INFORMATION:
  702. acpi_db_display_method_info(op);
  703. break;
  704. case CMD_INTEGRITY:
  705. acpi_db_check_integrity();
  706. break;
  707. case CMD_INTO:
  708. if (op) {
  709. acpi_gbl_cm_single_step = TRUE;
  710. return (AE_OK);
  711. }
  712. break;
  713. case CMD_LEVEL:
  714. if (param_count == 0) {
  715. acpi_os_printf
  716. ("Current debug level for file output is: %8.8lX\n",
  717. acpi_gbl_db_debug_level);
  718. acpi_os_printf
  719. ("Current debug level for console output is: %8.8lX\n",
  720. acpi_gbl_db_console_debug_level);
  721. } else if (param_count == 2) {
  722. temp = acpi_gbl_db_console_debug_level;
  723. acpi_gbl_db_console_debug_level =
  724. strtoul(acpi_gbl_db_args[1], NULL, 16);
  725. acpi_os_printf
  726. ("Debug Level for console output was %8.8lX, now %8.8lX\n",
  727. temp, acpi_gbl_db_console_debug_level);
  728. } else {
  729. temp = acpi_gbl_db_debug_level;
  730. acpi_gbl_db_debug_level =
  731. strtoul(acpi_gbl_db_args[1], NULL, 16);
  732. acpi_os_printf
  733. ("Debug Level for file output was %8.8lX, now %8.8lX\n",
  734. temp, acpi_gbl_db_debug_level);
  735. }
  736. break;
  737. case CMD_LIST:
  738. acpi_db_disassemble_aml(acpi_gbl_db_args[1], op);
  739. break;
  740. case CMD_LOCKS:
  741. acpi_db_display_locks();
  742. break;
  743. case CMD_LOCALS:
  744. acpi_db_display_locals();
  745. break;
  746. case CMD_METHODS:
  747. status = acpi_db_display_objects("METHOD", acpi_gbl_db_args[1]);
  748. break;
  749. case CMD_NAMESPACE:
  750. acpi_db_dump_namespace(acpi_gbl_db_args[1],
  751. acpi_gbl_db_args[2]);
  752. break;
  753. case CMD_NOTIFY:
  754. temp = strtoul(acpi_gbl_db_args[2], NULL, 0);
  755. acpi_db_send_notify(acpi_gbl_db_args[1], temp);
  756. break;
  757. case CMD_OBJECTS:
  758. acpi_ut_strupr(acpi_gbl_db_args[1]);
  759. status =
  760. acpi_db_display_objects(acpi_gbl_db_args[1],
  761. acpi_gbl_db_args[2]);
  762. break;
  763. case CMD_OSI:
  764. acpi_db_display_interfaces(acpi_gbl_db_args[1],
  765. acpi_gbl_db_args[2]);
  766. break;
  767. case CMD_OWNER:
  768. acpi_db_dump_namespace_by_owner(acpi_gbl_db_args[1],
  769. acpi_gbl_db_args[2]);
  770. break;
  771. case CMD_PATHS:
  772. acpi_db_dump_namespace_paths();
  773. break;
  774. case CMD_PREFIX:
  775. acpi_db_set_scope(acpi_gbl_db_args[1]);
  776. break;
  777. case CMD_REFERENCES:
  778. acpi_db_find_references(acpi_gbl_db_args[1]);
  779. break;
  780. case CMD_RESOURCES:
  781. acpi_db_display_resources(acpi_gbl_db_args[1]);
  782. break;
  783. case CMD_RESULTS:
  784. acpi_db_display_results();
  785. break;
  786. case CMD_SET:
  787. acpi_db_set_method_data(acpi_gbl_db_args[1],
  788. acpi_gbl_db_args[2],
  789. acpi_gbl_db_args[3]);
  790. break;
  791. case CMD_STATS:
  792. status = acpi_db_display_statistics(acpi_gbl_db_args[1]);
  793. break;
  794. case CMD_STOP:
  795. return (AE_NOT_IMPLEMENTED);
  796. case CMD_TABLES:
  797. acpi_db_display_table_info(acpi_gbl_db_args[1]);
  798. break;
  799. case CMD_TEMPLATE:
  800. acpi_db_display_template(acpi_gbl_db_args[1]);
  801. break;
  802. case CMD_TRACE:
  803. acpi_db_trace(acpi_gbl_db_args[1], acpi_gbl_db_args[2],
  804. acpi_gbl_db_args[3]);
  805. break;
  806. case CMD_TREE:
  807. acpi_db_display_calling_tree();
  808. break;
  809. case CMD_TYPE:
  810. acpi_db_display_object_type(acpi_gbl_db_args[1]);
  811. break;
  812. #ifdef ACPI_APPLICATION
  813. /* Hardware simulation commands. */
  814. case CMD_ENABLEACPI:
  815. #if (!ACPI_REDUCED_HARDWARE)
  816. status = acpi_enable();
  817. if (ACPI_FAILURE(status)) {
  818. acpi_os_printf("AcpiEnable failed (Status=%X)\n",
  819. status);
  820. return (status);
  821. }
  822. #endif /* !ACPI_REDUCED_HARDWARE */
  823. break;
  824. case CMD_EVENT:
  825. acpi_os_printf("Event command not implemented\n");
  826. break;
  827. case CMD_GPE:
  828. acpi_db_generate_gpe(acpi_gbl_db_args[1], acpi_gbl_db_args[2]);
  829. break;
  830. case CMD_GPES:
  831. acpi_db_display_gpes();
  832. break;
  833. case CMD_SCI:
  834. acpi_db_generate_sci();
  835. break;
  836. case CMD_SLEEP:
  837. status = acpi_db_sleep(acpi_gbl_db_args[1]);
  838. break;
  839. /* File I/O commands. */
  840. case CMD_CLOSE:
  841. acpi_db_close_debug_file();
  842. break;
  843. case CMD_LOAD:{
  844. struct acpi_new_table_desc *list_head = NULL;
  845. status =
  846. ac_get_all_tables_from_file(acpi_gbl_db_args[1],
  847. ACPI_GET_ALL_TABLES,
  848. &list_head);
  849. if (ACPI_SUCCESS(status)) {
  850. acpi_db_load_tables(list_head);
  851. }
  852. }
  853. break;
  854. case CMD_OPEN:
  855. acpi_db_open_debug_file(acpi_gbl_db_args[1]);
  856. break;
  857. /* User space commands. */
  858. case CMD_TERMINATE:
  859. acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT);
  860. acpi_ut_subsystem_shutdown();
  861. /*
  862. * TBD: [Restructure] Need some way to re-initialize without
  863. * re-creating the semaphores!
  864. */
  865. acpi_gbl_db_terminate_loop = TRUE;
  866. /* acpi_initialize (NULL); */
  867. break;
  868. case CMD_THREADS:
  869. acpi_db_create_execution_threads(acpi_gbl_db_args[1],
  870. acpi_gbl_db_args[2],
  871. acpi_gbl_db_args[3]);
  872. break;
  873. /* Debug test commands. */
  874. case CMD_PREDEFINED:
  875. acpi_db_check_predefined_names();
  876. break;
  877. case CMD_TEST:
  878. acpi_db_execute_test(acpi_gbl_db_args[1]);
  879. break;
  880. case CMD_UNLOAD:
  881. acpi_db_unload_acpi_table(acpi_gbl_db_args[1]);
  882. break;
  883. #endif
  884. case CMD_EXIT:
  885. case CMD_QUIT:
  886. if (op) {
  887. acpi_os_printf("Method execution terminated\n");
  888. return (AE_CTRL_TERMINATE);
  889. }
  890. if (!acpi_gbl_db_output_to_file) {
  891. acpi_dbg_level = ACPI_DEBUG_DEFAULT;
  892. }
  893. #ifdef ACPI_APPLICATION
  894. acpi_db_close_debug_file();
  895. #endif
  896. acpi_gbl_db_terminate_loop = TRUE;
  897. return (AE_CTRL_TERMINATE);
  898. case CMD_NOT_FOUND:
  899. default:
  900. acpi_os_printf("%s: unknown command\n", acpi_gbl_db_args[0]);
  901. return (AE_CTRL_TRUE);
  902. }
  903. if (ACPI_SUCCESS(status)) {
  904. status = AE_CTRL_TRUE;
  905. }
  906. return (status);
  907. }
  908. /*******************************************************************************
  909. *
  910. * FUNCTION: acpi_db_execute_thread
  911. *
  912. * PARAMETERS: context - Not used
  913. *
  914. * RETURN: None
  915. *
  916. * DESCRIPTION: Debugger execute thread. Waits for a command line, then
  917. * simply dispatches it.
  918. *
  919. ******************************************************************************/
  920. void ACPI_SYSTEM_XFACE acpi_db_execute_thread(void *context)
  921. {
  922. (void)acpi_db_user_commands();
  923. acpi_gbl_db_threads_terminated = TRUE;
  924. }
  925. /*******************************************************************************
  926. *
  927. * FUNCTION: acpi_db_user_commands
  928. *
  929. * PARAMETERS: None
  930. *
  931. * RETURN: None
  932. *
  933. * DESCRIPTION: Command line execution for the AML debugger. Commands are
  934. * matched and dispatched here.
  935. *
  936. ******************************************************************************/
  937. acpi_status acpi_db_user_commands(void)
  938. {
  939. acpi_status status = AE_OK;
  940. acpi_os_printf("\n");
  941. /* TBD: [Restructure] Need a separate command line buffer for step mode */
  942. while (!acpi_gbl_db_terminate_loop) {
  943. /* Wait the readiness of the command */
  944. status = acpi_os_wait_command_ready();
  945. if (ACPI_FAILURE(status)) {
  946. break;
  947. }
  948. /* Just call to the command line interpreter */
  949. acpi_gbl_method_executing = FALSE;
  950. acpi_gbl_step_to_next_call = FALSE;
  951. (void)acpi_db_command_dispatch(acpi_gbl_db_line_buf, NULL,
  952. NULL);
  953. /* Notify the completion of the command */
  954. status = acpi_os_notify_command_complete();
  955. if (ACPI_FAILURE(status)) {
  956. break;
  957. }
  958. }
  959. if (ACPI_FAILURE(status) && status != AE_CTRL_TERMINATE) {
  960. ACPI_EXCEPTION((AE_INFO, status, "While parsing command line"));
  961. }
  962. return (status);
  963. }