Rev 1498 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1498 | serge | 1 | |
2 | * |
||
3 | * Module Name: aslfold - Constant folding |
||
4 | * |
||
5 | *****************************************************************************/ |
||
6 | |||
7 | |||
8 | * |
||
9 | * 1. Copyright Notice |
||
10 | * |
||
11 | * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp. |
||
2216 | Serge | 12 | * All rights reserved. |
1498 | serge | 13 | * |
14 | * 2. License |
||
15 | * |
||
16 | * 2.1. This is your license from Intel Corp. under its intellectual property |
||
17 | * rights. You may have additional license terms from the party that provided |
||
18 | * you this software, covering your right to use that party's intellectual |
||
19 | * property rights. |
||
20 | * |
||
21 | * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a |
||
22 | * copy of the source code appearing in this file ("Covered Code") an |
||
23 | * irrevocable, perpetual, worldwide license under Intel's copyrights in the |
||
24 | * base code distributed originally by Intel ("Original Intel Code") to copy, |
||
25 | * make derivatives, distribute, use and display any portion of the Covered |
||
26 | * Code in any form, with the right to sublicense such rights; and |
||
27 | * |
||
28 | * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent |
||
29 | * license (with the right to sublicense), under only those claims of Intel |
||
30 | * patents that are infringed by the Original Intel Code, to make, use, sell, |
||
31 | * offer to sell, and import the Covered Code and derivative works thereof |
||
32 | * solely to the minimum extent necessary to exercise the above copyright |
||
33 | * license, and in no event shall the patent license extend to any additions |
||
34 | * to or modifications of the Original Intel Code. No other license or right |
||
35 | * is granted directly or by implication, estoppel or otherwise; |
||
36 | * |
||
37 | * The above copyright and patent license is granted only if the following |
||
38 | * conditions are met: |
||
39 | * |
||
40 | * 3. Conditions |
||
41 | * |
||
42 | * 3.1. Redistribution of Source with Rights to Further Distribute Source. |
||
43 | * Redistribution of source code of any substantial portion of the Covered |
||
44 | * Code or modification with rights to further distribute source must include |
||
45 | * the above Copyright Notice, the above License, this list of Conditions, |
||
46 | * and the following Disclaimer and Export Compliance provision. In addition, |
||
47 | * Licensee must cause all Covered Code to which Licensee contributes to |
||
48 | * contain a file documenting the changes Licensee made to create that Covered |
||
49 | * Code and the date of any change. Licensee must include in that file the |
||
50 | * documentation of any changes made by any predecessor Licensee. Licensee |
||
51 | * must include a prominent statement that the modification is derived, |
||
52 | * directly or indirectly, from Original Intel Code. |
||
53 | * |
||
54 | * 3.2. Redistribution of Source with no Rights to Further Distribute Source. |
||
55 | * Redistribution of source code of any substantial portion of the Covered |
||
56 | * Code or modification without rights to further distribute source must |
||
57 | * include the following Disclaimer and Export Compliance provision in the |
||
58 | * documentation and/or other materials provided with distribution. In |
||
59 | * addition, Licensee may not authorize further sublicense of source of any |
||
60 | * portion of the Covered Code, and must include terms to the effect that the |
||
61 | * license from Licensee to its licensee is limited to the intellectual |
||
62 | * property embodied in the software Licensee provides to its licensee, and |
||
63 | * not to intellectual property embodied in modifications its licensee may |
||
64 | * make. |
||
65 | * |
||
66 | * 3.3. Redistribution of Executable. Redistribution in executable form of any |
||
67 | * substantial portion of the Covered Code or modification must reproduce the |
||
68 | * above Copyright Notice, and the following Disclaimer and Export Compliance |
||
69 | * provision in the documentation and/or other materials provided with the |
||
70 | * distribution. |
||
71 | * |
||
72 | * 3.4. Intel retains all right, title, and interest in and to the Original |
||
73 | * Intel Code. |
||
74 | * |
||
75 | * 3.5. Neither the name Intel nor any other trademark owned or controlled by |
||
76 | * Intel shall be used in advertising or otherwise to promote the sale, use or |
||
77 | * other dealings in products derived from or relating to the Covered Code |
||
78 | * without prior written authorization from Intel. |
||
79 | * |
||
80 | * 4. Disclaimer and Export Compliance |
||
81 | * |
||
82 | * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED |
||
83 | * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE |
||
84 | * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, |
||
85 | * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY |
||
86 | * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY |
||
87 | * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A |
||
88 | * PARTICULAR PURPOSE. |
||
89 | * |
||
90 | * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES |
||
91 | * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR |
||
92 | * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, |
||
93 | * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY |
||
94 | * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL |
||
95 | * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS |
||
96 | * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY |
||
97 | * LIMITED REMEDY. |
||
98 | * |
||
99 | * 4.3. Licensee shall not export, either directly or indirectly, any of this |
||
100 | * software or system incorporating such software without first obtaining any |
||
101 | * required license or other approval from the U. S. Department of Commerce or |
||
102 | * any other agency or department of the United States Government. In the |
||
103 | * event Licensee exports any such software from the United States or |
||
104 | * re-exports any such software from a foreign destination, Licensee shall |
||
105 | * ensure that the distribution and export/re-export of the software is in |
||
106 | * compliance with all laws, regulations, orders, or other restrictions of the |
||
107 | * U.S. Export Administration Regulations. Licensee agrees that neither it nor |
||
108 | * any of its subsidiaries will export/re-export any technical data, process, |
||
109 | * software, or service, directly or indirectly, to any country for which the |
||
110 | * United States government or any agency thereof requires an export license, |
||
111 | * other governmental approval, or letter of assurance, without first obtaining |
||
112 | * such license, approval or letter. |
||
113 | * |
||
114 | *****************************************************************************/ |
||
115 | |||
116 | |||
117 | |||
118 | #include "aslcompiler.y.h" |
||
119 | #include "amlcode.h" |
||
120 | |||
121 | |||
122 | #include "acparser.h" |
||
123 | |||
124 | |||
125 | ACPI_MODULE_NAME ("aslfold") |
||
126 | |||
127 | |||
128 | |||
129 | |||
130 | OpcAmlEvaluationWalk1 ( |
||
131 | ACPI_PARSE_OBJECT *Op, |
||
132 | UINT32 Level, |
||
133 | void *Context); |
||
134 | |||
135 | |||
136 | OpcAmlEvaluationWalk2 ( |
||
137 | ACPI_PARSE_OBJECT *Op, |
||
138 | UINT32 Level, |
||
139 | void *Context); |
||
140 | |||
141 | |||
142 | OpcAmlCheckForConstant ( |
||
143 | ACPI_PARSE_OBJECT *Op, |
||
144 | UINT32 Level, |
||
145 | void *Context); |
||
146 | |||
147 | |||
148 | |||
149 | * |
||
150 | * FUNCTION: OpcAmlEvaluationWalk1 |
||
151 | * |
||
152 | * PARAMETERS: ASL_WALK_CALLBACK |
||
153 | * |
||
154 | * RETURN: Status |
||
155 | * |
||
156 | * DESCRIPTION: Descending callback for AML execution of constant subtrees |
||
157 | * |
||
158 | ******************************************************************************/ |
||
159 | |||
160 | |||
161 | OpcAmlEvaluationWalk1 ( |
||
162 | ACPI_PARSE_OBJECT *Op, |
||
163 | UINT32 Level, |
||
164 | void *Context) |
||
165 | { |
||
166 | ACPI_WALK_STATE *WalkState = Context; |
||
167 | ACPI_STATUS Status; |
||
168 | ACPI_PARSE_OBJECT *OutOp; |
||
169 | |||
170 | |||
171 | |||
172 | WalkState->Opcode = Op->Common.AmlOpcode; |
||
173 | WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode); |
||
174 | |||
175 | |||
176 | |||
177 | |||
178 | { |
||
179 | Op->Common.Value.Arg = Op->Asl.Child; |
||
180 | } |
||
181 | |||
182 | |||
183 | |||
184 | |||
185 | if (ACPI_FAILURE (Status)) |
||
186 | { |
||
187 | AcpiOsPrintf ("Constant interpretation failed - %s\n", |
||
188 | AcpiFormatException (Status)); |
||
189 | } |
||
190 | |||
191 | |||
192 | } |
||
193 | |||
194 | |||
195 | |||
196 | * |
||
197 | * FUNCTION: OpcAmlEvaluationWalk2 |
||
198 | * |
||
199 | * PARAMETERS: ASL_WALK_CALLBACK |
||
200 | * |
||
201 | * RETURN: Status |
||
202 | * |
||
203 | * DESCRIPTION: Ascending callback for AML execution of constant subtrees |
||
204 | * |
||
205 | ******************************************************************************/ |
||
206 | |||
207 | |||
208 | OpcAmlEvaluationWalk2 ( |
||
209 | ACPI_PARSE_OBJECT *Op, |
||
210 | UINT32 Level, |
||
211 | void *Context) |
||
212 | { |
||
213 | ACPI_WALK_STATE *WalkState = Context; |
||
214 | ACPI_STATUS Status; |
||
215 | |||
216 | |||
217 | |||
218 | WalkState->Opcode = Op->Common.AmlOpcode; |
||
219 | WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode); |
||
220 | |||
221 | |||
222 | |||
223 | |||
224 | { |
||
225 | Op->Common.Value.Arg = Op->Asl.Child; |
||
226 | } |
||
227 | |||
228 | |||
229 | |||
230 | |||
231 | if (ACPI_FAILURE (Status)) |
||
232 | { |
||
233 | AcpiOsPrintf ("Constant interpretation failed - %s\n", |
||
234 | AcpiFormatException (Status)); |
||
235 | } |
||
236 | |||
237 | |||
238 | } |
||
239 | |||
240 | |||
241 | |||
242 | * |
||
243 | * FUNCTION: OpcAmlCheckForConstant |
||
244 | * |
||
245 | * PARAMETERS: ASL_WALK_CALLBACK |
||
246 | * |
||
247 | * RETURN: Status |
||
248 | * |
||
249 | * DESCRIPTION: Check one Op for a type 3/4/5 AML opcode |
||
250 | * |
||
251 | ******************************************************************************/ |
||
252 | |||
253 | |||
254 | OpcAmlCheckForConstant ( |
||
255 | ACPI_PARSE_OBJECT *Op, |
||
256 | UINT32 Level, |
||
257 | void *Context) |
||
258 | { |
||
259 | ACPI_WALK_STATE *WalkState = Context; |
||
260 | |||
261 | |||
262 | |||
263 | WalkState->Opcode = Op->Common.AmlOpcode; |
||
264 | WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode); |
||
265 | |||
266 | |||
267 | Op->Asl.LogicalLineNumber, Op->Asl.ParseOpName); |
||
268 | |||
269 | |||
270 | { |
||
271 | /* The opcode is not a Type 3/4/5 opcode */ |
||
272 | |||
273 | |||
274 | { |
||
275 | DbgPrint (ASL_PARSE_OUTPUT, |
||
276 | "**** Valid Target, cannot reduce ****\n"); |
||
277 | } |
||
278 | else |
||
279 | { |
||
280 | DbgPrint (ASL_PARSE_OUTPUT, |
||
281 | "**** Not a Type 3/4/5 opcode ****\n"); |
||
282 | } |
||
283 | |||
284 | |||
285 | { |
||
286 | /* |
||
287 | * We are looking at at normal expression to see if it can be |
||
288 | * reduced. It can't. No error |
||
289 | */ |
||
290 | return (AE_TYPE); |
||
291 | } |
||
292 | |||
293 | |||
294 | * This is an expression that MUST reduce to a constant, and it |
||
295 | * can't be reduced. This is an error |
||
296 | */ |
||
297 | if (Op->Asl.CompileFlags & NODE_IS_TARGET) |
||
298 | { |
||
299 | AslError (ASL_ERROR, ASL_MSG_INVALID_TARGET, Op, |
||
300 | Op->Asl.ParseOpName); |
||
301 | } |
||
302 | else |
||
303 | { |
||
304 | AslError (ASL_ERROR, ASL_MSG_INVALID_CONSTANT_OP, Op, |
||
305 | Op->Asl.ParseOpName); |
||
306 | } |
||
307 | |||
308 | |||
309 | } |
||
310 | |||
311 | |||
312 | |||
313 | |||
314 | |||
315 | |||
316 | { |
||
317 | DbgPrint (ASL_PARSE_OUTPUT, " TARGET"); |
||
318 | } |
||
319 | if (Op->Asl.CompileFlags & NODE_IS_TERM_ARG) |
||
320 | { |
||
321 | DbgPrint (ASL_PARSE_OUTPUT, " TERMARG"); |
||
322 | } |
||
323 | DbgPrint (ASL_PARSE_OUTPUT, "\n"); |
||
324 | |||
325 | |||
326 | } |
||
327 | |||
328 | |||
329 | |||
330 | * |
||
331 | * FUNCTION: OpcAmlConstantWalk |
||
332 | * |
||
333 | * PARAMETERS: ASL_WALK_CALLBACK |
||
334 | * |
||
335 | * RETURN: Status |
||
336 | * |
||
337 | * DESCRIPTION: Reduce an Op and its subtree to a constant if possible |
||
338 | * |
||
339 | ******************************************************************************/ |
||
340 | |||
341 | |||
342 | OpcAmlConstantWalk ( |
||
343 | ACPI_PARSE_OBJECT *Op, |
||
344 | UINT32 Level, |
||
345 | void *Context) |
||
346 | { |
||
347 | ACPI_WALK_STATE *WalkState; |
||
348 | ACPI_STATUS Status = AE_OK; |
||
349 | ACPI_OPERAND_OBJECT *ObjDesc; |
||
350 | ACPI_PARSE_OBJECT *RootOp; |
||
351 | ACPI_PARSE_OBJECT *OriginalParentOp; |
||
352 | UINT8 WalkType; |
||
353 | |||
354 | |||
355 | |||
356 | * Only interested in subtrees that could possibly contain |
||
357 | * expressions that can be evaluated at this time |
||
358 | */ |
||
359 | if ((!(Op->Asl.CompileFlags & NODE_COMPILE_TIME_CONST)) || |
||
360 | (Op->Asl.CompileFlags & NODE_IS_TARGET)) |
||
361 | { |
||
362 | return (AE_OK); |
||
363 | } |
||
364 | |||
365 | |||
366 | |||
367 | |||
368 | { |
||
369 | /* Op is a TermArg, constant folding is merely optional */ |
||
370 | |||
371 | |||
372 | { |
||
373 | return (AE_CTRL_DEPTH); |
||
374 | } |
||
375 | |||
376 | |||
377 | } |
||
378 | else |
||
379 | { |
||
380 | /* Op is a DataObject, the expression MUST reduced to a constant */ |
||
381 | |||
382 | |||
383 | } |
||
384 | |||
385 | |||
386 | |||
387 | |||
388 | if (!WalkState) |
||
389 | { |
||
390 | return AE_NO_MEMORY; |
||
391 | } |
||
392 | |||
393 | |||
394 | WalkState->Params = NULL; |
||
395 | WalkState->CallerReturnDesc = &ObjDesc; |
||
396 | WalkState->WalkType = WalkType; |
||
397 | |||
398 | |||
399 | * Examine the entire subtree -- all nodes must be constants |
||
400 | * or type 3/4/5 opcodes |
||
401 | */ |
||
402 | Status = TrWalkParseTree (Op, ASL_WALK_VISIT_DOWNWARD, |
||
403 | OpcAmlCheckForConstant, NULL, WalkState); |
||
404 | |||
405 | |||
406 | * Did we find an entire subtree that contains all constants and type 3/4/5 |
||
407 | * opcodes? (Only AE_OK or AE_TYPE returned from above) |
||
408 | */ |
||
409 | if (Status == AE_TYPE) |
||
410 | { |
||
411 | /* Subtree cannot be reduced to a constant */ |
||
412 | |||
413 | |||
414 | { |
||
415 | AcpiDsDeleteWalkState (WalkState); |
||
416 | return (AE_OK); |
||
417 | } |
||
418 | |||
419 | |||
420 | |||
421 | |||
422 | } |
||
423 | else |
||
424 | { |
||
425 | /* Subtree can be reduced */ |
||
426 | |||
427 | |||
428 | |||
429 | |||
430 | if (!RootOp) |
||
431 | { |
||
432 | return (AE_NO_MEMORY); |
||
433 | } |
||
434 | |||
435 | |||
436 | |||
437 | |||
438 | Op->Common.Parent = RootOp; |
||
439 | |||
440 | |||
441 | |||
442 | |||
443 | OpcAmlEvaluationWalk1, OpcAmlEvaluationWalk2, WalkState); |
||
444 | Op->Common.Parent = OriginalParentOp; |
||
445 | |||
446 | |||
447 | |||
448 | |||
449 | { |
||
450 | TotalFolds++; |
||
451 | |||
452 | |||
453 | |||
454 | |||
455 | } |
||
456 | } |
||
457 | |||
458 | |||
459 | { |
||
460 | /* We could not resolve the subtree for some reason */ |
||
461 | |||
462 | |||
463 | "Failure during constant evaluation", FALSE); |
||
464 | AslError (ASL_ERROR, ASL_MSG_CONSTANT_EVALUATION, Op, |
||
465 | Op->Asl.ParseOpName); |
||
466 | |||
467 | |||
468 | |||
469 | |||
470 | Op->Common.Value.Integer = 0; |
||
471 | OpcSetOptimalIntegerSize (Op); |
||
472 | } |
||
473 | else |
||
474 | { |
||
475 | AslError (ASL_OPTIMIZATION, ASL_MSG_CONSTANT_FOLDED, Op, |
||
476 | Op->Asl.ParseOpName); |
||
477 | |||
478 | |||
479 | * Because we know we executed type 3/4/5 opcodes above, we know that |
||
480 | * the result must be either an Integer, String, or Buffer. |
||
481 | */ |
||
482 | switch (ObjDesc->Common.Type) |
||
483 | { |
||
484 | case ACPI_TYPE_INTEGER: |
||
485 | |||
486 | |||
487 | Op->Common.Value.Integer = ObjDesc->Integer.Value; |
||
488 | OpcSetOptimalIntegerSize (Op); |
||
489 | |||
490 | |||
491 | "Constant expression reduced to (INTEGER) %8.8X%8.8X\n", |
||
492 | ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value)); |
||
493 | break; |
||
494 | |||
495 | |||
496 | |||
497 | |||
498 | |||
499 | Op->Common.AmlOpcode = AML_STRING_OP; |
||
500 | Op->Asl.AmlLength = ACPI_STRLEN (ObjDesc->String.Pointer) + 1; |
||
501 | Op->Common.Value.String = ObjDesc->String.Pointer; |
||
502 | |||
503 | |||
504 | "Constant expression reduced to (STRING) %s\n", |
||
505 | Op->Common.Value.String); |
||
506 | |||
507 | |||
508 | |||
509 | |||
510 | |||
511 | |||
512 | |||
513 | Op->Common.AmlOpcode = AML_BUFFER_OP; |
||
514 | Op->Asl.CompileFlags = NODE_AML_PACKAGE; |
||
515 | UtSetParseOpName (Op); |
||
516 | |||
517 | |||
518 | |||
519 | |||
520 | |||
521 | |||
522 | RootOp->Asl.Value.Integer = ObjDesc->Buffer.Length; |
||
523 | RootOp->Asl.Parent = Op; |
||
524 | |||
525 | |||
526 | |||
527 | |||
528 | Op = RootOp; |
||
529 | UtSetParseOpName (Op); |
||
530 | |||
531 | |||
532 | |||
533 | |||
534 | RootOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER; |
||
535 | RootOp->Asl.AmlLength = ObjDesc->Buffer.Length; |
||
536 | RootOp->Asl.Value.String = (char *) ObjDesc->Buffer.Pointer; |
||
537 | RootOp->Asl.Parent = Op->Asl.Parent; |
||
538 | |||
539 | |||
540 | Op = RootOp; |
||
541 | |||
542 | |||
543 | "Constant expression reduced to (BUFFER) length %X\n", |
||
544 | ObjDesc->Buffer.Length); |
||
545 | break; |
||
546 | |||
547 | |||
548 | |||
549 | printf ("Unsupported return type: %s\n", |
||
550 | AcpiUtGetObjectTypeName (ObjDesc)); |
||
551 | break; |
||
552 | } |
||
553 | } |
||
554 | |||
555 | |||
556 | Op->Asl.Child = NULL; |
||
557 | |||
558 | |||
559 | |||
560 | |||
561 | } |
||
562 |