mem_map.cpp 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/common.h"
  5. #include "common/mem_arena.h"
  6. #include "core/mem_map.h"
  7. ////////////////////////////////////////////////////////////////////////////////////////////////////
  8. namespace Memory {
  9. u8* g_base = nullptr; ///< The base pointer to the auto-mirrored arena.
  10. static MemArena arena; ///< The MemArena class
  11. u8* g_exefs_code = nullptr; ///< ExeFS:/.code is loaded here
  12. u8* g_system_mem = nullptr; ///< System memory
  13. u8* g_heap = nullptr; ///< Application heap (main memory)
  14. u8* g_heap_linear = nullptr; ///< Linear heap
  15. u8* g_vram = nullptr; ///< Video memory (VRAM) pointer
  16. u8* g_shared_mem = nullptr; ///< Shared memory
  17. u8* g_dsp_mem = nullptr; ///< DSP memory
  18. u8* g_kernel_mem; ///< Kernel memory
  19. static u8* physical_bootrom = nullptr; ///< Bootrom physical memory
  20. static u8* uncached_bootrom = nullptr;
  21. static u8* physical_exefs_code = nullptr; ///< Phsical ExeFS:/.code is loaded here
  22. static u8* physical_system_mem = nullptr; ///< System physical memory
  23. static u8* physical_fcram = nullptr; ///< Main physical memory (FCRAM)
  24. static u8* physical_heap_gsp = nullptr; ///< GSP heap physical memory
  25. static u8* physical_vram = nullptr; ///< Video physical memory (VRAM)
  26. static u8* physical_shared_mem = nullptr; ///< Physical shared memory
  27. static u8* physical_dsp_mem = nullptr; ///< Physical DSP memory
  28. static u8* physical_kernel_mem; ///< Kernel memory
  29. // We don't declare the IO region in here since its handled by other means.
  30. static MemoryView g_views[] = {
  31. {&g_exefs_code, &physical_exefs_code, EXEFS_CODE_VADDR, EXEFS_CODE_SIZE, 0},
  32. {&g_vram, &physical_vram, VRAM_VADDR, VRAM_SIZE, 0},
  33. {&g_heap, &physical_fcram, HEAP_VADDR, HEAP_SIZE, MV_IS_PRIMARY_RAM},
  34. {&g_shared_mem, &physical_shared_mem, SHARED_MEMORY_VADDR, SHARED_MEMORY_SIZE, 0},
  35. {&g_system_mem, &physical_system_mem, SYSTEM_MEMORY_VADDR, SYSTEM_MEMORY_SIZE, 0},
  36. {&g_dsp_mem, &physical_dsp_mem, DSP_MEMORY_VADDR, DSP_MEMORY_SIZE, 0},
  37. {&g_kernel_mem, &physical_kernel_mem, KERNEL_MEMORY_VADDR, KERNEL_MEMORY_SIZE, 0},
  38. {&g_heap_linear, &physical_heap_gsp, HEAP_LINEAR_VADDR, HEAP_LINEAR_SIZE, 0},
  39. };
  40. /*static MemoryView views[] =
  41. {
  42. {&m_pScratchPad, &m_pPhysicalScratchPad, 0x00010000, SCRATCHPAD_SIZE, 0},
  43. {NULL, &m_pUncachedScratchPad, 0x40010000, SCRATCHPAD_SIZE, MV_MIRROR_PREVIOUS},
  44. {&m_pVRAM, &m_pPhysicalVRAM, 0x04000000, 0x00800000, 0},
  45. {NULL, &m_pUncachedVRAM, 0x44000000, 0x00800000, MV_MIRROR_PREVIOUS},
  46. {&m_pRAM, &m_pPhysicalRAM, 0x08000000, g_MemorySize, MV_IS_PRIMARY_RAM}, // only from 0x08800000 is it usable (last 24 megs)
  47. {NULL, &m_pUncachedRAM, 0x48000000, g_MemorySize, MV_MIRROR_PREVIOUS | MV_IS_PRIMARY_RAM},
  48. {NULL, &m_pKernelRAM, 0x88000000, g_MemorySize, MV_MIRROR_PREVIOUS | MV_IS_PRIMARY_RAM},
  49. // TODO: There are a few swizzled mirrors of VRAM, not sure about the best way to
  50. // implement those.
  51. };*/
  52. static const int kNumMemViews = sizeof(g_views) / sizeof(MemoryView); ///< Number of mem views
  53. void Init() {
  54. int flags = 0;
  55. for (size_t i = 0; i < ARRAY_SIZE(g_views); i++) {
  56. if (g_views[i].flags & MV_IS_PRIMARY_RAM)
  57. g_views[i].size = FCRAM_SIZE;
  58. }
  59. g_base = MemoryMap_Setup(g_views, kNumMemViews, flags, &arena);
  60. LOG_DEBUG(HW_Memory, "initialized OK, RAM at %p (mirror at 0 @ %p)", g_heap,
  61. physical_fcram);
  62. }
  63. void Shutdown() {
  64. u32 flags = 0;
  65. MemoryMap_Shutdown(g_views, kNumMemViews, flags, &arena);
  66. arena.ReleaseSpace();
  67. g_base = nullptr;
  68. LOG_DEBUG(HW_Memory, "shutdown OK");
  69. }
  70. } // namespace