fix opcode address in exec callbacks + tracing (thanks prefetch)

sp/lr/pc for r13/r14/r15 for tracing
fix a bad for threaded renderer's thread start callback
This commit is contained in:
CasualPokePlayer 2022-09-18 02:39:31 -07:00
parent e242d35a22
commit 38d3d36199
6 changed files with 11 additions and 10 deletions

Binary file not shown.

View File

@ -124,7 +124,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS
}
[UnmanagedFunctionPointer(CC)]
public delegate void TraceCallback(TraceMask type, IntPtr regs, IntPtr disasm, uint cyclesOff);
public delegate void TraceCallback(TraceMask type, uint opcode, IntPtr regs, IntPtr disasm, uint cyclesOff);
[BizImport(CC)]
public abstract void SetTraceCallback(TraceCallback callback, TraceMask mask);

View File

@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS
private ITraceable Tracer { get; }
private readonly LibMelonDS.TraceCallback _tracecb;
private unsafe void MakeTrace(LibMelonDS.TraceMask type, IntPtr r, IntPtr disasm, uint cyclesOff)
private unsafe void MakeTrace(LibMelonDS.TraceMask type, uint opcode, IntPtr r, IntPtr disasm, uint cyclesOff)
{
string cpu = type switch
{
@ -24,12 +24,12 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS
uint* regs = (uint*)r;
bool isthumb = type is LibMelonDS.TraceMask.ARM7_THUMB or LibMelonDS.TraceMask.ARM9_THUMB;
uint pc = regs[15] - (isthumb ? 2u : 4u); // handle prefetch
uint opaddr = regs[15] - (isthumb ? 4u : 8u); // handle prefetch
Tracer.Put(new(
disassembly: string.Format("{0:x8}", pc).PadRight(12) + Marshal.PtrToStringAnsi(disasm).PadRight(36),
disassembly: string.Format("{0:x8}: {1:x8} ", opaddr, opcode).PadRight(12) + Marshal.PtrToStringAnsi(disasm).PadRight(36),
registerInfo: string.Format(
"r0:{0:x8} r1:{1:x8} r2:{2:x8} r3:{3:x8} r4:{4:x8} r5:{5:x8} r6:{6:x8} r7:{7:x8} r8:{8:x8} r9:{9:x8} r10:{10:x8} r11:{11:x8} r12:{12:x8} r13:{13:x8} r14:{14:x8} r15:{15:x8} Cy:{16} {17}",
"r0:{0:x8} r1:{1:x8} r2:{2:x8} r3:{3:x8} r4:{4:x8} r5:{5:x8} r6:{6:x8} r7:{7:x8} r8:{8:x8} r9:{9:x8} r10:{10:x8} r11:{11:x8} r12:{12:x8} SP:{13:x8} LR:{14:x8} PC:{15:x8} Cy:{16} {17}",
regs[0],
regs[1],
regs[2],

View File

@ -216,7 +216,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS
_disassembler = new(_core);
_serviceProvider.Register<IDisassemblable>(_disassembler);
const string TRACE_HEADER = "ARM9+ARM7: PC, opcode, registers (r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, Cy, CpuMode)";
const string TRACE_HEADER = "ARM9+ARM7: Opcode address, opcode, registers (r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, SP, LR, PC, Cy, CpuMode)";
Tracer = new TraceBuffer(TRACE_HEADER);
_serviceProvider.Register(Tracer);
}
@ -365,6 +365,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS
{
_core.ResetCaches();
SetMemoryCallbacks();
_core.SetThreadStartCallback(_threadstartcb);
if (_frameThreadPtr != _core.GetFrameThreadProc())
{
throw new InvalidOperationException("_frameThreadPtr mismatch");

View File

@ -471,7 +471,7 @@ EXPORT void SetMemoryCallback(u32 which, void (*callback)(u32 addr))
}
TraceMask_t TraceMask = TRACE_NONE;
static void (*TraceCallback)(TraceMask_t, u32*, char*, u32) = nullptr;
static void (*TraceCallback)(TraceMask_t, u32, u32*, char*, u32) = nullptr;
#define TRACE_STRING_LENGTH 80
typedef enum {
ARMv4T, //ARM v4, THUMB v1
@ -492,10 +492,10 @@ void TraceTrampoline(TraceMask_t type, u32* regs, u32 opcode)
case TRACE_ARM9_ARM: Disassemble_arm(opcode, disasm, ARMv5TE); break;
default: __builtin_unreachable();
}
TraceCallback(type, regs, disasm, NDS::GetSysClockCycles(2));
TraceCallback(type, opcode, regs, disasm, NDS::GetSysClockCycles(2));
}
EXPORT void SetTraceCallback(void (*callback)(TraceMask_t mask, u32* regs, char* disasm, u32 cyclesOff), TraceMask_t mask)
EXPORT void SetTraceCallback(void (*callback)(TraceMask_t mask, u32 opcode, u32* regs, char* disasm, u32 cyclesOff), TraceMask_t mask)
{
TraceCallback = callback;
TraceMask = callback ? mask : TRACE_NONE;

@ -1 +1 @@
Subproject commit c9e835f87408ba9b00708941fc07e541eedcb3ec
Subproject commit 8dae55983080b7dfc7be346892da9963d1645dca