Import acpica-20050211 from Intel.
[dragonfly.git] / sys / contrib / dev / acpica-unix-20050211 / interpreter / executer / exoparg1.c
blobe270c972de8669bf5ff9eaa5fc61d5355dbc8f76
2 /******************************************************************************
4 * Module Name: exoparg1 - AML execution - opcodes with 1 argument
5 * $Revision: 165 $
7 *****************************************************************************/
9 /******************************************************************************
11 * 1. Copyright Notice
13 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
14 * All rights reserved.
16 * 2. License
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
21 * property rights.
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
40 * conditions are met:
42 * 3. Conditions
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
66 * make.
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
72 * distribution.
74 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * Intel Code.
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
90 * PARTICULAR PURPOSE.
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
99 * LIMITED REMEDY.
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 __EXOPARG1_C__
120 #include "acpi.h"
121 #include "acparser.h"
122 #include "acdispat.h"
123 #include "acinterp.h"
124 #include "amlcode.h"
125 #include "acnamesp.h"
128 #define _COMPONENT ACPI_EXECUTER
129 ACPI_MODULE_NAME ("exoparg1")
133 * Naming convention for AML interpreter execution routines.
135 * The routines that begin execution of AML opcodes are named with a common
136 * convention based upon the number of arguments, the number of target operands,
137 * and whether or not a value is returned:
139 * AcpiExOpcode_xA_yT_zR
141 * Where:
143 * xA - ARGUMENTS: The number of arguments (input operands) that are
144 * required for this opcode type (0 through 6 args).
145 * yT - TARGETS: The number of targets (output operands) that are required
146 * for this opcode type (0, 1, or 2 targets).
147 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
148 * as the function return (0 or 1).
150 * The AcpiExOpcode* functions are called via the Dispatcher component with
151 * fully resolved operands.
154 /*******************************************************************************
156 * FUNCTION: AcpiExOpcode_0A_0T_1R
158 * PARAMETERS: WalkState - Current state (contains AML opcode)
160 * RETURN: Status
162 * DESCRIPTION: Execute operator with no operands, one return value
164 ******************************************************************************/
166 ACPI_STATUS
167 AcpiExOpcode_0A_0T_1R (
168 ACPI_WALK_STATE *WalkState)
170 ACPI_STATUS Status = AE_OK;
171 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
174 ACPI_FUNCTION_TRACE_STR ("ExOpcode_0A_0T_1R", AcpiPsGetOpcodeName (WalkState->Opcode));
177 /* Examine the AML opcode */
179 switch (WalkState->Opcode)
181 case AML_TIMER_OP: /* Timer () */
183 /* Create a return object of type Integer */
185 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
186 if (!ReturnDesc)
188 Status = AE_NO_MEMORY;
189 goto Cleanup;
192 ReturnDesc->Integer.Value = AcpiOsGetTimer ();
193 break;
195 default: /* Unknown opcode */
197 ACPI_REPORT_ERROR (("AcpiExOpcode_0A_0T_1R: Unknown opcode %X\n",
198 WalkState->Opcode));
199 Status = AE_AML_BAD_OPCODE;
200 break;
203 Cleanup:
205 if (!WalkState->ResultObj)
207 WalkState->ResultObj = ReturnDesc;
210 /* Delete return object on error */
212 if (ACPI_FAILURE (Status))
214 AcpiUtRemoveReference (ReturnDesc);
217 return_ACPI_STATUS (Status);
221 /*******************************************************************************
223 * FUNCTION: AcpiExOpcode_1A_0T_0R
225 * PARAMETERS: WalkState - Current state (contains AML opcode)
227 * RETURN: Status
229 * DESCRIPTION: Execute Type 1 monadic operator with numeric operand on
230 * object stack
232 ******************************************************************************/
234 ACPI_STATUS
235 AcpiExOpcode_1A_0T_0R (
236 ACPI_WALK_STATE *WalkState)
238 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
239 ACPI_STATUS Status = AE_OK;
242 ACPI_FUNCTION_TRACE_STR ("ExOpcode_1A_0T_0R", AcpiPsGetOpcodeName (WalkState->Opcode));
245 /* Examine the AML opcode */
247 switch (WalkState->Opcode)
249 case AML_RELEASE_OP: /* Release (MutexObject) */
251 Status = AcpiExReleaseMutex (Operand[0], WalkState);
252 break;
255 case AML_RESET_OP: /* Reset (EventObject) */
257 Status = AcpiExSystemResetEvent (Operand[0]);
258 break;
261 case AML_SIGNAL_OP: /* Signal (EventObject) */
263 Status = AcpiExSystemSignalEvent (Operand[0]);
264 break;
267 case AML_SLEEP_OP: /* Sleep (MsecTime) */
269 Status = AcpiExSystemDoSuspend (Operand[0]->Integer.Value);
270 break;
273 case AML_STALL_OP: /* Stall (UsecTime) */
275 Status = AcpiExSystemDoStall ((UINT32) Operand[0]->Integer.Value);
276 break;
279 case AML_UNLOAD_OP: /* Unload (Handle) */
281 Status = AcpiExUnloadTable (Operand[0]);
282 break;
285 default: /* Unknown opcode */
287 ACPI_REPORT_ERROR (("AcpiExOpcode_1A_0T_0R: Unknown opcode %X\n",
288 WalkState->Opcode));
289 Status = AE_AML_BAD_OPCODE;
290 break;
293 return_ACPI_STATUS (Status);
297 /*******************************************************************************
299 * FUNCTION: AcpiExOpcode_1A_1T_0R
301 * PARAMETERS: WalkState - Current state (contains AML opcode)
303 * RETURN: Status
305 * DESCRIPTION: Execute opcode with one argument, one target, and no
306 * return value.
308 ******************************************************************************/
310 ACPI_STATUS
311 AcpiExOpcode_1A_1T_0R (
312 ACPI_WALK_STATE *WalkState)
314 ACPI_STATUS Status = AE_OK;
315 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
318 ACPI_FUNCTION_TRACE_STR ("ExOpcode_1A_1T_0R", AcpiPsGetOpcodeName (WalkState->Opcode));
321 /* Examine the AML opcode */
323 switch (WalkState->Opcode)
325 case AML_LOAD_OP:
327 Status = AcpiExLoadOp (Operand[0], Operand[1], WalkState);
328 break;
330 default: /* Unknown opcode */
332 ACPI_REPORT_ERROR (("AcpiExOpcode_1A_1T_0R: Unknown opcode %X\n",
333 WalkState->Opcode));
334 Status = AE_AML_BAD_OPCODE;
335 goto Cleanup;
339 Cleanup:
341 return_ACPI_STATUS (Status);
345 /*******************************************************************************
347 * FUNCTION: AcpiExOpcode_1A_1T_1R
349 * PARAMETERS: WalkState - Current state (contains AML opcode)
351 * RETURN: Status
353 * DESCRIPTION: Execute opcode with one argument, one target, and a
354 * return value.
356 ******************************************************************************/
358 ACPI_STATUS
359 AcpiExOpcode_1A_1T_1R (
360 ACPI_WALK_STATE *WalkState)
362 ACPI_STATUS Status = AE_OK;
363 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
364 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
365 ACPI_OPERAND_OBJECT *ReturnDesc2 = NULL;
366 UINT32 Temp32;
367 UINT32 i;
368 ACPI_INTEGER PowerOfTen;
369 ACPI_INTEGER Digit;
372 ACPI_FUNCTION_TRACE_STR ("ExOpcode_1A_1T_1R", AcpiPsGetOpcodeName (WalkState->Opcode));
375 /* Examine the AML opcode */
377 switch (WalkState->Opcode)
379 case AML_BIT_NOT_OP:
380 case AML_FIND_SET_LEFT_BIT_OP:
381 case AML_FIND_SET_RIGHT_BIT_OP:
382 case AML_FROM_BCD_OP:
383 case AML_TO_BCD_OP:
384 case AML_COND_REF_OF_OP:
386 /* Create a return object of type Integer for these opcodes */
388 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
389 if (!ReturnDesc)
391 Status = AE_NO_MEMORY;
392 goto Cleanup;
395 switch (WalkState->Opcode)
397 case AML_BIT_NOT_OP: /* Not (Operand, Result) */
399 ReturnDesc->Integer.Value = ~Operand[0]->Integer.Value;
400 break;
403 case AML_FIND_SET_LEFT_BIT_OP: /* FindSetLeftBit (Operand, Result) */
405 ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
408 * Acpi specification describes Integer type as a little
409 * endian unsigned value, so this boundary condition is valid.
411 for (Temp32 = 0; ReturnDesc->Integer.Value &&
412 Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
414 ReturnDesc->Integer.Value >>= 1;
417 ReturnDesc->Integer.Value = Temp32;
418 break;
421 case AML_FIND_SET_RIGHT_BIT_OP: /* FindSetRightBit (Operand, Result) */
423 ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
426 * The Acpi specification describes Integer type as a little
427 * endian unsigned value, so this boundary condition is valid.
429 for (Temp32 = 0; ReturnDesc->Integer.Value &&
430 Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
432 ReturnDesc->Integer.Value <<= 1;
435 /* Since the bit position is one-based, subtract from 33 (65) */
437 ReturnDesc->Integer.Value = Temp32 == 0 ? 0 :
438 (ACPI_INTEGER_BIT_SIZE + 1) - Temp32;
439 break;
442 case AML_FROM_BCD_OP: /* FromBcd (BCDValue, Result) */
445 * The 64-bit ACPI integer can hold 16 4-bit BCD characters
446 * (if table is 32-bit, integer can hold 8 BCD characters)
447 * Convert each 4-bit BCD value
449 PowerOfTen = 1;
450 ReturnDesc->Integer.Value = 0;
451 Digit = Operand[0]->Integer.Value;
453 /* Convert each BCD digit (each is one nybble wide) */
455 for (i = 0; (i < AcpiGbl_IntegerNybbleWidth) && (Digit > 0); i++)
457 /* Get the least significant 4-bit BCD digit */
459 Temp32 = ((UINT32) Digit) & 0xF;
461 /* Check the range of the digit */
463 if (Temp32 > 9)
465 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
466 "BCD digit too large (not decimal): 0x%X\n",
467 Temp32));
469 Status = AE_AML_NUMERIC_OVERFLOW;
470 goto Cleanup;
473 /* Sum the digit into the result with the current power of 10 */
475 ReturnDesc->Integer.Value += (((ACPI_INTEGER) Temp32) *
476 PowerOfTen);
478 /* Shift to next BCD digit */
480 Digit >>= 4;
482 /* Next power of 10 */
484 PowerOfTen *= 10;
486 break;
489 case AML_TO_BCD_OP: /* ToBcd (Operand, Result) */
491 ReturnDesc->Integer.Value = 0;
492 Digit = Operand[0]->Integer.Value;
494 /* Each BCD digit is one nybble wide */
496 for (i = 0; (i < AcpiGbl_IntegerNybbleWidth) && (Digit > 0); i++)
498 (void) AcpiUtShortDivide (Digit, 10, &Digit, &Temp32);
500 /* Insert the BCD digit that resides in the remainder from above */
502 ReturnDesc->Integer.Value |= (((ACPI_INTEGER) Temp32) <<
503 ACPI_MUL_4 (i));
506 /* Overflow if there is any data left in Digit */
508 if (Digit > 0)
510 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
511 "Integer too large to convert to BCD: %8.8X%8.8X\n",
512 ACPI_FORMAT_UINT64 (Operand[0]->Integer.Value)));
513 Status = AE_AML_NUMERIC_OVERFLOW;
514 goto Cleanup;
516 break;
519 case AML_COND_REF_OF_OP: /* CondRefOf (SourceObject, Result) */
522 * This op is a little strange because the internal return value is
523 * different than the return value stored in the result descriptor
524 * (There are really two return values)
526 if ((ACPI_NAMESPACE_NODE *) Operand[0] == AcpiGbl_RootNode)
529 * This means that the object does not exist in the namespace,
530 * return FALSE
532 ReturnDesc->Integer.Value = 0;
533 goto Cleanup;
536 /* Get the object reference, store it, and remove our reference */
538 Status = AcpiExGetObjectReference (Operand[0], &ReturnDesc2, WalkState);
539 if (ACPI_FAILURE (Status))
541 goto Cleanup;
544 Status = AcpiExStore (ReturnDesc2, Operand[1], WalkState);
545 AcpiUtRemoveReference (ReturnDesc2);
547 /* The object exists in the namespace, return TRUE */
549 ReturnDesc->Integer.Value = ACPI_INTEGER_MAX;
550 goto Cleanup;
553 default:
554 /* No other opcodes get here */
555 break;
557 break;
560 case AML_STORE_OP: /* Store (Source, Target) */
563 * A store operand is typically a number, string, buffer or lvalue
564 * Be careful about deleting the source object,
565 * since the object itself may have been stored.
567 Status = AcpiExStore (Operand[0], Operand[1], WalkState);
568 if (ACPI_FAILURE (Status))
570 return_ACPI_STATUS (Status);
573 /* It is possible that the Store already produced a return object */
575 if (!WalkState->ResultObj)
578 * Normally, we would remove a reference on the Operand[0] parameter;
579 * But since it is being used as the internal return object
580 * (meaning we would normally increment it), the two cancel out,
581 * and we simply don't do anything.
583 WalkState->ResultObj = Operand[0];
584 WalkState->Operands[0] = NULL; /* Prevent deletion */
586 return_ACPI_STATUS (Status);
590 * ACPI 2.0 Opcodes
592 case AML_COPY_OP: /* Copy (Source, Target) */
594 Status = AcpiUtCopyIobjectToIobject (Operand[0], &ReturnDesc,
595 WalkState);
596 break;
599 case AML_TO_DECSTRING_OP: /* ToDecimalString (Data, Result) */
601 Status = AcpiExConvertToString (Operand[0], &ReturnDesc,
602 ACPI_EXPLICIT_CONVERT_DECIMAL);
603 if (ReturnDesc == Operand[0])
605 /* No conversion performed, add ref to handle return value */
606 AcpiUtAddReference (ReturnDesc);
608 break;
611 case AML_TO_HEXSTRING_OP: /* ToHexString (Data, Result) */
613 Status = AcpiExConvertToString (Operand[0], &ReturnDesc,
614 ACPI_EXPLICIT_CONVERT_HEX);
615 if (ReturnDesc == Operand[0])
617 /* No conversion performed, add ref to handle return value */
618 AcpiUtAddReference (ReturnDesc);
620 break;
623 case AML_TO_BUFFER_OP: /* ToBuffer (Data, Result) */
625 Status = AcpiExConvertToBuffer (Operand[0], &ReturnDesc);
626 if (ReturnDesc == Operand[0])
628 /* No conversion performed, add ref to handle return value */
629 AcpiUtAddReference (ReturnDesc);
631 break;
634 case AML_TO_INTEGER_OP: /* ToInteger (Data, Result) */
636 Status = AcpiExConvertToInteger (Operand[0], &ReturnDesc,
637 ACPI_ANY_BASE);
638 if (ReturnDesc == Operand[0])
640 /* No conversion performed, add ref to handle return value */
641 AcpiUtAddReference (ReturnDesc);
643 break;
646 case AML_SHIFT_LEFT_BIT_OP: /* ShiftLeftBit (Source, BitNum) */
647 case AML_SHIFT_RIGHT_BIT_OP: /* ShiftRightBit (Source, BitNum) */
650 * These are two obsolete opcodes
652 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
653 "%s is obsolete and not implemented\n",
654 AcpiPsGetOpcodeName (WalkState->Opcode)));
655 Status = AE_SUPPORT;
656 goto Cleanup;
659 default: /* Unknown opcode */
661 ACPI_REPORT_ERROR (("AcpiExOpcode_1A_1T_1R: Unknown opcode %X\n",
662 WalkState->Opcode));
663 Status = AE_AML_BAD_OPCODE;
664 goto Cleanup;
667 if (ACPI_SUCCESS (Status))
670 * Store the return value computed above into the target object
672 Status = AcpiExStore (ReturnDesc, Operand[1], WalkState);
676 Cleanup:
678 if (!WalkState->ResultObj)
680 WalkState->ResultObj = ReturnDesc;
683 /* Delete return object on error */
685 if (ACPI_FAILURE (Status))
687 AcpiUtRemoveReference (ReturnDesc);
690 return_ACPI_STATUS (Status);
694 /*******************************************************************************
696 * FUNCTION: AcpiExOpcode_1A_0T_1R
698 * PARAMETERS: WalkState - Current state (contains AML opcode)
700 * RETURN: Status
702 * DESCRIPTION: Execute opcode with one argument, no target, and a return value
704 ******************************************************************************/
706 ACPI_STATUS
707 AcpiExOpcode_1A_0T_1R (
708 ACPI_WALK_STATE *WalkState)
710 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
711 ACPI_OPERAND_OBJECT *TempDesc;
712 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
713 ACPI_STATUS Status = AE_OK;
714 UINT32 Type;
715 ACPI_INTEGER Value;
718 ACPI_FUNCTION_TRACE_STR ("ExOpcode_1A_0T_1R", AcpiPsGetOpcodeName (WalkState->Opcode));
721 /* Examine the AML opcode */
723 switch (WalkState->Opcode)
725 case AML_LNOT_OP: /* LNot (Operand) */
727 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
728 if (!ReturnDesc)
730 Status = AE_NO_MEMORY;
731 goto Cleanup;
735 * Set result to ONES (TRUE) if Value == 0. Note:
736 * ReturnDesc->Integer.Value is initially == 0 (FALSE) from above.
738 if (!Operand[0]->Integer.Value)
740 ReturnDesc->Integer.Value = ACPI_INTEGER_MAX;
742 break;
745 case AML_DECREMENT_OP: /* Decrement (Operand) */
746 case AML_INCREMENT_OP: /* Increment (Operand) */
749 * Create a new integer. Can't just get the base integer and
750 * increment it because it may be an Arg or Field.
752 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
753 if (!ReturnDesc)
755 Status = AE_NO_MEMORY;
756 goto Cleanup;
760 * Since we are expecting a Reference operand, it can be either a
761 * NS Node or an internal object.
763 TempDesc = Operand[0];
764 if (ACPI_GET_DESCRIPTOR_TYPE (TempDesc) == ACPI_DESC_TYPE_OPERAND)
766 /* Internal reference object - prevent deletion */
768 AcpiUtAddReference (TempDesc);
772 * Convert the Reference operand to an Integer (This removes a
773 * reference on the Operand[0] object)
775 * NOTE: We use LNOT_OP here in order to force resolution of the
776 * reference operand to an actual integer.
778 Status = AcpiExResolveOperands (AML_LNOT_OP, &TempDesc, WalkState);
779 if (ACPI_FAILURE (Status))
781 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%s: bad operand(s) %s\n",
782 AcpiPsGetOpcodeName (WalkState->Opcode),
783 AcpiFormatException(Status)));
785 goto Cleanup;
789 * TempDesc is now guaranteed to be an Integer object --
790 * Perform the actual increment or decrement
792 if (WalkState->Opcode == AML_INCREMENT_OP)
794 ReturnDesc->Integer.Value = TempDesc->Integer.Value +1;
796 else
798 ReturnDesc->Integer.Value = TempDesc->Integer.Value -1;
801 /* Finished with this Integer object */
803 AcpiUtRemoveReference (TempDesc);
806 * Store the result back (indirectly) through the original
807 * Reference object
809 Status = AcpiExStore (ReturnDesc, Operand[0], WalkState);
810 break;
813 case AML_TYPE_OP: /* ObjectType (SourceObject) */
816 * Note: The operand is not resolved at this point because we want to
817 * get the associated object, not its value. For example, we don't want
818 * to resolve a FieldUnit to its value, we want the actual FieldUnit
819 * object.
822 /* Get the type of the base object */
824 Status = AcpiExResolveMultiple (WalkState, Operand[0], &Type, NULL);
825 if (ACPI_FAILURE (Status))
827 goto Cleanup;
829 /* Allocate a descriptor to hold the type. */
831 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
832 if (!ReturnDesc)
834 Status = AE_NO_MEMORY;
835 goto Cleanup;
838 ReturnDesc->Integer.Value = Type;
839 break;
842 case AML_SIZE_OF_OP: /* SizeOf (SourceObject) */
845 * Note: The operand is not resolved at this point because we want to
846 * get the associated object, not its value.
849 /* Get the base object */
851 Status = AcpiExResolveMultiple (WalkState, Operand[0], &Type, &TempDesc);
852 if (ACPI_FAILURE (Status))
854 goto Cleanup;
858 * The type of the base object must be integer, buffer, string, or
859 * package. All others are not supported.
861 * NOTE: Integer is not specifically supported by the ACPI spec,
862 * but is supported implicitly via implicit operand conversion.
863 * rather than bother with conversion, we just use the byte width
864 * global (4 or 8 bytes).
866 switch (Type)
868 case ACPI_TYPE_INTEGER:
869 Value = AcpiGbl_IntegerByteWidth;
870 break;
872 case ACPI_TYPE_BUFFER:
873 Value = TempDesc->Buffer.Length;
874 break;
876 case ACPI_TYPE_STRING:
877 Value = TempDesc->String.Length;
878 break;
880 case ACPI_TYPE_PACKAGE:
881 Value = TempDesc->Package.Count;
882 break;
884 default:
885 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
886 "SizeOf - Operand is not Buf/Int/Str/Pkg - found type %s\n",
887 AcpiUtGetTypeName (Type)));
888 Status = AE_AML_OPERAND_TYPE;
889 goto Cleanup;
893 * Now that we have the size of the object, create a result
894 * object to hold the value
896 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
897 if (!ReturnDesc)
899 Status = AE_NO_MEMORY;
900 goto Cleanup;
903 ReturnDesc->Integer.Value = Value;
904 break;
907 case AML_REF_OF_OP: /* RefOf (SourceObject) */
909 Status = AcpiExGetObjectReference (Operand[0], &ReturnDesc, WalkState);
910 if (ACPI_FAILURE (Status))
912 goto Cleanup;
914 break;
917 case AML_DEREF_OF_OP: /* DerefOf (ObjReference | String) */
919 /* Check for a method local or argument, or standalone String */
921 if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) != ACPI_DESC_TYPE_NAMED)
923 switch (ACPI_GET_OBJECT_TYPE (Operand[0]))
925 case ACPI_TYPE_LOCAL_REFERENCE:
927 * This is a DerefOf (LocalX | ArgX)
929 * Must resolve/dereference the local/arg reference first
931 switch (Operand[0]->Reference.Opcode)
933 case AML_LOCAL_OP:
934 case AML_ARG_OP:
936 /* Set Operand[0] to the value of the local/arg */
938 Status = AcpiDsMethodDataGetValue (Operand[0]->Reference.Opcode,
939 Operand[0]->Reference.Offset, WalkState, &TempDesc);
940 if (ACPI_FAILURE (Status))
942 goto Cleanup;
946 * Delete our reference to the input object and
947 * point to the object just retrieved
949 AcpiUtRemoveReference (Operand[0]);
950 Operand[0] = TempDesc;
951 break;
953 case AML_REF_OF_OP:
955 /* Get the object to which the reference refers */
957 TempDesc = Operand[0]->Reference.Object;
958 AcpiUtRemoveReference (Operand[0]);
959 Operand[0] = TempDesc;
960 break;
962 default:
964 /* Must be an Index op - handled below */
965 break;
967 break;
970 case ACPI_TYPE_STRING:
973 * This is a DerefOf (String). The string is a reference to a named ACPI object.
975 * 1) Find the owning Node
976 * 2) Dereference the node to an actual object. Could be a Field, so we nee
977 * to resolve the node to a value.
979 Status = AcpiNsGetNodeByPath (Operand[0]->String.Pointer,
980 WalkState->ScopeInfo->Scope.Node, ACPI_NS_SEARCH_PARENT,
981 ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &ReturnDesc));
982 if (ACPI_FAILURE (Status))
984 goto Cleanup;
987 Status = AcpiExResolveNodeToValue (
988 ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &ReturnDesc), WalkState);
989 goto Cleanup;
992 default:
994 Status = AE_AML_OPERAND_TYPE;
995 goto Cleanup;
999 /* Operand[0] may have changed from the code above */
1001 if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_NAMED)
1004 * This is a DerefOf (ObjectReference)
1005 * Get the actual object from the Node (This is the dereference).
1006 * -- This case may only happen when a LocalX or ArgX is dereferenced above.
1008 ReturnDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) Operand[0]);
1010 else
1013 * This must be a reference object produced by either the Index() or
1014 * RefOf() operator
1016 switch (Operand[0]->Reference.Opcode)
1018 case AML_INDEX_OP:
1021 * The target type for the Index operator must be
1022 * either a Buffer or a Package
1024 switch (Operand[0]->Reference.TargetType)
1026 case ACPI_TYPE_BUFFER_FIELD:
1028 TempDesc = Operand[0]->Reference.Object;
1031 * Create a new object that contains one element of the
1032 * buffer -- the element pointed to by the index.
1034 * NOTE: index into a buffer is NOT a pointer to a
1035 * sub-buffer of the main buffer, it is only a pointer to a
1036 * single element (byte) of the buffer!
1038 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
1039 if (!ReturnDesc)
1041 Status = AE_NO_MEMORY;
1042 goto Cleanup;
1046 * Since we are returning the value of the buffer at the
1047 * indexed location, we don't need to add an additional
1048 * reference to the buffer itself.
1050 ReturnDesc->Integer.Value =
1051 TempDesc->Buffer.Pointer[Operand[0]->Reference.Offset];
1052 break;
1055 case ACPI_TYPE_PACKAGE:
1058 * Return the referenced element of the package. We must add
1059 * another reference to the referenced object, however.
1061 ReturnDesc = *(Operand[0]->Reference.Where);
1062 if (!ReturnDesc)
1065 * We can't return a NULL dereferenced value. This is
1066 * an uninitialized package element and is thus a
1067 * severe error.
1069 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
1070 "NULL package element obj %p\n",
1071 Operand[0]));
1072 Status = AE_AML_UNINITIALIZED_ELEMENT;
1073 goto Cleanup;
1076 AcpiUtAddReference (ReturnDesc);
1077 break;
1080 default:
1082 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
1083 "Unknown Index TargetType %X in obj %p\n",
1084 Operand[0]->Reference.TargetType, Operand[0]));
1085 Status = AE_AML_OPERAND_TYPE;
1086 goto Cleanup;
1088 break;
1091 case AML_REF_OF_OP:
1093 ReturnDesc = Operand[0]->Reference.Object;
1095 if (ACPI_GET_DESCRIPTOR_TYPE (ReturnDesc) == ACPI_DESC_TYPE_NAMED)
1098 ReturnDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) ReturnDesc);
1101 /* Add another reference to the object! */
1103 AcpiUtAddReference (ReturnDesc);
1104 break;
1107 default:
1108 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
1109 "Unknown opcode in ref(%p) - %X\n",
1110 Operand[0], Operand[0]->Reference.Opcode));
1112 Status = AE_TYPE;
1113 goto Cleanup;
1116 break;
1119 default:
1121 ACPI_REPORT_ERROR (("AcpiExOpcode_1A_0T_1R: Unknown opcode %X\n",
1122 WalkState->Opcode));
1123 Status = AE_AML_BAD_OPCODE;
1124 goto Cleanup;
1128 Cleanup:
1130 /* Delete return object on error */
1132 if (ACPI_FAILURE (Status))
1134 AcpiUtRemoveReference (ReturnDesc);
1137 WalkState->ResultObj = ReturnDesc;
1138 return_ACPI_STATUS (Status);