checkdirs() was being passed the wrong mount point, resulting in a panic
[dragonfly.git] / sys / contrib / dev / acpica-unix-20050309 / compiler / aslmain.c
blob9b7ae28149f489cbe8b406981d56038515e4fa3f
2 /******************************************************************************
4 * Module Name: aslmain - compiler main and utilities
5 * $Revision: 79 $
7 *****************************************************************************/
9 /******************************************************************************
11 * 1. Copyright Notice
13 * Some or all of this work - Copyright (c) 1999 - 2005, 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 "acapps.h"
125 #ifdef _DEBUG
126 #include <crtdbg.h>
127 #endif
129 #define _COMPONENT ACPI_COMPILER
130 ACPI_MODULE_NAME ("aslmain")
132 BOOLEAN AslToFile = TRUE;
133 BOOLEAN DoCompile = TRUE;
134 BOOLEAN DoSignon = TRUE;
136 char hex[] = {'0','1','2','3','4','5','6','7',
137 '8','9','A','B','C','D','E','F'};
140 /*******************************************************************************
142 * FUNCTION: Options
144 * PARAMETERS: None
146 * RETURN: None
148 * DESCRIPTION: Display option help message
150 ******************************************************************************/
152 void
153 Options (
154 void)
157 printf ("General Output:\n");
158 printf (" -p <prefix> Specify filename prefix for all output files (including .aml)\n");
159 printf (" -vi Less verbose errors and warnings for use with IDEs\n");
160 printf (" -vo Enable optimization comments\n");
161 printf (" -vr Disable remarks\n");
162 printf (" -vs Disable signon\n");
164 printf ("\nAML Output Files:\n");
165 printf (" -s<a|c> Create AML in assembler or C source file (*.asm or *.c)\n");
166 printf (" -i<a|c> Create assembler or C include file (*.inc or *.h)\n");
167 printf (" -t<a|c> Create AML in assembler or C hex table (*.hex)\n");
169 printf ("\nAML Code Generation:\n");
170 printf (" -oa Disable all optimizations (compatibility mode)\n");
171 printf (" -of Disable constant folding\n");
172 printf (" -oi Disable integer optimization to Zero/One/Ones\n");
173 printf (" -on Disable named reference string optimization\n");
174 printf (" -r<Revision> Override table header Revision (1-255)\n");
176 printf ("\nListings:\n");
177 printf (" -l Create mixed listing file (ASL source and AML) (*.lst)\n");
178 printf (" -ln Create namespace file (*.nsp)\n");
179 printf (" -ls Create combined source file (expanded includes) (*.src)\n");
181 printf ("\nAML Disassembler:\n");
182 printf (" -d [file] Disassemble AML to ASL source code file (*.dsl)\n");
183 printf (" -dc [file] Disassemble AML and immediately compile it\n");
184 printf (" (Obtain DSDT from current system if no input file)\n");
185 printf (" -e Generate External() statements for unresolved symbols\n");
186 printf (" -g Get ACPI tables and write to files (*.dat)\n");
188 printf ("\nMiscellaneous:\n");
189 printf (" -a Verify source file is entirely ASCII text (0x00-0x7F)\n");
191 printf ("\nHelp:\n");
192 printf (" -h Additional help and compiler debug options\n");
193 printf (" -hc Display operators allowed in constant expressions\n");
194 printf (" -hr Display ACPI reserved method names\n");
198 /*******************************************************************************
200 * FUNCTION: Usage
202 * PARAMETERS: None
204 * RETURN: None
206 * DESCRIPTION: Display help message
208 ******************************************************************************/
210 void
211 HelpMessage (
212 void)
215 printf ("AML output filename generation:\n");
216 printf (" Output filenames are generated by appending an extension to a common\n");
217 printf (" filename prefix. The filename prefix is obtained via one of the\n");
218 printf (" following methods (in priority order):\n");
219 printf (" 1) The -p option specifies the prefix\n");
220 printf (" 2) The prefix of the AMLFileName in the ASL Definition Block\n");
221 printf (" 3) The prefix of the input filename\n");
222 printf ("\n");
224 Options ();
226 printf ("\nCompiler Debug Options:\n");
227 printf (" -b<p|t|b> Create compiler debug/trace file (*.txt)\n");
228 printf (" Types: Parse/Tree/Both\n");
229 printf (" -f Ignore errors, force creation of AML output file(s)\n");
230 printf (" -c Parse only, no output generation\n");
231 printf (" -ot Display compile times\n");
232 printf (" -x<level> Set debug level for trace output\n");
236 /*******************************************************************************
238 * FUNCTION: Usage
240 * PARAMETERS: None
242 * RETURN: None
244 * DESCRIPTION: Display usage and option message
246 ******************************************************************************/
248 void
249 Usage (
250 void)
253 printf ("Usage: %s [Options] [InputFile]\n\n", CompilerName);
254 Options ();
258 /*******************************************************************************
260 * FUNCTION: AslInitialize
262 * PARAMETERS: None
264 * RETURN: None
266 * DESCRIPTION: Initialize compiler globals
268 ******************************************************************************/
270 void
271 AslInitialize (void)
273 UINT32 i;
276 #ifdef _DEBUG
277 _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0));
278 #endif
280 AcpiDbgLevel = 0;
282 for (i = 0; i < ASL_NUM_FILES; i++)
284 Gbl_Files[i].Handle = NULL;
285 Gbl_Files[i].Filename = NULL;
288 Gbl_Files[ASL_FILE_STDOUT].Handle = stdout;
289 Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
291 Gbl_Files[ASL_FILE_STDERR].Handle = stderr;
292 Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
296 /*******************************************************************************
298 * FUNCTION: AslCommandLine
300 * PARAMETERS: argc/argv
302 * RETURN: None
304 * DESCRIPTION: Command line processing
306 ******************************************************************************/
308 void
309 AslCommandLine (
310 int argc,
311 char **argv)
313 BOOLEAN BadCommandLine = FALSE;
314 ACPI_NATIVE_UINT j;
317 /* Minimum command line contains at least one option or an input file */
319 if (argc < 2)
321 AslCompilerSignon (ASL_FILE_STDOUT);
322 Usage ();
323 exit (1);
326 /* Get the command line options */
328 while ((j = AcpiGetopt (argc, argv, "ab:cd^efgh^i^l^o:p:r:s:t:v:x:")) != EOF) switch (j)
330 case 'a':
331 Gbl_CheckForAscii = TRUE;
332 break;
335 case 'b':
337 switch (AcpiGbl_Optarg[0])
339 case 'b':
340 AslCompilerdebug = 1; /* same as yydebug */
341 break;
343 case 'p':
344 AslCompilerdebug = 1; /* same as yydebug */
345 break;
347 case 't':
348 break;
350 default:
351 printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
352 BadCommandLine = TRUE;
353 break;
356 /* Produce debug output file */
358 Gbl_DebugFlag = TRUE;
359 break;
362 case 'c':
364 /* Parse only */
366 Gbl_ParseOnlyFlag = TRUE;
367 break;
370 case 'd':
371 switch (AcpiGbl_Optarg[0])
373 case '^':
374 DoCompile = FALSE;
375 break;
377 case 'c':
378 break;
380 default:
381 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
382 BadCommandLine = TRUE;
383 break;
386 Gbl_DisasmFlag = TRUE;
387 break;
390 case 'e':
392 /* Generate external statements for unresolved symbols */
394 Gbl_GenerateExternals = TRUE;
395 break;
398 case 'f':
400 /* Ignore errors and force creation of aml file */
402 Gbl_IgnoreErrors = TRUE;
403 break;
406 case 'g':
408 /* Get all ACPI tables */
410 Gbl_GetAllTables = TRUE;
411 DoCompile = FALSE;
412 break;
415 case 'h':
417 switch (AcpiGbl_Optarg[0])
419 case '^':
420 HelpMessage ();
421 exit (0);
423 case 'c':
424 UtDisplayConstantOpcodes ();
425 exit (0);
427 case 'r':
428 /* reserved names */
430 MpDisplayReservedNames ();
431 exit (0);
433 default:
434 printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
435 BadCommandLine = TRUE;
436 break;
438 break;
441 case 'i':
443 switch (AcpiGbl_Optarg[0])
445 case 'a':
447 /* Produce assembly code include file */
449 Gbl_AsmIncludeOutputFlag = TRUE;
450 break;
452 case 'c':
454 /* Produce C include file */
456 Gbl_C_IncludeOutputFlag = TRUE;
457 break;
459 default:
460 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
461 BadCommandLine = TRUE;
462 break;
464 break;
467 case 'l':
469 switch (AcpiGbl_Optarg[0])
471 case '^':
472 /* Produce listing file (Mixed source/aml) */
474 Gbl_ListingFlag = TRUE;
475 break;
477 case 'n':
478 /* Produce namespace file */
480 Gbl_NsOutputFlag = TRUE;
481 break;
483 case 's':
484 /* Produce combined source file */
486 Gbl_SourceOutputFlag = TRUE;
487 break;
489 default:
490 printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
491 BadCommandLine = TRUE;
492 break;
494 break;
497 case 'o':
499 switch (AcpiGbl_Optarg[0])
501 case 'a':
503 /* Disable all optimizations */
505 Gbl_FoldConstants = FALSE;
506 Gbl_IntegerOptimizationFlag = FALSE;
507 Gbl_ReferenceOptimizationFlag = FALSE;
508 break;
510 case 'f':
512 /* Disable folding on "normal" expressions */
514 Gbl_FoldConstants = FALSE;
515 break;
517 case 'i':
519 /* Disable integer optimization to constants */
521 Gbl_IntegerOptimizationFlag = FALSE;
522 break;
524 case 'n':
526 /* Disable named reference optimization */
528 Gbl_ReferenceOptimizationFlag = FALSE;
529 break;
531 case 't':
533 /* Display compile time(s) */
535 Gbl_CompileTimesFlag = TRUE;
536 break;
538 default:
539 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
540 BadCommandLine = TRUE;
541 break;
543 break;
546 case 'p':
548 /* Override default AML output filename */
550 Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
551 Gbl_UseDefaultAmlFilename = FALSE;
552 break;
555 case 'r':
556 Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
557 break;
560 case 's':
562 switch (AcpiGbl_Optarg[0])
564 case 'a':
566 /* Produce assembly code output file */
568 Gbl_AsmOutputFlag = TRUE;
569 break;
571 case 'c':
573 /* Produce C hex output file */
575 Gbl_C_OutputFlag = TRUE;
576 break;
578 default:
579 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
580 BadCommandLine = TRUE;
581 break;
583 break;
586 case 't':
588 /* Produce hex table output file */
590 switch (AcpiGbl_Optarg[0])
592 case 'a':
593 Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
594 break;
596 case 'c':
597 Gbl_HexOutputFlag = HEX_OUTPUT_C;
598 break;
600 default:
601 printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
602 BadCommandLine = TRUE;
603 break;
605 break;
608 case 'v':
610 switch (AcpiGbl_Optarg[0])
612 case 'i':
613 /* Less verbose error messages */
615 Gbl_VerboseErrors = FALSE;
616 break;
618 case 'o':
619 Gbl_DisplayOptimizations = TRUE;
620 break;
622 case 'r':
623 Gbl_DisplayRemarks = FALSE;
624 break;
626 case 's':
627 DoSignon = FALSE;
628 break;
630 default:
631 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
632 BadCommandLine = TRUE;
633 break;
635 break;
638 case 'x':
640 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
641 break;
644 default:
646 BadCommandLine = TRUE;
647 break;
650 /* Next parameter must be the input filename */
652 Gbl_Files[ASL_FILE_INPUT].Filename = argv[AcpiGbl_Optind];
653 if (!Gbl_Files[ASL_FILE_INPUT].Filename && !Gbl_DisasmFlag && !Gbl_GetAllTables)
655 printf ("Missing input filename\n");
656 BadCommandLine = TRUE;
659 if (DoSignon)
661 AslCompilerSignon (ASL_FILE_STDOUT);
664 /* Abort if anything went wrong on the command line */
666 if (BadCommandLine)
668 printf ("\n");
669 Usage ();
670 exit (1);
673 if ((AcpiGbl_Optind + 1) < argc)
675 printf ("Warning: extra arguments (%d) after input filename are ignored\n\n",
676 argc - AcpiGbl_Optind - 1);
681 /*******************************************************************************
683 * FUNCTION: main
685 * PARAMETERS: Standard argc/argv
687 * RETURN: Program termination code
689 * DESCRIPTION: C main routine for the Asl Compiler. Handle command line
690 * options and begin the compile.
692 ******************************************************************************/
694 int ACPI_SYSTEM_XFACE
695 main (
696 int argc,
697 char **argv)
699 ACPI_STATUS Status;
700 char *Prefix;
703 /* Init and command line */
705 AslInitialize ();
706 AslCommandLine (argc, argv);
709 * If -p not specified, we will use the input filename as the
710 * output filename prefix
712 FlSplitInputPathname (Gbl_Files[ASL_FILE_INPUT].Filename,
713 &Gbl_DirectoryPath, &Prefix);
715 if (Gbl_UseDefaultAmlFilename)
717 Gbl_OutputFilenamePrefix = Prefix;
721 * AML Disassembly (Optional)
723 if (Gbl_DisasmFlag || Gbl_GetAllTables)
725 /* ACPI CA subsystem initialization */
727 Status = AcpiOsInitialize ();
728 AcpiUtInitGlobals ();
729 Status = AcpiUtMutexInitialize ();
730 if (ACPI_FAILURE (Status))
732 return -1;
735 Status = AcpiNsRootInitialize ();
736 if (ACPI_FAILURE (Status))
738 return -1;
741 /* This is where the disassembly happens */
743 AcpiGbl_DbOpt_disasm = TRUE;
744 Status = AdAmlDisassemble (AslToFile,
745 Gbl_Files[ASL_FILE_INPUT].Filename,
746 Gbl_OutputFilenamePrefix,
747 &Gbl_Files[ASL_FILE_INPUT].Filename,
748 Gbl_GetAllTables);
749 if (ACPI_FAILURE (Status))
751 return -1;
755 * Gbl_Files[ASL_FILE_INPUT].Filename was replaced with the
756 * .DSL disassembly file, which can now be compiled if requested
758 if (DoCompile)
760 AcpiOsPrintf ("\nCompiling \"%s\"\n",
761 Gbl_Files[ASL_FILE_INPUT].Filename);
766 * ASL Compilation (Optional)
768 if (DoCompile)
771 * If -p not specified, we will use the input filename as the
772 * output filename prefix
774 FlSplitInputPathname (Gbl_Files[ASL_FILE_INPUT].Filename,
775 &Gbl_DirectoryPath, &Prefix);
777 if (Gbl_UseDefaultAmlFilename)
779 Gbl_OutputFilenamePrefix = Prefix;
782 /* ACPI CA subsystem initialization (Must be re-initialized) */
784 Status = AcpiOsInitialize ();
785 AcpiUtInitGlobals ();
786 Status = AcpiUtMutexInitialize ();
787 if (ACPI_FAILURE (Status))
789 return -1;
792 Status = AcpiNsRootInitialize ();
793 if (ACPI_FAILURE (Status))
795 return -1;
797 Status = CmDoCompile ();
800 return (0);