From 0eebfb0aaaad4ae3fefe26f251b1975dc78ba21c Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Thu, 12 Feb 2015 23:10:25 +0300 Subject: [PATCH] Memory cleanup: u64 -> u32, empty TLS fixed cellGameContentPermit fixed --- rpcs3/Emu/Cell/RawSPUThread.cpp | 12 +- rpcs3/Emu/Cell/RawSPUThread.h | 5 +- rpcs3/Emu/Memory/Memory.cpp | 202 +++++++------------ rpcs3/Emu/Memory/Memory.h | 12 +- rpcs3/Emu/Memory/MemoryBlock.h | 92 ++++----- rpcs3/Emu/SysCalls/Modules/cellGame.cpp | 23 ++- rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp | 6 +- rpcs3/Emu/SysCalls/Modules/cellGcmSys.h | 1 - rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp | 12 +- rpcs3/Gui/RSXDebugger.cpp | 8 +- 10 files changed, 161 insertions(+), 212 deletions(-) diff --git a/rpcs3/Emu/Cell/RawSPUThread.cpp b/rpcs3/Emu/Cell/RawSPUThread.cpp index ba4c98f363..041ea63968 100644 --- a/rpcs3/Emu/Cell/RawSPUThread.cpp +++ b/rpcs3/Emu/Cell/RawSPUThread.cpp @@ -19,9 +19,9 @@ RawSPUThread::~RawSPUThread() Memory.CloseRawSPU(this, m_index); } -bool RawSPUThread::Read32(const u64 addr, u32* value) +bool RawSPUThread::Read32(const u32 addr, u32* value) { - const u64 offset = addr - GetStartAddr() - RAW_SPU_PROB_OFFSET; + const u32 offset = addr - GetStartAddr() - RAW_SPU_PROB_OFFSET; switch (offset) { @@ -68,9 +68,9 @@ bool RawSPUThread::Read32(const u64 addr, u32* value) return true; } -bool RawSPUThread::Write32(const u64 addr, const u32 value) +bool RawSPUThread::Write32(const u32 addr, const u32 value) { - const u64 offset = addr - GetStartAddr() - RAW_SPU_PROB_OFFSET; + const u32 offset = addr - GetStartAddr() - RAW_SPU_PROB_OFFSET; switch (offset) { @@ -198,7 +198,7 @@ bool RawSPUThread::Write32(const u64 addr, const u32 value) void RawSPUThread::InitRegs() { - ls_offset = m_offset = (u32)GetStartAddr() + RAW_SPU_LS_OFFSET; + ls_offset = m_offset = GetStartAddr() + RAW_SPU_LS_OFFSET; SPUThread::InitRegs(); } @@ -213,5 +213,5 @@ void RawSPUThread::Task() SPUThread::Task(); - SPU.NPC.SetValue((u32)PC); + SPU.NPC.SetValue(PC); } diff --git a/rpcs3/Emu/Cell/RawSPUThread.h b/rpcs3/Emu/Cell/RawSPUThread.h index c52dc696a1..7c166c6468 100644 --- a/rpcs3/Emu/Cell/RawSPUThread.h +++ b/rpcs3/Emu/Cell/RawSPUThread.h @@ -16,9 +16,8 @@ public: RawSPUThread(CPUThreadType type = CPU_THREAD_RAW_SPU); virtual ~RawSPUThread(); - bool Read32(const u64 addr, u32* value); - - bool Write32(const u64 addr, const u32 value); + bool Read32(const u32 addr, u32* value); + bool Write32(const u32 addr, const u32 value); public: virtual void InitRegs(); diff --git a/rpcs3/Emu/Memory/Memory.cpp b/rpcs3/Emu/Memory/Memory.cpp index 7f87615796..00eee9da85 100644 --- a/rpcs3/Emu/Memory/Memory.cpp +++ b/rpcs3/Emu/Memory/Memory.cpp @@ -17,42 +17,36 @@ MemoryBase Memory; -void MemoryBase::RegisterPages(u64 addr, u32 size) +void MemoryBase::RegisterPages(u32 addr, u32 size) { + assert(size && (size | addr) % 4096 == 0); + LV2_LOCK(0); - //LOG_NOTICE(MEMORY, "RegisterPages(addr=0x%llx, size=0x%x)", addr, size); - for (u64 i = addr / 4096; i < (addr + size) / 4096; i++) + //LOG_NOTICE(MEMORY, "RegisterPages(addr=0x%x, size=0x%x)", addr, size); + for (u32 i = addr / 4096; i < addr / 4096 + size / 4096; i++) { - if (i >= sizeof(m_pages) / sizeof(m_pages[0])) - { - LOG_ERROR(MEMORY, "%s(): invalid address 0x%llx", __FUNCTION__, i * 4096); - break; - } if (m_pages[i]) { - LOG_ERROR(MEMORY, "Page already registered (addr=0x%llx)", i * 4096); + LOG_ERROR(MEMORY, "Page already registered (addr=0x%x)", i * 4096); Emu.Pause(); } m_pages[i] = 1; // TODO: define page parameters } } -void MemoryBase::UnregisterPages(u64 addr, u32 size) +void MemoryBase::UnregisterPages(u32 addr, u32 size) { + assert(size && (size | addr) % 4096 == 0); + LV2_LOCK(0); - //LOG_NOTICE(MEMORY, "UnregisterPages(addr=0x%llx, size=0x%x)", addr, size); - for (u64 i = addr / 4096; i < (addr + size) / 4096; i++) + //LOG_NOTICE(MEMORY, "UnregisterPages(addr=0x%x, size=0x%x)", addr, size); + for (u32 i = addr / 4096; i < addr / 4096 + size / 4096; i++) { - if (i >= sizeof(m_pages) / sizeof(m_pages[0])) - { - LOG_ERROR(MEMORY, "%s(): invalid address 0x%llx", __FUNCTION__, i * 4096); - break; - } if (!m_pages[i]) { - LOG_ERROR(MEMORY, "Page not registered (addr=0x%llx)", i * 4096); + LOG_ERROR(MEMORY, "Page not registered (addr=0x%x)", i * 4096); Emu.Pause(); } m_pages[i] = 0; // TODO: define page parameters @@ -187,29 +181,27 @@ u32 MemoryBase::ReadMMIO32(u32 addr) throw fmt::Format("%s(addr=0x%x) failed", __FUNCTION__, addr); } -bool MemoryBase::Map(const u64 addr, const u32 size) +bool MemoryBase::Map(const u32 addr, const u32 size) { + assert(size && (size | addr) % 4096 == 0); + LV2_LOCK(0); - if ((addr | (addr + size)) & ~0xFFFFFFFFull) + for (u32 i = addr / 4096; i < addr / 4096 + size / 4096; i++) { - return false; - } - else - { - for (u32 i = (u32)addr / 4096; i <= ((u32)addr + size - 1) / 4096; i++) + if (m_pages[i]) { - if (m_pages[i]) return false; + return false; } } MemoryBlocks.push_back((new MemoryBlock())->SetRange(addr, size)); - LOG_WARNING(MEMORY, "Memory mapped at 0x%llx: size=0x%x", addr, size); + LOG_WARNING(MEMORY, "Memory mapped at 0x%x: size=0x%x", addr, size); return true; } -bool MemoryBase::Unmap(const u64 addr) +bool MemoryBase::Unmap(const u32 addr) { LV2_LOCK(0); @@ -225,11 +217,13 @@ bool MemoryBase::Unmap(const u64 addr) return false; } -MemBlockInfo::MemBlockInfo(u64 _addr, u32 _size) - : MemInfo(_addr, PAGE_4K(_size)) +MemBlockInfo::MemBlockInfo(u32 addr, u32 size) + : MemInfo(addr, size) { - void* real_addr = vm::get_ptr(vm::cast(_addr)); - void* priv_addr = vm::get_priv_ptr(vm::cast(_addr)); + assert(size && (size | addr) % 4096 == 0); + + void* real_addr = vm::get_ptr(addr); + void* priv_addr = vm::get_priv_ptr(addr); #ifdef _WIN32 if (!VirtualAlloc(priv_addr, size, MEM_COMMIT, PAGE_READWRITE) || !VirtualAlloc(real_addr, size, MEM_COMMIT, PAGE_READWRITE)) @@ -237,12 +231,12 @@ MemBlockInfo::MemBlockInfo(u64 _addr, u32 _size) if (mprotect(real_addr, size, PROT_READ | PROT_WRITE) || mprotect(priv_addr, size, PROT_READ | PROT_WRITE)) #endif { - LOG_ERROR(MEMORY, "Memory allocation failed (addr=0x%llx, size=0x%x)", addr, size); + LOG_ERROR(MEMORY, "Memory allocation failed (addr=0x%x, size=0x%x)", addr, size); Emu.Pause(); } else { - Memory.RegisterPages(_addr, PAGE_4K(_size)); + Memory.RegisterPages(addr, size); mem = real_addr; memset(mem, 0, size); // ??? @@ -257,12 +251,12 @@ void MemBlockInfo::Free() #ifdef _WIN32 DWORD old; - if (!VirtualProtect(mem, size, PAGE_NOACCESS, &old) || !VirtualProtect(vm::get_priv_ptr(vm::cast(addr)), size, PAGE_NOACCESS, &old)) + if (!VirtualProtect(mem, size, PAGE_NOACCESS, &old) || !VirtualProtect(vm::get_priv_ptr(addr), size, PAGE_NOACCESS, &old)) #else - if (mprotect(mem, size, PROT_NONE) || mprotect(vm::get_priv_ptr(vm::cast(addr)), size, PROT_NONE)) + if (mprotect(mem, size, PROT_NONE) || mprotect(vm::get_priv_ptr(addr), size, PROT_NONE)) #endif { - LOG_ERROR(MEMORY, "Memory deallocation failed (addr=0x%llx, size=0x%x)", addr, size); + LOG_ERROR(MEMORY, "Memory deallocation failed (addr=0x%x, size=0x%x)", addr, size); Emu.Pause(); } } @@ -316,15 +310,8 @@ void MemoryBlock::Delete() Init(); } -u64 MemoryBlock::FixAddr(const u64 addr) const +MemoryBlock* MemoryBlock::SetRange(const u32 start, const u32 size) { - return addr - GetStartAddr(); -} - -MemoryBlock* MemoryBlock::SetRange(const u64 start, const u32 size) -{ - if (start + size > 0x100000000) return nullptr; - range_start = start; range_size = size; @@ -332,11 +319,6 @@ MemoryBlock* MemoryBlock::SetRange(const u64 start, const u32 size) return this; } -bool MemoryBlock::IsMyAddress(const u64 addr) -{ - return mem && addr >= GetStartAddr() && addr < GetEndAddr(); -} - DynamicMemoryBlockBase::DynamicMemoryBlockBase() : MemoryBlock() , m_max_size(0) @@ -357,22 +339,12 @@ const u32 DynamicMemoryBlockBase::GetUsedSize() const return size; } -bool DynamicMemoryBlockBase::IsInMyRange(const u64 addr) +bool DynamicMemoryBlockBase::IsInMyRange(const u32 addr, const u32 size) { - return addr >= MemoryBlock::GetStartAddr() && addr < MemoryBlock::GetStartAddr() + GetSize(); + return addr >= MemoryBlock::GetStartAddr() && addr + size - 1 <= MemoryBlock::GetEndAddr(); } -bool DynamicMemoryBlockBase::IsInMyRange(const u64 addr, const u32 size) -{ - return IsInMyRange(addr) && IsInMyRange(addr + size - 1); -} - -bool DynamicMemoryBlockBase::IsMyAddress(const u64 addr) -{ - return IsInMyRange(addr); -} - -MemoryBlock* DynamicMemoryBlockBase::SetRange(const u64 start, const u32 size) +MemoryBlock* DynamicMemoryBlockBase::SetRange(const u32 start, const u32 size) { LV2_LOCK(0); @@ -396,8 +368,10 @@ void DynamicMemoryBlockBase::Delete() MemoryBlock::Delete(); } -bool DynamicMemoryBlockBase::AllocFixed(u64 addr, u32 size) +bool DynamicMemoryBlockBase::AllocFixed(u32 addr, u32 size) { + assert(size); + size = PAGE_4K(size + (addr & 4095)); // align size addr &= ~4095; // align start address @@ -420,13 +394,15 @@ bool DynamicMemoryBlockBase::AllocFixed(u64 addr, u32 size) return true; } -void DynamicMemoryBlockBase::AppendMem(u64 addr, u32 size) /* private */ +void DynamicMemoryBlockBase::AppendMem(u32 addr, u32 size) /* private */ { m_allocated.emplace_back(addr, size); } -u64 DynamicMemoryBlockBase::AllocAlign(u32 size, u32 align) +u32 DynamicMemoryBlockBase::AllocAlign(u32 size, u32 align) { + assert(size && align); + if (!MemoryBlock::GetStartAddr()) { LOG_ERROR(MEMORY, "DynamicMemoryBlockBase::AllocAlign(size=0x%x, align=0x%x): memory block not initialized", size, align); @@ -449,7 +425,7 @@ u64 DynamicMemoryBlockBase::AllocAlign(u32 size, u32 align) LV2_LOCK(0); - for (u64 addr = MemoryBlock::GetStartAddr(); addr <= MemoryBlock::GetEndAddr() - exsize;) + for (u32 addr = MemoryBlock::GetStartAddr(); addr <= MemoryBlock::GetEndAddr() - exsize;) { bool is_good_addr = true; @@ -486,7 +462,7 @@ bool DynamicMemoryBlockBase::Alloc() return AllocAlign(GetSize() - GetUsedSize()) != 0; } -bool DynamicMemoryBlockBase::Free(u64 addr) +bool DynamicMemoryBlockBase::Free(u32 addr) { LV2_LOCK(0); @@ -501,45 +477,19 @@ bool DynamicMemoryBlockBase::Free(u64 addr) } } - LOG_ERROR(MEMORY, "DynamicMemoryBlock::Free(addr=0x%llx): failed", addr); + LOG_ERROR(MEMORY, "DynamicMemoryBlock::Free(addr=0x%x): failed", addr); for (u32 i = 0; i < m_allocated.size(); i++) { - LOG_NOTICE(MEMORY, "*** Memory Block: addr = 0x%llx, size = 0x%x", m_allocated[i].addr, m_allocated[i].size); + LOG_NOTICE(MEMORY, "*** Memory Block: addr = 0x%x, size = 0x%x", m_allocated[i].addr, m_allocated[i].size); } return false; } -u8* DynamicMemoryBlockBase::GetMem(u64 addr) const -{ - return MemoryBlock::GetMem(addr); -} - -bool DynamicMemoryBlockBase::IsLocked(u64 addr) -{ - LOG_ERROR(MEMORY, "DynamicMemoryBlockBase::IsLocked() not implemented"); - Emu.Pause(); - return false; -} - -bool DynamicMemoryBlockBase::Lock(u64 addr, u32 size) -{ - LOG_ERROR(MEMORY, "DynamicMemoryBlockBase::Lock() not implemented"); - Emu.Pause(); - return false; -} - -bool DynamicMemoryBlockBase::Unlock(u64 addr, u32 size) -{ - LOG_ERROR(MEMORY, "DynamicMemoryBlockBase::Unlock() not implemented"); - Emu.Pause(); - return false; -} - VirtualMemoryBlock::VirtualMemoryBlock() : MemoryBlock(), m_reserve_size(0) { } -MemoryBlock* VirtualMemoryBlock::SetRange(const u64 start, const u32 size) +MemoryBlock* VirtualMemoryBlock::SetRange(const u32 start, const u32 size) { range_start = start; range_size = size; @@ -547,32 +497,16 @@ MemoryBlock* VirtualMemoryBlock::SetRange(const u64 start, const u32 size) return this; } -bool VirtualMemoryBlock::IsInMyRange(const u64 addr) +bool VirtualMemoryBlock::IsInMyRange(const u32 addr, const u32 size) { - return addr >= GetStartAddr() && addr < GetStartAddr() + GetSize() - GetReservedAmount(); + return addr >= GetStartAddr() && addr + size - 1 <= GetEndAddr() - GetReservedAmount(); } -bool VirtualMemoryBlock::IsInMyRange(const u64 addr, const u32 size) +u32 VirtualMemoryBlock::Map(u32 realaddr, u32 size) { - return IsInMyRange(addr) && IsInMyRange(addr + size - 1); -} + assert(size); -bool VirtualMemoryBlock::IsMyAddress(const u64 addr) -{ - for (u32 i = 0; i= m_mapped_memory[i].addr && addr < m_mapped_memory[i].addr + m_mapped_memory[i].size) - { - return true; - } - } - - return false; -} - -u64 VirtualMemoryBlock::Map(u64 realaddr, u32 size) -{ - for (u64 addr = GetStartAddr(); addr <= GetEndAddr() - GetReservedAmount() - size;) + for (u32 addr = GetStartAddr(); addr <= GetEndAddr() - GetReservedAmount() - size;) { bool is_good_addr = true; @@ -598,16 +532,28 @@ u64 VirtualMemoryBlock::Map(u64 realaddr, u32 size) return 0; } -bool VirtualMemoryBlock::Map(u64 realaddr, u32 size, u64 addr) +bool VirtualMemoryBlock::Map(u32 realaddr, u32 size, u32 addr) { - if (!IsInMyRange(addr, size) && (IsMyAddress(addr) || IsMyAddress(addr + size - 1))) + assert(size); + + if (!IsInMyRange(addr, size)) + { return false; + } + + for (u32 i = 0; i= m_mapped_memory[i].addr && addr + size - 1 <= m_mapped_memory[i].addr + m_mapped_memory[i].size - 1) + { + return false; + } + } m_mapped_memory.emplace_back(addr, realaddr, size); return true; } -bool VirtualMemoryBlock::UnmapRealAddress(u64 realaddr, u32& size) +bool VirtualMemoryBlock::UnmapRealAddress(u32 realaddr, u32& size) { for (u32 i = 0; iGetSize() - UserMemory->GetUsedSize(); } - u64 Alloc(const u32 size, const u32 align) + u32 Alloc(const u32 size, const u32 align) { return UserMemory->AllocAlign(size, align); } - bool Free(const u64 addr) + bool Free(const u32 addr) { return UserMemory->Free(addr); } - bool Map(const u64 addr, const u32 size); + bool Map(const u32 addr, const u32 size); - bool Unmap(const u64 addr); + bool Unmap(const u32 addr); }; extern MemoryBase Memory; diff --git a/rpcs3/Emu/Memory/MemoryBlock.h b/rpcs3/Emu/Memory/MemoryBlock.h index 1dcf833553..81dfcd3e1d 100644 --- a/rpcs3/Emu/Memory/MemoryBlock.h +++ b/rpcs3/Emu/Memory/MemoryBlock.h @@ -2,20 +2,20 @@ #define PAGE_4K(x) (x + 4095) & ~(4095) -//#include - struct MemInfo { - u64 addr; + u32 addr; u32 size; - MemInfo(u64 _addr, u32 _size) - : addr(_addr) - , size(_size) + MemInfo(u32 addr, u32 size) + : addr(addr) + , size(size) { } - MemInfo() : addr(0), size(0) + MemInfo() + : addr(0) + , size(0) { } }; @@ -24,7 +24,7 @@ struct MemBlockInfo : public MemInfo { void *mem; - MemBlockInfo(u64 _addr, u32 _size); + MemBlockInfo(u32 addr, u32 size); void Free(); @@ -58,11 +58,11 @@ struct MemBlockInfo : public MemInfo struct VirtualMemInfo : public MemInfo { - u64 realAddress; + u32 realAddress; - VirtualMemInfo(u64 _addr, u64 _realaddr, u32 _size) - : MemInfo(_addr, _size) - , realAddress(_realaddr) + VirtualMemInfo(u32 addr, u32 realaddr, u32 size) + : MemInfo(addr, size) + , realAddress(realaddr) { } @@ -77,7 +77,7 @@ class MemoryBlock { protected: u8* mem; - u64 range_start; + u32 range_start; u32 range_size; public: @@ -93,25 +93,17 @@ private: public: virtual void Delete(); - u64 FixAddr(const u64 addr) const; + virtual MemoryBlock* SetRange(const u32 start, const u32 size); - virtual MemoryBlock* SetRange(const u64 start, const u32 size); - virtual bool IsMyAddress(const u64 addr); - virtual bool IsLocked(const u64 addr) { return false; } - - const u64 GetStartAddr() const { return range_start; } - const u64 GetEndAddr() const { return GetStartAddr() + GetSize() - 1; } + const u32 GetStartAddr() const { return range_start; } + const u32 GetEndAddr() const { return GetStartAddr() + GetSize() - 1; } virtual const u32 GetSize() const { return range_size; } virtual const u32 GetUsedSize() const { return GetSize(); } - u8* GetMem() const { return mem; } - virtual u8* GetMem(u64 addr) const { return mem + addr; } - virtual bool AllocFixed(u64 addr, u32 size) { return false; } - virtual u64 AllocAlign(u32 size, u32 align = 1) { return 0; } + virtual bool AllocFixed(u32 addr, u32 size) { return false; } + virtual u32 AllocAlign(u32 size, u32 align = 1) { return 0; } virtual bool Alloc() { return false; } - virtual bool Free(u64 addr) { return false; } - virtual bool Lock(u64 addr, u32 size) { return false; } - virtual bool Unlock(u64 addr, u32 size) { return false; } + virtual bool Free(u32 addr) { return false; } }; class DynamicMemoryBlockBase : public MemoryBlock @@ -125,26 +117,19 @@ public: const u32 GetSize() const { return m_max_size; } const u32 GetUsedSize() const; - virtual bool IsInMyRange(const u64 addr); - virtual bool IsInMyRange(const u64 addr, const u32 size); - virtual bool IsMyAddress(const u64 addr); - virtual bool IsLocked(const u64 addr); + virtual bool IsInMyRange(const u32 addr, const u32 size = 1); - virtual MemoryBlock* SetRange(const u64 start, const u32 size); + virtual MemoryBlock* SetRange(const u32 start, const u32 size); virtual void Delete(); - virtual bool AllocFixed(u64 addr, u32 size); - virtual u64 AllocAlign(u32 size, u32 align = 1); + virtual bool AllocFixed(u32 addr, u32 size); + virtual u32 AllocAlign(u32 size, u32 align = 1); virtual bool Alloc(); - virtual bool Free(u64 addr); - virtual bool Lock(u64 addr, u32 size); - virtual bool Unlock(u64 addr, u32 size); - - virtual u8* GetMem(u64 addr) const; + virtual bool Free(u32 addr); private: - void AppendMem(u64 addr, u32 size); + void AppendMem(u32 addr, u32 size); }; class VirtualMemoryBlock : public MemoryBlock @@ -155,22 +140,20 @@ class VirtualMemoryBlock : public MemoryBlock public: VirtualMemoryBlock(); - virtual MemoryBlock* SetRange(const u64 start, const u32 size); - virtual bool IsInMyRange(const u64 addr); - virtual bool IsInMyRange(const u64 addr, const u32 size); - virtual bool IsMyAddress(const u64 addr); + virtual MemoryBlock* SetRange(const u32 start, const u32 size); + virtual bool IsInMyRange(const u32 addr, const u32 size = 1); virtual void Delete(); // maps real address to virtual address space, returns the mapped address or 0 on failure (if no address is specified the // first mappable space is used) - virtual bool Map(u64 realaddr, u32 size, u64 addr); - virtual u64 Map(u64 realaddr, u32 size); + virtual bool Map(u32 realaddr, u32 size, u32 addr); + virtual u32 Map(u32 realaddr, u32 size); // Unmap real address (please specify only starting point, no midway memory will be unmapped), returns the size of the unmapped area - virtual bool UnmapRealAddress(u64 realaddr, u32& size); + virtual bool UnmapRealAddress(u32 realaddr, u32& size); // Unmap address (please specify only starting point, no midway memory will be unmapped), returns the size of the unmapped area - virtual bool UnmapAddress(u64 addr, u32& size); + virtual bool UnmapAddress(u32 addr, u32& size); // Reserve a certain amount so no one can use it, returns true on succces, false on failure virtual bool Reserve(u32 size); @@ -181,24 +164,23 @@ public: // Return the total amount of reserved memory virtual u32 GetReservedAmount(); - bool Read32(const u64 addr, u32* value); + bool Read32(const u32 addr, u32* value); - bool Write32(const u64 addr, const u32 value); + bool Write32(const u32 addr, const u32 value); // try to get the real address given a mapped address // return true for success - bool getRealAddr(u64 addr, u64& result); + bool getRealAddr(u32 addr, u32& result); - u64 RealAddr(u64 addr) + u32 RealAddr(u32 addr) { - u64 realAddr = 0; + u32 realAddr = 0; getRealAddr(addr, realAddr); return realAddr; } // return the mapped address given a real address, if not mapped return 0 - u64 getMappedAddress(u64 realAddress); + u32 getMappedAddress(u32 realAddress); }; typedef DynamicMemoryBlockBase DynamicMemoryBlock; - diff --git a/rpcs3/Emu/SysCalls/Modules/cellGame.cpp b/rpcs3/Emu/SysCalls/Modules/cellGame.cpp index e54aedb7e2..4e45ddb87c 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGame.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellGame.cpp @@ -14,6 +14,7 @@ Module *cellGame = nullptr; std::string contentInfo = ""; std::string usrdir = ""; +bool path_set = false; int cellGameBootCheck(vm::ptr type, vm::ptr attributes, vm::ptr size, vm::ptr dirName) { @@ -52,6 +53,7 @@ int cellGameBootCheck(vm::ptr type, vm::ptr attributes, vm::ptr type, vm::ptr attributes, vm::ptr type, vm::ptr attributes, vm::ptr size, u32 reserved_addr) std::string titleId = psf.GetString("TITLE_ID"); contentInfo = "/dev_hdd0/game/" + titleId; usrdir = "/dev_hdd0/game/" + titleId + "/USRDIR"; + path_set = true; return CELL_GAME_RET_OK; } @@ -155,10 +160,15 @@ int cellGameDataCheck(u32 type, vm::ptr dirName, vm::ptrWarning("cellGameDataCheck(): /dev_bdvd/PS3_GAME not found"); + contentInfo = ""; + usrdir = ""; + path_set = true; return CELL_GAME_RET_NONE; } + contentInfo = "/dev_bdvd/PS3_GAME"; usrdir = "/dev_bdvd/PS3_GAME/USRDIR"; + path_set = true; } else { @@ -167,10 +177,15 @@ int cellGameDataCheck(u32 type, vm::ptr dirName, vm::ptrWarning("cellGameDataCheck(): '%s' directory not found", dir.c_str()); + contentInfo = ""; + usrdir = ""; + path_set = true; return CELL_GAME_RET_NONE; } + contentInfo = dir; usrdir = dir + "/USRDIR"; + path_set = true; } return CELL_GAME_RET_OK; @@ -186,9 +201,8 @@ int cellGameContentPermit(vm::ptr contentInfoPath, vm: return CELL_GAME_ERROR_PARAM; } - if (contentInfo == "" && usrdir == "") + if (!path_set) { - cellGame->Warning("cellGameContentPermit(): CELL_GAME_ERROR_FAILURE (no permission given)"); return CELL_GAME_ERROR_FAILURE; } @@ -197,6 +211,7 @@ int cellGameContentPermit(vm::ptr contentInfoPath, vm: contentInfo = ""; usrdir = ""; + path_set = false; return CELL_GAME_RET_OK; } @@ -476,6 +491,10 @@ void cellGame_init(Module *pxThis) { cellGame = pxThis; + contentInfo = ""; + usrdir = ""; + path_set = false; + // (TODO: Disc Exchange functions missing) cellGame->AddFunc(0xf52639ea, cellGameBootCheck); diff --git a/rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp b/rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp index 23659a60e5..547c1b61ad 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp @@ -842,16 +842,16 @@ void cellGcmGetOffsetTable(vm::ptr table) table->eaAddress = offsetTable.eaAddress; } -s32 cellGcmIoOffsetToAddress(u32 ioOffset, u64 address) +s32 cellGcmIoOffsetToAddress(u32 ioOffset, vm::ptr address) { cellGcmSys->Log("cellGcmIoOffsetToAddress(ioOffset=0x%x, address=0x%llx)", ioOffset, address); - u64 realAddr; + u32 realAddr; if (!Memory.RSXIOMem.getRealAddr(ioOffset, realAddr)) return CELL_GCM_ERROR_FAILURE; - vm::write64(address, realAddr); + *address = realAddr; return CELL_OK; } diff --git a/rpcs3/Emu/SysCalls/Modules/cellGcmSys.h b/rpcs3/Emu/SysCalls/Modules/cellGcmSys.h index 1ee95bdfaf..b7fad1b62f 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGcmSys.h +++ b/rpcs3/Emu/SysCalls/Modules/cellGcmSys.h @@ -27,7 +27,6 @@ s32 cellGcmSetPrepareFlip(vm::ptr ctxt, u32 id); s32 cellGcmAddressToOffset(u64 address, vm::ptr> offset); u32 cellGcmGetMaxIoMapSize(); void cellGcmGetOffsetTable(vm::ptr table); -s32 cellGcmIoOffsetToAddress(u32 ioOffset, u64 address); s32 cellGcmMapEaIoAddress(u32 ea, u32 io, u32 size); s32 cellGcmMapEaIoAddressWithFlags(u32 ea, u32 io, u32 size, u32 flags); s32 cellGcmMapMainMemory(u32 ea, u32 size, vm::ptr offset); diff --git a/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp b/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp index 3fc79e4256..961e04dde3 100644 --- a/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp @@ -24,8 +24,10 @@ Module *sysPrxForUser = nullptr; #define TLS_MAX 128 +#define TLS_SYS 0x30 u32 g_tls_start; // start of TLS memory area +u32 g_tls_size; std::array, TLS_MAX> g_tls_owners; @@ -38,8 +40,9 @@ u32 ppu_get_tls(u32 thread) { if (!g_tls_start) { - g_tls_start = vm::cast(Memory.MainMem.AllocAlign(Emu.GetTLSMemsz() * TLS_MAX, 4096)); // memory for up to TLS_MAX threads - sysPrxForUser->Notice("Thread Local Storage initialized (g_tls_start=0x%x, size = 0x%x)\n*** TLS segment addr: 0x%08x\n*** TLS segment size: 0x%08x", + g_tls_size = Emu.GetTLSMemsz() + TLS_SYS; + g_tls_start = vm::cast(Memory.MainMem.AllocAlign(g_tls_size * TLS_MAX, 4096)); // memory for up to TLS_MAX threads + sysPrxForUser->Notice("Thread Local Storage initialized (g_tls_start=0x%x, user_size=0x%x)\n*** TLS segment addr: 0x%08x\n*** TLS segment size: 0x%08x", g_tls_start, Emu.GetTLSMemsz(), Emu.GetTLSAddr(), Emu.GetTLSFilesz()); } @@ -52,7 +55,7 @@ u32 ppu_get_tls(u32 thread) { if (g_tls_owners[i] == thread) { - return g_tls_start + i * Emu.GetTLSMemsz(); // if already initialized, return TLS address + return g_tls_start + i * g_tls_size + TLS_SYS; // if already initialized, return TLS address } } @@ -61,7 +64,8 @@ u32 ppu_get_tls(u32 thread) u32 old = 0; if (g_tls_owners[i].compare_exchange_strong(old, thread)) { - const u32 addr = g_tls_start + i * Emu.GetTLSMemsz(); // get TLS address + const u32 addr = g_tls_start + i * g_tls_size + TLS_SYS; // get TLS address + memset(vm::get_ptr(addr - TLS_SYS), 0, TLS_SYS); // initialize system area with zeros memcpy(vm::get_ptr(addr), vm::get_ptr(Emu.GetTLSAddr()), Emu.GetTLSFilesz()); // initialize from TLS image memset(vm::get_ptr(addr + Emu.GetTLSFilesz()), 0, Emu.GetTLSMemsz() - Emu.GetTLSFilesz()); // fill the rest with zeros return addr; diff --git a/rpcs3/Gui/RSXDebugger.cpp b/rpcs3/Gui/RSXDebugger.cpp index 69a09bc2cb..4c408b509e 100644 --- a/rpcs3/Gui/RSXDebugger.cpp +++ b/rpcs3/Gui/RSXDebugger.cpp @@ -331,9 +331,9 @@ void RSXDebugger::GoToGet(wxCommandEvent& event) { if (!RSXReady()) return; auto ctrl = vm::get_ptr(Emu.GetGSManager().GetRender().m_ctrlAddress); - u64 realAddr; + u32 realAddr; if (Memory.RSXIOMem.getRealAddr(ctrl->get.read_relaxed(), realAddr)) { - m_addr = realAddr; // WARNING: Potential Truncation? Cast from u64 to u32 + m_addr = realAddr; t_addr->SetValue(wxString::Format("%08x", m_addr)); UpdateInformation(); event.Skip(); @@ -345,9 +345,9 @@ void RSXDebugger::GoToPut(wxCommandEvent& event) { if (!RSXReady()) return; auto ctrl = vm::get_ptr(Emu.GetGSManager().GetRender().m_ctrlAddress); - u64 realAddr; + u32 realAddr; if (Memory.RSXIOMem.getRealAddr(ctrl->put.read_relaxed(), realAddr)) { - m_addr = realAddr; // WARNING: Potential Truncation? Cast from u64 to u32 + m_addr = realAddr; t_addr->SetValue(wxString::Format("%08x", m_addr)); UpdateInformation(); event.Skip();