1 /******************************************************************************
2  *
3  * Module Name: aslutils -- compiler utilities
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights. You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code. No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision. In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change. Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee. Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution. In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100  * software or system incorporating such software without first obtaining any
101  * required license or other approval from the U. S. Department of Commerce or
102  * any other agency or department of the United States Government. In the
103  * event Licensee exports any such software from the United States or
104  * re-exports any such software from a foreign destination, Licensee shall
105  * ensure that the distribution and export/re-export of the software is in
106  * compliance with all laws, regulations, orders, or other restrictions of the
107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108  * any of its subsidiaries will export/re-export any technical data, process,
109  * software, or service, directly or indirectly, to any country for which the
110  * United States government or any agency thereof requires an export license,
111  * other governmental approval, or letter of assurance, without first obtaining
112  * such license, approval or letter.
113  *
114  *****************************************************************************
115  *
116  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
122  * 1. Redistributions of source code must retain the above copyright
123  *    notice, this list of conditions, and the following disclaimer,
124  *    without modification.
125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126  *    substantially similar to the "NO WARRANTY" disclaimer below
127  *    ("Disclaimer") and any redistribution must be conditioned upon
128  *    including a substantially similar Disclaimer requirement for further
129  *    binary redistribution.
130  * 3. Neither the names of the above-listed copyright holders nor the names
131  *    of any contributors may be used to endorse or promote products derived
132  *    from this software without specific prior written permission.
133  *
134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145  *
146  * Alternatively, you may choose to be licensed under the terms of the
147  * GNU General Public License ("GPL") version 2 as published by the Free
148  * Software Foundation.
149  *
150  *****************************************************************************/
151 
152 #include <contrib/dev/acpica/compiler/aslcompiler.h>
153 #include "aslcompiler.y.h"
154 #include <contrib/dev/acpica/include/acdisasm.h>
155 #include <contrib/dev/acpica/include/acnamesp.h>
156 #include <contrib/dev/acpica/include/amlcode.h>
157 #include <contrib/dev/acpica/include/acapps.h>
158 #include <sys/stat.h>
159 
160 
161 #define _COMPONENT          ACPI_COMPILER
162         ACPI_MODULE_NAME    ("aslutils")
163 
164 
165 /* Local prototypes */
166 
167 static void
168 UtPadNameWithUnderscores (
169     char                    *NameSeg,
170     char                    *PaddedNameSeg);
171 
172 static void
173 UtAttachNameseg (
174     ACPI_PARSE_OBJECT       *Op,
175     char                    *Name);
176 
177 
178 /*******************************************************************************
179  *
180  * FUNCTION:    UtIsBigEndianMachine
181  *
182  * PARAMETERS:  None
183  *
184  * RETURN:      TRUE if machine is big endian
185  *              FALSE if machine is little endian
186  *
187  * DESCRIPTION: Detect whether machine is little endian or big endian.
188  *
189  ******************************************************************************/
190 
191 UINT8
192 UtIsBigEndianMachine (
193     void)
194 {
195     union {
196         UINT32              Integer;
197         UINT8               Bytes[4];
198     } Overlay =                 {0xFF000000};
199 
200 
201     return (Overlay.Bytes[0]); /* Returns 0xFF (TRUE) for big endian */
202 }
203 
204 
205 /******************************************************************************
206  *
207  * FUNCTION:    UtQueryForOverwrite
208  *
209  * PARAMETERS:  Pathname            - Output filename
210  *
211  * RETURN:      TRUE if file does not exist or overwrite is authorized
212  *
213  * DESCRIPTION: Query for file overwrite if it already exists.
214  *
215  ******************************************************************************/
216 
217 BOOLEAN
218 UtQueryForOverwrite (
219     char                    *Pathname)
220 {
221     struct stat             StatInfo;
222 
223 
224     if (!stat (Pathname, &StatInfo))
225     {
226         fprintf (stderr, "Target file \"%s\" already exists, overwrite? [y|n] ",
227             Pathname);
228 
229         if (getchar () != 'y')
230         {
231             return (FALSE);
232         }
233     }
234 
235     return (TRUE);
236 }
237 
238 
239 /*******************************************************************************
240  *
241  * FUNCTION:    UtDisplaySupportedTables
242  *
243  * PARAMETERS:  None
244  *
245  * RETURN:      None
246  *
247  * DESCRIPTION: Print all supported ACPI table names.
248  *
249  ******************************************************************************/
250 
251 void
252 UtDisplaySupportedTables (
253     void)
254 {
255     const AH_TABLE          *TableData;
256     UINT32                  i;
257 
258 
259     printf ("\nACPI tables supported by iASL version %8.8X:\n"
260         "  (Compiler, Disassembler, Template Generator)\n\n",
261         ACPI_CA_VERSION);
262 
263     /* All ACPI tables with the common table header */
264 
265     printf ("\n  Supported ACPI tables:\n");
266     for (TableData = Gbl_AcpiSupportedTables, i = 1;
267          TableData->Signature; TableData++, i++)
268     {
269         printf ("%8u) %s    %s\n", i,
270             TableData->Signature, TableData->Description);
271     }
272 }
273 
274 
275 /*******************************************************************************
276  *
277  * FUNCTION:    UtDisplayConstantOpcodes
278  *
279  * PARAMETERS:  None
280  *
281  * RETURN:      None
282  *
283  * DESCRIPTION: Print AML opcodes that can be used in constant expressions.
284  *
285  ******************************************************************************/
286 
287 void
288 UtDisplayConstantOpcodes (
289     void)
290 {
291     UINT32                  i;
292 
293 
294     printf ("Constant expression opcode information\n\n");
295 
296     for (i = 0; i < sizeof (AcpiGbl_AmlOpInfo) / sizeof (ACPI_OPCODE_INFO); i++)
297     {
298         if (AcpiGbl_AmlOpInfo[i].Flags & AML_CONSTANT)
299         {
300             printf ("%s\n", AcpiGbl_AmlOpInfo[i].Name);
301         }
302     }
303 }
304 
305 
306 /*******************************************************************************
307  *
308  * FUNCTION:    UtBeginEvent
309  *
310  * PARAMETERS:  Name                - Ascii name of this event
311  *
312  * RETURN:      Event number (integer index)
313  *
314  * DESCRIPTION: Saves the current time with this event
315  *
316  ******************************************************************************/
317 
318 UINT8
319 UtBeginEvent (
320     char                    *Name)
321 {
322 
323     if (AslGbl_NextEvent >= ASL_NUM_EVENTS)
324     {
325         AcpiOsPrintf ("Ran out of compiler event structs!\n");
326         return (AslGbl_NextEvent);
327     }
328 
329     /* Init event with current (start) time */
330 
331     AslGbl_Events[AslGbl_NextEvent].StartTime = AcpiOsGetTimer ();
332     AslGbl_Events[AslGbl_NextEvent].EventName = Name;
333     AslGbl_Events[AslGbl_NextEvent].Valid = TRUE;
334     return (AslGbl_NextEvent++);
335 }
336 
337 
338 /*******************************************************************************
339  *
340  * FUNCTION:    UtEndEvent
341  *
342  * PARAMETERS:  Event               - Event number (integer index)
343  *
344  * RETURN:      None
345  *
346  * DESCRIPTION: Saves the current time (end time) with this event
347  *
348  ******************************************************************************/
349 
350 void
351 UtEndEvent (
352     UINT8                   Event)
353 {
354 
355     if (Event >= ASL_NUM_EVENTS)
356     {
357         return;
358     }
359 
360     /* Insert end time for event */
361 
362     AslGbl_Events[Event].EndTime = AcpiOsGetTimer ();
363 }
364 
365 
366 /*******************************************************************************
367  *
368  * FUNCTION:    DbgPrint
369  *
370  * PARAMETERS:  Type                - Type of output
371  *              Fmt                 - Printf format string
372  *              ...                 - variable printf list
373  *
374  * RETURN:      None
375  *
376  * DESCRIPTION: Conditional print statement. Prints to stderr only if the
377  *              debug flag is set.
378  *
379  ******************************************************************************/
380 
381 void
382 DbgPrint (
383     UINT32                  Type,
384     char                    *Fmt,
385     ...)
386 {
387     va_list                 Args;
388 
389 
390     if (!Gbl_DebugFlag)
391     {
392         return;
393     }
394 
395     if ((Type == ASL_PARSE_OUTPUT) &&
396         (!(AslCompilerdebug)))
397     {
398         return;
399     }
400 
401     va_start (Args, Fmt);
402     (void) vfprintf (stderr, Fmt, Args);
403     va_end (Args);
404     return;
405 }
406 
407 
408 /*******************************************************************************
409  *
410  * FUNCTION:    UtSetParseOpName
411  *
412  * PARAMETERS:  Op                  - Parse op to be named.
413  *
414  * RETURN:      None
415  *
416  * DESCRIPTION: Insert the ascii name of the parse opcode
417  *
418  ******************************************************************************/
419 
420 void
421 UtSetParseOpName (
422     ACPI_PARSE_OBJECT       *Op)
423 {
424 
425     strncpy (Op->Asl.ParseOpName, UtGetOpName (Op->Asl.ParseOpcode),
426         ACPI_MAX_PARSEOP_NAME);
427 }
428 
429 
430 /*******************************************************************************
431  *
432  * FUNCTION:    UtDisplaySummary
433  *
434  * PARAMETERS:  FileID              - ID of outpout file
435  *
436  * RETURN:      None
437  *
438  * DESCRIPTION: Display compilation statistics
439  *
440  ******************************************************************************/
441 
442 void
443 UtDisplaySummary (
444     UINT32                  FileId)
445 {
446     UINT32                  i;
447 
448 
449     if (FileId != ASL_FILE_STDOUT)
450     {
451         /* Compiler name and version number */
452 
453         FlPrintFile (FileId, "%s version %X\n\n",
454             ASL_COMPILER_NAME, (UINT32) ACPI_CA_VERSION);
455     }
456 
457     /* Summary of main input and output files */
458 
459     if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA)
460     {
461         FlPrintFile (FileId,
462             "%-14s %s - %u lines, %u bytes, %u fields\n",
463             "Table Input:",
464             Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_CurrentLineNumber,
465             Gbl_InputByteCount, Gbl_InputFieldCount);
466 
467         if ((Gbl_ExceptionCount[ASL_ERROR] == 0) || (Gbl_IgnoreErrors))
468         {
469             FlPrintFile (FileId,
470                 "%-14s %s - %u bytes\n",
471                 "Binary Output:",
472                 Gbl_Files[ASL_FILE_AML_OUTPUT].Filename, Gbl_TableLength);
473         }
474     }
475     else
476     {
477         FlPrintFile (FileId,
478             "%-14s %s - %u lines, %u bytes, %u keywords\n",
479             "ASL Input:",
480             Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_CurrentLineNumber,
481             Gbl_OriginalInputFileSize, TotalKeywords);
482 
483         /* AML summary */
484 
485         if ((Gbl_ExceptionCount[ASL_ERROR] == 0) || (Gbl_IgnoreErrors))
486         {
487             if (Gbl_Files[ASL_FILE_AML_OUTPUT].Handle)
488             {
489                 FlPrintFile (FileId,
490                     "%-14s %s - %u bytes, %u named objects, "
491                     "%u executable opcodes\n",
492                     "AML Output:",
493                     Gbl_Files[ASL_FILE_AML_OUTPUT].Filename,
494                     FlGetFileSize (ASL_FILE_AML_OUTPUT),
495                     TotalNamedObjects, TotalExecutableOpcodes);
496             }
497         }
498     }
499 
500     /* Display summary of any optional files */
501 
502     for (i = ASL_FILE_SOURCE_OUTPUT; i <= ASL_MAX_FILE_TYPE; i++)
503     {
504         if (!Gbl_Files[i].Filename || !Gbl_Files[i].Handle)
505         {
506             continue;
507         }
508 
509         /* .SRC is a temp file unless specifically requested */
510 
511         if ((i == ASL_FILE_SOURCE_OUTPUT) && (!Gbl_SourceOutputFlag))
512         {
513             continue;
514         }
515 
516         /* .PRE is the preprocessor intermediate file */
517 
518         if ((i == ASL_FILE_PREPROCESSOR)  && (!Gbl_KeepPreprocessorTempFile))
519         {
520             continue;
521         }
522 
523         FlPrintFile (FileId, "%14s %s - %u bytes\n",
524             Gbl_Files[i].ShortDescription,
525             Gbl_Files[i].Filename, FlGetFileSize (i));
526     }
527 
528     /* Error summary */
529 
530     FlPrintFile (FileId,
531         "\nCompilation complete. %u Errors, %u Warnings, %u Remarks",
532         Gbl_ExceptionCount[ASL_ERROR],
533         Gbl_ExceptionCount[ASL_WARNING] +
534             Gbl_ExceptionCount[ASL_WARNING2] +
535             Gbl_ExceptionCount[ASL_WARNING3],
536         Gbl_ExceptionCount[ASL_REMARK]);
537 
538     if (Gbl_FileType != ASL_INPUT_TYPE_ASCII_DATA)
539     {
540         FlPrintFile (FileId, ", %u Optimizations",
541             Gbl_ExceptionCount[ASL_OPTIMIZATION]);
542 
543         if (TotalFolds)
544         {
545             FlPrintFile (FileId, ", %u Constants Folded", TotalFolds);
546         }
547     }
548 
549     FlPrintFile (FileId, "\n");
550 }
551 
552 
553 /*******************************************************************************
554  *
555  * FUNCTION:    UtCheckIntegerRange
556  *
557  * PARAMETERS:  Op                  - Integer parse node
558  *              LowValue            - Smallest allowed value
559  *              HighValue           - Largest allowed value
560  *
561  * RETURN:      Op if OK, otherwise NULL
562  *
563  * DESCRIPTION: Check integer for an allowable range
564  *
565  ******************************************************************************/
566 
567 ACPI_PARSE_OBJECT *
568 UtCheckIntegerRange (
569     ACPI_PARSE_OBJECT       *Op,
570     UINT32                  LowValue,
571     UINT32                  HighValue)
572 {
573 
574     if (!Op)
575     {
576         return (NULL);
577     }
578 
579     if ((Op->Asl.Value.Integer < LowValue) ||
580         (Op->Asl.Value.Integer > HighValue))
581     {
582         sprintf (MsgBuffer, "0x%X, allowable: 0x%X-0x%X",
583             (UINT32) Op->Asl.Value.Integer, LowValue, HighValue);
584 
585         AslError (ASL_ERROR, ASL_MSG_RANGE, Op, MsgBuffer);
586         return (NULL);
587     }
588 
589     return (Op);
590 }
591 
592 
593 /*******************************************************************************
594  *
595  * FUNCTION:    UtInternalizeName
596  *
597  * PARAMETERS:  ExternalName        - Name to convert
598  *              ConvertedName       - Where the converted name is returned
599  *
600  * RETURN:      Status
601  *
602  * DESCRIPTION: Convert an external (ASL) name to an internal (AML) name
603  *
604  ******************************************************************************/
605 
606 ACPI_STATUS
607 UtInternalizeName (
608     char                    *ExternalName,
609     char                    **ConvertedName)
610 {
611     ACPI_NAMESTRING_INFO    Info;
612     ACPI_STATUS             Status;
613 
614 
615     if (!ExternalName)
616     {
617         return (AE_OK);
618     }
619 
620     /* Get the length of the new internal name */
621 
622     Info.ExternalName = ExternalName;
623     AcpiNsGetInternalNameLength (&Info);
624 
625     /* We need a segment to store the internal name */
626 
627     Info.InternalName = UtLocalCacheCalloc (Info.Length);
628 
629     /* Build the name */
630 
631     Status = AcpiNsBuildInternalName (&Info);
632     if (ACPI_FAILURE (Status))
633     {
634         return (Status);
635     }
636 
637     *ConvertedName = Info.InternalName;
638     return (AE_OK);
639 }
640 
641 
642 /*******************************************************************************
643  *
644  * FUNCTION:    UtPadNameWithUnderscores
645  *
646  * PARAMETERS:  NameSeg             - Input nameseg
647  *              PaddedNameSeg       - Output padded nameseg
648  *
649  * RETURN:      Padded nameseg.
650  *
651  * DESCRIPTION: Pads a NameSeg with underscores if necessary to form a full
652  *              ACPI_NAME.
653  *
654  ******************************************************************************/
655 
656 static void
657 UtPadNameWithUnderscores (
658     char                    *NameSeg,
659     char                    *PaddedNameSeg)
660 {
661     UINT32                  i;
662 
663 
664     for (i = 0; (i < ACPI_NAME_SIZE); i++)
665     {
666         if (*NameSeg)
667         {
668             *PaddedNameSeg = *NameSeg;
669             NameSeg++;
670         }
671         else
672         {
673             *PaddedNameSeg = '_';
674         }
675 
676         PaddedNameSeg++;
677     }
678 }
679 
680 
681 /*******************************************************************************
682  *
683  * FUNCTION:    UtAttachNameseg
684  *
685  * PARAMETERS:  Op                  - Parent parse node
686  *              Name                - Full ExternalName
687  *
688  * RETURN:      None; Sets the NameSeg field in parent node
689  *
690  * DESCRIPTION: Extract the last nameseg of the ExternalName and store it
691  *              in the NameSeg field of the Op.
692  *
693  ******************************************************************************/
694 
695 static void
696 UtAttachNameseg (
697     ACPI_PARSE_OBJECT       *Op,
698     char                    *Name)
699 {
700     char                    *NameSeg;
701     char                    PaddedNameSeg[4];
702 
703 
704     if (!Name)
705     {
706         return;
707     }
708 
709     /* Look for the last dot in the namepath */
710 
711     NameSeg = strrchr (Name, '.');
712     if (NameSeg)
713     {
714         /* Found last dot, we have also found the final nameseg */
715 
716         NameSeg++;
717         UtPadNameWithUnderscores (NameSeg, PaddedNameSeg);
718     }
719     else
720     {
721         /* No dots in the namepath, there is only a single nameseg. */
722         /* Handle prefixes */
723 
724         while (ACPI_IS_ROOT_PREFIX (*Name) ||
725                ACPI_IS_PARENT_PREFIX (*Name))
726         {
727             Name++;
728         }
729 
730         /* Remaining string should be one single nameseg */
731 
732         UtPadNameWithUnderscores (Name, PaddedNameSeg);
733     }
734 
735     ACPI_MOVE_NAME (Op->Asl.NameSeg, PaddedNameSeg);
736 }
737 
738 
739 /*******************************************************************************
740  *
741  * FUNCTION:    UtAttachNamepathToOwner
742  *
743  * PARAMETERS:  Op                  - Parent parse node
744  *              NameOp              - Node that contains the name
745  *
746  * RETURN:      Sets the ExternalName and Namepath in the parent node
747  *
748  * DESCRIPTION: Store the name in two forms in the parent node: The original
749  *              (external) name, and the internalized name that is used within
750  *              the ACPI namespace manager.
751  *
752  ******************************************************************************/
753 
754 void
755 UtAttachNamepathToOwner (
756     ACPI_PARSE_OBJECT       *Op,
757     ACPI_PARSE_OBJECT       *NameOp)
758 {
759     ACPI_STATUS             Status;
760 
761 
762     /* Full external path */
763 
764     Op->Asl.ExternalName = NameOp->Asl.Value.String;
765 
766     /* Save the NameOp for possible error reporting later */
767 
768     Op->Asl.ParentMethod = (void *) NameOp;
769 
770     /* Last nameseg of the path */
771 
772     UtAttachNameseg (Op, Op->Asl.ExternalName);
773 
774     /* Create internalized path */
775 
776     Status = UtInternalizeName (NameOp->Asl.Value.String, &Op->Asl.Namepath);
777     if (ACPI_FAILURE (Status))
778     {
779         /* TBD: abort on no memory */
780     }
781 }
782 
783 
784 /*******************************************************************************
785  *
786  * FUNCTION:    UtDoConstant
787  *
788  * PARAMETERS:  String              - Hex/Decimal/Octal
789  *
790  * RETURN:      Converted Integer
791  *
792  * DESCRIPTION: Convert a string to an integer, with overflow/error checking.
793  *
794  ******************************************************************************/
795 
796 UINT64
797 UtDoConstant (
798     char                    *String)
799 {
800     ACPI_STATUS             Status;
801     UINT64                  ConvertedInteger;
802     char                    ErrBuf[64];
803 
804 
805     Status = AcpiUtStrtoul64 (String, &ConvertedInteger);
806     if (ACPI_FAILURE (Status))
807     {
808         sprintf (ErrBuf, "While creating 64-bit constant: %s\n",
809             AcpiFormatException (Status));
810 
811         AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, Gbl_CurrentLineNumber,
812             Gbl_LogicalLineNumber, Gbl_CurrentLineOffset,
813             Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename, ErrBuf);
814     }
815 
816     return (ConvertedInteger);
817 }
818