aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Newsome <tim@sifive.com>2018-01-04 17:12:01 -0800
committerTim Newsome <tim@sifive.com>2018-01-04 17:12:01 -0800
commit6f3913cedcc0fc2399937e70f44b45c5fbff25a8 (patch)
tree95f700dac3ee40a0120f3c235bfc9d2df9a029cf
parent82529e71e0e686d11dcf4c505d13d5c6b3da9d73 (diff)
downloadriscv-openocd-6f3913cedcc0fc2399937e70f44b45c5fbff25a8.zip
riscv-openocd-6f3913cedcc0fc2399937e70f44b45c5fbff25a8.tar.gz
riscv-openocd-6f3913cedcc0fc2399937e70f44b45c5fbff25a8.tar.bz2
Select current hart before reading memory.
This avoids trying to read memory from the wrong hart, if the current hart was changed by an earlier call (eg. to poll()). Change-Id: I73da1e01c8d01d68f01ac7fdd6c548380a70cfd3
-rw-r--r--src/target/riscv/riscv.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c
index 009bc3a..5ea0c94 100644
--- a/src/target/riscv/riscv.c
+++ b/src/target/riscv/riscv.c
@@ -720,9 +720,19 @@ static int old_or_new_riscv_resume(
return riscv_openocd_resume(target, current, address, handle_breakpoints, debug_execution);
}
+static void riscv_select_current_hart(struct target *target)
+{
+ RISCV_INFO(r);
+ if (r->rtos_hartid != -1 && riscv_rtos_enabled(target))
+ riscv_set_current_hartid(target, r->rtos_hartid);
+ else
+ riscv_set_current_hartid(target, target->coreid);
+}
+
static int riscv_read_memory(struct target *target, target_addr_t address,
uint32_t size, uint32_t count, uint8_t *buffer)
{
+ riscv_select_current_hart(target);
struct target_type *tt = get_target_type(target);
return tt->read_memory(target, address, size, count, buffer);
}
@@ -730,6 +740,7 @@ static int riscv_read_memory(struct target *target, target_addr_t address,
static int riscv_write_memory(struct target *target, target_addr_t address,
uint32_t size, uint32_t count, const uint8_t *buffer)
{
+ riscv_select_current_hart(target);
struct target_type *tt = get_target_type(target);
return tt->write_memory(target, address, size, count, buffer);
}
@@ -747,10 +758,7 @@ static int riscv_get_gdb_reg_list(struct target *target,
return ERROR_FAIL;
}
- if (r->rtos_hartid != -1 && riscv_rtos_enabled(target))
- riscv_set_current_hartid(target, r->rtos_hartid);
- else
- riscv_set_current_hartid(target, target->coreid);
+ riscv_select_current_hart(target);
switch (reg_class) {
case REG_CLASS_GENERAL: