Sync ACPICA with Intel's version 20170831.
[dragonfly.git] / sys / contrib / dev / acpica / source / compiler / aslutils.c
blob8b46d38bb532605faaa809e344af208a571b1e8e
1 /******************************************************************************
3 * Module Name: aslutils -- compiler utilities
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
12 * All rights reserved.
14 * 2. License
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.
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
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;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
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.
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.
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.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
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.
80 * 4. Disclaimer and Export Compliance
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.
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.
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.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
117 * following license:
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.
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.
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.
150 *****************************************************************************/
152 #include "aslcompiler.h"
153 #include "aslcompiler.y.h"
154 #include "acdisasm.h"
155 #include "acnamesp.h"
156 #include "amlcode.h"
157 #include "acapps.h"
158 #include <sys/stat.h>
161 #define _COMPONENT ACPI_COMPILER
162 ACPI_MODULE_NAME ("aslutils")
165 /* Local prototypes */
167 static void
168 UtPadNameWithUnderscores (
169 char *NameSeg,
170 char *PaddedNameSeg);
172 static void
173 UtAttachNameseg (
174 ACPI_PARSE_OBJECT *Op,
175 char *Name);
177 static void
178 UtReallocLineBuffers (
179 char **Buffer,
180 UINT32 OldSize,
181 UINT32 NewSize);
184 /*******************************************************************************
186 * FUNCTION: UtIsBigEndianMachine
188 * PARAMETERS: None
190 * RETURN: TRUE if machine is big endian
191 * FALSE if machine is little endian
193 * DESCRIPTION: Detect whether machine is little endian or big endian.
195 ******************************************************************************/
197 UINT8
198 UtIsBigEndianMachine (
199 void)
201 union {
202 UINT32 Integer;
203 UINT8 Bytes[4];
204 } Overlay = {0xFF000000};
207 return (Overlay.Bytes[0]); /* Returns 0xFF (TRUE) for big endian */
211 /******************************************************************************
213 * FUNCTION: UtQueryForOverwrite
215 * PARAMETERS: Pathname - Output filename
217 * RETURN: TRUE if file does not exist or overwrite is authorized
219 * DESCRIPTION: Query for file overwrite if it already exists.
221 ******************************************************************************/
223 BOOLEAN
224 UtQueryForOverwrite (
225 char *Pathname)
227 struct stat StatInfo;
230 if (!stat (Pathname, &StatInfo))
232 fprintf (stderr, "Target file \"%s\" already exists, overwrite? [y|n] ",
233 Pathname);
235 if (getchar () != 'y')
237 return (FALSE);
241 return (TRUE);
245 /*******************************************************************************
247 * FUNCTION: UtDisplaySupportedTables
249 * PARAMETERS: None
251 * RETURN: None
253 * DESCRIPTION: Print all supported ACPI table names.
255 ******************************************************************************/
257 void
258 UtDisplaySupportedTables (
259 void)
261 const AH_TABLE *TableData;
262 UINT32 i;
265 printf ("\nACPI tables supported by iASL version %8.8X:\n"
266 " (Compiler, Disassembler, Template Generator)\n\n",
267 ACPI_CA_VERSION);
269 /* All ACPI tables with the common table header */
271 printf ("\n Supported ACPI tables:\n");
272 for (TableData = Gbl_AcpiSupportedTables, i = 1;
273 TableData->Signature; TableData++, i++)
275 printf ("%8u) %s %s\n", i,
276 TableData->Signature, TableData->Description);
281 /*******************************************************************************
283 * FUNCTION: UtDisplayConstantOpcodes
285 * PARAMETERS: None
287 * RETURN: None
289 * DESCRIPTION: Print AML opcodes that can be used in constant expressions.
291 ******************************************************************************/
293 void
294 UtDisplayConstantOpcodes (
295 void)
297 UINT32 i;
300 printf ("Constant expression opcode information\n\n");
302 for (i = 0; i < sizeof (AcpiGbl_AmlOpInfo) / sizeof (ACPI_OPCODE_INFO); i++)
304 if (AcpiGbl_AmlOpInfo[i].Flags & AML_CONSTANT)
306 printf ("%s\n", AcpiGbl_AmlOpInfo[i].Name);
312 /*******************************************************************************
314 * FUNCTION: UtLocalCalloc
316 * PARAMETERS: Size - Bytes to be allocated
318 * RETURN: Pointer to the allocated memory. Guaranteed to be valid.
320 * DESCRIPTION: Allocate zero-initialized memory. Aborts the compile on an
321 * allocation failure, on the assumption that nothing more can be
322 * accomplished.
324 ******************************************************************************/
326 void *
327 UtLocalCalloc (
328 UINT32 Size)
330 void *Allocated;
333 Allocated = ACPI_ALLOCATE_ZEROED (Size);
334 if (!Allocated)
336 AslCommonError (ASL_ERROR, ASL_MSG_MEMORY_ALLOCATION,
337 Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
338 Gbl_InputByteCount, Gbl_CurrentColumn,
339 Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
341 CmCleanupAndExit ();
342 exit (1);
345 TotalAllocations++;
346 TotalAllocated += Size;
347 return (Allocated);
351 /*******************************************************************************
353 * FUNCTION: UtBeginEvent
355 * PARAMETERS: Name - Ascii name of this event
357 * RETURN: Event number (integer index)
359 * DESCRIPTION: Saves the current time with this event
361 ******************************************************************************/
363 UINT8
364 UtBeginEvent (
365 char *Name)
368 if (AslGbl_NextEvent >= ASL_NUM_EVENTS)
370 AcpiOsPrintf ("Ran out of compiler event structs!\n");
371 return (AslGbl_NextEvent);
374 /* Init event with current (start) time */
376 AslGbl_Events[AslGbl_NextEvent].StartTime = AcpiOsGetTimer ();
377 AslGbl_Events[AslGbl_NextEvent].EventName = Name;
378 AslGbl_Events[AslGbl_NextEvent].Valid = TRUE;
379 return (AslGbl_NextEvent++);
383 /*******************************************************************************
385 * FUNCTION: UtEndEvent
387 * PARAMETERS: Event - Event number (integer index)
389 * RETURN: None
391 * DESCRIPTION: Saves the current time (end time) with this event
393 ******************************************************************************/
395 void
396 UtEndEvent (
397 UINT8 Event)
400 if (Event >= ASL_NUM_EVENTS)
402 return;
405 /* Insert end time for event */
407 AslGbl_Events[Event].EndTime = AcpiOsGetTimer ();
411 /*******************************************************************************
413 * FUNCTION: DbgPrint
415 * PARAMETERS: Type - Type of output
416 * Fmt - Printf format string
417 * ... - variable printf list
419 * RETURN: None
421 * DESCRIPTION: Conditional print statement. Prints to stderr only if the
422 * debug flag is set.
424 ******************************************************************************/
426 void
427 DbgPrint (
428 UINT32 Type,
429 char *Fmt,
430 ...)
432 va_list Args;
435 if (!Gbl_DebugFlag)
437 return;
440 if ((Type == ASL_PARSE_OUTPUT) &&
441 (!(AslCompilerdebug)))
443 return;
446 va_start (Args, Fmt);
447 (void) vfprintf (stderr, Fmt, Args);
448 va_end (Args);
449 return;
453 /*******************************************************************************
455 * FUNCTION: UtSetParseOpName
457 * PARAMETERS: Op - Parse op to be named.
459 * RETURN: None
461 * DESCRIPTION: Insert the ascii name of the parse opcode
463 ******************************************************************************/
465 void
466 UtSetParseOpName (
467 ACPI_PARSE_OBJECT *Op)
470 strncpy (Op->Asl.ParseOpName, UtGetOpName (Op->Asl.ParseOpcode),
471 ACPI_MAX_PARSEOP_NAME);
475 /*******************************************************************************
477 * FUNCTION: UtDisplaySummary
479 * PARAMETERS: FileID - ID of outpout file
481 * RETURN: None
483 * DESCRIPTION: Display compilation statistics
485 ******************************************************************************/
487 void
488 UtDisplaySummary (
489 UINT32 FileId)
491 UINT32 i;
494 if (FileId != ASL_FILE_STDOUT)
496 /* Compiler name and version number */
498 FlPrintFile (FileId, "%s version %X [%s]\n\n",
499 ASL_COMPILER_NAME, (UINT32) ACPI_CA_VERSION, __DATE__);
502 /* Summary of main input and output files */
504 if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA)
506 FlPrintFile (FileId,
507 "%-14s %s - %u lines, %u bytes, %u fields\n",
508 "Table Input:",
509 Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_CurrentLineNumber,
510 Gbl_InputByteCount, Gbl_InputFieldCount);
512 if ((Gbl_ExceptionCount[ASL_ERROR] == 0) || (Gbl_IgnoreErrors))
514 FlPrintFile (FileId,
515 "%-14s %s - %u bytes\n",
516 "Binary Output:",
517 Gbl_Files[ASL_FILE_AML_OUTPUT].Filename, Gbl_TableLength);
520 else
522 FlPrintFile (FileId,
523 "%-14s %s - %u lines, %u bytes, %u keywords\n",
524 "ASL Input:",
525 Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_CurrentLineNumber,
526 Gbl_OriginalInputFileSize, TotalKeywords);
528 /* AML summary */
530 if ((Gbl_ExceptionCount[ASL_ERROR] == 0) || (Gbl_IgnoreErrors))
532 if (Gbl_Files[ASL_FILE_AML_OUTPUT].Handle)
534 FlPrintFile (FileId,
535 "%-14s %s - %u bytes, %u named objects, "
536 "%u executable opcodes\n",
537 "AML Output:",
538 Gbl_Files[ASL_FILE_AML_OUTPUT].Filename,
539 FlGetFileSize (ASL_FILE_AML_OUTPUT),
540 TotalNamedObjects, TotalExecutableOpcodes);
545 /* Display summary of any optional files */
547 for (i = ASL_FILE_SOURCE_OUTPUT; i <= ASL_MAX_FILE_TYPE; i++)
549 if (!Gbl_Files[i].Filename || !Gbl_Files[i].Handle)
551 continue;
554 /* .SRC is a temp file unless specifically requested */
556 if ((i == ASL_FILE_SOURCE_OUTPUT) && (!Gbl_SourceOutputFlag))
558 continue;
561 /* .PRE is the preprocessor intermediate file */
563 if ((i == ASL_FILE_PREPROCESSOR) && (!Gbl_KeepPreprocessorTempFile))
565 continue;
568 FlPrintFile (FileId, "%14s %s - %u bytes\n",
569 Gbl_Files[i].ShortDescription,
570 Gbl_Files[i].Filename, FlGetFileSize (i));
573 /* Error summary */
575 FlPrintFile (FileId,
576 "\nCompilation complete. %u Errors, %u Warnings, %u Remarks",
577 Gbl_ExceptionCount[ASL_ERROR],
578 Gbl_ExceptionCount[ASL_WARNING] +
579 Gbl_ExceptionCount[ASL_WARNING2] +
580 Gbl_ExceptionCount[ASL_WARNING3],
581 Gbl_ExceptionCount[ASL_REMARK]);
583 if (Gbl_FileType != ASL_INPUT_TYPE_ASCII_DATA)
585 FlPrintFile (FileId, ", %u Optimizations",
586 Gbl_ExceptionCount[ASL_OPTIMIZATION]);
588 if (TotalFolds)
590 FlPrintFile (FileId, ", %u Constants Folded", TotalFolds);
594 FlPrintFile (FileId, "\n");
598 /*******************************************************************************
600 * FUNCTION: UtCheckIntegerRange
602 * PARAMETERS: Op - Integer parse node
603 * LowValue - Smallest allowed value
604 * HighValue - Largest allowed value
606 * RETURN: Op if OK, otherwise NULL
608 * DESCRIPTION: Check integer for an allowable range
610 ******************************************************************************/
612 ACPI_PARSE_OBJECT *
613 UtCheckIntegerRange (
614 ACPI_PARSE_OBJECT *Op,
615 UINT32 LowValue,
616 UINT32 HighValue)
619 if (!Op)
621 return (NULL);
624 if ((Op->Asl.Value.Integer < LowValue) ||
625 (Op->Asl.Value.Integer > HighValue))
627 sprintf (MsgBuffer, "0x%X, allowable: 0x%X-0x%X",
628 (UINT32) Op->Asl.Value.Integer, LowValue, HighValue);
630 AslError (ASL_ERROR, ASL_MSG_RANGE, Op, MsgBuffer);
631 return (NULL);
634 return (Op);
638 /*******************************************************************************
640 * FUNCTION: UtStringCacheCalloc
642 * PARAMETERS: Length - Size of buffer requested
644 * RETURN: Pointer to the buffer. Aborts compiler on allocation failure
646 * DESCRIPTION: Allocate a string buffer. Bypass the local
647 * dynamic memory manager for performance reasons (This has a
648 * major impact on the speed of the compiler.)
650 ******************************************************************************/
652 char *
653 UtStringCacheCalloc (
654 UINT32 Length)
656 char *Buffer;
657 ASL_CACHE_INFO *Cache;
658 UINT32 CacheSize = ASL_STRING_CACHE_SIZE;
661 if (Length > CacheSize)
663 CacheSize = Length;
665 if (Gbl_StringCacheList)
667 Cache = UtLocalCalloc (sizeof (Cache->Next) + CacheSize);
669 /* Link new cache buffer just following head of list */
671 Cache->Next = Gbl_StringCacheList->Next;
672 Gbl_StringCacheList->Next = Cache;
674 /* Leave cache management pointers alone as they pertain to head */
676 Gbl_StringCount++;
677 Gbl_StringSize += Length;
679 return (Cache->Buffer);
683 if ((Gbl_StringCacheNext + Length) >= Gbl_StringCacheLast)
685 /* Allocate a new buffer */
687 Cache = UtLocalCalloc (sizeof (Cache->Next) + CacheSize);
689 /* Link new cache buffer to head of list */
691 Cache->Next = Gbl_StringCacheList;
692 Gbl_StringCacheList = Cache;
694 /* Setup cache management pointers */
696 Gbl_StringCacheNext = Cache->Buffer;
697 Gbl_StringCacheLast = Gbl_StringCacheNext + CacheSize;
700 Gbl_StringCount++;
701 Gbl_StringSize += Length;
703 Buffer = Gbl_StringCacheNext;
704 Gbl_StringCacheNext += Length;
705 return (Buffer);
709 /******************************************************************************
711 * FUNCTION: UtExpandLineBuffers
713 * PARAMETERS: None. Updates global line buffer pointers.
715 * RETURN: None. Reallocates the global line buffers
717 * DESCRIPTION: Called if the current line buffer becomes filled. Reallocates
718 * all global line buffers and updates Gbl_LineBufferSize. NOTE:
719 * Also used for the initial allocation of the buffers, when
720 * all of the buffer pointers are NULL. Initial allocations are
721 * of size ASL_DEFAULT_LINE_BUFFER_SIZE
723 *****************************************************************************/
725 void
726 UtExpandLineBuffers (
727 void)
729 UINT32 NewSize;
732 /* Attempt to double the size of all line buffers */
734 NewSize = Gbl_LineBufferSize * 2;
735 if (Gbl_CurrentLineBuffer)
737 DbgPrint (ASL_DEBUG_OUTPUT,
738 "Increasing line buffer size from %u to %u\n",
739 Gbl_LineBufferSize, NewSize);
742 UtReallocLineBuffers (&Gbl_CurrentLineBuffer, Gbl_LineBufferSize, NewSize);
743 UtReallocLineBuffers (&Gbl_MainTokenBuffer, Gbl_LineBufferSize, NewSize);
744 UtReallocLineBuffers (&Gbl_MacroTokenBuffer, Gbl_LineBufferSize, NewSize);
745 UtReallocLineBuffers (&Gbl_ExpressionTokenBuffer, Gbl_LineBufferSize, NewSize);
747 Gbl_LineBufPtr = Gbl_CurrentLineBuffer;
748 Gbl_LineBufferSize = NewSize;
752 /******************************************************************************
754 * FUNCTION: UtReallocLineBuffers
756 * PARAMETERS: Buffer - Buffer to realloc
757 * OldSize - Old size of Buffer
758 * NewSize - New size of Buffer
760 * RETURN: none
762 * DESCRIPTION: Reallocate and initialize Buffer
764 *****************************************************************************/
766 static void
767 UtReallocLineBuffers (
768 char **Buffer,
769 UINT32 OldSize,
770 UINT32 NewSize)
773 *Buffer = realloc (*Buffer, NewSize);
774 if (*Buffer)
776 memset (*Buffer + OldSize, 0, NewSize - OldSize);
777 return;
780 printf ("Could not increase line buffer size from %u to %u\n",
781 OldSize, NewSize);
783 AslError (ASL_ERROR, ASL_MSG_BUFFER_ALLOCATION, NULL, NULL);
784 AslAbort ();
788 /******************************************************************************
790 * FUNCTION: UtFreeLineBuffers
792 * PARAMETERS: None
794 * RETURN: None
796 * DESCRIPTION: Free all line buffers
798 *****************************************************************************/
800 void
801 UtFreeLineBuffers (
802 void)
805 free (Gbl_CurrentLineBuffer);
806 free (Gbl_MainTokenBuffer);
807 free (Gbl_MacroTokenBuffer);
808 free (Gbl_ExpressionTokenBuffer);
812 /*******************************************************************************
814 * FUNCTION: UtInternalizeName
816 * PARAMETERS: ExternalName - Name to convert
817 * ConvertedName - Where the converted name is returned
819 * RETURN: Status
821 * DESCRIPTION: Convert an external (ASL) name to an internal (AML) name
823 ******************************************************************************/
825 ACPI_STATUS
826 UtInternalizeName (
827 char *ExternalName,
828 char **ConvertedName)
830 ACPI_NAMESTRING_INFO Info;
831 ACPI_STATUS Status;
834 if (!ExternalName)
836 return (AE_OK);
839 /* Get the length of the new internal name */
841 Info.ExternalName = ExternalName;
842 AcpiNsGetInternalNameLength (&Info);
844 /* We need a segment to store the internal name */
846 Info.InternalName = UtStringCacheCalloc (Info.Length);
848 /* Build the name */
850 Status = AcpiNsBuildInternalName (&Info);
851 if (ACPI_FAILURE (Status))
853 return (Status);
856 *ConvertedName = Info.InternalName;
857 return (AE_OK);
861 /*******************************************************************************
863 * FUNCTION: UtPadNameWithUnderscores
865 * PARAMETERS: NameSeg - Input nameseg
866 * PaddedNameSeg - Output padded nameseg
868 * RETURN: Padded nameseg.
870 * DESCRIPTION: Pads a NameSeg with underscores if necessary to form a full
871 * ACPI_NAME.
873 ******************************************************************************/
875 static void
876 UtPadNameWithUnderscores (
877 char *NameSeg,
878 char *PaddedNameSeg)
880 UINT32 i;
883 for (i = 0; (i < ACPI_NAME_SIZE); i++)
885 if (*NameSeg)
887 *PaddedNameSeg = *NameSeg;
888 NameSeg++;
890 else
892 *PaddedNameSeg = '_';
895 PaddedNameSeg++;
900 /*******************************************************************************
902 * FUNCTION: UtAttachNameseg
904 * PARAMETERS: Op - Parent parse node
905 * Name - Full ExternalName
907 * RETURN: None; Sets the NameSeg field in parent node
909 * DESCRIPTION: Extract the last nameseg of the ExternalName and store it
910 * in the NameSeg field of the Op.
912 ******************************************************************************/
914 static void
915 UtAttachNameseg (
916 ACPI_PARSE_OBJECT *Op,
917 char *Name)
919 char *NameSeg;
920 char PaddedNameSeg[4];
923 if (!Name)
925 return;
928 /* Look for the last dot in the namepath */
930 NameSeg = strrchr (Name, '.');
931 if (NameSeg)
933 /* Found last dot, we have also found the final nameseg */
935 NameSeg++;
936 UtPadNameWithUnderscores (NameSeg, PaddedNameSeg);
938 else
940 /* No dots in the namepath, there is only a single nameseg. */
941 /* Handle prefixes */
943 while (ACPI_IS_ROOT_PREFIX (*Name) ||
944 ACPI_IS_PARENT_PREFIX (*Name))
946 Name++;
949 /* Remaining string should be one single nameseg */
951 UtPadNameWithUnderscores (Name, PaddedNameSeg);
954 ACPI_MOVE_NAME (Op->Asl.NameSeg, PaddedNameSeg);
958 /*******************************************************************************
960 * FUNCTION: UtAttachNamepathToOwner
962 * PARAMETERS: Op - Parent parse node
963 * NameOp - Node that contains the name
965 * RETURN: Sets the ExternalName and Namepath in the parent node
967 * DESCRIPTION: Store the name in two forms in the parent node: The original
968 * (external) name, and the internalized name that is used within
969 * the ACPI namespace manager.
971 ******************************************************************************/
973 void
974 UtAttachNamepathToOwner (
975 ACPI_PARSE_OBJECT *Op,
976 ACPI_PARSE_OBJECT *NameOp)
978 ACPI_STATUS Status;
981 /* Full external path */
983 Op->Asl.ExternalName = NameOp->Asl.Value.String;
985 /* Save the NameOp for possible error reporting later */
987 Op->Asl.ParentMethod = (void *) NameOp;
989 /* Last nameseg of the path */
991 UtAttachNameseg (Op, Op->Asl.ExternalName);
993 /* Create internalized path */
995 Status = UtInternalizeName (NameOp->Asl.Value.String, &Op->Asl.Namepath);
996 if (ACPI_FAILURE (Status))
998 /* TBD: abort on no memory */
1003 /*******************************************************************************
1005 * FUNCTION: UtDoConstant
1007 * PARAMETERS: String - Hex/Decimal/Octal
1009 * RETURN: Converted Integer
1011 * DESCRIPTION: Convert a string to an integer, with overflow/error checking.
1013 ******************************************************************************/
1015 UINT64
1016 UtDoConstant (
1017 char *String)
1019 ACPI_STATUS Status;
1020 UINT64 ConvertedInteger;
1021 char ErrBuf[64];
1024 Status = AcpiUtStrtoul64 (String, &ConvertedInteger);
1025 if (ACPI_FAILURE (Status))
1027 sprintf (ErrBuf, "While creating 64-bit constant: %s\n",
1028 AcpiFormatException (Status));
1030 AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, Gbl_CurrentLineNumber,
1031 Gbl_LogicalLineNumber, Gbl_CurrentLineOffset,
1032 Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename, ErrBuf);
1035 return (ConvertedInteger);