Path: blob/main/sys/contrib/dev/acpica/compiler/aslerror.c
48373 views
/******************************************************************************1*2* Module Name: aslerror - Error handling and statistics3*4*****************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#include <contrib/dev/acpica/compiler/aslcompiler.h>152153#define _COMPONENT ACPI_COMPILER154ACPI_MODULE_NAME ("aslerror")155156/* Local prototypes */157158static void159AeAddToErrorLog (160ASL_ERROR_MSG *Enode);161162static BOOLEAN163AslIsExceptionExpected (164char *Filename,165UINT32 LineNumber,166UINT8 Level,167UINT16 MessageId);168169static BOOLEAN170AslIsExceptionDisabled (171UINT8 Level,172UINT16 MessageId);173174static void175AslInitEnode (176ASL_ERROR_MSG **Enode,177UINT8 Level,178UINT16 MessageId,179UINT32 LineNumber,180UINT32 LogicalLineNumber,181UINT32 LogicalByteOffset,182UINT32 Column,183char *Filename,184char *Message,185char *SourceLine,186ASL_ERROR_MSG *SubError);187188static void189AslLogNewError (190UINT8 Level,191UINT16 MessageId,192UINT32 LineNumber,193UINT32 LogicalLineNumber,194UINT32 LogicalByteOffset,195UINT32 Column,196char *Filename,197char *Message,198char *SourceLine,199ASL_ERROR_MSG *SubError);200201static void202AePrintSubError (203FILE *OutputFile,204ASL_ERROR_MSG *Enode);205206static UINT8207GetModifiedLevel (208UINT8 Level,209UINT16 MessageId);210211212/*******************************************************************************213*214* FUNCTION: AslAbort215*216* PARAMETERS: None217*218* RETURN: None219*220* DESCRIPTION: Dump the error log and abort the compiler. Used for serious221* I/O errors.222*223******************************************************************************/224225void226AslAbort (227void)228{229230AePrintErrorLog (ASL_FILE_STDERR);231if (AslGbl_DebugFlag)232{233/* Print error summary to stdout also */234235AePrintErrorLog (ASL_FILE_STDOUT);236}237238exit (1);239}240241242/*******************************************************************************243*244* FUNCTION: AeClearErrorLog245*246* PARAMETERS: None247*248* RETURN: None249*250* DESCRIPTION: Empty the error list251*252******************************************************************************/253254void255AeClearErrorLog (256void)257{258ASL_ERROR_MSG *Enode = AslGbl_ErrorLog;259ASL_ERROR_MSG *Next;260261262/* Walk the error node list */263264while (Enode)265{266Next = Enode->Next;267ACPI_FREE (Enode);268Enode = Next;269}270271AslGbl_ErrorLog = NULL;272}273274275/*******************************************************************************276*277* FUNCTION: AeAddToErrorLog278*279* PARAMETERS: Enode - An error node to add to the log280*281* RETURN: None282*283* DESCRIPTION: Add a new error node to the error log. The error log is284* ordered by the "logical" line number (cumulative line number285* including all include files.)286*287******************************************************************************/288289static void290AeAddToErrorLog (291ASL_ERROR_MSG *Enode)292{293ASL_ERROR_MSG *Next;294ASL_ERROR_MSG *Prev;295296297/* If Gbl_ErrorLog is null, this is the first error node */298299if (!AslGbl_ErrorLog)300{301AslGbl_ErrorLog = Enode;302return;303}304305/*306* Walk error list until we find a line number greater than ours.307* List is sorted according to line number.308*/309Prev = NULL;310Next = AslGbl_ErrorLog;311312while ((Next) && (Next->LogicalLineNumber <= Enode->LogicalLineNumber))313{314Prev = Next;315Next = Next->Next;316}317318/* Found our place in the list */319320Enode->Next = Next;321322if (Prev)323{324Prev->Next = Enode;325}326else327{328AslGbl_ErrorLog = Enode;329}330}331332333/*******************************************************************************334*335* FUNCTION: AeDecodeErrorMessageId336*337* PARAMETERS: OutputFile - Output file338* Enode - Error node to print339* PrematureEOF - True = PrematureEOF has been reached340* Total - Total length of line341*342* RETURN: None343*344* DESCRIPTION: Print the source line of an error.345*346******************************************************************************/347348static void349AeDecodeErrorMessageId (350FILE *OutputFile,351ASL_ERROR_MSG *Enode,352BOOLEAN PrematureEOF,353UINT32 Total)354{355UINT32 MsgLength;356const char *MainMessage;357char *ExtraMessage;358UINT32 SourceColumn;359UINT32 ErrorColumn;360361362fprintf (OutputFile, "%s %4.4d -",363AeDecodeExceptionLevel (Enode->Level),364AeBuildFullExceptionCode (Enode->Level, Enode->MessageId));365366MainMessage = AeDecodeMessageId (Enode->MessageId);367ExtraMessage = Enode->Message;368369/* If a NULL line number, just print the decoded message */370371if (!Enode->LineNumber)372{373fprintf (OutputFile, " %s %s\n\n", MainMessage, ExtraMessage);374return;375}376377MsgLength = strlen (MainMessage);378if (MsgLength == 0)379{380/* Use the secondary/extra message as main message */381382MainMessage = Enode->Message;383if (!MainMessage)384{385MainMessage = "";386}387388MsgLength = strlen (MainMessage);389ExtraMessage = NULL;390}391392if (AslGbl_VerboseErrors && !PrematureEOF)393{394if (Total >= 256)395{396fprintf (OutputFile, " %s",397MainMessage);398}399else400{401SourceColumn = Enode->Column + Enode->FilenameLength + 6 + 2;402ErrorColumn = ASL_ERROR_LEVEL_LENGTH + 5 + 2 + 1;403404if ((MsgLength + ErrorColumn) < (SourceColumn - 1))405{406fprintf (OutputFile, "%*s%s",407(int) ((SourceColumn - 1) - ErrorColumn),408MainMessage, " ^ ");409}410else411{412fprintf (OutputFile, "%*s %s",413(int) ((SourceColumn - ErrorColumn) + 1), "^",414MainMessage);415}416}417}418else419{420fprintf (OutputFile, " %s", MainMessage);421}422423/* Print the extra info message if present */424425if (ExtraMessage)426{427fprintf (OutputFile, " (%s)", ExtraMessage);428}429430if (PrematureEOF)431{432fprintf (OutputFile, " and premature End-Of-File");433}434435fprintf (OutputFile, "\n");436if (AslGbl_VerboseErrors && !Enode->SubError)437{438fprintf (OutputFile, "\n");439}440}441442443/*******************************************************************************444*445* FUNCTION: AePrintErrorSourceLine446*447* PARAMETERS: OutputFile - Output file448* Enode - Error node to print449* PrematureEOF - True = PrematureEOF has been reached450* Total - Number of characters printed so far451*452*453* RETURN: Status454*455* DESCRIPTION: Print the source line of an error.456*457******************************************************************************/458459static ACPI_STATUS460AePrintErrorSourceLine (461FILE *OutputFile,462ASL_ERROR_MSG *Enode,463BOOLEAN *PrematureEOF,464UINT32 *Total)465{466UINT8 SourceByte;467int Actual;468size_t RActual;469FILE *SourceFile = NULL;470long FileSize;471472473if (!Enode->SourceLine)474{475/*476* Use the merged header/source file if present, otherwise477* use input file478*/479SourceFile = FlGetFileHandle (ASL_FILE_SOURCE_OUTPUT,480ASL_FILE_SOURCE_OUTPUT, Enode->SourceFilename);481if (!SourceFile)482{483SourceFile = FlGetFileHandle (ASL_FILE_INPUT,484ASL_FILE_INPUT, Enode->Filename);485}486487if (SourceFile)488{489/* Determine if the error occurred at source file EOF */490491fseek (SourceFile, 0, SEEK_END);492FileSize = ftell (SourceFile);493494if ((long) Enode->LogicalByteOffset >= FileSize)495{496*PrematureEOF = TRUE;497}498}499else500{501fprintf (OutputFile,502"[*** iASL: Source File Does not exist ***]\n");503return AE_IO_ERROR;504}505}506507/* Print filename and line number if present and valid */508509if (AslGbl_VerboseErrors)510{511fprintf (OutputFile, "%-8s", Enode->Filename);512513if (Enode->SourceLine && Enode->LineNumber)514{515fprintf (OutputFile, " %6u: %s",516Enode->LineNumber, Enode->SourceLine);517}518else if (Enode->LineNumber)519{520fprintf (OutputFile, " %6u: ", Enode->LineNumber);521522/*523* If not at EOF, get the corresponding source code line524* and display it. Don't attempt this if we have a525* premature EOF condition.526*/527if (*PrematureEOF)528{529fprintf (OutputFile, "\n");530return AE_OK;531}532533/*534* Seek to the offset in the combined source file,535* read the source line, and write it to the output.536*/537Actual = fseek (SourceFile,538(long) Enode->LogicalByteOffset, (int) SEEK_SET);539if (Actual)540{541fprintf (OutputFile,542"[*** iASL: Seek error on source code temp file %s ***]",543AslGbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);544545fprintf (OutputFile, "\n");546return AE_OK;547}548RActual = fread (&SourceByte, 1, 1, SourceFile);549if (RActual != 1)550{551fprintf (OutputFile,552"[*** iASL: Read error on source code temp file %s ***]",553AslGbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);554return AE_IO_ERROR;555}556557/* Read/write the source line, up to the maximum line length */558559while (RActual && SourceByte && (SourceByte != '\n'))560{561if (*Total < 256)562{563/* After the max line length, we will just read the line, no write */564565if (fwrite (&SourceByte, 1, 1, OutputFile) != 1)566{567printf ("[*** iASL: Write error on output file ***]\n");568return AE_IO_ERROR;569}570}571else if (*Total == 256)572{573fprintf (OutputFile,574"\n[*** iASL: Very long input line, message below refers to column %u ***]",575Enode->Column);576}577578RActual = fread (&SourceByte, 1, 1, SourceFile);579if (RActual != 1)580{581fprintf (OutputFile,582"[*** iASL: Read error on source code temp file %s ***]",583AslGbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);584585return AE_IO_ERROR;586}587*Total += 1;588}589590fprintf (OutputFile, "\n");591}592}593else594{595/*596* Less verbose version of the error message, enabled via the597* -vi switch. The format is compatible with MS Visual Studio.598*/599fprintf (OutputFile, "%s", Enode->Filename);600601if (Enode->LineNumber)602{603fprintf (OutputFile, "(%u) : ",604Enode->LineNumber);605}606}607608return AE_OK;609}610611/*******************************************************************************612*613* FUNCTION: AePrintException614*615* PARAMETERS: FileId - ID of output file616* Enode - Error node to print617* Header - Additional text before each message618*619* RETURN: None620*621* DESCRIPTION: Print the contents of an error node.622*623* NOTE: We don't use the FlxxxFile I/O functions here because on error624* they abort the compiler and call this function! Since we625* are reporting errors here, we ignore most output errors and626* just try to get out as much as we can.627*628******************************************************************************/629630void631AePrintException (632UINT32 FileId,633ASL_ERROR_MSG *Enode,634char *Header)635{636FILE *OutputFile;637BOOLEAN PrematureEOF = FALSE;638UINT32 Total = 0;639ACPI_STATUS Status;640ASL_ERROR_MSG *Child = Enode->SubError;641642643if (AslGbl_NoErrors)644{645return;646}647648/*649* Only listing files have a header, and remarks/optimizations650* are always output651*/652if (!Header)653{654/* Ignore remarks if requested */655656switch (Enode->Level)657{658case ASL_WARNING:659case ASL_WARNING2:660case ASL_WARNING3:661662if (!AslGbl_DisplayWarnings)663{664return;665}666break;667668case ASL_REMARK:669670if (!AslGbl_DisplayRemarks)671{672return;673}674break;675676case ASL_OPTIMIZATION:677678if (!AslGbl_DisplayOptimizations)679{680return;681}682break;683684default:685686break;687}688}689690/* Get the various required file handles */691692OutputFile = AslGbl_Files[FileId].Handle;693694if (Header)695{696fprintf (OutputFile, "%s", Header);697}698699if (!Enode->Filename)700{701AeDecodeErrorMessageId (OutputFile, Enode, PrematureEOF, Total);702return;703}704705Status = AePrintErrorSourceLine (OutputFile, Enode, &PrematureEOF, &Total);706if (ACPI_FAILURE (Status))707{708return;709}710711/* If a NULL message ID, just print the raw message */712713if (Enode->MessageId == 0)714{715fprintf (OutputFile, "%s\n", Enode->Message);716return;717}718719AeDecodeErrorMessageId (OutputFile, Enode, PrematureEOF, Total);720721while (Child)722{723fprintf (OutputFile, "\n");724AePrintSubError (OutputFile, Child);725Child = Child->SubError;726}727}728729730/*******************************************************************************731*732* FUNCTION: AePrintSubError733*734* PARAMETERS: OutputFile - Output file735* Enode - Error node to print736*737* RETURN: None738*739* DESCRIPTION: Print the contents of an error node. This function is tailored740* to print error nodes that are SubErrors within ASL_ERROR_MSG741*742******************************************************************************/743744static void745AePrintSubError (746FILE *OutputFile,747ASL_ERROR_MSG *Enode)748{749UINT32 Total = 0;750BOOLEAN PrematureEOF = FALSE;751const char *MainMessage;752753754MainMessage = AeDecodeMessageId (Enode->MessageId);755756fprintf (OutputFile, " %s", MainMessage);757758if (Enode->Message)759{760fprintf (OutputFile, "(%s)", Enode->Message);761}762763fprintf (OutputFile, "\n ");764(void) AePrintErrorSourceLine (OutputFile, Enode, &PrematureEOF, &Total);765fprintf (OutputFile, "\n");766}767768769/*******************************************************************************770*771* FUNCTION: AePrintErrorLog772*773* PARAMETERS: FileId - Where to output the error log774*775* RETURN: None776*777* DESCRIPTION: Print the entire contents of the error log778*779******************************************************************************/780781void782AePrintErrorLog (783UINT32 FileId)784{785ASL_ERROR_MSG *Enode = AslGbl_ErrorLog;786787788/* Walk the error node list */789790while (Enode)791{792AePrintException (FileId, Enode, NULL);793Enode = Enode->Next;794}795}796797798/*******************************************************************************799*800* FUNCTION: AslInitEnode801*802* PARAMETERS: InputEnode - Input Error node to initialize803* Level - Seriousness (Warning/error, etc.)804* MessageId - Index into global message buffer805* CurrentLineNumber - Actual file line number806* LogicalLineNumber - Cumulative line number807* LogicalByteOffset - Byte offset in source file808* Column - Column in current line809* Filename - Source filename810* ExtraMessage - Additional error message811* SourceLine - Line of error source code812* SubError - SubError of this InputEnode813*814* RETURN: None815*816* DESCRIPTION: Initialize an Error node817*818******************************************************************************/819820static void AslInitEnode (821ASL_ERROR_MSG **InputEnode,822UINT8 Level,823UINT16 MessageId,824UINT32 LineNumber,825UINT32 LogicalLineNumber,826UINT32 LogicalByteOffset,827UINT32 Column,828char *Filename,829char *ExtraMessage,830char *SourceLine,831ASL_ERROR_MSG *SubError)832{833ASL_ERROR_MSG *Enode;834ASL_GLOBAL_FILE_NODE *FileNode;835836837*InputEnode = UtLocalCalloc (sizeof (ASL_ERROR_MSG));838Enode = *InputEnode;839Enode->Level = Level;840Enode->MessageId = MessageId;841Enode->LineNumber = LineNumber;842Enode->LogicalLineNumber = LogicalLineNumber;843Enode->LogicalByteOffset = LogicalByteOffset;844Enode->Column = Column;845Enode->SubError = SubError;846Enode->Message = NULL;847Enode->SourceLine = NULL;848Enode->Filename = NULL;849850if (ExtraMessage)851{852/* Allocate a buffer for the message and a new error node */853854Enode->Message = UtLocalCacheCalloc (strlen (ExtraMessage) + 1);855856/* Keep a copy of the extra message */857858strcpy (Enode->Message, ExtraMessage);859}860861if (SourceLine)862{863Enode->SourceLine = UtLocalCalloc (strlen (SourceLine) + 1);864strcpy (Enode->SourceLine, SourceLine);865}866867868if (Filename)869{870Enode->Filename = Filename;871Enode->FilenameLength = strlen (Filename);872if (Enode->FilenameLength < 6)873{874Enode->FilenameLength = 6;875}876877/*878* Attempt to get the file node of the filename listed in the parse879* node. If the name doesn't exist in the global file node, it is880* because the file is included by #include or ASL include. In this881* case, get the current file node. The source output of the current882* file will contain the contents of the file listed in the parse node.883*/884FileNode = FlGetFileNode (ASL_FILE_INPUT, Filename);885if (!FileNode)886{887FileNode = FlGetCurrentFileNode ();888}889890Enode->SourceFilename =891FileNode->Files[ASL_FILE_SOURCE_OUTPUT].Filename;892}893}894895896/*******************************************************************************897*898* FUNCTION: AslCommonError2899*900* PARAMETERS: Level - Seriousness (Warning/error, etc.)901* MessageId - Index into global message buffer902* LineNumber - Actual file line number903* Column - Column in current line904* SourceLine - Actual source code line905* Filename - Source filename906* ExtraMessage - Additional error message907*908* RETURN: None909*910* DESCRIPTION: Create a new error node and add it to the error log911*912******************************************************************************/913914void915AslCommonError2 (916UINT8 Level,917UINT16 MessageId,918UINT32 LineNumber,919UINT32 Column,920char *SourceLine,921char *Filename,922char *ExtraMessage)923{924AslLogNewError (Level, MessageId, LineNumber, LineNumber, 0, Column,925Filename, ExtraMessage, SourceLine, NULL);926}927928929/*******************************************************************************930*931* FUNCTION: AslCommonError932*933* PARAMETERS: Level - Seriousness (Warning/error, etc.)934* MessageId - Index into global message buffer935* CurrentLineNumber - Actual file line number936* LogicalLineNumber - Cumulative line number937* LogicalByteOffset - Byte offset in source file938* Column - Column in current line939* Filename - Source filename940* ExtraMessage - Additional error message941*942* RETURN: None943*944* DESCRIPTION: Create a new error node and add it to the error log945*946******************************************************************************/947948void949AslCommonError (950UINT8 Level,951UINT16 MessageId,952UINT32 CurrentLineNumber,953UINT32 LogicalLineNumber,954UINT32 LogicalByteOffset,955UINT32 Column,956char *Filename,957char *ExtraMessage)958{959/* Check if user wants to ignore this exception */960961if (AslIsExceptionIgnored (Filename, LogicalLineNumber, Level, MessageId))962{963return;964}965966AslLogNewError (Level, MessageId, CurrentLineNumber, LogicalLineNumber,967LogicalByteOffset, Column, Filename, ExtraMessage,968NULL, NULL);969}970971972/*******************************************************************************973*974* FUNCTION: AslLogNewError975*976* PARAMETERS: Level - Seriousness (Warning/error, etc.)977* MessageId - Index into global message buffer978* CurrentLineNumber - Actual file line number979* LogicalLineNumber - Cumulative line number980* LogicalByteOffset - Byte offset in source file981* Column - Column in current line982* Filename - Source filename983* Message - Additional error message984* SourceLine - Actual line of source code985* SubError - Sub-error associated with this error986*987* RETURN: None988*989* DESCRIPTION: Create a new error node and add it to the error log990*991******************************************************************************/992static void993AslLogNewError (994UINT8 Level,995UINT16 MessageId,996UINT32 LineNumber,997UINT32 LogicalLineNumber,998UINT32 LogicalByteOffset,999UINT32 Column,1000char *Filename,1001char *Message,1002char *SourceLine,1003ASL_ERROR_MSG *SubError)1004{1005ASL_ERROR_MSG *Enode = NULL;1006UINT8 ModifiedLevel = GetModifiedLevel (Level, MessageId);100710081009AslInitEnode (&Enode, ModifiedLevel, MessageId, LineNumber,1010LogicalLineNumber, LogicalByteOffset, Column, Filename, Message,1011SourceLine, SubError);10121013/* Add the new node to the error node list */10141015AeAddToErrorLog (Enode);10161017if (AslGbl_DebugFlag)1018{1019/* stderr is a file, send error to it immediately */10201021AePrintException (ASL_FILE_STDERR, Enode, NULL);1022}10231024AslGbl_ExceptionCount[ModifiedLevel]++;1025if (!AslGbl_IgnoreErrors && AslGbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)1026{1027printf ("\nMaximum error count (%u) exceeded (aslerror.c)\n", ASL_MAX_ERROR_COUNT);10281029AslGbl_SourceLine = 0;1030AslGbl_NextError = AslGbl_ErrorLog;1031CmCleanupAndExit ();1032exit(1);1033}10341035return;1036}103710381039/*******************************************************************************1040*1041* FUNCTION: GetModifiedLevel1042*1043* PARAMETERS: Level - Seriousness (Warning/error, etc.)1044* MessageId - Index into global message buffer1045*1046* RETURN: UINT8 - Modified level1047*1048* DESCRIPTION: Get the modified level of exception codes that are reported as1049* errors from the -ww option.1050*1051******************************************************************************/10521053static UINT81054GetModifiedLevel (1055UINT8 Level,1056UINT16 MessageId)1057{1058UINT32 i;1059UINT16 ExceptionCode;106010611062ExceptionCode = AeBuildFullExceptionCode (Level, MessageId);10631064for (i = 0; i < AslGbl_ElevatedMessagesIndex; i++)1065{1066if (ExceptionCode == AslGbl_ElevatedMessages[i])1067{1068return (ASL_ERROR);1069}1070}10711072return (Level);1073}107410751076/*******************************************************************************1077*1078* FUNCTION: AslIsExceptionIgnored1079*1080* PARAMETERS: Level - Seriousness (Warning/error, etc.)1081* MessageId - Index into global message buffer1082*1083* RETURN: BOOLEAN1084*1085* DESCRIPTION: Check if a particular exception is ignored. In this case it1086* means that the exception is (expected or disabled.1087*1088******************************************************************************/10891090BOOLEAN1091AslIsExceptionIgnored (1092char *Filename,1093UINT32 LineNumber,1094UINT8 Level,1095UINT16 MessageId)1096{1097BOOLEAN ExceptionIgnored;109810991100/* Note: this allows exception to be disabled and expected */11011102ExceptionIgnored = AslIsExceptionDisabled (Level, MessageId);1103ExceptionIgnored |=1104AslIsExceptionExpected (Filename, LineNumber, Level, MessageId);11051106return (AslGbl_AllExceptionsDisabled || ExceptionIgnored);1107}110811091110/*******************************************************************************1111*1112* FUNCTION: AslCheckExpectedException1113*1114* PARAMETERS: none1115*1116* RETURN: none1117*1118* DESCRIPTION: Check the global expected messages table and raise an error1119* for each message that has not been received.1120*1121******************************************************************************/11221123void1124AslCheckExpectedExceptions (1125void)1126{1127UINT32 i;1128ASL_EXPECTED_MSG_NODE *Current = AslGbl_ExpectedErrorCodeList;1129ASL_LOCATION_NODE *LocationNode;113011311132for (i = 0; i < AslGbl_ExpectedMessagesIndex; ++i)1133{1134if (!AslGbl_ExpectedMessages[i].MessageReceived)1135{1136AslError (ASL_ERROR, ASL_MSG_EXCEPTION_NOT_RECEIVED, NULL,1137AslGbl_ExpectedMessages[i].MessageIdStr);1138}1139}11401141while (Current)1142{1143LocationNode = Current->LocationList;11441145while (LocationNode)1146{1147if (!LocationNode->MessageReceived)1148{1149AslCommonError (ASL_ERROR, ASL_MSG_EXCEPTION_NOT_RECEIVED,1150LocationNode->LineNumber, LocationNode->LineNumber,1151LocationNode->LogicalByteOffset, LocationNode->Column,1152LocationNode->Filename, Current->MessageIdStr);1153}11541155LocationNode = LocationNode->Next;1156}11571158Current = Current->Next;1159}1160}116111621163/*******************************************************************************1164*1165* FUNCTION: AslLogExpectedException1166*1167* PARAMETERS: MessageIdString - ID of excepted exception during compile1168*1169* RETURN: Status1170*1171* DESCRIPTION: Enter a message ID into the global expected messages table1172* If these messages are not raised during the compilation, throw1173* an error.1174*1175******************************************************************************/11761177ACPI_STATUS1178AslLogExpectedException (1179char *MessageIdString)1180{1181UINT32 MessageId;118211831184/* Convert argument to an integer and validate it */11851186MessageId = (UINT32) strtoul (MessageIdString, NULL, 0);11871188if (MessageId > 6999)1189{1190printf ("\"%s\" is not a valid warning/remark/error ID\n",1191MessageIdString);1192return (AE_BAD_PARAMETER);1193}11941195/* Insert value into the global expected message array */11961197if (AslGbl_ExpectedMessagesIndex >= ASL_MAX_EXPECTED_MESSAGES)1198{1199printf ("Too many messages have been registered as expected (max %d)\n",1200ASL_MAX_DISABLED_MESSAGES);1201return (AE_LIMIT);1202}12031204AslGbl_ExpectedMessages[AslGbl_ExpectedMessagesIndex].MessageId = MessageId;1205AslGbl_ExpectedMessages[AslGbl_ExpectedMessagesIndex].MessageIdStr = MessageIdString;1206AslGbl_ExpectedMessages[AslGbl_ExpectedMessagesIndex].MessageReceived = FALSE;1207AslGbl_ExpectedMessagesIndex++;1208return (AE_OK);1209}121012111212/*******************************************************************************1213*1214* FUNCTION: AslLogExpectedExceptionByLine1215*1216* PARAMETERS: MessageIdString - ID of excepted exception during compile1217*1218* RETURN: Status1219*1220* DESCRIPTION: Enter a message ID into the global expected messages table1221* based on file and line number. If these messages are not raised1222* during the compilation, throw an error.1223*1224******************************************************************************/12251226void1227AslLogExpectedExceptionByLine (1228char *MessageIdString)1229{1230ASL_LOCATION_NODE *NewErrorLocationNode;1231ASL_EXPECTED_MSG_NODE *Current = AslGbl_ExpectedErrorCodeList;1232UINT32 MessageId;123312341235NewErrorLocationNode = UtLocalCalloc (sizeof (ASL_LOCATION_NODE));12361237NewErrorLocationNode->LineNumber = AslGbl_CurrentLineNumber;1238NewErrorLocationNode->Filename = AslGbl_Files[ASL_FILE_INPUT].Filename;1239NewErrorLocationNode->LogicalByteOffset = AslGbl_CurrentLineOffset;1240NewErrorLocationNode->Column = AslGbl_CurrentColumn;12411242MessageId = (UINT32) strtoul (MessageIdString, NULL, 0);12431244/* search the existing list for a matching message ID */12451246while (Current && Current->MessageId != MessageId )1247{1248Current = Current->Next;1249}1250if (!Current)1251{1252/* ID was not found, create a new node for this message ID */12531254Current = UtLocalCalloc (sizeof (ASL_EXPECTED_MSG_NODE));12551256Current->Next = AslGbl_ExpectedErrorCodeList;1257Current->MessageIdStr = MessageIdString;1258Current->MessageId = MessageId;1259AslGbl_ExpectedErrorCodeList = Current;1260}12611262NewErrorLocationNode->Next = Current->LocationList;1263Current->LocationList = NewErrorLocationNode;1264}126512661267/*******************************************************************************1268*1269* FUNCTION: AslDisableException1270*1271* PARAMETERS: MessageIdString - ID to be disabled1272*1273* RETURN: Status1274*1275* DESCRIPTION: Enter a message ID into the global disabled messages table1276*1277******************************************************************************/12781279ACPI_STATUS1280AslDisableException (1281char *MessageIdString)1282{1283UINT32 MessageId;128412851286/* Convert argument to an integer and validate it */12871288MessageId = (UINT32) strtoul (MessageIdString, NULL, 0);12891290if ((MessageId < 2000) || (MessageId > 6999))1291{1292printf ("\"%s\" is not a valid warning/remark/error ID\n",1293MessageIdString);1294return (AE_BAD_PARAMETER);1295}12961297/* Insert value into the global disabled message array */12981299if (AslGbl_DisabledMessagesIndex >= ASL_MAX_DISABLED_MESSAGES)1300{1301printf ("Too many messages have been disabled (max %d)\n",1302ASL_MAX_DISABLED_MESSAGES);1303return (AE_LIMIT);1304}13051306AslGbl_DisabledMessages[AslGbl_DisabledMessagesIndex] = MessageId;1307AslGbl_DisabledMessagesIndex++;1308return (AE_OK);1309}131013111312/*******************************************************************************1313*1314* FUNCTION: AslElevateException1315*1316* PARAMETERS: MessageIdString - ID of excepted exception during compile1317*1318* RETURN: Status1319*1320* DESCRIPTION: Enter a message ID into the global elevated exceptions table.1321* These messages will be considered as compilation errors.1322*1323******************************************************************************/13241325ACPI_STATUS1326AslElevateException (1327char *MessageIdString)1328{1329UINT32 MessageId;133013311332/* Convert argument to an integer and validate it */13331334MessageId = (UINT32) strtoul (MessageIdString, NULL, 0);13351336if (MessageId > 6999)1337{1338printf ("\"%s\" is not a valid warning/remark/error ID\n",1339MessageIdString);1340return (AE_BAD_PARAMETER);1341}13421343/* Insert value into the global expected message array */13441345if (AslGbl_ElevatedMessagesIndex >= ASL_MAX_ELEVATED_MESSAGES)1346{1347printf ("Too many messages have been registered as elevated (max %d)\n",1348ASL_MAX_DISABLED_MESSAGES);1349return (AE_LIMIT);1350}13511352AslGbl_ElevatedMessages[AslGbl_ElevatedMessagesIndex] = MessageId;1353AslGbl_ElevatedMessagesIndex++;1354return (AE_OK);1355}135613571358/*******************************************************************************1359*1360* FUNCTION: AslIsExceptionDisabled1361*1362* PARAMETERS: Level - Seriousness (Warning/error, etc.)1363* MessageId - Index into global message buffer1364*1365* RETURN: TRUE if exception/message should be ignored1366*1367* DESCRIPTION: Check if the user has specified options such that this1368* exception should be ignored1369*1370******************************************************************************/13711372static BOOLEAN1373AslIsExceptionExpected (1374char *Filename,1375UINT32 LineNumber,1376UINT8 Level,1377UINT16 MessageId)1378{1379ASL_EXPECTED_MSG_NODE *Current = AslGbl_ExpectedErrorCodeList;1380ASL_LOCATION_NODE *CurrentErrorLocation;1381UINT32 EncodedMessageId;1382UINT32 i;138313841385/* Mark this exception as received */13861387EncodedMessageId = AeBuildFullExceptionCode (Level, MessageId);1388for (i = 0; i < AslGbl_ExpectedMessagesIndex; i++)1389{1390/* Simple implementation via fixed array */13911392if (EncodedMessageId == AslGbl_ExpectedMessages[i].MessageId)1393{1394return (AslGbl_ExpectedMessages[i].MessageReceived = TRUE);1395}1396}13971398while (Current && Current->MessageId != EncodedMessageId)1399{1400Current = Current->Next;1401}1402if (!Current)1403{1404return (FALSE);1405}14061407CurrentErrorLocation = Current->LocationList;14081409while (CurrentErrorLocation)1410{1411if (!strcmp (CurrentErrorLocation->Filename, Filename) &&1412CurrentErrorLocation->LineNumber == LineNumber)1413{1414return (CurrentErrorLocation->MessageReceived = TRUE);1415}14161417CurrentErrorLocation = CurrentErrorLocation->Next;1418}14191420return (FALSE);1421}142214231424/*******************************************************************************1425*1426* FUNCTION: AslIsExceptionDisabled1427*1428* PARAMETERS: Level - Seriousness (Warning/error, etc.)1429* MessageId - Index into global message buffer1430*1431* RETURN: TRUE if exception/message should be ignored1432*1433* DESCRIPTION: Check if the user has specified options such that this1434* exception should be ignored1435*1436******************************************************************************/14371438static BOOLEAN1439AslIsExceptionDisabled (1440UINT8 Level,1441UINT16 MessageId)1442{1443UINT32 EncodedMessageId;1444UINT32 i;144514461447switch (Level)1448{1449case ASL_WARNING2:1450case ASL_WARNING3:14511452/* Check for global disable via -w1/-w2/-w3 options */14531454if (Level > AslGbl_WarningLevel)1455{1456return (TRUE);1457}1458ACPI_FALLTHROUGH;14591460case ASL_WARNING:1461case ASL_REMARK:1462case ASL_ERROR:1463/*1464* Ignore this error/warning/remark if it has been disabled by1465* the user (-vw option)1466*/1467EncodedMessageId = AeBuildFullExceptionCode (Level, MessageId);1468for (i = 0; i < AslGbl_DisabledMessagesIndex; i++)1469{1470/* Simple implementation via fixed array */14711472if (EncodedMessageId == AslGbl_DisabledMessages[i])1473{1474return (TRUE);1475}1476}1477break;14781479default:1480break;1481}14821483return (FALSE);1484}148514861487/*******************************************************************************1488*1489* FUNCTION: AslDualParseOpError1490*1491* PARAMETERS: Level - Seriousness (Warning/error, etc.)1492* MainMsgId - Index into global message buffer1493* MainOp - Parse node where error happened1494* MainMsg - Message pertaining to the MainOp1495* SubMsgId - Index into global message buffer1496* SubOp - Additional parse node for better message1497* SubMsg - Message pertaining to SubOp1498*1499*1500* RETURN: None1501*1502* DESCRIPTION: Main error reporting routine for the ASL compiler for error1503* messages that point to multiple parse objects.1504*1505******************************************************************************/15061507void1508AslDualParseOpError (1509UINT8 Level,1510UINT16 MainMsgId,1511ACPI_PARSE_OBJECT *MainOp,1512char *MainMsg,1513UINT16 SubMsgId,1514ACPI_PARSE_OBJECT *SubOp,1515char *SubMsg)1516{1517ASL_ERROR_MSG *SubEnode = NULL;151815191520/* Check if user wants to ignore this exception */15211522if (!MainOp || AslIsExceptionIgnored (MainOp->Asl.Filename,1523MainOp->Asl.LogicalLineNumber, Level, MainMsgId))1524{1525return;1526}15271528if (SubOp)1529{1530AslInitEnode (&SubEnode, Level, SubMsgId, SubOp->Asl.LineNumber,1531SubOp->Asl.LogicalLineNumber, SubOp->Asl.LogicalByteOffset,1532SubOp->Asl.Column, SubOp->Asl.Filename, SubMsg,1533NULL, NULL);1534}15351536AslLogNewError (Level, MainMsgId, MainOp->Asl.LineNumber,1537MainOp->Asl.LogicalLineNumber, MainOp->Asl.LogicalByteOffset,1538MainOp->Asl.Column, MainOp->Asl.Filename, MainMsg,1539NULL, SubEnode);1540}154115421543/*******************************************************************************1544*1545* FUNCTION: AslError1546*1547* PARAMETERS: Level - Seriousness (Warning/error, etc.)1548* MessageId - Index into global message buffer1549* Op - Parse node where error happened1550* ExtraMessage - Additional error message1551*1552* RETURN: None1553*1554* DESCRIPTION: Main error reporting routine for the ASL compiler (all code1555* except the parser.)1556*1557******************************************************************************/15581559void1560AslError (1561UINT8 Level,1562UINT16 MessageId,1563ACPI_PARSE_OBJECT *Op,1564char *ExtraMessage)1565{1566if (Op)1567{1568AslCommonError (Level, MessageId, Op->Asl.LineNumber,1569Op->Asl.LogicalLineNumber,1570Op->Asl.LogicalByteOffset,1571Op->Asl.Column,1572Op->Asl.Filename, ExtraMessage);1573}1574else1575{1576AslCommonError (Level, MessageId, 0,15770, 0, 0, NULL, ExtraMessage);1578}1579}158015811582/*******************************************************************************1583*1584* FUNCTION: AslCoreSubsystemError1585*1586* PARAMETERS: Op - Parse node where error happened1587* Status - The ACPICA Exception1588* ExtraMessage - Additional error message1589* Abort - TRUE -> Abort compilation1590*1591* RETURN: None1592*1593* DESCRIPTION: Error reporting routine for exceptions returned by the ACPICA1594* core subsystem.1595*1596******************************************************************************/15971598void1599AslCoreSubsystemError (1600ACPI_PARSE_OBJECT *Op,1601ACPI_STATUS Status,1602char *ExtraMessage,1603BOOLEAN Abort)1604{16051606sprintf (AslGbl_MsgBuffer, "%s %s", AcpiFormatException (Status), ExtraMessage);16071608if (Op)1609{1610AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION,1611Op->Asl.LineNumber,1612Op->Asl.LogicalLineNumber,1613Op->Asl.LogicalByteOffset,1614Op->Asl.Column,1615Op->Asl.Filename, AslGbl_MsgBuffer);1616}1617else1618{1619AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION,16200, 0, 0, 0, NULL, AslGbl_MsgBuffer);1621}16221623if (Abort)1624{1625AslAbort ();1626}1627}162816291630/*******************************************************************************1631*1632* FUNCTION: AslCompilererror1633*1634* PARAMETERS: CompilerMessage - Error message from the parser1635*1636* RETURN: Status (0 for now)1637*1638* DESCRIPTION: Report an error situation discovered in a production1639* NOTE: don't change the name of this function, it is called1640* from the auto-generated parser.1641*1642******************************************************************************/16431644int1645AslCompilererror (1646const char *CompilerMessage)1647{16481649AslGbl_SyntaxError++;16501651AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, AslGbl_CurrentLineNumber,1652AslGbl_LogicalLineNumber, AslGbl_CurrentLineOffset,1653AslGbl_CurrentColumn, AslGbl_Files[ASL_FILE_INPUT].Filename,1654ACPI_CAST_PTR (char, CompilerMessage));16551656return (0);1657}165816591660