diff options
author | Yuri Kunde Schlesner <yuriks@yuriks.net> | 2017-06-22 05:25:46 +0200 |
---|---|---|
committer | Yuri Kunde Schlesner <yuriks@yuriks.net> | 2017-06-22 07:55:18 +0200 |
commit | 6ae0086b39769f5f11d7d4bb7115be8bf2565afe (patch) | |
tree | 1940846ad71e490ae37f643c57cbdbfb850ef3c9 | |
parent | Memory: Make PhysicalToVirtualAddress return a boost::optional (diff) | |
download | yuzu-6ae0086b39769f5f11d7d4bb7115be8bf2565afe.tar yuzu-6ae0086b39769f5f11d7d4bb7115be8bf2565afe.tar.gz yuzu-6ae0086b39769f5f11d7d4bb7115be8bf2565afe.tar.bz2 yuzu-6ae0086b39769f5f11d7d4bb7115be8bf2565afe.tar.lz yuzu-6ae0086b39769f5f11d7d4bb7115be8bf2565afe.tar.xz yuzu-6ae0086b39769f5f11d7d4bb7115be8bf2565afe.tar.zst yuzu-6ae0086b39769f5f11d7d4bb7115be8bf2565afe.zip |
-rw-r--r-- | src/core/memory.cpp | 16 | ||||
-rw-r--r-- | src/core/memory.h | 14 |
2 files changed, 23 insertions, 7 deletions
diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 7d849d55f..42ca69e00 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -670,7 +670,7 @@ void WriteMMIO<u64>(MMIORegionPointer mmio_handler, VAddr addr, const u64 data) mmio_handler->Write64(addr, data); } -PAddr VirtualToPhysicalAddress(const VAddr addr) { +boost::optional<PAddr> TryVirtualToPhysicalAddress(const VAddr addr) { if (addr == 0) { return 0; } else if (addr >= VRAM_VADDR && addr < VRAM_VADDR_END) { @@ -687,9 +687,17 @@ PAddr VirtualToPhysicalAddress(const VAddr addr) { return addr - N3DS_EXTRA_RAM_VADDR + N3DS_EXTRA_RAM_PADDR; } - 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; + return boost::none; +} + +PAddr VirtualToPhysicalAddress(const VAddr addr) { + auto paddr = TryVirtualToPhysicalAddress(addr); + if (!paddr) { + 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; + } + return *paddr; } boost::optional<VAddr> PhysicalToVirtualAddress(const PAddr addr) { diff --git a/src/core/memory.h b/src/core/memory.h index 77277c342..96ce9e52e 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -149,9 +149,17 @@ u8* GetPointer(VAddr virtual_address); std::string ReadCString(VAddr virtual_address, std::size_t max_length); /** -* Converts a virtual address inside a region with 1:1 mapping to physical memory to a physical -* address. This should be used by services to translate addresses for use by the hardware. -*/ + * Converts a virtual address inside a region with 1:1 mapping to physical memory to a physical + * address. This should be used by services to translate addresses for use by the hardware. + */ +boost::optional<PAddr> TryVirtualToPhysicalAddress(VAddr addr); + +/** + * Converts a virtual address inside a region with 1:1 mapping to physical memory to a physical + * address. This should be used by services to translate addresses for use by the hardware. + * + * @deprecated Use TryVirtualToPhysicalAddress(), which reports failure. + */ PAddr VirtualToPhysicalAddress(VAddr addr); /** |