Skip to content

Commit

Permalink
- Fixes build script (#1115)
Browse files Browse the repository at this point in the history
* - WIP - ARMv8A32

* - WIP - ARMv8A32

* - Updated builds.yml

* - Updated builds.yml

* - Updated builds.yml

* - Updated builds.yml

* - WIP - x64

* More BareMetal changes

* Update Mosa.Kernel.x86.ConsolePlug

* Fix IDT issue

* - WIP

* - WIP

---------

Co-authored-by: AnErrupTion <anerruption@disroot.org>
  • Loading branch information
tgiphil and AnErrupTion committed Aug 10, 2023
1 parent 2dd0ddb commit 8cdde18
Show file tree
Hide file tree
Showing 17 changed files with 216 additions and 12 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ jobs:
run: dotnet nuget push bin\nupkg\Mosa.Kernel.x86.${{ env.BUILD_VERSION }}.nupkg -k ${{ secrets.NUGET_KEY }} -s https://api.nuget.org/v3/index.json
- name: Publish Package - Mosa.Platform.x64
run: dotnet nuget push bin\nupkg\Mosa.Platform.x64.${{ env.BUILD_VERSION }}.nupkg -k ${{ secrets.NUGET_KEY }} -s https://api.nuget.org/v3/index.json
- name: Publish Package - Mosa.Kernel.x64
run: dotnet nuget push bin\nupkg\Mosa.Kernel.x64.${{ env.BUILD_VERSION }}.nupkg -k ${{ secrets.NUGET_KEY }} -s https://api.nuget.org/v3/index.json

linux-build:
name: Linux Build
Expand Down
5 changes: 5 additions & 0 deletions Source/Mosa.BareMetal.HelloWorld.x64/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 Include()
{
Kernel.BareMetal.x64.VGAText.Clear();
}
}
5 changes: 4 additions & 1 deletion Source/Mosa.Compiler.Framework/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ internal void Finalization()
private void LogException(Exception exception, string title, string stage)
{
PostEvent(CompilerEvent.Exception, exception.Message);
PostEvent(CompilerEvent.Exception, exception.ToString());

var exceptionLog = new TraceLog(TraceType.GlobalDebug, null, stage, "Exception");

Expand Down Expand Up @@ -647,7 +648,9 @@ public void PostEvent(CompilerEvent compilerEvent, string message = null, int th

private MosaType GetPlatformInternalRuntimeType()
{
return TypeSystem.GetTypeByName("Mosa.Runtime." + Architecture.PlatformName + ".Internal");
Console.WriteLine($"Mosa.Runtime.{Architecture.PlatformName}.Internal");

return TypeSystem.GetTypeByName($"Mosa.Runtime.{Architecture.PlatformName}.Internal");
}

private MosaType GeInternalRuntimeType()
Expand Down
26 changes: 26 additions & 0 deletions Source/Mosa.Platform.x64/Intrinsic/XAddLoad32.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Framework;

namespace Mosa.Platform.x64.Intrinsic;

/// <summary>
/// IntrinsicMethods
/// </summary>
internal static partial class IntrinsicMethods
{
[IntrinsicMethod("Mosa.Platform.x64.Intrinsic::XAddLoad32")]
private static void XAddLoad32(Context context, TransformContext transformContext)
{
var location = context.Operand1;
var value = context.Operand2;
var result = context.Result;

var v1 = transformContext.VirtualRegisters.Allocate64();

context.SetInstruction(X64.Mov32, v1, value);
context.AppendInstruction(X64.Lock);
context.AppendInstruction(X64.XAddLoad32, v1, location, Operand.Constant32_0, v1);
context.AppendInstruction(X64.Mov32, result, v1);
}
}
2 changes: 1 addition & 1 deletion Source/Mosa.Platform.x64/Intrinsic/XAddLoad64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private static void XAddLoad64(Context context, TransformContext transformContex

context.SetInstruction(X64.Mov64, v1, value);
context.AppendInstruction(X64.Lock);
context.AppendInstruction(X64.XAddLoad32, v1, location, Operand.Constant32_0, v1);
context.AppendInstruction(X64.XAddLoad64, v1, location, Operand.Constant64_0, v1);
context.AppendInstruction(X64.Mov64, result, v1);
}
}
26 changes: 26 additions & 0 deletions Source/Mosa.Platform.x64/Intrinsic/XChgLoad32.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Framework;

namespace Mosa.Platform.x64.Intrinsic;

/// <summary>
/// IntrinsicMethods
/// </summary>
internal static partial class IntrinsicMethods
{
[IntrinsicMethod("Mosa.Platform.x64.Intrinsic::XChgLoad32")]
private static void XChgLoad32(Context context, TransformContext transformContext)
{
var location = context.Operand1;
var value = context.Operand2;
var result = context.Result;

var v1 = transformContext.VirtualRegisters.Allocate64();

context.SetInstruction(X64.Mov32, v1, value);
context.AppendInstruction(X64.Lock);
context.AppendInstruction(X64.XChgLoad32, v1, location, Operand.Constant32_0, v1);
context.AppendInstruction(X64.Mov32, result, v1);
}
}
2 changes: 1 addition & 1 deletion Source/Mosa.Platform.x64/Intrinsic/XChgLoad64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private static void XChgLoad64(Context context, TransformContext transformContex

context.SetInstruction(X64.Mov64, v1, value);
context.AppendInstruction(X64.Lock);
context.AppendInstruction(X64.XChgLoad64, v1, location, Operand.Constant32_0, v1);
context.AppendInstruction(X64.XChgLoad64, v1, location, Operand.Constant64_0, v1);
context.AppendInstruction(X64.Mov64, result, v1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ internal static long ExchangeAdd(ref long location1, long value)
return Native.XAddLoad64(ref location1, value);
}

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

[Plug("System.Threading.Interlocked::CompareExchange")]
public static IntPtr CompareExchange(ref IntPtr location1, IntPtr value, IntPtr comparand)
{
Expand Down
12 changes: 12 additions & 0 deletions Source/Mosa.Plug.Korlib.x64/System.Threading/MonitorPlug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ internal static void Enter(Object obj)
{ }
}

[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.CmpXChgLoad64(sync.ToInt64(), 1, 0) != 0)
{ }

lockTaken = true;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Plug("System.Threading.Monitor::Exit")]
internal static void Exit(Object obj)
Expand Down
57 changes: 57 additions & 0 deletions Source/Mosa.Plug.Korlib.x64/System/Math.CoreCLR.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Runtime.Plug;
using Mosa.Runtime.x64;

namespace Mosa.Plug.Korlib.System.x64;

internal static class Math
{
//[Plug("System.Math::Abs")]
//internal static double Abs(double value)
//{
// return 0; // TODO
//}

//[Plug("System.Math::Abs")]
//internal static float Abs(float value)
//{
// return 0; // TODO
//}

[Plug("System.Math::Sqrt")]
internal static double Sqrt(double d)
{
return Native.Sqrtsd(d);
}

[Plug("System.Math::Ceiling")]
internal static double Ceiling(double d)
{
return Native.Roundsd2Positive(d);
}

[Plug("System.Math::Floor")]
internal static double Floor(double d)
{
return Native.Roundsd2Negative(d);
}

//[Plug("System.Math::Log")]
//internal static double Log(double d)
//{
// return 0; // TODO
//}

//[Plug("System.Math::FMod")]
//internal static double FMod(double x, double y)
//{
// return 0; // TODO
//}

//[Plug("System.Math::ModF")]
//internal static unsafe double ModF(double x, double* intptr)
//{
// return 0; // TODO
//}
}
45 changes: 45 additions & 0 deletions Source/Mosa.Plug.Korlib.x64/System/MathF.CoreCLR.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Runtime.Plug;
using Mosa.Runtime.x64;

namespace Mosa.Plug.Korlib.System.x64;

internal static class MathF
{
[Plug("System.MathF::Ceiling")]
internal static float Ceiling(float s)
{
return Native.Roundss2Positive(s);
}

[Plug("System.MathF::Sqrt")]
internal static float Sqrt(float s)
{
return Native.Sqrtss(s);
}

[Plug("System.MathF::Floor")]
internal static float Floor(float s)
{
return Native.Roundss2Negative(s);
}

//[Plug("System.MathF::Log")]
//internal static float Log(float s)
//{
// return 0; // TODO
//}

//[Plug("System.MathF::FMod")]
//internal static float FMod(float x, float y)
//{
// return 0; // TODO
//}

//[Plug("System.MathF::ModF")]
//internal static unsafe float ModF(float x, float* intptr)
//{
// return 0; // TODO
//}
}
24 changes: 24 additions & 0 deletions Source/Mosa.Runtime.x64/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ public static unsafe class Native
[DllImport("Mosa.Platform.x64.Intrinsic::Blsr64")]
public static extern uint Blsr64(uint esp);

[DllImport("Mosa.Platform.x64.Intrinsic::Sqrtsd")]
public static extern double Sqrtsd(double destination);

[DllImport("Mosa.Platform.x64.Intrinsic::Sqrtss")]
public static extern float Sqrtss(float destination);

[DllImport("Mosa.Platform.x64.Intrinsic::Roundsd2Negative")]
public static extern double Roundsd2Negative(double destination);

[DllImport("Mosa.Platform.x64.Intrinsic::Roundsd2Positive")]
public static extern double Roundsd2Positive(double destination);

[DllImport("Mosa.Platform.x64.Intrinsic::Roundss2Negative")]
public static extern float Roundss2Negative(float destination);

[DllImport("Mosa.Platform.x64.Intrinsic::Roundss2Positive")]
public static extern float Roundss2Positive(float destination);

//[DllImport("Mosa.Platform.x64.Intrinsic::Popcnt32")]
//public static extern uint Popcnt32(uint esp);

Expand Down Expand Up @@ -159,12 +177,18 @@ public static unsafe class Native
[DllImport("Mosa.Platform.x64.Intrinsic::CmpXChgLoad64")]
public static extern long CmpXChgLoad64(long location, long value, long comparand);

[DllImport("Mosa.Platform.x64.Intrinsic::XAddLoad32")]
public static extern long XAddLoad32(ref int location, int value);

[DllImport("Mosa.Platform.x64.Intrinsic::XAddLoad64")]
public static extern long XAddLoad64(ref long location, long value);

[DllImport("Mosa.Platform.x64.Intrinsic::XAddLoad64")]
public static extern long XAddLoad64(long location, long value);

[DllImport("Mosa.Platform.x64.Intrinsic::XChgLoad32")]
public static extern long XChgLoad32(ref int location, int value);

[DllImport("Mosa.Platform.x64.Intrinsic::XChgLoad64")]
public static extern long XChgLoad64(ref long location, long value);

Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Tool.Compiler/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"Mosa.Tool.Compiler": {
"commandName": "Project",
"commandLineArgs": "Mosa.BareMetal.HelloWorldARMv8A32.dll -check -arm32"
"commandLineArgs": "Mosa.BareMetal.HelloWorld.x64.dll -check -x64 -threads 1 -o0"
}
}
}
2 changes: 1 addition & 1 deletion Source/Mosa.Tool.Explorer/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ private void UpdateSettings(string filename)
MosaSettings.AddSourceFile(filename);
MosaSettings.AddSourceFile(fileHunter.HuntFile("Mosa.Plug.Korlib.dll")?.FullName);
MosaSettings.AddSourceFile(fileHunter.HuntFile($"Mosa.Plug.Korlib.{MosaSettings.Platform}.dll")?.FullName);
MosaSettings.AddSourceFile(fileHunter.HuntFile(filename: "Mosa.Runtime." + MosaSettings.Platform + ".dll")?.FullName);
MosaSettings.AddSourceFile(fileHunter.HuntFile($"Mosa.Runtime.{MosaSettings.Platform}.dll")?.FullName);

// Search Paths
MosaSettings.ClearSearchPaths();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"Mosa.Tool.Launcher.Console": {
"commandName": "Project",
"commandLineArgs": "Mosa.Demo.TestWorld.x64.dll -check -x64 -o5",
"commandLineArgs": "Mosa.BareMetal.HelloWorld.x64.dll -check -x64",
"workingDirectory": "..\\..\\bin"
}
}
Expand Down
6 changes: 4 additions & 2 deletions Source/Mosa.Utility.Configuration/MOSASettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,9 @@ public void NormalizeSettings()

// special case - to match with DLL
if (Platform == "armv8a32")
{
Platform = "ARMv8A32";
}
}

public void UpdateFileAndPathSettings()
Expand Down Expand Up @@ -883,7 +885,7 @@ public void ExpandSearchPaths()
}
}

#region Customer Helpers
#region Custom Helpers

public void ClearSourceFiles()
{
Expand All @@ -905,5 +907,5 @@ public void AddSearchPath(string filename)
Settings.AddPropertyListValue(Name.SearchPaths, filename);
}

#endregion Customer Helpers
#endregion Custom Helpers
}
4 changes: 2 additions & 2 deletions Source/Mosa.sln
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Packages", "Packages", "{52
Mosa.Packages\Mosa.Tools.Package.Qemu.nuspec = Mosa.Packages\Mosa.Tools.Package.Qemu.nuspec
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Setup", "Setup", "{624E8284-4F0A-4C3F-B5F2-271105E48ECF}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{624E8284-4F0A-4C3F-B5F2-271105E48ECF}"
ProjectSection(SolutionItems) = preProject
..\.github\workflows\builds.yml = ..\.github\workflows\builds.yml
EndProjectSection
Expand Down Expand Up @@ -231,7 +231,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mosa.Compiler.MosaTypeSyste
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mosa.UnitTests.BareMetal.x86", "Mosa.UnitTests.BareMetal.x86\Mosa.UnitTests.BareMetal.x86.csproj", "{3F820CBC-E5DB-4E72-BA98-491D06355C53}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mosa.BareMetal.HelloWorld", "Mosa.BareMetal.HelloWorld\Mosa.BareMetal.HelloWorld.csproj", "{6BF93B57-2BCB-4BE7-88B9-F071394B3FA7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mosa.BareMetal.HelloWorld", "Mosa.BareMetal.HelloWorld\Mosa.BareMetal.HelloWorld.csproj", "{6BF93B57-2BCB-4BE7-88B9-F071394B3FA7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down

0 comments on commit 8cdde18

Please sign in to comment.