CB_FUNC / SC_FUNC small update

This commit is contained in:
Nekotekina 2014-09-16 17:56:27 +04:00
parent 667da92934
commit b600cba180
7 changed files with 73 additions and 77 deletions

View File

@ -1,5 +1,4 @@
#pragma once
#include <array>
#include "Utilities/MTRingbuffer.h"
//#define BUFFERED_LOGGING 1

View File

@ -95,49 +95,37 @@ namespace cb_detail
return _bind_func_args<g, f, v>(CPU, args...) || (t == ARG_STACK);
}
template<typename RT>
template<typename T, _func_arg_type type>
struct _func_res
{
static_assert(sizeof(RT) <= 8, "Invalid callback result type");
static_assert(!std::is_pointer<RT>::value, "Invalid callback result type (pointer)");
static_assert(!std::is_reference<RT>::value, "Invalid callback result type (reference)");
static_assert(type == ARG_GENERAL, "Wrong use of _func_res template");
static_assert(sizeof(T) <= 8, "Invalid callback result type for ARG_GENERAL");
__forceinline static RT get_value(const PPUThread& CPU)
__forceinline static T get_value(const PPUThread& CPU)
{
if (std::is_floating_point<RT>::value)
{
return (RT)CPU.FPR[1];
}
else
{
return (RT&)CPU.GPR[3];
}
return (T&)CPU.GPR[3];
}
};
template<>
struct _func_res<u128>
template<typename T>
struct _func_res<T, ARG_FLOAT>
{
__forceinline static const u128 get_value(const PPUThread& CPU)
static_assert(sizeof(T) <= 8, "Invalid callback result type for ARG_FLOAT");
__forceinline static T get_value(const PPUThread& CPU)
{
return CPU.VPR[2];
return (T)CPU.FPR[1];
}
};
template<>
struct _func_res<const u128>
template<typename T>
struct _func_res<T, ARG_VECTOR>
{
__forceinline static const u128 get_value(const PPUThread& CPU)
{
return CPU.VPR[2];
}
};
static_assert(sizeof(T) == 16, "Invalid callback result type for ARG_VECTOR");
template<>
struct _func_res<void>
{
__forceinline static void get_value(const PPUThread& CPU)
__forceinline static T get_value(const PPUThread& CPU)
{
return (T&)CPU.VPR[2];
}
};
@ -150,7 +138,14 @@ namespace cb_detail
if (stack) CPU.GPR[1] -= FIXED_STACK_FRAME_SIZE;
CPU.FastCall2(pc, rtoc);
if (stack) CPU.GPR[1] += FIXED_STACK_FRAME_SIZE;
return _func_res<RT>::get_value(CPU);
static_assert(!std::is_pointer<RT>::value, "Invalid callback result type (pointer)");
static_assert(!std::is_reference<RT>::value, "Invalid callback result type (reference)");
const bool is_float = std::is_floating_point<RT>::value;
const bool is_vector = std::is_same<RT, u128>::value;
const _func_arg_type t = is_float ? ARG_FLOAT : (is_vector ? ARG_VECTOR : ARG_GENERAL);
return _func_res<RT, t>::get_value(CPU);
}
};

View File

@ -31,7 +31,7 @@ s64 spursInit(
{
// internal function
#ifdef PRX_DEBUG
return cb_caller<s32,vm::ptr<CellSpurs2>, u32, u32, s32, s32, s32, u32, u32, u32, u32, u32, u32, u32>::call(GetCurrentPPUThread(), libsre + 0x74E4, libsre_rtoc,
return cb_call<s32, vm::ptr<CellSpurs2>, u32, u32, s32, s32, s32, u32, u32, u32, u32, u32, u32, u32>(GetCurrentPPUThread(), libsre + 0x74E4, libsre_rtoc,
spurs, revision, sdkVersion, nSpus, spuPriority, ppuPriority, flags, Memory.RealToVirtualAddr(prefix), prefixSize, container, Memory.RealToVirtualAddr(swlPriority), swlMaxSpu, swlIsPreem);
#else
//spurs->spurs = new SPURSManager(attr);
@ -294,7 +294,7 @@ s64 cellSpursAttributeEnableSystemWorkload(vm::ptr<CellSpursAttribute> attr, vm:
return CELL_SPURS_CORE_ERROR_ALIGN;
}
const u32 nSpus = attr->m.nSpus;
const u32 nSpus = attr->_u32[2];
if (!nSpus)
{
return CELL_SPURS_CORE_ERROR_INVAL;

View File

@ -1535,7 +1535,7 @@ s32 _cellSyncLFQueuePushBody(vm::ptr<CellSyncLFQueue> queue, vm::ptr<const void>
else
{
#ifdef PRX_DEBUG
res = cb_caller<s32, vm::ptr<CellSyncLFQueue>, u32, u32, u64>::call(GetCurrentPPUThread(), libsre + 0x3050, libsre_rtoc,
res = cb_call<s32, vm::ptr<CellSyncLFQueue>, u32, u32, u64>(GetCurrentPPUThread(), libsre + 0x3050, libsre_rtoc,
queue, position_v.addr(), isBlocking, 0);
position = position_v->ToLE();
#else
@ -1580,7 +1580,7 @@ s32 _cellSyncLFQueuePushBody(vm::ptr<CellSyncLFQueue> queue, vm::ptr<const void>
else
{
#ifdef PRX_DEBUG
res = cb_caller<s32, vm::ptr<CellSyncLFQueue>, s32, u64>::call(GetCurrentPPUThread(), libsre + 0x355C, libsre_rtoc,
res = cb_call<s32, vm::ptr<CellSyncLFQueue>, s32, u64>(GetCurrentPPUThread(), libsre + 0x355C, libsre_rtoc,
queue, position, 0);
#else
res = syncLFQueueCompletePushPointer2(queue, position, nullptr);
@ -1930,7 +1930,7 @@ s32 _cellSyncLFQueuePopBody(vm::ptr<CellSyncLFQueue> queue, vm::ptr<void> buffer
else
{
#ifdef PRX_DEBUG
res = cb_caller<s32, vm::ptr<CellSyncLFQueue>, u32, u32, u64>::call(GetCurrentPPUThread(), libsre + 0x39AC, libsre_rtoc,
res = cb_call<s32, vm::ptr<CellSyncLFQueue>, u32, u32, u64>(GetCurrentPPUThread(), libsre + 0x39AC, libsre_rtoc,
queue, position_v.addr(), isBlocking, 0);
position = position_v->ToLE();
#else
@ -1972,7 +1972,7 @@ s32 _cellSyncLFQueuePopBody(vm::ptr<CellSyncLFQueue> queue, vm::ptr<void> buffer
else
{
#ifdef PRX_DEBUG
res = cb_caller<s32, vm::ptr<CellSyncLFQueue>, s32, u64, u64>::call(GetCurrentPPUThread(), libsre + 0x3EB8, libsre_rtoc,
res = cb_call<s32, vm::ptr<CellSyncLFQueue>, s32, u64, u64>(GetCurrentPPUThread(), libsre + 0x3EB8, libsre_rtoc,
queue, position, 0, 0);
#else
res = syncLFQueueCompletePopPointer2(queue, position, nullptr, 0);

View File

@ -46,7 +46,7 @@ namespace detail
template<typename T, int g_count, int f_count, int v_count>
struct bind_arg<T, ARG_VECTOR, g_count, f_count, v_count>
{
static_assert(std::is_same<T, u128>::value, "Invalid function argument type for ARG_VECTOR");
static_assert(sizeof(T) == 16, "Invalid function argument type for ARG_VECTOR");
static __forceinline T func(PPUThread& CPU)
{
@ -69,41 +69,37 @@ namespace detail
}
};
template<typename T>
template<typename T, bind_arg_type type>
struct bind_result
{
static_assert(sizeof(T) <= 8, "Invalid function result type");
static_assert(!std::is_pointer<T>::value, "Invalid function result type (pointer)");
static_assert(!std::is_reference<T>::value, "Invalid function result type (reference)");
static_assert(type == ARG_GENERAL, "Wrong use of bind_result template");
static_assert(sizeof(T) <= 8, "Invalid function result type for ARG_GENERAL");
static __forceinline void func(PPUThread& CPU, T result)
{
if (std::is_floating_point<T>::value)
{
CPU.FPR[1] = (double)result;
}
else
{
(T&)CPU.GPR[3] = result;
}
(T&)CPU.GPR[3] = result;
}
};
template<>
struct bind_result<u128>
template<typename T>
struct bind_result<T, ARG_FLOAT>
{
static __forceinline void func(PPUThread& CPU, const u128 result)
static_assert(sizeof(T) <= 8, "Invalid function result type for ARG_FLOAT");
static __forceinline void func(PPUThread& CPU, T result)
{
CPU.VPR[2] = result;
CPU.FPR[1] = (double)result;
}
};
template<>
struct bind_result<const u128>
template<typename T>
struct bind_result<T, ARG_VECTOR>
{
static __forceinline void func(PPUThread& CPU, const u128 result)
static_assert(sizeof(T) == 16, "Invalid function result type for ARG_VECTOR");
static __forceinline void func(PPUThread& CPU, const T result)
{
CPU.VPR[2] = result;
(T&)CPU.VPR[2] = result;
}
};
@ -157,13 +153,13 @@ namespace detail
return std::tuple_cat(std::tuple<T>(bind_arg<T, t, g, f, v>::func(CPU)), iterate<g, f, v, A...>(CPU));
}
template<typename RT, typename... TA>
template<typename RT, typename... T>
class func_binder;
template<typename... TA>
class func_binder<void, TA...> : public func_caller
template<typename... T>
class func_binder<void, T...> : public func_caller
{
typedef void(*func_t)(TA...);
typedef void(*func_t)(T...);
const func_t m_call;
public:
@ -176,14 +172,14 @@ namespace detail
virtual void operator()()
{
declCPU();
call<void>(m_call, iterate<0, 0, 0, TA...>(CPU));
call<void>(m_call, iterate<0, 0, 0, T...>(CPU));
}
};
template<typename TR, typename... TA>
template<typename RT, typename... T>
class func_binder : public func_caller
{
typedef TR(*func_t)(TA...);
typedef RT(*func_t)(T...);
const func_t m_call;
public:
@ -196,13 +192,19 @@ namespace detail
virtual void operator()()
{
declCPU();
bind_result<TR>::func(CPU, call<TR>(m_call, iterate<0, 0, 0, TA...>(CPU)));
static_assert(!std::is_pointer<RT>::value, "Invalid function result type (pointer)");
static_assert(!std::is_reference<RT>::value, "Invalid function result type (reference)");
const bool is_float = std::is_floating_point<RT>::value;
const bool is_vector = std::is_same<RT, u128>::value;
const bind_arg_type t = is_float ? ARG_FLOAT : (is_vector ? ARG_VECTOR : ARG_GENERAL);
bind_result<RT, t>::func(CPU, call<RT>(m_call, iterate<0, 0, 0, T...>(CPU)));
}
};
}
template<typename TR, typename... TA>
func_caller* bind_func(TR(*call)(TA...))
template<typename RT, typename... T>
func_caller* bind_func(RT(*call)(T...))
{
return new detail::func_binder<TR, TA...>(call);
return new detail::func_binder<RT, T...>(call);
}

View File

@ -11,8 +11,8 @@
#include "lv2/sys_event.h"
#include "lv2/sys_event_flag.h"
#include "lv2/sys_interrupt.h"
#include "lv2/sys_lwcond.h"
#include "lv2/sys_lwmutex.h"
//#include "lv2/sys_lwcond.h"
//#include "lv2/sys_lwmutex.h"
#include "lv2/sys_memory.h"
#include "lv2/sys_mmapper.h"
#include "lv2/sys_ppu_thread.h"
@ -21,7 +21,6 @@
#include "lv2/sys_rsx.h"
#include "lv2/sys_rwlock.h"
#include "lv2/sys_semaphore.h"
#include "lv2/sys_spinlock.h"
#include "lv2/sys_spu.h"
#include "lv2/sys_time.h"
#include "lv2/sys_timer.h"
@ -138,11 +137,11 @@ static func_caller* sc_table[kSyscallTableLength] =
bind_func(sys_semaphore_wait), //92 (0x05C)
bind_func(sys_semaphore_trywait), //93 (0x05D)
bind_func(sys_semaphore_post), //94 (0x05E)
null_func,//bind_func(sys_lwmutex_create), //95 (0x05F)
null_func,//bind_func(sys_lwmutex_destroy), //96 (0x060)
null_func,//bind_func(sys_lwmutex_lock), //97 (0x061)
null_func,//bind_func(sys_lwmutex_trylock), //98 (0x062)
null_func,//bind_func(sys_lwmutex_unlock), //99 (0x063)
null_func,//bind_func(sys_lwmutex_create), //95 (0x05F) // internal, used by sys_lwmutex_create
null_func,//bind_func(sys_lwmutex_destroy), //96 (0x060) // internal, used by sys_lwmutex_destroy
null_func,//bind_func(sys_lwmutex_lock), //97 (0x061) // internal, used by sys_lwmutex_lock
null_func,//bind_func(sys_lwmutex_trylock), //98 (0x062) // internal, used by sys_lwmutex_unlock
null_func,//bind_func(sys_lwmutex_unlock), //99 (0x063) // internal, used by sys_lwmutex_trylock
bind_func(sys_mutex_create), //100 (0x064)
bind_func(sys_mutex_destroy), //101 (0x065)
bind_func(sys_mutex_lock), //102 (0x066)
@ -160,7 +159,7 @@ static func_caller* sc_table[kSyscallTableLength] =
bind_func(sys_semaphore_get_value), //114 (0x072)
null_func,//bind_func(sys_semaphore_...) //115 (0x073)
null_func,//bind_func(sys_semaphore_...) //116 (0x074)
null_func,//bind_func(sys_semaphore_...) //117 (0x075)
null_func,//bind_func(sys_semaphore_...) //117 (0x075) // internal, used by sys_lwmutex_unlock
bind_func(sys_event_flag_clear), //118 (0x076)
null_func,//bind_func(sys_event_...) //119 (0x077) ROOT
bind_func(sys_rwlock_create), //120 (0x078)

View File

@ -26,6 +26,7 @@
#include <memory>
#include <vector>
#include <set>
#include <array>
#include <string>
#include <ostream>
#include <sstream>