From bfa405335dff574d6d20d304bcbb044a63a115a6 Mon Sep 17 00:00:00 2001 From: kudzu_cp <6d05c8c8ef5431987001abfdb2eadc9593ac9498> Date: Sun, 17 Jul 2011 05:01:14 +0000 Subject: [PATCH] X# work. --- .../Cosmos.Compiler.Assembler/DataMember.cs | 4 ++-- .../Cosmos.Compiler.DebugStub/DebugStub.cs | 24 ++++++++++++------- .../Cosmos.Compiler.DebugStub/DebugStubOld.cs | 4 +--- .../Cosmos.Compiler.XSharp/CodeGroup.cs | 2 ++ .../Cosmos.Compiler.XSharp.csproj | 2 ++ .../InteruptHandlerAttribute.cs | 12 ++++++++++ .../Cosmos.Compiler.XSharp/XSharpAttribute.cs | 13 ++++++++++ 7 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 source2/Compiler/Cosmos.Compiler.XSharp/InteruptHandlerAttribute.cs create mode 100644 source2/Compiler/Cosmos.Compiler.XSharp/XSharpAttribute.cs diff --git a/source2/Compiler/Cosmos.Compiler.Assembler/DataMember.cs b/source2/Compiler/Cosmos.Compiler.Assembler/DataMember.cs index 363f953f8..6a17dcbe6 100644 --- a/source2/Compiler/Cosmos.Compiler.Assembler/DataMember.cs +++ b/source2/Compiler/Cosmos.Compiler.Assembler/DataMember.cs @@ -284,8 +284,8 @@ namespace Cosmos.Compiler.Assembler { // This is the new type of DataMember, eventually we can eliminate many of the // code in DataMember (base) - public class DataMemberInt : DataMember { - public DataMemberInt(string aName) : base(aName) { + public class DataMember32 : DataMember { + public DataMember32(string aName) : base(aName) { int[] xValue = { 0 }; UntypedDefaultValue = xValue.Cast().ToArray(); } diff --git a/source2/Compiler/Cosmos.Compiler.DebugStub/DebugStub.cs b/source2/Compiler/Cosmos.Compiler.DebugStub/DebugStub.cs index 8064682e7..b24c54e2f 100644 --- a/source2/Compiler/Cosmos.Compiler.DebugStub/DebugStub.cs +++ b/source2/Compiler/Cosmos.Compiler.DebugStub/DebugStub.cs @@ -316,7 +316,7 @@ namespace Cosmos.Compiler.DebugStub { EAX = (uint)xCount; Call(); - ESI = Memory["DebugEBP", 32]; + ESI = Memory["DebugStub_OldEBP", 32]; ESI.Add(8); // Dont transmit EIP or old EBP for (int i = 1; i <= xCount; i++) { Call("WriteByteToComPort"); @@ -331,7 +331,7 @@ namespace Cosmos.Compiler.DebugStub { // Send size of bytes ESI = Memory["DebugESP", 32]; - EAX = Memory["DebugEBP", 32]; + EAX = Memory["DebugStub_OldEBP", 32]; EAX.Sub(ESI); Call(); @@ -340,7 +340,7 @@ namespace Cosmos.Compiler.DebugStub { // Need to reload ESI, WriteAXToCompPort modifies it ESI = Memory["DebugESP", 32]; Label = "DebugStub_SendStack_SendByte"; - ESI.Compare(Memory["DebugEBP", 32]); + ESI.Compare(Memory["DebugStub_OldEBP", 32]); JumpIf(Flags.Equal, "DebugStub_SendStack_Exit"); Call("WriteByteToComPort"); Jump("DebugStub_SendStack_SendByte"); @@ -492,7 +492,7 @@ namespace Cosmos.Compiler.DebugStub { Memory["DebugBreakOnNextTrace", 32].Compare(StepTrigger.Over); JumpIf(Flags.NotEqual, "DebugStub_ExecutingStepOverAfter"); Label = "Debug__StepOver__"; - EAX = Memory["DebugEBP", 32]; + EAX = Memory["DebugStub_OldEBP", 32]; EAX.Compare(Memory["DebugBreakEBP", 32]); // If EBP and start EBP arent equal, dont break // Dont use Equal because we aslo need to stop above if the user starts @@ -505,7 +505,7 @@ namespace Cosmos.Compiler.DebugStub { Memory["DebugBreakOnNextTrace", 32].Compare(StepTrigger.Out); JumpIf(Flags.NotEqual, "DebugStub_ExecutingStepOutAfter"); - EAX = Memory["DebugEBP", 32]; // TODO: X# Allow memory object instead of string, maybe the Datamember object itself. ie EAX = DebugEBP, and below inside Compare + EAX = Memory["DebugStub_OldEBP", 32]; // TODO: X# Allow memory object instead of string, maybe the Datamember object itself. ie EAX = DebugEBP, and below inside Compare EAX.Compare(Memory["DebugBreakEBP", 32]); // TODO: X# JumpIf(EAX == Memory[...... or better yet if(EAX==Memory..., new Delegate { Jump.... Jump should be handled specially so we dont jump around jumps... TODO: Also allow Compare(EAX, 0), in fact force this new syntax JumpIf(Flags.Equal, "DebugStub_Executing_Normal"); CallIf(Flags.LessThanOrEqualTo, "DebugStub_Break"); @@ -584,7 +584,7 @@ namespace Cosmos.Compiler.DebugStub { JumpIf(Flags.NotEqual, "DebugStub_Break_StepOver_After"); Memory["DebugBreakOnNextTrace", 32] = StepTrigger.Over; // TODO: Change this so ,32 is not necessary, can be implied by 32 bit register - ie Memory["DebugBreakEBP", 32] = EBP; - EAX = Memory["DebugEBP", 32]; + EAX = Memory["DebugStub_OldEBP", 32]; Memory["DebugBreakEBP", 32] = EAX; Jump("DebugStub_Break_Exit"); Label = "DebugStub_Break_StepOver_After"; @@ -592,7 +592,7 @@ namespace Cosmos.Compiler.DebugStub { AL.Compare(DsCommand.StepOut); JumpIf(Flags.NotEqual, "DebugStub_Break_StepOut_After"); Memory["DebugBreakOnNextTrace", 32] = StepTrigger.Out; - EAX = Memory["DebugEBP", 32]; + EAX = Memory["DebugStub_OldEBP", 32]; Memory["DebugBreakEBP", 32] = EAX; Jump("DebugStub_Break_Exit"); Label = "DebugStub_Break_StepOut_After"; @@ -605,7 +605,12 @@ namespace Cosmos.Compiler.DebugStub { } } - protected DataMemberInt Test; + // Calling code's EBP value + protected DataMember32 OldEBP; + [XSharp] + public void Test() { + } + public class TracerEntry : CodeBlock { public override void Assemble() { // Main entry point for the DebugStub which is executed at the @@ -613,7 +618,8 @@ namespace Cosmos.Compiler.DebugStub { // EBP is restored by PopAll, but SendFrame uses it. Could // get it from the PushAll data, but this is easier. - Memory["DebugEBP", 32] = EBP; + //Memory[OldEBP.Name, 32] = EBP; + Memory["DebugStub_OldEBP", 32] = EBP; // Could also get ESP from PushAll but this is easier // Another reason to do it here is that soem day we may need to use diff --git a/source2/Compiler/Cosmos.Compiler.DebugStub/DebugStubOld.cs b/source2/Compiler/Cosmos.Compiler.DebugStub/DebugStubOld.cs index 5969c59cd..9993ca28c 100644 --- a/source2/Compiler/Cosmos.Compiler.DebugStub/DebugStubOld.cs +++ b/source2/Compiler/Cosmos.Compiler.DebugStub/DebugStubOld.cs @@ -33,8 +33,6 @@ namespace Cosmos.Compiler.DebugStub { new DataMember("DebugResumeLevel", 0), // Last EIP value new DataMember("DebugEIP", 0), - // Calling code's EBP value - new DataMember("DebugEBP", 0), // Calling code's ESP value new DataMember("DebugESP", 0), // Ptr to the push all data. It points to the "bottom" after a PushAll op. @@ -125,7 +123,7 @@ namespace Cosmos.Compiler.DebugStub { // now ECX contains size of data (count) // EAX contains relative to EBP Label = "DebugStub_SendMethodContext2"; - ESI = Memory["DebugEBP", 32]; + ESI = Memory["DebugStub_OldEBP", 32]; ESI.Add(EAX); Label = "DebugStub_SendMethodContext_SendByte"; diff --git a/source2/Compiler/Cosmos.Compiler.XSharp/CodeGroup.cs b/source2/Compiler/Cosmos.Compiler.XSharp/CodeGroup.cs index 3179a8df9..357ff7834 100644 --- a/source2/Compiler/Cosmos.Compiler.XSharp/CodeGroup.cs +++ b/source2/Compiler/Cosmos.Compiler.XSharp/CodeGroup.cs @@ -12,6 +12,7 @@ namespace Cosmos.Compiler.XSharp { var xThisType = this.GetType(); var xAsm = Assembler.Assembler.CurrentInstance; + // Generate DataMembers foreach (var xMember in xThisType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { if (xMember.FieldType.IsSubclassOf(typeof(DataMember))) { var xCtor = xMember.FieldType.GetConstructor(new Type[] { typeof(string) }); @@ -21,6 +22,7 @@ namespace Cosmos.Compiler.XSharp { } } + // Genereate code foreach (var xType in xThisType.GetNestedTypes()) { if (xType.IsSubclassOf(typeof(CodeBlock))) { var xCtor = xType.GetConstructor(new Type[0]); diff --git a/source2/Compiler/Cosmos.Compiler.XSharp/Cosmos.Compiler.XSharp.csproj b/source2/Compiler/Cosmos.Compiler.XSharp/Cosmos.Compiler.XSharp.csproj index 542a9eb6f..b705d8fba 100644 --- a/source2/Compiler/Cosmos.Compiler.XSharp/Cosmos.Compiler.XSharp.csproj +++ b/source2/Compiler/Cosmos.Compiler.XSharp/Cosmos.Compiler.XSharp.csproj @@ -70,6 +70,7 @@ + @@ -92,6 +93,7 @@ + diff --git a/source2/Compiler/Cosmos.Compiler.XSharp/InteruptHandlerAttribute.cs b/source2/Compiler/Cosmos.Compiler.XSharp/InteruptHandlerAttribute.cs new file mode 100644 index 000000000..d4e6758e8 --- /dev/null +++ b/source2/Compiler/Cosmos.Compiler.XSharp/InteruptHandlerAttribute.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Cosmos.Compiler.XSharp { + + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] + public class InteruptHandlerAttribute : Attribute { + } + +} diff --git a/source2/Compiler/Cosmos.Compiler.XSharp/XSharpAttribute.cs b/source2/Compiler/Cosmos.Compiler.XSharp/XSharpAttribute.cs new file mode 100644 index 000000000..0d7ef6468 --- /dev/null +++ b/source2/Compiler/Cosmos.Compiler.XSharp/XSharpAttribute.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Cosmos.Compiler.XSharp { + + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] + public class XSharpAttribute : Attribute { + public bool InteruptHandler { get; set; } + } + +}