1 /******************************************************************************
3 * Module Name: aslfold - Constant folding
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2017, 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/amlcode.h>
156 #include <contrib/dev/acpica/include/acdispat.h>
157 #include <contrib/dev/acpica/include/acparser.h>
159 #define _COMPONENT ACPI_COMPILER
160 ACPI_MODULE_NAME ("aslfold")
162 /* Local prototypes */
165 OpcAmlEvaluationWalk1 (
166 ACPI_PARSE_OBJECT *Op,
171 OpcAmlEvaluationWalk2 (
172 ACPI_PARSE_OBJECT *Op,
177 OpcAmlCheckForConstant (
178 ACPI_PARSE_OBJECT *Op,
183 OpcUpdateIntegerNode (
184 ACPI_PARSE_OBJECT *Op,
188 TrTransformToStoreOp (
189 ACPI_PARSE_OBJECT *Op,
190 ACPI_WALK_STATE *WalkState);
193 TrSimpleConstantReduction (
194 ACPI_PARSE_OBJECT *Op,
195 ACPI_WALK_STATE *WalkState);
198 TrInstallReducedConstant (
199 ACPI_PARSE_OBJECT *Op,
200 ACPI_OPERAND_OBJECT *ObjDesc);
203 /*******************************************************************************
205 * FUNCTION: OpcAmlConstantWalk
207 * PARAMETERS: ASL_WALK_CALLBACK
211 * DESCRIPTION: Reduce an Op and its subtree to a constant if possible.
212 * Called during ascent of the parse tree.
214 ******************************************************************************/
218 ACPI_PARSE_OBJECT *Op,
222 ACPI_WALK_STATE *WalkState;
223 ACPI_STATUS Status = AE_OK;
226 if (Op->Asl.CompileFlags == 0)
232 * Only interested in subtrees that could possibly contain
233 * expressions that can be evaluated at this time
235 if ((!(Op->Asl.CompileFlags & NODE_COMPILE_TIME_CONST)) ||
236 (Op->Asl.CompileFlags & NODE_IS_TARGET))
241 /* Create a new walk state */
243 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
246 return (AE_NO_MEMORY);
249 WalkState->NextOp = NULL;
250 WalkState->Params = NULL;
253 * Examine the entire subtree -- all nodes must be constants
254 * or type 3/4/5 opcodes
256 Status = TrWalkParseTree (Op, ASL_WALK_VISIT_DOWNWARD,
257 OpcAmlCheckForConstant, NULL, WalkState);
260 * Did we find an entire subtree that contains all constants
261 * and type 3/4/5 opcodes?
267 /* Simple case, like Add(3,4) -> 7 */
269 Status = TrSimpleConstantReduction (Op, WalkState);
272 case AE_CTRL_RETURN_VALUE:
274 /* More complex case, like Add(3,4,Local0) -> Store(7,Local0) */
276 Status = TrTransformToStoreOp (Op, WalkState);
281 AcpiDsDeleteWalkState (WalkState);
285 AcpiDsDeleteWalkState (WalkState);
289 if (ACPI_FAILURE (Status))
291 DbgPrint (ASL_PARSE_OUTPUT, "Cannot resolve, %s\n",
292 AcpiFormatException (Status));
294 /* We could not resolve the subtree for some reason */
296 AslError (ASL_ERROR, ASL_MSG_CONSTANT_EVALUATION, Op,
297 (char *) AcpiFormatException (Status));
299 /* Set the subtree value to ZERO anyway. Eliminates further errors */
301 OpcUpdateIntegerNode (Op, 0);
308 /*******************************************************************************
310 * FUNCTION: OpcAmlCheckForConstant
312 * PARAMETERS: ASL_WALK_CALLBACK
316 * DESCRIPTION: Check one Op for a reducible type 3/4/5 AML opcode.
317 * This is performed via an upward walk of the parse subtree.
319 ******************************************************************************/
322 OpcAmlCheckForConstant (
323 ACPI_PARSE_OBJECT *Op,
327 ACPI_WALK_STATE *WalkState = Context;
328 ACPI_STATUS Status = AE_OK;
329 ACPI_PARSE_OBJECT *NextOp;
330 const ACPI_OPCODE_INFO *OpInfo;
334 WalkState->Opcode = Op->Common.AmlOpcode;
335 WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
337 DbgPrint (ASL_PARSE_OUTPUT, "[%.4d] Opcode: %12.12s ",
338 Op->Asl.LogicalLineNumber, Op->Asl.ParseOpName);
341 * These opcodes do not appear in the OpcodeInfo table, but
342 * they represent constants, so abort the constant walk now.
344 if ((WalkState->Opcode == AML_RAW_DATA_BYTE) ||
345 (WalkState->Opcode == AML_RAW_DATA_WORD) ||
346 (WalkState->Opcode == AML_RAW_DATA_DWORD) ||
347 (WalkState->Opcode == AML_RAW_DATA_QWORD))
349 DbgPrint (ASL_PARSE_OUTPUT, "RAW DATA");
355 * Search upwards for a possible Name() operator. This is done
356 * because a type 3/4/5 opcode within a Name() expression
357 * MUST be reduced to a simple constant.
359 NextOp = Op->Asl.Parent;
362 /* Finished if we find a Name() opcode */
364 if (NextOp->Asl.AmlOpcode == AML_NAME_OP)
370 * Any "deferred" opcodes contain one or more TermArg parameters,
371 * and thus are not required to be folded to constants at compile
372 * time. This affects things like Buffer() and Package() objects.
373 * We just ignore them here. However, any sub-expressions can and
374 * will still be typechecked. Note: These are called the
375 * "deferred" opcodes in the AML interpreter.
377 OpInfo = AcpiPsGetOpcodeInfo (NextOp->Common.AmlOpcode);
378 if (OpInfo->Flags & AML_DEFER)
384 NextOp = NextOp->Asl.Parent;
387 /* Type 3/4/5 opcodes have the AML_CONSTANT flag set */
389 if (!(WalkState->OpInfo->Flags & AML_CONSTANT))
392 * From the ACPI specification:
394 * "The Type 3/4/5 opcodes return a value and can be used in an
395 * expression that evaluates to a constant. These opcodes may be
396 * evaluated at ASL compile-time. To ensure that these opcodes
397 * will evaluate to a constant, the following rules apply: The
398 * term cannot have a destination (target) operand, and must have
399 * either a Type3Opcode, Type4Opcode, Type5Opcode, ConstExprTerm,
400 * Integer, BufferTerm, Package, or String for all arguments."
404 * The value (second) operand for the Name() operator MUST
405 * reduce to a single constant, as per the ACPI specification
406 * (the operand is a DataObject). This also implies that there
407 * can be no target operand. Name() is the only ASL operator
408 * with a "DataObject" as an operand and is thus special-
411 if (NextOp) /* Inspect a Name() operator */
413 /* Error if there is a target operand */
415 if (Op->Asl.CompileFlags & NODE_IS_TARGET)
417 AslError (ASL_ERROR, ASL_MSG_INVALID_TARGET, Op, NULL);
421 /* Error if expression cannot be reduced (folded) */
423 if (!(NextOp->Asl.CompileFlags & NODE_COULD_NOT_REDUCE))
425 /* Ensure only one error message per statement */
427 NextOp->Asl.CompileFlags |= NODE_COULD_NOT_REDUCE;
428 DbgPrint (ASL_PARSE_OUTPUT,
429 "**** Could not reduce operands for NAME opcode ****\n");
431 AslError (ASL_ERROR, ASL_MSG_CONSTANT_REQUIRED, Op,
432 "Constant is required for Name operator");
437 if (ACPI_FAILURE (Status))
442 /* This is not a 3/4/5 opcode, but maybe can convert to STORE */
444 if (Op->Asl.CompileFlags & NODE_IS_TARGET)
446 DbgPrint (ASL_PARSE_OUTPUT,
447 "**** Valid Target, transform to Store ****\n");
448 return (AE_CTRL_RETURN_VALUE);
451 /* Expression cannot be reduced */
453 DbgPrint (ASL_PARSE_OUTPUT,
454 "**** Not a Type 3/4/5 opcode or cannot reduce/fold (%s) ****\n",
455 Op->Asl.ParseOpName);
462 * TBD: Ignore buffer constants for now. The problem is that these
463 * constants have been transformed into RAW_DATA at this point, from
464 * the parse tree transform process which currently happens before
465 * the constant folding process. We may need to defer this transform
466 * for buffer until after the constant folding.
468 if (WalkState->Opcode == AML_BUFFER_OP)
470 DbgPrint (ASL_PARSE_OUTPUT,
471 "\nBuffer constant reduction is not supported yet\n");
473 if (NextOp) /* Found a Name() operator, error */
475 AslError (ASL_ERROR, ASL_MSG_UNSUPPORTED, Op,
476 "Buffer expression cannot be reduced");
485 DbgPrint (ASL_PARSE_OUTPUT, "TYPE_345");
487 if (Op->Asl.CompileFlags & NODE_IS_TARGET)
489 if (Op->Asl.ParseOpcode == PARSEOP_ZERO)
491 DbgPrint (ASL_PARSE_OUTPUT, "%-16s", " NULL TARGET");
495 DbgPrint (ASL_PARSE_OUTPUT, "%-16s", " VALID TARGET");
499 if (Op->Asl.CompileFlags & NODE_IS_TERM_ARG)
501 DbgPrint (ASL_PARSE_OUTPUT, "%-16s", " TERMARG");
506 /* Dump the node compile flags also */
508 TrPrintNodeCompileFlags (Op->Asl.CompileFlags);
509 DbgPrint (ASL_PARSE_OUTPUT, "\n");
514 /*******************************************************************************
516 * FUNCTION: TrSimpleConstantReduction
518 * PARAMETERS: Op - Parent operator to be transformed
519 * WalkState - Current walk state
523 * DESCRIPTION: Reduce an entire AML operation to a single constant. The
524 * operation must not have a target operand.
528 ******************************************************************************/
531 TrSimpleConstantReduction (
532 ACPI_PARSE_OBJECT *Op,
533 ACPI_WALK_STATE *WalkState)
535 ACPI_PARSE_OBJECT *RootOp;
536 ACPI_PARSE_OBJECT *OriginalParentOp;
537 ACPI_OPERAND_OBJECT *ObjDesc;
541 DbgPrint (ASL_PARSE_OUTPUT,
542 "Simple subtree constant reduction, operator to constant\n");
544 /* Allocate a new temporary root for this subtree */
546 RootOp = TrAllocateNode (PARSEOP_INTEGER);
549 return (AE_NO_MEMORY);
552 RootOp->Common.AmlOpcode = AML_INT_EVAL_SUBTREE_OP;
554 OriginalParentOp = Op->Common.Parent;
555 Op->Common.Parent = RootOp;
557 /* Hand off the subtree to the AML interpreter */
559 WalkState->CallerReturnDesc = &ObjDesc;
561 Status = TrWalkParseTree (Op, ASL_WALK_VISIT_TWICE,
562 OpcAmlEvaluationWalk1, OpcAmlEvaluationWalk2, WalkState);
564 /* Restore original parse tree */
566 Op->Common.Parent = OriginalParentOp;
568 if (ACPI_FAILURE (Status))
570 DbgPrint (ASL_PARSE_OUTPUT,
571 "Constant Subtree evaluation(1), %s\n",
572 AcpiFormatException (Status));
576 /* Get the final result */
578 Status = AcpiDsResultPop (&ObjDesc, WalkState);
579 if (ACPI_FAILURE (Status))
581 DbgPrint (ASL_PARSE_OUTPUT,
582 "Constant Subtree evaluation(2), %s\n",
583 AcpiFormatException (Status));
587 /* Disconnect any existing children, install new constant */
589 Op->Asl.Child = NULL;
590 TrInstallReducedConstant (Op, ObjDesc);
592 UtSetParseOpName (Op);
597 /*******************************************************************************
599 * FUNCTION: TrTransformToStoreOp
601 * PARAMETERS: Op - Parent operator to be transformed
602 * WalkState - Current walk state
606 * DESCRIPTION: Transforms a single AML operation with a constant and target
607 * to a simple store operation:
609 * Add (32,64,DATA) --> Store (96,DATA)
611 ******************************************************************************/
614 TrTransformToStoreOp (
615 ACPI_PARSE_OBJECT *Op,
616 ACPI_WALK_STATE *WalkState)
618 ACPI_PARSE_OBJECT *OriginalTarget;
619 ACPI_PARSE_OBJECT *NewTarget;
620 ACPI_PARSE_OBJECT *Child1;
621 ACPI_PARSE_OBJECT *Child2;
622 ACPI_OPERAND_OBJECT *ObjDesc;
623 ACPI_PARSE_OBJECT *NewParent;
624 ACPI_PARSE_OBJECT *OriginalParent;
628 /* Extract the operands */
630 Child1 = Op->Asl.Child;
631 Child2 = Child1->Asl.Next;
634 * Special case for DIVIDE -- it has two targets. The first
635 * is for the remainder and if present, we will not attempt
636 * to reduce the expression.
638 if (Op->Asl.ParseOpcode == PARSEOP_DIVIDE)
640 Child2 = Child2->Asl.Next;
641 if (Child2->Asl.ParseOpcode != PARSEOP_ZERO)
643 DbgPrint (ASL_PARSE_OUTPUT,
644 "Cannot reduce DIVIDE - has two targets\n\n");
649 DbgPrint (ASL_PARSE_OUTPUT,
650 "Reduction/Transform to StoreOp: Store(%s, %s)\n",
651 Child1->Asl.ParseOpName, Child2->Asl.ParseOpName);
654 * Create a NULL (zero) target so that we can use the
655 * interpreter to evaluate the expression.
657 NewTarget = TrCreateNullTarget ();
658 NewTarget->Common.AmlOpcode = AML_INT_NAMEPATH_OP;
660 /* Handle one-operand cases (NOT, TOBCD, etc.) */
662 if (!Child2->Asl.Next)
667 /* Link in new NULL target as the last operand */
669 OriginalTarget = Child2->Asl.Next;
670 Child2->Asl.Next = NewTarget;
671 NewTarget->Asl.Parent = OriginalTarget->Asl.Parent;
673 NewParent = TrAllocateNode (PARSEOP_INTEGER);
674 NewParent->Common.AmlOpcode = AML_INT_EVAL_SUBTREE_OP;
676 OriginalParent = Op->Common.Parent;
677 Op->Common.Parent = NewParent;
679 /* Hand off the subtree to the AML interpreter */
681 WalkState->CallerReturnDesc = &ObjDesc;
683 Status = TrWalkParseTree (Op, ASL_WALK_VISIT_TWICE,
684 OpcAmlEvaluationWalk1, OpcAmlEvaluationWalk2, WalkState);
685 if (ACPI_FAILURE (Status))
687 DbgPrint (ASL_PARSE_OUTPUT,
688 "Constant Subtree evaluation(3), %s\n",
689 AcpiFormatException (Status));
693 /* Get the final result */
695 Status = AcpiDsResultPop (&ObjDesc, WalkState);
696 if (ACPI_FAILURE (Status))
698 DbgPrint (ASL_PARSE_OUTPUT,
699 "Constant Subtree evaluation(4), %s\n",
700 AcpiFormatException (Status));
704 /* Truncate any subtree expressions, they have been evaluated */
706 Child1->Asl.Child = NULL;
708 /* Folded constant is in ObjDesc, store into Child1 */
710 TrInstallReducedConstant (Child1, ObjDesc);
712 /* Convert operator to STORE */
714 Op->Asl.ParseOpcode = PARSEOP_STORE;
715 Op->Asl.AmlOpcode = AML_STORE_OP;
716 UtSetParseOpName (Op);
717 Op->Common.Parent = OriginalParent;
719 /* First child is the folded constant */
721 /* Second child will be the target */
723 Child1->Asl.Next = OriginalTarget;
729 /* Restore original links */
731 Op->Common.Parent = OriginalParent;
732 Child2->Asl.Next = OriginalTarget;
737 /*******************************************************************************
739 * FUNCTION: TrInstallReducedConstant
741 * PARAMETERS: Op - Parent operator to be transformed
742 * ObjDesc - Reduced constant to be installed
746 * DESCRIPTION: Transform the original operator to a simple constant.
747 * Handles Integers, Strings, and Buffers.
749 ******************************************************************************/
752 TrInstallReducedConstant (
753 ACPI_PARSE_OBJECT *Op,
754 ACPI_OPERAND_OBJECT *ObjDesc)
756 ACPI_PARSE_OBJECT *LengthOp;
757 ACPI_PARSE_OBJECT *DataOp;
761 AslError (ASL_OPTIMIZATION, ASL_MSG_CONSTANT_FOLDED, Op,
762 Op->Asl.ParseOpName);
765 * Because we know we executed type 3/4/5 opcodes above, we know that
766 * the result must be either an Integer, String, or Buffer.
768 switch (ObjDesc->Common.Type)
770 case ACPI_TYPE_INTEGER:
772 OpcUpdateIntegerNode (Op, ObjDesc->Integer.Value);
774 DbgPrint (ASL_PARSE_OUTPUT,
775 "Constant expression reduced to (%s) %8.8X%8.8X\n\n",
777 ACPI_FORMAT_UINT64 (Op->Common.Value.Integer));
780 case ACPI_TYPE_STRING:
782 Op->Asl.ParseOpcode = PARSEOP_STRING_LITERAL;
783 Op->Common.AmlOpcode = AML_STRING_OP;
784 Op->Asl.AmlLength = strlen (ObjDesc->String.Pointer) + 1;
785 Op->Common.Value.String = ObjDesc->String.Pointer;
787 DbgPrint (ASL_PARSE_OUTPUT,
788 "Constant expression reduced to (STRING) %s\n\n",
789 Op->Common.Value.String);
792 case ACPI_TYPE_BUFFER:
794 * Create a new parse subtree of the form:
796 * BUFFER (Buffer AML opcode)
797 * INTEGER (Buffer length in bytes)
798 * RAW_DATA (Buffer byte data)
800 Op->Asl.ParseOpcode = PARSEOP_BUFFER;
801 Op->Common.AmlOpcode = AML_BUFFER_OP;
802 Op->Asl.CompileFlags = NODE_AML_PACKAGE;
803 UtSetParseOpName (Op);
805 /* Child node is the buffer length */
807 LengthOp = TrAllocateNode (PARSEOP_INTEGER);
809 LengthOp->Asl.AmlOpcode = AML_DWORD_OP;
810 LengthOp->Asl.Value.Integer = ObjDesc->Buffer.Length;
811 LengthOp->Asl.Parent = Op;
812 (void) OpcSetOptimalIntegerSize (LengthOp);
814 Op->Asl.Child = LengthOp;
816 /* Next child is the raw buffer data */
818 DataOp = TrAllocateNode (PARSEOP_RAW_DATA);
819 DataOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER;
820 DataOp->Asl.AmlLength = ObjDesc->Buffer.Length;
821 DataOp->Asl.Value.String = (char *) ObjDesc->Buffer.Pointer;
822 DataOp->Asl.Parent = Op;
824 LengthOp->Asl.Next = DataOp;
826 DbgPrint (ASL_PARSE_OUTPUT,
827 "Constant expression reduced to (BUFFER) length %X\n\n",
828 ObjDesc->Buffer.Length);
837 /*******************************************************************************
839 * FUNCTION: OpcUpdateIntegerNode
841 * PARAMETERS: Op - Current parse object
842 * Value - Value for the integer op
846 * DESCRIPTION: Update node to the correct Integer type and value
848 ******************************************************************************/
851 OpcUpdateIntegerNode (
852 ACPI_PARSE_OBJECT *Op,
856 Op->Common.Value.Integer = Value;
859 * The AmlLength is used by the parser to indicate a constant,
860 * (if non-zero). Length is either (1/2/4/8)
862 switch (Op->Asl.AmlLength)
866 TrUpdateNode (PARSEOP_BYTECONST, Op);
867 Op->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
872 TrUpdateNode (PARSEOP_WORDCONST, Op);
873 Op->Asl.AmlOpcode = AML_RAW_DATA_WORD;
878 TrUpdateNode (PARSEOP_DWORDCONST, Op);
879 Op->Asl.AmlOpcode = AML_RAW_DATA_DWORD;
884 TrUpdateNode (PARSEOP_QWORDCONST, Op);
885 Op->Asl.AmlOpcode = AML_RAW_DATA_QWORD;
891 OpcSetOptimalIntegerSize (Op);
892 TrUpdateNode (PARSEOP_INTEGER, Op);
896 Op->Asl.AmlLength = 0;
900 /*******************************************************************************
902 * FUNCTION: OpcAmlEvaluationWalk1
904 * PARAMETERS: ASL_WALK_CALLBACK
908 * DESCRIPTION: Descending callback for AML execution of constant subtrees
910 ******************************************************************************/
913 OpcAmlEvaluationWalk1 (
914 ACPI_PARSE_OBJECT *Op,
918 ACPI_WALK_STATE *WalkState = Context;
920 ACPI_PARSE_OBJECT *OutOp;
924 WalkState->Opcode = Op->Common.AmlOpcode;
925 WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
927 /* Copy child pointer to Arg for compatibility with Interpreter */
931 Op->Common.Value.Arg = Op->Asl.Child;
934 /* Call AML dispatcher */
936 Status = AcpiDsExecBeginOp (WalkState, &OutOp);
937 if (ACPI_FAILURE (Status))
939 DbgPrint (ASL_PARSE_OUTPUT,
940 "%s Constant interpretation failed (1) - %s\n",
941 Op->Asl.ParseOpName, AcpiFormatException (Status));
948 /*******************************************************************************
950 * FUNCTION: OpcAmlEvaluationWalk2
952 * PARAMETERS: ASL_WALK_CALLBACK
956 * DESCRIPTION: Ascending callback for AML execution of constant subtrees
958 ******************************************************************************/
961 OpcAmlEvaluationWalk2 (
962 ACPI_PARSE_OBJECT *Op,
966 ACPI_WALK_STATE *WalkState = Context;
971 WalkState->Opcode = Op->Common.AmlOpcode;
972 WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
974 /* Copy child pointer to Arg for compatibility with Interpreter */
978 Op->Common.Value.Arg = Op->Asl.Child;
981 /* Call AML dispatcher */
983 Status = AcpiDsExecEndOp (WalkState);
984 if (ACPI_FAILURE (Status))
986 DbgPrint (ASL_PARSE_OUTPUT,
987 "%s: Constant interpretation failed (2) - %s\n",
988 Op->Asl.ParseOpName, AcpiFormatException (Status));