memory.cpp 21 KB

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