Skip to content

Commit

Permalink
EE Cache: Writeback dirty cache entries when exiting the interpreter.
Browse files Browse the repository at this point in the history
  • Loading branch information
F0bes committed Dec 8, 2024
1 parent ac968f9 commit f24a269
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pcsx2/Cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,17 @@ void resetCache()
std::memset(&cache, 0, sizeof(cache));
}

void writebackCache()
{
for (int i = 0; i < 64; i++)
{
for (int j = 0; j < 2; j++)
{
cache.lineAt(i, j).writeBackIfNeeded();
}
}
}

static bool findInCache(const CacheSet& set, uptr ppf, int* way)
{
auto check = [&](int checkWay) -> bool {
Expand Down
3 changes: 3 additions & 0 deletions pcsx2/Cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include "common/SingleRegisterTypes.h"

void resetCache();
// Dumps all dirty cache entries to memory
// This was implemented to safely allow to emulator to go from int+cache to the recompiler.
void writebackCache();
void writeCache8(u32 mem, u8 value, bool validPFN = true);
void writeCache16(u32 mem, u16 value, bool validPFN = true);
void writeCache32(u32 mem, u32 value, bool validPFN = true);
Expand Down
5 changes: 5 additions & 0 deletions pcsx2/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "R5900OpcodeTables.h"
#include "VMManager.h"
#include "Elfheader.h"
#include "Cache.h"

#include "DebugTools/Breakpoints.h"

Expand Down Expand Up @@ -555,6 +556,7 @@ static void intEventTest()
if (intExitExecution)
{
intExitExecution = false;
writebackCache();
fastjmp_jmp(&intJmpBuf, 1);
}
}
Expand All @@ -566,7 +568,10 @@ static void intSafeExitExecution()
if (eeEventTestIsActive)
intExitExecution = true;
else
{
writebackCache();
fastjmp_jmp(&intJmpBuf, 1);
}
}

static void intCancelInstruction()
Expand Down

0 comments on commit f24a269

Please sign in to comment.