Skip to content

Commit

Permalink
Ongoing changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mterwoord committed Feb 1, 2015
1 parent a4ee9fe commit 274f035
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 49 deletions.
9 changes: 6 additions & 3 deletions Users/Matthijs/DebugCompiler/Program.TestCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ namespace DebugCompiler
{
internal class Program
{
public const string CosmosRoot = @"e:\OpenSource\Cosmos";
public const string CosmosRoot = @"c:\data\sources\OpenSource\Cosmos";

//public const string CosmosRoot = @"C:\Users\Emile\Source\Repos\Cosmos";
//public const string CosmosRoot = @"c:\Development\Cosmos";
//public const string CosmosRoot = @"C:\Users\Huge\Documents\Visual Studio 2010\Projects\IL2CPU";
Expand All @@ -27,8 +28,10 @@ internal class Program
//private const string OutputFile = CosmosRoot + @"\Users\Sentinel209\SentinelKernel\bin\Debug\SentinelKernelBoot.asm";
//private const string KernelFile = CosmosRoot + @"\Users\Matthijs\Playground\bin\Debug\Playground.dll";
//private const string OutputFile = CosmosRoot + @"\Users\Matthijs\Playground\bin\Debug\PlaygroundBoot.asm";
private const string KernelFile = CosmosRoot + @"\Demos\Guess\bin\Debug\GuessKernel.dll";
private const string OutputFile = CosmosRoot + @"\Demos\Guess\bin\Debug\GuessKernelBoot.asm";
//private const string KernelFile = CosmosRoot + @"\Demos\Guess\bin\Debug\GuessKernel.dll";
//private const string OutputFile = CosmosRoot + @"\Demos\Guess\bin\Debug\GuessKernelBoot.asm";
private const string KernelFile = @"c:\Data\Sources\OpenSource\Edison\CosmosEdison\Sources\Playgrounds.Matthijs\bin\Debug\Playgrounds.Matthijs.dll";
private const string OutputFile = @"c:\Data\Sources\OpenSource\Edison\CosmosEdison\Sources\Playgrounds.Matthijs\bin\Debug\Playgrounds.MatthijsBoot.asm";
//private const string KernelFile = CosmosRoot + @"\Users\Emile\TestBed\TestBed\bin\Debug\TestBed.dll";
//private const string OutputFile = CosmosRoot + @"\Users\Emile\TestBed\TestBed\bin\Debug\TestBedBoot.asm";

Expand Down
30 changes: 16 additions & 14 deletions source/Cosmos.Debug.Common/DebugConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,24 +185,24 @@ protected void SendCmd(byte aCmd, byte[] aData, bool aWait)
//So this forces us to only return when we are back in-sync or after we think we've frozen the system for
//too long
//If we haven't gone past the command already!
if ((!resetID && lastCmdCompletedID < mCommandID)
|| (resetID && lastCmdCompletedID > 5))
{
int attempts = 0;
do
if ((!resetID && lastCmdCompletedID < mCommandID)
|| (resetID && lastCmdCompletedID > 5))
{
mCmdWait.WaitOne(2000 /*60000*/);
} while ((
(!resetID && lastCmdCompletedID < mCommandID) ||
(resetID && lastCmdCompletedID > 5)
)
&&
++attempts < 10);
int attempts = 0;
do
{
mCmdWait.WaitOne(2000 /*60000*/);
} while ((
(!resetID && lastCmdCompletedID < mCommandID) ||
(resetID && lastCmdCompletedID > 5)
)
&&
++attempts < 10);
}
}
}
}
}
}

DoDebugMsg("Send unlocked.");
}
Expand Down Expand Up @@ -578,7 +578,9 @@ protected void PacketOtherChannelCommand(byte aChannel, byte[] aPacket)

protected void PacketOtherChannelSize(byte aChannel, byte aCommand, byte[] aPacket)
{
Next((int)GetUInt32(aPacket, 0), data => PacketChannel(aChannel, aCommand, data));
var xPacketSize = (int)GetUInt32(aPacket, 0);
xPacketSize &= 0xFFF;
Next(xPacketSize, data => PacketChannel(aChannel, aCommand, data));
}

protected void PacketMessageBoxTextSize(byte[] aPacket)
Expand Down
53 changes: 34 additions & 19 deletions source/Cosmos.Debug.Common/DebugConnectorEdison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,21 @@ public DebugConnectorEdison(string aPort, string kernelFile) : base(aPort)
private byte[] mBootPrompt = new byte[7] { 98, 111, 111, 116, 32, 62, 32 };
private byte[] mBootPromptCheck = new byte[7];

protected override void BeforeSendCmd()
{
SendRawData(new byte[1]
{
Vs2Ds.Noop
});
SendRawData(new byte[1]
{
Vs2Ds.Noop
});
SendRawData(new byte[1]
{
Vs2Ds.Noop
});
}

//protected override void BeforeSendCmd()
//{
// SendRawData(new byte[1]
// {
// Vs2Ds.Noop
// });
// SendRawData(new byte[1]
// {
// Vs2Ds.Noop
// });
// SendRawData(new byte[1]
// {
// Vs2Ds.Noop
// });
//}

private int mBootStage = 0;

Expand Down Expand Up @@ -75,13 +74,29 @@ protected override void WaitForSignature(byte[] aPacket)
case 3:
if (WaitForBootPrompt(aPacket))
{
// now at boot prompt.
SendTextToConsole("Now starting kernel\r\n");
SendTextToConsole("mw.l 0xFF009000 0x11F8 1\r\n");
SendRawData("mw.l 0xFF009000 0x11F8 1\r\n");
mBootStage = 4;
SendRawData("\0go 0x200000\r\n");
}
break;
case 4:
if (WaitForBootPrompt(aPacket))
{
SendTextToConsole("mw.l 0xFF009000 0x10F8 1\r\n");
SendRawData("mw.l 0xFF009000 0x10F8 1\r\n");
mBootStage = 5;
}
break;
case 5:
if (WaitForBootPrompt(aPacket))
{
// now at boot prompt.
SendTextToConsole("Now starting kernel\r\n");
mBootStage = 6;
SendRawData("go 0x1000000\r\n");
}
break;
case 6:
//if (WaitForBootPrompt(aPacket))
//{
// SendRawData("\0A");
Expand Down
6 changes: 5 additions & 1 deletion source/Cosmos.Debug.Common/DebugConnectorStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ protected override void Next(int aPacketSize, Action<byte[]> aCompleted)
}
else
{
xIncoming.Completed = aCompleted;
xIncoming.Completed = bytes =>
{
DoDebugMsg(String.Format("DC - Received: 0x{0}", BytesToString(bytes, 0, bytes.Length)));
aCompleted(bytes);
};
}
if (aPacketSize > (1024 * 1024))
{
Expand Down
4 changes: 2 additions & 2 deletions source/Cosmos.Debug.DebugStub/Init.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; Generated at 13-1-2015 19:09:16
; Generated at 1-2-2015 13:56:15

DebugStub_DebugBPs TIMES 256 dd 0
DebugStub_MaxBPId dd 0
Expand Down Expand Up @@ -49,8 +49,8 @@ Mov AL, DebugStub_Const_Ds2Vs_Started
Call DebugStub_ComWriteAL

Call DebugStub_WaitForSignature
Call DebugStub_Hook_OnHandshakeCompleted
Call DebugStub_ProcessCommandBatch
Call DebugStub_Hook_OnHandshakeCompleted
DebugStub_WaitForDbgHandshake_Exit:
mov dword [static_field__Cosmos_Core_INTs_mLastKnownAddress], DebugStub_WaitForDbgHandshake_Exit
Ret
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.Debug.DebugStub/Init.xs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ function WaitForDbgHandshake {
ComWriteAL()

WaitForSignature()
Hook_OnHandshakeCompleted()
ProcessCommandBatch()
Hook_OnHandshakeCompleted()
}

! %ifndef Exclude_Dummy_Hooks
Expand Down
10 changes: 5 additions & 5 deletions source/Cosmos.Debug.Kernel.Plugs/DebuggerAsm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static unsafe void SendMessageBox(Kernel.Debugger aThis, int aLength, cha
[PlugMethod(Assembler = typeof(DebugSendPtr))]
public static unsafe void SendPtr(Kernel.Debugger aThis, object aPtr) { }
[PlugMethod(Assembler = typeof(DebugSendChannelCommand))]
public static unsafe void SendChannelCommand(Kernel.Debugger aThis, byte aChannel, byte aCommand, int aByteCount, byte* aData) { }
public static unsafe void SendChannelCommand(byte aChannel, byte aCommand, int aByteCount, byte* aData) { }
//[PlugMethod(Assembler = typeof(DebugTraceOff))]
//public static void TraceOff() { }

Expand Down Expand Up @@ -56,13 +56,13 @@ public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object a
{
new LiteralAssemblerCode("%ifdef DEBUGSTUB");
// AL contains channel
new LiteralAssemblerCode("mov AL, [EBP + 20]");
new LiteralAssemblerCode("mov AL, [EBP + 16]");
// BL contains command
new LiteralAssemblerCode("mov BL, [EBP + 16]");
new LiteralAssemblerCode("mov BL, [EBP + 12]");
// ECX contains number of bytes to send as command data
new LiteralAssemblerCode("mov ECX, [EBP + 12]");
new LiteralAssemblerCode("mov ECX, [EBP + 8]");
// ESI contains data start pointer
new LiteralAssemblerCode("mov ESI, [EBP + 8]");
new LiteralAssemblerCode("mov ESI, [EBP + 4]");
new LiteralAssemblerCode("call DebugStub_SendCommandOnChannel");
new LiteralAssemblerCode("%endif");
}
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.Debug.Kernel/Debugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public unsafe void SendChannelCommand(byte aChannel, byte aCommand, byte[] aData
}
}

public unsafe void SendChannelCommand(byte aChannel, byte aCommand, int aByteCount, byte* aData)
public static unsafe void SendChannelCommand(byte aChannel, byte aCommand, int aByteCount, byte* aData)
{
//
}
Expand Down
25 changes: 23 additions & 2 deletions source/Cosmos.IL2CPU/AppAssembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ protected void MethodBegin(MethodInfo aMethod)
xMethodLabel = LabelName.Get(aMethod.MethodBase);
}
new Cosmos.Assembler.Label(xMethodLabel);
//Assembler.WriteDebugVideo("Method " + xMethodLabel);

// We could use same GUID as MethodLabelStart, but its better to keep GUIDs unique globaly for items
// so during debugging they can never be confused as to what they point to.
Expand Down Expand Up @@ -460,7 +461,7 @@ public void ProcessMethod(MethodInfo aMethod, List<ILOpCode> aOpCodes)
}

MethodBegin(aMethod);
mLog.WriteLine("Method '{0}'", aMethod.MethodBase.GetFullName());
mLog.WriteLine("Method '{0}', ID = '{1}'", aMethod.MethodBase.GetFullName(), aMethod.UID);
mLog.Flush();
if (aMethod.MethodAssembler != null)
{
Expand Down Expand Up @@ -636,7 +637,7 @@ private void EmitInstructions(MethodInfo aMethod, List<ILOpCode> aCurrentGroup,
}
xILOp.DebugEnabled = DebugEnabled;
xILOp.Execute(aMethod, xOpCode);

AfterOp(aMethod, xOpCode);
//mLog.WriteLine( " end: " + Stack.Count.ToString() );
}
Expand Down Expand Up @@ -1367,6 +1368,19 @@ protected void BeforeOp(MethodInfo aMethod, ILOpCode aOpCode, bool emitInt3NotNo
string xLabel = TmpPosLabel(aMethod, aOpCode);
Assembler.CurrentIlLabel = xLabel;
new Cosmos.Assembler.Label(xLabel);
if (aMethod.MethodBase.DeclaringType != typeof(VTablesImpl))
{
Assembler.EmitAsmLabels = false;
try
{
Assembler.WriteDebugVideo(String.Format("Method {0}:{1}.", aMethod.UID, aOpCode.Position));
//Assembler.WriteDebugVideo(xLabel);
}
finally
{
Assembler.EmitAsmLabels = true;
}
}

uint? xStackDifference = null;

Expand Down Expand Up @@ -1398,6 +1412,8 @@ protected void BeforeOp(MethodInfo aMethod, ILOpCode aOpCode, bool emitInt3NotNo
DebugInfo.AddSymbols(mSymbols, false);

bool INT3PlaceholderEmitted = false;
// for now, don't emit int3's
emitInt3NotNop = false;
EmitTracer(aMethod, aOpCode, aMethod.MethodBase.DeclaringType.Namespace, emitInt3NotNop, out INT3Emitted, out INT3PlaceholderEmitted, hasSourcePoint);

if (INT3Emitted || INT3PlaceholderEmitted)
Expand Down Expand Up @@ -1443,6 +1459,11 @@ protected void BeforeOp(MethodInfo aMethod, ILOpCode aOpCode, bool emitInt3NotNo
new Assembler.Label(xLabel + ".StackCorruptionCheck_End");

}

if (xLabel == "SystemUInt32CosmosCorePlugsGCImplementionImplAllocNewObjectSystemUInt32.IL_0001")
{
//
}
}

protected void EmitTracer(MethodInfo aMethod, ILOpCode aOp, string aNamespace, bool emitInt3NotNop, out bool INT3Emitted, out bool INT3PlaceholderEmitted, bool isNewSourcePoint)
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.VS.Windows/ConsoleUC.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected override void HandleChannelMessage(byte aChannel, byte aCommand, byte[
}
else
{
mOut.WriteLine("Command '" + aCommand + "' not recognized");
mOut.WriteLine("Command '{0}' not recognized. Data = '{1}'", aCommand, Encoding.ASCII.GetString(aData).Replace("\t", " "));
// textBox.Text += ("Command '" + aCommand + "' not recognized!\r\n");
}
//textBox.ScrollToEnd();
Expand Down

0 comments on commit 274f035

Please sign in to comment.