xref: /freebsd/sys/contrib/dev/acpica/compiler/aslstartup.c (revision 4c52cad2f9c8cd2b25d156455f9263616da1fb79)
1a9f12690SJung-uk Kim 
2a9f12690SJung-uk Kim /******************************************************************************
3a9f12690SJung-uk Kim  *
4a9f12690SJung-uk Kim  * Module Name: aslstartup - Compiler startup routines, called from main
5a9f12690SJung-uk Kim  *
6a9f12690SJung-uk Kim  *****************************************************************************/
7a9f12690SJung-uk Kim 
8d244b227SJung-uk Kim /*
9ec3fc72fSJung-uk Kim  * Copyright (C) 2000 - 2012, Intel Corp.
10a9f12690SJung-uk Kim  * All rights reserved.
11a9f12690SJung-uk Kim  *
12d244b227SJung-uk Kim  * Redistribution and use in source and binary forms, with or without
13d244b227SJung-uk Kim  * modification, are permitted provided that the following conditions
14d244b227SJung-uk Kim  * are met:
15d244b227SJung-uk Kim  * 1. Redistributions of source code must retain the above copyright
16d244b227SJung-uk Kim  *    notice, this list of conditions, and the following disclaimer,
17d244b227SJung-uk Kim  *    without modification.
18d244b227SJung-uk Kim  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19d244b227SJung-uk Kim  *    substantially similar to the "NO WARRANTY" disclaimer below
20d244b227SJung-uk Kim  *    ("Disclaimer") and any redistribution must be conditioned upon
21d244b227SJung-uk Kim  *    including a substantially similar Disclaimer requirement for further
22d244b227SJung-uk Kim  *    binary redistribution.
23d244b227SJung-uk Kim  * 3. Neither the names of the above-listed copyright holders nor the names
24d244b227SJung-uk Kim  *    of any contributors may be used to endorse or promote products derived
25d244b227SJung-uk Kim  *    from this software without specific prior written permission.
26a9f12690SJung-uk Kim  *
27d244b227SJung-uk Kim  * Alternatively, this software may be distributed under the terms of the
28d244b227SJung-uk Kim  * GNU General Public License ("GPL") version 2 as published by the Free
29d244b227SJung-uk Kim  * Software Foundation.
30a9f12690SJung-uk Kim  *
31d244b227SJung-uk Kim  * NO WARRANTY
32d244b227SJung-uk Kim  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33d244b227SJung-uk Kim  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34d244b227SJung-uk Kim  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35d244b227SJung-uk Kim  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36d244b227SJung-uk Kim  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37d244b227SJung-uk Kim  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38d244b227SJung-uk Kim  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39d244b227SJung-uk Kim  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40d244b227SJung-uk Kim  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41d244b227SJung-uk Kim  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42d244b227SJung-uk Kim  * POSSIBILITY OF SUCH DAMAGES.
43d244b227SJung-uk Kim  */
44a9f12690SJung-uk Kim 
45a9f12690SJung-uk Kim 
46ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h>
47ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/actables.h>
48ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acapps.h>
49a9f12690SJung-uk Kim 
50a9f12690SJung-uk Kim #define _COMPONENT          ACPI_COMPILER
51a9f12690SJung-uk Kim         ACPI_MODULE_NAME    ("aslstartup")
52a9f12690SJung-uk Kim 
53a9f12690SJung-uk Kim 
54a9f12690SJung-uk Kim #define ASL_MAX_FILES   256
5542fecd12SJung-uk Kim static char             *FileList[ASL_MAX_FILES];
5642fecd12SJung-uk Kim static BOOLEAN          AslToFile = TRUE;
57a9f12690SJung-uk Kim 
58a9f12690SJung-uk Kim 
59a9f12690SJung-uk Kim /* Local prototypes */
60a9f12690SJung-uk Kim 
61a9f12690SJung-uk Kim static char **
62a9f12690SJung-uk Kim AsDoWildcard (
63a9f12690SJung-uk Kim     char                    *DirectoryPathname,
64a9f12690SJung-uk Kim     char                    *FileSpecifier);
65a9f12690SJung-uk Kim 
6642fecd12SJung-uk Kim static UINT8
67a88e22b7SJung-uk Kim AslDetectSourceFileType (
68a88e22b7SJung-uk Kim     ASL_FILE_INFO           *Info);
69a88e22b7SJung-uk Kim 
70a9f12690SJung-uk Kim 
71a9f12690SJung-uk Kim /*******************************************************************************
72a9f12690SJung-uk Kim  *
73a9f12690SJung-uk Kim  * FUNCTION:    AslInitializeGlobals
74a9f12690SJung-uk Kim  *
75a9f12690SJung-uk Kim  * PARAMETERS:  None
76a9f12690SJung-uk Kim  *
77a9f12690SJung-uk Kim  * RETURN:      None
78a9f12690SJung-uk Kim  *
79a9f12690SJung-uk Kim  * DESCRIPTION: Re-initialize globals needed to restart the compiler. This
80a9f12690SJung-uk Kim  *              allows multiple files to be disassembled and/or compiled.
81a9f12690SJung-uk Kim  *
82a9f12690SJung-uk Kim  ******************************************************************************/
83a9f12690SJung-uk Kim 
84a88e22b7SJung-uk Kim void
85a9f12690SJung-uk Kim AslInitializeGlobals (
86a9f12690SJung-uk Kim     void)
87a9f12690SJung-uk Kim {
88a9f12690SJung-uk Kim     UINT32                  i;
89a9f12690SJung-uk Kim 
90a9f12690SJung-uk Kim 
91a9f12690SJung-uk Kim     /* Init compiler globals */
92a9f12690SJung-uk Kim 
93a9f12690SJung-uk Kim     Gbl_CurrentColumn = 0;
94a9f12690SJung-uk Kim     Gbl_CurrentLineNumber = 1;
95a9f12690SJung-uk Kim     Gbl_LogicalLineNumber = 1;
96a9f12690SJung-uk Kim     Gbl_CurrentLineOffset = 0;
97a88e22b7SJung-uk Kim     Gbl_InputFieldCount = 0;
98*4c52cad2SJung-uk Kim     Gbl_InputByteCount = 0;
99*4c52cad2SJung-uk Kim     Gbl_NsLookupCount = 0;
100a9f12690SJung-uk Kim     Gbl_LineBufPtr = Gbl_CurrentLineBuffer;
101a9f12690SJung-uk Kim 
102a9f12690SJung-uk Kim     Gbl_ErrorLog = NULL;
103a9f12690SJung-uk Kim     Gbl_NextError = NULL;
104a88e22b7SJung-uk Kim     Gbl_Signature = NULL;
105a88e22b7SJung-uk Kim     Gbl_FileType = 0;
106a9f12690SJung-uk Kim 
107*4c52cad2SJung-uk Kim     TotalExecutableOpcodes = 0;
108*4c52cad2SJung-uk Kim     TotalNamedObjects = 0;
109*4c52cad2SJung-uk Kim     TotalKeywords = 0;
110*4c52cad2SJung-uk Kim     TotalParseNodes = 0;
111*4c52cad2SJung-uk Kim     TotalMethods = 0;
112*4c52cad2SJung-uk Kim     TotalAllocations = 0;
113*4c52cad2SJung-uk Kim     TotalAllocated = 0;
114*4c52cad2SJung-uk Kim     TotalFolds = 0;
115*4c52cad2SJung-uk Kim 
116a9f12690SJung-uk Kim     AslGbl_NextEvent = 0;
117a9f12690SJung-uk Kim     for (i = 0; i < ASL_NUM_REPORT_LEVELS; i++)
118a9f12690SJung-uk Kim     {
119a9f12690SJung-uk Kim         Gbl_ExceptionCount[i] = 0;
120a9f12690SJung-uk Kim     }
121a9f12690SJung-uk Kim 
122*4c52cad2SJung-uk Kim     for (i = ASL_FILE_INPUT; i <= ASL_MAX_FILE_TYPE; i++)
123*4c52cad2SJung-uk Kim     {
124*4c52cad2SJung-uk Kim         Gbl_Files[i].Handle = NULL;
125*4c52cad2SJung-uk Kim         Gbl_Files[i].Filename = NULL;
126*4c52cad2SJung-uk Kim     }
127a9f12690SJung-uk Kim }
128a9f12690SJung-uk Kim 
129a9f12690SJung-uk Kim 
130a9f12690SJung-uk Kim /******************************************************************************
131a9f12690SJung-uk Kim  *
132a9f12690SJung-uk Kim  * FUNCTION:    AsDoWildcard
133a9f12690SJung-uk Kim  *
134a9f12690SJung-uk Kim  * PARAMETERS:  None
135a9f12690SJung-uk Kim  *
136a9f12690SJung-uk Kim  * RETURN:      None
137a9f12690SJung-uk Kim  *
138a9f12690SJung-uk Kim  * DESCRIPTION: Process files via wildcards. This function is for the Windows
139a9f12690SJung-uk Kim  *              case only.
140a9f12690SJung-uk Kim  *
141a9f12690SJung-uk Kim  ******************************************************************************/
142a9f12690SJung-uk Kim 
143a9f12690SJung-uk Kim static char **
144a9f12690SJung-uk Kim AsDoWildcard (
145a9f12690SJung-uk Kim     char                    *DirectoryPathname,
146a9f12690SJung-uk Kim     char                    *FileSpecifier)
147a9f12690SJung-uk Kim {
148a9f12690SJung-uk Kim #ifdef WIN32
149a9f12690SJung-uk Kim     void                    *DirInfo;
150a9f12690SJung-uk Kim     char                    *Filename;
15142fecd12SJung-uk Kim     int                     FileCount;
152a9f12690SJung-uk Kim 
153a9f12690SJung-uk Kim 
154a9f12690SJung-uk Kim     FileCount = 0;
155a9f12690SJung-uk Kim 
156a9f12690SJung-uk Kim     /* Open parent directory */
157a9f12690SJung-uk Kim 
158a9f12690SJung-uk Kim     DirInfo = AcpiOsOpenDirectory (DirectoryPathname, FileSpecifier, REQUEST_FILE_ONLY);
159a9f12690SJung-uk Kim     if (!DirInfo)
160a9f12690SJung-uk Kim     {
161a9f12690SJung-uk Kim         /* Either the directory of file does not exist */
162a9f12690SJung-uk Kim 
163a9f12690SJung-uk Kim         Gbl_Files[ASL_FILE_INPUT].Filename = FileSpecifier;
164a9f12690SJung-uk Kim         FlFileError (ASL_FILE_INPUT, ASL_MSG_OPEN);
165a9f12690SJung-uk Kim         AslAbort ();
166a9f12690SJung-uk Kim     }
167a9f12690SJung-uk Kim 
168a9f12690SJung-uk Kim     /* Process each file that matches the wildcard specification */
169a9f12690SJung-uk Kim 
170a9f12690SJung-uk Kim     while ((Filename = AcpiOsGetNextFilename (DirInfo)))
171a9f12690SJung-uk Kim     {
172a9f12690SJung-uk Kim         /* Add the filename to the file list */
173a9f12690SJung-uk Kim 
174a9f12690SJung-uk Kim         FileList[FileCount] = AcpiOsAllocate (strlen (Filename) + 1);
175a9f12690SJung-uk Kim         strcpy (FileList[FileCount], Filename);
176a9f12690SJung-uk Kim         FileCount++;
177a9f12690SJung-uk Kim 
178a9f12690SJung-uk Kim         if (FileCount >= ASL_MAX_FILES)
179a9f12690SJung-uk Kim         {
180a9f12690SJung-uk Kim             printf ("Max files reached\n");
181a9f12690SJung-uk Kim             FileList[0] = NULL;
182a9f12690SJung-uk Kim             return (FileList);
183a9f12690SJung-uk Kim         }
184a9f12690SJung-uk Kim     }
185a9f12690SJung-uk Kim 
186a9f12690SJung-uk Kim     /* Cleanup */
187a9f12690SJung-uk Kim 
188a9f12690SJung-uk Kim     AcpiOsCloseDirectory (DirInfo);
189a9f12690SJung-uk Kim     FileList[FileCount] = NULL;
190a9f12690SJung-uk Kim     return (FileList);
191a9f12690SJung-uk Kim 
192a9f12690SJung-uk Kim #else
193a9f12690SJung-uk Kim     /*
194a9f12690SJung-uk Kim      * Linux/Unix cases - Wildcards are expanded by the shell automatically.
195a9f12690SJung-uk Kim      * Just return the filename in a null terminated list
196a9f12690SJung-uk Kim      */
197a9f12690SJung-uk Kim     FileList[0] = AcpiOsAllocate (strlen (FileSpecifier) + 1);
198a9f12690SJung-uk Kim     strcpy (FileList[0], FileSpecifier);
199a9f12690SJung-uk Kim     FileList[1] = NULL;
200a9f12690SJung-uk Kim 
201a9f12690SJung-uk Kim     return (FileList);
202a9f12690SJung-uk Kim #endif
203a9f12690SJung-uk Kim }
204a9f12690SJung-uk Kim 
205a9f12690SJung-uk Kim 
206a9f12690SJung-uk Kim /*******************************************************************************
207a9f12690SJung-uk Kim  *
208a88e22b7SJung-uk Kim  * FUNCTION:    AslDetectSourceFileType
209a88e22b7SJung-uk Kim  *
210a88e22b7SJung-uk Kim  * PARAMETERS:  Info            - Name/Handle for the file (must be open)
211a88e22b7SJung-uk Kim  *
212a88e22b7SJung-uk Kim  * RETURN:      File Type
213a88e22b7SJung-uk Kim  *
214a88e22b7SJung-uk Kim  * DESCRIPTION: Determine the type of the input file. Either binary (contains
215a88e22b7SJung-uk Kim  *              non-ASCII characters), ASL file, or an ACPI Data Table file.
216a88e22b7SJung-uk Kim  *
217a88e22b7SJung-uk Kim  ******************************************************************************/
218a88e22b7SJung-uk Kim 
21942fecd12SJung-uk Kim static UINT8
220a88e22b7SJung-uk Kim AslDetectSourceFileType (
221a88e22b7SJung-uk Kim     ASL_FILE_INFO           *Info)
222a88e22b7SJung-uk Kim {
223a88e22b7SJung-uk Kim     char                    *FileChar;
224a88e22b7SJung-uk Kim     UINT8                   Type;
225a88e22b7SJung-uk Kim     ACPI_STATUS             Status;
226a88e22b7SJung-uk Kim 
227a88e22b7SJung-uk Kim 
228a88e22b7SJung-uk Kim     /* Check for 100% ASCII source file (comments are ignored) */
229a88e22b7SJung-uk Kim 
230a88e22b7SJung-uk Kim     Status = FlCheckForAscii (Info);
231a88e22b7SJung-uk Kim     if (ACPI_FAILURE (Status))
232a88e22b7SJung-uk Kim     {
233a88e22b7SJung-uk Kim         printf ("Non-ascii input file - %s\n", Info->Filename);
234a88e22b7SJung-uk Kim         Type = ASL_INPUT_TYPE_BINARY;
235a88e22b7SJung-uk Kim         goto Cleanup;
236a88e22b7SJung-uk Kim     }
237a88e22b7SJung-uk Kim 
238a88e22b7SJung-uk Kim     /*
239a88e22b7SJung-uk Kim      * File is ASCII. Determine if this is an ASL file or an ACPI data
240a88e22b7SJung-uk Kim      * table file.
241a88e22b7SJung-uk Kim      */
242a88e22b7SJung-uk Kim     while (fgets (Gbl_CurrentLineBuffer, ASL_LINE_BUFFER_SIZE, Info->Handle))
243a88e22b7SJung-uk Kim     {
244a88e22b7SJung-uk Kim         /* Uppercase the buffer for caseless compare */
245a88e22b7SJung-uk Kim 
246a88e22b7SJung-uk Kim         FileChar = Gbl_CurrentLineBuffer;
247a88e22b7SJung-uk Kim         while (*FileChar)
248a88e22b7SJung-uk Kim         {
249a88e22b7SJung-uk Kim             *FileChar = (char) toupper ((int) *FileChar);
250a88e22b7SJung-uk Kim             FileChar++;
251a88e22b7SJung-uk Kim         }
252a88e22b7SJung-uk Kim 
253a88e22b7SJung-uk Kim         /* Presence of "DefinitionBlock" indicates actual ASL code */
254a88e22b7SJung-uk Kim 
255a88e22b7SJung-uk Kim         if (strstr (Gbl_CurrentLineBuffer, "DEFINITIONBLOCK"))
256a88e22b7SJung-uk Kim         {
257a88e22b7SJung-uk Kim             /* Appears to be an ASL file */
258a88e22b7SJung-uk Kim 
259a88e22b7SJung-uk Kim             Type = ASL_INPUT_TYPE_ASCII_ASL;
260a88e22b7SJung-uk Kim             goto Cleanup;
261a88e22b7SJung-uk Kim         }
262a88e22b7SJung-uk Kim     }
263a88e22b7SJung-uk Kim 
264a88e22b7SJung-uk Kim     /* Not an ASL source file, default to a data table source file */
265a88e22b7SJung-uk Kim 
266a88e22b7SJung-uk Kim     Type = ASL_INPUT_TYPE_ASCII_DATA;
267a88e22b7SJung-uk Kim 
268a88e22b7SJung-uk Kim Cleanup:
269a88e22b7SJung-uk Kim 
270a88e22b7SJung-uk Kim     /* Must seek back to the start of the file */
271a88e22b7SJung-uk Kim 
272a88e22b7SJung-uk Kim     fseek (Info->Handle, 0, SEEK_SET);
273a88e22b7SJung-uk Kim     return (Type);
274a88e22b7SJung-uk Kim }
275a88e22b7SJung-uk Kim 
276a88e22b7SJung-uk Kim 
277a88e22b7SJung-uk Kim /*******************************************************************************
278a88e22b7SJung-uk Kim  *
279a9f12690SJung-uk Kim  * FUNCTION:    AslDoOneFile
280a9f12690SJung-uk Kim  *
281a9f12690SJung-uk Kim  * PARAMETERS:  Filename        - Name of the file
282a9f12690SJung-uk Kim  *
283a9f12690SJung-uk Kim  * RETURN:      Status
284a9f12690SJung-uk Kim  *
285a9f12690SJung-uk Kim  * DESCRIPTION: Process a single file - either disassemble, compile, or both
286a9f12690SJung-uk Kim  *
287a9f12690SJung-uk Kim  ******************************************************************************/
288a9f12690SJung-uk Kim 
289a9f12690SJung-uk Kim ACPI_STATUS
290a9f12690SJung-uk Kim AslDoOneFile (
291a9f12690SJung-uk Kim     char                    *Filename)
292a9f12690SJung-uk Kim {
293a9f12690SJung-uk Kim     ACPI_STATUS             Status;
294a9f12690SJung-uk Kim 
295a9f12690SJung-uk Kim 
296*4c52cad2SJung-uk Kim     /* Re-initialize "some" compiler/preprocessor globals */
297a9f12690SJung-uk Kim 
298a9f12690SJung-uk Kim     AslInitializeGlobals ();
299*4c52cad2SJung-uk Kim     PrInitializeGlobals ();
300*4c52cad2SJung-uk Kim 
301*4c52cad2SJung-uk Kim     Gbl_Files[ASL_FILE_INPUT].Filename = Filename;
302a9f12690SJung-uk Kim 
303a9f12690SJung-uk Kim     /*
304a9f12690SJung-uk Kim      * AML Disassembly (Optional)
305a9f12690SJung-uk Kim      */
306a9f12690SJung-uk Kim     if (Gbl_DisasmFlag || Gbl_GetAllTables)
307a9f12690SJung-uk Kim     {
308a9f12690SJung-uk Kim         /* ACPICA subsystem initialization */
309a9f12690SJung-uk Kim 
310a9f12690SJung-uk Kim         Status = AdInitialize ();
311a9f12690SJung-uk Kim         if (ACPI_FAILURE (Status))
312a9f12690SJung-uk Kim         {
313a9f12690SJung-uk Kim             return (Status);
314a9f12690SJung-uk Kim         }
315a9f12690SJung-uk Kim 
316a9f12690SJung-uk Kim         Status = AcpiAllocateRootTable (4);
317a9f12690SJung-uk Kim         if (ACPI_FAILURE (Status))
318a9f12690SJung-uk Kim         {
319a9f12690SJung-uk Kim             AcpiOsPrintf ("Could not initialize ACPI Table Manager, %s\n",
320a9f12690SJung-uk Kim                 AcpiFormatException (Status));
321a9f12690SJung-uk Kim             return (Status);
322a9f12690SJung-uk Kim         }
323a9f12690SJung-uk Kim 
324a9f12690SJung-uk Kim         /* This is where the disassembly happens */
325a9f12690SJung-uk Kim 
326a9f12690SJung-uk Kim         AcpiGbl_DbOpt_disasm = TRUE;
327a9f12690SJung-uk Kim         Status = AdAmlDisassemble (AslToFile,
328a9f12690SJung-uk Kim                     Gbl_Files[ASL_FILE_INPUT].Filename,
329a9f12690SJung-uk Kim                     Gbl_OutputFilenamePrefix,
330a9f12690SJung-uk Kim                     &Gbl_Files[ASL_FILE_INPUT].Filename,
331a9f12690SJung-uk Kim                     Gbl_GetAllTables);
332a9f12690SJung-uk Kim         if (ACPI_FAILURE (Status))
333a9f12690SJung-uk Kim         {
334a9f12690SJung-uk Kim             return (Status);
335a9f12690SJung-uk Kim         }
336a9f12690SJung-uk Kim 
337a9f12690SJung-uk Kim         /* Shutdown compiler and ACPICA subsystem */
338a9f12690SJung-uk Kim 
339a9f12690SJung-uk Kim         AeClearErrorLog ();
34042fecd12SJung-uk Kim         (void) AcpiTerminate ();
341a9f12690SJung-uk Kim 
342a9f12690SJung-uk Kim         /*
343a9f12690SJung-uk Kim          * Gbl_Files[ASL_FILE_INPUT].Filename was replaced with the
344a9f12690SJung-uk Kim          * .DSL disassembly file, which can now be compiled if requested
345a9f12690SJung-uk Kim          */
346a9f12690SJung-uk Kim         if (Gbl_DoCompile)
347a9f12690SJung-uk Kim         {
348a9f12690SJung-uk Kim             AcpiOsPrintf ("\nCompiling \"%s\"\n",
349a9f12690SJung-uk Kim                 Gbl_Files[ASL_FILE_INPUT].Filename);
350a9f12690SJung-uk Kim         }
351a88e22b7SJung-uk Kim         else
352a88e22b7SJung-uk Kim         {
353a88e22b7SJung-uk Kim             Gbl_Files[ASL_FILE_INPUT].Filename = NULL;
354a88e22b7SJung-uk Kim             return (AE_OK);
355a88e22b7SJung-uk Kim         }
356a9f12690SJung-uk Kim     }
357a9f12690SJung-uk Kim 
358a9f12690SJung-uk Kim     /*
359a88e22b7SJung-uk Kim      * Open the input file. Here, this should be an ASCII source file,
360a88e22b7SJung-uk Kim      * either an ASL file or a Data Table file
361a9f12690SJung-uk Kim      */
362a88e22b7SJung-uk Kim     Status = FlOpenInputFile (Gbl_Files[ASL_FILE_INPUT].Filename);
363a88e22b7SJung-uk Kim     if (ACPI_FAILURE (Status))
364a9f12690SJung-uk Kim     {
365a88e22b7SJung-uk Kim         AePrintErrorLog (ASL_FILE_STDERR);
366a88e22b7SJung-uk Kim         return (AE_ERROR);
367a88e22b7SJung-uk Kim     }
368a88e22b7SJung-uk Kim 
369a88e22b7SJung-uk Kim     /* Determine input file type */
370a88e22b7SJung-uk Kim 
371a88e22b7SJung-uk Kim     Gbl_FileType = AslDetectSourceFileType (&Gbl_Files[ASL_FILE_INPUT]);
372a88e22b7SJung-uk Kim     if (Gbl_FileType == ASL_INPUT_TYPE_BINARY)
373a88e22b7SJung-uk Kim     {
374a88e22b7SJung-uk Kim         return (AE_ERROR);
375a88e22b7SJung-uk Kim     }
376a88e22b7SJung-uk Kim 
377a9f12690SJung-uk Kim     /*
378a9f12690SJung-uk Kim      * If -p not specified, we will use the input filename as the
379a9f12690SJung-uk Kim      * output filename prefix
380a9f12690SJung-uk Kim      */
381a9f12690SJung-uk Kim     if (Gbl_UseDefaultAmlFilename)
382a9f12690SJung-uk Kim     {
383a9f12690SJung-uk Kim         Gbl_OutputFilenamePrefix = Gbl_Files[ASL_FILE_INPUT].Filename;
384a9f12690SJung-uk Kim     }
385a9f12690SJung-uk Kim 
386a88e22b7SJung-uk Kim     /* Open the optional output files (listings, etc.) */
387a88e22b7SJung-uk Kim 
388a88e22b7SJung-uk Kim     Status = FlOpenMiscOutputFiles (Gbl_OutputFilenamePrefix);
389a88e22b7SJung-uk Kim     if (ACPI_FAILURE (Status))
390a88e22b7SJung-uk Kim     {
391a88e22b7SJung-uk Kim         AePrintErrorLog (ASL_FILE_STDERR);
392a88e22b7SJung-uk Kim         return (AE_ERROR);
393a88e22b7SJung-uk Kim     }
394a88e22b7SJung-uk Kim 
395a88e22b7SJung-uk Kim     /*
396a88e22b7SJung-uk Kim      * Compilation of ASL source versus DataTable source uses different
397a88e22b7SJung-uk Kim      * compiler subsystems
398a88e22b7SJung-uk Kim      */
399a88e22b7SJung-uk Kim     switch (Gbl_FileType)
400a88e22b7SJung-uk Kim     {
401a88e22b7SJung-uk Kim     /*
402a88e22b7SJung-uk Kim      * Data Table Compilation
403a88e22b7SJung-uk Kim      */
404a88e22b7SJung-uk Kim     case ASL_INPUT_TYPE_ASCII_DATA:
405a88e22b7SJung-uk Kim 
406a88e22b7SJung-uk Kim         Status = DtDoCompile ();
407a88e22b7SJung-uk Kim 
408a88e22b7SJung-uk Kim         if (Gbl_Signature)
409a88e22b7SJung-uk Kim         {
410a88e22b7SJung-uk Kim             ACPI_FREE (Gbl_Signature);
411a88e22b7SJung-uk Kim             Gbl_Signature = NULL;
412a88e22b7SJung-uk Kim         }
413a88e22b7SJung-uk Kim         AeClearErrorLog ();
414*4c52cad2SJung-uk Kim         PrTerminatePreprocessor ();
415a88e22b7SJung-uk Kim         return (Status);
416a88e22b7SJung-uk Kim 
417a88e22b7SJung-uk Kim     /*
418a88e22b7SJung-uk Kim      * ASL Compilation (Optional)
419a88e22b7SJung-uk Kim      */
420a88e22b7SJung-uk Kim     case ASL_INPUT_TYPE_ASCII_ASL:
421a88e22b7SJung-uk Kim 
422a88e22b7SJung-uk Kim         /* ACPICA subsystem initialization */
423a9f12690SJung-uk Kim 
424a9f12690SJung-uk Kim         Status = AdInitialize ();
425a9f12690SJung-uk Kim         if (ACPI_FAILURE (Status))
426a9f12690SJung-uk Kim         {
427a9f12690SJung-uk Kim             return (Status);
428a9f12690SJung-uk Kim         }
429a9f12690SJung-uk Kim 
430a9f12690SJung-uk Kim         Status = CmDoCompile ();
43142fecd12SJung-uk Kim         (void) AcpiTerminate ();
432a9f12690SJung-uk Kim 
433a9f12690SJung-uk Kim         /*
434a9f12690SJung-uk Kim          * Return non-zero exit code if there have been errors, unless the
435a9f12690SJung-uk Kim          * global ignore error flag has been set
436a9f12690SJung-uk Kim          */
437a9f12690SJung-uk Kim         if ((Gbl_ExceptionCount[ASL_ERROR] > 0) && (!Gbl_IgnoreErrors))
438a9f12690SJung-uk Kim         {
439a9f12690SJung-uk Kim             return (AE_ERROR);
440a9f12690SJung-uk Kim         }
441a9f12690SJung-uk Kim 
442a9f12690SJung-uk Kim         AeClearErrorLog ();
443*4c52cad2SJung-uk Kim         PrTerminatePreprocessor ();
444a9f12690SJung-uk Kim         return (AE_OK);
445a88e22b7SJung-uk Kim 
446a88e22b7SJung-uk Kim     case ASL_INPUT_TYPE_BINARY:
447a88e22b7SJung-uk Kim 
448a88e22b7SJung-uk Kim         AePrintErrorLog (ASL_FILE_STDERR);
449a88e22b7SJung-uk Kim         return (AE_ERROR);
450a88e22b7SJung-uk Kim 
451a88e22b7SJung-uk Kim     default:
452a88e22b7SJung-uk Kim         printf ("Unknown file type %X\n", Gbl_FileType);
453a88e22b7SJung-uk Kim         return (AE_ERROR);
454a88e22b7SJung-uk Kim     }
455a9f12690SJung-uk Kim }
456a9f12690SJung-uk Kim 
457a9f12690SJung-uk Kim 
458a9f12690SJung-uk Kim /*******************************************************************************
459a9f12690SJung-uk Kim  *
460a9f12690SJung-uk Kim  * FUNCTION:    AslDoOnePathname
461a9f12690SJung-uk Kim  *
462a9f12690SJung-uk Kim  * PARAMETERS:  Pathname            - Full pathname, possibly with wildcards
463a9f12690SJung-uk Kim  *
464a9f12690SJung-uk Kim  * RETURN:      Status
465a9f12690SJung-uk Kim  *
466a9f12690SJung-uk Kim  * DESCRIPTION: Process one pathname, possible terminated with a wildcard
467a9f12690SJung-uk Kim  *              specification. If a wildcard, it is expanded and the multiple
468a9f12690SJung-uk Kim  *              files are processed.
469a9f12690SJung-uk Kim  *
470a9f12690SJung-uk Kim  ******************************************************************************/
471a9f12690SJung-uk Kim 
472a9f12690SJung-uk Kim ACPI_STATUS
473a9f12690SJung-uk Kim AslDoOnePathname (
474709fac06SJung-uk Kim     char                    *Pathname,
475709fac06SJung-uk Kim     ASL_PATHNAME_CALLBACK   PathCallback)
476a9f12690SJung-uk Kim {
477a88e22b7SJung-uk Kim     ACPI_STATUS             Status = AE_OK;
47842fecd12SJung-uk Kim     char                    **WildcardList;
479a9f12690SJung-uk Kim     char                    *Filename;
480a9f12690SJung-uk Kim     char                    *FullPathname;
481a9f12690SJung-uk Kim 
482a9f12690SJung-uk Kim 
483a9f12690SJung-uk Kim     /* Split incoming path into a directory/filename combo */
484a9f12690SJung-uk Kim 
485a9f12690SJung-uk Kim     Status = FlSplitInputPathname (Pathname, &Gbl_DirectoryPath, &Filename);
486a9f12690SJung-uk Kim     if (ACPI_FAILURE (Status))
487a9f12690SJung-uk Kim     {
488a9f12690SJung-uk Kim         return (Status);
489a9f12690SJung-uk Kim     }
490a9f12690SJung-uk Kim 
491a9f12690SJung-uk Kim     /* Expand possible wildcard into a file list (Windows/DOS only) */
492a9f12690SJung-uk Kim 
49342fecd12SJung-uk Kim     WildcardList = AsDoWildcard (Gbl_DirectoryPath, Filename);
49442fecd12SJung-uk Kim     while (*WildcardList)
495a9f12690SJung-uk Kim     {
496a9f12690SJung-uk Kim         FullPathname = ACPI_ALLOCATE (
49742fecd12SJung-uk Kim             strlen (Gbl_DirectoryPath) + strlen (*WildcardList) + 1);
498a9f12690SJung-uk Kim 
499a9f12690SJung-uk Kim         /* Construct a full path to the file */
500a9f12690SJung-uk Kim 
501a9f12690SJung-uk Kim         strcpy (FullPathname, Gbl_DirectoryPath);
50242fecd12SJung-uk Kim         strcat (FullPathname, *WildcardList);
503a9f12690SJung-uk Kim 
504a9f12690SJung-uk Kim         /*
505a9f12690SJung-uk Kim          * If -p not specified, we will use the input filename as the
506a9f12690SJung-uk Kim          * output filename prefix
507a9f12690SJung-uk Kim          */
508a9f12690SJung-uk Kim         if (Gbl_UseDefaultAmlFilename)
509a9f12690SJung-uk Kim         {
510a9f12690SJung-uk Kim             Gbl_OutputFilenamePrefix = FullPathname;
511a9f12690SJung-uk Kim         }
512a9f12690SJung-uk Kim 
513a88e22b7SJung-uk Kim         /* Save status from all compiles */
514a88e22b7SJung-uk Kim 
515709fac06SJung-uk Kim         Status |= (*PathCallback) (FullPathname);
516a9f12690SJung-uk Kim 
517a9f12690SJung-uk Kim         ACPI_FREE (FullPathname);
51842fecd12SJung-uk Kim         ACPI_FREE (*WildcardList);
51942fecd12SJung-uk Kim         *WildcardList = NULL;
52042fecd12SJung-uk Kim         WildcardList++;
521a9f12690SJung-uk Kim     }
522a9f12690SJung-uk Kim 
523a9f12690SJung-uk Kim     ACPI_FREE (Gbl_DirectoryPath);
524a9f12690SJung-uk Kim     ACPI_FREE (Filename);
525a88e22b7SJung-uk Kim     return (Status);
526a9f12690SJung-uk Kim }
527a9f12690SJung-uk Kim 
528