1 /******************************************************************************
3 * Module Name: asltransform - Parse tree transforms
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2020, 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 <contrib/dev/acpica/compiler/aslcompiler.h>
153 #include "aslcompiler.y.h"
154 #include <contrib/dev/acpica/include/acnamesp.h>
156 #define _COMPONENT ACPI_COMPILER
157 ACPI_MODULE_NAME ("asltransform")
159 /* Local prototypes */
163 ACPI_PARSE_OBJECT *Op);
166 TrAmlGetNextTempName (
167 ACPI_PARSE_OBJECT *Op,
171 TrAmlInitLineNumbers (
172 ACPI_PARSE_OBJECT *Op,
173 ACPI_PARSE_OBJECT *Neighbor);
177 ACPI_PARSE_OBJECT *Op,
181 TrAmlSetSubtreeParent (
182 ACPI_PARSE_OBJECT *Op,
183 ACPI_PARSE_OBJECT *Parent);
187 ACPI_PARSE_OBJECT *Op,
188 ACPI_PARSE_OBJECT *NewPeer);
191 TrDoDefinitionBlock (
192 ACPI_PARSE_OBJECT *Op);
196 ACPI_PARSE_OBJECT *StartNode);
199 TrCheckForDuplicateCase (
200 ACPI_PARSE_OBJECT *CaseOp,
201 ACPI_PARSE_OBJECT *Predicate1);
204 TrCheckForBufferMatch (
205 ACPI_PARSE_OBJECT *Next1,
206 ACPI_PARSE_OBJECT *Next2);
210 ACPI_PARSE_OBJECT *Op);
213 /*******************************************************************************
215 * FUNCTION: TrAmlGetNextTempName
217 * PARAMETERS: Op - Current parse op
218 * TempCount - Current temporary counter. Was originally
219 * per-module; Currently per method, could be
220 * expanded to per-scope.
222 * RETURN: A pointer to name (allocated here).
224 * DESCRIPTION: Generate an ACPI name of the form _T_x. These names are
225 * reserved for use by the ASL compiler. (_T_0 through _T_Z)
227 ******************************************************************************/
230 TrAmlGetNextTempName (
231 ACPI_PARSE_OBJECT *Op,
237 if (*TempCount >= (10 + 26)) /* 0-35 valid: 0-9 and A-Z for TempName[3] */
241 AslError (ASL_ERROR, ASL_MSG_TOO_MANY_TEMPS, Op, NULL);
245 TempName = UtLocalCalloc (5);
247 if (*TempCount < 10) /* 0-9 */
249 TempName[3] = (char) (*TempCount + '0');
251 else /* 10-35: A-Z */
253 TempName[3] = (char) (*TempCount + ('A' - 10));
258 /* First three characters are always "_T_" */
268 /*******************************************************************************
270 * FUNCTION: TrAmlInitLineNumbers
272 * PARAMETERS: Op - Op to be initialized
273 * Neighbor - Op used for initialization values
277 * DESCRIPTION: Initialized the various line numbers for a parse node.
279 ******************************************************************************/
282 TrAmlInitLineNumbers (
283 ACPI_PARSE_OBJECT *Op,
284 ACPI_PARSE_OBJECT *Neighbor)
287 Op->Asl.EndLine = Neighbor->Asl.EndLine;
288 Op->Asl.EndLogicalLine = Neighbor->Asl.EndLogicalLine;
289 Op->Asl.LineNumber = Neighbor->Asl.LineNumber;
290 Op->Asl.LogicalByteOffset = Neighbor->Asl.LogicalByteOffset;
291 Op->Asl.LogicalLineNumber = Neighbor->Asl.LogicalLineNumber;
295 /*******************************************************************************
297 * FUNCTION: TrAmlInitNode
299 * PARAMETERS: Op - Op to be initialized
300 * ParseOpcode - Opcode for this node
304 * DESCRIPTION: Initialize a node with the parse opcode and opcode name.
306 ******************************************************************************/
310 ACPI_PARSE_OBJECT *Op,
314 Op->Asl.ParseOpcode = ParseOpcode;
315 UtSetParseOpName (Op);
319 /*******************************************************************************
321 * FUNCTION: TrAmlSetSubtreeParent
323 * PARAMETERS: Op - First node in a list of peer nodes
324 * Parent - Parent of the subtree
328 * DESCRIPTION: Set the parent for all peer nodes in a subtree
330 ******************************************************************************/
333 TrAmlSetSubtreeParent (
334 ACPI_PARSE_OBJECT *Op,
335 ACPI_PARSE_OBJECT *Parent)
337 ACPI_PARSE_OBJECT *Next;
343 Next->Asl.Parent = Parent;
344 Next = Next->Asl.Next;
349 /*******************************************************************************
351 * FUNCTION: TrAmlInsertPeer
353 * PARAMETERS: Op - First node in a list of peer nodes
354 * NewPeer - Peer node to insert
358 * DESCRIPTION: Insert a new peer node into a list of peers.
360 ******************************************************************************/
364 ACPI_PARSE_OBJECT *Op,
365 ACPI_PARSE_OBJECT *NewPeer)
368 NewPeer->Asl.Next = Op->Asl.Next;
369 Op->Asl.Next = NewPeer;
373 /*******************************************************************************
375 * FUNCTION: TrAmlTransformWalkBegin
377 * PARAMETERS: ASL_WALK_CALLBACK
381 * DESCRIPTION: Parse tree walk to generate both the AML opcodes and the AML
384 ******************************************************************************/
387 TrAmlTransformWalkBegin (
388 ACPI_PARSE_OBJECT *Op,
393 TrTransformSubtree (Op);
398 /*******************************************************************************
400 * FUNCTION: TrAmlTransformWalkEnd
402 * PARAMETERS: ASL_WALK_CALLBACK
406 * DESCRIPTION: Parse tree walk to generate both the AML opcodes and the AML
409 ******************************************************************************/
412 TrAmlTransformWalkEnd (
413 ACPI_PARSE_OBJECT *Op,
418 /* Save possible Externals list in the DefintionBlock Op */
420 if (Op->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK)
422 Op->Asl.Value.Arg = AslGbl_ExternalsListHead;
423 AslGbl_ExternalsListHead = NULL;
430 /*******************************************************************************
432 * FUNCTION: TrTransformSubtree
434 * PARAMETERS: Op - The parent parse node
438 * DESCRIPTION: Prepare nodes to be output as AML data and operands. The more
439 * complex AML opcodes require processing of the child nodes
440 * (arguments/operands).
442 ******************************************************************************/
446 ACPI_PARSE_OBJECT *Op)
448 ACPI_PARSE_OBJECT *MethodOp;
449 ACPI_NAMESTRING_INFO Info;
452 if (Op->Asl.AmlOpcode == AML_RAW_DATA_BYTE)
457 switch (Op->Asl.ParseOpcode)
459 case PARSEOP_DEFINITION_BLOCK:
461 TrDoDefinitionBlock (Op);
474 case PARSEOP_EXTERNAL:
479 case PARSEOP___METHOD__:
481 /* Transform to a string op containing the parent method name */
483 Op->Asl.ParseOpcode = PARSEOP_STRING_LITERAL;
484 UtSetParseOpName (Op);
486 /* Find the parent control method op */
491 if (MethodOp->Asl.ParseOpcode == PARSEOP_METHOD)
493 /* First child contains the method name */
495 MethodOp = MethodOp->Asl.Child;
496 Op->Asl.Value.String = MethodOp->Asl.Value.String;
500 MethodOp = MethodOp->Asl.Parent;
503 /* At the root, invocation not within a control method */
505 Op->Asl.Value.String = "\\";
508 case PARSEOP_NAMESTRING:
510 * A NameString can be up to 255 (0xFF) individual NameSegs maximum
511 * (with 254 dot separators) - as per the ACPI specification. Note:
512 * Cannot check for NumSegments == 0 because things like
513 * Scope(\) are legal and OK.
515 Info.ExternalName = Op->Asl.Value.String;
516 AcpiNsGetInternalNameLength (&Info);
518 if (Info.NumSegments > 255)
520 AslError (ASL_ERROR, ASL_MSG_NAMESTRING_LENGTH, Op, NULL);
526 AslError (ASL_WARNING, ASL_MSG_UNLOAD, Op, NULL);
531 /* Remark for very long sleep values */
533 if (Op->Asl.Child->Asl.Value.Integer > 1000)
535 AslError (ASL_REMARK, ASL_MSG_LONG_SLEEP, Op, NULL);
539 case PARSEOP_PROCESSOR:
541 AslError (ASL_WARNING, ASL_MSG_LEGACY_PROCESSOR_OP, Op, Op->Asl.ExternalName);
546 /* Nothing to do here for other opcodes */
553 /*******************************************************************************
555 * FUNCTION: TrDoDefinitionBlock
557 * PARAMETERS: Op - Parse node
561 * DESCRIPTION: Find the end of the definition block and set a global to this
562 * node. It is used by the compiler to insert compiler-generated
563 * names at the root level of the namespace.
565 ******************************************************************************/
568 TrDoDefinitionBlock (
569 ACPI_PARSE_OBJECT *Op)
571 ACPI_PARSE_OBJECT *Next;
575 /* Reset external list when starting a definition block */
577 AslGbl_ExternalsListHead = NULL;
579 Next = Op->Asl.Child;
580 for (i = 0; i < 5; i++)
582 Next = Next->Asl.Next;
586 * This is the table signature. Only the DSDT can be assumed
587 * to be at the root of the namespace; Therefore, namepath
588 * optimization can only be performed on the DSDT.
590 if (!ACPI_COMPARE_NAMESEG (Next->Asl.Value.String, ACPI_SIG_DSDT))
592 AslGbl_ReferenceOptimizationFlag = FALSE;
597 AslGbl_FirstLevelInsertionNode = Next;
601 /*******************************************************************************
603 * FUNCTION: TrDoSwitch
605 * PARAMETERS: StartNode - Parse node for SWITCH
609 * DESCRIPTION: Translate ASL SWITCH statement to if/else pairs. There is
610 * no actual AML opcode for SWITCH -- it must be simulated.
612 ******************************************************************************/
616 ACPI_PARSE_OBJECT *StartNode)
618 ACPI_PARSE_OBJECT *Next;
619 ACPI_PARSE_OBJECT *CaseOp = NULL;
620 ACPI_PARSE_OBJECT *CaseBlock = NULL;
621 ACPI_PARSE_OBJECT *DefaultOp = NULL;
622 ACPI_PARSE_OBJECT *CurrentParentNode;
623 ACPI_PARSE_OBJECT *Conditional = NULL;
624 ACPI_PARSE_OBJECT *Predicate;
625 ACPI_PARSE_OBJECT *Peer;
626 ACPI_PARSE_OBJECT *NewOp;
627 ACPI_PARSE_OBJECT *NewOp2;
628 ACPI_PARSE_OBJECT *MethodOp;
629 ACPI_PARSE_OBJECT *StoreOp;
630 ACPI_PARSE_OBJECT *BreakOp;
631 ACPI_PARSE_OBJECT *BufferOp;
632 char *PredicateValueName;
637 /* Start node is the Switch() node */
639 CurrentParentNode = StartNode;
641 /* Create a new temp name of the form _T_x */
643 PredicateValueName = TrAmlGetNextTempName (StartNode, &AslGbl_TempCount);
644 if (!PredicateValueName)
649 /* First child is the Switch() predicate */
651 Next = StartNode->Asl.Child;
654 * Examine the return type of the Switch Value -
655 * must be Integer/Buffer/String
657 Index = (UINT16) (Next->Asl.ParseOpcode - ASL_PARSE_OPCODE_BASE);
658 Btype = AslKeywordMapping[Index].AcpiBtype;
659 if ((Btype != ACPI_BTYPE_INTEGER) &&
660 (Btype != ACPI_BTYPE_STRING) &&
661 (Btype != ACPI_BTYPE_BUFFER))
663 AslError (ASL_WARNING, ASL_MSG_SWITCH_TYPE, Next, NULL);
664 Btype = ACPI_BTYPE_INTEGER;
667 /* CASE statements start at next child */
669 Peer = Next->Asl.Next;
673 Peer = Next->Asl.Next;
675 if (Next->Asl.ParseOpcode == PARSEOP_CASE)
677 TrCheckForDuplicateCase (Next, Next->Asl.Child);
681 /* Add an ELSE to complete the previous CASE */
683 NewOp = TrCreateLeafOp (PARSEOP_ELSE);
684 NewOp->Asl.Parent = Conditional->Asl.Parent;
685 TrAmlInitLineNumbers (NewOp, NewOp->Asl.Parent);
687 /* Link ELSE node as a peer to the previous IF */
689 TrAmlInsertPeer (Conditional, NewOp);
690 CurrentParentNode = NewOp;
694 Conditional = CaseOp;
695 CaseBlock = CaseOp->Asl.Child->Asl.Next;
696 Conditional->Asl.Child->Asl.Next = NULL;
697 Predicate = CaseOp->Asl.Child;
699 if ((Predicate->Asl.ParseOpcode == PARSEOP_PACKAGE) ||
700 (Predicate->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE))
703 * Convert the package declaration to this form:
705 * If (LNotEqual (Match (Package(<size>){<data>},
706 * MEQ, _T_x, MTR, Zero, Zero), Ones))
708 NewOp2 = TrCreateLeafOp (PARSEOP_MATCHTYPE_MEQ);
709 Predicate->Asl.Next = NewOp2;
710 TrAmlInitLineNumbers (NewOp2, Conditional);
713 NewOp2 = TrCreateValuedLeafOp (PARSEOP_NAMESTRING,
714 (UINT64) ACPI_TO_INTEGER (PredicateValueName));
715 NewOp->Asl.Next = NewOp2;
716 TrAmlInitLineNumbers (NewOp2, Predicate);
719 NewOp2 = TrCreateLeafOp (PARSEOP_MATCHTYPE_MTR);
720 NewOp->Asl.Next = NewOp2;
721 TrAmlInitLineNumbers (NewOp2, Predicate);
724 NewOp2 = TrCreateLeafOp (PARSEOP_ZERO);
725 NewOp->Asl.Next = NewOp2;
726 TrAmlInitLineNumbers (NewOp2, Predicate);
729 NewOp2 = TrCreateLeafOp (PARSEOP_ZERO);
730 NewOp->Asl.Next = NewOp2;
731 TrAmlInitLineNumbers (NewOp2, Predicate);
733 NewOp2 = TrCreateLeafOp (PARSEOP_MATCH);
734 NewOp2->Asl.Child = Predicate; /* PARSEOP_PACKAGE */
735 TrAmlInitLineNumbers (NewOp2, Conditional);
736 TrAmlSetSubtreeParent (Predicate, NewOp2);
739 NewOp2 = TrCreateLeafOp (PARSEOP_ONES);
740 NewOp->Asl.Next = NewOp2;
741 TrAmlInitLineNumbers (NewOp2, Conditional);
743 NewOp2 = TrCreateLeafOp (PARSEOP_LEQUAL);
744 NewOp2->Asl.Child = NewOp;
745 NewOp->Asl.Parent = NewOp2;
746 TrAmlInitLineNumbers (NewOp2, Conditional);
747 TrAmlSetSubtreeParent (NewOp, NewOp2);
750 NewOp2 = TrCreateLeafOp (PARSEOP_LNOT);
751 NewOp2->Asl.Child = NewOp;
752 NewOp2->Asl.Parent = Conditional;
753 NewOp->Asl.Parent = NewOp2;
754 TrAmlInitLineNumbers (NewOp2, Conditional);
756 Conditional->Asl.Child = NewOp2;
757 NewOp2->Asl.Next = CaseBlock;
762 * Integer and Buffer case.
764 * Change CaseOp() to: If (LEqual (SwitchValue, CaseValue)) {...}
765 * Note: SwitchValue is first to allow the CaseValue to be implicitly
766 * converted to the type of SwitchValue if necessary.
768 * CaseOp->Child is the case value
769 * CaseOp->Child->Peer is the beginning of the case block
771 NewOp = TrCreateValuedLeafOp (PARSEOP_NAMESTRING,
772 (UINT64) ACPI_TO_INTEGER (PredicateValueName));
773 NewOp->Asl.Next = Predicate;
774 TrAmlInitLineNumbers (NewOp, Predicate);
776 NewOp2 = TrCreateLeafOp (PARSEOP_LEQUAL);
777 NewOp2->Asl.Parent = Conditional;
778 NewOp2->Asl.Child = NewOp;
779 TrAmlInitLineNumbers (NewOp2, Conditional);
781 TrAmlSetSubtreeParent (NewOp, NewOp2);
784 Predicate->Asl.Next = CaseBlock;
786 TrAmlSetSubtreeParent (Predicate, Conditional);
787 Conditional->Asl.Child = Predicate;
790 /* Reinitialize the CASE node to an IF node */
792 TrAmlInitNode (Conditional, PARSEOP_IF);
795 * The first CASE(IF) is not nested under an ELSE.
796 * All other CASEs are children of a parent ELSE.
798 if (CurrentParentNode == StartNode)
800 Conditional->Asl.Next = NULL;
805 * The IF is a child of previous IF/ELSE. It
806 * is therefore without peer.
808 CurrentParentNode->Asl.Child = Conditional;
809 Conditional->Asl.Parent = CurrentParentNode;
810 Conditional->Asl.Next = NULL;
813 else if (Next->Asl.ParseOpcode == PARSEOP_DEFAULT)
818 * More than one Default
819 * (Parser does not catch this, must check here)
821 AslError (ASL_ERROR, ASL_MSG_MULTIPLE_DEFAULT, Next, NULL);
825 /* Save the DEFAULT node for later, after CASEs */
832 /* Unknown peer opcode */
834 AcpiOsPrintf ("Unknown parse opcode for switch statement: %s (%u)\n",
835 Next->Asl.ParseOpName, Next->Asl.ParseOpcode);
839 /* Add the default case at the end of the if/else construct */
843 /* If no CASE statements, this is an error - see below */
847 /* Convert the DEFAULT node to an ELSE */
849 TrAmlInitNode (DefaultOp, PARSEOP_ELSE);
850 DefaultOp->Asl.Parent = Conditional->Asl.Parent;
852 /* Link ELSE node as a peer to the previous IF */
854 TrAmlInsertPeer (Conditional, DefaultOp);
860 AslError (ASL_ERROR, ASL_MSG_NO_CASES, StartNode, NULL);
865 * Create a Name(_T_x, ...) statement. This statement must appear at the
866 * method level, in case a loop surrounds the switch statement and could
867 * cause the name to be created twice (error).
870 /* Create the Name node */
872 Predicate = StartNode->Asl.Child;
873 NewOp = TrCreateLeafOp (PARSEOP_NAME);
874 TrAmlInitLineNumbers (NewOp, StartNode);
876 /* Find the parent method */
879 while ((Next->Asl.ParseOpcode != PARSEOP_METHOD) &&
880 (Next->Asl.ParseOpcode != PARSEOP_DEFINITION_BLOCK))
882 Next = Next->Asl.Parent;
886 NewOp->Asl.CompileFlags |= OP_COMPILER_EMITTED;
887 NewOp->Asl.Parent = Next;
889 /* Insert name after the method name and arguments */
891 Next = Next->Asl.Child; /* Name */
892 Next = Next->Asl.Next; /* NumArgs */
893 Next = Next->Asl.Next; /* SerializeRule */
896 * If method is not Serialized, we must make is so, because of the way
897 * that Switch() must be implemented -- we cannot allow multiple threads
898 * to execute this method concurrently since we need to create local
901 if (Next->Asl.ParseOpcode != PARSEOP_SERIALIZERULE_SERIAL)
903 AslError (ASL_REMARK, ASL_MSG_SERIALIZED, MethodOp,
904 "Due to use of Switch operator");
905 Next->Asl.ParseOpcode = PARSEOP_SERIALIZERULE_SERIAL;
908 Next = Next->Asl.Next; /* SyncLevel */
909 Next = Next->Asl.Next; /* ReturnType */
910 Next = Next->Asl.Next; /* ParameterTypes */
912 TrAmlInsertPeer (Next, NewOp);
913 TrAmlInitLineNumbers (NewOp, Next);
915 /* Create the NameSeg child for the Name node */
917 NewOp2 = TrCreateValuedLeafOp (PARSEOP_NAMESEG,
918 (UINT64) ACPI_TO_INTEGER (PredicateValueName));
919 TrAmlInitLineNumbers (NewOp2, NewOp);
920 NewOp2->Asl.CompileFlags |= OP_IS_NAME_DECLARATION;
921 NewOp->Asl.Child = NewOp2;
923 /* Create the initial value for the Name. Btype was already validated above */
927 case ACPI_BTYPE_INTEGER:
929 NewOp2->Asl.Next = TrCreateValuedLeafOp (PARSEOP_ZERO,
931 TrAmlInitLineNumbers (NewOp2->Asl.Next, NewOp);
934 case ACPI_BTYPE_STRING:
936 NewOp2->Asl.Next = TrCreateValuedLeafOp (PARSEOP_STRING_LITERAL,
937 (UINT64) ACPI_TO_INTEGER (""));
938 TrAmlInitLineNumbers (NewOp2->Asl.Next, NewOp);
941 case ACPI_BTYPE_BUFFER:
943 (void) TrLinkPeerOp (NewOp2, TrCreateValuedLeafOp (PARSEOP_BUFFER,
945 Next = NewOp2->Asl.Next;
946 TrAmlInitLineNumbers (Next, NewOp2);
948 (void) TrLinkOpChildren (Next, 1, TrCreateValuedLeafOp (PARSEOP_ZERO,
950 TrAmlInitLineNumbers (Next->Asl.Child, Next);
952 BufferOp = TrCreateValuedLeafOp (PARSEOP_DEFAULT_ARG, (UINT64) 0);
953 TrAmlInitLineNumbers (BufferOp, Next->Asl.Child);
954 (void) TrLinkPeerOp (Next->Asl.Child, BufferOp);
956 TrAmlSetSubtreeParent (Next->Asl.Child, Next);
964 TrAmlSetSubtreeParent (NewOp2, NewOp);
967 * Transform the Switch() into a While(One)-Break node.
968 * And create a Store() node which will be used to save the
969 * Switch() value. The store is of the form: Store (Value, _T_x)
970 * where _T_x is the temp variable.
972 TrAmlInitNode (StartNode, PARSEOP_WHILE);
973 NewOp = TrCreateLeafOp (PARSEOP_ONE);
974 TrAmlInitLineNumbers (NewOp, StartNode);
975 NewOp->Asl.Next = Predicate->Asl.Next;
976 NewOp->Asl.Parent = StartNode;
977 StartNode->Asl.Child = NewOp;
979 /* Create a Store() node */
981 StoreOp = TrCreateLeafOp (PARSEOP_STORE);
982 TrAmlInitLineNumbers (StoreOp, NewOp);
983 StoreOp->Asl.Parent = StartNode;
984 TrAmlInsertPeer (NewOp, StoreOp);
986 /* Complete the Store subtree */
988 StoreOp->Asl.Child = Predicate;
989 Predicate->Asl.Parent = StoreOp;
991 NewOp = TrCreateValuedLeafOp (PARSEOP_NAMESEG,
992 (UINT64) ACPI_TO_INTEGER (PredicateValueName));
993 TrAmlInitLineNumbers (NewOp, StoreOp);
994 NewOp->Asl.Parent = StoreOp;
995 Predicate->Asl.Next = NewOp;
997 /* Create a Break() node and insert it into the end of While() */
999 Conditional = StartNode->Asl.Child;
1000 while (Conditional->Asl.Next)
1002 Conditional = Conditional->Asl.Next;
1005 BreakOp = TrCreateLeafOp (PARSEOP_BREAK);
1006 TrAmlInitLineNumbers (BreakOp, NewOp);
1007 BreakOp->Asl.Parent = StartNode;
1008 TrAmlInsertPeer (Conditional, BreakOp);
1012 /*******************************************************************************
1014 * FUNCTION: TrCheckForDuplicateCase
1016 * PARAMETERS: CaseOp - Parse node for first Case statement in list
1017 * Predicate1 - Case value for the input CaseOp
1021 * DESCRIPTION: Check for duplicate case values. Currently, only handles
1022 * Integers, Strings and Buffers. No support for Package objects.
1024 ******************************************************************************/
1027 TrCheckForDuplicateCase (
1028 ACPI_PARSE_OBJECT *CaseOp,
1029 ACPI_PARSE_OBJECT *Predicate1)
1031 ACPI_PARSE_OBJECT *Next;
1032 ACPI_PARSE_OBJECT *Predicate2;
1035 /* Walk the list of CASE opcodes */
1037 Next = CaseOp->Asl.Next;
1040 if (Next->Asl.ParseOpcode == PARSEOP_CASE)
1042 /* Emit error only once */
1044 if (Next->Asl.CompileFlags & OP_IS_DUPLICATE)
1049 /* Check for a duplicate plain integer */
1051 Predicate2 = Next->Asl.Child;
1052 if ((Predicate1->Asl.ParseOpcode == PARSEOP_INTEGER) &&
1053 (Predicate2->Asl.ParseOpcode == PARSEOP_INTEGER))
1055 if (Predicate1->Asl.Value.Integer == Predicate2->Asl.Value.Integer)
1057 goto FoundDuplicate;
1061 /* Check for pairs of the constants ZERO, ONE, ONES */
1063 else if (((Predicate1->Asl.ParseOpcode == PARSEOP_ZERO) &&
1064 (Predicate2->Asl.ParseOpcode == PARSEOP_ZERO)) ||
1065 ((Predicate1->Asl.ParseOpcode == PARSEOP_ONE) &&
1066 (Predicate2->Asl.ParseOpcode == PARSEOP_ONE)) ||
1067 ((Predicate1->Asl.ParseOpcode == PARSEOP_ONES) &&
1068 (Predicate2->Asl.ParseOpcode == PARSEOP_ONES)))
1070 goto FoundDuplicate;
1073 /* Check for a duplicate string constant (literal) */
1075 else if ((Predicate1->Asl.ParseOpcode == PARSEOP_STRING_LITERAL) &&
1076 (Predicate2->Asl.ParseOpcode == PARSEOP_STRING_LITERAL))
1078 if (!strcmp (Predicate1->Asl.Value.String,
1079 Predicate2->Asl.Value.String))
1081 goto FoundDuplicate;
1085 /* Check for a duplicate buffer constant */
1087 else if ((Predicate1->Asl.ParseOpcode == PARSEOP_BUFFER) &&
1088 (Predicate2->Asl.ParseOpcode == PARSEOP_BUFFER))
1090 if (TrCheckForBufferMatch (Predicate1->Asl.Child,
1091 Predicate2->Asl.Child))
1093 goto FoundDuplicate;
1100 /* Emit error message only once */
1102 Next->Asl.CompileFlags |= OP_IS_DUPLICATE;
1104 AslDualParseOpError (ASL_ERROR, ASL_MSG_DUPLICATE_CASE, Next,
1105 Next->Asl.Value.String, ASL_MSG_CASE_FOUND_HERE, CaseOp,
1106 CaseOp->Asl.ExternalName);
1109 Next = Next->Asl.Next;
1113 /*******************************************************************************
1115 * FUNCTION: TrBufferIsAllZero
1117 * PARAMETERS: Op - Parse node for first opcode in buffer initializer
1120 * RETURN: TRUE if buffer contains all zeros or a DEFAULT_ARG
1122 * DESCRIPTION: Check for duplicate Buffer case values.
1124 ******************************************************************************/
1128 ACPI_PARSE_OBJECT *Op)
1132 if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
1136 else if (Op->Asl.Value.Integer != 0)
1148 /*******************************************************************************
1150 * FUNCTION: TrCheckForBufferMatch
1152 * PARAMETERS: Next1 - Parse node for first opcode in first buffer list
1153 * (The DEFAULT_ARG or INTEGER node)
1154 * Next2 - Parse node for first opcode in second buffer list
1155 * (The DEFAULT_ARG or INTEGER node)
1157 * RETURN: TRUE if buffers match, FALSE otherwise
1159 * DESCRIPTION: Check for duplicate Buffer case values.
1161 ******************************************************************************/
1164 TrCheckForBufferMatch (
1165 ACPI_PARSE_OBJECT *NextOp1,
1166 ACPI_PARSE_OBJECT *NextOp2)
1169 * The buffer length can be a DEFAULT_ARG or INTEGER. If any of the nodes
1170 * are DEFAULT_ARG, it means that the length has yet to be computed.
1171 * However, the initializer list can be compared to determine if these two
1174 if ((NextOp1->Asl.ParseOpcode == PARSEOP_INTEGER &&
1175 NextOp2->Asl.ParseOpcode == PARSEOP_INTEGER) &&
1176 NextOp1->Asl.Value.Integer != NextOp2->Asl.Value.Integer)
1182 * Buffers that have explicit lengths but no initializer lists are
1183 * filled with zeros at runtime. This is equivalent to buffers that have the
1184 * same length that are filled with zeros.
1186 * In other words, the following buffers are equivalent:
1189 * Buffer() {0x0, 0x0, 0x0, 0x0}
1191 * This statement checks for matches where one buffer does not have an
1192 * initializer list and another buffer contains all zeros.
1194 if (NextOp1->Asl.ParseOpcode != NextOp2->Asl.ParseOpcode &&
1195 TrBufferIsAllZero (NextOp1->Asl.Next) &&
1196 TrBufferIsAllZero (NextOp2->Asl.Next))
1201 /* Start at the BYTECONST initializer node list */
1203 NextOp1 = NextOp1->Asl.Next;
1204 NextOp2 = NextOp2->Asl.Next;
1207 * Walk both lists until either a mismatch is found, or one or more
1208 * end-of-lists are found
1210 while (NextOp1 && NextOp2)
1212 if ((NextOp1->Asl.ParseOpcode == PARSEOP_STRING_LITERAL) &&
1213 (NextOp2->Asl.ParseOpcode == PARSEOP_STRING_LITERAL))
1215 if (!strcmp (NextOp1->Asl.Value.String, NextOp2->Asl.Value.String))
1224 if ((UINT8) NextOp1->Asl.Value.Integer != (UINT8) NextOp2->Asl.Value.Integer)
1229 NextOp1 = NextOp1->Asl.Next;
1230 NextOp2 = NextOp2->Asl.Next;
1233 /* Not a match if one of the lists is not at end-of-list */
1235 if (NextOp1 || NextOp2)
1240 /* Otherwise, the buffers match */
1246 /*******************************************************************************
1248 * FUNCTION: TrDoMethod
1250 * PARAMETERS: Op - Parse node for SWITCH
1254 * DESCRIPTION: Determine that parameter count of an ASL method node by
1255 * translating the parameter count parse node from
1256 * PARSEOP_DEFAULT_ARG to PARSEOP_BYTECONST.
1258 ******************************************************************************/
1262 ACPI_PARSE_OBJECT *Op)
1264 ACPI_PARSE_OBJECT *ArgCountOp;
1266 ACPI_PARSE_OBJECT *ParameterOp;
1270 * TBD: Zero the tempname (_T_x) count. Probably shouldn't be a global,
1273 AslGbl_TempCount = 0;
1275 ArgCountOp = Op->Asl.Child->Asl.Next;
1276 if (ArgCountOp->Asl.ParseOpcode == PARSEOP_BYTECONST)
1279 * Parameter count for this method has already been recorded in the
1280 * method declaration.
1286 * Parameter count has been omitted in the method declaration.
1287 * Count the amount of arguments here.
1289 ParameterOp = ArgCountOp->Asl.Next->Asl.Next->Asl.Next->Asl.Next;
1290 if (ParameterOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
1293 ParameterOp = ParameterOp->Asl.Child;
1297 ParameterOp = ParameterOp->Asl.Next;
1301 ArgCountOp->Asl.Value.Integer = ArgCount;
1302 ArgCountOp->Asl.ParseOpcode = PARSEOP_BYTECONST;
1307 * Method parameters can be counted by analyzing the Parameter type
1308 * list. If the Parameter list contains more than 1 parameter, it
1309 * is nested under PARSEOP_DEFAULT_ARG. When there is only 1
1310 * parameter, the parse tree contains a single node representing
1313 ArgCountOp->Asl.Value.Integer = 1;
1314 ArgCountOp->Asl.ParseOpcode = PARSEOP_BYTECONST;