mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-24 12:35:31 +00:00
.
This commit is contained in:
parent
8a87dfff87
commit
9d203f141e
4 changed files with 71 additions and 36 deletions
|
|
@ -34,7 +34,7 @@ namespace Cosmos.IL2CPU.X86.IL
|
||||||
for (int i = 0; i < (xSize / 4); i++)
|
for (int i = 0; i < (xSize / 4); i++)
|
||||||
{
|
{
|
||||||
XS.Pop(OldToNewRegister(CPUx86.RegistersEnum.EDX));
|
XS.Pop(OldToNewRegister(CPUx86.RegistersEnum.EDX));
|
||||||
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.ESI, DestinationIsIndirect = true, DestinationDisplacement = (ObjectImpl.FieldDataOffset + (i * 4)), SourceReg = CPUx86.RegistersEnum.EDX, Size = 32 };
|
XS.Set(ESI, EDX, destinationDisplacement: (ObjectImpl.FieldDataOffset + (i * 4)), size: RegisterSize.Int32);
|
||||||
}
|
}
|
||||||
XS.Push(OldToNewRegister(CPUx86.RegistersEnum.EAX));
|
XS.Push(OldToNewRegister(CPUx86.RegistersEnum.EAX));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ using CPU = Cosmos.Assembler.x86;
|
||||||
using CPUx86 = Cosmos.Assembler.x86;
|
using CPUx86 = Cosmos.Assembler.x86;
|
||||||
using Cosmos.Assembler;
|
using Cosmos.Assembler;
|
||||||
using XSharp.Compiler;
|
using XSharp.Compiler;
|
||||||
|
using static XSharp.Compiler.XSRegisters;
|
||||||
|
|
||||||
namespace Cosmos.IL2CPU.X86.IL
|
namespace Cosmos.IL2CPU.X86.IL
|
||||||
{
|
{
|
||||||
|
|
@ -16,7 +17,7 @@ namespace Cosmos.IL2CPU.X86.IL
|
||||||
|
|
||||||
public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
|
public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
|
||||||
{
|
{
|
||||||
XS.Pop(XSRegisters.OldToNewRegister(CPU.RegistersEnum.ECX)); // shift amount
|
XS.Pop(OldToNewRegister(CPU.RegistersEnum.ECX)); // shift amount
|
||||||
var xStackItem_ShiftAmount = aOpCode.StackPopTypes[0];
|
var xStackItem_ShiftAmount = aOpCode.StackPopTypes[0];
|
||||||
var xStackItem_Value = aOpCode.StackPopTypes[1];
|
var xStackItem_Value = aOpCode.StackPopTypes[1];
|
||||||
var xStackItem_Value_Size = SizeOfType(xStackItem_Value);
|
var xStackItem_Value_Size = SizeOfType(xStackItem_Value);
|
||||||
|
|
@ -42,7 +43,7 @@ namespace Cosmos.IL2CPU.X86.IL
|
||||||
// [ESP + 4] is high part
|
// [ESP + 4] is high part
|
||||||
|
|
||||||
// move high part in EAX
|
// move high part in EAX
|
||||||
XS.Set(XSRegisters.OldToNewRegister(CPU.RegistersEnum.EAX), XSRegisters.OldToNewRegister(CPU.RegistersEnum.ESP), sourceDisplacement: 4);
|
XS.Set(OldToNewRegister(CPU.RegistersEnum.EAX), OldToNewRegister(CPU.RegistersEnum.ESP), sourceDisplacement: 4);
|
||||||
|
|
||||||
new CPUx86.Compare { DestinationReg = CPUx86.RegistersEnum.CL, SourceValue = 32, Size = 8 };
|
new CPUx86.Compare { DestinationReg = CPUx86.RegistersEnum.CL, SourceValue = 32, Size = 8 };
|
||||||
XS.Jump(CPU.ConditionalTestEnum.AboveOrEqual, HighPartIsZero);
|
XS.Jump(CPU.ConditionalTestEnum.AboveOrEqual, HighPartIsZero);
|
||||||
|
|
@ -50,7 +51,7 @@ namespace Cosmos.IL2CPU.X86.IL
|
||||||
// shift lower part
|
// shift lower part
|
||||||
new CPUx86.ShiftRightDouble { DestinationReg = CPUx86.RegistersEnum.ESP, DestinationIsIndirect = true, SourceReg = CPUx86.RegistersEnum.EAX, ArgumentReg = CPUx86.RegistersEnum.CL };
|
new CPUx86.ShiftRightDouble { DestinationReg = CPUx86.RegistersEnum.ESP, DestinationIsIndirect = true, SourceReg = CPUx86.RegistersEnum.EAX, ArgumentReg = CPUx86.RegistersEnum.CL };
|
||||||
// shift higher part
|
// shift higher part
|
||||||
new CPUx86.ShiftRight { DestinationReg = CPUx86.RegistersEnum.ESP, DestinationIsIndirect = true, DestinationDisplacement = 4, Size = 32, SourceReg = CPUx86.RegistersEnum.CL };
|
XS.ShiftRight(ESP, CL, destinationDisplacement: 4, size: RegisterSize.Int32);
|
||||||
XS.Jump(End_Shr);
|
XS.Jump(End_Shr);
|
||||||
|
|
||||||
XS.Label(HighPartIsZero);
|
XS.Label(HighPartIsZero);
|
||||||
|
|
@ -59,7 +60,7 @@ namespace Cosmos.IL2CPU.X86.IL
|
||||||
|
|
||||||
// shift high part and move it in low part
|
// shift high part and move it in low part
|
||||||
new CPUx86.ShiftRight{ DestinationReg = CPUx86.RegistersEnum.EAX, Size = 32, SourceReg = CPUx86.RegistersEnum.CL };
|
new CPUx86.ShiftRight{ DestinationReg = CPUx86.RegistersEnum.EAX, Size = 32, SourceReg = CPUx86.RegistersEnum.CL };
|
||||||
XS.Set(XSRegisters.ESP, XSRegisters.EAX, destinationIsIndirect: true);
|
XS.Set(ESP, EAX, destinationIsIndirect: true);
|
||||||
// replace unknown high part with a zero, if <= 32
|
// replace unknown high part with a zero, if <= 32
|
||||||
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.ESP, DestinationIsIndirect = true, DestinationDisplacement = 4, SourceValue = 0};
|
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.ESP, DestinationIsIndirect = true, DestinationDisplacement = 4, SourceValue = 0};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ using CPUx86 = Cosmos.Assembler.x86;
|
||||||
using CPU = Cosmos.Assembler.x86;
|
using CPU = Cosmos.Assembler.x86;
|
||||||
using Cosmos.Assembler;
|
using Cosmos.Assembler;
|
||||||
using XSharp.Compiler;
|
using XSharp.Compiler;
|
||||||
|
using static XSharp.Compiler.XSRegisters;
|
||||||
|
|
||||||
namespace Cosmos.IL2CPU.X86.IL
|
namespace Cosmos.IL2CPU.X86.IL
|
||||||
{
|
{
|
||||||
|
|
@ -26,27 +27,27 @@ namespace Cosmos.IL2CPU.X86.IL
|
||||||
var xStackItem_Value_Size = SizeOfType(xStackItem_Value);
|
var xStackItem_Value_Size = SizeOfType(xStackItem_Value);
|
||||||
if( xStackItem_Value_Size <= 4 )
|
if( xStackItem_Value_Size <= 4 )
|
||||||
{
|
{
|
||||||
XS.Pop(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX)); // shift amount
|
XS.Pop(OldToNewRegister(CPUx86.RegistersEnum.EAX)); // shift amount
|
||||||
XS.Pop(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBX)); // value
|
XS.Pop(OldToNewRegister(CPUx86.RegistersEnum.EBX)); // value
|
||||||
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.CL), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.AL));
|
XS.Set(OldToNewRegister(CPUx86.RegistersEnum.CL), OldToNewRegister(CPUx86.RegistersEnum.AL));
|
||||||
XS.ShiftRight(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBX), XSRegisters.CL);
|
XS.ShiftRight(OldToNewRegister(CPUx86.RegistersEnum.EBX), CL);
|
||||||
XS.Push(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBX));
|
XS.Push(OldToNewRegister(CPUx86.RegistersEnum.EBX));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if( xStackItem_Value_Size <= 8 )
|
if( xStackItem_Value_Size <= 8 )
|
||||||
{
|
{
|
||||||
XS.Pop(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDX));
|
XS.Pop(OldToNewRegister(CPUx86.RegistersEnum.EDX));
|
||||||
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), 0);
|
XS.Set(OldToNewRegister(CPUx86.RegistersEnum.EAX), 0);
|
||||||
XS.Label(xBaseLabel + "__StartLoop" );
|
XS.Label(xBaseLabel + "__StartLoop" );
|
||||||
XS.Compare(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX));
|
XS.Compare(OldToNewRegister(CPUx86.RegistersEnum.EDX), OldToNewRegister(CPUx86.RegistersEnum.EAX));
|
||||||
XS.Jump(CPUx86.ConditionalTestEnum.Equal, xBaseLabel + "__EndLoop");
|
XS.Jump(CPUx86.ConditionalTestEnum.Equal, xBaseLabel + "__EndLoop");
|
||||||
XS.Set(XSRegisters.EBX, XSRegisters.ESP, sourceIsIndirect: true);
|
XS.Set(EBX, ESP, sourceIsIndirect: true);
|
||||||
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.CL), 1);
|
XS.Set(OldToNewRegister(CPUx86.RegistersEnum.CL), 1);
|
||||||
XS.ShiftRight(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBX), XSRegisters.CL);
|
XS.ShiftRight(OldToNewRegister(CPUx86.RegistersEnum.EBX), CL);
|
||||||
XS.Set(XSRegisters.ESP, XSRegisters.EBX, destinationIsIndirect: true);
|
XS.Set(ESP, EBX, destinationIsIndirect: true);
|
||||||
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.CL), 1);
|
XS.Set(OldToNewRegister(CPUx86.RegistersEnum.CL), 1);
|
||||||
new CPUx86.RotateThroughCarryRight { DestinationReg = CPUx86.RegistersEnum.ESP, DestinationIsIndirect = true, DestinationDisplacement = 4, Size = 32, SourceReg = CPUx86.RegistersEnum.CL };
|
XS.RotateThroughCarryRight(ESP, CL, destinationDisplacement: 4, size: RegisterSize.Int32);
|
||||||
XS.Add(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), 1);
|
XS.Add(OldToNewRegister(CPUx86.RegistersEnum.EAX), 1);
|
||||||
new CPUx86.Jump { DestinationLabel = xBaseLabel + "__StartLoop" };
|
new CPUx86.Jump { DestinationLabel = xBaseLabel + "__StartLoop" };
|
||||||
|
|
||||||
XS.Label(xBaseLabel + "__EndLoop" );
|
XS.Label(xBaseLabel + "__EndLoop" );
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,8 @@ namespace XSharp.Compiler
|
||||||
int? destinationDisplacement = null,
|
int? destinationDisplacement = null,
|
||||||
bool sourceIsIndirect = false,
|
bool sourceIsIndirect = false,
|
||||||
int? sourceDisplacement = null,
|
int? sourceDisplacement = null,
|
||||||
bool skipSizeCheck = false)
|
bool skipSizeCheck = false,
|
||||||
|
RegisterSize? size = null)
|
||||||
where T : InstructionWithDestinationAndSourceAndSize, new()
|
where T : InstructionWithDestinationAndSourceAndSize, new()
|
||||||
{
|
{
|
||||||
if (destinationDisplacement != null)
|
if (destinationDisplacement != null)
|
||||||
|
|
@ -256,19 +257,21 @@ namespace XSharp.Compiler
|
||||||
{
|
{
|
||||||
throw new Exception("Both destination and source cannot be indirect!");
|
throw new Exception("Both destination and source cannot be indirect!");
|
||||||
}
|
}
|
||||||
RegisterSize xSize;
|
if (size == null)
|
||||||
if (!destinationIsIndirect)
|
|
||||||
{
|
{
|
||||||
xSize = destination.Size;
|
if (!destinationIsIndirect)
|
||||||
}
|
{
|
||||||
else
|
size = destination.Size;
|
||||||
{
|
}
|
||||||
xSize = source.Size;
|
else
|
||||||
|
{
|
||||||
|
size = source.Size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new T
|
new T
|
||||||
{
|
{
|
||||||
Size = (byte)xSize,
|
Size = (byte)size,
|
||||||
DestinationReg = destination.RegEnum,
|
DestinationReg = destination.RegEnum,
|
||||||
DestinationIsIndirect = destinationIsIndirect,
|
DestinationIsIndirect = destinationIsIndirect,
|
||||||
DestinationDisplacement = destinationDisplacement,
|
DestinationDisplacement = destinationDisplacement,
|
||||||
|
|
@ -591,9 +594,9 @@ namespace XSharp.Compiler
|
||||||
Do<Mov>(destination, value, destinationIsIndirect, destinationDisplacement, sourceIsIndirect, sourceDisplacement, size);
|
Do<Mov>(destination, value, destinationIsIndirect, destinationDisplacement, sourceIsIndirect, sourceDisplacement, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Set(Register destination, Register source, bool destinationIsIndirect = false, int? destinationDisplacement = null, bool sourceIsIndirect = false, int? sourceDisplacement = null)
|
public static void Set(Register destination, Register source, bool destinationIsIndirect = false, int? destinationDisplacement = null, bool sourceIsIndirect = false, int? sourceDisplacement = null, RegisterSize? size = null)
|
||||||
{
|
{
|
||||||
Do<Mov>(destination, source, destinationIsIndirect, destinationDisplacement, sourceIsIndirect, sourceDisplacement);
|
Do<Mov>(destination, source, destinationIsIndirect, destinationDisplacement, sourceIsIndirect, sourceDisplacement, size: size);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetByte(uint address, byte value)
|
public static void SetByte(uint address, byte value)
|
||||||
|
|
@ -658,18 +661,18 @@ namespace XSharp.Compiler
|
||||||
Do<RotateLeft>(register, bitCount);
|
Do<RotateLeft>(register, bitCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ShiftRight(Register register, byte bitCount)
|
public static void ShiftRight(Register destination, byte bitCount)
|
||||||
{
|
{
|
||||||
Do<ShiftRight>(register, bitCount);
|
Do<ShiftRight>(destination, bitCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ShiftRight(Register register, Register8 bitCount)
|
public static void ShiftRight(Register destination, Register8 source, bool destinationIsIndirect = false, int? destinationDisplacement = null, RegisterSize? size = null)
|
||||||
{
|
{
|
||||||
if (bitCount != CL)
|
if (source != CL)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException();
|
throw new InvalidOperationException();
|
||||||
}
|
}
|
||||||
Do<ShiftRight>(register, bitCount, skipSizeCheck: true);
|
Do<ShiftRight>(destination, source, skipSizeCheck: true, destinationIsIndirect:destinationIsIndirect, destinationDisplacement: destinationDisplacement, size: size);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ShiftLeft(Register register, byte bitCount)
|
public static void ShiftLeft(Register register, byte bitCount)
|
||||||
|
|
@ -1113,5 +1116,35 @@ namespace XSharp.Compiler
|
||||||
DestinationIsIndirect = isIndirect
|
DestinationIsIndirect = isIndirect
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void RotateThroughCarryRight(string destination, Register source, bool destinationIsIndirect = false, int? destinationDisplacement = null, bool sourceIsIndirect = false, int? sourceDisplacement = null, RegisterSize? size = null)
|
||||||
|
{
|
||||||
|
Do<RotateThroughCarryRight>(destination, source, destinationIsIndirect, destinationDisplacement, sourceIsIndirect, sourceDisplacement, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RotateThroughCarryRight(string destination, UInt32 value, bool destinationIsIndirect = false, int? destinationDisplacement = null, bool sourceIsIndirect = false, int? sourceDisplacement = null, RegisterSize size = RegisterSize.Int32)
|
||||||
|
{
|
||||||
|
Do<RotateThroughCarryRight>(destination, value, destinationIsIndirect, destinationDisplacement, sourceIsIndirect, sourceDisplacement, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RotateThroughCarryRight(string destination, string source, bool destinationIsIndirect = false, int? destinationDisplacement = null, bool sourceIsIndirect = false, int? sourceDisplacement = null, RegisterSize size = RegisterSize.Int32)
|
||||||
|
{
|
||||||
|
Do<RotateThroughCarryRight>(destination, source, destinationIsIndirect, destinationDisplacement, sourceIsIndirect, sourceDisplacement, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RotateThroughCarryRight(Register destination, string sourceLabel, bool destinationIsIndirect = false, int? destinationDisplacement = null, bool sourceIsIndirect = false, int? sourceDisplacement = null, RegisterSize? size = null)
|
||||||
|
{
|
||||||
|
Do<RotateThroughCarryRight>(destination, sourceLabel, destinationIsIndirect, destinationDisplacement, sourceIsIndirect, sourceDisplacement, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RotateThroughCarryRight(Register destination, uint value, bool destinationIsIndirect = false, int? destinationDisplacement = null, bool sourceIsIndirect = false, int? sourceDisplacement = null, RegisterSize? size = null)
|
||||||
|
{
|
||||||
|
Do<RotateThroughCarryRight>(destination, value, destinationIsIndirect, destinationDisplacement, sourceIsIndirect, sourceDisplacement, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RotateThroughCarryRight(Register destination, Register source, bool destinationIsIndirect = false, int? destinationDisplacement = null, bool sourceIsIndirect = false, int? sourceDisplacement = null, RegisterSize? size = null)
|
||||||
|
{
|
||||||
|
Do<RotateThroughCarryRight>(destination, source, destinationIsIndirect, destinationDisplacement, sourceIsIndirect, sourceDisplacement, size: size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue