aslfiles.c revision 209746
113547Sjulian 213547Sjulian/****************************************************************************** 335025Sjb * 413547Sjulian * Module Name: aslfiles - file I/O suppoert 513547Sjulian * 613547Sjulian *****************************************************************************/ 713547Sjulian 813547Sjulian/****************************************************************************** 913547Sjulian * 1013547Sjulian * 1. Copyright Notice 1113547Sjulian * 1213547Sjulian * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp. 1313547Sjulian * All rights reserved. 1413547Sjulian * 1513547Sjulian * 2. License 1613547Sjulian * 1713547Sjulian * 2.1. This is your license from Intel Corp. under its intellectual property 1813547Sjulian * rights. You may have additional license terms from the party that provided 1913547Sjulian * you this software, covering your right to use that party's intellectual 2013547Sjulian * property rights. 2113547Sjulian * 2213547Sjulian * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 2313547Sjulian * copy of the source code appearing in this file ("Covered Code") an 2413547Sjulian * irrevocable, perpetual, worldwide license under Intel's copyrights in the 2513547Sjulian * base code distributed originally by Intel ("Original Intel Code") to copy, 2613547Sjulian * make derivatives, distribute, use and display any portion of the Covered 2713547Sjulian * Code in any form, with the right to sublicense such rights; and 2813547Sjulian * 2913547Sjulian * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 3013547Sjulian * license (with the right to sublicense), under only those claims of Intel 3113547Sjulian * patents that are infringed by the Original Intel Code, to make, use, sell, 3213547Sjulian * offer to sell, and import the Covered Code and derivative works thereof 3350473Speter * solely to the minimum extent necessary to exercise the above copyright 3413547Sjulian * license, and in no event shall the patent license extend to any additions 3513547Sjulian * to or modifications of the Original Intel Code. No other license or right 3613547Sjulian * is granted directly or by implication, estoppel or otherwise; 3713547Sjulian * 3813547Sjulian * The above copyright and patent license is granted only if the following 3913547Sjulian * conditions are met: 4013547Sjulian * 4113547Sjulian * 3. Conditions 4213547Sjulian * 4313547Sjulian * 3.1. Redistribution of Source with Rights to Further Distribute Source. 4417706Sjulian * Redistribution of source code of any substantial portion of the Covered 4517706Sjulian * Code or modification with rights to further distribute source must include 4644965Sjb * the above Copyright Notice, the above License, this list of Conditions, 4713547Sjulian * and the following Disclaimer and Export Compliance provision. In addition, 4813547Sjulian * Licensee must cause all Covered Code to which Licensee contributes to 4917706Sjulian * contain a file documenting the changes Licensee made to create that Covered 5013547Sjulian * Code and the date of any change. Licensee must include in that file the 5117706Sjulian * documentation of any changes made by any predecessor Licensee. Licensee 5217706Sjulian * must include a prominent statement that the modification is derived, 5317706Sjulian * directly or indirectly, from Original Intel Code. 5417706Sjulian * 5513547Sjulian * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 5613547Sjulian * Redistribution of source code of any substantial portion of the Covered 5722315Sjulian * Code or modification without rights to further distribute source must 5822315Sjulian * include the following Disclaimer and Export Compliance provision in the 5922315Sjulian * documentation and/or other materials provided with distribution. In 6022315Sjulian * addition, Licensee may not authorize further sublicense of source of any 6122315Sjulian * portion of the Covered Code, and must include terms to the effect that the 6222315Sjulian * license from Licensee to its licensee is limited to the intellectual 6322315Sjulian * property embodied in the software Licensee provides to its licensee, and 6422315Sjulian * not to intellectual property embodied in modifications its licensee may 6522315Sjulian * make. 6622315Sjulian * 6722315Sjulian * 3.3. Redistribution of Executable. Redistribution in executable form of any 6822315Sjulian * substantial portion of the Covered Code or modification must reproduce the 6922315Sjulian * above Copyright Notice, and the following Disclaimer and Export Compliance 7038919Salex * provision in the documentation and/or other materials provided with the 7138919Salex * distribution. 7238919Salex * 7338919Salex * 3.4. Intel retains all right, title, and interest in and to the Original 7438919Salex * Intel Code. 7538919Salex * 7653812Salfred * 3.5. Neither the name Intel nor any other trademark owned or controlled by 7753812Salfred * Intel shall be used in advertising or otherwise to promote the sale, use or 7853812Salfred * other dealings in products derived from or relating to the Covered Code 7953812Salfred * without prior written authorization from Intel. 8053812Salfred * 8153812Salfred * 4. Disclaimer and Export Compliance 8253812Salfred * 8353812Salfred * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 8453812Salfred * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 8517706Sjulian * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 8617706Sjulian * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 8717706Sjulian * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 8813547Sjulian * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 8917706Sjulian * PARTICULAR PURPOSE. 9017706Sjulian * 9117706Sjulian * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 9217706Sjulian * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 9317706Sjulian * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 9417706Sjulian * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 9517706Sjulian * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 9638919Salex * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 9738919Salex * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 9813547Sjulian * LIMITED REMEDY. 9913547Sjulian * 10017706Sjulian * 4.3. Licensee shall not export, either directly or indirectly, any of this 10117706Sjulian * software or system incorporating such software without first obtaining any 10217706Sjulian * required license or other approval from the U. S. Department of Commerce or 10317706Sjulian * any other agency or department of the United States Government. In the 10417706Sjulian * event Licensee exports any such software from the United States or 10513547Sjulian * re-exports any such software from a foreign destination, Licensee shall 10617706Sjulian * ensure that the distribution and export/re-export of the software is in 10717706Sjulian * compliance with all laws, regulations, orders, or other restrictions of the 10817706Sjulian * U.S. Export Administration Regulations. Licensee agrees that neither it nor 10917706Sjulian * any of its subsidiaries will export/re-export any technical data, process, 11017706Sjulian * software, or service, directly or indirectly, to any country for which the 11117706Sjulian * United States government or any agency thereof requires an export license, 11217706Sjulian * other governmental approval, or letter of assurance, without first obtaining 11317706Sjulian * such license, approval or letter. 11438919Salex * 11538919Salex *****************************************************************************/ 11613547Sjulian 11713547Sjulian#include <contrib/dev/acpica/compiler/aslcompiler.h> 11817706Sjulian#include <contrib/dev/acpica/include/acapps.h> 11917706Sjulian 12017706Sjulian#define _COMPONENT ACPI_COMPILER 12117706Sjulian ACPI_MODULE_NAME ("aslfiles") 12213547Sjulian 12317706Sjulian/* Local prototypes */ 12493032Simp 12513547SjulianFILE * 12613547SjulianFlOpenIncludeWithPrefix ( 12713547Sjulian char *PrefixDir, 12813547Sjulian char *Filename); 12913547Sjulian 13017706Sjulian 13117706Sjulian#ifdef ACPI_OBSOLETE_FUNCTIONS 13213547SjulianACPI_STATUS 13313547SjulianFlParseInputPathname ( 13413547Sjulian char *InputFilename); 13513547Sjulian#endif 13613547Sjulian 13713547Sjulian 13813547Sjulian/******************************************************************************* 13913547Sjulian * 14013547Sjulian * FUNCTION: AslAbort 14113547Sjulian * 14213547Sjulian * PARAMETERS: None 14317706Sjulian * 14413547Sjulian * RETURN: None 14513547Sjulian * 14635025Sjb * DESCRIPTION: Dump the error log and abort the compiler. Used for serious 14713547Sjulian * I/O errors 14835025Sjb * 14935025Sjb ******************************************************************************/ 15038919Salex 15135025Sjbvoid 15235025SjbAslAbort ( 15335025Sjb void) 15435025Sjb{ 15522315Sjulian 15613547Sjulian AePrintErrorLog (ASL_FILE_STDOUT); 15713547Sjulian if (Gbl_DebugFlag) 15813547Sjulian { 15913547Sjulian /* Print error summary to the debug file */ 16013547Sjulian 16144965Sjb AePrintErrorLog (ASL_FILE_STDERR); 16244965Sjb } 16344965Sjb 16444965Sjb exit (1); 16544965Sjb} 16644965Sjb 16744965Sjb 16844965Sjb/******************************************************************************* 16944965Sjb * 17044965Sjb * FUNCTION: FlFileError 17144965Sjb * 17244965Sjb * PARAMETERS: FileId - Index into file info array 17344965Sjb * ErrorId - Index into error message array 17444965Sjb * 17544965Sjb * RETURN: None 17644965Sjb * 17719637Shsu * DESCRIPTION: Decode errno to an error message and add the entire error 17844965Sjb * to the error log. 17944965Sjb * 18044965Sjb ******************************************************************************/ 18119637Shsu 18219637Shsuvoid 18319637ShsuFlFileError ( 18444965Sjb UINT32 FileId, 18544965Sjb UINT8 ErrorId) 18641390Seivind{ 18741390Seivind 18813547Sjulian sprintf (MsgBuffer, "\"%s\" (%s)", Gbl_Files[FileId].Filename, 18913547Sjulian strerror (errno)); 19013547Sjulian AslCommonError (ASL_ERROR, ErrorId, 0, 0, 0, 0, NULL, MsgBuffer); 19113547Sjulian} 19293032Simp 19393032Simp 19493032Simp/******************************************************************************* 19593032Simp * 19693032Simp * FUNCTION: FlOpenFile 19793032Simp * 19893032Simp * PARAMETERS: FileId - Index into file info array 19993032Simp * Filename - file pathname to open 20093032Simp * Mode - Open mode for fopen 20193032Simp * 20293032Simp * RETURN: None 20393032Simp * 20493032Simp * DESCRIPTION: Open a file. 20593032Simp * NOTE: Aborts compiler on any error. 20644965Sjb * 20744965Sjb ******************************************************************************/ 20893032Simp 20993032Simpvoid 21044965SjbFlOpenFile ( 21144965Sjb UINT32 FileId, 21293032Simp char *Filename, 21393032Simp char *Mode) 21493032Simp{ 21593032Simp FILE *File; 21693032Simp 21793032Simp 21893032Simp File = fopen (Filename, Mode); 21993032Simp 22093032Simp Gbl_Files[FileId].Filename = Filename; 22193032Simp Gbl_Files[FileId].Handle = File; 22293032Simp 22393032Simp if (!File) 22493032Simp { 22593032Simp FlFileError (FileId, ASL_MSG_OPEN); 22693032Simp AslAbort (); 22793032Simp } 22893032Simp} 22993032Simp 23093032Simp 23193032Simp/******************************************************************************* 23293032Simp * 23393032Simp * FUNCTION: FlGetFileSize 23493032Simp * 23593032Simp * PARAMETERS: FileId - Index into file info array 23693032Simp * 23793032Simp * RETURN: File Size 23893032Simp * 23993032Simp * DESCRIPTION: Get current file size. Uses seek-to-EOF. File must be open. 24093032Simp * 24193032Simp ******************************************************************************/ 24293032Simp 24393032SimpUINT32 24493032SimpFlGetFileSize ( 24593032Simp UINT32 FileId) 24693032Simp{ 24793032Simp FILE *fp; 24893032Simp UINT32 FileSize; 24993032Simp 25093032Simp 25193032Simp fp = Gbl_Files[FileId].Handle; 25293032Simp 25393032Simp fseek (fp, 0, SEEK_END); 25493032Simp FileSize = (UINT32) ftell (fp); 25593032Simp fseek (fp, 0, SEEK_SET); 25693032Simp 25793032Simp return (FileSize); 25817706Sjulian} 25993032Simp 26093032Simp 26193032Simp/******************************************************************************* 26293032Simp * 26317706Sjulian * FUNCTION: FlReadFile 26493032Simp * 26593032Simp * PARAMETERS: FileId - Index into file info array 26693032Simp * Buffer - Where to place the data 26744965Sjb * Length - Amount to read 26844965Sjb * 26993032Simp * RETURN: Status. AE_ERROR indicates EOF. 27093032Simp * 27193032Simp * DESCRIPTION: Read data from an open file. 27293032Simp * NOTE: Aborts compiler on any error. 27344965Sjb * 27444965Sjb ******************************************************************************/ 27593032Simp 27693032SimpACPI_STATUS 27793032SimpFlReadFile ( 27893032Simp UINT32 FileId, 27993032Simp void *Buffer, 28093032Simp UINT32 Length) 28144965Sjb{ 28293032Simp UINT32 Actual; 28393032Simp 28444965Sjb 28593032Simp /* Read and check for error */ 28693032Simp 28793032Simp Actual = fread (Buffer, 1, Length, Gbl_Files[FileId].Handle); 28893032Simp if (Actual != Length) 28993032Simp { 29093032Simp if (feof (Gbl_Files[FileId].Handle)) 29193032Simp { 29293032Simp /* End-of-file, just return error */ 29393032Simp 29493032Simp return (AE_ERROR); 29593032Simp } 29693032Simp 29793032Simp FlFileError (FileId, ASL_MSG_READ); 29893032Simp AslAbort (); 29913547Sjulian } 30013547Sjulian 30113547Sjulian return (AE_OK); 302} 303 304 305/******************************************************************************* 306 * 307 * FUNCTION: FlWriteFile 308 * 309 * PARAMETERS: FileId - Index into file info array 310 * Buffer - Data to write 311 * Length - Amount of data to write 312 * 313 * RETURN: None 314 * 315 * DESCRIPTION: Write data to an open file. 316 * NOTE: Aborts compiler on any error. 317 * 318 ******************************************************************************/ 319 320void 321FlWriteFile ( 322 UINT32 FileId, 323 void *Buffer, 324 UINT32 Length) 325{ 326 UINT32 Actual; 327 328 329 /* Write and check for error */ 330 331 Actual = fwrite ((char *) Buffer, 1, Length, Gbl_Files[FileId].Handle); 332 if (Actual != Length) 333 { 334 FlFileError (FileId, ASL_MSG_WRITE); 335 AslAbort (); 336 } 337} 338 339 340/******************************************************************************* 341 * 342 * FUNCTION: FlPrintFile 343 * 344 * PARAMETERS: FileId - Index into file info array 345 * Format - Printf format string 346 * ... - Printf arguments 347 * 348 * RETURN: None 349 * 350 * DESCRIPTION: Formatted write to an open file. 351 * NOTE: Aborts compiler on any error. 352 * 353 ******************************************************************************/ 354 355void 356FlPrintFile ( 357 UINT32 FileId, 358 char *Format, 359 ...) 360{ 361 INT32 Actual; 362 va_list Args; 363 364 365 va_start (Args, Format); 366 367 Actual = vfprintf (Gbl_Files[FileId].Handle, Format, Args); 368 va_end (Args); 369 370 if (Actual == -1) 371 { 372 FlFileError (FileId, ASL_MSG_WRITE); 373 AslAbort (); 374 } 375} 376 377 378/******************************************************************************* 379 * 380 * FUNCTION: FlSeekFile 381 * 382 * PARAMETERS: FileId - Index into file info array 383 * Offset - Absolute byte offset in file 384 * 385 * RETURN: None 386 * 387 * DESCRIPTION: Seek to absolute offset 388 * NOTE: Aborts compiler on any error. 389 * 390 ******************************************************************************/ 391 392void 393FlSeekFile ( 394 UINT32 FileId, 395 long Offset) 396{ 397 int Error; 398 399 400 Error = fseek (Gbl_Files[FileId].Handle, Offset, SEEK_SET); 401 if (Error) 402 { 403 FlFileError (FileId, ASL_MSG_SEEK); 404 AslAbort (); 405 } 406} 407 408 409/******************************************************************************* 410 * 411 * FUNCTION: FlCloseFile 412 * 413 * PARAMETERS: FileId - Index into file info array 414 * 415 * RETURN: None 416 * 417 * DESCRIPTION: Close an open file. Aborts compiler on error 418 * 419 ******************************************************************************/ 420 421void 422FlCloseFile ( 423 UINT32 FileId) 424{ 425 int Error; 426 427 428 if (!Gbl_Files[FileId].Handle) 429 { 430 return; 431 } 432 433 Error = fclose (Gbl_Files[FileId].Handle); 434 Gbl_Files[FileId].Handle = NULL; 435 436 if (Error) 437 { 438 FlFileError (FileId, ASL_MSG_CLOSE); 439 AslAbort (); 440 } 441 442 return; 443} 444 445 446/******************************************************************************* 447 * 448 * FUNCTION: FlSetLineNumber 449 * 450 * PARAMETERS: Op - Parse node for the LINE asl statement 451 * 452 * RETURN: None. 453 * 454 * DESCRIPTION: Set the current line number 455 * 456 ******************************************************************************/ 457 458void 459FlSetLineNumber ( 460 ACPI_PARSE_OBJECT *Op) 461{ 462 463 Gbl_CurrentLineNumber = (UINT32) Op->Asl.Value.Integer; 464 Gbl_LogicalLineNumber = (UINT32) Op->Asl.Value.Integer; 465} 466 467 468/******************************************************************************* 469 * 470 * FUNCTION: FlAddIncludeDirectory 471 * 472 * PARAMETERS: Dir - Directory pathname string 473 * 474 * RETURN: None 475 * 476 * DESCRIPTION: Add a directory the list of include prefix directories. 477 * 478 ******************************************************************************/ 479 480void 481FlAddIncludeDirectory ( 482 char *Dir) 483{ 484 ASL_INCLUDE_DIR *NewDir; 485 ASL_INCLUDE_DIR *NextDir; 486 ASL_INCLUDE_DIR *PrevDir = NULL; 487 UINT32 NeedsSeparator = 0; 488 size_t DirLength; 489 490 491 DirLength = strlen (Dir); 492 if (!DirLength) 493 { 494 return; 495 } 496 497 /* Make sure that the pathname ends with a path separator */ 498 499 if ((Dir[DirLength-1] != '/') && 500 (Dir[DirLength-1] != '\\')) 501 { 502 NeedsSeparator = 1; 503 } 504 505 NewDir = ACPI_ALLOCATE_ZEROED (sizeof (ASL_INCLUDE_DIR)); 506 NewDir->Dir = ACPI_ALLOCATE (DirLength + 1 + NeedsSeparator); 507 strcpy (NewDir->Dir, Dir); 508 if (NeedsSeparator) 509 { 510 strcat (NewDir->Dir, "/"); 511 } 512 513 /* 514 * Preserve command line ordering of -I options by adding new elements 515 * at the end of the list 516 */ 517 NextDir = Gbl_IncludeDirList; 518 while (NextDir) 519 { 520 PrevDir = NextDir; 521 NextDir = NextDir->Next; 522 } 523 524 if (PrevDir) 525 { 526 PrevDir->Next = NewDir; 527 } 528 else 529 { 530 Gbl_IncludeDirList = NewDir; 531 } 532} 533 534 535/******************************************************************************* 536 * 537 * FUNCTION: FlOpenIncludeWithPrefix 538 * 539 * PARAMETERS: PrefixDir - Prefix directory pathname. Can be a zero 540 * length string. 541 * Filename - The include filename from the source ASL. 542 * 543 * RETURN: Valid file descriptor if successful. Null otherwise. 544 * 545 * DESCRIPTION: Open an include file and push it on the input file stack. 546 * 547 ******************************************************************************/ 548 549FILE * 550FlOpenIncludeWithPrefix ( 551 char *PrefixDir, 552 char *Filename) 553{ 554 FILE *IncludeFile; 555 char *Pathname; 556 557 558 /* Build the full pathname to the file */ 559 560 Pathname = ACPI_ALLOCATE (strlen (PrefixDir) + strlen (Filename) + 1); 561 562 strcpy (Pathname, PrefixDir); 563 strcat (Pathname, Filename); 564 565 DbgPrint (ASL_PARSE_OUTPUT, "\nAttempt to open include file: path %s\n\n", 566 Pathname); 567 568 /* Attempt to open the file, push if successful */ 569 570 IncludeFile = fopen (Pathname, "r"); 571 if (IncludeFile) 572 { 573 /* Push the include file on the open input file stack */ 574 575 AslPushInputFileStack (IncludeFile, Pathname); 576 return (IncludeFile); 577 } 578 579 ACPI_FREE (Pathname); 580 return (NULL); 581} 582 583 584/******************************************************************************* 585 * 586 * FUNCTION: FlOpenIncludeFile 587 * 588 * PARAMETERS: Op - Parse node for the INCLUDE ASL statement 589 * 590 * RETURN: None. 591 * 592 * DESCRIPTION: Open an include file and push it on the input file stack. 593 * 594 ******************************************************************************/ 595 596void 597FlOpenIncludeFile ( 598 ACPI_PARSE_OBJECT *Op) 599{ 600 FILE *IncludeFile; 601 ASL_INCLUDE_DIR *NextDir; 602 603 604 /* Op must be valid */ 605 606 if (!Op) 607 { 608 AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, 609 Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, 610 Gbl_InputByteCount, Gbl_CurrentColumn, 611 Gbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node"); 612 613 return; 614 } 615 616 /* 617 * Flush out the "include ()" statement on this line, start 618 * the actual include file on the next line 619 */ 620 ResetCurrentLineBuffer (); 621 FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n"); 622 Gbl_CurrentLineOffset++; 623 624 625 /* Attempt to open the include file */ 626 627 /* If the file specifies an absolute path, just open it */ 628 629 if ((Op->Asl.Value.String[0] == '/') || 630 (Op->Asl.Value.String[0] == '\\') || 631 (Op->Asl.Value.String[1] == ':')) 632 { 633 IncludeFile = FlOpenIncludeWithPrefix ("", Op->Asl.Value.String); 634 if (!IncludeFile) 635 { 636 goto ErrorExit; 637 } 638 return; 639 } 640 641 /* 642 * The include filename is not an absolute path. 643 * 644 * First, search for the file within the "local" directory -- meaning 645 * the same directory that contains the source file. 646 * 647 * Construct the file pathname from the global directory name. 648 */ 649 IncludeFile = FlOpenIncludeWithPrefix (Gbl_DirectoryPath, Op->Asl.Value.String); 650 if (IncludeFile) 651 { 652 return; 653 } 654 655 /* 656 * Second, search for the file within the (possibly multiple) directories 657 * specified by the -I option on the command line. 658 */ 659 NextDir = Gbl_IncludeDirList; 660 while (NextDir) 661 { 662 IncludeFile = FlOpenIncludeWithPrefix (NextDir->Dir, Op->Asl.Value.String); 663 if (IncludeFile) 664 { 665 return; 666 } 667 668 NextDir = NextDir->Next; 669 } 670 671 /* We could not open the include file after trying very hard */ 672 673ErrorExit: 674 sprintf (MsgBuffer, "%s, %s", Op->Asl.Value.String, strerror (errno)); 675 AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, MsgBuffer); 676} 677 678 679/******************************************************************************* 680 * 681 * FUNCTION: FlOpenInputFile 682 * 683 * PARAMETERS: InputFilename - The user-specified ASL source file to be 684 * compiled 685 * 686 * RETURN: Status 687 * 688 * DESCRIPTION: Open the specified input file, and save the directory path to 689 * the file so that include files can be opened in 690 * the same directory. 691 * 692 ******************************************************************************/ 693 694ACPI_STATUS 695FlOpenInputFile ( 696 char *InputFilename) 697{ 698 699 /* Open the input ASL file, text mode */ 700 701 FlOpenFile (ASL_FILE_INPUT, InputFilename, "r"); 702 AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle; 703 704 return (AE_OK); 705} 706 707 708/******************************************************************************* 709 * 710 * FUNCTION: FlOpenAmlOutputFile 711 * 712 * PARAMETERS: FilenamePrefix - The user-specified ASL source file 713 * 714 * RETURN: Status 715 * 716 * DESCRIPTION: Create the output filename (*.AML) and open the file. The file 717 * is created in the same directory as the parent input file. 718 * 719 ******************************************************************************/ 720 721ACPI_STATUS 722FlOpenAmlOutputFile ( 723 char *FilenamePrefix) 724{ 725 char *Filename; 726 727 728 /* Output filename usually comes from the ASL itself */ 729 730 Filename = Gbl_Files[ASL_FILE_AML_OUTPUT].Filename; 731 if (!Filename) 732 { 733 /* Create the output AML filename */ 734 735 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE); 736 if (!Filename) 737 { 738 AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME, 739 0, 0, 0, 0, NULL, NULL); 740 return (AE_ERROR); 741 } 742 } 743 744 /* Open the output AML file in binary mode */ 745 746 FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b"); 747 return (AE_OK); 748} 749 750 751/******************************************************************************* 752 * 753 * FUNCTION: FlOpenMiscOutputFiles 754 * 755 * PARAMETERS: FilenamePrefix - The user-specified ASL source file 756 * 757 * RETURN: Status 758 * 759 * DESCRIPTION: Create and open the various output files needed, depending on 760 * the command line options 761 * 762 ******************************************************************************/ 763 764ACPI_STATUS 765FlOpenMiscOutputFiles ( 766 char *FilenamePrefix) 767{ 768 char *Filename; 769 770 771 /* Create/Open a hex output file if asked */ 772 773 if (Gbl_HexOutputFlag) 774 { 775 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP); 776 if (!Filename) 777 { 778 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 779 0, 0, 0, 0, NULL, NULL); 780 return (AE_ERROR); 781 } 782 783 /* Open the hex file, text mode */ 784 785 FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+"); 786 787 AslCompilerSignon (ASL_FILE_HEX_OUTPUT); 788 AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT); 789 } 790 791 /* Create/Open a debug output file if asked */ 792 793 if (Gbl_DebugFlag) 794 { 795 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG); 796 if (!Filename) 797 { 798 AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME, 799 0, 0, 0, 0, NULL, NULL); 800 return (AE_ERROR); 801 } 802 803 /* Open the debug file as STDERR, text mode */ 804 805 /* TBD: hide this behind a FlReopenFile function */ 806 807 Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename; 808 Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle = 809 freopen (Filename, "w+t", stderr); 810 811 AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT); 812 AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT); 813 } 814 815 if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA) 816 { 817 return (AE_OK); 818 } 819 820 /* Create/Open a combined source output file */ 821 822 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE); 823 if (!Filename) 824 { 825 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 826 0, 0, 0, 0, NULL, NULL); 827 return (AE_ERROR); 828 } 829 830 /* 831 * Open the source output file, binary mode (so that LF does not get 832 * expanded to CR/LF on some systems, messing up our seek 833 * calculations.) 834 */ 835 FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b"); 836 837 /* Create/Open a listing output file if asked */ 838 839 if (Gbl_ListingFlag) 840 { 841 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING); 842 if (!Filename) 843 { 844 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 845 0, 0, 0, 0, NULL, NULL); 846 return (AE_ERROR); 847 } 848 849 /* Open the listing file, text mode */ 850 851 FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+"); 852 853 AslCompilerSignon (ASL_FILE_LISTING_OUTPUT); 854 AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT); 855 } 856 857 /* Create/Open a assembly code source output file if asked */ 858 859 if (Gbl_AsmOutputFlag) 860 { 861 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE); 862 if (!Filename) 863 { 864 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 865 0, 0, 0, 0, NULL, NULL); 866 return (AE_ERROR); 867 } 868 869 /* Open the assembly code source file, text mode */ 870 871 FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+"); 872 873 AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT); 874 AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT); 875 } 876 877 /* Create/Open a C code source output file if asked */ 878 879 if (Gbl_C_OutputFlag) 880 { 881 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE); 882 if (!Filename) 883 { 884 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 885 0, 0, 0, 0, NULL, NULL); 886 return (AE_ERROR); 887 } 888 889 /* Open the C code source file, text mode */ 890 891 FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+"); 892 893 FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n"); 894 AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT); 895 AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT); 896 } 897 898 /* Create/Open a assembly include output file if asked */ 899 900 if (Gbl_AsmIncludeOutputFlag) 901 { 902 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE); 903 if (!Filename) 904 { 905 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 906 0, 0, 0, 0, NULL, NULL); 907 return (AE_ERROR); 908 } 909 910 /* Open the assembly include file, text mode */ 911 912 FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+"); 913 914 AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT); 915 AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT); 916 } 917 918 /* Create/Open a C include output file if asked */ 919 920 if (Gbl_C_IncludeOutputFlag) 921 { 922 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE); 923 if (!Filename) 924 { 925 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 926 0, 0, 0, 0, NULL, NULL); 927 return (AE_ERROR); 928 } 929 930 /* Open the C include file, text mode */ 931 932 FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+"); 933 934 FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n"); 935 AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT); 936 AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT); 937 } 938 939 /* Create a namespace output file if asked */ 940 941 if (Gbl_NsOutputFlag) 942 { 943 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE); 944 if (!Filename) 945 { 946 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 947 0, 0, 0, 0, NULL, NULL); 948 return (AE_ERROR); 949 } 950 951 /* Open the namespace file, text mode */ 952 953 FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+"); 954 955 AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT); 956 AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT); 957 } 958 959 return (AE_OK); 960} 961 962 963#ifdef ACPI_OBSOLETE_FUNCTIONS 964/******************************************************************************* 965 * 966 * FUNCTION: FlParseInputPathname 967 * 968 * PARAMETERS: InputFilename - The user-specified ASL source file to be 969 * compiled 970 * 971 * RETURN: Status 972 * 973 * DESCRIPTION: Split the input path into a directory and filename part 974 * 1) Directory part used to open include files 975 * 2) Filename part used to generate output filenames 976 * 977 ******************************************************************************/ 978 979ACPI_STATUS 980FlParseInputPathname ( 981 char *InputFilename) 982{ 983 char *Substring; 984 985 986 if (!InputFilename) 987 { 988 return (AE_OK); 989 } 990 991 /* Get the path to the input filename's directory */ 992 993 Gbl_DirectoryPath = strdup (InputFilename); 994 if (!Gbl_DirectoryPath) 995 { 996 return (AE_NO_MEMORY); 997 } 998 999 Substring = strrchr (Gbl_DirectoryPath, '\\'); 1000 if (!Substring) 1001 { 1002 Substring = strrchr (Gbl_DirectoryPath, '/'); 1003 if (!Substring) 1004 { 1005 Substring = strrchr (Gbl_DirectoryPath, ':'); 1006 } 1007 } 1008 1009 if (!Substring) 1010 { 1011 Gbl_DirectoryPath[0] = 0; 1012 if (Gbl_UseDefaultAmlFilename) 1013 { 1014 Gbl_OutputFilenamePrefix = strdup (InputFilename); 1015 } 1016 } 1017 else 1018 { 1019 if (Gbl_UseDefaultAmlFilename) 1020 { 1021 Gbl_OutputFilenamePrefix = strdup (Substring + 1); 1022 } 1023 *(Substring+1) = 0; 1024 } 1025 1026 return (AE_OK); 1027} 1028#endif 1029 1030 1031