From 8bb494229d676e9efee2f724350d5f13db9579f3 Mon Sep 17 00:00:00 2001 From: wheremyfoodat Date: Sat, 17 Sep 2022 01:31:45 +0300 Subject: [PATCH] Fix LDREX/STREX --- include/cpu_dynarmic.hpp | 27 ++++++++++++++++++++++++++- src/core/CPU/cpu_dynarmic.cpp | 5 +++++ src/core/memory.cpp | 11 ++++++++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/include/cpu_dynarmic.hpp b/include/cpu_dynarmic.hpp index 31c045d0..d5b79750 100644 --- a/include/cpu_dynarmic.hpp +++ b/include/cpu_dynarmic.hpp @@ -2,6 +2,7 @@ #include "dynarmic/interface/A32/a32.h" #include "dynarmic/interface/A32/config.h" +#include "dynarmic/interface/exclusive_monitor.h" #include "dynarmic_cp15.hpp" #include "helpers.hpp" #include "kernel.hpp" @@ -45,6 +46,26 @@ public: mem.write64(vaddr, value); } + bool MemoryWriteExclusive8(u32 addr, u8 value, u8 expected) override { + mem.write8(addr, value); + return true; + } + + bool MemoryWriteExclusive16(u32 addr, u16 value, u16 expected) override { + mem.write16(addr, value); + return true; + } + + bool MemoryWriteExclusive32(u32 addr, u32 value, u32 expected) override { + mem.write32(addr, value); + return true; + } + + bool MemoryWriteExclusive64(u32 addr, u64 value, u64 expected) override { + mem.write64(addr, value); + return true; + } + void InterpreterFallback(u32 pc, size_t num_instructions) override { // This is never called in practice. std::terminate(); @@ -76,6 +97,9 @@ public: class CPU { std::unique_ptr jit; std::shared_ptr cp15; + + // Make exclusive monitor with only 1 CPU core + Dynarmic::ExclusiveMonitor exclusiveMonitor{1}; MyEnvironment env; Memory& mem; @@ -106,6 +130,7 @@ public: void runFrame() { env.ticksLeft = 268111856 / 60; const auto exitReason = jit->Run(); - Helpers::panic("Exit reason: %d", (u32)exitReason); + for (u32 i = 0; i < 4; i++)printf("r%d: %08X\n", i, getReg(i)); + Helpers::panic("Exit reason: %d\nPC: %08X", (u32)exitReason, getReg(15)); } }; \ No newline at end of file diff --git a/src/core/CPU/cpu_dynarmic.cpp b/src/core/CPU/cpu_dynarmic.cpp index 279b928b..4e16478d 100644 --- a/src/core/CPU/cpu_dynarmic.cpp +++ b/src/core/CPU/cpu_dynarmic.cpp @@ -5,8 +5,13 @@ CPU::CPU(Memory& mem, Kernel& kernel) : mem(mem), env(mem, kernel) { cp15 = std::make_shared(); Dynarmic::A32::UserConfig config; + config.arch_version = Dynarmic::A32::ArchVersion::v6K; config.callbacks = &env; config.coprocessors[15] = cp15; + // config.define_unpredictable_behaviour = true; + config.global_monitor = &exclusiveMonitor; + config.processor_id = 0; + jit = std::make_unique(config); } diff --git a/src/core/memory.cpp b/src/core/memory.cpp index cac66d11..50e91c7a 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -114,7 +114,16 @@ std::optional Memory::findPaddr(u32 size) { } u8 Memory::read8(u32 vaddr) { - Helpers::panic("Unimplemented 8-bit read, addr: %08X", vaddr); + const u32 page = vaddr >> pageShift; + const u32 offset = vaddr & pageMask; + + uintptr_t pointer = readTable[page]; + if (pointer != 0) [[likely]] { + return *(u8*)(pointer + offset); + } + else { + Helpers::panic("Unimplemented 8-bit read, addr: %08X", vaddr); + } } u16 Memory::read16(u32 vaddr) {