1 /******************************************************************************
3 * Module Name: exoparg2 - AML execution - opcodes with 2 arguments
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
118 #define __EXOPARG2_C__
121 #include "acparser.h"
122 #include "acinterp.h"
123 #include "acevents.h"
127 #define _COMPONENT ACPI_EXECUTER
128 ACPI_MODULE_NAME ("exoparg2")
132 * Naming convention for AML interpreter execution routines.
134 * The routines that begin execution of AML opcodes are named with a common
135 * convention based upon the number of arguments, the number of target operands,
136 * and whether or not a value is returned:
138 * AcpiExOpcode_xA_yT_zR
142 * xA - ARGUMENTS: The number of arguments (input operands) that are
143 * required for this opcode type (1 through 6 args).
144 * yT - TARGETS: The number of targets (output operands) that are required
145 * for this opcode type (0, 1, or 2 targets).
146 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
147 * as the function return (0 or 1).
149 * The AcpiExOpcode* functions are called via the Dispatcher component with
150 * fully resolved operands.
154 /*******************************************************************************
156 * FUNCTION: AcpiExOpcode_2A_0T_0R
158 * PARAMETERS: WalkState - Current walk state
162 * DESCRIPTION: Execute opcode with two arguments, no target, and no return
165 * ALLOCATION: Deletes both operands
167 ******************************************************************************/
170 AcpiExOpcode_2A_0T_0R (
171 ACPI_WALK_STATE *WalkState)
173 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
174 ACPI_NAMESPACE_NODE *Node;
176 ACPI_STATUS Status = AE_OK;
179 ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_0T_0R,
180 AcpiPsGetOpcodeName (WalkState->Opcode));
183 /* Examine the opcode */
185 switch (WalkState->Opcode)
187 case AML_NOTIFY_OP: /* Notify (NotifyObject, NotifyValue) */
189 /* The first operand is a namespace node */
191 Node = (ACPI_NAMESPACE_NODE *) Operand[0];
193 /* Second value is the notify value */
195 Value = (UINT32) Operand[1]->Integer.Value;
197 /* Are notifies allowed on this object? */
199 if (!AcpiEvIsNotifyObject (Node))
201 ACPI_ERROR ((AE_INFO,
202 "Unexpected notify object type [%s]",
203 AcpiUtGetTypeName (Node->Type)));
205 Status = AE_AML_OPERAND_TYPE;
209 #ifdef ACPI_GPE_NOTIFY_CHECK
211 * GPE method wake/notify check. Here, we want to ensure that we
212 * don't receive any "DeviceWake" Notifies from a GPE _Lxx or _Exx
213 * GPE method during system runtime. If we do, the GPE is marked
214 * as "wake-only" and disabled.
216 * 1) Is the Notify() value == DeviceWake?
217 * 2) Is this a GPE deferred method? (An _Lxx or _Exx method)
218 * 3) Did the original GPE happen at system runtime?
219 * (versus during wake)
221 * If all three cases are true, this is a wake-only GPE that should
222 * be disabled at runtime.
224 if (Value == 2) /* DeviceWake */
226 Status = AcpiEvCheckForWakeOnlyGpe (WalkState->GpeEventInfo);
227 if (ACPI_FAILURE (Status))
229 /* AE_WAKE_ONLY_GPE only error, means ignore this notify */
231 return_ACPI_STATUS (AE_OK)
237 * Dispatch the notify to the appropriate handler
238 * NOTE: the request is queued for execution after this method
239 * completes. The notify handlers are NOT invoked synchronously
240 * from this thread -- because handlers may in turn run other
243 Status = AcpiEvQueueNotifyRequest (Node, Value);
249 ACPI_ERROR ((AE_INFO, "Unknown AML opcode %X",
251 Status = AE_AML_BAD_OPCODE;
254 return_ACPI_STATUS (Status);
258 /*******************************************************************************
260 * FUNCTION: AcpiExOpcode_2A_2T_1R
262 * PARAMETERS: WalkState - Current walk state
266 * DESCRIPTION: Execute a dyadic operator (2 operands) with 2 output targets
267 * and one implicit return value.
269 ******************************************************************************/
272 AcpiExOpcode_2A_2T_1R (
273 ACPI_WALK_STATE *WalkState)
275 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
276 ACPI_OPERAND_OBJECT *ReturnDesc1 = NULL;
277 ACPI_OPERAND_OBJECT *ReturnDesc2 = NULL;
281 ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_2T_1R,
282 AcpiPsGetOpcodeName (WalkState->Opcode));
285 /* Execute the opcode */
287 switch (WalkState->Opcode)
291 /* Divide (Dividend, Divisor, RemainderResult QuotientResult) */
293 ReturnDesc1 = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
296 Status = AE_NO_MEMORY;
300 ReturnDesc2 = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
303 Status = AE_NO_MEMORY;
307 /* Quotient to ReturnDesc1, remainder to ReturnDesc2 */
309 Status = AcpiUtDivide (Operand[0]->Integer.Value,
310 Operand[1]->Integer.Value,
311 &ReturnDesc1->Integer.Value,
312 &ReturnDesc2->Integer.Value);
313 if (ACPI_FAILURE (Status))
322 ACPI_ERROR ((AE_INFO, "Unknown AML opcode %X",
324 Status = AE_AML_BAD_OPCODE;
328 /* Store the results to the target reference operands */
330 Status = AcpiExStore (ReturnDesc2, Operand[2], WalkState);
331 if (ACPI_FAILURE (Status))
336 Status = AcpiExStore (ReturnDesc1, Operand[3], WalkState);
337 if (ACPI_FAILURE (Status))
344 * Since the remainder is not returned indirectly, remove a reference to
345 * it. Only the quotient is returned indirectly.
347 AcpiUtRemoveReference (ReturnDesc2);
349 if (ACPI_FAILURE (Status))
351 /* Delete the return object */
353 AcpiUtRemoveReference (ReturnDesc1);
356 /* Save return object (the remainder) on success */
360 WalkState->ResultObj = ReturnDesc1;
363 return_ACPI_STATUS (Status);
367 /*******************************************************************************
369 * FUNCTION: AcpiExOpcode_2A_1T_1R
371 * PARAMETERS: WalkState - Current walk state
375 * DESCRIPTION: Execute opcode with two arguments, one target, and a return
378 ******************************************************************************/
381 AcpiExOpcode_2A_1T_1R (
382 ACPI_WALK_STATE *WalkState)
384 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
385 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
387 ACPI_STATUS Status = AE_OK;
391 ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_1T_1R,
392 AcpiPsGetOpcodeName (WalkState->Opcode));
395 /* Execute the opcode */
397 if (WalkState->OpInfo->Flags & AML_MATH)
399 /* All simple math opcodes (add, etc.) */
401 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
404 Status = AE_NO_MEMORY;
408 ReturnDesc->Integer.Value = AcpiExDoMathOp (WalkState->Opcode,
409 Operand[0]->Integer.Value,
410 Operand[1]->Integer.Value);
411 goto StoreResultToTarget;
414 switch (WalkState->Opcode)
416 case AML_MOD_OP: /* Mod (Dividend, Divisor, RemainderResult (ACPI 2.0) */
418 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
421 Status = AE_NO_MEMORY;
425 /* ReturnDesc will contain the remainder */
427 Status = AcpiUtDivide (Operand[0]->Integer.Value,
428 Operand[1]->Integer.Value,
430 &ReturnDesc->Integer.Value);
434 case AML_CONCAT_OP: /* Concatenate (Data1, Data2, Result) */
436 Status = AcpiExDoConcatenate (Operand[0], Operand[1],
437 &ReturnDesc, WalkState);
441 case AML_TO_STRING_OP: /* ToString (Buffer, Length, Result) (ACPI 2.0) */
444 * Input object is guaranteed to be a buffer at this point (it may have
445 * been converted.) Copy the raw buffer data to a new object of
450 * Get the length of the new string. It is the smallest of:
451 * 1) Length of the input buffer
452 * 2) Max length as specified in the ToString operator
453 * 3) Length of input buffer up to a zero byte (null terminator)
455 * NOTE: A length of zero is ok, and will create a zero-length, null
459 while ((Length < Operand[0]->Buffer.Length) &&
460 (Length < Operand[1]->Integer.Value) &&
461 (Operand[0]->Buffer.Pointer[Length]))
466 /* Allocate a new string object */
468 ReturnDesc = AcpiUtCreateStringObject (Length);
471 Status = AE_NO_MEMORY;
476 * Copy the raw buffer data with no transform.
477 * (NULL terminated already)
479 ACPI_MEMCPY (ReturnDesc->String.Pointer,
480 Operand[0]->Buffer.Pointer, Length);
484 case AML_CONCAT_RES_OP:
486 /* ConcatenateResTemplate (Buffer, Buffer, Result) (ACPI 2.0) */
488 Status = AcpiExConcatTemplate (Operand[0], Operand[1],
489 &ReturnDesc, WalkState);
493 case AML_INDEX_OP: /* Index (Source Index Result) */
495 /* Create the internal return object */
497 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
500 Status = AE_NO_MEMORY;
504 /* Initialize the Index reference object */
506 Index = Operand[1]->Integer.Value;
507 ReturnDesc->Reference.Offset = (UINT32) Index;
508 ReturnDesc->Reference.Opcode = AML_INDEX_OP;
511 * At this point, the Source operand is a String, Buffer, or Package.
512 * Verify that the index is within range.
514 switch (ACPI_GET_OBJECT_TYPE (Operand[0]))
516 case ACPI_TYPE_STRING:
518 if (Index >= Operand[0]->String.Length)
520 Status = AE_AML_STRING_LIMIT;
523 ReturnDesc->Reference.TargetType = ACPI_TYPE_BUFFER_FIELD;
526 case ACPI_TYPE_BUFFER:
528 if (Index >= Operand[0]->Buffer.Length)
530 Status = AE_AML_BUFFER_LIMIT;
533 ReturnDesc->Reference.TargetType = ACPI_TYPE_BUFFER_FIELD;
536 case ACPI_TYPE_PACKAGE:
538 if (Index >= Operand[0]->Package.Count)
540 Status = AE_AML_PACKAGE_LIMIT;
543 ReturnDesc->Reference.TargetType = ACPI_TYPE_PACKAGE;
544 ReturnDesc->Reference.Where = &Operand[0]->Package.Elements [Index];
549 Status = AE_AML_INTERNAL;
553 /* Failure means that the Index was beyond the end of the object */
555 if (ACPI_FAILURE (Status))
557 ACPI_EXCEPTION ((AE_INFO, Status,
558 "Index (%X%8.8X) is beyond end of object",
559 ACPI_FORMAT_UINT64 (Index)));
564 * Save the target object and add a reference to it for the life
567 ReturnDesc->Reference.Object = Operand[0];
568 AcpiUtAddReference (Operand[0]);
570 /* Store the reference to the Target */
572 Status = AcpiExStore (ReturnDesc, Operand[2], WalkState);
574 /* Return the reference */
576 WalkState->ResultObj = ReturnDesc;
582 ACPI_ERROR ((AE_INFO, "Unknown AML opcode %X",
584 Status = AE_AML_BAD_OPCODE;
591 if (ACPI_SUCCESS (Status))
594 * Store the result of the operation (which is now in ReturnDesc) into
595 * the Target descriptor.
597 Status = AcpiExStore (ReturnDesc, Operand[2], WalkState);
598 if (ACPI_FAILURE (Status))
603 if (!WalkState->ResultObj)
605 WalkState->ResultObj = ReturnDesc;
612 /* Delete return object on error */
614 if (ACPI_FAILURE (Status))
616 AcpiUtRemoveReference (ReturnDesc);
617 WalkState->ResultObj = NULL;
620 return_ACPI_STATUS (Status);
624 /*******************************************************************************
626 * FUNCTION: AcpiExOpcode_2A_0T_1R
628 * PARAMETERS: WalkState - Current walk state
632 * DESCRIPTION: Execute opcode with 2 arguments, no target, and a return value
634 ******************************************************************************/
637 AcpiExOpcode_2A_0T_1R (
638 ACPI_WALK_STATE *WalkState)
640 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
641 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
642 ACPI_STATUS Status = AE_OK;
643 BOOLEAN LogicalResult = FALSE;
646 ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_0T_1R,
647 AcpiPsGetOpcodeName (WalkState->Opcode));
650 /* Create the internal return object */
652 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
655 Status = AE_NO_MEMORY;
659 /* Execute the Opcode */
661 if (WalkState->OpInfo->Flags & AML_LOGICAL_NUMERIC)
663 /* LogicalOp (Operand0, Operand1) */
665 Status = AcpiExDoLogicalNumericOp (WalkState->Opcode,
666 Operand[0]->Integer.Value, Operand[1]->Integer.Value,
668 goto StoreLogicalResult;
670 else if (WalkState->OpInfo->Flags & AML_LOGICAL)
672 /* LogicalOp (Operand0, Operand1) */
674 Status = AcpiExDoLogicalOp (WalkState->Opcode, Operand[0],
675 Operand[1], &LogicalResult);
676 goto StoreLogicalResult;
679 switch (WalkState->Opcode)
681 case AML_ACQUIRE_OP: /* Acquire (MutexObject, Timeout) */
683 Status = AcpiExAcquireMutex (Operand[1], Operand[0], WalkState);
684 if (Status == AE_TIME)
686 LogicalResult = TRUE; /* TRUE = Acquire timed out */
692 case AML_WAIT_OP: /* Wait (EventObject, Timeout) */
694 Status = AcpiExSystemWaitEvent (Operand[1], Operand[0]);
695 if (Status == AE_TIME)
697 LogicalResult = TRUE; /* TRUE, Wait timed out */
705 ACPI_ERROR ((AE_INFO, "Unknown AML opcode %X",
707 Status = AE_AML_BAD_OPCODE;
714 * Set return value to according to LogicalResult. logical TRUE (all ones)
715 * Default is FALSE (zero)
719 ReturnDesc->Integer.Value = ACPI_INTEGER_MAX;
724 /* Delete return object on error */
726 if (ACPI_FAILURE (Status))
728 AcpiUtRemoveReference (ReturnDesc);
731 /* Save return object on success */
735 WalkState->ResultObj = ReturnDesc;
738 return_ACPI_STATUS (Status);