mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-20 11:36:13 +00:00
Move HLE table address to FXO (#10284)
This commit is contained in:
parent
2e28e2d293
commit
57cd4ff3c6
9 changed files with 31 additions and 21 deletions
|
@ -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<u8>& 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<ppu_function_manager>().func_addr(sfunc->index) + 4;
|
||||
|
||||
// write stub
|
||||
vm::write32(addr, ppu_instructions::LIS(0, (target&0xFFFF0000)>>16));
|
||||
|
|
|
@ -417,7 +417,7 @@ error_code _cellGcmInitBody(ppu_thread& ppu, vm::pptr<CellGcmContextData> 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<ppu_function_manager>().func_addr(FIND_FUNC(cellGcmCallback)));
|
||||
|
||||
gcm_cfg.ctxt_addr = context.addr();
|
||||
gcm_cfg.gcm_buffers.set(vm::alloc(sizeof(CellGcmDisplayInfo) * 8, vm::main));
|
||||
|
|
|
@ -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<ppu_function_manager>().func_addr(FIND_FUNC(exit_game)));
|
||||
}
|
||||
|
||||
const error_code res = open_msg_dialog
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "stdafx.h"
|
||||
#include "PPUDisAsm.h"
|
||||
#include "PPUFunction.h"
|
||||
#include "Emu/IdManager.h"
|
||||
|
||||
const ppu_decoder<PPUDisAsm> s_ppu_disasm;
|
||||
|
||||
|
@ -2349,10 +2350,10 @@ extern std::vector<std::string> g_ppu_function_names;
|
|||
|
||||
void PPUDisAsm::UNK(ppu_opcode_t)
|
||||
{
|
||||
if (ppu_function_manager::addr)
|
||||
if (u32 addr{}; g_fxo->is_init<ppu_function_manager>() && (addr = g_fxo->get<ppu_function_manager>().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())
|
||||
{
|
||||
|
|
|
@ -1947,5 +1947,3 @@ u32 ppu_function_manager::add_function(ppu_function_t function)
|
|||
|
||||
return ::size32(list) - 1;
|
||||
}
|
||||
|
||||
DECLARE(ppu_function_manager::addr);
|
||||
|
|
|
@ -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<typename T, T Func>
|
||||
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<typename T, T Func>
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "Emu/Cell/Common.h"
|
||||
#include "Emu/Cell/PPUFunction.h"
|
||||
#include "Emu/Cell/timers.hpp"
|
||||
#include "Emu/IdManager.h"
|
||||
|
||||
#include <bit>
|
||||
#include <cmath>
|
||||
|
@ -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<ppu_function_manager>().addr) / 8;
|
||||
|
||||
const auto& hle_funcs = ppu_function_manager::get();
|
||||
|
||||
|
|
|
@ -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<ppu_function_manager>().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<ppu_function_manager>().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<ppu_function_manager>().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<ppu_function_manager>().func_addr(_sf->index) + 4;
|
||||
|
||||
// Set exported function
|
||||
flink.export_addr = target - 4;
|
||||
|
@ -654,7 +656,7 @@ static auto ppu_load_imports(std::vector<ppu_reloc>& 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<ppu_function_manager>().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<ppu_linkage_info::module_data::info*>(exp.second);
|
||||
// if (pinfo->static_func)
|
||||
// {
|
||||
// pinfo->export_addr = ppu_function_manager::func_addr(pinfo->static_func->index);
|
||||
// pinfo->export_addr = g_fxo->get<ppu_function_manager>().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<ppu_linkage_info>();
|
||||
g_fxo->need<ppu_function_manager>();
|
||||
|
||||
// Set for delayed initialization in ppu_initialize()
|
||||
auto& _main = g_fxo->get<ppu_module>();
|
||||
|
|
|
@ -784,7 +784,7 @@ std::vector<std::pair<u32, u32>> ppu_thread::dump_callstack_list() const
|
|||
}
|
||||
|
||||
// Ignore HLE stop address
|
||||
return addr == ppu_function_manager::func_addr(1) + 4;
|
||||
return addr == g_fxo->get<ppu_function_manager>().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<ppu_function_manager>().func_addr(1) + 4; // HLE stop address
|
||||
current_function = nullptr;
|
||||
|
||||
g_tls_log_prefix = []
|
||||
|
|
Loading…
Add table
Reference in a new issue