dmcstyle.c revision 1.2 1 1.1 christos /*******************************************************************************
2 1.1 christos *
3 1.1 christos * Module Name: dmcstyle - Support for C-style operator disassembly
4 1.1 christos *
5 1.1 christos ******************************************************************************/
6 1.1 christos
7 1.1 christos /*
8 1.1 christos * Copyright (C) 2000 - 2015, Intel Corp.
9 1.1 christos * All rights reserved.
10 1.1 christos *
11 1.1 christos * Redistribution and use in source and binary forms, with or without
12 1.1 christos * modification, are permitted provided that the following conditions
13 1.1 christos * are met:
14 1.1 christos * 1. Redistributions of source code must retain the above copyright
15 1.1 christos * notice, this list of conditions, and the following disclaimer,
16 1.1 christos * without modification.
17 1.1 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1 christos * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1 christos * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1 christos * including a substantially similar Disclaimer requirement for further
21 1.1 christos * binary redistribution.
22 1.1 christos * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1 christos * of any contributors may be used to endorse or promote products derived
24 1.1 christos * from this software without specific prior written permission.
25 1.1 christos *
26 1.1 christos * Alternatively, this software may be distributed under the terms of the
27 1.1 christos * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1 christos * Software Foundation.
29 1.1 christos *
30 1.1 christos * NO WARRANTY
31 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1 christos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1 christos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1 christos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1 christos * POSSIBILITY OF SUCH DAMAGES.
42 1.1 christos */
43 1.1 christos
44 1.1 christos #include "acpi.h"
45 1.1 christos #include "accommon.h"
46 1.1 christos #include "acparser.h"
47 1.1 christos #include "amlcode.h"
48 1.1 christos #include "acdisasm.h"
49 1.1 christos #include "acdebug.h"
50 1.1 christos
51 1.1 christos #ifdef ACPI_DISASSEMBLER
52 1.1 christos
53 1.1 christos #define _COMPONENT ACPI_CA_DEBUGGER
54 1.1 christos ACPI_MODULE_NAME ("dmcstyle")
55 1.1 christos
56 1.1 christos
57 1.1 christos /* Local prototypes */
58 1.1 christos
59 1.2 christos static const char *
60 1.1 christos AcpiDmGetCompoundSymbol (
61 1.1 christos UINT16 AslOpcode);
62 1.1 christos
63 1.1 christos static void
64 1.1 christos AcpiDmPromoteTarget (
65 1.1 christos ACPI_PARSE_OBJECT *Op,
66 1.1 christos ACPI_PARSE_OBJECT *Target);
67 1.1 christos
68 1.1 christos static BOOLEAN
69 1.1 christos AcpiDmIsValidTarget (
70 1.1 christos ACPI_PARSE_OBJECT *Op);
71 1.1 christos
72 1.1 christos static BOOLEAN
73 1.1 christos AcpiDmIsTargetAnOperand (
74 1.1 christos ACPI_PARSE_OBJECT *Target,
75 1.1 christos ACPI_PARSE_OBJECT *Operand,
76 1.1 christos BOOLEAN TopLevel);
77 1.1 christos
78 1.1 christos
79 1.1 christos /*******************************************************************************
80 1.1 christos *
81 1.1 christos * FUNCTION: AcpiDmCheckForSymbolicOpcode
82 1.1 christos *
83 1.1 christos * PARAMETERS: Op - Current parse object
84 1.1 christos * Walk - Current parse tree walk info
85 1.1 christos *
86 1.1 christos * RETURN: TRUE if opcode can be converted to symbolic, FALSE otherwise
87 1.1 christos *
88 1.1 christos * DESCRIPTION: This is the main code that implements disassembly of AML code
89 1.1 christos * to C-style operators. Called during descending phase of the
90 1.1 christos * parse tree walk.
91 1.1 christos *
92 1.1 christos ******************************************************************************/
93 1.1 christos
94 1.1 christos BOOLEAN
95 1.1 christos AcpiDmCheckForSymbolicOpcode (
96 1.1 christos ACPI_PARSE_OBJECT *Op,
97 1.1 christos ACPI_OP_WALK_INFO *Info)
98 1.1 christos {
99 1.2 christos const char *OperatorSymbol = NULL;
100 1.1 christos ACPI_PARSE_OBJECT *Child1;
101 1.1 christos ACPI_PARSE_OBJECT *Child2;
102 1.1 christos ACPI_PARSE_OBJECT *Target;
103 1.1 christos
104 1.1 christos
105 1.1 christos /* Exit immediately if ASL+ not enabled */
106 1.1 christos
107 1.1 christos if (!AcpiGbl_CstyleDisassembly)
108 1.1 christos {
109 1.1 christos return (FALSE);
110 1.1 christos }
111 1.1 christos
112 1.1 christos /* Get the first operand */
113 1.1 christos
114 1.1 christos Child1 = AcpiPsGetArg (Op, 0);
115 1.1 christos if (!Child1)
116 1.1 christos {
117 1.1 christos return (FALSE);
118 1.1 christos }
119 1.1 christos
120 1.1 christos /* Get the second operand */
121 1.1 christos
122 1.1 christos Child2 = Child1->Common.Next;
123 1.1 christos
124 1.1 christos /* Setup the operator string for this opcode */
125 1.1 christos
126 1.1 christos switch (Op->Common.AmlOpcode)
127 1.1 christos {
128 1.1 christos case AML_ADD_OP:
129 1.1 christos OperatorSymbol = " + ";
130 1.1 christos break;
131 1.1 christos
132 1.1 christos case AML_SUBTRACT_OP:
133 1.1 christos OperatorSymbol = " - ";
134 1.1 christos break;
135 1.1 christos
136 1.1 christos case AML_MULTIPLY_OP:
137 1.1 christos OperatorSymbol = " * ";
138 1.1 christos break;
139 1.1 christos
140 1.1 christos case AML_DIVIDE_OP:
141 1.1 christos OperatorSymbol = " / ";
142 1.1 christos break;
143 1.1 christos
144 1.1 christos case AML_MOD_OP:
145 1.1 christos OperatorSymbol = " % ";
146 1.1 christos break;
147 1.1 christos
148 1.1 christos case AML_SHIFT_LEFT_OP:
149 1.1 christos OperatorSymbol = " << ";
150 1.1 christos break;
151 1.1 christos
152 1.1 christos case AML_SHIFT_RIGHT_OP:
153 1.1 christos OperatorSymbol = " >> ";
154 1.1 christos break;
155 1.1 christos
156 1.1 christos case AML_BIT_AND_OP:
157 1.1 christos OperatorSymbol = " & ";
158 1.1 christos break;
159 1.1 christos
160 1.1 christos case AML_BIT_OR_OP:
161 1.1 christos OperatorSymbol = " | ";
162 1.1 christos break;
163 1.1 christos
164 1.1 christos case AML_BIT_XOR_OP:
165 1.1 christos OperatorSymbol = " ^ ";
166 1.1 christos break;
167 1.1 christos
168 1.1 christos /* Logical operators, no target */
169 1.1 christos
170 1.1 christos case AML_LAND_OP:
171 1.1 christos OperatorSymbol = " && ";
172 1.1 christos break;
173 1.1 christos
174 1.1 christos case AML_LEQUAL_OP:
175 1.1 christos OperatorSymbol = " == ";
176 1.1 christos break;
177 1.1 christos
178 1.1 christos case AML_LGREATER_OP:
179 1.1 christos OperatorSymbol = " > ";
180 1.1 christos break;
181 1.1 christos
182 1.1 christos case AML_LLESS_OP:
183 1.1 christos OperatorSymbol = " < ";
184 1.1 christos break;
185 1.1 christos
186 1.1 christos case AML_LOR_OP:
187 1.1 christos OperatorSymbol = " || ";
188 1.1 christos break;
189 1.1 christos
190 1.1 christos case AML_LNOT_OP:
191 1.1 christos /*
192 1.1 christos * Check for the LNOT sub-opcodes. These correspond to
193 1.1 christos * LNotEqual, LLessEqual, and LGreaterEqual. There are
194 1.1 christos * no actual AML opcodes for these operators.
195 1.1 christos */
196 1.1 christos switch (Child1->Common.AmlOpcode)
197 1.1 christos {
198 1.1 christos case AML_LEQUAL_OP:
199 1.1 christos OperatorSymbol = " != ";
200 1.1 christos break;
201 1.1 christos
202 1.1 christos case AML_LGREATER_OP:
203 1.1 christos OperatorSymbol = " <= ";
204 1.1 christos break;
205 1.1 christos
206 1.1 christos case AML_LLESS_OP:
207 1.1 christos OperatorSymbol = " >= ";
208 1.1 christos break;
209 1.1 christos
210 1.1 christos default:
211 1.1 christos
212 1.1 christos /* Unary LNOT case, emit "!" immediately */
213 1.1 christos
214 1.1 christos AcpiOsPrintf ("!");
215 1.1 christos return (TRUE);
216 1.1 christos }
217 1.1 christos
218 1.1 christos Child1->Common.DisasmOpcode = ACPI_DASM_LNOT_SUFFIX;
219 1.1 christos Op->Common.DisasmOpcode = ACPI_DASM_LNOT_PREFIX;
220 1.1 christos
221 1.1 christos /* Save symbol string in the next child (not peer) */
222 1.1 christos
223 1.1 christos Child2 = AcpiPsGetArg (Child1, 0);
224 1.1 christos if (!Child2)
225 1.1 christos {
226 1.1 christos return (FALSE);
227 1.1 christos }
228 1.1 christos
229 1.1 christos Child2->Common.OperatorSymbol = OperatorSymbol;
230 1.1 christos return (TRUE);
231 1.1 christos
232 1.1 christos #ifdef INDEX_SUPPORT
233 1.1 christos case AML_INDEX_OP:
234 1.1 christos Child1->Common.OperatorSymbol = " [";
235 1.1 christos Child2->Common.OperatorSymbol = "]";
236 1.1 christos break;
237 1.1 christos #endif
238 1.1 christos
239 1.1 christos /* Unary operators */
240 1.1 christos
241 1.1 christos case AML_DECREMENT_OP:
242 1.1 christos OperatorSymbol = "--";
243 1.1 christos break;
244 1.1 christos
245 1.1 christos case AML_INCREMENT_OP:
246 1.1 christos OperatorSymbol = "++";
247 1.1 christos break;
248 1.1 christos
249 1.1 christos case AML_BIT_NOT_OP:
250 1.1 christos case AML_STORE_OP:
251 1.1 christos OperatorSymbol = NULL;
252 1.1 christos break;
253 1.1 christos
254 1.1 christos default:
255 1.1 christos return (FALSE);
256 1.1 christos }
257 1.1 christos
258 1.1 christos if (Child1->Common.DisasmOpcode == ACPI_DASM_LNOT_SUFFIX)
259 1.1 christos {
260 1.1 christos return (TRUE);
261 1.1 christos }
262 1.1 christos
263 1.1 christos /*
264 1.1 christos * This is the key to how the disassembly of the C-style operators
265 1.1 christos * works. We save the operator symbol in the first child, thus
266 1.1 christos * deferring symbol output until after the first operand has been
267 1.1 christos * emitted.
268 1.1 christos */
269 1.1 christos if (!Child1->Common.OperatorSymbol)
270 1.1 christos {
271 1.1 christos Child1->Common.OperatorSymbol = OperatorSymbol;
272 1.1 christos }
273 1.1 christos
274 1.1 christos /*
275 1.1 christos * Check for a valid target as the 3rd (or sometimes 2nd) operand
276 1.1 christos *
277 1.1 christos * Compound assignment operator support:
278 1.1 christos * Attempt to optimize constructs of the form:
279 1.1 christos * Add (Local1, 0xFF, Local1)
280 1.1 christos * to:
281 1.1 christos * Local1 += 0xFF
282 1.1 christos *
283 1.1 christos * Only the math operators and Store() have a target.
284 1.1 christos * Logicals have no target.
285 1.1 christos */
286 1.1 christos switch (Op->Common.AmlOpcode)
287 1.1 christos {
288 1.1 christos case AML_ADD_OP:
289 1.1 christos case AML_SUBTRACT_OP:
290 1.1 christos case AML_MULTIPLY_OP:
291 1.1 christos case AML_DIVIDE_OP:
292 1.1 christos case AML_MOD_OP:
293 1.1 christos case AML_SHIFT_LEFT_OP:
294 1.1 christos case AML_SHIFT_RIGHT_OP:
295 1.1 christos case AML_BIT_AND_OP:
296 1.1 christos case AML_BIT_OR_OP:
297 1.1 christos case AML_BIT_XOR_OP:
298 1.1 christos
299 1.1 christos /* Target is 3rd operand */
300 1.1 christos
301 1.1 christos Target = Child2->Common.Next;
302 1.1 christos if (Op->Common.AmlOpcode == AML_DIVIDE_OP)
303 1.1 christos {
304 1.1 christos /*
305 1.1 christos * Divide has an extra target operand (Remainder).
306 1.1 christos * If this extra target is specified, it cannot be converted
307 1.1 christos * to a C-style operator
308 1.1 christos */
309 1.1 christos if (AcpiDmIsValidTarget (Target))
310 1.1 christos {
311 1.1 christos Child1->Common.OperatorSymbol = NULL;
312 1.1 christos return (FALSE);
313 1.1 christos }
314 1.1 christos
315 1.1 christos Target->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
316 1.1 christos Target = Target->Common.Next;
317 1.1 christos }
318 1.1 christos
319 1.1 christos /* Parser should ensure there is at least a placeholder target */
320 1.1 christos
321 1.1 christos if (!Target)
322 1.1 christos {
323 1.1 christos return (FALSE);
324 1.1 christos }
325 1.1 christos
326 1.1 christos if (!AcpiDmIsValidTarget (Target))
327 1.1 christos {
328 1.1 christos /* Not a valid target (placeholder only, from parser) */
329 1.1 christos break;
330 1.1 christos }
331 1.1 christos
332 1.1 christos /*
333 1.1 christos * Promote the target up to the first child in the parse
334 1.1 christos * tree. This is done because the target will be output
335 1.1 christos * first, in the form:
336 1.1 christos * <Target> = Operands...
337 1.1 christos */
338 1.1 christos AcpiDmPromoteTarget (Op, Target);
339 1.1 christos
340 1.1 christos /*
341 1.1 christos * Check for possible conversion to a "Compound Assignment".
342 1.1 christos *
343 1.1 christos * Determine if either operand is the same as the target
344 1.1 christos * and display compound assignment operator and other operand.
345 1.1 christos */
346 1.1 christos if ((AcpiDmIsTargetAnOperand (Target, Child1, TRUE)) ||
347 1.1 christos (AcpiDmIsTargetAnOperand (Target, Child2, TRUE)))
348 1.1 christos {
349 1.1 christos Target->Common.OperatorSymbol =
350 1.1 christos AcpiDmGetCompoundSymbol (Op->Common.AmlOpcode);
351 1.1 christos
352 1.1 christos /* Convert operator to compound assignment */
353 1.1 christos
354 1.1 christos Op->Common.DisasmFlags |= ACPI_PARSEOP_COMPOUND;
355 1.1 christos Child1->Common.OperatorSymbol = NULL;
356 1.1 christos return (TRUE);
357 1.1 christos }
358 1.1 christos
359 1.1 christos /*
360 1.1 christos * If we are within a C-style expression, emit an extra open
361 1.1 christos * paren. Implemented by examining the parent op.
362 1.1 christos */
363 1.1 christos switch (Op->Common.Parent->Common.AmlOpcode)
364 1.1 christos {
365 1.1 christos case AML_ADD_OP:
366 1.1 christos case AML_SUBTRACT_OP:
367 1.1 christos case AML_MULTIPLY_OP:
368 1.1 christos case AML_DIVIDE_OP:
369 1.1 christos case AML_MOD_OP:
370 1.1 christos case AML_SHIFT_LEFT_OP:
371 1.1 christos case AML_SHIFT_RIGHT_OP:
372 1.1 christos case AML_BIT_AND_OP:
373 1.1 christos case AML_BIT_OR_OP:
374 1.1 christos case AML_BIT_XOR_OP:
375 1.1 christos case AML_LAND_OP:
376 1.1 christos case AML_LEQUAL_OP:
377 1.1 christos case AML_LGREATER_OP:
378 1.1 christos case AML_LLESS_OP:
379 1.1 christos case AML_LOR_OP:
380 1.1 christos
381 1.1 christos Op->Common.DisasmFlags |= ACPI_PARSEOP_ASSIGNMENT;
382 1.1 christos AcpiOsPrintf ("(");
383 1.1 christos break;
384 1.1 christos
385 1.1 christos default:
386 1.1 christos break;
387 1.1 christos }
388 1.1 christos
389 1.1 christos /* Normal output for ASL/AML operators with a target operand */
390 1.1 christos
391 1.1 christos Target->Common.OperatorSymbol = " = (";
392 1.1 christos return (TRUE);
393 1.1 christos
394 1.1 christos /* Binary operators, no parens */
395 1.1 christos
396 1.1 christos case AML_DECREMENT_OP:
397 1.1 christos case AML_INCREMENT_OP:
398 1.1 christos return (TRUE);
399 1.1 christos
400 1.1 christos #ifdef INDEX_SUPPORT
401 1.1 christos case AML_INDEX_OP:
402 1.1 christos
403 1.1 christos /* Target is optional, 3rd operand */
404 1.1 christos
405 1.1 christos Target = Child2->Common.Next;
406 1.1 christos if (AcpiDmIsValidTarget (Target))
407 1.1 christos {
408 1.1 christos AcpiDmPromoteTarget (Op, Target);
409 1.1 christos
410 1.1 christos if (!Target->Common.OperatorSymbol)
411 1.1 christos {
412 1.1 christos Target->Common.OperatorSymbol = " = ";
413 1.1 christos }
414 1.1 christos }
415 1.1 christos return (TRUE);
416 1.1 christos #endif
417 1.1 christos
418 1.1 christos case AML_STORE_OP:
419 1.1 christos /*
420 1.1 christos * Target is the 2nd operand.
421 1.1 christos * We know the target is valid, it is not optional.
422 1.1 christos * In the parse tree, simply swap the target with the
423 1.1 christos * source so that the target is processed first.
424 1.1 christos */
425 1.1 christos Target = Child1->Common.Next;
426 1.1 christos AcpiDmPromoteTarget (Op, Target);
427 1.1 christos
428 1.1 christos if (!Target->Common.OperatorSymbol)
429 1.1 christos {
430 1.1 christos Target->Common.OperatorSymbol = " = ";
431 1.1 christos }
432 1.1 christos return (TRUE);
433 1.1 christos
434 1.1 christos case AML_BIT_NOT_OP:
435 1.1 christos
436 1.1 christos /* Target is optional, 2nd operand */
437 1.1 christos
438 1.1 christos Target = Child1->Common.Next;
439 1.1 christos if (!Target)
440 1.1 christos {
441 1.1 christos return (FALSE);
442 1.1 christos }
443 1.1 christos
444 1.1 christos if (AcpiDmIsValidTarget (Target))
445 1.1 christos {
446 1.1 christos /* Valid target, not a placeholder */
447 1.1 christos
448 1.1 christos AcpiDmPromoteTarget (Op, Target);
449 1.1 christos Target->Common.OperatorSymbol = " = ~";
450 1.1 christos }
451 1.1 christos else
452 1.1 christos {
453 1.1 christos /* No target. Emit this prefix operator immediately */
454 1.1 christos
455 1.1 christos AcpiOsPrintf ("~");
456 1.1 christos }
457 1.1 christos return (TRUE);
458 1.1 christos
459 1.1 christos default:
460 1.1 christos break;
461 1.1 christos }
462 1.1 christos
463 1.1 christos /* All other operators, emit an open paren */
464 1.1 christos
465 1.1 christos AcpiOsPrintf ("(");
466 1.1 christos return (TRUE);
467 1.1 christos }
468 1.1 christos
469 1.1 christos
470 1.1 christos /*******************************************************************************
471 1.1 christos *
472 1.1 christos * FUNCTION: AcpiDmCloseOperator
473 1.1 christos *
474 1.1 christos * PARAMETERS: Op - Current parse object
475 1.1 christos *
476 1.1 christos * RETURN: None
477 1.1 christos *
478 1.1 christos * DESCRIPTION: Closes an operator by adding a closing parentheses if and
479 1.1 christos * when necessary. Called during ascending phase of the
480 1.1 christos * parse tree walk.
481 1.1 christos *
482 1.1 christos ******************************************************************************/
483 1.1 christos
484 1.1 christos void
485 1.1 christos AcpiDmCloseOperator (
486 1.1 christos ACPI_PARSE_OBJECT *Op)
487 1.1 christos {
488 1.1 christos
489 1.1 christos /* Always emit paren if ASL+ disassembly disabled */
490 1.1 christos
491 1.1 christos if (!AcpiGbl_CstyleDisassembly)
492 1.1 christos {
493 1.1 christos AcpiOsPrintf (")");
494 1.1 christos return;
495 1.1 christos }
496 1.1 christos
497 1.1 christos /* Check if we need to add an additional closing paren */
498 1.1 christos
499 1.1 christos switch (Op->Common.AmlOpcode)
500 1.1 christos {
501 1.1 christos case AML_ADD_OP:
502 1.1 christos case AML_SUBTRACT_OP:
503 1.1 christos case AML_MULTIPLY_OP:
504 1.1 christos case AML_DIVIDE_OP:
505 1.1 christos case AML_MOD_OP:
506 1.1 christos case AML_SHIFT_LEFT_OP:
507 1.1 christos case AML_SHIFT_RIGHT_OP:
508 1.1 christos case AML_BIT_AND_OP:
509 1.1 christos case AML_BIT_OR_OP:
510 1.1 christos case AML_BIT_XOR_OP:
511 1.1 christos case AML_LAND_OP:
512 1.1 christos case AML_LEQUAL_OP:
513 1.1 christos case AML_LGREATER_OP:
514 1.1 christos case AML_LLESS_OP:
515 1.1 christos case AML_LOR_OP:
516 1.1 christos
517 1.1 christos /* Emit paren only if this is not a compound assignment */
518 1.1 christos
519 1.1 christos if (Op->Common.DisasmFlags & ACPI_PARSEOP_COMPOUND)
520 1.1 christos {
521 1.1 christos return;
522 1.1 christos }
523 1.1 christos
524 1.1 christos /* Emit extra close paren for assignment within an expression */
525 1.1 christos
526 1.1 christos if (Op->Common.DisasmFlags & ACPI_PARSEOP_ASSIGNMENT)
527 1.1 christos {
528 1.1 christos AcpiOsPrintf (")");
529 1.1 christos }
530 1.1 christos break;
531 1.1 christos
532 1.1 christos
533 1.1 christos /* No need for parens for these */
534 1.1 christos
535 1.1 christos #ifdef INDEX_SUPPORT
536 1.1 christos case AML_INDEX_OP:
537 1.1 christos #endif
538 1.1 christos case AML_DECREMENT_OP:
539 1.1 christos case AML_INCREMENT_OP:
540 1.1 christos case AML_LNOT_OP:
541 1.1 christos case AML_BIT_NOT_OP:
542 1.1 christos case AML_STORE_OP:
543 1.1 christos return;
544 1.1 christos
545 1.1 christos default:
546 1.1 christos
547 1.1 christos /* Always emit paren for non-ASL+ operators */
548 1.1 christos break;
549 1.1 christos }
550 1.1 christos
551 1.1 christos AcpiOsPrintf (")");
552 1.1 christos }
553 1.1 christos
554 1.1 christos
555 1.1 christos /*******************************************************************************
556 1.1 christos *
557 1.1 christos * FUNCTION: AcpiDmGetCompoundSymbol
558 1.1 christos *
559 1.1 christos * PARAMETERS: AslOpcode
560 1.1 christos *
561 1.1 christos * RETURN: String containing the compound assignment symbol
562 1.1 christos *
563 1.1 christos * DESCRIPTION: Detect opcodes that can be converted to compound assignment,
564 1.1 christos * return the appropriate operator string.
565 1.1 christos *
566 1.1 christos ******************************************************************************/
567 1.1 christos
568 1.2 christos static const char *
569 1.1 christos AcpiDmGetCompoundSymbol (
570 1.1 christos UINT16 AmlOpcode)
571 1.1 christos {
572 1.2 christos const char *Symbol;
573 1.1 christos
574 1.1 christos
575 1.1 christos switch (AmlOpcode)
576 1.1 christos {
577 1.1 christos case AML_ADD_OP:
578 1.1 christos Symbol = " += ";
579 1.1 christos break;
580 1.1 christos
581 1.1 christos case AML_SUBTRACT_OP:
582 1.1 christos Symbol = " -= ";
583 1.1 christos break;
584 1.1 christos
585 1.1 christos case AML_MULTIPLY_OP:
586 1.1 christos Symbol = " *= ";
587 1.1 christos break;
588 1.1 christos
589 1.1 christos case AML_DIVIDE_OP:
590 1.1 christos Symbol = " /= ";
591 1.1 christos break;
592 1.1 christos
593 1.1 christos case AML_MOD_OP:
594 1.1 christos Symbol = " %= ";
595 1.1 christos break;
596 1.1 christos
597 1.1 christos case AML_SHIFT_LEFT_OP:
598 1.1 christos Symbol = " <<= ";
599 1.1 christos break;
600 1.1 christos
601 1.1 christos case AML_SHIFT_RIGHT_OP:
602 1.1 christos Symbol = " >>= ";
603 1.1 christos break;
604 1.1 christos
605 1.1 christos case AML_BIT_AND_OP:
606 1.1 christos Symbol = " &= ";
607 1.1 christos break;
608 1.1 christos
609 1.1 christos case AML_BIT_OR_OP:
610 1.1 christos Symbol = " |= ";
611 1.1 christos break;
612 1.1 christos
613 1.1 christos case AML_BIT_XOR_OP:
614 1.1 christos Symbol = " ^= ";
615 1.1 christos break;
616 1.1 christos
617 1.1 christos default:
618 1.1 christos
619 1.1 christos /* No operator string for all other opcodes */
620 1.1 christos return (NULL);
621 1.1 christos }
622 1.1 christos
623 1.1 christos return (Symbol);
624 1.1 christos }
625 1.1 christos
626 1.1 christos
627 1.1 christos /*******************************************************************************
628 1.1 christos *
629 1.1 christos * FUNCTION: AcpiDmPromoteTarget
630 1.1 christos *
631 1.1 christos * PARAMETERS: Op - Operator parse object
632 1.1 christos * Target - Target associate with the Op
633 1.1 christos *
634 1.1 christos * RETURN: None
635 1.1 christos *
636 1.1 christos * DESCRIPTION: Transform the parse tree by moving the target up to the first
637 1.1 christos * child of the Op.
638 1.1 christos *
639 1.1 christos ******************************************************************************/
640 1.1 christos
641 1.1 christos static void
642 1.1 christos AcpiDmPromoteTarget (
643 1.1 christos ACPI_PARSE_OBJECT *Op,
644 1.1 christos ACPI_PARSE_OBJECT *Target)
645 1.1 christos {
646 1.1 christos ACPI_PARSE_OBJECT *Child;
647 1.1 christos
648 1.1 christos
649 1.1 christos /* Link target directly to the Op as first child */
650 1.1 christos
651 1.1 christos Child = Op->Common.Value.Arg;
652 1.1 christos Op->Common.Value.Arg = Target;
653 1.1 christos Target->Common.Next = Child;
654 1.1 christos
655 1.1 christos /* Find the last peer, it is linked to the target. Unlink it. */
656 1.1 christos
657 1.1 christos while (Child->Common.Next != Target)
658 1.1 christos {
659 1.1 christos Child = Child->Common.Next;
660 1.1 christos }
661 1.1 christos
662 1.1 christos Child->Common.Next = NULL;
663 1.1 christos }
664 1.1 christos
665 1.1 christos
666 1.1 christos /*******************************************************************************
667 1.1 christos *
668 1.1 christos * FUNCTION: AcpiDmIsValidTarget
669 1.1 christos *
670 1.1 christos * PARAMETERS: Target - Target Op from the parse tree
671 1.1 christos *
672 1.1 christos * RETURN: TRUE if the Target is real. FALSE if it is just a placeholder
673 1.1 christos * Op that was inserted by the parser.
674 1.1 christos *
675 1.1 christos * DESCRIPTION: Determine if a Target Op is a placeholder Op or a real Target.
676 1.1 christos * In other words, determine if the optional target is used or
677 1.1 christos * not.
678 1.1 christos *
679 1.1 christos ******************************************************************************/
680 1.1 christos
681 1.1 christos static BOOLEAN
682 1.1 christos AcpiDmIsValidTarget (
683 1.1 christos ACPI_PARSE_OBJECT *Target)
684 1.1 christos {
685 1.1 christos
686 1.1 christos if ((Target->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
687 1.1 christos (Target->Common.Value.Arg == NULL))
688 1.1 christos {
689 1.1 christos return (FALSE);
690 1.1 christos }
691 1.1 christos
692 1.1 christos return (TRUE);
693 1.1 christos }
694 1.1 christos
695 1.1 christos
696 1.1 christos /*******************************************************************************
697 1.1 christos *
698 1.1 christos * FUNCTION: AcpiDmIsTargetAnOperand
699 1.1 christos *
700 1.1 christos * PARAMETERS: Target - Target associated with the expression
701 1.1 christos * Operand - An operand associated with expression
702 1.1 christos *
703 1.1 christos * RETURN: TRUE if expression can be converted to a compound assignment.
704 1.1 christos * FALSE otherwise.
705 1.1 christos *
706 1.1 christos * DESCRIPTION: Determine if the Target duplicates the operand, in order to
707 1.1 christos * detect if the expression can be converted to a compound
708 1.1 christos * assigment. (+=, *=, etc.)
709 1.1 christos *
710 1.1 christos ******************************************************************************/
711 1.1 christos
712 1.1 christos static BOOLEAN
713 1.1 christos AcpiDmIsTargetAnOperand (
714 1.1 christos ACPI_PARSE_OBJECT *Target,
715 1.1 christos ACPI_PARSE_OBJECT *Operand,
716 1.1 christos BOOLEAN TopLevel)
717 1.1 christos {
718 1.1 christos const ACPI_OPCODE_INFO *OpInfo;
719 1.1 christos BOOLEAN Same;
720 1.1 christos
721 1.1 christos
722 1.1 christos /*
723 1.1 christos * Opcodes must match. Note: ignoring the difference between nameseg
724 1.1 christos * and namepath for now. May be needed later.
725 1.1 christos */
726 1.1 christos if (Target->Common.AmlOpcode != Operand->Common.AmlOpcode)
727 1.1 christos {
728 1.1 christos return (FALSE);
729 1.1 christos }
730 1.1 christos
731 1.1 christos /* Nodes should match, even if they are NULL */
732 1.1 christos
733 1.1 christos if (Target->Common.Node != Operand->Common.Node)
734 1.1 christos {
735 1.1 christos return (FALSE);
736 1.1 christos }
737 1.1 christos
738 1.1 christos /* Determine if a child exists */
739 1.1 christos
740 1.1 christos OpInfo = AcpiPsGetOpcodeInfo (Operand->Common.AmlOpcode);
741 1.1 christos if (OpInfo->Flags & AML_HAS_ARGS)
742 1.1 christos {
743 1.1 christos Same = AcpiDmIsTargetAnOperand (Target->Common.Value.Arg,
744 1.1 christos Operand->Common.Value.Arg, FALSE);
745 1.1 christos if (!Same)
746 1.1 christos {
747 1.1 christos return (FALSE);
748 1.1 christos }
749 1.1 christos }
750 1.1 christos
751 1.1 christos /* Check the next peer, as long as we are not at the top level */
752 1.1 christos
753 1.1 christos if ((!TopLevel) &&
754 1.1 christos Target->Common.Next)
755 1.1 christos {
756 1.1 christos Same = AcpiDmIsTargetAnOperand (Target->Common.Next,
757 1.1 christos Operand->Common.Next, FALSE);
758 1.1 christos if (!Same)
759 1.1 christos {
760 1.1 christos return (FALSE);
761 1.1 christos }
762 1.1 christos }
763 1.1 christos
764 1.1 christos /* Supress the duplicate operand at the top-level */
765 1.1 christos
766 1.1 christos if (TopLevel)
767 1.1 christos {
768 1.1 christos Operand->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
769 1.1 christos }
770 1.1 christos return (TRUE);
771 1.1 christos }
772 1.1 christos
773 1.1 christos #endif
774