asllisting.c revision 118611
1118611Snjl
2118611Snjl/******************************************************************************
3118611Snjl *
4118611Snjl * Module Name: asllisting - Listing file generation
5118611Snjl *              $Revision: 50 $
6118611Snjl *
7118611Snjl *****************************************************************************/
8118611Snjl
9118611Snjl/******************************************************************************
10118611Snjl *
11118611Snjl * 1. Copyright Notice
12118611Snjl *
13118611Snjl * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
14118611Snjl * All rights reserved.
15118611Snjl *
16118611Snjl * 2. License
17118611Snjl *
18118611Snjl * 2.1. This is your license from Intel Corp. under its intellectual property
19118611Snjl * rights.  You may have additional license terms from the party that provided
20118611Snjl * you this software, covering your right to use that party's intellectual
21118611Snjl * property rights.
22118611Snjl *
23118611Snjl * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24118611Snjl * copy of the source code appearing in this file ("Covered Code") an
25118611Snjl * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26118611Snjl * base code distributed originally by Intel ("Original Intel Code") to copy,
27118611Snjl * make derivatives, distribute, use and display any portion of the Covered
28118611Snjl * Code in any form, with the right to sublicense such rights; and
29118611Snjl *
30118611Snjl * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31118611Snjl * license (with the right to sublicense), under only those claims of Intel
32118611Snjl * patents that are infringed by the Original Intel Code, to make, use, sell,
33118611Snjl * offer to sell, and import the Covered Code and derivative works thereof
34118611Snjl * solely to the minimum extent necessary to exercise the above copyright
35118611Snjl * license, and in no event shall the patent license extend to any additions
36118611Snjl * to or modifications of the Original Intel Code.  No other license or right
37118611Snjl * is granted directly or by implication, estoppel or otherwise;
38118611Snjl *
39118611Snjl * The above copyright and patent license is granted only if the following
40118611Snjl * conditions are met:
41118611Snjl *
42118611Snjl * 3. Conditions
43118611Snjl *
44118611Snjl * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45118611Snjl * Redistribution of source code of any substantial portion of the Covered
46118611Snjl * Code or modification with rights to further distribute source must include
47118611Snjl * the above Copyright Notice, the above License, this list of Conditions,
48118611Snjl * and the following Disclaimer and Export Compliance provision.  In addition,
49118611Snjl * Licensee must cause all Covered Code to which Licensee contributes to
50118611Snjl * contain a file documenting the changes Licensee made to create that Covered
51118611Snjl * Code and the date of any change.  Licensee must include in that file the
52118611Snjl * documentation of any changes made by any predecessor Licensee.  Licensee
53118611Snjl * must include a prominent statement that the modification is derived,
54118611Snjl * directly or indirectly, from Original Intel Code.
55118611Snjl *
56118611Snjl * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57118611Snjl * Redistribution of source code of any substantial portion of the Covered
58118611Snjl * Code or modification without rights to further distribute source must
59118611Snjl * include the following Disclaimer and Export Compliance provision in the
60118611Snjl * documentation and/or other materials provided with distribution.  In
61118611Snjl * addition, Licensee may not authorize further sublicense of source of any
62118611Snjl * portion of the Covered Code, and must include terms to the effect that the
63118611Snjl * license from Licensee to its licensee is limited to the intellectual
64118611Snjl * property embodied in the software Licensee provides to its licensee, and
65118611Snjl * not to intellectual property embodied in modifications its licensee may
66118611Snjl * make.
67118611Snjl *
68118611Snjl * 3.3. Redistribution of Executable. Redistribution in executable form of any
69118611Snjl * substantial portion of the Covered Code or modification must reproduce the
70118611Snjl * above Copyright Notice, and the following Disclaimer and Export Compliance
71118611Snjl * provision in the documentation and/or other materials provided with the
72118611Snjl * distribution.
73118611Snjl *
74118611Snjl * 3.4. Intel retains all right, title, and interest in and to the Original
75118611Snjl * Intel Code.
76118611Snjl *
77118611Snjl * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78118611Snjl * Intel shall be used in advertising or otherwise to promote the sale, use or
79118611Snjl * other dealings in products derived from or relating to the Covered Code
80118611Snjl * without prior written authorization from Intel.
81118611Snjl *
82118611Snjl * 4. Disclaimer and Export Compliance
83118611Snjl *
84118611Snjl * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85118611Snjl * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86118611Snjl * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
87118611Snjl * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
88118611Snjl * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
89118611Snjl * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90118611Snjl * PARTICULAR PURPOSE.
91118611Snjl *
92118611Snjl * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93118611Snjl * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94118611Snjl * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95118611Snjl * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96118611Snjl * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97118611Snjl * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
98118611Snjl * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99118611Snjl * LIMITED REMEDY.
100118611Snjl *
101118611Snjl * 4.3. Licensee shall not export, either directly or indirectly, any of this
102118611Snjl * software or system incorporating such software without first obtaining any
103118611Snjl * required license or other approval from the U. S. Department of Commerce or
104118611Snjl * any other agency or department of the United States Government.  In the
105118611Snjl * event Licensee exports any such software from the United States or
106118611Snjl * re-exports any such software from a foreign destination, Licensee shall
107118611Snjl * ensure that the distribution and export/re-export of the software is in
108118611Snjl * compliance with all laws, regulations, orders, or other restrictions of the
109118611Snjl * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110118611Snjl * any of its subsidiaries will export/re-export any technical data, process,
111118611Snjl * software, or service, directly or indirectly, to any country for which the
112118611Snjl * United States government or any agency thereof requires an export license,
113118611Snjl * other governmental approval, or letter of assurance, without first obtaining
114118611Snjl * such license, approval or letter.
115118611Snjl *
116118611Snjl *****************************************************************************/
117118611Snjl
118118611Snjl
119118611Snjl#include "aslcompiler.h"
120118611Snjl#include "aslcompiler.y.h"
121118611Snjl#include "amlcode.h"
122118611Snjl#include "acparser.h"
123118611Snjl#include "acnamesp.h"
124118611Snjl
125118611Snjl#define _COMPONENT          ACPI_COMPILER
126118611Snjl        ACPI_MODULE_NAME    ("aslisting")
127118611Snjl
128118611Snjl
129118611Snjl/*******************************************************************************
130118611Snjl *
131118611Snjl * FUNCTION:    LsDumpAscii
132118611Snjl *
133118611Snjl * PARAMETERS:  FileId          - ID of current listing file
134118611Snjl *              Count           - Number of bytes to convert
135118611Snjl *              Buffer          - Buffer of bytes to convert
136118611Snjl *
137118611Snjl * RETURN:      None.
138118611Snjl *
139118611Snjl * DESCRIPTION: Convert hex bytes to ascii
140118611Snjl *
141118611Snjl ******************************************************************************/
142118611Snjl
143118611Snjlvoid
144118611SnjlLsDumpAscii (
145118611Snjl    UINT32                  FileId,
146118611Snjl    UINT32                  Count,
147118611Snjl    UINT8                   *Buffer)
148118611Snjl{
149118611Snjl    UINT8                   BufChar;
150118611Snjl    UINT32                  i;
151118611Snjl
152118611Snjl
153118611Snjl    FlPrintFile (FileId, "    \"");
154118611Snjl    for (i = 0; i < Count; i++)
155118611Snjl    {
156118611Snjl        BufChar = Buffer[i];
157118611Snjl        if (isprint (BufChar))
158118611Snjl        {
159118611Snjl            FlPrintFile (FileId, "%c", BufChar);
160118611Snjl        }
161118611Snjl        else
162118611Snjl        {
163118611Snjl            /* Not a printable character, just put out a dot */
164118611Snjl
165118611Snjl            FlPrintFile (FileId, ".");
166118611Snjl        }
167118611Snjl    }
168118611Snjl    FlPrintFile (FileId, "\"");
169118611Snjl}
170118611Snjl
171118611Snjl
172118611Snjl/*******************************************************************************
173118611Snjl *
174118611Snjl * FUNCTION:    LsDumpAsciiInComment
175118611Snjl *
176118611Snjl * PARAMETERS:  FileId          - ID of current listing file
177118611Snjl *              Count           - Number of bytes to convert
178118611Snjl *              Buffer          - Buffer of bytes to convert
179118611Snjl *
180118611Snjl * RETURN:      None.
181118611Snjl *
182118611Snjl * DESCRIPTION: Convert hex bytes to ascii
183118611Snjl *
184118611Snjl ******************************************************************************/
185118611Snjl
186118611Snjlvoid
187118611SnjlLsDumpAsciiInComment (
188118611Snjl    UINT32                  FileId,
189118611Snjl    UINT32                  Count,
190118611Snjl    UINT8                   *Buffer)
191118611Snjl{
192118611Snjl    UINT8                   BufChar = 0;
193118611Snjl    UINT8                   LastChar;
194118611Snjl    UINT32                  i;
195118611Snjl
196118611Snjl
197118611Snjl    FlPrintFile (FileId, "    \"");
198118611Snjl    for (i = 0; i < Count; i++)
199118611Snjl    {
200118611Snjl        LastChar = BufChar;
201118611Snjl        BufChar = Buffer[i];
202118611Snjl
203118611Snjl        if (isprint (BufChar))
204118611Snjl        {
205118611Snjl            /* Handle embedded C comment sequences */
206118611Snjl
207118611Snjl            if (((LastChar == '*') && (BufChar == '/')) ||
208118611Snjl                ((LastChar == '/') && (BufChar == '*')))
209118611Snjl            {
210118611Snjl                /* Insert a space to break the sequence */
211118611Snjl
212118611Snjl                FlPrintFile (FileId, ".", BufChar);
213118611Snjl            }
214118611Snjl
215118611Snjl            FlPrintFile (FileId, "%c", BufChar);
216118611Snjl        }
217118611Snjl        else
218118611Snjl        {
219118611Snjl            /* Not a printable character, just put out a dot */
220118611Snjl
221118611Snjl            FlPrintFile (FileId, ".");
222118611Snjl        }
223118611Snjl    }
224118611Snjl    FlPrintFile (FileId, "\"");
225118611Snjl}
226118611Snjl
227118611Snjl
228118611Snjl/*******************************************************************************
229118611Snjl *
230118611Snjl * FUNCTION:    LsAmlListingWalk
231118611Snjl *
232118611Snjl * PARAMETERS:  ASL_WALK_CALLBACK
233118611Snjl *
234118611Snjl * RETURN:      Status
235118611Snjl *
236118611Snjl * DESCRIPTION: Process one node during a listing file generation.
237118611Snjl *
238118611Snjl ******************************************************************************/
239118611Snjl
240118611SnjlACPI_STATUS
241118611SnjlLsAmlListingWalk (
242118611Snjl    ACPI_PARSE_OBJECT       *Op,
243118611Snjl    UINT32                  Level,
244118611Snjl    void                    *Context)
245118611Snjl{
246118611Snjl    UINT8                   FileByte;
247118611Snjl    UINT32                  i;
248118611Snjl    UINT32                  FileId = (UINT32) Context;
249118611Snjl
250118611Snjl
251118611Snjl    LsWriteNodeToListing (Op, FileId);
252118611Snjl
253118611Snjl    /* Write the hex bytes to the listing file(s) (if requested) */
254118611Snjl
255118611Snjl    for (i = 0; i < Op->Asl.FinalAmlLength; i++)
256118611Snjl    {
257118611Snjl        if (ACPI_FAILURE (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte, 1)))
258118611Snjl        {
259118611Snjl            FlFileError (ASL_FILE_AML_OUTPUT, ASL_MSG_READ);
260118611Snjl            AslAbort ();
261118611Snjl        }
262118611Snjl        LsWriteListingHexBytes (&FileByte, 1, FileId);
263118611Snjl    }
264118611Snjl
265118611Snjl    return (AE_OK);
266118611Snjl}
267118611Snjl
268118611Snjl
269118611Snjl/*******************************************************************************
270118611Snjl *
271118611Snjl * FUNCTION:    LsGenerateListing
272118611Snjl *
273118611Snjl * PARAMETERS:  FileId      - ID of listing file
274118611Snjl *
275118611Snjl * RETURN:      None
276118611Snjl *
277118611Snjl * DESCRIPTION: Generate a listing file.  This can be one of the several types
278118611Snjl *              of "listings" supported.
279118611Snjl *
280118611Snjl ******************************************************************************/
281118611Snjl
282118611Snjlvoid
283118611SnjlLsGenerateListing (
284118611Snjl    UINT32                  FileId)
285118611Snjl{
286118611Snjl
287118611Snjl    /* Start at the beginning of both the source and AML files */
288118611Snjl
289118611Snjl    FlSeekFile (ASL_FILE_SOURCE_OUTPUT, 0);
290118611Snjl    FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
291118611Snjl    Gbl_SourceLine = 0;
292118611Snjl    Gbl_CurrentHexColumn = 0;
293118611Snjl    LsPushNode (Gbl_Files[ASL_FILE_INPUT].Filename);
294118611Snjl
295118611Snjl    /* Process all parse nodes */
296118611Snjl
297118611Snjl    TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, LsAmlListingWalk,
298118611Snjl                        NULL, (void *) ACPI_TO_POINTER (FileId));
299118611Snjl
300118611Snjl    /* Final processing */
301118611Snjl
302118611Snjl    LsFinishSourceListing (FileId);
303118611Snjl}
304118611Snjl
305118611Snjl
306118611Snjl/*******************************************************************************
307118611Snjl *
308118611Snjl * FUNCTION:    LsDoListings
309118611Snjl *
310118611Snjl * PARAMETERS:  None.
311118611Snjl *
312118611Snjl * RETURN:      None
313118611Snjl *
314118611Snjl * DESCRIPTION: Generate all requested listing files.
315118611Snjl *
316118611Snjl ******************************************************************************/
317118611Snjl
318118611Snjlvoid
319118611SnjlLsDoListings (void)
320118611Snjl{
321118611Snjl
322118611Snjl    if (Gbl_C_OutputFlag)
323118611Snjl    {
324118611Snjl        LsGenerateListing (ASL_FILE_C_SOURCE_OUTPUT);
325118611Snjl    }
326118611Snjl
327118611Snjl    if (Gbl_ListingFlag)
328118611Snjl    {
329118611Snjl        LsGenerateListing (ASL_FILE_LISTING_OUTPUT);
330118611Snjl    }
331118611Snjl
332118611Snjl    if (Gbl_AsmOutputFlag)
333118611Snjl    {
334118611Snjl        LsGenerateListing (ASL_FILE_ASM_SOURCE_OUTPUT);
335118611Snjl    }
336118611Snjl
337118611Snjl    if (Gbl_C_IncludeOutputFlag)
338118611Snjl    {
339118611Snjl        LsGenerateListing (ASL_FILE_C_INCLUDE_OUTPUT);
340118611Snjl    }
341118611Snjl
342118611Snjl    if (Gbl_AsmIncludeOutputFlag)
343118611Snjl    {
344118611Snjl        LsGenerateListing (ASL_FILE_ASM_INCLUDE_OUTPUT);
345118611Snjl    }
346118611Snjl}
347118611Snjl
348118611Snjl
349118611Snjl/*******************************************************************************
350118611Snjl *
351118611Snjl * FUNCTION:    LsPushNode
352118611Snjl *
353118611Snjl * PARAMETERS:  Filename        - Pointer to the include filename
354118611Snjl *
355118611Snjl * RETURN:      None
356118611Snjl *
357118611Snjl * DESCRIPTION: Push a listing node on the listing/include file stack.  This
358118611Snjl *              stack enables tracking of include files (infinitely nested)
359118611Snjl *              and resumption of the listing of the parent file when the
360118611Snjl *              include file is finished.
361118611Snjl *
362118611Snjl ******************************************************************************/
363118611Snjl
364118611Snjlvoid
365118611SnjlLsPushNode (
366118611Snjl    char                    *Filename)
367118611Snjl{
368118611Snjl    ASL_LISTING_NODE        *Lnode;
369118611Snjl
370118611Snjl
371118611Snjl    /* Create a new node */
372118611Snjl
373118611Snjl    Lnode = UtLocalCalloc (sizeof (ASL_LISTING_NODE));
374118611Snjl
375118611Snjl    /* Initialize */
376118611Snjl
377118611Snjl    Lnode->Filename = Filename;
378118611Snjl    Lnode->LineNumber = 0;
379118611Snjl
380118611Snjl    /* Link (push) */
381118611Snjl
382118611Snjl    Lnode->Next = Gbl_ListingNode;
383118611Snjl    Gbl_ListingNode = Lnode;
384118611Snjl}
385118611Snjl
386118611Snjl
387118611Snjl/*******************************************************************************
388118611Snjl *
389118611Snjl * FUNCTION:    LsPopNode
390118611Snjl *
391118611Snjl * PARAMETERS:  None
392118611Snjl *
393118611Snjl * RETURN:      List head after current head is popped off
394118611Snjl *
395118611Snjl * DESCRIPTION: Pop the current head of the list, free it, and return the
396118611Snjl *              next node on the stack (the new current node).
397118611Snjl *
398118611Snjl ******************************************************************************/
399118611Snjl
400118611SnjlASL_LISTING_NODE *
401118611SnjlLsPopNode (void)
402118611Snjl{
403118611Snjl    ASL_LISTING_NODE        *Lnode;
404118611Snjl
405118611Snjl
406118611Snjl    /* Just grab the node at the head of the list */
407118611Snjl
408118611Snjl    Lnode = Gbl_ListingNode;
409118611Snjl    if ((!Lnode) ||
410118611Snjl        (!Lnode->Next))
411118611Snjl    {
412118611Snjl        AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, NULL, "Could not pop empty listing stack");
413118611Snjl        return Gbl_ListingNode;
414118611Snjl    }
415118611Snjl
416118611Snjl    Gbl_ListingNode = Lnode->Next;
417118611Snjl    ACPI_MEM_FREE (Lnode);
418118611Snjl
419118611Snjl    /* New "Current" node is the new head */
420118611Snjl
421118611Snjl    return (Gbl_ListingNode);
422118611Snjl}
423118611Snjl
424118611Snjl
425118611Snjl/*******************************************************************************
426118611Snjl *
427118611Snjl * FUNCTION:    LsCheckException
428118611Snjl *
429118611Snjl * PARAMETERS:  LineNumber          - Current logical (cumulative) line #
430118611Snjl *              FileId              - ID of output listing file
431118611Snjl *
432118611Snjl * RETURN:      None
433118611Snjl *
434118611Snjl * DESCRIPTION: Check if there is an exception for this line, and if there is,
435118611Snjl *              put it in the listing immediately.  Handles multiple errors
436118611Snjl *              per line.  Gbl_NextError points to the next error in the
437118611Snjl *              sorted (by line #) list of compile errors/warnings.
438118611Snjl *
439118611Snjl ******************************************************************************/
440118611Snjl
441118611Snjlvoid
442118611SnjlLsCheckException (
443118611Snjl    UINT32                  LineNumber,
444118611Snjl    UINT32                  FileId)
445118611Snjl{
446118611Snjl
447118611Snjl    if ((!Gbl_NextError) ||
448118611Snjl        (LineNumber < Gbl_NextError->LogicalLineNumber ))
449118611Snjl    {
450118611Snjl        return;
451118611Snjl    }
452118611Snjl
453118611Snjl    /* Handle multiple errors per line */
454118611Snjl
455118611Snjl    if (FileId == ASL_FILE_LISTING_OUTPUT)
456118611Snjl    {
457118611Snjl        while (Gbl_NextError &&
458118611Snjl              (LineNumber >= Gbl_NextError->LogicalLineNumber))
459118611Snjl        {
460118611Snjl            AePrintException (FileId, Gbl_NextError, "\n[****iasl****]\n");
461118611Snjl
462118611Snjl            Gbl_NextError = Gbl_NextError->Next;
463118611Snjl        }
464118611Snjl
465118611Snjl        FlPrintFile (FileId, "\n");
466118611Snjl    }
467118611Snjl}
468118611Snjl
469118611Snjl
470118611Snjl/*******************************************************************************
471118611Snjl *
472118611Snjl * FUNCTION:    LsFlushListingBuffer
473118611Snjl *
474118611Snjl * PARAMETERS:  FileId          - ID of the listing file
475118611Snjl *
476118611Snjl * RETURN:      None
477118611Snjl *
478118611Snjl * DESCRIPTION: Flush out the current contents of the 16-byte hex AML code
479118611Snjl *              buffer.  Usually called at the termination of a single line
480118611Snjl *              of source code or when the buffer is full.
481118611Snjl *
482118611Snjl ******************************************************************************/
483118611Snjl
484118611Snjlvoid
485118611SnjlLsFlushListingBuffer (
486118611Snjl    UINT32                  FileId)
487118611Snjl{
488118611Snjl    UINT32                  i;
489118611Snjl
490118611Snjl
491118611Snjl    if (Gbl_CurrentHexColumn == 0)
492118611Snjl    {
493118611Snjl        return;
494118611Snjl    }
495118611Snjl
496118611Snjl    /* Write the hex bytes */
497118611Snjl
498118611Snjl    switch (FileId)
499118611Snjl    {
500118611Snjl    case ASL_FILE_LISTING_OUTPUT:
501118611Snjl
502118611Snjl        for (i = 0; i < Gbl_CurrentHexColumn; i++)
503118611Snjl        {
504118611Snjl            FlPrintFile (FileId, "%2.2X ", Gbl_AmlBuffer[i]);
505118611Snjl        }
506118611Snjl
507118611Snjl        for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 3); i++)
508118611Snjl        {
509118611Snjl            FlWriteFile (FileId, ".", 1);
510118611Snjl        }
511118611Snjl
512118611Snjl        /* Write the ASCII character associated with each of the bytes */
513118611Snjl
514118611Snjl        LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer);
515118611Snjl        break;
516118611Snjl
517118611Snjl
518118611Snjl    case ASL_FILE_ASM_SOURCE_OUTPUT:
519118611Snjl
520118611Snjl        for (i = 0; i < Gbl_CurrentHexColumn; i++)
521118611Snjl        {
522118611Snjl            if (i > 0)
523118611Snjl            {
524118611Snjl                FlPrintFile (FileId, ",");
525118611Snjl            }
526118611Snjl            FlPrintFile (FileId, "0%2.2Xh", Gbl_AmlBuffer[i]);
527118611Snjl        }
528118611Snjl
529118611Snjl        for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++)
530118611Snjl        {
531118611Snjl            FlWriteFile (FileId, " ", 1);
532118611Snjl        }
533118611Snjl
534118611Snjl        FlPrintFile (FileId, "  ;%8.8X", Gbl_CurrentAmlOffset - HEX_LISTING_LINE_SIZE);
535118611Snjl
536118611Snjl        /* Write the ASCII character associated with each of the bytes */
537118611Snjl
538118611Snjl        LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer);
539118611Snjl        break;
540118611Snjl
541118611Snjl
542118611Snjl    case ASL_FILE_C_SOURCE_OUTPUT:
543118611Snjl
544118611Snjl        for (i = 0; i < Gbl_CurrentHexColumn; i++)
545118611Snjl        {
546118611Snjl            FlPrintFile (FileId, "0x%2.2X,", Gbl_AmlBuffer[i]);
547118611Snjl        }
548118611Snjl
549118611Snjl        for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++)
550118611Snjl        {
551118611Snjl            FlWriteFile (FileId, " ", 1);
552118611Snjl        }
553118611Snjl
554118611Snjl        FlPrintFile (FileId, "    /* %8.8X", Gbl_CurrentAmlOffset - HEX_LISTING_LINE_SIZE);
555118611Snjl
556118611Snjl        /* Write the ASCII character associated with each of the bytes */
557118611Snjl
558118611Snjl        LsDumpAsciiInComment (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer);
559118611Snjl        FlPrintFile (FileId, " */");
560118611Snjl        break;
561118611Snjl
562118611Snjl    default:
563118611Snjl        /* No other types supported */
564118611Snjl        return;
565118611Snjl    }
566118611Snjl
567118611Snjl    FlPrintFile (FileId, "\n");
568118611Snjl
569118611Snjl    Gbl_CurrentHexColumn = 0;
570118611Snjl    Gbl_HexBytesWereWritten = TRUE;
571118611Snjl}
572118611Snjl
573118611Snjl
574118611Snjl/*******************************************************************************
575118611Snjl *
576118611Snjl * FUNCTION:    LsWriteListingHexBytes
577118611Snjl *
578118611Snjl * PARAMETERS:  Buffer          - AML code buffer
579118611Snjl *              Length          - Number of AML bytes to write
580118611Snjl *              FileId          - ID of current listing file.
581118611Snjl *
582118611Snjl * RETURN:      None
583118611Snjl *
584118611Snjl * DESCRIPTION: Write the contents of the AML buffer to the listing file via
585118611Snjl *              the listing buffer.  The listing buffer is flushed every 16
586118611Snjl *              AML bytes.
587118611Snjl *
588118611Snjl ******************************************************************************/
589118611Snjl
590118611Snjlvoid
591118611SnjlLsWriteListingHexBytes (
592118611Snjl    UINT8                   *Buffer,
593118611Snjl    UINT32                  Length,
594118611Snjl    UINT32                  FileId)
595118611Snjl{
596118611Snjl    UINT32                  i;
597118611Snjl
598118611Snjl
599118611Snjl    /* Transfer all requested bytes */
600118611Snjl
601118611Snjl    for (i = 0; i < Length; i++)
602118611Snjl    {
603118611Snjl        /* Print line header when buffer is empty */
604118611Snjl
605118611Snjl        if (Gbl_CurrentHexColumn == 0)
606118611Snjl        {
607118611Snjl            if (Gbl_HasIncludeFiles)
608118611Snjl            {
609118611Snjl                FlPrintFile (FileId, "%*s", 10, " ");
610118611Snjl            }
611118611Snjl
612118611Snjl            switch (FileId)
613118611Snjl            {
614118611Snjl            case ASL_FILE_LISTING_OUTPUT:
615118611Snjl
616118611Snjl                FlPrintFile (FileId, "%8.8X....", Gbl_CurrentAmlOffset);
617118611Snjl                break;
618118611Snjl
619118611Snjl            case ASL_FILE_ASM_SOURCE_OUTPUT:
620118611Snjl
621118611Snjl                FlPrintFile (FileId, "    db ");
622118611Snjl                break;
623118611Snjl
624118611Snjl            case ASL_FILE_C_SOURCE_OUTPUT:
625118611Snjl
626118611Snjl                FlPrintFile (FileId, "        ");
627118611Snjl                break;
628118611Snjl
629118611Snjl            default:
630118611Snjl                /* No other types supported */
631118611Snjl                return;
632118611Snjl            }
633118611Snjl        }
634118611Snjl
635118611Snjl        /* Transfer AML byte and update counts */
636118611Snjl
637118611Snjl        Gbl_AmlBuffer[Gbl_CurrentHexColumn] = Buffer[i];
638118611Snjl
639118611Snjl        Gbl_CurrentHexColumn++;
640118611Snjl        Gbl_CurrentAmlOffset++;
641118611Snjl
642118611Snjl        /* Flush buffer when it is full */
643118611Snjl
644118611Snjl        if (Gbl_CurrentHexColumn >= HEX_LISTING_LINE_SIZE)
645118611Snjl        {
646118611Snjl            LsFlushListingBuffer (FileId);
647118611Snjl        }
648118611Snjl    }
649118611Snjl}
650118611Snjl
651118611Snjl
652118611Snjl/*******************************************************************************
653118611Snjl *
654118611Snjl * FUNCTION:    LsWriteOneSourceLine
655118611Snjl *
656118611Snjl * PARAMETERS:  FileID          - ID of current listing file
657118611Snjl *
658118611Snjl * RETURN:      FALSE on EOF (input source file), TRUE otherwise
659118611Snjl *
660118611Snjl * DESCRIPTION: Read one line from the input source file and echo it to the
661118611Snjl *              listing file, prefixed with the line number, and if the source
662118611Snjl *              file contains include files, prefixed with the current filename
663118611Snjl *
664118611Snjl ******************************************************************************/
665118611Snjl
666118611SnjlUINT32
667118611SnjlLsWriteOneSourceLine (
668118611Snjl    UINT32                  FileId)
669118611Snjl{
670118611Snjl    UINT8                   FileByte;
671118611Snjl
672118611Snjl
673118611Snjl    Gbl_SourceLine++;
674118611Snjl    Gbl_ListingNode->LineNumber++;
675118611Snjl
676118611Snjl    if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
677118611Snjl    {
678118611Snjl        FlPrintFile (FileId, "     *");
679118611Snjl    }
680118611Snjl    if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
681118611Snjl    {
682118611Snjl        FlPrintFile (FileId, "; ");
683118611Snjl    }
684118611Snjl
685118611Snjl    if (Gbl_HasIncludeFiles)
686118611Snjl    {
687118611Snjl        /*
688118611Snjl         * This file contains "include" statements, print the current
689118611Snjl         * filename and line number within the current file
690118611Snjl         */
691118611Snjl        FlPrintFile (FileId, "%12s %5d....",
692118611Snjl                    Gbl_ListingNode->Filename, Gbl_ListingNode->LineNumber);
693118611Snjl    }
694118611Snjl    else
695118611Snjl    {
696118611Snjl        /* No include files, just print the line number */
697118611Snjl
698118611Snjl        FlPrintFile (FileId, "%8d....", Gbl_SourceLine);
699118611Snjl    }
700118611Snjl
701118611Snjl    /* Read one line (up to a newline or EOF) */
702118611Snjl
703118611Snjl    while (FlReadFile (ASL_FILE_SOURCE_OUTPUT, &FileByte, 1) == AE_OK)
704118611Snjl    {
705118611Snjl        if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
706118611Snjl        {
707118611Snjl            if (FileByte == '/')
708118611Snjl            {
709118611Snjl                FileByte = '*';
710118611Snjl            }
711118611Snjl        }
712118611Snjl
713118611Snjl        FlWriteFile (FileId, &FileByte, 1);
714118611Snjl        if (FileByte == '\n')
715118611Snjl        {
716118611Snjl            /*
717118611Snjl             * Check if an error occurred on this source line during the compile.
718118611Snjl             * If so, we print the error message after the source line.
719118611Snjl             */
720118611Snjl            LsCheckException (Gbl_SourceLine, FileId);
721118611Snjl            return (1);
722118611Snjl        }
723118611Snjl    }
724118611Snjl
725118611Snjl    /* EOF on the input file was reached */
726118611Snjl
727118611Snjl    return (0);
728118611Snjl}
729118611Snjl
730118611Snjl
731118611Snjl/*******************************************************************************
732118611Snjl *
733118611Snjl * FUNCTION:    LsFinishSourceListing
734118611Snjl *
735118611Snjl * PARAMETERS:  FileId          - ID of current listing file.
736118611Snjl *
737118611Snjl * RETURN:      None
738118611Snjl *
739118611Snjl * DESCRIPTION: Cleanup routine for the listing file.  Flush the hex AML
740118611Snjl *              listing buffer, and flush out any remaining lines in the
741118611Snjl *              source input file.
742118611Snjl *
743118611Snjl ******************************************************************************/
744118611Snjl
745118611Snjlvoid
746118611SnjlLsFinishSourceListing (
747118611Snjl    UINT32                  FileId)
748118611Snjl{
749118611Snjl
750118611Snjl    if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) ||
751118611Snjl        (FileId == ASL_FILE_C_INCLUDE_OUTPUT))
752118611Snjl    {
753118611Snjl        return;
754118611Snjl    }
755118611Snjl
756118611Snjl    LsFlushListingBuffer (FileId);
757118611Snjl    Gbl_CurrentAmlOffset = 0;
758118611Snjl
759118611Snjl    /* Flush any remaining text in the source file */
760118611Snjl
761118611Snjl    if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
762118611Snjl    {
763118611Snjl        FlPrintFile (FileId, "    /*\n");
764118611Snjl    }
765118611Snjl
766118611Snjl    while (LsWriteOneSourceLine (FileId))
767118611Snjl    { ; }
768118611Snjl
769118611Snjl    if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
770118611Snjl    {
771118611Snjl        FlPrintFile (FileId, "\n     */\n    };\n");
772118611Snjl    }
773118611Snjl
774118611Snjl    FlPrintFile (FileId, "\n");
775118611Snjl
776118611Snjl    if (FileId == ASL_FILE_LISTING_OUTPUT)
777118611Snjl    {
778118611Snjl        /* Print a summary of the compile exceptions */
779118611Snjl
780118611Snjl        FlPrintFile (FileId, "\n\nSummary of errors and warnings\n\n");
781118611Snjl        AePrintErrorLog (FileId);
782118611Snjl        FlPrintFile (FileId, "\n\n");
783118611Snjl        UtDisplaySummary (FileId);
784118611Snjl        FlPrintFile (FileId, "\n\n");
785118611Snjl    }
786118611Snjl}
787118611Snjl
788118611Snjl
789118611Snjl/*******************************************************************************
790118611Snjl *
791118611Snjl * FUNCTION:    LsWriteSourceLines
792118611Snjl *
793118611Snjl * PARAMETERS:  ToLineNumber            -
794118611Snjl *              ToLogicalLineNumber     - Write up to this source line number
795118611Snjl *              FileId                  - ID of current listing file
796118611Snjl *
797118611Snjl * RETURN:      None
798118611Snjl *
799118611Snjl * DESCRIPTION: Read then write source lines to the listing file until we have
800118611Snjl *              reached the specified logical (cumulative) line number.  This
801118611Snjl *              automatically echos out comment blocks and other non-AML
802118611Snjl *              generating text until we get to the actual AML-generating line
803118611Snjl *              of ASL code specified by the logical line number.
804118611Snjl *
805118611Snjl ******************************************************************************/
806118611Snjl
807118611Snjlvoid
808118611SnjlLsWriteSourceLines (
809118611Snjl    UINT32                  ToLineNumber,
810118611Snjl    UINT32                  ToLogicalLineNumber,
811118611Snjl    UINT32                  FileId)
812118611Snjl{
813118611Snjl
814118611Snjl    if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) ||
815118611Snjl        (FileId == ASL_FILE_C_INCLUDE_OUTPUT))
816118611Snjl    {
817118611Snjl        return;
818118611Snjl    }
819118611Snjl
820118611Snjl    Gbl_CurrentLine = ToLogicalLineNumber;
821118611Snjl
822118611Snjl    /* Flush any hex bytes remaining from the last opcode */
823118611Snjl
824118611Snjl    LsFlushListingBuffer (FileId);
825118611Snjl
826118611Snjl    /*
827118611Snjl     * Read lines and write them as long as we are not caught up
828118611Snjl     */
829118611Snjl    if (Gbl_SourceLine < Gbl_CurrentLine)
830118611Snjl    {
831118611Snjl        /*
832118611Snjl         * If we just completed writing some AML hex bytes, output a linefeed
833118611Snjl         * to add some whitespace for readability.
834118611Snjl         */
835118611Snjl        if (Gbl_HexBytesWereWritten)
836118611Snjl        {
837118611Snjl            FlPrintFile (FileId, "\n");
838118611Snjl            Gbl_HexBytesWereWritten = FALSE;
839118611Snjl        }
840118611Snjl
841118611Snjl        if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
842118611Snjl        {
843118611Snjl            FlPrintFile (FileId, "    /*\n");
844118611Snjl        }
845118611Snjl
846118611Snjl        /*
847118611Snjl         * Write one line at a time until we have reached the target line #
848118611Snjl         */
849118611Snjl        while ((Gbl_SourceLine < Gbl_CurrentLine) &&
850118611Snjl                LsWriteOneSourceLine (FileId))
851118611Snjl        { ; }
852118611Snjl
853118611Snjl        if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
854118611Snjl        {
855118611Snjl            FlPrintFile (FileId, "     */");
856118611Snjl        }
857118611Snjl        FlPrintFile (FileId, "\n");
858118611Snjl    }
859118611Snjl}
860118611Snjl
861118611Snjl
862118611Snjl/*******************************************************************************
863118611Snjl *
864118611Snjl * FUNCTION:    LsWriteNodeToListing
865118611Snjl *
866118611Snjl * PARAMETERS:  Op            - Parse node to write to the listing file.
867118611Snjl *              FileId          - ID of current listing file
868118611Snjl *
869118611Snjl * RETURN:      None.
870118611Snjl *
871118611Snjl * DESCRIPTION: Write "a node" to the listing file.  This means to
872118611Snjl *              1) Write out all of the source text associated with the node
873118611Snjl *              2) Write out all of the AML bytes associated with the node
874118611Snjl *              3) Write any compiler exceptions associated with the node
875118611Snjl *
876118611Snjl ******************************************************************************/
877118611Snjl
878118611Snjlvoid
879118611SnjlLsWriteNodeToListing (
880118611Snjl    ACPI_PARSE_OBJECT       *Op,
881118611Snjl    UINT32                  FileId)
882118611Snjl{
883118611Snjl    const ACPI_OPCODE_INFO  *OpInfo;
884118611Snjl    UINT32                  OpClass;
885118611Snjl    char                    *Pathname;
886118611Snjl    UINT32                  Length;
887118611Snjl    UINT32                  i;
888118611Snjl
889118611Snjl
890118611Snjl    OpInfo  = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
891118611Snjl    OpClass = OpInfo->Class;
892118611Snjl
893118611Snjl    /* TBD: clean this up with a single flag that says: I start a named output block */
894118611Snjl
895118611Snjl    if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
896118611Snjl    {
897118611Snjl        switch (Op->Asl.ParseOpcode)
898118611Snjl        {
899118611Snjl        case PARSEOP_DEFINITIONBLOCK:
900118611Snjl        case PARSEOP_METHODCALL:
901118611Snjl        case PARSEOP_INCLUDE:
902118611Snjl        case PARSEOP_INCLUDE_END:
903118611Snjl        case PARSEOP_DEFAULT_ARG:
904118611Snjl
905118611Snjl            break;
906118611Snjl
907118611Snjl        default:
908118611Snjl            switch (OpClass)
909118611Snjl            {
910118611Snjl            case AML_CLASS_NAMED_OBJECT:
911118611Snjl                switch (Op->Asl.AmlOpcode)
912118611Snjl                {
913118611Snjl                case AML_SCOPE_OP:
914118611Snjl                case AML_ALIAS_OP:
915118611Snjl                    break;
916118611Snjl
917118611Snjl                default:
918118611Snjl                    if (Op->Asl.ExternalName)
919118611Snjl                    {
920118611Snjl                        LsFlushListingBuffer (FileId);
921118611Snjl                        FlPrintFile (FileId, "    };\n");
922118611Snjl                    }
923118611Snjl                    break;
924118611Snjl                }
925118611Snjl                break;
926118611Snjl
927118611Snjl            default:
928118611Snjl                /* Don't care about other objects */
929118611Snjl                break;
930118611Snjl            }
931118611Snjl            break;
932118611Snjl        }
933118611Snjl    }
934118611Snjl
935118611Snjl
936118611Snjl    /* These cases do not have a corresponding AML opcode */
937118611Snjl
938118611Snjl    switch (Op->Asl.ParseOpcode)
939118611Snjl    {
940118611Snjl    case PARSEOP_DEFINITIONBLOCK:
941118611Snjl
942118611Snjl        LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine, FileId);
943118611Snjl
944118611Snjl        /* Use the table Signature and TableId to build a unique name */
945118611Snjl
946118611Snjl        if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
947118611Snjl        {
948118611Snjl            FlPrintFile (FileId, "%s_%s_Header \\\n",
949118611Snjl                Gbl_TableSignature, Gbl_TableId);
950118611Snjl        }
951118611Snjl        if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
952118611Snjl        {
953118611Snjl            FlPrintFile (FileId, "    unsigned char    %s_%s_Header [] = \n    {\n",
954118611Snjl                Gbl_TableSignature, Gbl_TableId);
955118611Snjl        }
956118611Snjl        if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT)
957118611Snjl        {
958118611Snjl            FlPrintFile (FileId, "extrn %s_%s_Header : byte\n",
959118611Snjl                Gbl_TableSignature, Gbl_TableId);
960118611Snjl        }
961118611Snjl        if (FileId == ASL_FILE_C_INCLUDE_OUTPUT)
962118611Snjl        {
963118611Snjl            FlPrintFile (FileId, "extern unsigned char    %s_%s_Header [];\n",
964118611Snjl                Gbl_TableSignature, Gbl_TableId);
965118611Snjl        }
966118611Snjl        return;
967118611Snjl
968118611Snjl
969118611Snjl    case PARSEOP_METHODCALL:
970118611Snjl
971118611Snjl        LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber, FileId);
972118611Snjl        return;
973118611Snjl
974118611Snjl
975118611Snjl    case PARSEOP_INCLUDE:
976118611Snjl
977118611Snjl        /*
978118611Snjl         * Flush everything up to and including the include source line
979118611Snjl         */
980118611Snjl        LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber, FileId);
981118611Snjl
982118611Snjl        /*
983118611Snjl         * Create a new listing node and push it
984118611Snjl         */
985118611Snjl        LsPushNode (Op->Asl.Child->Asl.Value.String);
986118611Snjl        return;
987118611Snjl
988118611Snjl
989118611Snjl    case PARSEOP_INCLUDE_END:
990118611Snjl
991118611Snjl        /*
992118611Snjl         * Flush out the rest of the include file
993118611Snjl         */
994118611Snjl        LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber, FileId);
995118611Snjl
996118611Snjl        /*
997118611Snjl         * Pop off this listing node and go back to the parent file
998118611Snjl         */
999118611Snjl        LsPopNode ();
1000118611Snjl        return;
1001118611Snjl
1002118611Snjl
1003118611Snjl    case PARSEOP_DEFAULT_ARG:
1004118611Snjl        return;
1005118611Snjl
1006118611Snjl
1007118611Snjl    default:
1008118611Snjl        /* All other opcodes have an AML opcode */
1009118611Snjl        break;
1010118611Snjl    }
1011118611Snjl
1012118611Snjl    /*
1013118611Snjl     * Otherwise, we look at the AML opcode because we can
1014118611Snjl     * switch on the opcode type, getting an entire class
1015118611Snjl     * at once
1016118611Snjl     */
1017118611Snjl    switch (OpClass)
1018118611Snjl    {
1019118611Snjl    case AML_CLASS_ARGUMENT:       /* argument type only */
1020118611Snjl    case AML_CLASS_INTERNAL:
1021118611Snjl
1022118611Snjl        break;
1023118611Snjl
1024118611Snjl
1025118611Snjl    case AML_CLASS_NAMED_OBJECT:
1026118611Snjl
1027118611Snjl        switch (Op->Asl.AmlOpcode)
1028118611Snjl        {
1029118611Snjl        case AML_FIELD_OP:
1030118611Snjl        case AML_INDEX_FIELD_OP:
1031118611Snjl        case AML_BANK_FIELD_OP:
1032118611Snjl        case AML_NAME_OP:
1033118611Snjl
1034118611Snjl            /* For fields, we want to dump all the AML after the entire definition */
1035118611Snjl
1036118611Snjl            LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine, FileId);
1037118611Snjl            break;
1038118611Snjl
1039118611Snjl        default:
1040118611Snjl            LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber, FileId);
1041118611Snjl            break;
1042118611Snjl        }
1043118611Snjl
1044118611Snjl        switch (Op->Asl.AmlOpcode)
1045118611Snjl        {
1046118611Snjl        case AML_SCOPE_OP:
1047118611Snjl        case AML_ALIAS_OP:
1048118611Snjl
1049118611Snjl            /* These opcodes do not declare a new object, ignore them */
1050118611Snjl
1051118611Snjl            break;
1052118611Snjl
1053118611Snjl        default:
1054118611Snjl
1055118611Snjl            /* All other named object opcodes come here */
1056118611Snjl
1057118611Snjl            switch (FileId)
1058118611Snjl            {
1059118611Snjl            case ASL_FILE_ASM_SOURCE_OUTPUT:
1060118611Snjl            case ASL_FILE_C_SOURCE_OUTPUT:
1061118611Snjl            case ASL_FILE_ASM_INCLUDE_OUTPUT:
1062118611Snjl            case ASL_FILE_C_INCLUDE_OUTPUT:
1063118611Snjl
1064118611Snjl                /*
1065118611Snjl                 * For named objects, we will create a valid symbol so that the
1066118611Snjl                 * AML code can be referenced from C or ASM
1067118611Snjl                 */
1068118611Snjl                if (Op->Asl.ExternalName)
1069118611Snjl                {
1070118611Snjl                    /* Get the full pathname associated with this node */
1071118611Snjl
1072118611Snjl                    Pathname = AcpiNsGetExternalPathname (Op->Asl.Node);
1073118611Snjl                    Length = strlen (Pathname);
1074118611Snjl                    if (Length >= 4)
1075118611Snjl                    {
1076118611Snjl                        /* Convert all dots in the path to underscores */
1077118611Snjl
1078118611Snjl                        for (i = 0; i < Length; i++)
1079118611Snjl                        {
1080118611Snjl                            if (Pathname[i] == '.')
1081118611Snjl                            {
1082118611Snjl                                Pathname[i] = '_';
1083118611Snjl                            }
1084118611Snjl                        }
1085118611Snjl
1086118611Snjl                        /* Create the appropriate symbol in the output file */
1087118611Snjl
1088118611Snjl                        if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
1089118611Snjl                        {
1090118611Snjl                            FlPrintFile (FileId, "%s_%s_%s  \\\n",
1091118611Snjl                                Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1092118611Snjl                        }
1093118611Snjl                        if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
1094118611Snjl                        {
1095118611Snjl                            FlPrintFile (FileId, "    unsigned char    %s_%s_%s [] = \n    {\n",
1096118611Snjl                                Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1097118611Snjl                        }
1098118611Snjl                        if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT)
1099118611Snjl                        {
1100118611Snjl                            FlPrintFile (FileId, "extrn %s_%s_%s : byte\n",
1101118611Snjl                                Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1102118611Snjl                        }
1103118611Snjl                        if (FileId == ASL_FILE_C_INCLUDE_OUTPUT)
1104118611Snjl                        {
1105118611Snjl                            FlPrintFile (FileId, "extern unsigned char    %s_%s_%s [];\n",
1106118611Snjl                                Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1107118611Snjl                        }
1108118611Snjl                    }
1109118611Snjl                    ACPI_MEM_FREE (Pathname);
1110118611Snjl                }
1111118611Snjl                break;
1112118611Snjl
1113118611Snjl            default:
1114118611Snjl                /* Nothing to do for listing file */
1115118611Snjl                break;
1116118611Snjl            }
1117118611Snjl        }
1118118611Snjl        break;
1119118611Snjl
1120118611Snjl    case AML_CLASS_EXECUTE:
1121118611Snjl    case AML_CLASS_CREATE:
1122118611Snjl    default:
1123118611Snjl
1124118611Snjl        LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber, FileId);
1125118611Snjl        break;
1126118611Snjl
1127118611Snjl    case AML_CLASS_UNKNOWN:
1128118611Snjl        break;
1129118611Snjl    }
1130118611Snjl}
1131118611Snjl
1132118611Snjl
1133118611Snjl/*******************************************************************************
1134118611Snjl *
1135118611Snjl * FUNCTION:    LsDoHexOutput
1136118611Snjl *
1137118611Snjl * PARAMETERS:  None
1138118611Snjl *
1139118611Snjl * RETURN:      None.
1140118611Snjl *
1141118611Snjl * DESCRIPTION: Create the hex output file.
1142118611Snjl *
1143118611Snjl ******************************************************************************/
1144118611Snjl
1145118611Snjlvoid
1146118611SnjlLsDoHexOutput (void)
1147118611Snjl{
1148118611Snjl
1149118611Snjl    switch (Gbl_HexOutputFlag)
1150118611Snjl    {
1151118611Snjl    case HEX_OUTPUT_C:
1152118611Snjl
1153118611Snjl        LsDoHexOutputC ();
1154118611Snjl        break;
1155118611Snjl
1156118611Snjl    case HEX_OUTPUT_ASM:
1157118611Snjl
1158118611Snjl        LsDoHexOutputAsm ();
1159118611Snjl        break;
1160118611Snjl
1161118611Snjl    default:
1162118611Snjl        /* No other output types supported */
1163118611Snjl        break;
1164118611Snjl    }
1165118611Snjl}
1166118611Snjl
1167118611Snjl
1168118611Snjl/*******************************************************************************
1169118611Snjl *
1170118611Snjl * FUNCTION:    LsDoHexOutputC
1171118611Snjl *
1172118611Snjl * PARAMETERS:  None
1173118611Snjl *
1174118611Snjl * RETURN:      None.
1175118611Snjl *
1176118611Snjl * DESCRIPTION: Create the hex output file.  This is the same data as the AML
1177118611Snjl *              output file, but formatted into hex/ascii bytes suitable for
1178118611Snjl *              inclusion into a C source file.
1179118611Snjl *
1180118611Snjl ******************************************************************************/
1181118611Snjl
1182118611Snjlvoid
1183118611SnjlLsDoHexOutputC (void)
1184118611Snjl{
1185118611Snjl    UINT32                  j;
1186118611Snjl    UINT8                   FileByte[HEX_TABLE_LINE_SIZE];
1187118611Snjl    UINT8                   Buffer[4];
1188118611Snjl    UINT32                  Offset = 0;
1189118611Snjl
1190118611Snjl
1191118611Snjl    FlPrintFile (ASL_FILE_HEX_OUTPUT, " * C source code output\n *\n */\n");
1192118611Snjl    FlPrintFile (ASL_FILE_HEX_OUTPUT, "unsigned char AmlCode[] = \n{\n");
1193118611Snjl
1194118611Snjl    /* Start at the beginning of the AML file */
1195118611Snjl
1196118611Snjl    FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
1197118611Snjl
1198118611Snjl    /* Process all AML bytes in the AML file */
1199118611Snjl
1200118611Snjl    j = 0;
1201118611Snjl    while (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte[j], 1) == AE_OK)
1202118611Snjl    {
1203118611Snjl        if (j == 0)
1204118611Snjl        {
1205118611Snjl            FlPrintFile (ASL_FILE_HEX_OUTPUT, "    ");
1206118611Snjl        }
1207118611Snjl
1208118611Snjl        /*
1209118611Snjl         * Convert each AML byte to hex
1210118611Snjl         */
1211118611Snjl        UtConvertByteToHex (FileByte[j], Buffer);
1212118611Snjl        FlWriteFile (ASL_FILE_HEX_OUTPUT, Buffer, 4);
1213118611Snjl        FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
1214118611Snjl
1215118611Snjl        /* An occasional linefeed improves readability */
1216118611Snjl
1217118611Snjl        Offset++;
1218118611Snjl        j++;
1219118611Snjl
1220118611Snjl        if (j >= HEX_TABLE_LINE_SIZE)
1221118611Snjl        {
1222118611Snjl            /* End of line, emit the ascii dump of the entire line */
1223118611Snjl
1224118611Snjl            FlPrintFile (ASL_FILE_HEX_OUTPUT, "  /* %8.8X", Offset - HEX_TABLE_LINE_SIZE);
1225118611Snjl
1226118611Snjl            /* Write the ASCII character associated with each of the bytes */
1227118611Snjl
1228118611Snjl            LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, HEX_TABLE_LINE_SIZE, FileByte);
1229118611Snjl            FlPrintFile (ASL_FILE_HEX_OUTPUT, " */\n");
1230118611Snjl
1231118611Snjl            /* Start new line */
1232118611Snjl
1233118611Snjl            j = 0;
1234118611Snjl        }
1235118611Snjl
1236118611Snjl    }
1237118611Snjl
1238118611Snjl    FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n};\n");
1239118611Snjl    FlCloseFile (ASL_FILE_HEX_OUTPUT);
1240118611Snjl}
1241118611Snjl
1242118611Snjl
1243118611Snjl/*******************************************************************************
1244118611Snjl *
1245118611Snjl * FUNCTION:    LsDoHexOutputAsm
1246118611Snjl *
1247118611Snjl * PARAMETERS:  None
1248118611Snjl *
1249118611Snjl * RETURN:      None.
1250118611Snjl *
1251118611Snjl * DESCRIPTION: Create the hex output file.  This is the same data as the AML
1252118611Snjl *              output file, but formatted into hex/ascii bytes suitable for
1253118611Snjl *              inclusion into a ASM source file.
1254118611Snjl *
1255118611Snjl ******************************************************************************/
1256118611Snjl
1257118611Snjlvoid
1258118611SnjlLsDoHexOutputAsm (
1259118611Snjl    void)
1260118611Snjl{
1261118611Snjl    UINT32                  j;
1262118611Snjl    UINT8                   FileByte[HEX_TABLE_LINE_SIZE];
1263118611Snjl    UINT8                   Buffer[4];
1264118611Snjl    UINT32                  Offset = 0;
1265118611Snjl    BOOLEAN                 DoComma = FALSE;
1266118611Snjl
1267118611Snjl
1268118611Snjl    FlPrintFile (ASL_FILE_HEX_OUTPUT, "; Assembly code source output\n;\n");
1269118611Snjl
1270118611Snjl    /* Start at the beginning of the AML file */
1271118611Snjl
1272118611Snjl    FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
1273118611Snjl
1274118611Snjl    /* Process all AML bytes in the AML file */
1275118611Snjl
1276118611Snjl    j = 0;
1277118611Snjl    while (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte[j], 1) == AE_OK)
1278118611Snjl    {
1279118611Snjl        if (j == 0)
1280118611Snjl        {
1281118611Snjl            FlPrintFile (ASL_FILE_HEX_OUTPUT, "  db  ");
1282118611Snjl        }
1283118611Snjl        else if (DoComma)
1284118611Snjl        {
1285118611Snjl            FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
1286118611Snjl            DoComma = FALSE;
1287118611Snjl        }
1288118611Snjl
1289118611Snjl        /*
1290118611Snjl         * Convert each AML byte to hex
1291118611Snjl         */
1292118611Snjl        UtConvertByteToAsmHex (FileByte[j], Buffer);
1293118611Snjl        FlWriteFile (ASL_FILE_HEX_OUTPUT, Buffer, 4);
1294118611Snjl
1295118611Snjl        /* An occasional linefeed improves readability */
1296118611Snjl
1297118611Snjl        Offset++;
1298118611Snjl        j++;
1299118611Snjl        if (j >= HEX_TABLE_LINE_SIZE)
1300118611Snjl        {
1301118611Snjl            FlPrintFile (ASL_FILE_HEX_OUTPUT, "  ;%8.8X", Offset - HEX_TABLE_LINE_SIZE);
1302118611Snjl
1303118611Snjl            /* Write the ASCII character associated with each of the bytes */
1304118611Snjl
1305118611Snjl            LsDumpAscii (ASL_FILE_HEX_OUTPUT, HEX_TABLE_LINE_SIZE, FileByte);
1306118611Snjl            FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n");
1307118611Snjl            j = 0;
1308118611Snjl        }
1309118611Snjl        else
1310118611Snjl        {
1311118611Snjl            DoComma = TRUE;
1312118611Snjl        }
1313118611Snjl    }
1314118611Snjl
1315118611Snjl    FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n");
1316118611Snjl    FlCloseFile (ASL_FILE_HEX_OUTPUT);
1317118611Snjl}
1318118611Snjl
1319118611Snjl
1320