Skip to content

Commit

Permalink
Seem to be there. Merging follows.
Browse files Browse the repository at this point in the history
  • Loading branch information
mterwoord committed Aug 2, 2015
1 parent ac67400 commit 1d9c648
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 59 deletions.
15 changes: 4 additions & 11 deletions Tests/Cosmos.Compiler.Tests.SimpleWriteLine.Kernel/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,13 @@ protected override void Run()
try
{
Console.WriteLine("Started correctly!");
var x = new object[]
{
"The solution is: ",
(int)42
};
var xMessage = String.Concat(x);
Console.WriteLine(xMessage);
object x = 42;
Console.WriteLine(x.ToString());
Console.WriteLine("Done doing tests");
Assert.IsTrue(true, "Dummy assertion, to test the system");
//TestController.Completed();
while (true)
;
TestController.Completed();
}
catch(Exception E)
catch (Exception E)
{
Console.WriteLine("Exception");
Console.WriteLine(E.ToString());
Expand Down
10 changes: 5 additions & 5 deletions Tests/Cosmos.TestRunner.Core/DefaultEngineConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ public static void Apply(Engine engine)
throw new ArgumentNullException("engine");
}

engine.AllowedSecondsInKernel = 120;
engine.AllowedSecondsInKernel = 3600;

// If you want to test only specific platforms, add them to the list, like next line. By default, all platforms are ran.
engine.RunTargets.Add(RunTargetEnum.VMware);

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

engine.AddKernel(typeof(Cosmos.Compiler.Tests.SimpleWriteLine.Kernel.Kernel).Assembly.Location);
engine.AddKernel(typeof(SimpleStructsAndArraysTest.Kernel).Assembly.Location);
//engine.AddKernel(typeof(VGACompilerCrash.Kernel).Assembly.Location);
//engine.AddKernel(typeof(Cosmos.Compiler.Tests.SimpleWriteLine.Kernel.Kernel).Assembly.Location);
//engine.AddKernel(typeof(SimpleStructsAndArraysTest.Kernel).Assembly.Location);
engine.AddKernel(typeof(VGACompilerCrash.Kernel).Assembly.Location);
// engine.AddKernel(typeof(BoxingTests.Kernel).Assembly.Location);
// known bugs, therefor disabled for now:

Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.HAL/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static internal void InitPciDevices() {
// system level and not accessible from Core. Need to think about this
// for the future.
Debugger.DoSend("Finding PCI Devices");
PCI.Setup();
//PCI.Setup();
}

static public void Init(TextScreenBase textScreen, Keyboard keyboard)
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.IL2CPU/AppAssembler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//#define VMT_DEBUG
#define VMT_DEBUG
using System;
using System.Collections.Generic;
using System.Diagnostics.SymbolStore;
Expand Down
12 changes: 7 additions & 5 deletions source/Cosmos.IL2CPU/CustomImplementation/System/ObjectImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ public static string ToString(object aThis)

/// <summary>
/// <para>
/// The object first stores any metadata involved. (Most likely containing a reference to the
/// The object first stores any metadata involved. (Most likely containing a reference to the
/// object type). This is the number of bytes.
/// </para>
/// <para>
/// The first 4 bytes are the reference to the type information of the instance, the second 4 bytes
/// are the <see cref="InstanceTypeEnum"/> value. For arrays, there are 4 following bytes containing the element count, for objects, the amount of reference fields.
/// For arrays, next 4 bytes containing the element size.
/// The first 4 bytes are the reference to the type information of the instance,
/// the second 4 bytes are the <see cref="InstanceTypeEnum"/> value.
/// For arrays, there are 4 following bytes containing the element count,
/// for objects, the amount of reference fields.
/// For arrays, next 4 bytes containing the element size.
/// </para>
/// </summary>
public const int FieldDataOffset = 12;
Expand All @@ -54,4 +56,4 @@ public static Type GetType(object aThis) {
}
}

}
}
11 changes: 6 additions & 5 deletions source/Cosmos.IL2CPU/IL/Box.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@ public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
string xTypeID = GetTypeIDLabel(xType.Value);
new CPUx86.Push { DestinationValue = ( ObjectImpl.FieldDataOffset + xSize ) };
new CPUx86.Call { DestinationLabel = LabelName.Get( GCImplementationRefs.AllocNewObjectRef ) };
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.RegistersEnum.ESP, SourceIsIndirect=true };
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.EAX, SourceIsIndirect = true };
new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX };
new CPUx86.Mov { DestinationReg = CPUx86.Registers.ESI, SourceReg = CPUx86.Registers.EAX, SourceIsIndirect = true };
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EBX, SourceRef = Cosmos.Assembler.ElementReference.New( xTypeID ), SourceIsIndirect = true };
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EAX, DestinationIsIndirect = true, SourceReg = CPUx86.Registers.EBX };
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EAX, DestinationIsIndirect = true, DestinationDisplacement = 4, SourceValue = ( uint )InstanceTypeEnum.BoxedValueType, Size = 32 };
new CPUx86.Mov { DestinationReg = CPUx86.Registers.ESI, DestinationIsIndirect = true, SourceReg = CPUx86.Registers.EBX };
new CPUx86.Mov { DestinationReg = CPUx86.Registers.ESI, DestinationIsIndirect = true, DestinationDisplacement = 4, SourceValue = ( uint )InstanceTypeEnum.BoxedValueType, Size = 32 };
new Comment(Assembler, "xSize is " + xSize );
for( int i = 0; i < ( xSize / 4 ); i++ )
{
new CPUx86.Pop { DestinationReg = CPUx86.Registers.EDX };
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EAX, DestinationIsIndirect = true, DestinationDisplacement = ( ObjectImpl.FieldDataOffset + ( i * 4 ) ), SourceReg = CPUx86.Registers.EDX, Size = 32 };
new CPUx86.Mov { DestinationReg = CPUx86.Registers.ESI, DestinationIsIndirect = true, DestinationDisplacement = ( ObjectImpl.FieldDataOffset + ( i * 4 ) ), SourceReg = CPUx86.Registers.EDX, Size = 32 };
}
new CPUx86.Push {DestinationReg = CPUx86.RegistersEnum.EAX};
}
}
}
48 changes: 17 additions & 31 deletions source/Cosmos.IL2CPU/IL/Callvirt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Cosmos.IL2CPU.ILOpCodes;
using Cosmos.Assembler;
using System.Reflection;
using Cosmos.IL2CPU.IL.CustomImplementations.System;
using SysReflection = System.Reflection;

namespace Cosmos.IL2CPU.X86.IL
Expand Down Expand Up @@ -111,77 +112,62 @@ public static void DoExecute(Cosmos.Assembler.Assembler Assembler, MethodInfo aM
// mLabelName + "_AfterAddressCheck",
// true,
// xEmitCleanup );
new CPUx86.Pop {DestinationReg = CPU.RegistersEnum.ECX};

new Label(xCurrentMethodLabel + ".AfterAddressCheck");
if (xMethodInfo.DeclaringType == typeof(object))
{

/*
* On the stack now:
* $esp method to call
* $esp + 4 Params
* $esp + mThisOffset + 4 This
* $esp + 0 Params
* $esp + mThisOffset This
*/
// we need to see if $this is a boxed object, and if so, we need to box it
new CPUx86.Mov {DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.ESP, SourceIsIndirect = true, SourceDisplacement = (int)(xThisOffset + 4)};
new CPUx86.Mov {DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.ESP, SourceIsIndirect = true, SourceDisplacement = (int)xThisOffset};
//new CPUx86.Compare { DestinationReg = CPUx86.Registers.EAX, DestinationIsIndirect = true, DestinationDisplacement = 4, SourceValue = ( ( uint )InstanceTypeEnum.BoxedValueType ), Size = 32 };

//InstanceTypeEnum.BoxedValueType == 3 =>
new CPUx86.Compare {DestinationReg = CPUx86.Registers.EAX, DestinationIsIndirect = true, DestinationDisplacement = 4, SourceValue = 3, Size = 32};
// EAX contains the handle now, lets dereference it
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.EAX, SourceIsIndirect = true };

new CPUx86.Compare {DestinationReg = CPUx86.Registers.EAX, DestinationIsIndirect = true, DestinationDisplacement = 4, SourceValue = (int)InstanceTypeEnum.BoxedValueType, Size = 32};

/*
* On the stack now:
* $esp Params
* $esp + mThisOffset This
*
* EAX contains the method to call
*/
new CPUx86.ConditionalJump {Condition = CPUx86.ConditionalTestEnum.NotEqual, DestinationLabel = xCurrentMethodLabel + ".NotBoxedThis"};
new CPUx86.Pop {DestinationReg = CPUx86.Registers.ECX};
new CPUx86.Mov {DestinationReg = CPUx86.Registers.ECX, SourceReg = CPUx86.Registers.ECX, SourceIsIndirect = true};
/*
* On the stack now:
* $esp Params
* $esp + mThisOffset This
*
* ECX contains the method to call
* EAX contains the type pointer (not the handle!!)
*/
new CPUx86.Mov {DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.ESP, SourceIsIndirect = true, SourceDisplacement = (int)xThisOffset};
/*
new CPUx86.ConditionalJump {Condition = CPUx86.ConditionalTestEnum.NotEqual, DestinationLabel = xCurrentMethodLabel + ".NotBoxedThis"};

/*
* On the stack now:
* $esp Params
* $esp + mThisOffset This
*
* ECX contains the method to call
* EAX contains $This, but boxed
* EAX contains the type pointer (not the handle!!)
*/

//new CPUx86.Add { DestinationReg = CPUx86.Registers.EAX, SourceValue = ( uint )ObjectImpl.FieldDataOffset };
new CPUx86.Add { DestinationReg = CPUx86.Registers.EAX, SourceValue = ( uint )ObjectImpl.FieldDataOffset };

//public const int FieldDataOffset = 12; // ObjectImpl says that. so..
new CPUx86.Add {DestinationReg = CPUx86.Registers.EAX, SourceValue = 12};
new CPUx86.Mov {DestinationReg = CPUx86.Registers.ESP, DestinationIsIndirect = true, DestinationDisplacement = (int)xThisOffset, SourceReg = CPUx86.Registers.EAX};
/*
* On the stack now:
* $esp Params
* $esp + mThisOffset Pointer to address inside box
*
* ECX contains the method to call
*/
new CPUx86.Push {DestinationReg = CPUx86.Registers.ECX};
/*
* On the stack now:
* $esp Method to call
* $esp + 4 Params
* $esp + mThisOffset + 4 This
*/
}
new Label(xCurrentMethodLabel + ".NotBoxedThis");
new CPUx86.Pop {DestinationReg = CPUx86.Registers.EAX};
if (xExtraStackSize > 0)
{
new CPUx86.Sub {DestinationReg = CPUx86.Registers.ESP, SourceValue = xExtraStackSize};
}
new CPUx86.Call {DestinationReg = CPUx86.Registers.EAX};
new CPUx86.Call {DestinationReg = CPUx86.Registers.ECX};
new Label(xCurrentMethodLabel + ".AfterNotBoxedThis");
}
ILOp.EmitExceptionLogic(Assembler, aMethod, aOp, true,
Expand Down

0 comments on commit 1d9c648

Please sign in to comment.