memory.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 Kernel {
  9. class Process;
  10. }
  11. namespace Memory {
  12. /**
  13. * Page size used by the ARM architecture. This is the smallest granularity with which memory can
  14. * be mapped.
  15. */
  16. constexpr std::size_t PAGE_BITS = 12;
  17. constexpr u64 PAGE_SIZE = 1ULL << PAGE_BITS;
  18. constexpr u64 PAGE_MASK = PAGE_SIZE - 1;
  19. /// Virtual user-space memory regions
  20. enum : VAddr {
  21. /// TLS (Thread-Local Storage) related.
  22. TLS_ENTRY_SIZE = 0x200,
  23. /// Application stack
  24. DEFAULT_STACK_SIZE = 0x100000,
  25. /// Kernel Virtual Address Range
  26. KERNEL_REGION_VADDR = 0xFFFFFF8000000000,
  27. KERNEL_REGION_SIZE = 0x7FFFE00000,
  28. KERNEL_REGION_END = KERNEL_REGION_VADDR + KERNEL_REGION_SIZE,
  29. };
  30. /// Changes the currently active page table to that of
  31. /// the given process instance.
  32. void SetCurrentPageTable(Kernel::Process& process);
  33. /// Determines if the given VAddr is valid for the specified process.
  34. bool IsValidVirtualAddress(const Kernel::Process& process, VAddr vaddr);
  35. bool IsValidVirtualAddress(VAddr vaddr);
  36. /// Determines if the given VAddr is a kernel address
  37. bool IsKernelVirtualAddress(VAddr vaddr);
  38. u8 Read8(VAddr addr);
  39. u16 Read16(VAddr addr);
  40. u32 Read32(VAddr addr);
  41. u64 Read64(VAddr addr);
  42. void Write8(VAddr addr, u8 data);
  43. void Write16(VAddr addr, u16 data);
  44. void Write32(VAddr addr, u32 data);
  45. void Write64(VAddr addr, u64 data);
  46. void ReadBlock(const Kernel::Process& process, VAddr src_addr, void* dest_buffer, std::size_t size);
  47. void ReadBlock(VAddr src_addr, void* dest_buffer, std::size_t size);
  48. void WriteBlock(const Kernel::Process& process, VAddr dest_addr, const void* src_buffer,
  49. std::size_t size);
  50. void WriteBlock(VAddr dest_addr, const void* src_buffer, std::size_t size);
  51. void ZeroBlock(const Kernel::Process& process, VAddr dest_addr, std::size_t size);
  52. void CopyBlock(VAddr dest_addr, VAddr src_addr, std::size_t size);
  53. u8* GetPointer(VAddr vaddr);
  54. std::string ReadCString(VAddr vaddr, std::size_t max_length);
  55. /**
  56. * Mark each page touching the region as cached.
  57. */
  58. void RasterizerMarkRegionCached(VAddr vaddr, u64 size, bool cached);
  59. } // namespace Memory