1 /******************************************************************************
3 * Module Name: dswexec - Dispatcher method execution callbacks;
4 * dispatch to interpreter.
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2016, 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.
55 #define _COMPONENT ACPI_DISPATCHER
56 ACPI_MODULE_NAME ("dswexec")
59 * Dispatch table for opcode classes
61 static ACPI_EXECUTE_OP AcpiGbl_OpTypeDispatch
[] =
63 AcpiExOpcode_0A_0T_1R
,
64 AcpiExOpcode_1A_0T_0R
,
65 AcpiExOpcode_1A_0T_1R
,
66 AcpiExOpcode_1A_1T_0R
,
67 AcpiExOpcode_1A_1T_1R
,
68 AcpiExOpcode_2A_0T_0R
,
69 AcpiExOpcode_2A_0T_1R
,
70 AcpiExOpcode_2A_1T_1R
,
71 AcpiExOpcode_2A_2T_1R
,
72 AcpiExOpcode_3A_0T_0R
,
73 AcpiExOpcode_3A_1T_1R
,
78 /*****************************************************************************
80 * FUNCTION: AcpiDsGetPredicateValue
82 * PARAMETERS: WalkState - Current state of the parse tree walk
83 * ResultObj - if non-zero, pop result from result stack
87 * DESCRIPTION: Get the result of a predicate evaluation
89 ****************************************************************************/
92 AcpiDsGetPredicateValue (
93 ACPI_WALK_STATE
*WalkState
,
94 ACPI_OPERAND_OBJECT
*ResultObj
)
96 ACPI_STATUS Status
= AE_OK
;
97 ACPI_OPERAND_OBJECT
*ObjDesc
;
98 ACPI_OPERAND_OBJECT
*LocalObjDesc
= NULL
;
101 ACPI_FUNCTION_TRACE_PTR (DsGetPredicateValue
, WalkState
);
104 WalkState
->ControlState
->Common
.State
= 0;
108 Status
= AcpiDsResultPop (&ObjDesc
, WalkState
);
109 if (ACPI_FAILURE (Status
))
111 ACPI_EXCEPTION ((AE_INFO
, Status
,
112 "Could not get result from predicate evaluation"));
114 return_ACPI_STATUS (Status
);
119 Status
= AcpiDsCreateOperand (WalkState
, WalkState
->Op
, 0);
120 if (ACPI_FAILURE (Status
))
122 return_ACPI_STATUS (Status
);
125 Status
= AcpiExResolveToValue (&WalkState
->Operands
[0], WalkState
);
126 if (ACPI_FAILURE (Status
))
128 return_ACPI_STATUS (Status
);
131 ObjDesc
= WalkState
->Operands
[0];
136 ACPI_ERROR ((AE_INFO
,
137 "No predicate ObjDesc=%p State=%p",
138 ObjDesc
, WalkState
));
140 return_ACPI_STATUS (AE_AML_NO_OPERAND
);
144 * Result of predicate evaluation must be an Integer
145 * object. Implicitly convert the argument if necessary.
147 Status
= AcpiExConvertToInteger (ObjDesc
, &LocalObjDesc
, 16);
148 if (ACPI_FAILURE (Status
))
153 if (LocalObjDesc
->Common
.Type
!= ACPI_TYPE_INTEGER
)
155 ACPI_ERROR ((AE_INFO
,
156 "Bad predicate (not an integer) ObjDesc=%p State=%p Type=0x%X",
157 ObjDesc
, WalkState
, ObjDesc
->Common
.Type
));
159 Status
= AE_AML_OPERAND_TYPE
;
163 /* Truncate the predicate to 32-bits if necessary */
165 (void) AcpiExTruncateFor32bitTable (LocalObjDesc
);
168 * Save the result of the predicate evaluation on
171 if (LocalObjDesc
->Integer
.Value
)
173 WalkState
->ControlState
->Common
.Value
= TRUE
;
178 * Predicate is FALSE, we will just toss the
179 * rest of the package
181 WalkState
->ControlState
->Common
.Value
= FALSE
;
182 Status
= AE_CTRL_FALSE
;
185 /* Predicate can be used for an implicit return value */
187 (void) AcpiDsDoImplicitReturn (LocalObjDesc
, WalkState
, TRUE
);
192 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
193 "Completed a predicate eval=%X Op=%p\n",
194 WalkState
->ControlState
->Common
.Value
, WalkState
->Op
));
197 /* Break to debugger to display result */
199 AcpiDbDisplayResultObject (LocalObjDesc
, WalkState
);
203 * Delete the predicate result object (we know that
204 * we don't need it anymore)
206 if (LocalObjDesc
!= ObjDesc
)
208 AcpiUtRemoveReference (LocalObjDesc
);
210 AcpiUtRemoveReference (ObjDesc
);
212 WalkState
->ControlState
->Common
.State
= ACPI_CONTROL_NORMAL
;
213 return_ACPI_STATUS (Status
);
217 /*****************************************************************************
219 * FUNCTION: AcpiDsExecBeginOp
221 * PARAMETERS: WalkState - Current state of the parse tree walk
222 * OutOp - Where to return op if a new one is created
226 * DESCRIPTION: Descending callback used during the execution of control
227 * methods. This is where most operators and operands are
228 * dispatched to the interpreter.
230 ****************************************************************************/
234 ACPI_WALK_STATE
*WalkState
,
235 ACPI_PARSE_OBJECT
**OutOp
)
237 ACPI_PARSE_OBJECT
*Op
;
238 ACPI_STATUS Status
= AE_OK
;
242 ACPI_FUNCTION_TRACE_PTR (DsExecBeginOp
, WalkState
);
248 Status
= AcpiDsLoad2BeginOp (WalkState
, OutOp
);
249 if (ACPI_FAILURE (Status
))
256 WalkState
->Opcode
= Op
->Common
.AmlOpcode
;
257 WalkState
->OpInfo
= AcpiPsGetOpcodeInfo (Op
->Common
.AmlOpcode
);
259 if (AcpiNsOpensScope (WalkState
->OpInfo
->ObjectType
))
261 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
262 "(%s) Popping scope for Op %p\n",
263 AcpiUtGetTypeName (WalkState
->OpInfo
->ObjectType
), Op
));
265 Status
= AcpiDsScopeStackPop (WalkState
);
266 if (ACPI_FAILURE (Status
))
273 if (Op
== WalkState
->Origin
)
280 return_ACPI_STATUS (AE_OK
);
284 * If the previous opcode was a conditional, this opcode
285 * must be the beginning of the associated predicate.
286 * Save this knowledge in the current scope descriptor
288 if ((WalkState
->ControlState
) &&
289 (WalkState
->ControlState
->Common
.State
==
290 ACPI_CONTROL_CONDITIONAL_EXECUTING
))
292 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
293 "Exec predicate Op=%p State=%p\n",
296 WalkState
->ControlState
->Common
.State
=
297 ACPI_CONTROL_PREDICATE_EXECUTING
;
299 /* Save start of predicate */
301 WalkState
->ControlState
->Control
.PredicateOp
= Op
;
305 OpcodeClass
= WalkState
->OpInfo
->Class
;
307 /* We want to send namepaths to the load code */
309 if (Op
->Common
.AmlOpcode
== AML_INT_NAMEPATH_OP
)
311 OpcodeClass
= AML_CLASS_NAMED_OBJECT
;
315 * Handle the opcode based upon the opcode type
319 case AML_CLASS_CONTROL
:
321 Status
= AcpiDsExecBeginControlOp (WalkState
, Op
);
324 case AML_CLASS_NAMED_OBJECT
:
326 if (WalkState
->WalkType
& ACPI_WALK_METHOD
)
329 * Found a named object declaration during method execution;
330 * we must enter this object into the namespace. The created
331 * object is temporary and will be deleted upon completion of
332 * the execution of this method.
334 * Note 10/2010: Except for the Scope() op. This opcode does
335 * not actually create a new object, it refers to an existing
336 * object. However, for Scope(), we want to indeed open a
339 if (Op
->Common
.AmlOpcode
!= AML_SCOPE_OP
)
341 Status
= AcpiDsLoad2BeginOp (WalkState
, NULL
);
345 Status
= AcpiDsScopeStackPush (
346 Op
->Named
.Node
, Op
->Named
.Node
->Type
, WalkState
);
347 if (ACPI_FAILURE (Status
))
349 return_ACPI_STATUS (Status
);
355 case AML_CLASS_EXECUTE
:
356 case AML_CLASS_CREATE
:
365 /* Nothing to do here during method execution */
367 return_ACPI_STATUS (Status
);
371 Status
= AcpiDsMethodError (Status
, WalkState
);
372 return_ACPI_STATUS (Status
);
376 /*****************************************************************************
378 * FUNCTION: AcpiDsExecEndOp
380 * PARAMETERS: WalkState - Current state of the parse tree walk
384 * DESCRIPTION: Ascending callback used during the execution of control
385 * methods. The only thing we really need to do here is to
386 * notice the beginning of IF, ELSE, and WHILE blocks.
388 ****************************************************************************/
392 ACPI_WALK_STATE
*WalkState
)
394 ACPI_PARSE_OBJECT
*Op
;
395 ACPI_STATUS Status
= AE_OK
;
398 ACPI_PARSE_OBJECT
*NextOp
;
399 ACPI_PARSE_OBJECT
*FirstArg
;
402 ACPI_FUNCTION_TRACE_PTR (DsExecEndOp
, WalkState
);
406 OpType
= WalkState
->OpInfo
->Type
;
407 OpClass
= WalkState
->OpInfo
->Class
;
409 if (OpClass
== AML_CLASS_UNKNOWN
)
411 ACPI_ERROR ((AE_INFO
, "Unknown opcode 0x%X", Op
->Common
.AmlOpcode
));
412 return_ACPI_STATUS (AE_NOT_IMPLEMENTED
);
415 FirstArg
= Op
->Common
.Value
.Arg
;
417 /* Init the walk state */
419 WalkState
->NumOperands
= 0;
420 WalkState
->OperandIndex
= 0;
421 WalkState
->ReturnDesc
= NULL
;
422 WalkState
->ResultObj
= NULL
;
425 /* Call debugger for single step support (DEBUG build only) */
427 Status
= AcpiDbSingleStep (WalkState
, Op
, OpClass
);
428 if (ACPI_FAILURE (Status
))
430 return_ACPI_STATUS (Status
);
434 /* Decode the Opcode Class */
438 case AML_CLASS_ARGUMENT
: /* Constants, literals, etc. */
440 if (WalkState
->Opcode
== AML_INT_NAMEPATH_OP
)
442 Status
= AcpiDsEvaluateNamePath (WalkState
);
443 if (ACPI_FAILURE (Status
))
450 case AML_CLASS_EXECUTE
: /* Most operators with arguments */
452 /* Build resolved operand stack */
454 Status
= AcpiDsCreateOperands (WalkState
, FirstArg
);
455 if (ACPI_FAILURE (Status
))
461 * All opcodes require operand resolution, with the only exceptions
462 * being the ObjectType and SizeOf operators.
464 if (!(WalkState
->OpInfo
->Flags
& AML_NO_OPERAND_RESOLVE
))
466 /* Resolve all operands */
468 Status
= AcpiExResolveOperands (WalkState
->Opcode
,
469 &(WalkState
->Operands
[WalkState
->NumOperands
-1]),
473 if (ACPI_SUCCESS (Status
))
476 * Dispatch the request to the appropriate interpreter handler
477 * routine. There is one routine per opcode "type" based upon the
478 * number of opcode arguments and return type.
480 Status
= AcpiGbl_OpTypeDispatch
[OpType
] (WalkState
);
485 * Treat constructs of the form "Store(LocalX,LocalX)" as noops when the
486 * Local is uninitialized.
488 if ((Status
== AE_AML_UNINITIALIZED_LOCAL
) &&
489 (WalkState
->Opcode
== AML_STORE_OP
) &&
490 (WalkState
->Operands
[0]->Common
.Type
== ACPI_TYPE_LOCAL_REFERENCE
) &&
491 (WalkState
->Operands
[1]->Common
.Type
== ACPI_TYPE_LOCAL_REFERENCE
) &&
492 (WalkState
->Operands
[0]->Reference
.Class
==
493 WalkState
->Operands
[1]->Reference
.Class
) &&
494 (WalkState
->Operands
[0]->Reference
.Value
==
495 WalkState
->Operands
[1]->Reference
.Value
))
501 ACPI_EXCEPTION ((AE_INFO
, Status
,
502 "While resolving operands for [%s]",
503 AcpiPsGetOpcodeName (WalkState
->Opcode
)));
507 /* Always delete the argument objects and clear the operand stack */
509 AcpiDsClearOperands (WalkState
);
512 * If a result object was returned from above, push it on the
513 * current result stack
515 if (ACPI_SUCCESS (Status
) &&
516 WalkState
->ResultObj
)
518 Status
= AcpiDsResultPush (WalkState
->ResultObj
, WalkState
);
526 case AML_TYPE_CONTROL
: /* Type 1 opcode, IF/ELSE/WHILE/NOOP */
528 /* 1 Operand, 0 ExternalResult, 0 InternalResult */
530 Status
= AcpiDsExecEndControlOp (WalkState
, Op
);
534 case AML_TYPE_METHOD_CALL
:
536 * If the method is referenced from within a package
537 * declaration, it is not a invocation of the method, just
540 if ((Op
->Asl
.Parent
) &&
541 ((Op
->Asl
.Parent
->Asl
.AmlOpcode
== AML_PACKAGE_OP
) ||
542 (Op
->Asl
.Parent
->Asl
.AmlOpcode
== AML_VAR_PACKAGE_OP
)))
544 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
545 "Method Reference in a Package, Op=%p\n", Op
));
547 Op
->Common
.Node
= (ACPI_NAMESPACE_NODE
*)
548 Op
->Asl
.Value
.Arg
->Asl
.Node
;
549 AcpiUtAddReference (Op
->Asl
.Value
.Arg
->Asl
.Node
->Object
);
550 return_ACPI_STATUS (AE_OK
);
553 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
554 "Method invocation, Op=%p\n", Op
));
557 * (AML_METHODCALL) Op->Asl.Value.Arg->Asl.Node contains
558 * the method Node pointer
560 /* NextOp points to the op that holds the method name */
564 /* NextOp points to first argument op */
566 NextOp
= NextOp
->Common
.Next
;
569 * Get the method's arguments and put them on the operand stack
571 Status
= AcpiDsCreateOperands (WalkState
, NextOp
);
572 if (ACPI_FAILURE (Status
))
578 * Since the operands will be passed to another control method,
579 * we must resolve all local references here (Local variables,
580 * arguments to *this* method, etc.)
582 Status
= AcpiDsResolveOperands (WalkState
);
583 if (ACPI_FAILURE (Status
))
585 /* On error, clear all resolved operands */
587 AcpiDsClearOperands (WalkState
);
592 * Tell the walk loop to preempt this running method and
593 * execute the new method
595 Status
= AE_CTRL_TRANSFER
;
598 * Return now; we don't want to disturb anything,
599 * especially the operand count!
601 return_ACPI_STATUS (Status
);
603 case AML_TYPE_CREATE_FIELD
:
605 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
606 "Executing CreateField Buffer/Index Op=%p\n", Op
));
608 Status
= AcpiDsLoad2EndOp (WalkState
);
609 if (ACPI_FAILURE (Status
))
614 Status
= AcpiDsEvalBufferFieldOperands (WalkState
, Op
);
618 case AML_TYPE_CREATE_OBJECT
:
620 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
621 "Executing CreateObject (Buffer/Package) Op=%p\n", Op
));
623 switch (Op
->Common
.Parent
->Common
.AmlOpcode
)
627 * Put the Node on the object stack (Contains the ACPI Name
630 WalkState
->Operands
[0] = (void *)
631 Op
->Common
.Parent
->Common
.Node
;
632 WalkState
->NumOperands
= 1;
634 Status
= AcpiDsCreateNode (WalkState
,
635 Op
->Common
.Parent
->Common
.Node
, Op
->Common
.Parent
);
636 if (ACPI_FAILURE (Status
))
642 /*lint -fallthrough */
644 case AML_INT_EVAL_SUBTREE_OP
:
646 Status
= AcpiDsEvalDataObjectOperands (WalkState
, Op
,
647 AcpiNsGetAttachedObject (Op
->Common
.Parent
->Common
.Node
));
652 Status
= AcpiDsEvalDataObjectOperands (WalkState
, Op
, NULL
);
657 * If a result object was returned from above, push it on the
658 * current result stack
660 if (WalkState
->ResultObj
)
662 Status
= AcpiDsResultPush (WalkState
->ResultObj
, WalkState
);
666 case AML_TYPE_NAMED_FIELD
:
667 case AML_TYPE_NAMED_COMPLEX
:
668 case AML_TYPE_NAMED_SIMPLE
:
669 case AML_TYPE_NAMED_NO_OBJ
:
671 Status
= AcpiDsLoad2EndOp (WalkState
);
672 if (ACPI_FAILURE (Status
))
677 if (Op
->Common
.AmlOpcode
== AML_REGION_OP
)
679 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
680 "Executing OpRegion Address/Length Op=%p\n", Op
));
682 Status
= AcpiDsEvalRegionOperands (WalkState
, Op
);
683 if (ACPI_FAILURE (Status
))
688 else if (Op
->Common
.AmlOpcode
== AML_DATA_REGION_OP
)
690 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
691 "Executing DataTableRegion Strings Op=%p\n", Op
));
693 Status
= AcpiDsEvalTableRegionOperands (WalkState
, Op
);
694 if (ACPI_FAILURE (Status
))
699 else if (Op
->Common
.AmlOpcode
== AML_BANK_FIELD_OP
)
701 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
702 "Executing BankField Op=%p\n", Op
));
704 Status
= AcpiDsEvalBankFieldOperands (WalkState
, Op
);
705 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
);
720 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
721 "Internal opcode=%X type Op=%p\n",
722 WalkState
->Opcode
, Op
));
727 ACPI_ERROR ((AE_INFO
,
728 "Unimplemented opcode, class=0x%X "
729 "type=0x%X Opcode=0x%X Op=%p",
730 OpClass
, OpType
, Op
->Common
.AmlOpcode
, Op
));
732 Status
= AE_NOT_IMPLEMENTED
;
738 * ACPI 2.0 support for 64-bit integers: Truncate numeric
739 * result value if we are executing from a 32-bit ACPI table
741 (void) AcpiExTruncateFor32bitTable (WalkState
->ResultObj
);
744 * Check if we just completed the evaluation of a
745 * conditional predicate
747 if ((ACPI_SUCCESS (Status
)) &&
748 (WalkState
->ControlState
) &&
749 (WalkState
->ControlState
->Common
.State
==
750 ACPI_CONTROL_PREDICATE_EXECUTING
) &&
751 (WalkState
->ControlState
->Control
.PredicateOp
== Op
))
753 Status
= AcpiDsGetPredicateValue (WalkState
, WalkState
->ResultObj
);
754 WalkState
->ResultObj
= NULL
;
760 if (WalkState
->ResultObj
)
763 /* Break to debugger to display result */
765 AcpiDbDisplayResultObject (WalkState
->ResultObj
,WalkState
);
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
);