1 /******************************************************************************
3 * Module Name: exoparg2 - AML execution - opcodes with 2 arguments
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #define __EXOPARG2_C__
54 #define _COMPONENT ACPI_EXECUTER
55 ACPI_MODULE_NAME ("exoparg2")
59 * Naming convention for AML interpreter execution routines.
61 * The routines that begin execution of AML opcodes are named with a common
62 * convention based upon the number of arguments, the number of target operands,
63 * and whether or not a value is returned:
65 * AcpiExOpcode_xA_yT_zR
69 * xA - ARGUMENTS: The number of arguments (input operands) that are
70 * required for this opcode type (1 through 6 args).
71 * yT - TARGETS: The number of targets (output operands) that are required
72 * for this opcode type (0, 1, or 2 targets).
73 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
74 * as the function return (0 or 1).
76 * The AcpiExOpcode* functions are called via the Dispatcher component with
77 * fully resolved operands.
81 /*******************************************************************************
83 * FUNCTION: AcpiExOpcode_2A_0T_0R
85 * PARAMETERS: WalkState - Current walk state
89 * DESCRIPTION: Execute opcode with two arguments, no target, and no return
92 * ALLOCATION: Deletes both operands
94 ******************************************************************************/
97 AcpiExOpcode_2A_0T_0R (
98 ACPI_WALK_STATE *WalkState)
100 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
101 ACPI_NAMESPACE_NODE *Node;
103 ACPI_STATUS Status = AE_OK;
106 ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_0T_0R,
107 AcpiPsGetOpcodeName (WalkState->Opcode));
110 /* Examine the opcode */
112 switch (WalkState->Opcode)
114 case AML_NOTIFY_OP: /* Notify (NotifyObject, NotifyValue) */
116 /* The first operand is a namespace node */
118 Node = (ACPI_NAMESPACE_NODE *) Operand[0];
120 /* Second value is the notify value */
122 Value = (UINT32) Operand[1]->Integer.Value;
124 /* Are notifies allowed on this object? */
126 if (!AcpiEvIsNotifyObject (Node))
128 ACPI_ERROR ((AE_INFO,
129 "Unexpected notify object type [%s]",
130 AcpiUtGetTypeName (Node->Type)));
132 Status = AE_AML_OPERAND_TYPE;
137 * Dispatch the notify to the appropriate handler
138 * NOTE: the request is queued for execution after this method
139 * completes. The notify handlers are NOT invoked synchronously
140 * from this thread -- because handlers may in turn run other
143 Status = AcpiEvQueueNotifyRequest (Node, Value);
148 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
150 Status = AE_AML_BAD_OPCODE;
153 return_ACPI_STATUS (Status);
157 /*******************************************************************************
159 * FUNCTION: AcpiExOpcode_2A_2T_1R
161 * PARAMETERS: WalkState - Current walk state
165 * DESCRIPTION: Execute a dyadic operator (2 operands) with 2 output targets
166 * and one implicit return value.
168 ******************************************************************************/
171 AcpiExOpcode_2A_2T_1R (
172 ACPI_WALK_STATE *WalkState)
174 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
175 ACPI_OPERAND_OBJECT *ReturnDesc1 = NULL;
176 ACPI_OPERAND_OBJECT *ReturnDesc2 = NULL;
180 ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_2T_1R,
181 AcpiPsGetOpcodeName (WalkState->Opcode));
184 /* Execute the opcode */
186 switch (WalkState->Opcode)
190 /* Divide (Dividend, Divisor, RemainderResult QuotientResult) */
192 ReturnDesc1 = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
195 Status = AE_NO_MEMORY;
199 ReturnDesc2 = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
202 Status = AE_NO_MEMORY;
206 /* Quotient to ReturnDesc1, remainder to ReturnDesc2 */
208 Status = AcpiUtDivide (Operand[0]->Integer.Value,
209 Operand[1]->Integer.Value,
210 &ReturnDesc1->Integer.Value,
211 &ReturnDesc2->Integer.Value);
212 if (ACPI_FAILURE (Status))
220 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
222 Status = AE_AML_BAD_OPCODE;
226 /* Store the results to the target reference operands */
228 Status = AcpiExStore (ReturnDesc2, Operand[2], WalkState);
229 if (ACPI_FAILURE (Status))
234 Status = AcpiExStore (ReturnDesc1, Operand[3], WalkState);
235 if (ACPI_FAILURE (Status))
242 * Since the remainder is not returned indirectly, remove a reference to
243 * it. Only the quotient is returned indirectly.
245 AcpiUtRemoveReference (ReturnDesc2);
247 if (ACPI_FAILURE (Status))
249 /* Delete the return object */
251 AcpiUtRemoveReference (ReturnDesc1);
254 /* Save return object (the remainder) on success */
258 WalkState->ResultObj = ReturnDesc1;
261 return_ACPI_STATUS (Status);
265 /*******************************************************************************
267 * FUNCTION: AcpiExOpcode_2A_1T_1R
269 * PARAMETERS: WalkState - Current walk state
273 * DESCRIPTION: Execute opcode with two arguments, one target, and a return
276 ******************************************************************************/
279 AcpiExOpcode_2A_1T_1R (
280 ACPI_WALK_STATE *WalkState)
282 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
283 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
285 ACPI_STATUS Status = AE_OK;
286 ACPI_SIZE Length = 0;
289 ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_1T_1R,
290 AcpiPsGetOpcodeName (WalkState->Opcode));
293 /* Execute the opcode */
295 if (WalkState->OpInfo->Flags & AML_MATH)
297 /* All simple math opcodes (add, etc.) */
299 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
302 Status = AE_NO_MEMORY;
306 ReturnDesc->Integer.Value = AcpiExDoMathOp (WalkState->Opcode,
307 Operand[0]->Integer.Value,
308 Operand[1]->Integer.Value);
309 goto StoreResultToTarget;
312 switch (WalkState->Opcode)
314 case AML_MOD_OP: /* Mod (Dividend, Divisor, RemainderResult (ACPI 2.0) */
316 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
319 Status = AE_NO_MEMORY;
323 /* ReturnDesc will contain the remainder */
325 Status = AcpiUtDivide (Operand[0]->Integer.Value,
326 Operand[1]->Integer.Value,
328 &ReturnDesc->Integer.Value);
331 case AML_CONCAT_OP: /* Concatenate (Data1, Data2, Result) */
333 Status = AcpiExDoConcatenate (Operand[0], Operand[1],
334 &ReturnDesc, WalkState);
337 case AML_TO_STRING_OP: /* ToString (Buffer, Length, Result) (ACPI 2.0) */
339 * Input object is guaranteed to be a buffer at this point (it may have
340 * been converted.) Copy the raw buffer data to a new object of
345 * Get the length of the new string. It is the smallest of:
346 * 1) Length of the input buffer
347 * 2) Max length as specified in the ToString operator
348 * 3) Length of input buffer up to a zero byte (null terminator)
350 * NOTE: A length of zero is ok, and will create a zero-length, null
353 while ((Length < Operand[0]->Buffer.Length) &&
354 (Length < Operand[1]->Integer.Value) &&
355 (Operand[0]->Buffer.Pointer[Length]))
360 /* Allocate a new string object */
362 ReturnDesc = AcpiUtCreateStringObject (Length);
365 Status = AE_NO_MEMORY;
370 * Copy the raw buffer data with no transform.
371 * (NULL terminated already)
373 ACPI_MEMCPY (ReturnDesc->String.Pointer,
374 Operand[0]->Buffer.Pointer, Length);
377 case AML_CONCAT_RES_OP:
379 /* ConcatenateResTemplate (Buffer, Buffer, Result) (ACPI 2.0) */
381 Status = AcpiExConcatTemplate (Operand[0], Operand[1],
382 &ReturnDesc, WalkState);
385 case AML_INDEX_OP: /* Index (Source Index Result) */
387 /* Create the internal return object */
389 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
392 Status = AE_NO_MEMORY;
396 /* Initialize the Index reference object */
398 Index = Operand[1]->Integer.Value;
399 ReturnDesc->Reference.Value = (UINT32) Index;
400 ReturnDesc->Reference.Class = ACPI_REFCLASS_INDEX;
403 * At this point, the Source operand is a String, Buffer, or Package.
404 * Verify that the index is within range.
406 switch ((Operand[0])->Common.Type)
408 case ACPI_TYPE_STRING:
410 if (Index >= Operand[0]->String.Length)
412 Length = Operand[0]->String.Length;
413 Status = AE_AML_STRING_LIMIT;
416 ReturnDesc->Reference.TargetType = ACPI_TYPE_BUFFER_FIELD;
419 case ACPI_TYPE_BUFFER:
421 if (Index >= Operand[0]->Buffer.Length)
423 Length = Operand[0]->Buffer.Length;
424 Status = AE_AML_BUFFER_LIMIT;
427 ReturnDesc->Reference.TargetType = ACPI_TYPE_BUFFER_FIELD;
430 case ACPI_TYPE_PACKAGE:
432 if (Index >= Operand[0]->Package.Count)
434 Length = Operand[0]->Package.Count;
435 Status = AE_AML_PACKAGE_LIMIT;
438 ReturnDesc->Reference.TargetType = ACPI_TYPE_PACKAGE;
439 ReturnDesc->Reference.Where = &Operand[0]->Package.Elements [Index];
444 Status = AE_AML_INTERNAL;
448 /* Failure means that the Index was beyond the end of the object */
450 if (ACPI_FAILURE (Status))
452 ACPI_EXCEPTION ((AE_INFO, Status,
453 "Index (0x%X%8.8X) is beyond end of object (length 0x%X)",
454 ACPI_FORMAT_UINT64 (Index), (UINT32) Length));
459 * Save the target object and add a reference to it for the life
462 ReturnDesc->Reference.Object = Operand[0];
463 AcpiUtAddReference (Operand[0]);
465 /* Store the reference to the Target */
467 Status = AcpiExStore (ReturnDesc, Operand[2], WalkState);
469 /* Return the reference */
471 WalkState->ResultObj = ReturnDesc;
476 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
478 Status = AE_AML_BAD_OPCODE;
485 if (ACPI_SUCCESS (Status))
488 * Store the result of the operation (which is now in ReturnDesc) into
489 * the Target descriptor.
491 Status = AcpiExStore (ReturnDesc, Operand[2], WalkState);
492 if (ACPI_FAILURE (Status))
497 if (!WalkState->ResultObj)
499 WalkState->ResultObj = ReturnDesc;
506 /* Delete return object on error */
508 if (ACPI_FAILURE (Status))
510 AcpiUtRemoveReference (ReturnDesc);
511 WalkState->ResultObj = NULL;
514 return_ACPI_STATUS (Status);
518 /*******************************************************************************
520 * FUNCTION: AcpiExOpcode_2A_0T_1R
522 * PARAMETERS: WalkState - Current walk state
526 * DESCRIPTION: Execute opcode with 2 arguments, no target, and a return value
528 ******************************************************************************/
531 AcpiExOpcode_2A_0T_1R (
532 ACPI_WALK_STATE *WalkState)
534 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
535 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
536 ACPI_STATUS Status = AE_OK;
537 BOOLEAN LogicalResult = FALSE;
540 ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_0T_1R,
541 AcpiPsGetOpcodeName (WalkState->Opcode));
544 /* Create the internal return object */
546 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
549 Status = AE_NO_MEMORY;
553 /* Execute the Opcode */
555 if (WalkState->OpInfo->Flags & AML_LOGICAL_NUMERIC)
557 /* LogicalOp (Operand0, Operand1) */
559 Status = AcpiExDoLogicalNumericOp (WalkState->Opcode,
560 Operand[0]->Integer.Value, Operand[1]->Integer.Value,
562 goto StoreLogicalResult;
564 else if (WalkState->OpInfo->Flags & AML_LOGICAL)
566 /* LogicalOp (Operand0, Operand1) */
568 Status = AcpiExDoLogicalOp (WalkState->Opcode, Operand[0],
569 Operand[1], &LogicalResult);
570 goto StoreLogicalResult;
573 switch (WalkState->Opcode)
575 case AML_ACQUIRE_OP: /* Acquire (MutexObject, Timeout) */
577 Status = AcpiExAcquireMutex (Operand[1], Operand[0], WalkState);
578 if (Status == AE_TIME)
580 LogicalResult = TRUE; /* TRUE = Acquire timed out */
586 case AML_WAIT_OP: /* Wait (EventObject, Timeout) */
588 Status = AcpiExSystemWaitEvent (Operand[1], Operand[0]);
589 if (Status == AE_TIME)
591 LogicalResult = TRUE; /* TRUE, Wait timed out */
598 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
600 Status = AE_AML_BAD_OPCODE;
607 * Set return value to according to LogicalResult. logical TRUE (all ones)
608 * Default is FALSE (zero)
612 ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
617 /* Delete return object on error */
619 if (ACPI_FAILURE (Status))
621 AcpiUtRemoveReference (ReturnDesc);
624 /* Save return object on success */
628 WalkState->ResultObj = ReturnDesc;
631 return_ACPI_STATUS (Status);