diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/memory.cpp | 51 |
1 files changed, 15 insertions, 36 deletions
diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 2e578f189..0b8e36b08 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp | |||
| @@ -176,7 +176,7 @@ struct Memory::Impl { | |||
| 176 | return string; | 176 | return string; |
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | void WalkBlock(const Kernel::KProcess& process, VAddr addr, const std::size_t size, | 179 | void WalkBlock(const Kernel::KProcess& process, const VAddr addr, const std::size_t size, |
| 180 | auto on_unmapped, auto on_memory, auto on_rasterizer, auto increment) { | 180 | auto on_unmapped, auto on_memory, auto on_rasterizer, auto increment) { |
| 181 | const auto& page_table = process.PageTable().PageTableImpl(); | 181 | const auto& page_table = process.PageTable().PageTableImpl(); |
| 182 | std::size_t remaining_size = size; | 182 | std::size_t remaining_size = size; |
| @@ -211,7 +211,6 @@ struct Memory::Impl { | |||
| 211 | 211 | ||
| 212 | page_index++; | 212 | page_index++; |
| 213 | page_offset = 0; | 213 | page_offset = 0; |
| 214 | addr += static_cast<VAddr>(copy_amount); | ||
| 215 | increment(copy_amount); | 214 | increment(copy_amount); |
| 216 | remaining_size -= copy_amount; | 215 | remaining_size -= copy_amount; |
| 217 | } | 216 | } |
| @@ -307,47 +306,27 @@ struct Memory::Impl { | |||
| 307 | 306 | ||
| 308 | void CopyBlock(const Kernel::KProcess& process, VAddr dest_addr, VAddr src_addr, | 307 | void CopyBlock(const Kernel::KProcess& process, VAddr dest_addr, VAddr src_addr, |
| 309 | const std::size_t size) { | 308 | const std::size_t size) { |
| 310 | const auto& page_table = process.PageTable().PageTableImpl(); | 309 | WalkBlock( |
| 311 | std::size_t remaining_size = size; | 310 | process, dest_addr, size, |
| 312 | std::size_t page_index = src_addr >> PAGE_BITS; | 311 | [this, &process, &dest_addr, &src_addr, size](const std::size_t copy_amount, |
| 313 | std::size_t page_offset = src_addr & PAGE_MASK; | 312 | const VAddr current_vaddr) { |
| 314 | |||
| 315 | while (remaining_size) { | ||
| 316 | const std::size_t copy_amount = | ||
| 317 | std::min(static_cast<std::size_t>(PAGE_SIZE) - page_offset, remaining_size); | ||
| 318 | const auto current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset); | ||
| 319 | |||
| 320 | const auto [pointer, type] = page_table.pointers[page_index].PointerType(); | ||
| 321 | switch (type) { | ||
| 322 | case Common::PageType::Unmapped: { | ||
| 323 | LOG_ERROR(HW_Memory, | 313 | LOG_ERROR(HW_Memory, |
| 324 | "Unmapped CopyBlock @ 0x{:016X} (start address = 0x{:016X}, size = {})", | 314 | "Unmapped CopyBlock @ 0x{:016X} (start address = 0x{:016X}, size = {})", |
| 325 | current_vaddr, src_addr, size); | 315 | current_vaddr, src_addr, size); |
| 326 | ZeroBlock(process, dest_addr, copy_amount); | 316 | ZeroBlock(process, dest_addr, copy_amount); |
| 327 | break; | 317 | }, |
| 328 | } | 318 | [this, &process, &dest_addr](const std::size_t copy_amount, const u8* const src_ptr) { |
| 329 | case Common::PageType::Memory: { | ||
| 330 | DEBUG_ASSERT(pointer); | ||
| 331 | const u8* src_ptr = pointer + page_offset + (page_index << PAGE_BITS); | ||
| 332 | WriteBlockImpl<false>(process, dest_addr, src_ptr, copy_amount); | 319 | WriteBlockImpl<false>(process, dest_addr, src_ptr, copy_amount); |
| 333 | break; | 320 | }, |
| 334 | } | 321 | [this, &system = system, &process, &dest_addr]( |
| 335 | case Common::PageType::RasterizerCachedMemory: { | 322 | const VAddr current_vaddr, const std::size_t copy_amount, u8* const host_ptr) { |
| 336 | const u8* const host_ptr{GetPointerFromRasterizerCachedMemory(current_vaddr)}; | ||
| 337 | system.GPU().FlushRegion(current_vaddr, copy_amount); | 323 | system.GPU().FlushRegion(current_vaddr, copy_amount); |
| 338 | WriteBlockImpl<false>(process, dest_addr, host_ptr, copy_amount); | 324 | WriteBlockImpl<false>(process, dest_addr, host_ptr, copy_amount); |
| 339 | break; | 325 | }, |
| 340 | } | 326 | [&dest_addr, &src_addr](const std::size_t copy_amount) { |
| 341 | default: | 327 | dest_addr += static_cast<VAddr>(copy_amount); |
| 342 | UNREACHABLE(); | 328 | src_addr += static_cast<VAddr>(copy_amount); |
| 343 | } | 329 | }); |
| 344 | |||
| 345 | page_index++; | ||
| 346 | page_offset = 0; | ||
| 347 | dest_addr += static_cast<VAddr>(copy_amount); | ||
| 348 | src_addr += static_cast<VAddr>(copy_amount); | ||
| 349 | remaining_size -= copy_amount; | ||
| 350 | } | ||
| 351 | } | 330 | } |
| 352 | 331 | ||
| 353 | void RasterizerMarkRegionCached(VAddr vaddr, u64 size, bool cached) { | 332 | void RasterizerMarkRegionCached(VAddr vaddr, u64 size, bool cached) { |