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};
76 /*****************************************************************************
78 * FUNCTION: acpi_ds_get_predicate_value
80 * PARAMETERS: walk_state - Current state of the parse tree walk
84 * DESCRIPTION: Get the result of a predicate evaluation
86 ****************************************************************************/
89 acpi_ds_get_predicate_value (
90 struct acpi_walk_state *walk_state,
91 union acpi_operand_object *result_obj) {
92 acpi_status status = AE_OK;
93 union acpi_operand_object *obj_desc;
96 ACPI_FUNCTION_TRACE_PTR ("ds_get_predicate_value", walk_state);
99 walk_state->control_state->common.state = 0;
102 status = acpi_ds_result_pop (&obj_desc, walk_state);
103 if (ACPI_FAILURE (status)) {
104 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
105 "Could not get result from predicate evaluation, %s\n",
106 acpi_format_exception (status)));
108 return_ACPI_STATUS (status);
112 status = acpi_ds_create_operand (walk_state, walk_state->op, 0);
113 if (ACPI_FAILURE (status)) {
114 return_ACPI_STATUS (status);
117 status = acpi_ex_resolve_to_value (&walk_state->operands [0], walk_state);
118 if (ACPI_FAILURE (status)) {
119 return_ACPI_STATUS (status);
122 obj_desc = walk_state->operands [0];
126 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No predicate obj_desc=%p State=%p\n",
127 obj_desc, walk_state));
129 return_ACPI_STATUS (AE_AML_NO_OPERAND);
133 * Result of predicate evaluation currently must
136 if (ACPI_GET_OBJECT_TYPE (obj_desc) != ACPI_TYPE_INTEGER) {
137 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
138 "Bad predicate (not a number) obj_desc=%p State=%p Type=%X\n",
139 obj_desc, walk_state, ACPI_GET_OBJECT_TYPE (obj_desc)));
141 status = AE_AML_OPERAND_TYPE;
145 /* Truncate the predicate to 32-bits if necessary */
147 acpi_ex_truncate_for32bit_table (obj_desc);
150 * Save the result of the predicate evaluation on
153 if (obj_desc->integer.value) {
154 walk_state->control_state->common.value = TRUE;
158 * Predicate is FALSE, we will just toss the
159 * rest of the package
161 walk_state->control_state->common.value = FALSE;
162 status = AE_CTRL_FALSE;
168 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Completed a predicate eval=%X Op=%p\n",
169 walk_state->control_state->common.value, walk_state->op));
171 /* Break to debugger to display result */
173 ACPI_DEBUGGER_EXEC (acpi_db_display_result_object (obj_desc, walk_state));
176 * Delete the predicate result object (we know that
177 * we don't need it anymore)
179 acpi_ut_remove_reference (obj_desc);
181 walk_state->control_state->common.state = ACPI_CONTROL_NORMAL;
182 return_ACPI_STATUS (status);
186 /*****************************************************************************
188 * FUNCTION: acpi_ds_exec_begin_op
190 * PARAMETERS: walk_state - Current state of the parse tree walk
191 * out_op - Return op if a new one is created
195 * DESCRIPTION: Descending callback used during the execution of control
196 * methods. This is where most operators and operands are
197 * dispatched to the interpreter.
199 ****************************************************************************/
202 acpi_ds_exec_begin_op (
203 struct acpi_walk_state *walk_state,
204 union acpi_parse_object **out_op)
206 union acpi_parse_object *op;
207 acpi_status status = AE_OK;
211 ACPI_FUNCTION_TRACE_PTR ("ds_exec_begin_op", walk_state);
216 status = acpi_ds_load2_begin_op (walk_state, out_op);
217 if (ACPI_FAILURE (status)) {
218 return_ACPI_STATUS (status);
223 walk_state->opcode = op->common.aml_opcode;
224 walk_state->op_info = acpi_ps_get_opcode_info (op->common.aml_opcode);
226 if (acpi_ns_opens_scope (walk_state->op_info->object_type)) {
227 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n",
228 acpi_ut_get_type_name (walk_state->op_info->object_type), op));
230 status = acpi_ds_scope_stack_pop (walk_state);
231 if (ACPI_FAILURE (status)) {
232 return_ACPI_STATUS (status);
237 if (op == walk_state->origin) {
242 return_ACPI_STATUS (AE_OK);
246 * If the previous opcode was a conditional, this opcode
247 * must be the beginning of the associated predicate.
248 * Save this knowledge in the current scope descriptor
250 if ((walk_state->control_state) &&
251 (walk_state->control_state->common.state ==
252 ACPI_CONTROL_CONDITIONAL_EXECUTING)) {
253 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Exec predicate Op=%p State=%p\n",
256 walk_state->control_state->common.state = ACPI_CONTROL_PREDICATE_EXECUTING;
258 /* Save start of predicate */
260 walk_state->control_state->control.predicate_op = op;
264 opcode_class = walk_state->op_info->class;
266 /* We want to send namepaths to the load code */
268 if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
269 opcode_class = AML_CLASS_NAMED_OBJECT;
273 * Handle the opcode based upon the opcode type
275 switch (opcode_class) {
276 case AML_CLASS_CONTROL:
278 status = acpi_ds_result_stack_push (walk_state);
279 if (ACPI_FAILURE (status)) {
280 return_ACPI_STATUS (status);
283 status = acpi_ds_exec_begin_control_op (walk_state, op);
287 case AML_CLASS_NAMED_OBJECT:
289 if (walk_state->walk_type == ACPI_WALK_METHOD) {
291 * Found a named object declaration during method
292 * execution; we must enter this object into the
293 * namespace. The created object is temporary and
294 * will be deleted upon completion of the execution
297 status = acpi_ds_load2_begin_op (walk_state, NULL);
300 if (op->common.aml_opcode == AML_REGION_OP) {
301 status = acpi_ds_result_stack_push (walk_state);
306 case AML_CLASS_EXECUTE:
307 case AML_CLASS_CREATE:
309 /* most operators with arguments */
310 /* Start a new result/operand state */
312 status = acpi_ds_result_stack_push (walk_state);
320 /* Nothing to do here during method execution */
322 return_ACPI_STATUS (status);
326 /*****************************************************************************
328 * FUNCTION: acpi_ds_exec_end_op
330 * PARAMETERS: walk_state - Current state of the parse tree walk
331 * Op - Op that has been just been completed in the
332 * walk; Arguments have now been evaluated.
336 * DESCRIPTION: Ascending callback used during the execution of control
337 * methods. The only thing we really need to do here is to
338 * notice the beginning of IF, ELSE, and WHILE blocks.
340 ****************************************************************************/
343 acpi_ds_exec_end_op (
344 struct acpi_walk_state *walk_state)
346 union acpi_parse_object *op;
347 acpi_status status = AE_OK;
350 union acpi_parse_object *next_op;
351 union acpi_parse_object *first_arg;
354 ACPI_FUNCTION_TRACE_PTR ("ds_exec_end_op", walk_state);
358 op_type = walk_state->op_info->type;
359 op_class = walk_state->op_info->class;
361 if (op_class == AML_CLASS_UNKNOWN) {
362 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown opcode %X\n", op->common.aml_opcode));
363 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
366 first_arg = op->common.value.arg;
368 /* Init the walk state */
370 walk_state->num_operands = 0;
371 walk_state->return_desc = NULL;
372 walk_state->result_obj = NULL;
374 /* Call debugger for single step support (DEBUG build only) */
376 ACPI_DEBUGGER_EXEC (status = acpi_db_single_step (walk_state, op, op_class));
377 ACPI_DEBUGGER_EXEC (if (ACPI_FAILURE (status)) {return_ACPI_STATUS (status);});
379 /* Decode the Opcode Class */
382 case AML_CLASS_ARGUMENT: /* constants, literals, etc. -- do nothing */
386 case AML_CLASS_EXECUTE: /* most operators with arguments */
388 /* Build resolved operand stack */
390 status = acpi_ds_create_operands (walk_state, first_arg);
391 if (ACPI_FAILURE (status)) {
395 /* Done with this result state (Now that operand stack is built) */
397 status = acpi_ds_result_stack_pop (walk_state);
398 if (ACPI_FAILURE (status)) {
403 * All opcodes require operand resolution, with the only exceptions
404 * being the object_type and size_of operators.
406 if (!(walk_state->op_info->flags & AML_NO_OPERAND_RESOLVE)) {
407 /* Resolve all operands */
409 status = acpi_ex_resolve_operands (walk_state->opcode,
410 &(walk_state->operands [walk_state->num_operands -1]),
412 if (ACPI_SUCCESS (status)) {
413 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
414 acpi_ps_get_opcode_name (walk_state->opcode),
415 walk_state->num_operands, "after ex_resolve_operands");
419 if (ACPI_SUCCESS (status)) {
421 * Dispatch the request to the appropriate interpreter handler
422 * routine. There is one routine per opcode "type" based upon the
423 * number of opcode arguments and return type.
425 status = acpi_gbl_op_type_dispatch[op_type] (walk_state);
429 * Treat constructs of the form "Store(local_x,local_x)" as noops when the
430 * Local is uninitialized.
432 if ((status == AE_AML_UNINITIALIZED_LOCAL) &&
433 (walk_state->opcode == AML_STORE_OP) &&
434 (walk_state->operands[0]->common.type == ACPI_TYPE_LOCAL_REFERENCE) &&
435 (walk_state->operands[1]->common.type == ACPI_TYPE_LOCAL_REFERENCE) &&
436 (walk_state->operands[0]->reference.opcode ==
437 walk_state->operands[1]->reference.opcode) &&
438 (walk_state->operands[0]->reference.offset ==
439 walk_state->operands[1]->reference.offset)) {
443 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
444 "[%s]: Could not resolve operands, %s\n",
445 acpi_ps_get_opcode_name (walk_state->opcode),
446 acpi_format_exception (status)));
450 /* Always delete the argument objects and clear the operand stack */
452 acpi_ds_clear_operands (walk_state);
455 * If a result object was returned from above, push it on the
456 * current result stack
458 if (ACPI_SUCCESS (status) &&
459 walk_state->result_obj) {
460 status = acpi_ds_result_push (walk_state->result_obj, walk_state);
469 case AML_TYPE_CONTROL: /* Type 1 opcode, IF/ELSE/WHILE/NOOP */
471 /* 1 Operand, 0 external_result, 0 internal_result */
473 status = acpi_ds_exec_end_control_op (walk_state, op);
474 if (ACPI_FAILURE (status)) {
478 status = acpi_ds_result_stack_pop (walk_state);
482 case AML_TYPE_METHOD_CALL:
484 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Method invocation, Op=%p\n", op));
487 * (AML_METHODCALL) Op->Value->Arg->Node contains
488 * the method Node pointer
490 /* next_op points to the op that holds the method name */
494 /* next_op points to first argument op */
496 next_op = next_op->common.next;
499 * Get the method's arguments and put them on the operand stack
501 status = acpi_ds_create_operands (walk_state, next_op);
502 if (ACPI_FAILURE (status)) {
507 * Since the operands will be passed to another control method,
508 * we must resolve all local references here (Local variables,
509 * arguments to *this* method, etc.)
511 status = acpi_ds_resolve_operands (walk_state);
512 if (ACPI_FAILURE (status)) {
513 /* On error, clear all resolved operands */
515 acpi_ds_clear_operands (walk_state);
520 * Tell the walk loop to preempt this running method and
521 * execute the new method
523 status = AE_CTRL_TRANSFER;
526 * Return now; we don't want to disturb anything,
527 * especially the operand count!
529 return_ACPI_STATUS (status);
532 case AML_TYPE_CREATE_FIELD:
534 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
535 "Executing create_field Buffer/Index Op=%p\n", op));
537 status = acpi_ds_load2_end_op (walk_state);
538 if (ACPI_FAILURE (status)) {
542 status = acpi_ds_eval_buffer_field_operands (walk_state, op);
546 case AML_TYPE_CREATE_OBJECT:
548 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
549 "Executing create_object (Buffer/Package) Op=%p\n", op));
551 switch (op->common.parent->common.aml_opcode) {
555 * Put the Node on the object stack (Contains the ACPI Name of
558 walk_state->operands[0] = (void *) op->common.parent->common.node;
559 walk_state->num_operands = 1;
561 status = acpi_ds_create_node (walk_state, op->common.parent->common.node, op->common.parent);
562 if (ACPI_FAILURE (status)) {
567 /*lint -fallthrough */
569 case AML_INT_EVAL_SUBTREE_OP:
571 status = acpi_ds_eval_data_object_operands (walk_state, op,
572 acpi_ns_get_attached_object (op->common.parent->common.node));
577 status = acpi_ds_eval_data_object_operands (walk_state, op, NULL);
581 /* Done with this result state (Now that operand stack is built) */
583 status = acpi_ds_result_stack_pop (walk_state);
584 if (ACPI_FAILURE (status)) {
589 * If a result object was returned from above, push it on the
590 * current result stack
592 if (ACPI_SUCCESS (status) &&
593 walk_state->result_obj) {
594 status = acpi_ds_result_push (walk_state->result_obj, walk_state);
599 case AML_TYPE_NAMED_FIELD:
600 case AML_TYPE_NAMED_COMPLEX:
601 case AML_TYPE_NAMED_SIMPLE:
602 case AML_TYPE_NAMED_NO_OBJ:
604 status = acpi_ds_load2_end_op (walk_state);
605 if (ACPI_FAILURE (status)) {
609 if (op->common.aml_opcode == AML_REGION_OP) {
610 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
611 "Executing op_region Address/Length Op=%p\n", op));
613 status = acpi_ds_eval_region_operands (walk_state, op);
614 if (ACPI_FAILURE (status)) {
618 status = acpi_ds_result_stack_pop (walk_state);
624 case AML_TYPE_UNDEFINED:
626 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Undefined opcode type Op=%p\n", op));
627 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
632 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
633 "Internal opcode=%X type Op=%p\n",
634 walk_state->opcode, op));
640 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
641 "Unimplemented opcode, class=%X type=%X Opcode=%X Op=%p\n",
642 op_class, op_type, op->common.aml_opcode, op));
644 status = AE_NOT_IMPLEMENTED;
650 * ACPI 2.0 support for 64-bit integers: Truncate numeric
651 * result value if we are executing from a 32-bit ACPI table
653 acpi_ex_truncate_for32bit_table (walk_state->result_obj);
656 * Check if we just completed the evaluation of a
657 * conditional predicate
660 if ((ACPI_SUCCESS (status)) &&
661 (walk_state->control_state) &&
662 (walk_state->control_state->common.state ==
663 ACPI_CONTROL_PREDICATE_EXECUTING) &&
664 (walk_state->control_state->control.predicate_op == op)) {
665 status = acpi_ds_get_predicate_value (walk_state, walk_state->result_obj);
666 walk_state->result_obj = NULL;
672 /* Invoke exception handler on error */
674 if (ACPI_FAILURE (status) &&
675 acpi_gbl_exception_handler &&
676 !(status & AE_CODE_CONTROL)) {
677 acpi_ex_exit_interpreter ();
678 status = acpi_gbl_exception_handler (status,
679 walk_state->method_node->name.integer, walk_state->opcode,
680 walk_state->aml_offset, NULL);
681 acpi_ex_enter_interpreter ();
684 if (walk_state->result_obj) {
685 /* Break to debugger to display result */
687 ACPI_DEBUGGER_EXEC (acpi_db_display_result_object (walk_state->result_obj, walk_state));
690 * Delete the result op if and only if:
691 * Parent will not use the result -- such as any
692 * non-nested type2 op in a method (parent will be method)
694 acpi_ds_delete_result_if_not_used (op, walk_state->result_obj, walk_state);
697 #ifdef _UNDER_DEVELOPMENT
699 if (walk_state->parser_state.aml == walk_state->parser_state.aml_end) {
700 acpi_db_method_end (walk_state);
704 /* Always clear the object stack */
706 walk_state->num_operands = 0;
708 #ifdef ACPI_DISASSEMBLER
710 /* On error, display method locals/args */
712 if (ACPI_FAILURE (status)) {
713 acpi_dm_dump_method_info (status, walk_state, op);
717 return_ACPI_STATUS (status);