Home | History | Annotate | Line # | Download | only in compiler
asllisting.c revision 1.1.1.1
      1 
      2 /******************************************************************************
      3  *
      4  * Module Name: asllisting - Listing file generation
      5  *
      6  *****************************************************************************/
      7 
      8 /******************************************************************************
      9  *
     10  * 1. Copyright Notice
     11  *
     12  * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
     13  * All rights reserved.
     14  *
     15  * 2. License
     16  *
     17  * 2.1. This is your license from Intel Corp. under its intellectual property
     18  * rights.  You may have additional license terms from the party that provided
     19  * you this software, covering your right to use that party's intellectual
     20  * property rights.
     21  *
     22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     23  * copy of the source code appearing in this file ("Covered Code") an
     24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     25  * base code distributed originally by Intel ("Original Intel Code") to copy,
     26  * make derivatives, distribute, use and display any portion of the Covered
     27  * Code in any form, with the right to sublicense such rights; and
     28  *
     29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     30  * license (with the right to sublicense), under only those claims of Intel
     31  * patents that are infringed by the Original Intel Code, to make, use, sell,
     32  * offer to sell, and import the Covered Code and derivative works thereof
     33  * solely to the minimum extent necessary to exercise the above copyright
     34  * license, and in no event shall the patent license extend to any additions
     35  * to or modifications of the Original Intel Code.  No other license or right
     36  * is granted directly or by implication, estoppel or otherwise;
     37  *
     38  * The above copyright and patent license is granted only if the following
     39  * conditions are met:
     40  *
     41  * 3. Conditions
     42  *
     43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     44  * Redistribution of source code of any substantial portion of the Covered
     45  * Code or modification with rights to further distribute source must include
     46  * the above Copyright Notice, the above License, this list of Conditions,
     47  * and the following Disclaimer and Export Compliance provision.  In addition,
     48  * Licensee must cause all Covered Code to which Licensee contributes to
     49  * contain a file documenting the changes Licensee made to create that Covered
     50  * Code and the date of any change.  Licensee must include in that file the
     51  * documentation of any changes made by any predecessor Licensee.  Licensee
     52  * must include a prominent statement that the modification is derived,
     53  * directly or indirectly, from Original Intel Code.
     54  *
     55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     56  * Redistribution of source code of any substantial portion of the Covered
     57  * Code or modification without rights to further distribute source must
     58  * include the following Disclaimer and Export Compliance provision in the
     59  * documentation and/or other materials provided with distribution.  In
     60  * addition, Licensee may not authorize further sublicense of source of any
     61  * portion of the Covered Code, and must include terms to the effect that the
     62  * license from Licensee to its licensee is limited to the intellectual
     63  * property embodied in the software Licensee provides to its licensee, and
     64  * not to intellectual property embodied in modifications its licensee may
     65  * make.
     66  *
     67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     68  * substantial portion of the Covered Code or modification must reproduce the
     69  * above Copyright Notice, and the following Disclaimer and Export Compliance
     70  * provision in the documentation and/or other materials provided with the
     71  * distribution.
     72  *
     73  * 3.4. Intel retains all right, title, and interest in and to the Original
     74  * Intel Code.
     75  *
     76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     77  * Intel shall be used in advertising or otherwise to promote the sale, use or
     78  * other dealings in products derived from or relating to the Covered Code
     79  * without prior written authorization from Intel.
     80  *
     81  * 4. Disclaimer and Export Compliance
     82  *
     83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
     86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
     87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
     88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     89  * PARTICULAR PURPOSE.
     90  *
     91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
     97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     98  * LIMITED REMEDY.
     99  *
    100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    101  * software or system incorporating such software without first obtaining any
    102  * required license or other approval from the U. S. Department of Commerce or
    103  * any other agency or department of the United States Government.  In the
    104  * event Licensee exports any such software from the United States or
    105  * re-exports any such software from a foreign destination, Licensee shall
    106  * ensure that the distribution and export/re-export of the software is in
    107  * compliance with all laws, regulations, orders, or other restrictions of the
    108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    109  * any of its subsidiaries will export/re-export any technical data, process,
    110  * software, or service, directly or indirectly, to any country for which the
    111  * United States government or any agency thereof requires an export license,
    112  * other governmental approval, or letter of assurance, without first obtaining
    113  * such license, approval or letter.
    114  *
    115  *****************************************************************************/
    116 
    117 
    118 #include "aslcompiler.h"
    119 #include "aslcompiler.y.h"
    120 #include "amlcode.h"
    121 #include "acparser.h"
    122 #include "acnamesp.h"
    123 
    124 #define _COMPONENT          ACPI_COMPILER
    125         ACPI_MODULE_NAME    ("aslisting")
    126 
    127 /* Local prototypes */
    128 
    129 static void
    130 LsDumpAscii (
    131     UINT32                  FileId,
    132     UINT32                  Count,
    133     UINT8                   *Buffer);
    134 
    135 static void
    136 LsDumpAsciiInComment (
    137     UINT32                  FileId,
    138     UINT32                  Count,
    139     UINT8                   *Buffer);
    140 
    141 static ACPI_STATUS
    142 LsAmlListingWalk (
    143     ACPI_PARSE_OBJECT       *Op,
    144     UINT32                  Level,
    145     void                    *Context);
    146 
    147 static void
    148 LsGenerateListing (
    149     UINT32                  FileId);
    150 
    151 static void
    152 LsPushNode (
    153     char                    *Filename);
    154 
    155 static ASL_LISTING_NODE *
    156 LsPopNode (
    157     void);
    158 
    159 static void
    160 LsCheckException (
    161     UINT32                  LineNumber,
    162     UINT32                  FileId);
    163 
    164 static void
    165 LsFlushListingBuffer (
    166     UINT32                  FileId);
    167 
    168 static void
    169 LsWriteListingHexBytes (
    170     UINT8                   *Buffer,
    171     UINT32                  Length,
    172     UINT32                  FileId);
    173 
    174 static UINT32
    175 LsWriteOneSourceLine (
    176     UINT32                  FileId);
    177 
    178 static void
    179 LsFinishSourceListing (
    180     UINT32                  FileId);
    181 
    182 static void
    183 LsWriteSourceLines (
    184     UINT32                  ToLineNumber,
    185     UINT32                  ToLogicalLineNumber,
    186     UINT32                  FileId);
    187 
    188 static void
    189 LsWriteNodeToListing (
    190     ACPI_PARSE_OBJECT       *Op,
    191     UINT32                  FileId);
    192 
    193 static void
    194 LsDoHexOutputC (
    195     void);
    196 
    197 static void
    198 LsDoHexOutputAsm (
    199     void);
    200 
    201 static void
    202 LsDoHexOutputAsl (
    203     void);
    204 
    205 ACPI_STATUS
    206 LsTreeWriteWalk (
    207     ACPI_PARSE_OBJECT       *Op,
    208     UINT32                  Level,
    209     void                    *Context);
    210 
    211 
    212 /*******************************************************************************
    213  *
    214  * FUNCTION:    LsTreeWriteWalk
    215  *
    216  * PARAMETERS:  ASL_WALK_CALLBACK
    217  *
    218  *
    219  * RETURN:      None.
    220  *
    221  * DESCRIPTION: Dump entire parse tree, for compiler debug only
    222  *
    223  ******************************************************************************/
    224 
    225 ACPI_STATUS
    226 LsTreeWriteWalk (
    227     ACPI_PARSE_OBJECT       *Op,
    228     UINT32                  Level,
    229     void                    *Context)
    230 {
    231 
    232     /* Debug output */
    233 
    234     DbgPrint (ASL_TREE_OUTPUT,
    235         "%5.5d [%2d]", Op->Asl.LogicalLineNumber, Level);
    236     UtPrintFormattedName (Op->Asl.ParseOpcode, Level);
    237 
    238 
    239     DbgPrint (ASL_TREE_OUTPUT, "\n");
    240     return (AE_OK);
    241 }
    242 
    243 
    244 void
    245 LsDumpParseTree (
    246     void)
    247 {
    248 
    249     if (!Gbl_DebugFlag)
    250     {
    251         return;
    252     }
    253 
    254     DbgPrint (ASL_TREE_OUTPUT, "\nOriginal parse tree from parser:\n\n");
    255     TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
    256         LsTreeWriteWalk, NULL, NULL);
    257 }
    258 
    259 
    260 /*******************************************************************************
    261  *
    262  * FUNCTION:    LsDumpAscii
    263  *
    264  * PARAMETERS:  FileId          - ID of current listing file
    265  *              Count           - Number of bytes to convert
    266  *              Buffer          - Buffer of bytes to convert
    267  *
    268  * RETURN:      None.
    269  *
    270  * DESCRIPTION: Convert hex bytes to ascii
    271  *
    272  ******************************************************************************/
    273 
    274 static void
    275 LsDumpAscii (
    276     UINT32                  FileId,
    277     UINT32                  Count,
    278     UINT8                   *Buffer)
    279 {
    280     UINT8                   BufChar;
    281     UINT32                  i;
    282 
    283 
    284     FlPrintFile (FileId, "    \"");
    285     for (i = 0; i < Count; i++)
    286     {
    287         BufChar = Buffer[i];
    288         if (isprint (BufChar))
    289         {
    290             FlPrintFile (FileId, "%c", BufChar);
    291         }
    292         else
    293         {
    294             /* Not a printable character, just put out a dot */
    295 
    296             FlPrintFile (FileId, ".");
    297         }
    298     }
    299     FlPrintFile (FileId, "\"");
    300 }
    301 
    302 
    303 /*******************************************************************************
    304  *
    305  * FUNCTION:    LsDumpAsciiInComment
    306  *
    307  * PARAMETERS:  FileId          - ID of current listing file
    308  *              Count           - Number of bytes to convert
    309  *              Buffer          - Buffer of bytes to convert
    310  *
    311  * RETURN:      None.
    312  *
    313  * DESCRIPTION: Convert hex bytes to ascii
    314  *
    315  ******************************************************************************/
    316 
    317 static void
    318 LsDumpAsciiInComment (
    319     UINT32                  FileId,
    320     UINT32                  Count,
    321     UINT8                   *Buffer)
    322 {
    323     UINT8                   BufChar = 0;
    324     UINT8                   LastChar;
    325     UINT32                  i;
    326 
    327 
    328     FlPrintFile (FileId, "    \"");
    329     for (i = 0; i < Count; i++)
    330     {
    331         LastChar = BufChar;
    332         BufChar = Buffer[i];
    333 
    334         if (isprint (BufChar))
    335         {
    336             /* Handle embedded C comment sequences */
    337 
    338             if (((LastChar == '*') && (BufChar == '/')) ||
    339                 ((LastChar == '/') && (BufChar == '*')))
    340             {
    341                 /* Insert a space to break the sequence */
    342 
    343                 FlPrintFile (FileId, ".", BufChar);
    344             }
    345 
    346             FlPrintFile (FileId, "%c", BufChar);
    347         }
    348         else
    349         {
    350             /* Not a printable character, just put out a dot */
    351 
    352             FlPrintFile (FileId, ".");
    353         }
    354     }
    355     FlPrintFile (FileId, "\"");
    356 }
    357 
    358 
    359 /*******************************************************************************
    360  *
    361  * FUNCTION:    LsAmlListingWalk
    362  *
    363  * PARAMETERS:  ASL_WALK_CALLBACK
    364  *
    365  * RETURN:      Status
    366  *
    367  * DESCRIPTION: Process one node during a listing file generation.
    368  *
    369  ******************************************************************************/
    370 
    371 static ACPI_STATUS
    372 LsAmlListingWalk (
    373     ACPI_PARSE_OBJECT       *Op,
    374     UINT32                  Level,
    375     void                    *Context)
    376 {
    377     UINT8                   FileByte;
    378     UINT32                  i;
    379     UINT32                  FileId = (UINT32) ACPI_TO_INTEGER (Context);
    380 
    381 
    382     LsWriteNodeToListing (Op, FileId);
    383 
    384     if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DATA)
    385     {
    386         /* Buffer is a resource template, don't dump the data all at once */
    387 
    388         return (AE_OK);
    389     }
    390 
    391     /* Write the hex bytes to the listing file(s) (if requested) */
    392 
    393     for (i = 0; i < Op->Asl.FinalAmlLength; i++)
    394     {
    395         if (ACPI_FAILURE (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte, 1)))
    396         {
    397             FlFileError (ASL_FILE_AML_OUTPUT, ASL_MSG_READ);
    398             AslAbort ();
    399         }
    400         LsWriteListingHexBytes (&FileByte, 1, FileId);
    401     }
    402 
    403     return (AE_OK);
    404 }
    405 
    406 
    407 /*******************************************************************************
    408  *
    409  * FUNCTION:    LsGenerateListing
    410  *
    411  * PARAMETERS:  FileId      - ID of listing file
    412  *
    413  * RETURN:      None
    414  *
    415  * DESCRIPTION: Generate a listing file.  This can be one of the several types
    416  *              of "listings" supported.
    417  *
    418  ******************************************************************************/
    419 
    420 static void
    421 LsGenerateListing (
    422     UINT32                  FileId)
    423 {
    424 
    425     /* Start at the beginning of both the source and AML files */
    426 
    427     FlSeekFile (ASL_FILE_SOURCE_OUTPUT, 0);
    428     FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
    429     Gbl_SourceLine = 0;
    430     Gbl_CurrentHexColumn = 0;
    431     LsPushNode (Gbl_Files[ASL_FILE_INPUT].Filename);
    432 
    433     /* Process all parse nodes */
    434 
    435     TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, LsAmlListingWalk,
    436                         NULL, (void *) ACPI_TO_POINTER (FileId));
    437 
    438     /* Final processing */
    439 
    440     LsFinishSourceListing (FileId);
    441 }
    442 
    443 
    444 /*******************************************************************************
    445  *
    446  * FUNCTION:    LsDoListings
    447  *
    448  * PARAMETERS:  None.
    449  *
    450  * RETURN:      None
    451  *
    452  * DESCRIPTION: Generate all requested listing files.
    453  *
    454  ******************************************************************************/
    455 
    456 void
    457 LsDoListings (
    458     void)
    459 {
    460 
    461     if (Gbl_C_OutputFlag)
    462     {
    463         LsGenerateListing (ASL_FILE_C_SOURCE_OUTPUT);
    464     }
    465 
    466     if (Gbl_ListingFlag)
    467     {
    468         LsGenerateListing (ASL_FILE_LISTING_OUTPUT);
    469     }
    470 
    471     if (Gbl_AsmOutputFlag)
    472     {
    473         LsGenerateListing (ASL_FILE_ASM_SOURCE_OUTPUT);
    474     }
    475 
    476     if (Gbl_C_IncludeOutputFlag)
    477     {
    478         LsGenerateListing (ASL_FILE_C_INCLUDE_OUTPUT);
    479     }
    480 
    481     if (Gbl_AsmIncludeOutputFlag)
    482     {
    483         LsGenerateListing (ASL_FILE_ASM_INCLUDE_OUTPUT);
    484     }
    485 }
    486 
    487 
    488 /*******************************************************************************
    489  *
    490  * FUNCTION:    LsPushNode
    491  *
    492  * PARAMETERS:  Filename        - Pointer to the include filename
    493  *
    494  * RETURN:      None
    495  *
    496  * DESCRIPTION: Push a listing node on the listing/include file stack.  This
    497  *              stack enables tracking of include files (infinitely nested)
    498  *              and resumption of the listing of the parent file when the
    499  *              include file is finished.
    500  *
    501  ******************************************************************************/
    502 
    503 static void
    504 LsPushNode (
    505     char                    *Filename)
    506 {
    507     ASL_LISTING_NODE        *Lnode;
    508 
    509 
    510     /* Create a new node */
    511 
    512     Lnode = UtLocalCalloc (sizeof (ASL_LISTING_NODE));
    513 
    514     /* Initialize */
    515 
    516     Lnode->Filename = Filename;
    517     Lnode->LineNumber = 0;
    518 
    519     /* Link (push) */
    520 
    521     Lnode->Next = Gbl_ListingNode;
    522     Gbl_ListingNode = Lnode;
    523 }
    524 
    525 
    526 /*******************************************************************************
    527  *
    528  * FUNCTION:    LsPopNode
    529  *
    530  * PARAMETERS:  None
    531  *
    532  * RETURN:      List head after current head is popped off
    533  *
    534  * DESCRIPTION: Pop the current head of the list, free it, and return the
    535  *              next node on the stack (the new current node).
    536  *
    537  ******************************************************************************/
    538 
    539 static ASL_LISTING_NODE *
    540 LsPopNode (
    541     void)
    542 {
    543     ASL_LISTING_NODE        *Lnode;
    544 
    545 
    546     /* Just grab the node at the head of the list */
    547 
    548     Lnode = Gbl_ListingNode;
    549     if ((!Lnode) ||
    550         (!Lnode->Next))
    551     {
    552         AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, NULL,
    553             "Could not pop empty listing stack");
    554         return Gbl_ListingNode;
    555     }
    556 
    557     Gbl_ListingNode = Lnode->Next;
    558     ACPI_FREE (Lnode);
    559 
    560     /* New "Current" node is the new head */
    561 
    562     return (Gbl_ListingNode);
    563 }
    564 
    565 
    566 /*******************************************************************************
    567  *
    568  * FUNCTION:    LsCheckException
    569  *
    570  * PARAMETERS:  LineNumber          - Current logical (cumulative) line #
    571  *              FileId              - ID of output listing file
    572  *
    573  * RETURN:      None
    574  *
    575  * DESCRIPTION: Check if there is an exception for this line, and if there is,
    576  *              put it in the listing immediately.  Handles multiple errors
    577  *              per line.  Gbl_NextError points to the next error in the
    578  *              sorted (by line #) list of compile errors/warnings.
    579  *
    580  ******************************************************************************/
    581 
    582 static void
    583 LsCheckException (
    584     UINT32                  LineNumber,
    585     UINT32                  FileId)
    586 {
    587 
    588     if ((!Gbl_NextError) ||
    589         (LineNumber < Gbl_NextError->LogicalLineNumber ))
    590     {
    591         return;
    592     }
    593 
    594     /* Handle multiple errors per line */
    595 
    596     if (FileId == ASL_FILE_LISTING_OUTPUT)
    597     {
    598         while (Gbl_NextError &&
    599               (LineNumber >= Gbl_NextError->LogicalLineNumber))
    600         {
    601             AePrintException (FileId, Gbl_NextError, "\n[****iasl****]\n");
    602 
    603             Gbl_NextError = Gbl_NextError->Next;
    604         }
    605 
    606         FlPrintFile (FileId, "\n");
    607     }
    608 }
    609 
    610 
    611 /*******************************************************************************
    612  *
    613  * FUNCTION:    LsFlushListingBuffer
    614  *
    615  * PARAMETERS:  FileId          - ID of the listing file
    616  *
    617  * RETURN:      None
    618  *
    619  * DESCRIPTION: Flush out the current contents of the 16-byte hex AML code
    620  *              buffer.  Usually called at the termination of a single line
    621  *              of source code or when the buffer is full.
    622  *
    623  ******************************************************************************/
    624 
    625 static void
    626 LsFlushListingBuffer (
    627     UINT32                  FileId)
    628 {
    629     UINT32                  i;
    630 
    631 
    632     if (Gbl_CurrentHexColumn == 0)
    633     {
    634         return;
    635     }
    636 
    637     /* Write the hex bytes */
    638 
    639     switch (FileId)
    640     {
    641     case ASL_FILE_LISTING_OUTPUT:
    642 
    643         for (i = 0; i < Gbl_CurrentHexColumn; i++)
    644         {
    645             FlPrintFile (FileId, "%2.2X ", Gbl_AmlBuffer[i]);
    646         }
    647 
    648         for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 3); i++)
    649         {
    650             FlWriteFile (FileId, ".", 1);
    651         }
    652 
    653         /* Write the ASCII character associated with each of the bytes */
    654 
    655         LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer);
    656         break;
    657 
    658 
    659     case ASL_FILE_ASM_SOURCE_OUTPUT:
    660 
    661         for (i = 0; i < Gbl_CurrentHexColumn; i++)
    662         {
    663             if (i > 0)
    664             {
    665                 FlPrintFile (FileId, ",");
    666             }
    667             FlPrintFile (FileId, "0%2.2Xh", Gbl_AmlBuffer[i]);
    668         }
    669 
    670         for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++)
    671         {
    672             FlWriteFile (FileId, " ", 1);
    673         }
    674 
    675         FlPrintFile (FileId, "  ;%8.8X",
    676             Gbl_CurrentAmlOffset - HEX_LISTING_LINE_SIZE);
    677 
    678         /* Write the ASCII character associated with each of the bytes */
    679 
    680         LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer);
    681         break;
    682 
    683 
    684     case ASL_FILE_C_SOURCE_OUTPUT:
    685 
    686         for (i = 0; i < Gbl_CurrentHexColumn; i++)
    687         {
    688             FlPrintFile (FileId, "0x%2.2X,", Gbl_AmlBuffer[i]);
    689         }
    690 
    691         for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++)
    692         {
    693             FlWriteFile (FileId, " ", 1);
    694         }
    695 
    696         FlPrintFile (FileId, "    /* %8.8X",
    697             Gbl_CurrentAmlOffset - HEX_LISTING_LINE_SIZE);
    698 
    699         /* Write the ASCII character associated with each of the bytes */
    700 
    701         LsDumpAsciiInComment (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer);
    702         FlPrintFile (FileId, " */");
    703         break;
    704 
    705     default:
    706         /* No other types supported */
    707         return;
    708     }
    709 
    710     FlPrintFile (FileId, "\n");
    711 
    712     Gbl_CurrentHexColumn = 0;
    713     Gbl_HexBytesWereWritten = TRUE;
    714 }
    715 
    716 
    717 /*******************************************************************************
    718  *
    719  * FUNCTION:    LsWriteListingHexBytes
    720  *
    721  * PARAMETERS:  Buffer          - AML code buffer
    722  *              Length          - Number of AML bytes to write
    723  *              FileId          - ID of current listing file.
    724  *
    725  * RETURN:      None
    726  *
    727  * DESCRIPTION: Write the contents of the AML buffer to the listing file via
    728  *              the listing buffer.  The listing buffer is flushed every 16
    729  *              AML bytes.
    730  *
    731  ******************************************************************************/
    732 
    733 static void
    734 LsWriteListingHexBytes (
    735     UINT8                   *Buffer,
    736     UINT32                  Length,
    737     UINT32                  FileId)
    738 {
    739     UINT32                  i;
    740 
    741 
    742     /* Transfer all requested bytes */
    743 
    744     for (i = 0; i < Length; i++)
    745     {
    746         /* Print line header when buffer is empty */
    747 
    748         if (Gbl_CurrentHexColumn == 0)
    749         {
    750             if (Gbl_HasIncludeFiles)
    751             {
    752                 FlPrintFile (FileId, "%*s", 10, " ");
    753             }
    754 
    755             switch (FileId)
    756             {
    757             case ASL_FILE_LISTING_OUTPUT:
    758 
    759                 FlPrintFile (FileId, "%8.8X....", Gbl_CurrentAmlOffset);
    760                 break;
    761 
    762             case ASL_FILE_ASM_SOURCE_OUTPUT:
    763 
    764                 FlPrintFile (FileId, "    db ");
    765                 break;
    766 
    767             case ASL_FILE_C_SOURCE_OUTPUT:
    768 
    769                 FlPrintFile (FileId, "        ");
    770                 break;
    771 
    772             default:
    773                 /* No other types supported */
    774                 return;
    775             }
    776         }
    777 
    778         /* Transfer AML byte and update counts */
    779 
    780         Gbl_AmlBuffer[Gbl_CurrentHexColumn] = Buffer[i];
    781 
    782         Gbl_CurrentHexColumn++;
    783         Gbl_CurrentAmlOffset++;
    784 
    785         /* Flush buffer when it is full */
    786 
    787         if (Gbl_CurrentHexColumn >= HEX_LISTING_LINE_SIZE)
    788         {
    789             LsFlushListingBuffer (FileId);
    790         }
    791     }
    792 }
    793 
    794 
    795 /*******************************************************************************
    796  *
    797  * FUNCTION:    LsWriteOneSourceLine
    798  *
    799  * PARAMETERS:  FileID          - ID of current listing file
    800  *
    801  * RETURN:      FALSE on EOF (input source file), TRUE otherwise
    802  *
    803  * DESCRIPTION: Read one line from the input source file and echo it to the
    804  *              listing file, prefixed with the line number, and if the source
    805  *              file contains include files, prefixed with the current filename
    806  *
    807  ******************************************************************************/
    808 
    809 static UINT32
    810 LsWriteOneSourceLine (
    811     UINT32                  FileId)
    812 {
    813     UINT8                   FileByte;
    814 
    815 
    816     Gbl_SourceLine++;
    817     Gbl_ListingNode->LineNumber++;
    818 
    819     if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
    820     {
    821         FlPrintFile (FileId, "     *");
    822     }
    823     if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
    824     {
    825         FlPrintFile (FileId, "; ");
    826     }
    827 
    828     if (Gbl_HasIncludeFiles)
    829     {
    830         /*
    831          * This file contains "include" statements, print the current
    832          * filename and line number within the current file
    833          */
    834         FlPrintFile (FileId, "%12s %5d....",
    835                     Gbl_ListingNode->Filename, Gbl_ListingNode->LineNumber);
    836     }
    837     else
    838     {
    839         /* No include files, just print the line number */
    840 
    841         FlPrintFile (FileId, "%8d....", Gbl_SourceLine);
    842     }
    843 
    844     /* Read one line (up to a newline or EOF) */
    845 
    846     while (FlReadFile (ASL_FILE_SOURCE_OUTPUT, &FileByte, 1) == AE_OK)
    847     {
    848         if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
    849         {
    850             if (FileByte == '/')
    851             {
    852                 FileByte = '*';
    853             }
    854         }
    855 
    856         FlWriteFile (FileId, &FileByte, 1);
    857         if (FileByte == '\n')
    858         {
    859             /*
    860              * Check if an error occurred on this source line during the compile.
    861              * If so, we print the error message after the source line.
    862              */
    863             LsCheckException (Gbl_SourceLine, FileId);
    864             return (1);
    865         }
    866     }
    867 
    868     /* EOF on the input file was reached */
    869 
    870     return (0);
    871 }
    872 
    873 
    874 /*******************************************************************************
    875  *
    876  * FUNCTION:    LsFinishSourceListing
    877  *
    878  * PARAMETERS:  FileId          - ID of current listing file.
    879  *
    880  * RETURN:      None
    881  *
    882  * DESCRIPTION: Cleanup routine for the listing file.  Flush the hex AML
    883  *              listing buffer, and flush out any remaining lines in the
    884  *              source input file.
    885  *
    886  ******************************************************************************/
    887 
    888 static void
    889 LsFinishSourceListing (
    890     UINT32                  FileId)
    891 {
    892 
    893     if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) ||
    894         (FileId == ASL_FILE_C_INCLUDE_OUTPUT))
    895     {
    896         return;
    897     }
    898 
    899     LsFlushListingBuffer (FileId);
    900     Gbl_CurrentAmlOffset = 0;
    901 
    902     /* Flush any remaining text in the source file */
    903 
    904     if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
    905     {
    906         FlPrintFile (FileId, "    /*\n");
    907     }
    908 
    909     while (LsWriteOneSourceLine (FileId))
    910     { ; }
    911 
    912     if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
    913     {
    914         FlPrintFile (FileId, "\n     */\n    };\n");
    915     }
    916 
    917     FlPrintFile (FileId, "\n");
    918 
    919     if (FileId == ASL_FILE_LISTING_OUTPUT)
    920     {
    921         /* Print a summary of the compile exceptions */
    922 
    923         FlPrintFile (FileId, "\n\nSummary of errors and warnings\n\n");
    924         AePrintErrorLog (FileId);
    925         FlPrintFile (FileId, "\n\n");
    926         UtDisplaySummary (FileId);
    927         FlPrintFile (FileId, "\n\n");
    928     }
    929 }
    930 
    931 
    932 /*******************************************************************************
    933  *
    934  * FUNCTION:    LsWriteSourceLines
    935  *
    936  * PARAMETERS:  ToLineNumber            -
    937  *              ToLogicalLineNumber     - Write up to this source line number
    938  *              FileId                  - ID of current listing file
    939  *
    940  * RETURN:      None
    941  *
    942  * DESCRIPTION: Read then write source lines to the listing file until we have
    943  *              reached the specified logical (cumulative) line number.  This
    944  *              automatically echos out comment blocks and other non-AML
    945  *              generating text until we get to the actual AML-generating line
    946  *              of ASL code specified by the logical line number.
    947  *
    948  ******************************************************************************/
    949 
    950 static void
    951 LsWriteSourceLines (
    952     UINT32                  ToLineNumber,
    953     UINT32                  ToLogicalLineNumber,
    954     UINT32                  FileId)
    955 {
    956 
    957     if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) ||
    958         (FileId == ASL_FILE_C_INCLUDE_OUTPUT))
    959     {
    960         return;
    961     }
    962 
    963     Gbl_CurrentLine = ToLogicalLineNumber;
    964 
    965     /* Flush any hex bytes remaining from the last opcode */
    966 
    967     LsFlushListingBuffer (FileId);
    968 
    969     /* Read lines and write them as long as we are not caught up */
    970 
    971     if (Gbl_SourceLine < Gbl_CurrentLine)
    972     {
    973         /*
    974          * If we just completed writing some AML hex bytes, output a linefeed
    975          * to add some whitespace for readability.
    976          */
    977         if (Gbl_HexBytesWereWritten)
    978         {
    979             FlPrintFile (FileId, "\n");
    980             Gbl_HexBytesWereWritten = FALSE;
    981         }
    982 
    983         if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
    984         {
    985             FlPrintFile (FileId, "    /*\n");
    986         }
    987 
    988         /* Write one line at a time until we have reached the target line # */
    989 
    990         while ((Gbl_SourceLine < Gbl_CurrentLine) &&
    991                 LsWriteOneSourceLine (FileId))
    992         { ; }
    993 
    994         if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
    995         {
    996             FlPrintFile (FileId, "     */");
    997         }
    998         FlPrintFile (FileId, "\n");
    999     }
   1000 }
   1001 
   1002 
   1003 /*******************************************************************************
   1004  *
   1005  * FUNCTION:    LsWriteNodeToListing
   1006  *
   1007  * PARAMETERS:  Op            - Parse node to write to the listing file.
   1008  *              FileId          - ID of current listing file
   1009  *
   1010  * RETURN:      None.
   1011  *
   1012  * DESCRIPTION: Write "a node" to the listing file.  This means to
   1013  *              1) Write out all of the source text associated with the node
   1014  *              2) Write out all of the AML bytes associated with the node
   1015  *              3) Write any compiler exceptions associated with the node
   1016  *
   1017  ******************************************************************************/
   1018 
   1019 static void
   1020 LsWriteNodeToListing (
   1021     ACPI_PARSE_OBJECT       *Op,
   1022     UINT32                  FileId)
   1023 {
   1024     const ACPI_OPCODE_INFO  *OpInfo;
   1025     UINT32                  OpClass;
   1026     char                    *Pathname;
   1027     UINT32                  Length;
   1028     UINT32                  i;
   1029 
   1030 
   1031     OpInfo  = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
   1032     OpClass = OpInfo->Class;
   1033 
   1034     /* TBD: clean this up with a single flag that says:
   1035      * I start a named output block
   1036      */
   1037     if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
   1038     {
   1039         switch (Op->Asl.ParseOpcode)
   1040         {
   1041         case PARSEOP_DEFINITIONBLOCK:
   1042         case PARSEOP_METHODCALL:
   1043         case PARSEOP_INCLUDE:
   1044         case PARSEOP_INCLUDE_END:
   1045         case PARSEOP_DEFAULT_ARG:
   1046 
   1047             break;
   1048 
   1049         default:
   1050             switch (OpClass)
   1051             {
   1052             case AML_CLASS_NAMED_OBJECT:
   1053                 switch (Op->Asl.AmlOpcode)
   1054                 {
   1055                 case AML_SCOPE_OP:
   1056                 case AML_ALIAS_OP:
   1057                     break;
   1058 
   1059                 default:
   1060                     if (Op->Asl.ExternalName)
   1061                     {
   1062                         LsFlushListingBuffer (FileId);
   1063                         FlPrintFile (FileId, "    };\n");
   1064                     }
   1065                     break;
   1066                 }
   1067                 break;
   1068 
   1069             default:
   1070                 /* Don't care about other objects */
   1071                 break;
   1072             }
   1073             break;
   1074         }
   1075     }
   1076 
   1077     /* These cases do not have a corresponding AML opcode */
   1078 
   1079     switch (Op->Asl.ParseOpcode)
   1080     {
   1081     case PARSEOP_DEFINITIONBLOCK:
   1082 
   1083         LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine, FileId);
   1084 
   1085         /* Use the table Signature and TableId to build a unique name */
   1086 
   1087         if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
   1088         {
   1089             FlPrintFile (FileId,
   1090                 "%s_%s_Header \\\n",
   1091                 Gbl_TableSignature, Gbl_TableId);
   1092         }
   1093         if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
   1094         {
   1095             FlPrintFile (FileId,
   1096                 "    unsigned char    %s_%s_Header [] =\n    {\n",
   1097                 Gbl_TableSignature, Gbl_TableId);
   1098         }
   1099         if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT)
   1100         {
   1101             FlPrintFile (FileId,
   1102                 "extrn %s_%s_Header : byte\n",
   1103                 Gbl_TableSignature, Gbl_TableId);
   1104         }
   1105         if (FileId == ASL_FILE_C_INCLUDE_OUTPUT)
   1106         {
   1107             FlPrintFile (FileId,
   1108                 "extern unsigned char    %s_%s_Header [];\n",
   1109                 Gbl_TableSignature, Gbl_TableId);
   1110         }
   1111         return;
   1112 
   1113 
   1114     case PARSEOP_METHODCALL:
   1115 
   1116         LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
   1117             FileId);
   1118         return;
   1119 
   1120 
   1121     case PARSEOP_INCLUDE:
   1122 
   1123         /* Flush everything up to and including the include source line */
   1124 
   1125         LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
   1126             FileId);
   1127 
   1128         /* Create a new listing node and push it */
   1129 
   1130         LsPushNode (Op->Asl.Child->Asl.Value.String);
   1131         return;
   1132 
   1133 
   1134     case PARSEOP_INCLUDE_END:
   1135 
   1136         /* Flush out the rest of the include file */
   1137 
   1138         LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
   1139             FileId);
   1140 
   1141         /* Pop off this listing node and go back to the parent file */
   1142 
   1143         (void) LsPopNode ();
   1144         return;
   1145 
   1146 
   1147     case PARSEOP_DEFAULT_ARG:
   1148 
   1149         if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
   1150         {
   1151             LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.EndLogicalLine,
   1152                 FileId);
   1153         }
   1154         return;
   1155 
   1156 
   1157     default:
   1158         /* All other opcodes have an AML opcode */
   1159         break;
   1160     }
   1161 
   1162     /*
   1163      * Otherwise, we look at the AML opcode because we can
   1164      * switch on the opcode type, getting an entire class
   1165      * at once
   1166      */
   1167     switch (OpClass)
   1168     {
   1169     case AML_CLASS_ARGUMENT:       /* argument type only */
   1170     case AML_CLASS_INTERNAL:
   1171 
   1172         break;
   1173 
   1174 
   1175     case AML_CLASS_NAMED_OBJECT:
   1176 
   1177         switch (Op->Asl.AmlOpcode)
   1178         {
   1179         case AML_FIELD_OP:
   1180         case AML_INDEX_FIELD_OP:
   1181         case AML_BANK_FIELD_OP:
   1182 
   1183             /*
   1184              * For fields, we want to dump all the AML after the
   1185              * entire definition
   1186              */
   1187             LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine,
   1188                 FileId);
   1189             break;
   1190 
   1191         case AML_NAME_OP:
   1192 
   1193             if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
   1194             {
   1195                 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
   1196                     FileId);
   1197             }
   1198             else
   1199             {
   1200                 /*
   1201                  * For fields, we want to dump all the AML after the
   1202                  * entire definition
   1203                  */
   1204                 LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine,
   1205                     FileId);
   1206             }
   1207             break;
   1208 
   1209         default:
   1210             LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
   1211                 FileId);
   1212             break;
   1213         }
   1214 
   1215         switch (Op->Asl.AmlOpcode)
   1216         {
   1217         case AML_SCOPE_OP:
   1218         case AML_ALIAS_OP:
   1219 
   1220             /* These opcodes do not declare a new object, ignore them */
   1221 
   1222             break;
   1223 
   1224         default:
   1225 
   1226             /* All other named object opcodes come here */
   1227 
   1228             switch (FileId)
   1229             {
   1230             case ASL_FILE_ASM_SOURCE_OUTPUT:
   1231             case ASL_FILE_C_SOURCE_OUTPUT:
   1232             case ASL_FILE_ASM_INCLUDE_OUTPUT:
   1233             case ASL_FILE_C_INCLUDE_OUTPUT:
   1234 
   1235                 /*
   1236                  * For named objects, we will create a valid symbol so that the
   1237                  * AML code can be referenced from C or ASM
   1238                  */
   1239                 if (Op->Asl.ExternalName)
   1240                 {
   1241                     /* Get the full pathname associated with this node */
   1242 
   1243                     Pathname = AcpiNsGetExternalPathname (Op->Asl.Node);
   1244                     Length = strlen (Pathname);
   1245                     if (Length >= 4)
   1246                     {
   1247                         /* Convert all dots in the path to underscores */
   1248 
   1249                         for (i = 0; i < Length; i++)
   1250                         {
   1251                             if (Pathname[i] == '.')
   1252                             {
   1253                                 Pathname[i] = '_';
   1254                             }
   1255                         }
   1256 
   1257                         /* Create the appropriate symbol in the output file */
   1258 
   1259                         if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
   1260                         {
   1261                             FlPrintFile (FileId,
   1262                                 "%s_%s_%s  \\\n",
   1263                                 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
   1264                         }
   1265                         if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
   1266                         {
   1267                             FlPrintFile (FileId,
   1268                                 "    unsigned char    %s_%s_%s [] =\n    {\n",
   1269                                 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
   1270                         }
   1271                         if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT)
   1272                         {
   1273                             FlPrintFile (FileId,
   1274                                 "extrn %s_%s_%s : byte\n",
   1275                                 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
   1276                         }
   1277                         if (FileId == ASL_FILE_C_INCLUDE_OUTPUT)
   1278                         {
   1279                             FlPrintFile (FileId,
   1280                                 "extern unsigned char    %s_%s_%s [];\n",
   1281                                 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
   1282                         }
   1283                     }
   1284                     ACPI_FREE (Pathname);
   1285                 }
   1286                 break;
   1287 
   1288             default:
   1289                 /* Nothing to do for listing file */
   1290                 break;
   1291             }
   1292         }
   1293         break;
   1294 
   1295     case AML_CLASS_EXECUTE:
   1296     case AML_CLASS_CREATE:
   1297     default:
   1298 
   1299         if ((Op->Asl.ParseOpcode == PARSEOP_BUFFER) &&
   1300             (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC))
   1301         {
   1302             return;
   1303         }
   1304 
   1305         LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
   1306             FileId);
   1307         break;
   1308 
   1309     case AML_CLASS_UNKNOWN:
   1310         break;
   1311     }
   1312 }
   1313 
   1314 
   1315 /*******************************************************************************
   1316  *
   1317  * FUNCTION:    LsDoHexOutput
   1318  *
   1319  * PARAMETERS:  None
   1320  *
   1321  * RETURN:      None.
   1322  *
   1323  * DESCRIPTION: Create the hex output file.
   1324  *
   1325  ******************************************************************************/
   1326 
   1327 void
   1328 LsDoHexOutput (
   1329     void)
   1330 {
   1331 
   1332     switch (Gbl_HexOutputFlag)
   1333     {
   1334     case HEX_OUTPUT_C:
   1335 
   1336         LsDoHexOutputC ();
   1337         break;
   1338 
   1339     case HEX_OUTPUT_ASM:
   1340 
   1341         LsDoHexOutputAsm ();
   1342         break;
   1343 
   1344     case HEX_OUTPUT_ASL:
   1345 
   1346         LsDoHexOutputAsl ();
   1347         break;
   1348 
   1349     default:
   1350         /* No other output types supported */
   1351         break;
   1352     }
   1353 }
   1354 
   1355 
   1356 /*******************************************************************************
   1357  *
   1358  * FUNCTION:    LsDoHexOutputC
   1359  *
   1360  * PARAMETERS:  None
   1361  *
   1362  * RETURN:      None.
   1363  *
   1364  * DESCRIPTION: Create the hex output file.  This is the same data as the AML
   1365  *              output file, but formatted into hex/ascii bytes suitable for
   1366  *              inclusion into a C source file.
   1367  *
   1368  ******************************************************************************/
   1369 
   1370 static void
   1371 LsDoHexOutputC (
   1372     void)
   1373 {
   1374     UINT8                   FileData[HEX_TABLE_LINE_SIZE];
   1375     UINT32                  LineLength;
   1376     UINT32                  Offset = 0;
   1377     UINT32                  AmlFileSize;
   1378     UINT32                  i;
   1379 
   1380 
   1381     /* Get AML size, seek back to start */
   1382 
   1383     AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
   1384 
   1385     FlPrintFile (ASL_FILE_HEX_OUTPUT, " * C source code output\n");
   1386     FlPrintFile (ASL_FILE_HEX_OUTPUT, " * AML code block contains 0x%X bytes\n *\n */\n",
   1387         AmlFileSize);
   1388     FlPrintFile (ASL_FILE_HEX_OUTPUT, "unsigned char AmlCode[] =\n{\n");
   1389 
   1390     while (Offset < AmlFileSize)
   1391     {
   1392         /* Read enough bytes needed for one output line */
   1393 
   1394         LineLength = fread (FileData, 1, HEX_TABLE_LINE_SIZE,
   1395                         Gbl_Files[ASL_FILE_AML_OUTPUT].Handle);
   1396         if (!LineLength)
   1397         {
   1398             break;
   1399         }
   1400 
   1401         FlPrintFile (ASL_FILE_HEX_OUTPUT, "    ");
   1402 
   1403         for (i = 0; i < LineLength; i++)
   1404         {
   1405             /*
   1406              * Print each hex byte.
   1407              * Add a comma until the very last byte of the AML file
   1408              * (Some C compilers complain about a trailing comma)
   1409              */
   1410             FlPrintFile (ASL_FILE_HEX_OUTPUT, "0x%2.2X", FileData[i]);
   1411             if ((Offset + i + 1) < AmlFileSize)
   1412             {
   1413                 FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
   1414             }
   1415             else
   1416             {
   1417                 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
   1418             }
   1419         }
   1420 
   1421         /* Add fill spaces if needed for last line */
   1422 
   1423         if (LineLength < HEX_TABLE_LINE_SIZE)
   1424         {
   1425             FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
   1426                 5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
   1427         }
   1428 
   1429         /* Emit the offset and ascii dump for the entire line */
   1430 
   1431         FlPrintFile (ASL_FILE_HEX_OUTPUT, "  /* %8.8X", Offset);
   1432         LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData);
   1433         FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s*/\n",
   1434             HEX_TABLE_LINE_SIZE - LineLength + 1, " ");
   1435 
   1436         Offset += LineLength;
   1437     }
   1438 
   1439     FlPrintFile (ASL_FILE_HEX_OUTPUT, "};\n");
   1440     FlCloseFile (ASL_FILE_HEX_OUTPUT);
   1441 }
   1442 
   1443 
   1444 /*******************************************************************************
   1445  *
   1446  * FUNCTION:    LsDoHexOutputAsl
   1447  *
   1448  * PARAMETERS:  None
   1449  *
   1450  * RETURN:      None.
   1451  *
   1452  * DESCRIPTION: Create the hex output file.  This is the same data as the AML
   1453  *              output file, but formatted into hex/ascii bytes suitable for
   1454  *              inclusion into a C source file.
   1455  *
   1456  ******************************************************************************/
   1457 
   1458 static void
   1459 LsDoHexOutputAsl (
   1460     void)
   1461 {
   1462     UINT8                   FileData[HEX_TABLE_LINE_SIZE];
   1463     UINT32                  LineLength;
   1464     UINT32                  Offset = 0;
   1465     UINT32                  AmlFileSize;
   1466     UINT32                  i;
   1467 
   1468 
   1469     /* Get AML size, seek back to start */
   1470 
   1471     AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
   1472 
   1473     FlPrintFile (ASL_FILE_HEX_OUTPUT, " * ASL source code output\n");
   1474     FlPrintFile (ASL_FILE_HEX_OUTPUT, " * AML code block contains 0x%X bytes\n *\n */\n",
   1475         AmlFileSize);
   1476     FlPrintFile (ASL_FILE_HEX_OUTPUT, "    Name (BUF1, Buffer()\n    {\n");
   1477 
   1478     while (Offset < AmlFileSize)
   1479     {
   1480         /* Read enough bytes needed for one output line */
   1481 
   1482         LineLength = fread (FileData, 1, HEX_TABLE_LINE_SIZE,
   1483                         Gbl_Files[ASL_FILE_AML_OUTPUT].Handle);
   1484         if (!LineLength)
   1485         {
   1486             break;
   1487         }
   1488 
   1489         FlPrintFile (ASL_FILE_HEX_OUTPUT, "        ");
   1490 
   1491         for (i = 0; i < LineLength; i++)
   1492         {
   1493             /*
   1494              * Print each hex byte.
   1495              * Add a comma until the very last byte of the AML file
   1496              * (Some C compilers complain about a trailing comma)
   1497              */
   1498             FlPrintFile (ASL_FILE_HEX_OUTPUT, "0x%2.2X", FileData[i]);
   1499             if ((Offset + i + 1) < AmlFileSize)
   1500             {
   1501                 FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
   1502             }
   1503             else
   1504             {
   1505                 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
   1506             }
   1507         }
   1508 
   1509         /* Add fill spaces if needed for last line */
   1510 
   1511         if (LineLength < HEX_TABLE_LINE_SIZE)
   1512         {
   1513             FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
   1514                 5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
   1515         }
   1516 
   1517         /* Emit the offset and ascii dump for the entire line */
   1518 
   1519         FlPrintFile (ASL_FILE_HEX_OUTPUT, "  /* %8.8X", Offset);
   1520         LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData);
   1521         FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s*/\n",
   1522             HEX_TABLE_LINE_SIZE - LineLength + 1, " ");
   1523 
   1524         Offset += LineLength;
   1525     }
   1526 
   1527     FlPrintFile (ASL_FILE_HEX_OUTPUT, "    })\n");
   1528     FlCloseFile (ASL_FILE_HEX_OUTPUT);
   1529 }
   1530 
   1531 
   1532 /*******************************************************************************
   1533  *
   1534  * FUNCTION:    LsDoHexOutputAsm
   1535  *
   1536  * PARAMETERS:  None
   1537  *
   1538  * RETURN:      None.
   1539  *
   1540  * DESCRIPTION: Create the hex output file.  This is the same data as the AML
   1541  *              output file, but formatted into hex/ascii bytes suitable for
   1542  *              inclusion into a ASM source file.
   1543  *
   1544  ******************************************************************************/
   1545 
   1546 static void
   1547 LsDoHexOutputAsm (
   1548     void)
   1549 {
   1550     UINT8                   FileData[HEX_TABLE_LINE_SIZE];
   1551     UINT32                  LineLength;
   1552     UINT32                  Offset = 0;
   1553     UINT32                  AmlFileSize;
   1554     UINT32                  i;
   1555 
   1556 
   1557     /* Get AML size, seek back to start */
   1558 
   1559     AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
   1560 
   1561     FlPrintFile (ASL_FILE_HEX_OUTPUT, "; Assembly code source output\n");
   1562     FlPrintFile (ASL_FILE_HEX_OUTPUT, "; AML code block contains 0x%X bytes\n;\n",
   1563         AmlFileSize);
   1564 
   1565     while (Offset < AmlFileSize)
   1566     {
   1567         /* Read enough bytes needed for one output line */
   1568 
   1569         LineLength = fread (FileData, 1, HEX_TABLE_LINE_SIZE,
   1570                         Gbl_Files[ASL_FILE_AML_OUTPUT].Handle);
   1571         if (!LineLength)
   1572         {
   1573             break;
   1574         }
   1575 
   1576         FlPrintFile (ASL_FILE_HEX_OUTPUT, "  db  ");
   1577 
   1578         for (i = 0; i < LineLength; i++)
   1579         {
   1580             /*
   1581              * Print each hex byte.
   1582              * Add a comma until the last byte of the line
   1583              */
   1584             FlPrintFile (ASL_FILE_HEX_OUTPUT, "0%2.2Xh", FileData[i]);
   1585             if ((i + 1) < LineLength)
   1586             {
   1587                 FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
   1588             }
   1589         }
   1590 
   1591         FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
   1592 
   1593         /* Add fill spaces if needed for last line */
   1594 
   1595         if (LineLength < HEX_TABLE_LINE_SIZE)
   1596         {
   1597             FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
   1598                 5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
   1599         }
   1600 
   1601         /* Emit the offset and ascii dump for the entire line */
   1602 
   1603         FlPrintFile (ASL_FILE_HEX_OUTPUT, "  ; %8.8X", Offset);
   1604         LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData);
   1605         FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n");
   1606 
   1607         Offset += LineLength;
   1608     }
   1609 
   1610     FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n");
   1611     FlCloseFile (ASL_FILE_HEX_OUTPUT);
   1612 }
   1613 
   1614 
   1615