Remove CALL_FUNC, implement ppu_execute<>()

This commit is contained in:
Nekotekina 2018-10-06 17:09:09 +03:00
parent 4ab777b429
commit 73d35b0236
3 changed files with 26 additions and 27 deletions

View File

@ -491,7 +491,7 @@ void _spurs::handler_wait_ready(ppu_thread& ppu, vm::ptr<CellSpurs> spurs)
{
if (spurs->handlerExiting)
{
CHECK_SUCCESS(CALL_FUNC(ppu, sys_lwmutex_unlock, ppu, spurs.ptr(&CellSpurs::mutex)));
CHECK_SUCCESS(ppu_execute<&sys_lwmutex_unlock>(ppu, spurs.ptr(&CellSpurs::mutex)));
return sys_ppu_thread_exit(ppu, 0);
}

View File

@ -451,7 +451,7 @@ s32 cellVdecOpen(ppu_thread& ppu, vm::cptr<CellVdecType> type, vm::cptr<CellVdec
*handle = vdec->id;
vm::var<u64> _tid;
CALL_FUNC(ppu, sys_ppu_thread_create, ppu, +_tid, 1148, 0, 900, 0x4000, SYS_PPU_THREAD_CREATE_INTERRUPT, vm::null);
ppu_execute<&sys_ppu_thread_create>(ppu, +_tid, 1148, 0, 900, 0x4000, SYS_PPU_THREAD_CREATE_INTERRUPT, vm::null);
vdec->gpr[13] = idm::get<ppu_thread>(*_tid)->gpr[13];
vdec->ppu_tid = *_tid;
@ -471,7 +471,7 @@ s32 cellVdecOpenEx(ppu_thread& ppu, vm::cptr<CellVdecTypeEx> type, vm::cptr<Cell
*handle = vdec->id;
vm::var<u64> _tid;
CALL_FUNC(ppu, sys_ppu_thread_create, ppu, +_tid, 1148, 0, 900, 0x4000, SYS_PPU_THREAD_CREATE_INTERRUPT, vm::null);
ppu_execute<&sys_ppu_thread_create>(ppu, +_tid, 1148, 0, 900, 0x4000, SYS_PPU_THREAD_CREATE_INTERRUPT, vm::null);
vdec->gpr[13] = idm::get<ppu_thread>(*_tid)->gpr[13];
vdec->ppu_tid = *_tid;
@ -501,8 +501,7 @@ s32 cellVdecClose(ppu_thread& ppu, u32 handle)
vdec->notify();
vdec->join();
CALL_FUNC(ppu, sys_interrupt_thread_disestablish, ppu, vdec->ppu_tid);
idm::remove<ppu_thread>(handle);
ppu_execute<&sys_interrupt_thread_disestablish>(ppu, vdec->ppu_tid);
return CELL_OK;
}

View File

@ -112,7 +112,7 @@ class ppu_module_manager final
static ppu_static_variable& access_static_variable(const char* module, u32 vnid);
// Global variable for each registered function
template <typename T, T Func>
template <auto* Func>
struct registered
{
static ppu_static_function* info;
@ -121,40 +121,42 @@ class ppu_module_manager final
public:
static const ppu_static_module* get_module(const std::string& name);
template <typename T, T Func>
template <auto* Func>
static auto& register_static_function(const char* module, const char* name, ppu_function_t func, u32 fnid)
{
auto& info = access_static_function(module, fnid);
info.name = name;
info.index = ppu_function_manager::register_function<T, Func>(func);
info.index = ppu_function_manager::register_function<decltype(Func), Func>(func);
info.flags = 0;
info.type = typeid(T).name();
info.type = typeid(*Func).name();
registered<T, Func>::info = &info;
registered<Func>::info = &info;
return info;
}
template <typename T, T Func>
template <auto* Func>
static auto& find_static_function()
{
return *registered<T, Func>::info;
return *registered<Func>::info;
}
template <typename T, T* Var>
template <auto* Var>
static auto& register_static_variable(const char* module, const char* name, u32 vnid)
{
static_assert(std::is_same<u32, std::decay_t<typename T::addr_type>>::value, "Static variable registration: vm::gvar<T> expected");
using gvar = std::decay_t<decltype(*Var)>;
static_assert(std::is_same<u32, typename gvar::addr_type>::value, "Static variable registration: vm::gvar<T> expected");
auto& info = access_static_variable(module, vnid);
info.name = name;
info.var = reinterpret_cast<vm::gvar<void>*>(Var);
info.init = [] {};
info.size = sizeof(typename T::type);
info.align = alignof(typename T::type);
info.type = typeid(T).name();
info.size = sizeof(typename gvar::type);
info.align = alignof(typename gvar::type);
info.type = typeid(*Var).name();
info.flags = 0;
info.addr = 0;
@ -267,24 +269,22 @@ public:
static const ppu_static_module sys_lv2dbg;
};
template<typename T, T Func>
ppu_static_function* ppu_module_manager::registered<T, Func>::info = nullptr;
template <auto* Func>
ppu_static_function* ppu_module_manager::registered<Func>::info = nullptr;
// Call specified function directly if LLE is not available, call LLE equivalent in callback style otherwise
template<typename T, T Func, typename... Args, typename RT = std::invoke_result_t<T, Args...>>
inline RT ppu_execute_function_or_callback(ppu_thread& ppu, Args&&... args)
template <auto* Func, typename... Args, typename RT = std::invoke_result_t<decltype(Func), ppu_thread&, Args...>>
inline RT ppu_execute(ppu_thread& ppu, Args... args)
{
vm::ptr<RT(Args...)> func = vm::cast(*ppu_module_manager::find_static_function<T, Func>().export_addr);
return func(ppu, std::forward<Args>(args)...);
vm::ptr<RT(Args...)> func = vm::cast(*ppu_module_manager::find_static_function<Func>().export_addr);
return func(ppu, args...);
}
#define CALL_FUNC(ppu, func, ...) ppu_execute_function_or_callback<decltype(&func), &func>(ppu, __VA_ARGS__)
#define REG_FNID(module, nid, func) ppu_module_manager::register_static_function<decltype(&func), &func>(#module, ppu_select_name(#func, nid), BIND_FUNC(func, ppu.cia = (u32)ppu.lr & ~3), ppu_generate_id(nid))
#define REG_FNID(module, nid, func) ppu_module_manager::register_static_function<&func>(#module, ppu_select_name(#func, nid), BIND_FUNC(func, ppu.cia = (u32)ppu.lr & ~3), ppu_generate_id(nid))
#define REG_FUNC(module, func) REG_FNID(module, #func, func)
#define REG_VNID(module, nid, var) ppu_module_manager::register_static_variable<decltype(var), &var>(#module, ppu_select_name(#var, nid), ppu_generate_id(nid))
#define REG_VNID(module, nid, var) ppu_module_manager::register_static_variable<&var>(#module, ppu_select_name(#var, nid), ppu_generate_id(nid))
#define REG_VAR(module, var) REG_VNID(module, #var, var)