diff --git a/include/cpu_dynarmic.hpp b/include/cpu_dynarmic.hpp index bc386d33..13c16982 100644 --- a/include/cpu_dynarmic.hpp +++ b/include/cpu_dynarmic.hpp @@ -8,6 +8,8 @@ #include "kernel.hpp" #include "memory.hpp" +class CPU; + class MyEnvironment final : public Dynarmic::A32::UserCallbacks { public: u64 ticksLeft = 0; @@ -89,7 +91,7 @@ public: return ticksLeft; } - MyEnvironment(Memory& mem, Kernel& kernel) : mem(mem), kernel(kernel) {} + MyEnvironment(Memory& mem, Kernel& kernel, CPU& cpu) : mem(mem), kernel(kernel) {} }; class CPU { diff --git a/include/emulator.hpp b/include/emulator.hpp index b7e8489a..438e2053 100644 --- a/include/emulator.hpp +++ b/include/emulator.hpp @@ -28,7 +28,7 @@ class Emulator { public: Emulator() : window(sf::VideoMode(width, height), "Alber", sf::Style::Default, sf::ContextSettings(0, 0, 0, 4, 3)), - kernel(cpu.regs(), memory), cpu(memory, kernel) { + kernel(cpu, memory), cpu(memory, kernel) { reset(); window.setActive(true); } diff --git a/include/kernel/kernel.hpp b/include/kernel/kernel.hpp index 03c4ab7d..62699441 100644 --- a/include/kernel/kernel.hpp +++ b/include/kernel/kernel.hpp @@ -8,8 +8,11 @@ #include "memory.hpp" #include "services/service_manager.hpp" +class CPU; + class Kernel { std::array& regs; + CPU& cpu; Memory& mem; // The handle number for the next kernel object to be created @@ -89,11 +92,7 @@ class Kernel { void outputDebugString(); public: - Kernel(std::array& regs, Memory& mem) - : regs(regs), mem(mem), handleCounter(0), serviceManager(regs, mem, currentProcess) { - objects.reserve(512); // Make room for a few objects to avoid further memory allocs later - portHandles.reserve(32); - } + Kernel(CPU& cpu, Memory& mem); void serviceSVC(u32 svc); void reset(); }; \ No newline at end of file diff --git a/src/core/CPU/cpu_dynarmic.cpp b/src/core/CPU/cpu_dynarmic.cpp index 4e16478d..4848d580 100644 --- a/src/core/CPU/cpu_dynarmic.cpp +++ b/src/core/CPU/cpu_dynarmic.cpp @@ -1,7 +1,7 @@ #ifdef CPU_DYNARMIC #include "cpu_dynarmic.hpp" -CPU::CPU(Memory& mem, Kernel& kernel) : mem(mem), env(mem, kernel) { +CPU::CPU(Memory& mem, Kernel& kernel) : mem(mem), env(mem, kernel, *this) { cp15 = std::make_shared(); Dynarmic::A32::UserConfig config; diff --git a/src/core/kernel/kernel.cpp b/src/core/kernel/kernel.cpp index 83352bc6..954efd0c 100644 --- a/src/core/kernel/kernel.cpp +++ b/src/core/kernel/kernel.cpp @@ -1,6 +1,13 @@ #include #include "kernel.hpp" #include "kernel_types.hpp" +#include "cpu.hpp" + +Kernel::Kernel(CPU& cpu, Memory& mem) + : cpu(cpu), regs(cpu.regs()), mem(mem), handleCounter(0), serviceManager(regs, mem, currentProcess) { + objects.reserve(512); // Make room for a few objects to avoid further memory allocs later + portHandles.reserve(32); +} void Kernel::serviceSVC(u32 svc) { switch (svc) { diff --git a/src/core/kernel/threads.cpp b/src/core/kernel/threads.cpp index 7fc33477..fa10fdc1 100644 --- a/src/core/kernel/threads.cpp +++ b/src/core/kernel/threads.cpp @@ -1,4 +1,6 @@ #include "kernel.hpp" +// This header needs to be included because I did stupid forward decl hack so the kernel and CPU can both access each other +#include "cpu.hpp" #include "resource_limits.hpp" // Internal OS function to spawn a thread