[Project64] Get TLB class to use standard types

This commit is contained in:
zilmar 2015-11-09 17:21:32 +11:00
parent cfdb5dc8d0
commit 898f1da74d
5 changed files with 382 additions and 379 deletions

View File

@ -12,14 +12,16 @@
class CDebugTlb; class CDebugTlb;
class CTLB_CB __interface CTLB_CB
{ {
public: virtual void TLB_Mapped(uint32_t VAddr, uint32_t Len, uint32_t PAddr, bool bReadOnly) = 0;
virtual void TLB_Mapped(DWORD VAddr, DWORD Len, DWORD PAddr, bool bReadOnly) = 0; virtual void TLB_Unmaped(uint32_t VAddr, uint32_t Len) = 0;
virtual void TLB_Unmaped(DWORD VAddr, DWORD Len) = 0;
virtual void TLB_Changed() = 0; virtual void TLB_Changed() = 0;
}; };
#pragma warning(push)
#pragma warning(disable : 4201) // warning C4201: nonstandard extension used : nameless struct/union
class CTLB : class CTLB :
protected CSystemRegisters protected CSystemRegisters
{ {
@ -29,8 +31,8 @@ public:
bool EntryDefined; bool EntryDefined;
union union
{ {
unsigned long Value; uint32_t Value;
unsigned char A[4]; uint8_t A[4];
struct struct
{ {
@ -38,13 +40,12 @@ public:
unsigned Mask : 12; unsigned Mask : 12;
unsigned zero2 : 7; unsigned zero2 : 7;
} ; } ;
} PageMask; } PageMask;
union union
{ {
unsigned long Value; uint32_t Value;
unsigned char A[4]; uint8_t A[4];
struct struct
{ {
@ -53,13 +54,12 @@ public:
unsigned G : 1; unsigned G : 1;
unsigned VPN2 : 19; unsigned VPN2 : 19;
}; };
} EntryHi; } EntryHi;
union union
{ {
unsigned long Value; uint32_t Value;
unsigned char A[4]; uint8_t A[4];
struct struct
{ {
@ -70,13 +70,12 @@ public:
unsigned PFN : 20; unsigned PFN : 20;
unsigned ZERO: 6; unsigned ZERO: 6;
} ; } ;
} EntryLo0; } EntryLo0;
union union
{ {
unsigned long Value; uint32_t Value;
unsigned char A[4]; uint8_t A[4];
struct struct
{ {
@ -87,7 +86,6 @@ public:
unsigned PFN : 20; unsigned PFN : 20;
unsigned ZERO: 6; unsigned ZERO: 6;
} ; } ;
} EntryLo1; } EntryLo1;
}; };
@ -100,17 +98,17 @@ public:
//Used by opcodes of the same name to manipulate the tlb (reads the registers) //Used by opcodes of the same name to manipulate the tlb (reads the registers)
void Probe(); void Probe();
void ReadEntry(); void ReadEntry();
void WriteEntry(int index, bool Random); void WriteEntry(int32_t index, bool Random);
//See if a VAddr has an entry to translate to a PAddr //See if a VAddr has an entry to translate to a PAddr
bool AddressDefined(DWORD VAddr); bool AddressDefined(uint32_t VAddr);
const TLB_ENTRY & TlbEntry(int Entry) const const TLB_ENTRY & TlbEntry(int32_t Entry) const
{ {
return m_tlb[Entry]; return m_tlb[Entry];
} }
bool PAddrToVAddr(DWORD PAddr, DWORD & VAddr, DWORD & Index); bool PAddrToVAddr(uint32_t PAddr, uint32_t & VAddr, uint32_t & Index);
void RecordDifference(CLog &LogFile, const CTLB& rTLB); void RecordDifference(CLog &LogFile, const CTLB& rTLB);
@ -120,11 +118,11 @@ public:
private: private:
struct FASTTLB struct FASTTLB
{ {
DWORD VSTART; uint32_t VSTART;
DWORD VEND; uint32_t VEND;
DWORD PHYSSTART; uint32_t PHYSSTART;
DWORD PHYSEND; uint32_t PHYSEND;
DWORD Length; uint32_t Length;
bool VALID; bool VALID;
bool DIRTY; bool DIRTY;
bool GLOBAL; bool GLOBAL;
@ -140,5 +138,12 @@ private:
TLB_ENTRY m_tlb[32]; TLB_ENTRY m_tlb[32];
FASTTLB m_FastTlb[64]; FASTTLB m_FastTlb[64];
void SetupTLB_Entry(int index, bool Random); void SetupTLB_Entry(int32_t index, bool Random);
private:
CTLB(); // Disable default constructor
CTLB(const CTLB&); // Disable copy constructor
CTLB& operator=(const CTLB&); // Disable assignment
}; };
#pragma warning(pop)

View File

@ -28,7 +28,7 @@ CTLB::~CTLB()
void CTLB::Reset (bool InvalidateTLB) void CTLB::Reset (bool InvalidateTLB)
{ {
DWORD count; uint32_t count;
for (count = 0; count < 64; count++) for (count = 0; count < 64; count++)
{ {
@ -51,9 +51,9 @@ void CTLB::Reset (bool InvalidateTLB)
} }
} }
bool CTLB::AddressDefined ( DWORD VAddr) bool CTLB::AddressDefined ( uint32_t VAddr)
{ {
DWORD i; uint32_t i;
if (VAddr >= 0x80000000 && VAddr <= 0xBFFFFFFF) if (VAddr >= 0x80000000 && VAddr <= 0xBFFFFFFF)
{ {
@ -85,10 +85,10 @@ void CTLB::Probe()
continue; continue;
} }
DWORD & TlbEntryHiValue = m_tlb[Counter].EntryHi.Value; uint32_t & TlbEntryHiValue = m_tlb[Counter].EntryHi.Value;
DWORD Mask = ~m_tlb[Counter].PageMask.Mask << 13; uint32_t Mask = ~m_tlb[Counter].PageMask.Mask << 13;
DWORD TlbValueMasked = TlbEntryHiValue & Mask; uint32_t TlbValueMasked = TlbEntryHiValue & Mask;
DWORD EntryHiMasked = g_Reg->ENTRYHI_REGISTER & Mask; uint32_t EntryHiMasked = g_Reg->ENTRYHI_REGISTER & Mask;
if (TlbValueMasked == EntryHiMasked) if (TlbValueMasked == EntryHiMasked)
{ {
@ -108,7 +108,7 @@ void CTLB::Probe()
void CTLB::ReadEntry() void CTLB::ReadEntry()
{ {
DWORD index = g_Reg->INDEX_REGISTER & 0x1F; uint32_t index = g_Reg->INDEX_REGISTER & 0x1F;
g_Reg->PAGE_MASK_REGISTER = m_tlb[index].PageMask.Value ; g_Reg->PAGE_MASK_REGISTER = m_tlb[index].PageMask.Value ;
g_Reg->ENTRYHI_REGISTER = (m_tlb[index].EntryHi.Value & ~m_tlb[index].PageMask.Value) ; g_Reg->ENTRYHI_REGISTER = (m_tlb[index].EntryHi.Value & ~m_tlb[index].PageMask.Value) ;
@ -206,7 +206,6 @@ void CTLB::SetupTLB_Entry (int index, bool Random)
m_FastTlb[FastIndx].Random = Random; m_FastTlb[FastIndx].Random = Random;
m_FastTlb[FastIndx].Probed = false; m_FastTlb[FastIndx].Probed = false;
FastIndx = (index << 1) + 1; FastIndx = (index << 1) + 1;
if (m_FastTlb[FastIndx].VALID) if (m_FastTlb[FastIndx].VALID)
{ {
@ -252,7 +251,7 @@ void CTLB::SetupTLB_Entry (int index, bool Random)
} }
} }
bool CTLB::PAddrToVAddr(DWORD PAddr, DWORD & VAddr, DWORD & Index ) bool CTLB::PAddrToVAddr(uint32_t PAddr, uint32_t & VAddr, uint32_t & Index )
{ {
for (int i = Index; i < 64; i++) for (int i = Index; i < 64; i++)
{ {
@ -266,7 +265,6 @@ bool CTLB::PAddrToVAddr(DWORD PAddr, DWORD & VAddr, DWORD & Index )
Index = i + 1; Index = i + 1;
return true; return true;
} }
} }
return false; return false;
} }

View File

@ -2073,12 +2073,12 @@ bool CN64System::WriteToProtectedMemory (uint32_t Address, int length)
return false; return false;
} }
void CN64System::TLB_Mapped ( DWORD VAddr, DWORD Len, DWORD PAddr, bool bReadOnly ) void CN64System::TLB_Mapped ( uint32_t VAddr, uint32_t Len, uint32_t PAddr, bool bReadOnly )
{ {
m_MMU_VM.TLB_Mapped(VAddr,Len,PAddr,bReadOnly); m_MMU_VM.TLB_Mapped(VAddr,Len,PAddr,bReadOnly);
} }
void CN64System::TLB_Unmaped ( DWORD VAddr, DWORD Len ) void CN64System::TLB_Unmaped ( uint32_t VAddr, uint32_t Len )
{ {
m_MMU_VM.TLB_Unmaped(VAddr,Len); m_MMU_VM.TLB_Unmaped(VAddr,Len);
if (m_Recomp && bSMM_TLB()) if (m_Recomp && bSMM_TLB())

View File

@ -114,8 +114,8 @@ private:
virtual bool WriteToProtectedMemory(uint32_t Address, int length); virtual bool WriteToProtectedMemory(uint32_t Address, int length);
//Functions in CTLB_CB //Functions in CTLB_CB
void TLB_Mapped(DWORD VAddr, DWORD Len, DWORD PAddr, bool bReadOnly); void TLB_Mapped(uint32_t VAddr, uint32_t Len, uint32_t PAddr, bool bReadOnly);
void TLB_Unmaped(DWORD VAddr, DWORD Len); void TLB_Unmaped(uint32_t VAddr, uint32_t Len);
void TLB_Changed(); void TLB_Changed();
CPlugins * const m_Plugins; //The plugin container CPlugins * const m_Plugins; //The plugin container

View File

@ -908,7 +908,7 @@ void CRecompiler::ClearRecompCode_Phys(DWORD Address, int length, REMOVE_REASON
if (g_System->bUseTlb()) if (g_System->bUseTlb())
{ {
DWORD VAddr, Index = 0; uint32_t VAddr, Index = 0;
while (g_TLB->PAddrToVAddr(Address,VAddr,Index)) while (g_TLB->PAddrToVAddr(Address,VAddr,Index))
{ {
WriteTraceF(TraceRecompiler,__FUNCTION__ ": ClearRecompCode Vaddr %X len: %d",VAddr,length); WriteTraceF(TraceRecompiler,__FUNCTION__ ": ClearRecompCode Vaddr %X len: %d",VAddr,length);