aslmain.c revision 246849
1219820Sjeff/****************************************************************************** 2219820Sjeff * 3219820Sjeff * Module Name: aslmain - compiler main and utilities 4219820Sjeff * 5219820Sjeff *****************************************************************************/ 6219820Sjeff 7219820Sjeff/* 8219820Sjeff * Copyright (C) 2000 - 2013, Intel Corp. 9219820Sjeff * All rights reserved. 10219820Sjeff * 11219820Sjeff * Redistribution and use in source and binary forms, with or without 12219820Sjeff * modification, are permitted provided that the following conditions 13219820Sjeff * are met: 14219820Sjeff * 1. Redistributions of source code must retain the above copyright 15219820Sjeff * notice, this list of conditions, and the following disclaimer, 16219820Sjeff * without modification. 17219820Sjeff * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18219820Sjeff * substantially similar to the "NO WARRANTY" disclaimer below 19219820Sjeff * ("Disclaimer") and any redistribution must be conditioned upon 20219820Sjeff * including a substantially similar Disclaimer requirement for further 21219820Sjeff * binary redistribution. 22219820Sjeff * 3. Neither the names of the above-listed copyright holders nor the names 23219820Sjeff * of any contributors may be used to endorse or promote products derived 24219820Sjeff * from this software without specific prior written permission. 25219820Sjeff * 26219820Sjeff * Alternatively, this software may be distributed under the terms of the 27219820Sjeff * GNU General Public License ("GPL") version 2 as published by the Free 28219820Sjeff * Software Foundation. 29219820Sjeff * 30219820Sjeff * NO WARRANTY 31219820Sjeff * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32219820Sjeff * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33219820Sjeff * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34219820Sjeff * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35219820Sjeff * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36219820Sjeff * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37219820Sjeff * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38219820Sjeff * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39219820Sjeff * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40219820Sjeff * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41219820Sjeff * POSSIBILITY OF SUCH DAMAGES. 42219820Sjeff */ 43219820Sjeff 44219820Sjeff 45219820Sjeff#define _DECLARE_GLOBALS 46219820Sjeff 47219820Sjeff#include <contrib/dev/acpica/compiler/aslcompiler.h> 48219820Sjeff#include <contrib/dev/acpica/include/acapps.h> 49219820Sjeff#include <contrib/dev/acpica/include/acdisasm.h> 50219820Sjeff#include <signal.h> 51219820Sjeff 52219820Sjeff#ifdef _DEBUG 53219820Sjeff#include <crtdbg.h> 54219820Sjeff#endif 55219820Sjeff 56219820Sjeff#define _COMPONENT ACPI_COMPILER 57219820Sjeff ACPI_MODULE_NAME ("aslmain") 58219820Sjeff 59219820Sjeff/* Local prototypes */ 60219820Sjeff 61219820Sjeffstatic void 62219820SjeffOptions ( 63219820Sjeff void); 64219820Sjeff 65219820Sjeffstatic void 66219820SjeffFilenameHelp ( 67219820Sjeff void); 68219820Sjeff 69219820Sjeffstatic void 70219820SjeffUsage ( 71219820Sjeff void); 72219820Sjeff 73219820Sjeffstatic void ACPI_SYSTEM_XFACE 74219820SjeffAslSignalHandler ( 75219820Sjeff int Sig); 76219820Sjeff 77219820Sjeffstatic void 78219820SjeffAslInitialize ( 79219820Sjeff void); 80219820Sjeff 81219820Sjeffstatic int 82219820SjeffAslCommandLine ( 83219820Sjeff int argc, 84219820Sjeff char **argv); 85219820Sjeff 86219820Sjeffstatic int 87219820SjeffAslDoOptions ( 88219820Sjeff int argc, 89219820Sjeff char **argv, 90219820Sjeff BOOLEAN IsResponseFile); 91219820Sjeff 92219820Sjeffstatic void 93219820SjeffAslMergeOptionTokens ( 94219820Sjeff char *InBuffer, 95219820Sjeff char *OutBuffer); 96219820Sjeff 97219820Sjeffstatic int 98219820SjeffAslDoResponseFile ( 99219820Sjeff char *Filename); 100219820Sjeff 101219820Sjeff 102219820Sjeff#define ASL_TOKEN_SEPARATORS " \t\n" 103219820Sjeff#define ASL_SUPPORTED_OPTIONS "@:b|c|d^D:e:fgh^i|I:l^m:no|p:P^r:s|t|T:G^v^w|x:z" 104219820Sjeff 105219820Sjeff 106219820Sjeff/******************************************************************************* 107219820Sjeff * 108219820Sjeff * FUNCTION: Options 109219820Sjeff * 110219820Sjeff * PARAMETERS: None 111219820Sjeff * 112219820Sjeff * RETURN: None 113219820Sjeff * 114219820Sjeff * DESCRIPTION: Display option help message. 115219820Sjeff * Optional items in square brackets. 116219820Sjeff * 117219820Sjeff ******************************************************************************/ 118219820Sjeff 119219820Sjeffstatic void 120219820SjeffOptions ( 121219820Sjeff void) 122219820Sjeff{ 123219820Sjeff 124219820Sjeff printf ("\nGlobal:\n"); 125219820Sjeff ACPI_OPTION ("-@ <file>", "Specify command file"); 126219820Sjeff ACPI_OPTION ("-I <dir>", "Specify additional include directory"); 127219820Sjeff ACPI_OPTION ("-T <sig>|ALL|*", "Create table template file for ACPI <Sig>"); 128219820Sjeff ACPI_OPTION ("-v", "Display compiler version"); 129219820Sjeff 130219820Sjeff printf ("\nPreprocessor:\n"); 131219820Sjeff ACPI_OPTION ("-D <symbol>", "Define symbol for preprocessor use"); 132219820Sjeff ACPI_OPTION ("-li", "Create preprocessed output file (*.i)"); 133219820Sjeff ACPI_OPTION ("-P", "Preprocess only and create preprocessor output file (*.i)"); 134219820Sjeff ACPI_OPTION ("-Pn", "Disable preprocessor"); 135219820Sjeff 136219820Sjeff printf ("\nGeneral Processing:\n"); 137219820Sjeff ACPI_OPTION ("-p <prefix>", "Specify path/filename prefix for all output files"); 138219820Sjeff ACPI_OPTION ("-va", "Disable all errors and warnings (summary only)"); 139219820Sjeff ACPI_OPTION ("-vi", "Less verbose errors and warnings for use with IDEs"); 140219820Sjeff ACPI_OPTION ("-vo", "Enable optimization comments"); 141219820Sjeff ACPI_OPTION ("-vr", "Disable remarks"); 142219820Sjeff ACPI_OPTION ("-vs", "Disable signon"); 143219820Sjeff ACPI_OPTION ("-w1 -w2 -w3", "Set warning reporting level"); 144219820Sjeff ACPI_OPTION ("-we", "Report warnings as errors"); 145219820Sjeff 146219820Sjeff printf ("\nAML Code Generation (*.aml):\n"); 147219820Sjeff ACPI_OPTION ("-oa", "Disable all optimizations (compatibility mode)"); 148219820Sjeff ACPI_OPTION ("-of", "Disable constant folding"); 149219820Sjeff ACPI_OPTION ("-oi", "Disable integer optimization to Zero/One/Ones"); 150219820Sjeff ACPI_OPTION ("-on", "Disable named reference string optimization"); 151219820Sjeff ACPI_OPTION ("-cr", "Disable Resource Descriptor error checking"); 152219820Sjeff ACPI_OPTION ("-in", "Ignore NoOp operators"); 153219820Sjeff ACPI_OPTION ("-r <revision>", "Override table header Revision (1-255)"); 154219820Sjeff 155219820Sjeff printf ("\nOptional Source Code Output Files:\n"); 156219820Sjeff ACPI_OPTION ("-sc -sa", "Create source file in C or assembler (*.c or *.asm)"); 157219820Sjeff ACPI_OPTION ("-ic -ia", "Create include file in C or assembler (*.h or *.inc)"); 158219820Sjeff ACPI_OPTION ("-tc -ta -ts", "Create hex AML table in C, assembler, or ASL (*.hex)"); 159219820Sjeff 160219820Sjeff printf ("\nOptional Listing Files:\n"); 161219820Sjeff ACPI_OPTION ("-l", "Create mixed listing file (ASL source and AML) (*.lst)"); 162219820Sjeff ACPI_OPTION ("-ln", "Create namespace file (*.nsp)"); 163219820Sjeff ACPI_OPTION ("-ls", "Create combined source file (expanded includes) (*.src)"); 164219820Sjeff 165219820Sjeff printf ("\nData Table Compiler:\n"); 166219820Sjeff ACPI_OPTION ("-G", "Compile custom table that contains generic operators"); 167219820Sjeff ACPI_OPTION ("-vt", "Create verbose template files (full disassembly)"); 168219820Sjeff 169219820Sjeff printf ("\nAML Disassembler:\n"); 170219820Sjeff ACPI_OPTION ("-d <f1,f2>", "Disassemble or decode binary ACPI tables to file (*.dsl)"); 171219820Sjeff ACPI_OPTION ("", " (Optional, file type is automatically detected)"); 172219820Sjeff ACPI_OPTION ("-da <f1,f2>", "Disassemble multiple tables from single namespace"); 173219820Sjeff ACPI_OPTION ("-db", "Do not translate Buffers to Resource Templates"); 174219820Sjeff ACPI_OPTION ("-dc <f1,f2>", "Disassemble AML and immediately compile it"); 175219820Sjeff ACPI_OPTION ("", " (Obtain DSDT from current system if no input file)"); 176219820Sjeff ACPI_OPTION ("-e <f1,f2>", "Include ACPI table(s) for external symbol resolution"); 177219820Sjeff ACPI_OPTION ("-g", "Get ACPI tables and write to files (*.dat)"); 178219820Sjeff ACPI_OPTION ("-in", "Ignore NoOp opcodes"); 179219820Sjeff ACPI_OPTION ("-vt", "Dump binary table data in hex format within output file"); 180219820Sjeff 181219820Sjeff printf ("\nHelp:\n"); 182219820Sjeff ACPI_OPTION ("-h", "This message"); 183219820Sjeff ACPI_OPTION ("-hc", "Display operators allowed in constant expressions"); 184219820Sjeff ACPI_OPTION ("-hf", "Display help for output filename generation"); 185219820Sjeff ACPI_OPTION ("-hr", "Display ACPI reserved method names"); 186219820Sjeff ACPI_OPTION ("-ht", "Display currently supported ACPI table names"); 187219820Sjeff 188219820Sjeff printf ("\nDebug Options:\n"); 189219820Sjeff ACPI_OPTION ("-bf -bt", "Create debug file (full or parse tree only) (*.txt)"); 190219820Sjeff ACPI_OPTION ("-f", "Ignore errors, force creation of AML output file(s)"); 191219820Sjeff ACPI_OPTION ("-m <size>", "Set internal line buffer size (in Kbytes)"); 192219820Sjeff ACPI_OPTION ("-n", "Parse only, no output generation"); 193219820Sjeff ACPI_OPTION ("-ot", "Display compile times and statistics"); 194219820Sjeff ACPI_OPTION ("-x <level>", "Set debug level for trace output"); 195219820Sjeff ACPI_OPTION ("-z", "Do not insert new compiler ID for DataTables"); 196219820Sjeff} 197219820Sjeff 198219820Sjeff 199219820Sjeff/******************************************************************************* 200219820Sjeff * 201219820Sjeff * FUNCTION: FilenameHelp 202219820Sjeff * 203219820Sjeff * PARAMETERS: None 204219820Sjeff * 205219820Sjeff * RETURN: None 206219820Sjeff * 207219820Sjeff * DESCRIPTION: Display help message for output filename generation 208219820Sjeff * 209219820Sjeff ******************************************************************************/ 210219820Sjeff 211219820Sjeffstatic void 212219820SjeffFilenameHelp ( 213219820Sjeff void) 214219820Sjeff{ 215219820Sjeff 216219820Sjeff printf ("\nAML output filename generation:\n"); 217219820Sjeff printf (" Output filenames are generated by appending an extension to a common\n"); 218219820Sjeff printf (" filename prefix. The filename prefix is obtained via one of the\n"); 219219820Sjeff printf (" following methods (in priority order):\n"); 220219820Sjeff printf (" 1) The -p option specifies the prefix\n"); 221219820Sjeff printf (" 2) The prefix of the AMLFileName in the ASL Definition Block\n"); 222219820Sjeff printf (" 3) The prefix of the input filename\n"); 223219820Sjeff printf ("\n"); 224219820Sjeff} 225219820Sjeff 226219820Sjeff 227219820Sjeff/******************************************************************************* 228219820Sjeff * 229219820Sjeff * FUNCTION: Usage 230219820Sjeff * 231219820Sjeff * PARAMETERS: None 232219820Sjeff * 233219820Sjeff * RETURN: None 234219820Sjeff * 235219820Sjeff * DESCRIPTION: Display usage and option message 236219820Sjeff * 237219820Sjeff ******************************************************************************/ 238219820Sjeff 239219820Sjeffstatic void 240219820SjeffUsage ( 241219820Sjeff void) 242219820Sjeff{ 243219820Sjeff 244219820Sjeff printf ("%s\n\n", ASL_COMPLIANCE); 245219820Sjeff ACPI_USAGE_HEADER ("iasl [Options] [Files]"); 246219820Sjeff Options (); 247219820Sjeff} 248219820Sjeff 249219820Sjeff 250219820Sjeff/****************************************************************************** 251219820Sjeff * 252219820Sjeff * FUNCTION: AslSignalHandler 253219820Sjeff * 254219820Sjeff * PARAMETERS: Sig - Signal that invoked this handler 255219820Sjeff * 256219820Sjeff * RETURN: None 257219820Sjeff * 258219820Sjeff * DESCRIPTION: Control-C handler. Delete any intermediate files and any 259219820Sjeff * output files that may be left in an indeterminate state. 260219820Sjeff * 261219820Sjeff *****************************************************************************/ 262219820Sjeff 263219820Sjeffstatic void ACPI_SYSTEM_XFACE 264219820SjeffAslSignalHandler ( 265219820Sjeff int Sig) 266219820Sjeff{ 267219820Sjeff UINT32 i; 268219820Sjeff 269219820Sjeff 270219820Sjeff signal (Sig, SIG_IGN); 271219820Sjeff printf ("Aborting\n\n"); 272219820Sjeff 273219820Sjeff /* Close all open files */ 274219820Sjeff 275219820Sjeff Gbl_Files[ASL_FILE_PREPROCESSOR].Handle = NULL; /* the .i file is same as source file */ 276219820Sjeff 277219820Sjeff for (i = ASL_FILE_INPUT; i < ASL_MAX_FILE_TYPE; i++) 278219820Sjeff { 279219820Sjeff FlCloseFile (i); 280219820Sjeff } 281219820Sjeff 282219820Sjeff /* Delete any output files */ 283219820Sjeff 284219820Sjeff for (i = ASL_FILE_AML_OUTPUT; i < ASL_MAX_FILE_TYPE; i++) 285219820Sjeff { 286219820Sjeff FlDeleteFile (i); 287219820Sjeff } 288219820Sjeff 289219820Sjeff exit (0); 290219820Sjeff} 291219820Sjeff 292219820Sjeff 293219820Sjeff/******************************************************************************* 294219820Sjeff * 295219820Sjeff * FUNCTION: AslInitialize 296219820Sjeff * 297219820Sjeff * PARAMETERS: None 298219820Sjeff * 299219820Sjeff * RETURN: None 300219820Sjeff * 301219820Sjeff * DESCRIPTION: Initialize compiler globals 302219820Sjeff * 303219820Sjeff ******************************************************************************/ 304219820Sjeff 305219820Sjeffstatic void 306219820SjeffAslInitialize ( 307219820Sjeff void) 308219820Sjeff{ 309219820Sjeff UINT32 i; 310219820Sjeff 311219820Sjeff 312219820Sjeff#ifdef _DEBUG 313219820Sjeff _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0)); 314219820Sjeff#endif 315219820Sjeff 316219820Sjeff 317219820Sjeff for (i = 0; i < ASL_NUM_FILES; i++) 318219820Sjeff { 319219820Sjeff Gbl_Files[i].Handle = NULL; 320219820Sjeff Gbl_Files[i].Filename = NULL; 321219820Sjeff } 322219820Sjeff 323219820Sjeff Gbl_Files[ASL_FILE_STDOUT].Handle = stdout; 324219820Sjeff Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT"; 325219820Sjeff 326219820Sjeff Gbl_Files[ASL_FILE_STDERR].Handle = stderr; 327219820Sjeff Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR"; 328219820Sjeff 329219820Sjeff /* Allocate the line buffer(s) */ 330219820Sjeff 331219820Sjeff Gbl_LineBufferSize /= 2; 332219820Sjeff UtExpandLineBuffers (); 333219820Sjeff} 334219820Sjeff 335219820Sjeff 336219820Sjeff/******************************************************************************* 337219820Sjeff * 338219820Sjeff * FUNCTION: AslMergeOptionTokens 339219820Sjeff * 340219820Sjeff * PARAMETERS: InBuffer - Input containing an option string 341219820Sjeff * OutBuffer - Merged output buffer 342219820Sjeff * 343219820Sjeff * RETURN: None 344219820Sjeff * 345219820Sjeff * DESCRIPTION: Remove all whitespace from an option string. 346219820Sjeff * 347219820Sjeff ******************************************************************************/ 348219820Sjeff 349219820Sjeffstatic void 350219820SjeffAslMergeOptionTokens ( 351219820Sjeff char *InBuffer, 352219820Sjeff char *OutBuffer) 353219820Sjeff{ 354219820Sjeff char *Token; 355219820Sjeff 356219820Sjeff 357219820Sjeff *OutBuffer = 0; 358219820Sjeff 359219820Sjeff Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS); 360219820Sjeff while (Token) 361219820Sjeff { 362219820Sjeff strcat (OutBuffer, Token); 363219820Sjeff Token = strtok (NULL, ASL_TOKEN_SEPARATORS); 364219820Sjeff } 365219820Sjeff} 366219820Sjeff 367219820Sjeff 368219820Sjeff/******************************************************************************* 369219820Sjeff * 370219820Sjeff * FUNCTION: AslDoResponseFile 371219820Sjeff * 372219820Sjeff * PARAMETERS: Filename - Name of the response file 373219820Sjeff * 374219820Sjeff * RETURN: Status 375219820Sjeff * 376219820Sjeff * DESCRIPTION: Open a response file and process all options within. 377219820Sjeff * 378219820Sjeff ******************************************************************************/ 379219820Sjeff 380219820Sjeffstatic int 381219820SjeffAslDoResponseFile ( 382219820Sjeff char *Filename) 383219820Sjeff{ 384219820Sjeff char *argv = StringBuffer2; 385219820Sjeff FILE *ResponseFile; 386219820Sjeff int OptStatus = 0; 387219820Sjeff int Opterr; 388219820Sjeff int Optind; 389219820Sjeff 390219820Sjeff 391219820Sjeff ResponseFile = fopen (Filename, "r"); 392219820Sjeff if (!ResponseFile) 393219820Sjeff { 394219820Sjeff printf ("Could not open command file %s, %s\n", 395219820Sjeff Filename, strerror (errno)); 396219820Sjeff return (-1); 397219820Sjeff } 398219820Sjeff 399219820Sjeff /* Must save the current GetOpt globals */ 400219820Sjeff 401219820Sjeff Opterr = AcpiGbl_Opterr; 402219820Sjeff Optind = AcpiGbl_Optind; 403219820Sjeff 404219820Sjeff /* 405219820Sjeff * Process all lines in the response file. There must be one complete 406219820Sjeff * option per line 407219820Sjeff */ 408219820Sjeff while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile)) 409219820Sjeff { 410219820Sjeff /* Compress all tokens, allowing us to use a single argv entry */ 411219820Sjeff 412219820Sjeff AslMergeOptionTokens (StringBuffer, StringBuffer2); 413219820Sjeff 414219820Sjeff /* Process the option */ 415219820Sjeff 416219820Sjeff AcpiGbl_Opterr = 0; 417219820Sjeff AcpiGbl_Optind = 0; 418219820Sjeff 419219820Sjeff OptStatus = AslDoOptions (1, &argv, TRUE); 420219820Sjeff if (OptStatus) 421219820Sjeff { 422219820Sjeff printf ("Invalid option in command file %s: %s\n", 423219820Sjeff Filename, StringBuffer); 424219820Sjeff break; 425219820Sjeff } 426219820Sjeff } 427219820Sjeff 428219820Sjeff /* Restore the GetOpt globals */ 429219820Sjeff 430219820Sjeff AcpiGbl_Opterr = Opterr; 431219820Sjeff AcpiGbl_Optind = Optind; 432219820Sjeff 433219820Sjeff fclose (ResponseFile); 434219820Sjeff return (OptStatus); 435219820Sjeff} 436219820Sjeff 437219820Sjeff 438219820Sjeff/******************************************************************************* 439219820Sjeff * 440219820Sjeff * FUNCTION: AslDoOptions 441219820Sjeff * 442219820Sjeff * PARAMETERS: argc/argv - Standard argc/argv 443219820Sjeff * IsResponseFile - TRUE if executing a response file. 444219820Sjeff * 445219820Sjeff * RETURN: Status 446219820Sjeff * 447219820Sjeff * DESCRIPTION: Command line option processing 448219820Sjeff * 449219820Sjeff ******************************************************************************/ 450219820Sjeff 451219820Sjeffstatic int 452219820SjeffAslDoOptions ( 453219820Sjeff int argc, 454219820Sjeff char **argv, 455219820Sjeff BOOLEAN IsResponseFile) 456219820Sjeff{ 457219820Sjeff int j; 458219820Sjeff ACPI_STATUS Status; 459219820Sjeff 460219820Sjeff 461219820Sjeff /* Get the command line options */ 462219820Sjeff 463219820Sjeff while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j) 464219820Sjeff { 465219820Sjeff case '@': /* Begin a response file */ 466219820Sjeff 467219820Sjeff if (IsResponseFile) 468219820Sjeff { 469219820Sjeff printf ("Nested command files are not supported\n"); 470219820Sjeff return (-1); 471219820Sjeff } 472219820Sjeff 473219820Sjeff if (AslDoResponseFile (AcpiGbl_Optarg)) 474219820Sjeff { 475219820Sjeff return (-1); 476219820Sjeff } 477219820Sjeff break; 478219820Sjeff 479219820Sjeff 480219820Sjeff case 'b': /* Debug output options */ 481219820Sjeff switch (AcpiGbl_Optarg[0]) 482219820Sjeff { 483219820Sjeff case 'f': 484219820Sjeff AslCompilerdebug = 1; /* same as yydebug */ 485219820Sjeff DtParserdebug = 1; 486219820Sjeff PrParserdebug = 1; 487219820Sjeff break; 488219820Sjeff 489219820Sjeff case 't': 490219820Sjeff break; 491219820Sjeff 492219820Sjeff default: 493219820Sjeff printf ("Unknown option: -b%s\n", AcpiGbl_Optarg); 494219820Sjeff return (-1); 495219820Sjeff } 496219820Sjeff 497219820Sjeff /* Produce debug output file */ 498219820Sjeff 499219820Sjeff Gbl_DebugFlag = TRUE; 500219820Sjeff break; 501219820Sjeff 502219820Sjeff 503219820Sjeff case 'c': 504219820Sjeff switch (AcpiGbl_Optarg[0]) 505219820Sjeff { 506219820Sjeff case 'r': 507219820Sjeff Gbl_NoResourceChecking = TRUE; 508219820Sjeff break; 509219820Sjeff 510219820Sjeff default: 511219820Sjeff printf ("Unknown option: -c%s\n", AcpiGbl_Optarg); 512219820Sjeff return (-1); 513219820Sjeff } 514219820Sjeff break; 515219820Sjeff 516219820Sjeff 517219820Sjeff case 'd': /* Disassembler */ 518219820Sjeff switch (AcpiGbl_Optarg[0]) 519219820Sjeff { 520219820Sjeff case '^': 521219820Sjeff Gbl_DoCompile = FALSE; 522219820Sjeff break; 523219820Sjeff 524219820Sjeff case 'a': 525219820Sjeff Gbl_DoCompile = FALSE; 526219820Sjeff Gbl_DisassembleAll = TRUE; 527219820Sjeff break; 528219820Sjeff 529219820Sjeff case 'b': /* Do not convert buffers to resource descriptors */ 530219820Sjeff AcpiGbl_NoResourceDisassembly = TRUE; 531219820Sjeff break; 532219820Sjeff 533219820Sjeff case 'c': 534219820Sjeff break; 535219820Sjeff 536219820Sjeff default: 537219820Sjeff printf ("Unknown option: -d%s\n", AcpiGbl_Optarg); 538219820Sjeff return (-1); 539219820Sjeff } 540219820Sjeff 541219820Sjeff Gbl_DisasmFlag = TRUE; 542219820Sjeff break; 543219820Sjeff 544219820Sjeff 545219820Sjeff case 'D': /* Define a symbol */ 546219820Sjeff PrAddDefine (AcpiGbl_Optarg, NULL, TRUE); 547219820Sjeff break; 548219820Sjeff 549219820Sjeff 550219820Sjeff case 'e': /* External files for disassembler */ 551219820Sjeff Status = AcpiDmAddToExternalFileList (AcpiGbl_Optarg); 552219820Sjeff if (ACPI_FAILURE (Status)) 553219820Sjeff { 554219820Sjeff printf ("Could not add %s to external list\n", AcpiGbl_Optarg); 555219820Sjeff return (-1); 556219820Sjeff } 557219820Sjeff break; 558219820Sjeff 559219820Sjeff 560219820Sjeff case 'f': /* Ignore errors and force creation of aml file */ 561219820Sjeff Gbl_IgnoreErrors = TRUE; 562219820Sjeff break; 563219820Sjeff 564219820Sjeff 565219820Sjeff case 'G': 566219820Sjeff Gbl_CompileGeneric = TRUE; 567219820Sjeff break; 568219820Sjeff 569219820Sjeff 570219820Sjeff case 'g': /* Get all ACPI tables */ 571219820Sjeff 572219820Sjeff Gbl_GetAllTables = TRUE; 573219820Sjeff Gbl_DoCompile = FALSE; 574219820Sjeff break; 575219820Sjeff 576219820Sjeff 577219820Sjeff case 'h': 578219820Sjeff switch (AcpiGbl_Optarg[0]) 579219820Sjeff { 580219820Sjeff case '^': 581219820Sjeff Usage (); 582219820Sjeff exit (0); 583219820Sjeff 584219820Sjeff case 'c': 585219820Sjeff UtDisplayConstantOpcodes (); 586219820Sjeff exit (0); 587219820Sjeff 588219820Sjeff case 'f': 589219820Sjeff FilenameHelp (); 590219820Sjeff exit (0); 591219820Sjeff 592219820Sjeff case 'r': 593219820Sjeff /* reserved names */ 594219820Sjeff 595219820Sjeff ApDisplayReservedNames (); 596219820Sjeff exit (0); 597219820Sjeff 598219820Sjeff case 't': 599219820Sjeff UtDisplaySupportedTables (); 600219820Sjeff exit (0); 601219820Sjeff 602219820Sjeff default: 603219820Sjeff printf ("Unknown option: -h%s\n", AcpiGbl_Optarg); 604219820Sjeff return (-1); 605219820Sjeff } 606219820Sjeff 607219820Sjeff 608219820Sjeff case 'I': /* Add an include file search directory */ 609219820Sjeff FlAddIncludeDirectory (AcpiGbl_Optarg); 610219820Sjeff break; 611219820Sjeff 612219820Sjeff 613219820Sjeff case 'i': /* Output AML as an include file */ 614219820Sjeff switch (AcpiGbl_Optarg[0]) 615219820Sjeff { 616219820Sjeff case 'a': 617219820Sjeff 618219820Sjeff /* Produce assembly code include file */ 619219820Sjeff 620219820Sjeff Gbl_AsmIncludeOutputFlag = TRUE; 621219820Sjeff break; 622219820Sjeff 623219820Sjeff case 'c': 624219820Sjeff 625219820Sjeff /* Produce C include file */ 626219820Sjeff 627219820Sjeff Gbl_C_IncludeOutputFlag = TRUE; 628219820Sjeff break; 629219820Sjeff 630219820Sjeff case 'n': 631219820Sjeff 632219820Sjeff /* Compiler/Disassembler: Ignore the NOOP operator */ 633219820Sjeff 634219820Sjeff AcpiGbl_IgnoreNoopOperator = TRUE; 635219820Sjeff break; 636 637 default: 638 printf ("Unknown option: -i%s\n", AcpiGbl_Optarg); 639 return (-1); 640 } 641 break; 642 643 644 case 'l': /* Listing files */ 645 switch (AcpiGbl_Optarg[0]) 646 { 647 case '^': 648 /* Produce listing file (Mixed source/aml) */ 649 650 Gbl_ListingFlag = TRUE; 651 break; 652 653 case 'i': 654 /* Produce preprocessor output file */ 655 656 Gbl_PreprocessorOutputFlag = TRUE; 657 break; 658 659 case 'n': 660 /* Produce namespace file */ 661 662 Gbl_NsOutputFlag = TRUE; 663 break; 664 665 case 's': 666 /* Produce combined source file */ 667 668 Gbl_SourceOutputFlag = TRUE; 669 break; 670 671 default: 672 printf ("Unknown option: -l%s\n", AcpiGbl_Optarg); 673 return (-1); 674 } 675 break; 676 677 678 case 'm': /* Set line buffer size */ 679 Gbl_LineBufferSize = (UINT32) strtoul (AcpiGbl_Optarg, NULL, 0) * 1024; 680 if (Gbl_LineBufferSize < ASL_DEFAULT_LINE_BUFFER_SIZE) 681 { 682 Gbl_LineBufferSize = ASL_DEFAULT_LINE_BUFFER_SIZE; 683 } 684 printf ("Line Buffer Size: %u\n", Gbl_LineBufferSize); 685 break; 686 687 688 case 'n': /* Parse only */ 689 Gbl_ParseOnlyFlag = TRUE; 690 break; 691 692 693 case 'o': /* Control compiler AML optimizations */ 694 switch (AcpiGbl_Optarg[0]) 695 { 696 case 'a': 697 698 /* Disable all optimizations */ 699 700 Gbl_FoldConstants = FALSE; 701 Gbl_IntegerOptimizationFlag = FALSE; 702 Gbl_ReferenceOptimizationFlag = FALSE; 703 break; 704 705 case 'f': 706 707 /* Disable folding on "normal" expressions */ 708 709 Gbl_FoldConstants = FALSE; 710 break; 711 712 case 'i': 713 714 /* Disable integer optimization to constants */ 715 716 Gbl_IntegerOptimizationFlag = FALSE; 717 break; 718 719 case 'n': 720 721 /* Disable named reference optimization */ 722 723 Gbl_ReferenceOptimizationFlag = FALSE; 724 break; 725 726 case 't': 727 728 /* Display compile time(s) */ 729 730 Gbl_CompileTimesFlag = TRUE; 731 break; 732 733 default: 734 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg); 735 return (-1); 736 } 737 break; 738 739 740 case 'P': /* Preprocessor options */ 741 switch (AcpiGbl_Optarg[0]) 742 { 743 case '^': /* Proprocess only, emit (.i) file */ 744 Gbl_PreprocessOnly = TRUE; 745 Gbl_PreprocessorOutputFlag = TRUE; 746 break; 747 748 case 'n': /* Disable preprocessor */ 749 Gbl_PreprocessFlag = FALSE; 750 break; 751 752 default: 753 printf ("Unknown option: -P%s\n", AcpiGbl_Optarg); 754 return (-1); 755 } 756 break; 757 758 759 case 'p': /* Override default AML output filename */ 760 Gbl_OutputFilenamePrefix = AcpiGbl_Optarg; 761 Gbl_UseDefaultAmlFilename = FALSE; 762 break; 763 764 765 case 'r': /* Override revision found in table header */ 766 Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0); 767 break; 768 769 770 case 's': /* Create AML in a source code file */ 771 switch (AcpiGbl_Optarg[0]) 772 { 773 case 'a': 774 775 /* Produce assembly code output file */ 776 777 Gbl_AsmOutputFlag = TRUE; 778 break; 779 780 case 'c': 781 782 /* Produce C hex output file */ 783 784 Gbl_C_OutputFlag = TRUE; 785 break; 786 787 default: 788 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg); 789 return (-1); 790 } 791 break; 792 793 794 case 't': /* Produce hex table output file */ 795 switch (AcpiGbl_Optarg[0]) 796 { 797 case 'a': 798 Gbl_HexOutputFlag = HEX_OUTPUT_ASM; 799 break; 800 801 case 'c': 802 Gbl_HexOutputFlag = HEX_OUTPUT_C; 803 break; 804 805 case 's': 806 Gbl_HexOutputFlag = HEX_OUTPUT_ASL; 807 break; 808 809 default: 810 printf ("Unknown option: -t%s\n", AcpiGbl_Optarg); 811 return (-1); 812 } 813 break; 814 815 816 case 'T': /* Create a ACPI table template file */ 817 Gbl_DoTemplates = TRUE; 818 Gbl_TemplateSignature = AcpiGbl_Optarg; 819 break; 820 821 822 case 'v': /* Version and verbosity settings */ 823 switch (AcpiGbl_Optarg[0]) 824 { 825 case '^': 826 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME)); 827 exit (0); 828 829 case 'a': 830 /* Disable All error/warning messages */ 831 832 Gbl_NoErrors = TRUE; 833 break; 834 835 case 'i': 836 /* 837 * Support for integrated development environment(s). 838 * 839 * 1) No compiler signon 840 * 2) Send stderr messages to stdout 841 * 3) Less verbose error messages (single line only for each) 842 * 4) Error/warning messages are formatted appropriately to 843 * be recognized by MS Visual Studio 844 */ 845 Gbl_VerboseErrors = FALSE; 846 Gbl_DoSignon = FALSE; 847 Gbl_Files[ASL_FILE_STDERR].Handle = stdout; 848 break; 849 850 case 'o': 851 Gbl_DisplayOptimizations = TRUE; 852 break; 853 854 case 'r': 855 Gbl_DisplayRemarks = FALSE; 856 break; 857 858 case 's': 859 Gbl_DoSignon = FALSE; 860 break; 861 862 case 't': 863 Gbl_VerboseTemplates = TRUE; 864 break; 865 866 default: 867 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg); 868 return (-1); 869 } 870 break; 871 872 873 case 'w': /* Set warning levels */ 874 switch (AcpiGbl_Optarg[0]) 875 { 876 case '1': 877 Gbl_WarningLevel = ASL_WARNING; 878 break; 879 880 case '2': 881 Gbl_WarningLevel = ASL_WARNING2; 882 break; 883 884 case '3': 885 Gbl_WarningLevel = ASL_WARNING3; 886 break; 887 888 case 'e': 889 Gbl_WarningsAsErrors = TRUE; 890 break; 891 892 default: 893 printf ("Unknown option: -w%s\n", AcpiGbl_Optarg); 894 return (-1); 895 } 896 break; 897 898 899 case 'x': /* Set debug print output level */ 900 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16); 901 break; 902 903 904 case 'z': 905 Gbl_UseOriginalCompilerId = TRUE; 906 break; 907 908 909 default: 910 return (-1); 911 } 912 913 return (0); 914} 915 916 917/******************************************************************************* 918 * 919 * FUNCTION: AslCommandLine 920 * 921 * PARAMETERS: argc/argv 922 * 923 * RETURN: Last argv index 924 * 925 * DESCRIPTION: Command line processing 926 * 927 ******************************************************************************/ 928 929static int 930AslCommandLine ( 931 int argc, 932 char **argv) 933{ 934 int BadCommandLine = 0; 935 ACPI_STATUS Status; 936 937 938 /* Minimum command line contains at least the command and an input file */ 939 940 if (argc < 2) 941 { 942 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME)); 943 Usage (); 944 exit (1); 945 } 946 947 /* Process all command line options */ 948 949 BadCommandLine = AslDoOptions (argc, argv, FALSE); 950 951 if (Gbl_DoTemplates) 952 { 953 Status = DtCreateTemplates (Gbl_TemplateSignature); 954 if (ACPI_FAILURE (Status)) 955 { 956 exit (-1); 957 } 958 exit (1); 959 } 960 961 /* Next parameter must be the input filename */ 962 963 if (!argv[AcpiGbl_Optind] && 964 !Gbl_DisasmFlag && 965 !Gbl_GetAllTables) 966 { 967 printf ("Missing input filename\n"); 968 BadCommandLine = TRUE; 969 } 970 971 if (Gbl_DoSignon) 972 { 973 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME)); 974 if (Gbl_IgnoreErrors) 975 { 976 printf ("Ignoring all errors, forcing AML file generation\n\n"); 977 } 978 } 979 980 /* Abort if anything went wrong on the command line */ 981 982 if (BadCommandLine) 983 { 984 printf ("\n"); 985 Usage (); 986 exit (1); 987 } 988 989 return (AcpiGbl_Optind); 990} 991 992 993/******************************************************************************* 994 * 995 * FUNCTION: main 996 * 997 * PARAMETERS: Standard argc/argv 998 * 999 * RETURN: Program termination code 1000 * 1001 * DESCRIPTION: C main routine for the Asl Compiler. Handle command line 1002 * options and begin the compile for each file on the command line 1003 * 1004 ******************************************************************************/ 1005 1006int ACPI_SYSTEM_XFACE 1007main ( 1008 int argc, 1009 char **argv) 1010{ 1011 ACPI_STATUS Status; 1012 int Index1; 1013 int Index2; 1014 1015 1016 signal (SIGINT, AslSignalHandler); 1017 1018 AcpiGbl_ExternalFileList = NULL; 1019 AcpiDbgLevel = 0; 1020 1021#ifdef _DEBUG 1022 _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF | 1023 _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG)); 1024#endif 1025 1026 /* Init and command line */ 1027 1028 Index1 = Index2 = AslCommandLine (argc, argv); 1029 1030 AslInitialize (); 1031 PrInitializePreprocessor (); 1032 1033 /* Options that have no additional parameters or pathnames */ 1034 1035 if (Gbl_GetAllTables) 1036 { 1037 Status = AslDoOneFile (NULL); 1038 if (ACPI_FAILURE (Status)) 1039 { 1040 return (-1); 1041 } 1042 return (0); 1043 } 1044 1045 if (Gbl_DisassembleAll) 1046 { 1047 while (argv[Index1]) 1048 { 1049 Status = AslDoOnePathname (argv[Index1], AcpiDmAddToExternalFileList); 1050 if (ACPI_FAILURE (Status)) 1051 { 1052 return (-1); 1053 } 1054 1055 Index1++; 1056 } 1057 } 1058 1059 /* Process each pathname/filename in the list, with possible wildcards */ 1060 1061 while (argv[Index2]) 1062 { 1063 Status = AslDoOnePathname (argv[Index2], AslDoOneFile); 1064 if (ACPI_FAILURE (Status)) 1065 { 1066 return (-1); 1067 } 1068 1069 Index2++; 1070 } 1071 1072 if (AcpiGbl_ExternalFileList) 1073 { 1074 AcpiDmClearExternalFileList(); 1075 } 1076 1077 return (0); 1078} 1079