diff options
| author | 2017-06-21 20:25:46 -0700 | |
|---|---|---|
| committer | 2017-06-21 22:55:18 -0700 | |
| commit | 6ae0086b39769f5f11d7d4bb7115be8bf2565afe (patch) | |
| tree | 1940846ad71e490ae37f643c57cbdbfb850ef3c9 /src | |
| parent | Memory: Make PhysicalToVirtualAddress return a boost::optional (diff) | |
| download | yuzu-6ae0086b39769f5f11d7d4bb7115be8bf2565afe.tar.gz yuzu-6ae0086b39769f5f11d7d4bb7115be8bf2565afe.tar.xz yuzu-6ae0086b39769f5f11d7d4bb7115be8bf2565afe.zip | |
Memory: Add TryVirtualToPhysicalAddress, returning a boost::optional
Diffstat (limited to 'src')
| -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) | |||
| 670 | mmio_handler->Write64(addr, data); | 670 | mmio_handler->Write64(addr, data); |
| 671 | } | 671 | } |
| 672 | 672 | ||
| 673 | PAddr VirtualToPhysicalAddress(const VAddr addr) { | 673 | boost::optional<PAddr> TryVirtualToPhysicalAddress(const VAddr addr) { |
| 674 | if (addr == 0) { | 674 | if (addr == 0) { |
| 675 | return 0; | 675 | return 0; |
| 676 | } else if (addr >= VRAM_VADDR && addr < VRAM_VADDR_END) { | 676 | } else if (addr >= VRAM_VADDR && addr < VRAM_VADDR_END) { |
| @@ -687,9 +687,17 @@ PAddr VirtualToPhysicalAddress(const VAddr addr) { | |||
| 687 | return addr - N3DS_EXTRA_RAM_VADDR + N3DS_EXTRA_RAM_PADDR; | 687 | return addr - N3DS_EXTRA_RAM_VADDR + N3DS_EXTRA_RAM_PADDR; |
| 688 | } | 688 | } |
| 689 | 689 | ||
| 690 | LOG_ERROR(HW_Memory, "Unknown virtual address @ 0x%08X", addr); | 690 | return boost::none; |
| 691 | // To help with debugging, set bit on address so that it's obviously invalid. | 691 | } |
| 692 | return addr | 0x80000000; | 692 | |
| 693 | PAddr VirtualToPhysicalAddress(const VAddr addr) { | ||
| 694 | auto paddr = TryVirtualToPhysicalAddress(addr); | ||
| 695 | if (!paddr) { | ||
| 696 | LOG_ERROR(HW_Memory, "Unknown virtual address @ 0x%08X", addr); | ||
| 697 | // To help with debugging, set bit on address so that it's obviously invalid. | ||
| 698 | return addr | 0x80000000; | ||
| 699 | } | ||
| 700 | return *paddr; | ||
| 693 | } | 701 | } |
| 694 | 702 | ||
| 695 | boost::optional<VAddr> PhysicalToVirtualAddress(const PAddr addr) { | 703 | 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); | |||
| 149 | std::string ReadCString(VAddr virtual_address, std::size_t max_length); | 149 | std::string ReadCString(VAddr virtual_address, std::size_t max_length); |
| 150 | 150 | ||
| 151 | /** | 151 | /** |
| 152 | * Converts a virtual address inside a region with 1:1 mapping to physical memory to a physical | 152 | * Converts a virtual address inside a region with 1:1 mapping to physical memory to a physical |
| 153 | * address. This should be used by services to translate addresses for use by the hardware. | 153 | * address. This should be used by services to translate addresses for use by the hardware. |
| 154 | */ | 154 | */ |
| 155 | boost::optional<PAddr> TryVirtualToPhysicalAddress(VAddr addr); | ||
| 156 | |||
| 157 | /** | ||
| 158 | * Converts a virtual address inside a region with 1:1 mapping to physical memory to a physical | ||
| 159 | * address. This should be used by services to translate addresses for use by the hardware. | ||
| 160 | * | ||
| 161 | * @deprecated Use TryVirtualToPhysicalAddress(), which reports failure. | ||
| 162 | */ | ||
| 155 | PAddr VirtualToPhysicalAddress(VAddr addr); | 163 | PAddr VirtualToPhysicalAddress(VAddr addr); |
| 156 | 164 | ||
| 157 | /** | 165 | /** |