Skip to content

Commit

Permalink
WIP - BareMetal (#1101)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgiphil committed Jul 31, 2023
1 parent 35cb5fa commit 119a119
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 93 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ jobs:
- name: Demo Test - CoolWorld
run: bin\Mosa.Tool.Launcher.Console.exe bin\Mosa.Demo.CoolWorld.x86.dll -o${{ matrix.optimization }} -check -test
- name: Demo Test - SVGAWorld
run: bin\Mosa.Tool.Launcher.Console.exe bin\Mosa.Demo.SVGAWorld.x86.dll -o${{ matrix.optimization }} -check -test
run: bin\Mosa.Tool.Launcher.Console.exe bin\Mosa.Demo.SVGAWorld.x86.dll -o${{ matrix.optimization }} -check -test -vmware-svga -include bin\Include

linux-demo-testing:
strategy:
Expand Down Expand Up @@ -333,7 +333,7 @@ jobs:
- name: Demo Test - CoolWorld
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.Demo.CoolWorld.x86.dll -o${{ matrix.optimization }} -check -test
- name: Demo Test - SVGAWorld
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.Demo.SVGAWorld.x86.dll -o${{ matrix.optimization }} -check -test
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.Demo.SVGAWorld.x86.dll -o${{ matrix.optimization }} -check -test -vmware-svga -include bin/Include

#macos-demo-testing:
# strategy:
Expand Down
14 changes: 7 additions & 7 deletions Source/Mosa.Demo.CoolWorld.x86/Boot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,20 @@ public static void Main()
var pciDeviceService = new PCIDeviceService();
var pcService = new PCService();

serviceManager.AddService(DeviceService);
serviceManager.AddService(diskDeviceService);
serviceManager.AddService(partitionService);
serviceManager.AddService(pciControllerService);
serviceManager.AddService(pciDeviceService);
serviceManager.AddService(pcService);

Console.WriteLine("> Initializing hardware abstraction layer...");

// Set device driver system with the hardware HAL
var hardware = new HAL.Hardware();

DeviceSystem.Setup.Initialize(hardware, DeviceService.ProcessInterrupt);

serviceManager.AddService(DeviceService);
serviceManager.AddService(diskDeviceService);
serviceManager.AddService(partitionService);
serviceManager.AddService(pciControllerService);
serviceManager.AddService(pciDeviceService);
serviceManager.AddService(pcService);

Console.WriteLine("> Registering device drivers...");

DeviceService.RegisterDeviceDriver(DeviceDriver.Setup.GetDeviceDriverRegistryEntries());
Expand Down
14 changes: 10 additions & 4 deletions Source/Mosa.Demo.SVGAWorld.x86/Boot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public static void Main()
Kernel.x86.Kernel.Setup();
IDT.SetInterruptHandler(ProcessInterrupt);

Console.WriteLine("##PASS##");

HAL = new Hardware();
Random = new Random();
DeviceService = new DeviceService();
Expand All @@ -50,15 +48,15 @@ public static void Main()
var serviceManager = new ServiceManager();
var partitionService = new PartitionService();

DeviceSystem.Setup.Initialize(HAL, DeviceService.ProcessInterrupt);

serviceManager.AddService(DeviceService);
serviceManager.AddService(new DiskDeviceService());
serviceManager.AddService(partitionService);
serviceManager.AddService(new PCService());
serviceManager.AddService(new PCIControllerService());
serviceManager.AddService(new PCIDeviceService());

DeviceSystem.Setup.Initialize(HAL, DeviceService.ProcessInterrupt);

DeviceService.RegisterDeviceDriver(DeviceDriver.Setup.GetDeviceDriverRegistryEntries());
DeviceService.Initialize(new X86System(), null);

Expand Down Expand Up @@ -92,6 +90,8 @@ public static void Main()

private static void DoGraphics()
{
bool confirm = false;

Utils.BackColor = Color.Indigo;
Utils.Mouse.SetScreenResolution(Display.Width, Display.Height);

Expand Down Expand Up @@ -143,6 +143,12 @@ private static void DoGraphics()
// Update graphics and FPS meter
Display.Update();
FPSMeter.Update();

if (!confirm)
{
Logger.Log("##PASS##");
confirm = true;
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions Source/Mosa.Demo.SVGAWorld.x86/HAL/Hardware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public override ConstrainedPointer AllocateVirtualMemory(uint size, uint alignme
/// <param name="message">The message.</param>
public override void DebugWrite(string message)
{
Console.Write(message);
//Console.Write(message);
}

/// <summary>
Expand All @@ -100,8 +100,8 @@ public override void DebugWrite(string message)
/// <param name="message">The message.</param>
public override void DebugWriteLine(string message)
{
Serial.Write(Serial.COM1, message);
Serial.Write(Serial.COM1, (byte)'\n');
//Serial.Write(Serial.COM1, message);
//Serial.Write(Serial.COM1, (byte)'\n');
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.DeviceSystem/BaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void Start(ServiceManager serviceManager)
/// <summary>
/// Initializes this instance.
/// </summary>
public virtual void Initialize()
protected virtual void Initialize()
{ }

/// <summary>
Expand Down
10 changes: 10 additions & 0 deletions Source/Mosa.DeviceSystem/HAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ public static class HAL
/// <param name="message">The message.</param>
public static void Abort(string message) => hardwareAbstraction.Abort(message);

/// <summary>
/// Aborts with the specified message.
/// </summary>
/// <param name="message">The message.</param>
public static void Assert(bool condition, string message)
{
if (!condition)
hardwareAbstraction.Abort(message);
}

/// <summary>
/// Pause
/// </summary>
Expand Down
41 changes: 15 additions & 26 deletions Source/Mosa.DeviceSystem/Service/DeviceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public sealed class DeviceService : BaseService
/// </summary>
private readonly List<Device> pendingOnChange;

private readonly object _lock = new object();
private readonly object sync = new object();

/// <summary>
/// Initializes a new instance of the <see cref="DeviceService" /> class.
Expand Down Expand Up @@ -70,7 +70,7 @@ public void RegisterDeviceDriver(List<DeviceDriverRegistryEntry> deviceDrivers)

public void RegisterDeviceDriver(DeviceDriverRegistryEntry deviceDriver)
{
lock (_lock)
lock (sync)
{
Registry.Add(deviceDriver);
}
Expand All @@ -80,7 +80,7 @@ public List<DeviceDriverRegistryEntry> GetDeviceDrivers(DeviceBusType busType)
{
var drivers = new List<DeviceDriverRegistryEntry>();

lock (_lock)
lock (sync)
{
foreach (var deviceDriver in Registry)
{
Expand Down Expand Up @@ -140,7 +140,7 @@ private void StartDevice(Device device)
{
HAL.DebugWriteLine("DeviceService:StartDevice()");

lock (_lock)
lock (sync)
{
Devices.Add(device);

Expand All @@ -152,39 +152,28 @@ private void StartDevice(Device device)

device.Status = DeviceStatus.Initializing;

//HAL.DebugWriteLine($" # Setup");

device.DeviceDriver.Setup(device);

//HAL.DebugWriteLine($" # Setup [Done]");

if (device.Status == DeviceStatus.Initializing)
{
//HAL.DebugWriteLine(" # Initializing");
device.DeviceDriver.Initialize();

HAL.DebugWrite(" # Initialized: ");
HAL.DebugWriteLine(device.Name);

if (device.Status == DeviceStatus.Initializing)
{
//HAL.DebugWriteLine(" # Probing");
device.DeviceDriver.Probe();

if (device.Status == DeviceStatus.Available)
{
//HAL.DebugWriteLine(" # Starting");
device.DeviceDriver.Start();

//HAL.DebugWriteLine(" # Started");

AddInterruptHandler(device);
}
}
}

HAL.DebugWriteLine($" # ServiceManager.AddEvent");

ServiceManager.AddEvent(new ServiceEvent(ServiceEventType.Start, device));

HAL.DebugWriteLine("DeviceService:StartDevice():Exit");
Expand All @@ -196,7 +185,7 @@ private void StartDevice(Device device)

public Device GetFirstDevice<T>()
{
lock (_lock)
lock (sync)
{
foreach (var device in Devices)
{
Expand All @@ -214,7 +203,7 @@ public List<Device> GetDevices<T>()
{
var list = new List<Device>();

lock (_lock)
lock (sync)
{
foreach (var device in Devices)
{
Expand All @@ -230,7 +219,7 @@ public List<Device> GetDevices<T>()

public Device GetFirstDevice<T>(DeviceStatus status)
{
lock (_lock)
lock (sync)
{
foreach (var device in Devices)
{
Expand All @@ -248,7 +237,7 @@ public List<Device> GetDevices<T>(DeviceStatus status)
{
var list = new List<Device>();

lock (_lock)
lock (sync)
{
foreach (var device in Devices)
{
Expand All @@ -266,7 +255,7 @@ public List<Device> GetDevices(string name)
{
var list = new List<Device>();

lock (_lock)
lock (sync)
{
foreach (var device in Devices)
{
Expand All @@ -284,7 +273,7 @@ public List<Device> GetChildrenOf(Device parent)
{
var list = new List<Device>();

lock (_lock)
lock (sync)
{
foreach (var device in parent.Children)
{
Expand All @@ -297,7 +286,7 @@ public List<Device> GetChildrenOf(Device parent)

public List<Device> GetAllDevices()
{
lock (_lock)
lock (sync)
{
var list = new List<Device>(Devices.Count);

Expand All @@ -312,7 +301,7 @@ public List<Device> GetAllDevices()

public bool CheckExists(Device parent, ulong componentID)
{
lock (_lock)
lock (sync)
{
foreach (var device in Devices)
{
Expand All @@ -332,7 +321,7 @@ public bool CheckExists(Device parent, ulong componentID)

public void ProcessInterrupt(byte irq)
{
lock (_lock)
lock (sync)
{
foreach (var device in IRQDispatch[irq])
{
Expand All @@ -353,7 +342,7 @@ public void AddInterruptHandler(Device device)
if (irq >= MaxInterrupts)
return;

lock (_lock)
lock (sync)
{
IRQDispatch[irq].Add(device);
}
Expand All @@ -371,7 +360,7 @@ public void ReleaseInterruptHandler(Device device)
if (irq >= MaxInterrupts)
return;

lock (_lock)
lock (sync)
{
IRQDispatch[irq].Remove(device);
}
Expand Down
3 changes: 1 addition & 2 deletions Source/Mosa.DeviceSystem/Service/DiskDeviceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ public class DiskDeviceService : BaseService
[MethodImpl(MethodImplOptions.NoInlining)]
public override void PostEvent(ServiceEvent serviceEvent)
{
//HAL.DebugWriteLine("DiskDeviceService:PostEvent()-A");
//HAL.Pause();
//HAL.DebugWriteLine("DiskDeviceService:PostEvent()");

var device = MatchEvent<IDiskControllerDevice>(serviceEvent, ServiceEventType.Start);

Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.DeviceSystem/Service/PCIControllerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class PCIControllerService : BaseService
/// <summary>
/// Initializes this instance.
/// </summary>
public override void Initialize()
protected override void Initialize()
{
DeviceService = ServiceManager.GetFirstService<DeviceService>();
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.DeviceSystem/Service/PCIDeviceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class PCIDeviceService : BaseService
/// <summary>
/// Initializes this instance.
/// </summary>
public override void Initialize()
protected override void Initialize()
{
DeviceService = ServiceManager.GetFirstService<DeviceService>();
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.DeviceSystem/Service/PCService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class PCService : BaseService
/// <summary>
/// Initializes this instance.
/// </summary>
public override void Initialize()
protected override void Initialize()
{
DeviceService = ServiceManager.GetFirstService<DeviceService>();
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.DeviceSystem/Service/PartitionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class PartitionService : BaseService
/// <summary>
/// Initializes this instance.
/// </summary>
public override void Initialize()
protected override void Initialize()
{
DeviceService = ServiceManager.GetFirstService<DeviceService>();
}
Expand Down

0 comments on commit 119a119

Please sign in to comment.