xref: /netbsd-src/sys/external/bsd/acpica/dist/compiler/aslstartup.c (revision 046a29855e04359424fd074e8313af6b6be8cfb6)
128c506b8Sjruoho /******************************************************************************
228c506b8Sjruoho  *
328c506b8Sjruoho  * Module Name: aslstartup - Compiler startup routines, called from main
428c506b8Sjruoho  *
528c506b8Sjruoho  *****************************************************************************/
628c506b8Sjruoho 
7124f4c82Sjruoho /*
8*046a2985Schristos  * Copyright (C) 2000 - 2023, Intel Corp.
928c506b8Sjruoho  * All rights reserved.
1028c506b8Sjruoho  *
11124f4c82Sjruoho  * Redistribution and use in source and binary forms, with or without
12124f4c82Sjruoho  * modification, are permitted provided that the following conditions
13124f4c82Sjruoho  * are met:
14124f4c82Sjruoho  * 1. Redistributions of source code must retain the above copyright
15124f4c82Sjruoho  *    notice, this list of conditions, and the following disclaimer,
16124f4c82Sjruoho  *    without modification.
17124f4c82Sjruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18124f4c82Sjruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
19124f4c82Sjruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
20124f4c82Sjruoho  *    including a substantially similar Disclaimer requirement for further
21124f4c82Sjruoho  *    binary redistribution.
22124f4c82Sjruoho  * 3. Neither the names of the above-listed copyright holders nor the names
23124f4c82Sjruoho  *    of any contributors may be used to endorse or promote products derived
24124f4c82Sjruoho  *    from this software without specific prior written permission.
2528c506b8Sjruoho  *
26124f4c82Sjruoho  * Alternatively, this software may be distributed under the terms of the
27124f4c82Sjruoho  * GNU General Public License ("GPL") version 2 as published by the Free
28124f4c82Sjruoho  * Software Foundation.
2928c506b8Sjruoho  *
30124f4c82Sjruoho  * NO WARRANTY
31124f4c82Sjruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32124f4c82Sjruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3346a330b4Schristos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34124f4c82Sjruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35124f4c82Sjruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36124f4c82Sjruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37124f4c82Sjruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38124f4c82Sjruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39124f4c82Sjruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40124f4c82Sjruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41124f4c82Sjruoho  * POSSIBILITY OF SUCH DAMAGES.
42124f4c82Sjruoho  */
4328c506b8Sjruoho 
4428c506b8Sjruoho #include "aslcompiler.h"
4528c506b8Sjruoho #include "actables.h"
46ff4a156dSchristos #include "acdisasm.h"
4728c506b8Sjruoho #include "acapps.h"
48835858a6Schristos #include "acconvert.h"
4928c506b8Sjruoho 
5028c506b8Sjruoho #define _COMPONENT          ACPI_COMPILER
5128c506b8Sjruoho         ACPI_MODULE_NAME    ("aslstartup")
5228c506b8Sjruoho 
5328c506b8Sjruoho 
5428c506b8Sjruoho /* Local prototypes */
5528c506b8Sjruoho 
56124f4c82Sjruoho static UINT8
5728c506b8Sjruoho AslDetectSourceFileType (
5828c506b8Sjruoho     ASL_FILE_INFO           *Info);
5928c506b8Sjruoho 
60ff4a156dSchristos 
61ff4a156dSchristos /* Globals */
62ff4a156dSchristos 
63ff4a156dSchristos static BOOLEAN          AslToFile = TRUE;
64ff4a156dSchristos 
6528c506b8Sjruoho 
6628c506b8Sjruoho /*******************************************************************************
6728c506b8Sjruoho  *
6828c506b8Sjruoho  * FUNCTION:    AslInitializeGlobals
6928c506b8Sjruoho  *
7028c506b8Sjruoho  * PARAMETERS:  None
7128c506b8Sjruoho  *
7228c506b8Sjruoho  * RETURN:      None
7328c506b8Sjruoho  *
7428c506b8Sjruoho  * DESCRIPTION: Re-initialize globals needed to restart the compiler. This
7528c506b8Sjruoho  *              allows multiple files to be disassembled and/or compiled.
7628c506b8Sjruoho  *
7728c506b8Sjruoho  ******************************************************************************/
7828c506b8Sjruoho 
79124f4c82Sjruoho void
AslInitializeGlobals(void)8028c506b8Sjruoho AslInitializeGlobals (
8128c506b8Sjruoho     void)
8228c506b8Sjruoho {
8328c506b8Sjruoho     UINT32                  i;
8428c506b8Sjruoho 
8528c506b8Sjruoho 
8628c506b8Sjruoho     /* Init compiler globals */
8728c506b8Sjruoho 
884c4e8184Schristos     AslGbl_SyntaxError = 0;
894c4e8184Schristos     AslGbl_CurrentColumn = 0;
904c4e8184Schristos     AslGbl_CurrentLineNumber = 1;
914c4e8184Schristos     AslGbl_LogicalLineNumber = 1;
924c4e8184Schristos     AslGbl_CurrentLineOffset = 0;
934c4e8184Schristos     AslGbl_InputFieldCount = 0;
944c4e8184Schristos     AslGbl_InputByteCount = 0;
954c4e8184Schristos     AslGbl_NsLookupCount = 0;
964c4e8184Schristos     AslGbl_LineBufPtr = AslGbl_CurrentLineBuffer;
9728c506b8Sjruoho 
984c4e8184Schristos     AslGbl_ErrorLog = NULL;
994c4e8184Schristos     AslGbl_NextError = NULL;
1004c4e8184Schristos     AslGbl_Signature = NULL;
1014c4e8184Schristos     AslGbl_FileType = 0;
10228c506b8Sjruoho 
1034c4e8184Schristos     AslGbl_TotalExecutableOpcodes = 0;
1044c4e8184Schristos     AslGbl_TotalNamedObjects = 0;
1054c4e8184Schristos     AslGbl_TotalKeywords = 0;
1064c4e8184Schristos     AslGbl_TotalParseNodes = 0;
1074c4e8184Schristos     AslGbl_TotalMethods = 0;
1084c4e8184Schristos     AslGbl_TotalAllocations = 0;
1094c4e8184Schristos     AslGbl_TotalAllocated = 0;
1104c4e8184Schristos     AslGbl_TotalFolds = 0;
111ff4a156dSchristos 
11228c506b8Sjruoho     AslGbl_NextEvent = 0;
11328c506b8Sjruoho     for (i = 0; i < ASL_NUM_REPORT_LEVELS; i++)
11428c506b8Sjruoho     {
1154c4e8184Schristos         AslGbl_ExceptionCount[i] = 0;
11628c506b8Sjruoho     }
11728c506b8Sjruoho 
118062782b3Schristos     if (AcpiGbl_CaptureComments)
119835858a6Schristos     {
1204c4e8184Schristos         AslGbl_CommentState.SpacesBefore          = 0;
1214c4e8184Schristos         AslGbl_CommentState.CommentType           = 1;
1224c4e8184Schristos         AslGbl_CommentState.LatestParseOp         = NULL;
1234c4e8184Schristos         AslGbl_CommentState.ParsingParenBraceNode = NULL;
1244c4e8184Schristos         AslGbl_CommentState.CaptureComments       = TRUE;
125835858a6Schristos     }
12628c506b8Sjruoho }
12728c506b8Sjruoho 
12828c506b8Sjruoho 
12928c506b8Sjruoho /*******************************************************************************
13028c506b8Sjruoho  *
13128c506b8Sjruoho  * FUNCTION:    AslDetectSourceFileType
13228c506b8Sjruoho  *
13328c506b8Sjruoho  * PARAMETERS:  Info            - Name/Handle for the file (must be open)
13428c506b8Sjruoho  *
13528c506b8Sjruoho  * RETURN:      File Type
13628c506b8Sjruoho  *
13728c506b8Sjruoho  * DESCRIPTION: Determine the type of the input file. Either binary (contains
13828c506b8Sjruoho  *              non-ASCII characters), ASL file, or an ACPI Data Table file.
13928c506b8Sjruoho  *
14028c506b8Sjruoho  ******************************************************************************/
14128c506b8Sjruoho 
142124f4c82Sjruoho static UINT8
AslDetectSourceFileType(ASL_FILE_INFO * Info)14328c506b8Sjruoho AslDetectSourceFileType (
14428c506b8Sjruoho     ASL_FILE_INFO           *Info)
14528c506b8Sjruoho {
14628c506b8Sjruoho     char                    *FileChar;
14771e38f1dSchristos     UINT8                   Type = ASL_INPUT_TYPE_ASCII_DATA; /* default */
14828c506b8Sjruoho     ACPI_STATUS             Status;
14928c506b8Sjruoho 
15028c506b8Sjruoho 
15128c506b8Sjruoho     /* Check for 100% ASCII source file (comments are ignored) */
15228c506b8Sjruoho 
15371e38f1dSchristos     Status = FlIsFileAsciiSource (Info->Filename, FALSE);
15471e38f1dSchristos     if (ACPI_SUCCESS (Status))
15528c506b8Sjruoho     {
15628c506b8Sjruoho         /*
15771e38f1dSchristos          * File contains ASCII source code. Determine if this is an ASL
15871e38f1dSchristos          * file or an ACPI data table file.
15928c506b8Sjruoho          */
1604c4e8184Schristos         while (fgets (AslGbl_CurrentLineBuffer, AslGbl_LineBufferSize, Info->Handle))
16128c506b8Sjruoho         {
16228c506b8Sjruoho             /* Uppercase the buffer for caseless compare */
16328c506b8Sjruoho 
1644c4e8184Schristos             FileChar = AslGbl_CurrentLineBuffer;
16528c506b8Sjruoho             while (*FileChar)
16628c506b8Sjruoho             {
16728c506b8Sjruoho                 *FileChar = (char) toupper ((int) *FileChar);
16828c506b8Sjruoho                 FileChar++;
16928c506b8Sjruoho             }
17028c506b8Sjruoho 
17128c506b8Sjruoho             /* Presence of "DefinitionBlock" indicates actual ASL code */
17228c506b8Sjruoho 
1734c4e8184Schristos             if (strstr (AslGbl_CurrentLineBuffer, "DEFINITIONBLOCK"))
17428c506b8Sjruoho             {
17528c506b8Sjruoho                 /* Appears to be an ASL file */
17628c506b8Sjruoho 
17728c506b8Sjruoho                 Type = ASL_INPUT_TYPE_ASCII_ASL;
17828c506b8Sjruoho                 goto Cleanup;
17928c506b8Sjruoho             }
18028c506b8Sjruoho         }
18128c506b8Sjruoho 
18271e38f1dSchristos         /* Appears to be an ASCII data table source file */
18328c506b8Sjruoho 
18428c506b8Sjruoho         Type = ASL_INPUT_TYPE_ASCII_DATA;
18571e38f1dSchristos         goto Cleanup;
18671e38f1dSchristos     }
18771e38f1dSchristos 
1888a8be6c4Schristos     /*
1898a8be6c4Schristos      * We have some sort of binary table; reopen in binary mode, then
1908a8be6c4Schristos      * check for valid ACPI table
1918a8be6c4Schristos      */
1928a8be6c4Schristos     fclose (Info->Handle);
1938a8be6c4Schristos     Info->Handle = fopen (Info->Filename, "rb");
1948a8be6c4Schristos     if (!Info->Handle)
1958a8be6c4Schristos     {
1968a8be6c4Schristos         fprintf (stderr, "Could not open input file %s\n",
1978a8be6c4Schristos             Info->Filename);
1988a8be6c4Schristos     }
19971e38f1dSchristos 
20071e38f1dSchristos     Status = AcValidateTableHeader (Info->Handle, 0);
20171e38f1dSchristos     if (ACPI_SUCCESS (Status))
20271e38f1dSchristos     {
20371e38f1dSchristos         fprintf (stderr,
20471e38f1dSchristos             "Binary file appears to be a valid ACPI table, disassembling\n");
20571e38f1dSchristos 
20671e38f1dSchristos         Type = ASL_INPUT_TYPE_BINARY_ACPI_TABLE;
20771e38f1dSchristos         goto Cleanup;
20871e38f1dSchristos     }
20989b8eb6cSchristos     else
21089b8eb6cSchristos     {
21189b8eb6cSchristos         fprintf (stderr,
21282065f3bSchristos             "Binary file does not contain a valid standard ACPI table\n");
21389b8eb6cSchristos     }
21471e38f1dSchristos 
21571e38f1dSchristos     Type = ASL_INPUT_TYPE_BINARY;
21671e38f1dSchristos 
21728c506b8Sjruoho 
21828c506b8Sjruoho Cleanup:
21928c506b8Sjruoho 
22028c506b8Sjruoho     /* Must seek back to the start of the file */
22128c506b8Sjruoho 
22228c506b8Sjruoho     fseek (Info->Handle, 0, SEEK_SET);
22328c506b8Sjruoho     return (Type);
22428c506b8Sjruoho }
22528c506b8Sjruoho 
22628c506b8Sjruoho 
22728c506b8Sjruoho /*******************************************************************************
22828c506b8Sjruoho  *
229ff4a156dSchristos  * FUNCTION:    AslDoDisassembly
23028c506b8Sjruoho  *
231ff4a156dSchristos  * PARAMETERS:  None
23228c506b8Sjruoho  *
23328c506b8Sjruoho  * RETURN:      Status
23428c506b8Sjruoho  *
235ff4a156dSchristos  * DESCRIPTION: Initiate AML file disassembly. Uses ACPICA subsystem to build
23694783addSchristos  *              namespace. This function assumes that the ACPI subsystem has
23794783addSchristos  *              been initialized. The caller of the initialization will also
23894783addSchristos  *              terminate the ACPI subsystem.
23928c506b8Sjruoho  *
24028c506b8Sjruoho  ******************************************************************************/
24128c506b8Sjruoho 
24294783addSchristos ACPI_STATUS
AslDoDisassembly(void)243ff4a156dSchristos AslDoDisassembly (
244ff4a156dSchristos     void)
24528c506b8Sjruoho {
24628c506b8Sjruoho     ACPI_STATUS             Status;
24728c506b8Sjruoho 
24828c506b8Sjruoho 
24928c506b8Sjruoho     Status = AcpiAllocateRootTable (4);
25028c506b8Sjruoho     if (ACPI_FAILURE (Status))
25128c506b8Sjruoho     {
25228c506b8Sjruoho         AcpiOsPrintf ("Could not initialize ACPI Table Manager, %s\n",
25328c506b8Sjruoho             AcpiFormatException (Status));
25428c506b8Sjruoho         return (Status);
25528c506b8Sjruoho     }
25628c506b8Sjruoho 
25728c506b8Sjruoho     /* This is where the disassembly happens */
25828c506b8Sjruoho 
25971e38f1dSchristos     AcpiGbl_DmOpt_Disasm = TRUE;
26028c506b8Sjruoho     Status = AdAmlDisassemble (AslToFile,
2614c4e8184Schristos         AslGbl_Files[ASL_FILE_INPUT].Filename, AslGbl_OutputFilenamePrefix,
2624c4e8184Schristos         &AslGbl_Files[ASL_FILE_INPUT].Filename);
26328c506b8Sjruoho     if (ACPI_FAILURE (Status))
26428c506b8Sjruoho     {
26528c506b8Sjruoho         return (Status);
26628c506b8Sjruoho     }
26728c506b8Sjruoho 
268ff4a156dSchristos     /* Check if any control methods were unresolved */
269ff4a156dSchristos 
270ff4a156dSchristos     AcpiDmUnresolvedWarning (0);
271ff4a156dSchristos 
27294783addSchristos     /* Clear Error log */
27328c506b8Sjruoho 
27428c506b8Sjruoho     AeClearErrorLog ();
27528c506b8Sjruoho 
27628c506b8Sjruoho     /*
2774c4e8184Schristos      * AslGbl_Files[ASL_FILE_INPUT].Filename was replaced with the
27828c506b8Sjruoho      * .DSL disassembly file, which can now be compiled if requested
27928c506b8Sjruoho      */
2804c4e8184Schristos     if (AslGbl_DoCompile)
28128c506b8Sjruoho     {
28228c506b8Sjruoho         AcpiOsPrintf ("\nCompiling \"%s\"\n",
2834c4e8184Schristos             AslGbl_Files[ASL_FILE_INPUT].Filename);
284ff4a156dSchristos         return (AE_CTRL_CONTINUE);
28528c506b8Sjruoho     }
286ff4a156dSchristos 
28728c506b8Sjruoho     return (AE_OK);
28828c506b8Sjruoho }
289ff4a156dSchristos 
290ff4a156dSchristos 
291ff4a156dSchristos /*******************************************************************************
292ff4a156dSchristos  *
293ff4a156dSchristos  * FUNCTION:    AslDoOneFile
294ff4a156dSchristos  *
295ff4a156dSchristos  * PARAMETERS:  Filename        - Name of the file
296ff4a156dSchristos  *
297ff4a156dSchristos  * RETURN:      Status
298ff4a156dSchristos  *
299ff4a156dSchristos  * DESCRIPTION: Process a single file - either disassemble, compile, or both
300ff4a156dSchristos  *
301ff4a156dSchristos  ******************************************************************************/
302ff4a156dSchristos 
303ff4a156dSchristos ACPI_STATUS
AslDoOneFile(char * Filename)304ff4a156dSchristos AslDoOneFile (
305ff4a156dSchristos     char                    *Filename)
306ff4a156dSchristos {
307ff4a156dSchristos     ACPI_STATUS             Status;
30894783addSchristos     UINT8                   Event;
30994783addSchristos     ASL_GLOBAL_FILE_NODE    *FileNode;
310ff4a156dSchristos 
311ff4a156dSchristos 
312ff4a156dSchristos     /* Re-initialize "some" compiler/preprocessor globals */
313ff4a156dSchristos 
314ff4a156dSchristos     AslInitializeGlobals ();
315ff4a156dSchristos     PrInitializeGlobals ();
316ff4a156dSchristos 
317ff4a156dSchristos     /*
318ff4a156dSchristos      * Extract the directory path. This path is used for possible include
319ff4a156dSchristos      * files and the optional AML filename embedded in the input file
320ff4a156dSchristos      * DefinitionBlock declaration.
321ff4a156dSchristos      */
3224c4e8184Schristos     Status = FlSplitInputPathname (Filename, &AslGbl_DirectoryPath, NULL);
323ff4a156dSchristos     if (ACPI_FAILURE (Status))
324ff4a156dSchristos     {
325ff4a156dSchristos         return (Status);
326ff4a156dSchristos     }
327ff4a156dSchristos 
32894783addSchristos     /*
32994783addSchristos      * There was an input file detected at this point. Each input ASL file is
33094783addSchristos      * associated with one global file node consisting of the input file and
33194783addSchristos      * all output files associated with it. This is useful when compiling
33294783addSchristos      * multiple files in one command.
33394783addSchristos      */
33494783addSchristos     Status = FlInitOneFile(Filename);
33594783addSchristos     if (ACPI_FAILURE (Status))
33694783addSchristos     {
33794783addSchristos         return (AE_ERROR);
33894783addSchristos     }
33994783addSchristos 
340460301d4Schristos     /* Take a copy of the input filename, convert any backslashes */
341460301d4Schristos 
3424c4e8184Schristos     AslGbl_Files[ASL_FILE_INPUT].Filename =
343b406f703Schristos         UtLocalCacheCalloc (strlen (Filename) + 1);
344460301d4Schristos 
3454c4e8184Schristos     strcpy (AslGbl_Files[ASL_FILE_INPUT].Filename, Filename);
3464c4e8184Schristos     UtConvertBackslashes (AslGbl_Files[ASL_FILE_INPUT].Filename);
347ff4a156dSchristos 
348ff4a156dSchristos     /*
3498a8be6c4Schristos      * Open the input file. Here, this could be an ASCII source file,
3508a8be6c4Schristos      * either an ASL file or a Data Table file, or a binary AML file
3518a8be6c4Schristos      * or binary data table file (For disassembly).
35228c506b8Sjruoho      */
3534c4e8184Schristos     Status = FlOpenInputFile (AslGbl_Files[ASL_FILE_INPUT].Filename);
35428c506b8Sjruoho     if (ACPI_FAILURE (Status))
35528c506b8Sjruoho     {
35628c506b8Sjruoho         AePrintErrorLog (ASL_FILE_STDERR);
35728c506b8Sjruoho         return (AE_ERROR);
35828c506b8Sjruoho     }
35928c506b8Sjruoho 
36094783addSchristos     FileNode = FlGetCurrentFileNode();
36194783addSchristos 
36228c506b8Sjruoho     /* Determine input file type */
36328c506b8Sjruoho 
3644c4e8184Schristos     AslGbl_FileType = AslDetectSourceFileType (&AslGbl_Files[ASL_FILE_INPUT]);
365783af925Schristos     FileNode->FileType = AslGbl_FileType;
3664c4e8184Schristos     if (AslGbl_FileType == ASL_INPUT_TYPE_BINARY)
36728c506b8Sjruoho     {
36828c506b8Sjruoho         return (AE_ERROR);
36928c506b8Sjruoho     }
37028c506b8Sjruoho 
3718a8be6c4Schristos     FileNode->OriginalInputFileSize = FlGetFileSize (ASL_FILE_INPUT);
3728a8be6c4Schristos 
37328c506b8Sjruoho     /*
37428c506b8Sjruoho      * If -p not specified, we will use the input filename as the
37528c506b8Sjruoho      * output filename prefix
37628c506b8Sjruoho      */
3774c4e8184Schristos     if (AslGbl_UseDefaultAmlFilename)
37828c506b8Sjruoho     {
3794c4e8184Schristos         AslGbl_OutputFilenamePrefix = AslGbl_Files[ASL_FILE_INPUT].Filename;
38028c506b8Sjruoho     }
38128c506b8Sjruoho 
38294783addSchristos     /*
38394783addSchristos      * Open the output file. Note: by default, the name of this file comes from
38494783addSchristos      * the table descriptor within the input file.
38594783addSchristos      */
38694783addSchristos     if (AslGbl_FileType == ASL_INPUT_TYPE_ASCII_ASL)
38794783addSchristos     {
38894783addSchristos         Event = UtBeginEvent ("Open AML output file");
38994783addSchristos         Status = FlOpenAmlOutputFile (AslGbl_OutputFilenamePrefix);
39094783addSchristos         UtEndEvent (Event);
39194783addSchristos         if (ACPI_FAILURE (Status))
39294783addSchristos         {
39394783addSchristos             AePrintErrorLog (ASL_FILE_STDERR);
39494783addSchristos             return (AE_ERROR);
39594783addSchristos         }
39694783addSchristos     }
39794783addSchristos 
39828c506b8Sjruoho     /* Open the optional output files (listings, etc.) */
39928c506b8Sjruoho 
4004c4e8184Schristos     Status = FlOpenMiscOutputFiles (AslGbl_OutputFilenamePrefix);
40128c506b8Sjruoho     if (ACPI_FAILURE (Status))
40228c506b8Sjruoho     {
40328c506b8Sjruoho         AePrintErrorLog (ASL_FILE_STDERR);
40428c506b8Sjruoho         return (AE_ERROR);
40528c506b8Sjruoho     }
40628c506b8Sjruoho 
40728c506b8Sjruoho     /*
40828c506b8Sjruoho      * Compilation of ASL source versus DataTable source uses different
40928c506b8Sjruoho      * compiler subsystems
41028c506b8Sjruoho      */
4114c4e8184Schristos     switch (AslGbl_FileType)
41228c506b8Sjruoho     {
41328c506b8Sjruoho     /*
41428c506b8Sjruoho      * Data Table Compilation
41528c506b8Sjruoho      */
41628c506b8Sjruoho     case ASL_INPUT_TYPE_ASCII_DATA:
41728c506b8Sjruoho 
41828c506b8Sjruoho         Status = DtDoCompile ();
419ff4a156dSchristos         if (ACPI_FAILURE (Status))
420ff4a156dSchristos         {
421ff4a156dSchristos             return (Status);
422ff4a156dSchristos         }
42328c506b8Sjruoho 
4244c4e8184Schristos         if (AslGbl_Signature)
42528c506b8Sjruoho         {
4264c4e8184Schristos             AslGbl_Signature = NULL;
42728c506b8Sjruoho         }
428ff4a156dSchristos 
429ff4a156dSchristos         /* Check if any errors occurred during compile */
430ff4a156dSchristos 
431ff4a156dSchristos         Status = AslCheckForErrorExit ();
432ff4a156dSchristos         if (ACPI_FAILURE (Status))
433ff4a156dSchristos         {
434ff4a156dSchristos             return (Status);
435ff4a156dSchristos         }
436ff4a156dSchristos 
437ff4a156dSchristos         /* Cleanup (for next source file) and exit */
438ff4a156dSchristos 
43928c506b8Sjruoho         AeClearErrorLog ();
440ff4a156dSchristos         PrTerminatePreprocessor ();
44128c506b8Sjruoho         return (Status);
44228c506b8Sjruoho 
44328c506b8Sjruoho     /*
444ff4a156dSchristos      * ASL Compilation
44528c506b8Sjruoho      */
44628c506b8Sjruoho     case ASL_INPUT_TYPE_ASCII_ASL:
44728c506b8Sjruoho 
44894783addSchristos         Status = CmDoCompile ();
449ff4a156dSchristos         if (ACPI_FAILURE (Status))
45028c506b8Sjruoho         {
451783af925Schristos             PrTerminatePreprocessor ();
452ff4a156dSchristos             return (Status);
45328c506b8Sjruoho         }
45428c506b8Sjruoho 
455835858a6Schristos         /*
45694783addSchristos          * At this point, we know how many lines are in the input file. Save it
45794783addSchristos          * to display for post-compilation summary.
458835858a6Schristos          */
45994783addSchristos         FileNode->TotalLineCount = AslGbl_CurrentLineNumber;
46028c506b8Sjruoho         return (AE_OK);
46128c506b8Sjruoho 
462ff4a156dSchristos     /*
463ff4a156dSchristos      * Binary ACPI table was auto-detected, disassemble it
464ff4a156dSchristos      */
46571e38f1dSchristos     case ASL_INPUT_TYPE_BINARY_ACPI_TABLE:
466ff4a156dSchristos 
467ff4a156dSchristos         /* We have what appears to be an ACPI table, disassemble it */
468ff4a156dSchristos 
469ff4a156dSchristos         FlCloseFile (ASL_FILE_INPUT);
4704c4e8184Schristos         AslGbl_DoCompile = FALSE;
47189b8eb6cSchristos         AcpiGbl_DisasmFlag = TRUE;
472ff4a156dSchristos         Status = AslDoDisassembly ();
473ff4a156dSchristos         return (Status);
474ff4a156dSchristos 
475ff4a156dSchristos     /* Unknown binary table */
476ff4a156dSchristos 
47728c506b8Sjruoho     case ASL_INPUT_TYPE_BINARY:
47828c506b8Sjruoho 
47928c506b8Sjruoho         AePrintErrorLog (ASL_FILE_STDERR);
48028c506b8Sjruoho         return (AE_ERROR);
48128c506b8Sjruoho 
48228c506b8Sjruoho     default:
483ff4a156dSchristos 
4844c4e8184Schristos         printf ("Unknown file type %X\n", AslGbl_FileType);
48528c506b8Sjruoho         return (AE_ERROR);
48628c506b8Sjruoho     }
48728c506b8Sjruoho }
48828c506b8Sjruoho 
48928c506b8Sjruoho 
49028c506b8Sjruoho /*******************************************************************************
49128c506b8Sjruoho  *
492ff4a156dSchristos  * FUNCTION:    AslCheckForErrorExit
49328c506b8Sjruoho  *
494ff4a156dSchristos  * PARAMETERS:  None. Examines global exception count array
49528c506b8Sjruoho  *
49628c506b8Sjruoho  * RETURN:      Status
49728c506b8Sjruoho  *
498ff4a156dSchristos  * DESCRIPTION: Determine if compiler should abort with error status
49928c506b8Sjruoho  *
50028c506b8Sjruoho  ******************************************************************************/
50128c506b8Sjruoho 
50228c506b8Sjruoho ACPI_STATUS
AslCheckForErrorExit(void)503ff4a156dSchristos AslCheckForErrorExit (
504ff4a156dSchristos     void)
50528c506b8Sjruoho {
50628c506b8Sjruoho 
50728c506b8Sjruoho     /*
508ff4a156dSchristos      * Return non-zero exit code if there have been errors, unless the
509ff4a156dSchristos      * global ignore error flag has been set
51028c506b8Sjruoho      */
5114c4e8184Schristos     if (!AslGbl_IgnoreErrors)
51228c506b8Sjruoho     {
5134c4e8184Schristos         if (AslGbl_ExceptionCount[ASL_ERROR] > 0)
514ff4a156dSchristos         {
515ff4a156dSchristos             return (AE_ERROR);
51628c506b8Sjruoho         }
51728c506b8Sjruoho 
518ff4a156dSchristos         /* Optionally treat warnings as errors */
51928c506b8Sjruoho 
5204c4e8184Schristos         if (AslGbl_WarningsAsErrors)
521ff4a156dSchristos         {
5224c4e8184Schristos             if ((AslGbl_ExceptionCount[ASL_WARNING] > 0)  ||
5234c4e8184Schristos                 (AslGbl_ExceptionCount[ASL_WARNING2] > 0) ||
5244c4e8184Schristos                 (AslGbl_ExceptionCount[ASL_WARNING3] > 0))
525ff4a156dSchristos             {
52694783addSchristos                 AslError (ASL_ERROR, ASL_MSG_WARNING_AS_ERROR, NULL,
52794783addSchristos                     "(reporting warnings as errors)");
528ff4a156dSchristos                 return (AE_ERROR);
529ff4a156dSchristos             }
530ff4a156dSchristos         }
53128c506b8Sjruoho     }
53228c506b8Sjruoho 
533ff4a156dSchristos     return (AE_OK);
53428c506b8Sjruoho }
535