From 59450f9e86f642f05294a54d6ddb7fa4e37d72eb Mon Sep 17 00:00:00 2001 From: kudzu_cp <6d05c8c8ef5431987001abfdb2eadc9593ac9498> Date: Mon, 2 Aug 2010 15:54:11 +0000 Subject: [PATCH] DebugStub ACK functioning. --- Docs/XSharp/index.html | 3 ++ .../CDebugger/DebugConnector.cs | 26 ++++++++++++++--- .../AD7.Impl/AD7Process.cs | 11 ++++---- .../Engine.Impl/BreakpointManager.cs | 2 -- .../X86/SpecialDebug/DebugStub.cs | 28 +++++++++++++++---- 5 files changed, 53 insertions(+), 17 deletions(-) diff --git a/Docs/XSharp/index.html b/Docs/XSharp/index.html index 2b3055380..bb7a8d66b 100644 --- a/Docs/XSharp/index.html +++ b/Docs/XSharp/index.html @@ -21,6 +21,9 @@ generates warnings about dword being ignored new Push { DestinationReg = GetId() }; } |
AL.Push does not work at all.

+

+ EAX = Memory["lable"] does same as addressof.. you have to specify size... size + should be infreered and never use teh value o lable

X#milation would need to be implemented.
  • One of the goals of Cosmos is the need to write very little assembly, so only diff --git a/source2/Debug/Cosmos.Debug.Common/CDebugger/DebugConnector.cs b/source2/Debug/Cosmos.Debug.Common/CDebugger/DebugConnector.cs index 9f7e4fb47..c4a3dd7bc 100644 --- a/source2/Debug/Cosmos.Debug.Common/CDebugger/DebugConnector.cs +++ b/source2/Debug/Cosmos.Debug.Common/CDebugger/DebugConnector.cs @@ -9,19 +9,22 @@ using System.Windows.Forms; namespace Cosmos.Debug.Common.CDebugger { public abstract class DebugConnector: IDisposable { - //TODO: These should not be this way and should in fact - // be checked or better yet done by constructor arguments - // but that puts a restriction on where the sub classes - // are created. public Action ConnectionLost; public Action CmdTrace; public Action CmdText; public Action CmdStarted; + public Action OnDebugMsg; protected MsgType mCurrentMsgType; public abstract void WaitConnect(); + protected void DoDebugMsg(string aMsg) { + if (OnDebugMsg != null) { + OnDebugMsg(aMsg); + } + } + public abstract bool Connected { get; } @@ -84,6 +87,20 @@ namespace Cosmos.Debug.Common.CDebugger } public void SetBreakpoint(int aID, uint aAddress) { + // Not needed as SendCommand will do it, but it saves + // some execution, but more importantly stops it from + // logging messages to debug output for events that + // dont happen. + if (!Connected) { + return; + } + + if (aAddress == 0) { + DoDebugMsg("DS Cmd: BP " + aID + " deleted"); + } else { + DoDebugMsg("DS Cmd: BP " + aID + " @ " + aAddress.ToString("X8").ToUpper()); + } + var xData = CreateCommand(Command.BreakOnAddress, 5); Array.Copy(BitConverter.GetBytes(aAddress), 0, xData, CmdSize, 4); xData[CmdSize + 4] = (byte)aID; @@ -148,6 +165,7 @@ namespace Cosmos.Debug.Common.CDebugger protected void PacketCmdCompleted(byte[] aPacket) { byte xCmdID = aPacket[0]; + DoDebugMsg("DS Msg: Cmd " + xCmdID + " Complete"); WaitForMessage(); } diff --git a/source2/Debug/Cosmos.Debug.VSDebugEngine/AD7.Impl/AD7Process.cs b/source2/Debug/Cosmos.Debug.VSDebugEngine/AD7.Impl/AD7Process.cs index f90f8f6e7..78762422d 100644 --- a/source2/Debug/Cosmos.Debug.VSDebugEngine/AD7.Impl/AD7Process.cs +++ b/source2/Debug/Cosmos.Debug.VSDebugEngine/AD7.Impl/AD7Process.cs @@ -169,11 +169,12 @@ namespace Cosmos.Debug.VSDebugEngine { mDbgConnector.CmdTrace += new Action(DbgCmdTrace); mDbgConnector.CmdText += new Action(DbgCmdText); mDbgConnector.CmdStarted += new Action(DbgCmdStarted); - mDbgConnector.ConnectionLost = new Action( - delegate { - mEngine.Callback.OnProcessExit(0); - } - ); + mDbgConnector.OnDebugMsg += new Action(delegate(string aMsg) { + DebugMsg(aMsg); + }); + mDbgConnector.ConnectionLost = new Action( delegate { + mEngine.Callback.OnProcessExit(0); + } ); System.Threading.Thread.Sleep(250); System.Diagnostics.Debug.WriteLine(String.Format("Launching process: \"{0}\" {1}", mProcessStartInfo.FileName, mProcessStartInfo.Arguments).Trim()); diff --git a/source2/Debug/Cosmos.Debug.VSDebugEngine/Engine.Impl/BreakpointManager.cs b/source2/Debug/Cosmos.Debug.VSDebugEngine/Engine.Impl/BreakpointManager.cs index 2fd148c21..33c127da6 100644 --- a/source2/Debug/Cosmos.Debug.VSDebugEngine/Engine.Impl/BreakpointManager.cs +++ b/source2/Debug/Cosmos.Debug.VSDebugEngine/Engine.Impl/BreakpointManager.cs @@ -41,7 +41,6 @@ namespace Cosmos.Debug.VSDebugEngine { for (int xID = 0; xID < MaxBP; xID++) { if (mActiveBPs[xID] == null) { mActiveBPs[xID] = aBBP; - mEngine.mProcess.DebugMsg("Remote BP #" + xID + " @ " + aBBP.mAddress.ToString("X8").ToUpper()); mDbgConnector.SetBreakpoint(xID, aBBP.mAddress); return xID; } @@ -50,7 +49,6 @@ namespace Cosmos.Debug.VSDebugEngine { } public void RemoteDisable(AD7BoundBreakpoint aBBP) { - mEngine.mProcess.DebugMsg("Remote BP #" + aBBP.RemoteID + " deleted."); mActiveBPs[aBBP.RemoteID] = null; mDbgConnector.DeleteBreakpoint(aBBP.RemoteID); } diff --git a/source2/IL2PCU/Cosmos.IL2CPU.X86/X86/SpecialDebug/DebugStub.cs b/source2/IL2PCU/Cosmos.IL2CPU.X86/X86/SpecialDebug/DebugStub.cs index 0a78fdda5..561e390ac 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU.X86/X86/SpecialDebug/DebugStub.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU.X86/X86/SpecialDebug/DebugStub.cs @@ -385,8 +385,8 @@ namespace Cosmos.IL2CPU.X86 { // Read Command ID Call("ReadALFromComPort"); - Memory["DebugStub_CommandID"] = AL; - + Memory["DebugStub_CommandID", 32] = EAX; + // Get AL back so we can compare it, but also put it back for later EAX.Pop(); EAX.Push(); @@ -394,28 +394,44 @@ namespace Cosmos.IL2CPU.X86 { AL.Compare((byte)Command.TraceOff); JumpIf(Flags.NotEqual, "DebugStub_ProcessCmd_TraceOff_After"); Memory["DebugTraceMode", 32] = (int)Tracing.Off; - Jump("DebugStub_ProcessCmd_Exit"); + Jump("DebugStub_ProcessCmd_ACK"); Label = "DebugStub_ProcessCmd_TraceOff_After"; AL.Compare((byte)Command.TraceOn); JumpIf(Flags.NotEqual, "DebugStub_ProcessCmd_TraceOn_After"); Memory["DebugTraceMode", 32] = (int)Tracing.On; - Jump("DebugStub_ProcessCmd_Exit"); + Jump("DebugStub_ProcessCmd_ACK"); Label = "DebugStub_ProcessCmd_TraceOn_After"; AL.Compare((byte)Command.Break); JumpIf(Flags.NotEqual, "DebugStub_ProcessCmd_Break_After"); Call("DebugStub_Break"); - Jump("DebugStub_ProcessCmd_Exit"); + Jump("DebugStub_ProcessCmd_ACK"); Label = "DebugStub_ProcessCmd_Break_After"; AL.Compare((byte)Command.BreakOnAddress); JumpIf(Flags.NotEqual, "DebugStub_ProcessCmd_BreakOnAddress_After"); Call("DebugStub_BreakOnAddress"); - Jump("DebugStub_ProcessCmd_Exit"); + Jump("DebugStub_ProcessCmd_ACK"); Label = "DebugStub_ProcessCmd_BreakOnAddress_After"; + Label = "DebugStub_ProcessCmd_ACK"; + // We acknowledge receipt of the command, not processing of it. + // We have to do this because sometimes callers do more processing + // We ACK even ones we dont process here, but do not ACK Noop. + // The buffers should be ok becuase more wont be sent till after our NACK + // is received. + // Right now our max cmd size is 2 + 5 = 7. UART buffer is 16. + // We may need to revisit this in the future to ack not commands, but data chunks + // and move them to a buffer. + AL = (int)MsgType.CmdCompleted; + Call("WriteALToComPort"); + EAX = Memory["DebugStub_CommandID", 32]; + Call("WriteALToComPort"); + Label = "DebugStub_ProcessCmd_Exit"; + // Restore AL for callers who check the command and do + // further processing, or for commands not handled by this routine. EAX.Pop(); Return(); }