1 /******************************************************************************
3 * Module Name: dswexec - Dispatcher method execution callbacks;
4 * dispatch to interpreter.
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2005, R. Byron Moore
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
46 #include <acpi/acpi.h>
47 #include <acpi/acparser.h>
48 #include <acpi/amlcode.h>
49 #include <acpi/acdispat.h>
50 #include <acpi/acinterp.h>
51 #include <acpi/acnamesp.h>
52 #include <acpi/acdebug.h>
53 #include <acpi/acdisasm.h>
56 #define _COMPONENT ACPI_DISPATCHER
57 ACPI_MODULE_NAME ("dswexec")
60 * Dispatch table for opcode classes
62 static ACPI_EXECUTE_OP acpi_gbl_op_type_dispatch [] = {
63 acpi_ex_opcode_0A_0T_1R,
64 acpi_ex_opcode_1A_0T_0R,
65 acpi_ex_opcode_1A_0T_1R,
66 acpi_ex_opcode_1A_1T_0R,
67 acpi_ex_opcode_1A_1T_1R,
68 acpi_ex_opcode_2A_0T_0R,
69 acpi_ex_opcode_2A_0T_1R,
70 acpi_ex_opcode_2A_1T_1R,
71 acpi_ex_opcode_2A_2T_1R,
72 acpi_ex_opcode_3A_0T_0R,
73 acpi_ex_opcode_3A_1T_1R,
74 acpi_ex_opcode_6A_0T_1R};
77 /*****************************************************************************
79 * FUNCTION: acpi_ds_get_predicate_value
81 * PARAMETERS: walk_state - Current state of the parse tree walk
82 * result_obj - if non-zero, pop result from result stack
86 * DESCRIPTION: Get the result of a predicate evaluation
88 ****************************************************************************/
91 acpi_ds_get_predicate_value (
92 struct acpi_walk_state *walk_state,
93 union acpi_operand_object *result_obj) {
94 acpi_status status = AE_OK;
95 union acpi_operand_object *obj_desc;
96 union acpi_operand_object *local_obj_desc = NULL;
99 ACPI_FUNCTION_TRACE_PTR ("ds_get_predicate_value", walk_state);
102 walk_state->control_state->common.state = 0;
105 status = acpi_ds_result_pop (&obj_desc, walk_state);
106 if (ACPI_FAILURE (status)) {
107 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
108 "Could not get result from predicate evaluation, %s\n",
109 acpi_format_exception (status)));
111 return_ACPI_STATUS (status);
115 status = acpi_ds_create_operand (walk_state, walk_state->op, 0);
116 if (ACPI_FAILURE (status)) {
117 return_ACPI_STATUS (status);
120 status = acpi_ex_resolve_to_value (&walk_state->operands [0], walk_state);
121 if (ACPI_FAILURE (status)) {
122 return_ACPI_STATUS (status);
125 obj_desc = walk_state->operands [0];
129 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
130 "No predicate obj_desc=%p State=%p\n",
131 obj_desc, walk_state));
133 return_ACPI_STATUS (AE_AML_NO_OPERAND);
137 * Result of predicate evaluation must be an Integer
138 * object. Implicitly convert the argument if necessary.
140 status = acpi_ex_convert_to_integer (obj_desc, &local_obj_desc, 16);
141 if (ACPI_FAILURE (status)) {
145 if (ACPI_GET_OBJECT_TYPE (local_obj_desc) != ACPI_TYPE_INTEGER) {
146 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
147 "Bad predicate (not an integer) obj_desc=%p State=%p Type=%X\n",
148 obj_desc, walk_state, ACPI_GET_OBJECT_TYPE (obj_desc)));
150 status = AE_AML_OPERAND_TYPE;
154 /* Truncate the predicate to 32-bits if necessary */
156 acpi_ex_truncate_for32bit_table (local_obj_desc);
159 * Save the result of the predicate evaluation on
162 if (local_obj_desc->integer.value) {
163 walk_state->control_state->common.value = TRUE;
167 * Predicate is FALSE, we will just toss the
168 * rest of the package
170 walk_state->control_state->common.value = FALSE;
171 status = AE_CTRL_FALSE;
177 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Completed a predicate eval=%X Op=%p\n",
178 walk_state->control_state->common.value, walk_state->op));
180 /* Break to debugger to display result */
182 ACPI_DEBUGGER_EXEC (acpi_db_display_result_object (local_obj_desc, walk_state));
185 * Delete the predicate result object (we know that
186 * we don't need it anymore)
188 if (local_obj_desc != obj_desc) {
189 acpi_ut_remove_reference (local_obj_desc);
191 acpi_ut_remove_reference (obj_desc);
193 walk_state->control_state->common.state = ACPI_CONTROL_NORMAL;
194 return_ACPI_STATUS (status);
198 /*****************************************************************************
200 * FUNCTION: acpi_ds_exec_begin_op
202 * PARAMETERS: walk_state - Current state of the parse tree walk
203 * out_op - Where to return op if a new one is created
207 * DESCRIPTION: Descending callback used during the execution of control
208 * methods. This is where most operators and operands are
209 * dispatched to the interpreter.
211 ****************************************************************************/
214 acpi_ds_exec_begin_op (
215 struct acpi_walk_state *walk_state,
216 union acpi_parse_object **out_op)
218 union acpi_parse_object *op;
219 acpi_status status = AE_OK;
223 ACPI_FUNCTION_TRACE_PTR ("ds_exec_begin_op", walk_state);
228 status = acpi_ds_load2_begin_op (walk_state, out_op);
229 if (ACPI_FAILURE (status)) {
230 return_ACPI_STATUS (status);
235 walk_state->opcode = op->common.aml_opcode;
236 walk_state->op_info = acpi_ps_get_opcode_info (op->common.aml_opcode);
238 if (acpi_ns_opens_scope (walk_state->op_info->object_type)) {
239 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
240 "(%s) Popping scope for Op %p\n",
241 acpi_ut_get_type_name (walk_state->op_info->object_type), op));
243 status = acpi_ds_scope_stack_pop (walk_state);
244 if (ACPI_FAILURE (status)) {
245 return_ACPI_STATUS (status);
250 if (op == walk_state->origin) {
255 return_ACPI_STATUS (AE_OK);
259 * If the previous opcode was a conditional, this opcode
260 * must be the beginning of the associated predicate.
261 * Save this knowledge in the current scope descriptor
263 if ((walk_state->control_state) &&
264 (walk_state->control_state->common.state ==
265 ACPI_CONTROL_CONDITIONAL_EXECUTING)) {
266 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Exec predicate Op=%p State=%p\n",
269 walk_state->control_state->common.state = ACPI_CONTROL_PREDICATE_EXECUTING;
271 /* Save start of predicate */
273 walk_state->control_state->control.predicate_op = op;
277 opcode_class = walk_state->op_info->class;
279 /* We want to send namepaths to the load code */
281 if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
282 opcode_class = AML_CLASS_NAMED_OBJECT;
286 * Handle the opcode based upon the opcode type
288 switch (opcode_class) {
289 case AML_CLASS_CONTROL:
291 status = acpi_ds_result_stack_push (walk_state);
292 if (ACPI_FAILURE (status)) {
293 return_ACPI_STATUS (status);
296 status = acpi_ds_exec_begin_control_op (walk_state, op);
300 case AML_CLASS_NAMED_OBJECT:
302 if (walk_state->walk_type == ACPI_WALK_METHOD) {
304 * Found a named object declaration during method execution;
305 * we must enter this object into the namespace. The created
306 * object is temporary and will be deleted upon completion of
307 * the execution of this method.
309 status = acpi_ds_load2_begin_op (walk_state, NULL);
312 if (op->common.aml_opcode == AML_REGION_OP) {
313 status = acpi_ds_result_stack_push (walk_state);
318 case AML_CLASS_EXECUTE:
319 case AML_CLASS_CREATE:
322 * Most operators with arguments.
323 * Start a new result/operand state
325 status = acpi_ds_result_stack_push (walk_state);
333 /* Nothing to do here during method execution */
335 return_ACPI_STATUS (status);
339 /*****************************************************************************
341 * FUNCTION: acpi_ds_exec_end_op
343 * PARAMETERS: walk_state - Current state of the parse tree walk
347 * DESCRIPTION: Ascending callback used during the execution of control
348 * methods. The only thing we really need to do here is to
349 * notice the beginning of IF, ELSE, and WHILE blocks.
351 ****************************************************************************/
354 acpi_ds_exec_end_op (
355 struct acpi_walk_state *walk_state)
357 union acpi_parse_object *op;
358 acpi_status status = AE_OK;
361 union acpi_parse_object *next_op;
362 union acpi_parse_object *first_arg;
365 ACPI_FUNCTION_TRACE_PTR ("ds_exec_end_op", walk_state);
369 op_type = walk_state->op_info->type;
370 op_class = walk_state->op_info->class;
372 if (op_class == AML_CLASS_UNKNOWN) {
373 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown opcode %X\n", op->common.aml_opcode));
374 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
377 first_arg = op->common.value.arg;
379 /* Init the walk state */
381 walk_state->num_operands = 0;
382 walk_state->return_desc = NULL;
383 walk_state->result_obj = NULL;
385 /* Call debugger for single step support (DEBUG build only) */
387 ACPI_DEBUGGER_EXEC (status = acpi_db_single_step (walk_state, op, op_class));
388 ACPI_DEBUGGER_EXEC (if (ACPI_FAILURE (status)) {return_ACPI_STATUS (status);});
390 /* Decode the Opcode Class */
393 case AML_CLASS_ARGUMENT: /* constants, literals, etc. - do nothing */
397 case AML_CLASS_EXECUTE: /* most operators with arguments */
399 /* Build resolved operand stack */
401 status = acpi_ds_create_operands (walk_state, first_arg);
402 if (ACPI_FAILURE (status)) {
406 /* Done with this result state (Now that operand stack is built) */
408 status = acpi_ds_result_stack_pop (walk_state);
409 if (ACPI_FAILURE (status)) {
414 * All opcodes require operand resolution, with the only exceptions
415 * being the object_type and size_of operators.
417 if (!(walk_state->op_info->flags & AML_NO_OPERAND_RESOLVE)) {
418 /* Resolve all operands */
420 status = acpi_ex_resolve_operands (walk_state->opcode,
421 &(walk_state->operands [walk_state->num_operands -1]),
423 if (ACPI_SUCCESS (status)) {
424 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
425 acpi_ps_get_opcode_name (walk_state->opcode),
426 walk_state->num_operands, "after ex_resolve_operands");
430 if (ACPI_SUCCESS (status)) {
432 * Dispatch the request to the appropriate interpreter handler
433 * routine. There is one routine per opcode "type" based upon the
434 * number of opcode arguments and return type.
436 status = acpi_gbl_op_type_dispatch[op_type] (walk_state);
440 * Treat constructs of the form "Store(local_x,local_x)" as noops when the
441 * Local is uninitialized.
443 if ((status == AE_AML_UNINITIALIZED_LOCAL) &&
444 (walk_state->opcode == AML_STORE_OP) &&
445 (walk_state->operands[0]->common.type == ACPI_TYPE_LOCAL_REFERENCE) &&
446 (walk_state->operands[1]->common.type == ACPI_TYPE_LOCAL_REFERENCE) &&
447 (walk_state->operands[0]->reference.opcode ==
448 walk_state->operands[1]->reference.opcode) &&
449 (walk_state->operands[0]->reference.offset ==
450 walk_state->operands[1]->reference.offset)) {
454 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
455 "[%s]: Could not resolve operands, %s\n",
456 acpi_ps_get_opcode_name (walk_state->opcode),
457 acpi_format_exception (status)));
461 /* Always delete the argument objects and clear the operand stack */
463 acpi_ds_clear_operands (walk_state);
466 * If a result object was returned from above, push it on the
467 * current result stack
469 if (ACPI_SUCCESS (status) &&
470 walk_state->result_obj) {
471 status = acpi_ds_result_push (walk_state->result_obj, walk_state);
480 case AML_TYPE_CONTROL: /* Type 1 opcode, IF/ELSE/WHILE/NOOP */
482 /* 1 Operand, 0 external_result, 0 internal_result */
484 status = acpi_ds_exec_end_control_op (walk_state, op);
486 /* Make sure to properly pop the result stack */
488 if (ACPI_SUCCESS (status)) {
489 status = acpi_ds_result_stack_pop (walk_state);
491 else if (status == AE_CTRL_PENDING) {
492 status = acpi_ds_result_stack_pop (walk_state);
493 if (ACPI_SUCCESS (status)) {
494 status = AE_CTRL_PENDING;
500 case AML_TYPE_METHOD_CALL:
503 * If the method is referenced from within a package
504 * declaration, it is not a invocation of the method, just
507 if ((op->asl.parent) &&
508 ((op->asl.parent->asl.aml_opcode == AML_PACKAGE_OP) ||
509 (op->asl.parent->asl.aml_opcode == AML_VAR_PACKAGE_OP))) {
510 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
511 "Method Reference in a Package, Op=%p\n", op));
512 op->common.node = (struct acpi_namespace_node *) op->asl.value.arg->asl.node->object;
513 acpi_ut_add_reference (op->asl.value.arg->asl.node->object);
514 return_ACPI_STATUS (AE_OK);
517 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Method invocation, Op=%p\n", op));
520 * (AML_METHODCALL) Op->Asl.Value.Arg->Asl.Node contains
521 * the method Node pointer
523 /* next_op points to the op that holds the method name */
527 /* next_op points to first argument op */
529 next_op = next_op->common.next;
532 * Get the method's arguments and put them on the operand stack
534 status = acpi_ds_create_operands (walk_state, next_op);
535 if (ACPI_FAILURE (status)) {
540 * Since the operands will be passed to another control method,
541 * we must resolve all local references here (Local variables,
542 * arguments to *this* method, etc.)
544 status = acpi_ds_resolve_operands (walk_state);
545 if (ACPI_FAILURE (status)) {
546 /* On error, clear all resolved operands */
548 acpi_ds_clear_operands (walk_state);
553 * Tell the walk loop to preempt this running method and
554 * execute the new method
556 status = AE_CTRL_TRANSFER;
559 * Return now; we don't want to disturb anything,
560 * especially the operand count!
562 return_ACPI_STATUS (status);
565 case AML_TYPE_CREATE_FIELD:
567 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
568 "Executing create_field Buffer/Index Op=%p\n", op));
570 status = acpi_ds_load2_end_op (walk_state);
571 if (ACPI_FAILURE (status)) {
575 status = acpi_ds_eval_buffer_field_operands (walk_state, op);
579 case AML_TYPE_CREATE_OBJECT:
581 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
582 "Executing create_object (Buffer/Package) Op=%p\n", op));
584 switch (op->common.parent->common.aml_opcode) {
588 * Put the Node on the object stack (Contains the ACPI Name
591 walk_state->operands[0] = (void *) op->common.parent->common.node;
592 walk_state->num_operands = 1;
594 status = acpi_ds_create_node (walk_state,
595 op->common.parent->common.node,
597 if (ACPI_FAILURE (status)) {
602 /*lint -fallthrough */
604 case AML_INT_EVAL_SUBTREE_OP:
606 status = acpi_ds_eval_data_object_operands (walk_state, op,
607 acpi_ns_get_attached_object (op->common.parent->common.node));
612 status = acpi_ds_eval_data_object_operands (walk_state, op, NULL);
616 /* Done with result state (Now that operand stack is built) */
618 status = acpi_ds_result_stack_pop (walk_state);
619 if (ACPI_FAILURE (status)) {
624 * If a result object was returned from above, push it on the
625 * current result stack
627 if (walk_state->result_obj) {
628 status = acpi_ds_result_push (walk_state->result_obj, walk_state);
633 case AML_TYPE_NAMED_FIELD:
634 case AML_TYPE_NAMED_COMPLEX:
635 case AML_TYPE_NAMED_SIMPLE:
636 case AML_TYPE_NAMED_NO_OBJ:
638 status = acpi_ds_load2_end_op (walk_state);
639 if (ACPI_FAILURE (status)) {
643 if (op->common.aml_opcode == AML_REGION_OP) {
644 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
645 "Executing op_region Address/Length Op=%p\n", op));
647 status = acpi_ds_eval_region_operands (walk_state, op);
648 if (ACPI_FAILURE (status)) {
652 status = acpi_ds_result_stack_pop (walk_state);
658 case AML_TYPE_UNDEFINED:
660 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
661 "Undefined opcode type Op=%p\n", op));
662 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
667 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
668 "Internal opcode=%X type Op=%p\n",
669 walk_state->opcode, op));
675 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
676 "Unimplemented opcode, class=%X type=%X Opcode=%X Op=%p\n",
677 op_class, op_type, op->common.aml_opcode, op));
679 status = AE_NOT_IMPLEMENTED;
685 * ACPI 2.0 support for 64-bit integers: Truncate numeric
686 * result value if we are executing from a 32-bit ACPI table
688 acpi_ex_truncate_for32bit_table (walk_state->result_obj);
691 * Check if we just completed the evaluation of a
692 * conditional predicate
695 if ((ACPI_SUCCESS (status)) &&
696 (walk_state->control_state) &&
697 (walk_state->control_state->common.state ==
698 ACPI_CONTROL_PREDICATE_EXECUTING) &&
699 (walk_state->control_state->control.predicate_op == op)) {
700 status = acpi_ds_get_predicate_value (walk_state, walk_state->result_obj);
701 walk_state->result_obj = NULL;
707 /* Invoke exception handler on error */
709 if (ACPI_FAILURE (status) &&
710 acpi_gbl_exception_handler &&
711 !(status & AE_CODE_CONTROL)) {
712 acpi_ex_exit_interpreter ();
713 status = acpi_gbl_exception_handler (status,
714 walk_state->method_node->name.integer, walk_state->opcode,
715 walk_state->aml_offset, NULL);
716 (void) acpi_ex_enter_interpreter ();
719 if (walk_state->result_obj) {
720 /* Break to debugger to display result */
722 ACPI_DEBUGGER_EXEC (acpi_db_display_result_object (walk_state->result_obj,
726 * Delete the result op if and only if:
727 * Parent will not use the result -- such as any
728 * non-nested type2 op in a method (parent will be method)
730 acpi_ds_delete_result_if_not_used (op, walk_state->result_obj, walk_state);
733 #ifdef _UNDER_DEVELOPMENT
735 if (walk_state->parser_state.aml == walk_state->parser_state.aml_end) {
736 acpi_db_method_end (walk_state);
740 /* Always clear the object stack */
742 walk_state->num_operands = 0;
744 #ifdef ACPI_DISASSEMBLER
746 /* On error, display method locals/args */
748 if (ACPI_FAILURE (status)) {
749 acpi_dm_dump_method_info (status, walk_state, op);
753 return_ACPI_STATUS (status);