1 /******************************************************************************
3 * Module Name: exresop - AML Interpreter operand/object resolution
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2014, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
116 #define __EXRESOP_C__
119 #include "accommon.h"
121 #include "acparser.h"
122 #include "acinterp.h"
123 #include "acnamesp.h"
126 #define _COMPONENT ACPI_EXECUTER
127 ACPI_MODULE_NAME ("exresop")
129 /* Local prototypes */
132 AcpiExCheckObjectType (
133 ACPI_OBJECT_TYPE TypeNeeded
,
134 ACPI_OBJECT_TYPE ThisType
,
138 /*******************************************************************************
140 * FUNCTION: AcpiExCheckObjectType
142 * PARAMETERS: TypeNeeded Object type needed
143 * ThisType Actual object type
144 * Object Object pointer
148 * DESCRIPTION: Check required type against actual type
150 ******************************************************************************/
153 AcpiExCheckObjectType (
154 ACPI_OBJECT_TYPE TypeNeeded
,
155 ACPI_OBJECT_TYPE ThisType
,
158 ACPI_FUNCTION_ENTRY ();
161 if (TypeNeeded
== ACPI_TYPE_ANY
)
163 /* All types OK, so we don't perform any typechecks */
168 if (TypeNeeded
== ACPI_TYPE_LOCAL_REFERENCE
)
171 * Allow the AML "Constant" opcodes (Zero, One, etc.) to be reference
172 * objects and thus allow them to be targets. (As per the ACPI
173 * specification, a store to a constant is a noop.)
175 if ((ThisType
== ACPI_TYPE_INTEGER
) &&
176 (((ACPI_OPERAND_OBJECT
*) Object
)->Common
.Flags
& AOPOBJ_AML_CONSTANT
))
182 if (TypeNeeded
!= ThisType
)
184 ACPI_ERROR ((AE_INFO
,
185 "Needed type [%s], found [%s] %p",
186 AcpiUtGetTypeName (TypeNeeded
),
187 AcpiUtGetTypeName (ThisType
), Object
));
189 return (AE_AML_OPERAND_TYPE
);
196 /*******************************************************************************
198 * FUNCTION: AcpiExResolveOperands
200 * PARAMETERS: Opcode - Opcode being interpreted
201 * StackPtr - Pointer to the operand stack to be
203 * WalkState - Current state
207 * DESCRIPTION: Convert multiple input operands to the types required by the
210 * Each 5-bit group in ArgTypes represents one required
211 * operand and indicates the required Type. The corresponding operand
212 * will be converted to the required type if possible, otherwise we
213 * abort with an exception.
215 ******************************************************************************/
218 AcpiExResolveOperands (
220 ACPI_OPERAND_OBJECT
**StackPtr
,
221 ACPI_WALK_STATE
*WalkState
)
223 ACPI_OPERAND_OBJECT
*ObjDesc
;
224 ACPI_STATUS Status
= AE_OK
;
227 const ACPI_OPCODE_INFO
*OpInfo
;
229 ACPI_OBJECT_TYPE TypeNeeded
;
233 ACPI_FUNCTION_TRACE_U32 (ExResolveOperands
, Opcode
);
236 OpInfo
= AcpiPsGetOpcodeInfo (Opcode
);
237 if (OpInfo
->Class
== AML_CLASS_UNKNOWN
)
239 return_ACPI_STATUS (AE_AML_BAD_OPCODE
);
242 ArgTypes
= OpInfo
->RuntimeArgs
;
243 if (ArgTypes
== ARGI_INVALID_OPCODE
)
245 ACPI_ERROR ((AE_INFO
, "Unknown AML opcode 0x%X",
248 return_ACPI_STATUS (AE_AML_INTERNAL
);
251 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
252 "Opcode %X [%s] RequiredOperandTypes=%8.8X\n",
253 Opcode
, OpInfo
->Name
, ArgTypes
));
256 * Normal exit is with (ArgTypes == 0) at end of argument list.
257 * Function will return an exception from within the loop upon
258 * finding an entry which is not (or cannot be converted
259 * to) the required type; if stack underflows; or upon
260 * finding a NULL stack entry (which should not happen).
262 while (GET_CURRENT_ARG_TYPE (ArgTypes
))
264 if (!StackPtr
|| !*StackPtr
)
266 ACPI_ERROR ((AE_INFO
, "Null stack entry at %p",
269 return_ACPI_STATUS (AE_AML_INTERNAL
);
272 /* Extract useful items */
276 /* Decode the descriptor type */
278 switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc
))
280 case ACPI_DESC_TYPE_NAMED
:
284 ObjectType
= ((ACPI_NAMESPACE_NODE
*) ObjDesc
)->Type
;
287 * Resolve an alias object. The construction of these objects
288 * guarantees that there is only one level of alias indirection;
289 * thus, the attached object is always the aliased namespace node
291 if (ObjectType
== ACPI_TYPE_LOCAL_ALIAS
)
293 ObjDesc
= AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE
*) ObjDesc
);
295 ObjectType
= ((ACPI_NAMESPACE_NODE
*) ObjDesc
)->Type
;
299 case ACPI_DESC_TYPE_OPERAND
:
301 /* ACPI internal object */
303 ObjectType
= ObjDesc
->Common
.Type
;
305 /* Check for bad ACPI_OBJECT_TYPE */
307 if (!AcpiUtValidObjectType (ObjectType
))
309 ACPI_ERROR ((AE_INFO
,
310 "Bad operand object type [0x%X]", ObjectType
));
312 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
315 if (ObjectType
== (UINT8
) ACPI_TYPE_LOCAL_REFERENCE
)
317 /* Validate the Reference */
319 switch (ObjDesc
->Reference
.Class
)
321 case ACPI_REFCLASS_DEBUG
:
323 TargetOp
= AML_DEBUG_OP
;
325 /*lint -fallthrough */
327 case ACPI_REFCLASS_ARG
:
328 case ACPI_REFCLASS_LOCAL
:
329 case ACPI_REFCLASS_INDEX
:
330 case ACPI_REFCLASS_REFOF
:
331 case ACPI_REFCLASS_TABLE
: /* DdbHandle from LOAD_OP or LOAD_TABLE_OP */
332 case ACPI_REFCLASS_NAME
: /* Reference to a named object */
334 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
335 "Operand is a Reference, Class [%s] %2.2X\n",
336 AcpiUtGetReferenceName (ObjDesc
),
337 ObjDesc
->Reference
.Class
));
342 ACPI_ERROR ((AE_INFO
,
343 "Unknown Reference Class 0x%2.2X in %p",
344 ObjDesc
->Reference
.Class
, ObjDesc
));
346 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
353 /* Invalid descriptor */
355 ACPI_ERROR ((AE_INFO
, "Invalid descriptor %p [%s]",
356 ObjDesc
, AcpiUtGetDescriptorName (ObjDesc
)));
358 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
361 /* Get one argument type, point to the next */
363 ThisArgType
= GET_CURRENT_ARG_TYPE (ArgTypes
);
364 INCREMENT_ARG_LIST (ArgTypes
);
367 * Handle cases where the object does not need to be
368 * resolved to a value
372 case ARGI_REF_OR_STRING
: /* Can be a String or Reference */
374 if ((ACPI_GET_DESCRIPTOR_TYPE (ObjDesc
) == ACPI_DESC_TYPE_OPERAND
) &&
375 (ObjDesc
->Common
.Type
== ACPI_TYPE_STRING
))
378 * String found - the string references a named object and
379 * must be resolved to a node
385 * Else not a string - fall through to the normal Reference
388 /*lint -fallthrough */
390 case ARGI_REFERENCE
: /* References: */
391 case ARGI_INTEGER_REF
:
392 case ARGI_OBJECT_REF
:
393 case ARGI_DEVICE_REF
:
394 case ARGI_TARGETREF
: /* Allows implicit conversion rules before store */
395 case ARGI_FIXED_TARGET
: /* No implicit conversion before store to target */
396 case ARGI_SIMPLE_TARGET
: /* Name, Local, or Arg - no implicit conversion */
398 * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE
399 * A Namespace Node is OK as-is
401 if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc
) == ACPI_DESC_TYPE_NAMED
)
406 Status
= AcpiExCheckObjectType (ACPI_TYPE_LOCAL_REFERENCE
,
407 ObjectType
, ObjDesc
);
408 if (ACPI_FAILURE (Status
))
410 return_ACPI_STATUS (Status
);
414 case ARGI_DATAREFOBJ
: /* Store operator only */
416 * We don't want to resolve IndexOp reference objects during
417 * a store because this would be an implicit DeRefOf operation.
418 * Instead, we just want to store the reference object.
419 * -- All others must be resolved below.
421 if ((Opcode
== AML_STORE_OP
) &&
422 ((*StackPtr
)->Common
.Type
== ACPI_TYPE_LOCAL_REFERENCE
) &&
423 ((*StackPtr
)->Reference
.Class
== ACPI_REFCLASS_INDEX
))
431 /* All cases covered above */
437 * Resolve this object to a value
439 Status
= AcpiExResolveToValue (StackPtr
, WalkState
);
440 if (ACPI_FAILURE (Status
))
442 return_ACPI_STATUS (Status
);
445 /* Get the resolved object */
450 * Check the resulting object (value) type
455 * For the simple cases, only one type of resolved object
460 /* Need an operand of type ACPI_TYPE_MUTEX */
462 TypeNeeded
= ACPI_TYPE_MUTEX
;
467 /* Need an operand of type ACPI_TYPE_EVENT */
469 TypeNeeded
= ACPI_TYPE_EVENT
;
472 case ARGI_PACKAGE
: /* Package */
474 /* Need an operand of type ACPI_TYPE_PACKAGE */
476 TypeNeeded
= ACPI_TYPE_PACKAGE
;
481 /* Any operand type will do */
483 TypeNeeded
= ACPI_TYPE_ANY
;
488 /* Need an operand of type ACPI_TYPE_DDB_HANDLE */
490 TypeNeeded
= ACPI_TYPE_LOCAL_REFERENCE
;
495 * The more complex cases allow multiple resolved object types
500 * Need an operand of type ACPI_TYPE_INTEGER,
501 * But we can implicitly convert from a STRING or BUFFER
502 * Aka - "Implicit Source Operand Conversion"
504 Status
= AcpiExConvertToInteger (ObjDesc
, StackPtr
, 16);
505 if (ACPI_FAILURE (Status
))
507 if (Status
== AE_TYPE
)
509 ACPI_ERROR ((AE_INFO
,
510 "Needed [Integer/String/Buffer], found [%s] %p",
511 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
513 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
516 return_ACPI_STATUS (Status
);
519 if (ObjDesc
!= *StackPtr
)
521 AcpiUtRemoveReference (ObjDesc
);
527 * Need an operand of type ACPI_TYPE_BUFFER,
528 * But we can implicitly convert from a STRING or INTEGER
529 * Aka - "Implicit Source Operand Conversion"
531 Status
= AcpiExConvertToBuffer (ObjDesc
, StackPtr
);
532 if (ACPI_FAILURE (Status
))
534 if (Status
== AE_TYPE
)
536 ACPI_ERROR ((AE_INFO
,
537 "Needed [Integer/String/Buffer], found [%s] %p",
538 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
540 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
543 return_ACPI_STATUS (Status
);
546 if (ObjDesc
!= *StackPtr
)
548 AcpiUtRemoveReference (ObjDesc
);
554 * Need an operand of type ACPI_TYPE_STRING,
555 * But we can implicitly convert from a BUFFER or INTEGER
556 * Aka - "Implicit Source Operand Conversion"
558 Status
= AcpiExConvertToString (ObjDesc
, StackPtr
,
559 ACPI_IMPLICIT_CONVERT_HEX
);
560 if (ACPI_FAILURE (Status
))
562 if (Status
== AE_TYPE
)
564 ACPI_ERROR ((AE_INFO
,
565 "Needed [Integer/String/Buffer], found [%s] %p",
566 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
568 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
571 return_ACPI_STATUS (Status
);
574 if (ObjDesc
!= *StackPtr
)
576 AcpiUtRemoveReference (ObjDesc
);
580 case ARGI_COMPUTEDATA
:
582 /* Need an operand of type INTEGER, STRING or BUFFER */
584 switch (ObjDesc
->Common
.Type
)
586 case ACPI_TYPE_INTEGER
:
587 case ACPI_TYPE_STRING
:
588 case ACPI_TYPE_BUFFER
:
594 ACPI_ERROR ((AE_INFO
,
595 "Needed [Integer/String/Buffer], found [%s] %p",
596 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
598 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
602 case ARGI_BUFFER_OR_STRING
:
604 /* Need an operand of type STRING or BUFFER */
606 switch (ObjDesc
->Common
.Type
)
608 case ACPI_TYPE_STRING
:
609 case ACPI_TYPE_BUFFER
:
614 case ACPI_TYPE_INTEGER
:
616 /* Highest priority conversion is to type Buffer */
618 Status
= AcpiExConvertToBuffer (ObjDesc
, StackPtr
);
619 if (ACPI_FAILURE (Status
))
621 return_ACPI_STATUS (Status
);
624 if (ObjDesc
!= *StackPtr
)
626 AcpiUtRemoveReference (ObjDesc
);
631 ACPI_ERROR ((AE_INFO
,
632 "Needed [Integer/String/Buffer], found [%s] %p",
633 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
635 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
639 case ARGI_DATAOBJECT
:
641 * ARGI_DATAOBJECT is only used by the SizeOf operator.
642 * Need a buffer, string, package, or RefOf reference.
644 * The only reference allowed here is a direct reference to
647 switch (ObjDesc
->Common
.Type
)
649 case ACPI_TYPE_PACKAGE
:
650 case ACPI_TYPE_STRING
:
651 case ACPI_TYPE_BUFFER
:
652 case ACPI_TYPE_LOCAL_REFERENCE
:
659 ACPI_ERROR ((AE_INFO
,
660 "Needed [Buffer/String/Package/Reference], found [%s] %p",
661 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
663 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
667 case ARGI_COMPLEXOBJ
:
669 /* Need a buffer or package or (ACPI 2.0) String */
671 switch (ObjDesc
->Common
.Type
)
673 case ACPI_TYPE_PACKAGE
:
674 case ACPI_TYPE_STRING
:
675 case ACPI_TYPE_BUFFER
:
682 ACPI_ERROR ((AE_INFO
,
683 "Needed [Buffer/String/Package], found [%s] %p",
684 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
686 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
690 case ARGI_REGION_OR_BUFFER
: /* Used by Load() only */
692 /* Need an operand of type REGION or a BUFFER (which could be a resolved region field) */
694 switch (ObjDesc
->Common
.Type
)
696 case ACPI_TYPE_BUFFER
:
697 case ACPI_TYPE_REGION
:
704 ACPI_ERROR ((AE_INFO
,
705 "Needed [Region/Buffer], found [%s] %p",
706 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
708 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
712 case ARGI_DATAREFOBJ
:
714 /* Used by the Store() operator only */
716 switch (ObjDesc
->Common
.Type
)
718 case ACPI_TYPE_INTEGER
:
719 case ACPI_TYPE_PACKAGE
:
720 case ACPI_TYPE_STRING
:
721 case ACPI_TYPE_BUFFER
:
722 case ACPI_TYPE_BUFFER_FIELD
:
723 case ACPI_TYPE_LOCAL_REFERENCE
:
724 case ACPI_TYPE_LOCAL_REGION_FIELD
:
725 case ACPI_TYPE_LOCAL_BANK_FIELD
:
726 case ACPI_TYPE_LOCAL_INDEX_FIELD
:
727 case ACPI_TYPE_DDB_HANDLE
:
734 if (AcpiGbl_EnableInterpreterSlack
)
737 * Enable original behavior of Store(), allowing any and all
738 * objects as the source operand. The ACPI spec does not
739 * allow this, however.
744 if (TargetOp
== AML_DEBUG_OP
)
746 /* Allow store of any object to the Debug object */
751 ACPI_ERROR ((AE_INFO
,
752 "Needed Integer/Buffer/String/Package/Ref/Ddb], found [%s] %p",
753 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
755 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
763 ACPI_ERROR ((AE_INFO
,
764 "Internal - Unknown ARGI (required operand) type 0x%X",
767 return_ACPI_STATUS (AE_BAD_PARAMETER
);
771 * Make sure that the original object was resolved to the
772 * required object type (Simple cases only).
774 Status
= AcpiExCheckObjectType (TypeNeeded
,
775 (*StackPtr
)->Common
.Type
, *StackPtr
);
776 if (ACPI_FAILURE (Status
))
778 return_ACPI_STATUS (Status
);
783 * If more operands needed, decrement StackPtr to point
784 * to next operand on stack
786 if (GET_CURRENT_ARG_TYPE (ArgTypes
))
792 ACPI_DUMP_OPERANDS (WalkState
->Operands
,
793 AcpiPsGetOpcodeName (Opcode
), WalkState
->NumOperands
);
795 return_ACPI_STATUS (Status
);