ReactOS 0.4.16-dev-226-g79f2289
dscontrol.c File Reference
#include "acpi.h"
#include "accommon.h"
#include "amlcode.h"
#include "acdispat.h"
#include "acinterp.h"
#include "acdebug.h"
Include dependency graph for dscontrol.c:

Go to the source code of this file.

Macros

#define _COMPONENT   ACPI_DISPATCHER
 

Functions

ACPI_STATUS AcpiDsExecBeginControlOp (ACPI_WALK_STATE *WalkState, ACPI_PARSE_OBJECT *Op)
 
ACPI_STATUS AcpiDsExecEndControlOp (ACPI_WALK_STATE *WalkState, ACPI_PARSE_OBJECT *Op)
 

Macro Definition Documentation

◆ _COMPONENT

#define _COMPONENT   ACPI_DISPATCHER

Definition at line 52 of file dscontrol.c.

Function Documentation

◆ AcpiDsExecBeginControlOp()

ACPI_STATUS AcpiDsExecBeginControlOp ( ACPI_WALK_STATE WalkState,
ACPI_PARSE_OBJECT Op 
)

Definition at line 71 of file dscontrol.c.

74{
76 ACPI_GENERIC_STATE *ControlState;
77
78
79 ACPI_FUNCTION_NAME (DsExecBeginControlOp);
80
81
82 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n",
83 Op, Op->Common.AmlOpcode, WalkState));
84
85 switch (Op->Common.AmlOpcode)
86 {
87 case AML_WHILE_OP:
88 /*
89 * If this is an additional iteration of a while loop, continue.
90 * There is no need to allocate a new control state.
91 */
92 if (WalkState->ControlState)
93 {
94 if (WalkState->ControlState->Control.AmlPredicateStart ==
95 (WalkState->ParserState.Aml - 1))
96 {
97 /* Reset the state to start-of-loop */
98
99 WalkState->ControlState->Common.State =
101 break;
102 }
103 }
104
106
107 case AML_IF_OP:
108 /*
109 * IF/WHILE: Create a new control state to manage these
110 * constructs. We need to manage these as a stack, in order
111 * to handle nesting.
112 */
113 ControlState = AcpiUtCreateControlState ();
114 if (!ControlState)
115 {
117 break;
118 }
119 /*
120 * Save a pointer to the predicate for multiple executions
121 * of a loop
122 */
123 ControlState->Control.AmlPredicateStart =
124 WalkState->ParserState.Aml - 1;
125 ControlState->Control.PackageEnd =
126 WalkState->ParserState.PkgEnd;
127 ControlState->Control.Opcode =
128 Op->Common.AmlOpcode;
129 ControlState->Control.LoopTimeout = AcpiOsGetTimer () +
130 ((UINT64) AcpiGbl_MaxLoopIterations * ACPI_100NSEC_PER_SEC);
131
132 /* Push the control state on this walk's control stack */
133
134 AcpiUtPushGenericState (&WalkState->ControlState, ControlState);
135 break;
136
137 case AML_ELSE_OP:
138
139 /* Predicate is in the state object */
140 /* If predicate is true, the IF was executed, ignore ELSE part */
141
142 if (WalkState->LastPredicate)
143 {
145 }
146
147 break;
148
149 case AML_RETURN_OP:
150
151 break;
152
153 default:
154
155 break;
156 }
157
158 return (Status);
159}
unsigned long long UINT64
#define AE_CTRL_TRUE
Definition: acexcep.h:227
#define AE_NO_MEMORY
Definition: acexcep.h:112
#define AE_OK
Definition: acexcep.h:97
#define ACPI_CONTROL_CONDITIONAL_EXECUTING
Definition: aclocal.h:670
#define ACPI_DB_DISPATCH
Definition: acoutput.h:163
#define ACPI_DEBUG_PRINT(pl)
Definition: acoutput.h:475
#define ACPI_FUNCTION_NAME(a)
Definition: acoutput.h:479
UINT64 AcpiOsGetTimer(void)
Definition: osl.c:884
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_100NSEC_PER_SEC
Definition: actypes.h:475
#define ACPI_FALLTHROUGH
Definition: actypes.h:1466
ACPI_GENERIC_STATE * AcpiUtCreateControlState(void)
Definition: utstate.c:300
void AcpiUtPushGenericState(ACPI_GENERIC_STATE **ListHead, ACPI_GENERIC_STATE *State)
Definition: utstate.c:65
#define AML_RETURN_OP
Definition: amlcode.h:138
#define AML_IF_OP
Definition: amlcode.h:134
#define AML_ELSE_OP
Definition: amlcode.h:135
#define AML_WHILE_OP
Definition: amlcode.h:136
Status
Definition: gdiplustypes.h:25
UINT64 LoopTimeout
Definition: aclocal.h:729
UINT8 * AmlPredicateStart
Definition: aclocal.h:727
UINT8 * PackageEnd
Definition: aclocal.h:728
ACPI_STATE_COMMON UINT16 Opcode
Definition: aclocal.h:725
UINT8 * PkgEnd
Definition: aclocal.h:1105
BOOLEAN LastPredicate
Definition: acstruct.h:83
ACPI_GENERIC_STATE * ControlState
Definition: acstruct.h:110
ACPI_PARSE_STATE ParserState
Definition: acstruct.h:97
ACPI_COMMON_STATE Common
Definition: aclocal.h:822
ACPI_CONTROL_STATE Control
Definition: aclocal.h:823
ACPI_PARSE_OBJ_COMMON Common
Definition: aclocal.h:1078

Referenced by AcpiDsExecBeginOp().

◆ AcpiDsExecEndControlOp()

ACPI_STATUS AcpiDsExecEndControlOp ( ACPI_WALK_STATE WalkState,
ACPI_PARSE_OBJECT Op 
)

Definition at line 177 of file dscontrol.c.

180{
182 ACPI_GENERIC_STATE *ControlState;
183
184
185 ACPI_FUNCTION_NAME (DsExecEndControlOp);
186
187
188 switch (Op->Common.AmlOpcode)
189 {
190 case AML_IF_OP:
191
192 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", Op));
193
194 /*
195 * Save the result of the predicate in case there is an
196 * ELSE to come
197 */
198 WalkState->LastPredicate =
199 (BOOLEAN) WalkState->ControlState->Common.Value;
200
201 /*
202 * Pop the control state that was created at the start
203 * of the IF and free it
204 */
205 ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
206 AcpiUtDeleteGenericState (ControlState);
207 break;
208
209 case AML_ELSE_OP:
210
211 break;
212
213 case AML_WHILE_OP:
214
215 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", Op));
216
217 ControlState = WalkState->ControlState;
218 if (ControlState->Common.Value)
219 {
220 /* Predicate was true, the body of the loop was just executed */
221
222 /*
223 * This infinite loop detection mechanism allows the interpreter
224 * to escape possibly infinite loops. This can occur in poorly
225 * written AML when the hardware does not respond within a while
226 * loop and the loop does not implement a timeout.
227 */
229 ControlState->Control.LoopTimeout))
230 {
232 break;
233 }
234
235 /*
236 * Go back and evaluate the predicate and maybe execute the loop
237 * another time
238 */
240 WalkState->AmlLastWhile =
241 ControlState->Control.AmlPredicateStart;
242 break;
243 }
244
245 /* Predicate was false, terminate this while loop */
246
248 "[WHILE_OP] termination! Op=%p\n",Op));
249
250 /* Pop this control state and free it */
251
252 ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
253 AcpiUtDeleteGenericState (ControlState);
254 break;
255
256 case AML_RETURN_OP:
257
259 "[RETURN_OP] Op=%p Arg=%p\n",Op, Op->Common.Value.Arg));
260
261 /*
262 * One optional operand -- the return value
263 * It can be either an immediate operand or a result that
264 * has been bubbled up the tree
265 */
266 if (Op->Common.Value.Arg)
267 {
268 /* Since we have a real Return(), delete any implicit return */
269
270 AcpiDsClearImplicitReturn (WalkState);
271
272 /* Return statement has an immediate operand */
273
274 Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
275 if (ACPI_FAILURE (Status))
276 {
277 return (Status);
278 }
279
280 /*
281 * If value being returned is a Reference (such as
282 * an arg or local), resolve it now because it may
283 * cease to exist at the end of the method.
284 */
286 &WalkState->Operands [0], WalkState);
287 if (ACPI_FAILURE (Status))
288 {
289 return (Status);
290 }
291
292 /*
293 * Get the return value and save as the last result
294 * value. This is the only place where WalkState->ReturnDesc
295 * is set to anything other than zero!
296 */
297 WalkState->ReturnDesc = WalkState->Operands[0];
298 }
299 else if (WalkState->ResultCount)
300 {
301 /* Since we have a real Return(), delete any implicit return */
302
303 AcpiDsClearImplicitReturn (WalkState);
304
305 /*
306 * The return value has come from a previous calculation.
307 *
308 * If value being returned is a Reference (such as
309 * an arg or local), resolve it now because it may
310 * cease to exist at the end of the method.
311 *
312 * Allow references created by the Index operator to return
313 * unchanged.
314 */
315 if ((ACPI_GET_DESCRIPTOR_TYPE (WalkState->Results->Results.ObjDesc[0]) ==
317 ((WalkState->Results->Results.ObjDesc [0])->Common.Type ==
319 ((WalkState->Results->Results.ObjDesc [0])->Reference.Class !=
321 {
323 &WalkState->Results->Results.ObjDesc [0], WalkState);
324 if (ACPI_FAILURE (Status))
325 {
326 return (Status);
327 }
328 }
329
330 WalkState->ReturnDesc = WalkState->Results->Results.ObjDesc [0];
331 }
332 else
333 {
334 /* No return operand */
335
336 if (WalkState->NumOperands)
337 {
338 AcpiUtRemoveReference (WalkState->Operands [0]);
339 }
340
341 WalkState->Operands[0] = NULL;
342 WalkState->NumOperands = 0;
343 WalkState->ReturnDesc = NULL;
344 }
345
346
348 "Completed RETURN_OP State=%p, RetVal=%p\n",
349 WalkState, WalkState->ReturnDesc));
350
351 /* End the control method execution right now */
352
354 break;
355
356 case AML_NOOP_OP:
357
358 /* Just do nothing! */
359
360 break;
361
363
364 AcpiDbSignalBreakPoint (WalkState);
365
366 /* Call to the OSL in case OS wants a piece of the action */
367
369 "Executed AML Breakpoint opcode");
370 break;
371
372 case AML_BREAK_OP:
373 case AML_CONTINUE_OP: /* ACPI 2.0 */
374
375 /* Pop and delete control states until we find a while */
376
377 while (WalkState->ControlState &&
378 (WalkState->ControlState->Control.Opcode != AML_WHILE_OP))
379 {
380 ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
381 AcpiUtDeleteGenericState (ControlState);
382 }
383
384 /* No while found? */
385
386 if (!WalkState->ControlState)
387 {
388 return (AE_AML_NO_WHILE);
389 }
390
391 /* Was: WalkState->AmlLastWhile = WalkState->ControlState->Control.AmlPredicateStart; */
392
393 WalkState->AmlLastWhile =
394 WalkState->ControlState->Control.PackageEnd;
395
396 /* Return status depending on opcode */
397
398 if (Op->Common.AmlOpcode == AML_BREAK_OP)
399 {
401 }
402 else
403 {
405 }
406 break;
407
408 default:
409
410 ACPI_ERROR ((AE_INFO, "Unknown control opcode=0x%X Op=%p",
411 Op->Common.AmlOpcode, Op));
412
414 break;
415 }
416
417 return (Status);
418}
#define AE_CTRL_CONTINUE
Definition: acexcep.h:233
#define AE_AML_LOOP_TIMEOUT
Definition: acexcep.h:212
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define AE_AML_BAD_OPCODE
Definition: acexcep.h:180
#define AE_CTRL_PENDING
Definition: acexcep.h:225
#define AE_CTRL_BREAK
Definition: acexcep.h:232
#define AE_CTRL_TERMINATE
Definition: acexcep.h:226
#define AE_AML_NO_WHILE
Definition: acexcep.h:205
#define ACPI_GET_DESCRIPTOR_TYPE(d)
Definition: acmacros.h:414
#define ACPI_DESC_TYPE_OPERAND
Definition: acobject.h:576
@ ACPI_REFCLASS_INDEX
Definition: acobject.h:462
#define ACPI_ERROR(plist)
Definition: acoutput.h:240
#define AE_INFO
Definition: acoutput.h:230
#define ACPI_SIGNAL_BREAKPOINT
Definition: acpiosxf.h:74
ACPI_STATUS AcpiOsSignal(UINT32 Function, void *Info)
Definition: osl.c:904
#define ACPI_TYPE_LOCAL_REFERENCE
Definition: actypes.h:719
#define ACPI_TIME_AFTER(a, b)
Definition: actypes.h:481
void AcpiUtRemoveReference(ACPI_OPERAND_OBJECT *Object)
Definition: utdelete.c:790
ACPI_GENERIC_STATE * AcpiUtPopGenericState(ACPI_GENERIC_STATE **ListHead)
Definition: utstate.c:93
void AcpiUtDeleteGenericState(ACPI_GENERIC_STATE *State)
Definition: utstate.c:340
#define AML_BREAK_OP
Definition: amlcode.h:139
#define AML_BREAKPOINT_OP
Definition: amlcode.h:141
#define AML_NOOP_OP
Definition: amlcode.h:137
#define AML_CONTINUE_OP
Definition: amlcode.h:133
#define NULL
Definition: types.h:112
void AcpiDsClearImplicitReturn(ACPI_WALK_STATE *WalkState)
Definition: dsutils.c:73
ACPI_STATUS AcpiDsCreateOperands(ACPI_WALK_STATE *WalkState, ACPI_PARSE_OBJECT *FirstArg)
Definition: dsutils.c:753
ACPI_STATUS AcpiExResolveToValue(ACPI_OPERAND_OBJECT **StackPtr, ACPI_WALK_STATE *WalkState)
Definition: exresolv.c:79
#define BOOLEAN
Definition: pedump.c:73
ACPI_STATE_COMMON union acpi_operand_object * ObjDesc[ACPI_RESULTS_FRAME_OBJ_NUM]
Definition: aclocal.h:779
union acpi_operand_object * Operands[ACPI_OBJ_NUM_OPERANDS+1]
Definition: acstruct.h:105
ACPI_GENERIC_STATE * Results
Definition: acstruct.h:122
union acpi_operand_object * ReturnDesc
Definition: acstruct.h:123
UINT8 * AmlLastWhile
Definition: acstruct.h:108
UINT8 ResultCount
Definition: acstruct.h:90
UINT8 NumOperands
Definition: acstruct.h:80
ACPI_RESULT_VALUES Results
Definition: aclocal.h:829

Referenced by AcpiDsExecEndOp().