aslmain.c revision 207344
1118611Snjl 2118611Snjl/****************************************************************************** 3118611Snjl * 4118611Snjl * Module Name: aslmain - compiler main and utilities 5118611Snjl * 6118611Snjl *****************************************************************************/ 7118611Snjl 8118611Snjl/****************************************************************************** 9118611Snjl * 10118611Snjl * 1. Copyright Notice 11118611Snjl * 12202771Sjkim * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp. 13118611Snjl * All rights reserved. 14118611Snjl * 15118611Snjl * 2. License 16118611Snjl * 17118611Snjl * 2.1. This is your license from Intel Corp. under its intellectual property 18118611Snjl * rights. You may have additional license terms from the party that provided 19118611Snjl * you this software, covering your right to use that party's intellectual 20118611Snjl * property rights. 21118611Snjl * 22118611Snjl * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23118611Snjl * copy of the source code appearing in this file ("Covered Code") an 24118611Snjl * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25118611Snjl * base code distributed originally by Intel ("Original Intel Code") to copy, 26118611Snjl * make derivatives, distribute, use and display any portion of the Covered 27118611Snjl * Code in any form, with the right to sublicense such rights; and 28118611Snjl * 29118611Snjl * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30118611Snjl * license (with the right to sublicense), under only those claims of Intel 31118611Snjl * patents that are infringed by the Original Intel Code, to make, use, sell, 32118611Snjl * offer to sell, and import the Covered Code and derivative works thereof 33118611Snjl * solely to the minimum extent necessary to exercise the above copyright 34118611Snjl * license, and in no event shall the patent license extend to any additions 35118611Snjl * to or modifications of the Original Intel Code. No other license or right 36118611Snjl * is granted directly or by implication, estoppel or otherwise; 37118611Snjl * 38118611Snjl * The above copyright and patent license is granted only if the following 39118611Snjl * conditions are met: 40118611Snjl * 41118611Snjl * 3. Conditions 42118611Snjl * 43118611Snjl * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44118611Snjl * Redistribution of source code of any substantial portion of the Covered 45118611Snjl * Code or modification with rights to further distribute source must include 46118611Snjl * the above Copyright Notice, the above License, this list of Conditions, 47118611Snjl * and the following Disclaimer and Export Compliance provision. In addition, 48118611Snjl * Licensee must cause all Covered Code to which Licensee contributes to 49118611Snjl * contain a file documenting the changes Licensee made to create that Covered 50118611Snjl * Code and the date of any change. Licensee must include in that file the 51118611Snjl * documentation of any changes made by any predecessor Licensee. Licensee 52118611Snjl * must include a prominent statement that the modification is derived, 53118611Snjl * directly or indirectly, from Original Intel Code. 54118611Snjl * 55118611Snjl * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56118611Snjl * Redistribution of source code of any substantial portion of the Covered 57118611Snjl * Code or modification without rights to further distribute source must 58118611Snjl * include the following Disclaimer and Export Compliance provision in the 59118611Snjl * documentation and/or other materials provided with distribution. In 60118611Snjl * addition, Licensee may not authorize further sublicense of source of any 61118611Snjl * portion of the Covered Code, and must include terms to the effect that the 62118611Snjl * license from Licensee to its licensee is limited to the intellectual 63118611Snjl * property embodied in the software Licensee provides to its licensee, and 64118611Snjl * not to intellectual property embodied in modifications its licensee may 65118611Snjl * make. 66118611Snjl * 67118611Snjl * 3.3. Redistribution of Executable. Redistribution in executable form of any 68118611Snjl * substantial portion of the Covered Code or modification must reproduce the 69118611Snjl * above Copyright Notice, and the following Disclaimer and Export Compliance 70118611Snjl * provision in the documentation and/or other materials provided with the 71118611Snjl * distribution. 72118611Snjl * 73118611Snjl * 3.4. Intel retains all right, title, and interest in and to the Original 74118611Snjl * Intel Code. 75118611Snjl * 76118611Snjl * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77118611Snjl * Intel shall be used in advertising or otherwise to promote the sale, use or 78118611Snjl * other dealings in products derived from or relating to the Covered Code 79118611Snjl * without prior written authorization from Intel. 80118611Snjl * 81118611Snjl * 4. Disclaimer and Export Compliance 82118611Snjl * 83118611Snjl * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84118611Snjl * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85118611Snjl * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86118611Snjl * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87118611Snjl * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88118611Snjl * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89118611Snjl * PARTICULAR PURPOSE. 90118611Snjl * 91118611Snjl * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92118611Snjl * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93118611Snjl * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94118611Snjl * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95118611Snjl * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96118611Snjl * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97118611Snjl * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98118611Snjl * LIMITED REMEDY. 99118611Snjl * 100118611Snjl * 4.3. Licensee shall not export, either directly or indirectly, any of this 101118611Snjl * software or system incorporating such software without first obtaining any 102118611Snjl * required license or other approval from the U. S. Department of Commerce or 103118611Snjl * any other agency or department of the United States Government. In the 104118611Snjl * event Licensee exports any such software from the United States or 105118611Snjl * re-exports any such software from a foreign destination, Licensee shall 106118611Snjl * ensure that the distribution and export/re-export of the software is in 107118611Snjl * compliance with all laws, regulations, orders, or other restrictions of the 108118611Snjl * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109118611Snjl * any of its subsidiaries will export/re-export any technical data, process, 110118611Snjl * software, or service, directly or indirectly, to any country for which the 111118611Snjl * United States government or any agency thereof requires an export license, 112118611Snjl * other governmental approval, or letter of assurance, without first obtaining 113118611Snjl * such license, approval or letter. 114118611Snjl * 115118611Snjl *****************************************************************************/ 116118611Snjl 117118611Snjl 118118611Snjl#define _DECLARE_GLOBALS 119118611Snjl 120151937Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h> 121193529Sjkim#include <contrib/dev/acpica/include/acapps.h> 122118611Snjl 123118611Snjl#ifdef _DEBUG 124118611Snjl#include <crtdbg.h> 125118611Snjl#endif 126118611Snjl 127118611Snjl#define _COMPONENT ACPI_COMPILER 128118611Snjl ACPI_MODULE_NAME ("aslmain") 129118611Snjl 130151937Sjkim/* Local prototypes */ 131118611Snjl 132151937Sjkimstatic void 133151937SjkimOptions ( 134151937Sjkim void); 135151937Sjkim 136151937Sjkimstatic void 137151937SjkimHelpMessage ( 138151937Sjkim void); 139151937Sjkim 140151937Sjkimstatic void 141151937SjkimUsage ( 142151937Sjkim void); 143151937Sjkim 144151937Sjkimstatic void 145151937SjkimAslInitialize ( 146151937Sjkim void); 147151937Sjkim 148193529Sjkimstatic int 149151937SjkimAslCommandLine ( 150151937Sjkim int argc, 151151937Sjkim char **argv); 152151937Sjkim 153197104Sjkimstatic int 154197104SjkimAslDoOptions ( 155197104Sjkim int argc, 156197104Sjkim char **argv, 157197104Sjkim BOOLEAN IsResponseFile); 158151937Sjkim 159197104Sjkimstatic void 160197104SjkimAslMergeOptionTokens ( 161197104Sjkim char *InBuffer, 162197104Sjkim char *OutBuffer); 163197104Sjkim 164197104Sjkimstatic int 165197104SjkimAslDoResponseFile ( 166197104Sjkim char *Filename); 167197104Sjkim 168197104Sjkim 169197104Sjkim#define ASL_TOKEN_SEPARATORS " \t\n" 170207344Sjkim#define ASL_SUPPORTED_OPTIONS "@:2b:c:d^e:fgh^i^I:l^no:p:r:s:t:v:w:x:" 171197104Sjkim 172197104Sjkim 173118611Snjl/******************************************************************************* 174118611Snjl * 175118611Snjl * FUNCTION: Options 176118611Snjl * 177118611Snjl * PARAMETERS: None 178118611Snjl * 179118611Snjl * RETURN: None 180118611Snjl * 181118611Snjl * DESCRIPTION: Display option help message 182118611Snjl * 183118611Snjl ******************************************************************************/ 184118611Snjl 185151937Sjkimstatic void 186118611SnjlOptions ( 187118611Snjl void) 188118611Snjl{ 189118611Snjl 190197104Sjkim printf ("Global:\n"); 191197104Sjkim printf (" -@<file> Specify command file\n"); 192197104Sjkim printf (" -I<dir> Specify additional include directory\n"); 193197104Sjkim 194197104Sjkim printf ("\nGeneral Output:\n"); 195197104Sjkim printf (" -p<prefix> Specify path/filename prefix for all output files\n"); 196193529Sjkim printf (" -va Disable all errors and warnings (summary only)\n"); 197118611Snjl printf (" -vi Less verbose errors and warnings for use with IDEs\n"); 198118611Snjl printf (" -vo Enable optimization comments\n"); 199118611Snjl printf (" -vr Disable remarks\n"); 200118611Snjl printf (" -vs Disable signon\n"); 201167802Sjkim printf (" -w<1|2|3> Set warning reporting level\n"); 202118611Snjl 203138287Smarks printf ("\nAML Output Files:\n"); 204118611Snjl printf (" -s<a|c> Create AML in assembler or C source file (*.asm or *.c)\n"); 205118611Snjl printf (" -i<a|c> Create assembler or C include file (*.inc or *.h)\n"); 206207344Sjkim printf (" -t<a|c|s> Create AML in assembler, C, or ASL hex table (*.hex)\n"); 207118611Snjl 208138287Smarks printf ("\nAML Code Generation:\n"); 209118611Snjl printf (" -oa Disable all optimizations (compatibility mode)\n"); 210118611Snjl printf (" -of Disable constant folding\n"); 211118611Snjl printf (" -oi Disable integer optimization to Zero/One/Ones\n"); 212118611Snjl printf (" -on Disable named reference string optimization\n"); 213207344Sjkim printf (" -cr Disable Resource Descriptor error checking\n"); 214138287Smarks printf (" -r<Revision> Override table header Revision (1-255)\n"); 215118611Snjl 216118611Snjl printf ("\nListings:\n"); 217118611Snjl printf (" -l Create mixed listing file (ASL source and AML) (*.lst)\n"); 218118611Snjl printf (" -ln Create namespace file (*.nsp)\n"); 219118611Snjl printf (" -ls Create combined source file (expanded includes) (*.src)\n"); 220118611Snjl 221118611Snjl printf ("\nAML Disassembler:\n"); 222167802Sjkim printf (" -d [file] Disassemble or decode binary ACPI table to file (*.dsl)\n"); 223118611Snjl printf (" -dc [file] Disassemble AML and immediately compile it\n"); 224118611Snjl printf (" (Obtain DSDT from current system if no input file)\n"); 225193529Sjkim printf (" -e [f1,f2] Include ACPI table(s) for external symbol resolution\n"); 226151937Sjkim printf (" -2 Emit ACPI 2.0 compatible ASL code\n"); 227118611Snjl printf (" -g Get ACPI tables and write to files (*.dat)\n"); 228118611Snjl 229118611Snjl printf ("\nHelp:\n"); 230118611Snjl printf (" -h Additional help and compiler debug options\n"); 231118611Snjl printf (" -hc Display operators allowed in constant expressions\n"); 232118611Snjl printf (" -hr Display ACPI reserved method names\n"); 233118611Snjl} 234118611Snjl 235118611Snjl 236118611Snjl/******************************************************************************* 237118611Snjl * 238151937Sjkim * FUNCTION: HelpMessage 239118611Snjl * 240118611Snjl * PARAMETERS: None 241118611Snjl * 242118611Snjl * RETURN: None 243118611Snjl * 244118611Snjl * DESCRIPTION: Display help message 245118611Snjl * 246118611Snjl ******************************************************************************/ 247118611Snjl 248151937Sjkimstatic void 249118611SnjlHelpMessage ( 250118611Snjl void) 251118611Snjl{ 252118611Snjl 253118611Snjl printf ("AML output filename generation:\n"); 254118611Snjl printf (" Output filenames are generated by appending an extension to a common\n"); 255118611Snjl printf (" filename prefix. The filename prefix is obtained via one of the\n"); 256118611Snjl printf (" following methods (in priority order):\n"); 257118611Snjl printf (" 1) The -p option specifies the prefix\n"); 258118611Snjl printf (" 2) The prefix of the AMLFileName in the ASL Definition Block\n"); 259118611Snjl printf (" 3) The prefix of the input filename\n"); 260118611Snjl printf ("\n"); 261118611Snjl 262118611Snjl Options (); 263118611Snjl 264167802Sjkim printf ("\nCompiler/Disassembler Debug Options:\n"); 265118611Snjl printf (" -b<p|t|b> Create compiler debug/trace file (*.txt)\n"); 266118611Snjl printf (" Types: Parse/Tree/Both\n"); 267118611Snjl printf (" -f Ignore errors, force creation of AML output file(s)\n"); 268207344Sjkim printf (" -n Parse only, no output generation\n"); 269118611Snjl printf (" -ot Display compile times\n"); 270118611Snjl printf (" -x<level> Set debug level for trace output\n"); 271118611Snjl} 272118611Snjl 273118611Snjl 274118611Snjl/******************************************************************************* 275118611Snjl * 276118611Snjl * FUNCTION: Usage 277118611Snjl * 278118611Snjl * PARAMETERS: None 279118611Snjl * 280118611Snjl * RETURN: None 281118611Snjl * 282118611Snjl * DESCRIPTION: Display usage and option message 283118611Snjl * 284118611Snjl ******************************************************************************/ 285118611Snjl 286151937Sjkimstatic void 287118611SnjlUsage ( 288118611Snjl void) 289118611Snjl{ 290118611Snjl 291193529Sjkim printf ("Usage: %s [Options] [Files]\n\n", CompilerName); 292118611Snjl Options (); 293118611Snjl} 294118611Snjl 295118611Snjl 296118611Snjl/******************************************************************************* 297118611Snjl * 298118611Snjl * FUNCTION: AslInitialize 299118611Snjl * 300118611Snjl * PARAMETERS: None 301118611Snjl * 302118611Snjl * RETURN: None 303118611Snjl * 304118611Snjl * DESCRIPTION: Initialize compiler globals 305118611Snjl * 306118611Snjl ******************************************************************************/ 307118611Snjl 308151937Sjkimstatic void 309151937SjkimAslInitialize ( 310151937Sjkim void) 311118611Snjl{ 312118611Snjl UINT32 i; 313118611Snjl 314118611Snjl 315118611Snjl#ifdef _DEBUG 316118611Snjl _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0)); 317118611Snjl#endif 318118611Snjl 319118611Snjl AcpiDbgLevel = 0; 320118611Snjl 321118611Snjl for (i = 0; i < ASL_NUM_FILES; i++) 322118611Snjl { 323118611Snjl Gbl_Files[i].Handle = NULL; 324118611Snjl Gbl_Files[i].Filename = NULL; 325118611Snjl } 326118611Snjl 327118611Snjl Gbl_Files[ASL_FILE_STDOUT].Handle = stdout; 328118611Snjl Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT"; 329118611Snjl 330118611Snjl Gbl_Files[ASL_FILE_STDERR].Handle = stderr; 331118611Snjl Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR"; 332118611Snjl} 333118611Snjl 334118611Snjl 335118611Snjl/******************************************************************************* 336118611Snjl * 337197104Sjkim * FUNCTION: AslMergeOptionTokens 338118611Snjl * 339197104Sjkim * PARAMETERS: InBuffer - Input containing an option string 340197104Sjkim * OutBuffer - Merged output buffer 341118611Snjl * 342118611Snjl * RETURN: None 343118611Snjl * 344197104Sjkim * DESCRIPTION: Remove all whitespace from an option string. 345118611Snjl * 346118611Snjl ******************************************************************************/ 347118611Snjl 348197104Sjkimstatic void 349197104SjkimAslMergeOptionTokens ( 350197104Sjkim char *InBuffer, 351197104Sjkim char *OutBuffer) 352197104Sjkim{ 353197104Sjkim char *Token; 354197104Sjkim 355197104Sjkim 356197104Sjkim *OutBuffer = 0; 357197104Sjkim 358197104Sjkim Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS); 359197104Sjkim while (Token) 360197104Sjkim { 361197104Sjkim strcat (OutBuffer, Token); 362197104Sjkim Token = strtok (NULL, ASL_TOKEN_SEPARATORS); 363197104Sjkim } 364197104Sjkim} 365197104Sjkim 366197104Sjkim 367197104Sjkim/******************************************************************************* 368197104Sjkim * 369197104Sjkim * FUNCTION: AslDoResponseFile 370197104Sjkim * 371197104Sjkim * PARAMETERS: Filename - Name of the response file 372197104Sjkim * 373197104Sjkim * RETURN: Status 374197104Sjkim * 375197104Sjkim * DESCRIPTION: Open a response file and process all options within. 376197104Sjkim * 377197104Sjkim ******************************************************************************/ 378197104Sjkim 379193529Sjkimstatic int 380197104SjkimAslDoResponseFile ( 381197104Sjkim char *Filename) 382118611Snjl{ 383197104Sjkim char *argv = StringBuffer2; 384197104Sjkim FILE *ResponseFile; 385197104Sjkim int OptStatus = 0; 386197104Sjkim int Opterr; 387197104Sjkim int Optind; 388118611Snjl 389118611Snjl 390197104Sjkim ResponseFile = fopen (Filename, "r"); 391197104Sjkim if (!ResponseFile) 392197104Sjkim { 393197104Sjkim printf ("Could not open command file %s, %s\n", 394197104Sjkim Filename, strerror (errno)); 395197104Sjkim return -1; 396197104Sjkim } 397118611Snjl 398197104Sjkim /* Must save the current GetOpt globals */ 399197104Sjkim 400197104Sjkim Opterr = AcpiGbl_Opterr; 401197104Sjkim Optind = AcpiGbl_Optind; 402197104Sjkim 403197104Sjkim /* 404197104Sjkim * Process all lines in the response file. There must be one complete 405197104Sjkim * option per line 406197104Sjkim */ 407197104Sjkim while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile)) 408118611Snjl { 409197104Sjkim /* Compress all tokens, allowing us to use a single argv entry */ 410197104Sjkim 411197104Sjkim AslMergeOptionTokens (StringBuffer, StringBuffer2); 412197104Sjkim 413197104Sjkim /* Process the option */ 414197104Sjkim 415197104Sjkim AcpiGbl_Opterr = 0; 416197104Sjkim AcpiGbl_Optind = 0; 417197104Sjkim 418197104Sjkim OptStatus = AslDoOptions (1, &argv, TRUE); 419197104Sjkim if (OptStatus) 420197104Sjkim { 421197104Sjkim printf ("Invalid option in command file %s: %s\n", 422197104Sjkim Filename, StringBuffer); 423197104Sjkim break; 424197104Sjkim } 425118611Snjl } 426118611Snjl 427197104Sjkim /* Restore the GetOpt globals */ 428197104Sjkim 429197104Sjkim AcpiGbl_Opterr = Opterr; 430197104Sjkim AcpiGbl_Optind = Optind; 431197104Sjkim 432197104Sjkim fclose (ResponseFile); 433197104Sjkim return (OptStatus); 434197104Sjkim} 435197104Sjkim 436197104Sjkim 437197104Sjkim/******************************************************************************* 438197104Sjkim * 439197104Sjkim * FUNCTION: AslDoOptions 440197104Sjkim * 441197104Sjkim * PARAMETERS: argc/argv - Standard argc/argv 442197104Sjkim * IsResponseFile - TRUE if executing a response file. 443197104Sjkim * 444197104Sjkim * RETURN: Status 445197104Sjkim * 446197104Sjkim * DESCRIPTION: Command line option processing 447197104Sjkim * 448197104Sjkim ******************************************************************************/ 449197104Sjkim 450197104Sjkimstatic int 451197104SjkimAslDoOptions ( 452197104Sjkim int argc, 453197104Sjkim char **argv, 454197104Sjkim BOOLEAN IsResponseFile) 455197104Sjkim{ 456197104Sjkim int j; 457197104Sjkim 458197104Sjkim 459118611Snjl /* Get the command line options */ 460118611Snjl 461197104Sjkim while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j) 462118611Snjl { 463197104Sjkim case '@': /* Begin a response file */ 464197104Sjkim 465197104Sjkim if (IsResponseFile) 466197104Sjkim { 467197104Sjkim printf ("Nested command files are not supported\n"); 468197104Sjkim return -1; 469197104Sjkim } 470197104Sjkim 471197104Sjkim if (AslDoResponseFile (AcpiGbl_Optarg)) 472197104Sjkim { 473197104Sjkim return -1; 474197104Sjkim } 475197104Sjkim break; 476197104Sjkim 477197104Sjkim 478151937Sjkim case '2': 479197104Sjkim 480151937Sjkim Gbl_Acpi2 = TRUE; 481151937Sjkim break; 482151937Sjkim 483151937Sjkim 484118611Snjl case 'b': 485118611Snjl 486118611Snjl switch (AcpiGbl_Optarg[0]) 487118611Snjl { 488118611Snjl case 'b': 489118611Snjl AslCompilerdebug = 1; /* same as yydebug */ 490118611Snjl break; 491118611Snjl 492118611Snjl case 'p': 493118611Snjl AslCompilerdebug = 1; /* same as yydebug */ 494118611Snjl break; 495118611Snjl 496118611Snjl case 't': 497118611Snjl break; 498118611Snjl 499118611Snjl default: 500118611Snjl printf ("Unknown option: -b%s\n", AcpiGbl_Optarg); 501197104Sjkim return (-1); 502118611Snjl } 503118611Snjl 504118611Snjl /* Produce debug output file */ 505118611Snjl 506118611Snjl Gbl_DebugFlag = TRUE; 507118611Snjl break; 508118611Snjl 509118611Snjl 510118611Snjl case 'c': 511207344Sjkim switch (AcpiGbl_Optarg[0]) 512207344Sjkim { 513207344Sjkim case 'r': 514207344Sjkim Gbl_NoResourceChecking = TRUE; 515207344Sjkim break; 516118611Snjl 517207344Sjkim default: 518207344Sjkim printf ("Unknown option: -c%s\n", AcpiGbl_Optarg); 519207344Sjkim return (-1); 520207344Sjkim } 521118611Snjl break; 522118611Snjl 523118611Snjl 524118611Snjl case 'd': 525118611Snjl switch (AcpiGbl_Optarg[0]) 526118611Snjl { 527118611Snjl case '^': 528193529Sjkim Gbl_DoCompile = FALSE; 529118611Snjl break; 530118611Snjl 531118611Snjl case 'c': 532118611Snjl break; 533118611Snjl 534118611Snjl default: 535118611Snjl printf ("Unknown option: -d%s\n", AcpiGbl_Optarg); 536197104Sjkim return (-1); 537118611Snjl } 538118611Snjl 539118611Snjl Gbl_DisasmFlag = TRUE; 540118611Snjl break; 541118611Snjl 542118611Snjl 543118611Snjl case 'e': 544167802Sjkim Gbl_ExternalFilename = AcpiGbl_Optarg; 545118611Snjl break; 546118611Snjl 547118611Snjl 548118611Snjl case 'f': 549118611Snjl 550118611Snjl /* Ignore errors and force creation of aml file */ 551118611Snjl 552118611Snjl Gbl_IgnoreErrors = TRUE; 553118611Snjl break; 554118611Snjl 555118611Snjl 556118611Snjl case 'g': 557118611Snjl 558118611Snjl /* Get all ACPI tables */ 559118611Snjl 560118611Snjl Gbl_GetAllTables = TRUE; 561193529Sjkim Gbl_DoCompile = FALSE; 562118611Snjl break; 563118611Snjl 564118611Snjl 565118611Snjl case 'h': 566118611Snjl 567118611Snjl switch (AcpiGbl_Optarg[0]) 568118611Snjl { 569118611Snjl case '^': 570118611Snjl HelpMessage (); 571118611Snjl exit (0); 572118611Snjl 573118611Snjl case 'c': 574118611Snjl UtDisplayConstantOpcodes (); 575118611Snjl exit (0); 576118611Snjl 577118611Snjl case 'r': 578118611Snjl /* reserved names */ 579118611Snjl 580204773Sjkim ApDisplayReservedNames (); 581118611Snjl exit (0); 582118611Snjl 583118611Snjl default: 584118611Snjl printf ("Unknown option: -h%s\n", AcpiGbl_Optarg); 585197104Sjkim return (-1); 586118611Snjl } 587118611Snjl break; 588118611Snjl 589118611Snjl 590197104Sjkim case 'I': /* Add an include file search directory */ 591197104Sjkim 592197104Sjkim FlAddIncludeDirectory (AcpiGbl_Optarg); 593197104Sjkim break; 594197104Sjkim 595197104Sjkim 596118611Snjl case 'i': 597118611Snjl 598118611Snjl switch (AcpiGbl_Optarg[0]) 599118611Snjl { 600118611Snjl case 'a': 601118611Snjl 602118611Snjl /* Produce assembly code include file */ 603118611Snjl 604118611Snjl Gbl_AsmIncludeOutputFlag = TRUE; 605118611Snjl break; 606118611Snjl 607118611Snjl case 'c': 608118611Snjl 609118611Snjl /* Produce C include file */ 610118611Snjl 611118611Snjl Gbl_C_IncludeOutputFlag = TRUE; 612118611Snjl break; 613118611Snjl 614118611Snjl default: 615118611Snjl printf ("Unknown option: -s%s\n", AcpiGbl_Optarg); 616197104Sjkim return (-1); 617118611Snjl } 618118611Snjl break; 619118611Snjl 620118611Snjl 621118611Snjl case 'l': 622118611Snjl 623118611Snjl switch (AcpiGbl_Optarg[0]) 624118611Snjl { 625118611Snjl case '^': 626118611Snjl /* Produce listing file (Mixed source/aml) */ 627118611Snjl 628118611Snjl Gbl_ListingFlag = TRUE; 629118611Snjl break; 630118611Snjl 631118611Snjl case 'n': 632118611Snjl /* Produce namespace file */ 633118611Snjl 634118611Snjl Gbl_NsOutputFlag = TRUE; 635118611Snjl break; 636118611Snjl 637118611Snjl case 's': 638118611Snjl /* Produce combined source file */ 639118611Snjl 640118611Snjl Gbl_SourceOutputFlag = TRUE; 641118611Snjl break; 642118611Snjl 643118611Snjl default: 644118611Snjl printf ("Unknown option: -l%s\n", AcpiGbl_Optarg); 645197104Sjkim return (-1); 646118611Snjl } 647118611Snjl break; 648118611Snjl 649118611Snjl 650118611Snjl case 'o': 651118611Snjl 652118611Snjl switch (AcpiGbl_Optarg[0]) 653118611Snjl { 654118611Snjl case 'a': 655118611Snjl 656118611Snjl /* Disable all optimizations */ 657118611Snjl 658118611Snjl Gbl_FoldConstants = FALSE; 659118611Snjl Gbl_IntegerOptimizationFlag = FALSE; 660118611Snjl Gbl_ReferenceOptimizationFlag = FALSE; 661118611Snjl break; 662118611Snjl 663118611Snjl case 'f': 664118611Snjl 665118611Snjl /* Disable folding on "normal" expressions */ 666118611Snjl 667118611Snjl Gbl_FoldConstants = FALSE; 668118611Snjl break; 669118611Snjl 670118611Snjl case 'i': 671118611Snjl 672118611Snjl /* Disable integer optimization to constants */ 673118611Snjl 674118611Snjl Gbl_IntegerOptimizationFlag = FALSE; 675118611Snjl break; 676118611Snjl 677118611Snjl case 'n': 678118611Snjl 679118611Snjl /* Disable named reference optimization */ 680118611Snjl 681118611Snjl Gbl_ReferenceOptimizationFlag = FALSE; 682118611Snjl break; 683118611Snjl 684118611Snjl case 't': 685118611Snjl 686118611Snjl /* Display compile time(s) */ 687118611Snjl 688118611Snjl Gbl_CompileTimesFlag = TRUE; 689118611Snjl break; 690118611Snjl 691118611Snjl default: 692118611Snjl printf ("Unknown option: -c%s\n", AcpiGbl_Optarg); 693197104Sjkim return (-1); 694118611Snjl } 695118611Snjl break; 696118611Snjl 697118611Snjl 698207344Sjkim case 'n': 699207344Sjkim 700207344Sjkim /* Parse only */ 701207344Sjkim 702207344Sjkim Gbl_ParseOnlyFlag = TRUE; 703207344Sjkim break; 704207344Sjkim 705207344Sjkim 706118611Snjl case 'p': 707118611Snjl 708118611Snjl /* Override default AML output filename */ 709118611Snjl 710118611Snjl Gbl_OutputFilenamePrefix = AcpiGbl_Optarg; 711118611Snjl Gbl_UseDefaultAmlFilename = FALSE; 712118611Snjl break; 713118611Snjl 714118611Snjl 715118611Snjl case 'r': 716138287Smarks Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0); 717118611Snjl break; 718118611Snjl 719118611Snjl 720118611Snjl case 's': 721118611Snjl 722118611Snjl switch (AcpiGbl_Optarg[0]) 723118611Snjl { 724118611Snjl case 'a': 725118611Snjl 726118611Snjl /* Produce assembly code output file */ 727118611Snjl 728118611Snjl Gbl_AsmOutputFlag = TRUE; 729118611Snjl break; 730118611Snjl 731118611Snjl case 'c': 732118611Snjl 733118611Snjl /* Produce C hex output file */ 734118611Snjl 735118611Snjl Gbl_C_OutputFlag = TRUE; 736118611Snjl break; 737118611Snjl 738118611Snjl default: 739118611Snjl printf ("Unknown option: -s%s\n", AcpiGbl_Optarg); 740197104Sjkim return (-1); 741118611Snjl } 742118611Snjl break; 743118611Snjl 744118611Snjl 745118611Snjl case 't': 746118611Snjl 747118611Snjl /* Produce hex table output file */ 748118611Snjl 749118611Snjl switch (AcpiGbl_Optarg[0]) 750118611Snjl { 751118611Snjl case 'a': 752118611Snjl Gbl_HexOutputFlag = HEX_OUTPUT_ASM; 753118611Snjl break; 754118611Snjl 755118611Snjl case 'c': 756118611Snjl Gbl_HexOutputFlag = HEX_OUTPUT_C; 757118611Snjl break; 758118611Snjl 759207344Sjkim case 's': 760207344Sjkim Gbl_HexOutputFlag = HEX_OUTPUT_ASL; 761207344Sjkim break; 762207344Sjkim 763118611Snjl default: 764118611Snjl printf ("Unknown option: -t%s\n", AcpiGbl_Optarg); 765197104Sjkim return (-1); 766118611Snjl } 767118611Snjl break; 768118611Snjl 769118611Snjl 770118611Snjl case 'v': 771118611Snjl 772118611Snjl switch (AcpiGbl_Optarg[0]) 773118611Snjl { 774193529Sjkim case 'a': 775193529Sjkim /* Disable All error/warning messages */ 776193529Sjkim 777193529Sjkim Gbl_NoErrors = TRUE; 778193529Sjkim break; 779193529Sjkim 780118611Snjl case 'i': 781118611Snjl /* Less verbose error messages */ 782118611Snjl 783118611Snjl Gbl_VerboseErrors = FALSE; 784118611Snjl break; 785118611Snjl 786118611Snjl case 'o': 787118611Snjl Gbl_DisplayOptimizations = TRUE; 788118611Snjl break; 789118611Snjl 790118611Snjl case 'r': 791118611Snjl Gbl_DisplayRemarks = FALSE; 792118611Snjl break; 793118611Snjl 794118611Snjl case 's': 795193529Sjkim Gbl_DoSignon = FALSE; 796118611Snjl break; 797118611Snjl 798118611Snjl default: 799118611Snjl printf ("Unknown option: -v%s\n", AcpiGbl_Optarg); 800197104Sjkim return (-1); 801118611Snjl } 802118611Snjl break; 803118611Snjl 804118611Snjl 805167802Sjkim case 'w': /* Set warning levels */ 806167802Sjkim 807167802Sjkim switch (AcpiGbl_Optarg[0]) 808167802Sjkim { 809167802Sjkim case '1': 810167802Sjkim Gbl_WarningLevel = ASL_WARNING; 811167802Sjkim break; 812167802Sjkim 813167802Sjkim case '2': 814167802Sjkim Gbl_WarningLevel = ASL_WARNING2; 815167802Sjkim break; 816167802Sjkim 817167802Sjkim case '3': 818167802Sjkim Gbl_WarningLevel = ASL_WARNING3; 819167802Sjkim break; 820167802Sjkim 821167802Sjkim default: 822167802Sjkim printf ("Unknown option: -w%s\n", AcpiGbl_Optarg); 823197104Sjkim return (-1); 824167802Sjkim } 825167802Sjkim break; 826167802Sjkim 827167802Sjkim 828118611Snjl case 'x': 829118611Snjl 830118611Snjl AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16); 831118611Snjl break; 832118611Snjl 833118611Snjl 834118611Snjl default: 835118611Snjl 836197104Sjkim return (-1); 837118611Snjl } 838118611Snjl 839197104Sjkim return (0); 840197104Sjkim} 841197104Sjkim 842197104Sjkim 843197104Sjkim/******************************************************************************* 844197104Sjkim * 845197104Sjkim * FUNCTION: AslCommandLine 846197104Sjkim * 847197104Sjkim * PARAMETERS: argc/argv 848197104Sjkim * 849197104Sjkim * RETURN: Last argv index 850197104Sjkim * 851197104Sjkim * DESCRIPTION: Command line processing 852197104Sjkim * 853197104Sjkim ******************************************************************************/ 854197104Sjkim 855197104Sjkimstatic int 856197104SjkimAslCommandLine ( 857197104Sjkim int argc, 858197104Sjkim char **argv) 859197104Sjkim{ 860197104Sjkim int BadCommandLine = 0; 861197104Sjkim 862197104Sjkim 863197104Sjkim /* Minimum command line contains at least the command and an input file */ 864197104Sjkim 865197104Sjkim if (argc < 2) 866197104Sjkim { 867197104Sjkim AslCompilerSignon (ASL_FILE_STDOUT); 868197104Sjkim Usage (); 869197104Sjkim exit (1); 870197104Sjkim } 871197104Sjkim 872197104Sjkim /* Process all command line options */ 873197104Sjkim 874197104Sjkim BadCommandLine = AslDoOptions (argc, argv, FALSE); 875197104Sjkim 876118611Snjl /* Next parameter must be the input filename */ 877118611Snjl 878193529Sjkim if (!argv[AcpiGbl_Optind] && 879151937Sjkim !Gbl_DisasmFlag && 880151937Sjkim !Gbl_GetAllTables) 881118611Snjl { 882118611Snjl printf ("Missing input filename\n"); 883118611Snjl BadCommandLine = TRUE; 884118611Snjl } 885118611Snjl 886193529Sjkim if (Gbl_DoSignon) 887118611Snjl { 888118611Snjl AslCompilerSignon (ASL_FILE_STDOUT); 889118611Snjl } 890118611Snjl 891118611Snjl /* Abort if anything went wrong on the command line */ 892118611Snjl 893118611Snjl if (BadCommandLine) 894118611Snjl { 895118611Snjl printf ("\n"); 896118611Snjl Usage (); 897118611Snjl exit (1); 898118611Snjl } 899118611Snjl 900193529Sjkim return (AcpiGbl_Optind); 901118611Snjl} 902118611Snjl 903118611Snjl 904118611Snjl/******************************************************************************* 905118611Snjl * 906118611Snjl * FUNCTION: main 907118611Snjl * 908118611Snjl * PARAMETERS: Standard argc/argv 909118611Snjl * 910118611Snjl * RETURN: Program termination code 911118611Snjl * 912193529Sjkim * DESCRIPTION: C main routine for the Asl Compiler. Handle command line 913193529Sjkim * options and begin the compile for each file on the command line 914118611Snjl * 915118611Snjl ******************************************************************************/ 916118611Snjl 917118611Snjlint ACPI_SYSTEM_XFACE 918118611Snjlmain ( 919118611Snjl int argc, 920118611Snjl char **argv) 921118611Snjl{ 922118611Snjl ACPI_STATUS Status; 923193529Sjkim int Index; 924118611Snjl 925118611Snjl 926151937Sjkim#ifdef _DEBUG 927151937Sjkim _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF | 928151937Sjkim _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG)); 929151937Sjkim#endif 930151937Sjkim 931118611Snjl /* Init and command line */ 932118611Snjl 933118611Snjl AslInitialize (); 934193529Sjkim Index = AslCommandLine (argc, argv); 935118611Snjl 936193529Sjkim /* Options that have no additional parameters or pathnames */ 937118611Snjl 938193529Sjkim if (Gbl_GetAllTables) 939118611Snjl { 940193529Sjkim Status = AslDoOneFile (NULL); 941118611Snjl if (ACPI_FAILURE (Status)) 942118611Snjl { 943193529Sjkim return (-1); 944118611Snjl } 945193529Sjkim return (0); 946193529Sjkim } 947118611Snjl 948193529Sjkim /* Process each pathname/filename in the list, with possible wildcards */ 949118611Snjl 950193529Sjkim while (argv[Index]) 951118611Snjl { 952193529Sjkim Status = AslDoOnePathname (argv[Index]); 953151937Sjkim if (ACPI_FAILURE (Status)) 954151937Sjkim { 955193529Sjkim return (-1); 956151937Sjkim } 957118611Snjl 958193529Sjkim Index++; 959118611Snjl } 960118611Snjl 961118611Snjl return (0); 962118611Snjl} 963118611Snjl 964118611Snjl 965