Start adding memory stuff

This commit is contained in:
wheremyfoodat 2022-09-15 13:35:15 +03:00
parent 2057e0c447
commit 905c7ed770
8 changed files with 77 additions and 10 deletions

View file

@ -1,15 +1,16 @@
#ifdef CPU_DYNARMIC
#include "cpu_dynarmic.hpp"
CPU::CPU() {
CPU::CPU(Memory& mem) : mem(mem) {
// Execute at least 1 instruction.
// (Note: More than one instruction may be executed.)
env.ticks_left = 1;
env.ticks_left = 10;
// Write some code to memory.
env.MemoryWrite16(0, 0x0088); // lsls r0, r1, #2
env.MemoryWrite16(2, 0x3045); // adds r0, #69
env.MemoryWrite16(4, 0xE7FE); // b +#0 (infinite loop)
env.MemoryWrite16(4, 0xdf45); // swi #69
env.MemoryWrite16(6, 0xE7FE); // b +#0 (infinite loop)
// Setup registers.
auto& regs = jit.Regs();
@ -25,4 +26,10 @@ CPU::CPU() {
printf("R0: %u\n", jit.Regs()[0]);
}
void CPU::reset() {
jit.Regs().fill(0);
// ARM mode, all flags disabled, interrupts and aborts all enabled, user mode
setCPSR(0x00000010);
}
#endif // CPU_DYNARMIC

23
src/core/memory.cpp Normal file
View file

@ -0,0 +1,23 @@
#include "memory.hpp"
Memory::Memory() {
fcram = new uint8_t[128_MB]();
}
void* Memory::getReadPointer(u32 address) {
const auto page = address >> pageShift;
const auto offset = address & pageMask;
uintptr_t pointer = readTable[page];
if (pointer == 0) return nullptr;
return (void*)(pointer + offset);
}
void* Memory::getWritePointer(u32 address) {
const auto page = address >> pageShift;
const auto offset = address & pageMask;
uintptr_t pointer = writeTable[page];
if (pointer == 0) return nullptr;
return (void*)(pointer + offset);
}

View file

@ -1,6 +1,8 @@
#include "emulator.hpp"
void Emulator::reset() {}
void Emulator::reset() {
cpu.reset();
}
void Emulator::step() {}