diff --git a/Source/Project64-core/N64System/Recompiler/RecompilerClass.cpp b/Source/Project64-core/N64System/Recompiler/RecompilerClass.cpp index 37f54c463..5dddd391d 100644 --- a/Source/Project64-core/N64System/Recompiler/RecompilerClass.cpp +++ b/Source/Project64-core/N64System/Recompiler/RecompilerClass.cpp @@ -55,7 +55,7 @@ void CRecompiler::Run() m_EndEmulation = false; #ifdef legacycode - *g_MemoryStack = (uint32_t)(RDRAM+(_GPR[29].W[0] & 0x1FFFFFFF)); + *g_MemoryStack = (uint32_t)(RDRAM + (_GPR[29].W[0] & 0x1FFFFFFF)); #endif __except_try() { @@ -137,7 +137,7 @@ void CRecompiler::RecompilerMain_VirtualTable() continue; } } - CCompiledFunc * info = CompilerCode(); + CCompiledFunc * info = CompileCode(); if (info == NULL || m_EndEmulation) { break; @@ -250,7 +250,7 @@ void CRecompiler::RecompilerMain_VirtualTable_validate() } } #endif - CCompiledFunc * info = CompilerCode(); + CCompiledFunc * info = CompileCode(); if (info == NULL || EndEmulation()) { @@ -310,7 +310,7 @@ void CRecompiler::RecompilerMain_VirtualTable_validate() //Find Block on hash table if (Info == NULL) { - Info = CompilerCode(); + Info = CompileCode(); if (Info == NULL || EndEmulation()) { @@ -347,7 +347,7 @@ void CRecompiler::RecompilerMain_Lookup() CCompiledFunc * info = JumpTable()[PhysicalAddr >> 2]; if (info == NULL) { - info = CompilerCode(); + info = CompileCode(); if (info == NULL || m_EndEmulation) { break; @@ -477,7 +477,7 @@ void CRecompiler::RecompilerMain_Lookup() if (Info == NULL) { - Info = CompilerCode(); + Info = CompileCode(); if (Info == NULL || EndEmulation()) { @@ -551,7 +551,7 @@ void CRecompiler::RecompilerMain_Lookup_TLB() if (info == NULL) { - info = CompilerCode(); + info = CompileCode(); if (info == NULL || m_EndEmulation) { break; @@ -593,7 +593,7 @@ void CRecompiler::RecompilerMain_Lookup_validate() CCompiledFunc * info = JumpTable()[PhysicalAddr >> 2]; if (info == NULL) { - info = CompilerCode(); + info = CompileCode(); if (info == NULL || m_EndEmulation) { break; @@ -637,18 +637,21 @@ void CRecompiler::RecompilerMain_Lookup_validate() void CRecompiler::RecompilerMain_Lookup_validate_TLB() { - WriteTrace(TraceRecompiler, TraceDebug, "Start"); + WriteTrace(TraceRecompiler, TraceInfo, "Start"); + bool & Done = m_EndEmulation; + uint32_t & PC = PROGRAM_COUNTER; + uint32_t PhysicalAddr; - while (!m_EndEmulation) + while (!Done) { - if (!g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr)) + if (!g_TransVaddr->TranslateVaddr(PC, PhysicalAddr)) { - m_Registers.DoTLBReadMiss(false, PROGRAM_COUNTER); - if (!g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr)) + m_Registers.DoTLBReadMiss(false, PC); + if (!g_TransVaddr->TranslateVaddr(PC, PhysicalAddr)) { - g_Notify->DisplayError(stdstr_f("Failed to translate PC to a PAddr: %X\n\nEmulation stopped", PROGRAM_COUNTER).c_str()); - m_EndEmulation = true; + g_Notify->DisplayError(stdstr_f("Failed to translate PC to a PAddr: %X\n\nEmulation stopped", PC).c_str()); + Done = true; } continue; } @@ -658,14 +661,14 @@ void CRecompiler::RecompilerMain_Lookup_validate_TLB() if (info == NULL) { - info = CompilerCode(); + info = CompileCode(); if (info == NULL || m_EndEmulation) { break; } if (g_System->bSMM_Protect()) { - g_MMU->ProtectMemory(PROGRAM_COUNTER & ~0xFFF, PROGRAM_COUNTER | 0xFFF); + g_MMU->ProtectMemory(PC & ~0xFFF, PC | 0xFFF); } JumpTable()[PhysicalAddr >> 2] = info; } @@ -697,7 +700,7 @@ void CRecompiler::RecompilerMain_Lookup_validate_TLB() { uint32_t opsExecuted = 0; - while (g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr) && PhysicalAddr >= g_System->RdramSize()) + while (g_TransVaddr->TranslateVaddr(PC, PhysicalAddr) && PhysicalAddr >= g_System->RdramSize()) { CInterpreterCPU::ExecuteOps(g_System->CountPerOp()); opsExecuted += g_System->CountPerOp(); @@ -745,21 +748,23 @@ void CRecompiler::RecompilerMain_ChangeMemory() uint32_t Value, Addr; uint8_t * Block; - while(!EndEmulation()) + while (!EndEmulation()) { if (UseTlb) { if (!TranslateVaddr(PROGRAM_COUNTER, &Addr)) { - DoTLBMiss(NextInstruction == DELAY_SLOT,PROGRAM_COUNTER); + DoTLBMiss(NextInstruction == DELAY_SLOT, PROGRAM_COUNTER); NextInstruction = NORMAL; if (!TranslateVaddr(PROGRAM_COUNTER, &Addr)) { - g_Notify->DisplayError("Failed to translate PC to a PAddr: %X\n\nEmulation stopped",PROGRAM_COUNTER); + g_Notify->DisplayError("Failed to translate PC to a PAddr: %X\n\nEmulation stopped", PROGRAM_COUNTER); ExitThread(0); } } - } else { + } + else + { Addr = PROGRAM_COUNTER & 0x1FFFFFFF; } @@ -769,12 +774,12 @@ void CRecompiler::RecompilerMain_ChangeMemory() { Value = (uint32_t)(*(DelaySlotTable + (Addr >> 12))); } - __except(EXCEPTION_EXECUTE_HANDLER) + __except (EXCEPTION_EXECUTE_HANDLER) { - g_Notify->DisplayError("Executing Delay Slot from non maped space\nPROGRAM_COUNTER = 0x%X",PROGRAM_COUNTER); + g_Notify->DisplayError("Executing Delay Slot from non maped space\nPROGRAM_COUNTER = 0x%X", PROGRAM_COUNTER); ExitThread(0); } - if ( (Value >> 16) == 0x7C7C) + if ((Value >> 16) == 0x7C7C) { uint32_t Index = (Value & 0xFFFF); Block = (uint8_t *)OrigMem[Index].CompiledLocation; @@ -794,7 +799,7 @@ void CRecompiler::RecompilerMain_ChangeMemory() Value = 0x7C7C0000; Value += (uint16_t)(TargetIndex); MemValue = *(uint32_t *)(RDRAM + Addr); - if ( (MemValue >> 16) == 0x7C7C) + if ((MemValue >> 16) == 0x7C7C) { MemValue = OrigMem[(MemValue & 0xFFFF)].OriginalValue; } @@ -818,7 +823,7 @@ void CRecompiler::RecompilerMain_ChangeMemory() __try { Value = *(uint32_t *)(RDRAM + Addr); - if ( (Value >> 16) == 0x7C7C) + if ((Value >> 16) == 0x7C7C) { uint32_t Index = (Value & 0xFFFF); Block = (uint8_t *)OrigMem[Index].CompiledLocation; @@ -831,7 +836,7 @@ void CRecompiler::RecompilerMain_ChangeMemory() Block = NULL; } } - __except(EXCEPTION_EXECUTE_HANDLER) + __except (EXCEPTION_EXECUTE_HANDLER) { g_Notify->DisplayError(GS(MSG_NONMAPPED_SPACE)); ExitThread(0); @@ -845,7 +850,7 @@ void CRecompiler::RecompilerMain_ChangeMemory() { Block = Compiler4300iBlock(); } - __except(EXCEPTION_EXECUTE_HANDLER) + __except (EXCEPTION_EXECUTE_HANDLER) { ResetRecompCode(); Block = Compiler4300iBlock(); @@ -862,7 +867,7 @@ void CRecompiler::RecompilerMain_ChangeMemory() Value = 0x7C7C0000; Value += (uint16_t)(TargetIndex); MemValue = *(uint32_t *)(RDRAM + Addr); - if ( (MemValue >> 16) == 0x7C7C) + if ((MemValue >> 16) == 0x7C7C) { MemValue = OrigMem[(MemValue & 0xFFFF)].OriginalValue; } @@ -905,8 +910,10 @@ void CRecompiler::RecompilerMain_ChangeMemory() #endif } -CCompiledFunc * CRecompiler::CompilerCode() +CCompiledFunc * CRecompiler::CompileCode() { + WriteTrace(TraceRecompiler, TraceDebug, "Start (PC: %X)", PROGRAM_COUNTER); + uint32_t pAddr = 0; if (!g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, pAddr)) { @@ -917,6 +924,7 @@ CCompiledFunc * CRecompiler::CompilerCode() CCompiledFuncList::iterator iter = m_Functions.find(PROGRAM_COUNTER); if (iter != m_Functions.end()) { + WriteTrace(TraceRecompiler, TraceDebug, "exisiting functions for address"); for (CCompiledFunc * Func = iter->second; Func != NULL; Func = Func->Next()) { uint32_t PAddr; @@ -926,6 +934,7 @@ CCompiledFunc * CRecompiler::CompilerCode() MD5(g_MMU->Rdram() + PAddr, (Func->MaxPC() - Func->MinPC()) + 4).get_digest(Hash); if (memcmp(Hash.digest, Func->Hash().digest, sizeof(Hash.digest)) == 0) { + WriteTrace(TraceRecompiler, TraceDebug, "Using extisting compiled code"); return Func; } } @@ -935,7 +944,7 @@ CCompiledFunc * CRecompiler::CompilerCode() CheckRecompMem(); //uint32_t StartTime = timeGetTime(); - WriteTrace(TraceRecompiler, TraceDebug, ": Compile Block-Start: Program Counter: %X pAddr: %X", PROGRAM_COUNTER, pAddr); + WriteTrace(TraceRecompiler, TraceDebug, "Compile Block-Start: Program Counter: %X pAddr: %X", PROGRAM_COUNTER, pAddr); CCodeBlock CodeBlock(PROGRAM_COUNTER, *g_RecompPos); if (!CodeBlock.Compile()) @@ -955,6 +964,31 @@ CCompiledFunc * CRecompiler::CompilerCode() Func->SetNext(ret.first->second->Next()); ret.first->second->SetNext(Func); } + + if (g_ModuleLogLevel[TraceRecompiler] >= TraceDebug) + { + WriteTrace(TraceRecompiler, TraceDebug, "info->Function() = %X", Func->Function()); + std::string dumpline; + uint32_t start_address = (uint32_t)(Func->Function()) & ~1; + for (uint8_t * ptr = (uint8_t *)start_address; ptr < (uint8_t *)*g_RecompPos; ptr++) + { + if (dumpline.empty()) + { + dumpline += stdstr_f("%X: ", ptr); + } + dumpline += stdstr_f(" %02X", *ptr); + if ((((uint32_t)ptr - start_address) + 1) % 30 == 0) + { + WriteTrace(TraceRecompiler, TraceDebug, "%s", dumpline.c_str()); + dumpline.clear(); + } + } + + if (!dumpline.empty()) + { + WriteTrace(TraceRecompiler, TraceDebug, "%s", dumpline.c_str()); + } + } WriteTrace(TraceRecompiler, TraceVerbose, "Done"); return Func; } diff --git a/Source/Project64-core/N64System/Recompiler/RecompilerClass.h b/Source/Project64-core/N64System/Recompiler/RecompilerClass.h index b5cd58897..8abe1fd27 100644 --- a/Source/Project64-core/N64System/Recompiler/RecompilerClass.h +++ b/Source/Project64-core/N64System/Recompiler/RecompilerClass.h @@ -60,7 +60,7 @@ private: CRecompiler(const CRecompiler&); // Disable copy constructor CRecompiler& operator=(const CRecompiler&); // Disable assignment - CCompiledFunc * CompilerCode(); + CCompiledFunc * CompileCode(); // Main loops for the different look up methods void RecompilerMain_VirtualTable();