summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/arm/dyncom/arm_dyncom.cpp4
-rw-r--r--src/core/arm/dyncom/arm_dyncom_interpreter.cpp31
-rw-r--r--src/core/arm/interpreter/arminit.cpp2
-rw-r--r--src/core/arm/skyeye_common/armdefs.h6
-rw-r--r--src/core/core_timing.cpp10
-rw-r--r--src/core/hle/config_mem.cpp5
-rw-r--r--src/core/hle/config_mem.h2
-rw-r--r--src/core/hle/hle.cpp9
-rw-r--r--src/core/hle/kernel/kernel.cpp11
-rw-r--r--src/core/hle/kernel/kernel.h5
-rw-r--r--src/core/hle/kernel/thread.cpp10
-rw-r--r--src/core/hle/kernel/timer.cpp3
-rw-r--r--src/core/hle/service/apt/apt.cpp17
-rw-r--r--src/core/hle/service/cfg/cfg.cpp2
-rw-r--r--src/core/hle/service/dsp_dsp.cpp2
-rw-r--r--src/core/hle/service/hid/hid.cpp22
-rw-r--r--src/core/hle/service/ir/ir.cpp6
-rw-r--r--src/core/hle/service/nwm_uds.cpp2
-rw-r--r--src/core/hle/service/ptm/ptm.cpp7
-rw-r--r--src/core/hle/service/y2r_u.cpp2
-rw-r--r--src/core/hle/shared_page.cpp5
-rw-r--r--src/core/hle/shared_page.h2
-rw-r--r--src/core/hw/gpu.cpp8
-rw-r--r--src/core/hw/hw.cpp2
-rw-r--r--src/core/hw/lcd.cpp1
-rw-r--r--src/core/mem_map.cpp71
-rw-r--r--src/core/mem_map.h6
-rw-r--r--src/core/mem_map_funcs.cpp21
28 files changed, 174 insertions, 100 deletions
diff --git a/src/core/arm/dyncom/arm_dyncom.cpp b/src/core/arm/dyncom/arm_dyncom.cpp
index bc1e969e4..128413262 100644
--- a/src/core/arm/dyncom/arm_dyncom.cpp
+++ b/src/core/arm/dyncom/arm_dyncom.cpp
@@ -2,6 +2,8 @@
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 "common/make_unique.h"
6
5#include "core/arm/skyeye_common/armemu.h" 7#include "core/arm/skyeye_common/armemu.h"
6#include "core/arm/skyeye_common/vfp/vfp.h" 8#include "core/arm/skyeye_common/vfp/vfp.h"
7 9
@@ -17,7 +19,7 @@ const static cpu_config_t s_arm11_cpu_info = {
17}; 19};
18 20
19ARM_DynCom::ARM_DynCom(PrivilegeMode initial_mode) { 21ARM_DynCom::ARM_DynCom(PrivilegeMode initial_mode) {
20 state = std::unique_ptr<ARMul_State>(new ARMul_State); 22 state = Common::make_unique<ARMul_State>();
21 23
22 ARMul_NewState(state.get()); 24 ARMul_NewState(state.get());
23 ARMul_SelectProcessor(state.get(), ARM_v6_Prop | ARM_v5_Prop | ARM_v5e_Prop); 25 ARMul_SelectProcessor(state.get(), ARM_v6_Prop | ARM_v5_Prop | ARM_v5e_Prop);
diff --git a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
index fde11e4ff..991da740b 100644
--- a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
+++ b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
@@ -6,7 +6,6 @@
6 6
7#include <algorithm> 7#include <algorithm>
8#include <cstdio> 8#include <cstdio>
9#include <unordered_map>
10 9
11#include "common/logging/log.h" 10#include "common/logging/log.h"
12#include "common/profiler.h" 11#include "common/profiler.h"
@@ -3533,25 +3532,6 @@ const transop_fp_t arm_instruction_trans[] = {
3533 INTERPRETER_TRANSLATE(blx_1_thumb) 3532 INTERPRETER_TRANSLATE(blx_1_thumb)
3534}; 3533};
3535 3534
3536typedef std::unordered_map<u32, int> bb_map;
3537static bb_map CreamCache;
3538
3539static void insert_bb(unsigned int addr, int start) {
3540 CreamCache[addr] = start;
3541}
3542
3543static int find_bb(unsigned int addr, int& start) {
3544 int ret = -1;
3545 bb_map::const_iterator it = CreamCache.find(addr);
3546 if (it != CreamCache.end()) {
3547 start = static_cast<int>(it->second);
3548 ret = 0;
3549 } else {
3550 ret = -1;
3551 }
3552 return ret;
3553}
3554
3555enum { 3535enum {
3556 FETCH_SUCCESS, 3536 FETCH_SUCCESS,
3557 FETCH_FAILURE 3537 FETCH_FAILURE
@@ -3674,7 +3654,9 @@ translated:
3674 } 3654 }
3675 ret = inst_base->br; 3655 ret = inst_base->br;
3676 }; 3656 };
3677 insert_bb(pc_start, bb_start); 3657
3658 cpu->instruction_cache[pc_start] = bb_start;
3659
3678 return KEEP_GOING; 3660 return KEEP_GOING;
3679} 3661}
3680 3662
@@ -4001,9 +3983,14 @@ unsigned InterpreterMainLoop(ARMul_State* state) {
4001 3983
4002 phys_addr = cpu->Reg[15]; 3984 phys_addr = cpu->Reg[15];
4003 3985
4004 if (find_bb(cpu->Reg[15], ptr) == -1) 3986 // Find the cached instruction cream, otherwise translate it...
3987 auto itr = cpu->instruction_cache.find(cpu->Reg[15]);
3988 if (itr != cpu->instruction_cache.end()) {
3989 ptr = itr->second;
3990 } else {
4005 if (InterpreterTranslate(cpu, ptr, cpu->Reg[15]) == FETCH_EXCEPTION) 3991 if (InterpreterTranslate(cpu, ptr, cpu->Reg[15]) == FETCH_EXCEPTION)
4006 goto END; 3992 goto END;
3993 }
4007 3994
4008 inst_base = (arm_inst *)&inst_buf[ptr]; 3995 inst_base = (arm_inst *)&inst_buf[ptr];
4009 GOTO_NEXT_INST; 3996 GOTO_NEXT_INST;
diff --git a/src/core/arm/interpreter/arminit.cpp b/src/core/arm/interpreter/arminit.cpp
index 6ac45c396..31b2bab06 100644
--- a/src/core/arm/interpreter/arminit.cpp
+++ b/src/core/arm/interpreter/arminit.cpp
@@ -26,8 +26,6 @@
26\***************************************************************************/ 26\***************************************************************************/
27ARMul_State* ARMul_NewState(ARMul_State* state) 27ARMul_State* ARMul_NewState(ARMul_State* state)
28{ 28{
29 memset(state, 0, sizeof(ARMul_State));
30
31 state->Emulate = RUN; 29 state->Emulate = RUN;
32 state->Mode = USER32MODE; 30 state->Mode = USER32MODE;
33 31
diff --git a/src/core/arm/skyeye_common/armdefs.h b/src/core/arm/skyeye_common/armdefs.h
index 08da6d9eb..85d523bc2 100644
--- a/src/core/arm/skyeye_common/armdefs.h
+++ b/src/core/arm/skyeye_common/armdefs.h
@@ -17,6 +17,8 @@
17 17
18#pragma once 18#pragma once
19 19
20#include <unordered_map>
21
20#include "common/common_types.h" 22#include "common/common_types.h"
21#include "core/arm/skyeye_common/arm_regformat.h" 23#include "core/arm/skyeye_common/arm_regformat.h"
22#include "core/arm/skyeye_common/skyeye_defs.h" 24#include "core/arm/skyeye_common/skyeye_defs.h"
@@ -152,6 +154,10 @@ So, if lateabtSig=1, then it means Late Abort Model(Base Updated Abort Model)
152 154
153 // Added by ksh in 2005-10-1 155 // Added by ksh in 2005-10-1
154 cpu_config_t* cpu; 156 cpu_config_t* cpu;
157
158 // TODO(bunnei): Move this cache to a better place - it should be per codeset (likely per
159 // process for our purposes), not per ARMul_State (which tracks CPU core state).
160 std::unordered_map<u32, int> instruction_cache;
155}; 161};
156 162
157/***************************************************************************\ 163/***************************************************************************\
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp
index 6f716b1ca..f70c84c3d 100644
--- a/src/core/core_timing.cpp
+++ b/src/core/core_timing.cpp
@@ -160,6 +160,16 @@ void Init() {
160 last_global_time_us = 0; 160 last_global_time_us = 0;
161 has_ts_events = 0; 161 has_ts_events = 0;
162 mhz_change_callbacks.clear(); 162 mhz_change_callbacks.clear();
163
164 first = nullptr;
165 ts_first = nullptr;
166 ts_last = nullptr;
167
168 event_pool = nullptr;
169 event_ts_pool = nullptr;
170 allocated_ts_events = 0;
171
172 advance_callback = nullptr;
163} 173}
164 174
165void Shutdown() { 175void Shutdown() {
diff --git a/src/core/hle/config_mem.cpp b/src/core/hle/config_mem.cpp
index 30d73adac..9fcfcc285 100644
--- a/src/core/hle/config_mem.cpp
+++ b/src/core/hle/config_mem.cpp
@@ -61,6 +61,8 @@ template void Read<u16>(u16 &var, const u32 addr);
61template void Read<u8>(u8 &var, const u32 addr); 61template void Read<u8>(u8 &var, const u32 addr);
62 62
63void Init() { 63void Init() {
64 memset(&config_mem, 0, sizeof(config_mem));
65
64 config_mem.update_flag = 0; // No update 66 config_mem.update_flag = 0; // No update
65 config_mem.sys_core_ver = 0x2; 67 config_mem.sys_core_ver = 0x2;
66 config_mem.unit_info = 0x1; // Bit 0 set for Retail 68 config_mem.unit_info = 0x1; // Bit 0 set for Retail
@@ -76,4 +78,7 @@ void Init() {
76 config_mem.firm_sys_core_ver = 0x2; 78 config_mem.firm_sys_core_ver = 0x2;
77} 79}
78 80
81void Shutdown() {
82}
83
79} // namespace 84} // namespace
diff --git a/src/core/hle/config_mem.h b/src/core/hle/config_mem.h
index 94853901a..cbb478fb3 100644
--- a/src/core/hle/config_mem.h
+++ b/src/core/hle/config_mem.h
@@ -20,4 +20,6 @@ void Read(T &var, const u32 addr);
20 20
21void Init(); 21void Init();
22 22
23void Shutdown();
24
23} // namespace 25} // namespace
diff --git a/src/core/hle/hle.cpp b/src/core/hle/hle.cpp
index c645d6563..191d0411e 100644
--- a/src/core/hle/hle.cpp
+++ b/src/core/hle/hle.cpp
@@ -23,7 +23,7 @@ Common::Profiling::TimingCategory profiler_svc("SVC Calls");
23 23
24static std::vector<ModuleDef> g_module_db; 24static std::vector<ModuleDef> g_module_db;
25 25
26bool g_reschedule = false; ///< If true, immediately reschedules the CPU to a new thread 26bool g_reschedule; ///< If true, immediately reschedules the CPU to a new thread
27 27
28static const FunctionDef* GetSVCInfo(u32 opcode) { 28static const FunctionDef* GetSVCInfo(u32 opcode) {
29 u32 func_num = opcode & 0xFFFFFF; // 8 bits 29 u32 func_num = opcode & 0xFFFFFF; // 8 bits
@@ -73,17 +73,20 @@ static void RegisterAllModules() {
73} 73}
74 74
75void Init() { 75void Init() {
76 Service::Init();
77
78 RegisterAllModules(); 76 RegisterAllModules();
79 77
78 Service::Init();
80 ConfigMem::Init(); 79 ConfigMem::Init();
81 SharedPage::Init(); 80 SharedPage::Init();
82 81
82 g_reschedule = false;
83
83 LOG_DEBUG(Kernel, "initialized OK"); 84 LOG_DEBUG(Kernel, "initialized OK");
84} 85}
85 86
86void Shutdown() { 87void Shutdown() {
88 ConfigMem::Shutdown();
89 SharedPage::Shutdown();
87 Service::Shutdown(); 90 Service::Shutdown();
88 91
89 g_module_db.clear(); 92 g_module_db.clear();
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 6261b82b6..fca582bbe 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -14,11 +14,10 @@
14 14
15namespace Kernel { 15namespace Kernel {
16 16
17unsigned int Object::next_object_id = 0; 17unsigned int Object::next_object_id;
18 18SharedPtr<Thread> g_main_thread;
19SharedPtr<Thread> g_main_thread = nullptr;
20HandleTable g_handle_table; 19HandleTable g_handle_table;
21u64 g_program_id = 0; 20u64 g_program_id;
22 21
23void WaitObject::AddWaitingThread(SharedPtr<Thread> thread) { 22void WaitObject::AddWaitingThread(SharedPtr<Thread> thread) {
24 auto itr = std::find(waiting_threads.begin(), waiting_threads.end(), thread); 23 auto itr = std::find(waiting_threads.begin(), waiting_threads.end(), thread);
@@ -138,6 +137,10 @@ void HandleTable::Clear() {
138void Init() { 137void Init() {
139 Kernel::ThreadingInit(); 138 Kernel::ThreadingInit();
140 Kernel::TimersInit(); 139 Kernel::TimersInit();
140
141 Object::next_object_id = 0;
142 g_program_id = 0;
143 g_main_thread = nullptr;
141} 144}
142 145
143/// Shutdown the kernel 146/// Shutdown the kernel
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index 2d295ea00..ab06fa025 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -95,12 +95,13 @@ public:
95 return false; 95 return false;
96 } 96 }
97 97
98public:
99 static unsigned int next_object_id;
100
98private: 101private:
99 friend void intrusive_ptr_add_ref(Object*); 102 friend void intrusive_ptr_add_ref(Object*);
100 friend void intrusive_ptr_release(Object*); 103 friend void intrusive_ptr_release(Object*);
101 104
102 static unsigned int next_object_id;
103
104 unsigned int ref_count = 0; 105 unsigned int ref_count = 0;
105 unsigned int object_id = next_object_id++; 106 unsigned int object_id = next_object_id++;
106}; 107};
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index 33d66b986..d678f5f6f 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -23,7 +23,7 @@
23namespace Kernel { 23namespace Kernel {
24 24
25/// Event type for the thread wake up event 25/// Event type for the thread wake up event
26static int ThreadWakeupEventType = -1; 26static int ThreadWakeupEventType;
27 27
28bool Thread::ShouldWait() { 28bool Thread::ShouldWait() {
29 return status != THREADSTATUS_DEAD; 29 return status != THREADSTATUS_DEAD;
@@ -42,7 +42,7 @@ static Common::ThreadQueueList<Thread*, THREADPRIO_LOWEST+1> ready_queue;
42static Thread* current_thread; 42static Thread* current_thread;
43 43
44// The first available thread id at startup 44// The first available thread id at startup
45static u32 next_thread_id = 1; 45static u32 next_thread_id;
46 46
47/** 47/**
48 * Creates a new thread ID 48 * Creates a new thread ID
@@ -497,6 +497,12 @@ void Thread::SetWaitSynchronizationOutput(s32 output) {
497void ThreadingInit() { 497void ThreadingInit() {
498 ThreadWakeupEventType = CoreTiming::RegisterEvent("ThreadWakeupCallback", ThreadWakeupCallback); 498 ThreadWakeupEventType = CoreTiming::RegisterEvent("ThreadWakeupCallback", ThreadWakeupCallback);
499 499
500 current_thread = nullptr;
501 next_thread_id = 1;
502
503 thread_list.clear();
504 ready_queue.clear();
505
500 // Setup the idle thread 506 // Setup the idle thread
501 SetupIdleThread(); 507 SetupIdleThread();
502} 508}
diff --git a/src/core/hle/kernel/timer.cpp b/src/core/hle/kernel/timer.cpp
index 1ec2a4b10..36979248d 100644
--- a/src/core/hle/kernel/timer.cpp
+++ b/src/core/hle/kernel/timer.cpp
@@ -12,7 +12,7 @@
12namespace Kernel { 12namespace Kernel {
13 13
14/// The event type of the generic timer callback event 14/// The event type of the generic timer callback event
15static int timer_callback_event_type = -1; 15static int timer_callback_event_type;
16// TODO(yuriks): This can be removed if Timer objects are explicitly pooled in the future, allowing 16// TODO(yuriks): This can be removed if Timer objects are explicitly pooled in the future, allowing
17// us to simply use a pool index or similar. 17// us to simply use a pool index or similar.
18static Kernel::HandleTable timer_callback_handle_table; 18static Kernel::HandleTable timer_callback_handle_table;
@@ -89,6 +89,7 @@ static void TimerCallback(u64 timer_handle, int cycles_late) {
89} 89}
90 90
91void TimersInit() { 91void TimersInit() {
92 timer_callback_handle_table.Clear();
92 timer_callback_event_type = CoreTiming::RegisterEvent("TimerCallback", TimerCallback); 93 timer_callback_event_type = CoreTiming::RegisterEvent("TimerCallback", TimerCallback);
93} 94}
94 95
diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp
index 190c5df7a..98ae80b3a 100644
--- a/src/core/hle/service/apt/apt.cpp
+++ b/src/core/hle/service/apt/apt.cpp
@@ -28,15 +28,15 @@ namespace APT {
28static const VAddr SHARED_FONT_VADDR = 0x18000000; 28static const VAddr SHARED_FONT_VADDR = 0x18000000;
29 29
30/// Handle to shared memory region designated to for shared system font 30/// Handle to shared memory region designated to for shared system font
31static Kernel::SharedPtr<Kernel::SharedMemory> shared_font_mem = nullptr; 31static Kernel::SharedPtr<Kernel::SharedMemory> shared_font_mem;
32 32
33static Kernel::SharedPtr<Kernel::Mutex> lock = nullptr; 33static Kernel::SharedPtr<Kernel::Mutex> lock;
34static Kernel::SharedPtr<Kernel::Event> notification_event = nullptr; ///< APT notification event 34static Kernel::SharedPtr<Kernel::Event> notification_event; ///< APT notification event
35static Kernel::SharedPtr<Kernel::Event> start_event = nullptr; ///< APT start event 35static Kernel::SharedPtr<Kernel::Event> start_event; ///< APT start event
36 36
37static std::vector<u8> shared_font; 37static std::vector<u8> shared_font;
38 38
39static u32 cpu_percent = 0; ///< CPU time available to the running application 39static u32 cpu_percent; ///< CPU time available to the running application
40 40
41void Initialize(Service::Interface* self) { 41void Initialize(Service::Interface* self) {
42 u32* cmd_buff = Kernel::GetCommandBuffer(); 42 u32* cmd_buff = Kernel::GetCommandBuffer();
@@ -309,6 +309,7 @@ void Init() {
309 } 309 }
310 310
311 lock = Kernel::Mutex::Create(false, "APT_U:Lock"); 311 lock = Kernel::Mutex::Create(false, "APT_U:Lock");
312
312 cpu_percent = 0; 313 cpu_percent = 0;
313 314
314 // TODO(bunnei): Check if these are created in Initialize or on APT process startup. 315 // TODO(bunnei): Check if these are created in Initialize or on APT process startup.
@@ -317,7 +318,11 @@ void Init() {
317} 318}
318 319
319void Shutdown() { 320void Shutdown() {
320 321 shared_font.clear();
322 shared_font_mem = nullptr;
323 lock = nullptr;
324 notification_event = nullptr;
325 start_event = nullptr;
321} 326}
322 327
323} // namespace APT 328} // namespace APT
diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp
index 6af0352ac..5eccdecf7 100644
--- a/src/core/hle/service/cfg/cfg.cpp
+++ b/src/core/hle/service/cfg/cfg.cpp
@@ -207,6 +207,7 @@ void Init() {
207 207
208 // Initialize the Username block 208 // Initialize the Username block
209 // TODO(Subv): Initialize this directly in the variable when MSVC supports char16_t string literals 209 // TODO(Subv): Initialize this directly in the variable when MSVC supports char16_t string literals
210 memset(&CONSOLE_USERNAME_BLOCK, 0, sizeof(CONSOLE_USERNAME_BLOCK));
210 CONSOLE_USERNAME_BLOCK.ng_word = 0; 211 CONSOLE_USERNAME_BLOCK.ng_word = 0;
211 CONSOLE_USERNAME_BLOCK.zero = 0; 212 CONSOLE_USERNAME_BLOCK.zero = 0;
212 213
@@ -219,7 +220,6 @@ void Init() {
219} 220}
220 221
221void Shutdown() { 222void Shutdown() {
222
223} 223}
224 224
225} // namespace CFG 225} // namespace CFG
diff --git a/src/core/hle/service/dsp_dsp.cpp b/src/core/hle/service/dsp_dsp.cpp
index 4d6c70f4d..2e759a3e3 100644
--- a/src/core/hle/service/dsp_dsp.cpp
+++ b/src/core/hle/service/dsp_dsp.cpp
@@ -11,7 +11,7 @@
11 11
12namespace DSP_DSP { 12namespace DSP_DSP {
13 13
14static u32 read_pipe_count = 0; 14static u32 read_pipe_count;
15static Kernel::SharedPtr<Kernel::Event> semaphore_event; 15static Kernel::SharedPtr<Kernel::Event> semaphore_event;
16static Kernel::SharedPtr<Kernel::Event> interrupt_event; 16static Kernel::SharedPtr<Kernel::Event> interrupt_event;
17 17
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index 9ca5d13d4..0f30f743a 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -20,17 +20,17 @@ namespace HID {
20static const int MAX_CIRCLEPAD_POS = 0x9C; ///< Max value for a circle pad position 20static const int MAX_CIRCLEPAD_POS = 0x9C; ///< Max value for a circle pad position
21 21
22// Handle to shared memory region designated to HID_User service 22// Handle to shared memory region designated to HID_User service
23static Kernel::SharedPtr<Kernel::SharedMemory> shared_mem = nullptr; 23static Kernel::SharedPtr<Kernel::SharedMemory> shared_mem;
24 24
25// Event handles 25// Event handles
26static Kernel::SharedPtr<Kernel::Event> event_pad_or_touch_1 = nullptr; 26static Kernel::SharedPtr<Kernel::Event> event_pad_or_touch_1;
27static Kernel::SharedPtr<Kernel::Event> event_pad_or_touch_2 = nullptr; 27static Kernel::SharedPtr<Kernel::Event> event_pad_or_touch_2;
28static Kernel::SharedPtr<Kernel::Event> event_accelerometer = nullptr; 28static Kernel::SharedPtr<Kernel::Event> event_accelerometer;
29static Kernel::SharedPtr<Kernel::Event> event_gyroscope = nullptr; 29static Kernel::SharedPtr<Kernel::Event> event_gyroscope;
30static Kernel::SharedPtr<Kernel::Event> event_debug_pad = nullptr; 30static Kernel::SharedPtr<Kernel::Event> event_debug_pad;
31 31
32static u32 next_pad_index = 0; 32static u32 next_pad_index;
33static u32 next_touch_index = 0; 33static u32 next_touch_index;
34 34
35// TODO(peachum): 35// TODO(peachum):
36// Add a method for setting analog input from joystick device for the circle Pad. 36// Add a method for setting analog input from joystick device for the circle Pad.
@@ -175,6 +175,12 @@ void Init() {
175} 175}
176 176
177void Shutdown() { 177void Shutdown() {
178 shared_mem = nullptr;
179 event_pad_or_touch_1 = nullptr;
180 event_pad_or_touch_2 = nullptr;
181 event_accelerometer = nullptr;
182 event_gyroscope = nullptr;
183 event_debug_pad = nullptr;
178} 184}
179 185
180} // namespace HID 186} // namespace HID
diff --git a/src/core/hle/service/ir/ir.cpp b/src/core/hle/service/ir/ir.cpp
index 58dfd8e1a..15ac477ef 100644
--- a/src/core/hle/service/ir/ir.cpp
+++ b/src/core/hle/service/ir/ir.cpp
@@ -15,8 +15,8 @@
15namespace Service { 15namespace Service {
16namespace IR { 16namespace IR {
17 17
18static Kernel::SharedPtr<Kernel::Event> handle_event = nullptr; 18static Kernel::SharedPtr<Kernel::Event> handle_event;
19static Kernel::SharedPtr<Kernel::SharedMemory> shared_memory = nullptr; 19static Kernel::SharedPtr<Kernel::SharedMemory> shared_memory;
20 20
21void GetHandles(Service::Interface* self) { 21void GetHandles(Service::Interface* self) {
22 u32* cmd_buff = Kernel::GetCommandBuffer(); 22 u32* cmd_buff = Kernel::GetCommandBuffer();
@@ -41,6 +41,8 @@ void Init() {
41} 41}
42 42
43void Shutdown() { 43void Shutdown() {
44 shared_memory = nullptr;
45 handle_event = nullptr;
44} 46}
45 47
46} // namespace IR 48} // namespace IR
diff --git a/src/core/hle/service/nwm_uds.cpp b/src/core/hle/service/nwm_uds.cpp
index 1cee81ab2..4b06efc3a 100644
--- a/src/core/hle/service/nwm_uds.cpp
+++ b/src/core/hle/service/nwm_uds.cpp
@@ -11,7 +11,7 @@
11 11
12namespace NWM_UDS { 12namespace NWM_UDS {
13 13
14static Kernel::SharedPtr<Kernel::Event> handle_event = nullptr; 14static Kernel::SharedPtr<Kernel::Event> handle_event;
15 15
16/** 16/**
17 * NWM_UDS::Shutdown service function 17 * NWM_UDS::Shutdown service function
diff --git a/src/core/hle/service/ptm/ptm.cpp b/src/core/hle/service/ptm/ptm.cpp
index 57a301bec..d44510c1b 100644
--- a/src/core/hle/service/ptm/ptm.cpp
+++ b/src/core/hle/service/ptm/ptm.cpp
@@ -18,9 +18,9 @@ static const GameCoin default_game_coin = { 0x4F00, 42, 0, 0, 0, 2014, 12, 29 };
18/// Id of the SharedExtData archive used by the PTM process 18/// Id of the SharedExtData archive used by the PTM process
19static const std::vector<u8> ptm_shared_extdata_id = {0, 0, 0, 0, 0x0B, 0, 0, 0xF0, 0, 0, 0, 0}; 19static const std::vector<u8> ptm_shared_extdata_id = {0, 0, 0, 0, 0x0B, 0, 0, 0xF0, 0, 0, 0, 0};
20 20
21static bool shell_open = true; 21static bool shell_open;
22 22
23static bool battery_is_charging = true; 23static bool battery_is_charging;
24 24
25u32 GetAdapterState() { 25u32 GetAdapterState() {
26 // TODO(purpasmart96): This function is only a stub, 26 // TODO(purpasmart96): This function is only a stub,
@@ -43,6 +43,9 @@ void Init() {
43 AddService(new PTM_Sysm_Interface); 43 AddService(new PTM_Sysm_Interface);
44 AddService(new PTM_U_Interface); 44 AddService(new PTM_U_Interface);
45 45
46 shell_open = true;
47 battery_is_charging = true;
48
46 // Open the SharedExtSaveData archive 0xF000000B and create the gamecoin.dat file if it doesn't exist 49 // Open the SharedExtSaveData archive 0xF000000B and create the gamecoin.dat file if it doesn't exist
47 FileSys::Path archive_path(ptm_shared_extdata_id); 50 FileSys::Path archive_path(ptm_shared_extdata_id);
48 auto archive_result = Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SharedExtSaveData, archive_path); 51 auto archive_result = Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SharedExtSaveData, archive_path);
diff --git a/src/core/hle/service/y2r_u.cpp b/src/core/hle/service/y2r_u.cpp
index 6607965e1..33ecf64a2 100644
--- a/src/core/hle/service/y2r_u.cpp
+++ b/src/core/hle/service/y2r_u.cpp
@@ -11,7 +11,7 @@
11 11
12namespace Y2R_U { 12namespace Y2R_U {
13 13
14static Kernel::SharedPtr<Kernel::Event> completion_event = 0; 14static Kernel::SharedPtr<Kernel::Event> completion_event;
15 15
16/** 16/**
17 * Y2R_U::IsBusyConversion service function 17 * Y2R_U::IsBusyConversion service function
diff --git a/src/core/hle/shared_page.cpp b/src/core/hle/shared_page.cpp
index 568dad684..94fae2551 100644
--- a/src/core/hle/shared_page.cpp
+++ b/src/core/hle/shared_page.cpp
@@ -62,6 +62,8 @@ template void Read<u16>(u16 &var, const u32 addr);
62template void Read<u8>(u8 &var, const u32 addr); 62template void Read<u8>(u8 &var, const u32 addr);
63 63
64void Set3DSlider(float amount) { 64void Set3DSlider(float amount) {
65 memset(&shared_page, 0, sizeof(shared_page));
66
65 shared_page.sliderstate_3d = amount; 67 shared_page.sliderstate_3d = amount;
66 shared_page.ledstate_3d = (amount == 0.0f); // off when non-zero 68 shared_page.ledstate_3d = (amount == 0.0f); // off when non-zero
67} 69}
@@ -71,4 +73,7 @@ void Init() {
71 Set3DSlider(0.0f); 73 Set3DSlider(0.0f);
72} 74}
73 75
76void Shutdown() {
77}
78
74} // namespace 79} // namespace
diff --git a/src/core/hle/shared_page.h b/src/core/hle/shared_page.h
index 8f93545ec..1b6e4e581 100644
--- a/src/core/hle/shared_page.h
+++ b/src/core/hle/shared_page.h
@@ -23,4 +23,6 @@ void Set3DSlider(float amount);
23 23
24void Init(); 24void Init();
25 25
26void Shutdown();
27
26} // namespace 28} // namespace
diff --git a/src/core/hw/gpu.cpp b/src/core/hw/gpu.cpp
index 308ea2035..0ad7e2963 100644
--- a/src/core/hw/gpu.cpp
+++ b/src/core/hw/gpu.cpp
@@ -29,8 +29,7 @@ namespace GPU {
29Regs g_regs; 29Regs g_regs;
30 30
31/// True if the current frame was skipped 31/// True if the current frame was skipped
32bool g_skip_frame = false; 32bool g_skip_frame;
33
34/// 268MHz / gpu_refresh_rate frames per second 33/// 268MHz / gpu_refresh_rate frames per second
35static u64 frame_ticks; 34static u64 frame_ticks;
36/// Event id for CoreTiming 35/// Event id for CoreTiming
@@ -38,7 +37,7 @@ static int vblank_event;
38/// Total number of frames drawn 37/// Total number of frames drawn
39static u64 frame_count; 38static u64 frame_count;
40/// True if the last frame was skipped 39/// True if the last frame was skipped
41static bool last_skip_frame = false; 40static bool last_skip_frame;
42 41
43template <typename T> 42template <typename T>
44inline void Read(T &var, const u32 raw_addr) { 43inline void Read(T &var, const u32 raw_addr) {
@@ -320,6 +319,8 @@ static void VBlankCallback(u64 userdata, int cycles_late) {
320 319
321/// Initialize hardware 320/// Initialize hardware
322void Init() { 321void Init() {
322 memset(&g_regs, 0, sizeof(g_regs));
323
323 auto& framebuffer_top = g_regs.framebuffer_config[0]; 324 auto& framebuffer_top = g_regs.framebuffer_config[0];
324 auto& framebuffer_sub = g_regs.framebuffer_config[1]; 325 auto& framebuffer_sub = g_regs.framebuffer_config[1];
325 326
@@ -349,6 +350,7 @@ void Init() {
349 frame_ticks = 268123480 / Settings::values.gpu_refresh_rate; 350 frame_ticks = 268123480 / Settings::values.gpu_refresh_rate;
350 last_skip_frame = false; 351 last_skip_frame = false;
351 g_skip_frame = false; 352 g_skip_frame = false;
353 frame_count = 0;
352 354
353 vblank_event = CoreTiming::RegisterEvent("GPU::VBlankCallback", VBlankCallback); 355 vblank_event = CoreTiming::RegisterEvent("GPU::VBlankCallback", VBlankCallback);
354 CoreTiming::ScheduleEvent(frame_ticks, vblank_event); 356 CoreTiming::ScheduleEvent(frame_ticks, vblank_event);
diff --git a/src/core/hw/hw.cpp b/src/core/hw/hw.cpp
index bed50af50..236958139 100644
--- a/src/core/hw/hw.cpp
+++ b/src/core/hw/hw.cpp
@@ -63,6 +63,8 @@ void Init() {
63 63
64/// Shutdown hardware 64/// Shutdown hardware
65void Shutdown() { 65void Shutdown() {
66 GPU::Shutdown();
67 LCD::Shutdown();
66 LOG_DEBUG(HW, "shutdown OK"); 68 LOG_DEBUG(HW, "shutdown OK");
67} 69}
68 70
diff --git a/src/core/hw/lcd.cpp b/src/core/hw/lcd.cpp
index 7986f3ddb..8a09c3bc0 100644
--- a/src/core/hw/lcd.cpp
+++ b/src/core/hw/lcd.cpp
@@ -55,6 +55,7 @@ template void Write<u8>(u32 addr, const u8 data);
55 55
56/// Initialize hardware 56/// Initialize hardware
57void Init() { 57void Init() {
58 memset(&g_regs, 0, sizeof(g_regs));
58 LOG_DEBUG(HW_LCD, "initialized OK"); 59 LOG_DEBUG(HW_LCD, "initialized OK");
59} 60}
60 61
diff --git a/src/core/mem_map.cpp b/src/core/mem_map.cpp
index a14e8303e..22e359b3e 100644
--- a/src/core/mem_map.cpp
+++ b/src/core/mem_map.cpp
@@ -11,30 +11,30 @@
11 11
12namespace Memory { 12namespace Memory {
13 13
14u8* g_base = nullptr; ///< The base pointer to the auto-mirrored arena. 14u8* g_base; ///< The base pointer to the auto-mirrored arena.
15 15
16static MemArena arena; ///< The MemArena class 16static MemArena arena; ///< The MemArena class
17 17
18u8* g_exefs_code = nullptr; ///< ExeFS:/.code is loaded here 18u8* g_exefs_code; ///< ExeFS:/.code is loaded here
19u8* g_system_mem = nullptr; ///< System memory 19u8* g_system_mem; ///< System memory
20u8* g_heap = nullptr; ///< Application heap (main memory) 20u8* g_heap; ///< Application heap (main memory)
21u8* g_heap_linear = nullptr; ///< Linear heap 21u8* g_heap_linear; ///< Linear heap
22u8* g_vram = nullptr; ///< Video memory (VRAM) pointer 22u8* g_vram; ///< Video memory (VRAM) pointer
23u8* g_shared_mem = nullptr; ///< Shared memory 23u8* g_shared_mem; ///< Shared memory
24u8* g_dsp_mem = nullptr; ///< DSP memory 24u8* g_dsp_mem; ///< DSP memory
25u8* g_kernel_mem; ///< Kernel memory 25u8* g_kernel_mem; ///< Kernel memory
26 26
27static u8* physical_bootrom = nullptr; ///< Bootrom physical memory 27static u8* physical_bootrom; ///< Bootrom physical memory
28static u8* uncached_bootrom = nullptr; 28static u8* uncached_bootrom;
29 29
30static u8* physical_exefs_code = nullptr; ///< Phsical ExeFS:/.code is loaded here 30static u8* physical_exefs_code; ///< Phsical ExeFS:/.code is loaded here
31static u8* physical_system_mem = nullptr; ///< System physical memory 31static u8* physical_system_mem; ///< System physical memory
32static u8* physical_fcram = nullptr; ///< Main physical memory (FCRAM) 32static u8* physical_fcram; ///< Main physical memory (FCRAM)
33static u8* physical_heap_gsp = nullptr; ///< GSP heap physical memory 33static u8* physical_heap_gsp; ///< GSP heap physical memory
34static u8* physical_vram = nullptr; ///< Video physical memory (VRAM) 34static u8* physical_vram; ///< Video physical memory (VRAM)
35static u8* physical_shared_mem = nullptr; ///< Physical shared memory 35static u8* physical_shared_mem; ///< Physical shared memory
36static u8* physical_dsp_mem = nullptr; ///< Physical DSP memory 36static u8* physical_dsp_mem; ///< Physical DSP memory
37static u8* physical_kernel_mem; ///< Kernel memory 37static u8* physical_kernel_mem; ///< Kernel memory
38 38
39// We don't declare the IO region in here since its handled by other means. 39// We don't declare the IO region in here since its handled by other means.
40static MemoryView g_views[] = { 40static MemoryView g_views[] = {
@@ -73,6 +73,7 @@ void Init() {
73 } 73 }
74 74
75 g_base = MemoryMap_Setup(g_views, kNumMemViews, flags, &arena); 75 g_base = MemoryMap_Setup(g_views, kNumMemViews, flags, &arena);
76 MemBlock_Init();
76 77
77 LOG_DEBUG(HW_Memory, "initialized OK, RAM at %p (mirror at 0 @ %p)", g_heap, 78 LOG_DEBUG(HW_Memory, "initialized OK, RAM at %p (mirror at 0 @ %p)", g_heap,
78 physical_fcram); 79 physical_fcram);
@@ -81,9 +82,29 @@ void Init() {
81void Shutdown() { 82void Shutdown() {
82 u32 flags = 0; 83 u32 flags = 0;
83 MemoryMap_Shutdown(g_views, kNumMemViews, flags, &arena); 84 MemoryMap_Shutdown(g_views, kNumMemViews, flags, &arena);
84
85 arena.ReleaseSpace(); 85 arena.ReleaseSpace();
86 MemBlock_Shutdown();
87
86 g_base = nullptr; 88 g_base = nullptr;
89 g_exefs_code = nullptr;
90 g_system_mem = nullptr;
91 g_heap = nullptr;
92 g_heap_linear = nullptr;
93 g_vram = nullptr;
94 g_shared_mem = nullptr;
95 g_dsp_mem = nullptr;
96 g_kernel_mem = nullptr;
97
98 physical_bootrom = nullptr;
99 uncached_bootrom = nullptr;
100 physical_exefs_code = nullptr;
101 physical_system_mem = nullptr;
102 physical_fcram = nullptr;
103 physical_heap_gsp = nullptr;
104 physical_vram = nullptr;
105 physical_shared_mem = nullptr;
106 physical_dsp_mem = nullptr;
107 physical_kernel_mem = nullptr;
87 108
88 LOG_DEBUG(HW_Memory, "shutdown OK"); 109 LOG_DEBUG(HW_Memory, "shutdown OK");
89} 110}
diff --git a/src/core/mem_map.h b/src/core/mem_map.h
index ff730593e..1af02973b 100644
--- a/src/core/mem_map.h
+++ b/src/core/mem_map.h
@@ -171,6 +171,12 @@ u32 MapBlock_Heap(u32 size, u32 operation, u32 permissions);
171 */ 171 */
172u32 MapBlock_HeapLinear(u32 size, u32 operation, u32 permissions); 172u32 MapBlock_HeapLinear(u32 size, u32 operation, u32 permissions);
173 173
174/// Initialize mapped memory blocks
175void MemBlock_Init();
176
177/// Shutdown mapped memory blocks
178void MemBlock_Shutdown();
179
174inline const char* GetCharPointer(const VAddr address) { 180inline const char* GetCharPointer(const VAddr address) {
175 return (const char *)GetPointer(address); 181 return (const char *)GetPointer(address);
176} 182}
diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp
index 5878b99dc..8759ebdfb 100644
--- a/src/core/mem_map_funcs.cpp
+++ b/src/core/mem_map_funcs.cpp
@@ -15,7 +15,6 @@ namespace Memory {
15 15
16static std::map<u32, MemoryBlock> heap_map; 16static std::map<u32, MemoryBlock> heap_map;
17static std::map<u32, MemoryBlock> heap_linear_map; 17static std::map<u32, MemoryBlock> heap_linear_map;
18static std::map<u32, MemoryBlock> shared_map;
19 18
20/// Convert a physical address to virtual address 19/// Convert a physical address to virtual address
21VAddr PhysicalToVirtualAddress(const PAddr addr) { 20VAddr PhysicalToVirtualAddress(const PAddr addr) {
@@ -185,12 +184,6 @@ u8 *GetPointer(const VAddr vaddr) {
185 } 184 }
186} 185}
187 186
188/**
189 * Maps a block of memory on the heap
190 * @param size Size of block in bytes
191 * @param operation Memory map operation type
192 * @param flags Memory allocation flags
193 */
194u32 MapBlock_Heap(u32 size, u32 operation, u32 permissions) { 187u32 MapBlock_Heap(u32 size, u32 operation, u32 permissions) {
195 MemoryBlock block; 188 MemoryBlock block;
196 189
@@ -208,12 +201,6 @@ u32 MapBlock_Heap(u32 size, u32 operation, u32 permissions) {
208 return block.GetVirtualAddress(); 201 return block.GetVirtualAddress();
209} 202}
210 203
211/**
212 * Maps a block of memory on the linear heap
213 * @param size Size of block in bytes
214 * @param operation Memory map operation type
215 * @param flags Memory allocation flags
216 */
217u32 MapBlock_HeapLinear(u32 size, u32 operation, u32 permissions) { 204u32 MapBlock_HeapLinear(u32 size, u32 operation, u32 permissions) {
218 MemoryBlock block; 205 MemoryBlock block;
219 206
@@ -231,6 +218,14 @@ u32 MapBlock_HeapLinear(u32 size, u32 operation, u32 permissions) {
231 return block.GetVirtualAddress(); 218 return block.GetVirtualAddress();
232} 219}
233 220
221void MemBlock_Init() {
222}
223
224void MemBlock_Shutdown() {
225 heap_map.clear();
226 heap_linear_map.clear();
227}
228
234u8 Read8(const VAddr addr) { 229u8 Read8(const VAddr addr) {
235 u8 data = 0; 230 u8 data = 0;
236 Read<u8>(data, addr); 231 Read<u8>(data, addr);