diff --git a/src/core/core.cpp b/src/core/core.cpp index 6713631694..f448362360 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -187,6 +187,8 @@ System::ResultStatus System::Init(EmuWindow& emu_window, u32 system_mode) { cpu_core = std::make_unique(*this, USER32MODE); } + kernel->GetThreadManager().SetCPU(*cpu_core); + if (Settings::values.enable_dsp_lle) { dsp_core = std::make_unique(*memory, Settings::values.enable_dsp_lle_multithread); diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 4f4c9b174c..994beef4e5 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -38,7 +38,7 @@ u32 ThreadManager::NewThreadId() { } Thread::Thread(KernelSystem& kernel) - : WaitObject(kernel), context(Core::CPU().NewContext()), + : WaitObject(kernel), context(kernel.GetThreadManager().NewContext()), thread_manager(kernel.GetThreadManager()) {} Thread::~Thread() {} @@ -86,7 +86,7 @@ void ThreadManager::SwitchContext(Thread* new_thread) { // Save context for previous thread if (previous_thread) { previous_thread->last_running_ticks = timing.GetTicks(); - Core::CPU().SaveContext(previous_thread->context); + cpu->SaveContext(previous_thread->context); if (previous_thread->status == ThreadStatus::Running) { // This is only the case when a reschedule is triggered without the current thread @@ -117,8 +117,8 @@ void ThreadManager::SwitchContext(Thread* new_thread) { ¤t_thread->owner_process->vm_manager.page_table); } - Core::CPU().LoadContext(new_thread->context); - Core::CPU().SetCP15Register(CP15_THREAD_URO, new_thread->GetTLSAddress()); + cpu->LoadContext(new_thread->context); + cpu->SetCP15Register(CP15_THREAD_URO, new_thread->GetTLSAddress()); } else { current_thread = nullptr; // Note: We do not reset the current process and current page table when idling because diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index e0af473e09..8f5da92c7d 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -101,6 +101,14 @@ public: */ const std::vector>& GetThreadList(); + void SetCPU(ARM_Interface& cpu) { + this->cpu = &cpu; + } + + std::unique_ptr NewContext() { + return cpu->NewContext(); + } + private: /** * Switches the CPU's active thread context to that of the specified thread @@ -122,6 +130,7 @@ private: void ThreadWakeupCallback(u64 thread_id, s64 cycles_late); Kernel::KernelSystem& kernel; + ARM_Interface* cpu; u32 next_thread_id = 1; SharedPtr current_thread;