2 /******************************************************************************
4 * Module Name: exresop - AML Interpreter operand/object resolution
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/amlcode.h>
48 #include <acpi/acparser.h>
49 #include <acpi/acinterp.h>
52 #define _COMPONENT ACPI_EXECUTER
53 ACPI_MODULE_NAME ("exresop")
55 /* Local prototypes */
58 acpi_ex_check_object_type (
59 acpi_object_type type_needed,
60 acpi_object_type this_type,
64 /*******************************************************************************
66 * FUNCTION: acpi_ex_check_object_type
68 * PARAMETERS: type_needed Object type needed
69 * this_type Actual object type
70 * Object Object pointer
74 * DESCRIPTION: Check required type against actual type
76 ******************************************************************************/
79 acpi_ex_check_object_type (
80 acpi_object_type type_needed,
81 acpi_object_type this_type,
84 ACPI_FUNCTION_NAME ("ex_check_object_type");
87 if (type_needed == ACPI_TYPE_ANY) {
88 /* All types OK, so we don't perform any typechecks */
93 if (type_needed == ACPI_TYPE_LOCAL_REFERENCE) {
95 * Allow the AML "Constant" opcodes (Zero, One, etc.) to be reference
96 * objects and thus allow them to be targets. (As per the ACPI
97 * specification, a store to a constant is a noop.)
99 if ((this_type == ACPI_TYPE_INTEGER) &&
100 (((union acpi_operand_object *) object)->common.flags & AOPOBJ_AML_CONSTANT)) {
105 if (type_needed != this_type) {
106 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
107 "Needed [%s], found [%s] %p\n",
108 acpi_ut_get_type_name (type_needed),
109 acpi_ut_get_type_name (this_type), object));
111 return (AE_AML_OPERAND_TYPE);
118 /*******************************************************************************
120 * FUNCTION: acpi_ex_resolve_operands
122 * PARAMETERS: Opcode - Opcode being interpreted
123 * stack_ptr - Pointer to the operand stack to be
125 * walk_state - Current state
129 * DESCRIPTION: Convert multiple input operands to the types required by the
132 * Each 5-bit group in arg_types represents one required
133 * operand and indicates the required Type. The corresponding operand
134 * will be converted to the required type if possible, otherwise we
135 * abort with an exception.
137 ******************************************************************************/
140 acpi_ex_resolve_operands (
142 union acpi_operand_object **stack_ptr,
143 struct acpi_walk_state *walk_state)
145 union acpi_operand_object *obj_desc;
146 acpi_status status = AE_OK;
150 const struct acpi_opcode_info *op_info;
152 acpi_object_type type_needed;
156 ACPI_FUNCTION_TRACE_U32 ("ex_resolve_operands", opcode);
159 op_info = acpi_ps_get_opcode_info (opcode);
160 if (op_info->class == AML_CLASS_UNKNOWN) {
161 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
164 arg_types = op_info->runtime_args;
165 if (arg_types == ARGI_INVALID_OPCODE) {
166 ACPI_REPORT_ERROR (("resolve_operands: %X is not a valid AML opcode\n",
169 return_ACPI_STATUS (AE_AML_INTERNAL);
172 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
173 "Opcode %X [%s] required_operand_types=%8.8X \n",
174 opcode, op_info->name, arg_types));
177 * Normal exit is with (arg_types == 0) at end of argument list.
178 * Function will return an exception from within the loop upon
179 * finding an entry which is not (or cannot be converted
180 * to) the required type; if stack underflows; or upon
181 * finding a NULL stack entry (which should not happen).
183 while (GET_CURRENT_ARG_TYPE (arg_types)) {
184 if (!stack_ptr || !*stack_ptr) {
185 ACPI_REPORT_ERROR (("resolve_operands: Null stack entry at %p\n",
188 return_ACPI_STATUS (AE_AML_INTERNAL);
191 /* Extract useful items */
193 obj_desc = *stack_ptr;
195 /* Decode the descriptor type */
197 switch (ACPI_GET_DESCRIPTOR_TYPE (obj_desc)) {
198 case ACPI_DESC_TYPE_NAMED:
202 object_type = ((struct acpi_namespace_node *) obj_desc)->type;
206 case ACPI_DESC_TYPE_OPERAND:
208 /* ACPI internal object */
210 object_type = ACPI_GET_OBJECT_TYPE (obj_desc);
212 /* Check for bad acpi_object_type */
214 if (!acpi_ut_valid_object_type (object_type)) {
215 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
216 "Bad operand object type [%X]\n",
219 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
222 if (object_type == (u8) ACPI_TYPE_LOCAL_REFERENCE) {
223 /* Decode the Reference */
225 op_info = acpi_ps_get_opcode_info (opcode);
226 if (op_info->class == AML_CLASS_UNKNOWN) {
227 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
230 switch (obj_desc->reference.opcode) {
232 target_op = AML_DEBUG_OP;
234 /*lint -fallthrough */
241 case AML_LOAD_OP: /* ddb_handle from LOAD_OP or LOAD_TABLE_OP */
242 case AML_INT_NAMEPATH_OP: /* Reference to a named object */
244 ACPI_DEBUG_ONLY_MEMBERS (ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
245 "Operand is a Reference, ref_opcode [%s]\n",
246 (acpi_ps_get_opcode_info (obj_desc->reference.opcode))->name)));
250 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
251 "Operand is a Reference, Unknown Reference Opcode %X [%s]\n",
252 obj_desc->reference.opcode,
253 (acpi_ps_get_opcode_info (obj_desc->reference.opcode))->name));
255 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
263 /* Invalid descriptor */
265 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
266 "Invalid descriptor %p [%s]\n",
267 obj_desc, acpi_ut_get_descriptor_name (obj_desc)));
269 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
272 /* Get one argument type, point to the next */
274 this_arg_type = GET_CURRENT_ARG_TYPE (arg_types);
275 INCREMENT_ARG_LIST (arg_types);
278 * Handle cases where the object does not need to be
279 * resolved to a value
281 switch (this_arg_type) {
282 case ARGI_REF_OR_STRING: /* Can be a String or Reference */
284 if ((ACPI_GET_DESCRIPTOR_TYPE (obj_desc) == ACPI_DESC_TYPE_OPERAND) &&
285 (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_STRING)) {
287 * String found - the string references a named object and
288 * must be resolved to a node
294 * Else not a string - fall through to the normal Reference
297 /*lint -fallthrough */
299 case ARGI_REFERENCE: /* References: */
300 case ARGI_INTEGER_REF:
301 case ARGI_OBJECT_REF:
302 case ARGI_DEVICE_REF:
303 case ARGI_TARGETREF: /* Allows implicit conversion rules before store */
304 case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */
305 case ARGI_SIMPLE_TARGET: /* Name, Local, or Arg - no implicit conversion */
308 * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE
309 * A Namespace Node is OK as-is
311 if (ACPI_GET_DESCRIPTOR_TYPE (obj_desc) == ACPI_DESC_TYPE_NAMED) {
315 status = acpi_ex_check_object_type (ACPI_TYPE_LOCAL_REFERENCE,
316 object_type, obj_desc);
317 if (ACPI_FAILURE (status)) {
318 return_ACPI_STATUS (status);
321 if (obj_desc->reference.opcode == AML_NAME_OP) {
322 /* Convert a named reference to the actual named object */
324 temp_node = obj_desc->reference.object;
325 acpi_ut_remove_reference (obj_desc);
326 (*stack_ptr) = temp_node;
331 case ARGI_DATAREFOBJ: /* Store operator only */
334 * We don't want to resolve index_op reference objects during
335 * a store because this would be an implicit de_ref_of operation.
336 * Instead, we just want to store the reference object.
337 * -- All others must be resolved below.
339 if ((opcode == AML_STORE_OP) &&
340 (ACPI_GET_OBJECT_TYPE (*stack_ptr) == ACPI_TYPE_LOCAL_REFERENCE) &&
341 ((*stack_ptr)->reference.opcode == AML_INDEX_OP)) {
347 /* All cases covered above */
352 * Resolve this object to a value
354 status = acpi_ex_resolve_to_value (stack_ptr, walk_state);
355 if (ACPI_FAILURE (status)) {
356 return_ACPI_STATUS (status);
359 /* Get the resolved object */
361 obj_desc = *stack_ptr;
364 * Check the resulting object (value) type
366 switch (this_arg_type) {
368 * For the simple cases, only one type of resolved object
373 /* Need an operand of type ACPI_TYPE_MUTEX */
375 type_needed = ACPI_TYPE_MUTEX;
380 /* Need an operand of type ACPI_TYPE_EVENT */
382 type_needed = ACPI_TYPE_EVENT;
385 case ARGI_PACKAGE: /* Package */
387 /* Need an operand of type ACPI_TYPE_PACKAGE */
389 type_needed = ACPI_TYPE_PACKAGE;
394 /* Any operand type will do */
396 type_needed = ACPI_TYPE_ANY;
401 /* Need an operand of type ACPI_TYPE_DDB_HANDLE */
403 type_needed = ACPI_TYPE_LOCAL_REFERENCE;
408 * The more complex cases allow multiple resolved object types
413 * Need an operand of type ACPI_TYPE_INTEGER,
414 * But we can implicitly convert from a STRING or BUFFER
415 * Aka - "Implicit Source Operand Conversion"
417 status = acpi_ex_convert_to_integer (obj_desc, stack_ptr, 16);
418 if (ACPI_FAILURE (status)) {
419 if (status == AE_TYPE) {
420 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
421 "Needed [Integer/String/Buffer], found [%s] %p\n",
422 acpi_ut_get_object_type_name (obj_desc), obj_desc));
424 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
427 return_ACPI_STATUS (status);
435 * Need an operand of type ACPI_TYPE_BUFFER,
436 * But we can implicitly convert from a STRING or INTEGER
437 * Aka - "Implicit Source Operand Conversion"
439 status = acpi_ex_convert_to_buffer (obj_desc, stack_ptr);
440 if (ACPI_FAILURE (status)) {
441 if (status == AE_TYPE) {
442 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
443 "Needed [Integer/String/Buffer], found [%s] %p\n",
444 acpi_ut_get_object_type_name (obj_desc), obj_desc));
446 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
449 return_ACPI_STATUS (status);
457 * Need an operand of type ACPI_TYPE_STRING,
458 * But we can implicitly convert from a BUFFER or INTEGER
459 * Aka - "Implicit Source Operand Conversion"
461 status = acpi_ex_convert_to_string (obj_desc, stack_ptr,
462 ACPI_IMPLICIT_CONVERT_HEX);
463 if (ACPI_FAILURE (status)) {
464 if (status == AE_TYPE) {
465 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
466 "Needed [Integer/String/Buffer], found [%s] %p\n",
467 acpi_ut_get_object_type_name (obj_desc), obj_desc));
469 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
472 return_ACPI_STATUS (status);
477 case ARGI_COMPUTEDATA:
479 /* Need an operand of type INTEGER, STRING or BUFFER */
481 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
482 case ACPI_TYPE_INTEGER:
483 case ACPI_TYPE_STRING:
484 case ACPI_TYPE_BUFFER:
490 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
491 "Needed [Integer/String/Buffer], found [%s] %p\n",
492 acpi_ut_get_object_type_name (obj_desc), obj_desc));
494 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
499 case ARGI_BUFFER_OR_STRING:
501 /* Need an operand of type STRING or BUFFER */
503 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
504 case ACPI_TYPE_STRING:
505 case ACPI_TYPE_BUFFER:
510 case ACPI_TYPE_INTEGER:
512 /* Highest priority conversion is to type Buffer */
514 status = acpi_ex_convert_to_buffer (obj_desc, stack_ptr);
515 if (ACPI_FAILURE (status)) {
516 return_ACPI_STATUS (status);
521 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
522 "Needed [Integer/String/Buffer], found [%s] %p\n",
523 acpi_ut_get_object_type_name (obj_desc), obj_desc));
525 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
530 case ARGI_DATAOBJECT:
532 * ARGI_DATAOBJECT is only used by the size_of operator.
533 * Need a buffer, string, package, or ref_of reference.
535 * The only reference allowed here is a direct reference to
538 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
539 case ACPI_TYPE_PACKAGE:
540 case ACPI_TYPE_STRING:
541 case ACPI_TYPE_BUFFER:
542 case ACPI_TYPE_LOCAL_REFERENCE:
548 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
549 "Needed [Buffer/String/Package/Reference], found [%s] %p\n",
550 acpi_ut_get_object_type_name (obj_desc), obj_desc));
552 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
557 case ARGI_COMPLEXOBJ:
559 /* Need a buffer or package or (ACPI 2.0) String */
561 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
562 case ACPI_TYPE_PACKAGE:
563 case ACPI_TYPE_STRING:
564 case ACPI_TYPE_BUFFER:
570 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
571 "Needed [Buffer/String/Package], found [%s] %p\n",
572 acpi_ut_get_object_type_name (obj_desc), obj_desc));
574 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
579 case ARGI_REGION_OR_FIELD:
581 /* Need an operand of type REGION or a FIELD in a region */
583 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
584 case ACPI_TYPE_REGION:
585 case ACPI_TYPE_LOCAL_REGION_FIELD:
586 case ACPI_TYPE_LOCAL_BANK_FIELD:
587 case ACPI_TYPE_LOCAL_INDEX_FIELD:
593 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
594 "Needed [Region/region_field], found [%s] %p\n",
595 acpi_ut_get_object_type_name (obj_desc), obj_desc));
597 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
602 case ARGI_DATAREFOBJ:
604 /* Used by the Store() operator only */
606 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
607 case ACPI_TYPE_INTEGER:
608 case ACPI_TYPE_PACKAGE:
609 case ACPI_TYPE_STRING:
610 case ACPI_TYPE_BUFFER:
611 case ACPI_TYPE_BUFFER_FIELD:
612 case ACPI_TYPE_LOCAL_REFERENCE:
613 case ACPI_TYPE_LOCAL_REGION_FIELD:
614 case ACPI_TYPE_LOCAL_BANK_FIELD:
615 case ACPI_TYPE_LOCAL_INDEX_FIELD:
616 case ACPI_TYPE_DDB_HANDLE:
623 if (acpi_gbl_enable_interpreter_slack) {
625 * Enable original behavior of Store(), allowing any and all
626 * objects as the source operand. The ACPI spec does not
627 * allow this, however.
632 if (target_op == AML_DEBUG_OP) {
633 /* Allow store of any object to the Debug object */
638 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
639 "Needed Integer/Buffer/String/Package/Ref/Ddb], found [%s] %p\n",
640 acpi_ut_get_object_type_name (obj_desc), obj_desc));
642 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
651 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
652 "Internal - Unknown ARGI (required operand) type %X\n",
655 return_ACPI_STATUS (AE_BAD_PARAMETER);
659 * Make sure that the original object was resolved to the
660 * required object type (Simple cases only).
662 status = acpi_ex_check_object_type (type_needed,
663 ACPI_GET_OBJECT_TYPE (*stack_ptr), *stack_ptr);
664 if (ACPI_FAILURE (status)) {
665 return_ACPI_STATUS (status);
670 * If more operands needed, decrement stack_ptr to point
671 * to next operand on stack
673 if (GET_CURRENT_ARG_TYPE (arg_types)) {
678 return_ACPI_STATUS (status);