1 /******************************************************************************
3 * Module Name: dscontrol - Support for execution control opcodes -
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2013, 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.
45 #define __DSCONTROL_C__
53 #define _COMPONENT ACPI_DISPATCHER
54 ACPI_MODULE_NAME ("dscontrol")
57 /*******************************************************************************
59 * FUNCTION: AcpiDsExecBeginControlOp
61 * PARAMETERS: WalkList - The list that owns the walk stack
66 * DESCRIPTION: Handles all control ops encountered during control method
69 ******************************************************************************/
72 AcpiDsExecBeginControlOp (
73 ACPI_WALK_STATE
*WalkState
,
74 ACPI_PARSE_OBJECT
*Op
)
76 ACPI_STATUS Status
= AE_OK
;
77 ACPI_GENERIC_STATE
*ControlState
;
80 ACPI_FUNCTION_NAME (DsExecBeginControlOp
);
83 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
, "Op=%p Opcode=%2.2X State=%p\n",
84 Op
, Op
->Common
.AmlOpcode
, WalkState
));
86 switch (Op
->Common
.AmlOpcode
)
90 * If this is an additional iteration of a while loop, continue.
91 * There is no need to allocate a new control state.
93 if (WalkState
->ControlState
)
95 if (WalkState
->ControlState
->Control
.AmlPredicateStart
==
96 (WalkState
->ParserState
.Aml
- 1))
98 /* Reset the state to start-of-loop */
100 WalkState
->ControlState
->Common
.State
=
101 ACPI_CONTROL_CONDITIONAL_EXECUTING
;
106 /*lint -fallthrough */
110 * IF/WHILE: Create a new control state to manage these
111 * constructs. We need to manage these as a stack, in order
114 ControlState
= AcpiUtCreateControlState ();
117 Status
= AE_NO_MEMORY
;
121 * Save a pointer to the predicate for multiple executions
124 ControlState
->Control
.AmlPredicateStart
= WalkState
->ParserState
.Aml
- 1;
125 ControlState
->Control
.PackageEnd
= WalkState
->ParserState
.PkgEnd
;
126 ControlState
->Control
.Opcode
= Op
->Common
.AmlOpcode
;
129 /* Push the control state on this walk's control stack */
131 AcpiUtPushGenericState (&WalkState
->ControlState
, ControlState
);
136 /* Predicate is in the state object */
137 /* If predicate is true, the IF was executed, ignore ELSE part */
139 if (WalkState
->LastPredicate
)
141 Status
= AE_CTRL_TRUE
;
159 /*******************************************************************************
161 * FUNCTION: AcpiDsExecEndControlOp
163 * PARAMETERS: WalkList - The list that owns the walk stack
164 * Op - The control Op
168 * DESCRIPTION: Handles all control ops encountered during control method
171 ******************************************************************************/
174 AcpiDsExecEndControlOp (
175 ACPI_WALK_STATE
*WalkState
,
176 ACPI_PARSE_OBJECT
*Op
)
178 ACPI_STATUS Status
= AE_OK
;
179 ACPI_GENERIC_STATE
*ControlState
;
182 ACPI_FUNCTION_NAME (DsExecEndControlOp
);
185 switch (Op
->Common
.AmlOpcode
)
189 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
, "[IF_OP] Op=%p\n", Op
));
192 * Save the result of the predicate in case there is an
195 WalkState
->LastPredicate
=
196 (BOOLEAN
) WalkState
->ControlState
->Common
.Value
;
199 * Pop the control state that was created at the start
200 * of the IF and free it
202 ControlState
= AcpiUtPopGenericState (&WalkState
->ControlState
);
203 AcpiUtDeleteGenericState (ControlState
);
212 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
, "[WHILE_OP] Op=%p\n", Op
));
214 ControlState
= WalkState
->ControlState
;
215 if (ControlState
->Common
.Value
)
217 /* Predicate was true, the body of the loop was just executed */
220 * This loop counter mechanism allows the interpreter to escape
221 * possibly infinite loops. This can occur in poorly written AML
222 * when the hardware does not respond within a while loop and the
223 * loop does not implement a timeout.
225 ControlState
->Control
.LoopCount
++;
226 if (ControlState
->Control
.LoopCount
> ACPI_MAX_LOOP_ITERATIONS
)
228 Status
= AE_AML_INFINITE_LOOP
;
233 * Go back and evaluate the predicate and maybe execute the loop
236 Status
= AE_CTRL_PENDING
;
237 WalkState
->AmlLastWhile
= ControlState
->Control
.AmlPredicateStart
;
241 /* Predicate was false, terminate this while loop */
243 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
244 "[WHILE_OP] termination! Op=%p\n",Op
));
246 /* Pop this control state and free it */
248 ControlState
= AcpiUtPopGenericState (&WalkState
->ControlState
);
249 AcpiUtDeleteGenericState (ControlState
);
254 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
255 "[RETURN_OP] Op=%p Arg=%p\n",Op
, Op
->Common
.Value
.Arg
));
258 * One optional operand -- the return value
259 * It can be either an immediate operand or a result that
260 * has been bubbled up the tree
262 if (Op
->Common
.Value
.Arg
)
264 /* Since we have a real Return(), delete any implicit return */
266 AcpiDsClearImplicitReturn (WalkState
);
268 /* Return statement has an immediate operand */
270 Status
= AcpiDsCreateOperands (WalkState
, Op
->Common
.Value
.Arg
);
271 if (ACPI_FAILURE (Status
))
277 * If value being returned is a Reference (such as
278 * an arg or local), resolve it now because it may
279 * cease to exist at the end of the method.
281 Status
= AcpiExResolveToValue (&WalkState
->Operands
[0], WalkState
);
282 if (ACPI_FAILURE (Status
))
288 * Get the return value and save as the last result
289 * value. This is the only place where WalkState->ReturnDesc
290 * is set to anything other than zero!
292 WalkState
->ReturnDesc
= WalkState
->Operands
[0];
294 else if (WalkState
->ResultCount
)
296 /* Since we have a real Return(), delete any implicit return */
298 AcpiDsClearImplicitReturn (WalkState
);
301 * The return value has come from a previous calculation.
303 * If value being returned is a Reference (such as
304 * an arg or local), resolve it now because it may
305 * cease to exist at the end of the method.
307 * Allow references created by the Index operator to return
310 if ((ACPI_GET_DESCRIPTOR_TYPE (WalkState
->Results
->Results
.ObjDesc
[0]) == ACPI_DESC_TYPE_OPERAND
) &&
311 ((WalkState
->Results
->Results
.ObjDesc
[0])->Common
.Type
== ACPI_TYPE_LOCAL_REFERENCE
) &&
312 ((WalkState
->Results
->Results
.ObjDesc
[0])->Reference
.Class
!= ACPI_REFCLASS_INDEX
))
314 Status
= AcpiExResolveToValue (&WalkState
->Results
->Results
.ObjDesc
[0], WalkState
);
315 if (ACPI_FAILURE (Status
))
321 WalkState
->ReturnDesc
= WalkState
->Results
->Results
.ObjDesc
[0];
325 /* No return operand */
327 if (WalkState
->NumOperands
)
329 AcpiUtRemoveReference (WalkState
->Operands
[0]);
332 WalkState
->Operands
[0] = NULL
;
333 WalkState
->NumOperands
= 0;
334 WalkState
->ReturnDesc
= NULL
;
338 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
339 "Completed RETURN_OP State=%p, RetVal=%p\n",
340 WalkState
, WalkState
->ReturnDesc
));
342 /* End the control method execution right now */
344 Status
= AE_CTRL_TERMINATE
;
349 /* Just do nothing! */
353 case AML_BREAK_POINT_OP
:
356 * Set the single-step flag. This will cause the debugger (if present)
357 * to break to the console within the AML debugger at the start of the
358 * next AML instruction.
361 AcpiGbl_CmSingleStep
= TRUE
);
363 AcpiOsPrintf ("**break** Executed AML BreakPoint opcode\n"));
365 /* Call to the OSL in case OS wants a piece of the action */
367 Status
= AcpiOsSignal (ACPI_SIGNAL_BREAKPOINT
,
368 "Executed AML Breakpoint opcode");
372 case AML_CONTINUE_OP
: /* ACPI 2.0 */
374 /* Pop and delete control states until we find a while */
376 while (WalkState
->ControlState
&&
377 (WalkState
->ControlState
->Control
.Opcode
!= AML_WHILE_OP
))
379 ControlState
= AcpiUtPopGenericState (&WalkState
->ControlState
);
380 AcpiUtDeleteGenericState (ControlState
);
383 /* No while found? */
385 if (!WalkState
->ControlState
)
387 return (AE_AML_NO_WHILE
);
390 /* Was: WalkState->AmlLastWhile = WalkState->ControlState->Control.AmlPredicateStart; */
392 WalkState
->AmlLastWhile
= WalkState
->ControlState
->Control
.PackageEnd
;
394 /* Return status depending on opcode */
396 if (Op
->Common
.AmlOpcode
== AML_BREAK_OP
)
398 Status
= AE_CTRL_BREAK
;
402 Status
= AE_CTRL_CONTINUE
;
408 ACPI_ERROR ((AE_INFO
, "Unknown control opcode=0x%X Op=%p",
409 Op
->Common
.AmlOpcode
, Op
));
411 Status
= AE_AML_BAD_OPCODE
;