Improved cpu exception tracing.

This commit is contained in:
Matthijs ter Woord 2014-12-19 20:02:59 +01:00
parent 967c67f19f
commit dfdc58ee53
5 changed files with 3027 additions and 3013 deletions

View file

@ -142,6 +142,8 @@ namespace Cosmos.Core
}
#endregion
private static uint mLastKnownAddress;
private static IRQDelegate[] mIRQ_Handlers = new IRQDelegate[256];
// We used to use:
@ -396,7 +398,9 @@ namespace Cosmos.Core
public static void HandleInterrupt_06(ref IRQContext aContext)
{
HandleException(aContext.EIP, "Invalid Opcode", "EInvalidOpcode", ref aContext, true);
// although mLastKnownAddress is a static, we need to get it here, any subsequent calls will change the value!!!
var xLastKnownAddress = mLastKnownAddress;
HandleException(aContext.EIP, "Invalid Opcode", "EInvalidOpcode", ref aContext, xLastKnownAddress);
}
public static void HandleInterrupt_07(ref IRQContext aContext)
@ -472,7 +476,7 @@ namespace Cosmos.Core
#endregion
private static void HandleException(uint aEIP, string aDescription, string aName, ref IRQContext ctx, bool printOriginalEIP = false)
private static void HandleException(uint aEIP, string aDescription, string aName, ref IRQContext ctx, uint lastKnownAddressValue = 0)
{
// At this point we are in a very unstable state.
// Try not to use any Cosmos routines, just
@ -514,18 +518,18 @@ namespace Cosmos.Core
PutErrorChar(0, 25,'*');
PutErrorChar(0, 26,' ');
if (printOriginalEIP)
if (lastKnownAddressValue != 0)
{
PutErrorString(1, 0, "Original EIP: 0x");
PutErrorString(1, 0, "Last known address: 0x");
// start eip at 16
PutErrorChar(1, 16, xHex[(int)((aEIP >> 28) & 0xF)]);
PutErrorChar(1, 17, xHex[(int)((aEIP >> 24) & 0xF)]);
PutErrorChar(1, 18, xHex[(int)((aEIP >> 20) & 0xF)]);
PutErrorChar(1, 19, xHex[(int)((aEIP >> 16) & 0xF)]);
PutErrorChar(1, 20, xHex[(int)((aEIP >> 12) & 0xF)]);
PutErrorChar(1, 21, xHex[(int)((aEIP >> 8) & 0xF)]);
PutErrorChar(1, 22, xHex[(int)((aEIP >> 4) & 0xF)]);
PutErrorChar(1, 23, xHex[(int)(aEIP & 0xF)]);
PutErrorChar(1, 16, xHex[(int)((lastKnownAddressValue >> 28) & 0xF)]);
PutErrorChar(1, 17, xHex[(int)((lastKnownAddressValue >> 24) & 0xF)]);
PutErrorChar(1, 18, xHex[(int)((lastKnownAddressValue >> 20) & 0xF)]);
PutErrorChar(1, 19, xHex[(int)((lastKnownAddressValue >> 16) & 0xF)]);
PutErrorChar(1, 20, xHex[(int)((lastKnownAddressValue >> 12) & 0xF)]);
PutErrorChar(1, 21, xHex[(int)((lastKnownAddressValue >> 8) & 0xF)]);
PutErrorChar(1, 22, xHex[(int)((lastKnownAddressValue >> 4) & 0xF)]);
PutErrorChar(1, 23, xHex[(int)(lastKnownAddressValue & 0xF)]);
}
}

View file

@ -10,3 +10,6 @@ indent_size = 2
[IL/*.cs]
indent_size = 2
[AppAssembler.cs]
indent_style = 4

View file

@ -64,10 +64,6 @@ namespace Cosmos.IL2CPU
protected void MethodBegin(MethodInfo aMethod)
{
if (aMethod.MethodBase.GetFullName() == "SystemUInt64SystemCollectionsGenericList1SystemUInt64get_ItemSystemInt32")
{
Console.Write("");
}
new Comment("---------------------------------------------------------");
new Comment("Assembly: " + aMethod.MethodBase.DeclaringType.Assembly.FullName);
new Comment("Type: " + aMethod.MethodBase.DeclaringType.ToString());
@ -285,10 +281,21 @@ namespace Cosmos.IL2CPU
{
xReturnSize = ILOp.Align(ILOp.SizeOfType(xMethInfo.ReturnType), 4);
}
if (aMethod.PlugMethod == null && !aMethod.IsInlineAssembler)
var xMethodLabel = ILOp.GetMethodLabel(aMethod);
if (aMethod.PlugMethod == null
&& !aMethod.IsInlineAssembler)
{
new Cosmos.Assembler.Label(ILOp.GetMethodLabel(aMethod) + EndOfMethodLabelNameNormal);
new Cosmos.Assembler.Label(xMethodLabel + EndOfMethodLabelNameNormal);
new Comment("Following code is for debugging. Adjust accordingly!");
new Mov
{
DestinationRef = ElementReference.New("static_field__Cosmos_Core_INTs_mLastKnownAddress"),
DestinationIsIndirect = true,
SourceRef = ElementReference.New(xMethodLabel + EndOfMethodLabelNameNormal)
};
}
new Mov { DestinationReg = Registers.ECX, SourceValue = 0 };
var xTotalArgsSize = (from item in aMethod.MethodBase.GetParameters()
select (int)ILOp.Align(ILOp.SizeOfType(item.ParameterType), 4)).Sum();
@ -343,7 +350,7 @@ namespace Cosmos.IL2CPU
}
// extra stack space is the space reserved for example when a "public static int TestMethod();" method is called, 4 bytes is pushed, to make room for result;
}
var xLabelExc = ILOp.GetMethodLabel(aMethod) + EndOfMethodLabelNameException;
var xLabelExc = xMethodLabel + EndOfMethodLabelNameException;
new Cosmos.Assembler.Label(xLabelExc);
if (aMethod.MethodAssembler == null && aMethod.PlugMethod == null && !aMethod.IsInlineAssembler)
{