Home | History | Annotate | Line # | Download | only in executer
      1 /******************************************************************************
      2  *
      3  * Module Name: exoparg3 - AML execution - opcodes with 3 arguments
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2025, Intel Corp.
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions, and the following disclaimer,
     16  *    without modification.
     17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  *    including a substantially similar Disclaimer requirement for further
     21  *    binary redistribution.
     22  * 3. Neither the names of the above-listed copyright holders nor the names
     23  *    of any contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * Alternatively, this software may be distributed under the terms of the
     27  * GNU General Public License ("GPL") version 2 as published by the Free
     28  * Software Foundation.
     29  *
     30  * NO WARRANTY
     31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  * POSSIBILITY OF SUCH DAMAGES.
     42  */
     43 
     44 #include "acpi.h"
     45 #include "accommon.h"
     46 #include "acinterp.h"
     47 #include "acoutput.h"
     48 #include "acparser.h"
     49 #include "amlcode.h"
     50 
     51 
     52 #define _COMPONENT          ACPI_EXECUTER
     53         ACPI_MODULE_NAME    ("exoparg3")
     54 
     55 
     56 /*!
     57  * Naming convention for AML interpreter execution routines.
     58  *
     59  * The routines that begin execution of AML opcodes are named with a common
     60  * convention based upon the number of arguments, the number of target operands,
     61  * and whether or not a value is returned:
     62  *
     63  *      AcpiExOpcode_xA_yT_zR
     64  *
     65  * Where:
     66  *
     67  * xA - ARGUMENTS:    The number of arguments (input operands) that are
     68  *                    required for this opcode type (1 through 6 args).
     69  * yT - TARGETS:      The number of targets (output operands) that are required
     70  *                    for this opcode type (0, 1, or 2 targets).
     71  * zR - RETURN VALUE: Indicates whether this opcode type returns a value
     72  *                    as the function return (0 or 1).
     73  *
     74  * The AcpiExOpcode* functions are called via the Dispatcher component with
     75  * fully resolved operands.
     76 !*/
     77 
     78 
     79 /*******************************************************************************
     80  *
     81  * FUNCTION:    AcpiExOpcode_3A_0T_0R
     82  *
     83  * PARAMETERS:  WalkState           - Current walk state
     84  *
     85  * RETURN:      Status
     86  *
     87  * DESCRIPTION: Execute Triadic operator (3 operands)
     88  *
     89  ******************************************************************************/
     90 
     91 ACPI_STATUS
     92 AcpiExOpcode_3A_0T_0R (
     93     ACPI_WALK_STATE         *WalkState)
     94 {
     95     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
     96     ACPI_SIGNAL_FATAL_INFO  Fatal;
     97 
     98 
     99     ACPI_FUNCTION_TRACE_STR (ExOpcode_3A_0T_0R,
    100         AcpiPsGetOpcodeName (WalkState->Opcode));
    101 
    102 
    103     switch (WalkState->Opcode)
    104     {
    105     case AML_FATAL_OP:          /* Fatal (FatalType  FatalCode  FatalArg) */
    106 
    107         Fatal.Type = (UINT32) Operand[0]->Integer.Value;
    108         Fatal.Code = (UINT32) Operand[1]->Integer.Value;
    109         Fatal.Argument = (UINT32) Operand[2]->Integer.Value;
    110 
    111         ACPI_BIOS_ERROR ((AE_INFO,
    112             "Fatal ACPI BIOS error (Type 0x%X Code 0x%X Arg 0x%X)\n",
    113             Fatal.Type, Fatal.Code, Fatal.Argument));
    114 
    115         /* Always signal the OS! */
    116 
    117         AcpiOsSignal (ACPI_SIGNAL_FATAL, &Fatal);
    118 
    119         /*
    120          * Might return while OS is shutting down, so abort the AML execution
    121          * by returning an error.
    122          */
    123         return_ACPI_STATUS (AE_ERROR);
    124 
    125     case AML_EXTERNAL_OP:
    126         /*
    127          * If the interpreter sees this opcode, just ignore it. The External
    128          * op is intended for use by disassemblers in order to properly
    129          * disassemble control method invocations. The opcode or group of
    130          * opcodes should be surrounded by an "if (0)" clause to ensure that
    131          * AML interpreters never see the opcode. Thus, something is
    132          * wrong if an external opcode ever gets here.
    133          */
    134         ACPI_ERROR ((AE_INFO, "Executed External Op"));
    135 
    136         return_ACPI_STATUS (AE_OK);
    137 
    138     default:
    139 
    140         ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
    141             WalkState->Opcode));
    142 
    143         return_ACPI_STATUS (AE_AML_BAD_OPCODE);
    144     }
    145 }
    146 
    147 
    148 /*******************************************************************************
    149  *
    150  * FUNCTION:    AcpiExOpcode_3A_1T_1R
    151  *
    152  * PARAMETERS:  WalkState           - Current walk state
    153  *
    154  * RETURN:      Status
    155  *
    156  * DESCRIPTION: Execute Triadic operator (3 operands)
    157  *
    158  ******************************************************************************/
    159 
    160 ACPI_STATUS
    161 AcpiExOpcode_3A_1T_1R (
    162     ACPI_WALK_STATE         *WalkState)
    163 {
    164     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
    165     ACPI_OPERAND_OBJECT     *ReturnDesc = NULL;
    166     char                    *Buffer = NULL;
    167     ACPI_STATUS             Status = AE_OK;
    168     UINT64                  Index;
    169     ACPI_SIZE               Length;
    170 
    171 
    172     ACPI_FUNCTION_TRACE_STR (ExOpcode_3A_1T_1R,
    173         AcpiPsGetOpcodeName (WalkState->Opcode));
    174 
    175 
    176     switch (WalkState->Opcode)
    177     {
    178     case AML_MID_OP:    /* Mid (Source[0], Index[1], Length[2], Result[3]) */
    179         /*
    180          * Create the return object. The Source operand is guaranteed to be
    181          * either a String or a Buffer, so just use its type.
    182          */
    183         ReturnDesc = AcpiUtCreateInternalObject (
    184             (Operand[0])->Common.Type);
    185         if (!ReturnDesc)
    186         {
    187             Status = AE_NO_MEMORY;
    188             goto Cleanup;
    189         }
    190 
    191         /* Get the Integer values from the objects */
    192 
    193         Index = Operand[1]->Integer.Value;
    194         Length = (ACPI_SIZE) Operand[2]->Integer.Value;
    195 
    196         /*
    197          * If the index is beyond the length of the String/Buffer, or if the
    198          * requested length is zero, return a zero-length String/Buffer
    199          */
    200         if (Index >= Operand[0]->String.Length)
    201         {
    202             Length = 0;
    203         }
    204 
    205         /* Truncate request if larger than the actual String/Buffer */
    206 
    207         else if ((Index + Length) > Operand[0]->String.Length)
    208         {
    209             Length =
    210                 (ACPI_SIZE) Operand[0]->String.Length - (ACPI_SIZE) Index;
    211         }
    212 
    213         /* Strings always have a sub-pointer, not so for buffers */
    214 
    215         switch ((Operand[0])->Common.Type)
    216         {
    217         case ACPI_TYPE_STRING:
    218 
    219             /* Always allocate a new buffer for the String */
    220 
    221             Buffer = ACPI_ALLOCATE_ZEROED ((ACPI_SIZE) Length + 1);
    222             if (!Buffer)
    223             {
    224                 Status = AE_NO_MEMORY;
    225                 goto Cleanup;
    226             }
    227             break;
    228 
    229         case ACPI_TYPE_BUFFER:
    230 
    231             /* If the requested length is zero, don't allocate a buffer */
    232 
    233             if (Length > 0)
    234             {
    235                 /* Allocate a new buffer for the Buffer */
    236 
    237                 Buffer = ACPI_ALLOCATE_ZEROED (Length);
    238                 if (!Buffer)
    239                 {
    240                     Status = AE_NO_MEMORY;
    241                     goto Cleanup;
    242                 }
    243             }
    244             break;
    245 
    246         default:                        /* Should not happen */
    247 
    248             Status = AE_AML_OPERAND_TYPE;
    249             goto Cleanup;
    250         }
    251 
    252         if (Buffer)
    253         {
    254             /* We have a buffer, copy the portion requested */
    255 
    256             memcpy (Buffer,
    257                 Operand[0]->String.Pointer + Index, Length);
    258         }
    259 
    260         /* Set the length of the new String/Buffer */
    261 
    262         ReturnDesc->String.Pointer = Buffer;
    263         ReturnDesc->String.Length = (UINT32) Length;
    264 
    265         /* Mark buffer initialized */
    266 
    267         ReturnDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
    268         break;
    269 
    270     default:
    271 
    272         ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
    273             WalkState->Opcode));
    274 
    275         Status = AE_AML_BAD_OPCODE;
    276         goto Cleanup;
    277     }
    278 
    279     /* Store the result in the target */
    280 
    281     Status = AcpiExStore (ReturnDesc, Operand[3], WalkState);
    282 
    283 Cleanup:
    284 
    285     /* Delete return object on error */
    286 
    287     if (ACPI_FAILURE (Status) || WalkState->ResultObj)
    288     {
    289         AcpiUtRemoveReference (ReturnDesc);
    290         WalkState->ResultObj = NULL;
    291     }
    292     else
    293     {
    294         /* Set the return object and exit */
    295 
    296         WalkState->ResultObj = ReturnDesc;
    297     }
    298 
    299     return_ACPI_STATUS (Status);
    300 }
    301