From b74a2dc69fe1a43127a576913bc3c027fc572a06 Mon Sep 17 00:00:00 2001 From: zilmar Date: Mon, 2 May 2022 07:36:50 +0930 Subject: [PATCH] [Core] Change TranslateVaddr to VAddrToPAddr --- Source/Project64-core/Logging.cpp | 101 ------------------ Source/Project64-core/Logging.h | 2 - .../N64System/Interpreter/InterpreterOps.cpp | 9 -- .../Interpreter/InterpreterOps32.cpp | 5 - .../CartridgeDomain1Address3Handler.cpp | 2 +- .../N64System/Mips/MemoryVirtualMem.cpp | 23 ++-- .../N64System/Mips/MemoryVirtualMem.h | 7 +- .../N64System/Mips/TranslateVaddr.h | 8 -- Source/Project64-core/N64System/N64System.cpp | 2 - .../N64System/Recompiler/CodeBlock.cpp | 23 ++-- .../N64System/Recompiler/CodeBlock.h | 48 +++++---- .../N64System/Recompiler/Recompiler.cpp | 22 ++-- .../Recompiler/x86/x86RecompilerOps.cpp | 29 +++-- .../Recompiler/x86/x86RecompilerOps.h | 7 ++ .../N64System/SystemGlobals.cpp | 1 - .../Project64-core/N64System/SystemGlobals.h | 3 - .../UserInterface/Debugger/DebugMMU.cpp | 4 +- .../Debugger/Debugger-ViewMemory.cpp | 2 +- .../Debugger/ScriptAPI/ScriptAPI_mem.cpp | 2 +- .../Project64/UserInterface/EnhancementUI.cpp | 1 + 20 files changed, 91 insertions(+), 210 deletions(-) delete mode 100644 Source/Project64-core/N64System/Mips/TranslateVaddr.h diff --git a/Source/Project64-core/Logging.cpp b/Source/Project64-core/Logging.cpp index 739035e48..10811d623 100644 --- a/Source/Project64-core/Logging.cpp +++ b/Source/Project64-core/Logging.cpp @@ -5,112 +5,11 @@ #include #include #include -#include #include #include CFile * CLogging::m_hLogFile = nullptr; -void CLogging::Log_LW(uint32_t PC, uint32_t VAddr) -{ - if (!GenerateLog()) - { - return; - } - - if (VAddr < 0xA0000000 || VAddr >= 0xC0000000) - { - uint32_t PAddr; - if (!g_TransVaddr->TranslateVaddr(VAddr, PAddr)) - { - if (LogUnknown()) - { - LogMessage("%08X: read from unknown ??? (%08X)", PC, VAddr); - } - return; - } - VAddr = PAddr + 0xA0000000; - } - - if ((VAddr >= 0xA0000000 && VAddr < (0xA0000000 + g_MMU->RdramSize())) || - (VAddr >= 0xA3F00000 && VAddr <= 0xA3F00024) || - (VAddr >= 0xA4000000 && VAddr <= 0xA4001FFC) || - (VAddr == 0xA4080000) || - (VAddr >= 0xA4100000 && VAddr <= 0xA410001C) || - (VAddr >= 0xA4300000 && VAddr <= 0xA430000C) || - (VAddr >= 0xA4400000 && VAddr <= 0xA4400034) || - (VAddr >= 0xA4500000 && VAddr <= 0xA4500014) || - (VAddr == 0xA4800000 && VAddr <= 0xA4800018) || - (VAddr >= 0xB0000000 && ((VAddr - 0xB0000000) < g_Rom->GetRomSize())) || - (VAddr >= 0xBFC00000 && VAddr <= 0xBFC007FC)) - { - return; - } - if (!LogUnknown()) - { - return; - } - LogMessage("%08X: read from unknown ??? (%08X)", PC, VAddr); -} - -void CLogging::Log_SW(uint32_t PC, uint32_t VAddr, uint32_t Value) -{ - if (!GenerateLog()) - { - return; - } - - if (VAddr < 0xA0000000 || VAddr >= 0xC0000000) - { - uint32_t PAddr; - if (!g_TransVaddr->TranslateVaddr(VAddr, PAddr)) - { - if (LogUnknown()) - { - LogMessage("%08X: Writing 0x%08X to %08X", PC, Value, VAddr); - } - return; - } - VAddr = PAddr + 0xA0000000; - } - - if (VAddr >= 0xA4200000 && VAddr <= 0xA420000C) - { - if (!LogDPSRegisters()) - { - return; - } - switch (VAddr) - { - case 0xA4200000: LogMessage("%08X: Writing 0x%08X to DPS_TBIST_REG", PC, Value); return; - case 0xA4200004: LogMessage("%08X: Writing 0x%08X to DPS_TEST_MODE_REG", PC, Value); return; - case 0xA4200008: LogMessage("%08X: Writing 0x%08X to DPS_BUFTEST_ADDR_REG", PC, Value); return; - case 0xA420000C: LogMessage("%08X: Writing 0x%08X to DPS_BUFTEST_DATA_REG", PC, Value); return; - } - } - - if ((VAddr >= 0xA0000000 && VAddr < (0xA0000000 + g_MMU->RdramSize())) || - (VAddr >= 0xA3F00000 && VAddr <= 0xA3F00024) || - (VAddr >= 0xA4000000 && VAddr <= 0xA4001FFC) || - (VAddr >= 0xA4040000 && VAddr <= 0xA404001C) || - (VAddr == 0xA4080000) || - (VAddr >= 0xA4100000 && VAddr <= 0xA410001C) || - (VAddr >= 0xA4300000 && VAddr <= 0xA430000C) || - (VAddr >= 0xA4400000 && VAddr <= 0xA4400034) || - (VAddr >= 0xA4500000 && VAddr <= 0xA4500014) || - (VAddr >= 0xA4800000 && VAddr <= 0xA4800018) || - (VAddr >= 0xBFC007C0 && VAddr <= 0xBFC007FC)) - { - return; - } - - if (!LogUnknown()) - { - return; - } - LogMessage("%08X: Writing 0x%08X to %08X ????", PC, Value, VAddr); -} - void CLogging::LogMessage(const char * Message, ...) { char Msg[400]; diff --git a/Source/Project64-core/Logging.h b/Source/Project64-core/Logging.h index 092722e9b..b3a34a510 100644 --- a/Source/Project64-core/Logging.h +++ b/Source/Project64-core/Logging.h @@ -9,8 +9,6 @@ public: static void StartLog(void); static void StopLog(void); - static void Log_LW(uint32_t PC, uint32_t VAddr); - static void Log_SW(uint32_t PC, uint32_t VAddr, uint32_t Value); static void LogMessage(const char * Message, ...); private: diff --git a/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp b/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp index c0ce1f928..670a6bba4 100644 --- a/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp +++ b/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp @@ -1133,10 +1133,6 @@ void R4300iOp::LW() { return; } - if (GenerateLog()) - { - Log_LW((*_PROGRAM_COUNTER), Address); - } if (!g_MMU->LW_VAddr(Address, _GPR[m_Opcode.rt].UW[0])) { @@ -1330,10 +1326,6 @@ void R4300iOp::SW() { return; } - if (GenerateLog()) - { - Log_SW((*_PROGRAM_COUNTER), Address, _GPR[m_Opcode.rt].UW[0]); - } if (!g_MMU->SW_VAddr(Address, _GPR[m_Opcode.rt].UW[0])) { if (bShowTLBMisses()) @@ -1536,7 +1528,6 @@ void R4300iOp::SC() { return; } - Log_SW((*_PROGRAM_COUNTER), Address, _GPR[m_Opcode.rt].UW[0]); if ((*_LLBit) == 1) { if (!g_MMU->SW_VAddr(Address, _GPR[m_Opcode.rt].UW[0])) diff --git a/Source/Project64-core/N64System/Interpreter/InterpreterOps32.cpp b/Source/Project64-core/N64System/Interpreter/InterpreterOps32.cpp index e28329448..4c1932b80 100644 --- a/Source/Project64-core/N64System/Interpreter/InterpreterOps32.cpp +++ b/Source/Project64-core/N64System/Interpreter/InterpreterOps32.cpp @@ -964,11 +964,6 @@ void R4300iOp32::LW() return; } - if (GenerateLog()) - { - Log_LW((*_PROGRAM_COUNTER), Address); - } - if (!g_MMU->LW_VAddr(Address, _GPR[m_Opcode.rt].UW[0])) { if (bShowTLBMisses()) diff --git a/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain1Address3Handler.cpp b/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain1Address3Handler.cpp index dcac83d49..94074cfca 100644 --- a/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain1Address3Handler.cpp +++ b/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain1Address3Handler.cpp @@ -11,7 +11,7 @@ bool CartridgeDomain1Address3Handler::Read32(uint32_t Address, uint32_t & Value) return true; } -bool CartridgeDomain1Address3Handler::Write32(uint32_t Address, uint32_t Value, uint32_t Mask) +bool CartridgeDomain1Address3Handler::Write32(uint32_t /*Address*/, uint32_t /*Value*/, uint32_t /*Mask*/) { return true; } diff --git a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp index 1d67adeb5..c068e5269 100755 --- a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp +++ b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp @@ -21,6 +21,7 @@ uint32_t CMipsMemoryVM::RegModValue; CMipsMemoryVM::CMipsMemoryVM(CN64System & System, bool SavesReadOnly) : CPifRam(SavesReadOnly), CDMA(m_CartridgeDomain2Address2Handler), + m_System(System), m_Reg(System.m_Reg), m_AudioInterfaceHandler(System, System.m_Reg), m_CartridgeDomain1Address1Handler(g_DDRom), @@ -109,7 +110,6 @@ void CMipsMemoryVM::Reset(bool /*EraseMemory*/) } m_TLB_ReadMap[Address >> 12] = ((size_t)m_RDRAM + TargetAddress) - Address; m_TLB_WriteMap[Address >> 12] = ((size_t)m_RDRAM + TargetAddress) - Address; - } } } @@ -441,19 +441,8 @@ bool CMipsMemoryVM::ValidVaddr(uint32_t VAddr) const return m_TLB_ReadMap[VAddr >> 12] != 0; } -bool CMipsMemoryVM::VAddrToRealAddr(uint32_t VAddr, void * &RealAddress) const +bool CMipsMemoryVM::VAddrToPAddr(uint32_t VAddr, uint32_t &PAddr) const { - if (m_TLB_ReadMap[VAddr >> 12] == 0) - { - return false; - } - RealAddress = (uint8_t *)(m_TLB_ReadMap[VAddr >> 12] + VAddr); - return true; -} - -bool CMipsMemoryVM::TranslateVaddr(uint32_t VAddr, uint32_t &PAddr) const -{ - // Change the virtual address to a physical address if (m_TLB_ReadMap[VAddr >> 12] == 0) { return false; @@ -652,11 +641,11 @@ void CMipsMemoryVM::ProtectMemory(uint32_t StartVaddr, uint32_t EndVaddr) // Get physical addresses passed uint32_t StartPAddr, EndPAddr; - if (!TranslateVaddr(StartVaddr, StartPAddr)) + if (!VAddrToPAddr(StartVaddr, StartPAddr)) { g_Notify->BreakPoint(__FILE__, __LINE__); } - if (!TranslateVaddr(EndVaddr, EndPAddr)) + if (!VAddrToPAddr(EndVaddr, EndPAddr)) { g_Notify->BreakPoint(__FILE__, __LINE__); } @@ -682,11 +671,11 @@ void CMipsMemoryVM::UnProtectMemory(uint32_t StartVaddr, uint32_t EndVaddr) // Get physical addresses passed uint32_t StartPAddr, EndPAddr; - if (!TranslateVaddr(StartVaddr, StartPAddr)) + if (!VAddrToPAddr(StartVaddr, StartPAddr)) { g_Notify->BreakPoint(__FILE__, __LINE__); } - if (!TranslateVaddr(EndVaddr, EndPAddr)) + if (!VAddrToPAddr(EndVaddr, EndPAddr)) { g_Notify->BreakPoint(__FILE__, __LINE__); } diff --git a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h index b96972b9e..1cc3734fc 100644 --- a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h +++ b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h @@ -1,6 +1,5 @@ #pragma once #include -#include "TranslateVaddr.h" #include #include #include @@ -50,7 +49,6 @@ class CArmRecompilerOps; #endif class CMipsMemoryVM : - public CTransVaddr, private R4300iOp, public CPifRam, public CDMA, @@ -100,10 +98,8 @@ public: void TLB_Mapped(uint32_t VAddr, uint32_t Len, uint32_t PAddr, bool bReadOnly); void TLB_Unmaped(uint32_t Vaddr, uint32_t Len); - // CTransVaddr interface - bool TranslateVaddr(uint32_t VAddr, uint32_t &PAddr) const; bool ValidVaddr(uint32_t VAddr) const; - bool VAddrToRealAddr(uint32_t VAddr, void * &RealAddress) const; + bool VAddrToPAddr(uint32_t VAddr, uint32_t & PAddr) const; // Labels const char * LabelName(uint32_t Address) const; @@ -159,6 +155,7 @@ private: void FreeMemory(); static uint8_t * m_Reserve1, *m_Reserve2; + CN64System & m_System; CRegisters & m_Reg; AudioInterfaceHandler m_AudioInterfaceHandler; CartridgeDomain1Address1Handler m_CartridgeDomain1Address1Handler; diff --git a/Source/Project64-core/N64System/Mips/TranslateVaddr.h b/Source/Project64-core/N64System/Mips/TranslateVaddr.h deleted file mode 100644 index 5d9919c94..000000000 --- a/Source/Project64-core/N64System/Mips/TranslateVaddr.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -__interface CTransVaddr -{ - virtual bool TranslateVaddr ( uint32_t VAddr, uint32_t &PAddr) const = 0; - virtual bool ValidVaddr ( uint32_t VAddr ) const = 0; - virtual bool VAddrToRealAddr ( uint32_t VAddr, void * &RealAddress ) const = 0; -}; diff --git a/Source/Project64-core/N64System/N64System.cpp b/Source/Project64-core/N64System/N64System.cpp index 970919fcd..ca4fa9305 100644 --- a/Source/Project64-core/N64System/N64System.cpp +++ b/Source/Project64-core/N64System/N64System.cpp @@ -989,7 +989,6 @@ bool CN64System::SetActiveSystem(bool bActive) g_Reg = &m_Reg; g_Mempak = &m_Mempak; g_SystemTimer = &m_SystemTimer; - g_TransVaddr = &m_MMU_VM; g_SystemEvents = this; g_NextTimer = &m_NextTimer; g_Plugins = m_Plugins; @@ -1010,7 +1009,6 @@ bool CN64System::SetActiveSystem(bool bActive) g_TLB = nullptr; g_Reg = nullptr; g_SystemTimer = nullptr; - g_TransVaddr = nullptr; g_SystemEvents = nullptr; g_NextTimer = nullptr; g_Plugins = m_Plugins; diff --git a/Source/Project64-core/N64System/Recompiler/CodeBlock.cpp b/Source/Project64-core/N64System/Recompiler/CodeBlock.cpp index 529498fe8..140a86996 100644 --- a/Source/Project64-core/N64System/Recompiler/CodeBlock.cpp +++ b/Source/Project64-core/N64System/Recompiler/CodeBlock.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include @@ -16,7 +15,8 @@ bool DelaySlotEffectsCompare(uint32_t PC, uint32_t Reg1, uint32_t Reg2); extern "C" void __clear_cache_android(uint8_t* begin, uint8_t *end); #endif -CCodeBlock::CCodeBlock(uint32_t VAddrEnter, uint8_t * CompiledLocation) : +CCodeBlock::CCodeBlock(CMipsMemoryVM & MMU, uint32_t VAddrEnter, uint8_t * CompiledLocation) : + m_MMU(MMU), m_VAddrEnter(VAddrEnter), m_VAddrFirst(VAddrEnter), m_VAddrLast(VAddrEnter), @@ -33,7 +33,7 @@ CCodeBlock::CCodeBlock(uint32_t VAddrEnter, uint8_t * CompiledLocation) : } #endif #if defined(__i386__) || defined(_M_IX86) - m_RecompilerOps = new CX86RecompilerOps; + m_RecompilerOps = new CX86RecompilerOps(MMU); #elif defined(__arm__) || defined(_M_ARM) m_RecompilerOps = new CArmRecompilerOps; #endif @@ -65,8 +65,16 @@ CCodeBlock::CCodeBlock(uint32_t VAddrEnter, uint8_t * CompiledLocation) : m_Sections.push_back(m_EnterSection); m_SectionMap.insert(SectionMap::value_type(VAddrEnter, m_EnterSection)); - if (g_TransVaddr->VAddrToRealAddr(VAddrEnter, *(reinterpret_cast(&m_MemLocation[0])))) + uint32_t PAddr; + if (!MMU.VAddrToPAddr(VAddrEnter, PAddr)) { + memset(m_MemLocation, 0, sizeof(m_MemLocation)); + memset(m_MemContents, 0, sizeof(m_MemContents)); + return; + } + if (PAddr + 16 < MMU.RdramSize()) + { + m_MemLocation[0] = (uint64_t *)(MMU.Rdram() + PAddr); m_MemLocation[1] = m_MemLocation[0] + 1; m_MemContents[0] = *m_MemLocation[0]; m_MemContents[1] = *m_MemLocation[1]; @@ -75,8 +83,8 @@ CCodeBlock::CCodeBlock(uint32_t VAddrEnter, uint8_t * CompiledLocation) : { memset(m_MemLocation, 0, sizeof(m_MemLocation)); memset(m_MemContents, 0, sizeof(m_MemContents)); + return; } - AnalyseBlock(); } @@ -767,9 +775,8 @@ bool CCodeBlock::Compile() m_CompiledLocationEnd = *g_RecompPos; uint32_t PAddr; - g_TransVaddr->TranslateVaddr(VAddrFirst(), PAddr); - MD5(g_MMU->Rdram() + PAddr, (VAddrLast() - VAddrFirst()) + 4).get_digest(m_Hash); - + m_MMU.VAddrToPAddr(VAddrFirst(), PAddr); + MD5(g_MMU->Rdram() + PAddr, (VAddrLast() - VAddrFirst()) + 4).get_digest(m_Hash); #if defined(ANDROID) && (defined(__arm__) || defined(_M_ARM)) __clear_cache((uint8_t *)((uint32_t)m_CompiledLocation & ~1), m_CompiledLocationEnd); #endif diff --git a/Source/Project64-core/N64System/Recompiler/CodeBlock.h b/Source/Project64-core/N64System/Recompiler/CodeBlock.h index 4a5bc2dc9..eff677d0e 100644 --- a/Source/Project64-core/N64System/Recompiler/CodeBlock.h +++ b/Source/Project64-core/N64System/Recompiler/CodeBlock.h @@ -3,20 +3,22 @@ #include #include +class CMipsMemoryVM; + class CCodeBlock { public: - CCodeBlock(uint32_t VAddrEnter, uint8_t * CompiledLocation); + CCodeBlock(CMipsMemoryVM & MMU, uint32_t VAddrEnter, uint8_t * CompiledLocation); ~CCodeBlock(); bool Compile(); - uint32_t VAddrEnter() const { return m_VAddrEnter; } - uint32_t VAddrFirst() const { return m_VAddrFirst; } - uint32_t VAddrLast() const { return m_VAddrLast; } - uint8_t * CompiledLocation() const { return m_CompiledLocation; } - uint8_t * CompiledLocationEnd() const { return m_CompiledLocationEnd; } - int32_t NoOfSections() const { return (int32_t)m_Sections.size() - 1; } + uint32_t VAddrEnter() const { return m_VAddrEnter; } + uint32_t VAddrFirst() const { return m_VAddrFirst; } + uint32_t VAddrLast() const { return m_VAddrLast; } + uint8_t * CompiledLocation() const { return m_CompiledLocation; } + uint8_t * CompiledLocationEnd() const { return m_CompiledLocationEnd; } + int32_t NoOfSections() const { return (int32_t)m_Sections.size() - 1; } const CCodeSection & EnterSection() const { return *m_EnterSection; } const MD5Digest & Hash() const { return m_Hash; } CRecompilerOps *& RecompilerOps() { return m_RecompilerOps; } @@ -26,7 +28,7 @@ public: CCodeSection * ExistingSection(uint32_t Addr) { return m_EnterSection->ExistingSection(Addr, NextTest()); } bool SectionAccessible(uint32_t m_SectionID) { return m_EnterSection->SectionAccessible(m_SectionID, NextTest()); } - uint64_t MemContents(int32_t i) const { return m_MemContents[i]; } + uint64_t MemContents(int32_t i) const { return m_MemContents[i]; } uint64_t * MemLocation(int32_t i) const { return m_MemLocation[i]; } uint32_t NextTest(); @@ -42,24 +44,24 @@ private: void DetermineLoops(); void LogSectionInfo(); bool SetSection(CCodeSection * & Section, CCodeSection * CurrentSection, uint32_t TargetPC, bool LinkAllowed, uint32_t CurrentPC); - bool AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t & ContinuePC, bool & LikelyBranch, bool & IncludeDelaySlot, - bool & EndBlock, bool & PermLoop); + bool AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t & ContinuePC, bool & LikelyBranch, bool & IncludeDelaySlot, bool & EndBlock, bool & PermLoop); - uint32_t m_VAddrEnter; - uint32_t m_VAddrFirst; // The address of the first opcode in the block - uint32_t m_VAddrLast; // The address of the first opcode in the block - uint8_t* m_CompiledLocation; // What address is this compiled at? - uint8_t* m_CompiledLocationEnd; // What address is this compiled at? + uint32_t m_VAddrEnter; + uint32_t m_VAddrFirst; // The address of the first opcode in the block + uint32_t m_VAddrLast; // The address of the first opcode in the block + uint8_t * m_CompiledLocation; // What address is this compiled at? + uint8_t * m_CompiledLocationEnd; // What address is this compiled at? typedef std::map SectionMap; - typedef std::list SectionList; + typedef std::list SectionList; - SectionMap m_SectionMap; - SectionList m_Sections; - CCodeSection * m_EnterSection; - int32_t m_Test; - MD5Digest m_Hash; - uint64_t m_MemContents[2]; - uint64_t * m_MemLocation[2]; + CMipsMemoryVM & m_MMU; + SectionMap m_SectionMap; + SectionList m_Sections; + CCodeSection * m_EnterSection; + int32_t m_Test; + MD5Digest m_Hash; + uint64_t m_MemContents[2]; + uint64_t * m_MemLocation[2]; CRecompilerOps * m_RecompilerOps; }; diff --git a/Source/Project64-core/N64System/Recompiler/Recompiler.cpp b/Source/Project64-core/N64System/Recompiler/Recompiler.cpp index 54a0a6328..35c2bd3c8 100644 --- a/Source/Project64-core/N64System/Recompiler/Recompiler.cpp +++ b/Source/Project64-core/N64System/Recompiler/Recompiler.cpp @@ -147,10 +147,10 @@ void CRecompiler::RecompilerMain_Lookup() while (!m_EndEmulation) { - if (!m_MMU.TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr)) + if (!m_MMU.VAddrToPAddr(PROGRAM_COUNTER, PhysicalAddr)) { m_Registers.DoTLBReadMiss(false, PROGRAM_COUNTER); - if (!m_MMU.TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr)) + if (!m_MMU.VAddrToPAddr(PROGRAM_COUNTER, PhysicalAddr)) { g_Notify->DisplayError(stdstr_f("Failed to translate PC to a PAddr: %X\n\nEmulation stopped", PROGRAM_COUNTER).c_str()); m_EndEmulation = true; @@ -180,7 +180,7 @@ void CRecompiler::RecompilerMain_Lookup() { uint32_t opsExecuted = 0; - while (m_MMU.TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr) && PhysicalAddr >= g_System->RdramSize()) + while (m_MMU.VAddrToPAddr(PROGRAM_COUNTER, PhysicalAddr) && PhysicalAddr >= g_System->RdramSize()) { CInterpreterCPU::ExecuteOps(g_System->CountPerOp()); opsExecuted += g_System->CountPerOp(); @@ -205,10 +205,10 @@ void CRecompiler::RecompilerMain_Lookup_validate() while (!Done) { - if (!m_MMU.TranslateVaddr(PC, PhysicalAddr)) + if (!m_MMU.VAddrToPAddr(PC, PhysicalAddr)) { m_Registers.DoTLBReadMiss(false, PC); - if (!m_MMU.TranslateVaddr(PC, PhysicalAddr)) + if (!m_MMU.VAddrToPAddr(PC, PhysicalAddr)) { g_Notify->DisplayError(stdstr_f("Failed to translate PC to a PAddr: %X\n\nEmulation stopped", PC).c_str()); Done = true; @@ -292,7 +292,7 @@ void CRecompiler::RecompilerMain_Lookup_validate() { uint32_t opsExecuted = 0; - while (m_MMU.TranslateVaddr(PC, PhysicalAddr) && PhysicalAddr >= g_System->RdramSize()) + while (m_MMU.VAddrToPAddr(PC, PhysicalAddr) && PhysicalAddr >= g_System->RdramSize()) { CInterpreterCPU::ExecuteOps(g_System->CountPerOp()); opsExecuted += g_System->CountPerOp(); @@ -347,7 +347,7 @@ CCompiledFunc * CRecompiler::CompileCode() WriteTrace(TraceRecompiler, TraceDebug, "Start (PC: %X)", PROGRAM_COUNTER); uint32_t pAddr = 0; - if (!m_MMU.TranslateVaddr(PROGRAM_COUNTER, pAddr)) + if (!m_MMU.VAddrToPAddr(PROGRAM_COUNTER, pAddr)) { WriteTrace(TraceRecompiler, TraceError, "Failed to translate %X", PROGRAM_COUNTER); return nullptr; @@ -360,7 +360,7 @@ CCompiledFunc * CRecompiler::CompileCode() for (CCompiledFunc * Func = iter->second; Func != nullptr; Func = Func->Next()) { uint32_t PAddr; - if (m_MMU.TranslateVaddr(Func->MinPC(), PAddr)) + if (m_MMU.VAddrToPAddr(Func->MinPC(), PAddr)) { MD5Digest Hash; MD5(m_MMU.Rdram() + PAddr, (Func->MaxPC() - Func->MinPC()) + 4).get_digest(Hash); @@ -376,7 +376,7 @@ CCompiledFunc * CRecompiler::CompileCode() CheckRecompMem(); WriteTrace(TraceRecompiler, TraceDebug, "Compile Block-Start: Program Counter: %X pAddr: %X", PROGRAM_COUNTER, pAddr); - CCodeBlock CodeBlock(PROGRAM_COUNTER, *g_RecompPos); + CCodeBlock CodeBlock(m_MMU, PROGRAM_COUNTER, *g_RecompPos); if (!CodeBlock.Compile()) { return nullptr; @@ -500,7 +500,7 @@ void CRecompiler::ClearRecompCode_Virt(uint32_t Address, int length, REMOVE_REAS case FuncFind_PhysicalLookup: { uint32_t pAddr = 0; - if (m_MMU.TranslateVaddr(Address, pAddr)) + if (m_MMU.VAddrToPAddr(Address, pAddr)) { ClearRecompCode_Phys(pAddr, length, Reason); } @@ -523,7 +523,7 @@ void CRecompiler::ResetMemoryStackPos() } uint32_t pAddr = 0; - if (m_MMU.TranslateVaddr(m_Registers.m_GPR[29].UW[0], pAddr)) + if (m_MMU.VAddrToPAddr(m_Registers.m_GPR[29].UW[0], pAddr)) { m_MemoryStack = (uint32_t)(m_MMU.Rdram() + pAddr); } diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp index 908f9bb8d..a4af4a759 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp +++ b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp @@ -181,6 +181,15 @@ static void x86TestWriteBreakpoint64() } } +CX86RecompilerOps::CX86RecompilerOps(CMipsMemoryVM & MMU) : + m_MMU(MMU) +{ +} + +CX86RecompilerOps::~CX86RecompilerOps() +{ +} + void CX86RecompilerOps::PreCompileOpcode(void) { if (m_PipelineStage != PIPELINE_STAGE_DELAY_SLOT_DONE) @@ -2606,7 +2615,7 @@ void CX86RecompilerOps::LUI() x86Reg Reg = Map_MemoryStack(x86_Any, true, false); uint32_t Address; - g_TransVaddr->TranslateVaddr(((int16_t)m_Opcode.offset << 16), Address); + m_MMU.VAddrToPAddr(((int16_t)m_Opcode.offset << 16), Address); if (Reg < 0) { MoveConstToVariable((uint32_t)(Address + g_MMU->Rdram()), &(g_Recompiler->MemoryStackPos()), "MemoryStack"); @@ -2766,7 +2775,7 @@ void CX86RecompilerOps::LB_KnownAddress(x86Reg Reg, uint32_t VAddr, bool SignExt return; } - if (!g_TransVaddr->TranslateVaddr(VAddr, PAddr)) + if (!m_MMU.VAddrToPAddr(VAddr, PAddr)) { MoveConstToX86reg(0, Reg); CPU_Message("%s\nFailed to translate address %08X", __FUNCTION__, VAddr); @@ -2839,7 +2848,7 @@ void CX86RecompilerOps::LH_KnownAddress(x86Reg Reg, uint32_t VAddr, bool SignExt return; } - if (!g_TransVaddr->TranslateVaddr(VAddr, PAddr)) + if (!m_MMU.VAddrToPAddr(VAddr, PAddr)) { MoveConstToX86reg(0, Reg); CPU_Message("%s\nFailed to translate address %08X", __FUNCTION__, VAddr); @@ -3205,7 +3214,7 @@ void CX86RecompilerOps::LW_KnownAddress(x86Reg Reg, uint32_t VAddr) } else { - if (!g_TransVaddr->TranslateVaddr(VAddr, PAddr)) + if (!m_MMU.VAddrToPAddr(VAddr, PAddr)) { g_Notify->BreakPoint(__FILE__, __LINE__); } @@ -10387,7 +10396,7 @@ void CX86RecompilerOps::SB_Const(uint8_t Value, uint32_t VAddr) return; } - if (!g_TransVaddr->TranslateVaddr(VAddr, PAddr)) + if (!m_MMU.VAddrToPAddr(VAddr, PAddr)) { CPU_Message("%s\nFailed to translate address: %08X", __FUNCTION__, VAddr); if (ShowUnhandledMemory()) { g_Notify->DisplayError(stdstr_f("%s, \nFailed to translate address: %08X", __FUNCTION__, VAddr).c_str()); } @@ -10444,7 +10453,7 @@ void CX86RecompilerOps::SB_Register(x86Reg Reg, uint32_t VAddr) return; } - if (!g_TransVaddr->TranslateVaddr(VAddr, PAddr)) + if (!m_MMU.VAddrToPAddr(VAddr, PAddr)) { CPU_Message("%s\nFailed to translate address: %08X", __FUNCTION__, VAddr); if (ShowUnhandledMemory()) @@ -10502,7 +10511,7 @@ void CX86RecompilerOps::SH_Const(uint16_t Value, uint32_t VAddr) return; } - if (!g_TransVaddr->TranslateVaddr(VAddr, PAddr)) + if (!m_MMU.VAddrToPAddr(VAddr, PAddr)) { CPU_Message("%s\nFailed to translate address: %08X", __FUNCTION__, VAddr); if (ShowUnhandledMemory()) @@ -10562,7 +10571,7 @@ void CX86RecompilerOps::SH_Register(x86Reg Reg, uint32_t VAddr) return; } - if (!g_TransVaddr->TranslateVaddr(VAddr, PAddr)) + if (!m_MMU.VAddrToPAddr(VAddr, PAddr)) { CPU_Message("%s\nFailed to translate address: %08X", __FUNCTION__, VAddr); if (ShowUnhandledMemory()) @@ -10621,7 +10630,7 @@ void CX86RecompilerOps::SW_Const(uint32_t Value, uint32_t VAddr) return; } - if (!g_TransVaddr->TranslateVaddr(VAddr, PAddr)) + if (!m_MMU.VAddrToPAddr(VAddr, PAddr)) { CPU_Message("%s\nFailed to translate address: %08X", __FUNCTION__, VAddr); if (ShowUnhandledMemory()) @@ -11201,7 +11210,7 @@ void CX86RecompilerOps::SW_Register(x86Reg Reg, uint32_t VAddr) char VarName[100]; uint32_t PAddr; - if (!g_TransVaddr->TranslateVaddr(VAddr, PAddr)) + if (!m_MMU.VAddrToPAddr(VAddr, PAddr)) { CPU_Message("%s\nFailed to translate address: %08X", __FUNCTION__, VAddr); if (ShowUnhandledMemory()) diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h index a0a8230e1..ce1b7c694 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h +++ b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h @@ -25,6 +25,9 @@ class CX86RecompilerOps : private CGameSettings { public: + CX86RecompilerOps(CMipsMemoryVM & MMU); + ~CX86RecompilerOps(); + // Trap functions void Compile_TrapCompare(TRAP_COMPARE CompareType); @@ -351,6 +354,9 @@ public: static uint32_t CompilePC() { return m_CompilePC; } private: + CX86RecompilerOps(const CX86RecompilerOps&); + CX86RecompilerOps& operator=(const CX86RecompilerOps&); + void SB_Const(uint8_t Value, uint32_t Addr); void SB_Register(CX86Ops::x86Reg Reg, uint32_t Addr); void SH_Const(uint16_t Value, uint32_t Addr); @@ -367,6 +373,7 @@ private: void ResetMemoryStack(); EXIT_LIST m_ExitInfo; + CMipsMemoryVM & m_MMU; static PIPELINE_STAGE m_PipelineStage; static uint32_t m_CompilePC; static OPCODE m_Opcode; diff --git a/Source/Project64-core/N64System/SystemGlobals.cpp b/Source/Project64-core/N64System/SystemGlobals.cpp index 8bc897954..241c7ccdd 100644 --- a/Source/Project64-core/N64System/SystemGlobals.cpp +++ b/Source/Project64-core/N64System/SystemGlobals.cpp @@ -14,7 +14,6 @@ CN64Rom * g_Rom = nullptr; // The current ROM that this system is executing CN64Rom * g_DDRom = nullptr; // 64DD IPL ROM CN64Disk * g_Disk = nullptr; // 64DD disk CSystemTimer * g_SystemTimer = nullptr; -CTransVaddr * g_TransVaddr = nullptr; CSystemEvents * g_SystemEvents = nullptr; uint32_t * g_TLBLoadAddress = nullptr; uint32_t * g_TLBStoreAddress = nullptr; diff --git a/Source/Project64-core/N64System/SystemGlobals.h b/Source/Project64-core/N64System/SystemGlobals.h index f5d5b21d5..4ecb805f7 100644 --- a/Source/Project64-core/N64System/SystemGlobals.h +++ b/Source/Project64-core/N64System/SystemGlobals.h @@ -33,9 +33,6 @@ extern CN64Disk * g_Disk; // 64DD disk class CSystemTimer; extern CSystemTimer * g_SystemTimer; -__interface CTransVaddr; -extern CTransVaddr * g_TransVaddr; - class CSystemEvents; extern CSystemEvents * g_SystemEvents; diff --git a/Source/Project64/UserInterface/Debugger/DebugMMU.cpp b/Source/Project64/UserInterface/Debugger/DebugMMU.cpp index 369877365..6a0bb5ffe 100644 --- a/Source/Project64/UserInterface/Debugger/DebugMMU.cpp +++ b/Source/Project64/UserInterface/Debugger/DebugMMU.cpp @@ -292,7 +292,7 @@ size_t CDebugMMU::ReadVirtual(uint32_t vaddr, size_t length, uint8_t* buffer) for (nByte = 0; nByte < length; nByte++) { uint32_t paddr; - if (!g_MMU || !g_MMU->TranslateVaddr(vaddr + nByte, paddr)) + if (!g_MMU || !g_MMU->VAddrToPAddr(vaddr + nByte, paddr)) { return nByte; } @@ -323,7 +323,7 @@ size_t CDebugMMU::WriteVirtual(uint32_t vaddr, size_t length, uint8_t* buffer) for (nByte = 0; nByte < length; nByte++) { uint32_t paddr; - if (!g_MMU || !g_MMU->TranslateVaddr(vaddr + nByte, paddr)) + if (!g_MMU || !g_MMU->VAddrToPAddr(vaddr + nByte, paddr)) { return nByte; } diff --git a/Source/Project64/UserInterface/Debugger/Debugger-ViewMemory.cpp b/Source/Project64/UserInterface/Debugger/Debugger-ViewMemory.cpp index 067c5b57e..370220957 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-ViewMemory.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-ViewMemory.cpp @@ -773,7 +773,7 @@ LRESULT CDebugMemoryView::OnHxGetByteInfo(LPNMHDR lpNMHDR) newByte->bkColor = BKCOLOR_DEFAULT; newByte->color = COLOR_DEFAULT; - if (m_bVirtualMemory && (g_MMU == nullptr || !g_MMU->TranslateVaddr(address, paddress))) + if (m_bVirtualMemory && (g_MMU == nullptr || !g_MMU->VAddrToPAddr(address, paddress))) { newByte->bValid = false; continue; diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_mem.cpp b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_mem.cpp index ca71cf18a..ea31f0b7d 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_mem.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_mem.cpp @@ -93,7 +93,7 @@ duk_ret_t ScriptAPI::js_mem_getblock(duk_context *ctx) if (addr < 0x80000000 || addr >= 0xC0000000) { - if (!g_MMU || !g_MMU->TranslateVaddr(addr, paddr)) + if (!g_MMU || !g_MMU->VAddrToPAddr(addr, paddr)) { return ThrowMemoryError(ctx, addr); } diff --git a/Source/Project64/UserInterface/EnhancementUI.cpp b/Source/Project64/UserInterface/EnhancementUI.cpp index cfad6b515..9a8e5c80e 100644 --- a/Source/Project64/UserInterface/EnhancementUI.cpp +++ b/Source/Project64/UserInterface/EnhancementUI.cpp @@ -272,6 +272,7 @@ LRESULT CEnhancementUI::OnPopupDelete(WORD wNotifyCode, WORD wID, HWND hWndCtl, break; } RefreshList(); + return 0; } LRESULT CEnhancementUI::OnEnhancementListRClicked(NMHDR* pNMHDR)