1 /****************************************************************************** 2 * 3 * Module Name: aslfiles - File support functions 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2017, Intel Corp. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions, and the following disclaimer, 16 * without modification. 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18 * substantially similar to the "NO WARRANTY" disclaimer below 19 * ("Disclaimer") and any redistribution must be conditioned upon 20 * including a substantially similar Disclaimer requirement for further 21 * binary redistribution. 22 * 3. Neither the names of the above-listed copyright holders nor the names 23 * of any contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * Alternatively, this software may be distributed under the terms of the 27 * GNU General Public License ("GPL") version 2 as published by the Free 28 * Software Foundation. 29 * 30 * NO WARRANTY 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41 * POSSIBILITY OF SUCH DAMAGES. 42 */ 43 44 #include "aslcompiler.h" 45 #include "acapps.h" 46 #include "dtcompiler.h" 47 48 #define _COMPONENT ACPI_COMPILER 49 ACPI_MODULE_NAME ("aslfiles") 50 51 /* Local prototypes */ 52 53 static FILE * 54 FlOpenIncludeWithPrefix ( 55 char *PrefixDir, 56 ACPI_PARSE_OBJECT *Op, 57 char *Filename); 58 59 #ifdef ACPI_OBSOLETE_FUNCTIONS 60 ACPI_STATUS 61 FlParseInputPathname ( 62 char *InputFilename); 63 #endif 64 65 66 /******************************************************************************* 67 * 68 * FUNCTION: FlSetLineNumber 69 * 70 * PARAMETERS: Op - Parse node for the LINE asl statement 71 * 72 * RETURN: None. 73 * 74 * DESCRIPTION: Set the current line number 75 * 76 ******************************************************************************/ 77 78 void 79 FlSetLineNumber ( 80 UINT32 LineNumber) 81 { 82 83 DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New line number %u (old %u)\n", 84 LineNumber, Gbl_LogicalLineNumber); 85 86 Gbl_CurrentLineNumber = LineNumber; 87 } 88 89 90 /******************************************************************************* 91 * 92 * FUNCTION: FlSetFilename 93 * 94 * PARAMETERS: Op - Parse node for the LINE asl statement 95 * 96 * RETURN: None. 97 * 98 * DESCRIPTION: Set the current filename 99 * 100 ******************************************************************************/ 101 102 void 103 FlSetFilename ( 104 char *Filename) 105 { 106 107 DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New filename %s (old %s)\n", 108 Filename, Gbl_Files[ASL_FILE_INPUT].Filename); 109 110 /* No need to free any existing filename */ 111 112 Gbl_Files[ASL_FILE_INPUT].Filename = Filename; 113 } 114 115 116 /******************************************************************************* 117 * 118 * FUNCTION: FlAddIncludeDirectory 119 * 120 * PARAMETERS: Dir - Directory pathname string 121 * 122 * RETURN: None 123 * 124 * DESCRIPTION: Add a directory the list of include prefix directories. 125 * 126 ******************************************************************************/ 127 128 void 129 FlAddIncludeDirectory ( 130 char *Dir) 131 { 132 ASL_INCLUDE_DIR *NewDir; 133 ASL_INCLUDE_DIR *NextDir; 134 ASL_INCLUDE_DIR *PrevDir = NULL; 135 UINT32 NeedsSeparator = 0; 136 size_t DirLength; 137 138 139 DirLength = strlen (Dir); 140 if (!DirLength) 141 { 142 return; 143 } 144 145 /* Make sure that the pathname ends with a path separator */ 146 147 if ((Dir[DirLength-1] != '/') && 148 (Dir[DirLength-1] != '\\')) 149 { 150 NeedsSeparator = 1; 151 } 152 153 NewDir = ACPI_ALLOCATE_ZEROED (sizeof (ASL_INCLUDE_DIR)); 154 NewDir->Dir = ACPI_ALLOCATE (DirLength + 1 + NeedsSeparator); 155 strcpy (NewDir->Dir, Dir); 156 if (NeedsSeparator) 157 { 158 strcat (NewDir->Dir, "/"); 159 } 160 161 /* 162 * Preserve command line ordering of -I options by adding new elements 163 * at the end of the list 164 */ 165 NextDir = Gbl_IncludeDirList; 166 while (NextDir) 167 { 168 PrevDir = NextDir; 169 NextDir = NextDir->Next; 170 } 171 172 if (PrevDir) 173 { 174 PrevDir->Next = NewDir; 175 } 176 else 177 { 178 Gbl_IncludeDirList = NewDir; 179 } 180 } 181 182 183 /******************************************************************************* 184 * 185 * FUNCTION: FlMergePathnames 186 * 187 * PARAMETERS: PrefixDir - Prefix directory pathname. Can be NULL or 188 * a zero length string. 189 * FilePathname - The include filename from the source ASL. 190 * 191 * RETURN: Merged pathname string 192 * 193 * DESCRIPTION: Merge two pathnames that (probably) have common elements, to 194 * arrive at a minimal length string. Merge can occur if the 195 * FilePathname is relative to the PrefixDir. 196 * 197 ******************************************************************************/ 198 199 char * 200 FlMergePathnames ( 201 char *PrefixDir, 202 char *FilePathname) 203 { 204 char *CommonPath; 205 char *Pathname; 206 char *LastElement; 207 208 209 DbgPrint (ASL_PARSE_OUTPUT, "Include: Prefix path - \"%s\"\n" 210 "Include: FilePathname - \"%s\"\n", 211 PrefixDir, FilePathname); 212 213 /* 214 * If there is no prefix directory or if the file pathname is absolute, 215 * just return the original file pathname 216 */ 217 if (!PrefixDir || (!*PrefixDir) || 218 (*FilePathname == '/') || 219 (FilePathname[1] == ':')) 220 { 221 Pathname = UtStringCacheCalloc (strlen (FilePathname) + 1); 222 strcpy (Pathname, FilePathname); 223 goto ConvertBackslashes; 224 } 225 226 /* Need a local copy of the prefix directory path */ 227 228 CommonPath = UtStringCacheCalloc (strlen (PrefixDir) + 1); 229 strcpy (CommonPath, PrefixDir); 230 231 /* 232 * Walk forward through the file path, and simultaneously backward 233 * through the prefix directory path until there are no more 234 * relative references at the start of the file path. 235 */ 236 while (*FilePathname && (!strncmp (FilePathname, "../", 3))) 237 { 238 /* Remove last element of the prefix directory path */ 239 240 LastElement = strrchr (CommonPath, '/'); 241 if (!LastElement) 242 { 243 goto ConcatenatePaths; 244 } 245 246 *LastElement = 0; /* Terminate CommonPath string */ 247 FilePathname += 3; /* Point to next path element */ 248 } 249 250 /* 251 * Remove the last element of the prefix directory path (it is the same as 252 * the first element of the file pathname), and build the final merged 253 * pathname. 254 */ 255 LastElement = strrchr (CommonPath, '/'); 256 if (LastElement) 257 { 258 *LastElement = 0; 259 } 260 261 /* Build the final merged pathname */ 262 263 ConcatenatePaths: 264 Pathname = UtStringCacheCalloc ( 265 strlen (CommonPath) + strlen (FilePathname) + 2); 266 if (LastElement && *CommonPath) 267 { 268 strcpy (Pathname, CommonPath); 269 strcat (Pathname, "/"); 270 } 271 strcat (Pathname, FilePathname); 272 273 /* Convert all backslashes to normal slashes */ 274 275 ConvertBackslashes: 276 UtConvertBackslashes (Pathname); 277 278 DbgPrint (ASL_PARSE_OUTPUT, "Include: Merged Pathname - \"%s\"\n", 279 Pathname); 280 return (Pathname); 281 } 282 283 284 /******************************************************************************* 285 * 286 * FUNCTION: FlOpenIncludeWithPrefix 287 * 288 * PARAMETERS: PrefixDir - Prefix directory pathname. Can be a zero 289 * length string. 290 * Filename - The include filename from the source ASL. 291 * 292 * RETURN: Valid file descriptor if successful. Null otherwise. 293 * 294 * DESCRIPTION: Open an include file and push it on the input file stack. 295 * 296 ******************************************************************************/ 297 298 static FILE * 299 FlOpenIncludeWithPrefix ( 300 char *PrefixDir, 301 ACPI_PARSE_OBJECT *Op, 302 char *Filename) 303 { 304 FILE *IncludeFile; 305 char *Pathname; 306 UINT32 OriginalLineNumber; 307 308 309 /* Build the full pathname to the file */ 310 311 Pathname = FlMergePathnames (PrefixDir, Filename); 312 313 DbgPrint (ASL_PARSE_OUTPUT, "Include: Opening file - \"%s\"\n\n", 314 Pathname); 315 316 /* Attempt to open the file, push if successful */ 317 318 IncludeFile = fopen (Pathname, "r"); 319 if (!IncludeFile) 320 { 321 fprintf (stderr, "Could not open include file %s\n", Pathname); 322 ACPI_FREE (Pathname); 323 return (NULL); 324 } 325 326 /* 327 * Check the entire include file for any # preprocessor directives. 328 * This is because there may be some confusion between the #include 329 * preprocessor directive and the ASL Include statement. A file included 330 * by the ASL include cannot contain preprocessor directives because 331 * the preprocessor has already run by the time the ASL include is 332 * recognized (by the compiler, not the preprocessor.) 333 * 334 * Note: DtGetNextLine strips/ignores comments. 335 * Save current line number since DtGetNextLine modifies it. 336 */ 337 Gbl_CurrentLineNumber--; 338 OriginalLineNumber = Gbl_CurrentLineNumber; 339 340 while (DtGetNextLine (IncludeFile, DT_ALLOW_MULTILINE_QUOTES) != ASL_EOF) 341 { 342 if (Gbl_CurrentLineBuffer[0] == '#') 343 { 344 AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE, 345 Op, "use #include instead"); 346 } 347 } 348 349 Gbl_CurrentLineNumber = OriginalLineNumber; 350 351 /* Must seek back to the start of the file */ 352 353 fseek (IncludeFile, 0, SEEK_SET); 354 355 /* Push the include file on the open input file stack */ 356 357 AslPushInputFileStack (IncludeFile, Pathname); 358 return (IncludeFile); 359 } 360 361 362 /******************************************************************************* 363 * 364 * FUNCTION: FlOpenIncludeFile 365 * 366 * PARAMETERS: Op - Parse node for the INCLUDE ASL statement 367 * 368 * RETURN: None. 369 * 370 * DESCRIPTION: Open an include file and push it on the input file stack. 371 * 372 ******************************************************************************/ 373 374 void 375 FlOpenIncludeFile ( 376 ACPI_PARSE_OBJECT *Op) 377 { 378 FILE *IncludeFile; 379 ASL_INCLUDE_DIR *NextDir; 380 381 382 /* Op must be valid */ 383 384 if (!Op) 385 { 386 AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, 387 Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, 388 Gbl_InputByteCount, Gbl_CurrentColumn, 389 Gbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node"); 390 391 return; 392 } 393 394 /* 395 * Flush out the "include ()" statement on this line, start 396 * the actual include file on the next line 397 */ 398 AslResetCurrentLineBuffer (); 399 FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n"); 400 Gbl_CurrentLineOffset++; 401 402 403 /* Attempt to open the include file */ 404 405 /* If the file specifies an absolute path, just open it */ 406 407 if ((Op->Asl.Value.String[0] == '/') || 408 (Op->Asl.Value.String[0] == '\\') || 409 (Op->Asl.Value.String[1] == ':')) 410 { 411 IncludeFile = FlOpenIncludeWithPrefix ("", Op, Op->Asl.Value.String); 412 if (!IncludeFile) 413 { 414 goto ErrorExit; 415 } 416 return; 417 } 418 419 /* 420 * The include filename is not an absolute path. 421 * 422 * First, search for the file within the "local" directory -- meaning 423 * the same directory that contains the source file. 424 * 425 * Construct the file pathname from the global directory name. 426 */ 427 IncludeFile = FlOpenIncludeWithPrefix ( 428 Gbl_DirectoryPath, Op, Op->Asl.Value.String); 429 if (IncludeFile) 430 { 431 return; 432 } 433 434 /* 435 * Second, search for the file within the (possibly multiple) directories 436 * specified by the -I option on the command line. 437 */ 438 NextDir = Gbl_IncludeDirList; 439 while (NextDir) 440 { 441 IncludeFile = FlOpenIncludeWithPrefix ( 442 NextDir->Dir, Op, Op->Asl.Value.String); 443 if (IncludeFile) 444 { 445 return; 446 } 447 448 NextDir = NextDir->Next; 449 } 450 451 /* We could not open the include file after trying very hard */ 452 453 ErrorExit: 454 sprintf (MsgBuffer, "%s, %s", Op->Asl.Value.String, strerror (errno)); 455 AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, MsgBuffer); 456 } 457 458 459 /******************************************************************************* 460 * 461 * FUNCTION: FlOpenInputFile 462 * 463 * PARAMETERS: InputFilename - The user-specified ASL source file to be 464 * compiled 465 * 466 * RETURN: Status 467 * 468 * DESCRIPTION: Open the specified input file, and save the directory path to 469 * the file so that include files can be opened in 470 * the same directory. 471 * 472 ******************************************************************************/ 473 474 ACPI_STATUS 475 FlOpenInputFile ( 476 char *InputFilename) 477 { 478 479 /* Open the input ASL file, text mode */ 480 481 FlOpenFile (ASL_FILE_INPUT, InputFilename, "rt"); 482 AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle; 483 484 return (AE_OK); 485 } 486 487 488 /******************************************************************************* 489 * 490 * FUNCTION: FlOpenAmlOutputFile 491 * 492 * PARAMETERS: FilenamePrefix - The user-specified ASL source file 493 * 494 * RETURN: Status 495 * 496 * DESCRIPTION: Create the output filename (*.AML) and open the file. The file 497 * is created in the same directory as the parent input file. 498 * 499 ******************************************************************************/ 500 501 ACPI_STATUS 502 FlOpenAmlOutputFile ( 503 char *FilenamePrefix) 504 { 505 char *Filename; 506 507 508 /* Output filename usually comes from the ASL itself */ 509 510 Filename = Gbl_Files[ASL_FILE_AML_OUTPUT].Filename; 511 if (!Filename) 512 { 513 /* Create the output AML filename */ 514 if (!Gbl_CaptureComments) 515 { 516 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE); 517 } 518 else 519 { 520 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_CONVERT_AML); 521 } 522 if (!Filename) 523 { 524 AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME, 525 0, 0, 0, 0, NULL, NULL); 526 return (AE_ERROR); 527 } 528 529 Gbl_Files[ASL_FILE_AML_OUTPUT].Filename = Filename; 530 } 531 532 /* Open the output AML file in binary mode */ 533 534 FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b"); 535 return (AE_OK); 536 } 537 538 539 /******************************************************************************* 540 * 541 * FUNCTION: FlOpenMiscOutputFiles 542 * 543 * PARAMETERS: FilenamePrefix - The user-specified ASL source file 544 * 545 * RETURN: Status 546 * 547 * DESCRIPTION: Create and open the various output files needed, depending on 548 * the command line options 549 * 550 ******************************************************************************/ 551 552 ACPI_STATUS 553 FlOpenMiscOutputFiles ( 554 char *FilenamePrefix) 555 { 556 char *Filename; 557 558 559 /* Create/Open a map file if requested */ 560 561 if (Gbl_MapfileFlag) 562 { 563 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_MAP); 564 if (!Filename) 565 { 566 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 567 0, 0, 0, 0, NULL, NULL); 568 return (AE_ERROR); 569 } 570 571 /* Open the hex file, text mode (closed at compiler exit) */ 572 573 FlOpenFile (ASL_FILE_MAP_OUTPUT, Filename, "w+t"); 574 575 AslCompilerSignon (ASL_FILE_MAP_OUTPUT); 576 AslCompilerFileHeader (ASL_FILE_MAP_OUTPUT); 577 } 578 579 /* All done for disassembler */ 580 581 if (Gbl_FileType == ASL_INPUT_TYPE_BINARY_ACPI_TABLE) 582 { 583 return (AE_OK); 584 } 585 586 /* Create/Open a hex output file if asked */ 587 588 if (Gbl_HexOutputFlag) 589 { 590 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP); 591 if (!Filename) 592 { 593 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 594 0, 0, 0, 0, NULL, NULL); 595 return (AE_ERROR); 596 } 597 598 /* Open the hex file, text mode */ 599 600 FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+t"); 601 602 AslCompilerSignon (ASL_FILE_HEX_OUTPUT); 603 AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT); 604 } 605 606 /* Create/Open a debug output file if asked */ 607 608 if (Gbl_DebugFlag) 609 { 610 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG); 611 if (!Filename) 612 { 613 AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME, 614 0, 0, 0, 0, NULL, NULL); 615 return (AE_ERROR); 616 } 617 618 /* Open the debug file as STDERR, text mode */ 619 620 Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename; 621 Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle = 622 freopen (Filename, "w+t", stderr); 623 624 if (!Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle) 625 { 626 /* 627 * A problem with freopen is that on error, we no longer 628 * have stderr and cannot emit normal error messages. 629 * Emit error to stdout, close files, and exit. 630 */ 631 fprintf (stdout, 632 "\nCould not open debug output file: %s\n\n", Filename); 633 634 CmCleanupAndExit (); 635 exit (1); 636 } 637 638 AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT); 639 AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT); 640 } 641 642 /* Create/Open a cross-reference output file if asked */ 643 644 if (Gbl_CrossReferenceOutput) 645 { 646 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_XREF); 647 if (!Filename) 648 { 649 AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME, 650 0, 0, 0, 0, NULL, NULL); 651 return (AE_ERROR); 652 } 653 654 FlOpenFile (ASL_FILE_XREF_OUTPUT, Filename, "w+t"); 655 656 AslCompilerSignon (ASL_FILE_XREF_OUTPUT); 657 AslCompilerFileHeader (ASL_FILE_XREF_OUTPUT); 658 } 659 660 /* Create/Open a listing output file if asked */ 661 662 if (Gbl_ListingFlag) 663 { 664 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING); 665 if (!Filename) 666 { 667 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 668 0, 0, 0, 0, NULL, NULL); 669 return (AE_ERROR); 670 } 671 672 /* Open the listing file, text mode */ 673 674 FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+t"); 675 676 AslCompilerSignon (ASL_FILE_LISTING_OUTPUT); 677 AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT); 678 } 679 680 /* Create the preprocessor output temp file if preprocessor enabled */ 681 682 if (Gbl_PreprocessFlag) 683 { 684 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROCESSOR); 685 if (!Filename) 686 { 687 AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME, 688 0, 0, 0, 0, NULL, NULL); 689 return (AE_ERROR); 690 } 691 692 FlOpenFile (ASL_FILE_PREPROCESSOR, Filename, "w+t"); 693 } 694 695 /* 696 * Create the "user" preprocessor output file if -li flag set. 697 * Note, this file contains no embedded #line directives. 698 */ 699 if (Gbl_PreprocessorOutputFlag) 700 { 701 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROC_USER); 702 if (!Filename) 703 { 704 AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME, 705 0, 0, 0, 0, NULL, NULL); 706 return (AE_ERROR); 707 } 708 709 FlOpenFile (ASL_FILE_PREPROCESSOR_USER, Filename, "w+t"); 710 } 711 712 /* All done for data table compiler */ 713 714 if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA) 715 { 716 return (AE_OK); 717 } 718 719 /* Create/Open a combined source output file */ 720 721 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE); 722 if (!Filename) 723 { 724 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 725 0, 0, 0, 0, NULL, NULL); 726 return (AE_ERROR); 727 } 728 729 /* 730 * Open the source output file, binary mode (so that LF does not get 731 * expanded to CR/LF on some systems, messing up our seek 732 * calculations.) 733 */ 734 FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b"); 735 736 /* 737 // TBD: TEMP 738 // AslCompilerin = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle; 739 */ 740 /* Create/Open a assembly code source output file if asked */ 741 742 if (Gbl_AsmOutputFlag) 743 { 744 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE); 745 if (!Filename) 746 { 747 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 748 0, 0, 0, 0, NULL, NULL); 749 return (AE_ERROR); 750 } 751 752 /* Open the assembly code source file, text mode */ 753 754 FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+t"); 755 756 AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT); 757 AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT); 758 } 759 760 /* Create/Open a C code source output file if asked */ 761 762 if (Gbl_C_OutputFlag) 763 { 764 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE); 765 if (!Filename) 766 { 767 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 768 0, 0, 0, 0, NULL, NULL); 769 return (AE_ERROR); 770 } 771 772 /* Open the C code source file, text mode */ 773 774 FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+t"); 775 776 FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n"); 777 AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT); 778 AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT); 779 } 780 781 /* Create/Open a C code source output file for the offset table if asked */ 782 783 if (Gbl_C_OffsetTableFlag) 784 { 785 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_OFFSET); 786 if (!Filename) 787 { 788 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 789 0, 0, 0, 0, NULL, NULL); 790 return (AE_ERROR); 791 } 792 793 /* Open the C code source file, text mode */ 794 795 FlOpenFile (ASL_FILE_C_OFFSET_OUTPUT, Filename, "w+t"); 796 797 FlPrintFile (ASL_FILE_C_OFFSET_OUTPUT, "/*\n"); 798 AslCompilerSignon (ASL_FILE_C_OFFSET_OUTPUT); 799 AslCompilerFileHeader (ASL_FILE_C_OFFSET_OUTPUT); 800 } 801 802 /* Create/Open a assembly include output file if asked */ 803 804 if (Gbl_AsmIncludeOutputFlag) 805 { 806 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE); 807 if (!Filename) 808 { 809 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 810 0, 0, 0, 0, NULL, NULL); 811 return (AE_ERROR); 812 } 813 814 /* Open the assembly include file, text mode */ 815 816 FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+t"); 817 818 AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT); 819 AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT); 820 } 821 822 /* Create/Open a C include output file if asked */ 823 824 if (Gbl_C_IncludeOutputFlag) 825 { 826 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE); 827 if (!Filename) 828 { 829 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 830 0, 0, 0, 0, NULL, NULL); 831 return (AE_ERROR); 832 } 833 834 /* Open the C include file, text mode */ 835 836 FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+t"); 837 838 FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n"); 839 AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT); 840 AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT); 841 } 842 843 /* Create a namespace output file if asked */ 844 845 if (Gbl_NsOutputFlag) 846 { 847 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE); 848 if (!Filename) 849 { 850 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 851 0, 0, 0, 0, NULL, NULL); 852 return (AE_ERROR); 853 } 854 855 /* Open the namespace file, text mode */ 856 857 FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+t"); 858 859 AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT); 860 AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT); 861 } 862 863 /* Create a debug file for the converter */ 864 865 if (AcpiGbl_DebugAslConversion) 866 { 867 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_CONVERT_DEBUG); 868 if (!Filename) 869 { 870 AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, 871 0, 0, 0, 0, NULL, NULL); 872 return (AE_ERROR); 873 } 874 875 /* Open the converter debug file, text mode */ 876 877 FlOpenFile (ASL_FILE_CONV_DEBUG_OUTPUT, Filename, "w+t"); 878 879 AslCompilerSignon (ASL_FILE_CONV_DEBUG_OUTPUT); 880 AslCompilerFileHeader (ASL_FILE_CONV_DEBUG_OUTPUT); 881 882 AcpiGbl_ConvDebugFile = Gbl_Files[ASL_FILE_CONV_DEBUG_OUTPUT].Handle; 883 } 884 885 return (AE_OK); 886 } 887 888 889 #ifdef ACPI_OBSOLETE_FUNCTIONS 890 /******************************************************************************* 891 * 892 * FUNCTION: FlParseInputPathname 893 * 894 * PARAMETERS: InputFilename - The user-specified ASL source file to be 895 * compiled 896 * 897 * RETURN: Status 898 * 899 * DESCRIPTION: Split the input path into a directory and filename part 900 * 1) Directory part used to open include files 901 * 2) Filename part used to generate output filenames 902 * 903 ******************************************************************************/ 904 905 ACPI_STATUS 906 FlParseInputPathname ( 907 char *InputFilename) 908 { 909 char *Substring; 910 911 912 if (!InputFilename) 913 { 914 return (AE_OK); 915 } 916 917 /* Get the path to the input filename's directory */ 918 919 Gbl_DirectoryPath = strdup (InputFilename); 920 if (!Gbl_DirectoryPath) 921 { 922 return (AE_NO_MEMORY); 923 } 924 925 Substring = strrchr (Gbl_DirectoryPath, '\\'); 926 if (!Substring) 927 { 928 Substring = strrchr (Gbl_DirectoryPath, '/'); 929 if (!Substring) 930 { 931 Substring = strrchr (Gbl_DirectoryPath, ':'); 932 } 933 } 934 935 if (!Substring) 936 { 937 Gbl_DirectoryPath[0] = 0; 938 if (Gbl_UseDefaultAmlFilename) 939 { 940 Gbl_OutputFilenamePrefix = strdup (InputFilename); 941 } 942 } 943 else 944 { 945 if (Gbl_UseDefaultAmlFilename) 946 { 947 Gbl_OutputFilenamePrefix = strdup (Substring + 1); 948 } 949 *(Substring+1) = 0; 950 } 951 952 UtConvertBackslashes (Gbl_OutputFilenamePrefix); 953 return (AE_OK); 954 } 955 #endif 956