2 /******************************************************************************
4 * Module Name: aslopcode - AML opcode generation
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
13 * All rights reserved.
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
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
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;
38 * The above copyright and patent license is granted only if the following
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.
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
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
73 * 3.4. Intel retains all right, title, and interest in and to the Original
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.
81 * 4. Disclaimer and Export Compliance
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
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
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.
115 *****************************************************************************/
118 #include "aslcompiler.h"
119 #include "aslcompiler.y.h"
122 #define _COMPONENT ACPI_COMPILER
123 ACPI_MODULE_NAME ("aslopcodes")
128 static UINT8 OpcMapToUUID
[16] =
130 6,4,2,0,11,9,16,14,19,21,24,26,28,30,32,34
133 /* Local prototypes */
137 ACPI_PARSE_OBJECT
*Op
);
141 ACPI_PARSE_OBJECT
*Op
);
145 ACPI_PARSE_OBJECT
*Op
);
149 ACPI_PARSE_OBJECT
*Op
);
152 /*******************************************************************************
154 * FUNCTION: OpcAmlOpcodeUpdateWalk
156 * PARAMETERS: ASL_WALK_CALLBACK
160 * DESCRIPTION: Opcode update walk, ascending callback
162 ******************************************************************************/
165 OpcAmlOpcodeUpdateWalk (
166 ACPI_PARSE_OBJECT
*Op
,
172 * Handle the Package() case where the actual opcode cannot be determined
173 * until the PackageLength operand has been folded and minimized.
174 * (PackageOp versus VarPackageOp)
176 * This is (as of ACPI 3.0) the only case where the AML opcode can change
177 * based upon the value of a parameter.
179 * The parser always inserts a VarPackage opcode, which can possibly be
180 * optimized to a Package opcode.
182 if (Op
->Asl
.ParseOpcode
== PARSEOP_VAR_PACKAGE
)
191 /*******************************************************************************
193 * FUNCTION: OpcAmlOpcodeWalk
195 * PARAMETERS: ASL_WALK_CALLBACK
199 * DESCRIPTION: Parse tree walk to generate both the AML opcodes and the AML
202 ******************************************************************************/
206 ACPI_PARSE_OBJECT
*Op
,
213 OpcGenerateAmlOpcode (Op
);
214 OpnGenerateAmlOperands (Op
);
219 /*******************************************************************************
221 * FUNCTION: OpcGetIntegerWidth
223 * PARAMETERS: Op - DEFINITION BLOCK op
227 * DESCRIPTION: Extract integer width from the table revision
229 ******************************************************************************/
233 ACPI_PARSE_OBJECT
*Op
)
235 ACPI_PARSE_OBJECT
*Child
;
243 if (Gbl_RevisionOverride
)
245 AcpiUtSetIntegerWidth (Gbl_RevisionOverride
);
249 Child
= Op
->Asl
.Child
;
250 Child
= Child
->Asl
.Next
;
251 Child
= Child
->Asl
.Next
;
253 /* Use the revision to set the integer width */
255 AcpiUtSetIntegerWidth ((UINT8
) Child
->Asl
.Value
.Integer
);
260 /*******************************************************************************
262 * FUNCTION: OpcSetOptimalIntegerSize
264 * PARAMETERS: Op - A parse tree node
266 * RETURN: Integer width, in bytes. Also sets the node AML opcode to the
267 * optimal integer AML prefix opcode.
269 * DESCRIPTION: Determine the optimal AML encoding of an integer. All leading
270 * zeros can be truncated to squeeze the integer into the
271 * minimal number of AML bytes.
273 ******************************************************************************/
276 OpcSetOptimalIntegerSize (
277 ACPI_PARSE_OBJECT
*Op
)
282 * TBD: - we don't want to optimize integers in the block header, but the
283 * code below does not work correctly.
285 if (Op
->Asl
.Parent
&&
286 Op
->Asl
.Parent
->Asl
.Parent
&&
287 (Op
->Asl
.Parent
->Asl
.Parent
->Asl
.ParseOpcode
== PARSEOP_DEFINITIONBLOCK
))
294 * Check for the special AML integers first - Zero, One, Ones.
295 * These are single-byte opcodes that are the smallest possible
296 * representation of an integer.
298 * This optimization is optional.
300 if (Gbl_IntegerOptimizationFlag
)
302 switch (Op
->Asl
.Value
.Integer
)
306 Op
->Asl
.AmlOpcode
= AML_ZERO_OP
;
307 AslError (ASL_OPTIMIZATION
, ASL_MSG_INTEGER_OPTIMIZATION
,
313 Op
->Asl
.AmlOpcode
= AML_ONE_OP
;
314 AslError (ASL_OPTIMIZATION
, ASL_MSG_INTEGER_OPTIMIZATION
,
318 case ACPI_UINT32_MAX
:
320 /* Check for table integer width (32 or 64) */
322 if (AcpiGbl_IntegerByteWidth
== 4)
324 Op
->Asl
.AmlOpcode
= AML_ONES_OP
;
325 AslError (ASL_OPTIMIZATION
, ASL_MSG_INTEGER_OPTIMIZATION
,
331 case ACPI_INTEGER_MAX
:
333 /* Check for table integer width (32 or 64) */
335 if (AcpiGbl_IntegerByteWidth
== 8)
337 Op
->Asl
.AmlOpcode
= AML_ONES_OP
;
338 AslError (ASL_OPTIMIZATION
, ASL_MSG_INTEGER_OPTIMIZATION
,
349 /* Find the best fit using the various AML integer prefixes */
351 if (Op
->Asl
.Value
.Integer
<= ACPI_UINT8_MAX
)
353 Op
->Asl
.AmlOpcode
= AML_BYTE_OP
;
356 if (Op
->Asl
.Value
.Integer
<= ACPI_UINT16_MAX
)
358 Op
->Asl
.AmlOpcode
= AML_WORD_OP
;
361 if (Op
->Asl
.Value
.Integer
<= ACPI_UINT32_MAX
)
363 Op
->Asl
.AmlOpcode
= AML_DWORD_OP
;
368 if (AcpiGbl_IntegerByteWidth
== 4)
370 AslError (ASL_WARNING
, ASL_MSG_INTEGER_LENGTH
,
373 if (!Gbl_IgnoreErrors
)
375 /* Truncate the integer to 32-bit */
376 Op
->Asl
.AmlOpcode
= AML_DWORD_OP
;
381 Op
->Asl
.AmlOpcode
= AML_QWORD_OP
;
387 /*******************************************************************************
389 * FUNCTION: OpcDoAccessAs
391 * PARAMETERS: Op - Parse node
395 * DESCRIPTION: Implement the ACCESS_AS ASL keyword.
397 ******************************************************************************/
401 ACPI_PARSE_OBJECT
*Op
)
403 ACPI_PARSE_OBJECT
*Next
;
406 Op
->Asl
.AmlOpcodeLength
= 1;
407 Next
= Op
->Asl
.Child
;
409 /* First child is the access type */
411 Next
->Asl
.AmlOpcode
= AML_RAW_DATA_BYTE
;
412 Next
->Asl
.ParseOpcode
= PARSEOP_RAW_DATA
;
414 /* Second child is the optional access attribute */
416 Next
= Next
->Asl
.Next
;
417 if (Next
->Asl
.ParseOpcode
== PARSEOP_DEFAULT_ARG
)
419 Next
->Asl
.Value
.Integer
= 0;
421 Next
->Asl
.AmlOpcode
= AML_RAW_DATA_BYTE
;
422 Next
->Asl
.ParseOpcode
= PARSEOP_RAW_DATA
;
426 /*******************************************************************************
428 * FUNCTION: OpcDoUnicode
430 * PARAMETERS: Op - Parse node
434 * DESCRIPTION: Implement the UNICODE ASL "macro". Convert the input string
435 * to a unicode buffer. There is no Unicode AML opcode.
437 * Note: The Unicode string is 16 bits per character, no leading signature,
438 * with a 16-bit terminating NULL.
440 ******************************************************************************/
444 ACPI_PARSE_OBJECT
*Op
)
446 ACPI_PARSE_OBJECT
*InitializerOp
;
451 UINT16
*UnicodeString
;
452 ACPI_PARSE_OBJECT
*BufferLengthOp
;
455 /* Change op into a buffer object */
457 Op
->Asl
.CompileFlags
&= ~NODE_COMPILE_TIME_CONST
;
458 Op
->Asl
.ParseOpcode
= PARSEOP_BUFFER
;
459 UtSetParseOpName (Op
);
461 /* Buffer Length is first, followed by the string */
463 BufferLengthOp
= Op
->Asl
.Child
;
464 InitializerOp
= BufferLengthOp
->Asl
.Next
;
466 AsciiString
= (UINT8
*) InitializerOp
->Asl
.Value
.String
;
468 /* Create a new buffer for the Unicode string */
470 Count
= strlen (InitializerOp
->Asl
.Value
.String
) + 1;
471 Length
= Count
* sizeof (UINT16
);
472 UnicodeString
= UtLocalCalloc (Length
);
474 /* Convert to Unicode string (including null terminator) */
476 for (i
= 0; i
< Count
; i
++)
478 UnicodeString
[i
] = (UINT16
) AsciiString
[i
];
482 * Just set the buffer size node to be the buffer length, regardless
483 * of whether it was previously an integer or a default_arg placeholder
485 BufferLengthOp
->Asl
.ParseOpcode
= PARSEOP_INTEGER
;
486 BufferLengthOp
->Asl
.AmlOpcode
= AML_DWORD_OP
;
487 BufferLengthOp
->Asl
.Value
.Integer
= Length
;
488 UtSetParseOpName (BufferLengthOp
);
490 (void) OpcSetOptimalIntegerSize (BufferLengthOp
);
492 /* The Unicode string is a raw data buffer */
494 InitializerOp
->Asl
.Value
.Buffer
= (UINT8
*) UnicodeString
;
495 InitializerOp
->Asl
.AmlOpcode
= AML_RAW_DATA_BUFFER
;
496 InitializerOp
->Asl
.AmlLength
= Length
;
497 InitializerOp
->Asl
.ParseOpcode
= PARSEOP_RAW_DATA
;
498 InitializerOp
->Asl
.Child
= NULL
;
499 UtSetParseOpName (InitializerOp
);
503 /*******************************************************************************
505 * FUNCTION: OpcDoEisaId
507 * PARAMETERS: Op - Parse node
511 * DESCRIPTION: Convert a string EISA ID to numeric representation. See the
512 * Pnp BIOS Specification for details. Here is an excerpt:
514 * A seven character ASCII representation of the product
515 * identifier compressed into a 32-bit identifier. The seven
516 * character ID consists of a three character manufacturer code,
517 * a three character hexadecimal product identifier, and a one
518 * character hexadecimal revision number. The manufacturer code
519 * is a 3 uppercase character code that is compressed into 3 5-bit
521 * 1) Find hex ASCII value for each letter
522 * 2) Subtract 40h from each ASCII value
523 * 3) Retain 5 least signficant bits for each letter by
524 * discarding upper 3 bits because they are always 0.
525 * 4) Compressed code = concatenate 0 and the 3 5-bit values
527 * The format of the compressed product identifier is as follows:
528 * Byte 0: Bit 7 - Reserved (0)
529 * Bits 6-2: - 1st character of compressed mfg code
530 * Bits 1-0 - Upper 2 bits of 2nd character of mfg code
531 * Byte 1: Bits 7-5 - Lower 3 bits of 2nd character of mfg code
532 * Bits 4-0 - 3rd character of mfg code
533 * Byte 2: Bits 7-4 - 1st hex digit of product number
534 * Bits 3-0 - 2nd hex digit of product number
535 * Byte 3: Bits 7-4 - 3st hex digit of product number
536 * Bits 3-0 - Hex digit of the revision number
538 ******************************************************************************/
542 ACPI_PARSE_OBJECT
*Op
)
547 ACPI_STATUS Status
= AE_OK
;
551 InString
= (char *) Op
->Asl
.Value
.String
;
554 * The EISAID string must be exactly 7 characters and of the form
555 * "UUUXXXX" -- 3 uppercase letters and 4 hex digits (e.g., "PNP0001")
557 if (ACPI_STRLEN (InString
) != 7)
559 Status
= AE_BAD_PARAMETER
;
563 /* Check all 7 characters for correct format */
565 for (i
= 0; i
< 7; i
++)
567 /* First 3 characters must be uppercase letters */
571 if (!isupper (InString
[i
]))
573 Status
= AE_BAD_PARAMETER
;
577 /* Last 4 characters must be hex digits */
579 else if (!isxdigit (InString
[i
]))
581 Status
= AE_BAD_PARAMETER
;
586 if (ACPI_FAILURE (Status
))
588 AslError (ASL_ERROR
, ASL_MSG_INVALID_EISAID
, Op
, Op
->Asl
.Value
.String
);
592 /* Create ID big-endian first (bits are contiguous) */
595 (UINT32
) (InString
[0] - 0x40) << 26 |
596 (UINT32
) (InString
[1] - 0x40) << 21 |
597 (UINT32
) (InString
[2] - 0x40) << 16 |
599 (UtHexCharToValue (InString
[3])) << 12 |
600 (UtHexCharToValue (InString
[4])) << 8 |
601 (UtHexCharToValue (InString
[5])) << 4 |
602 UtHexCharToValue (InString
[6]);
604 /* Swap to little-endian to get final ID (see function header) */
606 EisaId
= AcpiUtDwordByteSwap (BigEndianId
);
610 * Morph the Op into an integer, regardless of whether there
611 * was an error in the EISAID string
613 Op
->Asl
.Value
.Integer
= EisaId
;
615 Op
->Asl
.CompileFlags
&= ~NODE_COMPILE_TIME_CONST
;
616 Op
->Asl
.ParseOpcode
= PARSEOP_INTEGER
;
617 (void) OpcSetOptimalIntegerSize (Op
);
619 /* Op is now an integer */
621 UtSetParseOpName (Op
);
625 /*******************************************************************************
627 * FUNCTION: OpcDoUiId
629 * PARAMETERS: Op - Parse node
633 * DESCRIPTION: Convert UUID string to 16-byte buffer
635 ******************************************************************************/
639 ACPI_PARSE_OBJECT
*Op
)
643 ACPI_STATUS Status
= AE_OK
;
645 ACPI_PARSE_OBJECT
*NewOp
;
648 InString
= (char *) Op
->Asl
.Value
.String
;
650 if (ACPI_STRLEN (InString
) != 36)
652 Status
= AE_BAD_PARAMETER
;
656 /* Check all 36 characters for correct format */
658 for (i
= 0; i
< 36; i
++)
660 if ((i
== 8) || (i
== 13) || (i
== 18) || (i
== 23))
662 if (InString
[i
] != '-')
664 Status
= AE_BAD_PARAMETER
;
669 if (!isxdigit (InString
[i
]))
671 Status
= AE_BAD_PARAMETER
;
677 Buffer
= UtLocalCalloc (16);
679 if (ACPI_FAILURE (Status
))
681 AslError (ASL_ERROR
, ASL_MSG_INVALID_UUID
, Op
, Op
->Asl
.Value
.String
);
683 else for (i
= 0; i
< 16; i
++)
685 Buffer
[i
] = (char) (UtHexCharToValue (InString
[OpcMapToUUID
[i
]]) << 4);
686 Buffer
[i
] |= (char) UtHexCharToValue (InString
[OpcMapToUUID
[i
] + 1]);
689 /* Change Op to a Buffer */
691 Op
->Asl
.ParseOpcode
= PARSEOP_BUFFER
;
692 Op
->Common
.AmlOpcode
= AML_BUFFER_OP
;
694 /* Disable further optimization */
696 Op
->Asl
.CompileFlags
&= ~NODE_COMPILE_TIME_CONST
;
697 UtSetParseOpName (Op
);
699 /* Child node is the buffer length */
701 NewOp
= TrAllocateNode (PARSEOP_INTEGER
);
703 NewOp
->Asl
.AmlOpcode
= AML_BYTE_OP
;
704 NewOp
->Asl
.Value
.Integer
= 16;
705 NewOp
->Asl
.Parent
= Op
;
707 Op
->Asl
.Child
= NewOp
;
710 /* Peer to the child is the raw buffer data */
712 NewOp
= TrAllocateNode (PARSEOP_RAW_DATA
);
713 NewOp
->Asl
.AmlOpcode
= AML_RAW_DATA_BUFFER
;
714 NewOp
->Asl
.AmlLength
= 16;
715 NewOp
->Asl
.Value
.String
= (char *) Buffer
;
716 NewOp
->Asl
.Parent
= Op
->Asl
.Parent
;
718 Op
->Asl
.Next
= NewOp
;
722 /*******************************************************************************
724 * FUNCTION: OpcGenerateAmlOpcode
726 * PARAMETERS: Op - Parse node
730 * DESCRIPTION: Generate the AML opcode associated with the node and its
731 * parse (lex/flex) keyword opcode. Essentially implements
732 * a mapping between the parse opcodes and the actual AML opcodes.
734 ******************************************************************************/
737 OpcGenerateAmlOpcode (
738 ACPI_PARSE_OBJECT
*Op
)
744 Index
= (UINT16
) (Op
->Asl
.ParseOpcode
- ASL_PARSE_OPCODE_BASE
);
746 Op
->Asl
.AmlOpcode
= AslKeywordMapping
[Index
].AmlOpcode
;
747 Op
->Asl
.AcpiBtype
= AslKeywordMapping
[Index
].AcpiBtype
;
748 Op
->Asl
.CompileFlags
|= AslKeywordMapping
[Index
].Flags
;
750 if (!Op
->Asl
.Value
.Integer
)
752 Op
->Asl
.Value
.Integer
= AslKeywordMapping
[Index
].Value
;
755 /* Special handling for some opcodes */
757 switch (Op
->Asl
.ParseOpcode
)
759 case PARSEOP_INTEGER
:
761 * Set the opcode based on the size of the integer
763 (void) OpcSetOptimalIntegerSize (Op
);
768 Op
->Asl
.AmlOpcodeLength
= 1;
771 case PARSEOP_ACCESSAS
:
786 case PARSEOP_UNICODE
:
791 case PARSEOP_INCLUDE
:
793 Op
->Asl
.Child
->Asl
.ParseOpcode
= PARSEOP_DEFAULT_ARG
;
794 Gbl_HasIncludeFiles
= TRUE
;
797 case PARSEOP_EXTERNAL
:
799 Op
->Asl
.Child
->Asl
.ParseOpcode
= PARSEOP_DEFAULT_ARG
;
800 Op
->Asl
.Child
->Asl
.Next
->Asl
.ParseOpcode
= PARSEOP_DEFAULT_ARG
;
804 /* Nothing to do for other opcodes */