]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/dev/acpica/exoparg1.c
This commit was generated by cvs2svn to compensate for changes in r156952,
[FreeBSD/FreeBSD.git] / sys / contrib / dev / acpica / exoparg1.c
1
2 /******************************************************************************
3  *
4  * Module Name: exoparg1 - AML execution - opcodes with 1 argument
5  *              $Revision: 1.172 $
6  *
7  *****************************************************************************/
8
9 /******************************************************************************
10  *
11  * 1. Copyright Notice
12  *
13  * Some or all of this work - Copyright (c) 1999 - 2005, 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
118 #define __EXOPARG1_C__
119
120 #include <contrib/dev/acpica/acpi.h>
121 #include <contrib/dev/acpica/acparser.h>
122 #include <contrib/dev/acpica/acdispat.h>
123 #include <contrib/dev/acpica/acinterp.h>
124 #include <contrib/dev/acpica/amlcode.h>
125 #include <contrib/dev/acpica/acnamesp.h>
126
127
128 #define _COMPONENT          ACPI_EXECUTER
129         ACPI_MODULE_NAME    ("exoparg1")
130
131
132 /*!
133  * Naming convention for AML interpreter execution routines.
134  *
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:
138  *
139  *      AcpiExOpcode_xA_yT_zR
140  *
141  * Where:
142  *
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).
149  *
150  * The AcpiExOpcode* functions are called via the Dispatcher component with
151  * fully resolved operands.
152 !*/
153
154 /*******************************************************************************
155  *
156  * FUNCTION:    AcpiExOpcode_0A_0T_1R
157  *
158  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
159  *
160  * RETURN:      Status
161  *
162  * DESCRIPTION: Execute operator with no operands, one return value
163  *
164  ******************************************************************************/
165
166 ACPI_STATUS
167 AcpiExOpcode_0A_0T_1R (
168     ACPI_WALK_STATE         *WalkState)
169 {
170     ACPI_STATUS             Status = AE_OK;
171     ACPI_OPERAND_OBJECT     *ReturnDesc = NULL;
172
173
174     ACPI_FUNCTION_TRACE_STR ("ExOpcode_0A_0T_1R",
175         AcpiPsGetOpcodeName (WalkState->Opcode));
176
177
178     /* Examine the AML opcode */
179
180     switch (WalkState->Opcode)
181     {
182     case AML_TIMER_OP:      /*  Timer () */
183
184         /* Create a return object of type Integer */
185
186         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
187         if (!ReturnDesc)
188         {
189             Status = AE_NO_MEMORY;
190             goto Cleanup;
191         }
192 #if ACPI_MACHINE_WIDTH != 16
193         ReturnDesc->Integer.Value = AcpiOsGetTimer ();
194 #endif
195         break;
196
197     default:                /*  Unknown opcode  */
198
199         ACPI_REPORT_ERROR (("AcpiExOpcode_0A_0T_1R: Unknown opcode %X\n",
200             WalkState->Opcode));
201         Status = AE_AML_BAD_OPCODE;
202         break;
203     }
204
205 Cleanup:
206
207     /* Delete return object on error */
208
209     if ((ACPI_FAILURE (Status)) || WalkState->ResultObj)
210     {
211         AcpiUtRemoveReference (ReturnDesc);
212     }
213     else
214     {
215         /* Save the return value */
216
217         WalkState->ResultObj = ReturnDesc;
218     }
219
220     return_ACPI_STATUS (Status);
221 }
222
223
224 /*******************************************************************************
225  *
226  * FUNCTION:    AcpiExOpcode_1A_0T_0R
227  *
228  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
229  *
230  * RETURN:      Status
231  *
232  * DESCRIPTION: Execute Type 1 monadic operator with numeric operand on
233  *              object stack
234  *
235  ******************************************************************************/
236
237 ACPI_STATUS
238 AcpiExOpcode_1A_0T_0R (
239     ACPI_WALK_STATE         *WalkState)
240 {
241     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
242     ACPI_STATUS             Status = AE_OK;
243
244
245     ACPI_FUNCTION_TRACE_STR ("ExOpcode_1A_0T_0R",
246         AcpiPsGetOpcodeName (WalkState->Opcode));
247
248
249     /* Examine the AML opcode */
250
251     switch (WalkState->Opcode)
252     {
253     case AML_RELEASE_OP:    /*  Release (MutexObject) */
254
255         Status = AcpiExReleaseMutex (Operand[0], WalkState);
256         break;
257
258
259     case AML_RESET_OP:      /*  Reset (EventObject) */
260
261         Status = AcpiExSystemResetEvent (Operand[0]);
262         break;
263
264
265     case AML_SIGNAL_OP:     /*  Signal (EventObject) */
266
267         Status = AcpiExSystemSignalEvent (Operand[0]);
268         break;
269
270
271     case AML_SLEEP_OP:      /*  Sleep (MsecTime) */
272
273         Status = AcpiExSystemDoSuspend (Operand[0]->Integer.Value);
274         break;
275
276
277     case AML_STALL_OP:      /*  Stall (UsecTime) */
278
279         Status = AcpiExSystemDoStall ((UINT32) Operand[0]->Integer.Value);
280         break;
281
282
283     case AML_UNLOAD_OP:     /*  Unload (Handle) */
284
285         Status = AcpiExUnloadTable (Operand[0]);
286         break;
287
288
289     default:                /*  Unknown opcode  */
290
291         ACPI_REPORT_ERROR (("AcpiExOpcode_1A_0T_0R: Unknown opcode %X\n",
292             WalkState->Opcode));
293         Status = AE_AML_BAD_OPCODE;
294         break;
295     }
296
297     return_ACPI_STATUS (Status);
298 }
299
300
301 /*******************************************************************************
302  *
303  * FUNCTION:    AcpiExOpcode_1A_1T_0R
304  *
305  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
306  *
307  * RETURN:      Status
308  *
309  * DESCRIPTION: Execute opcode with one argument, one target, and no
310  *              return value.
311  *
312  ******************************************************************************/
313
314 ACPI_STATUS
315 AcpiExOpcode_1A_1T_0R (
316     ACPI_WALK_STATE         *WalkState)
317 {
318     ACPI_STATUS             Status = AE_OK;
319     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
320
321
322     ACPI_FUNCTION_TRACE_STR ("ExOpcode_1A_1T_0R",
323         AcpiPsGetOpcodeName (WalkState->Opcode));
324
325
326     /* Examine the AML opcode */
327
328     switch (WalkState->Opcode)
329     {
330     case AML_LOAD_OP:
331
332         Status = AcpiExLoadOp (Operand[0], Operand[1], WalkState);
333         break;
334
335     default:                        /* Unknown opcode */
336
337         ACPI_REPORT_ERROR (("AcpiExOpcode_1A_1T_0R: Unknown opcode %X\n",
338             WalkState->Opcode));
339         Status = AE_AML_BAD_OPCODE;
340         goto Cleanup;
341     }
342
343
344 Cleanup:
345
346     return_ACPI_STATUS (Status);
347 }
348
349
350 /*******************************************************************************
351  *
352  * FUNCTION:    AcpiExOpcode_1A_1T_1R
353  *
354  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
355  *
356  * RETURN:      Status
357  *
358  * DESCRIPTION: Execute opcode with one argument, one target, and a
359  *              return value.
360  *
361  ******************************************************************************/
362
363 ACPI_STATUS
364 AcpiExOpcode_1A_1T_1R (
365     ACPI_WALK_STATE         *WalkState)
366 {
367     ACPI_STATUS             Status = AE_OK;
368     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
369     ACPI_OPERAND_OBJECT     *ReturnDesc = NULL;
370     ACPI_OPERAND_OBJECT     *ReturnDesc2 = NULL;
371     UINT32                  Temp32;
372     UINT32                  i;
373     ACPI_INTEGER            PowerOfTen;
374     ACPI_INTEGER            Digit;
375
376
377     ACPI_FUNCTION_TRACE_STR ("ExOpcode_1A_1T_1R",
378         AcpiPsGetOpcodeName (WalkState->Opcode));
379
380
381     /* Examine the AML opcode */
382
383     switch (WalkState->Opcode)
384     {
385     case AML_BIT_NOT_OP:
386     case AML_FIND_SET_LEFT_BIT_OP:
387     case AML_FIND_SET_RIGHT_BIT_OP:
388     case AML_FROM_BCD_OP:
389     case AML_TO_BCD_OP:
390     case AML_COND_REF_OF_OP:
391
392         /* Create a return object of type Integer for these opcodes */
393
394         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
395         if (!ReturnDesc)
396         {
397             Status = AE_NO_MEMORY;
398             goto Cleanup;
399         }
400
401         switch (WalkState->Opcode)
402         {
403         case AML_BIT_NOT_OP:            /* Not (Operand, Result)  */
404
405             ReturnDesc->Integer.Value = ~Operand[0]->Integer.Value;
406             break;
407
408
409         case AML_FIND_SET_LEFT_BIT_OP:  /* FindSetLeftBit (Operand, Result) */
410
411             ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
412
413             /*
414              * Acpi specification describes Integer type as a little
415              * endian unsigned value, so this boundary condition is valid.
416              */
417             for (Temp32 = 0; ReturnDesc->Integer.Value &&
418                              Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
419             {
420                 ReturnDesc->Integer.Value >>= 1;
421             }
422
423             ReturnDesc->Integer.Value = Temp32;
424             break;
425
426
427         case AML_FIND_SET_RIGHT_BIT_OP: /* FindSetRightBit (Operand, Result) */
428
429             ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
430
431             /*
432              * The Acpi specification describes Integer type as a little
433              * endian unsigned value, so this boundary condition is valid.
434              */
435             for (Temp32 = 0; ReturnDesc->Integer.Value &&
436                              Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
437             {
438                 ReturnDesc->Integer.Value <<= 1;
439             }
440
441             /* Since the bit position is one-based, subtract from 33 (65) */
442
443             ReturnDesc->Integer.Value = Temp32 == 0 ? 0 :
444                                         (ACPI_INTEGER_BIT_SIZE + 1) - Temp32;
445             break;
446
447
448         case AML_FROM_BCD_OP:           /* FromBcd (BCDValue, Result)  */
449
450             /*
451              * The 64-bit ACPI integer can hold 16 4-bit BCD characters
452              * (if table is 32-bit, integer can hold 8 BCD characters)
453              * Convert each 4-bit BCD value
454              */
455             PowerOfTen = 1;
456             ReturnDesc->Integer.Value = 0;
457             Digit = Operand[0]->Integer.Value;
458
459             /* Convert each BCD digit (each is one nybble wide) */
460
461             for (i = 0; (i < AcpiGbl_IntegerNybbleWidth) && (Digit > 0); i++)
462             {
463                 /* Get the least significant 4-bit BCD digit */
464
465                 Temp32 = ((UINT32) Digit) & 0xF;
466
467                 /* Check the range of the digit */
468
469                 if (Temp32 > 9)
470                 {
471                     ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
472                         "BCD digit too large (not decimal): 0x%X\n",
473                         Temp32));
474
475                     Status = AE_AML_NUMERIC_OVERFLOW;
476                     goto Cleanup;
477                 }
478
479                 /* Sum the digit into the result with the current power of 10 */
480
481                 ReturnDesc->Integer.Value += (((ACPI_INTEGER) Temp32) *
482                                               PowerOfTen);
483
484                 /* Shift to next BCD digit */
485
486                 Digit >>= 4;
487
488                 /* Next power of 10 */
489
490                 PowerOfTen *= 10;
491             }
492             break;
493
494
495         case AML_TO_BCD_OP:             /* ToBcd (Operand, Result)  */
496
497             ReturnDesc->Integer.Value = 0;
498             Digit = Operand[0]->Integer.Value;
499
500             /* Each BCD digit is one nybble wide */
501
502             for (i = 0; (i < AcpiGbl_IntegerNybbleWidth) && (Digit > 0); i++)
503             {
504                 (void) AcpiUtShortDivide (Digit, 10, &Digit, &Temp32);
505
506                 /*
507                  * Insert the BCD digit that resides in the
508                  * remainder from above
509                  */
510                 ReturnDesc->Integer.Value |= (((ACPI_INTEGER) Temp32) <<
511                                                 ACPI_MUL_4 (i));
512             }
513
514             /* Overflow if there is any data left in Digit */
515
516             if (Digit > 0)
517             {
518                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
519                     "Integer too large to convert to BCD: %8.8X%8.8X\n",
520                     ACPI_FORMAT_UINT64 (Operand[0]->Integer.Value)));
521                 Status = AE_AML_NUMERIC_OVERFLOW;
522                 goto Cleanup;
523             }
524             break;
525
526
527         case AML_COND_REF_OF_OP:        /* CondRefOf (SourceObject, Result)  */
528
529             /*
530              * This op is a little strange because the internal return value is
531              * different than the return value stored in the result descriptor
532              * (There are really two return values)
533              */
534             if ((ACPI_NAMESPACE_NODE *) Operand[0] == AcpiGbl_RootNode)
535             {
536                 /*
537                  * This means that the object does not exist in the namespace,
538                  * return FALSE
539                  */
540                 ReturnDesc->Integer.Value = 0;
541                 goto Cleanup;
542             }
543
544             /* Get the object reference, store it, and remove our reference */
545
546             Status = AcpiExGetObjectReference (Operand[0],
547                         &ReturnDesc2, WalkState);
548             if (ACPI_FAILURE (Status))
549             {
550                 goto Cleanup;
551             }
552
553             Status = AcpiExStore (ReturnDesc2, Operand[1], WalkState);
554             AcpiUtRemoveReference (ReturnDesc2);
555
556             /* The object exists in the namespace, return TRUE */
557
558             ReturnDesc->Integer.Value = ACPI_INTEGER_MAX;
559             goto Cleanup;
560
561
562         default:
563             /* No other opcodes get here */
564             break;
565         }
566         break;
567
568
569     case AML_STORE_OP:              /* Store (Source, Target) */
570
571         /*
572          * A store operand is typically a number, string, buffer or lvalue
573          * Be careful about deleting the source object,
574          * since the object itself may have been stored.
575          */
576         Status = AcpiExStore (Operand[0], Operand[1], WalkState);
577         if (ACPI_FAILURE (Status))
578         {
579             return_ACPI_STATUS (Status);
580         }
581
582         /* It is possible that the Store already produced a return object */
583
584         if (!WalkState->ResultObj)
585         {
586             /*
587              * Normally, we would remove a reference on the Operand[0]
588              * parameter; But since it is being used as the internal return
589              * object (meaning we would normally increment it), the two
590              * cancel out, and we simply don't do anything.
591              */
592             WalkState->ResultObj = Operand[0];
593             WalkState->Operands[0] = NULL;  /* Prevent deletion */
594         }
595         return_ACPI_STATUS (Status);
596
597
598     /*
599      * ACPI 2.0 Opcodes
600      */
601     case AML_COPY_OP:               /* Copy (Source, Target) */
602
603         Status = AcpiUtCopyIobjectToIobject (Operand[0], &ReturnDesc,
604                     WalkState);
605         break;
606
607
608     case AML_TO_DECSTRING_OP:       /* ToDecimalString (Data, Result) */
609
610         Status = AcpiExConvertToString (Operand[0], &ReturnDesc,
611                     ACPI_EXPLICIT_CONVERT_DECIMAL);
612         if (ReturnDesc == Operand[0])
613         {
614             /* No conversion performed, add ref to handle return value */
615             AcpiUtAddReference (ReturnDesc);
616         }
617         break;
618
619
620     case AML_TO_HEXSTRING_OP:       /* ToHexString (Data, Result) */
621
622         Status = AcpiExConvertToString (Operand[0], &ReturnDesc,
623                     ACPI_EXPLICIT_CONVERT_HEX);
624         if (ReturnDesc == Operand[0])
625         {
626             /* No conversion performed, add ref to handle return value */
627             AcpiUtAddReference (ReturnDesc);
628         }
629         break;
630
631
632     case AML_TO_BUFFER_OP:          /* ToBuffer (Data, Result) */
633
634         Status = AcpiExConvertToBuffer (Operand[0], &ReturnDesc);
635         if (ReturnDesc == Operand[0])
636         {
637             /* No conversion performed, add ref to handle return value */
638             AcpiUtAddReference (ReturnDesc);
639         }
640         break;
641
642
643     case AML_TO_INTEGER_OP:         /* ToInteger (Data, Result) */
644
645         Status = AcpiExConvertToInteger (Operand[0], &ReturnDesc,
646                     ACPI_ANY_BASE);
647         if (ReturnDesc == Operand[0])
648         {
649             /* No conversion performed, add ref to handle return value */
650             AcpiUtAddReference (ReturnDesc);
651         }
652         break;
653
654
655     case AML_SHIFT_LEFT_BIT_OP:     /* ShiftLeftBit (Source, BitNum)  */
656     case AML_SHIFT_RIGHT_BIT_OP:    /* ShiftRightBit (Source, BitNum) */
657
658         /* These are two obsolete opcodes */
659
660         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
661             "%s is obsolete and not implemented\n",
662             AcpiPsGetOpcodeName (WalkState->Opcode)));
663         Status = AE_SUPPORT;
664         goto Cleanup;
665
666
667     default:                        /* Unknown opcode */
668
669         ACPI_REPORT_ERROR (("AcpiExOpcode_1A_1T_1R: Unknown opcode %X\n",
670             WalkState->Opcode));
671         Status = AE_AML_BAD_OPCODE;
672         goto Cleanup;
673     }
674
675     if (ACPI_SUCCESS (Status))
676     {
677         /* Store the return value computed above into the target object */
678
679         Status = AcpiExStore (ReturnDesc, Operand[1], WalkState);
680     }
681
682
683 Cleanup:
684
685     if (!WalkState->ResultObj)
686     {
687         WalkState->ResultObj = ReturnDesc;
688     }
689
690     /* Delete return object on error */
691
692     if (ACPI_FAILURE (Status))
693     {
694         AcpiUtRemoveReference (ReturnDesc);
695     }
696
697     return_ACPI_STATUS (Status);
698 }
699
700
701 /*******************************************************************************
702  *
703  * FUNCTION:    AcpiExOpcode_1A_0T_1R
704  *
705  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
706  *
707  * RETURN:      Status
708  *
709  * DESCRIPTION: Execute opcode with one argument, no target, and a return value
710  *
711  ******************************************************************************/
712
713 ACPI_STATUS
714 AcpiExOpcode_1A_0T_1R (
715     ACPI_WALK_STATE         *WalkState)
716 {
717     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
718     ACPI_OPERAND_OBJECT     *TempDesc;
719     ACPI_OPERAND_OBJECT     *ReturnDesc = NULL;
720     ACPI_STATUS             Status = AE_OK;
721     UINT32                  Type;
722     ACPI_INTEGER            Value;
723
724
725     ACPI_FUNCTION_TRACE_STR ("ExOpcode_1A_0T_1R",
726         AcpiPsGetOpcodeName (WalkState->Opcode));
727
728
729     /* Examine the AML opcode */
730
731     switch (WalkState->Opcode)
732     {
733     case AML_LNOT_OP:               /* LNot (Operand) */
734
735         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
736         if (!ReturnDesc)
737         {
738             Status = AE_NO_MEMORY;
739             goto Cleanup;
740         }
741
742         /*
743          * Set result to ONES (TRUE) if Value == 0.  Note:
744          * ReturnDesc->Integer.Value is initially == 0 (FALSE) from above.
745          */
746         if (!Operand[0]->Integer.Value)
747         {
748             ReturnDesc->Integer.Value = ACPI_INTEGER_MAX;
749         }
750         break;
751
752
753     case AML_DECREMENT_OP:          /* Decrement (Operand)  */
754     case AML_INCREMENT_OP:          /* Increment (Operand)  */
755
756         /*
757          * Create a new integer.  Can't just get the base integer and
758          * increment it because it may be an Arg or Field.
759          */
760         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
761         if (!ReturnDesc)
762         {
763             Status = AE_NO_MEMORY;
764             goto Cleanup;
765         }
766
767         /*
768          * Since we are expecting a Reference operand, it can be either a
769          * NS Node or an internal object.
770          */
771         TempDesc = Operand[0];
772         if (ACPI_GET_DESCRIPTOR_TYPE (TempDesc) == ACPI_DESC_TYPE_OPERAND)
773         {
774             /* Internal reference object - prevent deletion */
775
776             AcpiUtAddReference (TempDesc);
777         }
778
779         /*
780          * Convert the Reference operand to an Integer (This removes a
781          * reference on the Operand[0] object)
782          *
783          * NOTE:  We use LNOT_OP here in order to force resolution of the
784          * reference operand to an actual integer.
785          */
786         Status = AcpiExResolveOperands (AML_LNOT_OP, &TempDesc, WalkState);
787         if (ACPI_FAILURE (Status))
788         {
789             ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%s: bad operand(s) %s\n",
790                 AcpiPsGetOpcodeName (WalkState->Opcode),
791                 AcpiFormatException(Status)));
792
793             goto Cleanup;
794         }
795
796         /*
797          * TempDesc is now guaranteed to be an Integer object --
798          * Perform the actual increment or decrement
799          */
800         if (WalkState->Opcode == AML_INCREMENT_OP)
801         {
802             ReturnDesc->Integer.Value = TempDesc->Integer.Value +1;
803         }
804         else
805         {
806             ReturnDesc->Integer.Value = TempDesc->Integer.Value -1;
807         }
808
809         /* Finished with this Integer object */
810
811         AcpiUtRemoveReference (TempDesc);
812
813         /*
814          * Store the result back (indirectly) through the original
815          * Reference object
816          */
817         Status = AcpiExStore (ReturnDesc, Operand[0], WalkState);
818         break;
819
820
821     case AML_TYPE_OP:               /* ObjectType (SourceObject) */
822
823         /*
824          * Note: The operand is not resolved at this point because we want to
825          * get the associated object, not its value.  For example, we don't
826          * want to resolve a FieldUnit to its value, we want the actual
827          * FieldUnit object.
828          */
829
830         /* Get the type of the base object */
831
832         Status = AcpiExResolveMultiple (WalkState, Operand[0], &Type, NULL);
833         if (ACPI_FAILURE (Status))
834         {
835             goto Cleanup;
836         }
837         /* Allocate a descriptor to hold the type. */
838
839         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
840         if (!ReturnDesc)
841         {
842             Status = AE_NO_MEMORY;
843             goto Cleanup;
844         }
845
846         ReturnDesc->Integer.Value = Type;
847         break;
848
849
850     case AML_SIZE_OF_OP:            /* SizeOf (SourceObject)  */
851
852         /*
853          * Note: The operand is not resolved at this point because we want to
854          * get the associated object, not its value.
855          */
856
857         /* Get the base object */
858
859         Status = AcpiExResolveMultiple (WalkState,
860                     Operand[0], &Type, &TempDesc);
861         if (ACPI_FAILURE (Status))
862         {
863             goto Cleanup;
864         }
865
866         /*
867          * The type of the base object must be integer, buffer, string, or
868          * package.  All others are not supported.
869          *
870          * NOTE: Integer is not specifically supported by the ACPI spec,
871          * but is supported implicitly via implicit operand conversion.
872          * rather than bother with conversion, we just use the byte width
873          * global (4 or 8 bytes).
874          */
875         switch (Type)
876         {
877         case ACPI_TYPE_INTEGER:
878             Value = AcpiGbl_IntegerByteWidth;
879             break;
880
881         case ACPI_TYPE_BUFFER:
882             Value = TempDesc->Buffer.Length;
883             break;
884
885         case ACPI_TYPE_STRING:
886             Value = TempDesc->String.Length;
887             break;
888
889         case ACPI_TYPE_PACKAGE:
890             Value = TempDesc->Package.Count;
891             break;
892
893         default:
894             ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
895                 "SizeOf - Operand is not Buf/Int/Str/Pkg - found type %s\n",
896                 AcpiUtGetTypeName (Type)));
897             Status = AE_AML_OPERAND_TYPE;
898             goto Cleanup;
899         }
900
901         /*
902          * Now that we have the size of the object, create a result
903          * object to hold the value
904          */
905         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
906         if (!ReturnDesc)
907         {
908             Status = AE_NO_MEMORY;
909             goto Cleanup;
910         }
911
912         ReturnDesc->Integer.Value = Value;
913         break;
914
915
916     case AML_REF_OF_OP:             /* RefOf (SourceObject) */
917
918         Status = AcpiExGetObjectReference (Operand[0], &ReturnDesc, WalkState);
919         if (ACPI_FAILURE (Status))
920         {
921             goto Cleanup;
922         }
923         break;
924
925
926     case AML_DEREF_OF_OP:           /* DerefOf (ObjReference | String) */
927
928         /* Check for a method local or argument, or standalone String */
929
930         if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) != ACPI_DESC_TYPE_NAMED)
931         {
932             switch (ACPI_GET_OBJECT_TYPE (Operand[0]))
933             {
934             case ACPI_TYPE_LOCAL_REFERENCE:
935                 /*
936                  * This is a DerefOf (LocalX | ArgX)
937                  *
938                  * Must resolve/dereference the local/arg reference first
939                  */
940                 switch (Operand[0]->Reference.Opcode)
941                 {
942                 case AML_LOCAL_OP:
943                 case AML_ARG_OP:
944
945                     /* Set Operand[0] to the value of the local/arg */
946
947                     Status = AcpiDsMethodDataGetValue (
948                                 Operand[0]->Reference.Opcode,
949                                 Operand[0]->Reference.Offset,
950                                 WalkState, &TempDesc);
951                     if (ACPI_FAILURE (Status))
952                     {
953                         goto Cleanup;
954                     }
955
956                     /*
957                      * Delete our reference to the input object and
958                      * point to the object just retrieved
959                      */
960                     AcpiUtRemoveReference (Operand[0]);
961                     Operand[0] = TempDesc;
962                     break;
963
964                 case AML_REF_OF_OP:
965
966                     /* Get the object to which the reference refers */
967
968                     TempDesc = Operand[0]->Reference.Object;
969                     AcpiUtRemoveReference (Operand[0]);
970                     Operand[0] = TempDesc;
971                     break;
972
973                 default:
974
975                     /* Must be an Index op - handled below */
976                     break;
977                 }
978                 break;
979
980
981             case ACPI_TYPE_STRING:
982
983                 /*
984                  * This is a DerefOf (String).  The string is a reference
985                  * to a named ACPI object.
986                  *
987                  * 1) Find the owning Node
988                  * 2) Dereference the node to an actual object.  Could be a
989                  *    Field, so we need to resolve the node to a value.
990                  */
991                 Status = AcpiNsGetNodeByPath (Operand[0]->String.Pointer,
992                             WalkState->ScopeInfo->Scope.Node,
993                             ACPI_NS_SEARCH_PARENT,
994                             ACPI_CAST_INDIRECT_PTR (
995                                 ACPI_NAMESPACE_NODE, &ReturnDesc));
996                 if (ACPI_FAILURE (Status))
997                 {
998                     goto Cleanup;
999                 }
1000
1001                 Status = AcpiExResolveNodeToValue (
1002                                 ACPI_CAST_INDIRECT_PTR (
1003                                     ACPI_NAMESPACE_NODE, &ReturnDesc),
1004                                 WalkState);
1005                 goto Cleanup;
1006
1007
1008             default:
1009
1010                 Status = AE_AML_OPERAND_TYPE;
1011                 goto Cleanup;
1012             }
1013         }
1014
1015         /* Operand[0] may have changed from the code above */
1016
1017         if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_NAMED)
1018         {
1019             /*
1020              * This is a DerefOf (ObjectReference)
1021              * Get the actual object from the Node (This is the dereference).
1022              * This case may only happen when a LocalX or ArgX is
1023              * dereferenced above.
1024              */
1025             ReturnDesc = AcpiNsGetAttachedObject (
1026                             (ACPI_NAMESPACE_NODE *) Operand[0]);
1027             AcpiUtAddReference (ReturnDesc);
1028         }
1029         else
1030         {
1031             /*
1032              * This must be a reference object produced by either the
1033              * Index() or RefOf() operator
1034              */
1035             switch (Operand[0]->Reference.Opcode)
1036             {
1037             case AML_INDEX_OP:
1038
1039                 /*
1040                  * The target type for the Index operator must be
1041                  * either a Buffer or a Package
1042                  */
1043                 switch (Operand[0]->Reference.TargetType)
1044                 {
1045                 case ACPI_TYPE_BUFFER_FIELD:
1046
1047                     TempDesc = Operand[0]->Reference.Object;
1048
1049                     /*
1050                      * Create a new object that contains one element of the
1051                      * buffer -- the element pointed to by the index.
1052                      *
1053                      * NOTE: index into a buffer is NOT a pointer to a
1054                      * sub-buffer of the main buffer, it is only a pointer to a
1055                      * single element (byte) of the buffer!
1056                      */
1057                     ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
1058                     if (!ReturnDesc)
1059                     {
1060                         Status = AE_NO_MEMORY;
1061                         goto Cleanup;
1062                     }
1063
1064                     /*
1065                      * Since we are returning the value of the buffer at the
1066                      * indexed location, we don't need to add an additional
1067                      * reference to the buffer itself.
1068                      */
1069                     ReturnDesc->Integer.Value =
1070                         TempDesc->Buffer.Pointer[Operand[0]->Reference.Offset];
1071                     break;
1072
1073
1074                 case ACPI_TYPE_PACKAGE:
1075
1076                     /*
1077                      * Return the referenced element of the package.  We must
1078                      * add another reference to the referenced object, however.
1079                      */
1080                     ReturnDesc = *(Operand[0]->Reference.Where);
1081                     if (ReturnDesc)
1082                     {
1083                         AcpiUtAddReference (ReturnDesc);
1084                     }
1085
1086                     break;
1087
1088
1089                 default:
1090
1091                     ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
1092                         "Unknown Index TargetType %X in obj %p\n",
1093                         Operand[0]->Reference.TargetType, Operand[0]));
1094                     Status = AE_AML_OPERAND_TYPE;
1095                     goto Cleanup;
1096                 }
1097                 break;
1098
1099
1100             case AML_REF_OF_OP:
1101
1102                 ReturnDesc = Operand[0]->Reference.Object;
1103
1104                 if (ACPI_GET_DESCRIPTOR_TYPE (ReturnDesc) ==
1105                         ACPI_DESC_TYPE_NAMED)
1106                 {
1107
1108                     ReturnDesc = AcpiNsGetAttachedObject (
1109                                     (ACPI_NAMESPACE_NODE *) ReturnDesc);
1110                 }
1111
1112                 /* Add another reference to the object! */
1113
1114                 AcpiUtAddReference (ReturnDesc);
1115                 break;
1116
1117
1118             default:
1119                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
1120                     "Unknown opcode in ref(%p) - %X\n",
1121                     Operand[0], Operand[0]->Reference.Opcode));
1122
1123                 Status = AE_TYPE;
1124                 goto Cleanup;
1125             }
1126         }
1127         break;
1128
1129
1130     default:
1131
1132         ACPI_REPORT_ERROR (("AcpiExOpcode_1A_0T_1R: Unknown opcode %X\n",
1133             WalkState->Opcode));
1134         Status = AE_AML_BAD_OPCODE;
1135         goto Cleanup;
1136     }
1137
1138
1139 Cleanup:
1140
1141     /* Delete return object on error */
1142
1143     if (ACPI_FAILURE (Status))
1144     {
1145         AcpiUtRemoveReference (ReturnDesc);
1146     }
1147
1148     WalkState->ResultObj = ReturnDesc;
1149     return_ACPI_STATUS (Status);
1150 }
1151