summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar bunnei2020-11-13 11:11:12 -0800
committerGravatar bunnei2020-11-29 01:31:51 -0800
commit7b642c77811dc3887756f5abac5a9710564b098e (patch)
tree09c9d764734db56896f77d986afa6ccd5d2c745d /src/core
parentMerge pull request #4998 from Morph1984/bioshock-patch (diff)
downloadyuzu-7b642c77811dc3887756f5abac5a9710564b098e.tar.gz
yuzu-7b642c77811dc3887756f5abac5a9710564b098e.tar.xz
yuzu-7b642c77811dc3887756f5abac5a9710564b098e.zip
hle: kernel: multicore: Replace n-JITs impl. with 4 JITs.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/arm/arm_interface.h3
-rw-r--r--src/core/arm/dynarmic/arm_dynarmic_32.cpp4
-rw-r--r--src/core/arm/dynarmic/arm_dynarmic_32.h1
-rw-r--r--src/core/arm/dynarmic/arm_dynarmic_64.cpp4
-rw-r--r--src/core/arm/dynarmic/arm_dynarmic_64.h1
-rw-r--r--src/core/core.cpp13
-rw-r--r--src/core/cpu_manager.cpp16
-rw-r--r--src/core/hle/kernel/kernel.cpp23
-rw-r--r--src/core/hle/kernel/kernel.h3
-rw-r--r--src/core/hle/kernel/physical_core.cpp38
-rw-r--r--src/core/hle/kernel/physical_core.h29
-rw-r--r--src/core/hle/kernel/scheduler.cpp20
-rw-r--r--src/core/hle/kernel/svc.cpp9
-rw-r--r--src/core/hle/kernel/thread.cpp27
-rw-r--r--src/core/hle/kernel/thread.h5
15 files changed, 124 insertions, 72 deletions
diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.h
index 1f24051e4..b3d8ceaf8 100644
--- a/src/core/arm/arm_interface.h
+++ b/src/core/arm/arm_interface.h
@@ -64,6 +64,9 @@ public:
64 /// Step CPU by one instruction 64 /// Step CPU by one instruction
65 virtual void Step() = 0; 65 virtual void Step() = 0;
66 66
67 /// Exits execution from a callback, the callback must rewind the stack
68 virtual void ExceptionalExit() = 0;
69
67 /// Clear all instruction cache 70 /// Clear all instruction cache
68 virtual void ClearInstructionCache() = 0; 71 virtual void ClearInstructionCache() = 0;
69 72
diff --git a/src/core/arm/dynarmic/arm_dynarmic_32.cpp b/src/core/arm/dynarmic/arm_dynarmic_32.cpp
index 6dc03f3b1..af23206f5 100644
--- a/src/core/arm/dynarmic/arm_dynarmic_32.cpp
+++ b/src/core/arm/dynarmic/arm_dynarmic_32.cpp
@@ -189,6 +189,10 @@ void ARM_Dynarmic_32::Run() {
189 jit->Run(); 189 jit->Run();
190} 190}
191 191
192void ARM_Dynarmic_32::ExceptionalExit() {
193 jit->ExceptionalExit();
194}
195
192void ARM_Dynarmic_32::Step() { 196void ARM_Dynarmic_32::Step() {
193 jit->Step(); 197 jit->Step();
194} 198}
diff --git a/src/core/arm/dynarmic/arm_dynarmic_32.h b/src/core/arm/dynarmic/arm_dynarmic_32.h
index 2bab31b92..e16b689c8 100644
--- a/src/core/arm/dynarmic/arm_dynarmic_32.h
+++ b/src/core/arm/dynarmic/arm_dynarmic_32.h
@@ -42,6 +42,7 @@ public:
42 u32 GetPSTATE() const override; 42 u32 GetPSTATE() const override;
43 void SetPSTATE(u32 pstate) override; 43 void SetPSTATE(u32 pstate) override;
44 void Run() override; 44 void Run() override;
45 void ExceptionalExit() override;
45 void Step() override; 46 void Step() override;
46 VAddr GetTlsAddress() const override; 47 VAddr GetTlsAddress() const override;
47 void SetTlsAddress(VAddr address) override; 48 void SetTlsAddress(VAddr address) override;
diff --git a/src/core/arm/dynarmic/arm_dynarmic_64.cpp b/src/core/arm/dynarmic/arm_dynarmic_64.cpp
index 5c2060d78..1c9fd18b5 100644
--- a/src/core/arm/dynarmic/arm_dynarmic_64.cpp
+++ b/src/core/arm/dynarmic/arm_dynarmic_64.cpp
@@ -220,6 +220,10 @@ void ARM_Dynarmic_64::Run() {
220 jit->Run(); 220 jit->Run();
221} 221}
222 222
223void ARM_Dynarmic_64::ExceptionalExit() {
224 jit->ExceptionalExit();
225}
226
223void ARM_Dynarmic_64::Step() { 227void ARM_Dynarmic_64::Step() {
224 cb->InterpreterFallback(jit->GetPC(), 1); 228 cb->InterpreterFallback(jit->GetPC(), 1);
225} 229}
diff --git a/src/core/arm/dynarmic/arm_dynarmic_64.h b/src/core/arm/dynarmic/arm_dynarmic_64.h
index 28e11a17d..aa0a5c424 100644
--- a/src/core/arm/dynarmic/arm_dynarmic_64.h
+++ b/src/core/arm/dynarmic/arm_dynarmic_64.h
@@ -40,6 +40,7 @@ public:
40 void SetPSTATE(u32 pstate) override; 40 void SetPSTATE(u32 pstate) override;
41 void Run() override; 41 void Run() override;
42 void Step() override; 42 void Step() override;
43 void ExceptionalExit() override;
43 VAddr GetTlsAddress() const override; 44 VAddr GetTlsAddress() const override;
44 void SetTlsAddress(VAddr address) override; 45 void SetTlsAddress(VAddr address) override;
45 void SetTPIDR_EL0(u64 value) override; 46 void SetTPIDR_EL0(u64 value) override;
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 76a38ea2a..58368fe3c 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -245,6 +245,7 @@ struct System::Impl {
245 } 245 }
246 AddGlueRegistrationForProcess(*app_loader, *main_process); 246 AddGlueRegistrationForProcess(*app_loader, *main_process);
247 kernel.MakeCurrentProcess(main_process.get()); 247 kernel.MakeCurrentProcess(main_process.get());
248 kernel.InitializeCores();
248 249
249 // Initialize cheat engine 250 // Initialize cheat engine
250 if (cheat_engine) { 251 if (cheat_engine) {
@@ -490,11 +491,11 @@ const TelemetrySession& System::TelemetrySession() const {
490} 491}
491 492
492ARM_Interface& System::CurrentArmInterface() { 493ARM_Interface& System::CurrentArmInterface() {
493 return impl->kernel.CurrentScheduler().GetCurrentThread()->ArmInterface(); 494 return impl->kernel.CurrentPhysicalCore().ArmInterface();
494} 495}
495 496
496const ARM_Interface& System::CurrentArmInterface() const { 497const ARM_Interface& System::CurrentArmInterface() const {
497 return impl->kernel.CurrentScheduler().GetCurrentThread()->ArmInterface(); 498 return impl->kernel.CurrentPhysicalCore().ArmInterface();
498} 499}
499 500
500std::size_t System::CurrentCoreIndex() const { 501std::size_t System::CurrentCoreIndex() const {
@@ -554,15 +555,11 @@ const Kernel::Process* System::CurrentProcess() const {
554} 555}
555 556
556ARM_Interface& System::ArmInterface(std::size_t core_index) { 557ARM_Interface& System::ArmInterface(std::size_t core_index) {
557 auto* thread = impl->kernel.Scheduler(core_index).GetCurrentThread(); 558 return impl->kernel.PhysicalCore(core_index).ArmInterface();
558 ASSERT(thread && !thread->IsHLEThread());
559 return thread->ArmInterface();
560} 559}
561 560
562const ARM_Interface& System::ArmInterface(std::size_t core_index) const { 561const ARM_Interface& System::ArmInterface(std::size_t core_index) const {
563 auto* thread = impl->kernel.Scheduler(core_index).GetCurrentThread(); 562 return impl->kernel.PhysicalCore(core_index).ArmInterface();
564 ASSERT(thread && !thread->IsHLEThread());
565 return thread->ArmInterface();
566} 563}
567 564
568ExclusiveMonitor& System::Monitor() { 565ExclusiveMonitor& System::Monitor() {
diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp
index eeeb6e8df..0cff985e9 100644
--- a/src/core/cpu_manager.cpp
+++ b/src/core/cpu_manager.cpp
@@ -113,22 +113,23 @@ void CpuManager::MultiCoreRunGuestThread() {
113 auto& sched = kernel.CurrentScheduler(); 113 auto& sched = kernel.CurrentScheduler();
114 sched.OnThreadStart(); 114 sched.OnThreadStart();
115 } 115 }
116 auto* thread = kernel.CurrentScheduler().GetCurrentThread();
117 auto& host_context = thread->GetHostContext();
118 host_context->SetRewindPoint(GuestRewindFunction, this);
116 MultiCoreRunGuestLoop(); 119 MultiCoreRunGuestLoop();
117} 120}
118 121
119void CpuManager::MultiCoreRunGuestLoop() { 122void CpuManager::MultiCoreRunGuestLoop() {
120 auto& kernel = system.Kernel(); 123 auto& kernel = system.Kernel();
121 auto* thread = kernel.CurrentScheduler().GetCurrentThread(); 124
122 while (true) { 125 while (true) {
123 auto* physical_core = &kernel.CurrentPhysicalCore(); 126 auto* physical_core = &kernel.CurrentPhysicalCore();
124 auto& arm_interface = thread->ArmInterface();
125 system.EnterDynarmicProfile(); 127 system.EnterDynarmicProfile();
126 while (!physical_core->IsInterrupted()) { 128 while (!physical_core->IsInterrupted()) {
127 arm_interface.Run(); 129 physical_core->Run();
128 physical_core = &kernel.CurrentPhysicalCore(); 130 physical_core = &kernel.CurrentPhysicalCore();
129 } 131 }
130 system.ExitDynarmicProfile(); 132 system.ExitDynarmicProfile();
131 arm_interface.ClearExclusiveState();
132 auto& scheduler = kernel.CurrentScheduler(); 133 auto& scheduler = kernel.CurrentScheduler();
133 scheduler.TryDoContextSwitch(); 134 scheduler.TryDoContextSwitch();
134 } 135 }
@@ -209,6 +210,9 @@ void CpuManager::SingleCoreRunGuestThread() {
209 auto& sched = kernel.CurrentScheduler(); 210 auto& sched = kernel.CurrentScheduler();
210 sched.OnThreadStart(); 211 sched.OnThreadStart();
211 } 212 }
213 auto* thread = kernel.CurrentScheduler().GetCurrentThread();
214 auto& host_context = thread->GetHostContext();
215 host_context->SetRewindPoint(GuestRewindFunction, this);
212 SingleCoreRunGuestLoop(); 216 SingleCoreRunGuestLoop();
213} 217}
214 218
@@ -217,17 +221,15 @@ void CpuManager::SingleCoreRunGuestLoop() {
217 auto* thread = kernel.CurrentScheduler().GetCurrentThread(); 221 auto* thread = kernel.CurrentScheduler().GetCurrentThread();
218 while (true) { 222 while (true) {
219 auto* physical_core = &kernel.CurrentPhysicalCore(); 223 auto* physical_core = &kernel.CurrentPhysicalCore();
220 auto& arm_interface = thread->ArmInterface();
221 system.EnterDynarmicProfile(); 224 system.EnterDynarmicProfile();
222 if (!physical_core->IsInterrupted()) { 225 if (!physical_core->IsInterrupted()) {
223 arm_interface.Run(); 226 physical_core->Run();
224 physical_core = &kernel.CurrentPhysicalCore(); 227 physical_core = &kernel.CurrentPhysicalCore();
225 } 228 }
226 system.ExitDynarmicProfile(); 229 system.ExitDynarmicProfile();
227 thread->SetPhantomMode(true); 230 thread->SetPhantomMode(true);
228 system.CoreTiming().Advance(); 231 system.CoreTiming().Advance();
229 thread->SetPhantomMode(false); 232 thread->SetPhantomMode(false);
230 arm_interface.ClearExclusiveState();
231 PreemptSingleCore(); 233 PreemptSingleCore();
232 auto& scheduler = kernel.Scheduler(current_core); 234 auto& scheduler = kernel.Scheduler(current_core);
233 scheduler.TryDoContextSwitch(); 235 scheduler.TryDoContextSwitch();
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index bb3e312a7..4cf9cee42 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -68,6 +68,12 @@ struct KernelCore::Impl {
68 InitializeSuspendThreads(); 68 InitializeSuspendThreads();
69 } 69 }
70 70
71 void InitializeCores() {
72 for (auto& core : cores) {
73 core.Initialize(current_process->Is64BitProcess());
74 }
75 }
76
71 void Shutdown() { 77 void Shutdown() {
72 next_object_id = 0; 78 next_object_id = 0;
73 next_kernel_process_id = Process::InitialKIPIDMin; 79 next_kernel_process_id = Process::InitialKIPIDMin;
@@ -116,7 +122,7 @@ struct KernelCore::Impl {
116 Core::MakeExclusiveMonitor(system.Memory(), Core::Hardware::NUM_CPU_CORES); 122 Core::MakeExclusiveMonitor(system.Memory(), Core::Hardware::NUM_CPU_CORES);
117 for (std::size_t i = 0; i < Core::Hardware::NUM_CPU_CORES; i++) { 123 for (std::size_t i = 0; i < Core::Hardware::NUM_CPU_CORES; i++) {
118 schedulers[i] = std::make_unique<Kernel::Scheduler>(system, i); 124 schedulers[i] = std::make_unique<Kernel::Scheduler>(system, i);
119 cores.emplace_back(system, i, *schedulers[i], interrupts[i]); 125 cores.emplace_back(i, system, *schedulers[i], interrupts);
120 } 126 }
121 } 127 }
122 128
@@ -181,6 +187,7 @@ struct KernelCore::Impl {
181 if (process == nullptr) { 187 if (process == nullptr) {
182 return; 188 return;
183 } 189 }
190
184 const u32 core_id = GetCurrentHostThreadID(); 191 const u32 core_id = GetCurrentHostThreadID();
185 if (core_id < Core::Hardware::NUM_CPU_CORES) { 192 if (core_id < Core::Hardware::NUM_CPU_CORES) {
186 system.Memory().SetCurrentPageTable(*process, core_id); 193 system.Memory().SetCurrentPageTable(*process, core_id);
@@ -372,6 +379,10 @@ void KernelCore::Initialize() {
372 impl->Initialize(*this); 379 impl->Initialize(*this);
373} 380}
374 381
382void KernelCore::InitializeCores() {
383 impl->InitializeCores();
384}
385
375void KernelCore::Shutdown() { 386void KernelCore::Shutdown() {
376 impl->Shutdown(); 387 impl->Shutdown();
377} 388}
@@ -486,12 +497,12 @@ const Core::ExclusiveMonitor& KernelCore::GetExclusiveMonitor() const {
486} 497}
487 498
488void KernelCore::InvalidateAllInstructionCaches() { 499void KernelCore::InvalidateAllInstructionCaches() {
489 auto& threads = GlobalScheduler().GetThreadList(); 500 if (!IsMulticore()) {
490 for (auto& thread : threads) { 501 for (auto& physical_core : impl->cores) {
491 if (!thread->IsHLEThread()) { 502 physical_core.ArmInterface().ClearInstructionCache();
492 auto& arm_interface = thread->ArmInterface();
493 arm_interface.ClearInstructionCache();
494 } 503 }
504 } else {
505 ASSERT_MSG(false, "UNIMPLEMENTED!!!!!!!!!!!");
495 } 506 }
496} 507}
497 508
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index 16285c3f0..a9fdc5860 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -74,6 +74,9 @@ public:
74 /// Resets the kernel to a clean slate for use. 74 /// Resets the kernel to a clean slate for use.
75 void Initialize(); 75 void Initialize();
76 76
77 /// Initializes the CPU cores.
78 void InitializeCores();
79
77 /// Clears all resources in use by the kernel instance. 80 /// Clears all resources in use by the kernel instance.
78 void Shutdown(); 81 void Shutdown();
79 82
diff --git a/src/core/hle/kernel/physical_core.cpp b/src/core/hle/kernel/physical_core.cpp
index 6e04d025f..50aca5752 100644
--- a/src/core/hle/kernel/physical_core.cpp
+++ b/src/core/hle/kernel/physical_core.cpp
@@ -4,21 +4,43 @@
4 4
5#include "common/spin_lock.h" 5#include "common/spin_lock.h"
6#include "core/arm/cpu_interrupt_handler.h" 6#include "core/arm/cpu_interrupt_handler.h"
7#include "core/arm/dynarmic/arm_dynarmic_32.h"
8#include "core/arm/dynarmic/arm_dynarmic_64.h"
7#include "core/core.h" 9#include "core/core.h"
10#include "core/hle/kernel/kernel.h"
8#include "core/hle/kernel/physical_core.h" 11#include "core/hle/kernel/physical_core.h"
9#include "core/hle/kernel/scheduler.h" 12#include "core/hle/kernel/scheduler.h"
10 13
11namespace Kernel { 14namespace Kernel {
12 15
13PhysicalCore::PhysicalCore(Core::System& system, std::size_t id, Kernel::Scheduler& scheduler, 16PhysicalCore::PhysicalCore(std::size_t core_index, Core::System& system,
14 Core::CPUInterruptHandler& interrupt_handler) 17 Kernel::Scheduler& scheduler, Core::CPUInterrupts& interrupts)
15 : interrupt_handler{interrupt_handler}, 18 : core_index{core_index}, system{system}, scheduler{scheduler},
16 core_index{id}, scheduler{scheduler}, guard{std::make_unique<Common::SpinLock>()} {} 19 interrupts{interrupts}, guard{std::make_unique<Common::SpinLock>()} {}
17 20
18PhysicalCore::~PhysicalCore() = default; 21PhysicalCore::~PhysicalCore() = default;
19 22
23void PhysicalCore::Initialize([[maybe_unused]] bool is_64_bit) {
24#ifdef ARCHITECTURE_x86_64
25 auto& kernel = system.Kernel();
26 if (is_64_bit) {
27 arm_interface = std::make_unique<Core::ARM_Dynarmic_64>(
28 system, interrupts, kernel.IsMulticore(), kernel.GetExclusiveMonitor(), core_index);
29 } else {
30 arm_interface = std::make_unique<Core::ARM_Dynarmic_32>(
31 system, interrupts, kernel.IsMulticore(), kernel.GetExclusiveMonitor(), core_index);
32 }
33#else
34#error Platform not supported yet.
35#endif
36}
37
38void PhysicalCore::Run() {
39 arm_interface->Run();
40}
41
20void PhysicalCore::Idle() { 42void PhysicalCore::Idle() {
21 interrupt_handler.AwaitInterrupt(); 43 interrupts[core_index].AwaitInterrupt();
22} 44}
23 45
24void PhysicalCore::Shutdown() { 46void PhysicalCore::Shutdown() {
@@ -26,18 +48,18 @@ void PhysicalCore::Shutdown() {
26} 48}
27 49
28bool PhysicalCore::IsInterrupted() const { 50bool PhysicalCore::IsInterrupted() const {
29 return interrupt_handler.IsInterrupted(); 51 return interrupts[core_index].IsInterrupted();
30} 52}
31 53
32void PhysicalCore::Interrupt() { 54void PhysicalCore::Interrupt() {
33 guard->lock(); 55 guard->lock();
34 interrupt_handler.SetInterrupt(true); 56 interrupts[core_index].SetInterrupt(true);
35 guard->unlock(); 57 guard->unlock();
36} 58}
37 59
38void PhysicalCore::ClearInterrupt() { 60void PhysicalCore::ClearInterrupt() {
39 guard->lock(); 61 guard->lock();
40 interrupt_handler.SetInterrupt(false); 62 interrupts[core_index].SetInterrupt(false);
41 guard->unlock(); 63 guard->unlock();
42} 64}
43 65
diff --git a/src/core/hle/kernel/physical_core.h b/src/core/hle/kernel/physical_core.h
index d7a7a951c..ace058a5a 100644
--- a/src/core/hle/kernel/physical_core.h
+++ b/src/core/hle/kernel/physical_core.h
@@ -4,9 +4,12 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <array>
7#include <cstddef> 8#include <cstddef>
8#include <memory> 9#include <memory>
9 10
11#include "core/arm/arm_interface.h"
12
10namespace Common { 13namespace Common {
11class SpinLock; 14class SpinLock;
12} 15}
@@ -16,7 +19,6 @@ class Scheduler;
16} // namespace Kernel 19} // namespace Kernel
17 20
18namespace Core { 21namespace Core {
19class ARM_Interface;
20class CPUInterruptHandler; 22class CPUInterruptHandler;
21class ExclusiveMonitor; 23class ExclusiveMonitor;
22class System; 24class System;
@@ -26,8 +28,8 @@ namespace Kernel {
26 28
27class PhysicalCore { 29class PhysicalCore {
28public: 30public:
29 PhysicalCore(Core::System& system, std::size_t id, Kernel::Scheduler& scheduler, 31 PhysicalCore(std::size_t core_index, Core::System& system, Kernel::Scheduler& scheduler,
30 Core::CPUInterruptHandler& interrupt_handler); 32 Core::CPUInterrupts& interrupts);
31 ~PhysicalCore(); 33 ~PhysicalCore();
32 34
33 PhysicalCore(const PhysicalCore&) = delete; 35 PhysicalCore(const PhysicalCore&) = delete;
@@ -36,7 +38,14 @@ public:
36 PhysicalCore(PhysicalCore&&) = default; 38 PhysicalCore(PhysicalCore&&) = default;
37 PhysicalCore& operator=(PhysicalCore&&) = default; 39 PhysicalCore& operator=(PhysicalCore&&) = default;
38 40
41 /// Initialize the core for the specified parameters.
42 void Initialize(bool is_64_bit);
43
44 /// Execute current jit state
45 void Run();
46
39 void Idle(); 47 void Idle();
48
40 /// Interrupt this physical core. 49 /// Interrupt this physical core.
41 void Interrupt(); 50 void Interrupt();
42 51
@@ -49,6 +58,14 @@ public:
49 // Shutdown this physical core. 58 // Shutdown this physical core.
50 void Shutdown(); 59 void Shutdown();
51 60
61 Core::ARM_Interface& ArmInterface() {
62 return *arm_interface;
63 }
64
65 const Core::ARM_Interface& ArmInterface() const {
66 return *arm_interface;
67 }
68
52 bool IsMainCore() const { 69 bool IsMainCore() const {
53 return core_index == 0; 70 return core_index == 0;
54 } 71 }
@@ -70,10 +87,12 @@ public:
70 } 87 }
71 88
72private: 89private:
73 Core::CPUInterruptHandler& interrupt_handler; 90 const std::size_t core_index;
74 std::size_t core_index; 91 Core::System& system;
75 Kernel::Scheduler& scheduler; 92 Kernel::Scheduler& scheduler;
93 Core::CPUInterrupts& interrupts;
76 std::unique_ptr<Common::SpinLock> guard; 94 std::unique_ptr<Common::SpinLock> guard;
95 std::unique_ptr<Core::ARM_Interface> arm_interface;
77}; 96};
78 97
79} // namespace Kernel 98} // namespace Kernel
diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp
index 6b7db5372..0805e9914 100644
--- a/src/core/hle/kernel/scheduler.cpp
+++ b/src/core/hle/kernel/scheduler.cpp
@@ -621,11 +621,14 @@ void Scheduler::OnThreadStart() {
621void Scheduler::Unload() { 621void Scheduler::Unload() {
622 Thread* thread = current_thread.get(); 622 Thread* thread = current_thread.get();
623 if (thread) { 623 if (thread) {
624 thread->SetContinuousOnSVC(false);
625 thread->last_running_ticks = system.CoreTiming().GetCPUTicks(); 624 thread->last_running_ticks = system.CoreTiming().GetCPUTicks();
626 thread->SetIsRunning(false); 625 thread->SetIsRunning(false);
626 if (thread->IsContinuousOnSVC() && !thread->IsHLEThread()) {
627 system.ArmInterface(core_id).ExceptionalExit();
628 thread->SetContinuousOnSVC(false);
629 }
627 if (!thread->IsHLEThread() && !thread->HasExited()) { 630 if (!thread->IsHLEThread() && !thread->HasExited()) {
628 Core::ARM_Interface& cpu_core = thread->ArmInterface(); 631 Core::ARM_Interface& cpu_core = system.ArmInterface(core_id);
629 cpu_core.SaveContext(thread->GetContext32()); 632 cpu_core.SaveContext(thread->GetContext32());
630 cpu_core.SaveContext(thread->GetContext64()); 633 cpu_core.SaveContext(thread->GetContext64());
631 // Save the TPIDR_EL0 system register in case it was modified. 634 // Save the TPIDR_EL0 system register in case it was modified.
@@ -652,12 +655,11 @@ void Scheduler::Reload() {
652 system.Kernel().MakeCurrentProcess(thread_owner_process); 655 system.Kernel().MakeCurrentProcess(thread_owner_process);
653 } 656 }
654 if (!thread->IsHLEThread()) { 657 if (!thread->IsHLEThread()) {
655 Core::ARM_Interface& cpu_core = thread->ArmInterface(); 658 Core::ARM_Interface& cpu_core = system.ArmInterface(core_id);
656 cpu_core.LoadContext(thread->GetContext32()); 659 cpu_core.LoadContext(thread->GetContext32());
657 cpu_core.LoadContext(thread->GetContext64()); 660 cpu_core.LoadContext(thread->GetContext64());
658 cpu_core.SetTlsAddress(thread->GetTLSAddress()); 661 cpu_core.SetTlsAddress(thread->GetTLSAddress());
659 cpu_core.SetTPIDR_EL0(thread->GetTPIDR_EL0()); 662 cpu_core.SetTPIDR_EL0(thread->GetTPIDR_EL0());
660 cpu_core.ChangeProcessorID(this->core_id);
661 cpu_core.ClearExclusiveState(); 663 cpu_core.ClearExclusiveState();
662 } 664 }
663 } 665 }
@@ -679,12 +681,11 @@ void Scheduler::SwitchContextStep2() {
679 system.Kernel().MakeCurrentProcess(thread_owner_process); 681 system.Kernel().MakeCurrentProcess(thread_owner_process);
680 } 682 }
681 if (!selected_thread->IsHLEThread()) { 683 if (!selected_thread->IsHLEThread()) {
682 Core::ARM_Interface& cpu_core = selected_thread->ArmInterface(); 684 Core::ARM_Interface& cpu_core = system.ArmInterface(core_id);
683 cpu_core.LoadContext(selected_thread->GetContext32()); 685 cpu_core.LoadContext(selected_thread->GetContext32());
684 cpu_core.LoadContext(selected_thread->GetContext64()); 686 cpu_core.LoadContext(selected_thread->GetContext64());
685 cpu_core.SetTlsAddress(selected_thread->GetTLSAddress()); 687 cpu_core.SetTlsAddress(selected_thread->GetTLSAddress());
686 cpu_core.SetTPIDR_EL0(selected_thread->GetTPIDR_EL0()); 688 cpu_core.SetTPIDR_EL0(selected_thread->GetTPIDR_EL0());
687 cpu_core.ChangeProcessorID(this->core_id);
688 cpu_core.ClearExclusiveState(); 689 cpu_core.ClearExclusiveState();
689 } 690 }
690 } 691 }
@@ -715,11 +716,14 @@ void Scheduler::SwitchContext() {
715 if (new_thread != nullptr && new_thread->IsSuspendThread()) { 716 if (new_thread != nullptr && new_thread->IsSuspendThread()) {
716 previous_thread->SetWasRunning(true); 717 previous_thread->SetWasRunning(true);
717 } 718 }
718 previous_thread->SetContinuousOnSVC(false);
719 previous_thread->last_running_ticks = system.CoreTiming().GetCPUTicks(); 719 previous_thread->last_running_ticks = system.CoreTiming().GetCPUTicks();
720 previous_thread->SetIsRunning(false); 720 previous_thread->SetIsRunning(false);
721 if (previous_thread->IsContinuousOnSVC() && !previous_thread->IsHLEThread()) {
722 system.ArmInterface(core_id).ExceptionalExit();
723 previous_thread->SetContinuousOnSVC(false);
724 }
721 if (!previous_thread->IsHLEThread() && !previous_thread->HasExited()) { 725 if (!previous_thread->IsHLEThread() && !previous_thread->HasExited()) {
722 Core::ARM_Interface& cpu_core = previous_thread->ArmInterface(); 726 Core::ARM_Interface& cpu_core = system.ArmInterface(core_id);
723 cpu_core.SaveContext(previous_thread->GetContext32()); 727 cpu_core.SaveContext(previous_thread->GetContext32());
724 cpu_core.SaveContext(previous_thread->GetContext64()); 728 cpu_core.SaveContext(previous_thread->GetContext64());
725 // Save the TPIDR_EL0 system register in case it was modified. 729 // Save the TPIDR_EL0 system register in case it was modified.
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index e3b770d66..95d6e2b4d 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -2639,6 +2639,9 @@ void Call(Core::System& system, u32 immediate) {
2639 auto& kernel = system.Kernel(); 2639 auto& kernel = system.Kernel();
2640 kernel.EnterSVCProfile(); 2640 kernel.EnterSVCProfile();
2641 2641
2642 auto* thread = system.CurrentScheduler().GetCurrentThread();
2643 thread->SetContinuousOnSVC(true);
2644
2642 const FunctionDef* info = system.CurrentProcess()->Is64BitProcess() ? GetSVCInfo64(immediate) 2645 const FunctionDef* info = system.CurrentProcess()->Is64BitProcess() ? GetSVCInfo64(immediate)
2643 : GetSVCInfo32(immediate); 2646 : GetSVCInfo32(immediate);
2644 if (info) { 2647 if (info) {
@@ -2652,6 +2655,12 @@ void Call(Core::System& system, u32 immediate) {
2652 } 2655 }
2653 2656
2654 kernel.ExitSVCProfile(); 2657 kernel.ExitSVCProfile();
2658
2659 if (!thread->IsContinuousOnSVC()) {
2660 auto* host_context = thread->GetHostContext().get();
2661 host_context->Rewind();
2662 }
2663
2655 system.EnterDynarmicProfile(); 2664 system.EnterDynarmicProfile();
2656} 2665}
2657 2666
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index da0cb26b6..3abe12810 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -12,7 +12,6 @@
12#include "common/fiber.h" 12#include "common/fiber.h"
13#include "common/logging/log.h" 13#include "common/logging/log.h"
14#include "common/thread_queue_list.h" 14#include "common/thread_queue_list.h"
15#include "core/arm/arm_interface.h"
16#include "core/core.h" 15#include "core/core.h"
17#include "core/cpu_manager.h" 16#include "core/cpu_manager.h"
18#include "core/hardware_properties.h" 17#include "core/hardware_properties.h"
@@ -62,7 +61,6 @@ void Thread::Stop() {
62 // Mark the TLS slot in the thread's page as free. 61 // Mark the TLS slot in the thread's page as free.
63 owner_process->FreeTLSRegion(tls_address); 62 owner_process->FreeTLSRegion(tls_address);
64 } 63 }
65 arm_interface.reset();
66 has_exited = true; 64 has_exited = true;
67 } 65 }
68 global_handle = 0; 66 global_handle = 0;
@@ -217,22 +215,9 @@ ResultVal<std::shared_ptr<Thread>> Thread::Create(Core::System& system, ThreadTy
217 thread->tls_address = 0; 215 thread->tls_address = 0;
218 } 216 }
219 217
220 thread->arm_interface.reset(); 218 // TODO(peachum): move to ScheduleThread() when scheduler is added so selected core is used
219 // to initialize the context
221 if ((type_flags & THREADTYPE_HLE) == 0) { 220 if ((type_flags & THREADTYPE_HLE) == 0) {
222#ifdef ARCHITECTURE_x86_64
223 if (owner_process && !owner_process->Is64BitProcess()) {
224 thread->arm_interface = std::make_unique<Core::ARM_Dynarmic_32>(
225 system, kernel.Interrupts(), kernel.IsMulticore(), kernel.GetExclusiveMonitor(),
226 processor_id);
227 } else {
228 thread->arm_interface = std::make_unique<Core::ARM_Dynarmic_64>(
229 system, kernel.Interrupts(), kernel.IsMulticore(), kernel.GetExclusiveMonitor(),
230 processor_id);
231 }
232#else
233#error Platform not supported yet.
234#endif
235
236 ResetThreadContext32(thread->context_32, static_cast<u32>(stack_top), 221 ResetThreadContext32(thread->context_32, static_cast<u32>(stack_top),
237 static_cast<u32>(entry_point), static_cast<u32>(arg)); 222 static_cast<u32>(entry_point), static_cast<u32>(arg));
238 ResetThreadContext64(thread->context_64, stack_top, entry_point, arg); 223 ResetThreadContext64(thread->context_64, stack_top, entry_point, arg);
@@ -268,14 +253,6 @@ VAddr Thread::GetCommandBufferAddress() const {
268 return GetTLSAddress() + command_header_offset; 253 return GetTLSAddress() + command_header_offset;
269} 254}
270 255
271Core::ARM_Interface& Thread::ArmInterface() {
272 return *arm_interface;
273}
274
275const Core::ARM_Interface& Thread::ArmInterface() const {
276 return *arm_interface;
277}
278
279void Thread::SetStatus(ThreadStatus new_status) { 256void Thread::SetStatus(ThreadStatus new_status) {
280 if (new_status == status) { 257 if (new_status == status) {
281 return; 258 return;
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index 8daf79fac..20e86fb81 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -248,10 +248,6 @@ public:
248 248
249 void SetSynchronizationResults(SynchronizationObject* object, ResultCode result); 249 void SetSynchronizationResults(SynchronizationObject* object, ResultCode result);
250 250
251 Core::ARM_Interface& ArmInterface();
252
253 const Core::ARM_Interface& ArmInterface() const;
254
255 SynchronizationObject* GetSignalingObject() const { 251 SynchronizationObject* GetSignalingObject() const {
256 return signaling_object; 252 return signaling_object;
257 } 253 }
@@ -586,7 +582,6 @@ private:
586 Common::SpinLock context_guard{}; 582 Common::SpinLock context_guard{};
587 ThreadContext32 context_32{}; 583 ThreadContext32 context_32{};
588 ThreadContext64 context_64{}; 584 ThreadContext64 context_64{};
589 std::unique_ptr<Core::ARM_Interface> arm_interface{};
590 std::shared_ptr<Common::Fiber> host_context{}; 585 std::shared_ptr<Common::Fiber> host_context{};
591 586
592 u64 thread_id = 0; 587 u64 thread_id = 0;