dbmethod.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /*******************************************************************************
  2. *
  3. * Module Name: dbmethod - Debug commands for control methods
  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 "acdispat.h"
  45. #include "acnamesp.h"
  46. #include "acdebug.h"
  47. #include "acparser.h"
  48. #include "acpredef.h"
  49. #define _COMPONENT ACPI_CA_DEBUGGER
  50. ACPI_MODULE_NAME("dbmethod")
  51. /*******************************************************************************
  52. *
  53. * FUNCTION: acpi_db_set_method_breakpoint
  54. *
  55. * PARAMETERS: location - AML offset of breakpoint
  56. * walk_state - Current walk info
  57. * op - Current Op (from parse walk)
  58. *
  59. * RETURN: None
  60. *
  61. * DESCRIPTION: Set a breakpoint in a control method at the specified
  62. * AML offset
  63. *
  64. ******************************************************************************/
  65. void
  66. acpi_db_set_method_breakpoint(char *location,
  67. struct acpi_walk_state *walk_state,
  68. union acpi_parse_object *op)
  69. {
  70. u32 address;
  71. u32 aml_offset;
  72. if (!op) {
  73. acpi_os_printf("There is no method currently executing\n");
  74. return;
  75. }
  76. /* Get and verify the breakpoint address */
  77. address = strtoul(location, NULL, 16);
  78. aml_offset = (u32)ACPI_PTR_DIFF(op->common.aml,
  79. walk_state->parser_state.aml_start);
  80. if (address <= aml_offset) {
  81. acpi_os_printf("Breakpoint %X is beyond current address %X\n",
  82. address, aml_offset);
  83. }
  84. /* Save breakpoint in current walk */
  85. walk_state->user_breakpoint = address;
  86. acpi_os_printf("Breakpoint set at AML offset %X\n", address);
  87. }
  88. /*******************************************************************************
  89. *
  90. * FUNCTION: acpi_db_set_method_call_breakpoint
  91. *
  92. * PARAMETERS: op - Current Op (from parse walk)
  93. *
  94. * RETURN: None
  95. *
  96. * DESCRIPTION: Set a breakpoint in a control method at the specified
  97. * AML offset
  98. *
  99. ******************************************************************************/
  100. void acpi_db_set_method_call_breakpoint(union acpi_parse_object *op)
  101. {
  102. if (!op) {
  103. acpi_os_printf("There is no method currently executing\n");
  104. return;
  105. }
  106. acpi_gbl_step_to_next_call = TRUE;
  107. }
  108. /*******************************************************************************
  109. *
  110. * FUNCTION: acpi_db_set_method_data
  111. *
  112. * PARAMETERS: type_arg - L for local, A for argument
  113. * index_arg - which one
  114. * value_arg - Value to set.
  115. *
  116. * RETURN: None
  117. *
  118. * DESCRIPTION: Set a local or argument for the running control method.
  119. * NOTE: only object supported is Number.
  120. *
  121. ******************************************************************************/
  122. void acpi_db_set_method_data(char *type_arg, char *index_arg, char *value_arg)
  123. {
  124. char type;
  125. u32 index;
  126. u32 value;
  127. struct acpi_walk_state *walk_state;
  128. union acpi_operand_object *obj_desc;
  129. acpi_status status;
  130. struct acpi_namespace_node *node;
  131. /* Validate type_arg */
  132. acpi_ut_strupr(type_arg);
  133. type = type_arg[0];
  134. if ((type != 'L') && (type != 'A') && (type != 'N')) {
  135. acpi_os_printf("Invalid SET operand: %s\n", type_arg);
  136. return;
  137. }
  138. value = strtoul(value_arg, NULL, 16);
  139. if (type == 'N') {
  140. node = acpi_db_convert_to_node(index_arg);
  141. if (!node) {
  142. return;
  143. }
  144. if (node->type != ACPI_TYPE_INTEGER) {
  145. acpi_os_printf("Can only set Integer nodes\n");
  146. return;
  147. }
  148. obj_desc = node->object;
  149. obj_desc->integer.value = value;
  150. return;
  151. }
  152. /* Get the index and value */
  153. index = strtoul(index_arg, NULL, 16);
  154. walk_state = acpi_ds_get_current_walk_state(acpi_gbl_current_walk_list);
  155. if (!walk_state) {
  156. acpi_os_printf("There is no method currently executing\n");
  157. return;
  158. }
  159. /* Create and initialize the new object */
  160. obj_desc = acpi_ut_create_integer_object((u64)value);
  161. if (!obj_desc) {
  162. acpi_os_printf("Could not create an internal object\n");
  163. return;
  164. }
  165. /* Store the new object into the target */
  166. switch (type) {
  167. case 'A':
  168. /* Set a method argument */
  169. if (index > ACPI_METHOD_MAX_ARG) {
  170. acpi_os_printf("Arg%u - Invalid argument name\n",
  171. index);
  172. goto cleanup;
  173. }
  174. status = acpi_ds_store_object_to_local(ACPI_REFCLASS_ARG,
  175. index, obj_desc,
  176. walk_state);
  177. if (ACPI_FAILURE(status)) {
  178. goto cleanup;
  179. }
  180. obj_desc = walk_state->arguments[index].object;
  181. acpi_os_printf("Arg%u: ", index);
  182. acpi_db_display_internal_object(obj_desc, walk_state);
  183. break;
  184. case 'L':
  185. /* Set a method local */
  186. if (index > ACPI_METHOD_MAX_LOCAL) {
  187. acpi_os_printf
  188. ("Local%u - Invalid local variable name\n", index);
  189. goto cleanup;
  190. }
  191. status = acpi_ds_store_object_to_local(ACPI_REFCLASS_LOCAL,
  192. index, obj_desc,
  193. walk_state);
  194. if (ACPI_FAILURE(status)) {
  195. goto cleanup;
  196. }
  197. obj_desc = walk_state->local_variables[index].object;
  198. acpi_os_printf("Local%u: ", index);
  199. acpi_db_display_internal_object(obj_desc, walk_state);
  200. break;
  201. default:
  202. break;
  203. }
  204. cleanup:
  205. acpi_ut_remove_reference(obj_desc);
  206. }
  207. /*******************************************************************************
  208. *
  209. * FUNCTION: acpi_db_disassemble_aml
  210. *
  211. * PARAMETERS: statements - Number of statements to disassemble
  212. * op - Current Op (from parse walk)
  213. *
  214. * RETURN: None
  215. *
  216. * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
  217. * of statements specified.
  218. *
  219. ******************************************************************************/
  220. void acpi_db_disassemble_aml(char *statements, union acpi_parse_object *op)
  221. {
  222. u32 num_statements = 8;
  223. if (!op) {
  224. acpi_os_printf("There is no method currently executing\n");
  225. return;
  226. }
  227. if (statements) {
  228. num_statements = strtoul(statements, NULL, 0);
  229. }
  230. #ifdef ACPI_DISASSEMBLER
  231. acpi_dm_disassemble(NULL, op, num_statements);
  232. #endif
  233. }
  234. /*******************************************************************************
  235. *
  236. * FUNCTION: acpi_db_disassemble_method
  237. *
  238. * PARAMETERS: name - Name of control method
  239. *
  240. * RETURN: None
  241. *
  242. * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
  243. * of statements specified.
  244. *
  245. ******************************************************************************/
  246. acpi_status acpi_db_disassemble_method(char *name)
  247. {
  248. acpi_status status;
  249. union acpi_parse_object *op;
  250. struct acpi_walk_state *walk_state;
  251. union acpi_operand_object *obj_desc;
  252. struct acpi_namespace_node *method;
  253. method = acpi_db_convert_to_node(name);
  254. if (!method) {
  255. return (AE_BAD_PARAMETER);
  256. }
  257. if (method->type != ACPI_TYPE_METHOD) {
  258. ACPI_ERROR((AE_INFO, "%s (%s): Object must be a control method",
  259. name, acpi_ut_get_type_name(method->type)));
  260. return (AE_BAD_PARAMETER);
  261. }
  262. obj_desc = method->object;
  263. op = acpi_ps_create_scope_op(obj_desc->method.aml_start);
  264. if (!op) {
  265. return (AE_NO_MEMORY);
  266. }
  267. /* Create and initialize a new walk state */
  268. walk_state = acpi_ds_create_walk_state(0, op, NULL, NULL);
  269. if (!walk_state) {
  270. return (AE_NO_MEMORY);
  271. }
  272. status = acpi_ds_init_aml_walk(walk_state, op, NULL,
  273. obj_desc->method.aml_start,
  274. obj_desc->method.aml_length, NULL,
  275. ACPI_IMODE_LOAD_PASS1);
  276. if (ACPI_FAILURE(status)) {
  277. return (status);
  278. }
  279. status = acpi_ut_allocate_owner_id(&obj_desc->method.owner_id);
  280. walk_state->owner_id = obj_desc->method.owner_id;
  281. /* Push start scope on scope stack and make it current */
  282. status = acpi_ds_scope_stack_push(method, method->type, walk_state);
  283. if (ACPI_FAILURE(status)) {
  284. return (status);
  285. }
  286. /* Parse the entire method AML including deferred operators */
  287. walk_state->parse_flags &= ~ACPI_PARSE_DELETE_TREE;
  288. walk_state->parse_flags |= ACPI_PARSE_DISASSEMBLE;
  289. status = acpi_ps_parse_aml(walk_state);
  290. #ifdef ACPI_DISASSEMBLER
  291. (void)acpi_dm_parse_deferred_ops(op);
  292. /* Now we can disassemble the method */
  293. acpi_gbl_dm_opt_verbose = FALSE;
  294. acpi_dm_disassemble(NULL, op, 0);
  295. acpi_gbl_dm_opt_verbose = TRUE;
  296. #endif
  297. acpi_ps_delete_parse_tree(op);
  298. /* Method cleanup */
  299. acpi_ns_delete_namespace_subtree(method);
  300. acpi_ns_delete_namespace_by_owner(obj_desc->method.owner_id);
  301. acpi_ut_release_owner_id(&obj_desc->method.owner_id);
  302. return (AE_OK);
  303. }