1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /*******************************************************************************
4 * Module Name: dbmethod - Debug commands for control methods
6 ******************************************************************************/
16 #define _COMPONENT ACPI_CA_DEBUGGER
17 ACPI_MODULE_NAME("dbmethod")
19 /* Local prototypes */
21 acpi_db_walk_for_execute(acpi_handle obj_handle
,
22 u32 nesting_level
, void *context
, void **return_value
);
24 /*******************************************************************************
26 * FUNCTION: acpi_db_set_method_breakpoint
28 * PARAMETERS: location - AML offset of breakpoint
29 * walk_state - Current walk info
30 * op - Current Op (from parse walk)
34 * DESCRIPTION: Set a breakpoint in a control method at the specified
37 ******************************************************************************/
40 acpi_db_set_method_breakpoint(char *location
,
41 struct acpi_walk_state
*walk_state
,
42 union acpi_parse_object
*op
)
48 acpi_os_printf("There is no method currently executing\n");
52 /* Get and verify the breakpoint address */
54 address
= strtoul(location
, NULL
, 16);
55 aml_offset
= (u32
)ACPI_PTR_DIFF(op
->common
.aml
,
56 walk_state
->parser_state
.aml_start
);
57 if (address
<= aml_offset
) {
58 acpi_os_printf("Breakpoint %X is beyond current address %X\n",
62 /* Save breakpoint in current walk */
64 walk_state
->user_breakpoint
= address
;
65 acpi_os_printf("Breakpoint set at AML offset %X\n", address
);
68 /*******************************************************************************
70 * FUNCTION: acpi_db_set_method_call_breakpoint
72 * PARAMETERS: op - Current Op (from parse walk)
76 * DESCRIPTION: Set a breakpoint in a control method at the specified
79 ******************************************************************************/
81 void acpi_db_set_method_call_breakpoint(union acpi_parse_object
*op
)
85 acpi_os_printf("There is no method currently executing\n");
89 acpi_gbl_step_to_next_call
= TRUE
;
92 /*******************************************************************************
94 * FUNCTION: acpi_db_set_method_data
96 * PARAMETERS: type_arg - L for local, A for argument
97 * index_arg - which one
98 * value_arg - Value to set.
102 * DESCRIPTION: Set a local or argument for the running control method.
103 * NOTE: only object supported is Number.
105 ******************************************************************************/
107 void acpi_db_set_method_data(char *type_arg
, char *index_arg
, char *value_arg
)
112 struct acpi_walk_state
*walk_state
;
113 union acpi_operand_object
*obj_desc
;
115 struct acpi_namespace_node
*node
;
117 /* Validate type_arg */
119 acpi_ut_strupr(type_arg
);
121 if ((type
!= 'L') && (type
!= 'A') && (type
!= 'N')) {
122 acpi_os_printf("Invalid SET operand: %s\n", type_arg
);
126 value
= strtoul(value_arg
, NULL
, 16);
129 node
= acpi_db_convert_to_node(index_arg
);
134 if (node
->type
!= ACPI_TYPE_INTEGER
) {
135 acpi_os_printf("Can only set Integer nodes\n");
138 obj_desc
= node
->object
;
139 obj_desc
->integer
.value
= value
;
143 /* Get the index and value */
145 index
= strtoul(index_arg
, NULL
, 16);
147 walk_state
= acpi_ds_get_current_walk_state(acpi_gbl_current_walk_list
);
149 acpi_os_printf("There is no method currently executing\n");
153 /* Create and initialize the new object */
155 obj_desc
= acpi_ut_create_integer_object((u64
)value
);
157 acpi_os_printf("Could not create an internal object\n");
161 /* Store the new object into the target */
166 /* Set a method argument */
168 if (index
> ACPI_METHOD_MAX_ARG
) {
169 acpi_os_printf("Arg%u - Invalid argument name\n",
174 status
= acpi_ds_store_object_to_local(ACPI_REFCLASS_ARG
,
177 if (ACPI_FAILURE(status
)) {
181 obj_desc
= walk_state
->arguments
[index
].object
;
183 acpi_os_printf("Arg%u: ", index
);
184 acpi_db_display_internal_object(obj_desc
, walk_state
);
189 /* Set a method local */
191 if (index
> ACPI_METHOD_MAX_LOCAL
) {
193 ("Local%u - Invalid local variable name\n", index
);
197 status
= acpi_ds_store_object_to_local(ACPI_REFCLASS_LOCAL
,
200 if (ACPI_FAILURE(status
)) {
204 obj_desc
= walk_state
->local_variables
[index
].object
;
206 acpi_os_printf("Local%u: ", index
);
207 acpi_db_display_internal_object(obj_desc
, walk_state
);
216 acpi_ut_remove_reference(obj_desc
);
219 /*******************************************************************************
221 * FUNCTION: acpi_db_disassemble_aml
223 * PARAMETERS: statements - Number of statements to disassemble
224 * op - Current Op (from parse walk)
228 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
229 * of statements specified.
231 ******************************************************************************/
233 void acpi_db_disassemble_aml(char *statements
, union acpi_parse_object
*op
)
235 u32 num_statements
= 8;
238 acpi_os_printf("There is no method currently executing\n");
243 num_statements
= strtoul(statements
, NULL
, 0);
245 #ifdef ACPI_DISASSEMBLER
246 acpi_dm_disassemble(NULL
, op
, num_statements
);
250 /*******************************************************************************
252 * FUNCTION: acpi_db_disassemble_method
254 * PARAMETERS: name - Name of control method
258 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
259 * of statements specified.
261 ******************************************************************************/
263 acpi_status
acpi_db_disassemble_method(char *name
)
266 union acpi_parse_object
*op
;
267 struct acpi_walk_state
*walk_state
;
268 union acpi_operand_object
*obj_desc
;
269 struct acpi_namespace_node
*method
;
271 method
= acpi_db_convert_to_node(name
);
273 return (AE_BAD_PARAMETER
);
276 if (method
->type
!= ACPI_TYPE_METHOD
) {
277 ACPI_ERROR((AE_INFO
, "%s (%s): Object must be a control method",
278 name
, acpi_ut_get_type_name(method
->type
)));
279 return (AE_BAD_PARAMETER
);
282 obj_desc
= method
->object
;
284 op
= acpi_ps_create_scope_op(obj_desc
->method
.aml_start
);
286 return (AE_NO_MEMORY
);
289 /* Create and initialize a new walk state */
291 walk_state
= acpi_ds_create_walk_state(0, op
, NULL
, NULL
);
293 return (AE_NO_MEMORY
);
296 status
= acpi_ds_init_aml_walk(walk_state
, op
, NULL
,
297 obj_desc
->method
.aml_start
,
298 obj_desc
->method
.aml_length
, NULL
,
299 ACPI_IMODE_LOAD_PASS1
);
300 if (ACPI_FAILURE(status
)) {
304 status
= acpi_ut_allocate_owner_id(&obj_desc
->method
.owner_id
);
305 walk_state
->owner_id
= obj_desc
->method
.owner_id
;
307 /* Push start scope on scope stack and make it current */
309 status
= acpi_ds_scope_stack_push(method
, method
->type
, walk_state
);
310 if (ACPI_FAILURE(status
)) {
314 /* Parse the entire method AML including deferred operators */
316 walk_state
->parse_flags
&= ~ACPI_PARSE_DELETE_TREE
;
317 walk_state
->parse_flags
|= ACPI_PARSE_DISASSEMBLE
;
319 status
= acpi_ps_parse_aml(walk_state
);
321 #ifdef ACPI_DISASSEMBLER
322 (void)acpi_dm_parse_deferred_ops(op
);
324 /* Now we can disassemble the method */
326 acpi_gbl_dm_opt_verbose
= FALSE
;
327 acpi_dm_disassemble(NULL
, op
, 0);
328 acpi_gbl_dm_opt_verbose
= TRUE
;
331 acpi_ps_delete_parse_tree(op
);
335 acpi_ns_delete_namespace_subtree(method
);
336 acpi_ns_delete_namespace_by_owner(obj_desc
->method
.owner_id
);
337 acpi_ut_release_owner_id(&obj_desc
->method
.owner_id
);
341 /*******************************************************************************
343 * FUNCTION: acpi_db_walk_for_execute
345 * PARAMETERS: Callback from walk_namespace
349 * DESCRIPTION: Batch execution module. Currently only executes predefined
352 ******************************************************************************/
355 acpi_db_walk_for_execute(acpi_handle obj_handle
,
356 u32 nesting_level
, void *context
, void **return_value
)
358 struct acpi_namespace_node
*node
=
359 (struct acpi_namespace_node
*)obj_handle
;
360 struct acpi_db_execute_walk
*info
=
361 (struct acpi_db_execute_walk
*)context
;
362 struct acpi_buffer return_obj
;
366 struct acpi_device_info
*obj_info
;
367 struct acpi_object_list param_objects
;
368 union acpi_object params
[ACPI_METHOD_NUM_ARGS
];
369 const union acpi_predefined_info
*predefined
;
371 predefined
= acpi_ut_match_predefined_method(node
->name
.ascii
);
376 if (node
->type
== ACPI_TYPE_LOCAL_SCOPE
) {
380 pathname
= acpi_ns_get_external_pathname(node
);
385 /* Get the object info for number of method parameters */
387 status
= acpi_get_object_info(obj_handle
, &obj_info
);
388 if (ACPI_FAILURE(status
)) {
393 param_objects
.pointer
= NULL
;
394 param_objects
.count
= 0;
396 if (obj_info
->type
== ACPI_TYPE_METHOD
) {
398 /* Setup default parameters */
400 for (i
= 0; i
< obj_info
->param_count
; i
++) {
401 params
[i
].type
= ACPI_TYPE_INTEGER
;
402 params
[i
].integer
.value
= 1;
405 param_objects
.pointer
= params
;
406 param_objects
.count
= obj_info
->param_count
;
410 return_obj
.pointer
= NULL
;
411 return_obj
.length
= ACPI_ALLOCATE_BUFFER
;
413 /* Do the actual method execution */
415 acpi_gbl_method_executing
= TRUE
;
417 status
= acpi_evaluate_object(node
, NULL
, ¶m_objects
, &return_obj
);
419 acpi_os_printf("%-32s returned %s\n", pathname
,
420 acpi_format_exception(status
));
421 acpi_gbl_method_executing
= FALSE
;
424 /* Ignore status from method execution */
428 /* Update count, check if we have executed enough methods */
431 if (info
->count
>= info
->max_count
) {
432 status
= AE_CTRL_TERMINATE
;
438 /*******************************************************************************
440 * FUNCTION: acpi_db_evaluate_predefined_names
446 * DESCRIPTION: Namespace batch execution. Execute predefined names in the
447 * namespace, up to the max count, if specified.
449 ******************************************************************************/
451 void acpi_db_evaluate_predefined_names(void)
453 struct acpi_db_execute_walk info
;
456 info
.max_count
= ACPI_UINT32_MAX
;
458 /* Search all nodes in namespace */
460 (void)acpi_walk_namespace(ACPI_TYPE_ANY
, ACPI_ROOT_OBJECT
,
461 ACPI_UINT32_MAX
, acpi_db_walk_for_execute
,
462 NULL
, (void *)&info
, NULL
);
464 acpi_os_printf("Evaluated %u predefined names in the namespace\n",