2 /******************************************************************************
4 * Module Name: exresop - AML Interpreter operand/object resolution
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
117 #define __EXRESOP_C__
120 #include "accommon.h"
122 #include "acparser.h"
123 #include "acinterp.h"
124 #include "acnamesp.h"
127 #define _COMPONENT ACPI_EXECUTER
128 ACPI_MODULE_NAME ("exresop")
130 /* Local prototypes */
133 AcpiExCheckObjectType (
134 ACPI_OBJECT_TYPE TypeNeeded
,
135 ACPI_OBJECT_TYPE ThisType
,
139 /*******************************************************************************
141 * FUNCTION: AcpiExCheckObjectType
143 * PARAMETERS: TypeNeeded Object type needed
144 * ThisType Actual object type
145 * Object Object pointer
149 * DESCRIPTION: Check required type against actual type
151 ******************************************************************************/
154 AcpiExCheckObjectType (
155 ACPI_OBJECT_TYPE TypeNeeded
,
156 ACPI_OBJECT_TYPE ThisType
,
159 ACPI_FUNCTION_ENTRY ();
162 if (TypeNeeded
== ACPI_TYPE_ANY
)
164 /* All types OK, so we don't perform any typechecks */
169 if (TypeNeeded
== ACPI_TYPE_LOCAL_REFERENCE
)
172 * Allow the AML "Constant" opcodes (Zero, One, etc.) to be reference
173 * objects and thus allow them to be targets. (As per the ACPI
174 * specification, a store to a constant is a noop.)
176 if ((ThisType
== ACPI_TYPE_INTEGER
) &&
177 (((ACPI_OPERAND_OBJECT
*) Object
)->Common
.Flags
& AOPOBJ_AML_CONSTANT
))
183 if (TypeNeeded
!= ThisType
)
185 ACPI_ERROR ((AE_INFO
,
186 "Needed type [%s], found [%s] %p",
187 AcpiUtGetTypeName (TypeNeeded
),
188 AcpiUtGetTypeName (ThisType
), Object
));
190 return (AE_AML_OPERAND_TYPE
);
197 /*******************************************************************************
199 * FUNCTION: AcpiExResolveOperands
201 * PARAMETERS: Opcode - Opcode being interpreted
202 * StackPtr - Pointer to the operand stack to be
204 * WalkState - Current state
208 * DESCRIPTION: Convert multiple input operands to the types required by the
211 * Each 5-bit group in ArgTypes represents one required
212 * operand and indicates the required Type. The corresponding operand
213 * will be converted to the required type if possible, otherwise we
214 * abort with an exception.
216 ******************************************************************************/
219 AcpiExResolveOperands (
221 ACPI_OPERAND_OBJECT
**StackPtr
,
222 ACPI_WALK_STATE
*WalkState
)
224 ACPI_OPERAND_OBJECT
*ObjDesc
;
225 ACPI_STATUS Status
= AE_OK
;
228 const ACPI_OPCODE_INFO
*OpInfo
;
230 ACPI_OBJECT_TYPE TypeNeeded
;
234 ACPI_FUNCTION_TRACE_U32 (ExResolveOperands
, Opcode
);
237 OpInfo
= AcpiPsGetOpcodeInfo (Opcode
);
238 if (OpInfo
->Class
== AML_CLASS_UNKNOWN
)
240 return_ACPI_STATUS (AE_AML_BAD_OPCODE
);
243 ArgTypes
= OpInfo
->RuntimeArgs
;
244 if (ArgTypes
== ARGI_INVALID_OPCODE
)
246 ACPI_ERROR ((AE_INFO
, "Unknown AML opcode 0x%X",
249 return_ACPI_STATUS (AE_AML_INTERNAL
);
252 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
253 "Opcode %X [%s] RequiredOperandTypes=%8.8X\n",
254 Opcode
, OpInfo
->Name
, ArgTypes
));
257 * Normal exit is with (ArgTypes == 0) at end of argument list.
258 * Function will return an exception from within the loop upon
259 * finding an entry which is not (or cannot be converted
260 * to) the required type; if stack underflows; or upon
261 * finding a NULL stack entry (which should not happen).
263 while (GET_CURRENT_ARG_TYPE (ArgTypes
))
265 if (!StackPtr
|| !*StackPtr
)
267 ACPI_ERROR ((AE_INFO
, "Null stack entry at %p",
270 return_ACPI_STATUS (AE_AML_INTERNAL
);
273 /* Extract useful items */
277 /* Decode the descriptor type */
279 switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc
))
281 case ACPI_DESC_TYPE_NAMED
:
285 ObjectType
= ((ACPI_NAMESPACE_NODE
*) ObjDesc
)->Type
;
288 * Resolve an alias object. The construction of these objects
289 * guarantees that there is only one level of alias indirection;
290 * thus, the attached object is always the aliased namespace node
292 if (ObjectType
== ACPI_TYPE_LOCAL_ALIAS
)
294 ObjDesc
= AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE
*) ObjDesc
);
296 ObjectType
= ((ACPI_NAMESPACE_NODE
*) ObjDesc
)->Type
;
301 case ACPI_DESC_TYPE_OPERAND
:
303 /* ACPI internal object */
305 ObjectType
= ObjDesc
->Common
.Type
;
307 /* Check for bad ACPI_OBJECT_TYPE */
309 if (!AcpiUtValidObjectType (ObjectType
))
311 ACPI_ERROR ((AE_INFO
,
312 "Bad operand object type [0x%X]", ObjectType
));
314 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
317 if (ObjectType
== (UINT8
) ACPI_TYPE_LOCAL_REFERENCE
)
319 /* Validate the Reference */
321 switch (ObjDesc
->Reference
.Class
)
323 case ACPI_REFCLASS_DEBUG
:
325 TargetOp
= AML_DEBUG_OP
;
327 /*lint -fallthrough */
329 case ACPI_REFCLASS_ARG
:
330 case ACPI_REFCLASS_LOCAL
:
331 case ACPI_REFCLASS_INDEX
:
332 case ACPI_REFCLASS_REFOF
:
333 case ACPI_REFCLASS_TABLE
: /* DdbHandle from LOAD_OP or LOAD_TABLE_OP */
334 case ACPI_REFCLASS_NAME
: /* Reference to a named object */
336 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
337 "Operand is a Reference, Class [%s] %2.2X\n",
338 AcpiUtGetReferenceName (ObjDesc
),
339 ObjDesc
->Reference
.Class
));
344 ACPI_ERROR ((AE_INFO
,
345 "Unknown Reference Class 0x%2.2X in %p",
346 ObjDesc
->Reference
.Class
, ObjDesc
));
348 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
356 /* Invalid descriptor */
358 ACPI_ERROR ((AE_INFO
, "Invalid descriptor %p [%s]",
359 ObjDesc
, AcpiUtGetDescriptorName (ObjDesc
)));
361 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
364 /* Get one argument type, point to the next */
366 ThisArgType
= GET_CURRENT_ARG_TYPE (ArgTypes
);
367 INCREMENT_ARG_LIST (ArgTypes
);
370 * Handle cases where the object does not need to be
371 * resolved to a value
375 case ARGI_REF_OR_STRING
: /* Can be a String or Reference */
377 if ((ACPI_GET_DESCRIPTOR_TYPE (ObjDesc
) == ACPI_DESC_TYPE_OPERAND
) &&
378 (ObjDesc
->Common
.Type
== ACPI_TYPE_STRING
))
381 * String found - the string references a named object and
382 * must be resolved to a node
388 * Else not a string - fall through to the normal Reference
391 /*lint -fallthrough */
393 case ARGI_REFERENCE
: /* References: */
394 case ARGI_INTEGER_REF
:
395 case ARGI_OBJECT_REF
:
396 case ARGI_DEVICE_REF
:
397 case ARGI_TARGETREF
: /* Allows implicit conversion rules before store */
398 case ARGI_FIXED_TARGET
: /* No implicit conversion before store to target */
399 case ARGI_SIMPLE_TARGET
: /* Name, Local, or Arg - no implicit conversion */
402 * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE
403 * A Namespace Node is OK as-is
405 if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc
) == ACPI_DESC_TYPE_NAMED
)
410 Status
= AcpiExCheckObjectType (ACPI_TYPE_LOCAL_REFERENCE
,
411 ObjectType
, ObjDesc
);
412 if (ACPI_FAILURE (Status
))
414 return_ACPI_STATUS (Status
);
419 case ARGI_DATAREFOBJ
: /* Store operator only */
422 * We don't want to resolve IndexOp reference objects during
423 * a store because this would be an implicit DeRefOf operation.
424 * Instead, we just want to store the reference object.
425 * -- All others must be resolved below.
427 if ((Opcode
== AML_STORE_OP
) &&
428 ((*StackPtr
)->Common
.Type
== ACPI_TYPE_LOCAL_REFERENCE
) &&
429 ((*StackPtr
)->Reference
.Class
== ACPI_REFCLASS_INDEX
))
436 /* All cases covered above */
441 * Resolve this object to a value
443 Status
= AcpiExResolveToValue (StackPtr
, WalkState
);
444 if (ACPI_FAILURE (Status
))
446 return_ACPI_STATUS (Status
);
449 /* Get the resolved object */
454 * Check the resulting object (value) type
459 * For the simple cases, only one type of resolved object
464 /* Need an operand of type ACPI_TYPE_MUTEX */
466 TypeNeeded
= ACPI_TYPE_MUTEX
;
471 /* Need an operand of type ACPI_TYPE_EVENT */
473 TypeNeeded
= ACPI_TYPE_EVENT
;
476 case ARGI_PACKAGE
: /* Package */
478 /* Need an operand of type ACPI_TYPE_PACKAGE */
480 TypeNeeded
= ACPI_TYPE_PACKAGE
;
485 /* Any operand type will do */
487 TypeNeeded
= ACPI_TYPE_ANY
;
492 /* Need an operand of type ACPI_TYPE_DDB_HANDLE */
494 TypeNeeded
= ACPI_TYPE_LOCAL_REFERENCE
;
499 * The more complex cases allow multiple resolved object types
504 * Need an operand of type ACPI_TYPE_INTEGER,
505 * But we can implicitly convert from a STRING or BUFFER
506 * Aka - "Implicit Source Operand Conversion"
508 Status
= AcpiExConvertToInteger (ObjDesc
, StackPtr
, 16);
509 if (ACPI_FAILURE (Status
))
511 if (Status
== AE_TYPE
)
513 ACPI_ERROR ((AE_INFO
,
514 "Needed [Integer/String/Buffer], found [%s] %p",
515 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
517 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
520 return_ACPI_STATUS (Status
);
523 if (ObjDesc
!= *StackPtr
)
525 AcpiUtRemoveReference (ObjDesc
);
533 * Need an operand of type ACPI_TYPE_BUFFER,
534 * But we can implicitly convert from a STRING or INTEGER
535 * Aka - "Implicit Source Operand Conversion"
537 Status
= AcpiExConvertToBuffer (ObjDesc
, StackPtr
);
538 if (ACPI_FAILURE (Status
))
540 if (Status
== AE_TYPE
)
542 ACPI_ERROR ((AE_INFO
,
543 "Needed [Integer/String/Buffer], found [%s] %p",
544 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
546 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
549 return_ACPI_STATUS (Status
);
552 if (ObjDesc
!= *StackPtr
)
554 AcpiUtRemoveReference (ObjDesc
);
562 * Need an operand of type ACPI_TYPE_STRING,
563 * But we can implicitly convert from a BUFFER or INTEGER
564 * Aka - "Implicit Source Operand Conversion"
566 Status
= AcpiExConvertToString (ObjDesc
, StackPtr
,
567 ACPI_IMPLICIT_CONVERT_HEX
);
568 if (ACPI_FAILURE (Status
))
570 if (Status
== AE_TYPE
)
572 ACPI_ERROR ((AE_INFO
,
573 "Needed [Integer/String/Buffer], found [%s] %p",
574 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
576 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
579 return_ACPI_STATUS (Status
);
582 if (ObjDesc
!= *StackPtr
)
584 AcpiUtRemoveReference (ObjDesc
);
589 case ARGI_COMPUTEDATA
:
591 /* Need an operand of type INTEGER, STRING or BUFFER */
593 switch (ObjDesc
->Common
.Type
)
595 case ACPI_TYPE_INTEGER
:
596 case ACPI_TYPE_STRING
:
597 case ACPI_TYPE_BUFFER
:
603 ACPI_ERROR ((AE_INFO
,
604 "Needed [Integer/String/Buffer], found [%s] %p",
605 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
607 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
612 case ARGI_BUFFER_OR_STRING
:
614 /* Need an operand of type STRING or BUFFER */
616 switch (ObjDesc
->Common
.Type
)
618 case ACPI_TYPE_STRING
:
619 case ACPI_TYPE_BUFFER
:
624 case ACPI_TYPE_INTEGER
:
626 /* Highest priority conversion is to type Buffer */
628 Status
= AcpiExConvertToBuffer (ObjDesc
, StackPtr
);
629 if (ACPI_FAILURE (Status
))
631 return_ACPI_STATUS (Status
);
634 if (ObjDesc
!= *StackPtr
)
636 AcpiUtRemoveReference (ObjDesc
);
641 ACPI_ERROR ((AE_INFO
,
642 "Needed [Integer/String/Buffer], found [%s] %p",
643 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
645 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
650 case ARGI_DATAOBJECT
:
652 * ARGI_DATAOBJECT is only used by the SizeOf operator.
653 * Need a buffer, string, package, or RefOf reference.
655 * The only reference allowed here is a direct reference to
658 switch (ObjDesc
->Common
.Type
)
660 case ACPI_TYPE_PACKAGE
:
661 case ACPI_TYPE_STRING
:
662 case ACPI_TYPE_BUFFER
:
663 case ACPI_TYPE_LOCAL_REFERENCE
:
669 ACPI_ERROR ((AE_INFO
,
670 "Needed [Buffer/String/Package/Reference], found [%s] %p",
671 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
673 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
678 case ARGI_COMPLEXOBJ
:
680 /* Need a buffer or package or (ACPI 2.0) String */
682 switch (ObjDesc
->Common
.Type
)
684 case ACPI_TYPE_PACKAGE
:
685 case ACPI_TYPE_STRING
:
686 case ACPI_TYPE_BUFFER
:
692 ACPI_ERROR ((AE_INFO
,
693 "Needed [Buffer/String/Package], found [%s] %p",
694 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
696 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
701 case ARGI_REGION_OR_BUFFER
: /* Used by Load() only */
703 /* Need an operand of type REGION or a BUFFER (which could be a resolved region field) */
705 switch (ObjDesc
->Common
.Type
)
707 case ACPI_TYPE_BUFFER
:
708 case ACPI_TYPE_REGION
:
714 ACPI_ERROR ((AE_INFO
,
715 "Needed [Region/Buffer], found [%s] %p",
716 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
718 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
723 case ARGI_DATAREFOBJ
:
725 /* Used by the Store() operator only */
727 switch (ObjDesc
->Common
.Type
)
729 case ACPI_TYPE_INTEGER
:
730 case ACPI_TYPE_PACKAGE
:
731 case ACPI_TYPE_STRING
:
732 case ACPI_TYPE_BUFFER
:
733 case ACPI_TYPE_BUFFER_FIELD
:
734 case ACPI_TYPE_LOCAL_REFERENCE
:
735 case ACPI_TYPE_LOCAL_REGION_FIELD
:
736 case ACPI_TYPE_LOCAL_BANK_FIELD
:
737 case ACPI_TYPE_LOCAL_INDEX_FIELD
:
738 case ACPI_TYPE_DDB_HANDLE
:
745 if (AcpiGbl_EnableInterpreterSlack
)
748 * Enable original behavior of Store(), allowing any and all
749 * objects as the source operand. The ACPI spec does not
750 * allow this, however.
755 if (TargetOp
== AML_DEBUG_OP
)
757 /* Allow store of any object to the Debug object */
762 ACPI_ERROR ((AE_INFO
,
763 "Needed Integer/Buffer/String/Package/Ref/Ddb], found [%s] %p",
764 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
766 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
775 ACPI_ERROR ((AE_INFO
,
776 "Internal - Unknown ARGI (required operand) type 0x%X",
779 return_ACPI_STATUS (AE_BAD_PARAMETER
);
783 * Make sure that the original object was resolved to the
784 * required object type (Simple cases only).
786 Status
= AcpiExCheckObjectType (TypeNeeded
,
787 (*StackPtr
)->Common
.Type
, *StackPtr
);
788 if (ACPI_FAILURE (Status
))
790 return_ACPI_STATUS (Status
);
795 * If more operands needed, decrement StackPtr to point
796 * to next operand on stack
798 if (GET_CURRENT_ARG_TYPE (ArgTypes
))
804 ACPI_DUMP_OPERANDS (WalkState
->Operands
,
805 AcpiPsGetOpcodeName (Opcode
), WalkState
->NumOperands
);
807 return_ACPI_STATUS (Status
);