Subversion Repositories Kolibri OS

Rev

Rev 1498 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2. /******************************************************************************
  3.  *
  4.  * Module Name: aslopcode - AML opcode generation
  5.  *
  6.  *****************************************************************************/
  7.  
  8. /******************************************************************************
  9.  *
  10.  * 1. Copyright Notice
  11.  *
  12.  * Some or all of this work - Copyright (c) 1999 - 2011, 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.  
  122. #define _COMPONENT          ACPI_COMPILER
  123.         ACPI_MODULE_NAME    ("aslopcodes")
  124.  
  125.  
  126. /* Local prototypes */
  127.  
  128. static void
  129. OpcDoAccessAs (
  130.     ACPI_PARSE_OBJECT       *Op);
  131.  
  132. static void
  133. OpcDoUnicode (
  134.     ACPI_PARSE_OBJECT       *Op);
  135.  
  136. static void
  137. OpcDoEisaId (
  138.     ACPI_PARSE_OBJECT       *Op);
  139.  
  140. static void
  141. OpcDoUuId (
  142.     ACPI_PARSE_OBJECT       *Op);
  143.  
  144.  
  145. /*******************************************************************************
  146.  *
  147.  * FUNCTION:    OpcAmlOpcodeUpdateWalk
  148.  *
  149.  * PARAMETERS:  ASL_WALK_CALLBACK
  150.  *
  151.  * RETURN:      Status
  152.  *
  153.  * DESCRIPTION: Opcode update walk, ascending callback
  154.  *
  155.  ******************************************************************************/
  156.  
  157. ACPI_STATUS
  158. OpcAmlOpcodeUpdateWalk (
  159.     ACPI_PARSE_OBJECT       *Op,
  160.     UINT32                  Level,
  161.     void                    *Context)
  162. {
  163.  
  164.     /*
  165.      * Handle the Package() case where the actual opcode cannot be determined
  166.      * until the PackageLength operand has been folded and minimized.
  167.      * (PackageOp versus VarPackageOp)
  168.      *
  169.      * This is (as of ACPI 3.0) the only case where the AML opcode can change
  170.      * based upon the value of a parameter.
  171.      *
  172.      * The parser always inserts a VarPackage opcode, which can possibly be
  173.      * optimized to a Package opcode.
  174.      */
  175.     if (Op->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE)
  176.     {
  177.         OpnDoPackage (Op);
  178.     }
  179.  
  180.     return (AE_OK);
  181. }
  182.  
  183.  
  184. /*******************************************************************************
  185.  *
  186.  * FUNCTION:    OpcAmlOpcodeWalk
  187.  *
  188.  * PARAMETERS:  ASL_WALK_CALLBACK
  189.  *
  190.  * RETURN:      Status
  191.  *
  192.  * DESCRIPTION: Parse tree walk to generate both the AML opcodes and the AML
  193.  *              operands.
  194.  *
  195.  ******************************************************************************/
  196.  
  197. ACPI_STATUS
  198. OpcAmlOpcodeWalk (
  199.     ACPI_PARSE_OBJECT       *Op,
  200.     UINT32                  Level,
  201.     void                    *Context)
  202. {
  203.  
  204.     TotalParseNodes++;
  205.  
  206.     OpcGenerateAmlOpcode (Op);
  207.     OpnGenerateAmlOperands (Op);
  208.     return (AE_OK);
  209. }
  210.  
  211.  
  212. /*******************************************************************************
  213.  *
  214.  * FUNCTION:    OpcGetIntegerWidth
  215.  *
  216.  * PARAMETERS:  Op          - DEFINITION BLOCK op
  217.  *
  218.  * RETURN:      none
  219.  *
  220.  * DESCRIPTION: Extract integer width from the table revision
  221.  *
  222.  ******************************************************************************/
  223.  
  224. void
  225. OpcGetIntegerWidth (
  226.     ACPI_PARSE_OBJECT       *Op)
  227. {
  228.     ACPI_PARSE_OBJECT       *Child;
  229.  
  230.  
  231.     if (!Op)
  232.     {
  233.         return;
  234.     }
  235.  
  236.     if (Gbl_RevisionOverride)
  237.     {
  238.         AcpiUtSetIntegerWidth (Gbl_RevisionOverride);
  239.     }
  240.     else
  241.     {
  242.         Child = Op->Asl.Child;
  243.         Child = Child->Asl.Next;
  244.         Child = Child->Asl.Next;
  245.  
  246.         /* Use the revision to set the integer width */
  247.  
  248.         AcpiUtSetIntegerWidth ((UINT8) Child->Asl.Value.Integer);
  249.     }
  250. }
  251.  
  252.  
  253. /*******************************************************************************
  254.  *
  255.  * FUNCTION:    OpcSetOptimalIntegerSize
  256.  *
  257.  * PARAMETERS:  Op        - A parse tree node
  258.  *
  259.  * RETURN:      Integer width, in bytes.  Also sets the node AML opcode to the
  260.  *              optimal integer AML prefix opcode.
  261.  *
  262.  * DESCRIPTION: Determine the optimal AML encoding of an integer.  All leading
  263.  *              zeros can be truncated to squeeze the integer into the
  264.  *              minimal number of AML bytes.
  265.  *
  266.  ******************************************************************************/
  267.  
  268. UINT32
  269. OpcSetOptimalIntegerSize (
  270.     ACPI_PARSE_OBJECT       *Op)
  271. {
  272.  
  273. #if 0
  274.     /*
  275.      * TBD: - we don't want to optimize integers in the block header, but the
  276.      * code below does not work correctly.
  277.      */
  278.     if (Op->Asl.Parent &&
  279.         Op->Asl.Parent->Asl.Parent &&
  280.        (Op->Asl.Parent->Asl.Parent->Asl.ParseOpcode == PARSEOP_DEFINITIONBLOCK))
  281.     {
  282.         return 0;
  283.     }
  284. #endif
  285.  
  286.     /*
  287.      * Check for the special AML integers first - Zero, One, Ones.
  288.      * These are single-byte opcodes that are the smallest possible
  289.      * representation of an integer.
  290.      *
  291.      * This optimization is optional.
  292.      */
  293.     if (Gbl_IntegerOptimizationFlag)
  294.     {
  295.         switch (Op->Asl.Value.Integer)
  296.         {
  297.         case 0:
  298.  
  299.             Op->Asl.AmlOpcode = AML_ZERO_OP;
  300.             AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
  301.                 Op, "Zero");
  302.             return 1;
  303.  
  304.         case 1:
  305.  
  306.             Op->Asl.AmlOpcode = AML_ONE_OP;
  307.             AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
  308.                 Op, "One");
  309.             return 1;
  310.  
  311.         case ACPI_UINT32_MAX:
  312.  
  313.             /* Check for table integer width (32 or 64) */
  314.  
  315.             if (AcpiGbl_IntegerByteWidth == 4)
  316.             {
  317.                 Op->Asl.AmlOpcode = AML_ONES_OP;
  318.                 AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
  319.                     Op, "Ones");
  320.                 return 1;
  321.             }
  322.             break;
  323.  
  324.         case ACPI_UINT64_MAX:
  325.  
  326.             /* Check for table integer width (32 or 64) */
  327.  
  328.             if (AcpiGbl_IntegerByteWidth == 8)
  329.             {
  330.                 Op->Asl.AmlOpcode = AML_ONES_OP;
  331.                 AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
  332.                     Op, "Ones");
  333.                 return 1;
  334.             }
  335.             break;
  336.  
  337.         default:
  338.             break;
  339.         }
  340.     }
  341.  
  342.     /* Find the best fit using the various AML integer prefixes */
  343.  
  344.     if (Op->Asl.Value.Integer <= ACPI_UINT8_MAX)
  345.     {
  346.         Op->Asl.AmlOpcode = AML_BYTE_OP;
  347.         return 1;
  348.     }
  349.     if (Op->Asl.Value.Integer <= ACPI_UINT16_MAX)
  350.     {
  351.         Op->Asl.AmlOpcode = AML_WORD_OP;
  352.         return 2;
  353.     }
  354.     if (Op->Asl.Value.Integer <= ACPI_UINT32_MAX)
  355.     {
  356.         Op->Asl.AmlOpcode = AML_DWORD_OP;
  357.         return 4;
  358.     }
  359.     else
  360.     {
  361.         if (AcpiGbl_IntegerByteWidth == 4)
  362.         {
  363.             AslError (ASL_WARNING, ASL_MSG_INTEGER_LENGTH,
  364.                 Op, NULL);
  365.  
  366.             if (!Gbl_IgnoreErrors)
  367.             {
  368.                 /* Truncate the integer to 32-bit */
  369.                 Op->Asl.AmlOpcode = AML_DWORD_OP;
  370.                 return 4;
  371.             }
  372.         }
  373.  
  374.         Op->Asl.AmlOpcode = AML_QWORD_OP;
  375.         return 8;
  376.     }
  377. }
  378.  
  379.  
  380. /*******************************************************************************
  381.  *
  382.  * FUNCTION:    OpcDoAccessAs
  383.  *
  384.  * PARAMETERS:  Op        - Parse node
  385.  *
  386.  * RETURN:      None
  387.  *
  388.  * DESCRIPTION: Implement the ACCESS_AS ASL keyword.
  389.  *
  390.  ******************************************************************************/
  391.  
  392. static void
  393. OpcDoAccessAs (
  394.     ACPI_PARSE_OBJECT       *Op)
  395. {
  396.     ACPI_PARSE_OBJECT       *Next;
  397.  
  398.  
  399.     Op->Asl.AmlOpcodeLength = 1;
  400.     Next = Op->Asl.Child;
  401.  
  402.     /* First child is the access type */
  403.  
  404.     Next->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
  405.     Next->Asl.ParseOpcode = PARSEOP_RAW_DATA;
  406.  
  407.     /* Second child is the optional access attribute */
  408.  
  409.     Next = Next->Asl.Next;
  410.     if (Next->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
  411.     {
  412.         Next->Asl.Value.Integer = 0;
  413.     }
  414.     Next->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
  415.     Next->Asl.ParseOpcode = PARSEOP_RAW_DATA;
  416. }
  417.  
  418.  
  419. /*******************************************************************************
  420.  *
  421.  * FUNCTION:    OpcDoUnicode
  422.  *
  423.  * PARAMETERS:  Op        - Parse node
  424.  *
  425.  * RETURN:      None
  426.  *
  427.  * DESCRIPTION: Implement the UNICODE ASL "macro".  Convert the input string
  428.  *              to a unicode buffer.  There is no Unicode AML opcode.
  429.  *
  430.  * Note:  The Unicode string is 16 bits per character, no leading signature,
  431.  *        with a 16-bit terminating NULL.
  432.  *
  433.  ******************************************************************************/
  434.  
  435. static void
  436. OpcDoUnicode (
  437.     ACPI_PARSE_OBJECT       *Op)
  438. {
  439.     ACPI_PARSE_OBJECT       *InitializerOp;
  440.     UINT32                  Length;
  441.     UINT32                  Count;
  442.     UINT32                  i;
  443.     UINT8                   *AsciiString;
  444.     UINT16                  *UnicodeString;
  445.     ACPI_PARSE_OBJECT       *BufferLengthOp;
  446.  
  447.  
  448.     /* Change op into a buffer object */
  449.  
  450.     Op->Asl.CompileFlags &= ~NODE_COMPILE_TIME_CONST;
  451.     Op->Asl.ParseOpcode = PARSEOP_BUFFER;
  452.     UtSetParseOpName (Op);
  453.  
  454.     /* Buffer Length is first, followed by the string */
  455.  
  456.     BufferLengthOp = Op->Asl.Child;
  457.     InitializerOp = BufferLengthOp->Asl.Next;
  458.  
  459.     AsciiString = (UINT8 *) InitializerOp->Asl.Value.String;
  460.  
  461.     /* Create a new buffer for the Unicode string */
  462.  
  463.     Count = strlen (InitializerOp->Asl.Value.String) + 1;
  464.     Length = Count * sizeof (UINT16);
  465.     UnicodeString = UtLocalCalloc (Length);
  466.  
  467.     /* Convert to Unicode string (including null terminator) */
  468.  
  469.     for (i = 0; i < Count; i++)
  470.     {
  471.         UnicodeString[i] = (UINT16) AsciiString[i];
  472.     }
  473.  
  474.     /*
  475.      * Just set the buffer size node to be the buffer length, regardless
  476.      * of whether it was previously an integer or a default_arg placeholder
  477.      */
  478.     BufferLengthOp->Asl.ParseOpcode   = PARSEOP_INTEGER;
  479.     BufferLengthOp->Asl.AmlOpcode     = AML_DWORD_OP;
  480.     BufferLengthOp->Asl.Value.Integer = Length;
  481.     UtSetParseOpName (BufferLengthOp);
  482.  
  483.     (void) OpcSetOptimalIntegerSize (BufferLengthOp);
  484.  
  485.     /* The Unicode string is a raw data buffer */
  486.  
  487.     InitializerOp->Asl.Value.Buffer   = (UINT8 *) UnicodeString;
  488.     InitializerOp->Asl.AmlOpcode      = AML_RAW_DATA_BUFFER;
  489.     InitializerOp->Asl.AmlLength      = Length;
  490.     InitializerOp->Asl.ParseOpcode    = PARSEOP_RAW_DATA;
  491.     InitializerOp->Asl.Child          = NULL;
  492.     UtSetParseOpName (InitializerOp);
  493. }
  494.  
  495.  
  496. /*******************************************************************************
  497.  *
  498.  * FUNCTION:    OpcDoEisaId
  499.  *
  500.  * PARAMETERS:  Op        - Parse node
  501.  *
  502.  * RETURN:      None
  503.  *
  504.  * DESCRIPTION: Convert a string EISA ID to numeric representation.  See the
  505.  *              Pnp BIOS Specification for details.  Here is an excerpt:
  506.  *
  507.  *              A seven character ASCII representation of the product
  508.  *              identifier compressed into a 32-bit identifier.  The seven
  509.  *              character ID consists of a three character manufacturer code,
  510.  *              a three character hexadecimal product identifier, and a one
  511.  *              character hexadecimal revision number.  The manufacturer code
  512.  *              is a 3 uppercase character code that is compressed into 3 5-bit
  513.  *              values as follows:
  514.  *                  1) Find hex ASCII value for each letter
  515.  *                  2) Subtract 40h from each ASCII value
  516.  *                  3) Retain 5 least signficant bits for each letter by
  517.  *                     discarding upper 3 bits because they are always 0.
  518.  *                  4) Compressed code = concatenate 0 and the 3 5-bit values
  519.  *
  520.  *              The format of the compressed product identifier is as follows:
  521.  *              Byte 0: Bit 7       - Reserved (0)
  522.  *                      Bits 6-2:   - 1st character of compressed mfg code
  523.  *                      Bits 1-0    - Upper 2 bits of 2nd character of mfg code
  524.  *              Byte 1: Bits 7-5    - Lower 3 bits of 2nd character of mfg code
  525.  *                      Bits 4-0    - 3rd character of mfg code
  526.  *              Byte 2: Bits 7-4    - 1st hex digit of product number
  527.  *                      Bits 3-0    - 2nd hex digit of product number
  528.  *              Byte 3: Bits 7-4    - 3st hex digit of product number
  529.  *                      Bits 3-0    - Hex digit of the revision number
  530.  *
  531.  ******************************************************************************/
  532.  
  533. static void
  534. OpcDoEisaId (
  535.     ACPI_PARSE_OBJECT       *Op)
  536. {
  537.     UINT32                  EisaId = 0;
  538.     UINT32                  BigEndianId;
  539.     char                    *InString;
  540.     ACPI_STATUS             Status = AE_OK;
  541.     UINT32                  i;
  542.  
  543.  
  544.     InString = (char *) Op->Asl.Value.String;
  545.  
  546.     /*
  547.      * The EISAID string must be exactly 7 characters and of the form
  548.      * "UUUXXXX" -- 3 uppercase letters and 4 hex digits (e.g., "PNP0001")
  549.      */
  550.     if (ACPI_STRLEN (InString) != 7)
  551.     {
  552.         Status = AE_BAD_PARAMETER;
  553.     }
  554.     else
  555.     {
  556.         /* Check all 7 characters for correct format */
  557.  
  558.         for (i = 0; i < 7; i++)
  559.         {
  560.             /* First 3 characters must be uppercase letters */
  561.  
  562.             if (i < 3)
  563.             {
  564.                 if (!isupper ((int) InString[i]))
  565.                 {
  566.                     Status = AE_BAD_PARAMETER;
  567.                 }
  568.             }
  569.  
  570.             /* Last 4 characters must be hex digits */
  571.  
  572.             else if (!isxdigit ((int) InString[i]))
  573.             {
  574.                 Status = AE_BAD_PARAMETER;
  575.             }
  576.         }
  577.     }
  578.  
  579.     if (ACPI_FAILURE (Status))
  580.     {
  581.         AslError (ASL_ERROR, ASL_MSG_INVALID_EISAID, Op, Op->Asl.Value.String);
  582.     }
  583.     else
  584.     {
  585.         /* Create ID big-endian first (bits are contiguous) */
  586.  
  587.         BigEndianId =
  588.             (UINT32) ((UINT8) (InString[0] - 0x40)) << 26 |
  589.             (UINT32) ((UINT8) (InString[1] - 0x40)) << 21 |
  590.             (UINT32) ((UINT8) (InString[2] - 0x40)) << 16 |
  591.  
  592.             (UtHexCharToValue (InString[3])) << 12 |
  593.             (UtHexCharToValue (InString[4])) << 8  |
  594.             (UtHexCharToValue (InString[5])) << 4  |
  595.              UtHexCharToValue (InString[6]);
  596.  
  597.         /* Swap to little-endian to get final ID (see function header) */
  598.  
  599.         EisaId = AcpiUtDwordByteSwap (BigEndianId);
  600.     }
  601.  
  602.     /*
  603.      * Morph the Op into an integer, regardless of whether there
  604.      * was an error in the EISAID string
  605.      */
  606.     Op->Asl.Value.Integer = EisaId;
  607.  
  608.     Op->Asl.CompileFlags &= ~NODE_COMPILE_TIME_CONST;
  609.     Op->Asl.ParseOpcode = PARSEOP_INTEGER;
  610.     (void) OpcSetOptimalIntegerSize (Op);
  611.  
  612.     /* Op is now an integer */
  613.  
  614.     UtSetParseOpName (Op);
  615. }
  616.  
  617.  
  618. /*******************************************************************************
  619.  *
  620.  * FUNCTION:    OpcDoUiId
  621.  *
  622.  * PARAMETERS:  Op        - Parse node
  623.  *
  624.  * RETURN:      None
  625.  *
  626.  * DESCRIPTION: Convert UUID string to 16-byte buffer
  627.  *
  628.  ******************************************************************************/
  629.  
  630. static void
  631. OpcDoUuId (
  632.     ACPI_PARSE_OBJECT       *Op)
  633. {
  634.     char                    *InString;
  635.     char                    *Buffer;
  636.     ACPI_STATUS             Status = AE_OK;
  637.     ACPI_PARSE_OBJECT       *NewOp;
  638.  
  639.  
  640.     InString = (char *) Op->Asl.Value.String;
  641.     Buffer = UtLocalCalloc (16);
  642.  
  643.     Status = AuValidateUuid (InString);
  644.     if (ACPI_FAILURE (Status))
  645.     {
  646.         AslError (ASL_ERROR, ASL_MSG_INVALID_UUID, Op, Op->Asl.Value.String);
  647.     }
  648.     else
  649.     {
  650.         (void) AuConvertStringToUuid (InString, Buffer);
  651.     }
  652.  
  653.     /* Change Op to a Buffer */
  654.  
  655.     Op->Asl.ParseOpcode = PARSEOP_BUFFER;
  656.     Op->Common.AmlOpcode = AML_BUFFER_OP;
  657.  
  658.     /* Disable further optimization */
  659.  
  660.     Op->Asl.CompileFlags &= ~NODE_COMPILE_TIME_CONST;
  661.     UtSetParseOpName (Op);
  662.  
  663.     /* Child node is the buffer length */
  664.  
  665.     NewOp = TrAllocateNode (PARSEOP_INTEGER);
  666.  
  667.     NewOp->Asl.AmlOpcode     = AML_BYTE_OP;
  668.     NewOp->Asl.Value.Integer = 16;
  669.     NewOp->Asl.Parent        = Op;
  670.  
  671.     Op->Asl.Child = NewOp;
  672.     Op = NewOp;
  673.  
  674.     /* Peer to the child is the raw buffer data */
  675.  
  676.     NewOp = TrAllocateNode (PARSEOP_RAW_DATA);
  677.     NewOp->Asl.AmlOpcode     = AML_RAW_DATA_BUFFER;
  678.     NewOp->Asl.AmlLength     = 16;
  679.     NewOp->Asl.Value.String  = (char *) Buffer;
  680.     NewOp->Asl.Parent        = Op->Asl.Parent;
  681.  
  682.     Op->Asl.Next = NewOp;
  683. }
  684.  
  685.  
  686. /*******************************************************************************
  687.  *
  688.  * FUNCTION:    OpcGenerateAmlOpcode
  689.  *
  690.  * PARAMETERS:  Op        - Parse node
  691.  *
  692.  * RETURN:      None
  693.  *
  694.  * DESCRIPTION: Generate the AML opcode associated with the node and its
  695.  *              parse (lex/flex) keyword opcode.  Essentially implements
  696.  *              a mapping between the parse opcodes and the actual AML opcodes.
  697.  *
  698.  ******************************************************************************/
  699.  
  700. void
  701. OpcGenerateAmlOpcode (
  702.     ACPI_PARSE_OBJECT       *Op)
  703. {
  704.  
  705.     UINT16                  Index;
  706.  
  707.  
  708.     Index = (UINT16) (Op->Asl.ParseOpcode - ASL_PARSE_OPCODE_BASE);
  709.  
  710.     Op->Asl.AmlOpcode     = AslKeywordMapping[Index].AmlOpcode;
  711.     Op->Asl.AcpiBtype     = AslKeywordMapping[Index].AcpiBtype;
  712.     Op->Asl.CompileFlags |= AslKeywordMapping[Index].Flags;
  713.  
  714.     if (!Op->Asl.Value.Integer)
  715.     {
  716.         Op->Asl.Value.Integer = AslKeywordMapping[Index].Value;
  717.     }
  718.  
  719.     /* Special handling for some opcodes */
  720.  
  721.     switch (Op->Asl.ParseOpcode)
  722.     {
  723.     case PARSEOP_INTEGER:
  724.         /*
  725.          * Set the opcode based on the size of the integer
  726.          */
  727.         (void) OpcSetOptimalIntegerSize (Op);
  728.         break;
  729.  
  730.     case PARSEOP_OFFSET:
  731.  
  732.         Op->Asl.AmlOpcodeLength = 1;
  733.         break;
  734.  
  735.     case PARSEOP_ACCESSAS:
  736.  
  737.         OpcDoAccessAs (Op);
  738.         break;
  739.  
  740.     case PARSEOP_EISAID:
  741.  
  742.         OpcDoEisaId (Op);
  743.         break;
  744.  
  745.     case PARSEOP_TOUUID:
  746.  
  747.         OpcDoUuId (Op);
  748.         break;
  749.  
  750.     case PARSEOP_UNICODE:
  751.  
  752.         OpcDoUnicode (Op);
  753.         break;
  754.  
  755.     case PARSEOP_INCLUDE:
  756.  
  757.         Op->Asl.Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
  758.         Gbl_HasIncludeFiles = TRUE;
  759.         break;
  760.  
  761.     case PARSEOP_EXTERNAL:
  762.  
  763.         Op->Asl.Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
  764.         Op->Asl.Child->Asl.Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
  765.         break;
  766.  
  767.     default:
  768.         /* Nothing to do for other opcodes */
  769.         break;
  770.     }
  771.  
  772.     return;
  773. }
  774.  
  775.  
  776.