public static void DoExecute(Cosmos.Assembler.Assembler Assembler, MethodInfo aMethod, ushort aParam) { var xDisplacement = Ldarg.GetArgumentDisplacement(aMethod, aParam); var xType = Ldarg.GetArgumentType(aMethod, aParam); XS.Comment("Arg idx = " + aParam); XS.Comment("Arg type = " + xType); XS.Set(XSRegisters.EAX, XSRegisters.EBP); XS.Set(XSRegisters.EBX, (uint)(xDisplacement)); XS.Add(XSRegisters.EAX, XSRegisters.EBX); XS.Push(XSRegisters.EAX); }
public override void Execute(MethodInfo aMethod, ILOpCode aOpCode) { #if false var xOpVar = (OpVar)aOpCode; var xDisplacement = Ldarg.GetArgumentDisplacement(aMethod, xOpVar.Value); /* * 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()[xOpVar.Value].ParameterType; } else { if (xOpVar.Value == 0u) { xArgType = aMethod.MethodBase.DeclaringType; if (xArgType.IsValueType) { xArgType = xArgType.MakeByRefType(); } } else { xArgType = aMethod.MethodBase.GetParameters()[xOpVar.Value - 1].ParameterType; } } uint xArgRealSize = SizeOfType(xArgType); uint xArgSize = Align(xArgRealSize, 4); XS.Comment("Arg type = " + xArgType.ToString()); XS.Comment("Arg real size = " + xArgRealSize + " aligned size = " + xArgSize); xDisplacement -= (int)(xArgSize - 4); XS.Comment("Real displacement " + xDisplacement); XS.Set(XSRegisters.EBX, (uint)(xDisplacement)); XS.Set(XSRegisters.EAX, XSRegisters.EBP); XS.Add(XSRegisters.EAX, XSRegisters.EBX); XS.Push(XSRegisters.EAX); #endif var xOpVar = (OpVar)aOpCode; DoExecute(Assembler, aMethod, xOpVar.Value); }
public static void DoExecute(Cosmos.Assembler.Assembler Assembler, MethodInfo aMethod, ushort aParam) { var xDisplacement = Ldarg.GetArgumentDisplacement(aMethod, aParam); //var xType = Ldarg.GetArgumentType(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(XSRegisters.EAX, XSRegisters.EBP); XS.Set(XSRegisters.EBX, (uint)(xDisplacement)); XS.Add(XSRegisters.EAX, XSRegisters.EBX); XS.Push(XSRegisters.EAX); }
public static void DoExecute(Cosmos.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 override void Execute(MethodInfo aMethod, ILOpCode aOpCode) { var xOpVar = (OpVar)aOpCode; var xDisplacement = Ldarg.GetArgumentDisplacement(aMethod, xOpVar.Value); new Mov { DestinationReg = RegistersEnum.EBX, SourceValue = (uint)(xDisplacement) }; XS.Set(XSRegisters.OldToNewRegister(RegistersEnum.EAX), XSRegisters.OldToNewRegister(RegistersEnum.EBP)); new CPUx86.Add { DestinationReg = RegistersEnum.EAX, SourceReg = RegistersEnum.EBX }; new CPUx86.Push { DestinationReg = RegistersEnum.EAX }; // if (aMethod.MethodBase.DeclaringType.FullName == "Cosmos.Kernel.Plugs.Console" // && aMethod.MethodBase.Name == "Write" // && aMethod.MethodBase.GetParameters()[0].ParameterType == typeof(int)) // { // Console.Write(""); // } // Cosmos.IL2CPU.ILOpCodes.OpVar xOpVar = ( Cosmos.IL2CPU.ILOpCodes.OpVar )aOpCode; // var xMethodInfo = aMethod.MethodBase as System.Reflection.MethodInfo; // uint xReturnSize = 0; // if( xMethodInfo != null ) // { // xReturnSize = Align( SizeOfType( xMethodInfo.ReturnType ), 4 ); // } // uint xOffset = 8; // var xCorrectedOpValValue = xOpVar.Value; // if( !aMethod.MethodBase.IsStatic && xOpVar.Value > 0 ) // { // // if the method has a $this, the OpCode value includes the this at index 0, but GetParameters() doesnt include the this // xCorrectedOpValValue -= 1; // } // var xParams = aMethod.MethodBase.GetParameters(); // for( int i = xParams.Length - 1; i > xCorrectedOpValValue; i-- ) // { // var xSize = Align( SizeOfType( xParams[ i ].ParameterType ), 4 ); // xOffset += xSize; // } // var xCurArgSize = Align( SizeOfType( xParams[ xCorrectedOpValValue ].ParameterType ), 4 ); // uint xArgSize = 0; // foreach( var xParam in xParams ) // { // xArgSize += Align( SizeOfType( xParam.ParameterType ), 4 ); // } // xReturnSize = 0; // uint xExtraSize = 0; // if( xReturnSize > xArgSize ) // { // xExtraSize = xArgSize - xReturnSize; // } // xOffset += xExtraSize; //#warning TODO: check this // new CPUx86.Push { DestinationReg = CPUx86.Registers.EBP }; // for( int i = 0; i < ( xCurArgSize / 4 ); i++ ) // { // new CPUx86.Push { DestinationValue = ( uint )( xCurArgSize - ( ( i + 1 ) * 4 ) ) }; // } // Assembler.Stack.Push( ( int )xCurArgSize, xParams[ xCorrectedOpValValue ].ParameterType ); // //for( int i = 0; i < ( mSize / 4 ); i++ ) // //{ // // mVirtualAddresses[ i ] = ( mOffset + ( ( i + 1 ) * 4 ) + 4 ); // //} // //mAddress = aMethodInfo.Arguments[ aIndex ].VirtualAddresses.First(); // Assembler.Stack.Push( new StackContents.Item( 4, typeof( uint ) ) ); // //new CPUx86.Push { DestinationValue = ( uint )mAddress }; // // // Assembler.Stack.Push( new StackContents.Item( 4, typeof( uint ) ) ); // new Add( Assembler ).Execute( aMethod, aOpCode ); }