xref: /freebsd/sys/contrib/dev/acpica/compiler/aslmain.c (revision 6486b015fc84e96725fef22b0e3363351399ae83)
1 
2 /******************************************************************************
3  *
4  * Module Name: aslmain - compiler main and utilities
5  *
6  *****************************************************************************/
7 
8 /*
9  * Copyright (C) 2000 - 2012, Intel Corp.
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions, and the following disclaimer,
17  *    without modification.
18  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19  *    substantially similar to the "NO WARRANTY" disclaimer below
20  *    ("Disclaimer") and any redistribution must be conditioned upon
21  *    including a substantially similar Disclaimer requirement for further
22  *    binary redistribution.
23  * 3. Neither the names of the above-listed copyright holders nor the names
24  *    of any contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * Alternatively, this software may be distributed under the terms of the
28  * GNU General Public License ("GPL") version 2 as published by the Free
29  * Software Foundation.
30  *
31  * NO WARRANTY
32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42  * POSSIBILITY OF SUCH DAMAGES.
43  */
44 
45 
46 #define _DECLARE_GLOBALS
47 
48 #include <contrib/dev/acpica/compiler/aslcompiler.h>
49 #include <contrib/dev/acpica/include/acapps.h>
50 #include <contrib/dev/acpica/include/acdisasm.h>
51 
52 #ifdef _DEBUG
53 #include <crtdbg.h>
54 #endif
55 
56 #define _COMPONENT          ACPI_COMPILER
57         ACPI_MODULE_NAME    ("aslmain")
58 
59 /* Local prototypes */
60 
61 static void
62 Options (
63     void);
64 
65 static void
66 HelpMessage (
67     void);
68 
69 static void
70 Usage (
71     void);
72 
73 static void
74 AslInitialize (
75     void);
76 
77 static int
78 AslCommandLine (
79     int                     argc,
80     char                    **argv);
81 
82 static int
83 AslDoOptions (
84     int                     argc,
85     char                    **argv,
86     BOOLEAN                 IsResponseFile);
87 
88 static void
89 AslMergeOptionTokens (
90     char                    *InBuffer,
91     char                    *OutBuffer);
92 
93 static int
94 AslDoResponseFile (
95     char                    *Filename);
96 
97 
98 #define ASL_TOKEN_SEPARATORS    " \t\n"
99 #define ASL_SUPPORTED_OPTIONS   "@:2b|c|d^D:e:fgh^i|I:l^mno|p:P^r:s|t|T:G^v|w|x:z"
100 
101 
102 /*******************************************************************************
103  *
104  * FUNCTION:    Options
105  *
106  * PARAMETERS:  None
107  *
108  * RETURN:      None
109  *
110  * DESCRIPTION: Display option help message
111  *
112  ******************************************************************************/
113 
114 static void
115 Options (
116     void)
117 {
118 
119     printf ("\nGlobal:\n");
120     ACPI_OPTION ("-@ <file>",       "Specify command file");
121     ACPI_OPTION ("-I <dir>",        "Specify additional include directory");
122 
123     printf ("\nPreprocessor:\n");
124     ACPI_OPTION ("-D <symbol>",     "Define symbol for preprocessor use");
125     ACPI_OPTION ("-li",             "Create preprocessed output file (*.i)");
126     ACPI_OPTION ("-P",              "Preprocess only and create preprocessor output file (*.i)");
127     ACPI_OPTION ("-Pn",             "Disable preprocessor");
128 
129     printf ("\nGeneral Output:\n");
130     ACPI_OPTION ("-p <prefix>",     "Specify path/filename prefix for all output files");
131     ACPI_OPTION ("-va",             "Disable all errors and warnings (summary only)");
132     ACPI_OPTION ("-vi",             "Less verbose errors and warnings for use with IDEs");
133     ACPI_OPTION ("-vo",             "Enable optimization comments");
134     ACPI_OPTION ("-vr",             "Disable remarks");
135     ACPI_OPTION ("-vs",             "Disable signon");
136     ACPI_OPTION ("-w1 -w2 -w3",     "Set warning reporting level");
137     ACPI_OPTION ("-we",             "Report warnings as errors");
138 
139     printf ("\nAML Output Files:\n");
140     ACPI_OPTION ("-sa -sc",         "Create AML in assembler or C source file (*.asm or *.c)");
141     ACPI_OPTION ("-ia -ic",         "Create assembler or C include file (*.inc or *.h)");
142     ACPI_OPTION ("-ta -tc -ts",     "Create AML in assembler, C, or ASL hex table (*.hex)");
143 
144     printf ("\nAML Code Generation:\n");
145     ACPI_OPTION ("-oa",             "Disable all optimizations (compatibility mode)");
146     ACPI_OPTION ("-of",             "Disable constant folding");
147     ACPI_OPTION ("-oi",             "Disable integer optimization to Zero/One/Ones");
148     ACPI_OPTION ("-on",             "Disable named reference string optimization");
149     ACPI_OPTION ("-cr",             "Disable Resource Descriptor error checking");
150     ACPI_OPTION ("-r <revision>",   "Override table header Revision (1-255)");
151 
152     printf ("\nASL Listing Files:\n");
153     ACPI_OPTION ("-l",              "Create mixed listing file (ASL source and AML) (*.lst)");
154     ACPI_OPTION ("-ln",             "Create namespace file (*.nsp)");
155     ACPI_OPTION ("-ls",             "Create combined source file (expanded includes) (*.src)");
156 
157     printf ("\nACPI Data Tables:\n");
158     ACPI_OPTION ("-G",              "Compile custom table containing generic operators");
159     ACPI_OPTION ("-T <sig>|ALL|*",  "Create table template file(s) for <Sig>");
160     ACPI_OPTION ("-vt",             "Create verbose templates (full disassembly)");
161 
162     printf ("\nAML Disassembler:\n");
163     ACPI_OPTION ("-d  [file]",      "Disassemble or decode binary ACPI table to file (*.dsl)");
164     ACPI_OPTION ("-da [f1,f2]",     "Disassemble multiple tables from single namespace");
165     ACPI_OPTION ("-dc [file]",      "Disassemble AML and immediately compile it");
166     ACPI_OPTION ("",                "(Obtain DSDT from current system if no input file)");
167     ACPI_OPTION ("-e  [f1,f2]",     "Include ACPI table(s) for external symbol resolution");
168     ACPI_OPTION ("-m",              "Do not translate Buffers to Resource Templates");
169     ACPI_OPTION ("-2",              "Emit ACPI 2.0 compatible ASL code");
170     ACPI_OPTION ("-g",              "Get ACPI tables and write to files (*.dat)");
171 
172     printf ("\nHelp:\n");
173     ACPI_OPTION ("-h",              "Additional help and compiler debug options");
174     ACPI_OPTION ("-hc",             "Display operators allowed in constant expressions");
175     ACPI_OPTION ("-hr",             "Display ACPI reserved method names");
176     ACPI_OPTION ("-ht",             "Display currently supported ACPI table names");
177 }
178 
179 
180 /*******************************************************************************
181  *
182  * FUNCTION:    HelpMessage
183  *
184  * PARAMETERS:  None
185  *
186  * RETURN:      None
187  *
188  * DESCRIPTION: Display help message
189  *
190  ******************************************************************************/
191 
192 static void
193 HelpMessage (
194     void)
195 {
196 
197     printf ("\nAML output filename generation:\n");
198     printf ("  Output filenames are generated by appending an extension to a common\n");
199     printf ("  filename prefix.  The filename prefix is obtained via one of the\n");
200     printf ("  following methods (in priority order):\n");
201     printf ("    1) The -p option specifies the prefix\n");
202     printf ("    2) The prefix of the AMLFileName in the ASL Definition Block\n");
203     printf ("    3) The prefix of the input filename\n");
204     printf ("\n");
205 
206     Options ();
207 
208     printf ("\nCompiler/Disassembler Debug Options:\n");
209     ACPI_OPTION ("-bb -bp -bt",     "Create compiler debug/trace file (*.txt)");
210     ACPI_OPTION ("",                "Types: Parse/Tree/Both");
211     ACPI_OPTION ("-f",              "Ignore errors, force creation of AML output file(s)");
212     ACPI_OPTION ("-n",              "Parse only, no output generation");
213     ACPI_OPTION ("-ot",             "Display compile times");
214     ACPI_OPTION ("-x <level>",      "Set debug level for trace output");
215     ACPI_OPTION ("-z",              "Do not insert new compiler ID for DataTables");
216 }
217 
218 
219 /*******************************************************************************
220  *
221  * FUNCTION:    Usage
222  *
223  * PARAMETERS:  None
224  *
225  * RETURN:      None
226  *
227  * DESCRIPTION: Display usage and option message
228  *
229  ******************************************************************************/
230 
231 static void
232 Usage (
233     void)
234 {
235 
236     printf ("%s\n\n", ASL_COMPLIANCE);
237     ACPI_USAGE_HEADER ("iasl [Options] [Files]");
238     Options ();
239 }
240 
241 
242 /*******************************************************************************
243  *
244  * FUNCTION:    AslInitialize
245  *
246  * PARAMETERS:  None
247  *
248  * RETURN:      None
249  *
250  * DESCRIPTION: Initialize compiler globals
251  *
252  ******************************************************************************/
253 
254 static void
255 AslInitialize (
256     void)
257 {
258     UINT32                  i;
259 
260 
261 #ifdef _DEBUG
262     _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0));
263 #endif
264 
265     AcpiDbgLevel = 0;
266 
267     for (i = 0; i < ASL_NUM_FILES; i++)
268     {
269         Gbl_Files[i].Handle = NULL;
270         Gbl_Files[i].Filename = NULL;
271     }
272 
273     Gbl_Files[ASL_FILE_STDOUT].Handle   = stdout;
274     Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
275 
276     Gbl_Files[ASL_FILE_STDERR].Handle   = stderr;
277     Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
278 }
279 
280 
281 /*******************************************************************************
282  *
283  * FUNCTION:    AslMergeOptionTokens
284  *
285  * PARAMETERS:  InBuffer            - Input containing an option string
286  *              OutBuffer           - Merged output buffer
287  *
288  * RETURN:      None
289  *
290  * DESCRIPTION: Remove all whitespace from an option string.
291  *
292  ******************************************************************************/
293 
294 static void
295 AslMergeOptionTokens (
296     char                    *InBuffer,
297     char                    *OutBuffer)
298 {
299     char                    *Token;
300 
301 
302     *OutBuffer = 0;
303 
304     Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
305     while (Token)
306     {
307         strcat (OutBuffer, Token);
308         Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
309     }
310 }
311 
312 
313 /*******************************************************************************
314  *
315  * FUNCTION:    AslDoResponseFile
316  *
317  * PARAMETERS:  Filename        - Name of the response file
318  *
319  * RETURN:      Status
320  *
321  * DESCRIPTION: Open a response file and process all options within.
322  *
323  ******************************************************************************/
324 
325 static int
326 AslDoResponseFile (
327     char                    *Filename)
328 {
329     char                    *argv = StringBuffer2;
330     FILE                    *ResponseFile;
331     int                     OptStatus = 0;
332     int                     Opterr;
333     int                     Optind;
334 
335 
336     ResponseFile = fopen (Filename, "r");
337     if (!ResponseFile)
338     {
339         printf ("Could not open command file %s, %s\n",
340             Filename, strerror (errno));
341         return -1;
342     }
343 
344     /* Must save the current GetOpt globals */
345 
346     Opterr = AcpiGbl_Opterr;
347     Optind = AcpiGbl_Optind;
348 
349     /*
350      * Process all lines in the response file. There must be one complete
351      * option per line
352      */
353     while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile))
354     {
355         /* Compress all tokens, allowing us to use a single argv entry */
356 
357         AslMergeOptionTokens (StringBuffer, StringBuffer2);
358 
359         /* Process the option */
360 
361         AcpiGbl_Opterr = 0;
362         AcpiGbl_Optind = 0;
363 
364         OptStatus = AslDoOptions (1, &argv, TRUE);
365         if (OptStatus)
366         {
367             printf ("Invalid option in command file %s: %s\n",
368                 Filename, StringBuffer);
369             break;
370         }
371     }
372 
373     /* Restore the GetOpt globals */
374 
375     AcpiGbl_Opterr = Opterr;
376     AcpiGbl_Optind = Optind;
377 
378     fclose (ResponseFile);
379     return (OptStatus);
380 }
381 
382 
383 /*******************************************************************************
384  *
385  * FUNCTION:    AslDoOptions
386  *
387  * PARAMETERS:  argc/argv           - Standard argc/argv
388  *              IsResponseFile      - TRUE if executing a response file.
389  *
390  * RETURN:      Status
391  *
392  * DESCRIPTION: Command line option processing
393  *
394  ******************************************************************************/
395 
396 static int
397 AslDoOptions (
398     int                     argc,
399     char                    **argv,
400     BOOLEAN                 IsResponseFile)
401 {
402     int                     j;
403     ACPI_STATUS             Status;
404 
405 
406     /* Get the command line options */
407 
408     while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j)
409     {
410     case '@':   /* Begin a response file */
411 
412         if (IsResponseFile)
413         {
414             printf ("Nested command files are not supported\n");
415             return (-1);
416         }
417 
418         if (AslDoResponseFile (AcpiGbl_Optarg))
419         {
420             return (-1);
421         }
422         break;
423 
424 
425     case '2':   /* ACPI 2.0 compatibility mode */
426         Gbl_Acpi2 = TRUE;
427         break;
428 
429 
430     case 'b':   /* Debug output options */
431         switch (AcpiGbl_Optarg[0])
432         {
433         case 'b':
434             AslCompilerdebug = 1; /* same as yydebug */
435             DtParserdebug = 1;
436             PrParserdebug = 1;
437             break;
438 
439         case 'p':
440             AslCompilerdebug = 1; /* same as yydebug */
441             DtParserdebug = 1;
442             PrParserdebug = 1;
443             break;
444 
445         case 't':
446             break;
447 
448         default:
449             printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
450             return (-1);
451         }
452 
453         /* Produce debug output file */
454 
455         Gbl_DebugFlag = TRUE;
456         break;
457 
458 
459     case 'c':
460         switch (AcpiGbl_Optarg[0])
461         {
462         case 'r':
463             Gbl_NoResourceChecking = TRUE;
464             break;
465 
466         default:
467             printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
468             return (-1);
469         }
470         break;
471 
472 
473     case 'd':   /* Disassembler */
474         switch (AcpiGbl_Optarg[0])
475         {
476         case '^':
477             Gbl_DoCompile = FALSE;
478             break;
479 
480         case 'a':
481             Gbl_DoCompile = FALSE;
482             Gbl_DisassembleAll = TRUE;
483             break;
484 
485         case 'c':
486             break;
487 
488         default:
489             printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
490             return (-1);
491         }
492 
493         Gbl_DisasmFlag = TRUE;
494         break;
495 
496 
497     case 'D':   /* Define a symbol */
498         PrAddDefine (AcpiGbl_Optarg, NULL, TRUE);
499         break;
500 
501 
502     case 'e':   /* External files for disassembler */
503         Status = AcpiDmAddToExternalFileList (AcpiGbl_Optarg);
504         if (ACPI_FAILURE (Status))
505         {
506             printf ("Could not add %s to external list\n", AcpiGbl_Optarg);
507             return (-1);
508         }
509         break;
510 
511 
512     case 'f':   /* Ignore errors and force creation of aml file */
513         Gbl_IgnoreErrors = TRUE;
514         break;
515 
516 
517     case 'G':
518         Gbl_CompileGeneric = TRUE;
519         break;
520 
521 
522     case 'g':   /* Get all ACPI tables */
523 
524         Gbl_GetAllTables = TRUE;
525         Gbl_DoCompile = FALSE;
526         break;
527 
528 
529     case 'h':
530         switch (AcpiGbl_Optarg[0])
531         {
532         case '^':
533             HelpMessage ();
534             exit (0);
535 
536         case 'c':
537             UtDisplayConstantOpcodes ();
538             exit (0);
539 
540         case 'r':
541             /* reserved names */
542 
543             ApDisplayReservedNames ();
544             exit (0);
545 
546         case 't':
547             UtDisplaySupportedTables ();
548             exit (0);
549 
550         default:
551             printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
552             return (-1);
553         }
554 
555 
556     case 'I':   /* Add an include file search directory */
557         FlAddIncludeDirectory (AcpiGbl_Optarg);
558         break;
559 
560 
561     case 'i':   /* Output AML as an include file */
562         switch (AcpiGbl_Optarg[0])
563         {
564         case 'a':
565 
566             /* Produce assembly code include file */
567 
568             Gbl_AsmIncludeOutputFlag = TRUE;
569             break;
570 
571         case 'c':
572 
573             /* Produce C include file */
574 
575             Gbl_C_IncludeOutputFlag = TRUE;
576             break;
577 
578         default:
579             printf ("Unknown option: -i%s\n", AcpiGbl_Optarg);
580             return (-1);
581         }
582         break;
583 
584 
585     case 'l':   /* Listing files */
586         switch (AcpiGbl_Optarg[0])
587         {
588         case '^':
589             /* Produce listing file (Mixed source/aml) */
590 
591             Gbl_ListingFlag = TRUE;
592             break;
593 
594         case 'i':
595             /* Produce preprocessor output file */
596 
597             Gbl_PreprocessorOutputFlag = TRUE;
598             break;
599 
600         case 'n':
601             /* Produce namespace file */
602 
603             Gbl_NsOutputFlag = TRUE;
604             break;
605 
606         case 's':
607             /* Produce combined source file */
608 
609             Gbl_SourceOutputFlag = TRUE;
610             break;
611 
612         default:
613             printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
614             return (-1);
615         }
616         break;
617 
618 
619     case 'm':   /* Do not convert buffers to resource descriptors */
620         AcpiGbl_NoResourceDisassembly = TRUE;
621         break;
622 
623 
624     case 'n':   /* Parse only */
625         Gbl_ParseOnlyFlag = TRUE;
626         break;
627 
628 
629     case 'o':   /* Control compiler AML optimizations */
630         switch (AcpiGbl_Optarg[0])
631         {
632         case 'a':
633 
634             /* Disable all optimizations */
635 
636             Gbl_FoldConstants = FALSE;
637             Gbl_IntegerOptimizationFlag = FALSE;
638             Gbl_ReferenceOptimizationFlag = FALSE;
639             break;
640 
641         case 'f':
642 
643             /* Disable folding on "normal" expressions */
644 
645             Gbl_FoldConstants = FALSE;
646             break;
647 
648         case 'i':
649 
650             /* Disable integer optimization to constants */
651 
652             Gbl_IntegerOptimizationFlag = FALSE;
653             break;
654 
655         case 'n':
656 
657             /* Disable named reference optimization */
658 
659             Gbl_ReferenceOptimizationFlag = FALSE;
660             break;
661 
662         case 't':
663 
664             /* Display compile time(s) */
665 
666             Gbl_CompileTimesFlag = TRUE;
667             break;
668 
669         default:
670             printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
671             return (-1);
672         }
673         break;
674 
675 
676     case 'P':   /* Preprocessor options */
677         switch (AcpiGbl_Optarg[0])
678         {
679         case '^':   /* Proprocess only, emit (.i) file */
680             Gbl_PreprocessOnly = TRUE;
681             Gbl_PreprocessorOutputFlag = TRUE;
682             break;
683 
684         case 'n':   /* Disable preprocessor */
685             Gbl_PreprocessFlag = FALSE;
686             break;
687 
688         default:
689             printf ("Unknown option: -P%s\n", AcpiGbl_Optarg);
690             return (-1);
691         }
692         break;
693 
694 
695     case 'p':   /* Override default AML output filename */
696         Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
697         Gbl_UseDefaultAmlFilename = FALSE;
698         break;
699 
700 
701     case 'r':   /* Override revision found in table header */
702         Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
703         break;
704 
705 
706     case 's':   /* Create AML in a source code file */
707         switch (AcpiGbl_Optarg[0])
708         {
709         case 'a':
710 
711             /* Produce assembly code output file */
712 
713             Gbl_AsmOutputFlag = TRUE;
714             break;
715 
716         case 'c':
717 
718             /* Produce C hex output file */
719 
720             Gbl_C_OutputFlag = TRUE;
721             break;
722 
723         default:
724             printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
725             return (-1);
726         }
727         break;
728 
729 
730     case 't':   /* Produce hex table output file */
731         switch (AcpiGbl_Optarg[0])
732         {
733         case 'a':
734             Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
735             break;
736 
737         case 'c':
738             Gbl_HexOutputFlag = HEX_OUTPUT_C;
739             break;
740 
741         case 's':
742             Gbl_HexOutputFlag = HEX_OUTPUT_ASL;
743             break;
744 
745         default:
746             printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
747             return (-1);
748         }
749         break;
750 
751 
752     case 'T':   /* Create a ACPI table template file */
753         Gbl_DoTemplates = TRUE;
754         Gbl_TemplateSignature = AcpiGbl_Optarg;
755         break;
756 
757 
758     case 'v':   /* Verbosity settings */
759         switch (AcpiGbl_Optarg[0])
760         {
761         case 'a':
762             /* Disable All error/warning messages */
763 
764             Gbl_NoErrors = TRUE;
765             break;
766 
767         case 'i':
768             /* Less verbose error messages */
769 
770             Gbl_VerboseErrors = FALSE;
771             break;
772 
773         case 'o':
774             Gbl_DisplayOptimizations = TRUE;
775             break;
776 
777         case 'r':
778             Gbl_DisplayRemarks = FALSE;
779             break;
780 
781         case 's':
782             Gbl_DoSignon = FALSE;
783             break;
784 
785         case 't':
786             Gbl_VerboseTemplates = TRUE;
787             break;
788 
789         default:
790             printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
791             return (-1);
792         }
793         break;
794 
795 
796     case 'w': /* Set warning levels */
797         switch (AcpiGbl_Optarg[0])
798         {
799         case '1':
800             Gbl_WarningLevel = ASL_WARNING;
801             break;
802 
803         case '2':
804             Gbl_WarningLevel = ASL_WARNING2;
805             break;
806 
807         case '3':
808             Gbl_WarningLevel = ASL_WARNING3;
809             break;
810 
811         case 'e':
812             Gbl_WarningsAsErrors = TRUE;
813             break;
814 
815         default:
816             printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
817             return (-1);
818         }
819         break;
820 
821 
822     case 'x':   /* Set debug print output level */
823         AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
824         break;
825 
826 
827     case 'z':
828         Gbl_UseOriginalCompilerId = TRUE;
829         break;
830 
831 
832     default:
833         return (-1);
834     }
835 
836     return (0);
837 }
838 
839 
840 /*******************************************************************************
841  *
842  * FUNCTION:    AslCommandLine
843  *
844  * PARAMETERS:  argc/argv
845  *
846  * RETURN:      Last argv index
847  *
848  * DESCRIPTION: Command line processing
849  *
850  ******************************************************************************/
851 
852 static int
853 AslCommandLine (
854     int                     argc,
855     char                    **argv)
856 {
857     int                     BadCommandLine = 0;
858     ACPI_STATUS             Status;
859 
860 
861     /* Minimum command line contains at least the command and an input file */
862 
863     if (argc < 2)
864     {
865         printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
866         Usage ();
867         exit (1);
868     }
869 
870     /* Process all command line options */
871 
872     BadCommandLine = AslDoOptions (argc, argv, FALSE);
873 
874     if (Gbl_DoTemplates)
875     {
876         Status = DtCreateTemplates (Gbl_TemplateSignature);
877         if (ACPI_FAILURE (Status))
878         {
879             exit (-1);
880         }
881         exit (1);
882     }
883 
884     /* Next parameter must be the input filename */
885 
886     if (!argv[AcpiGbl_Optind] &&
887         !Gbl_DisasmFlag &&
888         !Gbl_GetAllTables)
889     {
890         printf ("Missing input filename\n");
891         BadCommandLine = TRUE;
892     }
893 
894     if (Gbl_DoSignon)
895     {
896         printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
897         if (Gbl_IgnoreErrors)
898         {
899             printf ("Ignoring all errors, forcing AML file generation\n\n");
900         }
901     }
902 
903     /* Abort if anything went wrong on the command line */
904 
905     if (BadCommandLine)
906     {
907         printf ("\n");
908         Usage ();
909         exit (1);
910     }
911 
912     return (AcpiGbl_Optind);
913 }
914 
915 
916 /*******************************************************************************
917  *
918  * FUNCTION:    main
919  *
920  * PARAMETERS:  Standard argc/argv
921  *
922  * RETURN:      Program termination code
923  *
924  * DESCRIPTION: C main routine for the Asl Compiler. Handle command line
925  *              options and begin the compile for each file on the command line
926  *
927  ******************************************************************************/
928 
929 int ACPI_SYSTEM_XFACE
930 main (
931     int                     argc,
932     char                    **argv)
933 {
934     ACPI_STATUS             Status;
935     int                     Index1;
936     int                     Index2;
937 
938 
939     AcpiGbl_ExternalFileList = NULL;
940 
941 #ifdef _DEBUG
942     _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF |
943                     _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
944 #endif
945 
946     /* Init and command line */
947 
948     AslInitialize ();
949     PrInitializePreprocessor ();
950     Index1 = Index2 = AslCommandLine (argc, argv);
951 
952     /* Options that have no additional parameters or pathnames */
953 
954     if (Gbl_GetAllTables)
955     {
956         Status = AslDoOneFile (NULL);
957         if (ACPI_FAILURE (Status))
958         {
959             return (-1);
960         }
961         return (0);
962     }
963 
964     if (Gbl_DisassembleAll)
965     {
966         while (argv[Index1])
967         {
968             Status = AslDoOnePathname (argv[Index1], AcpiDmAddToExternalFileList);
969             if (ACPI_FAILURE (Status))
970             {
971                 return (-1);
972             }
973 
974             Index1++;
975         }
976     }
977 
978     /* Process each pathname/filename in the list, with possible wildcards */
979 
980     while (argv[Index2])
981     {
982         Status = AslDoOnePathname (argv[Index2], AslDoOneFile);
983         if (ACPI_FAILURE (Status))
984         {
985             return (-1);
986         }
987 
988         Index2++;
989     }
990 
991     if (AcpiGbl_ExternalFileList)
992     {
993         AcpiDmClearExternalFileList();
994     }
995 
996     return (0);
997 }
998 
999 
1000