From 994f623b0efb8a23b3b2a61bd8d96b9c2f30fe19 Mon Sep 17 00:00:00 2001 From: AnErrupTion Date: Sat, 9 Mar 2024 11:04:51 +0100 Subject: [PATCH] Mosa.DeviceDriver: clean up pointless types + other minor changes Signed-off-by: AnErrupTion --- LICENSE.txt | 2 +- Source/Directory.Build.props | 4 +- Source/Docs/conf.py | 2 +- .../PCI/GenericHostBridgeController.cs | 45 ------------- .../Mosa.DeviceDriver/PCI/Intel/Intel440FX.cs | 4 +- Source/Mosa.DeviceDriver/Setup.cs | 14 +---- Source/Mosa.DeviceDriver/X86System.cs | 38 ----------- Source/Mosa.DeviceSystem/Misc/DataBlock.cs | 6 -- .../PCI/IHostBridgeController.cs | 13 ---- Source/Mosa.Kernel.BareMetal/Startup.cs | 5 +- .../Mosa.Korlib/System.Text/StringBuilder.cs | 63 +++++++++++++------ Source/Mosa.Korlib/System/Char.cs | 2 + Source/Mosa.Korlib/System/String.cs | 30 ++++++++- Source/Mosa.Packages/Mosa.DeviceSystem.nuspec | 2 +- Source/Mosa.Packages/Mosa.Platform.nuspec | 2 +- Source/Mosa.Packages/Mosa.Platform.x86.nuspec | 2 +- .../Mosa.Tools.Package.Qemu.nuspec | 2 +- .../Mosa.Packages/Mosa.Tools.Package.nuspec | 2 +- Source/Mosa.Tool.Compiler/Compiler.cs | 2 +- Source/Mosa.Tool.Launcher.Console/Program.cs | 2 +- 20 files changed, 94 insertions(+), 148 deletions(-) delete mode 100644 Source/Mosa.DeviceDriver/PCI/GenericHostBridgeController.cs delete mode 100644 Source/Mosa.DeviceDriver/X86System.cs delete mode 100644 Source/Mosa.DeviceSystem/PCI/IHostBridgeController.cs diff --git a/LICENSE.txt b/LICENSE.txt index 8baa529966..eaefc4771d 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2023, MOSA-Project +Copyright (c) 2024, MOSA-Project All rights reserved. Redistribution and use in source and binary forms, diff --git a/Source/Directory.Build.props b/Source/Directory.Build.props index 54a8b0a3b0..a889854b3a 100644 --- a/Source/Directory.Build.props +++ b/Source/Directory.Build.props @@ -12,7 +12,7 @@ false ../Common.ruleset MOSA Project - Copyright © MOSA Project 2023 - 2.5.0.0 + Copyright © MOSA Project 2024 + 2.6.0.0 diff --git a/Source/Docs/conf.py b/Source/Docs/conf.py index d7d11b4959..b718722d27 100644 --- a/Source/Docs/conf.py +++ b/Source/Docs/conf.py @@ -16,7 +16,7 @@ # -- Project information ----------------------------------------------------- project = 'MOSA Project' -copyright = '2008-{}, Mosa Project & contributors'.format(2023) +copyright = '2008-{}, Mosa Project & contributors'.format(2024) author = 'Phil Garcia' # -- General configuration --------------------------------------------------- diff --git a/Source/Mosa.DeviceDriver/PCI/GenericHostBridgeController.cs b/Source/Mosa.DeviceDriver/PCI/GenericHostBridgeController.cs deleted file mode 100644 index c941919fd0..0000000000 --- a/Source/Mosa.DeviceDriver/PCI/GenericHostBridgeController.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) MOSA Project. Licensed under the New BSD License. - -using Mosa.DeviceSystem.Framework; -using Mosa.DeviceSystem.PCI; - -namespace Mosa.DeviceDriver.PCI; - -/// -/// Generic PCI Host Bridge Controller -/// -//[PCIDeviceDriver(ClassCode = 0x06, SubClassCode = 0x00, Platforms = PlatformArchitecture.X86AndX64)] -public class GenericHostBridgeController : BaseDeviceDriver, IHostBridgeController -{ - private byte resetAddress; - private byte resetValue; - - public override void Initialize() => Device.Name = "GenericHostBridgeController"; - - public override void Probe() => Device.Status = DeviceStatus.Available; - - public override void Start() => Device.Status = DeviceStatus.Online; - - public override void Stop() => Device.Status = DeviceStatus.Offline; - - // TODO: Fix - public bool CPUReset() - { - var pciDevice = (PCIDevice)Device.Parent.DeviceDriver; - var pciController = (IPCIControllerLegacy)Device.Parent.Parent.DeviceDriver; - - pciController.WriteConfig8(pciDevice.Bus, - (byte)((resetAddress >> 32) & 0xFFFF), - (byte)((resetAddress >> 16) & 0xFFFF), - (byte)(resetAddress & 0xFFFF), - resetValue); - - return false; - } - - public void SetCPUResetInformation(byte address, byte value) - { - resetAddress = address; - resetValue = value; - } -} diff --git a/Source/Mosa.DeviceDriver/PCI/Intel/Intel440FX.cs b/Source/Mosa.DeviceDriver/PCI/Intel/Intel440FX.cs index 46b7e87007..d83875da60 100644 --- a/Source/Mosa.DeviceDriver/PCI/Intel/Intel440FX.cs +++ b/Source/Mosa.DeviceDriver/PCI/Intel/Intel440FX.cs @@ -1,5 +1,7 @@ // Copyright (c) MOSA Project. Licensed under the New BSD License. +using Mosa.DeviceSystem.Framework; + namespace Mosa.DeviceDriver.PCI.Intel; // Intel® 440FX PCIset 82441FX (PMC) and 82442FX (DBX) @@ -8,7 +10,7 @@ namespace Mosa.DeviceDriver.PCI.Intel; /// /// //[PCIDeviceDriver(VendorID = 0x8086, DeviceID = 0x1237, Platforms = PlatformArchitecture.X86AndX64)] -public class Intel440FX : GenericHostBridgeController +public class Intel440FX : BaseDeviceDriver { public override void Initialize() => Device.Name = "Intel440FX"; } diff --git a/Source/Mosa.DeviceDriver/Setup.cs b/Source/Mosa.DeviceDriver/Setup.cs index 4461fd4224..19db8ef59b 100644 --- a/Source/Mosa.DeviceDriver/Setup.cs +++ b/Source/Mosa.DeviceDriver/Setup.cs @@ -56,17 +56,6 @@ public static class Setup Factory = () => new ISA.PCIController() }, - new PCIDeviceDriverRegistryEntry - { - Name = "PCIGenericHostBridge", - Platform = PlatformArchitecture.X86AndX64, - BusType = DeviceBusType.PCI, - ClassCode = 0x06, - SubClassCode = 0x00, - PCIFields = PCIField.ClassCode | PCIField.SubClassCode, - Factory = () => new PCI.GenericHostBridgeController() - }, - new ISADeviceDriverRegistryEntry { Name = "IDEController", @@ -92,6 +81,7 @@ public static class Setup Factory = () => new ISA.IDEController() }, + // Future: Clarify how these 4-series controllers are differentiated in PCI (right now most are pointing to the same device?) new PCIDeviceDriverRegistryEntry { Name = "Intel4SeriesChipsetDRAMController", @@ -120,7 +110,7 @@ public static class Setup Platform = PlatformArchitecture.X86AndX64, BusType = DeviceBusType.PCI, VendorID = 0x8086, - DeviceID = 0x2E10, + DeviceID = 0x2E13, PCIFields = PCIField.VendorID | PCIField.DeviceID, Factory = () => new PCI.Intel.Intel4SeriesChipsetIntegratedGraphicsController2E13() }, diff --git a/Source/Mosa.DeviceDriver/X86System.cs b/Source/Mosa.DeviceDriver/X86System.cs deleted file mode 100644 index 91084a2147..0000000000 --- a/Source/Mosa.DeviceDriver/X86System.cs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) MOSA Project. Licensed under the New BSD License. - -using Mosa.DeviceDriver.ISA; -using Mosa.DeviceSystem.Framework; -using Mosa.DeviceSystem.HardwareAbstraction; - -namespace Mosa.DeviceDriver; - -/// -/// X86 System -/// -public class X86System : BaseDeviceDriver -{ - public override void Initialize() => Device.Name = "X86System"; - - public override void Probe() => Device.Status = DeviceStatus.Available; - - public override void Start() - { - HAL.DebugWriteLine("X86System:Start()"); - - CreateISABusDevices(); - Device.Status = DeviceStatus.Online; - - HAL.DebugWriteLine("X86System:Start() [Exit]"); - } - - public override bool OnInterrupt() => true; - - private void CreateISABusDevices() - { - HAL.DebugWriteLine("X86System:CreateISABusDevices()"); - - DeviceService.Initialize(new ISABus(), Device, true, null, null, null); - - HAL.DebugWriteLine("X86System:CreateISABusDevices() [Exit]"); - } -} diff --git a/Source/Mosa.DeviceSystem/Misc/DataBlock.cs b/Source/Mosa.DeviceSystem/Misc/DataBlock.cs index 94e463cea6..36ea8bbbde 100644 --- a/Source/Mosa.DeviceSystem/Misc/DataBlock.cs +++ b/Source/Mosa.DeviceSystem/Misc/DataBlock.cs @@ -18,12 +18,6 @@ public class DataBlock public DataBlock(uint length) => Data = new byte[length]; - public byte this[int index] - { - get => Data[index]; - set => Data[index] = value; - } - public char GetChar(uint offset) => (char)Data[offset]; public void SetChar(uint offset, char value) => Data[offset] = (byte)value; diff --git a/Source/Mosa.DeviceSystem/PCI/IHostBridgeController.cs b/Source/Mosa.DeviceSystem/PCI/IHostBridgeController.cs deleted file mode 100644 index 246431575c..0000000000 --- a/Source/Mosa.DeviceSystem/PCI/IHostBridgeController.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) MOSA Project. Licensed under the New BSD License. - -namespace Mosa.DeviceSystem.PCI; - -/// -/// PCI Host Bridge interface -/// -public interface IHostBridgeController -{ - bool CPUReset(); - - void SetCPUResetInformation(byte address, byte value); -} diff --git a/Source/Mosa.Kernel.BareMetal/Startup.cs b/Source/Mosa.Kernel.BareMetal/Startup.cs index 7d34c17902..7b2c43d66c 100644 --- a/Source/Mosa.Kernel.BareMetal/Startup.cs +++ b/Source/Mosa.Kernel.BareMetal/Startup.cs @@ -192,9 +192,10 @@ public static void EntryPoint() Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine(" [Completed]"); + // Future: We shouldn't be directly initializing ISA devices on non-x86 platforms (even if it doesn't do anything on those) Console.ForegroundColor = ConsoleColor.LightGreen; - Console.Write("> X86System..."); - deviceService.Initialize(new X86System(), null); + Console.Write("> ISABus..."); + deviceService.Initialize(new ISABus(), null); Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine(" [Completed]"); diff --git a/Source/Mosa.Korlib/System.Text/StringBuilder.cs b/Source/Mosa.Korlib/System.Text/StringBuilder.cs index a8fe2f7617..0d15e2f4df 100644 --- a/Source/Mosa.Korlib/System.Text/StringBuilder.cs +++ b/Source/Mosa.Korlib/System.Text/StringBuilder.cs @@ -4,47 +4,72 @@ namespace System.Text; public class StringBuilder { - private char[] Characters = new char[int.MaxValue]; + private char[] characters; + private int length; - private int Length = 0; + public StringBuilder() => characters = new char[byte.MaxValue]; + + public StringBuilder(int capacity) => characters = new char[capacity]; public StringBuilder Clear() { - Length = 0; + length = 0; return this; } public StringBuilder Append(char c) { - if (Length >= Characters.Length) - { - var chars = new char[Length + 100]; - for (var i = 0; i < Length; i++) - chars[i] = Characters[i]; - Characters = chars; - } + EnsureCapacity(); + + characters[length++] = c; + return this; + } + + public StringBuilder Append(char c, int count) + { + EnsureCapacity(count); - Characters[Length] = c; - Length++; + for (var i = 0; i < count; i++) + characters[length++] = c; return this; } - public StringBuilder AppendLine(string s) + public StringBuilder Append(string s) { - for (var i = 0; i < s.length; i++) - Append(s[i]); + EnsureCapacity(s.length); + + foreach (var c in s) + characters[length++] = c; return this; } - public char[] ToCharArray() + public StringBuilder AppendLine(string s) { - return Characters; + EnsureCapacity(s.length); + + foreach (var c in s) + characters[length++] = c; + + characters[length++] = '\n'; + return this; } - public override string ToString() + public char[] ToCharArray() => characters; + + public override string ToString() => new string(characters, 0, length); + + private void EnsureCapacity(int capacity = 0) { - return new string(Characters, 0, Length); + var newLength = length + capacity; + if (newLength < characters.Length) + return; + + var chars = new char[newLength + 100]; + for (var i = 0; i < length; i++) + chars[i] = characters[i]; + + characters = chars; } } diff --git a/Source/Mosa.Korlib/System/Char.cs b/Source/Mosa.Korlib/System/Char.cs index 767847784b..91bc8bf729 100644 --- a/Source/Mosa.Korlib/System/Char.cs +++ b/Source/Mosa.Korlib/System/Char.cs @@ -137,6 +137,8 @@ public static bool IsDigit(char c) return c >= '0' && c <= '9'; } + public static bool IsAsciiDigit(char c) => IsDigit(c); + public static bool IsLetterOrDigit(char c) { return (IsLetter(c) || IsDigit(c)); diff --git a/Source/Mosa.Korlib/System/String.cs b/Source/Mosa.Korlib/System/String.cs index 87841e0765..0c1ffb55eb 100644 --- a/Source/Mosa.Korlib/System/String.cs +++ b/Source/Mosa.Korlib/System/String.cs @@ -331,7 +331,35 @@ public string Remove(int startIndex, int count) public static string Format(string format, params object[] args) { - return format; + var sb = new StringBuilder(format.length + args.Length * 8); + var index = 0; + + while (index < format.length) + { + var c = format[index++]; + + if (c != '{') + { + sb.Append(c); + continue; + } + + var argIndexStr = Empty; + var current = format[index++]; + + while (current != '}') + { + argIndexStr += current; + current = format[index++]; + } + + var argIndex = int.Parse(argIndexStr); + var arg = args[argIndex]; + + sb.Append(arg.ToString()); + } + + return sb.ToString(); } public bool Equals(string s) diff --git a/Source/Mosa.Packages/Mosa.DeviceSystem.nuspec b/Source/Mosa.Packages/Mosa.DeviceSystem.nuspec index 1b868ec553..4b8b27ecb5 100644 --- a/Source/Mosa.Packages/Mosa.DeviceSystem.nuspec +++ b/Source/Mosa.Packages/Mosa.DeviceSystem.nuspec @@ -12,7 +12,7 @@ false MOSA device drivers framework and file system This package contains the MOSA device drivers framework along with the VFS (Virtual File System) and the file systems implementations. - Copyright © MOSA Project 2023 + Copyright © MOSA Project 2024 MOSA Compiler diff --git a/Source/Mosa.Packages/Mosa.Platform.nuspec b/Source/Mosa.Packages/Mosa.Platform.nuspec index cfa62dec6e..d5caee14ad 100644 --- a/Source/Mosa.Packages/Mosa.Platform.nuspec +++ b/Source/Mosa.Packages/Mosa.Platform.nuspec @@ -12,7 +12,7 @@ false MOSA BareMetal kernel and runtime libraries This package contains the platform-agnostic BareMetal kernel and runtime libraries (including the core library). - Copyright © MOSA Project 2023 + Copyright © MOSA Project 2024 MOSA Compiler diff --git a/Source/Mosa.Packages/Mosa.Platform.x86.nuspec b/Source/Mosa.Packages/Mosa.Platform.x86.nuspec index 0425eb113a..1336f1e0fc 100644 --- a/Source/Mosa.Packages/Mosa.Platform.x86.nuspec +++ b/Source/Mosa.Packages/Mosa.Platform.x86.nuspec @@ -12,7 +12,7 @@ false MOSA x86 platform libraries This package contains the x86 implementations of the BareMetal kernel and runtime libraries (including the core library). - Copyright © MOSA Project 2023 + Copyright © MOSA Project 2024 MOSA Compiler diff --git a/Source/Mosa.Packages/Mosa.Tools.Package.Qemu.nuspec b/Source/Mosa.Packages/Mosa.Tools.Package.Qemu.nuspec index b9fee03ca3..7b8a0df42f 100644 --- a/Source/Mosa.Packages/Mosa.Tools.Package.Qemu.nuspec +++ b/Source/Mosa.Packages/Mosa.Tools.Package.Qemu.nuspec @@ -12,7 +12,7 @@ false MOSA tools with QEMU for Windows This package contains all the tools for MOSA along with QEMU binaries for Windows. - Copyright © MOSA Project 2023 + Copyright © MOSA Project 2024 MOSA Compiler diff --git a/Source/Mosa.Packages/Mosa.Tools.Package.nuspec b/Source/Mosa.Packages/Mosa.Tools.Package.nuspec index bae98cb6ff..571982e6f5 100644 --- a/Source/Mosa.Packages/Mosa.Tools.Package.nuspec +++ b/Source/Mosa.Packages/Mosa.Tools.Package.nuspec @@ -12,7 +12,7 @@ false MOSA Tools without QEMU This package contains all the tools for MOSA without QEMU binaries. - Copyright © MOSA Project 2023 + Copyright © MOSA Project 2024 MOSA Compiler diff --git a/Source/Mosa.Tool.Compiler/Compiler.cs b/Source/Mosa.Tool.Compiler/Compiler.cs index 74d90dcc26..c59a272ea8 100644 --- a/Source/Mosa.Tool.Compiler/Compiler.cs +++ b/Source/Mosa.Tool.Compiler/Compiler.cs @@ -30,7 +30,7 @@ public int Run(string[] args) // always print header with version information Console.WriteLine("MOSA Compiler, Version {0}.", CompilerVersion.VersionString); - Console.WriteLine("Copyright 2023 by the MOSA Project. Licensed under the New BSD License."); + Console.WriteLine("Copyright 2024 by the MOSA Project. Licensed under the New BSD License."); //OutputStatus($"Current Directory: {Environment.CurrentDirectory}"); diff --git a/Source/Mosa.Tool.Launcher.Console/Program.cs b/Source/Mosa.Tool.Launcher.Console/Program.cs index 72d74dac5a..9fa5de2a18 100644 --- a/Source/Mosa.Tool.Launcher.Console/Program.cs +++ b/Source/Mosa.Tool.Launcher.Console/Program.cs @@ -18,7 +18,7 @@ internal static int Main(string[] args) RegisterPlatforms(); System.Console.WriteLine("MOSA Launcher, Version {0}.", CompilerVersion.VersionString); - System.Console.WriteLine("Copyright 2023 by the MOSA Project. Licensed under the New BSD License."); + System.Console.WriteLine("Copyright 2024 by the MOSA Project. Licensed under the New BSD License."); //OutputStatus($"Current Directory: {Environment.CurrentDirectory}");