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