From 15d2ab1b33e8ef579d15bb6f20e6c625a58fb166 Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 26 May 2014 20:55:48 -0400 Subject: [PATCH 01/44] svc: added stub for DuplicateHandle SVC call --- src/core/hle/svc.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 90c05cb74..0c647b86f 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -226,6 +226,13 @@ Result CreateEvent(void* _event, u32 reset_type) { return 0; } +/// Duplicates a kernel handle +Result DuplicateHandle(void* _out, Handle handle) { + Handle* out = (Handle*)_out; + DEBUG_LOG(SVC, "(UNIMPLEMENTED) DuplicateHandle called handle=0x%08X", handle); + return 0; +} + const HLE::FunctionDef SVC_Table[] = { {0x00, NULL, "Unknown"}, {0x01, WrapI_VUUUUU, "ControlMemory"}, @@ -266,7 +273,7 @@ const HLE::FunctionDef SVC_Table[] = { {0x24, WrapI_US64, "WaitSynchronization1"}, {0x25, WrapI_VVUUS64, "WaitSynchronizationN"}, {0x26, NULL, "SignalAndWait"}, - {0x27, NULL, "DuplicateHandle"}, + {0x27, WrapI_VU, "DuplicateHandle"}, {0x28, NULL, "GetSystemTick"}, {0x29, NULL, "GetHandleInfo"}, {0x2A, NULL, "GetSystemInfo"}, From d73d782ba7ea6f3f2dd9c4f70d34c1004397dacb Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 26 May 2014 21:01:27 -0400 Subject: [PATCH 02/44] kernel: add a SyncRequest method to KernelObject for use with svcSendSyncRequest --- src/core/hle/kernel/kernel.h | 1 + src/core/hle/kernel/mutex.cpp | 5 +++++ src/core/hle/kernel/thread.cpp | 5 +++++ src/core/hle/service/srv.h | 6 ------ 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 7cd79c2c4..046d583cb 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -42,6 +42,7 @@ public: virtual const char *GetTypeName() { return "[BAD KERNEL OBJECT TYPE]"; } virtual const char *GetName() { return "[UNKNOWN KERNEL OBJECT]"; } virtual Kernel::HandleType GetHandleType() const = 0; + virtual Result SyncRequest() = 0; }; class ObjectPool : NonCopyable { diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp index 019efbc78..fa924404d 100644 --- a/src/core/hle/kernel/mutex.cpp +++ b/src/core/hle/kernel/mutex.cpp @@ -23,6 +23,11 @@ public: bool locked; ///< Current locked state Handle lock_thread; ///< Handle to thread that currently has mutex std::vector waiting_threads; ///< Threads that are waiting for the mutex + + /// Synchronize kernel object + Result SyncRequest() { + return 0; + } }; //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index bf4c8353c..b9dd9fac4 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -36,6 +36,11 @@ public: inline bool IsWaiting() const { return (status & THREADSTATUS_WAIT) != 0; } inline bool IsSuspended() const { return (status & THREADSTATUS_SUSPEND) != 0; } + /// Synchronize kernel object + Result SyncRequest() { + return 0; + } + ThreadContext context; u32 status; diff --git a/src/core/hle/service/srv.h b/src/core/hle/service/srv.h index 1e35032ba..81109a2a8 100644 --- a/src/core/hle/service/srv.h +++ b/src/core/hle/service/srv.h @@ -26,12 +26,6 @@ public: return "srv:"; } - /** - * Called when svcSendSyncRequest is called, loads command buffer and executes comand - * @return Return result of svcSendSyncRequest passed back to user app - */ - Result Sync(); - }; } // namespace From 9f7ed2d027462b6f2f9e1cb96eb586419f5351a8 Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 26 May 2014 21:17:10 -0400 Subject: [PATCH 03/44] svc: changed SendSyncRequest to use Kernel::Object SyncRequest (instead of just service Interface class) --- src/core/hle/svc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 0c647b86f..ac016a966 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -96,8 +96,8 @@ Result ConnectToPort(void* out, const char* port_name) { /// Synchronize to an OS service Result SendSyncRequest(Handle handle) { DEBUG_LOG(SVC, "SendSyncRequest called handle=0x%08X"); - Service::Interface* service = Service::g_manager->FetchFromHandle(handle); - service->Sync(); + Kernel::Object* object = Kernel::g_object_pool.GetFast(handle); + object->SyncRequest(); return 0; } From 96b21055249ade8a36f8117e4e22ea2a8a10707b Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 26 May 2014 21:55:55 -0400 Subject: [PATCH 04/44] srv: added a real mutex for GetProcSemaphore (instead of stubbed) --- src/core/hle/service/srv.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core/hle/service/srv.cpp b/src/core/hle/service/srv.cpp index ff6da8f1c..7bbc03bf6 100644 --- a/src/core/hle/service/srv.cpp +++ b/src/core/hle/service/srv.cpp @@ -5,21 +5,28 @@ #include "core/hle/hle.h" #include "core/hle/service/srv.h" #include "core/hle/service/service.h" - +#include "core/hle/kernel/mutex.h" //////////////////////////////////////////////////////////////////////////////////////////////////// // Namespace SRV namespace SRV { +Handle g_mutex = 0; + void Initialize(Service::Interface* self) { - NOTICE_LOG(OSHLE, "SRV::Sync - Initialize"); + DEBUG_LOG(OSHLE, "SRV::Initialize called"); + if (!g_mutex) { + g_mutex = Kernel::CreateMutex(false); + } } void GetProcSemaphore(Service::Interface* self) { + DEBUG_LOG(OSHLE, "SRV::GetProcSemaphore called"); // Get process semaphore? u32* cmd_buff = Service::GetCommandBuffer(); - cmd_buff[3] = 0xDEADBEEF; // Return something... 0 == NULL, raises an exception + cmd_buff[1] = 0; // No error + cmd_buff[3] = g_mutex; // Return something... 0 == NULL, raises an exception } void GetServiceHandle(Service::Interface* self) { From 3d7693f75f4a599d0da4a23dea0ec1a0578da0e1 Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 26 May 2014 21:56:23 -0400 Subject: [PATCH 05/44] kernel: added enum for known CurrentThread and CurrentProcess handles --- src/core/hle/kernel/kernel.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 046d583cb..786d3abf3 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -11,6 +11,11 @@ typedef s32 Result; namespace Kernel { +enum KernelHandle { + CurrentThread = 0xFFFF8000, + CurrentProcess = 0xFFFF8001, +}; + enum class HandleType : u32 { Unknown = 0, Port = 1, From 16fea415d09e3c1e55667a6affab495e03117f96 Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 26 May 2014 21:56:51 -0400 Subject: [PATCH 06/44] service: Renamed Sync to SyncRequest --- src/core/hle/service/service.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index 716669bed..c970ace4b 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -79,7 +79,7 @@ public: * Called when svcSendSyncRequest is called, loads command buffer and executes comand * @return Return result of svcSendSyncRequest passed back to user app */ - Result Sync() { + Result SyncRequest() { u32* cmd_buff = GetCommandBuffer(); auto itr = m_functions.find(cmd_buff[0]); From 6e51c56fe41c3ff38db3a13e8773a9e9b2103377 Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 26 May 2014 21:57:10 -0400 Subject: [PATCH 07/44] svc: added some assertions --- src/core/hle/svc.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index ac016a966..6f72a6eb7 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -84,19 +84,17 @@ Result MapMemoryBlock(Handle memblock, u32 addr, u32 mypermissions, u32 otherper /// Connect to an OS service given the port name, returns the handle to the port to out Result ConnectToPort(void* out, const char* port_name) { Service::Interface* service = Service::g_manager->FetchFromPortName(port_name); - if (service) { - Core::g_app_core->SetReg(1, service->GetHandle()); - } else { - PanicYesNo("ConnectToPort called port_name=%s, but it is not implemented!", port_name); - } DEBUG_LOG(SVC, "ConnectToPort called port_name=%s", port_name); + _assert_msg_(KERNEL, service, "ConnectToPort called, but service is not implemented!"); + Core::g_app_core->SetReg(1, service->GetHandle()); return 0; } /// Synchronize to an OS service Result SendSyncRequest(Handle handle) { - DEBUG_LOG(SVC, "SendSyncRequest called handle=0x%08X"); Kernel::Object* object = Kernel::g_object_pool.GetFast(handle); + DEBUG_LOG(SVC, "SendSyncRequest called handle=0x%08X"); + _assert_msg_(KERNEL, object, "SendSyncRequest called, but kernel object is NULL!"); object->SyncRequest(); return 0; } From 58a3adcdd2eed9d31cd441186af872a0a8924e73 Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 26 May 2014 22:12:46 -0400 Subject: [PATCH 08/44] kernel: updated SyncRequest to take boolean thread wait result as a parameter --- src/core/hle/kernel/kernel.h | 9 ++++++++- src/core/hle/kernel/mutex.cpp | 8 ++++++-- src/core/hle/kernel/thread.cpp | 8 ++++++-- src/core/hle/service/service.h | 7 ++++--- src/core/hle/svc.cpp | 11 +++++++++-- 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 786d3abf3..4acc9f220 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -47,7 +47,14 @@ public: virtual const char *GetTypeName() { return "[BAD KERNEL OBJECT TYPE]"; } virtual const char *GetName() { return "[UNKNOWN KERNEL OBJECT]"; } virtual Kernel::HandleType GetHandleType() const = 0; - virtual Result SyncRequest() = 0; + + /** + * Synchronize kernel object + * @param wait Boolean wait set if current thread should wait as a result of sync operation + * @return Result of operation, 0 on success, otherwise error code + */ + virtual Result SyncRequest(bool* wait) = 0; + }; class ObjectPool : NonCopyable { diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp index fa924404d..5465b7a3c 100644 --- a/src/core/hle/kernel/mutex.cpp +++ b/src/core/hle/kernel/mutex.cpp @@ -24,8 +24,12 @@ public: Handle lock_thread; ///< Handle to thread that currently has mutex std::vector waiting_threads; ///< Threads that are waiting for the mutex - /// Synchronize kernel object - Result SyncRequest() { + /** + * Synchronize kernel object + * @param wait Boolean wait set if current thread should wait as a result of sync operation + * @return Result of operation, 0 on success, otherwise error code + */ + Result SyncRequest(bool* wait) { return 0; } }; diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index b9dd9fac4..56c7755cf 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -36,8 +36,12 @@ public: inline bool IsWaiting() const { return (status & THREADSTATUS_WAIT) != 0; } inline bool IsSuspended() const { return (status & THREADSTATUS_SUSPEND) != 0; } - /// Synchronize kernel object - Result SyncRequest() { + /** + * Synchronize kernel object + * @param wait Boolean wait set if current thread should wait as a result of sync operation + * @return Result of operation, 0 on success, otherwise error code + */ + Result SyncRequest(bool* wait) { return 0; } diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index c970ace4b..12ef51b91 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -76,10 +76,11 @@ public: } /** - * Called when svcSendSyncRequest is called, loads command buffer and executes comand - * @return Return result of svcSendSyncRequest passed back to user app + * Synchronize kernel object + * @param wait Boolean wait set if current thread should wait as a result of sync operation + * @return Result of operation, 0 on success, otherwise error code */ - Result SyncRequest() { + Result SyncRequest(bool* wait) { u32* cmd_buff = GetCommandBuffer(); auto itr = m_functions.find(cmd_buff[0]); diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 6f72a6eb7..e566036e5 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -92,11 +92,18 @@ Result ConnectToPort(void* out, const char* port_name) { /// Synchronize to an OS service Result SendSyncRequest(Handle handle) { + bool wait = false; Kernel::Object* object = Kernel::g_object_pool.GetFast(handle); + DEBUG_LOG(SVC, "SendSyncRequest called handle=0x%08X"); _assert_msg_(KERNEL, object, "SendSyncRequest called, but kernel object is NULL!"); - object->SyncRequest(); - return 0; + + Result res = object->SyncRequest(&wait); + if (wait) { + Kernel::WaitCurrentThread(WAITTYPE_SYNCH); // TODO(bunnei): Is this correct? + } + + return res; } /// Close a handle From a432dc8f39a866b7b523235d6d94531f93bb4aa1 Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 26 May 2014 22:17:49 -0400 Subject: [PATCH 09/44] kernel: added WaitSynchronization method to Kernel::Object --- src/core/hle/kernel/kernel.h | 7 +++++++ src/core/hle/kernel/mutex.cpp | 11 +++++++++++ src/core/hle/kernel/thread.cpp | 11 +++++++++++ src/core/hle/service/service.h | 10 ++++++++++ 4 files changed, 39 insertions(+) diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 4acc9f220..620cd2d73 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -55,6 +55,13 @@ public: */ virtual Result SyncRequest(bool* wait) = 0; + /** + * Wait for kernel object to synchronize + * @param wait Boolean wait set if current thread should wait as a result of sync operation + * @return Result of operation, 0 on success, otherwise error code + */ + virtual Result WaitSynchronization(bool* wait) = 0; + }; class ObjectPool : NonCopyable { diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp index 5465b7a3c..17fd40acd 100644 --- a/src/core/hle/kernel/mutex.cpp +++ b/src/core/hle/kernel/mutex.cpp @@ -30,6 +30,17 @@ public: * @return Result of operation, 0 on success, otherwise error code */ Result SyncRequest(bool* wait) { + // TODO(bunnei): ImplementMe + return 0; + } + + /** + * Wait for kernel object to synchronize + * @param wait Boolean wait set if current thread should wait as a result of sync operation + * @return Result of operation, 0 on success, otherwise error code + */ + Result WaitSynchronization(bool* wait) { + // TODO(bunnei): ImplementMe return 0; } }; diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 56c7755cf..6e8b53eb1 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -42,6 +42,17 @@ public: * @return Result of operation, 0 on success, otherwise error code */ Result SyncRequest(bool* wait) { + // TODO(bunnei): ImplementMe + return 0; + } + + /** + * Wait for kernel object to synchronize + * @param wait Boolean wait set if current thread should wait as a result of sync operation + * @return Result of operation, 0 on success, otherwise error code + */ + Result WaitSynchronization(bool* wait) { + // TODO(bunnei): ImplementMe return 0; } diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index 12ef51b91..4671d4528 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -100,6 +100,16 @@ public: return 0; // TODO: Implement return from actual function } + /** + * Wait for kernel object to synchronize + * @param wait Boolean wait set if current thread should wait as a result of sync operation + * @return Result of operation, 0 on success, otherwise error code + */ + Result WaitSynchronization(bool* wait) { + // TODO(bunnei): ImplementMe + return 0; + } + protected: /** From 93cd5a069122e86605ce2c15347e9498ceda2cc4 Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 26 May 2014 22:47:47 -0400 Subject: [PATCH 10/44] mutex: added additional docstrings --- src/core/hle/kernel/mutex.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/hle/kernel/mutex.h b/src/core/hle/kernel/mutex.h index 871e2e562..8a9309069 100644 --- a/src/core/hle/kernel/mutex.h +++ b/src/core/hle/kernel/mutex.h @@ -13,6 +13,7 @@ namespace Kernel { /** * Releases a mutex * @param handle Handle to mutex to release + * @return Result of operation, 0 on success, otherwise error code */ Result ReleaseMutex(Handle handle); @@ -20,6 +21,7 @@ Result ReleaseMutex(Handle handle); * Creates a mutex * @param handle Reference to handle for the newly created mutex * @param initial_locked Specifies if the mutex should be locked initially + * @return Handle to newly created object */ Handle CreateMutex(bool initial_locked); From d493d725acfc431fcbed729bb28d9b8a19250f96 Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 26 May 2014 22:49:11 -0400 Subject: [PATCH 11/44] mutex: removed docstring comment that is no longer relevant --- src/core/hle/kernel/mutex.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core/hle/kernel/mutex.h b/src/core/hle/kernel/mutex.h index 8a9309069..4cd266725 100644 --- a/src/core/hle/kernel/mutex.h +++ b/src/core/hle/kernel/mutex.h @@ -19,7 +19,6 @@ Result ReleaseMutex(Handle handle); /** * Creates a mutex - * @param handle Reference to handle for the newly created mutex * @param initial_locked Specifies if the mutex should be locked initially * @return Handle to newly created object */ From fd69fd03259b71be521aeb69d3f73761b598be8a Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 27 May 2014 20:16:13 -0400 Subject: [PATCH 12/44] kernel: added event module to support creation of CTR "Event" objects --- src/core/core.vcxproj | 2 + src/core/core.vcxproj.filters | 6 +++ src/core/hle/kernel/event.cpp | 91 +++++++++++++++++++++++++++++++++++ src/core/hle/kernel/event.h | 28 +++++++++++ 4 files changed, 127 insertions(+) create mode 100644 src/core/hle/kernel/event.cpp create mode 100644 src/core/hle/kernel/event.h diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index f271d336e..efcd30d77 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -168,6 +168,7 @@ + @@ -217,6 +218,7 @@ + diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index b6c1d5b93..135e4c89c 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -165,6 +165,9 @@ arm\interpreter + + hle\kernel + @@ -295,6 +298,9 @@ hle\kernel + + hle\kernel + diff --git a/src/core/hle/kernel/event.cpp b/src/core/hle/kernel/event.cpp new file mode 100644 index 000000000..cc15ba9bc --- /dev/null +++ b/src/core/hle/kernel/event.cpp @@ -0,0 +1,91 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include +#include + +#include "common/common.h" + +#include "core/hle/kernel/kernel.h" +#include "core/hle/kernel/event.h" + +namespace Kernel { + +class Event : public Object { +public: + const char* GetTypeName() { return "Event"; } + + static Kernel::HandleType GetStaticHandleType() { return Kernel::HandleType::Event; } + Kernel::HandleType GetHandleType() const { return Kernel::HandleType::Event; } + + ResetType intitial_reset_type; ///< ResetType specified at Event initialization + ResetType reset_type; ///< Current ResetType + + bool locked; ///< Current locked state + + /** + * Synchronize kernel object + * @param wait Boolean wait set if current thread should wait as a result of sync operation + * @return Result of operation, 0 on success, otherwise error code + */ + Result SyncRequest(bool* wait) { + // TODO(bunnei): ImplementMe + ERROR_LOG(KERNEL, "Unimplemented function Event::SyncRequest"); + return 0; + } + + /** + * Wait for kernel object to synchronize + * @param wait Boolean wait set if current thread should wait as a result of sync operation + * @return Result of operation, 0 on success, otherwise error code + */ + Result WaitSynchronization(bool* wait) { + // TODO(bunnei): ImplementMe + *wait = locked; + if (reset_type != RESETTYPE_STICKY) { + locked = true; + } + return 0; + } +}; + +/** + * Clears an event + * @param handle Handle to event to clear + * @return Result of operation, 0 on success, otherwise error code + */ +Result ClearEvent(Handle handle) { + ERROR_LOG(KERNEL, "Unimplemented function ClearEvent"); + return 0; +} + +/** + * Creates an event + * @param handle Reference to handle for the newly created mutex + * @param reset_type ResetType describing how to create event + * @return Handle to newly created object + */ +Event* CreateEvent(Handle& handle, const ResetType reset_type) { + Event* evt = new Event; + + handle = Kernel::g_object_pool.Create(evt); + + evt->reset_type = evt->intitial_reset_type = reset_type; + evt->locked = false; + + return evt; +} + +/** + * Creates an event + * @param reset_type ResetType describing how to create event + * @return Handle to newly created object + */ +Handle CreateEvent(const ResetType reset_type) { + Handle handle; + Event* evt = CreateEvent(handle, reset_type); + return handle; +} + +} // namespace diff --git a/src/core/hle/kernel/event.h b/src/core/hle/kernel/event.h new file mode 100644 index 000000000..2ef1bd65b --- /dev/null +++ b/src/core/hle/kernel/event.h @@ -0,0 +1,28 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_types.h" + +#include "core/hle/kernel/kernel.h" +#include "core/hle/svc.h" + +namespace Kernel { + +/** + * Clears an event + * @param handle Handle to event to clear + * @return Result of operation, 0 on success, otherwise error code + */ +Result ClearEvent(Handle handle); + +/** + * Creates an event + * @param reset_type ResetType describing how to create event + * @return Handle to newly created object + */ +Handle CreateEvent(const ResetType reset_type); + +} // namespace From beea6f054ae0bd40d1a564aa586735b81f2bf662 Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 27 May 2014 22:14:00 -0400 Subject: [PATCH 13/44] event: added SetEventLocked method to change status an events lock --- src/core/hle/kernel/event.cpp | 11 +++++++++++ src/core/hle/kernel/event.h | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/src/core/hle/kernel/event.cpp b/src/core/hle/kernel/event.cpp index cc15ba9bc..e85f39f0d 100644 --- a/src/core/hle/kernel/event.cpp +++ b/src/core/hle/kernel/event.cpp @@ -50,6 +50,17 @@ public: } }; +/** + * Changes whether an event is locked or not + * @param handle Handle to event to change + * @param locked Boolean locked value to set event + */ +void SetEventLocked(const Handle handle, const bool locked) { + Event* evt = g_object_pool.GetFast(handle); + evt->locked = locked; + return; +} + /** * Clears an event * @param handle Handle to event to clear diff --git a/src/core/hle/kernel/event.h b/src/core/hle/kernel/event.h index 2ef1bd65b..0bcfe00b7 100644 --- a/src/core/hle/kernel/event.h +++ b/src/core/hle/kernel/event.h @@ -11,6 +11,13 @@ namespace Kernel { +/** + * Changes whether an event is locked or not + * @param handle Handle to event to change + * @param locked Boolean locked value to set event + */ +void SetEventLocked(const Handle handle, const bool locked) + /** * Clears an event * @param handle Handle to event to clear From ea8627d5360eedaa10c979854ad9b4dd3b85f800 Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 27 May 2014 22:14:38 -0400 Subject: [PATCH 14/44] event: fixed typos and updated CMakeLists --- src/core/CMakeLists.txt | 1 + src/core/hle/kernel/event.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 6ad308798..468e6a631 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -34,6 +34,7 @@ set(SRCS core.cpp hle/config_mem.cpp hle/coprocessor.cpp hle/svc.cpp + hle/kernel/event.cpp hle/kernel/kernel.cpp hle/kernel/mutex.cpp hle/kernel/thread.cpp diff --git a/src/core/hle/kernel/event.h b/src/core/hle/kernel/event.h index 0bcfe00b7..c1842cb88 100644 --- a/src/core/hle/kernel/event.h +++ b/src/core/hle/kernel/event.h @@ -16,7 +16,7 @@ namespace Kernel { * @param handle Handle to event to change * @param locked Boolean locked value to set event */ -void SetEventLocked(const Handle handle, const bool locked) +void SetEventLocked(const Handle handle, const bool locked); /** * Clears an event From 94b30e8a3875346888fb7d0d36b9145cbed34836 Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 27 May 2014 22:29:11 -0400 Subject: [PATCH 15/44] APT_U: added event creation to Initialize method --- src/core/hle/service/apt.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/core/hle/service/apt.cpp b/src/core/hle/service/apt.cpp index 32759a087..67c53529a 100644 --- a/src/core/hle/service/apt.cpp +++ b/src/core/hle/service/apt.cpp @@ -6,6 +6,7 @@ #include "common/common.h" #include "core/hle/hle.h" +#include "core/hle/kernel/event.h" #include "core/hle/kernel/mutex.h" #include "core/hle/service/apt.h" @@ -15,7 +16,16 @@ namespace APT_U { void Initialize(Service::Interface* self) { - NOTICE_LOG(OSHLE, "APT_U::Sync - Initialize"); + u32* cmd_buff = Service::GetCommandBuffer(); + DEBUG_LOG(KERNEL, "APT_U::Sync - Initialize"); + + cmd_buff[3] = Kernel::CreateEvent(RESETTYPE_ONESHOT); // APT menu event handle + cmd_buff[4] = Kernel::CreateEvent(RESETTYPE_ONESHOT); // APT pause event handle + + Kernel::SetEventLocked(cmd_buff[3], true); + Kernel::SetEventLocked(cmd_buff[4], false); // Fire start event + + cmd_buff[1] = 0; // No error } void GetLockHandle(Service::Interface* self) { From 47e781e80a4bc0f37eb431a89aa36b27224185e7 Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 27 May 2014 22:41:09 -0400 Subject: [PATCH 16/44] svc: implemented WaitSynchronization1, WaitSynchronizationN, and CreateEvent --- src/core/hle/svc.cpp | 68 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index e566036e5..8468c4fab 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -9,6 +9,7 @@ #include "core/mem_map.h" +#include "core/hle/kernel/event.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/mutex.h" #include "core/hle/kernel/thread.h" @@ -16,7 +17,6 @@ #include "core/hle/function_wrappers.h" #include "core/hle/svc.h" #include "core/hle/service/service.h" -#include "core/hle/kernel/thread.h" //////////////////////////////////////////////////////////////////////////////////////////////////// // Namespace SVC @@ -95,7 +95,7 @@ Result SendSyncRequest(Handle handle) { bool wait = false; Kernel::Object* object = Kernel::g_object_pool.GetFast(handle); - DEBUG_LOG(SVC, "SendSyncRequest called handle=0x%08X"); + DEBUG_LOG(SVC, "SendSyncRequest called handle=0x%08X", handle); _assert_msg_(KERNEL, object, "SendSyncRequest called, but kernel object is NULL!"); Result res = object->SyncRequest(&wait); @@ -115,24 +115,62 @@ Result CloseHandle(Handle handle) { /// Wait for a handle to synchronize, timeout after the specified nanoseconds Result WaitSynchronization1(Handle handle, s64 nano_seconds) { - DEBUG_LOG(SVC, "(UNIMPLEMENTED) WaitSynchronization1 called handle=0x%08X, nanoseconds=%d", - handle, nano_seconds); - Kernel::WaitCurrentThread(WAITTYPE_SYNCH); // TODO(bunnei): Is this correct? - return 0; + // TODO(bunnei): Do something with nano_seconds, currently ignoring this + bool wait = false; + + Kernel::Object* object = Kernel::g_object_pool.GetFast(handle); + + DEBUG_LOG(SVC, "WaitSynchronization1 called handle=0x%08X, nanoseconds=%d", handle, + nano_seconds); + _assert_msg_(KERNEL, object, "WaitSynchronization1 called, but kernel object is NULL!"); + + Result res = object->WaitSynchronization(&wait); + + if (wait) { + Kernel::WaitCurrentThread(WAITTYPE_SYNCH); // TODO(bunnei): Is this correct? + } + + return res; } /// Wait for the given handles to synchronize, timeout after the specified nanoseconds -Result WaitSynchronizationN(void* _out, void* _handles, u32 handle_count, u32 wait_all, s64 nano_seconds) { +Result WaitSynchronizationN(void* _out, void* _handles, u32 handle_count, u32 wait_all, + s64 nano_seconds) { + // TODO(bunnei): Do something with nano_seconds, currently ignoring this + s32* out = (s32*)_out; Handle* handles = (Handle*)_handles; + bool unlock_all = true; - DEBUG_LOG(SVC, "(UNIMPLEMENTED) WaitSynchronizationN called handle_count=%d, wait_all=%s, nanoseconds=%d %s", + DEBUG_LOG(SVC, "WaitSynchronizationN called handle_count=%d, wait_all=%s, nanoseconds=%d", handle_count, (wait_all ? "true" : "false"), nano_seconds); + // Iterate through each handle, synchronize kernel object for (u32 i = 0; i < handle_count; i++) { - DEBUG_LOG(SVC, "\thandle[%d]=0x%08X", i, handles[i]); + bool wait = false; + Kernel::Object* object = Kernel::g_object_pool.GetFast(handles[i]); // 0 handle + + _assert_msg_(KERNEL, object, "WaitSynchronizationN called handle=0x%08X, but kernel object " + "is NULL!", handles[i]); + + Result res = object->WaitSynchronization(&wait); + + if (!wait && !wait_all) { + Core::g_app_core->SetReg(1, i); + return 0; + } else { + unlock_all = false; + } } + + if (wait_all && unlock_all) { + Core::g_app_core->SetReg(1, handle_count); + return 0; + } + + // Set current thread to wait state if not all handles were unlocked Kernel::WaitCurrentThread(WAITTYPE_SYNCH); // TODO(bunnei): Is this correct? + return 0; } @@ -195,16 +233,17 @@ Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top, u32 p /// Create a mutex Result CreateMutex(void* _mutex, u32 initial_locked) { Handle* mutex = (Handle*)_mutex; - *mutex = Kernel::CreateMutex((initial_locked != 0)); - Core::g_app_core->SetReg(1, *mutex); DEBUG_LOG(SVC, "CreateMutex called initial_locked=%s : created handle 0x%08X", initial_locked ? "true" : "false", *mutex); + *mutex = Kernel::CreateMutex((initial_locked != 0)); + Core::g_app_core->SetReg(1, *mutex); return 0; } /// Release a mutex Result ReleaseMutex(Handle handle) { DEBUG_LOG(SVC, "ReleaseMutex called handle=0x%08X", handle); + _assert_msg_(KERNEL, handle, "ReleaseMutex called, but handle is NULL!"); Kernel::ReleaseMutex(handle); return 0; } @@ -225,9 +264,10 @@ Result QueryMemory(void *_info, void *_out, u32 addr) { /// Create an event Result CreateEvent(void* _event, u32 reset_type) { - Handle* event = (Handle*)_event; - DEBUG_LOG(SVC, "(UNIMPLEMENTED) CreateEvent called reset_type=0x%08X", reset_type); - Core::g_app_core->SetReg(1, 0xBADC0DE0); + Handle* evt = (Handle*)_event; + DEBUG_LOG(SVC, "CreateEvent called reset_type=0x%08X", reset_type); + *evt = Kernel::CreateEvent((ResetType)reset_type); + Core::g_app_core->SetReg(1, *evt); return 0; } From 2ed6652f100fdbc5ad7d72a0602dc2c99ef79cce Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 27 May 2014 22:42:16 -0400 Subject: [PATCH 17/44] mutex: added preliminary SyncRequest/WaitSynchronization, added some comments/assertions --- src/core/hle/kernel/mutex.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp index 17fd40acd..23c064571 100644 --- a/src/core/hle/kernel/mutex.cpp +++ b/src/core/hle/kernel/mutex.cpp @@ -31,6 +31,7 @@ public: */ Result SyncRequest(bool* wait) { // TODO(bunnei): ImplementMe + locked = true; return 0; } @@ -41,6 +42,7 @@ public: */ Result WaitSynchronization(bool* wait) { // TODO(bunnei): ImplementMe + *wait = locked; return 0; } }; @@ -111,6 +113,9 @@ bool ReleaseMutex(Mutex* mutex) { */ Result ReleaseMutex(Handle handle) { Mutex* mutex = Kernel::g_object_pool.GetFast(handle); + + _assert_msg_(KERNEL, mutex, "ReleaseMutex tried to release a NULL mutex!"); + if (!ReleaseMutex(mutex)) { return -1; } @@ -121,6 +126,7 @@ Result ReleaseMutex(Handle handle) { * Creates a mutex * @param handle Reference to handle for the newly created mutex * @param initial_locked Specifies if the mutex should be locked initially + * @return Pointer to new Mutex object */ Mutex* CreateMutex(Handle& handle, bool initial_locked) { Mutex* mutex = new Mutex; From 3972d4ca8ba82a1e344e1255b0c113751d4b9f59 Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 27 May 2014 23:56:08 -0400 Subject: [PATCH 18/44] APT_U: added stubbed function for APT_U::Enable, fixed some log messages to be more consistent --- src/core/hle/service/apt.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core/hle/service/apt.cpp b/src/core/hle/service/apt.cpp index 67c53529a..ae040562c 100644 --- a/src/core/hle/service/apt.cpp +++ b/src/core/hle/service/apt.cpp @@ -17,7 +17,7 @@ namespace APT_U { void Initialize(Service::Interface* self) { u32* cmd_buff = Service::GetCommandBuffer(); - DEBUG_LOG(KERNEL, "APT_U::Sync - Initialize"); + DEBUG_LOG(KERNEL, "APT_U::Initialize called"); cmd_buff[3] = Kernel::CreateEvent(RESETTYPE_ONESHOT); // APT menu event handle cmd_buff[4] = Kernel::CreateEvent(RESETTYPE_ONESHOT); // APT pause event handle @@ -33,13 +33,20 @@ void GetLockHandle(Service::Interface* self) { u32 flags = cmd_buff[1]; // TODO(bunnei): Figure out the purpose of the flag field cmd_buff[1] = 0; // No error cmd_buff[5] = Kernel::CreateMutex(false); - DEBUG_LOG(KERNEL, "APT_U::GetLockHandle called : created handle 0x%08X", cmd_buff[5]); + DEBUG_LOG(KERNEL, "APT_U::GetLockHandle called handle=0x%08X", cmd_buff[5]); +} + +void Enable(Service::Interface* self) { + u32* cmd_buff = Service::GetCommandBuffer(); + u32 unk = cmd_buff[1]; // TODO(bunnei): What is this field used for? + cmd_buff[1] = 0; // No error + ERROR_LOG(KERNEL, "(UNIMPEMENTED) APT_U::Enable called unk=0x%08X", unk); } const Interface::FunctionInfo FunctionTable[] = { {0x00010040, GetLockHandle, "GetLockHandle"}, {0x00020080, Initialize, "Initialize"}, - {0x00030040, NULL, "Enable"}, + {0x00030040, Enable, "Enable"}, {0x00040040, NULL, "Finalize"}, {0x00050040, NULL, "GetAppletManInfo"}, {0x00060040, NULL, "GetAppletInfo"}, From 70af9d620b8c1ebbc203c3601aad7c746fddff76 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 28 May 2014 18:39:28 -0400 Subject: [PATCH 19/44] service: changed interface to return 0 (no error) when a service method is unimplemented - hack to make apps boot further --- src/core/hle/service/service.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index 4671d4528..4a3d4c68a 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -87,12 +87,12 @@ public: if (itr == m_functions.end()) { ERROR_LOG(OSHLE, "Unknown/unimplemented function: port = %s, command = 0x%08X!", GetPortName(), cmd_buff[0]); - return -1; + return 0; // TODO(bunnei): Hack - ignore error } if (itr->second.func == NULL) { ERROR_LOG(OSHLE, "Unimplemented function: port = %s, name = %s!", GetPortName(), itr->second.name.c_str()); - return -1; + return 0; // TODO(bunnei): Hack - ignore error } itr->second.func(this); From 46aef01d0431253a4aa17b31b85cb35603a036ec Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 28 May 2014 21:19:13 -0400 Subject: [PATCH 20/44] lcd: moved kFrameTicks to lcd.h for use in other modules --- src/core/hw/lcd.cpp | 2 -- src/core/hw/lcd.h | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/hw/lcd.cpp b/src/core/hw/lcd.cpp index b57563a73..6cbce14ed 100644 --- a/src/core/hw/lcd.cpp +++ b/src/core/hw/lcd.cpp @@ -17,8 +17,6 @@ namespace LCD { Registers g_regs; -static const u32 kFrameTicks = 268123480 / 60; ///< 268MHz / 60 frames per second - u64 g_last_ticks = 0; ///< Last CPU ticks /** diff --git a/src/core/hw/lcd.h b/src/core/hw/lcd.h index 2dd3b4adc..41baa51d0 100644 --- a/src/core/hw/lcd.h +++ b/src/core/hw/lcd.h @@ -8,6 +8,8 @@ namespace LCD { +static const u32 kFrameTicks = 268123480 / 60; ///< 268MHz / 60 frames per second + struct Registers { u32 framebuffer_top_left_1; u32 framebuffer_top_left_2; From 9fd5d6c7d81053e05b3b4218bdee2575cd1f3fd0 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 28 May 2014 21:20:00 -0400 Subject: [PATCH 21/44] hle: removed PARAM64 macro (this was incorrect), made several bug fixes accordingly for decoding U64 function parameters --- src/core/hle/function_wrappers.h | 4 ++-- src/core/hle/hle.h | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h index 24cc74fc6..d31fab298 100644 --- a/src/core/hle/function_wrappers.h +++ b/src/core/hle/function_wrappers.h @@ -750,11 +750,11 @@ template void WrapI_VUUUUU(){ } template void WrapI_US64() { - int retval = func(PARAM(0), PARAM64(1)); + int retval = func(PARAM(0), ((PARAM(3) << 32) | PARAM(2))); RETURN(retval); } template void WrapI_VVUUS64() { - int retval = func(Memory::GetPointer(PARAM(0)), Memory::GetPointer(PARAM(1)), PARAM(2), PARAM(3), PARAM(4)); + int retval = func(Memory::GetPointer(PARAM(5)), Memory::GetPointer(PARAM(1)), PARAM(2), PARAM(3), ((PARAM(4) << 32) | PARAM(0))); RETURN(retval); } diff --git a/src/core/hle/hle.h b/src/core/hle/hle.h index c075147c3..c31e273b5 100644 --- a/src/core/hle/hle.h +++ b/src/core/hle/hle.h @@ -10,7 +10,6 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// #define PARAM(n) Core::g_app_core->GetReg(n) -#define PARAM64(n) (Core::g_app_core->GetReg(n) | ((u64)Core::g_app_core->GetReg(n + 1) << 32)) #define RETURN(n) Core::g_app_core->SetReg(0, n) //////////////////////////////////////////////////////////////////////////////////////////////////// From c4b5168b453ed2738bac61e05810fd4f5b95217d Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 28 May 2014 22:03:10 -0400 Subject: [PATCH 22/44] hle: properly cast 64-bit function wrapper parameters to (u64) --- src/core/hle/function_wrappers.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h index d31fab298..7b07d8ca8 100644 --- a/src/core/hle/function_wrappers.h +++ b/src/core/hle/function_wrappers.h @@ -750,11 +750,11 @@ template void WrapI_VUUUUU(){ } template void WrapI_US64() { - int retval = func(PARAM(0), ((PARAM(3) << 32) | PARAM(2))); + int retval = func(PARAM(0), (((u64)PARAM(3) << 32) | PARAM(2))); RETURN(retval); } template void WrapI_VVUUS64() { - int retval = func(Memory::GetPointer(PARAM(5)), Memory::GetPointer(PARAM(1)), PARAM(2), PARAM(3), ((PARAM(4) << 32) | PARAM(0))); + int retval = func(Memory::GetPointer(PARAM(5)), Memory::GetPointer(PARAM(1)), PARAM(2), PARAM(3), (((u64)PARAM(4) << 32) | PARAM(0))); RETURN(retval); } From 4b4a6de1d810c9e274eb1f9978f5fb006c9346f9 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 28 May 2014 23:33:24 -0400 Subject: [PATCH 23/44] apt: added stubbed function for InquireNotification --- src/core/hle/service/apt.cpp | 164 ++++++++++++++++++----------------- 1 file changed, 86 insertions(+), 78 deletions(-) diff --git a/src/core/hle/service/apt.cpp b/src/core/hle/service/apt.cpp index ae040562c..f2118ba03 100644 --- a/src/core/hle/service/apt.cpp +++ b/src/core/hle/service/apt.cpp @@ -43,85 +43,93 @@ void Enable(Service::Interface* self) { ERROR_LOG(KERNEL, "(UNIMPEMENTED) APT_U::Enable called unk=0x%08X", unk); } +void InquireNotification(Service::Interface* self) { + u32* cmd_buff = Service::GetCommandBuffer(); + u32 app_id = cmd_buff[2]; + cmd_buff[1] = 0; // No error + cmd_buff[3] = 0; // Signal type + ERROR_LOG(KERNEL, "(UNIMPEMENTED) APT_U::InquireNotification called app_id=0x%08X", app_id); +} + const Interface::FunctionInfo FunctionTable[] = { - {0x00010040, GetLockHandle, "GetLockHandle"}, - {0x00020080, Initialize, "Initialize"}, - {0x00030040, Enable, "Enable"}, - {0x00040040, NULL, "Finalize"}, - {0x00050040, NULL, "GetAppletManInfo"}, - {0x00060040, NULL, "GetAppletInfo"}, - {0x00070000, NULL, "GetLastSignaledAppletId"}, - {0x00080000, NULL, "CountRegisteredApplet"}, - {0x00090040, NULL, "IsRegistered"}, - {0x000A0040, NULL, "GetAttribute"}, - {0x000B0040, NULL, "InquireNotification"}, - {0x000C0104, NULL, "SendParameter"}, - {0x000D0080, NULL, "ReceiveParameter"}, - {0x000E0080, NULL, "GlanceParameter"}, - {0x000F0100, NULL, "CancelParameter"}, - {0x001000C2, NULL, "DebugFunc"}, - {0x001100C0, NULL, "MapProgramIdForDebug"}, - {0x00120040, NULL, "SetHomeMenuAppletIdForDebug"}, - {0x00130000, NULL, "GetPreparationState"}, - {0x00140040, NULL, "SetPreparationState"}, - {0x00150140, NULL, "PrepareToStartApplication"}, - {0x00160040, NULL, "PreloadLibraryApplet"}, - {0x00170040, NULL, "FinishPreloadingLibraryApplet"}, - {0x00180040, NULL, "PrepareToStartLibraryApplet"}, - {0x00190040, NULL, "PrepareToStartSystemApplet"}, - {0x001A0000, NULL, "PrepareToStartNewestHomeMenu"}, - {0x001B00C4, NULL, "StartApplication"}, - {0x001C0000, NULL, "WakeupApplication"}, - {0x001D0000, NULL, "CancelApplication"}, - {0x001E0084, NULL, "StartLibraryApplet"}, - {0x001F0084, NULL, "StartSystemApplet"}, - {0x00200044, NULL, "StartNewestHomeMenu"}, - {0x00210000, NULL, "OrderToCloseApplication"}, - {0x00220040, NULL, "PrepareToCloseApplication"}, - {0x00230040, NULL, "PrepareToJumpToApplication"}, - {0x00240044, NULL, "JumpToApplication"}, - {0x002500C0, NULL, "PrepareToCloseLibraryApplet"}, - {0x00260000, NULL, "PrepareToCloseSystemApplet"}, - {0x00270044, NULL, "CloseApplication"}, - {0x00280044, NULL, "CloseLibraryApplet"}, - {0x00290044, NULL, "CloseSystemApplet"}, - {0x002A0000, NULL, "OrderToCloseSystemApplet"}, - {0x002B0000, NULL, "PrepareToJumpToHomeMenu"}, - {0x002C0044, NULL, "JumpToHomeMenu"}, - {0x002D0000, NULL, "PrepareToLeaveHomeMenu"}, - {0x002E0044, NULL, "LeaveHomeMenu"}, - {0x002F0040, NULL, "PrepareToLeaveResidentApplet"}, - {0x00300044, NULL, "LeaveResidentApplet"}, - {0x00310100, NULL, "PrepareToDoApplicationJump"}, - {0x00320084, NULL, "DoApplicationJump"}, - {0x00330000, NULL, "GetProgramIdOnApplicationJump"}, - {0x00340084, NULL, "SendDeliverArg"}, - {0x00350080, NULL, "ReceiveDeliverArg"}, - {0x00360040, NULL, "LoadSysMenuArg"}, - {0x00370042, NULL, "StoreSysMenuArg"}, - {0x00380040, NULL, "PreloadResidentApplet"}, - {0x00390040, NULL, "PrepareToStartResidentApplet"}, - {0x003A0044, NULL, "StartResidentApplet"}, - {0x003B0040, NULL, "CancelLibraryApplet"}, - {0x003C0042, NULL, "SendDspSleep"}, - {0x003D0042, NULL, "SendDspWakeUp"}, - {0x003E0080, NULL, "ReplySleepQuery"}, - {0x003F0040, NULL, "ReplySleepNotificationComplete"}, - {0x00400042, NULL, "SendCaptureBufferInfo"}, - {0x00410040, NULL, "ReceiveCaptureBufferInfo"}, - {0x00420080, NULL, "SleepSystem"}, - {0x00430040, NULL, "NotifyToWait"}, - {0x00440000, NULL, "GetSharedFont"}, - {0x00450040, NULL, "GetWirelessRebootInfo"}, - {0x00460104, NULL, "Wrap"}, - {0x00470104, NULL, "Unwrap"}, - {0x00480100, NULL, "GetProgramInfo"}, - {0x00490180, NULL, "Reboot"}, - {0x004A0040, NULL, "GetCaptureInfo"}, - {0x004B00C2, NULL, "AppletUtility"}, - {0x004C0000, NULL, "SetFatalErrDispMode"}, - {0x004D0080, NULL, "GetAppletProgramInfo"}, - {0x004E0000, NULL, "HardwareResetAsync"}, + {0x00010040, GetLockHandle, "GetLockHandle"}, + {0x00020080, Initialize, "Initialize"}, + {0x00030040, Enable, "Enable"}, + {0x00040040, NULL, "Finalize"}, + {0x00050040, NULL, "GetAppletManInfo"}, + {0x00060040, NULL, "GetAppletInfo"}, + {0x00070000, NULL, "GetLastSignaledAppletId"}, + {0x00080000, NULL, "CountRegisteredApplet"}, + {0x00090040, NULL, "IsRegistered"}, + {0x000A0040, NULL, "GetAttribute"}, + {0x000B0040, InquireNotification, "InquireNotification"}, + {0x000C0104, NULL, "SendParameter"}, + {0x000D0080, NULL, "ReceiveParameter"}, + {0x000E0080, NULL, "GlanceParameter"}, + {0x000F0100, NULL, "CancelParameter"}, + {0x001000C2, NULL, "DebugFunc"}, + {0x001100C0, NULL, "MapProgramIdForDebug"}, + {0x00120040, NULL, "SetHomeMenuAppletIdForDebug"}, + {0x00130000, NULL, "GetPreparationState"}, + {0x00140040, NULL, "SetPreparationState"}, + {0x00150140, NULL, "PrepareToStartApplication"}, + {0x00160040, NULL, "PreloadLibraryApplet"}, + {0x00170040, NULL, "FinishPreloadingLibraryApplet"}, + {0x00180040, NULL, "PrepareToStartLibraryApplet"}, + {0x00190040, NULL, "PrepareToStartSystemApplet"}, + {0x001A0000, NULL, "PrepareToStartNewestHomeMenu"}, + {0x001B00C4, NULL, "StartApplication"}, + {0x001C0000, NULL, "WakeupApplication"}, + {0x001D0000, NULL, "CancelApplication"}, + {0x001E0084, NULL, "StartLibraryApplet"}, + {0x001F0084, NULL, "StartSystemApplet"}, + {0x00200044, NULL, "StartNewestHomeMenu"}, + {0x00210000, NULL, "OrderToCloseApplication"}, + {0x00220040, NULL, "PrepareToCloseApplication"}, + {0x00230040, NULL, "PrepareToJumpToApplication"}, + {0x00240044, NULL, "JumpToApplication"}, + {0x002500C0, NULL, "PrepareToCloseLibraryApplet"}, + {0x00260000, NULL, "PrepareToCloseSystemApplet"}, + {0x00270044, NULL, "CloseApplication"}, + {0x00280044, NULL, "CloseLibraryApplet"}, + {0x00290044, NULL, "CloseSystemApplet"}, + {0x002A0000, NULL, "OrderToCloseSystemApplet"}, + {0x002B0000, NULL, "PrepareToJumpToHomeMenu"}, + {0x002C0044, NULL, "JumpToHomeMenu"}, + {0x002D0000, NULL, "PrepareToLeaveHomeMenu"}, + {0x002E0044, NULL, "LeaveHomeMenu"}, + {0x002F0040, NULL, "PrepareToLeaveResidentApplet"}, + {0x00300044, NULL, "LeaveResidentApplet"}, + {0x00310100, NULL, "PrepareToDoApplicationJump"}, + {0x00320084, NULL, "DoApplicationJump"}, + {0x00330000, NULL, "GetProgramIdOnApplicationJump"}, + {0x00340084, NULL, "SendDeliverArg"}, + {0x00350080, NULL, "ReceiveDeliverArg"}, + {0x00360040, NULL, "LoadSysMenuArg"}, + {0x00370042, NULL, "StoreSysMenuArg"}, + {0x00380040, NULL, "PreloadResidentApplet"}, + {0x00390040, NULL, "PrepareToStartResidentApplet"}, + {0x003A0044, NULL, "StartResidentApplet"}, + {0x003B0040, NULL, "CancelLibraryApplet"}, + {0x003C0042, NULL, "SendDspSleep"}, + {0x003D0042, NULL, "SendDspWakeUp"}, + {0x003E0080, NULL, "ReplySleepQuery"}, + {0x003F0040, NULL, "ReplySleepNotificationComplete"}, + {0x00400042, NULL, "SendCaptureBufferInfo"}, + {0x00410040, NULL, "ReceiveCaptureBufferInfo"}, + {0x00420080, NULL, "SleepSystem"}, + {0x00430040, NULL, "NotifyToWait"}, + {0x00440000, NULL, "GetSharedFont"}, + {0x00450040, NULL, "GetWirelessRebootInfo"}, + {0x00460104, NULL, "Wrap"}, + {0x00470104, NULL, "Unwrap"}, + {0x00480100, NULL, "GetProgramInfo"}, + {0x00490180, NULL, "Reboot"}, + {0x004A0040, NULL, "GetCaptureInfo"}, + {0x004B00C2, NULL, "AppletUtility"}, + {0x004C0000, NULL, "SetFatalErrDispMode"}, + {0x004D0080, NULL, "GetAppletProgramInfo"}, + {0x004E0000, NULL, "HardwareResetAsync"}, }; //////////////////////////////////////////////////////////////////////////////////////////////////// From e7202e5b2d086c4eaa8a324a54b878aa4689d4e4 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 29 May 2014 18:52:57 -0400 Subject: [PATCH 24/44] svc: added ArbitrationType enumeration --- src/core/hle/svc.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/core/hle/svc.h b/src/core/hle/svc.h index 5c35977d1..c5170aab7 100644 --- a/src/core/hle/svc.h +++ b/src/core/hle/svc.h @@ -38,6 +38,15 @@ enum ResetType { RESETTYPE_MAX_BIT = (1u << 31), }; +enum ArbitrationType { + ARBITRATIONTYPE_SIGNAL, + ARBITRATIONTYPE_WAIT_IF_LESS_THAN, + ARBITRATIONTYPE_DECREMENT_AND_WAIT_IF_LESS_THAN, + ARBITRATIONTYPE_WAIT_IF_LESS_THAN_WITH_TIMEOUT, + ARBITRATIONTYPE_DECREMENT_AND_WAIT_IF_LESS_THAN_WITH_TIMEOUT, + ARBITRATIONTYPE_MAX_BIT = (1u << 31) +}; + //////////////////////////////////////////////////////////////////////////////////////////////////// // Namespace SVC From b08b3c154fd5c2cdb12ab88597863f736c156123 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 29 May 2014 18:53:45 -0400 Subject: [PATCH 25/44] srv: changed a NOTICE_LOG to DEBUG_LOG --- src/core/hle/service/srv.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/service/srv.cpp b/src/core/hle/service/srv.cpp index 7bbc03bf6..97e7fc8fa 100644 --- a/src/core/hle/service/srv.cpp +++ b/src/core/hle/service/srv.cpp @@ -36,7 +36,7 @@ void GetServiceHandle(Service::Interface* self) { std::string port_name = std::string((const char*)&cmd_buff[1], 0, Service::kMaxPortSize); Service::Interface* service = Service::g_manager->FetchFromPortName(port_name); - NOTICE_LOG(OSHLE, "SRV::Sync - GetHandle - port: %s, handle: 0x%08X", port_name.c_str(), + DEBUG_LOG(OSHLE, "SRV::Sync - GetHandle - port: %s, handle: 0x%08X", port_name.c_str(), service->GetHandle()); if (NULL != service) { From 545e6919ce33a815761aef0f32e8e052858a60b3 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 29 May 2014 18:54:59 -0400 Subject: [PATCH 26/44] service: added additional hack to return success on unimplemented service calls --- src/core/hle/service/service.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index 4a3d4c68a..8f8d4d552 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -87,12 +87,20 @@ public: if (itr == m_functions.end()) { ERROR_LOG(OSHLE, "Unknown/unimplemented function: port = %s, command = 0x%08X!", GetPortName(), cmd_buff[0]); - return 0; // TODO(bunnei): Hack - ignore error + + // TODO(bunnei): Hack - ignore error + u32* cmd_buff = Service::GetCommandBuffer(); + cmd_buff[1] = 0; + return 0; } if (itr->second.func == NULL) { ERROR_LOG(OSHLE, "Unimplemented function: port = %s, name = %s!", GetPortName(), itr->second.name.c_str()); - return 0; // TODO(bunnei): Hack - ignore error + + // TODO(bunnei): Hack - ignore error + u32* cmd_buff = Service::GetCommandBuffer(); + cmd_buff[1] = 0; + return 0; } itr->second.func(this); From d51c84dde22549c7413e52a682158e6da3ff1fdc Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 29 May 2014 20:00:44 -0400 Subject: [PATCH 27/44] event: added support for ClearEvent, fixed a bug with CreateEvent, fixed some comments --- src/core/hle/kernel/event.cpp | 18 +++++++++++------- src/core/hle/kernel/event.h | 5 +++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/core/hle/kernel/event.cpp b/src/core/hle/kernel/event.cpp index e85f39f0d..7cb8c5142 100644 --- a/src/core/hle/kernel/event.cpp +++ b/src/core/hle/kernel/event.cpp @@ -54,11 +54,16 @@ public: * Changes whether an event is locked or not * @param handle Handle to event to change * @param locked Boolean locked value to set event + * @return Result of operation, 0 on success, otherwise error code */ -void SetEventLocked(const Handle handle, const bool locked) { +Result SetEventLocked(const Handle handle, const bool locked) { Event* evt = g_object_pool.GetFast(handle); + if (!evt) { + ERROR_LOG(KERNEL, "SetEventLocked called with unknown handle=0x%08X", handle); + return -1; + } evt->locked = locked; - return; + return 0; } /** @@ -67,23 +72,22 @@ void SetEventLocked(const Handle handle, const bool locked) { * @return Result of operation, 0 on success, otherwise error code */ Result ClearEvent(Handle handle) { - ERROR_LOG(KERNEL, "Unimplemented function ClearEvent"); - return 0; + return SetEventLocked(handle, true); } /** * Creates an event * @param handle Reference to handle for the newly created mutex * @param reset_type ResetType describing how to create event - * @return Handle to newly created object + * @return Newly created Event object */ Event* CreateEvent(Handle& handle, const ResetType reset_type) { Event* evt = new Event; handle = Kernel::g_object_pool.Create(evt); + evt->locked = true; evt->reset_type = evt->intitial_reset_type = reset_type; - evt->locked = false; return evt; } @@ -91,7 +95,7 @@ Event* CreateEvent(Handle& handle, const ResetType reset_type) { /** * Creates an event * @param reset_type ResetType describing how to create event - * @return Handle to newly created object + * @return Handle to newly created Event object */ Handle CreateEvent(const ResetType reset_type) { Handle handle; diff --git a/src/core/hle/kernel/event.h b/src/core/hle/kernel/event.h index c1842cb88..b1d2c6ad1 100644 --- a/src/core/hle/kernel/event.h +++ b/src/core/hle/kernel/event.h @@ -15,8 +15,9 @@ namespace Kernel { * Changes whether an event is locked or not * @param handle Handle to event to change * @param locked Boolean locked value to set event + * @return Result of operation, 0 on success, otherwise error code */ -void SetEventLocked(const Handle handle, const bool locked); +Result SetEventLocked(const Handle handle, const bool locked); /** * Clears an event @@ -28,7 +29,7 @@ Result ClearEvent(Handle handle); /** * Creates an event * @param reset_type ResetType describing how to create event - * @return Handle to newly created object + * @return Handle to newly created Event object */ Handle CreateEvent(const ResetType reset_type); From 58af0da792adab4bfd77699f9431050290a75b7c Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 29 May 2014 20:24:51 -0400 Subject: [PATCH 28/44] svc: added svcClearEvent, stubbed function for svcArbitrateAddress, and various fixes - force kernel reschedule after svcWaitSynchronization - fixed some bugs with passing in pointer arguments - cleaned up some comments and log messages --- src/core/hle/function_wrappers.h | 6 ++++ src/core/hle/svc.cpp | 54 +++++++++++++++++++------------- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h index 7b07d8ca8..43f0d15e0 100644 --- a/src/core/hle/function_wrappers.h +++ b/src/core/hle/function_wrappers.h @@ -758,3 +758,9 @@ template void WrapI_VVUUS64() { int retval = func(Memory::GetPointer(PARAM(5)), Memory::GetPointer(PARAM(1)), PARAM(2), PARAM(3), (((u64)PARAM(4) << 32) | PARAM(0))); RETURN(retval); } + +// TODO(bunne): Is this correct? Probably not +template void WrapI_UUUUS64() { + int retval = func(PARAM(5), PARAM(1), PARAM(2), PARAM(3), (((u64)PARAM(4) << 32) | PARAM(0))); + RETURN(retval); +} diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 8468c4fab..8ef894e68 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -35,7 +35,6 @@ enum MapMemoryPermission { /// Map application or GSP heap memory Result ControlMemory(void* _outaddr, u32 operation, u32 addr0, u32 addr1, u32 size, u32 permissions) { - u32* outaddr = (u32*)_outaddr; u32 virtual_address = 0x00000000; DEBUG_LOG(SVC, "ControlMemory called operation=0x%08X, addr0=0x%08X, addr1=0x%08X, size=%08X, permissions=0x%08X", @@ -57,9 +56,7 @@ Result ControlMemory(void* _outaddr, u32 operation, u32 addr0, u32 addr1, u32 si default: ERROR_LOG(SVC, "ControlMemory unknown operation=0x%08X", operation); } - if (NULL != outaddr) { - *outaddr = virtual_address; - } + Core::g_app_core->SetReg(1, virtual_address); return 0; @@ -82,7 +79,7 @@ Result MapMemoryBlock(Handle memblock, u32 addr, u32 mypermissions, u32 otherper } /// Connect to an OS service given the port name, returns the handle to the port to out -Result ConnectToPort(void* out, const char* port_name) { +Result ConnectToPort(void* _out, const char* port_name) { Service::Interface* service = Service::g_manager->FetchFromPortName(port_name); DEBUG_LOG(SVC, "ConnectToPort called port_name=%s", port_name); _assert_msg_(KERNEL, service, "ConnectToPort called, but service is not implemented!"); @@ -128,6 +125,7 @@ Result WaitSynchronization1(Handle handle, s64 nano_seconds) { if (wait) { Kernel::WaitCurrentThread(WAITTYPE_SYNCH); // TODO(bunnei): Is this correct? + Kernel::Reschedule(); } return res; @@ -138,7 +136,6 @@ Result WaitSynchronizationN(void* _out, void* _handles, u32 handle_count, u32 wa s64 nano_seconds) { // TODO(bunnei): Do something with nano_seconds, currently ignoring this - s32* out = (s32*)_out; Handle* handles = (Handle*)_handles; bool unlock_all = true; @@ -153,6 +150,8 @@ Result WaitSynchronizationN(void* _out, void* _handles, u32 handle_count, u32 wa _assert_msg_(KERNEL, object, "WaitSynchronizationN called handle=0x%08X, but kernel object " "is NULL!", handles[i]); + DEBUG_LOG(SVC, "\thandle[%d] = 0x%08X", i, handles[i]); + Result res = object->WaitSynchronization(&wait); if (!wait && !wait_all) { @@ -170,18 +169,26 @@ Result WaitSynchronizationN(void* _out, void* _handles, u32 handle_count, u32 wa // Set current thread to wait state if not all handles were unlocked Kernel::WaitCurrentThread(WAITTYPE_SYNCH); // TODO(bunnei): Is this correct? + Kernel::Reschedule(); return 0; } /// Create an address arbiter (to allocate access to shared resources) Result CreateAddressArbiter(void* arbiter) { - // ImplementMe DEBUG_LOG(SVC, "(UNIMPLEMENTED) CreateAddressArbiter called"); Core::g_app_core->SetReg(1, 0xFABBDADD); return 0; } +/// Arbitrate address +Result ArbitrateAddress(Handle arbiter, u32 addr, u32 _type, u32 value, s64 nanoseconds) { + DEBUG_LOG(SVC, "(UNIMPLEMENTED) ArbitrateAddress called"); + ArbitrationType type = (ArbitrationType)_type; + Memory::Write32(addr, type); + return 0; +} + /// Used to output a message on a debug hardware unit - does nothing on a retail unit void OutputDebugString(const char* string) { NOTICE_LOG(SVC, "## OSDEBUG: %08X %s", Core::g_app_core->GetPC(), string); @@ -199,7 +206,6 @@ Result GetResourceLimit(void* resource_limit, Handle process) { /// Get resource limit current values Result GetResourceLimitCurrentValues(void* _values, Handle resource_limit, void* names, s32 name_count) { - //s64* values = (s64*)_values; DEBUG_LOG(SVC, "(UNIMPLEMENTED) GetResourceLimitCurrentValues called resource_limit=%08X, names=%s, name_count=%d", resource_limit, names, name_count); Memory::Write32(Core::g_app_core->GetReg(0), 0); // Normmatt: Set used memory to 0 for now @@ -224,7 +230,7 @@ Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top, u32 p Core::g_app_core->SetReg(1, thread); DEBUG_LOG(SVC, "CreateThread called entrypoint=0x%08X (%s), arg=0x%08X, stacktop=0x%08X, " - "threadpriority=0x%08X, processorid=0x%08X : created handle 0x%08X", entry_point, + "threadpriority=0x%08X, processorid=0x%08X : created handle=0x%08X", entry_point, name.c_str(), arg, stack_top, priority, processor_id, thread); return 0; @@ -232,11 +238,10 @@ Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top, u32 p /// Create a mutex Result CreateMutex(void* _mutex, u32 initial_locked) { - Handle* mutex = (Handle*)_mutex; - DEBUG_LOG(SVC, "CreateMutex called initial_locked=%s : created handle 0x%08X", - initial_locked ? "true" : "false", *mutex); - *mutex = Kernel::CreateMutex((initial_locked != 0)); - Core::g_app_core->SetReg(1, *mutex); + Handle mutex = Kernel::CreateMutex((initial_locked != 0)); + Core::g_app_core->SetReg(1, mutex); + DEBUG_LOG(SVC, "CreateMutex called initial_locked=%s : created handle=0x%08X", + initial_locked ? "true" : "false", mutex); return 0; } @@ -256,18 +261,16 @@ Result GetThreadId(void* thread_id, u32 thread) { /// Query memory Result QueryMemory(void *_info, void *_out, u32 addr) { - MemoryInfo* info = (MemoryInfo*) _info; - PageInfo* out = (PageInfo*) _out; DEBUG_LOG(SVC, "(UNIMPLEMENTED) QueryMemory called addr=0x%08X", addr); return 0; } /// Create an event Result CreateEvent(void* _event, u32 reset_type) { - Handle* evt = (Handle*)_event; - DEBUG_LOG(SVC, "CreateEvent called reset_type=0x%08X", reset_type); - *evt = Kernel::CreateEvent((ResetType)reset_type); - Core::g_app_core->SetReg(1, *evt); + Handle evt = Kernel::CreateEvent((ResetType)reset_type); + Core::g_app_core->SetReg(1, evt); + DEBUG_LOG(SVC, "CreateEvent called reset_type=0x%08X : created handle=0x%08X", + reset_type, evt); return 0; } @@ -278,6 +281,13 @@ Result DuplicateHandle(void* _out, Handle handle) { return 0; } +/// Clears an event +Result ClearEvent(Handle evt) { + Result res = Kernel::ClearEvent(evt); + DEBUG_LOG(SVC, "ClearEvent called event=0x%08X", evt); + return res; +} + const HLE::FunctionDef SVC_Table[] = { {0x00, NULL, "Unknown"}, {0x01, WrapI_VUUUUU, "ControlMemory"}, @@ -304,7 +314,7 @@ const HLE::FunctionDef SVC_Table[] = { {0x16, NULL, "ReleaseSemaphore"}, {0x17, WrapI_VU, "CreateEvent"}, {0x18, NULL, "SignalEvent"}, - {0x19, NULL, "ClearEvent"}, + {0x19, WrapI_U, "ClearEvent"}, {0x1A, NULL, "CreateTimer"}, {0x1B, NULL, "SetTimer"}, {0x1C, NULL, "CancelTimer"}, @@ -313,7 +323,7 @@ const HLE::FunctionDef SVC_Table[] = { {0x1F, WrapI_UUUU, "MapMemoryBlock"}, {0x20, NULL, "UnmapMemoryBlock"}, {0x21, WrapI_V, "CreateAddressArbiter"}, - {0x22, NULL, "ArbitrateAddress"}, + {0x22, WrapI_UUUUS64, "ArbitrateAddress"}, {0x23, WrapI_U, "CloseHandle"}, {0x24, WrapI_US64, "WaitSynchronization1"}, {0x25, WrapI_VVUUS64, "WaitSynchronizationN"}, From 6d267142ad42ed09e475742cab463b55d9176c29 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 29 May 2014 20:26:27 -0400 Subject: [PATCH 29/44] svc: changed unimplemented SVC log messages from "debug" messages to "error" messages --- src/core/hle/svc.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 8ef894e68..6df0309e6 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -106,7 +106,7 @@ Result SendSyncRequest(Handle handle) { /// Close a handle Result CloseHandle(Handle handle) { // ImplementMe - DEBUG_LOG(SVC, "(UNIMPLEMENTED) CloseHandle called handle=0x%08X", handle); + ERROR_LOG(SVC, "(UNIMPLEMENTED) CloseHandle called handle=0x%08X", handle); return 0; } @@ -176,14 +176,14 @@ Result WaitSynchronizationN(void* _out, void* _handles, u32 handle_count, u32 wa /// Create an address arbiter (to allocate access to shared resources) Result CreateAddressArbiter(void* arbiter) { - DEBUG_LOG(SVC, "(UNIMPLEMENTED) CreateAddressArbiter called"); + ERROR_LOG(SVC, "(UNIMPLEMENTED) CreateAddressArbiter called"); Core::g_app_core->SetReg(1, 0xFABBDADD); return 0; } /// Arbitrate address Result ArbitrateAddress(Handle arbiter, u32 addr, u32 _type, u32 value, s64 nanoseconds) { - DEBUG_LOG(SVC, "(UNIMPLEMENTED) ArbitrateAddress called"); + ERROR_LOG(SVC, "(UNIMPLEMENTED) ArbitrateAddress called"); ArbitrationType type = (ArbitrationType)_type; Memory::Write32(addr, type); return 0; @@ -199,14 +199,14 @@ Result GetResourceLimit(void* resource_limit, Handle process) { // With regards to proceess values: // 0xFFFF8001 is a handle alias for the current KProcess, and 0xFFFF8000 is a handle alias for // the current KThread. - DEBUG_LOG(SVC, "(UNIMPLEMENTED) GetResourceLimit called process=0x%08X", process); + ERROR_LOG(SVC, "(UNIMPLEMENTED) GetResourceLimit called process=0x%08X", process); Core::g_app_core->SetReg(1, 0xDEADBEEF); return 0; } /// Get resource limit current values Result GetResourceLimitCurrentValues(void* _values, Handle resource_limit, void* names, s32 name_count) { - DEBUG_LOG(SVC, "(UNIMPLEMENTED) GetResourceLimitCurrentValues called resource_limit=%08X, names=%s, name_count=%d", + ERROR_LOG(SVC, "(UNIMPLEMENTED) GetResourceLimitCurrentValues called resource_limit=%08X, names=%s, name_count=%d", resource_limit, names, name_count); Memory::Write32(Core::g_app_core->GetReg(0), 0); // Normmatt: Set used memory to 0 for now return 0; @@ -255,13 +255,13 @@ Result ReleaseMutex(Handle handle) { /// Get current thread ID Result GetThreadId(void* thread_id, u32 thread) { - DEBUG_LOG(SVC, "(UNIMPLEMENTED) GetThreadId called thread=0x%08X", thread); + ERROR_LOG(SVC, "(UNIMPLEMENTED) GetThreadId called thread=0x%08X", thread); return 0; } /// Query memory Result QueryMemory(void *_info, void *_out, u32 addr) { - DEBUG_LOG(SVC, "(UNIMPLEMENTED) QueryMemory called addr=0x%08X", addr); + ERROR_LOG(SVC, "(UNIMPLEMENTED) QueryMemory called addr=0x%08X", addr); return 0; } @@ -277,7 +277,7 @@ Result CreateEvent(void* _event, u32 reset_type) { /// Duplicates a kernel handle Result DuplicateHandle(void* _out, Handle handle) { Handle* out = (Handle*)_out; - DEBUG_LOG(SVC, "(UNIMPLEMENTED) DuplicateHandle called handle=0x%08X", handle); + ERROR_LOG(SVC, "(UNIMPLEMENTED) DuplicateHandle called handle=0x%08X", handle); return 0; } From 9839f3b6cd9ea0d62730edee7db027dde86f6239 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 29 May 2014 20:30:17 -0400 Subject: [PATCH 30/44] core: changed time delay before kernel reschedule to "approximate" a screen refresh --- src/core/core.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/core/core.cpp b/src/core/core.cpp index f88bcd704..070f92ed5 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -9,6 +9,7 @@ #include "core/core.h" #include "core/mem_map.h" #include "core/hw/hw.h" +#include "core/hw/lcd.h" #include "core/arm/disassembler/arm_disasm.h" #include "core/arm/interpreter/arm_interpreter.h" @@ -23,7 +24,7 @@ ARM_Interface* g_sys_core = NULL; ///< ARM11 system (OS) core /// Run the core CPU loop void RunLoop() { for (;;){ - g_app_core->Run(100); + g_app_core->Run(LCD::kFrameTicks / 2); HW::Update(); Kernel::Reschedule(); } @@ -31,9 +32,17 @@ void RunLoop() { /// Step the CPU one instruction void SingleStep() { + static int ticks = 0; + g_app_core->Step(); - HW::Update(); - Kernel::Reschedule(); + + if (ticks >= LCD::kFrameTicks / 2) { + HW::Update(); + Kernel::Reschedule(); + ticks = 0; + } else { + ticks++; + } } /// Halt the core From 6fc62f8c93bd81f6207fcbdfe332b4e56c2aa2be Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 29 May 2014 23:03:03 -0400 Subject: [PATCH 31/44] log: fixed to not print twice, enabled coloring, added OS print logging as its own type --- src/common/console_listener.cpp | 16 ++++++---------- src/common/log.h | 31 +++++++++++++++++++------------ src/common/log_manager.cpp | 28 +++++++++++++++------------- src/common/log_manager.h | 4 ++-- 4 files changed, 42 insertions(+), 37 deletions(-) diff --git a/src/common/console_listener.cpp b/src/common/console_listener.cpp index b5f32d1bd..db48abbf6 100644 --- a/src/common/console_listener.cpp +++ b/src/common/console_listener.cpp @@ -259,14 +259,17 @@ void ConsoleListener::Log(LogTypes::LOG_LEVELS Level, const char *Text) switch (Level) { + case OS_LEVEL: // light yellow + Color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; + break; case NOTICE_LEVEL: // light green Color = FOREGROUND_GREEN | FOREGROUND_INTENSITY; break; case ERROR_LEVEL: // light red Color = FOREGROUND_RED | FOREGROUND_INTENSITY; break; - case WARNING_LEVEL: // light yellow - Color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; + case WARNING_LEVEL: // light purple + Color = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY; break; case INFO_LEVEL: // cyan Color = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; @@ -278,15 +281,8 @@ void ConsoleListener::Log(LogTypes::LOG_LEVELS Level, const char *Text) Color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; break; } - if (strlen(Text) > 10) - { - // First 10 chars white - SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY); - WriteConsole(hConsole, Text, 10, &cCharsWritten, NULL); - Text += 10; - } SetConsoleTextAttribute(hConsole, Color); - WriteConsole(hConsole, Text, (DWORD)strlen(Text), &cCharsWritten, NULL); + printf(Text); #else char ColorAttr[16] = ""; char ResetAttr[16] = ""; diff --git a/src/common/log.h b/src/common/log.h index 8b39b03a1..2543b51a8 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -7,11 +7,14 @@ #define LOGGING -#define NOTICE_LEVEL 1 // VERY important information that is NOT errors. Like startup and OSReports. -#define ERROR_LEVEL 2 // Critical errors -#define WARNING_LEVEL 3 // Something is suspicious. -#define INFO_LEVEL 4 // General information. -#define DEBUG_LEVEL 5 // Detailed debugging - might make things slow. +enum { + OS_LEVEL, // Printed by the emulated operating system + NOTICE_LEVEL, // VERY important information that is NOT errors. Like startup and OSReports. + ERROR_LEVEL, // Critical errors + WARNING_LEVEL, // Something is suspicious. + INFO_LEVEL, // General information. + DEBUG_LEVEL, // Detailed debugging - might make things slow. +}; namespace LogTypes { @@ -70,6 +73,7 @@ enum LOG_TYPE { // FIXME: should this be removed? enum LOG_LEVELS { + LOS = OS_LEVEL, LNOTICE = NOTICE_LEVEL, LERROR = ERROR_LEVEL, LWARNING = WARNING_LEVEL, @@ -82,8 +86,8 @@ enum LOG_LEVELS { } // namespace -void GenericLog(LOGTYPES_LEVELS level, LOGTYPES_TYPE type, - const char *file, int line, const char *fmt, ...) +void GenericLog(LOGTYPES_LEVELS level, LOGTYPES_TYPE type, const char*file, int line, + const char* function, const char* fmt, ...) #ifdef __GNUC__ __attribute__((format(printf, 5, 6))) #endif @@ -97,16 +101,19 @@ void GenericLog(LOGTYPES_LEVELS level, LOGTYPES_TYPE type, #endif // loglevel #endif // logging -#ifdef GEKKO -#define GENERIC_LOG(t, v, ...) -#else +#ifdef _WIN32 +#ifndef __func__ +#define __func__ __FUNCTION__ +#endif +#endif + // Let the compiler optimize this out #define GENERIC_LOG(t, v, ...) { \ if (v <= MAX_LOGLEVEL) \ - GenericLog(v, t, __FILE__, __LINE__, __VA_ARGS__); \ + GenericLog(v, t, __FILE__, __LINE__, __func__, __VA_ARGS__); \ } -#endif +#define OS_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LOS, __VA_ARGS__) } while (0) #define ERROR_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LERROR, __VA_ARGS__) } while (0) #define WARN_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LWARNING, __VA_ARGS__) } while (0) #define NOTICE_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LNOTICE, __VA_ARGS__) } while (0) diff --git a/src/common/log_manager.cpp b/src/common/log_manager.cpp index 146472888..d026fca56 100644 --- a/src/common/log_manager.cpp +++ b/src/common/log_manager.cpp @@ -10,14 +10,16 @@ #include "common/thread.h" #include "common/file_util.h" -void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, - const char *file, int line, const char* fmt, ...) +void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file, int line, + const char* function, const char* fmt, ...) { va_list args; va_start(args, fmt); - if (LogManager::GetInstance()) + + if (LogManager::GetInstance()) { LogManager::GetInstance()->Log(level, type, - file, line, fmt, args); + file, line, function, fmt, args); + } va_end(args); } @@ -88,6 +90,8 @@ LogManager::LogManager() m_Log[i]->AddListener(m_debuggerLog); #endif } + + m_consoleLog->Open(); } LogManager::~LogManager() @@ -107,8 +111,8 @@ LogManager::~LogManager() delete m_debuggerLog; } -void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, - const char *file, int line, const char *format, va_list args) +void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file, + int line, const char* function, const char *fmt, va_list args) { char temp[MAX_MSGLEN]; char msg[MAX_MSGLEN * 2]; @@ -117,17 +121,15 @@ void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, if (!log->IsEnabled() || level > log->GetLevel() || ! log->HasListeners()) return; - CharArrayFromFormatV(temp, MAX_MSGLEN, format, args); + CharArrayFromFormatV(temp, MAX_MSGLEN, fmt, args); - static const char level_to_char[7] = "-NEWID"; - sprintf(msg, "%s %s:%u %c[%s]: %s\n", - Common::Timer::GetTimeFormatted().c_str(), - file, line, level_to_char[(int)level], - log->GetShortName(), temp); + static const char level_to_char[7] = "ONEWID"; + sprintf(msg, "%s %s:%u %c[%s] %s: %s\n", Common::Timer::GetTimeFormatted().c_str(), file, line, + level_to_char[(int)level], log->GetShortName(), function, temp); + #ifdef ANDROID Host_SysMessage(msg); #endif - printf(msg); // TODO(ShizZy): RemoveMe when I no longer need this log->Trigger(level, msg); } diff --git a/src/common/log_manager.h b/src/common/log_manager.h index 580860b4d..3e238dfa7 100644 --- a/src/common/log_manager.h +++ b/src/common/log_manager.h @@ -99,8 +99,8 @@ public: static u32 GetMaxLevel() { return MAX_LOGLEVEL; } - void Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, - const char *file, int line, const char *fmt, va_list args); + void Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file, int line, + const char* function, const char *fmt, va_list args); void SetLogLevel(LogTypes::LOG_TYPE type, LogTypes::LOG_LEVELS level) { From 55a540eb0209b58a03c6a095b3b475892af150a9 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 29 May 2014 23:03:47 -0400 Subject: [PATCH 32/44] arm: removed unnecessary code when calling SVC from skyeye --- src/core/arm/interpreter/armemu.cpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/core/arm/interpreter/armemu.cpp b/src/core/arm/interpreter/armemu.cpp index e5dc7bd44..1e22cda9d 100644 --- a/src/core/arm/interpreter/armemu.cpp +++ b/src/core/arm/interpreter/armemu.cpp @@ -4533,23 +4533,7 @@ ARMul_Emulate26 (ARMul_State * state) case 0xfd: case 0xfe: case 0xff: - if (instr == ARMul_ABORTWORD - && state->AbortAddr == pc) { - /* A prefetch abort. */ - XScale_set_fsr_far (state, - ARMul_CP15_R5_MMU_EXCPT, - pc); - ARMul_Abort (state, - ARMul_PrefetchAbortV); - break; - } - //sky_pref_t* pref = get_skyeye_pref(); - //if(pref->user_mode_sim){ - // ARMul_OSHandleSWI (state, BITS (0, 23)); - // break; - //} HLE::CallSVC(instr); - ARMul_Abort (state, ARMul_SWIV); break; } } From b0bad47c0e25717bb1c69bc9a286e57f39064238 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 29 May 2014 23:04:18 -0400 Subject: [PATCH 33/44] svc: updated OutputDebugString to use OS_LOG --- src/core/hle/svc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 6df0309e6..27f2b2315 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -191,7 +191,7 @@ Result ArbitrateAddress(Handle arbiter, u32 addr, u32 _type, u32 value, s64 nano /// Used to output a message on a debug hardware unit - does nothing on a retail unit void OutputDebugString(const char* string) { - NOTICE_LOG(SVC, "## OSDEBUG: %08X %s", Core::g_app_core->GetPC(), string); + OS_LOG(SVC, "%s", string); } /// Get resource limit From c404d22036e16d20d91fca0cf29d56785656c0f5 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 29 May 2014 23:26:58 -0400 Subject: [PATCH 34/44] hle: cleaned up log messages --- src/core/hle/config_mem.cpp | 2 +- src/core/hle/hle.cpp | 6 ++-- src/core/hle/service/apt.cpp | 8 ++--- src/core/hle/service/gsp.cpp | 4 +-- src/core/hle/service/service.cpp | 8 +++-- src/core/hle/service/srv.cpp | 6 ++-- src/core/hle/svc.cpp | 55 ++++++++++++++++---------------- src/core/mem_map_funcs.cpp | 5 ++- 8 files changed, 49 insertions(+), 45 deletions(-) diff --git a/src/core/hle/config_mem.cpp b/src/core/hle/config_mem.cpp index 48aa878cc..8c898b265 100644 --- a/src/core/hle/config_mem.cpp +++ b/src/core/hle/config_mem.cpp @@ -55,7 +55,7 @@ inline void Read(T &var, const u32 addr) { break; default: - ERROR_LOG(HLE, "unknown ConfigMem::Read%d @ 0x%08X", sizeof(var) * 8, addr); + ERROR_LOG(HLE, "unknown addr=0x%08X", addr); } } diff --git a/src/core/hle/hle.cpp b/src/core/hle/hle.cpp index 080c36abf..f703da44e 100644 --- a/src/core/hle/hle.cpp +++ b/src/core/hle/hle.cpp @@ -18,7 +18,7 @@ static std::vector g_module_db; const FunctionDef* GetSVCInfo(u32 opcode) { u32 func_num = opcode & 0xFFFFFF; // 8 bits if (func_num > 0xFF) { - ERROR_LOG(HLE,"Unknown SVC: 0x%02X", func_num); + ERROR_LOG(HLE,"unknown svc=0x%02X", func_num); return NULL; } return &g_module_db[0].func_table[func_num]; @@ -33,7 +33,7 @@ void CallSVC(u32 opcode) { if (info->func) { info->func(); } else { - ERROR_LOG(HLE, "Unimplemented SVC function %s(..)", info->name.c_str()); + ERROR_LOG(HLE, "unimplemented SVC function %s(..)", info->name.c_str()); } } @@ -43,7 +43,7 @@ void EatCycles(u32 cycles) { void ReSchedule(const char *reason) { #ifdef _DEBUG - _dbg_assert_msg_(HLE, reason != 0 && strlen(reason) < 256, "ReSchedule: Invalid or too long reason."); + _dbg_assert_msg_(HLE, reason != 0 && strlen(reason) < 256, "Reschedule: Invalid or too long reason."); #endif // TODO: ImplementMe } diff --git a/src/core/hle/service/apt.cpp b/src/core/hle/service/apt.cpp index f2118ba03..10d9a94bd 100644 --- a/src/core/hle/service/apt.cpp +++ b/src/core/hle/service/apt.cpp @@ -17,7 +17,7 @@ namespace APT_U { void Initialize(Service::Interface* self) { u32* cmd_buff = Service::GetCommandBuffer(); - DEBUG_LOG(KERNEL, "APT_U::Initialize called"); + DEBUG_LOG(KERNEL, "called"); cmd_buff[3] = Kernel::CreateEvent(RESETTYPE_ONESHOT); // APT menu event handle cmd_buff[4] = Kernel::CreateEvent(RESETTYPE_ONESHOT); // APT pause event handle @@ -33,14 +33,14 @@ void GetLockHandle(Service::Interface* self) { u32 flags = cmd_buff[1]; // TODO(bunnei): Figure out the purpose of the flag field cmd_buff[1] = 0; // No error cmd_buff[5] = Kernel::CreateMutex(false); - DEBUG_LOG(KERNEL, "APT_U::GetLockHandle called handle=0x%08X", cmd_buff[5]); + DEBUG_LOG(KERNEL, "called handle=0x%08X", cmd_buff[5]); } void Enable(Service::Interface* self) { u32* cmd_buff = Service::GetCommandBuffer(); u32 unk = cmd_buff[1]; // TODO(bunnei): What is this field used for? cmd_buff[1] = 0; // No error - ERROR_LOG(KERNEL, "(UNIMPEMENTED) APT_U::Enable called unk=0x%08X", unk); + ERROR_LOG(KERNEL, "(UNIMPEMENTED) called unk=0x%08X", unk); } void InquireNotification(Service::Interface* self) { @@ -48,7 +48,7 @@ void InquireNotification(Service::Interface* self) { u32 app_id = cmd_buff[2]; cmd_buff[1] = 0; // No error cmd_buff[3] = 0; // Signal type - ERROR_LOG(KERNEL, "(UNIMPEMENTED) APT_U::InquireNotification called app_id=0x%08X", app_id); + ERROR_LOG(KERNEL, "(UNIMPEMENTED) called app_id=0x%08X", app_id); } const Interface::FunctionInfo FunctionTable[] = { diff --git a/src/core/hle/service/gsp.cpp b/src/core/hle/service/gsp.cpp index 50cee2c41..575db86c1 100644 --- a/src/core/hle/service/gsp.cpp +++ b/src/core/hle/service/gsp.cpp @@ -92,7 +92,7 @@ void ReadHWRegs(Service::Interface* self) { break; default: - ERROR_LOG(GSP, "ReadHWRegs unknown register read at address %08X", reg_addr); + ERROR_LOG(GSP, "unknown register read at address %08X", reg_addr); } } @@ -117,7 +117,7 @@ void TriggerCmdReqQueue(Service::Interface* self) { break; default: - ERROR_LOG(GSP, "TriggerCmdReqQueue unknown command 0x%08X", cmd_buff[0]); + ERROR_LOG(GSP, "unknown command 0x%08X", cmd_buff[0]); } GX_FinishCommand(g_thread_id); diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 08d0c43ff..904670e62 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -12,6 +12,8 @@ #include "core/hle/service/apt.h" #include "core/hle/service/gsp.h" #include "core/hle/service/hid.h" +#include "core/hle/service/ndm.h" +#include "core/hle/service/pt.h" #include "core/hle/service/srv.h" #include "core/hle/kernel/kernel.h" @@ -72,14 +74,16 @@ void Init() { g_manager->AddService(new APT_U::Interface); g_manager->AddService(new GSP_GPU::Interface); g_manager->AddService(new HID_User::Interface); + g_manager->AddService(new NDM_U::Interface); + g_manager->AddService(new PT_A::Interface); - NOTICE_LOG(HLE, "Services initialized OK"); + NOTICE_LOG(HLE, "initialized OK"); } /// Shutdown ServiceManager void Shutdown() { delete g_manager; - NOTICE_LOG(HLE, "Services shutdown OK"); + NOTICE_LOG(HLE, "shutdown OK"); } diff --git a/src/core/hle/service/srv.cpp b/src/core/hle/service/srv.cpp index 97e7fc8fa..ac8f398fc 100644 --- a/src/core/hle/service/srv.cpp +++ b/src/core/hle/service/srv.cpp @@ -15,14 +15,14 @@ namespace SRV { Handle g_mutex = 0; void Initialize(Service::Interface* self) { - DEBUG_LOG(OSHLE, "SRV::Initialize called"); + DEBUG_LOG(OSHLE, "called"); if (!g_mutex) { g_mutex = Kernel::CreateMutex(false); } } void GetProcSemaphore(Service::Interface* self) { - DEBUG_LOG(OSHLE, "SRV::GetProcSemaphore called"); + DEBUG_LOG(OSHLE, "called"); // Get process semaphore? u32* cmd_buff = Service::GetCommandBuffer(); cmd_buff[1] = 0; // No error @@ -36,7 +36,7 @@ void GetServiceHandle(Service::Interface* self) { std::string port_name = std::string((const char*)&cmd_buff[1], 0, Service::kMaxPortSize); Service::Interface* service = Service::g_manager->FetchFromPortName(port_name); - DEBUG_LOG(OSHLE, "SRV::Sync - GetHandle - port: %s, handle: 0x%08X", port_name.c_str(), + DEBUG_LOG(OSHLE, "called port=%s, handle=0x%08X", port_name.c_str(), service->GetHandle()); if (NULL != service) { diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 27f2b2315..01fb647e7 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -37,7 +37,7 @@ enum MapMemoryPermission { Result ControlMemory(void* _outaddr, u32 operation, u32 addr0, u32 addr1, u32 size, u32 permissions) { u32 virtual_address = 0x00000000; - DEBUG_LOG(SVC, "ControlMemory called operation=0x%08X, addr0=0x%08X, addr1=0x%08X, size=%08X, permissions=0x%08X", + DEBUG_LOG(SVC,"called operation=0x%08X, addr0=0x%08X, addr1=0x%08X, size=%08X, permissions=0x%08X", operation, addr0, addr1, size, permissions); switch (operation) { @@ -54,7 +54,7 @@ Result ControlMemory(void* _outaddr, u32 operation, u32 addr0, u32 addr1, u32 si // Unknown ControlMemory operation default: - ERROR_LOG(SVC, "ControlMemory unknown operation=0x%08X", operation); + ERROR_LOG(SVC, "unknown operation=0x%08X", operation); } Core::g_app_core->SetReg(1, virtual_address); @@ -64,7 +64,7 @@ Result ControlMemory(void* _outaddr, u32 operation, u32 addr0, u32 addr1, u32 si /// Maps a memory block to specified address Result MapMemoryBlock(Handle memblock, u32 addr, u32 mypermissions, u32 otherpermission) { - DEBUG_LOG(SVC, "MapMemoryBlock called memblock=0x08X, addr=0x%08X, mypermissions=0x%08X, otherpermission=%d", + DEBUG_LOG(SVC, "called memblock=0x08X, addr=0x%08X, mypermissions=0x%08X, otherpermission=%d", memblock, addr, mypermissions, otherpermission); switch (mypermissions) { case MEMORY_PERMISSION_NORMAL: @@ -73,7 +73,7 @@ Result MapMemoryBlock(Handle memblock, u32 addr, u32 mypermissions, u32 otherper Memory::MapBlock_Shared(memblock, addr, mypermissions); break; default: - ERROR_LOG(OSHLE, "MapMemoryBlock unknown permissions=0x%08X", mypermissions); + ERROR_LOG(OSHLE, "unknown permissions=0x%08X", mypermissions); } return 0; } @@ -81,8 +81,8 @@ Result MapMemoryBlock(Handle memblock, u32 addr, u32 mypermissions, u32 otherper /// Connect to an OS service given the port name, returns the handle to the port to out Result ConnectToPort(void* _out, const char* port_name) { Service::Interface* service = Service::g_manager->FetchFromPortName(port_name); - DEBUG_LOG(SVC, "ConnectToPort called port_name=%s", port_name); - _assert_msg_(KERNEL, service, "ConnectToPort called, but service is not implemented!"); + DEBUG_LOG(SVC, "called port_name=%s", port_name); + _assert_msg_(KERNEL, service, "called, but service is not implemented!"); Core::g_app_core->SetReg(1, service->GetHandle()); return 0; } @@ -92,8 +92,8 @@ Result SendSyncRequest(Handle handle) { bool wait = false; Kernel::Object* object = Kernel::g_object_pool.GetFast(handle); - DEBUG_LOG(SVC, "SendSyncRequest called handle=0x%08X", handle); - _assert_msg_(KERNEL, object, "SendSyncRequest called, but kernel object is NULL!"); + DEBUG_LOG(SVC, "called handle=0x%08X", handle); + _assert_msg_(KERNEL, object, "called, but kernel object is NULL!"); Result res = object->SyncRequest(&wait); if (wait) { @@ -106,7 +106,7 @@ Result SendSyncRequest(Handle handle) { /// Close a handle Result CloseHandle(Handle handle) { // ImplementMe - ERROR_LOG(SVC, "(UNIMPLEMENTED) CloseHandle called handle=0x%08X", handle); + ERROR_LOG(SVC, "(UNIMPLEMENTED) called handle=0x%08X", handle); return 0; } @@ -117,9 +117,9 @@ Result WaitSynchronization1(Handle handle, s64 nano_seconds) { Kernel::Object* object = Kernel::g_object_pool.GetFast(handle); - DEBUG_LOG(SVC, "WaitSynchronization1 called handle=0x%08X, nanoseconds=%d", handle, + DEBUG_LOG(SVC, "called handle=0x%08X, nanoseconds=%d", handle, nano_seconds); - _assert_msg_(KERNEL, object, "WaitSynchronization1 called, but kernel object is NULL!"); + _assert_msg_(KERNEL, object, "called, but kernel object is NULL!"); Result res = object->WaitSynchronization(&wait); @@ -139,7 +139,7 @@ Result WaitSynchronizationN(void* _out, void* _handles, u32 handle_count, u32 wa Handle* handles = (Handle*)_handles; bool unlock_all = true; - DEBUG_LOG(SVC, "WaitSynchronizationN called handle_count=%d, wait_all=%s, nanoseconds=%d", + DEBUG_LOG(SVC, "called handle_count=%d, wait_all=%s, nanoseconds=%d", handle_count, (wait_all ? "true" : "false"), nano_seconds); // Iterate through each handle, synchronize kernel object @@ -147,7 +147,7 @@ Result WaitSynchronizationN(void* _out, void* _handles, u32 handle_count, u32 wa bool wait = false; Kernel::Object* object = Kernel::g_object_pool.GetFast(handles[i]); // 0 handle - _assert_msg_(KERNEL, object, "WaitSynchronizationN called handle=0x%08X, but kernel object " + _assert_msg_(KERNEL, object, "called handle=0x%08X, but kernel object " "is NULL!", handles[i]); DEBUG_LOG(SVC, "\thandle[%d] = 0x%08X", i, handles[i]); @@ -176,14 +176,14 @@ Result WaitSynchronizationN(void* _out, void* _handles, u32 handle_count, u32 wa /// Create an address arbiter (to allocate access to shared resources) Result CreateAddressArbiter(void* arbiter) { - ERROR_LOG(SVC, "(UNIMPLEMENTED) CreateAddressArbiter called"); + ERROR_LOG(SVC, "(UNIMPLEMENTED) called"); Core::g_app_core->SetReg(1, 0xFABBDADD); return 0; } /// Arbitrate address Result ArbitrateAddress(Handle arbiter, u32 addr, u32 _type, u32 value, s64 nanoseconds) { - ERROR_LOG(SVC, "(UNIMPLEMENTED) ArbitrateAddress called"); + ERROR_LOG(SVC, "(UNIMPLEMENTED) called"); ArbitrationType type = (ArbitrationType)_type; Memory::Write32(addr, type); return 0; @@ -199,14 +199,15 @@ Result GetResourceLimit(void* resource_limit, Handle process) { // With regards to proceess values: // 0xFFFF8001 is a handle alias for the current KProcess, and 0xFFFF8000 is a handle alias for // the current KThread. - ERROR_LOG(SVC, "(UNIMPLEMENTED) GetResourceLimit called process=0x%08X", process); + ERROR_LOG(SVC, "(UNIMPLEMENTED) called process=0x%08X", process); Core::g_app_core->SetReg(1, 0xDEADBEEF); return 0; } /// Get resource limit current values -Result GetResourceLimitCurrentValues(void* _values, Handle resource_limit, void* names, s32 name_count) { - ERROR_LOG(SVC, "(UNIMPLEMENTED) GetResourceLimitCurrentValues called resource_limit=%08X, names=%s, name_count=%d", +Result GetResourceLimitCurrentValues(void* _values, Handle resource_limit, void* names, + s32 name_count) { + ERROR_LOG(SVC, "(UNIMPLEMENTED) called resource_limit=%08X, names=%s, name_count=%d", resource_limit, names, name_count); Memory::Write32(Core::g_app_core->GetReg(0), 0); // Normmatt: Set used memory to 0 for now return 0; @@ -229,7 +230,7 @@ Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top, u32 p Core::g_app_core->SetReg(1, thread); - DEBUG_LOG(SVC, "CreateThread called entrypoint=0x%08X (%s), arg=0x%08X, stacktop=0x%08X, " + DEBUG_LOG(SVC, "called entrypoint=0x%08X (%s), arg=0x%08X, stacktop=0x%08X, " "threadpriority=0x%08X, processorid=0x%08X : created handle=0x%08X", entry_point, name.c_str(), arg, stack_top, priority, processor_id, thread); @@ -240,28 +241,28 @@ Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top, u32 p Result CreateMutex(void* _mutex, u32 initial_locked) { Handle mutex = Kernel::CreateMutex((initial_locked != 0)); Core::g_app_core->SetReg(1, mutex); - DEBUG_LOG(SVC, "CreateMutex called initial_locked=%s : created handle=0x%08X", + DEBUG_LOG(SVC, "called initial_locked=%s : created handle=0x%08X", initial_locked ? "true" : "false", mutex); return 0; } /// Release a mutex Result ReleaseMutex(Handle handle) { - DEBUG_LOG(SVC, "ReleaseMutex called handle=0x%08X", handle); - _assert_msg_(KERNEL, handle, "ReleaseMutex called, but handle is NULL!"); + DEBUG_LOG(SVC, "called handle=0x%08X", handle); + _assert_msg_(KERNEL, handle, "called, but handle is NULL!"); Kernel::ReleaseMutex(handle); return 0; } /// Get current thread ID Result GetThreadId(void* thread_id, u32 thread) { - ERROR_LOG(SVC, "(UNIMPLEMENTED) GetThreadId called thread=0x%08X", thread); + ERROR_LOG(SVC, "(UNIMPLEMENTED) called thread=0x%08X", thread); return 0; } /// Query memory Result QueryMemory(void *_info, void *_out, u32 addr) { - ERROR_LOG(SVC, "(UNIMPLEMENTED) QueryMemory called addr=0x%08X", addr); + ERROR_LOG(SVC, "(UNIMPLEMENTED) called addr=0x%08X", addr); return 0; } @@ -269,7 +270,7 @@ Result QueryMemory(void *_info, void *_out, u32 addr) { Result CreateEvent(void* _event, u32 reset_type) { Handle evt = Kernel::CreateEvent((ResetType)reset_type); Core::g_app_core->SetReg(1, evt); - DEBUG_LOG(SVC, "CreateEvent called reset_type=0x%08X : created handle=0x%08X", + DEBUG_LOG(SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, evt); return 0; } @@ -277,14 +278,14 @@ Result CreateEvent(void* _event, u32 reset_type) { /// Duplicates a kernel handle Result DuplicateHandle(void* _out, Handle handle) { Handle* out = (Handle*)_out; - ERROR_LOG(SVC, "(UNIMPLEMENTED) DuplicateHandle called handle=0x%08X", handle); + ERROR_LOG(SVC, "(UNIMPLEMENTED) called handle=0x%08X", handle); return 0; } /// Clears an event Result ClearEvent(Handle evt) { Result res = Kernel::ClearEvent(evt); - DEBUG_LOG(SVC, "ClearEvent called event=0x%08X", evt); + DEBUG_LOG(SVC, "called event=0x%08X", evt); return res; } diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index 86e9eaa20..ab014a596 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -86,7 +86,7 @@ inline void _Read(T &var, const u32 addr) { var = *((const T*)&g_vram[vaddr & VRAM_MASK]); } else { - //_assert_msg_(MEMMAP, false, "unknown Read%d @ 0x%08X", sizeof(var) * 8, vaddr); + ERROR_LOG(MEMMAP, "unknown Read%d @ 0x%08X", sizeof(var) * 8, vaddr); } } @@ -136,8 +136,7 @@ inline void _Write(u32 addr, const T data) { // Error out... } else { - _assert_msg_(MEMMAP, false, "unknown Write%d 0x%08X @ 0x%08X", sizeof(data) * 8, - data, vaddr); + ERROR_LOG(MEMMAP, "unknown Write%d 0x%08X @ 0x%08X", sizeof(data) * 8, data, vaddr); } } From d8a2c8c6579b78d9c61abe544cfaea651238130c Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 29 May 2014 23:31:01 -0400 Subject: [PATCH 35/44] mutex: fixed typo in ReleaseMutex --- src/core/hle/kernel/mutex.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp index 23c064571..5ac88cd85 100644 --- a/src/core/hle/kernel/mutex.cpp +++ b/src/core/hle/kernel/mutex.cpp @@ -8,6 +8,7 @@ #include "common/common.h" #include "core/hle/kernel/kernel.h" +#include "core/hle/kernel/mutex.h" #include "core/hle/kernel/thread.h" namespace Kernel { @@ -92,10 +93,11 @@ bool ReleaseMutexForThread(Mutex* mutex, Handle thread) { bool ReleaseMutex(Mutex* mutex) { MutexEraseLock(mutex); bool woke_threads = false; - auto iter = mutex->waiting_threads.begin(); + std::vector::iterator iter; // Find the next waiting thread for the mutex... while (!woke_threads && !mutex->waiting_threads.empty()) { + iter = mutex->waiting_threads.begin(); woke_threads |= ReleaseMutexForThread(mutex, *iter); mutex->waiting_threads.erase(iter); } From 007b7edada86bf97e1499625c3c8fda25132bbac Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 29 May 2014 23:54:09 -0400 Subject: [PATCH 36/44] srv: fix to log unimplemented service (instead of crash) --- src/core/hle/service/srv.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/core/hle/service/srv.cpp b/src/core/hle/service/srv.cpp index ac8f398fc..f1940e6f5 100644 --- a/src/core/hle/service/srv.cpp +++ b/src/core/hle/service/srv.cpp @@ -36,18 +36,14 @@ void GetServiceHandle(Service::Interface* self) { std::string port_name = std::string((const char*)&cmd_buff[1], 0, Service::kMaxPortSize); Service::Interface* service = Service::g_manager->FetchFromPortName(port_name); - DEBUG_LOG(OSHLE, "called port=%s, handle=0x%08X", port_name.c_str(), - service->GetHandle()); - if (NULL != service) { cmd_buff[3] = service->GetHandle(); + DEBUG_LOG(OSHLE, "called port=%s, handle=0x%08X", port_name.c_str(), cmd_buff[3]); } else { - ERROR_LOG(OSHLE, "Service %s does not exist", port_name.c_str()); + ERROR_LOG(OSHLE, "(UNIMPLEMENTED) called port=%s", port_name.c_str()); res = -1; } cmd_buff[1] = res; - - //return res; } const Interface::FunctionInfo FunctionTable[] = { From 2482be13df81eaae17b721e080249bd6c4de759e Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 30 May 2014 00:22:25 -0400 Subject: [PATCH 37/44] service: removed PT_A from, as this was just an alias for APT_U --- src/core/hle/service/service.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 904670e62..781b41fb0 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -13,7 +13,6 @@ #include "core/hle/service/gsp.h" #include "core/hle/service/hid.h" #include "core/hle/service/ndm.h" -#include "core/hle/service/pt.h" #include "core/hle/service/srv.h" #include "core/hle/kernel/kernel.h" @@ -75,7 +74,6 @@ void Init() { g_manager->AddService(new GSP_GPU::Interface); g_manager->AddService(new HID_User::Interface); g_manager->AddService(new NDM_U::Interface); - g_manager->AddService(new PT_A::Interface); NOTICE_LOG(HLE, "initialized OK"); } From c451ad28355b48f9d55a9b1a939e913fbf875953 Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 30 May 2014 00:22:39 -0400 Subject: [PATCH 38/44] service: cleaned up log messages --- src/core/hle/service/service.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index 8f8d4d552..c3e9dd313 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -85,7 +85,7 @@ public: auto itr = m_functions.find(cmd_buff[0]); if (itr == m_functions.end()) { - ERROR_LOG(OSHLE, "Unknown/unimplemented function: port = %s, command = 0x%08X!", + ERROR_LOG(OSHLE, "unknown/unimplemented function: port=%s, command=0x%08X", GetPortName(), cmd_buff[0]); // TODO(bunnei): Hack - ignore error @@ -94,7 +94,7 @@ public: return 0; } if (itr->second.func == NULL) { - ERROR_LOG(OSHLE, "Unimplemented function: port = %s, name = %s!", + ERROR_LOG(OSHLE, "unimplemented function: port=%s, name=%s", GetPortName(), itr->second.name.c_str()); // TODO(bunnei): Hack - ignore error From 55325dea4c85e1a91c6d37282322b466ef40ffac Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 30 May 2014 00:24:04 -0400 Subject: [PATCH 39/44] hle: added stubbed service for ndm_u --- src/core/CMakeLists.txt | 1 + src/core/core.vcxproj | 2 ++ src/core/core.vcxproj.filters | 6 ++++++ src/core/hle/service/ndm.cpp | 32 ++++++++++++++++++++++++++++++++ src/core/hle/service/ndm.h | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 74 insertions(+) create mode 100644 src/core/hle/service/ndm.cpp create mode 100644 src/core/hle/service/ndm.h diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 468e6a631..7236033c4 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -41,6 +41,7 @@ set(SRCS core.cpp hle/service/apt.cpp hle/service/gsp.cpp hle/service/hid.cpp + hle/service/ndm.cpp hle/service/service.cpp hle/service/srv.cpp hw/hw.cpp diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index efcd30d77..6fec75d79 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -175,6 +175,7 @@ + @@ -225,6 +226,7 @@ + diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index 135e4c89c..8e5966d73 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -168,6 +168,9 @@ hle\kernel + + hle\service + @@ -301,6 +304,9 @@ hle\kernel + + hle\service + diff --git a/src/core/hle/service/ndm.cpp b/src/core/hle/service/ndm.cpp new file mode 100644 index 000000000..671e9d4bd --- /dev/null +++ b/src/core/hle/service/ndm.cpp @@ -0,0 +1,32 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "common/log.h" + +#include "core/hle/hle.h" +#include "core/hle/service/ndm.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Namespace NDM_U + +namespace NDM_U { + +const Interface::FunctionInfo FunctionTable[] = { + {0x00060040, NULL, "SuspendDaemons"}, + {0x00080040, NULL, "DisableWifiUsage"}, + {0x00090000, NULL, "EnableWifiUsage"}, + {0x00140040, NULL, "OverrideDefaultDaemons"}, +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Interface class + +Interface::Interface() { + Register(FunctionTable, ARRAY_SIZE(FunctionTable)); +} + +Interface::~Interface() { +} + +} // namespace diff --git a/src/core/hle/service/ndm.h b/src/core/hle/service/ndm.h new file mode 100644 index 000000000..fbe88fb8f --- /dev/null +++ b/src/core/hle/service/ndm.h @@ -0,0 +1,33 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include "core/hle/service/service.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Namespace NDM + +// No idea what this is + +namespace NDM_U { + +class Interface : public Service::Interface { +public: + + Interface(); + + ~Interface(); + + /** + * Gets the string port name used by CTROS for the service + * @return Port name of service + */ + const char *GetPortName() const { + return "ndm:u"; + } + +}; + +} // namespace From f7cececc5ca82f97a9fb1ab50c62fd9e3a49ccdc Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 1 Jun 2014 10:33:55 -0400 Subject: [PATCH 40/44] event: added a hackish ability to set an event as "locked" to its current state, cleaned up some comments --- src/core/hle/kernel/event.cpp | 28 ++++++++++++++++++++++++---- src/core/hle/kernel/event.h | 8 ++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/core/hle/kernel/event.cpp b/src/core/hle/kernel/event.cpp index 7cb8c5142..e84d0b49e 100644 --- a/src/core/hle/kernel/event.cpp +++ b/src/core/hle/kernel/event.cpp @@ -23,6 +23,7 @@ public: ResetType reset_type; ///< Current ResetType bool locked; ///< Current locked state + bool permanent_locked; ///< Hack - to set event permanent state (for easy passthrough) /** * Synchronize kernel object @@ -31,7 +32,7 @@ public: */ Result SyncRequest(bool* wait) { // TODO(bunnei): ImplementMe - ERROR_LOG(KERNEL, "Unimplemented function Event::SyncRequest"); + ERROR_LOG(KERNEL, "(UMIMPLEMENTED) call"); return 0; } @@ -43,7 +44,7 @@ public: Result WaitSynchronization(bool* wait) { // TODO(bunnei): ImplementMe *wait = locked; - if (reset_type != RESETTYPE_STICKY) { + if (reset_type != RESETTYPE_STICKY && !permanent_locked) { locked = true; } return 0; @@ -59,10 +60,28 @@ public: Result SetEventLocked(const Handle handle, const bool locked) { Event* evt = g_object_pool.GetFast(handle); if (!evt) { - ERROR_LOG(KERNEL, "SetEventLocked called with unknown handle=0x%08X", handle); + ERROR_LOG(KERNEL, "called with unknown handle=0x%08X", handle); return -1; } - evt->locked = locked; + if (!evt->permanent_locked) { + evt->locked = locked; + } + return 0; +} + +/** + * Hackish function to set an events permanent lock state, used to pass through synch blocks + * @param handle Handle to event to change + * @param permanent_locked Boolean permanent locked value to set event + * @return Result of operation, 0 on success, otherwise error code + */ +Result SetPermanentLock(Handle handle, const bool permanent_locked) { + Event* evt = g_object_pool.GetFast(handle); + if (!evt) { + ERROR_LOG(KERNEL, "called with unknown handle=0x%08X", handle); + return -1; + } + evt->permanent_locked = permanent_locked; return 0; } @@ -87,6 +106,7 @@ Event* CreateEvent(Handle& handle, const ResetType reset_type) { handle = Kernel::g_object_pool.Create(evt); evt->locked = true; + evt->permanent_locked = false; evt->reset_type = evt->intitial_reset_type = reset_type; return evt; diff --git a/src/core/hle/kernel/event.h b/src/core/hle/kernel/event.h index b1d2c6ad1..f91a72c1c 100644 --- a/src/core/hle/kernel/event.h +++ b/src/core/hle/kernel/event.h @@ -19,6 +19,14 @@ namespace Kernel { */ Result SetEventLocked(const Handle handle, const bool locked); +/** + * Hackish function to set an events permanent lock state, used to pass through synch blocks + * @param handle Handle to event to change + * @param permanent_locked Boolean permanent locked value to set event + * @return Result of operation, 0 on success, otherwise error code + */ +Result SetPermanentLock(Handle handle, const bool permanent_locked); + /** * Clears an event * @param handle Handle to event to clear From ba98e25e979b1aedaa9b917a7db8f710c83c073c Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 1 Jun 2014 10:35:42 -0400 Subject: [PATCH 41/44] thread: updated Reschedule to sit at a synchronization barrier when no other threads are ready for execution --- src/core/hle/kernel/thread.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 6e8b53eb1..d1e13c949 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -323,11 +323,29 @@ void Reschedule() { Thread* prev = GetCurrentThread(); Thread* next = NextThread(); if (next > 0) { + INFO_LOG(KERNEL, "context switch 0x%08X -> 0x%08X", prev->GetHandle(), next->GetHandle()); + SwitchContext(next); // Hack - automatically change previous thread (which would have been in "wait" state) to // "ready" state, so that we can immediately resume to it when new thread yields. FixMe to // actually wait for whatever event it is supposed to be waiting on. + + ChangeReadyState(prev, true); + } else { + INFO_LOG(KERNEL, "no ready threads, staying on 0x%08X", prev->GetHandle()); + + // Hack - no other threads are available, so decrement current PC to the last instruction, + // and then resume current thread. This should always be called on a blocking instruction + // (e.g. svcWaitSynchronization), and the result should be that the instruction is repeated + // until it no longer blocks. + + // TODO(bunnei): A better solution: Have the CPU switch to an idle thread + + ThreadContext ctx; + SaveContext(ctx); + ctx.pc -= 4; + LoadContext(ctx); ChangeReadyState(prev, true); } } From f2f638492b1585739d193b400e34ede91c256462 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 1 Jun 2014 10:37:19 -0400 Subject: [PATCH 42/44] svc: updated waitSychronization to not overwrite handle on return, added stub for SleepThread (does nothing) --- src/core/hle/svc.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 01fb647e7..5ba42973a 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -126,6 +126,14 @@ Result WaitSynchronization1(Handle handle, s64 nano_seconds) { if (wait) { Kernel::WaitCurrentThread(WAITTYPE_SYNCH); // TODO(bunnei): Is this correct? Kernel::Reschedule(); + + // Context switch - Function blocked, is not actually returning (will be "called" again) + + // TODO(bunnei): This saves handle to R0 so that it's correctly reloaded on context switch + // (otherwise R0 will be set to whatever is returned, and handle will be invalid when this + // thread is resumed). There is probably a better way of keeping track of state so that we + // don't necessarily have to do this. + return (Result)PARAM(0); } return res; @@ -171,7 +179,13 @@ Result WaitSynchronizationN(void* _out, void* _handles, u32 handle_count, u32 wa Kernel::WaitCurrentThread(WAITTYPE_SYNCH); // TODO(bunnei): Is this correct? Kernel::Reschedule(); - return 0; + // Context switch - Function blocked, is not actually returning (will be "called" again) + + // TODO(bunnei): This saves handle to R0 so that it's correctly reloaded on context switch + // (otherwise R0 will be set to whatever is returned, and handle will be invalid when this + // thread is resumed). There is probably a better way of keeping track of state so that we + // don't necessarily have to do this. + return (Result)PARAM(0); } /// Create an address arbiter (to allocate access to shared resources) @@ -289,6 +303,11 @@ Result ClearEvent(Handle evt) { return res; } +/// Sleep the current thread +void SleepThread(s64 nanoseconds) { + DEBUG_LOG(SVC, "called nanoseconds=%d", nanoseconds); +} + const HLE::FunctionDef SVC_Table[] = { {0x00, NULL, "Unknown"}, {0x01, WrapI_VUUUUU, "ControlMemory"}, @@ -300,7 +319,7 @@ const HLE::FunctionDef SVC_Table[] = { {0x07, NULL, "SetProcessIdealProcessor"}, {0x08, WrapI_UUUUU, "CreateThread"}, {0x09, NULL, "ExitThread"}, - {0x0A, NULL, "SleepThread"}, + {0x0A, WrapV_S64, "SleepThread"}, {0x0B, NULL, "GetThreadPriority"}, {0x0C, NULL, "SetThreadPriority"}, {0x0D, NULL, "GetThreadAffinityMask"}, From 7dd18a8df97f7497447ff121d8ad07c5a708a5c5 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 1 Jun 2014 10:41:23 -0400 Subject: [PATCH 43/44] gsp: always pass through synchronization barrier for commands --- src/core/hle/service/gsp.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/core/hle/service/gsp.cpp b/src/core/hle/service/gsp.cpp index 575db86c1..2635a2eb8 100644 --- a/src/core/hle/service/gsp.cpp +++ b/src/core/hle/service/gsp.cpp @@ -8,6 +8,7 @@ #include "core/mem_map.h" #include "core/hle/hle.h" +#include "core/hle/kernel/event.h" #include "core/hle/service/gsp.h" #include "core/hw/lcd.h" @@ -52,6 +53,7 @@ void GX_FinishCommand(u32 thread_id) { namespace GSP_GPU { +Handle g_event_handle = 0; u32 g_thread_id = 0; enum { @@ -100,7 +102,20 @@ void ReadHWRegs(Service::Interface* self) { void RegisterInterruptRelayQueue(Service::Interface* self) { u32* cmd_buff = Service::GetCommandBuffer(); u32 flags = cmd_buff[1]; - u32 event_handle = cmd_buff[3]; // TODO(bunnei): Implement event handling + u32 event_handle = cmd_buff[3]; + + _assert_msg_(GSP, event_handle, "called, but event is NULL!"); + + g_event_handle = event_handle; + + Kernel::SetEventLocked(event_handle, false); + + // Hack - This function will permanently set the state of the GSP event such that GPU command + // synchronization barriers always passthrough. Correct solution would be to set this after the + // GPU as processed all queued up commands, but due to the emulator being single-threaded they + // will always be ready. + Kernel::SetPermanentLock(event_handle, true); + cmd_buff[2] = g_thread_id; // ThreadID } From 2f55c9e55bb8b505dd2faefb74cad5a8306b7a2a Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 1 Jun 2014 10:41:41 -0400 Subject: [PATCH 44/44] svc: added missing function wrapper for SleepThread --- src/core/hle/function_wrappers.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h index 43f0d15e0..7eb62fc48 100644 --- a/src/core/hle/function_wrappers.h +++ b/src/core/hle/function_wrappers.h @@ -642,6 +642,10 @@ template void WrapV_C() { func(Memory::GetCharPointer(PARAM(0))); } +template void WrapV_S64() { + func(((s64)PARAM(1) << 32) | PARAM(0)); +} + template void WrapV_CI() { func(Memory::GetCharPointer(PARAM(0)), PARAM(1)); }