Skip to content

Commit

Permalink
WIP - BareMetal (#1095)
Browse files Browse the repository at this point in the history
* - Added Graphviz integration to Explorer
- Updated IDT

* - WIP

* - WIP
  • Loading branch information
tgiphil committed Jul 29, 2023
1 parent b883129 commit a6dfe7e
Show file tree
Hide file tree
Showing 19 changed files with 493 additions and 239 deletions.
6 changes: 3 additions & 3 deletions Source/Mosa.Compiler.Framework/TransformContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,17 @@ public bool ApplyTransform(Context context, BaseTransform transform, int count)

public void TraceBefore(Context context, BaseTransform transformation, int count)
{
TraceLog?.Log($"[{context.Block}-{count}] {transformation.Name}");
TraceLog?.Log($"{count,-7}\t| {transformation.Name}");

if (transformation.Log)
SpecialTraceLog?.Log($"{transformation.Name}\t{Method.FullName} at {context}");

TraceLog?.Log($"BEFORE:\t{context}");
TraceLog?.Log($"{context.Block}\t| {context}");
}

public void TraceAfter(Context context)
{
TraceLog?.Log($"AFTER: \t{context}");
TraceLog?.Log($" \t| {context}");
TraceLog?.Log();
}

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

/// <summary>
Expand All @@ -95,7 +95,7 @@ public override void DebugWrite(string message)
/// <param name="message">The message.</param>
public override void DebugWriteLine(string message)
{
Boot.Console.WriteLine(message);
//Boot.Debug.WriteLine(message);
}

/// <summary>
Expand Down
8 changes: 5 additions & 3 deletions Source/Mosa.DeviceDriver/ISA/ISABus.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System.Collections.Generic;
using System.Diagnostics;
using Mosa.DeviceSystem;
using Mosa.Runtime;

Expand Down Expand Up @@ -30,7 +29,7 @@ public override void Start()

protected void StartISADevices()
{
Debug.WriteLine("ISABus:StartISADevices()");
HAL.DebugWriteLine("ISABus:StartISADevices()");

// Start ISA Drivers
var drivers = DeviceService.GetDeviceDrivers(DeviceBusType.ISA);
Expand All @@ -39,11 +38,14 @@ protected void StartISADevices()
{
if (driver is ISADeviceDriverRegistryEntry)
{
Debug.WriteLine("ISA: ", driver.Name);
HAL.DebugWrite("ISA: ");
HAL.DebugWriteLine(driver.Name);

StartISADevice(driver as ISADeviceDriverRegistryEntry);
}
}

HAL.DebugWriteLine("ISABus:StartISADevices() [Exit]");
}

protected void StartISADevice(ISADeviceDriverRegistryEntry driverEntry)
Expand Down
9 changes: 4 additions & 5 deletions Source/Mosa.DeviceDriver/X86System.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System.Diagnostics;
using Mosa.DeviceDriver.ISA;
using Mosa.DeviceSystem;

Expand All @@ -23,23 +22,23 @@ public override void Probe()

public override void Start()
{
Debug.WriteLine("X86System:Start()");
HAL.DebugWriteLine("X86System:Start()");

CreateISABusDevices();

Device.Status = DeviceStatus.Online;

Debug.WriteLine("X86System:Start() [Exit]");
HAL.DebugWriteLine("X86System:Start() [Exit]");
}

public override bool OnInterrupt() => true;

protected void CreateISABusDevices()
{
Debug.WriteLine("X86System:CreateISABusDevices()");
HAL.DebugWriteLine("X86System:CreateISABusDevices()");

DeviceService.Initialize(new ISABus(), Device, true, null, null, null);

Debug.WriteLine("X86System:CreateISABusDevices() [Exit]");
HAL.DebugWriteLine("X86System:CreateISABusDevices() [Exit]");
}
}
2 changes: 1 addition & 1 deletion Source/Mosa.DeviceSystem/DataBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Mosa.DeviceSystem;

/// <summary>
/// Data Block (Little Endian)
/// Data Block
/// </summary>
public class DataBlock
{
Expand Down
28 changes: 28 additions & 0 deletions Source/Mosa.DeviceSystem/IPAddress.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

namespace Mosa.DeviceSystem;

/// <summary>
/// IP Address
/// </summary>
public struct IPAddress
{
public static readonly IPAddress Default = new IPAddress(0, 0, 0, 0);
public static readonly IPAddress Local = new IPAddress(127, 0, 0, 1);

private readonly uint address;

public readonly byte A => (byte)address;

public readonly byte B => (byte)(address >> 8);

public readonly byte C => (byte)(address >> 16);

public readonly byte D => (byte)(address >> 24);

public IPAddress(IPAddress ipAddress) => address = ipAddress.address;

public IPAddress(byte a, byte b, byte c, byte d) => address = a | ((uint)b << 8) | ((uint)c << 16) | ((uint)d << 24);

public override readonly string ToString() => $"{A}.{B}.{C}.{D}";
}
43 changes: 21 additions & 22 deletions Source/Mosa.DeviceSystem/Service/DeviceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,6 @@ public Device Initialize(BaseDeviceDriver deviceDriver, Device parent, bool auto
{
HAL.DebugWriteLine("DeviceService:Initialize()");

if (deviceDriverRegistryEntry != null)
{
HAL.DebugWrite($" > Driver: ");
HAL.DebugWriteLine(deviceDriverRegistryEntry.Name);
}

var device = new Device
{
DeviceDriver = deviceDriver,
Expand Down Expand Up @@ -146,15 +140,6 @@ private void StartDevice(Device device)
{
HAL.DebugWriteLine("DeviceService:StartDevice()");

if (device.Name != null)
{
HAL.DebugWriteLine("#Device Name Length: " + device.Name.Length.ToString());

HAL.DebugWrite($" > Device: ");

HAL.DebugWriteLine(device.Name);
}

lock (_lock)
{
Devices.Add(device);
Expand All @@ -167,32 +152,42 @@ 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("DeviceService:StartDevice():Initializing = " + (device.Name ?? string.Empty));
//Debug.WriteLine(" > Initializing: ", device.Name);

HAL.DebugWriteLine(" # Initializing");
device.DeviceDriver.Initialize();

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

if (device.Status == DeviceStatus.Initializing)
{
//HAL.DebugWriteLine("DeviceService:StartDevice():Probing = " + (device.Name ?? string.Empty));
HAL.DebugWriteLine(" # Probing");
device.DeviceDriver.Probe();

if (device.Status == DeviceStatus.Available)
{
//HAL.DebugWriteLine("DeviceService:StartDevice():Starting = " + (device.Name ?? string.Empty));
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");
HAL.DebugWriteLine("DeviceService:StartDevice():Exit");
}

#endregion Initialize Devices Drivers
Expand Down Expand Up @@ -349,9 +344,11 @@ public void ProcessInterrupt(byte irq)

public void AddInterruptHandler(Device device)
{
HAL.DebugWriteLine("DeviceService::AddInterruptHandler()");

if (device.Resources != null)
{
byte irq = device.Resources.IRQ;
var irq = device.Resources.IRQ;

if (irq >= MaxInterrupts)
return;
Expand All @@ -361,6 +358,8 @@ public void AddInterruptHandler(Device device)
IRQDispatch[irq].Add(device);
}
}

HAL.DebugWriteLine("DeviceService::AddInterruptHandler() [Exit]");
}

public void ReleaseInterruptHandler(Device device)
Expand Down

0 comments on commit a6dfe7e

Please sign in to comment.