CPU/CodeCache: Fix DMA writes not invalidating code blocks

Fixes Crash Team Racing and Spyro in Cached Interpreter/Recompiler
modes.
This commit is contained in:
Connor McLaughlin 2019-11-26 19:45:36 +10:00
parent 47cbe75b48
commit 519dbc818d
3 changed files with 11 additions and 6 deletions

View file

@ -165,6 +165,14 @@ TickCount Bus::WriteWords(PhysicalMemoryAddress address, const u32* words, u32 w
return total_ticks;
}
const u32 start_page = address / CPU_CODE_CACHE_PAGE_SIZE;
const u32 end_page = (address + word_count * sizeof(u32)) / CPU_CODE_CACHE_PAGE_SIZE;
for (u32 page = start_page; page <= end_page; page++)
{
if (m_ram_code_bits[page])
DoInvalidateCodeCache(page);
}
std::memcpy(&m_ram[address], words, sizeof(u32) * word_count);
return static_cast<TickCount>(word_count + ((word_count + 15) / 16));
}

View file

@ -357,7 +357,7 @@ void CodeCache::AddBlockToPageMap(CodeBlock* block)
const u32 start_page = block->GetStartPageIndex();
const u32 end_page = block->GetEndPageIndex();
for (u32 page = start_page; page < end_page; page++)
for (u32 page = start_page; page <= end_page; page++)
{
m_ram_block_map[page].push_back(block);
m_bus->SetRAMCodePage(page);
@ -371,7 +371,7 @@ void CodeCache::RemoveBlockFromPageMap(CodeBlock* block)
const u32 start_page = block->GetStartPageIndex();
const u32 end_page = block->GetEndPageIndex();
for (u32 page = start_page; page < end_page; page++)
for (u32 page = start_page; page <= end_page; page++)
{
auto& page_blocks = m_ram_block_map[page];
auto page_block_iter = std::find(page_blocks.begin(), page_blocks.end(), block);

View file

@ -435,10 +435,7 @@ struct CodeBlock
const u32 GetPC() const { return key.GetPC(); }
const u32 GetSizeInBytes() const { return static_cast<u32>(instructions.size()) * sizeof(Instruction); }
const u32 GetStartPageIndex() const { return (key.GetPC() / CPU_CODE_CACHE_PAGE_SIZE); }
const u32 GetEndPageIndex() const
{
return ((key.GetPC() + GetSizeInBytes() + (CPU_CODE_CACHE_PAGE_SIZE - 1)) / CPU_CODE_CACHE_PAGE_SIZE);
}
const u32 GetEndPageIndex() const { return ((key.GetPC() + GetSizeInBytes()) / CPU_CODE_CACHE_PAGE_SIZE); }
bool IsInRAM() const
{
// TODO: Constant