aboutsummaryrefslogtreecommitdiff
path: root/src/core/core.cpp
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2018-08-28 12:30:33 -0400
committerLioncash <mathew1800@gmail.com>2018-08-28 22:31:51 -0400
commit0cbcd6ec9aeeafc298fe2e6e4ac10d68bb7267c5 (patch)
tree2d7bb143d490c3984bff6deda426b818bf27d552 /src/core/core.cpp
parent4d7e1662c84ef65f7da5a27b0473125cc6759d5c (diff)
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 07da4c4937..2293669e5b 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) {
return cpu_cores[core_index]->Scheduler();
}
+Kernel::KernelCore& System::Kernel() {
+ return kernel;
+}
+
+const Kernel::KernelCore& System::Kernel() const {
+ return kernel;
+}
+
ARM_Interface& System::ArmInterface(size_t core_index) {
ASSERT(core_index < NUM_CPU_CORES);
return cpu_cores[core_index]->ArmInterface();
@@ -185,12 +193,13 @@ System::ResultStatus System::Init(Frontend::EmuWindow& emu_window) {
LOG_DEBUG(HW_Memory, "initialized OK");
CoreTiming::Init();
+ kernel.Initialize();
// Create a default fs if one doesn't already exist.
if (virtual_filesystem == nullptr)
virtual_filesystem = std::make_shared<FileSys::RealVfsFilesystem>();
- current_process = Kernel::Process::Create("main");
+ current_process = Kernel::Process::Create(kernel, "main");
cpu_barrier = std::make_shared<CpuBarrier>();
cpu_exclusive_monitor = Cpu::MakeExclusiveMonitor(cpu_cores.size());
@@ -201,7 +210,6 @@ System::ResultStatus System::Init(Frontend::EmuWindow& emu_window) {
telemetry_session = std::make_unique<Core::TelemetrySession>();
service_manager = std::make_shared<Service::SM::ServiceManager>();
- Kernel::Init();
Service::Init(service_manager, virtual_filesystem);
GDBStub::Init();
@@ -246,7 +254,6 @@ void System::Shutdown() {
renderer.reset();
GDBStub::Shutdown();
Service::Shutdown();
- Kernel::Shutdown();
service_manager.reset();
telemetry_session.reset();
gpu_core.reset();
@@ -265,7 +272,8 @@ void System::Shutdown() {
}
cpu_barrier.reset();
- // Close core timing
+ // Shutdown kernel and core timing
+ kernel.Shutdown();
CoreTiming::Shutdown();
// Close app loader