From 942d984dc57109e5fc5592c3e25983619769c5ca Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sat, 28 Feb 2015 17:41:15 +0300 Subject: [PATCH] sys_process_get_paramsfo implemented --- Utilities/Thread.cpp | 24 ++++++++--------- rpcs3/Emu/Cell/SPUThread.cpp | 2 +- rpcs3/Emu/Memory/vm.cpp | 6 ++--- rpcs3/Emu/Memory/vm.h | 6 ++--- rpcs3/Emu/Memory/vm_ptr.h | 12 ++++----- rpcs3/Emu/SysCalls/Modules/cellSpursSpu.cpp | 22 ++++++++-------- rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp | 11 ++++---- rpcs3/Emu/SysCalls/SysCalls.cpp | 2 +- rpcs3/Emu/SysCalls/lv2/sys_process.cpp | 27 ++++++++------------ rpcs3/Emu/SysCalls/lv2/sys_process.h | 2 +- rpcs3/Emu/System.cpp | 19 +------------- rpcs3/Emu/System.h | 6 ++--- rpcs3/Gui/GLGSFrame.cpp | 2 +- rpcs3/Loader/ELF64.cpp | 3 --- 14 files changed, 58 insertions(+), 86 deletions(-) diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index 54f032bdbd..0bb5ece45a 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -832,7 +832,7 @@ bool handle_access_violation(u32 addr, bool is_writing, x64_context* context) return false; } - memcpy(vm::get_priv_ptr(addr), XMMREG(context, reg - X64R_XMM0), 16); + memcpy(vm::priv_ptr(addr), XMMREG(context, reg - X64R_XMM0), 16); break; } @@ -842,7 +842,7 @@ bool handle_access_violation(u32 addr, bool is_writing, x64_context* context) return false; } - memcpy(vm::get_priv_ptr(addr), ®_value, d_size); + memcpy(vm::priv_ptr(addr), ®_value, d_size); break; } case X64OP_MOVS: @@ -867,7 +867,7 @@ bool handle_access_violation(u32 addr, bool is_writing, x64_context* context) // copy data memcpy(&value, (void*)RSI(context), d_size); - memcpy(vm::get_priv_ptr(a_addr), &value, d_size); + memcpy(vm::priv_ptr(a_addr), &value, d_size); // shift pointers if (EFLAGS(context) & 0x400 /* direction flag */) @@ -925,7 +925,7 @@ bool handle_access_violation(u32 addr, bool is_writing, x64_context* context) while (a_addr >> 12 == addr >> 12) { // fill data with value - memcpy(vm::get_priv_ptr(a_addr), &value, d_size); + memcpy(vm::priv_ptr(a_addr), &value, d_size); // shift pointers if (EFLAGS(context) & 0x400 /* direction flag */) @@ -966,10 +966,10 @@ bool handle_access_violation(u32 addr, bool is_writing, x64_context* context) switch (d_size) { - case 1: reg_value = vm::get_priv_ref>(addr).exchange((u8)reg_value); break; - case 2: reg_value = vm::get_priv_ref>(addr).exchange((u16)reg_value); break; - case 4: reg_value = vm::get_priv_ref>(addr).exchange((u32)reg_value); break; - case 8: reg_value = vm::get_priv_ref>(addr).exchange((u64)reg_value); break; + case 1: reg_value = vm::priv_ref>(addr).exchange((u8)reg_value); break; + case 2: reg_value = vm::priv_ref>(addr).exchange((u16)reg_value); break; + case 4: reg_value = vm::priv_ref>(addr).exchange((u32)reg_value); break; + case 8: reg_value = vm::priv_ref>(addr).exchange((u64)reg_value); break; default: return false; } @@ -989,10 +989,10 @@ bool handle_access_violation(u32 addr, bool is_writing, x64_context* context) switch (d_size) { - case 1: old_value = vm::get_priv_ref>(addr).compare_and_swap((u8)cmp_value, (u8)reg_value); break; - case 2: old_value = vm::get_priv_ref>(addr).compare_and_swap((u16)cmp_value, (u16)reg_value); break; - case 4: old_value = vm::get_priv_ref>(addr).compare_and_swap((u32)cmp_value, (u32)reg_value); break; - case 8: old_value = vm::get_priv_ref>(addr).compare_and_swap((u64)cmp_value, (u64)reg_value); break; + case 1: old_value = vm::priv_ref>(addr).compare_and_swap((u8)cmp_value, (u8)reg_value); break; + case 2: old_value = vm::priv_ref>(addr).compare_and_swap((u16)cmp_value, (u16)reg_value); break; + case 4: old_value = vm::priv_ref>(addr).compare_and_swap((u32)cmp_value, (u32)reg_value); break; + case 8: old_value = vm::priv_ref>(addr).compare_and_swap((u64)cmp_value, (u64)reg_value); break; default: return false; } diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index c986098d88..0f044d4994 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -410,7 +410,7 @@ void SPUThread::EnqMfcCmd(MFCReg& MFCArgs) { vm::reservation_op(vm::cast(ea), 128, [this, tag, lsa, ea]() { - memcpy(vm::get_priv_ptr(vm::cast(ea)), vm::get_ptr(ls_offset + lsa), 128); + memcpy(vm::priv_ptr(vm::cast(ea)), vm::get_ptr(ls_offset + lsa), 128); }); if (op == MFC_PUTLLUC_CMD) diff --git a/rpcs3/Emu/Memory/vm.cpp b/rpcs3/Emu/Memory/vm.cpp index 93b0482422..9939033bdc 100644 --- a/rpcs3/Emu/Memory/vm.cpp +++ b/rpcs3/Emu/Memory/vm.cpp @@ -264,7 +264,7 @@ namespace vm _reservation_set(addr, true); // update memory using privileged access - memcpy(vm::get_priv_ptr(addr), data, size); + memcpy(vm::priv_ptr(addr), data, size); // remove callback to not call it on successful update g_reservation_cb = nullptr; @@ -362,7 +362,7 @@ namespace vm } void* real_addr = vm::get_ptr(addr); - void* priv_addr = vm::get_priv_ptr(addr); + void* priv_addr = vm::priv_ptr(addr); #ifdef _WIN32 auto protection = flags & page_writable ? PAGE_READWRITE : (flags & page_readable ? PAGE_READONLY : PAGE_NOACCESS); @@ -464,7 +464,7 @@ namespace vm } void* real_addr = vm::get_ptr(addr); - void* priv_addr = vm::get_priv_ptr(addr); + void* priv_addr = vm::priv_ptr(addr); #ifdef _WIN32 DWORD old; diff --git a/rpcs3/Emu/Memory/vm.h b/rpcs3/Emu/Memory/vm.h index 0df015a82e..73ae618404 100644 --- a/rpcs3/Emu/Memory/vm.h +++ b/rpcs3/Emu/Memory/vm.h @@ -77,15 +77,15 @@ namespace vm } template - T* const get_priv_ptr(u32 addr) + T* const priv_ptr(u32 addr) { return reinterpret_cast(static_cast(g_priv_addr) + addr); } template - T& get_priv_ref(u32 addr) + T& priv_ref(u32 addr) { - return *get_priv_ptr(addr); + return *priv_ptr(addr); } u32 get_addr(const void* real_pointer); diff --git a/rpcs3/Emu/Memory/vm_ptr.h b/rpcs3/Emu/Memory/vm_ptr.h index 68d940ea6b..be49e8a42d 100644 --- a/rpcs3/Emu/Memory/vm_ptr.h +++ b/rpcs3/Emu/Memory/vm_ptr.h @@ -214,9 +214,9 @@ namespace vm return vm::get_ptr(vm::cast(m_addr)); } - T* get_priv_ptr() const + T* priv_ptr() const { - return vm::get_priv_ptr(vm::cast(m_addr)); + return vm::priv_ptr(vm::cast(m_addr)); } static const _ptr_base make(const AT& addr) @@ -248,9 +248,9 @@ namespace vm return vm::get_ptr(vm::cast(m_addr)); } - void* get_priv_ptr() const + void* priv_ptr() const { - return vm::get_priv_ptr(vm::cast(m_addr)); + return vm::priv_ptr(vm::cast(m_addr)); } explicit operator void*() const @@ -311,9 +311,9 @@ namespace vm return vm::get_ptr(vm::cast(m_addr)); } - const void* get_priv_ptr() const + const void* priv_ptr() const { - return vm::get_priv_ptr(vm::cast(m_addr)); + return vm::priv_ptr(vm::cast(m_addr)); } explicit operator const void*() const diff --git a/rpcs3/Emu/SysCalls/Modules/cellSpursSpu.cpp b/rpcs3/Emu/SysCalls/Modules/cellSpursSpu.cpp index 25c2911a8f..51a64ef198 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSpursSpu.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSpursSpu.cpp @@ -168,7 +168,7 @@ bool spursKernel1SelectWorkload(SPUThread & spu) { vm::reservation_op(vm::cast(ctxt->spurs.addr()), 128, [&]() { // lock the first 0x80 bytes of spurs - auto spurs = ctxt->spurs.get_priv_ptr(); + auto spurs = ctxt->spurs.priv_ptr(); // Calculate the contention (number of SPUs used) for each workload u8 contention[CELL_SPURS_MAX_WORKLOAD]; @@ -325,7 +325,7 @@ bool spursKernel2SelectWorkload(SPUThread & spu) { vm::reservation_op(vm::cast(ctxt->spurs.addr()), 128, [&]() { // lock the first 0x80 bytes of spurs - auto spurs = ctxt->spurs.get_priv_ptr(); + auto spurs = ctxt->spurs.priv_ptr(); // Calculate the contention (number of SPUs used) for each workload u8 contention[CELL_SPURS_MAX_WORKLOAD2]; @@ -696,7 +696,7 @@ void spursSysServiceMain(SPUThread & spu, u32 pollStatus) { vm::reservation_acquire(vm::get_ptr(spu.ls_offset + 0x100), vm::cast(ctxt->spurs.addr()), 128); vm::reservation_op(vm::cast(ctxt->spurs.addr() + offsetof(CellSpurs, m.wklState1)), 128, [&]() { - auto spurs = ctxt->spurs.get_priv_ptr(); + auto spurs = ctxt->spurs.priv_ptr(); // Halt if already initialised if (spurs->m.sysSrvOnSpu & (1 << ctxt->spuNum)) { @@ -786,7 +786,7 @@ void spursSysServiceProcessRequests(SPUThread & spu, SpursKernelContext * ctxt) bool terminate = false; vm::reservation_op(vm::cast(ctxt->spurs.addr() + offsetof(CellSpurs, m.wklState1)), 128, [&]() { - auto spurs = ctxt->spurs.get_priv_ptr(); + auto spurs = ctxt->spurs.priv_ptr(); // Terminate request if (spurs->m.sysSrvMsgTerminate & (1 << ctxt->spuNum)) { @@ -853,7 +853,7 @@ void spursSysServiceActivateWorkload(SPUThread & spu, SpursKernelContext * ctxt) } vm::reservation_op(vm::cast(ctxt->spurs.addr() + offsetof(CellSpurs, m.wklState1)), 128, [&]() { - auto spurs = ctxt->spurs.get_priv_ptr(); + auto spurs = ctxt->spurs.priv_ptr(); for (u32 i = 0; i < CELL_SPURS_MAX_WORKLOAD; i++) { // Update workload status and runnable flag based on the workload state @@ -910,7 +910,7 @@ void spursSysServiceUpdateShutdownCompletionEvents(SPUThread & spu, SpursKernelC u32 wklNotifyBitSet; u8 spuPort; vm::reservation_op(vm::cast(ctxt->spurs.addr() + offsetof(CellSpurs, m.wklState1)), 128, [&]() { - auto spurs = ctxt->spurs.get_priv_ptr(); + auto spurs = ctxt->spurs.priv_ptr(); wklNotifyBitSet = 0; spuPort = spurs->m.spuPort;; @@ -952,7 +952,7 @@ void spursSysServiceTraceUpdate(SPUThread & spu, SpursKernelContext * ctxt, u32 u8 sysSrvMsgUpdateTrace; vm::reservation_op(vm::cast(ctxt->spurs.addr() + offsetof(CellSpurs, m.wklState1)), 128, [&]() { - auto spurs = ctxt->spurs.get_priv_ptr(); + auto spurs = ctxt->spurs.priv_ptr(); sysSrvMsgUpdateTrace = spurs->m.sysSrvMsgUpdateTrace; spurs->m.sysSrvMsgUpdateTrace &= ~(1 << ctxt->spuNum); @@ -1006,7 +1006,7 @@ void spursSysServiceCleanupAfterSystemWorkload(SPUThread & spu, SpursKernelConte bool do_return = false; vm::reservation_op(vm::cast(ctxt->spurs.addr() + offsetof(CellSpurs, m.wklState1)), 128, [&]() { - auto spurs = ctxt->spurs.get_priv_ptr(); + auto spurs = ctxt->spurs.priv_ptr(); if (spurs->m.sysSrvWorkload[ctxt->spuNum] == 0xFF) { do_return = true; @@ -1024,7 +1024,7 @@ void spursSysServiceCleanupAfterSystemWorkload(SPUThread & spu, SpursKernelConte spursSysServiceActivateWorkload(spu, ctxt); vm::reservation_op(vm::cast(ctxt->spurs.addr()), 128, [&]() { - auto spurs = ctxt->spurs.get_priv_ptr(); + auto spurs = ctxt->spurs.priv_ptr(); if (wklId >= CELL_SPURS_MAX_WORKLOAD) { spurs->m.wklCurrentContention[wklId & 0x0F] -= 0x10; @@ -1158,7 +1158,7 @@ s32 spursTasksetProcessRequest(SPUThread & spu, s32 request, u32 * taskId, u32 * s32 rc = CELL_OK; s32 numNewlyReadyTasks; vm::reservation_op(vm::cast(ctxt->taskset.addr()), 128, [&]() { - auto taskset = ctxt->taskset.get_priv_ptr(); + auto taskset = ctxt->taskset.priv_ptr(); // Verify taskset state is valid auto _0 = be_t::make(u128::from32(0)); @@ -1299,7 +1299,7 @@ s32 spursTasksetProcessRequest(SPUThread & spu, s32 request, u32 * taskId, u32 * // Increment the ready count of the workload by the number of tasks that have become ready vm::reservation_op(vm::cast(kernelCtxt->spurs.addr()), 128, [&]() { - auto spurs = kernelCtxt->spurs.get_priv_ptr(); + auto spurs = kernelCtxt->spurs.priv_ptr(); s32 readyCount = kernelCtxt->wklCurrentId < CELL_SPURS_MAX_WORKLOAD ? spurs->m.wklReadyCount1[kernelCtxt->wklCurrentId].read_relaxed() : spurs->m.wklIdleSpuCountOrReadyCount2[kernelCtxt->wklCurrentId & 0x0F].read_relaxed(); readyCount += numNewlyReadyTasks; diff --git a/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp b/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp index ee1d0e0e7c..bb6482a913 100644 --- a/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp @@ -559,13 +559,12 @@ s32 _sys_printf(vm::ptr fmt) // va_args... return CELL_OK; } -s32 _nid_E75C40F2(u32 dest) +s32 sys_process_get_paramsfo(vm::ptr buffer) { - sysPrxForUser.Todo("Unnamed function 0xE75C40F2 (dest=0x%x) -> CELL_ENOENT", dest); + sysPrxForUser.Warning("sys_process_get_paramsfo(buffer=0x%x)", buffer); - // prx: load some data (0x40 bytes) previously set by sys_process_get_paramsfo - //memset(Memory + dest, 0, 0x40); - return CELL_ENOENT; + // prx: load some data (0x40 bytes) previously set by _sys_process_get_paramsfo syscall + return _sys_process_get_paramsfo(buffer); } Module sysPrxForUser("sysPrxForUser", []() @@ -674,5 +673,5 @@ Module sysPrxForUser("sysPrxForUser", []() REG_FUNC(sysPrxForUser, _sys_printf); - REG_UNNAMED(sysPrxForUser, E75C40F2); + REG_FUNC(sysPrxForUser, sys_process_get_paramsfo); }); diff --git a/rpcs3/Emu/SysCalls/SysCalls.cpp b/rpcs3/Emu/SysCalls/SysCalls.cpp index 2adbd38fd2..6d1d7086a9 100644 --- a/rpcs3/Emu/SysCalls/SysCalls.cpp +++ b/rpcs3/Emu/SysCalls/SysCalls.cpp @@ -80,7 +80,7 @@ const ppu_func_caller sc_table[1024] = null_func,//bind_func(), //27 (0x01B) DBG null_func,//bind_func(_sys_process_get_number_of_object)//28 (0x01C) ROOT bind_func(sys_process_get_id), //29 (0x01D) ROOT - bind_func(sys_process_get_paramsfo), //30 (0x01E) + bind_func(_sys_process_get_paramsfo), //30 (0x01E) null_func,//bind_func(sys_process_get_ppu_guid), //31 (0x01F) null_func, null_func, null_func, null_func, null_func, null_func, null_func, null_func, null_func, //32-40 UNS diff --git a/rpcs3/Emu/SysCalls/lv2/sys_process.cpp b/rpcs3/Emu/SysCalls/lv2/sys_process.cpp index ccbe619bee..ad088ab503 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_process.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_process.cpp @@ -4,6 +4,8 @@ #include "Emu/System.h" #include "Emu/SysCalls/SysCalls.h" +#include "Emu/FS/vfsFile.h" +#include "Loader/PSF.h" #include "sys_memory.h" #include "sys_process.h" @@ -286,29 +288,20 @@ s32 sys_process_is_spu_lock_line_reservation_address(u32 addr, u64 flags) return process_is_spu_lock_line_reservation_address(addr, flags); } -s32 sys_process_get_paramsfo(vm::ptr buffer) +s32 _sys_process_get_paramsfo(vm::ptr buffer) { - sys_process.Todo("sys_process_get_paramsfo(buffer_addr=0x%x) -> CELL_ENOENT", buffer.addr()); + sys_process.Warning("_sys_process_get_paramsfo(buffer=0x%x)", buffer); + + memset(buffer.get_ptr(), 0, 0x40); + memcpy(buffer.get_ptr(), Emu.GetTitleID().c_str(), Emu.GetTitleID().length()); + return CELL_ENOENT; - - /*//Before uncommenting this code, we should check if it is actually working. - MemoryAllocator> fd; - char filePath [] = "/app_home/../PARAM.SFO"; - if (!cellFsOpen(Memory.RealToVirtualAddr(filePath), 0, fd, NULL, 0)) - return CELL_ENOENT; - - MemoryAllocator> pos, nread; - cellFsLseek(fd, 0, CELL_SEEK_SET, pos); //TODO: Move to the appropriate offset (probably 0x3F7) - cellFsRead(fd, buffer.addr(), 40, nread); //WARNING: If offset==0x3F7: The file will end before the buffer (40 bytes) is filled! - cellFsClose(fd); - - return CELL_OK;*/ } s32 process_get_sdk_version(u32 pid, s32& ver) { - // TODO: get correct SDK version for selected pid - ver = Emu.m_sdk_version; + // get correct SDK version for selected pid + ver = Emu.GetSDKVersion(); return CELL_OK; } diff --git a/rpcs3/Emu/SysCalls/lv2/sys_process.h b/rpcs3/Emu/SysCalls/lv2/sys_process.h index e7a1240444..e0a8f78bf7 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_process.h +++ b/rpcs3/Emu/SysCalls/lv2/sys_process.h @@ -33,7 +33,7 @@ s32 sys_process_getpid(); s32 sys_process_getppid(); s32 sys_process_get_number_of_object(u32 object, vm::ptr nump); s32 sys_process_get_id(u32 object, vm::ptr buffer, u32 size, vm::ptr set_size); -s32 sys_process_get_paramsfo(vm::ptr buffer); +s32 _sys_process_get_paramsfo(vm::ptr buffer); s32 sys_process_get_sdk_version(u32 pid, vm::ptr version); s32 sys_process_get_status(u64 unk); s32 sys_process_is_spu_lock_line_reservation_address(u32 addr, u64 flags); diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index aad29e36da..13cab011e9 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -255,24 +255,7 @@ void Emulator::Load() vm::close(); return; } - - // trying to load some info from PARAM.SFO - vfsFile f2("/app_home/../PARAM.SFO"); - if (f2.IsOpened()) - { - PSFLoader psf(f2); - if (psf.Load(false)) - { - std::string version = psf.GetString("PS3_SYSTEM_VER"); - - const size_t dot = version.find('.'); - if (dot != std::string::npos) - { - Emu.m_sdk_version = (std::stoi(version, nullptr, 16) << 20) | ((std::stoi(version.substr(dot + 1), nullptr, 16) & 0xffff) << 4) | 1; - } - } - } - + LoadPoints(BreakPointsDBName); m_status = Ready; diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index e6d0a6d9c1..deeb613e67 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -103,7 +103,6 @@ public: std::string m_emu_path; std::string m_title_id; std::string m_title; - s32 m_sdk_version; Emulator(); ~Emulator(); @@ -123,12 +122,12 @@ public: return m_emu_path; } - std::string GetTitleID() const + const std::string& GetTitleID() const { return m_title_id; } - std::string GetTitle() const + const std::string& GetTitle() const { return m_title; } @@ -177,6 +176,7 @@ public: u32 GetTLSMemsz() const { return m_info.GetTLSMemsz(); } u32 GetMallocPageSize() { return m_info.GetProcParam().malloc_pagesize; } + u32 GetSDKVersion() { return m_info.GetProcParam().sdk_version; } u32 GetRSXCallback() const { return m_rsx_callback; } u32 GetCPUThreadStop() const { return m_cpu_thr_stop; } diff --git a/rpcs3/Gui/GLGSFrame.cpp b/rpcs3/Gui/GLGSFrame.cpp index 0051364a08..432f88e43c 100644 --- a/rpcs3/Gui/GLGSFrame.cpp +++ b/rpcs3/Gui/GLGSFrame.cpp @@ -62,7 +62,7 @@ void GLGSFrame::Flip(void* context) canvas->SwapBuffers(); m_frames++; - const std::string sub_title = Emu.GetTitle() += Emu.GetTitleID().length() ? " [" + Emu.GetTitleID() + "] | " : " | "; + const std::string sub_title = Emu.GetTitle() + (Emu.GetTitleID().length() ? " [" + Emu.GetTitleID() + "] | " : " | "); if (fps_t.GetElapsedTimeInSec() >= 0.5) { diff --git a/rpcs3/Loader/ELF64.cpp b/rpcs3/Loader/ELF64.cpp index cdf1a4223f..fd06566207 100644 --- a/rpcs3/Loader/ELF64.cpp +++ b/rpcs3/Loader/ELF64.cpp @@ -307,8 +307,6 @@ namespace loader return load_sprx(info); } - Emu.m_sdk_version = -1; - //store elf to memory vm::ps3::init(); @@ -618,7 +616,6 @@ namespace loader */ info = proc_param.info; - Emu.m_sdk_version = info.sdk_version; } } break;