1 /******************************************************************************
3 * Module Name: exresop - AML Interpreter operand/object resolution
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2015, 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 *****************************************************************************/
117 #include "accommon.h"
119 #include "acparser.h"
120 #include "acinterp.h"
121 #include "acnamesp.h"
124 #define _COMPONENT ACPI_EXECUTER
125 ACPI_MODULE_NAME ("exresop")
127 /* Local prototypes */
130 AcpiExCheckObjectType (
131 ACPI_OBJECT_TYPE TypeNeeded
,
132 ACPI_OBJECT_TYPE ThisType
,
136 /*******************************************************************************
138 * FUNCTION: AcpiExCheckObjectType
140 * PARAMETERS: TypeNeeded Object type needed
141 * ThisType Actual object type
142 * Object Object pointer
146 * DESCRIPTION: Check required type against actual type
148 ******************************************************************************/
151 AcpiExCheckObjectType (
152 ACPI_OBJECT_TYPE TypeNeeded
,
153 ACPI_OBJECT_TYPE ThisType
,
156 ACPI_FUNCTION_ENTRY ();
159 if (TypeNeeded
== ACPI_TYPE_ANY
)
161 /* All types OK, so we don't perform any typechecks */
166 if (TypeNeeded
== ACPI_TYPE_LOCAL_REFERENCE
)
169 * Allow the AML "Constant" opcodes (Zero, One, etc.) to be reference
170 * objects and thus allow them to be targets. (As per the ACPI
171 * specification, a store to a constant is a noop.)
173 if ((ThisType
== ACPI_TYPE_INTEGER
) &&
174 (((ACPI_OPERAND_OBJECT
*) Object
)->Common
.Flags
&
175 AOPOBJ_AML_CONSTANT
))
181 if (TypeNeeded
!= ThisType
)
183 ACPI_ERROR ((AE_INFO
,
184 "Needed type [%s], found [%s] %p",
185 AcpiUtGetTypeName (TypeNeeded
),
186 AcpiUtGetTypeName (ThisType
), Object
));
188 return (AE_AML_OPERAND_TYPE
);
195 /*******************************************************************************
197 * FUNCTION: AcpiExResolveOperands
199 * PARAMETERS: Opcode - Opcode being interpreted
200 * StackPtr - Pointer to the operand stack to be
202 * WalkState - Current state
206 * DESCRIPTION: Convert multiple input operands to the types required by the
209 * Each 5-bit group in ArgTypes represents one required
210 * operand and indicates the required Type. The corresponding operand
211 * will be converted to the required type if possible, otherwise we
212 * abort with an exception.
214 ******************************************************************************/
217 AcpiExResolveOperands (
219 ACPI_OPERAND_OBJECT
**StackPtr
,
220 ACPI_WALK_STATE
*WalkState
)
222 ACPI_OPERAND_OBJECT
*ObjDesc
;
223 ACPI_STATUS Status
= AE_OK
;
226 const ACPI_OPCODE_INFO
*OpInfo
;
228 ACPI_OBJECT_TYPE TypeNeeded
;
232 ACPI_FUNCTION_TRACE_U32 (ExResolveOperands
, Opcode
);
235 OpInfo
= AcpiPsGetOpcodeInfo (Opcode
);
236 if (OpInfo
->Class
== AML_CLASS_UNKNOWN
)
238 return_ACPI_STATUS (AE_AML_BAD_OPCODE
);
241 ArgTypes
= OpInfo
->RuntimeArgs
;
242 if (ArgTypes
== ARGI_INVALID_OPCODE
)
244 ACPI_ERROR ((AE_INFO
, "Unknown AML opcode 0x%X",
247 return_ACPI_STATUS (AE_AML_INTERNAL
);
250 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
251 "Opcode %X [%s] RequiredOperandTypes=%8.8X\n",
252 Opcode
, OpInfo
->Name
, ArgTypes
));
255 * Normal exit is with (ArgTypes == 0) at end of argument list.
256 * Function will return an exception from within the loop upon
257 * finding an entry which is not (or cannot be converted
258 * to) the required type; if stack underflows; or upon
259 * finding a NULL stack entry (which should not happen).
261 while (GET_CURRENT_ARG_TYPE (ArgTypes
))
263 if (!StackPtr
|| !*StackPtr
)
265 ACPI_ERROR ((AE_INFO
, "Null stack entry at %p",
268 return_ACPI_STATUS (AE_AML_INTERNAL
);
271 /* Extract useful items */
275 /* Decode the descriptor type */
277 switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc
))
279 case ACPI_DESC_TYPE_NAMED
:
283 ObjectType
= ((ACPI_NAMESPACE_NODE
*) ObjDesc
)->Type
;
286 * Resolve an alias object. The construction of these objects
287 * guarantees that there is only one level of alias indirection;
288 * thus, the attached object is always the aliased namespace node
290 if (ObjectType
== ACPI_TYPE_LOCAL_ALIAS
)
292 ObjDesc
= AcpiNsGetAttachedObject (
293 (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
) ==
375 ACPI_DESC_TYPE_OPERAND
) &&
376 (ObjDesc
->Common
.Type
== ACPI_TYPE_STRING
))
379 * String found - the string references a named object and
380 * must be resolved to a node
386 * Else not a string - fall through to the normal Reference
389 /*lint -fallthrough */
391 case ARGI_REFERENCE
: /* References: */
392 case ARGI_INTEGER_REF
:
393 case ARGI_OBJECT_REF
:
394 case ARGI_DEVICE_REF
:
395 case ARGI_TARGETREF
: /* Allows implicit conversion rules before store */
396 case ARGI_FIXED_TARGET
: /* No implicit conversion before store to target */
397 case ARGI_SIMPLE_TARGET
: /* Name, Local, or Arg - no implicit conversion */
398 case ARGI_STORE_TARGET
:
401 * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE
402 * A Namespace Node is OK as-is
404 if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc
) == ACPI_DESC_TYPE_NAMED
)
409 Status
= AcpiExCheckObjectType (
410 ACPI_TYPE_LOCAL_REFERENCE
, ObjectType
, ObjDesc
);
411 if (ACPI_FAILURE (Status
))
413 return_ACPI_STATUS (Status
);
417 case ARGI_DATAREFOBJ
: /* Store operator only */
419 * We don't want to resolve IndexOp reference objects during
420 * a store because this would be an implicit DeRefOf operation.
421 * Instead, we just want to store the reference object.
422 * -- All others must be resolved below.
424 if ((Opcode
== AML_STORE_OP
) &&
425 ((*StackPtr
)->Common
.Type
== ACPI_TYPE_LOCAL_REFERENCE
) &&
426 ((*StackPtr
)->Reference
.Class
== ACPI_REFCLASS_INDEX
))
434 /* All cases covered above */
440 * Resolve this object to a value
442 Status
= AcpiExResolveToValue (StackPtr
, WalkState
);
443 if (ACPI_FAILURE (Status
))
445 return_ACPI_STATUS (Status
);
448 /* Get the resolved object */
453 * Check the resulting object (value) type
458 * For the simple cases, only one type of resolved object
463 /* Need an operand of type ACPI_TYPE_MUTEX */
465 TypeNeeded
= ACPI_TYPE_MUTEX
;
470 /* Need an operand of type ACPI_TYPE_EVENT */
472 TypeNeeded
= ACPI_TYPE_EVENT
;
475 case ARGI_PACKAGE
: /* Package */
477 /* Need an operand of type ACPI_TYPE_PACKAGE */
479 TypeNeeded
= ACPI_TYPE_PACKAGE
;
484 /* Any operand type will do */
486 TypeNeeded
= ACPI_TYPE_ANY
;
491 /* Need an operand of type ACPI_TYPE_DDB_HANDLE */
493 TypeNeeded
= ACPI_TYPE_LOCAL_REFERENCE
;
498 * The more complex cases allow multiple resolved object types
503 * Need an operand of type ACPI_TYPE_INTEGER,
504 * But we can implicitly convert from a STRING or BUFFER
505 * Aka - "Implicit Source Operand Conversion"
507 Status
= AcpiExConvertToInteger (ObjDesc
, StackPtr
, 16);
508 if (ACPI_FAILURE (Status
))
510 if (Status
== AE_TYPE
)
512 ACPI_ERROR ((AE_INFO
,
513 "Needed [Integer/String/Buffer], found [%s] %p",
514 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
516 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
519 return_ACPI_STATUS (Status
);
522 if (ObjDesc
!= *StackPtr
)
524 AcpiUtRemoveReference (ObjDesc
);
530 * Need an operand of type ACPI_TYPE_BUFFER,
531 * But we can implicitly convert from a STRING or INTEGER
532 * Aka - "Implicit Source Operand Conversion"
534 Status
= AcpiExConvertToBuffer (ObjDesc
, StackPtr
);
535 if (ACPI_FAILURE (Status
))
537 if (Status
== AE_TYPE
)
539 ACPI_ERROR ((AE_INFO
,
540 "Needed [Integer/String/Buffer], found [%s] %p",
541 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
543 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
546 return_ACPI_STATUS (Status
);
549 if (ObjDesc
!= *StackPtr
)
551 AcpiUtRemoveReference (ObjDesc
);
557 * Need an operand of type ACPI_TYPE_STRING,
558 * But we can implicitly convert from a BUFFER or INTEGER
559 * Aka - "Implicit Source Operand Conversion"
561 Status
= AcpiExConvertToString (
562 ObjDesc
, StackPtr
, ACPI_IMPLICIT_CONVERT_HEX
);
563 if (ACPI_FAILURE (Status
))
565 if (Status
== AE_TYPE
)
567 ACPI_ERROR ((AE_INFO
,
568 "Needed [Integer/String/Buffer], found [%s] %p",
569 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
571 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
574 return_ACPI_STATUS (Status
);
577 if (ObjDesc
!= *StackPtr
)
579 AcpiUtRemoveReference (ObjDesc
);
583 case ARGI_COMPUTEDATA
:
585 /* Need an operand of type INTEGER, STRING or BUFFER */
587 switch (ObjDesc
->Common
.Type
)
589 case ACPI_TYPE_INTEGER
:
590 case ACPI_TYPE_STRING
:
591 case ACPI_TYPE_BUFFER
:
597 ACPI_ERROR ((AE_INFO
,
598 "Needed [Integer/String/Buffer], found [%s] %p",
599 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
601 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
605 case ARGI_BUFFER_OR_STRING
:
607 /* Need an operand of type STRING or BUFFER */
609 switch (ObjDesc
->Common
.Type
)
611 case ACPI_TYPE_STRING
:
612 case ACPI_TYPE_BUFFER
:
617 case ACPI_TYPE_INTEGER
:
619 /* Highest priority conversion is to type Buffer */
621 Status
= AcpiExConvertToBuffer (ObjDesc
, StackPtr
);
622 if (ACPI_FAILURE (Status
))
624 return_ACPI_STATUS (Status
);
627 if (ObjDesc
!= *StackPtr
)
629 AcpiUtRemoveReference (ObjDesc
);
634 ACPI_ERROR ((AE_INFO
,
635 "Needed [Integer/String/Buffer], found [%s] %p",
636 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
638 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
642 case ARGI_DATAOBJECT
:
644 * ARGI_DATAOBJECT is only used by the SizeOf operator.
645 * Need a buffer, string, package, or RefOf reference.
647 * The only reference allowed here is a direct reference to
650 switch (ObjDesc
->Common
.Type
)
652 case ACPI_TYPE_PACKAGE
:
653 case ACPI_TYPE_STRING
:
654 case ACPI_TYPE_BUFFER
:
655 case ACPI_TYPE_LOCAL_REFERENCE
:
662 ACPI_ERROR ((AE_INFO
,
663 "Needed [Buffer/String/Package/Reference], found [%s] %p",
664 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
666 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
670 case ARGI_COMPLEXOBJ
:
672 /* Need a buffer or package or (ACPI 2.0) String */
674 switch (ObjDesc
->Common
.Type
)
676 case ACPI_TYPE_PACKAGE
:
677 case ACPI_TYPE_STRING
:
678 case ACPI_TYPE_BUFFER
:
685 ACPI_ERROR ((AE_INFO
,
686 "Needed [Buffer/String/Package], found [%s] %p",
687 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
689 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
693 case ARGI_REGION_OR_BUFFER
: /* Used by Load() only */
696 * Need an operand of type REGION or a BUFFER
697 * (which could be a resolved region field)
699 switch (ObjDesc
->Common
.Type
)
701 case ACPI_TYPE_BUFFER
:
702 case ACPI_TYPE_REGION
:
709 ACPI_ERROR ((AE_INFO
,
710 "Needed [Region/Buffer], found [%s] %p",
711 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
713 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
717 case ARGI_DATAREFOBJ
:
719 /* Used by the Store() operator only */
721 switch (ObjDesc
->Common
.Type
)
723 case ACPI_TYPE_INTEGER
:
724 case ACPI_TYPE_PACKAGE
:
725 case ACPI_TYPE_STRING
:
726 case ACPI_TYPE_BUFFER
:
727 case ACPI_TYPE_BUFFER_FIELD
:
728 case ACPI_TYPE_LOCAL_REFERENCE
:
729 case ACPI_TYPE_LOCAL_REGION_FIELD
:
730 case ACPI_TYPE_LOCAL_BANK_FIELD
:
731 case ACPI_TYPE_LOCAL_INDEX_FIELD
:
732 case ACPI_TYPE_DDB_HANDLE
:
739 if (AcpiGbl_EnableInterpreterSlack
)
742 * Enable original behavior of Store(), allowing any
743 * and all objects as the source operand. The ACPI
744 * spec does not allow this, however.
749 if (TargetOp
== AML_DEBUG_OP
)
751 /* Allow store of any object to the Debug object */
756 ACPI_ERROR ((AE_INFO
,
757 "Needed Integer/Buffer/String/Package/Ref/Ddb]"
759 AcpiUtGetObjectTypeName (ObjDesc
), ObjDesc
));
761 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
769 ACPI_ERROR ((AE_INFO
,
770 "Internal - Unknown ARGI (required operand) type 0x%X",
773 return_ACPI_STATUS (AE_BAD_PARAMETER
);
777 * Make sure that the original object was resolved to the
778 * required object type (Simple cases only).
780 Status
= AcpiExCheckObjectType (
781 TypeNeeded
, (*StackPtr
)->Common
.Type
, *StackPtr
);
782 if (ACPI_FAILURE (Status
))
784 return_ACPI_STATUS (Status
);
789 * If more operands needed, decrement StackPtr to point
790 * to next operand on stack
792 if (GET_CURRENT_ARG_TYPE (ArgTypes
))
798 ACPI_DUMP_OPERANDS (WalkState
->Operands
,
799 AcpiPsGetOpcodeName (Opcode
), WalkState
->NumOperands
);
801 return_ACPI_STATUS (Status
);