diff --git a/Utilities/SMutex.cpp b/Utilities/SMutex.cpp index fe853c191e..1803095f9d 100644 --- a/Utilities/SMutex.cpp +++ b/Utilities/SMutex.cpp @@ -6,7 +6,12 @@ #include "Utilities/SMutex.h" -__forceinline void SM_Sleep() +bool SM_IsAborted() +{ + return Emu.IsStopped(); +} + +void SM_Sleep() { if (NamedThreadBase* t = GetCurrentNamedThread()) { @@ -20,12 +25,12 @@ __forceinline void SM_Sleep() thread_local size_t g_this_thread_id = 0; -__forceinline size_t SM_GetCurrentThreadId() +size_t SM_GetCurrentThreadId() { return g_this_thread_id ? g_this_thread_id : g_this_thread_id = std::hash()(std::this_thread::get_id()); } -__forceinline u32 SM_GetCurrentCPUThreadId() +u32 SM_GetCurrentCPUThreadId() { if (CPUThread* t = GetCurrentCPUThread()) { @@ -34,7 +39,7 @@ __forceinline u32 SM_GetCurrentCPUThreadId() return 0; } -__forceinline be_t SM_GetCurrentCPUThreadIdBE() +be_t SM_GetCurrentCPUThreadIdBE() { return be_t::MakeFromLE(SM_GetCurrentCPUThreadId()); } diff --git a/Utilities/SMutex.h b/Utilities/SMutex.h index f4bdc7dff9..efd99b840f 100644 --- a/Utilities/SMutex.h +++ b/Utilities/SMutex.h @@ -1,11 +1,10 @@ #pragma once -#include "BEType.h" -#include "Emu/System.h" -extern void SM_Sleep(); -extern size_t SM_GetCurrentThreadId(); -extern u32 SM_GetCurrentCPUThreadId(); -extern be_t SM_GetCurrentCPUThreadIdBE(); +bool SM_IsAborted(); +void SM_Sleep(); +size_t SM_GetCurrentThreadId(); +u32 SM_GetCurrentCPUThreadId(); +be_t SM_GetCurrentCPUThreadIdBE(); enum SMutexResult { @@ -66,7 +65,7 @@ public: SMutexResult trylock(T tid) { - if (Emu.IsStopped()) + if (SM_IsAborted()) { return SMR_ABORT; } @@ -90,7 +89,7 @@ public: SMutexResult unlock(T tid, T to = GetFreeValue()) { - if (Emu.IsStopped()) + if (SM_IsAborted()) { return SMR_ABORT; } @@ -148,7 +147,7 @@ public: { if (!tid) { - if (!Emu.IsStopped()) + if (!SM_IsAborted()) { assert(!"SMutexLockerBase: thread id == 0"); } diff --git a/rpcs3/Emu/CPU/CPUThread.cpp b/rpcs3/Emu/CPU/CPUThread.cpp index cd23b42d1c..9cfa145da7 100644 --- a/rpcs3/Emu/CPU/CPUThread.cpp +++ b/rpcs3/Emu/CPU/CPUThread.cpp @@ -36,6 +36,10 @@ CPUThread::~CPUThread() safe_delete(m_dec); } +bool CPUThread::IsRunning() const { return m_status == Running; } +bool CPUThread::IsPaused() const { return m_status == Paused; } +bool CPUThread::IsStopped() const { return m_status == Stopped; } + void CPUThread::Close() { ThreadBase::Stop(m_sync_wait); diff --git a/rpcs3/Emu/CPU/CPUThread.h b/rpcs3/Emu/CPU/CPUThread.h index 466295df8a..2a8ea78f2c 100644 --- a/rpcs3/Emu/CPU/CPUThread.h +++ b/rpcs3/Emu/CPU/CPUThread.h @@ -1,7 +1,5 @@ #pragma once -#include "Emu/Memory/MemoryBlock.h" #include "Emu/CPU/CPUDecoder.h" -#include "Utilities/SMutex.h" enum CPUThreadType :unsigned char { @@ -147,13 +145,13 @@ public: static std::vector ErrorToString(const u32 error); std::vector ErrorToString() { return ErrorToString(m_error); } - bool IsOk() const { return m_error == 0; } - bool IsRunning() const { return m_status == Running; } - bool IsPaused() const { return m_status == Paused; } - bool IsStopped() const { return m_status == Stopped; } + bool IsOk() const { return m_error == 0; } + bool IsRunning() const; + bool IsPaused() const; + bool IsStopped() const; bool IsJoinable() const { return m_joinable; } - bool IsJoining() const { return m_joining; } + bool IsJoining() const { return m_joining; } void SetJoinable(bool joinable) { m_joinable = joinable; } void SetJoining(bool joining) { m_joining = joining; } diff --git a/rpcs3/Emu/Cell/PPCThread.cpp b/rpcs3/Emu/Cell/PPCThread.cpp index 86fdb951c0..96d9b732a2 100644 --- a/rpcs3/Emu/Cell/PPCThread.cpp +++ b/rpcs3/Emu/Cell/PPCThread.cpp @@ -1,5 +1,6 @@ #include "stdafx.h" #include "PPCThread.h" +#include "Emu/Memory/Memory.h" PPCThread* GetCurrentPPCThread() { diff --git a/rpcs3/Emu/Memory/MemoryBlock.h b/rpcs3/Emu/Memory/MemoryBlock.h index fa5b913797..43c36df710 100644 --- a/rpcs3/Emu/Memory/MemoryBlock.h +++ b/rpcs3/Emu/Memory/MemoryBlock.h @@ -2,193 +2,9 @@ #define PAGE_4K(x) (x + 4095) & ~(4095) -union u128 -{ - struct - { - u64 hi; - u64 lo; - }; - - u64 _u64[2]; - u32 _u32[4]; - u16 _u16[8]; - u8 _u8[16]; - - operator u64() const { return _u64[0]; } - operator u32() const { return _u32[0]; } - operator u16() const { return _u16[0]; } - operator u8() const { return _u8[0]; } - - operator bool() const { return _u64[0] != 0 || _u64[1] != 0; } - - static u128 From128( u64 hi, u64 lo ) - { - u128 ret = {hi, lo}; - return ret; - } - - static u128 From64( u64 src ) - { - u128 ret = {0, src}; - return ret; - } - - static u128 From32( u32 src ) - { - u128 ret; - ret._u32[0] = src; - ret._u32[1] = 0; - ret._u32[2] = 0; - ret._u32[3] = 0; - return ret; - } - - static u128 FromBit ( u32 bit ) - { - u128 ret; - if (bit < 64) - { - ret.hi = 0; - ret.lo = (u64)1 << bit; - } - else if (bit < 128) - { - ret.hi = (u64)1 << (bit - 64); - ret.lo = 0; - } - else - { - ret.hi = 0; - ret.lo = 0; - } - return ret; - } - - bool operator == ( const u128& right ) const - { - return (lo == right.lo) && (hi == right.hi); - } - - bool operator != ( const u128& right ) const - { - return (lo != right.lo) || (hi != right.hi); - } - - u128 operator | ( const u128& right ) const - { - return From128(hi | right.hi, lo | right.lo); - } - - u128 operator & ( const u128& right ) const - { - return From128(hi & right.hi, lo & right.lo); - } - - u128 operator ^ ( const u128& right ) const - { - return From128(hi ^ right.hi, lo ^ right.lo); - } - - u128 operator ~ () const - { - return From128(~hi, ~lo); - } -}; - -union s128 -{ - struct - { - s64 hi; - s64 lo; - }; - - u64 _i64[2]; - u32 _i32[4]; - u16 _i16[8]; - u8 _i8[16]; - - operator s64() const { return _i64[0]; } - operator s32() const { return _i32[0]; } - operator s16() const { return _i16[0]; } - operator s8() const { return _i8[0]; } - - operator bool() const { return _i64[0] != 0 || _i64[1] != 0; } - - static s128 From64( s64 src ) - { - s128 ret = {src, 0}; - return ret; - } - - static s128 From32( s32 src ) - { - s128 ret; - ret._i32[0] = src; - ret._i32[1] = 0; - ret.hi = 0; - return ret; - } - - bool operator == ( const s128& right ) const - { - return (lo == right.lo) && (hi == right.hi); - } - - bool operator != ( const s128& right ) const - { - return (lo != right.lo) || (hi != right.hi); - } -}; - #include #include -//TODO: SSE style -/* -struct u128 -{ - __m128 m_val; - - u128 GetValue128() - { - u128 ret; - _mm_store_ps( (float*)&ret, m_val ); - return ret; - } - - u64 GetValue64() - { - u64 ret; - _mm_store_ps( (float*)&ret, m_val ); - return ret; - } - - u32 GetValue32() - { - u32 ret; - _mm_store_ps( (float*)&ret, m_val ); - return ret; - } - - u16 GetValue16() - { - u16 ret; - _mm_store_ps( (float*)&ret, m_val ); - return ret; - } - - u8 GetValue8() - { - u8 ret; - _mm_store_ps( (float*)&ret, m_val ); - return ret; - } -}; -*/ - - struct MemInfo { u64 addr; diff --git a/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp b/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp index 57ddfa1626..d09df13b83 100644 --- a/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp @@ -16,6 +16,8 @@ //Module sysPrxForUser("sysPrxForUser", sysPrxForUser_init); Module *sysPrxForUser = nullptr; +extern u32 LoadSpuImage(vfsStream& stream, u32& spu_ep); + int _sys_heap_create_heap(const u32 heap_addr, const u32 align, const u32 size) { sysPrxForUser->Warning("_sys_heap_create_heap(heap_addr=0x%x, align=0x%x, size=0x%x)", heap_addr, align, size); diff --git a/rpcs3/Emu/SysCalls/SysCalls.cpp b/rpcs3/Emu/SysCalls/SysCalls.cpp index 024f39cea6..3c5e3fdd26 100644 --- a/rpcs3/Emu/SysCalls/SysCalls.cpp +++ b/rpcs3/Emu/SysCalls/SysCalls.cpp @@ -939,3 +939,8 @@ void SysCalls::DoSyscall(u32 code) declCPU(); RESULT(0); } + +IdManager& SysCallBase::GetIdManager() const +{ + return Emu.GetIdManager(); +} \ No newline at end of file diff --git a/rpcs3/Emu/SysCalls/SysCalls.h b/rpcs3/Emu/SysCalls/SysCalls.h index 51ba7168e0..3a5c3534be 100644 --- a/rpcs3/Emu/SysCalls/SysCalls.h +++ b/rpcs3/Emu/SysCalls/SysCalls.h @@ -54,6 +54,7 @@ class SysCallBase : public LogBase private: std::string m_module_name; //u32 m_id; + IdManager& GetIdManager() const; public: SysCallBase(const std::string& name/*, u32 id*/) @@ -69,7 +70,7 @@ public: bool CheckId(u32 id) const { - return Emu.GetIdManager().CheckID(id) && Emu.GetIdManager().GetID(id).m_name == GetName(); + return GetIdManager().CheckID(id) && GetIdManager().GetID(id).m_name == GetName(); } template bool CheckId(u32 id, T*& data) @@ -80,7 +81,7 @@ public: template u32 GetNewId(T* data, IDType type = TYPE_OTHER) { - return Emu.GetIdManager().GetNewID(GetName(), data, type); + return GetIdManager().GetNewID(GetName(), data, type); } }; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_rwlock.cpp b/rpcs3/Emu/SysCalls/lv2/sys_rwlock.cpp index 28a7d61d21..593b0ad532 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_rwlock.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_rwlock.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "Utilities/Log.h" #include "Emu/Cell/PPUThread.h" +#include "Emu/System.h" #include "Emu/SysCalls/SysCalls.h" #include "sys_rwlock.h" diff --git a/rpcs3/Emu/SysCalls/lv2/sys_spu.h b/rpcs3/Emu/SysCalls/lv2/sys_spu.h index 7f6399aa7b..e050703dd4 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_spu.h +++ b/rpcs3/Emu/SysCalls/lv2/sys_spu.h @@ -1,7 +1,5 @@ #pragma once -u32 LoadSpuImage(vfsStream& stream, u32& spu_ep); - enum { SYS_SPU_THREAD_GROUP_TYPE_NORMAL = 0x00, diff --git a/rpcs3/stdafx.h b/rpcs3/stdafx.h index 4304cf8f5b..374e4b14a4 100644 --- a/rpcs3/stdafx.h +++ b/rpcs3/stdafx.h @@ -55,6 +55,189 @@ typedef int16_t s16; typedef int32_t s32; typedef int64_t s64; +union u128 +{ + struct + { + u64 hi; + u64 lo; + }; + + u64 _u64[2]; + u32 _u32[4]; + u16 _u16[8]; + u8 _u8[16]; + + operator u64() const { return _u64[0]; } + operator u32() const { return _u32[0]; } + operator u16() const { return _u16[0]; } + operator u8() const { return _u8[0]; } + + operator bool() const { return _u64[0] != 0 || _u64[1] != 0; } + + static u128 From128(u64 hi, u64 lo) + { + u128 ret = { hi, lo }; + return ret; + } + + static u128 From64(u64 src) + { + u128 ret = { 0, src }; + return ret; + } + + static u128 From32(u32 src) + { + u128 ret; + ret._u32[0] = src; + ret._u32[1] = 0; + ret._u32[2] = 0; + ret._u32[3] = 0; + return ret; + } + + static u128 FromBit(u32 bit) + { + u128 ret; + if (bit < 64) + { + ret.hi = 0; + ret.lo = (u64)1 << bit; + } + else if (bit < 128) + { + ret.hi = (u64)1 << (bit - 64); + ret.lo = 0; + } + else + { + ret.hi = 0; + ret.lo = 0; + } + return ret; + } + + bool operator == (const u128& right) const + { + return (lo == right.lo) && (hi == right.hi); + } + + bool operator != (const u128& right) const + { + return (lo != right.lo) || (hi != right.hi); + } + + u128 operator | (const u128& right) const + { + return From128(hi | right.hi, lo | right.lo); + } + + u128 operator & (const u128& right) const + { + return From128(hi & right.hi, lo & right.lo); + } + + u128 operator ^ (const u128& right) const + { + return From128(hi ^ right.hi, lo ^ right.lo); + } + + u128 operator ~ () const + { + return From128(~hi, ~lo); + } +}; + +union s128 +{ + struct + { + s64 hi; + s64 lo; + }; + + u64 _i64[2]; + u32 _i32[4]; + u16 _i16[8]; + u8 _i8[16]; + + operator s64() const { return _i64[0]; } + operator s32() const { return _i32[0]; } + operator s16() const { return _i16[0]; } + operator s8() const { return _i8[0]; } + + operator bool() const { return _i64[0] != 0 || _i64[1] != 0; } + + static s128 From64(s64 src) + { + s128 ret = { src, 0 }; + return ret; + } + + static s128 From32(s32 src) + { + s128 ret; + ret._i32[0] = src; + ret._i32[1] = 0; + ret.hi = 0; + return ret; + } + + bool operator == (const s128& right) const + { + return (lo == right.lo) && (hi == right.hi); + } + + bool operator != (const s128& right) const + { + return (lo != right.lo) || (hi != right.hi); + } +}; + +//TODO: SSE style +/* +struct u128 +{ + __m128 m_val; + + u128 GetValue128() + { + u128 ret; + _mm_store_ps( (float*)&ret, m_val ); + return ret; + } + + u64 GetValue64() + { + u64 ret; + _mm_store_ps( (float*)&ret, m_val ); + return ret; + } + + u32 GetValue32() + { + u32 ret; + _mm_store_ps( (float*)&ret, m_val ); + return ret; + } + + u16 GetValue16() + { + u16 ret; + _mm_store_ps( (float*)&ret, m_val ); + return ret; + } + + u8 GetValue8() + { + u8 ret; + _mm_store_ps( (float*)&ret, m_val ); + return ret; + } +}; +*/ + #include "Utilities/StrFmt.h" #include "Utilities/GNU.h" #include "Utilities/BEType.h"