ACPI_PARSE_OBJECT * AcpiPsGetChild ( ACPI_PARSE_OBJECT *Op) { ACPI_PARSE_OBJECT *Child = NULL; ACPI_FUNCTION_ENTRY (); switch (Op->Common.AmlOpcode) { case AML_SCOPE_OP: case AML_ELSE_OP: case AML_DEVICE_OP: case AML_THERMAL_ZONE_OP: case AML_INT_METHODCALL_OP: Child = AcpiPsGetArg (Op, 0); break; case AML_BUFFER_OP: case AML_PACKAGE_OP: case AML_METHOD_OP: case AML_IF_OP: case AML_WHILE_OP: case AML_FIELD_OP: Child = AcpiPsGetArg (Op, 1); break; case AML_POWER_RES_OP: case AML_INDEX_FIELD_OP: Child = AcpiPsGetArg (Op, 2); break; case AML_PROCESSOR_OP: case AML_BANK_FIELD_OP: Child = AcpiPsGetArg (Op, 3); break; default: /* All others have no children */ break; } return (Child); }
void AcpiPsDeleteParseTree ( ACPI_PARSE_OBJECT *SubtreeRoot) { ACPI_PARSE_OBJECT *Op = SubtreeRoot; ACPI_PARSE_OBJECT *Next = NULL; ACPI_PARSE_OBJECT *Parent = NULL; ACPI_FUNCTION_TRACE_PTR (PsDeleteParseTree, SubtreeRoot); /* Visit all nodes in the subtree */ while (Op) { /* Check if we are not ascending */ if (Op != Parent) { /* Look for an argument or child of the current op */ Next = AcpiPsGetArg (Op, 0); if (Next) { /* Still going downward in tree (Op is not completed yet) */ Op = Next; continue; } } /* No more children, this Op is complete. */ Next = Op->Common.Next; Parent = Op->Common.Parent; AcpiPsFreeOp (Op); /* If we are back to the starting point, the walk is complete. */ if (Op == SubtreeRoot) { return_VOID; } if (Next) { Op = Next; } else { Op = Parent; } } return_VOID; }
ACPI_STATUS AcpiDsEvalBankFieldOperands ( ACPI_WALK_STATE *WalkState, ACPI_PARSE_OBJECT *Op) { ACPI_STATUS Status; ACPI_OPERAND_OBJECT *ObjDesc; ACPI_OPERAND_OBJECT *OperandDesc; ACPI_NAMESPACE_NODE *Node; ACPI_PARSE_OBJECT *NextOp; ACPI_PARSE_OBJECT *Arg; ACPI_FUNCTION_TRACE_PTR (DsEvalBankFieldOperands, Op); /* * This is where we evaluate the BankValue field of the * BankField declaration */ /* NextOp points to the op that holds the Region */ NextOp = Op->Common.Value.Arg; /* NextOp points to the op that holds the Bank Register */ NextOp = NextOp->Common.Next; /* NextOp points to the op that holds the Bank Value */ NextOp = NextOp->Common.Next; /* * Set proper index into operand stack for AcpiDsObjStackPush * invoked inside AcpiDsCreateOperand. * * We use WalkState->Operands[0] to store the evaluated BankValue */ WalkState->OperandIndex = 0; Status = AcpiDsCreateOperand (WalkState, NextOp, 0); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } Status = AcpiExResolveToValue (&WalkState->Operands[0], WalkState); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, AcpiPsGetOpcodeName (Op->Common.AmlOpcode), 1); /* * Get the BankValue operand and save it * (at Top of stack) */ OperandDesc = WalkState->Operands[0]; /* Arg points to the start Bank Field */ Arg = AcpiPsGetArg (Op, 4); while (Arg) { /* Ignore OFFSET and ACCESSAS terms here */ if (Arg->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP) { Node = Arg->Common.Node; ObjDesc = AcpiNsGetAttachedObject (Node); if (!ObjDesc) { return_ACPI_STATUS (AE_NOT_EXIST); } ObjDesc->BankField.Value = (UINT32) OperandDesc->Integer.Value; } /* Move to next field in the list */ Arg = Arg->Common.Next; } AcpiUtRemoveReference (OperandDesc); return_ACPI_STATUS (Status); }
void AcpiDmDisplayPath ( ACPI_PARSE_OBJECT *Op) { ACPI_PARSE_OBJECT *Prev; ACPI_PARSE_OBJECT *Search; UINT32 Name; BOOLEAN DoDot = FALSE; ACPI_PARSE_OBJECT *NamePath; const ACPI_OPCODE_INFO *OpInfo; /* We are only interested in named objects */ OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode); if (!(OpInfo->Flags & AML_NSNODE)) { return; } if (OpInfo->Flags & AML_CREATE) { /* Field creation - check for a fully qualified namepath */ if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP) { NamePath = AcpiPsGetArg (Op, 3); } else { NamePath = AcpiPsGetArg (Op, 2); } if ((NamePath) && (NamePath->Common.Value.String) && (ACPI_IS_ROOT_PREFIX (NamePath->Common.Value.String[0]))) { AcpiDmNamestring (NamePath->Common.Value.String); return; } } Prev = NULL; /* Start with Root Node */ while (Prev != Op) { /* Search upwards in the tree to find scope with "prev" as its parent */ Search = Op; for (; ;) { if (Search->Common.Parent == Prev) { break; } /* Go up one level */ Search = Search->Common.Parent; } if (Prev) { OpInfo = AcpiPsGetOpcodeInfo (Search->Common.AmlOpcode); if (!(OpInfo->Flags & AML_FIELD)) { /* Below root scope, append scope name */ if (DoDot) { /* Append dot */ AcpiOsPrintf ("."); } if (OpInfo->Flags & AML_CREATE) { if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP) { NamePath = AcpiPsGetArg (Op, 3); } else { NamePath = AcpiPsGetArg (Op, 2); } if ((NamePath) && (NamePath->Common.Value.String)) { AcpiDmDumpName (NamePath->Common.Value.String); } } else { Name = AcpiPsGetName (Search); AcpiDmDumpName ((char *) &Name); } DoDot = TRUE; } } Prev = Search; } }
void AcpiDmWalkParseTree ( ACPI_PARSE_OBJECT *Op, ASL_WALK_CALLBACK DescendingCallback, ASL_WALK_CALLBACK AscendingCallback, void *Context) { BOOLEAN NodePreviouslyVisited; ACPI_PARSE_OBJECT *StartOp = Op; ACPI_STATUS Status; ACPI_PARSE_OBJECT *Next; ACPI_OP_WALK_INFO *Info = Context; Info->Level = 0; NodePreviouslyVisited = FALSE; while (Op) { if (NodePreviouslyVisited) { if (AscendingCallback) { Status = AscendingCallback (Op, Info->Level, Context); if (ACPI_FAILURE (Status)) { return; } } } else { /* Let the callback process the node */ Status = DescendingCallback (Op, Info->Level, Context); if (ACPI_SUCCESS (Status)) { /* Visit children first, once */ Next = AcpiPsGetArg (Op, 0); if (Next) { Info->Level++; Op = Next; continue; } } else if (Status != AE_CTRL_DEPTH) { /* Exit immediately on any error */ return; } } /* Terminate walk at start op */ if (Op == StartOp) { break; } /* No more children, re-visit this node */ if (!NodePreviouslyVisited) { NodePreviouslyVisited = TRUE; continue; } /* No more children, visit peers */ if (Op->Common.Next) { Op = Op->Common.Next; NodePreviouslyVisited = FALSE; } else { /* No peers, re-visit parent */ if (Info->Level != 0 ) { Info->Level--; } Op = Op->Common.Parent; NodePreviouslyVisited = TRUE; } } /* If we get here, the walk completed with no errors */ return; }
BOOLEAN AcpiDmCheckForSymbolicOpcode ( ACPI_PARSE_OBJECT *Op, ACPI_OP_WALK_INFO *Info) { char *OperatorSymbol = NULL; ACPI_PARSE_OBJECT *Argument1; ACPI_PARSE_OBJECT *Argument2; ACPI_PARSE_OBJECT *Target; ACPI_PARSE_OBJECT *Target2; /* Exit immediately if ASL+ not enabled */ if (!AcpiGbl_CstyleDisassembly) { return (FALSE); } /* Get the first operand */ Argument1 = AcpiPsGetArg (Op, 0); if (!Argument1) { return (FALSE); } /* Get the second operand */ Argument2 = Argument1->Common.Next; /* Setup the operator string for this opcode */ switch (Op->Common.AmlOpcode) { case AML_ADD_OP: OperatorSymbol = " + "; break; case AML_SUBTRACT_OP: OperatorSymbol = " - "; break; case AML_MULTIPLY_OP: OperatorSymbol = " * "; break; case AML_DIVIDE_OP: OperatorSymbol = " / "; break; case AML_MOD_OP: OperatorSymbol = " % "; break; case AML_SHIFT_LEFT_OP: OperatorSymbol = " << "; break; case AML_SHIFT_RIGHT_OP: OperatorSymbol = " >> "; break; case AML_BIT_AND_OP: OperatorSymbol = " & "; break; case AML_BIT_OR_OP: OperatorSymbol = " | "; break; case AML_BIT_XOR_OP: OperatorSymbol = " ^ "; break; /* Logical operators, no target */ case AML_LAND_OP: OperatorSymbol = " && "; break; case AML_LEQUAL_OP: OperatorSymbol = " == "; break; case AML_LGREATER_OP: OperatorSymbol = " > "; break; case AML_LLESS_OP: OperatorSymbol = " < "; break; case AML_LOR_OP: OperatorSymbol = " || "; break; case AML_LNOT_OP: /* * Check for the LNOT sub-opcodes. These correspond to * LNotEqual, LLessEqual, and LGreaterEqual. There are * no actual AML opcodes for these operators. */ switch (Argument1->Common.AmlOpcode) { case AML_LEQUAL_OP: OperatorSymbol = " != "; break; case AML_LGREATER_OP: OperatorSymbol = " <= "; break; case AML_LLESS_OP: OperatorSymbol = " >= "; break; default: /* Unary LNOT case, emit "!" immediately */ AcpiOsPrintf ("!"); return (TRUE); } Argument1->Common.DisasmOpcode = ACPI_DASM_LNOT_SUFFIX; Op->Common.DisasmOpcode = ACPI_DASM_LNOT_PREFIX; /* Save symbol string in the next child (not peer) */ Argument2 = AcpiPsGetArg (Argument1, 0); if (!Argument2) { return (FALSE); } Argument2->Common.OperatorSymbol = OperatorSymbol; return (TRUE); case AML_INDEX_OP: /* * Check for constant source operand. Note: although technically * legal syntax, the iASL compiler does not support this with * the symbolic operators for Index(). It doesn't make sense to * use Index() with a constant anyway. */ if ((Argument1->Common.AmlOpcode == AML_STRING_OP) || (Argument1->Common.AmlOpcode == AML_BUFFER_OP) || (Argument1->Common.AmlOpcode == AML_PACKAGE_OP) || (Argument1->Common.AmlOpcode == AML_VAR_PACKAGE_OP)) { Op->Common.DisasmFlags |= ACPI_PARSEOP_CLOSING_PAREN; return (FALSE); } /* Index operator is [] */ Argument1->Common.OperatorSymbol = " ["; Argument2->Common.OperatorSymbol = "]"; break; /* Unary operators */ case AML_DECREMENT_OP: OperatorSymbol = "--"; break; case AML_INCREMENT_OP: OperatorSymbol = "++"; break; case AML_BIT_NOT_OP: case AML_STORE_OP: OperatorSymbol = NULL; break; default: return (FALSE); } if (Argument1->Common.DisasmOpcode == ACPI_DASM_LNOT_SUFFIX) { return (TRUE); } /* * This is the key to how the disassembly of the C-style operators * works. We save the operator symbol in the first child, thus * deferring symbol output until after the first operand has been * emitted. */ if (!Argument1->Common.OperatorSymbol) { Argument1->Common.OperatorSymbol = OperatorSymbol; } /* * Check for a valid target as the 3rd (or sometimes 2nd) operand * * Compound assignment operator support: * Attempt to optimize constructs of the form: * Add (Local1, 0xFF, Local1) * to: * Local1 += 0xFF * * Only the math operators and Store() have a target. * Logicals have no target. */ switch (Op->Common.AmlOpcode) { case AML_ADD_OP: case AML_SUBTRACT_OP: case AML_MULTIPLY_OP: case AML_DIVIDE_OP: case AML_MOD_OP: case AML_SHIFT_LEFT_OP: case AML_SHIFT_RIGHT_OP: case AML_BIT_AND_OP: case AML_BIT_OR_OP: case AML_BIT_XOR_OP: /* Target is 3rd operand */ Target = Argument2->Common.Next; if (Op->Common.AmlOpcode == AML_DIVIDE_OP) { Target2 = Target->Common.Next; /* * Divide has an extra target operand (Remainder). * Default behavior is to simply ignore ASL+ conversion * if the remainder target (modulo) is specified. */ if (!AcpiGbl_DoDisassemblerOptimizations) { if (AcpiDmIsValidTarget (Target)) { Argument1->Common.OperatorSymbol = NULL; Op->Common.DisasmFlags |= ACPI_PARSEOP_LEGACY_ASL_ONLY; return (FALSE); } Target->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE; Target = Target2; } else { /* * Divide has an extra target operand (Remainder). * If both targets are specified, it cannot be converted * to a C-style operator. */ if (AcpiDmIsValidTarget (Target) && AcpiDmIsValidTarget (Target2)) { Argument1->Common.OperatorSymbol = NULL; Op->Common.DisasmFlags |= ACPI_PARSEOP_LEGACY_ASL_ONLY; return (FALSE); } if (AcpiDmIsValidTarget (Target)) /* Only first Target is valid (remainder) */ { /* Convert the Divide to Modulo */ Op->Common.AmlOpcode = AML_MOD_OP; Argument1->Common.OperatorSymbol = " % "; Target2->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE; } else /* Only second Target (quotient) is valid */ { Target->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE; Target = Target2; } } } /* Parser should ensure there is at least a placeholder target */ if (!Target) { return (FALSE); } if (!AcpiDmIsValidTarget (Target)) { /* Not a valid target (placeholder only, from parser) */ break; } /* * Promote the target up to the first child in the parse * tree. This is done because the target will be output * first, in the form: * <Target> = Operands... */ AcpiDmPromoteTarget (Op, Target); /* Check operands for conversion to a "Compound Assignment" */ switch (Op->Common.AmlOpcode) { /* Commutative operators */ case AML_ADD_OP: case AML_MULTIPLY_OP: case AML_BIT_AND_OP: case AML_BIT_OR_OP: case AML_BIT_XOR_OP: /* * For the commutative operators, we can convert to a * compound statement only if at least one (either) operand * is the same as the target. * * Add (A, B, A) --> A += B * Add (B, A, A) --> A += B * Add (B, C, A) --> A = (B + C) */ if ((AcpiDmIsTargetAnOperand (Target, Argument1, TRUE)) || (AcpiDmIsTargetAnOperand (Target, Argument2, TRUE))) { Target->Common.OperatorSymbol = AcpiDmGetCompoundSymbol (Op->Common.AmlOpcode); /* Convert operator to compound assignment */ Op->Common.DisasmFlags |= ACPI_PARSEOP_COMPOUND_ASSIGNMENT; Argument1->Common.OperatorSymbol = NULL; return (TRUE); } break; /* Non-commutative operators */ case AML_SUBTRACT_OP: case AML_DIVIDE_OP: case AML_MOD_OP: case AML_SHIFT_LEFT_OP: case AML_SHIFT_RIGHT_OP: /* * For the non-commutative operators, we can convert to a * compound statement only if the target is the same as the * first operand. * * Subtract (A, B, A) --> A -= B * Subtract (B, A, A) --> A = (B - A) */ if ((AcpiDmIsTargetAnOperand (Target, Argument1, TRUE))) { Target->Common.OperatorSymbol = AcpiDmGetCompoundSymbol (Op->Common.AmlOpcode); /* Convert operator to compound assignment */ Op->Common.DisasmFlags |= ACPI_PARSEOP_COMPOUND_ASSIGNMENT; Argument1->Common.OperatorSymbol = NULL; return (TRUE); } break; default: break; } /* * If we are within a C-style expression, emit an extra open * paren. Implemented by examining the parent op. */ switch (Op->Common.Parent->Common.AmlOpcode) { case AML_ADD_OP: case AML_SUBTRACT_OP: case AML_MULTIPLY_OP: case AML_DIVIDE_OP: case AML_MOD_OP: case AML_SHIFT_LEFT_OP: case AML_SHIFT_RIGHT_OP: case AML_BIT_AND_OP: case AML_BIT_OR_OP: case AML_BIT_XOR_OP: case AML_LAND_OP: case AML_LEQUAL_OP: case AML_LGREATER_OP: case AML_LLESS_OP: case AML_LOR_OP: Op->Common.DisasmFlags |= ACPI_PARSEOP_ASSIGNMENT; AcpiOsPrintf ("("); break; default: break; } /* Normal output for ASL/AML operators with a target operand */ Target->Common.OperatorSymbol = " = ("; return (TRUE); /* Binary operators, no parens */ case AML_DECREMENT_OP: case AML_INCREMENT_OP: return (TRUE); case AML_INDEX_OP: /* Target is optional, 3rd operand */ Target = Argument2->Common.Next; if (AcpiDmIsValidTarget (Target)) { AcpiDmPromoteTarget (Op, Target); if (!Target->Common.OperatorSymbol) { Target->Common.OperatorSymbol = " = "; } } return (TRUE); case AML_STORE_OP: /* * For Store, the Target is the 2nd operand. We know the target * is valid, because it is not optional. * * Ignore any optimizations/folding if flag is set. * Used for iASL/disassembler test suite only. */ if (AcpiDmIsOptimizationIgnored (Op, Argument1)) { return (FALSE); } /* * Perform conversion. * In the parse tree, simply swap the target with the * source so that the target is processed first. */ Target = Argument1->Common.Next; if (!Target) { return (FALSE); } AcpiDmPromoteTarget (Op, Target); if (!Target->Common.OperatorSymbol) { Target->Common.OperatorSymbol = " = "; } return (TRUE); case AML_BIT_NOT_OP: /* Target is optional, 2nd operand */ Target = Argument1->Common.Next; if (!Target) { return (FALSE); } if (AcpiDmIsValidTarget (Target)) { /* Valid target, not a placeholder */ AcpiDmPromoteTarget (Op, Target); Target->Common.OperatorSymbol = " = ~"; } else { /* No target. Emit this prefix operator immediately */ AcpiOsPrintf ("~"); } return (TRUE); default: break; } /* All other operators, emit an open paren */ AcpiOsPrintf ("("); return (TRUE); }
BOOLEAN AcpiDmCheckForSymbolicOpcode ( ACPI_PARSE_OBJECT *Op, ACPI_OP_WALK_INFO *Info) { char *OperatorSymbol = NULL; ACPI_PARSE_OBJECT *Child1; ACPI_PARSE_OBJECT *Child2; ACPI_PARSE_OBJECT *Target; /* Exit immediately if ASL+ not enabled */ if (!AcpiGbl_CstyleDisassembly) { return (FALSE); } /* Get the first operand */ Child1 = AcpiPsGetArg (Op, 0); if (!Child1) { return (FALSE); } /* Get the second operand */ Child2 = Child1->Common.Next; /* Setup the operator string for this opcode */ switch (Op->Common.AmlOpcode) { case AML_ADD_OP: OperatorSymbol = " + "; break; case AML_SUBTRACT_OP: OperatorSymbol = " - "; break; case AML_MULTIPLY_OP: OperatorSymbol = " * "; break; case AML_DIVIDE_OP: OperatorSymbol = " / "; break; case AML_MOD_OP: OperatorSymbol = " % "; break; case AML_SHIFT_LEFT_OP: OperatorSymbol = " << "; break; case AML_SHIFT_RIGHT_OP: OperatorSymbol = " >> "; break; case AML_BIT_AND_OP: OperatorSymbol = " & "; break; case AML_BIT_OR_OP: OperatorSymbol = " | "; break; case AML_BIT_XOR_OP: OperatorSymbol = " ^ "; break; /* Logical operators, no target */ case AML_LAND_OP: OperatorSymbol = " && "; break; case AML_LEQUAL_OP: OperatorSymbol = " == "; break; case AML_LGREATER_OP: OperatorSymbol = " > "; break; case AML_LLESS_OP: OperatorSymbol = " < "; break; case AML_LOR_OP: OperatorSymbol = " || "; break; case AML_LNOT_OP: /* * Check for the LNOT sub-opcodes. These correspond to * LNotEqual, LLessEqual, and LGreaterEqual. There are * no actual AML opcodes for these operators. */ switch (Child1->Common.AmlOpcode) { case AML_LEQUAL_OP: OperatorSymbol = " != "; break; case AML_LGREATER_OP: OperatorSymbol = " <= "; break; case AML_LLESS_OP: OperatorSymbol = " >= "; break; default: /* Unary LNOT case, emit "!" immediately */ AcpiOsPrintf ("!"); return (TRUE); } Child1->Common.DisasmOpcode = ACPI_DASM_LNOT_SUFFIX; Op->Common.DisasmOpcode = ACPI_DASM_LNOT_PREFIX; /* Save symbol string in the next child (not peer) */ Child2 = AcpiPsGetArg (Child1, 0); if (!Child2) { return (FALSE); } Child2->Common.OperatorSymbol = OperatorSymbol; return (TRUE); #ifdef INDEX_SUPPORT case AML_INDEX_OP: Child1->Common.OperatorSymbol = " ["; Child2->Common.OperatorSymbol = "]"; break; #endif /* Unary operators */ case AML_DECREMENT_OP: OperatorSymbol = "--"; break; case AML_INCREMENT_OP: OperatorSymbol = "++"; break; case AML_BIT_NOT_OP: case AML_STORE_OP: OperatorSymbol = NULL; break; default: return (FALSE); } if (Child1->Common.DisasmOpcode == ACPI_DASM_LNOT_SUFFIX) { return (TRUE); } /* * This is the key to how the disassembly of the C-style operators * works. We save the operator symbol in the first child, thus * deferring symbol output until after the first operand has been * emitted. */ if (!Child1->Common.OperatorSymbol) { Child1->Common.OperatorSymbol = OperatorSymbol; } /* * Check for a valid target as the 3rd (or sometimes 2nd) operand * * Compound assignment operator support: * Attempt to optimize constructs of the form: * Add (Local1, 0xFF, Local1) * to: * Local1 += 0xFF * * Only the math operators and Store() have a target. * Logicals have no target. */ switch (Op->Common.AmlOpcode) { case AML_ADD_OP: case AML_SUBTRACT_OP: case AML_MULTIPLY_OP: case AML_DIVIDE_OP: case AML_MOD_OP: case AML_SHIFT_LEFT_OP: case AML_SHIFT_RIGHT_OP: case AML_BIT_AND_OP: case AML_BIT_OR_OP: case AML_BIT_XOR_OP: /* Target is 3rd operand */ Target = Child2->Common.Next; if (Op->Common.AmlOpcode == AML_DIVIDE_OP) { /* * Divide has an extra target operand (Remainder). * If this extra target is specified, it cannot be converted * to a C-style operator */ if (AcpiDmIsValidTarget (Target)) { Child1->Common.OperatorSymbol = NULL; return (FALSE); } Target->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE; Target = Target->Common.Next; } /* Parser should ensure there is at least a placeholder target */ if (!Target) { return (FALSE); } if (!AcpiDmIsValidTarget (Target)) { /* Not a valid target (placeholder only, from parser) */ break; } /* * Promote the target up to the first child in the parse * tree. This is done because the target will be output * first, in the form: * <Target> = Operands... */ AcpiDmPromoteTarget (Op, Target); /* Check operands for conversion to a "Compound Assignment" */ switch (Op->Common.AmlOpcode) { /* Commutative operators */ case AML_ADD_OP: case AML_MULTIPLY_OP: case AML_BIT_AND_OP: case AML_BIT_OR_OP: case AML_BIT_XOR_OP: /* * For the commutative operators, we can convert to a * compound statement only if at least one (either) operand * is the same as the target. * * Add (A, B, A) --> A += B * Add (B, A, A) --> A += B * Add (B, C, A) --> A = (B + C) */ if ((AcpiDmIsTargetAnOperand (Target, Child1, TRUE)) || (AcpiDmIsTargetAnOperand (Target, Child2, TRUE))) { Target->Common.OperatorSymbol = AcpiDmGetCompoundSymbol (Op->Common.AmlOpcode); /* Convert operator to compound assignment */ Op->Common.DisasmFlags |= ACPI_PARSEOP_COMPOUND; Child1->Common.OperatorSymbol = NULL; return (TRUE); } break; /* Non-commutative operators */ case AML_SUBTRACT_OP: case AML_DIVIDE_OP: case AML_MOD_OP: case AML_SHIFT_LEFT_OP: case AML_SHIFT_RIGHT_OP: /* * For the non-commutative operators, we can convert to a * compound statement only if the target is the same as the * first operand. * * Subtract (A, B, A) --> A -= B * Subtract (B, A, A) --> A = (B - A) */ if ((AcpiDmIsTargetAnOperand (Target, Child1, TRUE))) { Target->Common.OperatorSymbol = AcpiDmGetCompoundSymbol (Op->Common.AmlOpcode); /* Convert operator to compound assignment */ Op->Common.DisasmFlags |= ACPI_PARSEOP_COMPOUND; Child1->Common.OperatorSymbol = NULL; return (TRUE); } break; default: break; } /* * If we are within a C-style expression, emit an extra open * paren. Implemented by examining the parent op. */ switch (Op->Common.Parent->Common.AmlOpcode) { case AML_ADD_OP: case AML_SUBTRACT_OP: case AML_MULTIPLY_OP: case AML_DIVIDE_OP: case AML_MOD_OP: case AML_SHIFT_LEFT_OP: case AML_SHIFT_RIGHT_OP: case AML_BIT_AND_OP: case AML_BIT_OR_OP: case AML_BIT_XOR_OP: case AML_LAND_OP: case AML_LEQUAL_OP: case AML_LGREATER_OP: case AML_LLESS_OP: case AML_LOR_OP: Op->Common.DisasmFlags |= ACPI_PARSEOP_ASSIGNMENT; AcpiOsPrintf ("("); break; default: break; } /* Normal output for ASL/AML operators with a target operand */ Target->Common.OperatorSymbol = " = ("; return (TRUE); /* Binary operators, no parens */ case AML_DECREMENT_OP: case AML_INCREMENT_OP: return (TRUE); #ifdef INDEX_SUPPORT case AML_INDEX_OP: /* Target is optional, 3rd operand */ Target = Child2->Common.Next; if (AcpiDmIsValidTarget (Target)) { AcpiDmPromoteTarget (Op, Target); if (!Target->Common.OperatorSymbol) { Target->Common.OperatorSymbol = " = "; } } return (TRUE); #endif case AML_STORE_OP: /* * Target is the 2nd operand. * We know the target is valid, it is not optional. * In the parse tree, simply swap the target with the * source so that the target is processed first. */ Target = Child1->Common.Next; if (!Target) { return (FALSE); } AcpiDmPromoteTarget (Op, Target); if (!Target->Common.OperatorSymbol) { Target->Common.OperatorSymbol = " = "; } return (TRUE); case AML_BIT_NOT_OP: /* Target is optional, 2nd operand */ Target = Child1->Common.Next; if (!Target) { return (FALSE); } if (AcpiDmIsValidTarget (Target)) { /* Valid target, not a placeholder */ AcpiDmPromoteTarget (Op, Target); Target->Common.OperatorSymbol = " = ~"; } else { /* No target. Emit this prefix operator immediately */ AcpiOsPrintf ("~"); } return (TRUE); default: break; } /* All other operators, emit an open paren */ AcpiOsPrintf ("("); return (TRUE); }
ACPI_PARSE_OBJECT * AcpiPsGetDepthNext ( ACPI_PARSE_OBJECT *Origin, ACPI_PARSE_OBJECT *Op) { ACPI_PARSE_OBJECT *Next = NULL; ACPI_PARSE_OBJECT *Parent; ACPI_PARSE_OBJECT *Arg; ACPI_FUNCTION_ENTRY (); if (!Op) { return (NULL); } /* Look for an argument or child */ Next = AcpiPsGetArg (Op, 0); if (Next) { return (Next); } /* Look for a sibling */ Next = Op->Common.Next; if (Next) { return (Next); } /* Look for a sibling of parent */ Parent = Op->Common.Parent; while (Parent) { Arg = AcpiPsGetArg (Parent, 0); while (Arg && (Arg != Origin) && (Arg != Op)) { Arg = Arg->Common.Next; } if (Arg == Origin) { /* Reached parent of origin, end search */ return (NULL); } if (Parent->Common.Next) { /* Found sibling of parent */ return (Parent->Common.Next); } Op = Parent; Parent = Parent->Common.Parent; } return (Next); }
void AcpiPsGetNextNamepath ( ACPI_PARSE_STATE *ParserState, ACPI_PARSE_OBJECT *Arg, UINT32 *ArgCount, BOOLEAN MethodCall) { NATIVE_CHAR *Path; ACPI_PARSE_OBJECT *NameOp; ACPI_PARSE_OBJECT *Op; ACPI_PARSE_OBJECT *Count; FUNCTION_TRACE ("PsGetNextNamepath"); Path = AcpiPsGetNextNamestring (ParserState); if (!Path || !MethodCall) { /* Null name case, create a null namepath object */ AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP); Arg->Value.Name = Path; return_VOID; } if (AcpiGbl_ParsedNamespaceRoot) { /* * Lookup the name in the parsed namespace */ Op = NULL; if (MethodCall) { Op = AcpiPsFind (AcpiPsGetParentScope (ParserState), Path, AML_METHOD_OP, 0); } if (Op) { if (Op->Opcode == AML_METHOD_OP) { /* * The name refers to a control method, so this namepath is a * method invocation. We need to 1) Get the number of arguments * associated with this method, and 2) Change the NAMEPATH * object into a METHODCALL object. */ Count = AcpiPsGetArg (Op, 0); if (Count && Count->Opcode == AML_BYTE_OP) { NameOp = AcpiPsAllocOp (AML_INT_NAMEPATH_OP); if (NameOp) { /* Change arg into a METHOD CALL and attach the name */ AcpiPsInitOp (Arg, AML_INT_METHODCALL_OP); NameOp->Value.Name = Path; /* Point METHODCALL/NAME to the METHOD Node */ NameOp->Node = (ACPI_NAMESPACE_NODE *) Op; AcpiPsAppendArg (Arg, NameOp); *ArgCount = (UINT32) Count->Value.Integer & METHOD_FLAGS_ARG_COUNT; } } return_VOID; } /* * Else this is normal named object reference. * Just init the NAMEPATH object with the pathname. * (See code below) */ } } /* * Either we didn't find the object in the namespace, or the object is * something other than a control method. Just initialize the Op with the * pathname */ AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP); Arg->Value.Name = Path; return_VOID; }