Home | History | Annotate | Line # | Download | only in compiler
aslparseop.c revision 1.1.1.11.6.1
      1           1.1  christos /******************************************************************************
      2           1.1  christos  *
      3           1.1  christos  * Module Name: aslparseop - Parse op create/allocate/cache interfaces
      4           1.1  christos  *
      5           1.1  christos  *****************************************************************************/
      6           1.1  christos 
      7  1.1.1.11.6.1  perseant /******************************************************************************
      8  1.1.1.11.6.1  perseant  *
      9  1.1.1.11.6.1  perseant  * 1. Copyright Notice
     10  1.1.1.11.6.1  perseant  *
     11  1.1.1.11.6.1  perseant  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
     12           1.1  christos  * All rights reserved.
     13           1.1  christos  *
     14  1.1.1.11.6.1  perseant  * 2. License
     15  1.1.1.11.6.1  perseant  *
     16  1.1.1.11.6.1  perseant  * 2.1. This is your license from Intel Corp. under its intellectual property
     17  1.1.1.11.6.1  perseant  * rights. You may have additional license terms from the party that provided
     18  1.1.1.11.6.1  perseant  * you this software, covering your right to use that party's intellectual
     19  1.1.1.11.6.1  perseant  * property rights.
     20  1.1.1.11.6.1  perseant  *
     21  1.1.1.11.6.1  perseant  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     22  1.1.1.11.6.1  perseant  * copy of the source code appearing in this file ("Covered Code") an
     23  1.1.1.11.6.1  perseant  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     24  1.1.1.11.6.1  perseant  * base code distributed originally by Intel ("Original Intel Code") to copy,
     25  1.1.1.11.6.1  perseant  * make derivatives, distribute, use and display any portion of the Covered
     26  1.1.1.11.6.1  perseant  * Code in any form, with the right to sublicense such rights; and
     27  1.1.1.11.6.1  perseant  *
     28  1.1.1.11.6.1  perseant  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     29  1.1.1.11.6.1  perseant  * license (with the right to sublicense), under only those claims of Intel
     30  1.1.1.11.6.1  perseant  * patents that are infringed by the Original Intel Code, to make, use, sell,
     31  1.1.1.11.6.1  perseant  * offer to sell, and import the Covered Code and derivative works thereof
     32  1.1.1.11.6.1  perseant  * solely to the minimum extent necessary to exercise the above copyright
     33  1.1.1.11.6.1  perseant  * license, and in no event shall the patent license extend to any additions
     34  1.1.1.11.6.1  perseant  * to or modifications of the Original Intel Code. No other license or right
     35  1.1.1.11.6.1  perseant  * is granted directly or by implication, estoppel or otherwise;
     36  1.1.1.11.6.1  perseant  *
     37  1.1.1.11.6.1  perseant  * The above copyright and patent license is granted only if the following
     38  1.1.1.11.6.1  perseant  * conditions are met:
     39  1.1.1.11.6.1  perseant  *
     40  1.1.1.11.6.1  perseant  * 3. Conditions
     41  1.1.1.11.6.1  perseant  *
     42  1.1.1.11.6.1  perseant  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     43  1.1.1.11.6.1  perseant  * Redistribution of source code of any substantial portion of the Covered
     44  1.1.1.11.6.1  perseant  * Code or modification with rights to further distribute source must include
     45  1.1.1.11.6.1  perseant  * the above Copyright Notice, the above License, this list of Conditions,
     46  1.1.1.11.6.1  perseant  * and the following Disclaimer and Export Compliance provision. In addition,
     47  1.1.1.11.6.1  perseant  * Licensee must cause all Covered Code to which Licensee contributes to
     48  1.1.1.11.6.1  perseant  * contain a file documenting the changes Licensee made to create that Covered
     49  1.1.1.11.6.1  perseant  * Code and the date of any change. Licensee must include in that file the
     50  1.1.1.11.6.1  perseant  * documentation of any changes made by any predecessor Licensee. Licensee
     51  1.1.1.11.6.1  perseant  * must include a prominent statement that the modification is derived,
     52  1.1.1.11.6.1  perseant  * directly or indirectly, from Original Intel Code.
     53  1.1.1.11.6.1  perseant  *
     54  1.1.1.11.6.1  perseant  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     55  1.1.1.11.6.1  perseant  * Redistribution of source code of any substantial portion of the Covered
     56  1.1.1.11.6.1  perseant  * Code or modification without rights to further distribute source must
     57  1.1.1.11.6.1  perseant  * include the following Disclaimer and Export Compliance provision in the
     58  1.1.1.11.6.1  perseant  * documentation and/or other materials provided with distribution. In
     59  1.1.1.11.6.1  perseant  * addition, Licensee may not authorize further sublicense of source of any
     60  1.1.1.11.6.1  perseant  * portion of the Covered Code, and must include terms to the effect that the
     61  1.1.1.11.6.1  perseant  * license from Licensee to its licensee is limited to the intellectual
     62  1.1.1.11.6.1  perseant  * property embodied in the software Licensee provides to its licensee, and
     63  1.1.1.11.6.1  perseant  * not to intellectual property embodied in modifications its licensee may
     64  1.1.1.11.6.1  perseant  * make.
     65  1.1.1.11.6.1  perseant  *
     66  1.1.1.11.6.1  perseant  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     67  1.1.1.11.6.1  perseant  * substantial portion of the Covered Code or modification must reproduce the
     68  1.1.1.11.6.1  perseant  * above Copyright Notice, and the following Disclaimer and Export Compliance
     69  1.1.1.11.6.1  perseant  * provision in the documentation and/or other materials provided with the
     70  1.1.1.11.6.1  perseant  * distribution.
     71  1.1.1.11.6.1  perseant  *
     72  1.1.1.11.6.1  perseant  * 3.4. Intel retains all right, title, and interest in and to the Original
     73  1.1.1.11.6.1  perseant  * Intel Code.
     74  1.1.1.11.6.1  perseant  *
     75  1.1.1.11.6.1  perseant  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     76  1.1.1.11.6.1  perseant  * Intel shall be used in advertising or otherwise to promote the sale, use or
     77  1.1.1.11.6.1  perseant  * other dealings in products derived from or relating to the Covered Code
     78  1.1.1.11.6.1  perseant  * without prior written authorization from Intel.
     79  1.1.1.11.6.1  perseant  *
     80  1.1.1.11.6.1  perseant  * 4. Disclaimer and Export Compliance
     81  1.1.1.11.6.1  perseant  *
     82  1.1.1.11.6.1  perseant  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     83  1.1.1.11.6.1  perseant  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     84  1.1.1.11.6.1  perseant  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
     85  1.1.1.11.6.1  perseant  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
     86  1.1.1.11.6.1  perseant  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
     87  1.1.1.11.6.1  perseant  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     88  1.1.1.11.6.1  perseant  * PARTICULAR PURPOSE.
     89  1.1.1.11.6.1  perseant  *
     90  1.1.1.11.6.1  perseant  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     91  1.1.1.11.6.1  perseant  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     92  1.1.1.11.6.1  perseant  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     93  1.1.1.11.6.1  perseant  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     94  1.1.1.11.6.1  perseant  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     95  1.1.1.11.6.1  perseant  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
     96  1.1.1.11.6.1  perseant  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     97  1.1.1.11.6.1  perseant  * LIMITED REMEDY.
     98  1.1.1.11.6.1  perseant  *
     99  1.1.1.11.6.1  perseant  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    100  1.1.1.11.6.1  perseant  * software or system incorporating such software without first obtaining any
    101  1.1.1.11.6.1  perseant  * required license or other approval from the U. S. Department of Commerce or
    102  1.1.1.11.6.1  perseant  * any other agency or department of the United States Government. In the
    103  1.1.1.11.6.1  perseant  * event Licensee exports any such software from the United States or
    104  1.1.1.11.6.1  perseant  * re-exports any such software from a foreign destination, Licensee shall
    105  1.1.1.11.6.1  perseant  * ensure that the distribution and export/re-export of the software is in
    106  1.1.1.11.6.1  perseant  * compliance with all laws, regulations, orders, or other restrictions of the
    107  1.1.1.11.6.1  perseant  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    108  1.1.1.11.6.1  perseant  * any of its subsidiaries will export/re-export any technical data, process,
    109  1.1.1.11.6.1  perseant  * software, or service, directly or indirectly, to any country for which the
    110  1.1.1.11.6.1  perseant  * United States government or any agency thereof requires an export license,
    111  1.1.1.11.6.1  perseant  * other governmental approval, or letter of assurance, without first obtaining
    112  1.1.1.11.6.1  perseant  * such license, approval or letter.
    113  1.1.1.11.6.1  perseant  *
    114  1.1.1.11.6.1  perseant  *****************************************************************************
    115  1.1.1.11.6.1  perseant  *
    116  1.1.1.11.6.1  perseant  * Alternatively, you may choose to be licensed under the terms of the
    117  1.1.1.11.6.1  perseant  * following license:
    118  1.1.1.11.6.1  perseant  *
    119           1.1  christos  * Redistribution and use in source and binary forms, with or without
    120           1.1  christos  * modification, are permitted provided that the following conditions
    121           1.1  christos  * are met:
    122           1.1  christos  * 1. Redistributions of source code must retain the above copyright
    123           1.1  christos  *    notice, this list of conditions, and the following disclaimer,
    124           1.1  christos  *    without modification.
    125           1.1  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
    126           1.1  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
    127           1.1  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
    128           1.1  christos  *    including a substantially similar Disclaimer requirement for further
    129           1.1  christos  *    binary redistribution.
    130           1.1  christos  * 3. Neither the names of the above-listed copyright holders nor the names
    131           1.1  christos  *    of any contributors may be used to endorse or promote products derived
    132           1.1  christos  *    from this software without specific prior written permission.
    133           1.1  christos  *
    134           1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    135           1.1  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    136       1.1.1.9  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    137           1.1  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    138  1.1.1.11.6.1  perseant  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    139  1.1.1.11.6.1  perseant  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    140  1.1.1.11.6.1  perseant  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    141  1.1.1.11.6.1  perseant  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    142  1.1.1.11.6.1  perseant  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    143  1.1.1.11.6.1  perseant  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    144  1.1.1.11.6.1  perseant  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    145  1.1.1.11.6.1  perseant  *
    146  1.1.1.11.6.1  perseant  * Alternatively, you may choose to be licensed under the terms of the
    147  1.1.1.11.6.1  perseant  * GNU General Public License ("GPL") version 2 as published by the Free
    148  1.1.1.11.6.1  perseant  * Software Foundation.
    149  1.1.1.11.6.1  perseant  *
    150  1.1.1.11.6.1  perseant  *****************************************************************************/
    151           1.1  christos 
    152           1.1  christos #include "aslcompiler.h"
    153           1.1  christos #include "aslcompiler.y.h"
    154           1.1  christos #include "acapps.h"
    155           1.1  christos #include "acconvert.h"
    156           1.1  christos 
    157           1.1  christos #define _COMPONENT          ACPI_COMPILER
    158           1.1  christos         ACPI_MODULE_NAME    ("aslparseop")
    159           1.1  christos 
    160           1.1  christos 
    161           1.1  christos /*******************************************************************************
    162           1.1  christos  *
    163           1.1  christos  * FUNCTION:    TrCreateOp
    164           1.1  christos  *
    165           1.1  christos  * PARAMETERS:  ParseOpcode         - Opcode to be assigned to the op
    166           1.1  christos  *              NumChildren         - Number of children to follow
    167           1.1  christos  *              ...                 - A list of child ops to link to the new
    168           1.1  christos  *                                    op. NumChildren long.
    169           1.1  christos  *
    170           1.1  christos  * RETURN:      Pointer to the new op. Aborts on allocation failure
    171           1.1  christos  *
    172           1.1  christos  * DESCRIPTION: Create a new parse op and link together a list of child
    173           1.1  christos  *              ops underneath the new op.
    174           1.1  christos  *
    175           1.1  christos  ******************************************************************************/
    176           1.1  christos 
    177           1.1  christos ACPI_PARSE_OBJECT *
    178           1.1  christos TrCreateOp (
    179           1.1  christos     UINT32                  ParseOpcode,
    180           1.1  christos     UINT32                  NumChildren,
    181           1.1  christos     ...)
    182           1.1  christos {
    183           1.1  christos     ACPI_PARSE_OBJECT       *Op;
    184           1.1  christos     ACPI_PARSE_OBJECT       *Child;
    185           1.1  christos     ACPI_PARSE_OBJECT       *PrevChild;
    186           1.1  christos     va_list                 ap;
    187           1.1  christos     UINT32                  i;
    188           1.1  christos     BOOLEAN                 FirstChild;
    189           1.1  christos 
    190           1.1  christos 
    191           1.1  christos     va_start (ap, NumChildren);
    192           1.1  christos 
    193           1.1  christos     /* Allocate one new op */
    194           1.1  christos 
    195           1.1  christos     Op = TrAllocateOp (ParseOpcode);
    196           1.1  christos 
    197           1.1  christos     DbgPrint (ASL_PARSE_OUTPUT,
    198           1.1  christos         "\nCreateOp  Ln/Col %u/%u NewParent %p Child %u Op %s  ",
    199           1.1  christos         Op->Asl.LineNumber, Op->Asl.Column, Op,
    200           1.1  christos         NumChildren, UtGetOpName(ParseOpcode));
    201           1.1  christos 
    202           1.1  christos     /* Some extra debug output based on the parse opcode */
    203           1.1  christos 
    204           1.1  christos     switch (ParseOpcode)
    205           1.1  christos     {
    206           1.1  christos     case PARSEOP_ASL_CODE:
    207           1.1  christos 
    208       1.1.1.4  christos         AslGbl_ParseTreeRoot = Op;
    209           1.1  christos         Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
    210           1.1  christos         DbgPrint (ASL_PARSE_OUTPUT, "ASLCODE (Tree Completed)->");
    211           1.1  christos         break;
    212           1.1  christos 
    213           1.1  christos     case PARSEOP_DEFINITION_BLOCK:
    214           1.1  christos 
    215           1.1  christos         DbgPrint (ASL_PARSE_OUTPUT, "DEFINITION_BLOCK (Tree Completed)->");
    216           1.1  christos         break;
    217           1.1  christos 
    218           1.1  christos     case PARSEOP_OPERATIONREGION:
    219           1.1  christos 
    220           1.1  christos         DbgPrint (ASL_PARSE_OUTPUT, "OPREGION->");
    221           1.1  christos         break;
    222           1.1  christos 
    223           1.1  christos     case PARSEOP_OR:
    224           1.1  christos 
    225           1.1  christos         DbgPrint (ASL_PARSE_OUTPUT, "OR->");
    226           1.1  christos         break;
    227           1.1  christos 
    228           1.1  christos     default:
    229           1.1  christos 
    230           1.1  christos         /* Nothing to do for other opcodes */
    231           1.1  christos 
    232           1.1  christos         break;
    233           1.1  christos     }
    234           1.1  christos 
    235           1.1  christos     /* Link the new op to its children */
    236           1.1  christos 
    237           1.1  christos     PrevChild = NULL;
    238           1.1  christos     FirstChild = TRUE;
    239           1.1  christos     for (i = 0; i < NumChildren; i++)
    240           1.1  christos     {
    241           1.1  christos         /* Get the next child */
    242           1.1  christos 
    243           1.1  christos         Child = va_arg (ap, ACPI_PARSE_OBJECT *);
    244           1.1  christos         DbgPrint (ASL_PARSE_OUTPUT, "%p, ", Child);
    245           1.1  christos 
    246           1.1  christos         /*
    247           1.1  christos          * If child is NULL, this means that an optional argument
    248           1.1  christos          * was omitted. We must create a placeholder with a special
    249           1.1  christos          * opcode (DEFAULT_ARG) so that the code generator will know
    250           1.1  christos          * that it must emit the correct default for this argument
    251           1.1  christos          */
    252           1.1  christos         if (!Child)
    253           1.1  christos         {
    254           1.1  christos             Child = TrAllocateOp (PARSEOP_DEFAULT_ARG);
    255           1.1  christos         }
    256           1.1  christos 
    257           1.1  christos         /* Link first child to parent */
    258           1.1  christos 
    259           1.1  christos         if (FirstChild)
    260           1.1  christos         {
    261           1.1  christos             FirstChild = FALSE;
    262           1.1  christos             Op->Asl.Child = Child;
    263           1.1  christos 
    264           1.1  christos             /*
    265           1.1  christos              * For the ASL-/ASL+ converter: if the ParseOp is a Connection,
    266           1.1  christos              * External, Offset or AccessAs, it means that the comments in the
    267           1.1  christos              * FirstChild belongs to their parent due to the parsing order in
    268           1.1  christos              * the .y files. To correct this, take the comments in the
    269           1.1  christos              * FirstChild place it in the parent. This also means that
    270           1.1  christos              * legitimate comments for the child gets put to the parent.
    271           1.1  christos              */
    272       1.1.1.3  christos             if (AcpiGbl_CaptureComments &&
    273           1.1  christos                 ((ParseOpcode == PARSEOP_CONNECTION) ||
    274           1.1  christos                  (ParseOpcode == PARSEOP_EXTERNAL) ||
    275           1.1  christos                  (ParseOpcode == PARSEOP_OFFSET) ||
    276           1.1  christos                  (ParseOpcode == PARSEOP_ACCESSAS)))
    277           1.1  christos             {
    278           1.1  christos                 Op->Asl.CommentList      = Child->Asl.CommentList;
    279           1.1  christos                 Op->Asl.EndBlkComment    = Child->Asl.EndBlkComment;
    280           1.1  christos                 Op->Asl.InlineComment    = Child->Asl.InlineComment;
    281           1.1  christos                 Op->Asl.FileChanged      = Child->Asl.FileChanged;
    282           1.1  christos 
    283           1.1  christos                 Child->Asl.CommentList   = NULL;
    284           1.1  christos                 Child->Asl.EndBlkComment = NULL;
    285           1.1  christos                 Child->Asl.InlineComment = NULL;
    286           1.1  christos                 Child->Asl.FileChanged   = FALSE;
    287           1.1  christos 
    288           1.1  christos                 /*
    289           1.1  christos                  * These do not need to be "passed off". They can be copied
    290           1.1  christos                  * because the code for these opcodes should be printed in the
    291           1.1  christos                  * same file.
    292           1.1  christos                  */
    293           1.1  christos                 Op->Asl.Filename         = Child->Asl.Filename;
    294           1.1  christos                 Op->Asl.ParentFilename   = Child->Asl.ParentFilename;
    295           1.1  christos             }
    296           1.1  christos         }
    297           1.1  christos 
    298           1.1  christos         /* Point all children to parent */
    299           1.1  christos 
    300           1.1  christos         Child->Asl.Parent = Op;
    301           1.1  christos 
    302           1.1  christos         /* Link children in a peer list */
    303           1.1  christos 
    304           1.1  christos         if (PrevChild)
    305           1.1  christos         {
    306           1.1  christos             PrevChild->Asl.Next = Child;
    307           1.1  christos         };
    308           1.1  christos 
    309           1.1  christos         /* Get the comment from last child in the resource template call */
    310           1.1  christos 
    311       1.1.1.3  christos         if (AcpiGbl_CaptureComments &&
    312           1.1  christos             (Op->Asl.ParseOpcode == PARSEOP_RESOURCETEMPLATE))
    313           1.1  christos         {
    314           1.1  christos             CvDbgPrint ("Transferred current comment list to this op.\n");
    315           1.1  christos             Op->Asl.CommentList = Child->Asl.CommentList;
    316           1.1  christos             Child->Asl.CommentList = NULL;
    317           1.1  christos 
    318           1.1  christos             Op->Asl.InlineComment = Child->Asl.InlineComment;
    319           1.1  christos             Child->Asl.InlineComment = NULL;
    320           1.1  christos         }
    321           1.1  christos 
    322           1.1  christos         /*
    323           1.1  christos          * This child might be a list, point all ops in the list
    324           1.1  christos          * to the same parent
    325           1.1  christos          */
    326           1.1  christos         while (Child->Asl.Next)
    327           1.1  christos         {
    328           1.1  christos             Child = Child->Asl.Next;
    329           1.1  christos             Child->Asl.Parent = Op;
    330           1.1  christos         }
    331           1.1  christos 
    332           1.1  christos         PrevChild = Child;
    333           1.1  christos     }
    334           1.1  christos 
    335           1.1  christos     va_end(ap);
    336           1.1  christos     DbgPrint (ASL_PARSE_OUTPUT, "\n");
    337           1.1  christos     return (Op);
    338           1.1  christos }
    339           1.1  christos 
    340           1.1  christos 
    341           1.1  christos /*******************************************************************************
    342           1.1  christos  *
    343           1.1  christos  * FUNCTION:    TrCreateLeafOp
    344           1.1  christos  *
    345           1.1  christos  * PARAMETERS:  ParseOpcode         - New opcode to be assigned to the op
    346           1.1  christos  *
    347           1.1  christos  * RETURN:      Pointer to the new op. Aborts on allocation failure
    348           1.1  christos  *
    349           1.1  christos  * DESCRIPTION: Create a simple leaf op (no children or peers, and no value
    350           1.1  christos  *              assigned to the op)
    351           1.1  christos  *
    352           1.1  christos  ******************************************************************************/
    353           1.1  christos 
    354           1.1  christos ACPI_PARSE_OBJECT *
    355           1.1  christos TrCreateLeafOp (
    356           1.1  christos     UINT32                  ParseOpcode)
    357           1.1  christos {
    358           1.1  christos     ACPI_PARSE_OBJECT       *Op;
    359           1.1  christos 
    360           1.1  christos 
    361           1.1  christos     Op = TrAllocateOp (ParseOpcode);
    362           1.1  christos 
    363           1.1  christos     DbgPrint (ASL_PARSE_OUTPUT,
    364           1.1  christos         "\nCreateLeafOp  Ln/Col %u/%u NewOp %p  Op %s\n\n",
    365           1.1  christos         Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName (ParseOpcode));
    366           1.1  christos 
    367           1.1  christos     return (Op);
    368           1.1  christos }
    369           1.1  christos 
    370           1.1  christos 
    371           1.1  christos /*******************************************************************************
    372           1.1  christos  *
    373           1.1  christos  * FUNCTION:    TrCreateValuedLeafOp
    374           1.1  christos  *
    375           1.1  christos  * PARAMETERS:  ParseOpcode         - New opcode to be assigned to the op
    376           1.1  christos  *              Value               - Value to be assigned to the op
    377           1.1  christos  *
    378           1.1  christos  * RETURN:      Pointer to the new op. Aborts on allocation failure
    379           1.1  christos  *
    380           1.1  christos  * DESCRIPTION: Create a leaf op (no children or peers) with a value
    381           1.1  christos  *              assigned to it
    382           1.1  christos  *
    383           1.1  christos  ******************************************************************************/
    384           1.1  christos 
    385           1.1  christos ACPI_PARSE_OBJECT *
    386           1.1  christos TrCreateValuedLeafOp (
    387           1.1  christos     UINT32                  ParseOpcode,
    388           1.1  christos     UINT64                  Value)
    389           1.1  christos {
    390           1.1  christos     ACPI_PARSE_OBJECT       *Op;
    391       1.1.1.8  christos     UINT32                  i;
    392       1.1.1.8  christos     char                    *StringPtr = NULL;
    393           1.1  christos 
    394           1.1  christos 
    395           1.1  christos     Op = TrAllocateOp (ParseOpcode);
    396           1.1  christos     Op->Asl.Value.Integer = Value;
    397           1.1  christos 
    398           1.1  christos     DbgPrint (ASL_PARSE_OUTPUT,
    399           1.1  christos         "\nCreateValuedLeafOp  Ln/Col %u/%u NewOp %p  "
    400           1.1  christos         "Op %s  Value %8.8X%8.8X  ",
    401           1.1  christos         Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName(ParseOpcode),
    402           1.1  christos         ACPI_FORMAT_UINT64 (Value));
    403           1.1  christos 
    404           1.1  christos     switch (ParseOpcode)
    405           1.1  christos     {
    406           1.1  christos     case PARSEOP_STRING_LITERAL:
    407           1.1  christos 
    408       1.1.1.6  christos         DbgPrint (ASL_PARSE_OUTPUT, "STRING->%s", Op->Asl.Value.String);
    409           1.1  christos         break;
    410           1.1  christos 
    411           1.1  christos     case PARSEOP_NAMESEG:
    412           1.1  christos 
    413       1.1.1.8  christos         /* Check for mixed case (or all lower case). Issue a remark in this case */
    414       1.1.1.8  christos 
    415       1.1.1.8  christos         for (i = 0; i < ACPI_NAMESEG_SIZE; i++)
    416       1.1.1.8  christos         {
    417       1.1.1.9  christos             if (islower ((int) Op->Asl.Value.Name[i]))
    418       1.1.1.8  christos             {
    419       1.1.1.8  christos                 AcpiUtStrupr (&Op->Asl.Value.Name[i]);
    420       1.1.1.8  christos                 AslError (ASL_REMARK, ASL_MSG_LOWER_CASE_NAMESEG, Op, Op->Asl.Value.Name);
    421       1.1.1.8  christos                 break;
    422       1.1.1.8  christos             }
    423       1.1.1.8  christos         }
    424       1.1.1.6  christos         DbgPrint (ASL_PARSE_OUTPUT, "NAMESEG->%s", Op->Asl.Value.String);
    425           1.1  christos         break;
    426           1.1  christos 
    427           1.1  christos     case PARSEOP_NAMESTRING:
    428           1.1  christos 
    429       1.1.1.8  christos         /* Check for mixed case (or all lower case). Issue a remark in this case */
    430       1.1.1.8  christos 
    431       1.1.1.8  christos         StringPtr = Op->Asl.Value.Name;
    432       1.1.1.8  christos         for (i = 0; *StringPtr; i++)
    433       1.1.1.8  christos         {
    434       1.1.1.9  christos             if (islower ((int) *StringPtr))
    435       1.1.1.8  christos             {
    436       1.1.1.8  christos                 AcpiUtStrupr (&Op->Asl.Value.Name[i]);
    437       1.1.1.8  christos                 AslError (ASL_REMARK, ASL_MSG_LOWER_CASE_NAMEPATH, Op, Op->Asl.Value.Name);
    438       1.1.1.8  christos                 break;
    439       1.1.1.8  christos             }
    440       1.1.1.8  christos             StringPtr++;
    441       1.1.1.8  christos         }
    442       1.1.1.6  christos         DbgPrint (ASL_PARSE_OUTPUT, "NAMESTRING->%s", Op->Asl.Value.String);
    443           1.1  christos         break;
    444           1.1  christos 
    445           1.1  christos     case PARSEOP_EISAID:
    446           1.1  christos 
    447       1.1.1.6  christos         DbgPrint (ASL_PARSE_OUTPUT, "EISAID->%s", Op->Asl.Value.String);
    448           1.1  christos         break;
    449           1.1  christos 
    450           1.1  christos     case PARSEOP_METHOD:
    451           1.1  christos 
    452           1.1  christos         DbgPrint (ASL_PARSE_OUTPUT, "METHOD");
    453           1.1  christos         break;
    454           1.1  christos 
    455           1.1  christos     case PARSEOP_INTEGER:
    456           1.1  christos 
    457           1.1  christos         DbgPrint (ASL_PARSE_OUTPUT, "INTEGER->%8.8X%8.8X",
    458           1.1  christos             ACPI_FORMAT_UINT64 (Value));
    459           1.1  christos         break;
    460           1.1  christos 
    461           1.1  christos     default:
    462           1.1  christos         break;
    463           1.1  christos     }
    464           1.1  christos 
    465           1.1  christos     DbgPrint (ASL_PARSE_OUTPUT, "\n\n");
    466           1.1  christos     return (Op);
    467           1.1  christos }
    468           1.1  christos 
    469           1.1  christos 
    470           1.1  christos /*******************************************************************************
    471           1.1  christos  *
    472           1.1  christos  * FUNCTION:    TrCreateTargetOp
    473           1.1  christos  *
    474           1.1  christos  * PARAMETERS:  OriginalOp          - Op to be copied
    475           1.1  christos  *
    476           1.1  christos  * RETURN:      Pointer to the new op. Aborts on allocation failure
    477           1.1  christos  *
    478           1.1  christos  * DESCRIPTION: Copy an existing op (and subtree). Used in ASL+ (C-style)
    479           1.1  christos  *              expressions where the target is the same as one of the
    480           1.1  christos  *              operands. A new op and subtree must be created from the
    481           1.1  christos  *              original so that the parse tree can be linked properly.
    482           1.1  christos  *
    483           1.1  christos  * NOTE:        This code is specific to target operands that are the last
    484           1.1  christos  *              operand in an ASL/AML operator. Meaning that the top-level
    485           1.1  christos  *              parse Op in a possible subtree has a NULL Next pointer.
    486           1.1  christos  *              This simplifies the recursion.
    487           1.1  christos  *
    488           1.1  christos  *              Subtree example:
    489           1.1  christos  *                  DeRefOf (Local1) += 32
    490           1.1  christos  *
    491           1.1  christos  *              This gets converted to:
    492           1.1  christos  *                  Add (DeRefOf (Local1), 32, DeRefOf (Local1))
    493           1.1  christos  *
    494           1.1  christos  *              Each DeRefOf has a single child, Local1. Even more complex
    495           1.1  christos  *              subtrees can be created via the Index and DeRefOf operators.
    496           1.1  christos  *
    497           1.1  christos  ******************************************************************************/
    498           1.1  christos 
    499           1.1  christos ACPI_PARSE_OBJECT *
    500           1.1  christos TrCreateTargetOp (
    501           1.1  christos     ACPI_PARSE_OBJECT       *OriginalOp,
    502           1.1  christos     ACPI_PARSE_OBJECT       *ParentOp)
    503           1.1  christos {
    504           1.1  christos     ACPI_PARSE_OBJECT       *Op;
    505           1.1  christos 
    506           1.1  christos 
    507           1.1  christos     if (!OriginalOp)
    508           1.1  christos     {
    509           1.1  christos         return (NULL);
    510           1.1  christos     }
    511           1.1  christos 
    512       1.1.1.2  christos     Op = UtParseOpCacheCalloc ();
    513           1.1  christos 
    514           1.1  christos     /* Copy the pertinent values (omit link pointer fields) */
    515           1.1  christos 
    516           1.1  christos     Op->Asl.Value               = OriginalOp->Asl.Value;
    517           1.1  christos     Op->Asl.Filename            = OriginalOp->Asl.Filename;
    518           1.1  christos     Op->Asl.LineNumber          = OriginalOp->Asl.LineNumber;
    519           1.1  christos     Op->Asl.LogicalLineNumber   = OriginalOp->Asl.LogicalLineNumber;
    520           1.1  christos     Op->Asl.LogicalByteOffset   = OriginalOp->Asl.LogicalByteOffset;
    521           1.1  christos     Op->Asl.Column              = OriginalOp->Asl.Column;
    522           1.1  christos     Op->Asl.Flags               = OriginalOp->Asl.Flags;
    523           1.1  christos     Op->Asl.CompileFlags        = OriginalOp->Asl.CompileFlags;
    524           1.1  christos     Op->Asl.AmlOpcode           = OriginalOp->Asl.AmlOpcode;
    525           1.1  christos     Op->Asl.ParseOpcode         = OriginalOp->Asl.ParseOpcode;
    526           1.1  christos     Op->Asl.Parent              = ParentOp;
    527           1.1  christos 
    528           1.1  christos     UtSetParseOpName (Op);
    529           1.1  christos 
    530           1.1  christos     /* Copy a possible subtree below this op */
    531           1.1  christos 
    532           1.1  christos     if (OriginalOp->Asl.Child)
    533           1.1  christos     {
    534           1.1  christos         Op->Asl.Child = TrCreateTargetOp (OriginalOp->Asl.Child, Op);
    535           1.1  christos     }
    536           1.1  christos 
    537           1.1  christos     if (OriginalOp->Asl.Next) /* Null for top-level op */
    538           1.1  christos     {
    539           1.1  christos         Op->Asl.Next = TrCreateTargetOp (OriginalOp->Asl.Next, ParentOp);
    540           1.1  christos     }
    541           1.1  christos 
    542           1.1  christos     return (Op);
    543           1.1  christos }
    544           1.1  christos 
    545           1.1  christos 
    546           1.1  christos /*******************************************************************************
    547           1.1  christos  *
    548           1.1  christos  * FUNCTION:    TrCreateAssignmentOp
    549           1.1  christos  *
    550           1.1  christos  * PARAMETERS:  Target              - Assignment target
    551           1.1  christos  *              Source              - Assignment source
    552           1.1  christos  *
    553           1.1  christos  * RETURN:      Pointer to the new op. Aborts on allocation failure
    554           1.1  christos  *
    555           1.1  christos  * DESCRIPTION: Implements the C-style '=' operator. It changes the parse
    556           1.1  christos  *              tree if possible to utilize the last argument of the math
    557           1.1  christos  *              operators which is a target operand -- thus saving invocation
    558           1.1  christos  *              of and additional Store() operator. An optimization.
    559           1.1  christos  *
    560           1.1  christos  ******************************************************************************/
    561           1.1  christos 
    562           1.1  christos ACPI_PARSE_OBJECT *
    563           1.1  christos TrCreateAssignmentOp (
    564           1.1  christos     ACPI_PARSE_OBJECT       *Target,
    565           1.1  christos     ACPI_PARSE_OBJECT       *Source)
    566           1.1  christos {
    567           1.1  christos     ACPI_PARSE_OBJECT       *TargetOp;
    568           1.1  christos     ACPI_PARSE_OBJECT       *SourceOp1;
    569           1.1  christos     ACPI_PARSE_OBJECT       *SourceOp2;
    570           1.1  christos     ACPI_PARSE_OBJECT       *Operator;
    571           1.1  christos 
    572           1.1  christos 
    573           1.1  christos     DbgPrint (ASL_PARSE_OUTPUT,
    574           1.1  christos         "\nTrCreateAssignmentOp  Line [%u to %u] Source %s Target %s\n",
    575           1.1  christos         Source->Asl.LineNumber, Source->Asl.EndLine,
    576           1.1  christos         UtGetOpName (Source->Asl.ParseOpcode),
    577           1.1  christos         UtGetOpName (Target->Asl.ParseOpcode));
    578           1.1  christos 
    579           1.1  christos     TrSetOpFlags (Target, OP_IS_TARGET);
    580           1.1  christos 
    581           1.1  christos     switch (Source->Asl.ParseOpcode)
    582           1.1  christos     {
    583           1.1  christos     /*
    584           1.1  christos      * Only these operators can be optimized because they have
    585           1.1  christos      * a target operand
    586           1.1  christos      */
    587           1.1  christos     case PARSEOP_ADD:
    588           1.1  christos     case PARSEOP_AND:
    589           1.1  christos     case PARSEOP_DIVIDE:
    590           1.1  christos     case PARSEOP_INDEX:
    591           1.1  christos     case PARSEOP_MOD:
    592           1.1  christos     case PARSEOP_MULTIPLY:
    593           1.1  christos     case PARSEOP_NOT:
    594           1.1  christos     case PARSEOP_OR:
    595           1.1  christos     case PARSEOP_SHIFTLEFT:
    596           1.1  christos     case PARSEOP_SHIFTRIGHT:
    597           1.1  christos     case PARSEOP_SUBTRACT:
    598           1.1  christos     case PARSEOP_XOR:
    599           1.1  christos 
    600           1.1  christos         break;
    601           1.1  christos 
    602           1.1  christos     /* Otherwise, just create a normal Store operator */
    603           1.1  christos 
    604           1.1  christos     default:
    605           1.1  christos         goto CannotOptimize;
    606           1.1  christos     }
    607           1.1  christos 
    608           1.1  christos     /*
    609           1.1  christos      * Transform the parse tree such that the target is moved to the
    610           1.1  christos      * last operand of the operator
    611           1.1  christos      */
    612           1.1  christos     SourceOp1 = Source->Asl.Child;
    613           1.1  christos     SourceOp2 = SourceOp1->Asl.Next;
    614           1.1  christos 
    615           1.1  christos     /* NOT only has one operand, but has a target */
    616           1.1  christos 
    617           1.1  christos     if (Source->Asl.ParseOpcode == PARSEOP_NOT)
    618           1.1  christos     {
    619           1.1  christos         SourceOp2 = SourceOp1;
    620           1.1  christos     }
    621           1.1  christos 
    622           1.1  christos     /* DIVIDE has an extra target operand (remainder) */
    623           1.1  christos 
    624           1.1  christos     if (Source->Asl.ParseOpcode == PARSEOP_DIVIDE)
    625           1.1  christos     {
    626           1.1  christos         SourceOp2 = SourceOp2->Asl.Next;
    627           1.1  christos     }
    628           1.1  christos 
    629           1.1  christos     TargetOp = SourceOp2->Asl.Next;
    630           1.1  christos 
    631           1.1  christos     /*
    632           1.1  christos      * Can't perform this optimization if there already is a target
    633           1.1  christos      * for the operator (ZERO is a "no target" placeholder).
    634           1.1  christos      */
    635           1.1  christos     if (TargetOp->Asl.ParseOpcode != PARSEOP_ZERO)
    636           1.1  christos     {
    637           1.1  christos         goto CannotOptimize;
    638           1.1  christos     }
    639           1.1  christos 
    640           1.1  christos     /* Link in the target as the final operand */
    641           1.1  christos 
    642           1.1  christos     SourceOp2->Asl.Next = Target;
    643           1.1  christos     Target->Asl.Parent = Source;
    644           1.1  christos     return (Source);
    645           1.1  christos 
    646           1.1  christos 
    647           1.1  christos CannotOptimize:
    648           1.1  christos 
    649           1.1  christos     Operator = TrAllocateOp (PARSEOP_STORE);
    650           1.1  christos     TrLinkOpChildren (Operator, 2, Source, Target);
    651           1.1  christos 
    652           1.1  christos     /* Set the appropriate line numbers for the new op */
    653           1.1  christos 
    654           1.1  christos     Operator->Asl.LineNumber        = Target->Asl.LineNumber;
    655           1.1  christos     Operator->Asl.LogicalLineNumber = Target->Asl.LogicalLineNumber;
    656           1.1  christos     Operator->Asl.LogicalByteOffset = Target->Asl.LogicalByteOffset;
    657           1.1  christos     Operator->Asl.Column            = Target->Asl.Column;
    658           1.1  christos 
    659           1.1  christos     return (Operator);
    660           1.1  christos }
    661           1.1  christos 
    662           1.1  christos 
    663           1.1  christos /*******************************************************************************
    664           1.1  christos  *
    665           1.1  christos  * FUNCTION:    TrCreateNullTargetOp
    666           1.1  christos  *
    667           1.1  christos  * PARAMETERS:  None
    668           1.1  christos  *
    669           1.1  christos  * RETURN:      Pointer to the new op. Aborts on allocation failure
    670           1.1  christos  *
    671           1.1  christos  * DESCRIPTION: Create a "null" target op. This is defined by the ACPI
    672           1.1  christos  *              specification to be a zero AML opcode, and indicates that
    673           1.1  christos  *              no target has been specified for the parent operation
    674           1.1  christos  *
    675           1.1  christos  ******************************************************************************/
    676           1.1  christos 
    677           1.1  christos ACPI_PARSE_OBJECT *
    678           1.1  christos TrCreateNullTargetOp (
    679           1.1  christos     void)
    680           1.1  christos {
    681           1.1  christos     ACPI_PARSE_OBJECT       *Op;
    682           1.1  christos 
    683           1.1  christos 
    684           1.1  christos     Op = TrAllocateOp (PARSEOP_ZERO);
    685           1.1  christos     Op->Asl.CompileFlags |= (OP_IS_TARGET | OP_COMPILE_TIME_CONST);
    686           1.1  christos 
    687           1.1  christos     DbgPrint (ASL_PARSE_OUTPUT,
    688           1.1  christos         "\nCreateNullTargetOp  Ln/Col %u/%u NewOp %p  Op %s\n",
    689           1.1  christos         Op->Asl.LineNumber, Op->Asl.Column, Op,
    690           1.1  christos         UtGetOpName (Op->Asl.ParseOpcode));
    691           1.1  christos 
    692           1.1  christos     return (Op);
    693           1.1  christos }
    694           1.1  christos 
    695           1.1  christos 
    696           1.1  christos /*******************************************************************************
    697           1.1  christos  *
    698           1.1  christos  * FUNCTION:    TrCreateConstantLeafOp
    699           1.1  christos  *
    700           1.1  christos  * PARAMETERS:  ParseOpcode         - The constant opcode
    701           1.1  christos  *
    702           1.1  christos  * RETURN:      Pointer to the new op. Aborts on allocation failure
    703           1.1  christos  *
    704           1.1  christos  * DESCRIPTION: Create a leaf op (no children or peers) for one of the
    705           1.1  christos  *              special constants - __LINE__, __FILE__, and __DATE__.
    706           1.1  christos  *
    707           1.1  christos  * Note: The fullimplemenation of __METHOD__ cannot happen here because we
    708           1.1  christos  * don't have a full parse tree at this time and cannot find the parent
    709           1.1  christos  * control method. __METHOD__ must be implemented later, after the parse
    710           1.1  christos  * tree has been fully constructed.
    711           1.1  christos  *
    712           1.1  christos  ******************************************************************************/
    713           1.1  christos 
    714           1.1  christos ACPI_PARSE_OBJECT *
    715           1.1  christos TrCreateConstantLeafOp (
    716           1.1  christos     UINT32                  ParseOpcode)
    717           1.1  christos {
    718           1.1  christos     ACPI_PARSE_OBJECT       *Op = NULL;
    719           1.1  christos     time_t                  CurrentTime;
    720           1.1  christos     char                    *StaticTimeString;
    721           1.1  christos     char                    *TimeString;
    722       1.1.1.6  christos     char                    *Filename = NULL;
    723       1.1.1.6  christos     ACPI_STATUS             Status;
    724           1.1  christos 
    725           1.1  christos 
    726           1.1  christos     switch (ParseOpcode)
    727           1.1  christos     {
    728           1.1  christos     case PARSEOP___LINE__:
    729           1.1  christos 
    730           1.1  christos         Op = TrAllocateOp (PARSEOP_INTEGER);
    731           1.1  christos         Op->Asl.Value.Integer = Op->Asl.LineNumber;
    732           1.1  christos         break;
    733           1.1  christos 
    734           1.1  christos     case PARSEOP___METHOD__:
    735           1.1  christos 
    736           1.1  christos         /* Will become a string literal later */
    737           1.1  christos 
    738           1.1  christos         Op = TrAllocateOp (PARSEOP___METHOD__);
    739           1.1  christos         Op->Asl.Value.String = NULL;
    740           1.1  christos         break;
    741           1.1  christos 
    742           1.1  christos     case PARSEOP___PATH__:
    743           1.1  christos 
    744           1.1  christos         Op = TrAllocateOp (PARSEOP_STRING_LITERAL);
    745           1.1  christos 
    746           1.1  christos         /* Op.Asl.Filename contains the full pathname to the file */
    747           1.1  christos 
    748           1.1  christos         Op->Asl.Value.String = Op->Asl.Filename;
    749           1.1  christos         break;
    750           1.1  christos 
    751           1.1  christos     case PARSEOP___FILE__:
    752           1.1  christos 
    753           1.1  christos         Op = TrAllocateOp (PARSEOP_STRING_LITERAL);
    754           1.1  christos 
    755           1.1  christos         /* Get the simple filename from the full path */
    756           1.1  christos 
    757       1.1.1.6  christos         Status = FlSplitInputPathname (Op->Asl.Filename, NULL, &Filename);
    758       1.1.1.6  christos         if (ACPI_FAILURE (Status))
    759       1.1.1.6  christos         {
    760       1.1.1.6  christos             return (NULL);
    761       1.1.1.6  christos         }
    762       1.1.1.6  christos 
    763           1.1  christos         Op->Asl.Value.String = Filename;
    764           1.1  christos         break;
    765           1.1  christos 
    766           1.1  christos     case PARSEOP___DATE__:
    767           1.1  christos 
    768           1.1  christos         Op = TrAllocateOp (PARSEOP_STRING_LITERAL);
    769           1.1  christos 
    770           1.1  christos         /* Get a copy of the current time */
    771           1.1  christos 
    772       1.1.1.7  christos         Op->Asl.Value.String = "";
    773           1.1  christos         CurrentTime = time (NULL);
    774       1.1.1.7  christos 
    775           1.1  christos         StaticTimeString = ctime (&CurrentTime);
    776       1.1.1.7  christos         if (StaticTimeString)
    777       1.1.1.7  christos         {
    778       1.1.1.7  christos             TimeString = UtLocalCalloc (strlen (StaticTimeString) + 1);
    779       1.1.1.7  christos             strcpy (TimeString, StaticTimeString);
    780           1.1  christos 
    781       1.1.1.7  christos             TimeString[strlen(TimeString) -1] = 0;  /* Remove trailing newline */
    782       1.1.1.7  christos             Op->Asl.Value.String = TimeString;
    783       1.1.1.7  christos         }
    784           1.1  christos         break;
    785           1.1  christos 
    786           1.1  christos     default: /* This would be an internal error */
    787           1.1  christos 
    788           1.1  christos         return (NULL);
    789           1.1  christos     }
    790           1.1  christos 
    791           1.1  christos     DbgPrint (ASL_PARSE_OUTPUT,
    792           1.1  christos         "\nCreateConstantLeafOp  Ln/Col %u/%u NewOp %p  "
    793  1.1.1.11.6.1  perseant         "Op %s  Value %8.8X%8.8X\n",
    794           1.1  christos         Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName (ParseOpcode),
    795           1.1  christos         ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer));
    796           1.1  christos 
    797           1.1  christos     return (Op);
    798           1.1  christos }
    799           1.1  christos 
    800           1.1  christos 
    801           1.1  christos /*******************************************************************************
    802           1.1  christos  *
    803           1.1  christos  * FUNCTION:    TrAllocateOp
    804           1.1  christos  *
    805           1.1  christos  * PARAMETERS:  ParseOpcode         - Opcode to be assigned to the op
    806           1.1  christos  *
    807           1.1  christos  * RETURN:      New parse op. Aborts on allocation failure
    808           1.1  christos  *
    809           1.1  christos  * DESCRIPTION: Allocate and initialize a new parse op for the parse tree
    810           1.1  christos  *
    811           1.1  christos  ******************************************************************************/
    812           1.1  christos 
    813           1.1  christos ACPI_PARSE_OBJECT *
    814           1.1  christos TrAllocateOp (
    815           1.1  christos     UINT32                  ParseOpcode)
    816           1.1  christos {
    817           1.1  christos     ACPI_PARSE_OBJECT       *Op;
    818           1.1  christos     ACPI_PARSE_OBJECT       *LatestOp;
    819           1.1  christos 
    820      1.1.1.11  christos     ACPI_FUNCTION_NAME (TrAllocateOp);
    821      1.1.1.11  christos 
    822           1.1  christos 
    823       1.1.1.2  christos     Op = UtParseOpCacheCalloc ();
    824           1.1  christos 
    825           1.1  christos     Op->Asl.ParseOpcode       = (UINT16) ParseOpcode;
    826       1.1.1.4  christos     Op->Asl.Filename          = AslGbl_Files[ASL_FILE_INPUT].Filename;
    827       1.1.1.4  christos     Op->Asl.LineNumber        = AslGbl_CurrentLineNumber;
    828       1.1.1.4  christos     Op->Asl.LogicalLineNumber = AslGbl_LogicalLineNumber;
    829       1.1.1.4  christos     Op->Asl.LogicalByteOffset = AslGbl_CurrentLineOffset;
    830       1.1.1.4  christos     Op->Asl.Column            = AslGbl_CurrentColumn;
    831           1.1  christos 
    832           1.1  christos     UtSetParseOpName (Op);
    833           1.1  christos 
    834           1.1  christos     /* The following is for capturing comments */
    835           1.1  christos 
    836       1.1.1.3  christos     if (AcpiGbl_CaptureComments)
    837           1.1  christos     {
    838       1.1.1.4  christos         LatestOp = AslGbl_CommentState.LatestParseOp;
    839           1.1  christos         Op->Asl.InlineComment     = NULL;
    840           1.1  christos         Op->Asl.EndNodeComment    = NULL;
    841           1.1  christos         Op->Asl.CommentList       = NULL;
    842           1.1  christos         Op->Asl.FileChanged       = FALSE;
    843           1.1  christos 
    844           1.1  christos         /*
    845           1.1  christos          * Check to see if the file name has changed before resetting the
    846           1.1  christos          * latest parse op.
    847           1.1  christos          */
    848           1.1  christos         if (LatestOp &&
    849           1.1  christos             (ParseOpcode != PARSEOP_INCLUDE) &&
    850           1.1  christos             (ParseOpcode != PARSEOP_INCLUDE_END) &&
    851           1.1  christos             strcmp (LatestOp->Asl.Filename, Op->Asl.Filename))
    852           1.1  christos         {
    853           1.1  christos             CvDbgPrint ("latest op: %s\n", LatestOp->Asl.ParseOpName);
    854           1.1  christos             Op->Asl.FileChanged = TRUE;
    855       1.1.1.4  christos             if (AslGbl_IncludeFileStack)
    856           1.1  christos             {
    857       1.1.1.4  christos                 Op->Asl.ParentFilename = AslGbl_IncludeFileStack->Filename;
    858           1.1  christos             }
    859           1.1  christos             else
    860           1.1  christos             {
    861           1.1  christos                 Op->Asl.ParentFilename = NULL;
    862           1.1  christos             }
    863           1.1  christos         }
    864           1.1  christos 
    865       1.1.1.4  christos         AslGbl_CommentState.LatestParseOp = Op;
    866      1.1.1.11  christos         CvDbgPrint ("%s=Set latest parse op to this op.\n",  ACPI_GET_FUNCTION_NAME);
    867           1.1  christos         CvDbgPrint ("           Op->Asl.ParseOpName = %s\n",
    868       1.1.1.4  christos             AslGbl_CommentState.LatestParseOp->Asl.ParseOpName);
    869           1.1  christos         CvDbgPrint ("           Op->Asl.ParseOpcode = 0x%x\n", ParseOpcode);
    870           1.1  christos 
    871           1.1  christos         if (Op->Asl.FileChanged)
    872           1.1  christos         {
    873           1.1  christos             CvDbgPrint("    file has been changed!\n");
    874           1.1  christos         }
    875           1.1  christos 
    876           1.1  christos         /*
    877           1.1  christos          * if this parse op's syntax uses () and {} (i.e. Package(1){0x00}) then
    878           1.1  christos          * set a flag in the comment state. This facilitates paring comments for
    879           1.1  christos          * these types of opcodes.
    880           1.1  christos          */
    881           1.1  christos         if ((CvParseOpBlockType(Op) == (BLOCK_PAREN | BLOCK_BRACE)) &&
    882           1.1  christos             (ParseOpcode != PARSEOP_DEFINITION_BLOCK))
    883           1.1  christos         {
    884           1.1  christos             CvDbgPrint ("Parsing paren/Brace op now!\n");
    885       1.1.1.4  christos             AslGbl_CommentState.ParsingParenBraceNode = Op;
    886           1.1  christos         }
    887           1.1  christos 
    888       1.1.1.4  christos         if (AslGbl_CommentListHead)
    889           1.1  christos         {
    890           1.1  christos             CvDbgPrint ("Transferring...\n");
    891       1.1.1.4  christos             Op->Asl.CommentList = AslGbl_CommentListHead;
    892       1.1.1.4  christos             AslGbl_CommentListHead = NULL;
    893       1.1.1.4  christos             AslGbl_CommentListTail = NULL;
    894           1.1  christos             CvDbgPrint ("    Transferred current comment list to this op.\n");
    895           1.1  christos             CvDbgPrint ("    %s\n", Op->Asl.CommentList->Comment);
    896           1.1  christos         }
    897           1.1  christos 
    898       1.1.1.4  christos         if (AslGbl_InlineCommentBuffer)
    899           1.1  christos         {
    900       1.1.1.4  christos             Op->Asl.InlineComment = AslGbl_InlineCommentBuffer;
    901       1.1.1.4  christos             AslGbl_InlineCommentBuffer = NULL;
    902           1.1  christos             CvDbgPrint ("Transferred current inline comment list to this op.\n");
    903           1.1  christos         }
    904           1.1  christos     }
    905           1.1  christos 
    906           1.1  christos     return (Op);
    907           1.1  christos }
    908           1.1  christos 
    909           1.1  christos 
    910           1.1  christos /*******************************************************************************
    911           1.1  christos  *
    912           1.1  christos  * FUNCTION:    TrPrintOpFlags
    913           1.1  christos  *
    914           1.1  christos  * PARAMETERS:  Flags               - Flags word to be decoded
    915           1.1  christos  *              OutputLevel         - Debug output level: ASL_TREE_OUTPUT etc.
    916           1.1  christos  *
    917           1.1  christos  * RETURN:      None
    918           1.1  christos  *
    919           1.1  christos  * DESCRIPTION: Decode a flags word to text. Displays all flags that are set.
    920           1.1  christos  *
    921           1.1  christos  ******************************************************************************/
    922           1.1  christos 
    923           1.1  christos void
    924           1.1  christos TrPrintOpFlags (
    925           1.1  christos     UINT32                  Flags,
    926           1.1  christos     UINT32                  OutputLevel)
    927           1.1  christos {
    928           1.1  christos     UINT32                  FlagBit = 1;
    929           1.1  christos     UINT32                  i;
    930           1.1  christos 
    931           1.1  christos 
    932           1.1  christos     for (i = 0; i < ACPI_NUM_OP_FLAGS; i++)
    933           1.1  christos     {
    934           1.1  christos         if (Flags & FlagBit)
    935           1.1  christos         {
    936       1.1.1.4  christos             DbgPrint (OutputLevel, " %s", AslGbl_OpFlagNames[i]);
    937           1.1  christos         }
    938           1.1  christos 
    939           1.1  christos         FlagBit <<= 1;
    940           1.1  christos     }
    941           1.1  christos }
    942