2 /******************************************************************************
4 * Module Name: exmisc - ACPI AML (p-code) execution - specific opcodes
7 *****************************************************************************/
9 /******************************************************************************
13 * Some or all of this work - Copyright (c) 1999 - 2003, 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 *****************************************************************************/
118 /* $DragonFly: src/sys/contrib/dev/acpica/Attic/exmisc.c,v 1.1 2003/09/24 03:32:16 drhodus Exp $ */
123 #include "acinterp.h"
127 #define _COMPONENT ACPI_EXECUTER
128 ACPI_MODULE_NAME ("exmisc")
131 /*******************************************************************************
133 * FUNCTION: AcpiExGetObjectReference
135 * PARAMETERS: ObjDesc - Create a reference to this object
136 * ReturnDesc - Where to store the reference
137 * WalkState - Current state
141 * DESCRIPTION: Obtain and return a "reference" to the target object
142 * Common code for the RefOfOp and the CondRefOfOp.
144 ******************************************************************************/
147 AcpiExGetObjectReference (
148 ACPI_OPERAND_OBJECT *ObjDesc,
149 ACPI_OPERAND_OBJECT **ReturnDesc,
150 ACPI_WALK_STATE *WalkState)
152 ACPI_OPERAND_OBJECT *ReferenceObj;
153 ACPI_OPERAND_OBJECT *ReferencedObj;
156 ACPI_FUNCTION_TRACE_PTR ("ExGetObjectReference", ObjDesc);
161 switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
163 case ACPI_DESC_TYPE_OPERAND:
165 if (ACPI_GET_OBJECT_TYPE (ObjDesc) != ACPI_TYPE_LOCAL_REFERENCE)
167 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
171 * Must be a reference to a Local or Arg
173 switch (ObjDesc->Reference.Opcode)
178 /* The referenced object is the pseudo-node for the local/arg */
180 ReferencedObj = ObjDesc->Reference.Object;
185 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown Reference subtype %X\n",
186 ObjDesc->Reference.Opcode));
187 return_ACPI_STATUS (AE_AML_INTERNAL);
192 case ACPI_DESC_TYPE_NAMED:
195 * A named reference that has already been resolved to a Node
197 ReferencedObj = ObjDesc;
203 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid descriptor type %X in %p\n",
204 ACPI_GET_DESCRIPTOR_TYPE (ObjDesc), ObjDesc));
205 return_ACPI_STATUS (AE_TYPE);
209 /* Create a new reference object */
211 ReferenceObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
214 return_ACPI_STATUS (AE_NO_MEMORY);
217 ReferenceObj->Reference.Opcode = AML_REF_OF_OP;
218 ReferenceObj->Reference.Object = ReferencedObj;
219 *ReturnDesc = ReferenceObj;
221 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Object %p Type [%s], returning Reference %p\n",
222 ObjDesc, AcpiUtGetObjectTypeName (ObjDesc), *ReturnDesc));
224 return_ACPI_STATUS (AE_OK);
228 /*******************************************************************************
230 * FUNCTION: AcpiExConcatTemplate
232 * PARAMETERS: *ObjDesc - Object to be converted. Must be an
233 * Integer, Buffer, or String
234 * WalkState - Current walk state
238 * DESCRIPTION: Concatenate two resource templates
240 ******************************************************************************/
243 AcpiExConcatTemplate (
244 ACPI_OPERAND_OBJECT *ObjDesc1,
245 ACPI_OPERAND_OBJECT *ObjDesc2,
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 (ObjDesc1);
263 EndTag2 = AcpiUtGetResourceEndTag (ObjDesc2);
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, ObjDesc1->Buffer.Pointer);
272 Length2 = ACPI_PTR_DIFF (EndTag2, ObjDesc2->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, ObjDesc1->Buffer.Pointer, Length1);
287 ACPI_MEMCPY (NewBuf + Length1, ObjDesc2->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: ObjDesc1 - First source object
307 * ObjDesc2 - 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 *ObjDesc1,
320 ACPI_OPERAND_OBJECT *ObjDesc2,
321 ACPI_OPERAND_OBJECT **ActualReturnDesc,
322 ACPI_WALK_STATE *WalkState)
326 ACPI_INTEGER ThisInteger;
327 ACPI_OPERAND_OBJECT *ReturnDesc;
331 ACPI_FUNCTION_ENTRY ();
335 * There are three cases to handle:
337 * 1) Two Integers concatenated to produce a new Buffer
338 * 2) Two Strings concatenated to produce a new String
339 * 3) Two Buffers concatenated to produce a new Buffer
341 switch (ACPI_GET_OBJECT_TYPE (ObjDesc1))
343 case ACPI_TYPE_INTEGER:
345 /* Result of two Integers is a Buffer */
346 /* Need enough buffer space for two integers */
348 ReturnDesc = AcpiUtCreateBufferObject (AcpiGbl_IntegerByteWidth * 2);
351 return (AE_NO_MEMORY);
354 NewBuf = (char *) ReturnDesc->Buffer.Pointer;
356 /* Convert the first integer */
358 ThisInteger = ObjDesc1->Integer.Value;
359 for (i = 0; i < AcpiGbl_IntegerByteWidth; i++)
361 NewBuf[i] = (char) ThisInteger;
365 /* Convert the second integer */
367 ThisInteger = ObjDesc2->Integer.Value;
368 for (; i < (ACPI_MUL_2 (AcpiGbl_IntegerByteWidth)); i++)
370 NewBuf[i] = (char) ThisInteger;
377 case ACPI_TYPE_STRING:
379 /* Result of two Strings is a String */
381 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_STRING);
384 return (AE_NO_MEMORY);
387 /* Operand0 is string */
389 NewBuf = ACPI_MEM_CALLOCATE ((ACPI_SIZE) ObjDesc1->String.Length +
390 (ACPI_SIZE) ObjDesc2->String.Length + 1);
394 (("ExDoConcatenate: String allocation failure\n"));
395 Status = AE_NO_MEMORY;
399 /* Concatenate the strings */
401 ACPI_STRCPY (NewBuf, ObjDesc1->String.Pointer);
402 ACPI_STRCPY (NewBuf + ObjDesc1->String.Length,
403 ObjDesc2->String.Pointer);
405 /* Complete the String object initialization */
407 ReturnDesc->String.Pointer = NewBuf;
408 ReturnDesc->String.Length = ObjDesc1->String.Length +
409 ObjDesc2->String.Length;
413 case ACPI_TYPE_BUFFER:
415 /* Result of two Buffers is a Buffer */
417 ReturnDesc = AcpiUtCreateBufferObject (
418 (ACPI_SIZE) ObjDesc1->Buffer.Length +
419 (ACPI_SIZE) ObjDesc2->Buffer.Length);
422 return (AE_NO_MEMORY);
425 NewBuf = (char *) ReturnDesc->Buffer.Pointer;
427 /* Concatenate the buffers */
429 ACPI_MEMCPY (NewBuf, ObjDesc1->Buffer.Pointer,
430 ObjDesc1->Buffer.Length);
431 ACPI_MEMCPY (NewBuf + ObjDesc1->Buffer.Length, ObjDesc2->Buffer.Pointer,
432 ObjDesc2->Buffer.Length);
439 /* Invalid object type, should not happen here */
441 Status = AE_AML_INTERNAL;
445 *ActualReturnDesc = ReturnDesc;
451 AcpiUtRemoveReference (ReturnDesc);
456 /*******************************************************************************
458 * FUNCTION: AcpiExDoMathOp
460 * PARAMETERS: Opcode - AML opcode
461 * Operand0 - Integer operand #0
462 * Operand1 - Integer operand #1
464 * RETURN: Integer result of the operation
466 * DESCRIPTION: Execute a math AML opcode. The purpose of having all of the
467 * math functions here is to prevent a lot of pointer dereferencing
468 * to obtain the operands.
470 ******************************************************************************/
475 ACPI_INTEGER Operand0,
476 ACPI_INTEGER Operand1)
482 case AML_ADD_OP: /* Add (Operand0, Operand1, Result) */
484 return (Operand0 + Operand1);
487 case AML_BIT_AND_OP: /* And (Operand0, Operand1, Result) */
489 return (Operand0 & Operand1);
492 case AML_BIT_NAND_OP: /* NAnd (Operand0, Operand1, Result) */
494 return (~(Operand0 & Operand1));
497 case AML_BIT_OR_OP: /* Or (Operand0, Operand1, Result) */
499 return (Operand0 | Operand1);
502 case AML_BIT_NOR_OP: /* NOr (Operand0, Operand1, Result) */
504 return (~(Operand0 | Operand1));
507 case AML_BIT_XOR_OP: /* XOr (Operand0, Operand1, Result) */
509 return (Operand0 ^ Operand1);
512 case AML_MULTIPLY_OP: /* Multiply (Operand0, Operand1, Result) */
514 return (Operand0 * Operand1);
517 case AML_SHIFT_LEFT_OP: /* ShiftLeft (Operand, ShiftCount, Result) */
519 return (Operand0 << Operand1);
522 case AML_SHIFT_RIGHT_OP: /* ShiftRight (Operand, ShiftCount, Result) */
524 return (Operand0 >> Operand1);
527 case AML_SUBTRACT_OP: /* Subtract (Operand0, Operand1, Result) */
529 return (Operand0 - Operand1);
538 /*******************************************************************************
540 * FUNCTION: AcpiExDoLogicalOp
542 * PARAMETERS: Opcode - AML opcode
543 * Operand0 - Integer operand #0
544 * Operand1 - Integer operand #1
546 * RETURN: TRUE/FALSE result of the operation
548 * DESCRIPTION: Execute a logical AML opcode. The purpose of having all of the
549 * functions here is to prevent a lot of pointer dereferencing
550 * to obtain the operands and to simplify the generation of the
553 * Note: cleanest machine code seems to be produced by the code
554 * below, rather than using statements of the form:
555 * Result = (Operand0 == Operand1);
557 ******************************************************************************/
562 ACPI_INTEGER Operand0,
563 ACPI_INTEGER Operand1)
570 case AML_LAND_OP: /* LAnd (Operand0, Operand1) */
572 if (Operand0 && Operand1)
579 case AML_LEQUAL_OP: /* LEqual (Operand0, Operand1) */
581 if (Operand0 == Operand1)
588 case AML_LGREATER_OP: /* LGreater (Operand0, Operand1) */
590 if (Operand0 > Operand1)
597 case AML_LLESS_OP: /* LLess (Operand0, Operand1) */
599 if (Operand0 < Operand1)
606 case AML_LOR_OP: /* LOr (Operand0, Operand1) */
608 if (Operand0 || Operand1)