1 /******************************************************************************
3 * Module Name: dswexec - Dispatcher method execution callbacks;
4 * dispatch to interpreter.
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2017, 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
,
148 ACPI_STRTOUL_BASE16
);
149 if (ACPI_FAILURE (Status
))
154 if (LocalObjDesc
->Common
.Type
!= ACPI_TYPE_INTEGER
)
156 ACPI_ERROR ((AE_INFO
,
157 "Bad predicate (not an integer) ObjDesc=%p State=%p Type=0x%X",
158 ObjDesc
, WalkState
, ObjDesc
->Common
.Type
));
160 Status
= AE_AML_OPERAND_TYPE
;
164 /* Truncate the predicate to 32-bits if necessary */
166 (void) AcpiExTruncateFor32bitTable (LocalObjDesc
);
169 * Save the result of the predicate evaluation on
172 if (LocalObjDesc
->Integer
.Value
)
174 WalkState
->ControlState
->Common
.Value
= TRUE
;
179 * Predicate is FALSE, we will just toss the
180 * rest of the package
182 WalkState
->ControlState
->Common
.Value
= FALSE
;
183 Status
= AE_CTRL_FALSE
;
186 /* Predicate can be used for an implicit return value */
188 (void) AcpiDsDoImplicitReturn (LocalObjDesc
, WalkState
, TRUE
);
193 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
194 "Completed a predicate eval=%X Op=%p\n",
195 WalkState
->ControlState
->Common
.Value
, WalkState
->Op
));
197 /* Break to debugger to display result */
199 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
,
292 "Exec predicate Op=%p State=%p\n",
295 WalkState
->ControlState
->Common
.State
=
296 ACPI_CONTROL_PREDICATE_EXECUTING
;
298 /* Save start of predicate */
300 WalkState
->ControlState
->Control
.PredicateOp
= Op
;
304 OpcodeClass
= WalkState
->OpInfo
->Class
;
306 /* We want to send namepaths to the load code */
308 if (Op
->Common
.AmlOpcode
== AML_INT_NAMEPATH_OP
)
310 OpcodeClass
= AML_CLASS_NAMED_OBJECT
;
314 * Handle the opcode based upon the opcode type
318 case AML_CLASS_CONTROL
:
320 Status
= AcpiDsExecBeginControlOp (WalkState
, Op
);
323 case AML_CLASS_NAMED_OBJECT
:
325 if (WalkState
->WalkType
& ACPI_WALK_METHOD
)
328 * Found a named object declaration during method execution;
329 * we must enter this object into the namespace. The created
330 * object is temporary and will be deleted upon completion of
331 * the execution of this method.
333 * Note 10/2010: Except for the Scope() op. This opcode does
334 * not actually create a new object, it refers to an existing
335 * object. However, for Scope(), we want to indeed open a
338 if (Op
->Common
.AmlOpcode
!= AML_SCOPE_OP
)
340 Status
= AcpiDsLoad2BeginOp (WalkState
, NULL
);
344 Status
= AcpiDsScopeStackPush (
345 Op
->Named
.Node
, Op
->Named
.Node
->Type
, WalkState
);
346 if (ACPI_FAILURE (Status
))
348 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 Status
= AcpiDbSingleStep (WalkState
, Op
, OpClass
);
426 if (ACPI_FAILURE (Status
))
428 return_ACPI_STATUS (Status
);
431 /* Decode the Opcode Class */
435 case AML_CLASS_ARGUMENT
: /* Constants, literals, etc. */
437 if (WalkState
->Opcode
== AML_INT_NAMEPATH_OP
)
439 Status
= AcpiDsEvaluateNamePath (WalkState
);
440 if (ACPI_FAILURE (Status
))
447 case AML_CLASS_EXECUTE
: /* Most operators with arguments */
449 /* Build resolved operand stack */
451 Status
= AcpiDsCreateOperands (WalkState
, FirstArg
);
452 if (ACPI_FAILURE (Status
))
458 * All opcodes require operand resolution, with the only exceptions
459 * being the ObjectType and SizeOf operators.
461 if (!(WalkState
->OpInfo
->Flags
& AML_NO_OPERAND_RESOLVE
))
463 /* Resolve all operands */
465 Status
= AcpiExResolveOperands (WalkState
->Opcode
,
466 &(WalkState
->Operands
[WalkState
->NumOperands
-1]),
470 if (ACPI_SUCCESS (Status
))
473 * Dispatch the request to the appropriate interpreter handler
474 * routine. There is one routine per opcode "type" based upon the
475 * number of opcode arguments and return type.
477 Status
= AcpiGbl_OpTypeDispatch
[OpType
] (WalkState
);
482 * Treat constructs of the form "Store(LocalX,LocalX)" as noops when the
483 * Local is uninitialized.
485 if ((Status
== AE_AML_UNINITIALIZED_LOCAL
) &&
486 (WalkState
->Opcode
== AML_STORE_OP
) &&
487 (WalkState
->Operands
[0]->Common
.Type
== ACPI_TYPE_LOCAL_REFERENCE
) &&
488 (WalkState
->Operands
[1]->Common
.Type
== ACPI_TYPE_LOCAL_REFERENCE
) &&
489 (WalkState
->Operands
[0]->Reference
.Class
==
490 WalkState
->Operands
[1]->Reference
.Class
) &&
491 (WalkState
->Operands
[0]->Reference
.Value
==
492 WalkState
->Operands
[1]->Reference
.Value
))
498 ACPI_EXCEPTION ((AE_INFO
, Status
,
499 "While resolving operands for [%s]",
500 AcpiPsGetOpcodeName (WalkState
->Opcode
)));
504 /* Always delete the argument objects and clear the operand stack */
506 AcpiDsClearOperands (WalkState
);
509 * If a result object was returned from above, push it on the
510 * current result stack
512 if (ACPI_SUCCESS (Status
) &&
513 WalkState
->ResultObj
)
515 Status
= AcpiDsResultPush (WalkState
->ResultObj
, WalkState
);
523 case AML_TYPE_CONTROL
: /* Type 1 opcode, IF/ELSE/WHILE/NOOP */
525 /* 1 Operand, 0 ExternalResult, 0 InternalResult */
527 Status
= AcpiDsExecEndControlOp (WalkState
, Op
);
531 case AML_TYPE_METHOD_CALL
:
533 * If the method is referenced from within a package
534 * declaration, it is not a invocation of the method, just
537 if ((Op
->Asl
.Parent
) &&
538 ((Op
->Asl
.Parent
->Asl
.AmlOpcode
== AML_PACKAGE_OP
) ||
539 (Op
->Asl
.Parent
->Asl
.AmlOpcode
== AML_VARIABLE_PACKAGE_OP
)))
541 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
542 "Method Reference in a Package, Op=%p\n", Op
));
544 Op
->Common
.Node
= (ACPI_NAMESPACE_NODE
*)
545 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
,
551 "Method invocation, Op=%p\n", Op
));
554 * (AML_METHODCALL) Op->Asl.Value.Arg->Asl.Node contains
555 * the method Node pointer
557 /* NextOp points to the op that holds the method name */
561 /* NextOp points to first argument op */
563 NextOp
= NextOp
->Common
.Next
;
566 * Get the method's arguments and put them on the operand stack
568 Status
= AcpiDsCreateOperands (WalkState
, NextOp
);
569 if (ACPI_FAILURE (Status
))
575 * Since the operands will be passed to another control method,
576 * we must resolve all local references here (Local variables,
577 * arguments to *this* method, etc.)
579 Status
= AcpiDsResolveOperands (WalkState
);
580 if (ACPI_FAILURE (Status
))
582 /* On error, clear all resolved operands */
584 AcpiDsClearOperands (WalkState
);
589 * Tell the walk loop to preempt this running method and
590 * execute the new method
592 Status
= AE_CTRL_TRANSFER
;
595 * Return now; we don't want to disturb anything,
596 * especially the operand count!
598 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
)
624 * Put the Node on the object stack (Contains the ACPI Name
627 WalkState
->Operands
[0] = (void *)
628 Op
->Common
.Parent
->Common
.Node
;
629 WalkState
->NumOperands
= 1;
631 Status
= AcpiDsCreateNode (WalkState
,
632 Op
->Common
.Parent
->Common
.Node
, Op
->Common
.Parent
);
633 if (ACPI_FAILURE (Status
))
639 /*lint -fallthrough */
641 case AML_INT_EVAL_SUBTREE_OP
:
643 Status
= AcpiDsEvalDataObjectOperands (WalkState
, Op
,
644 AcpiNsGetAttachedObject (Op
->Common
.Parent
->Common
.Node
));
649 Status
= AcpiDsEvalDataObjectOperands (WalkState
, Op
, NULL
);
654 * If a result object was returned from above, push it on the
655 * current result stack
657 if (WalkState
->ResultObj
)
659 Status
= AcpiDsResultPush (WalkState
->ResultObj
, WalkState
);
663 case AML_TYPE_NAMED_FIELD
:
664 case AML_TYPE_NAMED_COMPLEX
:
665 case AML_TYPE_NAMED_SIMPLE
:
666 case AML_TYPE_NAMED_NO_OBJ
:
668 Status
= AcpiDsLoad2EndOp (WalkState
);
669 if (ACPI_FAILURE (Status
))
674 if (Op
->Common
.AmlOpcode
== AML_REGION_OP
)
676 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
677 "Executing OpRegion Address/Length Op=%p\n", Op
));
679 Status
= AcpiDsEvalRegionOperands (WalkState
, Op
);
680 if (ACPI_FAILURE (Status
))
685 else if (Op
->Common
.AmlOpcode
== AML_DATA_REGION_OP
)
687 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
688 "Executing DataTableRegion Strings Op=%p\n", Op
));
690 Status
= AcpiDsEvalTableRegionOperands (WalkState
, Op
);
691 if (ACPI_FAILURE (Status
))
696 else if (Op
->Common
.AmlOpcode
== AML_BANK_FIELD_OP
)
698 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
699 "Executing BankField Op=%p\n", Op
));
701 Status
= AcpiDsEvalBankFieldOperands (WalkState
, Op
);
702 if (ACPI_FAILURE (Status
))
709 case AML_TYPE_UNDEFINED
:
711 ACPI_ERROR ((AE_INFO
,
712 "Undefined opcode type Op=%p", Op
));
713 return_ACPI_STATUS (AE_NOT_IMPLEMENTED
);
717 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
718 "Internal opcode=%X type Op=%p\n",
719 WalkState
->Opcode
, Op
));
724 ACPI_ERROR ((AE_INFO
,
725 "Unimplemented opcode, class=0x%X "
726 "type=0x%X Opcode=0x%X Op=%p",
727 OpClass
, OpType
, Op
->Common
.AmlOpcode
, Op
));
729 Status
= AE_NOT_IMPLEMENTED
;
735 * ACPI 2.0 support for 64-bit integers: Truncate numeric
736 * result value if we are executing from a 32-bit ACPI table
738 (void) AcpiExTruncateFor32bitTable (WalkState
->ResultObj
);
741 * Check if we just completed the evaluation of a
742 * conditional predicate
744 if ((ACPI_SUCCESS (Status
)) &&
745 (WalkState
->ControlState
) &&
746 (WalkState
->ControlState
->Common
.State
==
747 ACPI_CONTROL_PREDICATE_EXECUTING
) &&
748 (WalkState
->ControlState
->Control
.PredicateOp
== Op
))
750 Status
= AcpiDsGetPredicateValue (WalkState
, WalkState
->ResultObj
);
751 WalkState
->ResultObj
= NULL
;
757 if (WalkState
->ResultObj
)
759 /* Break to debugger to display result */
761 AcpiDbDisplayResultObject (WalkState
->ResultObj
,WalkState
);
764 * Delete the result op if and only if:
765 * Parent will not use the result -- such as any
766 * non-nested type2 op in a method (parent will be method)
768 AcpiDsDeleteResultIfNotUsed (Op
, WalkState
->ResultObj
, WalkState
);
771 #ifdef _UNDER_DEVELOPMENT
773 if (WalkState
->ParserState
.Aml
== WalkState
->ParserState
.AmlEnd
)
775 AcpiDbMethodEnd (WalkState
);
779 /* Invoke exception handler on error */
781 if (ACPI_FAILURE (Status
))
783 Status
= AcpiDsMethodError (Status
, WalkState
);
786 /* Always clear the object stack */
788 WalkState
->NumOperands
= 0;
789 return_ACPI_STATUS (Status
);