summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2015-05-09 03:08:11 -0300
committerGravatar Yuri Kunde Schlesner2015-05-09 03:08:11 -0300
commit28a9e4c1d55c66e99b5cf16fda00dcb75ab27fde (patch)
tree9c40b519bff8a84c948b9343367763781cb64454 /src/core
parentMemory: Sort memory region variables by VAddr (diff)
downloadyuzu-28a9e4c1d55c66e99b5cf16fda00dcb75ab27fde.tar.gz
yuzu-28a9e4c1d55c66e99b5cf16fda00dcb75ab27fde.tar.xz
yuzu-28a9e4c1d55c66e99b5cf16fda00dcb75ab27fde.zip
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.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/mem_map.h13
-rw-r--r--src/core/mem_map_funcs.cpp48
2 files changed, 33 insertions, 28 deletions
diff --git a/src/core/mem_map.h b/src/core/mem_map.h
index 1591fc0a9..5a08cc105 100644
--- a/src/core/mem_map.h
+++ b/src/core/mem_map.h
@@ -181,10 +181,15 @@ inline const char* GetCharPointer(const VAddr address) {
181 return (const char *)GetPointer(address); 181 return (const char *)GetPointer(address);
182} 182}
183 183
184/// Converts a physical address to virtual address 184/**
185VAddr PhysicalToVirtualAddress(PAddr addr); 185 * Converts a virtual address inside a region with 1:1 mapping to physical memory to a physical
186 186 * address. This should be used by services to translate addresses for use by the hardware.
187/// Converts a virtual address to physical address 187 */
188PAddr VirtualToPhysicalAddress(VAddr addr); 188PAddr VirtualToPhysicalAddress(VAddr addr);
189 189
190/**
191 * Undoes a mapping performed by VirtualToPhysicalAddress().
192 */
193VAddr PhysicalToVirtualAddress(PAddr addr);
194
190} // namespace 195} // namespace
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 {
18static std::map<u32, MemoryBlock> heap_map; 18static std::map<u32, MemoryBlock> heap_map;
19static std::map<u32, MemoryBlock> heap_linear_map; 19static std::map<u32, MemoryBlock> heap_linear_map;
20 20
21/// Convert a physical address to virtual address 21PAddr VirtualToPhysicalAddress(const VAddr addr) {
22VAddr PhysicalToVirtualAddress(const PAddr addr) {
23 // Our memory interface read/write functions assume virtual addresses. Put any physical address
24 // to virtual address translations here. This is quite hacky, but necessary until we implement
25 // proper MMU emulation.
26 // TODO: Screw it, I'll let bunnei figure out how to do this properly.
27 if (addr == 0) { 22 if (addr == 0) {
28 return 0; 23 return 0;
29 } else if ((addr >= VRAM_PADDR) && (addr < VRAM_PADDR_END)) { 24 } else if (addr >= VRAM_VADDR && addr < VRAM_VADDR_END) {
30 return addr - VRAM_PADDR + VRAM_VADDR; 25 return addr - VRAM_VADDR + VRAM_PADDR;
31 } else if ((addr >= FCRAM_PADDR) && (addr < FCRAM_PADDR_END)) { 26 } else if (addr >= LINEAR_HEAP_VADDR && addr < LINEAR_HEAP_VADDR_END) {
32 return addr - FCRAM_PADDR + LINEAR_HEAP_VADDR; 27 return addr - LINEAR_HEAP_VADDR + FCRAM_PADDR;
28 } else if (addr >= DSP_RAM_VADDR && addr < DSP_RAM_VADDR_END) {
29 return addr - DSP_RAM_VADDR + DSP_RAM_PADDR;
30 } else if (addr >= IO_AREA_VADDR && addr < IO_AREA_VADDR_END) {
31 return addr - IO_AREA_VADDR + IO_AREA_PADDR;
33 } 32 }
34 33
35 LOG_ERROR(HW_Memory, "Unknown physical address @ 0x%08x", addr); 34 LOG_ERROR(HW_Memory, "Unknown virtual address @ 0x%08x", addr);
36 return addr; 35 // To help with debugging, set bit on address so that it's obviously invalid.
36 return addr | 0x80000000;
37} 37}
38 38
39/// Convert a physical address to virtual address 39VAddr PhysicalToVirtualAddress(const PAddr addr) {
40PAddr VirtualToPhysicalAddress(const VAddr addr) {
41 // Our memory interface read/write functions assume virtual addresses. Put any physical address
42 // to virtual address translations here. This is quite hacky, but necessary until we implement
43 // proper MMU emulation.
44 // TODO: Screw it, I'll let bunnei figure out how to do this properly.
45 if (addr == 0) { 40 if (addr == 0) {
46 return 0; 41 return 0;
47 } else if ((addr >= VRAM_VADDR) && (addr < VRAM_VADDR_END)) { 42 } else if (addr >= VRAM_PADDR && addr < VRAM_PADDR_END) {
48 return addr - VRAM_VADDR + VRAM_PADDR; 43 return addr - VRAM_PADDR + VRAM_VADDR;
49 } else if ((addr >= LINEAR_HEAP_VADDR) && (addr < LINEAR_HEAP_VADDR_END)) { 44 } else if (addr >= FCRAM_PADDR && addr < FCRAM_PADDR_END) {
50 return addr - LINEAR_HEAP_VADDR + FCRAM_PADDR; 45 return addr - FCRAM_PADDR + LINEAR_HEAP_VADDR;
46 } else if (addr >= DSP_RAM_PADDR && addr < DSP_RAM_PADDR_END) {
47 return addr - DSP_RAM_PADDR + DSP_RAM_VADDR;
48 } else if (addr >= IO_AREA_PADDR && addr < IO_AREA_PADDR_END) {
49 return addr - IO_AREA_PADDR + IO_AREA_VADDR;
51 } 50 }
52 51
53 LOG_ERROR(HW_Memory, "Unknown virtual address @ 0x%08x", addr); 52 LOG_ERROR(HW_Memory, "Unknown physical address @ 0x%08x", addr);
54 return addr; 53 // To help with debugging, set bit on address so that it's obviously invalid.
54 return addr | 0x80000000;
55} 55}
56 56
57template <typename T> 57template <typename T>