mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-27 22:12:25 +00:00
Merge pull request #201 from ImaBrokeDude/array_plug_fix
Array plug fixes for memory handles
This commit is contained in:
commit
7e03650e56
3 changed files with 52 additions and 39 deletions
|
|
@ -13,6 +13,7 @@ namespace Cosmos.IL2CPU.X86.Plugs.CustomImplementations.System
|
|||
[PlugMethod(Signature = "System_Void__System_Array_Clear_System_Array__System_Int32__System_Int32_")]
|
||||
public static unsafe void Clear(uint* aArray, uint aIndex, uint aLength)
|
||||
{
|
||||
aArray = (uint*)aArray[0];
|
||||
aArray += 3;
|
||||
uint xElementSize = *aArray;
|
||||
aArray += 1;
|
||||
|
|
@ -48,12 +49,14 @@ namespace Cosmos.IL2CPU.X86.Plugs.CustomImplementations.System
|
|||
[PlugMethod(Signature = "System_Boolean__System_Array_TrySZBinarySearch_System_Array__System_Int32__System_Int32__System_Object___System_Int32_")]
|
||||
public static unsafe bool TrySZBinarySearch(uint* aArray, uint sourceIndex, uint count, uint value, out uint retVal)
|
||||
{
|
||||
aArray = (uint*)aArray[0];
|
||||
return TrySZIndexOf(aArray, sourceIndex, count, value, out retVal);
|
||||
}
|
||||
|
||||
[PlugMethod(Signature = "System_Boolean__System_Array_TrySZLastIndexOf_System_Array__System_Int32__System_Int32__System_Object___System_Int32_")]
|
||||
public static unsafe bool TrySZLastIndexOf(uint* aArray, uint sourceIndex, uint count, uint value, out uint retVal)
|
||||
{
|
||||
aArray = (uint*)aArray[0];
|
||||
aArray += 4;
|
||||
for (uint i = (sourceIndex + count); i > sourceIndex; i--)
|
||||
{
|
||||
|
|
@ -70,6 +73,7 @@ namespace Cosmos.IL2CPU.X86.Plugs.CustomImplementations.System
|
|||
//[PlugMethod(Signature = "System_Boolean__System_Array_TrySZIndexOf_System_Array__System_Int32__System_Int32__System_Object__System_Int32__")]
|
||||
private static unsafe bool TrySZIndexOf(uint* aArray, uint sourceIndex, uint count, uint value, out uint retVal)
|
||||
{
|
||||
aArray = (uint*)aArray[0];
|
||||
aArray += 4;
|
||||
for (uint i = sourceIndex; i < (sourceIndex + count); i++)
|
||||
{
|
||||
|
|
@ -95,6 +99,7 @@ namespace Cosmos.IL2CPU.X86.Plugs.CustomImplementations.System
|
|||
|
||||
public static unsafe int GetLowerBound(int* aThis, int aDimension)
|
||||
{
|
||||
aThis = (int*)aThis[0];
|
||||
if (aDimension != 0)
|
||||
{
|
||||
//throw new NotSupportedException("Multidimensional arrays not supported yet!");
|
||||
|
|
@ -105,6 +110,7 @@ namespace Cosmos.IL2CPU.X86.Plugs.CustomImplementations.System
|
|||
[PlugMethod(Signature = "System_Object__System_Array_GetValue_System_Int32_")]
|
||||
public static unsafe uint GetValue(uint* aThis, int aIndex)
|
||||
{
|
||||
aThis = (uint*)aThis[0];
|
||||
aThis += 3;
|
||||
uint xElementSize = *aThis;
|
||||
aThis += 1;
|
||||
|
|
@ -131,6 +137,7 @@ namespace Cosmos.IL2CPU.X86.Plugs.CustomImplementations.System
|
|||
[PlugMethod(Signature = "System_Void__System_Array_SetValue_System_Object__System_Int32_")]
|
||||
public static unsafe void SetValue(uint* aThis, uint aValue, int aIndex)
|
||||
{
|
||||
aThis = (uint*)aThis[0];
|
||||
aThis += 3;
|
||||
uint xElementSize = *aThis;
|
||||
aThis += 1;
|
||||
|
|
|
|||
|
|
@ -3,44 +3,49 @@ using System.Linq;
|
|||
using Cosmos.IL2CPU.Plugs;
|
||||
using CPUx86 = Cosmos.Assembler.x86;
|
||||
|
||||
namespace Cosmos.IL2CPU.X86.Plugs.CustomImplementations.System.Assemblers {
|
||||
public class Array_InternalCopy: AssemblerMethod {
|
||||
namespace Cosmos.IL2CPU.X86.Plugs.CustomImplementations.System.Assemblers
|
||||
{
|
||||
public class Array_InternalCopy : AssemblerMethod
|
||||
{
|
||||
|
||||
/* void Copy(Array sourceArray, ebp + 0x1C
|
||||
* int sourceIndex, ebp + 0x18
|
||||
* Array destinationArray, ebp + 0x14
|
||||
* int destinationIndex, ebp + 0x10
|
||||
* int length, ebp + 0xC
|
||||
* bool reliable); ebp + 0x8
|
||||
*/
|
||||
public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object aMethodInfo) {
|
||||
new CPUx86.Push { DestinationReg = CPUx86.Registers.EBP, DestinationIsIndirect = true, DestinationDisplacement = 0x1C };
|
||||
new CPUx86.Add { DestinationReg = CPUx86.Registers.ESP, DestinationIsIndirect = true, SourceValue = 12, Size = 32 }; // pointer is at the element size
|
||||
new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX };
|
||||
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.EAX, SourceIsIndirect = true }; // element size
|
||||
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EBX, SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = 0x18 };
|
||||
new CPUx86.Multiply { DestinationReg = CPUx86.Registers.EBX };
|
||||
new CPUx86.Add { DestinationReg = CPUx86.Registers.EAX, SourceValue = 16 };
|
||||
new CPUx86.Mov { DestinationReg = CPUx86.Registers.ESI, SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = 0x1C };
|
||||
new CPUx86.Add { DestinationReg = CPUx86.Registers.ESI, SourceReg = CPUx86.Registers.EAX }; // source ptr
|
||||
new CPUx86.Push { DestinationReg = CPUx86.Registers.EBP, DestinationIsIndirect = true, DestinationDisplacement = 0x14 };
|
||||
new CPUx86.Add { DestinationReg = CPUx86.Registers.ESP, DestinationIsIndirect = true, SourceValue = 12, Size = 32 }; // pointer is at element size
|
||||
new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX };
|
||||
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.EAX, SourceIsIndirect = true };
|
||||
new CPUx86.Mov { DestinationReg = CPUx86.Registers.ECX, SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = 0x10 };
|
||||
new CPUx86.Multiply { DestinationReg = CPUx86.Registers.ECX };
|
||||
new CPUx86.Add { DestinationReg = CPUx86.Registers.EAX, SourceValue = 16 };
|
||||
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = 0x14 };
|
||||
new CPUx86.Add { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EAX };
|
||||
/* void Copy(Array sourceArray, ebp + 0x1C
|
||||
* int sourceIndex, ebp + 0x18
|
||||
* Array destinationArray, ebp + 0x14
|
||||
* int destinationIndex, ebp + 0x10
|
||||
* int length, ebp + 0xC
|
||||
* bool reliable); ebp + 0x8
|
||||
*/
|
||||
public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object aMethodInfo)
|
||||
{
|
||||
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = 8 };
|
||||
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.EAX, SourceIsIndirect = true };
|
||||
new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX };
|
||||
new CPUx86.Add { DestinationReg = CPUx86.Registers.ESP, DestinationIsIndirect = true, SourceValue = 12, Size = 32 }; // pointer is at the element size
|
||||
new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX };
|
||||
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.EAX, SourceIsIndirect = true }; // element size
|
||||
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EBX, SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = 0x18 };
|
||||
new CPUx86.Multiply { DestinationReg = CPUx86.Registers.EBX };
|
||||
new CPUx86.Add { DestinationReg = CPUx86.Registers.EAX, SourceValue = 16 };
|
||||
new CPUx86.Mov { DestinationReg = CPUx86.Registers.ESI, SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = 0x1C };
|
||||
new CPUx86.Add { DestinationReg = CPUx86.Registers.ESI, SourceReg = CPUx86.Registers.EAX }; // source ptr
|
||||
new CPUx86.Push { DestinationReg = CPUx86.Registers.EBP, DestinationIsIndirect = true, DestinationDisplacement = 0x14 };
|
||||
new CPUx86.Add { DestinationReg = CPUx86.Registers.ESP, DestinationIsIndirect = true, SourceValue = 12, Size = 32 }; // pointer is at element size
|
||||
new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX };
|
||||
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.EAX, SourceIsIndirect = true };
|
||||
new CPUx86.Mov { DestinationReg = CPUx86.Registers.ECX, SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = 0x10 };
|
||||
new CPUx86.Multiply { DestinationReg = CPUx86.Registers.ECX };
|
||||
new CPUx86.Add { DestinationReg = CPUx86.Registers.EAX, SourceValue = 16 };
|
||||
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = 0x14 };
|
||||
new CPUx86.Add { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EAX };
|
||||
|
||||
// calculate byte count to copy
|
||||
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = 0x14 };
|
||||
new CPUx86.Add { DestinationReg = CPUx86.Registers.EAX, SourceValue = 12 };
|
||||
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.EAX, SourceIsIndirect = true };
|
||||
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDX, SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = 0xC };
|
||||
new CPUx86.Multiply { DestinationReg = CPUx86.Registers.EDX };
|
||||
new CPUx86.Mov { DestinationReg = CPUx86.Registers.ECX, SourceReg = CPUx86.Registers.EAX, };
|
||||
new CPUx86.Movs { Size = 8, Prefixes = CPUx86.InstructionPrefixes.Repeat };
|
||||
// calculate byte count to copy
|
||||
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = 0x14 };
|
||||
new CPUx86.Add { DestinationReg = CPUx86.Registers.EAX, SourceValue = 12 };
|
||||
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.EAX, SourceIsIndirect = true };
|
||||
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDX, SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = 0xC };
|
||||
new CPUx86.Multiply { DestinationReg = CPUx86.Registers.EDX };
|
||||
new CPUx86.Mov { DestinationReg = CPUx86.Registers.ECX, SourceReg = CPUx86.Registers.EAX, };
|
||||
new CPUx86.Movs { Size = 8, Prefixes = CPUx86.InstructionPrefixes.Repeat };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,12 +7,13 @@ using Cosmos.Assembler.x86;
|
|||
|
||||
namespace Cosmos.IL2CPU.X86.Plugs.CustomImplementations.System.Assemblers
|
||||
{
|
||||
public class Array_get_Length: AssemblerMethod
|
||||
public class Array_get_Length : AssemblerMethod
|
||||
{
|
||||
public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object aMethodInfo)
|
||||
{
|
||||
// $this ebp+8
|
||||
// $this ebp+8
|
||||
new Mov { DestinationReg = Registers.EAX, SourceReg = Registers.EBP, SourceIsIndirect = true, SourceDisplacement = 8 };
|
||||
new Mov { DestinationReg = Registers.EAX, SourceReg = Registers.EAX, SourceIsIndirect = true };
|
||||
new Push { DestinationIsIndirect = true, DestinationReg = Registers.EAX, DestinationDisplacement = 8 };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue