aslstartup.c revision 193341
1193267Sjkim 2193267Sjkim/****************************************************************************** 3193267Sjkim * 4193267Sjkim * Module Name: aslstartup - Compiler startup routines, called from main 5193267Sjkim * 6193267Sjkim *****************************************************************************/ 7193267Sjkim 8193267Sjkim/****************************************************************************** 9193267Sjkim * 10193267Sjkim * 1. Copyright Notice 11193267Sjkim * 12193267Sjkim * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp. 13193267Sjkim * All rights reserved. 14193267Sjkim * 15193267Sjkim * 2. License 16193267Sjkim * 17193267Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property 18193267Sjkim * rights. You may have additional license terms from the party that provided 19193267Sjkim * you this software, covering your right to use that party's intellectual 20193267Sjkim * property rights. 21193267Sjkim * 22193267Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23193267Sjkim * copy of the source code appearing in this file ("Covered Code") an 24193267Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25193267Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy, 26193267Sjkim * make derivatives, distribute, use and display any portion of the Covered 27193267Sjkim * Code in any form, with the right to sublicense such rights; and 28193267Sjkim * 29193267Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30193267Sjkim * license (with the right to sublicense), under only those claims of Intel 31193267Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell, 32193267Sjkim * offer to sell, and import the Covered Code and derivative works thereof 33193267Sjkim * solely to the minimum extent necessary to exercise the above copyright 34193267Sjkim * license, and in no event shall the patent license extend to any additions 35193267Sjkim * to or modifications of the Original Intel Code. No other license or right 36193267Sjkim * is granted directly or by implication, estoppel or otherwise; 37193267Sjkim * 38193267Sjkim * The above copyright and patent license is granted only if the following 39193267Sjkim * conditions are met: 40193267Sjkim * 41193267Sjkim * 3. Conditions 42193267Sjkim * 43193267Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44193267Sjkim * Redistribution of source code of any substantial portion of the Covered 45193267Sjkim * Code or modification with rights to further distribute source must include 46193267Sjkim * the above Copyright Notice, the above License, this list of Conditions, 47193267Sjkim * and the following Disclaimer and Export Compliance provision. In addition, 48193267Sjkim * Licensee must cause all Covered Code to which Licensee contributes to 49193267Sjkim * contain a file documenting the changes Licensee made to create that Covered 50193267Sjkim * Code and the date of any change. Licensee must include in that file the 51193267Sjkim * documentation of any changes made by any predecessor Licensee. Licensee 52193267Sjkim * must include a prominent statement that the modification is derived, 53193267Sjkim * directly or indirectly, from Original Intel Code. 54193267Sjkim * 55193267Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56193267Sjkim * Redistribution of source code of any substantial portion of the Covered 57193267Sjkim * Code or modification without rights to further distribute source must 58193267Sjkim * include the following Disclaimer and Export Compliance provision in the 59193267Sjkim * documentation and/or other materials provided with distribution. In 60193267Sjkim * addition, Licensee may not authorize further sublicense of source of any 61193267Sjkim * portion of the Covered Code, and must include terms to the effect that the 62193267Sjkim * license from Licensee to its licensee is limited to the intellectual 63193267Sjkim * property embodied in the software Licensee provides to its licensee, and 64193267Sjkim * not to intellectual property embodied in modifications its licensee may 65193267Sjkim * make. 66193267Sjkim * 67193267Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any 68193267Sjkim * substantial portion of the Covered Code or modification must reproduce the 69193267Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance 70193267Sjkim * provision in the documentation and/or other materials provided with the 71193267Sjkim * distribution. 72193267Sjkim * 73193267Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original 74193267Sjkim * Intel Code. 75193267Sjkim * 76193267Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77193267Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or 78193267Sjkim * other dealings in products derived from or relating to the Covered Code 79193267Sjkim * without prior written authorization from Intel. 80193267Sjkim * 81193267Sjkim * 4. Disclaimer and Export Compliance 82193267Sjkim * 83193267Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84193267Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85193267Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86193267Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87193267Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88193267Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89193267Sjkim * PARTICULAR PURPOSE. 90193267Sjkim * 91193267Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92193267Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93193267Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94193267Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95193267Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96193267Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97193267Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98193267Sjkim * LIMITED REMEDY. 99193267Sjkim * 100193267Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this 101193267Sjkim * software or system incorporating such software without first obtaining any 102193267Sjkim * required license or other approval from the U. S. Department of Commerce or 103193267Sjkim * any other agency or department of the United States Government. In the 104193267Sjkim * event Licensee exports any such software from the United States or 105193267Sjkim * re-exports any such software from a foreign destination, Licensee shall 106193267Sjkim * ensure that the distribution and export/re-export of the software is in 107193267Sjkim * compliance with all laws, regulations, orders, or other restrictions of the 108193267Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109193267Sjkim * any of its subsidiaries will export/re-export any technical data, process, 110193267Sjkim * software, or service, directly or indirectly, to any country for which the 111193267Sjkim * United States government or any agency thereof requires an export license, 112193267Sjkim * other governmental approval, or letter of assurance, without first obtaining 113193267Sjkim * such license, approval or letter. 114193267Sjkim * 115193267Sjkim *****************************************************************************/ 116193267Sjkim 117193267Sjkim 118193341Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h> 119193341Sjkim#include <contrib/dev/acpica/include/actables.h> 120193341Sjkim#include <contrib/dev/acpica/include/acapps.h> 121193267Sjkim 122193267Sjkim#define _COMPONENT ACPI_COMPILER 123193267Sjkim ACPI_MODULE_NAME ("aslstartup") 124193267Sjkim 125193267Sjkim 126193267Sjkim#define ASL_MAX_FILES 256 127193267Sjkimchar *FileList[ASL_MAX_FILES]; 128193267Sjkimint FileCount; 129193267SjkimBOOLEAN AslToFile = TRUE; 130193267Sjkim 131193267Sjkim 132193267Sjkim/* Local prototypes */ 133193267Sjkim 134193267Sjkimstatic void 135193267SjkimAslInitializeGlobals ( 136193267Sjkim void); 137193267Sjkim 138193267Sjkimstatic char ** 139193267SjkimAsDoWildcard ( 140193267Sjkim char *DirectoryPathname, 141193267Sjkim char *FileSpecifier); 142193267Sjkim 143193267Sjkim 144193267Sjkim/******************************************************************************* 145193267Sjkim * 146193267Sjkim * FUNCTION: AslInitializeGlobals 147193267Sjkim * 148193267Sjkim * PARAMETERS: None 149193267Sjkim * 150193267Sjkim * RETURN: None 151193267Sjkim * 152193267Sjkim * DESCRIPTION: Re-initialize globals needed to restart the compiler. This 153193267Sjkim * allows multiple files to be disassembled and/or compiled. 154193267Sjkim * 155193267Sjkim ******************************************************************************/ 156193267Sjkim 157193267Sjkimstatic void 158193267SjkimAslInitializeGlobals ( 159193267Sjkim void) 160193267Sjkim{ 161193267Sjkim UINT32 i; 162193267Sjkim 163193267Sjkim 164193267Sjkim /* Init compiler globals */ 165193267Sjkim 166193267Sjkim Gbl_CurrentColumn = 0; 167193267Sjkim Gbl_CurrentLineNumber = 1; 168193267Sjkim Gbl_LogicalLineNumber = 1; 169193267Sjkim Gbl_CurrentLineOffset = 0; 170193267Sjkim Gbl_LineBufPtr = Gbl_CurrentLineBuffer; 171193267Sjkim 172193267Sjkim Gbl_ErrorLog = NULL; 173193267Sjkim Gbl_NextError = NULL; 174193267Sjkim 175193267Sjkim AslGbl_NextEvent = 0; 176193267Sjkim for (i = 0; i < ASL_NUM_REPORT_LEVELS; i++) 177193267Sjkim { 178193267Sjkim Gbl_ExceptionCount[i] = 0; 179193267Sjkim } 180193267Sjkim 181193267Sjkim Gbl_Files[ASL_FILE_AML_OUTPUT].Filename = NULL; 182193267Sjkim} 183193267Sjkim 184193267Sjkim 185193267Sjkim/****************************************************************************** 186193267Sjkim * 187193267Sjkim * FUNCTION: AsDoWildcard 188193267Sjkim * 189193267Sjkim * PARAMETERS: None 190193267Sjkim * 191193267Sjkim * RETURN: None 192193267Sjkim * 193193267Sjkim * DESCRIPTION: Process files via wildcards. This function is for the Windows 194193267Sjkim * case only. 195193267Sjkim * 196193267Sjkim ******************************************************************************/ 197193267Sjkim 198193267Sjkimstatic char ** 199193267SjkimAsDoWildcard ( 200193267Sjkim char *DirectoryPathname, 201193267Sjkim char *FileSpecifier) 202193267Sjkim{ 203193267Sjkim#ifdef WIN32 204193267Sjkim void *DirInfo; 205193267Sjkim char *Filename; 206193267Sjkim 207193267Sjkim 208193267Sjkim FileCount = 0; 209193267Sjkim 210193267Sjkim /* Open parent directory */ 211193267Sjkim 212193267Sjkim DirInfo = AcpiOsOpenDirectory (DirectoryPathname, FileSpecifier, REQUEST_FILE_ONLY); 213193267Sjkim if (!DirInfo) 214193267Sjkim { 215193267Sjkim /* Either the directory of file does not exist */ 216193267Sjkim 217193267Sjkim Gbl_Files[ASL_FILE_INPUT].Filename = FileSpecifier; 218193267Sjkim FlFileError (ASL_FILE_INPUT, ASL_MSG_OPEN); 219193267Sjkim AslAbort (); 220193267Sjkim } 221193267Sjkim 222193267Sjkim /* Process each file that matches the wildcard specification */ 223193267Sjkim 224193267Sjkim while ((Filename = AcpiOsGetNextFilename (DirInfo))) 225193267Sjkim { 226193267Sjkim /* Add the filename to the file list */ 227193267Sjkim 228193267Sjkim FileList[FileCount] = AcpiOsAllocate (strlen (Filename) + 1); 229193267Sjkim strcpy (FileList[FileCount], Filename); 230193267Sjkim FileCount++; 231193267Sjkim 232193267Sjkim if (FileCount >= ASL_MAX_FILES) 233193267Sjkim { 234193267Sjkim printf ("Max files reached\n"); 235193267Sjkim FileList[0] = NULL; 236193267Sjkim return (FileList); 237193267Sjkim } 238193267Sjkim } 239193267Sjkim 240193267Sjkim /* Cleanup */ 241193267Sjkim 242193267Sjkim AcpiOsCloseDirectory (DirInfo); 243193267Sjkim FileList[FileCount] = NULL; 244193267Sjkim return (FileList); 245193267Sjkim 246193267Sjkim#else 247193267Sjkim /* 248193267Sjkim * Linux/Unix cases - Wildcards are expanded by the shell automatically. 249193267Sjkim * Just return the filename in a null terminated list 250193267Sjkim */ 251193267Sjkim FileList[0] = AcpiOsAllocate (strlen (FileSpecifier) + 1); 252193267Sjkim strcpy (FileList[0], FileSpecifier); 253193267Sjkim FileList[1] = NULL; 254193267Sjkim 255193267Sjkim return (FileList); 256193267Sjkim#endif 257193267Sjkim} 258193267Sjkim 259193267Sjkim 260193267Sjkim/******************************************************************************* 261193267Sjkim * 262193267Sjkim * FUNCTION: AslDoOneFile 263193267Sjkim * 264193267Sjkim * PARAMETERS: Filename - Name of the file 265193267Sjkim * 266193267Sjkim * RETURN: Status 267193267Sjkim * 268193267Sjkim * DESCRIPTION: Process a single file - either disassemble, compile, or both 269193267Sjkim * 270193267Sjkim ******************************************************************************/ 271193267Sjkim 272193267SjkimACPI_STATUS 273193267SjkimAslDoOneFile ( 274193267Sjkim char *Filename) 275193267Sjkim{ 276193267Sjkim ACPI_STATUS Status; 277193267Sjkim 278193267Sjkim 279193267Sjkim Gbl_Files[ASL_FILE_INPUT].Filename = Filename; 280193267Sjkim 281193267Sjkim /* Re-initialize "some" compiler globals */ 282193267Sjkim 283193267Sjkim AslInitializeGlobals (); 284193267Sjkim 285193267Sjkim /* 286193267Sjkim * AML Disassembly (Optional) 287193267Sjkim */ 288193267Sjkim if (Gbl_DisasmFlag || Gbl_GetAllTables) 289193267Sjkim { 290193267Sjkim /* ACPI CA subsystem initialization */ 291193267Sjkim 292193267Sjkim Status = AdInitialize (); 293193267Sjkim if (ACPI_FAILURE (Status)) 294193267Sjkim { 295193267Sjkim return (Status); 296193267Sjkim } 297193267Sjkim 298193267Sjkim Status = AcpiAllocateRootTable (4); 299193267Sjkim if (ACPI_FAILURE (Status)) 300193267Sjkim { 301193267Sjkim AcpiOsPrintf ("Could not initialize ACPI Table Manager, %s\n", 302193267Sjkim AcpiFormatException (Status)); 303193267Sjkim return (Status); 304193267Sjkim } 305193267Sjkim 306193267Sjkim /* This is where the disassembly happens */ 307193267Sjkim 308193267Sjkim AcpiGbl_DbOpt_disasm = TRUE; 309193267Sjkim Status = AdAmlDisassemble (AslToFile, 310193267Sjkim Gbl_Files[ASL_FILE_INPUT].Filename, 311193267Sjkim Gbl_OutputFilenamePrefix, 312193267Sjkim &Gbl_Files[ASL_FILE_INPUT].Filename, 313193267Sjkim Gbl_GetAllTables); 314193267Sjkim if (ACPI_FAILURE (Status)) 315193267Sjkim { 316193267Sjkim return (Status); 317193267Sjkim } 318193267Sjkim 319193267Sjkim /* Shutdown compiler and ACPICA subsystem */ 320193267Sjkim 321193267Sjkim AeClearErrorLog (); 322193267Sjkim AcpiTerminate (); 323193267Sjkim 324193267Sjkim /* 325193267Sjkim * Gbl_Files[ASL_FILE_INPUT].Filename was replaced with the 326193267Sjkim * .DSL disassembly file, which can now be compiled if requested 327193267Sjkim */ 328193267Sjkim if (Gbl_DoCompile) 329193267Sjkim { 330193267Sjkim AcpiOsPrintf ("\nCompiling \"%s\"\n", 331193267Sjkim Gbl_Files[ASL_FILE_INPUT].Filename); 332193267Sjkim } 333193267Sjkim } 334193267Sjkim 335193267Sjkim /* 336193267Sjkim * ASL Compilation (Optional) 337193267Sjkim */ 338193267Sjkim if (Gbl_DoCompile) 339193267Sjkim { 340193267Sjkim /* 341193267Sjkim * If -p not specified, we will use the input filename as the 342193267Sjkim * output filename prefix 343193267Sjkim */ 344193267Sjkim if (Gbl_UseDefaultAmlFilename) 345193267Sjkim { 346193267Sjkim Gbl_OutputFilenamePrefix = Gbl_Files[ASL_FILE_INPUT].Filename; 347193267Sjkim } 348193267Sjkim 349193267Sjkim /* ACPI CA subsystem initialization (Must be re-initialized) */ 350193267Sjkim 351193267Sjkim Status = AdInitialize (); 352193267Sjkim if (ACPI_FAILURE (Status)) 353193267Sjkim { 354193267Sjkim return (Status); 355193267Sjkim } 356193267Sjkim 357193267Sjkim Status = CmDoCompile (); 358193267Sjkim AcpiTerminate (); 359193267Sjkim 360193267Sjkim /* 361193267Sjkim * Return non-zero exit code if there have been errors, unless the 362193267Sjkim * global ignore error flag has been set 363193267Sjkim */ 364193267Sjkim if ((Gbl_ExceptionCount[ASL_ERROR] > 0) && (!Gbl_IgnoreErrors)) 365193267Sjkim { 366193267Sjkim return (AE_ERROR); 367193267Sjkim } 368193267Sjkim 369193267Sjkim AeClearErrorLog (); 370193267Sjkim } 371193267Sjkim 372193267Sjkim return (AE_OK); 373193267Sjkim} 374193267Sjkim 375193267Sjkim 376193267Sjkim/******************************************************************************* 377193267Sjkim * 378193267Sjkim * FUNCTION: AslDoOnePathname 379193267Sjkim * 380193267Sjkim * PARAMETERS: Pathname - Full pathname, possibly with wildcards 381193267Sjkim * 382193267Sjkim * RETURN: Status 383193267Sjkim * 384193267Sjkim * DESCRIPTION: Process one pathname, possible terminated with a wildcard 385193267Sjkim * specification. If a wildcard, it is expanded and the multiple 386193267Sjkim * files are processed. 387193267Sjkim * 388193267Sjkim ******************************************************************************/ 389193267Sjkim 390193267SjkimACPI_STATUS 391193267SjkimAslDoOnePathname ( 392193267Sjkim char *Pathname) 393193267Sjkim{ 394193267Sjkim ACPI_STATUS Status; 395193267Sjkim char **FileList; 396193267Sjkim char *Filename; 397193267Sjkim char *FullPathname; 398193267Sjkim 399193267Sjkim 400193267Sjkim /* Split incoming path into a directory/filename combo */ 401193267Sjkim 402193267Sjkim Status = FlSplitInputPathname (Pathname, &Gbl_DirectoryPath, &Filename); 403193267Sjkim if (ACPI_FAILURE (Status)) 404193267Sjkim { 405193267Sjkim return (Status); 406193267Sjkim } 407193267Sjkim 408193267Sjkim /* Expand possible wildcard into a file list (Windows/DOS only) */ 409193267Sjkim 410193267Sjkim FileList = AsDoWildcard (Gbl_DirectoryPath, Filename); 411193267Sjkim while (*FileList) 412193267Sjkim { 413193267Sjkim FullPathname = ACPI_ALLOCATE ( 414193267Sjkim strlen (Gbl_DirectoryPath) + strlen (*FileList) + 1); 415193267Sjkim 416193267Sjkim /* Construct a full path to the file */ 417193267Sjkim 418193267Sjkim strcpy (FullPathname, Gbl_DirectoryPath); 419193267Sjkim strcat (FullPathname, *FileList); 420193267Sjkim 421193267Sjkim /* 422193267Sjkim * If -p not specified, we will use the input filename as the 423193267Sjkim * output filename prefix 424193267Sjkim */ 425193267Sjkim if (Gbl_UseDefaultAmlFilename) 426193267Sjkim { 427193267Sjkim Gbl_OutputFilenamePrefix = FullPathname; 428193267Sjkim } 429193267Sjkim 430193267Sjkim Status = AslDoOneFile (FullPathname); 431193267Sjkim if (ACPI_FAILURE (Status)) 432193267Sjkim { 433193267Sjkim return (Status); 434193267Sjkim } 435193267Sjkim 436193267Sjkim ACPI_FREE (FullPathname); 437193267Sjkim ACPI_FREE (*FileList); 438193267Sjkim *FileList = NULL; 439193267Sjkim FileList++; 440193267Sjkim } 441193267Sjkim 442193267Sjkim ACPI_FREE (Gbl_DirectoryPath); 443193267Sjkim ACPI_FREE (Filename); 444193267Sjkim return (AE_OK); 445193267Sjkim} 446193267Sjkim 447