This commit is contained in:
wheremyfoodat 2022-09-15 22:13:25 +03:00
parent e0204a1eff
commit 58fe2bcf18
4 changed files with 79 additions and 17 deletions

View file

@ -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

View file

@ -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<Dynarmic::A32::Jit> 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<u32, 16>& 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);
}
};

53
include/dynarmic_cp15.hpp Normal file
View file

@ -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<Callback> 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<Callback> CompileLoadWords(bool two, bool long_transfer, CoprocReg CRd,
std::optional<u8> option) override {
return std::nullopt;
}
std::optional<Callback> CompileStoreWords(bool two, bool long_transfer, CoprocReg CRd,
std::optional<u8> option) override {
return std::nullopt;
}
void reset() {
}
};

View file

@ -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<CP15>();
jit = std::make_unique<Dynarmic::A32::Jit>(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