diff --git a/rpcs3/Emu/Cell/Modules/StaticHLE.cpp b/rpcs3/Emu/Cell/Modules/StaticHLE.cpp index ed3f00dcda..59c5f439e3 100644 --- a/rpcs3/Emu/Cell/Modules/StaticHLE.cpp +++ b/rpcs3/Emu/Cell/Modules/StaticHLE.cpp @@ -2,6 +2,7 @@ #include "StaticHLE.h" #include "Emu/Cell/PPUModule.h" #include "Emu/Cell/PPUOpcodes.h" +#include "Emu/IdManager.h" LOG_CHANNEL(static_hle); @@ -162,7 +163,7 @@ bool statichle_handler::check_against_patterns(vm::cptr& data, u32 size, u32 } const auto sfunc = &smodule->functions.at(pat.fnid); - const u32 target = ppu_function_manager::func_addr(sfunc->index) + 4; + const u32 target = g_fxo->get().func_addr(sfunc->index) + 4; // write stub vm::write32(addr, ppu_instructions::LIS(0, (target&0xFFFF0000)>>16)); diff --git a/rpcs3/Emu/Cell/Modules/cellGcmSys.cpp b/rpcs3/Emu/Cell/Modules/cellGcmSys.cpp index 9082637732..c230e866f8 100644 --- a/rpcs3/Emu/Cell/Modules/cellGcmSys.cpp +++ b/rpcs3/Emu/Cell/Modules/cellGcmSys.cpp @@ -417,7 +417,7 @@ error_code _cellGcmInitBody(ppu_thread& ppu, vm::pptr contex gcm_cfg.current_context.begin.set(g_defaultCommandBufferBegin + 4096); // 4 kb reserved at the beginning gcm_cfg.current_context.end.set(g_defaultCommandBufferBegin + 32 * 1024 - 4); // 4b at the end for jump gcm_cfg.current_context.current = gcm_cfg.current_context.begin; - gcm_cfg.current_context.callback.set(ppu_function_manager::func_addr(FIND_FUNC(cellGcmCallback))); + gcm_cfg.current_context.callback.set(g_fxo->get().func_addr(FIND_FUNC(cellGcmCallback))); gcm_cfg.ctxt_addr = context.addr(); gcm_cfg.gcm_buffers.set(vm::alloc(sizeof(CellGcmDisplayInfo) * 8, vm::main)); diff --git a/rpcs3/Emu/Cell/Modules/cellMsgDialog.cpp b/rpcs3/Emu/Cell/Modules/cellMsgDialog.cpp index c62e803b20..e1e6e8cc06 100644 --- a/rpcs3/Emu/Cell/Modules/cellMsgDialog.cpp +++ b/rpcs3/Emu/Cell/Modules/cellMsgDialog.cpp @@ -259,7 +259,7 @@ error_code open_exit_dialog(const std::string& message, bool is_exit_requested) if (is_exit_requested) { - callback.set(ppu_function_manager::func_addr(FIND_FUNC(exit_game))); + callback.set(g_fxo->get().func_addr(FIND_FUNC(exit_game))); } const error_code res = open_msg_dialog diff --git a/rpcs3/Emu/Cell/PPUDisAsm.cpp b/rpcs3/Emu/Cell/PPUDisAsm.cpp index 82cbbb2a04..15a5db0049 100644 --- a/rpcs3/Emu/Cell/PPUDisAsm.cpp +++ b/rpcs3/Emu/Cell/PPUDisAsm.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "PPUDisAsm.h" #include "PPUFunction.h" +#include "Emu/IdManager.h" const ppu_decoder s_ppu_disasm; @@ -2349,10 +2350,10 @@ extern std::vector g_ppu_function_names; void PPUDisAsm::UNK(ppu_opcode_t) { - if (ppu_function_manager::addr) + if (u32 addr{}; g_fxo->is_init() && (addr = g_fxo->get().addr)) { // HLE function index - const u32 index = (dump_pc - ppu_function_manager::addr) / 8; + const u32 index = (dump_pc - addr) / 8; if (dump_pc % 8 == 4 && index < ppu_function_manager::get().size()) { diff --git a/rpcs3/Emu/Cell/PPUFunction.cpp b/rpcs3/Emu/Cell/PPUFunction.cpp index 29a22a5eec..3999b10b0c 100644 --- a/rpcs3/Emu/Cell/PPUFunction.cpp +++ b/rpcs3/Emu/Cell/PPUFunction.cpp @@ -1947,5 +1947,3 @@ u32 ppu_function_manager::add_function(ppu_function_t function) return ::size32(list) - 1; } - -DECLARE(ppu_function_manager::addr); diff --git a/rpcs3/Emu/Cell/PPUFunction.h b/rpcs3/Emu/Cell/PPUFunction.h index 8c284f8423..286e45535a 100644 --- a/rpcs3/Emu/Cell/PPUFunction.h +++ b/rpcs3/Emu/Cell/PPUFunction.h @@ -262,6 +262,12 @@ class ppu_function_manager static u32 add_function(ppu_function_t function); public: + ppu_function_manager() = default; + + ppu_function_manager(const ppu_function_manager&) = delete; + + ppu_function_manager& operator=(const ppu_function_manager&) = delete; + // Register function (shall only be called during global initialization) template static inline u32 register_function(ppu_function_t func) @@ -282,7 +288,7 @@ public: return access(llvm); } - static inline u32 func_addr(u32 index) + u32 func_addr(u32 index) const { if (index >= access().size() || !addr) { @@ -293,7 +299,7 @@ public: } // Allocation address - static u32 addr; + u32 addr = 0; }; template diff --git a/rpcs3/Emu/Cell/PPUInterpreter.cpp b/rpcs3/Emu/Cell/PPUInterpreter.cpp index 5bb6abf9b5..e1e28cdeff 100644 --- a/rpcs3/Emu/Cell/PPUInterpreter.cpp +++ b/rpcs3/Emu/Cell/PPUInterpreter.cpp @@ -7,6 +7,7 @@ #include "Emu/Cell/Common.h" #include "Emu/Cell/PPUFunction.h" #include "Emu/Cell/timers.hpp" +#include "Emu/IdManager.h" #include #include @@ -5180,7 +5181,7 @@ bool ppu_interpreter::FCFID(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::UNK(ppu_thread& ppu, ppu_opcode_t op) { // HLE function index - const u32 index = (ppu.cia - ppu_function_manager::addr) / 8; + const u32 index = (ppu.cia - g_fxo->get().addr) / 8; const auto& hle_funcs = ppu_function_manager::get(); diff --git a/rpcs3/Emu/Cell/PPUModule.cpp b/rpcs3/Emu/Cell/PPUModule.cpp index e90c4920da..ffc14934ea 100644 --- a/rpcs3/Emu/Cell/PPUModule.cpp +++ b/rpcs3/Emu/Cell/PPUModule.cpp @@ -253,14 +253,16 @@ static void ppu_initialize_modules(ppu_linkage_info* link) // Initialize double-purpose fake OPD array for HLE functions const auto& hle_funcs = ppu_function_manager::get(g_cfg.core.ppu_decoder == ppu_decoder_type::llvm); + u32& hle_funcs_addr = g_fxo->get().addr; + // Allocate memory for the array (must be called after fixed allocations) - ppu_function_manager::addr = vm::alloc(::size32(hle_funcs) * 8, vm::main); + hle_funcs_addr = vm::alloc(::size32(hle_funcs) * 8, vm::main); // Initialize as PPU executable code - ppu_register_range(ppu_function_manager::addr, ::size32(hle_funcs) * 8); + ppu_register_range(hle_funcs_addr, ::size32(hle_funcs) * 8); // Fill the array (visible data: self address and function index) - for (u32 addr = ppu_function_manager::addr, index = 0; index < hle_funcs.size(); addr += 8, index++) + for (u32 addr = hle_funcs_addr, index = 0; index < hle_funcs.size(); addr += 8, index++) { // Function address = next CIA, RTOC = 0 (vm::null) vm::write32(addr + 0, addr + 4); @@ -272,7 +274,7 @@ static void ppu_initialize_modules(ppu_linkage_info* link) } // Set memory protection to read-only - vm::page_protect(ppu_function_manager::addr, utils::align(::size32(hle_funcs) * 8, 0x1000), 0, 0, vm::page_writable); + vm::page_protect(hle_funcs_addr, utils::align(::size32(hle_funcs) * 8, 0x1000), 0, 0, vm::page_writable); // Initialize function names const bool is_first = g_ppu_function_names.empty(); @@ -312,7 +314,7 @@ static void ppu_initialize_modules(ppu_linkage_info* link) auto& flink = linkage.functions[function.first]; flink.static_func = &function.second; - flink.export_addr = ppu_function_manager::func_addr(function.second.index); + flink.export_addr = g_fxo->get().func_addr(function.second.index); function.second.export_addr = &flink.export_addr; } } @@ -512,7 +514,7 @@ static auto ppu_load_exports(ppu_linkage_info* link, u32 exports_start, u32 expo // Function linkage info auto& flink = mlink.functions[fnid]; - if (flink.static_func && flink.export_addr == ppu_function_manager::func_addr(flink.static_func->index)) + if (flink.static_func && flink.export_addr == g_fxo->get().func_addr(flink.static_func->index)) { flink.export_addr = 0; } @@ -530,7 +532,7 @@ static auto ppu_load_exports(ppu_linkage_info* link, u32 exports_start, u32 expo { // Inject a branch to the HLE implementation const u32 _entry = vm::read32(faddr); - const u32 target = ppu_function_manager::func_addr(_sf->index) + 4; + const u32 target = g_fxo->get().func_addr(_sf->index) + 4; // Set exported function flink.export_addr = target - 4; @@ -654,7 +656,7 @@ static auto ppu_load_imports(std::vector& relocs, ppu_linkage_info* l mlink.imported = true; // Link address (special HLE function by default) - const u32 link_addr = flink.export_addr ? flink.export_addr : ppu_function_manager::addr; + const u32 link_addr = flink.export_addr ? flink.export_addr : g_fxo->get().addr; // Write import table vm::write32(faddr, link_addr); @@ -1177,7 +1179,7 @@ void ppu_unload_prx(const lv2_prx& prx) // auto pinfo = static_cast(exp.second); // if (pinfo->static_func) // { - // pinfo->export_addr = ppu_function_manager::func_addr(pinfo->static_func->index); + // pinfo->export_addr = g_fxo->get().func_addr(pinfo->static_func->index); // } // else if (pinfo->static_var) // { @@ -1219,6 +1221,7 @@ bool ppu_load_exec(const ppu_exec_object& elf) } g_fxo->need(); + g_fxo->need(); // Set for delayed initialization in ppu_initialize() auto& _main = g_fxo->get(); diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index dcba123184..890fc85a47 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -784,7 +784,7 @@ std::vector> ppu_thread::dump_callstack_list() const } // Ignore HLE stop address - return addr == ppu_function_manager::func_addr(1) + 4; + return addr == g_fxo->get().func_addr(1) + 4; }; if (is_invalid(addr)) @@ -1219,7 +1219,7 @@ void ppu_thread::fast_call(u32 addr, u32 rtoc) cia = addr; gpr[2] = rtoc; - lr = ppu_function_manager::func_addr(1) + 4; // HLE stop address + lr = g_fxo->get().func_addr(1) + 4; // HLE stop address current_function = nullptr; g_tls_log_prefix = []