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