From 31d49e01094068519850bbfa414f314fdb27beee Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sat, 16 Apr 2016 15:22:45 +0100 Subject: Memory: CopyBlock --- src/core/memory.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ src/core/memory.h | 4 ++-- 2 files changed, 43 insertions(+), 2 deletions(-) (limited to 'src/core') 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 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(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); -- cgit v1.2.3