Home | History | Annotate | Line # | Download | only in compiler
aslfold.c revision 1.1.1.4.2.4
      1          1.1    jruoho /******************************************************************************
      2          1.1    jruoho  *
      3          1.1    jruoho  * Module Name: aslfold - Constant folding
      4          1.1    jruoho  *
      5          1.1    jruoho  *****************************************************************************/
      6          1.1    jruoho 
      7      1.1.1.2    jruoho /*
      8  1.1.1.4.2.3     skrll  * Copyright (C) 2000 - 2016, Intel Corp.
      9          1.1    jruoho  * All rights reserved.
     10          1.1    jruoho  *
     11      1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12      1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13      1.1.1.2    jruoho  * are met:
     14      1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15      1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16      1.1.1.2    jruoho  *    without modification.
     17      1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18      1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19      1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20      1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21      1.1.1.2    jruoho  *    binary redistribution.
     22      1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23      1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24      1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25      1.1.1.2    jruoho  *
     26      1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27      1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28      1.1.1.2    jruoho  * Software Foundation.
     29      1.1.1.2    jruoho  *
     30      1.1.1.2    jruoho  * NO WARRANTY
     31      1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32      1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33      1.1.1.2    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34      1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35      1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36      1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37      1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38      1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39      1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40      1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41      1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42      1.1.1.2    jruoho  */
     43          1.1    jruoho 
     44          1.1    jruoho #include "aslcompiler.h"
     45          1.1    jruoho #include "aslcompiler.y.h"
     46          1.1    jruoho #include "amlcode.h"
     47          1.1    jruoho 
     48          1.1    jruoho #include "acdispat.h"
     49          1.1    jruoho #include "acparser.h"
     50          1.1    jruoho 
     51          1.1    jruoho #define _COMPONENT          ACPI_COMPILER
     52          1.1    jruoho         ACPI_MODULE_NAME    ("aslfold")
     53          1.1    jruoho 
     54          1.1    jruoho /* Local prototypes */
     55          1.1    jruoho 
     56          1.1    jruoho static ACPI_STATUS
     57          1.1    jruoho OpcAmlEvaluationWalk1 (
     58          1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
     59          1.1    jruoho     UINT32                  Level,
     60          1.1    jruoho     void                    *Context);
     61          1.1    jruoho 
     62          1.1    jruoho static ACPI_STATUS
     63          1.1    jruoho OpcAmlEvaluationWalk2 (
     64          1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
     65          1.1    jruoho     UINT32                  Level,
     66          1.1    jruoho     void                    *Context);
     67          1.1    jruoho 
     68          1.1    jruoho static ACPI_STATUS
     69          1.1    jruoho OpcAmlCheckForConstant (
     70          1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
     71          1.1    jruoho     UINT32                  Level,
     72          1.1    jruoho     void                    *Context);
     73          1.1    jruoho 
     74      1.1.1.3  christos static void
     75      1.1.1.3  christos OpcUpdateIntegerNode (
     76      1.1.1.3  christos     ACPI_PARSE_OBJECT       *Op,
     77      1.1.1.3  christos     UINT64                  Value);
     78      1.1.1.3  christos 
     79  1.1.1.4.2.1     skrll static ACPI_STATUS
     80  1.1.1.4.2.1     skrll TrTransformToStoreOp (
     81  1.1.1.4.2.1     skrll     ACPI_PARSE_OBJECT       *Op,
     82  1.1.1.4.2.1     skrll     ACPI_WALK_STATE         *WalkState);
     83  1.1.1.4.2.1     skrll 
     84  1.1.1.4.2.1     skrll static ACPI_STATUS
     85  1.1.1.4.2.1     skrll TrSimpleConstantReduction (
     86  1.1.1.4.2.1     skrll     ACPI_PARSE_OBJECT       *Op,
     87  1.1.1.4.2.1     skrll     ACPI_WALK_STATE         *WalkState);
     88  1.1.1.4.2.1     skrll 
     89  1.1.1.4.2.1     skrll static void
     90  1.1.1.4.2.1     skrll TrInstallReducedConstant (
     91  1.1.1.4.2.1     skrll     ACPI_PARSE_OBJECT       *Op,
     92  1.1.1.4.2.1     skrll     ACPI_OPERAND_OBJECT     *ObjDesc);
     93  1.1.1.4.2.1     skrll 
     94          1.1    jruoho 
     95          1.1    jruoho /*******************************************************************************
     96          1.1    jruoho  *
     97  1.1.1.4.2.1     skrll  * FUNCTION:    OpcAmlConstantWalk
     98          1.1    jruoho  *
     99          1.1    jruoho  * PARAMETERS:  ASL_WALK_CALLBACK
    100          1.1    jruoho  *
    101          1.1    jruoho  * RETURN:      Status
    102          1.1    jruoho  *
    103  1.1.1.4.2.3     skrll  * DESCRIPTION: Reduce an Op and its subtree to a constant if possible.
    104  1.1.1.4.2.4     skrll  *              Called during ascent of the parse tree.
    105          1.1    jruoho  *
    106          1.1    jruoho  ******************************************************************************/
    107          1.1    jruoho 
    108  1.1.1.4.2.1     skrll ACPI_STATUS
    109  1.1.1.4.2.1     skrll OpcAmlConstantWalk (
    110          1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
    111          1.1    jruoho     UINT32                  Level,
    112          1.1    jruoho     void                    *Context)
    113          1.1    jruoho {
    114  1.1.1.4.2.1     skrll     ACPI_WALK_STATE         *WalkState;
    115  1.1.1.4.2.1     skrll     ACPI_STATUS             Status = AE_OK;
    116          1.1    jruoho 
    117          1.1    jruoho 
    118  1.1.1.4.2.1     skrll     if (Op->Asl.CompileFlags == 0)
    119  1.1.1.4.2.1     skrll     {
    120  1.1.1.4.2.1     skrll         return (AE_OK);
    121  1.1.1.4.2.1     skrll     }
    122          1.1    jruoho 
    123  1.1.1.4.2.1     skrll     /*
    124  1.1.1.4.2.1     skrll      * Only interested in subtrees that could possibly contain
    125  1.1.1.4.2.1     skrll      * expressions that can be evaluated at this time
    126  1.1.1.4.2.1     skrll      */
    127  1.1.1.4.2.1     skrll     if ((!(Op->Asl.CompileFlags & NODE_COMPILE_TIME_CONST)) ||
    128  1.1.1.4.2.1     skrll           (Op->Asl.CompileFlags & NODE_IS_TARGET))
    129          1.1    jruoho     {
    130  1.1.1.4.2.1     skrll         return (AE_OK);
    131          1.1    jruoho     }
    132          1.1    jruoho 
    133  1.1.1.4.2.1     skrll     /* Create a new walk state */
    134          1.1    jruoho 
    135  1.1.1.4.2.1     skrll     WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
    136  1.1.1.4.2.1     skrll     if (!WalkState)
    137          1.1    jruoho     {
    138  1.1.1.4.2.1     skrll         return (AE_NO_MEMORY);
    139          1.1    jruoho     }
    140          1.1    jruoho 
    141  1.1.1.4.2.1     skrll     WalkState->NextOp = NULL;
    142  1.1.1.4.2.1     skrll     WalkState->Params = NULL;
    143          1.1    jruoho 
    144  1.1.1.4.2.1     skrll     /*
    145  1.1.1.4.2.1     skrll      * Examine the entire subtree -- all nodes must be constants
    146  1.1.1.4.2.1     skrll      * or type 3/4/5 opcodes
    147  1.1.1.4.2.1     skrll      */
    148  1.1.1.4.2.1     skrll     Status = TrWalkParseTree (Op, ASL_WALK_VISIT_DOWNWARD,
    149  1.1.1.4.2.1     skrll         OpcAmlCheckForConstant, NULL, WalkState);
    150          1.1    jruoho 
    151  1.1.1.4.2.1     skrll     /*
    152  1.1.1.4.2.1     skrll      * Did we find an entire subtree that contains all constants
    153  1.1.1.4.2.1     skrll      * and type 3/4/5 opcodes?
    154  1.1.1.4.2.1     skrll      */
    155  1.1.1.4.2.1     skrll     switch (Status)
    156  1.1.1.4.2.1     skrll     {
    157  1.1.1.4.2.1     skrll     case AE_OK:
    158          1.1    jruoho 
    159  1.1.1.4.2.1     skrll         /* Simple case, like Add(3,4) -> 7 */
    160          1.1    jruoho 
    161  1.1.1.4.2.1     skrll         Status = TrSimpleConstantReduction (Op, WalkState);
    162  1.1.1.4.2.1     skrll         break;
    163          1.1    jruoho 
    164  1.1.1.4.2.1     skrll     case AE_CTRL_RETURN_VALUE:
    165          1.1    jruoho 
    166  1.1.1.4.2.1     skrll         /* More complex case, like Add(3,4,Local0) -> Store(7,Local0) */
    167          1.1    jruoho 
    168  1.1.1.4.2.1     skrll         Status = TrTransformToStoreOp (Op, WalkState);
    169  1.1.1.4.2.1     skrll         break;
    170          1.1    jruoho 
    171  1.1.1.4.2.1     skrll     case AE_TYPE:
    172  1.1.1.4.2.1     skrll 
    173  1.1.1.4.2.1     skrll         AcpiDsDeleteWalkState (WalkState);
    174  1.1.1.4.2.1     skrll         return (AE_OK);
    175  1.1.1.4.2.1     skrll 
    176  1.1.1.4.2.1     skrll     default:
    177  1.1.1.4.2.1     skrll         AcpiDsDeleteWalkState (WalkState);
    178  1.1.1.4.2.1     skrll         break;
    179  1.1.1.4.2.1     skrll     }
    180          1.1    jruoho 
    181          1.1    jruoho     if (ACPI_FAILURE (Status))
    182          1.1    jruoho     {
    183  1.1.1.4.2.1     skrll         DbgPrint (ASL_PARSE_OUTPUT, "Cannot resolve, %s\n",
    184  1.1.1.4.2.1     skrll             AcpiFormatException (Status));
    185  1.1.1.4.2.1     skrll 
    186  1.1.1.4.2.1     skrll         /* We could not resolve the subtree for some reason */
    187  1.1.1.4.2.1     skrll 
    188  1.1.1.4.2.1     skrll         AslError (ASL_ERROR, ASL_MSG_CONSTANT_EVALUATION, Op,
    189  1.1.1.4.2.1     skrll             (char *) AcpiFormatException (Status));
    190  1.1.1.4.2.1     skrll 
    191  1.1.1.4.2.1     skrll         /* Set the subtree value to ZERO anyway. Eliminates further errors */
    192  1.1.1.4.2.1     skrll 
    193  1.1.1.4.2.1     skrll         OpcUpdateIntegerNode (Op, 0);
    194          1.1    jruoho     }
    195          1.1    jruoho 
    196  1.1.1.4.2.4     skrll     return (AE_OK);
    197          1.1    jruoho }
    198          1.1    jruoho 
    199          1.1    jruoho 
    200          1.1    jruoho /*******************************************************************************
    201          1.1    jruoho  *
    202          1.1    jruoho  * FUNCTION:    OpcAmlCheckForConstant
    203          1.1    jruoho  *
    204          1.1    jruoho  * PARAMETERS:  ASL_WALK_CALLBACK
    205          1.1    jruoho  *
    206          1.1    jruoho  * RETURN:      Status
    207          1.1    jruoho  *
    208  1.1.1.4.2.3     skrll  * DESCRIPTION: Check one Op for a reducible type 3/4/5 AML opcode.
    209  1.1.1.4.2.4     skrll  *              This is performed via an upward walk of the parse subtree.
    210          1.1    jruoho  *
    211          1.1    jruoho  ******************************************************************************/
    212          1.1    jruoho 
    213          1.1    jruoho static ACPI_STATUS
    214          1.1    jruoho OpcAmlCheckForConstant (
    215          1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
    216          1.1    jruoho     UINT32                  Level,
    217          1.1    jruoho     void                    *Context)
    218          1.1    jruoho {
    219          1.1    jruoho     ACPI_WALK_STATE         *WalkState = Context;
    220  1.1.1.4.2.1     skrll     ACPI_STATUS             Status = AE_OK;
    221  1.1.1.4.2.3     skrll     ACPI_PARSE_OBJECT       *NextOp;
    222  1.1.1.4.2.3     skrll     const ACPI_OPCODE_INFO  *OpInfo;
    223          1.1    jruoho 
    224          1.1    jruoho 
    225          1.1    jruoho     WalkState->Op = Op;
    226          1.1    jruoho     WalkState->Opcode = Op->Common.AmlOpcode;
    227          1.1    jruoho     WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
    228          1.1    jruoho 
    229          1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT, "[%.4d] Opcode: %12.12s ",
    230  1.1.1.4.2.1     skrll         Op->Asl.LogicalLineNumber, Op->Asl.ParseOpName);
    231  1.1.1.4.2.1     skrll 
    232  1.1.1.4.2.1     skrll     /*
    233      1.1.1.3  christos      * These opcodes do not appear in the OpcodeInfo table, but
    234      1.1.1.3  christos      * they represent constants, so abort the constant walk now.
    235      1.1.1.3  christos      */
    236      1.1.1.3  christos     if ((WalkState->Opcode == AML_RAW_DATA_BYTE) ||
    237      1.1.1.3  christos         (WalkState->Opcode == AML_RAW_DATA_WORD) ||
    238      1.1.1.3  christos         (WalkState->Opcode == AML_RAW_DATA_DWORD) ||
    239      1.1.1.3  christos         (WalkState->Opcode == AML_RAW_DATA_QWORD))
    240      1.1.1.3  christos     {
    241  1.1.1.4.2.1     skrll         DbgPrint (ASL_PARSE_OUTPUT, "RAW DATA");
    242  1.1.1.4.2.1     skrll         Status = AE_TYPE;
    243  1.1.1.4.2.1     skrll         goto CleanupAndExit;
    244      1.1.1.3  christos     }
    245      1.1.1.3  christos 
    246  1.1.1.4.2.3     skrll     /*
    247  1.1.1.4.2.3     skrll      * Search upwards for a possible Name() operator. This is done
    248  1.1.1.4.2.3     skrll      * because a type 3/4/5 opcode within a Name() expression
    249  1.1.1.4.2.3     skrll      * MUST be reduced to a simple constant.
    250  1.1.1.4.2.3     skrll      */
    251  1.1.1.4.2.3     skrll     NextOp = Op->Asl.Parent;
    252  1.1.1.4.2.3     skrll     while (NextOp)
    253  1.1.1.4.2.3     skrll     {
    254  1.1.1.4.2.3     skrll         /* Finished if we find a Name() opcode */
    255  1.1.1.4.2.3     skrll 
    256  1.1.1.4.2.3     skrll         if (NextOp->Asl.AmlOpcode == AML_NAME_OP)
    257  1.1.1.4.2.3     skrll         {
    258  1.1.1.4.2.3     skrll             break;
    259  1.1.1.4.2.3     skrll         }
    260  1.1.1.4.2.3     skrll 
    261  1.1.1.4.2.3     skrll         /*
    262  1.1.1.4.2.3     skrll          * Any "deferred" opcodes contain one or more TermArg parameters,
    263  1.1.1.4.2.3     skrll          * and thus are not required to be folded to constants at compile
    264  1.1.1.4.2.3     skrll          * time. This affects things like Buffer() and Package() objects.
    265  1.1.1.4.2.3     skrll          * We just ignore them here. However, any sub-expressions can and
    266  1.1.1.4.2.3     skrll          * will still be typechecked. Note: These are called the
    267  1.1.1.4.2.3     skrll          * "deferred" opcodes in the AML interpreter.
    268  1.1.1.4.2.3     skrll          */
    269  1.1.1.4.2.3     skrll         OpInfo = AcpiPsGetOpcodeInfo (NextOp->Common.AmlOpcode);
    270  1.1.1.4.2.3     skrll         if (OpInfo->Flags & AML_DEFER)
    271  1.1.1.4.2.3     skrll         {
    272  1.1.1.4.2.3     skrll             NextOp = NULL;
    273  1.1.1.4.2.3     skrll             break;
    274  1.1.1.4.2.3     skrll         }
    275  1.1.1.4.2.3     skrll 
    276  1.1.1.4.2.3     skrll         NextOp = NextOp->Asl.Parent;
    277  1.1.1.4.2.3     skrll     }
    278  1.1.1.4.2.3     skrll 
    279  1.1.1.4.2.1     skrll     /* Type 3/4/5 opcodes have the AML_CONSTANT flag set */
    280  1.1.1.4.2.1     skrll 
    281          1.1    jruoho     if (!(WalkState->OpInfo->Flags & AML_CONSTANT))
    282          1.1    jruoho     {
    283  1.1.1.4.2.3     skrll         /*
    284  1.1.1.4.2.3     skrll          * From the ACPI specification:
    285  1.1.1.4.2.3     skrll          *
    286  1.1.1.4.2.3     skrll          * "The Type 3/4/5 opcodes return a value and can be used in an
    287  1.1.1.4.2.3     skrll          * expression that evaluates to a constant. These opcodes may be
    288  1.1.1.4.2.3     skrll          * evaluated at ASL compile-time. To ensure that these opcodes
    289  1.1.1.4.2.3     skrll          * will evaluate to a constant, the following rules apply: The
    290  1.1.1.4.2.3     skrll          * term cannot have a destination (target) operand, and must have
    291  1.1.1.4.2.3     skrll          * either a Type3Opcode, Type4Opcode, Type5Opcode, ConstExprTerm,
    292  1.1.1.4.2.3     skrll          * Integer, BufferTerm, Package, or String for all arguments."
    293  1.1.1.4.2.3     skrll          */
    294  1.1.1.4.2.3     skrll 
    295  1.1.1.4.2.3     skrll         /*
    296  1.1.1.4.2.3     skrll          * The value (second) operand for the Name() operator MUST
    297  1.1.1.4.2.3     skrll          * reduce to a single constant, as per the ACPI specification
    298  1.1.1.4.2.3     skrll          * (the operand is a DataObject). This also implies that there
    299  1.1.1.4.2.3     skrll          * can be no target operand. Name() is the only ASL operator
    300  1.1.1.4.2.3     skrll          * with a "DataObject" as an operand and is thus special-
    301  1.1.1.4.2.3     skrll          * cased here.
    302  1.1.1.4.2.3     skrll          */
    303  1.1.1.4.2.3     skrll         if (NextOp) /* Inspect a Name() operator */
    304  1.1.1.4.2.3     skrll         {
    305  1.1.1.4.2.3     skrll             /* Error if there is a target operand */
    306  1.1.1.4.2.3     skrll 
    307  1.1.1.4.2.3     skrll             if (Op->Asl.CompileFlags & NODE_IS_TARGET)
    308  1.1.1.4.2.3     skrll             {
    309  1.1.1.4.2.3     skrll                 AslError (ASL_ERROR, ASL_MSG_INVALID_TARGET, Op, NULL);
    310  1.1.1.4.2.3     skrll                 Status = AE_TYPE;
    311  1.1.1.4.2.3     skrll             }
    312  1.1.1.4.2.3     skrll 
    313  1.1.1.4.2.3     skrll             /* Error if expression cannot be reduced (folded) */
    314  1.1.1.4.2.3     skrll 
    315  1.1.1.4.2.3     skrll             if (!(NextOp->Asl.CompileFlags & NODE_COULD_NOT_REDUCE))
    316  1.1.1.4.2.3     skrll             {
    317  1.1.1.4.2.3     skrll                 /* Ensure only one error message per statement */
    318  1.1.1.4.2.3     skrll 
    319  1.1.1.4.2.3     skrll                 NextOp->Asl.CompileFlags |= NODE_COULD_NOT_REDUCE;
    320  1.1.1.4.2.3     skrll                 DbgPrint (ASL_PARSE_OUTPUT,
    321  1.1.1.4.2.3     skrll                     "**** Could not reduce operands for NAME opcode ****\n");
    322  1.1.1.4.2.3     skrll 
    323  1.1.1.4.2.3     skrll                 AslError (ASL_ERROR, ASL_MSG_CONSTANT_REQUIRED, Op,
    324  1.1.1.4.2.3     skrll                     "Constant is required for Name operator");
    325  1.1.1.4.2.3     skrll                 Status = AE_TYPE;
    326  1.1.1.4.2.3     skrll             }
    327  1.1.1.4.2.3     skrll         }
    328  1.1.1.4.2.3     skrll 
    329  1.1.1.4.2.3     skrll         if (ACPI_FAILURE (Status))
    330  1.1.1.4.2.3     skrll         {
    331  1.1.1.4.2.3     skrll             goto CleanupAndExit;
    332  1.1.1.4.2.3     skrll         }
    333  1.1.1.4.2.3     skrll 
    334  1.1.1.4.2.3     skrll         /* This is not a 3/4/5 opcode, but maybe can convert to STORE */
    335          1.1    jruoho 
    336          1.1    jruoho         if (Op->Asl.CompileFlags & NODE_IS_TARGET)
    337          1.1    jruoho         {
    338          1.1    jruoho             DbgPrint (ASL_PARSE_OUTPUT,
    339  1.1.1.4.2.1     skrll                 "**** Valid Target, transform to Store ****\n");
    340  1.1.1.4.2.1     skrll             return (AE_CTRL_RETURN_VALUE);
    341          1.1    jruoho         }
    342          1.1    jruoho 
    343  1.1.1.4.2.1     skrll         /* Expression cannot be reduced */
    344          1.1    jruoho 
    345  1.1.1.4.2.1     skrll         DbgPrint (ASL_PARSE_OUTPUT,
    346  1.1.1.4.2.3     skrll             "**** Not a Type 3/4/5 opcode or cannot reduce/fold (%s) ****\n",
    347  1.1.1.4.2.1     skrll              Op->Asl.ParseOpName);
    348          1.1    jruoho 
    349  1.1.1.4.2.1     skrll         Status = AE_TYPE;
    350  1.1.1.4.2.1     skrll         goto CleanupAndExit;
    351          1.1    jruoho     }
    352          1.1    jruoho 
    353  1.1.1.4.2.3     skrll     /*
    354  1.1.1.4.2.3     skrll      * TBD: Ignore buffer constants for now. The problem is that these
    355  1.1.1.4.2.3     skrll      * constants have been transformed into RAW_DATA at this point, from
    356  1.1.1.4.2.3     skrll      * the parse tree transform process which currently happens before
    357  1.1.1.4.2.3     skrll      * the constant folding process. We may need to defer this transform
    358  1.1.1.4.2.3     skrll      * for buffer until after the constant folding.
    359  1.1.1.4.2.3     skrll      */
    360  1.1.1.4.2.3     skrll     if (WalkState->Opcode == AML_BUFFER_OP)
    361  1.1.1.4.2.3     skrll     {
    362  1.1.1.4.2.3     skrll         DbgPrint (ASL_PARSE_OUTPUT,
    363  1.1.1.4.2.3     skrll             "\nBuffer constant reduction is not supported yet\n");
    364  1.1.1.4.2.3     skrll 
    365  1.1.1.4.2.3     skrll         if (NextOp) /* Found a Name() operator, error */
    366  1.1.1.4.2.3     skrll         {
    367  1.1.1.4.2.3     skrll             AslError (ASL_ERROR, ASL_MSG_UNSUPPORTED, Op,
    368  1.1.1.4.2.3     skrll                 "Buffer expression cannot be reduced");
    369  1.1.1.4.2.3     skrll         }
    370  1.1.1.4.2.3     skrll 
    371  1.1.1.4.2.3     skrll         Status = AE_TYPE;
    372  1.1.1.4.2.3     skrll         goto CleanupAndExit;
    373  1.1.1.4.2.3     skrll     }
    374  1.1.1.4.2.3     skrll 
    375          1.1    jruoho     /* Debug output */
    376          1.1    jruoho 
    377          1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT, "TYPE_345");
    378          1.1    jruoho 
    379          1.1    jruoho     if (Op->Asl.CompileFlags & NODE_IS_TARGET)
    380          1.1    jruoho     {
    381  1.1.1.4.2.1     skrll         if (Op->Asl.ParseOpcode == PARSEOP_ZERO)
    382  1.1.1.4.2.1     skrll         {
    383  1.1.1.4.2.1     skrll             DbgPrint (ASL_PARSE_OUTPUT, "%-16s", " NULL TARGET");
    384  1.1.1.4.2.1     skrll         }
    385  1.1.1.4.2.1     skrll         else
    386  1.1.1.4.2.1     skrll         {
    387  1.1.1.4.2.1     skrll             DbgPrint (ASL_PARSE_OUTPUT, "%-16s", " VALID TARGET");
    388  1.1.1.4.2.1     skrll         }
    389          1.1    jruoho     }
    390  1.1.1.4.2.3     skrll 
    391          1.1    jruoho     if (Op->Asl.CompileFlags & NODE_IS_TERM_ARG)
    392          1.1    jruoho     {
    393  1.1.1.4.2.1     skrll         DbgPrint (ASL_PARSE_OUTPUT, "%-16s", " TERMARG");
    394          1.1    jruoho     }
    395          1.1    jruoho 
    396  1.1.1.4.2.1     skrll CleanupAndExit:
    397  1.1.1.4.2.1     skrll 
    398  1.1.1.4.2.1     skrll     /* Dump the node compile flags also */
    399  1.1.1.4.2.1     skrll 
    400  1.1.1.4.2.1     skrll     TrPrintNodeCompileFlags (Op->Asl.CompileFlags);
    401      1.1.1.3  christos     DbgPrint (ASL_PARSE_OUTPUT, "\n");
    402  1.1.1.4.2.1     skrll     return (Status);
    403          1.1    jruoho }
    404          1.1    jruoho 
    405          1.1    jruoho 
    406          1.1    jruoho /*******************************************************************************
    407          1.1    jruoho  *
    408  1.1.1.4.2.1     skrll  * FUNCTION:    TrSimpleConstantReduction
    409          1.1    jruoho  *
    410  1.1.1.4.2.1     skrll  * PARAMETERS:  Op                  - Parent operator to be transformed
    411  1.1.1.4.2.1     skrll  *              WalkState           - Current walk state
    412          1.1    jruoho  *
    413          1.1    jruoho  * RETURN:      Status
    414          1.1    jruoho  *
    415  1.1.1.4.2.1     skrll  * DESCRIPTION: Reduce an entire AML operation to a single constant. The
    416  1.1.1.4.2.1     skrll  *              operation must not have a target operand.
    417  1.1.1.4.2.1     skrll  *
    418  1.1.1.4.2.1     skrll  *              Add (32,64) --> 96
    419          1.1    jruoho  *
    420          1.1    jruoho  ******************************************************************************/
    421          1.1    jruoho 
    422  1.1.1.4.2.1     skrll static ACPI_STATUS
    423  1.1.1.4.2.1     skrll TrSimpleConstantReduction (
    424          1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
    425  1.1.1.4.2.1     skrll     ACPI_WALK_STATE         *WalkState)
    426          1.1    jruoho {
    427          1.1    jruoho     ACPI_PARSE_OBJECT       *RootOp;
    428          1.1    jruoho     ACPI_PARSE_OBJECT       *OriginalParentOp;
    429  1.1.1.4.2.1     skrll     ACPI_OPERAND_OBJECT     *ObjDesc;
    430  1.1.1.4.2.1     skrll     ACPI_STATUS             Status;
    431          1.1    jruoho 
    432          1.1    jruoho 
    433  1.1.1.4.2.1     skrll     DbgPrint (ASL_PARSE_OUTPUT,
    434  1.1.1.4.2.1     skrll         "Simple subtree constant reduction, operator to constant\n");
    435  1.1.1.4.2.1     skrll 
    436  1.1.1.4.2.1     skrll     /* Allocate a new temporary root for this subtree */
    437  1.1.1.4.2.1     skrll 
    438  1.1.1.4.2.1     skrll     RootOp = TrAllocateNode (PARSEOP_INTEGER);
    439  1.1.1.4.2.1     skrll     if (!RootOp)
    440          1.1    jruoho     {
    441  1.1.1.4.2.1     skrll         return (AE_NO_MEMORY);
    442          1.1    jruoho     }
    443          1.1    jruoho 
    444  1.1.1.4.2.1     skrll     RootOp->Common.AmlOpcode = AML_INT_EVAL_SUBTREE_OP;
    445          1.1    jruoho 
    446  1.1.1.4.2.1     skrll     OriginalParentOp = Op->Common.Parent;
    447  1.1.1.4.2.1     skrll     Op->Common.Parent = RootOp;
    448          1.1    jruoho 
    449  1.1.1.4.2.1     skrll     /* Hand off the subtree to the AML interpreter */
    450          1.1    jruoho 
    451  1.1.1.4.2.1     skrll     WalkState->CallerReturnDesc = &ObjDesc;
    452  1.1.1.4.2.1     skrll 
    453  1.1.1.4.2.1     skrll     Status = TrWalkParseTree (Op, ASL_WALK_VISIT_TWICE,
    454  1.1.1.4.2.1     skrll         OpcAmlEvaluationWalk1, OpcAmlEvaluationWalk2, WalkState);
    455  1.1.1.4.2.1     skrll 
    456  1.1.1.4.2.1     skrll     /* Restore original parse tree */
    457          1.1    jruoho 
    458  1.1.1.4.2.1     skrll     Op->Common.Parent = OriginalParentOp;
    459  1.1.1.4.2.1     skrll 
    460  1.1.1.4.2.1     skrll     if (ACPI_FAILURE (Status))
    461  1.1.1.4.2.1     skrll     {
    462  1.1.1.4.2.1     skrll         DbgPrint (ASL_PARSE_OUTPUT,
    463  1.1.1.4.2.1     skrll             "Constant Subtree evaluation(1), %s\n",
    464  1.1.1.4.2.1     skrll             AcpiFormatException (Status));
    465  1.1.1.4.2.1     skrll         return (Status);
    466          1.1    jruoho     }
    467          1.1    jruoho 
    468  1.1.1.4.2.1     skrll     /* Get the final result */
    469          1.1    jruoho 
    470  1.1.1.4.2.1     skrll     Status = AcpiDsResultPop (&ObjDesc, WalkState);
    471  1.1.1.4.2.1     skrll     if (ACPI_FAILURE (Status))
    472          1.1    jruoho     {
    473  1.1.1.4.2.1     skrll         DbgPrint (ASL_PARSE_OUTPUT,
    474  1.1.1.4.2.1     skrll             "Constant Subtree evaluation(2), %s\n",
    475  1.1.1.4.2.1     skrll             AcpiFormatException (Status));
    476  1.1.1.4.2.1     skrll         return (Status);
    477          1.1    jruoho     }
    478          1.1    jruoho 
    479  1.1.1.4.2.2     skrll     /* Disconnect any existing children, install new constant */
    480  1.1.1.4.2.2     skrll 
    481  1.1.1.4.2.2     skrll     Op->Asl.Child = NULL;
    482  1.1.1.4.2.1     skrll     TrInstallReducedConstant (Op, ObjDesc);
    483          1.1    jruoho 
    484  1.1.1.4.2.1     skrll     UtSetParseOpName (Op);
    485  1.1.1.4.2.1     skrll     return (AE_OK);
    486  1.1.1.4.2.1     skrll }
    487  1.1.1.4.2.1     skrll 
    488  1.1.1.4.2.1     skrll 
    489  1.1.1.4.2.1     skrll /*******************************************************************************
    490  1.1.1.4.2.1     skrll  *
    491  1.1.1.4.2.1     skrll  * FUNCTION:    TrTransformToStoreOp
    492  1.1.1.4.2.1     skrll  *
    493  1.1.1.4.2.1     skrll  * PARAMETERS:  Op                  - Parent operator to be transformed
    494  1.1.1.4.2.1     skrll  *              WalkState           - Current walk state
    495  1.1.1.4.2.1     skrll  *
    496  1.1.1.4.2.1     skrll  * RETURN:      Status
    497  1.1.1.4.2.1     skrll  *
    498  1.1.1.4.2.1     skrll  * DESCRIPTION: Transforms a single AML operation with a constant and target
    499  1.1.1.4.2.1     skrll  *              to a simple store operation:
    500  1.1.1.4.2.1     skrll  *
    501  1.1.1.4.2.1     skrll  *              Add (32,64,DATA) --> Store (96,DATA)
    502  1.1.1.4.2.1     skrll  *
    503  1.1.1.4.2.1     skrll  ******************************************************************************/
    504  1.1.1.4.2.1     skrll 
    505  1.1.1.4.2.1     skrll static ACPI_STATUS
    506  1.1.1.4.2.1     skrll TrTransformToStoreOp (
    507  1.1.1.4.2.1     skrll     ACPI_PARSE_OBJECT       *Op,
    508  1.1.1.4.2.1     skrll     ACPI_WALK_STATE         *WalkState)
    509  1.1.1.4.2.1     skrll {
    510  1.1.1.4.2.1     skrll     ACPI_PARSE_OBJECT       *OriginalTarget;
    511  1.1.1.4.2.1     skrll     ACPI_PARSE_OBJECT       *NewTarget;
    512  1.1.1.4.2.1     skrll     ACPI_PARSE_OBJECT       *Child1;
    513  1.1.1.4.2.1     skrll     ACPI_PARSE_OBJECT       *Child2;
    514  1.1.1.4.2.1     skrll     ACPI_OPERAND_OBJECT     *ObjDesc;
    515  1.1.1.4.2.1     skrll     ACPI_PARSE_OBJECT       *NewParent;
    516  1.1.1.4.2.1     skrll     ACPI_PARSE_OBJECT       *OriginalParent;
    517  1.1.1.4.2.1     skrll     ACPI_STATUS             Status;
    518  1.1.1.4.2.1     skrll 
    519  1.1.1.4.2.1     skrll 
    520  1.1.1.4.2.1     skrll     /* Extract the operands */
    521  1.1.1.4.2.1     skrll 
    522  1.1.1.4.2.1     skrll     Child1 = Op->Asl.Child;
    523  1.1.1.4.2.1     skrll     Child2 = Child1->Asl.Next;
    524          1.1    jruoho 
    525          1.1    jruoho     /*
    526  1.1.1.4.2.1     skrll      * Special case for DIVIDE -- it has two targets. The first
    527  1.1.1.4.2.1     skrll      * is for the remainder and if present, we will not attempt
    528  1.1.1.4.2.1     skrll      * to reduce the expression.
    529          1.1    jruoho      */
    530  1.1.1.4.2.1     skrll     if (Op->Asl.ParseOpcode == PARSEOP_DIVIDE)
    531          1.1    jruoho     {
    532  1.1.1.4.2.1     skrll         Child2 = Child2->Asl.Next;
    533  1.1.1.4.2.1     skrll         if (Child2->Asl.ParseOpcode != PARSEOP_ZERO)
    534          1.1    jruoho         {
    535  1.1.1.4.2.1     skrll             DbgPrint (ASL_PARSE_OUTPUT,
    536  1.1.1.4.2.1     skrll                 "Cannot reduce DIVIDE - has two targets\n\n");
    537          1.1    jruoho             return (AE_OK);
    538          1.1    jruoho         }
    539  1.1.1.4.2.1     skrll     }
    540  1.1.1.4.2.1     skrll 
    541  1.1.1.4.2.4     skrll     DbgPrint (ASL_PARSE_OUTPUT,
    542  1.1.1.4.2.4     skrll         "Reduction/Transform to StoreOp: Store(%s, %s)\n",
    543  1.1.1.4.2.4     skrll         Child1->Asl.ParseOpName, Child2->Asl.ParseOpName);
    544  1.1.1.4.2.4     skrll 
    545  1.1.1.4.2.1     skrll     /*
    546  1.1.1.4.2.1     skrll      * Create a NULL (zero) target so that we can use the
    547  1.1.1.4.2.1     skrll      * interpreter to evaluate the expression.
    548  1.1.1.4.2.1     skrll      */
    549  1.1.1.4.2.1     skrll     NewTarget = TrCreateNullTarget ();
    550  1.1.1.4.2.1     skrll     NewTarget->Common.AmlOpcode = AML_INT_NAMEPATH_OP;
    551          1.1    jruoho 
    552  1.1.1.4.2.1     skrll     /* Handle one-operand cases (NOT, TOBCD, etc.) */
    553          1.1    jruoho 
    554  1.1.1.4.2.1     skrll     if (!Child2->Asl.Next)
    555          1.1    jruoho     {
    556  1.1.1.4.2.1     skrll         Child2 = Child1;
    557  1.1.1.4.2.1     skrll     }
    558          1.1    jruoho 
    559  1.1.1.4.2.1     skrll     /* Link in new NULL target as the last operand */
    560          1.1    jruoho 
    561  1.1.1.4.2.1     skrll     OriginalTarget = Child2->Asl.Next;
    562  1.1.1.4.2.1     skrll     Child2->Asl.Next = NewTarget;
    563  1.1.1.4.2.1     skrll     NewTarget->Asl.Parent = OriginalTarget->Asl.Parent;
    564          1.1    jruoho 
    565  1.1.1.4.2.1     skrll     NewParent = TrAllocateNode (PARSEOP_INTEGER);
    566  1.1.1.4.2.1     skrll     NewParent->Common.AmlOpcode = AML_INT_EVAL_SUBTREE_OP;
    567          1.1    jruoho 
    568  1.1.1.4.2.1     skrll     OriginalParent = Op->Common.Parent;
    569  1.1.1.4.2.1     skrll     Op->Common.Parent = NewParent;
    570          1.1    jruoho 
    571  1.1.1.4.2.1     skrll     /* Hand off the subtree to the AML interpreter */
    572          1.1    jruoho 
    573  1.1.1.4.2.1     skrll     WalkState->CallerReturnDesc = &ObjDesc;
    574          1.1    jruoho 
    575  1.1.1.4.2.1     skrll     Status = TrWalkParseTree (Op, ASL_WALK_VISIT_TWICE,
    576  1.1.1.4.2.1     skrll         OpcAmlEvaluationWalk1, OpcAmlEvaluationWalk2, WalkState);
    577  1.1.1.4.2.1     skrll     if (ACPI_FAILURE (Status))
    578  1.1.1.4.2.1     skrll     {
    579  1.1.1.4.2.1     skrll         DbgPrint (ASL_PARSE_OUTPUT,
    580  1.1.1.4.2.1     skrll             "Constant Subtree evaluation(3), %s\n",
    581  1.1.1.4.2.1     skrll             AcpiFormatException (Status));
    582  1.1.1.4.2.1     skrll         goto EvalError;
    583  1.1.1.4.2.1     skrll     }
    584          1.1    jruoho 
    585  1.1.1.4.2.1     skrll     /* Get the final result */
    586          1.1    jruoho 
    587  1.1.1.4.2.1     skrll     Status = AcpiDsResultPop (&ObjDesc, WalkState);
    588  1.1.1.4.2.1     skrll     if (ACPI_FAILURE (Status))
    589  1.1.1.4.2.1     skrll     {
    590  1.1.1.4.2.1     skrll         DbgPrint (ASL_PARSE_OUTPUT,
    591  1.1.1.4.2.1     skrll             "Constant Subtree evaluation(4), %s\n",
    592  1.1.1.4.2.1     skrll             AcpiFormatException (Status));
    593  1.1.1.4.2.1     skrll         goto EvalError;
    594  1.1.1.4.2.1     skrll     }
    595          1.1    jruoho 
    596  1.1.1.4.2.2     skrll     /* Truncate any subtree expressions, they have been evaluated */
    597  1.1.1.4.2.2     skrll 
    598  1.1.1.4.2.2     skrll     Child1->Asl.Child = NULL;
    599  1.1.1.4.2.2     skrll 
    600  1.1.1.4.2.1     skrll     /* Folded constant is in ObjDesc, store into Child1 */
    601      1.1.1.3  christos 
    602  1.1.1.4.2.1     skrll     TrInstallReducedConstant (Child1, ObjDesc);
    603      1.1.1.3  christos 
    604  1.1.1.4.2.1     skrll     /* Convert operator to STORE */
    605          1.1    jruoho 
    606  1.1.1.4.2.1     skrll     Op->Asl.ParseOpcode = PARSEOP_STORE;
    607  1.1.1.4.2.1     skrll     Op->Asl.AmlOpcode = AML_STORE_OP;
    608  1.1.1.4.2.1     skrll     UtSetParseOpName (Op);
    609  1.1.1.4.2.1     skrll     Op->Common.Parent = OriginalParent;
    610          1.1    jruoho 
    611  1.1.1.4.2.1     skrll     /* First child is the folded constant */
    612          1.1    jruoho 
    613  1.1.1.4.2.1     skrll     /* Second child will be the target */
    614          1.1    jruoho 
    615  1.1.1.4.2.1     skrll     Child1->Asl.Next = OriginalTarget;
    616  1.1.1.4.2.1     skrll     return (AE_OK);
    617          1.1    jruoho 
    618          1.1    jruoho 
    619  1.1.1.4.2.1     skrll EvalError:
    620  1.1.1.4.2.1     skrll 
    621  1.1.1.4.2.1     skrll     /* Restore original links */
    622  1.1.1.4.2.1     skrll 
    623  1.1.1.4.2.1     skrll     Op->Common.Parent = OriginalParent;
    624  1.1.1.4.2.1     skrll     Child2->Asl.Next = OriginalTarget;
    625  1.1.1.4.2.1     skrll     return (Status);
    626  1.1.1.4.2.1     skrll }
    627  1.1.1.4.2.1     skrll 
    628  1.1.1.4.2.1     skrll 
    629  1.1.1.4.2.1     skrll /*******************************************************************************
    630  1.1.1.4.2.1     skrll  *
    631  1.1.1.4.2.1     skrll  * FUNCTION:    TrInstallReducedConstant
    632  1.1.1.4.2.1     skrll  *
    633  1.1.1.4.2.1     skrll  * PARAMETERS:  Op                  - Parent operator to be transformed
    634  1.1.1.4.2.1     skrll  *              ObjDesc             - Reduced constant to be installed
    635  1.1.1.4.2.1     skrll  *
    636  1.1.1.4.2.1     skrll  * RETURN:      None
    637  1.1.1.4.2.1     skrll  *
    638  1.1.1.4.2.1     skrll  * DESCRIPTION: Transform the original operator to a simple constant.
    639  1.1.1.4.2.1     skrll  *              Handles Integers, Strings, and Buffers.
    640  1.1.1.4.2.1     skrll  *
    641  1.1.1.4.2.1     skrll  ******************************************************************************/
    642          1.1    jruoho 
    643  1.1.1.4.2.1     skrll static void
    644  1.1.1.4.2.1     skrll TrInstallReducedConstant (
    645  1.1.1.4.2.1     skrll     ACPI_PARSE_OBJECT       *Op,
    646  1.1.1.4.2.1     skrll     ACPI_OPERAND_OBJECT     *ObjDesc)
    647  1.1.1.4.2.1     skrll {
    648  1.1.1.4.2.2     skrll     ACPI_PARSE_OBJECT       *LengthOp;
    649  1.1.1.4.2.2     skrll     ACPI_PARSE_OBJECT       *DataOp;
    650          1.1    jruoho 
    651          1.1    jruoho 
    652  1.1.1.4.2.1     skrll     TotalFolds++;
    653  1.1.1.4.2.1     skrll     AslError (ASL_OPTIMIZATION, ASL_MSG_CONSTANT_FOLDED, Op,
    654  1.1.1.4.2.1     skrll         Op->Asl.ParseOpName);
    655          1.1    jruoho 
    656  1.1.1.4.2.1     skrll     /*
    657  1.1.1.4.2.1     skrll      * Because we know we executed type 3/4/5 opcodes above, we know that
    658  1.1.1.4.2.1     skrll      * the result must be either an Integer, String, or Buffer.
    659  1.1.1.4.2.1     skrll      */
    660  1.1.1.4.2.1     skrll     switch (ObjDesc->Common.Type)
    661  1.1.1.4.2.1     skrll     {
    662  1.1.1.4.2.1     skrll     case ACPI_TYPE_INTEGER:
    663          1.1    jruoho 
    664  1.1.1.4.2.1     skrll         OpcUpdateIntegerNode (Op, ObjDesc->Integer.Value);
    665          1.1    jruoho 
    666  1.1.1.4.2.1     skrll         DbgPrint (ASL_PARSE_OUTPUT,
    667  1.1.1.4.2.1     skrll             "Constant expression reduced to (%s) %8.8X%8.8X\n\n",
    668  1.1.1.4.2.1     skrll             Op->Asl.ParseOpName,
    669  1.1.1.4.2.1     skrll             ACPI_FORMAT_UINT64 (Op->Common.Value.Integer));
    670  1.1.1.4.2.1     skrll         break;
    671          1.1    jruoho 
    672  1.1.1.4.2.1     skrll     case ACPI_TYPE_STRING:
    673          1.1    jruoho 
    674  1.1.1.4.2.1     skrll         Op->Asl.ParseOpcode = PARSEOP_STRING_LITERAL;
    675  1.1.1.4.2.1     skrll         Op->Common.AmlOpcode = AML_STRING_OP;
    676  1.1.1.4.2.2     skrll         Op->Asl.AmlLength = strlen (ObjDesc->String.Pointer) + 1;
    677  1.1.1.4.2.1     skrll         Op->Common.Value.String = ObjDesc->String.Pointer;
    678  1.1.1.4.2.1     skrll 
    679  1.1.1.4.2.1     skrll         DbgPrint (ASL_PARSE_OUTPUT,
    680  1.1.1.4.2.1     skrll             "Constant expression reduced to (STRING) %s\n\n",
    681  1.1.1.4.2.1     skrll             Op->Common.Value.String);
    682  1.1.1.4.2.1     skrll         break;
    683          1.1    jruoho 
    684  1.1.1.4.2.1     skrll     case ACPI_TYPE_BUFFER:
    685  1.1.1.4.2.2     skrll         /*
    686  1.1.1.4.2.2     skrll          * Create a new parse subtree of the form:
    687  1.1.1.4.2.2     skrll          *
    688  1.1.1.4.2.2     skrll          * BUFFER (Buffer AML opcode)
    689  1.1.1.4.2.2     skrll          *    INTEGER (Buffer length in bytes)
    690  1.1.1.4.2.2     skrll          *    RAW_DATA (Buffer byte data)
    691  1.1.1.4.2.2     skrll          */
    692  1.1.1.4.2.1     skrll         Op->Asl.ParseOpcode = PARSEOP_BUFFER;
    693  1.1.1.4.2.1     skrll         Op->Common.AmlOpcode = AML_BUFFER_OP;
    694  1.1.1.4.2.1     skrll         Op->Asl.CompileFlags = NODE_AML_PACKAGE;
    695  1.1.1.4.2.1     skrll         UtSetParseOpName (Op);
    696          1.1    jruoho 
    697  1.1.1.4.2.1     skrll         /* Child node is the buffer length */
    698          1.1    jruoho 
    699  1.1.1.4.2.2     skrll         LengthOp = TrAllocateNode (PARSEOP_INTEGER);
    700          1.1    jruoho 
    701  1.1.1.4.2.2     skrll         LengthOp->Asl.AmlOpcode = AML_DWORD_OP;
    702  1.1.1.4.2.2     skrll         LengthOp->Asl.Value.Integer = ObjDesc->Buffer.Length;
    703  1.1.1.4.2.2     skrll         LengthOp->Asl.Parent = Op;
    704  1.1.1.4.2.2     skrll         (void) OpcSetOptimalIntegerSize (LengthOp);
    705  1.1.1.4.2.1     skrll 
    706  1.1.1.4.2.2     skrll         Op->Asl.Child = LengthOp;
    707  1.1.1.4.2.1     skrll 
    708  1.1.1.4.2.2     skrll         /* Next child is the raw buffer data */
    709  1.1.1.4.2.1     skrll 
    710  1.1.1.4.2.2     skrll         DataOp = TrAllocateNode (PARSEOP_RAW_DATA);
    711  1.1.1.4.2.2     skrll         DataOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER;
    712  1.1.1.4.2.2     skrll         DataOp->Asl.AmlLength = ObjDesc->Buffer.Length;
    713  1.1.1.4.2.2     skrll         DataOp->Asl.Value.String = (char *) ObjDesc->Buffer.Pointer;
    714  1.1.1.4.2.2     skrll         DataOp->Asl.Parent = Op;
    715  1.1.1.4.2.1     skrll 
    716  1.1.1.4.2.2     skrll         LengthOp->Asl.Next = DataOp;
    717  1.1.1.4.2.1     skrll 
    718  1.1.1.4.2.1     skrll         DbgPrint (ASL_PARSE_OUTPUT,
    719  1.1.1.4.2.1     skrll             "Constant expression reduced to (BUFFER) length %X\n\n",
    720  1.1.1.4.2.1     skrll             ObjDesc->Buffer.Length);
    721  1.1.1.4.2.1     skrll         break;
    722  1.1.1.4.2.1     skrll 
    723  1.1.1.4.2.1     skrll     default:
    724  1.1.1.4.2.1     skrll         break;
    725  1.1.1.4.2.1     skrll     }
    726          1.1    jruoho }
    727          1.1    jruoho 
    728      1.1.1.3  christos 
    729      1.1.1.3  christos /*******************************************************************************
    730      1.1.1.3  christos  *
    731      1.1.1.3  christos  * FUNCTION:    OpcUpdateIntegerNode
    732      1.1.1.3  christos  *
    733      1.1.1.3  christos  * PARAMETERS:  Op                  - Current parse object
    734  1.1.1.4.2.1     skrll  *              Value               - Value for the integer op
    735      1.1.1.3  christos  *
    736      1.1.1.3  christos  * RETURN:      None
    737      1.1.1.3  christos  *
    738  1.1.1.4.2.1     skrll  * DESCRIPTION: Update node to the correct Integer type and value
    739      1.1.1.3  christos  *
    740      1.1.1.3  christos  ******************************************************************************/
    741      1.1.1.3  christos 
    742      1.1.1.3  christos static void
    743      1.1.1.3  christos OpcUpdateIntegerNode (
    744      1.1.1.3  christos     ACPI_PARSE_OBJECT       *Op,
    745      1.1.1.3  christos     UINT64                  Value)
    746      1.1.1.3  christos {
    747      1.1.1.3  christos 
    748      1.1.1.3  christos     Op->Common.Value.Integer = Value;
    749      1.1.1.3  christos 
    750      1.1.1.3  christos     /*
    751      1.1.1.3  christos      * The AmlLength is used by the parser to indicate a constant,
    752      1.1.1.3  christos      * (if non-zero). Length is either (1/2/4/8)
    753      1.1.1.3  christos      */
    754      1.1.1.3  christos     switch (Op->Asl.AmlLength)
    755      1.1.1.3  christos     {
    756      1.1.1.3  christos     case 1:
    757      1.1.1.3  christos 
    758      1.1.1.3  christos         TrUpdateNode (PARSEOP_BYTECONST, Op);
    759      1.1.1.3  christos         Op->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
    760      1.1.1.3  christos         break;
    761      1.1.1.3  christos 
    762      1.1.1.3  christos     case 2:
    763      1.1.1.3  christos 
    764      1.1.1.3  christos         TrUpdateNode (PARSEOP_WORDCONST, Op);
    765      1.1.1.3  christos         Op->Asl.AmlOpcode = AML_RAW_DATA_WORD;
    766      1.1.1.3  christos         break;
    767      1.1.1.3  christos 
    768      1.1.1.3  christos     case 4:
    769      1.1.1.3  christos 
    770      1.1.1.3  christos         TrUpdateNode (PARSEOP_DWORDCONST, Op);
    771      1.1.1.3  christos         Op->Asl.AmlOpcode = AML_RAW_DATA_DWORD;
    772      1.1.1.3  christos         break;
    773      1.1.1.3  christos 
    774      1.1.1.3  christos     case 8:
    775      1.1.1.3  christos 
    776      1.1.1.3  christos         TrUpdateNode (PARSEOP_QWORDCONST, Op);
    777      1.1.1.3  christos         Op->Asl.AmlOpcode = AML_RAW_DATA_QWORD;
    778      1.1.1.3  christos         break;
    779      1.1.1.3  christos 
    780      1.1.1.3  christos     case 0:
    781      1.1.1.3  christos     default:
    782      1.1.1.3  christos 
    783      1.1.1.3  christos         OpcSetOptimalIntegerSize (Op);
    784      1.1.1.3  christos         TrUpdateNode (PARSEOP_INTEGER, Op);
    785      1.1.1.3  christos         break;
    786      1.1.1.3  christos     }
    787      1.1.1.3  christos 
    788      1.1.1.3  christos     Op->Asl.AmlLength = 0;
    789      1.1.1.3  christos }
    790  1.1.1.4.2.1     skrll 
    791  1.1.1.4.2.1     skrll 
    792  1.1.1.4.2.1     skrll /*******************************************************************************
    793  1.1.1.4.2.1     skrll  *
    794  1.1.1.4.2.1     skrll  * FUNCTION:    OpcAmlEvaluationWalk1
    795  1.1.1.4.2.1     skrll  *
    796  1.1.1.4.2.1     skrll  * PARAMETERS:  ASL_WALK_CALLBACK
    797  1.1.1.4.2.1     skrll  *
    798  1.1.1.4.2.1     skrll  * RETURN:      Status
    799  1.1.1.4.2.1     skrll  *
    800  1.1.1.4.2.1     skrll  * DESCRIPTION: Descending callback for AML execution of constant subtrees
    801  1.1.1.4.2.1     skrll  *
    802  1.1.1.4.2.1     skrll  ******************************************************************************/
    803  1.1.1.4.2.1     skrll 
    804  1.1.1.4.2.1     skrll static ACPI_STATUS
    805  1.1.1.4.2.1     skrll OpcAmlEvaluationWalk1 (
    806  1.1.1.4.2.1     skrll     ACPI_PARSE_OBJECT       *Op,
    807  1.1.1.4.2.1     skrll     UINT32                  Level,
    808  1.1.1.4.2.1     skrll     void                    *Context)
    809  1.1.1.4.2.1     skrll {
    810  1.1.1.4.2.1     skrll     ACPI_WALK_STATE         *WalkState = Context;
    811  1.1.1.4.2.1     skrll     ACPI_STATUS             Status;
    812  1.1.1.4.2.1     skrll     ACPI_PARSE_OBJECT       *OutOp;
    813  1.1.1.4.2.1     skrll 
    814  1.1.1.4.2.1     skrll 
    815  1.1.1.4.2.1     skrll     WalkState->Op = Op;
    816  1.1.1.4.2.1     skrll     WalkState->Opcode = Op->Common.AmlOpcode;
    817  1.1.1.4.2.1     skrll     WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
    818  1.1.1.4.2.1     skrll 
    819  1.1.1.4.2.1     skrll     /* Copy child pointer to Arg for compatibility with Interpreter */
    820  1.1.1.4.2.1     skrll 
    821  1.1.1.4.2.1     skrll     if (Op->Asl.Child)
    822  1.1.1.4.2.1     skrll     {
    823  1.1.1.4.2.1     skrll         Op->Common.Value.Arg = Op->Asl.Child;
    824  1.1.1.4.2.1     skrll     }
    825  1.1.1.4.2.1     skrll 
    826  1.1.1.4.2.1     skrll     /* Call AML dispatcher */
    827  1.1.1.4.2.1     skrll 
    828  1.1.1.4.2.1     skrll     Status = AcpiDsExecBeginOp (WalkState, &OutOp);
    829  1.1.1.4.2.1     skrll     if (ACPI_FAILURE (Status))
    830  1.1.1.4.2.1     skrll     {
    831  1.1.1.4.2.1     skrll         DbgPrint (ASL_PARSE_OUTPUT,
    832  1.1.1.4.2.1     skrll             "%s Constant interpretation failed (1) - %s\n",
    833  1.1.1.4.2.1     skrll             Op->Asl.ParseOpName, AcpiFormatException (Status));
    834  1.1.1.4.2.1     skrll     }
    835  1.1.1.4.2.1     skrll 
    836  1.1.1.4.2.1     skrll     return (Status);
    837  1.1.1.4.2.1     skrll }
    838  1.1.1.4.2.1     skrll 
    839  1.1.1.4.2.1     skrll 
    840  1.1.1.4.2.1     skrll /*******************************************************************************
    841  1.1.1.4.2.1     skrll  *
    842  1.1.1.4.2.1     skrll  * FUNCTION:    OpcAmlEvaluationWalk2
    843  1.1.1.4.2.1     skrll  *
    844  1.1.1.4.2.1     skrll  * PARAMETERS:  ASL_WALK_CALLBACK
    845  1.1.1.4.2.1     skrll  *
    846  1.1.1.4.2.1     skrll  * RETURN:      Status
    847  1.1.1.4.2.1     skrll  *
    848  1.1.1.4.2.1     skrll  * DESCRIPTION: Ascending callback for AML execution of constant subtrees
    849  1.1.1.4.2.1     skrll  *
    850  1.1.1.4.2.1     skrll  ******************************************************************************/
    851  1.1.1.4.2.1     skrll 
    852  1.1.1.4.2.1     skrll static ACPI_STATUS
    853  1.1.1.4.2.1     skrll OpcAmlEvaluationWalk2 (
    854  1.1.1.4.2.1     skrll     ACPI_PARSE_OBJECT       *Op,
    855  1.1.1.4.2.1     skrll     UINT32                  Level,
    856  1.1.1.4.2.1     skrll     void                    *Context)
    857  1.1.1.4.2.1     skrll {
    858  1.1.1.4.2.1     skrll     ACPI_WALK_STATE         *WalkState = Context;
    859  1.1.1.4.2.1     skrll     ACPI_STATUS             Status;
    860  1.1.1.4.2.1     skrll 
    861  1.1.1.4.2.1     skrll 
    862  1.1.1.4.2.1     skrll     WalkState->Op = Op;
    863  1.1.1.4.2.1     skrll     WalkState->Opcode = Op->Common.AmlOpcode;
    864  1.1.1.4.2.1     skrll     WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
    865  1.1.1.4.2.1     skrll 
    866  1.1.1.4.2.1     skrll     /* Copy child pointer to Arg for compatibility with Interpreter */
    867  1.1.1.4.2.1     skrll 
    868  1.1.1.4.2.1     skrll     if (Op->Asl.Child)
    869  1.1.1.4.2.1     skrll     {
    870  1.1.1.4.2.1     skrll         Op->Common.Value.Arg = Op->Asl.Child;
    871  1.1.1.4.2.1     skrll     }
    872  1.1.1.4.2.1     skrll 
    873  1.1.1.4.2.1     skrll     /* Call AML dispatcher */
    874  1.1.1.4.2.1     skrll 
    875  1.1.1.4.2.1     skrll     Status = AcpiDsExecEndOp (WalkState);
    876  1.1.1.4.2.1     skrll     if (ACPI_FAILURE (Status))
    877  1.1.1.4.2.1     skrll     {
    878  1.1.1.4.2.1     skrll         DbgPrint (ASL_PARSE_OUTPUT,
    879  1.1.1.4.2.1     skrll             "%s: Constant interpretation failed (2) - %s\n",
    880  1.1.1.4.2.1     skrll             Op->Asl.ParseOpName, AcpiFormatException (Status));
    881  1.1.1.4.2.1     skrll     }
    882  1.1.1.4.2.1     skrll 
    883  1.1.1.4.2.1     skrll     return (Status);
    884  1.1.1.4.2.1     skrll }
    885