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