From a74fd27e3da4bf228c54a6840990921edeff1667 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sat, 11 May 2019 13:57:34 +0300 Subject: [PATCH] SPU LLVM: fix SPU termination (spu_escape) on Windows Adjust restored stack pointer for the lack of tail call. --- rpcs3/Emu/Cell/SPURecompiler.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rpcs3/Emu/Cell/SPURecompiler.cpp b/rpcs3/Emu/Cell/SPURecompiler.cpp index a7198c746f..04bb2474d8 100644 --- a/rpcs3/Emu/Cell/SPURecompiler.cpp +++ b/rpcs3/Emu/Cell/SPURecompiler.cpp @@ -4134,6 +4134,11 @@ public: gateway->setLinkage(GlobalValue::InternalLinkage); gateway->setCallingConv(CallingConv::GHC); + // Save host thread's stack pointer + const auto native_sp = spu_ptr(&spu_thread::saved_native_sp); + const auto rsp_name = MetadataAsValue::get(m_context, MDNode::get(m_context, {MDString::get(m_context, "rsp")})); + m_ir->CreateStore(m_ir->CreateCall(get_intrinsic(Intrinsic::read_register), {rsp_name}), native_sp); + m_ir->CreateCall(gateway, {m_thread, m_lsptr, m_base_pc})->setCallingConv(gateway->getCallingConv()); m_ir->CreateRetVoid(); m_ir->SetInsertPoint(label_stop); @@ -4155,11 +4160,6 @@ public: set_function(gateway); - // Save host thread's stack pointer in the gateway - const auto native_sp = spu_ptr(&spu_thread::saved_native_sp); - const auto rsp_name = MetadataAsValue::get(m_context, MDNode::get(m_context, {MDString::get(m_context, "rsp")})); - m_ir->CreateStore(m_ir->CreateCall(get_intrinsic(Intrinsic::read_register), {rsp_name}), native_sp); - // Call the entry function chunk const auto entry_chunk = add_function(m_pos); tail_chunk(entry_chunk->chunk); @@ -4169,7 +4169,7 @@ public: escape->setLinkage(GlobalValue::InternalLinkage); m_ir->SetInsertPoint(BasicBlock::Create(m_context, "", escape)); const auto load_sp = m_ir->CreateLoad(_ptr(&*escape->arg_begin(), ::offset32(&spu_thread::saved_native_sp))); - m_ir->CreateCall(get_intrinsic(Intrinsic::write_register), {rsp_name, load_sp}); + m_ir->CreateCall(get_intrinsic(Intrinsic::write_register), {rsp_name, m_ir->CreateSub(load_sp, m_ir->getInt64(8))}); m_ir->CreateRetVoid(); // Function that executes check_state and escapes if necessary