Improved mem_t.

- Implemented mem_ptr_t.
- Fixed issue 3.
This commit is contained in:
DH 2013-09-25 00:11:29 +03:00
parent e655999a23
commit eebe859f83
20 changed files with 259 additions and 170 deletions

View File

@ -138,7 +138,7 @@ public:
wxArrayString ErrorToString() { return ErrorToString(m_error); } wxArrayString ErrorToString() { return ErrorToString(m_error); }
bool IsOk() const { return m_error == 0; } 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 IsPaused() const { return m_status == Paused; }
bool IsStopped() const { return m_status == Stopped; } bool IsStopped() const { return m_status == Stopped; }

View File

@ -105,7 +105,7 @@ void PPUThread::InitRegs()
stack_point -= 0xc + 4 * argc; stack_point -= 0xc + 4 * argc;
u64 argv = stack_point; u64 argv = stack_point;
mem64_t argv_list(argv); mem64_ptr_t argv_list(argv);
for(int i=0; i<argc; ++i) argv_list += argv_addr[i]; for(int i=0; i<argc; ++i) argv_list += argv_addr[i];
GPR[3] = argc; GPR[3] = argc;

View File

@ -11,8 +11,8 @@ public:
vfsFileBase(); vfsFileBase();
virtual ~vfsFileBase(); virtual ~vfsFileBase();
virtual bool Open(const wxString& path, vfsOpenMode mode); virtual bool Open(const wxString& path, vfsOpenMode mode) override;
virtual bool Close(); virtual bool Close() override;
/* /*
virtual bool Create(const wxString& path)=0; virtual bool Create(const wxString& path)=0;
virtual bool Exists(const wxString& path)=0; virtual bool Exists(const wxString& path)=0;

View File

@ -69,12 +69,12 @@ u64 vfsLocalFile::GetSize()
return m_file.Length(); return m_file.Length();
} }
u32 vfsLocalFile::Write(const void* src, u32 size) u64 vfsLocalFile::Write(const void* src, u64 size)
{ {
return m_file.Write(src, size); return m_file.Write(src, size);
} }
u32 vfsLocalFile::Read(void* dst, u32 size) u64 vfsLocalFile::Read(void* dst, u64 size)
{ {
return m_file.Read(dst, size); return m_file.Read(dst, size);
} }

View File

@ -11,17 +11,17 @@ public:
vfsLocalFile(const wxString path, vfsOpenMode mode = vfsRead); vfsLocalFile(const wxString path, vfsOpenMode mode = vfsRead);
vfsDevice* GetNew(); vfsDevice* GetNew();
virtual bool Open(const wxString& path, vfsOpenMode mode = vfsRead); virtual bool Open(const wxString& path, vfsOpenMode mode = vfsRead) override;
virtual bool Create(const wxString& path); virtual bool Create(const wxString& path) override;
virtual bool Close(); virtual bool Close() override;
virtual u64 GetSize(); virtual u64 GetSize() override;
virtual u32 Write(const void* src, u32 size); virtual u64 Write(const void* src, u64 size) override;
virtual u32 Read(void* dst, u32 size); virtual u64 Read(void* dst, u64 size) override;
virtual u64 Seek(s64 offset, vfsSeekMode mode = vfsSeekSet); virtual u64 Seek(s64 offset, vfsSeekMode mode = vfsSeekSet) override;
virtual u64 Tell() const; virtual u64 Tell() const override;
virtual bool IsOpened() const; virtual bool IsOpened() const override;
}; };

View File

@ -32,14 +32,14 @@ u64 vfsStream::GetSize()
return size; return size;
} }
u32 vfsStream::Write(const void* src, u32 size) u64 vfsStream::Write(const void* src, u64 size)
{ {
m_pos += size; m_pos += size;
return size; return size;
} }
u32 vfsStream::Read(void* dst, u32 size) u64 vfsStream::Read(void* dst, u64 size)
{ {
m_pos += size; m_pos += size;

View File

@ -22,8 +22,8 @@ public:
virtual u64 GetSize(); virtual u64 GetSize();
virtual u32 Write(const void* src, u32 size); virtual u64 Write(const void* src, u64 size);
virtual u32 Read(void* dst, u32 size); virtual u64 Read(void* dst, u64 size);
virtual u64 Seek(s64 offset, vfsSeekMode mode = vfsSeekSet); virtual u64 Seek(s64 offset, vfsSeekMode mode = vfsSeekSet);
virtual u64 Tell() const; virtual u64 Tell() const;

View File

@ -17,7 +17,7 @@ void vfsStreamMemory::Open(u64 addr)
vfsStream::Reset(); vfsStream::Reset();
} }
u32 vfsStreamMemory::Write(const void* src, u32 size) u64 vfsStreamMemory::Write(const void* src, u64 size)
{ {
if(!Memory.IsGoodAddr(m_addr + Tell(), size)) return 0; if(!Memory.IsGoodAddr(m_addr + Tell(), size)) return 0;
@ -26,7 +26,7 @@ u32 vfsStreamMemory::Write(const void* src, u32 size)
return vfsStream::Write(src, size); return vfsStream::Write(src, size);
} }
u32 vfsStreamMemory::Read(void* dst, u32 size) u64 vfsStreamMemory::Read(void* dst, u64 size)
{ {
if(!Memory.IsGoodAddr(m_addr + Tell(), size)) return 0; if(!Memory.IsGoodAddr(m_addr + Tell(), size)) return 0;

View File

@ -11,6 +11,6 @@ public:
void Open(u64 addr); void Open(u64 addr);
virtual u32 Write(const void* src, u32 size); virtual u64 Write(const void* src, u64 size) override;
virtual u32 Read(void* dst, u32 size); virtual u64 Read(void* dst, u64 size) override;
}; };

View File

@ -115,7 +115,7 @@ wxString FragmentDecompilerThread::AddCond(int fp16)
wxString FragmentDecompilerThread::AddConst() wxString FragmentDecompilerThread::AddConst()
{ {
mem32_t data(m_addr + m_size + m_offset); mem32_ptr_t data(m_addr + m_size + m_offset);
m_offset += 4 * 4; m_offset += 4 * 4;
u32 x = GetData(data[0]); u32 x = GetData(data[0]);
@ -221,7 +221,7 @@ wxString FragmentDecompilerThread::BuildCode()
void FragmentDecompilerThread::Task() void FragmentDecompilerThread::Task()
{ {
mem32_t data(m_addr); mem32_ptr_t data(m_addr);
m_size = 0; m_size = 0;
while(true) while(true)

View File

@ -191,7 +191,7 @@ void GLRSXThread::Task()
continue; continue;
} }
mem32_t args(p.m_ioAddress + get + 4); mem32_ptr_t args(p.m_ioAddress + get + 4);
if(!draw) if(!draw)
{ {
@ -508,7 +508,7 @@ void GLGSRender::InitFragmentData()
index = (cmd - a) / m; \ index = (cmd - a) / m; \
case a \ case a \
void GLGSRender::DoCmd(const u32 fcmd, const u32 cmd, mem32_t& args, const u32 count) void GLGSRender::DoCmd(const u32 fcmd, const u32 cmd, mem32_ptr_t& args, const u32 count)
{ {
#if CMD_DEBUG #if CMD_DEBUG
wxString debug = GetMethodName(cmd); wxString debug = GetMethodName(cmd);

View File

@ -558,7 +558,7 @@ private:
bool LoadProgram(); bool LoadProgram();
public: public:
void DoCmd(const u32 fcmd, const u32 cmd, mem32_t& args, const u32 count); void DoCmd(const u32 fcmd, const u32 cmd, mem32_ptr_t& args, const u32 count);
void CloseOpenGL(); void CloseOpenGL();
virtual void ExecCMD(); virtual void ExecCMD();

View File

@ -78,7 +78,7 @@ private:
} }
public: public:
void DoCmd(const u32 fcmd, const u32 cmd, mem32_t& args, const u32 count) void DoCmd(const u32 fcmd, const u32 cmd, mem32_ptr_t& args, const u32 count)
{ {
switch(cmd) switch(cmd)
{ {
@ -179,7 +179,7 @@ wxThread::ExitCode NullRSXThread::Entry()
continue; continue;
} }
p.DoCmd(cmd, cmd & 0x3ffff, mem32_t(p.m_ioAddress + get + 4), count); p.DoCmd(cmd, cmd & 0x3ffff, mem32_ptr_t(p.m_ioAddress + get + 4), count);
re(p.m_ctrl->get, get + (count + 1) * 4); re(p.m_ctrl->get, get + (count + 1) * 4);
} }

View File

@ -369,15 +369,91 @@ public:
extern MemoryBase Memory; extern MemoryBase Memory;
template<typename T> class mem_t class MemoryAllocator
{ {
u64 addr; u32 m_addr;
const u64 iaddr;
public: public:
mem_t(u64 _addr) MemoryAllocator(u32 size, u32 align = 1)
: addr(_addr) {
, iaddr(_addr) m_addr = Memory.Alloc(size, align);
}
~MemoryAllocator()
{
Memory.Free(m_addr);
}
operator u32() const
{
return m_addr;
}
};
template<typename T> 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<typename T> 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)) switch(sizeof(T))
{ {
case 1: Memory.Write8(addr, right); return; case 1: Memory.Write8(m_addr, right); return;
case 2: Memory.Write16(addr, right); return; case 2: Memory.Write16(m_addr, right); return;
case 4: Memory.Write32(addr, right); return; case 4: Memory.Write32(m_addr, right); return;
case 8: Memory.Write64(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 u8() const { return Memory.Read8(m_addr); }
operator u16() const { return Memory.Read16(addr); } operator u16() const { return Memory.Read16(m_addr); }
operator u32() const { return Memory.Read32(addr); } operator u32() const { return Memory.Read32(m_addr); }
operator u64() const { return Memory.Read64(addr); } operator u64() const { return Memory.Read64(m_addr); }
/*
u64 operator += (u64 right)
{
addr += right;
return addr;
}
*/
u64 operator += (T right) u64 operator += (T right)
{ {
*this = right; *this = right;
addr += sizeof(T); m_addr += sizeof(T);
return addr; return m_addr;
} }
T operator [] (u64 i) const T operator [] (u64 i) const
{ {
const u64 offset = i*sizeof(T); const u64 offset = i*sizeof(T);
addr += offset; (*(mem_ptr_t*)this).m_addr += offset;
const T ret = *this; const T ret = *this;
addr -= offset; (*(mem_ptr_t*)this).m_addr -= offset;
return ret; return ret;
} }
void Reset() { addr = iaddr; } void Reset() { m_addr = m_iaddr; }
u64 GetCurAddr() const { return addr; } u64 GetCurAddr() const { return m_addr; }
u64 GetAddr() const { return iaddr; } u64 GetAddr() const { return m_iaddr; }
u64 SetOffset(const u32 offset) { return addr += offset; } u64 SetOffset(const u32 offset) { return m_addr += offset; }
}; };
class mem_class_t class mem_class_t
@ -465,4 +534,9 @@ public:
typedef mem_t<u8> mem8_t; typedef mem_t<u8> mem8_t;
typedef mem_t<u16> mem16_t; typedef mem_t<u16> mem16_t;
typedef mem_t<u32> mem32_t; typedef mem_t<u32> mem32_t;
typedef mem_t<u64> mem64_t; typedef mem_t<u64> mem64_t;
typedef mem_ptr_t<u8> mem8_ptr_t;
typedef mem_ptr_t<u16> mem16_ptr_t;
typedef mem_ptr_t<u32> mem32_ptr_t;
typedef mem_ptr_t<u64> mem64_ptr_t;

View File

@ -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); extern int sys_mmapper_map_memory(u32 start_addr, u32 mem_id, u64 flags);
//cellFs //cellFs
extern int cellFsOpen(u32 path_addr, int flags, u32 fd_addr, u32 arg_addr, u64 size); 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, u32 nread_addr); extern int cellFsRead(u32 fd, u32 buf_addr, u64 nbytes, mem64_t nread_addr);
extern int cellFsWrite(u32 fd, u32 buf_addr, u64 nbytes, u32 nwrite_addr); extern int cellFsWrite(u32 fd, u32 buf_addr, u64 nbytes, mem64_t nwrite_addr);
extern int cellFsClose(u32 fd); extern int cellFsClose(u32 fd);
extern int cellFsOpendir(u32 path_addr, u32 fd_addr); extern int cellFsOpendir(u32 path_addr, mem32_t fd);
extern int cellFsReaddir(u32 fd, u32 dir_addr, u32 nread_addr); extern int cellFsReaddir(u32 fd, u32 dir_addr, mem64_t nread);
extern int cellFsClosedir(u32 fd); extern int cellFsClosedir(u32 fd);
extern int cellFsStat(u32 path_addr, u32 sb_addr); extern int cellFsStat(u32 path_addr, mem_class_t sb);
extern int cellFsFstat(u32 fd, u32 sb_addr); extern int cellFsFstat(u32 fd, mem_class_t sb);
extern int cellFsMkdir(u32 path_addr, u32 mode); extern int cellFsMkdir(u32 path_addr, u32 mode);
extern int cellFsRename(u32 from_addr, u32 to_addr); extern int cellFsRename(u32 from_addr, u32 to_addr);
extern int cellFsRmdir(u32 path_addr); extern int cellFsRmdir(u32 path_addr);
extern int cellFsUnlink(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 cellFsFtruncate(u32 fd, u64 size);
extern int cellFsTruncate(u32 path_addr, 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 //cellVideo
extern int cellVideoOutGetState(u32 videoOut, u32 deviceIndex, u32 state_addr); extern int cellVideoOutGetState(u32 videoOut, u32 deviceIndex, u32 state_addr);

View File

@ -1,7 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "Emu/SysCalls/SysCalls.h" #include "Emu/SysCalls/SysCalls.h"
enum Lv2FsOflag enum CellFsOflag
{ {
LV2_O_RDONLY = 000000, LV2_O_RDONLY = 000000,
LV2_O_WRONLY = 000001, LV2_O_WRONLY = 000001,
@ -16,14 +16,14 @@ enum Lv2FsOflag
#define CELL_FS_TYPE_UNKNOWN 0 #define CELL_FS_TYPE_UNKNOWN 0
enum Lv2FsSeek enum CellFsSeek
{ {
LV2_SEEK_SET, LV2_SEEK_SET,
LV2_SEEK_CUR, LV2_SEEK_CUR,
LV2_SEEK_END, LV2_SEEK_END,
}; };
enum Lv2FsLength enum CellFsLength
{ {
LV2_MAX_FS_PATH_LENGTH = 1024, LV2_MAX_FS_PATH_LENGTH = 1024,
LV2_MAX_FS_FILE_NAME_LENGTH = 255, LV2_MAX_FS_FILE_NAME_LENGTH = 255,
@ -50,25 +50,25 @@ enum
CELL_FS_S_IXOTH = 0000001, //X for other CELL_FS_S_IXOTH = 0000001, //X for other
}; };
struct Lv2FsStat struct CellFsStat
{ {
u32 st_mode; u32 st_mode;
s32 st_uid; s32 st_uid;
s32 st_gid; s32 st_gid;
time_t st_atime; u64 st_atime;
time_t st_mtime; u64 st_mtime;
time_t st_ctime; u64 st_ctime;
u64 st_size; u64 st_size;
u64 st_blksize; u64 st_blksize;
}; };
struct Lv2FsUtimbuf struct CellFsUtimbuf
{ {
time_t actime; u64 actime;
time_t modtime; u64 modtime;
}; };
struct Lv2FsDirent struct CellFsDirent
{ {
u8 d_type; u8 d_type;
u8 d_namlen; u8 d_namlen;
@ -84,11 +84,11 @@ enum FsDirentType
extern Module sys_fs; 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); 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)", 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; const wxString& ppath = path;
//ConLog.Warning("path: %s [%s]", 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; return CELL_ENOENT;
} }
Memory.Write32(fd_addr, sys_fs.GetNewId(stream, flags)); fd = sys_fs.GetNewId(stream, flags);
return CELL_OK; 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)", 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; ID id;
if(!sys_fs.CheckId(fd, id)) return CELL_ESRCH; if(!sys_fs.CheckId(fd, id)) return CELL_ESRCH;
vfsStream& file = *(vfsStream*)id.m_data; 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; 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)", 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; ID id;
if(!sys_fs.CheckId(fd, id)) return CELL_ESRCH; if(!sys_fs.CheckId(fd, id)) return CELL_ESRCH;
vfsStream& file = *(vfsStream*)id.m_data; 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()); nbytes = block.GetSize() - (buf_addr - block.GetStartAddr());
} }
int count = nbytes ? file.Write(Memory.GetMemFromAddr(buf_addr), nbytes) : 0; nwrite = nbytes ? file.Write(Memory.GetMemFromAddr(buf_addr), nbytes) : 0;
Memory.Write64NN(nwrite_addr, count);
return CELL_OK; return CELL_OK;
} }
@ -221,18 +221,18 @@ int cellFsClose(u32 fd)
return CELL_OK; 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); 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); sys_fs.Error("cellFsOpendir(path_addr: 0x%x(%s), fd_addr: 0x%x)", path_addr, path, fd.GetAddr());
if(!Memory.IsGoodAddr(path_addr, sizeof(u32)) || !Memory.IsGoodAddr(fd_addr, sizeof(u32))) return CELL_EFAULT; if(!Memory.IsGoodAddr(path_addr) || !fd.IsGood()) return CELL_EFAULT;
return CELL_OK; 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; return CELL_OK;
} }
@ -242,10 +242,10 @@ int cellFsClosedir(u32 fd)
return CELL_OK; 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); 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) // Check if path is a mount point. (TODO: Add information in sb_addr)
for(u32 i=0; i<Emu.GetVFS().m_devices.GetCount(); ++i) for(u32 i=0; i<Emu.GetVFS().m_devices.GetCount(); ++i)
@ -257,15 +257,15 @@ int cellFsStat(const u32 path_addr, const u32 sb_addr)
} }
} }
vfsStream* f = Emu.GetVFS().Open(path, vfsRead); auto f = Emu.OpenFile(path);
if(!f || !f->IsOpened())
if(!f->IsOpened())
{ {
sys_fs.Warning("cellFsFstat: '%s' not found.", path); sys_fs.Warning("cellFsFstat: '%s' not found.", path);
Emu.GetVFS().Close(f);
return CELL_ENOENT; return CELL_ENOENT;
} }
Lv2FsStat stat; CellFsStat stat;
stat.st_mode = stat.st_mode =
CELL_FS_S_IRUSR | CELL_FS_S_IWUSR | CELL_FS_S_IXUSR | CELL_FS_S_IRUSR | CELL_FS_S_IWUSR | CELL_FS_S_IXUSR |
CELL_FS_S_IRGRP | CELL_FS_S_IWGRP | CELL_FS_S_IXGRP | 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_size = f->GetSize();
stat.st_blksize = 4096; stat.st_blksize = 4096;
mem_class_t stat_c(sb_addr); sb += stat.st_mode;
stat_c += stat.st_mode; sb += stat.st_uid;
stat_c += stat.st_uid; sb += stat.st_gid;
stat_c += stat.st_gid; sb += stat.st_atime;
stat_c += stat.st_atime; sb += stat.st_mtime;
stat_c += stat.st_mtime; sb += stat.st_ctime;
stat_c += stat.st_ctime; sb += stat.st_size;
stat_c += stat.st_size; sb += stat.st_blksize;
stat_c += stat.st_blksize;
Emu.GetVFS().Close(f);
return CELL_OK; 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; ID id;
if(!sys_fs.CheckId(fd, id)) return CELL_ESRCH; if(!sys_fs.CheckId(fd, id)) return CELL_ESRCH;
vfsStream& file = *(vfsStream*)id.m_data; vfsStream& file = *(vfsStream*)id.m_data;
Lv2FsStat stat; CellFsStat stat;
stat.st_mode = stat.st_mode =
CELL_FS_S_IRUSR | CELL_FS_S_IWUSR | CELL_FS_S_IXUSR | CELL_FS_S_IRUSR | CELL_FS_S_IWUSR | CELL_FS_S_IXUSR |
CELL_FS_S_IRGRP | CELL_FS_S_IWGRP | CELL_FS_S_IXGRP | 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_size = file.GetSize();
stat.st_blksize = 4096; stat.st_blksize = 4096;
mem_class_t stat_c(sb_addr); sb += stat.st_mode;
stat_c += stat.st_mode; sb += stat.st_uid;
stat_c += stat.st_uid; sb += stat.st_gid;
stat_c += stat.st_gid; sb += stat.st_atime;
stat_c += stat.st_atime; sb += stat.st_mtime;
stat_c += stat.st_mtime; sb += stat.st_ctime;
stat_c += stat.st_ctime; sb += stat.st_size;
stat_c += stat.st_size; sb += stat.st_blksize;
stat_c += stat.st_blksize;
return CELL_OK; return CELL_OK;
} }
@ -377,10 +373,10 @@ int cellFsUnlink(u32 path_addr)
return CELL_OK; 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; 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) switch(whence)
{ {
case LV2_SEEK_SET: seek_mode = vfsSeekSet; break; 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; ID id;
if(!sys_fs.CheckId(fd, id)) return CELL_ESRCH; if(!sys_fs.CheckId(fd, id)) return CELL_ESRCH;
vfsStream& file = *(vfsStream*)id.m_data; vfsStream& file = *(vfsStream*)id.m_data;
Memory.Write64(pos_addr, file.Seek(offset, seek_mode)); pos = file.Seek(offset, seek_mode);
return CELL_OK; return CELL_OK;
} }
@ -432,7 +428,7 @@ int cellFsFtruncate(u32 fd, u64 size)
int cellFsTruncate(u32 path_addr, u64 size) int cellFsTruncate(u32 path_addr, u64 size)
{ {
const wxString& path = Memory.ReadString(path_addr); 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); vfsStream* f = Emu.GetVFS().Open(path, vfsRead);
if(!f || !f->IsOpened()) if(!f || !f->IsOpened())
@ -468,12 +464,12 @@ int cellFsTruncate(u32 path_addr, u64 size)
return CELL_OK; 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); // ? sector_size = 4096; // ?
Memory.Write64(block_size_addr, 4096); // ? block_size = 4096; // ?
return CELL_OK; return CELL_OK;
} }

View File

@ -36,9 +36,10 @@ void Emulator::Init()
//m_memory_viewer = new MemoryViewerPanel(wxGetApp().m_MainFrame); //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_path = path;
m_elf_path = elf_path;
} }
void Emulator::CheckStatus() void Emulator::CheckStatus()
@ -84,10 +85,30 @@ void Emulator::Load()
ConLog.Write("loading '%s'...", m_path); ConLog.Write("loading '%s'...", m_path);
Memory.Init(); Memory.Init();
GetInfo().Reset(); 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<m_vfs.m_devices.GetCount(); ++i)
{
ConLog.Write("%s -> %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<vfsLocalFile>(new vfsLocalFile(m_path));
if(!f->IsOpened())
{
ConLog.Error("Elf not found! (%s - %s)", m_path, m_elf_path);
return;
}
bool is_error; bool is_error;
vfsLocalFile f(m_path); Loader l(*f);
Loader l(f);
try try
{ {
@ -133,20 +154,33 @@ void Emulator::Load()
m_rsx_callback = Memory.MainMem.Alloc(4 * 4) + 4; m_rsx_callback = Memory.MainMem.Alloc(4 * 4) + 4;
Memory.Write32(m_rsx_callback - 4, m_rsx_callback); 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 += ADDI(11, 0, 0x3ff);
callback_data += SC(2); callback_data += SC(2);
callback_data += BCLR(0x10 | 0x04, 0, 0, 0); callback_data += BCLR(0x10 | 0x04, 0, 0, 0);
m_ppu_thr_exit = Memory.MainMem.Alloc(4 * 4); 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(3, 0, 0);
ppu_thr_exit_data += ADDI(11, 0, 41); ppu_thr_exit_data += ADDI(11, 0, 41);
ppu_thr_exit_data += SC(2); ppu_thr_exit_data += SC(2);
ppu_thr_exit_data += BCLR(0x10 | 0x04, 0, 0, 0); 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(); thread.Run();
wxCriticalSectionLocker lock(m_cs_status); wxCriticalSectionLocker lock(m_cs_status);
@ -175,39 +209,12 @@ void Emulator::Run()
//ConLog.Write("run..."); //ConLog.Write("run...");
m_status = Running; 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<m_vfs.m_devices.GetCount(); ++i)
{
ConLog.Write("%s -> %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); //if(m_memory_viewer && m_memory_viewer->exit) safe_delete(m_memory_viewer);
//m_memory_viewer->SetPC(loader.GetEntry()); //m_memory_viewer->SetPC(loader.GetEntry());
//m_memory_viewer->Show(); //m_memory_viewer->Show();
//m_memory_viewer->ShowPC(); //m_memory_viewer->ShowPC();
if(!m_dbg_console)
{
m_dbg_console = new DbgConsole();
}
else
{
GetDbgCon().Close();
GetDbgCon().Clear();
}
GetGSManager().Init();
GetCallbackManager().Init();
GetCPU().Exec(); GetCPU().Exec();
wxGetApp().SendDbgCommand(DID_STARTED_EMU); wxGetApp().SendDbgCommand(DID_STARTED_EMU);
} }
@ -327,4 +334,4 @@ void Emulator::LoadPoints(const wxString& path)
} }
} }
Emulator Emu; Emulator Emu;

View File

@ -92,11 +92,22 @@ class Emulator
public: public:
wxString m_path; wxString m_path;
wxString m_elf_path;
Emulator(); Emulator();
void Init(); void Init();
void SetPath(const wxString& path); void SetPath(const wxString& path, const wxString& elf_path = wxEmptyString);
std::shared_ptr<vfsFileBase> OpenFile(const wxString& path, vfsOpenMode mode = vfsRead)
{
return std::shared_ptr<vfsFileBase>((vfsFileBase*)m_vfs.Open(path, mode));
}
std::shared_ptr<vfsStream> OpenStream(const wxString& path, vfsOpenMode mode = vfsRead)
{
return std::shared_ptr<vfsStream>(m_vfs.Open(path, mode));
}
PPCThreadManager& GetCPU() { return m_thread_manager; } PPCThreadManager& GetCPU() { return m_thread_manager; }
PadManager& GetPadManager() { return m_pad_manager; } PadManager& GetPadManager() { return m_pad_manager; }

View File

@ -380,11 +380,11 @@ bool ELF64Loader::LoadPhdrData(u64 offset)
#endif #endif
Memory.Write32(stub.s_text + i*4, tbl + i*8); 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 += dst + i*section;
out_tbl += GetFuncNumById(nid); 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 += OR(11, 2, 2, 0);
out_dst += SC(2); out_dst += SC(2);
out_dst += BCLR(0x10 | 0x04, 0, 0, 0); out_dst += BCLR(0x10 | 0x04, 0, 0, 0);

View File

@ -122,6 +122,7 @@ union s128
} }
}; };
#include <memory>
#include <emmintrin.h> #include <emmintrin.h>
//TODO: SSE style //TODO: SSE style