Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/CosmosOS/Cosmos.git
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesbetros committed Jun 25, 2016
2 parents 4bd3c44 + 19160c3 commit 1550c86
Show file tree
Hide file tree
Showing 19 changed files with 157 additions and 145 deletions.
1 change: 1 addition & 0 deletions Tests/Cosmos.TestRunner.Core/TestKernelSets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static IEnumerable<Type> GetStableKernelTypes()
yield return typeof(Cosmos.Compiler.Tests.LinqTests.Kernel);
yield return typeof(Cosmos.Compiler.Tests.MethodTests.Kernel);
yield return typeof(Cosmos.Kernel.Tests.Fat.Kernel);
//yield return typeof(FrotzKernel.Kernel);
}
}
}
2 changes: 1 addition & 1 deletion Users/Matthijs/DebugCompiler/MyEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void Test(Type kernelToRun)
var xEngine = new Engine();
// Sets the time before an error is registered. For example if set to 60 then if a kernel runs for more than 60 seconds then
// that kernel will be marked as a failure and terminated
xEngine.AllowedSecondsInKernel = 30;
xEngine.AllowedSecondsInKernel = 300;

// If you want to test only specific platforms, add them to the list, like next line. By default, all platforms are run.
xEngine.RunTargets.Add(RunTargetEnum.Bochs);
Expand Down
11 changes: 6 additions & 5 deletions source/Cosmos.Core.Plugs/System/Buffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ namespace Cosmos.Core.Plugs.System
[Plug(Target = typeof(Buffer))]
public class BufferImpl
{

[PlugMethod(IsOptional = true)]
public static unsafe void __Memcpy(byte* src, byte* dest, int count)
{
global::System.Buffer.BlockCopy((Array)(object)*src, 0, (Array)(object)*dest, 0, count);
}

/// <summary>
/// The memmove() function copies n bytes from memory area src to memory area dest.
/// The memory areas may overlap: copying takes place as though the bytes in src
/// are first copied into a temporary array that does not overlap src or dest,
/// The memmove() function copies n bytes from memory area src to memory area dest.
/// The memory areas may overlap: copying takes place as though the bytes in src
/// are first copied into a temporary array that does not overlap src or dest,
/// and the bytes are then copied from the temporary array to dest.
/// </summary>
/// <param name="dest">Destination address to copy data into.</param>
/// <param name="src">Source address from where copy data.</param>
/// <param name="count">Count of bytes to copy.</param>
[PlugMethod(IsOptional = true)]
public static unsafe void __Memmove(byte* dest, byte* src, uint count)
{
uint t;
Expand Down Expand Up @@ -149,4 +150,4 @@ public static void InternalBlockCopy(Array src, int srcOffset, Array dst, int ds
global::System.Buffer.BlockCopy(src, srcOffset, dst, dstOffset, count);
}
}
}
}
4 changes: 1 addition & 3 deletions source/Cosmos.Core.Plugs/System/DelegateImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ public static bool Equals(Delegate aThis, object aThat)
return false;
}

public static unsafe bool InternalEqualTypes(uint** a, uint** b)
public static unsafe bool InternalEqualTypes([ObjectPointerAccess] uint** a, [ObjectPointerAccess] uint** b)
{
var xTypeA = a[0][0];
var xTypeB = b[0][0];



return xTypeA == xTypeB;
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/Cosmos.Core.Plugs/System/ObjectImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Cosmos.Core.Plugs.System
[Plug(Target = typeof(object))]
public class ObjectImpl
{
public static unsafe uint MemberwiseClone(uint aThis)
public static unsafe uint MemberwiseClone([ObjectPointerAccess] uint aThis)
{
// pointers are handles!

Expand All @@ -27,4 +27,4 @@ public static unsafe uint MemberwiseClone(uint aThis)
return xResult;
}
}
}
}
1 change: 1 addition & 0 deletions source/Cosmos.Core.Plugs/System/StringImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ public static string FastAllocateString(int length)
return new string(new char[length]);
}

[PlugMethod(IsOptional = true)]
public static string TrimStart(string aThis, string aSubStr)
{
char[] ci = aThis.ToCharArray();
Expand Down
2 changes: 2 additions & 0 deletions source/Cosmos.IL2CPU.Plugs/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.cs]
indent_size=2
2 changes: 2 additions & 0 deletions source/Cosmos.IL2CPU.Plugs/Cosmos.IL2CPU.Plugs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<Compile Include="FieldTypeAttribute.cs" />
<Compile Include="FieldAccessAttribute.cs" />
<Compile Include="InlineAttribute.cs" />
<Compile Include="ObjectAccessPointerAttribute.cs" />
<Compile Include="PlugAttribute.cs" />
<Compile Include="PlugFieldAttribute.cs" />
<Compile Include="PlugMethodAttribute.cs" />
Expand All @@ -99,6 +100,7 @@
<None Include="Key.snk" />
</ItemGroup>
<ItemGroup>
<None Include=".editorconfig" />
<Content Include="ReadMe.html" />
</ItemGroup>
<ItemGroup>
Expand Down
13 changes: 13 additions & 0 deletions source/Cosmos.IL2CPU.Plugs/ObjectAccessPointerAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace Cosmos.IL2CPU.Plugs
{
/// <summary>
/// This attribute is used on plug parameters, that need the unsafe pointer to an object's data area
/// </summary>
[AttributeUsage(AttributeTargets.Parameter)]
public class ObjectPointerAccessAttribute : Attribute
{

}
}
3 changes: 2 additions & 1 deletion source/Cosmos.IL2CPU.Plugs/PlugMethodAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public sealed class PlugMethodAttribute: Attribute {
public bool PlugRequired = false;
public bool IsWildcard = false;
public bool WildcardMatchParameters = false;
public bool IsOptional = true;
}
}
}
40 changes: 20 additions & 20 deletions source/Cosmos.IL2CPU/AppAssembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,26 +209,21 @@ protected void MethodBegin(MethodInfo aMethod)
{
DebugInfo.AddDocument(mSequences[0].Document);

var xMethod = new Method()
var xMethod = new Method();
xMethod.ID = mCurrentMethodGuid;
xMethod.TypeToken = aMethod.MethodBase.DeclaringType.MetadataToken;
xMethod.MethodToken = aMethod.MethodBase.MetadataToken;
xMethod.LabelStartID = xLabelGuid;
xMethod.LabelEndID = mCurrentMethodLabelEndGuid;
xMethod.LabelCall = xMethodLabel;
long xAssemblyFileID;
if (DebugInfo.AssemblyGUIDs.TryGetValue(aMethod.MethodBase.DeclaringType.Assembly, out xAssemblyFileID))
{
ID = mCurrentMethodGuid,
TypeToken = aMethod.MethodBase.DeclaringType.MetadataToken,
MethodToken = aMethod.MethodBase.MetadataToken,

LabelStartID = xLabelGuid,
LabelEndID = mCurrentMethodLabelEndGuid,
LabelCall = xMethodLabel,

AssemblyFileID = DebugInfo.AssemblyGUIDs[aMethod.MethodBase.DeclaringType.Assembly],
DocumentID = DebugInfo.DocumentGUIDs[mSequences[0].Document.ToLower()],

// Storing Line + Col as one item makes comparisons MUCH easier, otherwise we have to
// check for things like col < start col but line > start line.
//
// () around << are VERY important.. + has precedence over <<
LineColStart = ((Int64)mSequences[0].LineStart << 32) + mSequences[0].ColStart,
LineColEnd = ((Int64)(mSequences[mSequences.Length - 1].LineEnd) << 32) + mSequences[mSequences.Length - 1].ColEnd
};
xMethod.AssemblyFileID = xAssemblyFileID;
}
xMethod.DocumentID = DebugInfo.DocumentGUIDs[mSequences[0].Document.ToLower()];
xMethod.LineColStart = ((Int64)mSequences[0].LineStart << 32) + mSequences[0].ColStart;
xMethod.LineColEnd = ((Int64)(mSequences[mSequences.Length - 1].LineEnd) << 32) + mSequences[mSequences.Length - 1].ColEnd;
DebugInfo.AddMethod(xMethod);
}
}
Expand Down Expand Up @@ -475,6 +470,11 @@ public void ProcessMethod(MethodInfo aMethod, List<ILOpCode> aOpCodes)
throw new Exception("Method needs plug, but no plug was assigned.");
}

if (aMethod.MethodBase.Name == "InitializeArray")
{
;
}

// todo: MtW: how to do this? we need some extra space.
// see ConstructLabel for extra info
if (aMethod.UID > 0x00FFFFFF)
Expand All @@ -492,7 +492,7 @@ public void ProcessMethod(MethodInfo aMethod, List<ILOpCode> aOpCodes)
}
else if (aMethod.IsInlineAssembler)
{
aMethod.MethodBase.Invoke("", new object[aMethod.MethodBase.GetParameters().Length]);
aMethod.MethodBase.Invoke(null, new object[aMethod.MethodBase.GetParameters().Length]);
}
else
{
Expand Down
80 changes: 46 additions & 34 deletions source/Cosmos.IL2CPU/ILScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public ILScanner(AppAssembler aAsmblr)
mAsmblr = aAsmblr;
mReader = new ILReader();

mPlugManager = new PlugManager(this.LogException, this.ScanMethod, this.Queue);
mPlugManager = new PlugManager(LogException);
}

public bool EnableLogging(string aPathname)
Expand All @@ -94,6 +94,11 @@ public bool EnableLogging(string aPathname)

protected void Queue(_MemberInfo aItem, object aSrc, string aSrcType, string sourceItem = null)
{
if (aItem == null)
{
throw new ArgumentNullException(nameof(aItem));
}

var xMemInfo = aItem as MemberInfo;
//TODO: fix this, as each label/symbol should also contain an assembly specifier.

Expand Down Expand Up @@ -373,7 +378,6 @@ protected void ScanMethod(MethodBase aMethod, bool aIsPlug, string sourceItem)
// isn't guaranteed.
//string xMethodFullName = LabelName.GenerateFullName(aMethod);


for (int i = 0; i < xParams.Length; i++)
{
xParamTypes[i] = xParams[i].ParameterType;
Expand Down Expand Up @@ -479,10 +483,19 @@ protected void ScanMethod(MethodBase aMethod, bool aIsPlug, string sourceItem)

MethodBase xPlug = null;
// Plugs may use plugs, but plugs won't be plugged over themself
var inl = aMethod.GetCustomAttribute<InlineAttribute>();
if (!aIsPlug && !xIsDynamicMethod)
{
// Check to see if method is plugged, if it is we don't scan body
xPlug = mPlugManager.ResolvePlug(aMethod, xParamTypes);
if (xPlug != null)
{
//ScanMethod(xPlug, true, "Plug method");
if (inl == null)
{
Queue(xPlug, aMethod, "Plug method");
}
}
}

if (xPlug == null)
Expand Down Expand Up @@ -517,11 +530,6 @@ protected void ScanMethod(MethodBase aMethod, bool aIsPlug, string sourceItem)
//TODO: Dont queue new items if they are plugged
// or do we need to queue them with a resolved ref in a new list?

InlineAttribute inl = null;
foreach (InlineAttribute inli in aMethod.GetCustomAttributes(typeof(InlineAttribute), false))
{
inl = inli;
}
if (inl != null)
return; // cancel inline

Expand Down Expand Up @@ -651,6 +659,7 @@ protected void ScanQueue()
// and will reduce compares
if (xItem.Item is MethodBase)
{
//if (xItem.QueueReason == "Plug m")
ScanMethod((MethodBase)xItem.Item, false, xItem.SourceItem);
}
else if (xItem.Item is Type)
Expand Down Expand Up @@ -834,20 +843,33 @@ protected void Assemble()
var xMethodType = MethodInfo.TypeEnum.Normal;
Type xPlugAssembler = null;
MethodInfo xPlugInfo = null;
var xMethodInline = xMethod.GetCustomAttribute<InlineAttribute>();
if (xMethodInline != null)
{
// inline assembler, shouldn't come here..
continue;
}
var xMethodIdMethod = mItemsList.IndexOf(xMethod);
if (xMethodIdMethod == -1)
{
throw new Exception("Method not in scanner list!");
}
if (xPlug != null)
{
xMethodType = MethodInfo.TypeEnum.NeedsPlug;
PlugMethodAttribute xAttrib = null;
foreach (PlugMethodAttribute attrib in xPlug.GetCustomAttributes(typeof(PlugMethodAttribute), true))
var xAttrib = xPlug.GetCustomAttribute<PlugMethodAttribute>();
var xInline = xPlug.GetCustomAttribute<InlineAttribute>();
var xMethodIdPlug = mItemsList.IndexOf(xPlug);
if (xMethodIdPlug == -1 && xInline == null)
{
xAttrib = attrib;
throw new Exception("Plug method not in scanner list!");
}
if (xAttrib != null)
if (xAttrib != null && xInline == null)
{
xPlugAssembler = xAttrib.Assembler;
xPlugInfo = new MethodInfo(xPlug, (uint)mItemsList.IndexOf(xPlug), MethodInfo.TypeEnum.Plug, null, xPlugAssembler);
xPlugInfo = new MethodInfo(xPlug, (uint)xMethodIdPlug, MethodInfo.TypeEnum.Plug, null, xPlugAssembler);

var xMethodInfo = new MethodInfo(xMethod, (uint)mItemsList.IndexOf(xMethod), xMethodType, xPlugInfo/*, xPlugAssembler*/);
var xMethodInfo = new MethodInfo(xMethod, (uint)xMethodIdMethod, xMethodType, xPlugInfo/*, xPlugAssembler*/);
if (xAttrib != null && xAttrib.IsWildcard)
{
xPlugInfo.PluggedMethod = xMethodInfo;
Expand All @@ -862,16 +884,16 @@ protected void Assemble()
}
else
{
InlineAttribute inl = null;
foreach (InlineAttribute inli in xPlug.GetCustomAttributes(typeof(InlineAttribute), false))
{
inl = inli;
}
if (inl != null)
if (xInline != null)
{
xPlugInfo = new MethodInfo(xPlug, (uint)mItemsList.IndexOf(xItem), MethodInfo.TypeEnum.Plug, null, true);
var xMethodID = mItemsList.IndexOf(xItem);
if (xMethodID == -1)
{
throw new Exception("Method not in list!");
}
xPlugInfo = new MethodInfo(xPlug, (uint)xMethodID, MethodInfo.TypeEnum.Plug, null, true);

var xMethodInfo = new MethodInfo(xMethod, (uint)mItemsList.IndexOf(xMethod), xMethodType, xPlugInfo/*, xPlugAssembler*/);
var xMethodInfo = new MethodInfo(xMethod, (uint)xMethodIdMethod, xMethodType, xPlugInfo/*, xPlugAssembler*/);

xPlugInfo.PluggedMethod = xMethodInfo;
var xInstructions = mReader.ProcessMethod(xPlug);
Expand All @@ -884,19 +906,9 @@ protected void Assemble()
}
else
{
xPlugInfo = new MethodInfo(xPlug, (uint)mItemsList.IndexOf(xPlug), MethodInfo.TypeEnum.Plug, null, xPlugAssembler);
xPlugInfo = new MethodInfo(xPlug, (uint)xMethodIdPlug, MethodInfo.TypeEnum.Plug, null, xPlugAssembler);

var xMethodInfo = new MethodInfo(xMethod, (uint)mItemsList.IndexOf(xMethod), xMethodType, xPlugInfo/*, xPlugAssembler*/);
if (xAttrib != null && xAttrib.IsWildcard)
{
xPlugInfo.PluggedMethod = xMethodInfo;
var xInstructions = mReader.ProcessMethod(xPlug);
if (xInstructions != null)
{
ProcessInstructions(xInstructions);
mAsmblr.ProcessMethod(xPlugInfo, xInstructions);
}
}
var xMethodInfo = new MethodInfo(xMethod, (uint)xMethodIdMethod, xMethodType, xPlugInfo/*, xPlugAssembler*/);
mAsmblr.GenerateMethodForward(xMethodInfo, xPlugInfo);
}
}
Expand All @@ -921,7 +933,7 @@ protected void Assemble()
xPlugAssembler = xAttrib.Assembler;
}

var xMethodInfo = new MethodInfo(xMethod, (uint)mItemsList.IndexOf(xMethod), xMethodType, xPlugInfo, xPlugAssembler);
var xMethodInfo = new MethodInfo(xMethod, (uint)xMethodIdMethod, xMethodType, xPlugInfo, xPlugAssembler);
var xInstructions = mReader.ProcessMethod(xMethod);
if (xInstructions != null)
{
Expand Down
Loading

0 comments on commit 1550c86

Please sign in to comment.