diff options
| author | 2013-09-05 23:04:04 -0400 | |
|---|---|---|
| committer | 2013-09-05 23:04:04 -0400 | |
| commit | 62d873da3ec77044d0135dbb2c6492eca29482fa (patch) | |
| tree | 3a21f3df2e1784af68f2df5ac98ced6a73f43c20 | |
| parent | added core and mem_map files to the project (diff) | |
| download | yuzu-62d873da3ec77044d0135dbb2c6492eca29482fa.tar.gz yuzu-62d873da3ec77044d0135dbb2c6492eca29482fa.tar.xz yuzu-62d873da3ec77044d0135dbb2c6492eca29482fa.zip | |
start of 3DS memory map
| -rw-r--r-- | src/common/src/common_funcs.h | 2 | ||||
| -rw-r--r-- | src/common/src/mem_arena.cpp | 10 | ||||
| -rw-r--r-- | src/common/src/mem_arena.h | 3 | ||||
| -rw-r--r-- | src/core/src/mem_map.cpp | 52 | ||||
| -rw-r--r-- | src/core/src/mem_map.h | 29 |
5 files changed, 80 insertions, 16 deletions
diff --git a/src/common/src/common_funcs.h b/src/common/src/common_funcs.h index 73320a3ac..9fa44c894 100644 --- a/src/common/src/common_funcs.h +++ b/src/common/src/common_funcs.h | |||
| @@ -22,6 +22,8 @@ template<> struct CompileTimeAssert<true> {}; | |||
| 22 | #define b32(x) (b16(x) | (b16(x) >>16) ) | 22 | #define b32(x) (b16(x) | (b16(x) >>16) ) |
| 23 | #define ROUND_UP_POW2(x) (b32(x - 1) + 1) | 23 | #define ROUND_UP_POW2(x) (b32(x - 1) + 1) |
| 24 | 24 | ||
| 25 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) | ||
| 26 | |||
| 25 | #if defined __GNUC__ && !defined __SSSE3__ && !defined _M_GENERIC | 27 | #if defined __GNUC__ && !defined __SSSE3__ && !defined _M_GENERIC |
| 26 | #include <emmintrin.h> | 28 | #include <emmintrin.h> |
| 27 | static __inline __m128i __attribute__((__always_inline__)) | 29 | static __inline __m128i __attribute__((__always_inline__)) |
diff --git a/src/common/src/mem_arena.cpp b/src/common/src/mem_arena.cpp index 13cd00fd3..291103be7 100644 --- a/src/common/src/mem_arena.cpp +++ b/src/common/src/mem_arena.cpp | |||
| @@ -163,14 +163,6 @@ u8* MemArena::Find4GBBase() | |||
| 163 | } | 163 | } |
| 164 | 164 | ||
| 165 | 165 | ||
| 166 | // yeah, this could also be done in like two bitwise ops... | ||
| 167 | #define SKIP(a_flags, b_flags) \ | ||
| 168 | if (!(a_flags & MV_WII_ONLY) && (b_flags & MV_WII_ONLY)) \ | ||
| 169 | continue; \ | ||
| 170 | if (!(a_flags & MV_FAKE_VMEM) && (b_flags & MV_FAKE_VMEM)) \ | ||
| 171 | continue; \ | ||
| 172 | |||
| 173 | |||
| 174 | static bool Memory_TryBase(u8 *base, const MemoryView *views, int num_views, u32 flags, MemArena *arena) { | 166 | static bool Memory_TryBase(u8 *base, const MemoryView *views, int num_views, u32 flags, MemArena *arena) { |
| 175 | // OK, we know where to find free space. Now grab it! | 167 | // OK, we know where to find free space. Now grab it! |
| 176 | // We just mimic the popular BAT setup. | 168 | // We just mimic the popular BAT setup. |
| @@ -189,7 +181,6 @@ static bool Memory_TryBase(u8 *base, const MemoryView *views, int num_views, u32 | |||
| 189 | int i; | 181 | int i; |
| 190 | for (i = 0; i < num_views; i++) | 182 | for (i = 0; i < num_views; i++) |
| 191 | { | 183 | { |
| 192 | SKIP(flags, views[i].flags); | ||
| 193 | if (views[i].flags & MV_MIRROR_PREVIOUS) { | 184 | if (views[i].flags & MV_MIRROR_PREVIOUS) { |
| 194 | position = last_position; | 185 | position = last_position; |
| 195 | } else { | 186 | } else { |
| @@ -230,7 +221,6 @@ u8 *MemoryMap_Setup(const MemoryView *views, int num_views, u32 flags, MemArena | |||
| 230 | 221 | ||
| 231 | for (int i = 0; i < num_views; i++) | 222 | for (int i = 0; i < num_views; i++) |
| 232 | { | 223 | { |
| 233 | SKIP(flags, views[i].flags); | ||
| 234 | if ((views[i].flags & MV_MIRROR_PREVIOUS) == 0) | 224 | if ((views[i].flags & MV_MIRROR_PREVIOUS) == 0) |
| 235 | total_mem += views[i].size; | 225 | total_mem += views[i].size; |
| 236 | } | 226 | } |
diff --git a/src/common/src/mem_arena.h b/src/common/src/mem_arena.h index 4c3ded0df..3c14756db 100644 --- a/src/common/src/mem_arena.h +++ b/src/common/src/mem_arena.h | |||
| @@ -37,8 +37,7 @@ private: | |||
| 37 | 37 | ||
| 38 | enum { | 38 | enum { |
| 39 | MV_MIRROR_PREVIOUS = 1, | 39 | MV_MIRROR_PREVIOUS = 1, |
| 40 | MV_FAKE_VMEM = 2, | 40 | MV_IS_PRIMARY_RAM = 0x100, |
| 41 | MV_WII_ONLY = 4, | ||
| 42 | }; | 41 | }; |
| 43 | 42 | ||
| 44 | struct MemoryView | 43 | struct MemoryView |
diff --git a/src/core/src/mem_map.cpp b/src/core/src/mem_map.cpp index 3ff516cbd..e649da91b 100644 --- a/src/core/src/mem_map.cpp +++ b/src/core/src/mem_map.cpp | |||
| @@ -22,10 +22,41 @@ | |||
| 22 | * http://code.google.com/p/gekko-gc-emu/ | 22 | * http://code.google.com/p/gekko-gc-emu/ |
| 23 | */ | 23 | */ |
| 24 | 24 | ||
| 25 | #include "common.h" | ||
| 26 | #include "mem_arena.h" | ||
| 27 | |||
| 25 | #include "mem_map.h" | 28 | #include "mem_map.h" |
| 29 | #include "core.h" | ||
| 30 | |||
| 31 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 26 | 32 | ||
| 27 | namespace Memory { | 33 | namespace Memory { |
| 28 | 34 | ||
| 35 | |||
| 36 | u8* g_mem_base = NULL; ///< The base pointer to the auto-mirrored arena. | ||
| 37 | |||
| 38 | MemArena g_mem_arena; ///< The MemArena class | ||
| 39 | |||
| 40 | u8* g_fcram = NULL; ///< Main memory (FCRAM) pointer | ||
| 41 | u8* g_vram = NULL; ///< Video memory (VRAM) pointer | ||
| 42 | |||
| 43 | u8* g_physical_fcram = NULL; ///< Main physical memory (FCRAM) | ||
| 44 | u8* g_physical_vram = NULL; ///< Video physical memory (VRAM) | ||
| 45 | |||
| 46 | // We don't declare the IO region in here since its handled by other means. | ||
| 47 | static MemoryView g_mem_views[] = | ||
| 48 | { | ||
| 49 | {NULL, NULL, 0x00000000, MEM_BOOTROM_SIZE, 0}, | ||
| 50 | {NULL, NULL, 0x00010000, MEM_BOOTROM_SIZE, MV_MIRROR_PREVIOUS}, | ||
| 51 | {NULL, NULL, 0x17E00000, MEM_MPCORE_PRIV_SIZE, 0}, | ||
| 52 | {&g_vram, &g_physical_vram, 0x18000000, MEM_VRAM_SIZE, 0}, | ||
| 53 | {NULL, NULL, 0x1FF00000, MEM_DSP_SIZE, 0}, | ||
| 54 | {NULL, NULL, 0x1FF80000, MEM_AXI_WRAM_SIZE, 0}, | ||
| 55 | {&g_ram, &g_physical_fcram, 0x20000000, MEM_FCRAM_SIZE, MV_IS_PRIMARY_RAM}, | ||
| 56 | }; | ||
| 57 | |||
| 58 | static const int kNumMemViews = sizeof(g_mem_views) / sizeof(MemoryView); ///< Number of mem views | ||
| 59 | |||
| 29 | u8 Read8(const u32 addr) { | 60 | u8 Read8(const u32 addr) { |
| 30 | return 0xDE; | 61 | return 0xDE; |
| 31 | } | 62 | } |
| @@ -47,6 +78,27 @@ void Write16(const u32 addr, const u32 data) { | |||
| 47 | void Write32(const u32 addr, const u32 data) { | 78 | void Write32(const u32 addr, const u32 data) { |
| 48 | } | 79 | } |
| 49 | 80 | ||
| 81 | void Init() { | ||
| 82 | int flags = 0; | ||
| 83 | |||
| 84 | for (size_t i = 0; i < ARRAY_SIZE(g_mem_views); i++) { | ||
| 85 | if (g_mem_views[i].flags & MV_IS_PRIMARY_RAM) | ||
| 86 | g_mem_views[i].size = MEMORY_SIZE; | ||
| 87 | } | ||
| 88 | g_base = MemoryMap_Setup(g_mem_views, kNumMemViews, flags, &g_mem_arena); | ||
| 89 | |||
| 90 | INFO_LOG(MEMMAP, "Memory system initialized. RAM at %p (mirror at 0 @ %p)", g_fcram, | ||
| 91 | g_physical_fcram); | ||
| 92 | } | ||
| 93 | |||
| 94 | void Shutdown() { | ||
| 95 | u32 flags = 0; | ||
| 96 | MemoryMap_Shutdown(g_mem_views, kNumMemViews, flags, &g_mem_arena); | ||
| 97 | g_mem_arena.ReleaseSpace(); | ||
| 98 | g_mem_base = NULL; | ||
| 99 | INFO_LOG(MEMMAP, "Memory system shut down."); | ||
| 100 | } | ||
| 101 | |||
| 50 | 102 | ||
| 51 | 103 | ||
| 52 | } // namespace | 104 | } // namespace |
diff --git a/src/core/src/mem_map.h b/src/core/src/mem_map.h index 8ef6e58a2..3251fc416 100644 --- a/src/core/src/mem_map.h +++ b/src/core/src/mem_map.h | |||
| @@ -32,13 +32,34 @@ | |||
| 32 | 32 | ||
| 33 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 33 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 34 | 34 | ||
| 35 | #define MEM_BOOTROM_SIZE 0x00010000 ///< Bootrom (super secret code/data @ 0x8000) size | ||
| 36 | #define MEM_MPCORE_PRIV_SIZE 0x00002000 ///< MPCore private memory region size | ||
| 37 | #define MEM_VRAM_SIZE 0x00600000 ///< VRAM size | ||
| 38 | #define MEM_DSP_SIZE 0x00080000 ///< DSP memory size | ||
| 39 | #define MEM_AXI_WRAM_SIZE 0x00080000 ///< AXI WRAM size | ||
| 40 | #define MEM_FCRAM_SIZE 0x08000000 ///< FCRAM size | ||
| 41 | |||
| 42 | #define MEMORY_SIZE MEM_FCRAM_SIZE | ||
| 43 | #define MEMORY_MASK (MEM_FCRAM_SIZE - 1) ///< Main memory mask | ||
| 44 | |||
| 45 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 46 | |||
| 35 | namespace Memory { | 47 | namespace Memory { |
| 36 | 48 | ||
| 37 | extern u8* g_ram; | 49 | // Base is a pointer to the base of the memory map. Yes, some MMU tricks |
| 38 | extern u8* g_vram; | 50 | // are used to set up a full GC or Wii memory map in process memory. on |
| 51 | // 32-bit, you have to mask your offsets with 0x3FFFFFFF. This means that | ||
| 52 | // some things are mirrored too many times, but eh... it works. | ||
| 53 | |||
| 54 | // In 64-bit, this might point to "high memory" (above the 32-bit limit), | ||
| 55 | // so be sure to load it into a 64-bit register. | ||
| 56 | extern u8 *g_base; | ||
| 39 | 57 | ||
| 40 | extern u32 g_memory_size; | 58 | // These are guaranteed to point to "low memory" addresses (sub-32-bit). |
| 41 | extern u32 g_memory_mask; | 59 | // 64-bit: Pointers to low-mem (sub-0x10000000) mirror |
| 60 | // 32-bit: Same as the corresponding physical/virtual pointers. | ||
| 61 | extern u8* g_ram; ///< Main memory | ||
| 62 | extern u8* g_vram; ///< Video memory (VRAM) | ||
| 42 | 63 | ||
| 43 | void Init(); | 64 | void Init(); |
| 44 | void Shutdown(); | 65 | void Shutdown(); |