Home | History | Annotate | Line # | Download | only in compiler
asltree.c revision 1.1.1.19
      1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3  1.1.1.10  christos  * Module Name: asltree - Parse tree management
      4       1.1    jruoho  *
      5       1.1    jruoho  *****************************************************************************/
      6       1.1    jruoho 
      7  1.1.1.18  christos /******************************************************************************
      8  1.1.1.18  christos  *
      9  1.1.1.18  christos  * 1. Copyright Notice
     10  1.1.1.18  christos  *
     11  1.1.1.19  christos  * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.
     12       1.1    jruoho  * All rights reserved.
     13       1.1    jruoho  *
     14  1.1.1.18  christos  * 2. License
     15  1.1.1.18  christos  *
     16  1.1.1.18  christos  * 2.1. This is your license from Intel Corp. under its intellectual property
     17  1.1.1.18  christos  * rights. You may have additional license terms from the party that provided
     18  1.1.1.18  christos  * you this software, covering your right to use that party's intellectual
     19  1.1.1.18  christos  * property rights.
     20  1.1.1.18  christos  *
     21  1.1.1.18  christos  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     22  1.1.1.18  christos  * copy of the source code appearing in this file ("Covered Code") an
     23  1.1.1.18  christos  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     24  1.1.1.18  christos  * base code distributed originally by Intel ("Original Intel Code") to copy,
     25  1.1.1.18  christos  * make derivatives, distribute, use and display any portion of the Covered
     26  1.1.1.18  christos  * Code in any form, with the right to sublicense such rights; and
     27  1.1.1.18  christos  *
     28  1.1.1.18  christos  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     29  1.1.1.18  christos  * license (with the right to sublicense), under only those claims of Intel
     30  1.1.1.18  christos  * patents that are infringed by the Original Intel Code, to make, use, sell,
     31  1.1.1.18  christos  * offer to sell, and import the Covered Code and derivative works thereof
     32  1.1.1.18  christos  * solely to the minimum extent necessary to exercise the above copyright
     33  1.1.1.18  christos  * license, and in no event shall the patent license extend to any additions
     34  1.1.1.18  christos  * to or modifications of the Original Intel Code. No other license or right
     35  1.1.1.18  christos  * is granted directly or by implication, estoppel or otherwise;
     36  1.1.1.18  christos  *
     37  1.1.1.18  christos  * The above copyright and patent license is granted only if the following
     38  1.1.1.18  christos  * conditions are met:
     39  1.1.1.18  christos  *
     40  1.1.1.18  christos  * 3. Conditions
     41  1.1.1.18  christos  *
     42  1.1.1.18  christos  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     43  1.1.1.18  christos  * Redistribution of source code of any substantial portion of the Covered
     44  1.1.1.18  christos  * Code or modification with rights to further distribute source must include
     45  1.1.1.18  christos  * the above Copyright Notice, the above License, this list of Conditions,
     46  1.1.1.18  christos  * and the following Disclaimer and Export Compliance provision. In addition,
     47  1.1.1.18  christos  * Licensee must cause all Covered Code to which Licensee contributes to
     48  1.1.1.18  christos  * contain a file documenting the changes Licensee made to create that Covered
     49  1.1.1.18  christos  * Code and the date of any change. Licensee must include in that file the
     50  1.1.1.18  christos  * documentation of any changes made by any predecessor Licensee. Licensee
     51  1.1.1.18  christos  * must include a prominent statement that the modification is derived,
     52  1.1.1.18  christos  * directly or indirectly, from Original Intel Code.
     53  1.1.1.18  christos  *
     54  1.1.1.18  christos  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     55  1.1.1.18  christos  * Redistribution of source code of any substantial portion of the Covered
     56  1.1.1.18  christos  * Code or modification without rights to further distribute source must
     57  1.1.1.18  christos  * include the following Disclaimer and Export Compliance provision in the
     58  1.1.1.18  christos  * documentation and/or other materials provided with distribution. In
     59  1.1.1.18  christos  * addition, Licensee may not authorize further sublicense of source of any
     60  1.1.1.18  christos  * portion of the Covered Code, and must include terms to the effect that the
     61  1.1.1.18  christos  * license from Licensee to its licensee is limited to the intellectual
     62  1.1.1.18  christos  * property embodied in the software Licensee provides to its licensee, and
     63  1.1.1.18  christos  * not to intellectual property embodied in modifications its licensee may
     64  1.1.1.18  christos  * make.
     65  1.1.1.18  christos  *
     66  1.1.1.18  christos  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     67  1.1.1.18  christos  * substantial portion of the Covered Code or modification must reproduce the
     68  1.1.1.18  christos  * above Copyright Notice, and the following Disclaimer and Export Compliance
     69  1.1.1.18  christos  * provision in the documentation and/or other materials provided with the
     70  1.1.1.18  christos  * distribution.
     71  1.1.1.18  christos  *
     72  1.1.1.18  christos  * 3.4. Intel retains all right, title, and interest in and to the Original
     73  1.1.1.18  christos  * Intel Code.
     74  1.1.1.18  christos  *
     75  1.1.1.18  christos  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     76  1.1.1.18  christos  * Intel shall be used in advertising or otherwise to promote the sale, use or
     77  1.1.1.18  christos  * other dealings in products derived from or relating to the Covered Code
     78  1.1.1.18  christos  * without prior written authorization from Intel.
     79  1.1.1.18  christos  *
     80  1.1.1.18  christos  * 4. Disclaimer and Export Compliance
     81  1.1.1.18  christos  *
     82  1.1.1.18  christos  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     83  1.1.1.18  christos  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     84  1.1.1.18  christos  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
     85  1.1.1.18  christos  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
     86  1.1.1.18  christos  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
     87  1.1.1.18  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     88  1.1.1.18  christos  * PARTICULAR PURPOSE.
     89  1.1.1.18  christos  *
     90  1.1.1.18  christos  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     91  1.1.1.18  christos  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     92  1.1.1.18  christos  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     93  1.1.1.18  christos  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     94  1.1.1.18  christos  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     95  1.1.1.18  christos  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
     96  1.1.1.18  christos  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     97  1.1.1.18  christos  * LIMITED REMEDY.
     98  1.1.1.18  christos  *
     99  1.1.1.18  christos  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    100  1.1.1.18  christos  * software or system incorporating such software without first obtaining any
    101  1.1.1.18  christos  * required license or other approval from the U. S. Department of Commerce or
    102  1.1.1.18  christos  * any other agency or department of the United States Government. In the
    103  1.1.1.18  christos  * event Licensee exports any such software from the United States or
    104  1.1.1.18  christos  * re-exports any such software from a foreign destination, Licensee shall
    105  1.1.1.18  christos  * ensure that the distribution and export/re-export of the software is in
    106  1.1.1.18  christos  * compliance with all laws, regulations, orders, or other restrictions of the
    107  1.1.1.18  christos  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    108  1.1.1.18  christos  * any of its subsidiaries will export/re-export any technical data, process,
    109  1.1.1.18  christos  * software, or service, directly or indirectly, to any country for which the
    110  1.1.1.18  christos  * United States government or any agency thereof requires an export license,
    111  1.1.1.18  christos  * other governmental approval, or letter of assurance, without first obtaining
    112  1.1.1.18  christos  * such license, approval or letter.
    113  1.1.1.18  christos  *
    114  1.1.1.18  christos  *****************************************************************************
    115  1.1.1.18  christos  *
    116  1.1.1.18  christos  * Alternatively, you may choose to be licensed under the terms of the
    117  1.1.1.18  christos  * following license:
    118  1.1.1.18  christos  *
    119   1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
    120   1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
    121   1.1.1.2    jruoho  * are met:
    122   1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
    123   1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
    124   1.1.1.2    jruoho  *    without modification.
    125   1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
    126   1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
    127   1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
    128   1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
    129   1.1.1.2    jruoho  *    binary redistribution.
    130   1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
    131   1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
    132   1.1.1.2    jruoho  *    from this software without specific prior written permission.
    133   1.1.1.2    jruoho  *
    134   1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    135   1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    136  1.1.1.15  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    137   1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    138  1.1.1.18  christos  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    139  1.1.1.18  christos  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    140  1.1.1.18  christos  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    141  1.1.1.18  christos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    142  1.1.1.18  christos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    143  1.1.1.18  christos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    144  1.1.1.18  christos  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    145  1.1.1.18  christos  *
    146  1.1.1.18  christos  * Alternatively, you may choose to be licensed under the terms of the
    147  1.1.1.18  christos  * GNU General Public License ("GPL") version 2 as published by the Free
    148  1.1.1.18  christos  * Software Foundation.
    149  1.1.1.18  christos  *
    150  1.1.1.18  christos  *****************************************************************************/
    151       1.1    jruoho 
    152       1.1    jruoho #include "aslcompiler.h"
    153       1.1    jruoho #include "aslcompiler.y.h"
    154   1.1.1.3  christos #include "acapps.h"
    155       1.1    jruoho 
    156       1.1    jruoho #define _COMPONENT          ACPI_COMPILER
    157       1.1    jruoho         ACPI_MODULE_NAME    ("asltree")
    158       1.1    jruoho 
    159   1.1.1.7  christos 
    160   1.1.1.7  christos /*******************************************************************************
    161   1.1.1.7  christos  *
    162  1.1.1.10  christos  * FUNCTION:    TrSetOpIntegerValue
    163       1.1    jruoho  *
    164  1.1.1.10  christos  * PARAMETERS:  ParseOpcode         - New opcode to be assigned to the op
    165  1.1.1.10  christos  *              Op                  - An existing parse op
    166       1.1    jruoho  *
    167  1.1.1.10  christos  * RETURN:      The updated op
    168       1.1    jruoho  *
    169  1.1.1.10  christos  * DESCRIPTION: Used to set the integer value of a op,
    170  1.1.1.10  christos  *              usually to a specific size (8, 16, 32, or 64 bits)
    171       1.1    jruoho  *
    172       1.1    jruoho  ******************************************************************************/
    173       1.1    jruoho 
    174       1.1    jruoho ACPI_PARSE_OBJECT *
    175  1.1.1.10  christos TrSetOpIntegerValue (
    176       1.1    jruoho     UINT32                  ParseOpcode,
    177       1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    178       1.1    jruoho {
    179       1.1    jruoho 
    180       1.1    jruoho     if (!Op)
    181       1.1    jruoho     {
    182   1.1.1.3  christos         return (NULL);
    183       1.1    jruoho     }
    184       1.1    jruoho 
    185       1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT,
    186  1.1.1.10  christos         "\nUpdateOp: Old - %s, New - %s\n",
    187       1.1    jruoho         UtGetOpName (Op->Asl.ParseOpcode),
    188       1.1    jruoho         UtGetOpName (ParseOpcode));
    189       1.1    jruoho 
    190       1.1    jruoho     /* Assign new opcode and name */
    191       1.1    jruoho 
    192       1.1    jruoho     if (Op->Asl.ParseOpcode == PARSEOP_ONES)
    193       1.1    jruoho     {
    194       1.1    jruoho         switch (ParseOpcode)
    195       1.1    jruoho         {
    196       1.1    jruoho         case PARSEOP_BYTECONST:
    197   1.1.1.3  christos 
    198   1.1.1.3  christos             Op->Asl.Value.Integer = ACPI_UINT8_MAX;
    199       1.1    jruoho             break;
    200       1.1    jruoho 
    201       1.1    jruoho         case PARSEOP_WORDCONST:
    202   1.1.1.3  christos 
    203   1.1.1.3  christos             Op->Asl.Value.Integer = ACPI_UINT16_MAX;
    204       1.1    jruoho             break;
    205       1.1    jruoho 
    206       1.1    jruoho         case PARSEOP_DWORDCONST:
    207   1.1.1.3  christos 
    208   1.1.1.3  christos             Op->Asl.Value.Integer = ACPI_UINT32_MAX;
    209       1.1    jruoho             break;
    210       1.1    jruoho 
    211   1.1.1.3  christos         /* Don't need to do the QWORD case */
    212   1.1.1.3  christos 
    213       1.1    jruoho         default:
    214   1.1.1.3  christos 
    215   1.1.1.3  christos             /* Don't care about others */
    216       1.1    jruoho             break;
    217       1.1    jruoho         }
    218       1.1    jruoho     }
    219       1.1    jruoho 
    220       1.1    jruoho     Op->Asl.ParseOpcode = (UINT16) ParseOpcode;
    221       1.1    jruoho     UtSetParseOpName (Op);
    222       1.1    jruoho 
    223       1.1    jruoho     /*
    224       1.1    jruoho      * For the BYTE, WORD, and DWORD constants, make sure that the integer
    225       1.1    jruoho      * that was passed in will actually fit into the data type
    226       1.1    jruoho      */
    227       1.1    jruoho     switch (ParseOpcode)
    228       1.1    jruoho     {
    229       1.1    jruoho     case PARSEOP_BYTECONST:
    230   1.1.1.3  christos 
    231   1.1.1.3  christos         UtCheckIntegerRange (Op, 0x00, ACPI_UINT8_MAX);
    232   1.1.1.3  christos         Op->Asl.Value.Integer &= ACPI_UINT8_MAX;
    233       1.1    jruoho         break;
    234       1.1    jruoho 
    235       1.1    jruoho     case PARSEOP_WORDCONST:
    236   1.1.1.3  christos 
    237   1.1.1.3  christos         UtCheckIntegerRange (Op, 0x00, ACPI_UINT16_MAX);
    238   1.1.1.3  christos         Op->Asl.Value.Integer &= ACPI_UINT16_MAX;
    239       1.1    jruoho         break;
    240       1.1    jruoho 
    241  1.1.1.10  christos     case PARSEOP_DWORDCONST:
    242   1.1.1.5  christos 
    243  1.1.1.10  christos         UtCheckIntegerRange (Op, 0x00, ACPI_UINT32_MAX);
    244  1.1.1.10  christos         Op->Asl.Value.Integer &= ACPI_UINT32_MAX;
    245  1.1.1.10  christos         break;
    246   1.1.1.5  christos 
    247  1.1.1.10  christos     default:
    248   1.1.1.5  christos 
    249  1.1.1.10  christos         /* Don't care about others, don't need to check QWORD */
    250   1.1.1.5  christos 
    251  1.1.1.10  christos         break;
    252  1.1.1.10  christos     }
    253   1.1.1.5  christos 
    254  1.1.1.10  christos     /* Converter: if this is a method invocation, turn off capture comments */
    255   1.1.1.5  christos 
    256  1.1.1.11  christos     if (AcpiGbl_CaptureComments &&
    257  1.1.1.10  christos         (ParseOpcode == PARSEOP_METHODCALL))
    258  1.1.1.10  christos     {
    259  1.1.1.12  christos         AslGbl_CommentState.CaptureComments = FALSE;
    260  1.1.1.10  christos     }
    261   1.1.1.5  christos 
    262  1.1.1.10  christos     return (Op);
    263   1.1.1.5  christos }
    264   1.1.1.5  christos 
    265   1.1.1.5  christos 
    266   1.1.1.5  christos /*******************************************************************************
    267   1.1.1.5  christos  *
    268  1.1.1.10  christos  * FUNCTION:    TrSetOpFlags
    269       1.1    jruoho  *
    270  1.1.1.10  christos  * PARAMETERS:  Op                  - An existing parse op
    271  1.1.1.10  christos  *              Flags               - New flags word
    272       1.1    jruoho  *
    273  1.1.1.10  christos  * RETURN:      The updated parser op
    274       1.1    jruoho  *
    275  1.1.1.10  christos  * DESCRIPTION: Set bits in the op flags word. Will not clear bits, only set
    276       1.1    jruoho  *
    277       1.1    jruoho  ******************************************************************************/
    278       1.1    jruoho 
    279       1.1    jruoho ACPI_PARSE_OBJECT *
    280  1.1.1.10  christos TrSetOpFlags (
    281  1.1.1.10  christos     ACPI_PARSE_OBJECT       *Op,
    282  1.1.1.10  christos     UINT32                  Flags)
    283       1.1    jruoho {
    284       1.1    jruoho 
    285  1.1.1.10  christos     if (!Op)
    286  1.1.1.10  christos     {
    287  1.1.1.10  christos         return (NULL);
    288  1.1.1.10  christos     }
    289       1.1    jruoho 
    290       1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT,
    291  1.1.1.10  christos         "\nSetOpFlags: %s Op %p, %8.8X", Op->Asl.ParseOpName, Op, Flags);
    292  1.1.1.10  christos 
    293  1.1.1.10  christos     TrPrintOpFlags (Flags, ASL_PARSE_OUTPUT);
    294  1.1.1.10  christos     DbgPrint (ASL_PARSE_OUTPUT, "\n\n");
    295   1.1.1.5  christos 
    296  1.1.1.10  christos     Op->Asl.CompileFlags |= Flags;
    297   1.1.1.5  christos     return (Op);
    298   1.1.1.5  christos }
    299   1.1.1.5  christos 
    300   1.1.1.5  christos 
    301   1.1.1.5  christos /*******************************************************************************
    302   1.1.1.5  christos  *
    303  1.1.1.10  christos  * FUNCTION:    TrSetOpAmlLength
    304   1.1.1.5  christos  *
    305  1.1.1.10  christos  * PARAMETERS:  Op                  - An existing parse op
    306  1.1.1.10  christos  *              Length              - AML Length
    307   1.1.1.5  christos  *
    308  1.1.1.10  christos  * RETURN:      The updated parser op
    309   1.1.1.5  christos  *
    310  1.1.1.10  christos  * DESCRIPTION: Set the AML Length in a op. Used by the parser to indicate
    311  1.1.1.10  christos  *              the presence of a op that must be reduced to a fixed length
    312  1.1.1.10  christos  *              constant.
    313   1.1.1.5  christos  *
    314   1.1.1.5  christos  ******************************************************************************/
    315   1.1.1.5  christos 
    316   1.1.1.5  christos ACPI_PARSE_OBJECT *
    317  1.1.1.10  christos TrSetOpAmlLength (
    318  1.1.1.10  christos     ACPI_PARSE_OBJECT       *Op,
    319  1.1.1.10  christos     UINT32                  Length)
    320   1.1.1.5  christos {
    321   1.1.1.5  christos 
    322   1.1.1.5  christos     DbgPrint (ASL_PARSE_OUTPUT,
    323  1.1.1.10  christos         "\nSetOpAmlLength: Op %p, %8.8X\n", Op, Length);
    324  1.1.1.10  christos 
    325  1.1.1.10  christos     if (!Op)
    326  1.1.1.10  christos     {
    327  1.1.1.10  christos         return (NULL);
    328  1.1.1.10  christos     }
    329       1.1    jruoho 
    330  1.1.1.10  christos     Op->Asl.AmlLength = Length;
    331   1.1.1.3  christos     return (Op);
    332       1.1    jruoho }
    333       1.1    jruoho 
    334       1.1    jruoho 
    335       1.1    jruoho /*******************************************************************************
    336       1.1    jruoho  *
    337  1.1.1.10  christos  * FUNCTION:    TrSetOpParent
    338   1.1.1.2    jruoho  *
    339  1.1.1.10  christos  * PARAMETERS:  Op                  - To be set to new parent
    340  1.1.1.10  christos  *              ParentOp            - The parent
    341   1.1.1.2    jruoho  *
    342  1.1.1.10  christos  * RETURN:      None, sets Op parent directly
    343   1.1.1.2    jruoho  *
    344  1.1.1.10  christos  * DESCRIPTION: Change the parent of a parse op.
    345   1.1.1.2    jruoho  *
    346   1.1.1.2    jruoho  ******************************************************************************/
    347   1.1.1.2    jruoho 
    348  1.1.1.10  christos void
    349  1.1.1.10  christos TrSetOpParent (
    350  1.1.1.10  christos     ACPI_PARSE_OBJECT       *Op,
    351  1.1.1.10  christos     ACPI_PARSE_OBJECT       *ParentOp)
    352   1.1.1.2    jruoho {
    353   1.1.1.3  christos 
    354  1.1.1.10  christos     Op->Asl.Parent = ParentOp;
    355   1.1.1.2    jruoho }
    356   1.1.1.2    jruoho 
    357   1.1.1.2    jruoho 
    358   1.1.1.2    jruoho /*******************************************************************************
    359   1.1.1.2    jruoho  *
    360  1.1.1.10  christos  * FUNCTION:    TrSetOpCurrentFilename
    361   1.1.1.5  christos  *
    362  1.1.1.10  christos  * PARAMETERS:  Op                  - An existing parse op
    363   1.1.1.5  christos  *
    364  1.1.1.10  christos  * RETURN:      None
    365   1.1.1.5  christos  *
    366  1.1.1.10  christos  * DESCRIPTION: Save the include file filename. Used for debug output only.
    367   1.1.1.5  christos  *
    368   1.1.1.5  christos  ******************************************************************************/
    369   1.1.1.5  christos 
    370  1.1.1.10  christos void
    371  1.1.1.10  christos TrSetOpCurrentFilename (
    372  1.1.1.10  christos     ACPI_PARSE_OBJECT       *Op)
    373   1.1.1.5  christos {
    374   1.1.1.5  christos 
    375  1.1.1.12  christos     Op->Asl.Filename = AslGbl_PreviousIncludeFilename;
    376   1.1.1.5  christos }
    377   1.1.1.5  christos 
    378   1.1.1.5  christos 
    379   1.1.1.5  christos /*******************************************************************************
    380   1.1.1.5  christos  *
    381  1.1.1.10  christos  * FUNCTION:    TrSetOpIntegerWidth
    382       1.1    jruoho  *
    383  1.1.1.10  christos  * PARAMETERS:  Op                  - An existing parse op
    384       1.1    jruoho  *
    385  1.1.1.10  christos  * RETURN:      None
    386       1.1    jruoho  *
    387  1.1.1.10  christos  * DESCRIPTION:
    388       1.1    jruoho  *
    389       1.1    jruoho  ******************************************************************************/
    390       1.1    jruoho 
    391  1.1.1.10  christos void
    392  1.1.1.10  christos TrSetOpIntegerWidth (
    393  1.1.1.10  christos     ACPI_PARSE_OBJECT       *TableSignatureOp,
    394  1.1.1.10  christos     ACPI_PARSE_OBJECT       *RevisionOp)
    395       1.1    jruoho {
    396       1.1    jruoho 
    397  1.1.1.10  christos     /* TBD: Check table sig? (DSDT vs. SSDT) */
    398       1.1    jruoho 
    399  1.1.1.10  christos     /* Handle command-line version override */
    400       1.1    jruoho 
    401  1.1.1.12  christos     if (AslGbl_RevisionOverride)
    402       1.1    jruoho     {
    403  1.1.1.12  christos         AcpiUtSetIntegerWidth (AslGbl_RevisionOverride);
    404  1.1.1.10  christos     }
    405  1.1.1.10  christos     else
    406  1.1.1.10  christos     {
    407  1.1.1.10  christos         AcpiUtSetIntegerWidth ((UINT8) RevisionOp->Asl.Value.Integer);
    408       1.1    jruoho     }
    409       1.1    jruoho }
    410       1.1    jruoho 
    411       1.1    jruoho 
    412       1.1    jruoho /*******************************************************************************
    413       1.1    jruoho  *
    414  1.1.1.10  christos  * FUNCTION:    TrSetOpEndLineNumber
    415       1.1    jruoho  *
    416  1.1.1.10  christos  * PARAMETERS:  Op                - An existing parse op
    417       1.1    jruoho  *
    418  1.1.1.10  christos  * RETURN:      None.
    419       1.1    jruoho  *
    420  1.1.1.10  christos  * DESCRIPTION: Set the ending line numbers (file line and logical line) of a
    421  1.1.1.10  christos  *              parse op to the current line numbers.
    422       1.1    jruoho  *
    423       1.1    jruoho  ******************************************************************************/
    424       1.1    jruoho 
    425  1.1.1.10  christos void
    426  1.1.1.10  christos TrSetOpEndLineNumber (
    427  1.1.1.10  christos     ACPI_PARSE_OBJECT       *Op)
    428       1.1    jruoho {
    429       1.1    jruoho 
    430  1.1.1.10  christos     /* If the end line # is already set, just return */
    431       1.1    jruoho 
    432  1.1.1.10  christos     if (Op->Asl.EndLine)
    433       1.1    jruoho     {
    434  1.1.1.10  christos         return;
    435       1.1    jruoho     }
    436       1.1    jruoho 
    437  1.1.1.12  christos     Op->Asl.EndLine = AslGbl_CurrentLineNumber;
    438  1.1.1.12  christos     Op->Asl.EndLogicalLine = AslGbl_LogicalLineNumber;
    439       1.1    jruoho }
    440       1.1    jruoho 
    441       1.1    jruoho 
    442       1.1    jruoho /*******************************************************************************
    443       1.1    jruoho  *
    444  1.1.1.10  christos  * FUNCTION:    TrLinkOpChildren
    445       1.1    jruoho  *
    446  1.1.1.10  christos  * PARAMETERS:  Op                - An existing parse op
    447   1.1.1.9  christos  *              NumChildren        - Number of children to follow
    448  1.1.1.10  christos  *              ...                - A list of child ops to link to the new
    449  1.1.1.10  christos  *                                   op. NumChildren long.
    450       1.1    jruoho  *
    451  1.1.1.10  christos  * RETURN:      The updated (linked) op
    452       1.1    jruoho  *
    453  1.1.1.10  christos  * DESCRIPTION: Link a group of ops to an existing parse op
    454       1.1    jruoho  *
    455       1.1    jruoho  ******************************************************************************/
    456       1.1    jruoho 
    457       1.1    jruoho ACPI_PARSE_OBJECT *
    458  1.1.1.10  christos TrLinkOpChildren (
    459       1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
    460       1.1    jruoho     UINT32                  NumChildren,
    461       1.1    jruoho     ...)
    462       1.1    jruoho {
    463       1.1    jruoho     ACPI_PARSE_OBJECT       *Child;
    464       1.1    jruoho     ACPI_PARSE_OBJECT       *PrevChild;
    465  1.1.1.13  christos     ACPI_PARSE_OBJECT       *LastSibling;
    466       1.1    jruoho     va_list                 ap;
    467       1.1    jruoho     UINT32                  i;
    468       1.1    jruoho     BOOLEAN                 FirstChild;
    469       1.1    jruoho 
    470  1.1.1.17  christos     ACPI_FUNCTION_NAME (TrLinkOpChildren);
    471       1.1    jruoho 
    472       1.1    jruoho     va_start (ap, NumChildren);
    473       1.1    jruoho 
    474  1.1.1.10  christos     TrSetOpEndLineNumber (Op);
    475       1.1    jruoho 
    476       1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT,
    477       1.1    jruoho         "\nLinkChildren  Line [%u to %u] NewParent %p Child %u Op %s  ",
    478       1.1    jruoho         Op->Asl.LineNumber, Op->Asl.EndLine,
    479       1.1    jruoho         Op, NumChildren, UtGetOpName(Op->Asl.ParseOpcode));
    480       1.1    jruoho 
    481       1.1    jruoho     switch (Op->Asl.ParseOpcode)
    482       1.1    jruoho     {
    483   1.1.1.6  christos     case PARSEOP_ASL_CODE:
    484   1.1.1.3  christos 
    485  1.1.1.13  christos         if (!AslGbl_ParseTreeRoot)
    486  1.1.1.13  christos         {
    487  1.1.1.13  christos             DbgPrint (ASL_PARSE_OUTPUT, "Creating first Definition Block\n");
    488  1.1.1.13  christos             AslGbl_ParseTreeRoot = Op;
    489  1.1.1.13  christos             Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
    490  1.1.1.13  christos         }
    491  1.1.1.13  christos         else
    492  1.1.1.13  christos         {
    493  1.1.1.13  christos             DbgPrint (ASL_PARSE_OUTPUT, "Creating subsequent Definition Block\n");
    494  1.1.1.13  christos             Op = AslGbl_ParseTreeRoot;
    495  1.1.1.13  christos         }
    496  1.1.1.13  christos 
    497   1.1.1.6  christos         DbgPrint (ASL_PARSE_OUTPUT, "ASLCODE (Tree Completed)->");
    498   1.1.1.6  christos         break;
    499   1.1.1.6  christos 
    500   1.1.1.6  christos     case PARSEOP_DEFINITION_BLOCK:
    501   1.1.1.6  christos 
    502       1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "DEFINITION_BLOCK (Tree Completed)->");
    503       1.1    jruoho         break;
    504       1.1    jruoho 
    505       1.1    jruoho     case PARSEOP_OPERATIONREGION:
    506   1.1.1.3  christos 
    507       1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "OPREGION->");
    508       1.1    jruoho         break;
    509       1.1    jruoho 
    510       1.1    jruoho     case PARSEOP_OR:
    511   1.1.1.3  christos 
    512       1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "OR->");
    513       1.1    jruoho         break;
    514       1.1    jruoho 
    515       1.1    jruoho     default:
    516   1.1.1.3  christos 
    517       1.1    jruoho         /* Nothing to do for other opcodes */
    518   1.1.1.3  christos 
    519       1.1    jruoho         break;
    520       1.1    jruoho     }
    521       1.1    jruoho 
    522   1.1.1.9  christos     /* The following is for capturing comments */
    523   1.1.1.9  christos 
    524  1.1.1.11  christos     if (AcpiGbl_CaptureComments)
    525   1.1.1.9  christos     {
    526   1.1.1.9  christos         /*
    527   1.1.1.9  christos          * If there are "regular comments" detected at this point,
    528   1.1.1.9  christos          * then is an endBlk comment. Categorize it as so and distribute
    529  1.1.1.10  christos          * all regular comments to this parse op.
    530   1.1.1.9  christos          */
    531  1.1.1.12  christos         if (AslGbl_CommentListHead)
    532   1.1.1.9  christos         {
    533  1.1.1.12  christos             Op->Asl.EndBlkComment = AslGbl_CommentListHead;
    534   1.1.1.9  christos             CvDbgPrint ("EndBlk Comment for %s: %s",
    535  1.1.1.12  christos                 Op->Asl.ParseOpName, AslGbl_CommentListHead->Comment);
    536  1.1.1.12  christos             AslGbl_CommentListHead = NULL;
    537  1.1.1.12  christos             AslGbl_CommentListTail = NULL;
    538   1.1.1.9  christos         }
    539   1.1.1.9  christos     }
    540   1.1.1.9  christos 
    541  1.1.1.10  christos     /* Link the new op to it's children */
    542       1.1    jruoho 
    543       1.1    jruoho     PrevChild = NULL;
    544       1.1    jruoho     FirstChild = TRUE;
    545       1.1    jruoho     for (i = 0; i < NumChildren; i++)
    546       1.1    jruoho     {
    547       1.1    jruoho         Child = va_arg (ap, ACPI_PARSE_OBJECT *);
    548       1.1    jruoho 
    549       1.1    jruoho         if ((Child == PrevChild) && (Child != NULL))
    550       1.1    jruoho         {
    551       1.1    jruoho             AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Child,
    552  1.1.1.10  christos                 "Child op list invalid");
    553   1.1.1.3  christos             va_end(ap);
    554   1.1.1.3  christos             return (Op);
    555       1.1    jruoho         }
    556       1.1    jruoho 
    557       1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "%p, ", Child);
    558       1.1    jruoho 
    559       1.1    jruoho         /*
    560       1.1    jruoho          * If child is NULL, this means that an optional argument
    561   1.1.1.3  christos          * was omitted. We must create a placeholder with a special
    562       1.1    jruoho          * opcode (DEFAULT_ARG) so that the code generator will know
    563       1.1    jruoho          * that it must emit the correct default for this argument
    564       1.1    jruoho          */
    565       1.1    jruoho         if (!Child)
    566       1.1    jruoho         {
    567  1.1.1.10  christos             Child = TrAllocateOp (PARSEOP_DEFAULT_ARG);
    568       1.1    jruoho         }
    569       1.1    jruoho 
    570       1.1    jruoho         /* Link first child to parent */
    571       1.1    jruoho 
    572       1.1    jruoho         if (FirstChild)
    573       1.1    jruoho         {
    574       1.1    jruoho             FirstChild = FALSE;
    575  1.1.1.13  christos 
    576  1.1.1.13  christos             /*
    577  1.1.1.13  christos              * In the case that multiple definition blocks are being compiled,
    578  1.1.1.13  christos              * append the definition block to the end of the child list as the
    579  1.1.1.13  christos              * last sibling. This is done to facilitate namespace cross-
    580  1.1.1.13  christos              * reference between multiple definition blocks.
    581  1.1.1.13  christos              */
    582  1.1.1.13  christos             if (Op->Asl.Child &&
    583  1.1.1.13  christos                 (Op->Asl.Child->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK))
    584  1.1.1.13  christos             {
    585  1.1.1.13  christos                 LastSibling = Op->Asl.Child;
    586  1.1.1.13  christos                 while (LastSibling->Asl.Next)
    587  1.1.1.13  christos                 {
    588  1.1.1.13  christos                     LastSibling = LastSibling->Asl.Next;
    589  1.1.1.13  christos                 }
    590  1.1.1.13  christos                 LastSibling->Asl.Next = Child;
    591  1.1.1.13  christos             }
    592  1.1.1.13  christos             else
    593  1.1.1.13  christos             {
    594  1.1.1.13  christos                 Op->Asl.Child = Child;
    595  1.1.1.13  christos             }
    596       1.1    jruoho         }
    597       1.1    jruoho 
    598       1.1    jruoho         /* Point all children to parent */
    599       1.1    jruoho 
    600       1.1    jruoho         Child->Asl.Parent = Op;
    601       1.1    jruoho 
    602       1.1    jruoho         /* Link children in a peer list */
    603       1.1    jruoho 
    604       1.1    jruoho         if (PrevChild)
    605       1.1    jruoho         {
    606       1.1    jruoho             PrevChild->Asl.Next = Child;
    607  1.1.1.10  christos         }
    608       1.1    jruoho 
    609       1.1    jruoho         /*
    610  1.1.1.10  christos          * This child might be a list, point all ops in the list
    611       1.1    jruoho          * to the same parent
    612       1.1    jruoho          */
    613       1.1    jruoho         while (Child->Asl.Next)
    614       1.1    jruoho         {
    615       1.1    jruoho             Child = Child->Asl.Next;
    616       1.1    jruoho             Child->Asl.Parent = Op;
    617       1.1    jruoho         }
    618   1.1.1.6  christos 
    619       1.1    jruoho         PrevChild = Child;
    620       1.1    jruoho     }
    621       1.1    jruoho 
    622   1.1.1.3  christos     va_end(ap);
    623       1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT, "\n\n");
    624   1.1.1.9  christos 
    625  1.1.1.11  christos     if (AcpiGbl_CaptureComments)
    626   1.1.1.9  christos     {
    627  1.1.1.12  christos         AslGbl_CommentState.LatestParseOp = Op;
    628  1.1.1.17  christos         CvDbgPrint ("%s=====Set latest parse op to this op.\n",  ACPI_GET_FUNCTION_NAME);
    629   1.1.1.9  christos     }
    630  1.1.1.10  christos 
    631   1.1.1.3  christos     return (Op);
    632       1.1    jruoho }
    633       1.1    jruoho 
    634       1.1    jruoho 
    635       1.1    jruoho /*******************************************************************************
    636       1.1    jruoho  *
    637  1.1.1.10  christos  * FUNCTION:    TrLinkPeerOp
    638       1.1    jruoho  *
    639       1.1    jruoho  * PARAMETERS:  Op1           - First peer
    640       1.1    jruoho  *              Op2           - Second peer
    641       1.1    jruoho  *
    642  1.1.1.10  christos  * RETURN:      Op1 or the non-null op.
    643       1.1    jruoho  *
    644  1.1.1.10  christos  * DESCRIPTION: Link two ops as peers. Handles cases where one peer is null.
    645       1.1    jruoho  *
    646       1.1    jruoho  ******************************************************************************/
    647       1.1    jruoho 
    648       1.1    jruoho ACPI_PARSE_OBJECT *
    649  1.1.1.10  christos TrLinkPeerOp (
    650       1.1    jruoho     ACPI_PARSE_OBJECT       *Op1,
    651       1.1    jruoho     ACPI_PARSE_OBJECT       *Op2)
    652       1.1    jruoho {
    653       1.1    jruoho     ACPI_PARSE_OBJECT       *Next;
    654       1.1    jruoho 
    655       1.1    jruoho 
    656       1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT,
    657  1.1.1.10  christos         "\nLinkPeerOp: 1=%p (%s), 2=%p (%s)\n",
    658       1.1    jruoho         Op1, Op1 ? UtGetOpName(Op1->Asl.ParseOpcode) : NULL,
    659       1.1    jruoho         Op2, Op2 ? UtGetOpName(Op2->Asl.ParseOpcode) : NULL);
    660       1.1    jruoho 
    661       1.1    jruoho 
    662       1.1    jruoho     if ((!Op1) && (!Op2))
    663       1.1    jruoho     {
    664  1.1.1.10  christos         DbgPrint (ASL_PARSE_OUTPUT, "\nTwo Null ops!\n");
    665   1.1.1.3  christos         return (Op1);
    666       1.1    jruoho     }
    667       1.1    jruoho 
    668  1.1.1.10  christos     /* If one of the ops is null, just return the non-null op */
    669       1.1    jruoho 
    670       1.1    jruoho     if (!Op2)
    671       1.1    jruoho     {
    672   1.1.1.3  christos         return (Op1);
    673       1.1    jruoho     }
    674       1.1    jruoho 
    675       1.1    jruoho     if (!Op1)
    676       1.1    jruoho     {
    677   1.1.1.3  christos         return (Op2);
    678       1.1    jruoho     }
    679       1.1    jruoho 
    680       1.1    jruoho     if (Op1 == Op2)
    681       1.1    jruoho     {
    682       1.1    jruoho         DbgPrint (ASL_DEBUG_OUTPUT,
    683  1.1.1.10  christos             "\n************* Internal error, linking op to itself %p\n",
    684       1.1    jruoho             Op1);
    685       1.1    jruoho         AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op1,
    686  1.1.1.10  christos             "Linking op to itself");
    687   1.1.1.3  christos         return (Op1);
    688       1.1    jruoho     }
    689       1.1    jruoho 
    690       1.1    jruoho     Op1->Asl.Parent = Op2->Asl.Parent;
    691       1.1    jruoho 
    692       1.1    jruoho     /*
    693       1.1    jruoho      * Op 1 may already have a peer list (such as an IF/ELSE pair),
    694       1.1    jruoho      * so we must walk to the end of the list and attach the new
    695       1.1    jruoho      * peer at the end
    696       1.1    jruoho      */
    697       1.1    jruoho     Next = Op1;
    698       1.1    jruoho     while (Next->Asl.Next)
    699       1.1    jruoho     {
    700       1.1    jruoho         Next = Next->Asl.Next;
    701       1.1    jruoho     }
    702       1.1    jruoho 
    703       1.1    jruoho     Next->Asl.Next = Op2;
    704   1.1.1.3  christos     return (Op1);
    705       1.1    jruoho }
    706       1.1    jruoho 
    707       1.1    jruoho 
    708       1.1    jruoho /*******************************************************************************
    709       1.1    jruoho  *
    710  1.1.1.10  christos  * FUNCTION:    TrLinkPeerOps
    711       1.1    jruoho  *
    712  1.1.1.10  christos  * PARAMETERS:  NumPeers            - The number of ops in the list to follow
    713  1.1.1.10  christos  *              ...                 - A list of ops to link together as peers
    714       1.1    jruoho  *
    715  1.1.1.10  christos  * RETURN:      The first op in the list (head of the peer list)
    716       1.1    jruoho  *
    717  1.1.1.10  christos  * DESCRIPTION: Link together an arbitrary number of peer ops.
    718       1.1    jruoho  *
    719       1.1    jruoho  ******************************************************************************/
    720       1.1    jruoho 
    721       1.1    jruoho ACPI_PARSE_OBJECT *
    722  1.1.1.10  christos TrLinkPeerOps (
    723       1.1    jruoho     UINT32                  NumPeers,
    724       1.1    jruoho     ...)
    725       1.1    jruoho {
    726       1.1    jruoho     ACPI_PARSE_OBJECT       *This;
    727       1.1    jruoho     ACPI_PARSE_OBJECT       *Next;
    728       1.1    jruoho     va_list                 ap;
    729       1.1    jruoho     UINT32                  i;
    730       1.1    jruoho     ACPI_PARSE_OBJECT       *Start;
    731       1.1    jruoho 
    732       1.1    jruoho 
    733       1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT,
    734  1.1.1.10  christos         "\nLinkPeerOps: (%u) ", NumPeers);
    735       1.1    jruoho 
    736       1.1    jruoho     va_start (ap, NumPeers);
    737       1.1    jruoho     This = va_arg (ap, ACPI_PARSE_OBJECT *);
    738       1.1    jruoho     Start = This;
    739       1.1    jruoho 
    740       1.1    jruoho     /*
    741       1.1    jruoho      * Link all peers
    742       1.1    jruoho      */
    743       1.1    jruoho     for (i = 0; i < (NumPeers -1); i++)
    744       1.1    jruoho     {
    745       1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "%u=%p ", (i+1), This);
    746       1.1    jruoho 
    747       1.1    jruoho         while (This->Asl.Next)
    748       1.1    jruoho         {
    749       1.1    jruoho             This = This->Asl.Next;
    750       1.1    jruoho         }
    751       1.1    jruoho 
    752  1.1.1.10  christos         /* Get another peer op */
    753       1.1    jruoho 
    754       1.1    jruoho         Next = va_arg (ap, ACPI_PARSE_OBJECT *);
    755       1.1    jruoho         if (!Next)
    756       1.1    jruoho         {
    757  1.1.1.10  christos             Next = TrAllocateOp (PARSEOP_DEFAULT_ARG);
    758       1.1    jruoho         }
    759       1.1    jruoho 
    760  1.1.1.10  christos         /* link new op to the current op */
    761       1.1    jruoho 
    762       1.1    jruoho         This->Asl.Next = Next;
    763       1.1    jruoho         This = Next;
    764       1.1    jruoho     }
    765       1.1    jruoho 
    766  1.1.1.10  christos     va_end (ap);
    767   1.1.1.5  christos     DbgPrint (ASL_PARSE_OUTPUT,"\n");
    768       1.1    jruoho     return (Start);
    769       1.1    jruoho }
    770       1.1    jruoho 
    771       1.1    jruoho 
    772       1.1    jruoho /*******************************************************************************
    773       1.1    jruoho  *
    774  1.1.1.10  christos  * FUNCTION:    TrLinkChildOp
    775       1.1    jruoho  *
    776  1.1.1.10  christos  * PARAMETERS:  Op1           - Parent op
    777       1.1    jruoho  *              Op2           - Op to become a child
    778       1.1    jruoho  *
    779  1.1.1.10  christos  * RETURN:      The parent op
    780       1.1    jruoho  *
    781  1.1.1.10  christos  * DESCRIPTION: Link two ops together as a parent and child
    782       1.1    jruoho  *
    783       1.1    jruoho  ******************************************************************************/
    784       1.1    jruoho 
    785       1.1    jruoho ACPI_PARSE_OBJECT *
    786  1.1.1.10  christos TrLinkChildOp (
    787       1.1    jruoho     ACPI_PARSE_OBJECT       *Op1,
    788       1.1    jruoho     ACPI_PARSE_OBJECT       *Op2)
    789       1.1    jruoho {
    790       1.1    jruoho     ACPI_PARSE_OBJECT       *Next;
    791       1.1    jruoho 
    792       1.1    jruoho 
    793       1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT,
    794  1.1.1.10  christos         "\nLinkChildOp: Parent=%p (%s), Child=%p (%s)\n",
    795       1.1    jruoho         Op1, Op1 ? UtGetOpName(Op1->Asl.ParseOpcode): NULL,
    796       1.1    jruoho         Op2, Op2 ? UtGetOpName(Op2->Asl.ParseOpcode): NULL);
    797       1.1    jruoho 
    798   1.1.1.9  christos     /*
    799  1.1.1.10  christos      * Converter: if TrLinkChildOp is called to link a method call,
    800   1.1.1.9  christos      * turn on capture comments as it signifies that we are done parsing
    801   1.1.1.9  christos      * a method call.
    802   1.1.1.9  christos      */
    803  1.1.1.11  christos     if (AcpiGbl_CaptureComments && Op1)
    804   1.1.1.9  christos     {
    805   1.1.1.9  christos         if (Op1->Asl.ParseOpcode == PARSEOP_METHODCALL)
    806   1.1.1.9  christos         {
    807  1.1.1.12  christos             AslGbl_CommentState.CaptureComments = TRUE;
    808   1.1.1.9  christos         }
    809  1.1.1.12  christos         AslGbl_CommentState.LatestParseOp = Op1;
    810   1.1.1.9  christos     }
    811  1.1.1.10  christos 
    812       1.1    jruoho     if (!Op1 || !Op2)
    813       1.1    jruoho     {
    814   1.1.1.3  christos         return (Op1);
    815       1.1    jruoho     }
    816       1.1    jruoho 
    817       1.1    jruoho     Op1->Asl.Child = Op2;
    818       1.1    jruoho 
    819       1.1    jruoho     /* Set the child and all peers of the child to point to the parent */
    820       1.1    jruoho 
    821       1.1    jruoho     Next = Op2;
    822       1.1    jruoho     while (Next)
    823       1.1    jruoho     {
    824       1.1    jruoho         Next->Asl.Parent = Op1;
    825       1.1    jruoho         Next = Next->Asl.Next;
    826       1.1    jruoho     }
    827       1.1    jruoho 
    828   1.1.1.3  christos     return (Op1);
    829       1.1    jruoho }
    830       1.1    jruoho 
    831       1.1    jruoho 
    832       1.1    jruoho /*******************************************************************************
    833       1.1    jruoho  *
    834       1.1    jruoho  * FUNCTION:    TrWalkParseTree
    835       1.1    jruoho  *
    836  1.1.1.10  christos  * PARAMETERS:  Op                      - Walk starting point
    837  1.1.1.10  christos  *              Visitation              - Type of walk
    838       1.1    jruoho  *              DescendingCallback      - Called during tree descent
    839       1.1    jruoho  *              AscendingCallback       - Called during tree ascent
    840       1.1    jruoho  *              Context                 - To be passed to the callbacks
    841       1.1    jruoho  *
    842       1.1    jruoho  * RETURN:      Status from callback(s)
    843       1.1    jruoho  *
    844       1.1    jruoho  * DESCRIPTION: Walk the entire parse tree.
    845       1.1    jruoho  *
    846       1.1    jruoho  ******************************************************************************/
    847       1.1    jruoho 
    848       1.1    jruoho ACPI_STATUS
    849       1.1    jruoho TrWalkParseTree (
    850       1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
    851       1.1    jruoho     UINT32                  Visitation,
    852       1.1    jruoho     ASL_WALK_CALLBACK       DescendingCallback,
    853       1.1    jruoho     ASL_WALK_CALLBACK       AscendingCallback,
    854       1.1    jruoho     void                    *Context)
    855       1.1    jruoho {
    856       1.1    jruoho     UINT32                  Level;
    857  1.1.1.10  christos     BOOLEAN                 OpPreviouslyVisited;
    858       1.1    jruoho     ACPI_PARSE_OBJECT       *StartOp = Op;
    859       1.1    jruoho     ACPI_STATUS             Status;
    860  1.1.1.13  christos     ACPI_PARSE_OBJECT       *Restore = NULL;
    861  1.1.1.13  christos     BOOLEAN                 WalkOneDefinitionBlock = Visitation & ASL_WALK_VISIT_DB_SEPARATELY;
    862       1.1    jruoho 
    863       1.1    jruoho 
    864  1.1.1.12  christos     if (!AslGbl_ParseTreeRoot)
    865       1.1    jruoho     {
    866       1.1    jruoho         return (AE_OK);
    867       1.1    jruoho     }
    868       1.1    jruoho 
    869       1.1    jruoho     Level = 0;
    870  1.1.1.10  christos     OpPreviouslyVisited = FALSE;
    871       1.1    jruoho 
    872  1.1.1.13  christos     if (Op->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK &&
    873  1.1.1.13  christos         WalkOneDefinitionBlock)
    874  1.1.1.13  christos     {
    875  1.1.1.13  christos         Restore = Op->Asl.Next;
    876  1.1.1.13  christos         Op->Asl.Next = NULL;
    877  1.1.1.13  christos     }
    878  1.1.1.13  christos     switch (Visitation & ~ASL_WALK_VISIT_DB_SEPARATELY)
    879       1.1    jruoho     {
    880       1.1    jruoho     case ASL_WALK_VISIT_DOWNWARD:
    881       1.1    jruoho 
    882       1.1    jruoho         while (Op)
    883       1.1    jruoho         {
    884  1.1.1.10  christos             if (!OpPreviouslyVisited)
    885       1.1    jruoho             {
    886  1.1.1.10  christos                 /* Let the callback process the op. */
    887       1.1    jruoho 
    888       1.1    jruoho                 Status = DescendingCallback (Op, Level, Context);
    889       1.1    jruoho                 if (ACPI_SUCCESS (Status))
    890       1.1    jruoho                 {
    891       1.1    jruoho                     /* Visit children first, once */
    892       1.1    jruoho 
    893       1.1    jruoho                     if (Op->Asl.Child)
    894       1.1    jruoho                     {
    895       1.1    jruoho                         Level++;
    896       1.1    jruoho                         Op = Op->Asl.Child;
    897       1.1    jruoho                         continue;
    898       1.1    jruoho                     }
    899       1.1    jruoho                 }
    900       1.1    jruoho                 else if (Status != AE_CTRL_DEPTH)
    901       1.1    jruoho                 {
    902       1.1    jruoho                     /* Exit immediately on any error */
    903       1.1    jruoho 
    904  1.1.1.13  christos                     goto ErrorExit;
    905       1.1    jruoho                 }
    906       1.1    jruoho             }
    907       1.1    jruoho 
    908       1.1    jruoho             /* Terminate walk at start op */
    909       1.1    jruoho 
    910       1.1    jruoho             if (Op == StartOp)
    911       1.1    jruoho             {
    912       1.1    jruoho                 break;
    913       1.1    jruoho             }
    914       1.1    jruoho 
    915       1.1    jruoho             /* No more children, visit peers */
    916       1.1    jruoho 
    917       1.1    jruoho             if (Op->Asl.Next)
    918       1.1    jruoho             {
    919       1.1    jruoho                 Op = Op->Asl.Next;
    920  1.1.1.10  christos                 OpPreviouslyVisited = FALSE;
    921       1.1    jruoho             }
    922       1.1    jruoho             else
    923       1.1    jruoho             {
    924       1.1    jruoho                 /* No children or peers, re-visit parent */
    925       1.1    jruoho 
    926       1.1    jruoho                 if (Level != 0 )
    927       1.1    jruoho                 {
    928       1.1    jruoho                     Level--;
    929       1.1    jruoho                 }
    930       1.1    jruoho                 Op = Op->Asl.Parent;
    931  1.1.1.10  christos                 OpPreviouslyVisited = TRUE;
    932       1.1    jruoho             }
    933       1.1    jruoho         }
    934       1.1    jruoho         break;
    935       1.1    jruoho 
    936       1.1    jruoho     case ASL_WALK_VISIT_UPWARD:
    937       1.1    jruoho 
    938       1.1    jruoho         while (Op)
    939       1.1    jruoho         {
    940  1.1.1.10  christos             /* Visit leaf op (no children) or parent op on return trip */
    941       1.1    jruoho 
    942       1.1    jruoho             if ((!Op->Asl.Child) ||
    943  1.1.1.10  christos                 (OpPreviouslyVisited))
    944       1.1    jruoho             {
    945  1.1.1.10  christos                 /* Let the callback process the op. */
    946       1.1    jruoho 
    947       1.1    jruoho                 Status = AscendingCallback (Op, Level, Context);
    948       1.1    jruoho                 if (ACPI_FAILURE (Status))
    949       1.1    jruoho                 {
    950  1.1.1.13  christos                     goto ErrorExit;
    951       1.1    jruoho                 }
    952       1.1    jruoho             }
    953       1.1    jruoho             else
    954       1.1    jruoho             {
    955       1.1    jruoho                 /* Visit children first, once */
    956       1.1    jruoho 
    957       1.1    jruoho                 Level++;
    958       1.1    jruoho                 Op = Op->Asl.Child;
    959       1.1    jruoho                 continue;
    960       1.1    jruoho             }
    961       1.1    jruoho 
    962       1.1    jruoho             /* Terminate walk at start op */
    963       1.1    jruoho 
    964       1.1    jruoho             if (Op == StartOp)
    965       1.1    jruoho             {
    966       1.1    jruoho                 break;
    967       1.1    jruoho             }
    968       1.1    jruoho 
    969       1.1    jruoho             /* No more children, visit peers */
    970       1.1    jruoho 
    971       1.1    jruoho             if (Op->Asl.Next)
    972       1.1    jruoho             {
    973       1.1    jruoho                 Op = Op->Asl.Next;
    974  1.1.1.10  christos                 OpPreviouslyVisited = FALSE;
    975       1.1    jruoho             }
    976       1.1    jruoho             else
    977       1.1    jruoho             {
    978       1.1    jruoho                 /* No children or peers, re-visit parent */
    979       1.1    jruoho 
    980       1.1    jruoho                 if (Level != 0 )
    981       1.1    jruoho                 {
    982       1.1    jruoho                     Level--;
    983       1.1    jruoho                 }
    984       1.1    jruoho                 Op = Op->Asl.Parent;
    985  1.1.1.10  christos                 OpPreviouslyVisited = TRUE;
    986       1.1    jruoho             }
    987       1.1    jruoho         }
    988       1.1    jruoho         break;
    989       1.1    jruoho 
    990       1.1    jruoho      case ASL_WALK_VISIT_TWICE:
    991       1.1    jruoho 
    992       1.1    jruoho         while (Op)
    993       1.1    jruoho         {
    994  1.1.1.10  christos             if (OpPreviouslyVisited)
    995       1.1    jruoho             {
    996       1.1    jruoho                 Status = AscendingCallback (Op, Level, Context);
    997       1.1    jruoho                 if (ACPI_FAILURE (Status))
    998       1.1    jruoho                 {
    999  1.1.1.13  christos                     goto ErrorExit;
   1000       1.1    jruoho                 }
   1001       1.1    jruoho             }
   1002       1.1    jruoho             else
   1003       1.1    jruoho             {
   1004  1.1.1.10  christos                 /* Let the callback process the op. */
   1005       1.1    jruoho 
   1006       1.1    jruoho                 Status = DescendingCallback (Op, Level, Context);
   1007       1.1    jruoho                 if (ACPI_SUCCESS (Status))
   1008       1.1    jruoho                 {
   1009       1.1    jruoho                     /* Visit children first, once */
   1010       1.1    jruoho 
   1011       1.1    jruoho                     if (Op->Asl.Child)
   1012       1.1    jruoho                     {
   1013       1.1    jruoho                         Level++;
   1014       1.1    jruoho                         Op = Op->Asl.Child;
   1015       1.1    jruoho                         continue;
   1016       1.1    jruoho                     }
   1017       1.1    jruoho                 }
   1018       1.1    jruoho                 else if (Status != AE_CTRL_DEPTH)
   1019       1.1    jruoho                 {
   1020       1.1    jruoho                     /* Exit immediately on any error */
   1021       1.1    jruoho 
   1022  1.1.1.13  christos                     goto ErrorExit;
   1023       1.1    jruoho                 }
   1024       1.1    jruoho             }
   1025       1.1    jruoho 
   1026       1.1    jruoho             /* Terminate walk at start op */
   1027       1.1    jruoho 
   1028       1.1    jruoho             if (Op == StartOp)
   1029       1.1    jruoho             {
   1030       1.1    jruoho                 break;
   1031       1.1    jruoho             }
   1032       1.1    jruoho 
   1033       1.1    jruoho             /* No more children, visit peers */
   1034       1.1    jruoho 
   1035       1.1    jruoho             if (Op->Asl.Next)
   1036       1.1    jruoho             {
   1037       1.1    jruoho                 Op = Op->Asl.Next;
   1038  1.1.1.10  christos                 OpPreviouslyVisited = FALSE;
   1039       1.1    jruoho             }
   1040       1.1    jruoho             else
   1041       1.1    jruoho             {
   1042       1.1    jruoho                 /* No children or peers, re-visit parent */
   1043       1.1    jruoho 
   1044       1.1    jruoho                 if (Level != 0 )
   1045       1.1    jruoho                 {
   1046       1.1    jruoho                     Level--;
   1047       1.1    jruoho                 }
   1048       1.1    jruoho                 Op = Op->Asl.Parent;
   1049  1.1.1.10  christos                 OpPreviouslyVisited = TRUE;
   1050       1.1    jruoho             }
   1051       1.1    jruoho         }
   1052       1.1    jruoho         break;
   1053       1.1    jruoho 
   1054       1.1    jruoho     default:
   1055       1.1    jruoho         /* No other types supported */
   1056       1.1    jruoho         break;
   1057       1.1    jruoho     }
   1058       1.1    jruoho 
   1059       1.1    jruoho     /* If we get here, the walk completed with no errors */
   1060       1.1    jruoho 
   1061  1.1.1.13  christos     if (Op->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK &&
   1062  1.1.1.13  christos         WalkOneDefinitionBlock)
   1063  1.1.1.13  christos     {
   1064  1.1.1.13  christos         Op->Asl.Next = Restore;
   1065  1.1.1.13  christos     }
   1066  1.1.1.13  christos 
   1067       1.1    jruoho     return (AE_OK);
   1068  1.1.1.13  christos 
   1069  1.1.1.13  christos ErrorExit:
   1070  1.1.1.13  christos 
   1071  1.1.1.13  christos     if (Op->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK &&
   1072  1.1.1.13  christos         WalkOneDefinitionBlock)
   1073  1.1.1.13  christos     {
   1074  1.1.1.13  christos         Op->Asl.Next = Restore;
   1075  1.1.1.13  christos     }
   1076  1.1.1.13  christos     return (Status);
   1077       1.1    jruoho }
   1078