Home | History | Annotate | Line # | Download | only in compiler
aslutils.c revision 1.33.6.1
      1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3       1.1    jruoho  * Module Name: aslutils -- compiler utilities
      4       1.1    jruoho  *
      5       1.1    jruoho  *****************************************************************************/
      6       1.1    jruoho 
      7  1.33.6.1  perseant /******************************************************************************
      8  1.33.6.1  perseant  *
      9  1.33.6.1  perseant  * 1. Copyright Notice
     10  1.33.6.1  perseant  *
     11  1.33.6.1  perseant  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
     12       1.1    jruoho  * All rights reserved.
     13       1.1    jruoho  *
     14  1.33.6.1  perseant  * 2. License
     15  1.33.6.1  perseant  *
     16  1.33.6.1  perseant  * 2.1. This is your license from Intel Corp. under its intellectual property
     17  1.33.6.1  perseant  * rights. You may have additional license terms from the party that provided
     18  1.33.6.1  perseant  * you this software, covering your right to use that party's intellectual
     19  1.33.6.1  perseant  * property rights.
     20  1.33.6.1  perseant  *
     21  1.33.6.1  perseant  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     22  1.33.6.1  perseant  * copy of the source code appearing in this file ("Covered Code") an
     23  1.33.6.1  perseant  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     24  1.33.6.1  perseant  * base code distributed originally by Intel ("Original Intel Code") to copy,
     25  1.33.6.1  perseant  * make derivatives, distribute, use and display any portion of the Covered
     26  1.33.6.1  perseant  * Code in any form, with the right to sublicense such rights; and
     27  1.33.6.1  perseant  *
     28  1.33.6.1  perseant  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     29  1.33.6.1  perseant  * license (with the right to sublicense), under only those claims of Intel
     30  1.33.6.1  perseant  * patents that are infringed by the Original Intel Code, to make, use, sell,
     31  1.33.6.1  perseant  * offer to sell, and import the Covered Code and derivative works thereof
     32  1.33.6.1  perseant  * solely to the minimum extent necessary to exercise the above copyright
     33  1.33.6.1  perseant  * license, and in no event shall the patent license extend to any additions
     34  1.33.6.1  perseant  * to or modifications of the Original Intel Code. No other license or right
     35  1.33.6.1  perseant  * is granted directly or by implication, estoppel or otherwise;
     36  1.33.6.1  perseant  *
     37  1.33.6.1  perseant  * The above copyright and patent license is granted only if the following
     38  1.33.6.1  perseant  * conditions are met:
     39  1.33.6.1  perseant  *
     40  1.33.6.1  perseant  * 3. Conditions
     41  1.33.6.1  perseant  *
     42  1.33.6.1  perseant  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     43  1.33.6.1  perseant  * Redistribution of source code of any substantial portion of the Covered
     44  1.33.6.1  perseant  * Code or modification with rights to further distribute source must include
     45  1.33.6.1  perseant  * the above Copyright Notice, the above License, this list of Conditions,
     46  1.33.6.1  perseant  * and the following Disclaimer and Export Compliance provision. In addition,
     47  1.33.6.1  perseant  * Licensee must cause all Covered Code to which Licensee contributes to
     48  1.33.6.1  perseant  * contain a file documenting the changes Licensee made to create that Covered
     49  1.33.6.1  perseant  * Code and the date of any change. Licensee must include in that file the
     50  1.33.6.1  perseant  * documentation of any changes made by any predecessor Licensee. Licensee
     51  1.33.6.1  perseant  * must include a prominent statement that the modification is derived,
     52  1.33.6.1  perseant  * directly or indirectly, from Original Intel Code.
     53  1.33.6.1  perseant  *
     54  1.33.6.1  perseant  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     55  1.33.6.1  perseant  * Redistribution of source code of any substantial portion of the Covered
     56  1.33.6.1  perseant  * Code or modification without rights to further distribute source must
     57  1.33.6.1  perseant  * include the following Disclaimer and Export Compliance provision in the
     58  1.33.6.1  perseant  * documentation and/or other materials provided with distribution. In
     59  1.33.6.1  perseant  * addition, Licensee may not authorize further sublicense of source of any
     60  1.33.6.1  perseant  * portion of the Covered Code, and must include terms to the effect that the
     61  1.33.6.1  perseant  * license from Licensee to its licensee is limited to the intellectual
     62  1.33.6.1  perseant  * property embodied in the software Licensee provides to its licensee, and
     63  1.33.6.1  perseant  * not to intellectual property embodied in modifications its licensee may
     64  1.33.6.1  perseant  * make.
     65  1.33.6.1  perseant  *
     66  1.33.6.1  perseant  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     67  1.33.6.1  perseant  * substantial portion of the Covered Code or modification must reproduce the
     68  1.33.6.1  perseant  * above Copyright Notice, and the following Disclaimer and Export Compliance
     69  1.33.6.1  perseant  * provision in the documentation and/or other materials provided with the
     70  1.33.6.1  perseant  * distribution.
     71  1.33.6.1  perseant  *
     72  1.33.6.1  perseant  * 3.4. Intel retains all right, title, and interest in and to the Original
     73  1.33.6.1  perseant  * Intel Code.
     74  1.33.6.1  perseant  *
     75  1.33.6.1  perseant  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     76  1.33.6.1  perseant  * Intel shall be used in advertising or otherwise to promote the sale, use or
     77  1.33.6.1  perseant  * other dealings in products derived from or relating to the Covered Code
     78  1.33.6.1  perseant  * without prior written authorization from Intel.
     79  1.33.6.1  perseant  *
     80  1.33.6.1  perseant  * 4. Disclaimer and Export Compliance
     81  1.33.6.1  perseant  *
     82  1.33.6.1  perseant  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     83  1.33.6.1  perseant  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     84  1.33.6.1  perseant  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
     85  1.33.6.1  perseant  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
     86  1.33.6.1  perseant  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
     87  1.33.6.1  perseant  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     88  1.33.6.1  perseant  * PARTICULAR PURPOSE.
     89  1.33.6.1  perseant  *
     90  1.33.6.1  perseant  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     91  1.33.6.1  perseant  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     92  1.33.6.1  perseant  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     93  1.33.6.1  perseant  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     94  1.33.6.1  perseant  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     95  1.33.6.1  perseant  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
     96  1.33.6.1  perseant  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     97  1.33.6.1  perseant  * LIMITED REMEDY.
     98  1.33.6.1  perseant  *
     99  1.33.6.1  perseant  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    100  1.33.6.1  perseant  * software or system incorporating such software without first obtaining any
    101  1.33.6.1  perseant  * required license or other approval from the U. S. Department of Commerce or
    102  1.33.6.1  perseant  * any other agency or department of the United States Government. In the
    103  1.33.6.1  perseant  * event Licensee exports any such software from the United States or
    104  1.33.6.1  perseant  * re-exports any such software from a foreign destination, Licensee shall
    105  1.33.6.1  perseant  * ensure that the distribution and export/re-export of the software is in
    106  1.33.6.1  perseant  * compliance with all laws, regulations, orders, or other restrictions of the
    107  1.33.6.1  perseant  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    108  1.33.6.1  perseant  * any of its subsidiaries will export/re-export any technical data, process,
    109  1.33.6.1  perseant  * software, or service, directly or indirectly, to any country for which the
    110  1.33.6.1  perseant  * United States government or any agency thereof requires an export license,
    111  1.33.6.1  perseant  * other governmental approval, or letter of assurance, without first obtaining
    112  1.33.6.1  perseant  * such license, approval or letter.
    113  1.33.6.1  perseant  *
    114  1.33.6.1  perseant  *****************************************************************************
    115  1.33.6.1  perseant  *
    116  1.33.6.1  perseant  * Alternatively, you may choose to be licensed under the terms of the
    117  1.33.6.1  perseant  * following license:
    118  1.33.6.1  perseant  *
    119       1.3    jruoho  * Redistribution and use in source and binary forms, with or without
    120       1.3    jruoho  * modification, are permitted provided that the following conditions
    121       1.3    jruoho  * are met:
    122       1.3    jruoho  * 1. Redistributions of source code must retain the above copyright
    123       1.3    jruoho  *    notice, this list of conditions, and the following disclaimer,
    124       1.3    jruoho  *    without modification.
    125       1.3    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
    126       1.3    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
    127       1.3    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
    128       1.3    jruoho  *    including a substantially similar Disclaimer requirement for further
    129       1.3    jruoho  *    binary redistribution.
    130       1.3    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
    131       1.3    jruoho  *    of any contributors may be used to endorse or promote products derived
    132       1.3    jruoho  *    from this software without specific prior written permission.
    133       1.3    jruoho  *
    134       1.3    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    135       1.3    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    136      1.28  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    137       1.3    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    138  1.33.6.1  perseant  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    139  1.33.6.1  perseant  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    140  1.33.6.1  perseant  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    141  1.33.6.1  perseant  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    142  1.33.6.1  perseant  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    143  1.33.6.1  perseant  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    144  1.33.6.1  perseant  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    145  1.33.6.1  perseant  *
    146  1.33.6.1  perseant  * Alternatively, you may choose to be licensed under the terms of the
    147  1.33.6.1  perseant  * GNU General Public License ("GPL") version 2 as published by the Free
    148  1.33.6.1  perseant  * Software Foundation.
    149  1.33.6.1  perseant  *
    150  1.33.6.1  perseant  *****************************************************************************/
    151       1.1    jruoho 
    152       1.1    jruoho #include "aslcompiler.h"
    153       1.1    jruoho #include "aslcompiler.y.h"
    154       1.3    jruoho #include "acdisasm.h"
    155       1.1    jruoho #include "acnamesp.h"
    156       1.1    jruoho #include "amlcode.h"
    157      1.13  christos #include "acapps.h"
    158      1.13  christos #include <sys/stat.h>
    159      1.13  christos 
    160       1.1    jruoho 
    161       1.1    jruoho #define _COMPONENT          ACPI_COMPILER
    162       1.1    jruoho         ACPI_MODULE_NAME    ("aslutils")
    163       1.1    jruoho 
    164       1.1    jruoho 
    165       1.1    jruoho /* Local prototypes */
    166       1.1    jruoho 
    167       1.1    jruoho static void
    168       1.1    jruoho UtPadNameWithUnderscores (
    169       1.1    jruoho     char                    *NameSeg,
    170       1.1    jruoho     char                    *PaddedNameSeg);
    171       1.1    jruoho 
    172       1.1    jruoho static void
    173       1.1    jruoho UtAttachNameseg (
    174       1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
    175       1.1    jruoho     char                    *Name);
    176       1.1    jruoho 
    177      1.23  christos static void
    178      1.23  christos UtDisplayErrorSummary (
    179      1.23  christos     UINT32                  FileId);
    180      1.23  christos 
    181       1.1    jruoho 
    182      1.14  christos /*******************************************************************************
    183      1.14  christos  *
    184      1.14  christos  * FUNCTION:    UtIsBigEndianMachine
    185      1.14  christos  *
    186      1.14  christos  * PARAMETERS:  None
    187      1.14  christos  *
    188      1.14  christos  * RETURN:      TRUE if machine is big endian
    189      1.14  christos  *              FALSE if machine is little endian
    190      1.14  christos  *
    191      1.14  christos  * DESCRIPTION: Detect whether machine is little endian or big endian.
    192      1.14  christos  *
    193      1.14  christos  ******************************************************************************/
    194      1.14  christos 
    195      1.14  christos UINT8
    196      1.14  christos UtIsBigEndianMachine (
    197      1.14  christos     void)
    198      1.14  christos {
    199      1.14  christos     union {
    200      1.14  christos         UINT32              Integer;
    201      1.14  christos         UINT8               Bytes[4];
    202      1.14  christos     } Overlay =                 {0xFF000000};
    203      1.14  christos 
    204      1.14  christos 
    205      1.14  christos     return (Overlay.Bytes[0]); /* Returns 0xFF (TRUE) for big endian */
    206      1.14  christos }
    207      1.14  christos 
    208      1.14  christos 
    209      1.29  christos /*******************************************************************************
    210      1.29  christos  *
    211      1.29  christos  * FUNCTION:    UtIsIdInteger
    212      1.29  christos  *
    213      1.29  christos  * PARAMETERS:  Pointer to an ACPI ID (HID, CID) string
    214      1.29  christos  *
    215      1.29  christos  * RETURN:      TRUE if string is an integer
    216      1.29  christos  *              FALSE if string is not an integer
    217      1.29  christos  *
    218      1.29  christos  * DESCRIPTION: Determine whether the input ACPI ID string can be converted to
    219      1.29  christos  *              an integer value.
    220      1.29  christos  *
    221      1.29  christos  ******************************************************************************/
    222      1.29  christos 
    223      1.29  christos BOOLEAN
    224      1.29  christos UtIsIdInteger (
    225      1.29  christos     UINT8                   *Target)
    226      1.29  christos {
    227      1.29  christos     UINT32                  i;
    228      1.29  christos 
    229      1.29  christos 
    230      1.29  christos     /* The first three characters of the string must be alphabetic */
    231      1.29  christos 
    232      1.29  christos     for (i = 0; i < 3; i++)
    233      1.29  christos     {
    234      1.29  christos         if (!isalpha ((int) Target[i]))
    235      1.29  christos         {
    236      1.29  christos             break;
    237      1.29  christos         }
    238      1.29  christos     }
    239      1.29  christos 
    240      1.29  christos     if (i < 3)
    241      1.29  christos     {
    242      1.29  christos         return (TRUE);
    243      1.29  christos     }
    244      1.29  christos 
    245      1.29  christos     return (FALSE);
    246      1.29  christos }
    247      1.29  christos 
    248      1.29  christos 
    249      1.13  christos /******************************************************************************
    250      1.13  christos  *
    251      1.13  christos  * FUNCTION:    UtQueryForOverwrite
    252      1.13  christos  *
    253      1.13  christos  * PARAMETERS:  Pathname            - Output filename
    254      1.13  christos  *
    255      1.13  christos  * RETURN:      TRUE if file does not exist or overwrite is authorized
    256      1.13  christos  *
    257      1.13  christos  * DESCRIPTION: Query for file overwrite if it already exists.
    258      1.13  christos  *
    259      1.13  christos  ******************************************************************************/
    260      1.13  christos 
    261      1.13  christos BOOLEAN
    262      1.13  christos UtQueryForOverwrite (
    263      1.13  christos     char                    *Pathname)
    264      1.13  christos {
    265      1.13  christos     struct stat             StatInfo;
    266      1.25  christos     int                     InChar;
    267      1.13  christos 
    268      1.13  christos 
    269      1.13  christos     if (!stat (Pathname, &StatInfo))
    270      1.13  christos     {
    271      1.13  christos         fprintf (stderr, "Target file \"%s\" already exists, overwrite? [y|n] ",
    272      1.13  christos             Pathname);
    273      1.13  christos 
    274      1.24  christos         InChar = fgetc (stdin);
    275      1.24  christos         if (InChar == '\n')
    276      1.24  christos         {
    277      1.24  christos             InChar = fgetc (stdin);
    278      1.24  christos         }
    279      1.24  christos 
    280      1.24  christos         if ((InChar != 'y') && (InChar != 'Y'))
    281      1.13  christos         {
    282      1.13  christos             return (FALSE);
    283      1.13  christos         }
    284      1.13  christos     }
    285      1.13  christos 
    286      1.13  christos     return (TRUE);
    287      1.13  christos }
    288      1.13  christos 
    289      1.13  christos 
    290       1.1    jruoho /*******************************************************************************
    291       1.1    jruoho  *
    292      1.21  christos  * FUNCTION:    UtNodeIsDescendantOf
    293      1.21  christos  *
    294      1.21  christos  * PARAMETERS:  Node1                   - Child node
    295      1.21  christos  *              Node2                   - Possible parent node
    296      1.21  christos  *
    297      1.21  christos  * RETURN:      Boolean
    298      1.21  christos  *
    299      1.21  christos  * DESCRIPTION: Returns TRUE if Node1 is a descendant of Node2. Otherwise,
    300      1.21  christos  *              return FALSE. Note, we assume a NULL Node2 element to be the
    301      1.21  christos  *              topmost (root) scope. All nodes are descendants of the root.
    302      1.21  christos  *              Note: Nodes at the same level (siblings) are not considered
    303      1.21  christos  *              descendants.
    304      1.21  christos  *
    305      1.21  christos  ******************************************************************************/
    306      1.21  christos 
    307      1.21  christos BOOLEAN
    308      1.21  christos UtNodeIsDescendantOf (
    309      1.21  christos     ACPI_NAMESPACE_NODE     *Node1,
    310      1.21  christos     ACPI_NAMESPACE_NODE     *Node2)
    311      1.21  christos {
    312      1.21  christos 
    313      1.21  christos     if (Node1 == Node2)
    314      1.21  christos     {
    315      1.21  christos         return (FALSE);
    316      1.21  christos     }
    317      1.21  christos 
    318      1.21  christos     if (!Node2)
    319      1.21  christos     {
    320      1.21  christos         return (TRUE); /* All nodes descend from the root */
    321      1.21  christos     }
    322      1.21  christos 
    323      1.21  christos     /* Walk upward until the root is reached or parent is found */
    324      1.21  christos 
    325      1.21  christos     while (Node1)
    326      1.21  christos     {
    327      1.21  christos         if (Node1 == Node2)
    328      1.21  christos         {
    329      1.21  christos             return (TRUE);
    330      1.21  christos         }
    331      1.21  christos 
    332      1.21  christos         Node1 = Node1->Parent;
    333      1.21  christos     }
    334      1.21  christos 
    335      1.21  christos     return (FALSE);
    336      1.21  christos }
    337      1.21  christos 
    338      1.21  christos 
    339      1.21  christos /*******************************************************************************
    340      1.21  christos  *
    341      1.26  christos  * FUNCTION:    UtGetParentMethodNode
    342      1.21  christos  *
    343      1.21  christos  * PARAMETERS:  Node                    - Namespace node for any object
    344      1.21  christos  *
    345      1.21  christos  * RETURN:      Namespace node for the parent method
    346      1.21  christos  *              NULL - object is not within a method
    347      1.21  christos  *
    348      1.21  christos  * DESCRIPTION: Find the parent (owning) method node for a namespace object
    349      1.21  christos  *
    350      1.21  christos  ******************************************************************************/
    351      1.21  christos 
    352      1.26  christos ACPI_NAMESPACE_NODE *
    353      1.26  christos UtGetParentMethodNode (
    354      1.21  christos     ACPI_NAMESPACE_NODE     *Node)
    355      1.21  christos {
    356      1.21  christos     ACPI_NAMESPACE_NODE     *ParentNode;
    357      1.21  christos 
    358      1.21  christos 
    359      1.21  christos     if (!Node)
    360      1.21  christos     {
    361      1.21  christos         return (NULL);
    362      1.21  christos     }
    363      1.21  christos 
    364      1.21  christos     /* Walk upward until a method is found, or the root is reached */
    365      1.21  christos 
    366      1.21  christos     ParentNode = Node->Parent;
    367      1.21  christos     while (ParentNode)
    368      1.21  christos     {
    369      1.21  christos         if (ParentNode->Type == ACPI_TYPE_METHOD)
    370      1.21  christos         {
    371      1.21  christos             return (ParentNode);
    372      1.21  christos         }
    373      1.21  christos 
    374      1.21  christos         ParentNode = ParentNode->Parent;
    375      1.21  christos     }
    376      1.21  christos 
    377      1.21  christos     return (NULL); /* Object is not within a control method */
    378      1.21  christos }
    379      1.21  christos 
    380      1.21  christos 
    381      1.21  christos /*******************************************************************************
    382      1.21  christos  *
    383      1.26  christos  * FUNCTION:    UtGetParentMethodOp
    384      1.26  christos  *
    385      1.26  christos  * PARAMETERS:  Op                      - Parse Op to be checked
    386      1.26  christos  *
    387      1.26  christos  * RETURN:      Control method Op if found. NULL otherwise
    388      1.26  christos  *
    389      1.26  christos  * DESCRIPTION: Find the control method parent of a parse op. Returns NULL if
    390      1.26  christos  *              the input Op is not within a control method.
    391      1.26  christos  *
    392      1.26  christos  ******************************************************************************/
    393      1.26  christos 
    394      1.26  christos ACPI_PARSE_OBJECT *
    395      1.26  christos UtGetParentMethodOp (
    396      1.26  christos     ACPI_PARSE_OBJECT       *Op)
    397      1.26  christos {
    398      1.26  christos     ACPI_PARSE_OBJECT       *NextOp;
    399      1.26  christos 
    400      1.26  christos 
    401      1.26  christos     NextOp = Op->Asl.Parent;
    402      1.26  christos     while (NextOp)
    403      1.26  christos     {
    404      1.26  christos         if (NextOp->Asl.AmlOpcode == AML_METHOD_OP)
    405      1.26  christos         {
    406      1.26  christos             return (NextOp);
    407      1.26  christos         }
    408      1.26  christos 
    409      1.26  christos         NextOp = NextOp->Asl.Parent;
    410      1.26  christos     }
    411      1.26  christos 
    412      1.26  christos     return (NULL); /* No parent method found */
    413      1.26  christos }
    414      1.26  christos 
    415      1.26  christos 
    416      1.26  christos /*******************************************************************************
    417      1.26  christos  *
    418       1.3    jruoho  * FUNCTION:    UtDisplaySupportedTables
    419       1.3    jruoho  *
    420       1.3    jruoho  * PARAMETERS:  None
    421       1.3    jruoho  *
    422       1.3    jruoho  * RETURN:      None
    423       1.3    jruoho  *
    424       1.3    jruoho  * DESCRIPTION: Print all supported ACPI table names.
    425       1.3    jruoho  *
    426       1.3    jruoho  ******************************************************************************/
    427       1.3    jruoho 
    428       1.3    jruoho void
    429       1.3    jruoho UtDisplaySupportedTables (
    430       1.3    jruoho     void)
    431       1.3    jruoho {
    432      1.12  christos     const AH_TABLE          *TableData;
    433       1.6  christos     UINT32                  i;
    434       1.3    jruoho 
    435       1.3    jruoho 
    436       1.6  christos     printf ("\nACPI tables supported by iASL version %8.8X:\n"
    437      1.30  christos         "  (Compiler, Disassembler, Template Generator)\n",
    438       1.6  christos         ACPI_CA_VERSION);
    439       1.3    jruoho 
    440      1.12  christos     /* All ACPI tables with the common table header */
    441       1.3    jruoho 
    442      1.30  christos     printf ("\nKnown/Supported ACPI tables:\n");
    443      1.22  christos     for (TableData = AcpiGbl_SupportedTables, i = 1;
    444      1.12  christos          TableData->Signature; TableData++, i++)
    445       1.3    jruoho     {
    446      1.12  christos         printf ("%8u) %s    %s\n", i,
    447      1.12  christos             TableData->Signature, TableData->Description);
    448       1.3    jruoho     }
    449      1.30  christos 
    450      1.30  christos     printf ("\nTotal %u ACPI tables\n\n", i-1);
    451       1.3    jruoho }
    452       1.3    jruoho 
    453       1.3    jruoho 
    454       1.3    jruoho /*******************************************************************************
    455       1.3    jruoho  *
    456       1.6  christos  * FUNCTION:    UtDisplayConstantOpcodes
    457       1.1    jruoho  *
    458       1.1    jruoho  * PARAMETERS:  None
    459       1.1    jruoho  *
    460       1.1    jruoho  * RETURN:      None
    461       1.1    jruoho  *
    462       1.1    jruoho  * DESCRIPTION: Print AML opcodes that can be used in constant expressions.
    463       1.1    jruoho  *
    464       1.1    jruoho  ******************************************************************************/
    465       1.1    jruoho 
    466       1.1    jruoho void
    467       1.1    jruoho UtDisplayConstantOpcodes (
    468       1.1    jruoho     void)
    469       1.1    jruoho {
    470       1.1    jruoho     UINT32                  i;
    471       1.1    jruoho 
    472       1.1    jruoho 
    473       1.1    jruoho     printf ("Constant expression opcode information\n\n");
    474       1.1    jruoho 
    475       1.1    jruoho     for (i = 0; i < sizeof (AcpiGbl_AmlOpInfo) / sizeof (ACPI_OPCODE_INFO); i++)
    476       1.1    jruoho     {
    477       1.1    jruoho         if (AcpiGbl_AmlOpInfo[i].Flags & AML_CONSTANT)
    478       1.1    jruoho         {
    479       1.1    jruoho             printf ("%s\n", AcpiGbl_AmlOpInfo[i].Name);
    480       1.1    jruoho         }
    481       1.1    jruoho     }
    482       1.1    jruoho }
    483       1.1    jruoho 
    484       1.1    jruoho 
    485       1.1    jruoho /*******************************************************************************
    486       1.1    jruoho  *
    487       1.1    jruoho  * FUNCTION:    UtBeginEvent
    488       1.1    jruoho  *
    489       1.6  christos  * PARAMETERS:  Name                - Ascii name of this event
    490       1.1    jruoho  *
    491       1.6  christos  * RETURN:      Event number (integer index)
    492       1.1    jruoho  *
    493       1.1    jruoho  * DESCRIPTION: Saves the current time with this event
    494       1.1    jruoho  *
    495       1.1    jruoho  ******************************************************************************/
    496       1.1    jruoho 
    497       1.1    jruoho UINT8
    498       1.1    jruoho UtBeginEvent (
    499       1.1    jruoho     char                    *Name)
    500       1.1    jruoho {
    501       1.1    jruoho 
    502       1.1    jruoho     if (AslGbl_NextEvent >= ASL_NUM_EVENTS)
    503       1.1    jruoho     {
    504       1.1    jruoho         AcpiOsPrintf ("Ran out of compiler event structs!\n");
    505       1.1    jruoho         return (AslGbl_NextEvent);
    506       1.1    jruoho     }
    507       1.1    jruoho 
    508       1.1    jruoho     /* Init event with current (start) time */
    509       1.1    jruoho 
    510       1.1    jruoho     AslGbl_Events[AslGbl_NextEvent].StartTime = AcpiOsGetTimer ();
    511       1.1    jruoho     AslGbl_Events[AslGbl_NextEvent].EventName = Name;
    512       1.1    jruoho     AslGbl_Events[AslGbl_NextEvent].Valid = TRUE;
    513       1.1    jruoho     return (AslGbl_NextEvent++);
    514       1.1    jruoho }
    515       1.1    jruoho 
    516       1.1    jruoho 
    517       1.1    jruoho /*******************************************************************************
    518       1.1    jruoho  *
    519       1.1    jruoho  * FUNCTION:    UtEndEvent
    520       1.1    jruoho  *
    521       1.6  christos  * PARAMETERS:  Event               - Event number (integer index)
    522       1.1    jruoho  *
    523       1.1    jruoho  * RETURN:      None
    524       1.1    jruoho  *
    525       1.1    jruoho  * DESCRIPTION: Saves the current time (end time) with this event
    526       1.1    jruoho  *
    527       1.1    jruoho  ******************************************************************************/
    528       1.1    jruoho 
    529       1.1    jruoho void
    530       1.1    jruoho UtEndEvent (
    531       1.6  christos     UINT8                   Event)
    532       1.1    jruoho {
    533       1.1    jruoho 
    534       1.1    jruoho     if (Event >= ASL_NUM_EVENTS)
    535       1.1    jruoho     {
    536       1.1    jruoho         return;
    537       1.1    jruoho     }
    538       1.1    jruoho 
    539       1.1    jruoho     /* Insert end time for event */
    540       1.1    jruoho 
    541       1.1    jruoho     AslGbl_Events[Event].EndTime = AcpiOsGetTimer ();
    542       1.1    jruoho }
    543       1.1    jruoho 
    544       1.1    jruoho 
    545       1.1    jruoho /*******************************************************************************
    546       1.1    jruoho  *
    547       1.1    jruoho  * FUNCTION:    DbgPrint
    548       1.1    jruoho  *
    549       1.6  christos  * PARAMETERS:  Type                - Type of output
    550       1.6  christos  *              Fmt                 - Printf format string
    551       1.6  christos  *              ...                 - variable printf list
    552       1.1    jruoho  *
    553       1.1    jruoho  * RETURN:      None
    554       1.1    jruoho  *
    555       1.6  christos  * DESCRIPTION: Conditional print statement. Prints to stderr only if the
    556       1.1    jruoho  *              debug flag is set.
    557       1.1    jruoho  *
    558       1.1    jruoho  ******************************************************************************/
    559       1.1    jruoho 
    560       1.1    jruoho void
    561       1.1    jruoho DbgPrint (
    562       1.1    jruoho     UINT32                  Type,
    563       1.1    jruoho     char                    *Fmt,
    564       1.1    jruoho     ...)
    565       1.1    jruoho {
    566       1.1    jruoho     va_list                 Args;
    567       1.1    jruoho 
    568       1.1    jruoho 
    569      1.22  christos     if (!AslGbl_DebugFlag)
    570       1.1    jruoho     {
    571       1.1    jruoho         return;
    572       1.1    jruoho     }
    573       1.1    jruoho 
    574       1.1    jruoho     if ((Type == ASL_PARSE_OUTPUT) &&
    575       1.1    jruoho         (!(AslCompilerdebug)))
    576       1.1    jruoho     {
    577       1.1    jruoho         return;
    578       1.1    jruoho     }
    579       1.1    jruoho 
    580       1.5  christos     va_start (Args, Fmt);
    581       1.1    jruoho     (void) vfprintf (stderr, Fmt, Args);
    582       1.1    jruoho     va_end (Args);
    583       1.1    jruoho     return;
    584       1.1    jruoho }
    585       1.1    jruoho 
    586       1.1    jruoho 
    587       1.1    jruoho /*******************************************************************************
    588       1.1    jruoho  *
    589       1.1    jruoho  * FUNCTION:    UtSetParseOpName
    590       1.1    jruoho  *
    591       1.6  christos  * PARAMETERS:  Op                  - Parse op to be named.
    592       1.1    jruoho  *
    593       1.1    jruoho  * RETURN:      None
    594       1.1    jruoho  *
    595       1.1    jruoho  * DESCRIPTION: Insert the ascii name of the parse opcode
    596       1.1    jruoho  *
    597       1.1    jruoho  ******************************************************************************/
    598       1.1    jruoho 
    599       1.1    jruoho void
    600       1.1    jruoho UtSetParseOpName (
    601       1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    602       1.1    jruoho {
    603       1.1    jruoho 
    604      1.20  christos     AcpiUtSafeStrncpy (Op->Asl.ParseOpName, UtGetOpName (Op->Asl.ParseOpcode),
    605       1.1    jruoho         ACPI_MAX_PARSEOP_NAME);
    606       1.1    jruoho }
    607       1.1    jruoho 
    608       1.1    jruoho 
    609       1.1    jruoho /*******************************************************************************
    610       1.1    jruoho  *
    611      1.23  christos  * FUNCTION:    UtDisplayOneSummary
    612       1.1    jruoho  *
    613      1.33  christos  * PARAMETERS:  FileID              - ID of output file
    614       1.1    jruoho  *
    615       1.1    jruoho  * RETURN:      None
    616       1.1    jruoho  *
    617      1.23  christos  * DESCRIPTION: Display compilation statistics for one input file
    618       1.1    jruoho  *
    619       1.1    jruoho  ******************************************************************************/
    620       1.1    jruoho 
    621       1.1    jruoho void
    622      1.23  christos UtDisplayOneSummary (
    623      1.23  christos     UINT32                  FileId,
    624      1.23  christos     BOOLEAN                 DisplayErrorSummary)
    625       1.1    jruoho {
    626       1.6  christos     UINT32                  i;
    627      1.23  christos     ASL_GLOBAL_FILE_NODE    *FileNode;
    628      1.24  christos     BOOLEAN                 DisplayAMLSummary;
    629       1.6  christos 
    630       1.1    jruoho 
    631      1.24  christos     DisplayAMLSummary =
    632      1.24  christos         !AslGbl_PreprocessOnly && !AslGbl_ParserErrorDetected &&
    633      1.24  christos         ((AslGbl_ExceptionCount[ASL_ERROR] == 0) || AslGbl_IgnoreErrors) &&
    634      1.24  christos         AslGbl_Files[ASL_FILE_AML_OUTPUT].Handle;
    635      1.24  christos 
    636       1.1    jruoho     if (FileId != ASL_FILE_STDOUT)
    637       1.1    jruoho     {
    638       1.1    jruoho         /* Compiler name and version number */
    639       1.1    jruoho 
    640      1.16  christos         FlPrintFile (FileId, "%s version %X [%s]\n\n",
    641      1.31  christos             ASL_COMPILER_NAME, (UINT32) ACPI_CA_VERSION, ACPI_DATE);
    642       1.1    jruoho     }
    643       1.1    jruoho 
    644       1.6  christos     /* Summary of main input and output files */
    645       1.6  christos 
    646      1.24  christos     FileNode = FlGetCurrentFileNode ();
    647      1.24  christos 
    648      1.24  christos     if (FileNode->ParserErrorDetected)
    649       1.1    jruoho     {
    650       1.1    jruoho         FlPrintFile (FileId,
    651      1.24  christos             "%-14s %s - Compilation aborted due to parser-detected syntax error(s)\n",
    652      1.24  christos             "Input file:", AslGbl_Files[ASL_FILE_INPUT].Filename);
    653      1.24  christos     }
    654      1.24  christos     else if (FileNode->FileType == ASL_INPUT_TYPE_ASCII_DATA)
    655      1.24  christos     {
    656      1.24  christos         FlPrintFile (FileId,
    657      1.24  christos             "%-14s %s - %7u bytes %6u fields %8u source lines\n",
    658       1.6  christos             "Table Input:",
    659      1.24  christos             AslGbl_Files[ASL_FILE_INPUT].Filename,
    660      1.24  christos             FileNode->OriginalInputFileSize, FileNode->TotalFields,
    661      1.24  christos             FileNode->TotalLineCount);
    662       1.1    jruoho 
    663      1.24  christos         FlPrintFile (FileId,
    664      1.24  christos             "%-14s %s - %7u bytes\n",
    665      1.24  christos             "Binary Output:",
    666      1.24  christos             AslGbl_Files[ASL_FILE_AML_OUTPUT].Filename, FileNode->OutputByteLength);
    667       1.1    jruoho     }
    668      1.24  christos     else if (FileNode->FileType == ASL_INPUT_TYPE_ASCII_ASL)
    669       1.1    jruoho     {
    670      1.24  christos         FlPrintFile (FileId,
    671      1.24  christos             "%-14s %s - %7u bytes %6u keywords %6u source lines\n",
    672      1.24  christos             "ASL Input:",
    673      1.24  christos             AslGbl_Files[ASL_FILE_INPUT].Filename,
    674      1.24  christos             FileNode->OriginalInputFileSize,
    675      1.24  christos             FileNode->TotalKeywords,
    676      1.24  christos             FileNode->TotalLineCount);
    677      1.24  christos 
    678      1.24  christos         /* AML summary */
    679      1.24  christos 
    680      1.24  christos         if (DisplayAMLSummary)
    681      1.23  christos         {
    682      1.23  christos             FlPrintFile (FileId,
    683      1.24  christos                 "%-14s %s - %7u bytes %6u opcodes  %6u named objects\n",
    684      1.24  christos                 "AML Output:",
    685      1.24  christos                 AslGbl_Files[ASL_FILE_AML_OUTPUT].Filename,
    686      1.24  christos                 FlGetFileSize (ASL_FILE_AML_OUTPUT),
    687      1.24  christos                 FileNode->TotalExecutableOpcodes,
    688      1.24  christos                 FileNode->TotalNamedObjects);
    689       1.1    jruoho         }
    690       1.1    jruoho     }
    691       1.1    jruoho 
    692       1.6  christos     /* Display summary of any optional files */
    693       1.6  christos 
    694       1.6  christos     for (i = ASL_FILE_SOURCE_OUTPUT; i <= ASL_MAX_FILE_TYPE; i++)
    695       1.6  christos     {
    696      1.22  christos         if (!AslGbl_Files[i].Filename || !AslGbl_Files[i].Handle)
    697       1.6  christos         {
    698       1.6  christos             continue;
    699       1.6  christos         }
    700       1.6  christos 
    701       1.6  christos         /* .SRC is a temp file unless specifically requested */
    702       1.6  christos 
    703      1.22  christos         if ((i == ASL_FILE_SOURCE_OUTPUT) && (!AslGbl_SourceOutputFlag))
    704       1.6  christos         {
    705       1.6  christos             continue;
    706       1.6  christos         }
    707       1.6  christos 
    708      1.12  christos         /* .PRE is the preprocessor intermediate file */
    709       1.6  christos 
    710      1.22  christos         if ((i == ASL_FILE_PREPROCESSOR)  && (!AslGbl_KeepPreprocessorTempFile))
    711       1.6  christos         {
    712       1.6  christos             continue;
    713       1.6  christos         }
    714       1.6  christos 
    715      1.24  christos         FlPrintFile (FileId, "%-14s %s - %7u bytes\n",
    716      1.23  christos             AslGbl_FileDescs[i].ShortDescription,
    717      1.22  christos             AslGbl_Files[i].Filename, FlGetFileSize (i));
    718       1.6  christos     }
    719       1.6  christos 
    720      1.23  christos 
    721      1.23  christos     /*
    722      1.23  christos      * Optionally emit an error summary for a file. This is used to enhance the
    723      1.23  christos      * appearance of listing files.
    724      1.23  christos      */
    725      1.23  christos     if (DisplayErrorSummary)
    726      1.23  christos     {
    727      1.23  christos         UtDisplayErrorSummary (FileId);
    728      1.23  christos     }
    729      1.23  christos }
    730      1.23  christos 
    731      1.23  christos 
    732      1.23  christos /*******************************************************************************
    733      1.23  christos  *
    734      1.23  christos  * FUNCTION:    UtDisplayErrorSummary
    735      1.23  christos  *
    736      1.33  christos  * PARAMETERS:  FileID              - ID of output file
    737      1.23  christos  *
    738      1.23  christos  * RETURN:      None
    739      1.23  christos  *
    740      1.23  christos  * DESCRIPTION: Display compilation statistics for all input files
    741      1.23  christos  *
    742      1.23  christos  ******************************************************************************/
    743      1.23  christos 
    744      1.23  christos static void
    745      1.23  christos UtDisplayErrorSummary (
    746      1.23  christos     UINT32                  FileId)
    747      1.23  christos {
    748      1.23  christos     BOOLEAN                 ErrorDetected;
    749      1.23  christos 
    750      1.23  christos 
    751      1.23  christos     ErrorDetected = AslGbl_ParserErrorDetected ||
    752      1.23  christos         ((AslGbl_ExceptionCount[ASL_ERROR] > 0) && !AslGbl_IgnoreErrors);
    753      1.23  christos 
    754      1.23  christos     if (ErrorDetected)
    755      1.23  christos     {
    756      1.23  christos         FlPrintFile (FileId, "\nCompilation failed. ");
    757      1.23  christos     }
    758      1.23  christos     else
    759      1.23  christos     {
    760      1.23  christos         FlPrintFile (FileId, "\nCompilation successful. ");
    761      1.23  christos     }
    762       1.1    jruoho 
    763       1.1    jruoho     FlPrintFile (FileId,
    764      1.23  christos         "%u Errors, %u Warnings, %u Remarks",
    765      1.22  christos         AslGbl_ExceptionCount[ASL_ERROR],
    766      1.22  christos         AslGbl_ExceptionCount[ASL_WARNING] +
    767      1.22  christos             AslGbl_ExceptionCount[ASL_WARNING2] +
    768      1.22  christos             AslGbl_ExceptionCount[ASL_WARNING3],
    769      1.22  christos         AslGbl_ExceptionCount[ASL_REMARK]);
    770       1.1    jruoho 
    771      1.22  christos     if (AslGbl_FileType != ASL_INPUT_TYPE_ASCII_DATA)
    772       1.1    jruoho     {
    773      1.23  christos         if (AslGbl_ParserErrorDetected)
    774      1.23  christos         {
    775      1.23  christos             FlPrintFile (FileId,
    776      1.23  christos                 "\nNo AML files were generated due to syntax error(s)\n");
    777      1.23  christos             return;
    778      1.23  christos         }
    779      1.23  christos         else if (ErrorDetected)
    780      1.23  christos         {
    781      1.23  christos             FlPrintFile (FileId,
    782      1.23  christos                 "\nNo AML files were generated due to compiler error(s)\n");
    783      1.23  christos             return;
    784      1.23  christos         }
    785      1.23  christos 
    786      1.10  christos         FlPrintFile (FileId, ", %u Optimizations",
    787      1.22  christos             AslGbl_ExceptionCount[ASL_OPTIMIZATION]);
    788      1.10  christos 
    789      1.22  christos         if (AslGbl_TotalFolds)
    790      1.10  christos         {
    791      1.22  christos             FlPrintFile (FileId, ", %u Constants Folded", AslGbl_TotalFolds);
    792      1.10  christos         }
    793       1.1    jruoho     }
    794       1.1    jruoho 
    795       1.1    jruoho     FlPrintFile (FileId, "\n");
    796       1.1    jruoho }
    797       1.1    jruoho 
    798       1.1    jruoho 
    799       1.1    jruoho /*******************************************************************************
    800       1.1    jruoho  *
    801      1.23  christos  * FUNCTION:    UtDisplaySummary
    802      1.23  christos  *
    803      1.33  christos  * PARAMETERS:  FileID              - ID of output file
    804      1.23  christos  *
    805      1.23  christos  * RETURN:      None
    806      1.23  christos  *
    807      1.23  christos  * DESCRIPTION: Display compilation statistics for all input files
    808      1.23  christos  *
    809      1.23  christos  ******************************************************************************/
    810      1.23  christos 
    811      1.23  christos void
    812      1.23  christos UtDisplaySummary (
    813      1.23  christos     UINT32                  FileId)
    814      1.23  christos {
    815      1.23  christos     ASL_GLOBAL_FILE_NODE    *Current = AslGbl_FilesList;
    816      1.23  christos 
    817      1.23  christos 
    818      1.23  christos     while (Current)
    819      1.23  christos     {
    820      1.23  christos         switch  (FlSwitchFileSet(Current->Files[ASL_FILE_INPUT].Filename))
    821      1.23  christos         {
    822      1.23  christos             case SWITCH_TO_SAME_FILE:
    823      1.23  christos             case SWITCH_TO_DIFFERENT_FILE:
    824      1.23  christos 
    825      1.23  christos                 UtDisplayOneSummary (FileId, FALSE);
    826      1.23  christos                 Current = Current->Next;
    827      1.23  christos                 break;
    828      1.23  christos 
    829      1.23  christos             case FILE_NOT_FOUND:
    830      1.23  christos             default:
    831      1.23  christos 
    832      1.23  christos                 Current = NULL;
    833      1.23  christos                 break;
    834      1.23  christos         }
    835      1.23  christos     }
    836      1.23  christos     UtDisplayErrorSummary (FileId);
    837      1.23  christos }
    838      1.23  christos 
    839      1.23  christos /*******************************************************************************
    840      1.23  christos  *
    841       1.6  christos  * FUNCTION:    UtCheckIntegerRange
    842       1.1    jruoho  *
    843       1.6  christos  * PARAMETERS:  Op                  - Integer parse node
    844       1.6  christos  *              LowValue            - Smallest allowed value
    845       1.6  christos  *              HighValue           - Largest allowed value
    846       1.1    jruoho  *
    847       1.1    jruoho  * RETURN:      Op if OK, otherwise NULL
    848       1.1    jruoho  *
    849       1.1    jruoho  * DESCRIPTION: Check integer for an allowable range
    850       1.1    jruoho  *
    851       1.1    jruoho  ******************************************************************************/
    852       1.1    jruoho 
    853       1.1    jruoho ACPI_PARSE_OBJECT *
    854       1.1    jruoho UtCheckIntegerRange (
    855       1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
    856       1.1    jruoho     UINT32                  LowValue,
    857       1.1    jruoho     UINT32                  HighValue)
    858       1.1    jruoho {
    859       1.1    jruoho 
    860       1.1    jruoho     if (!Op)
    861       1.1    jruoho     {
    862       1.6  christos         return (NULL);
    863       1.1    jruoho     }
    864       1.1    jruoho 
    865       1.6  christos     if ((Op->Asl.Value.Integer < LowValue) ||
    866       1.6  christos         (Op->Asl.Value.Integer > HighValue))
    867       1.1    jruoho     {
    868      1.22  christos         snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "0x%X, allowable: 0x%X-0x%X",
    869       1.6  christos             (UINT32) Op->Asl.Value.Integer, LowValue, HighValue);
    870       1.1    jruoho 
    871      1.22  christos         AslError (ASL_ERROR, ASL_MSG_RANGE, Op, AslGbl_MsgBuffer);
    872       1.6  christos         return (NULL);
    873       1.1    jruoho     }
    874       1.1    jruoho 
    875       1.6  christos     return (Op);
    876       1.1    jruoho }
    877       1.1    jruoho 
    878       1.1    jruoho 
    879       1.1    jruoho /*******************************************************************************
    880       1.1    jruoho  *
    881       1.1    jruoho  * FUNCTION:    UtInternalizeName
    882       1.1    jruoho  *
    883       1.6  christos  * PARAMETERS:  ExternalName        - Name to convert
    884       1.6  christos  *              ConvertedName       - Where the converted name is returned
    885       1.1    jruoho  *
    886       1.1    jruoho  * RETURN:      Status
    887       1.1    jruoho  *
    888       1.1    jruoho  * DESCRIPTION: Convert an external (ASL) name to an internal (AML) name
    889       1.1    jruoho  *
    890       1.1    jruoho  ******************************************************************************/
    891       1.1    jruoho 
    892       1.1    jruoho ACPI_STATUS
    893       1.1    jruoho UtInternalizeName (
    894       1.1    jruoho     char                    *ExternalName,
    895       1.1    jruoho     char                    **ConvertedName)
    896       1.1    jruoho {
    897       1.1    jruoho     ACPI_NAMESTRING_INFO    Info;
    898       1.1    jruoho     ACPI_STATUS             Status;
    899       1.1    jruoho 
    900       1.1    jruoho 
    901       1.1    jruoho     if (!ExternalName)
    902       1.1    jruoho     {
    903       1.1    jruoho         return (AE_OK);
    904       1.1    jruoho     }
    905       1.1    jruoho 
    906       1.1    jruoho     /* Get the length of the new internal name */
    907       1.1    jruoho 
    908       1.1    jruoho     Info.ExternalName = ExternalName;
    909       1.1    jruoho     AcpiNsGetInternalNameLength (&Info);
    910       1.1    jruoho 
    911       1.9  christos     /* We need a segment to store the internal name */
    912       1.1    jruoho 
    913      1.19  christos     Info.InternalName = UtLocalCacheCalloc (Info.Length);
    914       1.1    jruoho 
    915       1.1    jruoho     /* Build the name */
    916       1.1    jruoho 
    917       1.1    jruoho     Status = AcpiNsBuildInternalName (&Info);
    918       1.1    jruoho     if (ACPI_FAILURE (Status))
    919       1.1    jruoho     {
    920       1.1    jruoho         return (Status);
    921       1.1    jruoho     }
    922       1.1    jruoho 
    923       1.1    jruoho     *ConvertedName = Info.InternalName;
    924       1.1    jruoho     return (AE_OK);
    925       1.1    jruoho }
    926       1.1    jruoho 
    927       1.1    jruoho 
    928       1.1    jruoho /*******************************************************************************
    929       1.1    jruoho  *
    930       1.1    jruoho  * FUNCTION:    UtPadNameWithUnderscores
    931       1.1    jruoho  *
    932       1.6  christos  * PARAMETERS:  NameSeg             - Input nameseg
    933       1.6  christos  *              PaddedNameSeg       - Output padded nameseg
    934       1.1    jruoho  *
    935       1.1    jruoho  * RETURN:      Padded nameseg.
    936       1.1    jruoho  *
    937       1.1    jruoho  * DESCRIPTION: Pads a NameSeg with underscores if necessary to form a full
    938       1.1    jruoho  *              ACPI_NAME.
    939       1.1    jruoho  *
    940       1.1    jruoho  ******************************************************************************/
    941       1.1    jruoho 
    942       1.1    jruoho static void
    943       1.1    jruoho UtPadNameWithUnderscores (
    944       1.1    jruoho     char                    *NameSeg,
    945       1.1    jruoho     char                    *PaddedNameSeg)
    946       1.1    jruoho {
    947       1.1    jruoho     UINT32                  i;
    948       1.1    jruoho 
    949       1.1    jruoho 
    950      1.23  christos     for (i = 0; (i < ACPI_NAMESEG_SIZE); i++)
    951       1.1    jruoho     {
    952       1.1    jruoho         if (*NameSeg)
    953       1.1    jruoho         {
    954       1.1    jruoho             *PaddedNameSeg = *NameSeg;
    955       1.1    jruoho             NameSeg++;
    956       1.1    jruoho         }
    957       1.1    jruoho         else
    958       1.1    jruoho         {
    959       1.1    jruoho             *PaddedNameSeg = '_';
    960       1.1    jruoho         }
    961      1.13  christos 
    962       1.1    jruoho         PaddedNameSeg++;
    963       1.1    jruoho     }
    964       1.1    jruoho }
    965       1.1    jruoho 
    966       1.1    jruoho 
    967       1.1    jruoho /*******************************************************************************
    968       1.1    jruoho  *
    969       1.1    jruoho  * FUNCTION:    UtAttachNameseg
    970       1.1    jruoho  *
    971       1.6  christos  * PARAMETERS:  Op                  - Parent parse node
    972       1.6  christos  *              Name                - Full ExternalName
    973       1.1    jruoho  *
    974       1.1    jruoho  * RETURN:      None; Sets the NameSeg field in parent node
    975       1.1    jruoho  *
    976       1.1    jruoho  * DESCRIPTION: Extract the last nameseg of the ExternalName and store it
    977       1.1    jruoho  *              in the NameSeg field of the Op.
    978       1.1    jruoho  *
    979       1.1    jruoho  ******************************************************************************/
    980       1.1    jruoho 
    981       1.1    jruoho static void
    982       1.1    jruoho UtAttachNameseg (
    983       1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
    984       1.1    jruoho     char                    *Name)
    985       1.1    jruoho {
    986       1.1    jruoho     char                    *NameSeg;
    987       1.1    jruoho     char                    PaddedNameSeg[4];
    988       1.1    jruoho 
    989       1.1    jruoho 
    990       1.1    jruoho     if (!Name)
    991       1.1    jruoho     {
    992       1.1    jruoho         return;
    993       1.1    jruoho     }
    994       1.1    jruoho 
    995       1.1    jruoho     /* Look for the last dot in the namepath */
    996       1.1    jruoho 
    997       1.1    jruoho     NameSeg = strrchr (Name, '.');
    998       1.1    jruoho     if (NameSeg)
    999       1.1    jruoho     {
   1000       1.1    jruoho         /* Found last dot, we have also found the final nameseg */
   1001       1.1    jruoho 
   1002       1.1    jruoho         NameSeg++;
   1003       1.1    jruoho         UtPadNameWithUnderscores (NameSeg, PaddedNameSeg);
   1004       1.1    jruoho     }
   1005       1.1    jruoho     else
   1006       1.1    jruoho     {
   1007       1.1    jruoho         /* No dots in the namepath, there is only a single nameseg. */
   1008       1.1    jruoho         /* Handle prefixes */
   1009       1.1    jruoho 
   1010       1.6  christos         while (ACPI_IS_ROOT_PREFIX (*Name) ||
   1011       1.6  christos                ACPI_IS_PARENT_PREFIX (*Name))
   1012       1.1    jruoho         {
   1013       1.1    jruoho             Name++;
   1014       1.1    jruoho         }
   1015       1.1    jruoho 
   1016       1.6  christos         /* Remaining string should be one single nameseg */
   1017       1.1    jruoho 
   1018       1.1    jruoho         UtPadNameWithUnderscores (Name, PaddedNameSeg);
   1019       1.1    jruoho     }
   1020       1.1    jruoho 
   1021      1.23  christos     ACPI_COPY_NAMESEG (Op->Asl.NameSeg, PaddedNameSeg);
   1022       1.1    jruoho }
   1023       1.1    jruoho 
   1024       1.1    jruoho 
   1025       1.1    jruoho /*******************************************************************************
   1026       1.1    jruoho  *
   1027       1.1    jruoho  * FUNCTION:    UtAttachNamepathToOwner
   1028       1.1    jruoho  *
   1029       1.6  christos  * PARAMETERS:  Op                  - Parent parse node
   1030       1.6  christos  *              NameOp              - Node that contains the name
   1031       1.1    jruoho  *
   1032       1.1    jruoho  * RETURN:      Sets the ExternalName and Namepath in the parent node
   1033       1.1    jruoho  *
   1034       1.6  christos  * DESCRIPTION: Store the name in two forms in the parent node: The original
   1035       1.1    jruoho  *              (external) name, and the internalized name that is used within
   1036       1.1    jruoho  *              the ACPI namespace manager.
   1037       1.1    jruoho  *
   1038       1.1    jruoho  ******************************************************************************/
   1039       1.1    jruoho 
   1040       1.1    jruoho void
   1041       1.1    jruoho UtAttachNamepathToOwner (
   1042       1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
   1043       1.1    jruoho     ACPI_PARSE_OBJECT       *NameOp)
   1044       1.1    jruoho {
   1045       1.1    jruoho     ACPI_STATUS             Status;
   1046       1.1    jruoho 
   1047       1.1    jruoho 
   1048       1.1    jruoho     /* Full external path */
   1049       1.1    jruoho 
   1050       1.1    jruoho     Op->Asl.ExternalName = NameOp->Asl.Value.String;
   1051       1.1    jruoho 
   1052       1.1    jruoho     /* Save the NameOp for possible error reporting later */
   1053       1.1    jruoho 
   1054       1.1    jruoho     Op->Asl.ParentMethod = (void *) NameOp;
   1055       1.1    jruoho 
   1056       1.1    jruoho     /* Last nameseg of the path */
   1057       1.1    jruoho 
   1058       1.1    jruoho     UtAttachNameseg (Op, Op->Asl.ExternalName);
   1059       1.1    jruoho 
   1060       1.1    jruoho     /* Create internalized path */
   1061       1.1    jruoho 
   1062       1.1    jruoho     Status = UtInternalizeName (NameOp->Asl.Value.String, &Op->Asl.Namepath);
   1063       1.1    jruoho     if (ACPI_FAILURE (Status))
   1064       1.1    jruoho     {
   1065       1.1    jruoho         /* TBD: abort on no memory */
   1066       1.1    jruoho     }
   1067       1.1    jruoho }
   1068       1.1    jruoho 
   1069       1.1    jruoho 
   1070       1.1    jruoho /*******************************************************************************
   1071       1.1    jruoho  *
   1072      1.24  christos  * FUNCTION:    UtNameContainsAllPrefix
   1073      1.24  christos  *
   1074      1.24  christos  * PARAMETERS:  Op                  - Op containing NameString
   1075      1.24  christos  *
   1076      1.24  christos  * RETURN:      NameString consists of all ^ characters
   1077      1.24  christos  *
   1078      1.24  christos  * DESCRIPTION: Determine if this Op contains a name segment that consists of
   1079      1.24  christos  *              all '^' characters.
   1080      1.24  christos  *
   1081      1.24  christos  ******************************************************************************/
   1082      1.24  christos 
   1083      1.24  christos BOOLEAN
   1084      1.24  christos UtNameContainsAllPrefix (
   1085      1.24  christos     ACPI_PARSE_OBJECT       *Op)
   1086      1.24  christos {
   1087      1.24  christos     UINT32                  Length = Op->Asl.AmlLength;
   1088      1.24  christos     UINT32                  i;
   1089      1.24  christos 
   1090      1.24  christos     for (i = 0; i < Length; i++)
   1091      1.24  christos     {
   1092      1.24  christos         if (Op->Asl.Value.String[i] != '^')
   1093      1.24  christos         {
   1094      1.24  christos             return (FALSE);
   1095      1.24  christos         }
   1096      1.24  christos     }
   1097      1.24  christos 
   1098      1.24  christos     return (TRUE);
   1099      1.24  christos }
   1100      1.24  christos 
   1101      1.24  christos /*******************************************************************************
   1102      1.24  christos  *
   1103       1.1    jruoho  * FUNCTION:    UtDoConstant
   1104       1.1    jruoho  *
   1105      1.18  christos  * PARAMETERS:  String              - Hex/Decimal/Octal
   1106       1.1    jruoho  *
   1107       1.1    jruoho  * RETURN:      Converted Integer
   1108       1.1    jruoho  *
   1109      1.18  christos  * DESCRIPTION: Convert a string to an integer, with overflow/error checking.
   1110       1.1    jruoho  *
   1111       1.1    jruoho  ******************************************************************************/
   1112       1.1    jruoho 
   1113       1.1    jruoho UINT64
   1114       1.1    jruoho UtDoConstant (
   1115       1.1    jruoho     char                    *String)
   1116       1.1    jruoho {
   1117       1.1    jruoho     ACPI_STATUS             Status;
   1118      1.18  christos     UINT64                  ConvertedInteger;
   1119      1.27  christos     char                    ErrBuf[128];
   1120      1.27  christos     const ACPI_EXCEPTION_INFO *ExceptionInfo;
   1121       1.1    jruoho 
   1122       1.1    jruoho 
   1123      1.18  christos     Status = AcpiUtStrtoul64 (String, &ConvertedInteger);
   1124       1.1    jruoho     if (ACPI_FAILURE (Status))
   1125       1.1    jruoho     {
   1126      1.27  christos         ExceptionInfo = AcpiUtValidateException ((ACPI_STATUS) Status);
   1127      1.27  christos         snprintf (ErrBuf, sizeof(ErrBuf), " %s while converting to 64-bit integer",
   1128      1.27  christos             ExceptionInfo->Description);
   1129      1.18  christos 
   1130      1.22  christos         AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, AslGbl_CurrentLineNumber,
   1131      1.22  christos             AslGbl_LogicalLineNumber, AslGbl_CurrentLineOffset,
   1132      1.22  christos             AslGbl_CurrentColumn, AslGbl_Files[ASL_FILE_INPUT].Filename, ErrBuf);
   1133       1.1    jruoho     }
   1134       1.1    jruoho 
   1135      1.18  christos     return (ConvertedInteger);
   1136       1.1    jruoho }
   1137      1.24  christos 
   1138      1.24  christos 
   1139      1.24  christos /******************************************************************************
   1140      1.24  christos  *
   1141      1.24  christos  * FUNCTION:    AcpiUtStrdup
   1142      1.24  christos  *
   1143      1.24  christos  * PARAMETERS:  String1             - string to duplicate
   1144      1.24  christos  *
   1145      1.24  christos  * RETURN:      int that signifies string relationship. Zero means strings
   1146      1.24  christos  *              are equal.
   1147      1.24  christos  *
   1148      1.24  christos  * DESCRIPTION: Duplicate the string using UtCacheAlloc to avoid manual memory
   1149      1.24  christos  *              reclamation.
   1150      1.24  christos  *
   1151      1.24  christos  ******************************************************************************/
   1152      1.24  christos 
   1153      1.24  christos char *
   1154      1.24  christos AcpiUtStrdup (
   1155      1.24  christos     char                    *String)
   1156      1.24  christos {
   1157      1.24  christos     char                    *NewString = (char *) UtLocalCalloc (strlen (String) + 1);
   1158      1.24  christos 
   1159      1.24  christos 
   1160      1.24  christos     strcpy (NewString, String);
   1161      1.24  christos     return (NewString);
   1162      1.24  christos }
   1163      1.24  christos 
   1164      1.24  christos 
   1165      1.24  christos /******************************************************************************
   1166      1.24  christos  *
   1167      1.24  christos  * FUNCTION:    AcpiUtStrcat
   1168      1.24  christos  *
   1169      1.24  christos  * PARAMETERS:  String1
   1170      1.24  christos  *              String2
   1171      1.24  christos  *
   1172      1.24  christos  * RETURN:      New string with String1 concatenated with String2
   1173      1.24  christos  *
   1174      1.24  christos  * DESCRIPTION: Concatenate string1 and string2
   1175      1.24  christos  *
   1176      1.24  christos  ******************************************************************************/
   1177      1.24  christos 
   1178      1.24  christos char *
   1179      1.24  christos AcpiUtStrcat (
   1180      1.24  christos     char                    *String1,
   1181      1.24  christos     char                    *String2)
   1182      1.24  christos {
   1183      1.24  christos     UINT32                  String1Length = strlen (String1);
   1184      1.24  christos     char                    *NewString = (char *) UtLocalCalloc (strlen (String1) + strlen (String2) + 1);
   1185      1.24  christos 
   1186      1.24  christos     strcpy (NewString, String1);
   1187      1.24  christos     strcpy (NewString + String1Length, String2);
   1188      1.24  christos     return (NewString);
   1189      1.24  christos }
   1190