From e7fb5f001eb42f8c99189d146bb16021f32577a3 Mon Sep 17 00:00:00 2001 From: Chris Moeller Date: Sat, 21 Feb 2015 00:55:46 -0800 Subject: [PATCH] Added debugging traces to lazyusf --- .../lazyusf/lazyusf.xcodeproj/project.pbxproj | 39 +++++++++++++++++++ Frameworks/lazyusf/lazyusf/audio.c | 4 ++ Frameworks/lazyusf/lazyusf/cpu.c | 16 +++++++- Frameworks/lazyusf/lazyusf/exception.c | 11 ++++++ Frameworks/lazyusf/lazyusf/interpreter_cpu.c | 18 ++++++++- 5 files changed, 85 insertions(+), 3 deletions(-) diff --git a/Frameworks/lazyusf/lazyusf.xcodeproj/project.pbxproj b/Frameworks/lazyusf/lazyusf.xcodeproj/project.pbxproj index 2aeb39b70..1f8cfb0a3 100644 --- a/Frameworks/lazyusf/lazyusf.xcodeproj/project.pbxproj +++ b/Frameworks/lazyusf/lazyusf.xcodeproj/project.pbxproj @@ -112,6 +112,11 @@ 83C8B6F818AF58090071B040 /* usf_internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 83C8B6A818AF58080071B040 /* usf_internal.h */; }; 83C8B6F918AF58090071B040 /* usf.c in Sources */ = {isa = PBXBuildFile; fileRef = 83C8B6A918AF58080071B040 /* usf.c */; }; 83C8B6FA18AF58090071B040 /* usf.h in Headers */ = {isa = PBXBuildFile; fileRef = 83C8B6AA18AF58080071B040 /* usf.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 83CA14741A987E91005E7ED4 /* preproc.h in Headers */ = {isa = PBXBuildFile; fileRef = 83CA146E1A987E91005E7ED4 /* preproc.h */; }; + 83CA14751A987E91005E7ED4 /* dbg_decoder.c in Sources */ = {isa = PBXBuildFile; fileRef = 83CA14701A987E91005E7ED4 /* dbg_decoder.c */; }; + 83CA14761A987E91005E7ED4 /* dbg_decoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 83CA14711A987E91005E7ED4 /* dbg_decoder.h */; }; + 83CA14771A987E91005E7ED4 /* dbg_decoder_local.h in Headers */ = {isa = PBXBuildFile; fileRef = 83CA14721A987E91005E7ED4 /* dbg_decoder_local.h */; }; + 83CA14781A987E91005E7ED4 /* dbg_types.h in Headers */ = {isa = PBXBuildFile; fileRef = 83CA14731A987E91005E7ED4 /* dbg_types.h */; }; 83FBECBA18ECE86B00311448 /* ucodes.h in Headers */ = {isa = PBXBuildFile; fileRef = 83FBECB918ECE86B00311448 /* ucodes.h */; }; /* End PBXBuildFile section */ @@ -223,6 +228,11 @@ 83C8B6A918AF58080071B040 /* usf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = usf.c; sourceTree = ""; }; 83C8B6AA18AF58080071B040 /* usf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = usf.h; sourceTree = ""; }; 83C8B6FD18AF59E70071B040 /* lazyusf-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "lazyusf-Info.plist"; sourceTree = ""; }; + 83CA146E1A987E91005E7ED4 /* preproc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = preproc.h; sourceTree = ""; }; + 83CA14701A987E91005E7ED4 /* dbg_decoder.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = dbg_decoder.c; sourceTree = ""; }; + 83CA14711A987E91005E7ED4 /* dbg_decoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dbg_decoder.h; sourceTree = ""; }; + 83CA14721A987E91005E7ED4 /* dbg_decoder_local.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dbg_decoder_local.h; sourceTree = ""; }; + 83CA14731A987E91005E7ED4 /* dbg_types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dbg_types.h; sourceTree = ""; }; 83FBECB918ECE86B00311448 /* ucodes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ucodes.h; sourceTree = ""; }; /* End PBXFileReference section */ @@ -299,6 +309,8 @@ 83C8B62B18AF57770071B040 /* lazyusf */ = { isa = PBXGroup; children = ( + 83CA146D1A987E91005E7ED4 /* osal */, + 83CA146F1A987E91005E7ED4 /* debugger */, 8319EF1F1A219BE7009DD5C4 /* audiolib.c */, 8319EF201A219BE7009DD5C4 /* audiolib.h */, 8319EF1B1A2198B9009DD5C4 /* os.c */, @@ -415,6 +427,25 @@ path = vu; sourceTree = ""; }; + 83CA146D1A987E91005E7ED4 /* osal */ = { + isa = PBXGroup; + children = ( + 83CA146E1A987E91005E7ED4 /* preproc.h */, + ); + path = osal; + sourceTree = ""; + }; + 83CA146F1A987E91005E7ED4 /* debugger */ = { + isa = PBXGroup; + children = ( + 83CA14701A987E91005E7ED4 /* dbg_decoder.c */, + 83CA14711A987E91005E7ED4 /* dbg_decoder.h */, + 83CA14721A987E91005E7ED4 /* dbg_decoder_local.h */, + 83CA14731A987E91005E7ED4 /* dbg_types.h */, + ); + path = debugger; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -426,6 +457,7 @@ 83C8B6AC18AF58080071B040 /* audio.h in Headers */, 837841C118C847B2002C4FE5 /* audio.h in Headers */, 83C8B6B118AF58080071B040 /* dma.h in Headers */, + 83CA14781A987E91005E7ED4 /* dbg_types.h in Headers */, 83A2249518CAC28500FE4173 /* hle.h in Headers */, 83C8B6AD18AF58080071B040 /* config.h in Headers */, 83A2249318CAC28500FE4173 /* hle_internal.h in Headers */, @@ -435,6 +467,7 @@ 8378417018C6E56B002C4FE5 /* arithmetics.h in Headers */, 8319EF221A219BE7009DD5C4 /* audiolib.h in Headers */, 83C8B6C018AF58080071B040 /* registers.h in Headers */, + 83CA14741A987E91005E7ED4 /* preproc.h in Headers */, 83C8B6BE18AF58080071B040 /* pif.h in Headers */, 83C8B6F618AF58090071B040 /* tlb.h in Headers */, 83C8B6F718AF58090071B040 /* types.h in Headers */, @@ -442,6 +475,7 @@ 8319EF1E1A2198B9009DD5C4 /* os.h in Headers */, 83C8B6BC18AF58080071B040 /* opcode.h in Headers */, 83C8B6B718AF58080071B040 /* interpreter_ops.h in Headers */, + 83CA14761A987E91005E7ED4 /* dbg_decoder.h in Headers */, 83C8B6B318AF58080071B040 /* exception.h in Headers */, 83C8B6AF18AF58080071B040 /* cpu.h in Headers */, 83C8B6F118AF58090071B040 /* vsubc.h in Headers */, @@ -461,6 +495,7 @@ 83C8B6D218AF58080071B040 /* vge.h in Headers */, 83C8B6C518AF58080071B040 /* su.h in Headers */, 83C8B6C218AF58080071B040 /* execute.h in Headers */, + 83CA14771A987E91005E7ED4 /* dbg_decoder_local.h in Headers */, 83C8B6E518AF58080071B040 /* vnop.h in Headers */, 83C8B6E418AF58080071B040 /* vne.h in Headers */, 83C8B6D418AF58080071B040 /* vmacf.h in Headers */, @@ -584,6 +619,7 @@ 8378416A18C6E56B002C4FE5 /* alist.c in Sources */, 83C8B6AE18AF58080071B040 /* cpu.c in Sources */, 83C8B6AB18AF58080071B040 /* audio.c in Sources */, + 83CA14751A987E91005E7ED4 /* dbg_decoder.c in Sources */, 83A2249418CAC28500FE4173 /* hle.c in Sources */, 8319EF191A219846009DD5C4 /* cpu_hle.c in Sources */, 8319EF1D1A2198B9009DD5C4 /* os.c in Sources */, @@ -676,6 +712,7 @@ FRAMEWORK_VERSION = A; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", + DEBUG_INFO, ARCH_MIN_SSE2, ); GCC_WARN_PEDANTIC = YES; @@ -683,6 +720,7 @@ INSTALL_PATH = "@loader_path/../Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + USER_HEADER_SEARCH_PATHS = lazyusf; WRAPPER_EXTENSION = framework; }; name = Debug; @@ -704,6 +742,7 @@ INSTALL_PATH = "@loader_path/../Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + USER_HEADER_SEARCH_PATHS = lazyusf; WRAPPER_EXTENSION = framework; }; name = Release; diff --git a/Frameworks/lazyusf/lazyusf/audio.c b/Frameworks/lazyusf/lazyusf/audio.c index 1ce16813d..d3ba00a3b 100644 --- a/Frameworks/lazyusf/lazyusf/audio.c +++ b/Frameworks/lazyusf/lazyusf/audio.c @@ -53,6 +53,10 @@ void AiLenChanged(usf_state_t * state) { uint32_t address = (AI_DRAM_ADDR_REG & 0x00FFFFF8); length = AI_LEN_REG & 0x3FFF8; + +#ifdef DEBUG_INFO + fprintf(stderr, "Audio buffer queued from %08x for %d bytes\n", AI_DRAM_ADDR_REG, length); +#endif AddBuffer(state, state->RDRAM+address, length); diff --git a/Frameworks/lazyusf/lazyusf/cpu.c b/Frameworks/lazyusf/lazyusf/cpu.c index 3855775f9..09da38a4a 100644 --- a/Frameworks/lazyusf/lazyusf/cpu.c +++ b/Frameworks/lazyusf/lazyusf/cpu.c @@ -524,6 +524,9 @@ void RefreshScreen (usf_state_t * state){ } void RunRsp (usf_state_t * state) { +#ifdef DEBUG_INFO + fprintf(stderr, "RSP Task:"); +#endif if ( ( SP_STATUS_REG & SP_STATUS_HALT ) == 0) { if ( ( SP_STATUS_REG & SP_STATUS_BROKE ) == 0 ) { @@ -536,6 +539,10 @@ void RunRsp (usf_state_t * state) { SP_STATUS_REG |= (0x0203 ); if ((SP_STATUS_REG & SP_STATUS_INTR_BREAK) != 0 ) MI_INTR_REG |= 1; + +#ifdef DEBUG_INFO + fprintf(stderr, " DList - interrupts %d\n", MI_INTR_REG); +#endif CheckInterrupts(state); @@ -545,7 +552,7 @@ void RunRsp (usf_state_t * state) { } break; case 2: { - + fprintf(stderr, " AList"); break; } break; @@ -557,10 +564,15 @@ void RunRsp (usf_state_t * state) { real_run_rsp(state, 100); SP_STATUS_REG |= (0x0203 ); if ((SP_STATUS_REG & SP_STATUS_INTR_BREAK) != 0 ) { +#ifdef DEBUG_INFO + fprintf(stderr, " - interrupt"); +#endif MI_INTR_REG |= 1; CheckInterrupts(state); } - +#ifdef DEBUG_INFO + fprintf(stderr, "\n"); +#endif } } } diff --git a/Frameworks/lazyusf/lazyusf/exception.c b/Frameworks/lazyusf/lazyusf/exception.c index 01eaf9bb7..502fc7b22 100644 --- a/Frameworks/lazyusf/lazyusf/exception.c +++ b/Frameworks/lazyusf/lazyusf/exception.c @@ -33,9 +33,20 @@ void CheckInterrupts ( usf_state_t * state ) { MI_INTR_REG &= ~MI_INTR_AI; MI_INTR_REG |= (state->AudioIntrReg & MI_INTR_AI); +#ifdef DEBUG_INFO + if (MI_INTR_REG) + fprintf(stderr, "Interrupt %d - ", MI_INTR_REG); +#endif if ((MI_INTR_MASK_REG & MI_INTR_REG) != 0) { +#ifdef DEBUG_INFO + fprintf(stderr, "triggered\n"); +#endif FAKE_CAUSE_REGISTER |= CAUSE_IP2; } else { +#ifdef DEBUG_INFO + if (MI_INTR_REG) + fprintf(stderr, "masked\n"); +#endif FAKE_CAUSE_REGISTER &= ~CAUSE_IP2; } diff --git a/Frameworks/lazyusf/lazyusf/interpreter_cpu.c b/Frameworks/lazyusf/lazyusf/interpreter_cpu.c index 3f7ee2990..a1f76410e 100644 --- a/Frameworks/lazyusf/lazyusf/interpreter_cpu.c +++ b/Frameworks/lazyusf/lazyusf/interpreter_cpu.c @@ -703,6 +703,10 @@ void RunFunction(usf_state_t * state, uint32_t address) { state->NextInstruction = la; } +#ifdef DEBUG_INFO +#include "debugger/dbg_decoder.h" +#endif + void ExecuteInterpreterOpCode (usf_state_t * state) { @@ -713,6 +717,18 @@ void ExecuteInterpreterOpCode (usf_state_t * state) { state->NextInstruction = NORMAL; return; } + +#ifdef DEBUG_INFO + { + static const char filler[] = " "; + char opcode[256]; + char arguments[256]; + r4300_decode_op(state->Opcode.u.Hex, opcode, arguments, state->PROGRAM_COUNTER); + strcat(opcode, filler); + opcode[16] = '\0'; + fprintf(stderr, "%08x: %s %s\n", state->PROGRAM_COUNTER, opcode, arguments); + } +#endif COUNT_REGISTER += 2; state->Timers->Timer -= 2; @@ -737,7 +753,7 @@ void ExecuteInterpreterOpCode (usf_state_t * state) { state->PROGRAM_COUNTER += 4; break; case JUMP: - if (state->cpu_hle_entry_count && + if (0 && state->cpu_hle_entry_count && DoCPUHLE(state, state->JumpToLocation)) { state->PROGRAM_COUNTER = state->GPR[31].UW[0]; state->NextInstruction = NORMAL;