2 /******************************************************************************
4 * Module Name: exmisc - ACPI AML (p-code) execution - specific opcodes
7 *****************************************************************************/
9 /******************************************************************************
13 * Some or all of this work - Copyright (c) 1999 - 2004, 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: *ObjDesc - Object to be converted. Must be an
232 * Integer, Buffer, or String
233 * WalkState - Current walk state
237 * DESCRIPTION: Concatenate two resource templates
239 ******************************************************************************/
242 AcpiExConcatTemplate (
243 ACPI_OPERAND_OBJECT *ObjDesc1,
244 ACPI_OPERAND_OBJECT *ObjDesc2,
245 ACPI_OPERAND_OBJECT **ActualReturnDesc,
246 ACPI_WALK_STATE *WalkState)
248 ACPI_OPERAND_OBJECT *ReturnDesc;
256 ACPI_FUNCTION_TRACE ("ExConcatTemplate");
259 /* Find the EndTags in each resource template */
261 EndTag1 = AcpiUtGetResourceEndTag (ObjDesc1);
262 EndTag2 = AcpiUtGetResourceEndTag (ObjDesc2);
263 if (!EndTag1 || !EndTag2)
265 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
268 /* Compute the length of each part */
270 Length1 = ACPI_PTR_DIFF (EndTag1, ObjDesc1->Buffer.Pointer);
271 Length2 = ACPI_PTR_DIFF (EndTag2, ObjDesc2->Buffer.Pointer) +
272 2; /* Size of END_TAG */
274 /* Create a new buffer object for the result */
276 ReturnDesc = AcpiUtCreateBufferObject (Length1 + Length2);
279 return_ACPI_STATUS (AE_NO_MEMORY);
282 /* Copy the templates to the new descriptor */
284 NewBuf = ReturnDesc->Buffer.Pointer;
285 ACPI_MEMCPY (NewBuf, ObjDesc1->Buffer.Pointer, Length1);
286 ACPI_MEMCPY (NewBuf + Length1, ObjDesc2->Buffer.Pointer, Length2);
288 /* Compute the new checksum */
290 NewBuf[ReturnDesc->Buffer.Length - 1] =
291 AcpiUtGenerateChecksum (ReturnDesc->Buffer.Pointer,
292 (ReturnDesc->Buffer.Length - 1));
294 /* Return the completed template descriptor */
296 *ActualReturnDesc = ReturnDesc;
297 return_ACPI_STATUS (AE_OK);
301 /*******************************************************************************
303 * FUNCTION: AcpiExDoConcatenate
305 * PARAMETERS: ObjDesc1 - First source object
306 * ObjDesc2 - Second source object
307 * ActualReturnDesc - Where to place the return object
308 * WalkState - Current walk state
312 * DESCRIPTION: Concatenate two objects OF THE SAME TYPE.
314 ******************************************************************************/
317 AcpiExDoConcatenate (
318 ACPI_OPERAND_OBJECT *ObjDesc1,
319 ACPI_OPERAND_OBJECT *ObjDesc2,
320 ACPI_OPERAND_OBJECT **ActualReturnDesc,
321 ACPI_WALK_STATE *WalkState)
325 ACPI_INTEGER ThisInteger;
326 ACPI_OPERAND_OBJECT *ReturnDesc;
330 ACPI_FUNCTION_ENTRY ();
334 * There are three cases to handle:
336 * 1) Two Integers concatenated to produce a new Buffer
337 * 2) Two Strings concatenated to produce a new String
338 * 3) Two Buffers concatenated to produce a new Buffer
340 switch (ACPI_GET_OBJECT_TYPE (ObjDesc1))
342 case ACPI_TYPE_INTEGER:
344 /* Result of two Integers is a Buffer */
345 /* Need enough buffer space for two integers */
347 ReturnDesc = AcpiUtCreateBufferObject (AcpiGbl_IntegerByteWidth * 2);
350 return (AE_NO_MEMORY);
353 NewBuf = (char *) ReturnDesc->Buffer.Pointer;
355 /* Convert the first integer */
357 ThisInteger = ObjDesc1->Integer.Value;
358 for (i = 0; i < AcpiGbl_IntegerByteWidth; i++)
360 NewBuf[i] = (char) ThisInteger;
364 /* Convert the second integer */
366 ThisInteger = ObjDesc2->Integer.Value;
367 for (; i < (ACPI_MUL_2 (AcpiGbl_IntegerByteWidth)); i++)
369 NewBuf[i] = (char) ThisInteger;
376 case ACPI_TYPE_STRING:
378 /* Result of two Strings is a String */
380 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_STRING);
383 return (AE_NO_MEMORY);
386 /* Operand0 is string */
388 NewBuf = ACPI_MEM_CALLOCATE ((ACPI_SIZE) ObjDesc1->String.Length +
389 (ACPI_SIZE) ObjDesc2->String.Length + 1);
393 (("ExDoConcatenate: String allocation failure\n"));
394 Status = AE_NO_MEMORY;
398 /* Concatenate the strings */
400 ACPI_STRCPY (NewBuf, ObjDesc1->String.Pointer);
401 ACPI_STRCPY (NewBuf + ObjDesc1->String.Length,
402 ObjDesc2->String.Pointer);
404 /* Complete the String object initialization */
406 ReturnDesc->String.Pointer = NewBuf;
407 ReturnDesc->String.Length = ObjDesc1->String.Length +
408 ObjDesc2->String.Length;
412 case ACPI_TYPE_BUFFER:
414 /* Result of two Buffers is a Buffer */
416 ReturnDesc = AcpiUtCreateBufferObject (
417 (ACPI_SIZE) ObjDesc1->Buffer.Length +
418 (ACPI_SIZE) ObjDesc2->Buffer.Length);
421 return (AE_NO_MEMORY);
424 NewBuf = (char *) ReturnDesc->Buffer.Pointer;
426 /* Concatenate the buffers */
428 ACPI_MEMCPY (NewBuf, ObjDesc1->Buffer.Pointer,
429 ObjDesc1->Buffer.Length);
430 ACPI_MEMCPY (NewBuf + ObjDesc1->Buffer.Length, ObjDesc2->Buffer.Pointer,
431 ObjDesc2->Buffer.Length);
438 /* Invalid object type, should not happen here */
440 ACPI_REPORT_ERROR (("Concat - invalid obj type: %X\n",
441 ACPI_GET_OBJECT_TYPE (ObjDesc1)));
442 Status = AE_AML_INTERNAL;
446 *ActualReturnDesc = ReturnDesc;
452 AcpiUtRemoveReference (ReturnDesc);
457 /*******************************************************************************
459 * FUNCTION: AcpiExDoMathOp
461 * PARAMETERS: Opcode - AML opcode
462 * Operand0 - Integer operand #0
463 * Operand1 - Integer operand #1
465 * RETURN: Integer result of the operation
467 * DESCRIPTION: Execute a math AML opcode. The purpose of having all of the
468 * math functions here is to prevent a lot of pointer dereferencing
469 * to obtain the operands.
471 ******************************************************************************/
476 ACPI_INTEGER Operand0,
477 ACPI_INTEGER Operand1)
483 case AML_ADD_OP: /* Add (Operand0, Operand1, Result) */
485 return (Operand0 + Operand1);
488 case AML_BIT_AND_OP: /* And (Operand0, Operand1, Result) */
490 return (Operand0 & Operand1);
493 case AML_BIT_NAND_OP: /* NAnd (Operand0, Operand1, Result) */
495 return (~(Operand0 & Operand1));
498 case AML_BIT_OR_OP: /* Or (Operand0, Operand1, Result) */
500 return (Operand0 | Operand1);
503 case AML_BIT_NOR_OP: /* NOr (Operand0, Operand1, Result) */
505 return (~(Operand0 | Operand1));
508 case AML_BIT_XOR_OP: /* XOr (Operand0, Operand1, Result) */
510 return (Operand0 ^ Operand1);
513 case AML_MULTIPLY_OP: /* Multiply (Operand0, Operand1, Result) */
515 return (Operand0 * Operand1);
518 case AML_SHIFT_LEFT_OP: /* ShiftLeft (Operand, ShiftCount, Result) */
520 return (Operand0 << Operand1);
523 case AML_SHIFT_RIGHT_OP: /* ShiftRight (Operand, ShiftCount, Result) */
525 return (Operand0 >> Operand1);
528 case AML_SUBTRACT_OP: /* Subtract (Operand0, Operand1, Result) */
530 return (Operand0 - Operand1);
539 /*******************************************************************************
541 * FUNCTION: AcpiExDoLogicalOp
543 * PARAMETERS: Opcode - AML opcode
544 * Operand0 - Integer operand #0
545 * Operand1 - Integer operand #1
547 * RETURN: TRUE/FALSE result of the operation
549 * DESCRIPTION: Execute a logical AML opcode. The purpose of having all of the
550 * functions here is to prevent a lot of pointer dereferencing
551 * to obtain the operands and to simplify the generation of the
554 * Note: cleanest machine code seems to be produced by the code
555 * below, rather than using statements of the form:
556 * Result = (Operand0 == Operand1);
558 ******************************************************************************/
563 ACPI_INTEGER Operand0,
564 ACPI_INTEGER Operand1)
571 case AML_LAND_OP: /* LAnd (Operand0, Operand1) */
573 if (Operand0 && Operand1)
580 case AML_LEQUAL_OP: /* LEqual (Operand0, Operand1) */
582 if (Operand0 == Operand1)
589 case AML_LGREATER_OP: /* LGreater (Operand0, Operand1) */
591 if (Operand0 > Operand1)
598 case AML_LLESS_OP: /* LLess (Operand0, Operand1) */
600 if (Operand0 < Operand1)
607 case AML_LOR_OP: /* LOr (Operand0, Operand1) */
609 if (Operand0 || Operand1)