summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2015-05-14 20:40:53 -0700
committerGravatar Yuri Kunde Schlesner2015-05-14 20:40:53 -0700
commitbb689338943791c735c7c6adb186256457e064b4 (patch)
treea04ba64d18dd163709b1cb4b4212afaca6c091a6 /src
parentMerge pull request #769 from lioncash/cond (diff)
parentMemory: Use a table based lookup scheme to read from memory regions (diff)
downloadyuzu-bb689338943791c735c7c6adb186256457e064b4.tar.gz
yuzu-bb689338943791c735c7c6adb186256457e064b4.tar.xz
yuzu-bb689338943791c735c7c6adb186256457e064b4.zip
Merge pull request #762 from yuriks/memmap
Memory: Use a table based lookup scheme to read from memory regions
Diffstat (limited to 'src')
-rw-r--r--src/citra_qt/debugger/callstack.cpp2
-rw-r--r--src/citra_qt/debugger/disassembler.cpp2
-rw-r--r--src/citra_qt/debugger/graphics_framebuffer.cpp2
-rw-r--r--src/citra_qt/debugger/ramview.cpp2
-rw-r--r--src/core/CMakeLists.txt4
-rw-r--r--src/core/arm/dyncom/arm_dyncom_interpreter.cpp2
-rw-r--r--src/core/arm/interpreter/arminit.cpp1
-rw-r--r--src/core/arm/skyeye_common/armmmu.h2
-rw-r--r--src/core/core.cpp1
-rw-r--r--src/core/file_sys/archive_backend.cpp2
-rw-r--r--src/core/hle/config_mem.cpp49
-rw-r--r--src/core/hle/config_mem.h38
-rw-r--r--src/core/hle/function_wrappers.h6
-rw-r--r--src/core/hle/kernel/address_arbiter.cpp2
-rw-r--r--src/core/hle/kernel/process.cpp2
-rw-r--r--src/core/hle/kernel/session.h2
-rw-r--r--src/core/hle/kernel/shared_memory.cpp2
-rw-r--r--src/core/hle/kernel/thread.cpp2
-rw-r--r--src/core/hle/kernel/thread.h1
-rw-r--r--src/core/hle/service/gsp_gpu.cpp1
-rw-r--r--src/core/hle/shared_page.cpp57
-rw-r--r--src/core/hle/shared_page.h38
-rw-r--r--src/core/hle/svc.cpp2
-rw-r--r--src/core/hw/gpu.cpp2
-rw-r--r--src/core/loader/3dsx.cpp2
-rw-r--r--src/core/loader/elf.cpp2
-rw-r--r--src/core/loader/loader.cpp1
-rw-r--r--src/core/loader/ncch.cpp2
-rw-r--r--src/core/mem_map.cpp122
-rw-r--r--src/core/mem_map.h157
-rw-r--r--src/core/mem_map_funcs.cpp283
-rw-r--r--src/core/memory.cpp202
-rw-r--r--src/core/memory.h129
-rw-r--r--src/core/memory_setup.h29
-rw-r--r--src/video_core/pica.h2
-rw-r--r--src/video_core/rasterizer.cpp2
-rw-r--r--src/video_core/renderer_opengl/renderer_opengl.cpp2
-rw-r--r--src/video_core/vertex_shader.cpp2
38 files changed, 572 insertions, 589 deletions
diff --git a/src/citra_qt/debugger/callstack.cpp b/src/citra_qt/debugger/callstack.cpp
index 3742c2d38..94e204717 100644
--- a/src/citra_qt/debugger/callstack.cpp
+++ b/src/citra_qt/debugger/callstack.cpp
@@ -8,7 +8,7 @@
8 8
9#include "core/core.h" 9#include "core/core.h"
10#include "core/arm/arm_interface.h" 10#include "core/arm/arm_interface.h"
11#include "core/mem_map.h" 11#include "core/memory.h"
12#include "common/symbols.h" 12#include "common/symbols.h"
13#include "core/arm/disassembler/arm_disasm.h" 13#include "core/arm/disassembler/arm_disasm.h"
14 14
diff --git a/src/citra_qt/debugger/disassembler.cpp b/src/citra_qt/debugger/disassembler.cpp
index 780607e82..e99ec1b30 100644
--- a/src/citra_qt/debugger/disassembler.cpp
+++ b/src/citra_qt/debugger/disassembler.cpp
@@ -7,7 +7,7 @@
7#include "../bootmanager.h" 7#include "../bootmanager.h"
8#include "../hotkeys.h" 8#include "../hotkeys.h"
9 9
10#include "core/mem_map.h" 10#include "core/memory.h"
11 11
12#include "core/core.h" 12#include "core/core.h"
13#include "common/break_points.h" 13#include "common/break_points.h"
diff --git a/src/citra_qt/debugger/graphics_framebuffer.cpp b/src/citra_qt/debugger/graphics_framebuffer.cpp
index 3287b4706..0c1a3f47f 100644
--- a/src/citra_qt/debugger/graphics_framebuffer.cpp
+++ b/src/citra_qt/debugger/graphics_framebuffer.cpp
@@ -10,6 +10,8 @@
10#include <QSpinBox> 10#include <QSpinBox>
11 11
12#include "core/hw/gpu.h" 12#include "core/hw/gpu.h"
13#include "core/memory.h"
14
13#include "video_core/color.h" 15#include "video_core/color.h"
14#include "video_core/pica.h" 16#include "video_core/pica.h"
15#include "video_core/utils.h" 17#include "video_core/utils.h"
diff --git a/src/citra_qt/debugger/ramview.cpp b/src/citra_qt/debugger/ramview.cpp
index 7149a0485..b6ebc7fc4 100644
--- a/src/citra_qt/debugger/ramview.cpp
+++ b/src/citra_qt/debugger/ramview.cpp
@@ -4,8 +4,6 @@
4 4
5#include "ramview.h" 5#include "ramview.h"
6 6
7#include "core/mem_map.h"
8
9 7
10GRamView::GRamView(QWidget* parent) : QHexEdit(parent) 8GRamView::GRamView(QWidget* parent) : QHexEdit(parent)
11{ 9{
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index ebedcb710..e8d8c96d7 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -99,7 +99,7 @@ set(SRCS
99 loader/loader.cpp 99 loader/loader.cpp
100 loader/ncch.cpp 100 loader/ncch.cpp
101 mem_map.cpp 101 mem_map.cpp
102 mem_map_funcs.cpp 102 memory.cpp
103 settings.cpp 103 settings.cpp
104 system.cpp 104 system.cpp
105 ) 105 )
@@ -211,6 +211,8 @@ set(HEADERS
211 loader/loader.h 211 loader/loader.h
212 loader/ncch.h 212 loader/ncch.h
213 mem_map.h 213 mem_map.h
214 memory.h
215 memory_setup.h
214 settings.h 216 settings.h
215 system.h 217 system.h
216 ) 218 )
diff --git a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
index 8c52bdb72..b79fd1719 100644
--- a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
+++ b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
@@ -10,7 +10,7 @@
10#include "common/logging/log.h" 10#include "common/logging/log.h"
11#include "common/profiler.h" 11#include "common/profiler.h"
12 12
13#include "core/mem_map.h" 13#include "core/memory.h"
14#include "core/hle/svc.h" 14#include "core/hle/svc.h"
15#include "core/arm/disassembler/arm_disasm.h" 15#include "core/arm/disassembler/arm_disasm.h"
16#include "core/arm/dyncom/arm_dyncom_interpreter.h" 16#include "core/arm/dyncom/arm_dyncom_interpreter.h"
diff --git a/src/core/arm/interpreter/arminit.cpp b/src/core/arm/interpreter/arminit.cpp
index 31b2bab06..680a94a39 100644
--- a/src/core/arm/interpreter/arminit.cpp
+++ b/src/core/arm/interpreter/arminit.cpp
@@ -16,7 +16,6 @@
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17 17
18#include <cstring> 18#include <cstring>
19#include "core/mem_map.h"
20#include "core/arm/skyeye_common/armdefs.h" 19#include "core/arm/skyeye_common/armdefs.h"
21#include "core/arm/skyeye_common/armemu.h" 20#include "core/arm/skyeye_common/armemu.h"
22#include "core/arm/skyeye_common/vfp/vfp.h" 21#include "core/arm/skyeye_common/vfp/vfp.h"
diff --git a/src/core/arm/skyeye_common/armmmu.h b/src/core/arm/skyeye_common/armmmu.h
index 0463d83c8..c67d7209b 100644
--- a/src/core/arm/skyeye_common/armmmu.h
+++ b/src/core/arm/skyeye_common/armmmu.h
@@ -22,7 +22,7 @@
22 22
23#include "common/swap.h" 23#include "common/swap.h"
24 24
25#include "core/mem_map.h" 25#include "core/memory.h"
26#include "core/arm/skyeye_common/armdefs.h" 26#include "core/arm/skyeye_common/armdefs.h"
27 27
28// Register numbers in the MMU 28// Register numbers in the MMU
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 53aae8c2f..79038cd52 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -8,7 +8,6 @@
8#include "core/core.h" 8#include "core/core.h"
9#include "core/core_timing.h" 9#include "core/core_timing.h"
10 10
11#include "core/mem_map.h"
12#include "core/settings.h" 11#include "core/settings.h"
13#include "core/arm/arm_interface.h" 12#include "core/arm/arm_interface.h"
14#include "core/arm/disassembler/arm_disasm.h" 13#include "core/arm/disassembler/arm_disasm.h"
diff --git a/src/core/file_sys/archive_backend.cpp b/src/core/file_sys/archive_backend.cpp
index 0439868ab..45a559ce8 100644
--- a/src/core/file_sys/archive_backend.cpp
+++ b/src/core/file_sys/archive_backend.cpp
@@ -8,7 +8,7 @@
8#include "common/string_util.h" 8#include "common/string_util.h"
9 9
10#include "core/file_sys/archive_backend.h" 10#include "core/file_sys/archive_backend.h"
11#include "core/mem_map.h" 11#include "core/memory.h"
12 12
13 13
14namespace FileSys { 14namespace FileSys {
diff --git a/src/core/hle/config_mem.cpp b/src/core/hle/config_mem.cpp
index 35dc9cf58..aea936d2d 100644
--- a/src/core/hle/config_mem.cpp
+++ b/src/core/hle/config_mem.cpp
@@ -9,59 +9,14 @@
9#include "common/common_funcs.h" 9#include "common/common_funcs.h"
10 10
11#include "core/core.h" 11#include "core/core.h"
12#include "core/mem_map.h" 12#include "core/memory.h"
13#include "core/hle/config_mem.h" 13#include "core/hle/config_mem.h"
14 14
15//////////////////////////////////////////////////////////////////////////////////////////////////// 15////////////////////////////////////////////////////////////////////////////////////////////////////
16 16
17namespace ConfigMem { 17namespace ConfigMem {
18 18
19struct ConfigMemDef { 19ConfigMemDef config_mem;
20 u8 kernel_unk; // 0
21 u8 kernel_version_rev; // 1
22 u8 kernel_version_min; // 2
23 u8 kernel_version_maj; // 3
24 u32 update_flag; // 4
25 u64 ns_tid; // 8
26 u32 sys_core_ver; // 10
27 u8 unit_info; // 14
28 u8 boot_firm; // 15
29 u8 prev_firm; // 16
30 INSERT_PADDING_BYTES(0x1); // 17
31 u32 ctr_sdk_ver; // 18
32 INSERT_PADDING_BYTES(0x30 - 0x1C); // 1C
33 u32 app_mem_type; // 30
34 INSERT_PADDING_BYTES(0x40 - 0x34); // 34
35 u32 app_mem_alloc; // 40
36 u32 sys_mem_alloc; // 44
37 u32 base_mem_alloc; // 48
38 INSERT_PADDING_BYTES(0x60 - 0x4C); // 4C
39 u8 firm_unk; // 60
40 u8 firm_version_rev; // 61
41 u8 firm_version_min; // 62
42 u8 firm_version_maj; // 63
43 u32 firm_sys_core_ver; // 64
44 u32 firm_ctr_sdk_ver; // 68
45 INSERT_PADDING_BYTES(0x1000 - 0x6C); // 6C
46};
47
48static_assert(sizeof(ConfigMemDef) == Memory::CONFIG_MEMORY_SIZE, "Config Memory structure size is wrong");
49
50static ConfigMemDef config_mem;
51
52template <typename T>
53inline void Read(T &var, const u32 addr) {
54 u32 offset = addr - Memory::CONFIG_MEMORY_VADDR;
55 ASSERT(offset < Memory::CONFIG_MEMORY_SIZE);
56 var = *(reinterpret_cast<T*>(((uintptr_t)&config_mem) + offset));
57}
58
59// Explicitly instantiate template functions because we aren't defining this in the header:
60
61template void Read<u64>(u64 &var, const u32 addr);
62template void Read<u32>(u32 &var, const u32 addr);
63template void Read<u16>(u16 &var, const u32 addr);
64template void Read<u8>(u8 &var, const u32 addr);
65 20
66void Init() { 21void Init() {
67 std::memset(&config_mem, 0, sizeof(config_mem)); 22 std::memset(&config_mem, 0, sizeof(config_mem));
diff --git a/src/core/hle/config_mem.h b/src/core/hle/config_mem.h
index cbb478fb3..9825a09e8 100644
--- a/src/core/hle/config_mem.h
+++ b/src/core/hle/config_mem.h
@@ -9,17 +9,49 @@
9// bootrom. Because we're not emulating this, and essentially just "stubbing" the functionality, I'm 9// bootrom. Because we're not emulating this, and essentially just "stubbing" the functionality, I'm
10// putting this as a subset of HLE for now. 10// putting this as a subset of HLE for now.
11 11
12#include "common/common_funcs.h"
12#include "common/common_types.h" 13#include "common/common_types.h"
14#include "common/swap.h"
15
16#include "core/memory.h"
13 17
14//////////////////////////////////////////////////////////////////////////////////////////////////// 18////////////////////////////////////////////////////////////////////////////////////////////////////
15 19
16namespace ConfigMem { 20namespace ConfigMem {
17 21
18template <typename T> 22struct ConfigMemDef {
19void Read(T &var, const u32 addr); 23 u8 kernel_unk; // 0
24 u8 kernel_version_rev; // 1
25 u8 kernel_version_min; // 2
26 u8 kernel_version_maj; // 3
27 u32_le update_flag; // 4
28 u64_le ns_tid; // 8
29 u32_le sys_core_ver; // 10
30 u8 unit_info; // 14
31 u8 boot_firm; // 15
32 u8 prev_firm; // 16
33 INSERT_PADDING_BYTES(0x1); // 17
34 u32_le ctr_sdk_ver; // 18
35 INSERT_PADDING_BYTES(0x30 - 0x1C); // 1C
36 u32_le app_mem_type; // 30
37 INSERT_PADDING_BYTES(0x40 - 0x34); // 34
38 u32_le app_mem_alloc; // 40
39 u32_le sys_mem_alloc; // 44
40 u32_le base_mem_alloc; // 48
41 INSERT_PADDING_BYTES(0x60 - 0x4C); // 4C
42 u8 firm_unk; // 60
43 u8 firm_version_rev; // 61
44 u8 firm_version_min; // 62
45 u8 firm_version_maj; // 63
46 u32_le firm_sys_core_ver; // 64
47 u32_le firm_ctr_sdk_ver; // 68
48 INSERT_PADDING_BYTES(0x1000 - 0x6C); // 6C
49};
50static_assert(sizeof(ConfigMemDef) == Memory::CONFIG_MEMORY_SIZE, "Config Memory structure size is wrong");
51
52extern ConfigMemDef config_mem;
20 53
21void Init(); 54void Init();
22
23void Shutdown(); 55void Shutdown();
24 56
25} // namespace 57} // namespace
diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h
index be2626eef..eb52c8fb1 100644
--- a/src/core/hle/function_wrappers.h
+++ b/src/core/hle/function_wrappers.h
@@ -7,7 +7,7 @@
7#include "common/common_types.h" 7#include "common/common_types.h"
8 8
9#include "core/arm/arm_interface.h" 9#include "core/arm/arm_interface.h"
10#include "core/mem_map.h" 10#include "core/memory.h"
11#include "core/hle/hle.h" 11#include "core/hle/hle.h"
12 12
13namespace HLE { 13namespace HLE {
@@ -109,7 +109,7 @@ template<ResultCode func(s64*, u32, void*, s32)> void Wrap(){
109 109
110template<ResultCode func(u32*, const char*)> void Wrap() { 110template<ResultCode func(u32*, const char*)> void Wrap() {
111 u32 param_1 = 0; 111 u32 param_1 = 0;
112 u32 retval = func(&param_1, Memory::GetCharPointer(PARAM(1))).raw; 112 u32 retval = func(&param_1, (char*)Memory::GetPointer(PARAM(1))).raw;
113 Core::g_app_core->SetReg(1, param_1); 113 Core::g_app_core->SetReg(1, param_1);
114 FuncReturn(retval); 114 FuncReturn(retval);
115} 115}
@@ -163,7 +163,7 @@ template<void func(s64)> void Wrap() {
163} 163}
164 164
165template<void func(const char*)> void Wrap() { 165template<void func(const char*)> void Wrap() {
166 func(Memory::GetCharPointer(PARAM(0))); 166 func((char*)Memory::GetPointer(PARAM(0)));
167} 167}
168 168
169#undef PARAM 169#undef PARAM
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp
index 9d7f6b280..a1221766e 100644
--- a/src/core/hle/kernel/address_arbiter.cpp
+++ b/src/core/hle/kernel/address_arbiter.cpp
@@ -5,7 +5,7 @@
5#include "common/common_types.h" 5#include "common/common_types.h"
6#include "common/logging/log.h" 6#include "common/logging/log.h"
7 7
8#include "core/mem_map.h" 8#include "core/memory.h"
9 9
10#include "core/hle/hle.h" 10#include "core/hle/hle.h"
11#include "core/hle/kernel/address_arbiter.h" 11#include "core/hle/kernel/address_arbiter.h"
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp
index 1e439db9e..0cdfa58d7 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -8,7 +8,7 @@
8 8
9#include "core/hle/kernel/process.h" 9#include "core/hle/kernel/process.h"
10#include "core/hle/kernel/thread.h" 10#include "core/hle/kernel/thread.h"
11#include "core/mem_map.h" 11#include "core/memory.h"
12 12
13namespace Kernel { 13namespace Kernel {
14 14
diff --git a/src/core/hle/kernel/session.h b/src/core/hle/kernel/session.h
index 8c3886ffd..54a062971 100644
--- a/src/core/hle/kernel/session.h
+++ b/src/core/hle/kernel/session.h
@@ -6,7 +6,7 @@
6 6
7#include "core/hle/kernel/kernel.h" 7#include "core/hle/kernel/kernel.h"
8#include "core/hle/kernel/thread.h" 8#include "core/hle/kernel/thread.h"
9#include "core/mem_map.h" 9#include "core/memory.h"
10 10
11namespace Kernel { 11namespace Kernel {
12 12
diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp
index 0c59f4876..4137683b5 100644
--- a/src/core/hle/kernel/shared_memory.cpp
+++ b/src/core/hle/kernel/shared_memory.cpp
@@ -6,7 +6,7 @@
6 6
7#include "common/logging/log.h" 7#include "common/logging/log.h"
8 8
9#include "core/mem_map.h" 9#include "core/memory.h"
10#include "core/hle/kernel/shared_memory.h" 10#include "core/hle/kernel/shared_memory.h"
11 11
12namespace Kernel { 12namespace Kernel {
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index 5bcd03ff3..a5f1904d7 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -21,7 +21,7 @@
21#include "core/hle/kernel/thread.h" 21#include "core/hle/kernel/thread.h"
22#include "core/hle/kernel/mutex.h" 22#include "core/hle/kernel/mutex.h"
23#include "core/hle/result.h" 23#include "core/hle/result.h"
24#include "core/mem_map.h" 24#include "core/memory.h"
25 25
26namespace Kernel { 26namespace Kernel {
27 27
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index 6b329c12a..389928178 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -12,7 +12,6 @@
12#include "common/common_types.h" 12#include "common/common_types.h"
13 13
14#include "core/core.h" 14#include "core/core.h"
15#include "core/mem_map.h"
16 15
17#include "core/hle/kernel/kernel.h" 16#include "core/hle/kernel/kernel.h"
18#include "core/hle/result.h" 17#include "core/hle/result.h"
diff --git a/src/core/hle/service/gsp_gpu.cpp b/src/core/hle/service/gsp_gpu.cpp
index c6252a03b..c11c5faba 100644
--- a/src/core/hle/service/gsp_gpu.cpp
+++ b/src/core/hle/service/gsp_gpu.cpp
@@ -5,6 +5,7 @@
5#include "common/bit_field.h" 5#include "common/bit_field.h"
6 6
7#include "core/mem_map.h" 7#include "core/mem_map.h"
8#include "core/memory.h"
8#include "core/hle/kernel/event.h" 9#include "core/hle/kernel/event.h"
9#include "core/hle/kernel/shared_memory.h" 10#include "core/hle/kernel/shared_memory.h"
10#include "core/hle/result.h" 11#include "core/hle/result.h"
diff --git a/src/core/hle/shared_page.cpp b/src/core/hle/shared_page.cpp
index 4f227a370..4014eee98 100644
--- a/src/core/hle/shared_page.cpp
+++ b/src/core/hle/shared_page.cpp
@@ -8,7 +8,7 @@
8#include "common/common_funcs.h" 8#include "common/common_funcs.h"
9 9
10#include "core/core.h" 10#include "core/core.h"
11#include "core/mem_map.h" 11#include "core/memory.h"
12#include "core/hle/config_mem.h" 12#include "core/hle/config_mem.h"
13#include "core/hle/shared_page.h" 13#include "core/hle/shared_page.h"
14 14
@@ -16,63 +16,12 @@
16 16
17namespace SharedPage { 17namespace SharedPage {
18 18
19// see http://3dbrew.org/wiki/Configuration_Memory#Shared_Memory_Page_For_ARM11_Processes 19SharedPageDef shared_page;
20 20
21#pragma pack(1) 21void Init() {
22struct DateTime {
23 u64 date_time; // 0x0
24 u64 update_tick; // 0x8
25 INSERT_PADDING_BYTES(0x20 - 0x10); // 0x10
26};
27
28struct SharedPageDef {
29 // most of these names are taken from the 3dbrew page linked above.
30 u32 date_time_selector; // 0x0
31 u8 running_hw; // 0x4
32 u8 mcu_hw_info; // 0x5: don't know what the acronyms mean
33 INSERT_PADDING_BYTES(0x20 - 0x6); // 0x6
34 DateTime date_time_0; // 0x20
35 DateTime date_time_1; // 0x40
36 u8 wifi_macaddr[6]; // 0x60
37 u8 wifi_unknown1; // 0x66: 3dbrew says these are "Likely wifi hardware related"
38 u8 wifi_unknown2; // 0x67
39 INSERT_PADDING_BYTES(0x80 - 0x68); // 0x68
40 float sliderstate_3d; // 0x80
41 u8 ledstate_3d; // 0x84
42 INSERT_PADDING_BYTES(0xA0 - 0x85); // 0x85
43 u64 menu_title_id; // 0xA0
44 u64 active_menu_title_id; // 0xA8
45 INSERT_PADDING_BYTES(0x1000 - 0xB0); // 0xB0
46};
47#pragma pack()
48
49static_assert(sizeof(DateTime) == 0x20, "Datetime size is wrong");
50static_assert(sizeof(SharedPageDef) == Memory::SHARED_PAGE_SIZE, "Shared page structure size is wrong");
51
52static SharedPageDef shared_page;
53
54template <typename T>
55inline void Read(T &var, const u32 addr) {
56 u32 offset = addr - Memory::SHARED_PAGE_VADDR;
57 var = *(reinterpret_cast<T*>(((uintptr_t)&shared_page) + offset));
58}
59
60// Explicitly instantiate template functions because we aren't defining this in the header:
61template void Read<u64>(u64 &var, const u32 addr);
62template void Read<u32>(u32 &var, const u32 addr);
63template void Read<u16>(u16 &var, const u32 addr);
64template void Read<u8>(u8 &var, const u32 addr);
65
66void Set3DSlider(float amount) {
67 std::memset(&shared_page, 0, sizeof(shared_page)); 22 std::memset(&shared_page, 0, sizeof(shared_page));
68 23
69 shared_page.sliderstate_3d = amount;
70 shared_page.ledstate_3d = (amount == 0.0f); // off when non-zero
71}
72
73void Init() {
74 shared_page.running_hw = 0x1; // product 24 shared_page.running_hw = 0x1; // product
75 Set3DSlider(0.0f);
76} 25}
77 26
78void Shutdown() { 27void Shutdown() {
diff --git a/src/core/hle/shared_page.h b/src/core/hle/shared_page.h
index 1b6e4e581..fd2ab66a2 100644
--- a/src/core/hle/shared_page.h
+++ b/src/core/hle/shared_page.h
@@ -11,18 +11,46 @@
11 */ 11 */
12 12
13#include "common/common_types.h" 13#include "common/common_types.h"
14#include "common/swap.h"
14 15
15//////////////////////////////////////////////////////////////////////////////////////////////////// 16////////////////////////////////////////////////////////////////////////////////////////////////////
16 17
17namespace SharedPage { 18namespace SharedPage {
18 19
19template <typename T> 20// See http://3dbrew.org/wiki/Configuration_Memory#Shared_Memory_Page_For_ARM11_Processes
20void Read(T &var, const u32 addr); 21
21 22struct DateTime {
22void Set3DSlider(float amount); 23 u64_le date_time; // 0
24 u64_le update_tick; // 8
25 INSERT_PADDING_BYTES(0x20 - 0x10); // 10
26};
27static_assert(sizeof(DateTime) == 0x20, "Datetime size is wrong");
28
29struct SharedPageDef {
30 // Most of these names are taken from the 3dbrew page linked above.
31 u32_le date_time_selector; // 0
32 u8 running_hw; // 4
33 /// "Microcontroller hardware info"
34 u8 mcu_hw_info; // 5
35 INSERT_PADDING_BYTES(0x20 - 0x6); // 6
36 DateTime date_time_0; // 20
37 DateTime date_time_1; // 40
38 u8 wifi_macaddr[6]; // 60
39 u8 wifi_unknown1; // 66
40 u8 wifi_unknown2; // 67
41 INSERT_PADDING_BYTES(0x80 - 0x68); // 68
42 float_le sliderstate_3d; // 80
43 u8 ledstate_3d; // 84
44 INSERT_PADDING_BYTES(0xA0 - 0x85); // 85
45 u64_le menu_title_id; // A0
46 u64_le active_menu_title_id; // A8
47 INSERT_PADDING_BYTES(0x1000 - 0xB0); // B0
48};
49static_assert(sizeof(SharedPageDef) == Memory::SHARED_PAGE_SIZE, "Shared page structure size is wrong");
50
51extern SharedPageDef shared_page;
23 52
24void Init(); 53void Init();
25
26void Shutdown(); 54void Shutdown();
27 55
28} // namespace 56} // namespace
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp
index e8159fbdb..9bf886256 100644
--- a/src/core/hle/svc.cpp
+++ b/src/core/hle/svc.cpp
@@ -315,7 +315,7 @@ static ResultCode GetResourceLimitCurrentValues(s64* values, Handle resource_lim
315 s32 name_count) { 315 s32 name_count) {
316 LOG_ERROR(Kernel_SVC, "(UNIMPLEMENTED) called resource_limit=%08X, names=%p, name_count=%d", 316 LOG_ERROR(Kernel_SVC, "(UNIMPLEMENTED) called resource_limit=%08X, names=%p, name_count=%d",
317 resource_limit, names, name_count); 317 resource_limit, names, name_count);
318 Memory::Write32(Core::g_app_core->GetReg(0), 0); // Normmatt: Set used memory to 0 for now 318 values[0] = 0; // Normmatt: Set used memory to 0 for now
319 return RESULT_SUCCESS; 319 return RESULT_SUCCESS;
320} 320}
321 321
diff --git a/src/core/hw/gpu.cpp b/src/core/hw/gpu.cpp
index e4a0e14c4..8ef1f70df 100644
--- a/src/core/hw/gpu.cpp
+++ b/src/core/hw/gpu.cpp
@@ -8,7 +8,7 @@
8 8
9#include "core/settings.h" 9#include "core/settings.h"
10#include "core/core.h" 10#include "core/core.h"
11#include "core/mem_map.h" 11#include "core/memory.h"
12#include "core/core_timing.h" 12#include "core/core_timing.h"
13 13
14#include "core/hle/hle.h" 14#include "core/hle/hle.h"
diff --git a/src/core/loader/3dsx.cpp b/src/core/loader/3dsx.cpp
index e28986085..84b13ee52 100644
--- a/src/core/loader/3dsx.cpp
+++ b/src/core/loader/3dsx.cpp
@@ -12,7 +12,7 @@
12#include "core/hle/service/fs/archive.h" 12#include "core/hle/service/fs/archive.h"
13#include "core/loader/elf.h" 13#include "core/loader/elf.h"
14#include "core/loader/ncch.h" 14#include "core/loader/ncch.h"
15#include "core/mem_map.h" 15#include "core/memory.h"
16 16
17#include "3dsx.h" 17#include "3dsx.h"
18 18
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp
index 47d4e8cea..a951bc80f 100644
--- a/src/core/loader/elf.cpp
+++ b/src/core/loader/elf.cpp
@@ -12,7 +12,7 @@
12 12
13#include "core/hle/kernel/kernel.h" 13#include "core/hle/kernel/kernel.h"
14#include "core/loader/elf.h" 14#include "core/loader/elf.h"
15#include "core/mem_map.h" 15#include "core/memory.h"
16 16
17//////////////////////////////////////////////////////////////////////////////////////////////////// 17////////////////////////////////////////////////////////////////////////////////////////////////////
18// ELF Header Constants 18// ELF Header Constants
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp
index 4f881cf6f..8b14edf00 100644
--- a/src/core/loader/loader.cpp
+++ b/src/core/loader/loader.cpp
@@ -13,7 +13,6 @@
13#include "core/loader/3dsx.h" 13#include "core/loader/3dsx.h"
14#include "core/loader/elf.h" 14#include "core/loader/elf.h"
15#include "core/loader/ncch.h" 15#include "core/loader/ncch.h"
16#include "core/mem_map.h"
17 16
18//////////////////////////////////////////////////////////////////////////////////////////////////// 17////////////////////////////////////////////////////////////////////////////////////////////////////
19 18
diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp
index 3325a6ab8..36e341fd4 100644
--- a/src/core/loader/ncch.cpp
+++ b/src/core/loader/ncch.cpp
@@ -12,7 +12,7 @@
12 12
13#include "core/hle/kernel/kernel.h" 13#include "core/hle/kernel/kernel.h"
14#include "core/loader/ncch.h" 14#include "core/loader/ncch.h"
15#include "core/mem_map.h" 15#include "core/memory.h"
16 16
17//////////////////////////////////////////////////////////////////////////////////////////////////// 17////////////////////////////////////////////////////////////////////////////////////////////////////
18// Loader namespace 18// Loader namespace
diff --git a/src/core/mem_map.cpp b/src/core/mem_map.cpp
index f99520464..5ecec9566 100644
--- a/src/core/mem_map.cpp
+++ b/src/core/mem_map.cpp
@@ -2,10 +2,16 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <map>
6
5#include "common/common_types.h" 7#include "common/common_types.h"
6#include "common/logging/log.h" 8#include "common/logging/log.h"
7 9
10#include "core/hle/config_mem.h"
11#include "core/hle/shared_page.h"
8#include "core/mem_map.h" 12#include "core/mem_map.h"
13#include "core/memory.h"
14#include "core/memory_setup.h"
9 15
10//////////////////////////////////////////////////////////////////////////////////////////////////// 16////////////////////////////////////////////////////////////////////////////////////////////////////
11 17
@@ -23,33 +29,129 @@ namespace {
23 29
24struct MemoryArea { 30struct MemoryArea {
25 u8** ptr; 31 u8** ptr;
26 size_t size; 32 u32 base;
33 u32 size;
27}; 34};
28 35
29// We don't declare the IO regions in here since its handled by other means. 36// We don't declare the IO regions in here since its handled by other means.
30static MemoryArea memory_areas[] = { 37static MemoryArea memory_areas[] = {
31 {&g_exefs_code, PROCESS_IMAGE_MAX_SIZE}, 38 {&g_exefs_code, PROCESS_IMAGE_VADDR, PROCESS_IMAGE_MAX_SIZE},
32 {&g_heap, HEAP_SIZE }, 39 {&g_heap, HEAP_VADDR, HEAP_SIZE },
33 {&g_shared_mem, SHARED_MEMORY_SIZE }, 40 {&g_shared_mem, SHARED_MEMORY_VADDR, SHARED_MEMORY_SIZE },
34 {&g_heap_linear, LINEAR_HEAP_SIZE }, 41 {&g_heap_linear, LINEAR_HEAP_VADDR, LINEAR_HEAP_SIZE },
35 {&g_vram, VRAM_SIZE }, 42 {&g_vram, VRAM_VADDR, VRAM_SIZE },
36 {&g_dsp_mem, DSP_RAM_SIZE }, 43 {&g_dsp_mem, DSP_RAM_VADDR, DSP_RAM_SIZE },
37 {&g_tls_mem, TLS_AREA_SIZE }, 44 {&g_tls_mem, TLS_AREA_VADDR, TLS_AREA_SIZE },
45};
46
47/// Represents a block of memory mapped by ControlMemory/MapMemoryBlock
48struct MemoryBlock {
49 MemoryBlock() : handle(0), base_address(0), address(0), size(0), operation(0), permissions(0) {
50 }
51 u32 handle;
52 u32 base_address;
53 u32 address;
54 u32 size;
55 u32 operation;
56 u32 permissions;
57
58 const u32 GetVirtualAddress() const{
59 return base_address + address;
60 }
38}; 61};
39 62
63static std::map<u32, MemoryBlock> heap_map;
64static std::map<u32, MemoryBlock> heap_linear_map;
65
66}
67
68u32 MapBlock_Heap(u32 size, u32 operation, u32 permissions) {
69 MemoryBlock block;
70
71 block.base_address = HEAP_VADDR;
72 block.size = size;
73 block.operation = operation;
74 block.permissions = permissions;
75
76 if (heap_map.size() > 0) {
77 const MemoryBlock last_block = heap_map.rbegin()->second;
78 block.address = last_block.address + last_block.size;
79 }
80 heap_map[block.GetVirtualAddress()] = block;
81
82 return block.GetVirtualAddress();
83}
84
85u32 MapBlock_HeapLinear(u32 size, u32 operation, u32 permissions) {
86 MemoryBlock block;
87
88 block.base_address = LINEAR_HEAP_VADDR;
89 block.size = size;
90 block.operation = operation;
91 block.permissions = permissions;
92
93 if (heap_linear_map.size() > 0) {
94 const MemoryBlock last_block = heap_linear_map.rbegin()->second;
95 block.address = last_block.address + last_block.size;
96 }
97 heap_linear_map[block.GetVirtualAddress()] = block;
98
99 return block.GetVirtualAddress();
100}
101
102PAddr VirtualToPhysicalAddress(const VAddr addr) {
103 if (addr == 0) {
104 return 0;
105 } else if (addr >= VRAM_VADDR && addr < VRAM_VADDR_END) {
106 return addr - VRAM_VADDR + VRAM_PADDR;
107 } else if (addr >= LINEAR_HEAP_VADDR && addr < LINEAR_HEAP_VADDR_END) {
108 return addr - LINEAR_HEAP_VADDR + FCRAM_PADDR;
109 } else if (addr >= DSP_RAM_VADDR && addr < DSP_RAM_VADDR_END) {
110 return addr - DSP_RAM_VADDR + DSP_RAM_PADDR;
111 } else if (addr >= IO_AREA_VADDR && addr < IO_AREA_VADDR_END) {
112 return addr - IO_AREA_VADDR + IO_AREA_PADDR;
113 }
114
115 LOG_ERROR(HW_Memory, "Unknown virtual address @ 0x%08x", addr);
116 // To help with debugging, set bit on address so that it's obviously invalid.
117 return addr | 0x80000000;
118}
119
120VAddr PhysicalToVirtualAddress(const PAddr addr) {
121 if (addr == 0) {
122 return 0;
123 } else if (addr >= VRAM_PADDR && addr < VRAM_PADDR_END) {
124 return addr - VRAM_PADDR + VRAM_VADDR;
125 } else if (addr >= FCRAM_PADDR && addr < FCRAM_PADDR_END) {
126 return addr - FCRAM_PADDR + LINEAR_HEAP_VADDR;
127 } else if (addr >= DSP_RAM_PADDR && addr < DSP_RAM_PADDR_END) {
128 return addr - DSP_RAM_PADDR + DSP_RAM_VADDR;
129 } else if (addr >= IO_AREA_PADDR && addr < IO_AREA_PADDR_END) {
130 return addr - IO_AREA_PADDR + IO_AREA_VADDR;
131 }
132
133 LOG_ERROR(HW_Memory, "Unknown physical address @ 0x%08x", addr);
134 // To help with debugging, set bit on address so that it's obviously invalid.
135 return addr | 0x80000000;
40} 136}
41 137
42void Init() { 138void Init() {
139 InitMemoryMap();
140
43 for (MemoryArea& area : memory_areas) { 141 for (MemoryArea& area : memory_areas) {
44 *area.ptr = new u8[area.size]; 142 *area.ptr = new u8[area.size];
143 MapMemoryRegion(area.base, area.size, *area.ptr);
45 } 144 }
46 MemBlock_Init(); 145 MapMemoryRegion(CONFIG_MEMORY_VADDR, CONFIG_MEMORY_SIZE, (u8*)&ConfigMem::config_mem);
146 MapMemoryRegion(SHARED_PAGE_VADDR, SHARED_PAGE_SIZE, (u8*)&SharedPage::shared_page);
47 147
48 LOG_DEBUG(HW_Memory, "initialized OK, RAM at %p", g_heap); 148 LOG_DEBUG(HW_Memory, "initialized OK, RAM at %p", g_heap);
49} 149}
50 150
51void Shutdown() { 151void Shutdown() {
52 MemBlock_Shutdown(); 152 heap_map.clear();
153 heap_linear_map.clear();
154
53 for (MemoryArea& area : memory_areas) { 155 for (MemoryArea& area : memory_areas) {
54 delete[] *area.ptr; 156 delete[] *area.ptr;
55 *area.ptr = nullptr; 157 *area.ptr = nullptr;
diff --git a/src/core/mem_map.h b/src/core/mem_map.h
index 71f90cb8a..945815cd6 100644
--- a/src/core/mem_map.h
+++ b/src/core/mem_map.h
@@ -8,121 +8,6 @@
8 8
9namespace Memory { 9namespace Memory {
10 10
11////////////////////////////////////////////////////////////////////////////////////////////////////
12
13const u32 PAGE_SIZE = 0x1000;
14
15/// Physical memory regions as seen from the ARM11
16enum : PAddr {
17 /// IO register area
18 IO_AREA_PADDR = 0x10100000,
19 IO_AREA_SIZE = 0x01000000, ///< IO area size (16MB)
20 IO_AREA_PADDR_END = IO_AREA_PADDR + IO_AREA_SIZE,
21
22 /// MPCore internal memory region
23 MPCORE_RAM_PADDR = 0x17E00000,
24 MPCORE_RAM_SIZE = 0x00002000, ///< MPCore internal memory size (8KB)
25 MPCORE_RAM_PADDR_END = MPCORE_RAM_PADDR + MPCORE_RAM_SIZE,
26
27 /// Video memory
28 VRAM_PADDR = 0x18000000,
29 VRAM_SIZE = 0x00600000, ///< VRAM size (6MB)
30 VRAM_PADDR_END = VRAM_PADDR + VRAM_SIZE,
31
32 /// DSP memory
33 DSP_RAM_PADDR = 0x1FF00000,
34 DSP_RAM_SIZE = 0x00080000, ///< DSP memory size (512KB)
35 DSP_RAM_PADDR_END = DSP_RAM_PADDR + DSP_RAM_SIZE,
36
37 /// AXI WRAM
38 AXI_WRAM_PADDR = 0x1FF80000,
39 AXI_WRAM_SIZE = 0x00080000, ///< AXI WRAM size (512KB)
40 AXI_WRAM_PADDR_END = AXI_WRAM_PADDR + AXI_WRAM_SIZE,
41
42 /// Main FCRAM
43 FCRAM_PADDR = 0x20000000,
44 FCRAM_SIZE = 0x08000000, ///< FCRAM size (128MB)
45 FCRAM_PADDR_END = FCRAM_PADDR + FCRAM_SIZE,
46};
47
48/// Virtual user-space memory regions
49enum : VAddr {
50 /// Where the application text, data and bss reside.
51 PROCESS_IMAGE_VADDR = 0x00100000,
52 PROCESS_IMAGE_MAX_SIZE = 0x03F00000,
53 PROCESS_IMAGE_VADDR_END = PROCESS_IMAGE_VADDR + PROCESS_IMAGE_MAX_SIZE,
54
55 /// Area where IPC buffers are mapped onto.
56 IPC_MAPPING_VADDR = 0x04000000,
57 IPC_MAPPING_SIZE = 0x04000000,
58 IPC_MAPPING_VADDR_END = IPC_MAPPING_VADDR + IPC_MAPPING_SIZE,
59
60 /// Application heap (includes stack).
61 HEAP_VADDR = 0x08000000,
62 HEAP_SIZE = 0x08000000,
63 HEAP_VADDR_END = HEAP_VADDR + HEAP_SIZE,
64
65 /// Area where shared memory buffers are mapped onto.
66 SHARED_MEMORY_VADDR = 0x10000000,
67 SHARED_MEMORY_SIZE = 0x04000000,
68 SHARED_MEMORY_VADDR_END = SHARED_MEMORY_VADDR + SHARED_MEMORY_SIZE,
69
70 /// Maps 1:1 to an offset in FCRAM. Used for HW allocations that need to be linear in physical memory.
71 LINEAR_HEAP_VADDR = 0x14000000,
72 LINEAR_HEAP_SIZE = 0x08000000,
73 LINEAR_HEAP_VADDR_END = LINEAR_HEAP_VADDR + LINEAR_HEAP_SIZE,
74
75 /// Maps 1:1 to the IO register area.
76 IO_AREA_VADDR = 0x1EC00000,
77 IO_AREA_VADDR_END = IO_AREA_VADDR + IO_AREA_SIZE,
78
79 /// Maps 1:1 to VRAM.
80 VRAM_VADDR = 0x1F000000,
81 VRAM_VADDR_END = VRAM_VADDR + VRAM_SIZE,
82
83 /// Maps 1:1 to DSP memory.
84 DSP_RAM_VADDR = 0x1FF00000,
85 DSP_RAM_VADDR_END = DSP_RAM_VADDR + DSP_RAM_SIZE,
86
87 /// Read-only page containing kernel and system configuration values.
88 CONFIG_MEMORY_VADDR = 0x1FF80000,
89 CONFIG_MEMORY_SIZE = 0x00001000,
90 CONFIG_MEMORY_VADDR_END = CONFIG_MEMORY_VADDR + CONFIG_MEMORY_SIZE,
91
92 /// Usually read-only page containing mostly values read from hardware.
93 SHARED_PAGE_VADDR = 0x1FF81000,
94 SHARED_PAGE_SIZE = 0x00001000,
95 SHARED_PAGE_VADDR_END = SHARED_PAGE_VADDR + SHARED_PAGE_SIZE,
96
97 // TODO(yuriks): The size of this area is dynamic, the kernel grows
98 // it as more and more threads are created. For now we'll just use a
99 // hardcoded value.
100 /// Area where TLS (Thread-Local Storage) buffers are allocated.
101 TLS_AREA_VADDR = 0x1FF82000,
102 TLS_AREA_SIZE = 0x00030000, // Each TLS buffer is 0x200 bytes, allows for 300 threads
103 TLS_AREA_VADDR_END = TLS_AREA_VADDR + TLS_AREA_SIZE,
104};
105
106////////////////////////////////////////////////////////////////////////////////////////////////////
107
108/// Represents a block of memory mapped by ControlMemory/MapMemoryBlock
109struct MemoryBlock {
110 MemoryBlock() : handle(0), base_address(0), address(0), size(0), operation(0), permissions(0) {
111 }
112 u32 handle;
113 u32 base_address;
114 u32 address;
115 u32 size;
116 u32 operation;
117 u32 permissions;
118
119 const u32 GetVirtualAddress() const{
120 return base_address + address;
121 }
122};
123
124////////////////////////////////////////////////////////////////////////////////////////////////////
125
126extern u8* g_exefs_code; ///< ExeFS:/.code is loaded here 11extern u8* g_exefs_code; ///< ExeFS:/.code is loaded here
127extern u8* g_heap; ///< Application heap (main memory) 12extern u8* g_heap; ///< Application heap (main memory)
128extern u8* g_shared_mem; ///< Shared memory 13extern u8* g_shared_mem; ///< Shared memory
@@ -134,29 +19,6 @@ extern u8* g_tls_mem; ///< TLS memory
134void Init(); 19void Init();
135void Shutdown(); 20void Shutdown();
136 21
137template <typename T>
138inline void Read(T &var, VAddr addr);
139
140template <typename T>
141inline void Write(VAddr addr, T data);
142
143u8 Read8(VAddr addr);
144u16 Read16(VAddr addr);
145u32 Read32(VAddr addr);
146u64 Read64(VAddr addr);
147
148u32 Read8_ZX(VAddr addr);
149u32 Read16_ZX(VAddr addr);
150
151void Write8(VAddr addr, u8 data);
152void Write16(VAddr addr, u16 data);
153void Write32(VAddr addr, u32 data);
154void Write64(VAddr addr, u64 data);
155
156void WriteBlock(VAddr addr, const u8* data, size_t size);
157
158u8* GetPointer(VAddr virtual_address);
159
160/** 22/**
161 * Maps a block of memory on the heap 23 * Maps a block of memory on the heap
162 * @param size Size of block in bytes 24 * @param size Size of block in bytes
@@ -173,16 +35,6 @@ u32 MapBlock_Heap(u32 size, u32 operation, u32 permissions);
173 */ 35 */
174u32 MapBlock_HeapLinear(u32 size, u32 operation, u32 permissions); 36u32 MapBlock_HeapLinear(u32 size, u32 operation, u32 permissions);
175 37
176/// Initialize mapped memory blocks
177void MemBlock_Init();
178
179/// Shutdown mapped memory blocks
180void MemBlock_Shutdown();
181
182inline const char* GetCharPointer(const VAddr address) {
183 return (const char *)GetPointer(address);
184}
185
186/** 38/**
187 * Converts a virtual address inside a region with 1:1 mapping to physical memory to a physical 39 * Converts a virtual address inside a region with 1:1 mapping to physical memory to a physical
188 * address. This should be used by services to translate addresses for use by the hardware. 40 * address. This should be used by services to translate addresses for use by the hardware.
@@ -194,13 +46,4 @@ PAddr VirtualToPhysicalAddress(VAddr addr);
194 */ 46 */
195VAddr PhysicalToVirtualAddress(PAddr addr); 47VAddr PhysicalToVirtualAddress(PAddr addr);
196 48
197/**
198 * Gets a pointer to the memory region beginning at the specified physical address.
199 *
200 * @note This is currently implemented using PhysicalToVirtualAddress().
201 */
202inline u8* GetPhysicalPointer(PAddr address) {
203 return GetPointer(PhysicalToVirtualAddress(address));
204}
205
206} // namespace 49} // namespace
diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp
deleted file mode 100644
index a8e0fed07..000000000
--- a/src/core/mem_map_funcs.cpp
+++ /dev/null
@@ -1,283 +0,0 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <map>
6
7#include "common/common_types.h"
8#include "common/logging/log.h"
9#include "common/swap.h"
10
11#include "core/mem_map.h"
12#include "core/hw/hw.h"
13#include "hle/config_mem.h"
14#include "hle/shared_page.h"
15
16namespace Memory {
17
18static std::map<u32, MemoryBlock> heap_map;
19static std::map<u32, MemoryBlock> heap_linear_map;
20
21PAddr VirtualToPhysicalAddress(const VAddr addr) {
22 if (addr == 0) {
23 return 0;
24 } else if (addr >= VRAM_VADDR && addr < VRAM_VADDR_END) {
25 return addr - VRAM_VADDR + VRAM_PADDR;
26 } else if (addr >= LINEAR_HEAP_VADDR && addr < LINEAR_HEAP_VADDR_END) {
27 return addr - LINEAR_HEAP_VADDR + FCRAM_PADDR;
28 } else if (addr >= DSP_RAM_VADDR && addr < DSP_RAM_VADDR_END) {
29 return addr - DSP_RAM_VADDR + DSP_RAM_PADDR;
30 } else if (addr >= IO_AREA_VADDR && addr < IO_AREA_VADDR_END) {
31 return addr - IO_AREA_VADDR + IO_AREA_PADDR;
32 }
33
34 LOG_ERROR(HW_Memory, "Unknown virtual address @ 0x%08x", addr);
35 // To help with debugging, set bit on address so that it's obviously invalid.
36 return addr | 0x80000000;
37}
38
39VAddr PhysicalToVirtualAddress(const PAddr addr) {
40 if (addr == 0) {
41 return 0;
42 } else if (addr >= VRAM_PADDR && addr < VRAM_PADDR_END) {
43 return addr - VRAM_PADDR + VRAM_VADDR;
44 } else if (addr >= FCRAM_PADDR && addr < FCRAM_PADDR_END) {
45 return addr - FCRAM_PADDR + LINEAR_HEAP_VADDR;
46 } else if (addr >= DSP_RAM_PADDR && addr < DSP_RAM_PADDR_END) {
47 return addr - DSP_RAM_PADDR + DSP_RAM_VADDR;
48 } else if (addr >= IO_AREA_PADDR && addr < IO_AREA_PADDR_END) {
49 return addr - IO_AREA_PADDR + IO_AREA_VADDR;
50 }
51
52 LOG_ERROR(HW_Memory, "Unknown physical address @ 0x%08x", addr);
53 // To help with debugging, set bit on address so that it's obviously invalid.
54 return addr | 0x80000000;
55}
56
57template <typename T>
58inline void Read(T &var, const VAddr vaddr) {
59 // TODO: Figure out the fastest order of tests for both read and write (they are probably different).
60 // TODO: Make sure this represents the mirrors in a correct way.
61 // Could just do a base-relative read, too.... TODO
62
63 // Kernel memory command buffer
64 if (vaddr >= TLS_AREA_VADDR && vaddr < TLS_AREA_VADDR_END) {
65 var = *((const T*)&g_tls_mem[vaddr - TLS_AREA_VADDR]);
66
67 // ExeFS:/.code is loaded here
68 } else if ((vaddr >= PROCESS_IMAGE_VADDR) && (vaddr < PROCESS_IMAGE_VADDR_END)) {
69 var = *((const T*)&g_exefs_code[vaddr - PROCESS_IMAGE_VADDR]);
70
71 // FCRAM - linear heap
72 } else if ((vaddr >= LINEAR_HEAP_VADDR) && (vaddr < LINEAR_HEAP_VADDR_END)) {
73 var = *((const T*)&g_heap_linear[vaddr - LINEAR_HEAP_VADDR]);
74
75 // FCRAM - application heap
76 } else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) {
77 var = *((const T*)&g_heap[vaddr - HEAP_VADDR]);
78
79 // Shared memory
80 } else if ((vaddr >= SHARED_MEMORY_VADDR) && (vaddr < SHARED_MEMORY_VADDR_END)) {
81 var = *((const T*)&g_shared_mem[vaddr - SHARED_MEMORY_VADDR]);
82
83 // Config memory
84 } else if ((vaddr >= CONFIG_MEMORY_VADDR) && (vaddr < CONFIG_MEMORY_VADDR_END)) {
85 ConfigMem::Read<T>(var, vaddr);
86
87 // Shared page
88 } else if ((vaddr >= SHARED_PAGE_VADDR) && (vaddr < SHARED_PAGE_VADDR_END)) {
89 SharedPage::Read<T>(var, vaddr);
90
91 // DSP memory
92 } else if ((vaddr >= DSP_RAM_VADDR) && (vaddr < DSP_RAM_VADDR_END)) {
93 var = *((const T*)&g_dsp_mem[vaddr - DSP_RAM_VADDR]);
94
95 // VRAM
96 } else if ((vaddr >= VRAM_VADDR) && (vaddr < VRAM_VADDR_END)) {
97 var = *((const T*)&g_vram[vaddr - VRAM_VADDR]);
98
99 } else {
100 LOG_ERROR(HW_Memory, "unknown Read%lu @ 0x%08X", sizeof(var) * 8, vaddr);
101 }
102}
103
104template <typename T>
105inline void Write(const VAddr vaddr, const T data) {
106
107 // Kernel memory command buffer
108 if (vaddr >= TLS_AREA_VADDR && vaddr < TLS_AREA_VADDR_END) {
109 *(T*)&g_tls_mem[vaddr - TLS_AREA_VADDR] = data;
110
111 // ExeFS:/.code is loaded here
112 } else if ((vaddr >= PROCESS_IMAGE_VADDR) && (vaddr < PROCESS_IMAGE_VADDR_END)) {
113 *(T*)&g_exefs_code[vaddr - PROCESS_IMAGE_VADDR] = data;
114
115 // FCRAM - linear heap
116 } else if ((vaddr >= LINEAR_HEAP_VADDR) && (vaddr < LINEAR_HEAP_VADDR_END)) {
117 *(T*)&g_heap_linear[vaddr - LINEAR_HEAP_VADDR] = data;
118
119 // FCRAM - application heap
120 } else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) {
121 *(T*)&g_heap[vaddr - HEAP_VADDR] = data;
122
123 // Shared memory
124 } else if ((vaddr >= SHARED_MEMORY_VADDR) && (vaddr < SHARED_MEMORY_VADDR_END)) {
125 *(T*)&g_shared_mem[vaddr - SHARED_MEMORY_VADDR] = data;
126
127 // VRAM
128 } else if ((vaddr >= VRAM_VADDR) && (vaddr < VRAM_VADDR_END)) {
129 *(T*)&g_vram[vaddr - VRAM_VADDR] = data;
130
131 // DSP memory
132 } else if ((vaddr >= DSP_RAM_VADDR) && (vaddr < DSP_RAM_VADDR_END)) {
133 *(T*)&g_dsp_mem[vaddr - DSP_RAM_VADDR] = data;
134
135 //} else if ((vaddr & 0xFFFF0000) == 0x1FF80000) {
136 // ASSERT_MSG(MEMMAP, false, "umimplemented write to Configuration Memory");
137 //} else if ((vaddr & 0xFFFFF000) == 0x1FF81000) {
138 // ASSERT_MSG(MEMMAP, false, "umimplemented write to shared page");
139
140 // Error out...
141 } else {
142 LOG_ERROR(HW_Memory, "unknown Write%lu 0x%08X @ 0x%08X", sizeof(data) * 8, (u32)data, vaddr);
143 }
144}
145
146u8 *GetPointer(const VAddr vaddr) {
147 // Kernel memory command buffer
148 if (vaddr >= TLS_AREA_VADDR && vaddr < TLS_AREA_VADDR_END) {
149 return g_tls_mem + (vaddr - TLS_AREA_VADDR);
150
151 // ExeFS:/.code is loaded here
152 } else if ((vaddr >= PROCESS_IMAGE_VADDR) && (vaddr < PROCESS_IMAGE_VADDR_END)) {
153 return g_exefs_code + (vaddr - PROCESS_IMAGE_VADDR);
154
155 // FCRAM - linear heap
156 } else if ((vaddr >= LINEAR_HEAP_VADDR) && (vaddr < LINEAR_HEAP_VADDR_END)) {
157 return g_heap_linear + (vaddr - LINEAR_HEAP_VADDR);
158
159 // FCRAM - application heap
160 } else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) {
161 return g_heap + (vaddr - HEAP_VADDR);
162
163 // Shared memory
164 } else if ((vaddr >= SHARED_MEMORY_VADDR) && (vaddr < SHARED_MEMORY_VADDR_END)) {
165 return g_shared_mem + (vaddr - SHARED_MEMORY_VADDR);
166
167 // VRAM
168 } else if ((vaddr >= VRAM_VADDR) && (vaddr < VRAM_VADDR_END)) {
169 return g_vram + (vaddr - VRAM_VADDR);
170
171 } else {
172 LOG_ERROR(HW_Memory, "unknown GetPointer @ 0x%08x", vaddr);
173 return 0;
174 }
175}
176
177u32 MapBlock_Heap(u32 size, u32 operation, u32 permissions) {
178 MemoryBlock block;
179
180 block.base_address = HEAP_VADDR;
181 block.size = size;
182 block.operation = operation;
183 block.permissions = permissions;
184
185 if (heap_map.size() > 0) {
186 const MemoryBlock last_block = heap_map.rbegin()->second;
187 block.address = last_block.address + last_block.size;
188 }
189 heap_map[block.GetVirtualAddress()] = block;
190
191 return block.GetVirtualAddress();
192}
193
194u32 MapBlock_HeapLinear(u32 size, u32 operation, u32 permissions) {
195 MemoryBlock block;
196
197 block.base_address = LINEAR_HEAP_VADDR;
198 block.size = size;
199 block.operation = operation;
200 block.permissions = permissions;
201
202 if (heap_linear_map.size() > 0) {
203 const MemoryBlock last_block = heap_linear_map.rbegin()->second;
204 block.address = last_block.address + last_block.size;
205 }
206 heap_linear_map[block.GetVirtualAddress()] = block;
207
208 return block.GetVirtualAddress();
209}
210
211void MemBlock_Init() {
212}
213
214void MemBlock_Shutdown() {
215 heap_map.clear();
216 heap_linear_map.clear();
217}
218
219u8 Read8(const VAddr addr) {
220 u8 data = 0;
221 Read<u8>(data, addr);
222 return data;
223}
224
225u16 Read16(const VAddr addr) {
226 u16_le data = 0;
227 Read<u16_le>(data, addr);
228 return (u16)data;
229}
230
231u32 Read32(const VAddr addr) {
232 u32_le data = 0;
233 Read<u32_le>(data, addr);
234 return (u32)data;
235}
236
237u64 Read64(const VAddr addr) {
238 u64_le data = 0;
239 Read<u64_le>(data, addr);
240 return (u64)data;
241}
242
243u32 Read8_ZX(const VAddr addr) {
244 return (u32)Read8(addr);
245}
246
247u32 Read16_ZX(const VAddr addr) {
248 return (u32)Read16(addr);
249}
250
251void Write8(const VAddr addr, const u8 data) {
252 Write<u8>(addr, data);
253}
254
255void Write16(const VAddr addr, const u16 data) {
256 Write<u16_le>(addr, data);
257}
258
259void Write32(const VAddr addr, const u32 data) {
260 Write<u32_le>(addr, data);
261}
262
263void Write64(const VAddr addr, const u64 data) {
264 Write<u64_le>(addr, data);
265}
266
267void WriteBlock(const VAddr addr, const u8* data, const size_t size) {
268 u32 offset = 0;
269 while (offset < (size & ~3)) {
270 Write32(addr + offset, *(u32*)&data[offset]);
271 offset += 4;
272 }
273
274 if (size & 2) {
275 Write16(addr + offset, *(u16*)&data[offset]);
276 offset += 2;
277 }
278
279 if (size & 1)
280 Write8(addr + offset, data[offset]);
281}
282
283} // namespace
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
new file mode 100644
index 000000000..5d8069acd
--- /dev/null
+++ b/src/core/memory.cpp
@@ -0,0 +1,202 @@
1// Copyright 2015 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <array>
6
7#include "common/assert.h"
8#include "common/common_types.h"
9#include "common/logging/log.h"
10#include "common/swap.h"
11
12#include "core/hle/config_mem.h"
13#include "core/hle/shared_page.h"
14#include "core/hw/hw.h"
15#include "core/mem_map.h"
16#include "core/memory.h"
17
18namespace Memory {
19
20const u32 PAGE_MASK = PAGE_SIZE - 1;
21const int PAGE_BITS = 12;
22
23enum class PageType {
24 /// Page is unmapped and should cause an access error.
25 Unmapped,
26 /// Page is mapped to regular memory. This is the only type you can get pointers to.
27 Memory,
28 /// Page is mapped to a I/O region. Writing and reading to this page is handled by functions.
29 Special,
30};
31
32/**
33 * A (reasonably) fast way of allowing switchable and remmapable process address spaces. It loosely
34 * mimics the way a real CPU page table works, but instead is optimized for minimal decoding and
35 * fetching requirements when acessing. In the usual case of an access to regular memory, it only
36 * requires an indexed fetch and a check for NULL.
37 */
38struct PageTable {
39 static const size_t NUM_ENTRIES = 1 << (32 - PAGE_BITS);
40
41 /**
42 * Array of memory pointers backing each page. An entry can only be non-null if the
43 * corresponding entry in the `attributes` array is of type `Memory`.
44 */
45 std::array<u8*, NUM_ENTRIES> pointers;
46
47 /**
48 * Array of fine grained page attributes. If it is set to any value other than `Memory`, then
49 * the corresponding entry in `pointer` MUST be set to null.
50 */
51 std::array<PageType, NUM_ENTRIES> attributes;
52};
53
54/// Singular page table used for the singleton process
55static PageTable main_page_table;
56/// Currently active page table
57static PageTable* current_page_table = &main_page_table;
58
59static void MapPages(u32 base, u32 size, u8* memory, PageType type) {
60 LOG_DEBUG(HW_Memory, "Mapping %p onto %08X-%08X", memory, base * PAGE_SIZE, (base + size) * PAGE_SIZE);
61
62 u32 end = base + size;
63
64 while (base != end) {
65 ASSERT_MSG(base < PageTable::NUM_ENTRIES, "out of range mapping at %08X", base);
66
67 if (current_page_table->attributes[base] != PageType::Unmapped) {
68 LOG_ERROR(HW_Memory, "overlapping memory ranges at %08X", base * PAGE_SIZE);
69 }
70 current_page_table->attributes[base] = type;
71 current_page_table->pointers[base] = memory;
72
73 base += 1;
74 memory += PAGE_SIZE;
75 }
76}
77
78void InitMemoryMap() {
79 main_page_table.pointers.fill(nullptr);
80 main_page_table.attributes.fill(PageType::Unmapped);
81}
82
83void MapMemoryRegion(VAddr base, u32 size, u8* target) {
84 ASSERT_MSG((size & PAGE_MASK) == 0, "non-page aligned size: %08X", size);
85 ASSERT_MSG((base & PAGE_MASK) == 0, "non-page aligned base: %08X", base);
86 MapPages(base / PAGE_SIZE, size / PAGE_SIZE, target, PageType::Memory);
87}
88
89void MapIoRegion(VAddr base, u32 size) {
90 ASSERT_MSG((size & PAGE_MASK) == 0, "non-page aligned size: %08X", size);
91 ASSERT_MSG((base & PAGE_MASK) == 0, "non-page aligned base: %08X", base);
92 MapPages(base / PAGE_SIZE, size / PAGE_SIZE, nullptr, PageType::Special);
93}
94
95template <typename T>
96T Read(const VAddr vaddr) {
97 const u8* page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS];
98 if (page_pointer) {
99 return *reinterpret_cast<const T*>(page_pointer + (vaddr & PAGE_MASK));
100 }
101
102 PageType type = current_page_table->attributes[vaddr >> PAGE_BITS];
103 switch (type) {
104 case PageType::Unmapped:
105 LOG_ERROR(HW_Memory, "unmapped Read%lu @ 0x%08X", sizeof(T) * 8, vaddr);
106 return 0;
107 case PageType::Memory:
108 ASSERT_MSG(false, "Mapped memory page without a pointer @ %08X", vaddr);
109 case PageType::Special:
110 LOG_ERROR(HW_Memory, "I/O reads aren't implemented yet @ %08X", vaddr);
111 return 0;
112 default:
113 UNREACHABLE();
114 }
115}
116
117template <typename T>
118void Write(const VAddr vaddr, const T data) {
119 u8* page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS];
120 if (page_pointer) {
121 *reinterpret_cast<T*>(page_pointer + (vaddr & PAGE_MASK)) = data;
122 return;
123 }
124
125 PageType type = current_page_table->attributes[vaddr >> PAGE_BITS];
126 switch (type) {
127 case PageType::Unmapped:
128 LOG_ERROR(HW_Memory, "unmapped Write%lu 0x%08X @ 0x%08X", sizeof(data) * 8, (u32) data, vaddr);
129 return;
130 case PageType::Memory:
131 ASSERT_MSG(false, "Mapped memory page without a pointer @ %08X", vaddr);
132 case PageType::Special:
133 LOG_ERROR(HW_Memory, "I/O writes aren't implemented yet @ %08X", vaddr);
134 return;
135 default:
136 UNREACHABLE();
137 }
138}
139
140u8* GetPointer(const VAddr vaddr) {
141 u8* page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS];
142 if (page_pointer) {
143 return page_pointer + (vaddr & PAGE_MASK);
144 }
145
146 LOG_ERROR(HW_Memory, "unknown GetPointer @ 0x%08x", vaddr);
147 return nullptr;
148}
149
150u8* GetPhysicalPointer(PAddr address) {
151 return GetPointer(PhysicalToVirtualAddress(address));
152}
153
154u8 Read8(const VAddr addr) {
155 return Read<u8>(addr);
156}
157
158u16 Read16(const VAddr addr) {
159 return Read<u16_le>(addr);
160}
161
162u32 Read32(const VAddr addr) {
163 return Read<u32_le>(addr);
164}
165
166u64 Read64(const VAddr addr) {
167 return Read<u64_le>(addr);
168}
169
170void Write8(const VAddr addr, const u8 data) {
171 Write<u8>(addr, data);
172}
173
174void Write16(const VAddr addr, const u16 data) {
175 Write<u16_le>(addr, data);
176}
177
178void Write32(const VAddr addr, const u32 data) {
179 Write<u32_le>(addr, data);
180}
181
182void Write64(const VAddr addr, const u64 data) {
183 Write<u64_le>(addr, data);
184}
185
186void WriteBlock(const VAddr addr, const u8* data, const size_t size) {
187 u32 offset = 0;
188 while (offset < (size & ~3)) {
189 Write32(addr + offset, *(u32*)&data[offset]);
190 offset += 4;
191 }
192
193 if (size & 2) {
194 Write16(addr + offset, *(u16*)&data[offset]);
195 offset += 2;
196 }
197
198 if (size & 1)
199 Write8(addr + offset, data[offset]);
200}
201
202} // namespace
diff --git a/src/core/memory.h b/src/core/memory.h
new file mode 100644
index 000000000..2d225801b
--- /dev/null
+++ b/src/core/memory.h
@@ -0,0 +1,129 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/common_types.h"
8
9namespace Memory {
10
11/**
12 * Page size used by the ARM architecture. This is the smallest granularity with which memory can
13 * be mapped.
14 */
15const u32 PAGE_SIZE = 0x1000;
16
17/// Physical memory regions as seen from the ARM11
18enum : PAddr {
19 /// IO register area
20 IO_AREA_PADDR = 0x10100000,
21 IO_AREA_SIZE = 0x01000000, ///< IO area size (16MB)
22 IO_AREA_PADDR_END = IO_AREA_PADDR + IO_AREA_SIZE,
23
24 /// MPCore internal memory region
25 MPCORE_RAM_PADDR = 0x17E00000,
26 MPCORE_RAM_SIZE = 0x00002000, ///< MPCore internal memory size (8KB)
27 MPCORE_RAM_PADDR_END = MPCORE_RAM_PADDR + MPCORE_RAM_SIZE,
28
29 /// Video memory
30 VRAM_PADDR = 0x18000000,
31 VRAM_SIZE = 0x00600000, ///< VRAM size (6MB)
32 VRAM_PADDR_END = VRAM_PADDR + VRAM_SIZE,
33
34 /// DSP memory
35 DSP_RAM_PADDR = 0x1FF00000,
36 DSP_RAM_SIZE = 0x00080000, ///< DSP memory size (512KB)
37 DSP_RAM_PADDR_END = DSP_RAM_PADDR + DSP_RAM_SIZE,
38
39 /// AXI WRAM
40 AXI_WRAM_PADDR = 0x1FF80000,
41 AXI_WRAM_SIZE = 0x00080000, ///< AXI WRAM size (512KB)
42 AXI_WRAM_PADDR_END = AXI_WRAM_PADDR + AXI_WRAM_SIZE,
43
44 /// Main FCRAM
45 FCRAM_PADDR = 0x20000000,
46 FCRAM_SIZE = 0x08000000, ///< FCRAM size (128MB)
47 FCRAM_PADDR_END = FCRAM_PADDR + FCRAM_SIZE,
48};
49
50/// Virtual user-space memory regions
51enum : VAddr {
52 /// Where the application text, data and bss reside.
53 PROCESS_IMAGE_VADDR = 0x00100000,
54 PROCESS_IMAGE_MAX_SIZE = 0x03F00000,
55 PROCESS_IMAGE_VADDR_END = PROCESS_IMAGE_VADDR + PROCESS_IMAGE_MAX_SIZE,
56
57 /// Area where IPC buffers are mapped onto.
58 IPC_MAPPING_VADDR = 0x04000000,
59 IPC_MAPPING_SIZE = 0x04000000,
60 IPC_MAPPING_VADDR_END = IPC_MAPPING_VADDR + IPC_MAPPING_SIZE,
61
62 /// Application heap (includes stack).
63 HEAP_VADDR = 0x08000000,
64 HEAP_SIZE = 0x08000000,
65 HEAP_VADDR_END = HEAP_VADDR + HEAP_SIZE,
66
67 /// Area where shared memory buffers are mapped onto.
68 SHARED_MEMORY_VADDR = 0x10000000,
69 SHARED_MEMORY_SIZE = 0x04000000,
70 SHARED_MEMORY_VADDR_END = SHARED_MEMORY_VADDR + SHARED_MEMORY_SIZE,
71
72 /// Maps 1:1 to an offset in FCRAM. Used for HW allocations that need to be linear in physical memory.
73 LINEAR_HEAP_VADDR = 0x14000000,
74 LINEAR_HEAP_SIZE = 0x08000000,
75 LINEAR_HEAP_VADDR_END = LINEAR_HEAP_VADDR + LINEAR_HEAP_SIZE,
76
77 /// Maps 1:1 to the IO register area.
78 IO_AREA_VADDR = 0x1EC00000,
79 IO_AREA_VADDR_END = IO_AREA_VADDR + IO_AREA_SIZE,
80
81 /// Maps 1:1 to VRAM.
82 VRAM_VADDR = 0x1F000000,
83 VRAM_VADDR_END = VRAM_VADDR + VRAM_SIZE,
84
85 /// Maps 1:1 to DSP memory.
86 DSP_RAM_VADDR = 0x1FF00000,
87 DSP_RAM_VADDR_END = DSP_RAM_VADDR + DSP_RAM_SIZE,
88
89 /// Read-only page containing kernel and system configuration values.
90 CONFIG_MEMORY_VADDR = 0x1FF80000,
91 CONFIG_MEMORY_SIZE = 0x00001000,
92 CONFIG_MEMORY_VADDR_END = CONFIG_MEMORY_VADDR + CONFIG_MEMORY_SIZE,
93
94 /// Usually read-only page containing mostly values read from hardware.
95 SHARED_PAGE_VADDR = 0x1FF81000,
96 SHARED_PAGE_SIZE = 0x00001000,
97 SHARED_PAGE_VADDR_END = SHARED_PAGE_VADDR + SHARED_PAGE_SIZE,
98
99 // TODO(yuriks): The size of this area is dynamic, the kernel grows
100 // it as more and more threads are created. For now we'll just use a
101 // hardcoded value.
102 /// Area where TLS (Thread-Local Storage) buffers are allocated.
103 TLS_AREA_VADDR = 0x1FF82000,
104 TLS_AREA_SIZE = 0x00030000, // Each TLS buffer is 0x200 bytes, allows for 300 threads
105 TLS_AREA_VADDR_END = TLS_AREA_VADDR + TLS_AREA_SIZE,
106};
107
108u8 Read8(VAddr addr);
109u16 Read16(VAddr addr);
110u32 Read32(VAddr addr);
111u64 Read64(VAddr addr);
112
113void Write8(VAddr addr, u8 data);
114void Write16(VAddr addr, u16 data);
115void Write32(VAddr addr, u32 data);
116void Write64(VAddr addr, u64 data);
117
118void WriteBlock(VAddr addr, const u8* data, size_t size);
119
120u8* GetPointer(VAddr virtual_address);
121
122/**
123 * Gets a pointer to the memory region beginning at the specified physical address.
124 *
125 * @note This is currently implemented using PhysicalToVirtualAddress().
126 */
127u8* GetPhysicalPointer(PAddr address);
128
129}
diff --git a/src/core/memory_setup.h b/src/core/memory_setup.h
new file mode 100644
index 000000000..46263495f
--- /dev/null
+++ b/src/core/memory_setup.h
@@ -0,0 +1,29 @@
1// Copyright 2015 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/common_types.h"
8
9namespace Memory {
10
11void InitMemoryMap();
12
13/**
14 * Maps an allocated buffer onto a region of the emulated process address space.
15 *
16 * @param base The address to start mapping at. Must be page-aligned.
17 * @param size The amount of bytes to map. Must be page-aligned.
18 * @param target Buffer with the memory backing the mapping. Must be of length at least `size`.
19 */
20void MapMemoryRegion(VAddr base, u32 size, u8* target);
21
22/**
23 * Maps a region of the emulated process address space as a IO region.
24 * @note Currently this can only be used to mark a region as being IO, since actual memory-mapped
25 * IO isn't yet supported.
26 */
27void MapIoRegion(VAddr base, u32 size);
28
29}
diff --git a/src/video_core/pica.h b/src/video_core/pica.h
index a53429716..3fbf95721 100644
--- a/src/video_core/pica.h
+++ b/src/video_core/pica.h
@@ -16,8 +16,6 @@
16#include "common/common_types.h" 16#include "common/common_types.h"
17#include "common/logging/log.h" 17#include "common/logging/log.h"
18 18
19#include "core/mem_map.h"
20
21namespace Pica { 19namespace Pica {
22 20
23// Returns index corresponding to the Regs member labeled by field_name 21// Returns index corresponding to the Regs member labeled by field_name
diff --git a/src/video_core/rasterizer.cpp b/src/video_core/rasterizer.cpp
index 02a08b20e..59eff48f9 100644
--- a/src/video_core/rasterizer.cpp
+++ b/src/video_core/rasterizer.cpp
@@ -9,6 +9,8 @@
9#include "common/profiler.h" 9#include "common/profiler.h"
10 10
11#include "core/hw/gpu.h" 11#include "core/hw/gpu.h"
12#include "core/memory.h"
13
12#include "debug_utils/debug_utils.h" 14#include "debug_utils/debug_utils.h"
13#include "math.h" 15#include "math.h"
14#include "color.h" 16#include "color.h"
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp
index 0c072120d..71ceb021b 100644
--- a/src/video_core/renderer_opengl/renderer_opengl.cpp
+++ b/src/video_core/renderer_opengl/renderer_opengl.cpp
@@ -5,7 +5,7 @@
5#include "core/hw/gpu.h" 5#include "core/hw/gpu.h"
6#include "core/hw/hw.h" 6#include "core/hw/hw.h"
7#include "core/hw/lcd.h" 7#include "core/hw/lcd.h"
8#include "core/mem_map.h" 8#include "core/memory.h"
9#include "core/settings.h" 9#include "core/settings.h"
10 10
11#include "common/emu_window.h" 11#include "common/emu_window.h"
diff --git a/src/video_core/vertex_shader.cpp b/src/video_core/vertex_shader.cpp
index 4734e546a..981d1a356 100644
--- a/src/video_core/vertex_shader.cpp
+++ b/src/video_core/vertex_shader.cpp
@@ -8,8 +8,6 @@
8 8
9#include <common/file_util.h> 9#include <common/file_util.h>
10 10
11#include <core/mem_map.h>
12
13#include <nihstro/shader_bytecode.h> 11#include <nihstro/shader_bytecode.h>
14 12
15#include "common/profiler.h" 13#include "common/profiler.h"