public static void DoExecute(XSharp.Assembler.Assembler Assembler, _MethodInfo aMethod, ushort aParam) { var xDisplacement = GetArgumentDisplacement(aMethod, aParam); var xType = GetArgumentType(aMethod, aParam); uint xArgRealSize = SizeOfType(xType); uint xArgSize = Align(xArgRealSize, 4); XS.Comment("Arg idx = " + aParam); XS.Comment("Arg type = " + xType); XS.Comment("Arg real size = " + xArgRealSize + " aligned size = " + xArgSize); if (IsIntegralType(xType) && xArgRealSize == 1 || xArgRealSize == 2) { if (TypeIsSigned(xType)) { XS.MoveSignExtend(EAX, EBP, sourceIsIndirect: true, sourceDisplacement: xDisplacement, size: (RegisterSize)(8 * xArgRealSize)); } else { XS.MoveZeroExtend(EAX, EBP, sourceIsIndirect: true, sourceDisplacement: xDisplacement, size: (RegisterSize)(8 * xArgRealSize)); } XS.Push(EAX); } else { for (int i = 0; i < (xArgSize / 4); i++) { XS.Push(EBP, isIndirect: true, displacement: (xDisplacement - (i * 4))); } } }
public override void UpdateAddress(XSharp.Assembler.Assembler aAssembler, ref ulong aAddress) { if (ArgumentRef != null) { ArgumentValue = 0xFFFFFFFF; } base.UpdateAddress(aAssembler, ref aAddress); }
public override void UpdateAddress(XSharp.Assembler.Assembler aAssembler, ref ulong aAddress) { if (SourceRef != null) { SourceValue = 0xFFFFFFFF; } base.UpdateAddress(aAssembler, ref aAddress); }
public override void UpdateAddress(XSharp.Assembler.Assembler aAssembler, ref ulong aAddresss) { if (DestinationRef != null) { DestinationValue = 0xFFFFFFFF; } base.UpdateAddress(aAssembler, ref aAddresss); }
public override bool IsComplete(XSharp.Assembler.Assembler aAssembler) { if (DestinationRef != null) { ulong xAddress; return(base.IsComplete(aAssembler) && DestinationRef.Resolve(aAssembler, out xAddress)); } return(base.IsComplete(aAssembler)); }
public override void WriteText(XSharp.Assembler.Assembler aAssembler, System.IO.TextWriter aOutput) { aOutput.Write(mMnemonic); aOutput.Write(" "); aOutput.Write(this.GetDestinationAsString()); aOutput.Write(", "); aOutput.Write(this.GetSourceAsString()); aOutput.Write(", "); aOutput.Write(this.pseudoOpcode); }
public override void WriteText(XSharp.Assembler.Assembler aAssembler, System.IO.TextWriter aOutput) { aOutput.Write(mMnemonic); aOutput.Write(" "); aOutput.Write(SizeToString(Size)); if (!DestinationEmpty) { aOutput.Write(" "); aOutput.Write(this.GetDestinationAsString()); } }
public override void WriteText(XSharp.Assembler.Assembler aAssembler, System.IO.TextWriter aOutput) { aOutput.Write(mMnemonic); String destination = this.GetDestinationAsString(); if (!(DestinationEmpty && destination.Equals(""))) { aOutput.Write(" "); aOutput.Write(destination); } }
//public override byte[] GetData(Assembler aAssembler) { public override void WriteData(XSharp.Assembler.Assembler aAssembler, System.IO.Stream aOutput) { aOutput.WriteByte(0xEA); ulong xAddress = 0; if (DestinationRef != null && DestinationRef.Resolve(aAssembler, out xAddress)) { xAddress = (ulong)(((long)xAddress) + DestinationRef.Offset); } aOutput.Write(BitConverter.GetBytes((uint)(xAddress)), 0, 4); aOutput.Write(BitConverter.GetBytes(Segment), 0, 2); }
public override void WriteText(XSharp.Assembler.Assembler aAssembler, System.IO.TextWriter aOutput) { if (IsGlobal) { aOutput.Write("global "); aOutput.WriteLine(QualifiedName); } aOutput.Write(QualifiedName); aOutput.Write(":"); if (Comment.Length > 0) { aOutput.Write(" ;"); aOutput.Write(Comment); } }
public override void WriteText(XSharp.Assembler.Assembler aAssembler, System.IO.TextWriter aOutput) { if (DestinationRef != null) { aOutput.Write("jmp "); aOutput.Write(Segment); aOutput.Write(":"); aOutput.Write(DestinationRef.ToString()); } else { aOutput.Write("jmp "); aOutput.Write(Segment); aOutput.Write(":0x0"); } }
public override void WriteText(XSharp.Assembler.Assembler aAssembler, System.IO.TextWriter aOutput) { aOutput.Write(mMnemonic); String destination = this.GetDestinationAsString(); if (!destination.Equals("")) { aOutput.Write(" "); aOutput.Write(destination); string source = this.GetSourceAsString(); if (!(SourceEmpty && source.Equals(""))) { aOutput.Write(", "); aOutput.Write(source); } } }
public static void DoExecute(XSharp.Assembler.Assembler Assembler, _MethodInfo aMethod, ushort aParam) { var xDisplacement = Ldarg.GetArgumentDisplacement(aMethod, aParam); /* * The function GetArgumentDisplacement() does not give the correct displacement for the Ldarga opcode * we need to "fix" it subtracting the argSize and 4 */ Type xArgType; if (aMethod.MethodBase.IsStatic) { xArgType = aMethod.MethodBase.GetParameters()[aParam].ParameterType; } else { if (aParam == 0u) { xArgType = aMethod.MethodBase.DeclaringType; if (xArgType.IsValueType) { xArgType = xArgType.MakeByRefType(); } } else { xArgType = aMethod.MethodBase.GetParameters()[aParam - 1].ParameterType; } } uint xArgRealSize = SizeOfType(xArgType); uint xArgSize = Align(xArgRealSize, 4); XS.Comment("Arg idx = " + aParam); XS.Comment("Arg type = " + xArgType); XS.Comment("Arg real size = " + xArgRealSize + " aligned size = " + xArgSize); xDisplacement -= (int)(xArgSize - 4); XS.Comment("Real displacement " + xDisplacement); XS.Set(EAX, EBP); XS.Set(EBX, (uint)(xDisplacement)); XS.Add(EAX, EBX); XS.Push(EAX); }
public static void DoExecute(XSharp.Assembler.Assembler assembler, _MethodInfo aMethod, string field, Type declaringType, ILOpCode aCurrentOpCode) { // call cctor: var xCctor = (declaringType.GetConstructors(BindingFlags.Static | BindingFlags.NonPublic) ?? Array.Empty <ConstructorInfo>()).SingleOrDefault(); if (xCctor != null) { XS.Call(LabelName.Get(xCctor)); if (aCurrentOpCode != null) { ILOp.EmitExceptionLogic(assembler, aMethod, aCurrentOpCode, true, null, ".AfterCCTorExceptionCheck"); XS.Label(".AfterCCTorExceptionCheck"); } } string xDataName = field; XS.Push(xDataName); }
public static void Assemble(XSharp.Assembler.Assembler aAssembler, OpType aOpType, uint aElementSize, bool debugEnabled, _MethodInfo aMethod, ILOpCode aOpCode) { XS.Comment("Arraytype: " + aOpType.StackPopTypes.Last().FullName); XS.Comment("Size: " + aElementSize); DoNullReferenceCheck(aAssembler, debugEnabled, 8); //Do check for index out of range var xBaseLabel = GetLabel(aMethod, aOpCode); var xNoIndexOutOfRangeExeptionLabel = xBaseLabel + "_NoIndexOutOfRangeException"; var xIndexOutOfRangeExeptionLabel = xBaseLabel + "_IndexOutOfRangeException"; XS.Pop(EBX); //get Position _, array, 0, index -> _, array, 0 XS.Push(ESP, true, 4); // _, array, 0 => _, array, 0, array XS.Push(ESP, true, 12); // _, array, 0, array => _, array, 0, array, 0 Ldlen.Assemble(aAssembler, debugEnabled, false); // _, array, 0, array, 0 -> _, array, 0, length XS.Pop(EAX); //Length of array _, array, 0, length -> _, array, 0 XS.Compare(EAX, EBX); XS.Jump(CPUx86.ConditionalTestEnum.LessThanOrEqualTo, xIndexOutOfRangeExeptionLabel); XS.Compare(EBX, 0); XS.Jump(CPUx86.ConditionalTestEnum.GreaterThanOrEqualTo, xNoIndexOutOfRangeExeptionLabel); XS.Label(xIndexOutOfRangeExeptionLabel); XS.Pop(EAX); XS.Pop(EAX); Call.DoExecute(aAssembler, aMethod, ExceptionHelperRefs.ThrowIndexOutOfRangeException, aOpCode, xNoIndexOutOfRangeExeptionLabel, debugEnabled); XS.Label(xNoIndexOutOfRangeExeptionLabel); XS.Push(EBX); //_, array, 0 -> _, array, 0, index // calculate element offset into array memory (including header) XS.Pop(EAX); XS.Set(EDX, aElementSize); XS.Multiply(EDX); XS.Add(EAX, (uint)(ObjectUtils.FieldDataOffset + 4)); // pop the array now XS.Add(ESP, 4); XS.Pop(EDX); XS.Add(EDX, EAX); XS.Push(EDX); }
public static void Assemble(XSharp.Assembler.Assembler aAssembler, OpType aOpType, uint aElementSize, bool debugEnabled) { XS.Comment("Arraytype: " + aOpType.StackPopTypes.Last().FullName); XS.Comment("Size: " + aElementSize); DoNullReferenceCheck(aAssembler, debugEnabled, 8); // calculate element offset into array memory (including header) XS.Pop(EAX); XS.Set(EDX, aElementSize); XS.Multiply(EDX); XS.Add(EAX, (uint)(ObjectUtils.FieldDataOffset + 4)); // pop the array now XS.Add(ESP, 4); XS.Pop(EDX); XS.Add(EDX, EAX); XS.Push(EDX); }
public override void WriteText(XSharp.Assembler.Assembler aAssembler, System.IO.TextWriter aOutput) { switch (Size) { case 32: aOutput.Write("cdq"); return; case 16: aOutput.Write("cwde"); return; case 8: aOutput.Write("cbw"); return; default: throw new NotSupportedException(); } }
public static void DoExecute(XSharp.Assembler.Assembler Assembler, _MethodInfo aMethod, Type aDeclaringType, _FieldInfo aField, bool aDerefValue, bool aDebugEnabled, Type aTypeOnStack) { XS.Comment("Field: " + aField.Id); int xExtraOffset = 0; bool xNeedsGC = aDeclaringType.IsClass && !aDeclaringType.IsValueType; if (xNeedsGC) { xExtraOffset = 12; } if ((!aTypeOnStack.IsPointer) && (aDeclaringType.IsClass)) { DoNullReferenceCheck(Assembler, aDebugEnabled, 4); XS.Add(ESP, 4); } else { DoNullReferenceCheck(Assembler, aDebugEnabled, 0); } if (aDerefValue && aField.IsExternalValue) { XS.Set(ESP, EAX, destinationIsIndirect: true); } else { XS.Pop(EAX); if (aDeclaringType.Name == "RawArrayData" && aField.Field.Name == "Data") { // if we accidently load 64bit assemblies, we get an incorrect extra 4 bytes of offset, so we just hardcode the offset XS.Add(EAX, (uint)(4 + xExtraOffset)); } else { XS.Add(EAX, (uint)(aField.Offset + xExtraOffset)); } XS.Push(EAX); } }
public override void WriteText(XSharp.Assembler.Assembler aAssembler, System.IO.TextWriter aOutput) { switch (Condition) { case FloatConditionalMoveTestEnum.Below: aOutput.Write("fcmovb"); break; case FloatConditionalMoveTestEnum.Equal: aOutput.Write("fcmove"); break; case FloatConditionalMoveTestEnum.BelowOrEqual: aOutput.Write("fcmovbe"); break; case FloatConditionalMoveTestEnum.Unordered: aOutput.Write("fcmovu"); break; case FloatConditionalMoveTestEnum.NotBelow: aOutput.Write("fcmovnb"); break; case FloatConditionalMoveTestEnum.NotEqual: aOutput.Write("fcmovne"); break; case FloatConditionalMoveTestEnum.NotBelowOrEqual: aOutput.Write("fcmovnbe"); break; case FloatConditionalMoveTestEnum.Ordered: aOutput.Write("fcmovnu"); break; } aOutput.Write(" "); aOutput.Write("ST0"); aOutput.Write(", "); aOutput.Write(this.GetSourceAsString()); }
public override void WriteData(XSharp.Assembler.Assembler aAssembler, Stream aOutput) { if (mCorrectAddress) { if (IsRelativeJump) { if (DestinationValue.HasValue && !DestinationIsIndirect) { var xCurAddress = ActualAddress; var xOrigValue = DestinationValue.Value; DestinationValue = (uint)(xOrigValue - xCurAddress.Value); try { base.WriteData(aAssembler, aOutput); return; } finally { DestinationValue = xOrigValue; } } } } base.WriteData(aAssembler, aOutput); }
public static void DoExecute(XSharp.Assembler.Assembler Assembler, _MethodInfo aMethod, Type aDeclaringType, _FieldInfo aField, bool aDerefValue, bool aDebugEnabled, Type aTypeOnStack) { XS.Comment("Field: " + aField.Id); int xExtraOffset = 0; var xType = aMethod.MethodBase.DeclaringType; bool xNeedsGC = aDeclaringType.IsClass && !aDeclaringType.IsValueType; if (xNeedsGC) { xExtraOffset = 12; } var xActualOffset = aField.Offset + xExtraOffset; var xSize = aField.Size; if ((!aTypeOnStack.IsPointer) && (aDeclaringType.IsClass)) { DoNullReferenceCheck(Assembler, aDebugEnabled, 4); XS.Add(ESP, 4); } else { DoNullReferenceCheck(Assembler, aDebugEnabled, 0); } if (aDerefValue && aField.IsExternalValue) { XS.Set(ESP, EAX, destinationIsIndirect: true); } else { XS.Pop(EAX); XS.Add(EAX, (uint)(xActualOffset)); XS.Push(EAX); } }
public static void DoExecute(XSharp.Assembler.Assembler Assembler, _MethodInfo aMethod, ushort aParam) { var xDisplacement = Ldarg.GetArgumentDisplacement(aMethod, aParam); Type xArgType; if (aMethod.MethodBase.IsStatic) { xArgType = aMethod.MethodBase.GetParameters()[aParam].ParameterType; } else { if (aParam == 0u) { xArgType = aMethod.MethodBase.DeclaringType; if (xArgType.IsValueType) { xArgType = xArgType.MakeByRefType(); } } else { xArgType = aMethod.MethodBase.GetParameters()[aParam - 1].ParameterType; } } XS.Comment("Arg idx = " + aParam); uint xArgRealSize = SizeOfType(xArgType); uint xArgSize = Align(xArgRealSize, 4); XS.Comment("Arg type = " + xArgType); XS.Comment("Arg real size = " + xArgRealSize + " aligned size = " + xArgSize); for (int i = (int)(xArgSize / 4) - 1; i >= 0; i--) { XS.Pop(EAX); XS.Set(EBP, EAX, destinationIsIndirect: true, destinationDisplacement: xDisplacement - (i * 4)); } }
public bool Resolve(XSharp.Assembler.Assembler aAssembler, out ulong aAddress) { // if (mActualAddress != null) { aAddress = mActualAddress.Value; return(true); } var xElement = DoResolve(aAssembler, Name); if (xElement != null) { if (xElement.ActualAddress.HasValue) { mActualAddress = (ulong)((long)xElement.ActualAddress.Value + Offset); aAddress = mActualAddress.Value; return(true); } } aAddress = 0; return(false); }
public override void WriteText(XSharp.Assembler.Assembler aAssembler, System.IO.TextWriter aOutput) { if ((Prefixes & InstructionPrefixes.RepeatTillEqual) != 0) { aOutput.Write("repne "); } switch (Size) { case 32: aOutput.Write("cmpsd"); return; case 16: aOutput.Write("cmpsw"); return; case 8: aOutput.Write("smpsb"); return; default: throw new Exception("Size not supported!"); } }
public Endfinally(XSharp.Assembler.Assembler aAsmblr) : base(aAsmblr) { }
private static BaseAssemblerElement DoResolve(XSharp.Assembler.Assembler aAssembler, string aName) { if (!mThreadId.HasValue) { mThreadId = Thread.CurrentThread.ManagedThreadId; } else { if (mThreadId.Value != Thread.CurrentThread.ManagedThreadId) { throw new Exception("Called from multiple threads"); } } mCacheLocker.EnterReadLock(); try { if (mCache != null) { if (mCache.TryGetValue(aName, out var xTempResult)) { return(xTempResult); } } } finally { mCacheLocker.ExitReadLock(); } mCacheLocker.EnterWriteLock(); try { if (mCache == null) { mCache = new Dictionary <string, BaseAssemblerElement>(StringComparer.OrdinalIgnoreCase); int xMax = aAssembler.AllAssemblerElementCount; for (int i = 0; i < xMax; i++) { var xInstruction = aAssembler.GetAssemblerElement(i); if (xInstruction is Label xLabel) { mCache.Add(xLabel.QualifiedName, xLabel); } if (xInstruction is DataMember xDataMember) { if (mCache.ContainsKey(xDataMember.Name)) { Console.Write(""); } mCache.Add(xDataMember.Name, xDataMember); } } } if (mCache.TryGetValue(aName, out var xTempResult)) { return(xTempResult); } throw new Exception("Cannot resolve ElementReference to '" + aName + "'!"); //foreach(var xInstruction in aAssembler.Instructions ) { // var xLabel = xInstruction as Label; // if(xLabel!=null) { // if(aName.Equals(xLabel.Name, StringComparison.InvariantCultureIgnoreCase)) { // xTempResult = xLabel; // break; // } // } //} //if (xTempResult == null) { // foreach (var xDataMember in aAssembler.DataMembers) { // if (aName.Equals(xDataMember.Name, StringComparison.InvariantCultureIgnoreCase)) { // xTempResult = xDataMember; // break; // } // } //} } finally { mCacheLocker.ExitWriteLock(); } }
public Mul(XSharp.Assembler.Assembler aAsmblr) : base(aAsmblr) { }
public override void WriteText(XSharp.Assembler.Assembler aAssembler, System.IO.TextWriter aOutput) { aOutput.Write(Mnemonic); }
public Rem_Un(XSharp.Assembler.Assembler aAsmblr) : base(aAsmblr) { }
public Shr(XSharp.Assembler.Assembler aAsmblr) : base(aAsmblr) { }