From 58fe2bcf18b57f11b0193cfe1bff28c074d3fe39 Mon Sep 17 00:00:00 2001 From: wheremyfoodat Date: Thu, 15 Sep 2022 22:13:25 +0300 Subject: [PATCH] Add cp15 --- CMakeLists.txt | 1 + include/cpu_dynarmic.hpp | 27 +++++++++--------- include/dynarmic_cp15.hpp | 53 +++++++++++++++++++++++++++++++++++ src/core/CPU/cpu_dynarmic.cpp | 15 +++++++--- 4 files changed, 79 insertions(+), 17 deletions(-) create mode 100644 include/dynarmic_cp15.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d79ec45..90f33f41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,7 @@ set(SOURCE_FILES src/main.cpp src/emulator.cpp src/core/CPU/cpu_dynarmic.cpp src ) 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/kernel.hpp + include/dynarmic_cp15.hpp ) set(THIRD_PARTY_SOURCE_FILES third_party/imgui/imgui.cpp diff --git a/include/cpu_dynarmic.hpp b/include/cpu_dynarmic.hpp index 7afd6742..f95fbed4 100644 --- a/include/cpu_dynarmic.hpp +++ b/include/cpu_dynarmic.hpp @@ -2,13 +2,14 @@ #include "dynarmic/interface/A32/a32.h" #include "dynarmic/interface/A32/config.h" +#include "dynarmic_cp15.hpp" #include "helpers.hpp" #include "kernel.hpp" #include "memory.hpp" class MyEnvironment final : public Dynarmic::A32::UserCallbacks { public: - u64 ticks_left = 0; + u64 ticksLeft = 0; Memory& mem; Kernel& kernel; @@ -59,23 +60,23 @@ public: } void AddTicks(u64 ticks) override { - if (ticks > ticks_left) { - ticks_left = 0; + if (ticks > ticksLeft) { + ticksLeft = 0; return; } - ticks_left -= ticks; + ticksLeft -= ticks; } u64 GetTicksRemaining() override { - return ticks_left; + return ticksLeft; } MyEnvironment(Memory& mem, Kernel& kernel) : mem(mem), kernel(kernel) {} }; class CPU { + std::unique_ptr jit; MyEnvironment env; - Dynarmic::A32::Jit jit{ {.callbacks = &env} }; Memory& mem; public: @@ -83,28 +84,28 @@ public: void reset(); void setReg(int index, u32 value) { - jit.Regs()[index] = value; + jit->Regs()[index] = value; } u32 getReg(int index) { - return jit.Regs()[index]; + return jit->Regs()[index]; } std::array& regs() { - return jit.Regs(); + return jit->Regs(); } void setCPSR(u32 value) { - jit.SetCpsr(value); + jit->SetCpsr(value); } u32 getCPSR() { - return jit.Cpsr(); + return jit->Cpsr(); } void runFrame() { - env.ticks_left = 268111856 / 60; - const auto exitReason = jit.Run(); + env.ticksLeft = 268111856 / 60; + const auto exitReason = jit->Run(); Helpers::panic("Exit reason: %d", (u32)exitReason); } }; \ No newline at end of file diff --git a/include/dynarmic_cp15.hpp b/include/dynarmic_cp15.hpp new file mode 100644 index 00000000..39b7cdd9 --- /dev/null +++ b/include/dynarmic_cp15.hpp @@ -0,0 +1,53 @@ +#pragma once + +#include "dynarmic/interface/A32/a32.h" +#include "dynarmic/interface/A32/config.h" +#include "dynarmic/interface/A32/coprocessor.h" +#include "helpers.hpp" + +class CP15 final : public Dynarmic::A32::Coprocessor { + using Callback = Dynarmic::A32::Coprocessor::Callback; + using CoprocReg = Dynarmic::A32::CoprocReg; + using CallbackOrAccessOneWord = Dynarmic::A32::Coprocessor::CallbackOrAccessOneWord; + using CallbackOrAccessTwoWords = Dynarmic::A32::Coprocessor::CallbackOrAccessTwoWords; + + u32 threadStoragePointer = 0x696966969; // Pointer to thread-local storage + + std::optional CompileInternalOperation(bool two, unsigned opc1, + CoprocReg CRd, CoprocReg CRn, + CoprocReg CRm, unsigned opc2) override { + return std::nullopt; + } + + CallbackOrAccessOneWord CompileSendOneWord(bool two, unsigned opc1, CoprocReg CRn, + CoprocReg CRm, unsigned opc2) override { + Helpers::panic("CP15: CompileSendOneWord\n"); + } + + CallbackOrAccessTwoWords CompileSendTwoWords(bool two, unsigned opc, CoprocReg CRm) override { + return std::monostate{}; + } + + CallbackOrAccessOneWord CompileGetOneWord(bool two, unsigned opc1, CoprocReg CRn, + CoprocReg CRm, unsigned opc2) override { + Helpers::panic("CP15: CompileGetOneWord"); + } + + CallbackOrAccessTwoWords CompileGetTwoWords(bool two, unsigned opc, CoprocReg CRm) override { + return std::monostate{}; + } + + std::optional CompileLoadWords(bool two, bool long_transfer, CoprocReg CRd, + std::optional option) override { + return std::nullopt; + } + + std::optional CompileStoreWords(bool two, bool long_transfer, CoprocReg CRd, + std::optional option) override { + return std::nullopt; + } + + 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 242ae8d4..67c9ef0f 100644 --- a/src/core/CPU/cpu_dynarmic.cpp +++ b/src/core/CPU/cpu_dynarmic.cpp @@ -1,15 +1,22 @@ #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) { + Dynarmic::A32::UserConfig config; + + config.callbacks = &env; + config.coprocessors[15] = std::make_shared(); + jit = std::make_unique(config); +} void CPU::reset() { // ARM mode, all flags disabled, interrupts and aborts all enabled, user mode + setCPSR(0x00000010); - jit.Reset(); - jit.ClearCache(); - jit.Regs().fill(0); + jit->Reset(); + jit->ClearCache(); + jit->Regs().fill(0); } #endif // CPU_DYNARMIC \ No newline at end of file