summaryrefslogtreecommitdiff
path: root/src/core/core.cpp
diff options
context:
space:
mode:
authorGravatar Lioncash2018-08-28 12:30:33 -0400
committerGravatar Lioncash2018-08-28 22:31:51 -0400
commit0cbcd6ec9aeeafc298fe2e6e4ac10d68bb7267c5 (patch)
tree2d7bb143d490c3984bff6deda426b818bf27d552 /src/core/core.cpp
parentMerge pull request #1193 from lioncash/priv (diff)
downloadyuzu-0cbcd6ec9aeeafc298fe2e6e4ac10d68bb7267c5.tar.gz
yuzu-0cbcd6ec9aeeafc298fe2e6e4ac10d68bb7267c5.tar.xz
yuzu-0cbcd6ec9aeeafc298fe2e6e4ac10d68bb7267c5.zip
kernel: Eliminate kernel global state
As means to pave the way for getting rid of global state within core, This eliminates kernel global state by removing all globals. Instead this introduces a KernelCore class which acts as a kernel instance. This instance lives in the System class, which keeps its lifetime contained to the lifetime of the System class. This also forces the kernel types to actually interact with the main kernel instance itself instead of having transient kernel state placed all over several translation units, keeping everything together. It also has a nice consequence of making dependencies much more explicit. This also makes our initialization a tad bit more correct. Previously we were creating a kernel process before the actual kernel was initialized, which doesn't really make much sense. The KernelCore class itself follows the PImpl idiom, which allows keeping all the implementation details sealed away from everything else, which forces the use of the exposed API and allows us to avoid any unnecessary inclusions within the main kernel header.
Diffstat (limited to 'src/core/core.cpp')
-rw-r--r--src/core/core.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 07da4c493..2293669e5 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -171,6 +171,14 @@ const std::shared_ptr<Kernel::Scheduler>& System::Scheduler(size_t core_index) {
171 return cpu_cores[core_index]->Scheduler(); 171 return cpu_cores[core_index]->Scheduler();
172} 172}
173 173
174Kernel::KernelCore& System::Kernel() {
175 return kernel;
176}
177
178const Kernel::KernelCore& System::Kernel() const {
179 return kernel;
180}
181
174ARM_Interface& System::ArmInterface(size_t core_index) { 182ARM_Interface& System::ArmInterface(size_t core_index) {
175 ASSERT(core_index < NUM_CPU_CORES); 183 ASSERT(core_index < NUM_CPU_CORES);
176 return cpu_cores[core_index]->ArmInterface(); 184 return cpu_cores[core_index]->ArmInterface();
@@ -185,12 +193,13 @@ System::ResultStatus System::Init(Frontend::EmuWindow& emu_window) {
185 LOG_DEBUG(HW_Memory, "initialized OK"); 193 LOG_DEBUG(HW_Memory, "initialized OK");
186 194
187 CoreTiming::Init(); 195 CoreTiming::Init();
196 kernel.Initialize();
188 197
189 // Create a default fs if one doesn't already exist. 198 // Create a default fs if one doesn't already exist.
190 if (virtual_filesystem == nullptr) 199 if (virtual_filesystem == nullptr)
191 virtual_filesystem = std::make_shared<FileSys::RealVfsFilesystem>(); 200 virtual_filesystem = std::make_shared<FileSys::RealVfsFilesystem>();
192 201
193 current_process = Kernel::Process::Create("main"); 202 current_process = Kernel::Process::Create(kernel, "main");
194 203
195 cpu_barrier = std::make_shared<CpuBarrier>(); 204 cpu_barrier = std::make_shared<CpuBarrier>();
196 cpu_exclusive_monitor = Cpu::MakeExclusiveMonitor(cpu_cores.size()); 205 cpu_exclusive_monitor = Cpu::MakeExclusiveMonitor(cpu_cores.size());
@@ -201,7 +210,6 @@ System::ResultStatus System::Init(Frontend::EmuWindow& emu_window) {
201 telemetry_session = std::make_unique<Core::TelemetrySession>(); 210 telemetry_session = std::make_unique<Core::TelemetrySession>();
202 service_manager = std::make_shared<Service::SM::ServiceManager>(); 211 service_manager = std::make_shared<Service::SM::ServiceManager>();
203 212
204 Kernel::Init();
205 Service::Init(service_manager, virtual_filesystem); 213 Service::Init(service_manager, virtual_filesystem);
206 GDBStub::Init(); 214 GDBStub::Init();
207 215
@@ -246,7 +254,6 @@ void System::Shutdown() {
246 renderer.reset(); 254 renderer.reset();
247 GDBStub::Shutdown(); 255 GDBStub::Shutdown();
248 Service::Shutdown(); 256 Service::Shutdown();
249 Kernel::Shutdown();
250 service_manager.reset(); 257 service_manager.reset();
251 telemetry_session.reset(); 258 telemetry_session.reset();
252 gpu_core.reset(); 259 gpu_core.reset();
@@ -265,7 +272,8 @@ void System::Shutdown() {
265 } 272 }
266 cpu_barrier.reset(); 273 cpu_barrier.reset();
267 274
268 // Close core timing 275 // Shutdown kernel and core timing
276 kernel.Shutdown();
269 CoreTiming::Shutdown(); 277 CoreTiming::Shutdown();
270 278
271 // Close app loader 279 // Close app loader