summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/mem_map.cpp4
-rw-r--r--src/core/mem_map.h27
-rw-r--r--src/core/mem_map_funcs.cpp54
3 files changed, 76 insertions, 9 deletions
diff --git a/src/core/mem_map.cpp b/src/core/mem_map.cpp
index 180829239..f0090206e 100644
--- a/src/core/mem_map.cpp
+++ b/src/core/mem_map.cpp
@@ -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
diff --git a/src/core/mem_map.h b/src/core/mem_map.h
index ab1eb2606..5346d04ee 100644
--- a/src/core/mem_map.h
+++ b/src/core/mem_map.h
@@ -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;
@@ -99,9 +102,25 @@ 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);
diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp
index af4cfacbd..eff0cf4b8 100644
--- a/src/core/mem_map_funcs.cpp
+++ b/src/core/mem_map_funcs.cpp
@@ -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) {
@@ -121,12 +123,58 @@ 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;