From 249d2a33f14639f9c432aa7a6577df1fdc215480 Mon Sep 17 00:00:00 2001 From: zilmar Date: Sat, 29 Sep 2012 06:17:44 +1000 Subject: [PATCH] added tlb checking to syncing the cores --- Source/Project64/N64 System/Mips/TLB Class.h | 74 +++++++------------ .../Project64/N64 System/Mips/TLB class.cpp | 51 +++++++++++++ Source/Project64/N64 System/N64 Class.cpp | 2 + 3 files changed, 80 insertions(+), 47 deletions(-) diff --git a/Source/Project64/N64 System/Mips/TLB Class.h b/Source/Project64/N64 System/Mips/TLB Class.h index db1c8770d..1548c1ccf 100644 --- a/Source/Project64/N64 System/Mips/TLB Class.h +++ b/Source/Project64/N64 System/Mips/TLB Class.h @@ -69,31 +69,6 @@ public: } EntryLo1; } TLB_ENTRY; - -private: - typedef struct { - DWORD VSTART; - DWORD VEND; - DWORD PHYSSTART; - DWORD PHYSEND; - DWORD Length; - bool VALID; - bool DIRTY; - bool GLOBAL; - bool ValidEntry; - bool Random; - bool Probed; - } FASTTLB; - - //friend CC_Core; - friend CDebugTlb; // enable debug window to read class - - CTLB_CB * const m_CB; - - TLB_ENTRY m_tlb[32]; - FASTTLB m_FastTlb[64]; - - void SetupTLB_Entry ( int index, bool Random ); public: CTLB ( CTLB_CB * CallBack ); @@ -113,28 +88,33 @@ public: bool PAddrToVAddr ( DWORD PAddr, DWORD & VAddr, DWORD & Index ); - //Change the Virtual address to a Phyiscal Address - /*inline bool TranslateVaddr ( DWORD VAddr, DWORD &PAddr) const - { - //Change the Virtual address to a Phyiscal Address - if (TLB_ReadMap[VAddr >> 12] == 0) { return false; } - PAddr = (DWORD)((BYTE *)(TLB_ReadMap[VAddr >> 12] + VAddr) - m_BasePAddr); - return true; - } - - inline DWORD TranslateVaddr ( DWORD VAddr ) const - { - //Change the Virtual address to a Phyiscal Address - return (DWORD)((BYTE *)(TLB_ReadMap[VAddr >> 12] + VAddr) - m_BasePAddr); - } + void RecordDifference ( CLog &LogFile, const CTLB& rTLB); - //Change the Virtual address to a pointer to the physical address in memory - bool VAddrToRealAddr ( DWORD VAddr, void * &RealAddress ); - - // Find a matching Virtual Addres from a phyiscal one - bool PAddrToVAddr ( DWORD PAddr, DWORD & VAddr, DWORD & Index ); + bool operator == (const CTLB& rTLB) const; + bool operator != (const CTLB& rTLB) const; - //see if the Vaddr is valid - inline bool ValidVaddr ( DWORD VAddr ) const { return TLB_ReadMap[VAddr >> 12] != 0; } - */ +private: + typedef struct { + DWORD VSTART; + DWORD VEND; + DWORD PHYSSTART; + DWORD PHYSEND; + DWORD Length; + bool VALID; + bool DIRTY; + bool GLOBAL; + bool ValidEntry; + bool Random; + bool Probed; + } FASTTLB; + + //friend CC_Core; + friend CDebugTlb; // enable debug window to read class + + CTLB_CB * const m_CB; + + TLB_ENTRY m_tlb[32]; + FASTTLB m_FastTlb[64]; + + void SetupTLB_Entry ( int index, bool Random ); }; diff --git a/Source/Project64/N64 System/Mips/TLB class.cpp b/Source/Project64/N64 System/Mips/TLB class.cpp index 7556a0c5d..e76d2c09b 100644 --- a/Source/Project64/N64 System/Mips/TLB class.cpp +++ b/Source/Project64/N64 System/Mips/TLB class.cpp @@ -227,3 +227,54 @@ bool CTLB::PAddrToVAddr(DWORD PAddr, DWORD & VAddr, DWORD & Index ) } return false; } + +void CTLB::RecordDifference( CLog &LogFile, const CTLB& rTLB) +{ + for (int i = 0, n = sizeof(m_tlb)/sizeof(m_tlb[0]); i < n; i++) + { + if (m_tlb[i].EntryDefined != rTLB.m_tlb[i].EntryDefined) + { + LogFile.LogF("TLB[%d] Defined: %s %s\r\n",i,m_tlb[i].EntryDefined ? "Yes" : "No",rTLB.m_tlb[i].EntryDefined ? "Yes" : "No"); + continue; + } + if (!m_tlb[i].EntryDefined) { continue; } + if (m_tlb[i].PageMask.Value != rTLB.m_tlb[i].PageMask.Value) + { + LogFile.LogF("TLB[%d] PageMask: %X %X\r\n",i,m_tlb[i].PageMask.Value,rTLB.m_tlb[i].PageMask.Value); + } + if (m_tlb[i].EntryHi.Value != rTLB.m_tlb[i].EntryHi.Value) + { + LogFile.LogF("TLB[%d] EntryHi: %X %X\r\n",i,m_tlb[i].EntryHi.Value,rTLB.m_tlb[i].EntryHi.Value); + } + if (m_tlb[i].EntryLo0.Value != rTLB.m_tlb[i].EntryLo0.Value) + { + LogFile.LogF("TLB[%d] EntryLo0: %X %X\r\n",i,m_tlb[i].EntryLo0.Value,rTLB.m_tlb[i].EntryLo0.Value); + } + if (m_tlb[i].EntryLo1.Value != rTLB.m_tlb[i].EntryLo1.Value) + { + LogFile.LogF("TLB[%d] EntryLo1: %X %X\r\n",i,m_tlb[i].EntryLo1.Value,rTLB.m_tlb[i].EntryLo1.Value); + } + } +} + +bool CTLB::operator == (const CTLB& rTLB) const +{ + for (int i = 0, n = sizeof(m_tlb)/sizeof(m_tlb[0]); i < n; i++) + { + if (m_tlb[i].EntryDefined != rTLB.m_tlb[i].EntryDefined) { return false; } + if (!m_tlb[i].EntryDefined) { continue; } + if (m_tlb[i].PageMask.Value != rTLB.m_tlb[i].PageMask.Value || + m_tlb[i].EntryHi.Value != rTLB.m_tlb[i].EntryHi.Value || + m_tlb[i].EntryLo0.Value != rTLB.m_tlb[i].EntryLo0.Value || + m_tlb[i].EntryLo1.Value != rTLB.m_tlb[i].EntryLo1.Value) + { + return false; + } + } + return true; +} + +bool CTLB::operator != (const CTLB& rTLB) const +{ + return !(*this == rTLB); +} \ No newline at end of file diff --git a/Source/Project64/N64 System/N64 Class.cpp b/Source/Project64/N64 System/N64 Class.cpp index 0cce35824..8e3eca74f 100644 --- a/Source/Project64/N64 System/N64 Class.cpp +++ b/Source/Project64/N64 System/N64 Class.cpp @@ -923,6 +923,7 @@ void CN64System::SyncCPU (CN64System * const SecondCPU) { } } + if (m_TLB != SecondCPU->m_TLB) { ErrorFound = true; } if (m_Reg.m_FPCR[0] != SecondCPU->m_Reg.m_FPCR[0]) { ErrorFound = true; } if (m_Reg.m_FPCR[31] != SecondCPU->m_Reg.m_FPCR[31]) { ErrorFound = true; } if (m_Reg.m_HI.DW != SecondCPU->m_Reg.m_HI.DW) { ErrorFound = true; } @@ -1027,6 +1028,7 @@ void CN64System::DumpSyncErrors (CN64System * SecondCPU) { { Error.LogF("Current Time: %X %X\r\n",(DWORD)m_NextTimer,(DWORD)SecondCPU->m_NextTimer); } + m_TLB.RecordDifference(Error,SecondCPU->m_TLB); m_SystemTimer.RecordDifference(Error,SecondCPU->m_SystemTimer); if (m_Reg.m_RoundingModel != SecondCPU->m_Reg.m_RoundingModel) {