Skip to content

Commit

Permalink
target/riscv: support disable auto fence
Browse files Browse the repository at this point in the history
Support disable automatic fence, it's useful for
debug some cache related issue.
  • Loading branch information
zqb-all committed Oct 30, 2024
1 parent 9ff272e commit d6dfb9c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/openocd.texi
Original file line number Diff line number Diff line change
Expand Up @@ -11631,6 +11631,12 @@ riscv exec_progbuf 0x0330000f 0x0000100f
riscv exec_progbuf 0x94a20405
@end example

@deffn {Command} {riscv autofence} [on|off]
When on (default), some situations, such as stepi, will automatically execute fence.
When off, user needs to take care of the cache themselves, for example, using the
riscv exec_progbuf to execute fence or cmo command.
@end deffn

@section ARC Architecture
@cindex ARC

Expand Down
7 changes: 7 additions & 0 deletions src/target/riscv/riscv-013.c
Original file line number Diff line number Diff line change
Expand Up @@ -2918,6 +2918,10 @@ static int execute_fence(struct target *target)
if (dm013_select_target(target) != ERROR_OK)
return ERROR_FAIL;

RISCV_INFO(r);
if (!r->auto_fence)
return ERROR_OK;

/* FIXME: For non-coherent systems we need to flush the caches right
* here, but there's no ISA-defined way of doing that. */
struct riscv_program program;
Expand All @@ -2941,6 +2945,7 @@ static int execute_fence(struct target *target)
}
LOG_TARGET_DEBUG(target, "Unable to execute fence");
}
LOG_TARGET_DEBUG(target, "Successfully executed fence");
return ERROR_OK;
}

Expand All @@ -2954,6 +2959,7 @@ static int execute_fence(struct target *target)
}
LOG_TARGET_DEBUG(target, "Unable to execute fence.i");
}
LOG_TARGET_DEBUG(target, "Successfully executed fence.i");

riscv_program_init(&program, target);
riscv_program_fence_rw_rw(&program);
Expand All @@ -2964,6 +2970,7 @@ static int execute_fence(struct target *target)
}
LOG_TARGET_DEBUG(target, "Unable to execute fence rw, rw");
}
LOG_TARGET_DEBUG(target, "Successfully executed fence rw, rw");
return ERROR_OK;
}

Expand Down
29 changes: 29 additions & 0 deletions src/target/riscv/riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -4521,6 +4521,23 @@ COMMAND_HANDLER(riscv_set_maskisr)
return ERROR_OK;
}

COMMAND_HANDLER(riscv_set_autofence)
{
struct target *target = get_current_target(CMD_CTX);
RISCV_INFO(r);

if (CMD_ARGC != 1) {
command_print(CMD, "autofence enabled: %s", r->autofence ? "on" : "off");
return ERROR_OK;
} else if (CMD_ARGC == 1) {
COMMAND_PARSE_ON_OFF(CMD_ARGV[0], r->autofence);
return ERROR_OK;
}

LOG_ERROR("Command takes 0 or 1 parameters");
return ERROR_COMMAND_SYNTAX_ERROR;
}

COMMAND_HANDLER(riscv_set_ebreakm)
{
struct target *target = get_current_target(CMD_CTX);
Expand Down Expand Up @@ -5428,6 +5445,16 @@ static const struct command_registration riscv_exec_command_handlers[] = {
"hw - translate vaddr to paddr by hardware, "
"off - no address translation."
},
{
.name = "autofence",
.handler = riscv_set_autofence,
.mode = COMMAND_ANY,
.usage = "[on|off]",
.help = "When on (default), some situations, such as stepi, will automatically execute fence. "
"When off, user needs to take care of the cache themselves, for example, using the "
"riscv exec_progbuf to execute fence or cmo command."

},
COMMAND_REGISTRATION_DONE
};

Expand Down Expand Up @@ -5569,6 +5596,8 @@ static void riscv_info_init(struct target *target, struct riscv_info *r)
r->wp_allow_equality_match_trigger = true;
r->wp_allow_ge_lt_trigger = true;
r->wp_allow_napot_trigger = true;

r->autofence = true;
}

static int riscv_resume_go_all_harts(struct target *target)
Expand Down
2 changes: 2 additions & 0 deletions src/target/riscv/riscv.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ struct riscv_info {
bool wp_allow_equality_match_trigger;
bool wp_allow_napot_trigger;
bool wp_allow_ge_lt_trigger;

bool autofence;
};

COMMAND_HELPER(riscv_print_info_line, const char *section, const char *key,
Expand Down

0 comments on commit d6dfb9c

Please sign in to comment.