CPU/CodeCache: Move backpatch lookup after RAM check

Saves a map lookup if we're just invalidating code.
This commit is contained in:
Stenzek 2024-02-27 21:02:44 +10:00
parent eb7b6d217d
commit 454cceab80
No known key found for this signature in database

View file

@ -832,9 +832,7 @@ template<PGXPMode pgxp_mode>
} }
} }
// TODO: make DebugAssert DebugAssert(!(HasPendingInterrupt()));
Assert(!(HasPendingInterrupt()));
if (g_settings.cpu_recompiler_icache) if (g_settings.cpu_recompiler_icache)
CheckAndUpdateICacheTags(block->icache_line_count, block->uncached_fetch_ticks); CheckAndUpdateICacheTags(block->icache_line_count, block->uncached_fetch_ticks);
@ -1605,6 +1603,15 @@ Common::PageFaultHandler::HandlerResult CPU::CodeCache::HandleFastmemException(v
guest_address = static_cast<PhysicalMemoryAddress>( guest_address = static_cast<PhysicalMemoryAddress>(
static_cast<ptrdiff_t>(static_cast<u8*>(fault_address) - static_cast<u8*>(g_state.fastmem_base))); static_cast<ptrdiff_t>(static_cast<u8*>(fault_address) - static_cast<u8*>(g_state.fastmem_base)));
// if we're writing to ram, let it go through a few times, and use manual block protection to sort it out
// TODO: path for manual protection to return back to read-only pages
if (is_write && !g_state.cop0_regs.sr.Isc && AddressInRAM(guest_address))
{
Log_DevFmt("Ignoring fault due to RAM write @ 0x{:08X}", guest_address);
InvalidateBlocksWithPageIndex(Bus::GetRAMCodePageIndex(guest_address));
return Common::PageFaultHandler::HandlerResult::ContinueExecution;
}
} }
else else
#endif #endif
@ -1623,16 +1630,7 @@ Common::PageFaultHandler::HandlerResult CPU::CodeCache::HandleFastmemException(v
return Common::PageFaultHandler::HandlerResult::ExecuteNextHandler; return Common::PageFaultHandler::HandlerResult::ExecuteNextHandler;
} }
// if we're writing to ram, let it go through a few times, and use manual block protection to sort it out
// TODO: path for manual protection to return back to read-only pages
LoadstoreBackpatchInfo& info = iter->second; LoadstoreBackpatchInfo& info = iter->second;
if (is_write && !g_state.cop0_regs.sr.Isc && AddressInRAM(guest_address))
{
Log_DevFmt("Ignoring fault due to RAM write @ 0x{:08X}", guest_address);
InvalidateBlocksWithPageIndex(Bus::GetRAMCodePageIndex(guest_address));
return Common::PageFaultHandler::HandlerResult::ContinueExecution;
}
Log_DevFmt("Backpatching {} at {}[{}] (pc {:08X} addr {:08X}): Bitmask {:08X} Addr {} Data {} Size {} Signed {:02X}", Log_DevFmt("Backpatching {} at {}[{}] (pc {:08X} addr {:08X}): Bitmask {:08X} Addr {} Data {} Size {} Signed {:02X}",
info.is_load ? "load" : "store", exception_pc, info.code_size, info.guest_pc, guest_address, info.is_load ? "load" : "store", exception_pc, info.code_size, info.guest_pc, guest_address,
info.gpr_bitmask, static_cast<unsigned>(info.address_register), static_cast<unsigned>(info.data_register), info.gpr_bitmask, static_cast<unsigned>(info.address_register), static_cast<unsigned>(info.data_register),