mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-21 12:05:23 +00:00
Test
This commit is contained in:
parent
26e03fa794
commit
571bd63644
7 changed files with 313 additions and 211 deletions
|
@ -6,14 +6,14 @@
|
|||
|
||||
#ifndef _WIN32
|
||||
#include <sys/mman.h>
|
||||
#else
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
/* OS X uses MAP_ANON instead of MAP_ANONYMOUS */
|
||||
#ifndef MAP_ANONYMOUS
|
||||
#define MAP_ANONYMOUS MAP_ANON
|
||||
#endif
|
||||
#else
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
MemoryBase Memory;
|
||||
|
||||
|
@ -108,14 +108,11 @@ void MemoryBase::Init(MemoryType type)
|
|||
memset(RawSPUMem, 0, sizeof(RawSPUMem));
|
||||
|
||||
#ifdef _WIN32
|
||||
m_base_addr = VirtualAlloc(nullptr, 0x100000000, MEM_RESERVE, PAGE_NOACCESS);
|
||||
if (!m_base_addr)
|
||||
#else
|
||||
m_base_addr = ::mmap(nullptr, 0x100000000, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
|
||||
if (m_base_addr == (void*)-1)
|
||||
if ((s64)m_base_addr == (s64)-1)
|
||||
#endif
|
||||
{
|
||||
m_base_addr = nullptr;
|
||||
LOG_ERROR(MEMORY, "Initializing memory failed");
|
||||
assert(0);
|
||||
return;
|
||||
|
@ -139,7 +136,6 @@ void MemoryBase::Init(MemoryType type)
|
|||
case Memory_PSV:
|
||||
MemoryBlocks.push_back(PSV.RAM.SetRange(0x81000000, 0x10000000));
|
||||
MemoryBlocks.push_back(UserMemory = PSV.Userspace.SetRange(0x91000000, 0x10000000));
|
||||
PSV.Init(GetBaseAddr());
|
||||
break;
|
||||
|
||||
case Memory_PSP:
|
||||
|
@ -148,7 +144,6 @@ void MemoryBase::Init(MemoryType type)
|
|||
MemoryBlocks.push_back(PSP.RAM.SetRange(0x08000000, 0x02000000));
|
||||
MemoryBlocks.push_back(PSP.Kernel.SetRange(0x88000000, 0x00800000));
|
||||
MemoryBlocks.push_back(UserMemory = PSP.Userspace.SetRange(0x08800000, 0x01800000));
|
||||
PSP.Init(GetBaseAddr());
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -173,17 +168,17 @@ void MemoryBase::Close()
|
|||
|
||||
MemoryBlocks.clear();
|
||||
|
||||
#ifdef _WIN32
|
||||
if (!VirtualFree(m_base_addr, 0, MEM_RELEASE))
|
||||
{
|
||||
LOG_ERROR(MEMORY, "VirtualFree(0x%llx) failed", (u64)m_base_addr);
|
||||
}
|
||||
#else
|
||||
if (::munmap(m_base_addr, 0x100000000))
|
||||
{
|
||||
LOG_ERROR(MEMORY, "::munmap(0x%llx) failed", (u64)m_base_addr);
|
||||
}
|
||||
#endif
|
||||
//#ifdef _WIN32
|
||||
// if (!VirtualFree(m_base_addr, 0, MEM_RELEASE))
|
||||
// {
|
||||
// LOG_ERROR(MEMORY, "VirtualFree(0x%llx) failed", (u64)m_base_addr);
|
||||
// }
|
||||
//#else
|
||||
// if (::munmap(m_base_addr, 0x100000000))
|
||||
// {
|
||||
// LOG_ERROR(MEMORY, "::munmap(0x%llx) failed", (u64)m_base_addr);
|
||||
// }
|
||||
//#endif
|
||||
}
|
||||
|
||||
void MemoryBase::WriteMMIO32(u32 addr, const u32 data)
|
||||
|
|
|
@ -8,6 +8,8 @@ using std::nullptr_t;
|
|||
#define safe_delete(x) do {delete (x);(x)=nullptr;} while(0)
|
||||
#define safe_free(x) do {free(x);(x)=nullptr;} while(0)
|
||||
|
||||
extern void* const m_base_addr;
|
||||
|
||||
enum MemoryType
|
||||
{
|
||||
Memory_PS3,
|
||||
|
@ -25,7 +27,6 @@ enum : u64
|
|||
|
||||
class MemoryBase
|
||||
{
|
||||
void* m_base_addr;
|
||||
std::vector<MemoryBlock*> MemoryBlocks;
|
||||
u32 m_pages[0x100000000 / 4096]; // information about every page
|
||||
std::recursive_mutex m_mutex;
|
||||
|
@ -44,12 +45,6 @@ public:
|
|||
|
||||
struct Wrapper32LE
|
||||
{
|
||||
private:
|
||||
void* m_base_addr;
|
||||
|
||||
public:
|
||||
Wrapper32LE() : m_base_addr(nullptr) {}
|
||||
|
||||
void Write8(const u32 addr, const u8 data) { *(u8*)((u8*)m_base_addr + addr) = data; }
|
||||
void Write16(const u32 addr, const u16 data) { *(u16*)((u8*)m_base_addr + addr) = data; }
|
||||
void Write32(const u32 addr, const u32 data) { *(u32*)((u8*)m_base_addr + addr) = data; }
|
||||
|
@ -61,8 +56,6 @@ public:
|
|||
u32 Read32(const u32 addr) { return *(u32*)((u8*)m_base_addr + addr); }
|
||||
u64 Read64(const u32 addr) { return *(u64*)((u8*)m_base_addr + addr); }
|
||||
u128 Read128(const u32 addr) { return *(u128*)((u8*)m_base_addr + addr); }
|
||||
|
||||
void Init(void* real_addr) { m_base_addr = real_addr; }
|
||||
};
|
||||
|
||||
struct : Wrapper32LE
|
||||
|
@ -92,7 +85,7 @@ public:
|
|||
Close();
|
||||
}
|
||||
|
||||
void* GetBaseAddr() const
|
||||
static void* const GetBaseAddr()
|
||||
{
|
||||
return m_base_addr;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,20 @@
|
|||
#include "stdafx.h"
|
||||
#include "Memory.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
|
||||
static void* const m_base_addr = VirtualAlloc(nullptr, 0x100000000, MEM_RESERVE, PAGE_NOACCESS);
|
||||
#else
|
||||
#include <sys/mman.h>
|
||||
|
||||
/* OS X uses MAP_ANON instead of MAP_ANONYMOUS */
|
||||
#ifndef MAP_ANONYMOUS
|
||||
#define MAP_ANONYMOUS MAP_ANON
|
||||
#endif
|
||||
|
||||
static void* const m_base_addr = ::mmap(nullptr, 0x100000000, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
|
||||
#endif
|
||||
|
||||
namespace vm
|
||||
{
|
||||
|
@ -28,13 +44,4 @@ namespace vm
|
|||
void unalloc(u32 addr)
|
||||
{
|
||||
}
|
||||
|
||||
u32 read32(u32 addr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void write32(u32 addr, u32 value)
|
||||
{
|
||||
}
|
||||
}
|
|
@ -8,19 +8,126 @@ namespace vm
|
|||
void unalloc(u32 addr);
|
||||
|
||||
template<typename T>
|
||||
T* get_ptr(u32 addr)
|
||||
T* const get_ptr(u32 addr)
|
||||
{
|
||||
return (T*)&Memory[addr];
|
||||
return (T*)((u8*)m_base_addr + addr);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T& get_ref(u32 addr)
|
||||
{
|
||||
return (T&)Memory[addr];
|
||||
return *(T*)((u8*)m_base_addr + addr);
|
||||
}
|
||||
|
||||
u32 read32(u32 addr);
|
||||
void write32(u32 addr, u32 value);
|
||||
static u8 read8(u32 addr)
|
||||
{
|
||||
return *((u8*)m_base_addr + addr);
|
||||
}
|
||||
|
||||
static void write8(u32 addr, u8 value)
|
||||
{
|
||||
*((u8*)m_base_addr + addr) = value;
|
||||
}
|
||||
|
||||
namespace ps3
|
||||
{
|
||||
static u16 read16(u32 addr)
|
||||
{
|
||||
return re16(*(u16*)((u8*)m_base_addr + addr));
|
||||
}
|
||||
|
||||
static void write16(u32 addr, u16 value)
|
||||
{
|
||||
*(u16*)((u8*)m_base_addr + addr) = re16(value);
|
||||
}
|
||||
|
||||
static u32 read32(u32 addr)
|
||||
{
|
||||
if (addr < RAW_SPU_BASE_ADDR || (addr % RAW_SPU_OFFSET) < RAW_SPU_PROB_OFFSET)
|
||||
{
|
||||
return re32(*(u32*)((u8*)m_base_addr + addr));
|
||||
}
|
||||
else
|
||||
{
|
||||
return Memory.ReadMMIO32((u32)addr);
|
||||
}
|
||||
}
|
||||
|
||||
static void write32(u32 addr, u32 value)
|
||||
{
|
||||
if (addr < RAW_SPU_BASE_ADDR || (addr % RAW_SPU_OFFSET) < RAW_SPU_PROB_OFFSET)
|
||||
{
|
||||
*(u32*)((u8*)m_base_addr + addr) = re32(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Memory.WriteMMIO32((u32)addr, value);
|
||||
}
|
||||
}
|
||||
|
||||
static u64 read64(u32 addr)
|
||||
{
|
||||
return re64(*(u64*)((u8*)m_base_addr + addr));
|
||||
}
|
||||
|
||||
static void write64(u32 addr, u64 value)
|
||||
{
|
||||
*(u64*)((u8*)m_base_addr + addr) = re64(value);
|
||||
}
|
||||
|
||||
static u128 read128(u32 addr)
|
||||
{
|
||||
return re128(*(u128*)((u8*)m_base_addr + addr));
|
||||
}
|
||||
|
||||
static void write128(u32 addr, u128 value)
|
||||
{
|
||||
*(u128*)((u8*)m_base_addr + addr) = re128(value);
|
||||
}
|
||||
}
|
||||
|
||||
namespace psv
|
||||
{
|
||||
static u16 read16(u32 addr)
|
||||
{
|
||||
return *(u16*)((u8*)m_base_addr + addr);
|
||||
}
|
||||
|
||||
static void write16(u32 addr, u16 value)
|
||||
{
|
||||
*(u16*)((u8*)m_base_addr + addr) = value;
|
||||
}
|
||||
|
||||
static u32 read32(u32 addr)
|
||||
{
|
||||
return *(u32*)((u8*)m_base_addr + addr);
|
||||
}
|
||||
|
||||
static void write32(u32 addr, u32 value)
|
||||
{
|
||||
*(u32*)((u8*)m_base_addr + addr) = value;
|
||||
}
|
||||
|
||||
static u64 read64(u32 addr)
|
||||
{
|
||||
return *(u64*)((u8*)m_base_addr + addr);
|
||||
}
|
||||
|
||||
static void write64(u32 addr, u64 value)
|
||||
{
|
||||
*(u64*)((u8*)m_base_addr + addr) = value;
|
||||
}
|
||||
|
||||
static u128 read128(u32 addr)
|
||||
{
|
||||
return *(u128*)((u8*)m_base_addr + addr);
|
||||
}
|
||||
|
||||
static void write128(u32 addr, u128 value)
|
||||
{
|
||||
*(u128*)((u8*)m_base_addr + addr) = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "vm_ref.h"
|
||||
|
|
|
@ -98,12 +98,12 @@ namespace vm
|
|||
AT m_addr;
|
||||
|
||||
public:
|
||||
__forceinline T* operator -> ()
|
||||
__forceinline T* const operator -> ()
|
||||
{
|
||||
return vm::get_ptr<T>(m_addr);
|
||||
}
|
||||
|
||||
__forceinline const T* operator -> () const
|
||||
__forceinline const T* const operator -> () const
|
||||
{
|
||||
return vm::get_ptr<const T>(m_addr);
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ namespace vm
|
|||
return m_addr != 0;
|
||||
}
|
||||
|
||||
T* get_ptr() const
|
||||
T* const get_ptr() const
|
||||
{
|
||||
return vm::get_ptr<T>(m_addr);
|
||||
}
|
||||
|
@ -220,7 +220,7 @@ namespace vm
|
|||
return m_addr;
|
||||
}
|
||||
|
||||
void* get_ptr() const
|
||||
void* const get_ptr() const
|
||||
{
|
||||
return vm::get_ptr<void>(m_addr);
|
||||
}
|
||||
|
@ -266,7 +266,7 @@ namespace vm
|
|||
return m_addr;
|
||||
}
|
||||
|
||||
type get_ptr() const
|
||||
type const get_ptr() const
|
||||
{
|
||||
return *((type*)vm::get_ptr<void*>(m_addr));
|
||||
}
|
||||
|
@ -340,7 +340,7 @@ namespace vm
|
|||
return m_addr;
|
||||
}
|
||||
|
||||
type get_ptr() const
|
||||
type const get_ptr() const
|
||||
{
|
||||
return *((type*)vm::get_ptr<void*>(m_addr));
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -341,7 +341,7 @@ void Emulator::Load()
|
|||
thread.SetEntry(l.GetEntry());
|
||||
Memory.StackMem.AllocAlign(0x1000);
|
||||
thread.InitStack();
|
||||
thread.AddArgv(m_elf_path);
|
||||
thread.AddArgv(m_elf_path); // it doesn't work
|
||||
//thread.AddArgv("-emu");
|
||||
|
||||
m_rsx_callback = (u32)Memory.MainMem.AllocAlign(4 * 4) + 4;
|
||||
|
|
Loading…
Add table
Reference in a new issue