memory.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 "common/common_types.h"
  7. namespace Memory {
  8. /**
  9. * Page size used by the ARM architecture. This is the smallest granularity with which memory can
  10. * be mapped.
  11. */
  12. const u32 PAGE_SIZE = 0x1000;
  13. /// Physical memory regions as seen from the ARM11
  14. enum : PAddr {
  15. /// IO register area
  16. IO_AREA_PADDR = 0x10100000,
  17. IO_AREA_SIZE = 0x01000000, ///< IO area size (16MB)
  18. IO_AREA_PADDR_END = IO_AREA_PADDR + IO_AREA_SIZE,
  19. /// MPCore internal memory region
  20. MPCORE_RAM_PADDR = 0x17E00000,
  21. MPCORE_RAM_SIZE = 0x00002000, ///< MPCore internal memory size (8KB)
  22. MPCORE_RAM_PADDR_END = MPCORE_RAM_PADDR + MPCORE_RAM_SIZE,
  23. /// Video memory
  24. VRAM_PADDR = 0x18000000,
  25. VRAM_SIZE = 0x00600000, ///< VRAM size (6MB)
  26. VRAM_PADDR_END = VRAM_PADDR + VRAM_SIZE,
  27. /// DSP memory
  28. DSP_RAM_PADDR = 0x1FF00000,
  29. DSP_RAM_SIZE = 0x00080000, ///< DSP memory size (512KB)
  30. DSP_RAM_PADDR_END = DSP_RAM_PADDR + DSP_RAM_SIZE,
  31. /// AXI WRAM
  32. AXI_WRAM_PADDR = 0x1FF80000,
  33. AXI_WRAM_SIZE = 0x00080000, ///< AXI WRAM size (512KB)
  34. AXI_WRAM_PADDR_END = AXI_WRAM_PADDR + AXI_WRAM_SIZE,
  35. /// Main FCRAM
  36. FCRAM_PADDR = 0x20000000,
  37. FCRAM_SIZE = 0x08000000, ///< FCRAM size (128MB)
  38. FCRAM_PADDR_END = FCRAM_PADDR + FCRAM_SIZE,
  39. };
  40. /// Virtual user-space memory regions
  41. enum : VAddr {
  42. /// Where the application text, data and bss reside.
  43. PROCESS_IMAGE_VADDR = 0x00100000,
  44. PROCESS_IMAGE_MAX_SIZE = 0x03F00000,
  45. PROCESS_IMAGE_VADDR_END = PROCESS_IMAGE_VADDR + PROCESS_IMAGE_MAX_SIZE,
  46. /// Area where IPC buffers are mapped onto.
  47. IPC_MAPPING_VADDR = 0x04000000,
  48. IPC_MAPPING_SIZE = 0x04000000,
  49. IPC_MAPPING_VADDR_END = IPC_MAPPING_VADDR + IPC_MAPPING_SIZE,
  50. /// Application heap (includes stack).
  51. HEAP_VADDR = 0x08000000,
  52. HEAP_SIZE = 0x08000000,
  53. HEAP_VADDR_END = HEAP_VADDR + HEAP_SIZE,
  54. /// Area where shared memory buffers are mapped onto.
  55. SHARED_MEMORY_VADDR = 0x10000000,
  56. SHARED_MEMORY_SIZE = 0x04000000,
  57. SHARED_MEMORY_VADDR_END = SHARED_MEMORY_VADDR + SHARED_MEMORY_SIZE,
  58. /// Maps 1:1 to an offset in FCRAM. Used for HW allocations that need to be linear in physical memory.
  59. LINEAR_HEAP_VADDR = 0x14000000,
  60. LINEAR_HEAP_SIZE = 0x08000000,
  61. LINEAR_HEAP_VADDR_END = LINEAR_HEAP_VADDR + LINEAR_HEAP_SIZE,
  62. /// Maps 1:1 to the IO register area.
  63. IO_AREA_VADDR = 0x1EC00000,
  64. IO_AREA_VADDR_END = IO_AREA_VADDR + IO_AREA_SIZE,
  65. /// Maps 1:1 to VRAM.
  66. VRAM_VADDR = 0x1F000000,
  67. VRAM_VADDR_END = VRAM_VADDR + VRAM_SIZE,
  68. /// Maps 1:1 to DSP memory.
  69. DSP_RAM_VADDR = 0x1FF00000,
  70. DSP_RAM_VADDR_END = DSP_RAM_VADDR + DSP_RAM_SIZE,
  71. /// Read-only page containing kernel and system configuration values.
  72. CONFIG_MEMORY_VADDR = 0x1FF80000,
  73. CONFIG_MEMORY_SIZE = 0x00001000,
  74. CONFIG_MEMORY_VADDR_END = CONFIG_MEMORY_VADDR + CONFIG_MEMORY_SIZE,
  75. /// Usually read-only page containing mostly values read from hardware.
  76. SHARED_PAGE_VADDR = 0x1FF81000,
  77. SHARED_PAGE_SIZE = 0x00001000,
  78. SHARED_PAGE_VADDR_END = SHARED_PAGE_VADDR + SHARED_PAGE_SIZE,
  79. // TODO(yuriks): The size of this area is dynamic, the kernel grows
  80. // it as more and more threads are created. For now we'll just use a
  81. // hardcoded value.
  82. /// Area where TLS (Thread-Local Storage) buffers are allocated.
  83. TLS_AREA_VADDR = 0x1FF82000,
  84. TLS_AREA_SIZE = 0x00030000, // Each TLS buffer is 0x200 bytes, allows for 300 threads
  85. TLS_AREA_VADDR_END = TLS_AREA_VADDR + TLS_AREA_SIZE,
  86. };
  87. u8 Read8(VAddr addr);
  88. u16 Read16(VAddr addr);
  89. u32 Read32(VAddr addr);
  90. u64 Read64(VAddr addr);
  91. void Write8(VAddr addr, u8 data);
  92. void Write16(VAddr addr, u16 data);
  93. void Write32(VAddr addr, u32 data);
  94. void Write64(VAddr addr, u64 data);
  95. void WriteBlock(VAddr addr, const u8* data, size_t size);
  96. u8* GetPointer(VAddr virtual_address);
  97. /**
  98. * Gets a pointer to the memory region beginning at the specified physical address.
  99. *
  100. * @note This is currently implemented using PhysicalToVirtualAddress().
  101. */
  102. u8* GetPhysicalPointer(PAddr address);
  103. }