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> 47*9c48c75eSJung-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 70*9c48c75eSJung-uk Kim static ACPI_STATUS 71*9c48c75eSJung-uk Kim AslDoDisassembly ( 72*9c48c75eSJung-uk Kim void); 73*9c48c75eSJung-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 232*9c48c75eSJung-uk Kim /* Check for a valid binary ACPI table */ 233*9c48c75eSJung-uk Kim 234*9c48c75eSJung-uk Kim Status = FlCheckForAcpiTable (Info->Handle); 235*9c48c75eSJung-uk Kim if (ACPI_SUCCESS (Status)) 236*9c48c75eSJung-uk Kim { 237*9c48c75eSJung-uk Kim Type = ASL_INPUT_TYPE_ACPI_TABLE; 238*9c48c75eSJung-uk Kim goto Cleanup; 239*9c48c75eSJung-uk Kim } 240*9c48c75eSJung-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 * 296*9c48c75eSJung-uk Kim * FUNCTION: AslDoDisassembly 297*9c48c75eSJung-uk Kim * 298*9c48c75eSJung-uk Kim * PARAMETERS: None 299*9c48c75eSJung-uk Kim * 300*9c48c75eSJung-uk Kim * RETURN: Status 301*9c48c75eSJung-uk Kim * 302*9c48c75eSJung-uk Kim * DESCRIPTION: Initiate AML file disassembly. Uses ACPICA subsystem to build 303*9c48c75eSJung-uk Kim * namespace. 304*9c48c75eSJung-uk Kim * 305*9c48c75eSJung-uk Kim ******************************************************************************/ 306*9c48c75eSJung-uk Kim 307*9c48c75eSJung-uk Kim static ACPI_STATUS 308*9c48c75eSJung-uk Kim AslDoDisassembly ( 309*9c48c75eSJung-uk Kim void) 310*9c48c75eSJung-uk Kim { 311*9c48c75eSJung-uk Kim ACPI_STATUS Status; 312*9c48c75eSJung-uk Kim 313*9c48c75eSJung-uk Kim 314*9c48c75eSJung-uk Kim /* ACPICA subsystem initialization */ 315*9c48c75eSJung-uk Kim 316*9c48c75eSJung-uk Kim Status = AdInitialize (); 317*9c48c75eSJung-uk Kim if (ACPI_FAILURE (Status)) 318*9c48c75eSJung-uk Kim { 319*9c48c75eSJung-uk Kim return (Status); 320*9c48c75eSJung-uk Kim } 321*9c48c75eSJung-uk Kim 322*9c48c75eSJung-uk Kim Status = AcpiAllocateRootTable (4); 323*9c48c75eSJung-uk Kim if (ACPI_FAILURE (Status)) 324*9c48c75eSJung-uk Kim { 325*9c48c75eSJung-uk Kim AcpiOsPrintf ("Could not initialize ACPI Table Manager, %s\n", 326*9c48c75eSJung-uk Kim AcpiFormatException (Status)); 327*9c48c75eSJung-uk Kim return (Status); 328*9c48c75eSJung-uk Kim } 329*9c48c75eSJung-uk Kim 330*9c48c75eSJung-uk Kim /* This is where the disassembly happens */ 331*9c48c75eSJung-uk Kim 332*9c48c75eSJung-uk Kim AcpiGbl_DbOpt_disasm = TRUE; 333*9c48c75eSJung-uk Kim Status = AdAmlDisassemble (AslToFile, 334*9c48c75eSJung-uk Kim Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_OutputFilenamePrefix, 335*9c48c75eSJung-uk Kim &Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_GetAllTables); 336*9c48c75eSJung-uk Kim if (ACPI_FAILURE (Status)) 337*9c48c75eSJung-uk Kim { 338*9c48c75eSJung-uk Kim return (Status); 339*9c48c75eSJung-uk Kim } 340*9c48c75eSJung-uk Kim 341*9c48c75eSJung-uk Kim /* Check if any control methods were unresolved */ 342*9c48c75eSJung-uk Kim 343*9c48c75eSJung-uk Kim AcpiDmUnresolvedWarning (0); 344*9c48c75eSJung-uk Kim 345*9c48c75eSJung-uk Kim #if 0 346*9c48c75eSJung-uk Kim /* TBD: Handle additional output files for disassembler */ 347*9c48c75eSJung-uk Kim 348*9c48c75eSJung-uk Kim Status = FlOpenMiscOutputFiles (Gbl_OutputFilenamePrefix); 349*9c48c75eSJung-uk Kim NsDisplayNamespace (); 350*9c48c75eSJung-uk Kim #endif 351*9c48c75eSJung-uk Kim 352*9c48c75eSJung-uk Kim /* Shutdown compiler and ACPICA subsystem */ 353*9c48c75eSJung-uk Kim 354*9c48c75eSJung-uk Kim AeClearErrorLog (); 355*9c48c75eSJung-uk Kim (void) AcpiTerminate (); 356*9c48c75eSJung-uk Kim 357*9c48c75eSJung-uk Kim /* 358*9c48c75eSJung-uk Kim * Gbl_Files[ASL_FILE_INPUT].Filename was replaced with the 359*9c48c75eSJung-uk Kim * .DSL disassembly file, which can now be compiled if requested 360*9c48c75eSJung-uk Kim */ 361*9c48c75eSJung-uk Kim if (Gbl_DoCompile) 362*9c48c75eSJung-uk Kim { 363*9c48c75eSJung-uk Kim AcpiOsPrintf ("\nCompiling \"%s\"\n", 364*9c48c75eSJung-uk Kim Gbl_Files[ASL_FILE_INPUT].Filename); 365*9c48c75eSJung-uk Kim return (AE_CTRL_CONTINUE); 366*9c48c75eSJung-uk Kim } 367*9c48c75eSJung-uk Kim 368*9c48c75eSJung-uk Kim ACPI_FREE (Gbl_Files[ASL_FILE_INPUT].Filename); 369*9c48c75eSJung-uk Kim Gbl_Files[ASL_FILE_INPUT].Filename = NULL; 370*9c48c75eSJung-uk Kim return (AE_OK); 371*9c48c75eSJung-uk Kim } 372*9c48c75eSJung-uk Kim 373*9c48c75eSJung-uk Kim 374*9c48c75eSJung-uk Kim /******************************************************************************* 375*9c48c75eSJung-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 { 405*9c48c75eSJung-uk Kim Status = AslDoDisassembly (); 406*9c48c75eSJung-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 516*9c48c75eSJung-uk Kim /* 517*9c48c75eSJung-uk Kim * Binary ACPI table was auto-detected, disassemble it 518*9c48c75eSJung-uk Kim */ 519*9c48c75eSJung-uk Kim case ASL_INPUT_TYPE_ACPI_TABLE: 520*9c48c75eSJung-uk Kim 521*9c48c75eSJung-uk Kim /* We have what appears to be an ACPI table, disassemble it */ 522*9c48c75eSJung-uk Kim 523*9c48c75eSJung-uk Kim FlCloseFile (ASL_FILE_INPUT); 524*9c48c75eSJung-uk Kim Gbl_DoCompile = FALSE; 525*9c48c75eSJung-uk Kim Gbl_DisasmFlag = TRUE; 526*9c48c75eSJung-uk Kim Status = AslDoDisassembly (); 527*9c48c75eSJung-uk Kim return (Status); 528*9c48c75eSJung-uk Kim 529*9c48c75eSJung-uk Kim /* Unknown binary table */ 530*9c48c75eSJung-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: 537a88e22b7SJung-uk Kim printf ("Unknown file type %X\n", Gbl_FileType); 538a88e22b7SJung-uk Kim return (AE_ERROR); 539a88e22b7SJung-uk Kim } 540a9f12690SJung-uk Kim } 541a9f12690SJung-uk Kim 542a9f12690SJung-uk Kim 543a9f12690SJung-uk Kim /******************************************************************************* 544a9f12690SJung-uk Kim * 545a9f12690SJung-uk Kim * FUNCTION: AslDoOnePathname 546a9f12690SJung-uk Kim * 547a9f12690SJung-uk Kim * PARAMETERS: Pathname - Full pathname, possibly with wildcards 548a9f12690SJung-uk Kim * 549a9f12690SJung-uk Kim * RETURN: Status 550a9f12690SJung-uk Kim * 551a9f12690SJung-uk Kim * DESCRIPTION: Process one pathname, possible terminated with a wildcard 552a9f12690SJung-uk Kim * specification. If a wildcard, it is expanded and the multiple 553a9f12690SJung-uk Kim * files are processed. 554a9f12690SJung-uk Kim * 555a9f12690SJung-uk Kim ******************************************************************************/ 556a9f12690SJung-uk Kim 557a9f12690SJung-uk Kim ACPI_STATUS 558a9f12690SJung-uk Kim AslDoOnePathname ( 559709fac06SJung-uk Kim char *Pathname, 560709fac06SJung-uk Kim ASL_PATHNAME_CALLBACK PathCallback) 561a9f12690SJung-uk Kim { 562a88e22b7SJung-uk Kim ACPI_STATUS Status = AE_OK; 56342fecd12SJung-uk Kim char **WildcardList; 564a9f12690SJung-uk Kim char *Filename; 565a9f12690SJung-uk Kim char *FullPathname; 566a9f12690SJung-uk Kim 567a9f12690SJung-uk Kim 568a9f12690SJung-uk Kim /* Split incoming path into a directory/filename combo */ 569a9f12690SJung-uk Kim 570a9f12690SJung-uk Kim Status = FlSplitInputPathname (Pathname, &Gbl_DirectoryPath, &Filename); 571a9f12690SJung-uk Kim if (ACPI_FAILURE (Status)) 572a9f12690SJung-uk Kim { 573a9f12690SJung-uk Kim return (Status); 574a9f12690SJung-uk Kim } 575a9f12690SJung-uk Kim 576a9f12690SJung-uk Kim /* Expand possible wildcard into a file list (Windows/DOS only) */ 577a9f12690SJung-uk Kim 57842fecd12SJung-uk Kim WildcardList = AsDoWildcard (Gbl_DirectoryPath, Filename); 57942fecd12SJung-uk Kim while (*WildcardList) 580a9f12690SJung-uk Kim { 581a9f12690SJung-uk Kim FullPathname = ACPI_ALLOCATE ( 58242fecd12SJung-uk Kim strlen (Gbl_DirectoryPath) + strlen (*WildcardList) + 1); 583a9f12690SJung-uk Kim 584a9f12690SJung-uk Kim /* Construct a full path to the file */ 585a9f12690SJung-uk Kim 586a9f12690SJung-uk Kim strcpy (FullPathname, Gbl_DirectoryPath); 58742fecd12SJung-uk Kim strcat (FullPathname, *WildcardList); 588a9f12690SJung-uk Kim 589a9f12690SJung-uk Kim /* 590a9f12690SJung-uk Kim * If -p not specified, we will use the input filename as the 591a9f12690SJung-uk Kim * output filename prefix 592a9f12690SJung-uk Kim */ 593a9f12690SJung-uk Kim if (Gbl_UseDefaultAmlFilename) 594a9f12690SJung-uk Kim { 595a9f12690SJung-uk Kim Gbl_OutputFilenamePrefix = FullPathname; 596a9f12690SJung-uk Kim } 597a9f12690SJung-uk Kim 598a88e22b7SJung-uk Kim /* Save status from all compiles */ 599a88e22b7SJung-uk Kim 600709fac06SJung-uk Kim Status |= (*PathCallback) (FullPathname); 601a9f12690SJung-uk Kim 602a9f12690SJung-uk Kim ACPI_FREE (FullPathname); 60342fecd12SJung-uk Kim ACPI_FREE (*WildcardList); 60442fecd12SJung-uk Kim *WildcardList = NULL; 60542fecd12SJung-uk Kim WildcardList++; 606a9f12690SJung-uk Kim } 607a9f12690SJung-uk Kim 608a9f12690SJung-uk Kim ACPI_FREE (Gbl_DirectoryPath); 609a9f12690SJung-uk Kim ACPI_FREE (Filename); 610a88e22b7SJung-uk Kim return (Status); 611a9f12690SJung-uk Kim } 612a9f12690SJung-uk Kim 613eef1b955SJung-uk Kim 614eef1b955SJung-uk Kim /******************************************************************************* 615eef1b955SJung-uk Kim * 616eef1b955SJung-uk Kim * FUNCTION: AslCheckForErrorExit 617eef1b955SJung-uk Kim * 618eef1b955SJung-uk Kim * PARAMETERS: None. Examines global exception count array 619eef1b955SJung-uk Kim * 620eef1b955SJung-uk Kim * RETURN: Status 621eef1b955SJung-uk Kim * 622eef1b955SJung-uk Kim * DESCRIPTION: Determine if compiler should abort with error status 623eef1b955SJung-uk Kim * 624eef1b955SJung-uk Kim ******************************************************************************/ 625eef1b955SJung-uk Kim 626eef1b955SJung-uk Kim ACPI_STATUS 627eef1b955SJung-uk Kim AslCheckForErrorExit ( 628eef1b955SJung-uk Kim void) 629eef1b955SJung-uk Kim { 630eef1b955SJung-uk Kim 631eef1b955SJung-uk Kim /* 632eef1b955SJung-uk Kim * Return non-zero exit code if there have been errors, unless the 633eef1b955SJung-uk Kim * global ignore error flag has been set 634eef1b955SJung-uk Kim */ 635eef1b955SJung-uk Kim if (!Gbl_IgnoreErrors) 636eef1b955SJung-uk Kim { 637eef1b955SJung-uk Kim if (Gbl_ExceptionCount[ASL_ERROR] > 0) 638eef1b955SJung-uk Kim { 639eef1b955SJung-uk Kim return (AE_ERROR); 640eef1b955SJung-uk Kim } 641eef1b955SJung-uk Kim 642eef1b955SJung-uk Kim /* Optionally treat warnings as errors */ 643eef1b955SJung-uk Kim 644eef1b955SJung-uk Kim if (Gbl_WarningsAsErrors) 645eef1b955SJung-uk Kim { 646eef1b955SJung-uk Kim if ((Gbl_ExceptionCount[ASL_WARNING] > 0) || 647eef1b955SJung-uk Kim (Gbl_ExceptionCount[ASL_WARNING2] > 0) || 648eef1b955SJung-uk Kim (Gbl_ExceptionCount[ASL_WARNING3] > 0)) 649eef1b955SJung-uk Kim { 650eef1b955SJung-uk Kim return (AE_ERROR); 651eef1b955SJung-uk Kim } 652eef1b955SJung-uk Kim } 653eef1b955SJung-uk Kim } 654eef1b955SJung-uk Kim 655eef1b955SJung-uk Kim return (AE_OK); 656eef1b955SJung-uk Kim } 657