1 /******************************************************************************
3 * Module Name: asloperands - AML operand processing
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include "aslcompiler.h"
153 #include "aslcompiler.y.h"
156 #define _COMPONENT ACPI_COMPILER
157 ACPI_MODULE_NAME ("asloperands")
159 /* Local prototypes */
163 ACPI_PARSE_OBJECT *Op);
167 ACPI_PARSE_OBJECT *Op);
171 ACPI_PARSE_OBJECT *Op);
174 OpnDoDefinitionBlock (
175 ACPI_PARSE_OBJECT *Op);
179 ACPI_PARSE_OBJECT *FieldOp,
180 ACPI_PARSE_OBJECT *Op);
184 ACPI_PARSE_OBJECT *Op);
188 ACPI_PARSE_OBJECT *Op);
192 ACPI_PARSE_OBJECT *Op);
196 ACPI_PARSE_OBJECT *Op);
200 ACPI_PARSE_OBJECT *Op);
203 OpnAttachNameToNode (
204 ACPI_PARSE_OBJECT *Op);
207 /*******************************************************************************
209 * FUNCTION: OpnDoMutex
211 * PARAMETERS: Op - The parent parse node
215 * DESCRIPTION: Construct the operands for the MUTEX ASL keyword.
217 ******************************************************************************/
221 ACPI_PARSE_OBJECT *Op)
223 ACPI_PARSE_OBJECT *Next;
226 Next = Op->Asl.Child;
227 Next = Next->Asl.Next;
229 if (Next->Asl.Value.Integer > 15)
231 AslError (ASL_ERROR, ASL_MSG_SYNC_LEVEL, Next, NULL);
237 /*******************************************************************************
239 * FUNCTION: OpnDoMethod
241 * PARAMETERS: Op - The parent parse node
245 * DESCRIPTION: Construct the operands for the METHOD ASL keyword.
247 ******************************************************************************/
251 ACPI_PARSE_OBJECT *Op)
253 ACPI_PARSE_OBJECT *Next;
255 /* Optional arguments for this opcode with defaults */
258 UINT8 Serialized = 0;
259 UINT8 Concurrency = 0;
263 /* Opcode and package length first */
266 Next = Op->Asl.Child;
270 Next = Next->Asl.Next;
271 if (Next->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
273 NumArgs = (UINT8) Next->Asl.Value.Integer;
274 Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
277 /* Serialized Flag */
279 Next = Next->Asl.Next;
280 if (Next->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
282 Serialized = (UINT8) Next->Asl.Value.Integer;
283 Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
286 /* Concurrency value (valid values are 0-15) */
288 Next = Next->Asl.Next;
289 if (Next->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
291 /* This is a ByteConstExpr, so eval the constant now */
293 OpcAmlConstantWalk (Next, 0, NULL);
295 if (Next->Asl.Value.Integer > 15)
297 AslError (ASL_ERROR, ASL_MSG_SYNC_LEVEL, Next, NULL);
300 Concurrency = (UINT8) Next->Asl.Value.Integer;
303 /* Put the bits in their proper places */
305 MethodFlags = (UINT8)
307 ((Serialized & 0x1) << 3) |
308 ((Concurrency & 0xF) << 4));
310 /* Use the last node for the combined flags byte */
312 Next->Asl.Value.Integer = MethodFlags;
313 Next->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
314 Next->Asl.AmlLength = 1;
315 Next->Asl.ParseOpcode = PARSEOP_RAW_DATA;
317 /* Save the arg count in the first node */
319 Op->Asl.Extra = NumArgs;
323 /*******************************************************************************
325 * FUNCTION: OpnDoFieldCommon
327 * PARAMETERS: FieldOp - Node for an ASL field
328 * Op - The parent parse node
332 * DESCRIPTION: Construct the AML operands for the various field keywords,
333 * FIELD, BANKFIELD, INDEXFIELD
335 ******************************************************************************/
339 ACPI_PARSE_OBJECT *FieldOp,
340 ACPI_PARSE_OBJECT *Op)
342 ACPI_PARSE_OBJECT *Next;
343 ACPI_PARSE_OBJECT *PkgLengthNode;
344 UINT32 CurrentBitOffset;
350 UINT32 MinimumLength;
353 /* AccessType -- not optional, so no need to check for DEFAULT_ARG */
355 AccessType = (UINT8) Op->Asl.Value.Integer;
356 Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
358 /* Set the access type in the parent (field) node for use later */
360 FieldOp->Asl.Value.Integer = AccessType;
362 /* LockRule -- not optional, so no need to check for DEFAULT_ARG */
365 LockRule = (UINT8) Next->Asl.Value.Integer;
366 Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
368 /* UpdateRule -- not optional, so no need to check for DEFAULT_ARG */
370 Next = Next->Asl.Next;
371 UpdateRule = (UINT8) Next->Asl.Value.Integer;
374 * Generate the flags byte. The various fields are already
375 * in the right bit position via translation from the
376 * keywords by the parser.
378 FieldFlags = (UINT8) (AccessType | LockRule | UpdateRule);
380 /* Use the previous node to be the FieldFlags node */
382 /* Set the node to RAW_DATA */
384 Next->Asl.Value.Integer = FieldFlags;
385 Next->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
386 Next->Asl.AmlLength = 1;
387 Next->Asl.ParseOpcode = PARSEOP_RAW_DATA;
389 /* Process the FieldUnitList */
391 Next = Next->Asl.Next;
392 CurrentBitOffset = 0;
396 /* Save the offset of this field unit */
398 Next->Asl.ExtraValue = CurrentBitOffset;
400 switch (Next->Asl.ParseOpcode)
402 case PARSEOP_ACCESSAS:
404 PkgLengthNode = Next->Asl.Child;
405 AccessType = (UINT8) PkgLengthNode->Asl.Value.Integer;
407 /* Nothing additional to do */
412 /* New offset into the field */
414 PkgLengthNode = Next->Asl.Child;
415 NewBitOffset = ((UINT32) PkgLengthNode->Asl.Value.Integer) * 8;
418 * Examine the specified offset in relation to the
419 * current offset counter.
421 if (NewBitOffset < CurrentBitOffset)
424 * Not allowed to specify a backwards offset!
425 * Issue error and ignore this node.
427 AslError (ASL_ERROR, ASL_MSG_BACKWARDS_OFFSET, PkgLengthNode,
429 Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
430 PkgLengthNode->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
432 else if (NewBitOffset == CurrentBitOffset)
435 * This Offset() operator is redundant and not needed,
436 * because the offset value is the same as the current
439 AslError (ASL_REMARK, ASL_MSG_OFFSET, PkgLengthNode, NULL);
441 if (AslGbl_OptimizeTrivialParseNodes)
444 * Optimize this Offset() operator by removing/ignoring
445 * it. Set the related nodes to default.
447 Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
448 PkgLengthNode->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
450 AslError (ASL_OPTIMIZATION, ASL_MSG_OFFSET, PkgLengthNode,
451 "Optimizer has removed statement");
455 /* Optimization is disabled, treat as a valid Offset */
457 PkgLengthNode->Asl.Value.Integer =
458 NewBitOffset - CurrentBitOffset;
459 CurrentBitOffset = NewBitOffset;
465 * Valid new offset - set the value to be inserted into the AML
466 * and update the offset counter.
468 PkgLengthNode->Asl.Value.Integer =
469 NewBitOffset - CurrentBitOffset;
470 CurrentBitOffset = NewBitOffset;
474 case PARSEOP_NAMESEG:
475 case PARSEOP_RESERVED_BYTES:
477 /* Named or reserved field entry */
479 PkgLengthNode = Next->Asl.Child;
480 NewBitOffset = (UINT32) PkgLengthNode->Asl.Value.Integer;
481 CurrentBitOffset += NewBitOffset;
483 if ((NewBitOffset == 0) &&
484 (Next->Asl.ParseOpcode == PARSEOP_RESERVED_BYTES) &&
485 AslGbl_OptimizeTrivialParseNodes)
488 * Unnamed field with a bit length of zero. We can
489 * safely just ignore this. However, we will not ignore
490 * a named field of zero length, we don't want to just
493 Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
494 PkgLengthNode->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
498 /* Save the current AccessAs value for error checking later */
502 case AML_FIELD_ACCESS_ANY:
503 case AML_FIELD_ACCESS_BYTE:
504 case AML_FIELD_ACCESS_BUFFER:
510 case AML_FIELD_ACCESS_WORD:
514 case AML_FIELD_ACCESS_DWORD:
518 case AML_FIELD_ACCESS_QWORD:
523 PkgLengthNode->Asl.ExtraValue = MinimumLength;
528 /* All supported field opcodes must appear above */
533 /* Move on to next entry in the field list */
535 Next = Next->Asl.Next;
540 /*******************************************************************************
542 * FUNCTION: OpnDoField
544 * PARAMETERS: Op - The parent parse node
548 * DESCRIPTION: Construct the AML operands for the FIELD ASL keyword
550 ******************************************************************************/
554 ACPI_PARSE_OBJECT *Op)
556 ACPI_PARSE_OBJECT *Next;
559 /* Opcode is parent node */
560 /* First child is field name */
562 Next = Op->Asl.Child;
564 /* Second child is the AccessType */
566 OpnDoFieldCommon (Op, Next->Asl.Next);
570 /*******************************************************************************
572 * FUNCTION: OpnDoIndexField
574 * PARAMETERS: Op - The parent parse node
578 * DESCRIPTION: Construct the AML operands for the INDEXFIELD ASL keyword
580 ******************************************************************************/
584 ACPI_PARSE_OBJECT *Op)
586 ACPI_PARSE_OBJECT *Next;
589 /* Opcode is parent node */
590 /* First child is the index name */
592 Next = Op->Asl.Child;
594 /* Second child is the data name */
596 Next = Next->Asl.Next;
598 /* Third child is the AccessType */
600 OpnDoFieldCommon (Op, Next->Asl.Next);
604 /*******************************************************************************
606 * FUNCTION: OpnDoBankField
608 * PARAMETERS: Op - The parent parse node
612 * DESCRIPTION: Construct the AML operands for the BANKFIELD ASL keyword
614 ******************************************************************************/
618 ACPI_PARSE_OBJECT *Op)
620 ACPI_PARSE_OBJECT *Next;
623 /* Opcode is parent node */
624 /* First child is the region name */
626 Next = Op->Asl.Child;
628 /* Second child is the bank name */
630 Next = Next->Asl.Next;
632 /* Third child is the bank value */
634 Next = Next->Asl.Next;
636 /* Fourth child is the AccessType */
638 OpnDoFieldCommon (Op, Next->Asl.Next);
642 /*******************************************************************************
644 * FUNCTION: OpnDoRegion
646 * PARAMETERS: Op - The parent parse node
650 * DESCRIPTION: Tries to get the length of the region. Can only do this at
651 * compile time if the length is a constant.
653 ******************************************************************************/
657 ACPI_PARSE_OBJECT *Op)
659 ACPI_PARSE_OBJECT *Next;
662 /* Opcode is parent node */
663 /* First child is the region name */
665 Next = Op->Asl.Child;
667 /* Second child is the space ID*/
669 Next = Next->Asl.Next;
671 /* Third child is the region offset */
673 Next = Next->Asl.Next;
675 /* Fourth child is the region length */
677 Next = Next->Asl.Next;
678 if (Next->Asl.ParseOpcode == PARSEOP_INTEGER)
680 Op->Asl.Value.Integer = Next->Asl.Value.Integer;
684 Op->Asl.Value.Integer = ACPI_UINT64_MAX;
689 /*******************************************************************************
691 * FUNCTION: OpnDoBuffer
693 * PARAMETERS: Op - The parent parse node
697 * DESCRIPTION: Construct the AML operands for the BUFFER ASL keyword. We
698 * build a single raw byte buffer from the initialization nodes,
699 * each parse node contains a buffer byte.
701 ******************************************************************************/
705 ACPI_PARSE_OBJECT *Op)
707 ACPI_PARSE_OBJECT *InitializerOp;
708 ACPI_PARSE_OBJECT *BufferLengthOp;
710 /* Optional arguments for this opcode with defaults */
712 UINT32 BufferLength = 0;
715 /* Opcode and package length first */
716 /* Buffer Length is next, followed by the initializer list */
718 BufferLengthOp = Op->Asl.Child;
719 InitializerOp = BufferLengthOp->Asl.Next;
722 * If the BufferLength is not an INTEGER or was not specified in the ASL
723 * (DEFAULT_ARG), it is a TermArg that is
724 * evaluated at run-time, and we are therefore finished.
726 if ((BufferLengthOp->Asl.ParseOpcode != PARSEOP_INTEGER) &&
727 (BufferLengthOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG))
733 * We want to count the number of items in the initializer list, because if
734 * it is larger than the buffer length, we will define the buffer size
735 * to be the size of the initializer list (as per the ACPI Specification)
737 switch (InitializerOp->Asl.ParseOpcode)
739 case PARSEOP_INTEGER:
740 case PARSEOP_BYTECONST:
741 case PARSEOP_WORDCONST:
742 case PARSEOP_DWORDCONST:
744 /* The peer list contains the byte list (if any...) */
746 while (InitializerOp)
748 /* For buffers, this is a list of raw bytes */
750 InitializerOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
751 InitializerOp->Asl.AmlLength = 1;
752 InitializerOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
755 InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
759 case PARSEOP_STRING_LITERAL:
762 * Only one initializer, the string. Buffer must be big enough to hold
763 * the string plus the null termination byte
765 BufferLength = strlen (InitializerOp->Asl.Value.String) + 1;
767 InitializerOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER;
768 InitializerOp->Asl.AmlLength = BufferLength;
769 InitializerOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
772 case PARSEOP_RAW_DATA:
774 /* Buffer nodes are already initialized (e.g. Unicode operator) */
777 case PARSEOP_DEFAULT_ARG:
782 AslError (ASL_ERROR, ASL_MSG_INVALID_OPERAND, InitializerOp,
783 "Unknown buffer initializer opcode");
784 printf ("Unknown buffer initializer opcode [%s]\n",
785 UtGetOpName (InitializerOp->Asl.ParseOpcode));
789 /* Check if initializer list is longer than the buffer length */
791 if (BufferLengthOp->Asl.Value.Integer > BufferLength)
793 BufferLength = (UINT32) BufferLengthOp->Asl.Value.Integer;
798 /* No length AND no items -- issue notice */
800 AslError (ASL_REMARK, ASL_MSG_BUFFER_LENGTH, BufferLengthOp, NULL);
802 /* But go ahead and put the buffer length of zero into the AML */
806 * Just set the buffer size node to be the buffer length, regardless
807 * of whether it was previously an integer or a default_arg placeholder
809 BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER;
810 BufferLengthOp->Asl.AmlOpcode = AML_DWORD_OP;
811 BufferLengthOp->Asl.Value.Integer = BufferLength;
813 (void) OpcSetOptimalIntegerSize (BufferLengthOp);
815 /* Remaining nodes are handled via the tree walk */
819 /*******************************************************************************
821 * FUNCTION: OpnDoPackage
823 * PARAMETERS: Op - The parent parse node
827 * DESCRIPTION: Construct the AML operands for the PACKAGE ASL keyword. NOTE:
828 * can only be called after constants have been folded, to ensure
829 * that the PackageLength operand has been fully reduced.
831 ******************************************************************************/
835 ACPI_PARSE_OBJECT *Op)
837 ACPI_PARSE_OBJECT *InitializerOp;
838 ACPI_PARSE_OBJECT *PackageLengthOp;
839 UINT32 PackageLength = 0;
842 /* Opcode and package length first, followed by the initializer list */
844 PackageLengthOp = Op->Asl.Child;
845 InitializerOp = PackageLengthOp->Asl.Next;
847 /* Count the number of items in the initializer list */
849 if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
851 /* The peer list contains the byte list (if any...) */
853 while (InitializerOp)
856 InitializerOp = InitializerOp->Asl.Next;
860 /* If package length is a constant, compare to the initializer list */
862 if ((PackageLengthOp->Asl.ParseOpcode == PARSEOP_INTEGER) ||
863 (PackageLengthOp->Asl.ParseOpcode == PARSEOP_QWORDCONST))
865 if (PackageLengthOp->Asl.Value.Integer > PackageLength)
868 * Allow package length to be longer than the initializer
869 * list -- but if the length of initializer list is nonzero,
870 * issue a message since this is probably a coding error,
871 * even though technically legal.
873 if (PackageLength > 0)
875 AslError (ASL_REMARK, ASL_MSG_LIST_LENGTH_SHORT,
876 PackageLengthOp, NULL);
879 PackageLength = (UINT32) PackageLengthOp->Asl.Value.Integer;
881 else if (PackageLengthOp->Asl.Value.Integer < PackageLength)
884 * The package length is smaller than the length of the
885 * initializer list. This is an error as per the ACPI spec.
887 AslError (ASL_ERROR, ASL_MSG_LIST_LENGTH_LONG,
888 PackageLengthOp, NULL);
892 if (PackageLengthOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
895 * This is the case if the PackageLength was left empty - Package()
896 * The package length becomes the length of the initializer list
898 Op->Asl.Child->Asl.ParseOpcode = PARSEOP_INTEGER;
899 Op->Asl.Child->Asl.Value.Integer = PackageLength;
901 /* Set the AML opcode */
903 (void) OpcSetOptimalIntegerSize (Op->Asl.Child);
906 /* If not a variable-length package, check for a zero package length */
908 if ((PackageLengthOp->Asl.ParseOpcode == PARSEOP_INTEGER) ||
909 (PackageLengthOp->Asl.ParseOpcode == PARSEOP_QWORDCONST) ||
910 (PackageLengthOp->Asl.ParseOpcode == PARSEOP_ZERO) ||
911 (PackageLengthOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG))
915 /* No length AND no initializer list -- issue a remark */
917 AslError (ASL_REMARK, ASL_MSG_PACKAGE_LENGTH,
918 PackageLengthOp, NULL);
920 /* But go ahead and put the buffer length of zero into the AML */
925 * If the PackageLength is a constant <= 255, we can change the
926 * AML opcode from VarPackage to a simple (ACPI 1.0) Package opcode.
928 if (((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_INTEGER) &&
929 (Op->Asl.Child->Asl.Value.Integer <= 255)) ||
930 (Op->Asl.Child->Asl.ParseOpcode == PARSEOP_ONE) ||
931 (Op->Asl.Child->Asl.ParseOpcode == PARSEOP_ONES)||
932 (Op->Asl.Child->Asl.ParseOpcode == PARSEOP_ZERO))
934 Op->Asl.AmlOpcode = AML_PACKAGE_OP;
935 Op->Asl.ParseOpcode = PARSEOP_PACKAGE;
938 * Just set the package size node to be the package length, regardless
939 * of whether it was previously an integer or a default_arg placeholder
941 PackageLengthOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
942 PackageLengthOp->Asl.AmlLength = 1;
943 PackageLengthOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
944 PackageLengthOp->Asl.Value.Integer = PackageLength;
947 /* Remaining nodes are handled via the tree walk */
951 /*******************************************************************************
953 * FUNCTION: OpnDoLoadTable
955 * PARAMETERS: Op - The parent parse node
959 * DESCRIPTION: Construct the AML operands for the LOADTABLE ASL keyword.
961 ******************************************************************************/
965 ACPI_PARSE_OBJECT *Op)
967 ACPI_PARSE_OBJECT *Next;
970 /* Opcode is parent node */
971 /* First child is the table signature */
973 Next = Op->Asl.Child;
975 /* Second child is the OEM ID*/
977 Next = Next->Asl.Next;
979 /* Third child is the OEM table ID */
981 Next = Next->Asl.Next;
983 /* Fourth child is the RootPath string */
985 Next = Next->Asl.Next;
986 if (Next->Asl.ParseOpcode == PARSEOP_ZERO)
988 Next->Asl.ParseOpcode = PARSEOP_STRING_LITERAL;
989 Next->Asl.Value.String = "\\";
990 Next->Asl.AmlLength = 2;
991 OpcGenerateAmlOpcode (Next);
994 #ifdef ASL_FUTURE_IMPLEMENTATION
996 /* TBD: NOT IMPLEMENTED */
997 /* Fifth child is the [optional] ParameterPathString */
998 /* Sixth child is the [optional] ParameterData */
1000 Next = Next->Asl.Next;
1001 if (Next->Asl.ParseOpcode == DEFAULT_ARG)
1003 Next->Asl.AmlLength = 1;
1004 Next->Asl.ParseOpcode = ZERO;
1005 OpcGenerateAmlOpcode (Next);
1009 Next = Next->Asl.Next;
1010 if (Next->Asl.ParseOpcode == DEFAULT_ARG)
1012 Next->Asl.AmlLength = 1;
1013 Next->Asl.ParseOpcode = ZERO;
1014 OpcGenerateAmlOpcode (Next);
1020 /*******************************************************************************
1022 * FUNCTION: OpnDoDefinitionBlock
1024 * PARAMETERS: Op - The parent parse node
1028 * DESCRIPTION: Construct the AML operands for the DEFINITIONBLOCK ASL keyword
1030 ******************************************************************************/
1033 OpnDoDefinitionBlock (
1034 ACPI_PARSE_OBJECT *Op)
1036 ACPI_PARSE_OBJECT *Child;
1043 * These nodes get stuffed into the table header. They are special
1044 * cased when the table is written to the output file.
1046 * Mark all of these nodes as non-usable so they won't get output
1050 /* Get AML filename. Use it if non-null */
1052 Child = Op->Asl.Child;
1053 if (Child->Asl.Value.Buffer &&
1054 *Child->Asl.Value.Buffer &&
1055 (AslGbl_UseDefaultAmlFilename))
1058 * We will use the AML filename that is embedded in the source file
1059 * for the output filename.
1061 Filename = UtLocalCacheCalloc (strlen (AslGbl_DirectoryPath) +
1062 strlen ((char *) Child->Asl.Value.Buffer) + 1);
1064 /* Prepend the current directory path */
1066 strcpy (Filename, AslGbl_DirectoryPath);
1067 strcat (Filename, (char *) Child->Asl.Value.Buffer);
1069 AslGbl_OutputFilenamePrefix = Filename;
1070 UtConvertBackslashes (AslGbl_OutputFilenamePrefix);
1073 Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
1077 Child = Child->Asl.Next;
1078 Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
1079 if (Child->Asl.Value.String)
1081 AslGbl_TableSignature = Child->Asl.Value.String;
1082 if (strlen (AslGbl_TableSignature) != ACPI_NAME_SIZE)
1084 AslError (ASL_ERROR, ASL_MSG_TABLE_SIGNATURE, Child,
1085 "Length must be exactly 4 characters");
1088 for (i = 0; i < ACPI_NAME_SIZE; i++)
1090 if (!isalnum ((int) AslGbl_TableSignature[i]))
1092 AslError (ASL_ERROR, ASL_MSG_TABLE_SIGNATURE, Child,
1093 "Contains non-alphanumeric characters");
1100 Child = Child->Asl.Next;
1101 Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
1104 * We used the revision to set the integer width earlier
1109 Child = Child->Asl.Next;
1110 Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
1111 if (Child->Asl.Value.String &&
1112 strlen (Child->Asl.Value.String) > ACPI_OEM_ID_SIZE)
1114 AslError (ASL_ERROR, ASL_MSG_OEM_ID, Child,
1115 "Length cannot exceed 6 characters");
1120 Child = Child->Asl.Next;
1121 Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
1122 if (Child->Asl.Value.String)
1124 Length = strlen (Child->Asl.Value.String);
1125 if (Length > ACPI_OEM_TABLE_ID_SIZE)
1127 AslError (ASL_ERROR, ASL_MSG_OEM_TABLE_ID, Child,
1128 "Length cannot exceed 8 characters");
1131 AslGbl_TableId = UtLocalCacheCalloc (Length + 1);
1132 strcpy (AslGbl_TableId, Child->Asl.Value.String);
1135 * Convert anything non-alphanumeric to an underscore. This
1136 * allows us to use the TableID to generate unique C symbols.
1138 for (i = 0; i < Length; i++)
1140 if (!isalnum ((int) AslGbl_TableId[i]))
1142 AslGbl_TableId[i] = '_';
1149 Child = Child->Asl.Next;
1150 Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
1154 /*******************************************************************************
1156 * FUNCTION: UtGetArg
1158 * PARAMETERS: Op - Get an argument for this op
1159 * Argn - Nth argument to get
1161 * RETURN: The argument (as an Op object). NULL if argument does not exist
1163 * DESCRIPTION: Get the specified op's argument (peer)
1165 ******************************************************************************/
1169 ACPI_PARSE_OBJECT *Op,
1172 ACPI_PARSE_OBJECT *Arg = NULL;
1175 /* Get the requested argument object */
1177 Arg = Op->Asl.Child;
1181 Arg = Arg->Asl.Next;
1188 /*******************************************************************************
1190 * FUNCTION: OpnAttachNameToNode
1192 * PARAMETERS: Op - The parent parse node
1196 * DESCRIPTION: For the named ASL/AML operators, get the actual name from the
1197 * argument list and attach it to the parent node so that we
1198 * can get to it quickly later.
1200 ******************************************************************************/
1203 OpnAttachNameToNode (
1204 ACPI_PARSE_OBJECT *Op)
1206 ACPI_PARSE_OBJECT *Child = NULL;
1209 switch (Op->Asl.AmlOpcode)
1211 case AML_DATA_REGION_OP:
1214 case AML_EXTERNAL_OP:
1218 case AML_POWER_RESOURCE_OP:
1219 case AML_PROCESSOR_OP:
1220 case AML_THERMAL_ZONE_OP:
1224 Child = UtGetArg (Op, 0);
1229 Child = UtGetArg (Op, 1);
1232 case AML_CREATE_BIT_FIELD_OP:
1233 case AML_CREATE_BYTE_FIELD_OP:
1234 case AML_CREATE_WORD_FIELD_OP:
1235 case AML_CREATE_DWORD_FIELD_OP:
1236 case AML_CREATE_QWORD_FIELD_OP:
1238 Child = UtGetArg (Op, 2);
1241 case AML_CREATE_FIELD_OP:
1243 Child = UtGetArg (Op, 3);
1246 case AML_BANK_FIELD_OP:
1247 case AML_INDEX_FIELD_OP:
1259 UtAttachNamepathToOwner (Op, Child);
1264 /*******************************************************************************
1266 * FUNCTION: OpnGenerateAmlOperands
1268 * PARAMETERS: Op - The parent parse node
1272 * DESCRIPTION: Prepare nodes to be output as AML data and operands. The more
1273 * complex AML opcodes require processing of the child nodes
1274 * (arguments/operands).
1276 ******************************************************************************/
1279 OpnGenerateAmlOperands (
1280 ACPI_PARSE_OBJECT *Op)
1284 if (Op->Asl.AmlOpcode == AML_RAW_DATA_BYTE)
1289 switch (Op->Asl.ParseOpcode)
1291 case PARSEOP_DEFINITION_BLOCK:
1293 OpnDoDefinitionBlock (Op);
1296 case PARSEOP_METHOD:
1311 case PARSEOP_INDEXFIELD:
1313 OpnDoIndexField (Op);
1316 case PARSEOP_BANKFIELD:
1318 OpnDoBankField (Op);
1321 case PARSEOP_BUFFER:
1326 case PARSEOP_LOADTABLE:
1328 OpnDoLoadTable (Op);
1331 case PARSEOP_OPERATIONREGION:
1336 case PARSEOP_RESOURCETEMPLATE:
1338 RsDoResourceTemplate (Op);
1341 case PARSEOP_NAMESEG:
1342 case PARSEOP_NAMESTRING:
1343 case PARSEOP_METHODCALL:
1344 case PARSEOP_STRING_LITERAL:
1352 OpnAttachNameToNode (Op);