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 *
11*58308fadSJung-uk Kim * Some or all of this work - Copyright (c) 1999 - 2025, 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
AslInitializeGlobals(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
AslDetectSourceFileType(ASL_FILE_INFO * Info)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
296ab71bbb7SJung-uk Kim /*
297ab71bbb7SJung-uk Kim * We have some sort of binary table; reopen in binary mode, then
298ab71bbb7SJung-uk Kim * check for valid ACPI table
299ab71bbb7SJung-uk Kim */
300ab71bbb7SJung-uk Kim fclose (Info->Handle);
301ab71bbb7SJung-uk Kim Info->Handle = fopen (Info->Filename, "rb");
302ab71bbb7SJung-uk Kim if (!Info->Handle)
303ab71bbb7SJung-uk Kim {
304ab71bbb7SJung-uk Kim fprintf (stderr, "Could not open input file %s\n",
305ab71bbb7SJung-uk Kim Info->Filename);
306ab71bbb7SJung-uk Kim }
307f8146b88SJung-uk Kim
308f8146b88SJung-uk Kim Status = AcValidateTableHeader (Info->Handle, 0);
309f8146b88SJung-uk Kim if (ACPI_SUCCESS (Status))
310f8146b88SJung-uk Kim {
311f8146b88SJung-uk Kim fprintf (stderr,
312f8146b88SJung-uk Kim "Binary file appears to be a valid ACPI table, disassembling\n");
313f8146b88SJung-uk Kim
314f8146b88SJung-uk Kim Type = ASL_INPUT_TYPE_BINARY_ACPI_TABLE;
315f8146b88SJung-uk Kim goto Cleanup;
316f8146b88SJung-uk Kim }
317af051161SJung-uk Kim else
318af051161SJung-uk Kim {
319af051161SJung-uk Kim fprintf (stderr,
3209a4bc520SJung-uk Kim "Binary file does not contain a valid standard ACPI table\n");
321af051161SJung-uk Kim }
322f8146b88SJung-uk Kim
323f8146b88SJung-uk Kim Type = ASL_INPUT_TYPE_BINARY;
324f8146b88SJung-uk Kim
325a88e22b7SJung-uk Kim
326a88e22b7SJung-uk Kim Cleanup:
327a88e22b7SJung-uk Kim
328a88e22b7SJung-uk Kim /* Must seek back to the start of the file */
329a88e22b7SJung-uk Kim
330a88e22b7SJung-uk Kim fseek (Info->Handle, 0, SEEK_SET);
331a88e22b7SJung-uk Kim return (Type);
332a88e22b7SJung-uk Kim }
333a88e22b7SJung-uk Kim
334a88e22b7SJung-uk Kim
335a88e22b7SJung-uk Kim /*******************************************************************************
336a88e22b7SJung-uk Kim *
3379c48c75eSJung-uk Kim * FUNCTION: AslDoDisassembly
3389c48c75eSJung-uk Kim *
3399c48c75eSJung-uk Kim * PARAMETERS: None
3409c48c75eSJung-uk Kim *
3419c48c75eSJung-uk Kim * RETURN: Status
3429c48c75eSJung-uk Kim *
3439c48c75eSJung-uk Kim * DESCRIPTION: Initiate AML file disassembly. Uses ACPICA subsystem to build
34444b0f624SJung-uk Kim * namespace. This function assumes that the ACPI subsystem has
34544b0f624SJung-uk Kim * been initialized. The caller of the initialization will also
34644b0f624SJung-uk Kim * terminate the ACPI subsystem.
3479c48c75eSJung-uk Kim *
3489c48c75eSJung-uk Kim ******************************************************************************/
3499c48c75eSJung-uk Kim
35044b0f624SJung-uk Kim ACPI_STATUS
AslDoDisassembly(void)3519c48c75eSJung-uk Kim AslDoDisassembly (
3529c48c75eSJung-uk Kim void)
3539c48c75eSJung-uk Kim {
3549c48c75eSJung-uk Kim ACPI_STATUS Status;
3559c48c75eSJung-uk Kim
3569c48c75eSJung-uk Kim
3579c48c75eSJung-uk Kim Status = AcpiAllocateRootTable (4);
3589c48c75eSJung-uk Kim if (ACPI_FAILURE (Status))
3599c48c75eSJung-uk Kim {
3609c48c75eSJung-uk Kim AcpiOsPrintf ("Could not initialize ACPI Table Manager, %s\n",
3619c48c75eSJung-uk Kim AcpiFormatException (Status));
3629c48c75eSJung-uk Kim return (Status);
3639c48c75eSJung-uk Kim }
3649c48c75eSJung-uk Kim
3659c48c75eSJung-uk Kim /* This is where the disassembly happens */
3669c48c75eSJung-uk Kim
36770e6ab8fSJung-uk Kim AcpiGbl_DmOpt_Disasm = TRUE;
3689c48c75eSJung-uk Kim Status = AdAmlDisassemble (AslToFile,
3696f1f1a63SJung-uk Kim AslGbl_Files[ASL_FILE_INPUT].Filename, AslGbl_OutputFilenamePrefix,
3706f1f1a63SJung-uk Kim &AslGbl_Files[ASL_FILE_INPUT].Filename);
3719c48c75eSJung-uk Kim if (ACPI_FAILURE (Status))
3729c48c75eSJung-uk Kim {
3739c48c75eSJung-uk Kim return (Status);
3749c48c75eSJung-uk Kim }
3759c48c75eSJung-uk Kim
3769c48c75eSJung-uk Kim /* Check if any control methods were unresolved */
3779c48c75eSJung-uk Kim
3789c48c75eSJung-uk Kim AcpiDmUnresolvedWarning (0);
3799c48c75eSJung-uk Kim
38044b0f624SJung-uk Kim /* Clear Error log */
3819c48c75eSJung-uk Kim
3829c48c75eSJung-uk Kim AeClearErrorLog ();
3839c48c75eSJung-uk Kim
3849c48c75eSJung-uk Kim /*
3856f1f1a63SJung-uk Kim * AslGbl_Files[ASL_FILE_INPUT].Filename was replaced with the
3869c48c75eSJung-uk Kim * .DSL disassembly file, which can now be compiled if requested
3879c48c75eSJung-uk Kim */
3886f1f1a63SJung-uk Kim if (AslGbl_DoCompile)
3899c48c75eSJung-uk Kim {
3909c48c75eSJung-uk Kim AcpiOsPrintf ("\nCompiling \"%s\"\n",
3916f1f1a63SJung-uk Kim AslGbl_Files[ASL_FILE_INPUT].Filename);
3929c48c75eSJung-uk Kim return (AE_CTRL_CONTINUE);
3939c48c75eSJung-uk Kim }
3949c48c75eSJung-uk Kim
3959c48c75eSJung-uk Kim return (AE_OK);
3969c48c75eSJung-uk Kim }
3979c48c75eSJung-uk Kim
3989c48c75eSJung-uk Kim
3999c48c75eSJung-uk Kim /*******************************************************************************
4009c48c75eSJung-uk Kim *
401a9f12690SJung-uk Kim * FUNCTION: AslDoOneFile
402a9f12690SJung-uk Kim *
403a9f12690SJung-uk Kim * PARAMETERS: Filename - Name of the file
404a9f12690SJung-uk Kim *
405a9f12690SJung-uk Kim * RETURN: Status
406a9f12690SJung-uk Kim *
407a9f12690SJung-uk Kim * DESCRIPTION: Process a single file - either disassemble, compile, or both
408a9f12690SJung-uk Kim *
409a9f12690SJung-uk Kim ******************************************************************************/
410a9f12690SJung-uk Kim
411a9f12690SJung-uk Kim ACPI_STATUS
AslDoOneFile(char * Filename)412a9f12690SJung-uk Kim AslDoOneFile (
413a9f12690SJung-uk Kim char *Filename)
414a9f12690SJung-uk Kim {
415a9f12690SJung-uk Kim ACPI_STATUS Status;
41644b0f624SJung-uk Kim UINT8 Event;
41744b0f624SJung-uk Kim ASL_GLOBAL_FILE_NODE *FileNode;
418a9f12690SJung-uk Kim
419a9f12690SJung-uk Kim
4204c52cad2SJung-uk Kim /* Re-initialize "some" compiler/preprocessor globals */
421a9f12690SJung-uk Kim
422a9f12690SJung-uk Kim AslInitializeGlobals ();
4234c52cad2SJung-uk Kim PrInitializeGlobals ();
4244c52cad2SJung-uk Kim
425313a0c13SJung-uk Kim /*
426313a0c13SJung-uk Kim * Extract the directory path. This path is used for possible include
427313a0c13SJung-uk Kim * files and the optional AML filename embedded in the input file
428313a0c13SJung-uk Kim * DefinitionBlock declaration.
429313a0c13SJung-uk Kim */
4306f1f1a63SJung-uk Kim Status = FlSplitInputPathname (Filename, &AslGbl_DirectoryPath, NULL);
431313a0c13SJung-uk Kim if (ACPI_FAILURE (Status))
432313a0c13SJung-uk Kim {
433313a0c13SJung-uk Kim return (Status);
434313a0c13SJung-uk Kim }
435313a0c13SJung-uk Kim
43644b0f624SJung-uk Kim /*
43744b0f624SJung-uk Kim * There was an input file detected at this point. Each input ASL file is
43844b0f624SJung-uk Kim * associated with one global file node consisting of the input file and
43944b0f624SJung-uk Kim * all output files associated with it. This is useful when compiling
44044b0f624SJung-uk Kim * multiple files in one command.
44144b0f624SJung-uk Kim */
44244b0f624SJung-uk Kim Status = FlInitOneFile(Filename);
44344b0f624SJung-uk Kim if (ACPI_FAILURE (Status))
44444b0f624SJung-uk Kim {
44544b0f624SJung-uk Kim return (AE_ERROR);
44644b0f624SJung-uk Kim }
44744b0f624SJung-uk Kim
448313a0c13SJung-uk Kim /* Take a copy of the input filename, convert any backslashes */
449313a0c13SJung-uk Kim
4506f1f1a63SJung-uk Kim AslGbl_Files[ASL_FILE_INPUT].Filename =
45167d9aa44SJung-uk Kim UtLocalCacheCalloc (strlen (Filename) + 1);
452313a0c13SJung-uk Kim
4536f1f1a63SJung-uk Kim strcpy (AslGbl_Files[ASL_FILE_INPUT].Filename, Filename);
4546f1f1a63SJung-uk Kim UtConvertBackslashes (AslGbl_Files[ASL_FILE_INPUT].Filename);
455a9f12690SJung-uk Kim
456a9f12690SJung-uk Kim /*
457ab71bbb7SJung-uk Kim * Open the input file. Here, this could be an ASCII source file,
458ab71bbb7SJung-uk Kim * either an ASL file or a Data Table file, or a binary AML file
459ab71bbb7SJung-uk Kim * or binary data table file (For disassembly).
460a9f12690SJung-uk Kim */
4616f1f1a63SJung-uk Kim Status = FlOpenInputFile (AslGbl_Files[ASL_FILE_INPUT].Filename);
462a88e22b7SJung-uk Kim if (ACPI_FAILURE (Status))
463a9f12690SJung-uk Kim {
464a88e22b7SJung-uk Kim AePrintErrorLog (ASL_FILE_STDERR);
465a88e22b7SJung-uk Kim return (AE_ERROR);
466a88e22b7SJung-uk Kim }
467a88e22b7SJung-uk Kim
46844b0f624SJung-uk Kim FileNode = FlGetCurrentFileNode();
46944b0f624SJung-uk Kim
470a88e22b7SJung-uk Kim /* Determine input file type */
471a88e22b7SJung-uk Kim
4726f1f1a63SJung-uk Kim AslGbl_FileType = AslDetectSourceFileType (&AslGbl_Files[ASL_FILE_INPUT]);
473a009b7dcSJung-uk Kim FileNode->FileType = AslGbl_FileType;
4746f1f1a63SJung-uk Kim if (AslGbl_FileType == ASL_INPUT_TYPE_BINARY)
475a88e22b7SJung-uk Kim {
476a88e22b7SJung-uk Kim return (AE_ERROR);
477a88e22b7SJung-uk Kim }
478a88e22b7SJung-uk Kim
479ab71bbb7SJung-uk Kim FileNode->OriginalInputFileSize = FlGetFileSize (ASL_FILE_INPUT);
480ab71bbb7SJung-uk Kim
481a9f12690SJung-uk Kim /*
482a9f12690SJung-uk Kim * If -p not specified, we will use the input filename as the
483a9f12690SJung-uk Kim * output filename prefix
484a9f12690SJung-uk Kim */
4856f1f1a63SJung-uk Kim if (AslGbl_UseDefaultAmlFilename)
486a9f12690SJung-uk Kim {
4876f1f1a63SJung-uk Kim AslGbl_OutputFilenamePrefix = AslGbl_Files[ASL_FILE_INPUT].Filename;
488a9f12690SJung-uk Kim }
489a9f12690SJung-uk Kim
49044b0f624SJung-uk Kim /*
49144b0f624SJung-uk Kim * Open the output file. Note: by default, the name of this file comes from
49244b0f624SJung-uk Kim * the table descriptor within the input file.
49344b0f624SJung-uk Kim */
49444b0f624SJung-uk Kim if (AslGbl_FileType == ASL_INPUT_TYPE_ASCII_ASL)
49544b0f624SJung-uk Kim {
49644b0f624SJung-uk Kim Event = UtBeginEvent ("Open AML output file");
49744b0f624SJung-uk Kim Status = FlOpenAmlOutputFile (AslGbl_OutputFilenamePrefix);
49844b0f624SJung-uk Kim UtEndEvent (Event);
49944b0f624SJung-uk Kim if (ACPI_FAILURE (Status))
50044b0f624SJung-uk Kim {
50144b0f624SJung-uk Kim AePrintErrorLog (ASL_FILE_STDERR);
50244b0f624SJung-uk Kim return (AE_ERROR);
50344b0f624SJung-uk Kim }
50444b0f624SJung-uk Kim }
50544b0f624SJung-uk Kim
506a88e22b7SJung-uk Kim /* Open the optional output files (listings, etc.) */
507a88e22b7SJung-uk Kim
5086f1f1a63SJung-uk Kim Status = FlOpenMiscOutputFiles (AslGbl_OutputFilenamePrefix);
509a88e22b7SJung-uk Kim if (ACPI_FAILURE (Status))
510a88e22b7SJung-uk Kim {
511a88e22b7SJung-uk Kim AePrintErrorLog (ASL_FILE_STDERR);
512a88e22b7SJung-uk Kim return (AE_ERROR);
513a88e22b7SJung-uk Kim }
514a88e22b7SJung-uk Kim
515a88e22b7SJung-uk Kim /*
516a88e22b7SJung-uk Kim * Compilation of ASL source versus DataTable source uses different
517a88e22b7SJung-uk Kim * compiler subsystems
518a88e22b7SJung-uk Kim */
5196f1f1a63SJung-uk Kim switch (AslGbl_FileType)
520a88e22b7SJung-uk Kim {
521a88e22b7SJung-uk Kim /*
522a88e22b7SJung-uk Kim * Data Table Compilation
523a88e22b7SJung-uk Kim */
524a88e22b7SJung-uk Kim case ASL_INPUT_TYPE_ASCII_DATA:
525a88e22b7SJung-uk Kim
526a88e22b7SJung-uk Kim Status = DtDoCompile ();
527eef1b955SJung-uk Kim if (ACPI_FAILURE (Status))
528eef1b955SJung-uk Kim {
529eef1b955SJung-uk Kim return (Status);
530eef1b955SJung-uk Kim }
531a88e22b7SJung-uk Kim
5326f1f1a63SJung-uk Kim if (AslGbl_Signature)
533a88e22b7SJung-uk Kim {
5346f1f1a63SJung-uk Kim AslGbl_Signature = NULL;
535a88e22b7SJung-uk Kim }
536eef1b955SJung-uk Kim
537eef1b955SJung-uk Kim /* Check if any errors occurred during compile */
538eef1b955SJung-uk Kim
539eef1b955SJung-uk Kim Status = AslCheckForErrorExit ();
540eef1b955SJung-uk Kim if (ACPI_FAILURE (Status))
541eef1b955SJung-uk Kim {
542eef1b955SJung-uk Kim return (Status);
543eef1b955SJung-uk Kim }
544eef1b955SJung-uk Kim
545eef1b955SJung-uk Kim /* Cleanup (for next source file) and exit */
546eef1b955SJung-uk Kim
547a88e22b7SJung-uk Kim AeClearErrorLog ();
5484c52cad2SJung-uk Kim PrTerminatePreprocessor ();
549a88e22b7SJung-uk Kim return (Status);
550a88e22b7SJung-uk Kim
551a88e22b7SJung-uk Kim /*
552eef1b955SJung-uk Kim * ASL Compilation
553a88e22b7SJung-uk Kim */
554a88e22b7SJung-uk Kim case ASL_INPUT_TYPE_ASCII_ASL:
555a88e22b7SJung-uk Kim
55644b0f624SJung-uk Kim Status = CmDoCompile ();
557eef1b955SJung-uk Kim if (ACPI_FAILURE (Status))
558a9f12690SJung-uk Kim {
5599ad8b64eSJung-uk Kim PrTerminatePreprocessor ();
560eef1b955SJung-uk Kim return (Status);
561a9f12690SJung-uk Kim }
562a9f12690SJung-uk Kim
5630d84335fSJung-uk Kim /*
56444b0f624SJung-uk Kim * At this point, we know how many lines are in the input file. Save it
56544b0f624SJung-uk Kim * to display for post-compilation summary.
5660d84335fSJung-uk Kim */
56744b0f624SJung-uk Kim FileNode->TotalLineCount = AslGbl_CurrentLineNumber;
568a9f12690SJung-uk Kim return (AE_OK);
569a88e22b7SJung-uk Kim
5709c48c75eSJung-uk Kim /*
5719c48c75eSJung-uk Kim * Binary ACPI table was auto-detected, disassemble it
5729c48c75eSJung-uk Kim */
573f8146b88SJung-uk Kim case ASL_INPUT_TYPE_BINARY_ACPI_TABLE:
5749c48c75eSJung-uk Kim
5759c48c75eSJung-uk Kim /* We have what appears to be an ACPI table, disassemble it */
5769c48c75eSJung-uk Kim
5779c48c75eSJung-uk Kim FlCloseFile (ASL_FILE_INPUT);
5786f1f1a63SJung-uk Kim AslGbl_DoCompile = FALSE;
579af051161SJung-uk Kim AcpiGbl_DisasmFlag = TRUE;
5809c48c75eSJung-uk Kim Status = AslDoDisassembly ();
5819c48c75eSJung-uk Kim return (Status);
5829c48c75eSJung-uk Kim
5839c48c75eSJung-uk Kim /* Unknown binary table */
5849c48c75eSJung-uk Kim
585a88e22b7SJung-uk Kim case ASL_INPUT_TYPE_BINARY:
586a88e22b7SJung-uk Kim
587a88e22b7SJung-uk Kim AePrintErrorLog (ASL_FILE_STDERR);
588a88e22b7SJung-uk Kim return (AE_ERROR);
589a88e22b7SJung-uk Kim
590a88e22b7SJung-uk Kim default:
591a9d8d09cSJung-uk Kim
5926f1f1a63SJung-uk Kim printf ("Unknown file type %X\n", AslGbl_FileType);
593a88e22b7SJung-uk Kim return (AE_ERROR);
594a88e22b7SJung-uk Kim }
595a9f12690SJung-uk Kim }
596a9f12690SJung-uk Kim
597a9f12690SJung-uk Kim
598a9f12690SJung-uk Kim /*******************************************************************************
599a9f12690SJung-uk Kim *
600eef1b955SJung-uk Kim * FUNCTION: AslCheckForErrorExit
601eef1b955SJung-uk Kim *
602eef1b955SJung-uk Kim * PARAMETERS: None. Examines global exception count array
603eef1b955SJung-uk Kim *
604eef1b955SJung-uk Kim * RETURN: Status
605eef1b955SJung-uk Kim *
606eef1b955SJung-uk Kim * DESCRIPTION: Determine if compiler should abort with error status
607eef1b955SJung-uk Kim *
608eef1b955SJung-uk Kim ******************************************************************************/
609eef1b955SJung-uk Kim
610eef1b955SJung-uk Kim ACPI_STATUS
AslCheckForErrorExit(void)611eef1b955SJung-uk Kim AslCheckForErrorExit (
612eef1b955SJung-uk Kim void)
613eef1b955SJung-uk Kim {
614eef1b955SJung-uk Kim
615eef1b955SJung-uk Kim /*
616eef1b955SJung-uk Kim * Return non-zero exit code if there have been errors, unless the
617eef1b955SJung-uk Kim * global ignore error flag has been set
618eef1b955SJung-uk Kim */
6196f1f1a63SJung-uk Kim if (!AslGbl_IgnoreErrors)
620eef1b955SJung-uk Kim {
6216f1f1a63SJung-uk Kim if (AslGbl_ExceptionCount[ASL_ERROR] > 0)
622eef1b955SJung-uk Kim {
623eef1b955SJung-uk Kim return (AE_ERROR);
624eef1b955SJung-uk Kim }
625eef1b955SJung-uk Kim
626eef1b955SJung-uk Kim /* Optionally treat warnings as errors */
627eef1b955SJung-uk Kim
6286f1f1a63SJung-uk Kim if (AslGbl_WarningsAsErrors)
629eef1b955SJung-uk Kim {
6306f1f1a63SJung-uk Kim if ((AslGbl_ExceptionCount[ASL_WARNING] > 0) ||
6316f1f1a63SJung-uk Kim (AslGbl_ExceptionCount[ASL_WARNING2] > 0) ||
6326f1f1a63SJung-uk Kim (AslGbl_ExceptionCount[ASL_WARNING3] > 0))
633eef1b955SJung-uk Kim {
63444b0f624SJung-uk Kim AslError (ASL_ERROR, ASL_MSG_WARNING_AS_ERROR, NULL,
63544b0f624SJung-uk Kim "(reporting warnings as errors)");
636eef1b955SJung-uk Kim return (AE_ERROR);
637eef1b955SJung-uk Kim }
638eef1b955SJung-uk Kim }
639eef1b955SJung-uk Kim }
640eef1b955SJung-uk Kim
641eef1b955SJung-uk Kim return (AE_OK);
642eef1b955SJung-uk Kim }
643