utstrtoul64.c revision 1.1.1.3.2.2 1 1.1.1.3.2.2 jdolecek /*******************************************************************************
2 1.1.1.3.2.2 jdolecek *
3 1.1.1.3.2.2 jdolecek * Module Name: utstrtoul64 - String-to-integer conversion support for both
4 1.1.1.3.2.2 jdolecek * 64-bit and 32-bit integers
5 1.1.1.3.2.2 jdolecek *
6 1.1.1.3.2.2 jdolecek ******************************************************************************/
7 1.1.1.3.2.2 jdolecek
8 1.1.1.3.2.2 jdolecek /*
9 1.1.1.3.2.2 jdolecek * Copyright (C) 2000 - 2017, Intel Corp.
10 1.1.1.3.2.2 jdolecek * All rights reserved.
11 1.1.1.3.2.2 jdolecek *
12 1.1.1.3.2.2 jdolecek * Redistribution and use in source and binary forms, with or without
13 1.1.1.3.2.2 jdolecek * modification, are permitted provided that the following conditions
14 1.1.1.3.2.2 jdolecek * are met:
15 1.1.1.3.2.2 jdolecek * 1. Redistributions of source code must retain the above copyright
16 1.1.1.3.2.2 jdolecek * notice, this list of conditions, and the following disclaimer,
17 1.1.1.3.2.2 jdolecek * without modification.
18 1.1.1.3.2.2 jdolecek * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 1.1.1.3.2.2 jdolecek * substantially similar to the "NO WARRANTY" disclaimer below
20 1.1.1.3.2.2 jdolecek * ("Disclaimer") and any redistribution must be conditioned upon
21 1.1.1.3.2.2 jdolecek * including a substantially similar Disclaimer requirement for further
22 1.1.1.3.2.2 jdolecek * binary redistribution.
23 1.1.1.3.2.2 jdolecek * 3. Neither the names of the above-listed copyright holders nor the names
24 1.1.1.3.2.2 jdolecek * of any contributors may be used to endorse or promote products derived
25 1.1.1.3.2.2 jdolecek * from this software without specific prior written permission.
26 1.1.1.3.2.2 jdolecek *
27 1.1.1.3.2.2 jdolecek * Alternatively, this software may be distributed under the terms of the
28 1.1.1.3.2.2 jdolecek * GNU General Public License ("GPL") version 2 as published by the Free
29 1.1.1.3.2.2 jdolecek * Software Foundation.
30 1.1.1.3.2.2 jdolecek *
31 1.1.1.3.2.2 jdolecek * NO WARRANTY
32 1.1.1.3.2.2 jdolecek * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 1.1.1.3.2.2 jdolecek * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 1.1.1.3.2.2 jdolecek * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 1.1.1.3.2.2 jdolecek * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 1.1.1.3.2.2 jdolecek * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1.1.3.2.2 jdolecek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1.1.3.2.2 jdolecek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1.1.3.2.2 jdolecek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 1.1.1.3.2.2 jdolecek * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 1.1.1.3.2.2 jdolecek * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 1.1.1.3.2.2 jdolecek * POSSIBILITY OF SUCH DAMAGES.
43 1.1.1.3.2.2 jdolecek */
44 1.1.1.3.2.2 jdolecek
45 1.1.1.3.2.2 jdolecek #include "acpi.h"
46 1.1.1.3.2.2 jdolecek #include "accommon.h"
47 1.1.1.3.2.2 jdolecek
48 1.1.1.3.2.2 jdolecek #define _COMPONENT ACPI_UTILITIES
49 1.1.1.3.2.2 jdolecek ACPI_MODULE_NAME ("utstrtoul64")
50 1.1.1.3.2.2 jdolecek
51 1.1.1.3.2.2 jdolecek
52 1.1.1.3.2.2 jdolecek /*******************************************************************************
53 1.1.1.3.2.2 jdolecek *
54 1.1.1.3.2.2 jdolecek * This module contains the top-level string to 64/32-bit unsigned integer
55 1.1.1.3.2.2 jdolecek * conversion functions:
56 1.1.1.3.2.2 jdolecek *
57 1.1.1.3.2.2 jdolecek * 1) A standard strtoul() function that supports 64-bit integers, base
58 1.1.1.3.2.2 jdolecek * 8/10/16, with integer overflow support. This is used mainly by the
59 1.1.1.3.2.2 jdolecek * iASL compiler, which implements tighter constraints on integer
60 1.1.1.3.2.2 jdolecek * constants than the runtime (interpreter) integer-to-string conversions.
61 1.1.1.3.2.2 jdolecek * 2) Runtime "Explicit conversion" as defined in the ACPI specification.
62 1.1.1.3.2.2 jdolecek * 3) Runtime "Implicit conversion" as defined in the ACPI specification.
63 1.1.1.3.2.2 jdolecek *
64 1.1.1.3.2.2 jdolecek * Current users of this module:
65 1.1.1.3.2.2 jdolecek *
66 1.1.1.3.2.2 jdolecek * iASL - Preprocessor (constants and math expressions)
67 1.1.1.3.2.2 jdolecek * iASL - Main parser, conversion of constants to integers
68 1.1.1.3.2.2 jdolecek * iASL - Data Table Compiler parser (constants and math expressions)
69 1.1.1.3.2.2 jdolecek * Interpreter - Implicit and explicit conversions, GPE method names
70 1.1.1.3.2.2 jdolecek * Interpreter - Repair code for return values from predefined names
71 1.1.1.3.2.2 jdolecek * Debugger - Command line input string conversion
72 1.1.1.3.2.2 jdolecek * AcpiDump - ACPI table physical addresses
73 1.1.1.3.2.2 jdolecek * AcpiExec - Support for namespace overrides
74 1.1.1.3.2.2 jdolecek *
75 1.1.1.3.2.2 jdolecek * Notes concerning users of these interfaces:
76 1.1.1.3.2.2 jdolecek *
77 1.1.1.3.2.2 jdolecek * AcpiGbl_IntegerByteWidth is used to set the 32/64 bit limit for explicit
78 1.1.1.3.2.2 jdolecek * and implicit conversions. This global must be set to the proper width.
79 1.1.1.3.2.2 jdolecek * For the core ACPICA code, the width depends on the DSDT version. For the
80 1.1.1.3.2.2 jdolecek * AcpiUtStrtoul64 interface, all conversions are 64 bits. This interface is
81 1.1.1.3.2.2 jdolecek * used primarily for iASL, where the default width is 64 bits for all parsers,
82 1.1.1.3.2.2 jdolecek * but error checking is performed later to flag cases where a 64-bit constant
83 1.1.1.3.2.2 jdolecek * is wrongly defined in a 32-bit DSDT/SSDT.
84 1.1.1.3.2.2 jdolecek *
85 1.1.1.3.2.2 jdolecek * In ACPI, the only place where octal numbers are supported is within
86 1.1.1.3.2.2 jdolecek * the ASL language itself. This is implemented via the main AcpiUtStrtoul64
87 1.1.1.3.2.2 jdolecek * interface. According the ACPI specification, there is no ACPI runtime
88 1.1.1.3.2.2 jdolecek * support (explicit/implicit) for octal string conversions.
89 1.1.1.3.2.2 jdolecek *
90 1.1.1.3.2.2 jdolecek ******************************************************************************/
91 1.1.1.3.2.2 jdolecek
92 1.1.1.3.2.2 jdolecek
93 1.1.1.3.2.2 jdolecek /*******************************************************************************
94 1.1.1.3.2.2 jdolecek *
95 1.1.1.3.2.2 jdolecek * FUNCTION: AcpiUtStrtoul64
96 1.1.1.3.2.2 jdolecek *
97 1.1.1.3.2.2 jdolecek * PARAMETERS: String - Null terminated input string,
98 1.1.1.3.2.2 jdolecek * must be a valid pointer
99 1.1.1.3.2.2 jdolecek * ReturnValue - Where the converted integer is
100 1.1.1.3.2.2 jdolecek * returned. Must be a valid pointer
101 1.1.1.3.2.2 jdolecek *
102 1.1.1.3.2.2 jdolecek * RETURN: Status and converted integer. Returns an exception on a
103 1.1.1.3.2.2 jdolecek * 64-bit numeric overflow
104 1.1.1.3.2.2 jdolecek *
105 1.1.1.3.2.2 jdolecek * DESCRIPTION: Convert a string into an unsigned integer. Always performs a
106 1.1.1.3.2.2 jdolecek * full 64-bit conversion, regardless of the current global
107 1.1.1.3.2.2 jdolecek * integer width. Supports Decimal, Hex, and Octal strings.
108 1.1.1.3.2.2 jdolecek *
109 1.1.1.3.2.2 jdolecek * Current users of this function:
110 1.1.1.3.2.2 jdolecek *
111 1.1.1.3.2.2 jdolecek * iASL - Preprocessor (constants and math expressions)
112 1.1.1.3.2.2 jdolecek * iASL - Main ASL parser, conversion of ASL constants to integers
113 1.1.1.3.2.2 jdolecek * iASL - Data Table Compiler parser (constants and math expressions)
114 1.1.1.3.2.2 jdolecek * Interpreter - Repair code for return values from predefined names
115 1.1.1.3.2.2 jdolecek * AcpiDump - ACPI table physical addresses
116 1.1.1.3.2.2 jdolecek * AcpiExec - Support for namespace overrides
117 1.1.1.3.2.2 jdolecek *
118 1.1.1.3.2.2 jdolecek ******************************************************************************/
119 1.1.1.3.2.2 jdolecek
120 1.1.1.3.2.2 jdolecek ACPI_STATUS
121 1.1.1.3.2.2 jdolecek AcpiUtStrtoul64 (
122 1.1.1.3.2.2 jdolecek char *String,
123 1.1.1.3.2.2 jdolecek UINT64 *ReturnValue)
124 1.1.1.3.2.2 jdolecek {
125 1.1.1.3.2.2 jdolecek ACPI_STATUS Status = AE_OK;
126 1.1.1.3.2.2 jdolecek UINT8 OriginalBitWidth;
127 1.1.1.3.2.2 jdolecek UINT32 Base = 10; /* Default is decimal */
128 1.1.1.3.2.2 jdolecek
129 1.1.1.3.2.2 jdolecek
130 1.1.1.3.2.2 jdolecek ACPI_FUNCTION_TRACE_STR (UtStrtoul64, String);
131 1.1.1.3.2.2 jdolecek
132 1.1.1.3.2.2 jdolecek
133 1.1.1.3.2.2 jdolecek *ReturnValue = 0;
134 1.1.1.3.2.2 jdolecek
135 1.1.1.3.2.2 jdolecek /* A NULL return string returns a value of zero */
136 1.1.1.3.2.2 jdolecek
137 1.1.1.3.2.2 jdolecek if (*String == 0)
138 1.1.1.3.2.2 jdolecek {
139 1.1.1.3.2.2 jdolecek return_ACPI_STATUS (AE_OK);
140 1.1.1.3.2.2 jdolecek }
141 1.1.1.3.2.2 jdolecek
142 1.1.1.3.2.2 jdolecek if (!AcpiUtRemoveWhitespace (&String))
143 1.1.1.3.2.2 jdolecek {
144 1.1.1.3.2.2 jdolecek return_ACPI_STATUS (AE_OK);
145 1.1.1.3.2.2 jdolecek }
146 1.1.1.3.2.2 jdolecek
147 1.1.1.3.2.2 jdolecek /*
148 1.1.1.3.2.2 jdolecek * 1) Check for a hex constant. A "0x" prefix indicates base 16.
149 1.1.1.3.2.2 jdolecek */
150 1.1.1.3.2.2 jdolecek if (AcpiUtDetectHexPrefix (&String))
151 1.1.1.3.2.2 jdolecek {
152 1.1.1.3.2.2 jdolecek Base = 16;
153 1.1.1.3.2.2 jdolecek }
154 1.1.1.3.2.2 jdolecek
155 1.1.1.3.2.2 jdolecek /*
156 1.1.1.3.2.2 jdolecek * 2) Check for an octal constant, defined to be a leading zero
157 1.1.1.3.2.2 jdolecek * followed by sequence of octal digits (0-7)
158 1.1.1.3.2.2 jdolecek */
159 1.1.1.3.2.2 jdolecek else if (AcpiUtDetectOctalPrefix (&String))
160 1.1.1.3.2.2 jdolecek {
161 1.1.1.3.2.2 jdolecek Base = 8;
162 1.1.1.3.2.2 jdolecek }
163 1.1.1.3.2.2 jdolecek
164 1.1.1.3.2.2 jdolecek if (!AcpiUtRemoveLeadingZeros (&String))
165 1.1.1.3.2.2 jdolecek {
166 1.1.1.3.2.2 jdolecek return_ACPI_STATUS (AE_OK); /* Return value 0 */
167 1.1.1.3.2.2 jdolecek }
168 1.1.1.3.2.2 jdolecek
169 1.1.1.3.2.2 jdolecek /*
170 1.1.1.3.2.2 jdolecek * Force a full 64-bit conversion. The caller (usually iASL) must
171 1.1.1.3.2.2 jdolecek * check for a 32-bit overflow later as necessary (If current mode
172 1.1.1.3.2.2 jdolecek * is 32-bit, meaning a 32-bit DSDT).
173 1.1.1.3.2.2 jdolecek */
174 1.1.1.3.2.2 jdolecek OriginalBitWidth = AcpiGbl_IntegerBitWidth;
175 1.1.1.3.2.2 jdolecek AcpiGbl_IntegerBitWidth = 64;
176 1.1.1.3.2.2 jdolecek
177 1.1.1.3.2.2 jdolecek /*
178 1.1.1.3.2.2 jdolecek * Perform the base 8, 10, or 16 conversion. A 64-bit numeric overflow
179 1.1.1.3.2.2 jdolecek * will return an exception (to allow iASL to flag the statement).
180 1.1.1.3.2.2 jdolecek */
181 1.1.1.3.2.2 jdolecek switch (Base)
182 1.1.1.3.2.2 jdolecek {
183 1.1.1.3.2.2 jdolecek case 8:
184 1.1.1.3.2.2 jdolecek Status = AcpiUtConvertOctalString (String, ReturnValue);
185 1.1.1.3.2.2 jdolecek break;
186 1.1.1.3.2.2 jdolecek
187 1.1.1.3.2.2 jdolecek case 10:
188 1.1.1.3.2.2 jdolecek Status = AcpiUtConvertDecimalString (String, ReturnValue);
189 1.1.1.3.2.2 jdolecek break;
190 1.1.1.3.2.2 jdolecek
191 1.1.1.3.2.2 jdolecek case 16:
192 1.1.1.3.2.2 jdolecek default:
193 1.1.1.3.2.2 jdolecek Status = AcpiUtConvertHexString (String, ReturnValue);
194 1.1.1.3.2.2 jdolecek break;
195 1.1.1.3.2.2 jdolecek }
196 1.1.1.3.2.2 jdolecek
197 1.1.1.3.2.2 jdolecek /* Only possible exception from above is a 64-bit overflow */
198 1.1.1.3.2.2 jdolecek
199 1.1.1.3.2.2 jdolecek AcpiGbl_IntegerBitWidth = OriginalBitWidth;
200 1.1.1.3.2.2 jdolecek return_ACPI_STATUS (Status);
201 1.1.1.3.2.2 jdolecek }
202 1.1.1.3.2.2 jdolecek
203 1.1.1.3.2.2 jdolecek
204 1.1.1.3.2.2 jdolecek /*******************************************************************************
205 1.1.1.3.2.2 jdolecek *
206 1.1.1.3.2.2 jdolecek * FUNCTION: AcpiUtImplicitStrtoul64
207 1.1.1.3.2.2 jdolecek *
208 1.1.1.3.2.2 jdolecek * PARAMETERS: String - Null terminated input string,
209 1.1.1.3.2.2 jdolecek * must be a valid pointer
210 1.1.1.3.2.2 jdolecek *
211 1.1.1.3.2.2 jdolecek * RETURN: Converted integer
212 1.1.1.3.2.2 jdolecek *
213 1.1.1.3.2.2 jdolecek * DESCRIPTION: Perform a 64-bit conversion with restrictions placed upon
214 1.1.1.3.2.2 jdolecek * an "implicit conversion" by the ACPI specification. Used by
215 1.1.1.3.2.2 jdolecek * many ASL operators that require an integer operand, and support
216 1.1.1.3.2.2 jdolecek * an automatic (implicit) conversion from a string operand
217 1.1.1.3.2.2 jdolecek * to the final integer operand. The major restriction is that
218 1.1.1.3.2.2 jdolecek * only hex strings are supported.
219 1.1.1.3.2.2 jdolecek *
220 1.1.1.3.2.2 jdolecek * -----------------------------------------------------------------------------
221 1.1.1.3.2.2 jdolecek *
222 1.1.1.3.2.2 jdolecek * Base is always 16, either with or without the 0x prefix. Decimal and
223 1.1.1.3.2.2 jdolecek * Octal strings are not supported, as per the ACPI specification.
224 1.1.1.3.2.2 jdolecek *
225 1.1.1.3.2.2 jdolecek * Examples (both are hex values):
226 1.1.1.3.2.2 jdolecek * Add ("BA98", Arg0, Local0)
227 1.1.1.3.2.2 jdolecek * Subtract ("0x12345678", Arg1, Local1)
228 1.1.1.3.2.2 jdolecek *
229 1.1.1.3.2.2 jdolecek * Conversion rules as extracted from the ACPI specification:
230 1.1.1.3.2.2 jdolecek *
231 1.1.1.3.2.2 jdolecek * The converted integer is initialized to the value zero.
232 1.1.1.3.2.2 jdolecek * The ASCII string is always interpreted as a hexadecimal constant.
233 1.1.1.3.2.2 jdolecek *
234 1.1.1.3.2.2 jdolecek * 1) According to the ACPI specification, a "0x" prefix is not allowed.
235 1.1.1.3.2.2 jdolecek * However, ACPICA allows this as an ACPI extension on general
236 1.1.1.3.2.2 jdolecek * principle. (NO ERROR)
237 1.1.1.3.2.2 jdolecek *
238 1.1.1.3.2.2 jdolecek * 2) The conversion terminates when the size of an integer is reached
239 1.1.1.3.2.2 jdolecek * (32 or 64 bits). There are no numeric overflow conditions. (NO ERROR)
240 1.1.1.3.2.2 jdolecek *
241 1.1.1.3.2.2 jdolecek * 3) The first non-hex character terminates the conversion and returns
242 1.1.1.3.2.2 jdolecek * the current accumulated value of the converted integer (NO ERROR).
243 1.1.1.3.2.2 jdolecek *
244 1.1.1.3.2.2 jdolecek * 4) Conversion of a null (zero-length) string to an integer is
245 1.1.1.3.2.2 jdolecek * technically not allowed. However, ACPICA allows this as an ACPI
246 1.1.1.3.2.2 jdolecek * extension. The conversion returns the value 0. (NO ERROR)
247 1.1.1.3.2.2 jdolecek *
248 1.1.1.3.2.2 jdolecek * NOTE: There are no error conditions returned by this function. At
249 1.1.1.3.2.2 jdolecek * the minimum, a value of zero is returned.
250 1.1.1.3.2.2 jdolecek *
251 1.1.1.3.2.2 jdolecek * Current users of this function:
252 1.1.1.3.2.2 jdolecek *
253 1.1.1.3.2.2 jdolecek * Interpreter - All runtime implicit conversions, as per ACPI specification
254 1.1.1.3.2.2 jdolecek * iASL - Data Table Compiler parser (constants and math expressions)
255 1.1.1.3.2.2 jdolecek *
256 1.1.1.3.2.2 jdolecek ******************************************************************************/
257 1.1.1.3.2.2 jdolecek
258 1.1.1.3.2.2 jdolecek UINT64
259 1.1.1.3.2.2 jdolecek AcpiUtImplicitStrtoul64 (
260 1.1.1.3.2.2 jdolecek char *String)
261 1.1.1.3.2.2 jdolecek {
262 1.1.1.3.2.2 jdolecek UINT64 ConvertedInteger = 0;
263 1.1.1.3.2.2 jdolecek
264 1.1.1.3.2.2 jdolecek
265 1.1.1.3.2.2 jdolecek ACPI_FUNCTION_TRACE_STR (UtImplicitStrtoul64, String);
266 1.1.1.3.2.2 jdolecek
267 1.1.1.3.2.2 jdolecek
268 1.1.1.3.2.2 jdolecek if (!AcpiUtRemoveWhitespace (&String))
269 1.1.1.3.2.2 jdolecek {
270 1.1.1.3.2.2 jdolecek return_VALUE (0);
271 1.1.1.3.2.2 jdolecek }
272 1.1.1.3.2.2 jdolecek
273 1.1.1.3.2.2 jdolecek /*
274 1.1.1.3.2.2 jdolecek * Per the ACPI specification, only hexadecimal is supported for
275 1.1.1.3.2.2 jdolecek * implicit conversions, and the "0x" prefix is "not allowed".
276 1.1.1.3.2.2 jdolecek * However, allow a "0x" prefix as an ACPI extension.
277 1.1.1.3.2.2 jdolecek */
278 1.1.1.3.2.2 jdolecek AcpiUtDetectHexPrefix (&String);
279 1.1.1.3.2.2 jdolecek
280 1.1.1.3.2.2 jdolecek if (!AcpiUtRemoveLeadingZeros (&String))
281 1.1.1.3.2.2 jdolecek {
282 1.1.1.3.2.2 jdolecek return_VALUE (0);
283 1.1.1.3.2.2 jdolecek }
284 1.1.1.3.2.2 jdolecek
285 1.1.1.3.2.2 jdolecek /*
286 1.1.1.3.2.2 jdolecek * Ignore overflow as per the ACPI specification. This is implemented by
287 1.1.1.3.2.2 jdolecek * ignoring the return status from the conversion function called below.
288 1.1.1.3.2.2 jdolecek * On overflow, the input string is simply truncated.
289 1.1.1.3.2.2 jdolecek */
290 1.1.1.3.2.2 jdolecek AcpiUtConvertHexString (String, &ConvertedInteger);
291 1.1.1.3.2.2 jdolecek return_VALUE (ConvertedInteger);
292 1.1.1.3.2.2 jdolecek }
293 1.1.1.3.2.2 jdolecek
294 1.1.1.3.2.2 jdolecek
295 1.1.1.3.2.2 jdolecek /*******************************************************************************
296 1.1.1.3.2.2 jdolecek *
297 1.1.1.3.2.2 jdolecek * FUNCTION: AcpiUtExplicitStrtoul64
298 1.1.1.3.2.2 jdolecek *
299 1.1.1.3.2.2 jdolecek * PARAMETERS: String - Null terminated input string,
300 1.1.1.3.2.2 jdolecek * must be a valid pointer
301 1.1.1.3.2.2 jdolecek *
302 1.1.1.3.2.2 jdolecek * RETURN: Converted integer
303 1.1.1.3.2.2 jdolecek *
304 1.1.1.3.2.2 jdolecek * DESCRIPTION: Perform a 64-bit conversion with the restrictions placed upon
305 1.1.1.3.2.2 jdolecek * an "explicit conversion" by the ACPI specification. The
306 1.1.1.3.2.2 jdolecek * main restriction is that only hex and decimal are supported.
307 1.1.1.3.2.2 jdolecek *
308 1.1.1.3.2.2 jdolecek * -----------------------------------------------------------------------------
309 1.1.1.3.2.2 jdolecek *
310 1.1.1.3.2.2 jdolecek * Base is either 10 (default) or 16 (with 0x prefix). Octal (base 8) strings
311 1.1.1.3.2.2 jdolecek * are not supported, as per the ACPI specification.
312 1.1.1.3.2.2 jdolecek *
313 1.1.1.3.2.2 jdolecek * Examples:
314 1.1.1.3.2.2 jdolecek * ToInteger ("1000") Decimal
315 1.1.1.3.2.2 jdolecek * ToInteger ("0xABCD") Hex
316 1.1.1.3.2.2 jdolecek *
317 1.1.1.3.2.2 jdolecek * Conversion rules as extracted from the ACPI specification:
318 1.1.1.3.2.2 jdolecek *
319 1.1.1.3.2.2 jdolecek * 1) The input string is either a decimal or hexadecimal numeric string.
320 1.1.1.3.2.2 jdolecek * A hex value must be prefixed by "0x" or it is interpreted as decimal.
321 1.1.1.3.2.2 jdolecek *
322 1.1.1.3.2.2 jdolecek * 2) The value must not exceed the maximum of an integer value
323 1.1.1.3.2.2 jdolecek * (32 or 64 bits). The ACPI specification states the behavior is
324 1.1.1.3.2.2 jdolecek * "unpredictable", so ACPICA matches the behavior of the implicit
325 1.1.1.3.2.2 jdolecek * conversion case. There are no numeric overflow conditions. (NO ERROR)
326 1.1.1.3.2.2 jdolecek *
327 1.1.1.3.2.2 jdolecek * 3) Behavior on the first non-hex character is not defined by the ACPI
328 1.1.1.3.2.2 jdolecek * specification (for the ToInteger operator), so ACPICA matches the
329 1.1.1.3.2.2 jdolecek * behavior of the implicit conversion case. It terminates the
330 1.1.1.3.2.2 jdolecek * conversion and returns the current accumulated value of the converted
331 1.1.1.3.2.2 jdolecek * integer. (NO ERROR)
332 1.1.1.3.2.2 jdolecek *
333 1.1.1.3.2.2 jdolecek * 4) Conversion of a null (zero-length) string to an integer is
334 1.1.1.3.2.2 jdolecek * technically not allowed. However, ACPICA allows this as an ACPI
335 1.1.1.3.2.2 jdolecek * extension. The conversion returns the value 0. (NO ERROR)
336 1.1.1.3.2.2 jdolecek *
337 1.1.1.3.2.2 jdolecek * NOTE: There are no error conditions returned by this function. At the
338 1.1.1.3.2.2 jdolecek * minimum, a value of zero is returned.
339 1.1.1.3.2.2 jdolecek *
340 1.1.1.3.2.2 jdolecek * Current users of this function:
341 1.1.1.3.2.2 jdolecek *
342 1.1.1.3.2.2 jdolecek * Interpreter - Runtime ASL ToInteger operator, as per the ACPI specification
343 1.1.1.3.2.2 jdolecek *
344 1.1.1.3.2.2 jdolecek ******************************************************************************/
345 1.1.1.3.2.2 jdolecek
346 1.1.1.3.2.2 jdolecek UINT64
347 1.1.1.3.2.2 jdolecek AcpiUtExplicitStrtoul64 (
348 1.1.1.3.2.2 jdolecek char *String)
349 1.1.1.3.2.2 jdolecek {
350 1.1.1.3.2.2 jdolecek UINT64 ConvertedInteger = 0;
351 1.1.1.3.2.2 jdolecek UINT32 Base = 10; /* Default is decimal */
352 1.1.1.3.2.2 jdolecek
353 1.1.1.3.2.2 jdolecek
354 1.1.1.3.2.2 jdolecek ACPI_FUNCTION_TRACE_STR (UtExplicitStrtoul64, String);
355 1.1.1.3.2.2 jdolecek
356 1.1.1.3.2.2 jdolecek
357 1.1.1.3.2.2 jdolecek if (!AcpiUtRemoveWhitespace (&String))
358 1.1.1.3.2.2 jdolecek {
359 1.1.1.3.2.2 jdolecek return_VALUE (0);
360 1.1.1.3.2.2 jdolecek }
361 1.1.1.3.2.2 jdolecek
362 1.1.1.3.2.2 jdolecek /*
363 1.1.1.3.2.2 jdolecek * Only Hex and Decimal are supported, as per the ACPI specification.
364 1.1.1.3.2.2 jdolecek * A "0x" prefix indicates hex; otherwise decimal is assumed.
365 1.1.1.3.2.2 jdolecek */
366 1.1.1.3.2.2 jdolecek if (AcpiUtDetectHexPrefix (&String))
367 1.1.1.3.2.2 jdolecek {
368 1.1.1.3.2.2 jdolecek Base = 16;
369 1.1.1.3.2.2 jdolecek }
370 1.1.1.3.2.2 jdolecek
371 1.1.1.3.2.2 jdolecek if (!AcpiUtRemoveLeadingZeros (&String))
372 1.1.1.3.2.2 jdolecek {
373 1.1.1.3.2.2 jdolecek return_VALUE (0);
374 1.1.1.3.2.2 jdolecek }
375 1.1.1.3.2.2 jdolecek
376 1.1.1.3.2.2 jdolecek /*
377 1.1.1.3.2.2 jdolecek * Ignore overflow as per the ACPI specification. This is implemented by
378 1.1.1.3.2.2 jdolecek * ignoring the return status from the conversion functions called below.
379 1.1.1.3.2.2 jdolecek * On overflow, the input string is simply truncated.
380 1.1.1.3.2.2 jdolecek */
381 1.1.1.3.2.2 jdolecek switch (Base)
382 1.1.1.3.2.2 jdolecek {
383 1.1.1.3.2.2 jdolecek case 10:
384 1.1.1.3.2.2 jdolecek default:
385 1.1.1.3.2.2 jdolecek AcpiUtConvertDecimalString (String, &ConvertedInteger);
386 1.1.1.3.2.2 jdolecek break;
387 1.1.1.3.2.2 jdolecek
388 1.1.1.3.2.2 jdolecek case 16:
389 1.1.1.3.2.2 jdolecek AcpiUtConvertHexString (String, &ConvertedInteger);
390 1.1.1.3.2.2 jdolecek break;
391 1.1.1.3.2.2 jdolecek }
392 1.1.1.3.2.2 jdolecek
393 1.1.1.3.2.2 jdolecek return_VALUE (ConvertedInteger);
394 1.1.1.3.2.2 jdolecek }
395