1
0
Fork 0

added functions to map Heap and Shared memory space

This commit is contained in:
bunnei 2014-04-24 22:32:26 -04:00
parent 66e1f8ab33
commit b7cd4c9e90
3 changed files with 76 additions and 9 deletions

View File

@ -16,15 +16,15 @@ u8* g_base = NULL; ///< The base pointer to the aut
MemArena g_arena; ///< The MemArena class 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 = NULL; ///< Application heap (main memory)
u8* g_heap_gsp = NULL; ///< GSP heap (main memory)
u8* g_vram = NULL; ///< Video memory (VRAM) pointer u8* g_vram = NULL; ///< Video memory (VRAM) pointer
u8* g_physical_bootrom = NULL; ///< Bootrom physical memory u8* g_physical_bootrom = NULL; ///< Bootrom physical memory
u8* g_uncached_bootrom = NULL; u8* g_uncached_bootrom = NULL;
u8* g_physical_fcram = NULL; ///< Main physical memory (FCRAM) 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_vram = NULL; ///< Video physical memory (VRAM)
u8* g_physical_scratchpad = NULL; ///< Scratchpad memory used for main thread stack u8* g_physical_scratchpad = NULL; ///< Scratchpad memory used for main thread stack

View File

@ -22,6 +22,8 @@ enum {
HEAP_GSP_SIZE = 0x02000000, ///< GSP heap size... TODO: Define correctly? HEAP_GSP_SIZE = 0x02000000, ///< GSP heap size... TODO: Define correctly?
HEAP_SIZE = FCRAM_SIZE, ///< Application heap size HEAP_SIZE = FCRAM_SIZE, ///< Application heap size
SHARED_MEMORY_VADDR = 0x10000000, ///< Shared memory
HEAP_PADDR = HEAP_GSP_SIZE, HEAP_PADDR = HEAP_GSP_SIZE,
HEAP_PADDR_END = (HEAP_PADDR + HEAP_SIZE), HEAP_PADDR_END = (HEAP_PADDR + HEAP_SIZE),
HEAP_VADDR = 0x08000000, HEAP_VADDR = 0x08000000,
@ -49,10 +51,11 @@ enum {
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
/// Represents a block of heap memory mapped by ControlMemory /// Represents a block of memory mapped by ControlMemory/MapMemoryBlock
struct HeapBlock { struct MemoryBlock {
HeapBlock() : base_address(0), address(0), size(0), operation(0), permissions(0) { MemoryBlock() : handle(0), base_address(0), address(0), size(0), operation(0), permissions(0) {
} }
u32 handle;
u32 base_address; u32 base_address;
u32 address; u32 address;
u32 size; u32 size;
@ -98,10 +101,26 @@ void Write32(const u32 addr, const u32 data);
u8* GetPointer(const u32 Address); 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 * Maps a block of memory on the GSP heap
* @param size Size of block in bytes * @param size Size of block in bytes
* @param operation Control memory operation * @param operation Memory map operation type
* @param permissions Control memory permissions * @param permissions Control memory permissions
*/ */
u32 MapBlock_HeapGSP(u32 size, u32 operation, u32 permissions); u32 MapBlock_HeapGSP(u32 size, u32 operation, u32 permissions);

View File

@ -12,7 +12,9 @@
namespace Memory { 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 /// Convert a physical address to virtual address
u32 _AddressPhysicalToVirtual(const u32 addr) { 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 * Maps a block of memory on the GSP heap
* @param size Size of block in bytes * @param size Size of block in bytes
* @param operation Memory map operation type
* @param flags Memory allocation flags * @param flags Memory allocation flags
*/ */
u32 MapBlock_HeapGSP(u32 size, u32 operation, u32 permissions) { u32 MapBlock_HeapGSP(u32 size, u32 operation, u32 permissions) {
HeapBlock block; MemoryBlock block;
block.base_address = HEAP_GSP_VADDR; block.base_address = HEAP_GSP_VADDR;
block.size = size; block.size = size;
@ -134,7 +182,7 @@ u32 MapBlock_HeapGSP(u32 size, u32 operation, u32 permissions) {
block.permissions = permissions; block.permissions = permissions;
if (g_heap_gsp_map.size() > 0) { 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; block.address = last_block.address + last_block.size;
} }
g_heap_gsp_map[block.GetVirtualAddress()] = block; g_heap_gsp_map[block.GetVirtualAddress()] = block;