1 /******************************************************************************
3 * Module Name: dswexec - Dispatcher method execution callbacks;
4 * dispatch to interpreter.
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2011, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
47 #include <contrib/dev/acpica/include/acpi.h>
48 #include <contrib/dev/acpica/include/accommon.h>
49 #include <contrib/dev/acpica/include/acparser.h>
50 #include <contrib/dev/acpica/include/amlcode.h>
51 #include <contrib/dev/acpica/include/acdispat.h>
52 #include <contrib/dev/acpica/include/acinterp.h>
53 #include <contrib/dev/acpica/include/acnamesp.h>
54 #include <contrib/dev/acpica/include/acdebug.h>
57 #define _COMPONENT ACPI_DISPATCHER
58 ACPI_MODULE_NAME ("dswexec")
61 * Dispatch table for opcode classes
63 static ACPI_EXECUTE_OP AcpiGbl_OpTypeDispatch [] =
65 AcpiExOpcode_0A_0T_1R,
66 AcpiExOpcode_1A_0T_0R,
67 AcpiExOpcode_1A_0T_1R,
68 AcpiExOpcode_1A_1T_0R,
69 AcpiExOpcode_1A_1T_1R,
70 AcpiExOpcode_2A_0T_0R,
71 AcpiExOpcode_2A_0T_1R,
72 AcpiExOpcode_2A_1T_1R,
73 AcpiExOpcode_2A_2T_1R,
74 AcpiExOpcode_3A_0T_0R,
75 AcpiExOpcode_3A_1T_1R,
80 /*****************************************************************************
82 * FUNCTION: AcpiDsGetPredicateValue
84 * PARAMETERS: WalkState - Current state of the parse tree walk
85 * ResultObj - if non-zero, pop result from result stack
89 * DESCRIPTION: Get the result of a predicate evaluation
91 ****************************************************************************/
94 AcpiDsGetPredicateValue (
95 ACPI_WALK_STATE *WalkState,
96 ACPI_OPERAND_OBJECT *ResultObj)
98 ACPI_STATUS Status = AE_OK;
99 ACPI_OPERAND_OBJECT *ObjDesc;
100 ACPI_OPERAND_OBJECT *LocalObjDesc = NULL;
103 ACPI_FUNCTION_TRACE_PTR (DsGetPredicateValue, WalkState);
106 WalkState->ControlState->Common.State = 0;
110 Status = AcpiDsResultPop (&ObjDesc, WalkState);
111 if (ACPI_FAILURE (Status))
113 ACPI_EXCEPTION ((AE_INFO, Status,
114 "Could not get result from predicate evaluation"));
116 return_ACPI_STATUS (Status);
121 Status = AcpiDsCreateOperand (WalkState, WalkState->Op, 0);
122 if (ACPI_FAILURE (Status))
124 return_ACPI_STATUS (Status);
127 Status = AcpiExResolveToValue (&WalkState->Operands [0], WalkState);
128 if (ACPI_FAILURE (Status))
130 return_ACPI_STATUS (Status);
133 ObjDesc = WalkState->Operands [0];
138 ACPI_ERROR ((AE_INFO,
139 "No predicate ObjDesc=%p State=%p",
140 ObjDesc, WalkState));
142 return_ACPI_STATUS (AE_AML_NO_OPERAND);
146 * Result of predicate evaluation must be an Integer
147 * object. Implicitly convert the argument if necessary.
149 Status = AcpiExConvertToInteger (ObjDesc, &LocalObjDesc, 16);
150 if (ACPI_FAILURE (Status))
155 if (LocalObjDesc->Common.Type != ACPI_TYPE_INTEGER)
157 ACPI_ERROR ((AE_INFO,
158 "Bad predicate (not an integer) ObjDesc=%p State=%p Type=0x%X",
159 ObjDesc, WalkState, ObjDesc->Common.Type));
161 Status = AE_AML_OPERAND_TYPE;
165 /* Truncate the predicate to 32-bits if necessary */
167 AcpiExTruncateFor32bitTable (LocalObjDesc);
170 * Save the result of the predicate evaluation on
173 if (LocalObjDesc->Integer.Value)
175 WalkState->ControlState->Common.Value = TRUE;
180 * Predicate is FALSE, we will just toss the
181 * rest of the package
183 WalkState->ControlState->Common.Value = FALSE;
184 Status = AE_CTRL_FALSE;
187 /* Predicate can be used for an implicit return value */
189 (void) AcpiDsDoImplicitReturn (LocalObjDesc, WalkState, TRUE);
194 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Completed a predicate eval=%X Op=%p\n",
195 WalkState->ControlState->Common.Value, WalkState->Op));
197 /* Break to debugger to display result */
199 ACPI_DEBUGGER_EXEC (AcpiDbDisplayResultObject (LocalObjDesc, WalkState));
202 * Delete the predicate result object (we know that
203 * we don't need it anymore)
205 if (LocalObjDesc != ObjDesc)
207 AcpiUtRemoveReference (LocalObjDesc);
209 AcpiUtRemoveReference (ObjDesc);
211 WalkState->ControlState->Common.State = ACPI_CONTROL_NORMAL;
212 return_ACPI_STATUS (Status);
216 /*****************************************************************************
218 * FUNCTION: AcpiDsExecBeginOp
220 * PARAMETERS: WalkState - Current state of the parse tree walk
221 * OutOp - Where to return op if a new one is created
225 * DESCRIPTION: Descending callback used during the execution of control
226 * methods. This is where most operators and operands are
227 * dispatched to the interpreter.
229 ****************************************************************************/
233 ACPI_WALK_STATE *WalkState,
234 ACPI_PARSE_OBJECT **OutOp)
236 ACPI_PARSE_OBJECT *Op;
237 ACPI_STATUS Status = AE_OK;
241 ACPI_FUNCTION_TRACE_PTR (DsExecBeginOp, WalkState);
247 Status = AcpiDsLoad2BeginOp (WalkState, OutOp);
248 if (ACPI_FAILURE (Status))
255 WalkState->Opcode = Op->Common.AmlOpcode;
256 WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
258 if (AcpiNsOpensScope (WalkState->OpInfo->ObjectType))
260 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
261 "(%s) Popping scope for Op %p\n",
262 AcpiUtGetTypeName (WalkState->OpInfo->ObjectType), Op));
264 Status = AcpiDsScopeStackPop (WalkState);
265 if (ACPI_FAILURE (Status))
272 if (Op == WalkState->Origin)
279 return_ACPI_STATUS (AE_OK);
283 * If the previous opcode was a conditional, this opcode
284 * must be the beginning of the associated predicate.
285 * Save this knowledge in the current scope descriptor
287 if ((WalkState->ControlState) &&
288 (WalkState->ControlState->Common.State ==
289 ACPI_CONTROL_CONDITIONAL_EXECUTING))
291 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Exec predicate Op=%p State=%p\n",
294 WalkState->ControlState->Common.State = ACPI_CONTROL_PREDICATE_EXECUTING;
296 /* Save start of predicate */
298 WalkState->ControlState->Control.PredicateOp = Op;
302 OpcodeClass = WalkState->OpInfo->Class;
304 /* We want to send namepaths to the load code */
306 if (Op->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
308 OpcodeClass = AML_CLASS_NAMED_OBJECT;
312 * Handle the opcode based upon the opcode type
316 case AML_CLASS_CONTROL:
318 Status = AcpiDsExecBeginControlOp (WalkState, Op);
322 case AML_CLASS_NAMED_OBJECT:
324 if (WalkState->WalkType & ACPI_WALK_METHOD)
327 * Found a named object declaration during method execution;
328 * we must enter this object into the namespace. The created
329 * object is temporary and will be deleted upon completion of
330 * the execution of this method.
332 * Note 10/2010: Except for the Scope() op. This opcode does
333 * not actually create a new object, it refers to an existing
334 * object. However, for Scope(), we want to indeed open a
337 if (Op->Common.AmlOpcode != AML_SCOPE_OP)
339 Status = AcpiDsLoad2BeginOp (WalkState, NULL);
343 Status = AcpiDsScopeStackPush (Op->Named.Node,
344 Op->Named.Node->Type, WalkState);
345 if (ACPI_FAILURE (Status))
347 return_ACPI_STATUS (Status);
354 case AML_CLASS_EXECUTE:
355 case AML_CLASS_CREATE:
364 /* Nothing to do here during method execution */
366 return_ACPI_STATUS (Status);
370 Status = AcpiDsMethodError (Status, WalkState);
371 return_ACPI_STATUS (Status);
375 /*****************************************************************************
377 * FUNCTION: AcpiDsExecEndOp
379 * PARAMETERS: WalkState - Current state of the parse tree walk
383 * DESCRIPTION: Ascending callback used during the execution of control
384 * methods. The only thing we really need to do here is to
385 * notice the beginning of IF, ELSE, and WHILE blocks.
387 ****************************************************************************/
391 ACPI_WALK_STATE *WalkState)
393 ACPI_PARSE_OBJECT *Op;
394 ACPI_STATUS Status = AE_OK;
397 ACPI_PARSE_OBJECT *NextOp;
398 ACPI_PARSE_OBJECT *FirstArg;
401 ACPI_FUNCTION_TRACE_PTR (DsExecEndOp, WalkState);
405 OpType = WalkState->OpInfo->Type;
406 OpClass = WalkState->OpInfo->Class;
408 if (OpClass == AML_CLASS_UNKNOWN)
410 ACPI_ERROR ((AE_INFO, "Unknown opcode 0x%X", Op->Common.AmlOpcode));
411 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
414 FirstArg = Op->Common.Value.Arg;
416 /* Init the walk state */
418 WalkState->NumOperands = 0;
419 WalkState->OperandIndex = 0;
420 WalkState->ReturnDesc = NULL;
421 WalkState->ResultObj = NULL;
423 /* Call debugger for single step support (DEBUG build only) */
425 ACPI_DEBUGGER_EXEC (Status = AcpiDbSingleStep (WalkState, Op, OpClass));
426 ACPI_DEBUGGER_EXEC (if (ACPI_FAILURE (Status)) {return_ACPI_STATUS (Status);});
428 /* Decode the Opcode Class */
432 case AML_CLASS_ARGUMENT: /* Constants, literals, etc. */
434 if (WalkState->Opcode == AML_INT_NAMEPATH_OP)
436 Status = AcpiDsEvaluateNamePath (WalkState);
437 if (ACPI_FAILURE (Status))
445 case AML_CLASS_EXECUTE: /* Most operators with arguments */
447 /* Build resolved operand stack */
449 Status = AcpiDsCreateOperands (WalkState, FirstArg);
450 if (ACPI_FAILURE (Status))
456 * All opcodes require operand resolution, with the only exceptions
457 * being the ObjectType and SizeOf operators.
459 if (!(WalkState->OpInfo->Flags & AML_NO_OPERAND_RESOLVE))
461 /* Resolve all operands */
463 Status = AcpiExResolveOperands (WalkState->Opcode,
464 &(WalkState->Operands [WalkState->NumOperands -1]),
468 if (ACPI_SUCCESS (Status))
471 * Dispatch the request to the appropriate interpreter handler
472 * routine. There is one routine per opcode "type" based upon the
473 * number of opcode arguments and return type.
475 Status = AcpiGbl_OpTypeDispatch[OpType] (WalkState);
480 * Treat constructs of the form "Store(LocalX,LocalX)" as noops when the
481 * Local is uninitialized.
483 if ((Status == AE_AML_UNINITIALIZED_LOCAL) &&
484 (WalkState->Opcode == AML_STORE_OP) &&
485 (WalkState->Operands[0]->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
486 (WalkState->Operands[1]->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
487 (WalkState->Operands[0]->Reference.Class ==
488 WalkState->Operands[1]->Reference.Class) &&
489 (WalkState->Operands[0]->Reference.Value ==
490 WalkState->Operands[1]->Reference.Value))
496 ACPI_EXCEPTION ((AE_INFO, Status,
497 "While resolving operands for [%s]",
498 AcpiPsGetOpcodeName (WalkState->Opcode)));
502 /* Always delete the argument objects and clear the operand stack */
504 AcpiDsClearOperands (WalkState);
507 * If a result object was returned from above, push it on the
508 * current result stack
510 if (ACPI_SUCCESS (Status) &&
511 WalkState->ResultObj)
513 Status = AcpiDsResultPush (WalkState->ResultObj, WalkState);
522 case AML_TYPE_CONTROL: /* Type 1 opcode, IF/ELSE/WHILE/NOOP */
524 /* 1 Operand, 0 ExternalResult, 0 InternalResult */
526 Status = AcpiDsExecEndControlOp (WalkState, Op);
531 case AML_TYPE_METHOD_CALL:
534 * If the method is referenced from within a package
535 * declaration, it is not a invocation of the method, just
538 if ((Op->Asl.Parent) &&
539 ((Op->Asl.Parent->Asl.AmlOpcode == AML_PACKAGE_OP) ||
540 (Op->Asl.Parent->Asl.AmlOpcode == AML_VAR_PACKAGE_OP)))
542 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
543 "Method Reference in a Package, Op=%p\n", Op));
545 Op->Common.Node = (ACPI_NAMESPACE_NODE *) Op->Asl.Value.Arg->Asl.Node;
546 AcpiUtAddReference (Op->Asl.Value.Arg->Asl.Node->Object);
547 return_ACPI_STATUS (AE_OK);
550 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Method invocation, Op=%p\n", Op));
553 * (AML_METHODCALL) Op->Asl.Value.Arg->Asl.Node contains
554 * the method Node pointer
556 /* NextOp points to the op that holds the method name */
560 /* NextOp points to first argument op */
562 NextOp = NextOp->Common.Next;
565 * Get the method's arguments and put them on the operand stack
567 Status = AcpiDsCreateOperands (WalkState, NextOp);
568 if (ACPI_FAILURE (Status))
574 * Since the operands will be passed to another control method,
575 * we must resolve all local references here (Local variables,
576 * arguments to *this* method, etc.)
578 Status = AcpiDsResolveOperands (WalkState);
579 if (ACPI_FAILURE (Status))
581 /* On error, clear all resolved operands */
583 AcpiDsClearOperands (WalkState);
588 * Tell the walk loop to preempt this running method and
589 * execute the new method
591 Status = AE_CTRL_TRANSFER;
594 * Return now; we don't want to disturb anything,
595 * especially the operand count!
597 return_ACPI_STATUS (Status);
600 case AML_TYPE_CREATE_FIELD:
602 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
603 "Executing CreateField Buffer/Index Op=%p\n", Op));
605 Status = AcpiDsLoad2EndOp (WalkState);
606 if (ACPI_FAILURE (Status))
611 Status = AcpiDsEvalBufferFieldOperands (WalkState, Op);
615 case AML_TYPE_CREATE_OBJECT:
617 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
618 "Executing CreateObject (Buffer/Package) Op=%p\n", Op));
620 switch (Op->Common.Parent->Common.AmlOpcode)
625 * Put the Node on the object stack (Contains the ACPI Name
628 WalkState->Operands[0] = (void *) Op->Common.Parent->Common.Node;
629 WalkState->NumOperands = 1;
631 Status = AcpiDsCreateNode (WalkState,
632 Op->Common.Parent->Common.Node,
634 if (ACPI_FAILURE (Status))
640 /*lint -fallthrough */
642 case AML_INT_EVAL_SUBTREE_OP:
644 Status = AcpiDsEvalDataObjectOperands (WalkState, Op,
645 AcpiNsGetAttachedObject (Op->Common.Parent->Common.Node));
650 Status = AcpiDsEvalDataObjectOperands (WalkState, Op, NULL);
655 * If a result object was returned from above, push it on the
656 * current result stack
658 if (WalkState->ResultObj)
660 Status = AcpiDsResultPush (WalkState->ResultObj, WalkState);
665 case AML_TYPE_NAMED_FIELD:
666 case AML_TYPE_NAMED_COMPLEX:
667 case AML_TYPE_NAMED_SIMPLE:
668 case AML_TYPE_NAMED_NO_OBJ:
670 Status = AcpiDsLoad2EndOp (WalkState);
671 if (ACPI_FAILURE (Status))
676 if (Op->Common.AmlOpcode == AML_REGION_OP)
678 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
679 "Executing OpRegion Address/Length Op=%p\n", Op));
681 Status = AcpiDsEvalRegionOperands (WalkState, Op);
682 if (ACPI_FAILURE (Status))
687 else if (Op->Common.AmlOpcode == AML_DATA_REGION_OP)
689 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
690 "Executing DataTableRegion Strings Op=%p\n", Op));
692 Status = AcpiDsEvalTableRegionOperands (WalkState, Op);
693 if (ACPI_FAILURE (Status))
698 else if (Op->Common.AmlOpcode == AML_BANK_FIELD_OP)
700 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
701 "Executing BankField Op=%p\n", Op));
703 Status = AcpiDsEvalBankFieldOperands (WalkState, Op);
704 if (ACPI_FAILURE (Status))
712 case AML_TYPE_UNDEFINED:
714 ACPI_ERROR ((AE_INFO,
715 "Undefined opcode type Op=%p", Op));
716 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
721 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
722 "Internal opcode=%X type Op=%p\n",
723 WalkState->Opcode, Op));
729 ACPI_ERROR ((AE_INFO,
730 "Unimplemented opcode, class=0x%X type=0x%X Opcode=-0x%X Op=%p",
731 OpClass, OpType, Op->Common.AmlOpcode, Op));
733 Status = AE_NOT_IMPLEMENTED;
739 * ACPI 2.0 support for 64-bit integers: Truncate numeric
740 * result value if we are executing from a 32-bit ACPI table
742 AcpiExTruncateFor32bitTable (WalkState->ResultObj);
745 * Check if we just completed the evaluation of a
746 * conditional predicate
748 if ((ACPI_SUCCESS (Status)) &&
749 (WalkState->ControlState) &&
750 (WalkState->ControlState->Common.State ==
751 ACPI_CONTROL_PREDICATE_EXECUTING) &&
752 (WalkState->ControlState->Control.PredicateOp == Op))
754 Status = AcpiDsGetPredicateValue (WalkState, WalkState->ResultObj);
755 WalkState->ResultObj = NULL;
761 if (WalkState->ResultObj)
763 /* Break to debugger to display result */
765 ACPI_DEBUGGER_EXEC (AcpiDbDisplayResultObject (WalkState->ResultObj,
769 * Delete the result op if and only if:
770 * Parent will not use the result -- such as any
771 * non-nested type2 op in a method (parent will be method)
773 AcpiDsDeleteResultIfNotUsed (Op, WalkState->ResultObj, WalkState);
776 #ifdef _UNDER_DEVELOPMENT
778 if (WalkState->ParserState.Aml == WalkState->ParserState.AmlEnd)
780 AcpiDbMethodEnd (WalkState);
784 /* Invoke exception handler on error */
786 if (ACPI_FAILURE (Status))
788 Status = AcpiDsMethodError (Status, WalkState);
791 /* Always clear the object stack */
793 WalkState->NumOperands = 0;
794 return_ACPI_STATUS (Status);