Home | History | Annotate | Line # | Download | only in compiler
aslcodegen.c revision 1.1.1.2.2.2
      1  1.1.1.2.2.2  bouyer 
      2  1.1.1.2.2.2  bouyer /******************************************************************************
      3  1.1.1.2.2.2  bouyer  *
      4  1.1.1.2.2.2  bouyer  * Module Name: aslcodegen - AML code generation
      5  1.1.1.2.2.2  bouyer  *
      6  1.1.1.2.2.2  bouyer  *****************************************************************************/
      7  1.1.1.2.2.2  bouyer 
      8  1.1.1.2.2.2  bouyer /*
      9  1.1.1.2.2.2  bouyer  * Copyright (C) 2000 - 2011, Intel Corp.
     10  1.1.1.2.2.2  bouyer  * All rights reserved.
     11  1.1.1.2.2.2  bouyer  *
     12  1.1.1.2.2.2  bouyer  * Redistribution and use in source and binary forms, with or without
     13  1.1.1.2.2.2  bouyer  * modification, are permitted provided that the following conditions
     14  1.1.1.2.2.2  bouyer  * are met:
     15  1.1.1.2.2.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     16  1.1.1.2.2.2  bouyer  *    notice, this list of conditions, and the following disclaimer,
     17  1.1.1.2.2.2  bouyer  *    without modification.
     18  1.1.1.2.2.2  bouyer  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     19  1.1.1.2.2.2  bouyer  *    substantially similar to the "NO WARRANTY" disclaimer below
     20  1.1.1.2.2.2  bouyer  *    ("Disclaimer") and any redistribution must be conditioned upon
     21  1.1.1.2.2.2  bouyer  *    including a substantially similar Disclaimer requirement for further
     22  1.1.1.2.2.2  bouyer  *    binary redistribution.
     23  1.1.1.2.2.2  bouyer  * 3. Neither the names of the above-listed copyright holders nor the names
     24  1.1.1.2.2.2  bouyer  *    of any contributors may be used to endorse or promote products derived
     25  1.1.1.2.2.2  bouyer  *    from this software without specific prior written permission.
     26  1.1.1.2.2.2  bouyer  *
     27  1.1.1.2.2.2  bouyer  * Alternatively, this software may be distributed under the terms of the
     28  1.1.1.2.2.2  bouyer  * GNU General Public License ("GPL") version 2 as published by the Free
     29  1.1.1.2.2.2  bouyer  * Software Foundation.
     30  1.1.1.2.2.2  bouyer  *
     31  1.1.1.2.2.2  bouyer  * NO WARRANTY
     32  1.1.1.2.2.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     33  1.1.1.2.2.2  bouyer  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     34  1.1.1.2.2.2  bouyer  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     35  1.1.1.2.2.2  bouyer  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     36  1.1.1.2.2.2  bouyer  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  1.1.1.2.2.2  bouyer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  1.1.1.2.2.2  bouyer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  1.1.1.2.2.2  bouyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     40  1.1.1.2.2.2  bouyer  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     41  1.1.1.2.2.2  bouyer  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     42  1.1.1.2.2.2  bouyer  * POSSIBILITY OF SUCH DAMAGES.
     43  1.1.1.2.2.2  bouyer  */
     44  1.1.1.2.2.2  bouyer 
     45  1.1.1.2.2.2  bouyer 
     46  1.1.1.2.2.2  bouyer #include "aslcompiler.h"
     47  1.1.1.2.2.2  bouyer #include "aslcompiler.y.h"
     48  1.1.1.2.2.2  bouyer #include "amlcode.h"
     49  1.1.1.2.2.2  bouyer 
     50  1.1.1.2.2.2  bouyer #define _COMPONENT          ACPI_COMPILER
     51  1.1.1.2.2.2  bouyer         ACPI_MODULE_NAME    ("aslcodegen")
     52  1.1.1.2.2.2  bouyer 
     53  1.1.1.2.2.2  bouyer /* Local prototypes */
     54  1.1.1.2.2.2  bouyer 
     55  1.1.1.2.2.2  bouyer static ACPI_STATUS
     56  1.1.1.2.2.2  bouyer CgAmlWriteWalk (
     57  1.1.1.2.2.2  bouyer     ACPI_PARSE_OBJECT       *Op,
     58  1.1.1.2.2.2  bouyer     UINT32                  Level,
     59  1.1.1.2.2.2  bouyer     void                    *Context);
     60  1.1.1.2.2.2  bouyer 
     61  1.1.1.2.2.2  bouyer static void
     62  1.1.1.2.2.2  bouyer CgLocalWriteAmlData (
     63  1.1.1.2.2.2  bouyer     ACPI_PARSE_OBJECT       *Op,
     64  1.1.1.2.2.2  bouyer     void                    *Buffer,
     65  1.1.1.2.2.2  bouyer     UINT32                  Length);
     66  1.1.1.2.2.2  bouyer 
     67  1.1.1.2.2.2  bouyer static void
     68  1.1.1.2.2.2  bouyer CgWriteAmlOpcode (
     69  1.1.1.2.2.2  bouyer     ACPI_PARSE_OBJECT       *Op);
     70  1.1.1.2.2.2  bouyer 
     71  1.1.1.2.2.2  bouyer static void
     72  1.1.1.2.2.2  bouyer CgWriteTableHeader (
     73  1.1.1.2.2.2  bouyer     ACPI_PARSE_OBJECT       *Op);
     74  1.1.1.2.2.2  bouyer 
     75  1.1.1.2.2.2  bouyer static void
     76  1.1.1.2.2.2  bouyer CgCloseTable (
     77  1.1.1.2.2.2  bouyer     void);
     78  1.1.1.2.2.2  bouyer 
     79  1.1.1.2.2.2  bouyer static void
     80  1.1.1.2.2.2  bouyer CgWriteNode (
     81  1.1.1.2.2.2  bouyer     ACPI_PARSE_OBJECT       *Op);
     82  1.1.1.2.2.2  bouyer 
     83  1.1.1.2.2.2  bouyer 
     84  1.1.1.2.2.2  bouyer /*******************************************************************************
     85  1.1.1.2.2.2  bouyer  *
     86  1.1.1.2.2.2  bouyer  * FUNCTION:    CgGenerateAmlOutput
     87  1.1.1.2.2.2  bouyer  *
     88  1.1.1.2.2.2  bouyer  * PARAMETERS:  None.
     89  1.1.1.2.2.2  bouyer  *
     90  1.1.1.2.2.2  bouyer  * RETURN:      None
     91  1.1.1.2.2.2  bouyer  *
     92  1.1.1.2.2.2  bouyer  * DESCRIPTION: Generate AML code.  Currently generates the listing file
     93  1.1.1.2.2.2  bouyer  *              simultaneously.
     94  1.1.1.2.2.2  bouyer  *
     95  1.1.1.2.2.2  bouyer  ******************************************************************************/
     96  1.1.1.2.2.2  bouyer 
     97  1.1.1.2.2.2  bouyer void
     98  1.1.1.2.2.2  bouyer CgGenerateAmlOutput (
     99  1.1.1.2.2.2  bouyer     void)
    100  1.1.1.2.2.2  bouyer {
    101  1.1.1.2.2.2  bouyer 
    102  1.1.1.2.2.2  bouyer     DbgPrint (ASL_DEBUG_OUTPUT, "\nWriting AML\n\n");
    103  1.1.1.2.2.2  bouyer 
    104  1.1.1.2.2.2  bouyer     /* Generate the AML output file */
    105  1.1.1.2.2.2  bouyer 
    106  1.1.1.2.2.2  bouyer     FlSeekFile (ASL_FILE_SOURCE_OUTPUT, 0);
    107  1.1.1.2.2.2  bouyer     Gbl_SourceLine = 0;
    108  1.1.1.2.2.2  bouyer     Gbl_NextError = Gbl_ErrorLog;
    109  1.1.1.2.2.2  bouyer 
    110  1.1.1.2.2.2  bouyer     TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
    111  1.1.1.2.2.2  bouyer         CgAmlWriteWalk, NULL, NULL);
    112  1.1.1.2.2.2  bouyer     CgCloseTable ();
    113  1.1.1.2.2.2  bouyer }
    114  1.1.1.2.2.2  bouyer 
    115  1.1.1.2.2.2  bouyer 
    116  1.1.1.2.2.2  bouyer /*******************************************************************************
    117  1.1.1.2.2.2  bouyer  *
    118  1.1.1.2.2.2  bouyer  * FUNCTION:    CgAmlWriteWalk
    119  1.1.1.2.2.2  bouyer  *
    120  1.1.1.2.2.2  bouyer  * PARAMETERS:  ASL_WALK_CALLBACK
    121  1.1.1.2.2.2  bouyer  *
    122  1.1.1.2.2.2  bouyer  * RETURN:      Status
    123  1.1.1.2.2.2  bouyer  *
    124  1.1.1.2.2.2  bouyer  * DESCRIPTION: Parse tree walk to generate the AML code.
    125  1.1.1.2.2.2  bouyer  *
    126  1.1.1.2.2.2  bouyer  ******************************************************************************/
    127  1.1.1.2.2.2  bouyer 
    128  1.1.1.2.2.2  bouyer static ACPI_STATUS
    129  1.1.1.2.2.2  bouyer CgAmlWriteWalk (
    130  1.1.1.2.2.2  bouyer     ACPI_PARSE_OBJECT       *Op,
    131  1.1.1.2.2.2  bouyer     UINT32                  Level,
    132  1.1.1.2.2.2  bouyer     void                    *Context)
    133  1.1.1.2.2.2  bouyer {
    134  1.1.1.2.2.2  bouyer 
    135  1.1.1.2.2.2  bouyer     /*
    136  1.1.1.2.2.2  bouyer      * Print header at level 0. Alignment assumes 32-bit pointers
    137  1.1.1.2.2.2  bouyer      */
    138  1.1.1.2.2.2  bouyer     if (!Level)
    139  1.1.1.2.2.2  bouyer     {
    140  1.1.1.2.2.2  bouyer         DbgPrint (ASL_TREE_OUTPUT,
    141  1.1.1.2.2.2  bouyer             "Final parse tree used for AML output:\n");
    142  1.1.1.2.2.2  bouyer         DbgPrint (ASL_TREE_OUTPUT,
    143  1.1.1.2.2.2  bouyer             "%*s Value    P_Op A_Op OpLen PByts Len  SubLen PSubLen OpPtr    Child    Parent   Flags    AcTyp    Final Col L\n",
    144  1.1.1.2.2.2  bouyer             76, " ");
    145  1.1.1.2.2.2  bouyer     }
    146  1.1.1.2.2.2  bouyer 
    147  1.1.1.2.2.2  bouyer     /* Debug output */
    148  1.1.1.2.2.2  bouyer 
    149  1.1.1.2.2.2  bouyer     DbgPrint (ASL_TREE_OUTPUT,
    150  1.1.1.2.2.2  bouyer         "%5.5d [%2d]", Op->Asl.LogicalLineNumber, Level);
    151  1.1.1.2.2.2  bouyer     UtPrintFormattedName (Op->Asl.ParseOpcode, Level);
    152  1.1.1.2.2.2  bouyer 
    153  1.1.1.2.2.2  bouyer     if (Op->Asl.ParseOpcode == PARSEOP_NAMESEG    ||
    154  1.1.1.2.2.2  bouyer         Op->Asl.ParseOpcode == PARSEOP_NAMESTRING ||
    155  1.1.1.2.2.2  bouyer         Op->Asl.ParseOpcode == PARSEOP_METHODCALL)
    156  1.1.1.2.2.2  bouyer     {
    157  1.1.1.2.2.2  bouyer         DbgPrint (ASL_TREE_OUTPUT,
    158  1.1.1.2.2.2  bouyer             "%10.32s      ", Op->Asl.ExternalName);
    159  1.1.1.2.2.2  bouyer     }
    160  1.1.1.2.2.2  bouyer     else
    161  1.1.1.2.2.2  bouyer     {
    162  1.1.1.2.2.2  bouyer         DbgPrint (ASL_TREE_OUTPUT, "                ");
    163  1.1.1.2.2.2  bouyer     }
    164  1.1.1.2.2.2  bouyer 
    165  1.1.1.2.2.2  bouyer     DbgPrint (ASL_TREE_OUTPUT,
    166  1.1.1.2.2.2  bouyer     "%08X %04X %04X %01X     %04X  %04X %04X   %04X    %08X %08X %08X %08X %08X %04X  %02d  %02d\n",
    167  1.1.1.2.2.2  bouyer             /* 1  */ (UINT32) Op->Asl.Value.Integer,
    168  1.1.1.2.2.2  bouyer             /* 2  */ Op->Asl.ParseOpcode,
    169  1.1.1.2.2.2  bouyer             /* 3  */ Op->Asl.AmlOpcode,
    170  1.1.1.2.2.2  bouyer             /* 4  */ Op->Asl.AmlOpcodeLength,
    171  1.1.1.2.2.2  bouyer             /* 5  */ Op->Asl.AmlPkgLenBytes,
    172  1.1.1.2.2.2  bouyer             /* 6  */ Op->Asl.AmlLength,
    173  1.1.1.2.2.2  bouyer             /* 7  */ Op->Asl.AmlSubtreeLength,
    174  1.1.1.2.2.2  bouyer             /* 8  */ Op->Asl.Parent ? Op->Asl.Parent->Asl.AmlSubtreeLength : 0,
    175  1.1.1.2.2.2  bouyer             /* 9  */ Op,
    176  1.1.1.2.2.2  bouyer             /* 10 */ Op->Asl.Child,
    177  1.1.1.2.2.2  bouyer             /* 11 */ Op->Asl.Parent,
    178  1.1.1.2.2.2  bouyer             /* 12 */ Op->Asl.CompileFlags,
    179  1.1.1.2.2.2  bouyer             /* 13 */ Op->Asl.AcpiBtype,
    180  1.1.1.2.2.2  bouyer             /* 14 */ Op->Asl.FinalAmlLength,
    181  1.1.1.2.2.2  bouyer             /* 15 */ Op->Asl.Column,
    182  1.1.1.2.2.2  bouyer             /* 16 */ Op->Asl.LineNumber);
    183  1.1.1.2.2.2  bouyer 
    184  1.1.1.2.2.2  bouyer     /* Generate the AML for this node */
    185  1.1.1.2.2.2  bouyer 
    186  1.1.1.2.2.2  bouyer     CgWriteNode (Op);
    187  1.1.1.2.2.2  bouyer     return (AE_OK);
    188  1.1.1.2.2.2  bouyer }
    189  1.1.1.2.2.2  bouyer 
    190  1.1.1.2.2.2  bouyer 
    191  1.1.1.2.2.2  bouyer /*******************************************************************************
    192  1.1.1.2.2.2  bouyer  *
    193  1.1.1.2.2.2  bouyer  * FUNCTION:    CgLocalWriteAmlData
    194  1.1.1.2.2.2  bouyer  *
    195  1.1.1.2.2.2  bouyer  * PARAMETERS:  Op              - Current parse op
    196  1.1.1.2.2.2  bouyer  *              Buffer          - Buffer to write
    197  1.1.1.2.2.2  bouyer  *              Length          - Size of data in buffer
    198  1.1.1.2.2.2  bouyer  *
    199  1.1.1.2.2.2  bouyer  * RETURN:      None
    200  1.1.1.2.2.2  bouyer  *
    201  1.1.1.2.2.2  bouyer  * DESCRIPTION: Write a buffer of AML data to the AML output file.
    202  1.1.1.2.2.2  bouyer  *
    203  1.1.1.2.2.2  bouyer  ******************************************************************************/
    204  1.1.1.2.2.2  bouyer 
    205  1.1.1.2.2.2  bouyer static void
    206  1.1.1.2.2.2  bouyer CgLocalWriteAmlData (
    207  1.1.1.2.2.2  bouyer     ACPI_PARSE_OBJECT       *Op,
    208  1.1.1.2.2.2  bouyer     void                    *Buffer,
    209  1.1.1.2.2.2  bouyer     UINT32                  Length)
    210  1.1.1.2.2.2  bouyer {
    211  1.1.1.2.2.2  bouyer 
    212  1.1.1.2.2.2  bouyer     /* Write the raw data to the AML file */
    213  1.1.1.2.2.2  bouyer 
    214  1.1.1.2.2.2  bouyer     FlWriteFile (ASL_FILE_AML_OUTPUT, Buffer, Length);
    215  1.1.1.2.2.2  bouyer 
    216  1.1.1.2.2.2  bouyer     /* Update the final AML length for this node (used for listings) */
    217  1.1.1.2.2.2  bouyer 
    218  1.1.1.2.2.2  bouyer     if (Op)
    219  1.1.1.2.2.2  bouyer     {
    220  1.1.1.2.2.2  bouyer         Op->Asl.FinalAmlLength += Length;
    221  1.1.1.2.2.2  bouyer     }
    222  1.1.1.2.2.2  bouyer }
    223  1.1.1.2.2.2  bouyer 
    224  1.1.1.2.2.2  bouyer 
    225  1.1.1.2.2.2  bouyer /*******************************************************************************
    226  1.1.1.2.2.2  bouyer  *
    227  1.1.1.2.2.2  bouyer  * FUNCTION:    CgWriteAmlOpcode
    228  1.1.1.2.2.2  bouyer  *
    229  1.1.1.2.2.2  bouyer  * PARAMETERS:  Op            - Parse node with an AML opcode
    230  1.1.1.2.2.2  bouyer  *
    231  1.1.1.2.2.2  bouyer  * RETURN:      None.
    232  1.1.1.2.2.2  bouyer  *
    233  1.1.1.2.2.2  bouyer  * DESCRIPTION: Write the AML opcode corresponding to a parse node.
    234  1.1.1.2.2.2  bouyer  *
    235  1.1.1.2.2.2  bouyer  ******************************************************************************/
    236  1.1.1.2.2.2  bouyer 
    237  1.1.1.2.2.2  bouyer static void
    238  1.1.1.2.2.2  bouyer CgWriteAmlOpcode (
    239  1.1.1.2.2.2  bouyer     ACPI_PARSE_OBJECT       *Op)
    240  1.1.1.2.2.2  bouyer {
    241  1.1.1.2.2.2  bouyer     UINT8                   PkgLenFirstByte;
    242  1.1.1.2.2.2  bouyer     UINT32                  i;
    243  1.1.1.2.2.2  bouyer     union {
    244  1.1.1.2.2.2  bouyer         UINT16                  Opcode;
    245  1.1.1.2.2.2  bouyer         UINT8                   OpcodeBytes[2];
    246  1.1.1.2.2.2  bouyer     } Aml;
    247  1.1.1.2.2.2  bouyer     union {
    248  1.1.1.2.2.2  bouyer         UINT32                  Len;
    249  1.1.1.2.2.2  bouyer         UINT8                   LenBytes[4];
    250  1.1.1.2.2.2  bouyer     } PkgLen;
    251  1.1.1.2.2.2  bouyer 
    252  1.1.1.2.2.2  bouyer 
    253  1.1.1.2.2.2  bouyer     /* We expect some DEFAULT_ARGs, just ignore them */
    254  1.1.1.2.2.2  bouyer 
    255  1.1.1.2.2.2  bouyer     if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
    256  1.1.1.2.2.2  bouyer     {
    257  1.1.1.2.2.2  bouyer         return;
    258  1.1.1.2.2.2  bouyer     }
    259  1.1.1.2.2.2  bouyer 
    260  1.1.1.2.2.2  bouyer     switch (Op->Asl.AmlOpcode)
    261  1.1.1.2.2.2  bouyer     {
    262  1.1.1.2.2.2  bouyer     case AML_UNASSIGNED_OPCODE:
    263  1.1.1.2.2.2  bouyer 
    264  1.1.1.2.2.2  bouyer         /* These opcodes should not get here */
    265  1.1.1.2.2.2  bouyer 
    266  1.1.1.2.2.2  bouyer         printf ("Found a node with an unassigned AML opcode\n");
    267  1.1.1.2.2.2  bouyer         fprintf (stderr, "Found a node with an unassigned AML opcode\n");
    268  1.1.1.2.2.2  bouyer         return;
    269  1.1.1.2.2.2  bouyer 
    270  1.1.1.2.2.2  bouyer     case AML_INT_RESERVEDFIELD_OP:
    271  1.1.1.2.2.2  bouyer 
    272  1.1.1.2.2.2  bouyer         /* Special opcodes for within a field definition */
    273  1.1.1.2.2.2  bouyer 
    274  1.1.1.2.2.2  bouyer         Aml.Opcode = 0x00;
    275  1.1.1.2.2.2  bouyer         break;
    276  1.1.1.2.2.2  bouyer 
    277  1.1.1.2.2.2  bouyer     case AML_INT_ACCESSFIELD_OP:
    278  1.1.1.2.2.2  bouyer 
    279  1.1.1.2.2.2  bouyer         Aml.Opcode = 0x01;
    280  1.1.1.2.2.2  bouyer         break;
    281  1.1.1.2.2.2  bouyer 
    282  1.1.1.2.2.2  bouyer     default:
    283  1.1.1.2.2.2  bouyer         Aml.Opcode = Op->Asl.AmlOpcode;
    284  1.1.1.2.2.2  bouyer         break;
    285  1.1.1.2.2.2  bouyer     }
    286  1.1.1.2.2.2  bouyer 
    287  1.1.1.2.2.2  bouyer 
    288  1.1.1.2.2.2  bouyer     switch (Aml.Opcode)
    289  1.1.1.2.2.2  bouyer     {
    290  1.1.1.2.2.2  bouyer     case AML_PACKAGE_LENGTH:
    291  1.1.1.2.2.2  bouyer 
    292  1.1.1.2.2.2  bouyer         /* Value is the length to be encoded (Used in field definitions) */
    293  1.1.1.2.2.2  bouyer 
    294  1.1.1.2.2.2  bouyer         PkgLen.Len = (UINT32) Op->Asl.Value.Integer;
    295  1.1.1.2.2.2  bouyer         break;
    296  1.1.1.2.2.2  bouyer 
    297  1.1.1.2.2.2  bouyer     default:
    298  1.1.1.2.2.2  bouyer 
    299  1.1.1.2.2.2  bouyer         /* Check for two-byte opcode */
    300  1.1.1.2.2.2  bouyer 
    301  1.1.1.2.2.2  bouyer         if (Aml.Opcode > 0x00FF)
    302  1.1.1.2.2.2  bouyer         {
    303  1.1.1.2.2.2  bouyer             /* Write the high byte first */
    304  1.1.1.2.2.2  bouyer 
    305  1.1.1.2.2.2  bouyer             CgLocalWriteAmlData (Op, &Aml.OpcodeBytes[1], 1);
    306  1.1.1.2.2.2  bouyer         }
    307  1.1.1.2.2.2  bouyer 
    308  1.1.1.2.2.2  bouyer         CgLocalWriteAmlData (Op, &Aml.OpcodeBytes[0], 1);
    309  1.1.1.2.2.2  bouyer 
    310  1.1.1.2.2.2  bouyer         /* Subtreelength doesn't include length of package length bytes */
    311  1.1.1.2.2.2  bouyer 
    312  1.1.1.2.2.2  bouyer         PkgLen.Len = Op->Asl.AmlSubtreeLength + Op->Asl.AmlPkgLenBytes;
    313  1.1.1.2.2.2  bouyer         break;
    314  1.1.1.2.2.2  bouyer     }
    315  1.1.1.2.2.2  bouyer 
    316  1.1.1.2.2.2  bouyer     /* Does this opcode have an associated "PackageLength" field? */
    317  1.1.1.2.2.2  bouyer 
    318  1.1.1.2.2.2  bouyer     if (Op->Asl.CompileFlags & NODE_AML_PACKAGE)
    319  1.1.1.2.2.2  bouyer     {
    320  1.1.1.2.2.2  bouyer         if (Op->Asl.AmlPkgLenBytes == 1)
    321  1.1.1.2.2.2  bouyer         {
    322  1.1.1.2.2.2  bouyer             /* Simplest case -- no bytes to follow, just write the count */
    323  1.1.1.2.2.2  bouyer 
    324  1.1.1.2.2.2  bouyer             CgLocalWriteAmlData (Op, &PkgLen.LenBytes[0], 1);
    325  1.1.1.2.2.2  bouyer         }
    326  1.1.1.2.2.2  bouyer         else if (Op->Asl.AmlPkgLenBytes != 0)
    327  1.1.1.2.2.2  bouyer         {
    328  1.1.1.2.2.2  bouyer             /*
    329  1.1.1.2.2.2  bouyer              * Encode the "bytes to follow" in the first byte, top two bits.
    330  1.1.1.2.2.2  bouyer              * The low-order nybble of the length is in the bottom 4 bits
    331  1.1.1.2.2.2  bouyer              */
    332  1.1.1.2.2.2  bouyer             PkgLenFirstByte = (UINT8)
    333  1.1.1.2.2.2  bouyer                 (((UINT32) (Op->Asl.AmlPkgLenBytes - 1) << 6) |
    334  1.1.1.2.2.2  bouyer                 (PkgLen.LenBytes[0] & 0x0F));
    335  1.1.1.2.2.2  bouyer 
    336  1.1.1.2.2.2  bouyer             CgLocalWriteAmlData (Op, &PkgLenFirstByte, 1);
    337  1.1.1.2.2.2  bouyer 
    338  1.1.1.2.2.2  bouyer             /*
    339  1.1.1.2.2.2  bouyer              * Shift the length over by the 4 bits we just stuffed
    340  1.1.1.2.2.2  bouyer              * in the first byte
    341  1.1.1.2.2.2  bouyer              */
    342  1.1.1.2.2.2  bouyer             PkgLen.Len >>= 4;
    343  1.1.1.2.2.2  bouyer 
    344  1.1.1.2.2.2  bouyer             /* Now we can write the remaining bytes - either 1, 2, or 3 bytes */
    345  1.1.1.2.2.2  bouyer 
    346  1.1.1.2.2.2  bouyer             for (i = 0; i < (UINT32) (Op->Asl.AmlPkgLenBytes - 1); i++)
    347  1.1.1.2.2.2  bouyer             {
    348  1.1.1.2.2.2  bouyer                 CgLocalWriteAmlData (Op, &PkgLen.LenBytes[i], 1);
    349  1.1.1.2.2.2  bouyer             }
    350  1.1.1.2.2.2  bouyer         }
    351  1.1.1.2.2.2  bouyer     }
    352  1.1.1.2.2.2  bouyer 
    353  1.1.1.2.2.2  bouyer     switch (Aml.Opcode)
    354  1.1.1.2.2.2  bouyer     {
    355  1.1.1.2.2.2  bouyer     case AML_BYTE_OP:
    356  1.1.1.2.2.2  bouyer 
    357  1.1.1.2.2.2  bouyer         CgLocalWriteAmlData (Op, &Op->Asl.Value.Integer, 1);
    358  1.1.1.2.2.2  bouyer         break;
    359  1.1.1.2.2.2  bouyer 
    360  1.1.1.2.2.2  bouyer     case AML_WORD_OP:
    361  1.1.1.2.2.2  bouyer 
    362  1.1.1.2.2.2  bouyer         CgLocalWriteAmlData (Op, &Op->Asl.Value.Integer, 2);
    363  1.1.1.2.2.2  bouyer        break;
    364  1.1.1.2.2.2  bouyer 
    365  1.1.1.2.2.2  bouyer     case AML_DWORD_OP:
    366  1.1.1.2.2.2  bouyer 
    367  1.1.1.2.2.2  bouyer         CgLocalWriteAmlData (Op, &Op->Asl.Value.Integer, 4);
    368  1.1.1.2.2.2  bouyer         break;
    369  1.1.1.2.2.2  bouyer 
    370  1.1.1.2.2.2  bouyer     case AML_QWORD_OP:
    371  1.1.1.2.2.2  bouyer 
    372  1.1.1.2.2.2  bouyer         CgLocalWriteAmlData (Op, &Op->Asl.Value.Integer, 8);
    373  1.1.1.2.2.2  bouyer         break;
    374  1.1.1.2.2.2  bouyer 
    375  1.1.1.2.2.2  bouyer     case AML_STRING_OP:
    376  1.1.1.2.2.2  bouyer 
    377  1.1.1.2.2.2  bouyer         CgLocalWriteAmlData (Op, Op->Asl.Value.String, Op->Asl.AmlLength);
    378  1.1.1.2.2.2  bouyer         break;
    379  1.1.1.2.2.2  bouyer 
    380  1.1.1.2.2.2  bouyer     default:
    381  1.1.1.2.2.2  bouyer         /* All data opcodes must appear above */
    382  1.1.1.2.2.2  bouyer         break;
    383  1.1.1.2.2.2  bouyer     }
    384  1.1.1.2.2.2  bouyer }
    385  1.1.1.2.2.2  bouyer 
    386  1.1.1.2.2.2  bouyer 
    387  1.1.1.2.2.2  bouyer /*******************************************************************************
    388  1.1.1.2.2.2  bouyer  *
    389  1.1.1.2.2.2  bouyer  * FUNCTION:    CgWriteTableHeader
    390  1.1.1.2.2.2  bouyer  *
    391  1.1.1.2.2.2  bouyer  * PARAMETERS:  Op        - The DEFINITIONBLOCK node
    392  1.1.1.2.2.2  bouyer  *
    393  1.1.1.2.2.2  bouyer  * RETURN:      None
    394  1.1.1.2.2.2  bouyer  *
    395  1.1.1.2.2.2  bouyer  * DESCRIPTION: Write a table header corresponding to the DEFINITIONBLOCK
    396  1.1.1.2.2.2  bouyer  *
    397  1.1.1.2.2.2  bouyer  ******************************************************************************/
    398  1.1.1.2.2.2  bouyer 
    399  1.1.1.2.2.2  bouyer static void
    400  1.1.1.2.2.2  bouyer CgWriteTableHeader (
    401  1.1.1.2.2.2  bouyer     ACPI_PARSE_OBJECT       *Op)
    402  1.1.1.2.2.2  bouyer {
    403  1.1.1.2.2.2  bouyer     ACPI_PARSE_OBJECT       *Child;
    404  1.1.1.2.2.2  bouyer 
    405  1.1.1.2.2.2  bouyer 
    406  1.1.1.2.2.2  bouyer     /* AML filename */
    407  1.1.1.2.2.2  bouyer 
    408  1.1.1.2.2.2  bouyer     Child = Op->Asl.Child;
    409  1.1.1.2.2.2  bouyer 
    410  1.1.1.2.2.2  bouyer     /* Signature */
    411  1.1.1.2.2.2  bouyer 
    412  1.1.1.2.2.2  bouyer     Child = Child->Asl.Next;
    413  1.1.1.2.2.2  bouyer     strncpy (TableHeader.Signature, Child->Asl.Value.String, 4);
    414  1.1.1.2.2.2  bouyer 
    415  1.1.1.2.2.2  bouyer     /* Revision */
    416  1.1.1.2.2.2  bouyer 
    417  1.1.1.2.2.2  bouyer     Child = Child->Asl.Next;
    418  1.1.1.2.2.2  bouyer     TableHeader.Revision = (UINT8) Child->Asl.Value.Integer;
    419  1.1.1.2.2.2  bouyer 
    420  1.1.1.2.2.2  bouyer     /* Command-line Revision override */
    421  1.1.1.2.2.2  bouyer 
    422  1.1.1.2.2.2  bouyer     if (Gbl_RevisionOverride)
    423  1.1.1.2.2.2  bouyer     {
    424  1.1.1.2.2.2  bouyer         TableHeader.Revision = Gbl_RevisionOverride;
    425  1.1.1.2.2.2  bouyer     }
    426  1.1.1.2.2.2  bouyer 
    427  1.1.1.2.2.2  bouyer     /* OEMID */
    428  1.1.1.2.2.2  bouyer 
    429  1.1.1.2.2.2  bouyer     Child = Child->Asl.Next;
    430  1.1.1.2.2.2  bouyer     strncpy (TableHeader.OemId, Child->Asl.Value.String, 6);
    431  1.1.1.2.2.2  bouyer 
    432  1.1.1.2.2.2  bouyer     /* OEM TableID */
    433  1.1.1.2.2.2  bouyer 
    434  1.1.1.2.2.2  bouyer     Child = Child->Asl.Next;
    435  1.1.1.2.2.2  bouyer     strncpy (TableHeader.OemTableId, Child->Asl.Value.String, 8);
    436  1.1.1.2.2.2  bouyer 
    437  1.1.1.2.2.2  bouyer     /* OEM Revision */
    438  1.1.1.2.2.2  bouyer 
    439  1.1.1.2.2.2  bouyer     Child = Child->Asl.Next;
    440  1.1.1.2.2.2  bouyer     TableHeader.OemRevision = (UINT32) Child->Asl.Value.Integer;
    441  1.1.1.2.2.2  bouyer 
    442  1.1.1.2.2.2  bouyer     /* Compiler ID */
    443  1.1.1.2.2.2  bouyer 
    444  1.1.1.2.2.2  bouyer     strncpy (TableHeader.AslCompilerId, ASL_CREATOR_ID, 4);
    445  1.1.1.2.2.2  bouyer 
    446  1.1.1.2.2.2  bouyer     /* Compiler version */
    447  1.1.1.2.2.2  bouyer 
    448  1.1.1.2.2.2  bouyer     TableHeader.AslCompilerRevision = ASL_REVISION;
    449  1.1.1.2.2.2  bouyer 
    450  1.1.1.2.2.2  bouyer     /* Table length. Checksum zero for now, will rewrite later */
    451  1.1.1.2.2.2  bouyer 
    452  1.1.1.2.2.2  bouyer     TableHeader.Length   = Gbl_TableLength;
    453  1.1.1.2.2.2  bouyer     TableHeader.Checksum = 0;
    454  1.1.1.2.2.2  bouyer 
    455  1.1.1.2.2.2  bouyer     CgLocalWriteAmlData (Op, &TableHeader, sizeof (ACPI_TABLE_HEADER));
    456  1.1.1.2.2.2  bouyer }
    457  1.1.1.2.2.2  bouyer 
    458  1.1.1.2.2.2  bouyer 
    459  1.1.1.2.2.2  bouyer /*******************************************************************************
    460  1.1.1.2.2.2  bouyer  *
    461  1.1.1.2.2.2  bouyer  * FUNCTION:    CgCloseTable
    462  1.1.1.2.2.2  bouyer  *
    463  1.1.1.2.2.2  bouyer  * PARAMETERS:  None.
    464  1.1.1.2.2.2  bouyer  *
    465  1.1.1.2.2.2  bouyer  * RETURN:      None.
    466  1.1.1.2.2.2  bouyer  *
    467  1.1.1.2.2.2  bouyer  * DESCRIPTION: Complete the ACPI table by calculating the checksum and
    468  1.1.1.2.2.2  bouyer  *              re-writing the header.
    469  1.1.1.2.2.2  bouyer  *
    470  1.1.1.2.2.2  bouyer  ******************************************************************************/
    471  1.1.1.2.2.2  bouyer 
    472  1.1.1.2.2.2  bouyer static void
    473  1.1.1.2.2.2  bouyer CgCloseTable (
    474  1.1.1.2.2.2  bouyer     void)
    475  1.1.1.2.2.2  bouyer {
    476  1.1.1.2.2.2  bouyer     signed char         Sum;
    477  1.1.1.2.2.2  bouyer     UINT8               FileByte;
    478  1.1.1.2.2.2  bouyer 
    479  1.1.1.2.2.2  bouyer 
    480  1.1.1.2.2.2  bouyer     FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
    481  1.1.1.2.2.2  bouyer     Sum = 0;
    482  1.1.1.2.2.2  bouyer 
    483  1.1.1.2.2.2  bouyer     /* Calculate the checksum over the entire file */
    484  1.1.1.2.2.2  bouyer 
    485  1.1.1.2.2.2  bouyer     while (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte, 1) == AE_OK)
    486  1.1.1.2.2.2  bouyer     {
    487  1.1.1.2.2.2  bouyer         Sum = (signed char) (Sum + FileByte);
    488  1.1.1.2.2.2  bouyer     }
    489  1.1.1.2.2.2  bouyer 
    490  1.1.1.2.2.2  bouyer     /* Re-write the table header with the checksum */
    491  1.1.1.2.2.2  bouyer 
    492  1.1.1.2.2.2  bouyer     TableHeader.Checksum = (UINT8) (0 - Sum);
    493  1.1.1.2.2.2  bouyer 
    494  1.1.1.2.2.2  bouyer     FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
    495  1.1.1.2.2.2  bouyer     CgLocalWriteAmlData (NULL, &TableHeader, sizeof (ACPI_TABLE_HEADER));
    496  1.1.1.2.2.2  bouyer }
    497  1.1.1.2.2.2  bouyer 
    498  1.1.1.2.2.2  bouyer 
    499  1.1.1.2.2.2  bouyer /*******************************************************************************
    500  1.1.1.2.2.2  bouyer  *
    501  1.1.1.2.2.2  bouyer  * FUNCTION:    CgWriteNode
    502  1.1.1.2.2.2  bouyer  *
    503  1.1.1.2.2.2  bouyer  * PARAMETERS:  Op            - Parse node to write.
    504  1.1.1.2.2.2  bouyer  *
    505  1.1.1.2.2.2  bouyer  * RETURN:      None.
    506  1.1.1.2.2.2  bouyer  *
    507  1.1.1.2.2.2  bouyer  * DESCRIPTION: Write the AML that corresponds to a parse node.
    508  1.1.1.2.2.2  bouyer  *
    509  1.1.1.2.2.2  bouyer  ******************************************************************************/
    510  1.1.1.2.2.2  bouyer 
    511  1.1.1.2.2.2  bouyer static void
    512  1.1.1.2.2.2  bouyer CgWriteNode (
    513  1.1.1.2.2.2  bouyer     ACPI_PARSE_OBJECT       *Op)
    514  1.1.1.2.2.2  bouyer {
    515  1.1.1.2.2.2  bouyer     ASL_RESOURCE_NODE       *Rnode;
    516  1.1.1.2.2.2  bouyer 
    517  1.1.1.2.2.2  bouyer 
    518  1.1.1.2.2.2  bouyer     /* Always check for DEFAULT_ARG and other "Noop" nodes */
    519  1.1.1.2.2.2  bouyer     /* TBD: this may not be the best place for this check */
    520  1.1.1.2.2.2  bouyer 
    521  1.1.1.2.2.2  bouyer     if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)  ||
    522  1.1.1.2.2.2  bouyer         (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL)     ||
    523  1.1.1.2.2.2  bouyer         (Op->Asl.ParseOpcode == PARSEOP_INCLUDE)      ||
    524  1.1.1.2.2.2  bouyer         (Op->Asl.ParseOpcode == PARSEOP_INCLUDE_END))
    525  1.1.1.2.2.2  bouyer     {
    526  1.1.1.2.2.2  bouyer         return;
    527  1.1.1.2.2.2  bouyer     }
    528  1.1.1.2.2.2  bouyer 
    529  1.1.1.2.2.2  bouyer     Op->Asl.FinalAmlLength = 0;
    530  1.1.1.2.2.2  bouyer 
    531  1.1.1.2.2.2  bouyer     switch (Op->Asl.AmlOpcode)
    532  1.1.1.2.2.2  bouyer     {
    533  1.1.1.2.2.2  bouyer     case AML_RAW_DATA_BYTE:
    534  1.1.1.2.2.2  bouyer     case AML_RAW_DATA_WORD:
    535  1.1.1.2.2.2  bouyer     case AML_RAW_DATA_DWORD:
    536  1.1.1.2.2.2  bouyer     case AML_RAW_DATA_QWORD:
    537  1.1.1.2.2.2  bouyer 
    538  1.1.1.2.2.2  bouyer         CgLocalWriteAmlData (Op, &Op->Asl.Value.Integer, Op->Asl.AmlLength);
    539  1.1.1.2.2.2  bouyer         return;
    540  1.1.1.2.2.2  bouyer 
    541  1.1.1.2.2.2  bouyer 
    542  1.1.1.2.2.2  bouyer     case AML_RAW_DATA_BUFFER:
    543  1.1.1.2.2.2  bouyer 
    544  1.1.1.2.2.2  bouyer         CgLocalWriteAmlData (Op, Op->Asl.Value.Buffer, Op->Asl.AmlLength);
    545  1.1.1.2.2.2  bouyer         return;
    546  1.1.1.2.2.2  bouyer 
    547  1.1.1.2.2.2  bouyer 
    548  1.1.1.2.2.2  bouyer     case AML_RAW_DATA_CHAIN:
    549  1.1.1.2.2.2  bouyer 
    550  1.1.1.2.2.2  bouyer         Rnode = ACPI_CAST_PTR (ASL_RESOURCE_NODE, Op->Asl.Value.Buffer);
    551  1.1.1.2.2.2  bouyer         while (Rnode)
    552  1.1.1.2.2.2  bouyer         {
    553  1.1.1.2.2.2  bouyer             CgLocalWriteAmlData (Op, Rnode->Buffer, Rnode->BufferLength);
    554  1.1.1.2.2.2  bouyer             Rnode = Rnode->Next;
    555  1.1.1.2.2.2  bouyer         }
    556  1.1.1.2.2.2  bouyer         return;
    557  1.1.1.2.2.2  bouyer 
    558  1.1.1.2.2.2  bouyer     default:
    559  1.1.1.2.2.2  bouyer         /* Internal data opcodes must all appear above */
    560  1.1.1.2.2.2  bouyer         break;
    561  1.1.1.2.2.2  bouyer     }
    562  1.1.1.2.2.2  bouyer 
    563  1.1.1.2.2.2  bouyer     switch (Op->Asl.ParseOpcode)
    564  1.1.1.2.2.2  bouyer     {
    565  1.1.1.2.2.2  bouyer     case PARSEOP_DEFAULT_ARG:
    566  1.1.1.2.2.2  bouyer 
    567  1.1.1.2.2.2  bouyer         break;
    568  1.1.1.2.2.2  bouyer 
    569  1.1.1.2.2.2  bouyer     case PARSEOP_DEFINITIONBLOCK:
    570  1.1.1.2.2.2  bouyer 
    571  1.1.1.2.2.2  bouyer         CgWriteTableHeader (Op);
    572  1.1.1.2.2.2  bouyer         break;
    573  1.1.1.2.2.2  bouyer 
    574  1.1.1.2.2.2  bouyer     case PARSEOP_NAMESEG:
    575  1.1.1.2.2.2  bouyer     case PARSEOP_NAMESTRING:
    576  1.1.1.2.2.2  bouyer     case PARSEOP_METHODCALL:
    577  1.1.1.2.2.2  bouyer 
    578  1.1.1.2.2.2  bouyer         CgLocalWriteAmlData (Op, Op->Asl.Value.String, Op->Asl.AmlLength);
    579  1.1.1.2.2.2  bouyer         break;
    580  1.1.1.2.2.2  bouyer 
    581  1.1.1.2.2.2  bouyer     default:
    582  1.1.1.2.2.2  bouyer 
    583  1.1.1.2.2.2  bouyer         CgWriteAmlOpcode (Op);
    584  1.1.1.2.2.2  bouyer         break;
    585  1.1.1.2.2.2  bouyer     }
    586  1.1.1.2.2.2  bouyer }
    587  1.1.1.2.2.2  bouyer 
    588  1.1.1.2.2.2  bouyer 
    589