Home | History | Annotate | Line # | Download | only in disassembler
      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.16  christos /******************************************************************************
      8  1.16  christos  *
      9  1.16  christos  * 1. Copyright Notice
     10  1.16  christos  *
     11  1.17  christos  * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.
     12   1.1  christos  * All rights reserved.
     13   1.1  christos  *
     14  1.16  christos  * 2. License
     15  1.16  christos  *
     16  1.16  christos  * 2.1. This is your license from Intel Corp. under its intellectual property
     17  1.16  christos  * rights. You may have additional license terms from the party that provided
     18  1.16  christos  * you this software, covering your right to use that party's intellectual
     19  1.16  christos  * property rights.
     20  1.16  christos  *
     21  1.16  christos  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     22  1.16  christos  * copy of the source code appearing in this file ("Covered Code") an
     23  1.16  christos  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     24  1.16  christos  * base code distributed originally by Intel ("Original Intel Code") to copy,
     25  1.16  christos  * make derivatives, distribute, use and display any portion of the Covered
     26  1.16  christos  * Code in any form, with the right to sublicense such rights; and
     27  1.16  christos  *
     28  1.16  christos  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     29  1.16  christos  * license (with the right to sublicense), under only those claims of Intel
     30  1.16  christos  * patents that are infringed by the Original Intel Code, to make, use, sell,
     31  1.16  christos  * offer to sell, and import the Covered Code and derivative works thereof
     32  1.16  christos  * solely to the minimum extent necessary to exercise the above copyright
     33  1.16  christos  * license, and in no event shall the patent license extend to any additions
     34  1.16  christos  * to or modifications of the Original Intel Code. No other license or right
     35  1.16  christos  * is granted directly or by implication, estoppel or otherwise;
     36  1.16  christos  *
     37  1.16  christos  * The above copyright and patent license is granted only if the following
     38  1.16  christos  * conditions are met:
     39  1.16  christos  *
     40  1.16  christos  * 3. Conditions
     41  1.16  christos  *
     42  1.16  christos  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     43  1.16  christos  * Redistribution of source code of any substantial portion of the Covered
     44  1.16  christos  * Code or modification with rights to further distribute source must include
     45  1.16  christos  * the above Copyright Notice, the above License, this list of Conditions,
     46  1.16  christos  * and the following Disclaimer and Export Compliance provision. In addition,
     47  1.16  christos  * Licensee must cause all Covered Code to which Licensee contributes to
     48  1.16  christos  * contain a file documenting the changes Licensee made to create that Covered
     49  1.16  christos  * Code and the date of any change. Licensee must include in that file the
     50  1.16  christos  * documentation of any changes made by any predecessor Licensee. Licensee
     51  1.16  christos  * must include a prominent statement that the modification is derived,
     52  1.16  christos  * directly or indirectly, from Original Intel Code.
     53  1.16  christos  *
     54  1.16  christos  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     55  1.16  christos  * Redistribution of source code of any substantial portion of the Covered
     56  1.16  christos  * Code or modification without rights to further distribute source must
     57  1.16  christos  * include the following Disclaimer and Export Compliance provision in the
     58  1.16  christos  * documentation and/or other materials provided with distribution. In
     59  1.16  christos  * addition, Licensee may not authorize further sublicense of source of any
     60  1.16  christos  * portion of the Covered Code, and must include terms to the effect that the
     61  1.16  christos  * license from Licensee to its licensee is limited to the intellectual
     62  1.16  christos  * property embodied in the software Licensee provides to its licensee, and
     63  1.16  christos  * not to intellectual property embodied in modifications its licensee may
     64  1.16  christos  * make.
     65  1.16  christos  *
     66  1.16  christos  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     67  1.16  christos  * substantial portion of the Covered Code or modification must reproduce the
     68  1.16  christos  * above Copyright Notice, and the following Disclaimer and Export Compliance
     69  1.16  christos  * provision in the documentation and/or other materials provided with the
     70  1.16  christos  * distribution.
     71  1.16  christos  *
     72  1.16  christos  * 3.4. Intel retains all right, title, and interest in and to the Original
     73  1.16  christos  * Intel Code.
     74  1.16  christos  *
     75  1.16  christos  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     76  1.16  christos  * Intel shall be used in advertising or otherwise to promote the sale, use or
     77  1.16  christos  * other dealings in products derived from or relating to the Covered Code
     78  1.16  christos  * without prior written authorization from Intel.
     79  1.16  christos  *
     80  1.16  christos  * 4. Disclaimer and Export Compliance
     81  1.16  christos  *
     82  1.16  christos  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     83  1.16  christos  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     84  1.16  christos  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
     85  1.16  christos  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
     86  1.16  christos  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
     87  1.16  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     88  1.16  christos  * PARTICULAR PURPOSE.
     89  1.16  christos  *
     90  1.16  christos  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     91  1.16  christos  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     92  1.16  christos  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     93  1.16  christos  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     94  1.16  christos  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     95  1.16  christos  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
     96  1.16  christos  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     97  1.16  christos  * LIMITED REMEDY.
     98  1.16  christos  *
     99  1.16  christos  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    100  1.16  christos  * software or system incorporating such software without first obtaining any
    101  1.16  christos  * required license or other approval from the U. S. Department of Commerce or
    102  1.16  christos  * any other agency or department of the United States Government. In the
    103  1.16  christos  * event Licensee exports any such software from the United States or
    104  1.16  christos  * re-exports any such software from a foreign destination, Licensee shall
    105  1.16  christos  * ensure that the distribution and export/re-export of the software is in
    106  1.16  christos  * compliance with all laws, regulations, orders, or other restrictions of the
    107  1.16  christos  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    108  1.16  christos  * any of its subsidiaries will export/re-export any technical data, process,
    109  1.16  christos  * software, or service, directly or indirectly, to any country for which the
    110  1.16  christos  * United States government or any agency thereof requires an export license,
    111  1.16  christos  * other governmental approval, or letter of assurance, without first obtaining
    112  1.16  christos  * such license, approval or letter.
    113  1.16  christos  *
    114  1.16  christos  *****************************************************************************
    115  1.16  christos  *
    116  1.16  christos  * Alternatively, you may choose to be licensed under the terms of the
    117  1.16  christos  * following license:
    118  1.16  christos  *
    119   1.1  christos  * Redistribution and use in source and binary forms, with or without
    120   1.1  christos  * modification, are permitted provided that the following conditions
    121   1.1  christos  * are met:
    122   1.1  christos  * 1. Redistributions of source code must retain the above copyright
    123   1.1  christos  *    notice, this list of conditions, and the following disclaimer,
    124   1.1  christos  *    without modification.
    125   1.1  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
    126   1.1  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
    127   1.1  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
    128   1.1  christos  *    including a substantially similar Disclaimer requirement for further
    129   1.1  christos  *    binary redistribution.
    130   1.1  christos  * 3. Neither the names of the above-listed copyright holders nor the names
    131   1.1  christos  *    of any contributors may be used to endorse or promote products derived
    132   1.1  christos  *    from this software without specific prior written permission.
    133   1.1  christos  *
    134   1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    135   1.1  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    136  1.13  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    137   1.1  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    138  1.16  christos  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    139  1.16  christos  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    140  1.16  christos  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    141  1.16  christos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    142  1.16  christos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    143  1.16  christos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    144  1.16  christos  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    145  1.16  christos  *
    146  1.16  christos  * Alternatively, you may choose to be licensed under the terms of the
    147  1.16  christos  * GNU General Public License ("GPL") version 2 as published by the Free
    148  1.16  christos  * Software Foundation.
    149  1.16  christos  *
    150  1.16  christos  *****************************************************************************/
    151   1.1  christos 
    152   1.1  christos #include "acpi.h"
    153   1.1  christos #include "accommon.h"
    154   1.1  christos #include "acparser.h"
    155   1.1  christos #include "amlcode.h"
    156   1.1  christos #include "acdebug.h"
    157   1.8  christos #include "acconvert.h"
    158   1.1  christos 
    159   1.1  christos 
    160   1.1  christos #define _COMPONENT          ACPI_CA_DEBUGGER
    161   1.1  christos         ACPI_MODULE_NAME    ("dmcstyle")
    162   1.1  christos 
    163   1.1  christos 
    164   1.1  christos /* Local prototypes */
    165   1.1  christos 
    166   1.2  christos static const char *
    167   1.1  christos AcpiDmGetCompoundSymbol (
    168   1.1  christos    UINT16                   AslOpcode);
    169   1.1  christos 
    170   1.1  christos static void
    171   1.1  christos AcpiDmPromoteTarget (
    172   1.1  christos     ACPI_PARSE_OBJECT       *Op,
    173   1.1  christos     ACPI_PARSE_OBJECT       *Target);
    174   1.1  christos 
    175   1.1  christos static BOOLEAN
    176   1.1  christos AcpiDmIsValidTarget (
    177   1.1  christos     ACPI_PARSE_OBJECT       *Op);
    178   1.1  christos 
    179   1.1  christos static BOOLEAN
    180   1.1  christos AcpiDmIsTargetAnOperand (
    181   1.1  christos     ACPI_PARSE_OBJECT       *Target,
    182   1.1  christos     ACPI_PARSE_OBJECT       *Operand,
    183   1.1  christos     BOOLEAN                 TopLevel);
    184   1.1  christos 
    185   1.7  christos static BOOLEAN
    186   1.7  christos AcpiDmIsOptimizationIgnored (
    187   1.7  christos     ACPI_PARSE_OBJECT       *StoreOp,
    188   1.7  christos     ACPI_PARSE_OBJECT       *StoreArgument);
    189   1.7  christos 
    190   1.1  christos 
    191   1.1  christos /*******************************************************************************
    192   1.1  christos  *
    193   1.1  christos  * FUNCTION:    AcpiDmCheckForSymbolicOpcode
    194   1.1  christos  *
    195   1.1  christos  * PARAMETERS:  Op                  - Current parse object
    196   1.1  christos  *              Walk                - Current parse tree walk info
    197   1.1  christos  *
    198   1.1  christos  * RETURN:      TRUE if opcode can be converted to symbolic, FALSE otherwise
    199   1.1  christos  *
    200   1.1  christos  * DESCRIPTION: This is the main code that implements disassembly of AML code
    201   1.1  christos  *              to C-style operators. Called during descending phase of the
    202   1.1  christos  *              parse tree walk.
    203   1.1  christos  *
    204   1.1  christos  ******************************************************************************/
    205   1.1  christos 
    206   1.1  christos BOOLEAN
    207   1.1  christos AcpiDmCheckForSymbolicOpcode (
    208   1.1  christos     ACPI_PARSE_OBJECT       *Op,
    209   1.1  christos     ACPI_OP_WALK_INFO       *Info)
    210   1.1  christos {
    211   1.2  christos     const char              *OperatorSymbol = NULL;
    212   1.7  christos     ACPI_PARSE_OBJECT       *Argument1;
    213   1.7  christos     ACPI_PARSE_OBJECT       *Argument2;
    214   1.1  christos     ACPI_PARSE_OBJECT       *Target;
    215   1.7  christos     ACPI_PARSE_OBJECT       *Target2;
    216   1.1  christos 
    217   1.1  christos 
    218   1.1  christos     /* Exit immediately if ASL+ not enabled */
    219   1.1  christos 
    220   1.1  christos     if (!AcpiGbl_CstyleDisassembly)
    221   1.1  christos     {
    222   1.1  christos         return (FALSE);
    223   1.1  christos     }
    224   1.1  christos 
    225   1.1  christos     /* Get the first operand */
    226   1.1  christos 
    227   1.7  christos     Argument1 = AcpiPsGetArg (Op, 0);
    228   1.7  christos     if (!Argument1)
    229   1.1  christos     {
    230   1.1  christos         return (FALSE);
    231   1.1  christos     }
    232   1.1  christos 
    233   1.1  christos     /* Get the second operand */
    234   1.1  christos 
    235   1.7  christos     Argument2 = Argument1->Common.Next;
    236   1.1  christos 
    237   1.1  christos     /* Setup the operator string for this opcode */
    238   1.1  christos 
    239   1.1  christos     switch (Op->Common.AmlOpcode)
    240   1.1  christos     {
    241   1.1  christos     case AML_ADD_OP:
    242   1.1  christos         OperatorSymbol = " + ";
    243   1.1  christos         break;
    244   1.1  christos 
    245   1.1  christos     case AML_SUBTRACT_OP:
    246   1.1  christos         OperatorSymbol = " - ";
    247   1.1  christos         break;
    248   1.1  christos 
    249   1.1  christos     case AML_MULTIPLY_OP:
    250   1.1  christos         OperatorSymbol = " * ";
    251   1.1  christos         break;
    252   1.1  christos 
    253   1.1  christos     case AML_DIVIDE_OP:
    254   1.1  christos         OperatorSymbol = " / ";
    255   1.1  christos         break;
    256   1.1  christos 
    257   1.1  christos     case AML_MOD_OP:
    258   1.1  christos         OperatorSymbol = " % ";
    259   1.1  christos         break;
    260   1.1  christos 
    261   1.1  christos     case AML_SHIFT_LEFT_OP:
    262   1.1  christos         OperatorSymbol = " << ";
    263   1.1  christos         break;
    264   1.1  christos 
    265   1.1  christos     case AML_SHIFT_RIGHT_OP:
    266   1.1  christos         OperatorSymbol = " >> ";
    267   1.1  christos         break;
    268   1.1  christos 
    269   1.1  christos     case AML_BIT_AND_OP:
    270   1.1  christos         OperatorSymbol = " & ";
    271   1.1  christos         break;
    272   1.1  christos 
    273   1.1  christos     case AML_BIT_OR_OP:
    274   1.1  christos         OperatorSymbol = " | ";
    275   1.1  christos         break;
    276   1.1  christos 
    277   1.1  christos     case AML_BIT_XOR_OP:
    278   1.1  christos         OperatorSymbol = " ^ ";
    279   1.1  christos         break;
    280   1.1  christos 
    281   1.1  christos     /* Logical operators, no target */
    282   1.1  christos 
    283   1.8  christos     case AML_LOGICAL_AND_OP:
    284   1.1  christos         OperatorSymbol = " && ";
    285   1.1  christos         break;
    286   1.1  christos 
    287   1.8  christos     case AML_LOGICAL_EQUAL_OP:
    288   1.1  christos         OperatorSymbol = " == ";
    289   1.1  christos         break;
    290   1.1  christos 
    291   1.8  christos     case AML_LOGICAL_GREATER_OP:
    292   1.1  christos         OperatorSymbol = " > ";
    293   1.1  christos         break;
    294   1.1  christos 
    295   1.8  christos     case AML_LOGICAL_LESS_OP:
    296   1.1  christos         OperatorSymbol = " < ";
    297   1.1  christos         break;
    298   1.1  christos 
    299   1.8  christos     case AML_LOGICAL_OR_OP:
    300   1.1  christos         OperatorSymbol = " || ";
    301   1.1  christos         break;
    302   1.1  christos 
    303   1.8  christos     case AML_LOGICAL_NOT_OP:
    304   1.1  christos         /*
    305   1.1  christos          * Check for the LNOT sub-opcodes. These correspond to
    306   1.1  christos          * LNotEqual, LLessEqual, and LGreaterEqual. There are
    307   1.1  christos          * no actual AML opcodes for these operators.
    308   1.1  christos          */
    309   1.7  christos         switch (Argument1->Common.AmlOpcode)
    310   1.1  christos         {
    311   1.8  christos         case AML_LOGICAL_EQUAL_OP:
    312   1.1  christos             OperatorSymbol = " != ";
    313   1.1  christos             break;
    314   1.1  christos 
    315   1.8  christos         case AML_LOGICAL_GREATER_OP:
    316   1.1  christos             OperatorSymbol = " <= ";
    317   1.1  christos             break;
    318   1.1  christos 
    319   1.8  christos         case AML_LOGICAL_LESS_OP:
    320   1.1  christos             OperatorSymbol = " >= ";
    321   1.1  christos             break;
    322   1.1  christos 
    323   1.1  christos         default:
    324   1.1  christos 
    325   1.1  christos             /* Unary LNOT case, emit "!" immediately */
    326   1.1  christos 
    327   1.1  christos             AcpiOsPrintf ("!");
    328   1.1  christos             return (TRUE);
    329   1.1  christos         }
    330   1.1  christos 
    331   1.7  christos         Argument1->Common.DisasmOpcode = ACPI_DASM_LNOT_SUFFIX;
    332   1.1  christos         Op->Common.DisasmOpcode = ACPI_DASM_LNOT_PREFIX;
    333   1.1  christos 
    334   1.1  christos         /* Save symbol string in the next child (not peer) */
    335   1.1  christos 
    336   1.7  christos         Argument2 = AcpiPsGetArg (Argument1, 0);
    337   1.7  christos         if (!Argument2)
    338   1.1  christos         {
    339   1.1  christos             return (FALSE);
    340   1.1  christos         }
    341   1.1  christos 
    342   1.7  christos         Argument2->Common.OperatorSymbol = OperatorSymbol;
    343   1.1  christos         return (TRUE);
    344   1.1  christos 
    345   1.1  christos     case AML_INDEX_OP:
    346   1.4  christos         /*
    347   1.4  christos          * Check for constant source operand. Note: although technically
    348   1.4  christos          * legal syntax, the iASL compiler does not support this with
    349   1.4  christos          * the symbolic operators for Index(). It doesn't make sense to
    350   1.4  christos          * use Index() with a constant anyway.
    351   1.4  christos          */
    352   1.7  christos         if ((Argument1->Common.AmlOpcode == AML_STRING_OP)  ||
    353   1.7  christos             (Argument1->Common.AmlOpcode == AML_BUFFER_OP)  ||
    354   1.7  christos             (Argument1->Common.AmlOpcode == AML_PACKAGE_OP) ||
    355   1.8  christos             (Argument1->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP))
    356   1.4  christos         {
    357   1.4  christos             Op->Common.DisasmFlags |= ACPI_PARSEOP_CLOSING_PAREN;
    358   1.4  christos             return (FALSE);
    359   1.4  christos         }
    360   1.4  christos 
    361   1.4  christos         /* Index operator is [] */
    362   1.4  christos 
    363   1.7  christos         Argument1->Common.OperatorSymbol = " [";
    364   1.7  christos         Argument2->Common.OperatorSymbol = "]";
    365   1.1  christos         break;
    366   1.1  christos 
    367   1.1  christos     /* Unary operators */
    368   1.1  christos 
    369   1.1  christos     case AML_DECREMENT_OP:
    370   1.1  christos         OperatorSymbol = "--";
    371   1.1  christos         break;
    372   1.1  christos 
    373   1.1  christos     case AML_INCREMENT_OP:
    374   1.1  christos         OperatorSymbol = "++";
    375   1.1  christos         break;
    376   1.1  christos 
    377   1.1  christos     case AML_BIT_NOT_OP:
    378   1.1  christos     case AML_STORE_OP:
    379   1.1  christos         OperatorSymbol = NULL;
    380   1.1  christos         break;
    381   1.1  christos 
    382   1.1  christos     default:
    383   1.1  christos         return (FALSE);
    384   1.1  christos     }
    385   1.1  christos 
    386   1.7  christos     if (Argument1->Common.DisasmOpcode == ACPI_DASM_LNOT_SUFFIX)
    387   1.1  christos     {
    388   1.1  christos         return (TRUE);
    389   1.1  christos     }
    390   1.1  christos 
    391   1.1  christos     /*
    392   1.1  christos      * This is the key to how the disassembly of the C-style operators
    393   1.1  christos      * works. We save the operator symbol in the first child, thus
    394   1.1  christos      * deferring symbol output until after the first operand has been
    395   1.1  christos      * emitted.
    396   1.1  christos      */
    397   1.7  christos     if (!Argument1->Common.OperatorSymbol)
    398   1.1  christos     {
    399   1.7  christos         Argument1->Common.OperatorSymbol = OperatorSymbol;
    400   1.1  christos     }
    401   1.1  christos 
    402   1.1  christos     /*
    403   1.1  christos      * Check for a valid target as the 3rd (or sometimes 2nd) operand
    404   1.1  christos      *
    405   1.1  christos      * Compound assignment operator support:
    406   1.1  christos      * Attempt to optimize constructs of the form:
    407   1.1  christos      *      Add (Local1, 0xFF, Local1)
    408   1.1  christos      * to:
    409   1.1  christos      *      Local1 += 0xFF
    410   1.1  christos      *
    411   1.1  christos      * Only the math operators and Store() have a target.
    412   1.1  christos      * Logicals have no target.
    413   1.1  christos      */
    414   1.1  christos     switch (Op->Common.AmlOpcode)
    415   1.1  christos     {
    416   1.1  christos     case AML_ADD_OP:
    417   1.1  christos     case AML_SUBTRACT_OP:
    418   1.1  christos     case AML_MULTIPLY_OP:
    419   1.1  christos     case AML_DIVIDE_OP:
    420   1.1  christos     case AML_MOD_OP:
    421   1.1  christos     case AML_SHIFT_LEFT_OP:
    422   1.1  christos     case AML_SHIFT_RIGHT_OP:
    423   1.1  christos     case AML_BIT_AND_OP:
    424   1.1  christos     case AML_BIT_OR_OP:
    425   1.1  christos     case AML_BIT_XOR_OP:
    426   1.1  christos 
    427   1.1  christos         /* Target is 3rd operand */
    428   1.1  christos 
    429   1.7  christos         Target = Argument2->Common.Next;
    430   1.1  christos         if (Op->Common.AmlOpcode == AML_DIVIDE_OP)
    431   1.1  christos         {
    432   1.7  christos             Target2 = Target->Common.Next;
    433   1.7  christos 
    434   1.1  christos             /*
    435   1.1  christos              * Divide has an extra target operand (Remainder).
    436   1.7  christos              * Default behavior is to simply ignore ASL+ conversion
    437   1.7  christos              * if the remainder target (modulo) is specified.
    438   1.1  christos              */
    439   1.7  christos             if (!AcpiGbl_DoDisassemblerOptimizations)
    440   1.1  christos             {
    441   1.7  christos                 if (AcpiDmIsValidTarget (Target))
    442   1.7  christos                 {
    443   1.7  christos                     Argument1->Common.OperatorSymbol = NULL;
    444   1.7  christos                     Op->Common.DisasmFlags |= ACPI_PARSEOP_LEGACY_ASL_ONLY;
    445   1.7  christos                     return (FALSE);
    446   1.7  christos                 }
    447   1.7  christos 
    448   1.7  christos                 Target->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
    449   1.7  christos                 Target = Target2;
    450   1.1  christos             }
    451   1.7  christos             else
    452   1.7  christos             {
    453   1.7  christos                 /*
    454   1.7  christos                  * Divide has an extra target operand (Remainder).
    455   1.7  christos                  * If both targets are specified, it cannot be converted
    456   1.7  christos                  * to a C-style operator.
    457   1.7  christos                  */
    458   1.7  christos                 if (AcpiDmIsValidTarget (Target) &&
    459   1.7  christos                     AcpiDmIsValidTarget (Target2))
    460   1.7  christos                 {
    461   1.7  christos                     Argument1->Common.OperatorSymbol = NULL;
    462   1.7  christos                     Op->Common.DisasmFlags |= ACPI_PARSEOP_LEGACY_ASL_ONLY;
    463   1.7  christos                     return (FALSE);
    464   1.7  christos                 }
    465   1.7  christos 
    466   1.7  christos                 if (AcpiDmIsValidTarget (Target)) /* Only first Target is valid (remainder) */
    467   1.7  christos                 {
    468   1.7  christos                     /* Convert the Divide to Modulo */
    469   1.1  christos 
    470   1.7  christos                     Op->Common.AmlOpcode = AML_MOD_OP;
    471   1.7  christos 
    472   1.7  christos                     Argument1->Common.OperatorSymbol = " % ";
    473   1.7  christos                     Target2->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
    474   1.7  christos                 }
    475   1.7  christos                 else /* Only second Target (quotient) is valid */
    476   1.7  christos                 {
    477   1.7  christos                     Target->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
    478   1.7  christos                     Target = Target2;
    479   1.7  christos                 }
    480   1.7  christos             }
    481   1.1  christos         }
    482   1.1  christos 
    483   1.1  christos         /* Parser should ensure there is at least a placeholder target */
    484   1.1  christos 
    485   1.1  christos         if (!Target)
    486   1.1  christos         {
    487   1.1  christos             return (FALSE);
    488   1.1  christos         }
    489   1.1  christos 
    490   1.1  christos         if (!AcpiDmIsValidTarget (Target))
    491   1.1  christos         {
    492   1.1  christos             /* Not a valid target (placeholder only, from parser) */
    493   1.1  christos             break;
    494   1.1  christos         }
    495   1.1  christos 
    496   1.1  christos         /*
    497   1.1  christos          * Promote the target up to the first child in the parse
    498   1.1  christos          * tree. This is done because the target will be output
    499   1.1  christos          * first, in the form:
    500   1.1  christos          *     <Target> = Operands...
    501   1.1  christos          */
    502   1.1  christos         AcpiDmPromoteTarget (Op, Target);
    503   1.1  christos 
    504   1.3  christos         /* Check operands for conversion to a "Compound Assignment" */
    505   1.3  christos 
    506   1.3  christos         switch (Op->Common.AmlOpcode)
    507   1.1  christos         {
    508   1.3  christos             /* Commutative operators */
    509   1.3  christos 
    510   1.3  christos         case AML_ADD_OP:
    511   1.3  christos         case AML_MULTIPLY_OP:
    512   1.3  christos         case AML_BIT_AND_OP:
    513   1.3  christos         case AML_BIT_OR_OP:
    514   1.3  christos         case AML_BIT_XOR_OP:
    515   1.3  christos             /*
    516   1.3  christos              * For the commutative operators, we can convert to a
    517   1.3  christos              * compound statement only if at least one (either) operand
    518   1.3  christos              * is the same as the target.
    519   1.3  christos              *
    520   1.3  christos              *      Add (A, B, A) --> A += B
    521   1.3  christos              *      Add (B, A, A) --> A += B
    522   1.3  christos              *      Add (B, C, A) --> A = (B + C)
    523   1.3  christos              */
    524   1.7  christos             if ((AcpiDmIsTargetAnOperand (Target, Argument1, TRUE)) ||
    525   1.7  christos                 (AcpiDmIsTargetAnOperand (Target, Argument2, TRUE)))
    526   1.3  christos             {
    527   1.3  christos                 Target->Common.OperatorSymbol =
    528   1.3  christos                     AcpiDmGetCompoundSymbol (Op->Common.AmlOpcode);
    529   1.1  christos 
    530   1.3  christos                 /* Convert operator to compound assignment */
    531   1.1  christos 
    532   1.5  christos                 Op->Common.DisasmFlags |= ACPI_PARSEOP_COMPOUND_ASSIGNMENT;
    533   1.7  christos                 Argument1->Common.OperatorSymbol = NULL;
    534   1.3  christos                 return (TRUE);
    535   1.3  christos             }
    536   1.3  christos             break;
    537   1.3  christos 
    538   1.3  christos             /* Non-commutative operators */
    539   1.3  christos 
    540   1.3  christos         case AML_SUBTRACT_OP:
    541   1.3  christos         case AML_DIVIDE_OP:
    542   1.3  christos         case AML_MOD_OP:
    543   1.3  christos         case AML_SHIFT_LEFT_OP:
    544   1.3  christos         case AML_SHIFT_RIGHT_OP:
    545   1.3  christos             /*
    546   1.3  christos              * For the non-commutative operators, we can convert to a
    547   1.3  christos              * compound statement only if the target is the same as the
    548   1.3  christos              * first operand.
    549   1.3  christos              *
    550   1.3  christos              *      Subtract (A, B, A) --> A -= B
    551   1.3  christos              *      Subtract (B, A, A) --> A = (B - A)
    552   1.3  christos              */
    553   1.7  christos             if ((AcpiDmIsTargetAnOperand (Target, Argument1, TRUE)))
    554   1.3  christos             {
    555   1.3  christos                 Target->Common.OperatorSymbol =
    556   1.3  christos                     AcpiDmGetCompoundSymbol (Op->Common.AmlOpcode);
    557   1.3  christos 
    558   1.3  christos                 /* Convert operator to compound assignment */
    559   1.3  christos 
    560   1.5  christos                 Op->Common.DisasmFlags |= ACPI_PARSEOP_COMPOUND_ASSIGNMENT;
    561   1.7  christos                 Argument1->Common.OperatorSymbol = NULL;
    562   1.3  christos                 return (TRUE);
    563   1.3  christos             }
    564   1.3  christos             break;
    565   1.3  christos 
    566   1.3  christos         default:
    567   1.3  christos             break;
    568   1.1  christos         }
    569   1.1  christos 
    570   1.1  christos         /*
    571   1.1  christos          * If we are within a C-style expression, emit an extra open
    572   1.1  christos          * paren. Implemented by examining the parent op.
    573   1.1  christos          */
    574   1.1  christos         switch (Op->Common.Parent->Common.AmlOpcode)
    575   1.1  christos         {
    576   1.1  christos         case AML_ADD_OP:
    577   1.1  christos         case AML_SUBTRACT_OP:
    578   1.1  christos         case AML_MULTIPLY_OP:
    579   1.1  christos         case AML_DIVIDE_OP:
    580   1.1  christos         case AML_MOD_OP:
    581   1.1  christos         case AML_SHIFT_LEFT_OP:
    582   1.1  christos         case AML_SHIFT_RIGHT_OP:
    583   1.1  christos         case AML_BIT_AND_OP:
    584   1.1  christos         case AML_BIT_OR_OP:
    585   1.1  christos         case AML_BIT_XOR_OP:
    586   1.8  christos         case AML_LOGICAL_AND_OP:
    587   1.8  christos         case AML_LOGICAL_EQUAL_OP:
    588   1.8  christos         case AML_LOGICAL_GREATER_OP:
    589   1.8  christos         case AML_LOGICAL_LESS_OP:
    590   1.8  christos         case AML_LOGICAL_OR_OP:
    591   1.1  christos 
    592   1.1  christos             Op->Common.DisasmFlags |= ACPI_PARSEOP_ASSIGNMENT;
    593   1.1  christos             AcpiOsPrintf ("(");
    594   1.1  christos             break;
    595   1.1  christos 
    596   1.1  christos         default:
    597   1.1  christos             break;
    598   1.1  christos         }
    599   1.1  christos 
    600   1.1  christos         /* Normal output for ASL/AML operators with a target operand */
    601   1.1  christos 
    602   1.1  christos         Target->Common.OperatorSymbol = " = (";
    603   1.1  christos         return (TRUE);
    604   1.1  christos 
    605   1.1  christos     /* Binary operators, no parens */
    606   1.1  christos 
    607   1.1  christos     case AML_DECREMENT_OP:
    608   1.1  christos     case AML_INCREMENT_OP:
    609   1.1  christos         return (TRUE);
    610   1.1  christos 
    611   1.1  christos     case AML_INDEX_OP:
    612   1.1  christos 
    613   1.1  christos         /* Target is optional, 3rd operand */
    614   1.1  christos 
    615   1.7  christos         Target = Argument2->Common.Next;
    616   1.1  christos         if (AcpiDmIsValidTarget (Target))
    617   1.1  christos         {
    618   1.1  christos             AcpiDmPromoteTarget (Op, Target);
    619   1.1  christos 
    620   1.1  christos             if (!Target->Common.OperatorSymbol)
    621   1.1  christos             {
    622   1.1  christos                 Target->Common.OperatorSymbol = " = ";
    623   1.1  christos             }
    624   1.1  christos         }
    625   1.1  christos         return (TRUE);
    626   1.1  christos 
    627   1.1  christos     case AML_STORE_OP:
    628   1.1  christos         /*
    629   1.7  christos          * For Store, the Target is the 2nd operand. We know the target
    630   1.7  christos          * is valid, because it is not optional.
    631   1.6  christos          *
    632   1.7  christos          * Ignore any optimizations/folding if flag is set.
    633   1.7  christos          * Used for iASL/disassembler test suite only.
    634   1.6  christos          */
    635   1.7  christos         if (AcpiDmIsOptimizationIgnored (Op, Argument1))
    636   1.6  christos         {
    637   1.7  christos             return (FALSE);
    638   1.6  christos         }
    639   1.6  christos 
    640   1.6  christos         /*
    641   1.7  christos          * Perform conversion.
    642   1.1  christos          * In the parse tree, simply swap the target with the
    643   1.1  christos          * source so that the target is processed first.
    644   1.1  christos          */
    645   1.7  christos         Target = Argument1->Common.Next;
    646   1.3  christos         if (!Target)
    647   1.3  christos         {
    648   1.3  christos             return (FALSE);
    649   1.3  christos         }
    650   1.3  christos 
    651   1.1  christos         AcpiDmPromoteTarget (Op, Target);
    652   1.1  christos         if (!Target->Common.OperatorSymbol)
    653   1.1  christos         {
    654   1.1  christos             Target->Common.OperatorSymbol = " = ";
    655   1.1  christos         }
    656   1.1  christos         return (TRUE);
    657   1.1  christos 
    658   1.1  christos     case AML_BIT_NOT_OP:
    659   1.1  christos 
    660   1.1  christos         /* Target is optional, 2nd operand */
    661   1.1  christos 
    662   1.7  christos         Target = Argument1->Common.Next;
    663   1.1  christos         if (!Target)
    664   1.1  christos         {
    665   1.1  christos             return (FALSE);
    666   1.1  christos         }
    667   1.1  christos 
    668   1.1  christos         if (AcpiDmIsValidTarget (Target))
    669   1.1  christos         {
    670   1.1  christos             /* Valid target, not a placeholder */
    671   1.1  christos 
    672   1.1  christos             AcpiDmPromoteTarget (Op, Target);
    673   1.1  christos             Target->Common.OperatorSymbol = " = ~";
    674   1.1  christos         }
    675   1.1  christos         else
    676   1.1  christos         {
    677   1.1  christos             /* No target. Emit this prefix operator immediately */
    678   1.1  christos 
    679   1.1  christos             AcpiOsPrintf ("~");
    680   1.1  christos         }
    681   1.1  christos         return (TRUE);
    682   1.1  christos 
    683   1.1  christos     default:
    684   1.1  christos         break;
    685   1.1  christos     }
    686   1.1  christos 
    687   1.7  christos     /* All other operators, emit an open paren */
    688   1.7  christos 
    689   1.7  christos     AcpiOsPrintf ("(");
    690   1.7  christos     return (TRUE);
    691   1.7  christos }
    692   1.7  christos 
    693   1.7  christos 
    694   1.7  christos /*******************************************************************************
    695   1.7  christos  *
    696   1.7  christos  * FUNCTION:    AcpiDmIsOptimizationIgnored
    697   1.7  christos  *
    698   1.7  christos  * PARAMETERS:  StoreOp             - Store operator parse object
    699   1.7  christos  *              StoreArgument       - Target associate with the Op
    700   1.7  christos  *
    701   1.7  christos  * RETURN:      TRUE if this Store operator should not be converted/removed.
    702   1.7  christos  *
    703   1.7  christos  * DESCRIPTION: The following function implements "Do not optimize if a
    704   1.7  christos  *              store is immediately followed by a math/bit operator that
    705   1.7  christos  *              has no target".
    706   1.7  christos  *
    707   1.7  christos  *              Function is ignored if DoDisassemblerOptimizations is TRUE.
    708   1.7  christos  *              This is the default, ignore this function.
    709   1.7  christos  *
    710   1.7  christos  *              Disables these types of optimizations, and simply emits
    711   1.7  christos  *              legacy ASL code:
    712   1.7  christos  *                  Store (Add (INT1, 4), INT2) --> Add (INT1, 4, INT2)
    713   1.7  christos  *                                              --> INT2 = INT1 + 4
    714   1.7  christos  *
    715   1.7  christos  *                  Store (Not (INT1), INT2)    --> Not (INT1, INT2)
    716   1.7  christos  *                                              --> INT2 = ~INT1
    717   1.7  christos  *
    718   1.7  christos  *              Used only for the ASL test suite. For the test suite, we
    719   1.7  christos  *              don't want to perform some optimizations to ensure binary
    720   1.7  christos  *              compatibility with the generation of the legacy ASL->AML.
    721   1.7  christos  *              In other words, for all test modules we want exactly:
    722   1.7  christos  *                  (ASL+ -> AML) == (ASL- -> AML)
    723   1.7  christos  *
    724   1.7  christos  ******************************************************************************/
    725   1.7  christos 
    726   1.7  christos static BOOLEAN
    727   1.7  christos AcpiDmIsOptimizationIgnored (
    728   1.7  christos     ACPI_PARSE_OBJECT       *StoreOp,
    729   1.7  christos     ACPI_PARSE_OBJECT       *StoreArgument)
    730   1.7  christos {
    731   1.7  christos     ACPI_PARSE_OBJECT       *Argument1;
    732   1.7  christos     ACPI_PARSE_OBJECT       *Argument2;
    733   1.7  christos     ACPI_PARSE_OBJECT       *Target;
    734   1.7  christos 
    735   1.7  christos 
    736   1.7  christos     /* No optimizations/folding for the typical case */
    737   1.7  christos 
    738   1.7  christos     if (AcpiGbl_DoDisassemblerOptimizations)
    739   1.7  christos     {
    740   1.7  christos         return (FALSE);
    741   1.7  christos     }
    742   1.7  christos 
    743   1.5  christos     /*
    744   1.7  christos      * Only a small subset of ASL/AML operators can be optimized.
    745   1.7  christos      * Can only optimize/fold if there is no target (or targets)
    746   1.7  christos      * specified for the operator. And of course, the operator
    747  1.12  christos      * is surrounded by a Store() operator.
    748   1.5  christos      */
    749   1.7  christos     switch (StoreArgument->Common.AmlOpcode)
    750   1.5  christos     {
    751   1.7  christos     case AML_ADD_OP:
    752   1.7  christos     case AML_SUBTRACT_OP:
    753   1.7  christos     case AML_MULTIPLY_OP:
    754   1.7  christos     case AML_MOD_OP:
    755   1.7  christos     case AML_SHIFT_LEFT_OP:
    756   1.7  christos     case AML_SHIFT_RIGHT_OP:
    757   1.7  christos     case AML_BIT_AND_OP:
    758   1.7  christos     case AML_BIT_OR_OP:
    759   1.7  christos     case AML_BIT_XOR_OP:
    760   1.7  christos     case AML_INDEX_OP:
    761   1.7  christos 
    762   1.7  christos         /* These operators have two arguments and one target */
    763   1.7  christos 
    764   1.7  christos         Argument1 = StoreArgument->Common.Value.Arg;
    765   1.7  christos         Argument2 = Argument1->Common.Next;
    766   1.7  christos         Target = Argument2->Common.Next;
    767   1.7  christos 
    768   1.7  christos         if (!AcpiDmIsValidTarget (Target))
    769   1.7  christos         {
    770   1.7  christos             StoreOp->Common.DisasmFlags |= ACPI_PARSEOP_LEGACY_ASL_ONLY;
    771   1.7  christos             return (TRUE);
    772   1.7  christos         }
    773   1.7  christos         break;
    774   1.7  christos 
    775   1.7  christos     case AML_DIVIDE_OP:
    776   1.7  christos 
    777   1.7  christos         /* This operator has two arguments and two targets */
    778   1.7  christos 
    779   1.7  christos         Argument1 = StoreArgument->Common.Value.Arg;
    780   1.7  christos         Argument2 = Argument1->Common.Next;
    781   1.7  christos         Target = Argument2->Common.Next;
    782   1.7  christos 
    783   1.7  christos         if (!AcpiDmIsValidTarget (Target) ||
    784   1.7  christos             !AcpiDmIsValidTarget (Target->Common.Next))
    785   1.7  christos         {
    786   1.7  christos             StoreOp->Common.DisasmFlags |= ACPI_PARSEOP_LEGACY_ASL_ONLY;
    787   1.7  christos             return (TRUE);
    788   1.7  christos         }
    789   1.7  christos         break;
    790   1.7  christos 
    791   1.7  christos     case AML_BIT_NOT_OP:
    792   1.7  christos 
    793   1.7  christos         /* This operator has one operand and one target */
    794   1.7  christos 
    795   1.7  christos         Argument1 = StoreArgument->Common.Value.Arg;
    796   1.7  christos         Target = Argument1->Common.Next;
    797   1.7  christos 
    798   1.7  christos         if (!AcpiDmIsValidTarget (Target))
    799   1.7  christos         {
    800   1.7  christos             StoreOp->Common.DisasmFlags |= ACPI_PARSEOP_LEGACY_ASL_ONLY;
    801   1.7  christos             return (TRUE);
    802   1.7  christos         }
    803   1.7  christos         break;
    804   1.7  christos 
    805   1.7  christos     default:
    806   1.7  christos         break;
    807   1.5  christos     }
    808   1.5  christos 
    809   1.7  christos     return (FALSE);
    810   1.1  christos }
    811   1.1  christos 
    812   1.1  christos 
    813   1.1  christos /*******************************************************************************
    814   1.1  christos  *
    815   1.1  christos  * FUNCTION:    AcpiDmCloseOperator
    816   1.1  christos  *
    817   1.1  christos  * PARAMETERS:  Op                  - Current parse object
    818   1.1  christos  *
    819   1.1  christos  * RETURN:      None
    820   1.1  christos  *
    821   1.1  christos  * DESCRIPTION: Closes an operator by adding a closing parentheses if and
    822   1.1  christos  *              when necessary. Called during ascending phase of the
    823   1.1  christos  *              parse tree walk.
    824   1.1  christos  *
    825   1.1  christos  ******************************************************************************/
    826   1.1  christos 
    827   1.1  christos void
    828   1.1  christos AcpiDmCloseOperator (
    829   1.1  christos     ACPI_PARSE_OBJECT       *Op)
    830   1.1  christos {
    831   1.6  christos 
    832   1.1  christos     /* Always emit paren if ASL+ disassembly disabled */
    833   1.1  christos 
    834   1.1  christos     if (!AcpiGbl_CstyleDisassembly)
    835   1.1  christos     {
    836   1.1  christos         AcpiOsPrintf (")");
    837   1.8  christos         ASL_CV_PRINT_ONE_COMMENT (Op, AML_COMMENT_END_NODE, NULL, 0);
    838   1.1  christos         return;
    839   1.1  christos     }
    840   1.1  christos 
    841   1.6  christos     if (Op->Common.DisasmFlags & ACPI_PARSEOP_LEGACY_ASL_ONLY)
    842   1.6  christos     {
    843   1.6  christos         AcpiOsPrintf (")");
    844   1.8  christos         ASL_CV_PRINT_ONE_COMMENT (Op, AML_COMMENT_END_NODE, NULL, 0);
    845   1.6  christos         return;
    846   1.6  christos     }
    847   1.6  christos 
    848   1.1  christos     /* Check if we need to add an additional closing paren */
    849   1.1  christos 
    850   1.1  christos     switch (Op->Common.AmlOpcode)
    851   1.1  christos     {
    852   1.1  christos     case AML_ADD_OP:
    853   1.1  christos     case AML_SUBTRACT_OP:
    854   1.1  christos     case AML_MULTIPLY_OP:
    855   1.1  christos     case AML_DIVIDE_OP:
    856   1.1  christos     case AML_MOD_OP:
    857   1.1  christos     case AML_SHIFT_LEFT_OP:
    858   1.1  christos     case AML_SHIFT_RIGHT_OP:
    859   1.1  christos     case AML_BIT_AND_OP:
    860   1.1  christos     case AML_BIT_OR_OP:
    861   1.1  christos     case AML_BIT_XOR_OP:
    862   1.8  christos     case AML_LOGICAL_AND_OP:
    863   1.8  christos     case AML_LOGICAL_EQUAL_OP:
    864   1.8  christos     case AML_LOGICAL_GREATER_OP:
    865   1.8  christos     case AML_LOGICAL_LESS_OP:
    866   1.8  christos     case AML_LOGICAL_OR_OP:
    867   1.1  christos 
    868   1.1  christos         /* Emit paren only if this is not a compound assignment */
    869   1.1  christos 
    870   1.5  christos         if (Op->Common.DisasmFlags & ACPI_PARSEOP_COMPOUND_ASSIGNMENT)
    871   1.1  christos         {
    872   1.8  christos             ASL_CV_PRINT_ONE_COMMENT (Op, AML_COMMENT_END_NODE, NULL, 0);
    873   1.1  christos             return;
    874   1.1  christos         }
    875   1.1  christos 
    876   1.1  christos         /* Emit extra close paren for assignment within an expression */
    877   1.1  christos 
    878   1.1  christos         if (Op->Common.DisasmFlags & ACPI_PARSEOP_ASSIGNMENT)
    879   1.1  christos         {
    880   1.1  christos             AcpiOsPrintf (")");
    881   1.1  christos         }
    882   1.1  christos         break;
    883   1.1  christos 
    884   1.4  christos     case AML_INDEX_OP:
    885   1.4  christos 
    886   1.4  christos         /* This is case for unsupported Index() source constants */
    887   1.4  christos 
    888   1.4  christos         if (Op->Common.DisasmFlags & ACPI_PARSEOP_CLOSING_PAREN)
    889   1.4  christos         {
    890   1.4  christos             AcpiOsPrintf (")");
    891   1.4  christos         }
    892   1.8  christos         ASL_CV_PRINT_ONE_COMMENT (Op, AML_COMMENT_END_NODE, NULL, 0);
    893   1.4  christos         return;
    894   1.1  christos 
    895   1.1  christos     /* No need for parens for these */
    896   1.1  christos 
    897   1.1  christos     case AML_DECREMENT_OP:
    898   1.1  christos     case AML_INCREMENT_OP:
    899   1.8  christos     case AML_LOGICAL_NOT_OP:
    900   1.1  christos     case AML_BIT_NOT_OP:
    901   1.1  christos     case AML_STORE_OP:
    902   1.8  christos         ASL_CV_PRINT_ONE_COMMENT (Op, AML_COMMENT_END_NODE, NULL, 0);
    903   1.1  christos         return;
    904   1.1  christos 
    905   1.1  christos     default:
    906   1.1  christos 
    907   1.1  christos         /* Always emit paren for non-ASL+ operators */
    908   1.1  christos         break;
    909   1.1  christos     }
    910   1.1  christos 
    911   1.1  christos     AcpiOsPrintf (")");
    912   1.8  christos     ASL_CV_PRINT_ONE_COMMENT (Op, AML_COMMENT_END_NODE, NULL, 0);
    913   1.8  christos 
    914   1.8  christos     return;
    915   1.1  christos }
    916   1.1  christos 
    917   1.1  christos 
    918   1.1  christos /*******************************************************************************
    919   1.1  christos  *
    920   1.1  christos  * FUNCTION:    AcpiDmGetCompoundSymbol
    921   1.1  christos  *
    922   1.1  christos  * PARAMETERS:  AslOpcode
    923   1.1  christos  *
    924   1.1  christos  * RETURN:      String containing the compound assignment symbol
    925   1.1  christos  *
    926   1.1  christos  * DESCRIPTION: Detect opcodes that can be converted to compound assignment,
    927   1.1  christos  *              return the appropriate operator string.
    928   1.1  christos  *
    929   1.1  christos  ******************************************************************************/
    930   1.1  christos 
    931   1.2  christos static const char *
    932   1.1  christos AcpiDmGetCompoundSymbol (
    933   1.1  christos    UINT16                   AmlOpcode)
    934   1.1  christos {
    935   1.2  christos     const char               *Symbol;
    936   1.1  christos 
    937   1.1  christos 
    938   1.1  christos     switch (AmlOpcode)
    939   1.1  christos     {
    940   1.1  christos     case AML_ADD_OP:
    941   1.1  christos         Symbol = " += ";
    942   1.1  christos         break;
    943   1.1  christos 
    944   1.1  christos     case AML_SUBTRACT_OP:
    945   1.1  christos         Symbol = " -= ";
    946   1.1  christos         break;
    947   1.1  christos 
    948   1.1  christos     case AML_MULTIPLY_OP:
    949   1.1  christos         Symbol = " *= ";
    950   1.1  christos         break;
    951   1.1  christos 
    952   1.1  christos     case AML_DIVIDE_OP:
    953   1.1  christos         Symbol = " /= ";
    954   1.1  christos         break;
    955   1.1  christos 
    956   1.1  christos     case AML_MOD_OP:
    957   1.1  christos         Symbol = " %= ";
    958   1.1  christos         break;
    959   1.1  christos 
    960   1.1  christos     case AML_SHIFT_LEFT_OP:
    961   1.1  christos         Symbol = " <<= ";
    962   1.1  christos         break;
    963   1.1  christos 
    964   1.1  christos     case AML_SHIFT_RIGHT_OP:
    965   1.1  christos         Symbol = " >>= ";
    966   1.1  christos         break;
    967   1.1  christos 
    968   1.1  christos     case AML_BIT_AND_OP:
    969   1.1  christos         Symbol = " &= ";
    970   1.1  christos         break;
    971   1.1  christos 
    972   1.1  christos     case AML_BIT_OR_OP:
    973   1.1  christos         Symbol = " |= ";
    974   1.1  christos         break;
    975   1.1  christos 
    976   1.1  christos     case AML_BIT_XOR_OP:
    977   1.1  christos         Symbol = " ^= ";
    978   1.1  christos         break;
    979   1.1  christos 
    980   1.1  christos     default:
    981   1.1  christos 
    982   1.1  christos         /* No operator string for all other opcodes */
    983   1.4  christos 
    984   1.1  christos         return (NULL);
    985   1.1  christos     }
    986   1.1  christos 
    987   1.1  christos     return (Symbol);
    988   1.1  christos }
    989   1.1  christos 
    990   1.1  christos 
    991   1.1  christos /*******************************************************************************
    992   1.1  christos  *
    993   1.1  christos  * FUNCTION:    AcpiDmPromoteTarget
    994   1.1  christos  *
    995   1.1  christos  * PARAMETERS:  Op                  - Operator parse object
    996   1.1  christos  *              Target              - Target associate with the Op
    997   1.1  christos  *
    998   1.1  christos  * RETURN:      None
    999   1.1  christos  *
   1000   1.1  christos  * DESCRIPTION: Transform the parse tree by moving the target up to the first
   1001   1.1  christos  *              child of the Op.
   1002   1.1  christos  *
   1003   1.1  christos  ******************************************************************************/
   1004   1.1  christos 
   1005   1.1  christos static void
   1006   1.1  christos AcpiDmPromoteTarget (
   1007   1.1  christos     ACPI_PARSE_OBJECT       *Op,
   1008   1.1  christos     ACPI_PARSE_OBJECT       *Target)
   1009   1.1  christos {
   1010   1.1  christos     ACPI_PARSE_OBJECT       *Child;
   1011   1.1  christos 
   1012   1.1  christos 
   1013   1.1  christos     /* Link target directly to the Op as first child */
   1014   1.1  christos 
   1015   1.1  christos     Child = Op->Common.Value.Arg;
   1016   1.1  christos     Op->Common.Value.Arg = Target;
   1017   1.1  christos     Target->Common.Next = Child;
   1018   1.1  christos 
   1019   1.1  christos     /* Find the last peer, it is linked to the target. Unlink it. */
   1020   1.1  christos 
   1021   1.1  christos     while (Child->Common.Next != Target)
   1022   1.1  christos     {
   1023   1.1  christos         Child = Child->Common.Next;
   1024   1.1  christos     }
   1025   1.1  christos 
   1026   1.1  christos     Child->Common.Next = NULL;
   1027   1.1  christos }
   1028   1.1  christos 
   1029   1.1  christos 
   1030   1.1  christos /*******************************************************************************
   1031   1.1  christos  *
   1032   1.1  christos  * FUNCTION:    AcpiDmIsValidTarget
   1033   1.1  christos  *
   1034   1.1  christos  * PARAMETERS:  Target              - Target Op from the parse tree
   1035   1.1  christos  *
   1036   1.1  christos  * RETURN:      TRUE if the Target is real. FALSE if it is just a placeholder
   1037   1.1  christos  *              Op that was inserted by the parser.
   1038   1.1  christos  *
   1039   1.1  christos  * DESCRIPTION: Determine if a Target Op is a placeholder Op or a real Target.
   1040   1.1  christos  *              In other words, determine if the optional target is used or
   1041   1.3  christos  *              not. Note: If Target is NULL, something is seriously wrong,
   1042   1.3  christos  *              probably with the parse tree.
   1043   1.1  christos  *
   1044   1.1  christos  ******************************************************************************/
   1045   1.1  christos 
   1046   1.1  christos static BOOLEAN
   1047   1.1  christos AcpiDmIsValidTarget (
   1048   1.1  christos     ACPI_PARSE_OBJECT       *Target)
   1049   1.1  christos {
   1050   1.1  christos 
   1051   1.3  christos     if (!Target)
   1052   1.3  christos     {
   1053   1.3  christos         return (FALSE);
   1054   1.3  christos     }
   1055   1.3  christos 
   1056   1.1  christos     if ((Target->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
   1057   1.1  christos         (Target->Common.Value.Arg == NULL))
   1058   1.1  christos     {
   1059   1.1  christos         return (FALSE);
   1060   1.1  christos     }
   1061   1.1  christos 
   1062   1.1  christos     return (TRUE);
   1063   1.1  christos }
   1064   1.1  christos 
   1065   1.1  christos 
   1066   1.1  christos /*******************************************************************************
   1067   1.1  christos  *
   1068   1.1  christos  * FUNCTION:    AcpiDmIsTargetAnOperand
   1069   1.1  christos  *
   1070   1.1  christos  * PARAMETERS:  Target              - Target associated with the expression
   1071   1.1  christos  *              Operand             - An operand associated with expression
   1072   1.1  christos  *
   1073   1.1  christos  * RETURN:      TRUE if expression can be converted to a compound assignment.
   1074   1.1  christos  *              FALSE otherwise.
   1075   1.1  christos  *
   1076   1.1  christos  * DESCRIPTION: Determine if the Target duplicates the operand, in order to
   1077   1.1  christos  *              detect if the expression can be converted to a compound
   1078  1.10  christos  *              assignment. (+=, *=, etc.)
   1079   1.1  christos  *
   1080   1.1  christos  ******************************************************************************/
   1081   1.1  christos 
   1082   1.1  christos static BOOLEAN
   1083   1.1  christos AcpiDmIsTargetAnOperand (
   1084   1.1  christos     ACPI_PARSE_OBJECT       *Target,
   1085   1.1  christos     ACPI_PARSE_OBJECT       *Operand,
   1086   1.1  christos     BOOLEAN                 TopLevel)
   1087   1.1  christos {
   1088   1.1  christos     const ACPI_OPCODE_INFO  *OpInfo;
   1089   1.1  christos     BOOLEAN                 Same;
   1090   1.1  christos 
   1091   1.1  christos 
   1092   1.1  christos     /*
   1093   1.1  christos      * Opcodes must match. Note: ignoring the difference between nameseg
   1094   1.1  christos      * and namepath for now. May be needed later.
   1095   1.1  christos      */
   1096   1.1  christos     if (Target->Common.AmlOpcode != Operand->Common.AmlOpcode)
   1097   1.1  christos     {
   1098   1.1  christos         return (FALSE);
   1099   1.1  christos     }
   1100   1.1  christos 
   1101   1.1  christos     /* Nodes should match, even if they are NULL */
   1102   1.1  christos 
   1103   1.1  christos     if (Target->Common.Node != Operand->Common.Node)
   1104   1.1  christos     {
   1105   1.1  christos         return (FALSE);
   1106   1.1  christos     }
   1107   1.1  christos 
   1108   1.1  christos     /* Determine if a child exists */
   1109   1.1  christos 
   1110   1.1  christos     OpInfo = AcpiPsGetOpcodeInfo (Operand->Common.AmlOpcode);
   1111   1.1  christos     if (OpInfo->Flags & AML_HAS_ARGS)
   1112   1.1  christos     {
   1113   1.1  christos         Same = AcpiDmIsTargetAnOperand (Target->Common.Value.Arg,
   1114   1.1  christos             Operand->Common.Value.Arg, FALSE);
   1115   1.1  christos         if (!Same)
   1116   1.1  christos         {
   1117   1.1  christos             return (FALSE);
   1118   1.1  christos         }
   1119   1.1  christos     }
   1120   1.1  christos 
   1121   1.1  christos     /* Check the next peer, as long as we are not at the top level */
   1122   1.1  christos 
   1123   1.1  christos     if ((!TopLevel) &&
   1124   1.1  christos          Target->Common.Next)
   1125   1.1  christos     {
   1126   1.1  christos         Same = AcpiDmIsTargetAnOperand (Target->Common.Next,
   1127   1.1  christos             Operand->Common.Next, FALSE);
   1128   1.1  christos         if (!Same)
   1129   1.1  christos         {
   1130   1.1  christos             return (FALSE);
   1131   1.1  christos         }
   1132   1.1  christos     }
   1133   1.1  christos 
   1134  1.10  christos     /* Suppress the duplicate operand at the top-level */
   1135   1.1  christos 
   1136   1.1  christos     if (TopLevel)
   1137   1.1  christos     {
   1138   1.1  christos         Operand->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
   1139   1.1  christos     }
   1140   1.1  christos     return (TRUE);
   1141   1.1  christos }
   1142