From eebe859f83f789801f5f974755967c9679cb56b9 Mon Sep 17 00:00:00 2001 From: DH Date: Wed, 25 Sep 2013 00:11:29 +0300 Subject: [PATCH] Improved mem_t. - Implemented mem_ptr_t. - Fixed issue 3. --- rpcs3/Emu/Cell/PPCThread.h | 2 +- rpcs3/Emu/Cell/PPUThread.cpp | 2 +- rpcs3/Emu/FS/vfsFileBase.h | 4 +- rpcs3/Emu/FS/vfsLocalFile.cpp | 4 +- rpcs3/Emu/FS/vfsLocalFile.h | 18 +-- rpcs3/Emu/FS/vfsStream.cpp | 4 +- rpcs3/Emu/FS/vfsStream.h | 4 +- rpcs3/Emu/FS/vfsStreamMemory.cpp | 4 +- rpcs3/Emu/FS/vfsStreamMemory.h | 4 +- rpcs3/Emu/GS/GL/FragmentProgram.cpp | 4 +- rpcs3/Emu/GS/GL/GLGSRender.cpp | 4 +- rpcs3/Emu/GS/GL/GLGSRender.h | 2 +- rpcs3/Emu/GS/Null/NullGSRender.h | 4 +- rpcs3/Emu/Memory/Memory.h | 138 +++++++++++++++++------ rpcs3/Emu/SysCalls/SysCalls.h | 18 +-- rpcs3/Emu/SysCalls/lv2/SC_FileSystem.cpp | 122 ++++++++++---------- rpcs3/Emu/System.cpp | 73 ++++++------ rpcs3/Emu/System.h | 13 ++- rpcs3/Loader/ELF64.cpp | 4 +- rpcs3/stdafx.h | 1 + 20 files changed, 259 insertions(+), 170 deletions(-) diff --git a/rpcs3/Emu/Cell/PPCThread.h b/rpcs3/Emu/Cell/PPCThread.h index 63ba891b28..f6194ad2bf 100644 --- a/rpcs3/Emu/Cell/PPCThread.h +++ b/rpcs3/Emu/Cell/PPCThread.h @@ -138,7 +138,7 @@ public: wxArrayString ErrorToString() { return ErrorToString(m_error); } bool IsOk() const { return m_error == 0; } - bool IsRunning() const { return m_status == Running; } + bool IsRunning() const { return m_status == Running; } bool IsPaused() const { return m_status == Paused; } bool IsStopped() const { return m_status == Stopped; } diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index 548d8ca9ba..2f329f4b16 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -105,7 +105,7 @@ void PPUThread::InitRegs() stack_point -= 0xc + 4 * argc; u64 argv = stack_point; - mem64_t argv_list(argv); + mem64_ptr_t argv_list(argv); for(int i=0; iget, get + (count + 1) * 4); } diff --git a/rpcs3/Emu/Memory/Memory.h b/rpcs3/Emu/Memory/Memory.h index 312ae36c91..f80f2bbcbc 100644 --- a/rpcs3/Emu/Memory/Memory.h +++ b/rpcs3/Emu/Memory/Memory.h @@ -369,15 +369,91 @@ public: extern MemoryBase Memory; -template class mem_t +class MemoryAllocator { - u64 addr; - const u64 iaddr; + u32 m_addr; public: - mem_t(u64 _addr) - : addr(_addr) - , iaddr(_addr) + MemoryAllocator(u32 size, u32 align = 1) + { + m_addr = Memory.Alloc(size, align); + } + + ~MemoryAllocator() + { + Memory.Free(m_addr); + } + + operator u32() const + { + return m_addr; + } +}; + +template class mem_t +{ + const u32 m_addr; + +public: + mem_t(u64 addr) : m_addr(addr) + { + } + + mem_t& operator = (T right) + { + switch(sizeof(T)) + { + case 1: Memory.Write8(m_addr, right); return *this; + case 2: Memory.Write16(m_addr, right); return *this; + case 4: Memory.Write32(m_addr, right); return *this; + case 8: Memory.Write64(m_addr, right); return *this; + } + + assert(0); + return *this; + } + + operator const T() const + { + switch(sizeof(T)) + { + case 1: return Memory.Read8(m_addr); + case 2: return Memory.Read16(m_addr); + case 4: return Memory.Read32(m_addr); + case 8: return Memory.Read64(m_addr); + } + + assert(0); + } + + mem_t& operator += (T right) { return *this = (*this) + right; } + mem_t& operator -= (T right) { return *this = (*this) - right; } + mem_t& operator *= (T right) { return *this = (*this) * right; } + mem_t& operator /= (T right) { return *this = (*this) / right; } + mem_t& operator %= (T right) { return *this = (*this) % right; } + mem_t& operator &= (T right) { return *this = (*this) & right; } + mem_t& operator |= (T right) { return *this = (*this) | right; } + mem_t& operator ^= (T right) { return *this = (*this) ^ right; } + mem_t& operator <<= (T right) { return *this = (*this) << right; } + mem_t& operator >>= (T right) { return *this = (*this) >> right; } + + u64 GetAddr() const { return m_addr; } + + bool IsGood() const + { + return Memory.IsGoodAddr(m_addr, sizeof(T)); + } +}; + +template class mem_ptr_t +{ + u64 m_addr; + const u64 m_iaddr; + +public: + mem_ptr_t(u64 addr) + : m_addr(addr) + , m_iaddr(addr) { } @@ -385,47 +461,40 @@ public: { switch(sizeof(T)) { - case 1: Memory.Write8(addr, right); return; - case 2: Memory.Write16(addr, right); return; - case 4: Memory.Write32(addr, right); return; - case 8: Memory.Write64(addr, right); return; + case 1: Memory.Write8(m_addr, right); return; + case 2: Memory.Write16(m_addr, right); return; + case 4: Memory.Write32(m_addr, right); return; + case 8: Memory.Write64(m_addr, right); return; } - ConLog.Error("Bad mem_t size! (%d : 0x%llx)", sizeof(T), addr); + ConLog.Error("Bad mem_t size! (%d : 0x%llx)", sizeof(T), m_addr); } - operator u8() const { return Memory.Read8(addr); } - operator u16() const { return Memory.Read16(addr); } - operator u32() const { return Memory.Read32(addr); } - operator u64() const { return Memory.Read64(addr); } + operator u8() const { return Memory.Read8(m_addr); } + operator u16() const { return Memory.Read16(m_addr); } + operator u32() const { return Memory.Read32(m_addr); } + operator u64() const { return Memory.Read64(m_addr); } - /* - u64 operator += (u64 right) - { - addr += right; - return addr; - } - */ u64 operator += (T right) { *this = right; - addr += sizeof(T); - return addr; + m_addr += sizeof(T); + return m_addr; } - T operator [] (u64 i) + const T operator [] (u64 i) const { const u64 offset = i*sizeof(T); - addr += offset; + (*(mem_ptr_t*)this).m_addr += offset; const T ret = *this; - addr -= offset; + (*(mem_ptr_t*)this).m_addr -= offset; return ret; } - void Reset() { addr = iaddr; } - u64 GetCurAddr() const { return addr; } - u64 GetAddr() const { return iaddr; } - u64 SetOffset(const u32 offset) { return addr += offset; } + void Reset() { m_addr = m_iaddr; } + u64 GetCurAddr() const { return m_addr; } + u64 GetAddr() const { return m_iaddr; } + u64 SetOffset(const u32 offset) { return m_addr += offset; } }; class mem_class_t @@ -465,4 +534,9 @@ public: typedef mem_t mem8_t; typedef mem_t mem16_t; typedef mem_t mem32_t; -typedef mem_t mem64_t; \ No newline at end of file +typedef mem_t mem64_t; + +typedef mem_ptr_t mem8_ptr_t; +typedef mem_ptr_t mem16_ptr_t; +typedef mem_ptr_t mem32_ptr_t; +typedef mem_ptr_t mem64_ptr_t; \ No newline at end of file diff --git a/rpcs3/Emu/SysCalls/SysCalls.h b/rpcs3/Emu/SysCalls/SysCalls.h index c54bfc70cc..f7ac186209 100644 --- a/rpcs3/Emu/SysCalls/SysCalls.h +++ b/rpcs3/Emu/SysCalls/SysCalls.h @@ -175,23 +175,23 @@ extern int sys_mmapper_allocate_memory(u32 size, u64 flags, u32 mem_id_addr); extern int sys_mmapper_map_memory(u32 start_addr, u32 mem_id, u64 flags); //cellFs -extern int cellFsOpen(u32 path_addr, int flags, u32 fd_addr, u32 arg_addr, u64 size); -extern int cellFsRead(u32 fd, u32 buf_addr, u64 nbytes, u32 nread_addr); -extern int cellFsWrite(u32 fd, u32 buf_addr, u64 nbytes, u32 nwrite_addr); +extern int cellFsOpen(u32 path_addr, int flags, mem32_t fd, mem32_t arg, u64 size); +extern int cellFsRead(u32 fd, u32 buf_addr, u64 nbytes, mem64_t nread_addr); +extern int cellFsWrite(u32 fd, u32 buf_addr, u64 nbytes, mem64_t nwrite_addr); extern int cellFsClose(u32 fd); -extern int cellFsOpendir(u32 path_addr, u32 fd_addr); -extern int cellFsReaddir(u32 fd, u32 dir_addr, u32 nread_addr); +extern int cellFsOpendir(u32 path_addr, mem32_t fd); +extern int cellFsReaddir(u32 fd, u32 dir_addr, mem64_t nread); extern int cellFsClosedir(u32 fd); -extern int cellFsStat(u32 path_addr, u32 sb_addr); -extern int cellFsFstat(u32 fd, u32 sb_addr); +extern int cellFsStat(u32 path_addr, mem_class_t sb); +extern int cellFsFstat(u32 fd, mem_class_t sb); extern int cellFsMkdir(u32 path_addr, u32 mode); extern int cellFsRename(u32 from_addr, u32 to_addr); extern int cellFsRmdir(u32 path_addr); extern int cellFsUnlink(u32 path_addr); -extern int cellFsLseek(u32 fd, s64 offset, u32 whence, u32 pos_addr); +extern int cellFsLseek(u32 fd, s64 offset, u32 whence, mem64_t pos); extern int cellFsFtruncate(u32 fd, u64 size); extern int cellFsTruncate(u32 path_addr, u64 size); -extern int cellFsFGetBlockSize(u32 fd, u32 sector_size_addr, u32 block_size_addr); +extern int cellFsFGetBlockSize(u32 fd, mem64_t sector_size, mem64_t block_size); //cellVideo extern int cellVideoOutGetState(u32 videoOut, u32 deviceIndex, u32 state_addr); diff --git a/rpcs3/Emu/SysCalls/lv2/SC_FileSystem.cpp b/rpcs3/Emu/SysCalls/lv2/SC_FileSystem.cpp index 6c409df644..d4e78008da 100644 --- a/rpcs3/Emu/SysCalls/lv2/SC_FileSystem.cpp +++ b/rpcs3/Emu/SysCalls/lv2/SC_FileSystem.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" #include "Emu/SysCalls/SysCalls.h" -enum Lv2FsOflag +enum CellFsOflag { LV2_O_RDONLY = 000000, LV2_O_WRONLY = 000001, @@ -16,14 +16,14 @@ enum Lv2FsOflag #define CELL_FS_TYPE_UNKNOWN 0 -enum Lv2FsSeek +enum CellFsSeek { LV2_SEEK_SET, LV2_SEEK_CUR, LV2_SEEK_END, }; -enum Lv2FsLength +enum CellFsLength { LV2_MAX_FS_PATH_LENGTH = 1024, LV2_MAX_FS_FILE_NAME_LENGTH = 255, @@ -50,25 +50,25 @@ enum CELL_FS_S_IXOTH = 0000001, //X for other }; -struct Lv2FsStat +struct CellFsStat { u32 st_mode; s32 st_uid; s32 st_gid; - time_t st_atime; - time_t st_mtime; - time_t st_ctime; + u64 st_atime; + u64 st_mtime; + u64 st_ctime; u64 st_size; u64 st_blksize; }; -struct Lv2FsUtimbuf +struct CellFsUtimbuf { - time_t actime; - time_t modtime; + u64 actime; + u64 modtime; }; -struct Lv2FsDirent +struct CellFsDirent { u8 d_type; u8 d_namlen; @@ -84,11 +84,11 @@ enum FsDirentType extern Module sys_fs; -int cellFsOpen(u32 path_addr, int flags, u32 fd_addr, u32 arg_addr, u64 size) +int cellFsOpen(u32 path_addr, int flags, mem32_t fd, mem32_t arg, u64 size) { const wxString& path = Memory.ReadString(path_addr); sys_fs.Log("cellFsOpen(path: %s, flags: 0x%x, fd_addr: 0x%x, arg_addr: 0x%x, size: 0x%llx)", - path, flags, fd_addr, arg_addr, size); + path, flags, fd.GetAddr(), arg.GetAddr(), size); const wxString& ppath = path; //ConLog.Warning("path: %s [%s]", ppath, path); @@ -174,28 +174,28 @@ int cellFsOpen(u32 path_addr, int flags, u32 fd_addr, u32 arg_addr, u64 size) return CELL_ENOENT; } - Memory.Write32(fd_addr, sys_fs.GetNewId(stream, flags)); + fd = sys_fs.GetNewId(stream, flags); return CELL_OK; } -int cellFsRead(u32 fd, u32 buf_addr, u64 nbytes, u32 nread_addr) +int cellFsRead(u32 fd, u32 buf_addr, u64 nbytes, mem64_t nread) { sys_fs.Log("cellFsRead(fd: %d, buf_addr: 0x%x, nbytes: 0x%llx, nread_addr: 0x%x)", - fd, buf_addr, nbytes, nread_addr); + fd, buf_addr, nbytes, nread.GetAddr()); ID id; if(!sys_fs.CheckId(fd, id)) return CELL_ESRCH; vfsStream& file = *(vfsStream*)id.m_data; - Memory.Write64NN(nread_addr, file.Read(Memory.GetMemFromAddr(buf_addr), nbytes)); + nread = file.Read(Memory.GetMemFromAddr(buf_addr), nbytes); return CELL_OK; } -int cellFsWrite(u32 fd, u32 buf_addr, u64 nbytes, u32 nwrite_addr) +int cellFsWrite(u32 fd, u32 buf_addr, u64 nbytes, mem64_t nwrite) { sys_fs.Log("cellFsWrite(fd: %d, buf_addr: 0x%x, nbytes: 0x%llx, nwrite_addr: 0x%x)", - fd, buf_addr, nbytes, nwrite_addr); + fd, buf_addr, nbytes, nwrite.GetAddr()); ID id; if(!sys_fs.CheckId(fd, id)) return CELL_ESRCH; vfsStream& file = *(vfsStream*)id.m_data; @@ -205,8 +205,8 @@ int cellFsWrite(u32 fd, u32 buf_addr, u64 nbytes, u32 nwrite_addr) nbytes = block.GetSize() - (buf_addr - block.GetStartAddr()); } - int count = nbytes ? file.Write(Memory.GetMemFromAddr(buf_addr), nbytes) : 0; - Memory.Write64NN(nwrite_addr, count); + nwrite = nbytes ? file.Write(Memory.GetMemFromAddr(buf_addr), nbytes) : 0; + return CELL_OK; } @@ -221,18 +221,18 @@ int cellFsClose(u32 fd) return CELL_OK; } -int cellFsOpendir(u32 path_addr, u32 fd_addr) +int cellFsOpendir(u32 path_addr, mem32_t fd) { const wxString& path = Memory.ReadString(path_addr); - sys_fs.Error("cellFsOpendir(path_addr: 0x%x(%s), fd_addr: 0x%x)", path_addr, path, fd_addr); - if(!Memory.IsGoodAddr(path_addr, sizeof(u32)) || !Memory.IsGoodAddr(fd_addr, sizeof(u32))) return CELL_EFAULT; + sys_fs.Error("cellFsOpendir(path_addr: 0x%x(%s), fd_addr: 0x%x)", path_addr, path, fd.GetAddr()); + if(!Memory.IsGoodAddr(path_addr) || !fd.IsGood()) return CELL_EFAULT; return CELL_OK; } -int cellFsReaddir(u32 fd, u32 dir_addr, u32 nread_addr) +int cellFsReaddir(u32 fd, u32 dir_addr, mem64_t nread) { - sys_fs.Error("cellFsReaddir(fd: %d, dir_addr: 0x%x, nread_addr: 0x%x)", fd, dir_addr, nread_addr); + sys_fs.Error("cellFsReaddir(fd: %d, dir_addr: 0x%x, nread_addr: 0x%x)", fd, dir_addr, nread.GetAddr()); return CELL_OK; } @@ -242,10 +242,10 @@ int cellFsClosedir(u32 fd) return CELL_OK; } -int cellFsStat(const u32 path_addr, const u32 sb_addr) +int cellFsStat(const u32 path_addr, mem_class_t sb) { const wxString& path = Memory.ReadString(path_addr); - sys_fs.Log("cellFsFstat(path: %s, sb_addr: 0x%x)", path, sb_addr); + sys_fs.Log("cellFsFstat(path: %s, sb_addr: 0x%x)", path, sb.GetAddr()); // Check if path is a mount point. (TODO: Add information in sb_addr) for(u32 i=0; iIsOpened()) + auto f = Emu.OpenFile(path); + + if(!f->IsOpened()) { sys_fs.Warning("cellFsFstat: '%s' not found.", path); - Emu.GetVFS().Close(f); return CELL_ENOENT; } - Lv2FsStat stat; + CellFsStat stat; stat.st_mode = CELL_FS_S_IRUSR | CELL_FS_S_IWUSR | CELL_FS_S_IXUSR | CELL_FS_S_IRGRP | CELL_FS_S_IWGRP | CELL_FS_S_IXGRP | @@ -280,29 +280,26 @@ int cellFsStat(const u32 path_addr, const u32 sb_addr) stat.st_size = f->GetSize(); stat.st_blksize = 4096; - mem_class_t stat_c(sb_addr); - stat_c += stat.st_mode; - stat_c += stat.st_uid; - stat_c += stat.st_gid; - stat_c += stat.st_atime; - stat_c += stat.st_mtime; - stat_c += stat.st_ctime; - stat_c += stat.st_size; - stat_c += stat.st_blksize; - - Emu.GetVFS().Close(f); + sb += stat.st_mode; + sb += stat.st_uid; + sb += stat.st_gid; + sb += stat.st_atime; + sb += stat.st_mtime; + sb += stat.st_ctime; + sb += stat.st_size; + sb += stat.st_blksize; return CELL_OK; } -int cellFsFstat(u32 fd, u32 sb_addr) +int cellFsFstat(u32 fd, mem_class_t sb) { - sys_fs.Log("cellFsFstat(fd: %d, sb_addr: 0x%x)", fd, sb_addr); + sys_fs.Log("cellFsFstat(fd: %d, sb_addr: 0x%x)", fd, sb.GetAddr()); ID id; if(!sys_fs.CheckId(fd, id)) return CELL_ESRCH; vfsStream& file = *(vfsStream*)id.m_data; - Lv2FsStat stat; + CellFsStat stat; stat.st_mode = CELL_FS_S_IRUSR | CELL_FS_S_IWUSR | CELL_FS_S_IXUSR | CELL_FS_S_IRGRP | CELL_FS_S_IWGRP | CELL_FS_S_IXGRP | @@ -317,15 +314,14 @@ int cellFsFstat(u32 fd, u32 sb_addr) stat.st_size = file.GetSize(); stat.st_blksize = 4096; - mem_class_t stat_c(sb_addr); - stat_c += stat.st_mode; - stat_c += stat.st_uid; - stat_c += stat.st_gid; - stat_c += stat.st_atime; - stat_c += stat.st_mtime; - stat_c += stat.st_ctime; - stat_c += stat.st_size; - stat_c += stat.st_blksize; + sb += stat.st_mode; + sb += stat.st_uid; + sb += stat.st_gid; + sb += stat.st_atime; + sb += stat.st_mtime; + sb += stat.st_ctime; + sb += stat.st_size; + sb += stat.st_blksize; return CELL_OK; } @@ -377,10 +373,10 @@ int cellFsUnlink(u32 path_addr) return CELL_OK; } -int cellFsLseek(u32 fd, s64 offset, u32 whence, u32 pos_addr) +int cellFsLseek(u32 fd, s64 offset, u32 whence, mem64_t pos) { vfsSeekMode seek_mode; - sys_fs.Log("cellFsLseek(fd: %d, offset: 0x%llx, whence: %d, pos_addr: 0x%x)", fd, offset, whence, pos_addr); + sys_fs.Log("cellFsLseek(fd: %d, offset: 0x%llx, whence: %d, pos_addr: 0x%x)", fd, offset, whence, pos.GetAddr()); switch(whence) { case LV2_SEEK_SET: seek_mode = vfsSeekSet; break; @@ -393,7 +389,7 @@ int cellFsLseek(u32 fd, s64 offset, u32 whence, u32 pos_addr) ID id; if(!sys_fs.CheckId(fd, id)) return CELL_ESRCH; vfsStream& file = *(vfsStream*)id.m_data; - Memory.Write64(pos_addr, file.Seek(offset, seek_mode)); + pos = file.Seek(offset, seek_mode); return CELL_OK; } @@ -432,7 +428,7 @@ int cellFsFtruncate(u32 fd, u64 size) int cellFsTruncate(u32 path_addr, u64 size) { const wxString& path = Memory.ReadString(path_addr); - sys_fs.Log("cellFsTruncate(path_addr: %s, size: %lld)", path, size); + sys_fs.Log("cellFsTruncate(path: %s, size: %lld)", path, size); vfsStream* f = Emu.GetVFS().Open(path, vfsRead); if(!f || !f->IsOpened()) @@ -468,12 +464,12 @@ int cellFsTruncate(u32 path_addr, u64 size) return CELL_OK; } -int cellFsFGetBlockSize(u32 fd, u32 sector_size_addr, u32 block_size_addr) +int cellFsFGetBlockSize(u32 fd, mem64_t sector_size, mem64_t block_size) { - sys_fs.Log("cellFsFGetBlockSize(fd: %d, sector_size_addr: 0x%x, block_size_addr: 0x%x)", fd, sector_size_addr, block_size_addr); + sys_fs.Log("cellFsFGetBlockSize(fd: %d, sector_size_addr: 0x%x, block_size_addr: 0x%x)", fd, sector_size.GetAddr(), block_size.GetAddr()); - Memory.Write64(sector_size_addr, 4096); // ? - Memory.Write64(block_size_addr, 4096); // ? + sector_size = 4096; // ? + block_size = 4096; // ? return CELL_OK; } \ No newline at end of file diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 6be36bfe64..22105acae6 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -36,9 +36,10 @@ void Emulator::Init() //m_memory_viewer = new MemoryViewerPanel(wxGetApp().m_MainFrame); } -void Emulator::SetPath(const wxString& path) +void Emulator::SetPath(const wxString& path, const wxString& elf_path) { m_path = path; + m_elf_path = elf_path; } void Emulator::CheckStatus() @@ -84,10 +85,30 @@ void Emulator::Load() ConLog.Write("loading '%s'...", m_path); Memory.Init(); GetInfo().Reset(); + m_vfs.Init(m_path); + //m_vfs.Mount("/", vfsDevice::GetRoot(m_path), new vfsLocalFile()); + //m_vfs.Mount("/dev_hdd0/", wxGetCwd() + "\\dev_hdd0\\", new vfsLocalFile()); + //m_vfs.Mount("/app_home/", vfsDevice::GetRoot(m_path), new vfsLocalFile()); + //m_vfs.Mount(vfsDevice::GetRootPs3(m_path), vfsDevice::GetRoot(m_path), new vfsLocalFile()); + + ConLog.SkipLn(); + ConLog.Write("Mount info:"); + for(uint i=0; i %s", m_vfs.m_devices[i].GetPs3Path(), m_vfs.m_devices[i].GetLocalPath()); + } + ConLog.SkipLn(); + + const auto f = m_elf_path.Len() ? OpenFile(m_elf_path) : std::shared_ptr(new vfsLocalFile(m_path)); + + if(!f->IsOpened()) + { + ConLog.Error("Elf not found! (%s - %s)", m_path, m_elf_path); + return; + } bool is_error; - vfsLocalFile f(m_path); - Loader l(f); + Loader l(*f); try { @@ -133,20 +154,33 @@ void Emulator::Load() m_rsx_callback = Memory.MainMem.Alloc(4 * 4) + 4; Memory.Write32(m_rsx_callback - 4, m_rsx_callback); - mem32_t callback_data(m_rsx_callback); + mem32_ptr_t callback_data(m_rsx_callback); callback_data += ADDI(11, 0, 0x3ff); callback_data += SC(2); callback_data += BCLR(0x10 | 0x04, 0, 0, 0); m_ppu_thr_exit = Memory.MainMem.Alloc(4 * 4); - mem32_t ppu_thr_exit_data(m_ppu_thr_exit); + mem32_ptr_t ppu_thr_exit_data(m_ppu_thr_exit); ppu_thr_exit_data += ADDI(3, 0, 0); ppu_thr_exit_data += ADDI(11, 0, 41); ppu_thr_exit_data += SC(2); ppu_thr_exit_data += BCLR(0x10 | 0x04, 0, 0, 0); } + if(!m_dbg_console) + { + m_dbg_console = new DbgConsole(); + } + else + { + GetDbgCon().Close(); + GetDbgCon().Clear(); + } + + GetGSManager().Init(); + GetCallbackManager().Init(); + thread.Run(); wxCriticalSectionLocker lock(m_cs_status); @@ -175,39 +209,12 @@ void Emulator::Run() //ConLog.Write("run..."); m_status = Running; - m_vfs.Init(m_path); - //m_vfs.Mount("/", vfsDevice::GetRoot(m_path), new vfsLocalFile()); - //m_vfs.Mount("/dev_hdd0/", wxGetCwd() + "\\dev_hdd0\\", new vfsLocalFile()); - //m_vfs.Mount("/app_home/", vfsDevice::GetRoot(m_path), new vfsLocalFile()); - //m_vfs.Mount(vfsDevice::GetRootPs3(m_path), vfsDevice::GetRoot(m_path), new vfsLocalFile()); - - ConLog.SkipLn(); - ConLog.Write("Mount info:"); - for(uint i=0; i %s", m_vfs.m_devices[i].GetPs3Path(), m_vfs.m_devices[i].GetLocalPath()); - } - ConLog.SkipLn(); - //if(m_memory_viewer && m_memory_viewer->exit) safe_delete(m_memory_viewer); //m_memory_viewer->SetPC(loader.GetEntry()); //m_memory_viewer->Show(); //m_memory_viewer->ShowPC(); - if(!m_dbg_console) - { - m_dbg_console = new DbgConsole(); - } - else - { - GetDbgCon().Close(); - GetDbgCon().Clear(); - } - - GetGSManager().Init(); - GetCallbackManager().Init(); - GetCPU().Exec(); wxGetApp().SendDbgCommand(DID_STARTED_EMU); } @@ -327,4 +334,4 @@ void Emulator::LoadPoints(const wxString& path) } } -Emulator Emu; \ No newline at end of file +Emulator Emu; diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index 36264a8ae2..670e951788 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -92,11 +92,22 @@ class Emulator public: wxString m_path; + wxString m_elf_path; Emulator(); void Init(); - void SetPath(const wxString& path); + void SetPath(const wxString& path, const wxString& elf_path = wxEmptyString); + + std::shared_ptr OpenFile(const wxString& path, vfsOpenMode mode = vfsRead) + { + return std::shared_ptr((vfsFileBase*)m_vfs.Open(path, mode)); + } + + std::shared_ptr OpenStream(const wxString& path, vfsOpenMode mode = vfsRead) + { + return std::shared_ptr(m_vfs.Open(path, mode)); + } PPCThreadManager& GetCPU() { return m_thread_manager; } PadManager& GetPadManager() { return m_pad_manager; } diff --git a/rpcs3/Loader/ELF64.cpp b/rpcs3/Loader/ELF64.cpp index b1cf1ff8ef..ccb462d15e 100644 --- a/rpcs3/Loader/ELF64.cpp +++ b/rpcs3/Loader/ELF64.cpp @@ -380,11 +380,11 @@ bool ELF64Loader::LoadPhdrData(u64 offset) #endif Memory.Write32(stub.s_text + i*4, tbl + i*8); - mem32_t out_tbl(tbl + i*8); + mem32_ptr_t out_tbl(tbl + i*8); out_tbl += dst + i*section; out_tbl += GetFuncNumById(nid); - mem32_t out_dst(dst + i*section); + mem32_ptr_t out_dst(dst + i*section); out_dst += OR(11, 2, 2, 0); out_dst += SC(2); out_dst += BCLR(0x10 | 0x04, 0, 0, 0); diff --git a/rpcs3/stdafx.h b/rpcs3/stdafx.h index dc4a743d78..3a02d6b320 100644 --- a/rpcs3/stdafx.h +++ b/rpcs3/stdafx.h @@ -122,6 +122,7 @@ union s128 } }; +#include #include //TODO: SSE style