From df6607e2367f182505e35f67ceaa0501c83b5d4d Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sat, 20 Aug 2016 00:14:10 +0300 Subject: [PATCH] Minor fixes --- rpcs3/Emu/Cell/Modules/cellFs.cpp | 2 + rpcs3/Emu/Cell/Modules/cellOvis.cpp | 2 + rpcs3/Emu/Cell/Modules/cellSpudll.cpp | 2 + rpcs3/Emu/Cell/Modules/cellSpursSpu.cpp | 1 + rpcs3/Emu/Cell/Modules/libsnd3.h | 2 + rpcs3/Emu/Cell/Modules/libsynth2.cpp | 2 + rpcs3/Emu/Cell/Modules/sys_libc.cpp | 2 + rpcs3/Emu/Cell/Modules/sys_libc_.cpp | 2 + rpcs3/Emu/Cell/Modules/sys_ppu_thread_.cpp | 4 +- rpcs3/Emu/Cell/PPUAnalyser.cpp | 2 + rpcs3/Emu/Cell/PPUModule.cpp | 2 + rpcs3/Emu/Cell/PPUModule.h | 6 +- rpcs3/Emu/Cell/PPUThread.cpp | 2 + rpcs3/Emu/Cell/SPUThread.cpp | 5 +- rpcs3/Emu/Cell/lv2/sys_cond.cpp | 2 + rpcs3/Emu/Cell/lv2/sys_cond.h | 2 +- rpcs3/Emu/Cell/lv2/sys_dbg.cpp | 2 + rpcs3/Emu/Cell/lv2/sys_dbg.h | 2 - rpcs3/Emu/Cell/lv2/sys_event.cpp | 2 + rpcs3/Emu/Cell/lv2/sys_event.h | 10 +- rpcs3/Emu/Cell/lv2/sys_event_flag.cpp | 2 + rpcs3/Emu/Cell/lv2/sys_event_flag.h | 10 +- rpcs3/Emu/Cell/lv2/sys_interrupt.cpp | 2 + rpcs3/Emu/Cell/lv2/sys_interrupt.h | 4 +- rpcs3/Emu/Cell/lv2/sys_lwmutex.cpp | 2 + rpcs3/Emu/Cell/lv2/sys_lwmutex.h | 2 +- rpcs3/Emu/Cell/lv2/sys_memory.cpp | 30 +-- rpcs3/Emu/Cell/lv2/sys_mmapper.cpp | 30 +-- rpcs3/Emu/Cell/lv2/sys_mutex.cpp | 2 + rpcs3/Emu/Cell/lv2/sys_mutex.h | 2 +- rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp | 2 + rpcs3/Emu/Cell/lv2/sys_ppu_thread.h | 12 +- rpcs3/Emu/Cell/lv2/sys_process.cpp | 7 +- rpcs3/Emu/Cell/lv2/sys_process.h | 16 +- rpcs3/Emu/Cell/lv2/sys_prx.cpp | 2 + rpcs3/Emu/Cell/lv2/sys_prx.h | 40 ++- rpcs3/Emu/Cell/lv2/sys_rsx.cpp | 2 + rpcs3/Emu/Cell/lv2/sys_rsx.h | 8 +- rpcs3/Emu/Cell/lv2/sys_rwlock.cpp | 2 + rpcs3/Emu/Cell/lv2/sys_rwlock.h | 2 +- rpcs3/Emu/Cell/lv2/sys_semaphore.cpp | 2 + rpcs3/Emu/Cell/lv2/sys_semaphore.h | 4 +- rpcs3/Emu/Cell/lv2/sys_spu.cpp | 2 + rpcs3/Emu/Cell/lv2/sys_spu.h | 40 +-- rpcs3/Emu/Cell/lv2/sys_sync.h | 2 - rpcs3/Emu/Cell/lv2/sys_time.cpp | 2 + rpcs3/Emu/Cell/lv2/sys_time.h | 6 +- rpcs3/Emu/Cell/lv2/sys_timer.cpp | 2 + rpcs3/Emu/Cell/lv2/sys_timer.h | 6 +- rpcs3/Emu/Cell/lv2/sys_trace.cpp | 2 + rpcs3/Emu/Cell/lv2/sys_trace.h | 2 - rpcs3/Emu/PSP2/Modules/sceLibKernel.cpp | 286 +++++++++++---------- 52 files changed, 309 insertions(+), 282 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellFs.cpp b/rpcs3/Emu/Cell/Modules/cellFs.cpp index 6b29870043..6e898bacf5 100644 --- a/rpcs3/Emu/Cell/Modules/cellFs.cpp +++ b/rpcs3/Emu/Cell/Modules/cellFs.cpp @@ -10,6 +10,8 @@ #include +namespace vm { using namespace ps3; } + logs::channel cellFs("cellFs", logs::level::notice); s32 cellFsOpen(vm::cptr path, s32 flags, vm::ptr fd, vm::cptr arg, u64 size) diff --git a/rpcs3/Emu/Cell/Modules/cellOvis.cpp b/rpcs3/Emu/Cell/Modules/cellOvis.cpp index f7a5daa2bd..c8a93072a7 100644 --- a/rpcs3/Emu/Cell/Modules/cellOvis.cpp +++ b/rpcs3/Emu/Cell/Modules/cellOvis.cpp @@ -1,6 +1,8 @@ #include "stdafx.h" #include "Emu/Cell/PPUModule.h" +namespace vm { using namespace ps3; } + logs::channel cellOvis("cellOvis", logs::level::notice); // Return Codes diff --git a/rpcs3/Emu/Cell/Modules/cellSpudll.cpp b/rpcs3/Emu/Cell/Modules/cellSpudll.cpp index cc264e93a0..68f0a80a7c 100644 --- a/rpcs3/Emu/Cell/Modules/cellSpudll.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSpudll.cpp @@ -1,6 +1,8 @@ #include "stdafx.h" #include "Emu/Cell/PPUModule.h" +namespace vm { using namespace ps3; } + logs::channel cellSpudll("cellSpudll", logs::level::notice); s32 cellSpudllGetImageSize(vm::ptr psize, vm::cptr so_elf, vm::cptr config) diff --git a/rpcs3/Emu/Cell/Modules/cellSpursSpu.cpp b/rpcs3/Emu/Cell/Modules/cellSpursSpu.cpp index 68930eabcb..c0ddb89942 100644 --- a/rpcs3/Emu/Cell/Modules/cellSpursSpu.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSpursSpu.cpp @@ -10,6 +10,7 @@ #include "cellSpurs.h" #include +#include //---------------------------------------------------------------------------- // Externs diff --git a/rpcs3/Emu/Cell/Modules/libsnd3.h b/rpcs3/Emu/Cell/Modules/libsnd3.h index 5afd3024b4..c54cff7914 100644 --- a/rpcs3/Emu/Cell/Modules/libsnd3.h +++ b/rpcs3/Emu/Cell/Modules/libsnd3.h @@ -1,5 +1,7 @@ #pragma once +namespace vm { using namespace ps3; } + // Error Codes enum { diff --git a/rpcs3/Emu/Cell/Modules/libsynth2.cpp b/rpcs3/Emu/Cell/Modules/libsynth2.cpp index 39ee322d85..07285b1606 100644 --- a/rpcs3/Emu/Cell/Modules/libsynth2.cpp +++ b/rpcs3/Emu/Cell/Modules/libsynth2.cpp @@ -3,6 +3,8 @@ #include "libsynth2.h" +namespace vm { using namespace ps3; } + logs::channel libsynth2("libsynth2", logs::level::notice); s32 cellSoundSynth2Config(s16 param, s32 value) diff --git a/rpcs3/Emu/Cell/Modules/sys_libc.cpp b/rpcs3/Emu/Cell/Modules/sys_libc.cpp index 38195675d8..0951256d99 100644 --- a/rpcs3/Emu/Cell/Modules/sys_libc.cpp +++ b/rpcs3/Emu/Cell/Modules/sys_libc.cpp @@ -3,6 +3,8 @@ #include "Emu/Cell/PPUModule.h" #include "Emu/Cell/PPUOpcodes.h" +namespace vm { using namespace ps3; } + logs::channel sys_libc("sys_libc", logs::level::notice); namespace sys_libc_func diff --git a/rpcs3/Emu/Cell/Modules/sys_libc_.cpp b/rpcs3/Emu/Cell/Modules/sys_libc_.cpp index e95c4f2044..07dba57beb 100644 --- a/rpcs3/Emu/Cell/Modules/sys_libc_.cpp +++ b/rpcs3/Emu/Cell/Modules/sys_libc_.cpp @@ -1,6 +1,8 @@ #include "stdafx.h" #include "Emu/Cell/PPUModule.h" +namespace vm { using namespace ps3; } + extern logs::channel sysPrxForUser; extern fs::file g_tty; diff --git a/rpcs3/Emu/Cell/Modules/sys_ppu_thread_.cpp b/rpcs3/Emu/Cell/Modules/sys_ppu_thread_.cpp index a7f2bd06d8..015b734c79 100644 --- a/rpcs3/Emu/Cell/Modules/sys_ppu_thread_.cpp +++ b/rpcs3/Emu/Cell/Modules/sys_ppu_thread_.cpp @@ -86,13 +86,13 @@ void sys_ppu_thread_exit(ppu_thread& ppu, u64 val) return _sys_ppu_thread_exit(ppu, val); } -std::mutex g_once_mutex; +shared_mutex g_once_mutex; void sys_ppu_thread_once(ppu_thread& ppu, vm::ptr> once_ctrl, vm::ptr init) { sysPrxForUser.warning("sys_ppu_thread_once(once_ctrl=*0x%x, init=*0x%x)", once_ctrl, init); - std::lock_guard lock(g_once_mutex); + writer_lock lock(g_once_mutex); if (once_ctrl->compare_and_swap_test(SYS_PPU_THREAD_ONCE_INIT, SYS_PPU_THREAD_DONE_INIT)) { diff --git a/rpcs3/Emu/Cell/PPUAnalyser.cpp b/rpcs3/Emu/Cell/PPUAnalyser.cpp index 41698db8ab..e3c19f0d30 100644 --- a/rpcs3/Emu/Cell/PPUAnalyser.cpp +++ b/rpcs3/Emu/Cell/PPUAnalyser.cpp @@ -7,6 +7,8 @@ #include "yaml-cpp/yaml.h" +namespace vm { using namespace ps3; } + const ppu_decoder s_ppu_itype; const ppu_decoder s_ppu_iname; diff --git a/rpcs3/Emu/Cell/PPUModule.cpp b/rpcs3/Emu/Cell/PPUModule.cpp index 7bed03d821..39741318a8 100644 --- a/rpcs3/Emu/Cell/PPUModule.cpp +++ b/rpcs3/Emu/Cell/PPUModule.cpp @@ -15,6 +15,8 @@ #include #include +namespace vm { using namespace ps3; } + LOG_CHANNEL(cellAdec); LOG_CHANNEL(cellAtrac); LOG_CHANNEL(cellAtracMulti); diff --git a/rpcs3/Emu/Cell/PPUModule.h b/rpcs3/Emu/Cell/PPUModule.h index 90e6eab97a..2d12983889 100644 --- a/rpcs3/Emu/Cell/PPUModule.h +++ b/rpcs3/Emu/Cell/PPUModule.h @@ -4,8 +4,6 @@ #include "PPUCallback.h" #include "ErrorCodes.h" -namespace vm { using namespace ps3; } - // Generate FNID or VNID for given name extern u32 ppu_generate_id(const char* name); @@ -28,7 +26,7 @@ struct ppu_static_function struct ppu_static_variable { const char* name; - vm::gvar* var; // Pointer to variable address storage + vm::ps3::gvar* var; // Pointer to variable address storage void(*init)(); // Variable initialization function u32 size; u32 align; @@ -95,7 +93,7 @@ public: auto& info = access_static_variable(module, vnid); info.name = name; - info.var = reinterpret_cast*>(Var); + info.var = reinterpret_cast*>(Var); info.init = init ? init : [] {}; info.size = SIZE_32(typename T::type); info.align = ALIGN_32(typename T::type); diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index 6bf802d2b1..b693e01c6f 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -41,6 +41,8 @@ #include "Modules/cellMsgDialog.h" #endif +namespace vm { using namespace ps3; } + enum class ppu_decoder_type { precise, diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index 60ed63b89f..7da1ed0bb1 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -21,6 +21,7 @@ #include #include #include +#include extern u64 get_timebased_time(); @@ -210,7 +211,7 @@ void SPUThread::cpu_task() (fmt::throw_exception("Invalid SPU decoder"), nullptr)); // LS base address - const auto base = vm::_ptr(offset); + const auto base = vm::ps3::_ptr(offset); while (true) { @@ -348,7 +349,7 @@ void SPUThread::do_dma_list_cmd(u32 cmd, spu_mfc_arg_t args) for (u32 i = 0; i < list_size; i++) { - auto rec = vm::ptr::make(offset + list_addr + i * 8); + auto rec = vm::ps3::ptr::make(offset + list_addr + i * 8); const u32 size = rec->ts; const u32 addr = rec->ea; diff --git a/rpcs3/Emu/Cell/lv2/sys_cond.cpp b/rpcs3/Emu/Cell/lv2/sys_cond.cpp index 902f3bd871..47f8b81266 100644 --- a/rpcs3/Emu/Cell/lv2/sys_cond.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_cond.cpp @@ -10,6 +10,8 @@ #include +namespace vm { using namespace ps3; } + logs::channel sys_cond("sys_cond", logs::level::notice); extern u64 get_system_time(); diff --git a/rpcs3/Emu/Cell/lv2/sys_cond.h b/rpcs3/Emu/Cell/lv2/sys_cond.h index 4bfb17e9b7..6712de3ac7 100644 --- a/rpcs3/Emu/Cell/lv2/sys_cond.h +++ b/rpcs3/Emu/Cell/lv2/sys_cond.h @@ -40,7 +40,7 @@ struct lv2_cond_t class ppu_thread; // SysCalls -s32 sys_cond_create(vm::ptr cond_id, u32 mutex_id, vm::ptr attr); +s32 sys_cond_create(vm::ps3::ptr cond_id, u32 mutex_id, vm::ps3::ptr attr); s32 sys_cond_destroy(u32 cond_id); s32 sys_cond_wait(ppu_thread& ppu, u32 cond_id, u64 timeout); s32 sys_cond_signal(u32 cond_id); diff --git a/rpcs3/Emu/Cell/lv2/sys_dbg.cpp b/rpcs3/Emu/Cell/lv2/sys_dbg.cpp index 7c73318b80..577cd73d45 100644 --- a/rpcs3/Emu/Cell/lv2/sys_dbg.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_dbg.cpp @@ -6,4 +6,6 @@ #include "Emu/Cell/ErrorCodes.h" #include "sys_dbg.h" +namespace vm { using namespace ps3; } + logs::channel sys_dbg("sys_dbg", logs::level::notice); diff --git a/rpcs3/Emu/Cell/lv2/sys_dbg.h b/rpcs3/Emu/Cell/lv2/sys_dbg.h index 8744312ca5..6f70f09bee 100644 --- a/rpcs3/Emu/Cell/lv2/sys_dbg.h +++ b/rpcs3/Emu/Cell/lv2/sys_dbg.h @@ -1,3 +1 @@ #pragma once - -namespace vm { using namespace ps3; } diff --git a/rpcs3/Emu/Cell/lv2/sys_event.cpp b/rpcs3/Emu/Cell/lv2/sys_event.cpp index 7ac9ff0e2c..d4fa9baffb 100644 --- a/rpcs3/Emu/Cell/lv2/sys_event.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_event.cpp @@ -10,6 +10,8 @@ #include "sys_process.h" #include "sys_event.h" +namespace vm { using namespace ps3; } + logs::channel sys_event("sys_event", logs::level::notice); template<> DECLARE(ipc_manager::g_ipc) {}; diff --git a/rpcs3/Emu/Cell/lv2/sys_event.h b/rpcs3/Emu/Cell/lv2/sys_event.h index 3d90481146..6acb7551e5 100644 --- a/rpcs3/Emu/Cell/lv2/sys_event.h +++ b/rpcs3/Emu/Cell/lv2/sys_event.h @@ -2,6 +2,8 @@ #include "sys_sync.h" +class cpu_thread; + // Event Queue Type enum : u32 { @@ -135,13 +137,13 @@ struct lv2_event_port_t class ppu_thread; // SysCalls -s32 sys_event_queue_create(vm::ptr equeue_id, vm::ptr attr, u64 event_queue_key, s32 size); +s32 sys_event_queue_create(vm::ps3::ptr equeue_id, vm::ps3::ptr attr, u64 event_queue_key, s32 size); s32 sys_event_queue_destroy(u32 equeue_id, s32 mode); -s32 sys_event_queue_receive(ppu_thread& ppu, u32 equeue_id, vm::ptr dummy_event, u64 timeout); -s32 sys_event_queue_tryreceive(u32 equeue_id, vm::ptr event_array, s32 size, vm::ptr number); +s32 sys_event_queue_receive(ppu_thread& ppu, u32 equeue_id, vm::ps3::ptr dummy_event, u64 timeout); +s32 sys_event_queue_tryreceive(u32 equeue_id, vm::ps3::ptr event_array, s32 size, vm::ps3::ptr number); s32 sys_event_queue_drain(u32 event_queue_id); -s32 sys_event_port_create(vm::ptr eport_id, s32 port_type, u64 name); +s32 sys_event_port_create(vm::ps3::ptr eport_id, s32 port_type, u64 name); s32 sys_event_port_destroy(u32 eport_id); s32 sys_event_port_connect_local(u32 event_port_id, u32 event_queue_id); s32 sys_event_port_disconnect(u32 eport_id); diff --git a/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp b/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp index e260f99359..a62444cf0a 100644 --- a/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp @@ -9,6 +9,8 @@ #include +namespace vm { using namespace ps3; } + logs::channel sys_event_flag("sys_event_flag", logs::level::notice); extern u64 get_system_time(); diff --git a/rpcs3/Emu/Cell/lv2/sys_event_flag.h b/rpcs3/Emu/Cell/lv2/sys_event_flag.h index 851c8fd6e0..4326288e7b 100644 --- a/rpcs3/Emu/Cell/lv2/sys_event_flag.h +++ b/rpcs3/Emu/Cell/lv2/sys_event_flag.h @@ -114,11 +114,11 @@ struct lv2_event_flag_t class ppu_thread; // SysCalls -s32 sys_event_flag_create(vm::ptr id, vm::ptr attr, u64 init); +s32 sys_event_flag_create(vm::ps3::ptr id, vm::ps3::ptr attr, u64 init); s32 sys_event_flag_destroy(u32 id); -s32 sys_event_flag_wait(ppu_thread& ppu, u32 id, u64 bitptn, u32 mode, vm::ptr result, u64 timeout); -s32 sys_event_flag_trywait(u32 id, u64 bitptn, u32 mode, vm::ptr result); +s32 sys_event_flag_wait(ppu_thread& ppu, u32 id, u64 bitptn, u32 mode, vm::ps3::ptr result, u64 timeout); +s32 sys_event_flag_trywait(u32 id, u64 bitptn, u32 mode, vm::ps3::ptr result); s32 sys_event_flag_set(u32 id, u64 bitptn); s32 sys_event_flag_clear(u32 id, u64 bitptn); -s32 sys_event_flag_cancel(u32 id, vm::ptr num); -s32 sys_event_flag_get(u32 id, vm::ptr flags); +s32 sys_event_flag_cancel(u32 id, vm::ps3::ptr num); +s32 sys_event_flag_get(u32 id, vm::ps3::ptr flags); diff --git a/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp b/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp index 4cbd7e3ad3..24aecb75ad 100644 --- a/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp @@ -8,6 +8,8 @@ #include "Emu/Cell/PPUOpcodes.h" #include "sys_interrupt.h" +namespace vm { using namespace ps3; } + logs::channel sys_interrupt("sys_interrupt", logs::level::notice); lv2_int_serv_t::lv2_int_serv_t(const std::shared_ptr& thread, u64 arg1, u64 arg2) diff --git a/rpcs3/Emu/Cell/lv2/sys_interrupt.h b/rpcs3/Emu/Cell/lv2/sys_interrupt.h index 2382036a36..c6f59e1f74 100644 --- a/rpcs3/Emu/Cell/lv2/sys_interrupt.h +++ b/rpcs3/Emu/Cell/lv2/sys_interrupt.h @@ -38,6 +38,6 @@ struct lv2_int_serv_t // SysCalls s32 sys_interrupt_tag_destroy(u32 intrtag); -s32 _sys_interrupt_thread_establish(vm::ptr ih, u32 intrtag, u32 intrthread, u64 arg1, u64 arg2); -s32 _sys_interrupt_thread_disestablish(ppu_thread& ppu, u32 ih, vm::ptr r13); +s32 _sys_interrupt_thread_establish(vm::ps3::ptr ih, u32 intrtag, u32 intrthread, u64 arg1, u64 arg2); +s32 _sys_interrupt_thread_disestablish(ppu_thread& ppu, u32 ih, vm::ps3::ptr r13); void sys_interrupt_thread_eoi(ppu_thread& ppu); diff --git a/rpcs3/Emu/Cell/lv2/sys_lwmutex.cpp b/rpcs3/Emu/Cell/lv2/sys_lwmutex.cpp index 2dc3cc272e..b35b4e4a64 100644 --- a/rpcs3/Emu/Cell/lv2/sys_lwmutex.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_lwmutex.cpp @@ -7,6 +7,8 @@ #include "Emu/Cell/PPUThread.h" #include "sys_lwmutex.h" +namespace vm { using namespace ps3; } + logs::channel sys_lwmutex("sys_lwmutex", logs::level::notice); extern u64 get_system_time(); diff --git a/rpcs3/Emu/Cell/lv2/sys_lwmutex.h b/rpcs3/Emu/Cell/lv2/sys_lwmutex.h index c3e90d8d11..21773a5ce9 100644 --- a/rpcs3/Emu/Cell/lv2/sys_lwmutex.h +++ b/rpcs3/Emu/Cell/lv2/sys_lwmutex.h @@ -71,7 +71,7 @@ struct lv2_lwmutex_t class ppu_thread; // SysCalls -s32 _sys_lwmutex_create(vm::ptr lwmutex_id, u32 protocol, vm::ptr control, u32 arg4, u64 name, u32 arg6); +s32 _sys_lwmutex_create(vm::ps3::ptr lwmutex_id, u32 protocol, vm::ps3::ptr control, u32 arg4, u64 name, u32 arg6); s32 _sys_lwmutex_destroy(u32 lwmutex_id); s32 _sys_lwmutex_lock(ppu_thread& ppu, u32 lwmutex_id, u64 timeout); s32 _sys_lwmutex_trylock(u32 lwmutex_id); diff --git a/rpcs3/Emu/Cell/lv2/sys_memory.cpp b/rpcs3/Emu/Cell/lv2/sys_memory.cpp index db16ea8337..1f512b0a8d 100644 --- a/rpcs3/Emu/Cell/lv2/sys_memory.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_memory.cpp @@ -86,28 +86,25 @@ error_code sys_memory_allocate_from_container(u32 size, u32 cid, u64 flags, vm:: } } - error_code result{}; - - const auto ct = idm::get(cid, [&](lv2_memory_container& ct) + const auto ct = idm::get(cid, [&](lv2_memory_container& ct) -> CellError { // Try to get "physical memory" if (!ct.take(size)) { - result = CELL_ENOMEM; - return false; + return CELL_ENOMEM; } - return true; + return {}; }); - if (!ct && !result) + if (!ct) { return CELL_ESRCH; } - if (!ct) + if (ct.value) { - return result; + return ct.value; } // Allocate memory, write back the start address of the allocated area, use cid as the supplementary info @@ -206,28 +203,25 @@ error_code sys_memory_container_destroy(u32 cid) { sys_memory.warning("sys_memory_container_destroy(cid=0x%x)", cid); - error_code result{}; - - const auto ct = idm::withdraw(cid, [&](lv2_memory_container& ct) + const auto ct = idm::withdraw(cid, [](lv2_memory_container& ct) -> CellError { // Check if some memory is not deallocated (the container cannot be destroyed in this case) if (!ct.used.compare_and_swap_test(0, ct.size)) { - result = CELL_EBUSY; - return false; + return CELL_EBUSY; } - return true; + return {}; }); - if (!ct && !result) + if (!ct) { return CELL_ESRCH; } - if (!ct) + if (ct.value) { - return result; + return ct.value; } // Return "physical memory" to the default container diff --git a/rpcs3/Emu/Cell/lv2/sys_mmapper.cpp b/rpcs3/Emu/Cell/lv2/sys_mmapper.cpp index e612310a82..1a851671fc 100644 --- a/rpcs3/Emu/Cell/lv2/sys_mmapper.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_mmapper.cpp @@ -141,28 +141,25 @@ error_code sys_mmapper_allocate_shared_memory_from_container(u64 unk, u32 size, } } - error_code result{}; - - const auto ct = idm::get(cid, [&](lv2_memory_container& ct) + const auto ct = idm::get(cid, [&](lv2_memory_container& ct) -> CellError { // Try to get "physical memory" if (!ct.take(size)) { - result = CELL_ENOMEM; - return false; + return CELL_ENOMEM; } - return true; + return {}; }); - if (!ct && !result) + if (!ct) { return CELL_ESRCH; } - if (!ct) + if (ct.value) { - return result; + return ct.value; } // Generate a new mem ID @@ -202,28 +199,25 @@ error_code sys_mmapper_free_shared_memory(u32 mem_id) { sys_mmapper.warning("sys_mmapper_free_shared_memory(mem_id=0x%x)", mem_id); - error_code result{}; - // Conditionally remove memory ID - const auto mem = idm::withdraw(mem_id, [&](lv2_memory& mem) + const auto mem = idm::withdraw(mem_id, [&](lv2_memory& mem) -> CellError { if (mem.addr.compare_and_swap_test(0, -1)) { - result = CELL_EBUSY; - return false; + return CELL_EBUSY; } - return true; + return {}; }); - if (!mem && !result) + if (!mem) { return CELL_ESRCH; } - if (!mem) + if (mem.value) { - return result; + return mem.value; } // Return "physical memory" to the memory container diff --git a/rpcs3/Emu/Cell/lv2/sys_mutex.cpp b/rpcs3/Emu/Cell/lv2/sys_mutex.cpp index ad0ac4e5c9..f51bf63e5b 100644 --- a/rpcs3/Emu/Cell/lv2/sys_mutex.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_mutex.cpp @@ -7,6 +7,8 @@ #include "Emu/Cell/PPUThread.h" #include "sys_mutex.h" +namespace vm { using namespace ps3; } + logs::channel sys_mutex("sys_mutex", logs::level::notice); extern u64 get_system_time(); diff --git a/rpcs3/Emu/Cell/lv2/sys_mutex.h b/rpcs3/Emu/Cell/lv2/sys_mutex.h index 1c9b7228c9..bec1f9ab30 100644 --- a/rpcs3/Emu/Cell/lv2/sys_mutex.h +++ b/rpcs3/Emu/Cell/lv2/sys_mutex.h @@ -48,7 +48,7 @@ struct lv2_mutex_t class ppu_thread; // SysCalls -s32 sys_mutex_create(vm::ptr mutex_id, vm::ptr attr); +s32 sys_mutex_create(vm::ps3::ptr mutex_id, vm::ps3::ptr attr); s32 sys_mutex_destroy(u32 mutex_id); s32 sys_mutex_lock(ppu_thread& ppu, u32 mutex_id, u64 timeout); s32 sys_mutex_trylock(ppu_thread& ppu, u32 mutex_id); diff --git a/rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp b/rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp index 3d043f4a8c..f3cae43e13 100644 --- a/rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp @@ -9,6 +9,8 @@ #include +namespace vm { using namespace ps3; } + logs::channel sys_ppu_thread("sys_ppu_thread", logs::level::notice); void _sys_ppu_thread_exit(ppu_thread& ppu, u64 errorcode) diff --git a/rpcs3/Emu/Cell/lv2/sys_ppu_thread.h b/rpcs3/Emu/Cell/lv2/sys_ppu_thread.h index 4c74ea0b68..512dd57a7a 100644 --- a/rpcs3/Emu/Cell/lv2/sys_ppu_thread.h +++ b/rpcs3/Emu/Cell/lv2/sys_ppu_thread.h @@ -44,14 +44,14 @@ enum : u32 // SysCalls void _sys_ppu_thread_exit(ppu_thread& ppu, u64 errorcode); void sys_ppu_thread_yield(); -s32 sys_ppu_thread_join(ppu_thread& ppu, u32 thread_id, vm::ptr vptr); +s32 sys_ppu_thread_join(ppu_thread& ppu, u32 thread_id, vm::ps3::ptr vptr); s32 sys_ppu_thread_detach(u32 thread_id); -void sys_ppu_thread_get_join_state(ppu_thread& ppu, vm::ptr isjoinable); +void sys_ppu_thread_get_join_state(ppu_thread& ppu, vm::ps3::ptr isjoinable); s32 sys_ppu_thread_set_priority(u32 thread_id, s32 prio); -s32 sys_ppu_thread_get_priority(u32 thread_id, vm::ptr priop); -s32 sys_ppu_thread_get_stack_information(ppu_thread& ppu, vm::ptr sp); +s32 sys_ppu_thread_get_priority(u32 thread_id, vm::ps3::ptr priop); +s32 sys_ppu_thread_get_stack_information(ppu_thread& ppu, vm::ps3::ptr sp); s32 sys_ppu_thread_stop(u32 thread_id); s32 sys_ppu_thread_restart(u32 thread_id); -s32 _sys_ppu_thread_create(vm::ptr thread_id, vm::ptr param, u64 arg, u64 arg4, s32 prio, u32 stacksize, u64 flags, vm::cptr threadname); +s32 _sys_ppu_thread_create(vm::ps3::ptr thread_id, vm::ps3::ptr param, u64 arg, u64 arg4, s32 prio, u32 stacksize, u64 flags, vm::ps3::cptr threadname); s32 sys_ppu_thread_start(u32 thread_id); -s32 sys_ppu_thread_rename(u32 thread_id, vm::cptr name); +s32 sys_ppu_thread_rename(u32 thread_id, vm::ps3::cptr name); diff --git a/rpcs3/Emu/Cell/lv2/sys_process.cpp b/rpcs3/Emu/Cell/lv2/sys_process.cpp index 23ad117250..81a448536b 100644 --- a/rpcs3/Emu/Cell/lv2/sys_process.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_process.cpp @@ -23,6 +23,8 @@ #include +namespace vm { using namespace ps3; } + logs::channel sys_process("sys_process", logs::level::notice); u32 g_ps3_sdk_version; @@ -49,14 +51,11 @@ s32 sys_process_exit(s32 status) { sys_process.warning("sys_process_exit(status=0x%x)", status); - LV2_LOCK; - CHECK_EMU_STATUS; - sys_process.success("Process finished"); - Emu.CallAfter([]() { + sys_process.success("Process finished"); Emu.Stop(); }); diff --git a/rpcs3/Emu/Cell/lv2/sys_process.h b/rpcs3/Emu/Cell/lv2/sys_process.h index 416a49fd72..be4951f978 100644 --- a/rpcs3/Emu/Cell/lv2/sys_process.h +++ b/rpcs3/Emu/Cell/lv2/sys_process.h @@ -1,7 +1,5 @@ #pragma once -namespace vm { using namespace ps3; } - // Process Local Object Type enum : u32 { @@ -33,16 +31,16 @@ s32 process_is_spu_lock_line_reservation_address(u32 addr, u64 flags); // SysCalls 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_sdk_version(u32 pid, vm::ptr version); +s32 sys_process_get_number_of_object(u32 object, vm::ps3::ptr nump); +s32 sys_process_get_id(u32 object, vm::ps3::ptr buffer, u32 size, vm::ps3::ptr set_size); +s32 _sys_process_get_paramsfo(vm::ps3::ptr buffer); +s32 sys_process_get_sdk_version(u32 pid, vm::ps3::ptr version); s32 sys_process_get_status(u64 unk); s32 sys_process_is_spu_lock_line_reservation_address(u32 addr, u64 flags); s32 sys_process_exit(s32 errorcode); s32 sys_process_kill(u32 pid); -s32 sys_process_wait_for_child(u32 pid, vm::ptr status, u64 unk); +s32 sys_process_wait_for_child(u32 pid, vm::ps3::ptr status, u64 unk); s32 sys_process_wait_for_child2(u64 unk1, u64 unk2, u64 unk3, u64 unk4, u64 unk5, u64 unk6); s32 sys_process_detach_child(u64 unk); -void sys_game_process_exitspawn(vm::cptr path, u32 argv_addr, u32 envp_addr, u32 data_addr, u32 data_size, u32 prio, u64 flags); -void sys_game_process_exitspawn2(vm::cptr path, u32 argv_addr, u32 envp_addr, u32 data_addr, u32 data_size, u32 prio, u64 flags); +void sys_game_process_exitspawn(vm::ps3::cptr path, u32 argv_addr, u32 envp_addr, u32 data_addr, u32 data_size, u32 prio, u64 flags); +void sys_game_process_exitspawn2(vm::ps3::cptr path, u32 argv_addr, u32 envp_addr, u32 data_addr, u32 data_size, u32 prio, u64 flags); diff --git a/rpcs3/Emu/Cell/lv2/sys_prx.cpp b/rpcs3/Emu/Cell/lv2/sys_prx.cpp index 6dad4408a6..31912cd02d 100644 --- a/rpcs3/Emu/Cell/lv2/sys_prx.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_prx.cpp @@ -8,6 +8,8 @@ #include "Emu/Cell/ErrorCodes.h" #include "sys_prx.h" +namespace vm { using namespace ps3; } + extern std::shared_ptr ppu_load_prx(const ppu_prx_object&); logs::channel sys_prx("sys_prx", logs::level::notice); diff --git a/rpcs3/Emu/Cell/lv2/sys_prx.h b/rpcs3/Emu/Cell/lv2/sys_prx.h index e18c6791ff..e1ec1228cf 100644 --- a/rpcs3/Emu/Cell/lv2/sys_prx.h +++ b/rpcs3/Emu/Cell/lv2/sys_prx.h @@ -2,8 +2,6 @@ #include "Emu/Cell/PPUAnalyser.h" -namespace vm { using namespace ps3; } - // Return codes enum { @@ -35,13 +33,13 @@ enum struct sys_prx_get_module_id_by_name_option_t { be_t size; - vm::ptr base; + vm::ps3::ptr base; }; struct sys_prx_load_module_option_t { be_t size; - vm::bptr base_addr; + vm::ps3::bptr base_addr; }; struct sys_prx_segment_info_t;// TODO @@ -51,14 +49,14 @@ struct sys_prx_start_module_option_t { be_t size; be_t put; - vm::bptr argv), u64> entry_point; + vm::ps3::bptr argv), u64> entry_point; }; struct sys_prx_stop_module_option_t { be_t size; be_t put; - vm::bptr argv), u64> entry_point; + vm::ps3::bptr argv), u64> entry_point; }; struct sys_prx_unload_module_option_t @@ -71,7 +69,7 @@ struct sys_prx_get_module_list_t be_t size; be_t max; be_t count; - vm::bptr idlist; + vm::ps3::bptr idlist; }; struct lv2_prx_t @@ -87,29 +85,29 @@ struct lv2_prx_t std::unordered_map specials; std::vector funcs; - vm::ptr argv)> start = vm::null; - vm::ptr argv)> stop = vm::null; - vm::ptr exit = vm::null; - + vm::ps3::ptr argv)> start = vm::null; + vm::ps3::ptr argv)> stop = vm::null; + vm::ps3::ptr exit = vm::null; + lv2_prx_t(); }; // SysCalls -s32 sys_prx_load_module(vm::cptr path, u64 flags, vm::ptr pOpt); -s32 sys_prx_load_module_list(s32 count, vm::cpptr path_list, u64 flags, vm::ptr pOpt, vm::ptr id_list); +s32 sys_prx_load_module(vm::ps3::cptr path, u64 flags, vm::ps3::ptr pOpt); +s32 sys_prx_load_module_list(s32 count, vm::ps3::cpptr path_list, u64 flags, vm::ps3::ptr pOpt, vm::ps3::ptr id_list); s32 sys_prx_load_module_on_memcontainer(); s32 sys_prx_load_module_by_fd(); s32 sys_prx_load_module_on_memcontainer_by_fd(); -s32 sys_prx_start_module(s32 id, u64 flags, vm::ptr pOpt); -s32 sys_prx_stop_module(s32 id, u64 flags, vm::ptr pOpt); -s32 sys_prx_unload_module(s32 id, u64 flags, vm::ptr pOpt); -s32 sys_prx_get_module_list(u64 flags, vm::ptr pInfo); +s32 sys_prx_start_module(s32 id, u64 flags, vm::ps3::ptr pOpt); +s32 sys_prx_stop_module(s32 id, u64 flags, vm::ps3::ptr pOpt); +s32 sys_prx_unload_module(s32 id, u64 flags, vm::ps3::ptr pOpt); +s32 sys_prx_get_module_list(u64 flags, vm::ps3::ptr pInfo); s32 sys_prx_get_my_module_id(); s32 sys_prx_get_module_id_by_address(); -s32 sys_prx_get_module_id_by_name(vm::cptr name, u64 flags, vm::ptr pOpt); -s32 sys_prx_get_module_info(s32 id, u64 flags, vm::ptr info); -s32 sys_prx_register_library(vm::ptr library); -s32 sys_prx_unregister_library(vm::ptr library); +s32 sys_prx_get_module_id_by_name(vm::ps3::cptr name, u64 flags, vm::ps3::ptr pOpt); +s32 sys_prx_get_module_info(s32 id, u64 flags, vm::ps3::ptr info); +s32 sys_prx_register_library(vm::ps3::ptr library); +s32 sys_prx_unregister_library(vm::ps3::ptr library); s32 sys_prx_get_ppu_guid(); s32 sys_prx_register_module(); s32 sys_prx_query_module(); diff --git a/rpcs3/Emu/Cell/lv2/sys_rsx.cpp b/rpcs3/Emu/Cell/lv2/sys_rsx.cpp index df512caf7a..834263838a 100644 --- a/rpcs3/Emu/Cell/lv2/sys_rsx.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_rsx.cpp @@ -5,6 +5,8 @@ #include "Emu/Cell/ErrorCodes.h" #include "sys_rsx.h" +namespace vm { using namespace ps3; } + logs::channel sys_rsx("sys_rsx", logs::level::notice); s32 sys_rsx_device_open() diff --git a/rpcs3/Emu/Cell/lv2/sys_rsx.h b/rpcs3/Emu/Cell/lv2/sys_rsx.h index 8b2b9d0b0a..91caa0b307 100644 --- a/rpcs3/Emu/Cell/lv2/sys_rsx.h +++ b/rpcs3/Emu/Cell/lv2/sys_rsx.h @@ -1,17 +1,15 @@ #pragma once -namespace vm { using namespace ps3; } - // SysCalls s32 sys_rsx_device_open(); s32 sys_rsx_device_close(); -s32 sys_rsx_memory_allocate(vm::ptr mem_handle, vm::ptr mem_addr, u32 size, u64 flags, u64 a5, u64 a6, u64 a7); +s32 sys_rsx_memory_allocate(vm::ps3::ptr mem_handle, vm::ps3::ptr mem_addr, u32 size, u64 flags, u64 a5, u64 a6, u64 a7); s32 sys_rsx_memory_free(u32 mem_handle); -s32 sys_rsx_context_allocate(vm::ptr context_id, vm::ptr lpar_dma_control, vm::ptr lpar_driver_info, vm::ptr lpar_reports, u64 mem_ctx, u64 system_mode); +s32 sys_rsx_context_allocate(vm::ps3::ptr context_id, vm::ps3::ptr lpar_dma_control, vm::ps3::ptr lpar_driver_info, vm::ps3::ptr lpar_reports, u64 mem_ctx, u64 system_mode); s32 sys_rsx_context_free(u32 context_id); s32 sys_rsx_context_iomap(u32 context_id, u32 io, u32 ea, u32 size, u64 flags); s32 sys_rsx_context_iounmap(u32 context_id, u32 a2, u32 io_addr, u32 size); s32 sys_rsx_context_attribute(s32 context_id, u32 package_id, u64 a3, u64 a4, u64 a5, u64 a6); -s32 sys_rsx_device_map(vm::ptr addr, vm::ptr a2, u32 dev_id); +s32 sys_rsx_device_map(vm::ps3::ptr addr, vm::ps3::ptr a2, u32 dev_id); s32 sys_rsx_device_unmap(u32 dev_id); s32 sys_rsx_attribute(u32 a1, u32 a2, u32 a3, u32 a4, u32 a5); diff --git a/rpcs3/Emu/Cell/lv2/sys_rwlock.cpp b/rpcs3/Emu/Cell/lv2/sys_rwlock.cpp index ecfad5d2a7..0c5a6d2d45 100644 --- a/rpcs3/Emu/Cell/lv2/sys_rwlock.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_rwlock.cpp @@ -7,6 +7,8 @@ #include "Emu/Cell/PPUThread.h" #include "sys_rwlock.h" +namespace vm { using namespace ps3; } + logs::channel sys_rwlock("sys_rwlock", logs::level::notice); extern u64 get_system_time(); diff --git a/rpcs3/Emu/Cell/lv2/sys_rwlock.h b/rpcs3/Emu/Cell/lv2/sys_rwlock.h index 53e4d8edc2..7ebf3e6eec 100644 --- a/rpcs3/Emu/Cell/lv2/sys_rwlock.h +++ b/rpcs3/Emu/Cell/lv2/sys_rwlock.h @@ -45,7 +45,7 @@ struct lv2_rwlock_t class ppu_thread; // SysCalls -s32 sys_rwlock_create(vm::ptr rw_lock_id, vm::ptr attr); +s32 sys_rwlock_create(vm::ps3::ptr rw_lock_id, vm::ps3::ptr attr); s32 sys_rwlock_destroy(u32 rw_lock_id); s32 sys_rwlock_rlock(ppu_thread& ppu, u32 rw_lock_id, u64 timeout); s32 sys_rwlock_tryrlock(u32 rw_lock_id); diff --git a/rpcs3/Emu/Cell/lv2/sys_semaphore.cpp b/rpcs3/Emu/Cell/lv2/sys_semaphore.cpp index cc375b9516..cead96f74f 100644 --- a/rpcs3/Emu/Cell/lv2/sys_semaphore.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_semaphore.cpp @@ -7,6 +7,8 @@ #include "Emu/Cell/PPUThread.h" #include "sys_semaphore.h" +namespace vm { using namespace ps3; } + logs::channel sys_semaphore("sys_semaphore", logs::level::notice); extern u64 get_system_time(); diff --git a/rpcs3/Emu/Cell/lv2/sys_semaphore.h b/rpcs3/Emu/Cell/lv2/sys_semaphore.h index 697bf542fb..533e80f4da 100644 --- a/rpcs3/Emu/Cell/lv2/sys_semaphore.h +++ b/rpcs3/Emu/Cell/lv2/sys_semaphore.h @@ -44,9 +44,9 @@ struct lv2_sema_t class ppu_thread; // SysCalls -s32 sys_semaphore_create(vm::ptr sem_id, vm::ptr attr, s32 initial_val, s32 max_val); +s32 sys_semaphore_create(vm::ps3::ptr sem_id, vm::ps3::ptr attr, s32 initial_val, s32 max_val); s32 sys_semaphore_destroy(u32 sem_id); s32 sys_semaphore_wait(ppu_thread& ppu, u32 sem_id, u64 timeout); s32 sys_semaphore_trywait(u32 sem_id); s32 sys_semaphore_post(u32 sem_id, s32 count); -s32 sys_semaphore_get_value(u32 sem_id, vm::ptr count); +s32 sys_semaphore_get_value(u32 sem_id, vm::ps3::ptr count); diff --git a/rpcs3/Emu/Cell/lv2/sys_spu.cpp b/rpcs3/Emu/Cell/lv2/sys_spu.cpp index 98728e2e2f..2bd63950f8 100644 --- a/rpcs3/Emu/Cell/lv2/sys_spu.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_spu.cpp @@ -11,6 +11,8 @@ #include "sys_event.h" #include "sys_spu.h" +namespace vm { using namespace ps3; } + logs::channel sys_spu("sys_spu", logs::level::notice); void LoadSpuImage(const fs::file& stream, u32& spu_ep, u32 addr) diff --git a/rpcs3/Emu/Cell/lv2/sys_spu.h b/rpcs3/Emu/Cell/lv2/sys_spu.h index c68e81221b..2b88620151 100644 --- a/rpcs3/Emu/Cell/lv2/sys_spu.h +++ b/rpcs3/Emu/Cell/lv2/sys_spu.h @@ -57,7 +57,7 @@ enum : s32 struct sys_spu_thread_group_attribute { be_t nsize; // name length including NULL terminator - vm::bcptr name; + vm::ps3::bcptr name; be_t type; be_t ct; // memory container id }; @@ -71,7 +71,7 @@ enum : u32 struct sys_spu_thread_attribute { - vm::bcptr name; + vm::ps3::bcptr name; be_t name_len; be_t option; }; @@ -109,7 +109,7 @@ struct sys_spu_image_t { be_t type; // user, kernel be_t entry_point; - vm::bptr segs; + vm::ps3::bptr segs; be_t nsegs; }; @@ -149,7 +149,7 @@ struct lv2_spu_group_t const u32 ct; // Memory Container Id std::array, 256> threads; // SPU Threads - std::array, 256> images; // SPU Images + std::array, 256> images; // SPU Images std::array args; // SPU Thread Arguments s32 prio; // SPU Thread Group Priority @@ -208,41 +208,41 @@ u32 LoadSpuImage(const fs::file& stream, u32& spu_ep); // SysCalls s32 sys_spu_initialize(u32 max_usable_spu, u32 max_raw_spu); -s32 sys_spu_image_open(vm::ptr img, vm::cptr path); -s32 sys_spu_image_close(vm::ptr img); -s32 sys_spu_thread_initialize(vm::ptr thread, u32 group, u32 spu_num, vm::ptr img, vm::ptr attr, vm::ptr arg); -s32 sys_spu_thread_set_argument(u32 id, vm::ptr arg); -s32 sys_spu_thread_group_create(vm::ptr id, u32 num, s32 prio, vm::ptr attr); +s32 sys_spu_image_open(vm::ps3::ptr img, vm::ps3::cptr path); +s32 sys_spu_image_close(vm::ps3::ptr img); +s32 sys_spu_thread_initialize(vm::ps3::ptr thread, u32 group, u32 spu_num, vm::ps3::ptr img, vm::ps3::ptr attr, vm::ps3::ptr arg); +s32 sys_spu_thread_set_argument(u32 id, vm::ps3::ptr arg); +s32 sys_spu_thread_group_create(vm::ps3::ptr id, u32 num, s32 prio, vm::ps3::ptr attr); s32 sys_spu_thread_group_destroy(u32 id); s32 sys_spu_thread_group_start(u32 id); s32 sys_spu_thread_group_suspend(u32 id); s32 sys_spu_thread_group_resume(u32 id); s32 sys_spu_thread_group_yield(u32 id); s32 sys_spu_thread_group_terminate(u32 id, s32 value); -s32 sys_spu_thread_group_join(u32 id, vm::ptr cause, vm::ptr status); +s32 sys_spu_thread_group_join(u32 id, vm::ps3::ptr cause, vm::ps3::ptr status); s32 sys_spu_thread_group_connect_event(u32 id, u32 eq, u32 et); s32 sys_spu_thread_group_disconnect_event(u32 id, u32 et); -s32 sys_spu_thread_group_connect_event_all_threads(u32 id, u32 eq_id, u64 req, vm::ptr spup); +s32 sys_spu_thread_group_connect_event_all_threads(u32 id, u32 eq_id, u64 req, vm::ps3::ptr spup); s32 sys_spu_thread_group_disconnect_event_all_threads(u32 id, u8 spup); s32 sys_spu_thread_write_ls(u32 id, u32 address, u64 value, u32 type); -s32 sys_spu_thread_read_ls(u32 id, u32 address, vm::ptr value, u32 type); +s32 sys_spu_thread_read_ls(u32 id, u32 address, vm::ps3::ptr value, u32 type); s32 sys_spu_thread_write_spu_mb(u32 id, u32 value); s32 sys_spu_thread_set_spu_cfg(u32 id, u64 value); -s32 sys_spu_thread_get_spu_cfg(u32 id, vm::ptr value); +s32 sys_spu_thread_get_spu_cfg(u32 id, vm::ps3::ptr value); s32 sys_spu_thread_write_snr(u32 id, u32 number, u32 value); s32 sys_spu_thread_connect_event(u32 id, u32 eq, u32 et, u8 spup); s32 sys_spu_thread_disconnect_event(u32 id, u32 event_type, u8 spup); s32 sys_spu_thread_bind_queue(u32 id, u32 spuq, u32 spuq_num); s32 sys_spu_thread_unbind_queue(u32 id, u32 spuq_num); -s32 sys_spu_thread_get_exit_status(u32 id, vm::ptr status); +s32 sys_spu_thread_get_exit_status(u32 id, vm::ps3::ptr status); -s32 sys_raw_spu_create(vm::ptr id, vm::ptr attr); +s32 sys_raw_spu_create(vm::ps3::ptr id, vm::ps3::ptr attr); s32 sys_raw_spu_destroy(ppu_thread& ppu, u32 id); -s32 sys_raw_spu_create_interrupt_tag(u32 id, u32 class_id, u32 hwthread, vm::ptr intrtag); +s32 sys_raw_spu_create_interrupt_tag(u32 id, u32 class_id, u32 hwthread, vm::ps3::ptr intrtag); s32 sys_raw_spu_set_int_mask(u32 id, u32 class_id, u64 mask); -s32 sys_raw_spu_get_int_mask(u32 id, u32 class_id, vm::ptr mask); +s32 sys_raw_spu_get_int_mask(u32 id, u32 class_id, vm::ps3::ptr mask); s32 sys_raw_spu_set_int_stat(u32 id, u32 class_id, u64 stat); -s32 sys_raw_spu_get_int_stat(u32 id, u32 class_id, vm::ptr stat); -s32 sys_raw_spu_read_puint_mb(u32 id, vm::ptr value); +s32 sys_raw_spu_get_int_stat(u32 id, u32 class_id, vm::ps3::ptr stat); +s32 sys_raw_spu_read_puint_mb(u32 id, vm::ps3::ptr value); s32 sys_raw_spu_set_spu_cfg(u32 id, u32 value); -s32 sys_raw_spu_get_spu_cfg(u32 id, vm::ptr value); +s32 sys_raw_spu_get_spu_cfg(u32 id, vm::ps3::ptr value); diff --git a/rpcs3/Emu/Cell/lv2/sys_sync.h b/rpcs3/Emu/Cell/lv2/sys_sync.h index efa12f4bdf..18ee7341e9 100644 --- a/rpcs3/Emu/Cell/lv2/sys_sync.h +++ b/rpcs3/Emu/Cell/lv2/sys_sync.h @@ -4,8 +4,6 @@ #include #include -namespace vm { using namespace ps3; } - // attr_protocol (waiting scheduling policy) enum { diff --git a/rpcs3/Emu/Cell/lv2/sys_time.cpp b/rpcs3/Emu/Cell/lv2/sys_time.cpp index 67bcf1a607..77d987b01c 100644 --- a/rpcs3/Emu/Cell/lv2/sys_time.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_time.cpp @@ -103,6 +103,8 @@ static int clock_gettime(int clk_id, struct timespec* tp) #endif +namespace vm { using namespace ps3; } + logs::channel sys_time("sys_time", logs::level::notice); static const u64 g_timebase_freq = /*79800000*/ 80000000; // 80 Mhz diff --git a/rpcs3/Emu/Cell/lv2/sys_time.h b/rpcs3/Emu/Cell/lv2/sys_time.h index 3070196c7f..3cdc8cf026 100644 --- a/rpcs3/Emu/Cell/lv2/sys_time.h +++ b/rpcs3/Emu/Cell/lv2/sys_time.h @@ -1,8 +1,6 @@ #pragma once -namespace vm { using namespace ps3; } - // SysCalls -s32 sys_time_get_timezone(vm::ptr timezone, vm::ptr summertime); -s32 sys_time_get_current_time(vm::ptr sec, vm::ptr nsec); +s32 sys_time_get_timezone(vm::ps3::ptr timezone, vm::ps3::ptr summertime); +s32 sys_time_get_current_time(vm::ps3::ptr sec, vm::ps3::ptr nsec); u64 sys_time_get_timebase_frequency(); diff --git a/rpcs3/Emu/Cell/lv2/sys_timer.cpp b/rpcs3/Emu/Cell/lv2/sys_timer.cpp index 0360edf6a8..e0bfa700ab 100644 --- a/rpcs3/Emu/Cell/lv2/sys_timer.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_timer.cpp @@ -8,6 +8,8 @@ #include "sys_process.h" #include "sys_timer.h" +namespace vm { using namespace ps3; } + logs::channel sys_timer("sys_timer", logs::level::notice); extern u64 get_system_time(); diff --git a/rpcs3/Emu/Cell/lv2/sys_timer.h b/rpcs3/Emu/Cell/lv2/sys_timer.h index 51210087e1..34550e2fd2 100644 --- a/rpcs3/Emu/Cell/lv2/sys_timer.h +++ b/rpcs3/Emu/Cell/lv2/sys_timer.h @@ -2,8 +2,6 @@ #include "Utilities/Thread.h" -namespace vm { using namespace ps3; } - // Timer State enum : u32 { @@ -45,9 +43,9 @@ public: u64 period = 0; // Period (oneshot if 0) }; -s32 sys_timer_create(vm::ptr timer_id); +s32 sys_timer_create(vm::ps3::ptr timer_id); s32 sys_timer_destroy(u32 timer_id); -s32 sys_timer_get_information(u32 timer_id, vm::ptr info); +s32 sys_timer_get_information(u32 timer_id, vm::ps3::ptr info); s32 _sys_timer_start(u32 timer_id, u64 basetime, u64 period); // basetime type changed from s64 s32 sys_timer_stop(u32 timer_id); s32 sys_timer_connect_event_queue(u32 timer_id, u32 queue_id, u64 name, u64 data1, u64 data2); diff --git a/rpcs3/Emu/Cell/lv2/sys_trace.cpp b/rpcs3/Emu/Cell/lv2/sys_trace.cpp index bf5fc20c61..f02b3cd922 100644 --- a/rpcs3/Emu/Cell/lv2/sys_trace.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_trace.cpp @@ -5,6 +5,8 @@ #include "Emu/Cell/ErrorCodes.h" #include "sys_trace.h" +namespace vm { using namespace ps3; } + logs::channel sys_trace("sys_trace", logs::level::notice); s32 sys_trace_create() diff --git a/rpcs3/Emu/Cell/lv2/sys_trace.h b/rpcs3/Emu/Cell/lv2/sys_trace.h index 43be75ff47..5b253893c3 100644 --- a/rpcs3/Emu/Cell/lv2/sys_trace.h +++ b/rpcs3/Emu/Cell/lv2/sys_trace.h @@ -1,7 +1,5 @@ #pragma once -namespace vm { using namespace ps3; } - // SysCalls s32 sys_trace_create(); s32 sys_trace_start(); diff --git a/rpcs3/Emu/PSP2/Modules/sceLibKernel.cpp b/rpcs3/Emu/PSP2/Modules/sceLibKernel.cpp index f11ab46626..0a2e93ea37 100644 --- a/rpcs3/Emu/PSP2/Modules/sceLibKernel.cpp +++ b/rpcs3/Emu/PSP2/Modules/sceLibKernel.cpp @@ -812,15 +812,6 @@ struct psp2_event_flag final static const u32 id_step = 1; static const u32 id_count = 32767; - struct alignas(8) ctrl_t - { - u32 waiters; - u32 pattern; - }; - - atomic_t ctrl; // Sync variable - atomic_t wait_ctr{}; // FIFO ordering helper - using ipc = ipc_manager; const std::string name; // IPC/Debug Name @@ -829,11 +820,15 @@ struct psp2_event_flag final const u32 attr; const u32 init; + atomic_t pattern{0}; // Sync variable + atomic_t waiters{0}; // Waiter number or waiter id + atomic_t wait_ctr; // FIFO ordering helper + psp2_event_flag(std::string&& name, u32 attr, u32 pattern) - : ctrl({0, pattern}) - , name(std::move(name)) + : name(std::move(name)) , attr(attr) , init(pattern) + , pattern(pattern) { } @@ -856,14 +851,15 @@ struct psp2_event_flag final // Commands enum class task : u32 { - null = 0, - wait, - poll, - set, - clear, - cancel, - destroy, - signal, + null, + wait, // Check condition, enqueue waiting thread + poll, // Check condition only + set, // Set pattern bits and wake up threads + clear, // Clear pattern bits (bitwise AND) + cancel, // Wake up all threads with SCE_KERNEL_ERROR_WAIT_CANCEL + destroy, // Wake up all threads with SCE_KERNEL_ERROR_WAIT_DELETE + timeout, // Dequeue waiting thread (cleanup) + signal, // Signal selected thread (aux) }; struct alignas(8) cmd_t @@ -907,13 +903,29 @@ struct psp2_event_flag final case task::wait: op_wait(cmd.arg); break; case task::poll: op_poll(cmd.arg); break; case task::set: op_set(cmd.arg); break; - case task::clear: op_clear(cmd.arg); break; + case task::clear: pattern &= cmd.arg; break; case task::cancel: op_stop(vm::cast(cmd.arg), SCE_KERNEL_ERROR_WAIT_CANCEL); break; case task::destroy: op_stop(vm::cast(cmd.arg), SCE_KERNEL_ERROR_WAIT_DELETE); break; + case task::timeout: + { + // Timeout cleanup + idm::check(cmd.arg, [&](ARMv7Thread& cpu) + { + if (cpu.owner.compare_and_swap_test(this, nullptr)) + { + cpu.GPR[0] = SCE_KERNEL_ERROR_WAIT_TIMEOUT; + cpu.GPR[1] = pattern; + waiters -= attr & SCE_KERNEL_ATTR_MULTI ? 1 : cpu.id; + } + }); + + break; + } + case task::signal: { - idm::get(cmd.arg, [&](ARMv7Thread& cpu) + idm::check(cmd.arg, [](auto& cpu) { cpu.state += cpu_flag::signal; cpu.lock_notify(); @@ -955,28 +967,40 @@ struct psp2_event_flag final private: lf_fifo, 16> m_workload; - // Check condition void op_wait(u32 thread_id) { - idm::get(thread_id, [&](ARMv7Thread& cpu) + idm::check(thread_id, [=](ARMv7Thread& cpu) { - const u32 pattern = ctrl.atomic_op([&](psp2_event_flag::ctrl_t& state) -> u32 + if (attr & SCE_KERNEL_ATTR_MULTI) { - const u32 pat = state.pattern; + waiters++; + } + else if (!waiters.compare_and_swap_test(0, thread_id)) + { + cpu.GPR[0] = SCE_KERNEL_ERROR_EVF_MULTI; + cpu.GPR[1] = pattern; + cpu.state += cpu_flag::signal; + cpu->lock_notify(); + return; + } + + const u32 old_pattern = pattern.atomic_op([&](u32& value) -> u32 + { + const u32 pat = value; if (pat_test(pat, cpu.GPR[1], cpu.GPR[0])) { - state.pattern &= pat_clear(cpu.GPR[1], cpu.GPR[0]); - state.waiters -= attr & SCE_KERNEL_ATTR_MULTI ? 1 : cpu.id; + value &= pat_clear(cpu.GPR[1], cpu.GPR[0]); return pat; } return 0; }); - if (pattern) + if (old_pattern) { + waiters -= attr & SCE_KERNEL_ATTR_MULTI ? 1 : cpu.id; cpu.GPR[0] = SCE_OK; - cpu.GPR[1] = pattern; + cpu.GPR[1] = old_pattern; cpu.state += cpu_flag::signal; cpu->lock_notify(); } @@ -988,17 +1012,16 @@ private: }); } - // Check condition void op_poll(u32 thread_id) { - idm::get(thread_id, [&](ARMv7Thread& cpu) + idm::check(thread_id, [&](ARMv7Thread& cpu) { - cpu.GPR[1] = ctrl.atomic_op([&](psp2_event_flag::ctrl_t& state) -> u32 + cpu.GPR[1] = pattern.atomic_op([&](u32& value) -> u32 { - const u32 pat = state.pattern; + const u32 pat = value; if (pat_test(pat, cpu.GPR[1], cpu.GPR[0])) { - state.pattern &= pat_clear(cpu.GPR[1], cpu.GPR[0]); + value &= pat_clear(cpu.GPR[1], cpu.GPR[0]); return pat; } @@ -1007,26 +1030,24 @@ private: }); } - // Set pattern bits and wake up threads - void op_set(u32 pattern) + void op_set(u32 _pattern) { - const auto new_state = ctrl.op_fetch([&](psp2_event_flag::ctrl_t& state) - { - state.pattern |= pattern; - }); + pattern |= _pattern; - if (new_state.waiters) + if (const u32 _waiters = waiters) { + const u32 new_pattern = pattern; + std::vector> threads; - // Check and lock appropriate threads + // Enumerate appropriate threads if (attr & SCE_KERNEL_ATTR_MULTI) { - threads.reserve(new_state.waiters); + threads.reserve(_waiters); - idm::select([&](u32 id, ARMv7Thread& cpu) + idm::select([&](u32, ARMv7Thread& cpu) { - if (cpu->lock_if([&] { return cpu.owner == this && pat_test(new_state.pattern, cpu.GPR[1], cpu.GPR[0]); })) + if (cpu.owner == this && pat_test(new_pattern, cpu.GPR[1], cpu.GPR[0])) { threads.emplace_back(cpu); } @@ -1047,9 +1068,9 @@ private: } else { - idm::get(new_state.waiters, [&](ARMv7Thread& cpu) + idm::check(_waiters, [&](ARMv7Thread& cpu) { - if (cpu->lock_if([&] { return cpu.owner == this && pat_test(new_state.pattern, cpu.GPR[1], cpu.GPR[0]); })) + if (cpu.owner == this && pat_test(new_pattern, cpu.GPR[1], cpu.GPR[0])) { threads.emplace_back(cpu); } @@ -1059,14 +1080,13 @@ private: // Wake up threads for (ARMv7Thread& cpu : threads) { - const u32 old_pattern = ctrl.atomic_op([&](psp2_event_flag::ctrl_t& state) -> u32 + const u32 old_pattern = pattern.atomic_op([&](u32& value) -> u32 { - const u32 pat = state.pattern; + const u32 pat = value; if (pat_test(pat, cpu.GPR[1], cpu.GPR[0])) { - state.pattern &= pat_clear(cpu.GPR[1], cpu.GPR[0]); - state.waiters -= attr & SCE_KERNEL_ATTR_MULTI ? 1 : cpu.id; + value &= pat_clear(cpu.GPR[1], cpu.GPR[0]); return pat; } @@ -1079,56 +1099,43 @@ private: cpu.GPR[1] = old_pattern; cpu.state += cpu_flag::signal; cpu.owner = nullptr; - cpu->unlock(); - cpu->notify(); - } - else - { - cpu->unlock(); + waiters -= attr & SCE_KERNEL_ATTR_MULTI ? 1 : cpu.id; + cpu->lock_notify(); } } } } - // Clear pattern bits (bitwise AND) - void op_clear(u32 pattern) - { - ctrl.atomic_op([&](psp2_event_flag::ctrl_t& state) - { - state.pattern &= pattern; - }); - } - - // Wake up all threads void op_stop(vm::ptr ptr, s32 error) { - s32 result = 0; - const u32 pattern = ptr ? ptr->value() : ctrl.load().pattern; + const u32 _pattern = ptr ? ptr->value() : pattern.load(); + + std::vector> threads; idm::select([&](u32, ARMv7Thread& cpu) { - if (cpu->lock_if([&] { return cpu.owner == this; })) + if (cpu.owner == this) { - cpu.GPR[0] = error; - cpu.GPR[1] = pattern; - cpu.state += cpu_flag::signal; - cpu.owner = nullptr; - cpu->unlock(); - cpu->notify(); - result++; + threads.emplace_back(cpu); } }); if (ptr) { - *ptr = result; + *ptr = static_cast(threads.size()); } - ctrl.atomic_op([&](psp2_event_flag::ctrl_t& state) + for (ARMv7Thread& cpu : threads) { - state.pattern = pattern; - state.waiters = attr & SCE_KERNEL_ATTR_MULTI ? state.waiters - result : 0; - }); + cpu.GPR[0] = error; + cpu.GPR[1] = _pattern; + cpu.state += cpu_flag::signal; + cpu.owner = nullptr; + cpu.lock_notify(); + } + + pattern = _pattern; + waiters = 0; } }; @@ -1226,62 +1233,66 @@ error_code sceKernelWaitEventFlag(ARMv7Thread& cpu, s32 evfId, u32 bitPattern, u return SCE_KERNEL_ERROR_INVALID_UID; } - // First chance - const auto state = evf->ctrl.fetch_op([&](psp2_event_flag::ctrl_t& state) - { - if (!state.waiters && psp2_event_flag::pat_test(state.pattern, bitPattern, waitMode)) - { - state.pattern &= psp2_event_flag::pat_clear(bitPattern, waitMode); - } - else if (evf->attr & SCE_KERNEL_ATTR_MULTI) - { - state.waiters++; - } - else if (!state.waiters) - { - state.waiters = cpu.id; - } - }); + // First chance (TODO) + //const auto state = evf->ctrl.fetch_op([&](psp2_event_flag::ctrl_t& state) + //{ + // if (!state.waiters && psp2_event_flag::pat_test(state.pattern, bitPattern, waitMode)) + // { + // state.pattern &= psp2_event_flag::pat_clear(bitPattern, waitMode); + // } + // else if (evf->attr & SCE_KERNEL_ATTR_MULTI) + // { + // state.waiters++; + // } + // else if (!state.waiters) + // { + // state.waiters = cpu.id; + // } + //}); - if (state.waiters && !(evf->attr & SCE_KERNEL_ATTR_MULTI)) - { - return SCE_KERNEL_ERROR_EVF_MULTI; - } + //if (evf->waiters && !(evf->attr & SCE_KERNEL_ATTR_MULTI)) + //{ + // return SCE_KERNEL_ERROR_EVF_MULTI; + //} - if (!state.waiters && psp2_event_flag::pat_test(state.pattern, bitPattern, waitMode)) - { - if (pResultPat) *pResultPat = state.pattern; - return SCE_OK; - } + //if (!state.waiters && psp2_event_flag::pat_test(state.pattern, bitPattern, waitMode)) + //{ + // if (pResultPat) *pResultPat = state.pattern; + // return SCE_OK; + //} // Set register values for external use cpu.GPR[0] = waitMode; cpu.GPR[1] = bitPattern; // Second chance - if (evf->exec(psp2_event_flag::task::wait, cpu.id) && cpu.state.test_and_reset(cpu_flag::signal)) + if (!evf->exec(psp2_event_flag::task::wait, cpu.id) || !cpu.state.test_and_reset(cpu_flag::signal)) { - if (pResultPat) *pResultPat = cpu.GPR[1]; - return SCE_OK; + thread_lock lock(cpu); + + if (!thread_ctrl::wait_for(timeout, [&] { return cpu.state.test_and_reset(cpu_flag::signal); })) + { + if (!evf->exec(psp2_event_flag::task::timeout, cpu.id)) + { + if (!evf->exec(psp2_event_flag::task::signal, cpu.id)) + { + thread_ctrl::wait([&] { return cpu.state.test_and_reset(cpu_flag::signal); }); + } + else + { + cpu.state -= cpu_flag::signal; + } + } + } } - thread_lock entry(cpu); - - if (!thread_ctrl::wait_for(timeout, [&] { return cpu.state.test_and_reset(cpu_flag::signal); })) + if (cpu.GPR[0] == SCE_KERNEL_ERROR_EVF_MULTI) { - // Timeout cleanup - cpu.owner = nullptr; - cpu.GPR[0] = SCE_KERNEL_ERROR_WAIT_TIMEOUT; - cpu.GPR[1] = evf->ctrl.atomic_op([&](psp2_event_flag::ctrl_t& state) - { - state.waiters -= evf->attr & SCE_KERNEL_ATTR_MULTI ? 1 : cpu.id; - return state.pattern; - }); + return SCE_KERNEL_ERROR_EVF_MULTI; } if (pResultPat) *pResultPat = cpu.GPR[1]; if (pTimeout) *pTimeout = static_cast(std::max(0, timeout - (get_system_time() - start_time))); - return not_an_error(cpu.GPR[0]); } @@ -1303,23 +1314,17 @@ error_code sceKernelPollEventFlag(ARMv7Thread& cpu, s32 evfId, u32 bitPattern, u return SCE_KERNEL_ERROR_INVALID_UID; } - // First chance - const auto state = evf->ctrl.fetch_op([&](psp2_event_flag::ctrl_t& state) - { - if (!state.waiters && psp2_event_flag::pat_test(state.pattern, bitPattern, waitMode)) - { - state.pattern &= psp2_event_flag::pat_clear(bitPattern, waitMode); - } - }); + // First chance (TODO) + //const auto state = evf->ctrl.fetch_op([&](psp2_event_flag::ctrl_t& state) + //{ + // if (!state.waiters && psp2_event_flag::pat_test(state.pattern, bitPattern, waitMode)) + // { + // state.pattern &= psp2_event_flag::pat_clear(bitPattern, waitMode); + // } + //}); - if (psp2_event_flag::pat_test(state.pattern, bitPattern, waitMode)) + if (psp2_event_flag::pat_test(evf->pattern, bitPattern, waitMode)) { - if (!state.waiters) - { - *pResultPat = state.pattern; - return SCE_OK; - } - cpu.GPR[0] = waitMode; cpu.GPR[1] = bitPattern; @@ -1407,11 +1412,8 @@ error_code sceKernelGetEventFlagInfo(s32 evfId, vm::ptr pInfo->attr = evf->attr; pInfo->initPattern = evf->init; - - const auto state = evf->ctrl.load(); - - pInfo->currentPattern = state.pattern; - pInfo->numWaitThreads = evf->attr & SCE_KERNEL_ATTR_MULTI ? state.waiters : state.waiters != 0; + pInfo->currentPattern = evf->pattern; + pInfo->numWaitThreads = evf->attr & SCE_KERNEL_ATTR_MULTI ? evf->waiters.load() : evf->waiters != 0; return SCE_OK; }