summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel
diff options
context:
space:
mode:
authorGravatar Subv2015-05-10 18:35:37 -0500
committerGravatar Subv2015-05-10 18:35:37 -0500
commit000876858d52d7e4fa8e21bc4407d43d548eff30 (patch)
treef0af4cde78349cfe4ea7875b24d37cf85eb3eb03 /src/core/hle/kernel
parentMerge pull request #726 from bunnei/gpu-improvements (diff)
downloadyuzu-000876858d52d7e4fa8e21bc4407d43d548eff30.tar.gz
yuzu-000876858d52d7e4fa8e21bc4407d43d548eff30.tar.xz
yuzu-000876858d52d7e4fa8e21bc4407d43d548eff30.zip
Core/Memory: Give every emulated thread it's own TLS area.
The TLS area for thread T with id Ti is located at TLS_AREA_VADDR + (Ti - 1) * 0x200. This allows some games like Mario Kart 7 to continue further.
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r--src/core/hle/kernel/session.h10
-rw-r--r--src/core/hle/kernel/thread.cpp10
-rw-r--r--src/core/hle/kernel/thread.h6
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 @@
5#pragma once 5#pragma once
6 6
7#include "core/hle/kernel/kernel.h" 7#include "core/hle/kernel/kernel.h"
8#include "core/hle/kernel/thread.h"
8#include "core/mem_map.h" 9#include "core/mem_map.h"
9 10
10namespace Kernel { 11namespace Kernel {
@@ -12,12 +13,15 @@ namespace Kernel {
12static const int kCommandHeaderOffset = 0x80; ///< Offset into command buffer of header 13static const int kCommandHeaderOffset = 0x80; ///< Offset into command buffer of header
13 14
14/** 15/**
15 * Returns a pointer to the command buffer in kernel memory 16 * Returns a pointer to the command buffer in the current thread's TLS
17 * TODO(Subv): This is not entirely correct, the command buffer should be copied from
18 * the thread's TLS to an intermediate buffer in kernel memory, and then copied again to
19 * the service handler process' memory.
16 * @param offset Optional offset into command buffer 20 * @param offset Optional offset into command buffer
17 * @return Pointer to command buffer 21 * @return Pointer to command buffer
18 */ 22 */
19inline static u32* GetCommandBuffer(const int offset=0) { 23inline static u32* GetCommandBuffer(const int offset = 0) {
20 return (u32*)Memory::GetPointer(Memory::TLS_AREA_VADDR + kCommandHeaderOffset + offset); 24 return (u32*)Memory::GetPointer(GetCurrentThread()->GetTLSAddress() + kCommandHeaderOffset + offset);
21} 25}
22 26
23/** 27/**
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,
402 thread->name = std::move(name); 402 thread->name = std::move(name);
403 thread->callback_handle = wakeup_callback_handle_table.Create(thread).MoveFrom(); 403 thread->callback_handle = wakeup_callback_handle_table.Create(thread).MoveFrom();
404 404
405 VAddr tls_address = Memory::TLS_AREA_VADDR + (thread->thread_id - 1) * 0x200;
406
407 ASSERT_MSG(tls_address < Memory::TLS_AREA_VADDR_END, "Too many threads");
408
405 // TODO(peachum): move to ScheduleThread() when scheduler is added so selected core is used 409 // TODO(peachum): move to ScheduleThread() when scheduler is added so selected core is used
406 // to initialize the context 410 // to initialize the context
407 Core::g_app_core->ResetContext(thread->context, stack_top, entry_point, arg); 411 Core::g_app_core->ResetContext(thread->context, stack_top, entry_point, arg, tls_address);
408 412
409 ready_queue.push_back(thread->current_priority, thread.get()); 413 ready_queue.push_back(thread->current_priority, thread.get());
410 thread->status = THREADSTATUS_READY; 414 thread->status = THREADSTATUS_READY;
@@ -495,6 +499,10 @@ void Thread::SetWaitSynchronizationOutput(s32 output) {
495 context.cpu_registers[1] = output; 499 context.cpu_registers[1] = output;
496} 500}
497 501
502VAddr Thread::GetTLSAddress() const {
503 return context.tls;
504}
505
498//////////////////////////////////////////////////////////////////////////////////////////////////// 506////////////////////////////////////////////////////////////////////////////////////////////////////
499 507
500void ThreadingInit() { 508void 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:
135 */ 135 */
136 void Stop(); 136 void Stop();
137 137
138 /*
139 * Returns the Thread Local Storage address of the current thread
140 * @returns VAddr of the thread's TLS
141 */
142 VAddr GetTLSAddress() const;
143
138 Core::ThreadContext context; 144 Core::ThreadContext context;
139 145
140 u32 thread_id; 146 u32 thread_id;