|
|
@ -13,6 +13,7 @@ |
|
|
#include "core/hle/kernel/code_set.h" |
|
|
#include "core/hle/kernel/code_set.h" |
|
|
#include "core/hle/kernel/k_typed_address.h" |
|
|
#include "core/hle/kernel/k_typed_address.h" |
|
|
#include "core/hle/kernel/physical_memory.h" |
|
|
#include "core/hle/kernel/physical_memory.h" |
|
|
|
|
|
#include "lru_cache.h" |
|
|
|
|
|
|
|
|
namespace Core::NCE { |
|
|
namespace Core::NCE { |
|
|
|
|
|
|
|
|
@ -60,8 +61,20 @@ private: |
|
|
void WriteCntpctHandler(ModuleDestLabel module_dest, oaknut::XReg dest_reg); |
|
|
void WriteCntpctHandler(ModuleDestLabel module_dest, oaknut::XReg dest_reg); |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
|
|
|
static constexpr size_t CACHE_SIZE = 1024; // Cache size for patch entries |
|
|
|
|
|
LRUCache<uintptr_t, PatchTextAddress> patch_cache{CACHE_SIZE}; |
|
|
|
|
|
|
|
|
void BranchToPatch(uintptr_t module_dest) { |
|
|
void BranchToPatch(uintptr_t module_dest) { |
|
|
curr_patch->m_branch_to_patch_relocations.push_back({c.offset(), module_dest}); |
|
|
|
|
|
|
|
|
// Try to get existing patch entry from cache |
|
|
|
|
|
if (auto* cached_patch = patch_cache.get(module_dest)) { |
|
|
|
|
|
curr_patch->m_branch_to_patch_relocations.push_back({c.offset(), *cached_patch}); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If not in cache, create new entry and cache it |
|
|
|
|
|
const auto patch_addr = c.offset(); |
|
|
|
|
|
curr_patch->m_branch_to_patch_relocations.push_back({patch_addr, module_dest}); |
|
|
|
|
|
patch_cache.put(module_dest, patch_addr); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void BranchToModule(uintptr_t module_dest) { |
|
|
void BranchToModule(uintptr_t module_dest) { |
|
|
|