Finish ELF loading, running actual code now

This commit is contained in:
wheremyfoodat 2022-09-15 17:35:59 +03:00
parent 51689af51f
commit 275c6dfd0c
7 changed files with 135 additions and 59 deletions

View file

@ -1,35 +1,15 @@
#ifdef CPU_DYNARMIC
#include "cpu_dynarmic.hpp"
CPU::CPU(Memory& mem) : mem(mem) {
// Execute at least 1 instruction.
// (Note: More than one instruction may be executed.)
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, 0x3845); // subs r0, #69
env.MemoryWrite16(6, 0xE7FE); // b +#0 (infinite loop)
// Setup registers.
auto& regs = jit.Regs();
regs[0] = 1;
regs[1] = 2;
regs[15] = 0; // PC = 0
setCPSR(0x00000030); // Thumb mode
// Execute!
jit.Run();
// Here we would expect cpu.Regs()[0] == 77
printf("R0: %u\n", jit.Regs()[0]);
}
CPU::CPU(Memory& mem) : mem(mem), env(mem) {}
void CPU::reset() {
jit.Regs().fill(0);
// ARM mode, all flags disabled, interrupts and aborts all enabled, user mode
setCPSR(0x00000010);
jit.Reset();
jit.ClearCache();
jit.Regs().fill(0);
}
#endif // CPU_DYNARMIC