memory.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. // Copyright 2015 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <algorithm>
  5. #include <cstring>
  6. #include <optional>
  7. #include <utility>
  8. #include "common/assert.h"
  9. #include "common/common_types.h"
  10. #include "common/logging/log.h"
  11. #include "common/swap.h"
  12. #include "core/arm/arm_interface.h"
  13. #include "core/core.h"
  14. #include "core/hle/kernel/process.h"
  15. #include "core/hle/kernel/vm_manager.h"
  16. #include "core/hle/lock.h"
  17. #include "core/memory.h"
  18. #include "core/memory_setup.h"
  19. #include "video_core/renderer_base.h"
  20. namespace Memory {
  21. static PageTable* current_page_table = nullptr;
  22. void SetCurrentPageTable(PageTable* page_table) {
  23. current_page_table = page_table;
  24. auto& system = Core::System::GetInstance();
  25. if (system.IsPoweredOn()) {
  26. system.ArmInterface(0).PageTableChanged();
  27. system.ArmInterface(1).PageTableChanged();
  28. system.ArmInterface(2).PageTableChanged();
  29. system.ArmInterface(3).PageTableChanged();
  30. }
  31. }
  32. PageTable* GetCurrentPageTable() {
  33. return current_page_table;
  34. }
  35. PageTable::PageTable() = default;
  36. PageTable::PageTable(std::size_t address_space_width_in_bits) {
  37. Resize(address_space_width_in_bits);
  38. }
  39. PageTable::~PageTable() = default;
  40. void PageTable::Resize(std::size_t address_space_width_in_bits) {
  41. const std::size_t num_page_table_entries = 1ULL << (address_space_width_in_bits - PAGE_BITS);
  42. pointers.resize(num_page_table_entries);
  43. attributes.resize(num_page_table_entries);
  44. }
  45. static void MapPages(PageTable& page_table, VAddr base, u64 size, u8* memory, PageType type) {
  46. LOG_DEBUG(HW_Memory, "Mapping {} onto {:016X}-{:016X}", fmt::ptr(memory), base * PAGE_SIZE,
  47. (base + size) * PAGE_SIZE);
  48. RasterizerFlushVirtualRegion(base << PAGE_BITS, size * PAGE_SIZE,
  49. FlushMode::FlushAndInvalidate);
  50. VAddr end = base + size;
  51. while (base != end) {
  52. ASSERT_MSG(base < page_table.pointers.size(), "out of range mapping at {:016X}", base);
  53. page_table.attributes[base] = type;
  54. page_table.pointers[base] = memory;
  55. base += 1;
  56. if (memory != nullptr)
  57. memory += PAGE_SIZE;
  58. }
  59. }
  60. void MapMemoryRegion(PageTable& page_table, VAddr base, u64 size, u8* target) {
  61. ASSERT_MSG((size & PAGE_MASK) == 0, "non-page aligned size: {:016X}", size);
  62. ASSERT_MSG((base & PAGE_MASK) == 0, "non-page aligned base: {:016X}", base);
  63. MapPages(page_table, base / PAGE_SIZE, size / PAGE_SIZE, target, PageType::Memory);
  64. }
  65. void MapIoRegion(PageTable& page_table, VAddr base, u64 size, MemoryHookPointer mmio_handler) {
  66. ASSERT_MSG((size & PAGE_MASK) == 0, "non-page aligned size: {:016X}", size);
  67. ASSERT_MSG((base & PAGE_MASK) == 0, "non-page aligned base: {:016X}", base);
  68. MapPages(page_table, base / PAGE_SIZE, size / PAGE_SIZE, nullptr, PageType::Special);
  69. auto interval = boost::icl::discrete_interval<VAddr>::closed(base, base + size - 1);
  70. SpecialRegion region{SpecialRegion::Type::IODevice, std::move(mmio_handler)};
  71. page_table.special_regions.add(std::make_pair(interval, std::set<SpecialRegion>{region}));
  72. }
  73. void UnmapRegion(PageTable& page_table, VAddr base, u64 size) {
  74. ASSERT_MSG((size & PAGE_MASK) == 0, "non-page aligned size: {:016X}", size);
  75. ASSERT_MSG((base & PAGE_MASK) == 0, "non-page aligned base: {:016X}", base);
  76. MapPages(page_table, base / PAGE_SIZE, size / PAGE_SIZE, nullptr, PageType::Unmapped);
  77. auto interval = boost::icl::discrete_interval<VAddr>::closed(base, base + size - 1);
  78. page_table.special_regions.erase(interval);
  79. }
  80. void AddDebugHook(PageTable& page_table, VAddr base, u64 size, MemoryHookPointer hook) {
  81. auto interval = boost::icl::discrete_interval<VAddr>::closed(base, base + size - 1);
  82. SpecialRegion region{SpecialRegion::Type::DebugHook, std::move(hook)};
  83. page_table.special_regions.add(std::make_pair(interval, std::set<SpecialRegion>{region}));
  84. }
  85. void RemoveDebugHook(PageTable& page_table, VAddr base, u64 size, MemoryHookPointer hook) {
  86. auto interval = boost::icl::discrete_interval<VAddr>::closed(base, base + size - 1);
  87. SpecialRegion region{SpecialRegion::Type::DebugHook, std::move(hook)};
  88. page_table.special_regions.subtract(std::make_pair(interval, std::set<SpecialRegion>{region}));
  89. }
  90. /**
  91. * Gets a pointer to the exact memory at the virtual address (i.e. not page aligned)
  92. * using a VMA from the current process
  93. */
  94. static u8* GetPointerFromVMA(const Kernel::Process& process, VAddr vaddr) {
  95. u8* direct_pointer = nullptr;
  96. auto& vm_manager = process.VMManager();
  97. auto it = vm_manager.FindVMA(vaddr);
  98. ASSERT(it != vm_manager.vma_map.end());
  99. auto& vma = it->second;
  100. switch (vma.type) {
  101. case Kernel::VMAType::AllocatedMemoryBlock:
  102. direct_pointer = vma.backing_block->data() + vma.offset;
  103. break;
  104. case Kernel::VMAType::BackingMemory:
  105. direct_pointer = vma.backing_memory;
  106. break;
  107. case Kernel::VMAType::Free:
  108. return nullptr;
  109. default:
  110. UNREACHABLE();
  111. }
  112. return direct_pointer + (vaddr - vma.base);
  113. }
  114. /**
  115. * Gets a pointer to the exact memory at the virtual address (i.e. not page aligned)
  116. * using a VMA from the current process.
  117. */
  118. static u8* GetPointerFromVMA(VAddr vaddr) {
  119. return GetPointerFromVMA(*Core::CurrentProcess(), vaddr);
  120. }
  121. template <typename T>
  122. T Read(const VAddr vaddr) {
  123. const u8* page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS];
  124. if (page_pointer) {
  125. // NOTE: Avoid adding any extra logic to this fast-path block
  126. T value;
  127. std::memcpy(&value, &page_pointer[vaddr & PAGE_MASK], sizeof(T));
  128. return value;
  129. }
  130. // The memory access might do an MMIO or cached access, so we have to lock the HLE kernel state
  131. std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock);
  132. PageType type = current_page_table->attributes[vaddr >> PAGE_BITS];
  133. switch (type) {
  134. case PageType::Unmapped:
  135. LOG_ERROR(HW_Memory, "Unmapped Read{} @ 0x{:08X}", sizeof(T) * 8, vaddr);
  136. return 0;
  137. case PageType::Memory:
  138. ASSERT_MSG(false, "Mapped memory page without a pointer @ {:016X}", vaddr);
  139. break;
  140. case PageType::RasterizerCachedMemory: {
  141. RasterizerFlushVirtualRegion(vaddr, sizeof(T), FlushMode::Flush);
  142. T value;
  143. std::memcpy(&value, GetPointerFromVMA(vaddr), sizeof(T));
  144. return value;
  145. }
  146. default:
  147. UNREACHABLE();
  148. }
  149. }
  150. template <typename T>
  151. void Write(const VAddr vaddr, const T data) {
  152. u8* page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS];
  153. if (page_pointer) {
  154. // NOTE: Avoid adding any extra logic to this fast-path block
  155. std::memcpy(&page_pointer[vaddr & PAGE_MASK], &data, sizeof(T));
  156. return;
  157. }
  158. // The memory access might do an MMIO or cached access, so we have to lock the HLE kernel state
  159. std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock);
  160. PageType type = current_page_table->attributes[vaddr >> PAGE_BITS];
  161. switch (type) {
  162. case PageType::Unmapped:
  163. LOG_ERROR(HW_Memory, "Unmapped Write{} 0x{:08X} @ 0x{:016X}", sizeof(data) * 8,
  164. static_cast<u32>(data), vaddr);
  165. return;
  166. case PageType::Memory:
  167. ASSERT_MSG(false, "Mapped memory page without a pointer @ {:016X}", vaddr);
  168. break;
  169. case PageType::RasterizerCachedMemory: {
  170. RasterizerFlushVirtualRegion(vaddr, sizeof(T), FlushMode::Invalidate);
  171. std::memcpy(GetPointerFromVMA(vaddr), &data, sizeof(T));
  172. break;
  173. }
  174. default:
  175. UNREACHABLE();
  176. }
  177. }
  178. bool IsValidVirtualAddress(const Kernel::Process& process, const VAddr vaddr) {
  179. const auto& page_table = process.VMManager().page_table;
  180. const u8* page_pointer = page_table.pointers[vaddr >> PAGE_BITS];
  181. if (page_pointer)
  182. return true;
  183. if (page_table.attributes[vaddr >> PAGE_BITS] == PageType::RasterizerCachedMemory)
  184. return true;
  185. if (page_table.attributes[vaddr >> PAGE_BITS] != PageType::Special)
  186. return false;
  187. return false;
  188. }
  189. bool IsValidVirtualAddress(const VAddr vaddr) {
  190. return IsValidVirtualAddress(*Core::CurrentProcess(), vaddr);
  191. }
  192. bool IsKernelVirtualAddress(const VAddr vaddr) {
  193. return KERNEL_REGION_VADDR <= vaddr && vaddr < KERNEL_REGION_END;
  194. }
  195. u8* GetPointer(const VAddr vaddr) {
  196. u8* page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS];
  197. if (page_pointer) {
  198. return page_pointer + (vaddr & PAGE_MASK);
  199. }
  200. if (current_page_table->attributes[vaddr >> PAGE_BITS] == PageType::RasterizerCachedMemory) {
  201. return GetPointerFromVMA(vaddr);
  202. }
  203. LOG_ERROR(HW_Memory, "Unknown GetPointer @ 0x{:016X}", vaddr);
  204. return nullptr;
  205. }
  206. std::string ReadCString(VAddr vaddr, std::size_t max_length) {
  207. std::string string;
  208. string.reserve(max_length);
  209. for (std::size_t i = 0; i < max_length; ++i) {
  210. char c = Read8(vaddr);
  211. if (c == '\0')
  212. break;
  213. string.push_back(c);
  214. ++vaddr;
  215. }
  216. string.shrink_to_fit();
  217. return string;
  218. }
  219. void RasterizerMarkRegionCached(VAddr vaddr, u64 size, bool cached) {
  220. if (vaddr == 0) {
  221. return;
  222. }
  223. // Iterate over a contiguous CPU address space, which corresponds to the specified GPU address
  224. // space, marking the region as un/cached. The region is marked un/cached at a granularity of
  225. // CPU pages, hence why we iterate on a CPU page basis (note: GPU page size is different). This
  226. // assumes the specified GPU address region is contiguous as well.
  227. u64 num_pages = ((vaddr + size - 1) >> PAGE_BITS) - (vaddr >> PAGE_BITS) + 1;
  228. for (unsigned i = 0; i < num_pages; ++i, vaddr += PAGE_SIZE) {
  229. PageType& page_type = current_page_table->attributes[vaddr >> PAGE_BITS];
  230. if (cached) {
  231. // Switch page type to cached if now cached
  232. switch (page_type) {
  233. case PageType::Unmapped:
  234. // It is not necessary for a process to have this region mapped into its address
  235. // space, for example, a system module need not have a VRAM mapping.
  236. break;
  237. case PageType::Memory:
  238. page_type = PageType::RasterizerCachedMemory;
  239. current_page_table->pointers[vaddr >> PAGE_BITS] = nullptr;
  240. break;
  241. case PageType::RasterizerCachedMemory:
  242. // There can be more than one GPU region mapped per CPU region, so it's common that
  243. // this area is already marked as cached.
  244. break;
  245. default:
  246. UNREACHABLE();
  247. }
  248. } else {
  249. // Switch page type to uncached if now uncached
  250. switch (page_type) {
  251. case PageType::Unmapped:
  252. // It is not necessary for a process to have this region mapped into its address
  253. // space, for example, a system module need not have a VRAM mapping.
  254. break;
  255. case PageType::Memory:
  256. // There can be more than one GPU region mapped per CPU region, so it's common that
  257. // this area is already unmarked as cached.
  258. break;
  259. case PageType::RasterizerCachedMemory: {
  260. u8* pointer = GetPointerFromVMA(vaddr & ~PAGE_MASK);
  261. if (pointer == nullptr) {
  262. // It's possible that this function has been called while updating the pagetable
  263. // after unmapping a VMA. In that case the underlying VMA will no longer exist,
  264. // and we should just leave the pagetable entry blank.
  265. page_type = PageType::Unmapped;
  266. } else {
  267. page_type = PageType::Memory;
  268. current_page_table->pointers[vaddr >> PAGE_BITS] = pointer;
  269. }
  270. break;
  271. }
  272. default:
  273. UNREACHABLE();
  274. }
  275. }
  276. }
  277. }
  278. void RasterizerFlushVirtualRegion(VAddr start, u64 size, FlushMode mode) {
  279. auto& system_instance = Core::System::GetInstance();
  280. // Since pages are unmapped on shutdown after video core is shutdown, the renderer may be
  281. // null here
  282. if (!system_instance.IsPoweredOn()) {
  283. return;
  284. }
  285. const VAddr end = start + size;
  286. const auto CheckRegion = [&](VAddr region_start, VAddr region_end) {
  287. if (start >= region_end || end <= region_start) {
  288. // No overlap with region
  289. return;
  290. }
  291. const VAddr overlap_start = std::max(start, region_start);
  292. const VAddr overlap_end = std::min(end, region_end);
  293. const VAddr overlap_size = overlap_end - overlap_start;
  294. auto& rasterizer = system_instance.Renderer().Rasterizer();
  295. switch (mode) {
  296. case FlushMode::Flush:
  297. rasterizer.FlushRegion(overlap_start, overlap_size);
  298. break;
  299. case FlushMode::Invalidate:
  300. rasterizer.InvalidateRegion(overlap_start, overlap_size);
  301. break;
  302. case FlushMode::FlushAndInvalidate:
  303. rasterizer.FlushAndInvalidateRegion(overlap_start, overlap_size);
  304. break;
  305. }
  306. };
  307. const auto& vm_manager = Core::CurrentProcess()->VMManager();
  308. CheckRegion(vm_manager.GetCodeRegionBaseAddress(), vm_manager.GetCodeRegionEndAddress());
  309. CheckRegion(vm_manager.GetHeapRegionBaseAddress(), vm_manager.GetHeapRegionEndAddress());
  310. }
  311. u8 Read8(const VAddr addr) {
  312. return Read<u8>(addr);
  313. }
  314. u16 Read16(const VAddr addr) {
  315. return Read<u16_le>(addr);
  316. }
  317. u32 Read32(const VAddr addr) {
  318. return Read<u32_le>(addr);
  319. }
  320. u64 Read64(const VAddr addr) {
  321. return Read<u64_le>(addr);
  322. }
  323. void ReadBlock(const Kernel::Process& process, const VAddr src_addr, void* dest_buffer,
  324. const std::size_t size) {
  325. const auto& page_table = process.VMManager().page_table;
  326. std::size_t remaining_size = size;
  327. std::size_t page_index = src_addr >> PAGE_BITS;
  328. std::size_t page_offset = src_addr & PAGE_MASK;
  329. while (remaining_size > 0) {
  330. const std::size_t copy_amount =
  331. std::min(static_cast<std::size_t>(PAGE_SIZE) - page_offset, remaining_size);
  332. const VAddr current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset);
  333. switch (page_table.attributes[page_index]) {
  334. case PageType::Unmapped: {
  335. LOG_ERROR(HW_Memory,
  336. "Unmapped ReadBlock @ 0x{:016X} (start address = 0x{:016X}, size = {})",
  337. current_vaddr, src_addr, size);
  338. std::memset(dest_buffer, 0, copy_amount);
  339. break;
  340. }
  341. case PageType::Memory: {
  342. DEBUG_ASSERT(page_table.pointers[page_index]);
  343. const u8* src_ptr = page_table.pointers[page_index] + page_offset;
  344. std::memcpy(dest_buffer, src_ptr, copy_amount);
  345. break;
  346. }
  347. case PageType::RasterizerCachedMemory: {
  348. RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount),
  349. FlushMode::Flush);
  350. std::memcpy(dest_buffer, GetPointerFromVMA(process, current_vaddr), copy_amount);
  351. break;
  352. }
  353. default:
  354. UNREACHABLE();
  355. }
  356. page_index++;
  357. page_offset = 0;
  358. dest_buffer = static_cast<u8*>(dest_buffer) + copy_amount;
  359. remaining_size -= copy_amount;
  360. }
  361. }
  362. void ReadBlock(const VAddr src_addr, void* dest_buffer, const std::size_t size) {
  363. ReadBlock(*Core::CurrentProcess(), src_addr, dest_buffer, size);
  364. }
  365. void Write8(const VAddr addr, const u8 data) {
  366. Write<u8>(addr, data);
  367. }
  368. void Write16(const VAddr addr, const u16 data) {
  369. Write<u16_le>(addr, data);
  370. }
  371. void Write32(const VAddr addr, const u32 data) {
  372. Write<u32_le>(addr, data);
  373. }
  374. void Write64(const VAddr addr, const u64 data) {
  375. Write<u64_le>(addr, data);
  376. }
  377. void WriteBlock(const Kernel::Process& process, const VAddr dest_addr, const void* src_buffer,
  378. const std::size_t size) {
  379. const auto& page_table = process.VMManager().page_table;
  380. std::size_t remaining_size = size;
  381. std::size_t page_index = dest_addr >> PAGE_BITS;
  382. std::size_t page_offset = dest_addr & PAGE_MASK;
  383. while (remaining_size > 0) {
  384. const std::size_t copy_amount =
  385. std::min(static_cast<std::size_t>(PAGE_SIZE) - page_offset, remaining_size);
  386. const VAddr current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset);
  387. switch (page_table.attributes[page_index]) {
  388. case PageType::Unmapped: {
  389. LOG_ERROR(HW_Memory,
  390. "Unmapped WriteBlock @ 0x{:016X} (start address = 0x{:016X}, size = {})",
  391. current_vaddr, dest_addr, size);
  392. break;
  393. }
  394. case PageType::Memory: {
  395. DEBUG_ASSERT(page_table.pointers[page_index]);
  396. u8* dest_ptr = page_table.pointers[page_index] + page_offset;
  397. std::memcpy(dest_ptr, src_buffer, copy_amount);
  398. break;
  399. }
  400. case PageType::RasterizerCachedMemory: {
  401. RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount),
  402. FlushMode::Invalidate);
  403. std::memcpy(GetPointerFromVMA(process, current_vaddr), src_buffer, copy_amount);
  404. break;
  405. }
  406. default:
  407. UNREACHABLE();
  408. }
  409. page_index++;
  410. page_offset = 0;
  411. src_buffer = static_cast<const u8*>(src_buffer) + copy_amount;
  412. remaining_size -= copy_amount;
  413. }
  414. }
  415. void WriteBlock(const VAddr dest_addr, const void* src_buffer, const std::size_t size) {
  416. WriteBlock(*Core::CurrentProcess(), dest_addr, src_buffer, size);
  417. }
  418. void ZeroBlock(const Kernel::Process& process, const VAddr dest_addr, const std::size_t size) {
  419. const auto& page_table = process.VMManager().page_table;
  420. std::size_t remaining_size = size;
  421. std::size_t page_index = dest_addr >> PAGE_BITS;
  422. std::size_t page_offset = dest_addr & PAGE_MASK;
  423. while (remaining_size > 0) {
  424. const std::size_t copy_amount =
  425. std::min(static_cast<std::size_t>(PAGE_SIZE) - page_offset, remaining_size);
  426. const VAddr current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset);
  427. switch (page_table.attributes[page_index]) {
  428. case PageType::Unmapped: {
  429. LOG_ERROR(HW_Memory,
  430. "Unmapped ZeroBlock @ 0x{:016X} (start address = 0x{:016X}, size = {})",
  431. current_vaddr, dest_addr, size);
  432. break;
  433. }
  434. case PageType::Memory: {
  435. DEBUG_ASSERT(page_table.pointers[page_index]);
  436. u8* dest_ptr = page_table.pointers[page_index] + page_offset;
  437. std::memset(dest_ptr, 0, copy_amount);
  438. break;
  439. }
  440. case PageType::RasterizerCachedMemory: {
  441. RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount),
  442. FlushMode::Invalidate);
  443. std::memset(GetPointerFromVMA(process, current_vaddr), 0, copy_amount);
  444. break;
  445. }
  446. default:
  447. UNREACHABLE();
  448. }
  449. page_index++;
  450. page_offset = 0;
  451. remaining_size -= copy_amount;
  452. }
  453. }
  454. void CopyBlock(const Kernel::Process& process, VAddr dest_addr, VAddr src_addr,
  455. const std::size_t size) {
  456. const auto& page_table = process.VMManager().page_table;
  457. std::size_t remaining_size = size;
  458. std::size_t page_index = src_addr >> PAGE_BITS;
  459. std::size_t page_offset = src_addr & PAGE_MASK;
  460. while (remaining_size > 0) {
  461. const std::size_t copy_amount =
  462. std::min(static_cast<std::size_t>(PAGE_SIZE) - page_offset, remaining_size);
  463. const VAddr current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset);
  464. switch (page_table.attributes[page_index]) {
  465. case PageType::Unmapped: {
  466. LOG_ERROR(HW_Memory,
  467. "Unmapped CopyBlock @ 0x{:016X} (start address = 0x{:016X}, size = {})",
  468. current_vaddr, src_addr, size);
  469. ZeroBlock(process, dest_addr, copy_amount);
  470. break;
  471. }
  472. case PageType::Memory: {
  473. DEBUG_ASSERT(page_table.pointers[page_index]);
  474. const u8* src_ptr = page_table.pointers[page_index] + page_offset;
  475. WriteBlock(process, dest_addr, src_ptr, copy_amount);
  476. break;
  477. }
  478. case PageType::RasterizerCachedMemory: {
  479. RasterizerFlushVirtualRegion(current_vaddr, static_cast<u32>(copy_amount),
  480. FlushMode::Flush);
  481. WriteBlock(process, dest_addr, GetPointerFromVMA(process, current_vaddr), copy_amount);
  482. break;
  483. }
  484. default:
  485. UNREACHABLE();
  486. }
  487. page_index++;
  488. page_offset = 0;
  489. dest_addr += static_cast<VAddr>(copy_amount);
  490. src_addr += static_cast<VAddr>(copy_amount);
  491. remaining_size -= copy_amount;
  492. }
  493. }
  494. void CopyBlock(VAddr dest_addr, VAddr src_addr, std::size_t size) {
  495. CopyBlock(*Core::CurrentProcess(), dest_addr, src_addr, size);
  496. }
  497. } // namespace Memory