summaryrefslogtreecommitdiff
path: root/src/core/hle
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/core/hle
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/core/hle')
-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
13 files changed, 83 insertions, 119 deletions
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