diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/mem_map.h | 39 | ||||
| -rw-r--r-- | src/core/mem_map_funcs.cpp | 32 |
2 files changed, 40 insertions, 31 deletions
diff --git a/src/core/mem_map.h b/src/core/mem_map.h index 3c7810573..eed445046 100644 --- a/src/core/mem_map.h +++ b/src/core/mem_map.h | |||
| @@ -9,6 +9,11 @@ | |||
| 9 | 9 | ||
| 10 | namespace Memory { | 10 | namespace Memory { |
| 11 | 11 | ||
| 12 | // TODO: It would be nice to eventually replace these with strong types that prevent accidental | ||
| 13 | // conversion between each other. | ||
| 14 | typedef u32 VAddr; ///< Represents a pointer in the ARM11 virtual address space. | ||
| 15 | typedef u32 PAddr; ///< Represents a pointer in the physical address space. | ||
| 16 | |||
| 12 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 17 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 13 | 18 | ||
| 14 | enum { | 19 | enum { |
| @@ -127,25 +132,25 @@ void Init(); | |||
| 127 | void Shutdown(); | 132 | void Shutdown(); |
| 128 | 133 | ||
| 129 | template <typename T> | 134 | template <typename T> |
| 130 | inline void Read(T &var, const u32 addr); | 135 | inline void Read(T &var, VAddr addr); |
| 131 | 136 | ||
| 132 | template <typename T> | 137 | template <typename T> |
| 133 | inline void Write(u32 addr, const T data); | 138 | inline void Write(VAddr addr, T data); |
| 134 | 139 | ||
| 135 | u8 Read8(const u32 addr); | 140 | u8 Read8(VAddr addr); |
| 136 | u16 Read16(const u32 addr); | 141 | u16 Read16(VAddr addr); |
| 137 | u32 Read32(const u32 addr); | 142 | u32 Read32(VAddr addr); |
| 138 | 143 | ||
| 139 | u32 Read8_ZX(const u32 addr); | 144 | u32 Read8_ZX(VAddr addr); |
| 140 | u32 Read16_ZX(const u32 addr); | 145 | u32 Read16_ZX(VAddr addr); |
| 141 | 146 | ||
| 142 | void Write8(const u32 addr, const u8 data); | 147 | void Write8(VAddr addr, u8 data); |
| 143 | void Write16(const u32 addr, const u16 data); | 148 | void Write16(VAddr addr, u16 data); |
| 144 | void Write32(const u32 addr, const u32 data); | 149 | void Write32(VAddr addr, u32 data); |
| 145 | 150 | ||
| 146 | void WriteBlock(const u32 addr, const u8* data, const int size); | 151 | void WriteBlock(VAddr addr, const u8* data, size_t size); |
| 147 | 152 | ||
| 148 | u8* GetPointer(const u32 virtual_address); | 153 | u8* GetPointer(VAddr virtual_address); |
| 149 | 154 | ||
| 150 | /** | 155 | /** |
| 151 | * Maps a block of memory on the heap | 156 | * Maps a block of memory on the heap |
| @@ -163,14 +168,18 @@ u32 MapBlock_Heap(u32 size, u32 operation, u32 permissions); | |||
| 163 | */ | 168 | */ |
| 164 | u32 MapBlock_HeapGSP(u32 size, u32 operation, u32 permissions); | 169 | u32 MapBlock_HeapGSP(u32 size, u32 operation, u32 permissions); |
| 165 | 170 | ||
| 166 | inline const char* GetCharPointer(const u32 address) { | 171 | inline const char* GetCharPointer(const VAddr address) { |
| 167 | return (const char *)GetPointer(address); | 172 | return (const char *)GetPointer(address); |
| 168 | } | 173 | } |
| 169 | 174 | ||
| 170 | /// Converts a physical address to virtual address | 175 | /// Converts a physical address to virtual address |
| 171 | u32 PhysicalToVirtualAddress(const u32 addr); | 176 | VAddr PhysicalToVirtualAddress(PAddr addr); |
| 172 | 177 | ||
| 173 | /// Converts a virtual address to physical address | 178 | /// Converts a virtual address to physical address |
| 174 | u32 VirtualToPhysicalAddress(const u32 addr); | 179 | PAddr VirtualToPhysicalAddress(VAddr addr); |
| 175 | 180 | ||
| 176 | } // namespace | 181 | } // namespace |
| 182 | |||
| 183 | // These are used often, so re-export then on the root namespace | ||
| 184 | using Memory::VAddr; | ||
| 185 | using Memory::PAddr; | ||
diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index ecdaa06d7..391b75fc2 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp | |||
| @@ -18,7 +18,7 @@ std::map<u32, MemoryBlock> g_heap_gsp_map; | |||
| 18 | std::map<u32, MemoryBlock> g_shared_map; | 18 | std::map<u32, MemoryBlock> g_shared_map; |
| 19 | 19 | ||
| 20 | /// Convert a physical address to virtual address | 20 | /// Convert a physical address to virtual address |
| 21 | u32 PhysicalToVirtualAddress(const u32 addr) { | 21 | VAddr PhysicalToVirtualAddress(const PAddr addr) { |
| 22 | // Our memory interface read/write functions assume virtual addresses. Put any physical address | 22 | // Our memory interface read/write functions assume virtual addresses. Put any physical address |
| 23 | // to virtual address translations here. This is quite hacky, but necessary until we implement | 23 | // to virtual address translations here. This is quite hacky, but necessary until we implement |
| 24 | // proper MMU emulation. | 24 | // proper MMU emulation. |
| @@ -34,7 +34,7 @@ u32 PhysicalToVirtualAddress(const u32 addr) { | |||
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | /// Convert a physical address to virtual address | 36 | /// Convert a physical address to virtual address |
| 37 | u32 VirtualToPhysicalAddress(const u32 addr) { | 37 | PAddr VirtualToPhysicalAddress(const VAddr addr) { |
| 38 | // Our memory interface read/write functions assume virtual addresses. Put any physical address | 38 | // Our memory interface read/write functions assume virtual addresses. Put any physical address |
| 39 | // to virtual address translations here. This is quite hacky, but necessary until we implement | 39 | // to virtual address translations here. This is quite hacky, but necessary until we implement |
| 40 | // proper MMU emulation. | 40 | // proper MMU emulation. |
| @@ -50,7 +50,7 @@ u32 VirtualToPhysicalAddress(const u32 addr) { | |||
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | template <typename T> | 52 | template <typename T> |
| 53 | inline void Read(T &var, const u32 vaddr) { | 53 | inline void Read(T &var, const VAddr vaddr) { |
| 54 | // TODO: Figure out the fastest order of tests for both read and write (they are probably different). | 54 | // TODO: Figure out the fastest order of tests for both read and write (they are probably different). |
| 55 | // TODO: Make sure this represents the mirrors in a correct way. | 55 | // TODO: Make sure this represents the mirrors in a correct way. |
| 56 | // Could just do a base-relative read, too.... TODO | 56 | // Could just do a base-relative read, too.... TODO |
| @@ -98,7 +98,7 @@ inline void Read(T &var, const u32 vaddr) { | |||
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | template <typename T> | 100 | template <typename T> |
| 101 | inline void Write(u32 vaddr, const T data) { | 101 | inline void Write(const VAddr vaddr, const T data) { |
| 102 | 102 | ||
| 103 | // Kernel memory command buffer | 103 | // Kernel memory command buffer |
| 104 | if (vaddr >= KERNEL_MEMORY_VADDR && vaddr < KERNEL_MEMORY_VADDR_END) { | 104 | if (vaddr >= KERNEL_MEMORY_VADDR && vaddr < KERNEL_MEMORY_VADDR_END) { |
| @@ -146,7 +146,7 @@ inline void Write(u32 vaddr, const T data) { | |||
| 146 | } | 146 | } |
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | u8 *GetPointer(const u32 vaddr) { | 149 | u8 *GetPointer(const VAddr vaddr) { |
| 150 | // Kernel memory command buffer | 150 | // Kernel memory command buffer |
| 151 | if (vaddr >= KERNEL_MEMORY_VADDR && vaddr < KERNEL_MEMORY_VADDR_END) { | 151 | if (vaddr >= KERNEL_MEMORY_VADDR && vaddr < KERNEL_MEMORY_VADDR_END) { |
| 152 | return g_kernel_mem + (vaddr & KERNEL_MEMORY_MASK); | 152 | return g_kernel_mem + (vaddr & KERNEL_MEMORY_MASK); |
| @@ -227,13 +227,13 @@ u32 MapBlock_HeapGSP(u32 size, u32 operation, u32 permissions) { | |||
| 227 | return block.GetVirtualAddress(); | 227 | return block.GetVirtualAddress(); |
| 228 | } | 228 | } |
| 229 | 229 | ||
| 230 | u8 Read8(const u32 addr) { | 230 | u8 Read8(const VAddr addr) { |
| 231 | u8 data = 0; | 231 | u8 data = 0; |
| 232 | Read<u8>(data, addr); | 232 | Read<u8>(data, addr); |
| 233 | return (u8)data; | 233 | return data; |
| 234 | } | 234 | } |
| 235 | 235 | ||
| 236 | u16 Read16(const u32 addr) { | 236 | u16 Read16(const VAddr addr) { |
| 237 | u16_le data = 0; | 237 | u16_le data = 0; |
| 238 | Read<u16_le>(data, addr); | 238 | Read<u16_le>(data, addr); |
| 239 | 239 | ||
| @@ -246,7 +246,7 @@ u16 Read16(const u32 addr) { | |||
| 246 | return (u16)data; | 246 | return (u16)data; |
| 247 | } | 247 | } |
| 248 | 248 | ||
| 249 | u32 Read32(const u32 addr) { | 249 | u32 Read32(const VAddr addr) { |
| 250 | u32_le data = 0; | 250 | u32_le data = 0; |
| 251 | Read<u32_le>(data, addr); | 251 | Read<u32_le>(data, addr); |
| 252 | 252 | ||
| @@ -263,31 +263,31 @@ u32 Read32(const u32 addr) { | |||
| 263 | return (u32)data; | 263 | return (u32)data; |
| 264 | } | 264 | } |
| 265 | 265 | ||
| 266 | u32 Read8_ZX(const u32 addr) { | 266 | u32 Read8_ZX(const VAddr addr) { |
| 267 | return (u32)Read8(addr); | 267 | return (u32)Read8(addr); |
| 268 | } | 268 | } |
| 269 | 269 | ||
| 270 | u32 Read16_ZX(const u32 addr) { | 270 | u32 Read16_ZX(const VAddr addr) { |
| 271 | return (u32)Read16(addr); | 271 | return (u32)Read16(addr); |
| 272 | } | 272 | } |
| 273 | 273 | ||
| 274 | void Write8(const u32 addr, const u8 data) { | 274 | void Write8(const VAddr addr, const u8 data) { |
| 275 | Write<u8>(addr, data); | 275 | Write<u8>(addr, data); |
| 276 | } | 276 | } |
| 277 | 277 | ||
| 278 | void Write16(const u32 addr, const u16 data) { | 278 | void Write16(const VAddr addr, const u16 data) { |
| 279 | Write<u16_le>(addr, data); | 279 | Write<u16_le>(addr, data); |
| 280 | } | 280 | } |
| 281 | 281 | ||
| 282 | void Write32(const u32 addr, const u32 data) { | 282 | void Write32(const VAddr addr, const u32 data) { |
| 283 | Write<u32_le>(addr, data); | 283 | Write<u32_le>(addr, data); |
| 284 | } | 284 | } |
| 285 | 285 | ||
| 286 | void Write64(const u32 addr, const u64 data) { | 286 | void Write64(const VAddr addr, const u64 data) { |
| 287 | Write<u64_le>(addr, data); | 287 | Write<u64_le>(addr, data); |
| 288 | } | 288 | } |
| 289 | 289 | ||
| 290 | void WriteBlock(const u32 addr, const u8* data, const int size) { | 290 | void WriteBlock(const VAddr addr, const u8* data, const size_t size) { |
| 291 | int offset = 0; | 291 | int offset = 0; |
| 292 | while (offset < (size & ~3)) { | 292 | while (offset < (size & ~3)) { |
| 293 | Write32(addr + offset, *(u32*)&data[offset]); | 293 | Write32(addr + offset, *(u32*)&data[offset]); |