Skip to content

Commit

Permalink
More BareMetal changes (#1114)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnErrupTion committed Aug 9, 2023
1 parent 4218a41 commit 2dd0ddb
Show file tree
Hide file tree
Showing 39 changed files with 1,296 additions and 381 deletions.
14 changes: 12 additions & 2 deletions Source/Mosa.BareMetal.HelloWorld/AppManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ namespace Mosa.BareMetal.HelloWorld;

public static class AppManager
{
private static readonly IApp[] Applications =
public static readonly IApp[] Applications =
{
new Shell()
new Clear(),
new Credits(),
new Help(),
new Mem(),
new Reboot(),
new Shell(),
new ShowDisks(),
new ShowFS(),
new ShowISA(),
new ShowPCI(),
new Shutdown()
};

public static bool Execute(string name)
Expand Down
17 changes: 17 additions & 0 deletions Source/Mosa.BareMetal.HelloWorld/Apps/Clear.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System;

namespace Mosa.BareMetal.HelloWorld.Apps;

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

public string Description => "Clears the screen.";

public void Execute()
{
Console.Clear();
}
}
30 changes: 30 additions & 0 deletions Source/Mosa.BareMetal.HelloWorld/Apps/Credits.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System;

namespace Mosa.BareMetal.HelloWorld.Apps;

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

public string Description => "Shows everyone who contributed to the project.";

public void Execute()
{
Console.WriteLine("*** MOSA Credits ****");
Console.WriteLine(" Phil Garcia");
Console.WriteLine(" Simon Wollwage");
Console.WriteLine(" Michael Frohlich");
Console.WriteLine(" Stefan Andres Charsley");
Console.WriteLine(" Chin Ki Yuen");
Console.WriteLine(" Patrick Reisert");
Console.WriteLine(" Phillip Webster");
Console.WriteLine(" Kevin Thompson");
Console.WriteLine(" Kai P.Reisert");
Console.WriteLine(" M.de Bruijn");
Console.WriteLine(" Royce Mitchell III");
Console.WriteLine(" Sebastian Loncar");
Console.WriteLine(" AnErrupTion");
}
}
18 changes: 18 additions & 0 deletions Source/Mosa.BareMetal.HelloWorld/Apps/Help.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System;

namespace Mosa.BareMetal.HelloWorld.Apps;

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

public string Description => "Shows information about all commands.";

public void Execute()
{
foreach (var app in AppManager.Applications)
Console.WriteLine(app.Name + " - " + app.Description);
}
}
22 changes: 22 additions & 0 deletions Source/Mosa.BareMetal.HelloWorld/Apps/Mem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System;
using Mosa.Kernel.BareMetal;

namespace Mosa.BareMetal.HelloWorld.Apps;

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

public string Description => "Shows memory information.";

public void Execute()
{
Console.WriteLine("**** Memory ****");
Console.WriteLine(" Total Pages : " + PageFrameAllocator.TotalPages);
Console.WriteLine(" Used Pages : " + PageFrameAllocator.UsedPages);
Console.WriteLine(" Page Size : " + Page.Size);
Console.WriteLine(" Free Memory : " + (PageFrameAllocator.TotalPages - PageFrameAllocator.UsedPages) * Page.Size / (1024 * 1024) + " MB");
}
}
24 changes: 24 additions & 0 deletions Source/Mosa.BareMetal.HelloWorld/Apps/Reboot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System;
using Mosa.DeviceSystem;
using Mosa.DeviceSystem.Service;

namespace Mosa.BareMetal.HelloWorld.Apps;

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

public string Description => "Reboots the computer.";

public void Execute()
{
Console.WriteLine("Rebooting...");

var pc = Kernel.BareMetal.Kernel.ServiceManager.GetFirstService<PCService>();
pc.Reset();

for (;;) HAL.Yield();
}
}
6 changes: 6 additions & 0 deletions Source/Mosa.BareMetal.HelloWorld/Apps/Shell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ public class Shell : IApp
{
public string Name => "Shell";

public string Description => "Runs the interactive shell.";

public void Execute()
{
Console.WriteLine();
Console.WriteLine("MOSA Shell v2.4");
Console.WriteLine("Enter \"quit\" to exit the shell.");

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

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

if (cmd == "quit")
break;

if (!AppManager.Execute(cmd))
Console.WriteLine("Unknown command: " + cmd);
}
Expand Down
45 changes: 45 additions & 0 deletions Source/Mosa.BareMetal.HelloWorld/Apps/ShowDisks.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 System;
using Mosa.DeviceDriver.ISA;
using Mosa.DeviceSystem;
using Mosa.DeviceSystem.Service;

namespace Mosa.BareMetal.HelloWorld.Apps;

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

public string Description => "Shows information about disk controllers and disks.";

public void Execute()
{
Console.Write("> Probing for disk controllers...");
var diskControllers = Program.DeviceService.GetDevices<IDiskControllerDevice>();
Console.WriteLine("[Completed: " + diskControllers.Count + " found]");

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

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

foreach (var disk in disks)
{
Console.Write(" ");
Program.Bullet(ConsoleColor.Yellow);
Console.Write(" ");
Program.InBrackets(disk.Name, ConsoleColor.White, ConsoleColor.Green);
Console.Write(" " + (disk.DeviceDriver as IDiskDevice).TotalBlocks + " blocks");
Console.WriteLine();
}
}
}
63 changes: 63 additions & 0 deletions Source/Mosa.BareMetal.HelloWorld/Apps/ShowFS.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System;
using Mosa.DeviceSystem;
using Mosa.FileSystem.FAT;

namespace Mosa.BareMetal.HelloWorld.Apps;

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

public string Description => "Shows information about partitions and file systems.";

public void Execute()
{
Console.Write("> Finding partitions...");
var partitions = Program.DeviceService.GetDevices<IPartitionDevice>();
Console.WriteLine("[Completed: " + partitions.Count + " found]");

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

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

foreach (var partition in partitions)
{
var fat = new FatFileSystem(partition.DeviceDriver as IPartitionDevice);
if (!fat.IsValid) continue;

Console.WriteLine("Found a FAT file system!");

var location = fat.FindEntry("TEST.TXT");
if (!location.IsValid) continue;

Console.Write("Found test file!");

var testStream = new FatFileStream(fat, location);

Console.WriteLine(" - Length: " + (uint)testStream.Length + " bytes");
Console.Write("Reading File: ");

for (; ; )
{
var i = testStream.ReadByte();

if (i < 0)
break;

Console.Write((char)i);
}

Console.WriteLine();
}
}
}
30 changes: 30 additions & 0 deletions Source/Mosa.BareMetal.HelloWorld/Apps/ShowISA.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System;
using Mosa.DeviceDriver.ISA;

namespace Mosa.BareMetal.HelloWorld.Apps;

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

public string Description => "Shows information about ISA devices.";

public void Execute()
{
Console.Write("> Probing for ISA devices...");

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

foreach (var device in isaDevices)
{
Console.Write(" ");
Program.Bullet(ConsoleColor.Yellow);
Console.Write(" ");
Program.InBrackets(device.Name, ConsoleColor.White, ConsoleColor.Green);
Console.WriteLine();
}
}
}
44 changes: 44 additions & 0 deletions Source/Mosa.BareMetal.HelloWorld/Apps/ShowPCI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System;
using Mosa.DeviceSystem.PCI;

namespace Mosa.BareMetal.HelloWorld.Apps;

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

public string Description => "Shows information about PCI devices.";

public void Execute()
{
Console.Write("> Probing for PCI devices...");
var devices = Program.DeviceService.GetDevices<PCIDevice>();
Console.WriteLine("[Completed: " + devices.Count + " found]");

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

var pciDevice = device.DeviceDriver as PCIDevice;
Program.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 = Program.DeviceService.GetChildrenOf(device);

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

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

Program.InBrackets(child.Name, ConsoleColor.White, ConsoleColor.Green);
}

Console.WriteLine();
}
}
}
24 changes: 24 additions & 0 deletions Source/Mosa.BareMetal.HelloWorld/Apps/Shutdown.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System;
using Mosa.DeviceSystem;
using Mosa.DeviceSystem.Service;

namespace Mosa.BareMetal.HelloWorld.Apps;

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

public string Description => "Shuts down the computer.";

public void Execute()
{
Console.WriteLine("Shutting down...");

var pc = Kernel.BareMetal.Kernel.ServiceManager.GetFirstService<PCService>();
pc.Shutdown();

for (;;) HAL.Yield();
}
}
2 changes: 2 additions & 0 deletions Source/Mosa.BareMetal.HelloWorld/IApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ public interface IApp
{
string Name { get; }

string Description { get; }

void Execute();
}

0 comments on commit 2dd0ddb

Please sign in to comment.