Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
charsleysa committed Feb 1, 2015
2 parents 6357d06 + e2fd002 commit 457b3d8
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Source/Mosa.Compiler.Framework/CIL/IInstructionDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface IInstructionDecoder
MosaMethod Method { get; }

/// <summary>
/// Gets the Instruction being decoded.
/// Gets the instruction being decoded.
/// </summary>
MosaInstruction Instruction { get; }

Expand All @@ -39,4 +39,4 @@ public interface IInstructionDecoder
/// </value>
TypeSystem TypeSystem { get; }
}
}
}
8 changes: 7 additions & 1 deletion Source/Mosa.Compiler.Framework/Register.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public int Index
/// </summary>
public abstract int Width { get; }

/// <summary>
/// Gets a value indicating whether this register is special register that the
/// registor allocator should not consider.
/// </summary>
public bool IsSpecial { get { return !(IsInteger || IsFloatingPoint); } }

#endregion Properties
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -395,20 +395,23 @@ private void ComputeLocalLiveSets()
if (liveSetTrace.Active)
liveSetTrace.Log(context.ToString());

OperandVisitor visitor = new OperandVisitor(context);
var visitor = new OperandVisitor(context);

foreach (var ops in visitor.Input)
foreach (var op in visitor.Input)
{
if (op.IsCPURegister && op.Register.IsSpecial)
continue;

if (liveSetTrace.Active)
liveSetTrace.Log("INPUT: " + ops.ToString());
liveSetTrace.Log("INPUT: " + op.ToString());

int index = GetIndex(ops);
int index = GetIndex(op);
if (!liveKill.Get(index))
{
liveGen.Set(index, true);

if (liveSetTrace.Active)
liveSetTrace.Log("GEN: " + index.ToString() + " " + ops.ToString());
liveSetTrace.Log("GEN: " + index.ToString() + " " + op.ToString());
}
}

Expand Down Expand Up @@ -438,16 +441,19 @@ private void ComputeLocalLiveSets()
liveSetTrace.Log("KILL EXCEPT PHYSICAL: " + context.Operand1.ToString());
}

foreach (var ops in visitor.Output)
foreach (var op in visitor.Output)
{
if (op.IsCPURegister && op.Register.IsSpecial)
continue;

if (liveSetTrace.Active)
liveSetTrace.Log("OUTPUT: " + ops.ToString());
liveSetTrace.Log("OUTPUT: " + op.ToString());

int index = GetIndex(ops);
int index = GetIndex(op);
liveKill.Set(index, true);

if (liveSetTrace.Active)
liveSetTrace.Log("KILL: " + index.ToString() + " " + ops.ToString());
liveSetTrace.Log("KILL: " + index.ToString() + " " + op.ToString());
}
}

Expand Down Expand Up @@ -574,6 +580,9 @@ private void BuildLiveIntervals()

foreach (var result in visitor.Output)
{
if (result.IsCPURegister && result.Register.IsSpecial)
continue;

var register = VirtualRegisters[GetIndex(result)];

if (register.IsReserved)
Expand Down Expand Up @@ -606,6 +615,9 @@ private void BuildLiveIntervals()

foreach (var result in visitor.Input)
{
if (result.IsCPURegister && result.Register.IsSpecial)
continue;

var register = VirtualRegisters[GetIndex(result)];

if (register.IsReserved)
Expand Down
17 changes: 14 additions & 3 deletions Source/Mosa.DebugWorld.x86/Boot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,20 @@ public static void Main()
while (true) ;
}

public static void Test()
public static bool Test()
{
Mosa.Test.Collection.DoubleTests.IsNaN(double.NaN);
uint address = 0x0B8050; //it's the display memory, but you can use any other adress, so far it's no critical area
Mosa.Platform.Internal.x86.Native.Set8(address, 81); //set ascii 'Q'
var num = Mosa.Platform.Internal.x86.Native.Get8(address); //get the 'Q' back

#region COMPILER_BUG

if (num >= 32 && num < 128) //COMPILER_BUG: This conditinal expression will not resolved correctly!
return true;
else
return false;

#endregion COMPILER_BUG
}
}
}
}
15 changes: 7 additions & 8 deletions Source/Mosa.Platform.Internal.x86/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/

using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

namespace Mosa.Platform.Internal.x86
{
Expand Down Expand Up @@ -187,17 +186,17 @@ public static unsafe class Native
[DllImportAttribute(@"Mosa.Platform.x86.Intrinsic.GetCR4, Mosa.Platform.x86")]
public extern static uint GetCR4();

[DllImportAttribute(@"Mosa.Platform.x86.Intrinsic.Get, Mosa.Platform.x86")]
[DllImportAttribute(@"Mosa.Platform.x86.Intrinsic.Get8, Mosa.Platform.x86")]
public extern static byte Get8(uint address);

[DllImportAttribute(@"Mosa.Platform.x86.Intrinsic.Get, Mosa.Platform.x86")]
[DllImportAttribute(@"Mosa.Platform.x86.Intrinsic.Get16, Mosa.Platform.x86")]
public extern static ushort Get16(uint address);

[DllImportAttribute(@"Mosa.Platform.x86.Intrinsic.Get, Mosa.Platform.x86")]
[DllImportAttribute(@"Mosa.Platform.x86.Intrinsic.Get32, Mosa.Platform.x86")]
public extern static uint Get32(uint address);

[DllImportAttribute(@"Mosa.Platform.x86.Intrinsic.Get, Mosa.Platform.x86")]
public extern static ulong Get64(uint address);
//[DllImportAttribute(@"Mosa.Platform.x86.Intrinsic.Get64, Mosa.Platform.x86")]
//public extern static ulong Get64(uint address);

[DllImportAttribute(@"Mosa.Platform.x86.Intrinsic.Set, Mosa.Platform.x86")]
public extern static void Set8(uint address, byte value);
Expand All @@ -208,8 +207,8 @@ public static unsafe class Native
[DllImportAttribute(@"Mosa.Platform.x86.Intrinsic.Set, Mosa.Platform.x86")]
public extern static void Set32(uint address, uint value);

[DllImportAttribute(@"Mosa.Platform.x86.Intrinsic.Set, Mosa.Platform.x86")]
public extern static void Set64(uint address, ulong value);
//[DllImportAttribute(@"Mosa.Platform.x86.Intrinsic.Set, Mosa.Platform.x86")]
//public extern static void Set64(uint address, ulong value);

[DllImportAttribute(@"Mosa.Platform.x86.Intrinsic.GetEBP, Mosa.Platform.x86")]
public extern static uint GetEBP();
Expand Down
41 changes: 41 additions & 0 deletions Source/Mosa.Platform.x86/Intrinsic/Get16.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* (c) 2008 MOSA - The Managed Operating System Alliance
*
* Licensed under the terms of the New BSD License.
*
* Authors:
* Simon Wollwage (rootnode) <[email protected]>
*/

using Mosa.Compiler.Framework;
using System.Diagnostics;

namespace Mosa.Platform.x86.Intrinsic
{
/// <summary>
///
/// </summary>
internal sealed class Get16 : IIntrinsicPlatformMethod
{
#region Methods

/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicPlatformMethod.ReplaceIntrinsicCall(Context context, BaseMethodCompiler methodCompiler)
{
Operand result = context.Result;
Operand v1 = methodCompiler.CreateVirtualRegister(methodCompiler.TypeSystem.BuiltIn.Pointer);
Operand operand = Operand.CreateMemoryAddress(methodCompiler.TypeSystem.BuiltIn.U2, v1, 0);

Debug.Assert(result.IsI4 | result.IsU4);

context.SetInstruction(X86.Mov, v1, context.Operand1);
context.AppendInstruction(X86.Movzx, InstructionSize.Size16, result, operand);
}

#endregion Methods
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Mosa.Platform.x86.Intrinsic
/// <summary>
///
/// </summary>
internal sealed class Get : IIntrinsicPlatformMethod
internal sealed class Get32 : IIntrinsicPlatformMethod
{
#region Methods

Expand All @@ -27,10 +27,10 @@ void IIntrinsicPlatformMethod.ReplaceIntrinsicCall(Context context, BaseMethodCo
{
Operand result = context.Result;
Operand v1 = methodCompiler.CreateVirtualRegister(methodCompiler.TypeSystem.BuiltIn.Pointer);
Operand operand = Operand.CreateMemoryAddress(context.Operand1.Type, v1, 0);
Operand operand = Operand.CreateMemoryAddress(methodCompiler.TypeSystem.BuiltIn.U4, v1, 0);

context.SetInstruction(X86.Mov, v1, context.Operand1);
context.AppendInstruction(X86.Mov, result, operand);
context.AppendInstruction(X86.Mov, InstructionSize.Size32, result, operand);
}

#endregion Methods
Expand Down
38 changes: 38 additions & 0 deletions Source/Mosa.Platform.x86/Intrinsic/Get8.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* (c) 2008 MOSA - The Managed Operating System Alliance
*
* Licensed under the terms of the New BSD License.
*
* Authors:
* Simon Wollwage (rootnode) <[email protected]>
*/

using Mosa.Compiler.Framework;

namespace Mosa.Platform.x86.Intrinsic
{
/// <summary>
///
/// </summary>
internal sealed class Get8 : IIntrinsicPlatformMethod
{
#region Methods

/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicPlatformMethod.ReplaceIntrinsicCall(Context context, BaseMethodCompiler methodCompiler)
{
Operand result = context.Result;
Operand v1 = methodCompiler.CreateVirtualRegister(methodCompiler.TypeSystem.BuiltIn.Pointer);
Operand operand = Operand.CreateMemoryAddress(methodCompiler.TypeSystem.BuiltIn.U1, v1, 0);

context.SetInstruction(X86.Mov, v1, context.Operand1);
context.AppendInstruction(X86.Movzx, InstructionSize.Size8, result, operand);
}

#endregion Methods
}
}
4 changes: 3 additions & 1 deletion Source/Mosa.Platform.x86/Mosa.Platform.x86.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
<Compile Include="Instructions\AddSD.cs" />
<Compile Include="Intrinsic\CreateInstanceSimple.cs" />
<Compile Include="Intrinsic\Div.cs" />
<Compile Include="Intrinsic\Get32.cs" />
<Compile Include="Intrinsic\Get16.cs" />
<Compile Include="Intrinsic\GetAssemblyListTable.cs" />
<Compile Include="Intrinsic\FrameJump.cs" />
<Compile Include="Intrinsic\GetExceptionRegister.cs" />
Expand Down Expand Up @@ -149,7 +151,7 @@
<Compile Include="Intrinsic\SetCR3.cs" />
<Compile Include="Intrinsic\SetCR4.cs" />
<Compile Include="Intrinsic\SwitchTask.cs" />
<Compile Include="Intrinsic\Get.cs" />
<Compile Include="Intrinsic\Get8.cs" />
<Compile Include="Intrinsic\Hlt.cs" />
<Compile Include="Intrinsic\Set.cs" />
<Compile Include="Intrinsic\CpuIdEax.cs" />
Expand Down
13 changes: 13 additions & 0 deletions Source/Mosa.TestWorld.x86/Tests/OtherTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public OtherTest()
testMethods.AddLast(StructNewObjTest);
testMethods.AddLast(StructNotBoxed);
testMethods.AddLast(ForeachBreak);
testMethods.AddLast(ConditionalBug);
}

private static uint StaticValue = 0x200000;
Expand Down Expand Up @@ -158,6 +159,18 @@ private static Pair FindPair(LinkedList<Pair> PairList)
}
return new Pair(0, 0);
}

public static bool ConditionalBug()
{
uint address = 0x0B8050; //it's the display memory, but you can use any other adress, so far it's no critical area
Mosa.Platform.Internal.x86.Native.Set8(address, 81); //set ascii 'Q'
var num = Mosa.Platform.Internal.x86.Native.Get8(address); //get the 'Q' back

if (num >= 32 && num < 128)
return true;
else
return false;
}
}

public struct TestStruct
Expand Down

0 comments on commit 457b3d8

Please sign in to comment.