diff --git a/source2/Compiler/Cosmos.Compiler.DebugStub/DebugStub.cs b/source2/Compiler/Cosmos.Compiler.DebugStub/DebugStub.cs index 1316e92e1..e18a9088b 100644 --- a/source2/Compiler/Cosmos.Compiler.DebugStub/DebugStub.cs +++ b/source2/Compiler/Cosmos.Compiler.DebugStub/DebugStub.cs @@ -157,18 +157,16 @@ namespace Cosmos.Compiler.DebugStub { // now ECX contains size of data (count) // EAX contains relative to EBP - Label = "DebugStub_SendMethodContext2"; ESI = Memory[DebugStub.CallerEBP.Name, 32]; ESI.Add(EAX); - Label = "DebugStub_SendMethodContext_SendByte"; - new Compare { DestinationReg = Registers.ECX, SourceValue = 0 }; - JumpIf(Flags.Equal, "DebugStub_SendMethodContext_After_SendByte"); + Label = ".SendByte"; + ECX.Compare(0); + JumpIf(Flags.Equal, ".AfterSendByte"); Call(); - new Dec { DestinationReg = Registers.ECX }; - Jump("DebugStub_SendMethodContext_SendByte"); - - Label = "DebugStub_SendMethodContext_After_SendByte"; + ECX--; + Jump(".SendByte"); + Label = ".AfterSendByte"; PopAll(); } diff --git a/source2/Compiler/Cosmos.Compiler.XSharp/Register.cs b/source2/Compiler/Cosmos.Compiler.XSharp/Register.cs index d597465ec..20f345e62 100644 --- a/source2/Compiler/Cosmos.Compiler.XSharp/Register.cs +++ b/source2/Compiler/Cosmos.Compiler.XSharp/Register.cs @@ -6,57 +6,56 @@ using Cosmos.Compiler.Assembler; using Cosmos.Compiler.Assembler.X86; namespace Cosmos.Compiler.XSharp { - public abstract class Register { - protected byte mBitSize; - public byte BitSize { - get { return mBitSize; } - } - - public readonly string Name; - - public Register() { - Name = GetType().Name.Substring(typeof(Register).Name.Length); - } - - public override string ToString() { - return Name; - } - - public RegistersEnum GetId() { - return Registers.GetRegister(Name).Value; - } - - public void Push() { - // TODO: This emits Push dword which generates warnings about dword being ignored - new Push { DestinationReg = GetId() }; - } - - public void Pop() { - new Pop { DestinationReg = GetId() }; - } - - protected void Move(uint aAddress) { - new Move { DestinationReg = GetId(), SourceValue = aAddress, Size=Registers.GetSize(GetId())}; - } - - protected void Move(MemoryAction aAction) { - new Move { DestinationReg = GetId(), SourceReg = aAction.Register, SourceDisplacement = aAction.Displacement, SourceIsIndirect = aAction.IsIndirect, SourceRef = aAction.Reference, Size = Registers.GetSize(GetId()) }; - } - - protected void Move(RegistersEnum aRegister) - { - new Move { DestinationReg = GetId(), SourceReg = aRegister, Size = Registers.GetSize(GetId()) }; - } - - protected void Move(ElementReference aReference) { - new Move { DestinationReg = GetId(), SourceRef = aReference, Size = Registers.GetSize(GetId())}; - } - - public bool isPort(){ - if (GetId().Equals(Registers.AX) || GetId().Equals(Registers.AL) || GetId().Equals(Registers.EAX)) { - return true; - } - return false; - } + public abstract class Register { + protected byte mBitSize; + public byte BitSize { + get { return mBitSize; } } + + public readonly string Name; + + public Register() { + Name = GetType().Name.Substring(typeof(Register).Name.Length); + } + + public override string ToString() { + return Name; + } + + public RegistersEnum GetId() { + return Registers.GetRegister(Name).Value; + } + + public void Push() { + // TODO: This emits Push dword which generates warnings about dword being ignored + new Push { DestinationReg = GetId() }; + } + + public void Pop() { + new Pop { DestinationReg = GetId() }; + } + + protected void Move(uint aAddress) { + new Move { DestinationReg = GetId(), SourceValue = aAddress, Size = Registers.GetSize(GetId()) }; + } + + protected void Move(MemoryAction aAction) { + new Move { DestinationReg = GetId(), SourceReg = aAction.Register, SourceDisplacement = aAction.Displacement, SourceIsIndirect = aAction.IsIndirect, SourceRef = aAction.Reference, Size = Registers.GetSize(GetId()) }; + } + + protected void Move(RegistersEnum aRegister) { + new Move { DestinationReg = GetId(), SourceReg = aRegister, Size = Registers.GetSize(GetId()) }; + } + + protected void Move(ElementReference aReference) { + new Move { DestinationReg = GetId(), SourceRef = aReference, Size = Registers.GetSize(GetId()) }; + } + + public bool isPort() { + if (GetId().Equals(Registers.AX) || GetId().Equals(Registers.AL) || GetId().Equals(Registers.EAX)) { + return true; + } + return false; + } + } } diff --git a/source2/Compiler/Cosmos.Compiler.XSharp/Register32.cs b/source2/Compiler/Cosmos.Compiler.XSharp/Register32.cs index ff35f7b7a..767d4e811 100644 --- a/source2/Compiler/Cosmos.Compiler.XSharp/Register32.cs +++ b/source2/Compiler/Cosmos.Compiler.XSharp/Register32.cs @@ -6,46 +6,47 @@ using Cosmos.Compiler.Assembler; using Cosmos.Compiler.Assembler.X86; namespace Cosmos.Compiler.XSharp { - public class Register32 : Register { - public Register32() { - mBitSize = 32; - } + public class Register32 : Register { - // Not all overloads can go here. - // 1- C# overloads specifically by exact class and does not inherit in many cases - // 2- x86 does not support all operations on all registers - - public static AddressIndirect operator+ (Register32 aBaseRegister, Int32 aDisplacement) { - return new AddressIndirect(aBaseRegister, aDisplacement); - } - - public void Add(UInt32 aValue) { - new Add { DestinationReg = GetId(), SourceValue = aValue }; - } - public void Add(Register32 aReg) { - new Add { DestinationReg = GetId(), SourceReg = aReg.GetId() }; - } - - public void Sub(UInt32 aValue) { - new Sub { DestinationReg = GetId(), SourceValue = aValue }; - } - public void Sub(Register32 aReg) { - new Sub { DestinationReg = GetId(), SourceReg = aReg.GetId() }; - } - - public void Compare(UInt32 aValue) { - new Compare { DestinationReg = GetId(), SourceValue = aValue }; - } - public void Compare(MemoryAction aAction) { - new Compare { - DestinationRef = aAction.Reference, - DestinationIsIndirect = true, - SourceReg = GetId() - }; - } - - public void Test(UInt32 aValue) { - new Test { DestinationReg = GetId(), SourceValue = aValue, Size = 32 }; - } + public Register32() { + mBitSize = 32; } + + // Not all overloads can go here. + // 1- C# overloads specifically by exact class and does not inherit in many cases + // 2- x86 does not support all operations on all registers + + public static AddressIndirect operator +(Register32 aBaseRegister, Int32 aDisplacement) { + return new AddressIndirect(aBaseRegister, aDisplacement); + } + + public void Add(UInt32 aValue) { + new Add { DestinationReg = GetId(), SourceValue = aValue }; + } + public void Add(Register32 aReg) { + new Add { DestinationReg = GetId(), SourceReg = aReg.GetId() }; + } + + public void Sub(UInt32 aValue) { + new Sub { DestinationReg = GetId(), SourceValue = aValue }; + } + public void Sub(Register32 aReg) { + new Sub { DestinationReg = GetId(), SourceReg = aReg.GetId() }; + } + + public void Compare(UInt32 aValue) { + new Compare { DestinationReg = GetId(), SourceValue = aValue }; + } + public void Compare(MemoryAction aAction) { + new Compare { + DestinationRef = aAction.Reference, + DestinationIsIndirect = true, + SourceReg = GetId() + }; + } + + public void Test(UInt32 aValue) { + new Test { DestinationReg = GetId(), SourceValue = aValue, Size = 32 }; + } + } } \ No newline at end of file diff --git a/source2/Compiler/Cosmos.Compiler.XSharp/RegisterEAX.cs b/source2/Compiler/Cosmos.Compiler.XSharp/RegisterEAX.cs index 1569faec9..dcf331706 100644 --- a/source2/Compiler/Cosmos.Compiler.XSharp/RegisterEAX.cs +++ b/source2/Compiler/Cosmos.Compiler.XSharp/RegisterEAX.cs @@ -6,74 +6,68 @@ using Cosmos.Compiler.Assembler; using Cosmos.Compiler.Assembler.X86; namespace Cosmos.Compiler.XSharp { - public class RegisterEAX : Register32 { - public const string Name = "EAX"; - public static readonly RegisterEAX Instance = new RegisterEAX(); - - public override string ToString() { - return Name; - } - - public static RegisterEAX operator++ (RegisterEAX aRegister) { - new Inc { DestinationReg = aRegister.GetId() }; - return aRegister; - } - public static RegisterEAX operator-- (RegisterEAX aRegister) { - new Dec { DestinationReg = aRegister.GetId() }; - return aRegister; - } - public static RegisterEAX operator<< (RegisterEAX aRegister, int aCount) { - new ShiftLeft { DestinationReg = aRegister.GetId(), SourceValue = (uint)aCount }; - return aRegister; - } - public static RegisterEAX operator>> (RegisterEAX aRegister, int aCount) { - new ShiftRight { DestinationReg = aRegister.GetId(), SourceValue = (uint)aCount }; - return aRegister; - } - - public static implicit operator RegisterEAX(ElementReference aReference) { - Instance.Move(aReference); - return Instance; - } - - public static implicit operator RegisterEAX(MemoryAction aAction) { - Instance.Move(aAction); - return Instance; - } - - public static implicit operator RegisterEAX(UInt32 aValue) { - Instance.Move(aValue); - return Instance; - } - - public static implicit operator RegisterEAX(RegisterEBX aReg) { - Instance.Move(aReg.GetId()); - return Instance; - } - - public static implicit operator RegisterEAX(RegisterECX aReg) { - Instance.Move(aReg.GetId()); - return Instance; - } - - public static implicit operator RegisterEAX(RegisterESI aReg) - { - Instance.Move(aReg.GetId()); - return Instance; - } - - public static implicit operator RegisterEAX(RegisterEDX aReg) { - Instance.Move(aReg.GetId()); - return Instance; - } - - public static implicit operator PortNumber(RegisterEAX aEAX) { - return new PortNumber(aEAX.GetId()); - } - - public void RotateRight(int aCount) { - new RotateRight { DestinationReg = Registers.EBX, SourceValue = (uint)aCount }; - } + public class RegisterEAX : Register32 { + public static readonly RegisterEAX Instance = new RegisterEAX(); + public static RegisterEAX operator ++(RegisterEAX aRegister) { + new Inc { DestinationReg = aRegister.GetId() }; + return aRegister; } + public static RegisterEAX operator --(RegisterEAX aRegister) { + new Dec { DestinationReg = aRegister.GetId() }; + return aRegister; + } + public static RegisterEAX operator <<(RegisterEAX aRegister, int aCount) { + new ShiftLeft { DestinationReg = aRegister.GetId(), SourceValue = (uint)aCount }; + return aRegister; + } + public static RegisterEAX operator >>(RegisterEAX aRegister, int aCount) { + new ShiftRight { DestinationReg = aRegister.GetId(), SourceValue = (uint)aCount }; + return aRegister; + } + + public static implicit operator RegisterEAX(ElementReference aReference) { + Instance.Move(aReference); + return Instance; + } + + public static implicit operator RegisterEAX(MemoryAction aAction) { + Instance.Move(aAction); + return Instance; + } + + public static implicit operator RegisterEAX(UInt32 aValue) { + Instance.Move(aValue); + return Instance; + } + + public static implicit operator RegisterEAX(RegisterEBX aReg) { + Instance.Move(aReg.GetId()); + return Instance; + } + + public static implicit operator RegisterEAX(RegisterECX aReg) { + Instance.Move(aReg.GetId()); + return Instance; + } + + public static implicit operator RegisterEAX(RegisterESI aReg) { + Instance.Move(aReg.GetId()); + return Instance; + } + + public static implicit operator RegisterEAX(RegisterEDX aReg) { + Instance.Move(aReg.GetId()); + return Instance; + } + + public static implicit operator PortNumber(RegisterEAX aEAX) { + return new PortNumber(aEAX.GetId()); + } + + public void RotateRight(int aCount) { + new RotateRight { DestinationReg = Registers.EBX, SourceValue = (uint)aCount }; + } + + } } diff --git a/source2/Compiler/Cosmos.Compiler.XSharp/RegisterEBX.cs b/source2/Compiler/Cosmos.Compiler.XSharp/RegisterEBX.cs index e85ed1920..ce223b6e5 100644 --- a/source2/Compiler/Cosmos.Compiler.XSharp/RegisterEBX.cs +++ b/source2/Compiler/Cosmos.Compiler.XSharp/RegisterEBX.cs @@ -6,59 +6,59 @@ using Cosmos.Compiler.Assembler; using Cosmos.Compiler.Assembler.X86; namespace Cosmos.Compiler.XSharp { - public class RegisterEBX : Register32 { - public static readonly RegisterEBX Instance = new RegisterEBX(); - - public static RegisterEBX operator ++(RegisterEBX aRegister) { - new Inc { DestinationReg = aRegister.GetId() }; - return aRegister; - } - public static RegisterEBX operator --(RegisterEBX aRegister) { - new Dec { DestinationReg = aRegister.GetId() }; - return aRegister; - } - public static RegisterEBX operator <<(RegisterEBX aRegister, int aCount) { - new ShiftLeft { DestinationReg = aRegister.GetId(), SourceValue = (uint)aCount }; - return aRegister; - } - public static RegisterEBX operator >>(RegisterEBX aRegister, int aCount) { - new ShiftRight { DestinationReg = aRegister.GetId(), SourceValue = (uint)aCount }; - return aRegister; - } - - public static implicit operator RegisterEBX(ElementReference aReference) { - Instance.Move(aReference); - return Instance; - } - - public static implicit operator RegisterEBX(MemoryAction aAction) { - Instance.Move(aAction); - return Instance; - } - - public static implicit operator RegisterEBX(UInt32 aValue) { - Instance.Move(aValue); - return Instance; - } - - public static implicit operator RegisterEBX(RegisterEAX aValue) { - Instance.Move(aValue.GetId()); - return Instance; - } - - public static implicit operator RegisterEBX(RegisterECX aValue) { - Instance.Move(aValue.GetId()); - return Instance; - } - - public static implicit operator RegisterEBX(RegisterEDX aValue) { - Instance.Move(aValue.GetId()); - return Instance; - } - - public void RotateRight(int aCount) { - new RotateRight { DestinationReg = Registers.EBX, SourceValue = (uint)aCount }; - } + public class RegisterEBX : Register32 { + public static readonly RegisterEBX Instance = new RegisterEBX(); + public static RegisterEBX operator ++(RegisterEBX aRegister) { + new Inc { DestinationReg = aRegister.GetId() }; + return aRegister; } + public static RegisterEBX operator --(RegisterEBX aRegister) { + new Dec { DestinationReg = aRegister.GetId() }; + return aRegister; + } + public static RegisterEBX operator <<(RegisterEBX aRegister, int aCount) { + new ShiftLeft { DestinationReg = aRegister.GetId(), SourceValue = (uint)aCount }; + return aRegister; + } + public static RegisterEBX operator >>(RegisterEBX aRegister, int aCount) { + new ShiftRight { DestinationReg = aRegister.GetId(), SourceValue = (uint)aCount }; + return aRegister; + } + + public static implicit operator RegisterEBX(ElementReference aReference) { + Instance.Move(aReference); + return Instance; + } + + public static implicit operator RegisterEBX(MemoryAction aAction) { + Instance.Move(aAction); + return Instance; + } + + public static implicit operator RegisterEBX(UInt32 aValue) { + Instance.Move(aValue); + return Instance; + } + + public static implicit operator RegisterEBX(RegisterEAX aValue) { + Instance.Move(aValue.GetId()); + return Instance; + } + + public static implicit operator RegisterEBX(RegisterECX aValue) { + Instance.Move(aValue.GetId()); + return Instance; + } + + public static implicit operator RegisterEBX(RegisterEDX aValue) { + Instance.Move(aValue.GetId()); + return Instance; + } + + public void RotateRight(int aCount) { + new RotateRight { DestinationReg = Registers.EBX, SourceValue = (uint)aCount }; + } + + } } diff --git a/source2/Compiler/Cosmos.Compiler.XSharp/RegisterECX.cs b/source2/Compiler/Cosmos.Compiler.XSharp/RegisterECX.cs index 07bae1c6d..371c35f83 100644 --- a/source2/Compiler/Cosmos.Compiler.XSharp/RegisterECX.cs +++ b/source2/Compiler/Cosmos.Compiler.XSharp/RegisterECX.cs @@ -3,39 +3,57 @@ using System.Collections.Generic; using System.Linq; using System.Text; using Cosmos.Compiler.Assembler; +using Cosmos.Compiler.Assembler.X86; namespace Cosmos.Compiler.XSharp { - public class RegisterECX : Register32 { - public static readonly RegisterECX Instance = new RegisterECX(); + public class RegisterECX : Register32 { + public static readonly RegisterECX Instance = new RegisterECX(); - public static implicit operator RegisterECX(ElementReference aReference) { - Instance.Move(aReference); - return Instance; - } - - public static implicit operator RegisterECX(MemoryAction aAction) { - Instance.Move(aAction); - return Instance; - } - - public static implicit operator RegisterECX(UInt32 aValue) { - Instance.Move(aValue); - return Instance; - } - - public static implicit operator RegisterECX(RegisterEAX aValue) { - Instance.Move(aValue.GetId()); - return Instance; - } - - public static implicit operator RegisterECX(RegisterEBX aValue) { - Instance.Move(aValue.GetId()); - return Instance; - } - - public static implicit operator RegisterECX(RegisterEDX aValue) { - Instance.Move(aValue.GetId()); - return Instance; - } + public static RegisterECX operator ++(RegisterECX aRegister) { + new Inc { DestinationReg = aRegister.GetId() }; + return aRegister; } + public static RegisterECX operator --(RegisterECX aRegister) { + new Dec { DestinationReg = aRegister.GetId() }; + return aRegister; + } + public static RegisterECX operator <<(RegisterECX aRegister, int aCount) { + new ShiftLeft { DestinationReg = aRegister.GetId(), SourceValue = (uint)aCount }; + return aRegister; + } + public static RegisterECX operator >>(RegisterECX aRegister, int aCount) { + new ShiftRight { DestinationReg = aRegister.GetId(), SourceValue = (uint)aCount }; + return aRegister; + } + + public static implicit operator RegisterECX(ElementReference aReference) { + Instance.Move(aReference); + return Instance; + } + + public static implicit operator RegisterECX(MemoryAction aAction) { + Instance.Move(aAction); + return Instance; + } + + public static implicit operator RegisterECX(UInt32 aValue) { + Instance.Move(aValue); + return Instance; + } + + public static implicit operator RegisterECX(RegisterEAX aValue) { + Instance.Move(aValue.GetId()); + return Instance; + } + + public static implicit operator RegisterECX(RegisterEBX aValue) { + Instance.Move(aValue.GetId()); + return Instance; + } + + public static implicit operator RegisterECX(RegisterEDX aValue) { + Instance.Move(aValue.GetId()); + return Instance; + } + } } diff --git a/source2/Compiler/Cosmos.Compiler.XSharp/RegisterEDX.cs b/source2/Compiler/Cosmos.Compiler.XSharp/RegisterEDX.cs index 0f4501090..e2ff16020 100644 --- a/source2/Compiler/Cosmos.Compiler.XSharp/RegisterEDX.cs +++ b/source2/Compiler/Cosmos.Compiler.XSharp/RegisterEDX.cs @@ -4,17 +4,17 @@ using System.Linq; using System.Text; namespace Cosmos.Compiler.XSharp { - public class RegisterEDX : Register32 { - public static readonly RegisterEDX Instance = new RegisterEDX(); + public class RegisterEDX : Register32 { + public static readonly RegisterEDX Instance = new RegisterEDX(); - public static implicit operator RegisterEDX(MemoryAction aAction) { - Instance.Move(aAction); - return Instance; - } - - public static implicit operator RegisterEDX(UInt32 aValue) { - Instance.Move(aValue); - return Instance; - } + public static implicit operator RegisterEDX(MemoryAction aAction) { + Instance.Move(aAction); + return Instance; } + + public static implicit operator RegisterEDX(UInt32 aValue) { + Instance.Move(aValue); + return Instance; + } + } }