From dc839e1784398b2bfd48cd0bd4893dca901203a3 Mon Sep 17 00:00:00 2001 From: Eladash Date: Sun, 22 Mar 2020 10:35:35 +0200 Subject: [PATCH] lv2: Do not lose r3 data on syscalls Allows to get the ID of the lv2 sync objects in the debugger by looking at r3's content. --- rpcs3/Emu/Cell/Modules/sys_spinlock.cpp | 2 +- rpcs3/Emu/Cell/PPUFunction.h | 1 + rpcs3/Emu/Cell/PPUThread.cpp | 1 + rpcs3/Emu/Cell/PPUThread.h | 1 + rpcs3/Emu/Cell/lv2/sys_event_flag.cpp | 3 ++- 5 files changed, 6 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/sys_spinlock.cpp b/rpcs3/Emu/Cell/Modules/sys_spinlock.cpp index 51b93cbdc6..9f76ed9634 100644 --- a/rpcs3/Emu/Cell/Modules/sys_spinlock.cpp +++ b/rpcs3/Emu/Cell/Modules/sys_spinlock.cpp @@ -28,7 +28,7 @@ error_code sys_spinlock_lock(ppu_thread& ppu, vm::ptr> lock) } } - return not_an_error(ppu.gpr[3]); + return CELL_OK; } s32 sys_spinlock_trylock(vm::ptr> lock) diff --git a/rpcs3/Emu/Cell/PPUFunction.h b/rpcs3/Emu/Cell/PPUFunction.h index d8cacce8e9..ec58e4b60b 100644 --- a/rpcs3/Emu/Cell/PPUFunction.h +++ b/rpcs3/Emu/Cell/PPUFunction.h @@ -9,6 +9,7 @@ using ppu_function_t = bool(*)(ppu_thread&); const auto old_f = ppu.current_function;\ if (!old_f) ppu.last_function = #func;\ ppu.current_function = #func;\ + ppu.syscall_r3 = ppu.gpr[3];\ ppu_func_detail::do_call(ppu, func);\ ppu.current_function = old_f;\ ppu.cia += 4;\ diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index aaa701b18e..e7e8e8341e 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -432,6 +432,7 @@ std::string ppu_thread::dump() const ret += "Current function: "; ret += _func; ret += '\n'; + fmt::append(ret, "syscall r3: 0x%llx\n", syscall_r3); } else if (is_paused()) { diff --git a/rpcs3/Emu/Cell/PPUThread.h b/rpcs3/Emu/Cell/PPUThread.h index b2799490c6..ce134e3db7 100644 --- a/rpcs3/Emu/Cell/PPUThread.h +++ b/rpcs3/Emu/Cell/PPUThread.h @@ -189,6 +189,7 @@ public: cmd64 cmd_get(u32 index) { return cmd_queue[cmd_queue.peek() + index].load(); } u64 start_time{0}; // Sleep start timepoint + u64 syscall_r3{0}; // Save r3 before syscalls const char* current_function{}; // Current function name for diagnosis, optimized for speed. const char* last_function{}; // Sticky copy of current_function, is not cleared on function return diff --git a/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp b/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp index af465326fb..d36921902d 100644 --- a/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp @@ -95,13 +95,14 @@ error_code sys_event_flag_wait(ppu_thread& ppu, u32 id, u64 bitptn, u32 mode, vm sys_event_flag.trace("sys_event_flag_wait(id=0x%x, bitptn=0x%llx, mode=0x%x, result=*0x%x, timeout=0x%llx)", id, bitptn, mode, result, timeout); // Fix function arguments for external access + // TODO: Avoid using registers ppu.gpr[3] = -1; ppu.gpr[4] = bitptn; ppu.gpr[5] = mode; ppu.gpr[6] = 0; // Always set result - if (result) *result = ppu.gpr[6]; + if (result) *result = 0; if (!lv2_event_flag::check_mode(mode)) {