2014-07-31 18:08:02 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
namespace vm
|
|
|
|
|
{
|
2014-08-01 18:27:48 +02:00
|
|
|
template<typename T, typename AT = u32>
|
|
|
|
|
class _ref_base
|
|
|
|
|
{
|
2014-09-01 18:16:44 +02:00
|
|
|
protected:
|
2014-08-01 18:27:48 +02:00
|
|
|
AT m_addr;
|
|
|
|
|
|
|
|
|
|
public:
|
2014-09-01 18:16:44 +02:00
|
|
|
typedef T type;
|
2015-02-01 08:09:24 +01:00
|
|
|
static_assert(!std::is_pointer<T>::value, "vm::_ref_base<> error: invalid type (pointer)");
|
|
|
|
|
static_assert(!std::is_reference<T>::value, "vm::_ref_base<> error: invalid type (reference)");
|
2014-09-01 23:22:07 +02:00
|
|
|
typedef typename remove_be_t<T>::type le_type;
|
|
|
|
|
typedef typename to_be_t<T>::type be_type;
|
2014-09-01 18:16:44 +02:00
|
|
|
|
2014-08-01 18:27:48 +02:00
|
|
|
operator T&()
|
|
|
|
|
{
|
|
|
|
|
return get_ref<T>(m_addr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
operator const T&() const
|
|
|
|
|
{
|
|
|
|
|
return get_ref<const T>(m_addr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AT addr() const
|
|
|
|
|
{
|
|
|
|
|
return m_addr;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 22:30:33 +01:00
|
|
|
static _ref_base make(const AT& addr)
|
2014-08-01 18:27:48 +02:00
|
|
|
{
|
2015-01-19 22:30:33 +01:00
|
|
|
return reinterpret_cast<_ref_base&>(addr);
|
2014-08-01 18:27:48 +02:00
|
|
|
}
|
2014-09-01 23:22:07 +02:00
|
|
|
|
|
|
|
|
_ref_base& operator = (le_type right)
|
|
|
|
|
{
|
|
|
|
|
get_ref<T>(m_addr) = right;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const _ref_base& operator = (le_type right) const
|
|
|
|
|
{
|
|
|
|
|
get_ref<T>(m_addr) = right;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_ref_base& operator = (be_type right)
|
|
|
|
|
{
|
|
|
|
|
get_ref<T>(m_addr) = right;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const _ref_base& operator = (be_type right) const
|
|
|
|
|
{
|
|
|
|
|
get_ref<T>(m_addr) = right;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2014-08-01 18:27:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//BE reference to LE data
|
2015-03-09 02:57:50 +01:00
|
|
|
template<typename T, typename AT = u32> using brefl = _ref_base<T, typename to_be_t<AT>::type>;
|
2014-08-01 18:27:48 +02:00
|
|
|
|
|
|
|
|
//BE reference to BE data
|
2015-03-09 02:57:50 +01:00
|
|
|
template<typename T, typename AT = u32> using brefb = _ref_base<typename to_be_t<T>::type, typename to_be_t<AT>::type>;
|
2014-08-01 18:27:48 +02:00
|
|
|
|
|
|
|
|
//LE reference to BE data
|
2015-03-09 02:57:50 +01:00
|
|
|
template<typename T, typename AT = u32> using lrefb = _ref_base<typename to_be_t<T>::type, AT>;
|
2014-08-01 18:27:48 +02:00
|
|
|
|
|
|
|
|
//LE reference to LE data
|
2015-03-09 02:57:50 +01:00
|
|
|
template<typename T, typename AT = u32> using lrefl = _ref_base<T, AT>;
|
2014-08-01 18:27:48 +02:00
|
|
|
|
|
|
|
|
namespace ps3
|
|
|
|
|
{
|
|
|
|
|
//default reference for HLE functions (LE reference to BE data)
|
2015-03-09 02:57:50 +01:00
|
|
|
template<typename T, typename AT = u32> using ref = lrefb<T, AT>;
|
2014-08-01 18:27:48 +02:00
|
|
|
|
|
|
|
|
//default reference for HLE structures (BE reference to BE data)
|
2015-03-09 02:57:50 +01:00
|
|
|
template<typename T, typename AT = u32> using bref = brefb<T, AT>;
|
2014-08-01 18:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace psv
|
|
|
|
|
{
|
|
|
|
|
//default reference for HLE functions & structures (LE reference to LE data)
|
2015-03-09 02:57:50 +01:00
|
|
|
template<typename T, typename AT = u32> using ref = lrefl<T, AT>;
|
2014-08-01 18:27:48 +02:00
|
|
|
}
|
2014-09-01 18:16:44 +02:00
|
|
|
|
|
|
|
|
//PS3 emulation is main now, so lets it be as default
|
|
|
|
|
using namespace ps3;
|
2015-01-13 18:38:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace fmt
|
|
|
|
|
{
|
2015-03-09 02:57:50 +01:00
|
|
|
// external specialization for fmt::format function
|
2015-01-18 23:54:56 +01:00
|
|
|
|
|
|
|
|
template<typename T, typename AT>
|
2015-03-09 02:57:50 +01:00
|
|
|
struct unveil<vm::_ref_base<T, AT>, false>
|
2015-01-18 23:54:56 +01:00
|
|
|
{
|
|
|
|
|
typedef typename unveil<AT>::result_type result_type;
|
2015-01-13 18:38:32 +01:00
|
|
|
|
2015-03-09 02:57:50 +01:00
|
|
|
__forceinline static result_type get_value(const vm::_ref_base<T, AT>& arg)
|
2015-01-13 18:38:32 +01:00
|
|
|
{
|
2015-01-18 23:54:56 +01:00
|
|
|
return unveil<AT>::get_value(arg.addr());
|
|
|
|
|
}
|
|
|
|
|
};
|
2015-01-13 18:38:32 +01:00
|
|
|
}
|
2015-01-19 15:16:31 +01:00
|
|
|
|
|
|
|
|
// external specializations for PPU GPR (SC_FUNC.h, CB_FUNC.h)
|
|
|
|
|
|
|
|
|
|
template<typename T, bool is_enum>
|
|
|
|
|
struct cast_ppu_gpr;
|
|
|
|
|
|
|
|
|
|
template<typename T, typename AT>
|
2015-03-09 02:57:50 +01:00
|
|
|
struct cast_ppu_gpr<vm::_ref_base<T, AT>, false>
|
2015-01-19 15:16:31 +01:00
|
|
|
{
|
2015-03-09 02:57:50 +01:00
|
|
|
__forceinline static u64 to_gpr(const vm::_ref_base<T, AT>& value)
|
2015-01-19 15:16:31 +01:00
|
|
|
{
|
|
|
|
|
return value.addr();
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-09 02:57:50 +01:00
|
|
|
__forceinline static vm::_ref_base<T, AT> from_gpr(const u64 reg)
|
2015-01-19 15:16:31 +01:00
|
|
|
{
|
2015-03-09 02:57:50 +01:00
|
|
|
return vm::_ref_base<T, AT>::make(cast_ppu_gpr<AT, std::is_enum<AT>::value>::from_gpr(reg));
|
2015-01-19 15:16:31 +01:00
|
|
|
}
|
|
|
|
|
};
|
2015-01-19 19:02:33 +01:00
|
|
|
|
|
|
|
|
// external specializations for ARMv7 GPR
|
|
|
|
|
|
|
|
|
|
template<typename T, bool is_enum>
|
|
|
|
|
struct cast_armv7_gpr;
|
|
|
|
|
|
|
|
|
|
template<typename T, typename AT>
|
2015-03-09 02:57:50 +01:00
|
|
|
struct cast_armv7_gpr<vm::_ref_base<T, AT>, false>
|
2015-01-19 19:02:33 +01:00
|
|
|
{
|
2015-03-09 02:57:50 +01:00
|
|
|
__forceinline static u32 to_gpr(const vm::_ref_base<T, AT>& value)
|
2015-01-19 19:02:33 +01:00
|
|
|
{
|
|
|
|
|
return value.addr();
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-09 02:57:50 +01:00
|
|
|
__forceinline static vm::_ref_base<T, AT> from_gpr(const u32 reg)
|
2015-01-19 19:02:33 +01:00
|
|
|
{
|
2015-03-09 02:57:50 +01:00
|
|
|
return vm::_ref_base<T, AT>::make(cast_armv7_gpr<AT, std::is_enum<AT>::value>::from_gpr(reg));
|
2015-01-19 19:02:33 +01:00
|
|
|
}
|
|
|
|
|
};
|