Skip to content

Commit

Permalink
Core: remove the global of g_TLB
Browse files Browse the repository at this point in the history
  • Loading branch information
project64 committed Dec 14, 2023
1 parent c67f3f0 commit 5fec3f8
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 27 deletions.
13 changes: 7 additions & 6 deletions Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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()
Expand Down
Expand Up @@ -260,6 +260,7 @@ class R4300iOp :

CN64System & m_System;
CRegisters & m_Reg;
CTLB & m_TLB;
CMipsMemoryVM & m_MMU;
R4300iOpcode m_Opcode;
uint32_t & m_PROGRAM_COUNTER;
Expand Down
17 changes: 9 additions & 8 deletions Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Source/Project64-core/N64System/Mips/MemoryVirtualMem.h
Expand Up @@ -211,6 +211,7 @@ class CMipsMemoryVM :
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;
Expand Down
7 changes: 5 additions & 2 deletions Source/Project64-core/N64System/N64System.cpp
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Source/Project64-core/N64System/N64System.h
Expand Up @@ -88,6 +88,7 @@ class CN64System :
{
return m_OpCodes.Opcode();
}
CTLB & TLB();
void Reset(bool bInitReg, bool ClearMenory);
void GameReset();
void PluginReset();
Expand Down
3 changes: 2 additions & 1 deletion Source/Project64-core/N64System/Recompiler/Recompiler.cpp
Expand Up @@ -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),
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions Source/Project64-core/N64System/Recompiler/Recompiler.h
Expand Up @@ -83,6 +83,7 @@ class CRecompiler :
CN64System & m_System;
CMipsMemoryVM & m_MMU;
CRegisters & m_Reg;
CTLB & m_TLB;
bool & m_EndEmulation;
uint8_t * m_MemoryStack;
FUNCTION_PROFILE m_BlockProfile;
Expand Down
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Source/Project64-core/N64System/Recompiler/RecompilerOps.h
Expand Up @@ -43,6 +43,7 @@ class CN64System;
class CSystemEvents;
class CMipsMemoryVM;
class CRegisters;
class CTLB;

class CRecompilerOpsBase :
protected CDebugSettings
Expand All @@ -55,6 +56,7 @@ class CRecompilerOpsBase :
CSystemEvents & m_SystemEvents;
CMipsMemoryVM & m_MMU;
CRegisters & m_Reg;
CTLB & m_TLB;
CCodeBlock & m_CodeBlock;
R4300iOpcode m_Opcode;
CCodeSection * m_Section;
Expand Down
Expand Up @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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();
}

Expand Down
1 change: 0 additions & 1 deletion Source/Project64-core/N64System/SystemGlobals.cpp
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions Source/Project64-core/N64System/SystemGlobals.h
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions Source/Project64/UserInterface/Debugger/Debugger-TLB.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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++)
{
Expand Down

0 comments on commit 5fec3f8

Please sign in to comment.