diff options
| author | 2017-06-21 20:21:49 -0700 | |
|---|---|---|
| committer | 2017-06-21 22:55:17 -0700 | |
| commit | 326e7c70208865b013e138972b25687d805488d0 (patch) | |
| tree | b88cd1431d0069052b0bab969ba480a9278f8c22 /src/core | |
| parent | Merge pull request #2792 from wwylele/lutlutlut (diff) | |
| download | yuzu-326e7c70208865b013e138972b25687d805488d0.tar.gz yuzu-326e7c70208865b013e138972b25687d805488d0.tar.xz yuzu-326e7c70208865b013e138972b25687d805488d0.zip | |
Memory: Make PhysicalToVirtualAddress return a boost::optional
And fix a few places in the code to take advantage of that.
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/hle/kernel/shared_memory.cpp | 2 | ||||
| -rw-r--r-- | src/core/hle/service/apt/apt.cpp | 2 | ||||
| -rw-r--r-- | src/core/memory.cpp | 21 | ||||
| -rw-r--r-- | src/core/memory.h | 7 |
4 files changed, 18 insertions, 14 deletions
diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp index 922e5ab58..a7b66142f 100644 --- a/src/core/hle/kernel/shared_memory.cpp +++ b/src/core/hle/kernel/shared_memory.cpp | |||
| @@ -149,7 +149,7 @@ ResultCode SharedMemory::Map(Process* target_process, VAddr address, MemoryPermi | |||
| 149 | 149 | ||
| 150 | if (base_address == 0 && target_address == 0) { | 150 | if (base_address == 0 && target_address == 0) { |
| 151 | // Calculate the address at which to map the memory block. | 151 | // Calculate the address at which to map the memory block. |
| 152 | target_address = Memory::PhysicalToVirtualAddress(linear_heap_phys_address); | 152 | target_address = Memory::PhysicalToVirtualAddress(linear_heap_phys_address).value(); |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | // Map the memory block into the target process | 155 | // Map the memory block into the target process |
diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index 25e7b777d..6375e28f9 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp | |||
| @@ -82,7 +82,7 @@ void GetSharedFont(Service::Interface* self) { | |||
| 82 | // The shared font has to be relocated to the new address before being passed to the | 82 | // The shared font has to be relocated to the new address before being passed to the |
| 83 | // application. | 83 | // application. |
| 84 | VAddr target_address = | 84 | VAddr target_address = |
| 85 | Memory::PhysicalToVirtualAddress(shared_font_mem->linear_heap_phys_address); | 85 | Memory::PhysicalToVirtualAddress(shared_font_mem->linear_heap_phys_address).value(); |
| 86 | if (!shared_font_relocated) { | 86 | if (!shared_font_relocated) { |
| 87 | BCFNT::RelocateSharedFont(shared_font_mem, target_address); | 87 | BCFNT::RelocateSharedFont(shared_font_mem, target_address); |
| 88 | shared_font_relocated = true; | 88 | shared_font_relocated = true; |
diff --git a/src/core/memory.cpp b/src/core/memory.cpp index b8438e490..7d849d55f 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp | |||
| @@ -268,7 +268,8 @@ bool IsValidVirtualAddress(const VAddr vaddr) { | |||
| 268 | } | 268 | } |
| 269 | 269 | ||
| 270 | bool IsValidPhysicalAddress(const PAddr paddr) { | 270 | bool IsValidPhysicalAddress(const PAddr paddr) { |
| 271 | return IsValidVirtualAddress(PhysicalToVirtualAddress(paddr)); | 271 | boost::optional<VAddr> vaddr = PhysicalToVirtualAddress(paddr); |
| 272 | return vaddr && IsValidVirtualAddress(*vaddr); | ||
| 272 | } | 273 | } |
| 273 | 274 | ||
| 274 | u8* GetPointer(const VAddr vaddr) { | 275 | u8* GetPointer(const VAddr vaddr) { |
| @@ -301,7 +302,8 @@ std::string ReadCString(VAddr vaddr, std::size_t max_length) { | |||
| 301 | 302 | ||
| 302 | u8* GetPhysicalPointer(PAddr address) { | 303 | u8* GetPhysicalPointer(PAddr address) { |
| 303 | // TODO(Subv): This call should not go through the application's memory mapping. | 304 | // TODO(Subv): This call should not go through the application's memory mapping. |
| 304 | return GetPointer(PhysicalToVirtualAddress(address)); | 305 | boost::optional<VAddr> vaddr = PhysicalToVirtualAddress(address); |
| 306 | return vaddr ? GetPointer(*vaddr) : nullptr; | ||
| 305 | } | 307 | } |
| 306 | 308 | ||
| 307 | void RasterizerMarkRegionCached(PAddr start, u32 size, int count_delta) { | 309 | void RasterizerMarkRegionCached(PAddr start, u32 size, int count_delta) { |
| @@ -312,8 +314,12 @@ void RasterizerMarkRegionCached(PAddr start, u32 size, int count_delta) { | |||
| 312 | u32 num_pages = ((start + size - 1) >> PAGE_BITS) - (start >> PAGE_BITS) + 1; | 314 | u32 num_pages = ((start + size - 1) >> PAGE_BITS) - (start >> PAGE_BITS) + 1; |
| 313 | PAddr paddr = start; | 315 | PAddr paddr = start; |
| 314 | 316 | ||
| 315 | for (unsigned i = 0; i < num_pages; ++i) { | 317 | for (unsigned i = 0; i < num_pages; ++i, paddr += PAGE_SIZE) { |
| 316 | VAddr vaddr = PhysicalToVirtualAddress(paddr); | 318 | boost::optional<VAddr> maybe_vaddr = PhysicalToVirtualAddress(paddr); |
| 319 | if (!maybe_vaddr) | ||
| 320 | continue; | ||
| 321 | VAddr vaddr = *maybe_vaddr; | ||
| 322 | |||
| 317 | u8& res_count = current_page_table->cached_res_count[vaddr >> PAGE_BITS]; | 323 | u8& res_count = current_page_table->cached_res_count[vaddr >> PAGE_BITS]; |
| 318 | ASSERT_MSG(count_delta <= UINT8_MAX - res_count, | 324 | ASSERT_MSG(count_delta <= UINT8_MAX - res_count, |
| 319 | "Rasterizer resource cache counter overflow!"); | 325 | "Rasterizer resource cache counter overflow!"); |
| @@ -353,7 +359,6 @@ void RasterizerMarkRegionCached(PAddr start, u32 size, int count_delta) { | |||
| 353 | UNREACHABLE(); | 359 | UNREACHABLE(); |
| 354 | } | 360 | } |
| 355 | } | 361 | } |
| 356 | paddr += PAGE_SIZE; | ||
| 357 | } | 362 | } |
| 358 | } | 363 | } |
| 359 | 364 | ||
| @@ -687,7 +692,7 @@ PAddr VirtualToPhysicalAddress(const VAddr addr) { | |||
| 687 | return addr | 0x80000000; | 692 | return addr | 0x80000000; |
| 688 | } | 693 | } |
| 689 | 694 | ||
| 690 | VAddr PhysicalToVirtualAddress(const PAddr addr) { | 695 | boost::optional<VAddr> PhysicalToVirtualAddress(const PAddr addr) { |
| 691 | if (addr == 0) { | 696 | if (addr == 0) { |
| 692 | return 0; | 697 | return 0; |
| 693 | } else if (addr >= VRAM_PADDR && addr < VRAM_PADDR_END) { | 698 | } else if (addr >= VRAM_PADDR && addr < VRAM_PADDR_END) { |
| @@ -702,9 +707,7 @@ VAddr PhysicalToVirtualAddress(const PAddr addr) { | |||
| 702 | return addr - N3DS_EXTRA_RAM_PADDR + N3DS_EXTRA_RAM_VADDR; | 707 | return addr - N3DS_EXTRA_RAM_PADDR + N3DS_EXTRA_RAM_VADDR; |
| 703 | } | 708 | } |
| 704 | 709 | ||
| 705 | LOG_ERROR(HW_Memory, "Unknown physical address @ 0x%08X", addr); | 710 | return boost::none; |
| 706 | // To help with debugging, set bit on address so that it's obviously invalid. | ||
| 707 | return addr | 0x80000000; | ||
| 708 | } | 711 | } |
| 709 | 712 | ||
| 710 | } // namespace | 713 | } // namespace |
diff --git a/src/core/memory.h b/src/core/memory.h index 71fb278ad..77277c342 100644 --- a/src/core/memory.h +++ b/src/core/memory.h | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <cstddef> | 8 | #include <cstddef> |
| 9 | #include <string> | 9 | #include <string> |
| 10 | #include <boost/optional.hpp> | ||
| 10 | #include "common/common_types.h" | 11 | #include "common/common_types.h" |
| 11 | 12 | ||
| 12 | namespace Memory { | 13 | namespace Memory { |
| @@ -154,9 +155,9 @@ std::string ReadCString(VAddr virtual_address, std::size_t max_length); | |||
| 154 | PAddr VirtualToPhysicalAddress(VAddr addr); | 155 | PAddr VirtualToPhysicalAddress(VAddr addr); |
| 155 | 156 | ||
| 156 | /** | 157 | /** |
| 157 | * Undoes a mapping performed by VirtualToPhysicalAddress(). | 158 | * Undoes a mapping performed by VirtualToPhysicalAddress(). |
| 158 | */ | 159 | */ |
| 159 | VAddr PhysicalToVirtualAddress(PAddr addr); | 160 | boost::optional<VAddr> PhysicalToVirtualAddress(PAddr addr); |
| 160 | 161 | ||
| 161 | /** | 162 | /** |
| 162 | * Gets a pointer to the memory region beginning at the specified physical address. | 163 | * Gets a pointer to the memory region beginning at the specified physical address. |