From 9739ca604ce3ef5dc14065dfd16f338a8caf3a75 Mon Sep 17 00:00:00 2001 From: kudzu_cp <6d05c8c8ef5431987001abfdb2eadc9593ac9498> Date: Mon, 28 Apr 2008 15:27:14 +0000 Subject: [PATCH] Tracing works, but stepping is broken currently. --- source/Indy.IL2CPU.Assembler.X86/DebugStub.cs | 63 ++++++++----------- source/Indy.IL2CPU.Assembler.X86/X/Y86.cs | 21 +++++++ source/Indy.IL2CPU.Assembler/Assembler.cs | 3 +- 3 files changed, 50 insertions(+), 37 deletions(-) diff --git a/source/Indy.IL2CPU.Assembler.X86/DebugStub.cs b/source/Indy.IL2CPU.Assembler.X86/DebugStub.cs index 81a063957..4fd961f5a 100644 --- a/source/Indy.IL2CPU.Assembler.X86/DebugStub.cs +++ b/source/Indy.IL2CPU.Assembler.X86/DebugStub.cs @@ -20,34 +20,26 @@ namespace Indy.IL2CPU.Assembler.X86 { JumpIf(Flags.Equal, "DebugStub_Step"); AL.Compare(4); JumpIf(Flags.Equal, "DebugStub_Break"); - Jump("DebugStub_Exit"); - } + Return(); - protected void TraceOff() { Label = "DebugStub_TraceOff"; Memory["DebugTraceMode", 32] = 0; - Jump("DebugStub_Exit"); - } + Return(); - protected void TraceOn() { Label = "DebugStub_TraceOn"; Memory["DebugTraceMode", 32] = 1; - Jump("DebugStub_Exit"); - } + Return(); + + Label = "DebugStub_Step"; + Memory["DebugTraceMode", 32] = 4; + Return(); - protected void Break() { Label = "DebugStub_Break"; Memory["DebugTraceMode", 32] = 4; Call("DebugPoint_WaitCmd"); Jump("DebugPoint_ProcessCmd"); } - protected void Step() { - Label = "DebugStub_Step"; - Memory["DebugTraceMode", 32] = 4; - Jump("DebugStub_Exit"); - } - protected void SendTrace() { Label = "SendTrace"; AL = Memory[EBP + 3]; @@ -97,21 +89,23 @@ namespace Indy.IL2CPU.Assembler.X86 { Return(); } - public void Main(UInt16 aComAddr) { - mComAddr = aComAddr; - mComStatusAddr = (UInt16)(aComAddr + 5); - // Assembler.GetIdentifier - + protected void Emit() { ProcessCmd(); - TraceOff(); - TraceOn(); - Break(); - Step(); SendTrace(); WriteByteToDebugger(); WaitCmd(); DebugSuspend(); DebugResume(); + } + + public void Main(UInt16 aComAddr) { + mComAddr = aComAddr; + mComStatusAddr = (UInt16)(aComAddr + 5); + Emit(); + // For Unique Labels + // Assembler.GetIdentifier + // For System..Break + // public class BreakAssembler: AssemblerMethod //"DebugTraceMode dd 1"); //"DebugStatus dd 0"); @@ -124,28 +118,25 @@ namespace Indy.IL2CPU.Assembler.X86 { // Check DebugTraceMode EAX = Memory["DebugTraceMode"]; + //TODO: Change this to support CallIf(AX == 0, "SendTrace"); AL.Compare(0); - JumpIf(Flags.Equal, "DebugPoint_NoTrace"); - Call("SendTrace"); + CallIf(Flags.NotEqual, "SendTrace"); - EAX = Memory["DebugTraceMode"]; - AL.Compare(4); - JumpIf(Flags.NotEqual, "DebugPoint_NoTrace"); - Call("DebugPoint_WaitCmd"); - Jump("DebugPoint_ProcessCmd"); - Label = "DebugPoint_NoTrace"; + //EAX = Memory["DebugTraceMode"]; + //AL.Compare(4); + //JumpIf(Flags.NotEqual, "DebugPoint_NoBreak"); + // Call("DebugStub_Break"); + // Jump("DebugStub_Exit"); + //Label = "DebugPoint_NoBreak"; // Is there a new incoming command? Label = "DebugPoint_CheckCmd"; DX = mComStatusAddr; AL = Port[DX]; AL.Test(0x01); + CallIf(Flags.NotZero, "DebugPoint_ProcessCmd"); - //separate command structure, when in break Wait for unbreak only but process others - JumpIf(Flags.Zero, "DebugStub_Exit"); - Jump("DebugPoint_ProcessCmd"); Label = "DebugStub_Exit"; - PopAll32(); Return(); } diff --git a/source/Indy.IL2CPU.Assembler.X86/X/Y86.cs b/source/Indy.IL2CPU.Assembler.X86/X/Y86.cs index f48f03bff..2cb5ee1aa 100644 --- a/source/Indy.IL2CPU.Assembler.X86/X/Y86.cs +++ b/source/Indy.IL2CPU.Assembler.X86/X/Y86.cs @@ -28,10 +28,31 @@ namespace Indy.IL2CPU.Assembler.X86.X { } } + private uint mLabelCounter = 0; + public string NewLabel() { + mLabelCounter++; + return GetType().Name + mLabelCounter.ToString("X8").ToUpper(); + } + public void Call(string aLabel) { new X86.Call(aLabel); } + public void CallIf(Flags aFlags, string aLabel) { + // TODO: This is inefficient - lots of jumps + // Maybe make an invert function for Flags + var xLabelIf = NewLabel(); + var xLabelExit = NewLabel(); + + JumpIf(aFlags, xLabelIf); + Jump(xLabelExit); + + Label = xLabelIf; + Call(aLabel); + + Label = xLabelExit; + } + public void Jump(string aLabel) { new X86.Jump(aLabel); } diff --git a/source/Indy.IL2CPU.Assembler/Assembler.cs b/source/Indy.IL2CPU.Assembler/Assembler.cs index 83f217042..81e60df99 100644 --- a/source/Indy.IL2CPU.Assembler/Assembler.cs +++ b/source/Indy.IL2CPU.Assembler/Assembler.cs @@ -85,7 +85,8 @@ namespace Indy.IL2CPU.Assembler { private uint mDataMemberCounter = 0; public string GetIdentifier(string aPrefix) { - return aPrefix + mDataMemberCounter++.ToString("X8").ToUpper(); + mDataMemberCounter++; + return aPrefix + mDataMemberCounter.ToString("X8").ToUpper(); } public Assembler(Func aGetStreamForGroup)