Skip to content

Commit

Permalink
Merge pull request riscv-collab#903 from wxjstz/riscv
Browse files Browse the repository at this point in the history
target/riscv: fix execute_fence
  • Loading branch information
timsifive authored Aug 18, 2023
2 parents f061623 + 373b8f1 commit 5cb60e3
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions src/target/riscv/riscv-013.c
Original file line number Diff line number Diff line change
Expand Up @@ -2920,15 +2920,35 @@ static int execute_fence(struct target *target)

/* FIXME: For non-coherent systems we need to flush the caches right
* here, but there's no ISA-defined way of doing that. */
int result;
struct riscv_program program;
riscv_program_init(&program, target);
riscv_program_fence_i(&program);
riscv_program_fence_rw_rw(&program);
int result = riscv_program_exec(&program, target);
if (result != ERROR_OK)
LOG_TARGET_DEBUG(target, "Unable to execute pre-fence");

return ERROR_OK;
if (has_sufficient_progbuf(target, 3)) {
riscv_program_init(&program, target);
riscv_program_fence_rw_rw(&program);
riscv_program_fence_i(&program);
result = riscv_program_exec(&program, target);
if (result != ERROR_OK)
LOG_TARGET_DEBUG(target, "Unable to execute pre-fence");
return ERROR_OK;
}

if (has_sufficient_progbuf(target, 2)) {
riscv_program_init(&program, target);
riscv_program_fence_i(&program);
result = riscv_program_exec(&program, target);
if (result != ERROR_OK)
LOG_TARGET_DEBUG(target, "Unable to execute fence.i");

riscv_program_init(&program, target);
riscv_program_fence_rw_rw(&program);
result = riscv_program_exec(&program, target);
if (result != ERROR_OK)
LOG_TARGET_DEBUG(target, "Unable to execute fence rw, rw");
return ERROR_OK;
}

return ERROR_FAIL;
}

static void log_memory_access128(target_addr_t address, uint64_t value_h,
Expand Down Expand Up @@ -5070,7 +5090,7 @@ void riscv013_fill_dm_nop_u64(struct target *target, char *buf)

static int maybe_execute_fence_i(struct target *target)
{
if (has_sufficient_progbuf(target, 3))
if (has_sufficient_progbuf(target, 2))
return execute_fence(target);
return ERROR_OK;
}
Expand Down

0 comments on commit 5cb60e3

Please sign in to comment.