1 /******************************************************************************
3 * Module Name: dswexec - Dispatcher method execution callbacks;
4 * dispatch to interpreter.
7 *****************************************************************************/
9 /******************************************************************************
13 * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
14 * All rights reserved.
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
39 * The above copyright and patent license is granted only if the following
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
74 * 3.4. Intel retains all right, title, and interest in and to the Original
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
82 * 4. Disclaimer and Export Compliance
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
116 *****************************************************************************/
117 /* $DragonFly: src/sys/contrib/dev/acpica/Attic/dswexec.c,v 1.1 2003/09/24 03:32:15 drhodus Exp $ */
119 #define __DSWEXEC_C__
122 #include "acparser.h"
124 #include "acdispat.h"
125 #include "acinterp.h"
126 #include "acnamesp.h"
130 #define _COMPONENT ACPI_DISPATCHER
131 ACPI_MODULE_NAME ("dswexec")
134 * Dispatch table for opcode classes
136 static ACPI_EXECUTE_OP AcpiGbl_OpTypeDispatch [] = {
137 AcpiExOpcode_1A_0T_0R,
138 AcpiExOpcode_1A_0T_1R,
139 AcpiExOpcode_1A_1T_0R,
140 AcpiExOpcode_1A_1T_1R,
141 AcpiExOpcode_2A_0T_0R,
142 AcpiExOpcode_2A_0T_1R,
143 AcpiExOpcode_2A_1T_1R,
144 AcpiExOpcode_2A_2T_1R,
145 AcpiExOpcode_3A_0T_0R,
146 AcpiExOpcode_3A_1T_1R,
147 AcpiExOpcode_6A_0T_1R};
149 /*****************************************************************************
151 * FUNCTION: AcpiDsGetPredicateValue
153 * PARAMETERS: WalkState - Current state of the parse tree walk
157 * DESCRIPTION: Get the result of a predicate evaluation
159 ****************************************************************************/
162 AcpiDsGetPredicateValue (
163 ACPI_WALK_STATE *WalkState,
164 ACPI_OPERAND_OBJECT *ResultObj)
166 ACPI_STATUS Status = AE_OK;
167 ACPI_OPERAND_OBJECT *ObjDesc;
170 ACPI_FUNCTION_TRACE_PTR ("DsGetPredicateValue", WalkState);
173 WalkState->ControlState->Common.State = 0;
177 Status = AcpiDsResultPop (&ObjDesc, WalkState);
178 if (ACPI_FAILURE (Status))
180 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
181 "Could not get result from predicate evaluation, %s\n",
182 AcpiFormatException (Status)));
184 return_ACPI_STATUS (Status);
189 Status = AcpiDsCreateOperand (WalkState, WalkState->Op, 0);
190 if (ACPI_FAILURE (Status))
192 return_ACPI_STATUS (Status);
195 Status = AcpiExResolveToValue (&WalkState->Operands [0], WalkState);
196 if (ACPI_FAILURE (Status))
198 return_ACPI_STATUS (Status);
201 ObjDesc = WalkState->Operands [0];
206 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No predicate ObjDesc=%p State=%p\n",
207 ObjDesc, WalkState));
209 return_ACPI_STATUS (AE_AML_NO_OPERAND);
213 * Result of predicate evaluation currently must
216 if (ACPI_GET_OBJECT_TYPE (ObjDesc) != ACPI_TYPE_INTEGER)
218 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
219 "Bad predicate (not a number) ObjDesc=%p State=%p Type=%X\n",
220 ObjDesc, WalkState, ACPI_GET_OBJECT_TYPE (ObjDesc)));
222 Status = AE_AML_OPERAND_TYPE;
226 /* Truncate the predicate to 32-bits if necessary */
228 AcpiExTruncateFor32bitTable (ObjDesc);
231 * Save the result of the predicate evaluation on
234 if (ObjDesc->Integer.Value)
236 WalkState->ControlState->Common.Value = TRUE;
241 * Predicate is FALSE, we will just toss the
242 * rest of the package
244 WalkState->ControlState->Common.Value = FALSE;
245 Status = AE_CTRL_FALSE;
251 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Completed a predicate eval=%X Op=%p\n",
252 WalkState->ControlState->Common.Value, WalkState->Op));
254 /* Break to debugger to display result */
256 ACPI_DEBUGGER_EXEC (AcpiDbDisplayResultObject (ObjDesc, WalkState));
259 * Delete the predicate result object (we know that
260 * we don't need it anymore)
262 AcpiUtRemoveReference (ObjDesc);
264 WalkState->ControlState->Common.State = ACPI_CONTROL_NORMAL;
265 return_ACPI_STATUS (Status);
269 /*****************************************************************************
271 * FUNCTION: AcpiDsExecBeginOp
273 * PARAMETERS: WalkState - Current state of the parse tree walk
274 * OutOp - Return op if a new one is created
278 * DESCRIPTION: Descending callback used during the execution of control
279 * methods. This is where most operators and operands are
280 * dispatched to the interpreter.
282 ****************************************************************************/
286 ACPI_WALK_STATE *WalkState,
287 ACPI_PARSE_OBJECT **OutOp)
289 ACPI_PARSE_OBJECT *Op;
290 ACPI_STATUS Status = AE_OK;
294 ACPI_FUNCTION_TRACE_PTR ("DsExecBeginOp", WalkState);
300 Status = AcpiDsLoad2BeginOp (WalkState, OutOp);
301 if (ACPI_FAILURE (Status))
303 return_ACPI_STATUS (Status);
308 WalkState->Opcode = Op->Common.AmlOpcode;
309 WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
311 if (AcpiNsOpensScope (WalkState->OpInfo->ObjectType))
313 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n",
314 AcpiUtGetTypeName (WalkState->OpInfo->ObjectType), Op));
316 Status = AcpiDsScopeStackPop (WalkState);
317 if (ACPI_FAILURE (Status))
319 return_ACPI_STATUS (Status);
324 if (Op == WalkState->Origin)
331 return_ACPI_STATUS (AE_OK);
335 * If the previous opcode was a conditional, this opcode
336 * must be the beginning of the associated predicate.
337 * Save this knowledge in the current scope descriptor
339 if ((WalkState->ControlState) &&
340 (WalkState->ControlState->Common.State ==
341 ACPI_CONTROL_CONDITIONAL_EXECUTING))
343 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Exec predicate Op=%p State=%p\n",
346 WalkState->ControlState->Common.State = ACPI_CONTROL_PREDICATE_EXECUTING;
348 /* Save start of predicate */
350 WalkState->ControlState->Control.PredicateOp = Op;
354 OpcodeClass = WalkState->OpInfo->Class;
356 /* We want to send namepaths to the load code */
358 if (Op->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
360 OpcodeClass = AML_CLASS_NAMED_OBJECT;
364 * Handle the opcode based upon the opcode type
368 case AML_CLASS_CONTROL:
370 Status = AcpiDsResultStackPush (WalkState);
371 if (ACPI_FAILURE (Status))
373 return_ACPI_STATUS (Status);
376 Status = AcpiDsExecBeginControlOp (WalkState, Op);
380 case AML_CLASS_NAMED_OBJECT:
382 if (WalkState->WalkType == ACPI_WALK_METHOD)
385 * Found a named object declaration during method
386 * execution; we must enter this object into the
387 * namespace. The created object is temporary and
388 * will be deleted upon completion of the execution
391 Status = AcpiDsLoad2BeginOp (WalkState, NULL);
394 if (Op->Common.AmlOpcode == AML_REGION_OP)
396 Status = AcpiDsResultStackPush (WalkState);
401 case AML_CLASS_EXECUTE:
402 case AML_CLASS_CREATE:
404 /* most operators with arguments */
405 /* Start a new result/operand state */
407 Status = AcpiDsResultStackPush (WalkState);
415 /* Nothing to do here during method execution */
417 return_ACPI_STATUS (Status);
421 /*****************************************************************************
423 * FUNCTION: AcpiDsExecEndOp
425 * PARAMETERS: WalkState - Current state of the parse tree walk
426 * Op - Op that has been just been completed in the
427 * walk; Arguments have now been evaluated.
431 * DESCRIPTION: Ascending callback used during the execution of control
432 * methods. The only thing we really need to do here is to
433 * notice the beginning of IF, ELSE, and WHILE blocks.
435 ****************************************************************************/
439 ACPI_WALK_STATE *WalkState)
441 ACPI_PARSE_OBJECT *Op;
442 ACPI_STATUS Status = AE_OK;
445 ACPI_PARSE_OBJECT *NextOp;
446 ACPI_PARSE_OBJECT *FirstArg;
449 ACPI_FUNCTION_TRACE_PTR ("DsExecEndOp", WalkState);
453 OpType = WalkState->OpInfo->Type;
454 OpClass = WalkState->OpInfo->Class;
456 if (OpClass == AML_CLASS_UNKNOWN)
458 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown opcode %X\n", Op->Common.AmlOpcode));
459 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
462 FirstArg = Op->Common.Value.Arg;
464 /* Init the walk state */
466 WalkState->NumOperands = 0;
467 WalkState->ReturnDesc = NULL;
468 WalkState->ResultObj = NULL;
470 /* Call debugger for single step support (DEBUG build only) */
472 ACPI_DEBUGGER_EXEC (Status = AcpiDbSingleStep (WalkState, Op, OpClass));
473 ACPI_DEBUGGER_EXEC (if (ACPI_FAILURE (Status)) {return_ACPI_STATUS (Status);});
475 /* Decode the Opcode Class */
479 case AML_CLASS_ARGUMENT: /* constants, literals, etc. -- do nothing */
483 case AML_CLASS_EXECUTE: /* most operators with arguments */
485 /* Build resolved operand stack */
487 Status = AcpiDsCreateOperands (WalkState, FirstArg);
488 if (ACPI_FAILURE (Status))
493 /* Done with this result state (Now that operand stack is built) */
495 Status = AcpiDsResultStackPop (WalkState);
496 if (ACPI_FAILURE (Status))
501 /* Resolve all operands */
503 Status = AcpiExResolveOperands (WalkState->Opcode,
504 &(WalkState->Operands [WalkState->NumOperands -1]),
506 if (ACPI_SUCCESS (Status))
508 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
509 AcpiPsGetOpcodeName (WalkState->Opcode),
510 WalkState->NumOperands, "after ExResolveOperands");
513 * Dispatch the request to the appropriate interpreter handler
514 * routine. There is one routine per opcode "type" based upon the
515 * number of opcode arguments and return type.
517 Status = AcpiGbl_OpTypeDispatch [OpType] (WalkState);
521 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
522 "[%s]: Could not resolve operands, %s\n",
523 AcpiPsGetOpcodeName (WalkState->Opcode),
524 AcpiFormatException (Status)));
527 /* Always delete the argument objects and clear the operand stack */
529 AcpiDsClearOperands (WalkState);
532 * If a result object was returned from above, push it on the
533 * current result stack
535 if (ACPI_SUCCESS (Status) &&
536 WalkState->ResultObj)
538 Status = AcpiDsResultPush (WalkState->ResultObj, WalkState);
548 case AML_TYPE_CONTROL: /* Type 1 opcode, IF/ELSE/WHILE/NOOP */
550 /* 1 Operand, 0 ExternalResult, 0 InternalResult */
552 Status = AcpiDsExecEndControlOp (WalkState, Op);
553 if (ACPI_FAILURE (Status))
558 Status = AcpiDsResultStackPop (WalkState);
562 case AML_TYPE_METHOD_CALL:
564 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Method invocation, Op=%p\n", Op));
567 * (AML_METHODCALL) Op->Value->Arg->Node contains
568 * the method Node pointer
570 /* NextOp points to the op that holds the method name */
574 /* NextOp points to first argument op */
576 NextOp = NextOp->Common.Next;
579 * Get the method's arguments and put them on the operand stack
581 Status = AcpiDsCreateOperands (WalkState, NextOp);
582 if (ACPI_FAILURE (Status))
588 * Since the operands will be passed to another control method,
589 * we must resolve all local references here (Local variables,
590 * arguments to *this* method, etc.)
592 Status = AcpiDsResolveOperands (WalkState);
593 if (ACPI_FAILURE (Status))
595 /* On error, clear all resolved operands */
597 AcpiDsClearOperands (WalkState);
602 * Tell the walk loop to preempt this running method and
603 * execute the new method
605 Status = AE_CTRL_TRANSFER;
608 * Return now; we don't want to disturb anything,
609 * especially the operand count!
611 return_ACPI_STATUS (Status);
614 case AML_TYPE_CREATE_FIELD:
616 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
617 "Executing CreateField Buffer/Index Op=%p\n", Op));
619 Status = AcpiDsLoad2EndOp (WalkState);
620 if (ACPI_FAILURE (Status))
625 Status = AcpiDsEvalBufferFieldOperands (WalkState, Op);
629 case AML_TYPE_CREATE_OBJECT:
631 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
632 "Executing CreateObject (Buffer/Package) Op=%p\n", Op));
634 switch (Op->Common.Parent->Common.AmlOpcode)
639 * Put the Node on the object stack (Contains the ACPI Name of
642 WalkState->Operands[0] = (void *) Op->Common.Parent->Common.Node;
643 WalkState->NumOperands = 1;
645 Status = AcpiDsCreateNode (WalkState, Op->Common.Parent->Common.Node, Op->Common.Parent);
646 if (ACPI_FAILURE (Status))
652 /*lint -fallthrough */
654 case AML_INT_EVAL_SUBTREE_OP:
656 Status = AcpiDsEvalDataObjectOperands (WalkState, Op,
657 AcpiNsGetAttachedObject (Op->Common.Parent->Common.Node));
662 Status = AcpiDsEvalDataObjectOperands (WalkState, Op, NULL);
667 * If a result object was returned from above, push it on the
668 * current result stack
670 if (ACPI_SUCCESS (Status) &&
671 WalkState->ResultObj)
673 Status = AcpiDsResultPush (WalkState->ResultObj, WalkState);
678 case AML_TYPE_NAMED_FIELD:
679 case AML_TYPE_NAMED_COMPLEX:
680 case AML_TYPE_NAMED_SIMPLE:
681 case AML_TYPE_NAMED_NO_OBJ:
683 Status = AcpiDsLoad2EndOp (WalkState);
684 if (ACPI_FAILURE (Status))
689 if (Op->Common.AmlOpcode == AML_REGION_OP)
691 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
692 "Executing OpRegion Address/Length Op=%p\n", Op));
694 Status = AcpiDsEvalRegionOperands (WalkState, Op);
695 if (ACPI_FAILURE (Status))
700 Status = AcpiDsResultStackPop (WalkState);
706 case AML_TYPE_UNDEFINED:
708 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Undefined opcode type Op=%p\n", Op));
709 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
714 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
715 "Internal opcode=%X type Op=%p\n",
716 WalkState->Opcode, Op));
722 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
723 "Unimplemented opcode, class=%X type=%X Opcode=%X Op=%p\n",
724 OpClass, OpType, Op->Common.AmlOpcode, Op));
726 Status = AE_NOT_IMPLEMENTED;
732 * ACPI 2.0 support for 64-bit integers: Truncate numeric
733 * result value if we are executing from a 32-bit ACPI table
735 AcpiExTruncateFor32bitTable (WalkState->ResultObj);
738 * Check if we just completed the evaluation of a
739 * conditional predicate
742 if ((WalkState->ControlState) &&
743 (WalkState->ControlState->Common.State ==
744 ACPI_CONTROL_PREDICATE_EXECUTING) &&
745 (WalkState->ControlState->Control.PredicateOp == Op))
747 Status = AcpiDsGetPredicateValue (WalkState, WalkState->ResultObj);
748 WalkState->ResultObj = NULL;
753 if (WalkState->ResultObj)
755 /* Break to debugger to display result */
757 ACPI_DEBUGGER_EXEC (AcpiDbDisplayResultObject (WalkState->ResultObj, WalkState));
760 * Delete the result op if and only if:
761 * Parent will not use the result -- such as any
762 * non-nested type2 op in a method (parent will be method)
764 AcpiDsDeleteResultIfNotUsed (Op, WalkState->ResultObj, WalkState);
767 #if _UNDER_DEVELOPMENT
769 if (WalkState->ParserState.Aml == WalkState->ParserState.AmlEnd)
771 AcpiDbMethodEnd (WalkState);
775 /* Always clear the object stack */
777 WalkState->NumOperands = 0;
778 return_ACPI_STATUS (Status);