Home | History | Annotate | Line # | Download | only in executer
exmisc.c revision 1.1.1.7
      1      1.1    jruoho /******************************************************************************
      2      1.1    jruoho  *
      3      1.1    jruoho  * Module Name: exmisc - ACPI AML (p-code) execution - specific opcodes
      4      1.1    jruoho  *
      5      1.1    jruoho  *****************************************************************************/
      6      1.1    jruoho 
      7  1.1.1.2    jruoho /*
      8  1.1.1.7  christos  * 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 "acpi.h"
     45      1.1    jruoho #include "accommon.h"
     46      1.1    jruoho #include "acinterp.h"
     47      1.1    jruoho #include "amlcode.h"
     48      1.1    jruoho #include "amlresrc.h"
     49      1.1    jruoho 
     50      1.1    jruoho 
     51      1.1    jruoho #define _COMPONENT          ACPI_EXECUTER
     52      1.1    jruoho         ACPI_MODULE_NAME    ("exmisc")
     53      1.1    jruoho 
     54      1.1    jruoho 
     55      1.1    jruoho /*******************************************************************************
     56      1.1    jruoho  *
     57      1.1    jruoho  * FUNCTION:    AcpiExGetObjectReference
     58      1.1    jruoho  *
     59      1.1    jruoho  * PARAMETERS:  ObjDesc             - Create a reference to this object
     60      1.1    jruoho  *              ReturnDesc          - Where to store the reference
     61      1.1    jruoho  *              WalkState           - Current state
     62      1.1    jruoho  *
     63      1.1    jruoho  * RETURN:      Status
     64      1.1    jruoho  *
     65      1.1    jruoho  * DESCRIPTION: Obtain and return a "reference" to the target object
     66      1.1    jruoho  *              Common code for the RefOfOp and the CondRefOfOp.
     67      1.1    jruoho  *
     68      1.1    jruoho  ******************************************************************************/
     69      1.1    jruoho 
     70      1.1    jruoho ACPI_STATUS
     71      1.1    jruoho AcpiExGetObjectReference (
     72      1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc,
     73      1.1    jruoho     ACPI_OPERAND_OBJECT     **ReturnDesc,
     74      1.1    jruoho     ACPI_WALK_STATE         *WalkState)
     75      1.1    jruoho {
     76      1.1    jruoho     ACPI_OPERAND_OBJECT     *ReferenceObj;
     77      1.1    jruoho     ACPI_OPERAND_OBJECT     *ReferencedObj;
     78      1.1    jruoho 
     79      1.1    jruoho 
     80      1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (ExGetObjectReference, ObjDesc);
     81      1.1    jruoho 
     82      1.1    jruoho 
     83      1.1    jruoho     *ReturnDesc = NULL;
     84      1.1    jruoho 
     85      1.1    jruoho     switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
     86      1.1    jruoho     {
     87      1.1    jruoho     case ACPI_DESC_TYPE_OPERAND:
     88      1.1    jruoho 
     89      1.1    jruoho         if (ObjDesc->Common.Type != ACPI_TYPE_LOCAL_REFERENCE)
     90      1.1    jruoho         {
     91      1.1    jruoho             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
     92      1.1    jruoho         }
     93      1.1    jruoho 
     94      1.1    jruoho         /*
     95      1.1    jruoho          * Must be a reference to a Local or Arg
     96      1.1    jruoho          */
     97      1.1    jruoho         switch (ObjDesc->Reference.Class)
     98      1.1    jruoho         {
     99      1.1    jruoho         case ACPI_REFCLASS_LOCAL:
    100      1.1    jruoho         case ACPI_REFCLASS_ARG:
    101      1.1    jruoho         case ACPI_REFCLASS_DEBUG:
    102      1.1    jruoho 
    103      1.1    jruoho             /* The referenced object is the pseudo-node for the local/arg */
    104      1.1    jruoho 
    105      1.1    jruoho             ReferencedObj = ObjDesc->Reference.Object;
    106      1.1    jruoho             break;
    107      1.1    jruoho 
    108      1.1    jruoho         default:
    109      1.1    jruoho 
    110  1.1.1.7  christos             ACPI_ERROR ((AE_INFO, "Invalid Reference Class 0x%2.2X",
    111      1.1    jruoho                 ObjDesc->Reference.Class));
    112  1.1.1.7  christos             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
    113      1.1    jruoho         }
    114      1.1    jruoho         break;
    115      1.1    jruoho 
    116      1.1    jruoho     case ACPI_DESC_TYPE_NAMED:
    117      1.1    jruoho         /*
    118      1.1    jruoho          * A named reference that has already been resolved to a Node
    119      1.1    jruoho          */
    120      1.1    jruoho         ReferencedObj = ObjDesc;
    121      1.1    jruoho         break;
    122      1.1    jruoho 
    123      1.1    jruoho     default:
    124      1.1    jruoho 
    125      1.1    jruoho         ACPI_ERROR ((AE_INFO, "Invalid descriptor type 0x%X",
    126      1.1    jruoho             ACPI_GET_DESCRIPTOR_TYPE (ObjDesc)));
    127      1.1    jruoho         return_ACPI_STATUS (AE_TYPE);
    128      1.1    jruoho     }
    129      1.1    jruoho 
    130      1.1    jruoho 
    131      1.1    jruoho     /* Create a new reference object */
    132      1.1    jruoho 
    133      1.1    jruoho     ReferenceObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
    134      1.1    jruoho     if (!ReferenceObj)
    135      1.1    jruoho     {
    136      1.1    jruoho         return_ACPI_STATUS (AE_NO_MEMORY);
    137      1.1    jruoho     }
    138      1.1    jruoho 
    139      1.1    jruoho     ReferenceObj->Reference.Class = ACPI_REFCLASS_REFOF;
    140      1.1    jruoho     ReferenceObj->Reference.Object = ReferencedObj;
    141      1.1    jruoho     *ReturnDesc = ReferenceObj;
    142      1.1    jruoho 
    143      1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    144      1.1    jruoho         "Object %p Type [%s], returning Reference %p\n",
    145      1.1    jruoho         ObjDesc, AcpiUtGetObjectTypeName (ObjDesc), *ReturnDesc));
    146      1.1    jruoho 
    147      1.1    jruoho     return_ACPI_STATUS (AE_OK);
    148      1.1    jruoho }
    149      1.1    jruoho 
    150      1.1    jruoho 
    151      1.1    jruoho /*******************************************************************************
    152      1.1    jruoho  *
    153      1.1    jruoho  * FUNCTION:    AcpiExConcatTemplate
    154      1.1    jruoho  *
    155      1.1    jruoho  * PARAMETERS:  Operand0            - First source object
    156      1.1    jruoho  *              Operand1            - Second source object
    157      1.1    jruoho  *              ActualReturnDesc    - Where to place the return object
    158      1.1    jruoho  *              WalkState           - Current walk state
    159      1.1    jruoho  *
    160      1.1    jruoho  * RETURN:      Status
    161      1.1    jruoho  *
    162      1.1    jruoho  * DESCRIPTION: Concatenate two resource templates
    163      1.1    jruoho  *
    164      1.1    jruoho  ******************************************************************************/
    165      1.1    jruoho 
    166      1.1    jruoho ACPI_STATUS
    167      1.1    jruoho AcpiExConcatTemplate (
    168      1.1    jruoho     ACPI_OPERAND_OBJECT     *Operand0,
    169      1.1    jruoho     ACPI_OPERAND_OBJECT     *Operand1,
    170      1.1    jruoho     ACPI_OPERAND_OBJECT     **ActualReturnDesc,
    171      1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    172      1.1    jruoho {
    173      1.1    jruoho     ACPI_STATUS             Status;
    174      1.1    jruoho     ACPI_OPERAND_OBJECT     *ReturnDesc;
    175      1.1    jruoho     UINT8                   *NewBuf;
    176      1.1    jruoho     UINT8                   *EndTag;
    177      1.1    jruoho     ACPI_SIZE               Length0;
    178      1.1    jruoho     ACPI_SIZE               Length1;
    179      1.1    jruoho     ACPI_SIZE               NewLength;
    180      1.1    jruoho 
    181      1.1    jruoho 
    182      1.1    jruoho     ACPI_FUNCTION_TRACE (ExConcatTemplate);
    183      1.1    jruoho 
    184      1.1    jruoho 
    185      1.1    jruoho     /*
    186      1.1    jruoho      * Find the EndTag descriptor in each resource template.
    187      1.1    jruoho      * Note1: returned pointers point TO the EndTag, not past it.
    188      1.1    jruoho      * Note2: zero-length buffers are allowed; treated like one EndTag
    189      1.1    jruoho      */
    190      1.1    jruoho 
    191      1.1    jruoho     /* Get the length of the first resource template */
    192      1.1    jruoho 
    193      1.1    jruoho     Status = AcpiUtGetResourceEndTag (Operand0, &EndTag);
    194      1.1    jruoho     if (ACPI_FAILURE (Status))
    195      1.1    jruoho     {
    196      1.1    jruoho         return_ACPI_STATUS (Status);
    197      1.1    jruoho     }
    198      1.1    jruoho 
    199      1.1    jruoho     Length0 = ACPI_PTR_DIFF (EndTag, Operand0->Buffer.Pointer);
    200      1.1    jruoho 
    201      1.1    jruoho     /* Get the length of the second resource template */
    202      1.1    jruoho 
    203      1.1    jruoho     Status = AcpiUtGetResourceEndTag (Operand1, &EndTag);
    204      1.1    jruoho     if (ACPI_FAILURE (Status))
    205      1.1    jruoho     {
    206      1.1    jruoho         return_ACPI_STATUS (Status);
    207      1.1    jruoho     }
    208      1.1    jruoho 
    209      1.1    jruoho     Length1 = ACPI_PTR_DIFF (EndTag, Operand1->Buffer.Pointer);
    210      1.1    jruoho 
    211      1.1    jruoho     /* Combine both lengths, minimum size will be 2 for EndTag */
    212      1.1    jruoho 
    213      1.1    jruoho     NewLength = Length0 + Length1 + sizeof (AML_RESOURCE_END_TAG);
    214      1.1    jruoho 
    215      1.1    jruoho     /* Create a new buffer object for the result (with one EndTag) */
    216      1.1    jruoho 
    217      1.1    jruoho     ReturnDesc = AcpiUtCreateBufferObject (NewLength);
    218      1.1    jruoho     if (!ReturnDesc)
    219      1.1    jruoho     {
    220      1.1    jruoho         return_ACPI_STATUS (AE_NO_MEMORY);
    221      1.1    jruoho     }
    222      1.1    jruoho 
    223      1.1    jruoho     /*
    224      1.1    jruoho      * Copy the templates to the new buffer, 0 first, then 1 follows. One
    225      1.1    jruoho      * EndTag descriptor is copied from Operand1.
    226      1.1    jruoho      */
    227      1.1    jruoho     NewBuf = ReturnDesc->Buffer.Pointer;
    228  1.1.1.6  christos     memcpy (NewBuf, Operand0->Buffer.Pointer, Length0);
    229  1.1.1.6  christos     memcpy (NewBuf + Length0, Operand1->Buffer.Pointer, Length1);
    230      1.1    jruoho 
    231      1.1    jruoho     /* Insert EndTag and set the checksum to zero, means "ignore checksum" */
    232      1.1    jruoho 
    233      1.1    jruoho     NewBuf[NewLength - 1] = 0;
    234      1.1    jruoho     NewBuf[NewLength - 2] = ACPI_RESOURCE_NAME_END_TAG | 1;
    235      1.1    jruoho 
    236      1.1    jruoho     /* Return the completed resource template */
    237      1.1    jruoho 
    238      1.1    jruoho     *ActualReturnDesc = ReturnDesc;
    239      1.1    jruoho     return_ACPI_STATUS (AE_OK);
    240      1.1    jruoho }
    241      1.1    jruoho 
    242      1.1    jruoho 
    243      1.1    jruoho /*******************************************************************************
    244      1.1    jruoho  *
    245      1.1    jruoho  * FUNCTION:    AcpiExDoConcatenate
    246      1.1    jruoho  *
    247      1.1    jruoho  * PARAMETERS:  Operand0            - First source object
    248      1.1    jruoho  *              Operand1            - Second source object
    249      1.1    jruoho  *              ActualReturnDesc    - Where to place the return object
    250      1.1    jruoho  *              WalkState           - Current walk state
    251      1.1    jruoho  *
    252      1.1    jruoho  * RETURN:      Status
    253      1.1    jruoho  *
    254      1.1    jruoho  * DESCRIPTION: Concatenate two objects OF THE SAME TYPE.
    255      1.1    jruoho  *
    256      1.1    jruoho  ******************************************************************************/
    257      1.1    jruoho 
    258      1.1    jruoho ACPI_STATUS
    259      1.1    jruoho AcpiExDoConcatenate (
    260      1.1    jruoho     ACPI_OPERAND_OBJECT     *Operand0,
    261      1.1    jruoho     ACPI_OPERAND_OBJECT     *Operand1,
    262      1.1    jruoho     ACPI_OPERAND_OBJECT     **ActualReturnDesc,
    263      1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    264      1.1    jruoho {
    265      1.1    jruoho     ACPI_OPERAND_OBJECT     *LocalOperand1 = Operand1;
    266      1.1    jruoho     ACPI_OPERAND_OBJECT     *ReturnDesc;
    267      1.1    jruoho     char                    *NewBuf;
    268  1.1.1.7  christos     const char              *TypeString;
    269      1.1    jruoho     ACPI_STATUS             Status;
    270      1.1    jruoho 
    271      1.1    jruoho 
    272      1.1    jruoho     ACPI_FUNCTION_TRACE (ExDoConcatenate);
    273      1.1    jruoho 
    274      1.1    jruoho 
    275      1.1    jruoho     /*
    276  1.1.1.3  christos      * Convert the second operand if necessary. The first operand
    277      1.1    jruoho      * determines the type of the second operand, (See the Data Types
    278      1.1    jruoho      * section of the ACPI specification.)  Both object types are
    279      1.1    jruoho      * guaranteed to be either Integer/String/Buffer by the operand
    280      1.1    jruoho      * resolution mechanism.
    281      1.1    jruoho      */
    282      1.1    jruoho     switch (Operand0->Common.Type)
    283      1.1    jruoho     {
    284      1.1    jruoho     case ACPI_TYPE_INTEGER:
    285  1.1.1.3  christos 
    286      1.1    jruoho         Status = AcpiExConvertToInteger (Operand1, &LocalOperand1, 16);
    287      1.1    jruoho         break;
    288      1.1    jruoho 
    289      1.1    jruoho     case ACPI_TYPE_STRING:
    290  1.1.1.7  christos         /*
    291  1.1.1.7  christos          * Per the ACPI spec, Concatenate only supports int/str/buf.
    292  1.1.1.7  christos          * However, we support all objects here as an extension.
    293  1.1.1.7  christos          * This improves the usefulness of the Printf() macro.
    294  1.1.1.7  christos          * 12/2015.
    295  1.1.1.7  christos          */
    296  1.1.1.7  christos         switch (Operand1->Common.Type)
    297  1.1.1.7  christos         {
    298  1.1.1.7  christos         case ACPI_TYPE_INTEGER:
    299  1.1.1.7  christos         case ACPI_TYPE_STRING:
    300  1.1.1.7  christos         case ACPI_TYPE_BUFFER:
    301  1.1.1.3  christos 
    302  1.1.1.7  christos             Status = AcpiExConvertToString (
    303  1.1.1.7  christos                 Operand1, &LocalOperand1, ACPI_IMPLICIT_CONVERT_HEX);
    304  1.1.1.7  christos             break;
    305  1.1.1.7  christos 
    306  1.1.1.7  christos         default:
    307  1.1.1.7  christos             /*
    308  1.1.1.7  christos              * Just emit a string containing the object type.
    309  1.1.1.7  christos              */
    310  1.1.1.7  christos             TypeString = AcpiUtGetTypeName (Operand1->Common.Type);
    311  1.1.1.7  christos 
    312  1.1.1.7  christos             LocalOperand1 = AcpiUtCreateStringObject (
    313  1.1.1.7  christos                 ((ACPI_SIZE) strlen (TypeString) + 9)); /* 9 For "[Object]" */
    314  1.1.1.7  christos             if (!LocalOperand1)
    315  1.1.1.7  christos             {
    316  1.1.1.7  christos                 Status = AE_NO_MEMORY;
    317  1.1.1.7  christos                 goto Cleanup;
    318  1.1.1.7  christos             }
    319  1.1.1.7  christos 
    320  1.1.1.7  christos             strcpy (LocalOperand1->String.Pointer, "[");
    321  1.1.1.7  christos             strcat (LocalOperand1->String.Pointer, TypeString);
    322  1.1.1.7  christos             strcat (LocalOperand1->String.Pointer, " Object]");
    323  1.1.1.7  christos             Status = AE_OK;
    324  1.1.1.7  christos             break;
    325  1.1.1.7  christos         }
    326      1.1    jruoho         break;
    327      1.1    jruoho 
    328      1.1    jruoho     case ACPI_TYPE_BUFFER:
    329  1.1.1.3  christos 
    330      1.1    jruoho         Status = AcpiExConvertToBuffer (Operand1, &LocalOperand1);
    331      1.1    jruoho         break;
    332      1.1    jruoho 
    333      1.1    jruoho     default:
    334  1.1.1.3  christos 
    335      1.1    jruoho         ACPI_ERROR ((AE_INFO, "Invalid object type: 0x%X",
    336      1.1    jruoho             Operand0->Common.Type));
    337      1.1    jruoho         Status = AE_AML_INTERNAL;
    338      1.1    jruoho     }
    339      1.1    jruoho 
    340      1.1    jruoho     if (ACPI_FAILURE (Status))
    341      1.1    jruoho     {
    342      1.1    jruoho         goto Cleanup;
    343      1.1    jruoho     }
    344      1.1    jruoho 
    345      1.1    jruoho     /*
    346      1.1    jruoho      * Both operands are now known to be the same object type
    347      1.1    jruoho      * (Both are Integer, String, or Buffer), and we can now perform the
    348      1.1    jruoho      * concatenation.
    349      1.1    jruoho      */
    350      1.1    jruoho 
    351      1.1    jruoho     /*
    352      1.1    jruoho      * There are three cases to handle:
    353      1.1    jruoho      *
    354      1.1    jruoho      * 1) Two Integers concatenated to produce a new Buffer
    355      1.1    jruoho      * 2) Two Strings concatenated to produce a new String
    356      1.1    jruoho      * 3) Two Buffers concatenated to produce a new Buffer
    357      1.1    jruoho      */
    358      1.1    jruoho     switch (Operand0->Common.Type)
    359      1.1    jruoho     {
    360      1.1    jruoho     case ACPI_TYPE_INTEGER:
    361      1.1    jruoho 
    362      1.1    jruoho         /* Result of two Integers is a Buffer */
    363      1.1    jruoho         /* Need enough buffer space for two integers */
    364      1.1    jruoho 
    365  1.1.1.7  christos         ReturnDesc = AcpiUtCreateBufferObject (
    366  1.1.1.7  christos             (ACPI_SIZE) ACPI_MUL_2 (AcpiGbl_IntegerByteWidth));
    367      1.1    jruoho         if (!ReturnDesc)
    368      1.1    jruoho         {
    369      1.1    jruoho             Status = AE_NO_MEMORY;
    370      1.1    jruoho             goto Cleanup;
    371      1.1    jruoho         }
    372      1.1    jruoho 
    373      1.1    jruoho         NewBuf = (char *) ReturnDesc->Buffer.Pointer;
    374      1.1    jruoho 
    375      1.1    jruoho         /* Copy the first integer, LSB first */
    376      1.1    jruoho 
    377  1.1.1.6  christos         memcpy (NewBuf, &Operand0->Integer.Value,
    378  1.1.1.7  christos             AcpiGbl_IntegerByteWidth);
    379      1.1    jruoho 
    380      1.1    jruoho         /* Copy the second integer (LSB first) after the first */
    381      1.1    jruoho 
    382  1.1.1.6  christos         memcpy (NewBuf + AcpiGbl_IntegerByteWidth,
    383  1.1.1.7  christos             &LocalOperand1->Integer.Value, AcpiGbl_IntegerByteWidth);
    384      1.1    jruoho         break;
    385      1.1    jruoho 
    386      1.1    jruoho     case ACPI_TYPE_STRING:
    387      1.1    jruoho 
    388      1.1    jruoho         /* Result of two Strings is a String */
    389      1.1    jruoho 
    390      1.1    jruoho         ReturnDesc = AcpiUtCreateStringObject (
    391  1.1.1.7  christos             ((ACPI_SIZE) Operand0->String.Length +
    392  1.1.1.7  christos             LocalOperand1->String.Length));
    393      1.1    jruoho         if (!ReturnDesc)
    394      1.1    jruoho         {
    395      1.1    jruoho             Status = AE_NO_MEMORY;
    396      1.1    jruoho             goto Cleanup;
    397      1.1    jruoho         }
    398      1.1    jruoho 
    399      1.1    jruoho         NewBuf = ReturnDesc->String.Pointer;
    400      1.1    jruoho 
    401      1.1    jruoho         /* Concatenate the strings */
    402      1.1    jruoho 
    403  1.1.1.6  christos         strcpy (NewBuf, Operand0->String.Pointer);
    404  1.1.1.7  christos         strcat (NewBuf, LocalOperand1->String.Pointer);
    405      1.1    jruoho         break;
    406      1.1    jruoho 
    407      1.1    jruoho     case ACPI_TYPE_BUFFER:
    408      1.1    jruoho 
    409      1.1    jruoho         /* Result of two Buffers is a Buffer */
    410      1.1    jruoho 
    411      1.1    jruoho         ReturnDesc = AcpiUtCreateBufferObject (
    412  1.1.1.7  christos             ((ACPI_SIZE) Operand0->Buffer.Length +
    413  1.1.1.7  christos             LocalOperand1->Buffer.Length));
    414      1.1    jruoho         if (!ReturnDesc)
    415      1.1    jruoho         {
    416      1.1    jruoho             Status = AE_NO_MEMORY;
    417      1.1    jruoho             goto Cleanup;
    418      1.1    jruoho         }
    419      1.1    jruoho 
    420      1.1    jruoho         NewBuf = (char *) ReturnDesc->Buffer.Pointer;
    421      1.1    jruoho 
    422      1.1    jruoho         /* Concatenate the buffers */
    423      1.1    jruoho 
    424  1.1.1.6  christos         memcpy (NewBuf, Operand0->Buffer.Pointer,
    425  1.1.1.7  christos             Operand0->Buffer.Length);
    426  1.1.1.6  christos         memcpy (NewBuf + Operand0->Buffer.Length,
    427  1.1.1.7  christos             LocalOperand1->Buffer.Pointer,
    428  1.1.1.7  christos             LocalOperand1->Buffer.Length);
    429      1.1    jruoho         break;
    430      1.1    jruoho 
    431      1.1    jruoho     default:
    432      1.1    jruoho 
    433      1.1    jruoho         /* Invalid object type, should not happen here */
    434      1.1    jruoho 
    435      1.1    jruoho         ACPI_ERROR ((AE_INFO, "Invalid object type: 0x%X",
    436      1.1    jruoho             Operand0->Common.Type));
    437      1.1    jruoho         Status =AE_AML_INTERNAL;
    438      1.1    jruoho         goto Cleanup;
    439      1.1    jruoho     }
    440      1.1    jruoho 
    441      1.1    jruoho     *ActualReturnDesc = ReturnDesc;
    442      1.1    jruoho 
    443      1.1    jruoho Cleanup:
    444      1.1    jruoho     if (LocalOperand1 != Operand1)
    445      1.1    jruoho     {
    446      1.1    jruoho         AcpiUtRemoveReference (LocalOperand1);
    447      1.1    jruoho     }
    448      1.1    jruoho     return_ACPI_STATUS (Status);
    449      1.1    jruoho }
    450      1.1    jruoho 
    451      1.1    jruoho 
    452      1.1    jruoho /*******************************************************************************
    453      1.1    jruoho  *
    454      1.1    jruoho  * FUNCTION:    AcpiExDoMathOp
    455      1.1    jruoho  *
    456      1.1    jruoho  * PARAMETERS:  Opcode              - AML opcode
    457      1.1    jruoho  *              Integer0            - Integer operand #0
    458      1.1    jruoho  *              Integer1            - Integer operand #1
    459      1.1    jruoho  *
    460      1.1    jruoho  * RETURN:      Integer result of the operation
    461      1.1    jruoho  *
    462      1.1    jruoho  * DESCRIPTION: Execute a math AML opcode. The purpose of having all of the
    463      1.1    jruoho  *              math functions here is to prevent a lot of pointer dereferencing
    464      1.1    jruoho  *              to obtain the operands.
    465      1.1    jruoho  *
    466      1.1    jruoho  ******************************************************************************/
    467      1.1    jruoho 
    468      1.1    jruoho UINT64
    469      1.1    jruoho AcpiExDoMathOp (
    470      1.1    jruoho     UINT16                  Opcode,
    471      1.1    jruoho     UINT64                  Integer0,
    472      1.1    jruoho     UINT64                  Integer1)
    473      1.1    jruoho {
    474      1.1    jruoho 
    475      1.1    jruoho     ACPI_FUNCTION_ENTRY ();
    476      1.1    jruoho 
    477      1.1    jruoho 
    478      1.1    jruoho     switch (Opcode)
    479      1.1    jruoho     {
    480      1.1    jruoho     case AML_ADD_OP:                /* Add (Integer0, Integer1, Result) */
    481      1.1    jruoho 
    482      1.1    jruoho         return (Integer0 + Integer1);
    483      1.1    jruoho 
    484      1.1    jruoho     case AML_BIT_AND_OP:            /* And (Integer0, Integer1, Result) */
    485      1.1    jruoho 
    486      1.1    jruoho         return (Integer0 & Integer1);
    487      1.1    jruoho 
    488      1.1    jruoho     case AML_BIT_NAND_OP:           /* NAnd (Integer0, Integer1, Result) */
    489      1.1    jruoho 
    490      1.1    jruoho         return (~(Integer0 & Integer1));
    491      1.1    jruoho 
    492      1.1    jruoho     case AML_BIT_OR_OP:             /* Or (Integer0, Integer1, Result) */
    493      1.1    jruoho 
    494      1.1    jruoho         return (Integer0 | Integer1);
    495      1.1    jruoho 
    496      1.1    jruoho     case AML_BIT_NOR_OP:            /* NOr (Integer0, Integer1, Result) */
    497      1.1    jruoho 
    498      1.1    jruoho         return (~(Integer0 | Integer1));
    499      1.1    jruoho 
    500      1.1    jruoho     case AML_BIT_XOR_OP:            /* XOr (Integer0, Integer1, Result) */
    501      1.1    jruoho 
    502      1.1    jruoho         return (Integer0 ^ Integer1);
    503      1.1    jruoho 
    504      1.1    jruoho     case AML_MULTIPLY_OP:           /* Multiply (Integer0, Integer1, Result) */
    505      1.1    jruoho 
    506      1.1    jruoho         return (Integer0 * Integer1);
    507      1.1    jruoho 
    508      1.1    jruoho     case AML_SHIFT_LEFT_OP:         /* ShiftLeft (Operand, ShiftCount, Result)*/
    509      1.1    jruoho 
    510      1.1    jruoho         /*
    511      1.1    jruoho          * We need to check if the shiftcount is larger than the integer bit
    512      1.1    jruoho          * width since the behavior of this is not well-defined in the C language.
    513      1.1    jruoho          */
    514      1.1    jruoho         if (Integer1 >= AcpiGbl_IntegerBitWidth)
    515      1.1    jruoho         {
    516      1.1    jruoho             return (0);
    517      1.1    jruoho         }
    518      1.1    jruoho         return (Integer0 << Integer1);
    519      1.1    jruoho 
    520      1.1    jruoho     case AML_SHIFT_RIGHT_OP:        /* ShiftRight (Operand, ShiftCount, Result) */
    521      1.1    jruoho 
    522      1.1    jruoho         /*
    523      1.1    jruoho          * We need to check if the shiftcount is larger than the integer bit
    524      1.1    jruoho          * width since the behavior of this is not well-defined in the C language.
    525      1.1    jruoho          */
    526      1.1    jruoho         if (Integer1 >= AcpiGbl_IntegerBitWidth)
    527      1.1    jruoho         {
    528      1.1    jruoho             return (0);
    529      1.1    jruoho         }
    530      1.1    jruoho         return (Integer0 >> Integer1);
    531      1.1    jruoho 
    532      1.1    jruoho     case AML_SUBTRACT_OP:           /* Subtract (Integer0, Integer1, Result) */
    533      1.1    jruoho 
    534      1.1    jruoho         return (Integer0 - Integer1);
    535      1.1    jruoho 
    536      1.1    jruoho     default:
    537      1.1    jruoho 
    538      1.1    jruoho         return (0);
    539      1.1    jruoho     }
    540      1.1    jruoho }
    541      1.1    jruoho 
    542      1.1    jruoho 
    543      1.1    jruoho /*******************************************************************************
    544      1.1    jruoho  *
    545      1.1    jruoho  * FUNCTION:    AcpiExDoLogicalNumericOp
    546      1.1    jruoho  *
    547      1.1    jruoho  * PARAMETERS:  Opcode              - AML opcode
    548      1.1    jruoho  *              Integer0            - Integer operand #0
    549      1.1    jruoho  *              Integer1            - Integer operand #1
    550      1.1    jruoho  *              LogicalResult       - TRUE/FALSE result of the operation
    551      1.1    jruoho  *
    552      1.1    jruoho  * RETURN:      Status
    553      1.1    jruoho  *
    554      1.1    jruoho  * DESCRIPTION: Execute a logical "Numeric" AML opcode. For these Numeric
    555      1.1    jruoho  *              operators (LAnd and LOr), both operands must be integers.
    556      1.1    jruoho  *
    557      1.1    jruoho  *              Note: cleanest machine code seems to be produced by the code
    558      1.1    jruoho  *              below, rather than using statements of the form:
    559      1.1    jruoho  *                  Result = (Integer0 && Integer1);
    560      1.1    jruoho  *
    561      1.1    jruoho  ******************************************************************************/
    562      1.1    jruoho 
    563      1.1    jruoho ACPI_STATUS
    564      1.1    jruoho AcpiExDoLogicalNumericOp (
    565      1.1    jruoho     UINT16                  Opcode,
    566      1.1    jruoho     UINT64                  Integer0,
    567      1.1    jruoho     UINT64                  Integer1,
    568      1.1    jruoho     BOOLEAN                 *LogicalResult)
    569      1.1    jruoho {
    570      1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    571      1.1    jruoho     BOOLEAN                 LocalResult = FALSE;
    572      1.1    jruoho 
    573      1.1    jruoho 
    574      1.1    jruoho     ACPI_FUNCTION_TRACE (ExDoLogicalNumericOp);
    575      1.1    jruoho 
    576      1.1    jruoho 
    577      1.1    jruoho     switch (Opcode)
    578      1.1    jruoho     {
    579      1.1    jruoho     case AML_LAND_OP:               /* LAnd (Integer0, Integer1) */
    580      1.1    jruoho 
    581      1.1    jruoho         if (Integer0 && Integer1)
    582      1.1    jruoho         {
    583      1.1    jruoho             LocalResult = TRUE;
    584      1.1    jruoho         }
    585      1.1    jruoho         break;
    586      1.1    jruoho 
    587      1.1    jruoho     case AML_LOR_OP:                /* LOr (Integer0, Integer1) */
    588      1.1    jruoho 
    589      1.1    jruoho         if (Integer0 || Integer1)
    590      1.1    jruoho         {
    591      1.1    jruoho             LocalResult = TRUE;
    592      1.1    jruoho         }
    593      1.1    jruoho         break;
    594      1.1    jruoho 
    595      1.1    jruoho     default:
    596  1.1.1.3  christos 
    597      1.1    jruoho         Status = AE_AML_INTERNAL;
    598      1.1    jruoho         break;
    599      1.1    jruoho     }
    600      1.1    jruoho 
    601      1.1    jruoho     /* Return the logical result and status */
    602      1.1    jruoho 
    603      1.1    jruoho     *LogicalResult = LocalResult;
    604      1.1    jruoho     return_ACPI_STATUS (Status);
    605      1.1    jruoho }
    606      1.1    jruoho 
    607      1.1    jruoho 
    608      1.1    jruoho /*******************************************************************************
    609      1.1    jruoho  *
    610      1.1    jruoho  * FUNCTION:    AcpiExDoLogicalOp
    611      1.1    jruoho  *
    612      1.1    jruoho  * PARAMETERS:  Opcode              - AML opcode
    613      1.1    jruoho  *              Operand0            - operand #0
    614      1.1    jruoho  *              Operand1            - operand #1
    615      1.1    jruoho  *              LogicalResult       - TRUE/FALSE result of the operation
    616      1.1    jruoho  *
    617      1.1    jruoho  * RETURN:      Status
    618      1.1    jruoho  *
    619      1.1    jruoho  * DESCRIPTION: Execute a logical AML opcode. The purpose of having all of the
    620      1.1    jruoho  *              functions here is to prevent a lot of pointer dereferencing
    621      1.1    jruoho  *              to obtain the operands and to simplify the generation of the
    622      1.1    jruoho  *              logical value. For the Numeric operators (LAnd and LOr), both
    623      1.1    jruoho  *              operands must be integers. For the other logical operators,
    624      1.1    jruoho  *              operands can be any combination of Integer/String/Buffer. The
    625      1.1    jruoho  *              first operand determines the type to which the second operand
    626      1.1    jruoho  *              will be converted.
    627      1.1    jruoho  *
    628      1.1    jruoho  *              Note: cleanest machine code seems to be produced by the code
    629      1.1    jruoho  *              below, rather than using statements of the form:
    630      1.1    jruoho  *                  Result = (Operand0 == Operand1);
    631      1.1    jruoho  *
    632      1.1    jruoho  ******************************************************************************/
    633      1.1    jruoho 
    634      1.1    jruoho ACPI_STATUS
    635      1.1    jruoho AcpiExDoLogicalOp (
    636      1.1    jruoho     UINT16                  Opcode,
    637      1.1    jruoho     ACPI_OPERAND_OBJECT     *Operand0,
    638      1.1    jruoho     ACPI_OPERAND_OBJECT     *Operand1,
    639      1.1    jruoho     BOOLEAN                 *LogicalResult)
    640      1.1    jruoho {
    641      1.1    jruoho     ACPI_OPERAND_OBJECT     *LocalOperand1 = Operand1;
    642      1.1    jruoho     UINT64                  Integer0;
    643      1.1    jruoho     UINT64                  Integer1;
    644      1.1    jruoho     UINT32                  Length0;
    645      1.1    jruoho     UINT32                  Length1;
    646      1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    647      1.1    jruoho     BOOLEAN                 LocalResult = FALSE;
    648      1.1    jruoho     int                     Compare;
    649      1.1    jruoho 
    650      1.1    jruoho 
    651      1.1    jruoho     ACPI_FUNCTION_TRACE (ExDoLogicalOp);
    652      1.1    jruoho 
    653      1.1    jruoho 
    654      1.1    jruoho     /*
    655  1.1.1.3  christos      * Convert the second operand if necessary. The first operand
    656      1.1    jruoho      * determines the type of the second operand, (See the Data Types
    657      1.1    jruoho      * section of the ACPI 3.0+ specification.)  Both object types are
    658      1.1    jruoho      * guaranteed to be either Integer/String/Buffer by the operand
    659      1.1    jruoho      * resolution mechanism.
    660      1.1    jruoho      */
    661      1.1    jruoho     switch (Operand0->Common.Type)
    662      1.1    jruoho     {
    663      1.1    jruoho     case ACPI_TYPE_INTEGER:
    664  1.1.1.3  christos 
    665      1.1    jruoho         Status = AcpiExConvertToInteger (Operand1, &LocalOperand1, 16);
    666      1.1    jruoho         break;
    667      1.1    jruoho 
    668      1.1    jruoho     case ACPI_TYPE_STRING:
    669  1.1.1.3  christos 
    670  1.1.1.7  christos         Status = AcpiExConvertToString (
    671  1.1.1.7  christos             Operand1, &LocalOperand1, ACPI_IMPLICIT_CONVERT_HEX);
    672      1.1    jruoho         break;
    673      1.1    jruoho 
    674      1.1    jruoho     case ACPI_TYPE_BUFFER:
    675  1.1.1.3  christos 
    676      1.1    jruoho         Status = AcpiExConvertToBuffer (Operand1, &LocalOperand1);
    677      1.1    jruoho         break;
    678      1.1    jruoho 
    679      1.1    jruoho     default:
    680  1.1.1.3  christos 
    681      1.1    jruoho         Status = AE_AML_INTERNAL;
    682      1.1    jruoho         break;
    683      1.1    jruoho     }
    684      1.1    jruoho 
    685      1.1    jruoho     if (ACPI_FAILURE (Status))
    686      1.1    jruoho     {
    687      1.1    jruoho         goto Cleanup;
    688      1.1    jruoho     }
    689      1.1    jruoho 
    690      1.1    jruoho     /*
    691      1.1    jruoho      * Two cases: 1) Both Integers, 2) Both Strings or Buffers
    692      1.1    jruoho      */
    693      1.1    jruoho     if (Operand0->Common.Type == ACPI_TYPE_INTEGER)
    694      1.1    jruoho     {
    695      1.1    jruoho         /*
    696      1.1    jruoho          * 1) Both operands are of type integer
    697      1.1    jruoho          *    Note: LocalOperand1 may have changed above
    698      1.1    jruoho          */
    699      1.1    jruoho         Integer0 = Operand0->Integer.Value;
    700      1.1    jruoho         Integer1 = LocalOperand1->Integer.Value;
    701      1.1    jruoho 
    702      1.1    jruoho         switch (Opcode)
    703      1.1    jruoho         {
    704      1.1    jruoho         case AML_LEQUAL_OP:             /* LEqual (Operand0, Operand1) */
    705      1.1    jruoho 
    706      1.1    jruoho             if (Integer0 == Integer1)
    707      1.1    jruoho             {
    708      1.1    jruoho                 LocalResult = TRUE;
    709      1.1    jruoho             }
    710      1.1    jruoho             break;
    711      1.1    jruoho 
    712      1.1    jruoho         case AML_LGREATER_OP:           /* LGreater (Operand0, Operand1) */
    713      1.1    jruoho 
    714      1.1    jruoho             if (Integer0 > Integer1)
    715      1.1    jruoho             {
    716      1.1    jruoho                 LocalResult = TRUE;
    717      1.1    jruoho             }
    718      1.1    jruoho             break;
    719      1.1    jruoho 
    720      1.1    jruoho         case AML_LLESS_OP:              /* LLess (Operand0, Operand1) */
    721      1.1    jruoho 
    722      1.1    jruoho             if (Integer0 < Integer1)
    723      1.1    jruoho             {
    724      1.1    jruoho                 LocalResult = TRUE;
    725      1.1    jruoho             }
    726      1.1    jruoho             break;
    727      1.1    jruoho 
    728      1.1    jruoho         default:
    729  1.1.1.3  christos 
    730      1.1    jruoho             Status = AE_AML_INTERNAL;
    731      1.1    jruoho             break;
    732      1.1    jruoho         }
    733      1.1    jruoho     }
    734      1.1    jruoho     else
    735      1.1    jruoho     {
    736      1.1    jruoho         /*
    737      1.1    jruoho          * 2) Both operands are Strings or both are Buffers
    738      1.1    jruoho          *    Note: Code below takes advantage of common Buffer/String
    739      1.1    jruoho          *          object fields. LocalOperand1 may have changed above. Use
    740      1.1    jruoho          *          memcmp to handle nulls in buffers.
    741      1.1    jruoho          */
    742      1.1    jruoho         Length0 = Operand0->Buffer.Length;
    743      1.1    jruoho         Length1 = LocalOperand1->Buffer.Length;
    744      1.1    jruoho 
    745      1.1    jruoho         /* Lexicographic compare: compare the data bytes */
    746      1.1    jruoho 
    747  1.1.1.6  christos         Compare = memcmp (Operand0->Buffer.Pointer,
    748  1.1.1.7  christos             LocalOperand1->Buffer.Pointer,
    749  1.1.1.7  christos             (Length0 > Length1) ? Length1 : Length0);
    750      1.1    jruoho 
    751      1.1    jruoho         switch (Opcode)
    752      1.1    jruoho         {
    753      1.1    jruoho         case AML_LEQUAL_OP:             /* LEqual (Operand0, Operand1) */
    754      1.1    jruoho 
    755      1.1    jruoho             /* Length and all bytes must be equal */
    756      1.1    jruoho 
    757      1.1    jruoho             if ((Length0 == Length1) &&
    758      1.1    jruoho                 (Compare == 0))
    759      1.1    jruoho             {
    760      1.1    jruoho                 /* Length and all bytes match ==> TRUE */
    761      1.1    jruoho 
    762      1.1    jruoho                 LocalResult = TRUE;
    763      1.1    jruoho             }
    764      1.1    jruoho             break;
    765      1.1    jruoho 
    766      1.1    jruoho         case AML_LGREATER_OP:           /* LGreater (Operand0, Operand1) */
    767      1.1    jruoho 
    768      1.1    jruoho             if (Compare > 0)
    769      1.1    jruoho             {
    770      1.1    jruoho                 LocalResult = TRUE;
    771      1.1    jruoho                 goto Cleanup;   /* TRUE */
    772      1.1    jruoho             }
    773      1.1    jruoho             if (Compare < 0)
    774      1.1    jruoho             {
    775      1.1    jruoho                 goto Cleanup;   /* FALSE */
    776      1.1    jruoho             }
    777      1.1    jruoho 
    778      1.1    jruoho             /* Bytes match (to shortest length), compare lengths */
    779      1.1    jruoho 
    780      1.1    jruoho             if (Length0 > Length1)
    781      1.1    jruoho             {
    782      1.1    jruoho                 LocalResult = TRUE;
    783      1.1    jruoho             }
    784      1.1    jruoho             break;
    785      1.1    jruoho 
    786      1.1    jruoho         case AML_LLESS_OP:              /* LLess (Operand0, Operand1) */
    787      1.1    jruoho 
    788      1.1    jruoho             if (Compare > 0)
    789      1.1    jruoho             {
    790      1.1    jruoho                 goto Cleanup;   /* FALSE */
    791      1.1    jruoho             }
    792      1.1    jruoho             if (Compare < 0)
    793      1.1    jruoho             {
    794      1.1    jruoho                 LocalResult = TRUE;
    795      1.1    jruoho                 goto Cleanup;   /* TRUE */
    796      1.1    jruoho             }
    797      1.1    jruoho 
    798      1.1    jruoho             /* Bytes match (to shortest length), compare lengths */
    799      1.1    jruoho 
    800      1.1    jruoho             if (Length0 < Length1)
    801      1.1    jruoho             {
    802      1.1    jruoho                 LocalResult = TRUE;
    803      1.1    jruoho             }
    804      1.1    jruoho             break;
    805      1.1    jruoho 
    806      1.1    jruoho         default:
    807  1.1.1.3  christos 
    808      1.1    jruoho             Status = AE_AML_INTERNAL;
    809      1.1    jruoho             break;
    810      1.1    jruoho         }
    811      1.1    jruoho     }
    812      1.1    jruoho 
    813      1.1    jruoho Cleanup:
    814      1.1    jruoho 
    815      1.1    jruoho     /* New object was created if implicit conversion performed - delete */
    816      1.1    jruoho 
    817      1.1    jruoho     if (LocalOperand1 != Operand1)
    818      1.1    jruoho     {
    819      1.1    jruoho         AcpiUtRemoveReference (LocalOperand1);
    820      1.1    jruoho     }
    821      1.1    jruoho 
    822      1.1    jruoho     /* Return the logical result and status */
    823      1.1    jruoho 
    824      1.1    jruoho     *LogicalResult = LocalResult;
    825      1.1    jruoho     return_ACPI_STATUS (Status);
    826      1.1    jruoho }
    827