Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expanding ARM32 Support #1181

Merged
merged 1 commit into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Source/Mosa.BareMetal.HelloWorld.ARM32/Boot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ public static void Main()

Program.EntryPoint();
}

public static void ForceInclude()
{
Mosa.Kernel.BareMetal.ARM32.PlatformPlug.ForceInclude();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<StartupObject>Mosa.BareMetal.HelloWorld.ARM32.Boot</StartupObject>
</PropertyGroup>

<Import Project="../Mosa.BareMetal.targets" />
Expand Down
12 changes: 11 additions & 1 deletion Source/Mosa.Compiler.ARM32/Architecture.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.ARM32.CompilerStages;
using Mosa.Compiler.ARM32.Stages;
using Mosa.Compiler.Common.Exceptions;
using Mosa.Compiler.Framework;
using Mosa.Compiler.Framework.CompilerStages;
using Mosa.Compiler.Framework.Linker.Elf;
using Mosa.Compiler.Framework.Stages;
using Mosa.Utility.Configuration;
Expand Down Expand Up @@ -126,6 +128,14 @@ public override OpcodeEncoder GetOpcodeEncoder()
/// <param name="pipeline">The pipeline to extend.</param>
public override void ExtendCompilerPipeline(Pipeline<BaseCompilerStage> pipeline, MosaSettings mosaSettings)
{
if (!string.IsNullOrEmpty(mosaSettings.MultibootVersion))
{
pipeline.InsertAfterFirst<TypeInitializerStage>(
new MultibootStage()
);
}

pipeline.Add(new StartUpStage());
}

/// <summary>
Expand All @@ -136,7 +146,7 @@ public override void ExtendCompilerPipeline(Pipeline<BaseCompilerStage> pipeline
public override void ExtendMethodCompilerPipeline(Pipeline<BaseMethodCompilerStage> pipeline, MosaSettings mosaSettings)
{
pipeline.InsertBefore<CallStage>(
new Stages.RuntimeCallStage()
new RuntimeCallStage()
);

pipeline.InsertAfterLast<PlatformIntrinsicStage>(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Framework;

namespace Mosa.Compiler.ARM32.Transforms.FloatingTweaks;

/// <summary>
/// ConvertR4ToU32
/// </summary>
public sealed class ConvertR4ToU32 : BaseTransform
{
public ConvertR4ToU32() : base(IR.ConvertR4ToU32, TransformType.Manual | TransformType.Transform)
{
}

public override bool Match(Context context, Transform transform)
{
return true;
}

public override void Transform(Context context, Transform transform)
{
var result = context.Result;
var operand1 = context.Operand1;

context.SetInstruction(IR.ConvertR4ToI32, result, operand1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Framework;

namespace Mosa.Compiler.ARM32.Transforms.FloatingTweaks;

/// <summary>
/// ConvertR8ToU32
/// </summary>
public sealed class ConvertR8ToU32 : BaseTransform
{
public ConvertR8ToU32() : base(IR.ConvertR8ToU32, TransformType.Manual | TransformType.Transform)
{
}

public override bool Match(Context context, Transform transform)
{
return true;
}

public override void Transform(Context context, Transform transform)
{
var result = context.Result;
var operand1 = context.Operand1;

context.SetInstruction(IR.ConvertR8ToI32, result, operand1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Framework;

namespace Mosa.Compiler.ARM32.Transforms.FloatingTweaks;

/// <summary>
/// ConvertU32ToR8
/// </summary>
public sealed class ConvertU32ToR8 : BaseTransform
{
public ConvertU32ToR8() : base(IR.ConvertU32ToR8, TransformType.Manual | TransformType.Transform)
{
}

public override bool Match(Context context, Transform transform)
{
return true;
}

public override void Transform(Context context, Transform transform)
{
var result = context.Result;
var operand1 = context.Operand1;

context.SetInstruction(IR.ConvertI32ToR8, result, operand1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@ public static class FloatingTweakTransforms
new ConvertR8ToI64(),
new ConvertR4ToU64(),
new ConvertR8ToU64(),

new ConvertR4ToU32(),
new ConvertR8ToU32(),
new ConvertU32ToR8(),

new RemR4NotSupported(),
new RemR8NotSupported(),
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Framework;

namespace Mosa.Compiler.ARM32.Transforms.FloatingTweaks;

/// <summary>
/// RemR4NotSupported
/// </summary>
public sealed class RemR4NotSupported : BaseTransform
{
public RemR4NotSupported() : base(IR.RemR4, TransformType.Manual | TransformType.Transform)
{
}

public override bool Match(Context context, Transform transform)
{
return true;
}

public override void Transform(Context context, Transform transform)
{
var result = context.Result;
var operand1 = context.Operand1;

context.SetInstruction(IR.MoveR4, result, operand1); // NOT SUPPORTED
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Framework;

namespace Mosa.Compiler.ARM32.Transforms.FloatingTweaks;

/// <summary>
/// RemR8NotSupported
/// </summary>
public sealed class RemR8NotSupported : BaseTransform
{
public RemR8NotSupported() : base(IR.RemR8, TransformType.Manual | TransformType.Transform)
{
}

public override bool Match(Context context, Transform transform)
{
return true;
}

public override void Transform(Context context, Transform transform)
{
var result = context.Result;
var operand1 = context.Operand1;

context.SetInstruction(IR.MoveR8, result, operand1); // NOT SUPPORTED
}
}
3 changes: 3 additions & 0 deletions Source/Mosa.Kernel.BareMetal.ARM32/PlatformPlug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public static class PlatformPlug
private const uint InitialGCMemoryPoolAddress = 0x03000000; // @ 48MB
private const uint InitialGCMemoryPoolSize = 16 * 1024 * 1024; // [Size=16MB]

public static void ForceInclude()
{ }

[Plug("Mosa.Kernel.BareMetal.Platform::Initialization")]
public static void Initialization()
{
Expand Down
3 changes: 3 additions & 0 deletions Source/Mosa.Kernel.BareMetal.ARM64/PlatformPlug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public static class PlatformPlug
private const uint InitialGCMemoryPoolAddress = 0x03000000; // @ 48MB
private const uint InitialGCMemoryPoolSize = 16 * 1024 * 1024; // [Size=16MB]

public static void ForceInclude()
{ }

[Plug("Mosa.Kernel.BareMetal.Platform::Initialization")]
public static void Initialization()
{
Expand Down
17 changes: 2 additions & 15 deletions Source/Mosa.Kernel.BareMetal/PageFrameAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,6 @@ public static void Setup()
var start = Alignment.AlignDown(entry.StartAddress.ToInt64(), Page.Size);
var end = Alignment.AlignUp(entry.EndAddress.ToInt64(), Page.Size);

//Debug.WriteLine(" > reserve");
//Debug.WriteLineHex(" > start: ", entry.StartAddress.ToInt64());
//Debug.WriteLineHex(" > end: ", entry.EndAddress.ToInt64());
//Debug.WriteLine(" > len: ", entry.Size);

//Debug.WriteLineHex(" > start-aligned: ", start);
//Debug.WriteLineHex(" > end-aligned: ", end);

var pages = (uint)(end - start) / Page.Size;

if (pages <= 0)
Expand All @@ -114,10 +106,6 @@ public static void Setup()
var startPage = (uint)(start / Page.Size);
var endPage = startPage + pages - 1;

//Debug.WriteLine(" > pages: ", pages);
//Debug.WriteLine(" > startPage: ", startPage);
//Debug.WriteLine(" > endPage: ", endPage);

MinimumReservedPage = Math.Min(MinimumReservedPage, startPage);
MaximumReservedPage = Math.Max(MaximumReservedPage, endPage);

Expand All @@ -133,8 +121,6 @@ public static void Setup()
if (endPage > TotalPages)
pages = TotalPages - startPage;

//Debug.WriteLine(" > pages2: ", pages);

Debug.WriteLine(" > reserved: ", startPage, " - ", endPage);

SetPageBitMapEntry(startPage, pages, false);
Expand Down Expand Up @@ -357,9 +343,10 @@ private static void ReserveMemory()
var region = Platform.GetBootReservedRegion();
SetPageBitMapEntry((uint)(region.Address.ToInt64() / Page.Size), ((uint)region.Size / Page.Size) + 1, false);

// Reserve first 24MB
// Reserve first 24MB (wide enough to cover initial stack and kernel)
SetPageBitMapEntry(0, 24 * 1024 * 1024 / Page.Size, false);

// TODO - initial stack
// TODO - reserve kernel code + memory
}

Expand Down
51 changes: 51 additions & 0 deletions Source/Mosa.Plug.Korlib.ARM32/System.Threading/InterlockedPlug.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System;
using Mosa.Runtime.Plug;

namespace Mosa.Plug.Korlib.System.Threading.ARM32;

public static class InterlockedPlug
{
[Plug("System.Threading.Interlocked::CompareExchange")]
internal static int CompareExchange(ref int location1, int value, int comparand)
{
//return Native.CmpXChgLoad32(ref location1, value, comparand);

return 0;
}

[Plug("System.Threading.Interlocked::Exchange")]
internal static int Exchange(ref int location1, int value)
{
//return Native.XChgLoad32(ref location1, value);

return 0;
}

[Plug("System.Threading.Interlocked::ExchangeAdd")]
internal static int ExchangeAdd(ref int location1, int value)
{
//return Native.XAddLoad32(ref location1, value);

return 0;
}

[Plug("System.Threading.Interlocked::CompareExchange")]
public static IntPtr CompareExchange(ref IntPtr location1, IntPtr value, IntPtr comparand)
{
//var address = location1.ToInt32();
//return new IntPtr(CompareExchange(ref address, value.ToInt32(), comparand.ToInt32()));

return IntPtr.Zero;
}

[Plug("System.Threading.Interlocked::CompareExchange")]
internal static long CompareExchange(ref long location1, long value, long comparand)
{
//int location = (int)location1;
//return Native.CmpXChgLoad32(location, (int)value, (int)comparand);

return 0;
}
}
41 changes: 41 additions & 0 deletions Source/Mosa.Plug.Korlib.ARM32/System.Threading/MonitorPlug.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System;
using System.Runtime.CompilerServices;
using Mosa.Runtime.Plug;

namespace Mosa.Plug.Korlib.System.Threading.ARM32;

public static class MonitorPlug
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Plug("System.Threading.Monitor::Enter")]
internal static void Enter(Object obj)
{
//var sync = Mosa.Runtime.Internal.GetObjectLockAndStatus(obj);

//while (Native.CmpXChgLoad32(sync.ToInt32(), 1, 0) != 0)
//{ }
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Plug("System.Threading.Monitor::ReliableEnter")]
internal static void ReliableEnter(Object obj, ref bool lockTaken)
{
//var sync = Mosa.Runtime.Internal.GetObjectLockAndStatus(obj);

//while (Native.CmpXChgLoad32(sync.ToInt32(), 1, 0) != 0)
//{ }

lockTaken = true;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Plug("System.Threading.Monitor::Exit")]
internal static void Exit(Object obj)
{
//var sync = Mosa.Runtime.Internal.GetObjectLockAndStatus(obj);

//Native.XAddLoad32(sync.ToInt32(), -1);
}
}
Loading
Loading