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