i386/identcpu.c: Add VIA Nano support
[dragonfly.git] / sys / contrib / dev / acpica-unix-20061109 / compiler / asloperands.c
blobb97d2dde8e004d2422cb93f81cd23ccd6bf5f706
2 /******************************************************************************
4 * Module Name: asloperands - AML operand processing
5 * $Revision: 1.60 $
7 *****************************************************************************/
9 /******************************************************************************
11 * 1. Copyright Notice
13 * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp.
14 * All rights reserved.
16 * 2. License
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
21 * property rights.
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
40 * conditions are met:
42 * 3. Conditions
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
66 * make.
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
72 * distribution.
74 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * Intel Code.
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
90 * PARTICULAR PURPOSE.
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
99 * LIMITED REMEDY.
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"
121 #include "amlcode.h"
123 #define _COMPONENT ACPI_COMPILER
124 ACPI_MODULE_NAME ("asloperands")
126 /* Local prototypes */
128 static void
129 OpnDoField (
130 ACPI_PARSE_OBJECT *Op);
132 static void
133 OpnDoBankField (
134 ACPI_PARSE_OBJECT *Op);
136 static void
137 OpnDoBuffer (
138 ACPI_PARSE_OBJECT *Op);
140 static void
141 OpnDoDefinitionBlock (
142 ACPI_PARSE_OBJECT *Op);
144 static void
145 OpnDoFieldCommon (
146 ACPI_PARSE_OBJECT *FieldOp,
147 ACPI_PARSE_OBJECT *Op);
149 static void
150 OpnDoIndexField (
151 ACPI_PARSE_OBJECT *Op);
153 static void
154 OpnDoLoadTable (
155 ACPI_PARSE_OBJECT *Op);
157 static void
158 OpnDoMethod (
159 ACPI_PARSE_OBJECT *Op);
161 static void
162 OpnDoMutex (
163 ACPI_PARSE_OBJECT *Op);
165 static void
166 OpnDoRegion (
167 ACPI_PARSE_OBJECT *Op);
169 static void
170 OpnAttachNameToNode (
171 ACPI_PARSE_OBJECT *Op);
174 /*******************************************************************************
176 * FUNCTION: OpnDoMutex
178 * PARAMETERS: Op - The parent parse node
180 * RETURN: None
182 * DESCRIPTION: Construct the operands for the MUTEX ASL keyword.
184 ******************************************************************************/
186 static void
187 OpnDoMutex (
188 ACPI_PARSE_OBJECT *Op)
190 ACPI_PARSE_OBJECT *Next;
193 Next = Op->Asl.Child;
194 Next = Next->Asl.Next;
196 if (Next->Asl.Value.Integer > 15)
198 AslError (ASL_ERROR, ASL_MSG_SYNC_LEVEL, Next, NULL);
200 return;
204 /*******************************************************************************
206 * FUNCTION: OpnDoMethod
208 * PARAMETERS: Op - The parent parse node
210 * RETURN: None
212 * DESCRIPTION: Construct the operands for the METHOD ASL keyword.
214 ******************************************************************************/
216 static void
217 OpnDoMethod (
218 ACPI_PARSE_OBJECT *Op)
220 ACPI_PARSE_OBJECT *Next;
222 /* Optional arguments for this opcode with defaults */
224 UINT8 NumArgs = 0;
225 UINT8 Serialized = 0;
226 UINT8 Concurrency = 0;
227 UINT8 MethodFlags;
230 /* Opcode and package length first */
231 /* Method name */
233 Next = Op->Asl.Child;
235 /* Num args */
237 Next = Next->Asl.Next;
238 if (Next->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
240 NumArgs = (UINT8) Next->Asl.Value.Integer;
241 Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
244 /* Serialized Flag */
246 Next = Next->Asl.Next;
247 if (Next->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
249 Serialized = (UINT8) Next->Asl.Value.Integer;
250 Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
253 /* Concurrency value (valid values are 0-15) */
255 Next = Next->Asl.Next;
256 if (Next->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
258 if (Next->Asl.Value.Integer > 15)
260 AslError (ASL_ERROR, ASL_MSG_SYNC_LEVEL, Next, NULL);
262 Concurrency = (UINT8) Next->Asl.Value.Integer;
265 /* Put the bits in their proper places */
267 MethodFlags = (UINT8) ((NumArgs & 0x7) |
268 ((Serialized & 0x1) << 3) |
269 ((Concurrency & 0xF) << 4));
271 /* Use the last node for the combined flags byte */
273 Next->Asl.Value.Integer = MethodFlags;
274 Next->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
275 Next->Asl.AmlLength = 1;
276 Next->Asl.ParseOpcode = PARSEOP_RAW_DATA;
278 /* Save the arg count in the first node */
280 Op->Asl.Extra = NumArgs;
284 /*******************************************************************************
286 * FUNCTION: OpnDoFieldCommon
288 * PARAMETERS: FieldOp - Node for an ASL field
289 * Op - The parent parse node
291 * RETURN: None
293 * DESCRIPTION: Construct the AML operands for the various field keywords,
294 * FIELD, BANKFIELD, INDEXFIELD
296 ******************************************************************************/
298 static void
299 OpnDoFieldCommon (
300 ACPI_PARSE_OBJECT *FieldOp,
301 ACPI_PARSE_OBJECT *Op)
303 ACPI_PARSE_OBJECT *Next;
304 ACPI_PARSE_OBJECT *PkgLengthNode;
305 UINT32 CurrentBitOffset;
306 UINT32 NewBitOffset;
307 UINT8 AccessType;
308 UINT8 LockRule;
309 UINT8 UpdateRule;
310 UINT8 FieldFlags;
311 UINT32 MinimumLength;
314 /* AccessType -- not optional, so no need to check for DEFAULT_ARG */
316 AccessType = (UINT8) Op->Asl.Value.Integer;
317 Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
319 /* Set the access type in the parent (field) node for use later */
321 FieldOp->Asl.Value.Integer = AccessType;
323 /* LockRule -- not optional, so no need to check for DEFAULT_ARG */
325 Next = Op->Asl.Next;
326 LockRule = (UINT8) Next->Asl.Value.Integer;
327 Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
329 /* UpdateRule -- not optional, so no need to check for DEFAULT_ARG */
331 Next = Next->Asl.Next;
332 UpdateRule = (UINT8) Next->Asl.Value.Integer;
335 * Generate the flags byte. The various fields are already
336 * in the right bit position via translation from the
337 * keywords by the parser.
339 FieldFlags = (UINT8) (AccessType | LockRule | UpdateRule);
341 /* Use the previous node to be the FieldFlags node */
343 /* Set the node to RAW_DATA */
345 Next->Asl.Value.Integer = FieldFlags;
346 Next->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
347 Next->Asl.AmlLength = 1;
348 Next->Asl.ParseOpcode = PARSEOP_RAW_DATA;
350 /* Process the FieldUnitList */
352 Next = Next->Asl.Next;
353 CurrentBitOffset = 0;
355 while (Next)
357 /* Save the offset of this field unit */
359 Next->Asl.ExtraValue = CurrentBitOffset;
361 switch (Next->Asl.ParseOpcode)
363 case PARSEOP_ACCESSAS:
365 PkgLengthNode = Next->Asl.Child;
366 AccessType = (UINT8) PkgLengthNode->Asl.Value.Integer;
368 /* Nothing additional to do */
369 break;
372 case PARSEOP_OFFSET:
374 /* New offset into the field */
376 PkgLengthNode = Next->Asl.Child;
377 NewBitOffset = ((UINT32) PkgLengthNode->Asl.Value.Integer) * 8;
380 * Examine the specified offset in relation to the
381 * current offset counter.
383 if (NewBitOffset < CurrentBitOffset)
386 * Not allowed to specify a backwards offset!
387 * Issue error and ignore this node.
389 AslError (ASL_ERROR, ASL_MSG_BACKWARDS_OFFSET, PkgLengthNode,
390 NULL);
391 Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
392 PkgLengthNode->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
394 else if (NewBitOffset == CurrentBitOffset)
397 * Offset is redundant; we don't need to output an
398 * offset opcode. Just set these nodes to default
400 Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
401 PkgLengthNode->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
403 else
406 * Valid new offset - set the value to be inserted into the AML
407 * and update the offset counter.
409 PkgLengthNode->Asl.Value.Integer =
410 NewBitOffset - CurrentBitOffset;
411 CurrentBitOffset = NewBitOffset;
413 break;
416 case PARSEOP_NAMESEG:
417 case PARSEOP_RESERVED_BYTES:
419 /* Named or reserved field entry */
421 PkgLengthNode = Next->Asl.Child;
422 NewBitOffset = (UINT32) PkgLengthNode->Asl.Value.Integer;
423 CurrentBitOffset += NewBitOffset;
425 /* Save the current AccessAs value for error checking later */
427 switch (AccessType)
429 case AML_FIELD_ACCESS_ANY:
430 case AML_FIELD_ACCESS_BYTE:
431 case AML_FIELD_ACCESS_BUFFER:
432 default:
433 MinimumLength = 8;
434 break;
436 case AML_FIELD_ACCESS_WORD:
437 MinimumLength = 16;
438 break;
440 case AML_FIELD_ACCESS_DWORD:
441 MinimumLength = 32;
442 break;
444 case AML_FIELD_ACCESS_QWORD:
445 MinimumLength = 64;
446 break;
449 PkgLengthNode->Asl.ExtraValue = MinimumLength;
450 break;
452 default:
453 /* All supported field opcodes must appear above */
454 break;
457 /* Move on to next entry in the field list */
459 Next = Next->Asl.Next;
464 /*******************************************************************************
466 * FUNCTION: OpnDoField
468 * PARAMETERS: Op - The parent parse node
470 * RETURN: None
472 * DESCRIPTION: Construct the AML operands for the FIELD ASL keyword
474 ******************************************************************************/
476 static void
477 OpnDoField (
478 ACPI_PARSE_OBJECT *Op)
480 ACPI_PARSE_OBJECT *Next;
483 /* Opcode is parent node */
484 /* First child is field name */
486 Next = Op->Asl.Child;
488 /* Second child is the AccessType */
490 OpnDoFieldCommon (Op, Next->Asl.Next);
494 /*******************************************************************************
496 * FUNCTION: OpnDoIndexField
498 * PARAMETERS: Op - The parent parse node
500 * RETURN: None
502 * DESCRIPTION: Construct the AML operands for the INDEXFIELD ASL keyword
504 ******************************************************************************/
506 static void
507 OpnDoIndexField (
508 ACPI_PARSE_OBJECT *Op)
510 ACPI_PARSE_OBJECT *Next;
513 /* Opcode is parent node */
514 /* First child is the index name */
516 Next = Op->Asl.Child;
518 /* Second child is the data name */
520 Next = Next->Asl.Next;
522 /* Third child is the AccessType */
524 OpnDoFieldCommon (Op, Next->Asl.Next);
528 /*******************************************************************************
530 * FUNCTION: OpnDoBankField
532 * PARAMETERS: Op - The parent parse node
534 * RETURN: None
536 * DESCRIPTION: Construct the AML operands for the BANKFIELD ASL keyword
538 ******************************************************************************/
540 static void
541 OpnDoBankField (
542 ACPI_PARSE_OBJECT *Op)
544 ACPI_PARSE_OBJECT *Next;
547 /* Opcode is parent node */
548 /* First child is the region name */
550 Next = Op->Asl.Child;
552 /* Second child is the bank name */
554 Next = Next->Asl.Next;
556 /* Third child is the bank value */
558 Next = Next->Asl.Next;
560 /* Fourth child is the AccessType */
562 OpnDoFieldCommon (Op, Next->Asl.Next);
566 /*******************************************************************************
568 * FUNCTION: OpnDoRegion
570 * PARAMETERS: Op - The parent parse node
572 * RETURN: None
574 * DESCRIPTION: Tries to get the length of the region. Can only do this at
575 * compile time if the length is a constant.
577 ******************************************************************************/
579 static void
580 OpnDoRegion (
581 ACPI_PARSE_OBJECT *Op)
583 ACPI_PARSE_OBJECT *Next;
586 /* Opcode is parent node */
587 /* First child is the region name */
589 Next = Op->Asl.Child;
591 /* Second child is the space ID*/
593 Next = Next->Asl.Next;
595 /* Third child is the region offset */
597 Next = Next->Asl.Next;
599 /* Fourth child is the region length */
601 Next = Next->Asl.Next;
602 if (Next->Asl.ParseOpcode == PARSEOP_INTEGER)
604 Op->Asl.Value.Integer = Next->Asl.Value.Integer;
606 else
608 Op->Asl.Value.Integer = ACPI_INTEGER_MAX;
613 /*******************************************************************************
615 * FUNCTION: OpnDoBuffer
617 * PARAMETERS: Op - The parent parse node
619 * RETURN: None
621 * DESCRIPTION: Construct the AML operands for the BUFFER ASL keyword. We
622 * build a single raw byte buffer from the initialization nodes,
623 * each parse node contains a buffer byte.
625 ******************************************************************************/
627 static void
628 OpnDoBuffer (
629 ACPI_PARSE_OBJECT *Op)
631 ACPI_PARSE_OBJECT *InitializerOp;
632 ACPI_PARSE_OBJECT *BufferLengthOp;
634 /* Optional arguments for this opcode with defaults */
636 UINT32 BufferLength = 0;
639 /* Opcode and package length first */
640 /* Buffer Length is next, followed by the initializer list */
642 BufferLengthOp = Op->Asl.Child;
643 InitializerOp = BufferLengthOp->Asl.Next;
646 * If the BufferLength is not an INTEGER or was not specified in the ASL
647 * (DEFAULT_ARG), it is a TermArg that is
648 * evaluated at run-time, and we are therefore finished.
650 if ((BufferLengthOp->Asl.ParseOpcode != PARSEOP_INTEGER) &&
651 (BufferLengthOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG))
653 return;
657 * We want to count the number of items in the initializer list, because if
658 * it is larger than the buffer length, we will define the buffer size
659 * to be the size of the initializer list (as per the ACPI Specification)
661 switch (InitializerOp->Asl.ParseOpcode)
663 case PARSEOP_INTEGER:
664 case PARSEOP_BYTECONST:
665 case PARSEOP_WORDCONST:
666 case PARSEOP_DWORDCONST:
668 /* The peer list contains the byte list (if any...) */
670 while (InitializerOp)
672 /* For buffers, this is a list of raw bytes */
674 InitializerOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
675 InitializerOp->Asl.AmlLength = 1;
676 InitializerOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
678 BufferLength++;
679 InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
681 break;
684 case PARSEOP_STRING_LITERAL:
687 * Only one initializer, the string. Buffer must be big enough to hold
688 * the string plus the null termination byte
690 BufferLength = strlen (InitializerOp->Asl.Value.String) + 1;
692 InitializerOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER;
693 InitializerOp->Asl.AmlLength = BufferLength;
694 InitializerOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
695 break;
698 case PARSEOP_RAW_DATA:
700 /* Buffer nodes are already initialized (e.g. Unicode operator) */
701 return;
704 case PARSEOP_DEFAULT_ARG:
705 break;
708 default:
709 AslError (ASL_ERROR, ASL_MSG_INVALID_OPERAND, InitializerOp,
710 "Unknown buffer initializer opcode");
711 printf ("Unknown buffer initializer opcode [%s]\n",
712 UtGetOpName (InitializerOp->Asl.ParseOpcode));
713 return;
716 /* Check if initializer list is longer than the buffer length */
718 if (BufferLengthOp->Asl.Value.Integer > BufferLength)
720 BufferLength = (UINT32) BufferLengthOp->Asl.Value.Integer;
723 if (!BufferLength)
725 /* No length AND no items -- issue notice */
727 AslError (ASL_REMARK, ASL_MSG_BUFFER_LENGTH, BufferLengthOp, NULL);
729 /* But go ahead and put the buffer length of zero into the AML */
733 * Just set the buffer size node to be the buffer length, regardless
734 * of whether it was previously an integer or a default_arg placeholder
736 BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER;
737 BufferLengthOp->Asl.AmlOpcode = AML_DWORD_OP;
738 BufferLengthOp->Asl.Value.Integer = BufferLength;
740 (void) OpcSetOptimalIntegerSize (BufferLengthOp);
742 /* Remaining nodes are handled via the tree walk */
746 /*******************************************************************************
748 * FUNCTION: OpnDoPackage
750 * PARAMETERS: Op - The parent parse node
752 * RETURN: None
754 * DESCRIPTION: Construct the AML operands for the PACKAGE ASL keyword. NOTE:
755 * can only be called after constants have been folded, to ensure
756 * that the PackageLength operand has been fully reduced.
758 ******************************************************************************/
760 void
761 OpnDoPackage (
762 ACPI_PARSE_OBJECT *Op)
764 ACPI_PARSE_OBJECT *InitializerOp;
765 ACPI_PARSE_OBJECT *PackageLengthOp;
766 UINT32 PackageLength = 0;
769 /* Opcode and package length first, followed by the initializer list */
771 PackageLengthOp = Op->Asl.Child;
772 InitializerOp = PackageLengthOp->Asl.Next;
774 /* Count the number of items in the initializer list */
776 if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
778 /* The peer list contains the byte list (if any...) */
780 while (InitializerOp)
782 PackageLength++;
783 InitializerOp = InitializerOp->Asl.Next;
787 /* If package length is a constant, compare to the initializer list */
789 if ((PackageLengthOp->Asl.ParseOpcode == PARSEOP_INTEGER) ||
790 (PackageLengthOp->Asl.ParseOpcode == PARSEOP_QWORDCONST))
792 if (PackageLengthOp->Asl.Value.Integer >= PackageLength)
794 /* Allow package to be longer than the initializer list */
796 PackageLength = (UINT32) PackageLengthOp->Asl.Value.Integer;
798 else
801 * Initializer list is longer than the package length. This
802 * is an error as per the ACPI spec.
804 AslError (ASL_ERROR, ASL_MSG_LIST_LENGTH,
805 PackageLengthOp->Asl.Next, NULL);
809 if (PackageLengthOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
812 * This is the case if the PackageLength was left empty - Package()
813 * The package length becomes the length of the initializer list
815 Op->Asl.Child->Asl.ParseOpcode = PARSEOP_INTEGER;
816 Op->Asl.Child->Asl.Value.Integer = PackageLength;
818 /* Set the AML opcode */
820 (void) OpcSetOptimalIntegerSize (Op->Asl.Child);
823 /* If not a variable-length package, check for a zero package length */
825 if ((PackageLengthOp->Asl.ParseOpcode == PARSEOP_INTEGER) ||
826 (PackageLengthOp->Asl.ParseOpcode == PARSEOP_QWORDCONST) ||
827 (PackageLengthOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG))
829 if (!PackageLength)
831 /* No length AND no initializer list -- issue a remark */
833 AslError (ASL_REMARK, ASL_MSG_PACKAGE_LENGTH,
834 PackageLengthOp, NULL);
836 /* But go ahead and put the buffer length of zero into the AML */
841 * If the PackageLength is a constant <= 255, we can change the
842 * AML opcode from VarPackage to a simple (ACPI 1.0) Package opcode.
844 if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_INTEGER) &&
845 (Op->Asl.Child->Asl.Value.Integer <= 255))
847 Op->Asl.AmlOpcode = AML_PACKAGE_OP;
848 Op->Asl.ParseOpcode = PARSEOP_PACKAGE;
851 * Just set the package size node to be the package length, regardless
852 * of whether it was previously an integer or a default_arg placeholder
854 PackageLengthOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
855 PackageLengthOp->Asl.AmlLength = 1;
856 PackageLengthOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
857 PackageLengthOp->Asl.Value.Integer = PackageLength;
860 /* Remaining nodes are handled via the tree walk */
864 /*******************************************************************************
866 * FUNCTION: OpnDoLoadTable
868 * PARAMETERS: Op - The parent parse node
870 * RETURN: None
872 * DESCRIPTION: Construct the AML operands for the LOADTABLE ASL keyword.
874 ******************************************************************************/
876 static void
877 OpnDoLoadTable (
878 ACPI_PARSE_OBJECT *Op)
880 ACPI_PARSE_OBJECT *Next;
883 /* Opcode is parent node */
884 /* First child is the table signature */
886 Next = Op->Asl.Child;
888 /* Second child is the OEM ID*/
890 Next = Next->Asl.Next;
892 /* Third child is the OEM table ID */
894 Next = Next->Asl.Next;
896 /* Fourth child is the RootPath string */
898 Next = Next->Asl.Next;
899 if (Next->Asl.ParseOpcode == PARSEOP_ZERO)
901 Next->Asl.ParseOpcode = PARSEOP_STRING_LITERAL;
902 Next->Asl.Value.String = "\\";
903 Next->Asl.AmlLength = 2;
904 OpcGenerateAmlOpcode (Next);
907 #ifdef ASL_FUTURE_IMPLEMENTATION
909 /* TBD: NOT IMPLEMENTED */
910 /* Fifth child is the [optional] ParameterPathString */
911 /* Sixth child is the [optional] ParameterData */
913 Next = Next->Asl.Next;
914 if (Next->Asl.ParseOpcode == DEFAULT_ARG)
916 Next->Asl.AmlLength = 1;
917 Next->Asl.ParseOpcode = ZERO;
918 OpcGenerateAmlOpcode (Next);
922 Next = Next->Asl.Next;
923 if (Next->Asl.ParseOpcode == DEFAULT_ARG)
925 Next->Asl.AmlLength = 1;
926 Next->Asl.ParseOpcode = ZERO;
927 OpcGenerateAmlOpcode (Next);
929 #endif
933 /*******************************************************************************
935 * FUNCTION: OpnDoDefinitionBlock
937 * PARAMETERS: Op - The parent parse node
939 * RETURN: None
941 * DESCRIPTION: Construct the AML operands for the DEFINITIONBLOCK ASL keyword
943 ******************************************************************************/
945 static void
946 OpnDoDefinitionBlock (
947 ACPI_PARSE_OBJECT *Op)
949 ACPI_PARSE_OBJECT *Child;
950 ACPI_SIZE Length;
951 ACPI_NATIVE_UINT i;
955 * These nodes get stuffed into the table header. They are special
956 * cased when the table is written to the output file.
958 * Mark all of these nodes as non-usable so they won't get output
959 * as AML opcodes!
962 /* Get AML filename. Use it if non-null */
964 Child = Op->Asl.Child;
965 if (Child->Asl.Value.Buffer &&
966 *Child->Asl.Value.Buffer &&
967 (Gbl_UseDefaultAmlFilename))
969 Gbl_OutputFilenamePrefix = (char *) Child->Asl.Value.Buffer;
971 Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
973 /* Signature */
975 Child = Child->Asl.Next;
976 Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
977 if (Child->Asl.Value.String)
979 Gbl_TableSignature = Child->Asl.Value.String;
980 if (ACPI_STRLEN (Gbl_TableSignature) != 4)
982 AslError (ASL_ERROR, ASL_MSG_TABLE_SIGNATURE, Child,
983 "Length not exactly 4");
986 for (i = 0; i < 4; i++)
988 if (!isalnum (Gbl_TableSignature[i]))
990 AslError (ASL_ERROR, ASL_MSG_TABLE_SIGNATURE, Child,
991 "Contains non-alphanumeric characters");
996 /* Revision */
998 Child = Child->Asl.Next;
999 Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
1001 * We used the revision to set the integer width earlier
1004 /* OEMID */
1006 Child = Child->Asl.Next;
1007 Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
1009 /* OEM TableID */
1011 Child = Child->Asl.Next;
1012 Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
1013 if (Child->Asl.Value.String)
1015 Length = ACPI_STRLEN (Child->Asl.Value.String);
1016 Gbl_TableId = AcpiOsAllocate (Length + 1);
1017 ACPI_STRCPY (Gbl_TableId, Child->Asl.Value.String);
1019 for (i = 0; i < Length; i++)
1021 if (Gbl_TableId[i] == ' ')
1023 Gbl_TableId[i] = 0;
1024 break;
1029 /* OEM Revision */
1031 Child = Child->Asl.Next;
1032 Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
1036 /*******************************************************************************
1038 * FUNCTION: UtGetArg
1040 * PARAMETERS: Op - Get an argument for this op
1041 * Argn - Nth argument to get
1043 * RETURN: The argument (as an Op object). NULL if argument does not exist
1045 * DESCRIPTION: Get the specified op's argument (peer)
1047 ******************************************************************************/
1049 ACPI_PARSE_OBJECT *
1050 UtGetArg (
1051 ACPI_PARSE_OBJECT *Op,
1052 UINT32 Argn)
1054 ACPI_PARSE_OBJECT *Arg = NULL;
1057 /* Get the requested argument object */
1059 Arg = Op->Asl.Child;
1060 while (Arg && Argn)
1062 Argn--;
1063 Arg = Arg->Asl.Next;
1066 return (Arg);
1070 /*******************************************************************************
1072 * FUNCTION: OpnAttachNameToNode
1074 * PARAMETERS: Op - The parent parse node
1076 * RETURN: None
1078 * DESCRIPTION: For the named ASL/AML operators, get the actual name from the
1079 * argument list and attach it to the parent node so that we
1080 * can get to it quickly later.
1082 ******************************************************************************/
1084 static void
1085 OpnAttachNameToNode (
1086 ACPI_PARSE_OBJECT *Op)
1088 ACPI_PARSE_OBJECT *Child = NULL;
1091 if (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL)
1093 Child = UtGetArg (Op, 0);
1095 else switch (Op->Asl.AmlOpcode)
1097 case AML_DATA_REGION_OP:
1098 case AML_DEVICE_OP:
1099 case AML_EVENT_OP:
1100 case AML_METHOD_OP:
1101 case AML_MUTEX_OP:
1102 case AML_REGION_OP:
1103 case AML_POWER_RES_OP:
1104 case AML_PROCESSOR_OP:
1105 case AML_THERMAL_ZONE_OP:
1106 case AML_NAME_OP:
1107 case AML_SCOPE_OP:
1109 Child = UtGetArg (Op, 0);
1110 break;
1112 case AML_ALIAS_OP:
1114 Child = UtGetArg (Op, 1);
1115 break;
1117 case AML_CREATE_BIT_FIELD_OP:
1118 case AML_CREATE_BYTE_FIELD_OP:
1119 case AML_CREATE_WORD_FIELD_OP:
1120 case AML_CREATE_DWORD_FIELD_OP:
1121 case AML_CREATE_QWORD_FIELD_OP:
1123 Child = UtGetArg (Op, 2);
1124 break;
1126 case AML_CREATE_FIELD_OP:
1128 Child = UtGetArg (Op, 3);
1129 break;
1131 case AML_BANK_FIELD_OP:
1132 case AML_INDEX_FIELD_OP:
1133 case AML_FIELD_OP:
1135 return;
1137 default:
1138 return;
1141 if (Child)
1143 UtAttachNamepathToOwner (Op, Child);
1148 /*******************************************************************************
1150 * FUNCTION: OpnGenerateAmlOperands
1152 * PARAMETERS: Op - The parent parse node
1154 * RETURN: None
1156 * DESCRIPTION: Prepare nodes to be output as AML data and operands. The more
1157 * complex AML opcodes require processing of the child nodes
1158 * (arguments/operands).
1160 ******************************************************************************/
1162 void
1163 OpnGenerateAmlOperands (
1164 ACPI_PARSE_OBJECT *Op)
1168 if (Op->Asl.AmlOpcode == AML_RAW_DATA_BYTE)
1170 return;
1173 switch (Op->Asl.ParseOpcode)
1175 case PARSEOP_DEFINITIONBLOCK:
1176 OpnDoDefinitionBlock (Op);
1177 break;
1179 case PARSEOP_METHOD:
1180 OpnDoMethod (Op);
1181 break;
1183 case PARSEOP_MUTEX:
1184 OpnDoMutex (Op);
1185 break;
1187 case PARSEOP_FIELD:
1188 OpnDoField (Op);
1189 break;
1191 case PARSEOP_INDEXFIELD:
1192 OpnDoIndexField (Op);
1193 break;
1195 case PARSEOP_BANKFIELD:
1196 OpnDoBankField (Op);
1197 break;
1199 case PARSEOP_BUFFER:
1200 OpnDoBuffer (Op);
1201 break;
1203 case PARSEOP_LOADTABLE:
1204 OpnDoLoadTable (Op);
1205 break;
1207 case PARSEOP_OPERATIONREGION:
1208 OpnDoRegion (Op);
1209 break;
1211 case PARSEOP_RESOURCETEMPLATE:
1212 RsDoResourceTemplate (Op);
1213 break;
1215 case PARSEOP_NAMESEG:
1216 case PARSEOP_NAMESTRING:
1217 case PARSEOP_METHODCALL:
1218 case PARSEOP_STRING_LITERAL:
1219 break;
1221 default:
1222 break;
1225 /* TBD: move */
1227 OpnAttachNameToNode (Op);