diff options
| author | 2016-04-16 08:46:11 +0100 | |
|---|---|---|
| committer | 2016-05-21 11:12:35 -0500 | |
| commit | c084fc824cf4e076bb83e41af64f5cfaa9204dcb (patch) | |
| tree | 056ee19984854e14b62d7fb6f14ff9c4d11c97b0 /src | |
| parent | Appveyor: Restore working directory after test_script (#1835) (diff) | |
| download | yuzu-c084fc824cf4e076bb83e41af64f5cfaa9204dcb.tar.gz yuzu-c084fc824cf4e076bb83e41af64f5cfaa9204dcb.tar.xz yuzu-c084fc824cf4e076bb83e41af64f5cfaa9204dcb.zip | |
Memory: IsValidVirtualAddress/IsValidPhysicalAddress
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/memory.cpp | 21 | ||||
| -rw-r--r-- | src/core/memory.h | 3 | ||||
| -rw-r--r-- | src/core/mmio.h | 2 |
3 files changed, 26 insertions, 0 deletions
diff --git a/src/core/memory.cpp b/src/core/memory.cpp index ee9b69f81..68a29b154 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp | |||
| @@ -246,6 +246,26 @@ void Write(const VAddr vaddr, const T data) { | |||
| 246 | } | 246 | } |
| 247 | } | 247 | } |
| 248 | 248 | ||
| 249 | bool IsValidVirtualAddress(const VAddr vaddr) { | ||
| 250 | const u8* page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS]; | ||
| 251 | if (page_pointer) | ||
| 252 | return true; | ||
| 253 | |||
| 254 | if (current_page_table->attributes[vaddr >> PAGE_BITS] != PageType::Special) | ||
| 255 | return false; | ||
| 256 | |||
| 257 | MMIORegionPointer mmio_region = GetMMIOHandler(vaddr); | ||
| 258 | if (mmio_region) { | ||
| 259 | return mmio_region->IsValidAddress(vaddr); | ||
| 260 | } | ||
| 261 | |||
| 262 | return false; | ||
| 263 | } | ||
| 264 | |||
| 265 | bool IsValidPhysicalAddress(const PAddr paddr) { | ||
| 266 | return IsValidVirtualAddress(PhysicalToVirtualAddress(paddr)); | ||
| 267 | } | ||
| 268 | |||
| 249 | u8* GetPointer(const VAddr vaddr) { | 269 | u8* GetPointer(const VAddr vaddr) { |
| 250 | u8* page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS]; | 270 | u8* page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS]; |
| 251 | if (page_pointer) { | 271 | if (page_pointer) { |
| @@ -261,6 +281,7 @@ u8* GetPointer(const VAddr vaddr) { | |||
| 261 | } | 281 | } |
| 262 | 282 | ||
| 263 | u8* GetPhysicalPointer(PAddr address) { | 283 | u8* GetPhysicalPointer(PAddr address) { |
| 284 | // TODO(Subv): This call should not go through the application's memory mapping. | ||
| 264 | return GetPointer(PhysicalToVirtualAddress(address)); | 285 | return GetPointer(PhysicalToVirtualAddress(address)); |
| 265 | } | 286 | } |
| 266 | 287 | ||
diff --git a/src/core/memory.h b/src/core/memory.h index 126d60471..9ada78fc8 100644 --- a/src/core/memory.h +++ b/src/core/memory.h | |||
| @@ -110,6 +110,9 @@ enum : VAddr { | |||
| 110 | NEW_LINEAR_HEAP_VADDR_END = NEW_LINEAR_HEAP_VADDR + NEW_LINEAR_HEAP_SIZE, | 110 | NEW_LINEAR_HEAP_VADDR_END = NEW_LINEAR_HEAP_VADDR + NEW_LINEAR_HEAP_SIZE, |
| 111 | }; | 111 | }; |
| 112 | 112 | ||
| 113 | bool IsValidVirtualAddress(const VAddr addr); | ||
| 114 | bool IsValidPhysicalAddress(const PAddr addr); | ||
| 115 | |||
| 113 | u8 Read8(VAddr addr); | 116 | u8 Read8(VAddr addr); |
| 114 | u16 Read16(VAddr addr); | 117 | u16 Read16(VAddr addr); |
| 115 | u32 Read32(VAddr addr); | 118 | u32 Read32(VAddr addr); |
diff --git a/src/core/mmio.h b/src/core/mmio.h index 06b555e98..cb644f51b 100644 --- a/src/core/mmio.h +++ b/src/core/mmio.h | |||
| @@ -18,6 +18,8 @@ class MMIORegion { | |||
| 18 | public: | 18 | public: |
| 19 | virtual ~MMIORegion() = default; | 19 | virtual ~MMIORegion() = default; |
| 20 | 20 | ||
| 21 | virtual bool IsValidAddress(VAddr addr) = 0; | ||
| 22 | |||
| 21 | virtual u8 Read8(VAddr addr) = 0; | 23 | virtual u8 Read8(VAddr addr) = 0; |
| 22 | virtual u16 Read16(VAddr addr) = 0; | 24 | virtual u16 Read16(VAddr addr) = 0; |
| 23 | virtual u32 Read32(VAddr addr) = 0; | 25 | virtual u32 Read32(VAddr addr) = 0; |