1a9f12690SJung-uk Kim /****************************************************************************** 2a9f12690SJung-uk Kim * 3a9f12690SJung-uk Kim * Module Name: aslstartup - Compiler startup routines, called from main 4a9f12690SJung-uk Kim * 5a9f12690SJung-uk Kim *****************************************************************************/ 6a9f12690SJung-uk Kim 7d244b227SJung-uk Kim /* 8efcc2a30SJung-uk Kim * Copyright (C) 2000 - 2013, Intel Corp. 9a9f12690SJung-uk Kim * All rights reserved. 10a9f12690SJung-uk Kim * 11d244b227SJung-uk Kim * Redistribution and use in source and binary forms, with or without 12d244b227SJung-uk Kim * modification, are permitted provided that the following conditions 13d244b227SJung-uk Kim * are met: 14d244b227SJung-uk Kim * 1. Redistributions of source code must retain the above copyright 15d244b227SJung-uk Kim * notice, this list of conditions, and the following disclaimer, 16d244b227SJung-uk Kim * without modification. 17d244b227SJung-uk Kim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18d244b227SJung-uk Kim * substantially similar to the "NO WARRANTY" disclaimer below 19d244b227SJung-uk Kim * ("Disclaimer") and any redistribution must be conditioned upon 20d244b227SJung-uk Kim * including a substantially similar Disclaimer requirement for further 21d244b227SJung-uk Kim * binary redistribution. 22d244b227SJung-uk Kim * 3. Neither the names of the above-listed copyright holders nor the names 23d244b227SJung-uk Kim * of any contributors may be used to endorse or promote products derived 24d244b227SJung-uk Kim * from this software without specific prior written permission. 25a9f12690SJung-uk Kim * 26d244b227SJung-uk Kim * Alternatively, this software may be distributed under the terms of the 27d244b227SJung-uk Kim * GNU General Public License ("GPL") version 2 as published by the Free 28d244b227SJung-uk Kim * Software Foundation. 29a9f12690SJung-uk Kim * 30d244b227SJung-uk Kim * NO WARRANTY 31d244b227SJung-uk Kim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32d244b227SJung-uk Kim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33d244b227SJung-uk Kim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34d244b227SJung-uk Kim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35d244b227SJung-uk Kim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36d244b227SJung-uk Kim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37d244b227SJung-uk Kim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38d244b227SJung-uk Kim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39d244b227SJung-uk Kim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40d244b227SJung-uk Kim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41d244b227SJung-uk Kim * POSSIBILITY OF SUCH DAMAGES. 42d244b227SJung-uk Kim */ 43a9f12690SJung-uk Kim 44a9f12690SJung-uk Kim 45ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h> 46ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/actables.h> 479c48c75eSJung-uk Kim #include <contrib/dev/acpica/include/acdisasm.h> 48ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acapps.h> 49a9f12690SJung-uk Kim 50a9f12690SJung-uk Kim #define _COMPONENT ACPI_COMPILER 51a9f12690SJung-uk Kim ACPI_MODULE_NAME ("aslstartup") 52a9f12690SJung-uk Kim 53a9f12690SJung-uk Kim 54a9f12690SJung-uk Kim #define ASL_MAX_FILES 256 5542fecd12SJung-uk Kim static char *FileList[ASL_MAX_FILES]; 5642fecd12SJung-uk Kim static BOOLEAN AslToFile = TRUE; 57a9f12690SJung-uk Kim 58a9f12690SJung-uk Kim 59a9f12690SJung-uk Kim /* Local prototypes */ 60a9f12690SJung-uk Kim 61a9f12690SJung-uk Kim static char ** 62a9f12690SJung-uk Kim AsDoWildcard ( 63a9f12690SJung-uk Kim char *DirectoryPathname, 64a9f12690SJung-uk Kim char *FileSpecifier); 65a9f12690SJung-uk Kim 6642fecd12SJung-uk Kim static UINT8 67a88e22b7SJung-uk Kim AslDetectSourceFileType ( 68a88e22b7SJung-uk Kim ASL_FILE_INFO *Info); 69a88e22b7SJung-uk Kim 709c48c75eSJung-uk Kim static ACPI_STATUS 719c48c75eSJung-uk Kim AslDoDisassembly ( 729c48c75eSJung-uk Kim void); 739c48c75eSJung-uk Kim 74a9f12690SJung-uk Kim 75a9f12690SJung-uk Kim /******************************************************************************* 76a9f12690SJung-uk Kim * 77a9f12690SJung-uk Kim * FUNCTION: AslInitializeGlobals 78a9f12690SJung-uk Kim * 79a9f12690SJung-uk Kim * PARAMETERS: None 80a9f12690SJung-uk Kim * 81a9f12690SJung-uk Kim * RETURN: None 82a9f12690SJung-uk Kim * 83a9f12690SJung-uk Kim * DESCRIPTION: Re-initialize globals needed to restart the compiler. This 84a9f12690SJung-uk Kim * allows multiple files to be disassembled and/or compiled. 85a9f12690SJung-uk Kim * 86a9f12690SJung-uk Kim ******************************************************************************/ 87a9f12690SJung-uk Kim 88a88e22b7SJung-uk Kim void 89a9f12690SJung-uk Kim AslInitializeGlobals ( 90a9f12690SJung-uk Kim void) 91a9f12690SJung-uk Kim { 92a9f12690SJung-uk Kim UINT32 i; 93a9f12690SJung-uk Kim 94a9f12690SJung-uk Kim 95a9f12690SJung-uk Kim /* Init compiler globals */ 96a9f12690SJung-uk Kim 97a9f12690SJung-uk Kim Gbl_CurrentColumn = 0; 98a9f12690SJung-uk Kim Gbl_CurrentLineNumber = 1; 99a9f12690SJung-uk Kim Gbl_LogicalLineNumber = 1; 100a9f12690SJung-uk Kim Gbl_CurrentLineOffset = 0; 101a88e22b7SJung-uk Kim Gbl_InputFieldCount = 0; 1024c52cad2SJung-uk Kim Gbl_InputByteCount = 0; 1034c52cad2SJung-uk Kim Gbl_NsLookupCount = 0; 104a9f12690SJung-uk Kim Gbl_LineBufPtr = Gbl_CurrentLineBuffer; 105a9f12690SJung-uk Kim 106a9f12690SJung-uk Kim Gbl_ErrorLog = NULL; 107a9f12690SJung-uk Kim Gbl_NextError = NULL; 108a88e22b7SJung-uk Kim Gbl_Signature = NULL; 109a88e22b7SJung-uk Kim Gbl_FileType = 0; 110a9f12690SJung-uk Kim 1114c52cad2SJung-uk Kim TotalExecutableOpcodes = 0; 1124c52cad2SJung-uk Kim TotalNamedObjects = 0; 1134c52cad2SJung-uk Kim TotalKeywords = 0; 1144c52cad2SJung-uk Kim TotalParseNodes = 0; 1154c52cad2SJung-uk Kim TotalMethods = 0; 1164c52cad2SJung-uk Kim TotalAllocations = 0; 1174c52cad2SJung-uk Kim TotalAllocated = 0; 1184c52cad2SJung-uk Kim TotalFolds = 0; 1194c52cad2SJung-uk Kim 120a9f12690SJung-uk Kim AslGbl_NextEvent = 0; 121a9f12690SJung-uk Kim for (i = 0; i < ASL_NUM_REPORT_LEVELS; i++) 122a9f12690SJung-uk Kim { 123a9f12690SJung-uk Kim Gbl_ExceptionCount[i] = 0; 124a9f12690SJung-uk Kim } 125a9f12690SJung-uk Kim 1264c52cad2SJung-uk Kim for (i = ASL_FILE_INPUT; i <= ASL_MAX_FILE_TYPE; i++) 1274c52cad2SJung-uk Kim { 1284c52cad2SJung-uk Kim Gbl_Files[i].Handle = NULL; 1294c52cad2SJung-uk Kim Gbl_Files[i].Filename = NULL; 1304c52cad2SJung-uk Kim } 131a9f12690SJung-uk Kim } 132a9f12690SJung-uk Kim 133a9f12690SJung-uk Kim 134a9f12690SJung-uk Kim /****************************************************************************** 135a9f12690SJung-uk Kim * 136a9f12690SJung-uk Kim * FUNCTION: AsDoWildcard 137a9f12690SJung-uk Kim * 138a9f12690SJung-uk Kim * PARAMETERS: None 139a9f12690SJung-uk Kim * 140a9f12690SJung-uk Kim * RETURN: None 141a9f12690SJung-uk Kim * 142a9f12690SJung-uk Kim * DESCRIPTION: Process files via wildcards. This function is for the Windows 143a9f12690SJung-uk Kim * case only. 144a9f12690SJung-uk Kim * 145a9f12690SJung-uk Kim ******************************************************************************/ 146a9f12690SJung-uk Kim 147a9f12690SJung-uk Kim static char ** 148a9f12690SJung-uk Kim AsDoWildcard ( 149a9f12690SJung-uk Kim char *DirectoryPathname, 150a9f12690SJung-uk Kim char *FileSpecifier) 151a9f12690SJung-uk Kim { 152a9f12690SJung-uk Kim #ifdef WIN32 153a9f12690SJung-uk Kim void *DirInfo; 154a9f12690SJung-uk Kim char *Filename; 15542fecd12SJung-uk Kim int FileCount; 156a9f12690SJung-uk Kim 157a9f12690SJung-uk Kim 158a9f12690SJung-uk Kim FileCount = 0; 159a9f12690SJung-uk Kim 160a9f12690SJung-uk Kim /* Open parent directory */ 161a9f12690SJung-uk Kim 162a9f12690SJung-uk Kim DirInfo = AcpiOsOpenDirectory (DirectoryPathname, FileSpecifier, REQUEST_FILE_ONLY); 163a9f12690SJung-uk Kim if (!DirInfo) 164a9f12690SJung-uk Kim { 165a9f12690SJung-uk Kim /* Either the directory of file does not exist */ 166a9f12690SJung-uk Kim 167a9f12690SJung-uk Kim Gbl_Files[ASL_FILE_INPUT].Filename = FileSpecifier; 168a9f12690SJung-uk Kim FlFileError (ASL_FILE_INPUT, ASL_MSG_OPEN); 169a9f12690SJung-uk Kim AslAbort (); 170a9f12690SJung-uk Kim } 171a9f12690SJung-uk Kim 172a9f12690SJung-uk Kim /* Process each file that matches the wildcard specification */ 173a9f12690SJung-uk Kim 174a9f12690SJung-uk Kim while ((Filename = AcpiOsGetNextFilename (DirInfo))) 175a9f12690SJung-uk Kim { 176a9f12690SJung-uk Kim /* Add the filename to the file list */ 177a9f12690SJung-uk Kim 178a9f12690SJung-uk Kim FileList[FileCount] = AcpiOsAllocate (strlen (Filename) + 1); 179a9f12690SJung-uk Kim strcpy (FileList[FileCount], Filename); 180a9f12690SJung-uk Kim FileCount++; 181a9f12690SJung-uk Kim 182a9f12690SJung-uk Kim if (FileCount >= ASL_MAX_FILES) 183a9f12690SJung-uk Kim { 184a9f12690SJung-uk Kim printf ("Max files reached\n"); 185a9f12690SJung-uk Kim FileList[0] = NULL; 186a9f12690SJung-uk Kim return (FileList); 187a9f12690SJung-uk Kim } 188a9f12690SJung-uk Kim } 189a9f12690SJung-uk Kim 190a9f12690SJung-uk Kim /* Cleanup */ 191a9f12690SJung-uk Kim 192a9f12690SJung-uk Kim AcpiOsCloseDirectory (DirInfo); 193a9f12690SJung-uk Kim FileList[FileCount] = NULL; 194a9f12690SJung-uk Kim return (FileList); 195a9f12690SJung-uk Kim 196a9f12690SJung-uk Kim #else 197a9f12690SJung-uk Kim /* 198a9f12690SJung-uk Kim * Linux/Unix cases - Wildcards are expanded by the shell automatically. 199a9f12690SJung-uk Kim * Just return the filename in a null terminated list 200a9f12690SJung-uk Kim */ 201a9f12690SJung-uk Kim FileList[0] = AcpiOsAllocate (strlen (FileSpecifier) + 1); 202a9f12690SJung-uk Kim strcpy (FileList[0], FileSpecifier); 203a9f12690SJung-uk Kim FileList[1] = NULL; 204a9f12690SJung-uk Kim 205a9f12690SJung-uk Kim return (FileList); 206a9f12690SJung-uk Kim #endif 207a9f12690SJung-uk Kim } 208a9f12690SJung-uk Kim 209a9f12690SJung-uk Kim 210a9f12690SJung-uk Kim /******************************************************************************* 211a9f12690SJung-uk Kim * 212a88e22b7SJung-uk Kim * FUNCTION: AslDetectSourceFileType 213a88e22b7SJung-uk Kim * 214a88e22b7SJung-uk Kim * PARAMETERS: Info - Name/Handle for the file (must be open) 215a88e22b7SJung-uk Kim * 216a88e22b7SJung-uk Kim * RETURN: File Type 217a88e22b7SJung-uk Kim * 218a88e22b7SJung-uk Kim * DESCRIPTION: Determine the type of the input file. Either binary (contains 219a88e22b7SJung-uk Kim * non-ASCII characters), ASL file, or an ACPI Data Table file. 220a88e22b7SJung-uk Kim * 221a88e22b7SJung-uk Kim ******************************************************************************/ 222a88e22b7SJung-uk Kim 22342fecd12SJung-uk Kim static UINT8 224a88e22b7SJung-uk Kim AslDetectSourceFileType ( 225a88e22b7SJung-uk Kim ASL_FILE_INFO *Info) 226a88e22b7SJung-uk Kim { 227a88e22b7SJung-uk Kim char *FileChar; 228a88e22b7SJung-uk Kim UINT8 Type; 229a88e22b7SJung-uk Kim ACPI_STATUS Status; 230a88e22b7SJung-uk Kim 231a88e22b7SJung-uk Kim 2329c48c75eSJung-uk Kim /* Check for a valid binary ACPI table */ 2339c48c75eSJung-uk Kim 2349c48c75eSJung-uk Kim Status = FlCheckForAcpiTable (Info->Handle); 2359c48c75eSJung-uk Kim if (ACPI_SUCCESS (Status)) 2369c48c75eSJung-uk Kim { 2379c48c75eSJung-uk Kim Type = ASL_INPUT_TYPE_ACPI_TABLE; 2389c48c75eSJung-uk Kim goto Cleanup; 2399c48c75eSJung-uk Kim } 2409c48c75eSJung-uk Kim 241a88e22b7SJung-uk Kim /* Check for 100% ASCII source file (comments are ignored) */ 242a88e22b7SJung-uk Kim 243a7a3b383SJung-uk Kim Status = FlCheckForAscii (Info->Handle, Info->Filename, TRUE); 244a88e22b7SJung-uk Kim if (ACPI_FAILURE (Status)) 245a88e22b7SJung-uk Kim { 246a88e22b7SJung-uk Kim printf ("Non-ascii input file - %s\n", Info->Filename); 2478ef1a331SJung-uk Kim 2488ef1a331SJung-uk Kim if (!Gbl_IgnoreErrors) 2498ef1a331SJung-uk Kim { 250a88e22b7SJung-uk Kim Type = ASL_INPUT_TYPE_BINARY; 251a88e22b7SJung-uk Kim goto Cleanup; 252a88e22b7SJung-uk Kim } 2538ef1a331SJung-uk Kim } 254a88e22b7SJung-uk Kim 255a88e22b7SJung-uk Kim /* 256a88e22b7SJung-uk Kim * File is ASCII. Determine if this is an ASL file or an ACPI data 257a88e22b7SJung-uk Kim * table file. 258a88e22b7SJung-uk Kim */ 259042ff955SJung-uk Kim while (fgets (Gbl_CurrentLineBuffer, Gbl_LineBufferSize, Info->Handle)) 260a88e22b7SJung-uk Kim { 261a88e22b7SJung-uk Kim /* Uppercase the buffer for caseless compare */ 262a88e22b7SJung-uk Kim 263a88e22b7SJung-uk Kim FileChar = Gbl_CurrentLineBuffer; 264a88e22b7SJung-uk Kim while (*FileChar) 265a88e22b7SJung-uk Kim { 266a88e22b7SJung-uk Kim *FileChar = (char) toupper ((int) *FileChar); 267a88e22b7SJung-uk Kim FileChar++; 268a88e22b7SJung-uk Kim } 269a88e22b7SJung-uk Kim 270a88e22b7SJung-uk Kim /* Presence of "DefinitionBlock" indicates actual ASL code */ 271a88e22b7SJung-uk Kim 272a88e22b7SJung-uk Kim if (strstr (Gbl_CurrentLineBuffer, "DEFINITIONBLOCK")) 273a88e22b7SJung-uk Kim { 274a88e22b7SJung-uk Kim /* Appears to be an ASL file */ 275a88e22b7SJung-uk Kim 276a88e22b7SJung-uk Kim Type = ASL_INPUT_TYPE_ASCII_ASL; 277a88e22b7SJung-uk Kim goto Cleanup; 278a88e22b7SJung-uk Kim } 279a88e22b7SJung-uk Kim } 280a88e22b7SJung-uk Kim 281a88e22b7SJung-uk Kim /* Not an ASL source file, default to a data table source file */ 282a88e22b7SJung-uk Kim 283a88e22b7SJung-uk Kim Type = ASL_INPUT_TYPE_ASCII_DATA; 284a88e22b7SJung-uk Kim 285a88e22b7SJung-uk Kim Cleanup: 286a88e22b7SJung-uk Kim 287a88e22b7SJung-uk Kim /* Must seek back to the start of the file */ 288a88e22b7SJung-uk Kim 289a88e22b7SJung-uk Kim fseek (Info->Handle, 0, SEEK_SET); 290a88e22b7SJung-uk Kim return (Type); 291a88e22b7SJung-uk Kim } 292a88e22b7SJung-uk Kim 293a88e22b7SJung-uk Kim 294a88e22b7SJung-uk Kim /******************************************************************************* 295a88e22b7SJung-uk Kim * 2969c48c75eSJung-uk Kim * FUNCTION: AslDoDisassembly 2979c48c75eSJung-uk Kim * 2989c48c75eSJung-uk Kim * PARAMETERS: None 2999c48c75eSJung-uk Kim * 3009c48c75eSJung-uk Kim * RETURN: Status 3019c48c75eSJung-uk Kim * 3029c48c75eSJung-uk Kim * DESCRIPTION: Initiate AML file disassembly. Uses ACPICA subsystem to build 3039c48c75eSJung-uk Kim * namespace. 3049c48c75eSJung-uk Kim * 3059c48c75eSJung-uk Kim ******************************************************************************/ 3069c48c75eSJung-uk Kim 3079c48c75eSJung-uk Kim static ACPI_STATUS 3089c48c75eSJung-uk Kim AslDoDisassembly ( 3099c48c75eSJung-uk Kim void) 3109c48c75eSJung-uk Kim { 3119c48c75eSJung-uk Kim ACPI_STATUS Status; 3129c48c75eSJung-uk Kim 3139c48c75eSJung-uk Kim 3149c48c75eSJung-uk Kim /* ACPICA subsystem initialization */ 3159c48c75eSJung-uk Kim 3169c48c75eSJung-uk Kim Status = AdInitialize (); 3179c48c75eSJung-uk Kim if (ACPI_FAILURE (Status)) 3189c48c75eSJung-uk Kim { 3199c48c75eSJung-uk Kim return (Status); 3209c48c75eSJung-uk Kim } 3219c48c75eSJung-uk Kim 3229c48c75eSJung-uk Kim Status = AcpiAllocateRootTable (4); 3239c48c75eSJung-uk Kim if (ACPI_FAILURE (Status)) 3249c48c75eSJung-uk Kim { 3259c48c75eSJung-uk Kim AcpiOsPrintf ("Could not initialize ACPI Table Manager, %s\n", 3269c48c75eSJung-uk Kim AcpiFormatException (Status)); 3279c48c75eSJung-uk Kim return (Status); 3289c48c75eSJung-uk Kim } 3299c48c75eSJung-uk Kim 3309c48c75eSJung-uk Kim /* This is where the disassembly happens */ 3319c48c75eSJung-uk Kim 3329c48c75eSJung-uk Kim AcpiGbl_DbOpt_disasm = TRUE; 3339c48c75eSJung-uk Kim Status = AdAmlDisassemble (AslToFile, 3349c48c75eSJung-uk Kim Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_OutputFilenamePrefix, 3359c48c75eSJung-uk Kim &Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_GetAllTables); 3369c48c75eSJung-uk Kim if (ACPI_FAILURE (Status)) 3379c48c75eSJung-uk Kim { 3389c48c75eSJung-uk Kim return (Status); 3399c48c75eSJung-uk Kim } 3409c48c75eSJung-uk Kim 3419c48c75eSJung-uk Kim /* Check if any control methods were unresolved */ 3429c48c75eSJung-uk Kim 3439c48c75eSJung-uk Kim AcpiDmUnresolvedWarning (0); 3449c48c75eSJung-uk Kim 3459c48c75eSJung-uk Kim #if 0 3469c48c75eSJung-uk Kim /* TBD: Handle additional output files for disassembler */ 3479c48c75eSJung-uk Kim 3489c48c75eSJung-uk Kim Status = FlOpenMiscOutputFiles (Gbl_OutputFilenamePrefix); 3499c48c75eSJung-uk Kim NsDisplayNamespace (); 3509c48c75eSJung-uk Kim #endif 3519c48c75eSJung-uk Kim 3529c48c75eSJung-uk Kim /* Shutdown compiler and ACPICA subsystem */ 3539c48c75eSJung-uk Kim 3549c48c75eSJung-uk Kim AeClearErrorLog (); 3559c48c75eSJung-uk Kim (void) AcpiTerminate (); 3569c48c75eSJung-uk Kim 3579c48c75eSJung-uk Kim /* 3589c48c75eSJung-uk Kim * Gbl_Files[ASL_FILE_INPUT].Filename was replaced with the 3599c48c75eSJung-uk Kim * .DSL disassembly file, which can now be compiled if requested 3609c48c75eSJung-uk Kim */ 3619c48c75eSJung-uk Kim if (Gbl_DoCompile) 3629c48c75eSJung-uk Kim { 3639c48c75eSJung-uk Kim AcpiOsPrintf ("\nCompiling \"%s\"\n", 3649c48c75eSJung-uk Kim Gbl_Files[ASL_FILE_INPUT].Filename); 3659c48c75eSJung-uk Kim return (AE_CTRL_CONTINUE); 3669c48c75eSJung-uk Kim } 3679c48c75eSJung-uk Kim 3689c48c75eSJung-uk Kim ACPI_FREE (Gbl_Files[ASL_FILE_INPUT].Filename); 3699c48c75eSJung-uk Kim Gbl_Files[ASL_FILE_INPUT].Filename = NULL; 3709c48c75eSJung-uk Kim return (AE_OK); 3719c48c75eSJung-uk Kim } 3729c48c75eSJung-uk Kim 3739c48c75eSJung-uk Kim 3749c48c75eSJung-uk Kim /******************************************************************************* 3759c48c75eSJung-uk Kim * 376a9f12690SJung-uk Kim * FUNCTION: AslDoOneFile 377a9f12690SJung-uk Kim * 378a9f12690SJung-uk Kim * PARAMETERS: Filename - Name of the file 379a9f12690SJung-uk Kim * 380a9f12690SJung-uk Kim * RETURN: Status 381a9f12690SJung-uk Kim * 382a9f12690SJung-uk Kim * DESCRIPTION: Process a single file - either disassemble, compile, or both 383a9f12690SJung-uk Kim * 384a9f12690SJung-uk Kim ******************************************************************************/ 385a9f12690SJung-uk Kim 386a9f12690SJung-uk Kim ACPI_STATUS 387a9f12690SJung-uk Kim AslDoOneFile ( 388a9f12690SJung-uk Kim char *Filename) 389a9f12690SJung-uk Kim { 390a9f12690SJung-uk Kim ACPI_STATUS Status; 391a9f12690SJung-uk Kim 392a9f12690SJung-uk Kim 3934c52cad2SJung-uk Kim /* Re-initialize "some" compiler/preprocessor globals */ 394a9f12690SJung-uk Kim 395a9f12690SJung-uk Kim AslInitializeGlobals (); 3964c52cad2SJung-uk Kim PrInitializeGlobals (); 3974c52cad2SJung-uk Kim 3984c52cad2SJung-uk Kim Gbl_Files[ASL_FILE_INPUT].Filename = Filename; 399a9f12690SJung-uk Kim 400a9f12690SJung-uk Kim /* 401a9f12690SJung-uk Kim * AML Disassembly (Optional) 402a9f12690SJung-uk Kim */ 403a9f12690SJung-uk Kim if (Gbl_DisasmFlag || Gbl_GetAllTables) 404a9f12690SJung-uk Kim { 4059c48c75eSJung-uk Kim Status = AslDoDisassembly (); 4069c48c75eSJung-uk Kim if (Status != AE_CTRL_CONTINUE) 407a9f12690SJung-uk Kim { 408a9f12690SJung-uk Kim return (Status); 409a9f12690SJung-uk Kim } 410a9f12690SJung-uk Kim } 411a9f12690SJung-uk Kim 412a9f12690SJung-uk Kim /* 413a88e22b7SJung-uk Kim * Open the input file. Here, this should be an ASCII source file, 414a88e22b7SJung-uk Kim * either an ASL file or a Data Table file 415a9f12690SJung-uk Kim */ 416a88e22b7SJung-uk Kim Status = FlOpenInputFile (Gbl_Files[ASL_FILE_INPUT].Filename); 417a88e22b7SJung-uk Kim if (ACPI_FAILURE (Status)) 418a9f12690SJung-uk Kim { 419a88e22b7SJung-uk Kim AePrintErrorLog (ASL_FILE_STDERR); 420a88e22b7SJung-uk Kim return (AE_ERROR); 421a88e22b7SJung-uk Kim } 422a88e22b7SJung-uk Kim 423a88e22b7SJung-uk Kim /* Determine input file type */ 424a88e22b7SJung-uk Kim 425a88e22b7SJung-uk Kim Gbl_FileType = AslDetectSourceFileType (&Gbl_Files[ASL_FILE_INPUT]); 426a88e22b7SJung-uk Kim if (Gbl_FileType == ASL_INPUT_TYPE_BINARY) 427a88e22b7SJung-uk Kim { 428a88e22b7SJung-uk Kim return (AE_ERROR); 429a88e22b7SJung-uk Kim } 430a88e22b7SJung-uk Kim 431a9f12690SJung-uk Kim /* 432a9f12690SJung-uk Kim * If -p not specified, we will use the input filename as the 433a9f12690SJung-uk Kim * output filename prefix 434a9f12690SJung-uk Kim */ 435a9f12690SJung-uk Kim if (Gbl_UseDefaultAmlFilename) 436a9f12690SJung-uk Kim { 437a9f12690SJung-uk Kim Gbl_OutputFilenamePrefix = Gbl_Files[ASL_FILE_INPUT].Filename; 438a9f12690SJung-uk Kim } 439a9f12690SJung-uk Kim 440a88e22b7SJung-uk Kim /* Open the optional output files (listings, etc.) */ 441a88e22b7SJung-uk Kim 442a88e22b7SJung-uk Kim Status = FlOpenMiscOutputFiles (Gbl_OutputFilenamePrefix); 443a88e22b7SJung-uk Kim if (ACPI_FAILURE (Status)) 444a88e22b7SJung-uk Kim { 445a88e22b7SJung-uk Kim AePrintErrorLog (ASL_FILE_STDERR); 446a88e22b7SJung-uk Kim return (AE_ERROR); 447a88e22b7SJung-uk Kim } 448a88e22b7SJung-uk Kim 449a88e22b7SJung-uk Kim /* 450a88e22b7SJung-uk Kim * Compilation of ASL source versus DataTable source uses different 451a88e22b7SJung-uk Kim * compiler subsystems 452a88e22b7SJung-uk Kim */ 453a88e22b7SJung-uk Kim switch (Gbl_FileType) 454a88e22b7SJung-uk Kim { 455a88e22b7SJung-uk Kim /* 456a88e22b7SJung-uk Kim * Data Table Compilation 457a88e22b7SJung-uk Kim */ 458a88e22b7SJung-uk Kim case ASL_INPUT_TYPE_ASCII_DATA: 459a88e22b7SJung-uk Kim 460a88e22b7SJung-uk Kim Status = DtDoCompile (); 461eef1b955SJung-uk Kim if (ACPI_FAILURE (Status)) 462eef1b955SJung-uk Kim { 463eef1b955SJung-uk Kim return (Status); 464eef1b955SJung-uk Kim } 465a88e22b7SJung-uk Kim 466a88e22b7SJung-uk Kim if (Gbl_Signature) 467a88e22b7SJung-uk Kim { 468a88e22b7SJung-uk Kim ACPI_FREE (Gbl_Signature); 469a88e22b7SJung-uk Kim Gbl_Signature = NULL; 470a88e22b7SJung-uk Kim } 471eef1b955SJung-uk Kim 472eef1b955SJung-uk Kim /* Check if any errors occurred during compile */ 473eef1b955SJung-uk Kim 474eef1b955SJung-uk Kim Status = AslCheckForErrorExit (); 475eef1b955SJung-uk Kim if (ACPI_FAILURE (Status)) 476eef1b955SJung-uk Kim { 477eef1b955SJung-uk Kim return (Status); 478eef1b955SJung-uk Kim } 479eef1b955SJung-uk Kim 480eef1b955SJung-uk Kim /* Cleanup (for next source file) and exit */ 481eef1b955SJung-uk Kim 482a88e22b7SJung-uk Kim AeClearErrorLog (); 4834c52cad2SJung-uk Kim PrTerminatePreprocessor (); 484a88e22b7SJung-uk Kim return (Status); 485a88e22b7SJung-uk Kim 486a88e22b7SJung-uk Kim /* 487eef1b955SJung-uk Kim * ASL Compilation 488a88e22b7SJung-uk Kim */ 489a88e22b7SJung-uk Kim case ASL_INPUT_TYPE_ASCII_ASL: 490a88e22b7SJung-uk Kim 491a88e22b7SJung-uk Kim /* ACPICA subsystem initialization */ 492a9f12690SJung-uk Kim 493a9f12690SJung-uk Kim Status = AdInitialize (); 494a9f12690SJung-uk Kim if (ACPI_FAILURE (Status)) 495a9f12690SJung-uk Kim { 496a9f12690SJung-uk Kim return (Status); 497a9f12690SJung-uk Kim } 498a9f12690SJung-uk Kim 499eef1b955SJung-uk Kim (void) CmDoCompile (); 50042fecd12SJung-uk Kim (void) AcpiTerminate (); 501a9f12690SJung-uk Kim 502eef1b955SJung-uk Kim /* Check if any errors occurred during compile */ 503eef1b955SJung-uk Kim 504eef1b955SJung-uk Kim Status = AslCheckForErrorExit (); 505eef1b955SJung-uk Kim if (ACPI_FAILURE (Status)) 506a9f12690SJung-uk Kim { 507eef1b955SJung-uk Kim return (Status); 508a9f12690SJung-uk Kim } 509a9f12690SJung-uk Kim 510eef1b955SJung-uk Kim /* Cleanup (for next source file) and exit */ 511eef1b955SJung-uk Kim 512a9f12690SJung-uk Kim AeClearErrorLog (); 5134c52cad2SJung-uk Kim PrTerminatePreprocessor (); 514a9f12690SJung-uk Kim return (AE_OK); 515a88e22b7SJung-uk Kim 5169c48c75eSJung-uk Kim /* 5179c48c75eSJung-uk Kim * Binary ACPI table was auto-detected, disassemble it 5189c48c75eSJung-uk Kim */ 5199c48c75eSJung-uk Kim case ASL_INPUT_TYPE_ACPI_TABLE: 5209c48c75eSJung-uk Kim 5219c48c75eSJung-uk Kim /* We have what appears to be an ACPI table, disassemble it */ 5229c48c75eSJung-uk Kim 5239c48c75eSJung-uk Kim FlCloseFile (ASL_FILE_INPUT); 5249c48c75eSJung-uk Kim Gbl_DoCompile = FALSE; 5259c48c75eSJung-uk Kim Gbl_DisasmFlag = TRUE; 5269c48c75eSJung-uk Kim Status = AslDoDisassembly (); 5279c48c75eSJung-uk Kim return (Status); 5289c48c75eSJung-uk Kim 5299c48c75eSJung-uk Kim /* Unknown binary table */ 5309c48c75eSJung-uk Kim 531a88e22b7SJung-uk Kim case ASL_INPUT_TYPE_BINARY: 532a88e22b7SJung-uk Kim 533a88e22b7SJung-uk Kim AePrintErrorLog (ASL_FILE_STDERR); 534a88e22b7SJung-uk Kim return (AE_ERROR); 535a88e22b7SJung-uk Kim 536a88e22b7SJung-uk Kim default: 537*a9d8d09cSJung-uk Kim 538a88e22b7SJung-uk Kim printf ("Unknown file type %X\n", Gbl_FileType); 539a88e22b7SJung-uk Kim return (AE_ERROR); 540a88e22b7SJung-uk Kim } 541a9f12690SJung-uk Kim } 542a9f12690SJung-uk Kim 543a9f12690SJung-uk Kim 544a9f12690SJung-uk Kim /******************************************************************************* 545a9f12690SJung-uk Kim * 546a9f12690SJung-uk Kim * FUNCTION: AslDoOnePathname 547a9f12690SJung-uk Kim * 548a9f12690SJung-uk Kim * PARAMETERS: Pathname - Full pathname, possibly with wildcards 549a9f12690SJung-uk Kim * 550a9f12690SJung-uk Kim * RETURN: Status 551a9f12690SJung-uk Kim * 552a9f12690SJung-uk Kim * DESCRIPTION: Process one pathname, possible terminated with a wildcard 553a9f12690SJung-uk Kim * specification. If a wildcard, it is expanded and the multiple 554a9f12690SJung-uk Kim * files are processed. 555a9f12690SJung-uk Kim * 556a9f12690SJung-uk Kim ******************************************************************************/ 557a9f12690SJung-uk Kim 558a9f12690SJung-uk Kim ACPI_STATUS 559a9f12690SJung-uk Kim AslDoOnePathname ( 560709fac06SJung-uk Kim char *Pathname, 561709fac06SJung-uk Kim ASL_PATHNAME_CALLBACK PathCallback) 562a9f12690SJung-uk Kim { 563a88e22b7SJung-uk Kim ACPI_STATUS Status = AE_OK; 56442fecd12SJung-uk Kim char **WildcardList; 565a9f12690SJung-uk Kim char *Filename; 566a9f12690SJung-uk Kim char *FullPathname; 567a9f12690SJung-uk Kim 568a9f12690SJung-uk Kim 569a9f12690SJung-uk Kim /* Split incoming path into a directory/filename combo */ 570a9f12690SJung-uk Kim 571a9f12690SJung-uk Kim Status = FlSplitInputPathname (Pathname, &Gbl_DirectoryPath, &Filename); 572a9f12690SJung-uk Kim if (ACPI_FAILURE (Status)) 573a9f12690SJung-uk Kim { 574a9f12690SJung-uk Kim return (Status); 575a9f12690SJung-uk Kim } 576a9f12690SJung-uk Kim 577a9f12690SJung-uk Kim /* Expand possible wildcard into a file list (Windows/DOS only) */ 578a9f12690SJung-uk Kim 57942fecd12SJung-uk Kim WildcardList = AsDoWildcard (Gbl_DirectoryPath, Filename); 58042fecd12SJung-uk Kim while (*WildcardList) 581a9f12690SJung-uk Kim { 582a9f12690SJung-uk Kim FullPathname = ACPI_ALLOCATE ( 58342fecd12SJung-uk Kim strlen (Gbl_DirectoryPath) + strlen (*WildcardList) + 1); 584a9f12690SJung-uk Kim 585a9f12690SJung-uk Kim /* Construct a full path to the file */ 586a9f12690SJung-uk Kim 587a9f12690SJung-uk Kim strcpy (FullPathname, Gbl_DirectoryPath); 58842fecd12SJung-uk Kim strcat (FullPathname, *WildcardList); 589a9f12690SJung-uk Kim 590a9f12690SJung-uk Kim /* 591a9f12690SJung-uk Kim * If -p not specified, we will use the input filename as the 592a9f12690SJung-uk Kim * output filename prefix 593a9f12690SJung-uk Kim */ 594a9f12690SJung-uk Kim if (Gbl_UseDefaultAmlFilename) 595a9f12690SJung-uk Kim { 596a9f12690SJung-uk Kim Gbl_OutputFilenamePrefix = FullPathname; 597a9f12690SJung-uk Kim } 598a9f12690SJung-uk Kim 599a88e22b7SJung-uk Kim /* Save status from all compiles */ 600a88e22b7SJung-uk Kim 601709fac06SJung-uk Kim Status |= (*PathCallback) (FullPathname); 602a9f12690SJung-uk Kim 603a9f12690SJung-uk Kim ACPI_FREE (FullPathname); 60442fecd12SJung-uk Kim ACPI_FREE (*WildcardList); 60542fecd12SJung-uk Kim *WildcardList = NULL; 60642fecd12SJung-uk Kim WildcardList++; 607a9f12690SJung-uk Kim } 608a9f12690SJung-uk Kim 609a9f12690SJung-uk Kim ACPI_FREE (Gbl_DirectoryPath); 610a9f12690SJung-uk Kim ACPI_FREE (Filename); 611a88e22b7SJung-uk Kim return (Status); 612a9f12690SJung-uk Kim } 613a9f12690SJung-uk Kim 614eef1b955SJung-uk Kim 615eef1b955SJung-uk Kim /******************************************************************************* 616eef1b955SJung-uk Kim * 617eef1b955SJung-uk Kim * FUNCTION: AslCheckForErrorExit 618eef1b955SJung-uk Kim * 619eef1b955SJung-uk Kim * PARAMETERS: None. Examines global exception count array 620eef1b955SJung-uk Kim * 621eef1b955SJung-uk Kim * RETURN: Status 622eef1b955SJung-uk Kim * 623eef1b955SJung-uk Kim * DESCRIPTION: Determine if compiler should abort with error status 624eef1b955SJung-uk Kim * 625eef1b955SJung-uk Kim ******************************************************************************/ 626eef1b955SJung-uk Kim 627eef1b955SJung-uk Kim ACPI_STATUS 628eef1b955SJung-uk Kim AslCheckForErrorExit ( 629eef1b955SJung-uk Kim void) 630eef1b955SJung-uk Kim { 631eef1b955SJung-uk Kim 632eef1b955SJung-uk Kim /* 633eef1b955SJung-uk Kim * Return non-zero exit code if there have been errors, unless the 634eef1b955SJung-uk Kim * global ignore error flag has been set 635eef1b955SJung-uk Kim */ 636eef1b955SJung-uk Kim if (!Gbl_IgnoreErrors) 637eef1b955SJung-uk Kim { 638eef1b955SJung-uk Kim if (Gbl_ExceptionCount[ASL_ERROR] > 0) 639eef1b955SJung-uk Kim { 640eef1b955SJung-uk Kim return (AE_ERROR); 641eef1b955SJung-uk Kim } 642eef1b955SJung-uk Kim 643eef1b955SJung-uk Kim /* Optionally treat warnings as errors */ 644eef1b955SJung-uk Kim 645eef1b955SJung-uk Kim if (Gbl_WarningsAsErrors) 646eef1b955SJung-uk Kim { 647eef1b955SJung-uk Kim if ((Gbl_ExceptionCount[ASL_WARNING] > 0) || 648eef1b955SJung-uk Kim (Gbl_ExceptionCount[ASL_WARNING2] > 0) || 649eef1b955SJung-uk Kim (Gbl_ExceptionCount[ASL_WARNING3] > 0)) 650eef1b955SJung-uk Kim { 651eef1b955SJung-uk Kim return (AE_ERROR); 652eef1b955SJung-uk Kim } 653eef1b955SJung-uk Kim } 654eef1b955SJung-uk Kim } 655eef1b955SJung-uk Kim 656eef1b955SJung-uk Kim return (AE_OK); 657eef1b955SJung-uk Kim } 658