From fcdecd88aecb98507e5e97926cdbbb84c36ce3b0 Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Thu, 14 Jan 2021 13:52:50 -0800 Subject: [PATCH] Don't write to zero. It doesn't have any effect on real hardware, and by caching the value we pretended it did. Fixes #564 Change-Id: I9f4e2cc8abddee61435bbd8d992cbff971a0c28d Signed-off-by: Tim Newsome --- src/target/riscv/riscv.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index 9978931a9..9a5656142 100644 --- a/src/target/riscv/riscv.c +++ b/src/target/riscv/riscv.c @@ -4165,6 +4165,11 @@ static int register_set(struct reg *reg, uint8_t *buf) riscv_current_hartid(target), str, reg->name, reg->valid); free(str); + /* Exit early for writing x0, which on the hardware would be ignored, and we + * don't want to update our cache. */ + if (reg->number == GDB_REGNO_ZERO) + return ERROR_OK; + memcpy(reg->value, buf, DIV_ROUND_UP(reg->size, 8)); reg->valid = gdb_regno_cacheable(reg->number, true);