📄 dswexec.c
字号:
/****************************************************************************** * * Module Name: dswexec - Dispatcher method execution callbacks; * dispatch to interpreter. * *****************************************************************************//* * Copyright (C) 2000 - 2005, R. Byron Moore * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. Redistributions in binary form must reproduce at minimum a disclaimer * substantially similar to the "NO WARRANTY" disclaimer below * ("Disclaimer") and any redistribution must be conditioned upon * including a substantially similar Disclaimer requirement for further * binary redistribution. * 3. Neither the names of the above-listed copyright holders nor the names * of any contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * NO WARRANTY * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. */#include <acpi/acpi.h>#include <acpi/acparser.h>#include <acpi/amlcode.h>#include <acpi/acdispat.h>#include <acpi/acinterp.h>#include <acpi/acnamesp.h>#include <acpi/acdebug.h>#include <acpi/acdisasm.h>#define _COMPONENT ACPI_DISPATCHERACPI_MODULE_NAME("dswexec")/* * Dispatch table for opcode classes */static ACPI_EXECUTE_OP acpi_gbl_op_type_dispatch[] = { acpi_ex_opcode_0A_0T_1R, acpi_ex_opcode_1A_0T_0R, acpi_ex_opcode_1A_0T_1R, acpi_ex_opcode_1A_1T_0R, acpi_ex_opcode_1A_1T_1R, acpi_ex_opcode_2A_0T_0R, acpi_ex_opcode_2A_0T_1R, acpi_ex_opcode_2A_1T_1R, acpi_ex_opcode_2A_2T_1R, acpi_ex_opcode_3A_0T_0R, acpi_ex_opcode_3A_1T_1R, acpi_ex_opcode_6A_0T_1R};/***************************************************************************** * * FUNCTION: acpi_ds_get_predicate_value * * PARAMETERS: walk_state - Current state of the parse tree walk * result_obj - if non-zero, pop result from result stack * * RETURN: Status * * DESCRIPTION: Get the result of a predicate evaluation * ****************************************************************************/acpi_statusacpi_ds_get_predicate_value(struct acpi_walk_state *walk_state, union acpi_operand_object *result_obj){ acpi_status status = AE_OK; union acpi_operand_object *obj_desc; union acpi_operand_object *local_obj_desc = NULL; ACPI_FUNCTION_TRACE_PTR("ds_get_predicate_value", walk_state); walk_state->control_state->common.state = 0; if (result_obj) { status = acpi_ds_result_pop(&obj_desc, walk_state); if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Could not get result from predicate evaluation, %s\n", acpi_format_exception(status))); return_ACPI_STATUS(status); } } else { status = acpi_ds_create_operand(walk_state, walk_state->op, 0); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } status = acpi_ex_resolve_to_value(&walk_state->operands[0], walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } obj_desc = walk_state->operands[0]; } if (!obj_desc) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "No predicate obj_desc=%p State=%p\n", obj_desc, walk_state)); return_ACPI_STATUS(AE_AML_NO_OPERAND); } /* * Result of predicate evaluation must be an Integer * object. Implicitly convert the argument if necessary. */ status = acpi_ex_convert_to_integer(obj_desc, &local_obj_desc, 16); if (ACPI_FAILURE(status)) { goto cleanup; } if (ACPI_GET_OBJECT_TYPE(local_obj_desc) != ACPI_TYPE_INTEGER) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Bad predicate (not an integer) obj_desc=%p State=%p Type=%X\n", obj_desc, walk_state, ACPI_GET_OBJECT_TYPE(obj_desc))); status = AE_AML_OPERAND_TYPE; goto cleanup; } /* Truncate the predicate to 32-bits if necessary */ acpi_ex_truncate_for32bit_table(local_obj_desc); /* * Save the result of the predicate evaluation on * the control stack */ if (local_obj_desc->integer.value) { walk_state->control_state->common.value = TRUE; } else { /* * Predicate is FALSE, we will just toss the * rest of the package */ walk_state->control_state->common.value = FALSE; status = AE_CTRL_FALSE; } cleanup: ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Completed a predicate eval=%X Op=%p\n", walk_state->control_state->common.value, walk_state->op)); /* Break to debugger to display result */ ACPI_DEBUGGER_EXEC(acpi_db_display_result_object (local_obj_desc, walk_state)); /* * Delete the predicate result object (we know that * we don't need it anymore) */ if (local_obj_desc != obj_desc) { acpi_ut_remove_reference(local_obj_desc); } acpi_ut_remove_reference(obj_desc); walk_state->control_state->common.state = ACPI_CONTROL_NORMAL; return_ACPI_STATUS(status);}/***************************************************************************** * * FUNCTION: acpi_ds_exec_begin_op * * PARAMETERS: walk_state - Current state of the parse tree walk * out_op - Where to return op if a new one is created * * RETURN: Status * * DESCRIPTION: Descending callback used during the execution of control * methods. This is where most operators and operands are * dispatched to the interpreter. * ****************************************************************************/acpi_statusacpi_ds_exec_begin_op(struct acpi_walk_state *walk_state, union acpi_parse_object **out_op){ union acpi_parse_object *op; acpi_status status = AE_OK; u32 opcode_class; ACPI_FUNCTION_TRACE_PTR("ds_exec_begin_op", walk_state); op = walk_state->op; if (!op) { status = acpi_ds_load2_begin_op(walk_state, out_op); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } op = *out_op; walk_state->op = op; walk_state->opcode = op->common.aml_opcode; walk_state->op_info = acpi_ps_get_opcode_info(op->common.aml_opcode); if (acpi_ns_opens_scope(walk_state->op_info->object_type)) { ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n", acpi_ut_get_type_name(walk_state-> op_info-> object_type), op)); status = acpi_ds_scope_stack_pop(walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } } if (op == walk_state->origin) { if (out_op) { *out_op = op; } return_ACPI_STATUS(AE_OK); } /* * If the previous opcode was a conditional, this opcode * must be the beginning of the associated predicate. * Save this knowledge in the current scope descriptor */ if ((walk_state->control_state) && (walk_state->control_state->common.state == ACPI_CONTROL_CONDITIONAL_EXECUTING)) { ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Exec predicate Op=%p State=%p\n", op, walk_state)); walk_state->control_state->common.state = ACPI_CONTROL_PREDICATE_EXECUTING; /* Save start of predicate */ walk_state->control_state->control.predicate_op = op; } opcode_class = walk_state->op_info->class; /* We want to send namepaths to the load code */ if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) { opcode_class = AML_CLASS_NAMED_OBJECT; } /* * Handle the opcode based upon the opcode type */ switch (opcode_class) { case AML_CLASS_CONTROL: status = acpi_ds_result_stack_push(walk_state); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } status = acpi_ds_exec_begin_control_op(walk_state, op); break; case AML_CLASS_NAMED_OBJECT: if (walk_state->walk_type == ACPI_WALK_METHOD) { /* * Found a named object declaration during method execution; * we must enter this object into the namespace. The created * object is temporary and will be deleted upon completion of * the execution of this method. */ status = acpi_ds_load2_begin_op(walk_state, NULL); } if (op->common.aml_opcode == AML_REGION_OP) { status = acpi_ds_result_stack_push(walk_state); } break; case AML_CLASS_EXECUTE: case AML_CLASS_CREATE: /* * Most operators with arguments. * Start a new result/operand state */ status = acpi_ds_result_stack_push(walk_state); break; default: break; } /* Nothing to do here during method execution */ return_ACPI_STATUS(status);}/***************************************************************************** * * FUNCTION: acpi_ds_exec_end_op * * PARAMETERS: walk_state - Current state of the parse tree walk * * RETURN: Status * * DESCRIPTION: Ascending callback used during the execution of control * methods. The only thing we really need to do here is to * notice the beginning of IF, ELSE, and WHILE blocks. * ****************************************************************************/acpi_status acpi_ds_exec_end_op(struct acpi_walk_state *walk_state){ union acpi_parse_object *op; acpi_status status = AE_OK; u32 op_type; u32 op_class; union acpi_parse_object *next_op; union acpi_parse_object *first_arg; ACPI_FUNCTION_TRACE_PTR("ds_exec_end_op", walk_state); op = walk_state->op; op_type = walk_state->op_info->type; op_class = walk_state->op_info->class; if (op_class == AML_CLASS_UNKNOWN) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown opcode %X\n", op->common.aml_opcode)); return_ACPI_STATUS(AE_NOT_IMPLEMENTED); } first_arg = op->common.value.arg; /* Init the walk state */ walk_state->num_operands = 0; walk_state->return_desc = NULL; walk_state->result_obj = NULL; /* Call debugger for single step support (DEBUG build only) */ ACPI_DEBUGGER_EXEC(status = acpi_db_single_step(walk_state, op, op_class)); ACPI_DEBUGGER_EXEC(if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status);} ) ; /* Decode the Opcode Class */ switch (op_class) { case AML_CLASS_ARGUMENT: /* constants, literals, etc. - do nothing */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -