Skip to content
Permalink
Browse files

WIP - Device System (#618)

* - Minor update

* - WIP

* - WIP

* - WIP

* - WIP

* - WIP

* - WIP

* - Fix

* - Initial service component

* - WIP

* - WIP

* - WIP

* - WIP

* - WIP

* - WIP

* - WIP

* - WIP

* - WIP
  • Loading branch information...
tgiphil committed Mar 29, 2019
1 parent 33dfff6 commit 6d96906dce5d015e869c342b8d000ee1f445cd27
Showing with 789 additions and 448 deletions.
  1. +1 −1 Demos/Windows/Run-CoolWorld.x86.bat
  2. +3 −0 Source/Mosa.Compiler.Framework/Compiler.cs
  3. +5 −0 Source/Mosa.Compiler.Framework/MosaTypeLayout.cs
  4. +8 −4 Source/Mosa.Compiler.MosaTypeSystem/Metadata/MetadataResolver.cs
  5. +110 −66 Source/Mosa.CoolWorld.x86/Boot.cs
  6. +2 −2 Source/Mosa.CoolWorld.x86/HAL/Hardware.cs
  7. +2 −2 Source/Mosa.DeviceDriver/ISA/ISABus.cs
  8. +1 −5 Source/Mosa.DeviceDriver/ISA/PCIController.cs
  9. +1 −1 Source/Mosa.DeviceDriver/Mosa.DeviceDriver.csproj
  10. +4 −0 Source/Mosa.DeviceDriver/PCI/VMware/VMwareSVGAII.cs
  11. +11 −9 Source/Mosa.DeviceDriver/PCI/VideoCard/GenericVGA.cs
  12. +79 −57 Source/Mosa.DeviceDriver/Setup.cs
  13. +1 −1 Source/Mosa.DeviceDriver/X86System.cs
  14. +1 −1 Source/Mosa.DeviceSystem/BaseDeviceDriver.cs
  15. +54 −0 Source/Mosa.DeviceSystem/BaseService.cs
  16. +1 −1 Source/Mosa.DeviceSystem/Device.cs
  17. +73 −108 Source/Mosa.DeviceSystem/{DeviceManager.cs → DeviceService.cs}
  18. +12 −10 Source/Mosa.DeviceSystem/{DiskDeviceMountDeamon.cs → DiskDeviceService.cs}
  19. +1 −0 Source/Mosa.DeviceSystem/DiskPartitionConfiguration.cs
  20. +0 −44 Source/Mosa.DeviceSystem/IHardwareDevice.cs
  21. +0 −11 Source/Mosa.DeviceSystem/IService.cs
  22. +1 −1 Source/Mosa.DeviceSystem/ITextScreen.cs
  23. +10 −8 Source/Mosa.DeviceSystem/Mosa.DeviceSystem.csproj
  24. +1 −1 Source/Mosa.DeviceSystem/PCI/IPCIDevice.cs
  25. +1 −1 Source/Mosa.DeviceSystem/PCI/IPCIDeviceResource.cs
  26. +4 −3 Source/Mosa.DeviceSystem/PCI/PCIDevice.cs
  27. +42 −37 Source/Mosa.DeviceSystem/{PCIControllerManager.cs → PCIControllerService.cs}
  28. +2 −2 Source/Mosa.DeviceSystem/PCIDeviceDriverRegistryEntry.cs
  29. +137 −0 Source/Mosa.DeviceSystem/PCIDeviceService.cs
  30. +0 −61 Source/Mosa.DeviceSystem/PartitionManager.cs
  31. +60 −0 Source/Mosa.DeviceSystem/PartitionService.cs
  32. +17 −0 Source/Mosa.DeviceSystem/ServiceEvent.cs
  33. +8 −2 Source/Mosa.DeviceSystem/{BaseMountDaemon.cs → ServiceEventType.cs}
  34. +133 −0 Source/Mosa.DeviceSystem/ServiceManager.cs
  35. +2 −9 Source/Mosa.DeviceSystem/Setup.cs
  36. +1 −0 Source/Mosa.Tool.Explorer/MainForm.cs
@@ -1,3 +1,3 @@
cd %~dp0
cd ..\..\bin
start Mosa.Tool.Launcher.exe --q --autostart --output-map --output-asm --output-debuginfo Mosa.CoolWorld.x86.exe
start Mosa.Tool.Launcher.exe --q --autostart --output-map --output-asm --output-debuginfo --inline-off Mosa.CoolWorld.x86.exe
@@ -375,6 +375,9 @@ private MosaMethod CompilerMethodInQueue(int threadID = 0)

public MosaMethod CompileMethod(MosaMethod method, int threadID = 0)
{
if (method.IsCompilerGenerated)
return method;

lock (method)
{
CompileMethod(method, null, threadID);
@@ -710,8 +710,13 @@ private List<MosaMethod> CreateMethodTable(MosaType type)
}
else if (!method.IsInternal && !method.IsExternal)
{
// HACK
if (methodSlots.ContainsKey(method))
continue;

int slot = methodTable.Count;
methodTable.Add(method);

methodSlots.Add(method, slot);
}
}
@@ -473,8 +473,7 @@ private MosaInstruction ResolveInstruction(MethodDef methodDef, CilBody body, in
private MosaField ResolveFieldOperand(IField operand, GenericArgumentResolver resolver)
{
TypeSig declType;
var fieldDef = operand as FieldDef;
if (fieldDef == null)
if (!(operand is FieldDef fieldDef))
{
var memberRef = (MemberRef)operand;
fieldDef = memberRef.ResolveFieldThrow();
@@ -502,6 +501,7 @@ private MosaField ResolveFieldOperand(IField operand, GenericArgumentResolver re
private MosaMethod ResolveArrayMethod(IMethod method, GenericArgumentResolver resolver)
{
var type = metadata.Loader.GetType(resolver.Resolve(method.DeclaringType.ToTypeSig()));

if (method.Name == "Get")
return type.FindMethodByName("Get");
else if (method.Name == "Set")
@@ -517,13 +517,16 @@ private MosaMethod ResolveArrayMethod(IMethod method, GenericArgumentResolver re
private MosaMethod ResolveMethodOperand(IMethod operand, GenericArgumentResolver resolver)
{
if (operand is MethodSpec)
{
return metadata.Loader.LoadGenericMethodInstance((MethodSpec)operand, resolver);
}
else if (operand.DeclaringType.TryGetArraySig() != null || operand.DeclaringType.TryGetSZArraySig() != null)
{
return ResolveArrayMethod(operand, resolver);
}

TypeSig declType;
var methodDef = operand as MethodDef;
if (methodDef == null)
if (!(operand is MethodDef methodDef))
{
var memberRef = (MemberRef)operand;
methodDef = memberRef.ResolveMethodThrow();
@@ -576,6 +579,7 @@ private void ResolveSZArray(MosaType arrayType)
.Methods
.Where(x => x.GenericArguments.Count > 0 && x.GenericArguments[0] == arrayType.ElementType)
.ToList();

foreach (var method in methods)
{
// HACK: the normal Equals for methods only compares signatures which causes issues with wrong methods being removed from the list
@@ -1,8 +1,11 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.AppSystem;
using Mosa.DeviceDriver;
using Mosa.DeviceDriver.ISA;
using Mosa.DeviceDriver.ScanCodeMap;
using Mosa.DeviceSystem;
using Mosa.DeviceSystem.PCI;
using Mosa.FileSystem.FAT;
using Mosa.Kernel.x86;
using Mosa.Runtime.Plug;
@@ -36,9 +39,6 @@ public static void Main()

Console.Clear();
Console.Goto(0, 0);

//IDT.SetInterruptHandler(ProcessInterrupt);

Console.ScrollRow = 23;
Console.Color = ScreenColor.White;
Console.BackgroundColor = ScreenColor.Green;
@@ -50,90 +50,134 @@ public static void Main()
Console.Color = ScreenColor.White;
Console.BackgroundColor = ScreenColor.Black;

Console.WriteLine("> Initializing hardware abstraction layer...");
var hardware = new HAL.Hardware();
Console.WriteLine("> Initializing services...");

var DeviceManager = Setup.Initialize(PlatformArchitecture.X86, hardware);
// Create Service manager and basic services
var serviceManager = new ServiceManager();

Console.WriteLine("> Registering device drivers...");
DeviceDriver.Setup.Register(DeviceManager);
var deviceService = new DeviceService();
var diskDeviceService = new DiskDeviceService();
var partitionService = new PartitionService();
var pciControllerService = new PCIControllerService();
var pciDeviceService = new PCIDeviceService();

Console.WriteLine("> Starting devices...");
DeviceDriver.Setup.Start(DeviceManager);

Console.Write("> Probing for ISA devices...");
var isaDevices = DeviceManager.GetAllDevices();
Console.WriteLine("[Completed: " + isaDevices.Count.ToString() + " found]");

foreach (var device in isaDevices)
{
Console.Write(" ");
Bullet(ScreenColor.Yellow);
Console.Write(" ");
InBrackets(device.Name, ScreenColor.White, ScreenColor.Green);
Console.WriteLine();
}
serviceManager.AddService(deviceService);
serviceManager.AddService(diskDeviceService);
serviceManager.AddService(partitionService);
serviceManager.AddService(pciControllerService);
serviceManager.AddService(pciDeviceService);

Console.Write("> Probing for PCI devices...");
Console.WriteLine("> Initializing hardware abstraction layer...");

//Setup.StartPCIDevices();
var pciDevices = DeviceManager.GetDevices<DeviceSystem.PCI.IPCIDevice>(DeviceStatus.Available);
Console.WriteLine("[Completed: " + pciDevices.Count.ToString() + " found]");
// Set device driver system with the hardware HAL
var hardware = new HAL.Hardware();
DeviceSystem.Setup.Initialize(hardware, deviceService.ProcessInterrupt);

foreach (var device in pciDevices)
{
var pciDevice = device.DeviceDriver as DeviceSystem.PCI.IPCIDevice;
Console.WriteLine("> Registering device drivers...");
deviceService.RegisterDeviceDriver(DeviceDriver.Setup.GetDeviceDriverRegistryEntries());

Console.Write(" ");
Bullet(ScreenColor.Yellow);
Console.Write(" ");
InBrackets(device.Name + ": " + pciDevice.VendorID.ToString("x") + ":" + pciDevice.DeviceID.ToString("x") + " " + pciDevice.SubSystemID.ToString("x") + ":" + pciDevice.SubVendorID.ToString("x") + " (" + pciDevice.Function.ToString("x") + ":" + pciDevice.ClassCode.ToString("x") + ":" + pciDevice.SubClassCode.ToString("x") + ":" + pciDevice.ProgIF.ToString("x") + ":" + pciDevice.RevisionID.ToString("x") + ")", ScreenColor.White, ScreenColor.Green);
Console.WriteLine();
}
Console.WriteLine("> Starting devices...");
deviceService.Initialize(new X86System(), null);

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

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

Console.Write("> Probing for disks...");
var disks = DeviceManager.GetDevices<IDiskDevice>();
Console.WriteLine("[Completed: " + disks.Count.ToString() + " found]");
if (device.Parent != null && device.Parent.DeviceDriver is PCIDevice)
{
var pciDevice = device.Parent.DeviceDriver as PCIDevice;
InBrackets(device.Name + ": " + pciDevice.VendorID.ToString("x") + ":" + pciDevice.DeviceID.ToString("x") + " " + pciDevice.SubSystemID.ToString("x") + ":" + pciDevice.SubSystemVendorID.ToString("x") + " (" + pciDevice.Function.ToString("x") + ":" + pciDevice.ClassCode.ToString("x") + ":" + pciDevice.SubClassCode.ToString("x") + ":" + pciDevice.ProgIF.ToString("x") + ":" + pciDevice.RevisionID.ToString("x") + ")", ScreenColor.White, ScreenColor.Green);
}
else if (device.DeviceDriver is PCIDevice)
{
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.Function.ToString("x") + ":" + pciDevice.ClassCode.ToString("x") + ":" + pciDevice.SubClassCode.ToString("x") + ":" + pciDevice.ProgIF.ToString("x") + ":" + pciDevice.RevisionID.ToString("x") + ")", ScreenColor.White, ScreenColor.Green);
}
else
{
InBrackets(device.Name, ScreenColor.White, ScreenColor.Green);
}

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

var partitionManager = new PartitionManager(DeviceManager);
partitionManager.CreatePartitionDevices();
//Console.Write("> Probing for ISA devices...");
//var isaDevices = deviceService.GetChildrenOf(deviceService.GetFirstDevice<ISABus>());
//Console.WriteLine("[Completed: " + isaDevices.Count.ToString() + " found]");

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

//Console.Write("> Probing for PCI devices...");
//var pciDevices = deviceService.GetAllDevices();
//Console.WriteLine("[Completed: " + pciDevices.Count.ToString() + " found]");

//foreach (var device in pciDevices)
//{
// var pciDevice = device.DeviceDriver as DeviceSystem.PCI.IPCIDevice;

// Console.Write(" ");
// Bullet(ScreenColor.Yellow);
// Console.Write(" ");

// InBrackets(device.Name + ": " + pciDevice.VendorID.ToString("x") + ":" + pciDevice.DeviceID.ToString("x") + " " + pciDevice.SubSystemID.ToString("x") + ":" + pciDevice.SubSystemVendorID.ToString("x") + " (" + pciDevice.Function.ToString("x") + ":" + pciDevice.ClassCode.ToString("x") + ":" + pciDevice.SubClassCode.ToString("x") + ":" + pciDevice.ProgIF.ToString("x") + ":" + pciDevice.RevisionID.ToString("x") + ")", ScreenColor.White, ScreenColor.Green);
// Console.WriteLine();
//}

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

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

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

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

partitionService.CreatePartitionDevices();

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

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

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

@@ -177,7 +221,7 @@ public static void Main()
}

// Get StandardKeyboard
var standardKeyboards = DeviceManager.GetDevices("StandardKeyboard");
var standardKeyboards = deviceService.GetDevices("StandardKeyboard");

if (standardKeyboards.Count == 0)
{
@@ -121,7 +121,7 @@ public override IOPortWrite RequestWriteIOPort(ushort port)
/// <param name="message">The message.</param>
public override void DebugWrite(string message)
{
Boot.Debug.Write(message);
Boot.Console.Write(message);
}

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

/// <summary>
@@ -29,7 +29,7 @@ public override void Start()
protected void StartISADevices()
{
// Start ISA Drivers
var drivers = DeviceManager.GetDeviceDrivers(DeviceBusType.ISA);
var drivers = DeviceService.GetDeviceDrivers(DeviceBusType.ISA);

foreach (var driver in drivers)
{
@@ -72,7 +72,7 @@ protected void StartISADevice(ISADeviceDriverRegistryEntry driverEntry)

var hardwareResources = new HardwareResources(ioPortRegions, memoryRegions, driverEntry.IRQ);

DeviceManager.Initialize(driverEntry, null, null, hardwareResources);
DeviceService.Initialize(driverEntry, Device, null, hardwareResources);
}
}
}
@@ -16,7 +16,6 @@ public class PCIController : BaseDeviceDriver, IPCIController

#endregion Definitions


/// <summary>
/// The configuration address
/// </summary>
@@ -45,10 +44,7 @@ public override void Probe()

var found = configAddress.Read32() == BaseValue;

if (!found)
{
Device.Status = DeviceStatus.NotFound;
}
Device.Status = (found) ? DeviceStatus.Available : DeviceStatus.NotFound;
}

public override void Start()
@@ -80,6 +80,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="PCI\VideoCard\GenericVGA.cs" />
<Compile Include="X86System.cs" />
<Compile Include="ISA\ISABus.cs" />
<Compile Include="ISA\CMOS.cs" />
@@ -101,7 +102,6 @@
<ItemGroup>
<Folder Include="PCI\MassStorage\" />
<Folder Include="PCI\Network\" />
<Folder Include="PCI\VideoCard\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
@@ -231,6 +231,10 @@ public override void Initialize()
}

public override void Start()
{
}

public void _Start()
{
videoRamSize = ReadRegister(Register.VRamSize);
maxWidth = ReadRegister(Register.MaxWidth);
Oops, something went wrong.

0 comments on commit 6d96906

Please sign in to comment.
You can’t perform that action at this time.