Code cleanup.

This commit is contained in:
José Pedro 2018-11-08 23:12:05 +00:00
parent 8b7613e2d8
commit e363ce3f3e
No known key found for this signature in database
GPG key ID: B8247B9301707B83
3 changed files with 86 additions and 124 deletions

View file

@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cosmos.Core {
[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=true)]
public sealed class DeviceIDAttribute : Attribute {
public UInt16 VendorID;
public UInt16 DeviceID;
}
}

View file

@ -1,8 +1,9 @@
using System;
using IL2CPU.API.Attribs; using IL2CPU.API.Attribs;
namespace Cosmos.Core { namespace Cosmos.Core
public abstract class IOPortBase { {
public abstract class IOPortBase
{
//TODO Make it that IO port classes are exclusive to each port. For example //TODO Make it that IO port classes are exclusive to each port. For example
// only one IOPort class can be created per port number. This will prevent // only one IOPort class can be created per port number. This will prevent
// two instances of an IOPort from using the same port. // two instances of an IOPort from using the same port.
@ -13,79 +14,83 @@ namespace Cosmos.Core {
// class. Or maybe some base support can be added to this class, but its functionality // class. Or maybe some base support can be added to this class, but its functionality
// is optional and only used by classes that need concurrency control like ATA. // is optional and only used by classes that need concurrency control like ATA.
public readonly UInt16 Port; protected readonly ushort Port;
// all ctors are internal - Only Core ring can create it.. but hardware ring can use it. // all ctors are internal - Only Core ring can create it.. but hardware ring can use it.
protected IOPortBase(UInt16 aPort) { protected IOPortBase(ushort aPort)
{
Port = aPort; Port = aPort;
} }
protected IOPortBase(UInt16 aBase, UInt16 aOffset) { protected IOPortBase(ushort aBase, ushort aOffset)
{
// C# math promotes things to integers, so we have this constructor // C# math promotes things to integers, so we have this constructor
// to relieve the use from having to do so many casts // to relieve the use from having to do so many casts
Port = (UInt16)(aBase + aOffset); Port = (ushort)(aBase + aOffset);
} }
//TODO: Reads and writes can use this to get port instead of argument //TODO: Reads and writes can use this to get port instead of argument
[PlugMethod(PlugRequired = true)] [PlugMethod(PlugRequired = true)]
static protected void Write8(UInt16 aPort, byte aData) { static protected void Write8(ushort aPort, byte aData) => throw null;
} // Plugged
[PlugMethod(PlugRequired = true)] [PlugMethod(PlugRequired = true)]
static protected void Write16(UInt16 aPort, UInt16 aData) { static protected void Write16(ushort aPort, ushort aData) => throw null;
} // Plugged
[PlugMethod(PlugRequired = true)] [PlugMethod(PlugRequired = true)]
static protected void Write32(UInt16 aPort, UInt32 aData) { static protected void Write32(ushort aPort, uint aData) => throw null;
} // Plugged
[PlugMethod(PlugRequired = true)] [PlugMethod(PlugRequired = true)]
static protected byte Read8(UInt16 aPort) { static protected byte Read8(ushort aPort) => throw null;
return 0;
} // Plugged
[PlugMethod(PlugRequired = true)] [PlugMethod(PlugRequired = true)]
static protected UInt16 Read16(UInt16 aPort) { static protected ushort Read16(ushort aPort) => throw null;
return 0;
} // Plugged
[PlugMethod(PlugRequired = true)] [PlugMethod(PlugRequired = true)]
static protected UInt32 Read32(UInt16 aPort) { static protected uint Read32(ushort aPort) => throw null;
return 0;
} // Plugged
//TODO: Plug these Reads with asm to read directly to RAM //TODO: Plug these Reads with asm to read directly to RAM
// REP INSW // REP INSW
public void Read8(byte[] aData) { public void Read8(byte[] aData)
UInt16 xValue; {
for (int i = 0; i < aData.Length / 2; i++) { for (int i = 0; i < aData.Length / 2; i++)
xValue = Read16(Port); {
var xValue = Read16(Port);
aData[i * 2] = (byte)xValue; aData[i * 2] = (byte)xValue;
aData[i * 2 + 1] = (byte)(xValue >> 8); aData[i * 2 + 1] = (byte)(xValue >> 8);
} }
} }
public void Read16(UInt16[] aData) { public void Read16(ushort[] aData)
for (int i = 0; i < aData.Length; i++) { {
for (int i = 0; i < aData.Length; i++)
{
aData[i] = Read16(Port); aData[i] = Read16(Port);
} }
} }
public void Read32(UInt32[] aData) { public void Read32(uint[] aData)
for (int i = 0; i < aData.Length; i++) { {
for (int i = 0; i < aData.Length; i++)
{
aData[i] = Read32(Port); aData[i] = Read32(Port);
} }
} }
} }
public class IOPort : IOPortBase { public class IOPort : IOPortBase
public IOPort(UInt16 aPort) : base(aPort) { {
public IOPort(ushort aPort)
: base(aPort)
{
} }
public IOPort(UInt16 aBase, UInt16 aOffset) : base(aBase, aOffset) { public IOPort(ushort aBase, ushort aOffset)
: base(aBase, aOffset)
{
} }
static public void Wait() { static public void Wait()
{
// Write to an unused port. This assures whatever we were waiting on for a previous // Write to an unused port. This assures whatever we were waiting on for a previous
// IO read/write has completed. // IO read/write has completed.
// Port 0x80 is unused after BIOS POST. // Port 0x80 is unused after BIOS POST.
@ -95,86 +100,70 @@ namespace Cosmos.Core {
Write8(0x80, 0x22); Write8(0x80, 0x22);
} }
public byte Byte { public byte Byte
get { {
return Read8(Port); get => Read8(Port);
} set => Write8(Port, value);
set {
Write8(Port, value);
}
} }
public UInt16 Word { public ushort Word
get { {
return Read16(Port); get => Read16(Port);
} set => Write16(Port, value);
set {
Write16(Port, value);
}
} }
public UInt32 DWord { public uint DWord
get { {
return Read32(Port); get => Read32(Port);
} set => Write32(Port, value);
set {
Write32(Port, value);
}
} }
} }
// I split these instead of adding CanRead/CanWrite because this enforces // I split these instead of adding CanRead/CanWrite because this enforces
// at build time, and its also faster at runtime. Finally it allows future optimizations better // at build time, and its also faster at runtime. Finally it allows future optimizations better
// than checking at runtime. // than checking at runtime.
public class IOPortRead : IOPortBase { public class IOPortRead : IOPortBase
public IOPortRead(UInt16 aPort) : base(aPort) { {
public IOPortRead(ushort aPort)
: base(aPort)
{
} }
public IOPortRead(UInt16 aBase, UInt16 aOffset) : base(aBase, aOffset) { public IOPortRead(ushort aBase, ushort aOffset)
: base(aBase, aOffset)
{
} }
public byte Byte { public byte Byte => Read8(Port);
get {
return Read8(Port);
}
}
public UInt16 Word { public ushort Word => Read16(Port);
get {
return Read16(Port);
}
}
public UInt32 DWord { public uint DWord => Read32(Port);
get {
return Read32(Port);
}
}
} }
public class IOPortWrite : IOPortBase { public class IOPortWrite : IOPortBase
public IOPortWrite(UInt16 aPort) : base(aPort) { {
public IOPortWrite(ushort aPort) : base(aPort)
{
} }
public IOPortWrite(UInt16 aBase, UInt16 aOffset) : base(aBase, aOffset) { public IOPortWrite(ushort aBase, ushort aOffset) : base(aBase, aOffset)
{
} }
public byte Byte { public byte Byte
set { {
Write8(Port, value); set => Write8(Port, value);
}
} }
public UInt16 Word { public ushort Word
set { {
Write16(Port, value); set => Write16(Port, value);
}
} }
public UInt32 DWord { public uint DWord
set { {
Write32(Port, value); set => Write32(Port, value);
}
} }
} }
} }

View file

@ -1,9 +1,9 @@
using System;
using XSharp.Assembler;
using Cosmos.Core; using Cosmos.Core;
using IL2CPU.API;
using IL2CPU.API.Attribs; using IL2CPU.API.Attribs;
using XSharp; using XSharp;
using XSharp.Assembler;
namespace Cosmos.Core_Asm namespace Cosmos.Core_Asm
{ {
@ -27,9 +27,7 @@ namespace Cosmos.Core_Asm
} }
[PlugMethod(Assembler = typeof(Write8Assembler))] [PlugMethod(Assembler = typeof(Write8Assembler))]
public static void Write8(UInt16 aPort, byte aData) public static void Write8(ushort aPort, byte aData) => throw null;
{
}
#endregion #endregion
@ -46,9 +44,7 @@ namespace Cosmos.Core_Asm
} }
[PlugMethod(Assembler = typeof(Write16Assembler))] [PlugMethod(Assembler = typeof(Write16Assembler))]
public static void Write16(UInt16 aPort, UInt16 aData) public static void Write16(ushort aPort, ushort aData) => throw null;
{
}
#endregion #endregion
@ -65,9 +61,7 @@ namespace Cosmos.Core_Asm
} }
[PlugMethod(Assembler = typeof(Write32Assembler))] [PlugMethod(Assembler = typeof(Write32Assembler))]
public static void Write32(UInt16 aPort, UInt32 aData) public static void Write32(ushort aPort, uint aData) => throw null;
{
}
#endregion #endregion
@ -87,10 +81,7 @@ namespace Cosmos.Core_Asm
} }
[PlugMethod(Assembler = typeof(Read8Assembler))] [PlugMethod(Assembler = typeof(Read8Assembler))]
public static byte Read8(UInt16 aPort) public static byte Read8(ushort aPort) => throw null;
{
return 0;
}
#endregion #endregion
@ -108,10 +99,7 @@ namespace Cosmos.Core_Asm
} }
[PlugMethod(Assembler = typeof(Read16Assembler))] [PlugMethod(Assembler = typeof(Read16Assembler))]
public static UInt16 Read16(UInt16 aPort) public static ushort Read16(ushort aPort) => throw null;
{
return 0;
}
#endregion #endregion
@ -128,10 +116,7 @@ namespace Cosmos.Core_Asm
} }
[PlugMethod(Assembler = typeof(Read32Assembler))] [PlugMethod(Assembler = typeof(Read32Assembler))]
public static UInt32 Read32(UInt16 aPort) public static uint Read32(ushort aPort) => throw null;
{
return 0;
}
#endregion #endregion