summaryrefslogtreecommitdiff
path: root/src/core/hle
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle')
-rw-r--r--src/core/hle/function_wrappers.h76
-rw-r--r--src/core/hle/hle.cpp4
-rw-r--r--src/core/hle/hle.h23
-rw-r--r--src/core/hle/kernel/address_arbiter.cpp1
-rw-r--r--src/core/hle/kernel/kernel.h3
-rw-r--r--src/core/hle/kernel/thread.cpp17
-rw-r--r--src/core/hle/kernel/thread.h4
-rw-r--r--src/core/hle/service/fs/archive.cpp5
-rw-r--r--src/core/hle/service/fs/archive.h4
-rw-r--r--src/core/hle/service/ir/ir.cpp3
-rw-r--r--src/core/hle/service/ldr_ro/ldr_ro.cpp8
-rw-r--r--src/core/hle/service/mic_u.cpp3
-rw-r--r--src/core/hle/svc.cpp92
13 files changed, 108 insertions, 135 deletions
diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h
index 8ce0f6d2b..7875971ce 100644
--- a/src/core/hle/function_wrappers.h
+++ b/src/core/hle/function_wrappers.h
@@ -7,14 +7,14 @@
7#include "common/common_types.h" 7#include "common/common_types.h"
8#include "core/arm/arm_interface.h" 8#include "core/arm/arm_interface.h"
9#include "core/core.h" 9#include "core/core.h"
10#include "core/hle/hle.h" 10#include "core/hle/kernel/kernel.h"
11#include "core/hle/result.h" 11#include "core/hle/result.h"
12#include "core/hle/svc.h" 12#include "core/hle/svc.h"
13#include "core/memory.h" 13#include "core/memory.h"
14 14
15namespace HLE { 15namespace HLE {
16 16
17#define PARAM(n) Core::g_app_core->GetReg(n) 17#define PARAM(n) Core::CPU().GetReg(n)
18 18
19/// An invalid result code that is meant to be overwritten when a thread resumes from waiting 19/// An invalid result code that is meant to be overwritten when a thread resumes from waiting
20static const ResultCode RESULT_INVALID(0xDEADC0DE); 20static const ResultCode RESULT_INVALID(0xDEADC0DE);
@@ -24,7 +24,7 @@ static const ResultCode RESULT_INVALID(0xDEADC0DE);
24 * @param res Result to return 24 * @param res Result to return
25 */ 25 */
26static inline void FuncReturn(u32 res) { 26static inline void FuncReturn(u32 res) {
27 Core::g_app_core->SetReg(0, res); 27 Core::CPU().SetReg(0, res);
28} 28}
29 29
30/** 30/**
@@ -33,8 +33,8 @@ static inline void FuncReturn(u32 res) {
33 * @todo Verify that this function is correct 33 * @todo Verify that this function is correct
34 */ 34 */
35static inline void FuncReturn64(u64 res) { 35static inline void FuncReturn64(u64 res) {
36 Core::g_app_core->SetReg(0, (u32)(res & 0xFFFFFFFF)); 36 Core::CPU().SetReg(0, (u32)(res & 0xFFFFFFFF));
37 Core::g_app_core->SetReg(1, (u32)((res >> 32) & 0xFFFFFFFF)); 37 Core::CPU().SetReg(1, (u32)((res >> 32) & 0xFFFFFFFF));
38} 38}
39 39
40//////////////////////////////////////////////////////////////////////////////////////////////////// 40////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -49,7 +49,7 @@ template <ResultCode func(u32*, u32, u32, u32, u32, u32)>
49void Wrap() { 49void Wrap() {
50 u32 param_1 = 0; 50 u32 param_1 = 0;
51 u32 retval = func(&param_1, PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)).raw; 51 u32 retval = func(&param_1, PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)).raw;
52 Core::g_app_core->SetReg(1, param_1); 52 Core::CPU().SetReg(1, param_1);
53 FuncReturn(retval); 53 FuncReturn(retval);
54} 54}
55 55
@@ -57,19 +57,19 @@ template <ResultCode func(u32*, s32, u32, u32, u32, s32)>
57void Wrap() { 57void Wrap() {
58 u32 param_1 = 0; 58 u32 param_1 = 0;
59 u32 retval = func(&param_1, PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)).raw; 59 u32 retval = func(&param_1, PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)).raw;
60 Core::g_app_core->SetReg(1, param_1); 60 Core::CPU().SetReg(1, param_1);
61 FuncReturn(retval); 61 FuncReturn(retval);
62} 62}
63 63
64template <ResultCode func(s32*, u32*, s32, bool, s64)> 64template <ResultCode func(s32*, u32*, s32, bool, s64)>
65void Wrap() { 65void Wrap() {
66 s32 param_1 = 0; 66 s32 param_1 = 0;
67 s32 retval = func(&param_1, (Handle*)Memory::GetPointer(PARAM(1)), (s32)PARAM(2), 67 s32 retval = func(&param_1, (Kernel::Handle*)Memory::GetPointer(PARAM(1)), (s32)PARAM(2),
68 (PARAM(3) != 0), (((s64)PARAM(4) << 32) | PARAM(0))) 68 (PARAM(3) != 0), (((s64)PARAM(4) << 32) | PARAM(0)))
69 .raw; 69 .raw;
70 70
71 if (retval != RESULT_INVALID.raw) { 71 if (retval != RESULT_INVALID.raw) {
72 Core::g_app_core->SetReg(1, (u32)param_1); 72 Core::CPU().SetReg(1, (u32)param_1);
73 FuncReturn(retval); 73 FuncReturn(retval);
74 } 74 }
75} 75}
@@ -84,7 +84,7 @@ template <ResultCode func(u32*)>
84void Wrap() { 84void Wrap() {
85 u32 param_1 = 0; 85 u32 param_1 = 0;
86 u32 retval = func(&param_1).raw; 86 u32 retval = func(&param_1).raw;
87 Core::g_app_core->SetReg(1, param_1); 87 Core::CPU().SetReg(1, param_1);
88 FuncReturn(retval); 88 FuncReturn(retval);
89} 89}
90 90
@@ -102,24 +102,24 @@ void Wrap() {
102 MemoryInfo memory_info = {}; 102 MemoryInfo memory_info = {};
103 PageInfo page_info = {}; 103 PageInfo page_info = {};
104 u32 retval = func(&memory_info, &page_info, PARAM(2)).raw; 104 u32 retval = func(&memory_info, &page_info, PARAM(2)).raw;
105 Core::g_app_core->SetReg(1, memory_info.base_address); 105 Core::CPU().SetReg(1, memory_info.base_address);
106 Core::g_app_core->SetReg(2, memory_info.size); 106 Core::CPU().SetReg(2, memory_info.size);
107 Core::g_app_core->SetReg(3, memory_info.permission); 107 Core::CPU().SetReg(3, memory_info.permission);
108 Core::g_app_core->SetReg(4, memory_info.state); 108 Core::CPU().SetReg(4, memory_info.state);
109 Core::g_app_core->SetReg(5, page_info.flags); 109 Core::CPU().SetReg(5, page_info.flags);
110 FuncReturn(retval); 110 FuncReturn(retval);
111} 111}
112 112
113template <ResultCode func(MemoryInfo*, PageInfo*, Handle, u32)> 113template <ResultCode func(MemoryInfo*, PageInfo*, Kernel::Handle, u32)>
114void Wrap() { 114void Wrap() {
115 MemoryInfo memory_info = {}; 115 MemoryInfo memory_info = {};
116 PageInfo page_info = {}; 116 PageInfo page_info = {};
117 u32 retval = func(&memory_info, &page_info, PARAM(2), PARAM(3)).raw; 117 u32 retval = func(&memory_info, &page_info, PARAM(2), PARAM(3)).raw;
118 Core::g_app_core->SetReg(1, memory_info.base_address); 118 Core::CPU().SetReg(1, memory_info.base_address);
119 Core::g_app_core->SetReg(2, memory_info.size); 119 Core::CPU().SetReg(2, memory_info.size);
120 Core::g_app_core->SetReg(3, memory_info.permission); 120 Core::CPU().SetReg(3, memory_info.permission);
121 Core::g_app_core->SetReg(4, memory_info.state); 121 Core::CPU().SetReg(4, memory_info.state);
122 Core::g_app_core->SetReg(5, page_info.flags); 122 Core::CPU().SetReg(5, page_info.flags);
123 FuncReturn(retval); 123 FuncReturn(retval);
124} 124}
125 125
@@ -127,7 +127,7 @@ template <ResultCode func(s32*, u32)>
127void Wrap() { 127void Wrap() {
128 s32 param_1 = 0; 128 s32 param_1 = 0;
129 u32 retval = func(&param_1, PARAM(1)).raw; 129 u32 retval = func(&param_1, PARAM(1)).raw;
130 Core::g_app_core->SetReg(1, param_1); 130 Core::CPU().SetReg(1, param_1);
131 FuncReturn(retval); 131 FuncReturn(retval);
132} 132}
133 133
@@ -140,7 +140,7 @@ template <ResultCode func(u32*, u32)>
140void Wrap() { 140void Wrap() {
141 u32 param_1 = 0; 141 u32 param_1 = 0;
142 u32 retval = func(&param_1, PARAM(1)).raw; 142 u32 retval = func(&param_1, PARAM(1)).raw;
143 Core::g_app_core->SetReg(1, param_1); 143 Core::CPU().SetReg(1, param_1);
144 FuncReturn(retval); 144 FuncReturn(retval);
145} 145}
146 146
@@ -160,7 +160,7 @@ template <ResultCode func(u32*, const char*)>
160void Wrap() { 160void Wrap() {
161 u32 param_1 = 0; 161 u32 param_1 = 0;
162 u32 retval = func(&param_1, (char*)Memory::GetPointer(PARAM(1))).raw; 162 u32 retval = func(&param_1, (char*)Memory::GetPointer(PARAM(1))).raw;
163 Core::g_app_core->SetReg(1, param_1); 163 Core::CPU().SetReg(1, param_1);
164 FuncReturn(retval); 164 FuncReturn(retval);
165} 165}
166 166
@@ -168,7 +168,7 @@ template <ResultCode func(u32*, s32, s32)>
168void Wrap() { 168void Wrap() {
169 u32 param_1 = 0; 169 u32 param_1 = 0;
170 u32 retval = func(&param_1, PARAM(1), PARAM(2)).raw; 170 u32 retval = func(&param_1, PARAM(1), PARAM(2)).raw;
171 Core::g_app_core->SetReg(1, param_1); 171 Core::CPU().SetReg(1, param_1);
172 FuncReturn(retval); 172 FuncReturn(retval);
173} 173}
174 174
@@ -176,7 +176,7 @@ template <ResultCode func(s32*, u32, s32)>
176void Wrap() { 176void Wrap() {
177 s32 param_1 = 0; 177 s32 param_1 = 0;
178 u32 retval = func(&param_1, PARAM(1), PARAM(2)).raw; 178 u32 retval = func(&param_1, PARAM(1), PARAM(2)).raw;
179 Core::g_app_core->SetReg(1, param_1); 179 Core::CPU().SetReg(1, param_1);
180 FuncReturn(retval); 180 FuncReturn(retval);
181} 181}
182 182
@@ -184,8 +184,8 @@ template <ResultCode func(s64*, u32, s32)>
184void Wrap() { 184void Wrap() {
185 s64 param_1 = 0; 185 s64 param_1 = 0;
186 u32 retval = func(&param_1, PARAM(1), PARAM(2)).raw; 186 u32 retval = func(&param_1, PARAM(1), PARAM(2)).raw;
187 Core::g_app_core->SetReg(1, (u32)param_1); 187 Core::CPU().SetReg(1, (u32)param_1);
188 Core::g_app_core->SetReg(2, (u32)(param_1 >> 32)); 188 Core::CPU().SetReg(2, (u32)(param_1 >> 32));
189 FuncReturn(retval); 189 FuncReturn(retval);
190} 190}
191 191
@@ -194,7 +194,7 @@ void Wrap() {
194 u32 param_1 = 0; 194 u32 param_1 = 0;
195 // The last parameter is passed in R0 instead of R4 195 // The last parameter is passed in R0 instead of R4
196 u32 retval = func(&param_1, PARAM(1), PARAM(2), PARAM(3), PARAM(0)).raw; 196 u32 retval = func(&param_1, PARAM(1), PARAM(2), PARAM(3), PARAM(0)).raw;
197 Core::g_app_core->SetReg(1, param_1); 197 Core::CPU().SetReg(1, param_1);
198 FuncReturn(retval); 198 FuncReturn(retval);
199} 199}
200 200
@@ -205,30 +205,30 @@ void Wrap() {
205 FuncReturn(func(PARAM(0), param1, param2).raw); 205 FuncReturn(func(PARAM(0), param1, param2).raw);
206} 206}
207 207
208template <ResultCode func(s64*, Handle, u32)> 208template <ResultCode func(s64*, Kernel::Handle, u32)>
209void Wrap() { 209void Wrap() {
210 s64 param_1 = 0; 210 s64 param_1 = 0;
211 u32 retval = func(&param_1, PARAM(1), PARAM(2)).raw; 211 u32 retval = func(&param_1, PARAM(1), PARAM(2)).raw;
212 Core::g_app_core->SetReg(1, (u32)param_1); 212 Core::CPU().SetReg(1, (u32)param_1);
213 Core::g_app_core->SetReg(2, (u32)(param_1 >> 32)); 213 Core::CPU().SetReg(2, (u32)(param_1 >> 32));
214 FuncReturn(retval); 214 FuncReturn(retval);
215} 215}
216 216
217template <ResultCode func(Handle, u32)> 217template <ResultCode func(Kernel::Handle, u32)>
218void Wrap() { 218void Wrap() {
219 FuncReturn(func(PARAM(0), PARAM(1)).raw); 219 FuncReturn(func(PARAM(0), PARAM(1)).raw);
220} 220}
221 221
222template <ResultCode func(Handle*, Handle*, const char*, u32)> 222template <ResultCode func(Kernel::Handle*, Kernel::Handle*, const char*, u32)>
223void Wrap() { 223void Wrap() {
224 Handle param_1 = 0; 224 Kernel::Handle param_1 = 0;
225 Handle param_2 = 0; 225 Kernel::Handle param_2 = 0;
226 u32 retval = func(&param_1, &param_2, 226 u32 retval = func(&param_1, &param_2,
227 reinterpret_cast<const char*>(Memory::GetPointer(PARAM(2))), PARAM(3)) 227 reinterpret_cast<const char*>(Memory::GetPointer(PARAM(2))), PARAM(3))
228 .raw; 228 .raw;
229 // The first out parameter is moved into R2 and the second is moved into R1. 229 // The first out parameter is moved into R2 and the second is moved into R1.
230 Core::g_app_core->SetReg(1, param_2); 230 Core::CPU().SetReg(1, param_2);
231 Core::g_app_core->SetReg(2, param_1); 231 Core::CPU().SetReg(2, param_1);
232 FuncReturn(retval); 232 FuncReturn(retval);
233} 233}
234 234
diff --git a/src/core/hle/hle.cpp b/src/core/hle/hle.cpp
index 41b772163..d73d98a70 100644
--- a/src/core/hle/hle.cpp
+++ b/src/core/hle/hle.cpp
@@ -26,9 +26,9 @@ void Reschedule(const char* reason) {
26 // routines. This simulates that time by artificially advancing the number of CPU "ticks". 26 // routines. This simulates that time by artificially advancing the number of CPU "ticks".
27 // The value was chosen empirically, it seems to work well enough for everything tested, but 27 // The value was chosen empirically, it seems to work well enough for everything tested, but
28 // is likely not ideal. We should find a more accurate way to simulate timing with HLE. 28 // is likely not ideal. We should find a more accurate way to simulate timing with HLE.
29 Core::g_app_core->AddTicks(4000); 29 Core::AppCore().AddTicks(4000);
30 30
31 Core::g_app_core->PrepareReschedule(); 31 Core::AppCore().PrepareReschedule();
32 32
33 reschedule = true; 33 reschedule = true;
34} 34}
diff --git a/src/core/hle/hle.h b/src/core/hle/hle.h
deleted file mode 100644
index 23859e129..000000000
--- a/src/core/hle/hle.h
+++ /dev/null
@@ -1,23 +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#pragma once
6
7#include "common/common_types.h"
8
9typedef u32 Handle;
10typedef s32 Result;
11
12const Handle INVALID_HANDLE = 0;
13
14namespace HLE {
15
16void Reschedule(const char* reason);
17bool IsReschedulePending();
18void DoneRescheduling();
19
20void Init();
21void Shutdown();
22
23} // namespace
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp
index b5a0cc3a3..01fab123e 100644
--- a/src/core/hle/kernel/address_arbiter.cpp
+++ b/src/core/hle/kernel/address_arbiter.cpp
@@ -4,7 +4,6 @@
4 4
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#include "core/hle/hle.h"
8#include "core/hle/kernel/address_arbiter.h" 7#include "core/hle/kernel/address_arbiter.h"
9#include "core/hle/kernel/thread.h" 8#include "core/hle/kernel/thread.h"
10#include "core/memory.h" 9#include "core/memory.h"
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index 1adcf6c71..9503e7d04 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -11,11 +11,12 @@
11#include <vector> 11#include <vector>
12#include <boost/smart_ptr/intrusive_ptr.hpp> 12#include <boost/smart_ptr/intrusive_ptr.hpp>
13#include "common/common_types.h" 13#include "common/common_types.h"
14#include "core/hle/hle.h"
15#include "core/hle/result.h" 14#include "core/hle/result.h"
16 15
17namespace Kernel { 16namespace Kernel {
18 17
18using Handle = u32;
19
19class Thread; 20class Thread;
20 21
21// TODO: Verify code 22// TODO: Verify code
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index 18b696f72..5fb95dada 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -14,7 +14,6 @@
14#include "core/arm/skyeye_common/armstate.h" 14#include "core/arm/skyeye_common/armstate.h"
15#include "core/core.h" 15#include "core/core.h"
16#include "core/core_timing.h" 16#include "core/core_timing.h"
17#include "core/hle/hle.h"
18#include "core/hle/kernel/kernel.h" 17#include "core/hle/kernel/kernel.h"
19#include "core/hle/kernel/memory.h" 18#include "core/hle/kernel/memory.h"
20#include "core/hle/kernel/mutex.h" 19#include "core/hle/kernel/mutex.h"
@@ -188,7 +187,7 @@ static void SwitchContext(Thread* new_thread) {
188 // Save context for previous thread 187 // Save context for previous thread
189 if (previous_thread) { 188 if (previous_thread) {
190 previous_thread->last_running_ticks = CoreTiming::GetTicks(); 189 previous_thread->last_running_ticks = CoreTiming::GetTicks();
191 Core::g_app_core->SaveContext(previous_thread->context); 190 Core::CPU().SaveContext(previous_thread->context);
192 191
193 if (previous_thread->status == THREADSTATUS_RUNNING) { 192 if (previous_thread->status == THREADSTATUS_RUNNING) {
194 // This is only the case when a reschedule is triggered without the current thread 193 // This is only the case when a reschedule is triggered without the current thread
@@ -214,8 +213,8 @@ static void SwitchContext(Thread* new_thread) {
214 // Restores thread to its nominal priority if it has been temporarily changed 213 // Restores thread to its nominal priority if it has been temporarily changed
215 new_thread->current_priority = new_thread->nominal_priority; 214 new_thread->current_priority = new_thread->nominal_priority;
216 215
217 Core::g_app_core->LoadContext(new_thread->context); 216 Core::CPU().LoadContext(new_thread->context);
218 Core::g_app_core->SetCP15Register(CP15_THREAD_URO, new_thread->GetTLSAddress()); 217 Core::CPU().SetCP15Register(CP15_THREAD_URO, new_thread->GetTLSAddress());
219 } else { 218 } else {
220 current_thread = nullptr; 219 current_thread = nullptr;
221 } 220 }
@@ -330,7 +329,7 @@ void Thread::ResumeFromWait() {
330 329
331 ready_queue.push_back(current_priority, this); 330 ready_queue.push_back(current_priority, this);
332 status = THREADSTATUS_READY; 331 status = THREADSTATUS_READY;
333 HLE::Reschedule(__func__); 332 Core::System::GetInstance().PrepareReschedule();
334} 333}
335 334
336/** 335/**
@@ -385,9 +384,9 @@ std::tuple<u32, u32, bool> GetFreeThreadLocalSlot(std::vector<std::bitset<8>>& t
385 * @param entry_point Address of entry point for execution 384 * @param entry_point Address of entry point for execution
386 * @param arg User argument for thread 385 * @param arg User argument for thread
387 */ 386 */
388static void ResetThreadContext(Core::ThreadContext& context, u32 stack_top, u32 entry_point, 387static void ResetThreadContext(ARM_Interface::ThreadContext& context, u32 stack_top,
389 u32 arg) { 388 u32 entry_point, u32 arg) {
390 memset(&context, 0, sizeof(Core::ThreadContext)); 389 memset(&context, 0, sizeof(ARM_Interface::ThreadContext));
391 390
392 context.cpu_registers[0] = arg; 391 context.cpu_registers[0] = arg;
393 context.pc = entry_point; 392 context.pc = entry_point;
@@ -545,8 +544,6 @@ void Reschedule() {
545 Thread* cur = GetCurrentThread(); 544 Thread* cur = GetCurrentThread();
546 Thread* next = PopNextReadyThread(); 545 Thread* next = PopNextReadyThread();
547 546
548 HLE::DoneRescheduling();
549
550 if (cur && next) { 547 if (cur && next) {
551 LOG_TRACE(Kernel, "context switch %u -> %u", cur->GetObjectId(), next->GetObjectId()); 548 LOG_TRACE(Kernel, "context switch %u -> %u", cur->GetObjectId(), next->GetObjectId());
552 } else if (cur) { 549 } else if (cur) {
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index d4fefc573..c77ac644d 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -10,8 +10,8 @@
10#include <boost/container/flat_map.hpp> 10#include <boost/container/flat_map.hpp>
11#include <boost/container/flat_set.hpp> 11#include <boost/container/flat_set.hpp>
12#include "common/common_types.h" 12#include "common/common_types.h"
13#include "core/arm/arm_interface.h"
13#include "core/core.h" 14#include "core/core.h"
14#include "core/hle/hle.h"
15#include "core/hle/kernel/kernel.h" 15#include "core/hle/kernel/kernel.h"
16#include "core/hle/result.h" 16#include "core/hle/result.h"
17 17
@@ -158,7 +158,7 @@ public:
158 return !wait_objects.empty(); 158 return !wait_objects.empty();
159 } 159 }
160 160
161 Core::ThreadContext context; 161 ARM_Interface::ThreadContext context;
162 162
163 u32 thread_id; 163 u32 thread_id;
164 164
diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp
index 09205e4b2..6cddc1fdb 100644
--- a/src/core/hle/service/fs/archive.cpp
+++ b/src/core/hle/service/fs/archive.cpp
@@ -23,7 +23,6 @@
23#include "core/file_sys/archive_systemsavedata.h" 23#include "core/file_sys/archive_systemsavedata.h"
24#include "core/file_sys/directory_backend.h" 24#include "core/file_sys/directory_backend.h"
25#include "core/file_sys/file_backend.h" 25#include "core/file_sys/file_backend.h"
26#include "core/hle/hle.h"
27#include "core/hle/kernel/client_session.h" 26#include "core/hle/kernel/client_session.h"
28#include "core/hle/result.h" 27#include "core/hle/result.h"
29#include "core/hle/service/fs/archive.h" 28#include "core/hle/service/fs/archive.h"
@@ -46,9 +45,7 @@ struct hash<Service::FS::ArchiveIdCode> {
46}; 45};
47} 46}
48 47
49/// TODO(Subv): Confirm length of these strings 48static constexpr Kernel::Handle INVALID_HANDLE{};
50const std::string SYSTEM_ID = "00000000000000000000000000000000";
51const std::string SDCARD_ID = "00000000000000000000000000000000";
52 49
53namespace Service { 50namespace Service {
54namespace FS { 51namespace FS {
diff --git a/src/core/hle/service/fs/archive.h b/src/core/hle/service/fs/archive.h
index 7ba62ede0..519c1f3a9 100644
--- a/src/core/hle/service/fs/archive.h
+++ b/src/core/hle/service/fs/archive.h
@@ -17,9 +17,9 @@ class FileBackend;
17} 17}
18 18
19/// The unique system identifier hash, also known as ID0 19/// The unique system identifier hash, also known as ID0
20extern const std::string SYSTEM_ID; 20static constexpr char SYSTEM_ID[]{"00000000000000000000000000000000"};
21/// The scrambled SD card CID, also known as ID1 21/// The scrambled SD card CID, also known as ID1
22extern const std::string SDCARD_ID; 22static constexpr char SDCARD_ID[]{"00000000000000000000000000000000"};
23 23
24namespace Service { 24namespace Service {
25namespace FS { 25namespace FS {
diff --git a/src/core/hle/service/ir/ir.cpp b/src/core/hle/service/ir/ir.cpp
index 4d6639ded..7f1731a50 100644
--- a/src/core/hle/service/ir/ir.cpp
+++ b/src/core/hle/service/ir/ir.cpp
@@ -3,6 +3,7 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include "core/hle/kernel/event.h" 5#include "core/hle/kernel/event.h"
6#include "core/hle/kernel/kernel.h"
6#include "core/hle/kernel/shared_memory.h" 7#include "core/hle/kernel/shared_memory.h"
7#include "core/hle/service/ir/ir.h" 8#include "core/hle/service/ir/ir.h"
8#include "core/hle/service/ir/ir_rst.h" 9#include "core/hle/service/ir/ir_rst.h"
@@ -36,7 +37,7 @@ void InitializeIrNopShared(Interface* self) {
36 u32 send_buff_size = cmd_buff[4]; 37 u32 send_buff_size = cmd_buff[4];
37 u32 unk2 = cmd_buff[5]; 38 u32 unk2 = cmd_buff[5];
38 u8 baud_rate = cmd_buff[6] & 0xFF; 39 u8 baud_rate = cmd_buff[6] & 0xFF;
39 Handle handle = cmd_buff[8]; 40 Kernel::Handle handle = cmd_buff[8];
40 41
41 if (Kernel::g_handle_table.IsValid(handle)) { 42 if (Kernel::g_handle_table.IsValid(handle)) {
42 transfer_shared_memory = Kernel::g_handle_table.Get<Kernel::SharedMemory>(handle); 43 transfer_shared_memory = Kernel::g_handle_table.Get<Kernel::SharedMemory>(handle);
diff --git a/src/core/hle/service/ldr_ro/ldr_ro.cpp b/src/core/hle/service/ldr_ro/ldr_ro.cpp
index 9e5d6a318..8d00a7577 100644
--- a/src/core/hle/service/ldr_ro/ldr_ro.cpp
+++ b/src/core/hle/service/ldr_ro/ldr_ro.cpp
@@ -457,7 +457,7 @@ static void LoadCRO(Interface* self, bool link_on_load_bug_fix) {
457 } 457 }
458 } 458 }
459 459
460 Core::g_app_core->ClearInstructionCache(); 460 Core::CPU().ClearInstructionCache();
461 461
462 LOG_INFO(Service_LDR, "CRO \"%s\" loaded at 0x%08X, fixed_end=0x%08X", cro.ModuleName().data(), 462 LOG_INFO(Service_LDR, "CRO \"%s\" loaded at 0x%08X, fixed_end=0x%08X", cro.ModuleName().data(),
463 cro_address, cro_address + fix_size); 463 cro_address, cro_address + fix_size);
@@ -562,7 +562,7 @@ static void UnloadCRO(Interface* self) {
562 memory_synchronizer.RemoveMemoryBlock(cro_address, cro_buffer_ptr); 562 memory_synchronizer.RemoveMemoryBlock(cro_address, cro_buffer_ptr);
563 } 563 }
564 564
565 Core::g_app_core->ClearInstructionCache(); 565 Core::CPU().ClearInstructionCache();
566 566
567 cmd_buff[1] = result.raw; 567 cmd_buff[1] = result.raw;
568} 568}
@@ -624,7 +624,7 @@ static void LinkCRO(Interface* self) {
624 } 624 }
625 625
626 memory_synchronizer.SynchronizeOriginalMemory(); 626 memory_synchronizer.SynchronizeOriginalMemory();
627 Core::g_app_core->ClearInstructionCache(); 627 Core::CPU().ClearInstructionCache();
628 628
629 cmd_buff[1] = result.raw; 629 cmd_buff[1] = result.raw;
630} 630}
@@ -686,7 +686,7 @@ static void UnlinkCRO(Interface* self) {
686 } 686 }
687 687
688 memory_synchronizer.SynchronizeOriginalMemory(); 688 memory_synchronizer.SynchronizeOriginalMemory();
689 Core::g_app_core->ClearInstructionCache(); 689 Core::CPU().ClearInstructionCache();
690 690
691 cmd_buff[1] = result.raw; 691 cmd_buff[1] = result.raw;
692} 692}
diff --git a/src/core/hle/service/mic_u.cpp b/src/core/hle/service/mic_u.cpp
index 7ced36439..4f1dd2fce 100644
--- a/src/core/hle/service/mic_u.cpp
+++ b/src/core/hle/service/mic_u.cpp
@@ -4,6 +4,7 @@
4 4
5#include "common/logging/log.h" 5#include "common/logging/log.h"
6#include "core/hle/kernel/event.h" 6#include "core/hle/kernel/event.h"
7#include "core/hle/kernel/kernel.h"
7#include "core/hle/kernel/shared_memory.h" 8#include "core/hle/kernel/shared_memory.h"
8#include "core/hle/service/mic_u.h" 9#include "core/hle/service/mic_u.h"
9 10
@@ -50,7 +51,7 @@ static bool audio_buffer_loop;
50static void MapSharedMem(Interface* self) { 51static void MapSharedMem(Interface* self) {
51 u32* cmd_buff = Kernel::GetCommandBuffer(); 52 u32* cmd_buff = Kernel::GetCommandBuffer();
52 u32 size = cmd_buff[1]; 53 u32 size = cmd_buff[1];
53 Handle mem_handle = cmd_buff[3]; 54 Kernel::Handle mem_handle = cmd_buff[3];
54 shared_memory = Kernel::g_handle_table.Get<Kernel::SharedMemory>(mem_handle); 55 shared_memory = Kernel::g_handle_table.Get<Kernel::SharedMemory>(mem_handle);
55 if (shared_memory) { 56 if (shared_memory) {
56 shared_memory->name = "MIC_U:shared_memory"; 57 shared_memory->name = "MIC_U:shared_memory";
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp
index 5839d7230..2ca270de3 100644
--- a/src/core/hle/svc.cpp
+++ b/src/core/hle/svc.cpp
@@ -166,7 +166,8 @@ static ResultCode ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 add
166} 166}
167 167
168/// Maps a memory block to specified address 168/// Maps a memory block to specified address
169static ResultCode MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 other_permissions) { 169static ResultCode MapMemoryBlock(Kernel::Handle handle, u32 addr, u32 permissions,
170 u32 other_permissions) {
170 using Kernel::SharedMemory; 171 using Kernel::SharedMemory;
171 using Kernel::MemoryPermission; 172 using Kernel::MemoryPermission;
172 173
@@ -198,7 +199,7 @@ static ResultCode MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 o
198 ErrorSummary::InvalidArgument, ErrorLevel::Usage); 199 ErrorSummary::InvalidArgument, ErrorLevel::Usage);
199} 200}
200 201
201static ResultCode UnmapMemoryBlock(Handle handle, u32 addr) { 202static ResultCode UnmapMemoryBlock(Kernel::Handle handle, u32 addr) {
202 using Kernel::SharedMemory; 203 using Kernel::SharedMemory;
203 204
204 LOG_TRACE(Kernel_SVC, "called memblock=0x%08X, addr=0x%08X", handle, addr); 205 LOG_TRACE(Kernel_SVC, "called memblock=0x%08X, addr=0x%08X", handle, addr);
@@ -213,7 +214,7 @@ static ResultCode UnmapMemoryBlock(Handle handle, u32 addr) {
213} 214}
214 215
215/// Connect to an OS service given the port name, returns the handle to the port to out 216/// Connect to an OS service given the port name, returns the handle to the port to out
216static ResultCode ConnectToPort(Handle* out_handle, const char* port_name) { 217static ResultCode ConnectToPort(Kernel::Handle* out_handle, const char* port_name) {
217 if (port_name == nullptr) 218 if (port_name == nullptr)
218 return ERR_NOT_FOUND; 219 return ERR_NOT_FOUND;
219 if (std::strlen(port_name) > 11) 220 if (std::strlen(port_name) > 11)
@@ -238,7 +239,7 @@ static ResultCode ConnectToPort(Handle* out_handle, const char* port_name) {
238} 239}
239 240
240/// Makes a blocking IPC call to an OS service. 241/// Makes a blocking IPC call to an OS service.
241static ResultCode SendSyncRequest(Handle handle) { 242static ResultCode SendSyncRequest(Kernel::Handle handle) {
242 SharedPtr<Kernel::ClientSession> session = 243 SharedPtr<Kernel::ClientSession> session =
243 Kernel::g_handle_table.Get<Kernel::ClientSession>(handle); 244 Kernel::g_handle_table.Get<Kernel::ClientSession>(handle);
244 if (session == nullptr) { 245 if (session == nullptr) {
@@ -253,13 +254,13 @@ static ResultCode SendSyncRequest(Handle handle) {
253} 254}
254 255
255/// Close a handle 256/// Close a handle
256static ResultCode CloseHandle(Handle handle) { 257static ResultCode CloseHandle(Kernel::Handle handle) {
257 LOG_TRACE(Kernel_SVC, "Closing handle 0x%08X", handle); 258 LOG_TRACE(Kernel_SVC, "Closing handle 0x%08X", handle);
258 return Kernel::g_handle_table.Close(handle); 259 return Kernel::g_handle_table.Close(handle);
259} 260}
260 261
261/// Wait for a handle to synchronize, timeout after the specified nanoseconds 262/// Wait for a handle to synchronize, timeout after the specified nanoseconds
262static ResultCode WaitSynchronization1(Handle handle, s64 nano_seconds) { 263static ResultCode WaitSynchronization1(Kernel::Handle handle, s64 nano_seconds) {
263 auto object = Kernel::g_handle_table.GetWaitObject(handle); 264 auto object = Kernel::g_handle_table.GetWaitObject(handle);
264 Kernel::Thread* thread = Kernel::GetCurrentThread(); 265 Kernel::Thread* thread = Kernel::GetCurrentThread();
265 266
@@ -295,8 +296,8 @@ static ResultCode WaitSynchronization1(Handle handle, s64 nano_seconds) {
295} 296}
296 297
297/// Wait for the given handles to synchronize, timeout after the specified nanoseconds 298/// Wait for the given handles to synchronize, timeout after the specified nanoseconds
298static ResultCode WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count, bool wait_all, 299static ResultCode WaitSynchronizationN(s32* out, Kernel::Handle* handles, s32 handle_count,
299 s64 nano_seconds) { 300 bool wait_all, s64 nano_seconds) {
300 Kernel::Thread* thread = Kernel::GetCurrentThread(); 301 Kernel::Thread* thread = Kernel::GetCurrentThread();
301 302
302 // Check if 'handles' is invalid 303 // Check if 'handles' is invalid
@@ -423,7 +424,7 @@ static ResultCode WaitSynchronizationN(s32* out, Handle* handles, s32 handle_cou
423} 424}
424 425
425/// Create an address arbiter (to allocate access to shared resources) 426/// Create an address arbiter (to allocate access to shared resources)
426static ResultCode CreateAddressArbiter(Handle* out_handle) { 427static ResultCode CreateAddressArbiter(Kernel::Handle* out_handle) {
427 using Kernel::AddressArbiter; 428 using Kernel::AddressArbiter;
428 429
429 SharedPtr<AddressArbiter> arbiter = AddressArbiter::Create(); 430 SharedPtr<AddressArbiter> arbiter = AddressArbiter::Create();
@@ -433,7 +434,7 @@ static ResultCode CreateAddressArbiter(Handle* out_handle) {
433} 434}
434 435
435/// Arbitrate address 436/// Arbitrate address
436static ResultCode ArbitrateAddress(Handle handle, u32 address, u32 type, u32 value, 437static ResultCode ArbitrateAddress(Kernel::Handle handle, u32 address, u32 type, u32 value,
437 s64 nanoseconds) { 438 s64 nanoseconds) {
438 using Kernel::AddressArbiter; 439 using Kernel::AddressArbiter;
439 440
@@ -476,7 +477,7 @@ static void OutputDebugString(const char* string) {
476} 477}
477 478
478/// Get resource limit 479/// Get resource limit
479static ResultCode GetResourceLimit(Handle* resource_limit, Handle process_handle) { 480static ResultCode GetResourceLimit(Kernel::Handle* resource_limit, Kernel::Handle process_handle) {
480 LOG_TRACE(Kernel_SVC, "called process=0x%08X", process_handle); 481 LOG_TRACE(Kernel_SVC, "called process=0x%08X", process_handle);
481 482
482 SharedPtr<Kernel::Process> process = 483 SharedPtr<Kernel::Process> process =
@@ -490,7 +491,7 @@ static ResultCode GetResourceLimit(Handle* resource_limit, Handle process_handle
490} 491}
491 492
492/// Get resource limit current values 493/// Get resource limit current values
493static ResultCode GetResourceLimitCurrentValues(s64* values, Handle resource_limit_handle, 494static ResultCode GetResourceLimitCurrentValues(s64* values, Kernel::Handle resource_limit_handle,
494 u32* names, u32 name_count) { 495 u32* names, u32 name_count) {
495 LOG_TRACE(Kernel_SVC, "called resource_limit=%08X, names=%p, name_count=%d", 496 LOG_TRACE(Kernel_SVC, "called resource_limit=%08X, names=%p, name_count=%d",
496 resource_limit_handle, names, name_count); 497 resource_limit_handle, names, name_count);
@@ -507,8 +508,8 @@ static ResultCode GetResourceLimitCurrentValues(s64* values, Handle resource_lim
507} 508}
508 509
509/// Get resource limit max values 510/// Get resource limit max values
510static ResultCode GetResourceLimitLimitValues(s64* values, Handle resource_limit_handle, u32* names, 511static ResultCode GetResourceLimitLimitValues(s64* values, Kernel::Handle resource_limit_handle,
511 u32 name_count) { 512 u32* names, u32 name_count) {
512 LOG_TRACE(Kernel_SVC, "called resource_limit=%08X, names=%p, name_count=%d", 513 LOG_TRACE(Kernel_SVC, "called resource_limit=%08X, names=%p, name_count=%d",
513 resource_limit_handle, names, name_count); 514 resource_limit_handle, names, name_count);
514 515
@@ -524,7 +525,7 @@ static ResultCode GetResourceLimitLimitValues(s64* values, Handle resource_limit
524} 525}
525 526
526/// Creates a new thread 527/// Creates a new thread
527static ResultCode CreateThread(Handle* out_handle, s32 priority, u32 entry_point, u32 arg, 528static ResultCode CreateThread(Kernel::Handle* out_handle, s32 priority, u32 entry_point, u32 arg,
528 u32 stack_top, s32 processor_id) { 529 u32 stack_top, s32 processor_id) {
529 using Kernel::Thread; 530 using Kernel::Thread;
530 531
@@ -582,13 +583,13 @@ static ResultCode CreateThread(Handle* out_handle, s32 priority, u32 entry_point
582 583
583/// Called when a thread exits 584/// Called when a thread exits
584static void ExitThread() { 585static void ExitThread() {
585 LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::g_app_core->GetPC()); 586 LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::CPU().GetPC());
586 587
587 Kernel::ExitCurrentThread(); 588 Kernel::ExitCurrentThread();
588} 589}
589 590
590/// Gets the priority for the specified thread 591/// Gets the priority for the specified thread
591static ResultCode GetThreadPriority(s32* priority, Handle handle) { 592static ResultCode GetThreadPriority(s32* priority, Kernel::Handle handle) {
592 const SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle); 593 const SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
593 if (thread == nullptr) 594 if (thread == nullptr)
594 return ERR_INVALID_HANDLE; 595 return ERR_INVALID_HANDLE;
@@ -598,7 +599,7 @@ static ResultCode GetThreadPriority(s32* priority, Handle handle) {
598} 599}
599 600
600/// Sets the priority for the specified thread 601/// Sets the priority for the specified thread
601static ResultCode SetThreadPriority(Handle handle, s32 priority) { 602static ResultCode SetThreadPriority(Kernel::Handle handle, s32 priority) {
602 SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle); 603 SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
603 if (thread == nullptr) 604 if (thread == nullptr)
604 return ERR_INVALID_HANDLE; 605 return ERR_INVALID_HANDLE;
@@ -608,11 +609,11 @@ static ResultCode SetThreadPriority(Handle handle, s32 priority) {
608} 609}
609 610
610/// Create a mutex 611/// Create a mutex
611static ResultCode CreateMutex(Handle* out_handle, u32 initial_locked) { 612static ResultCode CreateMutex(Kernel::Handle* out_handle, u32 initial_locked) {
612 using Kernel::Mutex; 613 using Kernel::Mutex;
613 614
614 SharedPtr<Mutex> mutex = Mutex::Create(initial_locked != 0); 615 SharedPtr<Mutex> mutex = Mutex::Create(initial_locked != 0);
615 mutex->name = Common::StringFromFormat("mutex-%08x", Core::g_app_core->GetReg(14)); 616 mutex->name = Common::StringFromFormat("mutex-%08x", Core::CPU().GetReg(14));
616 CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(mutex))); 617 CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(mutex)));
617 618
618 LOG_TRACE(Kernel_SVC, "called initial_locked=%s : created handle=0x%08X", 619 LOG_TRACE(Kernel_SVC, "called initial_locked=%s : created handle=0x%08X",
@@ -622,7 +623,7 @@ static ResultCode CreateMutex(Handle* out_handle, u32 initial_locked) {
622} 623}
623 624
624/// Release a mutex 625/// Release a mutex
625static ResultCode ReleaseMutex(Handle handle) { 626static ResultCode ReleaseMutex(Kernel::Handle handle) {
626 using Kernel::Mutex; 627 using Kernel::Mutex;
627 628
628 LOG_TRACE(Kernel_SVC, "called handle=0x%08X", handle); 629 LOG_TRACE(Kernel_SVC, "called handle=0x%08X", handle);
@@ -637,7 +638,7 @@ static ResultCode ReleaseMutex(Handle handle) {
637} 638}
638 639
639/// Get the ID of the specified process 640/// Get the ID of the specified process
640static ResultCode GetProcessId(u32* process_id, Handle process_handle) { 641static ResultCode GetProcessId(u32* process_id, Kernel::Handle process_handle) {
641 LOG_TRACE(Kernel_SVC, "called process=0x%08X", process_handle); 642 LOG_TRACE(Kernel_SVC, "called process=0x%08X", process_handle);
642 643
643 const SharedPtr<Kernel::Process> process = 644 const SharedPtr<Kernel::Process> process =
@@ -650,7 +651,7 @@ static ResultCode GetProcessId(u32* process_id, Handle process_handle) {
650} 651}
651 652
652/// Get the ID of the process that owns the specified thread 653/// Get the ID of the process that owns the specified thread
653static ResultCode GetProcessIdOfThread(u32* process_id, Handle thread_handle) { 654static ResultCode GetProcessIdOfThread(u32* process_id, Kernel::Handle thread_handle) {
654 LOG_TRACE(Kernel_SVC, "called thread=0x%08X", thread_handle); 655 LOG_TRACE(Kernel_SVC, "called thread=0x%08X", thread_handle);
655 656
656 const SharedPtr<Kernel::Thread> thread = 657 const SharedPtr<Kernel::Thread> thread =
@@ -667,7 +668,7 @@ static ResultCode GetProcessIdOfThread(u32* process_id, Handle thread_handle) {
667} 668}
668 669
669/// Get the ID for the specified thread. 670/// Get the ID for the specified thread.
670static ResultCode GetThreadId(u32* thread_id, Handle handle) { 671static ResultCode GetThreadId(u32* thread_id, Kernel::Handle handle) {
671 LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle); 672 LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle);
672 673
673 const SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle); 674 const SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
@@ -679,11 +680,11 @@ static ResultCode GetThreadId(u32* thread_id, Handle handle) {
679} 680}
680 681
681/// Creates a semaphore 682/// Creates a semaphore
682static ResultCode CreateSemaphore(Handle* out_handle, s32 initial_count, s32 max_count) { 683static ResultCode CreateSemaphore(Kernel::Handle* out_handle, s32 initial_count, s32 max_count) {
683 using Kernel::Semaphore; 684 using Kernel::Semaphore;
684 685
685 CASCADE_RESULT(SharedPtr<Semaphore> semaphore, Semaphore::Create(initial_count, max_count)); 686 CASCADE_RESULT(SharedPtr<Semaphore> semaphore, Semaphore::Create(initial_count, max_count));
686 semaphore->name = Common::StringFromFormat("semaphore-%08x", Core::g_app_core->GetReg(14)); 687 semaphore->name = Common::StringFromFormat("semaphore-%08x", Core::CPU().GetReg(14));
687 CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(semaphore))); 688 CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(semaphore)));
688 689
689 LOG_TRACE(Kernel_SVC, "called initial_count=%d, max_count=%d, created handle=0x%08X", 690 LOG_TRACE(Kernel_SVC, "called initial_count=%d, max_count=%d, created handle=0x%08X",
@@ -692,7 +693,7 @@ static ResultCode CreateSemaphore(Handle* out_handle, s32 initial_count, s32 max
692} 693}
693 694
694/// Releases a certain number of slots in a semaphore 695/// Releases a certain number of slots in a semaphore
695static ResultCode ReleaseSemaphore(s32* count, Handle handle, s32 release_count) { 696static ResultCode ReleaseSemaphore(s32* count, Kernel::Handle handle, s32 release_count) {
696 using Kernel::Semaphore; 697 using Kernel::Semaphore;
697 698
698 LOG_TRACE(Kernel_SVC, "called release_count=%d, handle=0x%08X", release_count, handle); 699 LOG_TRACE(Kernel_SVC, "called release_count=%d, handle=0x%08X", release_count, handle);
@@ -708,7 +709,7 @@ static ResultCode ReleaseSemaphore(s32* count, Handle handle, s32 release_count)
708 709
709/// Query process memory 710/// Query process memory
710static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* page_info, 711static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* page_info,
711 Handle process_handle, u32 addr) { 712 Kernel::Handle process_handle, u32 addr) {
712 using Kernel::Process; 713 using Kernel::Process;
713 Kernel::SharedPtr<Process> process = Kernel::g_handle_table.Get<Process>(process_handle); 714 Kernel::SharedPtr<Process> process = Kernel::g_handle_table.Get<Process>(process_handle);
714 if (process == nullptr) 715 if (process == nullptr)
@@ -736,11 +737,11 @@ static ResultCode QueryMemory(MemoryInfo* memory_info, PageInfo* page_info, u32
736} 737}
737 738
738/// Create an event 739/// Create an event
739static ResultCode CreateEvent(Handle* out_handle, u32 reset_type) { 740static ResultCode CreateEvent(Kernel::Handle* out_handle, u32 reset_type) {
740 using Kernel::Event; 741 using Kernel::Event;
741 742
742 SharedPtr<Event> evt = Event::Create(static_cast<Kernel::ResetType>(reset_type)); 743 SharedPtr<Event> evt = Event::Create(static_cast<Kernel::ResetType>(reset_type));
743 evt->name = Common::StringFromFormat("event-%08x", Core::g_app_core->GetReg(14)); 744 evt->name = Common::StringFromFormat("event-%08x", Core::CPU().GetReg(14));
744 CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(evt))); 745 CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(evt)));
745 746
746 LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, 747 LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type,
@@ -749,14 +750,14 @@ static ResultCode CreateEvent(Handle* out_handle, u32 reset_type) {
749} 750}
750 751
751/// Duplicates a kernel handle 752/// Duplicates a kernel handle
752static ResultCode DuplicateHandle(Handle* out, Handle handle) { 753static ResultCode DuplicateHandle(Kernel::Handle* out, Kernel::Handle handle) {
753 CASCADE_RESULT(*out, Kernel::g_handle_table.Duplicate(handle)); 754 CASCADE_RESULT(*out, Kernel::g_handle_table.Duplicate(handle));
754 LOG_TRACE(Kernel_SVC, "duplicated 0x%08X to 0x%08X", handle, *out); 755 LOG_TRACE(Kernel_SVC, "duplicated 0x%08X to 0x%08X", handle, *out);
755 return RESULT_SUCCESS; 756 return RESULT_SUCCESS;
756} 757}
757 758
758/// Signals an event 759/// Signals an event
759static ResultCode SignalEvent(Handle handle) { 760static ResultCode SignalEvent(Kernel::Handle handle) {
760 using Kernel::Event; 761 using Kernel::Event;
761 LOG_TRACE(Kernel_SVC, "called event=0x%08X", handle); 762 LOG_TRACE(Kernel_SVC, "called event=0x%08X", handle);
762 763
@@ -770,7 +771,7 @@ static ResultCode SignalEvent(Handle handle) {
770} 771}
771 772
772/// Clears an event 773/// Clears an event
773static ResultCode ClearEvent(Handle handle) { 774static ResultCode ClearEvent(Kernel::Handle handle) {
774 using Kernel::Event; 775 using Kernel::Event;
775 LOG_TRACE(Kernel_SVC, "called event=0x%08X", handle); 776 LOG_TRACE(Kernel_SVC, "called event=0x%08X", handle);
776 777
@@ -783,11 +784,11 @@ static ResultCode ClearEvent(Handle handle) {
783} 784}
784 785
785/// Creates a timer 786/// Creates a timer
786static ResultCode CreateTimer(Handle* out_handle, u32 reset_type) { 787static ResultCode CreateTimer(Kernel::Handle* out_handle, u32 reset_type) {
787 using Kernel::Timer; 788 using Kernel::Timer;
788 789
789 SharedPtr<Timer> timer = Timer::Create(static_cast<Kernel::ResetType>(reset_type)); 790 SharedPtr<Timer> timer = Timer::Create(static_cast<Kernel::ResetType>(reset_type));
790 timer->name = Common::StringFromFormat("timer-%08x", Core::g_app_core->GetReg(14)); 791 timer->name = Common::StringFromFormat("timer-%08x", Core::CPU().GetReg(14));
791 CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(timer))); 792 CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(timer)));
792 793
793 LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, 794 LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type,
@@ -796,7 +797,7 @@ static ResultCode CreateTimer(Handle* out_handle, u32 reset_type) {
796} 797}
797 798
798/// Clears a timer 799/// Clears a timer
799static ResultCode ClearTimer(Handle handle) { 800static ResultCode ClearTimer(Kernel::Handle handle) {
800 using Kernel::Timer; 801 using Kernel::Timer;
801 802
802 LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle); 803 LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle);
@@ -810,7 +811,7 @@ static ResultCode ClearTimer(Handle handle) {
810} 811}
811 812
812/// Starts a timer 813/// Starts a timer
813static ResultCode SetTimer(Handle handle, s64 initial, s64 interval) { 814static ResultCode SetTimer(Kernel::Handle handle, s64 initial, s64 interval) {
814 using Kernel::Timer; 815 using Kernel::Timer;
815 816
816 LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle); 817 LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle);
@@ -825,7 +826,7 @@ static ResultCode SetTimer(Handle handle, s64 initial, s64 interval) {
825} 826}
826 827
827/// Cancels a timer 828/// Cancels a timer
828static ResultCode CancelTimer(Handle handle) { 829static ResultCode CancelTimer(Kernel::Handle handle) {
829 using Kernel::Timer; 830 using Kernel::Timer;
830 831
831 LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle); 832 LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle);
@@ -854,14 +855,13 @@ static void SleepThread(s64 nanoseconds) {
854static s64 GetSystemTick() { 855static s64 GetSystemTick() {
855 s64 result = CoreTiming::GetTicks(); 856 s64 result = CoreTiming::GetTicks();
856 // Advance time to defeat dumb games (like Cubic Ninja) that busy-wait for the frame to end. 857 // Advance time to defeat dumb games (like Cubic Ninja) that busy-wait for the frame to end.
857 Core::g_app_core->AddTicks( 858 Core::CPU().AddTicks(150); // Measured time between two calls on a 9.2 o3DS with Ninjhax 1.1b
858 150); // Measured time between two calls on a 9.2 o3DS with Ninjhax 1.1b
859 return result; 859 return result;
860} 860}
861 861
862/// Creates a memory block at the specified address with the specified permissions and size 862/// Creates a memory block at the specified address with the specified permissions and size
863static ResultCode CreateMemoryBlock(Handle* out_handle, u32 addr, u32 size, u32 my_permission, 863static ResultCode CreateMemoryBlock(Kernel::Handle* out_handle, u32 addr, u32 size,
864 u32 other_permission) { 864 u32 my_permission, u32 other_permission) {
865 using Kernel::SharedMemory; 865 using Kernel::SharedMemory;
866 866
867 if (size % Memory::PAGE_SIZE != 0) 867 if (size % Memory::PAGE_SIZE != 0)
@@ -912,8 +912,8 @@ static ResultCode CreateMemoryBlock(Handle* out_handle, u32 addr, u32 size, u32
912 return RESULT_SUCCESS; 912 return RESULT_SUCCESS;
913} 913}
914 914
915static ResultCode CreatePort(Handle* server_port, Handle* client_port, const char* name, 915static ResultCode CreatePort(Kernel::Handle* server_port, Kernel::Handle* client_port,
916 u32 max_sessions) { 916 const char* name, u32 max_sessions) {
917 // TODO(Subv): Implement named ports. 917 // TODO(Subv): Implement named ports.
918 ASSERT_MSG(name == nullptr, "Named ports are currently unimplemented"); 918 ASSERT_MSG(name == nullptr, "Named ports are currently unimplemented");
919 919
@@ -978,7 +978,7 @@ static ResultCode GetSystemInfo(s64* out, u32 type, s32 param) {
978 return RESULT_SUCCESS; 978 return RESULT_SUCCESS;
979} 979}
980 980
981static ResultCode GetProcessInfo(s64* out, Handle process_handle, u32 type) { 981static ResultCode GetProcessInfo(s64* out, Kernel::Handle process_handle, u32 type) {
982 LOG_TRACE(Kernel_SVC, "called process=0x%08X type=%u", process_handle, type); 982 LOG_TRACE(Kernel_SVC, "called process=0x%08X type=%u", process_handle, type);
983 983
984 using Kernel::Process; 984 using Kernel::Process;
@@ -1185,7 +1185,7 @@ void CallSVC(u32 immediate) {
1185 if (info->func) { 1185 if (info->func) {
1186 info->func(); 1186 info->func();
1187 // TODO(Subv): Not all service functions should cause a reschedule in all cases. 1187 // TODO(Subv): Not all service functions should cause a reschedule in all cases.
1188 HLE::Reschedule(__func__); 1188 Core::System::GetInstance().PrepareReschedule();
1189 } else { 1189 } else {
1190 LOG_ERROR(Kernel_SVC, "unimplemented SVC function %s(..)", info->name); 1190 LOG_ERROR(Kernel_SVC, "unimplemented SVC function %s(..)", info->name);
1191 } 1191 }