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