2 /******************************************************************************
4 * Module Name: exresop - AML Interpreter operand/object resolution
7 *****************************************************************************/
9 /******************************************************************************
13 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
14 * All rights reserved.
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
39 * The above copyright and patent license is granted only if the following
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
74 * 3.4. Intel retains all right, title, and interest in and to the Original
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
82 * 4. Disclaimer and Export Compliance
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
116 *****************************************************************************/
118 #define __EXRESOP_C__
122 #include "acparser.h"
123 #include "acinterp.h"
126 #define _COMPONENT ACPI_EXECUTER
127 ACPI_MODULE_NAME ("exresop")
130 /*******************************************************************************
132 * FUNCTION: AcpiExCheckObjectType
134 * PARAMETERS: TypeNeeded Object type needed
135 * ThisType Actual object type
136 * Object Object pointer
140 * DESCRIPTION: Check required type against actual type
142 ******************************************************************************/
145 AcpiExCheckObjectType (
146 ACPI_OBJECT_TYPE TypeNeeded,
147 ACPI_OBJECT_TYPE ThisType,
150 ACPI_FUNCTION_NAME ("ExCheckObjectType");
153 if (TypeNeeded == ACPI_TYPE_ANY)
155 /* All types OK, so we don't perform any typechecks */
160 if (TypeNeeded == ACPI_TYPE_LOCAL_REFERENCE)
163 * Allow the AML "Constant" opcodes (Zero, One, etc.) to be reference
164 * objects and thus allow them to be targets. (As per the ACPI
165 * specification, a store to a constant is a noop.)
167 if ((ThisType == ACPI_TYPE_INTEGER) &&
168 (((ACPI_OPERAND_OBJECT *) Object)->Common.Flags & AOPOBJ_AML_CONSTANT))
174 if (TypeNeeded != ThisType)
176 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
177 "Needed [%s], found [%s] %p\n",
178 AcpiUtGetTypeName (TypeNeeded),
179 AcpiUtGetTypeName (ThisType), Object));
181 return (AE_AML_OPERAND_TYPE);
188 /*******************************************************************************
190 * FUNCTION: AcpiExResolveOperands
192 * PARAMETERS: Opcode - Opcode being interpreted
193 * StackPtr - Pointer to the operand stack to be
195 * WalkState - Current state
199 * DESCRIPTION: Convert multiple input operands to the types required by the
202 * Each 5-bit group in ArgTypes represents one required
203 * operand and indicates the required Type. The corresponding operand
204 * will be converted to the required type if possible, otherwise we
205 * abort with an exception.
207 ******************************************************************************/
210 AcpiExResolveOperands (
212 ACPI_OPERAND_OBJECT **StackPtr,
213 ACPI_WALK_STATE *WalkState)
215 ACPI_OPERAND_OBJECT *ObjDesc;
216 ACPI_STATUS Status = AE_OK;
220 const ACPI_OPCODE_INFO *OpInfo;
222 ACPI_OBJECT_TYPE TypeNeeded;
225 ACPI_FUNCTION_TRACE_U32 ("ExResolveOperands", Opcode);
228 OpInfo = AcpiPsGetOpcodeInfo (Opcode);
229 if (OpInfo->Class == AML_CLASS_UNKNOWN)
231 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
234 ArgTypes = OpInfo->RuntimeArgs;
235 if (ArgTypes == ARGI_INVALID_OPCODE)
237 ACPI_REPORT_ERROR (("ResolveOperands: %X is not a valid AML opcode\n",
240 return_ACPI_STATUS (AE_AML_INTERNAL);
243 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Opcode %X [%s] RequiredOperandTypes=%8.8X \n",
244 Opcode, OpInfo->Name, ArgTypes));
247 * Normal exit is with (ArgTypes == 0) at end of argument list.
248 * Function will return an exception from within the loop upon
249 * finding an entry which is not (or cannot be converted
250 * to) the required type; if stack underflows; or upon
251 * finding a NULL stack entry (which should not happen).
253 while (GET_CURRENT_ARG_TYPE (ArgTypes))
255 if (!StackPtr || !*StackPtr)
257 ACPI_REPORT_ERROR (("ResolveOperands: Null stack entry at %p\n",
260 return_ACPI_STATUS (AE_AML_INTERNAL);
263 /* Extract useful items */
267 /* Decode the descriptor type */
269 switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
271 case ACPI_DESC_TYPE_NAMED:
275 ObjectType = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;
279 case ACPI_DESC_TYPE_OPERAND:
281 /* ACPI internal object */
283 ObjectType = ACPI_GET_OBJECT_TYPE (ObjDesc);
285 /* Check for bad ACPI_OBJECT_TYPE */
287 if (!AcpiUtValidObjectType (ObjectType))
289 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Bad operand object type [%X]\n",
292 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
295 if (ObjectType == (UINT8) ACPI_TYPE_LOCAL_REFERENCE)
298 * Decode the Reference
300 OpInfo = AcpiPsGetOpcodeInfo (Opcode);
301 if (OpInfo->Class == AML_CLASS_UNKNOWN)
303 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
306 switch (ObjDesc->Reference.Opcode)
314 case AML_LOAD_OP: /* DdbHandle from LOAD_OP or LOAD_TABLE_OP */
316 ACPI_DEBUG_ONLY_MEMBERS (ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
317 "Operand is a Reference, RefOpcode [%s]\n",
318 (AcpiPsGetOpcodeInfo (ObjDesc->Reference.Opcode))->Name)));
322 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
323 "Operand is a Reference, Unknown Reference Opcode %X [%s]\n",
324 ObjDesc->Reference.Opcode,
325 (AcpiPsGetOpcodeInfo (ObjDesc->Reference.Opcode))->Name));
327 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
335 /* Invalid descriptor */
337 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
338 "Invalid descriptor %p [%s]\n",
339 ObjDesc, AcpiUtGetDescriptorName (ObjDesc)));
341 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
346 * Get one argument type, point to the next
348 ThisArgType = GET_CURRENT_ARG_TYPE (ArgTypes);
349 INCREMENT_ARG_LIST (ArgTypes);
352 * Handle cases where the object does not need to be
353 * resolved to a value
357 case ARGI_REF_OR_STRING: /* Can be a String or Reference */
359 if ((ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND) &&
360 (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_STRING))
363 * String found - the string references a named object and must be
369 /* Else not a string - fall through to the normal Reference case below */
370 /*lint -fallthrough */
372 case ARGI_REFERENCE: /* References: */
373 case ARGI_INTEGER_REF:
374 case ARGI_OBJECT_REF:
375 case ARGI_DEVICE_REF:
376 case ARGI_TARGETREF: /* Allows implicit conversion rules before store */
377 case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */
378 case ARGI_SIMPLE_TARGET: /* Name, Local, or Arg - no implicit conversion */
380 /* Need an operand of type ACPI_TYPE_LOCAL_REFERENCE */
382 if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_NAMED) /* Node (name) ptr OK as-is */
387 Status = AcpiExCheckObjectType (ACPI_TYPE_LOCAL_REFERENCE,
388 ObjectType, ObjDesc);
389 if (ACPI_FAILURE (Status))
391 return_ACPI_STATUS (Status);
394 if (AML_NAME_OP == ObjDesc->Reference.Opcode)
397 * Convert an indirect name ptr to direct name ptr and put
400 TempNode = ObjDesc->Reference.Object;
401 AcpiUtRemoveReference (ObjDesc);
402 (*StackPtr) = TempNode;
407 case ARGI_DATAREFOBJ: /* Store operator only */
410 * We don't want to resolve IndexOp reference objects during
411 * a store because this would be an implicit DeRefOf operation.
412 * Instead, we just want to store the reference object.
413 * -- All others must be resolved below.
415 if ((Opcode == AML_STORE_OP) &&
416 (ACPI_GET_OBJECT_TYPE (*StackPtr) == ACPI_TYPE_LOCAL_REFERENCE) &&
417 ((*StackPtr)->Reference.Opcode == AML_INDEX_OP))
424 /* All cases covered above */
430 * Resolve this object to a value
432 Status = AcpiExResolveToValue (StackPtr, WalkState);
433 if (ACPI_FAILURE (Status))
435 return_ACPI_STATUS (Status);
438 /* Get the resolved object */
443 * Check the resulting object (value) type
448 * For the simple cases, only one type of resolved object
453 /* Need an operand of type ACPI_TYPE_MUTEX */
455 TypeNeeded = ACPI_TYPE_MUTEX;
460 /* Need an operand of type ACPI_TYPE_EVENT */
462 TypeNeeded = ACPI_TYPE_EVENT;
465 case ARGI_PACKAGE: /* Package */
467 /* Need an operand of type ACPI_TYPE_PACKAGE */
469 TypeNeeded = ACPI_TYPE_PACKAGE;
474 /* Any operand type will do */
476 TypeNeeded = ACPI_TYPE_ANY;
481 /* Need an operand of type ACPI_TYPE_DDB_HANDLE */
483 TypeNeeded = ACPI_TYPE_LOCAL_REFERENCE;
488 * The more complex cases allow multiple resolved object types
490 case ARGI_INTEGER: /* Number */
493 * Need an operand of type ACPI_TYPE_INTEGER,
494 * But we can implicitly convert from a STRING or BUFFER
495 * Aka - "Implicit Source Operand Conversion"
497 Status = AcpiExConvertToInteger (ObjDesc, StackPtr, 16);
498 if (ACPI_FAILURE (Status))
500 if (Status == AE_TYPE)
502 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
503 "Needed [Integer/String/Buffer], found [%s] %p\n",
504 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
506 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
509 return_ACPI_STATUS (Status);
517 * Need an operand of type ACPI_TYPE_BUFFER,
518 * But we can implicitly convert from a STRING or INTEGER
519 * Aka - "Implicit Source Operand Conversion"
521 Status = AcpiExConvertToBuffer (ObjDesc, StackPtr);
522 if (ACPI_FAILURE (Status))
524 if (Status == AE_TYPE)
526 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
527 "Needed [Integer/String/Buffer], found [%s] %p\n",
528 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
530 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
533 return_ACPI_STATUS (Status);
541 * Need an operand of type ACPI_TYPE_STRING,
542 * But we can implicitly convert from a BUFFER or INTEGER
543 * Aka - "Implicit Source Operand Conversion"
545 Status = AcpiExConvertToString (ObjDesc, StackPtr,
546 ACPI_IMPLICIT_CONVERT_HEX);
547 if (ACPI_FAILURE (Status))
549 if (Status == AE_TYPE)
551 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
552 "Needed [Integer/String/Buffer], found [%s] %p\n",
553 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
555 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
558 return_ACPI_STATUS (Status);
563 case ARGI_COMPUTEDATA:
565 /* Need an operand of type INTEGER, STRING or BUFFER */
567 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
569 case ACPI_TYPE_INTEGER:
570 case ACPI_TYPE_STRING:
571 case ACPI_TYPE_BUFFER:
577 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
578 "Needed [Integer/String/Buffer], found [%s] %p\n",
579 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
581 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
586 case ARGI_BUFFER_OR_STRING:
588 /* Need an operand of type STRING or BUFFER */
590 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
592 case ACPI_TYPE_STRING:
593 case ACPI_TYPE_BUFFER:
598 case ACPI_TYPE_INTEGER:
600 /* Highest priority conversion is to type Buffer */
602 Status = AcpiExConvertToBuffer (ObjDesc, StackPtr);
603 if (ACPI_FAILURE (Status))
605 return_ACPI_STATUS (Status);
610 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
611 "Needed [Integer/String/Buffer], found [%s] %p\n",
612 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
614 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
619 case ARGI_DATAOBJECT:
621 * ARGI_DATAOBJECT is only used by the SizeOf operator.
622 * Need a buffer, string, package, or RefOf reference.
624 * The only reference allowed here is a direct reference to
627 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
629 case ACPI_TYPE_PACKAGE:
630 case ACPI_TYPE_STRING:
631 case ACPI_TYPE_BUFFER:
632 case ACPI_TYPE_LOCAL_REFERENCE:
638 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
639 "Needed [Buffer/String/Package/Reference], found [%s] %p\n",
640 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
642 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
647 case ARGI_COMPLEXOBJ:
649 /* Need a buffer or package or (ACPI 2.0) String */
651 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
653 case ACPI_TYPE_PACKAGE:
654 case ACPI_TYPE_STRING:
655 case ACPI_TYPE_BUFFER:
661 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
662 "Needed [Buffer/String/Package], found [%s] %p\n",
663 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
665 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
670 case ARGI_REGION_OR_FIELD:
672 /* Need an operand of type ACPI_TYPE_REGION or a FIELD in a region */
674 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
676 case ACPI_TYPE_REGION:
677 case ACPI_TYPE_LOCAL_REGION_FIELD:
678 case ACPI_TYPE_LOCAL_BANK_FIELD:
679 case ACPI_TYPE_LOCAL_INDEX_FIELD:
685 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
686 "Needed [Region/RegionField], found [%s] %p\n",
687 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
689 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
694 case ARGI_DATAREFOBJ:
696 /* Used by the Store() operator only */
698 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
700 case ACPI_TYPE_INTEGER:
701 case ACPI_TYPE_PACKAGE:
702 case ACPI_TYPE_STRING:
703 case ACPI_TYPE_BUFFER:
704 case ACPI_TYPE_BUFFER_FIELD:
705 case ACPI_TYPE_LOCAL_REFERENCE:
706 case ACPI_TYPE_LOCAL_REGION_FIELD:
707 case ACPI_TYPE_LOCAL_BANK_FIELD:
708 case ACPI_TYPE_LOCAL_INDEX_FIELD:
709 case ACPI_TYPE_DDB_HANDLE:
716 if (AcpiGbl_EnableInterpreterSlack)
719 * Enable original behavior of Store(), allowing any and all
720 * objects as the source operand. The ACPI spec does not
721 * allow this, however.
726 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
727 "Needed Integer/Buffer/String/Package/Ref/Ddb], found [%s] %p\n",
728 AcpiUtGetObjectTypeName (ObjDesc), ObjDesc));
730 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
739 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
740 "Internal - Unknown ARGI (required operand) type %X\n",
743 return_ACPI_STATUS (AE_BAD_PARAMETER);
747 * Make sure that the original object was resolved to the
748 * required object type (Simple cases only).
750 Status = AcpiExCheckObjectType (TypeNeeded,
751 ACPI_GET_OBJECT_TYPE (*StackPtr), *StackPtr);
752 if (ACPI_FAILURE (Status))
754 return_ACPI_STATUS (Status);
759 * If more operands needed, decrement StackPtr to point
760 * to next operand on stack
762 if (GET_CURRENT_ARG_TYPE (ArgTypes))
767 } /* while (*Types) */
769 return_ACPI_STATUS (Status);