diff --git a/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp b/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp index 3a85171c6..95e98e7fa 100644 --- a/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp +++ b/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp @@ -27,6 +27,7 @@ const int32_t R4300iOp::LWR_SHIFT[4] = {24, 16, 8, 0}; R4300iOp::R4300iOp(CN64System & System) : m_System(System), m_Reg(System.m_Reg), + m_TLB(System.m_TLB), m_MMU(System.m_MMU_VM), m_PROGRAM_COUNTER(System.m_Reg.m_PROGRAM_COUNTER), m_GPR(System.m_Reg.m_GPR), @@ -1462,7 +1463,7 @@ void R4300iOp::LL() m_LLBit = 1; uint32_t PhysicalAddr; bool MemoryUsed; - g_TLB->VAddrToPAddr(Address, PhysicalAddr, MemoryUsed); + m_TLB.VAddrToPAddr(Address, PhysicalAddr, MemoryUsed); m_CP0[17] = PhysicalAddr >> 4; } } @@ -1508,7 +1509,7 @@ void R4300iOp::LLD() m_LLBit = 1; uint32_t PhysicalAddr; bool MemoryUsed; - g_TLB->VAddrToPAddr(Address, PhysicalAddr, MemoryUsed); + m_TLB.VAddrToPAddr(Address, PhysicalAddr, MemoryUsed); m_CP0[17] = PhysicalAddr >> 4; } } @@ -2133,22 +2134,22 @@ void R4300iOp::COP0_DMT() void R4300iOp::COP0_CO_TLBR() { - g_TLB->ReadEntry(); + m_TLB.ReadEntry(); } void R4300iOp::COP0_CO_TLBWI() { - g_TLB->WriteEntry(m_Reg.INDEX_REGISTER & 0x1F, false); + m_TLB.WriteEntry(m_Reg.INDEX_REGISTER & 0x1F, false); } void R4300iOp::COP0_CO_TLBWR() { - g_TLB->WriteEntry(m_Reg.RANDOM_REGISTER & 0x1F, true); + m_TLB.WriteEntry(m_Reg.RANDOM_REGISTER & 0x1F, true); } void R4300iOp::COP0_CO_TLBP() { - g_TLB->Probe(); + m_TLB.Probe(); } void R4300iOp::COP0_CO_ERET() diff --git a/Source/Project64-core/N64System/Interpreter/InterpreterOps.h b/Source/Project64-core/N64System/Interpreter/InterpreterOps.h index 06d3fdc13..6a56f7124 100644 --- a/Source/Project64-core/N64System/Interpreter/InterpreterOps.h +++ b/Source/Project64-core/N64System/Interpreter/InterpreterOps.h @@ -260,6 +260,7 @@ private: CN64System & m_System; CRegisters & m_Reg; + CTLB & m_TLB; CMipsMemoryVM & m_MMU; R4300iOpcode m_Opcode; uint32_t & m_PROGRAM_COUNTER; diff --git a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp index e78d6db66..aa4ae4821 100755 --- a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp +++ b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp @@ -19,6 +19,7 @@ uint32_t CMipsMemoryVM::RegModValue; CMipsMemoryVM::CMipsMemoryVM(CN64System & System, bool SavesReadOnly) : m_System(System), m_Reg(System.m_Reg), + m_TLB(System.m_TLB), m_AudioInterfaceHandler(System, System.m_Reg), m_CartridgeDomain1Address1Handler(System.m_Reg, g_DDRom), m_CartridgeDomain2Address1Handler(System.m_Reg), @@ -368,7 +369,7 @@ bool CMipsMemoryVM::LB_Memory(uint64_t VAddr, uint8_t & Value) { uint32_t PAddr; bool MemoryUnused; - if (!g_TLB->VAddrToPAddr(VAddr, PAddr, MemoryUnused)) + if (!m_TLB.VAddrToPAddr(VAddr, PAddr, MemoryUnused)) { m_Reg.TriggerAddressException(VAddr, MemoryUnused ? EXC_RADE : EXC_RMISS); return false; @@ -400,7 +401,7 @@ bool CMipsMemoryVM::LH_Memory(uint64_t VAddr, uint16_t & Value) { uint32_t PAddr; bool MemoryUnused; - if (!g_TLB->VAddrToPAddr(VAddr, PAddr, MemoryUnused)) + if (!m_TLB.VAddrToPAddr(VAddr, PAddr, MemoryUnused)) { m_Reg.TriggerAddressException(VAddr, MemoryUnused ? EXC_RADE : EXC_RMISS); return false; @@ -432,7 +433,7 @@ bool CMipsMemoryVM::LW_Memory(uint64_t VAddr, uint32_t & Value) { uint32_t PAddr; bool MemoryUnused; - if (!g_TLB->VAddrToPAddr(VAddr, PAddr, MemoryUnused)) + if (!m_TLB.VAddrToPAddr(VAddr, PAddr, MemoryUnused)) { m_Reg.TriggerAddressException(VAddr, MemoryUnused ? EXC_RADE : EXC_RMISS); return false; @@ -464,7 +465,7 @@ bool CMipsMemoryVM::LD_Memory(uint64_t VAddr, uint64_t & Value) { uint32_t PAddr; bool MemoryUnused; - if (!g_TLB->VAddrToPAddr(VAddr, PAddr, MemoryUnused)) + if (!m_TLB.VAddrToPAddr(VAddr, PAddr, MemoryUnused)) { m_Reg.TriggerAddressException(VAddr, MemoryUnused ? EXC_RADE : EXC_RMISS); return false; @@ -492,7 +493,7 @@ bool CMipsMemoryVM::SB_Memory(uint64_t VAddr, uint32_t Value) { uint32_t PAddr; bool MemoryUnused; - if (!g_TLB->VAddrToPAddr(VAddr, PAddr, MemoryUnused)) + if (!m_TLB.VAddrToPAddr(VAddr, PAddr, MemoryUnused)) { m_Reg.TriggerAddressException(VAddr, MemoryUnused ? EXC_WADE : EXC_WMISS); return false; @@ -524,7 +525,7 @@ bool CMipsMemoryVM::SH_Memory(uint64_t VAddr, uint32_t Value) { uint32_t PAddr; bool MemoryUnused; - if (!g_TLB->VAddrToPAddr(VAddr, PAddr, MemoryUnused)) + if (!m_TLB.VAddrToPAddr(VAddr, PAddr, MemoryUnused)) { m_Reg.TriggerAddressException(VAddr, MemoryUnused ? EXC_WADE : EXC_WMISS); return false; @@ -556,7 +557,7 @@ bool CMipsMemoryVM::SW_Memory(uint64_t VAddr, uint32_t Value) { uint32_t PAddr; bool MemoryUnused; - if (!g_TLB->VAddrToPAddr(VAddr, PAddr, MemoryUnused)) + if (!m_TLB.VAddrToPAddr(VAddr, PAddr, MemoryUnused)) { m_Reg.TriggerAddressException(VAddr, MemoryUnused ? EXC_WADE : EXC_WMISS); return false; @@ -588,7 +589,7 @@ bool CMipsMemoryVM::SD_Memory(uint64_t VAddr, uint64_t Value) { uint32_t PAddr; bool MemoryUnused; - if (!g_TLB->VAddrToPAddr(VAddr, PAddr, MemoryUnused)) + if (!m_TLB.VAddrToPAddr(VAddr, PAddr, MemoryUnused)) { m_Reg.TriggerAddressException(VAddr, MemoryUnused ? EXC_WADE : EXC_WMISS); return false; diff --git a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h index a47f9cf4d..446ee5684 100644 --- a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h +++ b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h @@ -211,6 +211,7 @@ private: static uint8_t *m_Reserve1, *m_Reserve2; CN64System & m_System; CRegisters & m_Reg; + CTLB & m_TLB; AudioInterfaceHandler m_AudioInterfaceHandler; CartridgeDomain1Address1Handler m_CartridgeDomain1Address1Handler; CartridgeDomain1Address3Handler m_CartridgeDomain1Address3Handler; diff --git a/Source/Project64-core/N64System/N64System.cpp b/Source/Project64-core/N64System/N64System.cpp index 849751547..a3f667cdb 100644 --- a/Source/Project64-core/N64System/N64System.cpp +++ b/Source/Project64-core/N64System/N64System.cpp @@ -899,6 +899,11 @@ void CN64System::ApplyGSButton(void) } } +CTLB & CN64System::TLB() +{ + return m_TLB; +} + void CN64System::Reset(bool bInitReg, bool ClearMenory) { WriteTrace(TraceN64System, TraceDebug, "Start (bInitReg: %s, ClearMenory: %s)", bInitReg ? "true" : "false", ClearMenory ? "true" : "false"); @@ -969,7 +974,6 @@ bool CN64System::SetActiveSystem(bool bActive) } g_Recompiler = m_Recomp; g_MMU = &m_MMU_VM; - g_TLB = &m_TLB; g_Reg = &m_Reg; g_Mempak = &m_Mempak; g_SystemTimer = &m_SystemTimer; @@ -988,7 +992,6 @@ bool CN64System::SetActiveSystem(bool bActive) g_SyncSystem = nullptr; g_Recompiler = nullptr; g_MMU = nullptr; - g_TLB = nullptr; g_Reg = nullptr; g_SystemTimer = nullptr; g_NextTimer = nullptr; diff --git a/Source/Project64-core/N64System/N64System.h b/Source/Project64-core/N64System/N64System.h index 58d29e668..057f239e5 100644 --- a/Source/Project64-core/N64System/N64System.h +++ b/Source/Project64-core/N64System/N64System.h @@ -88,6 +88,7 @@ public: { return m_OpCodes.Opcode(); } + CTLB & TLB(); void Reset(bool bInitReg, bool ClearMenory); void GameReset(); void PluginReset(); diff --git a/Source/Project64-core/N64System/Recompiler/Recompiler.cpp b/Source/Project64-core/N64System/Recompiler/Recompiler.cpp index ca877da32..12bb0da8c 100644 --- a/Source/Project64-core/N64System/Recompiler/Recompiler.cpp +++ b/Source/Project64-core/N64System/Recompiler/Recompiler.cpp @@ -9,6 +9,7 @@ CRecompiler::CRecompiler(CN64System & System, bool & EndEmulation) : m_System(System), m_MMU(System.m_MMU_VM), m_Reg(System.m_Reg), + m_TLB(System.m_TLB), m_EndEmulation(EndEmulation), m_MemoryStack(0), PROGRAM_COUNTER(System.m_Reg.m_PROGRAM_COUNTER), @@ -447,7 +448,7 @@ void CRecompiler::ClearRecompCode_Phys(uint32_t Address, int length, REMOVE_REAS ClearRecompCode_Virt(Address + 0xA0000000, length, Reason); uint32_t VAddr, Index = 0; - while (g_TLB->PAddrToVAddr(Address, VAddr, Index)) + while (m_TLB.PAddrToVAddr(Address, VAddr, Index)) { WriteTrace(TraceRecompiler, TraceInfo, "ClearRecompCode Vaddr %X len: %d", VAddr, length); ClearRecompCode_Virt(VAddr, length, Reason); diff --git a/Source/Project64-core/N64System/Recompiler/Recompiler.h b/Source/Project64-core/N64System/Recompiler/Recompiler.h index e08d8e9d3..bb7c7145f 100644 --- a/Source/Project64-core/N64System/Recompiler/Recompiler.h +++ b/Source/Project64-core/N64System/Recompiler/Recompiler.h @@ -83,6 +83,7 @@ private: CN64System & m_System; CMipsMemoryVM & m_MMU; CRegisters & m_Reg; + CTLB & m_TLB; bool & m_EndEmulation; uint8_t * m_MemoryStack; FUNCTION_PROFILE m_BlockProfile; diff --git a/Source/Project64-core/N64System/Recompiler/RecompilerOps.cpp b/Source/Project64-core/N64System/Recompiler/RecompilerOps.cpp index d08cca76c..fd99c700f 100644 --- a/Source/Project64-core/N64System/Recompiler/RecompilerOps.cpp +++ b/Source/Project64-core/N64System/Recompiler/RecompilerOps.cpp @@ -7,6 +7,7 @@ CRecompilerOpsBase::CRecompilerOpsBase(CN64System & System, CCodeBlock & CodeBlo m_System(System), m_SystemEvents(System.m_SystemEvents), m_Reg(System.m_Reg), + m_TLB(System.m_TLB), m_MMU(System.m_MMU_VM), m_CodeBlock(CodeBlock), m_Section(nullptr) diff --git a/Source/Project64-core/N64System/Recompiler/RecompilerOps.h b/Source/Project64-core/N64System/Recompiler/RecompilerOps.h index 83382e915..5bb266227 100644 --- a/Source/Project64-core/N64System/Recompiler/RecompilerOps.h +++ b/Source/Project64-core/N64System/Recompiler/RecompilerOps.h @@ -43,6 +43,7 @@ class CN64System; class CSystemEvents; class CMipsMemoryVM; class CRegisters; +class CTLB; class CRecompilerOpsBase : protected CDebugSettings @@ -55,6 +56,7 @@ protected: CSystemEvents & m_SystemEvents; CMipsMemoryVM & m_MMU; CRegisters & m_Reg; + CTLB & m_TLB; CCodeBlock & m_CodeBlock; R4300iOpcode m_Opcode; CCodeSection * m_Section; diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp index 5cf2eb8f3..0f9675952 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp +++ b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp @@ -7384,7 +7384,7 @@ void CX86RecompilerOps::COP0_DMT() void CX86RecompilerOps::COP0_CO_TLBR(void) { m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.CallThis((uint32_t)g_TLB, AddressOf(&CTLB::ReadEntry), "CTLB::ReadEntry", 4); + m_Assembler.CallThis((uint32_t)&m_TLB, AddressOf(&CTLB::ReadEntry), "CTLB::ReadEntry", 4); m_RegWorkingSet.AfterCallDirect(); } @@ -7395,7 +7395,7 @@ void CX86RecompilerOps::COP0_CO_TLBWI(void) m_Assembler.MoveVariableToX86reg(asmjit::x86::ecx, &g_Reg->INDEX_REGISTER, "INDEX_REGISTER"); m_Assembler.and_(asmjit::x86::ecx, 0x1F); m_Assembler.push(asmjit::x86::ecx); - m_Assembler.CallThis((uint32_t)g_TLB, AddressOf(&CTLB::WriteEntry), "CTLB::WriteEntry", 12); + m_Assembler.CallThis((uint32_t)&m_TLB, AddressOf(&CTLB::WriteEntry), "CTLB::WriteEntry", 12); m_RegWorkingSet.AfterCallDirect(); } @@ -7408,14 +7408,14 @@ void CX86RecompilerOps::COP0_CO_TLBWR(void) m_Assembler.MoveVariableToX86reg(asmjit::x86::ecx, &g_Reg->RANDOM_REGISTER, "RANDOM_REGISTER"); m_Assembler.and_(asmjit::x86::ecx, 0x1F); m_Assembler.push(asmjit::x86::ecx); - m_Assembler.CallThis((uint32_t)g_TLB, AddressOf(&CTLB::WriteEntry), "CTLB::WriteEntry", 12); + m_Assembler.CallThis((uint32_t)&m_TLB, AddressOf(&CTLB::WriteEntry), "CTLB::WriteEntry", 12); m_RegWorkingSet.AfterCallDirect(); } void CX86RecompilerOps::COP0_CO_TLBP(void) { m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.CallThis((uint32_t)g_TLB, AddressOf(&CTLB::Probe), "CTLB::TLB_Probe", 4); + m_Assembler.CallThis((uint32_t)&m_TLB, AddressOf(&CTLB::Probe), "CTLB::TLB_Probe", 4); m_RegWorkingSet.AfterCallDirect(); } diff --git a/Source/Project64-core/N64System/SystemGlobals.cpp b/Source/Project64-core/N64System/SystemGlobals.cpp index f14eba283..5722018f6 100644 --- a/Source/Project64-core/N64System/SystemGlobals.cpp +++ b/Source/Project64-core/N64System/SystemGlobals.cpp @@ -7,7 +7,6 @@ CN64System * g_BaseSystem = nullptr; CN64System * g_SyncSystem = nullptr; CRecompiler * g_Recompiler = nullptr; CMipsMemoryVM * g_MMU = nullptr; // Memory of the N64 -CTLB * g_TLB = nullptr; // TLB unit CRegisters * g_Reg = nullptr; // Current register set attached to the g_MMU CNotification * g_Notify = nullptr; CPlugins * g_Plugins = nullptr; diff --git a/Source/Project64-core/N64System/SystemGlobals.h b/Source/Project64-core/N64System/SystemGlobals.h index 50d89615d..35f2d6235 100644 --- a/Source/Project64-core/N64System/SystemGlobals.h +++ b/Source/Project64-core/N64System/SystemGlobals.h @@ -14,9 +14,6 @@ extern CRecompiler * g_Recompiler; class CMipsMemoryVM; extern CMipsMemoryVM * g_MMU; // Memory of the N64 -class CTLB; -extern CTLB * g_TLB; // TLB unit - class CRegisters; extern CRegisters * g_Reg; // Current register set attached to the g_MMU diff --git a/Source/Project64/UserInterface/Debugger/Debugger-TLB.cpp b/Source/Project64/UserInterface/Debugger/Debugger-TLB.cpp index 014757a3e..60b57f123 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-TLB.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-TLB.cpp @@ -110,7 +110,7 @@ void CDebugTlb::RefreshTLBWindow(void) LV_ITEM item, OldItem; int count; - TLB_ENTRY * tlb = g_TLB->m_tlb; + TLB_ENTRY * tlb = g_System->TLB().m_tlb; for (count = 0; count < 32; count++) { swprintf(Output, sizeof(Output), L"0x%02X", count); @@ -202,7 +202,7 @@ void CDebugTlb::RefreshTLBWindow(void) } } - CTLB::FASTTLB * FastTlb = g_TLB->m_FastTlb; + CTLB::FASTTLB * FastTlb = g_System->TLB().m_FastTlb; hList = GetDlgItem(IDC_LIST2); for (count = 0; count < 64; count++) {