forked from CosmosOS/Cosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
107 additions
and
7 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
Cosmos/source/Kernel-X86/10-CPU/Cosmos.CPU_Asm/Array/ArrayGetLengthAsm.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Cosmos.Assembler; | ||
using XSharp.Common; | ||
|
||
namespace Cosmos.CPU_Asm | ||
{ | ||
public class ArrayGetLengthAsm : AssemblerMethod | ||
{ | ||
public override void AssembleNew(Assembler.Assembler aAssembler, object aMethodInfo) | ||
{ | ||
// $this ebp+8 | ||
XS.Set(XSRegisters.EAX, XSRegisters.EBP, sourceDisplacement: 8); | ||
XS.Set(XSRegisters.EAX, XSRegisters.EAX, sourceDisplacement: 8, sourceIsIndirect: true); // element count | ||
XS.Push(XSRegisters.EAX); | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
Cosmos/source/Kernel-X86/10-CPU/Cosmos.CPU_Asm/Array/ArrayInternalCopyAsm.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using Cosmos.Assembler; | ||
using Cosmos.IL2CPU.API; | ||
using XSharp.Common; | ||
using CPUx86 = Cosmos.Assembler.x86; | ||
|
||
namespace Cosmos.CPU_Asm | ||
{ | ||
public class ArrayInternalCopyAsm : AssemblerMethod | ||
{ | ||
private const int SourceArrayDisplacement = 36; | ||
private const int SourceIndexDisplacement = 32; | ||
private const int DestinationArrayDisplacement = 24; | ||
private const int DestinationIndexDisplacement = 16; | ||
private const int LengthDisplacement = 12; | ||
|
||
/* void Copy( | ||
* Array sourceArray, ebp + 36 | ||
* int sourceIndex, ebp + 28 | ||
* Array destinationArray, ebp + 24 | ||
* int destinationIndex, ebp + 16 | ||
* int length, ebp + 12 | ||
* bool reliable); ebp + 8 | ||
*/ | ||
|
||
public override void AssembleNew(Assembler.Assembler aAssembler, object aMethodInfo) | ||
{ | ||
XS.Comment("Source"); | ||
XS.Comment("Element size"); | ||
XS.Set(XSRegisters.EAX, XSRegisters.EBP, sourceDisplacement: SourceArrayDisplacement); | ||
XS.Add(XSRegisters.EAX, ObjectUtils.FieldDataOffset); | ||
XS.Set(XSRegisters.EAX, XSRegisters.EAX, sourceIsIndirect: true); // element size | ||
XS.Comment("Source ptr"); | ||
XS.Set(XSRegisters.EBX, XSRegisters.EBP, sourceDisplacement: SourceIndexDisplacement); | ||
XS.Multiply(XSRegisters.EBX); | ||
XS.Add(XSRegisters.EAX, ObjectUtils.FieldDataOffset + 4); // first element | ||
XS.Set(XSRegisters.ESI, XSRegisters.EBP, sourceDisplacement: SourceArrayDisplacement); | ||
XS.Add(XSRegisters.ESI, XSRegisters.EAX); // source ptr | ||
|
||
XS.Comment("Destination"); | ||
XS.Comment("Element size"); | ||
XS.Set(XSRegisters.EAX, XSRegisters.EBP, sourceDisplacement: DestinationArrayDisplacement); | ||
XS.Add(XSRegisters.EAX, ObjectUtils.FieldDataOffset); | ||
XS.Set(XSRegisters.EAX, XSRegisters.EAX, sourceIsIndirect: true); // element size | ||
XS.Comment("Destination ptr"); | ||
XS.Set(XSRegisters.ECX, XSRegisters.EBP, sourceDisplacement: DestinationIndexDisplacement); | ||
XS.Multiply(XSRegisters.ECX); | ||
XS.Add(XSRegisters.EAX, ObjectUtils.FieldDataOffset + 4); // first element | ||
XS.Set(XSRegisters.EDI, XSRegisters.EBP, sourceDisplacement: DestinationArrayDisplacement); | ||
XS.Add(XSRegisters.EDI, XSRegisters.EAX); // destination ptr | ||
|
||
XS.Comment("Copy byte count"); | ||
XS.Comment("Element size"); | ||
XS.Set(XSRegisters.EAX, XSRegisters.EBP, sourceDisplacement: DestinationArrayDisplacement); | ||
XS.Add(XSRegisters.EAX, ObjectUtils.FieldDataOffset); | ||
XS.Set(XSRegisters.EAX, XSRegisters.EAX, sourceIsIndirect: true); // element size | ||
XS.Comment("Count"); | ||
XS.Set(XSRegisters.EDX, XSRegisters.EBP, sourceDisplacement: LengthDisplacement); | ||
XS.Multiply(XSRegisters.EDX); | ||
XS.Set(XSRegisters.ECX, XSRegisters.EAX); | ||
new CPUx86.Movs { Size = 8, Prefixes = CPUx86.InstructionPrefixes.Repeat }; | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Cosmos/source/Kernel-X86/10-CPU/Cosmos.CPU_Asm/ArrayImpl.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using Cosmos.IL2CPU.API.Attribs; | ||
|
||
namespace Cosmos.CPU_Asm | ||
{ | ||
[Plug(Target = typeof(Array))] | ||
public class ArrayImpl | ||
{ | ||
[PlugMethod(Assembler = typeof(ArrayGetLengthAsm))] | ||
public static int get_Length(Array aThis) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
[PlugMethod(Assembler = typeof(ArrayInternalCopyAsm))] | ||
public static void Copy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length, bool reliable) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters