Print this page
acpica-unix2-20130823
PANKOVs restructure
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/io/acpica/dispatcher/dscontrol.c
+++ new/usr/src/common/acpica/components/dispatcher/dscontrol.c
1 1 /******************************************************************************
2 2 *
3 3 * Module Name: dscontrol - Support for execution control opcodes -
4 4 * if/else/while/return
5 5 *
6 6 *****************************************************************************/
7 7
8 8 /*
9 - * Copyright (C) 2000 - 2011, Intel Corp.
9 + * Copyright (C) 2000 - 2013, Intel Corp.
10 10 * All rights reserved.
11 11 *
12 12 * Redistribution and use in source and binary forms, with or without
13 13 * modification, are permitted provided that the following conditions
14 14 * are met:
15 15 * 1. Redistributions of source code must retain the above copyright
16 16 * notice, this list of conditions, and the following disclaimer,
17 17 * without modification.
18 18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 19 * substantially similar to the "NO WARRANTY" disclaimer below
20 20 * ("Disclaimer") and any redistribution must be conditioned upon
21 21 * including a substantially similar Disclaimer requirement for further
22 22 * binary redistribution.
23 23 * 3. Neither the names of the above-listed copyright holders nor the names
24 24 * of any contributors may be used to endorse or promote products derived
25 25 * from this software without specific prior written permission.
26 26 *
27 27 * Alternatively, this software may be distributed under the terms of the
28 28 * GNU General Public License ("GPL") version 2 as published by the Free
29 29 * Software Foundation.
30 30 *
31 31 * NO WARRANTY
32 32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 42 * POSSIBILITY OF SUCH DAMAGES.
43 43 */
44 44
45 45 #define __DSCONTROL_C__
46 46
47 47 #include "acpi.h"
48 48 #include "accommon.h"
49 49 #include "amlcode.h"
50 50 #include "acdispat.h"
51 51 #include "acinterp.h"
52 52
53 53 #define _COMPONENT ACPI_DISPATCHER
54 54 ACPI_MODULE_NAME ("dscontrol")
55 55
56 56
57 57 /*******************************************************************************
58 58 *
59 59 * FUNCTION: AcpiDsExecBeginControlOp
60 60 *
61 61 * PARAMETERS: WalkList - The list that owns the walk stack
62 62 * Op - The control Op
63 63 *
64 64 * RETURN: Status
65 65 *
66 66 * DESCRIPTION: Handles all control ops encountered during control method
67 67 * execution.
68 68 *
69 69 ******************************************************************************/
70 70
71 71 ACPI_STATUS
72 72 AcpiDsExecBeginControlOp (
73 73 ACPI_WALK_STATE *WalkState,
74 74 ACPI_PARSE_OBJECT *Op)
75 75 {
76 76 ACPI_STATUS Status = AE_OK;
77 77 ACPI_GENERIC_STATE *ControlState;
78 78
↓ open down ↓ |
59 lines elided |
↑ open up ↑ |
79 79
80 80 ACPI_FUNCTION_NAME (DsExecBeginControlOp);
81 81
82 82
83 83 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n",
84 84 Op, Op->Common.AmlOpcode, WalkState));
85 85
86 86 switch (Op->Common.AmlOpcode)
87 87 {
88 88 case AML_WHILE_OP:
89 -
90 89 /*
91 90 * If this is an additional iteration of a while loop, continue.
92 91 * There is no need to allocate a new control state.
93 92 */
94 93 if (WalkState->ControlState)
95 94 {
96 95 if (WalkState->ControlState->Control.AmlPredicateStart ==
97 96 (WalkState->ParserState.Aml - 1))
98 97 {
99 98 /* Reset the state to start-of-loop */
100 99
101 100 WalkState->ControlState->Common.State =
102 101 ACPI_CONTROL_CONDITIONAL_EXECUTING;
103 102 break;
104 103 }
105 104 }
106 105
107 106 /*lint -fallthrough */
108 107
109 108 case AML_IF_OP:
110 -
111 109 /*
112 110 * IF/WHILE: Create a new control state to manage these
113 111 * constructs. We need to manage these as a stack, in order
114 112 * to handle nesting.
115 113 */
116 114 ControlState = AcpiUtCreateControlState ();
117 115 if (!ControlState)
118 116 {
119 117 Status = AE_NO_MEMORY;
120 118 break;
121 119 }
122 120 /*
123 121 * Save a pointer to the predicate for multiple executions
124 122 * of a loop
125 123 */
126 124 ControlState->Control.AmlPredicateStart = WalkState->ParserState.Aml - 1;
127 125 ControlState->Control.PackageEnd = WalkState->ParserState.PkgEnd;
128 126 ControlState->Control.Opcode = Op->Common.AmlOpcode;
129 127
130 128
131 129 /* Push the control state on this walk's control stack */
132 130
133 131 AcpiUtPushGenericState (&WalkState->ControlState, ControlState);
134 132 break;
135 133
136 134 case AML_ELSE_OP:
137 135
138 136 /* Predicate is in the state object */
139 137 /* If predicate is true, the IF was executed, ignore ELSE part */
140 138
141 139 if (WalkState->LastPredicate)
142 140 {
↓ open down ↓ |
22 lines elided |
↑ open up ↑ |
143 141 Status = AE_CTRL_TRUE;
144 142 }
145 143
146 144 break;
147 145
148 146 case AML_RETURN_OP:
149 147
150 148 break;
151 149
152 150 default:
151 +
153 152 break;
154 153 }
155 154
156 155 return (Status);
157 156 }
158 157
159 158
160 159 /*******************************************************************************
161 160 *
162 161 * FUNCTION: AcpiDsExecEndControlOp
163 162 *
164 163 * PARAMETERS: WalkList - The list that owns the walk stack
165 164 * Op - The control Op
166 165 *
167 166 * RETURN: Status
168 167 *
169 168 * DESCRIPTION: Handles all control ops encountered during control method
170 169 * execution.
171 170 *
172 171 ******************************************************************************/
173 172
174 173 ACPI_STATUS
175 174 AcpiDsExecEndControlOp (
176 175 ACPI_WALK_STATE *WalkState,
177 176 ACPI_PARSE_OBJECT *Op)
178 177 {
179 178 ACPI_STATUS Status = AE_OK;
180 179 ACPI_GENERIC_STATE *ControlState;
181 180
182 181
183 182 ACPI_FUNCTION_NAME (DsExecEndControlOp);
184 183
185 184
186 185 switch (Op->Common.AmlOpcode)
187 186 {
188 187 case AML_IF_OP:
189 188
190 189 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", Op));
191 190
192 191 /*
193 192 * Save the result of the predicate in case there is an
194 193 * ELSE to come
195 194 */
196 195 WalkState->LastPredicate =
↓ open down ↓ |
34 lines elided |
↑ open up ↑ |
197 196 (BOOLEAN) WalkState->ControlState->Common.Value;
198 197
199 198 /*
200 199 * Pop the control state that was created at the start
201 200 * of the IF and free it
202 201 */
203 202 ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
204 203 AcpiUtDeleteGenericState (ControlState);
205 204 break;
206 205
207 -
208 206 case AML_ELSE_OP:
209 207
210 208 break;
211 209
212 -
213 210 case AML_WHILE_OP:
214 211
215 212 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", Op));
216 213
217 214 ControlState = WalkState->ControlState;
218 215 if (ControlState->Common.Value)
219 216 {
220 217 /* Predicate was true, the body of the loop was just executed */
221 218
222 219 /*
223 220 * This loop counter mechanism allows the interpreter to escape
224 221 * possibly infinite loops. This can occur in poorly written AML
225 222 * when the hardware does not respond within a while loop and the
226 223 * loop does not implement a timeout.
227 224 */
228 225 ControlState->Control.LoopCount++;
229 226 if (ControlState->Control.LoopCount > ACPI_MAX_LOOP_ITERATIONS)
230 227 {
231 228 Status = AE_AML_INFINITE_LOOP;
232 229 break;
233 230 }
234 231
235 232 /*
236 233 * Go back and evaluate the predicate and maybe execute the loop
237 234 * another time
238 235 */
239 236 Status = AE_CTRL_PENDING;
240 237 WalkState->AmlLastWhile = ControlState->Control.AmlPredicateStart;
241 238 break;
242 239 }
243 240
244 241 /* Predicate was false, terminate this while loop */
↓ open down ↓ |
22 lines elided |
↑ open up ↑ |
245 242
246 243 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
247 244 "[WHILE_OP] termination! Op=%p\n",Op));
248 245
249 246 /* Pop this control state and free it */
250 247
251 248 ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
252 249 AcpiUtDeleteGenericState (ControlState);
253 250 break;
254 251
255 -
256 252 case AML_RETURN_OP:
257 253
258 254 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
259 255 "[RETURN_OP] Op=%p Arg=%p\n",Op, Op->Common.Value.Arg));
260 256
261 257 /*
262 258 * One optional operand -- the return value
263 259 * It can be either an immediate operand or a result that
264 260 * has been bubbled up the tree
265 261 */
266 262 if (Op->Common.Value.Arg)
267 263 {
268 264 /* Since we have a real Return(), delete any implicit return */
269 265
270 266 AcpiDsClearImplicitReturn (WalkState);
271 267
272 268 /* Return statement has an immediate operand */
273 269
274 270 Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
275 271 if (ACPI_FAILURE (Status))
276 272 {
277 273 return (Status);
278 274 }
279 275
280 276 /*
281 277 * If value being returned is a Reference (such as
282 278 * an arg or local), resolve it now because it may
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
283 279 * cease to exist at the end of the method.
284 280 */
285 281 Status = AcpiExResolveToValue (&WalkState->Operands [0], WalkState);
286 282 if (ACPI_FAILURE (Status))
287 283 {
288 284 return (Status);
289 285 }
290 286
291 287 /*
292 288 * Get the return value and save as the last result
293 - * value. This is the only place where WalkState->ReturnDesc
289 + * value. This is the only place where WalkState->ReturnDesc
294 290 * is set to anything other than zero!
295 291 */
296 292 WalkState->ReturnDesc = WalkState->Operands[0];
297 293 }
298 294 else if (WalkState->ResultCount)
299 295 {
300 296 /* Since we have a real Return(), delete any implicit return */
301 297
302 298 AcpiDsClearImplicitReturn (WalkState);
303 299
304 300 /*
305 301 * The return value has come from a previous calculation.
306 302 *
307 303 * If value being returned is a Reference (such as
308 304 * an arg or local), resolve it now because it may
309 305 * cease to exist at the end of the method.
310 306 *
311 307 * Allow references created by the Index operator to return
312 308 * unchanged.
313 309 */
314 310 if ((ACPI_GET_DESCRIPTOR_TYPE (WalkState->Results->Results.ObjDesc[0]) == ACPI_DESC_TYPE_OPERAND) &&
315 311 ((WalkState->Results->Results.ObjDesc [0])->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
316 312 ((WalkState->Results->Results.ObjDesc [0])->Reference.Class != ACPI_REFCLASS_INDEX))
317 313 {
318 314 Status = AcpiExResolveToValue (&WalkState->Results->Results.ObjDesc [0], WalkState);
319 315 if (ACPI_FAILURE (Status))
320 316 {
321 317 return (Status);
322 318 }
323 319 }
324 320
325 321 WalkState->ReturnDesc = WalkState->Results->Results.ObjDesc [0];
326 322 }
327 323 else
328 324 {
329 325 /* No return operand */
330 326
331 327 if (WalkState->NumOperands)
332 328 {
333 329 AcpiUtRemoveReference (WalkState->Operands [0]);
334 330 }
335 331
336 332 WalkState->Operands [0] = NULL;
337 333 WalkState->NumOperands = 0;
338 334 WalkState->ReturnDesc = NULL;
339 335 }
340 336
↓ open down ↓ |
37 lines elided |
↑ open up ↑ |
341 337
342 338 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
343 339 "Completed RETURN_OP State=%p, RetVal=%p\n",
344 340 WalkState, WalkState->ReturnDesc));
345 341
346 342 /* End the control method execution right now */
347 343
348 344 Status = AE_CTRL_TERMINATE;
349 345 break;
350 346
351 -
352 347 case AML_NOOP_OP:
353 348
354 349 /* Just do nothing! */
350 +
355 351 break;
356 352
357 -
358 353 case AML_BREAK_POINT_OP:
359 354
360 355 /*
361 356 * Set the single-step flag. This will cause the debugger (if present)
362 357 * to break to the console within the AML debugger at the start of the
363 358 * next AML instruction.
364 359 */
365 360 ACPI_DEBUGGER_EXEC (
366 361 AcpiGbl_CmSingleStep = TRUE);
367 362 ACPI_DEBUGGER_EXEC (
368 363 AcpiOsPrintf ("**break** Executed AML BreakPoint opcode\n"));
369 364
370 365 /* Call to the OSL in case OS wants a piece of the action */
371 366
372 367 Status = AcpiOsSignal (ACPI_SIGNAL_BREAKPOINT,
373 368 "Executed AML Breakpoint opcode");
374 369 break;
375 370
376 -
377 371 case AML_BREAK_OP:
378 372 case AML_CONTINUE_OP: /* ACPI 2.0 */
379 373
380 -
381 374 /* Pop and delete control states until we find a while */
382 375
383 376 while (WalkState->ControlState &&
384 377 (WalkState->ControlState->Control.Opcode != AML_WHILE_OP))
385 378 {
386 379 ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
387 380 AcpiUtDeleteGenericState (ControlState);
388 381 }
389 382
390 383 /* No while found? */
391 384
392 385 if (!WalkState->ControlState)
393 386 {
394 387 return (AE_AML_NO_WHILE);
395 388 }
396 389
397 390 /* Was: WalkState->AmlLastWhile = WalkState->ControlState->Control.AmlPredicateStart; */
398 391
399 392 WalkState->AmlLastWhile = WalkState->ControlState->Control.PackageEnd;
400 393
401 394 /* Return status depending on opcode */
402 395
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
403 396 if (Op->Common.AmlOpcode == AML_BREAK_OP)
404 397 {
405 398 Status = AE_CTRL_BREAK;
406 399 }
407 400 else
408 401 {
409 402 Status = AE_CTRL_CONTINUE;
410 403 }
411 404 break;
412 405
413 -
414 406 default:
415 407
416 408 ACPI_ERROR ((AE_INFO, "Unknown control opcode=0x%X Op=%p",
417 409 Op->Common.AmlOpcode, Op));
418 410
419 411 Status = AE_AML_BAD_OPCODE;
420 412 break;
421 413 }
422 414
423 415 return (Status);
424 416 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX