2 /******************************************************************************
4 * Module Name: aslopcode - AML opcode generation
7 *****************************************************************************/
9 /******************************************************************************
13 * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
14 * All rights reserved.
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
39 * The above copyright and patent license is granted only if the following
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
74 * 3.4. Intel retains all right, title, and interest in and to the Original
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
82 * 4. Disclaimer and Export Compliance
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
116 *****************************************************************************/
119 #include "aslcompiler.h"
120 #include "aslcompiler.y.h"
123 #define _COMPONENT ACPI_COMPILER
124 ACPI_MODULE_NAME ("aslopcodes")
127 /*******************************************************************************
129 * FUNCTION: OpcAmlOpcodeWalk
131 * PARAMETERS: ASL_WALK_CALLBACK
135 * DESCRIPTION: Parse tree walk to generate both the AML opcodes and the AML
138 ******************************************************************************/
142 ACPI_PARSE_OBJECT *Op,
149 OpcGenerateAmlOpcode (Op);
150 OpnGenerateAmlOperands (Op);
156 /*******************************************************************************
158 * FUNCTION: OpcGetIntegerWidth
160 * PARAMETERS: Op - DEFINITION BLOCK op
164 * DESCRIPTION: Extract integer width from the table revision
166 ******************************************************************************/
170 ACPI_PARSE_OBJECT *Op)
172 ACPI_PARSE_OBJECT *Child;
179 Child = Op->Asl.Child;
180 Child = Child->Asl.Next;
181 Child = Child->Asl.Next;
183 /* Use the revision to set the integer width */
185 AcpiUtSetIntegerWidth ((UINT8) Child->Asl.Value.Integer);
189 /*******************************************************************************
191 * FUNCTION: OpcSetOptimalIntegerSize
193 * PARAMETERS: Op - A parse tree node
195 * RETURN: Integer width, in bytes. Also sets the node AML opcode to the
196 * optimal integer AML prefix opcode.
198 * DESCRIPTION: Determine the optimal AML encoding of an integer. All leading
199 * zeros can be truncated to squeeze the integer into the
200 * minimal number of AML bytes.
202 ******************************************************************************/
205 OpcSetOptimalIntegerSize (
206 ACPI_PARSE_OBJECT *Op)
210 * Check for the special AML integers first - Zero, One, Ones.
211 * These are single-byte opcodes that are the smallest possible
212 * representation of an integer.
214 * This optimization is optional.
216 if (Gbl_IntegerOptimizationFlag)
218 switch (Op->Asl.Value.Integer)
222 Op->Asl.AmlOpcode = AML_ZERO_OP;
223 AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION, Op, "Zero");
228 Op->Asl.AmlOpcode = AML_ONE_OP;
229 AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION, Op, "One");
232 case ACPI_UINT32_MAX:
234 /* Check for table integer width (32 or 64) */
236 if (AcpiGbl_IntegerByteWidth == 4)
238 Op->Asl.AmlOpcode = AML_ONES_OP;
239 AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION, Op, "Ones");
244 case ACPI_INTEGER_MAX:
246 /* Check for table integer width (32 or 64) */
248 if (AcpiGbl_IntegerByteWidth == 8)
250 Op->Asl.AmlOpcode = AML_ONES_OP;
251 AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION, Op, "Ones");
261 /* Find the best fit using the various AML integer prefixes */
263 if (Op->Asl.Value.Integer <= ACPI_UINT8_MAX)
265 Op->Asl.AmlOpcode = AML_BYTE_OP;
268 if (Op->Asl.Value.Integer <= ACPI_UINT16_MAX)
270 Op->Asl.AmlOpcode = AML_WORD_OP;
273 if (Op->Asl.Value.Integer <= ACPI_UINT32_MAX)
275 Op->Asl.AmlOpcode = AML_DWORD_OP;
280 Op->Asl.AmlOpcode = AML_QWORD_OP;
286 /*******************************************************************************
288 * FUNCTION: OpcDoAccessAs
290 * PARAMETERS: Op - Parse node
294 * DESCRIPTION: Implement the ACCESS_AS ASL keyword.
296 ******************************************************************************/
300 ACPI_PARSE_OBJECT *Op)
302 ACPI_PARSE_OBJECT *Next;
305 Op->Asl.AmlOpcodeLength = 1;
306 Next = Op->Asl.Child;
308 /* First child is the access type */
310 Next->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
311 Next->Asl.ParseOpcode = PARSEOP_RAW_DATA;
313 /* Second child is the optional access attribute */
315 Next = Next->Asl.Next;
316 if (Next->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
318 Next->Asl.Value.Integer = 0;
320 Next->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
321 Next->Asl.ParseOpcode = PARSEOP_RAW_DATA;
325 /*******************************************************************************
327 * FUNCTION: OpcDoUnicode
329 * PARAMETERS: Op - Parse node
333 * DESCRIPTION: Implement the UNICODE ASL "macro". Convert the input string
334 * to a unicode buffer. There is no Unicode AML opcode.
336 * Note: The Unicode string is 16 bits per character, no leading signature,
337 * with a 16-bit terminating NULL.
339 ******************************************************************************/
343 ACPI_PARSE_OBJECT *Op)
345 ACPI_PARSE_OBJECT *InitializerOp;
350 UINT16 *UnicodeString;
351 ACPI_PARSE_OBJECT *BufferLengthOp;
354 /* Change op into a buffer object */
356 Op->Asl.CompileFlags &= ~NODE_COMPILE_TIME_CONST;
357 Op->Asl.ParseOpcode = PARSEOP_BUFFER;
358 UtSetParseOpName (Op);
360 /* Buffer Length is first, followed by the string */
362 BufferLengthOp = Op->Asl.Child;
363 InitializerOp = BufferLengthOp->Asl.Next;
365 AsciiString = (UINT8 *) InitializerOp->Asl.Value.String;
367 /* Create a new buffer for the Unicode string */
369 Count = strlen (InitializerOp->Asl.Value.String) + 1;
370 Length = Count * sizeof (UINT16);
371 UnicodeString = UtLocalCalloc (Length);
373 /* Convert to Unicode string (including null terminator) */
375 for (i = 0; i < Count; i++)
377 UnicodeString[i] = (UINT16) AsciiString[i];
381 * Just set the buffer size node to be the buffer length, regardless
382 * of whether it was previously an integer or a default_arg placeholder
384 BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER;
385 BufferLengthOp->Asl.AmlOpcode = AML_DWORD_OP;
386 BufferLengthOp->Asl.Value.Integer = Length;
387 UtSetParseOpName (BufferLengthOp);
389 (void) OpcSetOptimalIntegerSize (BufferLengthOp);
391 /* The Unicode string is a raw data buffer */
393 InitializerOp->Asl.Value.Buffer = (UINT8 *) UnicodeString;
394 InitializerOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER;
395 InitializerOp->Asl.AmlLength = Length;
396 InitializerOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
397 InitializerOp->Asl.Child = NULL;
398 UtSetParseOpName (InitializerOp);
402 /*******************************************************************************
404 * FUNCTION: OpcDoEisaId
406 * PARAMETERS: Op - Parse node
411 * DESCRIPTION: Convert a string EISA ID to numeric representation. See the
412 * Pnp BIOS Specification for details. Here is an excerpt:
414 * A seven character ASCII representation of the product
415 * identifier compressed into a 32-bit identifier. The seven
416 * character ID consists of a three character manufacturer code,
417 * a three character hexadecimal product identifier, and a one
418 * character hexadecimal revision number. The manufacturer code
419 * is a 3 uppercase character code that is compressed into 3 5-bit
421 * 1) Find hex ASCII value for each letter
422 * 2) Subtract 40h from each ASCII value
423 * 3) Retain 5 least signficant bits for each letter by
424 * discarding upper 3 bits because they are always 0.
425 * 4) Compressed code = concatenate 0 and the 3 5-bit values
427 * The format of the compressed product identifier is as follows:
428 * Byte 0: Bit 7 - Reserved (0)
429 * Bits 6-2: - 1st character of compressed mfg code
430 * Bits 1-0 - Upper 2 bits of 2nd character of mfg code
431 * Byte 1: Bits 7-5 - Lower 3 bits of 2nd character of mfg code
432 * Bits 4-0 - 3rd character of mfg code
433 * Byte 2: Bits 7-4 - 1st hex digit of product number
434 * Bits 3-0 - 2nd hex digit of product number
435 * Byte 3: Bits 7-4 - 3st hex digit of product number
436 * Bits 3-0 - Hex digit of the revision number
438 ******************************************************************************/
442 ACPI_PARSE_OBJECT *Op)
447 ACPI_STATUS Status = AE_OK;
451 InString = (char *) Op->Asl.Value.String;
454 * The EISAID string must be exactly 7 characters and of the form
455 * "LLLXXXX" -- 3 letters and 4 hex digits (e.g., "PNP0001")
457 if (ACPI_STRLEN (InString) != 7)
459 Status = AE_BAD_PARAMETER;
463 /* Check all 7 characters for correct format */
465 for (i = 0; i < 7; i++)
467 /* First 3 characters must be letters */
471 if (!isalpha (InString[i]))
473 Status = AE_BAD_PARAMETER;
477 /* Last 4 characters must be hex digits */
479 else if (!isxdigit (InString[i]))
481 Status = AE_BAD_PARAMETER;
486 if (ACPI_FAILURE (Status))
488 AslError (ASL_ERROR, ASL_MSG_INVALID_EISAID, Op, Op->Asl.Value.String);
492 /* Create ID big-endian first (bits are contiguous) */
494 BigEndianId = (UINT32) (InString[0] - 0x40) << 26 |
495 (UINT32) (InString[1] - 0x40) << 21 |
496 (UINT32) (InString[2] - 0x40) << 16 |
498 (UtHexCharToValue (InString[3])) << 12 |
499 (UtHexCharToValue (InString[4])) << 8 |
500 (UtHexCharToValue (InString[5])) << 4 |
501 UtHexCharToValue (InString[6]);
503 /* Swap to little-endian to get final ID (see function header) */
505 EisaId = AcpiUtDwordByteSwap (BigEndianId);
509 * Morph the Op into an integer, regardless of whether there
510 * was an error in the EISAID string
512 Op->Asl.Value.Integer = EisaId;
514 Op->Asl.CompileFlags &= ~NODE_COMPILE_TIME_CONST;
515 Op->Asl.ParseOpcode = PARSEOP_INTEGER;
516 (void) OpcSetOptimalIntegerSize (Op);
518 /* Op is now an integer */
520 UtSetParseOpName (Op);
524 /*******************************************************************************
526 * FUNCTION: OpcGenerateAmlOpcode
528 * PARAMETERS: Op - Parse node
532 * DESCRIPTION: Generate the AML opcode associated with the node and its
533 * parse (lex/flex) keyword opcode. Essentially implements
534 * a mapping between the parse opcodes and the actual AML opcodes.
536 ******************************************************************************/
539 OpcGenerateAmlOpcode (
540 ACPI_PARSE_OBJECT *Op)
546 Index = (UINT16) (Op->Asl.ParseOpcode - ASL_PARSE_OPCODE_BASE);
548 Op->Asl.AmlOpcode = AslKeywordMapping[Index].AmlOpcode;
549 Op->Asl.AcpiBtype = AslKeywordMapping[Index].AcpiBtype;
550 Op->Asl.CompileFlags |= AslKeywordMapping[Index].Flags;
552 if (!Op->Asl.Value.Integer)
554 Op->Asl.Value.Integer = AslKeywordMapping[Index].Value;
557 /* Special handling for some opcodes */
559 switch (Op->Asl.ParseOpcode)
561 case PARSEOP_INTEGER:
563 * Set the opcode based on the size of the integer
565 (void) OpcSetOptimalIntegerSize (Op);
570 Op->Asl.AmlOpcodeLength = 1;
573 case PARSEOP_ACCESSAS:
583 case PARSEOP_UNICODE:
588 case PARSEOP_INCLUDE:
590 Op->Asl.Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
591 Gbl_HasIncludeFiles = TRUE;
594 case PARSEOP_EXTERNAL:
596 Op->Asl.Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
597 Op->Asl.Child->Asl.Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
600 case PARSEOP_PACKAGE:
602 * The variable-length package has a different opcode
604 if ((Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) &&
605 (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_INTEGER) &&
606 (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_BYTECONST))
608 Op->Asl.AmlOpcode = AML_VAR_PACKAGE_OP;
613 /* Nothing to do for other opcodes */