memory.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <cstddef>
  6. #include <string>
  7. #include "common/common_types.h"
  8. namespace Common {
  9. struct PageTable;
  10. }
  11. namespace Kernel {
  12. class Process;
  13. }
  14. namespace Memory {
  15. /**
  16. * Page size used by the ARM architecture. This is the smallest granularity with which memory can
  17. * be mapped.
  18. */
  19. constexpr std::size_t PAGE_BITS = 12;
  20. constexpr u64 PAGE_SIZE = 1ULL << PAGE_BITS;
  21. constexpr u64 PAGE_MASK = PAGE_SIZE - 1;
  22. /// Virtual user-space memory regions
  23. enum : VAddr {
  24. /// TLS (Thread-Local Storage) related.
  25. TLS_ENTRY_SIZE = 0x200,
  26. /// Application stack
  27. DEFAULT_STACK_SIZE = 0x100000,
  28. /// Kernel Virtual Address Range
  29. KERNEL_REGION_VADDR = 0xFFFFFF8000000000,
  30. KERNEL_REGION_SIZE = 0x7FFFE00000,
  31. KERNEL_REGION_END = KERNEL_REGION_VADDR + KERNEL_REGION_SIZE,
  32. };
  33. /// Changes the currently active page table.
  34. void SetCurrentPageTable(Common::PageTable* page_table);
  35. /// Determines if the given VAddr is valid for the specified process.
  36. bool IsValidVirtualAddress(const Kernel::Process& process, VAddr vaddr);
  37. bool IsValidVirtualAddress(VAddr vaddr);
  38. /// Determines if the given VAddr is a kernel address
  39. bool IsKernelVirtualAddress(VAddr vaddr);
  40. u8 Read8(VAddr addr);
  41. u16 Read16(VAddr addr);
  42. u32 Read32(VAddr addr);
  43. u64 Read64(VAddr addr);
  44. void Write8(VAddr addr, u8 data);
  45. void Write16(VAddr addr, u16 data);
  46. void Write32(VAddr addr, u32 data);
  47. void Write64(VAddr addr, u64 data);
  48. void ReadBlock(const Kernel::Process& process, VAddr src_addr, void* dest_buffer, std::size_t size);
  49. void ReadBlock(VAddr src_addr, void* dest_buffer, std::size_t size);
  50. void WriteBlock(const Kernel::Process& process, VAddr dest_addr, const void* src_buffer,
  51. std::size_t size);
  52. void WriteBlock(VAddr dest_addr, const void* src_buffer, std::size_t size);
  53. void ZeroBlock(const Kernel::Process& process, VAddr dest_addr, std::size_t size);
  54. void CopyBlock(VAddr dest_addr, VAddr src_addr, std::size_t size);
  55. u8* GetPointer(VAddr vaddr);
  56. std::string ReadCString(VAddr vaddr, std::size_t max_length);
  57. enum class FlushMode {
  58. /// Write back modified surfaces to RAM
  59. Flush,
  60. /// Remove region from the cache
  61. Invalidate,
  62. /// Write back modified surfaces to RAM, and also remove them from the cache
  63. FlushAndInvalidate,
  64. };
  65. /**
  66. * Mark each page touching the region as cached.
  67. */
  68. void RasterizerMarkRegionCached(VAddr vaddr, u64 size, bool cached);
  69. } // namespace Memory