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