aslmain.c revision 193529
1
2/******************************************************************************
3 *
4 * Module Name: aslmain - compiler main and utilities
5 *
6 *****************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
13 * All rights reserved.
14 *
15 * 2. License
16 *
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights.  You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
21 *
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
28 *
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code.  No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
37 *
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
40 *
41 * 3. Conditions
42 *
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision.  In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change.  Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee.  Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
54 *
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution.  In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
66 *
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
75 *
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
80 *
81 * 4. Disclaimer and Export Compliance
82 *
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
90 *
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
99 *
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government.  In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
114 *
115 *****************************************************************************/
116
117
118#define _DECLARE_GLOBALS
119
120#include <contrib/dev/acpica/compiler/aslcompiler.h>
121#include <contrib/dev/acpica/include/acapps.h>
122
123#ifdef _DEBUG
124#include <crtdbg.h>
125#endif
126
127#define _COMPONENT          ACPI_COMPILER
128        ACPI_MODULE_NAME    ("aslmain")
129
130/* Local prototypes */
131
132static void
133Options (
134    void);
135
136static void
137HelpMessage (
138    void);
139
140static void
141Usage (
142    void);
143
144static void
145AslInitialize (
146    void);
147
148static int
149AslCommandLine (
150    int                     argc,
151    char                    **argv);
152
153
154/*******************************************************************************
155 *
156 * FUNCTION:    Options
157 *
158 * PARAMETERS:  None
159 *
160 * RETURN:      None
161 *
162 * DESCRIPTION: Display option help message
163 *
164 ******************************************************************************/
165
166static void
167Options (
168    void)
169{
170
171    printf ("General Output:\n");
172    printf ("  -p <prefix>    Specify path/filename prefix for all output files\n");
173    printf ("  -va            Disable all errors and warnings (summary only)\n");
174    printf ("  -vi            Less verbose errors and warnings for use with IDEs\n");
175    printf ("  -vo            Enable optimization comments\n");
176    printf ("  -vr            Disable remarks\n");
177    printf ("  -vs            Disable signon\n");
178    printf ("  -w<1|2|3>      Set warning reporting level\n");
179
180    printf ("\nAML Output Files:\n");
181    printf ("  -s<a|c>        Create AML in assembler or C source file (*.asm or *.c)\n");
182    printf ("  -i<a|c>        Create assembler or C include file (*.inc or *.h)\n");
183    printf ("  -t<a|c>        Create AML in assembler or C hex table (*.hex)\n");
184
185    printf ("\nAML Code Generation:\n");
186    printf ("  -oa            Disable all optimizations (compatibility mode)\n");
187    printf ("  -of            Disable constant folding\n");
188    printf ("  -oi            Disable integer optimization to Zero/One/Ones\n");
189    printf ("  -on            Disable named reference string optimization\n");
190    printf ("  -r<Revision>   Override table header Revision (1-255)\n");
191
192    printf ("\nListings:\n");
193    printf ("  -l             Create mixed listing file (ASL source and AML) (*.lst)\n");
194    printf ("  -ln            Create namespace file (*.nsp)\n");
195    printf ("  -ls            Create combined source file (expanded includes) (*.src)\n");
196
197    printf ("\nAML Disassembler:\n");
198    printf ("  -d  [file]     Disassemble or decode binary ACPI table to file (*.dsl)\n");
199    printf ("  -dc [file]     Disassemble AML and immediately compile it\n");
200    printf ("                 (Obtain DSDT from current system if no input file)\n");
201    printf ("  -e  [f1,f2]    Include ACPI table(s) for external symbol resolution\n");
202    printf ("  -2             Emit ACPI 2.0 compatible ASL code\n");
203    printf ("  -g             Get ACPI tables and write to files (*.dat)\n");
204
205    printf ("\nHelp:\n");
206    printf ("  -h             Additional help and compiler debug options\n");
207    printf ("  -hc            Display operators allowed in constant expressions\n");
208    printf ("  -hr            Display ACPI reserved method names\n");
209}
210
211
212/*******************************************************************************
213 *
214 * FUNCTION:    HelpMessage
215 *
216 * PARAMETERS:  None
217 *
218 * RETURN:      None
219 *
220 * DESCRIPTION: Display help message
221 *
222 ******************************************************************************/
223
224static void
225HelpMessage (
226    void)
227{
228
229    printf ("AML output filename generation:\n");
230    printf ("  Output filenames are generated by appending an extension to a common\n");
231    printf ("  filename prefix.  The filename prefix is obtained via one of the\n");
232    printf ("  following methods (in priority order):\n");
233    printf ("    1) The -p option specifies the prefix\n");
234    printf ("    2) The prefix of the AMLFileName in the ASL Definition Block\n");
235    printf ("    3) The prefix of the input filename\n");
236    printf ("\n");
237
238    Options ();
239
240    printf ("\nCompiler/Disassembler Debug Options:\n");
241    printf ("  -b<p|t|b>      Create compiler debug/trace file (*.txt)\n");
242    printf ("                   Types: Parse/Tree/Both\n");
243    printf ("  -f             Ignore errors, force creation of AML output file(s)\n");
244    printf ("  -c             Parse only, no output generation\n");
245    printf ("  -ot            Display compile times\n");
246    printf ("  -x<level>      Set debug level for trace output\n");
247}
248
249
250/*******************************************************************************
251 *
252 * FUNCTION:    Usage
253 *
254 * PARAMETERS:  None
255 *
256 * RETURN:      None
257 *
258 * DESCRIPTION: Display usage and option message
259 *
260 ******************************************************************************/
261
262static void
263Usage (
264    void)
265{
266
267    printf ("Usage:    %s [Options] [Files]\n\n", CompilerName);
268    Options ();
269}
270
271
272/*******************************************************************************
273 *
274 * FUNCTION:    AslInitialize
275 *
276 * PARAMETERS:  None
277 *
278 * RETURN:      None
279 *
280 * DESCRIPTION: Initialize compiler globals
281 *
282 ******************************************************************************/
283
284static void
285AslInitialize (
286    void)
287{
288    UINT32                  i;
289
290
291#ifdef _DEBUG
292    _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0));
293#endif
294
295    AcpiDbgLevel = 0;
296
297    for (i = 0; i < ASL_NUM_FILES; i++)
298    {
299        Gbl_Files[i].Handle = NULL;
300        Gbl_Files[i].Filename = NULL;
301    }
302
303    Gbl_Files[ASL_FILE_STDOUT].Handle   = stdout;
304    Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
305
306    Gbl_Files[ASL_FILE_STDERR].Handle   = stderr;
307    Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
308}
309
310
311/*******************************************************************************
312 *
313 * FUNCTION:    AslCommandLine
314 *
315 * PARAMETERS:  argc/argv
316 *
317 * RETURN:      None
318 *
319 * DESCRIPTION: Command line processing
320 *
321 ******************************************************************************/
322
323static int
324AslCommandLine (
325    int                     argc,
326    char                    **argv)
327{
328    BOOLEAN                 BadCommandLine = FALSE;
329    int                     j;
330
331
332    /* Minimum command line contains at least one option or an input file */
333
334    if (argc < 2)
335    {
336        AslCompilerSignon (ASL_FILE_STDOUT);
337        Usage ();
338        exit (1);
339    }
340
341    /* Get the command line options */
342
343    while ((j = AcpiGetopt (argc, argv, "2b:cd^e:fgh^i^l^o:p:r:s:t:v:w:x:")) != EOF) switch (j)
344    {
345    case '2':
346        Gbl_Acpi2 = TRUE;
347        break;
348
349
350    case 'b':
351
352        switch (AcpiGbl_Optarg[0])
353        {
354        case 'b':
355            AslCompilerdebug = 1; /* same as yydebug */
356            break;
357
358        case 'p':
359            AslCompilerdebug = 1; /* same as yydebug */
360            break;
361
362        case 't':
363            break;
364
365        default:
366            printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
367            BadCommandLine = TRUE;
368            break;
369        }
370
371        /* Produce debug output file */
372
373        Gbl_DebugFlag = TRUE;
374        break;
375
376
377    case 'c':
378
379        /* Parse only */
380
381        Gbl_ParseOnlyFlag = TRUE;
382        break;
383
384
385    case 'd':
386        switch (AcpiGbl_Optarg[0])
387        {
388        case '^':
389            Gbl_DoCompile = FALSE;
390            break;
391
392        case 'c':
393            break;
394
395        default:
396            printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
397            BadCommandLine = TRUE;
398            break;
399        }
400
401        Gbl_DisasmFlag = TRUE;
402        break;
403
404
405    case 'e':
406        Gbl_ExternalFilename = AcpiGbl_Optarg;
407        break;
408
409
410    case 'f':
411
412        /* Ignore errors and force creation of aml file */
413
414        Gbl_IgnoreErrors = TRUE;
415        break;
416
417
418    case 'g':
419
420        /* Get all ACPI tables */
421
422        Gbl_GetAllTables = TRUE;
423        Gbl_DoCompile = FALSE;
424        break;
425
426
427    case 'h':
428
429        switch (AcpiGbl_Optarg[0])
430        {
431        case '^':
432            HelpMessage ();
433            exit (0);
434
435        case 'c':
436            UtDisplayConstantOpcodes ();
437            exit (0);
438
439        case 'r':
440            /* reserved names */
441
442            MpDisplayReservedNames ();
443            exit (0);
444
445        default:
446            printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
447            BadCommandLine = TRUE;
448            break;
449        }
450        break;
451
452
453    case 'i':
454
455        switch (AcpiGbl_Optarg[0])
456        {
457        case 'a':
458
459            /* Produce assembly code include file */
460
461            Gbl_AsmIncludeOutputFlag = TRUE;
462            break;
463
464        case 'c':
465
466            /* Produce C include file */
467
468            Gbl_C_IncludeOutputFlag = TRUE;
469            break;
470
471        default:
472            printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
473            BadCommandLine = TRUE;
474            break;
475        }
476        break;
477
478
479    case 'l':
480
481        switch (AcpiGbl_Optarg[0])
482        {
483        case '^':
484            /* Produce listing file (Mixed source/aml) */
485
486            Gbl_ListingFlag = TRUE;
487            break;
488
489        case 'n':
490            /* Produce namespace file */
491
492            Gbl_NsOutputFlag = TRUE;
493            break;
494
495        case 's':
496            /* Produce combined source file */
497
498            Gbl_SourceOutputFlag = TRUE;
499            break;
500
501        default:
502            printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
503            BadCommandLine = TRUE;
504            break;
505        }
506        break;
507
508
509    case 'o':
510
511        switch (AcpiGbl_Optarg[0])
512        {
513        case 'a':
514
515            /* Disable all optimizations */
516
517            Gbl_FoldConstants = FALSE;
518            Gbl_IntegerOptimizationFlag = FALSE;
519            Gbl_ReferenceOptimizationFlag = FALSE;
520            break;
521
522        case 'f':
523
524            /* Disable folding on "normal" expressions */
525
526            Gbl_FoldConstants = FALSE;
527            break;
528
529        case 'i':
530
531            /* Disable integer optimization to constants */
532
533            Gbl_IntegerOptimizationFlag = FALSE;
534            break;
535
536        case 'n':
537
538            /* Disable named reference optimization */
539
540            Gbl_ReferenceOptimizationFlag = FALSE;
541            break;
542
543        case 't':
544
545            /* Display compile time(s) */
546
547            Gbl_CompileTimesFlag = TRUE;
548            break;
549
550        default:
551            printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
552            BadCommandLine = TRUE;
553            break;
554        }
555        break;
556
557
558    case 'p':
559
560        /* Override default AML output filename */
561
562        Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
563        Gbl_UseDefaultAmlFilename = FALSE;
564        break;
565
566
567    case 'r':
568        Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
569        break;
570
571
572    case 's':
573
574        switch (AcpiGbl_Optarg[0])
575        {
576        case 'a':
577
578            /* Produce assembly code output file */
579
580            Gbl_AsmOutputFlag = TRUE;
581            break;
582
583        case 'c':
584
585            /* Produce C hex output file */
586
587            Gbl_C_OutputFlag = TRUE;
588            break;
589
590        default:
591            printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
592            BadCommandLine = TRUE;
593            break;
594        }
595        break;
596
597
598    case 't':
599
600        /* Produce hex table output file */
601
602        switch (AcpiGbl_Optarg[0])
603        {
604        case 'a':
605            Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
606            break;
607
608        case 'c':
609            Gbl_HexOutputFlag = HEX_OUTPUT_C;
610            break;
611
612        default:
613            printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
614            BadCommandLine = TRUE;
615            break;
616        }
617        break;
618
619
620    case 'v':
621
622        switch (AcpiGbl_Optarg[0])
623        {
624        case 'a':
625            /* Disable All error/warning messages */
626
627            Gbl_NoErrors = TRUE;
628            break;
629
630        case 'i':
631            /* Less verbose error messages */
632
633            Gbl_VerboseErrors = FALSE;
634            break;
635
636        case 'o':
637            Gbl_DisplayOptimizations = TRUE;
638            break;
639
640        case 'r':
641            Gbl_DisplayRemarks = FALSE;
642            break;
643
644        case 's':
645            Gbl_DoSignon = FALSE;
646            break;
647
648        default:
649            printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
650            BadCommandLine = TRUE;
651            break;
652        }
653        break;
654
655
656    case 'w': /* Set warning levels */
657
658        switch (AcpiGbl_Optarg[0])
659        {
660        case '1':
661            Gbl_WarningLevel = ASL_WARNING;
662            break;
663
664        case '2':
665            Gbl_WarningLevel = ASL_WARNING2;
666            break;
667
668        case '3':
669            Gbl_WarningLevel = ASL_WARNING3;
670            break;
671
672        default:
673            printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
674            BadCommandLine = TRUE;
675            break;
676        }
677        break;
678
679
680    case 'x':
681
682        AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
683        break;
684
685
686    default:
687
688        BadCommandLine = TRUE;
689        break;
690    }
691
692    /* Next parameter must be the input filename */
693
694    if (!argv[AcpiGbl_Optind] &&
695        !Gbl_DisasmFlag &&
696        !Gbl_GetAllTables)
697    {
698        printf ("Missing input filename\n");
699        BadCommandLine = TRUE;
700    }
701
702    if (Gbl_DoSignon)
703    {
704        AslCompilerSignon (ASL_FILE_STDOUT);
705    }
706
707    /* Abort if anything went wrong on the command line */
708
709    if (BadCommandLine)
710    {
711        printf ("\n");
712        Usage ();
713        exit (1);
714    }
715
716    return (AcpiGbl_Optind);
717}
718
719
720/*******************************************************************************
721 *
722 * FUNCTION:    main
723 *
724 * PARAMETERS:  Standard argc/argv
725 *
726 * RETURN:      Program termination code
727 *
728 * DESCRIPTION: C main routine for the Asl Compiler. Handle command line
729 *              options and begin the compile for each file on the command line
730 *
731 ******************************************************************************/
732
733int ACPI_SYSTEM_XFACE
734main (
735    int                     argc,
736    char                    **argv)
737{
738    ACPI_STATUS             Status;
739    int                     Index;
740
741
742#ifdef _DEBUG
743    _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF |
744                    _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
745#endif
746
747    /* Init and command line */
748
749    AslInitialize ();
750    Index = AslCommandLine (argc, argv);
751
752    /* Options that have no additional parameters or pathnames */
753
754    if (Gbl_GetAllTables)
755    {
756        Status = AslDoOneFile (NULL);
757        if (ACPI_FAILURE (Status))
758        {
759            return (-1);
760        }
761        return (0);
762    }
763
764    /* Process each pathname/filename in the list, with possible wildcards */
765
766    while (argv[Index])
767    {
768        Status = AslDoOnePathname (argv[Index]);
769        if (ACPI_FAILURE (Status))
770        {
771            return (-1);
772        }
773
774        Index++;
775    }
776
777    return (0);
778}
779
780
781