OSDN Git Service

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