xref: /illumos-gate/usr/src/cmd/acpi/iasl/aslutils.c (revision 20a2a10f)
1bc36eafdSMike Gerdts /******************************************************************************
2bc36eafdSMike Gerdts  *
3bc36eafdSMike Gerdts  * Module Name: aslutils -- compiler utilities
4bc36eafdSMike Gerdts  *
5bc36eafdSMike Gerdts  *****************************************************************************/
6bc36eafdSMike Gerdts 
735786f68SRobert Mustacchi /******************************************************************************
835786f68SRobert Mustacchi  *
935786f68SRobert Mustacchi  * 1. Copyright Notice
1035786f68SRobert Mustacchi  *
1135786f68SRobert Mustacchi  * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12bc36eafdSMike Gerdts  * All rights reserved.
13bc36eafdSMike Gerdts  *
1435786f68SRobert Mustacchi  * 2. License
1535786f68SRobert Mustacchi  *
1635786f68SRobert Mustacchi  * 2.1. This is your license from Intel Corp. under its intellectual property
1735786f68SRobert Mustacchi  * rights. You may have additional license terms from the party that provided
1835786f68SRobert Mustacchi  * you this software, covering your right to use that party's intellectual
1935786f68SRobert Mustacchi  * property rights.
2035786f68SRobert Mustacchi  *
2135786f68SRobert Mustacchi  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2235786f68SRobert Mustacchi  * copy of the source code appearing in this file ("Covered Code") an
2335786f68SRobert Mustacchi  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2435786f68SRobert Mustacchi  * base code distributed originally by Intel ("Original Intel Code") to copy,
2535786f68SRobert Mustacchi  * make derivatives, distribute, use and display any portion of the Covered
2635786f68SRobert Mustacchi  * Code in any form, with the right to sublicense such rights; and
2735786f68SRobert Mustacchi  *
2835786f68SRobert Mustacchi  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
2935786f68SRobert Mustacchi  * license (with the right to sublicense), under only those claims of Intel
3035786f68SRobert Mustacchi  * patents that are infringed by the Original Intel Code, to make, use, sell,
3135786f68SRobert Mustacchi  * offer to sell, and import the Covered Code and derivative works thereof
3235786f68SRobert Mustacchi  * solely to the minimum extent necessary to exercise the above copyright
3335786f68SRobert Mustacchi  * license, and in no event shall the patent license extend to any additions
3435786f68SRobert Mustacchi  * to or modifications of the Original Intel Code. No other license or right
3535786f68SRobert Mustacchi  * is granted directly or by implication, estoppel or otherwise;
3635786f68SRobert Mustacchi  *
3735786f68SRobert Mustacchi  * The above copyright and patent license is granted only if the following
3835786f68SRobert Mustacchi  * conditions are met:
3935786f68SRobert Mustacchi  *
4035786f68SRobert Mustacchi  * 3. Conditions
4135786f68SRobert Mustacchi  *
4235786f68SRobert Mustacchi  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4335786f68SRobert Mustacchi  * Redistribution of source code of any substantial portion of the Covered
4435786f68SRobert Mustacchi  * Code or modification with rights to further distribute source must include
4535786f68SRobert Mustacchi  * the above Copyright Notice, the above License, this list of Conditions,
4635786f68SRobert Mustacchi  * and the following Disclaimer and Export Compliance provision. In addition,
4735786f68SRobert Mustacchi  * Licensee must cause all Covered Code to which Licensee contributes to
4835786f68SRobert Mustacchi  * contain a file documenting the changes Licensee made to create that Covered
4935786f68SRobert Mustacchi  * Code and the date of any change. Licensee must include in that file the
5035786f68SRobert Mustacchi  * documentation of any changes made by any predecessor Licensee. Licensee
5135786f68SRobert Mustacchi  * must include a prominent statement that the modification is derived,
5235786f68SRobert Mustacchi  * directly or indirectly, from Original Intel Code.
5335786f68SRobert Mustacchi  *
5435786f68SRobert Mustacchi  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5535786f68SRobert Mustacchi  * Redistribution of source code of any substantial portion of the Covered
5635786f68SRobert Mustacchi  * Code or modification without rights to further distribute source must
5735786f68SRobert Mustacchi  * include the following Disclaimer and Export Compliance provision in the
5835786f68SRobert Mustacchi  * documentation and/or other materials provided with distribution. In
5935786f68SRobert Mustacchi  * addition, Licensee may not authorize further sublicense of source of any
6035786f68SRobert Mustacchi  * portion of the Covered Code, and must include terms to the effect that the
6135786f68SRobert Mustacchi  * license from Licensee to its licensee is limited to the intellectual
6235786f68SRobert Mustacchi  * property embodied in the software Licensee provides to its licensee, and
6335786f68SRobert Mustacchi  * not to intellectual property embodied in modifications its licensee may
6435786f68SRobert Mustacchi  * make.
6535786f68SRobert Mustacchi  *
6635786f68SRobert Mustacchi  * 3.3. Redistribution of Executable. Redistribution in executable form of any
6735786f68SRobert Mustacchi  * substantial portion of the Covered Code or modification must reproduce the
6835786f68SRobert Mustacchi  * above Copyright Notice, and the following Disclaimer and Export Compliance
6935786f68SRobert Mustacchi  * provision in the documentation and/or other materials provided with the
7035786f68SRobert Mustacchi  * distribution.
7135786f68SRobert Mustacchi  *
7235786f68SRobert Mustacchi  * 3.4. Intel retains all right, title, and interest in and to the Original
7335786f68SRobert Mustacchi  * Intel Code.
7435786f68SRobert Mustacchi  *
7535786f68SRobert Mustacchi  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7635786f68SRobert Mustacchi  * Intel shall be used in advertising or otherwise to promote the sale, use or
7735786f68SRobert Mustacchi  * other dealings in products derived from or relating to the Covered Code
7835786f68SRobert Mustacchi  * without prior written authorization from Intel.
7935786f68SRobert Mustacchi  *
8035786f68SRobert Mustacchi  * 4. Disclaimer and Export Compliance
8135786f68SRobert Mustacchi  *
8235786f68SRobert Mustacchi  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8335786f68SRobert Mustacchi  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8435786f68SRobert Mustacchi  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
8535786f68SRobert Mustacchi  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
8635786f68SRobert Mustacchi  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
8735786f68SRobert Mustacchi  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
8835786f68SRobert Mustacchi  * PARTICULAR PURPOSE.
8935786f68SRobert Mustacchi  *
9035786f68SRobert Mustacchi  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9135786f68SRobert Mustacchi  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9235786f68SRobert Mustacchi  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9335786f68SRobert Mustacchi  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9435786f68SRobert Mustacchi  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9535786f68SRobert Mustacchi  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
9635786f68SRobert Mustacchi  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9735786f68SRobert Mustacchi  * LIMITED REMEDY.
9835786f68SRobert Mustacchi  *
9935786f68SRobert Mustacchi  * 4.3. Licensee shall not export, either directly or indirectly, any of this
10035786f68SRobert Mustacchi  * software or system incorporating such software without first obtaining any
10135786f68SRobert Mustacchi  * required license or other approval from the U. S. Department of Commerce or
10235786f68SRobert Mustacchi  * any other agency or department of the United States Government. In the
10335786f68SRobert Mustacchi  * event Licensee exports any such software from the United States or
10435786f68SRobert Mustacchi  * re-exports any such software from a foreign destination, Licensee shall
10535786f68SRobert Mustacchi  * ensure that the distribution and export/re-export of the software is in
10635786f68SRobert Mustacchi  * compliance with all laws, regulations, orders, or other restrictions of the
10735786f68SRobert Mustacchi  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
10835786f68SRobert Mustacchi  * any of its subsidiaries will export/re-export any technical data, process,
10935786f68SRobert Mustacchi  * software, or service, directly or indirectly, to any country for which the
11035786f68SRobert Mustacchi  * United States government or any agency thereof requires an export license,
11135786f68SRobert Mustacchi  * other governmental approval, or letter of assurance, without first obtaining
11235786f68SRobert Mustacchi  * such license, approval or letter.
11335786f68SRobert Mustacchi  *
11435786f68SRobert Mustacchi  *****************************************************************************
11535786f68SRobert Mustacchi  *
11635786f68SRobert Mustacchi  * Alternatively, you may choose to be licensed under the terms of the
11735786f68SRobert Mustacchi  * following license:
11835786f68SRobert Mustacchi  *
119bc36eafdSMike Gerdts  * Redistribution and use in source and binary forms, with or without
120bc36eafdSMike Gerdts  * modification, are permitted provided that the following conditions
121bc36eafdSMike Gerdts  * are met:
122bc36eafdSMike Gerdts  * 1. Redistributions of source code must retain the above copyright
123bc36eafdSMike Gerdts  *    notice, this list of conditions, and the following disclaimer,
124bc36eafdSMike Gerdts  *    without modification.
125bc36eafdSMike Gerdts  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126bc36eafdSMike Gerdts  *    substantially similar to the "NO WARRANTY" disclaimer below
127bc36eafdSMike Gerdts  *    ("Disclaimer") and any redistribution must be conditioned upon
128bc36eafdSMike Gerdts  *    including a substantially similar Disclaimer requirement for further
129bc36eafdSMike Gerdts  *    binary redistribution.
130bc36eafdSMike Gerdts  * 3. Neither the names of the above-listed copyright holders nor the names
131bc36eafdSMike Gerdts  *    of any contributors may be used to endorse or promote products derived
132bc36eafdSMike Gerdts  *    from this software without specific prior written permission.
133bc36eafdSMike Gerdts  *
134bc36eafdSMike Gerdts  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135bc36eafdSMike Gerdts  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
13635786f68SRobert Mustacchi  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137bc36eafdSMike Gerdts  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
13835786f68SRobert Mustacchi  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
13935786f68SRobert Mustacchi  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
14035786f68SRobert Mustacchi  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
14135786f68SRobert Mustacchi  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
14235786f68SRobert Mustacchi  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14335786f68SRobert Mustacchi  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14435786f68SRobert Mustacchi  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14535786f68SRobert Mustacchi  *
14635786f68SRobert Mustacchi  * Alternatively, you may choose to be licensed under the terms of the
14735786f68SRobert Mustacchi  * GNU General Public License ("GPL") version 2 as published by the Free
14835786f68SRobert Mustacchi  * Software Foundation.
14935786f68SRobert Mustacchi  *
15035786f68SRobert Mustacchi  *****************************************************************************/
151bc36eafdSMike Gerdts 
152bc36eafdSMike Gerdts #include "aslcompiler.h"
153bc36eafdSMike Gerdts #include "aslcompiler.y.h"
154bc36eafdSMike Gerdts #include "acdisasm.h"
155bc36eafdSMike Gerdts #include "acnamesp.h"
156bc36eafdSMike Gerdts #include "amlcode.h"
157bc36eafdSMike Gerdts #include "acapps.h"
158bc36eafdSMike Gerdts #include <sys/stat.h>
159bc36eafdSMike Gerdts 
160bc36eafdSMike Gerdts 
161bc36eafdSMike Gerdts #define _COMPONENT          ACPI_COMPILER
162bc36eafdSMike Gerdts         ACPI_MODULE_NAME    ("aslutils")
163bc36eafdSMike Gerdts 
164bc36eafdSMike Gerdts 
165bc36eafdSMike Gerdts /* Local prototypes */
166bc36eafdSMike Gerdts 
167bc36eafdSMike Gerdts static void
168bc36eafdSMike Gerdts UtPadNameWithUnderscores (
169bc36eafdSMike Gerdts     char                    *NameSeg,
170bc36eafdSMike Gerdts     char                    *PaddedNameSeg);
171bc36eafdSMike Gerdts 
172bc36eafdSMike Gerdts static void
173bc36eafdSMike Gerdts UtAttachNameseg (
174bc36eafdSMike Gerdts     ACPI_PARSE_OBJECT       *Op,
175bc36eafdSMike Gerdts     char                    *Name);
176bc36eafdSMike Gerdts 
177bc36eafdSMike Gerdts 
178bc36eafdSMike Gerdts /*******************************************************************************
179bc36eafdSMike Gerdts  *
180bc36eafdSMike Gerdts  * FUNCTION:    UtIsBigEndianMachine
181bc36eafdSMike Gerdts  *
182bc36eafdSMike Gerdts  * PARAMETERS:  None
183bc36eafdSMike Gerdts  *
184bc36eafdSMike Gerdts  * RETURN:      TRUE if machine is big endian
185bc36eafdSMike Gerdts  *              FALSE if machine is little endian
186bc36eafdSMike Gerdts  *
187bc36eafdSMike Gerdts  * DESCRIPTION: Detect whether machine is little endian or big endian.
188bc36eafdSMike Gerdts  *
189bc36eafdSMike Gerdts  ******************************************************************************/
190bc36eafdSMike Gerdts 
191bc36eafdSMike Gerdts UINT8
UtIsBigEndianMachine(void)192bc36eafdSMike Gerdts UtIsBigEndianMachine (
193bc36eafdSMike Gerdts     void)
194bc36eafdSMike Gerdts {
195bc36eafdSMike Gerdts     union {
196bc36eafdSMike Gerdts         UINT32              Integer;
197bc36eafdSMike Gerdts         UINT8               Bytes[4];
198bc36eafdSMike Gerdts     } Overlay =                 {0xFF000000};
199bc36eafdSMike Gerdts 
200bc36eafdSMike Gerdts 
201bc36eafdSMike Gerdts     return (Overlay.Bytes[0]); /* Returns 0xFF (TRUE) for big endian */
202bc36eafdSMike Gerdts }
203bc36eafdSMike Gerdts 
204bc36eafdSMike Gerdts 
205bc36eafdSMike Gerdts /******************************************************************************
206bc36eafdSMike Gerdts  *
207bc36eafdSMike Gerdts  * FUNCTION:    UtQueryForOverwrite
208bc36eafdSMike Gerdts  *
209bc36eafdSMike Gerdts  * PARAMETERS:  Pathname            - Output filename
210bc36eafdSMike Gerdts  *
211bc36eafdSMike Gerdts  * RETURN:      TRUE if file does not exist or overwrite is authorized
212bc36eafdSMike Gerdts  *
213bc36eafdSMike Gerdts  * DESCRIPTION: Query for file overwrite if it already exists.
214bc36eafdSMike Gerdts  *
215bc36eafdSMike Gerdts  ******************************************************************************/
216bc36eafdSMike Gerdts 
217bc36eafdSMike Gerdts BOOLEAN
UtQueryForOverwrite(char * Pathname)218bc36eafdSMike Gerdts UtQueryForOverwrite (
219bc36eafdSMike Gerdts     char                    *Pathname)
220bc36eafdSMike Gerdts {
221bc36eafdSMike Gerdts     struct stat             StatInfo;
222bc36eafdSMike Gerdts 
223bc36eafdSMike Gerdts 
224bc36eafdSMike Gerdts     if (!stat (Pathname, &StatInfo))
225bc36eafdSMike Gerdts     {
226bc36eafdSMike Gerdts         fprintf (stderr, "Target file \"%s\" already exists, overwrite? [y|n] ",
227bc36eafdSMike Gerdts             Pathname);
228bc36eafdSMike Gerdts 
229bc36eafdSMike Gerdts         if (getchar () != 'y')
230bc36eafdSMike Gerdts         {
231bc36eafdSMike Gerdts             return (FALSE);
232bc36eafdSMike Gerdts         }
233bc36eafdSMike Gerdts     }
234bc36eafdSMike Gerdts 
235bc36eafdSMike Gerdts     return (TRUE);
236bc36eafdSMike Gerdts }
237bc36eafdSMike Gerdts 
238bc36eafdSMike Gerdts 
23935786f68SRobert Mustacchi /*******************************************************************************
24035786f68SRobert Mustacchi  *
24135786f68SRobert Mustacchi  * FUNCTION:    UtNodeIsDescendantOf
24235786f68SRobert Mustacchi  *
24335786f68SRobert Mustacchi  * PARAMETERS:  Node1                   - Child node
24435786f68SRobert Mustacchi  *              Node2                   - Possible parent node
24535786f68SRobert Mustacchi  *
24635786f68SRobert Mustacchi  * RETURN:      Boolean
24735786f68SRobert Mustacchi  *
24835786f68SRobert Mustacchi  * DESCRIPTION: Returns TRUE if Node1 is a descendant of Node2. Otherwise,
24935786f68SRobert Mustacchi  *              return FALSE. Note, we assume a NULL Node2 element to be the
25035786f68SRobert Mustacchi  *              topmost (root) scope. All nodes are descendants of the root.
25135786f68SRobert Mustacchi  *              Note: Nodes at the same level (siblings) are not considered
25235786f68SRobert Mustacchi  *              descendants.
25335786f68SRobert Mustacchi  *
25435786f68SRobert Mustacchi  ******************************************************************************/
25535786f68SRobert Mustacchi 
25635786f68SRobert Mustacchi BOOLEAN
UtNodeIsDescendantOf(ACPI_NAMESPACE_NODE * Node1,ACPI_NAMESPACE_NODE * Node2)25735786f68SRobert Mustacchi UtNodeIsDescendantOf (
25835786f68SRobert Mustacchi     ACPI_NAMESPACE_NODE     *Node1,
25935786f68SRobert Mustacchi     ACPI_NAMESPACE_NODE     *Node2)
26035786f68SRobert Mustacchi {
26135786f68SRobert Mustacchi 
26235786f68SRobert Mustacchi     if (Node1 == Node2)
26335786f68SRobert Mustacchi     {
26435786f68SRobert Mustacchi         return (FALSE);
26535786f68SRobert Mustacchi     }
26635786f68SRobert Mustacchi 
26735786f68SRobert Mustacchi     if (!Node2)
26835786f68SRobert Mustacchi     {
26935786f68SRobert Mustacchi         return (TRUE); /* All nodes descend from the root */
27035786f68SRobert Mustacchi     }
27135786f68SRobert Mustacchi 
27235786f68SRobert Mustacchi     /* Walk upward until the root is reached or parent is found */
27335786f68SRobert Mustacchi 
27435786f68SRobert Mustacchi     while (Node1)
27535786f68SRobert Mustacchi     {
27635786f68SRobert Mustacchi         if (Node1 == Node2)
27735786f68SRobert Mustacchi         {
27835786f68SRobert Mustacchi             return (TRUE);
27935786f68SRobert Mustacchi         }
28035786f68SRobert Mustacchi 
28135786f68SRobert Mustacchi         Node1 = Node1->Parent;
28235786f68SRobert Mustacchi     }
28335786f68SRobert Mustacchi 
28435786f68SRobert Mustacchi     return (FALSE);
28535786f68SRobert Mustacchi }
28635786f68SRobert Mustacchi 
28735786f68SRobert Mustacchi 
28835786f68SRobert Mustacchi /*******************************************************************************
28935786f68SRobert Mustacchi  *
29035786f68SRobert Mustacchi  * FUNCTION:    UtGetParentMethod
29135786f68SRobert Mustacchi  *
29235786f68SRobert Mustacchi  * PARAMETERS:  Node                    - Namespace node for any object
29335786f68SRobert Mustacchi  *
29435786f68SRobert Mustacchi  * RETURN:      Namespace node for the parent method
29535786f68SRobert Mustacchi  *              NULL - object is not within a method
29635786f68SRobert Mustacchi  *
29735786f68SRobert Mustacchi  * DESCRIPTION: Find the parent (owning) method node for a namespace object
29835786f68SRobert Mustacchi  *
29935786f68SRobert Mustacchi  ******************************************************************************/
30035786f68SRobert Mustacchi 
30135786f68SRobert Mustacchi void *
UtGetParentMethod(ACPI_NAMESPACE_NODE * Node)30235786f68SRobert Mustacchi UtGetParentMethod (
30335786f68SRobert Mustacchi     ACPI_NAMESPACE_NODE     *Node)
30435786f68SRobert Mustacchi {
30535786f68SRobert Mustacchi     ACPI_NAMESPACE_NODE     *ParentNode;
30635786f68SRobert Mustacchi 
30735786f68SRobert Mustacchi 
30835786f68SRobert Mustacchi     if (!Node)
30935786f68SRobert Mustacchi     {
31035786f68SRobert Mustacchi         return (NULL);
31135786f68SRobert Mustacchi     }
31235786f68SRobert Mustacchi 
31335786f68SRobert Mustacchi     /* Walk upward until a method is found, or the root is reached */
31435786f68SRobert Mustacchi 
31535786f68SRobert Mustacchi     ParentNode = Node->Parent;
31635786f68SRobert Mustacchi     while (ParentNode)
31735786f68SRobert Mustacchi     {
31835786f68SRobert Mustacchi         if (ParentNode->Type == ACPI_TYPE_METHOD)
31935786f68SRobert Mustacchi         {
32035786f68SRobert Mustacchi             return (ParentNode);
32135786f68SRobert Mustacchi         }
32235786f68SRobert Mustacchi 
32335786f68SRobert Mustacchi         ParentNode = ParentNode->Parent;
32435786f68SRobert Mustacchi     }
32535786f68SRobert Mustacchi 
32635786f68SRobert Mustacchi     return (NULL); /* Object is not within a control method */
32735786f68SRobert Mustacchi }
32835786f68SRobert Mustacchi 
32935786f68SRobert Mustacchi 
330bc36eafdSMike Gerdts /*******************************************************************************
331bc36eafdSMike Gerdts  *
332bc36eafdSMike Gerdts  * FUNCTION:    UtDisplaySupportedTables
333bc36eafdSMike Gerdts  *
334bc36eafdSMike Gerdts  * PARAMETERS:  None
335bc36eafdSMike Gerdts  *
336bc36eafdSMike Gerdts  * RETURN:      None
337bc36eafdSMike Gerdts  *
338bc36eafdSMike Gerdts  * DESCRIPTION: Print all supported ACPI table names.
339bc36eafdSMike Gerdts  *
340bc36eafdSMike Gerdts  ******************************************************************************/
341bc36eafdSMike Gerdts 
342bc36eafdSMike Gerdts void
UtDisplaySupportedTables(void)343bc36eafdSMike Gerdts UtDisplaySupportedTables (
344bc36eafdSMike Gerdts     void)
345bc36eafdSMike Gerdts {
346bc36eafdSMike Gerdts     const AH_TABLE          *TableData;
347bc36eafdSMike Gerdts     UINT32                  i;
348bc36eafdSMike Gerdts 
349bc36eafdSMike Gerdts 
350bc36eafdSMike Gerdts     printf ("\nACPI tables supported by iASL version %8.8X:\n"
351bc36eafdSMike Gerdts         "  (Compiler, Disassembler, Template Generator)\n\n",
352bc36eafdSMike Gerdts         ACPI_CA_VERSION);
353bc36eafdSMike Gerdts 
354bc36eafdSMike Gerdts     /* All ACPI tables with the common table header */
355bc36eafdSMike Gerdts 
356bc36eafdSMike Gerdts     printf ("\n  Supported ACPI tables:\n");
35735786f68SRobert Mustacchi     for (TableData = Gbl_AcpiSupportedTables, i = 1;
358bc36eafdSMike Gerdts          TableData->Signature; TableData++, i++)
359bc36eafdSMike Gerdts     {
360bc36eafdSMike Gerdts         printf ("%8u) %s    %s\n", i,
361bc36eafdSMike Gerdts             TableData->Signature, TableData->Description);
362bc36eafdSMike Gerdts     }
363bc36eafdSMike Gerdts }
364bc36eafdSMike Gerdts 
365bc36eafdSMike Gerdts 
366bc36eafdSMike Gerdts /*******************************************************************************
367bc36eafdSMike Gerdts  *
368bc36eafdSMike Gerdts  * FUNCTION:    UtDisplayConstantOpcodes
369bc36eafdSMike Gerdts  *
370bc36eafdSMike Gerdts  * PARAMETERS:  None
371bc36eafdSMike Gerdts  *
372bc36eafdSMike Gerdts  * RETURN:      None
373bc36eafdSMike Gerdts  *
374bc36eafdSMike Gerdts  * DESCRIPTION: Print AML opcodes that can be used in constant expressions.
375bc36eafdSMike Gerdts  *
376bc36eafdSMike Gerdts  ******************************************************************************/
377bc36eafdSMike Gerdts 
378bc36eafdSMike Gerdts void
UtDisplayConstantOpcodes(void)379bc36eafdSMike Gerdts UtDisplayConstantOpcodes (
380bc36eafdSMike Gerdts     void)
381bc36eafdSMike Gerdts {
382bc36eafdSMike Gerdts     UINT32                  i;
383bc36eafdSMike Gerdts 
384bc36eafdSMike Gerdts 
385bc36eafdSMike Gerdts     printf ("Constant expression opcode information\n\n");
386bc36eafdSMike Gerdts 
387bc36eafdSMike Gerdts     for (i = 0; i < sizeof (AcpiGbl_AmlOpInfo) / sizeof (ACPI_OPCODE_INFO); i++)
388bc36eafdSMike Gerdts     {
389bc36eafdSMike Gerdts         if (AcpiGbl_AmlOpInfo[i].Flags & AML_CONSTANT)
390bc36eafdSMike Gerdts         {
391bc36eafdSMike Gerdts             printf ("%s\n", AcpiGbl_AmlOpInfo[i].Name);
392bc36eafdSMike Gerdts         }
393bc36eafdSMike Gerdts     }
394bc36eafdSMike Gerdts }
395bc36eafdSMike Gerdts 
396bc36eafdSMike Gerdts 
397bc36eafdSMike Gerdts /*******************************************************************************
398bc36eafdSMike Gerdts  *
399bc36eafdSMike Gerdts  * FUNCTION:    UtBeginEvent
400bc36eafdSMike Gerdts  *
401bc36eafdSMike Gerdts  * PARAMETERS:  Name                - Ascii name of this event
402bc36eafdSMike Gerdts  *
403bc36eafdSMike Gerdts  * RETURN:      Event number (integer index)
404bc36eafdSMike Gerdts  *
405bc36eafdSMike Gerdts  * DESCRIPTION: Saves the current time with this event
406bc36eafdSMike Gerdts  *
407bc36eafdSMike Gerdts  ******************************************************************************/
408bc36eafdSMike Gerdts 
409bc36eafdSMike Gerdts UINT8
UtBeginEvent(char * Name)410bc36eafdSMike Gerdts UtBeginEvent (
411bc36eafdSMike Gerdts     char                    *Name)
412bc36eafdSMike Gerdts {
413bc36eafdSMike Gerdts 
414bc36eafdSMike Gerdts     if (AslGbl_NextEvent >= ASL_NUM_EVENTS)
415bc36eafdSMike Gerdts     {
416bc36eafdSMike Gerdts         AcpiOsPrintf ("Ran out of compiler event structs!\n");
417bc36eafdSMike Gerdts         return (AslGbl_NextEvent);
418bc36eafdSMike Gerdts     }
419bc36eafdSMike Gerdts 
420bc36eafdSMike Gerdts     /* Init event with current (start) time */
421bc36eafdSMike Gerdts 
422bc36eafdSMike Gerdts     AslGbl_Events[AslGbl_NextEvent].StartTime = AcpiOsGetTimer ();
423bc36eafdSMike Gerdts     AslGbl_Events[AslGbl_NextEvent].EventName = Name;
424bc36eafdSMike Gerdts     AslGbl_Events[AslGbl_NextEvent].Valid = TRUE;
425bc36eafdSMike Gerdts     return (AslGbl_NextEvent++);
426bc36eafdSMike Gerdts }
427bc36eafdSMike Gerdts 
428bc36eafdSMike Gerdts 
429bc36eafdSMike Gerdts /*******************************************************************************
430bc36eafdSMike Gerdts  *
431bc36eafdSMike Gerdts  * FUNCTION:    UtEndEvent
432bc36eafdSMike Gerdts  *
433bc36eafdSMike Gerdts  * PARAMETERS:  Event               - Event number (integer index)
434bc36eafdSMike Gerdts  *
435bc36eafdSMike Gerdts  * RETURN:      None
436bc36eafdSMike Gerdts  *
437bc36eafdSMike Gerdts  * DESCRIPTION: Saves the current time (end time) with this event
438bc36eafdSMike Gerdts  *
439bc36eafdSMike Gerdts  ******************************************************************************/
440bc36eafdSMike Gerdts 
441bc36eafdSMike Gerdts void
UtEndEvent(UINT8 Event)442bc36eafdSMike Gerdts UtEndEvent (
443bc36eafdSMike Gerdts     UINT8                   Event)
444bc36eafdSMike Gerdts {
445bc36eafdSMike Gerdts 
446bc36eafdSMike Gerdts     if (Event >= ASL_NUM_EVENTS)
447bc36eafdSMike Gerdts     {
448bc36eafdSMike Gerdts         return;
449bc36eafdSMike Gerdts     }
450bc36eafdSMike Gerdts 
451bc36eafdSMike Gerdts     /* Insert end time for event */
452bc36eafdSMike Gerdts 
453bc36eafdSMike Gerdts     AslGbl_Events[Event].EndTime = AcpiOsGetTimer ();
454bc36eafdSMike Gerdts }
455bc36eafdSMike Gerdts 
456bc36eafdSMike Gerdts 
457bc36eafdSMike Gerdts /*******************************************************************************
458bc36eafdSMike Gerdts  *
459bc36eafdSMike Gerdts  * FUNCTION:    DbgPrint
460bc36eafdSMike Gerdts  *
461bc36eafdSMike Gerdts  * PARAMETERS:  Type                - Type of output
462bc36eafdSMike Gerdts  *              Fmt                 - Printf format string
463bc36eafdSMike Gerdts  *              ...                 - variable printf list
464bc36eafdSMike Gerdts  *
465bc36eafdSMike Gerdts  * RETURN:      None
466bc36eafdSMike Gerdts  *
467bc36eafdSMike Gerdts  * DESCRIPTION: Conditional print statement. Prints to stderr only if the
468bc36eafdSMike Gerdts  *              debug flag is set.
469bc36eafdSMike Gerdts  *
470bc36eafdSMike Gerdts  ******************************************************************************/
471bc36eafdSMike Gerdts 
472bc36eafdSMike Gerdts void
DbgPrint(UINT32 Type,char * Fmt,...)473bc36eafdSMike Gerdts DbgPrint (
474bc36eafdSMike Gerdts     UINT32                  Type,
475bc36eafdSMike Gerdts     char                    *Fmt,
476bc36eafdSMike Gerdts     ...)
477bc36eafdSMike Gerdts {
478bc36eafdSMike Gerdts     va_list                 Args;
479bc36eafdSMike Gerdts 
480bc36eafdSMike Gerdts 
481bc36eafdSMike Gerdts     if (!Gbl_DebugFlag)
482bc36eafdSMike Gerdts     {
483bc36eafdSMike Gerdts         return;
484bc36eafdSMike Gerdts     }
485bc36eafdSMike Gerdts 
486bc36eafdSMike Gerdts     if ((Type == ASL_PARSE_OUTPUT) &&
487bc36eafdSMike Gerdts         (!(AslCompilerdebug)))
488bc36eafdSMike Gerdts     {
489bc36eafdSMike Gerdts         return;
490bc36eafdSMike Gerdts     }
491bc36eafdSMike Gerdts 
492bc36eafdSMike Gerdts     va_start (Args, Fmt);
493bc36eafdSMike Gerdts     (void) vfprintf (stderr, Fmt, Args);
494bc36eafdSMike Gerdts     va_end (Args);
495bc36eafdSMike Gerdts     return;
496bc36eafdSMike Gerdts }
497bc36eafdSMike Gerdts 
498bc36eafdSMike Gerdts 
499bc36eafdSMike Gerdts /*******************************************************************************
500bc36eafdSMike Gerdts  *
501bc36eafdSMike Gerdts  * FUNCTION:    UtSetParseOpName
502bc36eafdSMike Gerdts  *
503bc36eafdSMike Gerdts  * PARAMETERS:  Op                  - Parse op to be named.
504bc36eafdSMike Gerdts  *
505bc36eafdSMike Gerdts  * RETURN:      None
506bc36eafdSMike Gerdts  *
507bc36eafdSMike Gerdts  * DESCRIPTION: Insert the ascii name of the parse opcode
508bc36eafdSMike Gerdts  *
509bc36eafdSMike Gerdts  ******************************************************************************/
510bc36eafdSMike Gerdts 
511bc36eafdSMike Gerdts void
UtSetParseOpName(ACPI_PARSE_OBJECT * Op)512bc36eafdSMike Gerdts UtSetParseOpName (
513bc36eafdSMike Gerdts     ACPI_PARSE_OBJECT       *Op)
514bc36eafdSMike Gerdts {
515bc36eafdSMike Gerdts 
51635786f68SRobert Mustacchi     AcpiUtSafeStrncpy (Op->Asl.ParseOpName, UtGetOpName (Op->Asl.ParseOpcode),
517bc36eafdSMike Gerdts         ACPI_MAX_PARSEOP_NAME);
518bc36eafdSMike Gerdts }
519bc36eafdSMike Gerdts 
520bc36eafdSMike Gerdts 
521bc36eafdSMike Gerdts /*******************************************************************************
522bc36eafdSMike Gerdts  *
523bc36eafdSMike Gerdts  * FUNCTION:    UtDisplaySummary
524bc36eafdSMike Gerdts  *
525bc36eafdSMike Gerdts  * PARAMETERS:  FileID              - ID of outpout file
526bc36eafdSMike Gerdts  *
527bc36eafdSMike Gerdts  * RETURN:      None
528bc36eafdSMike Gerdts  *
529bc36eafdSMike Gerdts  * DESCRIPTION: Display compilation statistics
530bc36eafdSMike Gerdts  *
531bc36eafdSMike Gerdts  ******************************************************************************/
532bc36eafdSMike Gerdts 
533bc36eafdSMike Gerdts void
UtDisplaySummary(UINT32 FileId)534bc36eafdSMike Gerdts UtDisplaySummary (
535bc36eafdSMike Gerdts     UINT32                  FileId)
536bc36eafdSMike Gerdts {
537bc36eafdSMike Gerdts     UINT32                  i;
538bc36eafdSMike Gerdts 
539bc36eafdSMike Gerdts 
540bc36eafdSMike Gerdts     if (FileId != ASL_FILE_STDOUT)
541bc36eafdSMike Gerdts     {
542bc36eafdSMike Gerdts         /* Compiler name and version number */
543bc36eafdSMike Gerdts 
54435786f68SRobert Mustacchi         FlPrintFile (FileId, "%s version %X [%s]\n\n",
545*20a2a10fSRobert Mustacchi             ASL_COMPILER_NAME, (UINT32) ACPI_CA_VERSION, ACPI_DATE);
546bc36eafdSMike Gerdts     }
547bc36eafdSMike Gerdts 
548bc36eafdSMike Gerdts     /* Summary of main input and output files */
549bc36eafdSMike Gerdts 
550bc36eafdSMike Gerdts     if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA)
551bc36eafdSMike Gerdts     {
552bc36eafdSMike Gerdts         FlPrintFile (FileId,
553bc36eafdSMike Gerdts             "%-14s %s - %u lines, %u bytes, %u fields\n",
554bc36eafdSMike Gerdts             "Table Input:",
555bc36eafdSMike Gerdts             Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_CurrentLineNumber,
556bc36eafdSMike Gerdts             Gbl_InputByteCount, Gbl_InputFieldCount);
557bc36eafdSMike Gerdts 
558bc36eafdSMike Gerdts         if ((Gbl_ExceptionCount[ASL_ERROR] == 0) || (Gbl_IgnoreErrors))
559bc36eafdSMike Gerdts         {
560bc36eafdSMike Gerdts             FlPrintFile (FileId,
561bc36eafdSMike Gerdts                 "%-14s %s - %u bytes\n",
562bc36eafdSMike Gerdts                 "Binary Output:",
563bc36eafdSMike Gerdts                 Gbl_Files[ASL_FILE_AML_OUTPUT].Filename, Gbl_TableLength);
564bc36eafdSMike Gerdts         }
565bc36eafdSMike Gerdts     }
566bc36eafdSMike Gerdts     else
567bc36eafdSMike Gerdts     {
568bc36eafdSMike Gerdts         FlPrintFile (FileId,
569bc36eafdSMike Gerdts             "%-14s %s - %u lines, %u bytes, %u keywords\n",
570bc36eafdSMike Gerdts             "ASL Input:",
571bc36eafdSMike Gerdts             Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_CurrentLineNumber,
572bc36eafdSMike Gerdts             Gbl_OriginalInputFileSize, TotalKeywords);
573bc36eafdSMike Gerdts 
574bc36eafdSMike Gerdts         /* AML summary */
575bc36eafdSMike Gerdts 
576bc36eafdSMike Gerdts         if ((Gbl_ExceptionCount[ASL_ERROR] == 0) || (Gbl_IgnoreErrors))
577bc36eafdSMike Gerdts         {
578bc36eafdSMike Gerdts             if (Gbl_Files[ASL_FILE_AML_OUTPUT].Handle)
579bc36eafdSMike Gerdts             {
580bc36eafdSMike Gerdts                 FlPrintFile (FileId,
581bc36eafdSMike Gerdts                     "%-14s %s - %u bytes, %u named objects, "
582bc36eafdSMike Gerdts                     "%u executable opcodes\n",
583bc36eafdSMike Gerdts                     "AML Output:",
584bc36eafdSMike Gerdts                     Gbl_Files[ASL_FILE_AML_OUTPUT].Filename,
585bc36eafdSMike Gerdts                     FlGetFileSize (ASL_FILE_AML_OUTPUT),
586bc36eafdSMike Gerdts                     TotalNamedObjects, TotalExecutableOpcodes);
587bc36eafdSMike Gerdts             }
588bc36eafdSMike Gerdts         }
589bc36eafdSMike Gerdts     }
590bc36eafdSMike Gerdts 
591bc36eafdSMike Gerdts     /* Display summary of any optional files */
592bc36eafdSMike Gerdts 
593bc36eafdSMike Gerdts     for (i = ASL_FILE_SOURCE_OUTPUT; i <= ASL_MAX_FILE_TYPE; i++)
594bc36eafdSMike Gerdts     {
595bc36eafdSMike Gerdts         if (!Gbl_Files[i].Filename || !Gbl_Files[i].Handle)
596bc36eafdSMike Gerdts         {
597bc36eafdSMike Gerdts             continue;
598bc36eafdSMike Gerdts         }
599bc36eafdSMike Gerdts 
600bc36eafdSMike Gerdts         /* .SRC is a temp file unless specifically requested */
601bc36eafdSMike Gerdts 
602bc36eafdSMike Gerdts         if ((i == ASL_FILE_SOURCE_OUTPUT) && (!Gbl_SourceOutputFlag))
603bc36eafdSMike Gerdts         {
604bc36eafdSMike Gerdts             continue;
605bc36eafdSMike Gerdts         }
606bc36eafdSMike Gerdts 
607bc36eafdSMike Gerdts         /* .PRE is the preprocessor intermediate file */
608bc36eafdSMike Gerdts 
609bc36eafdSMike Gerdts         if ((i == ASL_FILE_PREPROCESSOR)  && (!Gbl_KeepPreprocessorTempFile))
610bc36eafdSMike Gerdts         {
611bc36eafdSMike Gerdts             continue;
612bc36eafdSMike Gerdts         }
613bc36eafdSMike Gerdts 
614bc36eafdSMike Gerdts         FlPrintFile (FileId, "%14s %s - %u bytes\n",
615bc36eafdSMike Gerdts             Gbl_Files[i].ShortDescription,
616bc36eafdSMike Gerdts             Gbl_Files[i].Filename, FlGetFileSize (i));
617bc36eafdSMike Gerdts     }
618bc36eafdSMike Gerdts 
619bc36eafdSMike Gerdts     /* Error summary */
620bc36eafdSMike Gerdts 
621bc36eafdSMike Gerdts     FlPrintFile (FileId,
622bc36eafdSMike Gerdts         "\nCompilation complete. %u Errors, %u Warnings, %u Remarks",
623bc36eafdSMike Gerdts         Gbl_ExceptionCount[ASL_ERROR],
624bc36eafdSMike Gerdts         Gbl_ExceptionCount[ASL_WARNING] +
625bc36eafdSMike Gerdts             Gbl_ExceptionCount[ASL_WARNING2] +
626bc36eafdSMike Gerdts             Gbl_ExceptionCount[ASL_WARNING3],
627bc36eafdSMike Gerdts         Gbl_ExceptionCount[ASL_REMARK]);
628bc36eafdSMike Gerdts 
629bc36eafdSMike Gerdts     if (Gbl_FileType != ASL_INPUT_TYPE_ASCII_DATA)
630bc36eafdSMike Gerdts     {
631bc36eafdSMike Gerdts         FlPrintFile (FileId, ", %u Optimizations",
632bc36eafdSMike Gerdts             Gbl_ExceptionCount[ASL_OPTIMIZATION]);
633bc36eafdSMike Gerdts 
634bc36eafdSMike Gerdts         if (TotalFolds)
635bc36eafdSMike Gerdts         {
636bc36eafdSMike Gerdts             FlPrintFile (FileId, ", %u Constants Folded", TotalFolds);
637bc36eafdSMike Gerdts         }
638bc36eafdSMike Gerdts     }
639bc36eafdSMike Gerdts 
640bc36eafdSMike Gerdts     FlPrintFile (FileId, "\n");
641bc36eafdSMike Gerdts }
642bc36eafdSMike Gerdts 
643bc36eafdSMike Gerdts 
644bc36eafdSMike Gerdts /*******************************************************************************
645bc36eafdSMike Gerdts  *
646bc36eafdSMike Gerdts  * FUNCTION:    UtCheckIntegerRange
647bc36eafdSMike Gerdts  *
648bc36eafdSMike Gerdts  * PARAMETERS:  Op                  - Integer parse node
649bc36eafdSMike Gerdts  *              LowValue            - Smallest allowed value
650bc36eafdSMike Gerdts  *              HighValue           - Largest allowed value
651bc36eafdSMike Gerdts  *
652bc36eafdSMike Gerdts  * RETURN:      Op if OK, otherwise NULL
653bc36eafdSMike Gerdts  *
654bc36eafdSMike Gerdts  * DESCRIPTION: Check integer for an allowable range
655bc36eafdSMike Gerdts  *
656bc36eafdSMike Gerdts  ******************************************************************************/
657bc36eafdSMike Gerdts 
658bc36eafdSMike Gerdts ACPI_PARSE_OBJECT *
UtCheckIntegerRange(ACPI_PARSE_OBJECT * Op,UINT32 LowValue,UINT32 HighValue)659bc36eafdSMike Gerdts UtCheckIntegerRange (
660bc36eafdSMike Gerdts     ACPI_PARSE_OBJECT       *Op,
661bc36eafdSMike Gerdts     UINT32                  LowValue,
662bc36eafdSMike Gerdts     UINT32                  HighValue)
663bc36eafdSMike Gerdts {
664bc36eafdSMike Gerdts 
665bc36eafdSMike Gerdts     if (!Op)
666bc36eafdSMike Gerdts     {
667bc36eafdSMike Gerdts         return (NULL);
668bc36eafdSMike Gerdts     }
669bc36eafdSMike Gerdts 
670bc36eafdSMike Gerdts     if ((Op->Asl.Value.Integer < LowValue) ||
671bc36eafdSMike Gerdts         (Op->Asl.Value.Integer > HighValue))
672bc36eafdSMike Gerdts     {
673bc36eafdSMike Gerdts         sprintf (MsgBuffer, "0x%X, allowable: 0x%X-0x%X",
674bc36eafdSMike Gerdts             (UINT32) Op->Asl.Value.Integer, LowValue, HighValue);
675bc36eafdSMike Gerdts 
676bc36eafdSMike Gerdts         AslError (ASL_ERROR, ASL_MSG_RANGE, Op, MsgBuffer);
677bc36eafdSMike Gerdts         return (NULL);
678bc36eafdSMike Gerdts     }
679bc36eafdSMike Gerdts 
680bc36eafdSMike Gerdts     return (Op);
681bc36eafdSMike Gerdts }
682bc36eafdSMike Gerdts 
683bc36eafdSMike Gerdts 
684bc36eafdSMike Gerdts /*******************************************************************************
685bc36eafdSMike Gerdts  *
686bc36eafdSMike Gerdts  * FUNCTION:    UtInternalizeName
687bc36eafdSMike Gerdts  *
688bc36eafdSMike Gerdts  * PARAMETERS:  ExternalName        - Name to convert
689bc36eafdSMike Gerdts  *              ConvertedName       - Where the converted name is returned
690bc36eafdSMike Gerdts  *
691bc36eafdSMike Gerdts  * RETURN:      Status
692bc36eafdSMike Gerdts  *
693bc36eafdSMike Gerdts  * DESCRIPTION: Convert an external (ASL) name to an internal (AML) name
694bc36eafdSMike Gerdts  *
695bc36eafdSMike Gerdts  ******************************************************************************/
696bc36eafdSMike Gerdts 
697bc36eafdSMike Gerdts ACPI_STATUS
UtInternalizeName(char * ExternalName,char ** ConvertedName)698bc36eafdSMike Gerdts UtInternalizeName (
699bc36eafdSMike Gerdts     char                    *ExternalName,
700bc36eafdSMike Gerdts     char                    **ConvertedName)
701bc36eafdSMike Gerdts {
702bc36eafdSMike Gerdts     ACPI_NAMESTRING_INFO    Info;
703bc36eafdSMike Gerdts     ACPI_STATUS             Status;
704bc36eafdSMike Gerdts 
705bc36eafdSMike Gerdts 
706bc36eafdSMike Gerdts     if (!ExternalName)
707bc36eafdSMike Gerdts     {
708bc36eafdSMike Gerdts         return (AE_OK);
709bc36eafdSMike Gerdts     }
710bc36eafdSMike Gerdts 
711bc36eafdSMike Gerdts     /* Get the length of the new internal name */
712bc36eafdSMike Gerdts 
713bc36eafdSMike Gerdts     Info.ExternalName = ExternalName;
714bc36eafdSMike Gerdts     AcpiNsGetInternalNameLength (&Info);
715bc36eafdSMike Gerdts 
716bc36eafdSMike Gerdts     /* We need a segment to store the internal name */
717bc36eafdSMike Gerdts 
71835786f68SRobert Mustacchi     Info.InternalName = UtLocalCacheCalloc (Info.Length);
719bc36eafdSMike Gerdts 
720bc36eafdSMike Gerdts     /* Build the name */
721bc36eafdSMike Gerdts 
722bc36eafdSMike Gerdts     Status = AcpiNsBuildInternalName (&Info);
723bc36eafdSMike Gerdts     if (ACPI_FAILURE (Status))
724bc36eafdSMike Gerdts     {
725bc36eafdSMike Gerdts         return (Status);
726bc36eafdSMike Gerdts     }
727bc36eafdSMike Gerdts 
728bc36eafdSMike Gerdts     *ConvertedName = Info.InternalName;
729bc36eafdSMike Gerdts     return (AE_OK);
730bc36eafdSMike Gerdts }
731bc36eafdSMike Gerdts 
732bc36eafdSMike Gerdts 
733bc36eafdSMike Gerdts /*******************************************************************************
734bc36eafdSMike Gerdts  *
735bc36eafdSMike Gerdts  * FUNCTION:    UtPadNameWithUnderscores
736bc36eafdSMike Gerdts  *
737bc36eafdSMike Gerdts  * PARAMETERS:  NameSeg             - Input nameseg
738bc36eafdSMike Gerdts  *              PaddedNameSeg       - Output padded nameseg
739bc36eafdSMike Gerdts  *
740bc36eafdSMike Gerdts  * RETURN:      Padded nameseg.
741bc36eafdSMike Gerdts  *
742bc36eafdSMike Gerdts  * DESCRIPTION: Pads a NameSeg with underscores if necessary to form a full
743bc36eafdSMike Gerdts  *              ACPI_NAME.
744bc36eafdSMike Gerdts  *
745bc36eafdSMike Gerdts  ******************************************************************************/
746bc36eafdSMike Gerdts 
747bc36eafdSMike Gerdts static void
UtPadNameWithUnderscores(char * NameSeg,char * PaddedNameSeg)748bc36eafdSMike Gerdts UtPadNameWithUnderscores (
749bc36eafdSMike Gerdts     char                    *NameSeg,
750bc36eafdSMike Gerdts     char                    *PaddedNameSeg)
751bc36eafdSMike Gerdts {
752bc36eafdSMike Gerdts     UINT32                  i;
753bc36eafdSMike Gerdts 
754bc36eafdSMike Gerdts 
755bc36eafdSMike Gerdts     for (i = 0; (i < ACPI_NAME_SIZE); i++)
756bc36eafdSMike Gerdts     {
757bc36eafdSMike Gerdts         if (*NameSeg)
758bc36eafdSMike Gerdts         {
759bc36eafdSMike Gerdts             *PaddedNameSeg = *NameSeg;
760bc36eafdSMike Gerdts             NameSeg++;
761bc36eafdSMike Gerdts         }
762bc36eafdSMike Gerdts         else
763bc36eafdSMike Gerdts         {
764bc36eafdSMike Gerdts             *PaddedNameSeg = '_';
765bc36eafdSMike Gerdts         }
766bc36eafdSMike Gerdts 
767bc36eafdSMike Gerdts         PaddedNameSeg++;
768bc36eafdSMike Gerdts     }
769bc36eafdSMike Gerdts }
770bc36eafdSMike Gerdts 
771bc36eafdSMike Gerdts 
772bc36eafdSMike Gerdts /*******************************************************************************
773bc36eafdSMike Gerdts  *
774bc36eafdSMike Gerdts  * FUNCTION:    UtAttachNameseg
775bc36eafdSMike Gerdts  *
776bc36eafdSMike Gerdts  * PARAMETERS:  Op                  - Parent parse node
777bc36eafdSMike Gerdts  *              Name                - Full ExternalName
778bc36eafdSMike Gerdts  *
779bc36eafdSMike Gerdts  * RETURN:      None; Sets the NameSeg field in parent node
780bc36eafdSMike Gerdts  *
781bc36eafdSMike Gerdts  * DESCRIPTION: Extract the last nameseg of the ExternalName and store it
782bc36eafdSMike Gerdts  *              in the NameSeg field of the Op.
783bc36eafdSMike Gerdts  *
784bc36eafdSMike Gerdts  ******************************************************************************/
785bc36eafdSMike Gerdts 
786bc36eafdSMike Gerdts static void
UtAttachNameseg(ACPI_PARSE_OBJECT * Op,char * Name)787bc36eafdSMike Gerdts UtAttachNameseg (
788bc36eafdSMike Gerdts     ACPI_PARSE_OBJECT       *Op,
789bc36eafdSMike Gerdts     char                    *Name)
790bc36eafdSMike Gerdts {
791bc36eafdSMike Gerdts     char                    *NameSeg;
792bc36eafdSMike Gerdts     char                    PaddedNameSeg[4];
793bc36eafdSMike Gerdts 
794bc36eafdSMike Gerdts 
795bc36eafdSMike Gerdts     if (!Name)
796bc36eafdSMike Gerdts     {
797bc36eafdSMike Gerdts         return;
798bc36eafdSMike Gerdts     }
799bc36eafdSMike Gerdts 
800bc36eafdSMike Gerdts     /* Look for the last dot in the namepath */
801bc36eafdSMike Gerdts 
802bc36eafdSMike Gerdts     NameSeg = strrchr (Name, '.');
803bc36eafdSMike Gerdts     if (NameSeg)
804bc36eafdSMike Gerdts     {
805bc36eafdSMike Gerdts         /* Found last dot, we have also found the final nameseg */
806bc36eafdSMike Gerdts 
807bc36eafdSMike Gerdts         NameSeg++;
808bc36eafdSMike Gerdts         UtPadNameWithUnderscores (NameSeg, PaddedNameSeg);
809bc36eafdSMike Gerdts     }
810bc36eafdSMike Gerdts     else
811bc36eafdSMike Gerdts     {
812bc36eafdSMike Gerdts         /* No dots in the namepath, there is only a single nameseg. */
813bc36eafdSMike Gerdts         /* Handle prefixes */
814bc36eafdSMike Gerdts 
815bc36eafdSMike Gerdts         while (ACPI_IS_ROOT_PREFIX (*Name) ||
816bc36eafdSMike Gerdts                ACPI_IS_PARENT_PREFIX (*Name))
817bc36eafdSMike Gerdts         {
818bc36eafdSMike Gerdts             Name++;
819bc36eafdSMike Gerdts         }
820bc36eafdSMike Gerdts 
821bc36eafdSMike Gerdts         /* Remaining string should be one single nameseg */
822bc36eafdSMike Gerdts 
823bc36eafdSMike Gerdts         UtPadNameWithUnderscores (Name, PaddedNameSeg);
824bc36eafdSMike Gerdts     }
825bc36eafdSMike Gerdts 
826bc36eafdSMike Gerdts     ACPI_MOVE_NAME (Op->Asl.NameSeg, PaddedNameSeg);
827bc36eafdSMike Gerdts }
828bc36eafdSMike Gerdts 
829bc36eafdSMike Gerdts 
830bc36eafdSMike Gerdts /*******************************************************************************
831bc36eafdSMike Gerdts  *
832bc36eafdSMike Gerdts  * FUNCTION:    UtAttachNamepathToOwner
833bc36eafdSMike Gerdts  *
834bc36eafdSMike Gerdts  * PARAMETERS:  Op                  - Parent parse node
835bc36eafdSMike Gerdts  *              NameOp              - Node that contains the name
836bc36eafdSMike Gerdts  *
837bc36eafdSMike Gerdts  * RETURN:      Sets the ExternalName and Namepath in the parent node
838bc36eafdSMike Gerdts  *
839bc36eafdSMike Gerdts  * DESCRIPTION: Store the name in two forms in the parent node: The original
840bc36eafdSMike Gerdts  *              (external) name, and the internalized name that is used within
841bc36eafdSMike Gerdts  *              the ACPI namespace manager.
842bc36eafdSMike Gerdts  *
843bc36eafdSMike Gerdts  ******************************************************************************/
844bc36eafdSMike Gerdts 
845bc36eafdSMike Gerdts void
UtAttachNamepathToOwner(ACPI_PARSE_OBJECT * Op,ACPI_PARSE_OBJECT * NameOp)846bc36eafdSMike Gerdts UtAttachNamepathToOwner (
847bc36eafdSMike Gerdts     ACPI_PARSE_OBJECT       *Op,
848bc36eafdSMike Gerdts     ACPI_PARSE_OBJECT       *NameOp)
849bc36eafdSMike Gerdts {
850bc36eafdSMike Gerdts     ACPI_STATUS             Status;
851bc36eafdSMike Gerdts 
852bc36eafdSMike Gerdts 
853bc36eafdSMike Gerdts     /* Full external path */
854bc36eafdSMike Gerdts 
855bc36eafdSMike Gerdts     Op->Asl.ExternalName = NameOp->Asl.Value.String;
856bc36eafdSMike Gerdts 
857bc36eafdSMike Gerdts     /* Save the NameOp for possible error reporting later */
858bc36eafdSMike Gerdts 
859bc36eafdSMike Gerdts     Op->Asl.ParentMethod = (void *) NameOp;
860bc36eafdSMike Gerdts 
861bc36eafdSMike Gerdts     /* Last nameseg of the path */
862bc36eafdSMike Gerdts 
863bc36eafdSMike Gerdts     UtAttachNameseg (Op, Op->Asl.ExternalName);
864bc36eafdSMike Gerdts 
865bc36eafdSMike Gerdts     /* Create internalized path */
866bc36eafdSMike Gerdts 
867bc36eafdSMike Gerdts     Status = UtInternalizeName (NameOp->Asl.Value.String, &Op->Asl.Namepath);
868bc36eafdSMike Gerdts     if (ACPI_FAILURE (Status))
869bc36eafdSMike Gerdts     {
870bc36eafdSMike Gerdts         /* TBD: abort on no memory */
871bc36eafdSMike Gerdts     }
872bc36eafdSMike Gerdts }
873bc36eafdSMike Gerdts 
874bc36eafdSMike Gerdts 
875bc36eafdSMike Gerdts /*******************************************************************************
876bc36eafdSMike Gerdts  *
877bc36eafdSMike Gerdts  * FUNCTION:    UtDoConstant
878bc36eafdSMike Gerdts  *
87935786f68SRobert Mustacchi  * PARAMETERS:  String              - Hex/Decimal/Octal
880bc36eafdSMike Gerdts  *
881bc36eafdSMike Gerdts  * RETURN:      Converted Integer
882bc36eafdSMike Gerdts  *
88335786f68SRobert Mustacchi  * DESCRIPTION: Convert a string to an integer, with overflow/error checking.
884bc36eafdSMike Gerdts  *
885bc36eafdSMike Gerdts  ******************************************************************************/
886bc36eafdSMike Gerdts 
887bc36eafdSMike Gerdts UINT64
UtDoConstant(char * String)888bc36eafdSMike Gerdts UtDoConstant (
889bc36eafdSMike Gerdts     char                    *String)
890bc36eafdSMike Gerdts {
891bc36eafdSMike Gerdts     ACPI_STATUS             Status;
89235786f68SRobert Mustacchi     UINT64                  ConvertedInteger;
893bc36eafdSMike Gerdts     char                    ErrBuf[64];
894bc36eafdSMike Gerdts 
895bc36eafdSMike Gerdts 
89635786f68SRobert Mustacchi     Status = AcpiUtStrtoul64 (String, &ConvertedInteger);
897bc36eafdSMike Gerdts     if (ACPI_FAILURE (Status))
898bc36eafdSMike Gerdts     {
89935786f68SRobert Mustacchi         sprintf (ErrBuf, "While creating 64-bit constant: %s\n",
900bc36eafdSMike Gerdts             AcpiFormatException (Status));
901bc36eafdSMike Gerdts 
90235786f68SRobert Mustacchi         AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, Gbl_CurrentLineNumber,
90335786f68SRobert Mustacchi             Gbl_LogicalLineNumber, Gbl_CurrentLineOffset,
90435786f68SRobert Mustacchi             Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename, ErrBuf);
90535786f68SRobert Mustacchi     }
906bc36eafdSMike Gerdts 
90735786f68SRobert Mustacchi     return (ConvertedInteger);
908bc36eafdSMike Gerdts }
909