aslfiles.c revision 197104
1118611Snjl 2118611Snjl/****************************************************************************** 3118611Snjl * 4118611Snjl * Module Name: aslfiles - file I/O suppoert 5118611Snjl * 6118611Snjl *****************************************************************************/ 7118611Snjl 8118611Snjl/****************************************************************************** 9118611Snjl * 10118611Snjl * 1. Copyright Notice 11118611Snjl * 12193529Sjkim * Some or all of this work - Copyright (c) 1999 - 2009, 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 117151937Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h> 118193529Sjkim#include <contrib/dev/acpica/include/acapps.h> 119118611Snjl 120118611Snjl#define _COMPONENT ACPI_COMPILER 121118611Snjl ACPI_MODULE_NAME ("aslfiles") 122118611Snjl 123151937Sjkim/* Local prototypes */ 124118611Snjl 125151937Sjkimstatic void 126151937SjkimFlOpenFile ( 127151937Sjkim UINT32 FileId, 128151937Sjkim char *Filename, 129151937Sjkim char *Mode); 130151937Sjkim 131197104SjkimFILE * 132197104SjkimFlOpenIncludeWithPrefix ( 133197104Sjkim char *PrefixDir, 134197104Sjkim char *Filename); 135151937Sjkim 136197104Sjkim 137151937Sjkim#ifdef ACPI_OBSOLETE_FUNCTIONS 138151937SjkimACPI_STATUS 139151937SjkimFlParseInputPathname ( 140151937Sjkim char *InputFilename); 141151937Sjkim#endif 142151937Sjkim 143151937Sjkim 144118611Snjl/******************************************************************************* 145118611Snjl * 146118611Snjl * FUNCTION: AslAbort 147118611Snjl * 148118611Snjl * PARAMETERS: None 149118611Snjl * 150118611Snjl * RETURN: None 151118611Snjl * 152118611Snjl * DESCRIPTION: Dump the error log and abort the compiler. Used for serious 153118611Snjl * I/O errors 154118611Snjl * 155118611Snjl ******************************************************************************/ 156118611Snjl 157118611Snjlvoid 158151937SjkimAslAbort ( 159151937Sjkim void) 160118611Snjl{ 161118611Snjl 162118611Snjl AePrintErrorLog (ASL_FILE_STDOUT); 163118611Snjl if (Gbl_DebugFlag) 164118611Snjl { 165118611Snjl /* Print error summary to the debug file */ 166118611Snjl 167118611Snjl AePrintErrorLog (ASL_FILE_STDERR); 168118611Snjl } 169118611Snjl 170151937Sjkim exit (1); 171118611Snjl} 172118611Snjl 173118611Snjl 174118611Snjl/******************************************************************************* 175118611Snjl * 176118611Snjl * FUNCTION: FlFileError 177118611Snjl * 178118611Snjl * PARAMETERS: FileId - Index into file info array 179118611Snjl * ErrorId - Index into error message array 180118611Snjl * 181118611Snjl * RETURN: None 182118611Snjl * 183118611Snjl * DESCRIPTION: Decode errno to an error message and add the entire error 184118611Snjl * to the error log. 185118611Snjl * 186118611Snjl ******************************************************************************/ 187118611Snjl 188118611Snjlvoid 189118611SnjlFlFileError ( 190118611Snjl UINT32 FileId, 191118611Snjl UINT8 ErrorId) 192118611Snjl{ 193118611Snjl 194151937Sjkim sprintf (MsgBuffer, "\"%s\" (%s)", Gbl_Files[FileId].Filename, 195151937Sjkim strerror (errno)); 196118611Snjl AslCommonError (ASL_ERROR, ErrorId, 0, 0, 0, 0, NULL, MsgBuffer); 197118611Snjl} 198118611Snjl 199118611Snjl 200118611Snjl/******************************************************************************* 201118611Snjl * 202118611Snjl * FUNCTION: FlOpenFile 203118611Snjl * 204118611Snjl * PARAMETERS: FileId - Index into file info array 205118611Snjl * Filename - file pathname to open 206118611Snjl * Mode - Open mode for fopen 207118611Snjl * 208151937Sjkim * RETURN: None 209118611Snjl * 210118611Snjl * DESCRIPTION: Open a file. 211118611Snjl * NOTE: Aborts compiler on any error. 212118611Snjl * 213118611Snjl ******************************************************************************/ 214118611Snjl 215151937Sjkimstatic void 216118611SnjlFlOpenFile ( 217118611Snjl UINT32 FileId, 218118611Snjl char *Filename, 219118611Snjl char *Mode) 220118611Snjl{ 221118611Snjl FILE *File; 222118611Snjl 223118611Snjl 224118611Snjl File = fopen (Filename, Mode); 225118611Snjl 226118611Snjl Gbl_Files[FileId].Filename = Filename; 227118611Snjl Gbl_Files[FileId].Handle = File; 228118611Snjl 229118611Snjl if (!File) 230118611Snjl { 231118611Snjl FlFileError (FileId, ASL_MSG_OPEN); 232118611Snjl AslAbort (); 233118611Snjl } 234118611Snjl} 235118611Snjl 236118611Snjl 237118611Snjl/******************************************************************************* 238118611Snjl * 239118611Snjl * FUNCTION: FlReadFile 240118611Snjl * 241118611Snjl * PARAMETERS: FileId - Index into file info array 242118611Snjl * Buffer - Where to place the data 243118611Snjl * Length - Amount to read 244118611Snjl * 245118611Snjl * RETURN: Status. AE_ERROR indicates EOF. 246118611Snjl * 247118611Snjl * DESCRIPTION: Read data from an open file. 248118611Snjl * NOTE: Aborts compiler on any error. 249118611Snjl * 250118611Snjl ******************************************************************************/ 251118611Snjl 252118611SnjlACPI_STATUS 253118611SnjlFlReadFile ( 254118611Snjl UINT32 FileId, 255118611Snjl void *Buffer, 256118611Snjl UINT32 Length) 257118611Snjl{ 258118611Snjl UINT32 Actual; 259118611Snjl 260118611Snjl 261118611Snjl /* Read and check for error */ 262118611Snjl 263118611Snjl Actual = fread (Buffer, 1, Length, Gbl_Files[FileId].Handle); 264118611Snjl if (Actual != Length) 265118611Snjl { 266118611Snjl if (feof (Gbl_Files[FileId].Handle)) 267118611Snjl { 268118611Snjl /* End-of-file, just return error */ 269118611Snjl 270118611Snjl return (AE_ERROR); 271118611Snjl } 272118611Snjl 273118611Snjl FlFileError (FileId, ASL_MSG_READ); 274118611Snjl AslAbort (); 275118611Snjl } 276118611Snjl 277118611Snjl return (AE_OK); 278118611Snjl} 279118611Snjl 280118611Snjl 281118611Snjl/******************************************************************************* 282118611Snjl * 283118611Snjl * FUNCTION: FlWriteFile 284118611Snjl * 285118611Snjl * PARAMETERS: FileId - Index into file info array 286118611Snjl * Buffer - Data to write 287118611Snjl * Length - Amount of data to write 288118611Snjl * 289151937Sjkim * RETURN: None 290118611Snjl * 291118611Snjl * DESCRIPTION: Write data to an open file. 292118611Snjl * NOTE: Aborts compiler on any error. 293118611Snjl * 294118611Snjl ******************************************************************************/ 295118611Snjl 296118611Snjlvoid 297118611SnjlFlWriteFile ( 298118611Snjl UINT32 FileId, 299118611Snjl void *Buffer, 300118611Snjl UINT32 Length) 301118611Snjl{ 302118611Snjl UINT32 Actual; 303118611Snjl 304118611Snjl 305118611Snjl /* Write and check for error */ 306118611Snjl 307118611Snjl Actual = fwrite ((char *) Buffer, 1, Length, Gbl_Files[FileId].Handle); 308118611Snjl if (Actual != Length) 309118611Snjl { 310118611Snjl FlFileError (FileId, ASL_MSG_WRITE); 311118611Snjl AslAbort (); 312118611Snjl } 313118611Snjl} 314118611Snjl 315118611Snjl 316118611Snjl/******************************************************************************* 317118611Snjl * 318118611Snjl * FUNCTION: FlPrintFile 319118611Snjl * 320118611Snjl * PARAMETERS: FileId - Index into file info array 321118611Snjl * Format - Printf format string 322118611Snjl * ... - Printf arguments 323118611Snjl * 324118611Snjl * RETURN: None 325118611Snjl * 326118611Snjl * DESCRIPTION: Formatted write to an open file. 327118611Snjl * NOTE: Aborts compiler on any error. 328118611Snjl * 329118611Snjl ******************************************************************************/ 330118611Snjl 331118611Snjlvoid 332118611SnjlFlPrintFile ( 333118611Snjl UINT32 FileId, 334118611Snjl char *Format, 335118611Snjl ...) 336118611Snjl{ 337118611Snjl INT32 Actual; 338118611Snjl va_list Args; 339118611Snjl 340118611Snjl 341118611Snjl va_start (Args, Format); 342118611Snjl 343118611Snjl Actual = vfprintf (Gbl_Files[FileId].Handle, Format, Args); 344193529Sjkim va_end (Args); 345193529Sjkim 346118611Snjl if (Actual == -1) 347118611Snjl { 348118611Snjl FlFileError (FileId, ASL_MSG_WRITE); 349118611Snjl AslAbort (); 350118611Snjl } 351118611Snjl} 352118611Snjl 353118611Snjl 354118611Snjl/******************************************************************************* 355118611Snjl * 356118611Snjl * FUNCTION: FlSeekFile 357118611Snjl * 358118611Snjl * PARAMETERS: FileId - Index into file info array 359118611Snjl * Offset - Absolute byte offset in file 360118611Snjl * 361151937Sjkim * RETURN: None 362118611Snjl * 363118611Snjl * DESCRIPTION: Seek to absolute offset 364118611Snjl * NOTE: Aborts compiler on any error. 365118611Snjl * 366118611Snjl ******************************************************************************/ 367118611Snjl 368118611Snjlvoid 369118611SnjlFlSeekFile ( 370118611Snjl UINT32 FileId, 371118611Snjl long Offset) 372118611Snjl{ 373118611Snjl int Error; 374118611Snjl 375118611Snjl 376118611Snjl Error = fseek (Gbl_Files[FileId].Handle, Offset, SEEK_SET); 377118611Snjl if (Error) 378118611Snjl { 379118611Snjl FlFileError (FileId, ASL_MSG_SEEK); 380118611Snjl AslAbort (); 381118611Snjl } 382118611Snjl} 383118611Snjl 384118611Snjl 385118611Snjl/******************************************************************************* 386118611Snjl * 387118611Snjl * FUNCTION: FlCloseFile 388118611Snjl * 389118611Snjl * PARAMETERS: FileId - Index into file info array 390118611Snjl * 391151937Sjkim * RETURN: None 392118611Snjl * 393118611Snjl * DESCRIPTION: Close an open file. Aborts compiler on error 394118611Snjl * 395118611Snjl ******************************************************************************/ 396118611Snjl 397118611Snjlvoid 398118611SnjlFlCloseFile ( 399118611Snjl UINT32 FileId) 400118611Snjl{ 401118611Snjl int Error; 402118611Snjl 403118611Snjl 404118611Snjl if (!Gbl_Files[FileId].Handle) 405118611Snjl { 406118611Snjl return; 407118611Snjl } 408118611Snjl 409118611Snjl Error = fclose (Gbl_Files[FileId].Handle); 410118611Snjl Gbl_Files[FileId].Handle = NULL; 411118611Snjl 412118611Snjl if (Error) 413118611Snjl { 414118611Snjl FlFileError (FileId, ASL_MSG_CLOSE); 415118611Snjl AslAbort (); 416118611Snjl } 417118611Snjl 418118611Snjl return; 419118611Snjl} 420118611Snjl 421118611Snjl 422118611Snjl/******************************************************************************* 423118611Snjl * 424118611Snjl * FUNCTION: FlSetLineNumber 425118611Snjl * 426118611Snjl * PARAMETERS: Op - Parse node for the LINE asl statement 427118611Snjl * 428118611Snjl * RETURN: None. 429118611Snjl * 430118611Snjl * DESCRIPTION: Set the current line number 431118611Snjl * 432118611Snjl ******************************************************************************/ 433118611Snjl 434118611Snjlvoid 435118611SnjlFlSetLineNumber ( 436118611Snjl ACPI_PARSE_OBJECT *Op) 437118611Snjl{ 438118611Snjl 439118611Snjl Gbl_CurrentLineNumber = (UINT32) Op->Asl.Value.Integer; 440118611Snjl Gbl_LogicalLineNumber = (UINT32) Op->Asl.Value.Integer; 441118611Snjl} 442118611Snjl 443118611Snjl 444118611Snjl/******************************************************************************* 445118611Snjl * 446197104Sjkim * FUNCTION: FlAddIncludeDirectory 447197104Sjkim * 448197104Sjkim * PARAMETERS: Dir - Directory pathname string 449197104Sjkim * 450197104Sjkim * RETURN: None 451197104Sjkim * 452197104Sjkim * DESCRIPTION: Add a directory the list of include prefix directories. 453197104Sjkim * 454197104Sjkim ******************************************************************************/ 455197104Sjkim 456197104Sjkimvoid 457197104SjkimFlAddIncludeDirectory ( 458197104Sjkim char *Dir) 459197104Sjkim{ 460197104Sjkim ASL_INCLUDE_DIR *NewDir; 461197104Sjkim ASL_INCLUDE_DIR *NextDir; 462197104Sjkim ASL_INCLUDE_DIR *PrevDir = NULL; 463197104Sjkim UINT32 NeedsSeparator = 0; 464197104Sjkim size_t DirLength; 465197104Sjkim 466197104Sjkim 467197104Sjkim DirLength = strlen (Dir); 468197104Sjkim if (!DirLength) 469197104Sjkim { 470197104Sjkim return; 471197104Sjkim } 472197104Sjkim 473197104Sjkim /* Make sure that the pathname ends with a path separator */ 474197104Sjkim 475197104Sjkim if ((Dir[DirLength-1] != '/') && 476197104Sjkim (Dir[DirLength-1] != '\\')) 477197104Sjkim { 478197104Sjkim NeedsSeparator = 1; 479197104Sjkim } 480197104Sjkim 481197104Sjkim NewDir = ACPI_ALLOCATE_ZEROED (sizeof (ASL_INCLUDE_DIR)); 482197104Sjkim NewDir->Dir = ACPI_ALLOCATE (DirLength + 1 + NeedsSeparator); 483197104Sjkim strcpy (NewDir->Dir, Dir); 484197104Sjkim if (NeedsSeparator) 485197104Sjkim { 486197104Sjkim strcat (NewDir->Dir, "/"); 487197104Sjkim } 488197104Sjkim 489197104Sjkim /* 490197104Sjkim * Preserve command line ordering of -I options by adding new elements 491197104Sjkim * at the end of the list 492197104Sjkim */ 493197104Sjkim NextDir = Gbl_IncludeDirList; 494197104Sjkim while (NextDir) 495197104Sjkim { 496197104Sjkim PrevDir = NextDir; 497197104Sjkim NextDir = NextDir->Next; 498197104Sjkim } 499197104Sjkim 500197104Sjkim if (PrevDir) 501197104Sjkim { 502197104Sjkim PrevDir->Next = NewDir; 503197104Sjkim } 504197104Sjkim else 505197104Sjkim { 506197104Sjkim Gbl_IncludeDirList = NewDir; 507197104Sjkim } 508197104Sjkim} 509197104Sjkim 510197104Sjkim 511197104Sjkim/******************************************************************************* 512197104Sjkim * 513197104Sjkim * FUNCTION: FlOpenIncludeWithPrefix 514197104Sjkim * 515197104Sjkim * PARAMETERS: PrefixDir - Prefix directory pathname. Can be a zero 516197104Sjkim * length string. 517197104Sjkim * Filename - The include filename from the source ASL. 518197104Sjkim * 519197104Sjkim * RETURN: Valid file descriptor if successful. Null otherwise. 520197104Sjkim * 521197104Sjkim * DESCRIPTION: Open an include file and push it on the input file stack. 522197104Sjkim * 523197104Sjkim ******************************************************************************/ 524197104Sjkim 525197104SjkimFILE * 526197104SjkimFlOpenIncludeWithPrefix ( 527197104Sjkim char *PrefixDir, 528197104Sjkim char *Filename) 529197104Sjkim{ 530197104Sjkim FILE *IncludeFile; 531197104Sjkim char *Pathname; 532197104Sjkim 533197104Sjkim 534197104Sjkim /* Build the full pathname to the file */ 535197104Sjkim 536197104Sjkim Pathname = ACPI_ALLOCATE (strlen (PrefixDir) + strlen (Filename) + 1); 537197104Sjkim 538197104Sjkim strcpy (Pathname, PrefixDir); 539197104Sjkim strcat (Pathname, Filename); 540197104Sjkim 541197104Sjkim DbgPrint (ASL_PARSE_OUTPUT, "\nAttempt to open include file: path %s\n\n", 542197104Sjkim Pathname); 543197104Sjkim 544197104Sjkim /* Attempt to open the file, push if successful */ 545197104Sjkim 546197104Sjkim IncludeFile = fopen (Pathname, "r"); 547197104Sjkim if (IncludeFile) 548197104Sjkim { 549197104Sjkim /* Push the include file on the open input file stack */ 550197104Sjkim 551197104Sjkim AslPushInputFileStack (IncludeFile, Pathname); 552197104Sjkim return (IncludeFile); 553197104Sjkim } 554197104Sjkim 555197104Sjkim ACPI_FREE (Pathname); 556197104Sjkim return (NULL); 557197104Sjkim} 558197104Sjkim 559197104Sjkim 560197104Sjkim/******************************************************************************* 561197104Sjkim * 562118611Snjl * FUNCTION: FlOpenIncludeFile 563118611Snjl * 564118611Snjl * PARAMETERS: Op - Parse node for the INCLUDE ASL statement 565118611Snjl * 566118611Snjl * RETURN: None. 567118611Snjl * 568118611Snjl * DESCRIPTION: Open an include file and push it on the input file stack. 569118611Snjl * 570118611Snjl ******************************************************************************/ 571118611Snjl 572118611Snjlvoid 573118611SnjlFlOpenIncludeFile ( 574118611Snjl ACPI_PARSE_OBJECT *Op) 575118611Snjl{ 576197104Sjkim FILE *IncludeFile; 577197104Sjkim ASL_INCLUDE_DIR *NextDir; 578118611Snjl 579118611Snjl 580118611Snjl /* Op must be valid */ 581118611Snjl 582118611Snjl if (!Op) 583118611Snjl { 584118611Snjl AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, 585118611Snjl Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, 586118611Snjl Gbl_InputByteCount, Gbl_CurrentColumn, 587118611Snjl Gbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node"); 588118611Snjl 589118611Snjl return; 590118611Snjl } 591118611Snjl 592118611Snjl /* 593118611Snjl * Flush out the "include ()" statement on this line, start 594118611Snjl * the actual include file on the next line 595118611Snjl */ 596118611Snjl ResetCurrentLineBuffer (); 597118611Snjl FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n"); 598118611Snjl Gbl_CurrentLineOffset++; 599118611Snjl 600118611Snjl 601197104Sjkim /* Attempt to open the include file */ 602197104Sjkim 603197104Sjkim /* If the file specifies an absolute path, just open it */ 604197104Sjkim 605197104Sjkim if ((Op->Asl.Value.String[0] == '/') || 606197104Sjkim (Op->Asl.Value.String[0] == '\\') || 607197104Sjkim (Op->Asl.Value.String[1] == ':')) 608118611Snjl { 609197104Sjkim IncludeFile = FlOpenIncludeWithPrefix ("", Op->Asl.Value.String); 610197104Sjkim if (!IncludeFile) 611197104Sjkim { 612197104Sjkim goto ErrorExit; 613197104Sjkim } 614118611Snjl return; 615118611Snjl } 616118611Snjl 617197104Sjkim /* 618197104Sjkim * The include filename is not an absolute path. 619197104Sjkim * 620197104Sjkim * First, search for the file within the "local" directory -- meaning 621197104Sjkim * the same directory that contains the source file. 622197104Sjkim * 623197104Sjkim * Construct the file pathname from the global directory name. 624197104Sjkim */ 625197104Sjkim IncludeFile = FlOpenIncludeWithPrefix (Gbl_DirectoryPath, Op->Asl.Value.String); 626197104Sjkim if (IncludeFile) 627197104Sjkim { 628197104Sjkim return; 629197104Sjkim } 630118611Snjl 631197104Sjkim /* 632197104Sjkim * Second, search for the file within the (possibly multiple) directories 633197104Sjkim * specified by the -I option on the command line. 634197104Sjkim */ 635197104Sjkim NextDir = Gbl_IncludeDirList; 636197104Sjkim while (NextDir) 637197104Sjkim { 638197104Sjkim IncludeFile = FlOpenIncludeWithPrefix (NextDir->Dir, Op->Asl.Value.String); 639197104Sjkim if (IncludeFile) 640197104Sjkim { 641197104Sjkim return; 642197104Sjkim } 643197104Sjkim 644197104Sjkim NextDir = NextDir->Next; 645197104Sjkim } 646197104Sjkim 647197104Sjkim /* We could not open the include file after trying very hard */ 648197104Sjkim 649197104SjkimErrorExit: 650197104Sjkim sprintf (MsgBuffer, "%s, %s", Op->Asl.Value.String, strerror (errno)); 651197104Sjkim AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, MsgBuffer); 652118611Snjl} 653118611Snjl 654118611Snjl 655118611Snjl/******************************************************************************* 656118611Snjl * 657118611Snjl * FUNCTION: FlOpenInputFile 658118611Snjl * 659118611Snjl * PARAMETERS: InputFilename - The user-specified ASL source file to be 660118611Snjl * compiled 661118611Snjl * 662118611Snjl * RETURN: Status 663118611Snjl * 664118611Snjl * DESCRIPTION: Open the specified input file, and save the directory path to 665118611Snjl * the file so that include files can be opened in 666118611Snjl * the same directory. 667118611Snjl * 668118611Snjl ******************************************************************************/ 669118611Snjl 670118611SnjlACPI_STATUS 671118611SnjlFlOpenInputFile ( 672118611Snjl char *InputFilename) 673118611Snjl{ 674118611Snjl 675118611Snjl /* Open the input ASL file, text mode */ 676118611Snjl 677118611Snjl FlOpenFile (ASL_FILE_INPUT, InputFilename, "r"); 678118611Snjl AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle; 679118611Snjl 680118611Snjl return (AE_OK); 681118611Snjl} 682118611Snjl 683118611Snjl 684118611Snjl/******************************************************************************* 685118611Snjl * 686118611Snjl * FUNCTION: FlOpenAmlOutputFile 687118611Snjl * 688118611Snjl * PARAMETERS: FilenamePrefix - The user-specified ASL source file 689118611Snjl * 690118611Snjl * RETURN: Status 691118611Snjl * 692118611Snjl * DESCRIPTION: Create the output filename (*.AML) and open the file. The file 693118611Snjl * is created in the same directory as the parent input file. 694118611Snjl * 695118611Snjl ******************************************************************************/ 696118611Snjl 697118611SnjlACPI_STATUS 698118611SnjlFlOpenAmlOutputFile ( 699118611Snjl char *FilenamePrefix) 700118611Snjl{ 701118611Snjl char *Filename; 702118611Snjl 703118611Snjl 704118611Snjl /* Output filename usually comes from the ASL itself */ 705118611Snjl 706118611Snjl Filename = Gbl_Files[ASL_FILE_AML_OUTPUT].Filename; 707118611Snjl if (!Filename) 708118611Snjl { 709118611Snjl /* Create the output AML filename */ 710118611Snjl 711118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE); 712118611Snjl if (!Filename) 713118611Snjl { 714151937Sjkim AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME, 715151937Sjkim 0, 0, 0, 0, NULL, NULL); 716118611Snjl return (AE_ERROR); 717118611Snjl } 718118611Snjl } 719118611Snjl 720118611Snjl /* Open the output AML file in binary mode */ 721118611Snjl 722118611Snjl FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b"); 723118611Snjl return (AE_OK); 724118611Snjl} 725118611Snjl 726118611Snjl 727118611Snjl/******************************************************************************* 728118611Snjl * 729118611Snjl * FUNCTION: FlOpenMiscOutputFiles 730118611Snjl * 731118611Snjl * PARAMETERS: FilenamePrefix - The user-specified ASL source file 732118611Snjl * 733118611Snjl * RETURN: Status 734118611Snjl * 735118611Snjl * DESCRIPTION: Create and open the various output files needed, depending on 736118611Snjl * the command line options 737118611Snjl * 738118611Snjl ******************************************************************************/ 739118611Snjl 740118611SnjlACPI_STATUS 741118611SnjlFlOpenMiscOutputFiles ( 742118611Snjl char *FilenamePrefix) 743118611Snjl{ 744118611Snjl char *Filename; 745118611Snjl 746118611Snjl 747118611Snjl /* Create/Open a combined source output file */ 748118611Snjl 749118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE); 750118611Snjl if (!Filename) 751118611Snjl { 752151937Sjkim AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 753151937Sjkim 0, 0, 0, 0, NULL, NULL); 754118611Snjl return (AE_ERROR); 755118611Snjl } 756118611Snjl 757118611Snjl /* 758118611Snjl * Open the source output file, binary mode (so that LF does not get 759118611Snjl * expanded to CR/LF on some systems, messing up our seek 760118611Snjl * calculations.) 761118611Snjl */ 762118611Snjl FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b"); 763118611Snjl 764118611Snjl /* Create/Open a listing output file if asked */ 765118611Snjl 766118611Snjl if (Gbl_ListingFlag) 767118611Snjl { 768118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING); 769118611Snjl if (!Filename) 770118611Snjl { 771151937Sjkim AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 772151937Sjkim 0, 0, 0, 0, NULL, NULL); 773118611Snjl return (AE_ERROR); 774118611Snjl } 775118611Snjl 776118611Snjl /* Open the listing file, text mode */ 777118611Snjl 778118611Snjl FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+"); 779118611Snjl 780118611Snjl AslCompilerSignon (ASL_FILE_LISTING_OUTPUT); 781118611Snjl AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT); 782118611Snjl } 783118611Snjl 784118611Snjl /* Create/Open a assembly code source output file if asked */ 785118611Snjl 786118611Snjl if (Gbl_AsmOutputFlag) 787118611Snjl { 788118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE); 789118611Snjl if (!Filename) 790118611Snjl { 791151937Sjkim AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 792151937Sjkim 0, 0, 0, 0, NULL, NULL); 793118611Snjl return (AE_ERROR); 794118611Snjl } 795118611Snjl 796118611Snjl /* Open the assembly code source file, text mode */ 797118611Snjl 798118611Snjl FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+"); 799118611Snjl 800118611Snjl AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT); 801118611Snjl AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT); 802118611Snjl } 803118611Snjl 804118611Snjl /* Create/Open a C code source output file if asked */ 805118611Snjl 806118611Snjl if (Gbl_C_OutputFlag) 807118611Snjl { 808118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE); 809118611Snjl if (!Filename) 810118611Snjl { 811151937Sjkim AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 812151937Sjkim 0, 0, 0, 0, NULL, NULL); 813118611Snjl return (AE_ERROR); 814118611Snjl } 815118611Snjl 816118611Snjl /* Open the C code source file, text mode */ 817118611Snjl 818118611Snjl FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+"); 819118611Snjl 820118611Snjl FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n"); 821118611Snjl AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT); 822118611Snjl AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT); 823118611Snjl } 824118611Snjl 825118611Snjl /* Create/Open a assembly include output file if asked */ 826118611Snjl 827118611Snjl if (Gbl_AsmIncludeOutputFlag) 828118611Snjl { 829118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE); 830118611Snjl if (!Filename) 831118611Snjl { 832151937Sjkim AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 833151937Sjkim 0, 0, 0, 0, NULL, NULL); 834118611Snjl return (AE_ERROR); 835118611Snjl } 836118611Snjl 837118611Snjl /* Open the assembly include file, text mode */ 838118611Snjl 839118611Snjl FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+"); 840118611Snjl 841118611Snjl AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT); 842118611Snjl AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT); 843118611Snjl } 844118611Snjl 845118611Snjl /* Create/Open a C include output file if asked */ 846118611Snjl 847118611Snjl if (Gbl_C_IncludeOutputFlag) 848118611Snjl { 849118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE); 850118611Snjl if (!Filename) 851118611Snjl { 852151937Sjkim AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 853151937Sjkim 0, 0, 0, 0, NULL, NULL); 854118611Snjl return (AE_ERROR); 855118611Snjl } 856118611Snjl 857118611Snjl /* Open the C include file, text mode */ 858118611Snjl 859118611Snjl FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+"); 860118611Snjl 861118611Snjl FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n"); 862118611Snjl AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT); 863118611Snjl AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT); 864118611Snjl } 865118611Snjl 866118611Snjl /* Create/Open a hex output file if asked */ 867118611Snjl 868118611Snjl if (Gbl_HexOutputFlag) 869118611Snjl { 870118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP); 871118611Snjl if (!Filename) 872118611Snjl { 873151937Sjkim AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 874151937Sjkim 0, 0, 0, 0, NULL, NULL); 875118611Snjl return (AE_ERROR); 876118611Snjl } 877118611Snjl 878118611Snjl /* Open the hex file, text mode */ 879118611Snjl 880118611Snjl FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+"); 881118611Snjl 882118611Snjl AslCompilerSignon (ASL_FILE_HEX_OUTPUT); 883118611Snjl AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT); 884118611Snjl } 885118611Snjl 886118611Snjl /* Create a namespace output file if asked */ 887118611Snjl 888118611Snjl if (Gbl_NsOutputFlag) 889118611Snjl { 890118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE); 891118611Snjl if (!Filename) 892118611Snjl { 893151937Sjkim AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 894151937Sjkim 0, 0, 0, 0, NULL, NULL); 895118611Snjl return (AE_ERROR); 896118611Snjl } 897118611Snjl 898118611Snjl /* Open the namespace file, text mode */ 899118611Snjl 900118611Snjl FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+"); 901118611Snjl 902118611Snjl AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT); 903118611Snjl AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT); 904118611Snjl } 905118611Snjl 906118611Snjl /* Create/Open a debug output file if asked */ 907118611Snjl 908118611Snjl if (Gbl_DebugFlag) 909118611Snjl { 910118611Snjl Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG); 911118611Snjl if (!Filename) 912118611Snjl { 913151937Sjkim AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME, 914151937Sjkim 0, 0, 0, 0, NULL, NULL); 915118611Snjl return (AE_ERROR); 916118611Snjl } 917118611Snjl 918118611Snjl /* Open the debug file as STDERR, text mode */ 919118611Snjl 920118611Snjl /* TBD: hide this behind a FlReopenFile function */ 921118611Snjl 922118611Snjl Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename; 923151937Sjkim Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle = 924151937Sjkim freopen (Filename, "w+t", stderr); 925118611Snjl 926118611Snjl AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT); 927118611Snjl AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT); 928118611Snjl } 929118611Snjl 930118611Snjl return (AE_OK); 931118611Snjl} 932118611Snjl 933118611Snjl 934151937Sjkim#ifdef ACPI_OBSOLETE_FUNCTIONS 935151937Sjkim/******************************************************************************* 936151937Sjkim * 937151937Sjkim * FUNCTION: FlParseInputPathname 938151937Sjkim * 939151937Sjkim * PARAMETERS: InputFilename - The user-specified ASL source file to be 940151937Sjkim * compiled 941151937Sjkim * 942151937Sjkim * RETURN: Status 943151937Sjkim * 944151937Sjkim * DESCRIPTION: Split the input path into a directory and filename part 945151937Sjkim * 1) Directory part used to open include files 946151937Sjkim * 2) Filename part used to generate output filenames 947151937Sjkim * 948151937Sjkim ******************************************************************************/ 949151937Sjkim 950151937SjkimACPI_STATUS 951151937SjkimFlParseInputPathname ( 952151937Sjkim char *InputFilename) 953151937Sjkim{ 954151937Sjkim char *Substring; 955151937Sjkim 956151937Sjkim 957151937Sjkim if (!InputFilename) 958151937Sjkim { 959151937Sjkim return (AE_OK); 960151937Sjkim } 961151937Sjkim 962151937Sjkim /* Get the path to the input filename's directory */ 963151937Sjkim 964151937Sjkim Gbl_DirectoryPath = strdup (InputFilename); 965151937Sjkim if (!Gbl_DirectoryPath) 966151937Sjkim { 967151937Sjkim return (AE_NO_MEMORY); 968151937Sjkim } 969151937Sjkim 970151937Sjkim Substring = strrchr (Gbl_DirectoryPath, '\\'); 971151937Sjkim if (!Substring) 972151937Sjkim { 973151937Sjkim Substring = strrchr (Gbl_DirectoryPath, '/'); 974151937Sjkim if (!Substring) 975151937Sjkim { 976151937Sjkim Substring = strrchr (Gbl_DirectoryPath, ':'); 977151937Sjkim } 978151937Sjkim } 979151937Sjkim 980151937Sjkim if (!Substring) 981151937Sjkim { 982151937Sjkim Gbl_DirectoryPath[0] = 0; 983151937Sjkim if (Gbl_UseDefaultAmlFilename) 984151937Sjkim { 985151937Sjkim Gbl_OutputFilenamePrefix = strdup (InputFilename); 986151937Sjkim } 987151937Sjkim } 988151937Sjkim else 989151937Sjkim { 990151937Sjkim if (Gbl_UseDefaultAmlFilename) 991151937Sjkim { 992151937Sjkim Gbl_OutputFilenamePrefix = strdup (Substring + 1); 993151937Sjkim } 994151937Sjkim *(Substring+1) = 0; 995151937Sjkim } 996151937Sjkim 997151937Sjkim return (AE_OK); 998151937Sjkim} 999151937Sjkim#endif 1000151937Sjkim 1001151937Sjkim 1002