i386/identcpu.c: Add VIA Nano support
[dragonfly.git] / sys / contrib / dev / acpica-unix-20061109 / compiler / aslmain.c
blob6b0c87bcabcc27d83f7298006f8ab1d997cb0943
2 /******************************************************************************
4 * Module Name: aslmain - compiler main and utilities
5 * $Revision: 1.94 $
7 *****************************************************************************/
9 /******************************************************************************
11 * 1. Copyright Notice
13 * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp.
14 * All rights reserved.
16 * 2. License
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
21 * property rights.
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
39 * The above copyright and patent license is granted only if the following
40 * conditions are met:
42 * 3. Conditions
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
66 * make.
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
72 * distribution.
74 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * Intel Code.
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
82 * 4. Disclaimer and Export Compliance
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * PARTICULAR PURPOSE.
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * LIMITED REMEDY.
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
116 *****************************************************************************/
119 #define _DECLARE_GLOBALS
121 #include "aslcompiler.h"
122 #include "acnamesp.h"
123 #include "actables.h"
124 #include "acapps.h"
126 #ifdef _DEBUG
127 #include <crtdbg.h>
128 #endif
130 #define _COMPONENT ACPI_COMPILER
131 ACPI_MODULE_NAME ("aslmain")
133 BOOLEAN AslToFile = TRUE;
134 BOOLEAN DoCompile = TRUE;
135 BOOLEAN DoSignon = TRUE;
137 char hex[] =
139 '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
142 /* Local prototypes */
144 static void
145 Options (
146 void);
148 static void
149 HelpMessage (
150 void);
152 static void
153 Usage (
154 void);
156 static void
157 AslInitialize (
158 void);
160 static void
161 AslCommandLine (
162 int argc,
163 char **argv);
165 #ifdef _DEBUG
166 #if ACPI_MACHINE_WIDTH != 16
167 #include <crtdbg.h>
168 #endif
169 #endif
171 /*******************************************************************************
173 * FUNCTION: Options
175 * PARAMETERS: None
177 * RETURN: None
179 * DESCRIPTION: Display option help message
181 ******************************************************************************/
183 static void
184 Options (
185 void)
188 printf ("General Output:\n");
189 printf (" -p <prefix> Specify filename prefix for all output files (including .aml)\n");
190 printf (" -vi Less verbose errors and warnings for use with IDEs\n");
191 printf (" -vo Enable optimization comments\n");
192 printf (" -vr Disable remarks\n");
193 printf (" -vs Disable signon\n");
194 printf (" -w<1|2|3> Set warning reporting level\n");
196 printf ("\nAML Output Files:\n");
197 printf (" -s<a|c> Create AML in assembler or C source file (*.asm or *.c)\n");
198 printf (" -i<a|c> Create assembler or C include file (*.inc or *.h)\n");
199 printf (" -t<a|c> Create AML in assembler or C hex table (*.hex)\n");
201 printf ("\nAML Code Generation:\n");
202 printf (" -oa Disable all optimizations (compatibility mode)\n");
203 printf (" -of Disable constant folding\n");
204 printf (" -oi Disable integer optimization to Zero/One/Ones\n");
205 printf (" -on Disable named reference string optimization\n");
206 printf (" -r<Revision> Override table header Revision (1-255)\n");
208 printf ("\nListings:\n");
209 printf (" -l Create mixed listing file (ASL source and AML) (*.lst)\n");
210 printf (" -ln Create namespace file (*.nsp)\n");
211 printf (" -ls Create combined source file (expanded includes) (*.src)\n");
213 printf ("\nAML Disassembler:\n");
214 printf (" -d [file] Disassemble or decode binary ACPI table to file (*.dsl)\n");
215 printf (" -dc [file] Disassemble AML and immediately compile it\n");
216 printf (" (Obtain DSDT from current system if no input file)\n");
217 printf (" -e [file] Include ACPI table for external symbol resolution\n");
218 printf (" -2 Emit ACPI 2.0 compatible ASL code\n");
219 printf (" -g Get ACPI tables and write to files (*.dat)\n");
221 printf ("\nHelp:\n");
222 printf (" -h Additional help and compiler debug options\n");
223 printf (" -hc Display operators allowed in constant expressions\n");
224 printf (" -hr Display ACPI reserved method names\n");
228 /*******************************************************************************
230 * FUNCTION: HelpMessage
232 * PARAMETERS: None
234 * RETURN: None
236 * DESCRIPTION: Display help message
238 ******************************************************************************/
240 static void
241 HelpMessage (
242 void)
245 printf ("AML output filename generation:\n");
246 printf (" Output filenames are generated by appending an extension to a common\n");
247 printf (" filename prefix. The filename prefix is obtained via one of the\n");
248 printf (" following methods (in priority order):\n");
249 printf (" 1) The -p option specifies the prefix\n");
250 printf (" 2) The prefix of the AMLFileName in the ASL Definition Block\n");
251 printf (" 3) The prefix of the input filename\n");
252 printf ("\n");
254 Options ();
256 printf ("\nCompiler/Disassembler Debug Options:\n");
257 printf (" -b<p|t|b> Create compiler debug/trace file (*.txt)\n");
258 printf (" Types: Parse/Tree/Both\n");
259 printf (" -f Ignore errors, force creation of AML output file(s)\n");
260 printf (" -c Parse only, no output generation\n");
261 printf (" -ot Display compile times\n");
262 printf (" -x<level> Set debug level for trace output\n");
266 /*******************************************************************************
268 * FUNCTION: Usage
270 * PARAMETERS: None
272 * RETURN: None
274 * DESCRIPTION: Display usage and option message
276 ******************************************************************************/
278 static void
279 Usage (
280 void)
283 printf ("Usage: %s [Options] [InputFile]\n\n", CompilerName);
284 Options ();
288 /*******************************************************************************
290 * FUNCTION: AslInitialize
292 * PARAMETERS: None
294 * RETURN: None
296 * DESCRIPTION: Initialize compiler globals
298 ******************************************************************************/
300 static void
301 AslInitialize (
302 void)
304 UINT32 i;
307 #ifdef _DEBUG
308 _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0));
309 #endif
311 AcpiDbgLevel = 0;
313 for (i = 0; i < ASL_NUM_FILES; i++)
315 Gbl_Files[i].Handle = NULL;
316 Gbl_Files[i].Filename = NULL;
319 Gbl_Files[ASL_FILE_STDOUT].Handle = stdout;
320 Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
322 Gbl_Files[ASL_FILE_STDERR].Handle = stderr;
323 Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
327 /*******************************************************************************
329 * FUNCTION: AslCommandLine
331 * PARAMETERS: argc/argv
333 * RETURN: None
335 * DESCRIPTION: Command line processing
337 ******************************************************************************/
339 static void
340 AslCommandLine (
341 int argc,
342 char **argv)
344 BOOLEAN BadCommandLine = FALSE;
345 ACPI_NATIVE_INT j;
348 /* Minimum command line contains at least one option or an input file */
350 if (argc < 2)
352 AslCompilerSignon (ASL_FILE_STDOUT);
353 Usage ();
354 exit (1);
357 /* Get the command line options */
359 while ((j = AcpiGetopt (argc, argv, "2b:cd^e:fgh^i^l^o:p:r:s:t:v:w:x:")) != EOF) switch (j)
361 case '2':
362 Gbl_Acpi2 = TRUE;
363 break;
366 case 'b':
368 switch (AcpiGbl_Optarg[0])
370 case 'b':
371 AslCompilerdebug = 1; /* same as yydebug */
372 break;
374 case 'p':
375 AslCompilerdebug = 1; /* same as yydebug */
376 break;
378 case 't':
379 break;
381 default:
382 printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
383 BadCommandLine = TRUE;
384 break;
387 /* Produce debug output file */
389 Gbl_DebugFlag = TRUE;
390 break;
393 case 'c':
395 /* Parse only */
397 Gbl_ParseOnlyFlag = TRUE;
398 break;
401 case 'd':
402 switch (AcpiGbl_Optarg[0])
404 case '^':
405 DoCompile = FALSE;
406 break;
408 case 'c':
409 break;
411 default:
412 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
413 BadCommandLine = TRUE;
414 break;
417 Gbl_DisasmFlag = TRUE;
418 break;
421 case 'e':
422 Gbl_ExternalFilename = AcpiGbl_Optarg;
423 break;
426 case 'f':
428 /* Ignore errors and force creation of aml file */
430 Gbl_IgnoreErrors = TRUE;
431 break;
434 case 'g':
436 /* Get all ACPI tables */
438 Gbl_GetAllTables = TRUE;
439 DoCompile = FALSE;
440 break;
443 case 'h':
445 switch (AcpiGbl_Optarg[0])
447 case '^':
448 HelpMessage ();
449 exit (0);
451 case 'c':
452 UtDisplayConstantOpcodes ();
453 exit (0);
455 case 'r':
456 /* reserved names */
458 MpDisplayReservedNames ();
459 exit (0);
461 default:
462 printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
463 BadCommandLine = TRUE;
464 break;
466 break;
469 case 'i':
471 switch (AcpiGbl_Optarg[0])
473 case 'a':
475 /* Produce assembly code include file */
477 Gbl_AsmIncludeOutputFlag = TRUE;
478 break;
480 case 'c':
482 /* Produce C include file */
484 Gbl_C_IncludeOutputFlag = TRUE;
485 break;
487 default:
488 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
489 BadCommandLine = TRUE;
490 break;
492 break;
495 case 'l':
497 switch (AcpiGbl_Optarg[0])
499 case '^':
500 /* Produce listing file (Mixed source/aml) */
502 Gbl_ListingFlag = TRUE;
503 break;
505 case 'n':
506 /* Produce namespace file */
508 Gbl_NsOutputFlag = TRUE;
509 break;
511 case 's':
512 /* Produce combined source file */
514 Gbl_SourceOutputFlag = TRUE;
515 break;
517 default:
518 printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
519 BadCommandLine = TRUE;
520 break;
522 break;
525 case 'o':
527 switch (AcpiGbl_Optarg[0])
529 case 'a':
531 /* Disable all optimizations */
533 Gbl_FoldConstants = FALSE;
534 Gbl_IntegerOptimizationFlag = FALSE;
535 Gbl_ReferenceOptimizationFlag = FALSE;
536 break;
538 case 'f':
540 /* Disable folding on "normal" expressions */
542 Gbl_FoldConstants = FALSE;
543 break;
545 case 'i':
547 /* Disable integer optimization to constants */
549 Gbl_IntegerOptimizationFlag = FALSE;
550 break;
552 case 'n':
554 /* Disable named reference optimization */
556 Gbl_ReferenceOptimizationFlag = FALSE;
557 break;
559 case 't':
561 /* Display compile time(s) */
563 Gbl_CompileTimesFlag = TRUE;
564 break;
566 default:
567 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
568 BadCommandLine = TRUE;
569 break;
571 break;
574 case 'p':
576 /* Override default AML output filename */
578 Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
579 Gbl_UseDefaultAmlFilename = FALSE;
580 break;
583 case 'r':
584 Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
585 break;
588 case 's':
590 switch (AcpiGbl_Optarg[0])
592 case 'a':
594 /* Produce assembly code output file */
596 Gbl_AsmOutputFlag = TRUE;
597 break;
599 case 'c':
601 /* Produce C hex output file */
603 Gbl_C_OutputFlag = TRUE;
604 break;
606 default:
607 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
608 BadCommandLine = TRUE;
609 break;
611 break;
614 case 't':
616 /* Produce hex table output file */
618 switch (AcpiGbl_Optarg[0])
620 case 'a':
621 Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
622 break;
624 case 'c':
625 Gbl_HexOutputFlag = HEX_OUTPUT_C;
626 break;
628 default:
629 printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
630 BadCommandLine = TRUE;
631 break;
633 break;
636 case 'v':
638 switch (AcpiGbl_Optarg[0])
640 case 'i':
641 /* Less verbose error messages */
643 Gbl_VerboseErrors = FALSE;
644 break;
646 case 'o':
647 Gbl_DisplayOptimizations = TRUE;
648 break;
650 case 'r':
651 Gbl_DisplayRemarks = FALSE;
652 break;
654 case 's':
655 DoSignon = FALSE;
656 break;
658 default:
659 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
660 BadCommandLine = TRUE;
661 break;
663 break;
666 case 'w': /* Set warning levels */
668 switch (AcpiGbl_Optarg[0])
670 case '1':
671 Gbl_WarningLevel = ASL_WARNING;
672 break;
674 case '2':
675 Gbl_WarningLevel = ASL_WARNING2;
676 break;
678 case '3':
679 Gbl_WarningLevel = ASL_WARNING3;
680 break;
682 default:
683 printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
684 BadCommandLine = TRUE;
685 break;
687 break;
690 case 'x':
692 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
693 break;
696 default:
698 BadCommandLine = TRUE;
699 break;
702 /* Next parameter must be the input filename */
704 Gbl_Files[ASL_FILE_INPUT].Filename = argv[AcpiGbl_Optind];
706 if (!Gbl_Files[ASL_FILE_INPUT].Filename &&
707 !Gbl_DisasmFlag &&
708 !Gbl_GetAllTables)
710 printf ("Missing input filename\n");
711 BadCommandLine = TRUE;
714 if (DoSignon)
716 AslCompilerSignon (ASL_FILE_STDOUT);
719 /* Abort if anything went wrong on the command line */
721 if (BadCommandLine)
723 printf ("\n");
724 Usage ();
725 exit (1);
728 if ((AcpiGbl_Optind + 1) < argc)
730 printf ("Warning: extra arguments (%d) after input filename are ignored\n\n",
731 argc - AcpiGbl_Optind - 1);
736 /*******************************************************************************
738 * FUNCTION: main
740 * PARAMETERS: Standard argc/argv
742 * RETURN: Program termination code
744 * DESCRIPTION: C main routine for the Asl Compiler. Handle command line
745 * options and begin the compile.
747 ******************************************************************************/
749 int ACPI_SYSTEM_XFACE
750 main (
751 int argc,
752 char **argv)
754 ACPI_STATUS Status;
755 char *Prefix;
758 #ifdef _DEBUG
759 #if ACPI_MACHINE_WIDTH != 16
760 _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF |
761 _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
762 #endif
763 #endif
765 /* Init and command line */
767 AslInitialize ();
768 AslCommandLine (argc, argv);
771 * If -p not specified, we will use the input filename as the
772 * output filename prefix
774 Status = FlSplitInputPathname (Gbl_Files[ASL_FILE_INPUT].Filename,
775 &Gbl_DirectoryPath, &Prefix);
776 if (ACPI_FAILURE (Status))
778 return -1;
781 if (Gbl_UseDefaultAmlFilename)
783 Gbl_OutputFilenamePrefix = Prefix;
786 /* AML Disassembly (Optional) */
788 if (Gbl_DisasmFlag || Gbl_GetAllTables)
790 /* ACPI CA subsystem initialization */
792 Status = AdInitialize ();
793 if (ACPI_FAILURE (Status))
795 return -1;
798 Status = AcpiAllocateRootTable (4);
799 if (ACPI_FAILURE (Status))
801 AcpiOsPrintf ("Could not initialize ACPI Table Manager, %s\n",
802 AcpiFormatException (Status));
803 return -1;
806 /* This is where the disassembly happens */
808 AcpiGbl_DbOpt_disasm = TRUE;
809 Status = AdAmlDisassemble (AslToFile,
810 Gbl_Files[ASL_FILE_INPUT].Filename,
811 Gbl_OutputFilenamePrefix,
812 &Gbl_Files[ASL_FILE_INPUT].Filename,
813 Gbl_GetAllTables);
814 if (ACPI_FAILURE (Status))
816 return -1;
820 * Gbl_Files[ASL_FILE_INPUT].Filename was replaced with the
821 * .DSL disassembly file, which can now be compiled if requested
823 if (DoCompile)
825 AcpiOsPrintf ("\nCompiling \"%s\"\n",
826 Gbl_Files[ASL_FILE_INPUT].Filename);
831 * ASL Compilation (Optional)
833 if (DoCompile)
836 * If -p not specified, we will use the input filename as the
837 * output filename prefix
839 Status = FlSplitInputPathname (Gbl_Files[ASL_FILE_INPUT].Filename,
840 &Gbl_DirectoryPath, &Prefix);
841 if (ACPI_FAILURE (Status))
843 return -1;
846 if (Gbl_UseDefaultAmlFilename)
848 Gbl_OutputFilenamePrefix = Prefix;
851 /* ACPI CA subsystem initialization (Must be re-initialized) */
853 Status = AcpiOsInitialize ();
854 AcpiUtInitGlobals ();
855 Status = AcpiUtMutexInitialize ();
856 if (ACPI_FAILURE (Status))
858 return -1;
861 Status = AcpiNsRootInitialize ();
862 if (ACPI_FAILURE (Status))
864 return -1;
866 Status = CmDoCompile ();
869 return (0);