Skip to content

Commit

Permalink
Remove BLR in HLE access
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 committed Apr 16, 2019
1 parent b7f2c8b commit 2c599de
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/Modules/StaticHLE.cpp
Expand Up @@ -162,7 +162,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::addr + 8 * sfunc->index;
const u32 target = ppu_function_manager::addr + 4 * sfunc->index;

// write stub
vm::write32(addr, ppu_instructions::LIS(0, (target&0xFFFF0000)>>16));
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/Modules/cellGcmSys.cpp
Expand Up @@ -424,7 +424,7 @@ s32 _cellGcmInitBody(ppu_thread& ppu, vm::pptr<CellGcmContextData> context, u32
m_config->current_context.begin.set(g_defaultCommandBufferBegin + 4096); // 4 kb reserved at the beginning
m_config->current_context.end.set(g_defaultCommandBufferBegin + 32 * 1024 - 4); // 4b at the end for jump
m_config->current_context.current = m_config->current_context.begin;
m_config->current_context.callback.set(ppu_function_manager::addr + 8 * FIND_FUNC(cellGcmCallback));
m_config->current_context.callback.set(ppu_function_manager::addr + 4 * FIND_FUNC(cellGcmCallback));

m_config->ctxt_addr = context.addr();
m_config->gcm_buffers.set(vm::alloc(sizeof(CellGcmDisplayInfo) * 8, vm::main));
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/Modules/cellMsgDialog.cpp
Expand Up @@ -82,7 +82,7 @@ error_code open_exit_dialog(const std::string& message, bool is_exit_requested)

if (is_exit_requested)
{
callback.set(ppu_function_manager::addr + 8 * FIND_FUNC(exit_game));
callback.set(ppu_function_manager::addr + 4 * FIND_FUNC(exit_game));
}

const error_code res = open_msg_dialog
Expand Down
20 changes: 9 additions & 11 deletions rpcs3/Emu/Cell/PPUModule.cpp
Expand Up @@ -271,25 +271,23 @@ static void ppu_initialize_modules(const std::shared_ptr<ppu_linkage_info>& link
const auto& hle_funcs = ppu_function_manager::get();

// Allocate memory for the array (must be called after fixed allocations)
ppu_function_manager::addr = vm::alloc(::size32(hle_funcs) * 8, vm::main);
ppu_function_manager::addr = vm::alloc(::size32(hle_funcs) * 4, vm::main);

// Initialize as PPU executable code
ppu_register_range(ppu_function_manager::addr, ::size32(hle_funcs) * 8);
ppu_register_range(ppu_function_manager::addr, ::size32(hle_funcs) * 4);

// 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 = ppu_function_manager::addr, index = 0; index < hle_funcs.size(); addr += 4, index++)
{
// Function address = current address, RTOC = BLR instruction for the interpreter
// Function address = current address
vm::write32(addr + 0, addr);
vm::write32(addr + 4, ppu_instructions::BLR());

// Register the HLE function directly
ppu_register_function_at(addr + 0, 4, hle_funcs[index]);
ppu_register_function_at(addr + 4, 4, nullptr);
}

// Set memory protection to read-only
vm::page_protect(ppu_function_manager::addr, ::align(::size32(hle_funcs) * 8, 0x1000), 0, 0, vm::page_writable);
vm::page_protect(ppu_function_manager::addr, ::align(::size32(hle_funcs) * 4, 0x1000), 0, 0, vm::page_writable);

// Initialize function names
const bool is_first = g_ppu_function_names.empty();
Expand Down Expand Up @@ -329,7 +327,7 @@ static void ppu_initialize_modules(const std::shared_ptr<ppu_linkage_info>& link
auto& flink = linkage.functions[function.first];

flink.static_func = &function.second;
flink.export_addr = ppu_function_manager::addr + 8 * function.second.index;
flink.export_addr = ppu_function_manager::addr + 4 * function.second.index;
function.second.export_addr = &flink.export_addr;
}
}
Expand Down Expand Up @@ -533,7 +531,7 @@ static auto ppu_load_exports(const std::shared_ptr<ppu_linkage_info>& link, u32
// Function linkage info
auto& flink = mlink.functions[fnid];

if (flink.static_func && flink.export_addr == ppu_function_manager::addr + 8 * flink.static_func->index)
if (flink.static_func && flink.export_addr == ppu_function_manager::addr + 4 * flink.static_func->index)
{
flink.export_addr = 0;
}
Expand All @@ -551,7 +549,7 @@ static auto ppu_load_exports(const std::shared_ptr<ppu_linkage_info>& link, u32
{
// Inject a branch to the HLE implementation
const u32 _entry = vm::read32(faddr);
const u32 target = ppu_function_manager::addr + 8 * _sf->index;
const u32 target = ppu_function_manager::addr + 4 * _sf->index;

if ((target <= _entry && _entry - target <= 0x2000000) || (target > _entry && target - _entry < 0x2000000))
{
Expand Down Expand Up @@ -1021,7 +1019,7 @@ void ppu_unload_prx(const lv2_prx& prx)
// auto pinfo = static_cast<ppu_linkage_info::module::info*>(exp.second);
// if (pinfo->static_func)
// {
// pinfo->export_addr = ppu_function_manager::addr + 8 * pinfo->static_func->index;
// pinfo->export_addr = ppu_function_manager::addr + 4 * pinfo->static_func->index;
// }
// else if (pinfo->static_var)
// {
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/PPUThread.cpp
Expand Up @@ -818,7 +818,7 @@ void ppu_thread::fast_call(u32 addr, u32 rtoc)

cia = addr;
gpr[2] = rtoc;
lr = ppu_function_manager::addr + 8; // HLE stop address
lr = ppu_function_manager::addr + 4; // HLE stop address
last_function = nullptr;

g_tls_log_prefix = []
Expand Down

0 comments on commit 2c599de

Please sign in to comment.