1 /******************************************************************************
3 * Module Name: dscontrol - Support for execution control opcodes -
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2014, 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.
51 #define _COMPONENT ACPI_DISPATCHER
52 ACPI_MODULE_NAME ("dscontrol")
55 /*******************************************************************************
57 * FUNCTION: AcpiDsExecBeginControlOp
59 * PARAMETERS: WalkList - The list that owns the walk stack
64 * DESCRIPTION: Handles all control ops encountered during control method
67 ******************************************************************************/
70 AcpiDsExecBeginControlOp (
71 ACPI_WALK_STATE *WalkState,
72 ACPI_PARSE_OBJECT *Op)
74 ACPI_STATUS Status = AE_OK;
75 ACPI_GENERIC_STATE *ControlState;
78 ACPI_FUNCTION_NAME (DsExecBeginControlOp);
81 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n",
82 Op, Op->Common.AmlOpcode, WalkState));
84 switch (Op->Common.AmlOpcode)
88 * If this is an additional iteration of a while loop, continue.
89 * There is no need to allocate a new control state.
91 if (WalkState->ControlState)
93 if (WalkState->ControlState->Control.AmlPredicateStart ==
94 (WalkState->ParserState.Aml - 1))
96 /* Reset the state to start-of-loop */
98 WalkState->ControlState->Common.State =
99 ACPI_CONTROL_CONDITIONAL_EXECUTING;
104 /*lint -fallthrough */
108 * IF/WHILE: Create a new control state to manage these
109 * constructs. We need to manage these as a stack, in order
112 ControlState = AcpiUtCreateControlState ();
115 Status = AE_NO_MEMORY;
119 * Save a pointer to the predicate for multiple executions
122 ControlState->Control.AmlPredicateStart = WalkState->ParserState.Aml - 1;
123 ControlState->Control.PackageEnd = WalkState->ParserState.PkgEnd;
124 ControlState->Control.Opcode = Op->Common.AmlOpcode;
127 /* Push the control state on this walk's control stack */
129 AcpiUtPushGenericState (&WalkState->ControlState, ControlState);
134 /* Predicate is in the state object */
135 /* If predicate is true, the IF was executed, ignore ELSE part */
137 if (WalkState->LastPredicate)
139 Status = AE_CTRL_TRUE;
157 /*******************************************************************************
159 * FUNCTION: AcpiDsExecEndControlOp
161 * PARAMETERS: WalkList - The list that owns the walk stack
162 * Op - The control Op
166 * DESCRIPTION: Handles all control ops encountered during control method
169 ******************************************************************************/
172 AcpiDsExecEndControlOp (
173 ACPI_WALK_STATE *WalkState,
174 ACPI_PARSE_OBJECT *Op)
176 ACPI_STATUS Status = AE_OK;
177 ACPI_GENERIC_STATE *ControlState;
180 ACPI_FUNCTION_NAME (DsExecEndControlOp);
183 switch (Op->Common.AmlOpcode)
187 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", Op));
190 * Save the result of the predicate in case there is an
193 WalkState->LastPredicate =
194 (BOOLEAN) WalkState->ControlState->Common.Value;
197 * Pop the control state that was created at the start
198 * of the IF and free it
200 ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
201 AcpiUtDeleteGenericState (ControlState);
210 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", Op));
212 ControlState = WalkState->ControlState;
213 if (ControlState->Common.Value)
215 /* Predicate was true, the body of the loop was just executed */
218 * This loop counter mechanism allows the interpreter to escape
219 * possibly infinite loops. This can occur in poorly written AML
220 * when the hardware does not respond within a while loop and the
221 * loop does not implement a timeout.
223 ControlState->Control.LoopCount++;
224 if (ControlState->Control.LoopCount > ACPI_MAX_LOOP_ITERATIONS)
226 Status = AE_AML_INFINITE_LOOP;
231 * Go back and evaluate the predicate and maybe execute the loop
234 Status = AE_CTRL_PENDING;
235 WalkState->AmlLastWhile = ControlState->Control.AmlPredicateStart;
239 /* Predicate was false, terminate this while loop */
241 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
242 "[WHILE_OP] termination! Op=%p\n",Op));
244 /* Pop this control state and free it */
246 ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
247 AcpiUtDeleteGenericState (ControlState);
252 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
253 "[RETURN_OP] Op=%p Arg=%p\n",Op, Op->Common.Value.Arg));
256 * One optional operand -- the return value
257 * It can be either an immediate operand or a result that
258 * has been bubbled up the tree
260 if (Op->Common.Value.Arg)
262 /* Since we have a real Return(), delete any implicit return */
264 AcpiDsClearImplicitReturn (WalkState);
266 /* Return statement has an immediate operand */
268 Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
269 if (ACPI_FAILURE (Status))
275 * If value being returned is a Reference (such as
276 * an arg or local), resolve it now because it may
277 * cease to exist at the end of the method.
279 Status = AcpiExResolveToValue (&WalkState->Operands [0], WalkState);
280 if (ACPI_FAILURE (Status))
286 * Get the return value and save as the last result
287 * value. This is the only place where WalkState->ReturnDesc
288 * is set to anything other than zero!
290 WalkState->ReturnDesc = WalkState->Operands[0];
292 else if (WalkState->ResultCount)
294 /* Since we have a real Return(), delete any implicit return */
296 AcpiDsClearImplicitReturn (WalkState);
299 * The return value has come from a previous calculation.
301 * If value being returned is a Reference (such as
302 * an arg or local), resolve it now because it may
303 * cease to exist at the end of the method.
305 * Allow references created by the Index operator to return
308 if ((ACPI_GET_DESCRIPTOR_TYPE (WalkState->Results->Results.ObjDesc[0]) == ACPI_DESC_TYPE_OPERAND) &&
309 ((WalkState->Results->Results.ObjDesc [0])->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
310 ((WalkState->Results->Results.ObjDesc [0])->Reference.Class != ACPI_REFCLASS_INDEX))
312 Status = AcpiExResolveToValue (&WalkState->Results->Results.ObjDesc [0], WalkState);
313 if (ACPI_FAILURE (Status))
319 WalkState->ReturnDesc = WalkState->Results->Results.ObjDesc [0];
323 /* No return operand */
325 if (WalkState->NumOperands)
327 AcpiUtRemoveReference (WalkState->Operands [0]);
330 WalkState->Operands [0] = NULL;
331 WalkState->NumOperands = 0;
332 WalkState->ReturnDesc = NULL;
336 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
337 "Completed RETURN_OP State=%p, RetVal=%p\n",
338 WalkState, WalkState->ReturnDesc));
340 /* End the control method execution right now */
342 Status = AE_CTRL_TERMINATE;
347 /* Just do nothing! */
351 case AML_BREAK_POINT_OP:
354 * Set the single-step flag. This will cause the debugger (if present)
355 * to break to the console within the AML debugger at the start of the
356 * next AML instruction.
359 AcpiGbl_CmSingleStep = TRUE);
361 AcpiOsPrintf ("**break** Executed AML BreakPoint opcode\n"));
363 /* Call to the OSL in case OS wants a piece of the action */
365 Status = AcpiOsSignal (ACPI_SIGNAL_BREAKPOINT,
366 "Executed AML Breakpoint opcode");
370 case AML_CONTINUE_OP: /* ACPI 2.0 */
372 /* Pop and delete control states until we find a while */
374 while (WalkState->ControlState &&
375 (WalkState->ControlState->Control.Opcode != AML_WHILE_OP))
377 ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
378 AcpiUtDeleteGenericState (ControlState);
381 /* No while found? */
383 if (!WalkState->ControlState)
385 return (AE_AML_NO_WHILE);
388 /* Was: WalkState->AmlLastWhile = WalkState->ControlState->Control.AmlPredicateStart; */
390 WalkState->AmlLastWhile = WalkState->ControlState->Control.PackageEnd;
392 /* Return status depending on opcode */
394 if (Op->Common.AmlOpcode == AML_BREAK_OP)
396 Status = AE_CTRL_BREAK;
400 Status = AE_CTRL_CONTINUE;
406 ACPI_ERROR ((AE_INFO, "Unknown control opcode=0x%X Op=%p",
407 Op->Common.AmlOpcode, Op));
409 Status = AE_AML_BAD_OPCODE;