aslutils.c revision 1.1.1.12 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: aslutils -- compiler utilities
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1.1.2 jruoho /*
8 1.1.1.11 christos * Copyright (C) 2000 - 2017, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without
12 1.1.1.2 jruoho * modification, are permitted provided that the following conditions
13 1.1.1.2 jruoho * are met:
14 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2 jruoho * without modification.
17 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further
21 1.1.1.2 jruoho * binary redistribution.
22 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived
24 1.1.1.2 jruoho * from this software without specific prior written permission.
25 1.1.1.2 jruoho *
26 1.1.1.2 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2 jruoho * Software Foundation.
29 1.1.1.2 jruoho *
30 1.1.1.2 jruoho * NO WARRANTY
31 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2 jruoho */
43 1.1 jruoho
44 1.1 jruoho #include "aslcompiler.h"
45 1.1 jruoho #include "aslcompiler.y.h"
46 1.1.1.2 jruoho #include "acdisasm.h"
47 1.1 jruoho #include "acnamesp.h"
48 1.1 jruoho #include "amlcode.h"
49 1.1.1.8 christos #include "acapps.h"
50 1.1.1.8 christos #include <sys/stat.h>
51 1.1.1.8 christos
52 1.1 jruoho
53 1.1 jruoho #define _COMPONENT ACPI_COMPILER
54 1.1 jruoho ACPI_MODULE_NAME ("aslutils")
55 1.1 jruoho
56 1.1 jruoho
57 1.1 jruoho /* Local prototypes */
58 1.1 jruoho
59 1.1 jruoho static void
60 1.1 jruoho UtPadNameWithUnderscores (
61 1.1 jruoho char *NameSeg,
62 1.1 jruoho char *PaddedNameSeg);
63 1.1 jruoho
64 1.1 jruoho static void
65 1.1 jruoho UtAttachNameseg (
66 1.1 jruoho ACPI_PARSE_OBJECT *Op,
67 1.1 jruoho char *Name);
68 1.1 jruoho
69 1.1.1.12 christos static void
70 1.1.1.12 christos UtReallocLineBuffers (
71 1.1.1.12 christos char **Buffer,
72 1.1.1.12 christos UINT32 OldSize,
73 1.1.1.12 christos UINT32 NewSize);
74 1.1.1.12 christos
75 1.1 jruoho
76 1.1.1.9 christos /*******************************************************************************
77 1.1.1.9 christos *
78 1.1.1.9 christos * FUNCTION: UtIsBigEndianMachine
79 1.1.1.9 christos *
80 1.1.1.9 christos * PARAMETERS: None
81 1.1.1.9 christos *
82 1.1.1.9 christos * RETURN: TRUE if machine is big endian
83 1.1.1.9 christos * FALSE if machine is little endian
84 1.1.1.9 christos *
85 1.1.1.9 christos * DESCRIPTION: Detect whether machine is little endian or big endian.
86 1.1.1.9 christos *
87 1.1.1.9 christos ******************************************************************************/
88 1.1.1.9 christos
89 1.1.1.9 christos UINT8
90 1.1.1.9 christos UtIsBigEndianMachine (
91 1.1.1.9 christos void)
92 1.1.1.9 christos {
93 1.1.1.9 christos union {
94 1.1.1.9 christos UINT32 Integer;
95 1.1.1.9 christos UINT8 Bytes[4];
96 1.1.1.9 christos } Overlay = {0xFF000000};
97 1.1.1.9 christos
98 1.1.1.9 christos
99 1.1.1.9 christos return (Overlay.Bytes[0]); /* Returns 0xFF (TRUE) for big endian */
100 1.1.1.9 christos }
101 1.1.1.9 christos
102 1.1.1.9 christos
103 1.1.1.8 christos /******************************************************************************
104 1.1.1.8 christos *
105 1.1.1.8 christos * FUNCTION: UtQueryForOverwrite
106 1.1.1.8 christos *
107 1.1.1.8 christos * PARAMETERS: Pathname - Output filename
108 1.1.1.8 christos *
109 1.1.1.8 christos * RETURN: TRUE if file does not exist or overwrite is authorized
110 1.1.1.8 christos *
111 1.1.1.8 christos * DESCRIPTION: Query for file overwrite if it already exists.
112 1.1.1.8 christos *
113 1.1.1.8 christos ******************************************************************************/
114 1.1.1.8 christos
115 1.1.1.8 christos BOOLEAN
116 1.1.1.8 christos UtQueryForOverwrite (
117 1.1.1.8 christos char *Pathname)
118 1.1.1.8 christos {
119 1.1.1.8 christos struct stat StatInfo;
120 1.1.1.8 christos
121 1.1.1.8 christos
122 1.1.1.8 christos if (!stat (Pathname, &StatInfo))
123 1.1.1.8 christos {
124 1.1.1.8 christos fprintf (stderr, "Target file \"%s\" already exists, overwrite? [y|n] ",
125 1.1.1.8 christos Pathname);
126 1.1.1.8 christos
127 1.1.1.8 christos if (getchar () != 'y')
128 1.1.1.8 christos {
129 1.1.1.8 christos return (FALSE);
130 1.1.1.8 christos }
131 1.1.1.8 christos }
132 1.1.1.8 christos
133 1.1.1.8 christos return (TRUE);
134 1.1.1.8 christos }
135 1.1.1.8 christos
136 1.1.1.8 christos
137 1.1 jruoho /*******************************************************************************
138 1.1 jruoho *
139 1.1.1.2 jruoho * FUNCTION: UtDisplaySupportedTables
140 1.1.1.2 jruoho *
141 1.1.1.2 jruoho * PARAMETERS: None
142 1.1.1.2 jruoho *
143 1.1.1.2 jruoho * RETURN: None
144 1.1.1.2 jruoho *
145 1.1.1.2 jruoho * DESCRIPTION: Print all supported ACPI table names.
146 1.1.1.2 jruoho *
147 1.1.1.2 jruoho ******************************************************************************/
148 1.1.1.2 jruoho
149 1.1.1.2 jruoho void
150 1.1.1.2 jruoho UtDisplaySupportedTables (
151 1.1.1.2 jruoho void)
152 1.1.1.2 jruoho {
153 1.1.1.7 christos const AH_TABLE *TableData;
154 1.1.1.4 christos UINT32 i;
155 1.1.1.2 jruoho
156 1.1.1.2 jruoho
157 1.1.1.4 christos printf ("\nACPI tables supported by iASL version %8.8X:\n"
158 1.1.1.4 christos " (Compiler, Disassembler, Template Generator)\n\n",
159 1.1.1.4 christos ACPI_CA_VERSION);
160 1.1.1.2 jruoho
161 1.1.1.7 christos /* All ACPI tables with the common table header */
162 1.1.1.2 jruoho
163 1.1.1.7 christos printf ("\n Supported ACPI tables:\n");
164 1.1.1.11 christos for (TableData = Gbl_AcpiSupportedTables, i = 1;
165 1.1.1.7 christos TableData->Signature; TableData++, i++)
166 1.1.1.2 jruoho {
167 1.1.1.7 christos printf ("%8u) %s %s\n", i,
168 1.1.1.7 christos TableData->Signature, TableData->Description);
169 1.1.1.2 jruoho }
170 1.1.1.2 jruoho }
171 1.1.1.2 jruoho
172 1.1.1.2 jruoho
173 1.1.1.2 jruoho /*******************************************************************************
174 1.1.1.2 jruoho *
175 1.1.1.4 christos * FUNCTION: UtDisplayConstantOpcodes
176 1.1 jruoho *
177 1.1 jruoho * PARAMETERS: None
178 1.1 jruoho *
179 1.1 jruoho * RETURN: None
180 1.1 jruoho *
181 1.1 jruoho * DESCRIPTION: Print AML opcodes that can be used in constant expressions.
182 1.1 jruoho *
183 1.1 jruoho ******************************************************************************/
184 1.1 jruoho
185 1.1 jruoho void
186 1.1 jruoho UtDisplayConstantOpcodes (
187 1.1 jruoho void)
188 1.1 jruoho {
189 1.1 jruoho UINT32 i;
190 1.1 jruoho
191 1.1 jruoho
192 1.1 jruoho printf ("Constant expression opcode information\n\n");
193 1.1 jruoho
194 1.1 jruoho for (i = 0; i < sizeof (AcpiGbl_AmlOpInfo) / sizeof (ACPI_OPCODE_INFO); i++)
195 1.1 jruoho {
196 1.1 jruoho if (AcpiGbl_AmlOpInfo[i].Flags & AML_CONSTANT)
197 1.1 jruoho {
198 1.1 jruoho printf ("%s\n", AcpiGbl_AmlOpInfo[i].Name);
199 1.1 jruoho }
200 1.1 jruoho }
201 1.1 jruoho }
202 1.1 jruoho
203 1.1 jruoho
204 1.1 jruoho /*******************************************************************************
205 1.1 jruoho *
206 1.1 jruoho * FUNCTION: UtLocalCalloc
207 1.1 jruoho *
208 1.1.1.4 christos * PARAMETERS: Size - Bytes to be allocated
209 1.1 jruoho *
210 1.1.1.4 christos * RETURN: Pointer to the allocated memory. Guaranteed to be valid.
211 1.1 jruoho *
212 1.1.1.4 christos * DESCRIPTION: Allocate zero-initialized memory. Aborts the compile on an
213 1.1 jruoho * allocation failure, on the assumption that nothing more can be
214 1.1 jruoho * accomplished.
215 1.1 jruoho *
216 1.1 jruoho ******************************************************************************/
217 1.1 jruoho
218 1.1 jruoho void *
219 1.1 jruoho UtLocalCalloc (
220 1.1 jruoho UINT32 Size)
221 1.1 jruoho {
222 1.1 jruoho void *Allocated;
223 1.1 jruoho
224 1.1 jruoho
225 1.1 jruoho Allocated = ACPI_ALLOCATE_ZEROED (Size);
226 1.1 jruoho if (!Allocated)
227 1.1 jruoho {
228 1.1 jruoho AslCommonError (ASL_ERROR, ASL_MSG_MEMORY_ALLOCATION,
229 1.1 jruoho Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
230 1.1 jruoho Gbl_InputByteCount, Gbl_CurrentColumn,
231 1.1 jruoho Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
232 1.1 jruoho
233 1.1 jruoho CmCleanupAndExit ();
234 1.1 jruoho exit (1);
235 1.1 jruoho }
236 1.1 jruoho
237 1.1 jruoho TotalAllocations++;
238 1.1 jruoho TotalAllocated += Size;
239 1.1 jruoho return (Allocated);
240 1.1 jruoho }
241 1.1 jruoho
242 1.1 jruoho
243 1.1 jruoho /*******************************************************************************
244 1.1 jruoho *
245 1.1 jruoho * FUNCTION: UtBeginEvent
246 1.1 jruoho *
247 1.1.1.4 christos * PARAMETERS: Name - Ascii name of this event
248 1.1 jruoho *
249 1.1.1.4 christos * RETURN: Event number (integer index)
250 1.1 jruoho *
251 1.1 jruoho * DESCRIPTION: Saves the current time with this event
252 1.1 jruoho *
253 1.1 jruoho ******************************************************************************/
254 1.1 jruoho
255 1.1 jruoho UINT8
256 1.1 jruoho UtBeginEvent (
257 1.1 jruoho char *Name)
258 1.1 jruoho {
259 1.1 jruoho
260 1.1 jruoho if (AslGbl_NextEvent >= ASL_NUM_EVENTS)
261 1.1 jruoho {
262 1.1 jruoho AcpiOsPrintf ("Ran out of compiler event structs!\n");
263 1.1 jruoho return (AslGbl_NextEvent);
264 1.1 jruoho }
265 1.1 jruoho
266 1.1 jruoho /* Init event with current (start) time */
267 1.1 jruoho
268 1.1 jruoho AslGbl_Events[AslGbl_NextEvent].StartTime = AcpiOsGetTimer ();
269 1.1 jruoho AslGbl_Events[AslGbl_NextEvent].EventName = Name;
270 1.1 jruoho AslGbl_Events[AslGbl_NextEvent].Valid = TRUE;
271 1.1 jruoho return (AslGbl_NextEvent++);
272 1.1 jruoho }
273 1.1 jruoho
274 1.1 jruoho
275 1.1 jruoho /*******************************************************************************
276 1.1 jruoho *
277 1.1 jruoho * FUNCTION: UtEndEvent
278 1.1 jruoho *
279 1.1.1.4 christos * PARAMETERS: Event - Event number (integer index)
280 1.1 jruoho *
281 1.1 jruoho * RETURN: None
282 1.1 jruoho *
283 1.1 jruoho * DESCRIPTION: Saves the current time (end time) with this event
284 1.1 jruoho *
285 1.1 jruoho ******************************************************************************/
286 1.1 jruoho
287 1.1 jruoho void
288 1.1 jruoho UtEndEvent (
289 1.1.1.4 christos UINT8 Event)
290 1.1 jruoho {
291 1.1 jruoho
292 1.1 jruoho if (Event >= ASL_NUM_EVENTS)
293 1.1 jruoho {
294 1.1 jruoho return;
295 1.1 jruoho }
296 1.1 jruoho
297 1.1 jruoho /* Insert end time for event */
298 1.1 jruoho
299 1.1 jruoho AslGbl_Events[Event].EndTime = AcpiOsGetTimer ();
300 1.1 jruoho }
301 1.1 jruoho
302 1.1 jruoho
303 1.1 jruoho /*******************************************************************************
304 1.1 jruoho *
305 1.1 jruoho * FUNCTION: DbgPrint
306 1.1 jruoho *
307 1.1.1.4 christos * PARAMETERS: Type - Type of output
308 1.1.1.4 christos * Fmt - Printf format string
309 1.1.1.4 christos * ... - variable printf list
310 1.1 jruoho *
311 1.1 jruoho * RETURN: None
312 1.1 jruoho *
313 1.1.1.4 christos * DESCRIPTION: Conditional print statement. Prints to stderr only if the
314 1.1 jruoho * debug flag is set.
315 1.1 jruoho *
316 1.1 jruoho ******************************************************************************/
317 1.1 jruoho
318 1.1 jruoho void
319 1.1 jruoho DbgPrint (
320 1.1 jruoho UINT32 Type,
321 1.1 jruoho char *Fmt,
322 1.1 jruoho ...)
323 1.1 jruoho {
324 1.1 jruoho va_list Args;
325 1.1 jruoho
326 1.1 jruoho
327 1.1 jruoho if (!Gbl_DebugFlag)
328 1.1 jruoho {
329 1.1 jruoho return;
330 1.1 jruoho }
331 1.1 jruoho
332 1.1 jruoho if ((Type == ASL_PARSE_OUTPUT) &&
333 1.1 jruoho (!(AslCompilerdebug)))
334 1.1 jruoho {
335 1.1 jruoho return;
336 1.1 jruoho }
337 1.1 jruoho
338 1.1.1.4 christos va_start (Args, Fmt);
339 1.1 jruoho (void) vfprintf (stderr, Fmt, Args);
340 1.1 jruoho va_end (Args);
341 1.1 jruoho return;
342 1.1 jruoho }
343 1.1 jruoho
344 1.1 jruoho
345 1.1 jruoho /*******************************************************************************
346 1.1 jruoho *
347 1.1 jruoho * FUNCTION: UtSetParseOpName
348 1.1 jruoho *
349 1.1.1.4 christos * PARAMETERS: Op - Parse op to be named.
350 1.1 jruoho *
351 1.1 jruoho * RETURN: None
352 1.1 jruoho *
353 1.1 jruoho * DESCRIPTION: Insert the ascii name of the parse opcode
354 1.1 jruoho *
355 1.1 jruoho ******************************************************************************/
356 1.1 jruoho
357 1.1 jruoho void
358 1.1 jruoho UtSetParseOpName (
359 1.1 jruoho ACPI_PARSE_OBJECT *Op)
360 1.1 jruoho {
361 1.1 jruoho
362 1.1 jruoho strncpy (Op->Asl.ParseOpName, UtGetOpName (Op->Asl.ParseOpcode),
363 1.1 jruoho ACPI_MAX_PARSEOP_NAME);
364 1.1 jruoho }
365 1.1 jruoho
366 1.1 jruoho
367 1.1 jruoho /*******************************************************************************
368 1.1 jruoho *
369 1.1 jruoho * FUNCTION: UtDisplaySummary
370 1.1 jruoho *
371 1.1.1.4 christos * PARAMETERS: FileID - ID of outpout file
372 1.1 jruoho *
373 1.1 jruoho * RETURN: None
374 1.1 jruoho *
375 1.1 jruoho * DESCRIPTION: Display compilation statistics
376 1.1 jruoho *
377 1.1 jruoho ******************************************************************************/
378 1.1 jruoho
379 1.1 jruoho void
380 1.1 jruoho UtDisplaySummary (
381 1.1 jruoho UINT32 FileId)
382 1.1 jruoho {
383 1.1.1.4 christos UINT32 i;
384 1.1.1.4 christos
385 1.1 jruoho
386 1.1 jruoho if (FileId != ASL_FILE_STDOUT)
387 1.1 jruoho {
388 1.1 jruoho /* Compiler name and version number */
389 1.1 jruoho
390 1.1.1.11 christos FlPrintFile (FileId, "%s version %X [%s]\n\n",
391 1.1.1.11 christos ASL_COMPILER_NAME, (UINT32) ACPI_CA_VERSION, __DATE__);
392 1.1 jruoho }
393 1.1 jruoho
394 1.1.1.4 christos /* Summary of main input and output files */
395 1.1.1.4 christos
396 1.1 jruoho if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA)
397 1.1 jruoho {
398 1.1 jruoho FlPrintFile (FileId,
399 1.1.1.4 christos "%-14s %s - %u lines, %u bytes, %u fields\n",
400 1.1.1.4 christos "Table Input:",
401 1.1 jruoho Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_CurrentLineNumber,
402 1.1 jruoho Gbl_InputByteCount, Gbl_InputFieldCount);
403 1.1 jruoho
404 1.1 jruoho if ((Gbl_ExceptionCount[ASL_ERROR] == 0) || (Gbl_IgnoreErrors))
405 1.1 jruoho {
406 1.1 jruoho FlPrintFile (FileId,
407 1.1.1.4 christos "%-14s %s - %u bytes\n",
408 1.1.1.4 christos "Binary Output:",
409 1.1 jruoho Gbl_Files[ASL_FILE_AML_OUTPUT].Filename, Gbl_TableLength);
410 1.1 jruoho }
411 1.1 jruoho }
412 1.1 jruoho else
413 1.1 jruoho {
414 1.1 jruoho FlPrintFile (FileId,
415 1.1.1.4 christos "%-14s %s - %u lines, %u bytes, %u keywords\n",
416 1.1.1.4 christos "ASL Input:",
417 1.1 jruoho Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_CurrentLineNumber,
418 1.1.1.7 christos Gbl_OriginalInputFileSize, TotalKeywords);
419 1.1 jruoho
420 1.1 jruoho /* AML summary */
421 1.1 jruoho
422 1.1 jruoho if ((Gbl_ExceptionCount[ASL_ERROR] == 0) || (Gbl_IgnoreErrors))
423 1.1 jruoho {
424 1.1.1.7 christos if (Gbl_Files[ASL_FILE_AML_OUTPUT].Handle)
425 1.1.1.7 christos {
426 1.1.1.7 christos FlPrintFile (FileId,
427 1.1.1.8 christos "%-14s %s - %u bytes, %u named objects, "
428 1.1.1.8 christos "%u executable opcodes\n",
429 1.1.1.7 christos "AML Output:",
430 1.1.1.8 christos Gbl_Files[ASL_FILE_AML_OUTPUT].Filename,
431 1.1.1.8 christos FlGetFileSize (ASL_FILE_AML_OUTPUT),
432 1.1.1.7 christos TotalNamedObjects, TotalExecutableOpcodes);
433 1.1.1.7 christos }
434 1.1 jruoho }
435 1.1 jruoho }
436 1.1 jruoho
437 1.1.1.4 christos /* Display summary of any optional files */
438 1.1.1.4 christos
439 1.1.1.4 christos for (i = ASL_FILE_SOURCE_OUTPUT; i <= ASL_MAX_FILE_TYPE; i++)
440 1.1.1.4 christos {
441 1.1.1.4 christos if (!Gbl_Files[i].Filename || !Gbl_Files[i].Handle)
442 1.1.1.4 christos {
443 1.1.1.4 christos continue;
444 1.1.1.4 christos }
445 1.1.1.4 christos
446 1.1.1.4 christos /* .SRC is a temp file unless specifically requested */
447 1.1.1.4 christos
448 1.1.1.4 christos if ((i == ASL_FILE_SOURCE_OUTPUT) && (!Gbl_SourceOutputFlag))
449 1.1.1.4 christos {
450 1.1.1.4 christos continue;
451 1.1.1.4 christos }
452 1.1.1.4 christos
453 1.1.1.7 christos /* .PRE is the preprocessor intermediate file */
454 1.1.1.4 christos
455 1.1.1.7 christos if ((i == ASL_FILE_PREPROCESSOR) && (!Gbl_KeepPreprocessorTempFile))
456 1.1.1.4 christos {
457 1.1.1.4 christos continue;
458 1.1.1.4 christos }
459 1.1.1.4 christos
460 1.1.1.4 christos FlPrintFile (FileId, "%14s %s - %u bytes\n",
461 1.1.1.4 christos Gbl_Files[i].ShortDescription,
462 1.1.1.4 christos Gbl_Files[i].Filename, FlGetFileSize (i));
463 1.1.1.4 christos }
464 1.1.1.4 christos
465 1.1 jruoho /* Error summary */
466 1.1 jruoho
467 1.1 jruoho FlPrintFile (FileId,
468 1.1.1.4 christos "\nCompilation complete. %u Errors, %u Warnings, %u Remarks",
469 1.1 jruoho Gbl_ExceptionCount[ASL_ERROR],
470 1.1 jruoho Gbl_ExceptionCount[ASL_WARNING] +
471 1.1 jruoho Gbl_ExceptionCount[ASL_WARNING2] +
472 1.1 jruoho Gbl_ExceptionCount[ASL_WARNING3],
473 1.1 jruoho Gbl_ExceptionCount[ASL_REMARK]);
474 1.1 jruoho
475 1.1 jruoho if (Gbl_FileType != ASL_INPUT_TYPE_ASCII_DATA)
476 1.1 jruoho {
477 1.1.1.6 christos FlPrintFile (FileId, ", %u Optimizations",
478 1.1.1.6 christos Gbl_ExceptionCount[ASL_OPTIMIZATION]);
479 1.1.1.6 christos
480 1.1.1.6 christos if (TotalFolds)
481 1.1.1.6 christos {
482 1.1.1.6 christos FlPrintFile (FileId, ", %u Constants Folded", TotalFolds);
483 1.1.1.6 christos }
484 1.1 jruoho }
485 1.1 jruoho
486 1.1 jruoho FlPrintFile (FileId, "\n");
487 1.1 jruoho }
488 1.1 jruoho
489 1.1 jruoho
490 1.1 jruoho /*******************************************************************************
491 1.1 jruoho *
492 1.1.1.4 christos * FUNCTION: UtCheckIntegerRange
493 1.1 jruoho *
494 1.1.1.4 christos * PARAMETERS: Op - Integer parse node
495 1.1.1.4 christos * LowValue - Smallest allowed value
496 1.1.1.4 christos * HighValue - Largest allowed value
497 1.1 jruoho *
498 1.1 jruoho * RETURN: Op if OK, otherwise NULL
499 1.1 jruoho *
500 1.1 jruoho * DESCRIPTION: Check integer for an allowable range
501 1.1 jruoho *
502 1.1 jruoho ******************************************************************************/
503 1.1 jruoho
504 1.1 jruoho ACPI_PARSE_OBJECT *
505 1.1 jruoho UtCheckIntegerRange (
506 1.1 jruoho ACPI_PARSE_OBJECT *Op,
507 1.1 jruoho UINT32 LowValue,
508 1.1 jruoho UINT32 HighValue)
509 1.1 jruoho {
510 1.1 jruoho
511 1.1 jruoho if (!Op)
512 1.1 jruoho {
513 1.1.1.4 christos return (NULL);
514 1.1 jruoho }
515 1.1 jruoho
516 1.1.1.4 christos if ((Op->Asl.Value.Integer < LowValue) ||
517 1.1.1.4 christos (Op->Asl.Value.Integer > HighValue))
518 1.1 jruoho {
519 1.1.1.4 christos sprintf (MsgBuffer, "0x%X, allowable: 0x%X-0x%X",
520 1.1.1.4 christos (UINT32) Op->Asl.Value.Integer, LowValue, HighValue);
521 1.1 jruoho
522 1.1.1.4 christos AslError (ASL_ERROR, ASL_MSG_RANGE, Op, MsgBuffer);
523 1.1.1.4 christos return (NULL);
524 1.1 jruoho }
525 1.1 jruoho
526 1.1.1.4 christos return (Op);
527 1.1 jruoho }
528 1.1 jruoho
529 1.1 jruoho
530 1.1 jruoho /*******************************************************************************
531 1.1 jruoho *
532 1.1.1.5 christos * FUNCTION: UtStringCacheCalloc
533 1.1 jruoho *
534 1.1.1.4 christos * PARAMETERS: Length - Size of buffer requested
535 1.1 jruoho *
536 1.1.1.12 christos * RETURN: Pointer to the buffer. Aborts compiler on allocation failure
537 1.1 jruoho *
538 1.1.1.4 christos * DESCRIPTION: Allocate a string buffer. Bypass the local
539 1.1 jruoho * dynamic memory manager for performance reasons (This has a
540 1.1 jruoho * major impact on the speed of the compiler.)
541 1.1 jruoho *
542 1.1 jruoho ******************************************************************************/
543 1.1 jruoho
544 1.1 jruoho char *
545 1.1.1.5 christos UtStringCacheCalloc (
546 1.1 jruoho UINT32 Length)
547 1.1 jruoho {
548 1.1 jruoho char *Buffer;
549 1.1.1.5 christos ASL_CACHE_INFO *Cache;
550 1.1.1.6 christos UINT32 CacheSize = ASL_STRING_CACHE_SIZE;
551 1.1 jruoho
552 1.1 jruoho
553 1.1.1.6 christos if (Length > CacheSize)
554 1.1.1.5 christos {
555 1.1.1.6 christos CacheSize = Length;
556 1.1.1.6 christos
557 1.1.1.6 christos if (Gbl_StringCacheList)
558 1.1.1.6 christos {
559 1.1.1.6 christos Cache = UtLocalCalloc (sizeof (Cache->Next) + CacheSize);
560 1.1.1.6 christos
561 1.1.1.6 christos /* Link new cache buffer just following head of list */
562 1.1.1.6 christos
563 1.1.1.6 christos Cache->Next = Gbl_StringCacheList->Next;
564 1.1.1.6 christos Gbl_StringCacheList->Next = Cache;
565 1.1.1.6 christos
566 1.1.1.6 christos /* Leave cache management pointers alone as they pertain to head */
567 1.1.1.6 christos
568 1.1.1.6 christos Gbl_StringCount++;
569 1.1.1.6 christos Gbl_StringSize += Length;
570 1.1.1.6 christos
571 1.1.1.6 christos return (Cache->Buffer);
572 1.1.1.6 christos }
573 1.1.1.5 christos }
574 1.1.1.5 christos
575 1.1 jruoho if ((Gbl_StringCacheNext + Length) >= Gbl_StringCacheLast)
576 1.1 jruoho {
577 1.1.1.5 christos /* Allocate a new buffer */
578 1.1.1.5 christos
579 1.1.1.6 christos Cache = UtLocalCalloc (sizeof (Cache->Next) + CacheSize);
580 1.1.1.5 christos
581 1.1.1.5 christos /* Link new cache buffer to head of list */
582 1.1.1.5 christos
583 1.1.1.5 christos Cache->Next = Gbl_StringCacheList;
584 1.1.1.5 christos Gbl_StringCacheList = Cache;
585 1.1.1.5 christos
586 1.1.1.5 christos /* Setup cache management pointers */
587 1.1.1.5 christos
588 1.1.1.5 christos Gbl_StringCacheNext = Cache->Buffer;
589 1.1.1.6 christos Gbl_StringCacheLast = Gbl_StringCacheNext + CacheSize;
590 1.1 jruoho }
591 1.1 jruoho
592 1.1.1.5 christos Gbl_StringCount++;
593 1.1.1.5 christos Gbl_StringSize += Length;
594 1.1.1.5 christos
595 1.1 jruoho Buffer = Gbl_StringCacheNext;
596 1.1 jruoho Gbl_StringCacheNext += Length;
597 1.1 jruoho return (Buffer);
598 1.1 jruoho }
599 1.1 jruoho
600 1.1 jruoho
601 1.1.1.4 christos /******************************************************************************
602 1.1.1.4 christos *
603 1.1.1.4 christos * FUNCTION: UtExpandLineBuffers
604 1.1.1.4 christos *
605 1.1.1.4 christos * PARAMETERS: None. Updates global line buffer pointers.
606 1.1.1.4 christos *
607 1.1.1.4 christos * RETURN: None. Reallocates the global line buffers
608 1.1.1.4 christos *
609 1.1.1.4 christos * DESCRIPTION: Called if the current line buffer becomes filled. Reallocates
610 1.1.1.4 christos * all global line buffers and updates Gbl_LineBufferSize. NOTE:
611 1.1.1.4 christos * Also used for the initial allocation of the buffers, when
612 1.1.1.4 christos * all of the buffer pointers are NULL. Initial allocations are
613 1.1.1.4 christos * of size ASL_DEFAULT_LINE_BUFFER_SIZE
614 1.1.1.4 christos *
615 1.1.1.4 christos *****************************************************************************/
616 1.1.1.4 christos
617 1.1.1.4 christos void
618 1.1.1.4 christos UtExpandLineBuffers (
619 1.1.1.4 christos void)
620 1.1.1.4 christos {
621 1.1.1.4 christos UINT32 NewSize;
622 1.1.1.4 christos
623 1.1.1.4 christos
624 1.1.1.4 christos /* Attempt to double the size of all line buffers */
625 1.1.1.4 christos
626 1.1.1.4 christos NewSize = Gbl_LineBufferSize * 2;
627 1.1.1.4 christos if (Gbl_CurrentLineBuffer)
628 1.1.1.4 christos {
629 1.1.1.5 christos DbgPrint (ASL_DEBUG_OUTPUT,
630 1.1.1.5 christos "Increasing line buffer size from %u to %u\n",
631 1.1.1.4 christos Gbl_LineBufferSize, NewSize);
632 1.1.1.4 christos }
633 1.1.1.4 christos
634 1.1.1.12 christos UtReallocLineBuffers (&Gbl_CurrentLineBuffer, Gbl_LineBufferSize, NewSize);
635 1.1.1.12 christos UtReallocLineBuffers (&Gbl_MainTokenBuffer, Gbl_LineBufferSize, NewSize);
636 1.1.1.12 christos UtReallocLineBuffers (&Gbl_MacroTokenBuffer, Gbl_LineBufferSize, NewSize);
637 1.1.1.12 christos UtReallocLineBuffers (&Gbl_ExpressionTokenBuffer, Gbl_LineBufferSize, NewSize);
638 1.1.1.12 christos
639 1.1.1.4 christos Gbl_LineBufPtr = Gbl_CurrentLineBuffer;
640 1.1.1.12 christos Gbl_LineBufferSize = NewSize;
641 1.1.1.12 christos }
642 1.1.1.4 christos
643 1.1.1.4 christos
644 1.1.1.12 christos /******************************************************************************
645 1.1.1.12 christos *
646 1.1.1.12 christos * FUNCTION: UtReallocLineBuffers
647 1.1.1.12 christos *
648 1.1.1.12 christos * PARAMETERS: Buffer - Buffer to realloc
649 1.1.1.12 christos * OldSize - Old size of Buffer
650 1.1.1.12 christos * NewSize - New size of Buffer
651 1.1.1.12 christos *
652 1.1.1.12 christos * RETURN: none
653 1.1.1.12 christos *
654 1.1.1.12 christos * DESCRIPTION: Reallocate and initialize Buffer
655 1.1.1.12 christos *
656 1.1.1.12 christos *****************************************************************************/
657 1.1.1.12 christos
658 1.1.1.12 christos static void
659 1.1.1.12 christos UtReallocLineBuffers (
660 1.1.1.12 christos char **Buffer,
661 1.1.1.12 christos UINT32 OldSize,
662 1.1.1.12 christos UINT32 NewSize)
663 1.1.1.12 christos {
664 1.1.1.4 christos
665 1.1.1.12 christos *Buffer = realloc (*Buffer, NewSize);
666 1.1.1.12 christos if (*Buffer)
667 1.1.1.4 christos {
668 1.1.1.12 christos memset (*Buffer + OldSize, 0, NewSize - OldSize);
669 1.1.1.12 christos return;
670 1.1.1.4 christos }
671 1.1.1.4 christos
672 1.1.1.4 christos printf ("Could not increase line buffer size from %u to %u\n",
673 1.1.1.12 christos OldSize, NewSize);
674 1.1.1.4 christos
675 1.1.1.12 christos AslError (ASL_ERROR, ASL_MSG_BUFFER_ALLOCATION, NULL, NULL);
676 1.1.1.4 christos AslAbort ();
677 1.1.1.4 christos }
678 1.1.1.4 christos
679 1.1.1.4 christos
680 1.1.1.5 christos /******************************************************************************
681 1.1.1.5 christos *
682 1.1.1.5 christos * FUNCTION: UtFreeLineBuffers
683 1.1.1.5 christos *
684 1.1.1.5 christos * PARAMETERS: None
685 1.1.1.5 christos *
686 1.1.1.5 christos * RETURN: None
687 1.1.1.5 christos *
688 1.1.1.5 christos * DESCRIPTION: Free all line buffers
689 1.1.1.5 christos *
690 1.1.1.5 christos *****************************************************************************/
691 1.1.1.5 christos
692 1.1.1.5 christos void
693 1.1.1.5 christos UtFreeLineBuffers (
694 1.1.1.5 christos void)
695 1.1.1.5 christos {
696 1.1.1.5 christos
697 1.1.1.5 christos free (Gbl_CurrentLineBuffer);
698 1.1.1.5 christos free (Gbl_MainTokenBuffer);
699 1.1.1.5 christos free (Gbl_MacroTokenBuffer);
700 1.1.1.5 christos free (Gbl_ExpressionTokenBuffer);
701 1.1.1.5 christos }
702 1.1.1.5 christos
703 1.1.1.5 christos
704 1.1 jruoho /*******************************************************************************
705 1.1 jruoho *
706 1.1 jruoho * FUNCTION: UtInternalizeName
707 1.1 jruoho *
708 1.1.1.4 christos * PARAMETERS: ExternalName - Name to convert
709 1.1.1.4 christos * ConvertedName - Where the converted name is returned
710 1.1 jruoho *
711 1.1 jruoho * RETURN: Status
712 1.1 jruoho *
713 1.1 jruoho * DESCRIPTION: Convert an external (ASL) name to an internal (AML) name
714 1.1 jruoho *
715 1.1 jruoho ******************************************************************************/
716 1.1 jruoho
717 1.1 jruoho ACPI_STATUS
718 1.1 jruoho UtInternalizeName (
719 1.1 jruoho char *ExternalName,
720 1.1 jruoho char **ConvertedName)
721 1.1 jruoho {
722 1.1 jruoho ACPI_NAMESTRING_INFO Info;
723 1.1 jruoho ACPI_STATUS Status;
724 1.1 jruoho
725 1.1 jruoho
726 1.1 jruoho if (!ExternalName)
727 1.1 jruoho {
728 1.1 jruoho return (AE_OK);
729 1.1 jruoho }
730 1.1 jruoho
731 1.1 jruoho /* Get the length of the new internal name */
732 1.1 jruoho
733 1.1 jruoho Info.ExternalName = ExternalName;
734 1.1 jruoho AcpiNsGetInternalNameLength (&Info);
735 1.1 jruoho
736 1.1.1.5 christos /* We need a segment to store the internal name */
737 1.1 jruoho
738 1.1.1.5 christos Info.InternalName = UtStringCacheCalloc (Info.Length);
739 1.1 jruoho
740 1.1 jruoho /* Build the name */
741 1.1 jruoho
742 1.1 jruoho Status = AcpiNsBuildInternalName (&Info);
743 1.1 jruoho if (ACPI_FAILURE (Status))
744 1.1 jruoho {
745 1.1 jruoho return (Status);
746 1.1 jruoho }
747 1.1 jruoho
748 1.1 jruoho *ConvertedName = Info.InternalName;
749 1.1 jruoho return (AE_OK);
750 1.1 jruoho }
751 1.1 jruoho
752 1.1 jruoho
753 1.1 jruoho /*******************************************************************************
754 1.1 jruoho *
755 1.1 jruoho * FUNCTION: UtPadNameWithUnderscores
756 1.1 jruoho *
757 1.1.1.4 christos * PARAMETERS: NameSeg - Input nameseg
758 1.1.1.4 christos * PaddedNameSeg - Output padded nameseg
759 1.1 jruoho *
760 1.1 jruoho * RETURN: Padded nameseg.
761 1.1 jruoho *
762 1.1 jruoho * DESCRIPTION: Pads a NameSeg with underscores if necessary to form a full
763 1.1 jruoho * ACPI_NAME.
764 1.1 jruoho *
765 1.1 jruoho ******************************************************************************/
766 1.1 jruoho
767 1.1 jruoho static void
768 1.1 jruoho UtPadNameWithUnderscores (
769 1.1 jruoho char *NameSeg,
770 1.1 jruoho char *PaddedNameSeg)
771 1.1 jruoho {
772 1.1 jruoho UINT32 i;
773 1.1 jruoho
774 1.1 jruoho
775 1.1 jruoho for (i = 0; (i < ACPI_NAME_SIZE); i++)
776 1.1 jruoho {
777 1.1 jruoho if (*NameSeg)
778 1.1 jruoho {
779 1.1 jruoho *PaddedNameSeg = *NameSeg;
780 1.1 jruoho NameSeg++;
781 1.1 jruoho }
782 1.1 jruoho else
783 1.1 jruoho {
784 1.1 jruoho *PaddedNameSeg = '_';
785 1.1 jruoho }
786 1.1.1.8 christos
787 1.1 jruoho PaddedNameSeg++;
788 1.1 jruoho }
789 1.1 jruoho }
790 1.1 jruoho
791 1.1 jruoho
792 1.1 jruoho /*******************************************************************************
793 1.1 jruoho *
794 1.1 jruoho * FUNCTION: UtAttachNameseg
795 1.1 jruoho *
796 1.1.1.4 christos * PARAMETERS: Op - Parent parse node
797 1.1.1.4 christos * Name - Full ExternalName
798 1.1 jruoho *
799 1.1 jruoho * RETURN: None; Sets the NameSeg field in parent node
800 1.1 jruoho *
801 1.1 jruoho * DESCRIPTION: Extract the last nameseg of the ExternalName and store it
802 1.1 jruoho * in the NameSeg field of the Op.
803 1.1 jruoho *
804 1.1 jruoho ******************************************************************************/
805 1.1 jruoho
806 1.1 jruoho static void
807 1.1 jruoho UtAttachNameseg (
808 1.1 jruoho ACPI_PARSE_OBJECT *Op,
809 1.1 jruoho char *Name)
810 1.1 jruoho {
811 1.1 jruoho char *NameSeg;
812 1.1 jruoho char PaddedNameSeg[4];
813 1.1 jruoho
814 1.1 jruoho
815 1.1 jruoho if (!Name)
816 1.1 jruoho {
817 1.1 jruoho return;
818 1.1 jruoho }
819 1.1 jruoho
820 1.1 jruoho /* Look for the last dot in the namepath */
821 1.1 jruoho
822 1.1 jruoho NameSeg = strrchr (Name, '.');
823 1.1 jruoho if (NameSeg)
824 1.1 jruoho {
825 1.1 jruoho /* Found last dot, we have also found the final nameseg */
826 1.1 jruoho
827 1.1 jruoho NameSeg++;
828 1.1 jruoho UtPadNameWithUnderscores (NameSeg, PaddedNameSeg);
829 1.1 jruoho }
830 1.1 jruoho else
831 1.1 jruoho {
832 1.1 jruoho /* No dots in the namepath, there is only a single nameseg. */
833 1.1 jruoho /* Handle prefixes */
834 1.1 jruoho
835 1.1.1.4 christos while (ACPI_IS_ROOT_PREFIX (*Name) ||
836 1.1.1.4 christos ACPI_IS_PARENT_PREFIX (*Name))
837 1.1 jruoho {
838 1.1 jruoho Name++;
839 1.1 jruoho }
840 1.1 jruoho
841 1.1.1.4 christos /* Remaining string should be one single nameseg */
842 1.1 jruoho
843 1.1 jruoho UtPadNameWithUnderscores (Name, PaddedNameSeg);
844 1.1 jruoho }
845 1.1 jruoho
846 1.1.1.4 christos ACPI_MOVE_NAME (Op->Asl.NameSeg, PaddedNameSeg);
847 1.1 jruoho }
848 1.1 jruoho
849 1.1 jruoho
850 1.1 jruoho /*******************************************************************************
851 1.1 jruoho *
852 1.1 jruoho * FUNCTION: UtAttachNamepathToOwner
853 1.1 jruoho *
854 1.1.1.4 christos * PARAMETERS: Op - Parent parse node
855 1.1.1.4 christos * NameOp - Node that contains the name
856 1.1 jruoho *
857 1.1 jruoho * RETURN: Sets the ExternalName and Namepath in the parent node
858 1.1 jruoho *
859 1.1.1.4 christos * DESCRIPTION: Store the name in two forms in the parent node: The original
860 1.1 jruoho * (external) name, and the internalized name that is used within
861 1.1 jruoho * the ACPI namespace manager.
862 1.1 jruoho *
863 1.1 jruoho ******************************************************************************/
864 1.1 jruoho
865 1.1 jruoho void
866 1.1 jruoho UtAttachNamepathToOwner (
867 1.1 jruoho ACPI_PARSE_OBJECT *Op,
868 1.1 jruoho ACPI_PARSE_OBJECT *NameOp)
869 1.1 jruoho {
870 1.1 jruoho ACPI_STATUS Status;
871 1.1 jruoho
872 1.1 jruoho
873 1.1 jruoho /* Full external path */
874 1.1 jruoho
875 1.1 jruoho Op->Asl.ExternalName = NameOp->Asl.Value.String;
876 1.1 jruoho
877 1.1 jruoho /* Save the NameOp for possible error reporting later */
878 1.1 jruoho
879 1.1 jruoho Op->Asl.ParentMethod = (void *) NameOp;
880 1.1 jruoho
881 1.1 jruoho /* Last nameseg of the path */
882 1.1 jruoho
883 1.1 jruoho UtAttachNameseg (Op, Op->Asl.ExternalName);
884 1.1 jruoho
885 1.1 jruoho /* Create internalized path */
886 1.1 jruoho
887 1.1 jruoho Status = UtInternalizeName (NameOp->Asl.Value.String, &Op->Asl.Namepath);
888 1.1 jruoho if (ACPI_FAILURE (Status))
889 1.1 jruoho {
890 1.1 jruoho /* TBD: abort on no memory */
891 1.1 jruoho }
892 1.1 jruoho }
893 1.1 jruoho
894 1.1 jruoho
895 1.1 jruoho /*******************************************************************************
896 1.1 jruoho *
897 1.1 jruoho * FUNCTION: UtDoConstant
898 1.1 jruoho *
899 1.1.1.12 christos * PARAMETERS: String - Hex/Decimal/Octal
900 1.1 jruoho *
901 1.1 jruoho * RETURN: Converted Integer
902 1.1 jruoho *
903 1.1.1.12 christos * DESCRIPTION: Convert a string to an integer, with overflow/error checking.
904 1.1 jruoho *
905 1.1 jruoho ******************************************************************************/
906 1.1 jruoho
907 1.1 jruoho UINT64
908 1.1 jruoho UtDoConstant (
909 1.1 jruoho char *String)
910 1.1 jruoho {
911 1.1 jruoho ACPI_STATUS Status;
912 1.1.1.12 christos UINT64 ConvertedInteger;
913 1.1 jruoho char ErrBuf[64];
914 1.1 jruoho
915 1.1 jruoho
916 1.1.1.12 christos Status = AcpiUtStrtoul64 (String, &ConvertedInteger);
917 1.1 jruoho if (ACPI_FAILURE (Status))
918 1.1 jruoho {
919 1.1.1.12 christos sprintf (ErrBuf, "While creating 64-bit constant: %s\n",
920 1.1 jruoho AcpiFormatException (Status));
921 1.1.1.12 christos
922 1.1.1.12 christos AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, Gbl_CurrentLineNumber,
923 1.1.1.12 christos Gbl_LogicalLineNumber, Gbl_CurrentLineOffset,
924 1.1.1.12 christos Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename, ErrBuf);
925 1.1 jruoho }
926 1.1 jruoho
927 1.1.1.12 christos return (ConvertedInteger);
928 1.1 jruoho }
929