mirror of
https://github.com/PabloMK7/citra.git
synced 2024-11-20 14:34:17 +00:00
added functions to map Heap and Shared memory space
This commit is contained in:
parent
66e1f8ab33
commit
b7cd4c9e90
3 changed files with 76 additions and 9 deletions
|
@ -16,15 +16,15 @@ u8* g_base = NULL; ///< The base pointer to the aut
|
|||
|
||||
MemArena g_arena; ///< The MemArena class
|
||||
|
||||
u8* g_heap_gsp = NULL; ///< GSP heap (main memory)
|
||||
u8* g_heap = NULL; ///< Application heap (main memory)
|
||||
u8* g_heap_gsp = NULL; ///< GSP heap (main memory)
|
||||
u8* g_vram = NULL; ///< Video memory (VRAM) pointer
|
||||
|
||||
u8* g_physical_bootrom = NULL; ///< Bootrom physical memory
|
||||
u8* g_uncached_bootrom = NULL;
|
||||
|
||||
u8* g_physical_fcram = NULL; ///< Main physical memory (FCRAM)
|
||||
u8* g_physical_heap_gsp = NULL;
|
||||
u8* g_physical_heap_gsp = NULL; ///< GSP heap physical memory
|
||||
u8* g_physical_vram = NULL; ///< Video physical memory (VRAM)
|
||||
u8* g_physical_scratchpad = NULL; ///< Scratchpad memory used for main thread stack
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ enum {
|
|||
HEAP_GSP_SIZE = 0x02000000, ///< GSP heap size... TODO: Define correctly?
|
||||
HEAP_SIZE = FCRAM_SIZE, ///< Application heap size
|
||||
|
||||
SHARED_MEMORY_VADDR = 0x10000000, ///< Shared memory
|
||||
|
||||
HEAP_PADDR = HEAP_GSP_SIZE,
|
||||
HEAP_PADDR_END = (HEAP_PADDR + HEAP_SIZE),
|
||||
HEAP_VADDR = 0x08000000,
|
||||
|
@ -49,10 +51,11 @@ enum {
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// Represents a block of heap memory mapped by ControlMemory
|
||||
struct HeapBlock {
|
||||
HeapBlock() : base_address(0), address(0), size(0), operation(0), permissions(0) {
|
||||
/// Represents a block of memory mapped by ControlMemory/MapMemoryBlock
|
||||
struct MemoryBlock {
|
||||
MemoryBlock() : handle(0), base_address(0), address(0), size(0), operation(0), permissions(0) {
|
||||
}
|
||||
u32 handle;
|
||||
u32 base_address;
|
||||
u32 address;
|
||||
u32 size;
|
||||
|
@ -98,10 +101,26 @@ void Write32(const u32 addr, const u32 data);
|
|||
|
||||
u8* GetPointer(const u32 Address);
|
||||
|
||||
/**
|
||||
* Maps a block of memory in shared memory
|
||||
* @param handle Handle to map memory block for
|
||||
* @param addr Address to map memory block to
|
||||
* @param permissions Memory map permissions
|
||||
*/
|
||||
u32 MapBlock_Shared(u32 handle, u32 addr,u32 permissions) ;
|
||||
|
||||
/**
|
||||
* Maps a block of memory on the heap
|
||||
* @param size Size of block in bytes
|
||||
* @param operation Memory map operation type
|
||||
* @param flags Memory allocation flags
|
||||
*/
|
||||
u32 MapBlock_Heap(u32 size, u32 operation, u32 permissions);
|
||||
|
||||
/**
|
||||
* Maps a block of memory on the GSP heap
|
||||
* @param size Size of block in bytes
|
||||
* @param operation Control memory operation
|
||||
* @param operation Memory map operation type
|
||||
* @param permissions Control memory permissions
|
||||
*/
|
||||
u32 MapBlock_HeapGSP(u32 size, u32 operation, u32 permissions);
|
||||
|
|
|
@ -12,7 +12,9 @@
|
|||
|
||||
namespace Memory {
|
||||
|
||||
std::map<u32, HeapBlock> g_heap_gsp_map;
|
||||
std::map<u32, MemoryBlock> g_heap_map;
|
||||
std::map<u32, MemoryBlock> g_heap_gsp_map;
|
||||
std::map<u32, MemoryBlock> g_shared_map;
|
||||
|
||||
/// Convert a physical address to virtual address
|
||||
u32 _AddressPhysicalToVirtual(const u32 addr) {
|
||||
|
@ -120,13 +122,59 @@ u8 *GetPointer(const u32 addr) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a block of memory in shared memory
|
||||
* @param handle Handle to map memory block for
|
||||
* @param addr Address to map memory block to
|
||||
* @param permissions Memory map permissions
|
||||
*/
|
||||
u32 MapBlock_Shared(u32 handle, u32 addr,u32 permissions) {
|
||||
MemoryBlock block;
|
||||
|
||||
block.handle = handle;
|
||||
block.base_address = addr;
|
||||
block.permissions = permissions;
|
||||
|
||||
if (g_shared_map.size() > 0) {
|
||||
const MemoryBlock last_block = g_shared_map.rbegin()->second;
|
||||
block.address = last_block.address + last_block.size;
|
||||
}
|
||||
g_shared_map[block.GetVirtualAddress()] = block;
|
||||
|
||||
return block.GetVirtualAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a block of memory on the heap
|
||||
* @param size Size of block in bytes
|
||||
* @param operation Memory map operation type
|
||||
* @param flags Memory allocation flags
|
||||
*/
|
||||
u32 MapBlock_Heap(u32 size, u32 operation, u32 permissions) {
|
||||
MemoryBlock block;
|
||||
|
||||
block.base_address = HEAP_VADDR;
|
||||
block.size = size;
|
||||
block.operation = operation;
|
||||
block.permissions = permissions;
|
||||
|
||||
if (g_heap_map.size() > 0) {
|
||||
const MemoryBlock last_block = g_heap_map.rbegin()->second;
|
||||
block.address = last_block.address + last_block.size;
|
||||
}
|
||||
g_heap_map[block.GetVirtualAddress()] = block;
|
||||
|
||||
return block.GetVirtualAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a block of memory on the GSP heap
|
||||
* @param size Size of block in bytes
|
||||
* @param operation Memory map operation type
|
||||
* @param flags Memory allocation flags
|
||||
*/
|
||||
u32 MapBlock_HeapGSP(u32 size, u32 operation, u32 permissions) {
|
||||
HeapBlock block;
|
||||
MemoryBlock block;
|
||||
|
||||
block.base_address = HEAP_GSP_VADDR;
|
||||
block.size = size;
|
||||
|
@ -134,7 +182,7 @@ u32 MapBlock_HeapGSP(u32 size, u32 operation, u32 permissions) {
|
|||
block.permissions = permissions;
|
||||
|
||||
if (g_heap_gsp_map.size() > 0) {
|
||||
const HeapBlock last_block = g_heap_gsp_map.rbegin()->second;
|
||||
const MemoryBlock last_block = g_heap_gsp_map.rbegin()->second;
|
||||
block.address = last_block.address + last_block.size;
|
||||
}
|
||||
g_heap_gsp_map[block.GetVirtualAddress()] = block;
|
||||
|
|
Loading…
Reference in a new issue