Subversion Repositories Kolibri OS

Rev

Rev 1498 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1498 serge 1
 
2
 *
3
 * Module Name: aslerror - Error handling and statistics
4
 *
5
 *****************************************************************************/
6
7
 
8
 *
9
 * 1. Copyright Notice
10
 *
11
 * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
2216 Serge 12
 * All rights reserved.
1498 serge 13
 *
14
 * 2. License
15
 *
16
 * 2.1. This is your license from Intel Corp. under its intellectual property
17
 * rights.  You may have additional license terms from the party that provided
18
 * you this software, covering your right to use that party's intellectual
19
 * property rights.
20
 *
21
 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22
 * copy of the source code appearing in this file ("Covered Code") an
23
 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24
 * base code distributed originally by Intel ("Original Intel Code") to copy,
25
 * make derivatives, distribute, use and display any portion of the Covered
26
 * Code in any form, with the right to sublicense such rights; and
27
 *
28
 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29
 * license (with the right to sublicense), under only those claims of Intel
30
 * patents that are infringed by the Original Intel Code, to make, use, sell,
31
 * offer to sell, and import the Covered Code and derivative works thereof
32
 * solely to the minimum extent necessary to exercise the above copyright
33
 * license, and in no event shall the patent license extend to any additions
34
 * to or modifications of the Original Intel Code.  No other license or right
35
 * is granted directly or by implication, estoppel or otherwise;
36
 *
37
 * The above copyright and patent license is granted only if the following
38
 * conditions are met:
39
 *
40
 * 3. Conditions
41
 *
42
 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43
 * Redistribution of source code of any substantial portion of the Covered
44
 * Code or modification with rights to further distribute source must include
45
 * the above Copyright Notice, the above License, this list of Conditions,
46
 * and the following Disclaimer and Export Compliance provision.  In addition,
47
 * Licensee must cause all Covered Code to which Licensee contributes to
48
 * contain a file documenting the changes Licensee made to create that Covered
49
 * Code and the date of any change.  Licensee must include in that file the
50
 * documentation of any changes made by any predecessor Licensee.  Licensee
51
 * must include a prominent statement that the modification is derived,
52
 * directly or indirectly, from Original Intel Code.
53
 *
54
 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55
 * Redistribution of source code of any substantial portion of the Covered
56
 * Code or modification without rights to further distribute source must
57
 * include the following Disclaimer and Export Compliance provision in the
58
 * documentation and/or other materials provided with distribution.  In
59
 * addition, Licensee may not authorize further sublicense of source of any
60
 * portion of the Covered Code, and must include terms to the effect that the
61
 * license from Licensee to its licensee is limited to the intellectual
62
 * property embodied in the software Licensee provides to its licensee, and
63
 * not to intellectual property embodied in modifications its licensee may
64
 * make.
65
 *
66
 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67
 * substantial portion of the Covered Code or modification must reproduce the
68
 * above Copyright Notice, and the following Disclaimer and Export Compliance
69
 * provision in the documentation and/or other materials provided with the
70
 * distribution.
71
 *
72
 * 3.4. Intel retains all right, title, and interest in and to the Original
73
 * Intel Code.
74
 *
75
 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76
 * Intel shall be used in advertising or otherwise to promote the sale, use or
77
 * other dealings in products derived from or relating to the Covered Code
78
 * without prior written authorization from Intel.
79
 *
80
 * 4. Disclaimer and Export Compliance
81
 *
82
 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83
 * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84
 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
85
 * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
86
 * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
87
 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88
 * PARTICULAR PURPOSE.
89
 *
90
 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91
 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92
 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93
 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94
 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95
 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
96
 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97
 * LIMITED REMEDY.
98
 *
99
 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100
 * software or system incorporating such software without first obtaining any
101
 * required license or other approval from the U. S. Department of Commerce or
102
 * any other agency or department of the United States Government.  In the
103
 * event Licensee exports any such software from the United States or
104
 * re-exports any such software from a foreign destination, Licensee shall
105
 * ensure that the distribution and export/re-export of the software is in
106
 * compliance with all laws, regulations, orders, or other restrictions of the
107
 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108
 * any of its subsidiaries will export/re-export any technical data, process,
109
 * software, or service, directly or indirectly, to any country for which the
110
 * United States government or any agency thereof requires an export license,
111
 * other governmental approval, or letter of assurance, without first obtaining
112
 * such license, approval or letter.
113
 *
114
 *****************************************************************************/
115
116
 
117
#include "aslcompiler.h"
118
119
 
120
        ACPI_MODULE_NAME    ("aslerror")
121
122
 
123
124
 
125
AeAddToErrorLog (
126
    ASL_ERROR_MSG           *Enode);
127
128
 
129
 
130
AeClearErrorLog (
131
    void)
132
{
133
    ASL_ERROR_MSG           *Enode = Gbl_ErrorLog;
134
    ASL_ERROR_MSG           *Next;
135
136
 
137
138
 
139
    {
140
        Next = Enode->Next;
141
        ACPI_FREE (Enode);
142
        Enode = Next;
143
    }
144
145
 
146
}
147
148
 
149
 
150
 *
151
 * FUNCTION:    AeAddToErrorLog
152
 *
153
 * PARAMETERS:  Enode       - An error node to add to the log
154
 *
155
 * RETURN:      None
156
 *
157
 * DESCRIPTION: Add a new error node to the error log.  The error log is
158
 *              ordered by the "logical" line number (cumulative line number
159
 *              including all include files.)
160
 *
161
 ******************************************************************************/
162
163
 
164
AeAddToErrorLog (
165
    ASL_ERROR_MSG           *Enode)
166
{
167
    ASL_ERROR_MSG           *Next;
168
    ASL_ERROR_MSG           *Prev;
169
170
 
171
 
172
173
 
174
    {
175
        Gbl_ErrorLog = Enode;
176
        return;
177
    }
178
179
 
180
     * Walk error list until we find a line number greater than ours.
181
     * List is sorted according to line number.
182
     */
183
    Prev = NULL;
184
    Next = Gbl_ErrorLog;
185
186
 
187
           (Next->LogicalLineNumber <= Enode->LogicalLineNumber))
188
    {
189
        Prev = Next;
190
        Next = Next->Next;
191
    }
192
193
 
194
195
 
196
197
 
198
    {
199
        Prev->Next = Enode;
200
    }
201
    else
202
    {
203
        Gbl_ErrorLog = Enode;
204
    }
205
}
206
207
 
208
 
209
 *
210
 * FUNCTION:    AePrintException
211
 *
212
 * PARAMETERS:  FileId          - ID of output file
213
 *              Enode           - Error node to print
214
 *              Header          - Additional text before each message
215
 *
216
 * RETURN:      None
217
 *
218
 * DESCRIPTION: Print the contents of an error node.
219
 *
220
 * NOTE:        We don't use the FlxxxFile I/O functions here because on error
221
 *              they abort the compiler and call this function!  Since we
222
 *              are reporting errors here, we ignore most output errors and
223
 *              just try to get out as much as we can.
224
 *
225
 ******************************************************************************/
226
227
 
228
AePrintException (
229
    UINT32                  FileId,
230
    ASL_ERROR_MSG           *Enode,
231
    char                    *Header)
232
{
233
    UINT8                   SourceByte;
234
    int                     Actual;
235
    size_t                  RActual;
236
    UINT32                  MsgLength;
237
    char                    *MainMessage;
238
    char                    *ExtraMessage;
239
    UINT32                  SourceColumn;
240
    UINT32                  ErrorColumn;
241
    FILE                    *OutputFile;
242
    FILE                    *SourceFile;
243
    long                    FileSize;
2216 Serge 244
    BOOLEAN                 PrematureEOF = FALSE;
245
1498 serge 246
 
247
 
248
    {
249
        return;
250
    }
251
252
 
253
     * Only listing files have a header, and remarks/optimizations
254
     * are always output
255
     */
256
    if (!Header)
257
    {
258
        /* Ignore remarks if requested */
259
260
 
261
        {
262
        case ASL_REMARK:
263
            if (!Gbl_DisplayRemarks)
264
            {
265
                return;
266
            }
267
            break;
268
269
 
270
            if (!Gbl_DisplayOptimizations)
271
            {
272
                return;
273
            }
274
            break;
275
276
 
277
            break;
278
        }
279
    }
280
281
 
282
283
 
284
2216 Serge 285
 
286
287
 
1498 serge 288
    if (!SourceFile)
2216 Serge 289
    {
290
        SourceFile = Gbl_Files[ASL_FILE_INPUT].Handle;
291
    }
292
1498 serge 293
 
2216 Serge 294
    {
295
        /* Determine if the error occurred at source file EOF */
296
297
 
298
        FileSize = ftell (SourceFile);
299
300
 
301
        {
302
            PrematureEOF = TRUE;
303
        }
304
    }
305
306
 
1498 serge 307
    {
308
        fprintf (OutputFile, "%s", Header);
309
    }
310
311
 
312
313
 
314
    {
315
        if (Gbl_VerboseErrors)
316
        {
317
            fprintf (OutputFile, "%6s", Enode->Filename);
318
319
 
320
            {
321
                fprintf (OutputFile, " %6u: ", Enode->LineNumber);
2216 Serge 322
1498 serge 323
 
324
                 * If not at EOF, get the corresponding source code line and
2216 Serge 325
                 * display it. Don't attempt this if we have a premature EOF
326
                 * condition.
327
                 */
1498 serge 328
                if (!PrematureEOF)
2216 Serge 329
                {
1498 serge 330
                    /*
2216 Serge 331
                     * Seek to the offset in the combined source file, read
332
                     * the source line, and write it to the output.
333
                     */
334
                    Actual = fseek (SourceFile, (long) Enode->LogicalByteOffset,
335
                                (int) SEEK_SET);
336
                    if (Actual)
337
                    {
1498 serge 338
                        fprintf (OutputFile,
339
                            "[*** iASL: Seek error on source code temp file %s ***]",
2216 Serge 340
                            Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
1498 serge 341
                    }
342
                    else
2216 Serge 343
                    {
1498 serge 344
                        RActual = fread (&SourceByte, 1, 1, SourceFile);
345
                        if (!RActual)
2216 Serge 346
                        {
347
                            fprintf (OutputFile,
348
                                "[*** iASL: Read error on source code temp file %s ***]",
349
                                Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
350
                        }
351
352
 
353
                        {
354
                            fwrite (&SourceByte, 1, 1, OutputFile);
355
                            RActual = fread (&SourceByte, 1, 1, SourceFile);
356
                        }
357
                    }
1498 serge 358
                }
359
2216 Serge 360
 
1498 serge 361
            }
362
        }
363
        else
364
        {
365
            fprintf (OutputFile, "%s", Enode->Filename);
366
367
 
368
            {
369
                fprintf (OutputFile, "(%u) : ", Enode->LineNumber);
370
            }
371
        }
372
    }
373
374
 
375
376
 
377
    {
378
        fprintf (OutputFile, "%s\n", Enode->Message);
379
    }
380
    else
381
    {
382
        /* Decode the message ID */
383
384
 
2216 Serge 385
                    AslErrorLevel[Enode->Level],
1498 serge 386
                    Enode->MessageId + ((Enode->Level+1) * 1000));
387
388
 
389
        ExtraMessage = Enode->Message;
390
391
 
392
        {
393
            MsgLength = strlen (MainMessage);
394
            if (MsgLength == 0)
395
            {
396
                MainMessage = Enode->Message;
397
398
 
399
                ExtraMessage = NULL;
400
            }
401
402
 
2216 Serge 403
            {
1498 serge 404
                SourceColumn = Enode->Column + Enode->FilenameLength + 6 + 2;
405
                ErrorColumn = ASL_ERROR_LEVEL_LENGTH + 5 + 2 + 1;
406
407
 
408
                {
409
                    fprintf (OutputFile, "%*s%s",
410
                        (int) ((SourceColumn - 1) - ErrorColumn),
411
                        MainMessage, " ^ ");
412
                }
413
                else
414
                {
415
                    fprintf (OutputFile, "%*s %s",
416
                        (int) ((SourceColumn - ErrorColumn) + 1), "^",
417
                        MainMessage);
418
                }
419
            }
420
            else
421
            {
422
                fprintf (OutputFile, " %s", MainMessage);
423
            }
424
425
 
426
427
 
428
            {
429
                fprintf (OutputFile, " (%s)", ExtraMessage);
430
            }
431
432
 
2216 Serge 433
            {
434
                fprintf (OutputFile, " and premature End-Of-File");
435
            }
436
437
 
1498 serge 438
            if (Gbl_VerboseErrors)
439
            {
440
                fprintf (OutputFile, "\n");
441
            }
442
        }
443
        else
444
        {
445
            fprintf (OutputFile, " %s %s\n\n", MainMessage, ExtraMessage);
446
        }
447
    }
448
}
449
450
 
451
 
452
 *
453
 * FUNCTION:    AePrintErrorLog
454
 *
455
 * PARAMETERS:  FileId           - Where to output the error log
456
 *
457
 * RETURN:      None
458
 *
459
 * DESCRIPTION: Print the entire contents of the error log
460
 *
461
 ******************************************************************************/
462
463
 
464
AePrintErrorLog (
465
    UINT32                  FileId)
466
{
467
    ASL_ERROR_MSG           *Enode = Gbl_ErrorLog;
468
469
 
470
 
471
472
 
473
    {
474
        AePrintException (FileId, Enode, NULL);
475
        Enode = Enode->Next;
476
    }
477
}
478
479
 
480
 
481
 *
482
 * FUNCTION:    AslCommonError
483
 *
484
 * PARAMETERS:  Level               - Seriousness (Warning/error, etc.)
485
 *              MessageId           - Index into global message buffer
486
 *              CurrentLineNumber   - Actual file line number
487
 *              LogicalLineNumber   - Cumulative line number
488
 *              LogicalByteOffset   - Byte offset in source file
489
 *              Column              - Column in current line
490
 *              Filename            - source filename
491
 *              ExtraMessage        - additional error message
492
 *
493
 * RETURN:      None
494
 *
495
 * DESCRIPTION: Create a new error node and add it to the error log
496
 *
497
 ******************************************************************************/
498
499
 
500
AslCommonError (
501
    UINT8                   Level,
502
    UINT8                   MessageId,
503
    UINT32                  CurrentLineNumber,
504
    UINT32                  LogicalLineNumber,
505
    UINT32                  LogicalByteOffset,
506
    UINT32                  Column,
507
    char                    *Filename,
508
    char                    *ExtraMessage)
509
{
510
    UINT32                  MessageSize;
511
    char                    *MessageBuffer = NULL;
512
    ASL_ERROR_MSG           *Enode;
513
514
 
515
 
516
517
 
518
    {
519
        /* Allocate a buffer for the message and a new error node */
520
521
 
522
        MessageBuffer = UtLocalCalloc (MessageSize);
523
524
 
525
526
 
527
    }
528
529
 
530
531
 
532
    {
533
        Enode->Filename       = Filename;
534
        Enode->FilenameLength = strlen (Filename);
535
        if (Enode->FilenameLength < 6)
536
        {
537
            Enode->FilenameLength = 6;
538
        }
539
    }
540
541
 
542
    Enode->Level                = Level;
543
    Enode->LineNumber           = CurrentLineNumber;
544
    Enode->LogicalLineNumber    = LogicalLineNumber;
545
    Enode->LogicalByteOffset    = LogicalByteOffset;
546
    Enode->Column               = Column;
547
    Enode->Message              = MessageBuffer;
548
549
 
550
551
 
552
553
 
554
    {
555
        /* stderr is a file, send error to it immediately */
556
557
 
558
    }
559
560
 
561
    if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
562
    {
563
        printf ("\nMaximum error count (%u) exceeded\n", ASL_MAX_ERROR_COUNT);
564
565
 
566
        Gbl_NextError = Gbl_ErrorLog;
567
        CmDoOutputFiles ();
568
        CmCleanupAndExit ();
569
        exit(1);
570
    }
571
572
 
573
}
574
575
 
576
 
577
 *
578
 * FUNCTION:    AslError
579
 *
580
 * PARAMETERS:  Level               - Seriousness (Warning/error, etc.)
581
 *              MessageId           - Index into global message buffer
582
 *              Op                  - Parse node where error happened
583
 *              ExtraMessage        - additional error message
584
 *
585
 * RETURN:      None
586
 *
587
 * DESCRIPTION: Main error reporting routine for the ASL compiler (all code
588
 *              except the parser.)
589
 *
590
 ******************************************************************************/
591
592
 
593
AslError (
594
    UINT8                   Level,
595
    UINT8                   MessageId,
596
    ACPI_PARSE_OBJECT       *Op,
597
    char                    *ExtraMessage)
598
{
599
600
 
601
    {
602
    case ASL_WARNING2:
603
    case ASL_WARNING3:
604
        if (Gbl_WarningLevel < Level)
605
        {
606
            return;
607
        }
608
        break;
609
610
 
611
        break;
612
    }
613
614
 
615
 
616
    {
617
        AslCommonError (Level, MessageId, Op->Asl.LineNumber,
618
                        Op->Asl.LogicalLineNumber,
619
                        Op->Asl.LogicalByteOffset,
620
                        Op->Asl.Column,
621
                        Op->Asl.Filename, ExtraMessage);
622
    }
623
    else
624
    {
625
        AslCommonError (Level, MessageId, 0,
626
                        0, 0, 0, NULL, ExtraMessage);
627
    }
628
}
629
630
 
631
 
632
 *
633
 * FUNCTION:    AslCoreSubsystemError
634
 *
635
 * PARAMETERS:  Op                  - Parse node where error happened
636
 *              Status              - The ACPI CA Exception
637
 *              ExtraMessage        - additional error message
638
 *              Abort               - TRUE -> Abort compilation
639
 *
640
 * RETURN:      None
641
 *
642
 * DESCRIPTION: Error reporting routine for exceptions returned by the ACPI
643
 *              CA core subsystem.
644
 *
645
 ******************************************************************************/
646
647
 
648
AslCoreSubsystemError (
649
    ACPI_PARSE_OBJECT       *Op,
650
    ACPI_STATUS             Status,
651
    char                    *ExtraMessage,
652
    BOOLEAN                 Abort)
653
{
654
655
 
656
657
 
658
    {
659
        AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Op->Asl.LineNumber,
660
                        Op->Asl.LogicalLineNumber,
661
                        Op->Asl.LogicalByteOffset,
662
                        Op->Asl.Column,
663
                        Op->Asl.Filename, MsgBuffer);
664
    }
665
    else
666
    {
667
        AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, 0,
668
                        0, 0, 0, NULL, MsgBuffer);
669
    }
670
671
 
672
    {
673
        AslAbort ();
674
    }
675
}
676
677
 
678
 
679
 *
680
 * FUNCTION:    AslCompilererror
681
 *
682
 * PARAMETERS:  CompilerMessage         - Error message from the parser
683
 *
684
 * RETURN:      Status (0 for now)
685
 *
686
 * DESCRIPTION: Report an error situation discovered in a production
687
 *              NOTE: don't change the name of this function, it is called
688
 *              from the auto-generated parser.
689
 *
690
 ******************************************************************************/
691
692
 
693
AslCompilererror (
694
    const char              *CompilerMessage)
2216 Serge 695
{
1498 serge 696
697
 
698
        Gbl_LogicalLineNumber, Gbl_CurrentLineOffset,
2216 Serge 699
        Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename,
700
        ACPI_CAST_PTR (char, CompilerMessage));
701
1498 serge 702
 
703
}
704