2 /******************************************************************************
4 * Module Name: aslmain - compiler main and utilities
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2011, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
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.
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.
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.
46 #define _DECLARE_GLOBALS
48 #include <contrib/dev/acpica/compiler/aslcompiler.h>
49 #include <contrib/dev/acpica/include/acapps.h>
50 #include <contrib/dev/acpica/include/acdisasm.h>
56 #define _COMPONENT ACPI_COMPILER
57 ACPI_MODULE_NAME ("aslmain")
59 /* Local prototypes */
86 BOOLEAN IsResponseFile);
89 AslMergeOptionTokens (
98 #define ASL_TOKEN_SEPARATORS " \t\n"
99 #define ASL_SUPPORTED_OPTIONS "@:2b:c:d^e:fgh^i^I:l^no:p:r:s:t:T:v:w:x:z"
102 /*******************************************************************************
110 * DESCRIPTION: Display option help message
112 ******************************************************************************/
119 printf ("Global:\n");
120 printf (" -@<file> Specify command file\n");
121 printf (" -I<dir> Specify additional include directory\n");
123 printf ("\nGeneral Output:\n");
124 printf (" -p<prefix> Specify path/filename prefix for all output files\n");
125 printf (" -va Disable all errors and warnings (summary only)\n");
126 printf (" -vi Less verbose errors and warnings for use with IDEs\n");
127 printf (" -vo Enable optimization comments\n");
128 printf (" -vr Disable remarks\n");
129 printf (" -vs Disable signon\n");
130 printf (" -w<1|2|3> Set warning reporting level\n");
132 printf ("\nAML Output Files:\n");
133 printf (" -s<a|c> Create AML in assembler or C source file (*.asm or *.c)\n");
134 printf (" -i<a|c> Create assembler or C include file (*.inc or *.h)\n");
135 printf (" -t<a|c|s> Create AML in assembler, C, or ASL hex table (*.hex)\n");
137 printf ("\nAML Code Generation:\n");
138 printf (" -oa Disable all optimizations (compatibility mode)\n");
139 printf (" -of Disable constant folding\n");
140 printf (" -oi Disable integer optimization to Zero/One/Ones\n");
141 printf (" -on Disable named reference string optimization\n");
142 printf (" -cr Disable Resource Descriptor error checking\n");
143 printf (" -r<Revision> Override table header Revision (1-255)\n");
145 printf ("\nASL Listing Files:\n");
146 printf (" -l Create mixed listing file (ASL source and AML) (*.lst)\n");
147 printf (" -ln Create namespace file (*.nsp)\n");
148 printf (" -ls Create combined source file (expanded includes) (*.src)\n");
150 printf ("\nACPI Data Tables:\n");
151 printf (" -T <Sig>|ALL|* Create table template file(s) for <Sig>\n");
152 printf (" -vt Create verbose templates (full disassembly)\n");
154 printf ("\nAML Disassembler:\n");
155 printf (" -d [file] Disassemble or decode binary ACPI table to file (*.dsl)\n");
156 printf (" -da [f1,f2] Disassemble multiple tables from single namespace\n");
157 printf (" -dc [file] Disassemble AML and immediately compile it\n");
158 printf (" (Obtain DSDT from current system if no input file)\n");
159 printf (" -e [f1,f2] Include ACPI table(s) for external symbol resolution\n");
160 printf (" -2 Emit ACPI 2.0 compatible ASL code\n");
161 printf (" -g Get ACPI tables and write to files (*.dat)\n");
163 printf ("\nHelp:\n");
164 printf (" -h Additional help and compiler debug options\n");
165 printf (" -hc Display operators allowed in constant expressions\n");
166 printf (" -hr Display ACPI reserved method names\n");
167 printf (" -ht Display currently supported ACPI table names\n");
171 /*******************************************************************************
173 * FUNCTION: HelpMessage
179 * DESCRIPTION: Display help message
181 ******************************************************************************/
188 printf ("AML output filename generation:\n");
189 printf (" Output filenames are generated by appending an extension to a common\n");
190 printf (" filename prefix. The filename prefix is obtained via one of the\n");
191 printf (" following methods (in priority order):\n");
192 printf (" 1) The -p option specifies the prefix\n");
193 printf (" 2) The prefix of the AMLFileName in the ASL Definition Block\n");
194 printf (" 3) The prefix of the input filename\n");
199 printf ("\nCompiler/Disassembler Debug Options:\n");
200 printf (" -b<p|t|b> Create compiler debug/trace file (*.txt)\n");
201 printf (" Types: Parse/Tree/Both\n");
202 printf (" -f Ignore errors, force creation of AML output file(s)\n");
203 printf (" -n Parse only, no output generation\n");
204 printf (" -ot Display compile times\n");
205 printf (" -x<level> Set debug level for trace output\n");
206 printf (" -z Do not insert new compiler ID for DataTables\n");
210 /*******************************************************************************
218 * DESCRIPTION: Display usage and option message
220 ******************************************************************************/
227 printf ("%s\n", ASL_COMPLIANCE);
228 printf ("Usage: %s [Options] [Files]\n\n", ASL_INVOCATION_NAME);
233 /*******************************************************************************
235 * FUNCTION: AslInitialize
241 * DESCRIPTION: Initialize compiler globals
243 ******************************************************************************/
253 _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0));
258 for (i = 0; i < ASL_NUM_FILES; i++)
260 Gbl_Files[i].Handle = NULL;
261 Gbl_Files[i].Filename = NULL;
264 Gbl_Files[ASL_FILE_STDOUT].Handle = stdout;
265 Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
267 Gbl_Files[ASL_FILE_STDERR].Handle = stderr;
268 Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
272 /*******************************************************************************
274 * FUNCTION: AslMergeOptionTokens
276 * PARAMETERS: InBuffer - Input containing an option string
277 * OutBuffer - Merged output buffer
281 * DESCRIPTION: Remove all whitespace from an option string.
283 ******************************************************************************/
286 AslMergeOptionTokens (
295 Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
298 strcat (OutBuffer, Token);
299 Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
304 /*******************************************************************************
306 * FUNCTION: AslDoResponseFile
308 * PARAMETERS: Filename - Name of the response file
312 * DESCRIPTION: Open a response file and process all options within.
314 ******************************************************************************/
320 char *argv = StringBuffer2;
327 ResponseFile = fopen (Filename, "r");
330 printf ("Could not open command file %s, %s\n",
331 Filename, strerror (errno));
335 /* Must save the current GetOpt globals */
337 Opterr = AcpiGbl_Opterr;
338 Optind = AcpiGbl_Optind;
341 * Process all lines in the response file. There must be one complete
344 while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile))
346 /* Compress all tokens, allowing us to use a single argv entry */
348 AslMergeOptionTokens (StringBuffer, StringBuffer2);
350 /* Process the option */
355 OptStatus = AslDoOptions (1, &argv, TRUE);
358 printf ("Invalid option in command file %s: %s\n",
359 Filename, StringBuffer);
364 /* Restore the GetOpt globals */
366 AcpiGbl_Opterr = Opterr;
367 AcpiGbl_Optind = Optind;
369 fclose (ResponseFile);
374 /*******************************************************************************
376 * FUNCTION: AslDoOptions
378 * PARAMETERS: argc/argv - Standard argc/argv
379 * IsResponseFile - TRUE if executing a response file.
383 * DESCRIPTION: Command line option processing
385 ******************************************************************************/
391 BOOLEAN IsResponseFile)
397 /* Get the command line options */
399 while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j)
401 case '@': /* Begin a response file */
405 printf ("Nested command files are not supported\n");
409 if (AslDoResponseFile (AcpiGbl_Optarg))
424 switch (AcpiGbl_Optarg[0])
427 AslCompilerdebug = 1; /* same as yydebug */
432 AslCompilerdebug = 1; /* same as yydebug */
440 printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
444 /* Produce debug output file */
446 Gbl_DebugFlag = TRUE;
451 switch (AcpiGbl_Optarg[0])
454 Gbl_NoResourceChecking = TRUE;
458 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
465 switch (AcpiGbl_Optarg[0])
468 Gbl_DoCompile = FALSE;
472 Gbl_DoCompile = FALSE;
473 Gbl_DisassembleAll = TRUE;
480 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
484 Gbl_DisasmFlag = TRUE;
489 Status = AcpiDmAddToExternalFileList (AcpiGbl_Optarg);
490 if (ACPI_FAILURE (Status))
492 printf ("Could not add %s to external list\n", AcpiGbl_Optarg);
500 /* Ignore errors and force creation of aml file */
502 Gbl_IgnoreErrors = TRUE;
508 /* Get all ACPI tables */
510 Gbl_GetAllTables = TRUE;
511 Gbl_DoCompile = FALSE;
517 switch (AcpiGbl_Optarg[0])
524 UtDisplayConstantOpcodes ();
530 ApDisplayReservedNames ();
534 UtDisplaySupportedTables ();
538 printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
543 case 'I': /* Add an include file search directory */
545 FlAddIncludeDirectory (AcpiGbl_Optarg);
551 switch (AcpiGbl_Optarg[0])
555 /* Produce assembly code include file */
557 Gbl_AsmIncludeOutputFlag = TRUE;
562 /* Produce C include file */
564 Gbl_C_IncludeOutputFlag = TRUE;
568 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
576 switch (AcpiGbl_Optarg[0])
579 /* Produce listing file (Mixed source/aml) */
581 Gbl_ListingFlag = TRUE;
585 /* Produce namespace file */
587 Gbl_NsOutputFlag = TRUE;
591 /* Produce combined source file */
593 Gbl_SourceOutputFlag = TRUE;
597 printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
605 switch (AcpiGbl_Optarg[0])
609 /* Disable all optimizations */
611 Gbl_FoldConstants = FALSE;
612 Gbl_IntegerOptimizationFlag = FALSE;
613 Gbl_ReferenceOptimizationFlag = FALSE;
618 /* Disable folding on "normal" expressions */
620 Gbl_FoldConstants = FALSE;
625 /* Disable integer optimization to constants */
627 Gbl_IntegerOptimizationFlag = FALSE;
632 /* Disable named reference optimization */
634 Gbl_ReferenceOptimizationFlag = FALSE;
639 /* Display compile time(s) */
641 Gbl_CompileTimesFlag = TRUE;
645 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
655 Gbl_ParseOnlyFlag = TRUE;
661 /* Override default AML output filename */
663 Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
664 Gbl_UseDefaultAmlFilename = FALSE;
669 Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
675 switch (AcpiGbl_Optarg[0])
679 /* Produce assembly code output file */
681 Gbl_AsmOutputFlag = TRUE;
686 /* Produce C hex output file */
688 Gbl_C_OutputFlag = TRUE;
692 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
700 /* Produce hex table output file */
702 switch (AcpiGbl_Optarg[0])
705 Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
709 Gbl_HexOutputFlag = HEX_OUTPUT_C;
713 Gbl_HexOutputFlag = HEX_OUTPUT_ASL;
717 printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
724 Gbl_DoTemplates = TRUE;
725 Gbl_TemplateSignature = AcpiGbl_Optarg;
731 switch (AcpiGbl_Optarg[0])
734 /* Disable All error/warning messages */
740 /* Less verbose error messages */
742 Gbl_VerboseErrors = FALSE;
746 Gbl_DisplayOptimizations = TRUE;
750 Gbl_DisplayRemarks = FALSE;
754 Gbl_DoSignon = FALSE;
758 Gbl_VerboseTemplates = TRUE;
762 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
768 case 'w': /* Set warning levels */
770 switch (AcpiGbl_Optarg[0])
773 Gbl_WarningLevel = ASL_WARNING;
777 Gbl_WarningLevel = ASL_WARNING2;
781 Gbl_WarningLevel = ASL_WARNING3;
785 printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
793 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
799 Gbl_UseOriginalCompilerId = TRUE;
812 /*******************************************************************************
814 * FUNCTION: AslCommandLine
816 * PARAMETERS: argc/argv
818 * RETURN: Last argv index
820 * DESCRIPTION: Command line processing
822 ******************************************************************************/
829 int BadCommandLine = 0;
833 /* Minimum command line contains at least the command and an input file */
837 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
842 /* Process all command line options */
844 BadCommandLine = AslDoOptions (argc, argv, FALSE);
848 Status = DtCreateTemplates (Gbl_TemplateSignature);
849 if (ACPI_FAILURE (Status))
856 /* Next parameter must be the input filename */
858 if (!argv[AcpiGbl_Optind] &&
862 printf ("Missing input filename\n");
863 BadCommandLine = TRUE;
868 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
871 /* Abort if anything went wrong on the command line */
880 return (AcpiGbl_Optind);
884 /*******************************************************************************
888 * PARAMETERS: Standard argc/argv
890 * RETURN: Program termination code
892 * DESCRIPTION: C main routine for the Asl Compiler. Handle command line
893 * options and begin the compile for each file on the command line
895 ******************************************************************************/
897 int ACPI_SYSTEM_XFACE
907 AcpiGbl_ExternalFileList = NULL;
910 _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF |
911 _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
914 /* Init and command line */
917 Index1 = Index2 = AslCommandLine (argc, argv);
919 /* Options that have no additional parameters or pathnames */
921 if (Gbl_GetAllTables)
923 Status = AslDoOneFile (NULL);
924 if (ACPI_FAILURE (Status))
931 if (Gbl_DisassembleAll)
935 Status = AslDoOnePathname (argv[Index1], AcpiDmAddToExternalFileList);
936 if (ACPI_FAILURE (Status))
945 /* Process each pathname/filename in the list, with possible wildcards */
949 Status = AslDoOnePathname (argv[Index2], AslDoOneFile);
950 if (ACPI_FAILURE (Status))
958 if (AcpiGbl_ExternalFileList)
960 AcpiDmClearExternalFileList();