Home | History | Annotate | Line # | Download | only in compiler
aslwalks.c revision 1.1.1.16
      1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3   1.1.1.3  christos  * Module Name: aslwalks.c - Miscellaneous analytical parse tree walks
      4       1.1    jruoho  *
      5       1.1    jruoho  *****************************************************************************/
      6       1.1    jruoho 
      7       1.1    jruoho /*
      8  1.1.1.16  christos  * Copyright (C) 2000 - 2021, Intel Corp.
      9       1.1    jruoho  * All rights reserved.
     10       1.1    jruoho  *
     11       1.1    jruoho  * Redistribution and use in source and binary forms, with or without
     12       1.1    jruoho  * modification, are permitted provided that the following conditions
     13       1.1    jruoho  * are met:
     14       1.1    jruoho  * 1. Redistributions of source code must retain the above copyright
     15       1.1    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16       1.1    jruoho  *    without modification.
     17       1.1    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18       1.1    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19       1.1    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20       1.1    jruoho  *    including a substantially similar Disclaimer requirement for further
     21       1.1    jruoho  *    binary redistribution.
     22       1.1    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23       1.1    jruoho  *    of any contributors may be used to endorse or promote products derived
     24       1.1    jruoho  *    from this software without specific prior written permission.
     25       1.1    jruoho  *
     26       1.1    jruoho  * Alternatively, this software may be distributed under the terms of the
     27       1.1    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28       1.1    jruoho  * Software Foundation.
     29       1.1    jruoho  *
     30       1.1    jruoho  * NO WARRANTY
     31       1.1    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32       1.1    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.16  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     34       1.1    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35       1.1    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36       1.1    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37       1.1    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38       1.1    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39       1.1    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40       1.1    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41       1.1    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42       1.1    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 "acparser.h"
     47       1.1    jruoho #include "amlcode.h"
     48       1.1    jruoho 
     49       1.1    jruoho 
     50       1.1    jruoho #define _COMPONENT          ACPI_COMPILER
     51       1.1    jruoho         ACPI_MODULE_NAME    ("aslwalks")
     52       1.1    jruoho 
     53       1.1    jruoho 
     54   1.1.1.6  christos /* Local prototypes */
     55   1.1.1.6  christos 
     56   1.1.1.6  christos static void
     57   1.1.1.6  christos AnAnalyzeStoreOperator (
     58   1.1.1.6  christos     ACPI_PARSE_OBJECT       *Op);
     59   1.1.1.6  christos 
     60  1.1.1.14  christos static BOOLEAN
     61  1.1.1.14  christos AnIsValidBufferConstant (
     62  1.1.1.14  christos     ACPI_PARSE_OBJECT       *Op);
     63  1.1.1.14  christos 
     64  1.1.1.14  christos static void
     65  1.1.1.14  christos AnValidateCreateBufferField (
     66  1.1.1.14  christos     ACPI_PARSE_OBJECT       *CreateBufferFieldOp);
     67  1.1.1.14  christos 
     68   1.1.1.6  christos 
     69       1.1    jruoho /*******************************************************************************
     70       1.1    jruoho  *
     71       1.1    jruoho  * FUNCTION:    AnMethodTypingWalkEnd
     72       1.1    jruoho  *
     73       1.1    jruoho  * PARAMETERS:  ASL_WALK_CALLBACK
     74       1.1    jruoho  *
     75       1.1    jruoho  * RETURN:      Status
     76       1.1    jruoho  *
     77       1.1    jruoho  * DESCRIPTION: Ascending callback for typing walk. Complete the method
     78       1.1    jruoho  *              return analysis. Check methods for:
     79       1.1    jruoho  *              1) Initialized local variables
     80       1.1    jruoho  *              2) Valid arguments
     81       1.1    jruoho  *              3) Return types
     82       1.1    jruoho  *
     83       1.1    jruoho  ******************************************************************************/
     84       1.1    jruoho 
     85       1.1    jruoho ACPI_STATUS
     86       1.1    jruoho AnMethodTypingWalkEnd (
     87       1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
     88       1.1    jruoho     UINT32                  Level,
     89       1.1    jruoho     void                    *Context)
     90       1.1    jruoho {
     91   1.1.1.6  christos     UINT32                  ThisOpBtype;
     92       1.1    jruoho 
     93       1.1    jruoho 
     94       1.1    jruoho     switch (Op->Asl.ParseOpcode)
     95       1.1    jruoho     {
     96       1.1    jruoho     case PARSEOP_METHOD:
     97       1.1    jruoho 
     98  1.1.1.10  christos         Op->Asl.CompileFlags |= OP_METHOD_TYPED;
     99       1.1    jruoho         break;
    100       1.1    jruoho 
    101       1.1    jruoho     case PARSEOP_RETURN:
    102       1.1    jruoho 
    103       1.1    jruoho         if ((Op->Asl.Child) &&
    104       1.1    jruoho             (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG))
    105       1.1    jruoho         {
    106   1.1.1.6  christos             ThisOpBtype = AnGetBtype (Op->Asl.Child);
    107       1.1    jruoho 
    108       1.1    jruoho             if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_METHODCALL) &&
    109   1.1.1.6  christos                 (ThisOpBtype == (ACPI_UINT32_MAX -1)))
    110       1.1    jruoho             {
    111       1.1    jruoho                 /*
    112       1.1    jruoho                  * The called method is untyped at this time (typically a
    113       1.1    jruoho                  * forward reference).
    114       1.1    jruoho                  *
    115   1.1.1.7  christos                  * Check for a recursive method call first. Note: the
    116   1.1.1.7  christos                  * Child->Node will be null if the method has not been
    117   1.1.1.7  christos                  * resolved.
    118       1.1    jruoho                  */
    119   1.1.1.7  christos                 if (Op->Asl.Child->Asl.Node &&
    120   1.1.1.7  christos                     (Op->Asl.ParentMethod != Op->Asl.Child->Asl.Node->Op))
    121       1.1    jruoho                 {
    122       1.1    jruoho                     /* We must type the method here */
    123       1.1    jruoho 
    124       1.1    jruoho                     TrWalkParseTree (Op->Asl.Child->Asl.Node->Op,
    125       1.1    jruoho                         ASL_WALK_VISIT_UPWARD, NULL,
    126       1.1    jruoho                         AnMethodTypingWalkEnd, NULL);
    127       1.1    jruoho 
    128   1.1.1.6  christos                     ThisOpBtype = AnGetBtype (Op->Asl.Child);
    129       1.1    jruoho                 }
    130       1.1    jruoho             }
    131       1.1    jruoho 
    132       1.1    jruoho             /* Returns a value, save the value type */
    133       1.1    jruoho 
    134       1.1    jruoho             if (Op->Asl.ParentMethod)
    135       1.1    jruoho             {
    136   1.1.1.6  christos                 Op->Asl.ParentMethod->Asl.AcpiBtype |= ThisOpBtype;
    137       1.1    jruoho             }
    138       1.1    jruoho         }
    139       1.1    jruoho         break;
    140       1.1    jruoho 
    141       1.1    jruoho     default:
    142   1.1.1.3  christos 
    143       1.1    jruoho         break;
    144       1.1    jruoho     }
    145       1.1    jruoho 
    146       1.1    jruoho     return (AE_OK);
    147       1.1    jruoho }
    148       1.1    jruoho 
    149       1.1    jruoho 
    150       1.1    jruoho /*******************************************************************************
    151       1.1    jruoho  *
    152       1.1    jruoho  * FUNCTION:    AnOperandTypecheckWalkEnd
    153       1.1    jruoho  *
    154       1.1    jruoho  * PARAMETERS:  ASL_WALK_CALLBACK
    155       1.1    jruoho  *
    156       1.1    jruoho  * RETURN:      Status
    157       1.1    jruoho  *
    158       1.1    jruoho  * DESCRIPTION: Ascending callback for analysis walk. Complete method
    159       1.1    jruoho  *              return analysis.
    160       1.1    jruoho  *
    161       1.1    jruoho  ******************************************************************************/
    162       1.1    jruoho 
    163       1.1    jruoho ACPI_STATUS
    164       1.1    jruoho AnOperandTypecheckWalkEnd (
    165       1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
    166       1.1    jruoho     UINT32                  Level,
    167       1.1    jruoho     void                    *Context)
    168       1.1    jruoho {
    169       1.1    jruoho     const ACPI_OPCODE_INFO  *OpInfo;
    170       1.1    jruoho     UINT32                  RuntimeArgTypes;
    171       1.1    jruoho     UINT32                  RuntimeArgTypes2;
    172       1.1    jruoho     UINT32                  RequiredBtypes;
    173       1.1    jruoho     UINT32                  ThisNodeBtype;
    174       1.1    jruoho     UINT32                  CommonBtypes;
    175       1.1    jruoho     UINT32                  OpcodeClass;
    176       1.1    jruoho     ACPI_PARSE_OBJECT       *ArgOp;
    177       1.1    jruoho     UINT32                  ArgType;
    178       1.1    jruoho 
    179       1.1    jruoho 
    180       1.1    jruoho     switch (Op->Asl.AmlOpcode)
    181       1.1    jruoho     {
    182       1.1    jruoho     case AML_RAW_DATA_BYTE:
    183       1.1    jruoho     case AML_RAW_DATA_WORD:
    184       1.1    jruoho     case AML_RAW_DATA_DWORD:
    185       1.1    jruoho     case AML_RAW_DATA_QWORD:
    186       1.1    jruoho     case AML_RAW_DATA_BUFFER:
    187       1.1    jruoho     case AML_RAW_DATA_CHAIN:
    188       1.1    jruoho     case AML_PACKAGE_LENGTH:
    189       1.1    jruoho     case AML_UNASSIGNED_OPCODE:
    190       1.1    jruoho     case AML_DEFAULT_ARG_OP:
    191       1.1    jruoho 
    192       1.1    jruoho         /* Ignore the internal (compiler-only) AML opcodes */
    193       1.1    jruoho 
    194       1.1    jruoho         return (AE_OK);
    195       1.1    jruoho 
    196       1.1    jruoho     default:
    197   1.1.1.3  christos 
    198       1.1    jruoho         break;
    199       1.1    jruoho     }
    200       1.1    jruoho 
    201       1.1    jruoho     OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
    202       1.1    jruoho     if (!OpInfo)
    203       1.1    jruoho     {
    204       1.1    jruoho         return (AE_OK);
    205       1.1    jruoho     }
    206       1.1    jruoho 
    207   1.1.1.6  christos     ArgOp = Op->Asl.Child;
    208   1.1.1.6  christos     OpcodeClass = OpInfo->Class;
    209       1.1    jruoho     RuntimeArgTypes = OpInfo->RuntimeArgs;
    210       1.1    jruoho 
    211       1.1    jruoho #ifdef ASL_ERROR_NAMED_OBJECT_IN_WHILE
    212       1.1    jruoho     /*
    213       1.1    jruoho      * Update 11/2008: In practice, we can't perform this check. A simple
    214       1.1    jruoho      * analysis is not sufficient. Also, it can cause errors when compiling
    215       1.1    jruoho      * disassembled code because of the way Switch operators are implemented
    216       1.1    jruoho      * (a While(One) loop with a named temp variable created within.)
    217       1.1    jruoho      */
    218       1.1    jruoho 
    219       1.1    jruoho     /*
    220       1.1    jruoho      * If we are creating a named object, check if we are within a while loop
    221       1.1    jruoho      * by checking if the parent is a WHILE op. This is a simple analysis, but
    222       1.1    jruoho      * probably sufficient for many cases.
    223       1.1    jruoho      *
    224       1.1    jruoho      * Allow Scope(), Buffer(), and Package().
    225       1.1    jruoho      */
    226       1.1    jruoho     if (((OpcodeClass == AML_CLASS_NAMED_OBJECT) && (Op->Asl.AmlOpcode != AML_SCOPE_OP)) ||
    227       1.1    jruoho         ((OpcodeClass == AML_CLASS_CREATE) && (OpInfo->Flags & AML_NSNODE)))
    228       1.1    jruoho     {
    229       1.1    jruoho         if (Op->Asl.Parent->Asl.AmlOpcode == AML_WHILE_OP)
    230       1.1    jruoho         {
    231       1.1    jruoho             AslError (ASL_ERROR, ASL_MSG_NAMED_OBJECT_IN_WHILE, Op, NULL);
    232       1.1    jruoho         }
    233       1.1    jruoho     }
    234       1.1    jruoho #endif
    235       1.1    jruoho 
    236       1.1    jruoho     /*
    237       1.1    jruoho      * Special case for control opcodes IF/RETURN/WHILE since they
    238       1.1    jruoho      * have no runtime arg list (at this time)
    239       1.1    jruoho      */
    240       1.1    jruoho     switch (Op->Asl.AmlOpcode)
    241       1.1    jruoho     {
    242       1.1    jruoho     case AML_IF_OP:
    243       1.1    jruoho     case AML_WHILE_OP:
    244       1.1    jruoho     case AML_RETURN_OP:
    245       1.1    jruoho 
    246       1.1    jruoho         if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL)
    247       1.1    jruoho         {
    248       1.1    jruoho             /* Check for an internal method */
    249       1.1    jruoho 
    250       1.1    jruoho             if (AnIsInternalMethod (ArgOp))
    251       1.1    jruoho             {
    252       1.1    jruoho                 return (AE_OK);
    253       1.1    jruoho             }
    254       1.1    jruoho 
    255       1.1    jruoho             /* The lone arg is a method call, check it */
    256       1.1    jruoho 
    257       1.1    jruoho             RequiredBtypes = AnMapArgTypeToBtype (ARGI_INTEGER);
    258       1.1    jruoho             if (Op->Asl.AmlOpcode == AML_RETURN_OP)
    259       1.1    jruoho             {
    260       1.1    jruoho                 RequiredBtypes = 0xFFFFFFFF;
    261       1.1    jruoho             }
    262       1.1    jruoho 
    263       1.1    jruoho             ThisNodeBtype = AnGetBtype (ArgOp);
    264       1.1    jruoho             if (ThisNodeBtype == ACPI_UINT32_MAX)
    265       1.1    jruoho             {
    266       1.1    jruoho                 return (AE_OK);
    267       1.1    jruoho             }
    268   1.1.1.6  christos 
    269       1.1    jruoho             AnCheckMethodReturnValue (Op, OpInfo, ArgOp,
    270       1.1    jruoho                 RequiredBtypes, ThisNodeBtype);
    271       1.1    jruoho         }
    272       1.1    jruoho         return (AE_OK);
    273       1.1    jruoho 
    274   1.1.1.5  christos     case AML_EXTERNAL_OP:
    275   1.1.1.5  christos         /*
    276   1.1.1.5  christos          * Not really a "runtime" opcode since it used by disassembler only.
    277   1.1.1.5  christos          * The parser will find any issues with the operands.
    278   1.1.1.5  christos          */
    279   1.1.1.5  christos         return (AE_OK);
    280   1.1.1.5  christos 
    281       1.1    jruoho     default:
    282   1.1.1.3  christos 
    283       1.1    jruoho         break;
    284       1.1    jruoho     }
    285       1.1    jruoho 
    286       1.1    jruoho     /* Ignore the non-executable opcodes */
    287       1.1    jruoho 
    288       1.1    jruoho     if (RuntimeArgTypes == ARGI_INVALID_OPCODE)
    289       1.1    jruoho     {
    290       1.1    jruoho         return (AE_OK);
    291       1.1    jruoho     }
    292       1.1    jruoho 
    293   1.1.1.6  christos     /*
    294   1.1.1.6  christos      * Special handling for certain opcodes.
    295   1.1.1.6  christos      */
    296   1.1.1.6  christos     switch (Op->Asl.AmlOpcode)
    297   1.1.1.6  christos     {
    298   1.1.1.6  christos         /* BankField has one TermArg */
    299   1.1.1.6  christos 
    300   1.1.1.6  christos     case AML_BANK_FIELD_OP:
    301   1.1.1.6  christos 
    302   1.1.1.6  christos         OpcodeClass = AML_CLASS_EXECUTE;
    303   1.1.1.6  christos         ArgOp = ArgOp->Asl.Next;
    304   1.1.1.6  christos         ArgOp = ArgOp->Asl.Next;
    305   1.1.1.6  christos         break;
    306   1.1.1.6  christos 
    307   1.1.1.6  christos         /* Operation Region has 2 TermArgs */
    308   1.1.1.6  christos 
    309   1.1.1.6  christos     case AML_REGION_OP:
    310   1.1.1.6  christos 
    311   1.1.1.6  christos         OpcodeClass = AML_CLASS_EXECUTE;
    312   1.1.1.6  christos         ArgOp = ArgOp->Asl.Next;
    313   1.1.1.6  christos         ArgOp = ArgOp->Asl.Next;
    314   1.1.1.6  christos         break;
    315   1.1.1.6  christos 
    316   1.1.1.6  christos         /* DataTableRegion has 3 TermArgs */
    317   1.1.1.6  christos 
    318   1.1.1.6  christos     case AML_DATA_REGION_OP:
    319   1.1.1.6  christos 
    320   1.1.1.6  christos         OpcodeClass = AML_CLASS_EXECUTE;
    321   1.1.1.6  christos         ArgOp = ArgOp->Asl.Next;
    322   1.1.1.6  christos         break;
    323   1.1.1.6  christos 
    324   1.1.1.6  christos         /* Buffers/Packages have a length that is a TermArg */
    325   1.1.1.6  christos 
    326   1.1.1.6  christos     case AML_BUFFER_OP:
    327   1.1.1.6  christos     case AML_PACKAGE_OP:
    328   1.1.1.9  christos     case AML_VARIABLE_PACKAGE_OP:
    329   1.1.1.6  christos 
    330   1.1.1.6  christos             /* If length is a constant, we are done */
    331   1.1.1.6  christos 
    332   1.1.1.6  christos         if ((ArgOp->Asl.ParseOpcode == PARSEOP_INTEGER) ||
    333   1.1.1.6  christos             (ArgOp->Asl.ParseOpcode == PARSEOP_RAW_DATA))
    334   1.1.1.6  christos         {
    335   1.1.1.6  christos             return (AE_OK);
    336   1.1.1.6  christos         }
    337   1.1.1.6  christos         break;
    338   1.1.1.6  christos 
    339   1.1.1.6  christos         /* Store can write any object to the Debug object */
    340   1.1.1.6  christos 
    341   1.1.1.6  christos     case AML_STORE_OP:
    342   1.1.1.6  christos         /*
    343   1.1.1.6  christos          * If this is a Store() to the Debug object, we don't need
    344   1.1.1.6  christos          * to perform any further validation -- because a Store of
    345   1.1.1.6  christos          * any object to Debug is permitted and supported.
    346   1.1.1.6  christos          */
    347   1.1.1.6  christos         if (ArgOp->Asl.Next->Asl.AmlOpcode == AML_DEBUG_OP)
    348   1.1.1.6  christos         {
    349   1.1.1.6  christos             return (AE_OK);
    350   1.1.1.6  christos         }
    351   1.1.1.6  christos         break;
    352   1.1.1.6  christos 
    353   1.1.1.6  christos     default:
    354   1.1.1.6  christos         break;
    355   1.1.1.6  christos     }
    356   1.1.1.6  christos 
    357       1.1    jruoho     switch (OpcodeClass)
    358       1.1    jruoho     {
    359       1.1    jruoho     case AML_CLASS_EXECUTE:
    360       1.1    jruoho     case AML_CLASS_CREATE:
    361       1.1    jruoho     case AML_CLASS_CONTROL:
    362       1.1    jruoho     case AML_CLASS_RETURN_VALUE:
    363       1.1    jruoho 
    364       1.1    jruoho         /* Reverse the runtime argument list */
    365       1.1    jruoho 
    366       1.1    jruoho         RuntimeArgTypes2 = 0;
    367       1.1    jruoho         while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes)))
    368       1.1    jruoho         {
    369       1.1    jruoho             RuntimeArgTypes2 <<= ARG_TYPE_WIDTH;
    370       1.1    jruoho             RuntimeArgTypes2 |= ArgType;
    371       1.1    jruoho             INCREMENT_ARG_LIST (RuntimeArgTypes);
    372       1.1    jruoho         }
    373       1.1    jruoho 
    374   1.1.1.6  christos         /* Typecheck each argument */
    375   1.1.1.6  christos 
    376       1.1    jruoho         while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes2)))
    377       1.1    jruoho         {
    378   1.1.1.6  christos             /* Get the required type(s) for the argument */
    379   1.1.1.6  christos 
    380       1.1    jruoho             RequiredBtypes = AnMapArgTypeToBtype (ArgType);
    381       1.1    jruoho 
    382   1.1.1.5  christos             if (!ArgOp)
    383   1.1.1.5  christos             {
    384   1.1.1.5  christos                 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
    385   1.1.1.5  christos                     "Null ArgOp in argument loop");
    386   1.1.1.5  christos                 AslAbort ();
    387   1.1.1.5  christos             }
    388   1.1.1.5  christos 
    389   1.1.1.6  christos             /* Get the actual type of the argument */
    390   1.1.1.6  christos 
    391       1.1    jruoho             ThisNodeBtype = AnGetBtype (ArgOp);
    392       1.1    jruoho             if (ThisNodeBtype == ACPI_UINT32_MAX)
    393       1.1    jruoho             {
    394       1.1    jruoho                 goto NextArgument;
    395       1.1    jruoho             }
    396       1.1    jruoho 
    397       1.1    jruoho             /* Examine the arg based on the required type of the arg */
    398       1.1    jruoho 
    399       1.1    jruoho             switch (ArgType)
    400       1.1    jruoho             {
    401       1.1    jruoho             case ARGI_TARGETREF:
    402       1.1    jruoho 
    403       1.1    jruoho                 if (ArgOp->Asl.ParseOpcode == PARSEOP_ZERO)
    404       1.1    jruoho                 {
    405       1.1    jruoho                     /* ZERO is the placeholder for "don't store result" */
    406       1.1    jruoho 
    407       1.1    jruoho                     ThisNodeBtype = RequiredBtypes;
    408       1.1    jruoho                     break;
    409       1.1    jruoho                 }
    410       1.1    jruoho 
    411  1.1.1.16  christos                 ACPI_FALLTHROUGH;
    412   1.1.1.6  christos 
    413   1.1.1.6  christos             case ARGI_STORE_TARGET:
    414   1.1.1.6  christos 
    415       1.1    jruoho                 if (ArgOp->Asl.ParseOpcode == PARSEOP_INTEGER)
    416       1.1    jruoho                 {
    417       1.1    jruoho                     /*
    418       1.1    jruoho                      * This is the case where an original reference to a resource
    419       1.1    jruoho                      * descriptor field has been replaced by an (Integer) offset.
    420       1.1    jruoho                      * These named fields are supported at compile-time only;
    421       1.1    jruoho                      * the names are not passed to the interpreter (via the AML).
    422       1.1    jruoho                      */
    423       1.1    jruoho                     if ((ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
    424       1.1    jruoho                         (ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
    425       1.1    jruoho                     {
    426   1.1.1.6  christos                         AslError (ASL_ERROR, ASL_MSG_RESOURCE_FIELD,
    427   1.1.1.6  christos                             ArgOp, NULL);
    428       1.1    jruoho                     }
    429       1.1    jruoho                     else
    430       1.1    jruoho                     {
    431   1.1.1.6  christos                         AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE,
    432   1.1.1.6  christos                             ArgOp, NULL);
    433       1.1    jruoho                     }
    434       1.1    jruoho                 }
    435       1.1    jruoho                 break;
    436       1.1    jruoho 
    437       1.1    jruoho 
    438   1.1.1.6  christos #ifdef __FUTURE_IMPLEMENTATION
    439   1.1.1.6  christos /*
    440   1.1.1.6  christos  * Possible future typechecking support
    441   1.1.1.6  christos  */
    442       1.1    jruoho             case ARGI_REFERENCE:            /* References */
    443       1.1    jruoho             case ARGI_INTEGER_REF:
    444       1.1    jruoho             case ARGI_OBJECT_REF:
    445       1.1    jruoho             case ARGI_DEVICE_REF:
    446       1.1    jruoho 
    447       1.1    jruoho                 switch (ArgOp->Asl.ParseOpcode)
    448       1.1    jruoho                 {
    449       1.1    jruoho                 case PARSEOP_LOCAL0:
    450       1.1    jruoho                 case PARSEOP_LOCAL1:
    451       1.1    jruoho                 case PARSEOP_LOCAL2:
    452       1.1    jruoho                 case PARSEOP_LOCAL3:
    453       1.1    jruoho                 case PARSEOP_LOCAL4:
    454       1.1    jruoho                 case PARSEOP_LOCAL5:
    455       1.1    jruoho                 case PARSEOP_LOCAL6:
    456       1.1    jruoho                 case PARSEOP_LOCAL7:
    457       1.1    jruoho 
    458       1.1    jruoho                     /* TBD: implement analysis of current value (type) of the local */
    459       1.1    jruoho                     /* For now, just treat any local as a typematch */
    460       1.1    jruoho 
    461       1.1    jruoho                     /*ThisNodeBtype = RequiredBtypes;*/
    462       1.1    jruoho                     break;
    463       1.1    jruoho 
    464       1.1    jruoho                 case PARSEOP_ARG0:
    465       1.1    jruoho                 case PARSEOP_ARG1:
    466       1.1    jruoho                 case PARSEOP_ARG2:
    467       1.1    jruoho                 case PARSEOP_ARG3:
    468       1.1    jruoho                 case PARSEOP_ARG4:
    469       1.1    jruoho                 case PARSEOP_ARG5:
    470       1.1    jruoho                 case PARSEOP_ARG6:
    471       1.1    jruoho 
    472   1.1.1.6  christos                     /* Hard to analyze argument types, so we won't */
    473   1.1.1.6  christos                     /* for now. Just treat any arg as a typematch */
    474       1.1    jruoho 
    475       1.1    jruoho                     /* ThisNodeBtype = RequiredBtypes; */
    476       1.1    jruoho                     break;
    477       1.1    jruoho 
    478       1.1    jruoho                 case PARSEOP_DEBUG:
    479       1.1    jruoho                 case PARSEOP_REFOF:
    480       1.1    jruoho                 case PARSEOP_INDEX:
    481       1.1    jruoho                 default:
    482   1.1.1.3  christos 
    483       1.1    jruoho                     break;
    484       1.1    jruoho                 }
    485       1.1    jruoho                 break;
    486   1.1.1.6  christos #endif
    487       1.1    jruoho             case ARGI_INTEGER:
    488       1.1    jruoho             default:
    489   1.1.1.3  christos 
    490       1.1    jruoho                 break;
    491       1.1    jruoho             }
    492       1.1    jruoho 
    493       1.1    jruoho 
    494   1.1.1.6  christos             /* Check for a type mismatch (required versus actual) */
    495   1.1.1.6  christos 
    496       1.1    jruoho             CommonBtypes = ThisNodeBtype & RequiredBtypes;
    497       1.1    jruoho 
    498       1.1    jruoho             if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL)
    499       1.1    jruoho             {
    500       1.1    jruoho                 if (AnIsInternalMethod (ArgOp))
    501       1.1    jruoho                 {
    502       1.1    jruoho                     return (AE_OK);
    503       1.1    jruoho                 }
    504       1.1    jruoho 
    505       1.1    jruoho                 /* Check a method call for a valid return value */
    506       1.1    jruoho 
    507       1.1    jruoho                 AnCheckMethodReturnValue (Op, OpInfo, ArgOp,
    508       1.1    jruoho                     RequiredBtypes, ThisNodeBtype);
    509       1.1    jruoho             }
    510       1.1    jruoho 
    511       1.1    jruoho             /*
    512       1.1    jruoho              * Now check if the actual type(s) match at least one
    513       1.1    jruoho              * bit to the required type
    514       1.1    jruoho              */
    515       1.1    jruoho             else if (!CommonBtypes)
    516       1.1    jruoho             {
    517       1.1    jruoho                 /* No match -- this is a type mismatch error */
    518       1.1    jruoho 
    519  1.1.1.12  christos                 AnFormatBtype (AslGbl_StringBuffer, ThisNodeBtype);
    520  1.1.1.12  christos                 AnFormatBtype (AslGbl_StringBuffer2, RequiredBtypes);
    521       1.1    jruoho 
    522  1.1.1.12  christos                 sprintf (AslGbl_MsgBuffer, "[%s] found, %s operator requires [%s]",
    523  1.1.1.12  christos                     AslGbl_StringBuffer, OpInfo->Name, AslGbl_StringBuffer2);
    524       1.1    jruoho 
    525   1.1.1.6  christos                 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE,
    526  1.1.1.12  christos                     ArgOp, AslGbl_MsgBuffer);
    527       1.1    jruoho             }
    528       1.1    jruoho 
    529       1.1    jruoho         NextArgument:
    530       1.1    jruoho             ArgOp = ArgOp->Asl.Next;
    531       1.1    jruoho             INCREMENT_ARG_LIST (RuntimeArgTypes2);
    532       1.1    jruoho         }
    533       1.1    jruoho         break;
    534       1.1    jruoho 
    535       1.1    jruoho     default:
    536   1.1.1.3  christos 
    537       1.1    jruoho         break;
    538       1.1    jruoho     }
    539       1.1    jruoho 
    540       1.1    jruoho     return (AE_OK);
    541       1.1    jruoho }
    542       1.1    jruoho 
    543       1.1    jruoho 
    544       1.1    jruoho /*******************************************************************************
    545       1.1    jruoho  *
    546       1.1    jruoho  * FUNCTION:    AnOtherSemanticAnalysisWalkBegin
    547       1.1    jruoho  *
    548       1.1    jruoho  * PARAMETERS:  ASL_WALK_CALLBACK
    549       1.1    jruoho  *
    550       1.1    jruoho  * RETURN:      Status
    551       1.1    jruoho  *
    552       1.1    jruoho  * DESCRIPTION: Descending callback for the analysis walk. Checks for
    553       1.1    jruoho  *              miscellaneous issues in the code.
    554       1.1    jruoho  *
    555       1.1    jruoho  ******************************************************************************/
    556       1.1    jruoho 
    557       1.1    jruoho ACPI_STATUS
    558       1.1    jruoho AnOtherSemanticAnalysisWalkBegin (
    559       1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
    560       1.1    jruoho     UINT32                  Level,
    561       1.1    jruoho     void                    *Context)
    562       1.1    jruoho {
    563   1.1.1.6  christos     ACPI_PARSE_OBJECT       *ArgOp;
    564   1.1.1.6  christos     ACPI_PARSE_OBJECT       *PrevArgOp = NULL;
    565       1.1    jruoho     const ACPI_OPCODE_INFO  *OpInfo;
    566   1.1.1.3  christos     ACPI_NAMESPACE_NODE     *Node;
    567       1.1    jruoho 
    568       1.1    jruoho 
    569       1.1    jruoho     OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
    570       1.1    jruoho 
    571   1.1.1.6  christos 
    572  1.1.1.14  christos     if (OpInfo->Flags & AML_CREATE)
    573  1.1.1.14  christos     {
    574  1.1.1.14  christos         /* This group contains all of the Create Buffer Field operators */
    575  1.1.1.14  christos 
    576  1.1.1.14  christos         AnValidateCreateBufferField (Op);
    577  1.1.1.14  christos         return (AE_OK);
    578  1.1.1.14  christos     }
    579  1.1.1.14  christos 
    580       1.1    jruoho     /*
    581       1.1    jruoho      * Determine if an execution class operator actually does something by
    582       1.1    jruoho      * checking if it has a target and/or the function return value is used.
    583       1.1    jruoho      * (Target is optional, so a standalone statement can actually do nothing.)
    584       1.1    jruoho      */
    585       1.1    jruoho     if ((OpInfo->Class == AML_CLASS_EXECUTE) &&
    586       1.1    jruoho         (OpInfo->Flags & AML_HAS_RETVAL) &&
    587       1.1    jruoho         (!AnIsResultUsed (Op)))
    588       1.1    jruoho     {
    589       1.1    jruoho         if (OpInfo->Flags & AML_HAS_TARGET)
    590       1.1    jruoho         {
    591       1.1    jruoho             /*
    592   1.1.1.6  christos              * Find the target node, it is always the last child. If the target
    593       1.1    jruoho              * is not specified in the ASL, a default node of type Zero was
    594       1.1    jruoho              * created by the parser.
    595       1.1    jruoho              */
    596   1.1.1.6  christos             ArgOp = Op->Asl.Child;
    597   1.1.1.6  christos             while (ArgOp->Asl.Next)
    598       1.1    jruoho             {
    599   1.1.1.6  christos                 PrevArgOp = ArgOp;
    600   1.1.1.6  christos                 ArgOp = ArgOp->Asl.Next;
    601       1.1    jruoho             }
    602       1.1    jruoho 
    603       1.1    jruoho             /* Divide() is the only weird case, it has two targets */
    604       1.1    jruoho 
    605       1.1    jruoho             if (Op->Asl.AmlOpcode == AML_DIVIDE_OP)
    606       1.1    jruoho             {
    607   1.1.1.6  christos                 if ((ArgOp->Asl.ParseOpcode == PARSEOP_ZERO) &&
    608   1.1.1.6  christos                     (PrevArgOp) &&
    609   1.1.1.6  christos                     (PrevArgOp->Asl.ParseOpcode == PARSEOP_ZERO))
    610       1.1    jruoho                 {
    611   1.1.1.3  christos                     AslError (ASL_ERROR, ASL_MSG_RESULT_NOT_USED,
    612       1.1    jruoho                         Op, Op->Asl.ExternalName);
    613       1.1    jruoho                 }
    614       1.1    jruoho             }
    615   1.1.1.6  christos 
    616   1.1.1.6  christos             else if (ArgOp->Asl.ParseOpcode == PARSEOP_ZERO)
    617       1.1    jruoho             {
    618   1.1.1.3  christos                 AslError (ASL_ERROR, ASL_MSG_RESULT_NOT_USED,
    619       1.1    jruoho                     Op, Op->Asl.ExternalName);
    620       1.1    jruoho             }
    621       1.1    jruoho         }
    622       1.1    jruoho         else
    623       1.1    jruoho         {
    624       1.1    jruoho             /*
    625       1.1    jruoho              * Has no target and the result is not used. Only a couple opcodes
    626       1.1    jruoho              * can have this combination.
    627       1.1    jruoho              */
    628       1.1    jruoho             switch (Op->Asl.ParseOpcode)
    629       1.1    jruoho             {
    630       1.1    jruoho             case PARSEOP_ACQUIRE:
    631       1.1    jruoho             case PARSEOP_WAIT:
    632       1.1    jruoho             case PARSEOP_LOADTABLE:
    633   1.1.1.3  christos 
    634       1.1    jruoho                 break;
    635       1.1    jruoho 
    636       1.1    jruoho             default:
    637   1.1.1.3  christos 
    638   1.1.1.3  christos                 AslError (ASL_ERROR, ASL_MSG_RESULT_NOT_USED,
    639       1.1    jruoho                     Op, Op->Asl.ExternalName);
    640       1.1    jruoho                 break;
    641       1.1    jruoho             }
    642       1.1    jruoho         }
    643       1.1    jruoho     }
    644       1.1    jruoho 
    645       1.1    jruoho     /*
    646       1.1    jruoho      * Semantic checks for individual ASL operators
    647       1.1    jruoho      */
    648  1.1.1.14  christos 
    649       1.1    jruoho     switch (Op->Asl.ParseOpcode)
    650       1.1    jruoho     {
    651   1.1.1.6  christos     case PARSEOP_STORE:
    652   1.1.1.6  christos 
    653  1.1.1.12  christos         if (AslGbl_DoTypechecking)
    654   1.1.1.6  christos         {
    655   1.1.1.6  christos             AnAnalyzeStoreOperator (Op);
    656   1.1.1.6  christos         }
    657   1.1.1.6  christos         break;
    658   1.1.1.6  christos 
    659   1.1.1.6  christos 
    660       1.1    jruoho     case PARSEOP_ACQUIRE:
    661       1.1    jruoho     case PARSEOP_WAIT:
    662       1.1    jruoho         /*
    663       1.1    jruoho          * Emit a warning if the timeout parameter for these operators is not
    664       1.1    jruoho          * ACPI_WAIT_FOREVER, and the result value from the operator is not
    665       1.1    jruoho          * checked, meaning that a timeout could happen, but the code
    666       1.1    jruoho          * would not know about it.
    667       1.1    jruoho          */
    668       1.1    jruoho 
    669       1.1    jruoho         /* First child is the namepath, 2nd child is timeout */
    670       1.1    jruoho 
    671   1.1.1.6  christos         ArgOp = Op->Asl.Child;
    672   1.1.1.6  christos         ArgOp = ArgOp->Asl.Next;
    673       1.1    jruoho 
    674       1.1    jruoho         /*
    675       1.1    jruoho          * Check for the WAIT_FOREVER case - defined by the ACPI spec to be
    676       1.1    jruoho          * 0xFFFF or greater
    677       1.1    jruoho          */
    678   1.1.1.6  christos         if (((ArgOp->Asl.ParseOpcode == PARSEOP_WORDCONST) ||
    679   1.1.1.6  christos              (ArgOp->Asl.ParseOpcode == PARSEOP_INTEGER))  &&
    680   1.1.1.6  christos              (ArgOp->Asl.Value.Integer >= (UINT64) ACPI_WAIT_FOREVER))
    681       1.1    jruoho         {
    682       1.1    jruoho             break;
    683       1.1    jruoho         }
    684       1.1    jruoho 
    685       1.1    jruoho         /*
    686       1.1    jruoho          * The operation could timeout. If the return value is not used
    687       1.1    jruoho          * (indicates timeout occurred), issue a warning
    688       1.1    jruoho          */
    689       1.1    jruoho         if (!AnIsResultUsed (Op))
    690       1.1    jruoho         {
    691   1.1.1.6  christos             AslError (ASL_WARNING, ASL_MSG_TIMEOUT, ArgOp,
    692       1.1    jruoho                 Op->Asl.ExternalName);
    693       1.1    jruoho         }
    694       1.1    jruoho         break;
    695       1.1    jruoho 
    696   1.1.1.3  christos     case PARSEOP_CONNECTION:
    697   1.1.1.3  christos         /*
    698   1.1.1.3  christos          * Ensure that the referenced operation region has the correct SPACE_ID.
    699   1.1.1.3  christos          * From the grammar/parser, we know the parent is a FIELD definition.
    700   1.1.1.3  christos          */
    701   1.1.1.6  christos         ArgOp = Op->Asl.Parent;     /* Field definition */
    702   1.1.1.6  christos         ArgOp = ArgOp->Asl.Child;   /* First child is the OpRegion Name */
    703   1.1.1.6  christos         Node = ArgOp->Asl.Node;     /* OpRegion namespace node */
    704   1.1.1.4  christos         if (!Node)
    705   1.1.1.4  christos         {
    706   1.1.1.4  christos             break;
    707   1.1.1.4  christos         }
    708   1.1.1.3  christos 
    709   1.1.1.6  christos         ArgOp = Node->Op;           /* OpRegion definition */
    710   1.1.1.6  christos         ArgOp = ArgOp->Asl.Child;   /* First child is the OpRegion Name */
    711   1.1.1.6  christos         ArgOp = ArgOp->Asl.Next;    /* Next peer is the SPACE_ID (what we want) */
    712   1.1.1.3  christos 
    713   1.1.1.3  christos         /*
    714   1.1.1.3  christos          * The Connection() operator is only valid for the following operation
    715   1.1.1.3  christos          * region SpaceIds: GeneralPurposeIo and GenericSerialBus.
    716   1.1.1.3  christos          */
    717   1.1.1.6  christos         if ((ArgOp->Asl.Value.Integer != ACPI_ADR_SPACE_GPIO) &&
    718   1.1.1.6  christos             (ArgOp->Asl.Value.Integer != ACPI_ADR_SPACE_GSBUS))
    719   1.1.1.3  christos         {
    720   1.1.1.3  christos             AslError (ASL_ERROR, ASL_MSG_CONNECTION_INVALID, Op, NULL);
    721   1.1.1.3  christos         }
    722   1.1.1.3  christos         break;
    723   1.1.1.3  christos 
    724   1.1.1.3  christos     case PARSEOP_FIELD:
    725   1.1.1.3  christos         /*
    726   1.1.1.3  christos          * Ensure that fields for GeneralPurposeIo and GenericSerialBus
    727   1.1.1.3  christos          * contain at least one Connection() operator
    728   1.1.1.3  christos          */
    729   1.1.1.6  christos         ArgOp = Op->Asl.Child;      /* 1st child is the OpRegion Name */
    730   1.1.1.6  christos         Node = ArgOp->Asl.Node;     /* OpRegion namespace node */
    731   1.1.1.3  christos         if (!Node)
    732   1.1.1.3  christos         {
    733   1.1.1.3  christos             break;
    734   1.1.1.3  christos         }
    735   1.1.1.3  christos 
    736   1.1.1.6  christos         ArgOp = Node->Op;           /* OpRegion definition */
    737   1.1.1.6  christos         ArgOp = ArgOp->Asl.Child;   /* First child is the OpRegion Name */
    738   1.1.1.6  christos         ArgOp = ArgOp->Asl.Next;    /* Next peer is the SPACE_ID (what we want) */
    739   1.1.1.3  christos 
    740   1.1.1.3  christos         /* We are only interested in GeneralPurposeIo and GenericSerialBus */
    741   1.1.1.3  christos 
    742   1.1.1.6  christos         if ((ArgOp->Asl.Value.Integer != ACPI_ADR_SPACE_GPIO) &&
    743   1.1.1.6  christos             (ArgOp->Asl.Value.Integer != ACPI_ADR_SPACE_GSBUS))
    744   1.1.1.3  christos         {
    745   1.1.1.3  christos             break;
    746   1.1.1.3  christos         }
    747   1.1.1.3  christos 
    748   1.1.1.6  christos         ArgOp = Op->Asl.Child;      /* 1st child is the OpRegion Name */
    749   1.1.1.6  christos         ArgOp = ArgOp->Asl.Next;    /* AccessType */
    750   1.1.1.6  christos         ArgOp = ArgOp->Asl.Next;    /* LockRule */
    751   1.1.1.6  christos         ArgOp = ArgOp->Asl.Next;    /* UpdateRule */
    752   1.1.1.6  christos         ArgOp = ArgOp->Asl.Next;    /* Start of FieldUnitList */
    753   1.1.1.3  christos 
    754   1.1.1.3  christos         /* Walk the FieldUnitList */
    755   1.1.1.3  christos 
    756   1.1.1.6  christos         while (ArgOp)
    757   1.1.1.3  christos         {
    758   1.1.1.6  christos             if (ArgOp->Asl.ParseOpcode == PARSEOP_CONNECTION)
    759   1.1.1.3  christos             {
    760   1.1.1.3  christos                 break;
    761   1.1.1.3  christos             }
    762   1.1.1.6  christos             else if (ArgOp->Asl.ParseOpcode == PARSEOP_NAMESEG)
    763   1.1.1.3  christos             {
    764   1.1.1.6  christos                 AslError (ASL_ERROR, ASL_MSG_CONNECTION_MISSING, ArgOp, NULL);
    765   1.1.1.3  christos                 break;
    766   1.1.1.3  christos             }
    767   1.1.1.3  christos 
    768   1.1.1.6  christos             ArgOp = ArgOp->Asl.Next;
    769   1.1.1.3  christos         }
    770   1.1.1.3  christos         break;
    771   1.1.1.3  christos 
    772       1.1    jruoho     default:
    773   1.1.1.3  christos 
    774       1.1    jruoho         break;
    775       1.1    jruoho     }
    776       1.1    jruoho 
    777       1.1    jruoho     return (AE_OK);
    778       1.1    jruoho }
    779   1.1.1.6  christos 
    780   1.1.1.6  christos 
    781   1.1.1.6  christos /*******************************************************************************
    782   1.1.1.6  christos  *
    783  1.1.1.14  christos  * FUNCTION:    AnValidateCreateBufferField
    784  1.1.1.14  christos  *
    785  1.1.1.14  christos  * PARAMETERS:  Op                  - A create buffer field operator
    786  1.1.1.14  christos  *
    787  1.1.1.14  christos  * RETURN:      None
    788  1.1.1.14  christos  *
    789  1.1.1.14  christos  * DESCRIPTION: Check if a buffer index argument to a create buffer field
    790  1.1.1.14  christos  *              operation is beyond the end of the target buffer.
    791  1.1.1.14  christos  *
    792  1.1.1.14  christos  *  Validates these AML operators:
    793  1.1.1.14  christos  *
    794  1.1.1.14  christos  *  AML_CREATE_FIELD_OP
    795  1.1.1.14  christos  *  AML_CREATE_BIT_FIELD_OP
    796  1.1.1.14  christos  *  AML_CREATE_BYTE_FIELD_OP
    797  1.1.1.14  christos  *  AML_CREATE_WORD_FIELD_OP
    798  1.1.1.14  christos  *  AML_CREATE_DWORD_FIELD_OP
    799  1.1.1.14  christos  *  AML_CREATE_QWORD_FIELD_OP
    800  1.1.1.14  christos  *
    801  1.1.1.14  christos  *  There are two conditions that must be satisfied in order to enable
    802  1.1.1.14  christos  *  validation at compile time:
    803  1.1.1.14  christos  *
    804  1.1.1.14  christos  *  1) The length of the target buffer must be an integer constant
    805  1.1.1.14  christos  *  2) The index specified in the create* must be an integer constant
    806  1.1.1.14  christos  *  3) For CreateField, the bit length argument must be non-zero.
    807  1.1.1.14  christos  *
    808  1.1.1.14  christos  ******************************************************************************/
    809  1.1.1.14  christos 
    810  1.1.1.14  christos static void
    811  1.1.1.14  christos AnValidateCreateBufferField (
    812  1.1.1.14  christos     ACPI_PARSE_OBJECT       *CreateBufferFieldOp)
    813  1.1.1.14  christos {
    814  1.1.1.14  christos     ACPI_PARSE_OBJECT       *TargetBufferOp;
    815  1.1.1.14  christos     ACPI_PARSE_OBJECT       *ArgOp;
    816  1.1.1.14  christos     UINT32                  TargetBufferLength;
    817  1.1.1.14  christos     UINT32                  LastFieldByteIndex;
    818  1.1.1.14  christos 
    819  1.1.1.14  christos 
    820  1.1.1.14  christos     /*
    821  1.1.1.14  christos      * 1) Get the length of the target buffer
    822  1.1.1.14  christos      */
    823  1.1.1.14  christos     ArgOp = CreateBufferFieldOp->Asl.Child;     /* Reference to target buffer */
    824  1.1.1.14  christos 
    825  1.1.1.14  christos     /*
    826  1.1.1.14  christos      * If no attached Node, the target buffer may be something like an
    827  1.1.1.14  christos      * ArgX or LocalX and cannot be evaluated at compile time.
    828  1.1.1.14  christos      */
    829  1.1.1.14  christos     if (!ArgOp->Asl.Node)
    830  1.1.1.14  christos     {
    831  1.1.1.14  christos         return;
    832  1.1.1.14  christos     }
    833  1.1.1.14  christos 
    834  1.1.1.14  christos     TargetBufferOp = ArgOp->Asl.Node->Op;
    835  1.1.1.14  christos     TargetBufferOp = TargetBufferOp->Asl.Child; /* Target buffer */
    836  1.1.1.14  christos     TargetBufferOp = TargetBufferOp->Asl.Next;  /* "Buffer" keyword */
    837  1.1.1.14  christos     if (!TargetBufferOp)
    838  1.1.1.14  christos     {
    839  1.1.1.14  christos         /* Not a statement of the form NAME(XXXX, Buffer.... */
    840  1.1.1.14  christos 
    841  1.1.1.14  christos         return;
    842  1.1.1.14  christos     }
    843  1.1.1.14  christos 
    844  1.1.1.14  christos     /* Get the buffer length argument. It must be an integer constant */
    845  1.1.1.14  christos 
    846  1.1.1.14  christos     ArgOp = TargetBufferOp->Asl.Child;
    847  1.1.1.14  christos     if (!AnIsValidBufferConstant (ArgOp))
    848  1.1.1.14  christos     {
    849  1.1.1.14  christos         return;
    850  1.1.1.14  christos     }
    851  1.1.1.14  christos 
    852  1.1.1.14  christos     TargetBufferLength = (UINT32) ArgOp->Asl.Value.Integer;
    853  1.1.1.14  christos 
    854  1.1.1.14  christos     /*
    855  1.1.1.14  christos      * 2) Get the value of the buffer index argument. It must be
    856  1.1.1.14  christos      * an integer constant.
    857  1.1.1.14  christos      */
    858  1.1.1.14  christos     ArgOp = CreateBufferFieldOp->Asl.Child;     /* Reference to target buffer */
    859  1.1.1.14  christos     ArgOp = ArgOp->Asl.Next;                    /* Buffer Index argument*/
    860  1.1.1.14  christos     if (!AnIsValidBufferConstant (ArgOp))
    861  1.1.1.14  christos     {
    862  1.1.1.14  christos         return;
    863  1.1.1.14  christos     }
    864  1.1.1.14  christos 
    865  1.1.1.14  christos     LastFieldByteIndex =
    866  1.1.1.14  christos         (UINT32) ArgOp->Asl.Value.Integer;      /* Index can be in either bytes or bits */
    867  1.1.1.14  christos 
    868  1.1.1.14  christos     /*
    869  1.1.1.14  christos      * 3) Get the length of the new buffer field, in bytes. Also,
    870  1.1.1.14  christos      * create the final target buffer index for the last byte of the field
    871  1.1.1.14  christos      */
    872  1.1.1.14  christos     switch (CreateBufferFieldOp->Asl.ParseOpcode)
    873  1.1.1.14  christos     {
    874  1.1.1.14  christos     case PARSEOP_CREATEBITFIELD:                /* A one bit field */
    875  1.1.1.14  christos 
    876  1.1.1.14  christos         LastFieldByteIndex = ACPI_ROUND_BITS_DOWN_TO_BYTES (LastFieldByteIndex);
    877  1.1.1.14  christos         break;
    878  1.1.1.14  christos 
    879  1.1.1.14  christos     case PARSEOP_CREATEBYTEFIELD:
    880  1.1.1.14  christos         break;
    881  1.1.1.14  christos 
    882  1.1.1.14  christos     case PARSEOP_CREATEWORDFIELD:
    883  1.1.1.14  christos 
    884  1.1.1.14  christos         LastFieldByteIndex += (sizeof (UINT16) - 1);
    885  1.1.1.14  christos         break;
    886  1.1.1.14  christos 
    887  1.1.1.14  christos     case PARSEOP_CREATEDWORDFIELD:
    888  1.1.1.14  christos 
    889  1.1.1.14  christos         LastFieldByteIndex += (sizeof (UINT32) - 1);
    890  1.1.1.14  christos         break;
    891  1.1.1.14  christos 
    892  1.1.1.14  christos     case PARSEOP_CREATEQWORDFIELD:
    893  1.1.1.14  christos 
    894  1.1.1.14  christos         LastFieldByteIndex += (sizeof (UINT64) - 1);
    895  1.1.1.14  christos         break;
    896  1.1.1.14  christos 
    897  1.1.1.14  christos     case PARSEOP_CREATEFIELD:                   /* Multi-bit field */
    898  1.1.1.14  christos 
    899  1.1.1.14  christos         ArgOp = ArgOp->Asl.Next;                /* Length argument, in bits */
    900  1.1.1.14  christos         if (!AnIsValidBufferConstant (ArgOp))
    901  1.1.1.14  christos         {
    902  1.1.1.14  christos             return;
    903  1.1.1.14  christos         }
    904  1.1.1.14  christos 
    905  1.1.1.14  christos         /* The buffer field length is not allowed to be zero */
    906  1.1.1.14  christos 
    907  1.1.1.14  christos         if (ArgOp->Asl.Value.Integer == 0)
    908  1.1.1.14  christos         {
    909  1.1.1.14  christos             AslError (ASL_WARNING,  ASL_MSG_BUFFER_FIELD_LENGTH, ArgOp, NULL);
    910  1.1.1.14  christos             return;
    911  1.1.1.14  christos         }
    912  1.1.1.14  christos 
    913  1.1.1.14  christos         LastFieldByteIndex +=
    914  1.1.1.14  christos             ((UINT32) ArgOp->Asl.Value.Integer - 1);    /* Create final bit index */
    915  1.1.1.14  christos 
    916  1.1.1.14  christos         /* Convert bit index to a byte index */
    917  1.1.1.14  christos 
    918  1.1.1.14  christos         LastFieldByteIndex = ACPI_ROUND_BITS_DOWN_TO_BYTES (LastFieldByteIndex);
    919  1.1.1.14  christos         break;
    920  1.1.1.14  christos 
    921  1.1.1.14  christos     default:
    922  1.1.1.14  christos         return;
    923  1.1.1.14  christos     }
    924  1.1.1.14  christos 
    925  1.1.1.14  christos     /*
    926  1.1.1.14  christos      * 4) Check for an access (index) beyond the end of the target buffer,
    927  1.1.1.14  christos      * or a zero length target buffer.
    928  1.1.1.14  christos      */
    929  1.1.1.14  christos     if (!TargetBufferLength || (LastFieldByteIndex >= TargetBufferLength))
    930  1.1.1.14  christos     {
    931  1.1.1.14  christos         AslError (ASL_WARNING, ASL_MSG_BUFFER_FIELD_OVERFLOW, ArgOp, NULL);
    932  1.1.1.14  christos     }
    933  1.1.1.14  christos }
    934  1.1.1.14  christos 
    935  1.1.1.14  christos 
    936  1.1.1.14  christos /*******************************************************************************
    937  1.1.1.14  christos  *
    938  1.1.1.14  christos  * FUNCTION:    AnIsValidBufferConstant
    939  1.1.1.14  christos  *
    940  1.1.1.14  christos  * PARAMETERS:  Op                  - A buffer-related operand
    941  1.1.1.14  christos  *
    942  1.1.1.14  christos  * RETURN:      TRUE if operand is valid constant, FALSE otherwise
    943  1.1.1.14  christos  *
    944  1.1.1.14  christos  * DESCRIPTION: Check if the input Op is valid constant that can be used
    945  1.1.1.14  christos  *              in compile-time analysis.
    946  1.1.1.14  christos  *
    947  1.1.1.14  christos  ******************************************************************************/
    948  1.1.1.14  christos 
    949  1.1.1.14  christos static BOOLEAN
    950  1.1.1.14  christos AnIsValidBufferConstant (
    951  1.1.1.14  christos     ACPI_PARSE_OBJECT       *Op)
    952  1.1.1.14  christos {
    953  1.1.1.14  christos     if (!Op)
    954  1.1.1.14  christos     {
    955  1.1.1.14  christos         return (FALSE);
    956  1.1.1.14  christos     }
    957  1.1.1.14  christos 
    958  1.1.1.14  christos     if ((Op->Asl.ParseOpcode == PARSEOP_INTEGER) ||
    959  1.1.1.14  christos         (Op->Asl.ParseOpcode == PARSEOP_ZERO)    ||
    960  1.1.1.14  christos         (Op->Asl.ParseOpcode == PARSEOP_ONE))
    961  1.1.1.14  christos     {
    962  1.1.1.14  christos         return (TRUE);
    963  1.1.1.14  christos     }
    964  1.1.1.14  christos 
    965  1.1.1.14  christos     return (FALSE);
    966  1.1.1.14  christos }
    967  1.1.1.14  christos 
    968  1.1.1.14  christos 
    969  1.1.1.14  christos /*******************************************************************************
    970  1.1.1.14  christos  *
    971   1.1.1.6  christos  * FUNCTION:    AnAnalyzeStoreOperator
    972   1.1.1.6  christos  *
    973   1.1.1.6  christos  * PARAMETERS:  Op                  - Store() operator
    974   1.1.1.6  christos  *
    975   1.1.1.6  christos  * RETURN:      None
    976   1.1.1.6  christos  *
    977   1.1.1.6  christos  * DESCRIPTION: Analyze a store operator. Mostly for stores to/from package
    978   1.1.1.6  christos  *              objects where there are more restrictions than other data
    979   1.1.1.6  christos  *              types.
    980   1.1.1.6  christos  *
    981   1.1.1.6  christos  ******************************************************************************/
    982   1.1.1.6  christos 
    983   1.1.1.6  christos static void
    984   1.1.1.6  christos AnAnalyzeStoreOperator (
    985   1.1.1.6  christos     ACPI_PARSE_OBJECT       *Op)
    986   1.1.1.6  christos {
    987   1.1.1.6  christos     ACPI_NAMESPACE_NODE     *SourceNode;
    988   1.1.1.6  christos     ACPI_NAMESPACE_NODE     *TargetNode;
    989   1.1.1.6  christos     ACPI_PARSE_OBJECT       *SourceOperandOp;
    990   1.1.1.6  christos     ACPI_PARSE_OBJECT       *TargetOperandOp;
    991   1.1.1.6  christos     UINT32                  SourceOperandBtype;
    992   1.1.1.6  christos     UINT32                  TargetOperandBtype;
    993   1.1.1.6  christos 
    994   1.1.1.6  christos 
    995   1.1.1.6  christos     /* Extract the two operands for STORE */
    996   1.1.1.6  christos 
    997   1.1.1.6  christos     SourceOperandOp = Op->Asl.Child;
    998   1.1.1.6  christos     TargetOperandOp = SourceOperandOp->Asl.Next;
    999   1.1.1.6  christos 
   1000   1.1.1.6  christos     /*
   1001   1.1.1.6  christos      * Ignore these Source operand opcodes, they cannot be typechecked,
   1002   1.1.1.6  christos      * the actual result is unknown here.
   1003   1.1.1.6  christos      */
   1004   1.1.1.6  christos     switch (SourceOperandOp->Asl.ParseOpcode)
   1005   1.1.1.6  christos     {
   1006   1.1.1.6  christos     /* For these, type of the returned value is unknown at compile time */
   1007   1.1.1.6  christos 
   1008   1.1.1.6  christos     case PARSEOP_DEREFOF:
   1009   1.1.1.6  christos     case PARSEOP_METHODCALL:
   1010   1.1.1.6  christos     case PARSEOP_STORE:
   1011   1.1.1.6  christos     case PARSEOP_COPYOBJECT:
   1012   1.1.1.6  christos 
   1013   1.1.1.6  christos         return;
   1014   1.1.1.6  christos 
   1015   1.1.1.6  christos     case PARSEOP_INDEX:
   1016   1.1.1.6  christos     case PARSEOP_REFOF:
   1017   1.1.1.6  christos 
   1018  1.1.1.12  christos         if (!AslGbl_EnableReferenceTypechecking)
   1019   1.1.1.6  christos         {
   1020   1.1.1.6  christos             return;
   1021   1.1.1.6  christos         }
   1022   1.1.1.6  christos 
   1023   1.1.1.6  christos         /*
   1024   1.1.1.6  christos          * These opcodes always return an object reference, and thus
   1025   1.1.1.6  christos          * the result can only be stored to a Local, Arg, or Debug.
   1026   1.1.1.6  christos          */
   1027   1.1.1.6  christos         if (TargetOperandOp->Asl.AmlOpcode == AML_DEBUG_OP)
   1028   1.1.1.6  christos         {
   1029   1.1.1.6  christos             return;
   1030   1.1.1.6  christos         }
   1031   1.1.1.6  christos 
   1032   1.1.1.6  christos         if ((TargetOperandOp->Asl.AmlOpcode < AML_LOCAL0) ||
   1033   1.1.1.6  christos             (TargetOperandOp->Asl.AmlOpcode > AML_ARG6))
   1034   1.1.1.6  christos         {
   1035   1.1.1.6  christos             AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, TargetOperandOp,
   1036   1.1.1.6  christos                 "Source [Reference], Target must be [Local/Arg/Debug]");
   1037   1.1.1.6  christos         }
   1038   1.1.1.6  christos         return;
   1039   1.1.1.6  christos 
   1040   1.1.1.6  christos     default:
   1041   1.1.1.6  christos         break;
   1042   1.1.1.6  christos     }
   1043   1.1.1.6  christos 
   1044   1.1.1.6  christos     /*
   1045   1.1.1.6  christos      * Ignore these Target operand opcodes, they cannot be typechecked
   1046   1.1.1.6  christos      */
   1047   1.1.1.6  christos     switch (TargetOperandOp->Asl.ParseOpcode)
   1048   1.1.1.6  christos     {
   1049   1.1.1.6  christos     case PARSEOP_DEBUG:
   1050   1.1.1.6  christos     case PARSEOP_DEREFOF:
   1051   1.1.1.6  christos     case PARSEOP_REFOF:
   1052   1.1.1.6  christos     case PARSEOP_INDEX:
   1053   1.1.1.8  christos     case PARSEOP_STORE:
   1054   1.1.1.6  christos 
   1055   1.1.1.6  christos         return;
   1056   1.1.1.6  christos 
   1057   1.1.1.6  christos     default:
   1058   1.1.1.6  christos         break;
   1059   1.1.1.6  christos     }
   1060   1.1.1.6  christos 
   1061   1.1.1.6  christos     /*
   1062   1.1.1.6  christos      * Ignore typecheck for External() operands of type "UnknownObj",
   1063   1.1.1.6  christos      * we don't know the actual type (source or target).
   1064   1.1.1.6  christos      */
   1065   1.1.1.6  christos     SourceNode = SourceOperandOp->Asl.Node;
   1066   1.1.1.6  christos     if (SourceNode &&
   1067   1.1.1.6  christos         (SourceNode->Flags & ANOBJ_IS_EXTERNAL) &&
   1068   1.1.1.6  christos         (SourceNode->Type == ACPI_TYPE_ANY))
   1069   1.1.1.6  christos     {
   1070   1.1.1.6  christos         return;
   1071   1.1.1.6  christos     }
   1072   1.1.1.6  christos 
   1073   1.1.1.6  christos     TargetNode = TargetOperandOp->Asl.Node;
   1074   1.1.1.6  christos     if (TargetNode &&
   1075   1.1.1.6  christos         (TargetNode->Flags & ANOBJ_IS_EXTERNAL) &&
   1076   1.1.1.6  christos         (TargetNode->Type == ACPI_TYPE_ANY))
   1077   1.1.1.6  christos     {
   1078   1.1.1.6  christos         return;
   1079   1.1.1.6  christos     }
   1080   1.1.1.6  christos 
   1081   1.1.1.6  christos     /*
   1082   1.1.1.6  christos      * A NULL node with a namepath AML opcode indicates non-existent
   1083   1.1.1.6  christos      * name. Just return, the error message is generated elsewhere.
   1084   1.1.1.6  christos      */
   1085   1.1.1.6  christos     if ((!SourceNode && (SourceOperandOp->Asl.AmlOpcode == AML_INT_NAMEPATH_OP)) ||
   1086   1.1.1.6  christos         (!TargetNode && (TargetOperandOp->Asl.AmlOpcode == AML_INT_NAMEPATH_OP)))
   1087   1.1.1.6  christos     {
   1088   1.1.1.6  christos         return;
   1089   1.1.1.6  christos     }
   1090   1.1.1.6  christos 
   1091   1.1.1.6  christos     /*
   1092   1.1.1.6  christos      * Simple check for source same as target via NS node.
   1093   1.1.1.6  christos      * -- Could be expanded to locals and args.
   1094   1.1.1.6  christos      */
   1095   1.1.1.6  christos     if (SourceNode && TargetNode)
   1096   1.1.1.6  christos     {
   1097   1.1.1.6  christos         if (SourceNode == TargetNode)
   1098   1.1.1.6  christos         {
   1099   1.1.1.6  christos             AslError (ASL_WARNING, ASL_MSG_DUPLICATE_ITEM,
   1100   1.1.1.6  christos                 TargetOperandOp, "Source is the same as Target");
   1101   1.1.1.6  christos             return;
   1102   1.1.1.6  christos         }
   1103   1.1.1.6  christos     }
   1104   1.1.1.6  christos 
   1105   1.1.1.6  christos     /* Ignore typecheck if either source or target is a local or arg */
   1106   1.1.1.6  christos 
   1107   1.1.1.6  christos     if ((SourceOperandOp->Asl.AmlOpcode >= AML_LOCAL0) &&
   1108   1.1.1.6  christos         (SourceOperandOp->Asl.AmlOpcode <= AML_ARG6))
   1109   1.1.1.6  christos     {
   1110   1.1.1.6  christos         return; /* Cannot type a local/arg at compile time */
   1111   1.1.1.6  christos     }
   1112   1.1.1.6  christos 
   1113   1.1.1.6  christos     if ((TargetOperandOp->Asl.AmlOpcode >= AML_LOCAL0) &&
   1114   1.1.1.6  christos         (TargetOperandOp->Asl.AmlOpcode <= AML_ARG6))
   1115   1.1.1.6  christos     {
   1116   1.1.1.6  christos         return; /* Cannot type a local/arg at compile time */
   1117   1.1.1.6  christos     }
   1118   1.1.1.6  christos 
   1119   1.1.1.6  christos     /*
   1120   1.1.1.6  christos      * Package objects are a special case because they cannot by implicitly
   1121   1.1.1.6  christos      * converted to/from anything. Check for these two illegal cases:
   1122   1.1.1.6  christos      *
   1123   1.1.1.6  christos      *      Store (non-package, package)
   1124   1.1.1.6  christos      *      Store (package, non-package)
   1125   1.1.1.6  christos      */
   1126   1.1.1.6  christos     SourceOperandBtype = AnGetBtype (SourceOperandOp);
   1127   1.1.1.6  christos     TargetOperandBtype = AnGetBtype (TargetOperandOp);
   1128   1.1.1.6  christos 
   1129   1.1.1.6  christos     /* Check source first for (package, non-package) case */
   1130   1.1.1.6  christos 
   1131   1.1.1.6  christos     if (SourceOperandBtype & ACPI_BTYPE_PACKAGE)
   1132   1.1.1.6  christos     {
   1133   1.1.1.6  christos         /* If Source is PACKAGE-->Target must be PACKAGE */
   1134   1.1.1.6  christos 
   1135   1.1.1.6  christos         if (!(TargetOperandBtype & ACPI_BTYPE_PACKAGE))
   1136   1.1.1.6  christos         {
   1137   1.1.1.6  christos             AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, TargetOperandOp,
   1138   1.1.1.6  christos                 "Source is [Package], Target must be a package also");
   1139   1.1.1.6  christos         }
   1140   1.1.1.6  christos     }
   1141   1.1.1.6  christos 
   1142   1.1.1.6  christos     /* Else check target for (non-package, package) case */
   1143   1.1.1.6  christos 
   1144   1.1.1.6  christos     else if (TargetOperandBtype & ACPI_BTYPE_PACKAGE)
   1145   1.1.1.6  christos     {
   1146   1.1.1.6  christos         /* If Target is PACKAGE, Source must be PACKAGE */
   1147   1.1.1.6  christos 
   1148   1.1.1.6  christos         if (!(SourceOperandBtype & ACPI_BTYPE_PACKAGE))
   1149   1.1.1.6  christos         {
   1150   1.1.1.6  christos             AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, SourceOperandOp,
   1151   1.1.1.6  christos                 "Target is [Package], Source must be a package also");
   1152   1.1.1.6  christos         }
   1153   1.1.1.6  christos     }
   1154   1.1.1.6  christos }
   1155