Skip to content

Commit

Permalink
g3
Browse files Browse the repository at this point in the history
  • Loading branch information
czhower committed Aug 8, 2017
1 parent 09b0ff7 commit 56d1acc
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 7 deletions.
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);
}
}
}
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 Cosmos/source/Kernel-X86/10-CPU/Cosmos.CPU_Asm/ArrayImpl.cs
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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
</ItemGroup>

<ItemGroup>
<ProjectReference PrivateAssets="All" Include="..\..\..\Cosmos.Assembler\Cosmos.Assembler.csproj"/>
<ProjectReference PrivateAssets="All" Include="..\..\..\Cosmos.Debug.Kernel\Cosmos.Debug.Kernel.csproj"/>
<ProjectReference PrivateAssets="All" Include="..\..\..\Cosmos.IL2CPU.API\Cosmos.IL2CPU.API.csproj"/>
<ProjectReference PrivateAssets="All" Include="..\..\..\Cosmos.IL2CPU\Cosmos.IL2CPU.csproj"/>
<ProjectReference PrivateAssets="All" Include="..\..\..\XSharp.Common\XSharp.Common.csproj"/>
<ProjectReference PrivateAssets="All" Include="..\Cosmos.CPU.x86\Cosmos.CPU.x86.csproj"/>
<ProjectReference PrivateAssets="All" Include="..\..\..\Cosmos.Assembler\Cosmos.Assembler.csproj" />
<ProjectReference PrivateAssets="All" Include="..\..\..\Cosmos.Debug.Kernel\Cosmos.Debug.Kernel.csproj" />
<ProjectReference PrivateAssets="All" Include="..\..\..\Cosmos.IL2CPU.API\Cosmos.IL2CPU.API.csproj" />
<ProjectReference PrivateAssets="All" Include="..\..\..\Cosmos.IL2CPU\Cosmos.IL2CPU.csproj" />
<ProjectReference PrivateAssets="All" Include="..\..\..\XSharp.Common\XSharp.Common.csproj" />
<ProjectReference PrivateAssets="All" Include="..\Cosmos.CPU.x86\Cosmos.CPU.x86.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Cosmos/source/Kernel-X86/30-HAL/Cosmos.HAL/DeviceMgr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public Processor Processor {
}

public void Add(Devices.Device aDevice) {
//mAll.Add(aDevice);
mAll.Add(aDevice);

if (aDevice is Processor) {
mProcessor = (Processor)aDevice;
Expand Down

0 comments on commit 56d1acc

Please sign in to comment.