From 4b8f7f55be5b566d03e2decb763716248ab358bb Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Mon, 11 Sep 2023 00:00:31 +0300 Subject: [PATCH] Handle dynarmic cache invalidation better --- include/cpu_dynarmic.hpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/include/cpu_dynarmic.hpp b/include/cpu_dynarmic.hpp index 7bed8704..8f1e277b 100644 --- a/include/cpu_dynarmic.hpp +++ b/include/cpu_dynarmic.hpp @@ -173,11 +173,18 @@ public: void clearCache() { jit->ClearCache(); } void runFrame() { - env.ticksLeft = ticksPerSec / 60; + env.ticksLeft = ticksPerSec / 60; + execute: + const auto exitReason = jit->Run(); - const auto exitReason = jit->Run(); - if (static_cast(exitReason) != 0) [[unlikely]] { - Helpers::panic("Exit reason: %d\nPC: %08X", static_cast(exitReason), getReg(15)); - } - } + if (static_cast(exitReason) != 0) [[unlikely]] { + // Cache invalidation needs to exit the JIT so it returns a CacheInvalidation HaltReason. In our case, we just go back to executing + // The goto might be terrible but it does guarantee that this does not recursively call run and crash, instead getting optimized to a jump + if (Dynarmic::Has(exitReason, Dynarmic::HaltReason::CacheInvalidation)) { + goto execute; + } else { + Helpers::panic("Exit reason: %d\nPC: %08X", static_cast(exitReason), getReg(15)); + } + } + } }; \ No newline at end of file