Home | History | Annotate | Line # | Download | only in compiler
asloperands.c revision 1.1
      1  1.1  jruoho 
      2  1.1  jruoho /******************************************************************************
      3  1.1  jruoho  *
      4  1.1  jruoho  * Module Name: asloperands - AML operand processing
      5  1.1  jruoho  *
      6  1.1  jruoho  *****************************************************************************/
      7  1.1  jruoho 
      8  1.1  jruoho /******************************************************************************
      9  1.1  jruoho  *
     10  1.1  jruoho  * 1. Copyright Notice
     11  1.1  jruoho  *
     12  1.1  jruoho  * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
     13  1.1  jruoho  * All rights reserved.
     14  1.1  jruoho  *
     15  1.1  jruoho  * 2. License
     16  1.1  jruoho  *
     17  1.1  jruoho  * 2.1. This is your license from Intel Corp. under its intellectual property
     18  1.1  jruoho  * rights.  You may have additional license terms from the party that provided
     19  1.1  jruoho  * you this software, covering your right to use that party's intellectual
     20  1.1  jruoho  * property rights.
     21  1.1  jruoho  *
     22  1.1  jruoho  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     23  1.1  jruoho  * copy of the source code appearing in this file ("Covered Code") an
     24  1.1  jruoho  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     25  1.1  jruoho  * base code distributed originally by Intel ("Original Intel Code") to copy,
     26  1.1  jruoho  * make derivatives, distribute, use and display any portion of the Covered
     27  1.1  jruoho  * Code in any form, with the right to sublicense such rights; and
     28  1.1  jruoho  *
     29  1.1  jruoho  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     30  1.1  jruoho  * license (with the right to sublicense), under only those claims of Intel
     31  1.1  jruoho  * patents that are infringed by the Original Intel Code, to make, use, sell,
     32  1.1  jruoho  * offer to sell, and import the Covered Code and derivative works thereof
     33  1.1  jruoho  * solely to the minimum extent necessary to exercise the above copyright
     34  1.1  jruoho  * license, and in no event shall the patent license extend to any additions
     35  1.1  jruoho  * to or modifications of the Original Intel Code.  No other license or right
     36  1.1  jruoho  * is granted directly or by implication, estoppel or otherwise;
     37  1.1  jruoho  *
     38  1.1  jruoho  * The above copyright and patent license is granted only if the following
     39  1.1  jruoho  * conditions are met:
     40  1.1  jruoho  *
     41  1.1  jruoho  * 3. Conditions
     42  1.1  jruoho  *
     43  1.1  jruoho  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     44  1.1  jruoho  * Redistribution of source code of any substantial portion of the Covered
     45  1.1  jruoho  * Code or modification with rights to further distribute source must include
     46  1.1  jruoho  * the above Copyright Notice, the above License, this list of Conditions,
     47  1.1  jruoho  * and the following Disclaimer and Export Compliance provision.  In addition,
     48  1.1  jruoho  * Licensee must cause all Covered Code to which Licensee contributes to
     49  1.1  jruoho  * contain a file documenting the changes Licensee made to create that Covered
     50  1.1  jruoho  * Code and the date of any change.  Licensee must include in that file the
     51  1.1  jruoho  * documentation of any changes made by any predecessor Licensee.  Licensee
     52  1.1  jruoho  * must include a prominent statement that the modification is derived,
     53  1.1  jruoho  * directly or indirectly, from Original Intel Code.
     54  1.1  jruoho  *
     55  1.1  jruoho  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     56  1.1  jruoho  * Redistribution of source code of any substantial portion of the Covered
     57  1.1  jruoho  * Code or modification without rights to further distribute source must
     58  1.1  jruoho  * include the following Disclaimer and Export Compliance provision in the
     59  1.1  jruoho  * documentation and/or other materials provided with distribution.  In
     60  1.1  jruoho  * addition, Licensee may not authorize further sublicense of source of any
     61  1.1  jruoho  * portion of the Covered Code, and must include terms to the effect that the
     62  1.1  jruoho  * license from Licensee to its licensee is limited to the intellectual
     63  1.1  jruoho  * property embodied in the software Licensee provides to its licensee, and
     64  1.1  jruoho  * not to intellectual property embodied in modifications its licensee may
     65  1.1  jruoho  * make.
     66  1.1  jruoho  *
     67  1.1  jruoho  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     68  1.1  jruoho  * substantial portion of the Covered Code or modification must reproduce the
     69  1.1  jruoho  * above Copyright Notice, and the following Disclaimer and Export Compliance
     70  1.1  jruoho  * provision in the documentation and/or other materials provided with the
     71  1.1  jruoho  * distribution.
     72  1.1  jruoho  *
     73  1.1  jruoho  * 3.4. Intel retains all right, title, and interest in and to the Original
     74  1.1  jruoho  * Intel Code.
     75  1.1  jruoho  *
     76  1.1  jruoho  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     77  1.1  jruoho  * Intel shall be used in advertising or otherwise to promote the sale, use or
     78  1.1  jruoho  * other dealings in products derived from or relating to the Covered Code
     79  1.1  jruoho  * without prior written authorization from Intel.
     80  1.1  jruoho  *
     81  1.1  jruoho  * 4. Disclaimer and Export Compliance
     82  1.1  jruoho  *
     83  1.1  jruoho  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     84  1.1  jruoho  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     85  1.1  jruoho  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
     86  1.1  jruoho  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
     87  1.1  jruoho  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
     88  1.1  jruoho  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     89  1.1  jruoho  * PARTICULAR PURPOSE.
     90  1.1  jruoho  *
     91  1.1  jruoho  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     92  1.1  jruoho  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     93  1.1  jruoho  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     94  1.1  jruoho  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     95  1.1  jruoho  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     96  1.1  jruoho  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
     97  1.1  jruoho  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     98  1.1  jruoho  * LIMITED REMEDY.
     99  1.1  jruoho  *
    100  1.1  jruoho  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    101  1.1  jruoho  * software or system incorporating such software without first obtaining any
    102  1.1  jruoho  * required license or other approval from the U. S. Department of Commerce or
    103  1.1  jruoho  * any other agency or department of the United States Government.  In the
    104  1.1  jruoho  * event Licensee exports any such software from the United States or
    105  1.1  jruoho  * re-exports any such software from a foreign destination, Licensee shall
    106  1.1  jruoho  * ensure that the distribution and export/re-export of the software is in
    107  1.1  jruoho  * compliance with all laws, regulations, orders, or other restrictions of the
    108  1.1  jruoho  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    109  1.1  jruoho  * any of its subsidiaries will export/re-export any technical data, process,
    110  1.1  jruoho  * software, or service, directly or indirectly, to any country for which the
    111  1.1  jruoho  * United States government or any agency thereof requires an export license,
    112  1.1  jruoho  * other governmental approval, or letter of assurance, without first obtaining
    113  1.1  jruoho  * such license, approval or letter.
    114  1.1  jruoho  *
    115  1.1  jruoho  *****************************************************************************/
    116  1.1  jruoho 
    117  1.1  jruoho 
    118  1.1  jruoho #include "aslcompiler.h"
    119  1.1  jruoho #include "aslcompiler.y.h"
    120  1.1  jruoho #include "amlcode.h"
    121  1.1  jruoho 
    122  1.1  jruoho #define _COMPONENT          ACPI_COMPILER
    123  1.1  jruoho         ACPI_MODULE_NAME    ("asloperands")
    124  1.1  jruoho 
    125  1.1  jruoho /* Local prototypes */
    126  1.1  jruoho 
    127  1.1  jruoho static void
    128  1.1  jruoho OpnDoField (
    129  1.1  jruoho     ACPI_PARSE_OBJECT       *Op);
    130  1.1  jruoho 
    131  1.1  jruoho static void
    132  1.1  jruoho OpnDoBankField (
    133  1.1  jruoho     ACPI_PARSE_OBJECT       *Op);
    134  1.1  jruoho 
    135  1.1  jruoho static void
    136  1.1  jruoho OpnDoBuffer (
    137  1.1  jruoho     ACPI_PARSE_OBJECT       *Op);
    138  1.1  jruoho 
    139  1.1  jruoho static void
    140  1.1  jruoho OpnDoDefinitionBlock (
    141  1.1  jruoho     ACPI_PARSE_OBJECT       *Op);
    142  1.1  jruoho 
    143  1.1  jruoho static void
    144  1.1  jruoho OpnDoFieldCommon (
    145  1.1  jruoho     ACPI_PARSE_OBJECT       *FieldOp,
    146  1.1  jruoho     ACPI_PARSE_OBJECT       *Op);
    147  1.1  jruoho 
    148  1.1  jruoho static void
    149  1.1  jruoho OpnDoIndexField (
    150  1.1  jruoho     ACPI_PARSE_OBJECT       *Op);
    151  1.1  jruoho 
    152  1.1  jruoho static void
    153  1.1  jruoho OpnDoLoadTable (
    154  1.1  jruoho     ACPI_PARSE_OBJECT       *Op);
    155  1.1  jruoho 
    156  1.1  jruoho static void
    157  1.1  jruoho OpnDoMethod (
    158  1.1  jruoho     ACPI_PARSE_OBJECT       *Op);
    159  1.1  jruoho 
    160  1.1  jruoho static void
    161  1.1  jruoho OpnDoMutex (
    162  1.1  jruoho     ACPI_PARSE_OBJECT       *Op);
    163  1.1  jruoho 
    164  1.1  jruoho static void
    165  1.1  jruoho OpnDoRegion (
    166  1.1  jruoho     ACPI_PARSE_OBJECT       *Op);
    167  1.1  jruoho 
    168  1.1  jruoho static void
    169  1.1  jruoho OpnAttachNameToNode (
    170  1.1  jruoho     ACPI_PARSE_OBJECT       *Op);
    171  1.1  jruoho 
    172  1.1  jruoho 
    173  1.1  jruoho /*******************************************************************************
    174  1.1  jruoho  *
    175  1.1  jruoho  * FUNCTION:    OpnDoMutex
    176  1.1  jruoho  *
    177  1.1  jruoho  * PARAMETERS:  Op        - The parent parse node
    178  1.1  jruoho  *
    179  1.1  jruoho  * RETURN:      None
    180  1.1  jruoho  *
    181  1.1  jruoho  * DESCRIPTION: Construct the operands for the MUTEX ASL keyword.
    182  1.1  jruoho  *
    183  1.1  jruoho  ******************************************************************************/
    184  1.1  jruoho 
    185  1.1  jruoho static void
    186  1.1  jruoho OpnDoMutex (
    187  1.1  jruoho     ACPI_PARSE_OBJECT       *Op)
    188  1.1  jruoho {
    189  1.1  jruoho     ACPI_PARSE_OBJECT       *Next;
    190  1.1  jruoho 
    191  1.1  jruoho 
    192  1.1  jruoho     Next = Op->Asl.Child;
    193  1.1  jruoho     Next = Next->Asl.Next;
    194  1.1  jruoho 
    195  1.1  jruoho     if (Next->Asl.Value.Integer > 15)
    196  1.1  jruoho     {
    197  1.1  jruoho         AslError (ASL_ERROR, ASL_MSG_SYNC_LEVEL, Next, NULL);
    198  1.1  jruoho     }
    199  1.1  jruoho     return;
    200  1.1  jruoho }
    201  1.1  jruoho 
    202  1.1  jruoho 
    203  1.1  jruoho /*******************************************************************************
    204  1.1  jruoho  *
    205  1.1  jruoho  * FUNCTION:    OpnDoMethod
    206  1.1  jruoho  *
    207  1.1  jruoho  * PARAMETERS:  Op        - The parent parse node
    208  1.1  jruoho  *
    209  1.1  jruoho  * RETURN:      None
    210  1.1  jruoho  *
    211  1.1  jruoho  * DESCRIPTION: Construct the operands for the METHOD ASL keyword.
    212  1.1  jruoho  *
    213  1.1  jruoho  ******************************************************************************/
    214  1.1  jruoho 
    215  1.1  jruoho static void
    216  1.1  jruoho OpnDoMethod (
    217  1.1  jruoho     ACPI_PARSE_OBJECT       *Op)
    218  1.1  jruoho {
    219  1.1  jruoho     ACPI_PARSE_OBJECT       *Next;
    220  1.1  jruoho 
    221  1.1  jruoho     /* Optional arguments for this opcode with defaults */
    222  1.1  jruoho 
    223  1.1  jruoho     UINT8                   NumArgs = 0;
    224  1.1  jruoho     UINT8                   Serialized = 0;
    225  1.1  jruoho     UINT8                   Concurrency = 0;
    226  1.1  jruoho     UINT8                   MethodFlags;
    227  1.1  jruoho 
    228  1.1  jruoho 
    229  1.1  jruoho     /* Opcode and package length first */
    230  1.1  jruoho     /* Method name */
    231  1.1  jruoho 
    232  1.1  jruoho     Next = Op->Asl.Child;
    233  1.1  jruoho 
    234  1.1  jruoho     /* Num args */
    235  1.1  jruoho 
    236  1.1  jruoho     Next = Next->Asl.Next;
    237  1.1  jruoho     if (Next->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
    238  1.1  jruoho     {
    239  1.1  jruoho         NumArgs = (UINT8) Next->Asl.Value.Integer;
    240  1.1  jruoho         Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
    241  1.1  jruoho     }
    242  1.1  jruoho 
    243  1.1  jruoho     /* Serialized Flag */
    244  1.1  jruoho 
    245  1.1  jruoho     Next = Next->Asl.Next;
    246  1.1  jruoho     if (Next->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
    247  1.1  jruoho     {
    248  1.1  jruoho         Serialized = (UINT8) Next->Asl.Value.Integer;
    249  1.1  jruoho         Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
    250  1.1  jruoho     }
    251  1.1  jruoho 
    252  1.1  jruoho     /* Concurrency value (valid values are 0-15) */
    253  1.1  jruoho 
    254  1.1  jruoho     Next = Next->Asl.Next;
    255  1.1  jruoho     if (Next->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
    256  1.1  jruoho     {
    257  1.1  jruoho         if (Next->Asl.Value.Integer > 15)
    258  1.1  jruoho         {
    259  1.1  jruoho             AslError (ASL_ERROR, ASL_MSG_SYNC_LEVEL, Next, NULL);
    260  1.1  jruoho         }
    261  1.1  jruoho         Concurrency = (UINT8) Next->Asl.Value.Integer;
    262  1.1  jruoho     }
    263  1.1  jruoho 
    264  1.1  jruoho     /* Put the bits in their proper places */
    265  1.1  jruoho 
    266  1.1  jruoho     MethodFlags = (UINT8) ((NumArgs & 0x7) |
    267  1.1  jruoho                           ((Serialized & 0x1) << 3) |
    268  1.1  jruoho                           ((Concurrency & 0xF) << 4));
    269  1.1  jruoho 
    270  1.1  jruoho     /* Use the last node for the combined flags byte */
    271  1.1  jruoho 
    272  1.1  jruoho     Next->Asl.Value.Integer = MethodFlags;
    273  1.1  jruoho     Next->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
    274  1.1  jruoho     Next->Asl.AmlLength = 1;
    275  1.1  jruoho     Next->Asl.ParseOpcode = PARSEOP_RAW_DATA;
    276  1.1  jruoho 
    277  1.1  jruoho     /* Save the arg count in the first node */
    278  1.1  jruoho 
    279  1.1  jruoho     Op->Asl.Extra = NumArgs;
    280  1.1  jruoho }
    281  1.1  jruoho 
    282  1.1  jruoho 
    283  1.1  jruoho /*******************************************************************************
    284  1.1  jruoho  *
    285  1.1  jruoho  * FUNCTION:    OpnDoFieldCommon
    286  1.1  jruoho  *
    287  1.1  jruoho  * PARAMETERS:  FieldOp       - Node for an ASL field
    288  1.1  jruoho  *              Op            - The parent parse node
    289  1.1  jruoho  *
    290  1.1  jruoho  * RETURN:      None
    291  1.1  jruoho  *
    292  1.1  jruoho  * DESCRIPTION: Construct the AML operands for the various field keywords,
    293  1.1  jruoho  *              FIELD, BANKFIELD, INDEXFIELD
    294  1.1  jruoho  *
    295  1.1  jruoho  ******************************************************************************/
    296  1.1  jruoho 
    297  1.1  jruoho static void
    298  1.1  jruoho OpnDoFieldCommon (
    299  1.1  jruoho     ACPI_PARSE_OBJECT       *FieldOp,
    300  1.1  jruoho     ACPI_PARSE_OBJECT       *Op)
    301  1.1  jruoho {
    302  1.1  jruoho     ACPI_PARSE_OBJECT       *Next;
    303  1.1  jruoho     ACPI_PARSE_OBJECT       *PkgLengthNode;
    304  1.1  jruoho     UINT32                  CurrentBitOffset;
    305  1.1  jruoho     UINT32                  NewBitOffset;
    306  1.1  jruoho     UINT8                   AccessType;
    307  1.1  jruoho     UINT8                   LockRule;
    308  1.1  jruoho     UINT8                   UpdateRule;
    309  1.1  jruoho     UINT8                   FieldFlags;
    310  1.1  jruoho     UINT32                  MinimumLength;
    311  1.1  jruoho 
    312  1.1  jruoho 
    313  1.1  jruoho     /* AccessType -- not optional, so no need to check for DEFAULT_ARG */
    314  1.1  jruoho 
    315  1.1  jruoho     AccessType = (UINT8) Op->Asl.Value.Integer;
    316  1.1  jruoho     Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
    317  1.1  jruoho 
    318  1.1  jruoho     /* Set the access type in the parent (field) node for use later */
    319  1.1  jruoho 
    320  1.1  jruoho     FieldOp->Asl.Value.Integer = AccessType;
    321  1.1  jruoho 
    322  1.1  jruoho     /* LockRule -- not optional, so no need to check for DEFAULT_ARG */
    323  1.1  jruoho 
    324  1.1  jruoho     Next = Op->Asl.Next;
    325  1.1  jruoho     LockRule = (UINT8) Next->Asl.Value.Integer;
    326  1.1  jruoho     Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
    327  1.1  jruoho 
    328  1.1  jruoho     /* UpdateRule -- not optional, so no need to check for DEFAULT_ARG */
    329  1.1  jruoho 
    330  1.1  jruoho     Next = Next->Asl.Next;
    331  1.1  jruoho     UpdateRule = (UINT8) Next->Asl.Value.Integer;
    332  1.1  jruoho 
    333  1.1  jruoho     /*
    334  1.1  jruoho      * Generate the flags byte.  The various fields are already
    335  1.1  jruoho      * in the right bit position via translation from the
    336  1.1  jruoho      * keywords by the parser.
    337  1.1  jruoho      */
    338  1.1  jruoho     FieldFlags = (UINT8) (AccessType | LockRule | UpdateRule);
    339  1.1  jruoho 
    340  1.1  jruoho     /* Use the previous node to be the FieldFlags node */
    341  1.1  jruoho 
    342  1.1  jruoho     /* Set the node to RAW_DATA */
    343  1.1  jruoho 
    344  1.1  jruoho     Next->Asl.Value.Integer = FieldFlags;
    345  1.1  jruoho     Next->Asl.AmlOpcode     = AML_RAW_DATA_BYTE;
    346  1.1  jruoho     Next->Asl.AmlLength     = 1;
    347  1.1  jruoho     Next->Asl.ParseOpcode   = PARSEOP_RAW_DATA;
    348  1.1  jruoho 
    349  1.1  jruoho     /* Process the FieldUnitList */
    350  1.1  jruoho 
    351  1.1  jruoho     Next = Next->Asl.Next;
    352  1.1  jruoho     CurrentBitOffset = 0;
    353  1.1  jruoho 
    354  1.1  jruoho     while (Next)
    355  1.1  jruoho     {
    356  1.1  jruoho         /* Save the offset of this field unit */
    357  1.1  jruoho 
    358  1.1  jruoho         Next->Asl.ExtraValue = CurrentBitOffset;
    359  1.1  jruoho 
    360  1.1  jruoho         switch (Next->Asl.ParseOpcode)
    361  1.1  jruoho         {
    362  1.1  jruoho         case PARSEOP_ACCESSAS:
    363  1.1  jruoho 
    364  1.1  jruoho             PkgLengthNode = Next->Asl.Child;
    365  1.1  jruoho             AccessType = (UINT8) PkgLengthNode->Asl.Value.Integer;
    366  1.1  jruoho 
    367  1.1  jruoho             /* Nothing additional to do */
    368  1.1  jruoho             break;
    369  1.1  jruoho 
    370  1.1  jruoho 
    371  1.1  jruoho         case PARSEOP_OFFSET:
    372  1.1  jruoho 
    373  1.1  jruoho             /* New offset into the field */
    374  1.1  jruoho 
    375  1.1  jruoho             PkgLengthNode = Next->Asl.Child;
    376  1.1  jruoho             NewBitOffset = ((UINT32) PkgLengthNode->Asl.Value.Integer) * 8;
    377  1.1  jruoho 
    378  1.1  jruoho             /*
    379  1.1  jruoho              * Examine the specified offset in relation to the
    380  1.1  jruoho              * current offset counter.
    381  1.1  jruoho              */
    382  1.1  jruoho             if (NewBitOffset < CurrentBitOffset)
    383  1.1  jruoho             {
    384  1.1  jruoho                 /*
    385  1.1  jruoho                  * Not allowed to specify a backwards offset!
    386  1.1  jruoho                  * Issue error and ignore this node.
    387  1.1  jruoho                  */
    388  1.1  jruoho                 AslError (ASL_ERROR, ASL_MSG_BACKWARDS_OFFSET, PkgLengthNode,
    389  1.1  jruoho                     NULL);
    390  1.1  jruoho                 Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
    391  1.1  jruoho                 PkgLengthNode->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
    392  1.1  jruoho             }
    393  1.1  jruoho             else if (NewBitOffset == CurrentBitOffset)
    394  1.1  jruoho             {
    395  1.1  jruoho                 /*
    396  1.1  jruoho                  * Offset is redundant; we don't need to output an
    397  1.1  jruoho                  * offset opcode.  Just set these nodes to default
    398  1.1  jruoho                  */
    399  1.1  jruoho                 Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
    400  1.1  jruoho                 PkgLengthNode->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
    401  1.1  jruoho             }
    402  1.1  jruoho             else
    403  1.1  jruoho             {
    404  1.1  jruoho                 /*
    405  1.1  jruoho                  * Valid new offset - set the value to be inserted into the AML
    406  1.1  jruoho                  * and update the offset counter.
    407  1.1  jruoho                  */
    408  1.1  jruoho                 PkgLengthNode->Asl.Value.Integer =
    409  1.1  jruoho                     NewBitOffset - CurrentBitOffset;
    410  1.1  jruoho                 CurrentBitOffset = NewBitOffset;
    411  1.1  jruoho             }
    412  1.1  jruoho             break;
    413  1.1  jruoho 
    414  1.1  jruoho 
    415  1.1  jruoho         case PARSEOP_NAMESEG:
    416  1.1  jruoho         case PARSEOP_RESERVED_BYTES:
    417  1.1  jruoho 
    418  1.1  jruoho             /* Named or reserved field entry */
    419  1.1  jruoho 
    420  1.1  jruoho             PkgLengthNode     = Next->Asl.Child;
    421  1.1  jruoho             NewBitOffset      = (UINT32) PkgLengthNode->Asl.Value.Integer;
    422  1.1  jruoho             CurrentBitOffset += NewBitOffset;
    423  1.1  jruoho 
    424  1.1  jruoho             /* Save the current AccessAs value for error checking later */
    425  1.1  jruoho 
    426  1.1  jruoho             switch (AccessType)
    427  1.1  jruoho             {
    428  1.1  jruoho                 case AML_FIELD_ACCESS_ANY:
    429  1.1  jruoho                 case AML_FIELD_ACCESS_BYTE:
    430  1.1  jruoho                 case AML_FIELD_ACCESS_BUFFER:
    431  1.1  jruoho                 default:
    432  1.1  jruoho                     MinimumLength = 8;
    433  1.1  jruoho                     break;
    434  1.1  jruoho 
    435  1.1  jruoho                 case AML_FIELD_ACCESS_WORD:
    436  1.1  jruoho                     MinimumLength = 16;
    437  1.1  jruoho                     break;
    438  1.1  jruoho 
    439  1.1  jruoho                 case AML_FIELD_ACCESS_DWORD:
    440  1.1  jruoho                     MinimumLength = 32;
    441  1.1  jruoho                     break;
    442  1.1  jruoho 
    443  1.1  jruoho                 case AML_FIELD_ACCESS_QWORD:
    444  1.1  jruoho                     MinimumLength = 64;
    445  1.1  jruoho                     break;
    446  1.1  jruoho             }
    447  1.1  jruoho 
    448  1.1  jruoho             PkgLengthNode->Asl.ExtraValue = MinimumLength;
    449  1.1  jruoho             break;
    450  1.1  jruoho 
    451  1.1  jruoho         default:
    452  1.1  jruoho             /* All supported field opcodes must appear above */
    453  1.1  jruoho             break;
    454  1.1  jruoho         }
    455  1.1  jruoho 
    456  1.1  jruoho         /* Move on to next entry in the field list */
    457  1.1  jruoho 
    458  1.1  jruoho         Next = Next->Asl.Next;
    459  1.1  jruoho     }
    460  1.1  jruoho }
    461  1.1  jruoho 
    462  1.1  jruoho 
    463  1.1  jruoho /*******************************************************************************
    464  1.1  jruoho  *
    465  1.1  jruoho  * FUNCTION:    OpnDoField
    466  1.1  jruoho  *
    467  1.1  jruoho  * PARAMETERS:  Op        - The parent parse node
    468  1.1  jruoho  *
    469  1.1  jruoho  * RETURN:      None
    470  1.1  jruoho  *
    471  1.1  jruoho  * DESCRIPTION: Construct the AML operands for the FIELD ASL keyword
    472  1.1  jruoho  *
    473  1.1  jruoho  ******************************************************************************/
    474  1.1  jruoho 
    475  1.1  jruoho static void
    476  1.1  jruoho OpnDoField (
    477  1.1  jruoho     ACPI_PARSE_OBJECT       *Op)
    478  1.1  jruoho {
    479  1.1  jruoho     ACPI_PARSE_OBJECT       *Next;
    480  1.1  jruoho 
    481  1.1  jruoho 
    482  1.1  jruoho     /* Opcode is parent node */
    483  1.1  jruoho     /* First child is field name */
    484  1.1  jruoho 
    485  1.1  jruoho     Next = Op->Asl.Child;
    486  1.1  jruoho 
    487  1.1  jruoho     /* Second child is the AccessType */
    488  1.1  jruoho 
    489  1.1  jruoho     OpnDoFieldCommon (Op, Next->Asl.Next);
    490  1.1  jruoho }
    491  1.1  jruoho 
    492  1.1  jruoho 
    493  1.1  jruoho /*******************************************************************************
    494  1.1  jruoho  *
    495  1.1  jruoho  * FUNCTION:    OpnDoIndexField
    496  1.1  jruoho  *
    497  1.1  jruoho  * PARAMETERS:  Op        - The parent parse node
    498  1.1  jruoho  *
    499  1.1  jruoho  * RETURN:      None
    500  1.1  jruoho  *
    501  1.1  jruoho  * DESCRIPTION: Construct the AML operands for the INDEXFIELD ASL keyword
    502  1.1  jruoho  *
    503  1.1  jruoho  ******************************************************************************/
    504  1.1  jruoho 
    505  1.1  jruoho static void
    506  1.1  jruoho OpnDoIndexField (
    507  1.1  jruoho     ACPI_PARSE_OBJECT       *Op)
    508  1.1  jruoho {
    509  1.1  jruoho     ACPI_PARSE_OBJECT       *Next;
    510  1.1  jruoho 
    511  1.1  jruoho 
    512  1.1  jruoho     /* Opcode is parent node */
    513  1.1  jruoho     /* First child is the index name */
    514  1.1  jruoho 
    515  1.1  jruoho     Next = Op->Asl.Child;
    516  1.1  jruoho 
    517  1.1  jruoho     /* Second child is the data name */
    518  1.1  jruoho 
    519  1.1  jruoho     Next = Next->Asl.Next;
    520  1.1  jruoho 
    521  1.1  jruoho     /* Third child is the AccessType */
    522  1.1  jruoho 
    523  1.1  jruoho     OpnDoFieldCommon (Op, Next->Asl.Next);
    524  1.1  jruoho }
    525  1.1  jruoho 
    526  1.1  jruoho 
    527  1.1  jruoho /*******************************************************************************
    528  1.1  jruoho  *
    529  1.1  jruoho  * FUNCTION:    OpnDoBankField
    530  1.1  jruoho  *
    531  1.1  jruoho  * PARAMETERS:  Op        - The parent parse node
    532  1.1  jruoho  *
    533  1.1  jruoho  * RETURN:      None
    534  1.1  jruoho  *
    535  1.1  jruoho  * DESCRIPTION: Construct the AML operands for the BANKFIELD ASL keyword
    536  1.1  jruoho  *
    537  1.1  jruoho  ******************************************************************************/
    538  1.1  jruoho 
    539  1.1  jruoho static void
    540  1.1  jruoho OpnDoBankField (
    541  1.1  jruoho     ACPI_PARSE_OBJECT       *Op)
    542  1.1  jruoho {
    543  1.1  jruoho     ACPI_PARSE_OBJECT       *Next;
    544  1.1  jruoho 
    545  1.1  jruoho 
    546  1.1  jruoho     /* Opcode is parent node */
    547  1.1  jruoho     /* First child is the region name */
    548  1.1  jruoho 
    549  1.1  jruoho     Next = Op->Asl.Child;
    550  1.1  jruoho 
    551  1.1  jruoho     /* Second child is the bank name */
    552  1.1  jruoho 
    553  1.1  jruoho     Next = Next->Asl.Next;
    554  1.1  jruoho 
    555  1.1  jruoho     /* Third child is the bank value */
    556  1.1  jruoho 
    557  1.1  jruoho     Next = Next->Asl.Next;
    558  1.1  jruoho 
    559  1.1  jruoho     /* Fourth child is the AccessType */
    560  1.1  jruoho 
    561  1.1  jruoho     OpnDoFieldCommon (Op, Next->Asl.Next);
    562  1.1  jruoho }
    563  1.1  jruoho 
    564  1.1  jruoho 
    565  1.1  jruoho /*******************************************************************************
    566  1.1  jruoho  *
    567  1.1  jruoho  * FUNCTION:    OpnDoRegion
    568  1.1  jruoho  *
    569  1.1  jruoho  * PARAMETERS:  Op        - The parent parse node
    570  1.1  jruoho  *
    571  1.1  jruoho  * RETURN:      None
    572  1.1  jruoho  *
    573  1.1  jruoho  * DESCRIPTION: Tries to get the length of the region.  Can only do this at
    574  1.1  jruoho  *              compile time if the length is a constant.
    575  1.1  jruoho  *
    576  1.1  jruoho  ******************************************************************************/
    577  1.1  jruoho 
    578  1.1  jruoho static void
    579  1.1  jruoho OpnDoRegion (
    580  1.1  jruoho     ACPI_PARSE_OBJECT       *Op)
    581  1.1  jruoho {
    582  1.1  jruoho     ACPI_PARSE_OBJECT       *Next;
    583  1.1  jruoho 
    584  1.1  jruoho 
    585  1.1  jruoho     /* Opcode is parent node */
    586  1.1  jruoho     /* First child is the region name */
    587  1.1  jruoho 
    588  1.1  jruoho     Next = Op->Asl.Child;
    589  1.1  jruoho 
    590  1.1  jruoho     /* Second child is the space ID*/
    591  1.1  jruoho 
    592  1.1  jruoho     Next = Next->Asl.Next;
    593  1.1  jruoho 
    594  1.1  jruoho     /* Third child is the region offset */
    595  1.1  jruoho 
    596  1.1  jruoho     Next = Next->Asl.Next;
    597  1.1  jruoho 
    598  1.1  jruoho     /* Fourth child is the region length */
    599  1.1  jruoho 
    600  1.1  jruoho     Next = Next->Asl.Next;
    601  1.1  jruoho     if (Next->Asl.ParseOpcode == PARSEOP_INTEGER)
    602  1.1  jruoho     {
    603  1.1  jruoho         Op->Asl.Value.Integer = Next->Asl.Value.Integer;
    604  1.1  jruoho     }
    605  1.1  jruoho     else
    606  1.1  jruoho     {
    607  1.1  jruoho         Op->Asl.Value.Integer = ACPI_UINT64_MAX;
    608  1.1  jruoho     }
    609  1.1  jruoho }
    610  1.1  jruoho 
    611  1.1  jruoho 
    612  1.1  jruoho /*******************************************************************************
    613  1.1  jruoho  *
    614  1.1  jruoho  * FUNCTION:    OpnDoBuffer
    615  1.1  jruoho  *
    616  1.1  jruoho  * PARAMETERS:  Op        - The parent parse node
    617  1.1  jruoho  *
    618  1.1  jruoho  * RETURN:      None
    619  1.1  jruoho  *
    620  1.1  jruoho  * DESCRIPTION: Construct the AML operands for the BUFFER ASL keyword.  We
    621  1.1  jruoho  *              build a single raw byte buffer from the initialization nodes,
    622  1.1  jruoho  *              each parse node contains a buffer byte.
    623  1.1  jruoho  *
    624  1.1  jruoho  ******************************************************************************/
    625  1.1  jruoho 
    626  1.1  jruoho static void
    627  1.1  jruoho OpnDoBuffer (
    628  1.1  jruoho     ACPI_PARSE_OBJECT       *Op)
    629  1.1  jruoho {
    630  1.1  jruoho     ACPI_PARSE_OBJECT       *InitializerOp;
    631  1.1  jruoho     ACPI_PARSE_OBJECT       *BufferLengthOp;
    632  1.1  jruoho 
    633  1.1  jruoho     /* Optional arguments for this opcode with defaults */
    634  1.1  jruoho 
    635  1.1  jruoho     UINT32                  BufferLength = 0;
    636  1.1  jruoho 
    637  1.1  jruoho 
    638  1.1  jruoho     /* Opcode and package length first */
    639  1.1  jruoho     /* Buffer Length is next, followed by the initializer list */
    640  1.1  jruoho 
    641  1.1  jruoho     BufferLengthOp = Op->Asl.Child;
    642  1.1  jruoho     InitializerOp = BufferLengthOp->Asl.Next;
    643  1.1  jruoho 
    644  1.1  jruoho     /*
    645  1.1  jruoho      * If the BufferLength is not an INTEGER or was not specified in the ASL
    646  1.1  jruoho      * (DEFAULT_ARG), it is a TermArg that is
    647  1.1  jruoho      * evaluated at run-time, and we are therefore finished.
    648  1.1  jruoho      */
    649  1.1  jruoho     if ((BufferLengthOp->Asl.ParseOpcode != PARSEOP_INTEGER) &&
    650  1.1  jruoho         (BufferLengthOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG))
    651  1.1  jruoho     {
    652  1.1  jruoho         return;
    653  1.1  jruoho     }
    654  1.1  jruoho 
    655  1.1  jruoho     /*
    656  1.1  jruoho      * We want to count the number of items in the initializer list, because if
    657  1.1  jruoho      * it is larger than the buffer length, we will define the buffer size
    658  1.1  jruoho      * to be the size of the initializer list (as per the ACPI Specification)
    659  1.1  jruoho      */
    660  1.1  jruoho     switch (InitializerOp->Asl.ParseOpcode)
    661  1.1  jruoho     {
    662  1.1  jruoho     case PARSEOP_INTEGER:
    663  1.1  jruoho     case PARSEOP_BYTECONST:
    664  1.1  jruoho     case PARSEOP_WORDCONST:
    665  1.1  jruoho     case PARSEOP_DWORDCONST:
    666  1.1  jruoho 
    667  1.1  jruoho         /* The peer list contains the byte list (if any...) */
    668  1.1  jruoho 
    669  1.1  jruoho         while (InitializerOp)
    670  1.1  jruoho         {
    671  1.1  jruoho             /* For buffers, this is a list of raw bytes */
    672  1.1  jruoho 
    673  1.1  jruoho             InitializerOp->Asl.AmlOpcode      = AML_RAW_DATA_BYTE;
    674  1.1  jruoho             InitializerOp->Asl.AmlLength      = 1;
    675  1.1  jruoho             InitializerOp->Asl.ParseOpcode    = PARSEOP_RAW_DATA;
    676  1.1  jruoho 
    677  1.1  jruoho             BufferLength++;
    678  1.1  jruoho             InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
    679  1.1  jruoho         }
    680  1.1  jruoho         break;
    681  1.1  jruoho 
    682  1.1  jruoho 
    683  1.1  jruoho     case PARSEOP_STRING_LITERAL:
    684  1.1  jruoho 
    685  1.1  jruoho         /*
    686  1.1  jruoho          * Only one initializer, the string.  Buffer must be big enough to hold
    687  1.1  jruoho          * the string plus the null termination byte
    688  1.1  jruoho          */
    689  1.1  jruoho         BufferLength = strlen (InitializerOp->Asl.Value.String) + 1;
    690  1.1  jruoho 
    691  1.1  jruoho         InitializerOp->Asl.AmlOpcode      = AML_RAW_DATA_BUFFER;
    692  1.1  jruoho         InitializerOp->Asl.AmlLength      = BufferLength;
    693  1.1  jruoho         InitializerOp->Asl.ParseOpcode    = PARSEOP_RAW_DATA;
    694  1.1  jruoho         break;
    695  1.1  jruoho 
    696  1.1  jruoho 
    697  1.1  jruoho     case PARSEOP_RAW_DATA:
    698  1.1  jruoho 
    699  1.1  jruoho         /* Buffer nodes are already initialized (e.g. Unicode operator) */
    700  1.1  jruoho         return;
    701  1.1  jruoho 
    702  1.1  jruoho 
    703  1.1  jruoho     case PARSEOP_DEFAULT_ARG:
    704  1.1  jruoho         break;
    705  1.1  jruoho 
    706  1.1  jruoho 
    707  1.1  jruoho     default:
    708  1.1  jruoho         AslError (ASL_ERROR, ASL_MSG_INVALID_OPERAND, InitializerOp,
    709  1.1  jruoho             "Unknown buffer initializer opcode");
    710  1.1  jruoho         printf ("Unknown buffer initializer opcode [%s]\n",
    711  1.1  jruoho                         UtGetOpName (InitializerOp->Asl.ParseOpcode));
    712  1.1  jruoho         return;
    713  1.1  jruoho     }
    714  1.1  jruoho 
    715  1.1  jruoho     /* Check if initializer list is longer than the buffer length */
    716  1.1  jruoho 
    717  1.1  jruoho     if (BufferLengthOp->Asl.Value.Integer > BufferLength)
    718  1.1  jruoho     {
    719  1.1  jruoho         BufferLength = (UINT32) BufferLengthOp->Asl.Value.Integer;
    720  1.1  jruoho     }
    721  1.1  jruoho 
    722  1.1  jruoho     if (!BufferLength)
    723  1.1  jruoho     {
    724  1.1  jruoho         /* No length AND no items -- issue notice */
    725  1.1  jruoho 
    726  1.1  jruoho         AslError (ASL_REMARK, ASL_MSG_BUFFER_LENGTH, BufferLengthOp, NULL);
    727  1.1  jruoho 
    728  1.1  jruoho         /* But go ahead and put the buffer length of zero into the AML */
    729  1.1  jruoho     }
    730  1.1  jruoho 
    731  1.1  jruoho     /*
    732  1.1  jruoho      * Just set the buffer size node to be the buffer length, regardless
    733  1.1  jruoho      * of whether it was previously an integer or a default_arg placeholder
    734  1.1  jruoho      */
    735  1.1  jruoho     BufferLengthOp->Asl.ParseOpcode   = PARSEOP_INTEGER;
    736  1.1  jruoho     BufferLengthOp->Asl.AmlOpcode     = AML_DWORD_OP;
    737  1.1  jruoho     BufferLengthOp->Asl.Value.Integer = BufferLength;
    738  1.1  jruoho 
    739  1.1  jruoho     (void) OpcSetOptimalIntegerSize (BufferLengthOp);
    740  1.1  jruoho 
    741  1.1  jruoho     /* Remaining nodes are handled via the tree walk */
    742  1.1  jruoho }
    743  1.1  jruoho 
    744  1.1  jruoho 
    745  1.1  jruoho /*******************************************************************************
    746  1.1  jruoho  *
    747  1.1  jruoho  * FUNCTION:    OpnDoPackage
    748  1.1  jruoho  *
    749  1.1  jruoho  * PARAMETERS:  Op        - The parent parse node
    750  1.1  jruoho  *
    751  1.1  jruoho  * RETURN:      None
    752  1.1  jruoho  *
    753  1.1  jruoho  * DESCRIPTION: Construct the AML operands for the PACKAGE ASL keyword.  NOTE:
    754  1.1  jruoho  *              can only be called after constants have been folded, to ensure
    755  1.1  jruoho  *              that the PackageLength operand has been fully reduced.
    756  1.1  jruoho  *
    757  1.1  jruoho  ******************************************************************************/
    758  1.1  jruoho 
    759  1.1  jruoho void
    760  1.1  jruoho OpnDoPackage (
    761  1.1  jruoho     ACPI_PARSE_OBJECT       *Op)
    762  1.1  jruoho {
    763  1.1  jruoho     ACPI_PARSE_OBJECT       *InitializerOp;
    764  1.1  jruoho     ACPI_PARSE_OBJECT       *PackageLengthOp;
    765  1.1  jruoho     UINT32                  PackageLength = 0;
    766  1.1  jruoho 
    767  1.1  jruoho 
    768  1.1  jruoho     /* Opcode and package length first, followed by the initializer list */
    769  1.1  jruoho 
    770  1.1  jruoho     PackageLengthOp = Op->Asl.Child;
    771  1.1  jruoho     InitializerOp = PackageLengthOp->Asl.Next;
    772  1.1  jruoho 
    773  1.1  jruoho     /* Count the number of items in the initializer list */
    774  1.1  jruoho 
    775  1.1  jruoho     if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
    776  1.1  jruoho     {
    777  1.1  jruoho         /* The peer list contains the byte list (if any...) */
    778  1.1  jruoho 
    779  1.1  jruoho         while (InitializerOp)
    780  1.1  jruoho         {
    781  1.1  jruoho             PackageLength++;
    782  1.1  jruoho             InitializerOp = InitializerOp->Asl.Next;
    783  1.1  jruoho         }
    784  1.1  jruoho     }
    785  1.1  jruoho 
    786  1.1  jruoho     /* If package length is a constant, compare to the initializer list */
    787  1.1  jruoho 
    788  1.1  jruoho     if ((PackageLengthOp->Asl.ParseOpcode == PARSEOP_INTEGER)      ||
    789  1.1  jruoho         (PackageLengthOp->Asl.ParseOpcode == PARSEOP_QWORDCONST))
    790  1.1  jruoho     {
    791  1.1  jruoho         if (PackageLengthOp->Asl.Value.Integer > PackageLength)
    792  1.1  jruoho         {
    793  1.1  jruoho             /*
    794  1.1  jruoho              * Allow package length to be longer than the initializer
    795  1.1  jruoho              * list -- but if the length of initializer list is nonzero,
    796  1.1  jruoho              * issue a message since this is probably a coding error,
    797  1.1  jruoho              * even though technically legal.
    798  1.1  jruoho              */
    799  1.1  jruoho             if (PackageLength > 0)
    800  1.1  jruoho             {
    801  1.1  jruoho                 AslError (ASL_REMARK, ASL_MSG_LIST_LENGTH_SHORT,
    802  1.1  jruoho                     PackageLengthOp, NULL);
    803  1.1  jruoho             }
    804  1.1  jruoho 
    805  1.1  jruoho             PackageLength = (UINT32) PackageLengthOp->Asl.Value.Integer;
    806  1.1  jruoho         }
    807  1.1  jruoho         else if (PackageLengthOp->Asl.Value.Integer < PackageLength)
    808  1.1  jruoho         {
    809  1.1  jruoho             /*
    810  1.1  jruoho              * The package length is smaller than the length of the
    811  1.1  jruoho              * initializer list. This is an error as per the ACPI spec.
    812  1.1  jruoho              */
    813  1.1  jruoho             AslError (ASL_ERROR, ASL_MSG_LIST_LENGTH_LONG,
    814  1.1  jruoho                 PackageLengthOp, NULL);
    815  1.1  jruoho         }
    816  1.1  jruoho     }
    817  1.1  jruoho 
    818  1.1  jruoho     if (PackageLengthOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
    819  1.1  jruoho     {
    820  1.1  jruoho         /*
    821  1.1  jruoho          * This is the case if the PackageLength was left empty - Package()
    822  1.1  jruoho          * The package length becomes the length of the initializer list
    823  1.1  jruoho          */
    824  1.1  jruoho         Op->Asl.Child->Asl.ParseOpcode = PARSEOP_INTEGER;
    825  1.1  jruoho         Op->Asl.Child->Asl.Value.Integer = PackageLength;
    826  1.1  jruoho 
    827  1.1  jruoho         /* Set the AML opcode */
    828  1.1  jruoho 
    829  1.1  jruoho         (void) OpcSetOptimalIntegerSize (Op->Asl.Child);
    830  1.1  jruoho     }
    831  1.1  jruoho 
    832  1.1  jruoho     /* If not a variable-length package, check for a zero package length */
    833  1.1  jruoho 
    834  1.1  jruoho     if ((PackageLengthOp->Asl.ParseOpcode == PARSEOP_INTEGER)      ||
    835  1.1  jruoho         (PackageLengthOp->Asl.ParseOpcode == PARSEOP_QWORDCONST)   ||
    836  1.1  jruoho         (PackageLengthOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG))
    837  1.1  jruoho     {
    838  1.1  jruoho         if (!PackageLength)
    839  1.1  jruoho         {
    840  1.1  jruoho             /* No length AND no initializer list -- issue a remark */
    841  1.1  jruoho 
    842  1.1  jruoho             AslError (ASL_REMARK, ASL_MSG_PACKAGE_LENGTH,
    843  1.1  jruoho                 PackageLengthOp, NULL);
    844  1.1  jruoho 
    845  1.1  jruoho             /* But go ahead and put the buffer length of zero into the AML */
    846  1.1  jruoho         }
    847  1.1  jruoho     }
    848  1.1  jruoho 
    849  1.1  jruoho     /*
    850  1.1  jruoho      * If the PackageLength is a constant <= 255, we can change the
    851  1.1  jruoho      * AML opcode from VarPackage to a simple (ACPI 1.0) Package opcode.
    852  1.1  jruoho      */
    853  1.1  jruoho     if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_INTEGER) &&
    854  1.1  jruoho         (Op->Asl.Child->Asl.Value.Integer <= 255))
    855  1.1  jruoho     {
    856  1.1  jruoho         Op->Asl.AmlOpcode = AML_PACKAGE_OP;
    857  1.1  jruoho         Op->Asl.ParseOpcode = PARSEOP_PACKAGE;
    858  1.1  jruoho 
    859  1.1  jruoho         /*
    860  1.1  jruoho          * Just set the package size node to be the package length, regardless
    861  1.1  jruoho          * of whether it was previously an integer or a default_arg placeholder
    862  1.1  jruoho          */
    863  1.1  jruoho         PackageLengthOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
    864  1.1  jruoho         PackageLengthOp->Asl.AmlLength = 1;
    865  1.1  jruoho         PackageLengthOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
    866  1.1  jruoho         PackageLengthOp->Asl.Value.Integer = PackageLength;
    867  1.1  jruoho     }
    868  1.1  jruoho 
    869  1.1  jruoho     /* Remaining nodes are handled via the tree walk */
    870  1.1  jruoho }
    871  1.1  jruoho 
    872  1.1  jruoho 
    873  1.1  jruoho /*******************************************************************************
    874  1.1  jruoho  *
    875  1.1  jruoho  * FUNCTION:    OpnDoLoadTable
    876  1.1  jruoho  *
    877  1.1  jruoho  * PARAMETERS:  Op        - The parent parse node
    878  1.1  jruoho  *
    879  1.1  jruoho  * RETURN:      None
    880  1.1  jruoho  *
    881  1.1  jruoho  * DESCRIPTION: Construct the AML operands for the LOADTABLE ASL keyword.
    882  1.1  jruoho  *
    883  1.1  jruoho  ******************************************************************************/
    884  1.1  jruoho 
    885  1.1  jruoho static void
    886  1.1  jruoho OpnDoLoadTable (
    887  1.1  jruoho     ACPI_PARSE_OBJECT       *Op)
    888  1.1  jruoho {
    889  1.1  jruoho     ACPI_PARSE_OBJECT       *Next;
    890  1.1  jruoho 
    891  1.1  jruoho 
    892  1.1  jruoho     /* Opcode is parent node */
    893  1.1  jruoho     /* First child is the table signature */
    894  1.1  jruoho 
    895  1.1  jruoho     Next = Op->Asl.Child;
    896  1.1  jruoho 
    897  1.1  jruoho     /* Second child is the OEM ID*/
    898  1.1  jruoho 
    899  1.1  jruoho     Next = Next->Asl.Next;
    900  1.1  jruoho 
    901  1.1  jruoho     /* Third child is the OEM table ID */
    902  1.1  jruoho 
    903  1.1  jruoho     Next = Next->Asl.Next;
    904  1.1  jruoho 
    905  1.1  jruoho     /* Fourth child is the RootPath string */
    906  1.1  jruoho 
    907  1.1  jruoho     Next = Next->Asl.Next;
    908  1.1  jruoho     if (Next->Asl.ParseOpcode == PARSEOP_ZERO)
    909  1.1  jruoho     {
    910  1.1  jruoho         Next->Asl.ParseOpcode    = PARSEOP_STRING_LITERAL;
    911  1.1  jruoho         Next->Asl.Value.String   = "\\";
    912  1.1  jruoho         Next->Asl.AmlLength      = 2;
    913  1.1  jruoho         OpcGenerateAmlOpcode (Next);
    914  1.1  jruoho     }
    915  1.1  jruoho 
    916  1.1  jruoho #ifdef ASL_FUTURE_IMPLEMENTATION
    917  1.1  jruoho 
    918  1.1  jruoho     /* TBD: NOT IMPLEMENTED */
    919  1.1  jruoho     /* Fifth child is the [optional] ParameterPathString */
    920  1.1  jruoho     /* Sixth child is the [optional] ParameterData */
    921  1.1  jruoho 
    922  1.1  jruoho     Next = Next->Asl.Next;
    923  1.1  jruoho     if (Next->Asl.ParseOpcode == DEFAULT_ARG)
    924  1.1  jruoho     {
    925  1.1  jruoho         Next->Asl.AmlLength = 1;
    926  1.1  jruoho         Next->Asl.ParseOpcode = ZERO;
    927  1.1  jruoho         OpcGenerateAmlOpcode (Next);
    928  1.1  jruoho     }
    929  1.1  jruoho 
    930  1.1  jruoho 
    931  1.1  jruoho     Next = Next->Asl.Next;
    932  1.1  jruoho     if (Next->Asl.ParseOpcode == DEFAULT_ARG)
    933  1.1  jruoho     {
    934  1.1  jruoho         Next->Asl.AmlLength = 1;
    935  1.1  jruoho         Next->Asl.ParseOpcode = ZERO;
    936  1.1  jruoho         OpcGenerateAmlOpcode (Next);
    937  1.1  jruoho     }
    938  1.1  jruoho #endif
    939  1.1  jruoho }
    940  1.1  jruoho 
    941  1.1  jruoho 
    942  1.1  jruoho /*******************************************************************************
    943  1.1  jruoho  *
    944  1.1  jruoho  * FUNCTION:    OpnDoDefinitionBlock
    945  1.1  jruoho  *
    946  1.1  jruoho  * PARAMETERS:  Op        - The parent parse node
    947  1.1  jruoho  *
    948  1.1  jruoho  * RETURN:      None
    949  1.1  jruoho  *
    950  1.1  jruoho  * DESCRIPTION: Construct the AML operands for the DEFINITIONBLOCK ASL keyword
    951  1.1  jruoho  *
    952  1.1  jruoho  ******************************************************************************/
    953  1.1  jruoho 
    954  1.1  jruoho static void
    955  1.1  jruoho OpnDoDefinitionBlock (
    956  1.1  jruoho     ACPI_PARSE_OBJECT       *Op)
    957  1.1  jruoho {
    958  1.1  jruoho     ACPI_PARSE_OBJECT       *Child;
    959  1.1  jruoho     ACPI_SIZE               Length;
    960  1.1  jruoho     UINT32                  i;
    961  1.1  jruoho     char                    *Filename;
    962  1.1  jruoho 
    963  1.1  jruoho 
    964  1.1  jruoho     /*
    965  1.1  jruoho      * These nodes get stuffed into the table header.  They are special
    966  1.1  jruoho      * cased when the table is written to the output file.
    967  1.1  jruoho      *
    968  1.1  jruoho      * Mark all of these nodes as non-usable so they won't get output
    969  1.1  jruoho      * as AML opcodes!
    970  1.1  jruoho      */
    971  1.1  jruoho 
    972  1.1  jruoho     /* Get AML filename. Use it if non-null */
    973  1.1  jruoho 
    974  1.1  jruoho     Child = Op->Asl.Child;
    975  1.1  jruoho     if (Child->Asl.Value.Buffer  &&
    976  1.1  jruoho         *Child->Asl.Value.Buffer &&
    977  1.1  jruoho         (Gbl_UseDefaultAmlFilename))
    978  1.1  jruoho     {
    979  1.1  jruoho         /*
    980  1.1  jruoho          * We will use the AML filename that is embedded in the source file
    981  1.1  jruoho          * for the output filename.
    982  1.1  jruoho          */
    983  1.1  jruoho         Filename = ACPI_ALLOCATE (strlen (Gbl_DirectoryPath) +
    984  1.1  jruoho                     strlen ((char *) Child->Asl.Value.Buffer) + 1);
    985  1.1  jruoho 
    986  1.1  jruoho         /* Prepend the current directory path */
    987  1.1  jruoho 
    988  1.1  jruoho         strcpy (Filename, Gbl_DirectoryPath);
    989  1.1  jruoho         strcat (Filename, (char *) Child->Asl.Value.Buffer);
    990  1.1  jruoho 
    991  1.1  jruoho         Gbl_OutputFilenamePrefix = Filename;
    992  1.1  jruoho     }
    993  1.1  jruoho     Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
    994  1.1  jruoho 
    995  1.1  jruoho     /* Signature */
    996  1.1  jruoho 
    997  1.1  jruoho     Child = Child->Asl.Next;
    998  1.1  jruoho     Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
    999  1.1  jruoho     if (Child->Asl.Value.String)
   1000  1.1  jruoho     {
   1001  1.1  jruoho         Gbl_TableSignature = Child->Asl.Value.String;
   1002  1.1  jruoho         if (ACPI_STRLEN (Gbl_TableSignature) != 4)
   1003  1.1  jruoho         {
   1004  1.1  jruoho             AslError (ASL_ERROR, ASL_MSG_TABLE_SIGNATURE, Child,
   1005  1.1  jruoho                 "Length not exactly 4");
   1006  1.1  jruoho         }
   1007  1.1  jruoho 
   1008  1.1  jruoho         for (i = 0; i < 4; i++)
   1009  1.1  jruoho         {
   1010  1.1  jruoho             if (!isalnum ((int) Gbl_TableSignature[i]))
   1011  1.1  jruoho             {
   1012  1.1  jruoho                 AslError (ASL_ERROR, ASL_MSG_TABLE_SIGNATURE, Child,
   1013  1.1  jruoho                     "Contains non-alphanumeric characters");
   1014  1.1  jruoho             }
   1015  1.1  jruoho         }
   1016  1.1  jruoho     }
   1017  1.1  jruoho 
   1018  1.1  jruoho     /* Revision */
   1019  1.1  jruoho 
   1020  1.1  jruoho     Child = Child->Asl.Next;
   1021  1.1  jruoho     Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
   1022  1.1  jruoho     /*
   1023  1.1  jruoho      * We used the revision to set the integer width earlier
   1024  1.1  jruoho      */
   1025  1.1  jruoho 
   1026  1.1  jruoho     /* OEMID */
   1027  1.1  jruoho 
   1028  1.1  jruoho     Child = Child->Asl.Next;
   1029  1.1  jruoho     Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
   1030  1.1  jruoho 
   1031  1.1  jruoho     /* OEM TableID */
   1032  1.1  jruoho 
   1033  1.1  jruoho     Child = Child->Asl.Next;
   1034  1.1  jruoho     Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
   1035  1.1  jruoho     if (Child->Asl.Value.String)
   1036  1.1  jruoho     {
   1037  1.1  jruoho         Length = ACPI_STRLEN (Child->Asl.Value.String);
   1038  1.1  jruoho         Gbl_TableId = AcpiOsAllocate (Length + 1);
   1039  1.1  jruoho         ACPI_STRCPY (Gbl_TableId, Child->Asl.Value.String);
   1040  1.1  jruoho 
   1041  1.1  jruoho         for (i = 0; i < Length; i++)
   1042  1.1  jruoho         {
   1043  1.1  jruoho             if (Gbl_TableId[i] == ' ')
   1044  1.1  jruoho             {
   1045  1.1  jruoho                 Gbl_TableId[i] = 0;
   1046  1.1  jruoho                 break;
   1047  1.1  jruoho             }
   1048  1.1  jruoho         }
   1049  1.1  jruoho     }
   1050  1.1  jruoho 
   1051  1.1  jruoho     /* OEM Revision */
   1052  1.1  jruoho 
   1053  1.1  jruoho     Child = Child->Asl.Next;
   1054  1.1  jruoho     Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
   1055  1.1  jruoho }
   1056  1.1  jruoho 
   1057  1.1  jruoho 
   1058  1.1  jruoho /*******************************************************************************
   1059  1.1  jruoho  *
   1060  1.1  jruoho  * FUNCTION:    UtGetArg
   1061  1.1  jruoho  *
   1062  1.1  jruoho  * PARAMETERS:  Op              - Get an argument for this op
   1063  1.1  jruoho  *              Argn            - Nth argument to get
   1064  1.1  jruoho  *
   1065  1.1  jruoho  * RETURN:      The argument (as an Op object).  NULL if argument does not exist
   1066  1.1  jruoho  *
   1067  1.1  jruoho  * DESCRIPTION: Get the specified op's argument (peer)
   1068  1.1  jruoho  *
   1069  1.1  jruoho  ******************************************************************************/
   1070  1.1  jruoho 
   1071  1.1  jruoho ACPI_PARSE_OBJECT *
   1072  1.1  jruoho UtGetArg (
   1073  1.1  jruoho     ACPI_PARSE_OBJECT       *Op,
   1074  1.1  jruoho     UINT32                  Argn)
   1075  1.1  jruoho {
   1076  1.1  jruoho     ACPI_PARSE_OBJECT       *Arg = NULL;
   1077  1.1  jruoho 
   1078  1.1  jruoho 
   1079  1.1  jruoho     /* Get the requested argument object */
   1080  1.1  jruoho 
   1081  1.1  jruoho     Arg = Op->Asl.Child;
   1082  1.1  jruoho     while (Arg && Argn)
   1083  1.1  jruoho     {
   1084  1.1  jruoho         Argn--;
   1085  1.1  jruoho         Arg = Arg->Asl.Next;
   1086  1.1  jruoho     }
   1087  1.1  jruoho 
   1088  1.1  jruoho     return (Arg);
   1089  1.1  jruoho }
   1090  1.1  jruoho 
   1091  1.1  jruoho 
   1092  1.1  jruoho /*******************************************************************************
   1093  1.1  jruoho  *
   1094  1.1  jruoho  * FUNCTION:    OpnAttachNameToNode
   1095  1.1  jruoho  *
   1096  1.1  jruoho  * PARAMETERS:  Op        - The parent parse node
   1097  1.1  jruoho  *
   1098  1.1  jruoho  * RETURN:      None
   1099  1.1  jruoho  *
   1100  1.1  jruoho  * DESCRIPTION: For the named ASL/AML operators, get the actual name from the
   1101  1.1  jruoho  *              argument list and attach it to the parent node so that we
   1102  1.1  jruoho  *              can get to it quickly later.
   1103  1.1  jruoho  *
   1104  1.1  jruoho  ******************************************************************************/
   1105  1.1  jruoho 
   1106  1.1  jruoho static void
   1107  1.1  jruoho OpnAttachNameToNode (
   1108  1.1  jruoho     ACPI_PARSE_OBJECT       *Op)
   1109  1.1  jruoho {
   1110  1.1  jruoho     ACPI_PARSE_OBJECT       *Child = NULL;
   1111  1.1  jruoho 
   1112  1.1  jruoho 
   1113  1.1  jruoho     if (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL)
   1114  1.1  jruoho     {
   1115  1.1  jruoho         Child = UtGetArg (Op, 0);
   1116  1.1  jruoho     }
   1117  1.1  jruoho     else switch (Op->Asl.AmlOpcode)
   1118  1.1  jruoho     {
   1119  1.1  jruoho     case AML_DATA_REGION_OP:
   1120  1.1  jruoho     case AML_DEVICE_OP:
   1121  1.1  jruoho     case AML_EVENT_OP:
   1122  1.1  jruoho     case AML_METHOD_OP:
   1123  1.1  jruoho     case AML_MUTEX_OP:
   1124  1.1  jruoho     case AML_REGION_OP:
   1125  1.1  jruoho     case AML_POWER_RES_OP:
   1126  1.1  jruoho     case AML_PROCESSOR_OP:
   1127  1.1  jruoho     case AML_THERMAL_ZONE_OP:
   1128  1.1  jruoho     case AML_NAME_OP:
   1129  1.1  jruoho     case AML_SCOPE_OP:
   1130  1.1  jruoho 
   1131  1.1  jruoho         Child = UtGetArg (Op, 0);
   1132  1.1  jruoho         break;
   1133  1.1  jruoho 
   1134  1.1  jruoho     case AML_ALIAS_OP:
   1135  1.1  jruoho 
   1136  1.1  jruoho         Child = UtGetArg (Op, 1);
   1137  1.1  jruoho         break;
   1138  1.1  jruoho 
   1139  1.1  jruoho     case AML_CREATE_BIT_FIELD_OP:
   1140  1.1  jruoho     case AML_CREATE_BYTE_FIELD_OP:
   1141  1.1  jruoho     case AML_CREATE_WORD_FIELD_OP:
   1142  1.1  jruoho     case AML_CREATE_DWORD_FIELD_OP:
   1143  1.1  jruoho     case AML_CREATE_QWORD_FIELD_OP:
   1144  1.1  jruoho 
   1145  1.1  jruoho         Child = UtGetArg (Op, 2);
   1146  1.1  jruoho         break;
   1147  1.1  jruoho 
   1148  1.1  jruoho     case AML_CREATE_FIELD_OP:
   1149  1.1  jruoho 
   1150  1.1  jruoho         Child = UtGetArg (Op, 3);
   1151  1.1  jruoho         break;
   1152  1.1  jruoho 
   1153  1.1  jruoho     case AML_BANK_FIELD_OP:
   1154  1.1  jruoho     case AML_INDEX_FIELD_OP:
   1155  1.1  jruoho     case AML_FIELD_OP:
   1156  1.1  jruoho 
   1157  1.1  jruoho         return;
   1158  1.1  jruoho 
   1159  1.1  jruoho     default:
   1160  1.1  jruoho         return;
   1161  1.1  jruoho     }
   1162  1.1  jruoho 
   1163  1.1  jruoho     if (Child)
   1164  1.1  jruoho     {
   1165  1.1  jruoho         UtAttachNamepathToOwner (Op, Child);
   1166  1.1  jruoho     }
   1167  1.1  jruoho }
   1168  1.1  jruoho 
   1169  1.1  jruoho 
   1170  1.1  jruoho /*******************************************************************************
   1171  1.1  jruoho  *
   1172  1.1  jruoho  * FUNCTION:    OpnGenerateAmlOperands
   1173  1.1  jruoho  *
   1174  1.1  jruoho  * PARAMETERS:  Op        - The parent parse node
   1175  1.1  jruoho  *
   1176  1.1  jruoho  * RETURN:      None
   1177  1.1  jruoho  *
   1178  1.1  jruoho  * DESCRIPTION: Prepare nodes to be output as AML data and operands.  The more
   1179  1.1  jruoho  *              complex AML opcodes require processing of the child nodes
   1180  1.1  jruoho  *              (arguments/operands).
   1181  1.1  jruoho  *
   1182  1.1  jruoho  ******************************************************************************/
   1183  1.1  jruoho 
   1184  1.1  jruoho void
   1185  1.1  jruoho OpnGenerateAmlOperands (
   1186  1.1  jruoho     ACPI_PARSE_OBJECT       *Op)
   1187  1.1  jruoho {
   1188  1.1  jruoho 
   1189  1.1  jruoho 
   1190  1.1  jruoho     if (Op->Asl.AmlOpcode == AML_RAW_DATA_BYTE)
   1191  1.1  jruoho     {
   1192  1.1  jruoho         return;
   1193  1.1  jruoho     }
   1194  1.1  jruoho 
   1195  1.1  jruoho     switch (Op->Asl.ParseOpcode)
   1196  1.1  jruoho     {
   1197  1.1  jruoho     case PARSEOP_DEFINITIONBLOCK:
   1198  1.1  jruoho         OpnDoDefinitionBlock (Op);
   1199  1.1  jruoho         break;
   1200  1.1  jruoho 
   1201  1.1  jruoho     case PARSEOP_METHOD:
   1202  1.1  jruoho         OpnDoMethod (Op);
   1203  1.1  jruoho         break;
   1204  1.1  jruoho 
   1205  1.1  jruoho     case PARSEOP_MUTEX:
   1206  1.1  jruoho         OpnDoMutex (Op);
   1207  1.1  jruoho         break;
   1208  1.1  jruoho 
   1209  1.1  jruoho     case PARSEOP_FIELD:
   1210  1.1  jruoho         OpnDoField (Op);
   1211  1.1  jruoho         break;
   1212  1.1  jruoho 
   1213  1.1  jruoho     case PARSEOP_INDEXFIELD:
   1214  1.1  jruoho         OpnDoIndexField (Op);
   1215  1.1  jruoho         break;
   1216  1.1  jruoho 
   1217  1.1  jruoho     case PARSEOP_BANKFIELD:
   1218  1.1  jruoho         OpnDoBankField (Op);
   1219  1.1  jruoho         break;
   1220  1.1  jruoho 
   1221  1.1  jruoho     case PARSEOP_BUFFER:
   1222  1.1  jruoho         OpnDoBuffer (Op);
   1223  1.1  jruoho         break;
   1224  1.1  jruoho 
   1225  1.1  jruoho     case PARSEOP_LOADTABLE:
   1226  1.1  jruoho         OpnDoLoadTable (Op);
   1227  1.1  jruoho         break;
   1228  1.1  jruoho 
   1229  1.1  jruoho     case PARSEOP_OPERATIONREGION:
   1230  1.1  jruoho         OpnDoRegion (Op);
   1231  1.1  jruoho         break;
   1232  1.1  jruoho 
   1233  1.1  jruoho     case PARSEOP_RESOURCETEMPLATE:
   1234  1.1  jruoho         RsDoResourceTemplate (Op);
   1235  1.1  jruoho         break;
   1236  1.1  jruoho 
   1237  1.1  jruoho     case PARSEOP_NAMESEG:
   1238  1.1  jruoho     case PARSEOP_NAMESTRING:
   1239  1.1  jruoho     case PARSEOP_METHODCALL:
   1240  1.1  jruoho     case PARSEOP_STRING_LITERAL:
   1241  1.1  jruoho         break;
   1242  1.1  jruoho 
   1243  1.1  jruoho     default:
   1244  1.1  jruoho         break;
   1245  1.1  jruoho     }
   1246  1.1  jruoho 
   1247  1.1  jruoho     /* TBD: move */
   1248  1.1  jruoho 
   1249  1.1  jruoho     OpnAttachNameToNode (Op);
   1250  1.1  jruoho }
   1251  1.1  jruoho 
   1252  1.1  jruoho 
   1253