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
));
196 /* Break to debugger to display result */
198 AcpiDbDisplayResultObject (LocalObjDesc
, WalkState
);
201 * Delete the predicate result object (we know that
202 * we don't need it anymore)
204 if (LocalObjDesc
!= ObjDesc
)
206 AcpiUtRemoveReference (LocalObjDesc
);
208 AcpiUtRemoveReference (ObjDesc
);
210 WalkState
->ControlState
->Common
.State
= ACPI_CONTROL_NORMAL
;
211 return_ACPI_STATUS (Status
);
215 /*****************************************************************************
217 * FUNCTION: AcpiDsExecBeginOp
219 * PARAMETERS: WalkState - Current state of the parse tree walk
220 * OutOp - Where to return op if a new one is created
224 * DESCRIPTION: Descending callback used during the execution of control
225 * methods. This is where most operators and operands are
226 * dispatched to the interpreter.
228 ****************************************************************************/
232 ACPI_WALK_STATE
*WalkState
,
233 ACPI_PARSE_OBJECT
**OutOp
)
235 ACPI_PARSE_OBJECT
*Op
;
236 ACPI_STATUS Status
= AE_OK
;
240 ACPI_FUNCTION_TRACE_PTR (DsExecBeginOp
, WalkState
);
246 Status
= AcpiDsLoad2BeginOp (WalkState
, OutOp
);
247 if (ACPI_FAILURE (Status
))
254 WalkState
->Opcode
= Op
->Common
.AmlOpcode
;
255 WalkState
->OpInfo
= AcpiPsGetOpcodeInfo (Op
->Common
.AmlOpcode
);
257 if (AcpiNsOpensScope (WalkState
->OpInfo
->ObjectType
))
259 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
260 "(%s) Popping scope for Op %p\n",
261 AcpiUtGetTypeName (WalkState
->OpInfo
->ObjectType
), Op
));
263 Status
= AcpiDsScopeStackPop (WalkState
);
264 if (ACPI_FAILURE (Status
))
271 if (Op
== WalkState
->Origin
)
278 return_ACPI_STATUS (AE_OK
);
282 * If the previous opcode was a conditional, this opcode
283 * must be the beginning of the associated predicate.
284 * Save this knowledge in the current scope descriptor
286 if ((WalkState
->ControlState
) &&
287 (WalkState
->ControlState
->Common
.State
==
288 ACPI_CONTROL_CONDITIONAL_EXECUTING
))
290 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
291 "Exec predicate Op=%p State=%p\n",
294 WalkState
->ControlState
->Common
.State
=
295 ACPI_CONTROL_PREDICATE_EXECUTING
;
297 /* Save start of predicate */
299 WalkState
->ControlState
->Control
.PredicateOp
= Op
;
303 OpcodeClass
= WalkState
->OpInfo
->Class
;
305 /* We want to send namepaths to the load code */
307 if (Op
->Common
.AmlOpcode
== AML_INT_NAMEPATH_OP
)
309 OpcodeClass
= AML_CLASS_NAMED_OBJECT
;
313 * Handle the opcode based upon the opcode type
317 case AML_CLASS_CONTROL
:
319 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 (
344 Op
->Named
.Node
, Op
->Named
.Node
->Type
, WalkState
);
345 if (ACPI_FAILURE (Status
))
347 return_ACPI_STATUS (Status
);
353 case AML_CLASS_EXECUTE
:
354 case AML_CLASS_CREATE
:
363 /* Nothing to do here during method execution */
365 return_ACPI_STATUS (Status
);
369 Status
= AcpiDsMethodError (Status
, WalkState
);
370 return_ACPI_STATUS (Status
);
374 /*****************************************************************************
376 * FUNCTION: AcpiDsExecEndOp
378 * PARAMETERS: WalkState - Current state of the parse tree walk
382 * DESCRIPTION: Ascending callback used during the execution of control
383 * methods. The only thing we really need to do here is to
384 * notice the beginning of IF, ELSE, and WHILE blocks.
386 ****************************************************************************/
390 ACPI_WALK_STATE
*WalkState
)
392 ACPI_PARSE_OBJECT
*Op
;
393 ACPI_STATUS Status
= AE_OK
;
396 ACPI_PARSE_OBJECT
*NextOp
;
397 ACPI_PARSE_OBJECT
*FirstArg
;
400 ACPI_FUNCTION_TRACE_PTR (DsExecEndOp
, WalkState
);
404 OpType
= WalkState
->OpInfo
->Type
;
405 OpClass
= WalkState
->OpInfo
->Class
;
407 if (OpClass
== AML_CLASS_UNKNOWN
)
409 ACPI_ERROR ((AE_INFO
, "Unknown opcode 0x%X", Op
->Common
.AmlOpcode
));
410 return_ACPI_STATUS (AE_NOT_IMPLEMENTED
);
413 FirstArg
= Op
->Common
.Value
.Arg
;
415 /* Init the walk state */
417 WalkState
->NumOperands
= 0;
418 WalkState
->OperandIndex
= 0;
419 WalkState
->ReturnDesc
= NULL
;
420 WalkState
->ResultObj
= NULL
;
422 /* Call debugger for single step support (DEBUG build only) */
424 Status
= AcpiDbSingleStep (WalkState
, Op
, OpClass
);
425 if (ACPI_FAILURE (Status
))
427 return_ACPI_STATUS (Status
);
430 /* Decode the Opcode Class */
434 case AML_CLASS_ARGUMENT
: /* Constants, literals, etc. */
436 if (WalkState
->Opcode
== AML_INT_NAMEPATH_OP
)
438 Status
= AcpiDsEvaluateNamePath (WalkState
);
439 if (ACPI_FAILURE (Status
))
446 case AML_CLASS_EXECUTE
: /* Most operators with arguments */
448 /* Build resolved operand stack */
450 Status
= AcpiDsCreateOperands (WalkState
, FirstArg
);
451 if (ACPI_FAILURE (Status
))
457 * All opcodes require operand resolution, with the only exceptions
458 * being the ObjectType and SizeOf operators.
460 if (!(WalkState
->OpInfo
->Flags
& AML_NO_OPERAND_RESOLVE
))
462 /* Resolve all operands */
464 Status
= AcpiExResolveOperands (WalkState
->Opcode
,
465 &(WalkState
->Operands
[WalkState
->NumOperands
-1]),
469 if (ACPI_SUCCESS (Status
))
472 * Dispatch the request to the appropriate interpreter handler
473 * routine. There is one routine per opcode "type" based upon the
474 * number of opcode arguments and return type.
476 Status
= AcpiGbl_OpTypeDispatch
[OpType
] (WalkState
);
481 * Treat constructs of the form "Store(LocalX,LocalX)" as noops when the
482 * Local is uninitialized.
484 if ((Status
== AE_AML_UNINITIALIZED_LOCAL
) &&
485 (WalkState
->Opcode
== AML_STORE_OP
) &&
486 (WalkState
->Operands
[0]->Common
.Type
== ACPI_TYPE_LOCAL_REFERENCE
) &&
487 (WalkState
->Operands
[1]->Common
.Type
== ACPI_TYPE_LOCAL_REFERENCE
) &&
488 (WalkState
->Operands
[0]->Reference
.Class
==
489 WalkState
->Operands
[1]->Reference
.Class
) &&
490 (WalkState
->Operands
[0]->Reference
.Value
==
491 WalkState
->Operands
[1]->Reference
.Value
))
497 ACPI_EXCEPTION ((AE_INFO
, Status
,
498 "While resolving operands for [%s]",
499 AcpiPsGetOpcodeName (WalkState
->Opcode
)));
503 /* Always delete the argument objects and clear the operand stack */
505 AcpiDsClearOperands (WalkState
);
508 * If a result object was returned from above, push it on the
509 * current result stack
511 if (ACPI_SUCCESS (Status
) &&
512 WalkState
->ResultObj
)
514 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
);
530 case AML_TYPE_METHOD_CALL
:
532 * If the method is referenced from within a package
533 * declaration, it is not a invocation of the method, just
536 if ((Op
->Asl
.Parent
) &&
537 ((Op
->Asl
.Parent
->Asl
.AmlOpcode
== AML_PACKAGE_OP
) ||
538 (Op
->Asl
.Parent
->Asl
.AmlOpcode
== AML_VAR_PACKAGE_OP
)))
540 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
541 "Method Reference in a Package, Op=%p\n", Op
));
543 Op
->Common
.Node
= (ACPI_NAMESPACE_NODE
*)
544 Op
->Asl
.Value
.Arg
->Asl
.Node
;
545 AcpiUtAddReference (Op
->Asl
.Value
.Arg
->Asl
.Node
->Object
);
546 return_ACPI_STATUS (AE_OK
);
549 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
550 "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
);
599 case AML_TYPE_CREATE_FIELD
:
601 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
602 "Executing CreateField Buffer/Index Op=%p\n", Op
));
604 Status
= AcpiDsLoad2EndOp (WalkState
);
605 if (ACPI_FAILURE (Status
))
610 Status
= AcpiDsEvalBufferFieldOperands (WalkState
, Op
);
614 case AML_TYPE_CREATE_OBJECT
:
616 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
617 "Executing CreateObject (Buffer/Package) Op=%p\n", Op
));
619 switch (Op
->Common
.Parent
->Common
.AmlOpcode
)
623 * Put the Node on the object stack (Contains the ACPI Name
626 WalkState
->Operands
[0] = (void *)
627 Op
->Common
.Parent
->Common
.Node
;
628 WalkState
->NumOperands
= 1;
630 Status
= AcpiDsCreateNode (WalkState
,
631 Op
->Common
.Parent
->Common
.Node
, Op
->Common
.Parent
);
632 if (ACPI_FAILURE (Status
))
638 /*lint -fallthrough */
640 case AML_INT_EVAL_SUBTREE_OP
:
642 Status
= AcpiDsEvalDataObjectOperands (WalkState
, Op
,
643 AcpiNsGetAttachedObject (Op
->Common
.Parent
->Common
.Node
));
648 Status
= AcpiDsEvalDataObjectOperands (WalkState
, Op
, NULL
);
653 * If a result object was returned from above, push it on the
654 * current result stack
656 if (WalkState
->ResultObj
)
658 Status
= AcpiDsResultPush (WalkState
->ResultObj
, WalkState
);
662 case AML_TYPE_NAMED_FIELD
:
663 case AML_TYPE_NAMED_COMPLEX
:
664 case AML_TYPE_NAMED_SIMPLE
:
665 case AML_TYPE_NAMED_NO_OBJ
:
667 Status
= AcpiDsLoad2EndOp (WalkState
);
668 if (ACPI_FAILURE (Status
))
673 if (Op
->Common
.AmlOpcode
== AML_REGION_OP
)
675 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
676 "Executing OpRegion Address/Length Op=%p\n", Op
));
678 Status
= AcpiDsEvalRegionOperands (WalkState
, Op
);
679 if (ACPI_FAILURE (Status
))
684 else if (Op
->Common
.AmlOpcode
== AML_DATA_REGION_OP
)
686 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
687 "Executing DataTableRegion Strings Op=%p\n", Op
));
689 Status
= AcpiDsEvalTableRegionOperands (WalkState
, Op
);
690 if (ACPI_FAILURE (Status
))
695 else if (Op
->Common
.AmlOpcode
== AML_BANK_FIELD_OP
)
697 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
698 "Executing BankField Op=%p\n", Op
));
700 Status
= AcpiDsEvalBankFieldOperands (WalkState
, Op
);
701 if (ACPI_FAILURE (Status
))
708 case AML_TYPE_UNDEFINED
:
710 ACPI_ERROR ((AE_INFO
,
711 "Undefined opcode type Op=%p", Op
));
712 return_ACPI_STATUS (AE_NOT_IMPLEMENTED
);
716 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
717 "Internal opcode=%X type Op=%p\n",
718 WalkState
->Opcode
, Op
));
723 ACPI_ERROR ((AE_INFO
,
724 "Unimplemented opcode, class=0x%X "
725 "type=0x%X Opcode=0x%X Op=%p",
726 OpClass
, OpType
, Op
->Common
.AmlOpcode
, Op
));
728 Status
= AE_NOT_IMPLEMENTED
;
734 * ACPI 2.0 support for 64-bit integers: Truncate numeric
735 * result value if we are executing from a 32-bit ACPI table
737 (void) AcpiExTruncateFor32bitTable (WalkState
->ResultObj
);
740 * Check if we just completed the evaluation of a
741 * conditional predicate
743 if ((ACPI_SUCCESS (Status
)) &&
744 (WalkState
->ControlState
) &&
745 (WalkState
->ControlState
->Common
.State
==
746 ACPI_CONTROL_PREDICATE_EXECUTING
) &&
747 (WalkState
->ControlState
->Control
.PredicateOp
== Op
))
749 Status
= AcpiDsGetPredicateValue (WalkState
, WalkState
->ResultObj
);
750 WalkState
->ResultObj
= NULL
;
756 if (WalkState
->ResultObj
)
758 /* Break to debugger to display result */
760 AcpiDbDisplayResultObject (WalkState
->ResultObj
,WalkState
);
763 * Delete the result op if and only if:
764 * Parent will not use the result -- such as any
765 * non-nested type2 op in a method (parent will be method)
767 AcpiDsDeleteResultIfNotUsed (Op
, WalkState
->ResultObj
, WalkState
);
770 #ifdef _UNDER_DEVELOPMENT
772 if (WalkState
->ParserState
.Aml
== WalkState
->ParserState
.AmlEnd
)
774 AcpiDbMethodEnd (WalkState
);
778 /* Invoke exception handler on error */
780 if (ACPI_FAILURE (Status
))
782 Status
= AcpiDsMethodError (Status
, WalkState
);
785 /* Always clear the object stack */
787 WalkState
->NumOperands
= 0;
788 return_ACPI_STATUS (Status
);