2 /******************************************************************************
4 * Module Name: exmisc - ACPI AML (p-code) execution - specific opcodes
7 *****************************************************************************/
9 /******************************************************************************
13 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
14 * All rights reserved.
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
39 * The above copyright and patent license is granted only if the following
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
74 * 3.4. Intel retains all right, title, and interest in and to the Original
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
82 * 4. Disclaimer and Export Compliance
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
89 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
90 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
93 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
94 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
95 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
96 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
97 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
98 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
99 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
102 * 4.3. Licensee shall not export, either directly or indirectly, any of this
103 * software or system incorporating such software without first obtaining any
104 * required license or other approval from the U. S. Department of Commerce or
105 * any other agency or department of the United States Government. In the
106 * event Licensee exports any such software from the United States or
107 * re-exports any such software from a foreign destination, Licensee shall
108 * ensure that the distribution and export/re-export of the software is in
109 * compliance with all laws, regulations, orders, or other restrictions of the
110 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
111 * any of its subsidiaries will export/re-export any technical data, process,
112 * software, or service, directly or indirectly, to any country for which the
113 * United States government or any agency thereof requires an export license,
114 * other governmental approval, or letter of assurance, without first obtaining
115 * such license, approval or letter.
117 *****************************************************************************/
122 #include "acinterp.h"
126 #define _COMPONENT ACPI_EXECUTER
127 ACPI_MODULE_NAME ("exmisc")
130 /*******************************************************************************
132 * FUNCTION: AcpiExGetObjectReference
134 * PARAMETERS: ObjDesc - Create a reference to this object
135 * ReturnDesc - Where to store the reference
136 * WalkState - Current state
140 * DESCRIPTION: Obtain and return a "reference" to the target object
141 * Common code for the RefOfOp and the CondRefOfOp.
143 ******************************************************************************/
146 AcpiExGetObjectReference (
147 ACPI_OPERAND_OBJECT *ObjDesc,
148 ACPI_OPERAND_OBJECT **ReturnDesc,
149 ACPI_WALK_STATE *WalkState)
151 ACPI_OPERAND_OBJECT *ReferenceObj;
152 ACPI_OPERAND_OBJECT *ReferencedObj;
155 ACPI_FUNCTION_TRACE_PTR ("ExGetObjectReference", ObjDesc);
160 switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
162 case ACPI_DESC_TYPE_OPERAND:
164 if (ACPI_GET_OBJECT_TYPE (ObjDesc) != ACPI_TYPE_LOCAL_REFERENCE)
166 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
170 * Must be a reference to a Local or Arg
172 switch (ObjDesc->Reference.Opcode)
177 /* The referenced object is the pseudo-node for the local/arg */
179 ReferencedObj = ObjDesc->Reference.Object;
184 ACPI_REPORT_ERROR (("Unknown Reference subtype in get ref %X\n",
185 ObjDesc->Reference.Opcode));
186 return_ACPI_STATUS (AE_AML_INTERNAL);
191 case ACPI_DESC_TYPE_NAMED:
194 * A named reference that has already been resolved to a Node
196 ReferencedObj = ObjDesc;
202 ACPI_REPORT_ERROR (("Invalid descriptor type in get ref: %X\n",
203 ACPI_GET_DESCRIPTOR_TYPE (ObjDesc)));
204 return_ACPI_STATUS (AE_TYPE);
208 /* Create a new reference object */
210 ReferenceObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
213 return_ACPI_STATUS (AE_NO_MEMORY);
216 ReferenceObj->Reference.Opcode = AML_REF_OF_OP;
217 ReferenceObj->Reference.Object = ReferencedObj;
218 *ReturnDesc = ReferenceObj;
220 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Object %p Type [%s], returning Reference %p\n",
221 ObjDesc, AcpiUtGetObjectTypeName (ObjDesc), *ReturnDesc));
223 return_ACPI_STATUS (AE_OK);
227 /*******************************************************************************
229 * FUNCTION: AcpiExConcatTemplate
231 * PARAMETERS: Operand0 - First source object
232 * Operand1 - Second source object
233 * ActualReturnDesc - Where to place the return object
234 * WalkState - Current walk state
238 * DESCRIPTION: Concatenate two resource templates
240 ******************************************************************************/
243 AcpiExConcatTemplate (
244 ACPI_OPERAND_OBJECT *Operand0,
245 ACPI_OPERAND_OBJECT *Operand1,
246 ACPI_OPERAND_OBJECT **ActualReturnDesc,
247 ACPI_WALK_STATE *WalkState)
249 ACPI_OPERAND_OBJECT *ReturnDesc;
257 ACPI_FUNCTION_TRACE ("ExConcatTemplate");
260 /* Find the EndTags in each resource template */
262 EndTag1 = AcpiUtGetResourceEndTag (Operand0);
263 EndTag2 = AcpiUtGetResourceEndTag (Operand1);
264 if (!EndTag1 || !EndTag2)
266 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
269 /* Compute the length of each part */
271 Length1 = ACPI_PTR_DIFF (EndTag1, Operand0->Buffer.Pointer);
272 Length2 = ACPI_PTR_DIFF (EndTag2, Operand1->Buffer.Pointer) +
273 2; /* Size of END_TAG */
275 /* Create a new buffer object for the result */
277 ReturnDesc = AcpiUtCreateBufferObject (Length1 + Length2);
280 return_ACPI_STATUS (AE_NO_MEMORY);
283 /* Copy the templates to the new descriptor */
285 NewBuf = ReturnDesc->Buffer.Pointer;
286 ACPI_MEMCPY (NewBuf, Operand0->Buffer.Pointer, Length1);
287 ACPI_MEMCPY (NewBuf + Length1, Operand1->Buffer.Pointer, Length2);
289 /* Compute the new checksum */
291 NewBuf[ReturnDesc->Buffer.Length - 1] =
292 AcpiUtGenerateChecksum (ReturnDesc->Buffer.Pointer,
293 (ReturnDesc->Buffer.Length - 1));
295 /* Return the completed template descriptor */
297 *ActualReturnDesc = ReturnDesc;
298 return_ACPI_STATUS (AE_OK);
302 /*******************************************************************************
304 * FUNCTION: AcpiExDoConcatenate
306 * PARAMETERS: Operand0 - First source object
307 * Operand1 - Second source object
308 * ActualReturnDesc - Where to place the return object
309 * WalkState - Current walk state
313 * DESCRIPTION: Concatenate two objects OF THE SAME TYPE.
315 ******************************************************************************/
318 AcpiExDoConcatenate (
319 ACPI_OPERAND_OBJECT *Operand0,
320 ACPI_OPERAND_OBJECT *Operand1,
321 ACPI_OPERAND_OBJECT **ActualReturnDesc,
322 ACPI_WALK_STATE *WalkState)
324 ACPI_OPERAND_OBJECT *LocalOperand1 = Operand1;
325 ACPI_OPERAND_OBJECT *ReturnDesc;
331 ACPI_FUNCTION_TRACE ("ExDoConcatenate");
335 * Convert the second operand if necessary. The first operand
336 * determines the type of the second operand, (See the Data Types
337 * section of the ACPI specification.) Both object types are
338 * guaranteed to be either Integer/String/Buffer by the operand
339 * resolution mechanism.
341 switch (ACPI_GET_OBJECT_TYPE (Operand0))
343 case ACPI_TYPE_INTEGER:
344 Status = AcpiExConvertToInteger (Operand1, &LocalOperand1, 16);
347 case ACPI_TYPE_STRING:
348 Status = AcpiExConvertToString (Operand1, &LocalOperand1,
349 ACPI_IMPLICIT_CONVERT_HEX);
352 case ACPI_TYPE_BUFFER:
353 Status = AcpiExConvertToBuffer (Operand1, &LocalOperand1);
357 ACPI_REPORT_ERROR (("Concat - invalid obj type: %X\n",
358 ACPI_GET_OBJECT_TYPE (Operand0)));
359 Status = AE_AML_INTERNAL;
362 if (ACPI_FAILURE (Status))
368 * Both operands are now known to be the same object type
369 * (Both are Integer, String, or Buffer), and we can now perform the
374 * There are three cases to handle:
376 * 1) Two Integers concatenated to produce a new Buffer
377 * 2) Two Strings concatenated to produce a new String
378 * 3) Two Buffers concatenated to produce a new Buffer
380 switch (ACPI_GET_OBJECT_TYPE (Operand0))
382 case ACPI_TYPE_INTEGER:
384 /* Result of two Integers is a Buffer */
385 /* Need enough buffer space for two integers */
387 ReturnDesc = AcpiUtCreateBufferObject (
388 ACPI_MUL_2 (AcpiGbl_IntegerByteWidth));
391 Status = AE_NO_MEMORY;
395 NewBuf = (char *) ReturnDesc->Buffer.Pointer;
397 /* Copy the first integer, LSB first */
400 &Operand0->Integer.Value,
401 AcpiGbl_IntegerByteWidth);
403 /* Copy the second integer (LSB first) after the first */
405 ACPI_MEMCPY (NewBuf + AcpiGbl_IntegerByteWidth,
406 &LocalOperand1->Integer.Value,
407 AcpiGbl_IntegerByteWidth);
410 case ACPI_TYPE_STRING:
412 /* Result of two Strings is a String */
414 NewLength = (ACPI_SIZE) Operand0->String.Length +
415 (ACPI_SIZE) LocalOperand1->String.Length;
416 if (NewLength > ACPI_MAX_STRING_CONVERSION)
418 Status = AE_AML_STRING_LIMIT;
422 ReturnDesc = AcpiUtCreateStringObject (NewLength);
425 Status = AE_NO_MEMORY;
429 NewBuf = ReturnDesc->String.Pointer;
431 /* Concatenate the strings */
434 Operand0->String.Pointer);
435 ACPI_STRCPY (NewBuf + Operand0->String.Length,
436 LocalOperand1->String.Pointer);
439 case ACPI_TYPE_BUFFER:
441 /* Result of two Buffers is a Buffer */
443 ReturnDesc = AcpiUtCreateBufferObject (
444 (ACPI_SIZE) Operand0->Buffer.Length +
445 (ACPI_SIZE) LocalOperand1->Buffer.Length);
448 Status = AE_NO_MEMORY;
452 NewBuf = (char *) ReturnDesc->Buffer.Pointer;
454 /* Concatenate the buffers */
457 Operand0->Buffer.Pointer,
458 Operand0->Buffer.Length);
459 ACPI_MEMCPY (NewBuf + Operand0->Buffer.Length,
460 LocalOperand1->Buffer.Pointer,
461 LocalOperand1->Buffer.Length);
466 /* Invalid object type, should not happen here */
468 ACPI_REPORT_ERROR (("Concatenate - Invalid object type: %X\n",
469 ACPI_GET_OBJECT_TYPE (Operand0)));
470 Status =AE_AML_INTERNAL;
474 *ActualReturnDesc = ReturnDesc;
477 if (LocalOperand1 != Operand1)
479 AcpiUtRemoveReference (LocalOperand1);
481 return_ACPI_STATUS (Status);
485 /*******************************************************************************
487 * FUNCTION: AcpiExDoMathOp
489 * PARAMETERS: Opcode - AML opcode
490 * Integer0 - Integer operand #0
491 * Integer1 - Integer operand #1
493 * RETURN: Integer result of the operation
495 * DESCRIPTION: Execute a math AML opcode. The purpose of having all of the
496 * math functions here is to prevent a lot of pointer dereferencing
497 * to obtain the operands.
499 ******************************************************************************/
504 ACPI_INTEGER Integer0,
505 ACPI_INTEGER Integer1)
508 ACPI_FUNCTION_ENTRY ();
513 case AML_ADD_OP: /* Add (Integer0, Integer1, Result) */
515 return (Integer0 + Integer1);
518 case AML_BIT_AND_OP: /* And (Integer0, Integer1, Result) */
520 return (Integer0 & Integer1);
523 case AML_BIT_NAND_OP: /* NAnd (Integer0, Integer1, Result) */
525 return (~(Integer0 & Integer1));
528 case AML_BIT_OR_OP: /* Or (Integer0, Integer1, Result) */
530 return (Integer0 | Integer1);
533 case AML_BIT_NOR_OP: /* NOr (Integer0, Integer1, Result) */
535 return (~(Integer0 | Integer1));
538 case AML_BIT_XOR_OP: /* XOr (Integer0, Integer1, Result) */
540 return (Integer0 ^ Integer1);
543 case AML_MULTIPLY_OP: /* Multiply (Integer0, Integer1, Result) */
545 return (Integer0 * Integer1);
548 case AML_SHIFT_LEFT_OP: /* ShiftLeft (Operand, ShiftCount, Result) */
550 return (Integer0 << Integer1);
553 case AML_SHIFT_RIGHT_OP: /* ShiftRight (Operand, ShiftCount, Result) */
555 return (Integer0 >> Integer1);
558 case AML_SUBTRACT_OP: /* Subtract (Integer0, Integer1, Result) */
560 return (Integer0 - Integer1);
569 /*******************************************************************************
571 * FUNCTION: AcpiExDoLogicalNumericOp
573 * PARAMETERS: Opcode - AML opcode
574 * Integer0 - Integer operand #0
575 * Integer1 - Integer operand #1
576 * LogicalResult - TRUE/FALSE result of the operation
580 * DESCRIPTION: Execute a logical "Numeric" AML opcode. For these Numeric
581 * operators (LAnd and LOr), both operands must be integers.
583 * Note: cleanest machine code seems to be produced by the code
584 * below, rather than using statements of the form:
585 * Result = (Integer0 && Integer1);
587 ******************************************************************************/
590 AcpiExDoLogicalNumericOp (
592 ACPI_INTEGER Integer0,
593 ACPI_INTEGER Integer1,
594 BOOLEAN *LogicalResult)
596 ACPI_STATUS Status = AE_OK;
597 BOOLEAN LocalResult = FALSE;
600 ACPI_FUNCTION_TRACE ("ExDoLogicalNumericOp");
605 case AML_LAND_OP: /* LAnd (Integer0, Integer1) */
607 if (Integer0 && Integer1)
613 case AML_LOR_OP: /* LOr (Integer0, Integer1) */
615 if (Integer0 || Integer1)
622 Status = AE_AML_INTERNAL;
626 /* Return the logical result and status */
628 *LogicalResult = LocalResult;
629 return_ACPI_STATUS (Status);
633 /*******************************************************************************
635 * FUNCTION: AcpiExDoLogicalOp
637 * PARAMETERS: Opcode - AML opcode
638 * Operand0 - operand #0
639 * Operand1 - operand #1
640 * LogicalResult - TRUE/FALSE result of the operation
644 * DESCRIPTION: Execute a logical AML opcode. The purpose of having all of the
645 * functions here is to prevent a lot of pointer dereferencing
646 * to obtain the operands and to simplify the generation of the
647 * logical value. For the Numeric operators (LAnd and LOr), both
648 * operands must be integers. For the other logical operators,
649 * operands can be any combination of Integer/String/Buffer. The
650 * first operand determines the type to which the second operand
653 * Note: cleanest machine code seems to be produced by the code
654 * below, rather than using statements of the form:
655 * Result = (Operand0 == Operand1);
657 ******************************************************************************/
662 ACPI_OPERAND_OBJECT *Operand0,
663 ACPI_OPERAND_OBJECT *Operand1,
664 BOOLEAN *LogicalResult)
666 ACPI_OPERAND_OBJECT *LocalOperand1 = Operand1;
667 ACPI_INTEGER Integer0;
668 ACPI_INTEGER Integer1;
671 ACPI_STATUS Status = AE_OK;
672 BOOLEAN LocalResult = FALSE;
676 ACPI_FUNCTION_TRACE ("ExDoLogicalOp");
680 * Convert the second operand if necessary. The first operand
681 * determines the type of the second operand, (See the Data Types
682 * section of the ACPI 3.0+ specification.) Both object types are
683 * guaranteed to be either Integer/String/Buffer by the operand
684 * resolution mechanism.
686 switch (ACPI_GET_OBJECT_TYPE (Operand0))
688 case ACPI_TYPE_INTEGER:
689 Status = AcpiExConvertToInteger (Operand1, &LocalOperand1, 16);
692 case ACPI_TYPE_STRING:
693 Status = AcpiExConvertToString (Operand1, &LocalOperand1,
694 ACPI_IMPLICIT_CONVERT_HEX);
697 case ACPI_TYPE_BUFFER:
698 Status = AcpiExConvertToBuffer (Operand1, &LocalOperand1);
702 Status = AE_AML_INTERNAL;
706 if (ACPI_FAILURE (Status))
712 * Two cases: 1) Both Integers, 2) Both Strings or Buffers
714 if (ACPI_GET_OBJECT_TYPE (Operand0) == ACPI_TYPE_INTEGER)
717 * 1) Both operands are of type integer
718 * Note: LocalOperand1 may have changed above
720 Integer0 = Operand0->Integer.Value;
721 Integer1 = LocalOperand1->Integer.Value;
725 case AML_LEQUAL_OP: /* LEqual (Operand0, Operand1) */
727 if (Integer0 == Integer1)
733 case AML_LGREATER_OP: /* LGreater (Operand0, Operand1) */
735 if (Integer0 > Integer1)
741 case AML_LLESS_OP: /* LLess (Operand0, Operand1) */
743 if (Integer0 < Integer1)
750 Status = AE_AML_INTERNAL;
757 * 2) Both operands are Strings or both are Buffers
758 * Note: Code below takes advantage of common Buffer/String
759 * object fields. LocalOperand1 may have changed above. Use
760 * memcmp to handle nulls in buffers.
762 Length0 = Operand0->Buffer.Length;
763 Length1 = LocalOperand1->Buffer.Length;
765 /* Lexicographic compare: compare the data bytes */
767 Compare = ACPI_MEMCMP ((const char * ) Operand0->Buffer.Pointer,
768 (const char * ) LocalOperand1->Buffer.Pointer,
769 (Length0 > Length1) ? Length1 : Length0);
773 case AML_LEQUAL_OP: /* LEqual (Operand0, Operand1) */
775 /* Length and all bytes must be equal */
777 if ((Length0 == Length1) &&
780 /* Length and all bytes match ==> TRUE */
786 case AML_LGREATER_OP: /* LGreater (Operand0, Operand1) */
791 goto Cleanup; /* TRUE */
795 goto Cleanup; /* FALSE */
798 /* Bytes match (to shortest length), compare lengths */
800 if (Length0 > Length1)
806 case AML_LLESS_OP: /* LLess (Operand0, Operand1) */
810 goto Cleanup; /* FALSE */
815 goto Cleanup; /* TRUE */
818 /* Bytes match (to shortest length), compare lengths */
820 if (Length0 < Length1)
827 Status = AE_AML_INTERNAL;
834 /* New object was created if implicit conversion performed - delete */
836 if (LocalOperand1 != Operand1)
838 AcpiUtRemoveReference (LocalOperand1);
841 /* Return the logical result and status */
843 *LogicalResult = LocalResult;
844 return_ACPI_STATUS (Status);