From 0a8bb6da9d739d3fc6079cbf283f4dc8f6554aab Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 24 Jul 2025 16:34:56 -0400 Subject: oemu: cpu: Keep X0 zerored as per the OSMX64 spec Ensure that after every instruction, we undo any potential side effects or operations upon the X0 register. The "Registers" section of the OSMX64 spec states that X0 is a 64-bit, always-zero and readonly register. All writes to this register are to be ignored by the processor. Signed-off-by: Ian Moffett --- usr.bin/oemu/cpu.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'usr.bin/oemu/cpu.c') diff --git a/usr.bin/oemu/cpu.c b/usr.bin/oemu/cpu.c index 5a2c761..fefdd4c 100644 --- a/usr.bin/oemu/cpu.c +++ b/usr.bin/oemu/cpu.c @@ -408,6 +408,13 @@ cpu_kick(struct oemu_cpu *cpu, struct sysmem *mem) break; } + /* + * X0 is readonly and should always be zero, undo + * any writes or side effects from any operations + * upon this register. + */ + regs->xreg[0] = 0; + /* Is this a halt instruction? */ if (inst->opcode == INST_HLT) { printf("HALTED\n"); -- cgit v1.2.3