Skip to content

Commit

Permalink
BareMetal changes (#1110)
Browse files Browse the repository at this point in the history
* BareMetal changes

* Remove Mosa.Kernel.x64 NuSpec

---------

Co-authored-by: AnErrupTion <anerruption@disroot.org>
  • Loading branch information
AnErrupTion and AnErrupTion committed Aug 7, 2023
1 parent 5dcd3f8 commit 72fb7f2
Show file tree
Hide file tree
Showing 30 changed files with 414 additions and 828 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ jobs:
run: nuget pack Source\Mosa.Packages\Mosa.Kernel.x86.nuspec -OutputDirectory bin\nupkg -Version ${{ env.BUILD_VERSION }}
- name: Create Package - Mosa.Platform.x64
run: nuget pack Source\Mosa.Packages\Mosa.Platform.x64.nuspec -OutputDirectory bin\nupkg -Version ${{ env.BUILD_VERSION }}
- name: Create Package - Mosa.Kernel.x64
run: nuget pack Source\Mosa.Packages\Mosa.Kernel.x64.nuspec -OutputDirectory bin\nupkg -Version ${{ env.BUILD_VERSION }}
- name: Store Nuget Packages Artifact
uses: actions/upload-artifact@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion Demos/Run-BareMetal.HelloWorld.x86.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
cd ../bin
./Mosa.Tool.Launcher.Console -autostart -oMax -output-asm -output-debug -output-hash Mosa.BareMetal.HelloWorld.x86.dll
./Mosa.Tool.Launcher.Console -autostart -oMax -output-asm -output-debug -output-hash Mosa.BareMetal.HelloWorld.x86.dll
19 changes: 5 additions & 14 deletions Source/Mosa.BareMetal.HelloWorld.ARMv8A32/Boot.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.UnitTests.Optimization;
using Mosa.Kernel.BareMetal;

namespace Mosa.BareMetal.HelloWorld.ARMv8A32;

/// <summary>
/// Boot
/// </summary>
public static class Boot
{
/// <summary>
/// Main
/// </summary>
public static void Main()
{
while (true)
{ }
}
Debug.WriteLine("Boot::Main()");
Debug.WriteLine("MOSA ARMv8A32 Kernel");

public static bool IncludeUnitTestAssembly()
{
return CommonTests.OptimizationTest1();
Program.EntryPoint();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Mosa.Kernel.BareMetal.x86\Mosa.Kernel.BareMetal.x86.csproj" />
<ProjectReference Include="..\Mosa.Kernel.BareMetal\Mosa.Kernel.BareMetal.csproj" />
<ProjectReference Include="..\Mosa.Korlib\Mosa.Korlib.csproj" />
<ProjectReference Include="..\Mosa.UnitTests\Mosa.UnitTests.csproj" />
<ProjectReference Include="..\Mosa.BareMetal.HelloWorld\Mosa.BareMetal.HelloWorld.csproj" />
<ProjectReference Include="..\Mosa.Kernel.BareMetal.ARMv8A32\Mosa.Kernel.BareMetal.ARMv8A32.csproj" />
</ItemGroup>
</Project>
16 changes: 5 additions & 11 deletions Source/Mosa.BareMetal.HelloWorld.x64/Boot.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Kernel.BareMetal.x64;
using Mosa.Kernel.BareMetal;

namespace Mosa.BareMetal.HelloWorld.x64;

/// <summary>
/// Boot
/// </summary>
public static class Boot
{
/// <summary>
/// Main
/// </summary>
public static void Main()
{
VGAText.Clear();
Debug.WriteLine("Boot::Main()");
Debug.WriteLine("MOSA x64 Kernel");

while (true)
{ }
Program.EntryPoint();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
<UseAppHost>false</UseAppHost>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>MSB3245</NoWarn>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Mosa.Kernel.BareMetal.x64\Mosa.Kernel.BareMetal.x64.csproj" />
<ProjectReference Include="..\Mosa.Kernel.BareMetal\Mosa.Kernel.BareMetal.csproj" />
<ProjectReference Include="..\Mosa.Korlib\Mosa.Korlib.csproj" />
<ProjectReference Include="..\Mosa.BareMetal.HelloWorld\Mosa.BareMetal.HelloWorld.csproj" />
<ProjectReference Include="..\Mosa.Kernel.BareMetal.x64\Mosa.Kernel.BareMetal.x64.csproj" />
</ItemGroup>
</Project>
180 changes: 4 additions & 176 deletions Source/Mosa.BareMetal.HelloWorld.x86/Boot.cs
Original file line number Diff line number Diff line change
@@ -1,193 +1,21 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System;
using Mosa.DeviceDriver.ISA;
using Mosa.DeviceSystem;
using Mosa.DeviceSystem.PCI;
using Mosa.DeviceSystem.Service;
using Mosa.FileSystem.FAT;
using Mosa.Kernel.BareMetal;
using Mosa.Kernel.BareMetal.x86;

namespace Mosa.BareMetal.HelloWorld.x86;

/// <summary>
/// Boot
/// </summary>
public static class Boot
{
public static void Main()
{
Debug.WriteLine("Boot::Main()");
Debug.WriteLine("MOSA x86 Kernel");

var deviceService = Mosa.Kernel.BareMetal.Kernel.ServiceManger.GetFirstService<DeviceService>();

Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.White;
Console.Clear();
Console.Write("> Probing for ISA devices...");

var isaDevices = deviceService.GetChildrenOf(deviceService.GetFirstDevice<ISABus>());
Console.WriteLine("[Completed: " + isaDevices.Count + " found]");

foreach (var device in isaDevices)
{
Console.Write(" ");
Bullet(ConsoleColor.Yellow);
Console.Write(" ");
InBrackets(device.Name, ConsoleColor.White, ConsoleColor.Green);
Console.WriteLine();
}

Console.Write("> Probing for PCI devices...");
var devices = deviceService.GetDevices<PCIDevice>();
Console.WriteLine("[Completed: " + devices.Count + " found]");

foreach (var device in devices)
{
Console.Write(" ");
Bullet(ConsoleColor.Yellow);
Console.Write(" ");

var pciDevice = device.DeviceDriver as PCIDevice;
InBrackets(device.Name + ": " + pciDevice.VendorID.ToString("x") + ":" + pciDevice.DeviceID.ToString("x") + " " + pciDevice.SubSystemID.ToString("x") + ":" + pciDevice.SubSystemVendorID.ToString("x") + " (" + pciDevice.ClassCode.ToString("x") + ":" + pciDevice.SubClassCode.ToString("x") + ":" + pciDevice.ProgIF.ToString("x") + ":" + pciDevice.RevisionID.ToString("x") + ")", ConsoleColor.White, ConsoleColor.Green);

var children = deviceService.GetChildrenOf(device);

if (children.Count != 0)
{
var child = children[0];

Console.WriteLine();
Console.Write(" ");

var pciDevice2 = child.DeviceDriver as PCIDevice;
InBrackets(child.Name, ConsoleColor.White, ConsoleColor.Green);
}

Console.WriteLine();
}

Console.Write("> Probing for disk controllers...");
var diskcontrollers = deviceService.GetDevices<IDiskControllerDevice>();
Console.WriteLine("[Completed: " + diskcontrollers.Count + " found]");

foreach (var device in diskcontrollers)
{
Console.Write(" ");
Bullet(ConsoleColor.Yellow);
Console.Write(" ");
InBrackets(device.Name, ConsoleColor.White, ConsoleColor.Green);
Console.WriteLine();
}

Console.Write("> Probing for disks...");
var disks = deviceService.GetDevices<IDiskDevice>();
Console.WriteLine("[Completed: " + disks.Count + " found]");

foreach (var disk in disks)
{
Console.Write(" ");
Bullet(ConsoleColor.Yellow);
Console.Write(" ");
InBrackets(disk.Name, ConsoleColor.White, ConsoleColor.Green);
Console.Write(" " + (disk.DeviceDriver as IDiskDevice).TotalBlocks + " blocks");
Console.WriteLine();
}

var partitionService = Mosa.Kernel.BareMetal.Kernel.ServiceManger.GetFirstService<PartitionService>();

partitionService.CreatePartitionDevices();

Console.Write("> Finding partitions...");
var partitions = deviceService.GetDevices<IPartitionDevice>();
Console.WriteLine("[Completed: " + partitions.Count + " found]");

foreach (var partition in partitions)
{
Console.Write(" ");
Bullet(ConsoleColor.Yellow);
Console.Write(" ");
InBrackets(partition.Name, ConsoleColor.White, ConsoleColor.Green);
Console.Write(" " + (partition.DeviceDriver as IPartitionDevice).BlockCount.ToString() + " blocks");
Console.WriteLine();
}

//Console.Write("> Finding file systems...");

//foreach (var partition in partitions)
//{
// var fat = new FatFileSystem(partition.DeviceDriver as IPartitionDevice);

// if (fat.IsValid)
// {
// Console.WriteLine("Found a FAT file system!");

// const string filename = "TEST.TXT";

// var location = fat.FindEntry(filename);

// if (location.IsValid)
// {
// Console.Write("Found: " + filename);

// var fatFileStream = new FatFileStream(fat, location);

// var len = (uint)fatFileStream.Length;

// Console.WriteLine(" - Length: " + len + " bytes");

// Console.Write("Reading File: ");

// for (; ; )
// {
// int i = fatFileStream.ReadByte();

// if (i < 0)
// break;

// Console.Write((char)i);
// }

// Console.WriteLine();
// }
// }
//}

while (true)
{ }
}

//[Plug("Mosa.Runtime.StartUp::BootOptions")]
public static void SetBootOptions()
{
BootOptions.EnableDebugOutput = true;
//BootOptions.EnableVirtualMemory = true;
//BootOptions.EnableMinimalBoot = true;
}

public static void InBrackets(string message, ConsoleColor outerColor, ConsoleColor innerColor)
{
var restore = Console.ForegroundColor;
Console.ForegroundColor = outerColor;
Console.Write("[");
Console.ForegroundColor = innerColor;
Console.Write(message);
Console.ForegroundColor = outerColor;
Console.Write("]");
Console.ForegroundColor = restore;
}

public static void Bullet(ConsoleColor color)
{
var restore = Console.ForegroundColor;
Console.ForegroundColor = color;
Console.Write("*");
Console.ForegroundColor = restore;
Program.EntryPoint();
}

public static void Include()
{
Mosa.Kernel.BareMetal.x86.Scheduler.SwitchToThread(null);
Kernel.BareMetal.x86.Scheduler.SwitchToThread(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
<UseAppHost>false</UseAppHost>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>MSB3245</NoWarn>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Mosa.DeviceDriver\Mosa.DeviceDriver.csproj" />
<ProjectReference Include="..\Mosa.DeviceSystem\Mosa.DeviceSystem.csproj" />
<ProjectReference Include="..\Mosa.FileSystem\Mosa.FileSystem.csproj" />
<ProjectReference Include="..\Mosa.BareMetal.HelloWorld\Mosa.BareMetal.HelloWorld.csproj" />
<ProjectReference Include="..\Mosa.Kernel.BareMetal.x86\Mosa.Kernel.BareMetal.x86.csproj" />
<ProjectReference Include="..\Mosa.Kernel.BareMetal\Mosa.Kernel.BareMetal.csproj" />
<ProjectReference Include="..\Mosa.Korlib\Mosa.Korlib.csproj" />
</ItemGroup>
</Project>
25 changes: 25 additions & 0 deletions Source/Mosa.BareMetal.HelloWorld/AppManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.BareMetal.HelloWorld.Apps;

namespace Mosa.BareMetal.HelloWorld;

public static class AppManager
{
private static readonly IApp[] Applications =
{
new Shell()
};

public static bool Execute(string name)
{
foreach (var app in Applications)
if (app.Name.ToLower() == name.ToLower())
{
app.Execute();
return true;
}

return false;
}
}
26 changes: 26 additions & 0 deletions Source/Mosa.BareMetal.HelloWorld/Apps/Shell.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 System;

namespace Mosa.BareMetal.HelloWorld.Apps;

public class Shell : IApp
{
public string Name => "Shell";

public void Execute()
{
Console.WriteLine();
Console.WriteLine("MOSA Shell v2.4");

while (true)
{
Console.Write("> ");

var cmd = Console.ReadLine().ToLower();

if (!AppManager.Execute(cmd))
Console.WriteLine("Unknown command: " + cmd);
}
}
}
10 changes: 10 additions & 0 deletions Source/Mosa.BareMetal.HelloWorld/IApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

namespace Mosa.BareMetal.HelloWorld;

public interface IApp
{
string Name { get; }

void Execute();
}

0 comments on commit 72fb7f2

Please sign in to comment.