From 28a9e4c1d55c66e99b5cf16fda00dcb75ab27fde Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 9 May 2015 03:08:11 -0300 Subject: Memory: Support more regions in the VAddr-PAddr translation functions Also adds better documentation and removes the one-off reimplementation of the function in pica.h. --- src/core/mem_map_funcs.cpp | 48 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 24 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 f96ae6e9e..a8e0fed07 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -18,40 +18,40 @@ namespace Memory { static std::map heap_map; static std::map heap_linear_map; -/// Convert a physical address to virtual address -VAddr PhysicalToVirtualAddress(const PAddr addr) { - // Our memory interface read/write functions assume virtual addresses. Put any physical address - // to virtual address translations here. This is quite hacky, but necessary until we implement - // proper MMU emulation. - // TODO: Screw it, I'll let bunnei figure out how to do this properly. +PAddr VirtualToPhysicalAddress(const VAddr addr) { if (addr == 0) { return 0; - } else if ((addr >= VRAM_PADDR) && (addr < VRAM_PADDR_END)) { - return addr - VRAM_PADDR + VRAM_VADDR; - } else if ((addr >= FCRAM_PADDR) && (addr < FCRAM_PADDR_END)) { - return addr - FCRAM_PADDR + LINEAR_HEAP_VADDR; + } else if (addr >= VRAM_VADDR && addr < VRAM_VADDR_END) { + return addr - VRAM_VADDR + VRAM_PADDR; + } else if (addr >= LINEAR_HEAP_VADDR && addr < LINEAR_HEAP_VADDR_END) { + return addr - LINEAR_HEAP_VADDR + FCRAM_PADDR; + } else if (addr >= DSP_RAM_VADDR && addr < DSP_RAM_VADDR_END) { + return addr - DSP_RAM_VADDR + DSP_RAM_PADDR; + } else if (addr >= IO_AREA_VADDR && addr < IO_AREA_VADDR_END) { + return addr - IO_AREA_VADDR + IO_AREA_PADDR; } - LOG_ERROR(HW_Memory, "Unknown physical address @ 0x%08x", addr); - return addr; + LOG_ERROR(HW_Memory, "Unknown virtual address @ 0x%08x", addr); + // To help with debugging, set bit on address so that it's obviously invalid. + return addr | 0x80000000; } -/// Convert a physical address to virtual address -PAddr VirtualToPhysicalAddress(const VAddr addr) { - // Our memory interface read/write functions assume virtual addresses. Put any physical address - // to virtual address translations here. This is quite hacky, but necessary until we implement - // proper MMU emulation. - // TODO: Screw it, I'll let bunnei figure out how to do this properly. +VAddr PhysicalToVirtualAddress(const PAddr addr) { if (addr == 0) { return 0; - } else if ((addr >= VRAM_VADDR) && (addr < VRAM_VADDR_END)) { - return addr - VRAM_VADDR + VRAM_PADDR; - } else if ((addr >= LINEAR_HEAP_VADDR) && (addr < LINEAR_HEAP_VADDR_END)) { - return addr - LINEAR_HEAP_VADDR + FCRAM_PADDR; + } else if (addr >= VRAM_PADDR && addr < VRAM_PADDR_END) { + return addr - VRAM_PADDR + VRAM_VADDR; + } else if (addr >= FCRAM_PADDR && addr < FCRAM_PADDR_END) { + return addr - FCRAM_PADDR + LINEAR_HEAP_VADDR; + } else if (addr >= DSP_RAM_PADDR && addr < DSP_RAM_PADDR_END) { + return addr - DSP_RAM_PADDR + DSP_RAM_VADDR; + } else if (addr >= IO_AREA_PADDR && addr < IO_AREA_PADDR_END) { + return addr - IO_AREA_PADDR + IO_AREA_VADDR; } - LOG_ERROR(HW_Memory, "Unknown virtual address @ 0x%08x", addr); - return addr; + LOG_ERROR(HW_Memory, "Unknown physical address @ 0x%08x", addr); + // To help with debugging, set bit on address so that it's obviously invalid. + return addr | 0x80000000; } template -- cgit v1.2.3