xref: /freebsd/sys/contrib/dev/acpica/compiler/aslstartup.c (revision 42fecd1294987e8ba9dc23c31c3f55307aca6406)
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 
8a9f12690SJung-uk Kim /******************************************************************************
9a9f12690SJung-uk Kim  *
10a9f12690SJung-uk Kim  * 1. Copyright Notice
11a9f12690SJung-uk Kim  *
129a179dd8SJung-uk Kim  * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
13a9f12690SJung-uk Kim  * All rights reserved.
14a9f12690SJung-uk Kim  *
15a9f12690SJung-uk Kim  * 2. License
16a9f12690SJung-uk Kim  *
17a9f12690SJung-uk Kim  * 2.1. This is your license from Intel Corp. under its intellectual property
18a9f12690SJung-uk Kim  * rights.  You may have additional license terms from the party that provided
19a9f12690SJung-uk Kim  * you this software, covering your right to use that party's intellectual
20a9f12690SJung-uk Kim  * property rights.
21a9f12690SJung-uk Kim  *
22a9f12690SJung-uk Kim  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23a9f12690SJung-uk Kim  * copy of the source code appearing in this file ("Covered Code") an
24a9f12690SJung-uk Kim  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25a9f12690SJung-uk Kim  * base code distributed originally by Intel ("Original Intel Code") to copy,
26a9f12690SJung-uk Kim  * make derivatives, distribute, use and display any portion of the Covered
27a9f12690SJung-uk Kim  * Code in any form, with the right to sublicense such rights; and
28a9f12690SJung-uk Kim  *
29a9f12690SJung-uk Kim  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30a9f12690SJung-uk Kim  * license (with the right to sublicense), under only those claims of Intel
31a9f12690SJung-uk Kim  * patents that are infringed by the Original Intel Code, to make, use, sell,
32a9f12690SJung-uk Kim  * offer to sell, and import the Covered Code and derivative works thereof
33a9f12690SJung-uk Kim  * solely to the minimum extent necessary to exercise the above copyright
34a9f12690SJung-uk Kim  * license, and in no event shall the patent license extend to any additions
35a9f12690SJung-uk Kim  * to or modifications of the Original Intel Code.  No other license or right
36a9f12690SJung-uk Kim  * is granted directly or by implication, estoppel or otherwise;
37a9f12690SJung-uk Kim  *
38a9f12690SJung-uk Kim  * The above copyright and patent license is granted only if the following
39a9f12690SJung-uk Kim  * conditions are met:
40a9f12690SJung-uk Kim  *
41a9f12690SJung-uk Kim  * 3. Conditions
42a9f12690SJung-uk Kim  *
43a9f12690SJung-uk Kim  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44a9f12690SJung-uk Kim  * Redistribution of source code of any substantial portion of the Covered
45a9f12690SJung-uk Kim  * Code or modification with rights to further distribute source must include
46a9f12690SJung-uk Kim  * the above Copyright Notice, the above License, this list of Conditions,
47a9f12690SJung-uk Kim  * and the following Disclaimer and Export Compliance provision.  In addition,
48a9f12690SJung-uk Kim  * Licensee must cause all Covered Code to which Licensee contributes to
49a9f12690SJung-uk Kim  * contain a file documenting the changes Licensee made to create that Covered
50a9f12690SJung-uk Kim  * Code and the date of any change.  Licensee must include in that file the
51a9f12690SJung-uk Kim  * documentation of any changes made by any predecessor Licensee.  Licensee
52a9f12690SJung-uk Kim  * must include a prominent statement that the modification is derived,
53a9f12690SJung-uk Kim  * directly or indirectly, from Original Intel Code.
54a9f12690SJung-uk Kim  *
55a9f12690SJung-uk Kim  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56a9f12690SJung-uk Kim  * Redistribution of source code of any substantial portion of the Covered
57a9f12690SJung-uk Kim  * Code or modification without rights to further distribute source must
58a9f12690SJung-uk Kim  * include the following Disclaimer and Export Compliance provision in the
59a9f12690SJung-uk Kim  * documentation and/or other materials provided with distribution.  In
60a9f12690SJung-uk Kim  * addition, Licensee may not authorize further sublicense of source of any
61a9f12690SJung-uk Kim  * portion of the Covered Code, and must include terms to the effect that the
62a9f12690SJung-uk Kim  * license from Licensee to its licensee is limited to the intellectual
63a9f12690SJung-uk Kim  * property embodied in the software Licensee provides to its licensee, and
64a9f12690SJung-uk Kim  * not to intellectual property embodied in modifications its licensee may
65a9f12690SJung-uk Kim  * make.
66a9f12690SJung-uk Kim  *
67a9f12690SJung-uk Kim  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68a9f12690SJung-uk Kim  * substantial portion of the Covered Code or modification must reproduce the
69a9f12690SJung-uk Kim  * above Copyright Notice, and the following Disclaimer and Export Compliance
70a9f12690SJung-uk Kim  * provision in the documentation and/or other materials provided with the
71a9f12690SJung-uk Kim  * distribution.
72a9f12690SJung-uk Kim  *
73a9f12690SJung-uk Kim  * 3.4. Intel retains all right, title, and interest in and to the Original
74a9f12690SJung-uk Kim  * Intel Code.
75a9f12690SJung-uk Kim  *
76a9f12690SJung-uk Kim  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77a9f12690SJung-uk Kim  * Intel shall be used in advertising or otherwise to promote the sale, use or
78a9f12690SJung-uk Kim  * other dealings in products derived from or relating to the Covered Code
79a9f12690SJung-uk Kim  * without prior written authorization from Intel.
80a9f12690SJung-uk Kim  *
81a9f12690SJung-uk Kim  * 4. Disclaimer and Export Compliance
82a9f12690SJung-uk Kim  *
83a9f12690SJung-uk Kim  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84a9f12690SJung-uk Kim  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85a9f12690SJung-uk Kim  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86a9f12690SJung-uk Kim  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87a9f12690SJung-uk Kim  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88a9f12690SJung-uk Kim  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89a9f12690SJung-uk Kim  * PARTICULAR PURPOSE.
90a9f12690SJung-uk Kim  *
91a9f12690SJung-uk Kim  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92a9f12690SJung-uk Kim  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93a9f12690SJung-uk Kim  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94a9f12690SJung-uk Kim  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95a9f12690SJung-uk Kim  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96a9f12690SJung-uk Kim  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97a9f12690SJung-uk Kim  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98a9f12690SJung-uk Kim  * LIMITED REMEDY.
99a9f12690SJung-uk Kim  *
100a9f12690SJung-uk Kim  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101a9f12690SJung-uk Kim  * software or system incorporating such software without first obtaining any
102a9f12690SJung-uk Kim  * required license or other approval from the U. S. Department of Commerce or
103a9f12690SJung-uk Kim  * any other agency or department of the United States Government.  In the
104a9f12690SJung-uk Kim  * event Licensee exports any such software from the United States or
105a9f12690SJung-uk Kim  * re-exports any such software from a foreign destination, Licensee shall
106a9f12690SJung-uk Kim  * ensure that the distribution and export/re-export of the software is in
107a9f12690SJung-uk Kim  * compliance with all laws, regulations, orders, or other restrictions of the
108a9f12690SJung-uk Kim  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109a9f12690SJung-uk Kim  * any of its subsidiaries will export/re-export any technical data, process,
110a9f12690SJung-uk Kim  * software, or service, directly or indirectly, to any country for which the
111a9f12690SJung-uk Kim  * United States government or any agency thereof requires an export license,
112a9f12690SJung-uk Kim  * other governmental approval, or letter of assurance, without first obtaining
113a9f12690SJung-uk Kim  * such license, approval or letter.
114a9f12690SJung-uk Kim  *
115a9f12690SJung-uk Kim  *****************************************************************************/
116a9f12690SJung-uk Kim 
117a9f12690SJung-uk Kim 
118ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h>
119ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/actables.h>
120ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acapps.h>
121a9f12690SJung-uk Kim 
122a9f12690SJung-uk Kim #define _COMPONENT          ACPI_COMPILER
123a9f12690SJung-uk Kim         ACPI_MODULE_NAME    ("aslstartup")
124a9f12690SJung-uk Kim 
125a9f12690SJung-uk Kim 
126a9f12690SJung-uk Kim #define ASL_MAX_FILES   256
127*42fecd12SJung-uk Kim static char             *FileList[ASL_MAX_FILES];
128*42fecd12SJung-uk Kim static BOOLEAN          AslToFile = TRUE;
129a9f12690SJung-uk Kim 
130a9f12690SJung-uk Kim 
131a9f12690SJung-uk Kim /* Local prototypes */
132a9f12690SJung-uk Kim 
133a9f12690SJung-uk Kim static char **
134a9f12690SJung-uk Kim AsDoWildcard (
135a9f12690SJung-uk Kim     char                    *DirectoryPathname,
136a9f12690SJung-uk Kim     char                    *FileSpecifier);
137a9f12690SJung-uk Kim 
138*42fecd12SJung-uk Kim static UINT8
139a88e22b7SJung-uk Kim AslDetectSourceFileType (
140a88e22b7SJung-uk Kim     ASL_FILE_INFO           *Info);
141a88e22b7SJung-uk Kim 
142a9f12690SJung-uk Kim 
143a9f12690SJung-uk Kim /*******************************************************************************
144a9f12690SJung-uk Kim  *
145a9f12690SJung-uk Kim  * FUNCTION:    AslInitializeGlobals
146a9f12690SJung-uk Kim  *
147a9f12690SJung-uk Kim  * PARAMETERS:  None
148a9f12690SJung-uk Kim  *
149a9f12690SJung-uk Kim  * RETURN:      None
150a9f12690SJung-uk Kim  *
151a9f12690SJung-uk Kim  * DESCRIPTION: Re-initialize globals needed to restart the compiler. This
152a9f12690SJung-uk Kim  *              allows multiple files to be disassembled and/or compiled.
153a9f12690SJung-uk Kim  *
154a9f12690SJung-uk Kim  ******************************************************************************/
155a9f12690SJung-uk Kim 
156a88e22b7SJung-uk Kim void
157a9f12690SJung-uk Kim AslInitializeGlobals (
158a9f12690SJung-uk Kim     void)
159a9f12690SJung-uk Kim {
160a9f12690SJung-uk Kim     UINT32                  i;
161a9f12690SJung-uk Kim 
162a9f12690SJung-uk Kim 
163a9f12690SJung-uk Kim     /* Init compiler globals */
164a9f12690SJung-uk Kim 
165a9f12690SJung-uk Kim     Gbl_CurrentColumn = 0;
166a9f12690SJung-uk Kim     Gbl_CurrentLineNumber = 1;
167a9f12690SJung-uk Kim     Gbl_LogicalLineNumber = 1;
168a9f12690SJung-uk Kim     Gbl_CurrentLineOffset = 0;
169a88e22b7SJung-uk Kim     Gbl_InputFieldCount = 0;
170a9f12690SJung-uk Kim     Gbl_LineBufPtr = Gbl_CurrentLineBuffer;
171a9f12690SJung-uk Kim 
172a9f12690SJung-uk Kim     Gbl_ErrorLog = NULL;
173a9f12690SJung-uk Kim     Gbl_NextError = NULL;
174a88e22b7SJung-uk Kim     Gbl_Signature = NULL;
175a88e22b7SJung-uk Kim     Gbl_FileType = 0;
176a9f12690SJung-uk Kim 
177a9f12690SJung-uk Kim     AslGbl_NextEvent = 0;
178a9f12690SJung-uk Kim     for (i = 0; i < ASL_NUM_REPORT_LEVELS; i++)
179a9f12690SJung-uk Kim     {
180a9f12690SJung-uk Kim         Gbl_ExceptionCount[i] = 0;
181a9f12690SJung-uk Kim     }
182a9f12690SJung-uk Kim 
183a9f12690SJung-uk Kim     Gbl_Files[ASL_FILE_AML_OUTPUT].Filename = NULL;
184a88e22b7SJung-uk Kim     Gbl_Files[ASL_FILE_AML_OUTPUT].Handle = NULL;
185a88e22b7SJung-uk Kim 
186a88e22b7SJung-uk Kim     Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename = NULL;
187a88e22b7SJung-uk Kim     Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle = NULL;
188a9f12690SJung-uk Kim }
189a9f12690SJung-uk Kim 
190a9f12690SJung-uk Kim 
191a9f12690SJung-uk Kim /******************************************************************************
192a9f12690SJung-uk Kim  *
193a9f12690SJung-uk Kim  * FUNCTION:    AsDoWildcard
194a9f12690SJung-uk Kim  *
195a9f12690SJung-uk Kim  * PARAMETERS:  None
196a9f12690SJung-uk Kim  *
197a9f12690SJung-uk Kim  * RETURN:      None
198a9f12690SJung-uk Kim  *
199a9f12690SJung-uk Kim  * DESCRIPTION: Process files via wildcards. This function is for the Windows
200a9f12690SJung-uk Kim  *              case only.
201a9f12690SJung-uk Kim  *
202a9f12690SJung-uk Kim  ******************************************************************************/
203a9f12690SJung-uk Kim 
204a9f12690SJung-uk Kim static char **
205a9f12690SJung-uk Kim AsDoWildcard (
206a9f12690SJung-uk Kim     char                    *DirectoryPathname,
207a9f12690SJung-uk Kim     char                    *FileSpecifier)
208a9f12690SJung-uk Kim {
209a9f12690SJung-uk Kim #ifdef WIN32
210a9f12690SJung-uk Kim     void                    *DirInfo;
211a9f12690SJung-uk Kim     char                    *Filename;
212*42fecd12SJung-uk Kim     int                     FileCount;
213a9f12690SJung-uk Kim 
214a9f12690SJung-uk Kim 
215a9f12690SJung-uk Kim     FileCount = 0;
216a9f12690SJung-uk Kim 
217a9f12690SJung-uk Kim     /* Open parent directory */
218a9f12690SJung-uk Kim 
219a9f12690SJung-uk Kim     DirInfo = AcpiOsOpenDirectory (DirectoryPathname, FileSpecifier, REQUEST_FILE_ONLY);
220a9f12690SJung-uk Kim     if (!DirInfo)
221a9f12690SJung-uk Kim     {
222a9f12690SJung-uk Kim         /* Either the directory of file does not exist */
223a9f12690SJung-uk Kim 
224a9f12690SJung-uk Kim         Gbl_Files[ASL_FILE_INPUT].Filename = FileSpecifier;
225a9f12690SJung-uk Kim         FlFileError (ASL_FILE_INPUT, ASL_MSG_OPEN);
226a9f12690SJung-uk Kim         AslAbort ();
227a9f12690SJung-uk Kim     }
228a9f12690SJung-uk Kim 
229a9f12690SJung-uk Kim     /* Process each file that matches the wildcard specification */
230a9f12690SJung-uk Kim 
231a9f12690SJung-uk Kim     while ((Filename = AcpiOsGetNextFilename (DirInfo)))
232a9f12690SJung-uk Kim     {
233a9f12690SJung-uk Kim         /* Add the filename to the file list */
234a9f12690SJung-uk Kim 
235a9f12690SJung-uk Kim         FileList[FileCount] = AcpiOsAllocate (strlen (Filename) + 1);
236a9f12690SJung-uk Kim         strcpy (FileList[FileCount], Filename);
237a9f12690SJung-uk Kim         FileCount++;
238a9f12690SJung-uk Kim 
239a9f12690SJung-uk Kim         if (FileCount >= ASL_MAX_FILES)
240a9f12690SJung-uk Kim         {
241a9f12690SJung-uk Kim             printf ("Max files reached\n");
242a9f12690SJung-uk Kim             FileList[0] = NULL;
243a9f12690SJung-uk Kim             return (FileList);
244a9f12690SJung-uk Kim         }
245a9f12690SJung-uk Kim     }
246a9f12690SJung-uk Kim 
247a9f12690SJung-uk Kim     /* Cleanup */
248a9f12690SJung-uk Kim 
249a9f12690SJung-uk Kim     AcpiOsCloseDirectory (DirInfo);
250a9f12690SJung-uk Kim     FileList[FileCount] = NULL;
251a9f12690SJung-uk Kim     return (FileList);
252a9f12690SJung-uk Kim 
253a9f12690SJung-uk Kim #else
254a9f12690SJung-uk Kim     /*
255a9f12690SJung-uk Kim      * Linux/Unix cases - Wildcards are expanded by the shell automatically.
256a9f12690SJung-uk Kim      * Just return the filename in a null terminated list
257a9f12690SJung-uk Kim      */
258a9f12690SJung-uk Kim     FileList[0] = AcpiOsAllocate (strlen (FileSpecifier) + 1);
259a9f12690SJung-uk Kim     strcpy (FileList[0], FileSpecifier);
260a9f12690SJung-uk Kim     FileList[1] = NULL;
261a9f12690SJung-uk Kim 
262a9f12690SJung-uk Kim     return (FileList);
263a9f12690SJung-uk Kim #endif
264a9f12690SJung-uk Kim }
265a9f12690SJung-uk Kim 
266a9f12690SJung-uk Kim 
267a9f12690SJung-uk Kim /*******************************************************************************
268a9f12690SJung-uk Kim  *
269a88e22b7SJung-uk Kim  * FUNCTION:    AslDetectSourceFileType
270a88e22b7SJung-uk Kim  *
271a88e22b7SJung-uk Kim  * PARAMETERS:  Info            - Name/Handle for the file (must be open)
272a88e22b7SJung-uk Kim  *
273a88e22b7SJung-uk Kim  * RETURN:      File Type
274a88e22b7SJung-uk Kim  *
275a88e22b7SJung-uk Kim  * DESCRIPTION: Determine the type of the input file. Either binary (contains
276a88e22b7SJung-uk Kim  *              non-ASCII characters), ASL file, or an ACPI Data Table file.
277a88e22b7SJung-uk Kim  *
278a88e22b7SJung-uk Kim  ******************************************************************************/
279a88e22b7SJung-uk Kim 
280*42fecd12SJung-uk Kim static UINT8
281a88e22b7SJung-uk Kim AslDetectSourceFileType (
282a88e22b7SJung-uk Kim     ASL_FILE_INFO           *Info)
283a88e22b7SJung-uk Kim {
284a88e22b7SJung-uk Kim     char                    *FileChar;
285a88e22b7SJung-uk Kim     UINT8                   Type;
286a88e22b7SJung-uk Kim     ACPI_STATUS             Status;
287a88e22b7SJung-uk Kim 
288a88e22b7SJung-uk Kim 
289a88e22b7SJung-uk Kim     /* Check for 100% ASCII source file (comments are ignored) */
290a88e22b7SJung-uk Kim 
291a88e22b7SJung-uk Kim     Status = FlCheckForAscii (Info);
292a88e22b7SJung-uk Kim     if (ACPI_FAILURE (Status))
293a88e22b7SJung-uk Kim     {
294a88e22b7SJung-uk Kim         printf ("Non-ascii input file - %s\n", Info->Filename);
295a88e22b7SJung-uk Kim         Type = ASL_INPUT_TYPE_BINARY;
296a88e22b7SJung-uk Kim         goto Cleanup;
297a88e22b7SJung-uk Kim     }
298a88e22b7SJung-uk Kim 
299a88e22b7SJung-uk Kim     /*
300a88e22b7SJung-uk Kim      * File is ASCII. Determine if this is an ASL file or an ACPI data
301a88e22b7SJung-uk Kim      * table file.
302a88e22b7SJung-uk Kim      */
303a88e22b7SJung-uk Kim     while (fgets (Gbl_CurrentLineBuffer, ASL_LINE_BUFFER_SIZE, Info->Handle))
304a88e22b7SJung-uk Kim     {
305a88e22b7SJung-uk Kim         /* Uppercase the buffer for caseless compare */
306a88e22b7SJung-uk Kim 
307a88e22b7SJung-uk Kim         FileChar = Gbl_CurrentLineBuffer;
308a88e22b7SJung-uk Kim         while (*FileChar)
309a88e22b7SJung-uk Kim         {
310a88e22b7SJung-uk Kim             *FileChar = (char) toupper ((int) *FileChar);
311a88e22b7SJung-uk Kim             FileChar++;
312a88e22b7SJung-uk Kim         }
313a88e22b7SJung-uk Kim 
314a88e22b7SJung-uk Kim         /* Presence of "DefinitionBlock" indicates actual ASL code */
315a88e22b7SJung-uk Kim 
316a88e22b7SJung-uk Kim         if (strstr (Gbl_CurrentLineBuffer, "DEFINITIONBLOCK"))
317a88e22b7SJung-uk Kim         {
318a88e22b7SJung-uk Kim             /* Appears to be an ASL file */
319a88e22b7SJung-uk Kim 
320a88e22b7SJung-uk Kim             Type = ASL_INPUT_TYPE_ASCII_ASL;
321a88e22b7SJung-uk Kim             goto Cleanup;
322a88e22b7SJung-uk Kim         }
323a88e22b7SJung-uk Kim     }
324a88e22b7SJung-uk Kim 
325a88e22b7SJung-uk Kim     /* Not an ASL source file, default to a data table source file */
326a88e22b7SJung-uk Kim 
327a88e22b7SJung-uk Kim     Type = ASL_INPUT_TYPE_ASCII_DATA;
328a88e22b7SJung-uk Kim 
329a88e22b7SJung-uk Kim Cleanup:
330a88e22b7SJung-uk Kim 
331a88e22b7SJung-uk Kim     /* Must seek back to the start of the file */
332a88e22b7SJung-uk Kim 
333a88e22b7SJung-uk Kim     fseek (Info->Handle, 0, SEEK_SET);
334a88e22b7SJung-uk Kim     return (Type);
335a88e22b7SJung-uk Kim }
336a88e22b7SJung-uk Kim 
337a88e22b7SJung-uk Kim 
338a88e22b7SJung-uk Kim /*******************************************************************************
339a88e22b7SJung-uk Kim  *
340a9f12690SJung-uk Kim  * FUNCTION:    AslDoOneFile
341a9f12690SJung-uk Kim  *
342a9f12690SJung-uk Kim  * PARAMETERS:  Filename        - Name of the file
343a9f12690SJung-uk Kim  *
344a9f12690SJung-uk Kim  * RETURN:      Status
345a9f12690SJung-uk Kim  *
346a9f12690SJung-uk Kim  * DESCRIPTION: Process a single file - either disassemble, compile, or both
347a9f12690SJung-uk Kim  *
348a9f12690SJung-uk Kim  ******************************************************************************/
349a9f12690SJung-uk Kim 
350a9f12690SJung-uk Kim ACPI_STATUS
351a9f12690SJung-uk Kim AslDoOneFile (
352a9f12690SJung-uk Kim     char                    *Filename)
353a9f12690SJung-uk Kim {
354a9f12690SJung-uk Kim     ACPI_STATUS             Status;
355a9f12690SJung-uk Kim 
356a9f12690SJung-uk Kim 
357a9f12690SJung-uk Kim     Gbl_Files[ASL_FILE_INPUT].Filename = Filename;
358a9f12690SJung-uk Kim 
359a9f12690SJung-uk Kim     /* Re-initialize "some" compiler globals */
360a9f12690SJung-uk Kim 
361a9f12690SJung-uk Kim     AslInitializeGlobals ();
362a9f12690SJung-uk Kim 
363a9f12690SJung-uk Kim     /*
364a9f12690SJung-uk Kim      * AML Disassembly (Optional)
365a9f12690SJung-uk Kim      */
366a9f12690SJung-uk Kim     if (Gbl_DisasmFlag || Gbl_GetAllTables)
367a9f12690SJung-uk Kim     {
368a9f12690SJung-uk Kim         /* ACPICA subsystem initialization */
369a9f12690SJung-uk Kim 
370a9f12690SJung-uk Kim         Status = AdInitialize ();
371a9f12690SJung-uk Kim         if (ACPI_FAILURE (Status))
372a9f12690SJung-uk Kim         {
373a9f12690SJung-uk Kim             return (Status);
374a9f12690SJung-uk Kim         }
375a9f12690SJung-uk Kim 
376a9f12690SJung-uk Kim         Status = AcpiAllocateRootTable (4);
377a9f12690SJung-uk Kim         if (ACPI_FAILURE (Status))
378a9f12690SJung-uk Kim         {
379a9f12690SJung-uk Kim             AcpiOsPrintf ("Could not initialize ACPI Table Manager, %s\n",
380a9f12690SJung-uk Kim                 AcpiFormatException (Status));
381a9f12690SJung-uk Kim             return (Status);
382a9f12690SJung-uk Kim         }
383a9f12690SJung-uk Kim 
384a9f12690SJung-uk Kim         /* This is where the disassembly happens */
385a9f12690SJung-uk Kim 
386a9f12690SJung-uk Kim         AcpiGbl_DbOpt_disasm = TRUE;
387a9f12690SJung-uk Kim         Status = AdAmlDisassemble (AslToFile,
388a9f12690SJung-uk Kim                     Gbl_Files[ASL_FILE_INPUT].Filename,
389a9f12690SJung-uk Kim                     Gbl_OutputFilenamePrefix,
390a9f12690SJung-uk Kim                     &Gbl_Files[ASL_FILE_INPUT].Filename,
391a9f12690SJung-uk Kim                     Gbl_GetAllTables);
392a9f12690SJung-uk Kim         if (ACPI_FAILURE (Status))
393a9f12690SJung-uk Kim         {
394a9f12690SJung-uk Kim             return (Status);
395a9f12690SJung-uk Kim         }
396a9f12690SJung-uk Kim 
397a9f12690SJung-uk Kim         /* Shutdown compiler and ACPICA subsystem */
398a9f12690SJung-uk Kim 
399a9f12690SJung-uk Kim         AeClearErrorLog ();
400*42fecd12SJung-uk Kim         (void) AcpiTerminate ();
401a9f12690SJung-uk Kim 
402a9f12690SJung-uk Kim         /*
403a9f12690SJung-uk Kim          * Gbl_Files[ASL_FILE_INPUT].Filename was replaced with the
404a9f12690SJung-uk Kim          * .DSL disassembly file, which can now be compiled if requested
405a9f12690SJung-uk Kim          */
406a9f12690SJung-uk Kim         if (Gbl_DoCompile)
407a9f12690SJung-uk Kim         {
408a9f12690SJung-uk Kim             AcpiOsPrintf ("\nCompiling \"%s\"\n",
409a9f12690SJung-uk Kim                 Gbl_Files[ASL_FILE_INPUT].Filename);
410a9f12690SJung-uk Kim         }
411a88e22b7SJung-uk Kim         else
412a88e22b7SJung-uk Kim         {
413a88e22b7SJung-uk Kim             Gbl_Files[ASL_FILE_INPUT].Filename = NULL;
414a88e22b7SJung-uk Kim             return (AE_OK);
415a88e22b7SJung-uk Kim         }
416a9f12690SJung-uk Kim     }
417a9f12690SJung-uk Kim 
418a9f12690SJung-uk Kim     /*
419a88e22b7SJung-uk Kim      * Open the input file. Here, this should be an ASCII source file,
420a88e22b7SJung-uk Kim      * either an ASL file or a Data Table file
421a9f12690SJung-uk Kim      */
422a88e22b7SJung-uk Kim     Status = FlOpenInputFile (Gbl_Files[ASL_FILE_INPUT].Filename);
423a88e22b7SJung-uk Kim     if (ACPI_FAILURE (Status))
424a9f12690SJung-uk Kim     {
425a88e22b7SJung-uk Kim         AePrintErrorLog (ASL_FILE_STDERR);
426a88e22b7SJung-uk Kim         return (AE_ERROR);
427a88e22b7SJung-uk Kim     }
428a88e22b7SJung-uk Kim 
429a88e22b7SJung-uk Kim     /* Determine input file type */
430a88e22b7SJung-uk Kim 
431a88e22b7SJung-uk Kim     Gbl_FileType = AslDetectSourceFileType (&Gbl_Files[ASL_FILE_INPUT]);
432a88e22b7SJung-uk Kim     if (Gbl_FileType == ASL_INPUT_TYPE_BINARY)
433a88e22b7SJung-uk Kim     {
434a88e22b7SJung-uk Kim         return (AE_ERROR);
435a88e22b7SJung-uk Kim     }
436a88e22b7SJung-uk Kim 
437a9f12690SJung-uk Kim     /*
438a9f12690SJung-uk Kim      * If -p not specified, we will use the input filename as the
439a9f12690SJung-uk Kim      * output filename prefix
440a9f12690SJung-uk Kim      */
441a9f12690SJung-uk Kim     if (Gbl_UseDefaultAmlFilename)
442a9f12690SJung-uk Kim     {
443a9f12690SJung-uk Kim         Gbl_OutputFilenamePrefix = Gbl_Files[ASL_FILE_INPUT].Filename;
444a9f12690SJung-uk Kim     }
445a9f12690SJung-uk Kim 
446a88e22b7SJung-uk Kim     /* Open the optional output files (listings, etc.) */
447a88e22b7SJung-uk Kim 
448a88e22b7SJung-uk Kim     Status = FlOpenMiscOutputFiles (Gbl_OutputFilenamePrefix);
449a88e22b7SJung-uk Kim     if (ACPI_FAILURE (Status))
450a88e22b7SJung-uk Kim     {
451a88e22b7SJung-uk Kim         AePrintErrorLog (ASL_FILE_STDERR);
452a88e22b7SJung-uk Kim         return (AE_ERROR);
453a88e22b7SJung-uk Kim     }
454a88e22b7SJung-uk Kim 
455a88e22b7SJung-uk Kim     /*
456a88e22b7SJung-uk Kim      * Compilation of ASL source versus DataTable source uses different
457a88e22b7SJung-uk Kim      * compiler subsystems
458a88e22b7SJung-uk Kim      */
459a88e22b7SJung-uk Kim     switch (Gbl_FileType)
460a88e22b7SJung-uk Kim     {
461a88e22b7SJung-uk Kim     /*
462a88e22b7SJung-uk Kim      * Data Table Compilation
463a88e22b7SJung-uk Kim      */
464a88e22b7SJung-uk Kim     case ASL_INPUT_TYPE_ASCII_DATA:
465a88e22b7SJung-uk Kim 
466a88e22b7SJung-uk Kim         Status = DtDoCompile ();
467a88e22b7SJung-uk Kim 
468a88e22b7SJung-uk Kim         if (Gbl_Signature)
469a88e22b7SJung-uk Kim         {
470a88e22b7SJung-uk Kim             ACPI_FREE (Gbl_Signature);
471a88e22b7SJung-uk Kim             Gbl_Signature = NULL;
472a88e22b7SJung-uk Kim         }
473a88e22b7SJung-uk Kim         AeClearErrorLog ();
474a88e22b7SJung-uk Kim         return (Status);
475a88e22b7SJung-uk Kim 
476a88e22b7SJung-uk Kim     /*
477a88e22b7SJung-uk Kim      * ASL Compilation (Optional)
478a88e22b7SJung-uk Kim      */
479a88e22b7SJung-uk Kim     case ASL_INPUT_TYPE_ASCII_ASL:
480a88e22b7SJung-uk Kim 
481a88e22b7SJung-uk Kim         /* ACPICA subsystem initialization */
482a9f12690SJung-uk Kim 
483a9f12690SJung-uk Kim         Status = AdInitialize ();
484a9f12690SJung-uk Kim         if (ACPI_FAILURE (Status))
485a9f12690SJung-uk Kim         {
486a9f12690SJung-uk Kim             return (Status);
487a9f12690SJung-uk Kim         }
488a9f12690SJung-uk Kim 
489a9f12690SJung-uk Kim         Status = CmDoCompile ();
490*42fecd12SJung-uk Kim         (void) AcpiTerminate ();
491a9f12690SJung-uk Kim 
492a9f12690SJung-uk Kim         /*
493a9f12690SJung-uk Kim          * Return non-zero exit code if there have been errors, unless the
494a9f12690SJung-uk Kim          * global ignore error flag has been set
495a9f12690SJung-uk Kim          */
496a9f12690SJung-uk Kim         if ((Gbl_ExceptionCount[ASL_ERROR] > 0) && (!Gbl_IgnoreErrors))
497a9f12690SJung-uk Kim         {
498a9f12690SJung-uk Kim             return (AE_ERROR);
499a9f12690SJung-uk Kim         }
500a9f12690SJung-uk Kim 
501a9f12690SJung-uk Kim         AeClearErrorLog ();
502a9f12690SJung-uk Kim         return (AE_OK);
503a88e22b7SJung-uk Kim 
504a88e22b7SJung-uk Kim     case ASL_INPUT_TYPE_BINARY:
505a88e22b7SJung-uk Kim 
506a88e22b7SJung-uk Kim         AePrintErrorLog (ASL_FILE_STDERR);
507a88e22b7SJung-uk Kim         return (AE_ERROR);
508a88e22b7SJung-uk Kim 
509a88e22b7SJung-uk Kim     default:
510a88e22b7SJung-uk Kim         printf ("Unknown file type %X\n", Gbl_FileType);
511a88e22b7SJung-uk Kim         return (AE_ERROR);
512a88e22b7SJung-uk Kim     }
513a9f12690SJung-uk Kim }
514a9f12690SJung-uk Kim 
515a9f12690SJung-uk Kim 
516a9f12690SJung-uk Kim /*******************************************************************************
517a9f12690SJung-uk Kim  *
518a9f12690SJung-uk Kim  * FUNCTION:    AslDoOnePathname
519a9f12690SJung-uk Kim  *
520a9f12690SJung-uk Kim  * PARAMETERS:  Pathname            - Full pathname, possibly with wildcards
521a9f12690SJung-uk Kim  *
522a9f12690SJung-uk Kim  * RETURN:      Status
523a9f12690SJung-uk Kim  *
524a9f12690SJung-uk Kim  * DESCRIPTION: Process one pathname, possible terminated with a wildcard
525a9f12690SJung-uk Kim  *              specification. If a wildcard, it is expanded and the multiple
526a9f12690SJung-uk Kim  *              files are processed.
527a9f12690SJung-uk Kim  *
528a9f12690SJung-uk Kim  ******************************************************************************/
529a9f12690SJung-uk Kim 
530a9f12690SJung-uk Kim ACPI_STATUS
531a9f12690SJung-uk Kim AslDoOnePathname (
532709fac06SJung-uk Kim     char                    *Pathname,
533709fac06SJung-uk Kim     ASL_PATHNAME_CALLBACK   PathCallback)
534a9f12690SJung-uk Kim {
535a88e22b7SJung-uk Kim     ACPI_STATUS             Status = AE_OK;
536*42fecd12SJung-uk Kim     char                    **WildcardList;
537a9f12690SJung-uk Kim     char                    *Filename;
538a9f12690SJung-uk Kim     char                    *FullPathname;
539a9f12690SJung-uk Kim 
540a9f12690SJung-uk Kim 
541a9f12690SJung-uk Kim     /* Split incoming path into a directory/filename combo */
542a9f12690SJung-uk Kim 
543a9f12690SJung-uk Kim     Status = FlSplitInputPathname (Pathname, &Gbl_DirectoryPath, &Filename);
544a9f12690SJung-uk Kim     if (ACPI_FAILURE (Status))
545a9f12690SJung-uk Kim     {
546a9f12690SJung-uk Kim         return (Status);
547a9f12690SJung-uk Kim     }
548a9f12690SJung-uk Kim 
549a9f12690SJung-uk Kim     /* Expand possible wildcard into a file list (Windows/DOS only) */
550a9f12690SJung-uk Kim 
551*42fecd12SJung-uk Kim     WildcardList = AsDoWildcard (Gbl_DirectoryPath, Filename);
552*42fecd12SJung-uk Kim     while (*WildcardList)
553a9f12690SJung-uk Kim     {
554a9f12690SJung-uk Kim         FullPathname = ACPI_ALLOCATE (
555*42fecd12SJung-uk Kim             strlen (Gbl_DirectoryPath) + strlen (*WildcardList) + 1);
556a9f12690SJung-uk Kim 
557a9f12690SJung-uk Kim         /* Construct a full path to the file */
558a9f12690SJung-uk Kim 
559a9f12690SJung-uk Kim         strcpy (FullPathname, Gbl_DirectoryPath);
560*42fecd12SJung-uk Kim         strcat (FullPathname, *WildcardList);
561a9f12690SJung-uk Kim 
562a9f12690SJung-uk Kim         /*
563a9f12690SJung-uk Kim          * If -p not specified, we will use the input filename as the
564a9f12690SJung-uk Kim          * output filename prefix
565a9f12690SJung-uk Kim          */
566a9f12690SJung-uk Kim         if (Gbl_UseDefaultAmlFilename)
567a9f12690SJung-uk Kim         {
568a9f12690SJung-uk Kim             Gbl_OutputFilenamePrefix = FullPathname;
569a9f12690SJung-uk Kim         }
570a9f12690SJung-uk Kim 
571a88e22b7SJung-uk Kim         /* Save status from all compiles */
572a88e22b7SJung-uk Kim 
573709fac06SJung-uk Kim         Status |= (*PathCallback) (FullPathname);
574a9f12690SJung-uk Kim 
575a9f12690SJung-uk Kim         ACPI_FREE (FullPathname);
576*42fecd12SJung-uk Kim         ACPI_FREE (*WildcardList);
577*42fecd12SJung-uk Kim         *WildcardList = NULL;
578*42fecd12SJung-uk Kim         WildcardList++;
579a9f12690SJung-uk Kim     }
580a9f12690SJung-uk Kim 
581a9f12690SJung-uk Kim     ACPI_FREE (Gbl_DirectoryPath);
582a9f12690SJung-uk Kim     ACPI_FREE (Filename);
583a88e22b7SJung-uk Kim     return (Status);
584a9f12690SJung-uk Kim }
585a9f12690SJung-uk Kim 
586