diff options
Diffstat (limited to 'src/core/mem_map_funcs.cpp')
-rw-r--r-- | src/core/mem_map_funcs.cpp | 106 |
1 files changed, 47 insertions, 59 deletions
diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index 9a19c9bf8..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<u32, MemoryBlock> heap_map; static std::map<u32, MemoryBlock> 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 + HEAP_LINEAR_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 >= HEAP_LINEAR_VADDR) && (addr < HEAP_LINEAR_VADDR_END)) { - return addr - HEAP_LINEAR_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 <typename T> @@ -61,16 +61,16 @@ inline void Read(T &var, const VAddr vaddr) { // Could just do a base-relative read, too.... TODO // Kernel memory command buffer - if (vaddr >= KERNEL_MEMORY_VADDR && vaddr < KERNEL_MEMORY_VADDR_END) { - var = *((const T*)&g_kernel_mem[vaddr - KERNEL_MEMORY_VADDR]); + if (vaddr >= TLS_AREA_VADDR && vaddr < TLS_AREA_VADDR_END) { + var = *((const T*)&g_tls_mem[vaddr - TLS_AREA_VADDR]); // ExeFS:/.code is loaded here - } else if ((vaddr >= EXEFS_CODE_VADDR) && (vaddr < EXEFS_CODE_VADDR_END)) { - var = *((const T*)&g_exefs_code[vaddr - EXEFS_CODE_VADDR]); + } else if ((vaddr >= PROCESS_IMAGE_VADDR) && (vaddr < PROCESS_IMAGE_VADDR_END)) { + var = *((const T*)&g_exefs_code[vaddr - PROCESS_IMAGE_VADDR]); // FCRAM - linear heap - } else if ((vaddr >= HEAP_LINEAR_VADDR) && (vaddr < HEAP_LINEAR_VADDR_END)) { - var = *((const T*)&g_heap_linear[vaddr - HEAP_LINEAR_VADDR]); + } else if ((vaddr >= LINEAR_HEAP_VADDR) && (vaddr < LINEAR_HEAP_VADDR_END)) { + var = *((const T*)&g_heap_linear[vaddr - LINEAR_HEAP_VADDR]); // FCRAM - application heap } else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { @@ -80,10 +80,6 @@ inline void Read(T &var, const VAddr vaddr) { } else if ((vaddr >= SHARED_MEMORY_VADDR) && (vaddr < SHARED_MEMORY_VADDR_END)) { var = *((const T*)&g_shared_mem[vaddr - SHARED_MEMORY_VADDR]); - // System memory - } else if ((vaddr >= SYSTEM_MEMORY_VADDR) && (vaddr < SYSTEM_MEMORY_VADDR_END)) { - var = *((const T*)&g_system_mem[vaddr - SYSTEM_MEMORY_VADDR]); - // Config memory } else if ((vaddr >= CONFIG_MEMORY_VADDR) && (vaddr < CONFIG_MEMORY_VADDR_END)) { ConfigMem::Read<T>(var, vaddr); @@ -93,8 +89,8 @@ inline void Read(T &var, const VAddr vaddr) { SharedPage::Read<T>(var, vaddr); // DSP memory - } else if ((vaddr >= DSP_MEMORY_VADDR) && (vaddr < DSP_MEMORY_VADDR_END)) { - var = *((const T*)&g_dsp_mem[vaddr - DSP_MEMORY_VADDR]); + } else if ((vaddr >= DSP_RAM_VADDR) && (vaddr < DSP_RAM_VADDR_END)) { + var = *((const T*)&g_dsp_mem[vaddr - DSP_RAM_VADDR]); // VRAM } else if ((vaddr >= VRAM_VADDR) && (vaddr < VRAM_VADDR_END)) { @@ -109,16 +105,16 @@ template <typename T> inline void Write(const VAddr vaddr, const T data) { // Kernel memory command buffer - if (vaddr >= KERNEL_MEMORY_VADDR && vaddr < KERNEL_MEMORY_VADDR_END) { - *(T*)&g_kernel_mem[vaddr - KERNEL_MEMORY_VADDR] = data; + if (vaddr >= TLS_AREA_VADDR && vaddr < TLS_AREA_VADDR_END) { + *(T*)&g_tls_mem[vaddr - TLS_AREA_VADDR] = data; // ExeFS:/.code is loaded here - } else if ((vaddr >= EXEFS_CODE_VADDR) && (vaddr < EXEFS_CODE_VADDR_END)) { - *(T*)&g_exefs_code[vaddr - EXEFS_CODE_VADDR] = data; + } else if ((vaddr >= PROCESS_IMAGE_VADDR) && (vaddr < PROCESS_IMAGE_VADDR_END)) { + *(T*)&g_exefs_code[vaddr - PROCESS_IMAGE_VADDR] = data; // FCRAM - linear heap - } else if ((vaddr >= HEAP_LINEAR_VADDR) && (vaddr < HEAP_LINEAR_VADDR_END)) { - *(T*)&g_heap_linear[vaddr - HEAP_LINEAR_VADDR] = data; + } else if ((vaddr >= LINEAR_HEAP_VADDR) && (vaddr < LINEAR_HEAP_VADDR_END)) { + *(T*)&g_heap_linear[vaddr - LINEAR_HEAP_VADDR] = data; // FCRAM - application heap } else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { @@ -128,17 +124,13 @@ inline void Write(const VAddr vaddr, const T data) { } else if ((vaddr >= SHARED_MEMORY_VADDR) && (vaddr < SHARED_MEMORY_VADDR_END)) { *(T*)&g_shared_mem[vaddr - SHARED_MEMORY_VADDR] = data; - // System memory - } else if ((vaddr >= SYSTEM_MEMORY_VADDR) && (vaddr < SYSTEM_MEMORY_VADDR_END)) { - *(T*)&g_system_mem[vaddr - SYSTEM_MEMORY_VADDR] = data; - // VRAM } else if ((vaddr >= VRAM_VADDR) && (vaddr < VRAM_VADDR_END)) { *(T*)&g_vram[vaddr - VRAM_VADDR] = data; // DSP memory - } else if ((vaddr >= DSP_MEMORY_VADDR) && (vaddr < DSP_MEMORY_VADDR_END)) { - *(T*)&g_dsp_mem[vaddr - DSP_MEMORY_VADDR] = data; + } else if ((vaddr >= DSP_RAM_VADDR) && (vaddr < DSP_RAM_VADDR_END)) { + *(T*)&g_dsp_mem[vaddr - DSP_RAM_VADDR] = data; //} else if ((vaddr & 0xFFFF0000) == 0x1FF80000) { // ASSERT_MSG(MEMMAP, false, "umimplemented write to Configuration Memory"); @@ -153,16 +145,16 @@ inline void Write(const VAddr vaddr, const T data) { u8 *GetPointer(const VAddr vaddr) { // Kernel memory command buffer - if (vaddr >= KERNEL_MEMORY_VADDR && vaddr < KERNEL_MEMORY_VADDR_END) { - return g_kernel_mem + (vaddr - KERNEL_MEMORY_VADDR); + if (vaddr >= TLS_AREA_VADDR && vaddr < TLS_AREA_VADDR_END) { + return g_tls_mem + (vaddr - TLS_AREA_VADDR); // ExeFS:/.code is loaded here - } else if ((vaddr >= EXEFS_CODE_VADDR) && (vaddr < EXEFS_CODE_VADDR_END)) { - return g_exefs_code + (vaddr - EXEFS_CODE_VADDR); + } else if ((vaddr >= PROCESS_IMAGE_VADDR) && (vaddr < PROCESS_IMAGE_VADDR_END)) { + return g_exefs_code + (vaddr - PROCESS_IMAGE_VADDR); // FCRAM - linear heap - } else if ((vaddr >= HEAP_LINEAR_VADDR) && (vaddr < HEAP_LINEAR_VADDR_END)) { - return g_heap_linear + (vaddr - HEAP_LINEAR_VADDR); + } else if ((vaddr >= LINEAR_HEAP_VADDR) && (vaddr < LINEAR_HEAP_VADDR_END)) { + return g_heap_linear + (vaddr - LINEAR_HEAP_VADDR); // FCRAM - application heap } else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { @@ -172,10 +164,6 @@ u8 *GetPointer(const VAddr vaddr) { } else if ((vaddr >= SHARED_MEMORY_VADDR) && (vaddr < SHARED_MEMORY_VADDR_END)) { return g_shared_mem + (vaddr - SHARED_MEMORY_VADDR); - // System memory - } else if ((vaddr >= SYSTEM_MEMORY_VADDR) && (vaddr < SYSTEM_MEMORY_VADDR_END)) { - return g_system_mem + (vaddr - SYSTEM_MEMORY_VADDR); - // VRAM } else if ((vaddr >= VRAM_VADDR) && (vaddr < VRAM_VADDR_END)) { return g_vram + (vaddr - VRAM_VADDR); @@ -206,7 +194,7 @@ u32 MapBlock_Heap(u32 size, u32 operation, u32 permissions) { u32 MapBlock_HeapLinear(u32 size, u32 operation, u32 permissions) { MemoryBlock block; - block.base_address = HEAP_LINEAR_VADDR; + block.base_address = LINEAR_HEAP_VADDR; block.size = size; block.operation = operation; block.permissions = permissions; |