]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/dev/acpica/compiler/aslerror.c
Import tzdata 2018c
[FreeBSD/FreeBSD.git] / sys / contrib / dev / acpica / compiler / aslerror.c
1 /******************************************************************************
2  *
3  * Module Name: aslerror - Error handling and statistics
4  *
5  *****************************************************************************/
6
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2018, 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
154 #define _COMPONENT          ACPI_COMPILER
155         ACPI_MODULE_NAME    ("aslerror")
156
157 /* Local prototypes */
158
159 static void
160 AeAddToErrorLog (
161     ASL_ERROR_MSG           *Enode);
162
163 static BOOLEAN
164 AslIsExceptionExpected (
165     UINT8                   Level,
166     UINT16                  MessageId);
167
168 static BOOLEAN
169 AslIsExceptionDisabled (
170     UINT8                   Level,
171     UINT16                  MessageId);
172
173 static void AslInitEnode (
174     ASL_ERROR_MSG           **Enode,
175     UINT8                   Level,
176     UINT16                  MessageId,
177     UINT32                  LineNumber,
178     UINT32                  LogicalLineNumber,
179     UINT32                  LogicalByteOffset,
180     UINT32                  Column,
181     char                    *Filename,
182     char                    *Message,
183     char                    *SourceLine,
184     ASL_ERROR_MSG           *SubError);
185
186 static void
187 AslLogNewError (
188     UINT8                   Level,
189     UINT16                  MessageId,
190     UINT32                  LineNumber,
191     UINT32                  LogicalLineNumber,
192     UINT32                  LogicalByteOffset,
193     UINT32                  Column,
194     char                    *Filename,
195     char                    *Message,
196     char                    *SourceLine,
197     ASL_ERROR_MSG           *SubError);
198
199 static void
200 AePrintSubError (
201     FILE                    *OutputFile,
202     ASL_ERROR_MSG           *Enode);
203
204
205 /*******************************************************************************
206  *
207  * FUNCTION:    AslAbort
208  *
209  * PARAMETERS:  None
210  *
211  * RETURN:      None
212  *
213  * DESCRIPTION: Dump the error log and abort the compiler. Used for serious
214  *              I/O errors.
215  *
216  ******************************************************************************/
217
218 void
219 AslAbort (
220     void)
221 {
222
223     AePrintErrorLog (ASL_FILE_STDERR);
224     if (Gbl_DebugFlag)
225     {
226         /* Print error summary to stdout also */
227
228         AePrintErrorLog (ASL_FILE_STDOUT);
229     }
230
231     exit (1);
232 }
233
234
235 /*******************************************************************************
236  *
237  * FUNCTION:    AeClearErrorLog
238  *
239  * PARAMETERS:  None
240  *
241  * RETURN:      None
242  *
243  * DESCRIPTION: Empty the error list
244  *
245  ******************************************************************************/
246
247 void
248 AeClearErrorLog (
249     void)
250 {
251     ASL_ERROR_MSG           *Enode = Gbl_ErrorLog;
252     ASL_ERROR_MSG           *Next;
253
254
255     /* Walk the error node list */
256
257     while (Enode)
258     {
259         Next = Enode->Next;
260         ACPI_FREE (Enode);
261         Enode = Next;
262     }
263
264     Gbl_ErrorLog = NULL;
265 }
266
267
268 /*******************************************************************************
269  *
270  * FUNCTION:    AeAddToErrorLog
271  *
272  * PARAMETERS:  Enode       - An error node to add to the log
273  *
274  * RETURN:      None
275  *
276  * DESCRIPTION: Add a new error node to the error log. The error log is
277  *              ordered by the "logical" line number (cumulative line number
278  *              including all include files.)
279  *
280  ******************************************************************************/
281
282 static void
283 AeAddToErrorLog (
284     ASL_ERROR_MSG           *Enode)
285 {
286     ASL_ERROR_MSG           *Next;
287     ASL_ERROR_MSG           *Prev;
288
289
290     /* If Gbl_ErrorLog is null, this is the first error node */
291
292     if (!Gbl_ErrorLog)
293     {
294         Gbl_ErrorLog = Enode;
295         return;
296     }
297
298     /*
299      * Walk error list until we find a line number greater than ours.
300      * List is sorted according to line number.
301      */
302     Prev = NULL;
303     Next = Gbl_ErrorLog;
304
305     while ((Next) && (Next->LogicalLineNumber <= Enode->LogicalLineNumber))
306     {
307         Prev = Next;
308         Next = Next->Next;
309     }
310
311     /* Found our place in the list */
312
313     Enode->Next = Next;
314
315     if (Prev)
316     {
317         Prev->Next = Enode;
318     }
319     else
320     {
321         Gbl_ErrorLog = Enode;
322     }
323 }
324
325
326 /*******************************************************************************
327  *
328  * FUNCTION:    AeDecodeErrorMessageId
329  *
330  * PARAMETERS:  OutputFile      - Output file
331  *              Enode           - Error node to print
332  *              PrematureEOF    - True = PrematureEOF has been reached
333  *              Total           - Total legth of line
334  *
335  * RETURN:      None
336  *
337  * DESCRIPTION: Print the source line of an error.
338  *
339  ******************************************************************************/
340
341 static void
342 AeDecodeErrorMessageId (
343     FILE                    *OutputFile,
344     ASL_ERROR_MSG           *Enode,
345     BOOLEAN                 PrematureEOF,
346     UINT32                  Total)
347 {
348     UINT32                  MsgLength;
349     const char              *MainMessage;
350     char                    *ExtraMessage;
351     UINT32                  SourceColumn;
352     UINT32                  ErrorColumn;
353
354
355     fprintf (OutputFile, "%s %4.4d -",
356         AeDecodeExceptionLevel (Enode->Level),
357         AeBuildFullExceptionCode (Enode->Level, Enode->MessageId));
358
359     MainMessage = AeDecodeMessageId (Enode->MessageId);
360     ExtraMessage = Enode->Message;
361
362     /* If a NULL line number, just print the decoded message */
363
364     if (!Enode->LineNumber)
365     {
366         fprintf (OutputFile, " %s %s\n\n", MainMessage, ExtraMessage);
367         return;
368     }
369
370     MsgLength = strlen (MainMessage);
371     if (MsgLength == 0)
372     {
373         /* Use the secondary/extra message as main message */
374
375         MainMessage = Enode->Message;
376         if (!MainMessage)
377         {
378             MainMessage = "";
379         }
380
381         MsgLength = strlen (MainMessage);
382         ExtraMessage = NULL;
383     }
384
385     if (Gbl_VerboseErrors && !PrematureEOF)
386     {
387         if (Total >= 256)
388         {
389             fprintf (OutputFile, "    %s",
390                 MainMessage);
391         }
392         else
393         {
394             SourceColumn = Enode->Column + Enode->FilenameLength + 6 + 2;
395             ErrorColumn = ASL_ERROR_LEVEL_LENGTH + 5 + 2 + 1;
396
397             if ((MsgLength + ErrorColumn) < (SourceColumn - 1))
398             {
399                 fprintf (OutputFile, "%*s%s",
400                     (int) ((SourceColumn - 1) - ErrorColumn),
401                     MainMessage, " ^ ");
402             }
403             else
404             {
405                 fprintf (OutputFile, "%*s %s",
406                     (int) ((SourceColumn - ErrorColumn) + 1), "^",
407                     MainMessage);
408             }
409         }
410     }
411     else
412     {
413         fprintf (OutputFile, " %s", MainMessage);
414     }
415
416     /* Print the extra info message if present */
417
418     if (ExtraMessage)
419     {
420         fprintf (OutputFile, " (%s)", ExtraMessage);
421     }
422
423     if (PrematureEOF)
424     {
425         fprintf (OutputFile, " and premature End-Of-File");
426     }
427
428     fprintf (OutputFile, "\n");
429     if (Gbl_VerboseErrors && !Enode->SubError)
430     {
431         fprintf (OutputFile, "\n");
432     }
433 }
434
435
436 /*******************************************************************************
437  *
438  * FUNCTION:    AePrintErrorSourceLine
439  *
440  * PARAMETERS:  OutputFile      - Output file
441  *              Enode           - Error node to print
442  *              PrematureEOF    - True = PrematureEOF has been reached
443  *              Total           - amount of characters printed so far
444  *
445  *
446  * RETURN:      Status
447  *
448  * DESCRIPTION: Print the source line of an error.
449  *
450  ******************************************************************************/
451
452 static ACPI_STATUS
453 AePrintErrorSourceLine (
454     FILE                    *OutputFile,
455     ASL_ERROR_MSG           *Enode,
456     BOOLEAN                 *PrematureEOF,
457     UINT32                  *Total)
458 {
459     UINT8                   SourceByte;
460     int                     Actual;
461     size_t                  RActual;
462     FILE                    *SourceFile = NULL;
463     long                    FileSize;
464
465
466     if (!Enode->SourceLine)
467     {
468         /*
469          * Use the merged header/source file if present, otherwise
470          * use input file
471          */
472         SourceFile = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
473         if (!SourceFile)
474         {
475             SourceFile = Gbl_Files[ASL_FILE_INPUT].Handle;
476         }
477
478         if (SourceFile)
479         {
480             /* Determine if the error occurred at source file EOF */
481
482             fseek (SourceFile, 0, SEEK_END);
483             FileSize = ftell (SourceFile);
484
485             if ((long) Enode->LogicalByteOffset >= FileSize)
486             {
487                 *PrematureEOF = TRUE;
488             }
489         }
490         else
491         {
492             fprintf (OutputFile,
493                 "[*** iASL: Source File Does not exist ***]\n");
494             return AE_IO_ERROR;
495         }
496     }
497
498     /* Print filename and line number if present and valid */
499
500     if (Gbl_VerboseErrors)
501     {
502         fprintf (OutputFile, "%-8s", Enode->Filename);
503
504         if (Enode->SourceLine && Enode->LineNumber)
505         {
506             fprintf (OutputFile, " %6u: %s",
507                 Enode->LineNumber, Enode->SourceLine);
508         }
509         else if (Enode->LineNumber)
510         {
511             fprintf (OutputFile, " %6u: ", Enode->LineNumber);
512
513             /*
514              * If not at EOF, get the corresponding source code line
515              * and display it. Don't attempt this if we have a
516              * premature EOF condition.
517              */
518             if (*PrematureEOF)
519             {
520                 fprintf (OutputFile, "\n");
521                 return AE_OK;
522             }
523             /*
524              * Seek to the offset in the combined source file,
525              * read the source line, and write it to the output.
526              */
527             Actual = fseek (SourceFile,
528                 (long) Enode->LogicalByteOffset, (int) SEEK_SET);
529             if (Actual)
530             {
531                 fprintf (OutputFile,
532                     "[*** iASL: Seek error on source code temp file %s ***]",
533                     Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
534
535                 fprintf (OutputFile, "\n");
536                 return AE_OK;
537             }
538             RActual = fread (&SourceByte, 1, 1, SourceFile);
539             if (RActual != 1)
540             {
541                 fprintf (OutputFile,
542                     "[*** iASL: Read error on source code temp file %s ***]",
543                     Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
544                 return AE_IO_ERROR;
545             }
546                 /* Read/write the source line, up to the maximum line length */
547
548             while (RActual && SourceByte && (SourceByte != '\n'))
549             {
550                 if (*Total < 256)
551                 {
552                     /* After the max line length, we will just read the line, no write */
553
554                     if (fwrite (&SourceByte, 1, 1, OutputFile) != 1)
555                     {
556                         printf ("[*** iASL: Write error on output file ***]\n");
557                         return AE_IO_ERROR;
558                     }
559                 }
560                 else if (*Total == 256)
561                 {
562                     fprintf (OutputFile,
563                         "\n[*** iASL: Very long input line, message below refers to column %u ***]",
564                         Enode->Column);
565                 }
566
567                 RActual = fread (&SourceByte, 1, 1, SourceFile);
568                 if (RActual != 1)
569                 {
570                     fprintf (OutputFile,
571                         "[*** iASL: Read error on source code temp file %s ***]",
572                         Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
573
574                     return AE_IO_ERROR;
575                 }
576                 *Total += 1;
577             }
578
579             fprintf (OutputFile, "\n");
580         }
581     }
582     else
583     {
584         /*
585          * Less verbose version of the error message, enabled via the
586          * -vi switch. The format is compatible with MS Visual Studio.
587          */
588         fprintf (OutputFile, "%s", Enode->Filename);
589
590         if (Enode->LineNumber)
591         {
592             fprintf (OutputFile, "(%u) : ",
593                 Enode->LineNumber);
594         }
595     }
596
597     return AE_OK;
598 }
599
600 /*******************************************************************************
601  *
602  * FUNCTION:    AePrintException
603  *
604  * PARAMETERS:  FileId          - ID of output file
605  *              Enode           - Error node to print
606  *              Header          - Additional text before each message
607  *
608  * RETURN:      None
609  *
610  * DESCRIPTION: Print the contents of an error node.
611  *
612  * NOTE:        We don't use the FlxxxFile I/O functions here because on error
613  *              they abort the compiler and call this function!  Since we
614  *              are reporting errors here, we ignore most output errors and
615  *              just try to get out as much as we can.
616  *
617  ******************************************************************************/
618
619 void
620 AePrintException (
621     UINT32                  FileId,
622     ASL_ERROR_MSG           *Enode,
623     char                    *Header)
624 {
625     FILE                    *OutputFile;
626     BOOLEAN                 PrematureEOF = FALSE;
627     UINT32                  Total = 0;
628     ACPI_STATUS             Status;
629     ASL_ERROR_MSG           *Child = Enode->SubError;
630
631
632     if (Gbl_NoErrors)
633     {
634         return;
635     }
636
637     /*
638      * Only listing files have a header, and remarks/optimizations
639      * are always output
640      */
641     if (!Header)
642     {
643         /* Ignore remarks if requested */
644
645         switch (Enode->Level)
646         {
647         case ASL_WARNING:
648         case ASL_WARNING2:
649         case ASL_WARNING3:
650
651             if (!Gbl_DisplayWarnings)
652             {
653                 return;
654             }
655             break;
656
657         case ASL_REMARK:
658
659             if (!Gbl_DisplayRemarks)
660             {
661                 return;
662             }
663             break;
664
665         case ASL_OPTIMIZATION:
666
667             if (!Gbl_DisplayOptimizations)
668             {
669                 return;
670             }
671             break;
672
673         default:
674
675             break;
676         }
677     }
678
679     /* Get the various required file handles */
680
681     OutputFile = Gbl_Files[FileId].Handle;
682
683     if (Header)
684     {
685         fprintf (OutputFile, "%s", Header);
686     }
687
688     if (!Enode->Filename)
689     {
690         AeDecodeErrorMessageId (OutputFile, Enode, PrematureEOF, Total);
691         return;
692     }
693
694     Status = AePrintErrorSourceLine (OutputFile, Enode, &PrematureEOF, &Total);
695     if (ACPI_FAILURE (Status))
696     {
697         return;
698     }
699
700     /* If a NULL message ID, just print the raw message */
701
702     if (Enode->MessageId == 0)
703     {
704         fprintf (OutputFile, "%s\n", Enode->Message);
705         return;
706     }
707
708     AeDecodeErrorMessageId (OutputFile, Enode, PrematureEOF, Total);
709
710     while (Child)
711     {
712         fprintf (OutputFile, "\n");
713         AePrintSubError (OutputFile, Child);
714         Child = Child->SubError;
715     }
716 }
717
718
719 /*******************************************************************************
720  *
721  * FUNCTION:    AePrintSubError
722  *
723  * PARAMETERS:  OutputFile      - Output file
724  *              Enode           - Error node to print
725  *
726  * RETURN:      None
727  *
728  * DESCRIPTION: Print the contents of an error nodes. This function is tailored
729  *              to print error nodes that are SubErrors within ASL_ERROR_MSG
730  *
731  ******************************************************************************/
732
733 static void
734 AePrintSubError (
735     FILE                    *OutputFile,
736     ASL_ERROR_MSG           *Enode)
737 {
738     UINT32                  Total = 0;
739     BOOLEAN                 PrematureEOF = FALSE;
740     const char              *MainMessage;
741
742
743     MainMessage = AeDecodeMessageId (Enode->MessageId);
744
745     fprintf (OutputFile, "    %s%s", MainMessage, "\n    ");
746     (void) AePrintErrorSourceLine (OutputFile, Enode, &PrematureEOF, &Total);
747     fprintf (OutputFile, "\n");
748 }
749
750
751 /*******************************************************************************
752  *
753  * FUNCTION:    AePrintErrorLog
754  *
755  * PARAMETERS:  FileId           - Where to output the error log
756  *
757  * RETURN:      None
758  *
759  * DESCRIPTION: Print the entire contents of the error log
760  *
761  ******************************************************************************/
762
763 void
764 AePrintErrorLog (
765     UINT32                  FileId)
766 {
767     ASL_ERROR_MSG           *Enode = Gbl_ErrorLog;
768
769
770     /* Walk the error node list */
771
772     while (Enode)
773     {
774         AePrintException (FileId, Enode, NULL);
775         Enode = Enode->Next;
776     }
777 }
778
779
780 /*******************************************************************************
781  *
782  * FUNCTION:    AslInitEnode
783  *
784  * PARAMETERS:  InputEnode          - Input Error node to initialize
785  *              Level               - Seriousness (Warning/error, etc.)
786  *              MessageId           - Index into global message buffer
787  *              CurrentLineNumber   - Actual file line number
788  *              LogicalLineNumber   - Cumulative line number
789  *              LogicalByteOffset   - Byte offset in source file
790  *              Column              - Column in current line
791  *              Filename            - source filename
792  *              ExtraMessage        - additional error message
793  *              SourceLine          - Line of error source code
794  *              SubError            - SubError of this InputEnode
795  *
796  * RETURN:      None
797  *
798  * DESCRIPTION: Initialize an Error node
799  *
800  ******************************************************************************/
801
802 static void AslInitEnode (
803     ASL_ERROR_MSG           **InputEnode,
804     UINT8                   Level,
805     UINT16                  MessageId,
806     UINT32                  LineNumber,
807     UINT32                  LogicalLineNumber,
808     UINT32                  LogicalByteOffset,
809     UINT32                  Column,
810     char                    *Filename,
811     char                    *ExtraMessage,
812     char                    *SourceLine,
813     ASL_ERROR_MSG           *SubError)
814 {
815     ASL_ERROR_MSG           *Enode;
816
817
818     *InputEnode = UtLocalCalloc (sizeof (ASL_ERROR_MSG));
819     Enode = *InputEnode;
820     Enode->Level                = Level;
821     Enode->MessageId            = MessageId;
822     Enode->LineNumber           = LineNumber;
823     Enode->LogicalLineNumber    = LogicalLineNumber;
824     Enode->LogicalByteOffset    = LogicalByteOffset;
825     Enode->Column               = Column;
826     Enode->SubError             = SubError;
827     Enode->Message              = NULL;
828     Enode->SourceLine           = NULL;
829     Enode->Filename             = NULL;
830
831     if (ExtraMessage)
832     {
833         /* Allocate a buffer for the message and a new error node */
834
835         Enode->Message = UtLocalCacheCalloc (strlen (ExtraMessage) + 1);
836
837         /* Keep a copy of the extra message */
838
839         strcpy (Enode->Message, ExtraMessage);
840     }
841
842     if (SourceLine)
843     {
844         Enode->SourceLine = UtLocalCalloc (strlen (SourceLine) + 1);
845         strcpy (Enode->SourceLine, SourceLine);
846     }
847
848
849     if (Filename)
850     {
851         Enode->Filename = Filename;
852         Enode->FilenameLength = strlen (Filename);
853         if (Enode->FilenameLength < 6)
854         {
855             Enode->FilenameLength = 6;
856         }
857     }
858 }
859
860
861 /*******************************************************************************
862  *
863  * FUNCTION:    AslCommonError2
864  *
865  * PARAMETERS:  Level               - Seriousness (Warning/error, etc.)
866  *              MessageId           - Index into global message buffer
867  *              LineNumber          - Actual file line number
868  *              Column              - Column in current line
869  *              SourceLine          - Actual source code line
870  *              Filename            - source filename
871  *              ExtraMessage        - additional error message
872  *
873  * RETURN:      None
874  *
875  * DESCRIPTION: Create a new error node and add it to the error log
876  *
877  ******************************************************************************/
878
879 void
880 AslCommonError2 (
881     UINT8                   Level,
882     UINT16                  MessageId,
883     UINT32                  LineNumber,
884     UINT32                  Column,
885     char                    *SourceLine,
886     char                    *Filename,
887     char                    *ExtraMessage)
888 {
889     AslLogNewError (Level, MessageId, LineNumber, LineNumber, 0, Column,
890         Filename, ExtraMessage, SourceLine, NULL);
891 }
892
893
894 /*******************************************************************************
895  *
896  * FUNCTION:    AslCommonError
897  *
898  * PARAMETERS:  Level               - Seriousness (Warning/error, etc.)
899  *              MessageId           - Index into global message buffer
900  *              CurrentLineNumber   - Actual file line number
901  *              LogicalLineNumber   - Cumulative line number
902  *              LogicalByteOffset   - Byte offset in source file
903  *              Column              - Column in current line
904  *              Filename            - source filename
905  *              ExtraMessage        - additional error message
906  *
907  * RETURN:      None
908  *
909  * DESCRIPTION: Create a new error node and add it to the error log
910  *
911  ******************************************************************************/
912
913 void
914 AslCommonError (
915     UINT8                   Level,
916     UINT16                  MessageId,
917     UINT32                  CurrentLineNumber,
918     UINT32                  LogicalLineNumber,
919     UINT32                  LogicalByteOffset,
920     UINT32                  Column,
921     char                    *Filename,
922     char                    *ExtraMessage)
923 {
924     AslLogNewError (Level, MessageId, CurrentLineNumber, LogicalLineNumber,
925         LogicalByteOffset, Column, Filename, ExtraMessage,
926         NULL, NULL);
927 }
928
929
930 /*******************************************************************************
931  *
932  * FUNCTION:    AslLogNewError
933  *
934  * PARAMETERS:  Level               - Seriousness (Warning/error, etc.)
935  *              MessageId           - Index into global message buffer
936  *              CurrentLineNumber   - Actual file line number
937  *              LogicalLineNumber   - Cumulative line number
938  *              LogicalByteOffset   - Byte offset in source file
939  *              Column              - Column in current line
940  *              Filename            - source filename
941  *              Message             - additional error message
942  *              SourceLine          - Actual line of source code
943  *              SubError            - Sub-error associated with this error
944  *
945  * RETURN:      None
946  *
947  * DESCRIPTION: Create a new error node and add it to the error log
948  *
949  ******************************************************************************/
950 static void
951 AslLogNewError (
952     UINT8                   Level,
953     UINT16                  MessageId,
954     UINT32                  LineNumber,
955     UINT32                  LogicalLineNumber,
956     UINT32                  LogicalByteOffset,
957     UINT32                  Column,
958     char                    *Filename,
959     char                    *Message,
960     char                    *SourceLine,
961     ASL_ERROR_MSG           *SubError)
962 {
963     ASL_ERROR_MSG           *Enode = NULL;
964
965
966     AslInitEnode (&Enode, Level, MessageId, LineNumber, LogicalLineNumber,
967         LogicalByteOffset, Column, Filename, Message, SourceLine,
968         SubError);
969
970     /* Add the new node to the error node list */
971
972     AeAddToErrorLog (Enode);
973
974     if (Gbl_DebugFlag)
975     {
976         /* stderr is a file, send error to it immediately */
977
978         AePrintException (ASL_FILE_STDERR, Enode, NULL);
979     }
980
981     Gbl_ExceptionCount[Level]++;
982     if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
983     {
984         printf ("\nMaximum error count (%u) exceeded\n", ASL_MAX_ERROR_COUNT);
985
986         Gbl_SourceLine = 0;
987         Gbl_NextError = Gbl_ErrorLog;
988         CmCleanupAndExit ();
989         exit(1);
990     }
991
992     return;
993 }
994
995 /*******************************************************************************
996  *
997  * FUNCTION:    AslIsExceptionIgnored
998  *
999  * PARAMETERS:  Level           - Seriousness (Warning/error, etc.)
1000  *              MessageId       - Index into global message buffer
1001  *
1002  * RETURN:      BOOLEAN
1003  *
1004  * DESCRIPTION: Check if a particular exception is ignored. In this case it
1005  *              means that the exception is (expected or disabled.
1006  *
1007  ******************************************************************************/
1008
1009 BOOLEAN
1010 AslIsExceptionIgnored (
1011     UINT8                   Level,
1012     UINT16                  MessageId)
1013 {
1014     BOOLEAN                 ExceptionIgnored;
1015
1016
1017     /* Note: this allows exception to be disabled and expected */
1018
1019     ExceptionIgnored = AslIsExceptionDisabled (Level, MessageId);
1020     ExceptionIgnored |= AslIsExceptionExpected (Level, MessageId);
1021
1022     return (Gbl_AllExceptionsDisabled || ExceptionIgnored);
1023 }
1024
1025
1026 /*******************************************************************************
1027  *
1028  * FUNCTION:    AslCheckExpectException
1029  *
1030  * PARAMETERS:  none
1031  *
1032  * RETURN:      none
1033  *
1034  * DESCRIPTION: Check the global expected messages table and raise an error
1035  *              for each message that has not been received.
1036  *
1037  ******************************************************************************/
1038
1039 void
1040 AslCheckExpectedExceptions (
1041     void)
1042 {
1043     UINT8                   i;
1044
1045
1046     for (i = 0; i < Gbl_ExpectedMessagesIndex; ++i)
1047     {
1048         if (!Gbl_ExpectedMessages[i].MessageReceived)
1049         {
1050             AslError (ASL_ERROR, ASL_MSG_EXCEPTION_NOT_RECEIVED, NULL,
1051                 Gbl_ExpectedMessages[i].MessageIdStr);
1052         }
1053     }
1054 }
1055
1056
1057 /*******************************************************************************
1058  *
1059  * FUNCTION:    AslExpectException
1060  *
1061  * PARAMETERS:  MessageIdString     - ID of excepted exception during compile
1062  *
1063  * RETURN:      Status
1064  *
1065  * DESCRIPTION: Enter a message ID into the global expected messages table
1066  *              If these messages are not raised during the compilation, throw
1067  *              an error.
1068  *
1069  ******************************************************************************/
1070
1071 ACPI_STATUS
1072 AslExpectException (
1073     char                    *MessageIdString)
1074 {
1075     UINT32                  MessageId;
1076
1077
1078     /* Convert argument to an integer and validate it */
1079
1080     MessageId = (UINT32) strtoul (MessageIdString, NULL, 0);
1081
1082     if (MessageId > 6999)
1083     {
1084         printf ("\"%s\" is not a valid warning/remark/erro ID\n",
1085             MessageIdString);
1086         return (AE_BAD_PARAMETER);
1087     }
1088
1089     /* Insert value into the global expected message array */
1090
1091     if (Gbl_ExpectedMessagesIndex >= ASL_MAX_EXPECTED_MESSAGES)
1092     {
1093         printf ("Too many messages have been registered as expected (max %u)\n",
1094             ASL_MAX_DISABLED_MESSAGES);
1095         return (AE_LIMIT);
1096     }
1097
1098     Gbl_ExpectedMessages[Gbl_ExpectedMessagesIndex].MessageId = MessageId;
1099     Gbl_ExpectedMessages[Gbl_ExpectedMessagesIndex].MessageIdStr = MessageIdString;
1100     Gbl_ExpectedMessages[Gbl_ExpectedMessagesIndex].MessageReceived = FALSE;
1101     Gbl_ExpectedMessagesIndex++;
1102     return (AE_OK);
1103 }
1104
1105
1106 /*******************************************************************************
1107  *
1108  * FUNCTION:    AslDisableException
1109  *
1110  * PARAMETERS:  MessageIdString     - ID to be disabled
1111  *
1112  * RETURN:      Status
1113  *
1114  * DESCRIPTION: Enter a message ID into the global disabled messages table
1115  *
1116  ******************************************************************************/
1117
1118 ACPI_STATUS
1119 AslDisableException (
1120     char                    *MessageIdString)
1121 {
1122     UINT32                  MessageId;
1123
1124
1125     /* Convert argument to an integer and validate it */
1126
1127     MessageId = (UINT32) strtoul (MessageIdString, NULL, 0);
1128
1129     if ((MessageId < 2000) || (MessageId > 6999))
1130     {
1131         printf ("\"%s\" is not a valid warning/remark/error ID\n",
1132             MessageIdString);
1133         return (AE_BAD_PARAMETER);
1134     }
1135
1136     /* Insert value into the global disabled message array */
1137
1138     if (Gbl_DisabledMessagesIndex >= ASL_MAX_DISABLED_MESSAGES)
1139     {
1140         printf ("Too many messages have been disabled (max %u)\n",
1141             ASL_MAX_DISABLED_MESSAGES);
1142         return (AE_LIMIT);
1143     }
1144
1145     Gbl_DisabledMessages[Gbl_DisabledMessagesIndex] = MessageId;
1146     Gbl_DisabledMessagesIndex++;
1147     return (AE_OK);
1148 }
1149
1150
1151 /*******************************************************************************
1152  *
1153  * FUNCTION:    AslIsExceptionDisabled
1154  *
1155  * PARAMETERS:  Level           - Seriousness (Warning/error, etc.)
1156  *              MessageId       - Index into global message buffer
1157  *
1158  * RETURN:      TRUE if exception/message should be ignored
1159  *
1160  * DESCRIPTION: Check if the user has specified options such that this
1161  *              exception should be ignored
1162  *
1163  ******************************************************************************/
1164
1165 static BOOLEAN
1166 AslIsExceptionExpected (
1167     UINT8                   Level,
1168     UINT16                  MessageId)
1169 {
1170     UINT32                  EncodedMessageId;
1171     UINT32                  i;
1172
1173
1174     /* Mark this exception as received */
1175
1176     EncodedMessageId = AeBuildFullExceptionCode (Level, MessageId);
1177     for (i = 0; i < Gbl_ExpectedMessagesIndex; i++)
1178     {
1179         /* Simple implementation via fixed array */
1180
1181         if (EncodedMessageId == Gbl_ExpectedMessages[i].MessageId)
1182         {
1183             return (Gbl_ExpectedMessages[i].MessageReceived = TRUE);
1184         }
1185     }
1186
1187     return (FALSE);
1188 }
1189
1190
1191 /*******************************************************************************
1192  *
1193  * FUNCTION:    AslIsExceptionDisabled
1194  *
1195  * PARAMETERS:  Level               - Seriousness (Warning/error, etc.)
1196  *              MessageId           - Index into global message buffer
1197  *
1198  * RETURN:      TRUE if exception/message should be ignored
1199  *
1200  * DESCRIPTION: Check if the user has specified options such that this
1201  *              exception should be ignored
1202  *
1203  ******************************************************************************/
1204
1205 static BOOLEAN
1206 AslIsExceptionDisabled (
1207     UINT8                   Level,
1208     UINT16                  MessageId)
1209 {
1210     UINT32                  EncodedMessageId;
1211     UINT32                  i;
1212
1213
1214     switch (Level)
1215     {
1216     case ASL_WARNING2:
1217     case ASL_WARNING3:
1218
1219         /* Check for global disable via -w1/-w2/-w3 options */
1220
1221         if (Level > Gbl_WarningLevel)
1222         {
1223             return (TRUE);
1224         }
1225         /* Fall through */
1226
1227     case ASL_WARNING:
1228     case ASL_REMARK:
1229     case ASL_ERROR:
1230         /*
1231          * Ignore this error/warning/remark if it has been disabled by
1232          * the user (-vw option)
1233          */
1234         EncodedMessageId = AeBuildFullExceptionCode (Level, MessageId);
1235         for (i = 0; i < Gbl_DisabledMessagesIndex; i++)
1236         {
1237             /* Simple implementation via fixed array */
1238
1239             if (EncodedMessageId == Gbl_DisabledMessages[i])
1240             {
1241                 return (TRUE);
1242             }
1243         }
1244         break;
1245
1246     default:
1247         break;
1248     }
1249
1250     return (FALSE);
1251 }
1252
1253
1254 /*******************************************************************************
1255  *
1256  * FUNCTION:    AslDualParseOpError
1257  *
1258  * PARAMETERS:  Level           - Seriousness (Warning/error, etc.)
1259  *              MainMsgId       - Index into global message buffer
1260  *              MainOp          - Parse node where error happened
1261  *              MainMsg         - Message pertaining to the MainOp
1262  *              SubMsgId        - Index into global message buffer
1263  *              SubOp           - Additional parse node for better message
1264  *              SubMsg          - Message pertainint to SubOp
1265  *
1266  *
1267  * RETURN:      None
1268  *
1269  * DESCRIPTION: Main error reporting routine for the ASL compiler for error
1270  *              messages that point to multiple parse objects.
1271  *
1272  ******************************************************************************/
1273
1274 void
1275 AslDualParseOpError (
1276     UINT8                   Level,
1277     UINT16                  MainMsgId,
1278     ACPI_PARSE_OBJECT       *MainOp,
1279     char                    *MainMsg,
1280     UINT16                  SubMsgId,
1281     ACPI_PARSE_OBJECT       *SubOp,
1282     char                    *SubMsg)
1283 {
1284     ASL_ERROR_MSG           *SubEnode = NULL;
1285
1286
1287     /* Check if user wants to ignore this exception */
1288
1289     if (AslIsExceptionIgnored (Level, MainMsgId) || !MainOp)
1290     {
1291         return;
1292     }
1293
1294     if (SubOp)
1295     {
1296         AslInitEnode (&SubEnode, Level, SubMsgId, SubOp->Asl.LineNumber,
1297             SubOp->Asl.LogicalLineNumber, SubOp->Asl.LogicalByteOffset,
1298             SubOp->Asl.Column, SubOp->Asl.Filename, SubMsg,
1299             NULL, NULL);
1300     }
1301
1302     AslLogNewError (Level, MainMsgId, MainOp->Asl.LineNumber,
1303         MainOp->Asl.LogicalLineNumber, MainOp->Asl.LogicalByteOffset,
1304         MainOp->Asl.Column, MainOp->Asl.Filename, MainMsg,
1305         NULL, SubEnode);
1306 }
1307
1308
1309 /*******************************************************************************
1310  *
1311  * FUNCTION:    AslError
1312  *
1313  * PARAMETERS:  Level               - Seriousness (Warning/error, etc.)
1314  *              MessageId           - Index into global message buffer
1315  *              Op                  - Parse node where error happened
1316  *              ExtraMessage        - additional error message
1317  *
1318  * RETURN:      None
1319  *
1320  * DESCRIPTION: Main error reporting routine for the ASL compiler (all code
1321  *              except the parser.)
1322  *
1323  ******************************************************************************/
1324
1325 void
1326 AslError (
1327     UINT8                   Level,
1328     UINT16                  MessageId,
1329     ACPI_PARSE_OBJECT       *Op,
1330     char                    *ExtraMessage)
1331 {
1332     if (Op)
1333     {
1334         AslCommonError (Level, MessageId, Op->Asl.LineNumber,
1335             Op->Asl.LogicalLineNumber,
1336             Op->Asl.LogicalByteOffset,
1337             Op->Asl.Column,
1338             Op->Asl.Filename, ExtraMessage);
1339     }
1340     else
1341     {
1342         AslCommonError (Level, MessageId, 0,
1343             0, 0, 0, NULL, ExtraMessage);
1344     }
1345 }
1346
1347
1348 /*******************************************************************************
1349  *
1350  * FUNCTION:    AslCoreSubsystemError
1351  *
1352  * PARAMETERS:  Op                  - Parse node where error happened
1353  *              Status              - The ACPICA Exception
1354  *              ExtraMessage        - additional error message
1355  *              Abort               - TRUE -> Abort compilation
1356  *
1357  * RETURN:      None
1358  *
1359  * DESCRIPTION: Error reporting routine for exceptions returned by the ACPICA
1360  *              core subsystem.
1361  *
1362  ******************************************************************************/
1363
1364 void
1365 AslCoreSubsystemError (
1366     ACPI_PARSE_OBJECT       *Op,
1367     ACPI_STATUS             Status,
1368     char                    *ExtraMessage,
1369     BOOLEAN                 Abort)
1370 {
1371
1372     sprintf (MsgBuffer, "%s %s", AcpiFormatException (Status), ExtraMessage);
1373
1374     if (Op)
1375     {
1376         AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION,
1377             Op->Asl.LineNumber,
1378             Op->Asl.LogicalLineNumber,
1379             Op->Asl.LogicalByteOffset,
1380             Op->Asl.Column,
1381             Op->Asl.Filename, MsgBuffer);
1382     }
1383     else
1384     {
1385         AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION,
1386             0, 0, 0, 0, NULL, MsgBuffer);
1387     }
1388
1389     if (Abort)
1390     {
1391         AslAbort ();
1392     }
1393 }
1394
1395
1396 /*******************************************************************************
1397  *
1398  * FUNCTION:    AslCompilererror
1399  *
1400  * PARAMETERS:  CompilerMessage         - Error message from the parser
1401  *
1402  * RETURN:      Status (0 for now)
1403  *
1404  * DESCRIPTION: Report an error situation discovered in a production
1405  *              NOTE: don't change the name of this function, it is called
1406  *              from the auto-generated parser.
1407  *
1408  ******************************************************************************/
1409
1410 int
1411 AslCompilererror (
1412     const char              *CompilerMessage)
1413 {
1414
1415     Gbl_SyntaxError++;
1416
1417     AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, Gbl_CurrentLineNumber,
1418         Gbl_LogicalLineNumber, Gbl_CurrentLineOffset,
1419         Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename,
1420         ACPI_CAST_PTR (char, CompilerMessage));
1421
1422     return (0);
1423 }