From 5d3f5c35d285fe7dc684fcbd94d3c5a8b4e8b8e1 Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Wed, 18 Oct 2017 12:32:41 -0700 Subject: [PATCH] Still restore registers if an access failed. Change-Id: I11571f0926f69a34f95b4929f633fdecd3a4e810 --- src/target/riscv/riscv-013.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 70531e9ad..5495516b0 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -781,14 +781,13 @@ static int register_write_direct(struct target *target, unsigned number, int exec_out = riscv_program_exec(&program, target); if (exec_out != ERROR_OK) { riscv013_clear_abstract_error(target); - return ERROR_FAIL; } // Restore S0. if (register_write_direct(target, GDB_REGNO_S0, s0) != ERROR_OK) return ERROR_FAIL; - return ERROR_OK; + return exec_out; } /** Actually read registers from the target right now. */ @@ -798,6 +797,8 @@ static int register_read_direct(struct target *target, uint64_t *value, uint32_t riscv_xlen(target)); if (result != ERROR_OK) { + result = ERROR_OK; + struct riscv_program program; riscv_program_init(&program, target); assert(number != GDB_REGNO_S0); @@ -823,10 +824,9 @@ static int register_read_direct(struct target *target, uint64_t *value, uint32_t } // Execute program. - int exec_out = riscv_program_exec(&program, target); - if (exec_out != ERROR_OK) { + result = riscv_program_exec(&program, target); + if (result != ERROR_OK) { riscv013_clear_abstract_error(target); - return ERROR_FAIL; } // Read S0 @@ -837,9 +837,12 @@ static int register_read_direct(struct target *target, uint64_t *value, uint32_t return ERROR_FAIL; } - LOG_DEBUG("[%d] reg[0x%x] = 0x%" PRIx64, riscv_current_hartid(target), - number, *value); - return ERROR_OK; + if (result == ERROR_OK) { + LOG_DEBUG("[%d] reg[0x%x] = 0x%" PRIx64, riscv_current_hartid(target), + number, *value); + } + + return result; } /*** OpenOCD target functions. ***/