Subversion Repositories Kolibri OS

Rev

Rev 1498 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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