xref: /freebsd/sys/contrib/dev/acpica/compiler/aslutils.c (revision 480093f4440d54b30b3025afeac24b48f2ba7a2e)
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 - 2020, 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  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
122  * 1. Redistributions of source code must retain the above copyright
123  *    notice, this list of conditions, and the following disclaimer,
124  *    without modification.
125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126  *    substantially similar to the "NO WARRANTY" disclaimer below
127  *    ("Disclaimer") and any redistribution must be conditioned upon
128  *    including a substantially similar Disclaimer requirement for further
129  *    binary redistribution.
130  * 3. Neither the names of the above-listed copyright holders nor the names
131  *    of any contributors may be used to endorse or promote products derived
132  *    from this software without specific prior written permission.
133  *
134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145  *
146  * Alternatively, you may choose to be licensed under the terms of the
147  * GNU General Public License ("GPL") version 2 as published by the Free
148  * Software Foundation.
149  *
150  *****************************************************************************/
151 
152 #include <contrib/dev/acpica/compiler/aslcompiler.h>
153 #include "aslcompiler.y.h"
154 #include <contrib/dev/acpica/include/acdisasm.h>
155 #include <contrib/dev/acpica/include/acnamesp.h>
156 #include <contrib/dev/acpica/include/amlcode.h>
157 #include <contrib/dev/acpica/include/acapps.h>
158 #include <sys/stat.h>
159 
160 
161 #define _COMPONENT          ACPI_COMPILER
162         ACPI_MODULE_NAME    ("aslutils")
163 
164 
165 /* Local prototypes */
166 
167 static void
168 UtPadNameWithUnderscores (
169     char                    *NameSeg,
170     char                    *PaddedNameSeg);
171 
172 static void
173 UtAttachNameseg (
174     ACPI_PARSE_OBJECT       *Op,
175     char                    *Name);
176 
177 static void
178 UtDisplayErrorSummary (
179     UINT32                  FileId);
180 
181 
182 /*******************************************************************************
183  *
184  * FUNCTION:    UtIsBigEndianMachine
185  *
186  * PARAMETERS:  None
187  *
188  * RETURN:      TRUE if machine is big endian
189  *              FALSE if machine is little endian
190  *
191  * DESCRIPTION: Detect whether machine is little endian or big endian.
192  *
193  ******************************************************************************/
194 
195 UINT8
196 UtIsBigEndianMachine (
197     void)
198 {
199     union {
200         UINT32              Integer;
201         UINT8               Bytes[4];
202     } Overlay =                 {0xFF000000};
203 
204 
205     return (Overlay.Bytes[0]); /* Returns 0xFF (TRUE) for big endian */
206 }
207 
208 
209 /******************************************************************************
210  *
211  * FUNCTION:    UtQueryForOverwrite
212  *
213  * PARAMETERS:  Pathname            - Output filename
214  *
215  * RETURN:      TRUE if file does not exist or overwrite is authorized
216  *
217  * DESCRIPTION: Query for file overwrite if it already exists.
218  *
219  ******************************************************************************/
220 
221 BOOLEAN
222 UtQueryForOverwrite (
223     char                    *Pathname)
224 {
225     struct stat             StatInfo;
226     int                     InChar;
227 
228 
229     if (!stat (Pathname, &StatInfo))
230     {
231         fprintf (stderr, "Target file \"%s\" already exists, overwrite? [y|n] ",
232             Pathname);
233 
234         InChar = fgetc (stdin);
235         if (InChar == '\n')
236         {
237             InChar = fgetc (stdin);
238         }
239 
240         if ((InChar != 'y') && (InChar != 'Y'))
241         {
242             return (FALSE);
243         }
244     }
245 
246     return (TRUE);
247 }
248 
249 
250 /*******************************************************************************
251  *
252  * FUNCTION:    UtNodeIsDescendantOf
253  *
254  * PARAMETERS:  Node1                   - Child node
255  *              Node2                   - Possible parent node
256  *
257  * RETURN:      Boolean
258  *
259  * DESCRIPTION: Returns TRUE if Node1 is a descendant of Node2. Otherwise,
260  *              return FALSE. Note, we assume a NULL Node2 element to be the
261  *              topmost (root) scope. All nodes are descendants of the root.
262  *              Note: Nodes at the same level (siblings) are not considered
263  *              descendants.
264  *
265  ******************************************************************************/
266 
267 BOOLEAN
268 UtNodeIsDescendantOf (
269     ACPI_NAMESPACE_NODE     *Node1,
270     ACPI_NAMESPACE_NODE     *Node2)
271 {
272 
273     if (Node1 == Node2)
274     {
275         return (FALSE);
276     }
277 
278     if (!Node2)
279     {
280         return (TRUE); /* All nodes descend from the root */
281     }
282 
283     /* Walk upward until the root is reached or parent is found */
284 
285     while (Node1)
286     {
287         if (Node1 == Node2)
288         {
289             return (TRUE);
290         }
291 
292         Node1 = Node1->Parent;
293     }
294 
295     return (FALSE);
296 }
297 
298 
299 /*******************************************************************************
300  *
301  * FUNCTION:    UtGetParentMethod
302  *
303  * PARAMETERS:  Node                    - Namespace node for any object
304  *
305  * RETURN:      Namespace node for the parent method
306  *              NULL - object is not within a method
307  *
308  * DESCRIPTION: Find the parent (owning) method node for a namespace object
309  *
310  ******************************************************************************/
311 
312 void *
313 UtGetParentMethod (
314     ACPI_NAMESPACE_NODE     *Node)
315 {
316     ACPI_NAMESPACE_NODE     *ParentNode;
317 
318 
319     if (!Node)
320     {
321         return (NULL);
322     }
323 
324     /* Walk upward until a method is found, or the root is reached */
325 
326     ParentNode = Node->Parent;
327     while (ParentNode)
328     {
329         if (ParentNode->Type == ACPI_TYPE_METHOD)
330         {
331             return (ParentNode);
332         }
333 
334         ParentNode = ParentNode->Parent;
335     }
336 
337     return (NULL); /* Object is not within a control method */
338 }
339 
340 
341 /*******************************************************************************
342  *
343  * FUNCTION:    UtDisplaySupportedTables
344  *
345  * PARAMETERS:  None
346  *
347  * RETURN:      None
348  *
349  * DESCRIPTION: Print all supported ACPI table names.
350  *
351  ******************************************************************************/
352 
353 void
354 UtDisplaySupportedTables (
355     void)
356 {
357     const AH_TABLE          *TableData;
358     UINT32                  i;
359 
360 
361     printf ("\nACPI tables supported by iASL version %8.8X:\n"
362         "  (Compiler, Disassembler, Template Generator)\n\n",
363         ACPI_CA_VERSION);
364 
365     /* All ACPI tables with the common table header */
366 
367     printf ("\n  Supported ACPI tables:\n");
368     for (TableData = AcpiGbl_SupportedTables, i = 1;
369          TableData->Signature; TableData++, i++)
370     {
371         printf ("%8u) %s    %s\n", i,
372             TableData->Signature, TableData->Description);
373     }
374 }
375 
376 
377 /*******************************************************************************
378  *
379  * FUNCTION:    UtDisplayConstantOpcodes
380  *
381  * PARAMETERS:  None
382  *
383  * RETURN:      None
384  *
385  * DESCRIPTION: Print AML opcodes that can be used in constant expressions.
386  *
387  ******************************************************************************/
388 
389 void
390 UtDisplayConstantOpcodes (
391     void)
392 {
393     UINT32                  i;
394 
395 
396     printf ("Constant expression opcode information\n\n");
397 
398     for (i = 0; i < sizeof (AcpiGbl_AmlOpInfo) / sizeof (ACPI_OPCODE_INFO); i++)
399     {
400         if (AcpiGbl_AmlOpInfo[i].Flags & AML_CONSTANT)
401         {
402             printf ("%s\n", AcpiGbl_AmlOpInfo[i].Name);
403         }
404     }
405 }
406 
407 
408 /*******************************************************************************
409  *
410  * FUNCTION:    UtBeginEvent
411  *
412  * PARAMETERS:  Name                - Ascii name of this event
413  *
414  * RETURN:      Event number (integer index)
415  *
416  * DESCRIPTION: Saves the current time with this event
417  *
418  ******************************************************************************/
419 
420 UINT8
421 UtBeginEvent (
422     char                    *Name)
423 {
424 
425     if (AslGbl_NextEvent >= ASL_NUM_EVENTS)
426     {
427         AcpiOsPrintf ("Ran out of compiler event structs!\n");
428         return (AslGbl_NextEvent);
429     }
430 
431     /* Init event with current (start) time */
432 
433     AslGbl_Events[AslGbl_NextEvent].StartTime = AcpiOsGetTimer ();
434     AslGbl_Events[AslGbl_NextEvent].EventName = Name;
435     AslGbl_Events[AslGbl_NextEvent].Valid = TRUE;
436     return (AslGbl_NextEvent++);
437 }
438 
439 
440 /*******************************************************************************
441  *
442  * FUNCTION:    UtEndEvent
443  *
444  * PARAMETERS:  Event               - Event number (integer index)
445  *
446  * RETURN:      None
447  *
448  * DESCRIPTION: Saves the current time (end time) with this event
449  *
450  ******************************************************************************/
451 
452 void
453 UtEndEvent (
454     UINT8                   Event)
455 {
456 
457     if (Event >= ASL_NUM_EVENTS)
458     {
459         return;
460     }
461 
462     /* Insert end time for event */
463 
464     AslGbl_Events[Event].EndTime = AcpiOsGetTimer ();
465 }
466 
467 
468 /*******************************************************************************
469  *
470  * FUNCTION:    DbgPrint
471  *
472  * PARAMETERS:  Type                - Type of output
473  *              Fmt                 - Printf format string
474  *              ...                 - variable printf list
475  *
476  * RETURN:      None
477  *
478  * DESCRIPTION: Conditional print statement. Prints to stderr only if the
479  *              debug flag is set.
480  *
481  ******************************************************************************/
482 
483 void
484 DbgPrint (
485     UINT32                  Type,
486     char                    *Fmt,
487     ...)
488 {
489     va_list                 Args;
490 
491 
492     if (!AslGbl_DebugFlag)
493     {
494         return;
495     }
496 
497     if ((Type == ASL_PARSE_OUTPUT) &&
498         (!(AslCompilerdebug)))
499     {
500         return;
501     }
502 
503     va_start (Args, Fmt);
504     (void) vfprintf (stderr, Fmt, Args);
505     va_end (Args);
506     return;
507 }
508 
509 
510 /*******************************************************************************
511  *
512  * FUNCTION:    UtSetParseOpName
513  *
514  * PARAMETERS:  Op                  - Parse op to be named.
515  *
516  * RETURN:      None
517  *
518  * DESCRIPTION: Insert the ascii name of the parse opcode
519  *
520  ******************************************************************************/
521 
522 void
523 UtSetParseOpName (
524     ACPI_PARSE_OBJECT       *Op)
525 {
526 
527     AcpiUtSafeStrncpy (Op->Asl.ParseOpName, UtGetOpName (Op->Asl.ParseOpcode),
528         ACPI_MAX_PARSEOP_NAME);
529 }
530 
531 
532 /*******************************************************************************
533  *
534  * FUNCTION:    UtDisplayOneSummary
535  *
536  * PARAMETERS:  FileID              - ID of outpout file
537  *
538  * RETURN:      None
539  *
540  * DESCRIPTION: Display compilation statistics for one input file
541  *
542  ******************************************************************************/
543 
544 void
545 UtDisplayOneSummary (
546     UINT32                  FileId,
547     BOOLEAN                 DisplayErrorSummary)
548 {
549     UINT32                  i;
550     ASL_GLOBAL_FILE_NODE    *FileNode;
551     BOOLEAN                 DisplayAMLSummary;
552 
553 
554     DisplayAMLSummary =
555         !AslGbl_PreprocessOnly && !AslGbl_ParserErrorDetected &&
556         ((AslGbl_ExceptionCount[ASL_ERROR] == 0) || AslGbl_IgnoreErrors) &&
557         AslGbl_Files[ASL_FILE_AML_OUTPUT].Handle;
558 
559     if (FileId != ASL_FILE_STDOUT)
560     {
561         /* Compiler name and version number */
562 
563         FlPrintFile (FileId, "%s version %X\n\n",
564             ASL_COMPILER_NAME, (UINT32) ACPI_CA_VERSION);
565     }
566 
567     /* Summary of main input and output files */
568 
569     FileNode = FlGetCurrentFileNode ();
570 
571     if (FileNode->ParserErrorDetected)
572     {
573         FlPrintFile (FileId,
574             "%-14s %s - Compilation aborted due to parser-detected syntax error(s)\n",
575             "Input file:", AslGbl_Files[ASL_FILE_INPUT].Filename);
576     }
577     else if (FileNode->FileType == ASL_INPUT_TYPE_ASCII_DATA)
578     {
579         FlPrintFile (FileId,
580             "%-14s %s - %7u bytes %6u fields %8u source lines\n",
581             "Table Input:",
582             AslGbl_Files[ASL_FILE_INPUT].Filename,
583             FileNode->OriginalInputFileSize, FileNode->TotalFields,
584             FileNode->TotalLineCount);
585 
586         FlPrintFile (FileId,
587             "%-14s %s - %7u bytes\n",
588             "Binary Output:",
589             AslGbl_Files[ASL_FILE_AML_OUTPUT].Filename, FileNode->OutputByteLength);
590     }
591     else if (FileNode->FileType == ASL_INPUT_TYPE_ASCII_ASL)
592     {
593         FlPrintFile (FileId,
594             "%-14s %s - %7u bytes %6u keywords %6u source lines\n",
595             "ASL Input:",
596             AslGbl_Files[ASL_FILE_INPUT].Filename,
597             FileNode->OriginalInputFileSize,
598             FileNode->TotalKeywords,
599             FileNode->TotalLineCount);
600 
601         /* AML summary */
602 
603         if (DisplayAMLSummary)
604         {
605             FlPrintFile (FileId,
606                 "%-14s %s - %7u bytes %6u opcodes  %6u named objects\n",
607                 "AML Output:",
608                 AslGbl_Files[ASL_FILE_AML_OUTPUT].Filename,
609                 FlGetFileSize (ASL_FILE_AML_OUTPUT),
610                 FileNode->TotalExecutableOpcodes,
611                 FileNode->TotalNamedObjects);
612         }
613     }
614 
615     /* Display summary of any optional files */
616 
617     for (i = ASL_FILE_SOURCE_OUTPUT; i <= ASL_MAX_FILE_TYPE; i++)
618     {
619         if (!AslGbl_Files[i].Filename || !AslGbl_Files[i].Handle)
620         {
621             continue;
622         }
623 
624         /* .SRC is a temp file unless specifically requested */
625 
626         if ((i == ASL_FILE_SOURCE_OUTPUT) && (!AslGbl_SourceOutputFlag))
627         {
628             continue;
629         }
630 
631         /* .PRE is the preprocessor intermediate file */
632 
633         if ((i == ASL_FILE_PREPROCESSOR)  && (!AslGbl_KeepPreprocessorTempFile))
634         {
635             continue;
636         }
637 
638         FlPrintFile (FileId, "%-14s %s - %7u bytes\n",
639             AslGbl_FileDescs[i].ShortDescription,
640             AslGbl_Files[i].Filename, FlGetFileSize (i));
641     }
642 
643 
644     /*
645      * Optionally emit an error summary for a file. This is used to enhance the
646      * appearance of listing files.
647      */
648     if (DisplayErrorSummary)
649     {
650         UtDisplayErrorSummary (FileId);
651     }
652 }
653 
654 
655 /*******************************************************************************
656  *
657  * FUNCTION:    UtDisplayErrorSummary
658  *
659  * PARAMETERS:  FileID              - ID of outpout file
660  *
661  * RETURN:      None
662  *
663  * DESCRIPTION: Display compilation statistics for all input files
664  *
665  ******************************************************************************/
666 
667 static void
668 UtDisplayErrorSummary (
669     UINT32                  FileId)
670 {
671     BOOLEAN                 ErrorDetected;
672 
673 
674     ErrorDetected = AslGbl_ParserErrorDetected ||
675         ((AslGbl_ExceptionCount[ASL_ERROR] > 0) && !AslGbl_IgnoreErrors);
676 
677     if (ErrorDetected)
678     {
679         FlPrintFile (FileId, "\nCompilation failed. ");
680     }
681     else
682     {
683         FlPrintFile (FileId, "\nCompilation successful. ");
684     }
685 
686     FlPrintFile (FileId,
687         "%u Errors, %u Warnings, %u Remarks",
688         AslGbl_ExceptionCount[ASL_ERROR],
689         AslGbl_ExceptionCount[ASL_WARNING] +
690             AslGbl_ExceptionCount[ASL_WARNING2] +
691             AslGbl_ExceptionCount[ASL_WARNING3],
692         AslGbl_ExceptionCount[ASL_REMARK]);
693 
694     if (AslGbl_FileType != ASL_INPUT_TYPE_ASCII_DATA)
695     {
696         if (AslGbl_ParserErrorDetected)
697         {
698             FlPrintFile (FileId,
699                 "\nNo AML files were generated due to syntax error(s)\n");
700             return;
701         }
702         else if (ErrorDetected)
703         {
704             FlPrintFile (FileId,
705                 "\nNo AML files were generated due to compiler error(s)\n");
706             return;
707         }
708 
709         FlPrintFile (FileId, ", %u Optimizations",
710             AslGbl_ExceptionCount[ASL_OPTIMIZATION]);
711 
712         if (AslGbl_TotalFolds)
713         {
714             FlPrintFile (FileId, ", %u Constants Folded", AslGbl_TotalFolds);
715         }
716     }
717 
718     FlPrintFile (FileId, "\n");
719 }
720 
721 
722 /*******************************************************************************
723  *
724  * FUNCTION:    UtDisplaySummary
725  *
726  * PARAMETERS:  FileID              - ID of outpout file
727  *
728  * RETURN:      None
729  *
730  * DESCRIPTION: Display compilation statistics for all input files
731  *
732  ******************************************************************************/
733 
734 void
735 UtDisplaySummary (
736     UINT32                  FileId)
737 {
738     ASL_GLOBAL_FILE_NODE    *Current = AslGbl_FilesList;
739 
740 
741     while (Current)
742     {
743         switch  (FlSwitchFileSet(Current->Files[ASL_FILE_INPUT].Filename))
744         {
745             case SWITCH_TO_SAME_FILE:
746             case SWITCH_TO_DIFFERENT_FILE:
747 
748                 UtDisplayOneSummary (FileId, FALSE);
749                 Current = Current->Next;
750                 break;
751 
752             case FILE_NOT_FOUND:
753             default:
754 
755                 Current = NULL;
756                 break;
757         }
758     }
759     UtDisplayErrorSummary (FileId);
760 }
761 
762 /*******************************************************************************
763  *
764  * FUNCTION:    UtCheckIntegerRange
765  *
766  * PARAMETERS:  Op                  - Integer parse node
767  *              LowValue            - Smallest allowed value
768  *              HighValue           - Largest allowed value
769  *
770  * RETURN:      Op if OK, otherwise NULL
771  *
772  * DESCRIPTION: Check integer for an allowable range
773  *
774  ******************************************************************************/
775 
776 ACPI_PARSE_OBJECT *
777 UtCheckIntegerRange (
778     ACPI_PARSE_OBJECT       *Op,
779     UINT32                  LowValue,
780     UINT32                  HighValue)
781 {
782 
783     if (!Op)
784     {
785         return (NULL);
786     }
787 
788     if ((Op->Asl.Value.Integer < LowValue) ||
789         (Op->Asl.Value.Integer > HighValue))
790     {
791         sprintf (AslGbl_MsgBuffer, "0x%X, allowable: 0x%X-0x%X",
792             (UINT32) Op->Asl.Value.Integer, LowValue, HighValue);
793 
794         AslError (ASL_ERROR, ASL_MSG_RANGE, Op, AslGbl_MsgBuffer);
795         return (NULL);
796     }
797 
798     return (Op);
799 }
800 
801 
802 /*******************************************************************************
803  *
804  * FUNCTION:    UtInternalizeName
805  *
806  * PARAMETERS:  ExternalName        - Name to convert
807  *              ConvertedName       - Where the converted name is returned
808  *
809  * RETURN:      Status
810  *
811  * DESCRIPTION: Convert an external (ASL) name to an internal (AML) name
812  *
813  ******************************************************************************/
814 
815 ACPI_STATUS
816 UtInternalizeName (
817     char                    *ExternalName,
818     char                    **ConvertedName)
819 {
820     ACPI_NAMESTRING_INFO    Info;
821     ACPI_STATUS             Status;
822 
823 
824     if (!ExternalName)
825     {
826         return (AE_OK);
827     }
828 
829     /* Get the length of the new internal name */
830 
831     Info.ExternalName = ExternalName;
832     AcpiNsGetInternalNameLength (&Info);
833 
834     /* We need a segment to store the internal name */
835 
836     Info.InternalName = UtLocalCacheCalloc (Info.Length);
837 
838     /* Build the name */
839 
840     Status = AcpiNsBuildInternalName (&Info);
841     if (ACPI_FAILURE (Status))
842     {
843         return (Status);
844     }
845 
846     *ConvertedName = Info.InternalName;
847     return (AE_OK);
848 }
849 
850 
851 /*******************************************************************************
852  *
853  * FUNCTION:    UtPadNameWithUnderscores
854  *
855  * PARAMETERS:  NameSeg             - Input nameseg
856  *              PaddedNameSeg       - Output padded nameseg
857  *
858  * RETURN:      Padded nameseg.
859  *
860  * DESCRIPTION: Pads a NameSeg with underscores if necessary to form a full
861  *              ACPI_NAME.
862  *
863  ******************************************************************************/
864 
865 static void
866 UtPadNameWithUnderscores (
867     char                    *NameSeg,
868     char                    *PaddedNameSeg)
869 {
870     UINT32                  i;
871 
872 
873     for (i = 0; (i < ACPI_NAMESEG_SIZE); i++)
874     {
875         if (*NameSeg)
876         {
877             *PaddedNameSeg = *NameSeg;
878             NameSeg++;
879         }
880         else
881         {
882             *PaddedNameSeg = '_';
883         }
884 
885         PaddedNameSeg++;
886     }
887 }
888 
889 
890 /*******************************************************************************
891  *
892  * FUNCTION:    UtAttachNameseg
893  *
894  * PARAMETERS:  Op                  - Parent parse node
895  *              Name                - Full ExternalName
896  *
897  * RETURN:      None; Sets the NameSeg field in parent node
898  *
899  * DESCRIPTION: Extract the last nameseg of the ExternalName and store it
900  *              in the NameSeg field of the Op.
901  *
902  ******************************************************************************/
903 
904 static void
905 UtAttachNameseg (
906     ACPI_PARSE_OBJECT       *Op,
907     char                    *Name)
908 {
909     char                    *NameSeg;
910     char                    PaddedNameSeg[4];
911 
912 
913     if (!Name)
914     {
915         return;
916     }
917 
918     /* Look for the last dot in the namepath */
919 
920     NameSeg = strrchr (Name, '.');
921     if (NameSeg)
922     {
923         /* Found last dot, we have also found the final nameseg */
924 
925         NameSeg++;
926         UtPadNameWithUnderscores (NameSeg, PaddedNameSeg);
927     }
928     else
929     {
930         /* No dots in the namepath, there is only a single nameseg. */
931         /* Handle prefixes */
932 
933         while (ACPI_IS_ROOT_PREFIX (*Name) ||
934                ACPI_IS_PARENT_PREFIX (*Name))
935         {
936             Name++;
937         }
938 
939         /* Remaining string should be one single nameseg */
940 
941         UtPadNameWithUnderscores (Name, PaddedNameSeg);
942     }
943 
944     ACPI_COPY_NAMESEG (Op->Asl.NameSeg, PaddedNameSeg);
945 }
946 
947 
948 /*******************************************************************************
949  *
950  * FUNCTION:    UtAttachNamepathToOwner
951  *
952  * PARAMETERS:  Op                  - Parent parse node
953  *              NameOp              - Node that contains the name
954  *
955  * RETURN:      Sets the ExternalName and Namepath in the parent node
956  *
957  * DESCRIPTION: Store the name in two forms in the parent node: The original
958  *              (external) name, and the internalized name that is used within
959  *              the ACPI namespace manager.
960  *
961  ******************************************************************************/
962 
963 void
964 UtAttachNamepathToOwner (
965     ACPI_PARSE_OBJECT       *Op,
966     ACPI_PARSE_OBJECT       *NameOp)
967 {
968     ACPI_STATUS             Status;
969 
970 
971     /* Full external path */
972 
973     Op->Asl.ExternalName = NameOp->Asl.Value.String;
974 
975     /* Save the NameOp for possible error reporting later */
976 
977     Op->Asl.ParentMethod = (void *) NameOp;
978 
979     /* Last nameseg of the path */
980 
981     UtAttachNameseg (Op, Op->Asl.ExternalName);
982 
983     /* Create internalized path */
984 
985     Status = UtInternalizeName (NameOp->Asl.Value.String, &Op->Asl.Namepath);
986     if (ACPI_FAILURE (Status))
987     {
988         /* TBD: abort on no memory */
989     }
990 }
991 
992 
993 /*******************************************************************************
994  *
995  * FUNCTION:    UtNameContainsAllPrefix
996  *
997  * PARAMETERS:  Op                  - Op containing NameString
998  *
999  * RETURN:      NameString consists of all ^ characters
1000  *
1001  * DESCRIPTION: Determine if this Op contains a name segment that consists of
1002  *              all '^' characters.
1003  *
1004  ******************************************************************************/
1005 
1006 BOOLEAN
1007 UtNameContainsAllPrefix (
1008     ACPI_PARSE_OBJECT       *Op)
1009 {
1010     UINT32                  Length = Op->Asl.AmlLength;
1011     UINT32                  i;
1012 
1013     for (i = 0; i < Length; i++)
1014     {
1015         if (Op->Asl.Value.String[i] != '^')
1016         {
1017             return (FALSE);
1018         }
1019     }
1020 
1021     return (TRUE);
1022 }
1023 
1024 /*******************************************************************************
1025  *
1026  * FUNCTION:    UtDoConstant
1027  *
1028  * PARAMETERS:  String              - Hex/Decimal/Octal
1029  *
1030  * RETURN:      Converted Integer
1031  *
1032  * DESCRIPTION: Convert a string to an integer, with overflow/error checking.
1033  *
1034  ******************************************************************************/
1035 
1036 UINT64
1037 UtDoConstant (
1038     char                    *String)
1039 {
1040     ACPI_STATUS             Status;
1041     UINT64                  ConvertedInteger;
1042     char                    ErrBuf[64];
1043 
1044 
1045     Status = AcpiUtStrtoul64 (String, &ConvertedInteger);
1046     if (ACPI_FAILURE (Status))
1047     {
1048         sprintf (ErrBuf, "While creating 64-bit constant: %s\n",
1049             AcpiFormatException (Status));
1050 
1051         AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, AslGbl_CurrentLineNumber,
1052             AslGbl_LogicalLineNumber, AslGbl_CurrentLineOffset,
1053             AslGbl_CurrentColumn, AslGbl_Files[ASL_FILE_INPUT].Filename, ErrBuf);
1054     }
1055 
1056     return (ConvertedInteger);
1057 }
1058 
1059 
1060 /******************************************************************************
1061  *
1062  * FUNCTION:    AcpiUtStrdup
1063  *
1064  * PARAMETERS:  String1             - string to duplicate
1065  *
1066  * RETURN:      int that signifies string relationship. Zero means strings
1067  *              are equal.
1068  *
1069  * DESCRIPTION: Duplicate the string using UtCacheAlloc to avoid manual memory
1070  *              reclamation.
1071  *
1072  ******************************************************************************/
1073 
1074 char *
1075 AcpiUtStrdup (
1076     char                    *String)
1077 {
1078     char                    *NewString = (char *) UtLocalCalloc (strlen (String) + 1);
1079 
1080 
1081     strcpy (NewString, String);
1082     return (NewString);
1083 }
1084 
1085 
1086 /******************************************************************************
1087  *
1088  * FUNCTION:    AcpiUtStrcat
1089  *
1090  * PARAMETERS:  String1
1091  *              String2
1092  *
1093  * RETURN:      New string with String1 concatenated with String2
1094  *
1095  * DESCRIPTION: Concatenate string1 and string2
1096  *
1097  ******************************************************************************/
1098 
1099 char *
1100 AcpiUtStrcat (
1101     char                    *String1,
1102     char                    *String2)
1103 {
1104     UINT32                  String1Length = strlen (String1);
1105     char                    *NewString = (char *) UtLocalCalloc (strlen (String1) + strlen (String2) + 1);
1106 
1107     strcpy (NewString, String1);
1108     strcpy (NewString + String1Length, String2);
1109     return (NewString);
1110 }
1111