2014-04-11 01:58:28 +02:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 06:38:14 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-11-19 09:49:13 +01:00
|
|
|
// Refer to the license.txt file included.
|
2014-04-11 01:58:28 +02:00
|
|
|
|
2014-04-12 00:44:21 +02:00
|
|
|
#include <map>
|
2014-05-18 23:52:02 +02:00
|
|
|
|
2014-08-17 20:28:36 +02:00
|
|
|
#include "common/string_util.h"
|
2014-05-18 23:52:02 +02:00
|
|
|
#include "common/symbols.h"
|
2014-04-12 00:44:21 +02:00
|
|
|
|
2014-12-22 07:30:09 +01:00
|
|
|
#include "core/arm/arm_interface.h"
|
2014-04-18 05:05:31 +02:00
|
|
|
#include "core/mem_map.h"
|
|
|
|
|
2014-07-07 05:15:40 +02:00
|
|
|
#include "core/hle/kernel/address_arbiter.h"
|
2014-05-28 04:41:09 +02:00
|
|
|
#include "core/hle/kernel/event.h"
|
2014-05-21 04:57:54 +02:00
|
|
|
#include "core/hle/kernel/mutex.h"
|
2014-12-04 00:49:51 +01:00
|
|
|
#include "core/hle/kernel/semaphore.h"
|
2014-07-05 06:59:58 +02:00
|
|
|
#include "core/hle/kernel/shared_memory.h"
|
2014-05-17 19:47:44 +02:00
|
|
|
#include "core/hle/kernel/thread.h"
|
2014-12-04 20:45:47 +01:00
|
|
|
#include "core/hle/kernel/timer.h"
|
2014-05-17 19:47:44 +02:00
|
|
|
|
2014-04-11 01:58:28 +02:00
|
|
|
#include "core/hle/function_wrappers.h"
|
2014-10-23 05:20:01 +02:00
|
|
|
#include "core/hle/result.h"
|
2014-04-13 03:55:36 +02:00
|
|
|
#include "core/hle/service/service.h"
|
2014-04-11 01:58:28 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
2014-05-21 00:28:38 +02:00
|
|
|
// Namespace SVC
|
2014-04-11 01:58:28 +02:00
|
|
|
|
2014-05-21 00:28:38 +02:00
|
|
|
namespace SVC {
|
2014-04-11 05:26:12 +02:00
|
|
|
|
2014-04-25 05:56:06 +02:00
|
|
|
enum ControlMemoryOperation {
|
|
|
|
MEMORY_OPERATION_HEAP = 0x00000003,
|
|
|
|
MEMORY_OPERATION_GSP_HEAP = 0x00010003,
|
|
|
|
};
|
|
|
|
|
2014-04-18 05:05:31 +02:00
|
|
|
/// Map application or GSP heap memory
|
2014-11-17 04:58:39 +01:00
|
|
|
static Result ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 addr1, u32 size, u32 permissions) {
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_TRACE(Kernel_SVC,"called operation=0x%08X, addr0=0x%08X, addr1=0x%08X, size=%08X, permissions=0x%08X",
|
2014-05-07 05:34:20 +02:00
|
|
|
operation, addr0, addr1, size, permissions);
|
|
|
|
|
2014-04-18 05:05:31 +02:00
|
|
|
switch (operation) {
|
|
|
|
|
2014-04-25 05:56:06 +02:00
|
|
|
// Map normal heap memory
|
|
|
|
case MEMORY_OPERATION_HEAP:
|
2014-06-02 02:48:29 +02:00
|
|
|
*out_addr = Memory::MapBlock_Heap(size, operation, permissions);
|
2014-04-25 05:56:06 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Map GSP heap memory
|
|
|
|
case MEMORY_OPERATION_GSP_HEAP:
|
2014-11-23 04:35:45 +01:00
|
|
|
*out_addr = Memory::MapBlock_HeapLinear(size, operation, permissions);
|
2014-04-18 05:05:31 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Unknown ControlMemory operation
|
|
|
|
default:
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_ERROR(Kernel_SVC, "unknown operation=0x%08X", operation);
|
2014-04-18 05:05:31 +02:00
|
|
|
}
|
2014-04-25 05:56:06 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Maps a memory block to specified address
|
2014-11-17 04:58:39 +01:00
|
|
|
static Result MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 other_permissions) {
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_TRACE(Kernel_SVC, "called memblock=0x%08X, addr=0x%08X, mypermissions=0x%08X, otherpermission=%d",
|
2014-07-05 06:59:58 +02:00
|
|
|
handle, addr, permissions, other_permissions);
|
2014-07-05 16:22:03 +02:00
|
|
|
|
|
|
|
Kernel::MemoryPermission permissions_type = static_cast<Kernel::MemoryPermission>(permissions);
|
|
|
|
switch (permissions_type) {
|
|
|
|
case Kernel::MemoryPermission::Read:
|
|
|
|
case Kernel::MemoryPermission::Write:
|
|
|
|
case Kernel::MemoryPermission::ReadWrite:
|
2014-11-08 03:53:18 +01:00
|
|
|
case Kernel::MemoryPermission::Execute:
|
|
|
|
case Kernel::MemoryPermission::ReadExecute:
|
|
|
|
case Kernel::MemoryPermission::WriteExecute:
|
|
|
|
case Kernel::MemoryPermission::ReadWriteExecute:
|
2014-07-05 16:22:03 +02:00
|
|
|
case Kernel::MemoryPermission::DontCare:
|
2014-11-19 09:49:13 +01:00
|
|
|
Kernel::MapSharedMemory(handle, addr, permissions_type,
|
2014-07-05 16:22:03 +02:00
|
|
|
static_cast<Kernel::MemoryPermission>(other_permissions));
|
2014-04-25 05:56:06 +02:00
|
|
|
break;
|
|
|
|
default:
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_ERROR(Kernel_SVC, "unknown permissions=0x%08X", permissions);
|
2014-04-25 05:56:06 +02:00
|
|
|
}
|
2014-04-18 05:05:31 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-04-13 03:55:36 +02:00
|
|
|
/// Connect to an OS service given the port name, returns the handle to the port to out
|
2014-11-17 04:58:39 +01:00
|
|
|
static Result ConnectToPort(Handle* out, const char* port_name) {
|
2014-04-13 03:55:36 +02:00
|
|
|
Service::Interface* service = Service::g_manager->FetchFromPortName(port_name);
|
2014-06-02 02:48:29 +02:00
|
|
|
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_TRACE(Kernel_SVC, "called port_name=%s", port_name);
|
2014-06-06 06:35:49 +02:00
|
|
|
_assert_msg_(KERNEL, (service != nullptr), "called, but service is not implemented!");
|
2014-06-02 02:48:29 +02:00
|
|
|
|
|
|
|
*out = service->GetHandle();
|
|
|
|
|
2014-04-13 03:55:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Synchronize to an OS service
|
2014-11-17 04:58:39 +01:00
|
|
|
static Result SendSyncRequest(Handle handle) {
|
2014-12-14 00:16:13 +01:00
|
|
|
Kernel::Session* session = Kernel::g_handle_table.Get<Kernel::Session>(handle);
|
2014-12-14 06:30:11 +01:00
|
|
|
if (session == nullptr) {
|
2014-10-23 05:20:01 +02:00
|
|
|
return InvalidHandle(ErrorModule::Kernel).raw;
|
|
|
|
}
|
2014-05-27 04:12:46 +02:00
|
|
|
|
2014-12-14 06:30:11 +01:00
|
|
|
LOG_TRACE(Kernel_SVC, "called handle=0x%08X(%s)", handle, session->GetName().c_str());
|
2014-05-27 04:12:46 +02:00
|
|
|
|
2014-12-14 06:30:11 +01:00
|
|
|
ResultVal<bool> wait = session->SyncRequest();
|
2014-10-23 05:20:01 +02:00
|
|
|
if (wait.Succeeded() && *wait) {
|
2014-05-27 04:12:46 +02:00
|
|
|
Kernel::WaitCurrentThread(WAITTYPE_SYNCH); // TODO(bunnei): Is this correct?
|
|
|
|
}
|
|
|
|
|
2014-10-23 05:20:01 +02:00
|
|
|
return wait.Code().raw;
|
2014-04-11 01:58:28 +02:00
|
|
|
}
|
|
|
|
|
2014-04-17 02:41:33 +02:00
|
|
|
/// Close a handle
|
2014-11-17 04:58:39 +01:00
|
|
|
static Result CloseHandle(Handle handle) {
|
2014-04-17 02:41:33 +02:00
|
|
|
// ImplementMe
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_ERROR(Kernel_SVC, "(UNIMPLEMENTED) called handle=0x%08X", handle);
|
2014-04-17 02:41:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Wait for a handle to synchronize, timeout after the specified nanoseconds
|
2014-11-17 04:58:39 +01:00
|
|
|
static Result WaitSynchronization1(Handle handle, s64 nano_seconds) {
|
2014-05-28 04:41:09 +02:00
|
|
|
// TODO(bunnei): Do something with nano_seconds, currently ignoring this
|
2014-06-06 04:35:36 +02:00
|
|
|
bool wait_infinite = (nano_seconds == -1); // Used to wait until a thread has terminated
|
2014-05-28 04:41:09 +02:00
|
|
|
|
2014-12-21 13:04:08 +01:00
|
|
|
Kernel::Object* object = Kernel::g_handle_table.GetGeneric(handle);
|
|
|
|
if (object == nullptr)
|
2014-10-23 05:20:01 +02:00
|
|
|
return InvalidHandle(ErrorModule::Kernel).raw;
|
2014-05-28 04:41:09 +02:00
|
|
|
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_TRACE(Kernel_SVC, "called handle=0x%08X(%s:%s), nanoseconds=%lld", handle, object->GetTypeName().c_str(),
|
2014-08-18 05:03:22 +02:00
|
|
|
object->GetName().c_str(), nano_seconds);
|
2014-06-06 04:35:36 +02:00
|
|
|
|
2014-10-23 05:20:01 +02:00
|
|
|
ResultVal<bool> wait = object->WaitSynchronization();
|
2014-05-28 04:41:09 +02:00
|
|
|
|
2014-06-06 04:35:36 +02:00
|
|
|
// Check for next thread to schedule
|
2014-10-23 05:20:01 +02:00
|
|
|
if (wait.Succeeded() && *wait) {
|
2014-06-02 03:42:50 +02:00
|
|
|
HLE::Reschedule(__func__);
|
2014-05-28 04:41:09 +02:00
|
|
|
}
|
|
|
|
|
2014-10-23 05:20:01 +02:00
|
|
|
return wait.Code().raw;
|
2014-05-18 05:37:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Wait for the given handles to synchronize, timeout after the specified nanoseconds
|
2014-11-17 04:58:39 +01:00
|
|
|
static Result WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count, bool wait_all,
|
2014-05-28 04:41:09 +02:00
|
|
|
s64 nano_seconds) {
|
2014-12-04 20:45:47 +01:00
|
|
|
|
2014-05-28 04:41:09 +02:00
|
|
|
// TODO(bunnei): Do something with nano_seconds, currently ignoring this
|
|
|
|
bool unlock_all = true;
|
2014-06-06 04:35:36 +02:00
|
|
|
bool wait_infinite = (nano_seconds == -1); // Used to wait until a thread has terminated
|
2014-05-23 01:32:45 +02:00
|
|
|
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_TRACE(Kernel_SVC, "called handle_count=%d, wait_all=%s, nanoseconds=%lld",
|
2014-05-18 23:52:02 +02:00
|
|
|
handle_count, (wait_all ? "true" : "false"), nano_seconds);
|
2014-05-23 01:32:45 +02:00
|
|
|
|
2014-05-28 04:41:09 +02:00
|
|
|
// Iterate through each handle, synchronize kernel object
|
2014-06-07 05:31:29 +02:00
|
|
|
for (s32 i = 0; i < handle_count; i++) {
|
2014-12-21 13:04:08 +01:00
|
|
|
Kernel::Object* object = Kernel::g_handle_table.GetGeneric(handles[i]);
|
|
|
|
if (object == nullptr)
|
2014-10-23 05:20:01 +02:00
|
|
|
return InvalidHandle(ErrorModule::Kernel).raw;
|
2014-05-28 04:41:09 +02:00
|
|
|
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_TRACE(Kernel_SVC, "\thandle[%d] = 0x%08X(%s:%s)", i, handles[i], object->GetTypeName().c_str(),
|
2014-08-18 05:03:22 +02:00
|
|
|
object->GetName().c_str());
|
2014-05-30 02:24:51 +02:00
|
|
|
|
2014-10-23 05:20:01 +02:00
|
|
|
// TODO(yuriks): Verify how the real function behaves when an error happens here
|
|
|
|
ResultVal<bool> wait_result = object->WaitSynchronization();
|
|
|
|
bool wait = wait_result.Succeeded() && *wait_result;
|
2014-05-28 04:41:09 +02:00
|
|
|
|
|
|
|
if (!wait && !wait_all) {
|
2014-06-02 23:54:07 +02:00
|
|
|
*out = i;
|
2014-10-23 05:20:01 +02:00
|
|
|
return RESULT_SUCCESS.raw;
|
2014-05-28 04:41:09 +02:00
|
|
|
} else {
|
|
|
|
unlock_all = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wait_all && unlock_all) {
|
2014-06-02 23:54:07 +02:00
|
|
|
*out = handle_count;
|
2014-10-23 05:20:01 +02:00
|
|
|
return RESULT_SUCCESS.raw;
|
2014-05-18 23:52:02 +02:00
|
|
|
}
|
2014-05-28 04:41:09 +02:00
|
|
|
|
2014-06-02 03:42:50 +02:00
|
|
|
// Check for next thread to schedule
|
|
|
|
HLE::Reschedule(__func__);
|
2014-05-28 04:41:09 +02:00
|
|
|
|
2014-10-23 05:20:01 +02:00
|
|
|
return RESULT_SUCCESS.raw;
|
2014-04-17 02:41:33 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 00:50:36 +02:00
|
|
|
/// Create an address arbiter (to allocate access to shared resources)
|
2014-11-17 04:58:39 +01:00
|
|
|
static Result CreateAddressArbiter(u32* arbiter) {
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_TRACE(Kernel_SVC, "called");
|
2014-07-07 05:15:40 +02:00
|
|
|
Handle handle = Kernel::CreateAddressArbiter();
|
|
|
|
*arbiter = handle;
|
2014-05-02 00:50:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-30 02:24:51 +02:00
|
|
|
/// Arbitrate address
|
2014-11-17 04:58:39 +01:00
|
|
|
static Result ArbitrateAddress(Handle arbiter, u32 address, u32 type, u32 value, s64 nanoseconds) {
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_TRACE(Kernel_SVC, "called handle=0x%08X, address=0x%08X, type=0x%08X, value=0x%08X", arbiter,
|
2014-11-26 06:35:20 +01:00
|
|
|
address, type, value);
|
2014-10-23 05:20:01 +02:00
|
|
|
return Kernel::ArbitrateAddress(arbiter, static_cast<Kernel::ArbitrationType>(type),
|
|
|
|
address, value).raw;
|
2014-05-30 02:24:51 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 00:50:36 +02:00
|
|
|
/// Used to output a message on a debug hardware unit - does nothing on a retail unit
|
2014-11-17 04:58:39 +01:00
|
|
|
static void OutputDebugString(const char* string) {
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_DEBUG(Debug_Emulated, "%s", string);
|
2014-05-07 05:34:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Get resource limit
|
2014-11-17 04:58:39 +01:00
|
|
|
static Result GetResourceLimit(Handle* resource_limit, Handle process) {
|
2014-05-07 05:34:20 +02:00
|
|
|
// With regards to proceess values:
|
2014-11-19 09:49:13 +01:00
|
|
|
// 0xFFFF8001 is a handle alias for the current KProcess, and 0xFFFF8000 is a handle alias for
|
2014-05-07 05:34:20 +02:00
|
|
|
// the current KThread.
|
2014-06-02 02:48:29 +02:00
|
|
|
*resource_limit = 0xDEADBEEF;
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_ERROR(Kernel_SVC, "(UNIMPLEMENTED) called process=0x%08X", process);
|
2014-05-07 05:34:20 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get resource limit current values
|
2014-11-17 04:58:39 +01:00
|
|
|
static Result GetResourceLimitCurrentValues(s64* values, Handle resource_limit, void* names,
|
2014-05-30 05:26:58 +02:00
|
|
|
s32 name_count) {
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_ERROR(Kernel_SVC, "(UNIMPLEMENTED) called resource_limit=%08X, names=%s, name_count=%d",
|
2014-05-07 05:34:20 +02:00
|
|
|
resource_limit, names, name_count);
|
|
|
|
Memory::Write32(Core::g_app_core->GetReg(0), 0); // Normmatt: Set used memory to 0 for now
|
|
|
|
return 0;
|
2014-05-02 00:50:36 +02:00
|
|
|
}
|
|
|
|
|
2014-05-21 04:57:54 +02:00
|
|
|
/// Creates a new thread
|
2014-11-17 04:58:39 +01:00
|
|
|
static Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top, u32 processor_id) {
|
2014-05-17 19:47:44 +02:00
|
|
|
std::string name;
|
2014-05-16 00:25:56 +02:00
|
|
|
if (Symbols::HasSymbol(entry_point)) {
|
|
|
|
TSymbol symbol = Symbols::GetSymbol(entry_point);
|
2014-05-17 19:47:44 +02:00
|
|
|
name = symbol.name;
|
2014-05-16 00:25:56 +02:00
|
|
|
} else {
|
2014-09-07 20:50:43 +02:00
|
|
|
name = Common::StringFromFormat("unknown-%08x", entry_point);
|
2014-05-14 03:58:26 +02:00
|
|
|
}
|
2014-05-17 19:47:44 +02:00
|
|
|
|
2014-12-22 14:07:22 +01:00
|
|
|
ResultVal<Kernel::Thread*> thread_res = Kernel::Thread::Create(name.c_str(), entry_point, priority, arg,
|
|
|
|
processor_id, stack_top);
|
|
|
|
if (thread_res.Failed())
|
|
|
|
return thread_res.Code().raw;
|
|
|
|
Kernel::Thread* thread = *thread_res;
|
2014-05-21 05:36:35 +02:00
|
|
|
|
2014-12-22 14:07:22 +01:00
|
|
|
Core::g_app_core->SetReg(1, thread->GetHandle());
|
2014-05-22 03:41:40 +02:00
|
|
|
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_TRACE(Kernel_SVC, "called entrypoint=0x%08X (%s), arg=0x%08X, stacktop=0x%08X, "
|
2014-11-19 09:49:13 +01:00
|
|
|
"threadpriority=0x%08X, processorid=0x%08X : created handle=0x%08X", entry_point,
|
2014-12-22 14:07:22 +01:00
|
|
|
name.c_str(), arg, stack_top, priority, processor_id, thread->GetHandle());
|
2014-11-19 09:49:13 +01:00
|
|
|
|
2014-05-14 03:58:26 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-06 04:35:36 +02:00
|
|
|
/// Called when a thread exits
|
2014-12-22 14:07:22 +01:00
|
|
|
static void ExitThread() {
|
|
|
|
LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::g_app_core->GetPC());
|
2014-06-06 04:35:36 +02:00
|
|
|
|
2014-12-22 14:07:22 +01:00
|
|
|
Kernel::GetCurrentThread()->Stop(__func__);
|
2014-06-06 04:35:36 +02:00
|
|
|
HLE::Reschedule(__func__);
|
|
|
|
}
|
|
|
|
|
2014-06-02 04:12:54 +02:00
|
|
|
/// Gets the priority for the specified thread
|
2014-11-17 04:58:39 +01:00
|
|
|
static Result GetThreadPriority(s32* priority, Handle handle) {
|
2014-12-22 14:07:22 +01:00
|
|
|
const Kernel::Thread* thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
|
|
|
|
if (thread == nullptr)
|
|
|
|
return InvalidHandle(ErrorModule::Kernel).raw;
|
|
|
|
|
|
|
|
*priority = thread->GetPriority();
|
|
|
|
return RESULT_SUCCESS.raw;
|
2014-06-02 04:12:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Sets the priority for the specified thread
|
2014-11-17 04:58:39 +01:00
|
|
|
static Result SetThreadPriority(Handle handle, s32 priority) {
|
2014-12-22 14:07:22 +01:00
|
|
|
Kernel::Thread* thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
|
|
|
|
if (thread == nullptr)
|
|
|
|
return InvalidHandle(ErrorModule::Kernel).raw;
|
|
|
|
|
|
|
|
thread->SetPriority(priority);
|
|
|
|
return RESULT_SUCCESS.raw;
|
2014-06-02 04:12:54 +02:00
|
|
|
}
|
|
|
|
|
2014-05-21 04:57:54 +02:00
|
|
|
/// Create a mutex
|
2014-11-17 04:58:39 +01:00
|
|
|
static Result CreateMutex(Handle* mutex, u32 initial_locked) {
|
2014-06-02 02:48:29 +02:00
|
|
|
*mutex = Kernel::CreateMutex((initial_locked != 0));
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_TRACE(Kernel_SVC, "called initial_locked=%s : created handle=0x%08X",
|
2014-06-02 02:48:29 +02:00
|
|
|
initial_locked ? "true" : "false", *mutex);
|
2014-05-14 03:58:26 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-21 04:57:54 +02:00
|
|
|
/// Release a mutex
|
2014-11-17 04:58:39 +01:00
|
|
|
static Result ReleaseMutex(Handle handle) {
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_TRACE(Kernel_SVC, "called handle=0x%08X", handle);
|
2014-10-23 05:20:01 +02:00
|
|
|
ResultCode res = Kernel::ReleaseMutex(handle);
|
|
|
|
return res.raw;
|
2014-05-14 03:58:26 +02:00
|
|
|
}
|
|
|
|
|
2014-12-04 05:22:06 +01:00
|
|
|
/// Get the ID for the specified thread.
|
|
|
|
static Result GetThreadId(u32* thread_id, Handle handle) {
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle);
|
2014-12-22 14:07:22 +01:00
|
|
|
|
|
|
|
const Kernel::Thread* thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
|
|
|
|
if (thread == nullptr)
|
|
|
|
return InvalidHandle(ErrorModule::Kernel).raw;
|
|
|
|
|
|
|
|
*thread_id = thread->GetThreadId();
|
|
|
|
return RESULT_SUCCESS.raw;
|
2014-05-16 02:17:30 +02:00
|
|
|
}
|
|
|
|
|
2014-12-04 00:49:51 +01:00
|
|
|
/// Creates a semaphore
|
|
|
|
static Result CreateSemaphore(Handle* semaphore, s32 initial_count, s32 max_count) {
|
2014-12-04 17:40:36 +01:00
|
|
|
ResultCode res = Kernel::CreateSemaphore(semaphore, initial_count, max_count);
|
2014-12-13 19:43:01 +01:00
|
|
|
LOG_TRACE(Kernel_SVC, "called initial_count=%d, max_count=%d, created handle=0x%08X",
|
2014-12-04 00:49:51 +01:00
|
|
|
initial_count, max_count, *semaphore);
|
2014-12-04 17:40:36 +01:00
|
|
|
return res.raw;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Releases a certain number of slots in a semaphore
|
|
|
|
static Result ReleaseSemaphore(s32* count, Handle semaphore, s32 release_count) {
|
2014-12-13 19:43:01 +01:00
|
|
|
LOG_TRACE(Kernel_SVC, "called release_count=%d, handle=0x%08X", release_count, semaphore);
|
2014-12-04 17:40:36 +01:00
|
|
|
ResultCode res = Kernel::ReleaseSemaphore(count, semaphore, release_count);
|
|
|
|
return res.raw;
|
2014-12-04 00:49:51 +01:00
|
|
|
}
|
|
|
|
|
2014-05-21 04:57:54 +02:00
|
|
|
/// Query memory
|
2014-11-17 04:58:39 +01:00
|
|
|
static Result QueryMemory(void* info, void* out, u32 addr) {
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_ERROR(Kernel_SVC, "(UNIMPLEMENTED) called addr=0x%08X", addr);
|
2014-05-16 02:17:30 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-21 04:57:54 +02:00
|
|
|
/// Create an event
|
2014-11-17 04:58:39 +01:00
|
|
|
static Result CreateEvent(Handle* evt, u32 reset_type) {
|
2014-06-02 02:48:29 +02:00
|
|
|
*evt = Kernel::CreateEvent((ResetType)reset_type);
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X",
|
2014-06-02 02:48:29 +02:00
|
|
|
reset_type, *evt);
|
2014-05-18 23:52:02 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-27 02:55:48 +02:00
|
|
|
/// Duplicates a kernel handle
|
2014-11-17 04:58:39 +01:00
|
|
|
static Result DuplicateHandle(Handle* out, Handle handle) {
|
2014-12-21 13:04:08 +01:00
|
|
|
ResultVal<Handle> out_h = Kernel::g_handle_table.Duplicate(handle);
|
|
|
|
if (out_h.Succeeded()) {
|
|
|
|
*out = *out_h;
|
|
|
|
LOG_TRACE(Kernel_SVC, "duplicated 0x%08X to 0x%08X", handle, *out);
|
2014-06-02 04:12:54 +02:00
|
|
|
}
|
2014-12-21 13:04:08 +01:00
|
|
|
return out_h.Code().raw;
|
2014-05-27 02:55:48 +02:00
|
|
|
}
|
|
|
|
|
2014-06-06 04:35:36 +02:00
|
|
|
/// Signals an event
|
2014-11-17 04:58:39 +01:00
|
|
|
static Result SignalEvent(Handle evt) {
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_TRACE(Kernel_SVC, "called event=0x%08X", evt);
|
2014-10-23 05:20:01 +02:00
|
|
|
return Kernel::SignalEvent(evt).raw;
|
2014-06-06 04:35:36 +02:00
|
|
|
}
|
|
|
|
|
2014-05-30 02:24:51 +02:00
|
|
|
/// Clears an event
|
2014-11-17 04:58:39 +01:00
|
|
|
static Result ClearEvent(Handle evt) {
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_TRACE(Kernel_SVC, "called event=0x%08X", evt);
|
2014-10-23 05:20:01 +02:00
|
|
|
return Kernel::ClearEvent(evt).raw;
|
2014-05-30 02:24:51 +02:00
|
|
|
}
|
|
|
|
|
2014-12-04 20:45:47 +01:00
|
|
|
/// Creates a timer
|
|
|
|
static Result CreateTimer(Handle* handle, u32 reset_type) {
|
|
|
|
ResultCode res = Kernel::CreateTimer(handle, static_cast<ResetType>(reset_type));
|
|
|
|
LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X",
|
|
|
|
reset_type, *handle);
|
|
|
|
return res.raw;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Clears a timer
|
|
|
|
static Result ClearTimer(Handle handle) {
|
|
|
|
LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle);
|
|
|
|
return Kernel::ClearTimer(handle).raw;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Starts a timer
|
|
|
|
static Result SetTimer(Handle handle, s64 initial, s64 interval) {
|
|
|
|
LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle);
|
|
|
|
return Kernel::SetTimer(handle, initial, interval).raw;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Cancels a timer
|
|
|
|
static Result CancelTimer(Handle handle) {
|
|
|
|
LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle);
|
|
|
|
return Kernel::CancelTimer(handle).raw;
|
|
|
|
}
|
|
|
|
|
2014-06-01 16:37:19 +02:00
|
|
|
/// Sleep the current thread
|
2014-11-17 04:58:39 +01:00
|
|
|
static void SleepThread(s64 nanoseconds) {
|
2014-12-06 02:53:49 +01:00
|
|
|
LOG_TRACE(Kernel_SVC, "called nanoseconds=%lld", nanoseconds);
|
2014-11-26 06:34:14 +01:00
|
|
|
|
2014-12-20 08:32:19 +01:00
|
|
|
// Sleep current thread and check for next thread to schedule
|
|
|
|
Kernel::WaitCurrentThread(WAITTYPE_SLEEP);
|
2015-01-07 22:40:08 +01:00
|
|
|
|
|
|
|
// Create an event to wake the thread up after the specified nanosecond delay has passed
|
2014-12-22 14:07:22 +01:00
|
|
|
Kernel::WakeThreadAfterDelay(Kernel::GetCurrentThread(), nanoseconds);
|
2015-01-07 22:40:08 +01:00
|
|
|
|
2014-11-26 06:34:14 +01:00
|
|
|
HLE::Reschedule(__func__);
|
2014-06-01 16:37:19 +02:00
|
|
|
}
|
|
|
|
|
2014-08-15 02:01:02 +02:00
|
|
|
/// This returns the total CPU ticks elapsed since the CPU was powered-on
|
2014-11-17 04:58:39 +01:00
|
|
|
static s64 GetSystemTick() {
|
2014-08-15 02:01:02 +02:00
|
|
|
return (s64)Core::g_app_core->GetTicks();
|
|
|
|
}
|
|
|
|
|
2014-12-09 05:52:27 +01:00
|
|
|
/// Creates a memory block at the specified address with the specified permissions and size
|
|
|
|
static Result CreateMemoryBlock(Handle* memblock, u32 addr, u32 size, u32 my_permission,
|
|
|
|
u32 other_permission) {
|
|
|
|
|
|
|
|
// TODO(Subv): Implement this function
|
|
|
|
|
|
|
|
Handle shared_memory = Kernel::CreateSharedMemory();
|
|
|
|
*memblock = shared_memory;
|
|
|
|
LOG_WARNING(Kernel_SVC, "(STUBBED) called addr=0x%08X", addr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-21 00:28:38 +02:00
|
|
|
const HLE::FunctionDef SVC_Table[] = {
|
2014-06-10 04:30:39 +02:00
|
|
|
{0x00, nullptr, "Unknown"},
|
|
|
|
{0x01, HLE::Wrap<ControlMemory>, "ControlMemory"},
|
|
|
|
{0x02, HLE::Wrap<QueryMemory>, "QueryMemory"},
|
|
|
|
{0x03, nullptr, "ExitProcess"},
|
|
|
|
{0x04, nullptr, "GetProcessAffinityMask"},
|
|
|
|
{0x05, nullptr, "SetProcessAffinityMask"},
|
|
|
|
{0x06, nullptr, "GetProcessIdealProcessor"},
|
|
|
|
{0x07, nullptr, "SetProcessIdealProcessor"},
|
|
|
|
{0x08, HLE::Wrap<CreateThread>, "CreateThread"},
|
2014-12-22 14:07:22 +01:00
|
|
|
{0x09, ExitThread, "ExitThread"},
|
2014-06-10 04:30:39 +02:00
|
|
|
{0x0A, HLE::Wrap<SleepThread>, "SleepThread"},
|
|
|
|
{0x0B, HLE::Wrap<GetThreadPriority>, "GetThreadPriority"},
|
|
|
|
{0x0C, HLE::Wrap<SetThreadPriority>, "SetThreadPriority"},
|
|
|
|
{0x0D, nullptr, "GetThreadAffinityMask"},
|
|
|
|
{0x0E, nullptr, "SetThreadAffinityMask"},
|
|
|
|
{0x0F, nullptr, "GetThreadIdealProcessor"},
|
|
|
|
{0x10, nullptr, "SetThreadIdealProcessor"},
|
|
|
|
{0x11, nullptr, "GetCurrentProcessorNumber"},
|
|
|
|
{0x12, nullptr, "Run"},
|
|
|
|
{0x13, HLE::Wrap<CreateMutex>, "CreateMutex"},
|
|
|
|
{0x14, HLE::Wrap<ReleaseMutex>, "ReleaseMutex"},
|
2014-12-04 00:49:51 +01:00
|
|
|
{0x15, HLE::Wrap<CreateSemaphore>, "CreateSemaphore"},
|
2014-12-04 17:40:36 +01:00
|
|
|
{0x16, HLE::Wrap<ReleaseSemaphore>, "ReleaseSemaphore"},
|
2014-06-10 04:30:39 +02:00
|
|
|
{0x17, HLE::Wrap<CreateEvent>, "CreateEvent"},
|
|
|
|
{0x18, HLE::Wrap<SignalEvent>, "SignalEvent"},
|
|
|
|
{0x19, HLE::Wrap<ClearEvent>, "ClearEvent"},
|
2014-12-04 20:45:47 +01:00
|
|
|
{0x1A, HLE::Wrap<CreateTimer>, "CreateTimer"},
|
|
|
|
{0x1B, HLE::Wrap<SetTimer>, "SetTimer"},
|
|
|
|
{0x1C, HLE::Wrap<CancelTimer>, "CancelTimer"},
|
|
|
|
{0x1D, HLE::Wrap<ClearTimer>, "ClearTimer"},
|
2014-12-09 05:52:27 +01:00
|
|
|
{0x1E, HLE::Wrap<CreateMemoryBlock>, "CreateMemoryBlock"},
|
2014-06-10 04:30:39 +02:00
|
|
|
{0x1F, HLE::Wrap<MapMemoryBlock>, "MapMemoryBlock"},
|
|
|
|
{0x20, nullptr, "UnmapMemoryBlock"},
|
|
|
|
{0x21, HLE::Wrap<CreateAddressArbiter>, "CreateAddressArbiter"},
|
|
|
|
{0x22, HLE::Wrap<ArbitrateAddress>, "ArbitrateAddress"},
|
|
|
|
{0x23, HLE::Wrap<CloseHandle>, "CloseHandle"},
|
|
|
|
{0x24, HLE::Wrap<WaitSynchronization1>, "WaitSynchronization1"},
|
|
|
|
{0x25, HLE::Wrap<WaitSynchronizationN>, "WaitSynchronizationN"},
|
|
|
|
{0x26, nullptr, "SignalAndWait"},
|
|
|
|
{0x27, HLE::Wrap<DuplicateHandle>, "DuplicateHandle"},
|
2014-08-15 02:01:02 +02:00
|
|
|
{0x28, HLE::Wrap<GetSystemTick>, "GetSystemTick"},
|
2014-06-10 04:30:39 +02:00
|
|
|
{0x29, nullptr, "GetHandleInfo"},
|
|
|
|
{0x2A, nullptr, "GetSystemInfo"},
|
|
|
|
{0x2B, nullptr, "GetProcessInfo"},
|
|
|
|
{0x2C, nullptr, "GetThreadInfo"},
|
|
|
|
{0x2D, HLE::Wrap<ConnectToPort>, "ConnectToPort"},
|
|
|
|
{0x2E, nullptr, "SendSyncRequest1"},
|
|
|
|
{0x2F, nullptr, "SendSyncRequest2"},
|
|
|
|
{0x30, nullptr, "SendSyncRequest3"},
|
|
|
|
{0x31, nullptr, "SendSyncRequest4"},
|
|
|
|
{0x32, HLE::Wrap<SendSyncRequest>, "SendSyncRequest"},
|
|
|
|
{0x33, nullptr, "OpenProcess"},
|
|
|
|
{0x34, nullptr, "OpenThread"},
|
|
|
|
{0x35, nullptr, "GetProcessId"},
|
|
|
|
{0x36, nullptr, "GetProcessIdOfThread"},
|
|
|
|
{0x37, HLE::Wrap<GetThreadId>, "GetThreadId"},
|
|
|
|
{0x38, HLE::Wrap<GetResourceLimit>, "GetResourceLimit"},
|
|
|
|
{0x39, nullptr, "GetResourceLimitLimitValues"},
|
|
|
|
{0x3A, HLE::Wrap<GetResourceLimitCurrentValues>, "GetResourceLimitCurrentValues"},
|
|
|
|
{0x3B, nullptr, "GetThreadContext"},
|
|
|
|
{0x3C, nullptr, "Break"},
|
|
|
|
{0x3D, HLE::Wrap<OutputDebugString>, "OutputDebugString"},
|
|
|
|
{0x3E, nullptr, "ControlPerformanceCounter"},
|
|
|
|
{0x3F, nullptr, "Unknown"},
|
|
|
|
{0x40, nullptr, "Unknown"},
|
|
|
|
{0x41, nullptr, "Unknown"},
|
|
|
|
{0x42, nullptr, "Unknown"},
|
|
|
|
{0x43, nullptr, "Unknown"},
|
|
|
|
{0x44, nullptr, "Unknown"},
|
|
|
|
{0x45, nullptr, "Unknown"},
|
|
|
|
{0x46, nullptr, "Unknown"},
|
|
|
|
{0x47, nullptr, "CreatePort"},
|
|
|
|
{0x48, nullptr, "CreateSessionToPort"},
|
|
|
|
{0x49, nullptr, "CreateSession"},
|
|
|
|
{0x4A, nullptr, "AcceptSession"},
|
|
|
|
{0x4B, nullptr, "ReplyAndReceive1"},
|
|
|
|
{0x4C, nullptr, "ReplyAndReceive2"},
|
|
|
|
{0x4D, nullptr, "ReplyAndReceive3"},
|
|
|
|
{0x4E, nullptr, "ReplyAndReceive4"},
|
|
|
|
{0x4F, nullptr, "ReplyAndReceive"},
|
|
|
|
{0x50, nullptr, "BindInterrupt"},
|
|
|
|
{0x51, nullptr, "UnbindInterrupt"},
|
|
|
|
{0x52, nullptr, "InvalidateProcessDataCache"},
|
|
|
|
{0x53, nullptr, "StoreProcessDataCache"},
|
|
|
|
{0x54, nullptr, "FlushProcessDataCache"},
|
|
|
|
{0x55, nullptr, "StartInterProcessDma"},
|
|
|
|
{0x56, nullptr, "StopDma"},
|
|
|
|
{0x57, nullptr, "GetDmaState"},
|
|
|
|
{0x58, nullptr, "RestartDma"},
|
|
|
|
{0x59, nullptr, "Unknown"},
|
|
|
|
{0x5A, nullptr, "Unknown"},
|
|
|
|
{0x5B, nullptr, "Unknown"},
|
|
|
|
{0x5C, nullptr, "Unknown"},
|
|
|
|
{0x5D, nullptr, "Unknown"},
|
|
|
|
{0x5E, nullptr, "Unknown"},
|
|
|
|
{0x5F, nullptr, "Unknown"},
|
|
|
|
{0x60, nullptr, "DebugActiveProcess"},
|
|
|
|
{0x61, nullptr, "BreakDebugProcess"},
|
|
|
|
{0x62, nullptr, "TerminateDebugProcess"},
|
|
|
|
{0x63, nullptr, "GetProcessDebugEvent"},
|
|
|
|
{0x64, nullptr, "ContinueDebugEvent"},
|
|
|
|
{0x65, nullptr, "GetProcessList"},
|
|
|
|
{0x66, nullptr, "GetThreadList"},
|
|
|
|
{0x67, nullptr, "GetDebugThreadContext"},
|
|
|
|
{0x68, nullptr, "SetDebugThreadContext"},
|
|
|
|
{0x69, nullptr, "QueryDebugProcessMemory"},
|
|
|
|
{0x6A, nullptr, "ReadProcessMemory"},
|
|
|
|
{0x6B, nullptr, "WriteProcessMemory"},
|
|
|
|
{0x6C, nullptr, "SetHardwareBreakPoint"},
|
|
|
|
{0x6D, nullptr, "GetDebugThreadParam"},
|
|
|
|
{0x6E, nullptr, "Unknown"},
|
|
|
|
{0x6F, nullptr, "Unknown"},
|
|
|
|
{0x70, nullptr, "ControlProcessMemory"},
|
|
|
|
{0x71, nullptr, "MapProcessMemory"},
|
|
|
|
{0x72, nullptr, "UnmapProcessMemory"},
|
|
|
|
{0x73, nullptr, "Unknown"},
|
|
|
|
{0x74, nullptr, "Unknown"},
|
|
|
|
{0x75, nullptr, "Unknown"},
|
|
|
|
{0x76, nullptr, "TerminateProcess"},
|
|
|
|
{0x77, nullptr, "Unknown"},
|
|
|
|
{0x78, nullptr, "CreateResourceLimit"},
|
|
|
|
{0x79, nullptr, "Unknown"},
|
|
|
|
{0x7A, nullptr, "Unknown"},
|
|
|
|
{0x7B, nullptr, "Unknown"},
|
|
|
|
{0x7C, nullptr, "KernelSetState"},
|
|
|
|
{0x7D, nullptr, "QueryProcessMemory"},
|
2014-04-11 01:58:28 +02:00
|
|
|
};
|
|
|
|
|
2014-04-12 00:44:21 +02:00
|
|
|
void Register() {
|
2014-05-21 00:28:38 +02:00
|
|
|
HLE::RegisterModule("SVC_Table", ARRAY_SIZE(SVC_Table), SVC_Table);
|
2014-04-11 01:58:28 +02:00
|
|
|
}
|
2014-04-12 00:44:21 +02:00
|
|
|
|
|
|
|
} // namespace
|