1 
2 /******************************************************************************
3  *
4  * Module Name: aslutils -- compiler utilities
5  *              $Revision: 1.66 $
6  *
7  *****************************************************************************/
8 
9 /******************************************************************************
10  *
11  * 1. Copyright Notice
12  *
13  * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
14  * All rights reserved.
15  *
16  * 2. License
17  *
18  * 2.1. This is your license from Intel Corp. under its intellectual property
19  * rights.  You may have additional license terms from the party that provided
20  * you this software, covering your right to use that party's intellectual
21  * property rights.
22  *
23  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24  * copy of the source code appearing in this file ("Covered Code") an
25  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26  * base code distributed originally by Intel ("Original Intel Code") to copy,
27  * make derivatives, distribute, use and display any portion of the Covered
28  * Code in any form, with the right to sublicense such rights; and
29  *
30  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31  * license (with the right to sublicense), under only those claims of Intel
32  * patents that are infringed by the Original Intel Code, to make, use, sell,
33  * offer to sell, and import the Covered Code and derivative works thereof
34  * solely to the minimum extent necessary to exercise the above copyright
35  * license, and in no event shall the patent license extend to any additions
36  * to or modifications of the Original Intel Code.  No other license or right
37  * is granted directly or by implication, estoppel or otherwise;
38  *
39  * The above copyright and patent license is granted only if the following
40  * conditions are met:
41  *
42  * 3. Conditions
43  *
44  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45  * Redistribution of source code of any substantial portion of the Covered
46  * Code or modification with rights to further distribute source must include
47  * the above Copyright Notice, the above License, this list of Conditions,
48  * and the following Disclaimer and Export Compliance provision.  In addition,
49  * Licensee must cause all Covered Code to which Licensee contributes to
50  * contain a file documenting the changes Licensee made to create that Covered
51  * Code and the date of any change.  Licensee must include in that file the
52  * documentation of any changes made by any predecessor Licensee.  Licensee
53  * must include a prominent statement that the modification is derived,
54  * directly or indirectly, from Original Intel Code.
55  *
56  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57  * Redistribution of source code of any substantial portion of the Covered
58  * Code or modification without rights to further distribute source must
59  * include the following Disclaimer and Export Compliance provision in the
60  * documentation and/or other materials provided with distribution.  In
61  * addition, Licensee may not authorize further sublicense of source of any
62  * portion of the Covered Code, and must include terms to the effect that the
63  * license from Licensee to its licensee is limited to the intellectual
64  * property embodied in the software Licensee provides to its licensee, and
65  * not to intellectual property embodied in modifications its licensee may
66  * make.
67  *
68  * 3.3. Redistribution of Executable. Redistribution in executable form of any
69  * substantial portion of the Covered Code or modification must reproduce the
70  * above Copyright Notice, and the following Disclaimer and Export Compliance
71  * provision in the documentation and/or other materials provided with the
72  * distribution.
73  *
74  * 3.4. Intel retains all right, title, and interest in and to the Original
75  * Intel Code.
76  *
77  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78  * Intel shall be used in advertising or otherwise to promote the sale, use or
79  * other dealings in products derived from or relating to the Covered Code
80  * without prior written authorization from Intel.
81  *
82  * 4. Disclaimer and Export Compliance
83  *
84  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
87  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
88  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
89  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90  * PARTICULAR PURPOSE.
91  *
92  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
98  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99  * LIMITED REMEDY.
100  *
101  * 4.3. Licensee shall not export, either directly or indirectly, any of this
102  * software or system incorporating such software without first obtaining any
103  * required license or other approval from the U. S. Department of Commerce or
104  * any other agency or department of the United States Government.  In the
105  * event Licensee exports any such software from the United States or
106  * re-exports any such software from a foreign destination, Licensee shall
107  * ensure that the distribution and export/re-export of the software is in
108  * compliance with all laws, regulations, orders, or other restrictions of the
109  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110  * any of its subsidiaries will export/re-export any technical data, process,
111  * software, or service, directly or indirectly, to any country for which the
112  * United States government or any agency thereof requires an export license,
113  * other governmental approval, or letter of assurance, without first obtaining
114  * such license, approval or letter.
115  *
116  *****************************************************************************/
117 
118 
119 #include <contrib/dev/acpica/compiler/aslcompiler.h>
120 #include "aslcompiler.y.h"
121 #include <contrib/dev/acpica/acnamesp.h>
122 #include <contrib/dev/acpica/amlcode.h>
123 
124 #define _COMPONENT          ACPI_COMPILER
125         ACPI_MODULE_NAME    ("aslutils")
126 
127 #ifdef _USE_BERKELEY_YACC
128 extern const char * const       AslCompilername[];
129 static const char * const       *yytname = &AslCompilername[254];
130 #else
131 extern const char * const       yytname[];
132 #endif
133 
134 /* Local prototypes */
135 
136 static ACPI_STATUS
137 UtStrtoul64 (
138     char                    *String,
139     UINT32                  Base,
140     ACPI_INTEGER            *RetInteger);
141 
142 static void
143 UtPadNameWithUnderscores (
144     char                    *NameSeg,
145     char                    *PaddedNameSeg);
146 
147 static void
148 UtAttachNameseg (
149     ACPI_PARSE_OBJECT       *Op,
150     char                    *Name);
151 
152 
153 /*******************************************************************************
154  *
155  * FUNCTION:    AcpiPsDisplayConstantOpcodes
156  *
157  * PARAMETERS:  None
158  *
159  * RETURN:      None
160  *
161  * DESCRIPTION: Print AML opcodes that can be used in constant expressions.
162  *
163  ******************************************************************************/
164 
165 void
166 UtDisplayConstantOpcodes (
167     void)
168 {
169     UINT32              i;
170 
171 
172     printf ("Constant expression opcode information\n\n");
173 
174     for (i = 0; i < sizeof (AcpiGbl_AmlOpInfo) / sizeof (ACPI_OPCODE_INFO); i++)
175     {
176         if (AcpiGbl_AmlOpInfo[i].Flags & AML_CONSTANT)
177         {
178             printf ("%s\n", AcpiGbl_AmlOpInfo[i].Name);
179         }
180     }
181 }
182 
183 
184 /*******************************************************************************
185  *
186  * FUNCTION:    UtLocalCalloc
187  *
188  * PARAMETERS:  Size        - Bytes to be allocated
189  *
190  * RETURN:      Pointer to the allocated memory.  Guaranteed to be valid.
191  *
192  * DESCRIPTION: Allocate zero-initialized memory.  Aborts the compile on an
193  *              allocation failure, on the assumption that nothing more can be
194  *              accomplished.
195  *
196  ******************************************************************************/
197 
198 void *
199 UtLocalCalloc (
200     UINT32                  Size)
201 {
202     void                    *Allocated;
203 
204 
205     Allocated = ACPI_MEM_CALLOCATE (Size);
206     if (!Allocated)
207     {
208         AslCommonError (ASL_ERROR, ASL_MSG_MEMORY_ALLOCATION,
209             Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
210             Gbl_InputByteCount, Gbl_CurrentColumn,
211             Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
212         exit (1);
213     }
214 
215     TotalAllocations++;
216     TotalAllocated += Size;
217     return Allocated;
218 }
219 
220 
221 /*******************************************************************************
222  *
223  * FUNCTION:    UtBeginEvent
224  *
225  * PARAMETERS:  Name        - Ascii name of this event
226  *
227  * RETURN:      Event       - Event number (integer index)
228  *
229  * DESCRIPTION: Saves the current time with this event
230  *
231  ******************************************************************************/
232 
233 UINT8
234 UtBeginEvent (
235     char                    *Name)
236 {
237 
238     if (AslGbl_NextEvent >= ASL_NUM_EVENTS)
239     {
240         AcpiOsPrintf ("Ran out of compiler event structs!\n");
241         return (AslGbl_NextEvent);
242     }
243 
244     /* Init event with current (start) time */
245 
246     AslGbl_Events[AslGbl_NextEvent].StartTime = AcpiOsGetTimer ();
247     AslGbl_Events[AslGbl_NextEvent].EventName = Name;
248     AslGbl_Events[AslGbl_NextEvent].Valid = TRUE;
249 
250     return (AslGbl_NextEvent++);
251 }
252 
253 
254 /*******************************************************************************
255  *
256  * FUNCTION:    UtEndEvent
257  *
258  * PARAMETERS:  Event       - Event number (integer index)
259  *
260  * RETURN:      None
261  *
262  * DESCRIPTION: Saves the current time (end time) with this event
263  *
264  ******************************************************************************/
265 
266 void
267 UtEndEvent (
268     UINT8                  Event)
269 {
270 
271     if (Event >= ASL_NUM_EVENTS)
272     {
273         return;
274     }
275 
276     /* Insert end time for event */
277 
278     AslGbl_Events[Event].EndTime = AcpiOsGetTimer ();
279 }
280 
281 
282 /*******************************************************************************
283  *
284  * FUNCTION:    UtHexCharToValue
285  *
286  * PARAMETERS:  HexChar         - Hex character in Ascii
287  *
288  * RETURN:      The binary value of the hex character
289  *
290  * DESCRIPTION: Perform ascii-to-hex translation
291  *
292  ******************************************************************************/
293 
294 UINT8
295 UtHexCharToValue (
296     int                     HexChar)
297 {
298 
299     if (HexChar <= 0x39)
300     {
301         return ((UINT8) (HexChar - 0x30));
302     }
303 
304     if (HexChar <= 0x46)
305     {
306         return ((UINT8) (HexChar - 0x37));
307     }
308 
309     return ((UINT8) (HexChar - 0x57));
310 }
311 
312 
313 /*******************************************************************************
314  *
315  * FUNCTION:    UtConvertByteToHex
316  *
317  * PARAMETERS:  RawByte         - Binary data
318  *              Buffer          - Pointer to where the hex bytes will be stored
319  *
320  * RETURN:      Ascii hex byte is stored in Buffer.
321  *
322  * DESCRIPTION: Perform hex-to-ascii translation.  The return data is prefixed
323  *              with "0x"
324  *
325  ******************************************************************************/
326 
327 void
328 UtConvertByteToHex (
329     UINT8                   RawByte,
330     UINT8                   *Buffer)
331 {
332 
333     Buffer[0] = '0';
334     Buffer[1] = 'x';
335 
336     Buffer[2] = (UINT8) hex[(RawByte >> 4) & 0xF];
337     Buffer[3] = (UINT8) hex[RawByte & 0xF];
338 }
339 
340 
341 /*******************************************************************************
342  *
343  * FUNCTION:    UtConvertByteToAsmHex
344  *
345  * PARAMETERS:  RawByte         - Binary data
346  *              Buffer          - Pointer to where the hex bytes will be stored
347  *
348  * RETURN:      Ascii hex byte is stored in Buffer.
349  *
350  * DESCRIPTION: Perform hex-to-ascii translation.  The return data is prefixed
351  *              with "0x"
352  *
353  ******************************************************************************/
354 
355 void
356 UtConvertByteToAsmHex (
357     UINT8                   RawByte,
358     UINT8                   *Buffer)
359 {
360 
361     Buffer[0] = '0';
362 
363     Buffer[1] = (UINT8) hex[(RawByte >> 4) & 0xF];
364     Buffer[2] = (UINT8) hex[RawByte & 0xF];
365     Buffer[3] = 'h';
366 }
367 
368 
369 /*******************************************************************************
370  *
371  * FUNCTION:    DbgPrint
372  *
373  * PARAMETERS:  Type            - Type of output
374  *              Fmt             - Printf format string
375  *              ...             - variable printf list
376  *
377  * RETURN:      None
378  *
379  * DESCRIPTION: Conditional print statement.  Prints to stderr only if the
380  *              debug flag is set.
381  *
382  ******************************************************************************/
383 
384 void
385 DbgPrint (
386     UINT32                  Type,
387     char                    *Fmt,
388     ...)
389 {
390     va_list                 Args;
391 
392 
393     va_start (Args, Fmt);
394 
395     if (!Gbl_DebugFlag)
396     {
397         return;
398     }
399 
400     if ((Type == ASL_PARSE_OUTPUT) &&
401         (!(AslCompilerdebug)))
402     {
403         return;
404     }
405 
406     (void) vfprintf (stderr, Fmt, Args);
407     va_end (Args);
408     return;
409 }
410 
411 
412 /*******************************************************************************
413  *
414  * FUNCTION:    UtPrintFormattedName
415  *
416  * PARAMETERS:  ParseOpcode         - Parser keyword ID
417  *              Level               - Indentation level
418  *
419  * RETURN:      None
420  *
421  * DESCRIPTION: Print the ascii name of the parse opcode.
422  *
423  ******************************************************************************/
424 
425 #define TEXT_OFFSET 10
426 
427 void
428 UtPrintFormattedName (
429     UINT16                  ParseOpcode,
430     UINT32                  Level)
431 {
432 
433     DbgPrint (ASL_TREE_OUTPUT,
434         "%*s %-16.16s", (3 * Level), " ",
435         UtGetOpName (ParseOpcode));
436 
437     if (Level < TEXT_OFFSET)
438     {
439         DbgPrint (ASL_TREE_OUTPUT,
440             "%*s", (TEXT_OFFSET - Level) * 3, " ");
441     }
442 }
443 
444 
445 /*******************************************************************************
446  *
447  * FUNCTION:    UtSetParseOpName
448  *
449  * PARAMETERS:  Op
450  *
451  * RETURN:      None
452  *
453  * DESCRIPTION: Insert the ascii name of the parse opcode
454  *
455  ******************************************************************************/
456 
457 void
458 UtSetParseOpName (
459     ACPI_PARSE_OBJECT       *Op)
460 {
461 
462     strncpy (Op->Asl.ParseOpName, UtGetOpName (Op->Asl.ParseOpcode), 12);
463 }
464 
465 
466 /*******************************************************************************
467  *
468  * FUNCTION:    UtGetOpName
469  *
470  * PARAMETERS:  ParseOpcode         - Parser keyword ID
471  *
472  * RETURN:      Pointer to the opcode name
473  *
474  * DESCRIPTION: Get the ascii name of the parse opcode
475  *
476  ******************************************************************************/
477 
478 char *
479 UtGetOpName (
480     UINT32                  ParseOpcode)
481 {
482 
483     /*
484      * First entries (ASL_YYTNAME_START) in yytname are special reserved names.
485      * Ignore first 8 characters of the name
486      */
487     return ((char *) yytname [(ParseOpcode - ASL_FIRST_PARSE_OPCODE) + ASL_YYTNAME_START] + 8);
488 }
489 
490 
491 /*******************************************************************************
492  *
493  * FUNCTION:    UtDisplaySummary
494  *
495  * PARAMETERS:  FileID          - ID of outpout file
496  *
497  * RETURN:      None
498  *
499  * DESCRIPTION: Display compilation statistics
500  *
501  ******************************************************************************/
502 
503 void
504 UtDisplaySummary (
505     UINT32                  FileId)
506 {
507 
508     if (FileId != ASL_FILE_STDOUT)
509     {
510         /* Compiler name and version number */
511 
512         FlPrintFile (FileId, "%s version %X [%s]\n",
513             CompilerId, (UINT32) ACPI_CA_VERSION, __DATE__);
514     }
515 
516     /* Input/Output summary */
517 
518     FlPrintFile (FileId,
519         "ASL Input:  %s - %d lines, %d bytes, %d keywords\n",
520         Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_CurrentLineNumber,
521         Gbl_InputByteCount, TotalKeywords);
522 
523     /* AML summary */
524 
525     if ((Gbl_ExceptionCount[ASL_ERROR] == 0) || (Gbl_IgnoreErrors))
526     {
527         FlPrintFile (FileId,
528             "AML Output: %s - %d bytes %d named objects %d executable opcodes\n\n",
529             Gbl_Files[ASL_FILE_AML_OUTPUT].Filename, Gbl_TableLength,
530             TotalNamedObjects, TotalExecutableOpcodes);
531     }
532 
533     /* Error summary */
534 
535     FlPrintFile (FileId,
536         "Compilation complete. %d Errors, %d Warnings, %d Remarks, %d Optimizations\n",
537         Gbl_ExceptionCount[ASL_ERROR],
538         Gbl_ExceptionCount[ASL_WARNING],
539         Gbl_ExceptionCount[ASL_REMARK],
540         Gbl_ExceptionCount[ASL_OPTIMIZATION]);
541 }
542 
543 
544 /*******************************************************************************
545  *
546  * FUNCTION:    UtDisplaySummary
547  *
548  * PARAMETERS:  Op            - Integer parse node
549  *              LowValue        - Smallest allowed value
550  *              HighValue       - Largest allowed value
551  *
552  * RETURN:      Op if OK, otherwise NULL
553  *
554  * DESCRIPTION: Check integer for an allowable range
555  *
556  ******************************************************************************/
557 
558 ACPI_PARSE_OBJECT *
559 UtCheckIntegerRange (
560     ACPI_PARSE_OBJECT       *Op,
561     UINT32                  LowValue,
562     UINT32                  HighValue)
563 {
564     char                    *ParseError = NULL;
565     char                    Buffer[64];
566 
567 
568     if (!Op)
569     {
570         return NULL;
571     }
572 
573     if (Op->Asl.Value.Integer < LowValue)
574     {
575         ParseError = "Value below valid range";
576         Op->Asl.Value.Integer = LowValue;
577     }
578 
579     if (Op->Asl.Value.Integer > HighValue)
580     {
581         ParseError = "Value above valid range";
582         Op->Asl.Value.Integer = HighValue;
583     }
584 
585     if (ParseError)
586     {
587         sprintf (Buffer, "%s 0x%X-0x%X", ParseError, LowValue, HighValue);
588         AslCompilererror (Buffer);
589 
590         return NULL;
591     }
592 
593     return Op;
594 }
595 
596 
597 /*******************************************************************************
598  *
599  * FUNCTION:    UtGetStringBuffer
600  *
601  * PARAMETERS:  Length          - Size of buffer requested
602  *
603  * RETURN:      Pointer to the buffer.  Aborts on allocation failure
604  *
605  * DESCRIPTION: Allocate a string buffer.  Bypass the local
606  *              dynamic memory manager for performance reasons (This has a
607  *              major impact on the speed of the compiler.)
608  *
609  ******************************************************************************/
610 
611 char *
612 UtGetStringBuffer (
613     UINT32                  Length)
614 {
615     char                    *Buffer;
616 
617 
618     if ((Gbl_StringCacheNext + Length) >= Gbl_StringCacheLast)
619     {
620         Gbl_StringCacheNext = UtLocalCalloc (ASL_STRING_CACHE_SIZE + Length);
621         Gbl_StringCacheLast = Gbl_StringCacheNext + ASL_STRING_CACHE_SIZE +
622                                 Length;
623     }
624 
625     Buffer = Gbl_StringCacheNext;
626     Gbl_StringCacheNext += Length;
627 
628     return (Buffer);
629 }
630 
631 
632 /*******************************************************************************
633  *
634  * FUNCTION:    UtInternalizeName
635  *
636  * PARAMETERS:  ExternalName            - Name to convert
637  *              ConvertedName           - Where the converted name is returned
638  *
639  * RETURN:      Status
640  *
641  * DESCRIPTION: Convert an external (ASL) name to an internal (AML) name
642  *
643  ******************************************************************************/
644 
645 ACPI_STATUS
646 UtInternalizeName (
647     char                    *ExternalName,
648     char                    **ConvertedName)
649 {
650     ACPI_NAMESTRING_INFO    Info;
651     ACPI_STATUS             Status;
652 
653 
654     if (!ExternalName)
655     {
656         return (AE_OK);
657     }
658 
659     /* Get the length of the new internal name */
660 
661     Info.ExternalName = ExternalName;
662     AcpiNsGetInternalNameLength (&Info);
663 
664     /* We need a segment to store the internal  name */
665 
666     Info.InternalName = UtGetStringBuffer (Info.Length);
667     if (!Info.InternalName)
668     {
669         return (AE_NO_MEMORY);
670     }
671 
672     /* Build the name */
673 
674     Status = AcpiNsBuildInternalName (&Info);
675     if (ACPI_FAILURE (Status))
676     {
677         return (Status);
678     }
679 
680     *ConvertedName = Info.InternalName;
681     return (AE_OK);
682 }
683 
684 
685 /*******************************************************************************
686  *
687  * FUNCTION:    UtPadNameWithUnderscores
688  *
689  * PARAMETERS:  NameSeg         - Input nameseg
690  *              PaddedNameSeg   - Output padded nameseg
691  *
692  * RETURN:      Padded nameseg.
693  *
694  * DESCRIPTION: Pads a NameSeg with underscores if necessary to form a full
695  *              ACPI_NAME.
696  *
697  ******************************************************************************/
698 
699 static void
700 UtPadNameWithUnderscores (
701     char                    *NameSeg,
702     char                    *PaddedNameSeg)
703 {
704     UINT32                  i;
705 
706 
707     for (i = 0; (i < ACPI_NAME_SIZE); i++)
708     {
709         if (*NameSeg)
710         {
711             *PaddedNameSeg = *NameSeg;
712             NameSeg++;
713         }
714         else
715         {
716             *PaddedNameSeg = '_';
717         }
718         PaddedNameSeg++;
719     }
720 }
721 
722 
723 /*******************************************************************************
724  *
725  * FUNCTION:    UtAttachNameseg
726  *
727  * PARAMETERS:  Op              - Parent parse node
728  *              Name            - Full ExternalName
729  *
730  * RETURN:      None; Sets the NameSeg field in parent node
731  *
732  * DESCRIPTION: Extract the last nameseg of the ExternalName and store it
733  *              in the NameSeg field of the Op.
734  *
735  ******************************************************************************/
736 
737 static void
738 UtAttachNameseg (
739     ACPI_PARSE_OBJECT       *Op,
740     char                    *Name)
741 {
742     char                    *NameSeg;
743     char                    PaddedNameSeg[4];
744 
745 
746     if (!Name)
747     {
748         return;
749     }
750 
751     /* Look for the last dot in the namepath */
752 
753     NameSeg = strrchr (Name, '.');
754     if (NameSeg)
755     {
756         /* Found last dot, we have also found the final nameseg */
757 
758         NameSeg++;
759         UtPadNameWithUnderscores (NameSeg, PaddedNameSeg);
760     }
761     else
762     {
763         /* No dots in the namepath, there is only a single nameseg. */
764         /* Handle prefixes */
765 
766         while ((*Name == '\\') || (*Name == '^'))
767         {
768             Name++;
769         }
770 
771         /* Remaing string should be one single nameseg */
772 
773         UtPadNameWithUnderscores (Name, PaddedNameSeg);
774     }
775 
776     strncpy (Op->Asl.NameSeg, PaddedNameSeg, 4);
777 }
778 
779 
780 /*******************************************************************************
781  *
782  * FUNCTION:    UtAttachNamepathToOwner
783  *
784  * PARAMETERS:  Op            - Parent parse node
785  *              NameOp        - Node that contains the name
786  *
787  * RETURN:      Sets the ExternalName and Namepath in the parent node
788  *
789  * DESCRIPTION: Store the name in two forms in the parent node:  The original
790  *              (external) name, and the internalized name that is used within
791  *              the ACPI namespace manager.
792  *
793  ******************************************************************************/
794 
795 void
796 UtAttachNamepathToOwner (
797     ACPI_PARSE_OBJECT       *Op,
798     ACPI_PARSE_OBJECT       *NameOp)
799 {
800     ACPI_STATUS             Status;
801 
802 
803     /* Full external path */
804 
805     Op->Asl.ExternalName = NameOp->Asl.Value.String;
806 
807     /* Save the NameOp for possible error reporting later */
808 
809     Op->Asl.ParentMethod = (void *) NameOp;
810 
811     /* Last nameseg of the path */
812 
813     UtAttachNameseg (Op, Op->Asl.ExternalName);
814 
815     /* Create internalized path */
816 
817     Status = UtInternalizeName (NameOp->Asl.Value.String, &Op->Asl.Namepath);
818     if (ACPI_FAILURE (Status))
819     {
820         /* TBD: abort on no memory */
821     }
822 }
823 
824 
825 /*******************************************************************************
826  *
827  * FUNCTION:    UtDoConstant
828  *
829  * PARAMETERS:  String      - Hex, Octal, or Decimal string
830  *
831  * RETURN:      Converted Integer
832  *
833  * DESCRIPTION: Convert a string to an integer.  With error checking.
834  *
835  ******************************************************************************/
836 
837 ACPI_INTEGER
838 UtDoConstant (
839     char                    *String)
840 {
841     ACPI_STATUS             Status;
842     ACPI_INTEGER            Converted;
843     char                    ErrBuf[64];
844 
845 
846     Status = UtStrtoul64 (String, 0, &Converted);
847     if (ACPI_FAILURE (Status))
848     {
849         sprintf (ErrBuf, "%s %s\n", "Conversion error:",
850             AcpiFormatException (Status));
851         AslCompilererror (ErrBuf);
852     }
853 
854     return (Converted);
855 }
856 
857 
858 /* TBD: use version in ACPI CA main code base? */
859 
860 /*******************************************************************************
861  *
862  * FUNCTION:    UtStrtoul64
863  *
864  * PARAMETERS:  String          - Null terminated string
865  *              Terminater      - Where a pointer to the terminating byte is
866  *                                returned
867  *              Base            - Radix of the string
868  *
869  * RETURN:      Converted value
870  *
871  * DESCRIPTION: Convert a string into an unsigned value.
872  *
873  ******************************************************************************/
874 
875 static ACPI_STATUS
876 UtStrtoul64 (
877     char                    *String,
878     UINT32                  Base,
879     ACPI_INTEGER            *RetInteger)
880 {
881     UINT32                  Index;
882     UINT32                  Sign;
883     ACPI_INTEGER            ReturnValue = 0;
884     ACPI_STATUS             Status = AE_OK;
885 
886 
887     *RetInteger = 0;
888 
889     switch (Base)
890     {
891     case 0:
892     case 8:
893     case 10:
894     case 16:
895         break;
896 
897     default:
898         /*
899          * The specified Base parameter is not in the domain of
900          * this function:
901          */
902         return (AE_BAD_PARAMETER);
903     }
904 
905     /* Skip over any white space in the buffer: */
906 
907     while (isspace (*String) || *String == '\t')
908     {
909         ++String;
910     }
911 
912     /*
913      * The buffer may contain an optional plus or minus sign.
914      * If it does, then skip over it but remember what is was:
915      */
916     if (*String == '-')
917     {
918         Sign = NEGATIVE;
919         ++String;
920     }
921     else if (*String == '+')
922     {
923         ++String;
924         Sign = POSITIVE;
925     }
926     else
927     {
928         Sign = POSITIVE;
929     }
930 
931     /*
932      * If the input parameter Base is zero, then we need to
933      * determine if it is octal, decimal, or hexadecimal:
934      */
935     if (Base == 0)
936     {
937         if (*String == '0')
938         {
939             if (tolower (*(++String)) == 'x')
940             {
941                 Base = 16;
942                 ++String;
943             }
944             else
945             {
946                 Base = 8;
947             }
948         }
949         else
950         {
951             Base = 10;
952         }
953     }
954 
955     /*
956      * For octal and hexadecimal bases, skip over the leading
957      * 0 or 0x, if they are present.
958      */
959     if (Base == 8 && *String == '0')
960     {
961         String++;
962     }
963 
964     if (Base == 16 &&
965         *String == '0' &&
966         tolower (*(++String)) == 'x')
967     {
968         String++;
969     }
970 
971     /* Main loop: convert the string to an unsigned long */
972 
973     while (*String)
974     {
975         if (isdigit (*String))
976         {
977             Index = ((UINT8) *String) - '0';
978         }
979         else
980         {
981             Index = (UINT8) toupper (*String);
982             if (isupper ((char) Index))
983             {
984                 Index = Index - 'A' + 10;
985             }
986             else
987             {
988                 goto ErrorExit;
989             }
990         }
991 
992         if (Index >= Base)
993         {
994             goto ErrorExit;
995         }
996 
997         /* Check to see if value is out of range: */
998 
999         if (ReturnValue > ((ACPI_INTEGER_MAX - (ACPI_INTEGER) Index) /
1000                             (ACPI_INTEGER) Base))
1001         {
1002             goto ErrorExit;
1003         }
1004         else
1005         {
1006             ReturnValue *= Base;
1007             ReturnValue += Index;
1008         }
1009 
1010         ++String;
1011     }
1012 
1013 
1014     /* If a minus sign was present, then "the conversion is negated": */
1015 
1016     if (Sign == NEGATIVE)
1017     {
1018         ReturnValue = (ACPI_UINT32_MAX - ReturnValue) + 1;
1019     }
1020 
1021     *RetInteger = ReturnValue;
1022     return (Status);
1023 
1024 
1025 ErrorExit:
1026     switch (Base)
1027     {
1028     case 8:
1029         Status = AE_BAD_OCTAL_CONSTANT;
1030         break;
1031 
1032     case 10:
1033         Status = AE_BAD_DECIMAL_CONSTANT;
1034         break;
1035 
1036     case 16:
1037         Status = AE_BAD_HEX_CONSTANT;
1038         break;
1039 
1040     default:
1041         /* Base validated above */
1042         break;
1043     }
1044 
1045     return (Status);
1046 }
1047 
1048 
1049