1 2 /****************************************************************************** 3 * 4 * Module Name: aslmain - compiler main and utilities 5 * 6 *****************************************************************************/ 7 8 /****************************************************************************** 9 * 10 * 1. Copyright Notice 11 * 12 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp. 13 * All rights reserved. 14 * 15 * 2. License 16 * 17 * 2.1. This is your license from Intel Corp. under its intellectual property 18 * rights. You may have additional license terms from the party that provided 19 * you this software, covering your right to use that party's intellectual 20 * property rights. 21 * 22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23 * copy of the source code appearing in this file ("Covered Code") an 24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25 * base code distributed originally by Intel ("Original Intel Code") to copy, 26 * make derivatives, distribute, use and display any portion of the Covered 27 * Code in any form, with the right to sublicense such rights; and 28 * 29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30 * license (with the right to sublicense), under only those claims of Intel 31 * patents that are infringed by the Original Intel Code, to make, use, sell, 32 * offer to sell, and import the Covered Code and derivative works thereof 33 * solely to the minimum extent necessary to exercise the above copyright 34 * license, and in no event shall the patent license extend to any additions 35 * to or modifications of the Original Intel Code. No other license or right 36 * is granted directly or by implication, estoppel or otherwise; 37 * 38 * The above copyright and patent license is granted only if the following 39 * conditions are met: 40 * 41 * 3. Conditions 42 * 43 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44 * Redistribution of source code of any substantial portion of the Covered 45 * Code or modification with rights to further distribute source must include 46 * the above Copyright Notice, the above License, this list of Conditions, 47 * and the following Disclaimer and Export Compliance provision. In addition, 48 * Licensee must cause all Covered Code to which Licensee contributes to 49 * contain a file documenting the changes Licensee made to create that Covered 50 * Code and the date of any change. Licensee must include in that file the 51 * documentation of any changes made by any predecessor Licensee. Licensee 52 * must include a prominent statement that the modification is derived, 53 * directly or indirectly, from Original Intel Code. 54 * 55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56 * Redistribution of source code of any substantial portion of the Covered 57 * Code or modification without rights to further distribute source must 58 * include the following Disclaimer and Export Compliance provision in the 59 * documentation and/or other materials provided with distribution. In 60 * addition, Licensee may not authorize further sublicense of source of any 61 * portion of the Covered Code, and must include terms to the effect that the 62 * license from Licensee to its licensee is limited to the intellectual 63 * property embodied in the software Licensee provides to its licensee, and 64 * not to intellectual property embodied in modifications its licensee may 65 * make. 66 * 67 * 3.3. Redistribution of Executable. Redistribution in executable form of any 68 * substantial portion of the Covered Code or modification must reproduce the 69 * above Copyright Notice, and the following Disclaimer and Export Compliance 70 * provision in the documentation and/or other materials provided with the 71 * distribution. 72 * 73 * 3.4. Intel retains all right, title, and interest in and to the Original 74 * Intel Code. 75 * 76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77 * Intel shall be used in advertising or otherwise to promote the sale, use or 78 * other dealings in products derived from or relating to the Covered Code 79 * without prior written authorization from Intel. 80 * 81 * 4. Disclaimer and Export Compliance 82 * 83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89 * PARTICULAR PURPOSE. 90 * 91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98 * LIMITED REMEDY. 99 * 100 * 4.3. Licensee shall not export, either directly or indirectly, any of this 101 * software or system incorporating such software without first obtaining any 102 * required license or other approval from the U. S. Department of Commerce or 103 * any other agency or department of the United States Government. In the 104 * event Licensee exports any such software from the United States or 105 * re-exports any such software from a foreign destination, Licensee shall 106 * ensure that the distribution and export/re-export of the software is in 107 * compliance with all laws, regulations, orders, or other restrictions of the 108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109 * any of its subsidiaries will export/re-export any technical data, process, 110 * software, or service, directly or indirectly, to any country for which the 111 * United States government or any agency thereof requires an export license, 112 * other governmental approval, or letter of assurance, without first obtaining 113 * such license, approval or letter. 114 * 115 *****************************************************************************/ 116 117 118 #define _DECLARE_GLOBALS 119 120 #include <contrib/dev/acpica/compiler/aslcompiler.h> 121 #include <contrib/dev/acpica/include/acapps.h> 122 #include <contrib/dev/acpica/include/acdisasm.h> 123 124 #ifdef _DEBUG 125 #include <crtdbg.h> 126 #endif 127 128 #define _COMPONENT ACPI_COMPILER 129 ACPI_MODULE_NAME ("aslmain") 130 131 /* Local prototypes */ 132 133 static void 134 Options ( 135 void); 136 137 static void 138 HelpMessage ( 139 void); 140 141 static void 142 Usage ( 143 void); 144 145 static void 146 AslInitialize ( 147 void); 148 149 static int 150 AslCommandLine ( 151 int argc, 152 char **argv); 153 154 static int 155 AslDoOptions ( 156 int argc, 157 char **argv, 158 BOOLEAN IsResponseFile); 159 160 static void 161 AslMergeOptionTokens ( 162 char *InBuffer, 163 char *OutBuffer); 164 165 static int 166 AslDoResponseFile ( 167 char *Filename); 168 169 170 #define ASL_TOKEN_SEPARATORS " \t\n" 171 #define ASL_SUPPORTED_OPTIONS "@:2b:c:d^e:fgh^i^I:l^no:p:r:s:t:T:v:w:x:z" 172 173 174 /******************************************************************************* 175 * 176 * FUNCTION: Options 177 * 178 * PARAMETERS: None 179 * 180 * RETURN: None 181 * 182 * DESCRIPTION: Display option help message 183 * 184 ******************************************************************************/ 185 186 static void 187 Options ( 188 void) 189 { 190 191 printf ("Global:\n"); 192 printf (" -@<file> Specify command file\n"); 193 printf (" -I<dir> Specify additional include directory\n"); 194 195 printf ("\nGeneral Output:\n"); 196 printf (" -p<prefix> Specify path/filename prefix for all output files\n"); 197 printf (" -va Disable all errors and warnings (summary only)\n"); 198 printf (" -vi Less verbose errors and warnings for use with IDEs\n"); 199 printf (" -vo Enable optimization comments\n"); 200 printf (" -vr Disable remarks\n"); 201 printf (" -vs Disable signon\n"); 202 printf (" -w<1|2|3> Set warning reporting level\n"); 203 204 printf ("\nAML Output Files:\n"); 205 printf (" -s<a|c> Create AML in assembler or C source file (*.asm or *.c)\n"); 206 printf (" -i<a|c> Create assembler or C include file (*.inc or *.h)\n"); 207 printf (" -t<a|c|s> Create AML in assembler, C, or ASL hex table (*.hex)\n"); 208 209 printf ("\nAML Code Generation:\n"); 210 printf (" -oa Disable all optimizations (compatibility mode)\n"); 211 printf (" -of Disable constant folding\n"); 212 printf (" -oi Disable integer optimization to Zero/One/Ones\n"); 213 printf (" -on Disable named reference string optimization\n"); 214 printf (" -cr Disable Resource Descriptor error checking\n"); 215 printf (" -r<Revision> Override table header Revision (1-255)\n"); 216 217 printf ("\nListings:\n"); 218 printf (" -l Create mixed listing file (ASL source and AML) (*.lst)\n"); 219 printf (" -ln Create namespace file (*.nsp)\n"); 220 printf (" -ls Create combined source file (expanded includes) (*.src)\n"); 221 222 printf ("\nACPI Data Tables:\n"); 223 printf (" -T <Sig> Create table template file for <Sig> (or \"ALL\")\n"); 224 printf (" -vt Create verbose templates (full disassembly)\n"); 225 226 printf ("\nAML Disassembler:\n"); 227 printf (" -d [file] Disassemble or decode binary ACPI table to file (*.dsl)\n"); 228 printf (" -da [f1,f2] Disassemble multiple tables from single namespace\n"); 229 printf (" -dc [file] Disassemble AML and immediately compile it\n"); 230 printf (" (Obtain DSDT from current system if no input file)\n"); 231 printf (" -e [f1,f2] Include ACPI table(s) for external symbol resolution\n"); 232 printf (" -2 Emit ACPI 2.0 compatible ASL code\n"); 233 printf (" -g Get ACPI tables and write to files (*.dat)\n"); 234 235 printf ("\nHelp:\n"); 236 printf (" -h Additional help and compiler debug options\n"); 237 printf (" -hc Display operators allowed in constant expressions\n"); 238 printf (" -hr Display ACPI reserved method names\n"); 239 printf (" -ht Display currently supported ACPI table names\n"); 240 } 241 242 243 /******************************************************************************* 244 * 245 * FUNCTION: HelpMessage 246 * 247 * PARAMETERS: None 248 * 249 * RETURN: None 250 * 251 * DESCRIPTION: Display help message 252 * 253 ******************************************************************************/ 254 255 static void 256 HelpMessage ( 257 void) 258 { 259 260 printf ("AML output filename generation:\n"); 261 printf (" Output filenames are generated by appending an extension to a common\n"); 262 printf (" filename prefix. The filename prefix is obtained via one of the\n"); 263 printf (" following methods (in priority order):\n"); 264 printf (" 1) The -p option specifies the prefix\n"); 265 printf (" 2) The prefix of the AMLFileName in the ASL Definition Block\n"); 266 printf (" 3) The prefix of the input filename\n"); 267 printf ("\n"); 268 269 Options (); 270 271 printf ("\nCompiler/Disassembler Debug Options:\n"); 272 printf (" -b<p|t|b> Create compiler debug/trace file (*.txt)\n"); 273 printf (" Types: Parse/Tree/Both\n"); 274 printf (" -f Ignore errors, force creation of AML output file(s)\n"); 275 printf (" -n Parse only, no output generation\n"); 276 printf (" -ot Display compile times\n"); 277 printf (" -x<level> Set debug level for trace output\n"); 278 printf (" -z Do not insert new compiler ID for DataTables\n"); 279 } 280 281 282 /******************************************************************************* 283 * 284 * FUNCTION: Usage 285 * 286 * PARAMETERS: None 287 * 288 * RETURN: None 289 * 290 * DESCRIPTION: Display usage and option message 291 * 292 ******************************************************************************/ 293 294 static void 295 Usage ( 296 void) 297 { 298 299 printf ("Usage: %s [Options] [Files]\n\n", CompilerName); 300 Options (); 301 } 302 303 304 /******************************************************************************* 305 * 306 * FUNCTION: AslInitialize 307 * 308 * PARAMETERS: None 309 * 310 * RETURN: None 311 * 312 * DESCRIPTION: Initialize compiler globals 313 * 314 ******************************************************************************/ 315 316 static void 317 AslInitialize ( 318 void) 319 { 320 UINT32 i; 321 322 323 #ifdef _DEBUG 324 _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0)); 325 #endif 326 327 AcpiDbgLevel = 0; 328 329 for (i = 0; i < ASL_NUM_FILES; i++) 330 { 331 Gbl_Files[i].Handle = NULL; 332 Gbl_Files[i].Filename = NULL; 333 } 334 335 Gbl_Files[ASL_FILE_STDOUT].Handle = stdout; 336 Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT"; 337 338 Gbl_Files[ASL_FILE_STDERR].Handle = stderr; 339 Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR"; 340 } 341 342 343 /******************************************************************************* 344 * 345 * FUNCTION: AslMergeOptionTokens 346 * 347 * PARAMETERS: InBuffer - Input containing an option string 348 * OutBuffer - Merged output buffer 349 * 350 * RETURN: None 351 * 352 * DESCRIPTION: Remove all whitespace from an option string. 353 * 354 ******************************************************************************/ 355 356 static void 357 AslMergeOptionTokens ( 358 char *InBuffer, 359 char *OutBuffer) 360 { 361 char *Token; 362 363 364 *OutBuffer = 0; 365 366 Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS); 367 while (Token) 368 { 369 strcat (OutBuffer, Token); 370 Token = strtok (NULL, ASL_TOKEN_SEPARATORS); 371 } 372 } 373 374 375 /******************************************************************************* 376 * 377 * FUNCTION: AslDoResponseFile 378 * 379 * PARAMETERS: Filename - Name of the response file 380 * 381 * RETURN: Status 382 * 383 * DESCRIPTION: Open a response file and process all options within. 384 * 385 ******************************************************************************/ 386 387 static int 388 AslDoResponseFile ( 389 char *Filename) 390 { 391 char *argv = StringBuffer2; 392 FILE *ResponseFile; 393 int OptStatus = 0; 394 int Opterr; 395 int Optind; 396 397 398 ResponseFile = fopen (Filename, "r"); 399 if (!ResponseFile) 400 { 401 printf ("Could not open command file %s, %s\n", 402 Filename, strerror (errno)); 403 return -1; 404 } 405 406 /* Must save the current GetOpt globals */ 407 408 Opterr = AcpiGbl_Opterr; 409 Optind = AcpiGbl_Optind; 410 411 /* 412 * Process all lines in the response file. There must be one complete 413 * option per line 414 */ 415 while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile)) 416 { 417 /* Compress all tokens, allowing us to use a single argv entry */ 418 419 AslMergeOptionTokens (StringBuffer, StringBuffer2); 420 421 /* Process the option */ 422 423 AcpiGbl_Opterr = 0; 424 AcpiGbl_Optind = 0; 425 426 OptStatus = AslDoOptions (1, &argv, TRUE); 427 if (OptStatus) 428 { 429 printf ("Invalid option in command file %s: %s\n", 430 Filename, StringBuffer); 431 break; 432 } 433 } 434 435 /* Restore the GetOpt globals */ 436 437 AcpiGbl_Opterr = Opterr; 438 AcpiGbl_Optind = Optind; 439 440 fclose (ResponseFile); 441 return (OptStatus); 442 } 443 444 445 /******************************************************************************* 446 * 447 * FUNCTION: AslDoOptions 448 * 449 * PARAMETERS: argc/argv - Standard argc/argv 450 * IsResponseFile - TRUE if executing a response file. 451 * 452 * RETURN: Status 453 * 454 * DESCRIPTION: Command line option processing 455 * 456 ******************************************************************************/ 457 458 static int 459 AslDoOptions ( 460 int argc, 461 char **argv, 462 BOOLEAN IsResponseFile) 463 { 464 int j; 465 466 467 /* Get the command line options */ 468 469 while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j) 470 { 471 case '@': /* Begin a response file */ 472 473 if (IsResponseFile) 474 { 475 printf ("Nested command files are not supported\n"); 476 return -1; 477 } 478 479 if (AslDoResponseFile (AcpiGbl_Optarg)) 480 { 481 return -1; 482 } 483 break; 484 485 486 case '2': 487 488 Gbl_Acpi2 = TRUE; 489 break; 490 491 492 case 'b': 493 494 switch (AcpiGbl_Optarg[0]) 495 { 496 case 'b': 497 AslCompilerdebug = 1; /* same as yydebug */ 498 break; 499 500 case 'p': 501 AslCompilerdebug = 1; /* same as yydebug */ 502 break; 503 504 case 't': 505 break; 506 507 default: 508 printf ("Unknown option: -b%s\n", AcpiGbl_Optarg); 509 return (-1); 510 } 511 512 /* Produce debug output file */ 513 514 Gbl_DebugFlag = TRUE; 515 break; 516 517 518 case 'c': 519 switch (AcpiGbl_Optarg[0]) 520 { 521 case 'r': 522 Gbl_NoResourceChecking = TRUE; 523 break; 524 525 default: 526 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg); 527 return (-1); 528 } 529 break; 530 531 532 case 'd': 533 switch (AcpiGbl_Optarg[0]) 534 { 535 case '^': 536 Gbl_DoCompile = FALSE; 537 break; 538 539 case 'a': 540 Gbl_DoCompile = FALSE; 541 Gbl_DisassembleAll = TRUE; 542 break; 543 544 case 'c': 545 break; 546 547 default: 548 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg); 549 return (-1); 550 } 551 552 Gbl_DisasmFlag = TRUE; 553 break; 554 555 556 case 'e': 557 AcpiDmAddToExternalFileList (AcpiGbl_Optarg); 558 break; 559 560 561 case 'f': 562 563 /* Ignore errors and force creation of aml file */ 564 565 Gbl_IgnoreErrors = TRUE; 566 break; 567 568 569 case 'g': 570 571 /* Get all ACPI tables */ 572 573 Gbl_GetAllTables = TRUE; 574 Gbl_DoCompile = FALSE; 575 break; 576 577 578 case 'h': 579 580 switch (AcpiGbl_Optarg[0]) 581 { 582 case '^': 583 HelpMessage (); 584 exit (0); 585 586 case 'c': 587 UtDisplayConstantOpcodes (); 588 exit (0); 589 590 case 'r': 591 /* reserved names */ 592 593 ApDisplayReservedNames (); 594 exit (0); 595 596 case 't': 597 UtDisplaySupportedTables (); 598 exit (0); 599 600 default: 601 printf ("Unknown option: -h%s\n", AcpiGbl_Optarg); 602 return (-1); 603 } 604 break; 605 606 607 case 'I': /* Add an include file search directory */ 608 609 FlAddIncludeDirectory (AcpiGbl_Optarg); 610 break; 611 612 613 case 'i': 614 615 switch (AcpiGbl_Optarg[0]) 616 { 617 case 'a': 618 619 /* Produce assembly code include file */ 620 621 Gbl_AsmIncludeOutputFlag = TRUE; 622 break; 623 624 case 'c': 625 626 /* Produce C include file */ 627 628 Gbl_C_IncludeOutputFlag = TRUE; 629 break; 630 631 default: 632 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg); 633 return (-1); 634 } 635 break; 636 637 638 case 'l': 639 640 switch (AcpiGbl_Optarg[0]) 641 { 642 case '^': 643 /* Produce listing file (Mixed source/aml) */ 644 645 Gbl_ListingFlag = TRUE; 646 break; 647 648 case 'n': 649 /* Produce namespace file */ 650 651 Gbl_NsOutputFlag = TRUE; 652 break; 653 654 case 's': 655 /* Produce combined source file */ 656 657 Gbl_SourceOutputFlag = TRUE; 658 break; 659 660 default: 661 printf ("Unknown option: -l%s\n", AcpiGbl_Optarg); 662 return (-1); 663 } 664 break; 665 666 667 case 'o': 668 669 switch (AcpiGbl_Optarg[0]) 670 { 671 case 'a': 672 673 /* Disable all optimizations */ 674 675 Gbl_FoldConstants = FALSE; 676 Gbl_IntegerOptimizationFlag = FALSE; 677 Gbl_ReferenceOptimizationFlag = FALSE; 678 break; 679 680 case 'f': 681 682 /* Disable folding on "normal" expressions */ 683 684 Gbl_FoldConstants = FALSE; 685 break; 686 687 case 'i': 688 689 /* Disable integer optimization to constants */ 690 691 Gbl_IntegerOptimizationFlag = FALSE; 692 break; 693 694 case 'n': 695 696 /* Disable named reference optimization */ 697 698 Gbl_ReferenceOptimizationFlag = FALSE; 699 break; 700 701 case 't': 702 703 /* Display compile time(s) */ 704 705 Gbl_CompileTimesFlag = TRUE; 706 break; 707 708 default: 709 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg); 710 return (-1); 711 } 712 break; 713 714 715 case 'n': 716 717 /* Parse only */ 718 719 Gbl_ParseOnlyFlag = TRUE; 720 break; 721 722 723 case 'p': 724 725 /* Override default AML output filename */ 726 727 Gbl_OutputFilenamePrefix = AcpiGbl_Optarg; 728 Gbl_UseDefaultAmlFilename = FALSE; 729 break; 730 731 732 case 'r': 733 Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0); 734 break; 735 736 737 case 's': 738 739 switch (AcpiGbl_Optarg[0]) 740 { 741 case 'a': 742 743 /* Produce assembly code output file */ 744 745 Gbl_AsmOutputFlag = TRUE; 746 break; 747 748 case 'c': 749 750 /* Produce C hex output file */ 751 752 Gbl_C_OutputFlag = TRUE; 753 break; 754 755 default: 756 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg); 757 return (-1); 758 } 759 break; 760 761 762 case 't': 763 764 /* Produce hex table output file */ 765 766 switch (AcpiGbl_Optarg[0]) 767 { 768 case 'a': 769 Gbl_HexOutputFlag = HEX_OUTPUT_ASM; 770 break; 771 772 case 'c': 773 Gbl_HexOutputFlag = HEX_OUTPUT_C; 774 break; 775 776 case 's': 777 Gbl_HexOutputFlag = HEX_OUTPUT_ASL; 778 break; 779 780 default: 781 printf ("Unknown option: -t%s\n", AcpiGbl_Optarg); 782 return (-1); 783 } 784 break; 785 786 787 case 'T': 788 Gbl_DoTemplates = TRUE; 789 Gbl_TemplateSignature = AcpiGbl_Optarg; 790 break; 791 792 793 case 'v': 794 795 switch (AcpiGbl_Optarg[0]) 796 { 797 case 'a': 798 /* Disable All error/warning messages */ 799 800 Gbl_NoErrors = TRUE; 801 break; 802 803 case 'i': 804 /* Less verbose error messages */ 805 806 Gbl_VerboseErrors = FALSE; 807 break; 808 809 case 'o': 810 Gbl_DisplayOptimizations = TRUE; 811 break; 812 813 case 'r': 814 Gbl_DisplayRemarks = FALSE; 815 break; 816 817 case 's': 818 Gbl_DoSignon = FALSE; 819 break; 820 821 case 't': 822 Gbl_VerboseTemplates = TRUE; 823 break; 824 825 default: 826 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg); 827 return (-1); 828 } 829 break; 830 831 832 case 'w': /* Set warning levels */ 833 834 switch (AcpiGbl_Optarg[0]) 835 { 836 case '1': 837 Gbl_WarningLevel = ASL_WARNING; 838 break; 839 840 case '2': 841 Gbl_WarningLevel = ASL_WARNING2; 842 break; 843 844 case '3': 845 Gbl_WarningLevel = ASL_WARNING3; 846 break; 847 848 default: 849 printf ("Unknown option: -w%s\n", AcpiGbl_Optarg); 850 return (-1); 851 } 852 break; 853 854 855 case 'x': 856 857 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16); 858 break; 859 860 861 case 'z': 862 863 Gbl_UseOriginalCompilerId = TRUE; 864 break; 865 866 867 default: 868 869 return (-1); 870 } 871 872 return (0); 873 } 874 875 876 /******************************************************************************* 877 * 878 * FUNCTION: AslCommandLine 879 * 880 * PARAMETERS: argc/argv 881 * 882 * RETURN: Last argv index 883 * 884 * DESCRIPTION: Command line processing 885 * 886 ******************************************************************************/ 887 888 static int 889 AslCommandLine ( 890 int argc, 891 char **argv) 892 { 893 int BadCommandLine = 0; 894 895 896 /* Minimum command line contains at least the command and an input file */ 897 898 if (argc < 2) 899 { 900 AslCompilerSignon (ASL_FILE_STDOUT); 901 Usage (); 902 exit (1); 903 } 904 905 /* Process all command line options */ 906 907 BadCommandLine = AslDoOptions (argc, argv, FALSE); 908 909 if (Gbl_DoTemplates) 910 { 911 DtCreateTemplates (Gbl_TemplateSignature); 912 exit (1); 913 } 914 915 /* Next parameter must be the input filename */ 916 917 if (!argv[AcpiGbl_Optind] && 918 !Gbl_DisasmFlag && 919 !Gbl_GetAllTables) 920 { 921 printf ("Missing input filename\n"); 922 BadCommandLine = TRUE; 923 } 924 925 if (Gbl_DoSignon) 926 { 927 AslCompilerSignon (ASL_FILE_STDOUT); 928 } 929 930 /* Abort if anything went wrong on the command line */ 931 932 if (BadCommandLine) 933 { 934 printf ("\n"); 935 Usage (); 936 exit (1); 937 } 938 939 return (AcpiGbl_Optind); 940 } 941 942 943 /******************************************************************************* 944 * 945 * FUNCTION: main 946 * 947 * PARAMETERS: Standard argc/argv 948 * 949 * RETURN: Program termination code 950 * 951 * DESCRIPTION: C main routine for the Asl Compiler. Handle command line 952 * options and begin the compile for each file on the command line 953 * 954 ******************************************************************************/ 955 956 int ACPI_SYSTEM_XFACE 957 main ( 958 int argc, 959 char **argv) 960 { 961 ACPI_STATUS Status; 962 int Index1; 963 int Index2; 964 965 966 AcpiGbl_ExternalFileList = NULL; 967 968 #ifdef _DEBUG 969 _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF | 970 _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG)); 971 #endif 972 973 /* Init and command line */ 974 975 AslInitialize (); 976 Index1 = Index2 = AslCommandLine (argc, argv); 977 978 /* Options that have no additional parameters or pathnames */ 979 980 if (Gbl_GetAllTables) 981 { 982 Status = AslDoOneFile (NULL); 983 if (ACPI_FAILURE (Status)) 984 { 985 return (-1); 986 } 987 return (0); 988 } 989 990 if (Gbl_DisassembleAll) 991 { 992 while (argv[Index1]) 993 { 994 Status = AslDoOnePathname (argv[Index1], AcpiDmAddToExternalFileList); 995 if (ACPI_FAILURE (Status)) 996 { 997 return (-1); 998 } 999 1000 Index1++; 1001 } 1002 } 1003 1004 /* Process each pathname/filename in the list, with possible wildcards */ 1005 1006 while (argv[Index2]) 1007 { 1008 Status = AslDoOnePathname (argv[Index2], AslDoOneFile); 1009 if (ACPI_FAILURE (Status)) 1010 { 1011 return (-1); 1012 } 1013 1014 Index2++; 1015 } 1016 1017 if (AcpiGbl_ExternalFileList) 1018 { 1019 AcpiDmClearExternalFileList(); 1020 } 1021 1022 return (0); 1023 } 1024 1025 1026