summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar bunnei2018-01-02 20:40:30 -0500
committerGravatar bunnei2018-01-02 20:40:30 -0500
commit480906fe1b31a8830aec80fbea04ec941894003f (patch)
treecef091503185cde98d5a8a6cd64bda83d6b8ff38 /src/core
parentsvc: Improve svcGetInfo. (diff)
downloadyuzu-480906fe1b31a8830aec80fbea04ec941894003f.tar.gz
yuzu-480906fe1b31a8830aec80fbea04ec941894003f.tar.xz
yuzu-480906fe1b31a8830aec80fbea04ec941894003f.zip
hle: Move SVC code to kernel namespace.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/CMakeLists.txt6
-rw-r--r--src/core/hle/kernel/svc.cpp (renamed from src/core/hle/svc.cpp)193
-rw-r--r--src/core/hle/kernel/svc.h (renamed from src/core/hle/svc.h)12
-rw-r--r--src/core/hle/kernel/svc_wrap.h (renamed from src/core/hle/function_wrappers.h)44
4 files changed, 121 insertions, 134 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index a5a633f82..d93eb39a4 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -43,6 +43,7 @@ set(SRCS
43 hle/kernel/server_port.cpp 43 hle/kernel/server_port.cpp
44 hle/kernel/server_session.cpp 44 hle/kernel/server_session.cpp
45 hle/kernel/shared_memory.cpp 45 hle/kernel/shared_memory.cpp
46 hle/kernel/svc.cpp
46 hle/kernel/thread.cpp 47 hle/kernel/thread.cpp
47 hle/kernel/timer.cpp 48 hle/kernel/timer.cpp
48 hle/kernel/vm_manager.cpp 49 hle/kernel/vm_manager.cpp
@@ -63,7 +64,6 @@ set(SRCS
63 hle/service/sm/controller.cpp 64 hle/service/sm/controller.cpp
64 hle/service/sm/sm.cpp 65 hle/service/sm/sm.cpp
65 hle/shared_page.cpp 66 hle/shared_page.cpp
66 hle/svc.cpp
67 hw/aes/arithmetic128.cpp 67 hw/aes/arithmetic128.cpp
68 hw/aes/ccm.cpp 68 hw/aes/ccm.cpp
69 hw/aes/key.cpp 69 hw/aes/key.cpp
@@ -116,7 +116,6 @@ set(HEADERS
116 frontend/input.h 116 frontend/input.h
117 gdbstub/gdbstub.h 117 gdbstub/gdbstub.h
118 hle/config_mem.h 118 hle/config_mem.h
119 hle/function_wrappers.h
120 hle/ipc.h 119 hle/ipc.h
121 hle/ipc_helpers.h 120 hle/ipc_helpers.h
122 hle/kernel/address_arbiter.h 121 hle/kernel/address_arbiter.h
@@ -139,6 +138,8 @@ set(HEADERS
139 hle/kernel/session.h 138 hle/kernel/session.h
140 hle/kernel/shared_memory.h 139 hle/kernel/shared_memory.h
141 hle/kernel/sync_object.h 140 hle/kernel/sync_object.h
141 hle/kernel/svc.h
142 hle/kernel/svc_wrap.h
142 hle/kernel/thread.h 143 hle/kernel/thread.h
143 hle/kernel/timer.h 144 hle/kernel/timer.h
144 hle/kernel/vm_manager.h 145 hle/kernel/vm_manager.h
@@ -160,7 +161,6 @@ set(HEADERS
160 hle/service/sm/controller.h 161 hle/service/sm/controller.h
161 hle/service/sm/sm.h 162 hle/service/sm/sm.h
162 hle/shared_page.h 163 hle/shared_page.h
163 hle/svc.h
164 hw/aes/arithmetic128.h 164 hw/aes/arithmetic128.h
165 hw/aes/ccm.h 165 hw/aes/ccm.h
166 hw/aes/key.h 166 hw/aes/key.h
diff --git a/src/core/hle/svc.cpp b/src/core/hle/kernel/svc.cpp
index 6ec151d94..3dae8b38b 100644
--- a/src/core/hle/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -5,7 +5,6 @@
5#include "common/logging/log.h" 5#include "common/logging/log.h"
6#include "common/microprofile.h" 6#include "common/microprofile.h"
7#include "core/core_timing.h" 7#include "core/core_timing.h"
8#include "core/hle/function_wrappers.h"
9#include "core/hle/kernel/client_port.h" 8#include "core/hle/kernel/client_port.h"
10#include "core/hle/kernel/client_session.h" 9#include "core/hle/kernel/client_session.h"
11#include "core/hle/kernel/handle_table.h" 10#include "core/hle/kernel/handle_table.h"
@@ -13,27 +12,22 @@
13#include "core/hle/kernel/object_address_table.h" 12#include "core/hle/kernel/object_address_table.h"
14#include "core/hle/kernel/process.h" 13#include "core/hle/kernel/process.h"
15#include "core/hle/kernel/resource_limit.h" 14#include "core/hle/kernel/resource_limit.h"
15#include "core/hle/kernel/svc.h"
16#include "core/hle/kernel/svc_wrap.h"
16#include "core/hle/kernel/sync_object.h" 17#include "core/hle/kernel/sync_object.h"
17#include "core/hle/kernel/thread.h" 18#include "core/hle/kernel/thread.h"
18#include "core/hle/lock.h" 19#include "core/hle/lock.h"
19#include "core/hle/result.h" 20#include "core/hle/result.h"
20#include "core/hle/service/service.h" 21#include "core/hle/service/service.h"
21 22
22//////////////////////////////////////////////////////////////////////////////////////////////////// 23namespace Kernel {
23// Namespace SVC
24
25using Kernel::ERR_INVALID_HANDLE;
26using Kernel::Handle;
27using Kernel::SharedPtr;
28
29namespace SVC {
30 24
31/// Set the process heap to a given Size. It can both extend and shrink the heap. 25/// Set the process heap to a given Size. It can both extend and shrink the heap.
32static ResultCode SetHeapSize(VAddr* heap_addr, u64 heap_size) { 26static ResultCode SetHeapSize(VAddr* heap_addr, u64 heap_size) {
33 LOG_TRACE(Kernel_SVC, "called, heap_size=0x%llx", heap_size); 27 LOG_TRACE(Kernel_SVC, "called, heap_size=0x%llx", heap_size);
34 auto& process = *Kernel::g_current_process; 28 auto& process = *g_current_process;
35 CASCADE_RESULT(*heap_addr, process.HeapAllocate(Memory::HEAP_VADDR, heap_size, 29 CASCADE_RESULT(*heap_addr, process.HeapAllocate(Memory::HEAP_VADDR, heap_size,
36 Kernel::VMAPermission::ReadWrite)); 30 VMAPermission::ReadWrite));
37 return RESULT_SUCCESS; 31 return RESULT_SUCCESS;
38} 32}
39 33
@@ -41,48 +35,48 @@ static ResultCode SetHeapSize(VAddr* heap_addr, u64 heap_size) {
41static ResultCode MapMemory(VAddr dst_addr, VAddr src_addr, u64 size) { 35static ResultCode MapMemory(VAddr dst_addr, VAddr src_addr, u64 size) {
42 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x%llx, src_addr=0x%llx, size=0x%llx", dst_addr, 36 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x%llx, src_addr=0x%llx, size=0x%llx", dst_addr,
43 src_addr, size); 37 src_addr, size);
44 return Kernel::g_current_process->MirrorMemory(dst_addr, src_addr, size); 38 return g_current_process->MirrorMemory(dst_addr, src_addr, size);
45} 39}
46 40
47/// Unmaps a region that was previously mapped with svcMapMemory 41/// Unmaps a region that was previously mapped with svcMapMemory
48static ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size) { 42static ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size) {
49 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x%llx, src_addr=0x%llx, size=0x%llx", dst_addr, 43 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x%llx, src_addr=0x%llx, size=0x%llx", dst_addr,
50 src_addr, size); 44 src_addr, size);
51 return Kernel::g_current_process->UnmapMemory(dst_addr, src_addr, size); 45 return g_current_process->UnmapMemory(dst_addr, src_addr, size);
52} 46}
53 47
54/// Connect to an OS service given the port name, returns the handle to the port to out 48/// Connect to an OS service given the port name, returns the handle to the port to out
55static ResultCode ConnectToPort(Kernel::Handle* out_handle, VAddr port_name_address) { 49static ResultCode ConnectToPort(Handle* out_handle, VAddr port_name_address) {
56 if (!Memory::IsValidVirtualAddress(port_name_address)) 50 if (!Memory::IsValidVirtualAddress(port_name_address))
57 return Kernel::ERR_NOT_FOUND; 51 return ERR_NOT_FOUND;
58 52
59 static constexpr std::size_t PortNameMaxLength = 11; 53 static constexpr std::size_t PortNameMaxLength = 11;
60 // Read 1 char beyond the max allowed port name to detect names that are too long. 54 // Read 1 char beyond the max allowed port name to detect names that are too long.
61 std::string port_name = Memory::ReadCString(port_name_address, PortNameMaxLength + 1); 55 std::string port_name = Memory::ReadCString(port_name_address, PortNameMaxLength + 1);
62 if (port_name.size() > PortNameMaxLength) 56 if (port_name.size() > PortNameMaxLength)
63 return Kernel::ERR_PORT_NAME_TOO_LONG; 57 return ERR_PORT_NAME_TOO_LONG;
64 58
65 LOG_TRACE(Kernel_SVC, "called port_name=%s", port_name.c_str()); 59 LOG_TRACE(Kernel_SVC, "called port_name=%s", port_name.c_str());
66 60
67 auto it = Service::g_kernel_named_ports.find(port_name); 61 auto it = Service::g_kernel_named_ports.find(port_name);
68 if (it == Service::g_kernel_named_ports.end()) { 62 if (it == Service::g_kernel_named_ports.end()) {
69 LOG_WARNING(Kernel_SVC, "tried to connect to unknown port: %s", port_name.c_str()); 63 LOG_WARNING(Kernel_SVC, "tried to connect to unknown port: %s", port_name.c_str());
70 return Kernel::ERR_NOT_FOUND; 64 return ERR_NOT_FOUND;
71 } 65 }
72 66
73 auto client_port = it->second; 67 auto client_port = it->second;
74 68
75 SharedPtr<Kernel::ClientSession> client_session; 69 SharedPtr<ClientSession> client_session;
76 CASCADE_RESULT(client_session, client_port->Connect()); 70 CASCADE_RESULT(client_session, client_port->Connect());
77 71
78 // Return the client session 72 // Return the client session
79 CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(client_session)); 73 CASCADE_RESULT(*out_handle, g_handle_table.Create(client_session));
80 return RESULT_SUCCESS; 74 return RESULT_SUCCESS;
81} 75}
82 76
83/// Makes a blocking IPC call to an OS service. 77/// Makes a blocking IPC call to an OS service.
84static ResultCode SendSyncRequest(Kernel::Handle handle) { 78static ResultCode SendSyncRequest(Handle handle) {
85 SharedPtr<Kernel::SyncObject> session = Kernel::g_handle_table.Get<Kernel::SyncObject>(handle); 79 SharedPtr<SyncObject> session = g_handle_table.Get<SyncObject>(handle);
86 if (!session) { 80 if (!session) {
87 LOG_ERROR(Kernel_SVC, "called with invalid handle=0x%08X", handle); 81 LOG_ERROR(Kernel_SVC, "called with invalid handle=0x%08X", handle);
88 return ERR_INVALID_HANDLE; 82 return ERR_INVALID_HANDLE;
@@ -94,15 +88,15 @@ static ResultCode SendSyncRequest(Kernel::Handle handle) {
94 88
95 // TODO(Subv): svcSendSyncRequest should put the caller thread to sleep while the server 89 // TODO(Subv): svcSendSyncRequest should put the caller thread to sleep while the server
96 // responds and cause a reschedule. 90 // responds and cause a reschedule.
97 return session->SendSyncRequest(Kernel::GetCurrentThread()); 91 return session->SendSyncRequest(GetCurrentThread());
98} 92}
99 93
100/// Get the ID for the specified thread. 94/// Get the ID for the specified thread.
101static ResultCode GetThreadId(u32* thread_id, Kernel::Handle thread_handle) { 95static ResultCode GetThreadId(u32* thread_id, Handle thread_handle) {
102 LOG_TRACE(Kernel_SVC, "called thread=0x%08X", thread_handle); 96 LOG_TRACE(Kernel_SVC, "called thread=0x%08X", thread_handle);
103 97
104 const SharedPtr<Kernel::Thread> thread = 98 const SharedPtr<Thread> thread =
105 Kernel::g_handle_table.Get<Kernel::Thread>(thread_handle); 99 g_handle_table.Get<Thread>(thread_handle);
106 if (!thread) { 100 if (!thread) {
107 return ERR_INVALID_HANDLE; 101 return ERR_INVALID_HANDLE;
108 } 102 }
@@ -112,11 +106,11 @@ static ResultCode GetThreadId(u32* thread_id, Kernel::Handle thread_handle) {
112} 106}
113 107
114/// Get the ID of the specified process 108/// Get the ID of the specified process
115static ResultCode GetProcessId(u32* process_id, Kernel::Handle process_handle) { 109static ResultCode GetProcessId(u32* process_id, Handle process_handle) {
116 LOG_TRACE(Kernel_SVC, "called process=0x%08X", process_handle); 110 LOG_TRACE(Kernel_SVC, "called process=0x%08X", process_handle);
117 111
118 const SharedPtr<Kernel::Process> process = 112 const SharedPtr<Process> process =
119 Kernel::g_handle_table.Get<Kernel::Process>(process_handle); 113 g_handle_table.Get<Process>(process_handle);
120 if (!process) { 114 if (!process) {
121 return ERR_INVALID_HANDLE; 115 return ERR_INVALID_HANDLE;
122 } 116 }
@@ -141,18 +135,18 @@ static ResultCode LockMutex(Handle holding_thread_handle, VAddr mutex_addr,
141 "requesting_current_thread_handle=0x%08X", 135 "requesting_current_thread_handle=0x%08X",
142 holding_thread_handle, mutex_addr, requesting_thread_handle); 136 holding_thread_handle, mutex_addr, requesting_thread_handle);
143 137
144 SharedPtr<Kernel::Thread> holding_thread = 138 SharedPtr<Thread> holding_thread =
145 Kernel::g_handle_table.Get<Kernel::Thread>(holding_thread_handle); 139 g_handle_table.Get<Thread>(holding_thread_handle);
146 SharedPtr<Kernel::Thread> requesting_thread = 140 SharedPtr<Thread> requesting_thread =
147 Kernel::g_handle_table.Get<Kernel::Thread>(requesting_thread_handle); 141 g_handle_table.Get<Thread>(requesting_thread_handle);
148 142
149 ASSERT(holding_thread); 143 ASSERT(holding_thread);
150 ASSERT(requesting_thread); 144 ASSERT(requesting_thread);
151 145
152 SharedPtr<Kernel::Mutex> mutex = Kernel::g_object_address_table.Get<Kernel::Mutex>(mutex_addr); 146 SharedPtr<Mutex> mutex = g_object_address_table.Get<Mutex>(mutex_addr);
153 if (!mutex) { 147 if (!mutex) {
154 // Create a new mutex for the specified address if one does not already exist 148 // Create a new mutex for the specified address if one does not already exist
155 mutex = Kernel::Mutex::Create(holding_thread, mutex_addr); 149 mutex = Mutex::Create(holding_thread, mutex_addr);
156 mutex->name = Common::StringFromFormat("mutex-%llx", mutex_addr); 150 mutex->name = Common::StringFromFormat("mutex-%llx", mutex_addr);
157 } 151 }
158 152
@@ -175,10 +169,10 @@ static ResultCode LockMutex(Handle holding_thread_handle, VAddr mutex_addr,
175static ResultCode UnlockMutex(VAddr mutex_addr) { 169static ResultCode UnlockMutex(VAddr mutex_addr) {
176 LOG_TRACE(Kernel_SVC, "called mutex_addr=0x%llx", mutex_addr); 170 LOG_TRACE(Kernel_SVC, "called mutex_addr=0x%llx", mutex_addr);
177 171
178 SharedPtr<Kernel::Mutex> mutex = Kernel::g_object_address_table.Get<Kernel::Mutex>(mutex_addr); 172 SharedPtr<Mutex> mutex = g_object_address_table.Get<Mutex>(mutex_addr);
179 ASSERT(mutex); 173 ASSERT(mutex);
180 174
181 return mutex->Release(Kernel::GetCurrentThread()); 175 return mutex->Release(GetCurrentThread());
182} 176}
183 177
184/// Break program execution 178/// Break program execution
@@ -199,7 +193,7 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id)
199 LOG_TRACE(Kernel_SVC, "called info_id=0x%X, info_sub_id=0x%X, handle=0x%08X", info_id, 193 LOG_TRACE(Kernel_SVC, "called info_id=0x%X, info_sub_id=0x%X, handle=0x%08X", info_id,
200 info_sub_id, handle); 194 info_sub_id, handle);
201 195
202 auto& vm_manager = Kernel::g_current_process->vm_manager; 196 auto& vm_manager = g_current_process->vm_manager;
203 switch (static_cast<GetInfoType>(info_id)) { 197 switch (static_cast<GetInfoType>(info_id)) {
204 case GetInfoType::TotalMemoryUsage: 198 case GetInfoType::TotalMemoryUsage:
205 *result = vm_manager.GetTotalMemoryUsage(); 199 *result = vm_manager.GetTotalMemoryUsage();
@@ -231,7 +225,7 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id)
231 225
232/// Gets the priority for the specified thread 226/// Gets the priority for the specified thread
233static ResultCode GetThreadPriority(u32* priority, Handle handle) { 227static ResultCode GetThreadPriority(u32* priority, Handle handle) {
234 const SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle); 228 const SharedPtr<Thread> thread = g_handle_table.Get<Thread>(handle);
235 if (!thread) 229 if (!thread)
236 return ERR_INVALID_HANDLE; 230 return ERR_INVALID_HANDLE;
237 231
@@ -242,18 +236,18 @@ static ResultCode GetThreadPriority(u32* priority, Handle handle) {
242/// Sets the priority for the specified thread 236/// Sets the priority for the specified thread
243static ResultCode SetThreadPriority(Handle handle, u32 priority) { 237static ResultCode SetThreadPriority(Handle handle, u32 priority) {
244 if (priority > THREADPRIO_LOWEST) { 238 if (priority > THREADPRIO_LOWEST) {
245 return Kernel::ERR_OUT_OF_RANGE; 239 return ERR_OUT_OF_RANGE;
246 } 240 }
247 241
248 SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle); 242 SharedPtr<Thread> thread = g_handle_table.Get<Thread>(handle);
249 if (!thread) 243 if (!thread)
250 return Kernel::ERR_INVALID_HANDLE; 244 return ERR_INVALID_HANDLE;
251 245
252 // Note: The kernel uses the current process's resource limit instead of 246 // Note: The kernel uses the current process's resource limit instead of
253 // the one from the thread owner's resource limit. 247 // the one from the thread owner's resource limit.
254 SharedPtr<Kernel::ResourceLimit>& resource_limit = Kernel::g_current_process->resource_limit; 248 SharedPtr<ResourceLimit>& resource_limit = g_current_process->resource_limit;
255 if (resource_limit->GetMaxResourceValue(Kernel::ResourceTypes::PRIORITY) > priority) { 249 if (resource_limit->GetMaxResourceValue(ResourceTypes::PRIORITY) > priority) {
256 return Kernel::ERR_NOT_AUTHORIZED; 250 return ERR_NOT_AUTHORIZED;
257 } 251 }
258 252
259 thread->SetPriority(priority); 253 thread->SetPriority(priority);
@@ -275,19 +269,18 @@ static u32 GetCurrentProcessorNumber() {
275 269
276/// Query process memory 270/// Query process memory
277static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* /*page_info*/, 271static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* /*page_info*/,
278 Kernel::Handle process_handle, u64 addr) { 272 Handle process_handle, u64 addr) {
279 using Kernel::Process; 273 SharedPtr<Process> process = g_handle_table.Get<Process>(process_handle);
280 Kernel::SharedPtr<Process> process = Kernel::g_handle_table.Get<Process>(process_handle);
281 if (!process) { 274 if (!process) {
282 return ERR_INVALID_HANDLE; 275 return ERR_INVALID_HANDLE;
283 } 276 }
284 auto vma = process->vm_manager.FindVMA(addr); 277 auto vma = process->vm_manager.FindVMA(addr);
285 memory_info->attributes = 0; 278 memory_info->attributes = 0;
286 if (vma == Kernel::g_current_process->vm_manager.vma_map.end()) { 279 if (vma == g_current_process->vm_manager.vma_map.end()) {
287 memory_info->base_address = 0; 280 memory_info->base_address = 0;
288 memory_info->permission = static_cast<u32>(Kernel::VMAPermission::None); 281 memory_info->permission = static_cast<u32>(VMAPermission::None);
289 memory_info->size = 0; 282 memory_info->size = 0;
290 memory_info->type = static_cast<u32>(Kernel::MemoryState::Free); 283 memory_info->type = static_cast<u32>(MemoryState::Free);
291 } else { 284 } else {
292 memory_info->base_address = vma->second.base; 285 memory_info->base_address = vma->second.base;
293 memory_info->permission = static_cast<u32>(vma->second.permissions); 286 memory_info->permission = static_cast<u32>(vma->second.permissions);
@@ -302,25 +295,25 @@ static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* /*page_i
302/// Query memory 295/// Query memory
303static ResultCode QueryMemory(MemoryInfo* memory_info, PageInfo* page_info, VAddr addr) { 296static ResultCode QueryMemory(MemoryInfo* memory_info, PageInfo* page_info, VAddr addr) {
304 LOG_TRACE(Kernel_SVC, "called, addr=%llx", addr); 297 LOG_TRACE(Kernel_SVC, "called, addr=%llx", addr);
305 return QueryProcessMemory(memory_info, page_info, Kernel::CurrentProcess, addr); 298 return QueryProcessMemory(memory_info, page_info, CurrentProcess, addr);
306} 299}
307 300
308/// Exits the current process 301/// Exits the current process
309static void ExitProcess() { 302static void ExitProcess() {
310 LOG_INFO(Kernel_SVC, "Process %u exiting", Kernel::g_current_process->process_id); 303 LOG_INFO(Kernel_SVC, "Process %u exiting", g_current_process->process_id);
311 304
312 ASSERT_MSG(Kernel::g_current_process->status == Kernel::ProcessStatus::Running, 305 ASSERT_MSG(g_current_process->status == ProcessStatus::Running,
313 "Process has already exited"); 306 "Process has already exited");
314 307
315 Kernel::g_current_process->status = Kernel::ProcessStatus::Exited; 308 g_current_process->status = ProcessStatus::Exited;
316 309
317 // Stop all the process threads that are currently waiting for objects. 310 // Stop all the process threads that are currently waiting for objects.
318 auto& thread_list = Kernel::GetThreadList(); 311 auto& thread_list = GetThreadList();
319 for (auto& thread : thread_list) { 312 for (auto& thread : thread_list) {
320 if (thread->owner_process != Kernel::g_current_process) 313 if (thread->owner_process != g_current_process)
321 continue; 314 continue;
322 315
323 if (thread == Kernel::GetCurrentThread()) 316 if (thread == GetCurrentThread())
324 continue; 317 continue;
325 318
326 // TODO(Subv): When are the other running/ready threads terminated? 319 // TODO(Subv): When are the other running/ready threads terminated?
@@ -332,7 +325,7 @@ static void ExitProcess() {
332 } 325 }
333 326
334 // Kill the current thread 327 // Kill the current thread
335 Kernel::GetCurrentThread()->Stop(); 328 GetCurrentThread()->Stop();
336 329
337 Core::System::GetInstance().PrepareReschedule(); 330 Core::System::GetInstance().PrepareReschedule();
338} 331}
@@ -343,17 +336,17 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V
343 std::string name = Common::StringFromFormat("unknown-%llx", entry_point); 336 std::string name = Common::StringFromFormat("unknown-%llx", entry_point);
344 337
345 if (priority > THREADPRIO_LOWEST) { 338 if (priority > THREADPRIO_LOWEST) {
346 return Kernel::ERR_OUT_OF_RANGE; 339 return ERR_OUT_OF_RANGE;
347 } 340 }
348 341
349 SharedPtr<Kernel::ResourceLimit>& resource_limit = Kernel::g_current_process->resource_limit; 342 SharedPtr<ResourceLimit>& resource_limit = g_current_process->resource_limit;
350 if (resource_limit->GetMaxResourceValue(Kernel::ResourceTypes::PRIORITY) > priority) { 343 if (resource_limit->GetMaxResourceValue(ResourceTypes::PRIORITY) > priority) {
351 return Kernel::ERR_NOT_AUTHORIZED; 344 return ERR_NOT_AUTHORIZED;
352 } 345 }
353 346
354 if (processor_id == THREADPROCESSORID_DEFAULT) { 347 if (processor_id == THREADPROCESSORID_DEFAULT) {
355 // Set the target CPU to the one specified in the process' exheader. 348 // Set the target CPU to the one specified in the process' exheader.
356 processor_id = Kernel::g_current_process->ideal_processor; 349 processor_id = g_current_process->ideal_processor;
357 ASSERT(processor_id != THREADPROCESSORID_DEFAULT); 350 ASSERT(processor_id != THREADPROCESSORID_DEFAULT);
358 } 351 }
359 352
@@ -374,14 +367,14 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V
374 break; 367 break;
375 } 368 }
376 369
377 CASCADE_RESULT(SharedPtr<Kernel::Thread> thread, 370 CASCADE_RESULT(SharedPtr<Thread> thread,
378 Kernel::Thread::Create(name, entry_point, priority, arg, processor_id, stack_top, 371 Thread::Create(name, entry_point, priority, arg, processor_id, stack_top,
379 Kernel::g_current_process)); 372 g_current_process));
380 373
381 thread->context.fpscr = 374 thread->context.fpscr =
382 FPSCR_DEFAULT_NAN | FPSCR_FLUSH_TO_ZERO | FPSCR_ROUND_TOZERO; // 0x03C00000 375 FPSCR_DEFAULT_NAN | FPSCR_FLUSH_TO_ZERO | FPSCR_ROUND_TOZERO; // 0x03C00000
383 376
384 CASCADE_RESULT(thread->guest_handle, Kernel::g_handle_table.Create(thread)); 377 CASCADE_RESULT(thread->guest_handle, g_handle_table.Create(thread));
385 *out_handle = thread->guest_handle; 378 *out_handle = thread->guest_handle;
386 379
387 Core::System::GetInstance().PrepareReschedule(); 380 Core::System::GetInstance().PrepareReschedule();
@@ -398,8 +391,8 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V
398static ResultCode StartThread(Handle thread_handle) { 391static ResultCode StartThread(Handle thread_handle) {
399 LOG_TRACE(Kernel_SVC, "called thread=0x%08X", thread_handle); 392 LOG_TRACE(Kernel_SVC, "called thread=0x%08X", thread_handle);
400 393
401 const SharedPtr<Kernel::Thread> thread = 394 const SharedPtr<Thread> thread =
402 Kernel::g_handle_table.Get<Kernel::Thread>(thread_handle); 395 g_handle_table.Get<Thread>(thread_handle);
403 if (!thread) { 396 if (!thread) {
404 return ERR_INVALID_HANDLE; 397 return ERR_INVALID_HANDLE;
405 } 398 }
@@ -413,7 +406,7 @@ static ResultCode StartThread(Handle thread_handle) {
413static void ExitThread() { 406static void ExitThread() {
414 LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::CPU().GetPC()); 407 LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::CPU().GetPC());
415 408
416 Kernel::ExitCurrentThread(); 409 ExitCurrentThread();
417 Core::System::GetInstance().PrepareReschedule(); 410 Core::System::GetInstance().PrepareReschedule();
418} 411}
419 412
@@ -423,14 +416,14 @@ static void SleepThread(s64 nanoseconds) {
423 416
424 // Don't attempt to yield execution if there are no available threads to run, 417 // Don't attempt to yield execution if there are no available threads to run,
425 // this way we avoid a useless reschedule to the idle thread. 418 // this way we avoid a useless reschedule to the idle thread.
426 if (nanoseconds == 0 && !Kernel::HaveReadyThreads()) 419 if (nanoseconds == 0 && !HaveReadyThreads())
427 return; 420 return;
428 421
429 // Sleep current thread and check for next thread to schedule 422 // Sleep current thread and check for next thread to schedule
430 Kernel::WaitCurrentThread_Sleep(); 423 WaitCurrentThread_Sleep();
431 424
432 // Create an event to wake the thread up after the specified nanosecond delay has passed 425 // Create an event to wake the thread up after the specified nanosecond delay has passed
433 Kernel::GetCurrentThread()->WakeAfterDelay(nanoseconds); 426 GetCurrentThread()->WakeAfterDelay(nanoseconds);
434 427
435 Core::System::GetInstance().PrepareReschedule(); 428 Core::System::GetInstance().PrepareReschedule();
436} 429}
@@ -442,9 +435,9 @@ static ResultCode SignalProcessWideKey(VAddr addr, u32 target) {
442} 435}
443 436
444/// Close a handle 437/// Close a handle
445static ResultCode CloseHandle(Kernel::Handle handle) { 438static ResultCode CloseHandle(Handle handle) {
446 LOG_TRACE(Kernel_SVC, "Closing handle 0x%08X", handle); 439 LOG_TRACE(Kernel_SVC, "Closing handle 0x%08X", handle);
447 return Kernel::g_handle_table.Close(handle); 440 return g_handle_table.Close(handle);
448} 441}
449 442
450namespace { 443namespace {
@@ -459,47 +452,47 @@ struct FunctionDef {
459 452
460static const FunctionDef SVC_Table[] = { 453static const FunctionDef SVC_Table[] = {
461 {0x00, nullptr, "Unknown"}, 454 {0x00, nullptr, "Unknown"},
462 {0x01, HLE::Wrap<SetHeapSize>, "svcSetHeapSize"}, 455 {0x01, SvcWrap<SetHeapSize>, "svcSetHeapSize"},
463 {0x02, nullptr, "svcSetMemoryPermission"}, 456 {0x02, nullptr, "svcSetMemoryPermission"},
464 {0x03, nullptr, "svcSetMemoryAttribute"}, 457 {0x03, nullptr, "svcSetMemoryAttribute"},
465 {0x04, HLE::Wrap<MapMemory>, "svcMapMemory"}, 458 {0x04, SvcWrap<MapMemory>, "svcMapMemory"},
466 {0x05, HLE::Wrap<UnmapMemory>, "svcUnmapMemory"}, 459 {0x05, SvcWrap<UnmapMemory>, "svcUnmapMemory"},
467 {0x06, HLE::Wrap<QueryMemory>, "svcQueryMemory"}, 460 {0x06, SvcWrap<QueryMemory>, "svcQueryMemory"},
468 {0x07, HLE::Wrap<ExitProcess>, "svcExitProcess"}, 461 {0x07, SvcWrap<ExitProcess>, "svcExitProcess"},
469 {0x08, HLE::Wrap<CreateThread>, "svcCreateThread"}, 462 {0x08, SvcWrap<CreateThread>, "svcCreateThread"},
470 {0x09, HLE::Wrap<StartThread>, "svcStartThread"}, 463 {0x09, SvcWrap<StartThread>, "svcStartThread"},
471 {0x0A, HLE::Wrap<ExitThread>, "svcExitThread"}, 464 {0x0A, SvcWrap<ExitThread>, "svcExitThread"},
472 {0x0B, HLE::Wrap<SleepThread>, "svcSleepThread"}, 465 {0x0B, SvcWrap<SleepThread>, "svcSleepThread"},
473 {0x0C, HLE::Wrap<GetThreadPriority>, "svcGetThreadPriority"}, 466 {0x0C, SvcWrap<GetThreadPriority>, "svcGetThreadPriority"},
474 {0x0D, HLE::Wrap<SetThreadPriority>, "svcSetThreadPriority"}, 467 {0x0D, SvcWrap<SetThreadPriority>, "svcSetThreadPriority"},
475 {0x0E, nullptr, "svcGetThreadCoreMask"}, 468 {0x0E, nullptr, "svcGetThreadCoreMask"},
476 {0x0F, nullptr, "svcSetThreadCoreMask"}, 469 {0x0F, nullptr, "svcSetThreadCoreMask"},
477 {0x10, HLE::Wrap<GetCurrentProcessorNumber>, "svcGetCurrentProcessorNumber"}, 470 {0x10, SvcWrap<GetCurrentProcessorNumber>, "svcGetCurrentProcessorNumber"},
478 {0x11, nullptr, "svcSignalEvent"}, 471 {0x11, nullptr, "svcSignalEvent"},
479 {0x12, nullptr, "svcClearEvent"}, 472 {0x12, nullptr, "svcClearEvent"},
480 {0x13, nullptr, "svcMapSharedMemory"}, 473 {0x13, nullptr, "svcMapSharedMemory"},
481 {0x14, nullptr, "svcUnmapSharedMemory"}, 474 {0x14, nullptr, "svcUnmapSharedMemory"},
482 {0x15, nullptr, "svcCreateTransferMemory"}, 475 {0x15, nullptr, "svcCreateTransferMemory"},
483 {0x16, HLE::Wrap<CloseHandle>, "svcCloseHandle"}, 476 {0x16, SvcWrap<CloseHandle>, "svcCloseHandle"},
484 {0x17, nullptr, "svcResetSignal"}, 477 {0x17, nullptr, "svcResetSignal"},
485 {0x18, HLE::Wrap<WaitSynchronization>, "svcWaitSynchronization"}, 478 {0x18, SvcWrap<WaitSynchronization>, "svcWaitSynchronization"},
486 {0x19, nullptr, "svcCancelSynchronization"}, 479 {0x19, nullptr, "svcCancelSynchronization"},
487 {0x1A, HLE::Wrap<LockMutex>, "svcLockMutex"}, 480 {0x1A, SvcWrap<LockMutex>, "svcLockMutex"},
488 {0x1B, HLE::Wrap<UnlockMutex>, "svcUnlockMutex"}, 481 {0x1B, SvcWrap<UnlockMutex>, "svcUnlockMutex"},
489 {0x1C, nullptr, "svcWaitProcessWideKeyAtomic"}, 482 {0x1C, nullptr, "svcWaitProcessWideKeyAtomic"},
490 {0x1D, HLE::Wrap<SignalProcessWideKey>, "svcSignalProcessWideKey"}, 483 {0x1D, SvcWrap<SignalProcessWideKey>, "svcSignalProcessWideKey"},
491 {0x1E, nullptr, "svcGetSystemTick"}, 484 {0x1E, nullptr, "svcGetSystemTick"},
492 {0x1F, HLE::Wrap<ConnectToPort>, "svcConnectToPort"}, 485 {0x1F, SvcWrap<ConnectToPort>, "svcConnectToPort"},
493 {0x20, nullptr, "svcSendSyncRequestLight"}, 486 {0x20, nullptr, "svcSendSyncRequestLight"},
494 {0x21, HLE::Wrap<SendSyncRequest>, "svcSendSyncRequest"}, 487 {0x21, SvcWrap<SendSyncRequest>, "svcSendSyncRequest"},
495 {0x22, nullptr, "svcSendSyncRequestWithUserBuffer"}, 488 {0x22, nullptr, "svcSendSyncRequestWithUserBuffer"},
496 {0x23, nullptr, "svcSendAsyncRequestWithUserBuffer"}, 489 {0x23, nullptr, "svcSendAsyncRequestWithUserBuffer"},
497 {0x24, HLE::Wrap<GetProcessId>, "svcGetProcessId"}, 490 {0x24, SvcWrap<GetProcessId>, "svcGetProcessId"},
498 {0x25, HLE::Wrap<GetThreadId>, "svcGetThreadId"}, 491 {0x25, SvcWrap<GetThreadId>, "svcGetThreadId"},
499 {0x26, HLE::Wrap<Break>, "svcBreak"}, 492 {0x26, SvcWrap<Break>, "svcBreak"},
500 {0x27, HLE::Wrap<OutputDebugString>, "svcOutputDebugString"}, 493 {0x27, SvcWrap<OutputDebugString>, "svcOutputDebugString"},
501 {0x28, nullptr, "svcReturnFromException"}, 494 {0x28, nullptr, "svcReturnFromException"},
502 {0x29, HLE::Wrap<GetInfo>, "svcGetInfo"}, 495 {0x29, SvcWrap<GetInfo>, "svcGetInfo"},
503 {0x2A, nullptr, "svcFlushEntireDataCache"}, 496 {0x2A, nullptr, "svcFlushEntireDataCache"},
504 {0x2B, nullptr, "svcFlushDataCache"}, 497 {0x2B, nullptr, "svcFlushDataCache"},
505 {0x2C, nullptr, "svcMapPhysicalMemory"}, 498 {0x2C, nullptr, "svcMapPhysicalMemory"},
@@ -616,4 +609,4 @@ void CallSVC(u32 immediate) {
616 } 609 }
617} 610}
618 611
619} // namespace SVC 612} // namespace Kernel
diff --git a/src/core/hle/svc.h b/src/core/hle/kernel/svc.h
index fd001a38e..b0265b6c8 100644
--- a/src/core/hle/svc.h
+++ b/src/core/hle/kernel/svc.h
@@ -1,4 +1,4 @@
1// Copyright 2014 Citra Emulator Project 1// Copyright 2018 Citra Emulator Project
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
@@ -6,8 +6,7 @@
6 6
7#include "common/common_types.h" 7#include "common/common_types.h"
8 8
9//////////////////////////////////////////////////////////////////////////////////////////////////// 9namespace Kernel {
10// SVC types
11 10
12struct MemoryInfo { 11struct MemoryInfo {
13 u64 base_address; 12 u64 base_address;
@@ -21,11 +20,6 @@ struct PageInfo {
21 u64 flags; 20 u64 flags;
22}; 21};
23 22
24////////////////////////////////////////////////////////////////////////////////////////////////////
25// Namespace SVC
26
27namespace SVC {
28
29/// Values accepted by svcGetInfo 23/// Values accepted by svcGetInfo
30enum class GetInfoType : u64 { 24enum class GetInfoType : u64 {
31 // 1.0.0+ 25 // 1.0.0+
@@ -41,4 +35,4 @@ enum class GetInfoType : u64 {
41 35
42void CallSVC(u32 immediate); 36void CallSVC(u32 immediate);
43 37
44} // namespace SVC 38} // namespace Kernel
diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/kernel/svc_wrap.h
index df2c3e843..65b64cb3c 100644
--- a/src/core/hle/function_wrappers.h
+++ b/src/core/hle/kernel/svc_wrap.h
@@ -1,4 +1,4 @@
1// Copyright 2017 Citra Emulator Project 1// Copyright 2018 Citra Emulator Project
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
@@ -7,11 +7,11 @@
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/kernel/svc.h"
10#include "core/hle/result.h" 11#include "core/hle/result.h"
11#include "core/hle/svc.h"
12#include "core/memory.h" 12#include "core/memory.h"
13 13
14namespace HLE { 14namespace Kernel {
15 15
16#define PARAM(n) Core::CPU().GetReg(n) 16#define PARAM(n) Core::CPU().GetReg(n)
17 17
@@ -27,22 +27,22 @@ static inline void FuncReturn(u64 res) {
27// Function wrappers that return type ResultCode 27// Function wrappers that return type ResultCode
28 28
29template <ResultCode func(u64)> 29template <ResultCode func(u64)>
30void Wrap() { 30void SvcWrap() {
31 FuncReturn(func(PARAM(0)).raw); 31 FuncReturn(func(PARAM(0)).raw);
32} 32}
33 33
34template <ResultCode func(u32)> 34template <ResultCode func(u32)>
35void Wrap() { 35void SvcWrap() {
36 FuncReturn(func((u32)PARAM(0)).raw); 36 FuncReturn(func((u32)PARAM(0)).raw);
37} 37}
38 38
39template <ResultCode func(u32, u32)> 39template <ResultCode func(u32, u32)>
40void Wrap() { 40void SvcWrap() {
41 FuncReturn(func((u32)PARAM(0), (u32)PARAM(1)).raw); 41 FuncReturn(func((u32)PARAM(0), (u32)PARAM(1)).raw);
42} 42}
43 43
44template <ResultCode func(u32*, u32)> 44template <ResultCode func(u32*, u32)>
45void Wrap() { 45void SvcWrap() {
46 u32 param_1 = 0; 46 u32 param_1 = 0;
47 u32 retval = func(&param_1, (u32)PARAM(1)).raw; 47 u32 retval = func(&param_1, (u32)PARAM(1)).raw;
48 Core::CPU().SetReg(1, param_1); 48 Core::CPU().SetReg(1, param_1);
@@ -50,7 +50,7 @@ void Wrap() {
50} 50}
51 51
52template <ResultCode func(u32*, u64)> 52template <ResultCode func(u32*, u64)>
53void Wrap() { 53void SvcWrap() {
54 u32 param_1 = 0; 54 u32 param_1 = 0;
55 u32 retval = func(&param_1, PARAM(1)).raw; 55 u32 retval = func(&param_1, PARAM(1)).raw;
56 Core::CPU().SetReg(1, param_1); 56 Core::CPU().SetReg(1, param_1);
@@ -58,12 +58,12 @@ void Wrap() {
58} 58}
59 59
60template <ResultCode func(u64, u32)> 60template <ResultCode func(u64, u32)>
61void Wrap() { 61void SvcWrap() {
62 FuncReturn(func(PARAM(0), (u32)PARAM(1)).raw); 62 FuncReturn(func(PARAM(0), (u32)PARAM(1)).raw);
63} 63}
64 64
65template <ResultCode func(u64*, u64)> 65template <ResultCode func(u64*, u64)>
66void Wrap() { 66void SvcWrap() {
67 u64 param_1 = 0; 67 u64 param_1 = 0;
68 u32 retval = func(&param_1, PARAM(1)).raw; 68 u32 retval = func(&param_1, PARAM(1)).raw;
69 Core::CPU().SetReg(1, param_1); 69 Core::CPU().SetReg(1, param_1);
@@ -71,22 +71,22 @@ void Wrap() {
71} 71}
72 72
73template <ResultCode func(u32, u64, u32)> 73template <ResultCode func(u32, u64, u32)>
74void Wrap() { 74void SvcWrap() {
75 FuncReturn(func((u32)PARAM(0), PARAM(1), (u32)PARAM(2)).raw); 75 FuncReturn(func((u32)PARAM(0), PARAM(1), (u32)PARAM(2)).raw);
76} 76}
77 77
78template <ResultCode func(u64, u64, u64)> 78template <ResultCode func(u64, u64, u64)>
79void Wrap() { 79void SvcWrap() {
80 FuncReturn(func(PARAM(0), PARAM(1), PARAM(2)).raw); 80 FuncReturn(func(PARAM(0), PARAM(1), PARAM(2)).raw);
81} 81}
82 82
83template <ResultCode func(u64, u64, s64)> 83template <ResultCode func(u64, u64, s64)>
84void Wrap() { 84void SvcWrap() {
85 FuncReturn(func(PARAM(1), PARAM(2), (s64)PARAM(3)).raw); 85 FuncReturn(func(PARAM(1), PARAM(2), (s64)PARAM(3)).raw);
86} 86}
87 87
88template <ResultCode func(u64*, u64, u64, u64)> 88template <ResultCode func(u64*, u64, u64, u64)>
89void Wrap() { 89void SvcWrap() {
90 u64 param_1 = 0; 90 u64 param_1 = 0;
91 u32 retval = func(&param_1, PARAM(1), PARAM(2), PARAM(3)).raw; 91 u32 retval = func(&param_1, PARAM(1), PARAM(2), PARAM(3)).raw;
92 Core::CPU().SetReg(1, param_1); 92 Core::CPU().SetReg(1, param_1);
@@ -94,7 +94,7 @@ void Wrap() {
94} 94}
95 95
96template <ResultCode func(u32*, u64, u64, u64, u32, s32)> 96template <ResultCode func(u32*, u64, u64, u64, u32, s32)>
97void Wrap() { 97void SvcWrap() {
98 u32 param_1 = 0; 98 u32 param_1 = 0;
99 u32 retval = 99 u32 retval =
100 func(&param_1, PARAM(1), PARAM(2), PARAM(3), (u32)PARAM(4), (s32)(PARAM(5) & 0xFFFFFFFF)) 100 func(&param_1, PARAM(1), PARAM(2), PARAM(3), (u32)PARAM(4), (s32)(PARAM(5) & 0xFFFFFFFF))
@@ -104,7 +104,7 @@ void Wrap() {
104} 104}
105 105
106template <ResultCode func(MemoryInfo*, PageInfo*, u64)> 106template <ResultCode func(MemoryInfo*, PageInfo*, u64)>
107void Wrap() { 107void SvcWrap() {
108 MemoryInfo memory_info = {}; 108 MemoryInfo memory_info = {};
109 PageInfo page_info = {}; 109 PageInfo page_info = {};
110 u32 retval = func(&memory_info, &page_info, PARAM(2)).raw; 110 u32 retval = func(&memory_info, &page_info, PARAM(2)).raw;
@@ -122,7 +122,7 @@ void Wrap() {
122// Function wrappers that return type u32 122// Function wrappers that return type u32
123 123
124template <u32 func()> 124template <u32 func()>
125void Wrap() { 125void SvcWrap() {
126 FuncReturn(func()); 126 FuncReturn(func());
127} 127}
128 128
@@ -130,26 +130,26 @@ void Wrap() {
130/// Function wrappers that return type void 130/// Function wrappers that return type void
131 131
132template <void func()> 132template <void func()>
133void Wrap() { 133void SvcWrap() {
134 func(); 134 func();
135} 135}
136 136
137template <void func(s64)> 137template <void func(s64)>
138void Wrap() { 138void SvcWrap() {
139 func((s64)PARAM(0)); 139 func((s64)PARAM(0));
140} 140}
141 141
142template <void func(u64, s32 len)> 142template <void func(u64, s32 len)>
143void Wrap() { 143void SvcWrap() {
144 func(PARAM(0), (s32)(PARAM(1) & 0xFFFFFFFF)); 144 func(PARAM(0), (s32)(PARAM(1) & 0xFFFFFFFF));
145} 145}
146 146
147template <void func(u64, u64, u64)> 147template <void func(u64, u64, u64)>
148void Wrap() { 148void SvcWrap() {
149 func(PARAM(0), PARAM(1), PARAM(2)); 149 func(PARAM(0), PARAM(1), PARAM(2));
150} 150}
151 151
152#undef PARAM 152#undef PARAM
153#undef FuncReturn 153#undef FuncReturn
154 154
155} // namespace HLE 155} // namespace Kernel