diff options
author | Subv <subv2112@gmail.com> | 2015-05-11 01:35:37 +0200 |
---|---|---|
committer | Subv <subv2112@gmail.com> | 2015-05-11 01:35:37 +0200 |
commit | 000876858d52d7e4fa8e21bc4407d43d548eff30 (patch) | |
tree | f0af4cde78349cfe4ea7875b24d37cf85eb3eb03 /src/core/hle | |
parent | Merge pull request #726 from bunnei/gpu-improvements (diff) | |
download | yuzu-000876858d52d7e4fa8e21bc4407d43d548eff30.tar yuzu-000876858d52d7e4fa8e21bc4407d43d548eff30.tar.gz yuzu-000876858d52d7e4fa8e21bc4407d43d548eff30.tar.bz2 yuzu-000876858d52d7e4fa8e21bc4407d43d548eff30.tar.lz yuzu-000876858d52d7e4fa8e21bc4407d43d548eff30.tar.xz yuzu-000876858d52d7e4fa8e21bc4407d43d548eff30.tar.zst yuzu-000876858d52d7e4fa8e21bc4407d43d548eff30.zip |
Diffstat (limited to 'src/core/hle')
-rw-r--r-- | src/core/hle/kernel/session.h | 10 | ||||
-rw-r--r-- | src/core/hle/kernel/thread.cpp | 10 | ||||
-rw-r--r-- | src/core/hle/kernel/thread.h | 6 |
3 files changed, 22 insertions, 4 deletions
diff --git a/src/core/hle/kernel/session.h b/src/core/hle/kernel/session.h index 0fd18148a..8c3886ffd 100644 --- a/src/core/hle/kernel/session.h +++ b/src/core/hle/kernel/session.h @@ -5,6 +5,7 @@ #pragma once #include "core/hle/kernel/kernel.h" +#include "core/hle/kernel/thread.h" #include "core/mem_map.h" namespace Kernel { @@ -12,12 +13,15 @@ namespace Kernel { static const int kCommandHeaderOffset = 0x80; ///< Offset into command buffer of header /** - * Returns a pointer to the command buffer in kernel memory + * Returns a pointer to the command buffer in the current thread's TLS + * TODO(Subv): This is not entirely correct, the command buffer should be copied from + * the thread's TLS to an intermediate buffer in kernel memory, and then copied again to + * the service handler process' memory. * @param offset Optional offset into command buffer * @return Pointer to command buffer */ -inline static u32* GetCommandBuffer(const int offset=0) { - return (u32*)Memory::GetPointer(Memory::TLS_AREA_VADDR + kCommandHeaderOffset + offset); +inline static u32* GetCommandBuffer(const int offset = 0) { + return (u32*)Memory::GetPointer(GetCurrentThread()->GetTLSAddress() + kCommandHeaderOffset + offset); } /** diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 0a3fd7cb1..61199c12a 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -402,9 +402,13 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, thread->name = std::move(name); thread->callback_handle = wakeup_callback_handle_table.Create(thread).MoveFrom(); + VAddr tls_address = Memory::TLS_AREA_VADDR + (thread->thread_id - 1) * 0x200; + + ASSERT_MSG(tls_address < Memory::TLS_AREA_VADDR_END, "Too many threads"); + // TODO(peachum): move to ScheduleThread() when scheduler is added so selected core is used // to initialize the context - Core::g_app_core->ResetContext(thread->context, stack_top, entry_point, arg); + Core::g_app_core->ResetContext(thread->context, stack_top, entry_point, arg, tls_address); ready_queue.push_back(thread->current_priority, thread.get()); thread->status = THREADSTATUS_READY; @@ -495,6 +499,10 @@ void Thread::SetWaitSynchronizationOutput(s32 output) { context.cpu_registers[1] = output; } +VAddr Thread::GetTLSAddress() const { + return context.tls; +} + //////////////////////////////////////////////////////////////////////////////////////////////////// void ThreadingInit() { diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 9958b16e6..17bb69f45 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -135,6 +135,12 @@ public: */ void Stop(); + /* + * Returns the Thread Local Storage address of the current thread + * @returns VAddr of the thread's TLS + */ + VAddr GetTLSAddress() const; + Core::ThreadContext context; u32 thread_id; |