summaryrefslogtreecommitdiff
path: root/src/core/memory.cpp
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2017-06-21 20:21:49 -0700
committerGravatar Yuri Kunde Schlesner2017-06-21 22:55:17 -0700
commit326e7c70208865b013e138972b25687d805488d0 (patch)
treeb88cd1431d0069052b0bab969ba480a9278f8c22 /src/core/memory.cpp
parentMerge pull request #2792 from wwylele/lutlutlut (diff)
downloadyuzu-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/memory.cpp')
-rw-r--r--src/core/memory.cpp21
1 files changed, 12 insertions, 9 deletions
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
270bool IsValidPhysicalAddress(const PAddr paddr) { 270bool 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
274u8* GetPointer(const VAddr vaddr) { 275u8* GetPointer(const VAddr vaddr) {
@@ -301,7 +302,8 @@ std::string ReadCString(VAddr vaddr, std::size_t max_length) {
301 302
302u8* GetPhysicalPointer(PAddr address) { 303u8* 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
307void RasterizerMarkRegionCached(PAddr start, u32 size, int count_delta) { 309void 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
690VAddr PhysicalToVirtualAddress(const PAddr addr) { 695boost::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