Sync ACPICA with Intel's version 20170831.
[dragonfly.git] / sys / contrib / dev / acpica / source / compiler / aslerror.c
blob56b5cabb947617ef965208bd0490bf2e97e25f40
1 /******************************************************************************
3 * Module Name: aslerror - Error handling and statistics
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
12 * All rights reserved.
14 * 2. License
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.
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
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;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
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.
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.
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.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
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.
80 * 4. Disclaimer and Export Compliance
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.
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.
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.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
117 * following license:
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.
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.
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.
150 *****************************************************************************/
152 #include "aslcompiler.h"
154 #define _COMPONENT ACPI_COMPILER
155 ACPI_MODULE_NAME ("aslerror")
157 /* Local prototypes */
159 static void
160 AeAddToErrorLog (
161 ASL_ERROR_MSG *Enode);
163 static BOOLEAN
164 AslIsExceptionExpected (
165 UINT8 Level,
166 UINT16 MessageId);
168 static BOOLEAN
169 AslIsExceptionDisabled (
170 UINT8 Level,
171 UINT16 MessageId);
174 /*******************************************************************************
176 * FUNCTION: AslAbort
178 * PARAMETERS: None
180 * RETURN: None
182 * DESCRIPTION: Dump the error log and abort the compiler. Used for serious
183 * I/O errors.
185 ******************************************************************************/
187 void
188 AslAbort (
189 void)
192 AePrintErrorLog (ASL_FILE_STDERR);
193 if (Gbl_DebugFlag)
195 /* Print error summary to stdout also */
197 AePrintErrorLog (ASL_FILE_STDOUT);
200 exit (1);
204 /*******************************************************************************
206 * FUNCTION: AeClearErrorLog
208 * PARAMETERS: None
210 * RETURN: None
212 * DESCRIPTION: Empty the error list
214 ******************************************************************************/
216 void
217 AeClearErrorLog (
218 void)
220 ASL_ERROR_MSG *Enode = Gbl_ErrorLog;
221 ASL_ERROR_MSG *Next;
223 /* Walk the error node list */
225 while (Enode)
227 Next = Enode->Next;
228 ACPI_FREE (Enode);
229 Enode = Next;
232 Gbl_ErrorLog = NULL;
236 /*******************************************************************************
238 * FUNCTION: AeAddToErrorLog
240 * PARAMETERS: Enode - An error node to add to the log
242 * RETURN: None
244 * DESCRIPTION: Add a new error node to the error log. The error log is
245 * ordered by the "logical" line number (cumulative line number
246 * including all include files.)
248 ******************************************************************************/
250 static void
251 AeAddToErrorLog (
252 ASL_ERROR_MSG *Enode)
254 ASL_ERROR_MSG *Next;
255 ASL_ERROR_MSG *Prev;
258 /* If Gbl_ErrorLog is null, this is the first error node */
260 if (!Gbl_ErrorLog)
262 Gbl_ErrorLog = Enode;
263 return;
267 * Walk error list until we find a line number greater than ours.
268 * List is sorted according to line number.
270 Prev = NULL;
271 Next = Gbl_ErrorLog;
273 while ((Next) &&
274 (Next->LogicalLineNumber <= Enode->LogicalLineNumber))
276 Prev = Next;
277 Next = Next->Next;
280 /* Found our place in the list */
282 Enode->Next = Next;
284 if (Prev)
286 Prev->Next = Enode;
288 else
290 Gbl_ErrorLog = Enode;
295 /*******************************************************************************
297 * FUNCTION: AePrintException
299 * PARAMETERS: FileId - ID of output file
300 * Enode - Error node to print
301 * Header - Additional text before each message
303 * RETURN: None
305 * DESCRIPTION: Print the contents of an error node.
307 * NOTE: We don't use the FlxxxFile I/O functions here because on error
308 * they abort the compiler and call this function! Since we
309 * are reporting errors here, we ignore most output errors and
310 * just try to get out as much as we can.
312 ******************************************************************************/
314 void
315 AePrintException (
316 UINT32 FileId,
317 ASL_ERROR_MSG *Enode,
318 char *Header)
320 UINT8 SourceByte;
321 int Actual;
322 size_t RActual;
323 UINT32 MsgLength;
324 const char *MainMessage;
325 char *ExtraMessage;
326 UINT32 SourceColumn;
327 UINT32 ErrorColumn;
328 FILE *OutputFile;
329 FILE *SourceFile = NULL;
330 long FileSize;
331 BOOLEAN PrematureEOF = FALSE;
332 UINT32 Total = 0;
335 if (Gbl_NoErrors)
337 return;
341 * Only listing files have a header, and remarks/optimizations
342 * are always output
344 if (!Header)
346 /* Ignore remarks if requested */
348 switch (Enode->Level)
350 case ASL_WARNING:
351 case ASL_WARNING2:
352 case ASL_WARNING3:
354 if (!Gbl_DisplayWarnings)
356 return;
358 break;
360 case ASL_REMARK:
362 if (!Gbl_DisplayRemarks)
364 return;
366 break;
368 case ASL_OPTIMIZATION:
370 if (!Gbl_DisplayOptimizations)
372 return;
374 break;
376 default:
378 break;
382 /* Get the various required file handles */
384 OutputFile = Gbl_Files[FileId].Handle;
386 if (!Enode->SourceLine)
389 * Use the merged header/source file if present, otherwise
390 * use input file
392 SourceFile = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
393 if (!SourceFile)
395 SourceFile = Gbl_Files[ASL_FILE_INPUT].Handle;
398 if (SourceFile)
400 /* Determine if the error occurred at source file EOF */
402 fseek (SourceFile, 0, SEEK_END);
403 FileSize = ftell (SourceFile);
405 if ((long) Enode->LogicalByteOffset >= FileSize)
407 PrematureEOF = TRUE;
412 if (Header)
414 fprintf (OutputFile, "%s", Header);
417 /* Print filename and line number if present and valid */
419 if (Enode->Filename)
421 if (Gbl_VerboseErrors)
423 fprintf (OutputFile, "%-8s", Enode->Filename);
425 if (Enode->LineNumber)
427 if (Enode->SourceLine)
429 fprintf (OutputFile, " %6u: %s",
430 Enode->LineNumber, Enode->SourceLine);
432 else
434 fprintf (OutputFile, " %6u: ", Enode->LineNumber);
437 * If not at EOF, get the corresponding source code line
438 * and display it. Don't attempt this if we have a
439 * premature EOF condition.
441 if (!PrematureEOF)
444 * Seek to the offset in the combined source file,
445 * read the source line, and write it to the output.
447 Actual = fseek (SourceFile,
448 (long) Enode->LogicalByteOffset, (int) SEEK_SET);
449 if (Actual)
451 fprintf (OutputFile,
452 "[*** iASL: Seek error on source code temp file %s ***]",
453 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
455 else
457 RActual = fread (&SourceByte, 1, 1, SourceFile);
458 if (RActual != 1)
460 fprintf (OutputFile,
461 "[*** iASL: Read error on source code temp file %s ***]",
462 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
464 else
466 /* Read/write the source line, up to the maximum line length */
468 while (RActual && SourceByte && (SourceByte != '\n'))
470 if (Total < 256)
472 /* After the max line length, we will just read the line, no write */
474 if (fwrite (&SourceByte, 1, 1, OutputFile) != 1)
476 printf ("[*** iASL: Write error on output file ***]\n");
477 return;
480 else if (Total == 256)
482 fprintf (OutputFile,
483 "\n[*** iASL: Very long input line, message below refers to column %u ***]",
484 Enode->Column);
487 RActual = fread (&SourceByte, 1, 1, SourceFile);
488 if (RActual != 1)
490 fprintf (OutputFile,
491 "[*** iASL: Read error on source code temp file %s ***]",
492 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
493 return;
495 Total++;
501 fprintf (OutputFile, "\n");
505 else
508 * Less verbose version of the error message, enabled via the
509 * -vi switch. The format is compatible with MS Visual Studio.
511 fprintf (OutputFile, "%s", Enode->Filename);
513 if (Enode->LineNumber)
515 fprintf (OutputFile, "(%u) : ",
516 Enode->LineNumber);
521 /* If a NULL message ID, just print the raw message */
523 if (Enode->MessageId == 0)
525 fprintf (OutputFile, "%s\n", Enode->Message);
526 return;
529 /* Decode the message ID */
531 fprintf (OutputFile, "%s %4.4d -",
532 AeDecodeExceptionLevel (Enode->Level),
533 AeBuildFullExceptionCode (Enode->Level, Enode->MessageId));
535 MainMessage = AeDecodeMessageId (Enode->MessageId);
536 ExtraMessage = Enode->Message;
538 /* If a NULL line number, just print the decoded message */
540 if (!Enode->LineNumber)
542 fprintf (OutputFile, " %s %s\n\n", MainMessage, ExtraMessage);
543 return;
546 MsgLength = strlen (MainMessage);
547 if (MsgLength == 0)
549 /* Use the secondary/extra message as main message */
551 MainMessage = Enode->Message;
552 if (!MainMessage)
554 MainMessage = "";
557 MsgLength = strlen (MainMessage);
558 ExtraMessage = NULL;
561 if (Gbl_VerboseErrors && !PrematureEOF)
563 if (Total >= 256)
565 fprintf (OutputFile, " %s",
566 MainMessage);
568 else
570 SourceColumn = Enode->Column + Enode->FilenameLength + 6 + 2;
571 ErrorColumn = ASL_ERROR_LEVEL_LENGTH + 5 + 2 + 1;
573 if ((MsgLength + ErrorColumn) < (SourceColumn - 1))
575 fprintf (OutputFile, "%*s%s",
576 (int) ((SourceColumn - 1) - ErrorColumn),
577 MainMessage, " ^ ");
579 else
581 fprintf (OutputFile, "%*s %s",
582 (int) ((SourceColumn - ErrorColumn) + 1), "^",
583 MainMessage);
587 else
589 fprintf (OutputFile, " %s", MainMessage);
592 /* Print the extra info message if present */
594 if (ExtraMessage)
596 fprintf (OutputFile, " (%s)", ExtraMessage);
599 if (PrematureEOF)
601 fprintf (OutputFile, " and premature End-Of-File");
604 fprintf (OutputFile, "\n");
605 if (Gbl_VerboseErrors)
607 fprintf (OutputFile, "\n");
612 /*******************************************************************************
614 * FUNCTION: AePrintErrorLog
616 * PARAMETERS: FileId - Where to output the error log
618 * RETURN: None
620 * DESCRIPTION: Print the entire contents of the error log
622 ******************************************************************************/
624 void
625 AePrintErrorLog (
626 UINT32 FileId)
628 ASL_ERROR_MSG *Enode = Gbl_ErrorLog;
631 /* Walk the error node list */
633 while (Enode)
635 AePrintException (FileId, Enode, NULL);
636 Enode = Enode->Next;
641 /*******************************************************************************
643 * FUNCTION: AslCommonError2
645 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
646 * MessageId - Index into global message buffer
647 * LineNumber - Actual file line number
648 * Column - Column in current line
649 * SourceLine - Actual source code line
650 * Filename - source filename
651 * ExtraMessage - additional error message
653 * RETURN: None
655 * DESCRIPTION: Create a new error node and add it to the error log
657 ******************************************************************************/
659 void
660 AslCommonError2 (
661 UINT8 Level,
662 UINT16 MessageId,
663 UINT32 LineNumber,
664 UINT32 Column,
665 char *SourceLine,
666 char *Filename,
667 char *ExtraMessage)
669 char *MessageBuffer = NULL;
670 char *LineBuffer;
671 ASL_ERROR_MSG *Enode;
674 Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG));
676 if (ExtraMessage)
678 /* Allocate a buffer for the message and a new error node */
680 MessageBuffer = UtStringCacheCalloc (strlen (ExtraMessage) + 1);
682 /* Keep a copy of the extra message */
684 strcpy (MessageBuffer, ExtraMessage);
687 LineBuffer = UtLocalCalloc (strlen (SourceLine) + 1);
688 strcpy (LineBuffer, SourceLine);
690 /* Initialize the error node */
692 if (Filename)
694 Enode->Filename = Filename;
695 Enode->FilenameLength = strlen (Filename);
696 if (Enode->FilenameLength < 6)
698 Enode->FilenameLength = 6;
702 Enode->MessageId = MessageId;
703 Enode->Level = Level;
704 Enode->LineNumber = LineNumber;
705 Enode->LogicalLineNumber = LineNumber;
706 Enode->LogicalByteOffset = 0;
707 Enode->Column = Column;
708 Enode->Message = MessageBuffer;
709 Enode->SourceLine = LineBuffer;
711 /* Add the new node to the error node list */
713 AeAddToErrorLog (Enode);
715 if (Gbl_DebugFlag)
717 /* stderr is a file, send error to it immediately */
719 AePrintException (ASL_FILE_STDERR, Enode, NULL);
722 Gbl_ExceptionCount[Level]++;
726 /*******************************************************************************
728 * FUNCTION: AslCommonError
730 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
731 * MessageId - Index into global message buffer
732 * CurrentLineNumber - Actual file line number
733 * LogicalLineNumber - Cumulative line number
734 * LogicalByteOffset - Byte offset in source file
735 * Column - Column in current line
736 * Filename - source filename
737 * ExtraMessage - additional error message
739 * RETURN: None
741 * DESCRIPTION: Create a new error node and add it to the error log
743 ******************************************************************************/
745 void
746 AslCommonError (
747 UINT8 Level,
748 UINT16 MessageId,
749 UINT32 CurrentLineNumber,
750 UINT32 LogicalLineNumber,
751 UINT32 LogicalByteOffset,
752 UINT32 Column,
753 char *Filename,
754 char *ExtraMessage)
756 char *MessageBuffer = NULL;
757 ASL_ERROR_MSG *Enode;
760 if (AslIsExceptionIgnored (Level, MessageId))
762 return;
765 Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG));
767 if (ExtraMessage)
769 /* Allocate a buffer for the message and a new error node */
771 MessageBuffer = UtStringCacheCalloc (strlen (ExtraMessage) + 1);
773 /* Keep a copy of the extra message */
775 strcpy (MessageBuffer, ExtraMessage);
778 /* Initialize the error node */
780 if (Filename)
782 Enode->Filename = Filename;
783 Enode->FilenameLength = strlen (Filename);
784 if (Enode->FilenameLength < 6)
786 Enode->FilenameLength = 6;
790 Enode->MessageId = MessageId;
791 Enode->Level = Level;
792 Enode->LineNumber = CurrentLineNumber;
793 Enode->LogicalLineNumber = LogicalLineNumber;
794 Enode->LogicalByteOffset = LogicalByteOffset;
795 Enode->Column = Column;
796 Enode->Message = MessageBuffer;
797 Enode->SourceLine = NULL;
799 /* Add the new node to the error node list */
801 AeAddToErrorLog (Enode);
803 if (Gbl_DebugFlag)
805 /* stderr is a file, send error to it immediately */
807 AePrintException (ASL_FILE_STDERR, Enode, NULL);
810 Gbl_ExceptionCount[Level]++;
811 if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
813 printf ("\nMaximum error count (%u) exceeded\n", ASL_MAX_ERROR_COUNT);
815 Gbl_SourceLine = 0;
816 Gbl_NextError = Gbl_ErrorLog;
817 CmCleanupAndExit ();
818 exit(1);
821 return;
824 /*******************************************************************************
826 * FUNCTION: AslIsExceptionIgnored
828 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
829 * MessageId - Index into global message buffer
831 * RETURN: BOOLEAN
833 * DESCRIPTION: Check if a particular exception is ignored. In this case it
834 * means that the exception is (expected or disabled.
836 ******************************************************************************/
838 BOOLEAN
839 AslIsExceptionIgnored (
840 UINT8 Level,
841 UINT16 MessageId)
843 BOOLEAN ExceptionIgnored;
846 /* Note: this allows exception to be disabled and expected */
848 ExceptionIgnored = AslIsExceptionDisabled (Level, MessageId);
849 ExceptionIgnored |= AslIsExceptionExpected (Level, MessageId);
851 return (Gbl_AllExceptionsDisabled || ExceptionIgnored);
855 /*******************************************************************************
857 * FUNCTION: AslCheckExpectException
859 * PARAMETERS: none
861 * RETURN: none
863 * DESCRIPTION: Check the global expected messages table and raise an error
864 * for each message that has not been received.
866 ******************************************************************************/
868 void
869 AslCheckExpectedExceptions (
870 void)
872 UINT8 i;
874 for (i = 0; i < Gbl_ExpectedMessagesIndex; ++i)
876 if (!Gbl_ExpectedMessages[i].MessageReceived)
878 AslError (ASL_ERROR, ASL_MSG_EXCEPTION_NOT_RECEIVED, NULL,
879 Gbl_ExpectedMessages[i].MessageIdStr);
885 /*******************************************************************************
887 * FUNCTION: AslExpectException
889 * PARAMETERS: MessageIdString - ID of excepted exception during compile
891 * RETURN: Status
893 * DESCRIPTION: Enter a message ID into the global expected messages table
894 * If these messages are not raised during the compilation, throw
895 * an error.
897 ******************************************************************************/
899 ACPI_STATUS
900 AslExpectException (
901 char *MessageIdString)
903 UINT32 MessageId;
906 /* Convert argument to an integer and validate it */
908 MessageId = (UINT32) strtoul (MessageIdString, NULL, 0);
910 if (MessageId > 6999)
912 printf ("\"%s\" is not a valid warning/remark/erro ID\n",
913 MessageIdString);
914 return (AE_BAD_PARAMETER);
917 /* Insert value into the global expected message array */
919 if (Gbl_ExpectedMessagesIndex >= ASL_MAX_EXPECTED_MESSAGES)
921 printf ("Too many messages have been registered as expected (max %u)\n",
922 ASL_MAX_DISABLED_MESSAGES);
923 return (AE_LIMIT);
926 Gbl_ExpectedMessages[Gbl_ExpectedMessagesIndex].MessageId = MessageId;
927 Gbl_ExpectedMessages[Gbl_ExpectedMessagesIndex].MessageIdStr = MessageIdString;
928 Gbl_ExpectedMessages[Gbl_ExpectedMessagesIndex].MessageReceived = FALSE;
929 Gbl_ExpectedMessagesIndex++;
930 return (AE_OK);
934 /*******************************************************************************
936 * FUNCTION: AslDisableException
938 * PARAMETERS: MessageIdString - ID to be disabled
940 * RETURN: Status
942 * DESCRIPTION: Enter a message ID into the global disabled messages table
944 ******************************************************************************/
946 ACPI_STATUS
947 AslDisableException (
948 char *MessageIdString)
950 UINT32 MessageId;
953 /* Convert argument to an integer and validate it */
955 MessageId = (UINT32) strtoul (MessageIdString, NULL, 0);
957 if ((MessageId < 2000) || (MessageId > 6999))
959 printf ("\"%s\" is not a valid warning/remark/error ID\n",
960 MessageIdString);
961 return (AE_BAD_PARAMETER);
964 /* Insert value into the global disabled message array */
966 if (Gbl_DisabledMessagesIndex >= ASL_MAX_DISABLED_MESSAGES)
968 printf ("Too many messages have been disabled (max %u)\n",
969 ASL_MAX_DISABLED_MESSAGES);
970 return (AE_LIMIT);
973 Gbl_DisabledMessages[Gbl_DisabledMessagesIndex] = MessageId;
974 Gbl_DisabledMessagesIndex++;
975 return (AE_OK);
979 /*******************************************************************************
981 * FUNCTION: AslIsExceptionDisabled
983 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
984 * MessageId - Index into global message buffer
986 * RETURN: TRUE if exception/message should be ignored
988 * DESCRIPTION: Check if the user has specified options such that this
989 * exception should be ignored
991 ******************************************************************************/
993 static BOOLEAN
994 AslIsExceptionExpected (
995 UINT8 Level,
996 UINT16 MessageId)
998 UINT32 EncodedMessageId;
999 UINT32 i;
1003 * Mark this exception as received
1005 EncodedMessageId = AeBuildFullExceptionCode (Level, MessageId);
1006 for (i = 0; i < Gbl_ExpectedMessagesIndex; i++)
1008 /* Simple implementation via fixed array */
1010 if (EncodedMessageId == Gbl_ExpectedMessages[i].MessageId)
1012 return (Gbl_ExpectedMessages[i].MessageReceived = TRUE);
1016 return (FALSE);
1020 /*******************************************************************************
1022 * FUNCTION: AslIsExceptionDisabled
1024 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
1025 * MessageId - Index into global message buffer
1027 * RETURN: TRUE if exception/message should be ignored
1029 * DESCRIPTION: Check if the user has specified options such that this
1030 * exception should be ignored
1032 ******************************************************************************/
1034 static BOOLEAN
1035 AslIsExceptionDisabled (
1036 UINT8 Level,
1037 UINT16 MessageId)
1039 UINT32 EncodedMessageId;
1040 UINT32 i;
1043 switch (Level)
1045 case ASL_WARNING2:
1046 case ASL_WARNING3:
1048 /* Check for global disable via -w1/-w2/-w3 options */
1050 if (Level > Gbl_WarningLevel)
1052 return (TRUE);
1054 /* Fall through */
1056 case ASL_WARNING:
1057 case ASL_REMARK:
1058 case ASL_ERROR:
1060 * Ignore this error/warning/remark if it has been disabled by
1061 * the user (-vw option)
1063 EncodedMessageId = AeBuildFullExceptionCode (Level, MessageId);
1064 for (i = 0; i < Gbl_DisabledMessagesIndex; i++)
1066 /* Simple implementation via fixed array */
1068 if (EncodedMessageId == Gbl_DisabledMessages[i])
1070 return (TRUE);
1073 break;
1075 default:
1076 break;
1079 return (FALSE);
1083 /*******************************************************************************
1085 * FUNCTION: AslError
1087 * PARAMETERS: Level - Seriousness (Warning/error, etc.)
1088 * MessageId - Index into global message buffer
1089 * Op - Parse node where error happened
1090 * ExtraMessage - additional error message
1092 * RETURN: None
1094 * DESCRIPTION: Main error reporting routine for the ASL compiler (all code
1095 * except the parser.)
1097 ******************************************************************************/
1099 void
1100 AslError (
1101 UINT8 Level,
1102 UINT16 MessageId,
1103 ACPI_PARSE_OBJECT *Op,
1104 char *ExtraMessage)
1106 if (Op)
1108 AslCommonError (Level, MessageId, Op->Asl.LineNumber,
1109 Op->Asl.LogicalLineNumber,
1110 Op->Asl.LogicalByteOffset,
1111 Op->Asl.Column,
1112 Op->Asl.Filename, ExtraMessage);
1114 else
1116 AslCommonError (Level, MessageId, 0,
1117 0, 0, 0, NULL, ExtraMessage);
1122 /*******************************************************************************
1124 * FUNCTION: AslCoreSubsystemError
1126 * PARAMETERS: Op - Parse node where error happened
1127 * Status - The ACPICA Exception
1128 * ExtraMessage - additional error message
1129 * Abort - TRUE -> Abort compilation
1131 * RETURN: None
1133 * DESCRIPTION: Error reporting routine for exceptions returned by the ACPICA
1134 * core subsystem.
1136 ******************************************************************************/
1138 void
1139 AslCoreSubsystemError (
1140 ACPI_PARSE_OBJECT *Op,
1141 ACPI_STATUS Status,
1142 char *ExtraMessage,
1143 BOOLEAN Abort)
1146 sprintf (MsgBuffer, "%s %s", AcpiFormatException (Status), ExtraMessage);
1148 if (Op)
1150 AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION,
1151 Op->Asl.LineNumber,
1152 Op->Asl.LogicalLineNumber,
1153 Op->Asl.LogicalByteOffset,
1154 Op->Asl.Column,
1155 Op->Asl.Filename, MsgBuffer);
1157 else
1159 AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION,
1160 0, 0, 0, 0, NULL, MsgBuffer);
1163 if (Abort)
1165 AslAbort ();
1170 /*******************************************************************************
1172 * FUNCTION: AslCompilererror
1174 * PARAMETERS: CompilerMessage - Error message from the parser
1176 * RETURN: Status (0 for now)
1178 * DESCRIPTION: Report an error situation discovered in a production
1179 * NOTE: don't change the name of this function, it is called
1180 * from the auto-generated parser.
1182 ******************************************************************************/
1185 AslCompilererror (
1186 const char *CompilerMessage)
1189 Gbl_SyntaxError++;
1191 AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, Gbl_CurrentLineNumber,
1192 Gbl_LogicalLineNumber, Gbl_CurrentLineOffset,
1193 Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename,
1194 ACPI_CAST_PTR (char, CompilerMessage));
1196 return (0);