1 /******************************************************************************
3 * Module Name: aslutils -- compiler utilities
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2015, Intel Corp.
12 * All rights reserved.
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
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
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
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
72 * 3.4. Intel retains all right, title, and interest in and to the Original
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
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
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 #include "aslcompiler.h"
117 #include "aslcompiler.y.h"
118 #include "acdisasm.h"
119 #include "acnamesp.h"
123 #define _COMPONENT ACPI_COMPILER
124 ACPI_MODULE_NAME ("aslutils")
127 /* Local prototypes */
130 UtPadNameWithUnderscores (
132 char *PaddedNameSeg);
136 ACPI_PARSE_OBJECT *Op,
140 /*******************************************************************************
142 * FUNCTION: UtDisplaySupportedTables
148 * DESCRIPTION: Print all supported ACPI table names.
150 ******************************************************************************/
153 UtDisplaySupportedTables (
156 const AH_TABLE *TableData;
160 printf ("\nACPI tables supported by iASL version %8.8X:\n"
161 " (Compiler, Disassembler, Template Generator)\n\n",
164 /* All ACPI tables with the common table header */
166 printf ("\n Supported ACPI tables:\n");
167 for (TableData = AcpiSupportedTables, i = 1;
168 TableData->Signature; TableData++, i++)
170 printf ("%8u) %s %s\n", i,
171 TableData->Signature, TableData->Description);
176 /*******************************************************************************
178 * FUNCTION: UtDisplayConstantOpcodes
184 * DESCRIPTION: Print AML opcodes that can be used in constant expressions.
186 ******************************************************************************/
189 UtDisplayConstantOpcodes (
195 printf ("Constant expression opcode information\n\n");
197 for (i = 0; i < sizeof (AcpiGbl_AmlOpInfo) / sizeof (ACPI_OPCODE_INFO); i++)
199 if (AcpiGbl_AmlOpInfo[i].Flags & AML_CONSTANT)
201 printf ("%s\n", AcpiGbl_AmlOpInfo[i].Name);
207 /*******************************************************************************
209 * FUNCTION: UtLocalCalloc
211 * PARAMETERS: Size - Bytes to be allocated
213 * RETURN: Pointer to the allocated memory. Guaranteed to be valid.
215 * DESCRIPTION: Allocate zero-initialized memory. Aborts the compile on an
216 * allocation failure, on the assumption that nothing more can be
219 ******************************************************************************/
228 Allocated = ACPI_ALLOCATE_ZEROED (Size);
231 AslCommonError (ASL_ERROR, ASL_MSG_MEMORY_ALLOCATION,
232 Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
233 Gbl_InputByteCount, Gbl_CurrentColumn,
234 Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
241 TotalAllocated += Size;
246 /*******************************************************************************
248 * FUNCTION: UtBeginEvent
250 * PARAMETERS: Name - Ascii name of this event
252 * RETURN: Event number (integer index)
254 * DESCRIPTION: Saves the current time with this event
256 ******************************************************************************/
263 if (AslGbl_NextEvent >= ASL_NUM_EVENTS)
265 AcpiOsPrintf ("Ran out of compiler event structs!\n");
266 return (AslGbl_NextEvent);
269 /* Init event with current (start) time */
271 AslGbl_Events[AslGbl_NextEvent].StartTime = AcpiOsGetTimer ();
272 AslGbl_Events[AslGbl_NextEvent].EventName = Name;
273 AslGbl_Events[AslGbl_NextEvent].Valid = TRUE;
275 return (AslGbl_NextEvent++);
279 /*******************************************************************************
281 * FUNCTION: UtEndEvent
283 * PARAMETERS: Event - Event number (integer index)
287 * DESCRIPTION: Saves the current time (end time) with this event
289 ******************************************************************************/
296 if (Event >= ASL_NUM_EVENTS)
301 /* Insert end time for event */
303 AslGbl_Events[Event].EndTime = AcpiOsGetTimer ();
307 /*******************************************************************************
309 * FUNCTION: UtConvertByteToHex
311 * PARAMETERS: RawByte - Binary data
312 * Buffer - Pointer to where the hex bytes will be
315 * RETURN: Ascii hex byte is stored in Buffer.
317 * DESCRIPTION: Perform hex-to-ascii translation. The return data is prefixed
320 ******************************************************************************/
331 Buffer[2] = (UINT8) AcpiUtHexToAsciiChar (RawByte, 4);
332 Buffer[3] = (UINT8) AcpiUtHexToAsciiChar (RawByte, 0);
336 /*******************************************************************************
338 * FUNCTION: UtConvertByteToAsmHex
340 * PARAMETERS: RawByte - Binary data
341 * Buffer - Pointer to where the hex bytes will be
344 * RETURN: Ascii hex byte is stored in Buffer.
346 * DESCRIPTION: Perform hex-to-ascii translation. The return data is prefixed
347 * with '0', and a trailing 'h' is added.
349 ******************************************************************************/
352 UtConvertByteToAsmHex (
358 Buffer[1] = (UINT8) AcpiUtHexToAsciiChar (RawByte, 4);
359 Buffer[2] = (UINT8) AcpiUtHexToAsciiChar (RawByte, 0);
364 /*******************************************************************************
368 * PARAMETERS: Type - Type of output
369 * Fmt - Printf format string
370 * ... - variable printf list
374 * DESCRIPTION: Conditional print statement. Prints to stderr only if the
377 ******************************************************************************/
393 if ((Type == ASL_PARSE_OUTPUT) &&
394 (!(AslCompilerdebug)))
399 va_start (Args, Fmt);
400 (void) vfprintf (stderr, Fmt, Args);
406 /*******************************************************************************
408 * FUNCTION: UtPrintFormattedName
410 * PARAMETERS: ParseOpcode - Parser keyword ID
411 * Level - Indentation level
415 * DESCRIPTION: Print the ascii name of the parse opcode.
417 ******************************************************************************/
419 #define TEXT_OFFSET 10
422 UtPrintFormattedName (
429 DbgPrint (ASL_TREE_OUTPUT,
430 "%*s", (3 * Level), " ");
432 DbgPrint (ASL_TREE_OUTPUT,
433 " %-20.20s", UtGetOpName (ParseOpcode));
435 if (Level < TEXT_OFFSET)
437 DbgPrint (ASL_TREE_OUTPUT,
438 "%*s", (TEXT_OFFSET - Level) * 3, " ");
443 /*******************************************************************************
445 * FUNCTION: UtSetParseOpName
447 * PARAMETERS: Op - Parse op to be named.
451 * DESCRIPTION: Insert the ascii name of the parse opcode
453 ******************************************************************************/
457 ACPI_PARSE_OBJECT *Op)
460 strncpy (Op->Asl.ParseOpName, UtGetOpName (Op->Asl.ParseOpcode),
461 ACPI_MAX_PARSEOP_NAME);
465 /*******************************************************************************
467 * FUNCTION: UtDisplaySummary
469 * PARAMETERS: FileID - ID of outpout file
473 * DESCRIPTION: Display compilation statistics
475 ******************************************************************************/
484 if (FileId != ASL_FILE_STDOUT)
486 /* Compiler name and version number */
488 FlPrintFile (FileId, "%s version %X%s [%s]\n\n",
489 ASL_COMPILER_NAME, (UINT32) ACPI_CA_VERSION, ACPI_WIDTH, __DATE__);
492 /* Summary of main input and output files */
494 if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA)
497 "%-14s %s - %u lines, %u bytes, %u fields\n",
499 Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_CurrentLineNumber,
500 Gbl_InputByteCount, Gbl_InputFieldCount);
502 if ((Gbl_ExceptionCount[ASL_ERROR] == 0) || (Gbl_IgnoreErrors))
505 "%-14s %s - %u bytes\n",
507 Gbl_Files[ASL_FILE_AML_OUTPUT].Filename, Gbl_TableLength);
513 "%-14s %s - %u lines, %u bytes, %u keywords\n",
515 Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_CurrentLineNumber,
516 Gbl_InputByteCount, TotalKeywords);
520 if ((Gbl_ExceptionCount[ASL_ERROR] == 0) || (Gbl_IgnoreErrors))
523 "%-14s %s - %u bytes, %u named objects, %u executable opcodes\n",
525 Gbl_Files[ASL_FILE_AML_OUTPUT].Filename, Gbl_TableLength,
526 TotalNamedObjects, TotalExecutableOpcodes);
530 /* Display summary of any optional files */
532 for (i = ASL_FILE_SOURCE_OUTPUT; i <= ASL_MAX_FILE_TYPE; i++)
534 if (!Gbl_Files[i].Filename || !Gbl_Files[i].Handle)
539 /* .SRC is a temp file unless specifically requested */
541 if ((i == ASL_FILE_SOURCE_OUTPUT) && (!Gbl_SourceOutputFlag))
546 /* .I is a temp file unless specifically requested */
548 if ((i == ASL_FILE_PREPROCESSOR) && (!Gbl_PreprocessorOutputFlag))
553 FlPrintFile (FileId, "%14s %s - %u bytes\n",
554 Gbl_Files[i].ShortDescription,
555 Gbl_Files[i].Filename, FlGetFileSize (i));
561 "\nCompilation complete. %u Errors, %u Warnings, %u Remarks",
562 Gbl_ExceptionCount[ASL_ERROR],
563 Gbl_ExceptionCount[ASL_WARNING] +
564 Gbl_ExceptionCount[ASL_WARNING2] +
565 Gbl_ExceptionCount[ASL_WARNING3],
566 Gbl_ExceptionCount[ASL_REMARK]);
568 if (Gbl_FileType != ASL_INPUT_TYPE_ASCII_DATA)
570 FlPrintFile (FileId, ", %u Optimizations",
571 Gbl_ExceptionCount[ASL_OPTIMIZATION]);
575 FlPrintFile (FileId, ", %u Constants Folded", TotalFolds);
579 FlPrintFile (FileId, "\n");
583 /*******************************************************************************
585 * FUNCTION: UtCheckIntegerRange
587 * PARAMETERS: Op - Integer parse node
588 * LowValue - Smallest allowed value
589 * HighValue - Largest allowed value
591 * RETURN: Op if OK, otherwise NULL
593 * DESCRIPTION: Check integer for an allowable range
595 ******************************************************************************/
598 UtCheckIntegerRange (
599 ACPI_PARSE_OBJECT *Op,
609 if ((Op->Asl.Value.Integer < LowValue) ||
610 (Op->Asl.Value.Integer > HighValue))
612 sprintf (MsgBuffer, "0x%X, allowable: 0x%X-0x%X",
613 (UINT32) Op->Asl.Value.Integer, LowValue, HighValue);
615 AslError (ASL_ERROR, ASL_MSG_RANGE, Op, MsgBuffer);
623 /*******************************************************************************
625 * FUNCTION: UtStringCacheCalloc
627 * PARAMETERS: Length - Size of buffer requested
629 * RETURN: Pointer to the buffer. Aborts on allocation failure
631 * DESCRIPTION: Allocate a string buffer. Bypass the local
632 * dynamic memory manager for performance reasons (This has a
633 * major impact on the speed of the compiler.)
635 ******************************************************************************/
638 UtStringCacheCalloc (
642 ASL_CACHE_INFO *Cache;
643 UINT32 CacheSize = ASL_STRING_CACHE_SIZE;
646 if (Length > CacheSize)
650 if (Gbl_StringCacheList)
652 Cache = UtLocalCalloc (sizeof (Cache->Next) + CacheSize);
654 /* Link new cache buffer just following head of list */
656 Cache->Next = Gbl_StringCacheList->Next;
657 Gbl_StringCacheList->Next = Cache;
659 /* Leave cache management pointers alone as they pertain to head */
662 Gbl_StringSize += Length;
664 return (Cache->Buffer);
668 if ((Gbl_StringCacheNext + Length) >= Gbl_StringCacheLast)
670 /* Allocate a new buffer */
672 Cache = UtLocalCalloc (sizeof (Cache->Next) + CacheSize);
674 /* Link new cache buffer to head of list */
676 Cache->Next = Gbl_StringCacheList;
677 Gbl_StringCacheList = Cache;
679 /* Setup cache management pointers */
681 Gbl_StringCacheNext = Cache->Buffer;
682 Gbl_StringCacheLast = Gbl_StringCacheNext + CacheSize;
686 Gbl_StringSize += Length;
688 Buffer = Gbl_StringCacheNext;
689 Gbl_StringCacheNext += Length;
694 /******************************************************************************
696 * FUNCTION: UtExpandLineBuffers
698 * PARAMETERS: None. Updates global line buffer pointers.
700 * RETURN: None. Reallocates the global line buffers
702 * DESCRIPTION: Called if the current line buffer becomes filled. Reallocates
703 * all global line buffers and updates Gbl_LineBufferSize. NOTE:
704 * Also used for the initial allocation of the buffers, when
705 * all of the buffer pointers are NULL. Initial allocations are
706 * of size ASL_DEFAULT_LINE_BUFFER_SIZE
708 *****************************************************************************/
711 UtExpandLineBuffers (
717 /* Attempt to double the size of all line buffers */
719 NewSize = Gbl_LineBufferSize * 2;
720 if (Gbl_CurrentLineBuffer)
722 DbgPrint (ASL_DEBUG_OUTPUT,
723 "Increasing line buffer size from %u to %u\n",
724 Gbl_LineBufferSize, NewSize);
727 Gbl_CurrentLineBuffer = realloc (Gbl_CurrentLineBuffer, NewSize);
728 Gbl_LineBufPtr = Gbl_CurrentLineBuffer;
729 if (!Gbl_CurrentLineBuffer)
734 Gbl_MainTokenBuffer = realloc (Gbl_MainTokenBuffer, NewSize);
735 if (!Gbl_MainTokenBuffer)
740 Gbl_MacroTokenBuffer = realloc (Gbl_MacroTokenBuffer, NewSize);
741 if (!Gbl_MacroTokenBuffer)
746 Gbl_ExpressionTokenBuffer = realloc (Gbl_ExpressionTokenBuffer, NewSize);
747 if (!Gbl_ExpressionTokenBuffer)
752 Gbl_LineBufferSize = NewSize;
756 /* On error above, simply issue error messages and abort, cannot continue */
759 printf ("Could not increase line buffer size from %u to %u\n",
760 Gbl_LineBufferSize, Gbl_LineBufferSize * 2);
762 AslError (ASL_ERROR, ASL_MSG_BUFFER_ALLOCATION,
768 /******************************************************************************
770 * FUNCTION: UtFreeLineBuffers
776 * DESCRIPTION: Free all line buffers
778 *****************************************************************************/
785 free (Gbl_CurrentLineBuffer);
786 free (Gbl_MainTokenBuffer);
787 free (Gbl_MacroTokenBuffer);
788 free (Gbl_ExpressionTokenBuffer);
792 /*******************************************************************************
794 * FUNCTION: UtInternalizeName
796 * PARAMETERS: ExternalName - Name to convert
797 * ConvertedName - Where the converted name is returned
801 * DESCRIPTION: Convert an external (ASL) name to an internal (AML) name
803 ******************************************************************************/
808 char **ConvertedName)
810 ACPI_NAMESTRING_INFO Info;
819 /* Get the length of the new internal name */
821 Info.ExternalName = ExternalName;
822 AcpiNsGetInternalNameLength (&Info);
824 /* We need a segment to store the internal name */
826 Info.InternalName = UtStringCacheCalloc (Info.Length);
827 if (!Info.InternalName)
829 return (AE_NO_MEMORY);
834 Status = AcpiNsBuildInternalName (&Info);
835 if (ACPI_FAILURE (Status))
840 *ConvertedName = Info.InternalName;
845 /*******************************************************************************
847 * FUNCTION: UtPadNameWithUnderscores
849 * PARAMETERS: NameSeg - Input nameseg
850 * PaddedNameSeg - Output padded nameseg
852 * RETURN: Padded nameseg.
854 * DESCRIPTION: Pads a NameSeg with underscores if necessary to form a full
857 ******************************************************************************/
860 UtPadNameWithUnderscores (
867 for (i = 0; (i < ACPI_NAME_SIZE); i++)
871 *PaddedNameSeg = *NameSeg;
876 *PaddedNameSeg = '_';
883 /*******************************************************************************
885 * FUNCTION: UtAttachNameseg
887 * PARAMETERS: Op - Parent parse node
888 * Name - Full ExternalName
890 * RETURN: None; Sets the NameSeg field in parent node
892 * DESCRIPTION: Extract the last nameseg of the ExternalName and store it
893 * in the NameSeg field of the Op.
895 ******************************************************************************/
899 ACPI_PARSE_OBJECT *Op,
903 char PaddedNameSeg[4];
911 /* Look for the last dot in the namepath */
913 NameSeg = strrchr (Name, '.');
916 /* Found last dot, we have also found the final nameseg */
919 UtPadNameWithUnderscores (NameSeg, PaddedNameSeg);
923 /* No dots in the namepath, there is only a single nameseg. */
924 /* Handle prefixes */
926 while (ACPI_IS_ROOT_PREFIX (*Name) ||
927 ACPI_IS_PARENT_PREFIX (*Name))
932 /* Remaining string should be one single nameseg */
934 UtPadNameWithUnderscores (Name, PaddedNameSeg);
937 ACPI_MOVE_NAME (Op->Asl.NameSeg, PaddedNameSeg);
941 /*******************************************************************************
943 * FUNCTION: UtAttachNamepathToOwner
945 * PARAMETERS: Op - Parent parse node
946 * NameOp - Node that contains the name
948 * RETURN: Sets the ExternalName and Namepath in the parent node
950 * DESCRIPTION: Store the name in two forms in the parent node: The original
951 * (external) name, and the internalized name that is used within
952 * the ACPI namespace manager.
954 ******************************************************************************/
957 UtAttachNamepathToOwner (
958 ACPI_PARSE_OBJECT *Op,
959 ACPI_PARSE_OBJECT *NameOp)
964 /* Full external path */
966 Op->Asl.ExternalName = NameOp->Asl.Value.String;
968 /* Save the NameOp for possible error reporting later */
970 Op->Asl.ParentMethod = (void *) NameOp;
972 /* Last nameseg of the path */
974 UtAttachNameseg (Op, Op->Asl.ExternalName);
976 /* Create internalized path */
978 Status = UtInternalizeName (NameOp->Asl.Value.String, &Op->Asl.Namepath);
979 if (ACPI_FAILURE (Status))
981 /* TBD: abort on no memory */
986 /*******************************************************************************
988 * FUNCTION: UtDoConstant
990 * PARAMETERS: String - Hex, Octal, or Decimal string
992 * RETURN: Converted Integer
994 * DESCRIPTION: Convert a string to an integer, with error checking.
996 ******************************************************************************/
1007 Status = UtStrtoul64 (String, 0, &Converted);
1008 if (ACPI_FAILURE (Status))
1010 sprintf (ErrBuf, "%s %s\n", "Conversion error:",
1011 AcpiFormatException (Status));
1012 AslCompilererror (ErrBuf);
1019 /* TBD: use version in ACPICA main code base? */
1021 /*******************************************************************************
1023 * FUNCTION: UtStrtoul64
1025 * PARAMETERS: String - Null terminated string
1026 * Terminater - Where a pointer to the terminating byte
1028 * Base - Radix of the string
1030 * RETURN: Converted value
1032 * DESCRIPTION: Convert a string into an unsigned value.
1034 ******************************************************************************/
1044 UINT64 ReturnValue = 0;
1045 ACPI_STATUS Status = AE_OK;
1061 * The specified Base parameter is not in the domain of
1064 return (AE_BAD_PARAMETER);
1067 /* Skip over any white space in the buffer: */
1069 while (isspace ((int) *String) || *String == '\t')
1075 * The buffer may contain an optional plus or minus sign.
1076 * If it does, then skip over it but remember what is was:
1083 else if (*String == '+')
1094 * If the input parameter Base is zero, then we need to
1095 * determine if it is octal, decimal, or hexadecimal:
1101 if (tolower ((int) *(++String)) == 'x')
1118 * For octal and hexadecimal bases, skip over the leading
1119 * 0 or 0x, if they are present.
1121 if (Base == 8 && *String == '0')
1128 tolower ((int) *(++String)) == 'x')
1133 /* Main loop: convert the string to an unsigned long */
1137 if (isdigit ((int) *String))
1139 Index = ((UINT8) *String) - '0';
1143 Index = (UINT8) toupper ((int) *String);
1144 if (isupper ((int) Index))
1146 Index = Index - 'A' + 10;
1159 /* Check to see if value is out of range: */
1161 if (ReturnValue > ((ACPI_UINT64_MAX - (UINT64) Index) /
1168 ReturnValue *= Base;
1169 ReturnValue += Index;
1176 /* If a minus sign was present, then "the conversion is negated": */
1178 if (Sign == NEGATIVE)
1180 ReturnValue = (ACPI_UINT32_MAX - ReturnValue) + 1;
1183 *RetInteger = ReturnValue;
1192 Status = AE_BAD_OCTAL_CONSTANT;
1197 Status = AE_BAD_DECIMAL_CONSTANT;
1202 Status = AE_BAD_HEX_CONSTANT;
1207 /* Base validated above */