aslmain.c revision 228110
1290001Sglebius 2290001Sglebius/****************************************************************************** 3290001Sglebius * 4290001Sglebius * Module Name: aslmain - compiler main and utilities 5290001Sglebius * 6290001Sglebius *****************************************************************************/ 7290001Sglebius 8290001Sglebius/* 9290001Sglebius * Copyright (C) 2000 - 2011, Intel Corp. 10290001Sglebius * All rights reserved. 11290001Sglebius * 12290001Sglebius * Redistribution and use in source and binary forms, with or without 13290001Sglebius * modification, are permitted provided that the following conditions 14290001Sglebius * are met: 15290001Sglebius * 1. Redistributions of source code must retain the above copyright 16290001Sglebius * notice, this list of conditions, and the following disclaimer, 17290001Sglebius * without modification. 18290001Sglebius * 2. Redistributions in binary form must reproduce at minimum a disclaimer 19290001Sglebius * substantially similar to the "NO WARRANTY" disclaimer below 20290001Sglebius * ("Disclaimer") and any redistribution must be conditioned upon 21290001Sglebius * including a substantially similar Disclaimer requirement for further 22290001Sglebius * binary redistribution. 23290001Sglebius * 3. Neither the names of the above-listed copyright holders nor the names 24290001Sglebius * of any contributors may be used to endorse or promote products derived 25290001Sglebius * from this software without specific prior written permission. 26290001Sglebius * 27290001Sglebius * Alternatively, this software may be distributed under the terms of the 28290001Sglebius * GNU General Public License ("GPL") version 2 as published by the Free 29290001Sglebius * Software Foundation. 30290001Sglebius * 31290001Sglebius * NO WARRANTY 32290001Sglebius * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 33290001Sglebius * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34290001Sglebius * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 35290001Sglebius * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 36290001Sglebius * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 37290001Sglebius * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 38290001Sglebius * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 39290001Sglebius * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 40290001Sglebius * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 41290001Sglebius * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 42290001Sglebius * POSSIBILITY OF SUCH DAMAGES. 43290001Sglebius */ 44290001Sglebius 45290001Sglebius 46290001Sglebius#define _DECLARE_GLOBALS 47290001Sglebius 48290001Sglebius#include <contrib/dev/acpica/compiler/aslcompiler.h> 49290001Sglebius#include <contrib/dev/acpica/include/acapps.h> 50290001Sglebius#include <contrib/dev/acpica/include/acdisasm.h> 51290001Sglebius 52290001Sglebius#ifdef _DEBUG 53290001Sglebius#include <crtdbg.h> 54290001Sglebius#endif 55290001Sglebius 56290001Sglebius#define _COMPONENT ACPI_COMPILER 57290001Sglebius ACPI_MODULE_NAME ("aslmain") 58290001Sglebius 59290001Sglebius/* Local prototypes */ 60290001Sglebius 61290001Sglebiusstatic void 62290001SglebiusOptions ( 63290001Sglebius void); 64290001Sglebius 65290001Sglebiusstatic void 66290001SglebiusHelpMessage ( 67290001Sglebius void); 68290001Sglebius 69290001Sglebiusstatic void 70290001SglebiusUsage ( 71290001Sglebius void); 72290001Sglebius 73290001Sglebiusstatic void 74290001SglebiusAslInitialize ( 75290001Sglebius void); 76290001Sglebius 77290001Sglebiusstatic int 78290001SglebiusAslCommandLine ( 79290001Sglebius int argc, 80290001Sglebius char **argv); 81290001Sglebius 82290001Sglebiusstatic int 83290001SglebiusAslDoOptions ( 84290001Sglebius int argc, 85290001Sglebius char **argv, 86290001Sglebius BOOLEAN IsResponseFile); 87290001Sglebius 88290001Sglebiusstatic void 89290001SglebiusAslMergeOptionTokens ( 90290001Sglebius char *InBuffer, 91290001Sglebius char *OutBuffer); 92290001Sglebius 93290001Sglebiusstatic int 94290001SglebiusAslDoResponseFile ( 95290001Sglebius char *Filename); 96290001Sglebius 97290001Sglebius 98290001Sglebius#define ASL_TOKEN_SEPARATORS " \t\n" 99290001Sglebius#define ASL_SUPPORTED_OPTIONS "@:2b:c:d^e:fgh^i^I:l^mno:p:r:s:t:T:G^v:w:x:z" 100290001Sglebius 101290001Sglebius 102290001Sglebius/******************************************************************************* 103290001Sglebius * 104290001Sglebius * FUNCTION: Options 105290001Sglebius * 106290001Sglebius * PARAMETERS: None 107290001Sglebius * 108290001Sglebius * RETURN: None 109290001Sglebius * 110290001Sglebius * DESCRIPTION: Display option help message 111290001Sglebius * 112290001Sglebius ******************************************************************************/ 113290001Sglebius 114290001Sglebiusstatic void 115290001SglebiusOptions ( 116290001Sglebius void) 117290001Sglebius{ 118290001Sglebius 119290001Sglebius printf ("\nGlobal:\n"); 120290001Sglebius ACPI_OPTION ("-@ <file>", "Specify command file"); 121290001Sglebius ACPI_OPTION ("-I <dir>", "Specify additional include directory"); 122290001Sglebius 123290001Sglebius printf ("\nGeneral Output:\n"); 124290001Sglebius ACPI_OPTION ("-p <prefix>", "Specify path/filename prefix for all output files"); 125290001Sglebius ACPI_OPTION ("-va", "Disable all errors and warnings (summary only)"); 126290001Sglebius ACPI_OPTION ("-vi", "Less verbose errors and warnings for use with IDEs"); 127290001Sglebius ACPI_OPTION ("-vo", "Enable optimization comments"); 128290001Sglebius ACPI_OPTION ("-vr", "Disable remarks"); 129290001Sglebius ACPI_OPTION ("-vs", "Disable signon"); 130290001Sglebius ACPI_OPTION ("-w <1|2|3>", "Set warning reporting level"); 131290001Sglebius 132290001Sglebius printf ("\nAML Output Files:\n"); 133290001Sglebius ACPI_OPTION ("-s <a|c>", "Create AML in assembler or C source file (*.asm or *.c)"); 134290001Sglebius ACPI_OPTION ("-i <a|c>", "Create assembler or C include file (*.inc or *.h)"); 135290001Sglebius ACPI_OPTION ("-t <a|c|s>", "Create AML in assembler, C, or ASL hex table (*.hex)"); 136290001Sglebius 137290001Sglebius printf ("\nAML Code Generation:\n"); 138290001Sglebius ACPI_OPTION ("-oa", "Disable all optimizations (compatibility mode)"); 139290001Sglebius ACPI_OPTION ("-of", "Disable constant folding"); 140290001Sglebius ACPI_OPTION ("-oi", "Disable integer optimization to Zero/One/Ones"); 141290001Sglebius ACPI_OPTION ("-on", "Disable named reference string optimization"); 142290001Sglebius ACPI_OPTION ("-cr", "Disable Resource Descriptor error checking"); 143290001Sglebius ACPI_OPTION ("-r <revision>", "Override table header Revision (1-255)"); 144290001Sglebius 145290001Sglebius printf ("\nASL Listing Files:\n"); 146290001Sglebius ACPI_OPTION ("-l", "Create mixed listing file (ASL source and AML) (*.lst)"); 147290001Sglebius ACPI_OPTION ("-ln", "Create namespace file (*.nsp)"); 148290001Sglebius ACPI_OPTION ("-ls", "Create combined source file (expanded includes) (*.src)"); 149290001Sglebius 150290001Sglebius printf ("\nACPI Data Tables:\n"); 151290001Sglebius ACPI_OPTION ("-G", "Compile custom table containing generic operators"); 152290001Sglebius ACPI_OPTION ("-T <sig>|ALL|*", "Create table template file(s) for <Sig>"); 153290001Sglebius ACPI_OPTION ("-vt", "Create verbose templates (full disassembly)"); 154290001Sglebius 155290001Sglebius printf ("\nAML Disassembler:\n"); 156290001Sglebius ACPI_OPTION ("-d [file]", "Disassemble or decode binary ACPI table to file (*.dsl)"); 157290001Sglebius ACPI_OPTION ("-da [f1,f2]", "Disassemble multiple tables from single namespace"); 158290001Sglebius ACPI_OPTION ("-dc [file]", "Disassemble AML and immediately compile it"); 159290001Sglebius ACPI_OPTION ("", "(Obtain DSDT from current system if no input file)"); 160290001Sglebius ACPI_OPTION ("-e [f1,f2]", "Include ACPI table(s) for external symbol resolution"); 161290001Sglebius ACPI_OPTION ("-m", "Do not translate Buffers to Resource Templates"); 162290001Sglebius ACPI_OPTION ("-2", "Emit ACPI 2.0 compatible ASL code"); 163290001Sglebius ACPI_OPTION ("-g", "Get ACPI tables and write to files (*.dat)"); 164290001Sglebius 165290001Sglebius printf ("\nHelp:\n"); 166290001Sglebius ACPI_OPTION ("-h", "Additional help and compiler debug options"); 167290001Sglebius ACPI_OPTION ("-hc", "Display operators allowed in constant expressions"); 168290001Sglebius ACPI_OPTION ("-hr", "Display ACPI reserved method names"); 169290001Sglebius ACPI_OPTION ("-ht", "Display currently supported ACPI table names"); 170290001Sglebius} 171290001Sglebius 172290001Sglebius 173290001Sglebius/******************************************************************************* 174290001Sglebius * 175290001Sglebius * FUNCTION: HelpMessage 176290001Sglebius * 177290001Sglebius * PARAMETERS: None 178290001Sglebius * 179290001Sglebius * RETURN: None 180290001Sglebius * 181290001Sglebius * DESCRIPTION: Display help message 182290001Sglebius * 183290001Sglebius ******************************************************************************/ 184290001Sglebius 185290001Sglebiusstatic void 186290001SglebiusHelpMessage ( 187290001Sglebius void) 188290001Sglebius{ 189290001Sglebius 190290001Sglebius printf ("\nAML output filename generation:\n"); 191290001Sglebius printf (" Output filenames are generated by appending an extension to a common\n"); 192290001Sglebius printf (" filename prefix. The filename prefix is obtained via one of the\n"); 193290001Sglebius printf (" following methods (in priority order):\n"); 194290001Sglebius printf (" 1) The -p option specifies the prefix\n"); 195290001Sglebius printf (" 2) The prefix of the AMLFileName in the ASL Definition Block\n"); 196290001Sglebius printf (" 3) The prefix of the input filename\n"); 197290001Sglebius printf ("\n"); 198290001Sglebius 199290001Sglebius Options (); 200290001Sglebius 201290001Sglebius printf ("\nCompiler/Disassembler Debug Options:\n"); 202290001Sglebius ACPI_OPTION ("-b<p|t|b>", "Create compiler debug/trace file (*.txt)"); 203290001Sglebius ACPI_OPTION ("", "Types: Parse/Tree/Both"); 204290001Sglebius ACPI_OPTION ("-f", "Ignore errors, force creation of AML output file(s)"); 205290001Sglebius ACPI_OPTION ("-n", "Parse only, no output generation"); 206290001Sglebius ACPI_OPTION ("-ot", "Display compile times"); 207290001Sglebius ACPI_OPTION ("-x<level>", "Set debug level for trace output"); 208290001Sglebius ACPI_OPTION ("-z", "Do not insert new compiler ID for DataTables"); 209290001Sglebius} 210290001Sglebius 211290001Sglebius 212290001Sglebius/******************************************************************************* 213290001Sglebius * 214290001Sglebius * FUNCTION: Usage 215290001Sglebius * 216290001Sglebius * PARAMETERS: None 217290001Sglebius * 218290001Sglebius * RETURN: None 219290001Sglebius * 220290001Sglebius * DESCRIPTION: Display usage and option message 221290001Sglebius * 222290001Sglebius ******************************************************************************/ 223290001Sglebius 224290001Sglebiusstatic void 225290001SglebiusUsage ( 226290001Sglebius void) 227290001Sglebius{ 228290001Sglebius 229290001Sglebius printf ("%s\n\n", ASL_COMPLIANCE); 230290001Sglebius ACPI_USAGE_HEADER ("iasl [Options] [Files]"); 231290001Sglebius Options (); 232290001Sglebius} 233290001Sglebius 234290001Sglebius 235290001Sglebius/******************************************************************************* 236290001Sglebius * 237290001Sglebius * FUNCTION: AslInitialize 238290001Sglebius * 239290001Sglebius * PARAMETERS: None 240290001Sglebius * 241290001Sglebius * RETURN: None 242290001Sglebius * 243290001Sglebius * DESCRIPTION: Initialize compiler globals 244290001Sglebius * 245290001Sglebius ******************************************************************************/ 246290001Sglebius 247290001Sglebiusstatic void 248290001SglebiusAslInitialize ( 249290001Sglebius void) 250290001Sglebius{ 251290001Sglebius UINT32 i; 252290001Sglebius 253290001Sglebius 254290001Sglebius#ifdef _DEBUG 255290001Sglebius _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0)); 256290001Sglebius#endif 257290001Sglebius 258290001Sglebius AcpiDbgLevel = 0; 259290001Sglebius 260290001Sglebius for (i = 0; i < ASL_NUM_FILES; i++) 261290001Sglebius { 262290001Sglebius Gbl_Files[i].Handle = NULL; 263290001Sglebius Gbl_Files[i].Filename = NULL; 264290001Sglebius } 265290001Sglebius 266290001Sglebius Gbl_Files[ASL_FILE_STDOUT].Handle = stdout; 267290001Sglebius Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT"; 268290001Sglebius 269290001Sglebius Gbl_Files[ASL_FILE_STDERR].Handle = stderr; 270290001Sglebius Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR"; 271290001Sglebius} 272290001Sglebius 273290001Sglebius 274290001Sglebius/******************************************************************************* 275290001Sglebius * 276290001Sglebius * FUNCTION: AslMergeOptionTokens 277290001Sglebius * 278290001Sglebius * PARAMETERS: InBuffer - Input containing an option string 279290001Sglebius * OutBuffer - Merged output buffer 280290001Sglebius * 281290001Sglebius * RETURN: None 282290001Sglebius * 283290001Sglebius * DESCRIPTION: Remove all whitespace from an option string. 284290001Sglebius * 285290001Sglebius ******************************************************************************/ 286290001Sglebius 287290001Sglebiusstatic void 288290001SglebiusAslMergeOptionTokens ( 289290001Sglebius char *InBuffer, 290290001Sglebius char *OutBuffer) 291290001Sglebius{ 292290001Sglebius char *Token; 293290001Sglebius 294290001Sglebius 295290001Sglebius *OutBuffer = 0; 296290001Sglebius 297290001Sglebius Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS); 298290001Sglebius while (Token) 299290001Sglebius { 300290001Sglebius strcat (OutBuffer, Token); 301290001Sglebius Token = strtok (NULL, ASL_TOKEN_SEPARATORS); 302290001Sglebius } 303290001Sglebius} 304290001Sglebius 305290001Sglebius 306290001Sglebius/******************************************************************************* 307290001Sglebius * 308290001Sglebius * FUNCTION: AslDoResponseFile 309290001Sglebius * 310290001Sglebius * PARAMETERS: Filename - Name of the response file 311290001Sglebius * 312290001Sglebius * RETURN: Status 313290001Sglebius * 314290001Sglebius * DESCRIPTION: Open a response file and process all options within. 315290001Sglebius * 316290001Sglebius ******************************************************************************/ 317290001Sglebius 318290001Sglebiusstatic int 319290001SglebiusAslDoResponseFile ( 320290001Sglebius char *Filename) 321290001Sglebius{ 322290001Sglebius char *argv = StringBuffer2; 323290001Sglebius FILE *ResponseFile; 324290001Sglebius int OptStatus = 0; 325290001Sglebius int Opterr; 326290001Sglebius int Optind; 327290001Sglebius 328290001Sglebius 329290001Sglebius ResponseFile = fopen (Filename, "r"); 330290001Sglebius if (!ResponseFile) 331290001Sglebius { 332290001Sglebius printf ("Could not open command file %s, %s\n", 333290001Sglebius Filename, strerror (errno)); 334290001Sglebius return -1; 335290001Sglebius } 336290001Sglebius 337290001Sglebius /* Must save the current GetOpt globals */ 338290001Sglebius 339290001Sglebius Opterr = AcpiGbl_Opterr; 340290001Sglebius Optind = AcpiGbl_Optind; 341290001Sglebius 342290001Sglebius /* 343290001Sglebius * Process all lines in the response file. There must be one complete 344290001Sglebius * option per line 345290001Sglebius */ 346290001Sglebius while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile)) 347290001Sglebius { 348290001Sglebius /* Compress all tokens, allowing us to use a single argv entry */ 349290001Sglebius 350290001Sglebius AslMergeOptionTokens (StringBuffer, StringBuffer2); 351290001Sglebius 352290001Sglebius /* Process the option */ 353290001Sglebius 354290001Sglebius AcpiGbl_Opterr = 0; 355290001Sglebius AcpiGbl_Optind = 0; 356290001Sglebius 357290001Sglebius OptStatus = AslDoOptions (1, &argv, TRUE); 358290001Sglebius if (OptStatus) 359290001Sglebius { 360290001Sglebius printf ("Invalid option in command file %s: %s\n", 361290001Sglebius Filename, StringBuffer); 362290001Sglebius break; 363290001Sglebius } 364290001Sglebius } 365290001Sglebius 366290001Sglebius /* Restore the GetOpt globals */ 367290001Sglebius 368290001Sglebius AcpiGbl_Opterr = Opterr; 369290001Sglebius AcpiGbl_Optind = Optind; 370290001Sglebius 371290001Sglebius fclose (ResponseFile); 372290001Sglebius return (OptStatus); 373290001Sglebius} 374290001Sglebius 375290001Sglebius 376290001Sglebius/******************************************************************************* 377290001Sglebius * 378290001Sglebius * FUNCTION: AslDoOptions 379290001Sglebius * 380290001Sglebius * PARAMETERS: argc/argv - Standard argc/argv 381290001Sglebius * IsResponseFile - TRUE if executing a response file. 382290001Sglebius * 383290001Sglebius * RETURN: Status 384290001Sglebius * 385290001Sglebius * DESCRIPTION: Command line option processing 386290001Sglebius * 387290001Sglebius ******************************************************************************/ 388290001Sglebius 389290001Sglebiusstatic int 390290001SglebiusAslDoOptions ( 391290001Sglebius int argc, 392290001Sglebius char **argv, 393290001Sglebius BOOLEAN IsResponseFile) 394290001Sglebius{ 395290001Sglebius int j; 396290001Sglebius ACPI_STATUS Status; 397290001Sglebius 398290001Sglebius 399290001Sglebius /* Get the command line options */ 400290001Sglebius 401290001Sglebius while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j) 402290001Sglebius { 403290001Sglebius case '@': /* Begin a response file */ 404290001Sglebius 405290001Sglebius if (IsResponseFile) 406290001Sglebius { 407290001Sglebius printf ("Nested command files are not supported\n"); 408290001Sglebius return -1; 409290001Sglebius } 410290001Sglebius 411290001Sglebius if (AslDoResponseFile (AcpiGbl_Optarg)) 412290001Sglebius { 413290001Sglebius return -1; 414290001Sglebius } 415290001Sglebius break; 416290001Sglebius 417290001Sglebius 418290001Sglebius case '2': 419290001Sglebius 420290001Sglebius Gbl_Acpi2 = TRUE; 421290001Sglebius break; 422290001Sglebius 423290001Sglebius 424290001Sglebius case 'b': 425290001Sglebius 426290001Sglebius switch (AcpiGbl_Optarg[0]) 427290001Sglebius { 428290001Sglebius case 'b': 429290001Sglebius AslCompilerdebug = 1; /* same as yydebug */ 430290001Sglebius DtParserdebug = 1; 431290001Sglebius break; 432290001Sglebius 433290001Sglebius case 'p': 434290001Sglebius AslCompilerdebug = 1; /* same as yydebug */ 435290001Sglebius DtParserdebug = 1; 436290001Sglebius break; 437290001Sglebius 438290001Sglebius case 't': 439290001Sglebius break; 440290001Sglebius 441290001Sglebius default: 442290001Sglebius printf ("Unknown option: -b%s\n", AcpiGbl_Optarg); 443290001Sglebius return (-1); 444290001Sglebius } 445290001Sglebius 446290001Sglebius /* Produce debug output file */ 447290001Sglebius 448290001Sglebius Gbl_DebugFlag = TRUE; 449290001Sglebius break; 450290001Sglebius 451290001Sglebius 452290001Sglebius case 'c': 453290001Sglebius switch (AcpiGbl_Optarg[0]) 454290001Sglebius { 455290001Sglebius case 'r': 456290001Sglebius Gbl_NoResourceChecking = TRUE; 457290001Sglebius break; 458290001Sglebius 459290001Sglebius default: 460290001Sglebius printf ("Unknown option: -c%s\n", AcpiGbl_Optarg); 461290001Sglebius return (-1); 462290001Sglebius } 463290001Sglebius break; 464290001Sglebius 465290001Sglebius 466290001Sglebius case 'd': 467290001Sglebius switch (AcpiGbl_Optarg[0]) 468290001Sglebius { 469290001Sglebius case '^': 470290001Sglebius Gbl_DoCompile = FALSE; 471290001Sglebius break; 472290001Sglebius 473290001Sglebius case 'a': 474290001Sglebius Gbl_DoCompile = FALSE; 475290001Sglebius Gbl_DisassembleAll = TRUE; 476290001Sglebius break; 477290001Sglebius 478290001Sglebius case 'c': 479290001Sglebius break; 480290001Sglebius 481290001Sglebius default: 482290001Sglebius printf ("Unknown option: -d%s\n", AcpiGbl_Optarg); 483290001Sglebius return (-1); 484290001Sglebius } 485290001Sglebius 486290001Sglebius Gbl_DisasmFlag = TRUE; 487290001Sglebius break; 488290001Sglebius 489290001Sglebius 490290001Sglebius case 'e': 491290001Sglebius Status = AcpiDmAddToExternalFileList (AcpiGbl_Optarg); 492290001Sglebius if (ACPI_FAILURE (Status)) 493290001Sglebius { 494290001Sglebius printf ("Could not add %s to external list\n", AcpiGbl_Optarg); 495290001Sglebius return (-1); 496290001Sglebius } 497290001Sglebius break; 498290001Sglebius 499290001Sglebius 500290001Sglebius case 'f': 501290001Sglebius 502290001Sglebius /* Ignore errors and force creation of aml file */ 503290001Sglebius 504290001Sglebius Gbl_IgnoreErrors = TRUE; 505290001Sglebius break; 506290001Sglebius 507290001Sglebius 508290001Sglebius case 'g': 509290001Sglebius 510290001Sglebius /* Get all ACPI tables */ 511290001Sglebius 512290001Sglebius Gbl_GetAllTables = TRUE; 513290001Sglebius Gbl_DoCompile = FALSE; 514290001Sglebius break; 515290001Sglebius 516290001Sglebius 517290001Sglebius case 'h': 518290001Sglebius 519290001Sglebius switch (AcpiGbl_Optarg[0]) 520290001Sglebius { 521290001Sglebius case '^': 522290001Sglebius HelpMessage (); 523290001Sglebius exit (0); 524290001Sglebius 525290001Sglebius case 'c': 526290001Sglebius UtDisplayConstantOpcodes (); 527290001Sglebius exit (0); 528290001Sglebius 529290001Sglebius case 'r': 530290001Sglebius /* reserved names */ 531290001Sglebius 532290001Sglebius ApDisplayReservedNames (); 533290001Sglebius exit (0); 534290001Sglebius 535290001Sglebius case 't': 536290001Sglebius UtDisplaySupportedTables (); 537290001Sglebius exit (0); 538290001Sglebius 539290001Sglebius default: 540290001Sglebius printf ("Unknown option: -h%s\n", AcpiGbl_Optarg); 541290001Sglebius return (-1); 542290001Sglebius } 543290001Sglebius 544290001Sglebius 545290001Sglebius case 'I': /* Add an include file search directory */ 546290001Sglebius 547290001Sglebius FlAddIncludeDirectory (AcpiGbl_Optarg); 548290001Sglebius break; 549290001Sglebius 550290001Sglebius 551290001Sglebius case 'i': 552290001Sglebius 553290001Sglebius switch (AcpiGbl_Optarg[0]) 554290001Sglebius { 555290001Sglebius case 'a': 556290001Sglebius 557290001Sglebius /* Produce assembly code include file */ 558290001Sglebius 559290001Sglebius Gbl_AsmIncludeOutputFlag = TRUE; 560290001Sglebius break; 561290001Sglebius 562290001Sglebius case 'c': 563290001Sglebius 564290001Sglebius /* Produce C include file */ 565290001Sglebius 566290001Sglebius Gbl_C_IncludeOutputFlag = TRUE; 567290001Sglebius break; 568290001Sglebius 569290001Sglebius default: 570290001Sglebius printf ("Unknown option: -s%s\n", AcpiGbl_Optarg); 571290001Sglebius return (-1); 572290001Sglebius } 573290001Sglebius break; 574290001Sglebius 575290001Sglebius 576290001Sglebius case 'l': 577290001Sglebius 578290001Sglebius switch (AcpiGbl_Optarg[0]) 579290001Sglebius { 580290001Sglebius case '^': 581290001Sglebius /* Produce listing file (Mixed source/aml) */ 582290001Sglebius 583290001Sglebius Gbl_ListingFlag = TRUE; 584290001Sglebius break; 585290001Sglebius 586290001Sglebius case 'n': 587290001Sglebius /* Produce namespace file */ 588290001Sglebius 589290001Sglebius Gbl_NsOutputFlag = TRUE; 590290001Sglebius break; 591290001Sglebius 592290001Sglebius case 's': 593290001Sglebius /* Produce combined source file */ 594290001Sglebius 595290001Sglebius Gbl_SourceOutputFlag = TRUE; 596290001Sglebius break; 597290001Sglebius 598290001Sglebius default: 599290001Sglebius printf ("Unknown option: -l%s\n", AcpiGbl_Optarg); 600290001Sglebius return (-1); 601290001Sglebius } 602290001Sglebius break; 603290001Sglebius 604290001Sglebius 605290001Sglebius case 'm': 606290001Sglebius 607290001Sglebius AcpiGbl_NoResourceDisassembly = TRUE; 608290001Sglebius break; 609290001Sglebius 610290001Sglebius 611290001Sglebius case 'n': 612290001Sglebius 613290001Sglebius /* Parse only */ 614290001Sglebius 615290001Sglebius Gbl_ParseOnlyFlag = TRUE; 616290001Sglebius break; 617290001Sglebius 618290001Sglebius 619290001Sglebius case 'o': 620290001Sglebius 621290001Sglebius switch (AcpiGbl_Optarg[0]) 622290001Sglebius { 623290001Sglebius case 'a': 624290001Sglebius 625290001Sglebius /* Disable all optimizations */ 626290001Sglebius 627290001Sglebius Gbl_FoldConstants = FALSE; 628290001Sglebius Gbl_IntegerOptimizationFlag = FALSE; 629290001Sglebius Gbl_ReferenceOptimizationFlag = FALSE; 630290001Sglebius break; 631290001Sglebius 632290001Sglebius case 'f': 633290001Sglebius 634290001Sglebius /* Disable folding on "normal" expressions */ 635290001Sglebius 636290001Sglebius Gbl_FoldConstants = FALSE; 637290001Sglebius break; 638290001Sglebius 639290001Sglebius case 'i': 640290001Sglebius 641290001Sglebius /* Disable integer optimization to constants */ 642290001Sglebius 643290001Sglebius Gbl_IntegerOptimizationFlag = FALSE; 644290001Sglebius break; 645290001Sglebius 646290001Sglebius case 'n': 647290001Sglebius 648290001Sglebius /* Disable named reference optimization */ 649290001Sglebius 650290001Sglebius Gbl_ReferenceOptimizationFlag = FALSE; 651290001Sglebius break; 652290001Sglebius 653290001Sglebius case 't': 654290001Sglebius 655290001Sglebius /* Display compile time(s) */ 656290001Sglebius 657290001Sglebius Gbl_CompileTimesFlag = TRUE; 658290001Sglebius break; 659290001Sglebius 660290001Sglebius default: 661290001Sglebius printf ("Unknown option: -c%s\n", AcpiGbl_Optarg); 662290001Sglebius return (-1); 663290001Sglebius } 664290001Sglebius break; 665290001Sglebius 666290001Sglebius 667290001Sglebius case 'p': 668290001Sglebius 669290001Sglebius /* Override default AML output filename */ 670290001Sglebius 671290001Sglebius Gbl_OutputFilenamePrefix = AcpiGbl_Optarg; 672290001Sglebius Gbl_UseDefaultAmlFilename = FALSE; 673290001Sglebius break; 674290001Sglebius 675290001Sglebius 676290001Sglebius case 'r': 677290001Sglebius Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0); 678290001Sglebius break; 679290001Sglebius 680290001Sglebius 681290001Sglebius case 's': 682290001Sglebius 683290001Sglebius switch (AcpiGbl_Optarg[0]) 684290001Sglebius { 685290001Sglebius case 'a': 686290001Sglebius 687290001Sglebius /* Produce assembly code output file */ 688290001Sglebius 689290001Sglebius Gbl_AsmOutputFlag = TRUE; 690290001Sglebius break; 691290001Sglebius 692290001Sglebius case 'c': 693290001Sglebius 694290001Sglebius /* Produce C hex output file */ 695290001Sglebius 696290001Sglebius Gbl_C_OutputFlag = TRUE; 697290001Sglebius break; 698290001Sglebius 699290001Sglebius default: 700290001Sglebius printf ("Unknown option: -s%s\n", AcpiGbl_Optarg); 701290001Sglebius return (-1); 702290001Sglebius } 703290001Sglebius break; 704290001Sglebius 705290001Sglebius 706290001Sglebius case 't': 707290001Sglebius 708290001Sglebius /* Produce hex table output file */ 709290001Sglebius 710290001Sglebius switch (AcpiGbl_Optarg[0]) 711290001Sglebius { 712290001Sglebius case 'a': 713290001Sglebius Gbl_HexOutputFlag = HEX_OUTPUT_ASM; 714290001Sglebius break; 715290001Sglebius 716290001Sglebius case 'c': 717290001Sglebius Gbl_HexOutputFlag = HEX_OUTPUT_C; 718290001Sglebius break; 719290001Sglebius 720290001Sglebius case 's': 721290001Sglebius Gbl_HexOutputFlag = HEX_OUTPUT_ASL; 722290001Sglebius break; 723290001Sglebius 724290001Sglebius default: 725290001Sglebius printf ("Unknown option: -t%s\n", AcpiGbl_Optarg); 726290001Sglebius return (-1); 727290001Sglebius } 728290001Sglebius break; 729290001Sglebius 730290001Sglebius 731290001Sglebius case 'G': 732290001Sglebius Gbl_CompileGeneric = TRUE; 733290001Sglebius break; 734290001Sglebius 735290001Sglebius 736290001Sglebius case 'T': 737290001Sglebius Gbl_DoTemplates = TRUE; 738290001Sglebius Gbl_TemplateSignature = AcpiGbl_Optarg; 739290001Sglebius break; 740290001Sglebius 741290001Sglebius 742290001Sglebius case 'v': 743290001Sglebius 744290001Sglebius switch (AcpiGbl_Optarg[0]) 745290001Sglebius { 746290001Sglebius case 'a': 747290001Sglebius /* Disable All error/warning messages */ 748290001Sglebius 749290001Sglebius Gbl_NoErrors = TRUE; 750290001Sglebius break; 751290001Sglebius 752290001Sglebius case 'i': 753290001Sglebius /* Less verbose error messages */ 754290001Sglebius 755290001Sglebius Gbl_VerboseErrors = FALSE; 756290001Sglebius break; 757290001Sglebius 758290001Sglebius case 'o': 759290001Sglebius Gbl_DisplayOptimizations = TRUE; 760290001Sglebius break; 761290001Sglebius 762290001Sglebius case 'r': 763290001Sglebius Gbl_DisplayRemarks = FALSE; 764290001Sglebius break; 765290001Sglebius 766290001Sglebius case 's': 767290001Sglebius Gbl_DoSignon = FALSE; 768290001Sglebius break; 769290001Sglebius 770290001Sglebius case 't': 771290001Sglebius Gbl_VerboseTemplates = TRUE; 772290001Sglebius break; 773290001Sglebius 774290001Sglebius default: 775290001Sglebius printf ("Unknown option: -v%s\n", AcpiGbl_Optarg); 776290001Sglebius return (-1); 777290001Sglebius } 778290001Sglebius break; 779290001Sglebius 780290001Sglebius 781290001Sglebius case 'w': /* Set warning levels */ 782290001Sglebius 783290001Sglebius switch (AcpiGbl_Optarg[0]) 784290001Sglebius { 785290001Sglebius case '1': 786290001Sglebius Gbl_WarningLevel = ASL_WARNING; 787290001Sglebius break; 788290001Sglebius 789290001Sglebius case '2': 790290001Sglebius Gbl_WarningLevel = ASL_WARNING2; 791290001Sglebius break; 792290001Sglebius 793290001Sglebius case '3': 794290001Sglebius Gbl_WarningLevel = ASL_WARNING3; 795290001Sglebius break; 796290001Sglebius 797290001Sglebius default: 798290001Sglebius printf ("Unknown option: -w%s\n", AcpiGbl_Optarg); 799290001Sglebius return (-1); 800290001Sglebius } 801290001Sglebius break; 802290001Sglebius 803290001Sglebius 804290001Sglebius case 'x': 805290001Sglebius 806290001Sglebius AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16); 807290001Sglebius break; 808290001Sglebius 809290001Sglebius 810290001Sglebius case 'z': 811290001Sglebius 812290001Sglebius Gbl_UseOriginalCompilerId = TRUE; 813290001Sglebius break; 814290001Sglebius 815290001Sglebius 816290001Sglebius default: 817290001Sglebius 818290001Sglebius return (-1); 819290001Sglebius } 820290001Sglebius 821290001Sglebius return (0); 822290001Sglebius} 823290001Sglebius 824290001Sglebius 825290001Sglebius/******************************************************************************* 826290001Sglebius * 827290001Sglebius * FUNCTION: AslCommandLine 828290001Sglebius * 829290001Sglebius * PARAMETERS: argc/argv 830290001Sglebius * 831290001Sglebius * RETURN: Last argv index 832290001Sglebius * 833290001Sglebius * DESCRIPTION: Command line processing 834290001Sglebius * 835290001Sglebius ******************************************************************************/ 836290001Sglebius 837290001Sglebiusstatic int 838290001SglebiusAslCommandLine ( 839290001Sglebius int argc, 840290001Sglebius char **argv) 841290001Sglebius{ 842290001Sglebius int BadCommandLine = 0; 843290001Sglebius ACPI_STATUS Status; 844290001Sglebius 845290001Sglebius 846290001Sglebius /* Minimum command line contains at least the command and an input file */ 847290001Sglebius 848290001Sglebius if (argc < 2) 849290001Sglebius { 850290001Sglebius printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME)); 851290001Sglebius Usage (); 852290001Sglebius exit (1); 853290001Sglebius } 854290001Sglebius 855290001Sglebius /* Process all command line options */ 856290001Sglebius 857290001Sglebius BadCommandLine = AslDoOptions (argc, argv, FALSE); 858290001Sglebius 859290001Sglebius if (Gbl_DoTemplates) 860290001Sglebius { 861290001Sglebius Status = DtCreateTemplates (Gbl_TemplateSignature); 862290001Sglebius if (ACPI_FAILURE (Status)) 863290001Sglebius { 864290001Sglebius exit (-1); 865290001Sglebius } 866290001Sglebius exit (1); 867290001Sglebius } 868290001Sglebius 869290001Sglebius /* Next parameter must be the input filename */ 870290001Sglebius 871290001Sglebius if (!argv[AcpiGbl_Optind] && 872290001Sglebius !Gbl_DisasmFlag && 873290001Sglebius !Gbl_GetAllTables) 874290001Sglebius { 875290001Sglebius printf ("Missing input filename\n"); 876290001Sglebius BadCommandLine = TRUE; 877290001Sglebius } 878290001Sglebius 879290001Sglebius if (Gbl_DoSignon) 880290001Sglebius { 881290001Sglebius printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME)); 882290001Sglebius } 883290001Sglebius 884290001Sglebius /* Abort if anything went wrong on the command line */ 885290001Sglebius 886290001Sglebius if (BadCommandLine) 887290001Sglebius { 888290001Sglebius printf ("\n"); 889290001Sglebius Usage (); 890290001Sglebius exit (1); 891290001Sglebius } 892290001Sglebius 893290001Sglebius return (AcpiGbl_Optind); 894290001Sglebius} 895290001Sglebius 896290001Sglebius 897290001Sglebius/******************************************************************************* 898290001Sglebius * 899290001Sglebius * FUNCTION: main 900290001Sglebius * 901290001Sglebius * PARAMETERS: Standard argc/argv 902290001Sglebius * 903290001Sglebius * RETURN: Program termination code 904290001Sglebius * 905290001Sglebius * DESCRIPTION: C main routine for the Asl Compiler. Handle command line 906290001Sglebius * options and begin the compile for each file on the command line 907290001Sglebius * 908290001Sglebius ******************************************************************************/ 909290001Sglebius 910290001Sglebiusint ACPI_SYSTEM_XFACE 911290001Sglebiusmain ( 912290001Sglebius int argc, 913290001Sglebius char **argv) 914290001Sglebius{ 915290001Sglebius ACPI_STATUS Status; 916290001Sglebius int Index1; 917290001Sglebius int Index2; 918290001Sglebius 919290001Sglebius 920290001Sglebius AcpiGbl_ExternalFileList = NULL; 921290001Sglebius 922290001Sglebius#ifdef _DEBUG 923290001Sglebius _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF | 924290001Sglebius _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG)); 925290001Sglebius#endif 926290001Sglebius 927290001Sglebius /* Init and command line */ 928290001Sglebius 929290001Sglebius AslInitialize (); 930290001Sglebius Index1 = Index2 = AslCommandLine (argc, argv); 931290001Sglebius 932290001Sglebius /* Options that have no additional parameters or pathnames */ 933290001Sglebius 934290001Sglebius if (Gbl_GetAllTables) 935290001Sglebius { 936290001Sglebius Status = AslDoOneFile (NULL); 937290001Sglebius if (ACPI_FAILURE (Status)) 938290001Sglebius { 939290001Sglebius return (-1); 940290001Sglebius } 941290001Sglebius return (0); 942290001Sglebius } 943290001Sglebius 944290001Sglebius if (Gbl_DisassembleAll) 945290001Sglebius { 946290001Sglebius while (argv[Index1]) 947290001Sglebius { 948290001Sglebius Status = AslDoOnePathname (argv[Index1], AcpiDmAddToExternalFileList); 949290001Sglebius if (ACPI_FAILURE (Status)) 950290001Sglebius { 951290001Sglebius return (-1); 952290001Sglebius } 953290001Sglebius 954290001Sglebius Index1++; 955290001Sglebius } 956290001Sglebius } 957290001Sglebius 958290001Sglebius /* Process each pathname/filename in the list, with possible wildcards */ 959290001Sglebius 960290001Sglebius while (argv[Index2]) 961290001Sglebius { 962290001Sglebius Status = AslDoOnePathname (argv[Index2], AslDoOneFile); 963290001Sglebius if (ACPI_FAILURE (Status)) 964290001Sglebius { 965290001Sglebius return (-1); 966290001Sglebius } 967290001Sglebius 968290001Sglebius Index2++; 969290001Sglebius } 970290001Sglebius 971290001Sglebius if (AcpiGbl_ExternalFileList) 972290001Sglebius { 973290001Sglebius AcpiDmClearExternalFileList(); 974290001Sglebius } 975290001Sglebius 976290001Sglebius return (0); 977290001Sglebius} 978290001Sglebius 979290001Sglebius 980290001Sglebius