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