aslfold.c revision 1.1.1.2.2.2 1 1.1.1.2.2.2 bouyer
2 1.1.1.2.2.2 bouyer /******************************************************************************
3 1.1.1.2.2.2 bouyer *
4 1.1.1.2.2.2 bouyer * Module Name: aslfold - Constant folding
5 1.1.1.2.2.2 bouyer *
6 1.1.1.2.2.2 bouyer *****************************************************************************/
7 1.1.1.2.2.2 bouyer
8 1.1.1.2.2.2 bouyer /*
9 1.1.1.2.2.2 bouyer * Copyright (C) 2000 - 2011, Intel Corp.
10 1.1.1.2.2.2 bouyer * All rights reserved.
11 1.1.1.2.2.2 bouyer *
12 1.1.1.2.2.2 bouyer * Redistribution and use in source and binary forms, with or without
13 1.1.1.2.2.2 bouyer * modification, are permitted provided that the following conditions
14 1.1.1.2.2.2 bouyer * are met:
15 1.1.1.2.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
16 1.1.1.2.2.2 bouyer * notice, this list of conditions, and the following disclaimer,
17 1.1.1.2.2.2 bouyer * without modification.
18 1.1.1.2.2.2 bouyer * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 1.1.1.2.2.2 bouyer * substantially similar to the "NO WARRANTY" disclaimer below
20 1.1.1.2.2.2 bouyer * ("Disclaimer") and any redistribution must be conditioned upon
21 1.1.1.2.2.2 bouyer * including a substantially similar Disclaimer requirement for further
22 1.1.1.2.2.2 bouyer * binary redistribution.
23 1.1.1.2.2.2 bouyer * 3. Neither the names of the above-listed copyright holders nor the names
24 1.1.1.2.2.2 bouyer * of any contributors may be used to endorse or promote products derived
25 1.1.1.2.2.2 bouyer * from this software without specific prior written permission.
26 1.1.1.2.2.2 bouyer *
27 1.1.1.2.2.2 bouyer * Alternatively, this software may be distributed under the terms of the
28 1.1.1.2.2.2 bouyer * GNU General Public License ("GPL") version 2 as published by the Free
29 1.1.1.2.2.2 bouyer * Software Foundation.
30 1.1.1.2.2.2 bouyer *
31 1.1.1.2.2.2 bouyer * NO WARRANTY
32 1.1.1.2.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 1.1.1.2.2.2 bouyer * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 1.1.1.2.2.2 bouyer * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 1.1.1.2.2.2 bouyer * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 1.1.1.2.2.2 bouyer * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1.1.2.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1.1.2.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1.1.2.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 1.1.1.2.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 1.1.1.2.2.2 bouyer * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 1.1.1.2.2.2 bouyer * POSSIBILITY OF SUCH DAMAGES.
43 1.1.1.2.2.2 bouyer */
44 1.1.1.2.2.2 bouyer
45 1.1.1.2.2.2 bouyer
46 1.1.1.2.2.2 bouyer #include "aslcompiler.h"
47 1.1.1.2.2.2 bouyer #include "aslcompiler.y.h"
48 1.1.1.2.2.2 bouyer #include "amlcode.h"
49 1.1.1.2.2.2 bouyer
50 1.1.1.2.2.2 bouyer #include "acdispat.h"
51 1.1.1.2.2.2 bouyer #include "acparser.h"
52 1.1.1.2.2.2 bouyer
53 1.1.1.2.2.2 bouyer #define _COMPONENT ACPI_COMPILER
54 1.1.1.2.2.2 bouyer ACPI_MODULE_NAME ("aslfold")
55 1.1.1.2.2.2 bouyer
56 1.1.1.2.2.2 bouyer /* Local prototypes */
57 1.1.1.2.2.2 bouyer
58 1.1.1.2.2.2 bouyer static ACPI_STATUS
59 1.1.1.2.2.2 bouyer OpcAmlEvaluationWalk1 (
60 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op,
61 1.1.1.2.2.2 bouyer UINT32 Level,
62 1.1.1.2.2.2 bouyer void *Context);
63 1.1.1.2.2.2 bouyer
64 1.1.1.2.2.2 bouyer static ACPI_STATUS
65 1.1.1.2.2.2 bouyer OpcAmlEvaluationWalk2 (
66 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op,
67 1.1.1.2.2.2 bouyer UINT32 Level,
68 1.1.1.2.2.2 bouyer void *Context);
69 1.1.1.2.2.2 bouyer
70 1.1.1.2.2.2 bouyer static ACPI_STATUS
71 1.1.1.2.2.2 bouyer OpcAmlCheckForConstant (
72 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op,
73 1.1.1.2.2.2 bouyer UINT32 Level,
74 1.1.1.2.2.2 bouyer void *Context);
75 1.1.1.2.2.2 bouyer
76 1.1.1.2.2.2 bouyer
77 1.1.1.2.2.2 bouyer /*******************************************************************************
78 1.1.1.2.2.2 bouyer *
79 1.1.1.2.2.2 bouyer * FUNCTION: OpcAmlEvaluationWalk1
80 1.1.1.2.2.2 bouyer *
81 1.1.1.2.2.2 bouyer * PARAMETERS: ASL_WALK_CALLBACK
82 1.1.1.2.2.2 bouyer *
83 1.1.1.2.2.2 bouyer * RETURN: Status
84 1.1.1.2.2.2 bouyer *
85 1.1.1.2.2.2 bouyer * DESCRIPTION: Descending callback for AML execution of constant subtrees
86 1.1.1.2.2.2 bouyer *
87 1.1.1.2.2.2 bouyer ******************************************************************************/
88 1.1.1.2.2.2 bouyer
89 1.1.1.2.2.2 bouyer static ACPI_STATUS
90 1.1.1.2.2.2 bouyer OpcAmlEvaluationWalk1 (
91 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op,
92 1.1.1.2.2.2 bouyer UINT32 Level,
93 1.1.1.2.2.2 bouyer void *Context)
94 1.1.1.2.2.2 bouyer {
95 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState = Context;
96 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
97 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *OutOp;
98 1.1.1.2.2.2 bouyer
99 1.1.1.2.2.2 bouyer
100 1.1.1.2.2.2 bouyer WalkState->Op = Op;
101 1.1.1.2.2.2 bouyer WalkState->Opcode = Op->Common.AmlOpcode;
102 1.1.1.2.2.2 bouyer WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
103 1.1.1.2.2.2 bouyer
104 1.1.1.2.2.2 bouyer /* Copy child pointer to Arg for compatibility with Interpreter */
105 1.1.1.2.2.2 bouyer
106 1.1.1.2.2.2 bouyer if (Op->Asl.Child)
107 1.1.1.2.2.2 bouyer {
108 1.1.1.2.2.2 bouyer Op->Common.Value.Arg = Op->Asl.Child;
109 1.1.1.2.2.2 bouyer }
110 1.1.1.2.2.2 bouyer
111 1.1.1.2.2.2 bouyer /* Call AML dispatcher */
112 1.1.1.2.2.2 bouyer
113 1.1.1.2.2.2 bouyer Status = AcpiDsExecBeginOp (WalkState, &OutOp);
114 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
115 1.1.1.2.2.2 bouyer {
116 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Constant interpretation failed - %s\n",
117 1.1.1.2.2.2 bouyer AcpiFormatException (Status));
118 1.1.1.2.2.2 bouyer }
119 1.1.1.2.2.2 bouyer
120 1.1.1.2.2.2 bouyer return (Status);
121 1.1.1.2.2.2 bouyer }
122 1.1.1.2.2.2 bouyer
123 1.1.1.2.2.2 bouyer
124 1.1.1.2.2.2 bouyer /*******************************************************************************
125 1.1.1.2.2.2 bouyer *
126 1.1.1.2.2.2 bouyer * FUNCTION: OpcAmlEvaluationWalk2
127 1.1.1.2.2.2 bouyer *
128 1.1.1.2.2.2 bouyer * PARAMETERS: ASL_WALK_CALLBACK
129 1.1.1.2.2.2 bouyer *
130 1.1.1.2.2.2 bouyer * RETURN: Status
131 1.1.1.2.2.2 bouyer *
132 1.1.1.2.2.2 bouyer * DESCRIPTION: Ascending callback for AML execution of constant subtrees
133 1.1.1.2.2.2 bouyer *
134 1.1.1.2.2.2 bouyer ******************************************************************************/
135 1.1.1.2.2.2 bouyer
136 1.1.1.2.2.2 bouyer static ACPI_STATUS
137 1.1.1.2.2.2 bouyer OpcAmlEvaluationWalk2 (
138 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op,
139 1.1.1.2.2.2 bouyer UINT32 Level,
140 1.1.1.2.2.2 bouyer void *Context)
141 1.1.1.2.2.2 bouyer {
142 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState = Context;
143 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
144 1.1.1.2.2.2 bouyer
145 1.1.1.2.2.2 bouyer
146 1.1.1.2.2.2 bouyer WalkState->Op = Op;
147 1.1.1.2.2.2 bouyer WalkState->Opcode = Op->Common.AmlOpcode;
148 1.1.1.2.2.2 bouyer WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
149 1.1.1.2.2.2 bouyer
150 1.1.1.2.2.2 bouyer /* Copy child pointer to Arg for compatibility with Interpreter */
151 1.1.1.2.2.2 bouyer
152 1.1.1.2.2.2 bouyer if (Op->Asl.Child)
153 1.1.1.2.2.2 bouyer {
154 1.1.1.2.2.2 bouyer Op->Common.Value.Arg = Op->Asl.Child;
155 1.1.1.2.2.2 bouyer }
156 1.1.1.2.2.2 bouyer
157 1.1.1.2.2.2 bouyer /* Call AML dispatcher */
158 1.1.1.2.2.2 bouyer
159 1.1.1.2.2.2 bouyer Status = AcpiDsExecEndOp (WalkState);
160 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
161 1.1.1.2.2.2 bouyer {
162 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Constant interpretation failed - %s\n",
163 1.1.1.2.2.2 bouyer AcpiFormatException (Status));
164 1.1.1.2.2.2 bouyer }
165 1.1.1.2.2.2 bouyer
166 1.1.1.2.2.2 bouyer return (Status);
167 1.1.1.2.2.2 bouyer }
168 1.1.1.2.2.2 bouyer
169 1.1.1.2.2.2 bouyer
170 1.1.1.2.2.2 bouyer /*******************************************************************************
171 1.1.1.2.2.2 bouyer *
172 1.1.1.2.2.2 bouyer * FUNCTION: OpcAmlCheckForConstant
173 1.1.1.2.2.2 bouyer *
174 1.1.1.2.2.2 bouyer * PARAMETERS: ASL_WALK_CALLBACK
175 1.1.1.2.2.2 bouyer *
176 1.1.1.2.2.2 bouyer * RETURN: Status
177 1.1.1.2.2.2 bouyer *
178 1.1.1.2.2.2 bouyer * DESCRIPTION: Check one Op for a type 3/4/5 AML opcode
179 1.1.1.2.2.2 bouyer *
180 1.1.1.2.2.2 bouyer ******************************************************************************/
181 1.1.1.2.2.2 bouyer
182 1.1.1.2.2.2 bouyer static ACPI_STATUS
183 1.1.1.2.2.2 bouyer OpcAmlCheckForConstant (
184 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op,
185 1.1.1.2.2.2 bouyer UINT32 Level,
186 1.1.1.2.2.2 bouyer void *Context)
187 1.1.1.2.2.2 bouyer {
188 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState = Context;
189 1.1.1.2.2.2 bouyer
190 1.1.1.2.2.2 bouyer
191 1.1.1.2.2.2 bouyer WalkState->Op = Op;
192 1.1.1.2.2.2 bouyer WalkState->Opcode = Op->Common.AmlOpcode;
193 1.1.1.2.2.2 bouyer WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
194 1.1.1.2.2.2 bouyer
195 1.1.1.2.2.2 bouyer DbgPrint (ASL_PARSE_OUTPUT, "[%.4d] Opcode: %12.12s ",
196 1.1.1.2.2.2 bouyer Op->Asl.LogicalLineNumber, Op->Asl.ParseOpName);
197 1.1.1.2.2.2 bouyer
198 1.1.1.2.2.2 bouyer if (!(WalkState->OpInfo->Flags & AML_CONSTANT))
199 1.1.1.2.2.2 bouyer {
200 1.1.1.2.2.2 bouyer /* The opcode is not a Type 3/4/5 opcode */
201 1.1.1.2.2.2 bouyer
202 1.1.1.2.2.2 bouyer if (Op->Asl.CompileFlags & NODE_IS_TARGET)
203 1.1.1.2.2.2 bouyer {
204 1.1.1.2.2.2 bouyer DbgPrint (ASL_PARSE_OUTPUT,
205 1.1.1.2.2.2 bouyer "**** Valid Target, cannot reduce ****\n");
206 1.1.1.2.2.2 bouyer }
207 1.1.1.2.2.2 bouyer else
208 1.1.1.2.2.2 bouyer {
209 1.1.1.2.2.2 bouyer DbgPrint (ASL_PARSE_OUTPUT,
210 1.1.1.2.2.2 bouyer "**** Not a Type 3/4/5 opcode ****\n");
211 1.1.1.2.2.2 bouyer }
212 1.1.1.2.2.2 bouyer
213 1.1.1.2.2.2 bouyer if (WalkState->WalkType == ACPI_WALK_CONST_OPTIONAL)
214 1.1.1.2.2.2 bouyer {
215 1.1.1.2.2.2 bouyer /*
216 1.1.1.2.2.2 bouyer * We are looking at at normal expression to see if it can be
217 1.1.1.2.2.2 bouyer * reduced. It can't. No error
218 1.1.1.2.2.2 bouyer */
219 1.1.1.2.2.2 bouyer return (AE_TYPE);
220 1.1.1.2.2.2 bouyer }
221 1.1.1.2.2.2 bouyer
222 1.1.1.2.2.2 bouyer /*
223 1.1.1.2.2.2 bouyer * This is an expression that MUST reduce to a constant, and it
224 1.1.1.2.2.2 bouyer * can't be reduced. This is an error
225 1.1.1.2.2.2 bouyer */
226 1.1.1.2.2.2 bouyer if (Op->Asl.CompileFlags & NODE_IS_TARGET)
227 1.1.1.2.2.2 bouyer {
228 1.1.1.2.2.2 bouyer AslError (ASL_ERROR, ASL_MSG_INVALID_TARGET, Op,
229 1.1.1.2.2.2 bouyer Op->Asl.ParseOpName);
230 1.1.1.2.2.2 bouyer }
231 1.1.1.2.2.2 bouyer else
232 1.1.1.2.2.2 bouyer {
233 1.1.1.2.2.2 bouyer AslError (ASL_ERROR, ASL_MSG_INVALID_CONSTANT_OP, Op,
234 1.1.1.2.2.2 bouyer Op->Asl.ParseOpName);
235 1.1.1.2.2.2 bouyer }
236 1.1.1.2.2.2 bouyer
237 1.1.1.2.2.2 bouyer return (AE_TYPE);
238 1.1.1.2.2.2 bouyer }
239 1.1.1.2.2.2 bouyer
240 1.1.1.2.2.2 bouyer /* Debug output */
241 1.1.1.2.2.2 bouyer
242 1.1.1.2.2.2 bouyer DbgPrint (ASL_PARSE_OUTPUT, "TYPE_345");
243 1.1.1.2.2.2 bouyer
244 1.1.1.2.2.2 bouyer if (Op->Asl.CompileFlags & NODE_IS_TARGET)
245 1.1.1.2.2.2 bouyer {
246 1.1.1.2.2.2 bouyer DbgPrint (ASL_PARSE_OUTPUT, " TARGET");
247 1.1.1.2.2.2 bouyer }
248 1.1.1.2.2.2 bouyer if (Op->Asl.CompileFlags & NODE_IS_TERM_ARG)
249 1.1.1.2.2.2 bouyer {
250 1.1.1.2.2.2 bouyer DbgPrint (ASL_PARSE_OUTPUT, " TERMARG");
251 1.1.1.2.2.2 bouyer }
252 1.1.1.2.2.2 bouyer DbgPrint (ASL_PARSE_OUTPUT, "\n");
253 1.1.1.2.2.2 bouyer
254 1.1.1.2.2.2 bouyer return (AE_OK);
255 1.1.1.2.2.2 bouyer }
256 1.1.1.2.2.2 bouyer
257 1.1.1.2.2.2 bouyer
258 1.1.1.2.2.2 bouyer /*******************************************************************************
259 1.1.1.2.2.2 bouyer *
260 1.1.1.2.2.2 bouyer * FUNCTION: OpcAmlConstantWalk
261 1.1.1.2.2.2 bouyer *
262 1.1.1.2.2.2 bouyer * PARAMETERS: ASL_WALK_CALLBACK
263 1.1.1.2.2.2 bouyer *
264 1.1.1.2.2.2 bouyer * RETURN: Status
265 1.1.1.2.2.2 bouyer *
266 1.1.1.2.2.2 bouyer * DESCRIPTION: Reduce an Op and its subtree to a constant if possible
267 1.1.1.2.2.2 bouyer *
268 1.1.1.2.2.2 bouyer ******************************************************************************/
269 1.1.1.2.2.2 bouyer
270 1.1.1.2.2.2 bouyer ACPI_STATUS
271 1.1.1.2.2.2 bouyer OpcAmlConstantWalk (
272 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op,
273 1.1.1.2.2.2 bouyer UINT32 Level,
274 1.1.1.2.2.2 bouyer void *Context)
275 1.1.1.2.2.2 bouyer {
276 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState;
277 1.1.1.2.2.2 bouyer ACPI_STATUS Status = AE_OK;
278 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *ObjDesc;
279 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *RootOp;
280 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *OriginalParentOp;
281 1.1.1.2.2.2 bouyer UINT8 WalkType;
282 1.1.1.2.2.2 bouyer
283 1.1.1.2.2.2 bouyer
284 1.1.1.2.2.2 bouyer /*
285 1.1.1.2.2.2 bouyer * Only interested in subtrees that could possibly contain
286 1.1.1.2.2.2 bouyer * expressions that can be evaluated at this time
287 1.1.1.2.2.2 bouyer */
288 1.1.1.2.2.2 bouyer if ((!(Op->Asl.CompileFlags & NODE_COMPILE_TIME_CONST)) ||
289 1.1.1.2.2.2 bouyer (Op->Asl.CompileFlags & NODE_IS_TARGET))
290 1.1.1.2.2.2 bouyer {
291 1.1.1.2.2.2 bouyer return (AE_OK);
292 1.1.1.2.2.2 bouyer }
293 1.1.1.2.2.2 bouyer
294 1.1.1.2.2.2 bouyer /* Set the walk type based on the reduction used for this op */
295 1.1.1.2.2.2 bouyer
296 1.1.1.2.2.2 bouyer if (Op->Asl.CompileFlags & NODE_IS_TERM_ARG)
297 1.1.1.2.2.2 bouyer {
298 1.1.1.2.2.2 bouyer /* Op is a TermArg, constant folding is merely optional */
299 1.1.1.2.2.2 bouyer
300 1.1.1.2.2.2 bouyer if (!Gbl_FoldConstants)
301 1.1.1.2.2.2 bouyer {
302 1.1.1.2.2.2 bouyer return (AE_CTRL_DEPTH);
303 1.1.1.2.2.2 bouyer }
304 1.1.1.2.2.2 bouyer
305 1.1.1.2.2.2 bouyer WalkType = ACPI_WALK_CONST_OPTIONAL;
306 1.1.1.2.2.2 bouyer }
307 1.1.1.2.2.2 bouyer else
308 1.1.1.2.2.2 bouyer {
309 1.1.1.2.2.2 bouyer /* Op is a DataObject, the expression MUST reduced to a constant */
310 1.1.1.2.2.2 bouyer
311 1.1.1.2.2.2 bouyer WalkType = ACPI_WALK_CONST_REQUIRED;
312 1.1.1.2.2.2 bouyer }
313 1.1.1.2.2.2 bouyer
314 1.1.1.2.2.2 bouyer /* Create a new walk state */
315 1.1.1.2.2.2 bouyer
316 1.1.1.2.2.2 bouyer WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
317 1.1.1.2.2.2 bouyer if (!WalkState)
318 1.1.1.2.2.2 bouyer {
319 1.1.1.2.2.2 bouyer return AE_NO_MEMORY;
320 1.1.1.2.2.2 bouyer }
321 1.1.1.2.2.2 bouyer
322 1.1.1.2.2.2 bouyer WalkState->NextOp = NULL;
323 1.1.1.2.2.2 bouyer WalkState->Params = NULL;
324 1.1.1.2.2.2 bouyer WalkState->CallerReturnDesc = &ObjDesc;
325 1.1.1.2.2.2 bouyer WalkState->WalkType = WalkType;
326 1.1.1.2.2.2 bouyer
327 1.1.1.2.2.2 bouyer /*
328 1.1.1.2.2.2 bouyer * Examine the entire subtree -- all nodes must be constants
329 1.1.1.2.2.2 bouyer * or type 3/4/5 opcodes
330 1.1.1.2.2.2 bouyer */
331 1.1.1.2.2.2 bouyer Status = TrWalkParseTree (Op, ASL_WALK_VISIT_DOWNWARD,
332 1.1.1.2.2.2 bouyer OpcAmlCheckForConstant, NULL, WalkState);
333 1.1.1.2.2.2 bouyer
334 1.1.1.2.2.2 bouyer /*
335 1.1.1.2.2.2 bouyer * Did we find an entire subtree that contains all constants and type 3/4/5
336 1.1.1.2.2.2 bouyer * opcodes? (Only AE_OK or AE_TYPE returned from above)
337 1.1.1.2.2.2 bouyer */
338 1.1.1.2.2.2 bouyer if (Status == AE_TYPE)
339 1.1.1.2.2.2 bouyer {
340 1.1.1.2.2.2 bouyer /* Subtree cannot be reduced to a constant */
341 1.1.1.2.2.2 bouyer
342 1.1.1.2.2.2 bouyer if (WalkState->WalkType == ACPI_WALK_CONST_OPTIONAL)
343 1.1.1.2.2.2 bouyer {
344 1.1.1.2.2.2 bouyer AcpiDsDeleteWalkState (WalkState);
345 1.1.1.2.2.2 bouyer return (AE_OK);
346 1.1.1.2.2.2 bouyer }
347 1.1.1.2.2.2 bouyer
348 1.1.1.2.2.2 bouyer /* Don't descend any further, and use a default "constant" value */
349 1.1.1.2.2.2 bouyer
350 1.1.1.2.2.2 bouyer Status = AE_CTRL_DEPTH;
351 1.1.1.2.2.2 bouyer }
352 1.1.1.2.2.2 bouyer else
353 1.1.1.2.2.2 bouyer {
354 1.1.1.2.2.2 bouyer /* Subtree can be reduced */
355 1.1.1.2.2.2 bouyer
356 1.1.1.2.2.2 bouyer /* Allocate a new temporary root for this subtree */
357 1.1.1.2.2.2 bouyer
358 1.1.1.2.2.2 bouyer RootOp = TrAllocateNode (PARSEOP_INTEGER);
359 1.1.1.2.2.2 bouyer if (!RootOp)
360 1.1.1.2.2.2 bouyer {
361 1.1.1.2.2.2 bouyer return (AE_NO_MEMORY);
362 1.1.1.2.2.2 bouyer }
363 1.1.1.2.2.2 bouyer
364 1.1.1.2.2.2 bouyer RootOp->Common.AmlOpcode = AML_INT_EVAL_SUBTREE_OP;
365 1.1.1.2.2.2 bouyer
366 1.1.1.2.2.2 bouyer OriginalParentOp = Op->Common.Parent;
367 1.1.1.2.2.2 bouyer Op->Common.Parent = RootOp;
368 1.1.1.2.2.2 bouyer
369 1.1.1.2.2.2 bouyer /* Hand off the subtree to the AML interpreter */
370 1.1.1.2.2.2 bouyer
371 1.1.1.2.2.2 bouyer Status = TrWalkParseTree (Op, ASL_WALK_VISIT_TWICE,
372 1.1.1.2.2.2 bouyer OpcAmlEvaluationWalk1, OpcAmlEvaluationWalk2, WalkState);
373 1.1.1.2.2.2 bouyer Op->Common.Parent = OriginalParentOp;
374 1.1.1.2.2.2 bouyer
375 1.1.1.2.2.2 bouyer /* TBD: we really *should* release the RootOp node */
376 1.1.1.2.2.2 bouyer
377 1.1.1.2.2.2 bouyer if (ACPI_SUCCESS (Status))
378 1.1.1.2.2.2 bouyer {
379 1.1.1.2.2.2 bouyer TotalFolds++;
380 1.1.1.2.2.2 bouyer
381 1.1.1.2.2.2 bouyer /* Get the final result */
382 1.1.1.2.2.2 bouyer
383 1.1.1.2.2.2 bouyer Status = AcpiDsResultPop (&ObjDesc, WalkState);
384 1.1.1.2.2.2 bouyer }
385 1.1.1.2.2.2 bouyer }
386 1.1.1.2.2.2 bouyer
387 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
388 1.1.1.2.2.2 bouyer {
389 1.1.1.2.2.2 bouyer /* We could not resolve the subtree for some reason */
390 1.1.1.2.2.2 bouyer
391 1.1.1.2.2.2 bouyer AslCoreSubsystemError (Op, Status,
392 1.1.1.2.2.2 bouyer "Failure during constant evaluation", FALSE);
393 1.1.1.2.2.2 bouyer AslError (ASL_ERROR, ASL_MSG_CONSTANT_EVALUATION, Op,
394 1.1.1.2.2.2 bouyer Op->Asl.ParseOpName);
395 1.1.1.2.2.2 bouyer
396 1.1.1.2.2.2 bouyer /* Set the subtree value to ZERO anyway. Eliminates further errors */
397 1.1.1.2.2.2 bouyer
398 1.1.1.2.2.2 bouyer Op->Asl.ParseOpcode = PARSEOP_INTEGER;
399 1.1.1.2.2.2 bouyer Op->Common.Value.Integer = 0;
400 1.1.1.2.2.2 bouyer OpcSetOptimalIntegerSize (Op);
401 1.1.1.2.2.2 bouyer }
402 1.1.1.2.2.2 bouyer else
403 1.1.1.2.2.2 bouyer {
404 1.1.1.2.2.2 bouyer AslError (ASL_OPTIMIZATION, ASL_MSG_CONSTANT_FOLDED, Op,
405 1.1.1.2.2.2 bouyer Op->Asl.ParseOpName);
406 1.1.1.2.2.2 bouyer
407 1.1.1.2.2.2 bouyer /*
408 1.1.1.2.2.2 bouyer * Because we know we executed type 3/4/5 opcodes above, we know that
409 1.1.1.2.2.2 bouyer * the result must be either an Integer, String, or Buffer.
410 1.1.1.2.2.2 bouyer */
411 1.1.1.2.2.2 bouyer switch (ObjDesc->Common.Type)
412 1.1.1.2.2.2 bouyer {
413 1.1.1.2.2.2 bouyer case ACPI_TYPE_INTEGER:
414 1.1.1.2.2.2 bouyer
415 1.1.1.2.2.2 bouyer Op->Asl.ParseOpcode = PARSEOP_INTEGER;
416 1.1.1.2.2.2 bouyer Op->Common.Value.Integer = ObjDesc->Integer.Value;
417 1.1.1.2.2.2 bouyer OpcSetOptimalIntegerSize (Op);
418 1.1.1.2.2.2 bouyer
419 1.1.1.2.2.2 bouyer DbgPrint (ASL_PARSE_OUTPUT,
420 1.1.1.2.2.2 bouyer "Constant expression reduced to (INTEGER) %8.8X%8.8X\n",
421 1.1.1.2.2.2 bouyer ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
422 1.1.1.2.2.2 bouyer break;
423 1.1.1.2.2.2 bouyer
424 1.1.1.2.2.2 bouyer
425 1.1.1.2.2.2 bouyer case ACPI_TYPE_STRING:
426 1.1.1.2.2.2 bouyer
427 1.1.1.2.2.2 bouyer Op->Asl.ParseOpcode = PARSEOP_STRING_LITERAL;
428 1.1.1.2.2.2 bouyer Op->Common.AmlOpcode = AML_STRING_OP;
429 1.1.1.2.2.2 bouyer Op->Asl.AmlLength = ACPI_STRLEN (ObjDesc->String.Pointer) + 1;
430 1.1.1.2.2.2 bouyer Op->Common.Value.String = ObjDesc->String.Pointer;
431 1.1.1.2.2.2 bouyer
432 1.1.1.2.2.2 bouyer DbgPrint (ASL_PARSE_OUTPUT,
433 1.1.1.2.2.2 bouyer "Constant expression reduced to (STRING) %s\n",
434 1.1.1.2.2.2 bouyer Op->Common.Value.String);
435 1.1.1.2.2.2 bouyer
436 1.1.1.2.2.2 bouyer break;
437 1.1.1.2.2.2 bouyer
438 1.1.1.2.2.2 bouyer
439 1.1.1.2.2.2 bouyer case ACPI_TYPE_BUFFER:
440 1.1.1.2.2.2 bouyer
441 1.1.1.2.2.2 bouyer Op->Asl.ParseOpcode = PARSEOP_BUFFER;
442 1.1.1.2.2.2 bouyer Op->Common.AmlOpcode = AML_BUFFER_OP;
443 1.1.1.2.2.2 bouyer Op->Asl.CompileFlags = NODE_AML_PACKAGE;
444 1.1.1.2.2.2 bouyer UtSetParseOpName (Op);
445 1.1.1.2.2.2 bouyer
446 1.1.1.2.2.2 bouyer /* Child node is the buffer length */
447 1.1.1.2.2.2 bouyer
448 1.1.1.2.2.2 bouyer RootOp = TrAllocateNode (PARSEOP_INTEGER);
449 1.1.1.2.2.2 bouyer
450 1.1.1.2.2.2 bouyer RootOp->Asl.AmlOpcode = AML_DWORD_OP;
451 1.1.1.2.2.2 bouyer RootOp->Asl.Value.Integer = ObjDesc->Buffer.Length;
452 1.1.1.2.2.2 bouyer RootOp->Asl.Parent = Op;
453 1.1.1.2.2.2 bouyer
454 1.1.1.2.2.2 bouyer (void) OpcSetOptimalIntegerSize (RootOp);
455 1.1.1.2.2.2 bouyer
456 1.1.1.2.2.2 bouyer Op->Asl.Child = RootOp;
457 1.1.1.2.2.2 bouyer Op = RootOp;
458 1.1.1.2.2.2 bouyer UtSetParseOpName (Op);
459 1.1.1.2.2.2 bouyer
460 1.1.1.2.2.2 bouyer /* Peer to the child is the raw buffer data */
461 1.1.1.2.2.2 bouyer
462 1.1.1.2.2.2 bouyer RootOp = TrAllocateNode (PARSEOP_RAW_DATA);
463 1.1.1.2.2.2 bouyer RootOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER;
464 1.1.1.2.2.2 bouyer RootOp->Asl.AmlLength = ObjDesc->Buffer.Length;
465 1.1.1.2.2.2 bouyer RootOp->Asl.Value.String = (char *) ObjDesc->Buffer.Pointer;
466 1.1.1.2.2.2 bouyer RootOp->Asl.Parent = Op->Asl.Parent;
467 1.1.1.2.2.2 bouyer
468 1.1.1.2.2.2 bouyer Op->Asl.Next = RootOp;
469 1.1.1.2.2.2 bouyer Op = RootOp;
470 1.1.1.2.2.2 bouyer
471 1.1.1.2.2.2 bouyer DbgPrint (ASL_PARSE_OUTPUT,
472 1.1.1.2.2.2 bouyer "Constant expression reduced to (BUFFER) length %X\n",
473 1.1.1.2.2.2 bouyer ObjDesc->Buffer.Length);
474 1.1.1.2.2.2 bouyer break;
475 1.1.1.2.2.2 bouyer
476 1.1.1.2.2.2 bouyer
477 1.1.1.2.2.2 bouyer default:
478 1.1.1.2.2.2 bouyer printf ("Unsupported return type: %s\n",
479 1.1.1.2.2.2 bouyer AcpiUtGetObjectTypeName (ObjDesc));
480 1.1.1.2.2.2 bouyer break;
481 1.1.1.2.2.2 bouyer }
482 1.1.1.2.2.2 bouyer }
483 1.1.1.2.2.2 bouyer
484 1.1.1.2.2.2 bouyer UtSetParseOpName (Op);
485 1.1.1.2.2.2 bouyer Op->Asl.Child = NULL;
486 1.1.1.2.2.2 bouyer
487 1.1.1.2.2.2 bouyer AcpiDsDeleteWalkState (WalkState);
488 1.1.1.2.2.2 bouyer
489 1.1.1.2.2.2 bouyer return (AE_CTRL_DEPTH);
490 1.1.1.2.2.2 bouyer }
491 1.1.1.2.2.2 bouyer
492