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