diff options
author | Ian Moffett <ian@osmora.org> | 2025-07-24 16:34:56 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-07-24 16:34:56 -0400 |
commit | 0a8bb6da9d739d3fc6079cbf283f4dc8f6554aab (patch) | |
tree | 91650c3f0136c623091b2153f3cb1943eada41c8 | |
parent | 0fa3dd385ce95647d1878bf863efa9ee251fdbdb (diff) |
oemu: cpu: Keep X0 zerored as per the OSMX64 specmain
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 <ian@osmora.org>
-rw-r--r-- | usr.bin/oemu/cpu.c | 7 |
1 files changed, 7 insertions, 0 deletions
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"); |