126f3cdf0SGordon Ross /******************************************************************************
226f3cdf0SGordon Ross *
326f3cdf0SGordon Ross * Module Name: dscontrol - Support for execution control opcodes -
426f3cdf0SGordon Ross * if/else/while/return
526f3cdf0SGordon Ross *
626f3cdf0SGordon Ross *****************************************************************************/
726f3cdf0SGordon Ross
8*35786f68SRobert Mustacchi /******************************************************************************
9*35786f68SRobert Mustacchi *
10*35786f68SRobert Mustacchi * 1. Copyright Notice
11*35786f68SRobert Mustacchi *
12*35786f68SRobert Mustacchi * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
1326f3cdf0SGordon Ross * All rights reserved.
1426f3cdf0SGordon Ross *
15*35786f68SRobert Mustacchi * 2. License
16*35786f68SRobert Mustacchi *
17*35786f68SRobert Mustacchi * 2.1. This is your license from Intel Corp. under its intellectual property
18*35786f68SRobert Mustacchi * rights. You may have additional license terms from the party that provided
19*35786f68SRobert Mustacchi * you this software, covering your right to use that party's intellectual
20*35786f68SRobert Mustacchi * property rights.
21*35786f68SRobert Mustacchi *
22*35786f68SRobert Mustacchi * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23*35786f68SRobert Mustacchi * copy of the source code appearing in this file ("Covered Code") an
24*35786f68SRobert Mustacchi * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25*35786f68SRobert Mustacchi * base code distributed originally by Intel ("Original Intel Code") to copy,
26*35786f68SRobert Mustacchi * make derivatives, distribute, use and display any portion of the Covered
27*35786f68SRobert Mustacchi * Code in any form, with the right to sublicense such rights; and
28*35786f68SRobert Mustacchi *
29*35786f68SRobert Mustacchi * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30*35786f68SRobert Mustacchi * license (with the right to sublicense), under only those claims of Intel
31*35786f68SRobert Mustacchi * patents that are infringed by the Original Intel Code, to make, use, sell,
32*35786f68SRobert Mustacchi * offer to sell, and import the Covered Code and derivative works thereof
33*35786f68SRobert Mustacchi * solely to the minimum extent necessary to exercise the above copyright
34*35786f68SRobert Mustacchi * license, and in no event shall the patent license extend to any additions
35*35786f68SRobert Mustacchi * to or modifications of the Original Intel Code. No other license or right
36*35786f68SRobert Mustacchi * is granted directly or by implication, estoppel or otherwise;
37*35786f68SRobert Mustacchi *
38*35786f68SRobert Mustacchi * The above copyright and patent license is granted only if the following
39*35786f68SRobert Mustacchi * conditions are met:
40*35786f68SRobert Mustacchi *
41*35786f68SRobert Mustacchi * 3. Conditions
42*35786f68SRobert Mustacchi *
43*35786f68SRobert Mustacchi * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44*35786f68SRobert Mustacchi * Redistribution of source code of any substantial portion of the Covered
45*35786f68SRobert Mustacchi * Code or modification with rights to further distribute source must include
46*35786f68SRobert Mustacchi * the above Copyright Notice, the above License, this list of Conditions,
47*35786f68SRobert Mustacchi * and the following Disclaimer and Export Compliance provision. In addition,
48*35786f68SRobert Mustacchi * Licensee must cause all Covered Code to which Licensee contributes to
49*35786f68SRobert Mustacchi * contain a file documenting the changes Licensee made to create that Covered
50*35786f68SRobert Mustacchi * Code and the date of any change. Licensee must include in that file the
51*35786f68SRobert Mustacchi * documentation of any changes made by any predecessor Licensee. Licensee
52*35786f68SRobert Mustacchi * must include a prominent statement that the modification is derived,
53*35786f68SRobert Mustacchi * directly or indirectly, from Original Intel Code.
54*35786f68SRobert Mustacchi *
55*35786f68SRobert Mustacchi * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56*35786f68SRobert Mustacchi * Redistribution of source code of any substantial portion of the Covered
57*35786f68SRobert Mustacchi * Code or modification without rights to further distribute source must
58*35786f68SRobert Mustacchi * include the following Disclaimer and Export Compliance provision in the
59*35786f68SRobert Mustacchi * documentation and/or other materials provided with distribution. In
60*35786f68SRobert Mustacchi * addition, Licensee may not authorize further sublicense of source of any
61*35786f68SRobert Mustacchi * portion of the Covered Code, and must include terms to the effect that the
62*35786f68SRobert Mustacchi * license from Licensee to its licensee is limited to the intellectual
63*35786f68SRobert Mustacchi * property embodied in the software Licensee provides to its licensee, and
64*35786f68SRobert Mustacchi * not to intellectual property embodied in modifications its licensee may
65*35786f68SRobert Mustacchi * make.
66*35786f68SRobert Mustacchi *
67*35786f68SRobert Mustacchi * 3.3. Redistribution of Executable. Redistribution in executable form of any
68*35786f68SRobert Mustacchi * substantial portion of the Covered Code or modification must reproduce the
69*35786f68SRobert Mustacchi * above Copyright Notice, and the following Disclaimer and Export Compliance
70*35786f68SRobert Mustacchi * provision in the documentation and/or other materials provided with the
71*35786f68SRobert Mustacchi * distribution.
72*35786f68SRobert Mustacchi *
73*35786f68SRobert Mustacchi * 3.4. Intel retains all right, title, and interest in and to the Original
74*35786f68SRobert Mustacchi * Intel Code.
75*35786f68SRobert Mustacchi *
76*35786f68SRobert Mustacchi * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77*35786f68SRobert Mustacchi * Intel shall be used in advertising or otherwise to promote the sale, use or
78*35786f68SRobert Mustacchi * other dealings in products derived from or relating to the Covered Code
79*35786f68SRobert Mustacchi * without prior written authorization from Intel.
80*35786f68SRobert Mustacchi *
81*35786f68SRobert Mustacchi * 4. Disclaimer and Export Compliance
82*35786f68SRobert Mustacchi *
83*35786f68SRobert Mustacchi * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84*35786f68SRobert Mustacchi * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85*35786f68SRobert Mustacchi * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86*35786f68SRobert Mustacchi * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87*35786f68SRobert Mustacchi * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88*35786f68SRobert Mustacchi * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89*35786f68SRobert Mustacchi * PARTICULAR PURPOSE.
90*35786f68SRobert Mustacchi *
91*35786f68SRobert Mustacchi * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92*35786f68SRobert Mustacchi * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93*35786f68SRobert Mustacchi * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94*35786f68SRobert Mustacchi * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95*35786f68SRobert Mustacchi * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96*35786f68SRobert Mustacchi * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97*35786f68SRobert Mustacchi * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98*35786f68SRobert Mustacchi * LIMITED REMEDY.
99*35786f68SRobert Mustacchi *
100*35786f68SRobert Mustacchi * 4.3. Licensee shall not export, either directly or indirectly, any of this
101*35786f68SRobert Mustacchi * software or system incorporating such software without first obtaining any
102*35786f68SRobert Mustacchi * required license or other approval from the U. S. Department of Commerce or
103*35786f68SRobert Mustacchi * any other agency or department of the United States Government. In the
104*35786f68SRobert Mustacchi * event Licensee exports any such software from the United States or
105*35786f68SRobert Mustacchi * re-exports any such software from a foreign destination, Licensee shall
106*35786f68SRobert Mustacchi * ensure that the distribution and export/re-export of the software is in
107*35786f68SRobert Mustacchi * compliance with all laws, regulations, orders, or other restrictions of the
108*35786f68SRobert Mustacchi * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109*35786f68SRobert Mustacchi * any of its subsidiaries will export/re-export any technical data, process,
110*35786f68SRobert Mustacchi * software, or service, directly or indirectly, to any country for which the
111*35786f68SRobert Mustacchi * United States government or any agency thereof requires an export license,
112*35786f68SRobert Mustacchi * other governmental approval, or letter of assurance, without first obtaining
113*35786f68SRobert Mustacchi * such license, approval or letter.
114*35786f68SRobert Mustacchi *
115*35786f68SRobert Mustacchi *****************************************************************************
116*35786f68SRobert Mustacchi *
117*35786f68SRobert Mustacchi * Alternatively, you may choose to be licensed under the terms of the
118*35786f68SRobert Mustacchi * following license:
119*35786f68SRobert Mustacchi *
12026f3cdf0SGordon Ross * Redistribution and use in source and binary forms, with or without
12126f3cdf0SGordon Ross * modification, are permitted provided that the following conditions
12226f3cdf0SGordon Ross * are met:
12326f3cdf0SGordon Ross * 1. Redistributions of source code must retain the above copyright
12426f3cdf0SGordon Ross * notice, this list of conditions, and the following disclaimer,
12526f3cdf0SGordon Ross * without modification.
12626f3cdf0SGordon Ross * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12726f3cdf0SGordon Ross * substantially similar to the "NO WARRANTY" disclaimer below
12826f3cdf0SGordon Ross * ("Disclaimer") and any redistribution must be conditioned upon
12926f3cdf0SGordon Ross * including a substantially similar Disclaimer requirement for further
13026f3cdf0SGordon Ross * binary redistribution.
13126f3cdf0SGordon Ross * 3. Neither the names of the above-listed copyright holders nor the names
13226f3cdf0SGordon Ross * of any contributors may be used to endorse or promote products derived
13326f3cdf0SGordon Ross * from this software without specific prior written permission.
13426f3cdf0SGordon Ross *
13526f3cdf0SGordon Ross * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13626f3cdf0SGordon Ross * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
137*35786f68SRobert Mustacchi * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
13826f3cdf0SGordon Ross * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
139*35786f68SRobert Mustacchi * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
140*35786f68SRobert Mustacchi * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
141*35786f68SRobert Mustacchi * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
142*35786f68SRobert Mustacchi * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
143*35786f68SRobert Mustacchi * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
144*35786f68SRobert Mustacchi * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
145*35786f68SRobert Mustacchi * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146*35786f68SRobert Mustacchi *
147*35786f68SRobert Mustacchi * Alternatively, you may choose to be licensed under the terms of the
148*35786f68SRobert Mustacchi * GNU General Public License ("GPL") version 2 as published by the Free
149*35786f68SRobert Mustacchi * Software Foundation.
150*35786f68SRobert Mustacchi *
151*35786f68SRobert Mustacchi *****************************************************************************/
15226f3cdf0SGordon Ross
15326f3cdf0SGordon Ross #include "acpi.h"
15426f3cdf0SGordon Ross #include "accommon.h"
15526f3cdf0SGordon Ross #include "amlcode.h"
15626f3cdf0SGordon Ross #include "acdispat.h"
15726f3cdf0SGordon Ross #include "acinterp.h"
1587b1019a6SJerry Jelinek #include "acdebug.h"
15926f3cdf0SGordon Ross
16026f3cdf0SGordon Ross #define _COMPONENT ACPI_DISPATCHER
16126f3cdf0SGordon Ross ACPI_MODULE_NAME ("dscontrol")
16226f3cdf0SGordon Ross
16326f3cdf0SGordon Ross
16426f3cdf0SGordon Ross /*******************************************************************************
16526f3cdf0SGordon Ross *
16626f3cdf0SGordon Ross * FUNCTION: AcpiDsExecBeginControlOp
16726f3cdf0SGordon Ross *
16826f3cdf0SGordon Ross * PARAMETERS: WalkList - The list that owns the walk stack
16926f3cdf0SGordon Ross * Op - The control Op
17026f3cdf0SGordon Ross *
17126f3cdf0SGordon Ross * RETURN: Status
17226f3cdf0SGordon Ross *
17326f3cdf0SGordon Ross * DESCRIPTION: Handles all control ops encountered during control method
17426f3cdf0SGordon Ross * execution.
17526f3cdf0SGordon Ross *
17626f3cdf0SGordon Ross ******************************************************************************/
17726f3cdf0SGordon Ross
17826f3cdf0SGordon Ross ACPI_STATUS
AcpiDsExecBeginControlOp(ACPI_WALK_STATE * WalkState,ACPI_PARSE_OBJECT * Op)17926f3cdf0SGordon Ross AcpiDsExecBeginControlOp (
18026f3cdf0SGordon Ross ACPI_WALK_STATE *WalkState,
18126f3cdf0SGordon Ross ACPI_PARSE_OBJECT *Op)
18226f3cdf0SGordon Ross {
18326f3cdf0SGordon Ross ACPI_STATUS Status = AE_OK;
18426f3cdf0SGordon Ross ACPI_GENERIC_STATE *ControlState;
18526f3cdf0SGordon Ross
18626f3cdf0SGordon Ross
18726f3cdf0SGordon Ross ACPI_FUNCTION_NAME (DsExecBeginControlOp);
18826f3cdf0SGordon Ross
18926f3cdf0SGordon Ross
19026f3cdf0SGordon Ross ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n",
19126f3cdf0SGordon Ross Op, Op->Common.AmlOpcode, WalkState));
19226f3cdf0SGordon Ross
19326f3cdf0SGordon Ross switch (Op->Common.AmlOpcode)
19426f3cdf0SGordon Ross {
19526f3cdf0SGordon Ross case AML_WHILE_OP:
19626f3cdf0SGordon Ross /*
19726f3cdf0SGordon Ross * If this is an additional iteration of a while loop, continue.
19826f3cdf0SGordon Ross * There is no need to allocate a new control state.
19926f3cdf0SGordon Ross */
20026f3cdf0SGordon Ross if (WalkState->ControlState)
20126f3cdf0SGordon Ross {
20226f3cdf0SGordon Ross if (WalkState->ControlState->Control.AmlPredicateStart ==
20326f3cdf0SGordon Ross (WalkState->ParserState.Aml - 1))
20426f3cdf0SGordon Ross {
20526f3cdf0SGordon Ross /* Reset the state to start-of-loop */
20626f3cdf0SGordon Ross
20726f3cdf0SGordon Ross WalkState->ControlState->Common.State =
20826f3cdf0SGordon Ross ACPI_CONTROL_CONDITIONAL_EXECUTING;
20926f3cdf0SGordon Ross break;
21026f3cdf0SGordon Ross }
21126f3cdf0SGordon Ross }
21226f3cdf0SGordon Ross
21326f3cdf0SGordon Ross /*lint -fallthrough */
21426f3cdf0SGordon Ross
21526f3cdf0SGordon Ross case AML_IF_OP:
21626f3cdf0SGordon Ross /*
21726f3cdf0SGordon Ross * IF/WHILE: Create a new control state to manage these
21826f3cdf0SGordon Ross * constructs. We need to manage these as a stack, in order
21926f3cdf0SGordon Ross * to handle nesting.
22026f3cdf0SGordon Ross */
22126f3cdf0SGordon Ross ControlState = AcpiUtCreateControlState ();
22226f3cdf0SGordon Ross if (!ControlState)
22326f3cdf0SGordon Ross {
22426f3cdf0SGordon Ross Status = AE_NO_MEMORY;
22526f3cdf0SGordon Ross break;
22626f3cdf0SGordon Ross }
22726f3cdf0SGordon Ross /*
22826f3cdf0SGordon Ross * Save a pointer to the predicate for multiple executions
22926f3cdf0SGordon Ross * of a loop
23026f3cdf0SGordon Ross */
2317b1019a6SJerry Jelinek ControlState->Control.AmlPredicateStart =
2327b1019a6SJerry Jelinek WalkState->ParserState.Aml - 1;
2337b1019a6SJerry Jelinek ControlState->Control.PackageEnd =
2347b1019a6SJerry Jelinek WalkState->ParserState.PkgEnd;
2357b1019a6SJerry Jelinek ControlState->Control.Opcode =
2367b1019a6SJerry Jelinek Op->Common.AmlOpcode;
237*35786f68SRobert Mustacchi ControlState->Control.LoopTimeout = AcpiOsGetTimer () +
238*35786f68SRobert Mustacchi (UINT64) (AcpiGbl_MaxLoopIterations * ACPI_100NSEC_PER_SEC);
23926f3cdf0SGordon Ross
24026f3cdf0SGordon Ross /* Push the control state on this walk's control stack */
24126f3cdf0SGordon Ross
24226f3cdf0SGordon Ross AcpiUtPushGenericState (&WalkState->ControlState, ControlState);
24326f3cdf0SGordon Ross break;
24426f3cdf0SGordon Ross
24526f3cdf0SGordon Ross case AML_ELSE_OP:
24626f3cdf0SGordon Ross
24726f3cdf0SGordon Ross /* Predicate is in the state object */
24826f3cdf0SGordon Ross /* If predicate is true, the IF was executed, ignore ELSE part */
24926f3cdf0SGordon Ross
25026f3cdf0SGordon Ross if (WalkState->LastPredicate)
25126f3cdf0SGordon Ross {
25226f3cdf0SGordon Ross Status = AE_CTRL_TRUE;
25326f3cdf0SGordon Ross }
25426f3cdf0SGordon Ross
25526f3cdf0SGordon Ross break;
25626f3cdf0SGordon Ross
25726f3cdf0SGordon Ross case AML_RETURN_OP:
25826f3cdf0SGordon Ross
25926f3cdf0SGordon Ross break;
26026f3cdf0SGordon Ross
26126f3cdf0SGordon Ross default:
2627b1019a6SJerry Jelinek
26326f3cdf0SGordon Ross break;
26426f3cdf0SGordon Ross }
26526f3cdf0SGordon Ross
26626f3cdf0SGordon Ross return (Status);
26726f3cdf0SGordon Ross }
26826f3cdf0SGordon Ross
26926f3cdf0SGordon Ross
27026f3cdf0SGordon Ross /*******************************************************************************
27126f3cdf0SGordon Ross *
27226f3cdf0SGordon Ross * FUNCTION: AcpiDsExecEndControlOp
27326f3cdf0SGordon Ross *
27426f3cdf0SGordon Ross * PARAMETERS: WalkList - The list that owns the walk stack
27526f3cdf0SGordon Ross * Op - The control Op
27626f3cdf0SGordon Ross *
27726f3cdf0SGordon Ross * RETURN: Status
27826f3cdf0SGordon Ross *
27926f3cdf0SGordon Ross * DESCRIPTION: Handles all control ops encountered during control method
28026f3cdf0SGordon Ross * execution.
28126f3cdf0SGordon Ross *
28226f3cdf0SGordon Ross ******************************************************************************/
28326f3cdf0SGordon Ross
28426f3cdf0SGordon Ross ACPI_STATUS
AcpiDsExecEndControlOp(ACPI_WALK_STATE * WalkState,ACPI_PARSE_OBJECT * Op)28526f3cdf0SGordon Ross AcpiDsExecEndControlOp (
28626f3cdf0SGordon Ross ACPI_WALK_STATE *WalkState,
28726f3cdf0SGordon Ross ACPI_PARSE_OBJECT *Op)
28826f3cdf0SGordon Ross {
28926f3cdf0SGordon Ross ACPI_STATUS Status = AE_OK;
29026f3cdf0SGordon Ross ACPI_GENERIC_STATE *ControlState;
29126f3cdf0SGordon Ross
29226f3cdf0SGordon Ross
29326f3cdf0SGordon Ross ACPI_FUNCTION_NAME (DsExecEndControlOp);
29426f3cdf0SGordon Ross
29526f3cdf0SGordon Ross
29626f3cdf0SGordon Ross switch (Op->Common.AmlOpcode)
29726f3cdf0SGordon Ross {
29826f3cdf0SGordon Ross case AML_IF_OP:
29926f3cdf0SGordon Ross
30026f3cdf0SGordon Ross ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", Op));
30126f3cdf0SGordon Ross
30226f3cdf0SGordon Ross /*
30326f3cdf0SGordon Ross * Save the result of the predicate in case there is an
30426f3cdf0SGordon Ross * ELSE to come
30526f3cdf0SGordon Ross */
30626f3cdf0SGordon Ross WalkState->LastPredicate =
30726f3cdf0SGordon Ross (BOOLEAN) WalkState->ControlState->Common.Value;
30826f3cdf0SGordon Ross
30926f3cdf0SGordon Ross /*
31026f3cdf0SGordon Ross * Pop the control state that was created at the start
31126f3cdf0SGordon Ross * of the IF and free it
31226f3cdf0SGordon Ross */
31326f3cdf0SGordon Ross ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
31426f3cdf0SGordon Ross AcpiUtDeleteGenericState (ControlState);
31526f3cdf0SGordon Ross break;
31626f3cdf0SGordon Ross
31726f3cdf0SGordon Ross case AML_ELSE_OP:
31826f3cdf0SGordon Ross
31926f3cdf0SGordon Ross break;
32026f3cdf0SGordon Ross
32126f3cdf0SGordon Ross case AML_WHILE_OP:
32226f3cdf0SGordon Ross
32326f3cdf0SGordon Ross ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", Op));
32426f3cdf0SGordon Ross
32526f3cdf0SGordon Ross ControlState = WalkState->ControlState;
32626f3cdf0SGordon Ross if (ControlState->Common.Value)
32726f3cdf0SGordon Ross {
32826f3cdf0SGordon Ross /* Predicate was true, the body of the loop was just executed */
32926f3cdf0SGordon Ross
33026f3cdf0SGordon Ross /*
331*35786f68SRobert Mustacchi * This infinite loop detection mechanism allows the interpreter
332*35786f68SRobert Mustacchi * to escape possibly infinite loops. This can occur in poorly
333*35786f68SRobert Mustacchi * written AML when the hardware does not respond within a while
334*35786f68SRobert Mustacchi * loop and the loop does not implement a timeout.
33526f3cdf0SGordon Ross */
336*35786f68SRobert Mustacchi if (ACPI_TIME_AFTER (AcpiOsGetTimer (),
337*35786f68SRobert Mustacchi ControlState->Control.LoopTimeout))
33826f3cdf0SGordon Ross {
339*35786f68SRobert Mustacchi Status = AE_AML_LOOP_TIMEOUT;
34026f3cdf0SGordon Ross break;
34126f3cdf0SGordon Ross }
34226f3cdf0SGordon Ross
34326f3cdf0SGordon Ross /*
34426f3cdf0SGordon Ross * Go back and evaluate the predicate and maybe execute the loop
34526f3cdf0SGordon Ross * another time
34626f3cdf0SGordon Ross */
34726f3cdf0SGordon Ross Status = AE_CTRL_PENDING;
3487b1019a6SJerry Jelinek WalkState->AmlLastWhile =
3497b1019a6SJerry Jelinek ControlState->Control.AmlPredicateStart;
35026f3cdf0SGordon Ross break;
35126f3cdf0SGordon Ross }
35226f3cdf0SGordon Ross
35326f3cdf0SGordon Ross /* Predicate was false, terminate this while loop */
35426f3cdf0SGordon Ross
35526f3cdf0SGordon Ross ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
35626f3cdf0SGordon Ross "[WHILE_OP] termination! Op=%p\n",Op));
35726f3cdf0SGordon Ross
35826f3cdf0SGordon Ross /* Pop this control state and free it */
35926f3cdf0SGordon Ross
36026f3cdf0SGordon Ross ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
36126f3cdf0SGordon Ross AcpiUtDeleteGenericState (ControlState);
36226f3cdf0SGordon Ross break;
36326f3cdf0SGordon Ross
36426f3cdf0SGordon Ross case AML_RETURN_OP:
36526f3cdf0SGordon Ross
36626f3cdf0SGordon Ross ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
36726f3cdf0SGordon Ross "[RETURN_OP] Op=%p Arg=%p\n",Op, Op->Common.Value.Arg));
36826f3cdf0SGordon Ross
36926f3cdf0SGordon Ross /*
37026f3cdf0SGordon Ross * One optional operand -- the return value
37126f3cdf0SGordon Ross * It can be either an immediate operand or a result that
37226f3cdf0SGordon Ross * has been bubbled up the tree
37326f3cdf0SGordon Ross */
37426f3cdf0SGordon Ross if (Op->Common.Value.Arg)
37526f3cdf0SGordon Ross {
37626f3cdf0SGordon Ross /* Since we have a real Return(), delete any implicit return */
37726f3cdf0SGordon Ross
37826f3cdf0SGordon Ross AcpiDsClearImplicitReturn (WalkState);
37926f3cdf0SGordon Ross
38026f3cdf0SGordon Ross /* Return statement has an immediate operand */
38126f3cdf0SGordon Ross
38226f3cdf0SGordon Ross Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
38326f3cdf0SGordon Ross if (ACPI_FAILURE (Status))
38426f3cdf0SGordon Ross {
38526f3cdf0SGordon Ross return (Status);
38626f3cdf0SGordon Ross }
38726f3cdf0SGordon Ross
38826f3cdf0SGordon Ross /*
38926f3cdf0SGordon Ross * If value being returned is a Reference (such as
39026f3cdf0SGordon Ross * an arg or local), resolve it now because it may
39126f3cdf0SGordon Ross * cease to exist at the end of the method.
39226f3cdf0SGordon Ross */
3937b1019a6SJerry Jelinek Status = AcpiExResolveToValue (
3947b1019a6SJerry Jelinek &WalkState->Operands [0], WalkState);
39526f3cdf0SGordon Ross if (ACPI_FAILURE (Status))
39626f3cdf0SGordon Ross {
39726f3cdf0SGordon Ross return (Status);
39826f3cdf0SGordon Ross }
39926f3cdf0SGordon Ross
40026f3cdf0SGordon Ross /*
40126f3cdf0SGordon Ross * Get the return value and save as the last result
4027b1019a6SJerry Jelinek * value. This is the only place where WalkState->ReturnDesc
40326f3cdf0SGordon Ross * is set to anything other than zero!
40426f3cdf0SGordon Ross */
40526f3cdf0SGordon Ross WalkState->ReturnDesc = WalkState->Operands[0];
40626f3cdf0SGordon Ross }
40726f3cdf0SGordon Ross else if (WalkState->ResultCount)
40826f3cdf0SGordon Ross {
40926f3cdf0SGordon Ross /* Since we have a real Return(), delete any implicit return */
41026f3cdf0SGordon Ross
41126f3cdf0SGordon Ross AcpiDsClearImplicitReturn (WalkState);
41226f3cdf0SGordon Ross
41326f3cdf0SGordon Ross /*
41426f3cdf0SGordon Ross * The return value has come from a previous calculation.
41526f3cdf0SGordon Ross *
41626f3cdf0SGordon Ross * If value being returned is a Reference (such as
41726f3cdf0SGordon Ross * an arg or local), resolve it now because it may
41826f3cdf0SGordon Ross * cease to exist at the end of the method.
41926f3cdf0SGordon Ross *
42026f3cdf0SGordon Ross * Allow references created by the Index operator to return
42126f3cdf0SGordon Ross * unchanged.
42226f3cdf0SGordon Ross */
4237b1019a6SJerry Jelinek if ((ACPI_GET_DESCRIPTOR_TYPE (WalkState->Results->Results.ObjDesc[0]) ==
4247b1019a6SJerry Jelinek ACPI_DESC_TYPE_OPERAND) &&
4257b1019a6SJerry Jelinek ((WalkState->Results->Results.ObjDesc [0])->Common.Type ==
4267b1019a6SJerry Jelinek ACPI_TYPE_LOCAL_REFERENCE) &&
4277b1019a6SJerry Jelinek ((WalkState->Results->Results.ObjDesc [0])->Reference.Class !=
4287b1019a6SJerry Jelinek ACPI_REFCLASS_INDEX))
42926f3cdf0SGordon Ross {
4307b1019a6SJerry Jelinek Status = AcpiExResolveToValue (
4317b1019a6SJerry Jelinek &WalkState->Results->Results.ObjDesc [0], WalkState);
43226f3cdf0SGordon Ross if (ACPI_FAILURE (Status))
43326f3cdf0SGordon Ross {
43426f3cdf0SGordon Ross return (Status);
43526f3cdf0SGordon Ross }
43626f3cdf0SGordon Ross }
43726f3cdf0SGordon Ross
43826f3cdf0SGordon Ross WalkState->ReturnDesc = WalkState->Results->Results.ObjDesc [0];
43926f3cdf0SGordon Ross }
44026f3cdf0SGordon Ross else
44126f3cdf0SGordon Ross {
44226f3cdf0SGordon Ross /* No return operand */
44326f3cdf0SGordon Ross
44426f3cdf0SGordon Ross if (WalkState->NumOperands)
44526f3cdf0SGordon Ross {
44626f3cdf0SGordon Ross AcpiUtRemoveReference (WalkState->Operands [0]);
44726f3cdf0SGordon Ross }
44826f3cdf0SGordon Ross
4497b1019a6SJerry Jelinek WalkState->Operands[0] = NULL;
4507b1019a6SJerry Jelinek WalkState->NumOperands = 0;
4517b1019a6SJerry Jelinek WalkState->ReturnDesc = NULL;
45226f3cdf0SGordon Ross }
45326f3cdf0SGordon Ross
45426f3cdf0SGordon Ross
45526f3cdf0SGordon Ross ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
45626f3cdf0SGordon Ross "Completed RETURN_OP State=%p, RetVal=%p\n",
45726f3cdf0SGordon Ross WalkState, WalkState->ReturnDesc));
45826f3cdf0SGordon Ross
45926f3cdf0SGordon Ross /* End the control method execution right now */
46026f3cdf0SGordon Ross
46126f3cdf0SGordon Ross Status = AE_CTRL_TERMINATE;
46226f3cdf0SGordon Ross break;
46326f3cdf0SGordon Ross
46426f3cdf0SGordon Ross case AML_NOOP_OP:
46526f3cdf0SGordon Ross
46626f3cdf0SGordon Ross /* Just do nothing! */
46726f3cdf0SGordon Ross
4687b1019a6SJerry Jelinek break;
46926f3cdf0SGordon Ross
470*35786f68SRobert Mustacchi case AML_BREAKPOINT_OP:
47126f3cdf0SGordon Ross
4727b1019a6SJerry Jelinek #ifdef ACPI_DEBUGGER
4737b1019a6SJerry Jelinek AcpiDbSignalBreakPoint (WalkState);
47426f3cdf0SGordon Ross
47526f3cdf0SGordon Ross /* Call to the OSL in case OS wants a piece of the action */
47626f3cdf0SGordon Ross
47726f3cdf0SGordon Ross Status = AcpiOsSignal (ACPI_SIGNAL_BREAKPOINT,
4787b1019a6SJerry Jelinek "Executed AML Breakpoint opcode");
4797b1019a6SJerry Jelinek #endif
48026f3cdf0SGordon Ross break;
48126f3cdf0SGordon Ross
48226f3cdf0SGordon Ross case AML_BREAK_OP:
48326f3cdf0SGordon Ross case AML_CONTINUE_OP: /* ACPI 2.0 */
48426f3cdf0SGordon Ross
48526f3cdf0SGordon Ross /* Pop and delete control states until we find a while */
48626f3cdf0SGordon Ross
48726f3cdf0SGordon Ross while (WalkState->ControlState &&
48826f3cdf0SGordon Ross (WalkState->ControlState->Control.Opcode != AML_WHILE_OP))
48926f3cdf0SGordon Ross {
49026f3cdf0SGordon Ross ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
49126f3cdf0SGordon Ross AcpiUtDeleteGenericState (ControlState);
49226f3cdf0SGordon Ross }
49326f3cdf0SGordon Ross
49426f3cdf0SGordon Ross /* No while found? */
49526f3cdf0SGordon Ross
49626f3cdf0SGordon Ross if (!WalkState->ControlState)
49726f3cdf0SGordon Ross {
49826f3cdf0SGordon Ross return (AE_AML_NO_WHILE);
49926f3cdf0SGordon Ross }
50026f3cdf0SGordon Ross
50126f3cdf0SGordon Ross /* Was: WalkState->AmlLastWhile = WalkState->ControlState->Control.AmlPredicateStart; */
50226f3cdf0SGordon Ross
5037b1019a6SJerry Jelinek WalkState->AmlLastWhile =
5047b1019a6SJerry Jelinek WalkState->ControlState->Control.PackageEnd;
50526f3cdf0SGordon Ross
50626f3cdf0SGordon Ross /* Return status depending on opcode */
50726f3cdf0SGordon Ross
50826f3cdf0SGordon Ross if (Op->Common.AmlOpcode == AML_BREAK_OP)
50926f3cdf0SGordon Ross {
51026f3cdf0SGordon Ross Status = AE_CTRL_BREAK;
51126f3cdf0SGordon Ross }
51226f3cdf0SGordon Ross else
51326f3cdf0SGordon Ross {
51426f3cdf0SGordon Ross Status = AE_CTRL_CONTINUE;
51526f3cdf0SGordon Ross }
51626f3cdf0SGordon Ross break;
51726f3cdf0SGordon Ross
51826f3cdf0SGordon Ross default:
51926f3cdf0SGordon Ross
52026f3cdf0SGordon Ross ACPI_ERROR ((AE_INFO, "Unknown control opcode=0x%X Op=%p",
52126f3cdf0SGordon Ross Op->Common.AmlOpcode, Op));
52226f3cdf0SGordon Ross
52326f3cdf0SGordon Ross Status = AE_AML_BAD_OPCODE;
52426f3cdf0SGordon Ross break;
52526f3cdf0SGordon Ross }
52626f3cdf0SGordon Ross
52726f3cdf0SGordon Ross return (Status);
52826f3cdf0SGordon Ross }
529