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