diff --git a/CMakeLists.txt b/CMakeLists.txt index eee48248..7d79ec45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,9 +43,11 @@ else() message(FATAL_ERROR "THIS IS NOT x64 WAIT FOR THE KVM IMPLEMENTATION") endif() -set(SOURCE_FILES src/main.cpp src/emulator.cpp src/core/CPU/cpu_dynarmic.cpp src/core/memory.cpp src/core/elf.cpp) +set(SOURCE_FILES src/main.cpp src/emulator.cpp src/core/CPU/cpu_dynarmic.cpp src/core/memory.cpp src/core/elf.cpp + src/core/kernel.cpp + ) set(HEADER_FILES include/emulator.hpp include/helpers.hpp include/opengl.hpp include/termcolor.hpp - include/cpu.hpp include/cpu_dynarmic.hpp include/memory.hpp + include/cpu.hpp include/cpu_dynarmic.hpp include/memory.hpp include/kernel.hpp ) set(THIRD_PARTY_SOURCE_FILES third_party/imgui/imgui.cpp diff --git a/include/cpu_dynarmic.hpp b/include/cpu_dynarmic.hpp index 6cd53101..7afd6742 100644 --- a/include/cpu_dynarmic.hpp +++ b/include/cpu_dynarmic.hpp @@ -3,12 +3,14 @@ #include "dynarmic/interface/A32/a32.h" #include "dynarmic/interface/A32/config.h" #include "helpers.hpp" +#include "kernel.hpp" #include "memory.hpp" class MyEnvironment final : public Dynarmic::A32::UserCallbacks { public: u64 ticks_left = 0; Memory& mem; + Kernel& kernel; u8 MemoryRead8(u32 vaddr) override { return mem.read8(vaddr); @@ -49,7 +51,7 @@ public: } void CallSVC(u32 swi) override { - Helpers::panic("Called SVC %d", swi); + kernel.serviceSVC(swi); } void ExceptionRaised(u32 pc, Dynarmic::A32::Exception exception) override { @@ -68,7 +70,7 @@ public: return ticks_left; } - MyEnvironment(Memory& mem) : mem(mem) {} + MyEnvironment(Memory& mem, Kernel& kernel) : mem(mem), kernel(kernel) {} }; class CPU { @@ -77,7 +79,7 @@ class CPU { Memory& mem; public: - CPU(Memory& mem); + CPU(Memory& mem, Kernel& kernel); void reset(); void setReg(int index, u32 value) { diff --git a/include/emulator.hpp b/include/emulator.hpp index 1c27e495..68bed83f 100644 --- a/include/emulator.hpp +++ b/include/emulator.hpp @@ -11,13 +11,15 @@ class Emulator { CPU cpu; Memory memory; + Kernel kernel; + sf::RenderWindow window; static constexpr u32 width = 400; static constexpr u32 height = 240 * 2; // * 2 because 2 screens public: Emulator() : window(sf::VideoMode(width, height), "Alber", sf::Style::Default, sf::ContextSettings(0, 0, 0, 4, 3)), - cpu(memory) { + kernel(cpu.regs(), memory), cpu(memory, kernel) { reset(); window.setActive(true); } diff --git a/include/kernel.hpp b/include/kernel.hpp new file mode 100644 index 00000000..7516f5b5 --- /dev/null +++ b/include/kernel.hpp @@ -0,0 +1,22 @@ +#pragma once +#include +#include "helpers.hpp" +#include "memory.hpp" + +namespace SVCResult { + enum : u32 { + Success = 0 + }; +} + +class Kernel { + std::array& regs; + Memory& mem; + +public: + Kernel(std::array& regs, Memory& mem) : regs(regs), mem(mem) {} + void serviceSVC(u32 svc); + void reset(); + + void createAddressArbiter(); +}; \ No newline at end of file diff --git a/src/core/CPU/cpu_dynarmic.cpp b/src/core/CPU/cpu_dynarmic.cpp index 499a4219..242ae8d4 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) : mem(mem), env(mem) {} +CPU::CPU(Memory& mem, Kernel& kernel) : mem(mem), env(mem, kernel) {} void CPU::reset() { // ARM mode, all flags disabled, interrupts and aborts all enabled, user mode diff --git a/src/core/kernel.cpp b/src/core/kernel.cpp new file mode 100644 index 00000000..3efa1f7c --- /dev/null +++ b/src/core/kernel.cpp @@ -0,0 +1,20 @@ +#include "kernel.hpp" + +void Kernel::serviceSVC(u32 svc) { + switch (svc) { + case 0x21: createAddressArbiter(); break; + default: Helpers::panic("Unimplemented svc: %x", svc); break; + } +} + +void Kernel::reset() { + +} + +// Result CreateAddressArbiter(Handle* arbiter) +// in: r0 -> Pointer to Handle object +// out: r0 -> result +void Kernel::createAddressArbiter() { + printf("Stubbed call to CreateAddressArbiter. Handle address: %08X\n", regs[0]); + regs[0] = SVCResult::Success; +} \ No newline at end of file diff --git a/src/emulator.cpp b/src/emulator.cpp index 445ccee1..905170fb 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -2,6 +2,7 @@ void Emulator::reset() { cpu.reset(); + kernel.reset(); } void Emulator::step() {}