2012-11-15 00:39:56 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2013-08-26 16:18:59 +02:00
|
|
|
struct MemInfo
|
2012-11-15 00:39:56 +01:00
|
|
|
{
|
2015-02-12 21:10:25 +01:00
|
|
|
u32 addr;
|
2012-11-15 00:39:56 +01:00
|
|
|
u32 size;
|
|
|
|
|
|
2015-02-12 21:10:25 +01:00
|
|
|
MemInfo(u32 addr, u32 size)
|
|
|
|
|
: addr(addr)
|
|
|
|
|
, size(size)
|
2013-08-26 16:18:59 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-12 21:10:25 +01:00
|
|
|
MemInfo()
|
|
|
|
|
: addr(0)
|
|
|
|
|
, size(0)
|
2013-08-26 16:18:59 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-01-17 17:56:03 +01:00
|
|
|
struct VirtualMemInfo : public MemInfo
|
|
|
|
|
{
|
2015-02-12 21:10:25 +01:00
|
|
|
u32 realAddress;
|
2014-01-17 17:56:03 +01:00
|
|
|
|
2015-02-12 21:10:25 +01:00
|
|
|
VirtualMemInfo(u32 addr, u32 realaddr, u32 size)
|
|
|
|
|
: MemInfo(addr, size)
|
|
|
|
|
, realAddress(realaddr)
|
2014-01-17 17:56:03 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VirtualMemInfo()
|
|
|
|
|
: MemInfo(0, 0)
|
|
|
|
|
, realAddress(0)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-07-11 22:44:53 +02:00
|
|
|
class VirtualMemoryBlock
|
2014-01-17 17:56:03 +01:00
|
|
|
{
|
2014-04-10 00:54:32 +02:00
|
|
|
std::vector<VirtualMemInfo> m_mapped_memory;
|
2015-07-11 22:44:53 +02:00
|
|
|
u32 m_reserve_size = 0;
|
|
|
|
|
u32 m_range_start = 0;
|
|
|
|
|
u32 m_range_size = 0;
|
2014-01-17 17:56:03 +01:00
|
|
|
|
|
|
|
|
public:
|
2015-07-11 22:44:53 +02:00
|
|
|
VirtualMemoryBlock() = default;
|
2014-01-17 17:56:03 +01:00
|
|
|
|
2015-07-11 22:44:53 +02:00
|
|
|
VirtualMemoryBlock* SetRange(const u32 start, const u32 size);
|
2015-07-12 13:52:55 +02:00
|
|
|
void Clear() { m_mapped_memory.clear(); m_reserve_size = 0; m_range_start = 0; m_range_size = 0; }
|
2015-07-11 22:44:53 +02:00
|
|
|
u32 GetStartAddr() const { return m_range_start; }
|
|
|
|
|
u32 GetSize() const { return m_range_size; }
|
|
|
|
|
bool IsInMyRange(const u32 addr, const u32 size);
|
2014-01-17 17:56:03 +01:00
|
|
|
|
|
|
|
|
// 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)
|
2015-07-11 22:44:53 +02:00
|
|
|
bool Map(u32 realaddr, u32 size, u32 addr);
|
|
|
|
|
u32 Map(u32 realaddr, u32 size);
|
2014-01-17 17:56:03 +01:00
|
|
|
|
2014-01-21 19:29:16 +01:00
|
|
|
// Unmap real address (please specify only starting point, no midway memory will be unmapped), returns the size of the unmapped area
|
2015-07-11 22:44:53 +02:00
|
|
|
bool UnmapRealAddress(u32 realaddr, u32& size);
|
2014-01-17 17:56:03 +01:00
|
|
|
|
2014-01-21 19:29:16 +01:00
|
|
|
// Unmap address (please specify only starting point, no midway memory will be unmapped), returns the size of the unmapped area
|
2015-07-11 22:44:53 +02:00
|
|
|
bool UnmapAddress(u32 addr, u32& size);
|
2014-01-17 17:56:03 +01:00
|
|
|
|
2014-01-21 18:55:48 +01:00
|
|
|
// Reserve a certain amount so no one can use it, returns true on succces, false on failure
|
2015-07-11 22:44:53 +02:00
|
|
|
bool Reserve(u32 size);
|
2014-01-21 18:55:48 +01:00
|
|
|
|
|
|
|
|
// Unreserve a certain amount of bytes, returns true on succcess, false if size is bigger than the reserved amount
|
2015-07-11 22:44:53 +02:00
|
|
|
bool Unreserve(u32 size);
|
2014-01-21 18:55:48 +01:00
|
|
|
|
|
|
|
|
// Return the total amount of reserved memory
|
2015-07-11 22:44:53 +02:00
|
|
|
u32 GetReservedAmount();
|
2014-01-21 18:55:48 +01:00
|
|
|
|
2015-02-12 21:10:25 +01:00
|
|
|
bool Read32(const u32 addr, u32* value);
|
2014-08-30 19:51:00 +02:00
|
|
|
|
2015-02-12 21:10:25 +01:00
|
|
|
bool Write32(const u32 addr, const u32 value);
|
2014-01-17 17:56:03 +01:00
|
|
|
|
2014-05-19 08:12:28 +02:00
|
|
|
// try to get the real address given a mapped address
|
|
|
|
|
// return true for success
|
2015-02-12 21:10:25 +01:00
|
|
|
bool getRealAddr(u32 addr, u32& result);
|
2014-01-18 22:36:22 +01:00
|
|
|
|
2015-02-12 21:10:25 +01:00
|
|
|
u32 RealAddr(u32 addr)
|
2014-07-07 01:36:07 +02:00
|
|
|
{
|
2015-02-12 21:10:25 +01:00
|
|
|
u32 realAddr = 0;
|
2014-07-07 01:36:07 +02:00
|
|
|
getRealAddr(addr, realAddr);
|
|
|
|
|
return realAddr;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-18 22:36:22 +01:00
|
|
|
// return the mapped address given a real address, if not mapped return 0
|
2015-02-12 21:10:25 +01:00
|
|
|
u32 getMappedAddress(u32 realAddress);
|
2014-01-17 17:56:03 +01:00
|
|
|
};
|