diff --git a/core/ARM/cpu.h b/core/ARM/cpu.h index c2ca23c..c8fc3aa 100644 --- a/core/ARM/cpu.h +++ b/core/ARM/cpu.h @@ -11,7 +11,28 @@ struct CPU { CPU() { std::memset(memory, 0, MEM_SIZE); } - uint64_t& x(int i) { return regs[i]; } + uint64_t &x(int i) { return regs[i]; } + + uint8_t read_byte(uint64_t addr) { + if (addr >= MEM_SIZE) { + printf("%s out of bounds\n", addr); + } + return memory[addr]; + } + + void write_byte(uint64_t addr, uint8_t byte) { + if (addr >= MEM_SIZE) { + printf("%s out of bounds\n", addr); + } + memory[addr] = byte; + } + + void print_debug_information() { + printf("PC = %lu\n", pc); + for (int reg = 0; reg < 32; reg++) { + printf("X%i = %lu\n", reg, x(reg)); // X0 = 0... + } + } }; #endif \ No newline at end of file diff --git a/ui/main.cpp b/ui/main.cpp index c602897..2be23b8 100644 --- a/ui/main.cpp +++ b/ui/main.cpp @@ -3,20 +3,23 @@ #include -int main() -{ +int main() { CPU cpu; cpu.pc = 0; // Simple ARMv8 program in memory (MOVZ X0, #5; ADD X0, X0, #3; RET) // These are placeholders; real encoding will be parsed later - cpu.memory[0] = 0x05; // MOVZ placeholder - cpu.memory[4] = 0x03; // ADD placeholder - cpu.memory[8] = 0xFF; // RET placeholder + cpu.write_byte(0, 0x05); // MOVZ placeholder + cpu.write_byte(4, 0x03); // ADD placeholder + cpu.write_byte(8, 0xFF); // RET placeholder + + printf("%u\n", cpu.read_byte(0)); JIT jit; jit.translate_and_run(cpu); - printf("X0 = %llu\n", cpu.regs[0]); + cpu.print_debug_information(); + + printf("X0 = %lu\n", cpu.x(0)); return 0; } \ No newline at end of file