target/riscv: Add some event callbacks.

Specifically, call into the RISC-V version when target becomes halted,
running, or unavailable.

I'll be using unavailable shortly.

Change-Id: I9ffffdccbf22e053fe6390d656b362bf9ab9559a
Signed-off-by: Tim Newsome <tim@sifive.com>
This commit is contained in:
Tim Newsome 2023-06-05 10:39:12 -07:00
parent 6e64b685f4
commit 34f9ff0d0d
2 changed files with 21 additions and 0 deletions

View File

@ -2752,6 +2752,10 @@ static int riscv_poll_hart(struct target *target, enum riscv_next_action *next_a
} }
} }
if (r->handle_became_halted &&
r->handle_became_halted(target, previous_riscv_state) != ERROR_OK)
return ERROR_FAIL;
/* We shouldn't do the callbacks yet. What if /* We shouldn't do the callbacks yet. What if
* there are multiple harts that halted at the * there are multiple harts that halted at the
* same time? We need to set debug reason on each * same time? We need to set debug reason on each
@ -2769,12 +2773,18 @@ static int riscv_poll_hart(struct target *target, enum riscv_next_action *next_a
LOG_TARGET_DEBUG(target, " triggered running"); LOG_TARGET_DEBUG(target, " triggered running");
target->state = TARGET_RUNNING; target->state = TARGET_RUNNING;
target->debug_reason = DBG_REASON_NOTHALTED; target->debug_reason = DBG_REASON_NOTHALTED;
if (r->handle_became_running &&
r->handle_became_running(target, previous_riscv_state) != ERROR_OK)
return ERROR_FAIL;
break; break;
case RISCV_STATE_UNAVAILABLE: case RISCV_STATE_UNAVAILABLE:
LOG_TARGET_DEBUG(target, " became unavailable"); LOG_TARGET_DEBUG(target, " became unavailable");
LOG_TARGET_INFO(target, "became unavailable."); LOG_TARGET_INFO(target, "became unavailable.");
target->state = TARGET_UNAVAILABLE; target->state = TARGET_UNAVAILABLE;
if (r->handle_became_unavailable &&
r->handle_became_unavailable(target, previous_riscv_state) != ERROR_OK)
return ERROR_FAIL;
break; break;
case RISCV_STATE_NON_EXISTENT: case RISCV_STATE_NON_EXISTENT:

View File

@ -193,6 +193,17 @@ struct riscv_info {
* was resumed. */ * was resumed. */
int (*resume_go)(struct target *target); int (*resume_go)(struct target *target);
int (*step_current_hart)(struct target *target); int (*step_current_hart)(struct target *target);
/* These get called from riscv_poll_hart(), which is a house of cards
* together with openocd_poll(), so be careful not to upset things too
* much. */
int (*handle_became_halted)(struct target *target,
enum riscv_hart_state previous_riscv_state);
int (*handle_became_running)(struct target *target,
enum riscv_hart_state previous_riscv_state);
int (*handle_became_unavailable)(struct target *target,
enum riscv_hart_state previous_riscv_state);
/* Get this target as ready as possible to resume, without actually /* Get this target as ready as possible to resume, without actually
* resuming. */ * resuming. */
int (*resume_prep)(struct target *target); int (*resume_prep)(struct target *target);