aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPalmer Dabbelt <palmer@dabbelt.com>2017-07-03 12:43:47 -0700
committerGitHub <noreply@github.com>2017-07-03 12:43:47 -0700
commitce48a5d3daa1fa03272ee781125ac7350664aa8e (patch)
tree137c94898a895e7f32c3fd24d95383a32e3f02a7
parent4e2e730abef0789143a3e10db30eb2771e311731 (diff)
parent99a36735073724bb29270dadaa3fb8f71f9aa923 (diff)
downloadriscv-openocd-ce48a5d3daa1fa03272ee781125ac7350664aa8e.zip
riscv-openocd-ce48a5d3daa1fa03272ee781125ac7350664aa8e.tar.gz
riscv-openocd-ce48a5d3daa1fa03272ee781125ac7350664aa8e.tar.bz2
Merge pull request #72 from dmitryryzhov/examine_restore_temp_reg
Restore value of temporary register (s0) in examine OpenOCD procedure…
-rw-r--r--src/target/riscv/riscv-013.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c
index 60846de..213c6fc 100644
--- a/src/target/riscv/riscv-013.c
+++ b/src/target/riscv/riscv-013.c
@@ -1175,6 +1175,16 @@ static int examine(struct target *target)
* In order to make this work we first need to */
int offset = (progbuf_addr % 8 == 0) ? -4 : 0;
+ /* This program uses a temporary register. If the core can not
+ * execute 64 bit instruction, the original value of temporary
+ * register (s0) will not be restored due to an exception.
+ * So we have to save it and restore manually in that case.
+ * If the core can execute 64 bit instruction, the saved value
+ * is wrong, because it was read with 32 bit lw instruction,
+ * but the value of s0 will be restored by the reverse swap
+ * of s0 and dscratch registers. */
+ uint64_t s0 = riscv_get_register(target, GDB_REGNO_S0);
+
struct riscv_program program64;
riscv_program_init(&program64, target);
riscv_program_csrrw(&program64, GDB_REGNO_S0, GDB_REGNO_S0, GDB_REGNO_DSCRATCH);
@@ -1190,6 +1200,8 @@ static int examine(struct target *target)
+ dmi_read(target, DMI_PROGBUF0 + (4 + offset) / 4)
- 4;
r->xlen[i] = 64;
+ } else {
+ riscv_set_register(target, GDB_REGNO_S0, s0);
}
/* Display this as early as possible to help people who are using