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