Merge from vendor branch LIBSTDC++:
[dragonfly.git] / sys / contrib / dev / acpica / exoparg1.c
1
2 /******************************************************************************
3  *
4  * Module Name: exoparg1 - AML execution - opcodes with 1 argument
5  *              $Revision: 147 $
6  *
7  *****************************************************************************/
8
9 /******************************************************************************
10  *
11  * 1. Copyright Notice
12  *
13  * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
14  * All rights reserved.
15  *
16  * 2. License
17  *
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.
22  *
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
29  *
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;
38  *
39  * The above copyright and patent license is granted only if the following
40  * conditions are met:
41  *
42  * 3. Conditions
43  *
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.
55  *
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.
67  *
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.
73  *
74  * 3.4. Intel retains all right, title, and interest in and to the Original
75  * Intel Code.
76  *
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.
81  *
82  * 4. Disclaimer and Export Compliance
83  *
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.
91  *
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.
100  *
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.
115  *
116  *****************************************************************************/
117 /* $DragonFly: src/sys/contrib/dev/acpica/Attic/exoparg1.c,v 1.1 2003/09/24 03:32:16 drhodus Exp $                                                               */
118
119 #define __EXOPARG1_C__
120
121 #include "acpi.h"
122 #include "acparser.h"
123 #include "acdispat.h"
124 #include "acinterp.h"
125 #include "amlcode.h"
126 #include "acnamesp.h"
127
128
129 #define _COMPONENT          ACPI_EXECUTER
130         ACPI_MODULE_NAME    ("exoparg1")
131
132
133 /*!
134  * Naming convention for AML interpreter execution routines.
135  *
136  * The routines that begin execution of AML opcodes are named with a common
137  * convention based upon the number of arguments, the number of target operands,
138  * and whether or not a value is returned:
139  *
140  *      AcpiExOpcode_xA_yT_zR
141  *
142  * Where:
143  *
144  * xA - ARGUMENTS:    The number of arguments (input operands) that are
145  *                    required for this opcode type (1 through 6 args).
146  * yT - TARGETS:      The number of targets (output operands) that are required
147  *                    for this opcode type (0, 1, or 2 targets).
148  * zR - RETURN VALUE: Indicates whether this opcode type returns a value
149  *                    as the function return (0 or 1).
150  *
151  * The AcpiExOpcode* functions are called via the Dispatcher component with
152  * fully resolved operands.
153 !*/
154
155 /*******************************************************************************
156  *
157  * FUNCTION:    AcpiExOpcode_1A_0T_0R
158  *
159  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
160  *
161  * RETURN:      Status
162  *
163  * DESCRIPTION: Execute Type 1 monadic operator with numeric operand on
164  *              object stack
165  *
166  ******************************************************************************/
167
168 ACPI_STATUS
169 AcpiExOpcode_1A_0T_0R (
170     ACPI_WALK_STATE         *WalkState)
171 {
172     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
173     ACPI_STATUS             Status = AE_OK;
174
175
176     ACPI_FUNCTION_TRACE_STR ("ExOpcode_1A_0T_0R", AcpiPsGetOpcodeName (WalkState->Opcode));
177
178
179     /* Examine the AML opcode */
180
181     switch (WalkState->Opcode)
182     {
183     case AML_RELEASE_OP:    /*  Release (MutexObject) */
184
185         Status = AcpiExReleaseMutex (Operand[0], WalkState);
186         break;
187
188
189     case AML_RESET_OP:      /*  Reset (EventObject) */
190
191         Status = AcpiExSystemResetEvent (Operand[0]);
192         break;
193
194
195     case AML_SIGNAL_OP:     /*  Signal (EventObject) */
196
197         Status = AcpiExSystemSignalEvent (Operand[0]);
198         break;
199
200
201     case AML_SLEEP_OP:      /*  Sleep (MsecTime) */
202
203         Status = AcpiExSystemDoSuspend ((UINT32) Operand[0]->Integer.Value);
204         break;
205
206
207     case AML_STALL_OP:      /*  Stall (UsecTime) */
208
209         Status = AcpiExSystemDoStall ((UINT32) Operand[0]->Integer.Value);
210         break;
211
212
213     case AML_UNLOAD_OP:     /*  Unload (Handle) */
214
215         Status = AcpiExUnloadTable (Operand[0]);
216         break;
217
218
219     default:                /*  Unknown opcode  */
220
221         ACPI_REPORT_ERROR (("AcpiExOpcode_1A_0T_0R: Unknown opcode %X\n",
222             WalkState->Opcode));
223         Status = AE_AML_BAD_OPCODE;
224         break;
225     }
226
227     return_ACPI_STATUS (Status);
228 }
229
230
231 /*******************************************************************************
232  *
233  * FUNCTION:    AcpiExOpcode_1A_1T_0R
234  *
235  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
236  *
237  * RETURN:      Status
238  *
239  * DESCRIPTION: Execute opcode with one argument, one target, and no
240  *              return value.
241  *
242  ******************************************************************************/
243
244 ACPI_STATUS
245 AcpiExOpcode_1A_1T_0R (
246     ACPI_WALK_STATE         *WalkState)
247 {
248     ACPI_STATUS             Status = AE_OK;
249     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
250
251
252     ACPI_FUNCTION_TRACE_STR ("ExOpcode_1A_1T_0R", AcpiPsGetOpcodeName (WalkState->Opcode));
253
254
255     /* Examine the AML opcode */
256
257     switch (WalkState->Opcode)
258     {
259     case AML_LOAD_OP:
260
261         Status = AcpiExLoadOp (Operand[0], Operand[1], WalkState);
262         break;
263
264     default:                        /* Unknown opcode */
265
266         ACPI_REPORT_ERROR (("AcpiExOpcode_1A_1T_0R: Unknown opcode %X\n",
267             WalkState->Opcode));
268         Status = AE_AML_BAD_OPCODE;
269         goto Cleanup;
270     }
271
272
273 Cleanup:
274
275     return_ACPI_STATUS (Status);
276 }
277
278
279 /*******************************************************************************
280  *
281  * FUNCTION:    AcpiExOpcode_1A_1T_1R
282  *
283  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
284  *
285  * RETURN:      Status
286  *
287  * DESCRIPTION: Execute opcode with one argument, one target, and a
288  *              return value.
289  *
290  ******************************************************************************/
291
292 ACPI_STATUS
293 AcpiExOpcode_1A_1T_1R (
294     ACPI_WALK_STATE         *WalkState)
295 {
296     ACPI_STATUS             Status = AE_OK;
297     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
298     ACPI_OPERAND_OBJECT     *ReturnDesc = NULL;
299     ACPI_OPERAND_OBJECT     *ReturnDesc2 = NULL;
300     UINT32                  Temp32;
301     UINT32                  i;
302     UINT32                  j;
303     ACPI_INTEGER            Digit;
304
305
306     ACPI_FUNCTION_TRACE_STR ("ExOpcode_1A_1T_1R", AcpiPsGetOpcodeName (WalkState->Opcode));
307
308
309     /* Examine the AML opcode */
310
311     switch (WalkState->Opcode)
312     {
313     case AML_BIT_NOT_OP:
314     case AML_FIND_SET_LEFT_BIT_OP:
315     case AML_FIND_SET_RIGHT_BIT_OP:
316     case AML_FROM_BCD_OP:
317     case AML_TO_BCD_OP:
318     case AML_COND_REF_OF_OP:
319
320         /* Create a return object of type Integer for these opcodes */
321
322         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
323         if (!ReturnDesc)
324         {
325             Status = AE_NO_MEMORY;
326             goto Cleanup;
327         }
328
329         switch (WalkState->Opcode)
330         {
331         case AML_BIT_NOT_OP:            /* Not (Operand, Result)  */
332
333             ReturnDesc->Integer.Value = ~Operand[0]->Integer.Value;
334             break;
335
336
337         case AML_FIND_SET_LEFT_BIT_OP:  /* FindSetLeftBit (Operand, Result) */
338
339             ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
340
341             /*
342              * Acpi specification describes Integer type as a little
343              * endian unsigned value, so this boundary condition is valid.
344              */
345             for (Temp32 = 0; ReturnDesc->Integer.Value && Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
346             {
347                 ReturnDesc->Integer.Value >>= 1;
348             }
349
350             ReturnDesc->Integer.Value = Temp32;
351             break;
352
353
354         case AML_FIND_SET_RIGHT_BIT_OP: /* FindSetRightBit (Operand, Result)  */
355
356             ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
357
358             /*
359              * The Acpi specification describes Integer type as a little
360              * endian unsigned value, so this boundary condition is valid.
361              */
362             for (Temp32 = 0; ReturnDesc->Integer.Value && Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
363             {
364                 ReturnDesc->Integer.Value <<= 1;
365             }
366
367             /* Since the bit position is one-based, subtract from 33 (65) */
368
369             ReturnDesc->Integer.Value = Temp32 == 0 ? 0 : (ACPI_INTEGER_BIT_SIZE + 1) - Temp32;
370             break;
371
372
373         case AML_FROM_BCD_OP:           /* FromBcd (BCDValue, Result)  */
374
375             /*
376              * The 64-bit ACPI integer can hold 16 4-bit BCD integers
377              */
378             ReturnDesc->Integer.Value = 0;
379             for (i = 0; i < ACPI_MAX_BCD_DIGITS; i++)
380             {
381                 /* Get one BCD digit */
382
383                 Digit = (ACPI_INTEGER) ((Operand[0]->Integer.Value >> (i * 4)) & 0xF);
384
385                 /* Check the range of the digit */
386
387                 if (Digit > 9)
388                 {
389                     ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "BCD digit too large: %d\n",
390                         (UINT32) Digit));
391                     Status = AE_AML_NUMERIC_OVERFLOW;
392                     goto Cleanup;
393                 }
394
395                 if (Digit > 0)
396                 {
397                     /* Sum into the result with the appropriate power of 10 */
398
399                     for (j = 0; j < i; j++)
400                     {
401                         Digit *= 10;
402                     }
403
404                     ReturnDesc->Integer.Value += Digit;
405                 }
406             }
407             break;
408
409
410         case AML_TO_BCD_OP:             /* ToBcd (Operand, Result)  */
411
412             if (Operand[0]->Integer.Value > ACPI_MAX_BCD_VALUE)
413             {
414                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "BCD overflow: %8.8X%8.8X\n",
415                     ACPI_HIDWORD(Operand[0]->Integer.Value),
416                     ACPI_LODWORD(Operand[0]->Integer.Value)));
417                 Status = AE_AML_NUMERIC_OVERFLOW;
418                 goto Cleanup;
419             }
420
421             ReturnDesc->Integer.Value = 0;
422             for (i = 0; i < ACPI_MAX_BCD_DIGITS; i++)
423             {
424                 /* Divide by nth factor of 10 */
425
426                 Temp32 = 0;
427                 Digit = Operand[0]->Integer.Value;
428                 for (j = 0; j < i; j++)
429                 {
430                     (void) AcpiUtShortDivide (&Digit, 10, &Digit, &Temp32);
431                 }
432
433                 /* Create the BCD digit from the remainder above */
434
435                 if (Digit > 0)
436                 {
437                     ReturnDesc->Integer.Value += ((ACPI_INTEGER) Temp32 << (i * 4));
438                 }
439             }
440             break;
441
442
443         case AML_COND_REF_OF_OP:        /* CondRefOf (SourceObject, Result)  */
444
445             /*
446              * This op is a little strange because the internal return value is
447              * different than the return value stored in the result descriptor
448              * (There are really two return values)
449              */
450             if ((ACPI_NAMESPACE_NODE *) Operand[0] == AcpiGbl_RootNode)
451             {
452                 /*
453                  * This means that the object does not exist in the namespace,
454                  * return FALSE
455                  */
456                 ReturnDesc->Integer.Value = 0;
457                 goto Cleanup;
458             }
459
460             /* Get the object reference, store it, and remove our reference */
461
462             Status = AcpiExGetObjectReference (Operand[0], &ReturnDesc2, WalkState);
463             if (ACPI_FAILURE (Status))
464             {
465                 goto Cleanup;
466             }
467
468             Status = AcpiExStore (ReturnDesc2, Operand[1], WalkState);
469             AcpiUtRemoveReference (ReturnDesc2);
470
471             /* The object exists in the namespace, return TRUE */
472
473             ReturnDesc->Integer.Value = ACPI_INTEGER_MAX;
474             goto Cleanup;
475
476
477         default:
478             /* No other opcodes get here */
479             break;
480         }
481         break;
482
483
484     case AML_STORE_OP:              /* Store (Source, Target) */
485
486         /*
487          * A store operand is typically a number, string, buffer or lvalue
488          * Be careful about deleting the source object,
489          * since the object itself may have been stored.
490          */
491         Status = AcpiExStore (Operand[0], Operand[1], WalkState);
492         if (ACPI_FAILURE (Status))
493         {
494             return_ACPI_STATUS (Status);
495         }
496
497         /* It is possible that the Store already produced a return object */
498
499         if (!WalkState->ResultObj)
500         {
501             /*
502              * Normally, we would remove a reference on the Operand[0] parameter;
503              * But since it is being used as the internal return object
504              * (meaning we would normally increment it), the two cancel out,
505              * and we simply don't do anything.
506              */
507             WalkState->ResultObj = Operand[0];
508             WalkState->Operands[0] = NULL;  /* Prevent deletion */
509         }
510         return_ACPI_STATUS (Status);
511
512
513     /*
514      * ACPI 2.0 Opcodes
515      */
516     case AML_COPY_OP:               /* Copy (Source, Target) */
517
518         Status = AcpiUtCopyIobjectToIobject (Operand[0], &ReturnDesc, WalkState);
519         break;
520
521
522     case AML_TO_DECSTRING_OP:       /* ToDecimalString (Data, Result) */
523
524         Status = AcpiExConvertToString (Operand[0], &ReturnDesc, 10, ACPI_UINT32_MAX, WalkState);
525         break;
526
527
528     case AML_TO_HEXSTRING_OP:       /* ToHexString (Data, Result) */
529
530         Status = AcpiExConvertToString (Operand[0], &ReturnDesc, 16, ACPI_UINT32_MAX, WalkState);
531         break;
532
533
534     case AML_TO_BUFFER_OP:          /* ToBuffer (Data, Result) */
535
536         Status = AcpiExConvertToBuffer (Operand[0], &ReturnDesc, WalkState);
537         break;
538
539
540     case AML_TO_INTEGER_OP:         /* ToInteger (Data, Result) */
541
542         Status = AcpiExConvertToInteger (Operand[0], &ReturnDesc, WalkState);
543         break;
544
545
546     case AML_SHIFT_LEFT_BIT_OP:     /*  ShiftLeftBit (Source, BitNum)  */
547     case AML_SHIFT_RIGHT_BIT_OP:    /*  ShiftRightBit (Source, BitNum) */
548
549         /*
550          * These are two obsolete opcodes
551          */
552         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%s is obsolete and not implemented\n",
553                         AcpiPsGetOpcodeName (WalkState->Opcode)));
554         Status = AE_SUPPORT;
555         goto Cleanup;
556
557
558     default:                        /* Unknown opcode */
559
560         ACPI_REPORT_ERROR (("AcpiExOpcode_1A_1T_1R: Unknown opcode %X\n",
561             WalkState->Opcode));
562         Status = AE_AML_BAD_OPCODE;
563         goto Cleanup;
564     }
565
566     /*
567      * Store the return value computed above into the target object
568      */
569     Status = AcpiExStore (ReturnDesc, Operand[1], WalkState);
570
571
572 Cleanup:
573
574     if (!WalkState->ResultObj)
575     {
576         WalkState->ResultObj = ReturnDesc;
577     }
578
579     /* Delete return object on error */
580
581     if (ACPI_FAILURE (Status))
582     {
583         AcpiUtRemoveReference (ReturnDesc);
584     }
585
586     return_ACPI_STATUS (Status);
587 }
588
589
590 /*******************************************************************************
591  *
592  * FUNCTION:    AcpiExOpcode_1A_0T_1R
593  *
594  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
595  *
596  * RETURN:      Status
597  *
598  * DESCRIPTION: Execute opcode with one argument, no target, and a return value
599  *
600  ******************************************************************************/
601
602 ACPI_STATUS
603 AcpiExOpcode_1A_0T_1R (
604     ACPI_WALK_STATE         *WalkState)
605 {
606     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
607     ACPI_OPERAND_OBJECT     *TempDesc;
608     ACPI_OPERAND_OBJECT     *ReturnDesc = NULL;
609     ACPI_STATUS             Status = AE_OK;
610     UINT32                  Type;
611     ACPI_INTEGER            Value;
612
613
614     ACPI_FUNCTION_TRACE_STR ("ExOpcode_1A_0T_0R", AcpiPsGetOpcodeName (WalkState->Opcode));
615
616
617     /* Examine the AML opcode */
618
619     switch (WalkState->Opcode)
620     {
621     case AML_LNOT_OP:               /* LNot (Operand) */
622
623         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
624         if (!ReturnDesc)
625         {
626             Status = AE_NO_MEMORY;
627             goto Cleanup;
628         }
629
630         ReturnDesc->Integer.Value = !Operand[0]->Integer.Value;
631         break;
632
633
634     case AML_DECREMENT_OP:          /* Decrement (Operand)  */
635     case AML_INCREMENT_OP:          /* Increment (Operand)  */
636
637         /*
638          * Since we are expecting a Reference operand, it
639          * can be either a NS Node or an internal object.
640          */
641         ReturnDesc = Operand[0];
642         if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_OPERAND)
643         {
644             /* Internal reference object - prevent deletion */
645
646             AcpiUtAddReference (ReturnDesc);
647         }
648
649         /*
650          * Convert the ReturnDesc Reference to a Number
651          * (This removes a reference on the ReturnDesc object)
652          */
653         Status = AcpiExResolveOperands (AML_LNOT_OP, &ReturnDesc, WalkState);
654         if (ACPI_FAILURE (Status))
655         {
656             ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%s: bad operand(s) %s\n",
657                 AcpiPsGetOpcodeName (WalkState->Opcode), AcpiFormatException(Status)));
658
659             goto Cleanup;
660         }
661
662         /*
663          * ReturnDesc is now guaranteed to be an Integer object
664          * Do the actual increment or decrement
665          */
666         if (AML_INCREMENT_OP == WalkState->Opcode)
667         {
668             ReturnDesc->Integer.Value++;
669         }
670         else
671         {
672             ReturnDesc->Integer.Value--;
673         }
674
675         /* Store the result back in the original descriptor */
676
677         Status = AcpiExStore (ReturnDesc, Operand[0], WalkState);
678         break;
679
680
681     case AML_TYPE_OP:               /* ObjectType (SourceObject) */
682
683         /* Get the type of the base object */
684
685         Status = AcpiExResolveMultiple (WalkState, Operand[0], &Type, NULL);
686         if (ACPI_FAILURE (Status))
687         {
688             goto Cleanup;
689         }
690
691         /* Allocate a descriptor to hold the type. */
692
693         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
694         if (!ReturnDesc)
695         {
696             Status = AE_NO_MEMORY;
697             goto Cleanup;
698         }
699
700         ReturnDesc->Integer.Value = Type;
701         break;
702
703
704     case AML_SIZE_OF_OP:            /* SizeOf (SourceObject)  */
705
706         /* Get the base object */
707
708         Status = AcpiExResolveMultiple (WalkState, Operand[0], &Type, &TempDesc);
709         if (ACPI_FAILURE (Status))
710         {
711             goto Cleanup;
712         }
713
714         /*
715          * Type is guaranteed to be a buffer, string, or package at this
716          * point (even if the original operand was an object reference, it
717          * will be resolved and typechecked during operand resolution.)
718          */
719         switch (Type)
720         {
721         case ACPI_TYPE_BUFFER:
722             Value = TempDesc->Buffer.Length;
723             break;
724
725         case ACPI_TYPE_STRING:
726             Value = TempDesc->String.Length;
727             break;
728
729         case ACPI_TYPE_PACKAGE:
730             Value = TempDesc->Package.Count;
731             break;
732
733         default:
734             ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "SizeOf, Not Buf/Str/Pkg - found type %s\n",
735                 AcpiUtGetTypeName (Type)));
736             Status = AE_AML_OPERAND_TYPE;
737             goto Cleanup;
738         }
739
740         /*
741          * Now that we have the size of the object, create a result
742          * object to hold the value
743          */
744         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
745         if (!ReturnDesc)
746         {
747             Status = AE_NO_MEMORY;
748             goto Cleanup;
749         }
750
751         ReturnDesc->Integer.Value = Value;
752         break;
753
754
755     case AML_REF_OF_OP:             /* RefOf (SourceObject) */
756
757         Status = AcpiExGetObjectReference (Operand[0], &ReturnDesc, WalkState);
758         if (ACPI_FAILURE (Status))
759         {
760             goto Cleanup;
761         }
762         break;
763
764
765     case AML_DEREF_OF_OP:           /* DerefOf (ObjReference | String) */
766
767         /* Check for a method local or argument, or standalone String */
768
769         if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) != ACPI_DESC_TYPE_NAMED)
770         {
771             switch (ACPI_GET_OBJECT_TYPE (Operand[0]))
772             {
773             case ACPI_TYPE_LOCAL_REFERENCE:
774                 /*
775                  * This is a DerefOf (LocalX | ArgX)
776                  *
777                  * Must resolve/dereference the local/arg reference first
778                  */
779                 switch (Operand[0]->Reference.Opcode)
780                 {
781                 case AML_LOCAL_OP:
782                 case AML_ARG_OP:
783
784                     /* Set Operand[0] to the value of the local/arg */
785
786                     Status = AcpiDsMethodDataGetValue (Operand[0]->Reference.Opcode,
787                                 Operand[0]->Reference.Offset, WalkState, &TempDesc);
788                     if (ACPI_FAILURE (Status))
789                     {
790                         goto Cleanup;
791                     }
792
793                     /*
794                      * Delete our reference to the input object and
795                      * point to the object just retrieved
796                      */
797                     AcpiUtRemoveReference (Operand[0]);
798                     Operand[0] = TempDesc;
799                     break;
800
801                 case AML_REF_OF_OP:
802
803                     /* Get the object to which the reference refers */
804
805                     TempDesc = Operand[0]->Reference.Object;
806                     AcpiUtRemoveReference (Operand[0]);
807                     Operand[0] = TempDesc;
808                     break;
809
810                 default:
811
812                     /* Must be an Index op - handled below */
813                     break;
814                 }
815                 break;
816
817
818             case ACPI_TYPE_STRING:
819
820                 /*
821                  * This is a DerefOf (String).  The string is a reference to a named ACPI object.
822                  *
823                  * 1) Find the owning Node
824                  * 2) Dereference the node to an actual object.  Could be a Field, so we nee
825                  *    to resolve the node to a value.
826                  */
827                 Status = AcpiNsGetNodeByPath (Operand[0]->String.Pointer,
828                                 WalkState->ScopeInfo->Scope.Node, ACPI_NS_SEARCH_PARENT,
829                                 ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &ReturnDesc));
830                 if (ACPI_FAILURE (Status))
831                 {
832                     goto Cleanup;
833                 }
834
835                 Status = AcpiExResolveNodeToValue (
836                                 ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &ReturnDesc), WalkState);
837                 goto Cleanup;
838
839
840             default:
841
842                 Status = AE_AML_OPERAND_TYPE;
843                 goto Cleanup;
844             }
845         }
846
847         /* Operand[0] may have changed from the code above */
848
849         if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_NAMED)
850         {
851             /*
852              * This is a DerefOf (ObjectReference)
853              * Get the actual object from the Node (This is the dereference).
854              * -- This case may only happen when a LocalX or ArgX is dereferenced above.
855              */
856             ReturnDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) Operand[0]);
857         }
858         else
859         {
860             /*
861              * This must be a reference object produced by either the Index() or
862              * RefOf() operator
863              */
864             switch (Operand[0]->Reference.Opcode)
865             {
866             case AML_INDEX_OP:
867
868                 /*
869                  * The target type for the Index operator must be
870                  * either a Buffer or a Package
871                  */
872                 switch (Operand[0]->Reference.TargetType)
873                 {
874                 case ACPI_TYPE_BUFFER_FIELD:
875
876                     TempDesc = Operand[0]->Reference.Object;
877
878                     /*
879                      * Create a new object that contains one element of the
880                      * buffer -- the element pointed to by the index.
881                      *
882                      * NOTE: index into a buffer is NOT a pointer to a
883                      * sub-buffer of the main buffer, it is only a pointer to a
884                      * single element (byte) of the buffer!
885                      */
886                     ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
887                     if (!ReturnDesc)
888                     {
889                         Status = AE_NO_MEMORY;
890                         goto Cleanup;
891                     }
892
893                     /*
894                      * Since we are returning the value of the buffer at the
895                      * indexed location, we don't need to add an additional
896                      * reference to the buffer itself.
897                      */
898                     ReturnDesc->Integer.Value =
899                         TempDesc->Buffer.Pointer[Operand[0]->Reference.Offset];
900                     break;
901
902
903                 case ACPI_TYPE_PACKAGE:
904
905                     /*
906                      * Return the referenced element of the package.  We must add
907                      * another reference to the referenced object, however.
908                      */
909                     ReturnDesc = *(Operand[0]->Reference.Where);
910                     if (!ReturnDesc)
911                     {
912                         /*
913                          * We can't return a NULL dereferenced value.  This is
914                          * an uninitialized package element and is thus a
915                          * severe error.
916                          */
917                         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "NULL package element obj %p\n",
918                             Operand[0]));
919                         Status = AE_AML_UNINITIALIZED_ELEMENT;
920                         goto Cleanup;
921                     }
922
923                     AcpiUtAddReference (ReturnDesc);
924                     break;
925
926
927                 default:
928
929                     ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown Index TargetType %X in obj %p\n",
930                         Operand[0]->Reference.TargetType, Operand[0]));
931                     Status = AE_AML_OPERAND_TYPE;
932                     goto Cleanup;
933                 }
934                 break;
935
936
937             case AML_REF_OF_OP:
938
939                 ReturnDesc = Operand[0]->Reference.Object;
940
941                 if (ACPI_GET_DESCRIPTOR_TYPE (ReturnDesc) == ACPI_DESC_TYPE_NAMED)
942                 {
943
944                     ReturnDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) ReturnDesc);
945                 }
946
947                 /* Add another reference to the object! */
948
949                 AcpiUtAddReference (ReturnDesc);
950                 break;
951
952
953             default:
954                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown opcode in ref(%p) - %X\n",
955                     Operand[0], Operand[0]->Reference.Opcode));
956
957                 Status = AE_TYPE;
958                 goto Cleanup;
959             }
960         }
961         break;
962
963
964     default:
965
966         ACPI_REPORT_ERROR (("AcpiExOpcode_1A_0T_1R: Unknown opcode %X\n",
967             WalkState->Opcode));
968         Status = AE_AML_BAD_OPCODE;
969         goto Cleanup;
970     }
971
972
973 Cleanup:
974
975     /* Delete return object on error */
976
977     if (ACPI_FAILURE (Status))
978     {
979         AcpiUtRemoveReference (ReturnDesc);
980     }
981
982     WalkState->ResultObj = ReturnDesc;
983     return_ACPI_STATUS (Status);
984 }
985