aslmain.c revision 213806
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> 122210976Sjkim#include <contrib/dev/acpica/include/acdisasm.h> 123118611Snjl 124118611Snjl#ifdef _DEBUG 125118611Snjl#include <crtdbg.h> 126118611Snjl#endif 127118611Snjl 128118611Snjl#define _COMPONENT ACPI_COMPILER 129118611Snjl ACPI_MODULE_NAME ("aslmain") 130118611Snjl 131151937Sjkim/* Local prototypes */ 132118611Snjl 133151937Sjkimstatic void 134151937SjkimOptions ( 135151937Sjkim void); 136151937Sjkim 137151937Sjkimstatic void 138151937SjkimHelpMessage ( 139151937Sjkim void); 140151937Sjkim 141151937Sjkimstatic void 142151937SjkimUsage ( 143151937Sjkim void); 144151937Sjkim 145151937Sjkimstatic void 146151937SjkimAslInitialize ( 147151937Sjkim void); 148151937Sjkim 149193529Sjkimstatic int 150151937SjkimAslCommandLine ( 151151937Sjkim int argc, 152151937Sjkim char **argv); 153151937Sjkim 154197104Sjkimstatic int 155197104SjkimAslDoOptions ( 156197104Sjkim int argc, 157197104Sjkim char **argv, 158197104Sjkim BOOLEAN IsResponseFile); 159151937Sjkim 160197104Sjkimstatic void 161197104SjkimAslMergeOptionTokens ( 162197104Sjkim char *InBuffer, 163197104Sjkim char *OutBuffer); 164197104Sjkim 165197104Sjkimstatic int 166197104SjkimAslDoResponseFile ( 167197104Sjkim char *Filename); 168197104Sjkim 169197104Sjkim 170197104Sjkim#define ASL_TOKEN_SEPARATORS " \t\n" 171209746Sjkim#define ASL_SUPPORTED_OPTIONS "@:2b:c:d^e:fgh^i^I:l^no:p:r:s:t:T:v:w:x:z" 172197104Sjkim 173197104Sjkim 174118611Snjl/******************************************************************************* 175118611Snjl * 176118611Snjl * FUNCTION: Options 177118611Snjl * 178118611Snjl * PARAMETERS: None 179118611Snjl * 180118611Snjl * RETURN: None 181118611Snjl * 182118611Snjl * DESCRIPTION: Display option help message 183118611Snjl * 184118611Snjl ******************************************************************************/ 185118611Snjl 186151937Sjkimstatic void 187118611SnjlOptions ( 188118611Snjl void) 189118611Snjl{ 190118611Snjl 191197104Sjkim printf ("Global:\n"); 192197104Sjkim printf (" -@<file> Specify command file\n"); 193197104Sjkim printf (" -I<dir> Specify additional include directory\n"); 194197104Sjkim 195197104Sjkim printf ("\nGeneral Output:\n"); 196197104Sjkim printf (" -p<prefix> Specify path/filename prefix for all output files\n"); 197193529Sjkim printf (" -va Disable all errors and warnings (summary only)\n"); 198118611Snjl printf (" -vi Less verbose errors and warnings for use with IDEs\n"); 199118611Snjl printf (" -vo Enable optimization comments\n"); 200118611Snjl printf (" -vr Disable remarks\n"); 201118611Snjl printf (" -vs Disable signon\n"); 202167802Sjkim printf (" -w<1|2|3> Set warning reporting level\n"); 203118611Snjl 204138287Smarks printf ("\nAML Output Files:\n"); 205118611Snjl printf (" -s<a|c> Create AML in assembler or C source file (*.asm or *.c)\n"); 206118611Snjl printf (" -i<a|c> Create assembler or C include file (*.inc or *.h)\n"); 207207344Sjkim printf (" -t<a|c|s> Create AML in assembler, C, or ASL hex table (*.hex)\n"); 208118611Snjl 209138287Smarks printf ("\nAML Code Generation:\n"); 210118611Snjl printf (" -oa Disable all optimizations (compatibility mode)\n"); 211118611Snjl printf (" -of Disable constant folding\n"); 212118611Snjl printf (" -oi Disable integer optimization to Zero/One/Ones\n"); 213118611Snjl printf (" -on Disable named reference string optimization\n"); 214207344Sjkim printf (" -cr Disable Resource Descriptor error checking\n"); 215138287Smarks printf (" -r<Revision> Override table header Revision (1-255)\n"); 216118611Snjl 217212761Sjkim printf ("\nASL Listing Files:\n"); 218118611Snjl printf (" -l Create mixed listing file (ASL source and AML) (*.lst)\n"); 219118611Snjl printf (" -ln Create namespace file (*.nsp)\n"); 220118611Snjl printf (" -ls Create combined source file (expanded includes) (*.src)\n"); 221118611Snjl 222209746Sjkim printf ("\nACPI Data Tables:\n"); 223209746Sjkim printf (" -T <Sig> Create table template file for <Sig> (or \"ALL\")\n"); 224209746Sjkim printf (" -vt Create verbose templates (full disassembly)\n"); 225209746Sjkim 226118611Snjl printf ("\nAML Disassembler:\n"); 227167802Sjkim printf (" -d [file] Disassemble or decode binary ACPI table to file (*.dsl)\n"); 228210976Sjkim printf (" -da [f1,f2] Disassemble multiple tables from single namespace\n"); 229118611Snjl printf (" -dc [file] Disassemble AML and immediately compile it\n"); 230118611Snjl printf (" (Obtain DSDT from current system if no input file)\n"); 231193529Sjkim printf (" -e [f1,f2] Include ACPI table(s) for external symbol resolution\n"); 232151937Sjkim printf (" -2 Emit ACPI 2.0 compatible ASL code\n"); 233118611Snjl printf (" -g Get ACPI tables and write to files (*.dat)\n"); 234118611Snjl 235118611Snjl printf ("\nHelp:\n"); 236118611Snjl printf (" -h Additional help and compiler debug options\n"); 237118611Snjl printf (" -hc Display operators allowed in constant expressions\n"); 238118611Snjl printf (" -hr Display ACPI reserved method names\n"); 239209746Sjkim printf (" -ht Display currently supported ACPI table names\n"); 240118611Snjl} 241118611Snjl 242118611Snjl 243118611Snjl/******************************************************************************* 244118611Snjl * 245151937Sjkim * FUNCTION: HelpMessage 246118611Snjl * 247118611Snjl * PARAMETERS: None 248118611Snjl * 249118611Snjl * RETURN: None 250118611Snjl * 251118611Snjl * DESCRIPTION: Display help message 252118611Snjl * 253118611Snjl ******************************************************************************/ 254118611Snjl 255151937Sjkimstatic void 256118611SnjlHelpMessage ( 257118611Snjl void) 258118611Snjl{ 259118611Snjl 260118611Snjl printf ("AML output filename generation:\n"); 261118611Snjl printf (" Output filenames are generated by appending an extension to a common\n"); 262118611Snjl printf (" filename prefix. The filename prefix is obtained via one of the\n"); 263118611Snjl printf (" following methods (in priority order):\n"); 264118611Snjl printf (" 1) The -p option specifies the prefix\n"); 265118611Snjl printf (" 2) The prefix of the AMLFileName in the ASL Definition Block\n"); 266118611Snjl printf (" 3) The prefix of the input filename\n"); 267118611Snjl printf ("\n"); 268118611Snjl 269118611Snjl Options (); 270118611Snjl 271167802Sjkim printf ("\nCompiler/Disassembler Debug Options:\n"); 272118611Snjl printf (" -b<p|t|b> Create compiler debug/trace file (*.txt)\n"); 273118611Snjl printf (" Types: Parse/Tree/Both\n"); 274118611Snjl printf (" -f Ignore errors, force creation of AML output file(s)\n"); 275207344Sjkim printf (" -n Parse only, no output generation\n"); 276118611Snjl printf (" -ot Display compile times\n"); 277118611Snjl printf (" -x<level> Set debug level for trace output\n"); 278209746Sjkim printf (" -z Do not insert new compiler ID for DataTables\n"); 279118611Snjl} 280118611Snjl 281118611Snjl 282118611Snjl/******************************************************************************* 283118611Snjl * 284118611Snjl * FUNCTION: Usage 285118611Snjl * 286118611Snjl * PARAMETERS: None 287118611Snjl * 288118611Snjl * RETURN: None 289118611Snjl * 290118611Snjl * DESCRIPTION: Display usage and option message 291118611Snjl * 292118611Snjl ******************************************************************************/ 293118611Snjl 294151937Sjkimstatic void 295118611SnjlUsage ( 296118611Snjl void) 297118611Snjl{ 298118611Snjl 299213806Sjkim printf ("%s\n", ASL_COMPLIANCE); 300213806Sjkim printf ("Usage: %s [Options] [Files]\n\n", ASL_INVOCATION_NAME); 301118611Snjl Options (); 302118611Snjl} 303118611Snjl 304118611Snjl 305118611Snjl/******************************************************************************* 306118611Snjl * 307118611Snjl * FUNCTION: AslInitialize 308118611Snjl * 309118611Snjl * PARAMETERS: None 310118611Snjl * 311118611Snjl * RETURN: None 312118611Snjl * 313118611Snjl * DESCRIPTION: Initialize compiler globals 314118611Snjl * 315118611Snjl ******************************************************************************/ 316118611Snjl 317151937Sjkimstatic void 318151937SjkimAslInitialize ( 319151937Sjkim void) 320118611Snjl{ 321118611Snjl UINT32 i; 322118611Snjl 323118611Snjl 324118611Snjl#ifdef _DEBUG 325118611Snjl _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0)); 326118611Snjl#endif 327118611Snjl 328118611Snjl AcpiDbgLevel = 0; 329118611Snjl 330118611Snjl for (i = 0; i < ASL_NUM_FILES; i++) 331118611Snjl { 332118611Snjl Gbl_Files[i].Handle = NULL; 333118611Snjl Gbl_Files[i].Filename = NULL; 334118611Snjl } 335118611Snjl 336118611Snjl Gbl_Files[ASL_FILE_STDOUT].Handle = stdout; 337118611Snjl Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT"; 338118611Snjl 339118611Snjl Gbl_Files[ASL_FILE_STDERR].Handle = stderr; 340118611Snjl Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR"; 341118611Snjl} 342118611Snjl 343118611Snjl 344118611Snjl/******************************************************************************* 345118611Snjl * 346197104Sjkim * FUNCTION: AslMergeOptionTokens 347118611Snjl * 348197104Sjkim * PARAMETERS: InBuffer - Input containing an option string 349197104Sjkim * OutBuffer - Merged output buffer 350118611Snjl * 351118611Snjl * RETURN: None 352118611Snjl * 353197104Sjkim * DESCRIPTION: Remove all whitespace from an option string. 354118611Snjl * 355118611Snjl ******************************************************************************/ 356118611Snjl 357197104Sjkimstatic void 358197104SjkimAslMergeOptionTokens ( 359197104Sjkim char *InBuffer, 360197104Sjkim char *OutBuffer) 361197104Sjkim{ 362197104Sjkim char *Token; 363197104Sjkim 364197104Sjkim 365197104Sjkim *OutBuffer = 0; 366197104Sjkim 367197104Sjkim Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS); 368197104Sjkim while (Token) 369197104Sjkim { 370197104Sjkim strcat (OutBuffer, Token); 371197104Sjkim Token = strtok (NULL, ASL_TOKEN_SEPARATORS); 372197104Sjkim } 373197104Sjkim} 374197104Sjkim 375197104Sjkim 376197104Sjkim/******************************************************************************* 377197104Sjkim * 378197104Sjkim * FUNCTION: AslDoResponseFile 379197104Sjkim * 380197104Sjkim * PARAMETERS: Filename - Name of the response file 381197104Sjkim * 382197104Sjkim * RETURN: Status 383197104Sjkim * 384197104Sjkim * DESCRIPTION: Open a response file and process all options within. 385197104Sjkim * 386197104Sjkim ******************************************************************************/ 387197104Sjkim 388193529Sjkimstatic int 389197104SjkimAslDoResponseFile ( 390197104Sjkim char *Filename) 391118611Snjl{ 392197104Sjkim char *argv = StringBuffer2; 393197104Sjkim FILE *ResponseFile; 394197104Sjkim int OptStatus = 0; 395197104Sjkim int Opterr; 396197104Sjkim int Optind; 397118611Snjl 398118611Snjl 399197104Sjkim ResponseFile = fopen (Filename, "r"); 400197104Sjkim if (!ResponseFile) 401197104Sjkim { 402197104Sjkim printf ("Could not open command file %s, %s\n", 403197104Sjkim Filename, strerror (errno)); 404197104Sjkim return -1; 405197104Sjkim } 406118611Snjl 407197104Sjkim /* Must save the current GetOpt globals */ 408197104Sjkim 409197104Sjkim Opterr = AcpiGbl_Opterr; 410197104Sjkim Optind = AcpiGbl_Optind; 411197104Sjkim 412197104Sjkim /* 413197104Sjkim * Process all lines in the response file. There must be one complete 414197104Sjkim * option per line 415197104Sjkim */ 416197104Sjkim while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile)) 417118611Snjl { 418197104Sjkim /* Compress all tokens, allowing us to use a single argv entry */ 419197104Sjkim 420197104Sjkim AslMergeOptionTokens (StringBuffer, StringBuffer2); 421197104Sjkim 422197104Sjkim /* Process the option */ 423197104Sjkim 424197104Sjkim AcpiGbl_Opterr = 0; 425197104Sjkim AcpiGbl_Optind = 0; 426197104Sjkim 427197104Sjkim OptStatus = AslDoOptions (1, &argv, TRUE); 428197104Sjkim if (OptStatus) 429197104Sjkim { 430197104Sjkim printf ("Invalid option in command file %s: %s\n", 431197104Sjkim Filename, StringBuffer); 432197104Sjkim break; 433197104Sjkim } 434118611Snjl } 435118611Snjl 436197104Sjkim /* Restore the GetOpt globals */ 437197104Sjkim 438197104Sjkim AcpiGbl_Opterr = Opterr; 439197104Sjkim AcpiGbl_Optind = Optind; 440197104Sjkim 441197104Sjkim fclose (ResponseFile); 442197104Sjkim return (OptStatus); 443197104Sjkim} 444197104Sjkim 445197104Sjkim 446197104Sjkim/******************************************************************************* 447197104Sjkim * 448197104Sjkim * FUNCTION: AslDoOptions 449197104Sjkim * 450197104Sjkim * PARAMETERS: argc/argv - Standard argc/argv 451197104Sjkim * IsResponseFile - TRUE if executing a response file. 452197104Sjkim * 453197104Sjkim * RETURN: Status 454197104Sjkim * 455197104Sjkim * DESCRIPTION: Command line option processing 456197104Sjkim * 457197104Sjkim ******************************************************************************/ 458197104Sjkim 459197104Sjkimstatic int 460197104SjkimAslDoOptions ( 461197104Sjkim int argc, 462197104Sjkim char **argv, 463197104Sjkim BOOLEAN IsResponseFile) 464197104Sjkim{ 465197104Sjkim int j; 466212761Sjkim ACPI_STATUS Status; 467197104Sjkim 468197104Sjkim 469118611Snjl /* Get the command line options */ 470118611Snjl 471197104Sjkim while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j) 472118611Snjl { 473197104Sjkim case '@': /* Begin a response file */ 474197104Sjkim 475197104Sjkim if (IsResponseFile) 476197104Sjkim { 477197104Sjkim printf ("Nested command files are not supported\n"); 478197104Sjkim return -1; 479197104Sjkim } 480197104Sjkim 481197104Sjkim if (AslDoResponseFile (AcpiGbl_Optarg)) 482197104Sjkim { 483197104Sjkim return -1; 484197104Sjkim } 485197104Sjkim break; 486197104Sjkim 487197104Sjkim 488151937Sjkim case '2': 489197104Sjkim 490151937Sjkim Gbl_Acpi2 = TRUE; 491151937Sjkim break; 492151937Sjkim 493151937Sjkim 494118611Snjl case 'b': 495118611Snjl 496118611Snjl switch (AcpiGbl_Optarg[0]) 497118611Snjl { 498118611Snjl case 'b': 499118611Snjl AslCompilerdebug = 1; /* same as yydebug */ 500118611Snjl break; 501118611Snjl 502118611Snjl case 'p': 503118611Snjl AslCompilerdebug = 1; /* same as yydebug */ 504118611Snjl break; 505118611Snjl 506118611Snjl case 't': 507118611Snjl break; 508118611Snjl 509118611Snjl default: 510118611Snjl printf ("Unknown option: -b%s\n", AcpiGbl_Optarg); 511197104Sjkim return (-1); 512118611Snjl } 513118611Snjl 514118611Snjl /* Produce debug output file */ 515118611Snjl 516118611Snjl Gbl_DebugFlag = TRUE; 517118611Snjl break; 518118611Snjl 519118611Snjl 520118611Snjl case 'c': 521207344Sjkim switch (AcpiGbl_Optarg[0]) 522207344Sjkim { 523207344Sjkim case 'r': 524207344Sjkim Gbl_NoResourceChecking = TRUE; 525207344Sjkim break; 526118611Snjl 527207344Sjkim default: 528207344Sjkim printf ("Unknown option: -c%s\n", AcpiGbl_Optarg); 529207344Sjkim return (-1); 530207344Sjkim } 531118611Snjl break; 532118611Snjl 533118611Snjl 534118611Snjl case 'd': 535118611Snjl switch (AcpiGbl_Optarg[0]) 536118611Snjl { 537118611Snjl case '^': 538193529Sjkim Gbl_DoCompile = FALSE; 539118611Snjl break; 540118611Snjl 541210976Sjkim case 'a': 542210976Sjkim Gbl_DoCompile = FALSE; 543210976Sjkim Gbl_DisassembleAll = TRUE; 544210976Sjkim break; 545210976Sjkim 546118611Snjl case 'c': 547118611Snjl break; 548118611Snjl 549118611Snjl default: 550118611Snjl printf ("Unknown option: -d%s\n", AcpiGbl_Optarg); 551197104Sjkim return (-1); 552118611Snjl } 553118611Snjl 554118611Snjl Gbl_DisasmFlag = TRUE; 555118611Snjl break; 556118611Snjl 557118611Snjl 558118611Snjl case 'e': 559212761Sjkim Status = AcpiDmAddToExternalFileList (AcpiGbl_Optarg); 560212761Sjkim if (ACPI_FAILURE (Status)) 561212761Sjkim { 562212761Sjkim printf ("Could not add %s to external list\n", AcpiGbl_Optarg); 563212761Sjkim return (-1); 564212761Sjkim } 565118611Snjl break; 566118611Snjl 567118611Snjl 568118611Snjl case 'f': 569118611Snjl 570118611Snjl /* Ignore errors and force creation of aml file */ 571118611Snjl 572118611Snjl Gbl_IgnoreErrors = TRUE; 573118611Snjl break; 574118611Snjl 575118611Snjl 576118611Snjl case 'g': 577118611Snjl 578118611Snjl /* Get all ACPI tables */ 579118611Snjl 580118611Snjl Gbl_GetAllTables = TRUE; 581193529Sjkim Gbl_DoCompile = FALSE; 582118611Snjl break; 583118611Snjl 584118611Snjl 585118611Snjl case 'h': 586118611Snjl 587118611Snjl switch (AcpiGbl_Optarg[0]) 588118611Snjl { 589118611Snjl case '^': 590118611Snjl HelpMessage (); 591118611Snjl exit (0); 592118611Snjl 593118611Snjl case 'c': 594118611Snjl UtDisplayConstantOpcodes (); 595118611Snjl exit (0); 596118611Snjl 597118611Snjl case 'r': 598118611Snjl /* reserved names */ 599118611Snjl 600204773Sjkim ApDisplayReservedNames (); 601118611Snjl exit (0); 602118611Snjl 603209746Sjkim case 't': 604209746Sjkim UtDisplaySupportedTables (); 605209746Sjkim exit (0); 606209746Sjkim 607118611Snjl default: 608118611Snjl printf ("Unknown option: -h%s\n", AcpiGbl_Optarg); 609197104Sjkim return (-1); 610118611Snjl } 611118611Snjl 612118611Snjl 613197104Sjkim case 'I': /* Add an include file search directory */ 614197104Sjkim 615197104Sjkim FlAddIncludeDirectory (AcpiGbl_Optarg); 616197104Sjkim break; 617197104Sjkim 618197104Sjkim 619118611Snjl case 'i': 620118611Snjl 621118611Snjl switch (AcpiGbl_Optarg[0]) 622118611Snjl { 623118611Snjl case 'a': 624118611Snjl 625118611Snjl /* Produce assembly code include file */ 626118611Snjl 627118611Snjl Gbl_AsmIncludeOutputFlag = TRUE; 628118611Snjl break; 629118611Snjl 630118611Snjl case 'c': 631118611Snjl 632118611Snjl /* Produce C include file */ 633118611Snjl 634118611Snjl Gbl_C_IncludeOutputFlag = TRUE; 635118611Snjl break; 636118611Snjl 637118611Snjl default: 638118611Snjl printf ("Unknown option: -s%s\n", AcpiGbl_Optarg); 639197104Sjkim return (-1); 640118611Snjl } 641118611Snjl break; 642118611Snjl 643118611Snjl 644118611Snjl case 'l': 645118611Snjl 646118611Snjl switch (AcpiGbl_Optarg[0]) 647118611Snjl { 648118611Snjl case '^': 649118611Snjl /* Produce listing file (Mixed source/aml) */ 650118611Snjl 651118611Snjl Gbl_ListingFlag = TRUE; 652118611Snjl break; 653118611Snjl 654118611Snjl case 'n': 655118611Snjl /* Produce namespace file */ 656118611Snjl 657118611Snjl Gbl_NsOutputFlag = TRUE; 658118611Snjl break; 659118611Snjl 660118611Snjl case 's': 661118611Snjl /* Produce combined source file */ 662118611Snjl 663118611Snjl Gbl_SourceOutputFlag = TRUE; 664118611Snjl break; 665118611Snjl 666118611Snjl default: 667118611Snjl printf ("Unknown option: -l%s\n", AcpiGbl_Optarg); 668197104Sjkim return (-1); 669118611Snjl } 670118611Snjl break; 671118611Snjl 672118611Snjl 673118611Snjl case 'o': 674118611Snjl 675118611Snjl switch (AcpiGbl_Optarg[0]) 676118611Snjl { 677118611Snjl case 'a': 678118611Snjl 679118611Snjl /* Disable all optimizations */ 680118611Snjl 681118611Snjl Gbl_FoldConstants = FALSE; 682118611Snjl Gbl_IntegerOptimizationFlag = FALSE; 683118611Snjl Gbl_ReferenceOptimizationFlag = FALSE; 684118611Snjl break; 685118611Snjl 686118611Snjl case 'f': 687118611Snjl 688118611Snjl /* Disable folding on "normal" expressions */ 689118611Snjl 690118611Snjl Gbl_FoldConstants = FALSE; 691118611Snjl break; 692118611Snjl 693118611Snjl case 'i': 694118611Snjl 695118611Snjl /* Disable integer optimization to constants */ 696118611Snjl 697118611Snjl Gbl_IntegerOptimizationFlag = FALSE; 698118611Snjl break; 699118611Snjl 700118611Snjl case 'n': 701118611Snjl 702118611Snjl /* Disable named reference optimization */ 703118611Snjl 704118611Snjl Gbl_ReferenceOptimizationFlag = FALSE; 705118611Snjl break; 706118611Snjl 707118611Snjl case 't': 708118611Snjl 709118611Snjl /* Display compile time(s) */ 710118611Snjl 711118611Snjl Gbl_CompileTimesFlag = TRUE; 712118611Snjl break; 713118611Snjl 714118611Snjl default: 715118611Snjl printf ("Unknown option: -c%s\n", AcpiGbl_Optarg); 716197104Sjkim return (-1); 717118611Snjl } 718118611Snjl break; 719118611Snjl 720118611Snjl 721207344Sjkim case 'n': 722207344Sjkim 723207344Sjkim /* Parse only */ 724207344Sjkim 725207344Sjkim Gbl_ParseOnlyFlag = TRUE; 726207344Sjkim break; 727207344Sjkim 728207344Sjkim 729118611Snjl case 'p': 730118611Snjl 731118611Snjl /* Override default AML output filename */ 732118611Snjl 733118611Snjl Gbl_OutputFilenamePrefix = AcpiGbl_Optarg; 734118611Snjl Gbl_UseDefaultAmlFilename = FALSE; 735118611Snjl break; 736118611Snjl 737118611Snjl 738118611Snjl case 'r': 739138287Smarks Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0); 740118611Snjl break; 741118611Snjl 742118611Snjl 743118611Snjl case 's': 744118611Snjl 745118611Snjl switch (AcpiGbl_Optarg[0]) 746118611Snjl { 747118611Snjl case 'a': 748118611Snjl 749118611Snjl /* Produce assembly code output file */ 750118611Snjl 751118611Snjl Gbl_AsmOutputFlag = TRUE; 752118611Snjl break; 753118611Snjl 754118611Snjl case 'c': 755118611Snjl 756118611Snjl /* Produce C hex output file */ 757118611Snjl 758118611Snjl Gbl_C_OutputFlag = TRUE; 759118611Snjl break; 760118611Snjl 761118611Snjl default: 762118611Snjl printf ("Unknown option: -s%s\n", AcpiGbl_Optarg); 763197104Sjkim return (-1); 764118611Snjl } 765118611Snjl break; 766118611Snjl 767118611Snjl 768118611Snjl case 't': 769118611Snjl 770118611Snjl /* Produce hex table output file */ 771118611Snjl 772118611Snjl switch (AcpiGbl_Optarg[0]) 773118611Snjl { 774118611Snjl case 'a': 775118611Snjl Gbl_HexOutputFlag = HEX_OUTPUT_ASM; 776118611Snjl break; 777118611Snjl 778118611Snjl case 'c': 779118611Snjl Gbl_HexOutputFlag = HEX_OUTPUT_C; 780118611Snjl break; 781118611Snjl 782207344Sjkim case 's': 783207344Sjkim Gbl_HexOutputFlag = HEX_OUTPUT_ASL; 784207344Sjkim break; 785207344Sjkim 786118611Snjl default: 787118611Snjl printf ("Unknown option: -t%s\n", AcpiGbl_Optarg); 788197104Sjkim return (-1); 789118611Snjl } 790118611Snjl break; 791118611Snjl 792118611Snjl 793209746Sjkim case 'T': 794209746Sjkim Gbl_DoTemplates = TRUE; 795209746Sjkim Gbl_TemplateSignature = AcpiGbl_Optarg; 796209746Sjkim break; 797209746Sjkim 798209746Sjkim 799118611Snjl case 'v': 800118611Snjl 801118611Snjl switch (AcpiGbl_Optarg[0]) 802118611Snjl { 803193529Sjkim case 'a': 804193529Sjkim /* Disable All error/warning messages */ 805193529Sjkim 806193529Sjkim Gbl_NoErrors = TRUE; 807193529Sjkim break; 808193529Sjkim 809118611Snjl case 'i': 810118611Snjl /* Less verbose error messages */ 811118611Snjl 812118611Snjl Gbl_VerboseErrors = FALSE; 813118611Snjl break; 814118611Snjl 815118611Snjl case 'o': 816118611Snjl Gbl_DisplayOptimizations = TRUE; 817118611Snjl break; 818118611Snjl 819118611Snjl case 'r': 820118611Snjl Gbl_DisplayRemarks = FALSE; 821118611Snjl break; 822118611Snjl 823118611Snjl case 's': 824193529Sjkim Gbl_DoSignon = FALSE; 825118611Snjl break; 826118611Snjl 827209746Sjkim case 't': 828209746Sjkim Gbl_VerboseTemplates = TRUE; 829209746Sjkim break; 830209746Sjkim 831118611Snjl default: 832118611Snjl printf ("Unknown option: -v%s\n", AcpiGbl_Optarg); 833197104Sjkim return (-1); 834118611Snjl } 835118611Snjl break; 836118611Snjl 837118611Snjl 838167802Sjkim case 'w': /* Set warning levels */ 839167802Sjkim 840167802Sjkim switch (AcpiGbl_Optarg[0]) 841167802Sjkim { 842167802Sjkim case '1': 843167802Sjkim Gbl_WarningLevel = ASL_WARNING; 844167802Sjkim break; 845167802Sjkim 846167802Sjkim case '2': 847167802Sjkim Gbl_WarningLevel = ASL_WARNING2; 848167802Sjkim break; 849167802Sjkim 850167802Sjkim case '3': 851167802Sjkim Gbl_WarningLevel = ASL_WARNING3; 852167802Sjkim break; 853167802Sjkim 854167802Sjkim default: 855167802Sjkim printf ("Unknown option: -w%s\n", AcpiGbl_Optarg); 856197104Sjkim return (-1); 857167802Sjkim } 858167802Sjkim break; 859167802Sjkim 860167802Sjkim 861118611Snjl case 'x': 862118611Snjl 863118611Snjl AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16); 864118611Snjl break; 865118611Snjl 866118611Snjl 867209746Sjkim case 'z': 868209746Sjkim 869209746Sjkim Gbl_UseOriginalCompilerId = TRUE; 870209746Sjkim break; 871209746Sjkim 872209746Sjkim 873118611Snjl default: 874118611Snjl 875197104Sjkim return (-1); 876118611Snjl } 877118611Snjl 878197104Sjkim return (0); 879197104Sjkim} 880197104Sjkim 881197104Sjkim 882197104Sjkim/******************************************************************************* 883197104Sjkim * 884197104Sjkim * FUNCTION: AslCommandLine 885197104Sjkim * 886197104Sjkim * PARAMETERS: argc/argv 887197104Sjkim * 888197104Sjkim * RETURN: Last argv index 889197104Sjkim * 890197104Sjkim * DESCRIPTION: Command line processing 891197104Sjkim * 892197104Sjkim ******************************************************************************/ 893197104Sjkim 894197104Sjkimstatic int 895197104SjkimAslCommandLine ( 896197104Sjkim int argc, 897197104Sjkim char **argv) 898197104Sjkim{ 899197104Sjkim int BadCommandLine = 0; 900212761Sjkim ACPI_STATUS Status; 901197104Sjkim 902197104Sjkim 903197104Sjkim /* Minimum command line contains at least the command and an input file */ 904197104Sjkim 905197104Sjkim if (argc < 2) 906197104Sjkim { 907213806Sjkim printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME)); 908197104Sjkim Usage (); 909197104Sjkim exit (1); 910197104Sjkim } 911197104Sjkim 912197104Sjkim /* Process all command line options */ 913197104Sjkim 914197104Sjkim BadCommandLine = AslDoOptions (argc, argv, FALSE); 915197104Sjkim 916209746Sjkim if (Gbl_DoTemplates) 917209746Sjkim { 918212761Sjkim Status = DtCreateTemplates (Gbl_TemplateSignature); 919212761Sjkim if (ACPI_FAILURE (Status)) 920212761Sjkim { 921212761Sjkim exit (-1); 922212761Sjkim } 923209746Sjkim exit (1); 924209746Sjkim } 925209746Sjkim 926118611Snjl /* Next parameter must be the input filename */ 927118611Snjl 928193529Sjkim if (!argv[AcpiGbl_Optind] && 929151937Sjkim !Gbl_DisasmFlag && 930151937Sjkim !Gbl_GetAllTables) 931118611Snjl { 932118611Snjl printf ("Missing input filename\n"); 933118611Snjl BadCommandLine = TRUE; 934118611Snjl } 935118611Snjl 936193529Sjkim if (Gbl_DoSignon) 937118611Snjl { 938213806Sjkim printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME)); 939118611Snjl } 940118611Snjl 941118611Snjl /* Abort if anything went wrong on the command line */ 942118611Snjl 943118611Snjl if (BadCommandLine) 944118611Snjl { 945118611Snjl printf ("\n"); 946118611Snjl Usage (); 947118611Snjl exit (1); 948118611Snjl } 949118611Snjl 950193529Sjkim return (AcpiGbl_Optind); 951118611Snjl} 952118611Snjl 953118611Snjl 954118611Snjl/******************************************************************************* 955118611Snjl * 956118611Snjl * FUNCTION: main 957118611Snjl * 958118611Snjl * PARAMETERS: Standard argc/argv 959118611Snjl * 960118611Snjl * RETURN: Program termination code 961118611Snjl * 962193529Sjkim * DESCRIPTION: C main routine for the Asl Compiler. Handle command line 963193529Sjkim * options and begin the compile for each file on the command line 964118611Snjl * 965118611Snjl ******************************************************************************/ 966118611Snjl 967118611Snjlint ACPI_SYSTEM_XFACE 968118611Snjlmain ( 969118611Snjl int argc, 970118611Snjl char **argv) 971118611Snjl{ 972118611Snjl ACPI_STATUS Status; 973210976Sjkim int Index1; 974210976Sjkim int Index2; 975118611Snjl 976118611Snjl 977210976Sjkim AcpiGbl_ExternalFileList = NULL; 978210976Sjkim 979151937Sjkim#ifdef _DEBUG 980151937Sjkim _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF | 981151937Sjkim _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG)); 982151937Sjkim#endif 983151937Sjkim 984118611Snjl /* Init and command line */ 985118611Snjl 986118611Snjl AslInitialize (); 987210976Sjkim Index1 = Index2 = AslCommandLine (argc, argv); 988118611Snjl 989193529Sjkim /* Options that have no additional parameters or pathnames */ 990118611Snjl 991193529Sjkim if (Gbl_GetAllTables) 992118611Snjl { 993193529Sjkim Status = AslDoOneFile (NULL); 994118611Snjl if (ACPI_FAILURE (Status)) 995118611Snjl { 996193529Sjkim return (-1); 997118611Snjl } 998193529Sjkim return (0); 999193529Sjkim } 1000118611Snjl 1001210976Sjkim if (Gbl_DisassembleAll) 1002210976Sjkim { 1003210976Sjkim while (argv[Index1]) 1004210976Sjkim { 1005210976Sjkim Status = AslDoOnePathname (argv[Index1], AcpiDmAddToExternalFileList); 1006210976Sjkim if (ACPI_FAILURE (Status)) 1007210976Sjkim { 1008210976Sjkim return (-1); 1009210976Sjkim } 1010210976Sjkim 1011210976Sjkim Index1++; 1012210976Sjkim } 1013210976Sjkim } 1014210976Sjkim 1015193529Sjkim /* Process each pathname/filename in the list, with possible wildcards */ 1016118611Snjl 1017210976Sjkim while (argv[Index2]) 1018118611Snjl { 1019210976Sjkim Status = AslDoOnePathname (argv[Index2], AslDoOneFile); 1020151937Sjkim if (ACPI_FAILURE (Status)) 1021151937Sjkim { 1022193529Sjkim return (-1); 1023151937Sjkim } 1024118611Snjl 1025210976Sjkim Index2++; 1026118611Snjl } 1027118611Snjl 1028210976Sjkim if (AcpiGbl_ExternalFileList) 1029210976Sjkim { 1030210976Sjkim AcpiDmClearExternalFileList(); 1031210976Sjkim } 1032210976Sjkim 1033118611Snjl return (0); 1034118611Snjl} 1035118611Snjl 1036118611Snjl 1037