summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/arm/arm_interface.h10
-rw-r--r--src/core/cpu_manager.cpp25
-rw-r--r--src/core/cpu_manager.h2
-rw-r--r--src/core/hle/kernel/scheduler.cpp3
-rw-r--r--src/core/hle/kernel/svc.cpp6
5 files changed, 39 insertions, 7 deletions
diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.h
index 87a1c29cc..be9f3703a 100644
--- a/src/core/arm/arm_interface.h
+++ b/src/core/arm/arm_interface.h
@@ -6,6 +6,7 @@
6 6
7#include <array> 7#include <array>
8#include <vector> 8#include <vector>
9#include <mutex>
9#include "common/common_types.h" 10#include "common/common_types.h"
10 11
11namespace Common { 12namespace Common {
@@ -164,6 +165,14 @@ public:
164 std::string name; 165 std::string name;
165 }; 166 };
166 167
168 void Lock() {
169 guard.lock();
170 }
171
172 void Unlock() {
173 guard.unlock();
174 }
175
167 std::vector<BacktraceEntry> GetBacktrace() const; 176 std::vector<BacktraceEntry> GetBacktrace() const;
168 177
169 /// fp (= r29) points to the last frame record. 178 /// fp (= r29) points to the last frame record.
@@ -178,6 +187,7 @@ protected:
178 /// System context that this ARM interface is running under. 187 /// System context that this ARM interface is running under.
179 System& system; 188 System& system;
180 CPUInterruptHandler& interrupt_handler; 189 CPUInterruptHandler& interrupt_handler;
190 std::mutex guard;
181}; 191};
182 192
183} // namespace Core 193} // namespace Core
diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp
index 904aacd97..9a261968a 100644
--- a/src/core/cpu_manager.cpp
+++ b/src/core/cpu_manager.cpp
@@ -46,6 +46,11 @@ void CpuManager::GuestThreadFunction(void* cpu_manager_) {
46 cpu_manager->RunGuestThread(); 46 cpu_manager->RunGuestThread();
47} 47}
48 48
49void CpuManager::GuestRewindFunction(void* cpu_manager_) {
50 CpuManager* cpu_manager = static_cast<CpuManager*>(cpu_manager_);
51 cpu_manager->RunGuestLoop();
52}
53
49void CpuManager::IdleThreadFunction(void* cpu_manager_) { 54void CpuManager::IdleThreadFunction(void* cpu_manager_) {
50 CpuManager* cpu_manager = static_cast<CpuManager*>(cpu_manager_); 55 CpuManager* cpu_manager = static_cast<CpuManager*>(cpu_manager_);
51 cpu_manager->RunIdleThread(); 56 cpu_manager->RunIdleThread();
@@ -78,14 +83,22 @@ void CpuManager::RunGuestThread() {
78 auto& sched = kernel.CurrentScheduler(); 83 auto& sched = kernel.CurrentScheduler();
79 sched.OnThreadStart(); 84 sched.OnThreadStart();
80 } 85 }
86 RunGuestLoop();
87}
88
89void CpuManager::RunGuestLoop() {
90 auto& kernel = system.Kernel();
91 auto* thread = kernel.CurrentScheduler().GetCurrentThread();
92 auto host_context = thread->GetHostContext();
93 host_context->SetRewindPoint(std::function<void(void*)>(GuestRewindFunction), this);
94 host_context.reset();
81 while (true) { 95 while (true) {
82 auto* physical_core = &kernel.CurrentPhysicalCore(); 96 auto& physical_core = kernel.CurrentPhysicalCore();
83 while (!physical_core->IsInterrupted()) { 97 while (!physical_core.IsInterrupted()) {
84 physical_core->Run(); 98 physical_core.Run();
85 physical_core = &kernel.CurrentPhysicalCore();
86 } 99 }
87 physical_core->ClearExclusive(); 100 physical_core.ClearExclusive();
88 auto& scheduler = physical_core->Scheduler(); 101 auto& scheduler = physical_core.Scheduler();
89 scheduler.TryDoContextSwitch(); 102 scheduler.TryDoContextSwitch();
90 } 103 }
91} 104}
diff --git a/src/core/cpu_manager.h b/src/core/cpu_manager.h
index 8103ae857..e83ab20f9 100644
--- a/src/core/cpu_manager.h
+++ b/src/core/cpu_manager.h
@@ -42,10 +42,12 @@ public:
42 42
43private: 43private:
44 static void GuestThreadFunction(void* cpu_manager); 44 static void GuestThreadFunction(void* cpu_manager);
45 static void GuestRewindFunction(void* cpu_manager);
45 static void IdleThreadFunction(void* cpu_manager); 46 static void IdleThreadFunction(void* cpu_manager);
46 static void SuspendThreadFunction(void* cpu_manager); 47 static void SuspendThreadFunction(void* cpu_manager);
47 48
48 void RunGuestThread(); 49 void RunGuestThread();
50 void RunGuestLoop();
49 void RunIdleThread(); 51 void RunIdleThread();
50 void RunSuspendThread(); 52 void RunSuspendThread();
51 53
diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp
index 758fa8188..727d2e6cc 100644
--- a/src/core/hle/kernel/scheduler.cpp
+++ b/src/core/hle/kernel/scheduler.cpp
@@ -581,6 +581,7 @@ void Scheduler::SwitchContextStep2() {
581 581
582 if (new_thread) { 582 if (new_thread) {
583 new_thread->context_guard.lock(); 583 new_thread->context_guard.lock();
584 cpu_core.Lock();
584 ASSERT_MSG(new_thread->GetProcessorID() == s32(this->core_id), 585 ASSERT_MSG(new_thread->GetProcessorID() == s32(this->core_id),
585 "Thread must be assigned to this core."); 586 "Thread must be assigned to this core.");
586 ASSERT_MSG(new_thread->GetStatus() == ThreadStatus::Ready, 587 ASSERT_MSG(new_thread->GetStatus() == ThreadStatus::Ready,
@@ -601,6 +602,7 @@ void Scheduler::SwitchContextStep2() {
601 cpu_core.LoadContext(new_thread->GetContext64()); 602 cpu_core.LoadContext(new_thread->GetContext64());
602 cpu_core.SetTlsAddress(new_thread->GetTLSAddress()); 603 cpu_core.SetTlsAddress(new_thread->GetTLSAddress());
603 cpu_core.SetTPIDR_EL0(new_thread->GetTPIDR_EL0()); 604 cpu_core.SetTPIDR_EL0(new_thread->GetTPIDR_EL0());
605 cpu_core.ClearExclusiveState();
604 } 606 }
605 } else { 607 } else {
606 current_thread = nullptr; 608 current_thread = nullptr;
@@ -639,6 +641,7 @@ void Scheduler::SwitchContext() {
639 } 641 }
640 previous_thread->SetIsRunning(false); 642 previous_thread->SetIsRunning(false);
641 previous_thread->context_guard.unlock(); 643 previous_thread->context_guard.unlock();
644 cpu_core.Unlock();
642 } 645 }
643 646
644 std::shared_ptr<Common::Fiber> old_context; 647 std::shared_ptr<Common::Fiber> old_context;
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 1e6c60d78..b535593c7 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -10,6 +10,7 @@
10 10
11#include "common/alignment.h" 11#include "common/alignment.h"
12#include "common/assert.h" 12#include "common/assert.h"
13#include "common/fiber.h"
13#include "common/logging/log.h" 14#include "common/logging/log.h"
14#include "common/microprofile.h" 15#include "common/microprofile.h"
15#include "common/string_util.h" 16#include "common/string_util.h"
@@ -2468,7 +2469,10 @@ void Call(Core::System& system, u32 immediate) {
2468 } 2469 }
2469 auto& physical_core_2 = system.CurrentPhysicalCore(); 2470 auto& physical_core_2 = system.CurrentPhysicalCore();
2470 if (physical_core.CoreIndex() != physical_core_2.CoreIndex()) { 2471 if (physical_core.CoreIndex() != physical_core_2.CoreIndex()) {
2471 physical_core.Stop(); 2472 LOG_CRITICAL(Kernel_SVC, "Rewinding");
2473 auto* thread = physical_core_2.Scheduler().GetCurrentThread();
2474 auto* host_context = thread->GetHostContext().get();
2475 host_context->Rewind();
2472 } 2476 }
2473} 2477}
2474 2478