diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 2d34550f6..cc06fa722 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -954,14 +954,6 @@ static int execute_resume(struct target *target, bool step) return ERROR_FAIL; } - // Restore GPRs - if (register_write_direct(target, S0, reg_cache_get(target, S0)) != ERROR_OK) { - return ERROR_FAIL; - } - if (register_write_direct(target, S1, reg_cache_get(target, S1)) != ERROR_OK) { - return ERROR_FAIL; - } - struct reg *mstatus_reg = &target->reg_cache->reg_list[REG_MSTATUS]; if (mstatus_reg->valid) { uint64_t mstatus_user = buf_get_u64(mstatus_reg->value, 0, xlen(target)); @@ -985,6 +977,14 @@ static int execute_resume(struct target *target, bool step) return ERROR_FAIL; } + // Restore GPRs + if (register_write_direct(target, S0, reg_cache_get(target, S0)) != ERROR_OK) { + return ERROR_FAIL; + } + if (register_write_direct(target, S1, reg_cache_get(target, S1)) != ERROR_OK) { + return ERROR_FAIL; + } + program_t *program = program_new(); program_add32(program, fence_i()); program_add32(program, ebreak());