VERY experimental Nintendo Switch 2 emulator
C++
General: Move ARM_Interface into Threads.
Fernando Sahmkowdb60ca2704b1
diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.hindex dc9b2ff7b9..e5c4843364 100644--- a/src/core/arm/arm_interface.h+++ b/src/core/arm/arm_interface.h@@ -148,6 +148,8 @@ public:*/virtual void SetTPIDR_EL0(u64 value) = 0;+ virtual void ChangeProcessorId(std::size_t new_core_id) = 0;+virtual void SaveContext(ThreadContext32& ctx) = 0;virtual void SaveContext(ThreadContext64& ctx) = 0;virtual void LoadContext(const ThreadContext32& ctx) = 0;diff --git a/src/core/arm/dynarmic/arm_dynarmic_32.cpp b/src/core/arm/dynarmic/arm_dynarmic_32.cppindex f36c5f4017..9c47c133c9 100644--- a/src/core/arm/dynarmic/arm_dynarmic_32.cpp+++ b/src/core/arm/dynarmic/arm_dynarmic_32.cpp@@ -165,6 +165,10 @@ void ARM_Dynarmic_32::SetTPIDR_EL0(u64 value) {cp15->uprw = static_cast<u32>(value);}+void ARM_Dynarmic_32::ChangeProcessorId(std::size_t new_core_id) {+ // jit->ChangeProcessorId(new_core_id);+}+void ARM_Dynarmic_32::SaveContext(ThreadContext32& ctx) {Dynarmic::A32::Context context;jit->SaveContext(context);diff --git a/src/core/arm/dynarmic/arm_dynarmic_32.h b/src/core/arm/dynarmic/arm_dynarmic_32.hindex 2dd9a4df0e..bea4933c81 100644--- a/src/core/arm/dynarmic/arm_dynarmic_32.h+++ b/src/core/arm/dynarmic/arm_dynarmic_32.h@@ -47,6 +47,7 @@ public:void SetTlsAddress(VAddr address) override;void SetTPIDR_EL0(u64 value) override;u64 GetTPIDR_EL0() const override;+ void ChangeProcessorId(std::size_t new_core_id) override;void SaveContext(ThreadContext32& ctx) override;void SaveContext(ThreadContext64& ctx) override {}diff --git a/src/core/arm/dynarmic/arm_dynarmic_64.cpp b/src/core/arm/dynarmic/arm_dynarmic_64.cppindex 8401ba631e..03b3313cf1 100644--- a/src/core/arm/dynarmic/arm_dynarmic_64.cpp+++ b/src/core/arm/dynarmic/arm_dynarmic_64.cpp@@ -258,6 +258,10 @@ void ARM_Dynarmic_64::SetTPIDR_EL0(u64 value) {cb->tpidr_el0 = value;}+void ARM_Dynarmic_64::ChangeProcessorId(std::size_t new_core_id) {+ jit->ChangeProcessorId(new_core_id);+}+void ARM_Dynarmic_64::SaveContext(ThreadContext64& ctx) {ctx.cpu_registers = jit->GetRegisters();ctx.sp = jit->GetSP();diff --git a/src/core/arm/dynarmic/arm_dynarmic_64.h b/src/core/arm/dynarmic/arm_dynarmic_64.hindex 1c6791d4e5..c26b47249c 100644--- a/src/core/arm/dynarmic/arm_dynarmic_64.h+++ b/src/core/arm/dynarmic/arm_dynarmic_64.h@@ -46,6 +46,7 @@ public:void SetTlsAddress(VAddr address) override;void SetTPIDR_EL0(u64 value) override;u64 GetTPIDR_EL0() const override;+ void ChangeProcessorId(std::size_t new_core_id) override;void SaveContext(ThreadContext32& ctx) override {}void SaveContext(ThreadContext64& ctx) override;diff --git a/src/core/arm/unicorn/arm_unicorn.cpp b/src/core/arm/unicorn/arm_unicorn.cppindex d81d1b5b08..099229c8d4 100644--- a/src/core/arm/unicorn/arm_unicorn.cpp+++ b/src/core/arm/unicorn/arm_unicorn.cpp@@ -159,6 +159,10 @@ void ARM_Unicorn::SetTPIDR_EL0(u64 value) {CHECKED(uc_reg_write(uc, UC_ARM64_REG_TPIDR_EL0, &value));}+void ARM_Unicorn::ChangeProcessorId(std::size_t new_core_id) {+ core_index = new_core_id;+}+void ARM_Unicorn::Run() {if (GDBStub::IsServerEnabled()) {ExecuteInstructions(std::max(4000000U, 0U));diff --git a/src/core/arm/unicorn/arm_unicorn.h b/src/core/arm/unicorn/arm_unicorn.hindex e3da368de9..f09b24a850 100644--- a/src/core/arm/unicorn/arm_unicorn.h+++ b/src/core/arm/unicorn/arm_unicorn.h@@ -36,6 +36,7 @@ public:void SetTlsAddress(VAddr address) override;void SetTPIDR_EL0(u64 value) override;u64 GetTPIDR_EL0() const override;+ void ChangeProcessorId(std::size_t new_core_id) override;void PrepareReschedule() override;void ClearExclusiveState() override;void ExecuteInstructions(std::size_t num_instructions);diff --git a/src/core/core.cpp b/src/core/core.cppindex 2ca9c0be54..40eea297ef 100644--- a/src/core/core.cpp+++ b/src/core/core.cpp@@ -119,14 +119,6 @@ struct System::Impl {: kernel{system}, fs_controller{system}, memory{system},cpu_manager{system}, reporter{system}, applet_manager{system} {}- Kernel::PhysicalCore& CurrentPhysicalCore() {- return kernel.CurrentPhysicalCore();- }-- Kernel::PhysicalCore& GetPhysicalCore(std::size_t index) {- return kernel.PhysicalCore(index);- }-ResultStatus Run() {status = ResultStatus::Success;@@ -443,7 +435,7 @@ bool System::IsPoweredOn() const {}void System::PrepareReschedule() {- impl->CurrentPhysicalCore().Stop();+ //impl->CurrentPhysicalCore().Stop();}void System::PrepareReschedule(const u32 core_index) {@@ -463,11 +455,11 @@ const TelemetrySession& System::TelemetrySession() const {}ARM_Interface& System::CurrentArmInterface() {- return impl->CurrentPhysicalCore().ArmInterface();+ return impl->kernel.CurrentScheduler().GetCurrentThread()->ArmInterface();}const ARM_Interface& System::CurrentArmInterface() const {- return impl->CurrentPhysicalCore().ArmInterface();+ return impl->kernel.CurrentScheduler().GetCurrentThread()->ArmInterface();}std::size_t System::CurrentCoreIndex() const {@@ -477,27 +469,27 @@ std::size_t System::CurrentCoreIndex() const {}Kernel::Scheduler& System::CurrentScheduler() {- return impl->CurrentPhysicalCore().Scheduler();+ return impl->kernel.CurrentScheduler();}const Kernel::Scheduler& System::CurrentScheduler() const {- return impl->CurrentPhysicalCore().Scheduler();+ return impl->kernel.CurrentScheduler();}Kernel::PhysicalCore& System::CurrentPhysicalCore() {- return impl->CurrentPhysicalCore();+ return impl->kernel.CurrentPhysicalCore();}const Kernel::PhysicalCore& System::CurrentPhysicalCore() const {- return impl->CurrentPhysicalCore();+ return impl->kernel.CurrentPhysicalCore();}Kernel::Scheduler& System::Scheduler(std::size_t core_index) {- return impl->GetPhysicalCore(core_index).Scheduler();+ return impl->kernel.Scheduler(core_index);}const Kernel::Scheduler& System::Scheduler(std::size_t core_index) const {- return impl->GetPhysicalCore(core_index).Scheduler();+ return impl->kernel.Scheduler(core_index);}/// Gets the global scheduler@@ -527,11 +519,15 @@ const Kernel::Process* System::CurrentProcess() const {}ARM_Interface& System::ArmInterface(std::size_t core_index) {- return impl->GetPhysicalCore(core_index).ArmInterface();+ auto* thread = impl->kernel.Scheduler(core_index).GetCurrentThread();+ ASSERT(thread && !thread->IsHLEThread());+ return thread->ArmInterface();}const ARM_Interface& System::ArmInterface(std::size_t core_index) const {- return impl->GetPhysicalCore(core_index).ArmInterface();+ auto* thread = impl->kernel.Scheduler(core_index).GetCurrentThread();+ ASSERT(thread && !thread->IsHLEThread());+ return thread->ArmInterface();}ExclusiveMonitor& System::Monitor() {diff --git a/src/core/core_manager.cpp b/src/core/core_manager.cppindex 45f0bb5470..82d7acb406 100644--- a/src/core/core_manager.cpp+++ b/src/core/core_manager.cpp@@ -28,21 +28,7 @@ CoreManager::CoreManager(System& system, std::size_t core_index)CoreManager::~CoreManager() = default;void CoreManager::RunLoop(bool tight_loop) {- Reschedule();-- // If we don't have a currently active thread then don't execute instructions,- // instead advance to the next event and try to yield to the next thread- if (Kernel::GetCurrentThread() == nullptr) {- LOG_TRACE(Core, "Core-{} idling", core_index);- } else {- if (tight_loop) {- physical_core.Run();- } else {- physical_core.Step();- }- }-- Reschedule();+ /// Deprecated}void CoreManager::SingleStep() {@@ -50,7 +36,7 @@ void CoreManager::SingleStep() {}void CoreManager::PrepareReschedule() {- physical_core.Stop();+ //physical_core.Stop();}void CoreManager::Reschedule() {diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cppindex 2aea95a257..2e9dc9dc3d 100644--- a/src/core/cpu_manager.cpp+++ b/src/core/cpu_manager.cpp@@ -129,18 +129,17 @@ void CpuManager::MultiCoreRunGuestThread() {void CpuManager::MultiCoreRunGuestLoop() {auto& kernel = system.Kernel();auto* thread = kernel.CurrentScheduler().GetCurrentThread();- auto host_context = thread->GetHostContext();- host_context->SetRewindPoint(std::function<void(void*)>(GuestRewindFunction), this);- host_context.reset();while (true) {- auto& physical_core = kernel.CurrentPhysicalCore();+ auto* physical_core = &kernel.CurrentPhysicalCore();+ auto& arm_interface = thread->ArmInterface();system.EnterDynarmicProfile();- while (!physical_core.IsInterrupted()) {- physical_core.Run();+ while (!physical_core->IsInterrupted()) {+ arm_interface.Run();+ physical_core = &kernel.CurrentPhysicalCore();}system.ExitDynarmicProfile();- physical_core.ClearExclusive();- auto& scheduler = physical_core.Scheduler();+ arm_interface.ClearExclusiveState();+ auto& scheduler = kernel.CurrentScheduler();scheduler.TryDoContextSwitch();}}@@ -150,7 +149,7 @@ void CpuManager::MultiCoreRunIdleThread() {while (true) {auto& physical_core = kernel.CurrentPhysicalCore();physical_core.Idle();- auto& scheduler = physical_core.Scheduler();+ auto& scheduler = kernel.CurrentScheduler();scheduler.TryDoContextSwitch();}}@@ -229,14 +228,13 @@ void CpuManager::SingleCoreRunGuestThread() {void CpuManager::SingleCoreRunGuestLoop() {auto& kernel = system.Kernel();auto* thread = kernel.CurrentScheduler().GetCurrentThread();- auto host_context = thread->GetHostContext();- host_context->SetRewindPoint(std::function<void(void*)>(GuestRewindFunction), this);- host_context.reset();while (true) {- auto& physical_core = kernel.CurrentPhysicalCore();+ auto* physical_core = &kernel.CurrentPhysicalCore();+ auto& arm_interface = thread->ArmInterface();system.EnterDynarmicProfile();- while (!physical_core.IsInterrupted()) {- physical_core.Run();+ while (!physical_core->IsInterrupted()) {+ arm_interface.Run();+ physical_core = &kernel.CurrentPhysicalCore();preemption_count++;if (preemption_count % max_cycle_runs == 0) {break;@@ -246,7 +244,7 @@ void CpuManager::SingleCoreRunGuestLoop() {thread->SetPhantomMode(true);system.CoreTiming().Advance();thread->SetPhantomMode(false);- physical_core.ClearExclusive();+ arm_interface.ClearExclusiveState();PreemptSingleCore();auto& scheduler = kernel.Scheduler(current_core);scheduler.TryDoContextSwitch();diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cppindex e33ef53238..3feddd9ad8 100644--- a/src/core/hle/kernel/kernel.cpp+++ b/src/core/hle/kernel/kernel.cpp@@ -19,7 +19,6 @@#include "core/arm/arm_interface.h"#include "core/arm/cpu_interrupt_handler.h"#include "core/arm/exclusive_monitor.h"-#include "core/arm/unicorn/arm_unicorn.h"#include "core/core.h"#include "core/core_timing.h"#include "core/core_timing_util.h"@@ -45,11 +44,6 @@#include "core/hle/result.h"#include "core/memory.h"-#ifdef ARCHITECTURE_x86_64-#include "core/arm/dynarmic/arm_dynarmic_32.h"-#include "core/arm/dynarmic/arm_dynarmic_64.h"-#endif-MICROPROFILE_DEFINE(Kernel_SVC, "Kernel", "SVC", MP_RGB(70, 200, 70));namespace Kernel {@@ -186,20 +180,8 @@ struct KernelCore::Impl {exclusive_monitor =Core::MakeExclusiveMonitor(system.Memory(), Core::Hardware::NUM_CPU_CORES);for (std::size_t i = 0; i < Core::Hardware::NUM_CPU_CORES; i++) {-#ifdef ARCHITECTURE_x86_64- arm_interfaces_32[i] =- std::make_unique<Core::ARM_Dynarmic_32>(system, interrupts, *exclusive_monitor, i);- arm_interfaces_64[i] =- std::make_unique<Core::ARM_Dynarmic_64>(system, interrupts, *exclusive_monitor, i);-#else- arm_interfaces_32[i] = std::make_shared<Core::ARM_Unicorn>(- system, interrupts, ARM_Unicorn::Arch::AArch32, i);- arm_interfaces_64[i] = std::make_shared<Core::ARM_Unicorn>(- system, interrupts, ARM_Unicorn::Arch::AArch64, i);- LOG_WARNING(Core, "CPU JIT requested, but Dynarmic not available");-#endif- cores.emplace_back(system, i, *exclusive_monitor, interrupts[i], *arm_interfaces_32[i],- *arm_interfaces_64[i]);+ schedulers[i] = std::make_unique<Kernel::Scheduler>(system, i);+ cores.emplace_back(system, i, *schedulers[i], interrupts[i]);}}@@ -268,10 +250,6 @@ struct KernelCore::Impl {return;}- for (auto& core : cores) {- core.SetIs64Bit(process->Is64BitProcess());- }-u32 core_id = GetCurrentHostThreadID();if (core_id < Core::Hardware::NUM_CPU_CORES) {system.Memory().SetCurrentPageTable(*process, core_id);@@ -429,10 +407,7 @@ struct KernelCore::Impl {std::array<std::shared_ptr<Thread>, Core::Hardware::NUM_CPU_CORES> suspend_threads{};std::array<Core::CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES> interrupts{};- std::array<std::unique_ptr<Core::ARM_Interface>, Core::Hardware::NUM_CPU_CORES>- arm_interfaces_32{};- std::array<std::unique_ptr<Core::ARM_Interface>, Core::Hardware::NUM_CPU_CORES>- arm_interfaces_64{};+ std::array<std::unique_ptr<Kernel::Scheduler>, Core::Hardware::NUM_CPU_CORES> schedulers{};bool is_multicore{};std::thread::id single_core_thread_id{};@@ -497,11 +472,11 @@ const Kernel::GlobalScheduler& KernelCore::GlobalScheduler() const {}Kernel::Scheduler& KernelCore::Scheduler(std::size_t id) {- return impl->cores[id].Scheduler();+ return *impl->schedulers[id];}const Kernel::Scheduler& KernelCore::Scheduler(std::size_t id) const {- return impl->cores[id].Scheduler();+ return *impl->schedulers[id];}Kernel::PhysicalCore& KernelCore::PhysicalCore(std::size_t id) {@@ -525,11 +500,23 @@ const Kernel::PhysicalCore& KernelCore::CurrentPhysicalCore() const {}Kernel::Scheduler& KernelCore::CurrentScheduler() {- return CurrentPhysicalCore().Scheduler();+ u32 core_id = impl->GetCurrentHostThreadID();+ ASSERT(core_id < Core::Hardware::NUM_CPU_CORES);+ return *impl->schedulers[core_id];}const Kernel::Scheduler& KernelCore::CurrentScheduler() const {- return CurrentPhysicalCore().Scheduler();+ u32 core_id = impl->GetCurrentHostThreadID();+ ASSERT(core_id < Core::Hardware::NUM_CPU_CORES);+ return *impl->schedulers[core_id];+}++std::array<Core::CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES>& KernelCore::Interrupts() {+ return impl->interrupts;+}++const std::array<Core::CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES>& KernelCore::Interrupts() const {+ return impl->interrupts;}Kernel::Synchronization& KernelCore::Synchronization() {@@ -557,15 +544,11 @@ const Core::ExclusiveMonitor& KernelCore::GetExclusiveMonitor() const {}void KernelCore::InvalidateAllInstructionCaches() {- for (std::size_t i = 0; i < impl->global_scheduler.CpuCoresCount(); i++) {- PhysicalCore(i).ArmInterface().ClearInstructionCache();- }+ //TODO: Reimplement, this}void KernelCore::PrepareReschedule(std::size_t id) {- if (id < impl->global_scheduler.CpuCoresCount()) {- impl->cores[id].Stop();- }+ // TODO: Reimplement, this}void KernelCore::AddNamedPort(std::string name, std::shared_ptr<ClientPort> port) {diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.hindex 1eb6ede73e..846056b85a 100644--- a/src/core/hle/kernel/kernel.h+++ b/src/core/hle/kernel/kernel.h@@ -4,15 +4,17 @@#pragma once+#include <array>#include <memory>#include <string>#include <unordered_map>#include <vector>+#include "core/hardware_properties.h"#include "core/hle/kernel/memory/memory_types.h"#include "core/hle/kernel/object.h"namespace Core {-struct EmuThreadHandle;+class CPUInterruptHandler;class ExclusiveMonitor;class System;} // namespace Core@@ -144,6 +146,10 @@ public:const Core::ExclusiveMonitor& GetExclusiveMonitor() const;+ std::array<Core::CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES>& Interrupts();++ const std::array<Core::CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES>& Interrupts() const;+void InvalidateAllInstructionCaches();/// Adds a port to the named port tablediff --git a/src/core/hle/kernel/physical_core.cpp b/src/core/hle/kernel/physical_core.cppindex 9146b331d4..c82c60a16d 100644--- a/src/core/hle/kernel/physical_core.cpp+++ b/src/core/hle/kernel/physical_core.cpp@@ -20,50 +20,21 @@namespace Kernel {-PhysicalCore::PhysicalCore(Core::System& system, std::size_t id,- Core::ExclusiveMonitor& exclusive_monitor,- Core::CPUInterruptHandler& interrupt_handler,- Core::ARM_Interface& arm_interface32,- Core::ARM_Interface& arm_interface64)- : interrupt_handler{interrupt_handler}, core_index{id}, arm_interface_32{arm_interface32},- arm_interface_64{arm_interface64} {+PhysicalCore::PhysicalCore(Core::System& system, std::size_t id, Kernel::Scheduler& scheduler,+ Core::CPUInterruptHandler& interrupt_handler)+ : interrupt_handler{interrupt_handler}, core_index{id}, scheduler{scheduler} {- scheduler = std::make_unique<Kernel::Scheduler>(system, core_index);guard = std::make_unique<Common::SpinLock>();}PhysicalCore::~PhysicalCore() = default;-void PhysicalCore::Run() {- arm_interface->Run();-}--void PhysicalCore::ClearExclusive() {- arm_interface->ClearExclusiveState();-}--void PhysicalCore::Step() {- arm_interface->Step();-}-void PhysicalCore::Idle() {interrupt_handler.AwaitInterrupt();}-void PhysicalCore::Stop() {- arm_interface->PrepareReschedule();-}-void PhysicalCore::Shutdown() {- scheduler->Shutdown();-}--void PhysicalCore::SetIs64Bit(bool is_64_bit) {- if (is_64_bit) {- arm_interface = &arm_interface_64;- } else {- arm_interface = &arm_interface_32;- }+ scheduler.Shutdown();}void PhysicalCore::Interrupt() {diff --git a/src/core/hle/kernel/physical_core.h b/src/core/hle/kernel/physical_core.hindex 2673d90f28..751b994a78 100644--- a/src/core/hle/kernel/physical_core.h+++ b/src/core/hle/kernel/physical_core.h@@ -10,7 +10,7 @@#include "core/arm/cpu_interrupt_handler.h"namespace Common {-class SpinLock;+ class SpinLock;}namespace Kernel {@@ -27,9 +27,9 @@ namespace Kernel {class PhysicalCore {public:- PhysicalCore(Core::System& system, std::size_t id, Core::ExclusiveMonitor& exclusive_monitor,- Core::CPUInterruptHandler& interrupt_handler, Core::ARM_Interface& arm_interface32,- Core::ARM_Interface& arm_interface64);+ PhysicalCore(Core::System& system, std::size_t id,+ Kernel::Scheduler& scheduler,+ Core::CPUInterruptHandler& interrupt_handler);~PhysicalCore();PhysicalCore(const PhysicalCore&) = delete;@@ -38,17 +38,7 @@ public:PhysicalCore(PhysicalCore&&) = default;PhysicalCore& operator=(PhysicalCore&&) = default;- /// Execute current jit state- void Run();- /// Clear Exclusive state.- void ClearExclusive();- /// Set this core in IdleState.void Idle();- /// Execute a single instruction in current jit.- void Step();- /// Stop JIT execution/exit- void Stop();-/// Interrupt this physical core.void Interrupt();@@ -63,14 +53,6 @@ public:// Shutdown this physical core.void Shutdown();- Core::ARM_Interface& ArmInterface() {- return *arm_interface;- }-- const Core::ARM_Interface& ArmInterface() const {- return *arm_interface;- }-bool IsMainCore() const {return core_index == 0;}@@ -84,22 +66,17 @@ public:}Kernel::Scheduler& Scheduler() {- return *scheduler;+ return scheduler;}const Kernel::Scheduler& Scheduler() const {- return *scheduler;+ return scheduler;}- void SetIs64Bit(bool is_64_bit);-private:Core::CPUInterruptHandler& interrupt_handler;std::size_t core_index;- Core::ARM_Interface& arm_interface_32;- Core::ARM_Interface& arm_interface_64;- std::unique_ptr<Kernel::Scheduler> scheduler;- Core::ARM_Interface* arm_interface{};+ Kernel::Scheduler& scheduler;std::unique_ptr<Common::SpinLock> guard;};diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cppindex 8d56b49ce6..a5083ae7c4 100644--- a/src/core/hle/kernel/scheduler.cpp+++ b/src/core/hle/kernel/scheduler.cpp@@ -681,15 +681,16 @@ void Scheduler::SwitchContextStep2() {new_thread->SetWasRunning(false);auto* const thread_owner_process = current_thread->GetOwnerProcess();- if (previous_process != thread_owner_process && thread_owner_process != nullptr) {+ if (thread_owner_process != nullptr) {system.Kernel().MakeCurrentProcess(thread_owner_process);}if (!new_thread->IsHLEThread()) {- auto& cpu_core = system.ArmInterface(core_id);+ Core::ARM_Interface& cpu_core = new_thread->ArmInterface();cpu_core.LoadContext(new_thread->GetContext32());cpu_core.LoadContext(new_thread->GetContext64());cpu_core.SetTlsAddress(new_thread->GetTLSAddress());cpu_core.SetTPIDR_EL0(new_thread->GetTPIDR_EL0());+ cpu_core.ChangeProcessorId(this->core_id);cpu_core.ClearExclusiveState();}}@@ -722,18 +723,15 @@ void Scheduler::SwitchContext() {}previous_thread->SetContinuousOnSVC(false);previous_thread->last_running_ticks = system.CoreTiming().GetCPUTicks();+ previous_thread->SetIsRunning(false);if (!previous_thread->IsHLEThread()) {- auto& cpu_core = system.ArmInterface(core_id);+ Core::ARM_Interface& cpu_core = previous_thread->ArmInterface();cpu_core.SaveContext(previous_thread->GetContext32());cpu_core.SaveContext(previous_thread->GetContext64());// Save the TPIDR_EL0 system register in case it was modified.previous_thread->SetTPIDR_EL0(cpu_core.GetTPIDR_EL0());cpu_core.ClearExclusiveState();}- if (previous_thread->GetStatus() == ThreadStatus::Running) {- previous_thread->SetStatus(ThreadStatus::Ready);- }- previous_thread->SetIsRunning(false);previous_thread->context_guard.unlock();}diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cppindex f087452262..5999722119 100644--- a/src/core/hle/kernel/svc.cpp+++ b/src/core/hle/kernel/svc.cpp@@ -1533,7 +1533,9 @@ static void SleepThread(Core::System& system, s64 nanoseconds) {}if (is_redundant && !system.Kernel().IsMulticore()) {+ system.Kernel().ExitSVCProfile();system.GetCpuManager().PreemptSingleCore();+ system.Kernel().EnterSVCProfile();}}@@ -2457,9 +2459,6 @@ void Call(Core::System& system, u32 immediate) {auto& kernel = system.Kernel();kernel.EnterSVCProfile();- auto* thread = system.CurrentScheduler().GetCurrentThread();- thread->SetContinuousOnSVC(true);-const FunctionDef* info = system.CurrentProcess()->Is64BitProcess() ? GetSVCInfo64(immediate): GetSVCInfo32(immediate);if (info) {@@ -2473,12 +2472,6 @@ void Call(Core::System& system, u32 immediate) {}kernel.ExitSVCProfile();-- if (!thread->IsContinuousOnSVC()) {- auto* host_context = thread->GetHostContext().get();- host_context->Rewind();- }-system.EnterDynarmicProfile();}diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cppindex 6f8e7a070a..58b06aa9ec 100644--- a/src/core/hle/kernel/thread.cpp+++ b/src/core/hle/kernel/thread.cpp@@ -13,6 +13,13 @@#include "common/logging/log.h"#include "common/thread_queue_list.h"#include "core/arm/arm_interface.h"+#ifdef ARCHITECTURE_x86_64+#include "core/arm/dynarmic/arm_dynarmic_32.h"+#include "core/arm/dynarmic/arm_dynarmic_64.h"+#endif+#include "core/arm/cpu_interrupt_handler.h"+#include "core/arm/exclusive_monitor.h"+#include "core/arm/unicorn/arm_unicorn.h"#include "core/core.h"#include "core/core_timing.h"#include "core/core_timing_util.h"@@ -232,7 +239,27 @@ ResultVal<std::shared_ptr<Thread>> Thread::Create(Core::System& system, ThreadTy}// TODO(peachum): move to ScheduleThread() when scheduler is added so selected core is used// to initialize the context+ thread->arm_interface.reset();if ((type_flags & THREADTYPE_HLE) == 0) {+#ifdef ARCHITECTURE_x86_64+ if (owner_process && !owner_process->Is64BitProcess()) {+ thread->arm_interface = std::make_unique<Core::ARM_Dynarmic_32>(+ system, kernel.Interrupts(), kernel.GetExclusiveMonitor(), processor_id);+ } else {+ thread->arm_interface = std::make_unique<Core::ARM_Dynarmic_64>(+ system, kernel.Interrupts(), kernel.GetExclusiveMonitor(), processor_id);+ }++#else+ if (owner_process && !owner_process->Is64BitProcess()) {+ thread->arm_interface = std::make_shared<Core::ARM_Unicorn>(+ system, kernel.Interrupts(), ARM_Unicorn::Arch::AArch32, processor_id);+ } else {+ thread->arm_interface = std::make_shared<Core::ARM_Unicorn>(+ system, kernel.Interrupts(), ARM_Unicorn::Arch::AArch64, processor_id);+ }+ LOG_WARNING(Core, "CPU JIT requested, but Dynarmic not available");+#endifResetThreadContext32(thread->context_32, static_cast<u32>(stack_top),static_cast<u32>(entry_point), static_cast<u32>(arg));ResetThreadContext64(thread->context_64, stack_top, entry_point, arg);@@ -276,6 +303,14 @@ VAddr Thread::GetCommandBufferAddress() const {return GetTLSAddress() + command_header_offset;}+Core::ARM_Interface& Thread::ArmInterface() {+ return *arm_interface;+}++const Core::ARM_Interface& Thread::ArmInterface() const {+ return *arm_interface;+}+void Thread::SetStatus(ThreadStatus new_status) {if (new_status == status) {return;diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.hindex f998890c4b..c08fc3a894 100644--- a/src/core/hle/kernel/thread.h+++ b/src/core/hle/kernel/thread.h@@ -21,6 +21,7 @@ class Fiber;}namespace Core {+class ARM_Interface;class System;} // namespace Core@@ -271,6 +272,10 @@ public:void SetSynchronizationResults(SynchronizationObject* object, ResultCode result);+ Core::ARM_Interface& ArmInterface();++ const Core::ARM_Interface& ArmInterface() const;+SynchronizationObject* GetSignalingObject() const {return signaling_object;}@@ -617,9 +622,10 @@ private:void AdjustSchedulingOnAffinity(u64 old_affinity_mask, s32 old_core);+ Common::SpinLock context_guard{};ThreadContext32 context_32{};ThreadContext64 context_64{};- Common::SpinLock context_guard{};+ std::unique_ptr<Core::ARM_Interface> arm_interface{};std::shared_ptr<Common::Fiber> host_context{};u64 thread_id = 0;