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 70d84335fSJung-uk Kim /****************************************************************************** 80d84335fSJung-uk Kim * 90d84335fSJung-uk Kim * 1. Copyright Notice 100d84335fSJung-uk Kim * 11e5e1f58aSJung-uk Kim * Some or all of this work - Copyright (c) 1999 - 2019, Intel Corp. 12a9f12690SJung-uk Kim * All rights reserved. 13a9f12690SJung-uk Kim * 140d84335fSJung-uk Kim * 2. License 150d84335fSJung-uk Kim * 160d84335fSJung-uk Kim * 2.1. This is your license from Intel Corp. under its intellectual property 170d84335fSJung-uk Kim * rights. You may have additional license terms from the party that provided 180d84335fSJung-uk Kim * you this software, covering your right to use that party's intellectual 190d84335fSJung-uk Kim * property rights. 200d84335fSJung-uk Kim * 210d84335fSJung-uk Kim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 220d84335fSJung-uk Kim * copy of the source code appearing in this file ("Covered Code") an 230d84335fSJung-uk Kim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 240d84335fSJung-uk Kim * base code distributed originally by Intel ("Original Intel Code") to copy, 250d84335fSJung-uk Kim * make derivatives, distribute, use and display any portion of the Covered 260d84335fSJung-uk Kim * Code in any form, with the right to sublicense such rights; and 270d84335fSJung-uk Kim * 280d84335fSJung-uk Kim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 290d84335fSJung-uk Kim * license (with the right to sublicense), under only those claims of Intel 300d84335fSJung-uk Kim * patents that are infringed by the Original Intel Code, to make, use, sell, 310d84335fSJung-uk Kim * offer to sell, and import the Covered Code and derivative works thereof 320d84335fSJung-uk Kim * solely to the minimum extent necessary to exercise the above copyright 330d84335fSJung-uk Kim * license, and in no event shall the patent license extend to any additions 340d84335fSJung-uk Kim * to or modifications of the Original Intel Code. No other license or right 350d84335fSJung-uk Kim * is granted directly or by implication, estoppel or otherwise; 360d84335fSJung-uk Kim * 370d84335fSJung-uk Kim * The above copyright and patent license is granted only if the following 380d84335fSJung-uk Kim * conditions are met: 390d84335fSJung-uk Kim * 400d84335fSJung-uk Kim * 3. Conditions 410d84335fSJung-uk Kim * 420d84335fSJung-uk Kim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 430d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered 440d84335fSJung-uk Kim * Code or modification with rights to further distribute source must include 450d84335fSJung-uk Kim * the above Copyright Notice, the above License, this list of Conditions, 460d84335fSJung-uk Kim * and the following Disclaimer and Export Compliance provision. In addition, 470d84335fSJung-uk Kim * Licensee must cause all Covered Code to which Licensee contributes to 480d84335fSJung-uk Kim * contain a file documenting the changes Licensee made to create that Covered 490d84335fSJung-uk Kim * Code and the date of any change. Licensee must include in that file the 500d84335fSJung-uk Kim * documentation of any changes made by any predecessor Licensee. Licensee 510d84335fSJung-uk Kim * must include a prominent statement that the modification is derived, 520d84335fSJung-uk Kim * directly or indirectly, from Original Intel Code. 530d84335fSJung-uk Kim * 540d84335fSJung-uk Kim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 550d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered 560d84335fSJung-uk Kim * Code or modification without rights to further distribute source must 570d84335fSJung-uk Kim * include the following Disclaimer and Export Compliance provision in the 580d84335fSJung-uk Kim * documentation and/or other materials provided with distribution. In 590d84335fSJung-uk Kim * addition, Licensee may not authorize further sublicense of source of any 600d84335fSJung-uk Kim * portion of the Covered Code, and must include terms to the effect that the 610d84335fSJung-uk Kim * license from Licensee to its licensee is limited to the intellectual 620d84335fSJung-uk Kim * property embodied in the software Licensee provides to its licensee, and 630d84335fSJung-uk Kim * not to intellectual property embodied in modifications its licensee may 640d84335fSJung-uk Kim * make. 650d84335fSJung-uk Kim * 660d84335fSJung-uk Kim * 3.3. Redistribution of Executable. Redistribution in executable form of any 670d84335fSJung-uk Kim * substantial portion of the Covered Code or modification must reproduce the 680d84335fSJung-uk Kim * above Copyright Notice, and the following Disclaimer and Export Compliance 690d84335fSJung-uk Kim * provision in the documentation and/or other materials provided with the 700d84335fSJung-uk Kim * distribution. 710d84335fSJung-uk Kim * 720d84335fSJung-uk Kim * 3.4. Intel retains all right, title, and interest in and to the Original 730d84335fSJung-uk Kim * Intel Code. 740d84335fSJung-uk Kim * 750d84335fSJung-uk Kim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 760d84335fSJung-uk Kim * Intel shall be used in advertising or otherwise to promote the sale, use or 770d84335fSJung-uk Kim * other dealings in products derived from or relating to the Covered Code 780d84335fSJung-uk Kim * without prior written authorization from Intel. 790d84335fSJung-uk Kim * 800d84335fSJung-uk Kim * 4. Disclaimer and Export Compliance 810d84335fSJung-uk Kim * 820d84335fSJung-uk Kim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 830d84335fSJung-uk Kim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 840d84335fSJung-uk Kim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 850d84335fSJung-uk Kim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 860d84335fSJung-uk Kim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 870d84335fSJung-uk Kim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 880d84335fSJung-uk Kim * PARTICULAR PURPOSE. 890d84335fSJung-uk Kim * 900d84335fSJung-uk Kim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 910d84335fSJung-uk Kim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 920d84335fSJung-uk Kim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 930d84335fSJung-uk Kim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 940d84335fSJung-uk Kim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 950d84335fSJung-uk Kim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 960d84335fSJung-uk Kim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 970d84335fSJung-uk Kim * LIMITED REMEDY. 980d84335fSJung-uk Kim * 990d84335fSJung-uk Kim * 4.3. Licensee shall not export, either directly or indirectly, any of this 1000d84335fSJung-uk Kim * software or system incorporating such software without first obtaining any 1010d84335fSJung-uk Kim * required license or other approval from the U. S. Department of Commerce or 1020d84335fSJung-uk Kim * any other agency or department of the United States Government. In the 1030d84335fSJung-uk Kim * event Licensee exports any such software from the United States or 1040d84335fSJung-uk Kim * re-exports any such software from a foreign destination, Licensee shall 1050d84335fSJung-uk Kim * ensure that the distribution and export/re-export of the software is in 1060d84335fSJung-uk Kim * compliance with all laws, regulations, orders, or other restrictions of the 1070d84335fSJung-uk Kim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 1080d84335fSJung-uk Kim * any of its subsidiaries will export/re-export any technical data, process, 1090d84335fSJung-uk Kim * software, or service, directly or indirectly, to any country for which the 1100d84335fSJung-uk Kim * United States government or any agency thereof requires an export license, 1110d84335fSJung-uk Kim * other governmental approval, or letter of assurance, without first obtaining 1120d84335fSJung-uk Kim * such license, approval or letter. 1130d84335fSJung-uk Kim * 1140d84335fSJung-uk Kim ***************************************************************************** 1150d84335fSJung-uk Kim * 1160d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the 1170d84335fSJung-uk Kim * following license: 1180d84335fSJung-uk Kim * 119d244b227SJung-uk Kim * Redistribution and use in source and binary forms, with or without 120d244b227SJung-uk Kim * modification, are permitted provided that the following conditions 121d244b227SJung-uk Kim * are met: 122d244b227SJung-uk Kim * 1. Redistributions of source code must retain the above copyright 123d244b227SJung-uk Kim * notice, this list of conditions, and the following disclaimer, 124d244b227SJung-uk Kim * without modification. 125d244b227SJung-uk Kim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126d244b227SJung-uk Kim * substantially similar to the "NO WARRANTY" disclaimer below 127d244b227SJung-uk Kim * ("Disclaimer") and any redistribution must be conditioned upon 128d244b227SJung-uk Kim * including a substantially similar Disclaimer requirement for further 129d244b227SJung-uk Kim * binary redistribution. 130d244b227SJung-uk Kim * 3. Neither the names of the above-listed copyright holders nor the names 131d244b227SJung-uk Kim * of any contributors may be used to endorse or promote products derived 132d244b227SJung-uk Kim * from this software without specific prior written permission. 133a9f12690SJung-uk Kim * 1340d84335fSJung-uk Kim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1350d84335fSJung-uk Kim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1360d84335fSJung-uk Kim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1370d84335fSJung-uk Kim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1380d84335fSJung-uk Kim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1390d84335fSJung-uk Kim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1400d84335fSJung-uk Kim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1410d84335fSJung-uk Kim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1420d84335fSJung-uk Kim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1430d84335fSJung-uk Kim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1440d84335fSJung-uk Kim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1450d84335fSJung-uk Kim * 1460d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the 147d244b227SJung-uk Kim * GNU General Public License ("GPL") version 2 as published by the Free 148d244b227SJung-uk Kim * Software Foundation. 149a9f12690SJung-uk Kim * 1500d84335fSJung-uk Kim *****************************************************************************/ 151a9f12690SJung-uk Kim 152ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h> 153ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/actables.h> 1549c48c75eSJung-uk Kim #include <contrib/dev/acpica/include/acdisasm.h> 155ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acapps.h> 1560d84335fSJung-uk Kim #include <contrib/dev/acpica/include/acconvert.h> 157a9f12690SJung-uk Kim 158a9f12690SJung-uk Kim #define _COMPONENT ACPI_COMPILER 159a9f12690SJung-uk Kim ACPI_MODULE_NAME ("aslstartup") 160a9f12690SJung-uk Kim 161a9f12690SJung-uk Kim 162a9f12690SJung-uk Kim /* Local prototypes */ 163a9f12690SJung-uk Kim 16442fecd12SJung-uk Kim static UINT8 165a88e22b7SJung-uk Kim AslDetectSourceFileType ( 166a88e22b7SJung-uk Kim ASL_FILE_INFO *Info); 167a88e22b7SJung-uk Kim 168a9f12690SJung-uk Kim 169313a0c13SJung-uk Kim /* Globals */ 170313a0c13SJung-uk Kim 171313a0c13SJung-uk Kim static BOOLEAN AslToFile = TRUE; 172313a0c13SJung-uk Kim 173313a0c13SJung-uk Kim 174a9f12690SJung-uk Kim /******************************************************************************* 175a9f12690SJung-uk Kim * 176a9f12690SJung-uk Kim * FUNCTION: AslInitializeGlobals 177a9f12690SJung-uk Kim * 178a9f12690SJung-uk Kim * PARAMETERS: None 179a9f12690SJung-uk Kim * 180a9f12690SJung-uk Kim * RETURN: None 181a9f12690SJung-uk Kim * 182a9f12690SJung-uk Kim * DESCRIPTION: Re-initialize globals needed to restart the compiler. This 183a9f12690SJung-uk Kim * allows multiple files to be disassembled and/or compiled. 184a9f12690SJung-uk Kim * 185a9f12690SJung-uk Kim ******************************************************************************/ 186a9f12690SJung-uk Kim 187a88e22b7SJung-uk Kim void 188a9f12690SJung-uk Kim AslInitializeGlobals ( 189a9f12690SJung-uk Kim void) 190a9f12690SJung-uk Kim { 191a9f12690SJung-uk Kim UINT32 i; 192a9f12690SJung-uk Kim 193a9f12690SJung-uk Kim 194a9f12690SJung-uk Kim /* Init compiler globals */ 195a9f12690SJung-uk Kim 1966f1f1a63SJung-uk Kim AslGbl_SyntaxError = 0; 1976f1f1a63SJung-uk Kim AslGbl_CurrentColumn = 0; 1986f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber = 1; 1996f1f1a63SJung-uk Kim AslGbl_LogicalLineNumber = 1; 2006f1f1a63SJung-uk Kim AslGbl_CurrentLineOffset = 0; 2016f1f1a63SJung-uk Kim AslGbl_InputFieldCount = 0; 2026f1f1a63SJung-uk Kim AslGbl_InputByteCount = 0; 2036f1f1a63SJung-uk Kim AslGbl_NsLookupCount = 0; 2046f1f1a63SJung-uk Kim AslGbl_LineBufPtr = AslGbl_CurrentLineBuffer; 205a9f12690SJung-uk Kim 2066f1f1a63SJung-uk Kim AslGbl_ErrorLog = NULL; 2076f1f1a63SJung-uk Kim AslGbl_NextError = NULL; 2086f1f1a63SJung-uk Kim AslGbl_Signature = NULL; 2096f1f1a63SJung-uk Kim AslGbl_FileType = 0; 210a9f12690SJung-uk Kim 2116f1f1a63SJung-uk Kim AslGbl_TotalExecutableOpcodes = 0; 2126f1f1a63SJung-uk Kim AslGbl_TotalNamedObjects = 0; 2136f1f1a63SJung-uk Kim AslGbl_TotalKeywords = 0; 2146f1f1a63SJung-uk Kim AslGbl_TotalParseNodes = 0; 2156f1f1a63SJung-uk Kim AslGbl_TotalMethods = 0; 2166f1f1a63SJung-uk Kim AslGbl_TotalAllocations = 0; 2176f1f1a63SJung-uk Kim AslGbl_TotalAllocated = 0; 2186f1f1a63SJung-uk Kim AslGbl_TotalFolds = 0; 2194c52cad2SJung-uk Kim 220a9f12690SJung-uk Kim AslGbl_NextEvent = 0; 221a9f12690SJung-uk Kim for (i = 0; i < ASL_NUM_REPORT_LEVELS; i++) 222a9f12690SJung-uk Kim { 2236f1f1a63SJung-uk Kim AslGbl_ExceptionCount[i] = 0; 224a9f12690SJung-uk Kim } 225a9f12690SJung-uk Kim 226f1db5ef7SJung-uk Kim if (AcpiGbl_CaptureComments) 2270d84335fSJung-uk Kim { 2286f1f1a63SJung-uk Kim AslGbl_CommentState.SpacesBefore = 0; 2296f1f1a63SJung-uk Kim AslGbl_CommentState.CommentType = 1; 2306f1f1a63SJung-uk Kim AslGbl_CommentState.LatestParseOp = NULL; 2316f1f1a63SJung-uk Kim AslGbl_CommentState.ParsingParenBraceNode = NULL; 2326f1f1a63SJung-uk Kim AslGbl_CommentState.CaptureComments = TRUE; 2330d84335fSJung-uk Kim } 234a9f12690SJung-uk Kim } 235a9f12690SJung-uk Kim 236a9f12690SJung-uk Kim 237a9f12690SJung-uk Kim /******************************************************************************* 238a9f12690SJung-uk Kim * 239a88e22b7SJung-uk Kim * FUNCTION: AslDetectSourceFileType 240a88e22b7SJung-uk Kim * 241a88e22b7SJung-uk Kim * PARAMETERS: Info - Name/Handle for the file (must be open) 242a88e22b7SJung-uk Kim * 243a88e22b7SJung-uk Kim * RETURN: File Type 244a88e22b7SJung-uk Kim * 245a88e22b7SJung-uk Kim * DESCRIPTION: Determine the type of the input file. Either binary (contains 246a88e22b7SJung-uk Kim * non-ASCII characters), ASL file, or an ACPI Data Table file. 247a88e22b7SJung-uk Kim * 248a88e22b7SJung-uk Kim ******************************************************************************/ 249a88e22b7SJung-uk Kim 25042fecd12SJung-uk Kim static UINT8 251a88e22b7SJung-uk Kim AslDetectSourceFileType ( 252a88e22b7SJung-uk Kim ASL_FILE_INFO *Info) 253a88e22b7SJung-uk Kim { 254a88e22b7SJung-uk Kim char *FileChar; 255f8146b88SJung-uk Kim UINT8 Type = ASL_INPUT_TYPE_ASCII_DATA; /* default */ 256a88e22b7SJung-uk Kim ACPI_STATUS Status; 257a88e22b7SJung-uk Kim 258a88e22b7SJung-uk Kim 259a88e22b7SJung-uk Kim /* Check for 100% ASCII source file (comments are ignored) */ 260a88e22b7SJung-uk Kim 261f8146b88SJung-uk Kim Status = FlIsFileAsciiSource (Info->Filename, FALSE); 262f8146b88SJung-uk Kim if (ACPI_SUCCESS (Status)) 263a88e22b7SJung-uk Kim { 264a88e22b7SJung-uk Kim /* 265f8146b88SJung-uk Kim * File contains ASCII source code. Determine if this is an ASL 266f8146b88SJung-uk Kim * file or an ACPI data table file. 267a88e22b7SJung-uk Kim */ 2686f1f1a63SJung-uk Kim while (fgets (AslGbl_CurrentLineBuffer, AslGbl_LineBufferSize, Info->Handle)) 269a88e22b7SJung-uk Kim { 270a88e22b7SJung-uk Kim /* Uppercase the buffer for caseless compare */ 271a88e22b7SJung-uk Kim 2726f1f1a63SJung-uk Kim FileChar = AslGbl_CurrentLineBuffer; 273a88e22b7SJung-uk Kim while (*FileChar) 274a88e22b7SJung-uk Kim { 275a88e22b7SJung-uk Kim *FileChar = (char) toupper ((int) *FileChar); 276a88e22b7SJung-uk Kim FileChar++; 277a88e22b7SJung-uk Kim } 278a88e22b7SJung-uk Kim 279a88e22b7SJung-uk Kim /* Presence of "DefinitionBlock" indicates actual ASL code */ 280a88e22b7SJung-uk Kim 2816f1f1a63SJung-uk Kim if (strstr (AslGbl_CurrentLineBuffer, "DEFINITIONBLOCK")) 282a88e22b7SJung-uk Kim { 283a88e22b7SJung-uk Kim /* Appears to be an ASL file */ 284a88e22b7SJung-uk Kim 285a88e22b7SJung-uk Kim Type = ASL_INPUT_TYPE_ASCII_ASL; 286a88e22b7SJung-uk Kim goto Cleanup; 287a88e22b7SJung-uk Kim } 288a88e22b7SJung-uk Kim } 289a88e22b7SJung-uk Kim 290f8146b88SJung-uk Kim /* Appears to be an ASCII data table source file */ 291a88e22b7SJung-uk Kim 292a88e22b7SJung-uk Kim Type = ASL_INPUT_TYPE_ASCII_DATA; 293f8146b88SJung-uk Kim goto Cleanup; 294f8146b88SJung-uk Kim } 295f8146b88SJung-uk Kim 296f8146b88SJung-uk Kim /* We have some sort of binary table, check for valid ACPI table */ 297f8146b88SJung-uk Kim 298f8146b88SJung-uk Kim fseek (Info->Handle, 0, SEEK_SET); 299f8146b88SJung-uk Kim 300f8146b88SJung-uk Kim Status = AcValidateTableHeader (Info->Handle, 0); 301f8146b88SJung-uk Kim if (ACPI_SUCCESS (Status)) 302f8146b88SJung-uk Kim { 303f8146b88SJung-uk Kim fprintf (stderr, 304f8146b88SJung-uk Kim "Binary file appears to be a valid ACPI table, disassembling\n"); 305f8146b88SJung-uk Kim 306f8146b88SJung-uk Kim Type = ASL_INPUT_TYPE_BINARY_ACPI_TABLE; 307f8146b88SJung-uk Kim goto Cleanup; 308f8146b88SJung-uk Kim } 309af051161SJung-uk Kim else 310af051161SJung-uk Kim { 311af051161SJung-uk Kim fprintf (stderr, 312af051161SJung-uk Kim "Binary file does not contain a valid ACPI table\n"); 313af051161SJung-uk Kim } 314f8146b88SJung-uk Kim 315f8146b88SJung-uk Kim Type = ASL_INPUT_TYPE_BINARY; 316f8146b88SJung-uk Kim 317a88e22b7SJung-uk Kim 318a88e22b7SJung-uk Kim Cleanup: 319a88e22b7SJung-uk Kim 320a88e22b7SJung-uk Kim /* Must seek back to the start of the file */ 321a88e22b7SJung-uk Kim 322a88e22b7SJung-uk Kim fseek (Info->Handle, 0, SEEK_SET); 323a88e22b7SJung-uk Kim return (Type); 324a88e22b7SJung-uk Kim } 325a88e22b7SJung-uk Kim 326a88e22b7SJung-uk Kim 327a88e22b7SJung-uk Kim /******************************************************************************* 328a88e22b7SJung-uk Kim * 3299c48c75eSJung-uk Kim * FUNCTION: AslDoDisassembly 3309c48c75eSJung-uk Kim * 3319c48c75eSJung-uk Kim * PARAMETERS: None 3329c48c75eSJung-uk Kim * 3339c48c75eSJung-uk Kim * RETURN: Status 3349c48c75eSJung-uk Kim * 3359c48c75eSJung-uk Kim * DESCRIPTION: Initiate AML file disassembly. Uses ACPICA subsystem to build 33644b0f624SJung-uk Kim * namespace. This function assumes that the ACPI subsystem has 33744b0f624SJung-uk Kim * been initialized. The caller of the initialization will also 33844b0f624SJung-uk Kim * terminate the ACPI subsystem. 3399c48c75eSJung-uk Kim * 3409c48c75eSJung-uk Kim ******************************************************************************/ 3419c48c75eSJung-uk Kim 34244b0f624SJung-uk Kim ACPI_STATUS 3439c48c75eSJung-uk Kim AslDoDisassembly ( 3449c48c75eSJung-uk Kim void) 3459c48c75eSJung-uk Kim { 3469c48c75eSJung-uk Kim ACPI_STATUS Status; 3479c48c75eSJung-uk Kim 3489c48c75eSJung-uk Kim 3499c48c75eSJung-uk Kim Status = AcpiAllocateRootTable (4); 3509c48c75eSJung-uk Kim if (ACPI_FAILURE (Status)) 3519c48c75eSJung-uk Kim { 3529c48c75eSJung-uk Kim AcpiOsPrintf ("Could not initialize ACPI Table Manager, %s\n", 3539c48c75eSJung-uk Kim AcpiFormatException (Status)); 3549c48c75eSJung-uk Kim return (Status); 3559c48c75eSJung-uk Kim } 3569c48c75eSJung-uk Kim 3579c48c75eSJung-uk Kim /* This is where the disassembly happens */ 3589c48c75eSJung-uk Kim 35970e6ab8fSJung-uk Kim AcpiGbl_DmOpt_Disasm = TRUE; 3609c48c75eSJung-uk Kim Status = AdAmlDisassemble (AslToFile, 3616f1f1a63SJung-uk Kim AslGbl_Files[ASL_FILE_INPUT].Filename, AslGbl_OutputFilenamePrefix, 3626f1f1a63SJung-uk Kim &AslGbl_Files[ASL_FILE_INPUT].Filename); 3639c48c75eSJung-uk Kim if (ACPI_FAILURE (Status)) 3649c48c75eSJung-uk Kim { 3659c48c75eSJung-uk Kim return (Status); 3669c48c75eSJung-uk Kim } 3679c48c75eSJung-uk Kim 3689c48c75eSJung-uk Kim /* Check if any control methods were unresolved */ 3699c48c75eSJung-uk Kim 3709c48c75eSJung-uk Kim AcpiDmUnresolvedWarning (0); 3719c48c75eSJung-uk Kim 37244b0f624SJung-uk Kim /* Clear Error log */ 3739c48c75eSJung-uk Kim 3749c48c75eSJung-uk Kim AeClearErrorLog (); 3759c48c75eSJung-uk Kim 3769c48c75eSJung-uk Kim /* 3776f1f1a63SJung-uk Kim * AslGbl_Files[ASL_FILE_INPUT].Filename was replaced with the 3789c48c75eSJung-uk Kim * .DSL disassembly file, which can now be compiled if requested 3799c48c75eSJung-uk Kim */ 3806f1f1a63SJung-uk Kim if (AslGbl_DoCompile) 3819c48c75eSJung-uk Kim { 3829c48c75eSJung-uk Kim AcpiOsPrintf ("\nCompiling \"%s\"\n", 3836f1f1a63SJung-uk Kim AslGbl_Files[ASL_FILE_INPUT].Filename); 3849c48c75eSJung-uk Kim return (AE_CTRL_CONTINUE); 3859c48c75eSJung-uk Kim } 3869c48c75eSJung-uk Kim 3879c48c75eSJung-uk Kim return (AE_OK); 3889c48c75eSJung-uk Kim } 3899c48c75eSJung-uk Kim 3909c48c75eSJung-uk Kim 3919c48c75eSJung-uk Kim /******************************************************************************* 3929c48c75eSJung-uk Kim * 393a9f12690SJung-uk Kim * FUNCTION: AslDoOneFile 394a9f12690SJung-uk Kim * 395a9f12690SJung-uk Kim * PARAMETERS: Filename - Name of the file 396a9f12690SJung-uk Kim * 397a9f12690SJung-uk Kim * RETURN: Status 398a9f12690SJung-uk Kim * 399a9f12690SJung-uk Kim * DESCRIPTION: Process a single file - either disassemble, compile, or both 400a9f12690SJung-uk Kim * 401a9f12690SJung-uk Kim ******************************************************************************/ 402a9f12690SJung-uk Kim 403a9f12690SJung-uk Kim ACPI_STATUS 404a9f12690SJung-uk Kim AslDoOneFile ( 405a9f12690SJung-uk Kim char *Filename) 406a9f12690SJung-uk Kim { 407a9f12690SJung-uk Kim ACPI_STATUS Status; 40844b0f624SJung-uk Kim UINT8 Event; 40944b0f624SJung-uk Kim ASL_GLOBAL_FILE_NODE *FileNode; 410a9f12690SJung-uk Kim 411a9f12690SJung-uk Kim 4124c52cad2SJung-uk Kim /* Re-initialize "some" compiler/preprocessor globals */ 413a9f12690SJung-uk Kim 414a9f12690SJung-uk Kim AslInitializeGlobals (); 4154c52cad2SJung-uk Kim PrInitializeGlobals (); 4164c52cad2SJung-uk Kim 417313a0c13SJung-uk Kim /* 418313a0c13SJung-uk Kim * Extract the directory path. This path is used for possible include 419313a0c13SJung-uk Kim * files and the optional AML filename embedded in the input file 420313a0c13SJung-uk Kim * DefinitionBlock declaration. 421313a0c13SJung-uk Kim */ 4226f1f1a63SJung-uk Kim Status = FlSplitInputPathname (Filename, &AslGbl_DirectoryPath, NULL); 423313a0c13SJung-uk Kim if (ACPI_FAILURE (Status)) 424313a0c13SJung-uk Kim { 425313a0c13SJung-uk Kim return (Status); 426313a0c13SJung-uk Kim } 427313a0c13SJung-uk Kim 42844b0f624SJung-uk Kim /* 42944b0f624SJung-uk Kim * There was an input file detected at this point. Each input ASL file is 43044b0f624SJung-uk Kim * associated with one global file node consisting of the input file and 43144b0f624SJung-uk Kim * all output files associated with it. This is useful when compiling 43244b0f624SJung-uk Kim * multiple files in one command. 43344b0f624SJung-uk Kim */ 43444b0f624SJung-uk Kim Status = FlInitOneFile(Filename); 43544b0f624SJung-uk Kim if (ACPI_FAILURE (Status)) 43644b0f624SJung-uk Kim { 43744b0f624SJung-uk Kim return (AE_ERROR); 43844b0f624SJung-uk Kim } 43944b0f624SJung-uk Kim 440313a0c13SJung-uk Kim /* Take a copy of the input filename, convert any backslashes */ 441313a0c13SJung-uk Kim 4426f1f1a63SJung-uk Kim AslGbl_Files[ASL_FILE_INPUT].Filename = 44367d9aa44SJung-uk Kim UtLocalCacheCalloc (strlen (Filename) + 1); 444313a0c13SJung-uk Kim 4456f1f1a63SJung-uk Kim strcpy (AslGbl_Files[ASL_FILE_INPUT].Filename, Filename); 4466f1f1a63SJung-uk Kim UtConvertBackslashes (AslGbl_Files[ASL_FILE_INPUT].Filename); 447a9f12690SJung-uk Kim 448a9f12690SJung-uk Kim /* 449a88e22b7SJung-uk Kim * Open the input file. Here, this should be an ASCII source file, 450a88e22b7SJung-uk Kim * either an ASL file or a Data Table file 451a9f12690SJung-uk Kim */ 4526f1f1a63SJung-uk Kim Status = FlOpenInputFile (AslGbl_Files[ASL_FILE_INPUT].Filename); 453a88e22b7SJung-uk Kim if (ACPI_FAILURE (Status)) 454a9f12690SJung-uk Kim { 455a88e22b7SJung-uk Kim AePrintErrorLog (ASL_FILE_STDERR); 456a88e22b7SJung-uk Kim return (AE_ERROR); 457a88e22b7SJung-uk Kim } 458a88e22b7SJung-uk Kim 45944b0f624SJung-uk Kim FileNode = FlGetCurrentFileNode(); 46044b0f624SJung-uk Kim if (!FileNode) 46144b0f624SJung-uk Kim { 46244b0f624SJung-uk Kim return (AE_ERROR); 46344b0f624SJung-uk Kim } 46444b0f624SJung-uk Kim 46544b0f624SJung-uk Kim FileNode->OriginalInputFileSize = FlGetFileSize (ASL_FILE_INPUT); 4665ef50723SJung-uk Kim 467a88e22b7SJung-uk Kim /* Determine input file type */ 468a88e22b7SJung-uk Kim 4696f1f1a63SJung-uk Kim AslGbl_FileType = AslDetectSourceFileType (&AslGbl_Files[ASL_FILE_INPUT]); 4706f1f1a63SJung-uk Kim if (AslGbl_FileType == ASL_INPUT_TYPE_BINARY) 471a88e22b7SJung-uk Kim { 472a88e22b7SJung-uk Kim return (AE_ERROR); 473a88e22b7SJung-uk Kim } 474a88e22b7SJung-uk Kim 475a9f12690SJung-uk Kim /* 476a9f12690SJung-uk Kim * If -p not specified, we will use the input filename as the 477a9f12690SJung-uk Kim * output filename prefix 478a9f12690SJung-uk Kim */ 4796f1f1a63SJung-uk Kim if (AslGbl_UseDefaultAmlFilename) 480a9f12690SJung-uk Kim { 4816f1f1a63SJung-uk Kim AslGbl_OutputFilenamePrefix = AslGbl_Files[ASL_FILE_INPUT].Filename; 482a9f12690SJung-uk Kim } 483a9f12690SJung-uk Kim 48444b0f624SJung-uk Kim /* 48544b0f624SJung-uk Kim * Open the output file. Note: by default, the name of this file comes from 48644b0f624SJung-uk Kim * the table descriptor within the input file. 48744b0f624SJung-uk Kim */ 48844b0f624SJung-uk Kim if (AslGbl_FileType == ASL_INPUT_TYPE_ASCII_ASL) 48944b0f624SJung-uk Kim { 49044b0f624SJung-uk Kim Event = UtBeginEvent ("Open AML output file"); 49144b0f624SJung-uk Kim Status = FlOpenAmlOutputFile (AslGbl_OutputFilenamePrefix); 49244b0f624SJung-uk Kim UtEndEvent (Event); 49344b0f624SJung-uk Kim if (ACPI_FAILURE (Status)) 49444b0f624SJung-uk Kim { 49544b0f624SJung-uk Kim AePrintErrorLog (ASL_FILE_STDERR); 49644b0f624SJung-uk Kim return (AE_ERROR); 49744b0f624SJung-uk Kim } 49844b0f624SJung-uk Kim } 49944b0f624SJung-uk Kim 500a88e22b7SJung-uk Kim /* Open the optional output files (listings, etc.) */ 501a88e22b7SJung-uk Kim 5026f1f1a63SJung-uk Kim Status = FlOpenMiscOutputFiles (AslGbl_OutputFilenamePrefix); 503a88e22b7SJung-uk Kim if (ACPI_FAILURE (Status)) 504a88e22b7SJung-uk Kim { 505a88e22b7SJung-uk Kim AePrintErrorLog (ASL_FILE_STDERR); 506a88e22b7SJung-uk Kim return (AE_ERROR); 507a88e22b7SJung-uk Kim } 508a88e22b7SJung-uk Kim 509a88e22b7SJung-uk Kim /* 510a88e22b7SJung-uk Kim * Compilation of ASL source versus DataTable source uses different 511a88e22b7SJung-uk Kim * compiler subsystems 512a88e22b7SJung-uk Kim */ 5136f1f1a63SJung-uk Kim switch (AslGbl_FileType) 514a88e22b7SJung-uk Kim { 515a88e22b7SJung-uk Kim /* 516a88e22b7SJung-uk Kim * Data Table Compilation 517a88e22b7SJung-uk Kim */ 518a88e22b7SJung-uk Kim case ASL_INPUT_TYPE_ASCII_DATA: 519a88e22b7SJung-uk Kim 520a88e22b7SJung-uk Kim Status = DtDoCompile (); 521eef1b955SJung-uk Kim if (ACPI_FAILURE (Status)) 522eef1b955SJung-uk Kim { 523eef1b955SJung-uk Kim return (Status); 524eef1b955SJung-uk Kim } 525a88e22b7SJung-uk Kim 5266f1f1a63SJung-uk Kim if (AslGbl_Signature) 527a88e22b7SJung-uk Kim { 5286f1f1a63SJung-uk Kim AslGbl_Signature = NULL; 529a88e22b7SJung-uk Kim } 530eef1b955SJung-uk Kim 531eef1b955SJung-uk Kim /* Check if any errors occurred during compile */ 532eef1b955SJung-uk Kim 533eef1b955SJung-uk Kim Status = AslCheckForErrorExit (); 534eef1b955SJung-uk Kim if (ACPI_FAILURE (Status)) 535eef1b955SJung-uk Kim { 536eef1b955SJung-uk Kim return (Status); 537eef1b955SJung-uk Kim } 538eef1b955SJung-uk Kim 539eef1b955SJung-uk Kim /* Cleanup (for next source file) and exit */ 540eef1b955SJung-uk Kim 541a88e22b7SJung-uk Kim AeClearErrorLog (); 5424c52cad2SJung-uk Kim PrTerminatePreprocessor (); 543a88e22b7SJung-uk Kim return (Status); 544a88e22b7SJung-uk Kim 545a88e22b7SJung-uk Kim /* 546eef1b955SJung-uk Kim * ASL Compilation 547a88e22b7SJung-uk Kim */ 548a88e22b7SJung-uk Kim case ASL_INPUT_TYPE_ASCII_ASL: 549a88e22b7SJung-uk Kim 55044b0f624SJung-uk Kim Status = CmDoCompile (); 551eef1b955SJung-uk Kim if (ACPI_FAILURE (Status)) 552a9f12690SJung-uk Kim { 553*9ad8b64eSJung-uk Kim PrTerminatePreprocessor (); 554eef1b955SJung-uk Kim return (Status); 555a9f12690SJung-uk Kim } 556a9f12690SJung-uk Kim 5570d84335fSJung-uk Kim /* 55844b0f624SJung-uk Kim * At this point, we know how many lines are in the input file. Save it 55944b0f624SJung-uk Kim * to display for post-compilation summary. 5600d84335fSJung-uk Kim */ 56144b0f624SJung-uk Kim FileNode->TotalLineCount = AslGbl_CurrentLineNumber; 562a9f12690SJung-uk Kim return (AE_OK); 563a88e22b7SJung-uk Kim 5649c48c75eSJung-uk Kim /* 5659c48c75eSJung-uk Kim * Binary ACPI table was auto-detected, disassemble it 5669c48c75eSJung-uk Kim */ 567f8146b88SJung-uk Kim case ASL_INPUT_TYPE_BINARY_ACPI_TABLE: 5689c48c75eSJung-uk Kim 5699c48c75eSJung-uk Kim /* We have what appears to be an ACPI table, disassemble it */ 5709c48c75eSJung-uk Kim 5719c48c75eSJung-uk Kim FlCloseFile (ASL_FILE_INPUT); 5726f1f1a63SJung-uk Kim AslGbl_DoCompile = FALSE; 573af051161SJung-uk Kim AcpiGbl_DisasmFlag = TRUE; 5749c48c75eSJung-uk Kim Status = AslDoDisassembly (); 5759c48c75eSJung-uk Kim return (Status); 5769c48c75eSJung-uk Kim 5779c48c75eSJung-uk Kim /* Unknown binary table */ 5789c48c75eSJung-uk Kim 579a88e22b7SJung-uk Kim case ASL_INPUT_TYPE_BINARY: 580a88e22b7SJung-uk Kim 581a88e22b7SJung-uk Kim AePrintErrorLog (ASL_FILE_STDERR); 582a88e22b7SJung-uk Kim return (AE_ERROR); 583a88e22b7SJung-uk Kim 584a88e22b7SJung-uk Kim default: 585a9d8d09cSJung-uk Kim 5866f1f1a63SJung-uk Kim printf ("Unknown file type %X\n", AslGbl_FileType); 587a88e22b7SJung-uk Kim return (AE_ERROR); 588a88e22b7SJung-uk Kim } 589a9f12690SJung-uk Kim } 590a9f12690SJung-uk Kim 591a9f12690SJung-uk Kim 592a9f12690SJung-uk Kim /******************************************************************************* 593a9f12690SJung-uk Kim * 594eef1b955SJung-uk Kim * FUNCTION: AslCheckForErrorExit 595eef1b955SJung-uk Kim * 596eef1b955SJung-uk Kim * PARAMETERS: None. Examines global exception count array 597eef1b955SJung-uk Kim * 598eef1b955SJung-uk Kim * RETURN: Status 599eef1b955SJung-uk Kim * 600eef1b955SJung-uk Kim * DESCRIPTION: Determine if compiler should abort with error status 601eef1b955SJung-uk Kim * 602eef1b955SJung-uk Kim ******************************************************************************/ 603eef1b955SJung-uk Kim 604eef1b955SJung-uk Kim ACPI_STATUS 605eef1b955SJung-uk Kim AslCheckForErrorExit ( 606eef1b955SJung-uk Kim void) 607eef1b955SJung-uk Kim { 608eef1b955SJung-uk Kim 609eef1b955SJung-uk Kim /* 610eef1b955SJung-uk Kim * Return non-zero exit code if there have been errors, unless the 611eef1b955SJung-uk Kim * global ignore error flag has been set 612eef1b955SJung-uk Kim */ 6136f1f1a63SJung-uk Kim if (!AslGbl_IgnoreErrors) 614eef1b955SJung-uk Kim { 6156f1f1a63SJung-uk Kim if (AslGbl_ExceptionCount[ASL_ERROR] > 0) 616eef1b955SJung-uk Kim { 617eef1b955SJung-uk Kim return (AE_ERROR); 618eef1b955SJung-uk Kim } 619eef1b955SJung-uk Kim 620eef1b955SJung-uk Kim /* Optionally treat warnings as errors */ 621eef1b955SJung-uk Kim 6226f1f1a63SJung-uk Kim if (AslGbl_WarningsAsErrors) 623eef1b955SJung-uk Kim { 6246f1f1a63SJung-uk Kim if ((AslGbl_ExceptionCount[ASL_WARNING] > 0) || 6256f1f1a63SJung-uk Kim (AslGbl_ExceptionCount[ASL_WARNING2] > 0) || 6266f1f1a63SJung-uk Kim (AslGbl_ExceptionCount[ASL_WARNING3] > 0)) 627eef1b955SJung-uk Kim { 62844b0f624SJung-uk Kim AslError (ASL_ERROR, ASL_MSG_WARNING_AS_ERROR, NULL, 62944b0f624SJung-uk Kim "(reporting warnings as errors)"); 630eef1b955SJung-uk Kim return (AE_ERROR); 631eef1b955SJung-uk Kim } 632eef1b955SJung-uk Kim } 633eef1b955SJung-uk Kim } 634eef1b955SJung-uk Kim 635eef1b955SJung-uk Kim return (AE_OK); 636eef1b955SJung-uk Kim } 637