summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMerryMage <MerryMage@users.noreply.github.com>2016-04-16 16:22:45 +0200
committerSubv <subv2112@gmail.com>2016-05-28 20:44:49 +0200
commit31d49e01094068519850bbfa414f314fdb27beee (patch)
tree088a73db78fdcd567c3e4850c4add8c4d6a6522e
parentDSP_DSP: Remove use of Memory::GetPointer (diff)
downloadyuzu-31d49e01094068519850bbfa414f314fdb27beee.tar
yuzu-31d49e01094068519850bbfa414f314fdb27beee.tar.gz
yuzu-31d49e01094068519850bbfa414f314fdb27beee.tar.bz2
yuzu-31d49e01094068519850bbfa414f314fdb27beee.tar.lz
yuzu-31d49e01094068519850bbfa414f314fdb27beee.tar.xz
yuzu-31d49e01094068519850bbfa414f314fdb27beee.tar.zst
yuzu-31d49e01094068519850bbfa414f314fdb27beee.zip
-rw-r--r--src/core/memory.cpp41
-rw-r--r--src/core/memory.h4
2 files changed, 43 insertions, 2 deletions
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index 1604a7da5..bf2493270 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -495,6 +495,47 @@ void ZeroBlock(const VAddr dest_addr, const size_t size) {
}
}
+void CopyBlock(VAddr dest_addr, VAddr src_addr, const size_t size) {
+ size_t remaining_size = size;
+ size_t page_index = src_addr >> PAGE_BITS;
+ size_t page_offset = src_addr & PAGE_MASK;
+
+ while (remaining_size > 0) {
+ const size_t copy_amount = std::min(PAGE_SIZE - page_offset, remaining_size);
+ const VAddr current_vaddr = (page_index << PAGE_BITS) + page_offset;
+
+ switch (current_page_table->attributes[page_index]) {
+ case PageType::Unmapped: {
+ LOG_ERROR(HW_Memory, "unmapped CopyBlock @ 0x%08X (start address = 0x%08X, size = %zu)", current_vaddr, src_addr, size);
+ ZeroBlock(dest_addr, copy_amount);
+ break;
+ }
+ case PageType::Memory: {
+ DEBUG_ASSERT(current_page_table->pointers[page_index]);
+ const u8* src_ptr = current_page_table->pointers[page_index] + page_offset;
+ WriteBlock(dest_addr, src_ptr, copy_amount);
+ break;
+ }
+ case PageType::Special: {
+ DEBUG_ASSERT(GetMMIOHandler(current_vaddr));
+
+ std::vector<u8> buffer(copy_amount);
+ GetMMIOHandler(current_vaddr)->ReadBlock(current_vaddr, buffer.data(), buffer.size());
+ WriteBlock(dest_addr, buffer.data(), buffer.size());
+ break;
+ }
+ default:
+ UNREACHABLE();
+ }
+
+ page_index++;
+ page_offset = 0;
+ dest_addr += copy_amount;
+ src_addr += copy_amount;
+ remaining_size -= copy_amount;
+ }
+}
+
template<>
u8 ReadMMIO<u8>(MMIORegionPointer mmio_handler, VAddr addr) {
return mmio_handler->Read8(addr);
diff --git a/src/core/memory.h b/src/core/memory.h
index 713cdfb2f..bb5dd0d15 100644
--- a/src/core/memory.h
+++ b/src/core/memory.h
@@ -118,15 +118,15 @@ u16 Read16(VAddr addr);
u32 Read32(VAddr addr);
u64 Read64(VAddr addr);
-void ReadBlock(const VAddr src_addr, u8* dest_buffer, size_t size);
-
void Write8(VAddr addr, u8 data);
void Write16(VAddr addr, u16 data);
void Write32(VAddr addr, u32 data);
void Write64(VAddr addr, u64 data);
+void ReadBlock(const VAddr src_addr, u8* dest_buffer, size_t size);
void WriteBlock(const VAddr dest_addr, const u8* src_buffer, size_t size);
void ZeroBlock(const VAddr dest_addr, const size_t size);
+void CopyBlock(VAddr dest_addr, VAddr src_addr, size_t size);
u8* GetPointer(VAddr virtual_address);