xref: /freebsd/sys/contrib/dev/acpica/compiler/aslstartup.c (revision 313a0c13efa638cf248e35eed49f36ec0a1a7f26)
1a9f12690SJung-uk Kim /******************************************************************************
2a9f12690SJung-uk Kim  *
3a9f12690SJung-uk Kim  * Module Name: aslstartup - Compiler startup routines, called from main
4a9f12690SJung-uk Kim  *
5a9f12690SJung-uk Kim  *****************************************************************************/
6a9f12690SJung-uk Kim 
7d244b227SJung-uk Kim /*
8*313a0c13SJung-uk Kim  * Copyright (C) 2000 - 2014, Intel Corp.
9a9f12690SJung-uk Kim  * All rights reserved.
10a9f12690SJung-uk Kim  *
11d244b227SJung-uk Kim  * Redistribution and use in source and binary forms, with or without
12d244b227SJung-uk Kim  * modification, are permitted provided that the following conditions
13d244b227SJung-uk Kim  * are met:
14d244b227SJung-uk Kim  * 1. Redistributions of source code must retain the above copyright
15d244b227SJung-uk Kim  *    notice, this list of conditions, and the following disclaimer,
16d244b227SJung-uk Kim  *    without modification.
17d244b227SJung-uk Kim  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18d244b227SJung-uk Kim  *    substantially similar to the "NO WARRANTY" disclaimer below
19d244b227SJung-uk Kim  *    ("Disclaimer") and any redistribution must be conditioned upon
20d244b227SJung-uk Kim  *    including a substantially similar Disclaimer requirement for further
21d244b227SJung-uk Kim  *    binary redistribution.
22d244b227SJung-uk Kim  * 3. Neither the names of the above-listed copyright holders nor the names
23d244b227SJung-uk Kim  *    of any contributors may be used to endorse or promote products derived
24d244b227SJung-uk Kim  *    from this software without specific prior written permission.
25a9f12690SJung-uk Kim  *
26d244b227SJung-uk Kim  * Alternatively, this software may be distributed under the terms of the
27d244b227SJung-uk Kim  * GNU General Public License ("GPL") version 2 as published by the Free
28d244b227SJung-uk Kim  * Software Foundation.
29a9f12690SJung-uk Kim  *
30d244b227SJung-uk Kim  * NO WARRANTY
31d244b227SJung-uk Kim  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32d244b227SJung-uk Kim  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33d244b227SJung-uk Kim  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34d244b227SJung-uk Kim  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35d244b227SJung-uk Kim  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36d244b227SJung-uk Kim  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37d244b227SJung-uk Kim  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38d244b227SJung-uk Kim  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39d244b227SJung-uk Kim  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40d244b227SJung-uk Kim  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41d244b227SJung-uk Kim  * POSSIBILITY OF SUCH DAMAGES.
42d244b227SJung-uk Kim  */
43a9f12690SJung-uk Kim 
44ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h>
45ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/actables.h>
469c48c75eSJung-uk Kim #include <contrib/dev/acpica/include/acdisasm.h>
47ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acapps.h>
48a9f12690SJung-uk Kim 
49a9f12690SJung-uk Kim #define _COMPONENT          ACPI_COMPILER
50a9f12690SJung-uk Kim         ACPI_MODULE_NAME    ("aslstartup")
51a9f12690SJung-uk Kim 
52a9f12690SJung-uk Kim 
53a9f12690SJung-uk Kim /* Local prototypes */
54a9f12690SJung-uk Kim 
5542fecd12SJung-uk Kim static UINT8
56a88e22b7SJung-uk Kim AslDetectSourceFileType (
57a88e22b7SJung-uk Kim     ASL_FILE_INFO           *Info);
58a88e22b7SJung-uk Kim 
599c48c75eSJung-uk Kim static ACPI_STATUS
609c48c75eSJung-uk Kim AslDoDisassembly (
619c48c75eSJung-uk Kim     void);
629c48c75eSJung-uk Kim 
63a9f12690SJung-uk Kim 
64*313a0c13SJung-uk Kim /* Globals */
65*313a0c13SJung-uk Kim 
66*313a0c13SJung-uk Kim static BOOLEAN          AslToFile = TRUE;
67*313a0c13SJung-uk Kim 
68*313a0c13SJung-uk Kim 
69a9f12690SJung-uk Kim /*******************************************************************************
70a9f12690SJung-uk Kim  *
71a9f12690SJung-uk Kim  * FUNCTION:    AslInitializeGlobals
72a9f12690SJung-uk Kim  *
73a9f12690SJung-uk Kim  * PARAMETERS:  None
74a9f12690SJung-uk Kim  *
75a9f12690SJung-uk Kim  * RETURN:      None
76a9f12690SJung-uk Kim  *
77a9f12690SJung-uk Kim  * DESCRIPTION: Re-initialize globals needed to restart the compiler. This
78a9f12690SJung-uk Kim  *              allows multiple files to be disassembled and/or compiled.
79a9f12690SJung-uk Kim  *
80a9f12690SJung-uk Kim  ******************************************************************************/
81a9f12690SJung-uk Kim 
82a88e22b7SJung-uk Kim void
83a9f12690SJung-uk Kim AslInitializeGlobals (
84a9f12690SJung-uk Kim     void)
85a9f12690SJung-uk Kim {
86a9f12690SJung-uk Kim     UINT32                  i;
87a9f12690SJung-uk Kim 
88a9f12690SJung-uk Kim 
89a9f12690SJung-uk Kim     /* Init compiler globals */
90a9f12690SJung-uk Kim 
91a9f12690SJung-uk Kim     Gbl_CurrentColumn = 0;
92a9f12690SJung-uk Kim     Gbl_CurrentLineNumber = 1;
93a9f12690SJung-uk Kim     Gbl_LogicalLineNumber = 1;
94a9f12690SJung-uk Kim     Gbl_CurrentLineOffset = 0;
95a88e22b7SJung-uk Kim     Gbl_InputFieldCount = 0;
964c52cad2SJung-uk Kim     Gbl_InputByteCount = 0;
974c52cad2SJung-uk Kim     Gbl_NsLookupCount = 0;
98a9f12690SJung-uk Kim     Gbl_LineBufPtr = Gbl_CurrentLineBuffer;
99a9f12690SJung-uk Kim 
100a9f12690SJung-uk Kim     Gbl_ErrorLog = NULL;
101a9f12690SJung-uk Kim     Gbl_NextError = NULL;
102a88e22b7SJung-uk Kim     Gbl_Signature = NULL;
103a88e22b7SJung-uk Kim     Gbl_FileType = 0;
104a9f12690SJung-uk Kim 
1054c52cad2SJung-uk Kim     TotalExecutableOpcodes = 0;
1064c52cad2SJung-uk Kim     TotalNamedObjects = 0;
1074c52cad2SJung-uk Kim     TotalKeywords = 0;
1084c52cad2SJung-uk Kim     TotalParseNodes = 0;
1094c52cad2SJung-uk Kim     TotalMethods = 0;
1104c52cad2SJung-uk Kim     TotalAllocations = 0;
1114c52cad2SJung-uk Kim     TotalAllocated = 0;
1124c52cad2SJung-uk Kim     TotalFolds = 0;
1134c52cad2SJung-uk Kim 
114a9f12690SJung-uk Kim     AslGbl_NextEvent = 0;
115a9f12690SJung-uk Kim     for (i = 0; i < ASL_NUM_REPORT_LEVELS; i++)
116a9f12690SJung-uk Kim     {
117a9f12690SJung-uk Kim         Gbl_ExceptionCount[i] = 0;
118a9f12690SJung-uk Kim     }
119a9f12690SJung-uk Kim 
1204c52cad2SJung-uk Kim     for (i = ASL_FILE_INPUT; i <= ASL_MAX_FILE_TYPE; i++)
1214c52cad2SJung-uk Kim     {
1224c52cad2SJung-uk Kim         Gbl_Files[i].Handle = NULL;
1234c52cad2SJung-uk Kim         Gbl_Files[i].Filename = NULL;
1244c52cad2SJung-uk Kim     }
125a9f12690SJung-uk Kim }
126a9f12690SJung-uk Kim 
127a9f12690SJung-uk Kim 
128a9f12690SJung-uk Kim /*******************************************************************************
129a9f12690SJung-uk Kim  *
130a88e22b7SJung-uk Kim  * FUNCTION:    AslDetectSourceFileType
131a88e22b7SJung-uk Kim  *
132a88e22b7SJung-uk Kim  * PARAMETERS:  Info            - Name/Handle for the file (must be open)
133a88e22b7SJung-uk Kim  *
134a88e22b7SJung-uk Kim  * RETURN:      File Type
135a88e22b7SJung-uk Kim  *
136a88e22b7SJung-uk Kim  * DESCRIPTION: Determine the type of the input file. Either binary (contains
137a88e22b7SJung-uk Kim  *              non-ASCII characters), ASL file, or an ACPI Data Table file.
138a88e22b7SJung-uk Kim  *
139a88e22b7SJung-uk Kim  ******************************************************************************/
140a88e22b7SJung-uk Kim 
14142fecd12SJung-uk Kim static UINT8
142a88e22b7SJung-uk Kim AslDetectSourceFileType (
143a88e22b7SJung-uk Kim     ASL_FILE_INFO           *Info)
144a88e22b7SJung-uk Kim {
145a88e22b7SJung-uk Kim     char                    *FileChar;
146a88e22b7SJung-uk Kim     UINT8                   Type;
147a88e22b7SJung-uk Kim     ACPI_STATUS             Status;
148a88e22b7SJung-uk Kim 
149a88e22b7SJung-uk Kim 
1509c48c75eSJung-uk Kim     /* Check for a valid binary ACPI table */
1519c48c75eSJung-uk Kim 
1529c48c75eSJung-uk Kim     Status = FlCheckForAcpiTable (Info->Handle);
1539c48c75eSJung-uk Kim     if (ACPI_SUCCESS (Status))
1549c48c75eSJung-uk Kim     {
1559c48c75eSJung-uk Kim         Type = ASL_INPUT_TYPE_ACPI_TABLE;
1569c48c75eSJung-uk Kim         goto Cleanup;
1579c48c75eSJung-uk Kim     }
1589c48c75eSJung-uk Kim 
159a88e22b7SJung-uk Kim     /* Check for 100% ASCII source file (comments are ignored) */
160a88e22b7SJung-uk Kim 
161a7a3b383SJung-uk Kim     Status = FlCheckForAscii (Info->Handle, Info->Filename, TRUE);
162a88e22b7SJung-uk Kim     if (ACPI_FAILURE (Status))
163a88e22b7SJung-uk Kim     {
164a88e22b7SJung-uk Kim         printf ("Non-ascii input file - %s\n", Info->Filename);
1658ef1a331SJung-uk Kim 
1668ef1a331SJung-uk Kim         if (!Gbl_IgnoreErrors)
1678ef1a331SJung-uk Kim         {
168a88e22b7SJung-uk Kim             Type = ASL_INPUT_TYPE_BINARY;
169a88e22b7SJung-uk Kim             goto Cleanup;
170a88e22b7SJung-uk Kim         }
1718ef1a331SJung-uk Kim     }
172a88e22b7SJung-uk Kim 
173a88e22b7SJung-uk Kim     /*
174a88e22b7SJung-uk Kim      * File is ASCII. Determine if this is an ASL file or an ACPI data
175a88e22b7SJung-uk Kim      * table file.
176a88e22b7SJung-uk Kim      */
177042ff955SJung-uk Kim     while (fgets (Gbl_CurrentLineBuffer, Gbl_LineBufferSize, Info->Handle))
178a88e22b7SJung-uk Kim     {
179a88e22b7SJung-uk Kim         /* Uppercase the buffer for caseless compare */
180a88e22b7SJung-uk Kim 
181a88e22b7SJung-uk Kim         FileChar = Gbl_CurrentLineBuffer;
182a88e22b7SJung-uk Kim         while (*FileChar)
183a88e22b7SJung-uk Kim         {
184a88e22b7SJung-uk Kim             *FileChar = (char) toupper ((int) *FileChar);
185a88e22b7SJung-uk Kim             FileChar++;
186a88e22b7SJung-uk Kim         }
187a88e22b7SJung-uk Kim 
188a88e22b7SJung-uk Kim         /* Presence of "DefinitionBlock" indicates actual ASL code */
189a88e22b7SJung-uk Kim 
190a88e22b7SJung-uk Kim         if (strstr (Gbl_CurrentLineBuffer, "DEFINITIONBLOCK"))
191a88e22b7SJung-uk Kim         {
192a88e22b7SJung-uk Kim             /* Appears to be an ASL file */
193a88e22b7SJung-uk Kim 
194a88e22b7SJung-uk Kim             Type = ASL_INPUT_TYPE_ASCII_ASL;
195a88e22b7SJung-uk Kim             goto Cleanup;
196a88e22b7SJung-uk Kim         }
197a88e22b7SJung-uk Kim     }
198a88e22b7SJung-uk Kim 
199a88e22b7SJung-uk Kim     /* Not an ASL source file, default to a data table source file */
200a88e22b7SJung-uk Kim 
201a88e22b7SJung-uk Kim     Type = ASL_INPUT_TYPE_ASCII_DATA;
202a88e22b7SJung-uk Kim 
203a88e22b7SJung-uk Kim Cleanup:
204a88e22b7SJung-uk Kim 
205a88e22b7SJung-uk Kim     /* Must seek back to the start of the file */
206a88e22b7SJung-uk Kim 
207a88e22b7SJung-uk Kim     fseek (Info->Handle, 0, SEEK_SET);
208a88e22b7SJung-uk Kim     return (Type);
209a88e22b7SJung-uk Kim }
210a88e22b7SJung-uk Kim 
211a88e22b7SJung-uk Kim 
212a88e22b7SJung-uk Kim /*******************************************************************************
213a88e22b7SJung-uk Kim  *
2149c48c75eSJung-uk Kim  * FUNCTION:    AslDoDisassembly
2159c48c75eSJung-uk Kim  *
2169c48c75eSJung-uk Kim  * PARAMETERS:  None
2179c48c75eSJung-uk Kim  *
2189c48c75eSJung-uk Kim  * RETURN:      Status
2199c48c75eSJung-uk Kim  *
2209c48c75eSJung-uk Kim  * DESCRIPTION: Initiate AML file disassembly. Uses ACPICA subsystem to build
2219c48c75eSJung-uk Kim  *              namespace.
2229c48c75eSJung-uk Kim  *
2239c48c75eSJung-uk Kim  ******************************************************************************/
2249c48c75eSJung-uk Kim 
2259c48c75eSJung-uk Kim static ACPI_STATUS
2269c48c75eSJung-uk Kim AslDoDisassembly (
2279c48c75eSJung-uk Kim     void)
2289c48c75eSJung-uk Kim {
2299c48c75eSJung-uk Kim     ACPI_STATUS             Status;
2309c48c75eSJung-uk Kim 
2319c48c75eSJung-uk Kim 
2329c48c75eSJung-uk Kim     /* ACPICA subsystem initialization */
2339c48c75eSJung-uk Kim 
2349c48c75eSJung-uk Kim     Status = AdInitialize ();
2359c48c75eSJung-uk Kim     if (ACPI_FAILURE (Status))
2369c48c75eSJung-uk Kim     {
2379c48c75eSJung-uk Kim         return (Status);
2389c48c75eSJung-uk Kim     }
2399c48c75eSJung-uk Kim 
2409c48c75eSJung-uk Kim     Status = AcpiAllocateRootTable (4);
2419c48c75eSJung-uk Kim     if (ACPI_FAILURE (Status))
2429c48c75eSJung-uk Kim     {
2439c48c75eSJung-uk Kim         AcpiOsPrintf ("Could not initialize ACPI Table Manager, %s\n",
2449c48c75eSJung-uk Kim             AcpiFormatException (Status));
2459c48c75eSJung-uk Kim         return (Status);
2469c48c75eSJung-uk Kim     }
2479c48c75eSJung-uk Kim 
2489c48c75eSJung-uk Kim     /* This is where the disassembly happens */
2499c48c75eSJung-uk Kim 
2509c48c75eSJung-uk Kim     AcpiGbl_DbOpt_disasm = TRUE;
2519c48c75eSJung-uk Kim     Status = AdAmlDisassemble (AslToFile,
2529c48c75eSJung-uk Kim         Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_OutputFilenamePrefix,
253*313a0c13SJung-uk Kim         &Gbl_Files[ASL_FILE_INPUT].Filename);
2549c48c75eSJung-uk Kim     if (ACPI_FAILURE (Status))
2559c48c75eSJung-uk Kim     {
2569c48c75eSJung-uk Kim         return (Status);
2579c48c75eSJung-uk Kim     }
2589c48c75eSJung-uk Kim 
2599c48c75eSJung-uk Kim     /* Check if any control methods were unresolved */
2609c48c75eSJung-uk Kim 
2619c48c75eSJung-uk Kim     AcpiDmUnresolvedWarning (0);
2629c48c75eSJung-uk Kim 
2639c48c75eSJung-uk Kim #if 0
2649c48c75eSJung-uk Kim     /* TBD: Handle additional output files for disassembler */
2659c48c75eSJung-uk Kim 
2669c48c75eSJung-uk Kim     Status = FlOpenMiscOutputFiles (Gbl_OutputFilenamePrefix);
2679c48c75eSJung-uk Kim     NsDisplayNamespace ();
2689c48c75eSJung-uk Kim #endif
2699c48c75eSJung-uk Kim 
2709c48c75eSJung-uk Kim     /* Shutdown compiler and ACPICA subsystem */
2719c48c75eSJung-uk Kim 
2729c48c75eSJung-uk Kim     AeClearErrorLog ();
2739c48c75eSJung-uk Kim     (void) AcpiTerminate ();
2749c48c75eSJung-uk Kim 
2759c48c75eSJung-uk Kim     /*
2769c48c75eSJung-uk Kim      * Gbl_Files[ASL_FILE_INPUT].Filename was replaced with the
2779c48c75eSJung-uk Kim      * .DSL disassembly file, which can now be compiled if requested
2789c48c75eSJung-uk Kim      */
2799c48c75eSJung-uk Kim     if (Gbl_DoCompile)
2809c48c75eSJung-uk Kim     {
2819c48c75eSJung-uk Kim         AcpiOsPrintf ("\nCompiling \"%s\"\n",
2829c48c75eSJung-uk Kim             Gbl_Files[ASL_FILE_INPUT].Filename);
2839c48c75eSJung-uk Kim         return (AE_CTRL_CONTINUE);
2849c48c75eSJung-uk Kim     }
2859c48c75eSJung-uk Kim 
286*313a0c13SJung-uk Kim     /* No need to free the filename string */
287*313a0c13SJung-uk Kim 
2889c48c75eSJung-uk Kim     Gbl_Files[ASL_FILE_INPUT].Filename = NULL;
289*313a0c13SJung-uk Kim 
290*313a0c13SJung-uk Kim     CmDeleteCaches ();
2919c48c75eSJung-uk Kim     return (AE_OK);
2929c48c75eSJung-uk Kim }
2939c48c75eSJung-uk Kim 
2949c48c75eSJung-uk Kim 
2959c48c75eSJung-uk Kim /*******************************************************************************
2969c48c75eSJung-uk Kim  *
297a9f12690SJung-uk Kim  * FUNCTION:    AslDoOneFile
298a9f12690SJung-uk Kim  *
299a9f12690SJung-uk Kim  * PARAMETERS:  Filename        - Name of the file
300a9f12690SJung-uk Kim  *
301a9f12690SJung-uk Kim  * RETURN:      Status
302a9f12690SJung-uk Kim  *
303a9f12690SJung-uk Kim  * DESCRIPTION: Process a single file - either disassemble, compile, or both
304a9f12690SJung-uk Kim  *
305a9f12690SJung-uk Kim  ******************************************************************************/
306a9f12690SJung-uk Kim 
307a9f12690SJung-uk Kim ACPI_STATUS
308a9f12690SJung-uk Kim AslDoOneFile (
309a9f12690SJung-uk Kim     char                    *Filename)
310a9f12690SJung-uk Kim {
311a9f12690SJung-uk Kim     ACPI_STATUS             Status;
312a9f12690SJung-uk Kim 
313a9f12690SJung-uk Kim 
3144c52cad2SJung-uk Kim     /* Re-initialize "some" compiler/preprocessor globals */
315a9f12690SJung-uk Kim 
316a9f12690SJung-uk Kim     AslInitializeGlobals ();
3174c52cad2SJung-uk Kim     PrInitializeGlobals ();
3184c52cad2SJung-uk Kim 
319*313a0c13SJung-uk Kim     /*
320*313a0c13SJung-uk Kim      * Extract the directory path. This path is used for possible include
321*313a0c13SJung-uk Kim      * files and the optional AML filename embedded in the input file
322*313a0c13SJung-uk Kim      * DefinitionBlock declaration.
323*313a0c13SJung-uk Kim      */
324*313a0c13SJung-uk Kim     Status = FlSplitInputPathname (Filename, &Gbl_DirectoryPath, NULL);
325*313a0c13SJung-uk Kim     if (ACPI_FAILURE (Status))
326*313a0c13SJung-uk Kim     {
327*313a0c13SJung-uk Kim         return (Status);
328*313a0c13SJung-uk Kim     }
329*313a0c13SJung-uk Kim 
330*313a0c13SJung-uk Kim     /* Take a copy of the input filename, convert any backslashes */
331*313a0c13SJung-uk Kim 
332*313a0c13SJung-uk Kim     Gbl_Files[ASL_FILE_INPUT].Filename =
333*313a0c13SJung-uk Kim         UtStringCacheCalloc (strlen (Filename) + 1);
334*313a0c13SJung-uk Kim 
335*313a0c13SJung-uk Kim     strcpy (Gbl_Files[ASL_FILE_INPUT].Filename, Filename);
336*313a0c13SJung-uk Kim     UtConvertBackslashes (Gbl_Files[ASL_FILE_INPUT].Filename);
337a9f12690SJung-uk Kim 
338a9f12690SJung-uk Kim     /*
339a9f12690SJung-uk Kim      * AML Disassembly (Optional)
340a9f12690SJung-uk Kim      */
341*313a0c13SJung-uk Kim     if (Gbl_DisasmFlag)
342a9f12690SJung-uk Kim     {
3439c48c75eSJung-uk Kim         Status = AslDoDisassembly ();
3449c48c75eSJung-uk Kim         if (Status != AE_CTRL_CONTINUE)
345a9f12690SJung-uk Kim         {
346a9f12690SJung-uk Kim             return (Status);
347a9f12690SJung-uk Kim         }
348a9f12690SJung-uk Kim     }
349a9f12690SJung-uk Kim 
350a9f12690SJung-uk Kim     /*
351a88e22b7SJung-uk Kim      * Open the input file. Here, this should be an ASCII source file,
352a88e22b7SJung-uk Kim      * either an ASL file or a Data Table file
353a9f12690SJung-uk Kim      */
354a88e22b7SJung-uk Kim     Status = FlOpenInputFile (Gbl_Files[ASL_FILE_INPUT].Filename);
355a88e22b7SJung-uk Kim     if (ACPI_FAILURE (Status))
356a9f12690SJung-uk Kim     {
357a88e22b7SJung-uk Kim         AePrintErrorLog (ASL_FILE_STDERR);
358a88e22b7SJung-uk Kim         return (AE_ERROR);
359a88e22b7SJung-uk Kim     }
360a88e22b7SJung-uk Kim 
361a88e22b7SJung-uk Kim     /* Determine input file type */
362a88e22b7SJung-uk Kim 
363a88e22b7SJung-uk Kim     Gbl_FileType = AslDetectSourceFileType (&Gbl_Files[ASL_FILE_INPUT]);
364a88e22b7SJung-uk Kim     if (Gbl_FileType == ASL_INPUT_TYPE_BINARY)
365a88e22b7SJung-uk Kim     {
366a88e22b7SJung-uk Kim         return (AE_ERROR);
367a88e22b7SJung-uk Kim     }
368a88e22b7SJung-uk Kim 
369a9f12690SJung-uk Kim     /*
370a9f12690SJung-uk Kim      * If -p not specified, we will use the input filename as the
371a9f12690SJung-uk Kim      * output filename prefix
372a9f12690SJung-uk Kim      */
373a9f12690SJung-uk Kim     if (Gbl_UseDefaultAmlFilename)
374a9f12690SJung-uk Kim     {
375a9f12690SJung-uk Kim         Gbl_OutputFilenamePrefix = Gbl_Files[ASL_FILE_INPUT].Filename;
376a9f12690SJung-uk Kim     }
377a9f12690SJung-uk Kim 
378a88e22b7SJung-uk Kim     /* Open the optional output files (listings, etc.) */
379a88e22b7SJung-uk Kim 
380a88e22b7SJung-uk Kim     Status = FlOpenMiscOutputFiles (Gbl_OutputFilenamePrefix);
381a88e22b7SJung-uk Kim     if (ACPI_FAILURE (Status))
382a88e22b7SJung-uk Kim     {
383a88e22b7SJung-uk Kim         AePrintErrorLog (ASL_FILE_STDERR);
384a88e22b7SJung-uk Kim         return (AE_ERROR);
385a88e22b7SJung-uk Kim     }
386a88e22b7SJung-uk Kim 
387a88e22b7SJung-uk Kim     /*
388a88e22b7SJung-uk Kim      * Compilation of ASL source versus DataTable source uses different
389a88e22b7SJung-uk Kim      * compiler subsystems
390a88e22b7SJung-uk Kim      */
391a88e22b7SJung-uk Kim     switch (Gbl_FileType)
392a88e22b7SJung-uk Kim     {
393a88e22b7SJung-uk Kim     /*
394a88e22b7SJung-uk Kim      * Data Table Compilation
395a88e22b7SJung-uk Kim      */
396a88e22b7SJung-uk Kim     case ASL_INPUT_TYPE_ASCII_DATA:
397a88e22b7SJung-uk Kim 
398a88e22b7SJung-uk Kim         Status = DtDoCompile ();
399eef1b955SJung-uk Kim         if (ACPI_FAILURE (Status))
400eef1b955SJung-uk Kim         {
401eef1b955SJung-uk Kim             return (Status);
402eef1b955SJung-uk Kim         }
403a88e22b7SJung-uk Kim 
404a88e22b7SJung-uk Kim         if (Gbl_Signature)
405a88e22b7SJung-uk Kim         {
406a88e22b7SJung-uk Kim             Gbl_Signature = NULL;
407a88e22b7SJung-uk Kim         }
408eef1b955SJung-uk Kim 
409eef1b955SJung-uk Kim         /* Check if any errors occurred during compile */
410eef1b955SJung-uk Kim 
411eef1b955SJung-uk Kim         Status = AslCheckForErrorExit ();
412eef1b955SJung-uk Kim         if (ACPI_FAILURE (Status))
413eef1b955SJung-uk Kim         {
414eef1b955SJung-uk Kim             return (Status);
415eef1b955SJung-uk Kim         }
416eef1b955SJung-uk Kim 
417eef1b955SJung-uk Kim         /* Cleanup (for next source file) and exit */
418eef1b955SJung-uk Kim 
419a88e22b7SJung-uk Kim         AeClearErrorLog ();
4204c52cad2SJung-uk Kim         PrTerminatePreprocessor ();
421a88e22b7SJung-uk Kim         return (Status);
422a88e22b7SJung-uk Kim 
423a88e22b7SJung-uk Kim     /*
424eef1b955SJung-uk Kim      * ASL Compilation
425a88e22b7SJung-uk Kim      */
426a88e22b7SJung-uk Kim     case ASL_INPUT_TYPE_ASCII_ASL:
427a88e22b7SJung-uk Kim 
428a88e22b7SJung-uk Kim         /* ACPICA subsystem initialization */
429a9f12690SJung-uk Kim 
430a9f12690SJung-uk Kim         Status = AdInitialize ();
431a9f12690SJung-uk Kim         if (ACPI_FAILURE (Status))
432a9f12690SJung-uk Kim         {
433a9f12690SJung-uk Kim             return (Status);
434a9f12690SJung-uk Kim         }
435a9f12690SJung-uk Kim 
436eef1b955SJung-uk Kim         (void) CmDoCompile ();
43742fecd12SJung-uk Kim         (void) AcpiTerminate ();
438a9f12690SJung-uk Kim 
439eef1b955SJung-uk Kim         /* Check if any errors occurred during compile */
440eef1b955SJung-uk Kim 
441eef1b955SJung-uk Kim         Status = AslCheckForErrorExit ();
442eef1b955SJung-uk Kim         if (ACPI_FAILURE (Status))
443a9f12690SJung-uk Kim         {
444eef1b955SJung-uk Kim             return (Status);
445a9f12690SJung-uk Kim         }
446a9f12690SJung-uk Kim 
447eef1b955SJung-uk Kim         /* Cleanup (for next source file) and exit */
448eef1b955SJung-uk Kim 
449a9f12690SJung-uk Kim         AeClearErrorLog ();
4504c52cad2SJung-uk Kim         PrTerminatePreprocessor ();
451a9f12690SJung-uk Kim         return (AE_OK);
452a88e22b7SJung-uk Kim 
4539c48c75eSJung-uk Kim     /*
4549c48c75eSJung-uk Kim      * Binary ACPI table was auto-detected, disassemble it
4559c48c75eSJung-uk Kim      */
4569c48c75eSJung-uk Kim     case ASL_INPUT_TYPE_ACPI_TABLE:
4579c48c75eSJung-uk Kim 
4589c48c75eSJung-uk Kim         /* We have what appears to be an ACPI table, disassemble it */
4599c48c75eSJung-uk Kim 
4609c48c75eSJung-uk Kim         FlCloseFile (ASL_FILE_INPUT);
4619c48c75eSJung-uk Kim         Gbl_DoCompile = FALSE;
4629c48c75eSJung-uk Kim         Gbl_DisasmFlag = TRUE;
4639c48c75eSJung-uk Kim         Status = AslDoDisassembly ();
4649c48c75eSJung-uk Kim         return (Status);
4659c48c75eSJung-uk Kim 
4669c48c75eSJung-uk Kim     /* Unknown binary table */
4679c48c75eSJung-uk Kim 
468a88e22b7SJung-uk Kim     case ASL_INPUT_TYPE_BINARY:
469a88e22b7SJung-uk Kim 
470a88e22b7SJung-uk Kim         AePrintErrorLog (ASL_FILE_STDERR);
471a88e22b7SJung-uk Kim         return (AE_ERROR);
472a88e22b7SJung-uk Kim 
473a88e22b7SJung-uk Kim     default:
474a9d8d09cSJung-uk Kim 
475a88e22b7SJung-uk Kim         printf ("Unknown file type %X\n", Gbl_FileType);
476a88e22b7SJung-uk Kim         return (AE_ERROR);
477a88e22b7SJung-uk Kim     }
478a9f12690SJung-uk Kim }
479a9f12690SJung-uk Kim 
480a9f12690SJung-uk Kim 
481a9f12690SJung-uk Kim /*******************************************************************************
482a9f12690SJung-uk Kim  *
483eef1b955SJung-uk Kim  * FUNCTION:    AslCheckForErrorExit
484eef1b955SJung-uk Kim  *
485eef1b955SJung-uk Kim  * PARAMETERS:  None. Examines global exception count array
486eef1b955SJung-uk Kim  *
487eef1b955SJung-uk Kim  * RETURN:      Status
488eef1b955SJung-uk Kim  *
489eef1b955SJung-uk Kim  * DESCRIPTION: Determine if compiler should abort with error status
490eef1b955SJung-uk Kim  *
491eef1b955SJung-uk Kim  ******************************************************************************/
492eef1b955SJung-uk Kim 
493eef1b955SJung-uk Kim ACPI_STATUS
494eef1b955SJung-uk Kim AslCheckForErrorExit (
495eef1b955SJung-uk Kim     void)
496eef1b955SJung-uk Kim {
497eef1b955SJung-uk Kim 
498eef1b955SJung-uk Kim     /*
499eef1b955SJung-uk Kim      * Return non-zero exit code if there have been errors, unless the
500eef1b955SJung-uk Kim      * global ignore error flag has been set
501eef1b955SJung-uk Kim      */
502eef1b955SJung-uk Kim     if (!Gbl_IgnoreErrors)
503eef1b955SJung-uk Kim     {
504eef1b955SJung-uk Kim         if (Gbl_ExceptionCount[ASL_ERROR] > 0)
505eef1b955SJung-uk Kim         {
506eef1b955SJung-uk Kim             return (AE_ERROR);
507eef1b955SJung-uk Kim         }
508eef1b955SJung-uk Kim 
509eef1b955SJung-uk Kim         /* Optionally treat warnings as errors */
510eef1b955SJung-uk Kim 
511eef1b955SJung-uk Kim         if (Gbl_WarningsAsErrors)
512eef1b955SJung-uk Kim         {
513eef1b955SJung-uk Kim             if ((Gbl_ExceptionCount[ASL_WARNING] > 0)  ||
514eef1b955SJung-uk Kim                 (Gbl_ExceptionCount[ASL_WARNING2] > 0) ||
515eef1b955SJung-uk Kim                 (Gbl_ExceptionCount[ASL_WARNING3] > 0))
516eef1b955SJung-uk Kim             {
517eef1b955SJung-uk Kim                 return (AE_ERROR);
518eef1b955SJung-uk Kim             }
519eef1b955SJung-uk Kim         }
520eef1b955SJung-uk Kim     }
521eef1b955SJung-uk Kim 
522eef1b955SJung-uk Kim     return (AE_OK);
523eef1b955SJung-uk Kim }
524