summaryrefslogtreecommitdiff
path: root/src/core/core.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/core.cpp')
-rw-r--r--src/core/core.cpp57
1 files changed, 9 insertions, 48 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 9e2229d02..0af78c18c 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -5,10 +5,6 @@
5#include <memory> 5#include <memory>
6#include <utility> 6#include <utility>
7#include "common/logging/log.h" 7#include "common/logging/log.h"
8#ifdef ARCHITECTURE_x86_64
9#include "core/arm/dynarmic/arm_dynarmic.h"
10#endif
11#include "core/arm/unicorn/arm_unicorn.h"
12#include "core/core.h" 8#include "core/core.h"
13#include "core/core_timing.h" 9#include "core/core_timing.h"
14#include "core/gdbstub/gdbstub.h" 10#include "core/gdbstub/gdbstub.h"
@@ -33,9 +29,6 @@ System::~System() = default;
33 29
34System::ResultStatus System::RunLoop(bool tight_loop) { 30System::ResultStatus System::RunLoop(bool tight_loop) {
35 status = ResultStatus::Success; 31 status = ResultStatus::Success;
36 if (!cpu_core) {
37 return ResultStatus::ErrorNotInitialized;
38 }
39 32
40 if (GDBStub::IsServerEnabled()) { 33 if (GDBStub::IsServerEnabled()) {
41 GDBStub::HandlePacket(); 34 GDBStub::HandlePacket();
@@ -52,24 +45,7 @@ System::ResultStatus System::RunLoop(bool tight_loop) {
52 } 45 }
53 } 46 }
54 47
55 // If we don't have a currently active thread then don't execute instructions, 48 cpu_cores[0]->RunLoop(tight_loop);
56 // instead advance to the next event and try to yield to the next thread
57 if (Kernel::GetCurrentThread() == nullptr) {
58 NGLOG_TRACE(Core_ARM, "Idling");
59 CoreTiming::Idle();
60 CoreTiming::Advance();
61 PrepareReschedule();
62 } else {
63 CoreTiming::Advance();
64 if (tight_loop) {
65 cpu_core->Run();
66 } else {
67 cpu_core->Step();
68 }
69 }
70
71 HW::Update();
72 Reschedule();
73 49
74 return status; 50 return status;
75} 51}
@@ -133,23 +109,13 @@ System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& file
133} 109}
134 110
135void System::PrepareReschedule() { 111void System::PrepareReschedule() {
136 cpu_core->PrepareReschedule(); 112 cpu_cores[0]->PrepareReschedule();
137 reschedule_pending = true;
138} 113}
139 114
140PerfStats::Results System::GetAndResetPerfStats() { 115PerfStats::Results System::GetAndResetPerfStats() {
141 return perf_stats.GetAndResetStats(CoreTiming::GetGlobalTimeUs()); 116 return perf_stats.GetAndResetStats(CoreTiming::GetGlobalTimeUs());
142} 117}
143 118
144void System::Reschedule() {
145 if (!reschedule_pending) {
146 return;
147 }
148
149 reschedule_pending = false;
150 Core::System::GetInstance().Scheduler().Reschedule();
151}
152
153System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) { 119System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) {
154 NGLOG_DEBUG(HW_Memory, "initialized OK"); 120 NGLOG_DEBUG(HW_Memory, "initialized OK");
155 121
@@ -157,15 +123,8 @@ System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) {
157 123
158 current_process = Kernel::Process::Create("main"); 124 current_process = Kernel::Process::Create("main");
159 125
160 if (Settings::values.use_cpu_jit) { 126 for (auto& cpu_core : cpu_cores) {
161#ifdef ARCHITECTURE_x86_64 127 cpu_core = std::make_unique<Cpu>();
162 cpu_core = std::make_shared<ARM_Dynarmic>();
163#else
164 cpu_core = std::make_shared<ARM_Unicorn>();
165 NGLOG_WARNING(Core, "CPU JIT requested, but Dynarmic not available");
166#endif
167 } else {
168 cpu_core = std::make_shared<ARM_Unicorn>();
169 } 128 }
170 129
171 gpu_core = std::make_unique<Tegra::GPU>(); 130 gpu_core = std::make_unique<Tegra::GPU>();
@@ -176,7 +135,6 @@ System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) {
176 135
177 HW::Init(); 136 HW::Init();
178 Kernel::Init(system_mode); 137 Kernel::Init(system_mode);
179 scheduler = std::make_unique<Kernel::Scheduler>(cpu_core.get());
180 Service::Init(service_manager); 138 Service::Init(service_manager);
181 GDBStub::Init(); 139 GDBStub::Init();
182 140
@@ -207,13 +165,16 @@ void System::Shutdown() {
207 VideoCore::Shutdown(); 165 VideoCore::Shutdown();
208 GDBStub::Shutdown(); 166 GDBStub::Shutdown();
209 Service::Shutdown(); 167 Service::Shutdown();
210 scheduler.reset();
211 Kernel::Shutdown(); 168 Kernel::Shutdown();
212 HW::Shutdown(); 169 HW::Shutdown();
213 service_manager.reset(); 170 service_manager.reset();
214 telemetry_session.reset(); 171 telemetry_session.reset();
215 gpu_core.reset(); 172 gpu_core.reset();
216 cpu_core.reset(); 173
174 for (auto& cpu_core : cpu_cores) {
175 cpu_core.reset();
176 }
177
217 CoreTiming::Shutdown(); 178 CoreTiming::Shutdown();
218 179
219 app_loader.reset(); 180 app_loader.reset();