Skip to content

Commit

Permalink
target/riscv: fix execute_fence
Browse files Browse the repository at this point in the history
This patch improves the following issues:
1. Makes it compatible with targets with progbufsize == 1.
2. Although exceptions don’t update any registers, but  do end execution
of the progbuf. This will make fence rw, rw impossible to execute.

Change-Id: I2208fd31ec6a7dae6e61c5952f90901568caada6
Signed-off-by: Xiang W <[email protected]>
  • Loading branch information
wxjstz committed Aug 12, 2023
1 parent ee5c5c2 commit a7a3d3e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/target/riscv/riscv-013.c
Original file line number Diff line number Diff line change
Expand Up @@ -2845,13 +2845,19 @@ 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);
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);
int result = riscv_program_exec(&program, target);
result = riscv_program_exec(&program, target);
if (result != ERROR_OK)
LOG_TARGET_DEBUG(target, "Unable to execute pre-fence");
LOG_TARGET_DEBUG(target, "Unable to execute fence rw, rw");

return ERROR_OK;
}
Expand Down Expand Up @@ -4995,7 +5001,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 a7a3d3e

Please sign in to comment.