1118611Snjl
2118611Snjl/******************************************************************************
3118611Snjl *
4118611Snjl * Module Name: asllisting - Listing file generation
5118611Snjl *
6118611Snjl *****************************************************************************/
7118611Snjl
8217365Sjkim/*
9217365Sjkim * Copyright (C) 2000 - 2011, Intel Corp.
10118611Snjl * All rights reserved.
11118611Snjl *
12217365Sjkim * Redistribution and use in source and binary forms, with or without
13217365Sjkim * modification, are permitted provided that the following conditions
14217365Sjkim * are met:
15217365Sjkim * 1. Redistributions of source code must retain the above copyright
16217365Sjkim *    notice, this list of conditions, and the following disclaimer,
17217365Sjkim *    without modification.
18217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19217365Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
20217365Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
21217365Sjkim *    including a substantially similar Disclaimer requirement for further
22217365Sjkim *    binary redistribution.
23217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
24217365Sjkim *    of any contributors may be used to endorse or promote products derived
25217365Sjkim *    from this software without specific prior written permission.
26118611Snjl *
27217365Sjkim * Alternatively, this software may be distributed under the terms of the
28217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
29217365Sjkim * Software Foundation.
30118611Snjl *
31217365Sjkim * NO WARRANTY
32217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42217365Sjkim * POSSIBILITY OF SUCH DAMAGES.
43217365Sjkim */
44118611Snjl
45118611Snjl
46151937Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h>
47118611Snjl#include "aslcompiler.y.h"
48193529Sjkim#include <contrib/dev/acpica/include/amlcode.h>
49193529Sjkim#include <contrib/dev/acpica/include/acparser.h>
50193529Sjkim#include <contrib/dev/acpica/include/acnamesp.h>
51118611Snjl
52118611Snjl#define _COMPONENT          ACPI_COMPILER
53118611Snjl        ACPI_MODULE_NAME    ("aslisting")
54118611Snjl
55151937Sjkim/* Local prototypes */
56118611Snjl
57151937Sjkimstatic void
58151937SjkimLsDumpAscii (
59151937Sjkim    UINT32                  FileId,
60151937Sjkim    UINT32                  Count,
61151937Sjkim    UINT8                   *Buffer);
62151937Sjkim
63151937Sjkimstatic void
64151937SjkimLsDumpAsciiInComment (
65151937Sjkim    UINT32                  FileId,
66151937Sjkim    UINT32                  Count,
67151937Sjkim    UINT8                   *Buffer);
68151937Sjkim
69151937Sjkimstatic ACPI_STATUS
70151937SjkimLsAmlListingWalk (
71151937Sjkim    ACPI_PARSE_OBJECT       *Op,
72151937Sjkim    UINT32                  Level,
73151937Sjkim    void                    *Context);
74151937Sjkim
75151937Sjkimstatic void
76151937SjkimLsGenerateListing (
77151937Sjkim    UINT32                  FileId);
78151937Sjkim
79151937Sjkimstatic void
80151937SjkimLsPushNode (
81151937Sjkim    char                    *Filename);
82151937Sjkim
83151937Sjkimstatic ASL_LISTING_NODE *
84151937SjkimLsPopNode (
85151937Sjkim    void);
86151937Sjkim
87151937Sjkimstatic void
88151937SjkimLsCheckException (
89151937Sjkim    UINT32                  LineNumber,
90151937Sjkim    UINT32                  FileId);
91151937Sjkim
92151937Sjkimstatic void
93151937SjkimLsFlushListingBuffer (
94151937Sjkim    UINT32                  FileId);
95151937Sjkim
96151937Sjkimstatic void
97151937SjkimLsWriteListingHexBytes (
98151937Sjkim    UINT8                   *Buffer,
99151937Sjkim    UINT32                  Length,
100151937Sjkim    UINT32                  FileId);
101151937Sjkim
102151937Sjkimstatic UINT32
103151937SjkimLsWriteOneSourceLine (
104151937Sjkim    UINT32                  FileId);
105151937Sjkim
106151937Sjkimstatic void
107151937SjkimLsFinishSourceListing (
108151937Sjkim    UINT32                  FileId);
109151937Sjkim
110151937Sjkimstatic void
111151937SjkimLsWriteSourceLines (
112151937Sjkim    UINT32                  ToLineNumber,
113151937Sjkim    UINT32                  ToLogicalLineNumber,
114151937Sjkim    UINT32                  FileId);
115151937Sjkim
116151937Sjkimstatic void
117151937SjkimLsWriteNodeToListing (
118151937Sjkim    ACPI_PARSE_OBJECT       *Op,
119151937Sjkim    UINT32                  FileId);
120151937Sjkim
121151937Sjkimstatic void
122151937SjkimLsDoHexOutputC (
123151937Sjkim    void);
124151937Sjkim
125151937Sjkimstatic void
126151937SjkimLsDoHexOutputAsm (
127151937Sjkim    void);
128151937Sjkim
129207344Sjkimstatic void
130207344SjkimLsDoHexOutputAsl (
131207344Sjkim    void);
132207344Sjkim
133212761Sjkimstatic ACPI_STATUS
134193529SjkimLsTreeWriteWalk (
135193529Sjkim    ACPI_PARSE_OBJECT       *Op,
136193529Sjkim    UINT32                  Level,
137193529Sjkim    void                    *Context);
138151937Sjkim
139193529Sjkim
140118611Snjl/*******************************************************************************
141118611Snjl *
142167802Sjkim * FUNCTION:    LsTreeWriteWalk
143167802Sjkim *
144167802Sjkim * PARAMETERS:  ASL_WALK_CALLBACK
145167802Sjkim *
146167802Sjkim *
147167802Sjkim * RETURN:      None.
148167802Sjkim *
149167802Sjkim * DESCRIPTION: Dump entire parse tree, for compiler debug only
150167802Sjkim *
151167802Sjkim ******************************************************************************/
152167802Sjkim
153212761Sjkimstatic ACPI_STATUS
154167802SjkimLsTreeWriteWalk (
155167802Sjkim    ACPI_PARSE_OBJECT       *Op,
156167802Sjkim    UINT32                  Level,
157167802Sjkim    void                    *Context)
158167802Sjkim{
159167802Sjkim
160167802Sjkim    /* Debug output */
161167802Sjkim
162167802Sjkim    DbgPrint (ASL_TREE_OUTPUT,
163167802Sjkim        "%5.5d [%2d]", Op->Asl.LogicalLineNumber, Level);
164167802Sjkim    UtPrintFormattedName (Op->Asl.ParseOpcode, Level);
165167802Sjkim
166167802Sjkim
167167802Sjkim    DbgPrint (ASL_TREE_OUTPUT, "\n");
168167802Sjkim    return (AE_OK);
169167802Sjkim}
170167802Sjkim
171167802Sjkim
172167802Sjkimvoid
173167802SjkimLsDumpParseTree (
174167802Sjkim    void)
175167802Sjkim{
176167802Sjkim
177167802Sjkim    if (!Gbl_DebugFlag)
178167802Sjkim    {
179167802Sjkim        return;
180167802Sjkim    }
181167802Sjkim
182167802Sjkim    DbgPrint (ASL_TREE_OUTPUT, "\nOriginal parse tree from parser:\n\n");
183167802Sjkim    TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
184167802Sjkim        LsTreeWriteWalk, NULL, NULL);
185167802Sjkim}
186167802Sjkim
187167802Sjkim
188167802Sjkim/*******************************************************************************
189167802Sjkim *
190118611Snjl * FUNCTION:    LsDumpAscii
191118611Snjl *
192118611Snjl * PARAMETERS:  FileId          - ID of current listing file
193118611Snjl *              Count           - Number of bytes to convert
194118611Snjl *              Buffer          - Buffer of bytes to convert
195118611Snjl *
196118611Snjl * RETURN:      None.
197118611Snjl *
198118611Snjl * DESCRIPTION: Convert hex bytes to ascii
199118611Snjl *
200118611Snjl ******************************************************************************/
201118611Snjl
202151937Sjkimstatic void
203118611SnjlLsDumpAscii (
204118611Snjl    UINT32                  FileId,
205118611Snjl    UINT32                  Count,
206118611Snjl    UINT8                   *Buffer)
207118611Snjl{
208118611Snjl    UINT8                   BufChar;
209118611Snjl    UINT32                  i;
210118611Snjl
211118611Snjl
212118611Snjl    FlPrintFile (FileId, "    \"");
213118611Snjl    for (i = 0; i < Count; i++)
214118611Snjl    {
215118611Snjl        BufChar = Buffer[i];
216118611Snjl        if (isprint (BufChar))
217118611Snjl        {
218118611Snjl            FlPrintFile (FileId, "%c", BufChar);
219118611Snjl        }
220118611Snjl        else
221118611Snjl        {
222118611Snjl            /* Not a printable character, just put out a dot */
223118611Snjl
224118611Snjl            FlPrintFile (FileId, ".");
225118611Snjl        }
226118611Snjl    }
227118611Snjl    FlPrintFile (FileId, "\"");
228118611Snjl}
229118611Snjl
230118611Snjl
231118611Snjl/*******************************************************************************
232118611Snjl *
233118611Snjl * FUNCTION:    LsDumpAsciiInComment
234118611Snjl *
235118611Snjl * PARAMETERS:  FileId          - ID of current listing file
236118611Snjl *              Count           - Number of bytes to convert
237118611Snjl *              Buffer          - Buffer of bytes to convert
238118611Snjl *
239118611Snjl * RETURN:      None.
240118611Snjl *
241118611Snjl * DESCRIPTION: Convert hex bytes to ascii
242118611Snjl *
243118611Snjl ******************************************************************************/
244118611Snjl
245151937Sjkimstatic void
246118611SnjlLsDumpAsciiInComment (
247118611Snjl    UINT32                  FileId,
248118611Snjl    UINT32                  Count,
249118611Snjl    UINT8                   *Buffer)
250118611Snjl{
251118611Snjl    UINT8                   BufChar = 0;
252118611Snjl    UINT8                   LastChar;
253118611Snjl    UINT32                  i;
254118611Snjl
255118611Snjl
256118611Snjl    FlPrintFile (FileId, "    \"");
257118611Snjl    for (i = 0; i < Count; i++)
258118611Snjl    {
259118611Snjl        LastChar = BufChar;
260118611Snjl        BufChar = Buffer[i];
261118611Snjl
262118611Snjl        if (isprint (BufChar))
263118611Snjl        {
264118611Snjl            /* Handle embedded C comment sequences */
265118611Snjl
266118611Snjl            if (((LastChar == '*') && (BufChar == '/')) ||
267118611Snjl                ((LastChar == '/') && (BufChar == '*')))
268118611Snjl            {
269118611Snjl                /* Insert a space to break the sequence */
270118611Snjl
271118611Snjl                FlPrintFile (FileId, ".", BufChar);
272118611Snjl            }
273118611Snjl
274118611Snjl            FlPrintFile (FileId, "%c", BufChar);
275118611Snjl        }
276118611Snjl        else
277118611Snjl        {
278118611Snjl            /* Not a printable character, just put out a dot */
279118611Snjl
280118611Snjl            FlPrintFile (FileId, ".");
281118611Snjl        }
282118611Snjl    }
283118611Snjl    FlPrintFile (FileId, "\"");
284118611Snjl}
285118611Snjl
286118611Snjl
287118611Snjl/*******************************************************************************
288118611Snjl *
289118611Snjl * FUNCTION:    LsAmlListingWalk
290118611Snjl *
291118611Snjl * PARAMETERS:  ASL_WALK_CALLBACK
292118611Snjl *
293118611Snjl * RETURN:      Status
294118611Snjl *
295118611Snjl * DESCRIPTION: Process one node during a listing file generation.
296118611Snjl *
297118611Snjl ******************************************************************************/
298118611Snjl
299151937Sjkimstatic ACPI_STATUS
300118611SnjlLsAmlListingWalk (
301118611Snjl    ACPI_PARSE_OBJECT       *Op,
302118611Snjl    UINT32                  Level,
303118611Snjl    void                    *Context)
304118611Snjl{
305118611Snjl    UINT8                   FileByte;
306118611Snjl    UINT32                  i;
307167802Sjkim    UINT32                  FileId = (UINT32) ACPI_TO_INTEGER (Context);
308118611Snjl
309118611Snjl
310118611Snjl    LsWriteNodeToListing (Op, FileId);
311118611Snjl
312167802Sjkim    if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DATA)
313167802Sjkim    {
314167802Sjkim        /* Buffer is a resource template, don't dump the data all at once */
315167802Sjkim
316167802Sjkim        return (AE_OK);
317167802Sjkim    }
318167802Sjkim
319118611Snjl    /* Write the hex bytes to the listing file(s) (if requested) */
320118611Snjl
321118611Snjl    for (i = 0; i < Op->Asl.FinalAmlLength; i++)
322118611Snjl    {
323118611Snjl        if (ACPI_FAILURE (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte, 1)))
324118611Snjl        {
325118611Snjl            FlFileError (ASL_FILE_AML_OUTPUT, ASL_MSG_READ);
326118611Snjl            AslAbort ();
327118611Snjl        }
328118611Snjl        LsWriteListingHexBytes (&FileByte, 1, FileId);
329118611Snjl    }
330118611Snjl
331118611Snjl    return (AE_OK);
332118611Snjl}
333118611Snjl
334118611Snjl
335118611Snjl/*******************************************************************************
336118611Snjl *
337118611Snjl * FUNCTION:    LsGenerateListing
338118611Snjl *
339118611Snjl * PARAMETERS:  FileId      - ID of listing file
340118611Snjl *
341118611Snjl * RETURN:      None
342118611Snjl *
343118611Snjl * DESCRIPTION: Generate a listing file.  This can be one of the several types
344118611Snjl *              of "listings" supported.
345118611Snjl *
346118611Snjl ******************************************************************************/
347118611Snjl
348151937Sjkimstatic void
349118611SnjlLsGenerateListing (
350118611Snjl    UINT32                  FileId)
351118611Snjl{
352118611Snjl
353118611Snjl    /* Start at the beginning of both the source and AML files */
354118611Snjl
355118611Snjl    FlSeekFile (ASL_FILE_SOURCE_OUTPUT, 0);
356118611Snjl    FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
357118611Snjl    Gbl_SourceLine = 0;
358118611Snjl    Gbl_CurrentHexColumn = 0;
359118611Snjl    LsPushNode (Gbl_Files[ASL_FILE_INPUT].Filename);
360118611Snjl
361118611Snjl    /* Process all parse nodes */
362118611Snjl
363118611Snjl    TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, LsAmlListingWalk,
364118611Snjl                        NULL, (void *) ACPI_TO_POINTER (FileId));
365118611Snjl
366118611Snjl    /* Final processing */
367118611Snjl
368118611Snjl    LsFinishSourceListing (FileId);
369118611Snjl}
370118611Snjl
371118611Snjl
372118611Snjl/*******************************************************************************
373118611Snjl *
374118611Snjl * FUNCTION:    LsDoListings
375118611Snjl *
376118611Snjl * PARAMETERS:  None.
377118611Snjl *
378118611Snjl * RETURN:      None
379118611Snjl *
380118611Snjl * DESCRIPTION: Generate all requested listing files.
381118611Snjl *
382118611Snjl ******************************************************************************/
383118611Snjl
384118611Snjlvoid
385151937SjkimLsDoListings (
386151937Sjkim    void)
387118611Snjl{
388118611Snjl
389118611Snjl    if (Gbl_C_OutputFlag)
390118611Snjl    {
391118611Snjl        LsGenerateListing (ASL_FILE_C_SOURCE_OUTPUT);
392118611Snjl    }
393118611Snjl
394118611Snjl    if (Gbl_ListingFlag)
395118611Snjl    {
396118611Snjl        LsGenerateListing (ASL_FILE_LISTING_OUTPUT);
397118611Snjl    }
398118611Snjl
399118611Snjl    if (Gbl_AsmOutputFlag)
400118611Snjl    {
401118611Snjl        LsGenerateListing (ASL_FILE_ASM_SOURCE_OUTPUT);
402118611Snjl    }
403118611Snjl
404118611Snjl    if (Gbl_C_IncludeOutputFlag)
405118611Snjl    {
406118611Snjl        LsGenerateListing (ASL_FILE_C_INCLUDE_OUTPUT);
407118611Snjl    }
408118611Snjl
409118611Snjl    if (Gbl_AsmIncludeOutputFlag)
410118611Snjl    {
411118611Snjl        LsGenerateListing (ASL_FILE_ASM_INCLUDE_OUTPUT);
412118611Snjl    }
413118611Snjl}
414118611Snjl
415118611Snjl
416118611Snjl/*******************************************************************************
417118611Snjl *
418118611Snjl * FUNCTION:    LsPushNode
419118611Snjl *
420118611Snjl * PARAMETERS:  Filename        - Pointer to the include filename
421118611Snjl *
422118611Snjl * RETURN:      None
423118611Snjl *
424118611Snjl * DESCRIPTION: Push a listing node on the listing/include file stack.  This
425118611Snjl *              stack enables tracking of include files (infinitely nested)
426118611Snjl *              and resumption of the listing of the parent file when the
427118611Snjl *              include file is finished.
428118611Snjl *
429118611Snjl ******************************************************************************/
430118611Snjl
431151937Sjkimstatic void
432118611SnjlLsPushNode (
433118611Snjl    char                    *Filename)
434118611Snjl{
435118611Snjl    ASL_LISTING_NODE        *Lnode;
436118611Snjl
437118611Snjl
438118611Snjl    /* Create a new node */
439118611Snjl
440118611Snjl    Lnode = UtLocalCalloc (sizeof (ASL_LISTING_NODE));
441118611Snjl
442118611Snjl    /* Initialize */
443118611Snjl
444118611Snjl    Lnode->Filename = Filename;
445118611Snjl    Lnode->LineNumber = 0;
446118611Snjl
447118611Snjl    /* Link (push) */
448118611Snjl
449118611Snjl    Lnode->Next = Gbl_ListingNode;
450118611Snjl    Gbl_ListingNode = Lnode;
451118611Snjl}
452118611Snjl
453118611Snjl
454118611Snjl/*******************************************************************************
455118611Snjl *
456118611Snjl * FUNCTION:    LsPopNode
457118611Snjl *
458118611Snjl * PARAMETERS:  None
459118611Snjl *
460118611Snjl * RETURN:      List head after current head is popped off
461118611Snjl *
462118611Snjl * DESCRIPTION: Pop the current head of the list, free it, and return the
463118611Snjl *              next node on the stack (the new current node).
464118611Snjl *
465118611Snjl ******************************************************************************/
466118611Snjl
467151937Sjkimstatic ASL_LISTING_NODE *
468151937SjkimLsPopNode (
469151937Sjkim    void)
470118611Snjl{
471118611Snjl    ASL_LISTING_NODE        *Lnode;
472118611Snjl
473118611Snjl
474118611Snjl    /* Just grab the node at the head of the list */
475118611Snjl
476118611Snjl    Lnode = Gbl_ListingNode;
477118611Snjl    if ((!Lnode) ||
478118611Snjl        (!Lnode->Next))
479118611Snjl    {
480151937Sjkim        AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, NULL,
481151937Sjkim            "Could not pop empty listing stack");
482118611Snjl        return Gbl_ListingNode;
483118611Snjl    }
484118611Snjl
485118611Snjl    Gbl_ListingNode = Lnode->Next;
486167802Sjkim    ACPI_FREE (Lnode);
487118611Snjl
488118611Snjl    /* New "Current" node is the new head */
489118611Snjl
490118611Snjl    return (Gbl_ListingNode);
491118611Snjl}
492118611Snjl
493118611Snjl
494118611Snjl/*******************************************************************************
495118611Snjl *
496118611Snjl * FUNCTION:    LsCheckException
497118611Snjl *
498118611Snjl * PARAMETERS:  LineNumber          - Current logical (cumulative) line #
499118611Snjl *              FileId              - ID of output listing file
500118611Snjl *
501118611Snjl * RETURN:      None
502118611Snjl *
503118611Snjl * DESCRIPTION: Check if there is an exception for this line, and if there is,
504118611Snjl *              put it in the listing immediately.  Handles multiple errors
505118611Snjl *              per line.  Gbl_NextError points to the next error in the
506118611Snjl *              sorted (by line #) list of compile errors/warnings.
507118611Snjl *
508118611Snjl ******************************************************************************/
509118611Snjl
510151937Sjkimstatic void
511118611SnjlLsCheckException (
512118611Snjl    UINT32                  LineNumber,
513118611Snjl    UINT32                  FileId)
514118611Snjl{
515118611Snjl
516118611Snjl    if ((!Gbl_NextError) ||
517118611Snjl        (LineNumber < Gbl_NextError->LogicalLineNumber ))
518118611Snjl    {
519118611Snjl        return;
520118611Snjl    }
521118611Snjl
522118611Snjl    /* Handle multiple errors per line */
523118611Snjl
524118611Snjl    if (FileId == ASL_FILE_LISTING_OUTPUT)
525118611Snjl    {
526118611Snjl        while (Gbl_NextError &&
527118611Snjl              (LineNumber >= Gbl_NextError->LogicalLineNumber))
528118611Snjl        {
529118611Snjl            AePrintException (FileId, Gbl_NextError, "\n[****iasl****]\n");
530118611Snjl
531118611Snjl            Gbl_NextError = Gbl_NextError->Next;
532118611Snjl        }
533118611Snjl
534118611Snjl        FlPrintFile (FileId, "\n");
535118611Snjl    }
536118611Snjl}
537118611Snjl
538118611Snjl
539118611Snjl/*******************************************************************************
540118611Snjl *
541118611Snjl * FUNCTION:    LsFlushListingBuffer
542118611Snjl *
543118611Snjl * PARAMETERS:  FileId          - ID of the listing file
544118611Snjl *
545118611Snjl * RETURN:      None
546118611Snjl *
547118611Snjl * DESCRIPTION: Flush out the current contents of the 16-byte hex AML code
548118611Snjl *              buffer.  Usually called at the termination of a single line
549118611Snjl *              of source code or when the buffer is full.
550118611Snjl *
551118611Snjl ******************************************************************************/
552118611Snjl
553151937Sjkimstatic void
554118611SnjlLsFlushListingBuffer (
555118611Snjl    UINT32                  FileId)
556118611Snjl{
557118611Snjl    UINT32                  i;
558118611Snjl
559118611Snjl
560118611Snjl    if (Gbl_CurrentHexColumn == 0)
561118611Snjl    {
562118611Snjl        return;
563118611Snjl    }
564118611Snjl
565118611Snjl    /* Write the hex bytes */
566118611Snjl
567118611Snjl    switch (FileId)
568118611Snjl    {
569118611Snjl    case ASL_FILE_LISTING_OUTPUT:
570118611Snjl
571118611Snjl        for (i = 0; i < Gbl_CurrentHexColumn; i++)
572118611Snjl        {
573118611Snjl            FlPrintFile (FileId, "%2.2X ", Gbl_AmlBuffer[i]);
574118611Snjl        }
575118611Snjl
576118611Snjl        for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 3); i++)
577118611Snjl        {
578118611Snjl            FlWriteFile (FileId, ".", 1);
579118611Snjl        }
580118611Snjl
581118611Snjl        /* Write the ASCII character associated with each of the bytes */
582118611Snjl
583118611Snjl        LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer);
584118611Snjl        break;
585118611Snjl
586118611Snjl
587118611Snjl    case ASL_FILE_ASM_SOURCE_OUTPUT:
588118611Snjl
589118611Snjl        for (i = 0; i < Gbl_CurrentHexColumn; i++)
590118611Snjl        {
591118611Snjl            if (i > 0)
592118611Snjl            {
593118611Snjl                FlPrintFile (FileId, ",");
594118611Snjl            }
595118611Snjl            FlPrintFile (FileId, "0%2.2Xh", Gbl_AmlBuffer[i]);
596118611Snjl        }
597118611Snjl
598118611Snjl        for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++)
599118611Snjl        {
600118611Snjl            FlWriteFile (FileId, " ", 1);
601118611Snjl        }
602118611Snjl
603151937Sjkim        FlPrintFile (FileId, "  ;%8.8X",
604151937Sjkim            Gbl_CurrentAmlOffset - HEX_LISTING_LINE_SIZE);
605118611Snjl
606118611Snjl        /* Write the ASCII character associated with each of the bytes */
607118611Snjl
608118611Snjl        LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer);
609118611Snjl        break;
610118611Snjl
611118611Snjl
612118611Snjl    case ASL_FILE_C_SOURCE_OUTPUT:
613118611Snjl
614118611Snjl        for (i = 0; i < Gbl_CurrentHexColumn; i++)
615118611Snjl        {
616118611Snjl            FlPrintFile (FileId, "0x%2.2X,", Gbl_AmlBuffer[i]);
617118611Snjl        }
618118611Snjl
619118611Snjl        for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++)
620118611Snjl        {
621118611Snjl            FlWriteFile (FileId, " ", 1);
622118611Snjl        }
623118611Snjl
624151937Sjkim        FlPrintFile (FileId, "    /* %8.8X",
625151937Sjkim            Gbl_CurrentAmlOffset - HEX_LISTING_LINE_SIZE);
626118611Snjl
627118611Snjl        /* Write the ASCII character associated with each of the bytes */
628118611Snjl
629118611Snjl        LsDumpAsciiInComment (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer);
630118611Snjl        FlPrintFile (FileId, " */");
631118611Snjl        break;
632118611Snjl
633118611Snjl    default:
634118611Snjl        /* No other types supported */
635118611Snjl        return;
636118611Snjl    }
637118611Snjl
638118611Snjl    FlPrintFile (FileId, "\n");
639118611Snjl
640118611Snjl    Gbl_CurrentHexColumn = 0;
641118611Snjl    Gbl_HexBytesWereWritten = TRUE;
642118611Snjl}
643118611Snjl
644118611Snjl
645118611Snjl/*******************************************************************************
646118611Snjl *
647118611Snjl * FUNCTION:    LsWriteListingHexBytes
648118611Snjl *
649118611Snjl * PARAMETERS:  Buffer          - AML code buffer
650118611Snjl *              Length          - Number of AML bytes to write
651118611Snjl *              FileId          - ID of current listing file.
652118611Snjl *
653118611Snjl * RETURN:      None
654118611Snjl *
655118611Snjl * DESCRIPTION: Write the contents of the AML buffer to the listing file via
656118611Snjl *              the listing buffer.  The listing buffer is flushed every 16
657118611Snjl *              AML bytes.
658118611Snjl *
659118611Snjl ******************************************************************************/
660118611Snjl
661151937Sjkimstatic void
662118611SnjlLsWriteListingHexBytes (
663118611Snjl    UINT8                   *Buffer,
664118611Snjl    UINT32                  Length,
665118611Snjl    UINT32                  FileId)
666118611Snjl{
667118611Snjl    UINT32                  i;
668118611Snjl
669118611Snjl
670118611Snjl    /* Transfer all requested bytes */
671118611Snjl
672118611Snjl    for (i = 0; i < Length; i++)
673118611Snjl    {
674118611Snjl        /* Print line header when buffer is empty */
675118611Snjl
676118611Snjl        if (Gbl_CurrentHexColumn == 0)
677118611Snjl        {
678118611Snjl            if (Gbl_HasIncludeFiles)
679118611Snjl            {
680118611Snjl                FlPrintFile (FileId, "%*s", 10, " ");
681118611Snjl            }
682118611Snjl
683118611Snjl            switch (FileId)
684118611Snjl            {
685118611Snjl            case ASL_FILE_LISTING_OUTPUT:
686118611Snjl
687118611Snjl                FlPrintFile (FileId, "%8.8X....", Gbl_CurrentAmlOffset);
688118611Snjl                break;
689118611Snjl
690118611Snjl            case ASL_FILE_ASM_SOURCE_OUTPUT:
691118611Snjl
692118611Snjl                FlPrintFile (FileId, "    db ");
693118611Snjl                break;
694118611Snjl
695118611Snjl            case ASL_FILE_C_SOURCE_OUTPUT:
696118611Snjl
697118611Snjl                FlPrintFile (FileId, "        ");
698118611Snjl                break;
699118611Snjl
700118611Snjl            default:
701118611Snjl                /* No other types supported */
702118611Snjl                return;
703118611Snjl            }
704118611Snjl        }
705118611Snjl
706118611Snjl        /* Transfer AML byte and update counts */
707118611Snjl
708118611Snjl        Gbl_AmlBuffer[Gbl_CurrentHexColumn] = Buffer[i];
709118611Snjl
710118611Snjl        Gbl_CurrentHexColumn++;
711118611Snjl        Gbl_CurrentAmlOffset++;
712118611Snjl
713118611Snjl        /* Flush buffer when it is full */
714118611Snjl
715118611Snjl        if (Gbl_CurrentHexColumn >= HEX_LISTING_LINE_SIZE)
716118611Snjl        {
717118611Snjl            LsFlushListingBuffer (FileId);
718118611Snjl        }
719118611Snjl    }
720118611Snjl}
721118611Snjl
722118611Snjl
723118611Snjl/*******************************************************************************
724118611Snjl *
725118611Snjl * FUNCTION:    LsWriteOneSourceLine
726118611Snjl *
727118611Snjl * PARAMETERS:  FileID          - ID of current listing file
728118611Snjl *
729118611Snjl * RETURN:      FALSE on EOF (input source file), TRUE otherwise
730118611Snjl *
731118611Snjl * DESCRIPTION: Read one line from the input source file and echo it to the
732118611Snjl *              listing file, prefixed with the line number, and if the source
733118611Snjl *              file contains include files, prefixed with the current filename
734118611Snjl *
735118611Snjl ******************************************************************************/
736118611Snjl
737151937Sjkimstatic UINT32
738118611SnjlLsWriteOneSourceLine (
739118611Snjl    UINT32                  FileId)
740118611Snjl{
741118611Snjl    UINT8                   FileByte;
742118611Snjl
743118611Snjl
744118611Snjl    Gbl_SourceLine++;
745118611Snjl    Gbl_ListingNode->LineNumber++;
746118611Snjl
747118611Snjl    if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
748118611Snjl    {
749118611Snjl        FlPrintFile (FileId, "     *");
750118611Snjl    }
751118611Snjl    if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
752118611Snjl    {
753118611Snjl        FlPrintFile (FileId, "; ");
754118611Snjl    }
755118611Snjl
756118611Snjl    if (Gbl_HasIncludeFiles)
757118611Snjl    {
758118611Snjl        /*
759118611Snjl         * This file contains "include" statements, print the current
760118611Snjl         * filename and line number within the current file
761118611Snjl         */
762118611Snjl        FlPrintFile (FileId, "%12s %5d....",
763118611Snjl                    Gbl_ListingNode->Filename, Gbl_ListingNode->LineNumber);
764118611Snjl    }
765118611Snjl    else
766118611Snjl    {
767118611Snjl        /* No include files, just print the line number */
768118611Snjl
769118611Snjl        FlPrintFile (FileId, "%8d....", Gbl_SourceLine);
770118611Snjl    }
771118611Snjl
772118611Snjl    /* Read one line (up to a newline or EOF) */
773118611Snjl
774118611Snjl    while (FlReadFile (ASL_FILE_SOURCE_OUTPUT, &FileByte, 1) == AE_OK)
775118611Snjl    {
776118611Snjl        if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
777118611Snjl        {
778118611Snjl            if (FileByte == '/')
779118611Snjl            {
780118611Snjl                FileByte = '*';
781118611Snjl            }
782118611Snjl        }
783118611Snjl
784118611Snjl        FlWriteFile (FileId, &FileByte, 1);
785118611Snjl        if (FileByte == '\n')
786118611Snjl        {
787118611Snjl            /*
788118611Snjl             * Check if an error occurred on this source line during the compile.
789118611Snjl             * If so, we print the error message after the source line.
790118611Snjl             */
791118611Snjl            LsCheckException (Gbl_SourceLine, FileId);
792118611Snjl            return (1);
793118611Snjl        }
794118611Snjl    }
795118611Snjl
796118611Snjl    /* EOF on the input file was reached */
797118611Snjl
798118611Snjl    return (0);
799118611Snjl}
800118611Snjl
801118611Snjl
802118611Snjl/*******************************************************************************
803118611Snjl *
804118611Snjl * FUNCTION:    LsFinishSourceListing
805118611Snjl *
806118611Snjl * PARAMETERS:  FileId          - ID of current listing file.
807118611Snjl *
808118611Snjl * RETURN:      None
809118611Snjl *
810118611Snjl * DESCRIPTION: Cleanup routine for the listing file.  Flush the hex AML
811118611Snjl *              listing buffer, and flush out any remaining lines in the
812118611Snjl *              source input file.
813118611Snjl *
814118611Snjl ******************************************************************************/
815118611Snjl
816151937Sjkimstatic void
817118611SnjlLsFinishSourceListing (
818118611Snjl    UINT32                  FileId)
819118611Snjl{
820118611Snjl
821118611Snjl    if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) ||
822118611Snjl        (FileId == ASL_FILE_C_INCLUDE_OUTPUT))
823118611Snjl    {
824118611Snjl        return;
825118611Snjl    }
826118611Snjl
827118611Snjl    LsFlushListingBuffer (FileId);
828118611Snjl    Gbl_CurrentAmlOffset = 0;
829118611Snjl
830118611Snjl    /* Flush any remaining text in the source file */
831118611Snjl
832118611Snjl    if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
833118611Snjl    {
834118611Snjl        FlPrintFile (FileId, "    /*\n");
835118611Snjl    }
836118611Snjl
837118611Snjl    while (LsWriteOneSourceLine (FileId))
838118611Snjl    { ; }
839118611Snjl
840118611Snjl    if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
841118611Snjl    {
842118611Snjl        FlPrintFile (FileId, "\n     */\n    };\n");
843118611Snjl    }
844118611Snjl
845118611Snjl    FlPrintFile (FileId, "\n");
846118611Snjl
847118611Snjl    if (FileId == ASL_FILE_LISTING_OUTPUT)
848118611Snjl    {
849118611Snjl        /* Print a summary of the compile exceptions */
850118611Snjl
851118611Snjl        FlPrintFile (FileId, "\n\nSummary of errors and warnings\n\n");
852118611Snjl        AePrintErrorLog (FileId);
853118611Snjl        FlPrintFile (FileId, "\n\n");
854118611Snjl        UtDisplaySummary (FileId);
855118611Snjl        FlPrintFile (FileId, "\n\n");
856118611Snjl    }
857118611Snjl}
858118611Snjl
859118611Snjl
860118611Snjl/*******************************************************************************
861118611Snjl *
862118611Snjl * FUNCTION:    LsWriteSourceLines
863118611Snjl *
864118611Snjl * PARAMETERS:  ToLineNumber            -
865118611Snjl *              ToLogicalLineNumber     - Write up to this source line number
866118611Snjl *              FileId                  - ID of current listing file
867118611Snjl *
868118611Snjl * RETURN:      None
869118611Snjl *
870118611Snjl * DESCRIPTION: Read then write source lines to the listing file until we have
871118611Snjl *              reached the specified logical (cumulative) line number.  This
872118611Snjl *              automatically echos out comment blocks and other non-AML
873118611Snjl *              generating text until we get to the actual AML-generating line
874118611Snjl *              of ASL code specified by the logical line number.
875118611Snjl *
876118611Snjl ******************************************************************************/
877118611Snjl
878151937Sjkimstatic void
879118611SnjlLsWriteSourceLines (
880118611Snjl    UINT32                  ToLineNumber,
881118611Snjl    UINT32                  ToLogicalLineNumber,
882118611Snjl    UINT32                  FileId)
883118611Snjl{
884118611Snjl
885118611Snjl    if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) ||
886118611Snjl        (FileId == ASL_FILE_C_INCLUDE_OUTPUT))
887118611Snjl    {
888118611Snjl        return;
889118611Snjl    }
890118611Snjl
891118611Snjl    Gbl_CurrentLine = ToLogicalLineNumber;
892118611Snjl
893118611Snjl    /* Flush any hex bytes remaining from the last opcode */
894118611Snjl
895118611Snjl    LsFlushListingBuffer (FileId);
896118611Snjl
897151937Sjkim    /* Read lines and write them as long as we are not caught up */
898151937Sjkim
899118611Snjl    if (Gbl_SourceLine < Gbl_CurrentLine)
900118611Snjl    {
901118611Snjl        /*
902118611Snjl         * If we just completed writing some AML hex bytes, output a linefeed
903118611Snjl         * to add some whitespace for readability.
904118611Snjl         */
905118611Snjl        if (Gbl_HexBytesWereWritten)
906118611Snjl        {
907118611Snjl            FlPrintFile (FileId, "\n");
908118611Snjl            Gbl_HexBytesWereWritten = FALSE;
909118611Snjl        }
910118611Snjl
911118611Snjl        if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
912118611Snjl        {
913118611Snjl            FlPrintFile (FileId, "    /*\n");
914118611Snjl        }
915118611Snjl
916151937Sjkim        /* Write one line at a time until we have reached the target line # */
917151937Sjkim
918118611Snjl        while ((Gbl_SourceLine < Gbl_CurrentLine) &&
919118611Snjl                LsWriteOneSourceLine (FileId))
920118611Snjl        { ; }
921118611Snjl
922118611Snjl        if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
923118611Snjl        {
924118611Snjl            FlPrintFile (FileId, "     */");
925118611Snjl        }
926118611Snjl        FlPrintFile (FileId, "\n");
927118611Snjl    }
928118611Snjl}
929118611Snjl
930118611Snjl
931118611Snjl/*******************************************************************************
932118611Snjl *
933118611Snjl * FUNCTION:    LsWriteNodeToListing
934118611Snjl *
935118611Snjl * PARAMETERS:  Op            - Parse node to write to the listing file.
936118611Snjl *              FileId          - ID of current listing file
937118611Snjl *
938118611Snjl * RETURN:      None.
939118611Snjl *
940118611Snjl * DESCRIPTION: Write "a node" to the listing file.  This means to
941118611Snjl *              1) Write out all of the source text associated with the node
942118611Snjl *              2) Write out all of the AML bytes associated with the node
943118611Snjl *              3) Write any compiler exceptions associated with the node
944118611Snjl *
945118611Snjl ******************************************************************************/
946118611Snjl
947151937Sjkimstatic void
948118611SnjlLsWriteNodeToListing (
949118611Snjl    ACPI_PARSE_OBJECT       *Op,
950118611Snjl    UINT32                  FileId)
951118611Snjl{
952118611Snjl    const ACPI_OPCODE_INFO  *OpInfo;
953118611Snjl    UINT32                  OpClass;
954118611Snjl    char                    *Pathname;
955118611Snjl    UINT32                  Length;
956118611Snjl    UINT32                  i;
957118611Snjl
958118611Snjl
959118611Snjl    OpInfo  = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
960118611Snjl    OpClass = OpInfo->Class;
961118611Snjl
962151937Sjkim    /* TBD: clean this up with a single flag that says:
963151937Sjkim     * I start a named output block
964151937Sjkim     */
965118611Snjl    if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
966118611Snjl    {
967118611Snjl        switch (Op->Asl.ParseOpcode)
968118611Snjl        {
969118611Snjl        case PARSEOP_DEFINITIONBLOCK:
970118611Snjl        case PARSEOP_METHODCALL:
971118611Snjl        case PARSEOP_INCLUDE:
972118611Snjl        case PARSEOP_INCLUDE_END:
973118611Snjl        case PARSEOP_DEFAULT_ARG:
974118611Snjl
975118611Snjl            break;
976118611Snjl
977118611Snjl        default:
978118611Snjl            switch (OpClass)
979118611Snjl            {
980118611Snjl            case AML_CLASS_NAMED_OBJECT:
981118611Snjl                switch (Op->Asl.AmlOpcode)
982118611Snjl                {
983118611Snjl                case AML_SCOPE_OP:
984118611Snjl                case AML_ALIAS_OP:
985118611Snjl                    break;
986118611Snjl
987118611Snjl                default:
988118611Snjl                    if (Op->Asl.ExternalName)
989118611Snjl                    {
990118611Snjl                        LsFlushListingBuffer (FileId);
991118611Snjl                        FlPrintFile (FileId, "    };\n");
992118611Snjl                    }
993118611Snjl                    break;
994118611Snjl                }
995118611Snjl                break;
996118611Snjl
997118611Snjl            default:
998118611Snjl                /* Don't care about other objects */
999118611Snjl                break;
1000118611Snjl            }
1001118611Snjl            break;
1002118611Snjl        }
1003118611Snjl    }
1004118611Snjl
1005118611Snjl    /* These cases do not have a corresponding AML opcode */
1006118611Snjl
1007118611Snjl    switch (Op->Asl.ParseOpcode)
1008118611Snjl    {
1009118611Snjl    case PARSEOP_DEFINITIONBLOCK:
1010118611Snjl
1011118611Snjl        LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine, FileId);
1012118611Snjl
1013118611Snjl        /* Use the table Signature and TableId to build a unique name */
1014118611Snjl
1015118611Snjl        if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
1016118611Snjl        {
1017151937Sjkim            FlPrintFile (FileId,
1018151937Sjkim                "%s_%s_Header \\\n",
1019118611Snjl                Gbl_TableSignature, Gbl_TableId);
1020118611Snjl        }
1021118611Snjl        if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
1022118611Snjl        {
1023151937Sjkim            FlPrintFile (FileId,
1024151937Sjkim                "    unsigned char    %s_%s_Header [] =\n    {\n",
1025118611Snjl                Gbl_TableSignature, Gbl_TableId);
1026118611Snjl        }
1027118611Snjl        if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT)
1028118611Snjl        {
1029151937Sjkim            FlPrintFile (FileId,
1030151937Sjkim                "extrn %s_%s_Header : byte\n",
1031118611Snjl                Gbl_TableSignature, Gbl_TableId);
1032118611Snjl        }
1033118611Snjl        if (FileId == ASL_FILE_C_INCLUDE_OUTPUT)
1034118611Snjl        {
1035151937Sjkim            FlPrintFile (FileId,
1036151937Sjkim                "extern unsigned char    %s_%s_Header [];\n",
1037118611Snjl                Gbl_TableSignature, Gbl_TableId);
1038118611Snjl        }
1039118611Snjl        return;
1040118611Snjl
1041118611Snjl
1042118611Snjl    case PARSEOP_METHODCALL:
1043118611Snjl
1044151937Sjkim        LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1045151937Sjkim            FileId);
1046118611Snjl        return;
1047118611Snjl
1048118611Snjl
1049118611Snjl    case PARSEOP_INCLUDE:
1050118611Snjl
1051151937Sjkim        /* Flush everything up to and including the include source line */
1052118611Snjl
1053151937Sjkim        LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1054151937Sjkim            FileId);
1055151937Sjkim
1056151937Sjkim        /* Create a new listing node and push it */
1057151937Sjkim
1058118611Snjl        LsPushNode (Op->Asl.Child->Asl.Value.String);
1059118611Snjl        return;
1060118611Snjl
1061118611Snjl
1062118611Snjl    case PARSEOP_INCLUDE_END:
1063118611Snjl
1064151937Sjkim        /* Flush out the rest of the include file */
1065118611Snjl
1066151937Sjkim        LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1067151937Sjkim            FileId);
1068151937Sjkim
1069151937Sjkim        /* Pop off this listing node and go back to the parent file */
1070151937Sjkim
1071151937Sjkim        (void) LsPopNode ();
1072118611Snjl        return;
1073118611Snjl
1074118611Snjl
1075118611Snjl    case PARSEOP_DEFAULT_ARG:
1076167802Sjkim
1077167802Sjkim        if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
1078167802Sjkim        {
1079167802Sjkim            LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.EndLogicalLine,
1080167802Sjkim                FileId);
1081167802Sjkim        }
1082118611Snjl        return;
1083118611Snjl
1084118611Snjl
1085118611Snjl    default:
1086118611Snjl        /* All other opcodes have an AML opcode */
1087118611Snjl        break;
1088118611Snjl    }
1089118611Snjl
1090118611Snjl    /*
1091118611Snjl     * Otherwise, we look at the AML opcode because we can
1092118611Snjl     * switch on the opcode type, getting an entire class
1093118611Snjl     * at once
1094118611Snjl     */
1095118611Snjl    switch (OpClass)
1096118611Snjl    {
1097118611Snjl    case AML_CLASS_ARGUMENT:       /* argument type only */
1098118611Snjl    case AML_CLASS_INTERNAL:
1099118611Snjl
1100118611Snjl        break;
1101118611Snjl
1102118611Snjl
1103118611Snjl    case AML_CLASS_NAMED_OBJECT:
1104118611Snjl
1105118611Snjl        switch (Op->Asl.AmlOpcode)
1106118611Snjl        {
1107118611Snjl        case AML_FIELD_OP:
1108118611Snjl        case AML_INDEX_FIELD_OP:
1109118611Snjl        case AML_BANK_FIELD_OP:
1110118611Snjl
1111151937Sjkim            /*
1112151937Sjkim             * For fields, we want to dump all the AML after the
1113151937Sjkim             * entire definition
1114151937Sjkim             */
1115151937Sjkim            LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine,
1116151937Sjkim                FileId);
1117118611Snjl            break;
1118118611Snjl
1119167802Sjkim        case AML_NAME_OP:
1120167802Sjkim
1121167802Sjkim            if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
1122167802Sjkim            {
1123167802Sjkim                LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1124167802Sjkim                    FileId);
1125167802Sjkim            }
1126167802Sjkim            else
1127167802Sjkim            {
1128167802Sjkim                /*
1129167802Sjkim                 * For fields, we want to dump all the AML after the
1130167802Sjkim                 * entire definition
1131167802Sjkim                 */
1132167802Sjkim                LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine,
1133167802Sjkim                    FileId);
1134167802Sjkim            }
1135167802Sjkim            break;
1136167802Sjkim
1137118611Snjl        default:
1138151937Sjkim            LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1139151937Sjkim                FileId);
1140118611Snjl            break;
1141118611Snjl        }
1142118611Snjl
1143118611Snjl        switch (Op->Asl.AmlOpcode)
1144118611Snjl        {
1145118611Snjl        case AML_SCOPE_OP:
1146118611Snjl        case AML_ALIAS_OP:
1147118611Snjl
1148118611Snjl            /* These opcodes do not declare a new object, ignore them */
1149118611Snjl
1150118611Snjl            break;
1151118611Snjl
1152118611Snjl        default:
1153118611Snjl
1154118611Snjl            /* All other named object opcodes come here */
1155118611Snjl
1156118611Snjl            switch (FileId)
1157118611Snjl            {
1158118611Snjl            case ASL_FILE_ASM_SOURCE_OUTPUT:
1159118611Snjl            case ASL_FILE_C_SOURCE_OUTPUT:
1160118611Snjl            case ASL_FILE_ASM_INCLUDE_OUTPUT:
1161118611Snjl            case ASL_FILE_C_INCLUDE_OUTPUT:
1162118611Snjl
1163118611Snjl                /*
1164118611Snjl                 * For named objects, we will create a valid symbol so that the
1165118611Snjl                 * AML code can be referenced from C or ASM
1166118611Snjl                 */
1167118611Snjl                if (Op->Asl.ExternalName)
1168118611Snjl                {
1169118611Snjl                    /* Get the full pathname associated with this node */
1170118611Snjl
1171118611Snjl                    Pathname = AcpiNsGetExternalPathname (Op->Asl.Node);
1172118611Snjl                    Length = strlen (Pathname);
1173118611Snjl                    if (Length >= 4)
1174118611Snjl                    {
1175118611Snjl                        /* Convert all dots in the path to underscores */
1176118611Snjl
1177118611Snjl                        for (i = 0; i < Length; i++)
1178118611Snjl                        {
1179118611Snjl                            if (Pathname[i] == '.')
1180118611Snjl                            {
1181118611Snjl                                Pathname[i] = '_';
1182118611Snjl                            }
1183118611Snjl                        }
1184118611Snjl
1185118611Snjl                        /* Create the appropriate symbol in the output file */
1186118611Snjl
1187118611Snjl                        if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
1188118611Snjl                        {
1189151937Sjkim                            FlPrintFile (FileId,
1190151937Sjkim                                "%s_%s_%s  \\\n",
1191118611Snjl                                Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1192118611Snjl                        }
1193118611Snjl                        if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
1194118611Snjl                        {
1195151937Sjkim                            FlPrintFile (FileId,
1196151937Sjkim                                "    unsigned char    %s_%s_%s [] =\n    {\n",
1197118611Snjl                                Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1198118611Snjl                        }
1199118611Snjl                        if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT)
1200118611Snjl                        {
1201151937Sjkim                            FlPrintFile (FileId,
1202151937Sjkim                                "extrn %s_%s_%s : byte\n",
1203118611Snjl                                Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1204118611Snjl                        }
1205118611Snjl                        if (FileId == ASL_FILE_C_INCLUDE_OUTPUT)
1206118611Snjl                        {
1207151937Sjkim                            FlPrintFile (FileId,
1208151937Sjkim                                "extern unsigned char    %s_%s_%s [];\n",
1209118611Snjl                                Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1210118611Snjl                        }
1211118611Snjl                    }
1212167802Sjkim                    ACPI_FREE (Pathname);
1213118611Snjl                }
1214118611Snjl                break;
1215118611Snjl
1216118611Snjl            default:
1217118611Snjl                /* Nothing to do for listing file */
1218118611Snjl                break;
1219118611Snjl            }
1220118611Snjl        }
1221118611Snjl        break;
1222118611Snjl
1223118611Snjl    case AML_CLASS_EXECUTE:
1224118611Snjl    case AML_CLASS_CREATE:
1225118611Snjl    default:
1226118611Snjl
1227167802Sjkim        if ((Op->Asl.ParseOpcode == PARSEOP_BUFFER) &&
1228167802Sjkim            (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC))
1229167802Sjkim        {
1230167802Sjkim            return;
1231167802Sjkim        }
1232167802Sjkim
1233151937Sjkim        LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1234151937Sjkim            FileId);
1235118611Snjl        break;
1236118611Snjl
1237118611Snjl    case AML_CLASS_UNKNOWN:
1238118611Snjl        break;
1239118611Snjl    }
1240118611Snjl}
1241118611Snjl
1242118611Snjl
1243118611Snjl/*******************************************************************************
1244118611Snjl *
1245118611Snjl * FUNCTION:    LsDoHexOutput
1246118611Snjl *
1247118611Snjl * PARAMETERS:  None
1248118611Snjl *
1249118611Snjl * RETURN:      None.
1250118611Snjl *
1251118611Snjl * DESCRIPTION: Create the hex output file.
1252118611Snjl *
1253118611Snjl ******************************************************************************/
1254118611Snjl
1255118611Snjlvoid
1256151937SjkimLsDoHexOutput (
1257151937Sjkim    void)
1258118611Snjl{
1259118611Snjl
1260118611Snjl    switch (Gbl_HexOutputFlag)
1261118611Snjl    {
1262118611Snjl    case HEX_OUTPUT_C:
1263118611Snjl
1264118611Snjl        LsDoHexOutputC ();
1265118611Snjl        break;
1266118611Snjl
1267118611Snjl    case HEX_OUTPUT_ASM:
1268118611Snjl
1269118611Snjl        LsDoHexOutputAsm ();
1270118611Snjl        break;
1271118611Snjl
1272207344Sjkim    case HEX_OUTPUT_ASL:
1273207344Sjkim
1274207344Sjkim        LsDoHexOutputAsl ();
1275207344Sjkim        break;
1276207344Sjkim
1277118611Snjl    default:
1278118611Snjl        /* No other output types supported */
1279118611Snjl        break;
1280118611Snjl    }
1281118611Snjl}
1282118611Snjl
1283118611Snjl
1284118611Snjl/*******************************************************************************
1285118611Snjl *
1286118611Snjl * FUNCTION:    LsDoHexOutputC
1287118611Snjl *
1288118611Snjl * PARAMETERS:  None
1289118611Snjl *
1290118611Snjl * RETURN:      None.
1291118611Snjl *
1292118611Snjl * DESCRIPTION: Create the hex output file.  This is the same data as the AML
1293118611Snjl *              output file, but formatted into hex/ascii bytes suitable for
1294118611Snjl *              inclusion into a C source file.
1295118611Snjl *
1296118611Snjl ******************************************************************************/
1297118611Snjl
1298151937Sjkimstatic void
1299151937SjkimLsDoHexOutputC (
1300151937Sjkim    void)
1301118611Snjl{
1302207344Sjkim    UINT8                   FileData[HEX_TABLE_LINE_SIZE];
1303207344Sjkim    UINT32                  LineLength;
1304118611Snjl    UINT32                  Offset = 0;
1305207344Sjkim    UINT32                  AmlFileSize;
1306207344Sjkim    UINT32                  i;
1307118611Snjl
1308118611Snjl
1309207344Sjkim    /* Get AML size, seek back to start */
1310207344Sjkim
1311207344Sjkim    AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
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    FlCloseFile (ASL_FILE_HEX_OUTPUT);
1369207344Sjkim}
1370207344Sjkim
1371207344Sjkim
1372207344Sjkim/*******************************************************************************
1373207344Sjkim *
1374207344Sjkim * FUNCTION:    LsDoHexOutputAsl
1375207344Sjkim *
1376207344Sjkim * PARAMETERS:  None
1377207344Sjkim *
1378207344Sjkim * RETURN:      None.
1379207344Sjkim *
1380207344Sjkim * DESCRIPTION: Create the hex output file.  This is the same data as the AML
1381207344Sjkim *              output file, but formatted into hex/ascii bytes suitable for
1382207344Sjkim *              inclusion into a C source file.
1383207344Sjkim *
1384207344Sjkim ******************************************************************************/
1385207344Sjkim
1386207344Sjkimstatic void
1387207344SjkimLsDoHexOutputAsl (
1388207344Sjkim    void)
1389207344Sjkim{
1390207344Sjkim    UINT8                   FileData[HEX_TABLE_LINE_SIZE];
1391207344Sjkim    UINT32                  LineLength;
1392207344Sjkim    UINT32                  Offset = 0;
1393207344Sjkim    UINT32                  AmlFileSize;
1394207344Sjkim    UINT32                  i;
1395207344Sjkim
1396207344Sjkim
1397207344Sjkim    /* Get AML size, seek back to start */
1398207344Sjkim
1399207344Sjkim    AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
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    FlCloseFile (ASL_FILE_HEX_OUTPUT);
1457118611Snjl}
1458118611Snjl
1459118611Snjl
1460118611Snjl/*******************************************************************************
1461118611Snjl *
1462118611Snjl * FUNCTION:    LsDoHexOutputAsm
1463118611Snjl *
1464118611Snjl * PARAMETERS:  None
1465118611Snjl *
1466118611Snjl * RETURN:      None.
1467118611Snjl *
1468118611Snjl * DESCRIPTION: Create the hex output file.  This is the same data as the AML
1469118611Snjl *              output file, but formatted into hex/ascii bytes suitable for
1470118611Snjl *              inclusion into a ASM source file.
1471118611Snjl *
1472118611Snjl ******************************************************************************/
1473118611Snjl
1474151937Sjkimstatic void
1475118611SnjlLsDoHexOutputAsm (
1476118611Snjl    void)
1477118611Snjl{
1478207344Sjkim    UINT8                   FileData[HEX_TABLE_LINE_SIZE];
1479207344Sjkim    UINT32                  LineLength;
1480118611Snjl    UINT32                  Offset = 0;
1481207344Sjkim    UINT32                  AmlFileSize;
1482207344Sjkim    UINT32                  i;
1483118611Snjl
1484118611Snjl
1485207344Sjkim    /* Get AML size, seek back to start */
1486118611Snjl
1487207344Sjkim    AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
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    FlCloseFile (ASL_FILE_HEX_OUTPUT);
1540118611Snjl}
1541118611Snjl
1542118611Snjl
1543