amstore.c
来自「一个类似windows」· C语言 代码 · 共 564 行 · 第 1/2 页
C
564 行
/******************************************************************************
*
* Module Name: amstore - AML Interpreter object store support
* $Revision: 1.1 $
*
*****************************************************************************/
/*
* Copyright (C) 2000, 2001 R. Byron Moore
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <acpi.h>
#define _COMPONENT ACPI_EXECUTER
MODULE_NAME ("amstore")
/*******************************************************************************
*
* FUNCTION: Acpi_aml_exec_store
*
* PARAMETERS: *Val_desc - Value to be stored
* *Dest_desc - Where to store it 0 Must be (ACPI_HANDLE)
* or an ACPI_OPERAND_OBJECT of type
* Reference; if the latter the descriptor
* will be either reused or deleted.
*
* RETURN: Status
*
* DESCRIPTION: Store the value described by Val_desc into the location
* described by Dest_desc. Called by various interpreter
* functions to store the result of an operation into
* the destination operand.
*
******************************************************************************/
ACPI_STATUS
acpi_aml_exec_store (
ACPI_OPERAND_OBJECT *val_desc,
ACPI_OPERAND_OBJECT *dest_desc,
ACPI_WALK_STATE *walk_state)
{
ACPI_STATUS status = AE_OK;
ACPI_OPERAND_OBJECT *ref_desc = dest_desc;
/* Validate parameters */
if (!val_desc || !dest_desc) {
return (AE_AML_NO_OPERAND);
}
/* Dest_desc can be either a namespace node or an ACPI object */
if (VALID_DESCRIPTOR_TYPE (dest_desc, ACPI_DESC_TYPE_NAMED)) {
/*
* Dest is a namespace node,
* Storing an object into a Name "container"
*/
status = acpi_aml_store_object_to_node (val_desc,
(ACPI_NAMESPACE_NODE *) dest_desc, walk_state);
/* All done, that's it */
return (status);
}
/* Destination object must be an object of type Reference */
if (dest_desc->common.type != INTERNAL_TYPE_REFERENCE) {
/* Destination is not an Reference */
return (AE_AML_OPERAND_TYPE);
}
/*
* Examine the Reference opcode. These cases are handled:
*
* 1) Store to Name (Change the object associated with a name)
* 2) Store to an indexed area of a Buffer or Package
* 3) Store to a Method Local or Arg
* 4) Store to the debug object
* 5) Store to a constant -- a noop
*/
switch (ref_desc->reference.opcode) {
case AML_NAME_OP:
/* Storing an object into a Name "container" */
status = acpi_aml_store_object_to_node (val_desc, ref_desc->reference.object,
walk_state);
break;
case AML_INDEX_OP:
/* Storing to an Index (pointer into a packager or buffer) */
status = acpi_aml_store_object_to_index (val_desc, ref_desc, walk_state);
break;
case AML_LOCAL_OP:
case AML_ARG_OP:
/* Store to a method local/arg */
status = acpi_ds_store_object_to_local (ref_desc->reference.opcode,
ref_desc->reference.offset, val_desc, walk_state);
break;
case AML_DEBUG_OP:
/*
* Storing to the Debug object causes the value stored to be
* displayed and otherwise has no effect -- see ACPI Specification
*
* TBD: print known object types "prettier".
*/
break;
case AML_ZERO_OP:
case AML_ONE_OP:
case AML_ONES_OP:
/*
* Storing to a constant is a no-op -- see ACPI Specification
* Delete the reference descriptor, however
*/
break;
default:
/* TBD: [Restructure] use object dump routine !! */
status = AE_AML_INTERNAL;
break;
} /* switch (Ref_desc->Reference.Opcode) */
/* Always delete the reference descriptor object */
if (ref_desc) {
acpi_cm_remove_reference (ref_desc);
}
return (status);
}
/*******************************************************************************
*
* FUNCTION: Acpi_aml_store_object_to_index
*
* PARAMETERS: *Val_desc - Value to be stored
* *Node - Named object to receive the value
*
* RETURN: Status
*
* DESCRIPTION: Store the object to the named object.
*
******************************************************************************/
ACPI_STATUS
acpi_aml_store_object_to_index (
ACPI_OPERAND_OBJECT *val_desc,
ACPI_OPERAND_OBJECT *dest_desc,
ACPI_WALK_STATE *walk_state)
{
ACPI_STATUS status = AE_OK;
ACPI_OPERAND_OBJECT *obj_desc;
u32 length;
u32 i;
u8 value = 0;
/*
* Destination must be a reference pointer, and
* must point to either a buffer or a package
*/
switch (dest_desc->reference.target_type) {
case ACPI_TYPE_PACKAGE:
/*
* Storing to a package element is not simple. The source must be
* evaluated and converted to the type of the destination and then the
* source is copied into the destination - we can't just point to the
* source object.
*/
if (dest_desc->reference.target_type == ACPI_TYPE_PACKAGE) {
/*
* The object at *(Dest_desc->Reference.Where) is the
* element within the package that is to be modified.
*/
obj_desc = *(dest_desc->reference.where);
if (obj_desc) {
/*
* If the Destination element is a package, we will delete
* that object and construct a new one.
*
* TBD: [Investigate] Should both the src and dest be required
* to be packages?
* && (Val_desc->Common.Type == ACPI_TYPE_PACKAGE)
*/
if (obj_desc->common.type == ACPI_TYPE_PACKAGE) {
/*
* Take away the reference for being part of a package and
* delete
*/
acpi_cm_remove_reference (obj_desc);
acpi_cm_remove_reference (obj_desc);
obj_desc = NULL;
}
}
if (!obj_desc) {
/*
* If the Obj_desc is NULL, it means that an uninitialized package
* element has been used as a destination (this is OK), therefore,
* we must create the destination element to match the type of the
* source element NOTE: Val_desc can be of any type.
*/
obj_desc = acpi_cm_create_internal_object (val_desc->common.type);
if (!obj_desc) {
return (AE_NO_MEMORY);
}
/*
* If the source is a package, copy the source to the new dest
*/
if (ACPI_TYPE_PACKAGE == obj_desc->common.type) {
status = acpi_cm_copy_ipackage_to_ipackage (val_desc, obj_desc, walk_state);
if (ACPI_FAILURE (status)) {
acpi_cm_remove_reference (obj_desc);
return (status);
}
}
/*
* Install the new descriptor into the package and add a
* reference to the newly created descriptor for now being
* part of the parent package
*/
*(dest_desc->reference.where) = obj_desc;
acpi_cm_add_reference (obj_desc);
}
if (ACPI_TYPE_PACKAGE != obj_desc->common.type) {
/*
* The destination element is not a package, so we need to
* convert the contents of the source (Val_desc) and copy into
* the destination (Obj_desc)
*/
status = acpi_aml_store_object_to_object (val_desc, obj_desc,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?