Skip to content

Commit

Permalink
Fixed delegates and moved some assemblers.
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesbetros committed Sep 29, 2016
1 parent 2c27520 commit 4b67c02
Show file tree
Hide file tree
Showing 33 changed files with 403 additions and 498 deletions.
8 changes: 4 additions & 4 deletions Tests/Cosmos.Compiler.Tests.Bcl/System/DelegatesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ private static void TestDelegateWithoutArguments()
{
mCount = 0;
Action xDelegate = IncreaseCounterOnce;

xDelegate();
Assert.AreEqual(1, mCount, "After calling delegate once, Count != 1");

mCount = 0;
var xTestInstance = new DelegatesTest();
xDelegate = xTestInstance.IncreaseCounterTwiceFromInstanceMethod;
mCount = 0;
xDelegate();
Assert.AreEqual(2, mCount, "After calling delegate second time, Count != 2");
}
Expand Down Expand Up @@ -68,12 +68,12 @@ private static void TestDelegateWithArguments()
{
mCount = 0;
Action<int> xDelegate = IncreaseCounter;

xDelegate(2);
Assert.AreEqual(2, mCount, "After calling delegate once, Count != 2");

mCount = 0;
var xTestInstance = new DelegatesTest();
xDelegate = xTestInstance.IncreaseCounterFromInstanceMethod;
mCount = 0;
xDelegate(3);
Assert.AreEqual(3, mCount, "After calling delegate second time, Count != 3");
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/Cosmos.TestRunner.Core/DefaultEngineConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public static void Apply(Engine engine)

// If you're working on the compiler (or other lower parts), you can choose to run the compiler in process
// one thing to keep in mind though, is that this only works with 1 kernel at a time!
engine.RunIL2CPUInProcess = true;
engine.RunIL2CPUInProcess = false;
engine.TraceAssembliesLevel = TraceAssemblies.User;
//engine.EnableStackCorruptionChecks = false;

engine.EnableStackCorruptionChecks = true;
engine.StackCorruptionChecksLevel = StackCorruptionDetectionLevel.AllInstructions;

engine.RunWithGDB = true;
engine.StartBochsDebugGui = true;
//engine.RunWithGDB = true;
//engine.StartBochsDebugGui = true;

// Select kernels to be tested by adding them to the engine
foreach (var xType in TestKernelSets.GetStableKernelTypes())
Expand Down
17 changes: 8 additions & 9 deletions Tests/Cosmos.TestRunner.Core/TestKernelSets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ public static class TestKernelSets
{
public static IEnumerable<Type> GetStableKernelTypes()
{
//yield return typeof(VGACompilerCrash.Kernel);
yield return typeof(VGACompilerCrash.Kernel);
yield return typeof(Cosmos.Compiler.Tests.Bcl.Kernel);
//yield return typeof(Cosmos.Compiler.Tests.SingleEchoTest.Kernel);
//yield return typeof(Cosmos.Compiler.Tests.SimpleWriteLine.Kernel.Kernel);
//yield return typeof(SimpleStructsAndArraysTest.Kernel);
//yield return typeof(Cosmos.Compiler.Tests.Exceptions.Kernel);
//yield return typeof(Cosmos.Compiler.Tests.LinqTests.Kernel);
//yield return typeof(Cosmos.Compiler.Tests.MethodTests.Kernel);
yield return typeof(Cosmos.Compiler.Tests.SingleEchoTest.Kernel);
yield return typeof(Cosmos.Compiler.Tests.SimpleWriteLine.Kernel.Kernel);
yield return typeof(SimpleStructsAndArraysTest.Kernel);
yield return typeof(Cosmos.Compiler.Tests.Exceptions.Kernel);
yield return typeof(Cosmos.Compiler.Tests.LinqTests.Kernel);
yield return typeof(Cosmos.Compiler.Tests.MethodTests.Kernel);
yield return typeof(Cosmos.Kernel.Tests.IO.Kernel);

//yield return typeof(Cosmos.Kernel.Tests.Fat.Kernel);
//yield return typeof(Cosmos.Kernel.Tests.IO.Kernel);

//yield return typeof(Cosmos.Compiler.Tests.Encryption.Kernel);
//yield return typeof(FrotzKernel.Kernel);
}
Expand Down
14 changes: 0 additions & 14 deletions source/Cosmos.Core.Plugs/Assemblers/DisableInterruptsAssembler.cs

This file was deleted.

14 changes: 0 additions & 14 deletions source/Cosmos.Core.Plugs/Assemblers/EnableInterruptsAssembler.cs

This file was deleted.

195 changes: 46 additions & 149 deletions source/Cosmos.Core.Plugs/CPUImpl.cs
Original file line number Diff line number Diff line change
@@ -1,161 +1,58 @@
using System;
using System.Collections.Generic;
using System.Text;
using Cosmos.IL2CPU.Plugs;
using XSharp.Compiler;
using Assembler = Cosmos.Assembler.Assembler;
using CPUAll = Cosmos.Assembler;
using CPUx86 = Cosmos.Assembler.x86;

namespace Cosmos.Core.Plugs {
[Plug(Target = typeof(Core.CPU))]
public class CPUImpl {
[PlugMethod(Assembler = typeof(UpdateIDT))]
public static void UpdateIDT(CPU aThis, bool aEnableInterruptsImmediately) {
}

public class GetAmountOfRAMAsm : AssemblerMethod {
public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object aMethodInfo) {
XS.Set(XSRegisters.EAX, "MultiBootInfo_Memory_High", sourceIsIndirect: true);
XS.Xor(XSRegisters.EDX, XSRegisters.EDX);
XS.Set(XSRegisters.ECX, 1024);
XS.Divide(XSRegisters.ECX);
XS.Add(XSRegisters.EAX, 1);
XS.Push(XSRegisters.EAX);
}
}

[PlugMethod(Assembler = typeof(GetAmountOfRAMAsm))]
public static uint GetAmountOfRAM() { return 0; }

public class GetEndOfKernelAsm : AssemblerMethod {
public override void AssembleNew(CPUAll.Assembler aAssembler, object aMethodInfo) {
XS.Push("_end_code");
}
}

[PlugMethod(Assembler = typeof(GetEndOfKernelAsm))]
public static uint GetEndOfKernel() {
return 0;
}

public class ZeroFillAsm : AssemblerMethod {
public override void AssembleNew(CPUAll.Assembler aAssembler, object aMethodInfo) {
XS.ClearDirectionFlag();
XS.Set(XSRegisters.EDI, XSRegisters.EBP, sourceDisplacement: 0xC); //address
XS.Set(XSRegisters.ECX, XSRegisters.EBP, sourceDisplacement: 0x8); //length
// set EAX to value of fill (zero)
XS.Xor(XSRegisters.EAX, XSRegisters.EAX);
XS.ShiftRight(XSRegisters.ECX, 1);
XS.Jump(CPUx86.ConditionalTestEnum.NotBelow, ".step2");
XS.StoreByteInString();
XS.Label(".step2");
XS.ShiftRight(XSRegisters.ECX, 1);
XS.Jump(CPUx86.ConditionalTestEnum.NotBelow, ".step3");
XS.StoreWordInString();
XS.Label(".step3");
new CPUx86.Stos { Size = 32, Prefixes = CPUx86.InstructionPrefixes.Repeat };
}
}
[PlugMethod(Assembler = typeof(ZeroFillAsm))]
// TODO: implement this using REP STOSB and REPO STOSD
public static void ZeroFill(uint aStartAddress, uint aLength) { }

public class InitFloatAsm : AssemblerMethod {
public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object aMethodInfo) {
XS.FPU.FloatInit();
}
}

[PlugMethod(Assembler = typeof(InitFloatAsm))]
public static void InitFloat(CPU aThis) { }

public class InitSSEAsm : AssemblerMethod
using Cosmos.IL2CPU.Plugs.Assemblers;
using Cosmos.IL2CPU.Plugs.Assemblers.CPU;

namespace Cosmos.Core.Plugs
{
[Plug(Target = typeof(CPU))]
public class CPUImpl
{
[PlugMethod(Assembler = typeof(CPUUpdateIDTAsm))]
public static void UpdateIDT(CPU aThis, bool aEnableInterruptsImmediately)
{
public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object aMethodInfo)
{
XS.SSE.SSEInit();
//new CPUx86.SSE.SSEInit();
}
}

[PlugMethod(Assembler = typeof(InitSSEAsm))]
public static void InitSSE(CPU aThis) { }

public class HaltAsm : AssemblerMethod {
public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object aMethodInfo) {
XS.Halt();
}
}

[PlugMethod(Assembler = typeof(HaltAsm))]
public static void Halt(CPU aThis) { }


// [PlugMethod(Assembler = typeof(P2.Assemblers.GetEndOfStack))]
// public static uint GetEndOfStack() {
// return 0;
// }

// [PlugMethod(Assembler = typeof(P2.Assemblers.GetCurrentESP))]
// public static uint GetCurrentESP() {
// return 0;
// }

// [PlugMethod(Assembler = typeof(P2.Assemblers.DoTest))]
// public static void DoTest() {
// }


// [PlugMethod(Assembler = typeof(P2.Assemblers.CPUIDSupport))]
// public static uint HasCPUIDSupport() {
// return 0;
// }

// [PlugMethod(Assembler = typeof(P2.Assemblers.GetCPUIDInternal))]
// public static void GetCPUId(out uint d, out uint c, out uint b, out uint a, uint v) {
// d = 0;
// c = 0;
// b = 0;
// a = 0;
// }
[PlugMethod(Assembler = typeof(CPUGetAmountOfRAMAsm))]
public static uint GetAmountOfRAM()
{
return 0;
}

// [PlugMethod(Assembler = typeof(P2.Assemblers.Halt))]
// public static void Halt() { }
[PlugMethod(Assembler = typeof(CPUGetEndOfKernelAsm))]
public static uint GetEndOfKernel()
{
return 0;
}

[PlugMethod(Assembler = typeof(DisableINTsAsm))]
public static void DoDisableInterrupts()
{
}
[PlugMethod(Assembler = typeof(CPUZeroFillAsm))]
// TODO: implement this using REP STOSB and REPO STOSD
public static void ZeroFill(uint aStartAddress, uint aLength)
{
}

[PlugMethod(Assembler = typeof(EnableINTsAsm))]
public static void DoEnableInterrupts() {
}
[PlugMethod(Assembler = typeof(CPUInitFloatAsm))]
public static void InitFloat(CPU aThis)
{
}

public class DisableINTsAsm : AssemblerMethod
{
public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object aMethodInfo)
{
XS.ClearInterruptFlag();
}
}
[PlugMethod(Assembler = typeof(CPUInitSSEAsm))]
public static void InitSSE(CPU aThis)
{
}

public class EnableINTsAsm : AssemblerMethod
{
public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object aMethodInfo)
{
XS.EnableInterrupts();
}
}
[PlugMethod(Assembler = typeof(CPUHaltAsm))]
public static void Halt(CPU aThis)
{
}

// [PlugMethod(Assembler = typeof(P2.Assemblers.Interrupt30))]
// public static void Interrupt30(ref uint aEAX, ref uint aEBX, ref uint aECX, ref uint aEDX) {
// aEAX = 0;
// }
[PlugMethod(Assembler = typeof(CPUDisableINTsAsm))]
public static void DoDisableInterrupts()
{
}

// [PlugMethod(Assembler = typeof(P2.Assemblers.GetMBIAddress))]
// public static uint GetMBIAddress() {
// return 0;
// }
}
[PlugMethod(Assembler = typeof(CPUEnableINTsAsm))]
public static void DoEnableInterrupts()
{
}
}
}
10 changes: 0 additions & 10 deletions source/Cosmos.Core.Plugs/Cosmos.Core.Plugs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,27 +97,17 @@
<Compile Include="IOPortImpl.cs" />
<Compile Include="ProcessorInformationImpl.cs" />
<Compile Include="System\ArrayImpl.cs" />
<Compile Include="Assemblers\DisableInterruptsAssembler.cs" />
<Compile Include="Assemblers\EnableInterruptsAssembler.cs" />
<Compile Include="System\Assemblers\Array_get_Length.cs" />
<Compile Include="System\Assemblers\Array_InternalCopy.cs" />
<Compile Include="System\Assemblers\Buffer_BlockCopy.cs" />
<Compile Include="System\Assemblers\DelegateImpl.cs" />
<Compile Include="System\Assemblers\GetMulticastInvokeAssembler.cs" />
<Compile Include="System\Assemblers\InvokeImplAssembler.cs" />
<Compile Include="System\Buffer.cs" />
<Compile Include="System\DateTimeImpl.cs" />
<Compile Include="System\DelegateImpl.cs" />
<Compile Include="System\Diagnostics\StopwatchImpl.cs" />
<Compile Include="System\IO\PathHelperImpl.cs" />
<Compile Include="System\MulticastDelegateImpl.cs" />
<Compile Include="System\NormalDelegateImpl.cs" />
<Compile Include="System\ObjectImpl.cs" />
<Compile Include="System\Runtime\InteropServices\MarshalImpl.cs" />
<Compile Include="System\StringImpl.cs" />
<Compile Include="GCImplementionImpl.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Assemblers\UpdateIDT.cs" />
<Compile Include="System\Text\ASCIIEncodingImpl.cs" />
<Compile Include="System\Text\DecoderFallbackImpl.cs" />
<Compile Include="System\Text\EncoderFallbackImpl.cs" />
Expand Down
15 changes: 8 additions & 7 deletions source/Cosmos.Core.Plugs/System/ArrayImpl.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;

using Cosmos.IL2CPU.Plugs;
using Cosmos.IL2CPU.Plugs.Assemblers;
using Cosmos.IL2CPU.Plugs.Assemblers.Array;

namespace Cosmos.Core.Plugs.System
{
Expand Down Expand Up @@ -36,7 +37,7 @@ public static int GetLength(Array aThis, int aDimension)
return aThis.Length;
}

[PlugMethod(Assembler = typeof(Assemblers.Array_get_Length))]
[PlugMethod(Assembler = typeof(ArrayGetLengthAsm))]
public static int get_Length(Array aThis)
{
//aThis += 2;
Expand Down Expand Up @@ -85,12 +86,12 @@ private static unsafe bool TrySZIndexOf(uint* aArray, uint sourceIndex, uint cou
return false;
}

[PlugMethod(Assembler = typeof(Assemblers.Array_InternalCopy))]
[PlugMethod(Assembler = typeof(ArrayInternalCopyAsm))]
public static void Copy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length, bool reliable)
{
}

public unsafe static int get_Rank(int* aThis)
public static unsafe int get_Rank(int* aThis)
{
return 1;
}
Expand Down Expand Up @@ -120,9 +121,9 @@ public static unsafe uint GetValue(uint* aThis, int aIndex)
case 2:
return *((ushort*)aThis);
case 3:
return (*((uint*)aThis)) & 0x0FFFFFFF;
return (*aThis) & 0x0FFFFFFF;
case 4:
return *((uint*)aThis);
return *aThis;
}
throw new NotSupportedException("GetValue not supported in this situation!");
}
Expand Down Expand Up @@ -158,4 +159,4 @@ public static unsafe void SetValue(uint* aThis, uint aValue, int aIndex)
throw new NotSupportedException("SetValue not supported in this situation!");
}
}
}
}
Loading

0 comments on commit 4b67c02

Please sign in to comment.