Home | History | Annotate | Line # | Download | only in compiler
cvparser.c revision 1.1.1.11.6.1
      1           1.1  christos /******************************************************************************
      2           1.1  christos  *
      3           1.1  christos  * Module Name: cvparser - Converter functions that are called from the AML
      4           1.1  christos  *                         parser.
      5           1.1  christos  *
      6           1.1  christos  *****************************************************************************/
      7           1.1  christos 
      8  1.1.1.11.6.1  perseant /******************************************************************************
      9  1.1.1.11.6.1  perseant  *
     10  1.1.1.11.6.1  perseant  * 1. Copyright Notice
     11  1.1.1.11.6.1  perseant  *
     12  1.1.1.11.6.1  perseant  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
     13           1.1  christos  * All rights reserved.
     14           1.1  christos  *
     15  1.1.1.11.6.1  perseant  * 2. License
     16  1.1.1.11.6.1  perseant  *
     17  1.1.1.11.6.1  perseant  * 2.1. This is your license from Intel Corp. under its intellectual property
     18  1.1.1.11.6.1  perseant  * rights. You may have additional license terms from the party that provided
     19  1.1.1.11.6.1  perseant  * you this software, covering your right to use that party's intellectual
     20  1.1.1.11.6.1  perseant  * property rights.
     21  1.1.1.11.6.1  perseant  *
     22  1.1.1.11.6.1  perseant  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     23  1.1.1.11.6.1  perseant  * copy of the source code appearing in this file ("Covered Code") an
     24  1.1.1.11.6.1  perseant  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     25  1.1.1.11.6.1  perseant  * base code distributed originally by Intel ("Original Intel Code") to copy,
     26  1.1.1.11.6.1  perseant  * make derivatives, distribute, use and display any portion of the Covered
     27  1.1.1.11.6.1  perseant  * Code in any form, with the right to sublicense such rights; and
     28  1.1.1.11.6.1  perseant  *
     29  1.1.1.11.6.1  perseant  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     30  1.1.1.11.6.1  perseant  * license (with the right to sublicense), under only those claims of Intel
     31  1.1.1.11.6.1  perseant  * patents that are infringed by the Original Intel Code, to make, use, sell,
     32  1.1.1.11.6.1  perseant  * offer to sell, and import the Covered Code and derivative works thereof
     33  1.1.1.11.6.1  perseant  * solely to the minimum extent necessary to exercise the above copyright
     34  1.1.1.11.6.1  perseant  * license, and in no event shall the patent license extend to any additions
     35  1.1.1.11.6.1  perseant  * to or modifications of the Original Intel Code. No other license or right
     36  1.1.1.11.6.1  perseant  * is granted directly or by implication, estoppel or otherwise;
     37  1.1.1.11.6.1  perseant  *
     38  1.1.1.11.6.1  perseant  * The above copyright and patent license is granted only if the following
     39  1.1.1.11.6.1  perseant  * conditions are met:
     40  1.1.1.11.6.1  perseant  *
     41  1.1.1.11.6.1  perseant  * 3. Conditions
     42  1.1.1.11.6.1  perseant  *
     43  1.1.1.11.6.1  perseant  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     44  1.1.1.11.6.1  perseant  * Redistribution of source code of any substantial portion of the Covered
     45  1.1.1.11.6.1  perseant  * Code or modification with rights to further distribute source must include
     46  1.1.1.11.6.1  perseant  * the above Copyright Notice, the above License, this list of Conditions,
     47  1.1.1.11.6.1  perseant  * and the following Disclaimer and Export Compliance provision. In addition,
     48  1.1.1.11.6.1  perseant  * Licensee must cause all Covered Code to which Licensee contributes to
     49  1.1.1.11.6.1  perseant  * contain a file documenting the changes Licensee made to create that Covered
     50  1.1.1.11.6.1  perseant  * Code and the date of any change. Licensee must include in that file the
     51  1.1.1.11.6.1  perseant  * documentation of any changes made by any predecessor Licensee. Licensee
     52  1.1.1.11.6.1  perseant  * must include a prominent statement that the modification is derived,
     53  1.1.1.11.6.1  perseant  * directly or indirectly, from Original Intel Code.
     54  1.1.1.11.6.1  perseant  *
     55  1.1.1.11.6.1  perseant  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     56  1.1.1.11.6.1  perseant  * Redistribution of source code of any substantial portion of the Covered
     57  1.1.1.11.6.1  perseant  * Code or modification without rights to further distribute source must
     58  1.1.1.11.6.1  perseant  * include the following Disclaimer and Export Compliance provision in the
     59  1.1.1.11.6.1  perseant  * documentation and/or other materials provided with distribution. In
     60  1.1.1.11.6.1  perseant  * addition, Licensee may not authorize further sublicense of source of any
     61  1.1.1.11.6.1  perseant  * portion of the Covered Code, and must include terms to the effect that the
     62  1.1.1.11.6.1  perseant  * license from Licensee to its licensee is limited to the intellectual
     63  1.1.1.11.6.1  perseant  * property embodied in the software Licensee provides to its licensee, and
     64  1.1.1.11.6.1  perseant  * not to intellectual property embodied in modifications its licensee may
     65  1.1.1.11.6.1  perseant  * make.
     66  1.1.1.11.6.1  perseant  *
     67  1.1.1.11.6.1  perseant  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     68  1.1.1.11.6.1  perseant  * substantial portion of the Covered Code or modification must reproduce the
     69  1.1.1.11.6.1  perseant  * above Copyright Notice, and the following Disclaimer and Export Compliance
     70  1.1.1.11.6.1  perseant  * provision in the documentation and/or other materials provided with the
     71  1.1.1.11.6.1  perseant  * distribution.
     72  1.1.1.11.6.1  perseant  *
     73  1.1.1.11.6.1  perseant  * 3.4. Intel retains all right, title, and interest in and to the Original
     74  1.1.1.11.6.1  perseant  * Intel Code.
     75  1.1.1.11.6.1  perseant  *
     76  1.1.1.11.6.1  perseant  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     77  1.1.1.11.6.1  perseant  * Intel shall be used in advertising or otherwise to promote the sale, use or
     78  1.1.1.11.6.1  perseant  * other dealings in products derived from or relating to the Covered Code
     79  1.1.1.11.6.1  perseant  * without prior written authorization from Intel.
     80  1.1.1.11.6.1  perseant  *
     81  1.1.1.11.6.1  perseant  * 4. Disclaimer and Export Compliance
     82  1.1.1.11.6.1  perseant  *
     83  1.1.1.11.6.1  perseant  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     84  1.1.1.11.6.1  perseant  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     85  1.1.1.11.6.1  perseant  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
     86  1.1.1.11.6.1  perseant  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
     87  1.1.1.11.6.1  perseant  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
     88  1.1.1.11.6.1  perseant  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     89  1.1.1.11.6.1  perseant  * PARTICULAR PURPOSE.
     90  1.1.1.11.6.1  perseant  *
     91  1.1.1.11.6.1  perseant  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     92  1.1.1.11.6.1  perseant  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     93  1.1.1.11.6.1  perseant  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     94  1.1.1.11.6.1  perseant  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     95  1.1.1.11.6.1  perseant  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     96  1.1.1.11.6.1  perseant  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
     97  1.1.1.11.6.1  perseant  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     98  1.1.1.11.6.1  perseant  * LIMITED REMEDY.
     99  1.1.1.11.6.1  perseant  *
    100  1.1.1.11.6.1  perseant  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    101  1.1.1.11.6.1  perseant  * software or system incorporating such software without first obtaining any
    102  1.1.1.11.6.1  perseant  * required license or other approval from the U. S. Department of Commerce or
    103  1.1.1.11.6.1  perseant  * any other agency or department of the United States Government. In the
    104  1.1.1.11.6.1  perseant  * event Licensee exports any such software from the United States or
    105  1.1.1.11.6.1  perseant  * re-exports any such software from a foreign destination, Licensee shall
    106  1.1.1.11.6.1  perseant  * ensure that the distribution and export/re-export of the software is in
    107  1.1.1.11.6.1  perseant  * compliance with all laws, regulations, orders, or other restrictions of the
    108  1.1.1.11.6.1  perseant  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    109  1.1.1.11.6.1  perseant  * any of its subsidiaries will export/re-export any technical data, process,
    110  1.1.1.11.6.1  perseant  * software, or service, directly or indirectly, to any country for which the
    111  1.1.1.11.6.1  perseant  * United States government or any agency thereof requires an export license,
    112  1.1.1.11.6.1  perseant  * other governmental approval, or letter of assurance, without first obtaining
    113  1.1.1.11.6.1  perseant  * such license, approval or letter.
    114  1.1.1.11.6.1  perseant  *
    115  1.1.1.11.6.1  perseant  *****************************************************************************
    116  1.1.1.11.6.1  perseant  *
    117  1.1.1.11.6.1  perseant  * Alternatively, you may choose to be licensed under the terms of the
    118  1.1.1.11.6.1  perseant  * following license:
    119  1.1.1.11.6.1  perseant  *
    120           1.1  christos  * Redistribution and use in source and binary forms, with or without
    121           1.1  christos  * modification, are permitted provided that the following conditions
    122           1.1  christos  * are met:
    123           1.1  christos  * 1. Redistributions of source code must retain the above copyright
    124           1.1  christos  *    notice, this list of conditions, and the following disclaimer,
    125           1.1  christos  *    without modification.
    126           1.1  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
    127           1.1  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
    128           1.1  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
    129           1.1  christos  *    including a substantially similar Disclaimer requirement for further
    130           1.1  christos  *    binary redistribution.
    131           1.1  christos  * 3. Neither the names of the above-listed copyright holders nor the names
    132           1.1  christos  *    of any contributors may be used to endorse or promote products derived
    133           1.1  christos  *    from this software without specific prior written permission.
    134           1.1  christos  *
    135           1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    136           1.1  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    137       1.1.1.9  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    138           1.1  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    139  1.1.1.11.6.1  perseant  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    140  1.1.1.11.6.1  perseant  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    141  1.1.1.11.6.1  perseant  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    142  1.1.1.11.6.1  perseant  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    143  1.1.1.11.6.1  perseant  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    144  1.1.1.11.6.1  perseant  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    145  1.1.1.11.6.1  perseant  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    146  1.1.1.11.6.1  perseant  *
    147  1.1.1.11.6.1  perseant  * Alternatively, you may choose to be licensed under the terms of the
    148  1.1.1.11.6.1  perseant  * GNU General Public License ("GPL") version 2 as published by the Free
    149  1.1.1.11.6.1  perseant  * Software Foundation.
    150  1.1.1.11.6.1  perseant  *
    151  1.1.1.11.6.1  perseant  *****************************************************************************/
    152           1.1  christos 
    153           1.1  christos #include "aslcompiler.h"
    154           1.1  christos #include "acparser.h"
    155           1.1  christos #include "acdispat.h"
    156           1.1  christos #include "amlcode.h"
    157           1.1  christos #include "acinterp.h"
    158           1.1  christos #include "acdisasm.h"
    159           1.1  christos #include "acconvert.h"
    160           1.1  christos 
    161           1.1  christos 
    162           1.1  christos /* local prototypes */
    163           1.1  christos 
    164           1.1  christos static BOOLEAN
    165           1.1  christos CvCommentExists (
    166           1.1  christos     UINT8                   *Address);
    167           1.1  christos 
    168           1.1  christos static BOOLEAN
    169           1.1  christos CvIsFilename (
    170           1.1  christos     char                   *Filename);
    171           1.1  christos 
    172           1.1  christos static ACPI_FILE_NODE*
    173           1.1  christos CvFileAddressLookup(
    174           1.1  christos     char                    *Address,
    175           1.1  christos     ACPI_FILE_NODE          *Head);
    176           1.1  christos 
    177           1.1  christos static void
    178           1.1  christos CvAddToFileTree (
    179           1.1  christos     char                    *Filename,
    180           1.1  christos     char                    *PreviousFilename);
    181           1.1  christos 
    182           1.1  christos static void
    183           1.1  christos CvSetFileParent (
    184           1.1  christos     char                    *ChildFile,
    185           1.1  christos     char                    *ParentFile);
    186           1.1  christos 
    187           1.1  christos 
    188           1.1  christos /*******************************************************************************
    189           1.1  christos  *
    190           1.1  christos  * FUNCTION:    CvIsFilename
    191           1.1  christos  *
    192           1.1  christos  * PARAMETERS:  filename - input filename
    193           1.1  christos  *
    194           1.1  christos  * RETURN:      BOOLEAN - TRUE if all characters are between 0x20 and 0x7f
    195           1.1  christos  *
    196           1.1  christos  * DESCRIPTION: Take a given char * and see if it contains all printable
    197           1.1  christos  *              characters. If all characters have hexvalues 20-7f and ends with
    198           1.1  christos  *              .dsl, we will assume that it is a proper filename.
    199           1.1  christos  *
    200           1.1  christos  ******************************************************************************/
    201           1.1  christos 
    202           1.1  christos static BOOLEAN
    203           1.1  christos CvIsFilename (
    204           1.1  christos     char                    *Filename)
    205           1.1  christos {
    206           1.1  christos     UINT64                  Length = strlen(Filename);
    207           1.1  christos     char                    *FileExt = Filename + Length - 4;
    208       1.1.1.2  christos     UINT64                  i;
    209           1.1  christos 
    210           1.1  christos 
    211           1.1  christos     if ((Length > 4) && AcpiUtStricmp (FileExt, ".dsl"))
    212           1.1  christos     {
    213       1.1.1.2  christos         return (FALSE);
    214           1.1  christos     }
    215           1.1  christos 
    216           1.1  christos     for(i = 0; i<Length; ++i)
    217           1.1  christos     {
    218       1.1.1.2  christos         if (!isprint ((int) Filename[i]))
    219           1.1  christos         {
    220       1.1.1.2  christos             return (FALSE);
    221           1.1  christos         }
    222           1.1  christos     }
    223       1.1.1.2  christos 
    224       1.1.1.2  christos     return (TRUE);
    225           1.1  christos }
    226           1.1  christos 
    227           1.1  christos 
    228           1.1  christos /*******************************************************************************
    229           1.1  christos  *
    230           1.1  christos  * FUNCTION:    CvInitFileTree
    231           1.1  christos  *
    232           1.1  christos  * PARAMETERS:  Table      - input table
    233       1.1.1.8  christos  *              RootFile   - Output file that defines the DefinitionBlock
    234           1.1  christos  *
    235       1.1.1.2  christos  * RETURN:      None
    236           1.1  christos  *
    237           1.1  christos  * DESCRIPTION: Initialize the file dependency tree by scanning the AML.
    238           1.1  christos  *              This is referred as ASL_CV_INIT_FILETREE.
    239           1.1  christos  *
    240           1.1  christos  ******************************************************************************/
    241           1.1  christos 
    242           1.1  christos void
    243           1.1  christos CvInitFileTree (
    244           1.1  christos     ACPI_TABLE_HEADER       *Table,
    245       1.1.1.8  christos     FILE                    *RootFile)
    246           1.1  christos {
    247           1.1  christos     UINT8                   *TreeAml;
    248           1.1  christos     UINT8                   *FileEnd;
    249           1.1  christos     char                    *Filename = NULL;
    250           1.1  christos     char                    *PreviousFilename = NULL;
    251           1.1  christos     char                    *ParentFilename = NULL;
    252           1.1  christos     char                    *ChildFilename = NULL;
    253       1.1.1.8  christos     UINT8                   *AmlStart;
    254       1.1.1.8  christos     UINT32                  AmlLength;
    255           1.1  christos 
    256           1.1  christos 
    257       1.1.1.4  christos     if (!AcpiGbl_CaptureComments)
    258           1.1  christos     {
    259           1.1  christos         return;
    260           1.1  christos     }
    261           1.1  christos 
    262       1.1.1.8  christos 
    263       1.1.1.8  christos     AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
    264       1.1.1.8  christos     AmlStart = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER));
    265       1.1.1.8  christos 
    266           1.1  christos     CvDbgPrint ("AmlLength: %x\n", AmlLength);
    267           1.1  christos     CvDbgPrint ("AmlStart:  %p\n", AmlStart);
    268       1.1.1.8  christos     CvDbgPrint ("AmlEnd:    %p\n", AmlStart+AmlLength);
    269           1.1  christos 
    270           1.1  christos     AcpiGbl_FileTreeRoot = AcpiOsAcquireObject (AcpiGbl_FileCache);
    271       1.1.1.2  christos 
    272           1.1  christos     AcpiGbl_FileTreeRoot->FileStart = (char *)(AmlStart);
    273           1.1  christos     AcpiGbl_FileTreeRoot->FileEnd = (char *)(AmlStart + Table->Length);
    274           1.1  christos     AcpiGbl_FileTreeRoot->Next = NULL;
    275           1.1  christos     AcpiGbl_FileTreeRoot->Parent = NULL;
    276           1.1  christos     AcpiGbl_FileTreeRoot->Filename = (char *)(AmlStart+2);
    277           1.1  christos 
    278           1.1  christos     /* Set the root file to the current open file */
    279           1.1  christos 
    280       1.1.1.8  christos     AcpiGbl_FileTreeRoot->File = RootFile;
    281           1.1  christos 
    282           1.1  christos     /*
    283       1.1.1.6  christos      * Set this to true because we don't need to output
    284           1.1  christos      * an include statement for the topmost file
    285           1.1  christos      */
    286           1.1  christos     AcpiGbl_FileTreeRoot->IncludeWritten = TRUE;
    287           1.1  christos     Filename = NULL;
    288           1.1  christos     AcpiGbl_CurrentFilename = (char *)(AmlStart+2);
    289           1.1  christos     AcpiGbl_RootFilename    = (char *)(AmlStart+2);
    290           1.1  christos 
    291           1.1  christos     TreeAml = AmlStart;
    292           1.1  christos     FileEnd = AmlStart + AmlLength;
    293           1.1  christos 
    294           1.1  christos     while (TreeAml <= FileEnd)
    295           1.1  christos     {
    296           1.1  christos         /*
    297           1.1  christos          * Make sure that this filename contains all printable characters
    298           1.1  christos          * and a .dsl extension at the end. If not, then it must be some
    299           1.1  christos          * raw data that doesn't outline a filename.
    300           1.1  christos          */
    301           1.1  christos         if ((*TreeAml == AML_COMMENT_OP) &&
    302       1.1.1.2  christos             (*(TreeAml +1) == FILENAME_COMMENT) &&
    303       1.1.1.2  christos             (CvIsFilename ((char *)(TreeAml +2))))
    304           1.1  christos         {
    305           1.1  christos             CvDbgPrint ("A9 and a 08 file\n");
    306           1.1  christos             PreviousFilename = Filename;
    307       1.1.1.2  christos             Filename = (char *) (TreeAml +2);
    308       1.1.1.2  christos 
    309           1.1  christos             CvAddToFileTree (Filename, PreviousFilename);
    310           1.1  christos             ChildFilename = Filename;
    311           1.1  christos             CvDbgPrint ("%s\n", Filename);
    312           1.1  christos         }
    313           1.1  christos         else if ((*TreeAml == AML_COMMENT_OP) &&
    314       1.1.1.2  christos             (*(TreeAml +1) == PARENTFILENAME_COMMENT) &&
    315       1.1.1.2  christos             (CvIsFilename ((char *)(TreeAml +2))))
    316           1.1  christos         {
    317           1.1  christos             CvDbgPrint ("A9 and a 09 file\n");
    318       1.1.1.2  christos             ParentFilename = (char *)(TreeAml +2);
    319           1.1  christos             CvSetFileParent (ChildFilename, ParentFilename);
    320           1.1  christos             CvDbgPrint ("%s\n", ParentFilename);
    321           1.1  christos         }
    322       1.1.1.2  christos 
    323           1.1  christos         ++TreeAml;
    324           1.1  christos     }
    325           1.1  christos }
    326           1.1  christos 
    327           1.1  christos 
    328           1.1  christos /*******************************************************************************
    329           1.1  christos  *
    330           1.1  christos  * FUNCTION:    CvClearOpComments
    331           1.1  christos  *
    332           1.1  christos  * PARAMETERS:  Op -- clear all comments within this Op
    333           1.1  christos  *
    334       1.1.1.2  christos  * RETURN:      None
    335           1.1  christos  *
    336           1.1  christos  * DESCRIPTION: Clear all converter-related fields of the given Op.
    337           1.1  christos  *              This is referred as ASL_CV_CLEAR_OP_COMMENTS.
    338           1.1  christos  *
    339           1.1  christos  ******************************************************************************/
    340           1.1  christos 
    341           1.1  christos void
    342           1.1  christos CvClearOpComments (
    343           1.1  christos     ACPI_PARSE_OBJECT       *Op)
    344           1.1  christos {
    345       1.1.1.2  christos 
    346           1.1  christos     Op->Common.InlineComment     = NULL;
    347           1.1  christos     Op->Common.EndNodeComment    = NULL;
    348           1.1  christos     Op->Common.NameComment       = NULL;
    349           1.1  christos     Op->Common.CommentList       = NULL;
    350           1.1  christos     Op->Common.EndBlkComment     = NULL;
    351           1.1  christos     Op->Common.CloseBraceComment = NULL;
    352           1.1  christos     Op->Common.CvFilename        = NULL;
    353           1.1  christos     Op->Common.CvParentFilename  = NULL;
    354           1.1  christos }
    355           1.1  christos 
    356           1.1  christos 
    357           1.1  christos /*******************************************************************************
    358           1.1  christos  *
    359           1.1  christos  * FUNCTION:    CvCommentExists
    360           1.1  christos  *
    361       1.1.1.2  christos  * PARAMETERS:  Address - check if this address appears in the list
    362           1.1  christos  *
    363           1.1  christos  * RETURN:      BOOLEAN - TRUE if the address exists.
    364           1.1  christos  *
    365       1.1.1.2  christos  * DESCRIPTION: Look at the pointer address and check if this appears in the
    366       1.1.1.2  christos  *              list of all addresses. If it exists in the list, return TRUE
    367           1.1  christos  *              if it exists. Otherwise add to the list and return FALSE.
    368           1.1  christos  *
    369           1.1  christos  ******************************************************************************/
    370           1.1  christos 
    371           1.1  christos static BOOLEAN
    372           1.1  christos CvCommentExists (
    373           1.1  christos     UINT8                    *Address)
    374           1.1  christos {
    375           1.1  christos     ACPI_COMMENT_ADDR_NODE   *Current = AcpiGbl_CommentAddrListHead;
    376           1.1  christos     UINT8                    Option;
    377           1.1  christos 
    378           1.1  christos 
    379           1.1  christos     if (!Address)
    380           1.1  christos     {
    381           1.1  christos         return (FALSE);
    382           1.1  christos     }
    383       1.1.1.2  christos 
    384           1.1  christos     Option = *(Address + 1);
    385           1.1  christos 
    386           1.1  christos     /*
    387       1.1.1.2  christos      * FILENAME_COMMENT and PARENTFILENAME_COMMENT are not treated as
    388       1.1.1.2  christos      * comments. They serve as markers for where the file starts and ends.
    389           1.1  christos      */
    390       1.1.1.2  christos     if ((Option == FILENAME_COMMENT) ||
    391       1.1.1.2  christos         (Option == PARENTFILENAME_COMMENT))
    392           1.1  christos     {
    393           1.1  christos        return (FALSE);
    394           1.1  christos     }
    395           1.1  christos 
    396           1.1  christos     if (!Current)
    397           1.1  christos     {
    398           1.1  christos         AcpiGbl_CommentAddrListHead =
    399           1.1  christos             AcpiOsAcquireObject (AcpiGbl_RegCommentCache);
    400           1.1  christos         AcpiGbl_CommentAddrListHead->Addr = Address;
    401           1.1  christos         AcpiGbl_CommentAddrListHead->Next = NULL;
    402           1.1  christos         return (FALSE);
    403           1.1  christos     }
    404           1.1  christos     else
    405           1.1  christos     {
    406           1.1  christos         while (Current)
    407           1.1  christos         {
    408           1.1  christos             if (Current->Addr != Address)
    409           1.1  christos             {
    410           1.1  christos                 Current = Current->Next;
    411           1.1  christos             }
    412           1.1  christos             else
    413           1.1  christos             {
    414           1.1  christos                 return (TRUE);
    415           1.1  christos             }
    416           1.1  christos         }
    417           1.1  christos 
    418           1.1  christos         /*
    419       1.1.1.2  christos          * If the execution gets to this point, it means that this
    420       1.1.1.2  christos          * address does not exists in the list. Add this address to the
    421           1.1  christos          * beginning of the list.
    422           1.1  christos          */
    423           1.1  christos         Current = AcpiGbl_CommentAddrListHead;
    424           1.1  christos         AcpiGbl_CommentAddrListHead =
    425           1.1  christos             AcpiOsAcquireObject (AcpiGbl_RegCommentCache);
    426       1.1.1.2  christos 
    427           1.1  christos         AcpiGbl_CommentAddrListHead->Addr = Address;
    428           1.1  christos         AcpiGbl_CommentAddrListHead->Next = Current;
    429           1.1  christos         return (FALSE);
    430           1.1  christos     }
    431           1.1  christos }
    432           1.1  christos 
    433           1.1  christos 
    434           1.1  christos /*******************************************************************************
    435           1.1  christos  *
    436           1.1  christos  * FUNCTION:    CvFilenameExists
    437           1.1  christos  *
    438           1.1  christos  * PARAMETERS:  Filename        - filename to search
    439           1.1  christos  *
    440           1.1  christos  * RETURN:      ACPI_FILE_NODE - a pointer to a file node
    441           1.1  christos  *
    442           1.1  christos  * DESCRIPTION: Look for the given filename in the file dependency tree.
    443           1.1  christos  *              Returns the file node if it exists, returns NULL if it does not.
    444           1.1  christos  *
    445           1.1  christos  ******************************************************************************/
    446           1.1  christos 
    447           1.1  christos ACPI_FILE_NODE*
    448           1.1  christos CvFilenameExists(
    449           1.1  christos     char                    *Filename,
    450           1.1  christos     ACPI_FILE_NODE          *Head)
    451           1.1  christos {
    452           1.1  christos     ACPI_FILE_NODE          *Current = Head;
    453           1.1  christos 
    454           1.1  christos 
    455       1.1.1.2  christos     if (!Filename)
    456       1.1.1.2  christos     {
    457       1.1.1.2  christos         return (NULL);
    458       1.1.1.2  christos     }
    459       1.1.1.2  christos 
    460           1.1  christos     while (Current)
    461           1.1  christos     {
    462           1.1  christos         if (!AcpiUtStricmp (Current->Filename, Filename))
    463           1.1  christos         {
    464           1.1  christos             return (Current);
    465           1.1  christos         }
    466       1.1.1.2  christos 
    467           1.1  christos         Current = Current->Next;
    468           1.1  christos     }
    469           1.1  christos     return (NULL);
    470           1.1  christos }
    471           1.1  christos 
    472           1.1  christos 
    473           1.1  christos /*******************************************************************************
    474           1.1  christos  *
    475           1.1  christos  * FUNCTION:    CvFileAddressLookup
    476           1.1  christos  *
    477           1.1  christos  * PARAMETERS:  Address        - address to look up
    478           1.1  christos  *              Head           - file dependency tree
    479           1.1  christos  *
    480       1.1.1.2  christos  * RETURN:      ACPI_FILE_NODE - pointer to a file node containing the address
    481           1.1  christos  *
    482           1.1  christos  * DESCRIPTION: Look for the given address in the file dependency tree.
    483           1.1  christos  *              Returns the first file node where the given address is within
    484           1.1  christos  *              the file node's starting and ending address.
    485           1.1  christos  *
    486           1.1  christos  ******************************************************************************/
    487           1.1  christos 
    488       1.1.1.2  christos static ACPI_FILE_NODE *
    489           1.1  christos CvFileAddressLookup(
    490           1.1  christos     char                    *Address,
    491           1.1  christos     ACPI_FILE_NODE          *Head)
    492           1.1  christos {
    493           1.1  christos     ACPI_FILE_NODE          *Current = Head;
    494           1.1  christos 
    495           1.1  christos 
    496           1.1  christos     while (Current)
    497           1.1  christos     {
    498           1.1  christos         if ((Address >= Current->FileStart) &&
    499           1.1  christos             (Address < Current->FileEnd ||
    500           1.1  christos             !Current->FileEnd))
    501           1.1  christos         {
    502           1.1  christos             return (Current);
    503           1.1  christos         }
    504       1.1.1.2  christos 
    505           1.1  christos         Current = Current->Next;
    506           1.1  christos     }
    507           1.1  christos 
    508           1.1  christos     return (NULL);
    509           1.1  christos }
    510           1.1  christos 
    511           1.1  christos 
    512           1.1  christos /*******************************************************************************
    513           1.1  christos  *
    514           1.1  christos  * FUNCTION:    CvLabelFileNode
    515           1.1  christos  *
    516           1.1  christos  * PARAMETERS:  Op
    517           1.1  christos  *
    518           1.1  christos  * RETURN:      None
    519           1.1  christos  *
    520           1.1  christos  * DESCRIPTION: Takes a given parse op, looks up its Op->Common.Aml field
    521       1.1.1.6  christos  *              within the file tree and fills in appropriate file information
    522           1.1  christos  *              from a matching node within the tree.
    523           1.1  christos  *              This is referred as ASL_CV_LABEL_FILENODE.
    524           1.1  christos  *
    525           1.1  christos  ******************************************************************************/
    526           1.1  christos 
    527           1.1  christos void
    528           1.1  christos CvLabelFileNode(
    529           1.1  christos     ACPI_PARSE_OBJECT       *Op)
    530           1.1  christos {
    531           1.1  christos     ACPI_FILE_NODE          *Node;
    532           1.1  christos 
    533           1.1  christos 
    534           1.1  christos     if (!Op)
    535           1.1  christos     {
    536           1.1  christos         return;
    537           1.1  christos     }
    538           1.1  christos 
    539       1.1.1.2  christos     Node = CvFileAddressLookup ((char *)
    540       1.1.1.2  christos         Op->Common.Aml, AcpiGbl_FileTreeRoot);
    541           1.1  christos     if (!Node)
    542           1.1  christos     {
    543           1.1  christos        return;
    544           1.1  christos     }
    545           1.1  christos 
    546           1.1  christos     Op->Common.CvFilename = Node->Filename;
    547           1.1  christos     if (Node->Parent)
    548           1.1  christos     {
    549           1.1  christos         Op->Common.CvParentFilename = Node->Parent->Filename;
    550           1.1  christos     }
    551           1.1  christos     else
    552           1.1  christos     {
    553           1.1  christos         Op->Common.CvParentFilename = Node->Filename;
    554           1.1  christos     }
    555           1.1  christos }
    556           1.1  christos 
    557           1.1  christos 
    558           1.1  christos /*******************************************************************************
    559           1.1  christos  *
    560           1.1  christos  * FUNCTION:    CvAddToFileTree
    561           1.1  christos  *
    562           1.1  christos  * PARAMETERS:  Filename          - Address containing the name of the current
    563           1.1  christos  *                                  filename
    564           1.1  christos  *              PreviousFilename  - Address containing the name of the previous
    565           1.1  christos  *                                  filename
    566           1.1  christos  *
    567       1.1.1.2  christos  * RETURN:      None
    568           1.1  christos  *
    569           1.1  christos  * DESCRIPTION: Add this filename to the AcpiGbl_FileTree if it does not exist.
    570           1.1  christos  *
    571           1.1  christos  ******************************************************************************/
    572           1.1  christos 
    573           1.1  christos static void
    574           1.1  christos CvAddToFileTree (
    575           1.1  christos     char                    *Filename,
    576           1.1  christos     char                    *PreviousFilename)
    577           1.1  christos {
    578           1.1  christos     ACPI_FILE_NODE          *Node;
    579           1.1  christos 
    580           1.1  christos 
    581           1.1  christos     if (!AcpiUtStricmp(Filename, AcpiGbl_RootFilename) &&
    582           1.1  christos         PreviousFilename)
    583           1.1  christos     {
    584           1.1  christos         Node = CvFilenameExists (PreviousFilename, AcpiGbl_FileTreeRoot);
    585           1.1  christos         if (Node)
    586           1.1  christos         {
    587           1.1  christos             /*
    588           1.1  christos              * Set the end point of the PreviousFilename to the address
    589           1.1  christos              * of Filename.
    590           1.1  christos              */
    591           1.1  christos             Node->FileEnd = Filename;
    592           1.1  christos         }
    593           1.1  christos     }
    594           1.1  christos     else if (!AcpiUtStricmp(Filename, AcpiGbl_RootFilename) &&
    595           1.1  christos              !PreviousFilename)
    596           1.1  christos     {
    597           1.1  christos         return;
    598           1.1  christos     }
    599           1.1  christos 
    600           1.1  christos     Node = CvFilenameExists (Filename, AcpiGbl_FileTreeRoot);
    601           1.1  christos     if (Node && PreviousFilename)
    602           1.1  christos     {
    603           1.1  christos         /*
    604       1.1.1.2  christos          * Update the end of the previous file and all of their parents'
    605       1.1.1.2  christos          * ending addresses. This is done to ensure that parent file
    606       1.1.1.2  christos          * ranges extend to the end of their childrens' files.
    607           1.1  christos          */
    608           1.1  christos         Node = CvFilenameExists (PreviousFilename, AcpiGbl_FileTreeRoot);
    609           1.1  christos         if (Node && (Node->FileEnd < Filename))
    610           1.1  christos         {
    611           1.1  christos             Node->FileEnd = Filename;
    612           1.1  christos             Node = Node->Parent;
    613           1.1  christos             while (Node)
    614           1.1  christos             {
    615           1.1  christos                 if (Node->FileEnd < Filename)
    616           1.1  christos                 {
    617           1.1  christos                     Node->FileEnd = Filename;
    618           1.1  christos                 }
    619       1.1.1.2  christos 
    620           1.1  christos                 Node = Node->Parent;
    621           1.1  christos             }
    622           1.1  christos         }
    623           1.1  christos     }
    624           1.1  christos     else
    625           1.1  christos     {
    626           1.1  christos         Node = AcpiGbl_FileTreeRoot;
    627           1.1  christos         AcpiGbl_FileTreeRoot = AcpiOsAcquireObject (AcpiGbl_FileCache);
    628       1.1.1.2  christos 
    629           1.1  christos         AcpiGbl_FileTreeRoot->Next = Node;
    630           1.1  christos         AcpiGbl_FileTreeRoot->Parent = NULL;
    631           1.1  christos         AcpiGbl_FileTreeRoot->Filename = Filename;
    632           1.1  christos         AcpiGbl_FileTreeRoot->FileStart = Filename;
    633           1.1  christos         AcpiGbl_FileTreeRoot->IncludeWritten = FALSE;
    634           1.1  christos         AcpiGbl_FileTreeRoot->File = fopen(Filename, "w+");
    635           1.1  christos 
    636           1.1  christos         /*
    637           1.1  christos          * If we can't open the file, we need to abort here before we
    638           1.1  christos          * accidentally write to a NULL file.
    639           1.1  christos          */
    640           1.1  christos         if (!AcpiGbl_FileTreeRoot->File)
    641           1.1  christos         {
    642           1.1  christos             /* delete the .xxx file */
    643           1.1  christos 
    644           1.1  christos             FlDeleteFile (ASL_FILE_AML_OUTPUT);
    645       1.1.1.5  christos             sprintf (AslGbl_MsgBuffer, "\"%s\" - %s", Filename, strerror (errno));
    646       1.1.1.2  christos             AslCommonError (ASL_ERROR, ASL_MSG_OPEN, 0, 0, 0, 0,
    647       1.1.1.5  christos                 NULL, AslGbl_MsgBuffer);
    648           1.1  christos             AslAbort ();
    649           1.1  christos         }
    650           1.1  christos     }
    651           1.1  christos }
    652           1.1  christos 
    653           1.1  christos 
    654           1.1  christos /*******************************************************************************
    655           1.1  christos  *
    656           1.1  christos  * FUNCTION:    CvSetFileParent
    657           1.1  christos  *
    658           1.1  christos  * PARAMETERS:  ChildFile  - contains the filename of the child file
    659           1.1  christos  *              ParentFile - contains the filename of the parent file.
    660           1.1  christos  *
    661       1.1.1.2  christos  * RETURN:      None
    662           1.1  christos  *
    663       1.1.1.2  christos  * DESCRIPTION: Point the parent pointer of the Child to the node that
    664           1.1  christos  *              corresponds with the parent file node.
    665           1.1  christos  *
    666           1.1  christos  ******************************************************************************/
    667           1.1  christos 
    668           1.1  christos static void
    669           1.1  christos CvSetFileParent (
    670           1.1  christos     char                    *ChildFile,
    671           1.1  christos     char                    *ParentFile)
    672           1.1  christos {
    673           1.1  christos     ACPI_FILE_NODE          *Child;
    674           1.1  christos     ACPI_FILE_NODE          *Parent;
    675           1.1  christos 
    676           1.1  christos 
    677           1.1  christos     Child  = CvFilenameExists (ChildFile, AcpiGbl_FileTreeRoot);
    678           1.1  christos     Parent = CvFilenameExists (ParentFile, AcpiGbl_FileTreeRoot);
    679       1.1.1.2  christos 
    680           1.1  christos     if (Child && Parent)
    681           1.1  christos     {
    682           1.1  christos         Child->Parent = Parent;
    683           1.1  christos 
    684           1.1  christos         while (Child->Parent)
    685           1.1  christos         {
    686           1.1  christos             if (Child->Parent->FileEnd < Child->FileStart)
    687           1.1  christos             {
    688           1.1  christos                 Child->Parent->FileEnd = Child->FileStart;
    689           1.1  christos             }
    690       1.1.1.2  christos 
    691           1.1  christos             Child = Child->Parent;
    692           1.1  christos         }
    693           1.1  christos     }
    694           1.1  christos }
    695           1.1  christos 
    696           1.1  christos 
    697           1.1  christos /*******************************************************************************
    698           1.1  christos  *
    699           1.1  christos  * FUNCTION:    CvCaptureCommentsOnly
    700           1.1  christos  *
    701           1.1  christos  * PARAMETERS:  ParserState         - A parser state object
    702           1.1  christos  *
    703       1.1.1.2  christos  * RETURN:      None
    704           1.1  christos  *
    705       1.1.1.2  christos  * DESCRIPTION: Look at the aml that the parser state is pointing to,
    706           1.1  christos  *              capture any AML_COMMENT_OP and it's arguments and increment the
    707           1.1  christos  *              aml pointer past the comment. Comments are transferred to parse
    708           1.1  christos  *              nodes through CvTransferComments() as well as
    709           1.1  christos  *              AcpiPsBuildNamedOp().
    710           1.1  christos  *              This is referred as ASL_CV_CAPTURE_COMMENTS_ONLY.
    711           1.1  christos  *
    712           1.1  christos  ******************************************************************************/
    713           1.1  christos 
    714           1.1  christos void
    715           1.1  christos CvCaptureCommentsOnly (
    716           1.1  christos     ACPI_PARSE_STATE        *ParserState)
    717           1.1  christos {
    718           1.1  christos     UINT8                   *Aml = ParserState->Aml;
    719           1.1  christos     UINT16                  Opcode = (UINT16) ACPI_GET8 (Aml);
    720           1.1  christos     UINT32                  Length = 0;
    721       1.1.1.3  christos     UINT8                   CommentOption;
    722           1.1  christos     BOOLEAN                 StdDefBlockFlag = FALSE;
    723           1.1  christos     ACPI_COMMENT_NODE       *CommentNode;
    724           1.1  christos     ACPI_FILE_NODE          *FileNode;
    725           1.1  christos 
    726           1.1  christos 
    727       1.1.1.4  christos     if (!AcpiGbl_CaptureComments ||
    728           1.1  christos         Opcode != AML_COMMENT_OP)
    729           1.1  christos     {
    730           1.1  christos        return;
    731           1.1  christos     }
    732           1.1  christos 
    733           1.1  christos     while (Opcode == AML_COMMENT_OP)
    734           1.1  christos     {
    735           1.1  christos         CvDbgPrint ("comment aml address: %p\n", Aml);
    736           1.1  christos 
    737           1.1  christos         if (CvCommentExists(ParserState->Aml))
    738           1.1  christos         {
    739           1.1  christos             CvDbgPrint ("Avoiding capturing an existing comment.\n");
    740           1.1  christos         }
    741           1.1  christos         else
    742           1.1  christos         {
    743       1.1.1.2  christos             CommentOption = *(Aml +1);
    744           1.1  christos 
    745       1.1.1.2  christos             /*
    746       1.1.1.2  christos              * Increment past the comment option and point the
    747       1.1.1.2  christos              * appropriate char pointers
    748       1.1.1.2  christos              */
    749           1.1  christos             Aml += 2;
    750           1.1  christos 
    751       1.1.1.2  christos             /* Found a comment. Now, set pointers to these comments. */
    752           1.1  christos 
    753           1.1  christos             switch (CommentOption)
    754           1.1  christos             {
    755           1.1  christos                 case STD_DEFBLK_COMMENT:
    756           1.1  christos 
    757           1.1  christos                     StdDefBlockFlag = TRUE;
    758           1.1  christos 
    759       1.1.1.2  christos                     /*
    760       1.1.1.2  christos                      * Add to a linked list of nodes. This list will be
    761       1.1.1.2  christos                      * taken by the parse node created next.
    762       1.1.1.2  christos                      */
    763       1.1.1.2  christos                     CommentNode = AcpiOsAcquireObject (
    764       1.1.1.2  christos                         AcpiGbl_RegCommentCache);
    765           1.1  christos                     CommentNode->Comment = ACPI_CAST_PTR (char, Aml);
    766           1.1  christos                     CommentNode->Next = NULL;
    767           1.1  christos 
    768           1.1  christos                     if (!AcpiGbl_DefBlkCommentListHead)
    769           1.1  christos                     {
    770           1.1  christos                         AcpiGbl_DefBlkCommentListHead = CommentNode;
    771           1.1  christos                         AcpiGbl_DefBlkCommentListTail = CommentNode;
    772           1.1  christos                     }
    773           1.1  christos                     else
    774           1.1  christos                     {
    775           1.1  christos                         AcpiGbl_DefBlkCommentListTail->Next = CommentNode;
    776       1.1.1.2  christos                         AcpiGbl_DefBlkCommentListTail =
    777       1.1.1.2  christos                             AcpiGbl_DefBlkCommentListTail->Next;
    778           1.1  christos                     }
    779           1.1  christos                     break;
    780           1.1  christos 
    781           1.1  christos                 case STANDARD_COMMENT:
    782           1.1  christos 
    783           1.1  christos                     CvDbgPrint ("found regular comment.\n");
    784           1.1  christos 
    785       1.1.1.2  christos                     /*
    786       1.1.1.2  christos                      * Add to a linked list of nodes. This list will be
    787       1.1.1.2  christos                      * taken by the parse node created next.
    788       1.1.1.2  christos                      */
    789       1.1.1.2  christos                     CommentNode = AcpiOsAcquireObject (
    790       1.1.1.2  christos                         AcpiGbl_RegCommentCache);
    791           1.1  christos                     CommentNode->Comment = ACPI_CAST_PTR (char, Aml);
    792           1.1  christos                     CommentNode->Next    = NULL;
    793           1.1  christos 
    794           1.1  christos                     if (!AcpiGbl_RegCommentListHead)
    795           1.1  christos                     {
    796           1.1  christos                         AcpiGbl_RegCommentListHead = CommentNode;
    797           1.1  christos                         AcpiGbl_RegCommentListTail = CommentNode;
    798           1.1  christos                     }
    799           1.1  christos                     else
    800           1.1  christos                     {
    801           1.1  christos                         AcpiGbl_RegCommentListTail->Next = CommentNode;
    802       1.1.1.2  christos                         AcpiGbl_RegCommentListTail =
    803       1.1.1.2  christos                             AcpiGbl_RegCommentListTail->Next;
    804           1.1  christos                     }
    805           1.1  christos                     break;
    806           1.1  christos 
    807           1.1  christos                 case ENDBLK_COMMENT:
    808           1.1  christos 
    809           1.1  christos                     CvDbgPrint ("found endblk comment.\n");
    810           1.1  christos 
    811       1.1.1.2  christos                     /* Add to a linked list of nodes. This will be
    812       1.1.1.2  christos                      * taken by the next created parse node.
    813       1.1.1.2  christos                      */
    814       1.1.1.2  christos                     CommentNode = AcpiOsAcquireObject (
    815       1.1.1.2  christos                         AcpiGbl_RegCommentCache);
    816           1.1  christos                     CommentNode->Comment = ACPI_CAST_PTR (char, Aml);
    817           1.1  christos                     CommentNode->Next    = NULL;
    818           1.1  christos 
    819           1.1  christos                     if (!AcpiGbl_EndBlkCommentListHead)
    820           1.1  christos                     {
    821           1.1  christos                         AcpiGbl_EndBlkCommentListHead = CommentNode;
    822           1.1  christos                         AcpiGbl_EndBlkCommentListTail = CommentNode;
    823           1.1  christos                     }
    824           1.1  christos                     else
    825           1.1  christos                     {
    826           1.1  christos                         AcpiGbl_EndBlkCommentListTail->Next = CommentNode;
    827       1.1.1.2  christos                         AcpiGbl_EndBlkCommentListTail =
    828       1.1.1.2  christos                             AcpiGbl_EndBlkCommentListTail->Next;
    829           1.1  christos                     }
    830           1.1  christos                     break;
    831           1.1  christos 
    832           1.1  christos                 case INLINE_COMMENT:
    833           1.1  christos 
    834           1.1  christos                     CvDbgPrint ("found inline comment.\n");
    835       1.1.1.2  christos                     AcpiGbl_CurrentInlineComment =
    836       1.1.1.2  christos                         ACPI_CAST_PTR (char, Aml);
    837           1.1  christos                     break;
    838           1.1  christos 
    839           1.1  christos                 case ENDNODE_COMMENT:
    840           1.1  christos 
    841           1.1  christos                     CvDbgPrint ("found EndNode comment.\n");
    842       1.1.1.2  christos                     AcpiGbl_CurrentEndNodeComment =
    843       1.1.1.2  christos                         ACPI_CAST_PTR (char, Aml);
    844           1.1  christos                     break;
    845           1.1  christos 
    846           1.1  christos                 case CLOSE_BRACE_COMMENT:
    847           1.1  christos 
    848           1.1  christos                     CvDbgPrint ("found close brace comment.\n");
    849       1.1.1.2  christos                     AcpiGbl_CurrentCloseBraceComment =
    850       1.1.1.2  christos                         ACPI_CAST_PTR (char, Aml);
    851           1.1  christos                     break;
    852           1.1  christos 
    853           1.1  christos                 case END_DEFBLK_COMMENT:
    854           1.1  christos 
    855       1.1.1.2  christos                     CvDbgPrint ("Found comment that belongs after"
    856       1.1.1.2  christos                         " the } for a definition block.\n");
    857       1.1.1.2  christos                     AcpiGbl_CurrentScope->Common.CloseBraceComment =
    858       1.1.1.2  christos                         ACPI_CAST_PTR (char, Aml);
    859           1.1  christos                     break;
    860           1.1  christos 
    861           1.1  christos                 case FILENAME_COMMENT:
    862           1.1  christos 
    863       1.1.1.2  christos                     CvDbgPrint ("Found a filename: %s\n",
    864       1.1.1.2  christos                         ACPI_CAST_PTR (char, Aml));
    865       1.1.1.2  christos                     FileNode = CvFilenameExists (
    866       1.1.1.2  christos                         ACPI_CAST_PTR (char, Aml), AcpiGbl_FileTreeRoot);
    867           1.1  christos 
    868           1.1  christos                     /*
    869           1.1  christos                      * If there is an INCLUDE_COMMENT followed by a
    870           1.1  christos                      * FILENAME_COMMENT, then the INCLUDE_COMMENT is a comment
    871           1.1  christos                      * that is emitted before the #include for the file.
    872           1.1  christos                      * We will save the IncludeComment within the FileNode
    873           1.1  christos                      * associated with this FILENAME_COMMENT.
    874           1.1  christos                      */
    875           1.1  christos                     if (FileNode && AcpiGbl_IncCommentListHead)
    876           1.1  christos                     {
    877           1.1  christos                         FileNode->IncludeComment = AcpiGbl_IncCommentListHead;
    878           1.1  christos                         AcpiGbl_IncCommentListHead = NULL;
    879           1.1  christos                         AcpiGbl_IncCommentListTail = NULL;
    880           1.1  christos                     }
    881           1.1  christos                     break;
    882           1.1  christos 
    883           1.1  christos                 case PARENTFILENAME_COMMENT:
    884           1.1  christos                     CvDbgPrint ("    Found a parent filename.\n");
    885           1.1  christos                     break;
    886           1.1  christos 
    887           1.1  christos                 case INCLUDE_COMMENT:
    888           1.1  christos 
    889           1.1  christos                     /*
    890           1.1  christos                      * Add to a linked list. This list will be taken by the
    891           1.1  christos                      * parse node created next. See the FILENAME_COMMENT case
    892           1.1  christos                      * for more details
    893           1.1  christos                      */
    894       1.1.1.2  christos                     CommentNode = AcpiOsAcquireObject (
    895       1.1.1.2  christos                         AcpiGbl_RegCommentCache);
    896           1.1  christos                     CommentNode->Comment = ACPI_CAST_PTR (char, Aml);
    897           1.1  christos                     CommentNode->Next = NULL;
    898           1.1  christos 
    899           1.1  christos                     if (!AcpiGbl_IncCommentListHead)
    900           1.1  christos                     {
    901           1.1  christos                         AcpiGbl_IncCommentListHead = CommentNode;
    902           1.1  christos                         AcpiGbl_IncCommentListTail = CommentNode;
    903           1.1  christos                     }
    904           1.1  christos                     else
    905           1.1  christos                     {
    906           1.1  christos                         AcpiGbl_IncCommentListTail->Next = CommentNode;
    907       1.1.1.2  christos                         AcpiGbl_IncCommentListTail =
    908       1.1.1.2  christos                             AcpiGbl_IncCommentListTail->Next;
    909           1.1  christos                     }
    910           1.1  christos 
    911       1.1.1.2  christos                     CvDbgPrint ("Found a include comment: %s\n",
    912       1.1.1.2  christos                         CommentNode->Comment);
    913           1.1  christos                     break;
    914           1.1  christos 
    915           1.1  christos                 default:
    916           1.1  christos 
    917           1.1  christos                     /* Not a valid comment option. Revert the AML */
    918           1.1  christos 
    919           1.1  christos                     goto DefBlock;
    920           1.1  christos 
    921       1.1.1.2  christos             } /* End switch statement */
    922           1.1  christos 
    923       1.1.1.2  christos         } /* End else */
    924           1.1  christos 
    925       1.1.1.2  christos         /* Determine the length and move forward that amount */
    926           1.1  christos 
    927           1.1  christos         Length = 0;
    928           1.1  christos         while (ParserState->Aml[Length])
    929           1.1  christos         {
    930           1.1  christos             Length++;
    931           1.1  christos         }
    932           1.1  christos 
    933           1.1  christos         ParserState->Aml += Length + 1;
    934           1.1  christos 
    935           1.1  christos         /* Peek at the next Opcode. */
    936           1.1  christos 
    937           1.1  christos         Aml = ParserState->Aml;
    938           1.1  christos         Opcode = (UINT16) ACPI_GET8 (Aml);
    939           1.1  christos     }
    940           1.1  christos 
    941           1.1  christos DefBlock:
    942           1.1  christos     if (StdDefBlockFlag)
    943           1.1  christos     {
    944           1.1  christos         /*
    945           1.1  christos          * Give all of its comments to the current scope, which is known as
    946           1.1  christos          * the definition block, since STD_DEFBLK_COMMENT only appears after
    947           1.1  christos          * definition block headers.
    948           1.1  christos          */
    949           1.1  christos         AcpiGbl_CurrentScope->Common.CommentList
    950           1.1  christos             = AcpiGbl_DefBlkCommentListHead;
    951           1.1  christos         AcpiGbl_DefBlkCommentListHead = NULL;
    952           1.1  christos         AcpiGbl_DefBlkCommentListTail = NULL;
    953           1.1  christos     }
    954           1.1  christos }
    955           1.1  christos 
    956           1.1  christos 
    957           1.1  christos /*******************************************************************************
    958           1.1  christos  *
    959           1.1  christos  * FUNCTION:    CvCaptureComments
    960           1.1  christos  *
    961           1.1  christos  * PARAMETERS:  ParserState         - A parser state object
    962           1.1  christos  *
    963       1.1.1.2  christos  * RETURN:      None
    964           1.1  christos  *
    965           1.1  christos  * DESCRIPTION: Wrapper function for CvCaptureCommentsOnly
    966           1.1  christos  *              This is referred as ASL_CV_CAPTURE_COMMENTS.
    967           1.1  christos  *
    968           1.1  christos  ******************************************************************************/
    969           1.1  christos 
    970           1.1  christos void
    971           1.1  christos CvCaptureComments (
    972           1.1  christos     ACPI_WALK_STATE         *WalkState)
    973           1.1  christos {
    974           1.1  christos     UINT8                   *Aml;
    975           1.1  christos     UINT16                  Opcode;
    976           1.1  christos     const ACPI_OPCODE_INFO  *OpInfo;
    977           1.1  christos 
    978           1.1  christos 
    979       1.1.1.4  christos     if (!AcpiGbl_CaptureComments)
    980           1.1  christos     {
    981           1.1  christos         return;
    982           1.1  christos     }
    983           1.1  christos 
    984           1.1  christos     /*
    985       1.1.1.2  christos      * Before parsing, check to see that comments that come directly
    986       1.1.1.2  christos      * after deferred opcodes aren't being processed.
    987           1.1  christos      */
    988           1.1  christos     Aml = WalkState->ParserState.Aml;
    989           1.1  christos     Opcode = (UINT16) ACPI_GET8 (Aml);
    990           1.1  christos     OpInfo = AcpiPsGetOpcodeInfo (Opcode);
    991           1.1  christos 
    992           1.1  christos     if (!(OpInfo->Flags & AML_DEFER) ||
    993           1.1  christos         ((OpInfo->Flags & AML_DEFER) &&
    994           1.1  christos         (WalkState->PassNumber != ACPI_IMODE_LOAD_PASS1)))
    995           1.1  christos     {
    996           1.1  christos         CvCaptureCommentsOnly (&WalkState->ParserState);
    997           1.1  christos         WalkState->Aml = WalkState->ParserState.Aml;
    998           1.1  christos     }
    999           1.1  christos 
   1000           1.1  christos }
   1001           1.1  christos 
   1002           1.1  christos 
   1003           1.1  christos /*******************************************************************************
   1004           1.1  christos  *
   1005           1.1  christos  * FUNCTION:    CvTransferComments
   1006           1.1  christos  *
   1007       1.1.1.2  christos  * PARAMETERS:  Op                  - Transfer comments to this Op
   1008           1.1  christos  *
   1009       1.1.1.2  christos  * RETURN:      None
   1010           1.1  christos  *
   1011       1.1.1.6  christos  * DESCRIPTION: Transfer all of the comments stored in global containers to the
   1012           1.1  christos  *              given Op. This will be invoked shortly after the parser creates
   1013           1.1  christos  *              a ParseOp.
   1014           1.1  christos  *              This is referred as ASL_CV_TRANSFER_COMMENTS.
   1015           1.1  christos  *
   1016           1.1  christos  ******************************************************************************/
   1017           1.1  christos 
   1018           1.1  christos void
   1019           1.1  christos CvTransferComments (
   1020           1.1  christos     ACPI_PARSE_OBJECT       *Op)
   1021           1.1  christos {
   1022       1.1.1.2  christos 
   1023           1.1  christos     Op->Common.InlineComment = AcpiGbl_CurrentInlineComment;
   1024           1.1  christos     AcpiGbl_CurrentInlineComment = NULL;
   1025           1.1  christos 
   1026           1.1  christos     Op->Common.EndNodeComment = AcpiGbl_CurrentEndNodeComment;
   1027           1.1  christos     AcpiGbl_CurrentEndNodeComment = NULL;
   1028           1.1  christos 
   1029           1.1  christos     Op->Common.CloseBraceComment = AcpiGbl_CurrentCloseBraceComment;
   1030           1.1  christos     AcpiGbl_CurrentCloseBraceComment = NULL;
   1031           1.1  christos 
   1032           1.1  christos     Op->Common.CommentList = AcpiGbl_RegCommentListHead;
   1033           1.1  christos     AcpiGbl_RegCommentListHead = NULL;
   1034           1.1  christos     AcpiGbl_RegCommentListTail = NULL;
   1035           1.1  christos 
   1036           1.1  christos     Op->Common.EndBlkComment = AcpiGbl_EndBlkCommentListHead;
   1037           1.1  christos     AcpiGbl_EndBlkCommentListHead = NULL;
   1038           1.1  christos     AcpiGbl_EndBlkCommentListTail = NULL;
   1039           1.1  christos }
   1040