Skip to content

Commit

Permalink
SPU LLVM: fix SPU termination (spu_escape) on Windows
Browse files Browse the repository at this point in the history
Adjust restored stack pointer for the lack of tail call.
  • Loading branch information
Nekotekina committed May 11, 2019
1 parent 49f50e3 commit aee5316
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions rpcs3/Emu/Cell/SPURecompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4123,7 +4123,11 @@ class spu_llvm_recompiler : public spu_recompiler_base, public cpu_translator
gateway->setLinkage(GlobalValue::InternalLinkage);
gateway->setCallingConv(CallingConv::GHC);

m_ir->CreateCall(gateway, {m_thread, m_lsptr, m_base_pc})->setCallingConv(gateway->getCallingConv());
const auto gway_ci = m_ir->CreateCall(gateway, {m_thread, m_lsptr, m_base_pc});
gway_ci->setCallingConv(gateway->getCallingConv());
#ifndef _WIN32
gway_ci->setTailCall();
#endif
m_ir->CreateRetVoid();
m_ir->SetInsertPoint(label_stop);
m_ir->CreateRetVoid();
Expand Down Expand Up @@ -4158,7 +4162,12 @@ class spu_llvm_recompiler : public spu_recompiler_base, public cpu_translator
escape->setLinkage(GlobalValue::InternalLinkage);
m_ir->SetInsertPoint(BasicBlock::Create(m_context, "", escape));
const auto load_sp = m_ir->CreateLoad(_ptr<u64>(&*escape->arg_begin(), ::offset32(&spu_thread::saved_native_sp)));
m_ir->CreateCall(get_intrinsic<u64>(Intrinsic::write_register), {rsp_name, load_sp});
#ifdef _WIN32
const auto rest_sp = m_ir->CreateSub(load_sp, m_ir->getInt64(8));
#else
const auto rest_sp = load_sp;
#endif
m_ir->CreateCall(get_intrinsic<u64>(Intrinsic::write_register), {rsp_name, rest_sp});
m_ir->CreateRetVoid();

// Function that executes check_state and escapes if necessary
Expand Down

0 comments on commit aee5316

Please sign in to comment.