1118611Snjl/******************************************************************************
2118611Snjl *
3118611Snjl * Module Name: aslerror - Error handling and statistics
4118611Snjl *
5118611Snjl *****************************************************************************/
6118611Snjl
7316303Sjkim/******************************************************************************
8316303Sjkim *
9316303Sjkim * 1. Copyright Notice
10316303Sjkim *
11316303Sjkim * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
12118611Snjl * All rights reserved.
13118611Snjl *
14316303Sjkim * 2. License
15316303Sjkim *
16316303Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property
17316303Sjkim * rights. You may have additional license terms from the party that provided
18316303Sjkim * you this software, covering your right to use that party's intellectual
19316303Sjkim * property rights.
20316303Sjkim *
21316303Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22316303Sjkim * copy of the source code appearing in this file ("Covered Code") an
23316303Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24316303Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy,
25316303Sjkim * make derivatives, distribute, use and display any portion of the Covered
26316303Sjkim * Code in any form, with the right to sublicense such rights; and
27316303Sjkim *
28316303Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29316303Sjkim * license (with the right to sublicense), under only those claims of Intel
30316303Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell,
31316303Sjkim * offer to sell, and import the Covered Code and derivative works thereof
32316303Sjkim * solely to the minimum extent necessary to exercise the above copyright
33316303Sjkim * license, and in no event shall the patent license extend to any additions
34316303Sjkim * to or modifications of the Original Intel Code. No other license or right
35316303Sjkim * is granted directly or by implication, estoppel or otherwise;
36316303Sjkim *
37316303Sjkim * The above copyright and patent license is granted only if the following
38316303Sjkim * conditions are met:
39316303Sjkim *
40316303Sjkim * 3. Conditions
41316303Sjkim *
42316303Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43316303Sjkim * Redistribution of source code of any substantial portion of the Covered
44316303Sjkim * Code or modification with rights to further distribute source must include
45316303Sjkim * the above Copyright Notice, the above License, this list of Conditions,
46316303Sjkim * and the following Disclaimer and Export Compliance provision. In addition,
47316303Sjkim * Licensee must cause all Covered Code to which Licensee contributes to
48316303Sjkim * contain a file documenting the changes Licensee made to create that Covered
49316303Sjkim * Code and the date of any change. Licensee must include in that file the
50316303Sjkim * documentation of any changes made by any predecessor Licensee. Licensee
51316303Sjkim * must include a prominent statement that the modification is derived,
52316303Sjkim * directly or indirectly, from Original Intel Code.
53316303Sjkim *
54316303Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55316303Sjkim * Redistribution of source code of any substantial portion of the Covered
56316303Sjkim * Code or modification without rights to further distribute source must
57316303Sjkim * include the following Disclaimer and Export Compliance provision in the
58316303Sjkim * documentation and/or other materials provided with distribution. In
59316303Sjkim * addition, Licensee may not authorize further sublicense of source of any
60316303Sjkim * portion of the Covered Code, and must include terms to the effect that the
61316303Sjkim * license from Licensee to its licensee is limited to the intellectual
62316303Sjkim * property embodied in the software Licensee provides to its licensee, and
63316303Sjkim * not to intellectual property embodied in modifications its licensee may
64316303Sjkim * make.
65316303Sjkim *
66316303Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any
67316303Sjkim * substantial portion of the Covered Code or modification must reproduce the
68316303Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance
69316303Sjkim * provision in the documentation and/or other materials provided with the
70316303Sjkim * distribution.
71316303Sjkim *
72316303Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original
73316303Sjkim * Intel Code.
74316303Sjkim *
75316303Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76316303Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or
77316303Sjkim * other dealings in products derived from or relating to the Covered Code
78316303Sjkim * without prior written authorization from Intel.
79316303Sjkim *
80316303Sjkim * 4. Disclaimer and Export Compliance
81316303Sjkim *
82316303Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83316303Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84316303Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85316303Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86316303Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87316303Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88316303Sjkim * PARTICULAR PURPOSE.
89316303Sjkim *
90316303Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91316303Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92316303Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93316303Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94316303Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95316303Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96316303Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97316303Sjkim * LIMITED REMEDY.
98316303Sjkim *
99316303Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this
100316303Sjkim * software or system incorporating such software without first obtaining any
101316303Sjkim * required license or other approval from the U. S. Department of Commerce or
102316303Sjkim * any other agency or department of the United States Government. In the
103316303Sjkim * event Licensee exports any such software from the United States or
104316303Sjkim * re-exports any such software from a foreign destination, Licensee shall
105316303Sjkim * ensure that the distribution and export/re-export of the software is in
106316303Sjkim * compliance with all laws, regulations, orders, or other restrictions of the
107316303Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108316303Sjkim * any of its subsidiaries will export/re-export any technical data, process,
109316303Sjkim * software, or service, directly or indirectly, to any country for which the
110316303Sjkim * United States government or any agency thereof requires an export license,
111316303Sjkim * other governmental approval, or letter of assurance, without first obtaining
112316303Sjkim * such license, approval or letter.
113316303Sjkim *
114316303Sjkim *****************************************************************************
115316303Sjkim *
116316303Sjkim * Alternatively, you may choose to be licensed under the terms of the
117316303Sjkim * following license:
118316303Sjkim *
119217365Sjkim * Redistribution and use in source and binary forms, with or without
120217365Sjkim * modification, are permitted provided that the following conditions
121217365Sjkim * are met:
122217365Sjkim * 1. Redistributions of source code must retain the above copyright
123217365Sjkim *    notice, this list of conditions, and the following disclaimer,
124217365Sjkim *    without modification.
125217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126217365Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
127217365Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
128217365Sjkim *    including a substantially similar Disclaimer requirement for further
129217365Sjkim *    binary redistribution.
130217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
131217365Sjkim *    of any contributors may be used to endorse or promote products derived
132217365Sjkim *    from this software without specific prior written permission.
133118611Snjl *
134316303Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135316303Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136316303Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137316303Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138316303Sjkim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139316303Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140316303Sjkim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141316303Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142316303Sjkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143316303Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144316303Sjkim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145316303Sjkim *
146316303Sjkim * Alternatively, you may choose to be licensed under the terms of the
147217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
148217365Sjkim * Software Foundation.
149118611Snjl *
150316303Sjkim *****************************************************************************/
151118611Snjl
152151937Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h>
153118611Snjl
154118611Snjl#define _COMPONENT          ACPI_COMPILER
155118611Snjl        ACPI_MODULE_NAME    ("aslerror")
156118611Snjl
157151937Sjkim/* Local prototypes */
158118611Snjl
159151937Sjkimstatic void
160151937SjkimAeAddToErrorLog (
161151937Sjkim    ASL_ERROR_MSG           *Enode);
162151937Sjkim
163322877Sjkimstatic BOOLEAN
164322877SjkimAslIsExceptionExpected (
165322877Sjkim    UINT8                   Level,
166322877Sjkim    UINT16                  MessageId);
167151937Sjkim
168322877Sjkimstatic BOOLEAN
169322877SjkimAslIsExceptionDisabled (
170322877Sjkim    UINT8                   Level,
171322877Sjkim    UINT16                  MessageId);
172322877Sjkim
173327557Sjkimstatic void AslInitEnode (
174327557Sjkim    ASL_ERROR_MSG           **Enode,
175327557Sjkim    UINT8                   Level,
176327557Sjkim    UINT16                  MessageId,
177327557Sjkim    UINT32                  LineNumber,
178327557Sjkim    UINT32                  LogicalLineNumber,
179327557Sjkim    UINT32                  LogicalByteOffset,
180327557Sjkim    UINT32                  Column,
181327557Sjkim    char                    *Filename,
182327557Sjkim    char                    *Message,
183327557Sjkim    char                    *SourceLine,
184327557Sjkim    ASL_ERROR_MSG           *SubError);
185322877Sjkim
186327557Sjkimstatic void
187327557SjkimAslLogNewError (
188327557Sjkim    UINT8                   Level,
189327557Sjkim    UINT16                  MessageId,
190327557Sjkim    UINT32                  LineNumber,
191327557Sjkim    UINT32                  LogicalLineNumber,
192327557Sjkim    UINT32                  LogicalByteOffset,
193327557Sjkim    UINT32                  Column,
194327557Sjkim    char                    *Filename,
195327557Sjkim    char                    *Message,
196327557Sjkim    char                    *SourceLine,
197327557Sjkim    ASL_ERROR_MSG           *SubError);
198327557Sjkim
199327557Sjkimstatic void
200327557SjkimAePrintSubError (
201327557Sjkim    FILE                    *OutputFile,
202327557Sjkim    ASL_ERROR_MSG           *Enode);
203327557Sjkim
204327557Sjkim
205233250Sjkim/*******************************************************************************
206233250Sjkim *
207272444Sjkim * FUNCTION:    AslAbort
208272444Sjkim *
209272444Sjkim * PARAMETERS:  None
210272444Sjkim *
211272444Sjkim * RETURN:      None
212272444Sjkim *
213272444Sjkim * DESCRIPTION: Dump the error log and abort the compiler. Used for serious
214272444Sjkim *              I/O errors.
215272444Sjkim *
216272444Sjkim ******************************************************************************/
217272444Sjkim
218272444Sjkimvoid
219272444SjkimAslAbort (
220272444Sjkim    void)
221272444Sjkim{
222272444Sjkim
223272444Sjkim    AePrintErrorLog (ASL_FILE_STDERR);
224272444Sjkim    if (Gbl_DebugFlag)
225272444Sjkim    {
226272444Sjkim        /* Print error summary to stdout also */
227272444Sjkim
228272444Sjkim        AePrintErrorLog (ASL_FILE_STDOUT);
229272444Sjkim    }
230272444Sjkim
231272444Sjkim    exit (1);
232272444Sjkim}
233272444Sjkim
234272444Sjkim
235272444Sjkim/*******************************************************************************
236272444Sjkim *
237233250Sjkim * FUNCTION:    AeClearErrorLog
238233250Sjkim *
239233250Sjkim * PARAMETERS:  None
240233250Sjkim *
241233250Sjkim * RETURN:      None
242233250Sjkim *
243233250Sjkim * DESCRIPTION: Empty the error list
244233250Sjkim *
245233250Sjkim ******************************************************************************/
246233250Sjkim
247193529Sjkimvoid
248193529SjkimAeClearErrorLog (
249193529Sjkim    void)
250193529Sjkim{
251193529Sjkim    ASL_ERROR_MSG           *Enode = Gbl_ErrorLog;
252193529Sjkim    ASL_ERROR_MSG           *Next;
253193529Sjkim
254327557Sjkim
255193529Sjkim    /* Walk the error node list */
256193529Sjkim
257193529Sjkim    while (Enode)
258193529Sjkim    {
259193529Sjkim        Next = Enode->Next;
260193529Sjkim        ACPI_FREE (Enode);
261193529Sjkim        Enode = Next;
262193529Sjkim    }
263193529Sjkim
264193529Sjkim    Gbl_ErrorLog = NULL;
265193529Sjkim}
266193529Sjkim
267193529Sjkim
268118611Snjl/*******************************************************************************
269118611Snjl *
270118611Snjl * FUNCTION:    AeAddToErrorLog
271118611Snjl *
272118611Snjl * PARAMETERS:  Enode       - An error node to add to the log
273118611Snjl *
274118611Snjl * RETURN:      None
275118611Snjl *
276241973Sjkim * DESCRIPTION: Add a new error node to the error log. The error log is
277118611Snjl *              ordered by the "logical" line number (cumulative line number
278118611Snjl *              including all include files.)
279118611Snjl *
280118611Snjl ******************************************************************************/
281118611Snjl
282151937Sjkimstatic void
283118611SnjlAeAddToErrorLog (
284118611Snjl    ASL_ERROR_MSG           *Enode)
285118611Snjl{
286118611Snjl    ASL_ERROR_MSG           *Next;
287118611Snjl    ASL_ERROR_MSG           *Prev;
288118611Snjl
289118611Snjl
290202771Sjkim    /* If Gbl_ErrorLog is null, this is the first error node */
291118611Snjl
292118611Snjl    if (!Gbl_ErrorLog)
293118611Snjl    {
294118611Snjl        Gbl_ErrorLog = Enode;
295118611Snjl        return;
296118611Snjl    }
297118611Snjl
298202771Sjkim    /*
299202771Sjkim     * Walk error list until we find a line number greater than ours.
300202771Sjkim     * List is sorted according to line number.
301202771Sjkim     */
302118611Snjl    Prev = NULL;
303118611Snjl    Next = Gbl_ErrorLog;
304118611Snjl
305327557Sjkim    while ((Next) && (Next->LogicalLineNumber <= Enode->LogicalLineNumber))
306118611Snjl    {
307118611Snjl        Prev = Next;
308118611Snjl        Next = Next->Next;
309118611Snjl    }
310118611Snjl
311118611Snjl    /* Found our place in the list */
312118611Snjl
313118611Snjl    Enode->Next = Next;
314118611Snjl
315118611Snjl    if (Prev)
316118611Snjl    {
317118611Snjl        Prev->Next = Enode;
318118611Snjl    }
319118611Snjl    else
320118611Snjl    {
321118611Snjl        Gbl_ErrorLog = Enode;
322118611Snjl    }
323118611Snjl}
324118611Snjl
325118611Snjl
326118611Snjl/*******************************************************************************
327118611Snjl *
328327557Sjkim * FUNCTION:    AeDecodeErrorMessageId
329118611Snjl *
330327557Sjkim * PARAMETERS:  OutputFile      - Output file
331118611Snjl *              Enode           - Error node to print
332327557Sjkim *              PrematureEOF    - True = PrematureEOF has been reached
333327557Sjkim *              Total           - Total legth of line
334118611Snjl *
335118611Snjl * RETURN:      None
336118611Snjl *
337327557Sjkim * DESCRIPTION: Print the source line of an error.
338118611Snjl *
339118611Snjl ******************************************************************************/
340118611Snjl
341327557Sjkimstatic void
342327557SjkimAeDecodeErrorMessageId (
343327557Sjkim    FILE                    *OutputFile,
344118611Snjl    ASL_ERROR_MSG           *Enode,
345327557Sjkim    BOOLEAN                 PrematureEOF,
346327557Sjkim    UINT32                  Total)
347118611Snjl{
348118611Snjl    UINT32                  MsgLength;
349272444Sjkim    const char              *MainMessage;
350118611Snjl    char                    *ExtraMessage;
351118611Snjl    UINT32                  SourceColumn;
352118611Snjl    UINT32                  ErrorColumn;
353118611Snjl
354118611Snjl
355327557Sjkim    fprintf (OutputFile, "%s %4.4d -",
356327557Sjkim        AeDecodeExceptionLevel (Enode->Level),
357327557Sjkim        AeBuildFullExceptionCode (Enode->Level, Enode->MessageId));
358327557Sjkim
359327557Sjkim    MainMessage = AeDecodeMessageId (Enode->MessageId);
360327557Sjkim    ExtraMessage = Enode->Message;
361327557Sjkim
362327557Sjkim    /* If a NULL line number, just print the decoded message */
363327557Sjkim
364327557Sjkim    if (!Enode->LineNumber)
365193529Sjkim    {
366327557Sjkim        fprintf (OutputFile, " %s %s\n\n", MainMessage, ExtraMessage);
367193529Sjkim        return;
368193529Sjkim    }
369193529Sjkim
370327557Sjkim    MsgLength = strlen (MainMessage);
371327557Sjkim    if (MsgLength == 0)
372118611Snjl    {
373327557Sjkim        /* Use the secondary/extra message as main message */
374118611Snjl
375327557Sjkim        MainMessage = Enode->Message;
376327557Sjkim        if (!MainMessage)
377118611Snjl        {
378327557Sjkim            MainMessage = "";
379327557Sjkim        }
380272444Sjkim
381327557Sjkim        MsgLength = strlen (MainMessage);
382327557Sjkim        ExtraMessage = NULL;
383327557Sjkim    }
384272444Sjkim
385327557Sjkim    if (Gbl_VerboseErrors && !PrematureEOF)
386327557Sjkim    {
387327557Sjkim        if (Total >= 256)
388327557Sjkim        {
389327557Sjkim            fprintf (OutputFile, "    %s",
390327557Sjkim                MainMessage);
391327557Sjkim        }
392327557Sjkim        else
393327557Sjkim        {
394327557Sjkim            SourceColumn = Enode->Column + Enode->FilenameLength + 6 + 2;
395327557Sjkim            ErrorColumn = ASL_ERROR_LEVEL_LENGTH + 5 + 2 + 1;
396250838Sjkim
397327557Sjkim            if ((MsgLength + ErrorColumn) < (SourceColumn - 1))
398118611Snjl            {
399327557Sjkim                fprintf (OutputFile, "%*s%s",
400327557Sjkim                    (int) ((SourceColumn - 1) - ErrorColumn),
401327557Sjkim                    MainMessage, " ^ ");
402118611Snjl            }
403327557Sjkim            else
404118611Snjl            {
405327557Sjkim                fprintf (OutputFile, "%*s %s",
406327557Sjkim                    (int) ((SourceColumn - ErrorColumn) + 1), "^",
407327557Sjkim                    MainMessage);
408118611Snjl            }
409327557Sjkim        }
410327557Sjkim    }
411327557Sjkim    else
412327557Sjkim    {
413327557Sjkim        fprintf (OutputFile, " %s", MainMessage);
414327557Sjkim    }
415118611Snjl
416327557Sjkim    /* Print the extra info message if present */
417250838Sjkim
418327557Sjkim    if (ExtraMessage)
419327557Sjkim    {
420327557Sjkim        fprintf (OutputFile, " (%s)", ExtraMessage);
421118611Snjl    }
422118611Snjl
423327557Sjkim    if (PrematureEOF)
424327557Sjkim    {
425327557Sjkim        fprintf (OutputFile, " and premature End-Of-File");
426327557Sjkim    }
427118611Snjl
428327557Sjkim    fprintf (OutputFile, "\n");
429327557Sjkim    if (Gbl_VerboseErrors && !Enode->SubError)
430327557Sjkim    {
431327557Sjkim        fprintf (OutputFile, "\n");
432327557Sjkim    }
433327557Sjkim}
434209746Sjkim
435327557Sjkim
436327557Sjkim/*******************************************************************************
437327557Sjkim *
438327557Sjkim * FUNCTION:    AePrintErrorSourceLine
439327557Sjkim *
440327557Sjkim * PARAMETERS:  OutputFile      - Output file
441327557Sjkim *              Enode           - Error node to print
442327557Sjkim *              PrematureEOF    - True = PrematureEOF has been reached
443327557Sjkim *              Total           - amount of characters printed so far
444327557Sjkim *
445327557Sjkim *
446327557Sjkim * RETURN:      Status
447327557Sjkim *
448327557Sjkim * DESCRIPTION: Print the source line of an error.
449327557Sjkim *
450327557Sjkim ******************************************************************************/
451327557Sjkim
452327557Sjkimstatic ACPI_STATUS
453327557SjkimAePrintErrorSourceLine (
454327557Sjkim    FILE                    *OutputFile,
455327557Sjkim    ASL_ERROR_MSG           *Enode,
456327557Sjkim    BOOLEAN                 *PrematureEOF,
457327557Sjkim    UINT32                  *Total)
458327557Sjkim{
459327557Sjkim    UINT8                   SourceByte;
460327557Sjkim    int                     Actual;
461327557Sjkim    size_t                  RActual;
462327557Sjkim    FILE                    *SourceFile = NULL;
463327557Sjkim    long                    FileSize;
464327557Sjkim
465327557Sjkim
466233250Sjkim    if (!Enode->SourceLine)
467209746Sjkim    {
468298714Sjkim        /*
469298714Sjkim         * Use the merged header/source file if present, otherwise
470298714Sjkim         * use input file
471298714Sjkim         */
472233250Sjkim        SourceFile = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
473233250Sjkim        if (!SourceFile)
474233250Sjkim        {
475233250Sjkim            SourceFile = Gbl_Files[ASL_FILE_INPUT].Handle;
476233250Sjkim        }
477216471Sjkim
478233250Sjkim        if (SourceFile)
479233250Sjkim        {
480233250Sjkim            /* Determine if the error occurred at source file EOF */
481216471Sjkim
482233250Sjkim            fseek (SourceFile, 0, SEEK_END);
483233250Sjkim            FileSize = ftell (SourceFile);
484233250Sjkim
485233250Sjkim            if ((long) Enode->LogicalByteOffset >= FileSize)
486233250Sjkim            {
487327557Sjkim                *PrematureEOF = TRUE;
488233250Sjkim            }
489216471Sjkim        }
490327557Sjkim        else
491327557Sjkim        {
492327557Sjkim            fprintf (OutputFile,
493327557Sjkim                "[*** iASL: Source File Does not exist ***]\n");
494327557Sjkim            return AE_IO_ERROR;
495327557Sjkim        }
496216471Sjkim    }
497216471Sjkim
498118611Snjl    /* Print filename and line number if present and valid */
499118611Snjl
500327557Sjkim    if (Gbl_VerboseErrors)
501118611Snjl    {
502327557Sjkim        fprintf (OutputFile, "%-8s", Enode->Filename);
503327557Sjkim
504327557Sjkim        if (Enode->SourceLine && Enode->LineNumber)
505118611Snjl        {
506327557Sjkim            fprintf (OutputFile, " %6u: %s",
507327557Sjkim                Enode->LineNumber, Enode->SourceLine);
508327557Sjkim        }
509327557Sjkim        else if (Enode->LineNumber)
510327557Sjkim        {
511327557Sjkim            fprintf (OutputFile, " %6u: ", Enode->LineNumber);
512118611Snjl
513327557Sjkim            /*
514327557Sjkim             * If not at EOF, get the corresponding source code line
515327557Sjkim             * and display it. Don't attempt this if we have a
516327557Sjkim             * premature EOF condition.
517327557Sjkim             */
518327557Sjkim            if (*PrematureEOF)
519118611Snjl            {
520327557Sjkim                fprintf (OutputFile, "\n");
521327557Sjkim                return AE_OK;
522327557Sjkim            }
523327557Sjkim            /*
524327557Sjkim             * Seek to the offset in the combined source file,
525327557Sjkim             * read the source line, and write it to the output.
526327557Sjkim             */
527327557Sjkim            Actual = fseek (SourceFile,
528327557Sjkim                (long) Enode->LogicalByteOffset, (int) SEEK_SET);
529327557Sjkim            if (Actual)
530327557Sjkim            {
531327557Sjkim                fprintf (OutputFile,
532327557Sjkim                    "[*** iASL: Seek error on source code temp file %s ***]",
533327557Sjkim                    Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
534327557Sjkim
535327557Sjkim                fprintf (OutputFile, "\n");
536327557Sjkim                return AE_OK;
537327557Sjkim            }
538327557Sjkim            RActual = fread (&SourceByte, 1, 1, SourceFile);
539327557Sjkim            if (RActual != 1)
540327557Sjkim            {
541327557Sjkim                fprintf (OutputFile,
542327557Sjkim                    "[*** iASL: Read error on source code temp file %s ***]",
543327557Sjkim                    Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
544327557Sjkim                return AE_IO_ERROR;
545327557Sjkim            }
546327557Sjkim                /* Read/write the source line, up to the maximum line length */
547327557Sjkim
548327557Sjkim            while (RActual && SourceByte && (SourceByte != '\n'))
549327557Sjkim            {
550327557Sjkim                if (*Total < 256)
551233250Sjkim                {
552327557Sjkim                    /* After the max line length, we will just read the line, no write */
553327557Sjkim
554327557Sjkim                    if (fwrite (&SourceByte, 1, 1, OutputFile) != 1)
555327557Sjkim                    {
556327557Sjkim                        printf ("[*** iASL: Write error on output file ***]\n");
557327557Sjkim                        return AE_IO_ERROR;
558327557Sjkim                    }
559233250Sjkim                }
560327557Sjkim                else if (*Total == 256)
561233250Sjkim                {
562327557Sjkim                    fprintf (OutputFile,
563327557Sjkim                        "\n[*** iASL: Very long input line, message below refers to column %u ***]",
564327557Sjkim                        Enode->Column);
565327557Sjkim                }
566118611Snjl
567327557Sjkim                RActual = fread (&SourceByte, 1, 1, SourceFile);
568327557Sjkim                if (RActual != 1)
569327557Sjkim                {
570327557Sjkim                    fprintf (OutputFile,
571327557Sjkim                        "[*** iASL: Read error on source code temp file %s ***]",
572327557Sjkim                        Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
573249112Sjkim
574327557Sjkim                    return AE_IO_ERROR;
575118611Snjl                }
576327557Sjkim                *Total += 1;
577118611Snjl            }
578118611Snjl
579327557Sjkim            fprintf (OutputFile, "\n");
580118611Snjl        }
581118611Snjl    }
582327557Sjkim    else
583327557Sjkim    {
584327557Sjkim        /*
585327557Sjkim         * Less verbose version of the error message, enabled via the
586327557Sjkim         * -vi switch. The format is compatible with MS Visual Studio.
587327557Sjkim         */
588327557Sjkim        fprintf (OutputFile, "%s", Enode->Filename);
589118611Snjl
590327557Sjkim        if (Enode->LineNumber)
591327557Sjkim        {
592327557Sjkim            fprintf (OutputFile, "(%u) : ",
593327557Sjkim                Enode->LineNumber);
594327557Sjkim        }
595118611Snjl    }
596272444Sjkim
597327557Sjkim    return AE_OK;
598327557Sjkim}
599272444Sjkim
600327557Sjkim/*******************************************************************************
601327557Sjkim *
602327557Sjkim * FUNCTION:    AePrintException
603327557Sjkim *
604327557Sjkim * PARAMETERS:  FileId          - ID of output file
605327557Sjkim *              Enode           - Error node to print
606327557Sjkim *              Header          - Additional text before each message
607327557Sjkim *
608327557Sjkim * RETURN:      None
609327557Sjkim *
610327557Sjkim * DESCRIPTION: Print the contents of an error node.
611327557Sjkim *
612327557Sjkim * NOTE:        We don't use the FlxxxFile I/O functions here because on error
613327557Sjkim *              they abort the compiler and call this function!  Since we
614327557Sjkim *              are reporting errors here, we ignore most output errors and
615327557Sjkim *              just try to get out as much as we can.
616327557Sjkim *
617327557Sjkim ******************************************************************************/
618272444Sjkim
619327557Sjkimvoid
620327557SjkimAePrintException (
621327557Sjkim    UINT32                  FileId,
622327557Sjkim    ASL_ERROR_MSG           *Enode,
623327557Sjkim    char                    *Header)
624327557Sjkim{
625327557Sjkim    FILE                    *OutputFile;
626327557Sjkim    BOOLEAN                 PrematureEOF = FALSE;
627327557Sjkim    UINT32                  Total = 0;
628327557Sjkim    ACPI_STATUS             Status;
629327557Sjkim    ASL_ERROR_MSG           *Child = Enode->SubError;
630272444Sjkim
631272444Sjkim
632327557Sjkim    if (Gbl_NoErrors)
633118611Snjl    {
634272444Sjkim        return;
635272444Sjkim    }
636118611Snjl
637327557Sjkim    /*
638327557Sjkim     * Only listing files have a header, and remarks/optimizations
639327557Sjkim     * are always output
640327557Sjkim     */
641327557Sjkim    if (!Header)
642272444Sjkim    {
643327557Sjkim        /* Ignore remarks if requested */
644272444Sjkim
645327557Sjkim        switch (Enode->Level)
646235945Sjkim        {
647327557Sjkim        case ASL_WARNING:
648327557Sjkim        case ASL_WARNING2:
649327557Sjkim        case ASL_WARNING3:
650118611Snjl
651327557Sjkim            if (!Gbl_DisplayWarnings)
652327557Sjkim            {
653327557Sjkim                return;
654327557Sjkim            }
655327557Sjkim            break;
656118611Snjl
657327557Sjkim        case ASL_REMARK:
658228110Sjkim
659327557Sjkim            if (!Gbl_DisplayRemarks)
660228110Sjkim            {
661327557Sjkim                return;
662228110Sjkim            }
663327557Sjkim            break;
664327557Sjkim
665327557Sjkim        case ASL_OPTIMIZATION:
666327557Sjkim
667327557Sjkim            if (!Gbl_DisplayOptimizations)
668118611Snjl            {
669327557Sjkim                return;
670118611Snjl            }
671327557Sjkim            break;
672327557Sjkim
673327557Sjkim        default:
674327557Sjkim
675327557Sjkim            break;
676272444Sjkim        }
677272444Sjkim    }
678327557Sjkim
679327557Sjkim    /* Get the various required file handles */
680327557Sjkim
681327557Sjkim    OutputFile = Gbl_Files[FileId].Handle;
682327557Sjkim
683327557Sjkim    if (Header)
684272444Sjkim    {
685327557Sjkim        fprintf (OutputFile, "%s", Header);
686272444Sjkim    }
687118611Snjl
688327557Sjkim    if (!Enode->Filename)
689327557Sjkim    {
690327557Sjkim        AeDecodeErrorMessageId (OutputFile, Enode, PrematureEOF, Total);
691327557Sjkim        return;
692327557Sjkim    }
693118611Snjl
694327557Sjkim    Status = AePrintErrorSourceLine (OutputFile, Enode, &PrematureEOF, &Total);
695327557Sjkim    if (ACPI_FAILURE (Status))
696272444Sjkim    {
697327557Sjkim        return;
698272444Sjkim    }
699118611Snjl
700327557Sjkim    /* If a NULL message ID, just print the raw message */
701327557Sjkim
702327557Sjkim    if (Enode->MessageId == 0)
703272444Sjkim    {
704327557Sjkim        fprintf (OutputFile, "%s\n", Enode->Message);
705327557Sjkim        return;
706272444Sjkim    }
707216471Sjkim
708327557Sjkim    AeDecodeErrorMessageId (OutputFile, Enode, PrematureEOF, Total);
709327557Sjkim
710327557Sjkim    while (Child)
711272444Sjkim    {
712272444Sjkim        fprintf (OutputFile, "\n");
713327557Sjkim        AePrintSubError (OutputFile, Child);
714327557Sjkim        Child = Child->SubError;
715118611Snjl    }
716118611Snjl}
717118611Snjl
718118611Snjl
719118611Snjl/*******************************************************************************
720118611Snjl *
721327557Sjkim * FUNCTION:    AePrintSubError
722327557Sjkim *
723327557Sjkim * PARAMETERS:  OutputFile      - Output file
724327557Sjkim *              Enode           - Error node to print
725327557Sjkim *
726327557Sjkim * RETURN:      None
727327557Sjkim *
728327557Sjkim * DESCRIPTION: Print the contents of an error nodes. This function is tailored
729327557Sjkim *              to print error nodes that are SubErrors within ASL_ERROR_MSG
730327557Sjkim *
731327557Sjkim ******************************************************************************/
732327557Sjkim
733327557Sjkimstatic void
734327557SjkimAePrintSubError (
735327557Sjkim    FILE                    *OutputFile,
736327557Sjkim    ASL_ERROR_MSG           *Enode)
737327557Sjkim{
738327557Sjkim    UINT32                  Total = 0;
739327557Sjkim    BOOLEAN                 PrematureEOF = FALSE;
740327557Sjkim    const char              *MainMessage;
741327557Sjkim
742327557Sjkim
743327557Sjkim    MainMessage = AeDecodeMessageId (Enode->MessageId);
744327557Sjkim
745327557Sjkim    fprintf (OutputFile, "    %s%s", MainMessage, "\n    ");
746327557Sjkim    (void) AePrintErrorSourceLine (OutputFile, Enode, &PrematureEOF, &Total);
747327557Sjkim    fprintf (OutputFile, "\n");
748327557Sjkim}
749327557Sjkim
750327557Sjkim
751327557Sjkim/*******************************************************************************
752327557Sjkim *
753118611Snjl * FUNCTION:    AePrintErrorLog
754118611Snjl *
755118611Snjl * PARAMETERS:  FileId           - Where to output the error log
756118611Snjl *
757118611Snjl * RETURN:      None
758118611Snjl *
759118611Snjl * DESCRIPTION: Print the entire contents of the error log
760118611Snjl *
761118611Snjl ******************************************************************************/
762118611Snjl
763118611Snjlvoid
764118611SnjlAePrintErrorLog (
765118611Snjl    UINT32                  FileId)
766118611Snjl{
767118611Snjl    ASL_ERROR_MSG           *Enode = Gbl_ErrorLog;
768118611Snjl
769118611Snjl
770118611Snjl    /* Walk the error node list */
771118611Snjl
772118611Snjl    while (Enode)
773118611Snjl    {
774118611Snjl        AePrintException (FileId, Enode, NULL);
775118611Snjl        Enode = Enode->Next;
776118611Snjl    }
777118611Snjl}
778118611Snjl
779118611Snjl
780118611Snjl/*******************************************************************************
781118611Snjl *
782327557Sjkim * FUNCTION:    AslInitEnode
783233250Sjkim *
784327557Sjkim * PARAMETERS:  InputEnode          - Input Error node to initialize
785327557Sjkim *              Level               - Seriousness (Warning/error, etc.)
786233250Sjkim *              MessageId           - Index into global message buffer
787327557Sjkim *              CurrentLineNumber   - Actual file line number
788327557Sjkim *              LogicalLineNumber   - Cumulative line number
789327557Sjkim *              LogicalByteOffset   - Byte offset in source file
790233250Sjkim *              Column              - Column in current line
791233250Sjkim *              Filename            - source filename
792233250Sjkim *              ExtraMessage        - additional error message
793327557Sjkim *              SourceLine          - Line of error source code
794327557Sjkim *              SubError            - SubError of this InputEnode
795233250Sjkim *
796233250Sjkim * RETURN:      None
797233250Sjkim *
798327557Sjkim * DESCRIPTION: Initialize an Error node
799233250Sjkim *
800233250Sjkim ******************************************************************************/
801233250Sjkim
802327557Sjkimstatic void AslInitEnode (
803327557Sjkim    ASL_ERROR_MSG           **InputEnode,
804233250Sjkim    UINT8                   Level,
805272444Sjkim    UINT16                  MessageId,
806233250Sjkim    UINT32                  LineNumber,
807327557Sjkim    UINT32                  LogicalLineNumber,
808327557Sjkim    UINT32                  LogicalByteOffset,
809233250Sjkim    UINT32                  Column,
810327557Sjkim    char                    *Filename,
811327557Sjkim    char                    *ExtraMessage,
812233250Sjkim    char                    *SourceLine,
813327557Sjkim    ASL_ERROR_MSG           *SubError)
814233250Sjkim{
815233250Sjkim    ASL_ERROR_MSG           *Enode;
816233250Sjkim
817233250Sjkim
818327557Sjkim    *InputEnode = UtLocalCalloc (sizeof (ASL_ERROR_MSG));
819327557Sjkim    Enode = *InputEnode;
820327557Sjkim    Enode->Level                = Level;
821327557Sjkim    Enode->MessageId            = MessageId;
822327557Sjkim    Enode->LineNumber           = LineNumber;
823327557Sjkim    Enode->LogicalLineNumber    = LogicalLineNumber;
824327557Sjkim    Enode->LogicalByteOffset    = LogicalByteOffset;
825327557Sjkim    Enode->Column               = Column;
826327557Sjkim    Enode->SubError             = SubError;
827327557Sjkim    Enode->Message              = NULL;
828327557Sjkim    Enode->SourceLine           = NULL;
829327557Sjkim    Enode->Filename             = NULL;
830233250Sjkim
831233250Sjkim    if (ExtraMessage)
832233250Sjkim    {
833233250Sjkim        /* Allocate a buffer for the message and a new error node */
834233250Sjkim
835327557Sjkim        Enode->Message = UtLocalCacheCalloc (strlen (ExtraMessage) + 1);
836233250Sjkim
837233250Sjkim        /* Keep a copy of the extra message */
838233250Sjkim
839327557Sjkim        strcpy (Enode->Message, ExtraMessage);
840233250Sjkim    }
841233250Sjkim
842327557Sjkim    if (SourceLine)
843327557Sjkim    {
844327557Sjkim        Enode->SourceLine = UtLocalCalloc (strlen (SourceLine) + 1);
845327557Sjkim        strcpy (Enode->SourceLine, SourceLine);
846327557Sjkim    }
847233250Sjkim
848233250Sjkim
849233250Sjkim    if (Filename)
850233250Sjkim    {
851272444Sjkim        Enode->Filename = Filename;
852233250Sjkim        Enode->FilenameLength = strlen (Filename);
853233250Sjkim        if (Enode->FilenameLength < 6)
854233250Sjkim        {
855233250Sjkim            Enode->FilenameLength = 6;
856233250Sjkim        }
857233250Sjkim    }
858327557Sjkim}
859233250Sjkim
860233250Sjkim
861327557Sjkim/*******************************************************************************
862327557Sjkim *
863327557Sjkim * FUNCTION:    AslCommonError2
864327557Sjkim *
865327557Sjkim * PARAMETERS:  Level               - Seriousness (Warning/error, etc.)
866327557Sjkim *              MessageId           - Index into global message buffer
867327557Sjkim *              LineNumber          - Actual file line number
868327557Sjkim *              Column              - Column in current line
869327557Sjkim *              SourceLine          - Actual source code line
870327557Sjkim *              Filename            - source filename
871327557Sjkim *              ExtraMessage        - additional error message
872327557Sjkim *
873327557Sjkim * RETURN:      None
874327557Sjkim *
875327557Sjkim * DESCRIPTION: Create a new error node and add it to the error log
876327557Sjkim *
877327557Sjkim ******************************************************************************/
878233250Sjkim
879327557Sjkimvoid
880327557SjkimAslCommonError2 (
881327557Sjkim    UINT8                   Level,
882327557Sjkim    UINT16                  MessageId,
883327557Sjkim    UINT32                  LineNumber,
884327557Sjkim    UINT32                  Column,
885327557Sjkim    char                    *SourceLine,
886327557Sjkim    char                    *Filename,
887327557Sjkim    char                    *ExtraMessage)
888327557Sjkim{
889327557Sjkim    AslLogNewError (Level, MessageId, LineNumber, LineNumber, 0, Column,
890327557Sjkim        Filename, ExtraMessage, SourceLine, NULL);
891233250Sjkim}
892233250Sjkim
893233250Sjkim
894233250Sjkim/*******************************************************************************
895233250Sjkim *
896118611Snjl * FUNCTION:    AslCommonError
897118611Snjl *
898118611Snjl * PARAMETERS:  Level               - Seriousness (Warning/error, etc.)
899118611Snjl *              MessageId           - Index into global message buffer
900118611Snjl *              CurrentLineNumber   - Actual file line number
901118611Snjl *              LogicalLineNumber   - Cumulative line number
902118611Snjl *              LogicalByteOffset   - Byte offset in source file
903118611Snjl *              Column              - Column in current line
904118611Snjl *              Filename            - source filename
905118611Snjl *              ExtraMessage        - additional error message
906118611Snjl *
907151937Sjkim * RETURN:      None
908118611Snjl *
909118611Snjl * DESCRIPTION: Create a new error node and add it to the error log
910118611Snjl *
911118611Snjl ******************************************************************************/
912118611Snjl
913118611Snjlvoid
914118611SnjlAslCommonError (
915118611Snjl    UINT8                   Level,
916272444Sjkim    UINT16                  MessageId,
917118611Snjl    UINT32                  CurrentLineNumber,
918118611Snjl    UINT32                  LogicalLineNumber,
919118611Snjl    UINT32                  LogicalByteOffset,
920118611Snjl    UINT32                  Column,
921118611Snjl    char                    *Filename,
922118611Snjl    char                    *ExtraMessage)
923118611Snjl{
924327557Sjkim    AslLogNewError (Level, MessageId, CurrentLineNumber, LogicalLineNumber,
925327557Sjkim        LogicalByteOffset, Column, Filename, ExtraMessage,
926327557Sjkim        NULL, NULL);
927327557Sjkim}
928118611Snjl
929118611Snjl
930327557Sjkim/*******************************************************************************
931327557Sjkim *
932327557Sjkim * FUNCTION:    AslLogNewError
933327557Sjkim *
934327557Sjkim * PARAMETERS:  Level               - Seriousness (Warning/error, etc.)
935327557Sjkim *              MessageId           - Index into global message buffer
936327557Sjkim *              CurrentLineNumber   - Actual file line number
937327557Sjkim *              LogicalLineNumber   - Cumulative line number
938327557Sjkim *              LogicalByteOffset   - Byte offset in source file
939327557Sjkim *              Column              - Column in current line
940327557Sjkim *              Filename            - source filename
941327557Sjkim *              Message             - additional error message
942327557Sjkim *              SourceLine          - Actual line of source code
943327557Sjkim *              SubError            - Sub-error associated with this error
944327557Sjkim *
945327557Sjkim * RETURN:      None
946327557Sjkim *
947327557Sjkim * DESCRIPTION: Create a new error node and add it to the error log
948327557Sjkim *
949327557Sjkim ******************************************************************************/
950327557Sjkimstatic void
951327557SjkimAslLogNewError (
952327557Sjkim    UINT8                   Level,
953327557Sjkim    UINT16                  MessageId,
954327557Sjkim    UINT32                  LineNumber,
955327557Sjkim    UINT32                  LogicalLineNumber,
956327557Sjkim    UINT32                  LogicalByteOffset,
957327557Sjkim    UINT32                  Column,
958327557Sjkim    char                    *Filename,
959327557Sjkim    char                    *Message,
960327557Sjkim    char                    *SourceLine,
961327557Sjkim    ASL_ERROR_MSG           *SubError)
962327557Sjkim{
963327557Sjkim    ASL_ERROR_MSG           *Enode = NULL;
964118611Snjl
965118611Snjl
966327557Sjkim    AslInitEnode (&Enode, Level, MessageId, LineNumber, LogicalLineNumber,
967327557Sjkim        LogicalByteOffset, Column, Filename, Message, SourceLine,
968327557Sjkim        SubError);
969118611Snjl
970118611Snjl    /* Add the new node to the error node list */
971118611Snjl
972118611Snjl    AeAddToErrorLog (Enode);
973118611Snjl
974118611Snjl    if (Gbl_DebugFlag)
975118611Snjl    {
976118611Snjl        /* stderr is a file, send error to it immediately */
977118611Snjl
978118611Snjl        AePrintException (ASL_FILE_STDERR, Enode, NULL);
979118611Snjl    }
980118611Snjl
981118611Snjl    Gbl_ExceptionCount[Level]++;
982118611Snjl    if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
983118611Snjl    {
984209746Sjkim        printf ("\nMaximum error count (%u) exceeded\n", ASL_MAX_ERROR_COUNT);
985118611Snjl
986118611Snjl        Gbl_SourceLine = 0;
987118611Snjl        Gbl_NextError = Gbl_ErrorLog;
988118611Snjl        CmCleanupAndExit ();
989199337Sjkim        exit(1);
990118611Snjl    }
991118611Snjl
992118611Snjl    return;
993118611Snjl}
994118611Snjl
995322877Sjkim/*******************************************************************************
996322877Sjkim *
997322877Sjkim * FUNCTION:    AslIsExceptionIgnored
998322877Sjkim *
999327557Sjkim * PARAMETERS:  Level           - Seriousness (Warning/error, etc.)
1000327557Sjkim *              MessageId       - Index into global message buffer
1001322877Sjkim *
1002322877Sjkim * RETURN:      BOOLEAN
1003322877Sjkim *
1004322877Sjkim * DESCRIPTION: Check if a particular exception is ignored. In this case it
1005322877Sjkim *              means that the exception is (expected or disabled.
1006322877Sjkim *
1007322877Sjkim ******************************************************************************/
1008118611Snjl
1009322877SjkimBOOLEAN
1010322877SjkimAslIsExceptionIgnored (
1011322877Sjkim    UINT8                   Level,
1012322877Sjkim    UINT16                  MessageId)
1013322877Sjkim{
1014327557Sjkim    BOOLEAN                 ExceptionIgnored;
1015322877Sjkim
1016322877Sjkim
1017322877Sjkim    /* Note: this allows exception to be disabled and expected */
1018322877Sjkim
1019322877Sjkim    ExceptionIgnored = AslIsExceptionDisabled (Level, MessageId);
1020322877Sjkim    ExceptionIgnored |= AslIsExceptionExpected (Level, MessageId);
1021322877Sjkim
1022322877Sjkim    return (Gbl_AllExceptionsDisabled || ExceptionIgnored);
1023322877Sjkim}
1024322877Sjkim
1025322877Sjkim
1026118611Snjl/*******************************************************************************
1027118611Snjl *
1028322877Sjkim * FUNCTION:    AslCheckExpectException
1029322877Sjkim *
1030322877Sjkim * PARAMETERS:  none
1031322877Sjkim *
1032322877Sjkim * RETURN:      none
1033322877Sjkim *
1034322877Sjkim * DESCRIPTION: Check the global expected messages table and raise an error
1035322877Sjkim *              for each message that has not been received.
1036322877Sjkim *
1037322877Sjkim ******************************************************************************/
1038322877Sjkim
1039322877Sjkimvoid
1040322877SjkimAslCheckExpectedExceptions (
1041322877Sjkim    void)
1042322877Sjkim{
1043327557Sjkim    UINT8                   i;
1044322877Sjkim
1045327557Sjkim
1046322877Sjkim    for (i = 0; i < Gbl_ExpectedMessagesIndex; ++i)
1047322877Sjkim    {
1048322877Sjkim        if (!Gbl_ExpectedMessages[i].MessageReceived)
1049322877Sjkim        {
1050322877Sjkim            AslError (ASL_ERROR, ASL_MSG_EXCEPTION_NOT_RECEIVED, NULL,
1051322877Sjkim                Gbl_ExpectedMessages[i].MessageIdStr);
1052322877Sjkim        }
1053322877Sjkim    }
1054322877Sjkim}
1055322877Sjkim
1056322877Sjkim
1057322877Sjkim/*******************************************************************************
1058322877Sjkim *
1059322877Sjkim * FUNCTION:    AslExpectException
1060322877Sjkim *
1061322877Sjkim * PARAMETERS:  MessageIdString     - ID of excepted exception during compile
1062322877Sjkim *
1063322877Sjkim * RETURN:      Status
1064322877Sjkim *
1065322877Sjkim * DESCRIPTION: Enter a message ID into the global expected messages table
1066322877Sjkim *              If these messages are not raised during the compilation, throw
1067322877Sjkim *              an error.
1068322877Sjkim *
1069322877Sjkim ******************************************************************************/
1070322877Sjkim
1071322877SjkimACPI_STATUS
1072322877SjkimAslExpectException (
1073322877Sjkim    char                    *MessageIdString)
1074322877Sjkim{
1075322877Sjkim    UINT32                  MessageId;
1076322877Sjkim
1077322877Sjkim
1078322877Sjkim    /* Convert argument to an integer and validate it */
1079322877Sjkim
1080322877Sjkim    MessageId = (UINT32) strtoul (MessageIdString, NULL, 0);
1081322877Sjkim
1082322877Sjkim    if (MessageId > 6999)
1083322877Sjkim    {
1084322877Sjkim        printf ("\"%s\" is not a valid warning/remark/erro ID\n",
1085322877Sjkim            MessageIdString);
1086322877Sjkim        return (AE_BAD_PARAMETER);
1087322877Sjkim    }
1088322877Sjkim
1089322877Sjkim    /* Insert value into the global expected message array */
1090322877Sjkim
1091322877Sjkim    if (Gbl_ExpectedMessagesIndex >= ASL_MAX_EXPECTED_MESSAGES)
1092322877Sjkim    {
1093322877Sjkim        printf ("Too many messages have been registered as expected (max %u)\n",
1094322877Sjkim            ASL_MAX_DISABLED_MESSAGES);
1095322877Sjkim        return (AE_LIMIT);
1096322877Sjkim    }
1097322877Sjkim
1098322877Sjkim    Gbl_ExpectedMessages[Gbl_ExpectedMessagesIndex].MessageId = MessageId;
1099322877Sjkim    Gbl_ExpectedMessages[Gbl_ExpectedMessagesIndex].MessageIdStr = MessageIdString;
1100322877Sjkim    Gbl_ExpectedMessages[Gbl_ExpectedMessagesIndex].MessageReceived = FALSE;
1101322877Sjkim    Gbl_ExpectedMessagesIndex++;
1102322877Sjkim    return (AE_OK);
1103322877Sjkim}
1104322877Sjkim
1105322877Sjkim
1106322877Sjkim/*******************************************************************************
1107322877Sjkim *
1108250838Sjkim * FUNCTION:    AslDisableException
1109250838Sjkim *
1110250838Sjkim * PARAMETERS:  MessageIdString     - ID to be disabled
1111250838Sjkim *
1112250838Sjkim * RETURN:      Status
1113250838Sjkim *
1114250838Sjkim * DESCRIPTION: Enter a message ID into the global disabled messages table
1115250838Sjkim *
1116250838Sjkim ******************************************************************************/
1117250838Sjkim
1118250838SjkimACPI_STATUS
1119250838SjkimAslDisableException (
1120250838Sjkim    char                    *MessageIdString)
1121250838Sjkim{
1122250838Sjkim    UINT32                  MessageId;
1123250838Sjkim
1124250838Sjkim
1125250838Sjkim    /* Convert argument to an integer and validate it */
1126250838Sjkim
1127250838Sjkim    MessageId = (UINT32) strtoul (MessageIdString, NULL, 0);
1128250838Sjkim
1129327557Sjkim    if ((MessageId < 2000) || (MessageId > 6999))
1130250838Sjkim    {
1131327557Sjkim        printf ("\"%s\" is not a valid warning/remark/error ID\n",
1132250838Sjkim            MessageIdString);
1133250838Sjkim        return (AE_BAD_PARAMETER);
1134250838Sjkim    }
1135250838Sjkim
1136250838Sjkim    /* Insert value into the global disabled message array */
1137250838Sjkim
1138250838Sjkim    if (Gbl_DisabledMessagesIndex >= ASL_MAX_DISABLED_MESSAGES)
1139250838Sjkim    {
1140250838Sjkim        printf ("Too many messages have been disabled (max %u)\n",
1141250838Sjkim            ASL_MAX_DISABLED_MESSAGES);
1142250838Sjkim        return (AE_LIMIT);
1143250838Sjkim    }
1144250838Sjkim
1145250838Sjkim    Gbl_DisabledMessages[Gbl_DisabledMessagesIndex] = MessageId;
1146250838Sjkim    Gbl_DisabledMessagesIndex++;
1147250838Sjkim    return (AE_OK);
1148250838Sjkim}
1149250838Sjkim
1150250838Sjkim
1151250838Sjkim/*******************************************************************************
1152250838Sjkim *
1153250838Sjkim * FUNCTION:    AslIsExceptionDisabled
1154250838Sjkim *
1155327557Sjkim * PARAMETERS:  Level           - Seriousness (Warning/error, etc.)
1156327557Sjkim *              MessageId       - Index into global message buffer
1157250838Sjkim *
1158250838Sjkim * RETURN:      TRUE if exception/message should be ignored
1159250838Sjkim *
1160250838Sjkim * DESCRIPTION: Check if the user has specified options such that this
1161250838Sjkim *              exception should be ignored
1162250838Sjkim *
1163250838Sjkim ******************************************************************************/
1164250838Sjkim
1165322877Sjkimstatic BOOLEAN
1166322877SjkimAslIsExceptionExpected (
1167322877Sjkim    UINT8                   Level,
1168322877Sjkim    UINT16                  MessageId)
1169322877Sjkim{
1170322877Sjkim    UINT32                  EncodedMessageId;
1171322877Sjkim    UINT32                  i;
1172322877Sjkim
1173322877Sjkim
1174327557Sjkim    /* Mark this exception as received */
1175327557Sjkim
1176322877Sjkim    EncodedMessageId = AeBuildFullExceptionCode (Level, MessageId);
1177322877Sjkim    for (i = 0; i < Gbl_ExpectedMessagesIndex; i++)
1178322877Sjkim    {
1179322877Sjkim        /* Simple implementation via fixed array */
1180322877Sjkim
1181322877Sjkim        if (EncodedMessageId == Gbl_ExpectedMessages[i].MessageId)
1182322877Sjkim        {
1183322877Sjkim            return (Gbl_ExpectedMessages[i].MessageReceived = TRUE);
1184322877Sjkim        }
1185322877Sjkim    }
1186322877Sjkim
1187322877Sjkim    return (FALSE);
1188322877Sjkim}
1189322877Sjkim
1190322877Sjkim
1191322877Sjkim/*******************************************************************************
1192322877Sjkim *
1193322877Sjkim * FUNCTION:    AslIsExceptionDisabled
1194322877Sjkim *
1195322877Sjkim * PARAMETERS:  Level               - Seriousness (Warning/error, etc.)
1196322877Sjkim *              MessageId           - Index into global message buffer
1197322877Sjkim *
1198322877Sjkim * RETURN:      TRUE if exception/message should be ignored
1199322877Sjkim *
1200322877Sjkim * DESCRIPTION: Check if the user has specified options such that this
1201322877Sjkim *              exception should be ignored
1202322877Sjkim *
1203322877Sjkim ******************************************************************************/
1204322877Sjkim
1205322877Sjkimstatic BOOLEAN
1206250838SjkimAslIsExceptionDisabled (
1207250838Sjkim    UINT8                   Level,
1208272444Sjkim    UINT16                  MessageId)
1209250838Sjkim{
1210250838Sjkim    UINT32                  EncodedMessageId;
1211250838Sjkim    UINT32                  i;
1212250838Sjkim
1213250838Sjkim
1214250838Sjkim    switch (Level)
1215250838Sjkim    {
1216250838Sjkim    case ASL_WARNING2:
1217250838Sjkim    case ASL_WARNING3:
1218250838Sjkim
1219250838Sjkim        /* Check for global disable via -w1/-w2/-w3 options */
1220250838Sjkim
1221250838Sjkim        if (Level > Gbl_WarningLevel)
1222250838Sjkim        {
1223250838Sjkim            return (TRUE);
1224250838Sjkim        }
1225250838Sjkim        /* Fall through */
1226250838Sjkim
1227250838Sjkim    case ASL_WARNING:
1228250838Sjkim    case ASL_REMARK:
1229327557Sjkim    case ASL_ERROR:
1230250838Sjkim        /*
1231327557Sjkim         * Ignore this error/warning/remark if it has been disabled by
1232250838Sjkim         * the user (-vw option)
1233250838Sjkim         */
1234272444Sjkim        EncodedMessageId = AeBuildFullExceptionCode (Level, MessageId);
1235250838Sjkim        for (i = 0; i < Gbl_DisabledMessagesIndex; i++)
1236250838Sjkim        {
1237250838Sjkim            /* Simple implementation via fixed array */
1238250838Sjkim
1239250838Sjkim            if (EncodedMessageId == Gbl_DisabledMessages[i])
1240250838Sjkim            {
1241250838Sjkim                return (TRUE);
1242250838Sjkim            }
1243250838Sjkim        }
1244250838Sjkim        break;
1245250838Sjkim
1246250838Sjkim    default:
1247250838Sjkim        break;
1248250838Sjkim    }
1249250838Sjkim
1250250838Sjkim    return (FALSE);
1251250838Sjkim}
1252250838Sjkim
1253250838Sjkim
1254250838Sjkim/*******************************************************************************
1255250838Sjkim *
1256327557Sjkim * FUNCTION:    AslDualParseOpError
1257327557Sjkim *
1258327557Sjkim * PARAMETERS:  Level           - Seriousness (Warning/error, etc.)
1259327557Sjkim *              MainMsgId       - Index into global message buffer
1260327557Sjkim *              MainOp          - Parse node where error happened
1261327557Sjkim *              MainMsg         - Message pertaining to the MainOp
1262327557Sjkim *              SubMsgId        - Index into global message buffer
1263327557Sjkim *              SubOp           - Additional parse node for better message
1264327557Sjkim *              SubMsg          - Message pertainint to SubOp
1265327557Sjkim *
1266327557Sjkim *
1267327557Sjkim * RETURN:      None
1268327557Sjkim *
1269327557Sjkim * DESCRIPTION: Main error reporting routine for the ASL compiler for error
1270327557Sjkim *              messages that point to multiple parse objects.
1271327557Sjkim *
1272327557Sjkim ******************************************************************************/
1273327557Sjkim
1274327557Sjkimvoid
1275327557SjkimAslDualParseOpError (
1276327557Sjkim    UINT8                   Level,
1277327557Sjkim    UINT16                  MainMsgId,
1278327557Sjkim    ACPI_PARSE_OBJECT       *MainOp,
1279327557Sjkim    char                    *MainMsg,
1280327557Sjkim    UINT16                  SubMsgId,
1281327557Sjkim    ACPI_PARSE_OBJECT       *SubOp,
1282327557Sjkim    char                    *SubMsg)
1283327557Sjkim{
1284327557Sjkim    ASL_ERROR_MSG           *SubEnode = NULL;
1285327557Sjkim
1286327557Sjkim
1287327557Sjkim    /* Check if user wants to ignore this exception */
1288327557Sjkim
1289327557Sjkim    if (AslIsExceptionIgnored (Level, MainMsgId) || !MainOp)
1290327557Sjkim    {
1291327557Sjkim        return;
1292327557Sjkim    }
1293327557Sjkim
1294327557Sjkim    if (SubOp)
1295327557Sjkim    {
1296327557Sjkim        AslInitEnode (&SubEnode, Level, SubMsgId, SubOp->Asl.LineNumber,
1297327557Sjkim            SubOp->Asl.LogicalLineNumber, SubOp->Asl.LogicalByteOffset,
1298327557Sjkim            SubOp->Asl.Column, SubOp->Asl.Filename, SubMsg,
1299327557Sjkim            NULL, NULL);
1300327557Sjkim    }
1301327557Sjkim
1302327557Sjkim    AslLogNewError (Level, MainMsgId, MainOp->Asl.LineNumber,
1303327557Sjkim        MainOp->Asl.LogicalLineNumber, MainOp->Asl.LogicalByteOffset,
1304327557Sjkim        MainOp->Asl.Column, MainOp->Asl.Filename, MainMsg,
1305327557Sjkim        NULL, SubEnode);
1306327557Sjkim}
1307327557Sjkim
1308327557Sjkim
1309327557Sjkim/*******************************************************************************
1310327557Sjkim *
1311118611Snjl * FUNCTION:    AslError
1312118611Snjl *
1313118611Snjl * PARAMETERS:  Level               - Seriousness (Warning/error, etc.)
1314118611Snjl *              MessageId           - Index into global message buffer
1315118611Snjl *              Op                  - Parse node where error happened
1316118611Snjl *              ExtraMessage        - additional error message
1317118611Snjl *
1318118611Snjl * RETURN:      None
1319118611Snjl *
1320118611Snjl * DESCRIPTION: Main error reporting routine for the ASL compiler (all code
1321118611Snjl *              except the parser.)
1322118611Snjl *
1323118611Snjl ******************************************************************************/
1324118611Snjl
1325118611Snjlvoid
1326118611SnjlAslError (
1327118611Snjl    UINT8                   Level,
1328272444Sjkim    UINT16                  MessageId,
1329118611Snjl    ACPI_PARSE_OBJECT       *Op,
1330118611Snjl    char                    *ExtraMessage)
1331118611Snjl{
1332118611Snjl    if (Op)
1333118611Snjl    {
1334118611Snjl        AslCommonError (Level, MessageId, Op->Asl.LineNumber,
1335250838Sjkim            Op->Asl.LogicalLineNumber,
1336250838Sjkim            Op->Asl.LogicalByteOffset,
1337250838Sjkim            Op->Asl.Column,
1338250838Sjkim            Op->Asl.Filename, ExtraMessage);
1339118611Snjl    }
1340118611Snjl    else
1341118611Snjl    {
1342118611Snjl        AslCommonError (Level, MessageId, 0,
1343250838Sjkim            0, 0, 0, NULL, ExtraMessage);
1344118611Snjl    }
1345118611Snjl}
1346118611Snjl
1347118611Snjl
1348118611Snjl/*******************************************************************************
1349118611Snjl *
1350118611Snjl * FUNCTION:    AslCoreSubsystemError
1351118611Snjl *
1352118611Snjl * PARAMETERS:  Op                  - Parse node where error happened
1353272444Sjkim *              Status              - The ACPICA Exception
1354118611Snjl *              ExtraMessage        - additional error message
1355118611Snjl *              Abort               - TRUE -> Abort compilation
1356118611Snjl *
1357118611Snjl * RETURN:      None
1358118611Snjl *
1359272444Sjkim * DESCRIPTION: Error reporting routine for exceptions returned by the ACPICA
1360272444Sjkim *              core subsystem.
1361118611Snjl *
1362118611Snjl ******************************************************************************/
1363118611Snjl
1364118611Snjlvoid
1365118611SnjlAslCoreSubsystemError (
1366118611Snjl    ACPI_PARSE_OBJECT       *Op,
1367118611Snjl    ACPI_STATUS             Status,
1368118611Snjl    char                    *ExtraMessage,
1369118611Snjl    BOOLEAN                 Abort)
1370118611Snjl{
1371118611Snjl
1372118611Snjl    sprintf (MsgBuffer, "%s %s", AcpiFormatException (Status), ExtraMessage);
1373118611Snjl
1374118611Snjl    if (Op)
1375118611Snjl    {
1376298714Sjkim        AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION,
1377298714Sjkim            Op->Asl.LineNumber,
1378298714Sjkim            Op->Asl.LogicalLineNumber,
1379298714Sjkim            Op->Asl.LogicalByteOffset,
1380298714Sjkim            Op->Asl.Column,
1381298714Sjkim            Op->Asl.Filename, MsgBuffer);
1382118611Snjl    }
1383118611Snjl    else
1384118611Snjl    {
1385298714Sjkim        AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION,
1386298714Sjkim            0, 0, 0, 0, NULL, MsgBuffer);
1387118611Snjl    }
1388118611Snjl
1389118611Snjl    if (Abort)
1390118611Snjl    {
1391118611Snjl        AslAbort ();
1392118611Snjl    }
1393118611Snjl}
1394118611Snjl
1395118611Snjl
1396118611Snjl/*******************************************************************************
1397118611Snjl *
1398118611Snjl * FUNCTION:    AslCompilererror
1399118611Snjl *
1400118611Snjl * PARAMETERS:  CompilerMessage         - Error message from the parser
1401118611Snjl *
1402151937Sjkim * RETURN:      Status (0 for now)
1403118611Snjl *
1404118611Snjl * DESCRIPTION: Report an error situation discovered in a production
1405151937Sjkim *              NOTE: don't change the name of this function, it is called
1406151937Sjkim *              from the auto-generated parser.
1407118611Snjl *
1408118611Snjl ******************************************************************************/
1409118611Snjl
1410118611Snjlint
1411118611SnjlAslCompilererror (
1412228110Sjkim    const char              *CompilerMessage)
1413118611Snjl{
1414118611Snjl
1415278970Sjkim    Gbl_SyntaxError++;
1416278970Sjkim
1417118611Snjl    AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, Gbl_CurrentLineNumber,
1418228110Sjkim        Gbl_LogicalLineNumber, Gbl_CurrentLineOffset,
1419228110Sjkim        Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename,
1420228110Sjkim        ACPI_CAST_PTR (char, CompilerMessage));
1421118611Snjl
1422241973Sjkim    return (0);
1423118611Snjl}
1424