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