aslmain.c revision 210976
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 217118611Snjl printf ("\nListings:\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 299193529Sjkim printf ("Usage: %s [Options] [Files]\n\n", CompilerName); 300118611Snjl Options (); 301118611Snjl} 302118611Snjl 303118611Snjl 304118611Snjl/******************************************************************************* 305118611Snjl * 306118611Snjl * FUNCTION: AslInitialize 307118611Snjl * 308118611Snjl * PARAMETERS: None 309118611Snjl * 310118611Snjl * RETURN: None 311118611Snjl * 312118611Snjl * DESCRIPTION: Initialize compiler globals 313118611Snjl * 314118611Snjl ******************************************************************************/ 315118611Snjl 316151937Sjkimstatic void 317151937SjkimAslInitialize ( 318151937Sjkim void) 319118611Snjl{ 320118611Snjl UINT32 i; 321118611Snjl 322118611Snjl 323118611Snjl#ifdef _DEBUG 324118611Snjl _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0)); 325118611Snjl#endif 326118611Snjl 327118611Snjl AcpiDbgLevel = 0; 328118611Snjl 329118611Snjl for (i = 0; i < ASL_NUM_FILES; i++) 330118611Snjl { 331118611Snjl Gbl_Files[i].Handle = NULL; 332118611Snjl Gbl_Files[i].Filename = NULL; 333118611Snjl } 334118611Snjl 335118611Snjl Gbl_Files[ASL_FILE_STDOUT].Handle = stdout; 336118611Snjl Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT"; 337118611Snjl 338118611Snjl Gbl_Files[ASL_FILE_STDERR].Handle = stderr; 339118611Snjl Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR"; 340118611Snjl} 341118611Snjl 342118611Snjl 343118611Snjl/******************************************************************************* 344118611Snjl * 345197104Sjkim * FUNCTION: AslMergeOptionTokens 346118611Snjl * 347197104Sjkim * PARAMETERS: InBuffer - Input containing an option string 348197104Sjkim * OutBuffer - Merged output buffer 349118611Snjl * 350118611Snjl * RETURN: None 351118611Snjl * 352197104Sjkim * DESCRIPTION: Remove all whitespace from an option string. 353118611Snjl * 354118611Snjl ******************************************************************************/ 355118611Snjl 356197104Sjkimstatic void 357197104SjkimAslMergeOptionTokens ( 358197104Sjkim char *InBuffer, 359197104Sjkim char *OutBuffer) 360197104Sjkim{ 361197104Sjkim char *Token; 362197104Sjkim 363197104Sjkim 364197104Sjkim *OutBuffer = 0; 365197104Sjkim 366197104Sjkim Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS); 367197104Sjkim while (Token) 368197104Sjkim { 369197104Sjkim strcat (OutBuffer, Token); 370197104Sjkim Token = strtok (NULL, ASL_TOKEN_SEPARATORS); 371197104Sjkim } 372197104Sjkim} 373197104Sjkim 374197104Sjkim 375197104Sjkim/******************************************************************************* 376197104Sjkim * 377197104Sjkim * FUNCTION: AslDoResponseFile 378197104Sjkim * 379197104Sjkim * PARAMETERS: Filename - Name of the response file 380197104Sjkim * 381197104Sjkim * RETURN: Status 382197104Sjkim * 383197104Sjkim * DESCRIPTION: Open a response file and process all options within. 384197104Sjkim * 385197104Sjkim ******************************************************************************/ 386197104Sjkim 387193529Sjkimstatic int 388197104SjkimAslDoResponseFile ( 389197104Sjkim char *Filename) 390118611Snjl{ 391197104Sjkim char *argv = StringBuffer2; 392197104Sjkim FILE *ResponseFile; 393197104Sjkim int OptStatus = 0; 394197104Sjkim int Opterr; 395197104Sjkim int Optind; 396118611Snjl 397118611Snjl 398197104Sjkim ResponseFile = fopen (Filename, "r"); 399197104Sjkim if (!ResponseFile) 400197104Sjkim { 401197104Sjkim printf ("Could not open command file %s, %s\n", 402197104Sjkim Filename, strerror (errno)); 403197104Sjkim return -1; 404197104Sjkim } 405118611Snjl 406197104Sjkim /* Must save the current GetOpt globals */ 407197104Sjkim 408197104Sjkim Opterr = AcpiGbl_Opterr; 409197104Sjkim Optind = AcpiGbl_Optind; 410197104Sjkim 411197104Sjkim /* 412197104Sjkim * Process all lines in the response file. There must be one complete 413197104Sjkim * option per line 414197104Sjkim */ 415197104Sjkim while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile)) 416118611Snjl { 417197104Sjkim /* Compress all tokens, allowing us to use a single argv entry */ 418197104Sjkim 419197104Sjkim AslMergeOptionTokens (StringBuffer, StringBuffer2); 420197104Sjkim 421197104Sjkim /* Process the option */ 422197104Sjkim 423197104Sjkim AcpiGbl_Opterr = 0; 424197104Sjkim AcpiGbl_Optind = 0; 425197104Sjkim 426197104Sjkim OptStatus = AslDoOptions (1, &argv, TRUE); 427197104Sjkim if (OptStatus) 428197104Sjkim { 429197104Sjkim printf ("Invalid option in command file %s: %s\n", 430197104Sjkim Filename, StringBuffer); 431197104Sjkim break; 432197104Sjkim } 433118611Snjl } 434118611Snjl 435197104Sjkim /* Restore the GetOpt globals */ 436197104Sjkim 437197104Sjkim AcpiGbl_Opterr = Opterr; 438197104Sjkim AcpiGbl_Optind = Optind; 439197104Sjkim 440197104Sjkim fclose (ResponseFile); 441197104Sjkim return (OptStatus); 442197104Sjkim} 443197104Sjkim 444197104Sjkim 445197104Sjkim/******************************************************************************* 446197104Sjkim * 447197104Sjkim * FUNCTION: AslDoOptions 448197104Sjkim * 449197104Sjkim * PARAMETERS: argc/argv - Standard argc/argv 450197104Sjkim * IsResponseFile - TRUE if executing a response file. 451197104Sjkim * 452197104Sjkim * RETURN: Status 453197104Sjkim * 454197104Sjkim * DESCRIPTION: Command line option processing 455197104Sjkim * 456197104Sjkim ******************************************************************************/ 457197104Sjkim 458197104Sjkimstatic int 459197104SjkimAslDoOptions ( 460197104Sjkim int argc, 461197104Sjkim char **argv, 462197104Sjkim BOOLEAN IsResponseFile) 463197104Sjkim{ 464197104Sjkim int j; 465197104Sjkim 466197104Sjkim 467118611Snjl /* Get the command line options */ 468118611Snjl 469197104Sjkim while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j) 470118611Snjl { 471197104Sjkim case '@': /* Begin a response file */ 472197104Sjkim 473197104Sjkim if (IsResponseFile) 474197104Sjkim { 475197104Sjkim printf ("Nested command files are not supported\n"); 476197104Sjkim return -1; 477197104Sjkim } 478197104Sjkim 479197104Sjkim if (AslDoResponseFile (AcpiGbl_Optarg)) 480197104Sjkim { 481197104Sjkim return -1; 482197104Sjkim } 483197104Sjkim break; 484197104Sjkim 485197104Sjkim 486151937Sjkim case '2': 487197104Sjkim 488151937Sjkim Gbl_Acpi2 = TRUE; 489151937Sjkim break; 490151937Sjkim 491151937Sjkim 492118611Snjl case 'b': 493118611Snjl 494118611Snjl switch (AcpiGbl_Optarg[0]) 495118611Snjl { 496118611Snjl case 'b': 497118611Snjl AslCompilerdebug = 1; /* same as yydebug */ 498118611Snjl break; 499118611Snjl 500118611Snjl case 'p': 501118611Snjl AslCompilerdebug = 1; /* same as yydebug */ 502118611Snjl break; 503118611Snjl 504118611Snjl case 't': 505118611Snjl break; 506118611Snjl 507118611Snjl default: 508118611Snjl printf ("Unknown option: -b%s\n", AcpiGbl_Optarg); 509197104Sjkim return (-1); 510118611Snjl } 511118611Snjl 512118611Snjl /* Produce debug output file */ 513118611Snjl 514118611Snjl Gbl_DebugFlag = TRUE; 515118611Snjl break; 516118611Snjl 517118611Snjl 518118611Snjl case 'c': 519207344Sjkim switch (AcpiGbl_Optarg[0]) 520207344Sjkim { 521207344Sjkim case 'r': 522207344Sjkim Gbl_NoResourceChecking = TRUE; 523207344Sjkim break; 524118611Snjl 525207344Sjkim default: 526207344Sjkim printf ("Unknown option: -c%s\n", AcpiGbl_Optarg); 527207344Sjkim return (-1); 528207344Sjkim } 529118611Snjl break; 530118611Snjl 531118611Snjl 532118611Snjl case 'd': 533118611Snjl switch (AcpiGbl_Optarg[0]) 534118611Snjl { 535118611Snjl case '^': 536193529Sjkim Gbl_DoCompile = FALSE; 537118611Snjl break; 538118611Snjl 539210976Sjkim case 'a': 540210976Sjkim Gbl_DoCompile = FALSE; 541210976Sjkim Gbl_DisassembleAll = TRUE; 542210976Sjkim break; 543210976Sjkim 544118611Snjl case 'c': 545118611Snjl break; 546118611Snjl 547118611Snjl default: 548118611Snjl printf ("Unknown option: -d%s\n", AcpiGbl_Optarg); 549197104Sjkim return (-1); 550118611Snjl } 551118611Snjl 552118611Snjl Gbl_DisasmFlag = TRUE; 553118611Snjl break; 554118611Snjl 555118611Snjl 556118611Snjl case 'e': 557210976Sjkim AcpiDmAddToExternalFileList (AcpiGbl_Optarg); 558118611Snjl break; 559118611Snjl 560118611Snjl 561118611Snjl case 'f': 562118611Snjl 563118611Snjl /* Ignore errors and force creation of aml file */ 564118611Snjl 565118611Snjl Gbl_IgnoreErrors = TRUE; 566118611Snjl break; 567118611Snjl 568118611Snjl 569118611Snjl case 'g': 570118611Snjl 571118611Snjl /* Get all ACPI tables */ 572118611Snjl 573118611Snjl Gbl_GetAllTables = TRUE; 574193529Sjkim Gbl_DoCompile = FALSE; 575118611Snjl break; 576118611Snjl 577118611Snjl 578118611Snjl case 'h': 579118611Snjl 580118611Snjl switch (AcpiGbl_Optarg[0]) 581118611Snjl { 582118611Snjl case '^': 583118611Snjl HelpMessage (); 584118611Snjl exit (0); 585118611Snjl 586118611Snjl case 'c': 587118611Snjl UtDisplayConstantOpcodes (); 588118611Snjl exit (0); 589118611Snjl 590118611Snjl case 'r': 591118611Snjl /* reserved names */ 592118611Snjl 593204773Sjkim ApDisplayReservedNames (); 594118611Snjl exit (0); 595118611Snjl 596209746Sjkim case 't': 597209746Sjkim UtDisplaySupportedTables (); 598209746Sjkim exit (0); 599209746Sjkim 600118611Snjl default: 601118611Snjl printf ("Unknown option: -h%s\n", AcpiGbl_Optarg); 602197104Sjkim return (-1); 603118611Snjl } 604118611Snjl break; 605118611Snjl 606118611Snjl 607197104Sjkim case 'I': /* Add an include file search directory */ 608197104Sjkim 609197104Sjkim FlAddIncludeDirectory (AcpiGbl_Optarg); 610197104Sjkim break; 611197104Sjkim 612197104Sjkim 613118611Snjl case 'i': 614118611Snjl 615118611Snjl switch (AcpiGbl_Optarg[0]) 616118611Snjl { 617118611Snjl case 'a': 618118611Snjl 619118611Snjl /* Produce assembly code include file */ 620118611Snjl 621118611Snjl Gbl_AsmIncludeOutputFlag = TRUE; 622118611Snjl break; 623118611Snjl 624118611Snjl case 'c': 625118611Snjl 626118611Snjl /* Produce C include file */ 627118611Snjl 628118611Snjl Gbl_C_IncludeOutputFlag = TRUE; 629118611Snjl break; 630118611Snjl 631118611Snjl default: 632118611Snjl printf ("Unknown option: -s%s\n", AcpiGbl_Optarg); 633197104Sjkim return (-1); 634118611Snjl } 635118611Snjl break; 636118611Snjl 637118611Snjl 638118611Snjl case 'l': 639118611Snjl 640118611Snjl switch (AcpiGbl_Optarg[0]) 641118611Snjl { 642118611Snjl case '^': 643118611Snjl /* Produce listing file (Mixed source/aml) */ 644118611Snjl 645118611Snjl Gbl_ListingFlag = TRUE; 646118611Snjl break; 647118611Snjl 648118611Snjl case 'n': 649118611Snjl /* Produce namespace file */ 650118611Snjl 651118611Snjl Gbl_NsOutputFlag = TRUE; 652118611Snjl break; 653118611Snjl 654118611Snjl case 's': 655118611Snjl /* Produce combined source file */ 656118611Snjl 657118611Snjl Gbl_SourceOutputFlag = TRUE; 658118611Snjl break; 659118611Snjl 660118611Snjl default: 661118611Snjl printf ("Unknown option: -l%s\n", AcpiGbl_Optarg); 662197104Sjkim return (-1); 663118611Snjl } 664118611Snjl break; 665118611Snjl 666118611Snjl 667118611Snjl case 'o': 668118611Snjl 669118611Snjl switch (AcpiGbl_Optarg[0]) 670118611Snjl { 671118611Snjl case 'a': 672118611Snjl 673118611Snjl /* Disable all optimizations */ 674118611Snjl 675118611Snjl Gbl_FoldConstants = FALSE; 676118611Snjl Gbl_IntegerOptimizationFlag = FALSE; 677118611Snjl Gbl_ReferenceOptimizationFlag = FALSE; 678118611Snjl break; 679118611Snjl 680118611Snjl case 'f': 681118611Snjl 682118611Snjl /* Disable folding on "normal" expressions */ 683118611Snjl 684118611Snjl Gbl_FoldConstants = FALSE; 685118611Snjl break; 686118611Snjl 687118611Snjl case 'i': 688118611Snjl 689118611Snjl /* Disable integer optimization to constants */ 690118611Snjl 691118611Snjl Gbl_IntegerOptimizationFlag = FALSE; 692118611Snjl break; 693118611Snjl 694118611Snjl case 'n': 695118611Snjl 696118611Snjl /* Disable named reference optimization */ 697118611Snjl 698118611Snjl Gbl_ReferenceOptimizationFlag = FALSE; 699118611Snjl break; 700118611Snjl 701118611Snjl case 't': 702118611Snjl 703118611Snjl /* Display compile time(s) */ 704118611Snjl 705118611Snjl Gbl_CompileTimesFlag = TRUE; 706118611Snjl break; 707118611Snjl 708118611Snjl default: 709118611Snjl printf ("Unknown option: -c%s\n", AcpiGbl_Optarg); 710197104Sjkim return (-1); 711118611Snjl } 712118611Snjl break; 713118611Snjl 714118611Snjl 715207344Sjkim case 'n': 716207344Sjkim 717207344Sjkim /* Parse only */ 718207344Sjkim 719207344Sjkim Gbl_ParseOnlyFlag = TRUE; 720207344Sjkim break; 721207344Sjkim 722207344Sjkim 723118611Snjl case 'p': 724118611Snjl 725118611Snjl /* Override default AML output filename */ 726118611Snjl 727118611Snjl Gbl_OutputFilenamePrefix = AcpiGbl_Optarg; 728118611Snjl Gbl_UseDefaultAmlFilename = FALSE; 729118611Snjl break; 730118611Snjl 731118611Snjl 732118611Snjl case 'r': 733138287Smarks Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0); 734118611Snjl break; 735118611Snjl 736118611Snjl 737118611Snjl case 's': 738118611Snjl 739118611Snjl switch (AcpiGbl_Optarg[0]) 740118611Snjl { 741118611Snjl case 'a': 742118611Snjl 743118611Snjl /* Produce assembly code output file */ 744118611Snjl 745118611Snjl Gbl_AsmOutputFlag = TRUE; 746118611Snjl break; 747118611Snjl 748118611Snjl case 'c': 749118611Snjl 750118611Snjl /* Produce C hex output file */ 751118611Snjl 752118611Snjl Gbl_C_OutputFlag = TRUE; 753118611Snjl break; 754118611Snjl 755118611Snjl default: 756118611Snjl printf ("Unknown option: -s%s\n", AcpiGbl_Optarg); 757197104Sjkim return (-1); 758118611Snjl } 759118611Snjl break; 760118611Snjl 761118611Snjl 762118611Snjl case 't': 763118611Snjl 764118611Snjl /* Produce hex table output file */ 765118611Snjl 766118611Snjl switch (AcpiGbl_Optarg[0]) 767118611Snjl { 768118611Snjl case 'a': 769118611Snjl Gbl_HexOutputFlag = HEX_OUTPUT_ASM; 770118611Snjl break; 771118611Snjl 772118611Snjl case 'c': 773118611Snjl Gbl_HexOutputFlag = HEX_OUTPUT_C; 774118611Snjl break; 775118611Snjl 776207344Sjkim case 's': 777207344Sjkim Gbl_HexOutputFlag = HEX_OUTPUT_ASL; 778207344Sjkim break; 779207344Sjkim 780118611Snjl default: 781118611Snjl printf ("Unknown option: -t%s\n", AcpiGbl_Optarg); 782197104Sjkim return (-1); 783118611Snjl } 784118611Snjl break; 785118611Snjl 786118611Snjl 787209746Sjkim case 'T': 788209746Sjkim Gbl_DoTemplates = TRUE; 789209746Sjkim Gbl_TemplateSignature = AcpiGbl_Optarg; 790209746Sjkim break; 791209746Sjkim 792209746Sjkim 793118611Snjl case 'v': 794118611Snjl 795118611Snjl switch (AcpiGbl_Optarg[0]) 796118611Snjl { 797193529Sjkim case 'a': 798193529Sjkim /* Disable All error/warning messages */ 799193529Sjkim 800193529Sjkim Gbl_NoErrors = TRUE; 801193529Sjkim break; 802193529Sjkim 803118611Snjl case 'i': 804118611Snjl /* Less verbose error messages */ 805118611Snjl 806118611Snjl Gbl_VerboseErrors = FALSE; 807118611Snjl break; 808118611Snjl 809118611Snjl case 'o': 810118611Snjl Gbl_DisplayOptimizations = TRUE; 811118611Snjl break; 812118611Snjl 813118611Snjl case 'r': 814118611Snjl Gbl_DisplayRemarks = FALSE; 815118611Snjl break; 816118611Snjl 817118611Snjl case 's': 818193529Sjkim Gbl_DoSignon = FALSE; 819118611Snjl break; 820118611Snjl 821209746Sjkim case 't': 822209746Sjkim Gbl_VerboseTemplates = TRUE; 823209746Sjkim break; 824209746Sjkim 825118611Snjl default: 826118611Snjl printf ("Unknown option: -v%s\n", AcpiGbl_Optarg); 827197104Sjkim return (-1); 828118611Snjl } 829118611Snjl break; 830118611Snjl 831118611Snjl 832167802Sjkim case 'w': /* Set warning levels */ 833167802Sjkim 834167802Sjkim switch (AcpiGbl_Optarg[0]) 835167802Sjkim { 836167802Sjkim case '1': 837167802Sjkim Gbl_WarningLevel = ASL_WARNING; 838167802Sjkim break; 839167802Sjkim 840167802Sjkim case '2': 841167802Sjkim Gbl_WarningLevel = ASL_WARNING2; 842167802Sjkim break; 843167802Sjkim 844167802Sjkim case '3': 845167802Sjkim Gbl_WarningLevel = ASL_WARNING3; 846167802Sjkim break; 847167802Sjkim 848167802Sjkim default: 849167802Sjkim printf ("Unknown option: -w%s\n", AcpiGbl_Optarg); 850197104Sjkim return (-1); 851167802Sjkim } 852167802Sjkim break; 853167802Sjkim 854167802Sjkim 855118611Snjl case 'x': 856118611Snjl 857118611Snjl AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16); 858118611Snjl break; 859118611Snjl 860118611Snjl 861209746Sjkim case 'z': 862209746Sjkim 863209746Sjkim Gbl_UseOriginalCompilerId = TRUE; 864209746Sjkim break; 865209746Sjkim 866209746Sjkim 867118611Snjl default: 868118611Snjl 869197104Sjkim return (-1); 870118611Snjl } 871118611Snjl 872197104Sjkim return (0); 873197104Sjkim} 874197104Sjkim 875197104Sjkim 876197104Sjkim/******************************************************************************* 877197104Sjkim * 878197104Sjkim * FUNCTION: AslCommandLine 879197104Sjkim * 880197104Sjkim * PARAMETERS: argc/argv 881197104Sjkim * 882197104Sjkim * RETURN: Last argv index 883197104Sjkim * 884197104Sjkim * DESCRIPTION: Command line processing 885197104Sjkim * 886197104Sjkim ******************************************************************************/ 887197104Sjkim 888197104Sjkimstatic int 889197104SjkimAslCommandLine ( 890197104Sjkim int argc, 891197104Sjkim char **argv) 892197104Sjkim{ 893197104Sjkim int BadCommandLine = 0; 894197104Sjkim 895197104Sjkim 896197104Sjkim /* Minimum command line contains at least the command and an input file */ 897197104Sjkim 898197104Sjkim if (argc < 2) 899197104Sjkim { 900197104Sjkim AslCompilerSignon (ASL_FILE_STDOUT); 901197104Sjkim Usage (); 902197104Sjkim exit (1); 903197104Sjkim } 904197104Sjkim 905197104Sjkim /* Process all command line options */ 906197104Sjkim 907197104Sjkim BadCommandLine = AslDoOptions (argc, argv, FALSE); 908197104Sjkim 909209746Sjkim if (Gbl_DoTemplates) 910209746Sjkim { 911209746Sjkim DtCreateTemplates (Gbl_TemplateSignature); 912209746Sjkim exit (1); 913209746Sjkim } 914209746Sjkim 915118611Snjl /* Next parameter must be the input filename */ 916118611Snjl 917193529Sjkim if (!argv[AcpiGbl_Optind] && 918151937Sjkim !Gbl_DisasmFlag && 919151937Sjkim !Gbl_GetAllTables) 920118611Snjl { 921118611Snjl printf ("Missing input filename\n"); 922118611Snjl BadCommandLine = TRUE; 923118611Snjl } 924118611Snjl 925193529Sjkim if (Gbl_DoSignon) 926118611Snjl { 927118611Snjl AslCompilerSignon (ASL_FILE_STDOUT); 928118611Snjl } 929118611Snjl 930118611Snjl /* Abort if anything went wrong on the command line */ 931118611Snjl 932118611Snjl if (BadCommandLine) 933118611Snjl { 934118611Snjl printf ("\n"); 935118611Snjl Usage (); 936118611Snjl exit (1); 937118611Snjl } 938118611Snjl 939193529Sjkim return (AcpiGbl_Optind); 940118611Snjl} 941118611Snjl 942118611Snjl 943118611Snjl/******************************************************************************* 944118611Snjl * 945118611Snjl * FUNCTION: main 946118611Snjl * 947118611Snjl * PARAMETERS: Standard argc/argv 948118611Snjl * 949118611Snjl * RETURN: Program termination code 950118611Snjl * 951193529Sjkim * DESCRIPTION: C main routine for the Asl Compiler. Handle command line 952193529Sjkim * options and begin the compile for each file on the command line 953118611Snjl * 954118611Snjl ******************************************************************************/ 955118611Snjl 956118611Snjlint ACPI_SYSTEM_XFACE 957118611Snjlmain ( 958118611Snjl int argc, 959118611Snjl char **argv) 960118611Snjl{ 961118611Snjl ACPI_STATUS Status; 962210976Sjkim int Index1; 963210976Sjkim int Index2; 964118611Snjl 965118611Snjl 966210976Sjkim AcpiGbl_ExternalFileList = NULL; 967210976Sjkim 968151937Sjkim#ifdef _DEBUG 969151937Sjkim _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF | 970151937Sjkim _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG)); 971151937Sjkim#endif 972151937Sjkim 973118611Snjl /* Init and command line */ 974118611Snjl 975118611Snjl AslInitialize (); 976210976Sjkim Index1 = Index2 = AslCommandLine (argc, argv); 977118611Snjl 978193529Sjkim /* Options that have no additional parameters or pathnames */ 979118611Snjl 980193529Sjkim if (Gbl_GetAllTables) 981118611Snjl { 982193529Sjkim Status = AslDoOneFile (NULL); 983118611Snjl if (ACPI_FAILURE (Status)) 984118611Snjl { 985193529Sjkim return (-1); 986118611Snjl } 987193529Sjkim return (0); 988193529Sjkim } 989118611Snjl 990210976Sjkim if (Gbl_DisassembleAll) 991210976Sjkim { 992210976Sjkim while (argv[Index1]) 993210976Sjkim { 994210976Sjkim Status = AslDoOnePathname (argv[Index1], AcpiDmAddToExternalFileList); 995210976Sjkim if (ACPI_FAILURE (Status)) 996210976Sjkim { 997210976Sjkim return (-1); 998210976Sjkim } 999210976Sjkim 1000210976Sjkim Index1++; 1001210976Sjkim } 1002210976Sjkim } 1003210976Sjkim 1004193529Sjkim /* Process each pathname/filename in the list, with possible wildcards */ 1005118611Snjl 1006210976Sjkim while (argv[Index2]) 1007118611Snjl { 1008210976Sjkim Status = AslDoOnePathname (argv[Index2], AslDoOneFile); 1009151937Sjkim if (ACPI_FAILURE (Status)) 1010151937Sjkim { 1011193529Sjkim return (-1); 1012151937Sjkim } 1013118611Snjl 1014210976Sjkim Index2++; 1015118611Snjl } 1016118611Snjl 1017210976Sjkim if (AcpiGbl_ExternalFileList) 1018210976Sjkim { 1019210976Sjkim AcpiDmClearExternalFileList(); 1020210976Sjkim } 1021210976Sjkim 1022118611Snjl return (0); 1023118611Snjl} 1024118611Snjl 1025118611Snjl 1026