From 5d95bb98434b8e7cd67010f6064ccdb69c1222bb Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 10 Apr 2014 22:45:40 -0400 Subject: cleaned up some logging messages --- src/core/mem_map_funcs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/mem_map_funcs.cpp') diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index 4c0e08b3f..00719445f 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -40,7 +40,7 @@ inline void _Read(T &var, const u32 addr) { var = *((const T*)&g_fcram[addr & MEM_FCRAM_MASK]); } else { - _assert_msg_(MEMMAP, false, "unknown memory read"); + _assert_msg_(MEMMAP, false, "unknown memory read @ 0x%08X", addr); } } -- cgit v1.2.3 From 68e198476f17a026fed88f3c9a271aa768694354 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 12 Apr 2014 21:55:36 -0400 Subject: - added HLE to connect to "srv:" service - added a manager for keeping track of services/ports - added a memory mapped region for memory accessed by HLE - added HLE for GetThreadCommandBuffer function --- src/core/mem_map_funcs.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/core/mem_map_funcs.cpp') diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index 00719445f..f35e25caf 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -6,6 +6,7 @@ #include "core/mem_map.h" #include "core/hw/hw.h" +#include "hle/hle.h" namespace Memory { @@ -15,9 +16,16 @@ inline void _Read(T &var, const u32 addr) { // TODO: Make sure this represents the mirrors in a correct way. // Could just do a base-relative read, too.... TODO + + // Memory allocated for HLE use that can be addressed from the emulated application + // The primary use of this is sharing a commandbuffer between the HLE OS (syscore) and the LLE + // core running the user application (appcore) + if (addr >= MEM_OSHLE_VADDR && addr < MEM_OSHLE_VADDR_END) { + NOTICE_LOG(MEMMAP, "OSHLE read @ 0x%08X", addr); + // Hardware I/O register reads // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space - if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) { + } else if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) { HW::Read(var, addr); // FCRAM virtual address reads @@ -47,9 +55,15 @@ inline void _Read(T &var, const u32 addr) { template inline void _Write(u32 addr, const T data) { + // Memory allocated for HLE use that can be addressed from the emulated application + // The primary use of this is sharing a commandbuffer between the HLE OS (syscore) and the LLE + // core running the user application (appcore) + if (addr >= MEM_OSHLE_VADDR && addr < MEM_OSHLE_VADDR_END) { + NOTICE_LOG(MEMMAP, "OSHLE write @ 0x%08X", addr); + // Hardware I/O register writes // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space - if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) { + } else if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) { HW::Write(addr, data); // ExeFS:/.code is loaded here: -- cgit v1.2.3 From 6f6d5158de18a7ca134406d55446c27f6db48a1a Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 12 Apr 2014 23:31:39 -0400 Subject: added OS memory read/write for thread command buffer --- src/core/mem_map_funcs.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/core/mem_map_funcs.cpp') diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index f35e25caf..184296287 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -20,8 +20,8 @@ inline void _Read(T &var, const u32 addr) { // Memory allocated for HLE use that can be addressed from the emulated application // The primary use of this is sharing a commandbuffer between the HLE OS (syscore) and the LLE // core running the user application (appcore) - if (addr >= MEM_OSHLE_VADDR && addr < MEM_OSHLE_VADDR_END) { - NOTICE_LOG(MEMMAP, "OSHLE read @ 0x%08X", addr); + if (addr >= HLE::CMD_BUFFER_ADDR && addr < HLE::CMD_BUFFER_ADDR_END) { + HLE::Read(var, addr); // Hardware I/O register reads // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space @@ -58,13 +58,13 @@ inline void _Write(u32 addr, const T data) { // Memory allocated for HLE use that can be addressed from the emulated application // The primary use of this is sharing a commandbuffer between the HLE OS (syscore) and the LLE // core running the user application (appcore) - if (addr >= MEM_OSHLE_VADDR && addr < MEM_OSHLE_VADDR_END) { - NOTICE_LOG(MEMMAP, "OSHLE write @ 0x%08X", addr); + if (addr >= HLE::CMD_BUFFER_ADDR && addr < HLE::CMD_BUFFER_ADDR_END) { + HLE::Write(addr, data); // Hardware I/O register writes // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space } else if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) { - HW::Write(addr, data); + HW::Write(addr, data); // ExeFS:/.code is loaded here: } else if ((addr & 0xFFF00000) == 0x00100000) { -- cgit v1.2.3 From 795d6bf5b7cd822f70213a9024c67efedde8d6a1 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 16 Apr 2014 21:21:53 -0400 Subject: changed unknown memory read/write to report the size --- src/core/mem_map_funcs.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/core/mem_map_funcs.cpp') diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index 184296287..3e85a119f 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -48,7 +48,7 @@ inline void _Read(T &var, const u32 addr) { var = *((const T*)&g_fcram[addr & MEM_FCRAM_MASK]); } else { - _assert_msg_(MEMMAP, false, "unknown memory read @ 0x%08X", addr); + _assert_msg_(MEMMAP, false, "unknown Read%d @ 0x%08X", sizeof(var) * 8, addr); } } @@ -109,7 +109,8 @@ inline void _Write(u32 addr, const T data) { // Error out... } else { - _assert_msg_(MEMMAP, false, "unknown memory write"); + _assert_msg_(MEMMAP, false, "unknown Write%d 0x%08X @ 0x%08X", sizeof(data) * 8, + data, addr); } } -- cgit v1.2.3 From ae99574b6dd2f21960bd42e0bb9a1978e18413d4 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 17 Apr 2014 18:40:42 -0400 Subject: cleaned up memory interfaces a lot, removed some hackish stuff --- src/core/mem_map_funcs.cpp | 144 +++++++++++++++------------------------------ 1 file changed, 48 insertions(+), 96 deletions(-) (limited to 'src/core/mem_map_funcs.cpp') diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index 3e85a119f..bb83855fe 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -10,154 +10,106 @@ namespace Memory { +/// Convert a physical address to virtual address +u32 _AddressPhysicalToVirtual(const u32 addr) { + // Our memory interface read/write functions assume virtual addresses. Put any physical address + // to virtual address translations here. This is obviously quite hacky... But we're not doing + // any MMU emulation yet or anything + if (((addr & 0xF0000000) == MEM_FCRAM_PADDR) && (addr < (MEM_FCRAM_PADDR_END))) { + return (addr & MEM_FCRAM_MASK) | MEM_FCRAM_VADDR; + } + return addr; +} + template inline void _Read(T &var, const u32 addr) { // TODO: Figure out the fastest order of tests for both read and write (they are probably different). // TODO: Make sure this represents the mirrors in a correct way. // Could just do a base-relative read, too.... TODO + const u32 vaddr = _AddressPhysicalToVirtual(addr); // Memory allocated for HLE use that can be addressed from the emulated application // The primary use of this is sharing a commandbuffer between the HLE OS (syscore) and the LLE // core running the user application (appcore) - if (addr >= HLE::CMD_BUFFER_ADDR && addr < HLE::CMD_BUFFER_ADDR_END) { - HLE::Read(var, addr); + if (vaddr >= HLE::CMD_BUFFER_ADDR && vaddr < HLE::CMD_BUFFER_ADDR_END) { + HLE::Read(var, vaddr); // Hardware I/O register reads // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space - } else if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) { - HW::Read(var, addr); - - // FCRAM virtual address reads - } else if ((addr & 0x3E000000) == 0x08000000) { - var = *((const T*)&g_fcram[addr & MEM_FCRAM_MASK]); - - // Scratchpad memory - } else if (addr > MEM_SCRATCHPAD_VADDR && addr <= (MEM_SCRATCHPAD_VADDR + MEM_SCRATCHPAD_SIZE)) { - var = *((const T*)&g_scratchpad[addr & MEM_SCRATCHPAD_MASK]); - - /*else if ((addr & 0x3F800000) == 0x04000000) { - var = *((const T*)&m_pVRAM[addr & VRAM_MASK]); - }*/ - - // HACK(bunnei): There is no layer yet to translate virtual addresses to physical addresses. - // Until we progress far enough along, we'll accept all physical address reads here. I think - // that this is typically a corner-case from usermode software unless they are trying to do - // bare-metal things (e.g. early 3DS homebrew writes directly to the FB @ 0x20184E60, etc. - } else if (((addr & 0xF0000000) == MEM_FCRAM_PADDR) && (addr < (MEM_FCRAM_PADDR_END))) { - var = *((const T*)&g_fcram[addr & MEM_FCRAM_MASK]); + } else if ((vaddr & 0xFF000000) == 0x10000000 || (vaddr & 0xFF000000) == 0x1E000000) { + HW::Read(var, vaddr); + + // FCRAM + } else if ((vaddr > MEM_FCRAM_VADDR) && (vaddr < MEM_FCRAM_VADDR_END)) { + var = *((const T*)&g_fcram[vaddr & MEM_FCRAM_MASK]); + + /*else if ((vaddr & 0x3F800000) == 0x04000000) { + var = *((const T*)&m_pVRAM[vaddr & VRAM_MASK]);*/ } else { - _assert_msg_(MEMMAP, false, "unknown Read%d @ 0x%08X", sizeof(var) * 8, addr); + _assert_msg_(MEMMAP, false, "unknown Read%d @ 0x%08X", sizeof(var) * 8, vaddr); } } template inline void _Write(u32 addr, const T data) { + u32 vaddr = _AddressPhysicalToVirtual(addr); // Memory allocated for HLE use that can be addressed from the emulated application // The primary use of this is sharing a commandbuffer between the HLE OS (syscore) and the LLE // core running the user application (appcore) - if (addr >= HLE::CMD_BUFFER_ADDR && addr < HLE::CMD_BUFFER_ADDR_END) { - HLE::Write(addr, data); + if (vaddr >= HLE::CMD_BUFFER_ADDR && vaddr < HLE::CMD_BUFFER_ADDR_END) { + HLE::Write(vaddr, data); // Hardware I/O register writes // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space - } else if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) { - HW::Write(addr, data); + } else if ((vaddr & 0xFF000000) == 0x10000000 || (vaddr & 0xFF000000) == 0x1E000000) { + HW::Write(vaddr, data); // ExeFS:/.code is loaded here: - } else if ((addr & 0xFFF00000) == 0x00100000) { + } else if ((vaddr & 0xFFF00000) == 0x00100000) { // TODO(ShizZy): This is dumb... handle correctly. From 3DBrew: // http://3dbrew.org/wiki/Memory_layout#ARM11_User-land_memory_regions // The ExeFS:/.code is loaded here, executables must be loaded to the 0x00100000 region when // the exheader "special memory" flag is clear. The 0x03F00000-byte size restriction only // applies when this flag is clear. Executables are usually loaded to 0x14000000 when the // exheader "special memory" flag is set, however this address can be arbitrary. - *(T*)&g_fcram[addr & MEM_FCRAM_MASK] = data; - - // Scratchpad memory - } else if (addr > MEM_SCRATCHPAD_VADDR && addr <= (MEM_SCRATCHPAD_VADDR + MEM_SCRATCHPAD_SIZE)) { - *(T*)&g_scratchpad[addr & MEM_SCRATCHPAD_MASK] = data; + *(T*)&g_fcram[vaddr & MEM_FCRAM_MASK] = data; - // Heap mapped by ControlMemory: - } else if ((addr & 0x3E000000) == 0x08000000) { - // TODO(ShizZy): Writes to this virtual address should be put in physical memory at FCRAM + GSP - // heap size... the following is writing to FCRAM + 0, which is actually supposed to be the - // application's GSP heap - *(T*)&g_fcram[addr & MEM_FCRAM_MASK] = data; + // FCRAM + } else if ((vaddr > MEM_FCRAM_VADDR) && (vaddr < MEM_FCRAM_VADDR_END)) { + *(T*)&g_fcram[vaddr & MEM_FCRAM_MASK] = data; - } else if ((addr & 0xFF000000) == 0x14000000) { + } else if ((vaddr & 0xFF000000) == 0x14000000) { _assert_msg_(MEMMAP, false, "umimplemented write to GSP heap"); - } else if ((addr & 0xFFF00000) == 0x1EC00000) { + } else if ((vaddr & 0xFFF00000) == 0x1EC00000) { _assert_msg_(MEMMAP, false, "umimplemented write to IO registers"); - } else if ((addr & 0xFF000000) == 0x1F000000) { + } else if ((vaddr & 0xFF000000) == 0x1F000000) { _assert_msg_(MEMMAP, false, "umimplemented write to VRAM"); - } else if ((addr & 0xFFF00000) == 0x1FF00000) { + } else if ((vaddr & 0xFFF00000) == 0x1FF00000) { _assert_msg_(MEMMAP, false, "umimplemented write to DSP memory"); - } else if ((addr & 0xFFFF0000) == 0x1FF80000) { + } else if ((vaddr & 0xFFFF0000) == 0x1FF80000) { _assert_msg_(MEMMAP, false, "umimplemented write to Configuration Memory"); - } else if ((addr & 0xFFFFF000) == 0x1FF81000) { + } else if ((vaddr & 0xFFFFF000) == 0x1FF81000) { _assert_msg_(MEMMAP, false, "umimplemented write to shared page"); - // HACK(bunnei): There is no layer yet to translate virtual addresses to physical addresses. - // Until we progress far enough along, we'll accept all physical address writes here. I think - // that this is typically a corner-case from usermode software unless they are trying to do - // bare-metal things (e.g. early 3DS homebrew writes directly to the FB @ 0x20184E60, etc. - } else if (((addr & 0xF0000000) == MEM_FCRAM_PADDR) && (addr < (MEM_FCRAM_PADDR_END))) { - *(T*)&g_fcram[addr & MEM_FCRAM_MASK] = data; - // Error out... } else { _assert_msg_(MEMMAP, false, "unknown Write%d 0x%08X @ 0x%08X", sizeof(data) * 8, - data, addr); - } -} - -bool IsValidAddress(const u32 addr) { - if ((addr & 0x3E000000) == 0x08000000) { - return true; - } else if ((addr & 0x3F800000) == 0x04000000) { - return true; - } else if ((addr & 0xBFFF0000) == 0x00010000) { - return true; - } else if ((addr & 0x3F000000) >= 0x08000000 && (addr & 0x3F000000) < 0x08000000 + MEM_FCRAM_MASK) { - return true; - } else { - return false; + data, vaddr); } } u8 *GetPointer(const u32 addr) { - // TODO(bunnei): Just a stub for now... ImplementMe! - if ((addr & 0x3E000000) == 0x08000000) { - return g_fcram + (addr & MEM_FCRAM_MASK); - - // HACK(bunnei): There is no layer yet to translate virtual addresses to physical addresses. - // Until we progress far enough along, we'll accept all physical address reads here. I think - // that this is typically a corner-case from usermode software unless they are trying to do - // bare-metal things (e.g. early 3DS homebrew writes directly to the FB @ 0x20184E60, etc. - } else if (((addr & 0xF0000000) == MEM_FCRAM_PADDR) && (addr < (MEM_FCRAM_PADDR_END))) { - return g_fcram + (addr & MEM_FCRAM_MASK); - - //else if ((addr & 0x3F800000) == 0x04000000) { - // return g_vram + (addr & MEM_VRAM_MASK); - //} - //else if ((addr & 0x3F000000) >= 0x08000000 && (addr & 0x3F000000) < 0x08000000 + g_MemorySize) { - // return m_pRAM + (addr & g_MemoryMask); - //} + const u32 vaddr = _AddressPhysicalToVirtual(addr); + + // FCRAM + if ((vaddr > MEM_FCRAM_VADDR) && (vaddr < MEM_FCRAM_VADDR_END)) { + return g_fcram + (vaddr & MEM_FCRAM_MASK); + } else { - //ERROR_LOG(MEMMAP, "Unknown GetPointer %08x PC %08x LR %08x", addr, currentMIPS->pc, currentMIPS->r[MIPS_REG_RA]); - ERROR_LOG(MEMMAP, "Unknown GetPointer %08x", addr); - static bool reported = false; - //if (!reported) { - // Reporting::ReportMessage("Unknown GetPointer %08x PC %08x LR %08x", addr, currentMIPS->pc, currentMIPS->r[MIPS_REG_RA]); - // reported = true; - //} - //if (!g_Config.bIgnoreBadMemAccess) { - // Core_EnableStepping(true); - // host->SetDebugMode(true); - //} + ERROR_LOG(MEMMAP, "Unknown GetPointer @ 0x%08x", vaddr); return 0; } } -- cgit v1.2.3 From 09ffe87360f39a76b084fe1c9bac2330d6f6f790 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 17 Apr 2014 21:05:34 -0400 Subject: more various refactors to memory interface --- src/core/mem_map_funcs.cpp | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) (limited to 'src/core/mem_map_funcs.cpp') diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index bb83855fe..40d9dab3a 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -15,8 +15,8 @@ u32 _AddressPhysicalToVirtual(const u32 addr) { // Our memory interface read/write functions assume virtual addresses. Put any physical address // to virtual address translations here. This is obviously quite hacky... But we're not doing // any MMU emulation yet or anything - if (((addr & 0xF0000000) == MEM_FCRAM_PADDR) && (addr < (MEM_FCRAM_PADDR_END))) { - return (addr & MEM_FCRAM_MASK) | MEM_FCRAM_VADDR; + if ((addr >= FCRAM_PADDR) && (addr < (FCRAM_PADDR_END))) { + return (addr & FCRAM_MASK) | FCRAM_VADDR; } return addr; } @@ -40,15 +40,15 @@ inline void _Read(T &var, const u32 addr) { } else if ((vaddr & 0xFF000000) == 0x10000000 || (vaddr & 0xFF000000) == 0x1E000000) { HW::Read(var, vaddr); - // FCRAM - } else if ((vaddr > MEM_FCRAM_VADDR) && (vaddr < MEM_FCRAM_VADDR_END)) { - var = *((const T*)&g_fcram[vaddr & MEM_FCRAM_MASK]); + // FCRAM - application heap + } else if ((vaddr > HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { + var = *((const T*)&g_heap[vaddr & HEAP_MASK]); /*else if ((vaddr & 0x3F800000) == 0x04000000) { var = *((const T*)&m_pVRAM[vaddr & VRAM_MASK]);*/ } else { - _assert_msg_(MEMMAP, false, "unknown Read%d @ 0x%08X", sizeof(var) * 8, vaddr); + //_assert_msg_(MEMMAP, false, "unknown Read%d @ 0x%08X", sizeof(var) * 8, vaddr); } } @@ -66,20 +66,14 @@ inline void _Write(u32 addr, const T data) { // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space } else if ((vaddr & 0xFF000000) == 0x10000000 || (vaddr & 0xFF000000) == 0x1E000000) { HW::Write(vaddr, data); - - // ExeFS:/.code is loaded here: - } else if ((vaddr & 0xFFF00000) == 0x00100000) { - // TODO(ShizZy): This is dumb... handle correctly. From 3DBrew: - // http://3dbrew.org/wiki/Memory_layout#ARM11_User-land_memory_regions - // The ExeFS:/.code is loaded here, executables must be loaded to the 0x00100000 region when - // the exheader "special memory" flag is clear. The 0x03F00000-byte size restriction only - // applies when this flag is clear. Executables are usually loaded to 0x14000000 when the - // exheader "special memory" flag is set, however this address can be arbitrary. - *(T*)&g_fcram[vaddr & MEM_FCRAM_MASK] = data; - - // FCRAM - } else if ((vaddr > MEM_FCRAM_VADDR) && (vaddr < MEM_FCRAM_VADDR_END)) { - *(T*)&g_fcram[vaddr & MEM_FCRAM_MASK] = data; + + // FCRAM - GSP heap + //} else if ((vaddr > HEAP_GSP_VADDR) && (vaddr < HEAP_VADDR_GSP_END)) { + // *(T*)&g_heap_gsp[vaddr & FCRAM_MASK] = data; + + // FCRAM - application heap + } else if ((vaddr > HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { + *(T*)&g_heap[vaddr & HEAP_MASK] = data; } else if ((vaddr & 0xFF000000) == 0x14000000) { _assert_msg_(MEMMAP, false, "umimplemented write to GSP heap"); @@ -104,9 +98,9 @@ inline void _Write(u32 addr, const T data) { u8 *GetPointer(const u32 addr) { const u32 vaddr = _AddressPhysicalToVirtual(addr); - // FCRAM - if ((vaddr > MEM_FCRAM_VADDR) && (vaddr < MEM_FCRAM_VADDR_END)) { - return g_fcram + (vaddr & MEM_FCRAM_MASK); + // FCRAM - application heap + if ((vaddr > HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { + return g_heap + (vaddr & HEAP_MASK); } else { ERROR_LOG(MEMMAP, "Unknown GetPointer @ 0x%08x", vaddr); -- cgit v1.2.3 From a9dba388eba586691724187fe53b385cc0bf23aa Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 17 Apr 2014 21:15:40 -0400 Subject: added memory read/write to GSP heap --- src/core/mem_map_funcs.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/core/mem_map_funcs.cpp') diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index 40d9dab3a..5ab1b6e92 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -40,6 +40,10 @@ inline void _Read(T &var, const u32 addr) { } else if ((vaddr & 0xFF000000) == 0x10000000 || (vaddr & 0xFF000000) == 0x1E000000) { HW::Read(var, vaddr); + // FCRAM - GSP heap + } else if ((vaddr > HEAP_GSP_VADDR) && (vaddr < HEAP_GSP_VADDR_END)) { + var = *((const T*)&g_heap_gsp[vaddr & HEAP_GSP_MASK]); + // FCRAM - application heap } else if ((vaddr > HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { var = *((const T*)&g_heap[vaddr & HEAP_MASK]); @@ -68,8 +72,8 @@ inline void _Write(u32 addr, const T data) { HW::Write(vaddr, data); // FCRAM - GSP heap - //} else if ((vaddr > HEAP_GSP_VADDR) && (vaddr < HEAP_VADDR_GSP_END)) { - // *(T*)&g_heap_gsp[vaddr & FCRAM_MASK] = data; + } else if ((vaddr > HEAP_GSP_VADDR) && (vaddr < HEAP_GSP_VADDR_END)) { + *(T*)&g_heap_gsp[vaddr & HEAP_GSP_MASK] = data; // FCRAM - application heap } else if ((vaddr > HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { @@ -98,8 +102,12 @@ inline void _Write(u32 addr, const T data) { u8 *GetPointer(const u32 addr) { const u32 vaddr = _AddressPhysicalToVirtual(addr); + // FCRAM - GSP heap + if ((vaddr > HEAP_GSP_VADDR) && (vaddr < HEAP_GSP_VADDR_END)) { + return g_heap_gsp + (vaddr & HEAP_GSP_MASK); + // FCRAM - application heap - if ((vaddr > HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { + } else if ((vaddr > HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { return g_heap + (vaddr & HEAP_MASK); } else { -- cgit v1.2.3 From 33e7d97d462b95a781a507fc9e3c59c6de063d91 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 17 Apr 2014 21:40:42 -0400 Subject: fixed bug in Memory::GetPointer --- src/core/mem_map_funcs.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core/mem_map_funcs.cpp') diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index 5ab1b6e92..8e97ef111 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -103,11 +103,11 @@ u8 *GetPointer(const u32 addr) { const u32 vaddr = _AddressPhysicalToVirtual(addr); // FCRAM - GSP heap - if ((vaddr > HEAP_GSP_VADDR) && (vaddr < HEAP_GSP_VADDR_END)) { + if ((vaddr >= HEAP_GSP_VADDR) && (vaddr < HEAP_GSP_VADDR_END)) { return g_heap_gsp + (vaddr & HEAP_GSP_MASK); // FCRAM - application heap - } else if ((vaddr > HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { + } else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { return g_heap + (vaddr & HEAP_MASK); } else { -- cgit v1.2.3 From b2baafaf8ba760ce2b975391fd04db52ad386e29 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 17 Apr 2014 23:05:31 -0400 Subject: added GSP heap memory allocation --- src/core/mem_map_funcs.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/core/mem_map_funcs.cpp') diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index 8e97ef111..af4cfacbd 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2 // Refer to the license.txt file included. +#include + #include "common/common.h" #include "core/mem_map.h" @@ -10,6 +12,8 @@ namespace Memory { +std::map g_heap_gsp_map; + /// Convert a physical address to virtual address u32 _AddressPhysicalToVirtual(const u32 addr) { // Our memory interface read/write functions assume virtual addresses. Put any physical address @@ -116,6 +120,28 @@ u8 *GetPointer(const u32 addr) { } } +/** + * Maps a block of memory on the GSP heap + * @param size Size of block in bytes + * @param flags Memory allocation flags + */ +u32 MapBlock_HeapGSP(u32 size, u32 operation, u32 permissions) { + HeapBlock block; + + block.base_address = HEAP_GSP_VADDR; + block.size = size; + block.operation = operation; + block.permissions = permissions; + + if (g_heap_gsp_map.size() > 0) { + const HeapBlock last_block = g_heap_gsp_map.rbegin()->second; + block.address = last_block.address + last_block.size; + } + g_heap_gsp_map[block.GetVirtualAddress()] = block; + + return block.GetVirtualAddress(); +} + u8 Read8(const u32 addr) { u8 _var = 0; _Read(_var, addr); -- cgit v1.2.3