From fba8c7c8276a7bb9aefd17587d79ea06f4d1895a Mon Sep 17 00:00:00 2001 From: gero_cp Date: Mon, 24 Aug 2009 17:42:45 +0000 Subject: [PATCH] Made extra files for classes --- source/Cosmos/Cosmos.Kernel/AddressSpace.cs | 248 ++---------------- .../Cosmos/Cosmos.Kernel/Cosmos.Kernel.csproj | 4 +- source/Cosmos/Cosmos.Kernel/IOAddressSpace.cs | 97 +++++++ .../Cosmos.Kernel/MemoryAddressSpace.cs | 124 +++++++++ 4 files changed, 248 insertions(+), 225 deletions(-) create mode 100644 source/Cosmos/Cosmos.Kernel/IOAddressSpace.cs create mode 100644 source/Cosmos/Cosmos.Kernel/MemoryAddressSpace.cs diff --git a/source/Cosmos/Cosmos.Kernel/AddressSpace.cs b/source/Cosmos/Cosmos.Kernel/AddressSpace.cs index e347fcc7a..ba9af09f7 100644 --- a/source/Cosmos/Cosmos.Kernel/AddressSpace.cs +++ b/source/Cosmos/Cosmos.Kernel/AddressSpace.cs @@ -2,13 +2,17 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.IO; -namespace Cosmos.Kernel { - public abstract class AddressSpace { +namespace Cosmos.Kernel +{ + public abstract class AddressSpace + { public UInt32 Offset; public UInt32 Size; - public AddressSpace(UInt32 offset, UInt32 size) { + public AddressSpace( UInt32 offset, UInt32 size ) + { Offset = offset; Size = size; } @@ -18,21 +22,21 @@ namespace Cosmos.Kernel { /// /// The offset to read from /// 8 bits of data read - public abstract byte Read8(UInt32 offset); - + public abstract byte Read8( UInt32 offset ); + /// /// Reads 16 bits from a given offset if it within the valid range /// /// The offset to read from /// 16 bits of data read - public abstract UInt16 Read16(UInt32 offset); - + public abstract UInt16 Read16( UInt32 offset ); + /// /// Reads 32 bits from a given offset if it within the valid range /// /// The offset to read from /// 32 bits of data read - public abstract UInt32 Read32(UInt32 offset); + public abstract UInt32 Read32( UInt32 offset ); /// /// Reads 64 bits from a given offset if it within the valid range @@ -46,21 +50,21 @@ namespace Cosmos.Kernel { /// /// The offset to read from /// 8 bits of data read - public abstract byte Read8Unchecked(UInt32 offset); + public abstract byte Read8Unchecked( UInt32 offset ); /// /// Reads 16 bits from a given offset. The offset is not checked. Use with caution /// /// The offset to read from /// 16 bits of data read - public abstract UInt16 Read16Unchecked(UInt32 offset); + public abstract UInt16 Read16Unchecked( UInt32 offset ); /// /// Reads 32 bits from a given offset. The offset is not checked. Use with caution /// /// The offset to read from /// 32 bits of data read - public abstract UInt32 Read32Unchecked(UInt32 offset); + public abstract UInt32 Read32Unchecked( UInt32 offset ); /// /// Reads 64 bits from a given offset. The offset is not checked. Use with caution @@ -74,21 +78,21 @@ namespace Cosmos.Kernel { /// /// The offset to write to /// The data to write - public abstract void Write8(UInt32 offset, byte value); + public abstract void Write8( UInt32 offset, byte value ); /// /// Writes 16 bits from a given offset if it is within the valid range. /// /// The offset to write to /// The data to write - public abstract void Write16(UInt32 offset, UInt16 value); + public abstract void Write16( UInt32 offset, UInt16 value ); /// /// Writes 32 bits from a given offset if it is within the valid range. /// /// The offset to write to /// The data to write - public abstract void Write32(UInt32 offset, UInt32 value); + public abstract void Write32( UInt32 offset, UInt32 value ); /// /// Writes 64 bits from a given offset if it is within the valid range. @@ -102,231 +106,27 @@ namespace Cosmos.Kernel { /// /// The offset to write to /// The data to write - public abstract void Write8Unchecked(UInt32 offset, byte value); - + public abstract void Write8Unchecked( UInt32 offset, byte value ); + /// /// Writes 16 bits from a given offset. The offset is not checked. Use with caution. /// /// The offset to write to /// The data to write - public abstract void Write16Unchecked(UInt32 offset, UInt16 value); - + public abstract void Write16Unchecked( UInt32 offset, UInt16 value ); + /// /// Writes 32 bits from a given offset. The offset is not checked. Use with caution. /// /// The offset to write to /// The data to write - public abstract void Write32Unchecked(UInt32 offset, UInt32 value); + public abstract void Write32Unchecked( UInt32 offset, UInt32 value ); /// /// Writes 64 bits from a given offset. The offset is not checked. Use with caution. /// /// The offset to write to /// The data to write - public abstract void Write64Unchecked( UInt32 offset, UInt64 value ); - } - - public unsafe class MemoryAddressSpace : AddressSpace - { - public MemoryAddressSpace(UInt32 offset, UInt32 size) : base(offset, size) - { } - - public override byte Read8(UInt32 offset) - { - if (offset > Size) - throw new ArgumentOutOfRangeException("offset"); - return *(byte*)(this.Offset + offset); - } - public override UInt16 Read16(UInt32 offset) - { - if (offset < 0 || offset > Size) - throw new ArgumentOutOfRangeException("offset"); - return *(UInt16*)(this.Offset + offset); - } - public override UInt32 Read32(UInt32 offset) - { - if (offset < 0 || offset > Size) - throw new ArgumentOutOfRangeException("offset"); - return *(UInt32*)(this.Offset + offset); - } - - public override UInt64 Read64( UInt32 offset ) - { - if( offset < 0 || offset > Size ) - throw new ArgumentOutOfRangeException( "offset" ); - return *( UInt64* )( this.Offset + offset ); - } - - public override byte Read8Unchecked(UInt32 offset) - { - return *(byte*)(this.Offset + offset); - } - public override UInt16 Read16Unchecked(UInt32 offset) - { - return *(UInt16*)(this.Offset + offset); - } - public override UInt32 Read32Unchecked(UInt32 offset) - { - return *(UInt32*)(this.Offset + offset); - } - - public override UInt64 Read64Unchecked( UInt32 offset ) - { - return *( UInt64* )( this.Offset + offset ); - } - - public override void Write8(UInt32 offset, byte value) - { - if (offset < 0 || offset > Size) - throw new ArgumentOutOfRangeException("offset"); - (*(byte*)(this.Offset + offset)) = value; - } - public override void Write16(UInt32 offset, UInt16 value) - { - if (offset < 0 || offset > Size) - throw new ArgumentOutOfRangeException("offset"); - (*(UInt16*)(this.Offset + offset)) = value; - } - public override void Write32(UInt32 offset, UInt32 value) - { - if (offset < 0 || offset > Size) - throw new ArgumentOutOfRangeException("offset"); - (*(UInt32*)(this.Offset + offset)) = value; - } - public override void Write64( UInt32 offset, UInt64 value ) - { - if( offset < 0 || offset > Size ) - throw new ArgumentOutOfRangeException( "offset" ); - ( *( UInt64* )( this.Offset + offset ) ) = value; - } - public override void Write8Unchecked(UInt32 offset, byte value) - { - (*(byte*)(this.Offset + offset)) = value; - } - public override void Write16Unchecked(UInt32 offset, UInt16 value) - { - (*(UInt16*)(this.Offset + offset)) = value; - } - public override void Write32Unchecked(UInt32 offset, UInt32 value) - { - (*(UInt32*)(this.Offset + offset)) = value; - } - public override void Write64Unchecked(UInt32 offset, UInt64 value) - { - (*(UInt64*)(this.Offset + offset)) = value; - } - - public void CopyFrom(MemoryAddressSpace src) - { - for (uint x = 0; x < src.Size; x++) - { - (*(byte*)(this.Offset + x)) = *(byte*)(src.Offset + x); - } - } - - public void CopyFrom(MemoryAddressSpace src, uint srcOffset, uint dstOffset, uint bytes) - { - for (uint x = 0; x < bytes; x++) - { - (*(byte*)(this.Offset + dstOffset + x)) = *(byte*)(src.Offset + srcOffset + x); - } - } - - public void SetMem(byte data) - { - for (uint x = 0; x < this.Size; x++) - { - (*(byte*)(this.Offset + x)) = data; - } - } - } - - public class IOAddressSpace : AddressSpace - { - public IOAddressSpace(UInt32 offset, UInt32 size) - : base(offset, size) - { - if (offset > 0xffff || offset + size > 0xffff) - throw new ArgumentOutOfRangeException("offset or size"); - } - - public override byte Read8(UInt32 offset) - { - if (offset < 0 || offset > Size) - throw new ArgumentOutOfRangeException("offset"); - return Kernel.CPUBus.Read8((UInt16)(this.Offset + offset)); - } - public override UInt16 Read16(UInt32 offset) - { - if (offset < 0 || offset > Size) - throw new ArgumentOutOfRangeException("offset"); - return Kernel.CPUBus.Read16((UInt16)(this.Offset + offset)); - } - public override UInt32 Read32(UInt32 offset) - { - if (offset < 0 || offset > Size) - throw new ArgumentOutOfRangeException("offset"); - return Kernel.CPUBus.Read32((UInt16)(this.Offset + offset)); - } - public override UInt64 Read64( UInt32 offset ) - { - throw new NotImplementedException(); - } - - public override byte Read8Unchecked(UInt32 offset) - { - return Kernel.CPUBus.Read8((UInt16)(this.Offset + offset)); - } - public override UInt16 Read16Unchecked(UInt32 offset) - { - return Kernel.CPUBus.Read16((UInt16)(this.Offset + offset)); - } - public override UInt32 Read32Unchecked(UInt32 offset) - { - return Kernel.CPUBus.Read32((UInt16)(this.Offset + offset)); - } - public override UInt64 Read64Unchecked( UInt32 offset ) - { - throw new NotImplementedException(); - } - - public override void Write8(UInt32 offset, byte value) - { - if (offset < 0 || offset > Size) - throw new ArgumentOutOfRangeException("offset"); - Kernel.CPUBus.Write8((UInt16)(this.Offset + offset), value); - } - public override void Write16(UInt32 offset, UInt16 value) - { - if (offset < 0 || offset > Size) - throw new ArgumentOutOfRangeException("offset"); - Kernel.CPUBus.Write16((UInt16)(this.Offset + offset), value); - } - public override void Write32(UInt32 offset, UInt32 value) - { - if (offset < 0 || offset > Size) - throw new ArgumentOutOfRangeException("offset"); - Kernel.CPUBus.Write32((UInt16)(this.Offset + offset), value); - } - public override void Write64( UInt32 offset, UInt64 value ) - { - throw new NotImplementedException(); - } - public override void Write8Unchecked(UInt32 offset, byte value) - { - Kernel.CPUBus.Write8((UInt16)(this.Offset + offset), value); - } - public override void Write16Unchecked(UInt32 offset, UInt16 value) - { - Kernel.CPUBus.Write16((UInt16)(this.Offset + offset), value); - } - public override void Write32Unchecked(UInt32 offset, UInt32 value) - { - Kernel.CPUBus.Write32((UInt16)(this.Offset + offset), value); - } - public override void Write64Unchecked( UInt32 offset, UInt64 value ) - { - throw new NotImplementedException(); - } + public abstract void Write64Unchecked( UInt32 offset, UInt64 value ); } } diff --git a/source/Cosmos/Cosmos.Kernel/Cosmos.Kernel.csproj b/source/Cosmos/Cosmos.Kernel/Cosmos.Kernel.csproj index c81ae5be1..f35221f0b 100644 --- a/source/Cosmos/Cosmos.Kernel/Cosmos.Kernel.csproj +++ b/source/Cosmos/Cosmos.Kernel/Cosmos.Kernel.csproj @@ -3,7 +3,7 @@ Debug AnyCPU - 9.0.21022 + 9.0.30729 2.0 {A1F83D9F-2D44-4264-A08B-416797123018} Library @@ -51,6 +51,8 @@ + + diff --git a/source/Cosmos/Cosmos.Kernel/IOAddressSpace.cs b/source/Cosmos/Cosmos.Kernel/IOAddressSpace.cs new file mode 100644 index 000000000..69be676c4 --- /dev/null +++ b/source/Cosmos/Cosmos.Kernel/IOAddressSpace.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; + +namespace Cosmos.Kernel +{ + public class IOAddressSpace : AddressSpace + { + public IOAddressSpace( UInt32 offset, UInt32 size ) + : base( offset, size ) + { + if( offset > 0xffff || offset + size > 0xffff ) + throw new ArgumentOutOfRangeException( "offset or size" ); + } + + public override byte Read8( UInt32 offset ) + { + if( offset < 0 || offset > Size ) + throw new ArgumentOutOfRangeException( "offset" ); + return Kernel.CPUBus.Read8( ( UInt16 )( this.Offset + offset ) ); + } + public override UInt16 Read16( UInt32 offset ) + { + if( offset < 0 || offset > Size ) + throw new ArgumentOutOfRangeException( "offset" ); + return Kernel.CPUBus.Read16( ( UInt16 )( this.Offset + offset ) ); + } + public override UInt32 Read32( UInt32 offset ) + { + if( offset < 0 || offset > Size ) + throw new ArgumentOutOfRangeException( "offset" ); + return Kernel.CPUBus.Read32( ( UInt16 )( this.Offset + offset ) ); + } + public override UInt64 Read64( UInt32 offset ) + { + throw new NotImplementedException(); + } + + public override byte Read8Unchecked( UInt32 offset ) + { + return Kernel.CPUBus.Read8( ( UInt16 )( this.Offset + offset ) ); + } + public override UInt16 Read16Unchecked( UInt32 offset ) + { + return Kernel.CPUBus.Read16( ( UInt16 )( this.Offset + offset ) ); + } + public override UInt32 Read32Unchecked( UInt32 offset ) + { + return Kernel.CPUBus.Read32( ( UInt16 )( this.Offset + offset ) ); + } + public override UInt64 Read64Unchecked( UInt32 offset ) + { + throw new NotImplementedException(); + } + + public override void Write8( UInt32 offset, byte value ) + { + if( offset < 0 || offset > Size ) + throw new ArgumentOutOfRangeException( "offset" ); + Kernel.CPUBus.Write8( ( UInt16 )( this.Offset + offset ), value ); + } + public override void Write16( UInt32 offset, UInt16 value ) + { + if( offset < 0 || offset > Size ) + throw new ArgumentOutOfRangeException( "offset" ); + Kernel.CPUBus.Write16( ( UInt16 )( this.Offset + offset ), value ); + } + public override void Write32( UInt32 offset, UInt32 value ) + { + if( offset < 0 || offset > Size ) + throw new ArgumentOutOfRangeException( "offset" ); + Kernel.CPUBus.Write32( ( UInt16 )( this.Offset + offset ), value ); + } + public override void Write64( UInt32 offset, UInt64 value ) + { + throw new NotImplementedException(); + } + public override void Write8Unchecked( UInt32 offset, byte value ) + { + Kernel.CPUBus.Write8( ( UInt16 )( this.Offset + offset ), value ); + } + public override void Write16Unchecked( UInt32 offset, UInt16 value ) + { + Kernel.CPUBus.Write16( ( UInt16 )( this.Offset + offset ), value ); + } + public override void Write32Unchecked( UInt32 offset, UInt32 value ) + { + Kernel.CPUBus.Write32( ( UInt16 )( this.Offset + offset ), value ); + } + public override void Write64Unchecked( UInt32 offset, UInt64 value ) + { + throw new NotImplementedException(); + } + } +} diff --git a/source/Cosmos/Cosmos.Kernel/MemoryAddressSpace.cs b/source/Cosmos/Cosmos.Kernel/MemoryAddressSpace.cs new file mode 100644 index 000000000..9f806a4d8 --- /dev/null +++ b/source/Cosmos/Cosmos.Kernel/MemoryAddressSpace.cs @@ -0,0 +1,124 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; + +namespace Cosmos.Kernel +{ + public unsafe class MemoryAddressSpace : AddressSpace + { + public MemoryAddressSpace( UInt32 offset, UInt32 size ) + : base( offset, size ) + { } + + public override byte Read8( UInt32 offset ) + { + if( offset > Size ) + throw new ArgumentOutOfRangeException( "offset" ); + return *( byte* )( this.Offset + offset ); + } + public override UInt16 Read16( UInt32 offset ) + { + if( offset < 0 || offset > Size ) + throw new ArgumentOutOfRangeException( "offset" ); + return *( UInt16* )( this.Offset + offset ); + } + public override UInt32 Read32( UInt32 offset ) + { + if( offset < 0 || offset > Size ) + throw new ArgumentOutOfRangeException( "offset" ); + return *( UInt32* )( this.Offset + offset ); + } + + public override UInt64 Read64( UInt32 offset ) + { + if( offset < 0 || offset > Size ) + throw new ArgumentOutOfRangeException( "offset" ); + return *( UInt64* )( this.Offset + offset ); + } + + public override byte Read8Unchecked( UInt32 offset ) + { + return *( byte* )( this.Offset + offset ); + } + public override UInt16 Read16Unchecked( UInt32 offset ) + { + return *( UInt16* )( this.Offset + offset ); + } + public override UInt32 Read32Unchecked( UInt32 offset ) + { + return *( UInt32* )( this.Offset + offset ); + } + + public override UInt64 Read64Unchecked( UInt32 offset ) + { + return *( UInt64* )( this.Offset + offset ); + } + + public override void Write8( UInt32 offset, byte value ) + { + if( offset < 0 || offset > Size ) + throw new ArgumentOutOfRangeException( "offset" ); + ( *( byte* )( this.Offset + offset ) ) = value; + } + public override void Write16( UInt32 offset, UInt16 value ) + { + if( offset < 0 || offset > Size ) + throw new ArgumentOutOfRangeException( "offset" ); + ( *( UInt16* )( this.Offset + offset ) ) = value; + } + public override void Write32( UInt32 offset, UInt32 value ) + { + if( offset < 0 || offset > Size ) + throw new ArgumentOutOfRangeException( "offset" ); + ( *( UInt32* )( this.Offset + offset ) ) = value; + } + public override void Write64( UInt32 offset, UInt64 value ) + { + if( offset < 0 || offset > Size ) + throw new ArgumentOutOfRangeException( "offset" ); + ( *( UInt64* )( this.Offset + offset ) ) = value; + } + public override void Write8Unchecked( UInt32 offset, byte value ) + { + ( *( byte* )( this.Offset + offset ) ) = value; + } + public override void Write16Unchecked( UInt32 offset, UInt16 value ) + { + ( *( UInt16* )( this.Offset + offset ) ) = value; + } + public override void Write32Unchecked( UInt32 offset, UInt32 value ) + { + ( *( UInt32* )( this.Offset + offset ) ) = value; + } + public override void Write64Unchecked( UInt32 offset, UInt64 value ) + { + ( *( UInt64* )( this.Offset + offset ) ) = value; + } + + public void CopyFrom( MemoryAddressSpace src ) + { + for( uint x = 0; x < src.Size; x++ ) + { + ( *( byte* )( this.Offset + x ) ) = *( byte* )( src.Offset + x ); + } + } + + public void CopyFrom( MemoryAddressSpace src, uint srcOffset, uint dstOffset, uint bytes ) + { + for( uint x = 0; x < bytes; x++ ) + { + ( *( byte* )( this.Offset + dstOffset + x ) ) = *( byte* )( src.Offset + srcOffset + x ); + } + } + + public void SetMem( byte data ) + { + for( uint x = 0; x < this.Size; x++ ) + { + ( *( byte* )( this.Offset + x ) ) = data; + } + } + } +}