aslerror.c revision 216471
1118611Snjl
2118611Snjl/******************************************************************************
3118611Snjl *
4118611Snjl * Module Name: aslerror - Error handling and statistics
5118611Snjl *
6118611Snjl *****************************************************************************/
7118611Snjl
8118611Snjl/******************************************************************************
9118611Snjl *
10118611Snjl * 1. Copyright Notice
11118611Snjl *
12202771Sjkim * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
13118611Snjl * All rights reserved.
14118611Snjl *
15118611Snjl * 2. License
16118611Snjl *
17118611Snjl * 2.1. This is your license from Intel Corp. under its intellectual property
18118611Snjl * rights.  You may have additional license terms from the party that provided
19118611Snjl * you this software, covering your right to use that party's intellectual
20118611Snjl * property rights.
21118611Snjl *
22118611Snjl * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23118611Snjl * copy of the source code appearing in this file ("Covered Code") an
24118611Snjl * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25118611Snjl * base code distributed originally by Intel ("Original Intel Code") to copy,
26118611Snjl * make derivatives, distribute, use and display any portion of the Covered
27118611Snjl * Code in any form, with the right to sublicense such rights; and
28118611Snjl *
29118611Snjl * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30118611Snjl * license (with the right to sublicense), under only those claims of Intel
31118611Snjl * patents that are infringed by the Original Intel Code, to make, use, sell,
32118611Snjl * offer to sell, and import the Covered Code and derivative works thereof
33118611Snjl * solely to the minimum extent necessary to exercise the above copyright
34118611Snjl * license, and in no event shall the patent license extend to any additions
35118611Snjl * to or modifications of the Original Intel Code.  No other license or right
36118611Snjl * is granted directly or by implication, estoppel or otherwise;
37118611Snjl *
38118611Snjl * The above copyright and patent license is granted only if the following
39118611Snjl * conditions are met:
40118611Snjl *
41118611Snjl * 3. Conditions
42118611Snjl *
43118611Snjl * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44118611Snjl * Redistribution of source code of any substantial portion of the Covered
45118611Snjl * Code or modification with rights to further distribute source must include
46118611Snjl * the above Copyright Notice, the above License, this list of Conditions,
47118611Snjl * and the following Disclaimer and Export Compliance provision.  In addition,
48118611Snjl * Licensee must cause all Covered Code to which Licensee contributes to
49118611Snjl * contain a file documenting the changes Licensee made to create that Covered
50118611Snjl * Code and the date of any change.  Licensee must include in that file the
51118611Snjl * documentation of any changes made by any predecessor Licensee.  Licensee
52118611Snjl * must include a prominent statement that the modification is derived,
53118611Snjl * directly or indirectly, from Original Intel Code.
54118611Snjl *
55118611Snjl * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56118611Snjl * Redistribution of source code of any substantial portion of the Covered
57118611Snjl * Code or modification without rights to further distribute source must
58118611Snjl * include the following Disclaimer and Export Compliance provision in the
59118611Snjl * documentation and/or other materials provided with distribution.  In
60118611Snjl * addition, Licensee may not authorize further sublicense of source of any
61118611Snjl * portion of the Covered Code, and must include terms to the effect that the
62118611Snjl * license from Licensee to its licensee is limited to the intellectual
63118611Snjl * property embodied in the software Licensee provides to its licensee, and
64118611Snjl * not to intellectual property embodied in modifications its licensee may
65118611Snjl * make.
66118611Snjl *
67118611Snjl * 3.3. Redistribution of Executable. Redistribution in executable form of any
68118611Snjl * substantial portion of the Covered Code or modification must reproduce the
69118611Snjl * above Copyright Notice, and the following Disclaimer and Export Compliance
70118611Snjl * provision in the documentation and/or other materials provided with the
71118611Snjl * distribution.
72118611Snjl *
73118611Snjl * 3.4. Intel retains all right, title, and interest in and to the Original
74118611Snjl * Intel Code.
75118611Snjl *
76118611Snjl * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77118611Snjl * Intel shall be used in advertising or otherwise to promote the sale, use or
78118611Snjl * other dealings in products derived from or relating to the Covered Code
79118611Snjl * without prior written authorization from Intel.
80118611Snjl *
81118611Snjl * 4. Disclaimer and Export Compliance
82118611Snjl *
83118611Snjl * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84118611Snjl * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85118611Snjl * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86118611Snjl * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87118611Snjl * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88118611Snjl * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89118611Snjl * PARTICULAR PURPOSE.
90118611Snjl *
91118611Snjl * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92118611Snjl * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93118611Snjl * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94118611Snjl * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95118611Snjl * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96118611Snjl * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97118611Snjl * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98118611Snjl * LIMITED REMEDY.
99118611Snjl *
100118611Snjl * 4.3. Licensee shall not export, either directly or indirectly, any of this
101118611Snjl * software or system incorporating such software without first obtaining any
102118611Snjl * required license or other approval from the U. S. Department of Commerce or
103118611Snjl * any other agency or department of the United States Government.  In the
104118611Snjl * event Licensee exports any such software from the United States or
105118611Snjl * re-exports any such software from a foreign destination, Licensee shall
106118611Snjl * ensure that the distribution and export/re-export of the software is in
107118611Snjl * compliance with all laws, regulations, orders, or other restrictions of the
108118611Snjl * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109118611Snjl * any of its subsidiaries will export/re-export any technical data, process,
110118611Snjl * software, or service, directly or indirectly, to any country for which the
111118611Snjl * United States government or any agency thereof requires an export license,
112118611Snjl * other governmental approval, or letter of assurance, without first obtaining
113118611Snjl * such license, approval or letter.
114118611Snjl *
115118611Snjl *****************************************************************************/
116118611Snjl
117118611Snjl#define ASL_EXCEPTIONS
118151937Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h>
119118611Snjl
120118611Snjl#define _COMPONENT          ACPI_COMPILER
121118611Snjl        ACPI_MODULE_NAME    ("aslerror")
122118611Snjl
123151937Sjkim/* Local prototypes */
124118611Snjl
125151937Sjkimstatic void
126151937SjkimAeAddToErrorLog (
127151937Sjkim    ASL_ERROR_MSG           *Enode);
128151937Sjkim
129151937Sjkim
130193529Sjkimvoid
131193529SjkimAeClearErrorLog (
132193529Sjkim    void)
133193529Sjkim{
134193529Sjkim    ASL_ERROR_MSG           *Enode = Gbl_ErrorLog;
135193529Sjkim    ASL_ERROR_MSG           *Next;
136193529Sjkim
137193529Sjkim    /* Walk the error node list */
138193529Sjkim
139193529Sjkim    while (Enode)
140193529Sjkim    {
141193529Sjkim        Next = Enode->Next;
142193529Sjkim        ACPI_FREE (Enode);
143193529Sjkim        Enode = Next;
144193529Sjkim    }
145193529Sjkim
146193529Sjkim    Gbl_ErrorLog = NULL;
147193529Sjkim}
148193529Sjkim
149193529Sjkim
150118611Snjl/*******************************************************************************
151118611Snjl *
152118611Snjl * FUNCTION:    AeAddToErrorLog
153118611Snjl *
154118611Snjl * PARAMETERS:  Enode       - An error node to add to the log
155118611Snjl *
156118611Snjl * RETURN:      None
157118611Snjl *
158118611Snjl * DESCRIPTION: Add a new error node to the error log.  The error log is
159118611Snjl *              ordered by the "logical" line number (cumulative line number
160118611Snjl *              including all include files.)
161118611Snjl *
162118611Snjl ******************************************************************************/
163118611Snjl
164151937Sjkimstatic void
165118611SnjlAeAddToErrorLog (
166118611Snjl    ASL_ERROR_MSG           *Enode)
167118611Snjl{
168118611Snjl    ASL_ERROR_MSG           *Next;
169118611Snjl    ASL_ERROR_MSG           *Prev;
170118611Snjl
171118611Snjl
172202771Sjkim    /* If Gbl_ErrorLog is null, this is the first error node */
173118611Snjl
174118611Snjl    if (!Gbl_ErrorLog)
175118611Snjl    {
176118611Snjl        Gbl_ErrorLog = Enode;
177118611Snjl        return;
178118611Snjl    }
179118611Snjl
180202771Sjkim    /*
181202771Sjkim     * Walk error list until we find a line number greater than ours.
182202771Sjkim     * List is sorted according to line number.
183202771Sjkim     */
184118611Snjl    Prev = NULL;
185118611Snjl    Next = Gbl_ErrorLog;
186118611Snjl
187118611Snjl    while ((Next) &&
188118611Snjl           (Next->LogicalLineNumber <= Enode->LogicalLineNumber))
189118611Snjl    {
190118611Snjl        Prev = Next;
191118611Snjl        Next = Next->Next;
192118611Snjl    }
193118611Snjl
194118611Snjl    /* Found our place in the list */
195118611Snjl
196118611Snjl    Enode->Next = Next;
197118611Snjl
198118611Snjl    if (Prev)
199118611Snjl    {
200118611Snjl        Prev->Next = Enode;
201118611Snjl    }
202118611Snjl    else
203118611Snjl    {
204118611Snjl        Gbl_ErrorLog = Enode;
205118611Snjl    }
206118611Snjl}
207118611Snjl
208118611Snjl
209118611Snjl/*******************************************************************************
210118611Snjl *
211118611Snjl * FUNCTION:    AePrintException
212118611Snjl *
213151937Sjkim * PARAMETERS:  FileId          - ID of output file
214118611Snjl *              Enode           - Error node to print
215118611Snjl *              Header          - Additional text before each message
216118611Snjl *
217118611Snjl * RETURN:      None
218118611Snjl *
219118611Snjl * DESCRIPTION: Print the contents of an error node.
220118611Snjl *
221118611Snjl * NOTE:        We don't use the FlxxxFile I/O functions here because on error
222118611Snjl *              they abort the compiler and call this function!  Since we
223118611Snjl *              are reporting errors here, we ignore most output errors and
224118611Snjl *              just try to get out as much as we can.
225118611Snjl *
226118611Snjl ******************************************************************************/
227118611Snjl
228118611Snjlvoid
229118611SnjlAePrintException (
230118611Snjl    UINT32                  FileId,
231118611Snjl    ASL_ERROR_MSG           *Enode,
232118611Snjl    char                    *Header)
233118611Snjl{
234118611Snjl    UINT8                   SourceByte;
235151937Sjkim    int                     Actual;
236151937Sjkim    size_t                  RActual;
237118611Snjl    UINT32                  MsgLength;
238118611Snjl    char                    *MainMessage;
239118611Snjl    char                    *ExtraMessage;
240118611Snjl    UINT32                  SourceColumn;
241118611Snjl    UINT32                  ErrorColumn;
242118611Snjl    FILE                    *OutputFile;
243118611Snjl    FILE                    *SourceFile;
244216471Sjkim    long                    FileSize;
245216471Sjkim    BOOLEAN                 PrematureEOF = FALSE;
246118611Snjl
247118611Snjl
248193529Sjkim    if (Gbl_NoErrors)
249193529Sjkim    {
250193529Sjkim        return;
251193529Sjkim    }
252193529Sjkim
253151937Sjkim    /*
254151937Sjkim     * Only listing files have a header, and remarks/optimizations
255151937Sjkim     * are always output
256151937Sjkim     */
257118611Snjl    if (!Header)
258118611Snjl    {
259118611Snjl        /* Ignore remarks if requested */
260118611Snjl
261118611Snjl        switch (Enode->Level)
262118611Snjl        {
263118611Snjl        case ASL_REMARK:
264118611Snjl            if (!Gbl_DisplayRemarks)
265118611Snjl            {
266118611Snjl                return;
267118611Snjl            }
268118611Snjl            break;
269118611Snjl
270118611Snjl        case ASL_OPTIMIZATION:
271118611Snjl            if (!Gbl_DisplayOptimizations)
272118611Snjl            {
273118611Snjl                return;
274118611Snjl            }
275118611Snjl            break;
276118611Snjl
277118611Snjl        default:
278118611Snjl            break;
279118611Snjl        }
280118611Snjl    }
281118611Snjl
282118611Snjl    /* Get the file handles */
283118611Snjl
284118611Snjl    OutputFile = Gbl_Files[FileId].Handle;
285209746Sjkim
286209746Sjkim    /* Use the merged header/source file if present, otherwise use input file */
287209746Sjkim
288118611Snjl    SourceFile = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
289209746Sjkim    if (!SourceFile)
290209746Sjkim    {
291209746Sjkim        SourceFile = Gbl_Files[ASL_FILE_INPUT].Handle;
292209746Sjkim    }
293118611Snjl
294216471Sjkim    if (SourceFile)
295216471Sjkim    {
296216471Sjkim        /* Determine if the error occurred at source file EOF */
297216471Sjkim
298216471Sjkim        fseek (SourceFile, 0, SEEK_END);
299216471Sjkim        FileSize = ftell (SourceFile);
300216471Sjkim
301216471Sjkim        if ((long) Enode->LogicalByteOffset >= FileSize)
302216471Sjkim        {
303216471Sjkim            PrematureEOF = TRUE;
304216471Sjkim        }
305216471Sjkim    }
306216471Sjkim
307118611Snjl    if (Header)
308118611Snjl    {
309118611Snjl        fprintf (OutputFile, "%s", Header);
310118611Snjl    }
311118611Snjl
312118611Snjl    /* Print filename and line number if present and valid */
313118611Snjl
314118611Snjl    if (Enode->Filename)
315118611Snjl    {
316118611Snjl        if (Gbl_VerboseErrors)
317118611Snjl        {
318118611Snjl            fprintf (OutputFile, "%6s", Enode->Filename);
319118611Snjl
320118611Snjl            if (Enode->LineNumber)
321118611Snjl            {
322212761Sjkim                fprintf (OutputFile, " %6u: ", Enode->LineNumber);
323118611Snjl
324118611Snjl                /*
325216471Sjkim                 * If not at EOF, get the corresponding source code line and
326216471Sjkim                 * display it. Don't attempt this if we have a premature EOF
327216471Sjkim                 * condition.
328118611Snjl                 */
329216471Sjkim                if (!PrematureEOF)
330118611Snjl                {
331216471Sjkim                    /*
332216471Sjkim                     * Seek to the offset in the combined source file, read
333216471Sjkim                     * the source line, and write it to the output.
334216471Sjkim                     */
335216471Sjkim                    Actual = fseek (SourceFile, (long) Enode->LogicalByteOffset,
336216471Sjkim                                (int) SEEK_SET);
337216471Sjkim                    if (Actual)
338118611Snjl                    {
339151937Sjkim                        fprintf (OutputFile,
340216471Sjkim                            "[*** iASL: Seek error on source code temp file %s ***]",
341193529Sjkim                            Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
342118611Snjl                    }
343216471Sjkim                    else
344118611Snjl                    {
345151937Sjkim                        RActual = fread (&SourceByte, 1, 1, SourceFile);
346216471Sjkim                        if (!RActual)
347216471Sjkim                        {
348216471Sjkim                            fprintf (OutputFile,
349216471Sjkim                                "[*** iASL: Read error on source code temp file %s ***]",
350216471Sjkim                                Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
351216471Sjkim                        }
352216471Sjkim
353216471Sjkim                        else while (RActual && SourceByte && (SourceByte != '\n'))
354216471Sjkim                        {
355216471Sjkim                            fwrite (&SourceByte, 1, 1, OutputFile);
356216471Sjkim                            RActual = fread (&SourceByte, 1, 1, SourceFile);
357216471Sjkim                        }
358118611Snjl                    }
359118611Snjl                }
360216471Sjkim
361118611Snjl                fprintf (OutputFile, "\n");
362118611Snjl            }
363118611Snjl        }
364118611Snjl        else
365118611Snjl        {
366118611Snjl            fprintf (OutputFile, "%s", Enode->Filename);
367118611Snjl
368118611Snjl            if (Enode->LineNumber)
369118611Snjl            {
370118611Snjl                fprintf (OutputFile, "(%u) : ", Enode->LineNumber);
371118611Snjl            }
372118611Snjl        }
373118611Snjl    }
374118611Snjl
375118611Snjl    /* NULL message ID, just print the raw message */
376118611Snjl
377118611Snjl    if (Enode->MessageId == 0)
378118611Snjl    {
379118611Snjl        fprintf (OutputFile, "%s\n", Enode->Message);
380118611Snjl    }
381118611Snjl    else
382118611Snjl    {
383118611Snjl        /* Decode the message ID */
384118611Snjl
385212761Sjkim        fprintf (OutputFile, "%s %4.4d - ",
386118611Snjl                    AslErrorLevel[Enode->Level],
387118611Snjl                    Enode->MessageId + ((Enode->Level+1) * 1000));
388118611Snjl
389118611Snjl        MainMessage = AslMessages[Enode->MessageId];
390118611Snjl        ExtraMessage = Enode->Message;
391118611Snjl
392118611Snjl        if (Enode->LineNumber)
393118611Snjl        {
394118611Snjl            MsgLength = strlen (MainMessage);
395118611Snjl            if (MsgLength == 0)
396118611Snjl            {
397118611Snjl                MainMessage = Enode->Message;
398118611Snjl
399118611Snjl                MsgLength = strlen (MainMessage);
400118611Snjl                ExtraMessage = NULL;
401118611Snjl            }
402118611Snjl
403216471Sjkim            if (Gbl_VerboseErrors && !PrematureEOF)
404118611Snjl            {
405118611Snjl                SourceColumn = Enode->Column + Enode->FilenameLength + 6 + 2;
406118611Snjl                ErrorColumn = ASL_ERROR_LEVEL_LENGTH + 5 + 2 + 1;
407118611Snjl
408118611Snjl                if ((MsgLength + ErrorColumn) < (SourceColumn - 1))
409118611Snjl                {
410118611Snjl                    fprintf (OutputFile, "%*s%s",
411118611Snjl                        (int) ((SourceColumn - 1) - ErrorColumn),
412118611Snjl                        MainMessage, " ^ ");
413118611Snjl                }
414118611Snjl                else
415118611Snjl                {
416118611Snjl                    fprintf (OutputFile, "%*s %s",
417118611Snjl                        (int) ((SourceColumn - ErrorColumn) + 1), "^",
418118611Snjl                        MainMessage);
419118611Snjl                }
420118611Snjl            }
421118611Snjl            else
422118611Snjl            {
423118611Snjl                fprintf (OutputFile, " %s", MainMessage);
424118611Snjl            }
425118611Snjl
426118611Snjl            /* Print the extra info message if present */
427118611Snjl
428118611Snjl            if (ExtraMessage)
429118611Snjl            {
430118611Snjl                fprintf (OutputFile, " (%s)", ExtraMessage);
431118611Snjl            }
432118611Snjl
433216471Sjkim            if (PrematureEOF)
434216471Sjkim            {
435216471Sjkim                fprintf (OutputFile, " and premature End-Of-File");
436216471Sjkim            }
437216471Sjkim
438118611Snjl            fprintf (OutputFile, "\n");
439118611Snjl            if (Gbl_VerboseErrors)
440118611Snjl            {
441118611Snjl                fprintf (OutputFile, "\n");
442118611Snjl            }
443118611Snjl        }
444118611Snjl        else
445118611Snjl        {
446151937Sjkim            fprintf (OutputFile, " %s %s\n\n", MainMessage, ExtraMessage);
447118611Snjl        }
448118611Snjl    }
449118611Snjl}
450118611Snjl
451118611Snjl
452118611Snjl/*******************************************************************************
453118611Snjl *
454118611Snjl * FUNCTION:    AePrintErrorLog
455118611Snjl *
456118611Snjl * PARAMETERS:  FileId           - Where to output the error log
457118611Snjl *
458118611Snjl * RETURN:      None
459118611Snjl *
460118611Snjl * DESCRIPTION: Print the entire contents of the error log
461118611Snjl *
462118611Snjl ******************************************************************************/
463118611Snjl
464118611Snjlvoid
465118611SnjlAePrintErrorLog (
466118611Snjl    UINT32                  FileId)
467118611Snjl{
468118611Snjl    ASL_ERROR_MSG           *Enode = Gbl_ErrorLog;
469118611Snjl
470118611Snjl
471118611Snjl    /* Walk the error node list */
472118611Snjl
473118611Snjl    while (Enode)
474118611Snjl    {
475118611Snjl        AePrintException (FileId, Enode, NULL);
476118611Snjl        Enode = Enode->Next;
477118611Snjl    }
478118611Snjl}
479118611Snjl
480118611Snjl
481118611Snjl/*******************************************************************************
482118611Snjl *
483118611Snjl * FUNCTION:    AslCommonError
484118611Snjl *
485118611Snjl * PARAMETERS:  Level               - Seriousness (Warning/error, etc.)
486118611Snjl *              MessageId           - Index into global message buffer
487118611Snjl *              CurrentLineNumber   - Actual file line number
488118611Snjl *              LogicalLineNumber   - Cumulative line number
489118611Snjl *              LogicalByteOffset   - Byte offset in source file
490118611Snjl *              Column              - Column in current line
491118611Snjl *              Filename            - source filename
492118611Snjl *              ExtraMessage        - additional error message
493118611Snjl *
494151937Sjkim * RETURN:      None
495118611Snjl *
496118611Snjl * DESCRIPTION: Create a new error node and add it to the error log
497118611Snjl *
498118611Snjl ******************************************************************************/
499118611Snjl
500118611Snjlvoid
501118611SnjlAslCommonError (
502118611Snjl    UINT8                   Level,
503118611Snjl    UINT8                   MessageId,
504118611Snjl    UINT32                  CurrentLineNumber,
505118611Snjl    UINT32                  LogicalLineNumber,
506118611Snjl    UINT32                  LogicalByteOffset,
507118611Snjl    UINT32                  Column,
508118611Snjl    char                    *Filename,
509118611Snjl    char                    *ExtraMessage)
510118611Snjl{
511118611Snjl    UINT32                  MessageSize;
512118611Snjl    char                    *MessageBuffer = NULL;
513118611Snjl    ASL_ERROR_MSG           *Enode;
514118611Snjl
515118611Snjl
516118611Snjl    Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG));
517118611Snjl
518118611Snjl    if (ExtraMessage)
519118611Snjl    {
520118611Snjl        /* Allocate a buffer for the message and a new error node */
521118611Snjl
522118611Snjl        MessageSize   = strlen (ExtraMessage) + 1;
523118611Snjl        MessageBuffer = UtLocalCalloc (MessageSize);
524118611Snjl
525118611Snjl        /* Keep a copy of the extra message */
526118611Snjl
527118611Snjl        ACPI_STRCPY (MessageBuffer, ExtraMessage);
528118611Snjl    }
529118611Snjl
530118611Snjl    /* Initialize the error node */
531118611Snjl
532118611Snjl    if (Filename)
533118611Snjl    {
534118611Snjl        Enode->Filename       = Filename;
535118611Snjl        Enode->FilenameLength = strlen (Filename);
536118611Snjl        if (Enode->FilenameLength < 6)
537118611Snjl        {
538118611Snjl            Enode->FilenameLength = 6;
539118611Snjl        }
540118611Snjl    }
541118611Snjl
542118611Snjl    Enode->MessageId            = MessageId;
543118611Snjl    Enode->Level                = Level;
544118611Snjl    Enode->LineNumber           = CurrentLineNumber;
545118611Snjl    Enode->LogicalLineNumber    = LogicalLineNumber;
546118611Snjl    Enode->LogicalByteOffset    = LogicalByteOffset;
547118611Snjl    Enode->Column               = Column;
548118611Snjl    Enode->Message              = MessageBuffer;
549118611Snjl
550118611Snjl    /* Add the new node to the error node list */
551118611Snjl
552118611Snjl    AeAddToErrorLog (Enode);
553118611Snjl
554118611Snjl    if (Gbl_DebugFlag)
555118611Snjl    {
556118611Snjl        /* stderr is a file, send error to it immediately */
557118611Snjl
558118611Snjl        AePrintException (ASL_FILE_STDERR, Enode, NULL);
559118611Snjl    }
560118611Snjl
561118611Snjl    Gbl_ExceptionCount[Level]++;
562118611Snjl    if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
563118611Snjl    {
564209746Sjkim        printf ("\nMaximum error count (%u) exceeded\n", ASL_MAX_ERROR_COUNT);
565118611Snjl
566118611Snjl        Gbl_SourceLine = 0;
567118611Snjl        Gbl_NextError = Gbl_ErrorLog;
568118611Snjl        CmDoOutputFiles ();
569118611Snjl        CmCleanupAndExit ();
570199337Sjkim        exit(1);
571118611Snjl    }
572118611Snjl
573118611Snjl    return;
574118611Snjl}
575118611Snjl
576118611Snjl
577118611Snjl/*******************************************************************************
578118611Snjl *
579118611Snjl * FUNCTION:    AslError
580118611Snjl *
581118611Snjl * PARAMETERS:  Level               - Seriousness (Warning/error, etc.)
582118611Snjl *              MessageId           - Index into global message buffer
583118611Snjl *              Op                  - Parse node where error happened
584118611Snjl *              ExtraMessage        - additional error message
585118611Snjl *
586118611Snjl * RETURN:      None
587118611Snjl *
588118611Snjl * DESCRIPTION: Main error reporting routine for the ASL compiler (all code
589118611Snjl *              except the parser.)
590118611Snjl *
591118611Snjl ******************************************************************************/
592118611Snjl
593118611Snjlvoid
594118611SnjlAslError (
595118611Snjl    UINT8                   Level,
596118611Snjl    UINT8                   MessageId,
597118611Snjl    ACPI_PARSE_OBJECT       *Op,
598118611Snjl    char                    *ExtraMessage)
599118611Snjl{
600118611Snjl
601167802Sjkim    switch (Level)
602167802Sjkim    {
603167802Sjkim    case ASL_WARNING2:
604167802Sjkim    case ASL_WARNING3:
605167802Sjkim        if (Gbl_WarningLevel < Level)
606167802Sjkim        {
607167802Sjkim            return;
608167802Sjkim        }
609167802Sjkim        break;
610167802Sjkim
611167802Sjkim    default:
612167802Sjkim        break;
613167802Sjkim    }
614167802Sjkim
615167802Sjkim
616118611Snjl    if (Op)
617118611Snjl    {
618118611Snjl        AslCommonError (Level, MessageId, Op->Asl.LineNumber,
619118611Snjl                        Op->Asl.LogicalLineNumber,
620118611Snjl                        Op->Asl.LogicalByteOffset,
621118611Snjl                        Op->Asl.Column,
622118611Snjl                        Op->Asl.Filename, ExtraMessage);
623118611Snjl    }
624118611Snjl    else
625118611Snjl    {
626118611Snjl        AslCommonError (Level, MessageId, 0,
627118611Snjl                        0, 0, 0, NULL, ExtraMessage);
628118611Snjl    }
629118611Snjl}
630118611Snjl
631118611Snjl
632118611Snjl/*******************************************************************************
633118611Snjl *
634118611Snjl * FUNCTION:    AslCoreSubsystemError
635118611Snjl *
636118611Snjl * PARAMETERS:  Op                  - Parse node where error happened
637118611Snjl *              Status              - The ACPI CA Exception
638118611Snjl *              ExtraMessage        - additional error message
639118611Snjl *              Abort               - TRUE -> Abort compilation
640118611Snjl *
641118611Snjl * RETURN:      None
642118611Snjl *
643118611Snjl * DESCRIPTION: Error reporting routine for exceptions returned by the ACPI
644118611Snjl *              CA core subsystem.
645118611Snjl *
646118611Snjl ******************************************************************************/
647118611Snjl
648118611Snjlvoid
649118611SnjlAslCoreSubsystemError (
650118611Snjl    ACPI_PARSE_OBJECT       *Op,
651118611Snjl    ACPI_STATUS             Status,
652118611Snjl    char                    *ExtraMessage,
653118611Snjl    BOOLEAN                 Abort)
654118611Snjl{
655118611Snjl
656118611Snjl    sprintf (MsgBuffer, "%s %s", AcpiFormatException (Status), ExtraMessage);
657118611Snjl
658118611Snjl    if (Op)
659118611Snjl    {
660118611Snjl        AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Op->Asl.LineNumber,
661118611Snjl                        Op->Asl.LogicalLineNumber,
662118611Snjl                        Op->Asl.LogicalByteOffset,
663118611Snjl                        Op->Asl.Column,
664118611Snjl                        Op->Asl.Filename, MsgBuffer);
665118611Snjl    }
666118611Snjl    else
667118611Snjl    {
668118611Snjl        AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, 0,
669118611Snjl                        0, 0, 0, NULL, MsgBuffer);
670118611Snjl    }
671118611Snjl
672118611Snjl    if (Abort)
673118611Snjl    {
674118611Snjl        AslAbort ();
675118611Snjl    }
676118611Snjl}
677118611Snjl
678118611Snjl
679118611Snjl/*******************************************************************************
680118611Snjl *
681118611Snjl * FUNCTION:    AslCompilererror
682118611Snjl *
683118611Snjl * PARAMETERS:  CompilerMessage         - Error message from the parser
684118611Snjl *
685151937Sjkim * RETURN:      Status (0 for now)
686118611Snjl *
687118611Snjl * DESCRIPTION: Report an error situation discovered in a production
688151937Sjkim *              NOTE: don't change the name of this function, it is called
689151937Sjkim *              from the auto-generated parser.
690118611Snjl *
691118611Snjl ******************************************************************************/
692118611Snjl
693118611Snjlint
694118611SnjlAslCompilererror (
695118611Snjl    char                    *CompilerMessage)
696118611Snjl{
697118611Snjl
698118611Snjl    AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, Gbl_CurrentLineNumber,
699118611Snjl                    Gbl_LogicalLineNumber, Gbl_CurrentLineOffset,
700118611Snjl                    Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename,
701118611Snjl                    CompilerMessage);
702118611Snjl
703118611Snjl    return 0;
704118611Snjl}
705118611Snjl
706118611Snjl
707