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