asllisting.c revision 241973
1118611Snjl/******************************************************************************
2118611Snjl *
3118611Snjl * Module Name: asllisting - Listing file generation
4118611Snjl *
5118611Snjl *****************************************************************************/
6118611Snjl
7217365Sjkim/*
8229989Sjkim * Copyright (C) 2000 - 2012, Intel Corp.
9118611Snjl * All rights reserved.
10118611Snjl *
11217365Sjkim * Redistribution and use in source and binary forms, with or without
12217365Sjkim * modification, are permitted provided that the following conditions
13217365Sjkim * are met:
14217365Sjkim * 1. Redistributions of source code must retain the above copyright
15217365Sjkim *    notice, this list of conditions, and the following disclaimer,
16217365Sjkim *    without modification.
17217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18217365Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
19217365Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
20217365Sjkim *    including a substantially similar Disclaimer requirement for further
21217365Sjkim *    binary redistribution.
22217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
23217365Sjkim *    of any contributors may be used to endorse or promote products derived
24217365Sjkim *    from this software without specific prior written permission.
25118611Snjl *
26217365Sjkim * Alternatively, this software may be distributed under the terms of the
27217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
28217365Sjkim * Software Foundation.
29118611Snjl *
30217365Sjkim * NO WARRANTY
31217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41217365Sjkim * POSSIBILITY OF SUCH DAMAGES.
42217365Sjkim */
43118611Snjl
44118611Snjl
45151937Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h>
46118611Snjl#include "aslcompiler.y.h"
47193529Sjkim#include <contrib/dev/acpica/include/amlcode.h>
48193529Sjkim#include <contrib/dev/acpica/include/acparser.h>
49193529Sjkim#include <contrib/dev/acpica/include/acnamesp.h>
50118611Snjl
51118611Snjl#define _COMPONENT          ACPI_COMPILER
52118611Snjl        ACPI_MODULE_NAME    ("aslisting")
53118611Snjl
54151937Sjkim/* Local prototypes */
55118611Snjl
56151937Sjkimstatic void
57151937SjkimLsDumpAscii (
58151937Sjkim    UINT32                  FileId,
59151937Sjkim    UINT32                  Count,
60151937Sjkim    UINT8                   *Buffer);
61151937Sjkim
62151937Sjkimstatic void
63151937SjkimLsDumpAsciiInComment (
64151937Sjkim    UINT32                  FileId,
65151937Sjkim    UINT32                  Count,
66151937Sjkim    UINT8                   *Buffer);
67151937Sjkim
68151937Sjkimstatic ACPI_STATUS
69151937SjkimLsAmlListingWalk (
70151937Sjkim    ACPI_PARSE_OBJECT       *Op,
71151937Sjkim    UINT32                  Level,
72151937Sjkim    void                    *Context);
73151937Sjkim
74151937Sjkimstatic void
75151937SjkimLsGenerateListing (
76151937Sjkim    UINT32                  FileId);
77151937Sjkim
78151937Sjkimstatic void
79151937SjkimLsPushNode (
80151937Sjkim    char                    *Filename);
81151937Sjkim
82151937Sjkimstatic ASL_LISTING_NODE *
83151937SjkimLsPopNode (
84151937Sjkim    void);
85151937Sjkim
86151937Sjkimstatic void
87151937SjkimLsCheckException (
88151937Sjkim    UINT32                  LineNumber,
89151937Sjkim    UINT32                  FileId);
90151937Sjkim
91151937Sjkimstatic void
92151937SjkimLsFlushListingBuffer (
93151937Sjkim    UINT32                  FileId);
94151937Sjkim
95151937Sjkimstatic void
96151937SjkimLsWriteListingHexBytes (
97151937Sjkim    UINT8                   *Buffer,
98151937Sjkim    UINT32                  Length,
99151937Sjkim    UINT32                  FileId);
100151937Sjkim
101151937Sjkimstatic UINT32
102151937SjkimLsWriteOneSourceLine (
103151937Sjkim    UINT32                  FileId);
104151937Sjkim
105151937Sjkimstatic void
106151937SjkimLsFinishSourceListing (
107151937Sjkim    UINT32                  FileId);
108151937Sjkim
109151937Sjkimstatic void
110151937SjkimLsWriteSourceLines (
111151937Sjkim    UINT32                  ToLineNumber,
112151937Sjkim    UINT32                  ToLogicalLineNumber,
113151937Sjkim    UINT32                  FileId);
114151937Sjkim
115151937Sjkimstatic void
116151937SjkimLsWriteNodeToListing (
117151937Sjkim    ACPI_PARSE_OBJECT       *Op,
118151937Sjkim    UINT32                  FileId);
119151937Sjkim
120151937Sjkimstatic void
121151937SjkimLsDoHexOutputC (
122151937Sjkim    void);
123151937Sjkim
124151937Sjkimstatic void
125151937SjkimLsDoHexOutputAsm (
126151937Sjkim    void);
127151937Sjkim
128207344Sjkimstatic void
129207344SjkimLsDoHexOutputAsl (
130207344Sjkim    void);
131207344Sjkim
132212761Sjkimstatic ACPI_STATUS
133193529SjkimLsTreeWriteWalk (
134193529Sjkim    ACPI_PARSE_OBJECT       *Op,
135193529Sjkim    UINT32                  Level,
136193529Sjkim    void                    *Context);
137151937Sjkim
138193529Sjkim
139118611Snjl/*******************************************************************************
140118611Snjl *
141167802Sjkim * FUNCTION:    LsTreeWriteWalk
142167802Sjkim *
143167802Sjkim * PARAMETERS:  ASL_WALK_CALLBACK
144167802Sjkim *
145167802Sjkim *
146167802Sjkim * RETURN:      None.
147167802Sjkim *
148167802Sjkim * DESCRIPTION: Dump entire parse tree, for compiler debug only
149167802Sjkim *
150167802Sjkim ******************************************************************************/
151167802Sjkim
152212761Sjkimstatic ACPI_STATUS
153167802SjkimLsTreeWriteWalk (
154167802Sjkim    ACPI_PARSE_OBJECT       *Op,
155167802Sjkim    UINT32                  Level,
156167802Sjkim    void                    *Context)
157167802Sjkim{
158167802Sjkim
159167802Sjkim    /* Debug output */
160167802Sjkim
161167802Sjkim    DbgPrint (ASL_TREE_OUTPUT,
162167802Sjkim        "%5.5d [%2d]", Op->Asl.LogicalLineNumber, Level);
163167802Sjkim    UtPrintFormattedName (Op->Asl.ParseOpcode, Level);
164167802Sjkim
165167802Sjkim
166167802Sjkim    DbgPrint (ASL_TREE_OUTPUT, "\n");
167167802Sjkim    return (AE_OK);
168167802Sjkim}
169167802Sjkim
170167802Sjkim
171167802Sjkimvoid
172167802SjkimLsDumpParseTree (
173167802Sjkim    void)
174167802Sjkim{
175167802Sjkim
176167802Sjkim    if (!Gbl_DebugFlag)
177167802Sjkim    {
178167802Sjkim        return;
179167802Sjkim    }
180167802Sjkim
181167802Sjkim    DbgPrint (ASL_TREE_OUTPUT, "\nOriginal parse tree from parser:\n\n");
182167802Sjkim    TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
183167802Sjkim        LsTreeWriteWalk, NULL, NULL);
184167802Sjkim}
185167802Sjkim
186167802Sjkim
187167802Sjkim/*******************************************************************************
188167802Sjkim *
189118611Snjl * FUNCTION:    LsDumpAscii
190118611Snjl *
191118611Snjl * PARAMETERS:  FileId          - ID of current listing file
192118611Snjl *              Count           - Number of bytes to convert
193118611Snjl *              Buffer          - Buffer of bytes to convert
194118611Snjl *
195118611Snjl * RETURN:      None.
196118611Snjl *
197118611Snjl * DESCRIPTION: Convert hex bytes to ascii
198118611Snjl *
199118611Snjl ******************************************************************************/
200118611Snjl
201151937Sjkimstatic void
202118611SnjlLsDumpAscii (
203118611Snjl    UINT32                  FileId,
204118611Snjl    UINT32                  Count,
205118611Snjl    UINT8                   *Buffer)
206118611Snjl{
207118611Snjl    UINT8                   BufChar;
208118611Snjl    UINT32                  i;
209118611Snjl
210118611Snjl
211118611Snjl    FlPrintFile (FileId, "    \"");
212118611Snjl    for (i = 0; i < Count; i++)
213118611Snjl    {
214118611Snjl        BufChar = Buffer[i];
215118611Snjl        if (isprint (BufChar))
216118611Snjl        {
217118611Snjl            FlPrintFile (FileId, "%c", BufChar);
218118611Snjl        }
219118611Snjl        else
220118611Snjl        {
221118611Snjl            /* Not a printable character, just put out a dot */
222118611Snjl
223118611Snjl            FlPrintFile (FileId, ".");
224118611Snjl        }
225118611Snjl    }
226118611Snjl    FlPrintFile (FileId, "\"");
227118611Snjl}
228118611Snjl
229118611Snjl
230118611Snjl/*******************************************************************************
231118611Snjl *
232118611Snjl * FUNCTION:    LsDumpAsciiInComment
233118611Snjl *
234118611Snjl * PARAMETERS:  FileId          - ID of current listing file
235118611Snjl *              Count           - Number of bytes to convert
236118611Snjl *              Buffer          - Buffer of bytes to convert
237118611Snjl *
238118611Snjl * RETURN:      None.
239118611Snjl *
240118611Snjl * DESCRIPTION: Convert hex bytes to ascii
241118611Snjl *
242118611Snjl ******************************************************************************/
243118611Snjl
244151937Sjkimstatic void
245118611SnjlLsDumpAsciiInComment (
246118611Snjl    UINT32                  FileId,
247118611Snjl    UINT32                  Count,
248118611Snjl    UINT8                   *Buffer)
249118611Snjl{
250118611Snjl    UINT8                   BufChar = 0;
251118611Snjl    UINT8                   LastChar;
252118611Snjl    UINT32                  i;
253118611Snjl
254118611Snjl
255118611Snjl    FlPrintFile (FileId, "    \"");
256118611Snjl    for (i = 0; i < Count; i++)
257118611Snjl    {
258118611Snjl        LastChar = BufChar;
259118611Snjl        BufChar = Buffer[i];
260118611Snjl
261118611Snjl        if (isprint (BufChar))
262118611Snjl        {
263118611Snjl            /* Handle embedded C comment sequences */
264118611Snjl
265118611Snjl            if (((LastChar == '*') && (BufChar == '/')) ||
266118611Snjl                ((LastChar == '/') && (BufChar == '*')))
267118611Snjl            {
268118611Snjl                /* Insert a space to break the sequence */
269118611Snjl
270118611Snjl                FlPrintFile (FileId, ".", BufChar);
271118611Snjl            }
272118611Snjl
273118611Snjl            FlPrintFile (FileId, "%c", BufChar);
274118611Snjl        }
275118611Snjl        else
276118611Snjl        {
277118611Snjl            /* Not a printable character, just put out a dot */
278118611Snjl
279118611Snjl            FlPrintFile (FileId, ".");
280118611Snjl        }
281118611Snjl    }
282118611Snjl    FlPrintFile (FileId, "\"");
283118611Snjl}
284118611Snjl
285118611Snjl
286118611Snjl/*******************************************************************************
287118611Snjl *
288118611Snjl * FUNCTION:    LsAmlListingWalk
289118611Snjl *
290118611Snjl * PARAMETERS:  ASL_WALK_CALLBACK
291118611Snjl *
292118611Snjl * RETURN:      Status
293118611Snjl *
294118611Snjl * DESCRIPTION: Process one node during a listing file generation.
295118611Snjl *
296118611Snjl ******************************************************************************/
297118611Snjl
298151937Sjkimstatic ACPI_STATUS
299118611SnjlLsAmlListingWalk (
300118611Snjl    ACPI_PARSE_OBJECT       *Op,
301118611Snjl    UINT32                  Level,
302118611Snjl    void                    *Context)
303118611Snjl{
304118611Snjl    UINT8                   FileByte;
305118611Snjl    UINT32                  i;
306167802Sjkim    UINT32                  FileId = (UINT32) ACPI_TO_INTEGER (Context);
307118611Snjl
308118611Snjl
309118611Snjl    LsWriteNodeToListing (Op, FileId);
310118611Snjl
311167802Sjkim    if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DATA)
312167802Sjkim    {
313167802Sjkim        /* Buffer is a resource template, don't dump the data all at once */
314167802Sjkim
315167802Sjkim        return (AE_OK);
316167802Sjkim    }
317167802Sjkim
318118611Snjl    /* Write the hex bytes to the listing file(s) (if requested) */
319118611Snjl
320118611Snjl    for (i = 0; i < Op->Asl.FinalAmlLength; i++)
321118611Snjl    {
322118611Snjl        if (ACPI_FAILURE (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte, 1)))
323118611Snjl        {
324118611Snjl            FlFileError (ASL_FILE_AML_OUTPUT, ASL_MSG_READ);
325118611Snjl            AslAbort ();
326118611Snjl        }
327118611Snjl        LsWriteListingHexBytes (&FileByte, 1, FileId);
328118611Snjl    }
329118611Snjl
330118611Snjl    return (AE_OK);
331118611Snjl}
332118611Snjl
333118611Snjl
334118611Snjl/*******************************************************************************
335118611Snjl *
336118611Snjl * FUNCTION:    LsGenerateListing
337118611Snjl *
338118611Snjl * PARAMETERS:  FileId      - ID of listing file
339118611Snjl *
340118611Snjl * RETURN:      None
341118611Snjl *
342241973Sjkim * DESCRIPTION: Generate a listing file. This can be one of the several types
343118611Snjl *              of "listings" supported.
344118611Snjl *
345118611Snjl ******************************************************************************/
346118611Snjl
347151937Sjkimstatic void
348118611SnjlLsGenerateListing (
349118611Snjl    UINT32                  FileId)
350118611Snjl{
351118611Snjl
352118611Snjl    /* Start at the beginning of both the source and AML files */
353118611Snjl
354118611Snjl    FlSeekFile (ASL_FILE_SOURCE_OUTPUT, 0);
355118611Snjl    FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
356118611Snjl    Gbl_SourceLine = 0;
357118611Snjl    Gbl_CurrentHexColumn = 0;
358118611Snjl    LsPushNode (Gbl_Files[ASL_FILE_INPUT].Filename);
359118611Snjl
360118611Snjl    /* Process all parse nodes */
361118611Snjl
362118611Snjl    TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, LsAmlListingWalk,
363118611Snjl                        NULL, (void *) ACPI_TO_POINTER (FileId));
364118611Snjl
365118611Snjl    /* Final processing */
366118611Snjl
367118611Snjl    LsFinishSourceListing (FileId);
368118611Snjl}
369118611Snjl
370118611Snjl
371118611Snjl/*******************************************************************************
372118611Snjl *
373118611Snjl * FUNCTION:    LsDoListings
374118611Snjl *
375118611Snjl * PARAMETERS:  None.
376118611Snjl *
377118611Snjl * RETURN:      None
378118611Snjl *
379118611Snjl * DESCRIPTION: Generate all requested listing files.
380118611Snjl *
381118611Snjl ******************************************************************************/
382118611Snjl
383118611Snjlvoid
384151937SjkimLsDoListings (
385151937Sjkim    void)
386118611Snjl{
387118611Snjl
388118611Snjl    if (Gbl_C_OutputFlag)
389118611Snjl    {
390118611Snjl        LsGenerateListing (ASL_FILE_C_SOURCE_OUTPUT);
391118611Snjl    }
392118611Snjl
393118611Snjl    if (Gbl_ListingFlag)
394118611Snjl    {
395118611Snjl        LsGenerateListing (ASL_FILE_LISTING_OUTPUT);
396118611Snjl    }
397118611Snjl
398118611Snjl    if (Gbl_AsmOutputFlag)
399118611Snjl    {
400118611Snjl        LsGenerateListing (ASL_FILE_ASM_SOURCE_OUTPUT);
401118611Snjl    }
402118611Snjl
403118611Snjl    if (Gbl_C_IncludeOutputFlag)
404118611Snjl    {
405118611Snjl        LsGenerateListing (ASL_FILE_C_INCLUDE_OUTPUT);
406118611Snjl    }
407118611Snjl
408118611Snjl    if (Gbl_AsmIncludeOutputFlag)
409118611Snjl    {
410118611Snjl        LsGenerateListing (ASL_FILE_ASM_INCLUDE_OUTPUT);
411118611Snjl    }
412118611Snjl}
413118611Snjl
414118611Snjl
415118611Snjl/*******************************************************************************
416118611Snjl *
417118611Snjl * FUNCTION:    LsPushNode
418118611Snjl *
419118611Snjl * PARAMETERS:  Filename        - Pointer to the include filename
420118611Snjl *
421118611Snjl * RETURN:      None
422118611Snjl *
423241973Sjkim * DESCRIPTION: Push a listing node on the listing/include file stack. This
424118611Snjl *              stack enables tracking of include files (infinitely nested)
425118611Snjl *              and resumption of the listing of the parent file when the
426118611Snjl *              include file is finished.
427118611Snjl *
428118611Snjl ******************************************************************************/
429118611Snjl
430151937Sjkimstatic void
431118611SnjlLsPushNode (
432118611Snjl    char                    *Filename)
433118611Snjl{
434118611Snjl    ASL_LISTING_NODE        *Lnode;
435118611Snjl
436118611Snjl
437118611Snjl    /* Create a new node */
438118611Snjl
439118611Snjl    Lnode = UtLocalCalloc (sizeof (ASL_LISTING_NODE));
440118611Snjl
441118611Snjl    /* Initialize */
442118611Snjl
443118611Snjl    Lnode->Filename = Filename;
444118611Snjl    Lnode->LineNumber = 0;
445118611Snjl
446118611Snjl    /* Link (push) */
447118611Snjl
448118611Snjl    Lnode->Next = Gbl_ListingNode;
449118611Snjl    Gbl_ListingNode = Lnode;
450118611Snjl}
451118611Snjl
452118611Snjl
453118611Snjl/*******************************************************************************
454118611Snjl *
455118611Snjl * FUNCTION:    LsPopNode
456118611Snjl *
457118611Snjl * PARAMETERS:  None
458118611Snjl *
459118611Snjl * RETURN:      List head after current head is popped off
460118611Snjl *
461118611Snjl * DESCRIPTION: Pop the current head of the list, free it, and return the
462118611Snjl *              next node on the stack (the new current node).
463118611Snjl *
464118611Snjl ******************************************************************************/
465118611Snjl
466151937Sjkimstatic ASL_LISTING_NODE *
467151937SjkimLsPopNode (
468151937Sjkim    void)
469118611Snjl{
470118611Snjl    ASL_LISTING_NODE        *Lnode;
471118611Snjl
472118611Snjl
473118611Snjl    /* Just grab the node at the head of the list */
474118611Snjl
475118611Snjl    Lnode = Gbl_ListingNode;
476118611Snjl    if ((!Lnode) ||
477118611Snjl        (!Lnode->Next))
478118611Snjl    {
479151937Sjkim        AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, NULL,
480151937Sjkim            "Could not pop empty listing stack");
481241973Sjkim        return (Gbl_ListingNode);
482118611Snjl    }
483118611Snjl
484118611Snjl    Gbl_ListingNode = Lnode->Next;
485167802Sjkim    ACPI_FREE (Lnode);
486118611Snjl
487118611Snjl    /* New "Current" node is the new head */
488118611Snjl
489118611Snjl    return (Gbl_ListingNode);
490118611Snjl}
491118611Snjl
492118611Snjl
493118611Snjl/*******************************************************************************
494118611Snjl *
495118611Snjl * FUNCTION:    LsCheckException
496118611Snjl *
497118611Snjl * PARAMETERS:  LineNumber          - Current logical (cumulative) line #
498118611Snjl *              FileId              - ID of output listing file
499118611Snjl *
500118611Snjl * RETURN:      None
501118611Snjl *
502118611Snjl * DESCRIPTION: Check if there is an exception for this line, and if there is,
503241973Sjkim *              put it in the listing immediately. Handles multiple errors
504241973Sjkim *              per line. Gbl_NextError points to the next error in the
505118611Snjl *              sorted (by line #) list of compile errors/warnings.
506118611Snjl *
507118611Snjl ******************************************************************************/
508118611Snjl
509151937Sjkimstatic void
510118611SnjlLsCheckException (
511118611Snjl    UINT32                  LineNumber,
512118611Snjl    UINT32                  FileId)
513118611Snjl{
514118611Snjl
515118611Snjl    if ((!Gbl_NextError) ||
516118611Snjl        (LineNumber < Gbl_NextError->LogicalLineNumber ))
517118611Snjl    {
518118611Snjl        return;
519118611Snjl    }
520118611Snjl
521118611Snjl    /* Handle multiple errors per line */
522118611Snjl
523118611Snjl    if (FileId == ASL_FILE_LISTING_OUTPUT)
524118611Snjl    {
525118611Snjl        while (Gbl_NextError &&
526118611Snjl              (LineNumber >= Gbl_NextError->LogicalLineNumber))
527118611Snjl        {
528118611Snjl            AePrintException (FileId, Gbl_NextError, "\n[****iasl****]\n");
529118611Snjl
530118611Snjl            Gbl_NextError = Gbl_NextError->Next;
531118611Snjl        }
532118611Snjl
533118611Snjl        FlPrintFile (FileId, "\n");
534118611Snjl    }
535118611Snjl}
536118611Snjl
537118611Snjl
538118611Snjl/*******************************************************************************
539118611Snjl *
540118611Snjl * FUNCTION:    LsFlushListingBuffer
541118611Snjl *
542118611Snjl * PARAMETERS:  FileId          - ID of the listing file
543118611Snjl *
544118611Snjl * RETURN:      None
545118611Snjl *
546118611Snjl * DESCRIPTION: Flush out the current contents of the 16-byte hex AML code
547241973Sjkim *              buffer. Usually called at the termination of a single line
548118611Snjl *              of source code or when the buffer is full.
549118611Snjl *
550118611Snjl ******************************************************************************/
551118611Snjl
552151937Sjkimstatic void
553118611SnjlLsFlushListingBuffer (
554118611Snjl    UINT32                  FileId)
555118611Snjl{
556118611Snjl    UINT32                  i;
557118611Snjl
558118611Snjl
559118611Snjl    if (Gbl_CurrentHexColumn == 0)
560118611Snjl    {
561118611Snjl        return;
562118611Snjl    }
563118611Snjl
564118611Snjl    /* Write the hex bytes */
565118611Snjl
566118611Snjl    switch (FileId)
567118611Snjl    {
568118611Snjl    case ASL_FILE_LISTING_OUTPUT:
569118611Snjl
570118611Snjl        for (i = 0; i < Gbl_CurrentHexColumn; i++)
571118611Snjl        {
572118611Snjl            FlPrintFile (FileId, "%2.2X ", Gbl_AmlBuffer[i]);
573118611Snjl        }
574118611Snjl
575118611Snjl        for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 3); i++)
576118611Snjl        {
577118611Snjl            FlWriteFile (FileId, ".", 1);
578118611Snjl        }
579118611Snjl
580118611Snjl        /* Write the ASCII character associated with each of the bytes */
581118611Snjl
582118611Snjl        LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer);
583118611Snjl        break;
584118611Snjl
585118611Snjl
586118611Snjl    case ASL_FILE_ASM_SOURCE_OUTPUT:
587118611Snjl
588118611Snjl        for (i = 0; i < Gbl_CurrentHexColumn; i++)
589118611Snjl        {
590118611Snjl            if (i > 0)
591118611Snjl            {
592118611Snjl                FlPrintFile (FileId, ",");
593118611Snjl            }
594118611Snjl            FlPrintFile (FileId, "0%2.2Xh", Gbl_AmlBuffer[i]);
595118611Snjl        }
596118611Snjl
597118611Snjl        for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++)
598118611Snjl        {
599118611Snjl            FlWriteFile (FileId, " ", 1);
600118611Snjl        }
601118611Snjl
602151937Sjkim        FlPrintFile (FileId, "  ;%8.8X",
603151937Sjkim            Gbl_CurrentAmlOffset - HEX_LISTING_LINE_SIZE);
604118611Snjl
605118611Snjl        /* Write the ASCII character associated with each of the bytes */
606118611Snjl
607118611Snjl        LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer);
608118611Snjl        break;
609118611Snjl
610118611Snjl
611118611Snjl    case ASL_FILE_C_SOURCE_OUTPUT:
612118611Snjl
613118611Snjl        for (i = 0; i < Gbl_CurrentHexColumn; i++)
614118611Snjl        {
615118611Snjl            FlPrintFile (FileId, "0x%2.2X,", Gbl_AmlBuffer[i]);
616118611Snjl        }
617118611Snjl
618118611Snjl        for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++)
619118611Snjl        {
620118611Snjl            FlWriteFile (FileId, " ", 1);
621118611Snjl        }
622118611Snjl
623151937Sjkim        FlPrintFile (FileId, "    /* %8.8X",
624151937Sjkim            Gbl_CurrentAmlOffset - HEX_LISTING_LINE_SIZE);
625118611Snjl
626118611Snjl        /* Write the ASCII character associated with each of the bytes */
627118611Snjl
628118611Snjl        LsDumpAsciiInComment (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer);
629118611Snjl        FlPrintFile (FileId, " */");
630118611Snjl        break;
631118611Snjl
632118611Snjl    default:
633118611Snjl        /* No other types supported */
634118611Snjl        return;
635118611Snjl    }
636118611Snjl
637118611Snjl    FlPrintFile (FileId, "\n");
638118611Snjl
639118611Snjl    Gbl_CurrentHexColumn = 0;
640118611Snjl    Gbl_HexBytesWereWritten = TRUE;
641118611Snjl}
642118611Snjl
643118611Snjl
644118611Snjl/*******************************************************************************
645118611Snjl *
646118611Snjl * FUNCTION:    LsWriteListingHexBytes
647118611Snjl *
648118611Snjl * PARAMETERS:  Buffer          - AML code buffer
649118611Snjl *              Length          - Number of AML bytes to write
650118611Snjl *              FileId          - ID of current listing file.
651118611Snjl *
652118611Snjl * RETURN:      None
653118611Snjl *
654118611Snjl * DESCRIPTION: Write the contents of the AML buffer to the listing file via
655241973Sjkim *              the listing buffer. The listing buffer is flushed every 16
656118611Snjl *              AML bytes.
657118611Snjl *
658118611Snjl ******************************************************************************/
659118611Snjl
660151937Sjkimstatic void
661118611SnjlLsWriteListingHexBytes (
662118611Snjl    UINT8                   *Buffer,
663118611Snjl    UINT32                  Length,
664118611Snjl    UINT32                  FileId)
665118611Snjl{
666118611Snjl    UINT32                  i;
667118611Snjl
668118611Snjl
669118611Snjl    /* Transfer all requested bytes */
670118611Snjl
671118611Snjl    for (i = 0; i < Length; i++)
672118611Snjl    {
673118611Snjl        /* Print line header when buffer is empty */
674118611Snjl
675118611Snjl        if (Gbl_CurrentHexColumn == 0)
676118611Snjl        {
677118611Snjl            if (Gbl_HasIncludeFiles)
678118611Snjl            {
679118611Snjl                FlPrintFile (FileId, "%*s", 10, " ");
680118611Snjl            }
681118611Snjl
682118611Snjl            switch (FileId)
683118611Snjl            {
684118611Snjl            case ASL_FILE_LISTING_OUTPUT:
685118611Snjl
686118611Snjl                FlPrintFile (FileId, "%8.8X....", Gbl_CurrentAmlOffset);
687118611Snjl                break;
688118611Snjl
689118611Snjl            case ASL_FILE_ASM_SOURCE_OUTPUT:
690118611Snjl
691118611Snjl                FlPrintFile (FileId, "    db ");
692118611Snjl                break;
693118611Snjl
694118611Snjl            case ASL_FILE_C_SOURCE_OUTPUT:
695118611Snjl
696118611Snjl                FlPrintFile (FileId, "        ");
697118611Snjl                break;
698118611Snjl
699118611Snjl            default:
700118611Snjl                /* No other types supported */
701118611Snjl                return;
702118611Snjl            }
703118611Snjl        }
704118611Snjl
705118611Snjl        /* Transfer AML byte and update counts */
706118611Snjl
707118611Snjl        Gbl_AmlBuffer[Gbl_CurrentHexColumn] = Buffer[i];
708118611Snjl
709118611Snjl        Gbl_CurrentHexColumn++;
710118611Snjl        Gbl_CurrentAmlOffset++;
711118611Snjl
712118611Snjl        /* Flush buffer when it is full */
713118611Snjl
714118611Snjl        if (Gbl_CurrentHexColumn >= HEX_LISTING_LINE_SIZE)
715118611Snjl        {
716118611Snjl            LsFlushListingBuffer (FileId);
717118611Snjl        }
718118611Snjl    }
719118611Snjl}
720118611Snjl
721118611Snjl
722118611Snjl/*******************************************************************************
723118611Snjl *
724118611Snjl * FUNCTION:    LsWriteOneSourceLine
725118611Snjl *
726118611Snjl * PARAMETERS:  FileID          - ID of current listing file
727118611Snjl *
728118611Snjl * RETURN:      FALSE on EOF (input source file), TRUE otherwise
729118611Snjl *
730118611Snjl * DESCRIPTION: Read one line from the input source file and echo it to the
731118611Snjl *              listing file, prefixed with the line number, and if the source
732118611Snjl *              file contains include files, prefixed with the current filename
733118611Snjl *
734118611Snjl ******************************************************************************/
735118611Snjl
736151937Sjkimstatic UINT32
737118611SnjlLsWriteOneSourceLine (
738118611Snjl    UINT32                  FileId)
739118611Snjl{
740118611Snjl    UINT8                   FileByte;
741118611Snjl
742118611Snjl
743118611Snjl    Gbl_SourceLine++;
744118611Snjl    Gbl_ListingNode->LineNumber++;
745118611Snjl
746118611Snjl    if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
747118611Snjl    {
748118611Snjl        FlPrintFile (FileId, "     *");
749118611Snjl    }
750118611Snjl    if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
751118611Snjl    {
752118611Snjl        FlPrintFile (FileId, "; ");
753118611Snjl    }
754118611Snjl
755118611Snjl    if (Gbl_HasIncludeFiles)
756118611Snjl    {
757118611Snjl        /*
758118611Snjl         * This file contains "include" statements, print the current
759118611Snjl         * filename and line number within the current file
760118611Snjl         */
761118611Snjl        FlPrintFile (FileId, "%12s %5d....",
762118611Snjl                    Gbl_ListingNode->Filename, Gbl_ListingNode->LineNumber);
763118611Snjl    }
764118611Snjl    else
765118611Snjl    {
766118611Snjl        /* No include files, just print the line number */
767118611Snjl
768118611Snjl        FlPrintFile (FileId, "%8d....", Gbl_SourceLine);
769118611Snjl    }
770118611Snjl
771118611Snjl    /* Read one line (up to a newline or EOF) */
772118611Snjl
773118611Snjl    while (FlReadFile (ASL_FILE_SOURCE_OUTPUT, &FileByte, 1) == AE_OK)
774118611Snjl    {
775118611Snjl        if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
776118611Snjl        {
777118611Snjl            if (FileByte == '/')
778118611Snjl            {
779118611Snjl                FileByte = '*';
780118611Snjl            }
781118611Snjl        }
782118611Snjl
783118611Snjl        FlWriteFile (FileId, &FileByte, 1);
784118611Snjl        if (FileByte == '\n')
785118611Snjl        {
786118611Snjl            /*
787118611Snjl             * Check if an error occurred on this source line during the compile.
788118611Snjl             * If so, we print the error message after the source line.
789118611Snjl             */
790118611Snjl            LsCheckException (Gbl_SourceLine, FileId);
791118611Snjl            return (1);
792118611Snjl        }
793118611Snjl    }
794118611Snjl
795118611Snjl    /* EOF on the input file was reached */
796118611Snjl
797118611Snjl    return (0);
798118611Snjl}
799118611Snjl
800118611Snjl
801118611Snjl/*******************************************************************************
802118611Snjl *
803118611Snjl * FUNCTION:    LsFinishSourceListing
804118611Snjl *
805118611Snjl * PARAMETERS:  FileId          - ID of current listing file.
806118611Snjl *
807118611Snjl * RETURN:      None
808118611Snjl *
809241973Sjkim * DESCRIPTION: Cleanup routine for the listing file. Flush the hex AML
810118611Snjl *              listing buffer, and flush out any remaining lines in the
811118611Snjl *              source input file.
812118611Snjl *
813118611Snjl ******************************************************************************/
814118611Snjl
815151937Sjkimstatic void
816118611SnjlLsFinishSourceListing (
817118611Snjl    UINT32                  FileId)
818118611Snjl{
819118611Snjl
820118611Snjl    if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) ||
821118611Snjl        (FileId == ASL_FILE_C_INCLUDE_OUTPUT))
822118611Snjl    {
823118611Snjl        return;
824118611Snjl    }
825118611Snjl
826118611Snjl    LsFlushListingBuffer (FileId);
827118611Snjl    Gbl_CurrentAmlOffset = 0;
828118611Snjl
829118611Snjl    /* Flush any remaining text in the source file */
830118611Snjl
831118611Snjl    if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
832118611Snjl    {
833118611Snjl        FlPrintFile (FileId, "    /*\n");
834118611Snjl    }
835118611Snjl
836118611Snjl    while (LsWriteOneSourceLine (FileId))
837118611Snjl    { ; }
838118611Snjl
839118611Snjl    if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
840118611Snjl    {
841118611Snjl        FlPrintFile (FileId, "\n     */\n    };\n");
842118611Snjl    }
843118611Snjl
844118611Snjl    FlPrintFile (FileId, "\n");
845118611Snjl
846118611Snjl    if (FileId == ASL_FILE_LISTING_OUTPUT)
847118611Snjl    {
848118611Snjl        /* Print a summary of the compile exceptions */
849118611Snjl
850118611Snjl        FlPrintFile (FileId, "\n\nSummary of errors and warnings\n\n");
851118611Snjl        AePrintErrorLog (FileId);
852228110Sjkim        FlPrintFile (FileId, "\n");
853118611Snjl        UtDisplaySummary (FileId);
854228110Sjkim        FlPrintFile (FileId, "\n");
855118611Snjl    }
856118611Snjl}
857118611Snjl
858118611Snjl
859118611Snjl/*******************************************************************************
860118611Snjl *
861118611Snjl * FUNCTION:    LsWriteSourceLines
862118611Snjl *
863118611Snjl * PARAMETERS:  ToLineNumber            -
864118611Snjl *              ToLogicalLineNumber     - Write up to this source line number
865118611Snjl *              FileId                  - ID of current listing file
866118611Snjl *
867118611Snjl * RETURN:      None
868118611Snjl *
869118611Snjl * DESCRIPTION: Read then write source lines to the listing file until we have
870241973Sjkim *              reached the specified logical (cumulative) line number. This
871118611Snjl *              automatically echos out comment blocks and other non-AML
872118611Snjl *              generating text until we get to the actual AML-generating line
873118611Snjl *              of ASL code specified by the logical line number.
874118611Snjl *
875118611Snjl ******************************************************************************/
876118611Snjl
877151937Sjkimstatic void
878118611SnjlLsWriteSourceLines (
879118611Snjl    UINT32                  ToLineNumber,
880118611Snjl    UINT32                  ToLogicalLineNumber,
881118611Snjl    UINT32                  FileId)
882118611Snjl{
883118611Snjl
884118611Snjl    if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) ||
885118611Snjl        (FileId == ASL_FILE_C_INCLUDE_OUTPUT))
886118611Snjl    {
887118611Snjl        return;
888118611Snjl    }
889118611Snjl
890118611Snjl    Gbl_CurrentLine = ToLogicalLineNumber;
891118611Snjl
892118611Snjl    /* Flush any hex bytes remaining from the last opcode */
893118611Snjl
894118611Snjl    LsFlushListingBuffer (FileId);
895118611Snjl
896151937Sjkim    /* Read lines and write them as long as we are not caught up */
897151937Sjkim
898118611Snjl    if (Gbl_SourceLine < Gbl_CurrentLine)
899118611Snjl    {
900118611Snjl        /*
901118611Snjl         * If we just completed writing some AML hex bytes, output a linefeed
902118611Snjl         * to add some whitespace for readability.
903118611Snjl         */
904118611Snjl        if (Gbl_HexBytesWereWritten)
905118611Snjl        {
906118611Snjl            FlPrintFile (FileId, "\n");
907118611Snjl            Gbl_HexBytesWereWritten = FALSE;
908118611Snjl        }
909118611Snjl
910118611Snjl        if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
911118611Snjl        {
912118611Snjl            FlPrintFile (FileId, "    /*\n");
913118611Snjl        }
914118611Snjl
915151937Sjkim        /* Write one line at a time until we have reached the target line # */
916151937Sjkim
917118611Snjl        while ((Gbl_SourceLine < Gbl_CurrentLine) &&
918118611Snjl                LsWriteOneSourceLine (FileId))
919118611Snjl        { ; }
920118611Snjl
921118611Snjl        if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
922118611Snjl        {
923118611Snjl            FlPrintFile (FileId, "     */");
924118611Snjl        }
925118611Snjl        FlPrintFile (FileId, "\n");
926118611Snjl    }
927118611Snjl}
928118611Snjl
929118611Snjl
930118611Snjl/*******************************************************************************
931118611Snjl *
932118611Snjl * FUNCTION:    LsWriteNodeToListing
933118611Snjl *
934118611Snjl * PARAMETERS:  Op            - Parse node to write to the listing file.
935118611Snjl *              FileId          - ID of current listing file
936118611Snjl *
937118611Snjl * RETURN:      None.
938118611Snjl *
939241973Sjkim * DESCRIPTION: Write "a node" to the listing file. This means to
940118611Snjl *              1) Write out all of the source text associated with the node
941118611Snjl *              2) Write out all of the AML bytes associated with the node
942118611Snjl *              3) Write any compiler exceptions associated with the node
943118611Snjl *
944118611Snjl ******************************************************************************/
945118611Snjl
946151937Sjkimstatic void
947118611SnjlLsWriteNodeToListing (
948118611Snjl    ACPI_PARSE_OBJECT       *Op,
949118611Snjl    UINT32                  FileId)
950118611Snjl{
951118611Snjl    const ACPI_OPCODE_INFO  *OpInfo;
952118611Snjl    UINT32                  OpClass;
953118611Snjl    char                    *Pathname;
954118611Snjl    UINT32                  Length;
955118611Snjl    UINT32                  i;
956118611Snjl
957118611Snjl
958118611Snjl    OpInfo  = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
959118611Snjl    OpClass = OpInfo->Class;
960118611Snjl
961151937Sjkim    /* TBD: clean this up with a single flag that says:
962151937Sjkim     * I start a named output block
963151937Sjkim     */
964118611Snjl    if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
965118611Snjl    {
966118611Snjl        switch (Op->Asl.ParseOpcode)
967118611Snjl        {
968118611Snjl        case PARSEOP_DEFINITIONBLOCK:
969118611Snjl        case PARSEOP_METHODCALL:
970118611Snjl        case PARSEOP_INCLUDE:
971118611Snjl        case PARSEOP_INCLUDE_END:
972118611Snjl        case PARSEOP_DEFAULT_ARG:
973118611Snjl
974118611Snjl            break;
975118611Snjl
976118611Snjl        default:
977118611Snjl            switch (OpClass)
978118611Snjl            {
979118611Snjl            case AML_CLASS_NAMED_OBJECT:
980118611Snjl                switch (Op->Asl.AmlOpcode)
981118611Snjl                {
982118611Snjl                case AML_SCOPE_OP:
983118611Snjl                case AML_ALIAS_OP:
984118611Snjl                    break;
985118611Snjl
986118611Snjl                default:
987118611Snjl                    if (Op->Asl.ExternalName)
988118611Snjl                    {
989118611Snjl                        LsFlushListingBuffer (FileId);
990118611Snjl                        FlPrintFile (FileId, "    };\n");
991118611Snjl                    }
992118611Snjl                    break;
993118611Snjl                }
994118611Snjl                break;
995118611Snjl
996118611Snjl            default:
997118611Snjl                /* Don't care about other objects */
998118611Snjl                break;
999118611Snjl            }
1000118611Snjl            break;
1001118611Snjl        }
1002118611Snjl    }
1003118611Snjl
1004118611Snjl    /* These cases do not have a corresponding AML opcode */
1005118611Snjl
1006118611Snjl    switch (Op->Asl.ParseOpcode)
1007118611Snjl    {
1008118611Snjl    case PARSEOP_DEFINITIONBLOCK:
1009118611Snjl
1010118611Snjl        LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine, FileId);
1011118611Snjl
1012118611Snjl        /* Use the table Signature and TableId to build a unique name */
1013118611Snjl
1014118611Snjl        if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
1015118611Snjl        {
1016151937Sjkim            FlPrintFile (FileId,
1017151937Sjkim                "%s_%s_Header \\\n",
1018118611Snjl                Gbl_TableSignature, Gbl_TableId);
1019118611Snjl        }
1020118611Snjl        if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
1021118611Snjl        {
1022151937Sjkim            FlPrintFile (FileId,
1023151937Sjkim                "    unsigned char    %s_%s_Header [] =\n    {\n",
1024118611Snjl                Gbl_TableSignature, Gbl_TableId);
1025118611Snjl        }
1026118611Snjl        if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT)
1027118611Snjl        {
1028151937Sjkim            FlPrintFile (FileId,
1029151937Sjkim                "extrn %s_%s_Header : byte\n",
1030118611Snjl                Gbl_TableSignature, Gbl_TableId);
1031118611Snjl        }
1032118611Snjl        if (FileId == ASL_FILE_C_INCLUDE_OUTPUT)
1033118611Snjl        {
1034151937Sjkim            FlPrintFile (FileId,
1035151937Sjkim                "extern unsigned char    %s_%s_Header [];\n",
1036118611Snjl                Gbl_TableSignature, Gbl_TableId);
1037118611Snjl        }
1038118611Snjl        return;
1039118611Snjl
1040118611Snjl
1041118611Snjl    case PARSEOP_METHODCALL:
1042118611Snjl
1043151937Sjkim        LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1044151937Sjkim            FileId);
1045118611Snjl        return;
1046118611Snjl
1047118611Snjl
1048118611Snjl    case PARSEOP_INCLUDE:
1049118611Snjl
1050151937Sjkim        /* Flush everything up to and including the include source line */
1051118611Snjl
1052151937Sjkim        LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1053151937Sjkim            FileId);
1054151937Sjkim
1055151937Sjkim        /* Create a new listing node and push it */
1056151937Sjkim
1057118611Snjl        LsPushNode (Op->Asl.Child->Asl.Value.String);
1058118611Snjl        return;
1059118611Snjl
1060118611Snjl
1061118611Snjl    case PARSEOP_INCLUDE_END:
1062118611Snjl
1063151937Sjkim        /* Flush out the rest of the include file */
1064118611Snjl
1065151937Sjkim        LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1066151937Sjkim            FileId);
1067151937Sjkim
1068151937Sjkim        /* Pop off this listing node and go back to the parent file */
1069151937Sjkim
1070151937Sjkim        (void) LsPopNode ();
1071118611Snjl        return;
1072118611Snjl
1073118611Snjl
1074118611Snjl    case PARSEOP_DEFAULT_ARG:
1075167802Sjkim
1076167802Sjkim        if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
1077167802Sjkim        {
1078167802Sjkim            LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.EndLogicalLine,
1079167802Sjkim                FileId);
1080167802Sjkim        }
1081118611Snjl        return;
1082118611Snjl
1083118611Snjl
1084118611Snjl    default:
1085118611Snjl        /* All other opcodes have an AML opcode */
1086118611Snjl        break;
1087118611Snjl    }
1088118611Snjl
1089118611Snjl    /*
1090118611Snjl     * Otherwise, we look at the AML opcode because we can
1091118611Snjl     * switch on the opcode type, getting an entire class
1092118611Snjl     * at once
1093118611Snjl     */
1094118611Snjl    switch (OpClass)
1095118611Snjl    {
1096118611Snjl    case AML_CLASS_ARGUMENT:       /* argument type only */
1097118611Snjl    case AML_CLASS_INTERNAL:
1098118611Snjl
1099118611Snjl        break;
1100118611Snjl
1101118611Snjl
1102118611Snjl    case AML_CLASS_NAMED_OBJECT:
1103118611Snjl
1104118611Snjl        switch (Op->Asl.AmlOpcode)
1105118611Snjl        {
1106118611Snjl        case AML_FIELD_OP:
1107118611Snjl        case AML_INDEX_FIELD_OP:
1108118611Snjl        case AML_BANK_FIELD_OP:
1109118611Snjl
1110151937Sjkim            /*
1111151937Sjkim             * For fields, we want to dump all the AML after the
1112151937Sjkim             * entire definition
1113151937Sjkim             */
1114151937Sjkim            LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine,
1115151937Sjkim                FileId);
1116118611Snjl            break;
1117118611Snjl
1118167802Sjkim        case AML_NAME_OP:
1119167802Sjkim
1120167802Sjkim            if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
1121167802Sjkim            {
1122167802Sjkim                LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1123167802Sjkim                    FileId);
1124167802Sjkim            }
1125167802Sjkim            else
1126167802Sjkim            {
1127167802Sjkim                /*
1128167802Sjkim                 * For fields, we want to dump all the AML after the
1129167802Sjkim                 * entire definition
1130167802Sjkim                 */
1131167802Sjkim                LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine,
1132167802Sjkim                    FileId);
1133167802Sjkim            }
1134167802Sjkim            break;
1135167802Sjkim
1136118611Snjl        default:
1137151937Sjkim            LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1138151937Sjkim                FileId);
1139118611Snjl            break;
1140118611Snjl        }
1141118611Snjl
1142118611Snjl        switch (Op->Asl.AmlOpcode)
1143118611Snjl        {
1144118611Snjl        case AML_SCOPE_OP:
1145118611Snjl        case AML_ALIAS_OP:
1146118611Snjl
1147118611Snjl            /* These opcodes do not declare a new object, ignore them */
1148118611Snjl
1149118611Snjl            break;
1150118611Snjl
1151118611Snjl        default:
1152118611Snjl
1153118611Snjl            /* All other named object opcodes come here */
1154118611Snjl
1155118611Snjl            switch (FileId)
1156118611Snjl            {
1157118611Snjl            case ASL_FILE_ASM_SOURCE_OUTPUT:
1158118611Snjl            case ASL_FILE_C_SOURCE_OUTPUT:
1159118611Snjl            case ASL_FILE_ASM_INCLUDE_OUTPUT:
1160118611Snjl            case ASL_FILE_C_INCLUDE_OUTPUT:
1161118611Snjl
1162118611Snjl                /*
1163118611Snjl                 * For named objects, we will create a valid symbol so that the
1164118611Snjl                 * AML code can be referenced from C or ASM
1165118611Snjl                 */
1166118611Snjl                if (Op->Asl.ExternalName)
1167118611Snjl                {
1168118611Snjl                    /* Get the full pathname associated with this node */
1169118611Snjl
1170118611Snjl                    Pathname = AcpiNsGetExternalPathname (Op->Asl.Node);
1171118611Snjl                    Length = strlen (Pathname);
1172118611Snjl                    if (Length >= 4)
1173118611Snjl                    {
1174118611Snjl                        /* Convert all dots in the path to underscores */
1175118611Snjl
1176118611Snjl                        for (i = 0; i < Length; i++)
1177118611Snjl                        {
1178118611Snjl                            if (Pathname[i] == '.')
1179118611Snjl                            {
1180118611Snjl                                Pathname[i] = '_';
1181118611Snjl                            }
1182118611Snjl                        }
1183118611Snjl
1184118611Snjl                        /* Create the appropriate symbol in the output file */
1185118611Snjl
1186118611Snjl                        if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
1187118611Snjl                        {
1188151937Sjkim                            FlPrintFile (FileId,
1189151937Sjkim                                "%s_%s_%s  \\\n",
1190118611Snjl                                Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1191118611Snjl                        }
1192118611Snjl                        if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
1193118611Snjl                        {
1194151937Sjkim                            FlPrintFile (FileId,
1195151937Sjkim                                "    unsigned char    %s_%s_%s [] =\n    {\n",
1196118611Snjl                                Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1197118611Snjl                        }
1198118611Snjl                        if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT)
1199118611Snjl                        {
1200151937Sjkim                            FlPrintFile (FileId,
1201151937Sjkim                                "extrn %s_%s_%s : byte\n",
1202118611Snjl                                Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1203118611Snjl                        }
1204118611Snjl                        if (FileId == ASL_FILE_C_INCLUDE_OUTPUT)
1205118611Snjl                        {
1206151937Sjkim                            FlPrintFile (FileId,
1207151937Sjkim                                "extern unsigned char    %s_%s_%s [];\n",
1208118611Snjl                                Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1209118611Snjl                        }
1210118611Snjl                    }
1211167802Sjkim                    ACPI_FREE (Pathname);
1212118611Snjl                }
1213118611Snjl                break;
1214118611Snjl
1215118611Snjl            default:
1216118611Snjl                /* Nothing to do for listing file */
1217118611Snjl                break;
1218118611Snjl            }
1219118611Snjl        }
1220118611Snjl        break;
1221118611Snjl
1222118611Snjl    case AML_CLASS_EXECUTE:
1223118611Snjl    case AML_CLASS_CREATE:
1224118611Snjl    default:
1225118611Snjl
1226167802Sjkim        if ((Op->Asl.ParseOpcode == PARSEOP_BUFFER) &&
1227167802Sjkim            (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC))
1228167802Sjkim        {
1229167802Sjkim            return;
1230167802Sjkim        }
1231167802Sjkim
1232151937Sjkim        LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1233151937Sjkim            FileId);
1234118611Snjl        break;
1235118611Snjl
1236118611Snjl    case AML_CLASS_UNKNOWN:
1237118611Snjl        break;
1238118611Snjl    }
1239118611Snjl}
1240118611Snjl
1241118611Snjl
1242118611Snjl/*******************************************************************************
1243118611Snjl *
1244118611Snjl * FUNCTION:    LsDoHexOutput
1245118611Snjl *
1246118611Snjl * PARAMETERS:  None
1247118611Snjl *
1248118611Snjl * RETURN:      None.
1249118611Snjl *
1250118611Snjl * DESCRIPTION: Create the hex output file.
1251118611Snjl *
1252118611Snjl ******************************************************************************/
1253118611Snjl
1254118611Snjlvoid
1255151937SjkimLsDoHexOutput (
1256151937Sjkim    void)
1257118611Snjl{
1258118611Snjl
1259118611Snjl    switch (Gbl_HexOutputFlag)
1260118611Snjl    {
1261118611Snjl    case HEX_OUTPUT_C:
1262118611Snjl
1263118611Snjl        LsDoHexOutputC ();
1264118611Snjl        break;
1265118611Snjl
1266118611Snjl    case HEX_OUTPUT_ASM:
1267118611Snjl
1268118611Snjl        LsDoHexOutputAsm ();
1269118611Snjl        break;
1270118611Snjl
1271207344Sjkim    case HEX_OUTPUT_ASL:
1272207344Sjkim
1273207344Sjkim        LsDoHexOutputAsl ();
1274207344Sjkim        break;
1275207344Sjkim
1276118611Snjl    default:
1277118611Snjl        /* No other output types supported */
1278118611Snjl        break;
1279118611Snjl    }
1280118611Snjl}
1281118611Snjl
1282118611Snjl
1283118611Snjl/*******************************************************************************
1284118611Snjl *
1285118611Snjl * FUNCTION:    LsDoHexOutputC
1286118611Snjl *
1287118611Snjl * PARAMETERS:  None
1288118611Snjl *
1289118611Snjl * RETURN:      None.
1290118611Snjl *
1291241973Sjkim * DESCRIPTION: Create the hex output file. This is the same data as the AML
1292118611Snjl *              output file, but formatted into hex/ascii bytes suitable for
1293118611Snjl *              inclusion into a C source file.
1294118611Snjl *
1295118611Snjl ******************************************************************************/
1296118611Snjl
1297151937Sjkimstatic void
1298151937SjkimLsDoHexOutputC (
1299151937Sjkim    void)
1300118611Snjl{
1301207344Sjkim    UINT8                   FileData[HEX_TABLE_LINE_SIZE];
1302207344Sjkim    UINT32                  LineLength;
1303118611Snjl    UINT32                  Offset = 0;
1304207344Sjkim    UINT32                  AmlFileSize;
1305207344Sjkim    UINT32                  i;
1306118611Snjl
1307118611Snjl
1308207344Sjkim    /* Get AML size, seek back to start */
1309207344Sjkim
1310207344Sjkim    AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
1311228110Sjkim    FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
1312207344Sjkim
1313207344Sjkim    FlPrintFile (ASL_FILE_HEX_OUTPUT, " * C source code output\n");
1314207344Sjkim    FlPrintFile (ASL_FILE_HEX_OUTPUT, " * AML code block contains 0x%X bytes\n *\n */\n",
1315207344Sjkim        AmlFileSize);
1316151937Sjkim    FlPrintFile (ASL_FILE_HEX_OUTPUT, "unsigned char AmlCode[] =\n{\n");
1317118611Snjl
1318207344Sjkim    while (Offset < AmlFileSize)
1319207344Sjkim    {
1320207344Sjkim        /* Read enough bytes needed for one output line */
1321118611Snjl
1322207344Sjkim        LineLength = fread (FileData, 1, HEX_TABLE_LINE_SIZE,
1323207344Sjkim                        Gbl_Files[ASL_FILE_AML_OUTPUT].Handle);
1324207344Sjkim        if (!LineLength)
1325207344Sjkim        {
1326207344Sjkim            break;
1327207344Sjkim        }
1328118611Snjl
1329207344Sjkim        FlPrintFile (ASL_FILE_HEX_OUTPUT, "    ");
1330118611Snjl
1331207344Sjkim        for (i = 0; i < LineLength; i++)
1332118611Snjl        {
1333207344Sjkim            /*
1334207344Sjkim             * Print each hex byte.
1335207344Sjkim             * Add a comma until the very last byte of the AML file
1336207344Sjkim             * (Some C compilers complain about a trailing comma)
1337207344Sjkim             */
1338207344Sjkim            FlPrintFile (ASL_FILE_HEX_OUTPUT, "0x%2.2X", FileData[i]);
1339207344Sjkim            if ((Offset + i + 1) < AmlFileSize)
1340207344Sjkim            {
1341207344Sjkim                FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
1342207344Sjkim            }
1343207344Sjkim            else
1344207344Sjkim            {
1345207344Sjkim                FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
1346207344Sjkim            }
1347118611Snjl        }
1348118611Snjl
1349207344Sjkim        /* Add fill spaces if needed for last line */
1350151937Sjkim
1351207344Sjkim        if (LineLength < HEX_TABLE_LINE_SIZE)
1352207344Sjkim        {
1353207344Sjkim            FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
1354207344Sjkim                5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
1355207344Sjkim        }
1356118611Snjl
1357207344Sjkim        /* Emit the offset and ascii dump for the entire line */
1358118611Snjl
1359207344Sjkim        FlPrintFile (ASL_FILE_HEX_OUTPUT, "  /* %8.8X", Offset);
1360207344Sjkim        LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData);
1361207344Sjkim        FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s*/\n",
1362207344Sjkim            HEX_TABLE_LINE_SIZE - LineLength + 1, " ");
1363118611Snjl
1364207344Sjkim        Offset += LineLength;
1365207344Sjkim    }
1366207344Sjkim
1367207344Sjkim    FlPrintFile (ASL_FILE_HEX_OUTPUT, "};\n");
1368207344Sjkim}
1369207344Sjkim
1370207344Sjkim
1371207344Sjkim/*******************************************************************************
1372207344Sjkim *
1373207344Sjkim * FUNCTION:    LsDoHexOutputAsl
1374207344Sjkim *
1375207344Sjkim * PARAMETERS:  None
1376207344Sjkim *
1377207344Sjkim * RETURN:      None.
1378207344Sjkim *
1379241973Sjkim * DESCRIPTION: Create the hex output file. This is the same data as the AML
1380207344Sjkim *              output file, but formatted into hex/ascii bytes suitable for
1381207344Sjkim *              inclusion into a C source file.
1382207344Sjkim *
1383207344Sjkim ******************************************************************************/
1384207344Sjkim
1385207344Sjkimstatic void
1386207344SjkimLsDoHexOutputAsl (
1387207344Sjkim    void)
1388207344Sjkim{
1389207344Sjkim    UINT8                   FileData[HEX_TABLE_LINE_SIZE];
1390207344Sjkim    UINT32                  LineLength;
1391207344Sjkim    UINT32                  Offset = 0;
1392207344Sjkim    UINT32                  AmlFileSize;
1393207344Sjkim    UINT32                  i;
1394207344Sjkim
1395207344Sjkim
1396207344Sjkim    /* Get AML size, seek back to start */
1397207344Sjkim
1398207344Sjkim    AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
1399228110Sjkim    FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
1400207344Sjkim
1401207344Sjkim    FlPrintFile (ASL_FILE_HEX_OUTPUT, " * ASL source code output\n");
1402207344Sjkim    FlPrintFile (ASL_FILE_HEX_OUTPUT, " * AML code block contains 0x%X bytes\n *\n */\n",
1403207344Sjkim        AmlFileSize);
1404207344Sjkim    FlPrintFile (ASL_FILE_HEX_OUTPUT, "    Name (BUF1, Buffer()\n    {\n");
1405207344Sjkim
1406207344Sjkim    while (Offset < AmlFileSize)
1407207344Sjkim    {
1408207344Sjkim        /* Read enough bytes needed for one output line */
1409207344Sjkim
1410207344Sjkim        LineLength = fread (FileData, 1, HEX_TABLE_LINE_SIZE,
1411207344Sjkim                        Gbl_Files[ASL_FILE_AML_OUTPUT].Handle);
1412207344Sjkim        if (!LineLength)
1413118611Snjl        {
1414207344Sjkim            break;
1415207344Sjkim        }
1416118611Snjl
1417207344Sjkim        FlPrintFile (ASL_FILE_HEX_OUTPUT, "        ");
1418118611Snjl
1419207344Sjkim        for (i = 0; i < LineLength; i++)
1420207344Sjkim        {
1421207344Sjkim            /*
1422207344Sjkim             * Print each hex byte.
1423207344Sjkim             * Add a comma until the very last byte of the AML file
1424207344Sjkim             * (Some C compilers complain about a trailing comma)
1425207344Sjkim             */
1426207344Sjkim            FlPrintFile (ASL_FILE_HEX_OUTPUT, "0x%2.2X", FileData[i]);
1427207344Sjkim            if ((Offset + i + 1) < AmlFileSize)
1428207344Sjkim            {
1429207344Sjkim                FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
1430207344Sjkim            }
1431207344Sjkim            else
1432207344Sjkim            {
1433207344Sjkim                FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
1434207344Sjkim            }
1435207344Sjkim        }
1436118611Snjl
1437207344Sjkim        /* Add fill spaces if needed for last line */
1438118611Snjl
1439207344Sjkim        if (LineLength < HEX_TABLE_LINE_SIZE)
1440207344Sjkim        {
1441207344Sjkim            FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
1442207344Sjkim                5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
1443207344Sjkim        }
1444118611Snjl
1445207344Sjkim        /* Emit the offset and ascii dump for the entire line */
1446207344Sjkim
1447207344Sjkim        FlPrintFile (ASL_FILE_HEX_OUTPUT, "  /* %8.8X", Offset);
1448207344Sjkim        LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData);
1449207344Sjkim        FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s*/\n",
1450207344Sjkim            HEX_TABLE_LINE_SIZE - LineLength + 1, " ");
1451207344Sjkim
1452207344Sjkim        Offset += LineLength;
1453118611Snjl    }
1454118611Snjl
1455207344Sjkim    FlPrintFile (ASL_FILE_HEX_OUTPUT, "    })\n");
1456118611Snjl}
1457118611Snjl
1458118611Snjl
1459118611Snjl/*******************************************************************************
1460118611Snjl *
1461118611Snjl * FUNCTION:    LsDoHexOutputAsm
1462118611Snjl *
1463118611Snjl * PARAMETERS:  None
1464118611Snjl *
1465118611Snjl * RETURN:      None.
1466118611Snjl *
1467241973Sjkim * DESCRIPTION: Create the hex output file. This is the same data as the AML
1468118611Snjl *              output file, but formatted into hex/ascii bytes suitable for
1469118611Snjl *              inclusion into a ASM source file.
1470118611Snjl *
1471118611Snjl ******************************************************************************/
1472118611Snjl
1473151937Sjkimstatic void
1474118611SnjlLsDoHexOutputAsm (
1475118611Snjl    void)
1476118611Snjl{
1477207344Sjkim    UINT8                   FileData[HEX_TABLE_LINE_SIZE];
1478207344Sjkim    UINT32                  LineLength;
1479118611Snjl    UINT32                  Offset = 0;
1480207344Sjkim    UINT32                  AmlFileSize;
1481207344Sjkim    UINT32                  i;
1482118611Snjl
1483118611Snjl
1484207344Sjkim    /* Get AML size, seek back to start */
1485118611Snjl
1486207344Sjkim    AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
1487228110Sjkim    FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
1488118611Snjl
1489207344Sjkim    FlPrintFile (ASL_FILE_HEX_OUTPUT, "; Assembly code source output\n");
1490207344Sjkim    FlPrintFile (ASL_FILE_HEX_OUTPUT, "; AML code block contains 0x%X bytes\n;\n",
1491207344Sjkim        AmlFileSize);
1492118611Snjl
1493207344Sjkim    while (Offset < AmlFileSize)
1494207344Sjkim    {
1495207344Sjkim        /* Read enough bytes needed for one output line */
1496118611Snjl
1497207344Sjkim        LineLength = fread (FileData, 1, HEX_TABLE_LINE_SIZE,
1498207344Sjkim                        Gbl_Files[ASL_FILE_AML_OUTPUT].Handle);
1499207344Sjkim        if (!LineLength)
1500118611Snjl        {
1501207344Sjkim            break;
1502118611Snjl        }
1503207344Sjkim
1504207344Sjkim        FlPrintFile (ASL_FILE_HEX_OUTPUT, "  db  ");
1505207344Sjkim
1506207344Sjkim        for (i = 0; i < LineLength; i++)
1507118611Snjl        {
1508207344Sjkim            /*
1509207344Sjkim             * Print each hex byte.
1510207344Sjkim             * Add a comma until the last byte of the line
1511207344Sjkim             */
1512207344Sjkim            FlPrintFile (ASL_FILE_HEX_OUTPUT, "0%2.2Xh", FileData[i]);
1513207344Sjkim            if ((i + 1) < LineLength)
1514207344Sjkim            {
1515207344Sjkim                FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
1516207344Sjkim            }
1517118611Snjl        }
1518118611Snjl
1519207344Sjkim        FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
1520151937Sjkim
1521207344Sjkim        /* Add fill spaces if needed for last line */
1522118611Snjl
1523207344Sjkim        if (LineLength < HEX_TABLE_LINE_SIZE)
1524118611Snjl        {
1525207344Sjkim            FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
1526207344Sjkim                5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
1527207344Sjkim        }
1528118611Snjl
1529207344Sjkim        /* Emit the offset and ascii dump for the entire line */
1530118611Snjl
1531207344Sjkim        FlPrintFile (ASL_FILE_HEX_OUTPUT, "  ; %8.8X", Offset);
1532207344Sjkim        LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData);
1533207344Sjkim        FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n");
1534207344Sjkim
1535207344Sjkim        Offset += LineLength;
1536118611Snjl    }
1537118611Snjl
1538118611Snjl    FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n");
1539118611Snjl}
1540