2012-11-15 01:39:56 +02:00
|
|
|
#pragma once
|
2014-07-08 21:18:12 +04:00
|
|
|
|
2012-11-15 01:39:56 +02:00
|
|
|
#include "MemoryBlock.h"
|
|
|
|
|
|
2014-04-10 00:54:32 +02:00
|
|
|
using std::nullptr_t;
|
|
|
|
|
|
2014-07-11 00:16:19 +10:00
|
|
|
#define safe_delete(x) do {delete (x);(x)=nullptr;} while(0)
|
|
|
|
|
#define safe_free(x) do {free(x);(x)=nullptr;} while(0)
|
|
|
|
|
|
2013-11-03 21:23:16 +02:00
|
|
|
enum MemoryType
|
|
|
|
|
{
|
|
|
|
|
Memory_PS3,
|
2013-11-05 20:12:18 +02:00
|
|
|
Memory_PSV,
|
|
|
|
|
Memory_PSP,
|
2013-11-03 21:23:16 +02:00
|
|
|
};
|
|
|
|
|
|
2012-11-15 01:39:56 +02:00
|
|
|
class MemoryBase
|
|
|
|
|
{
|
2014-07-07 21:22:36 +04:00
|
|
|
std::vector<MemoryBlock*> MemoryBlocks;
|
2012-11-15 01:39:56 +02:00
|
|
|
|
|
|
|
|
public:
|
2013-11-05 20:12:18 +02:00
|
|
|
MemoryBlock* UserMemory;
|
2012-11-15 01:39:56 +02:00
|
|
|
|
|
|
|
|
DynamicMemoryBlock MainMem;
|
2015-02-13 17:04:03 +03:00
|
|
|
DynamicMemoryBlock Userspace;
|
2012-11-15 01:39:56 +02:00
|
|
|
DynamicMemoryBlock RSXFBMem;
|
|
|
|
|
DynamicMemoryBlock StackMem;
|
2014-01-17 18:56:03 +02:00
|
|
|
VirtualMemoryBlock RSXIOMem;
|
2012-11-15 01:39:56 +02:00
|
|
|
|
2014-09-06 17:33:01 +04:00
|
|
|
struct
|
2013-11-05 20:12:18 +02:00
|
|
|
{
|
2014-09-03 01:48:44 +04:00
|
|
|
DynamicMemoryBlock RAM;
|
|
|
|
|
DynamicMemoryBlock Userspace;
|
2014-07-13 16:26:38 +04:00
|
|
|
} PSV;
|
2013-11-05 20:12:18 +02:00
|
|
|
|
2014-09-06 17:33:01 +04:00
|
|
|
struct
|
2013-11-05 20:12:18 +02:00
|
|
|
{
|
2014-09-03 01:48:44 +04:00
|
|
|
DynamicMemoryBlock Scratchpad;
|
|
|
|
|
DynamicMemoryBlock VRAM;
|
|
|
|
|
DynamicMemoryBlock RAM;
|
|
|
|
|
DynamicMemoryBlock Kernel;
|
|
|
|
|
DynamicMemoryBlock Userspace;
|
2014-07-13 16:26:38 +04:00
|
|
|
} PSP;
|
2013-11-05 20:12:18 +02:00
|
|
|
|
2012-11-15 01:39:56 +02:00
|
|
|
bool m_inited;
|
|
|
|
|
|
|
|
|
|
MemoryBase()
|
|
|
|
|
{
|
|
|
|
|
m_inited = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~MemoryBase()
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-12 23:10:25 +03:00
|
|
|
void RegisterPages(u32 addr, u32 size);
|
2014-07-09 03:04:36 +04:00
|
|
|
|
2015-02-12 23:10:25 +03:00
|
|
|
void UnregisterPages(u32 addr, u32 size);
|
2014-07-08 18:26:49 +04:00
|
|
|
|
2014-08-22 18:21:55 +04:00
|
|
|
void Init(MemoryType type);
|
2012-11-15 01:39:56 +02:00
|
|
|
|
2014-08-22 18:21:55 +04:00
|
|
|
void Close();
|
2012-11-15 01:39:56 +02:00
|
|
|
|
|
|
|
|
u32 GetUserMemTotalSize()
|
|
|
|
|
{
|
2013-11-05 20:12:18 +02:00
|
|
|
return UserMemory->GetSize();
|
2012-11-15 01:39:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u32 GetUserMemAvailSize()
|
|
|
|
|
{
|
2013-11-05 20:12:18 +02:00
|
|
|
return UserMemory->GetSize() - UserMemory->GetUsedSize();
|
2012-11-15 01:39:56 +02:00
|
|
|
}
|
|
|
|
|
|
2015-02-12 23:10:25 +03:00
|
|
|
u32 Alloc(const u32 size, const u32 align)
|
2012-11-15 01:39:56 +02:00
|
|
|
{
|
2014-02-02 23:49:10 +04:00
|
|
|
return UserMemory->AllocAlign(size, align);
|
2012-11-15 01:39:56 +02:00
|
|
|
}
|
|
|
|
|
|
2015-02-12 23:10:25 +03:00
|
|
|
bool Free(const u32 addr)
|
2012-11-15 01:39:56 +02:00
|
|
|
{
|
2013-11-05 20:12:18 +02:00
|
|
|
return UserMemory->Free(addr);
|
2012-11-15 01:39:56 +02:00
|
|
|
}
|
|
|
|
|
|
2015-02-12 23:10:25 +03:00
|
|
|
bool Map(const u32 addr, const u32 size);
|
2014-07-07 21:22:36 +04:00
|
|
|
|
2015-02-12 23:10:25 +03:00
|
|
|
bool Unmap(const u32 addr);
|
2012-11-15 01:39:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
extern MemoryBase Memory;
|
|
|
|
|
|
2014-07-31 19:08:02 +03:00
|
|
|
#include "vm.h"
|