Skip to content

Commit

Permalink
introduce execution status for riscv_program
Browse files Browse the repository at this point in the history
This commit addresses #933

Change-Id: I318d5fd6af3a17d1c1099401427ca80ffbec0007
Signed-off-by: Parshintsev Anatoly <anatoly.parshintsev@syntacore.com>
  • Loading branch information
aap-sc committed Nov 16, 2023
1 parent 6de536b commit 464fb8d
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 73 deletions.
6 changes: 5 additions & 1 deletion src/target/riscv/program.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ int riscv_program_init(struct riscv_program *p, struct target *target)
for (size_t i = 0; i < RISCV_MAX_DEBUG_BUFFER_SIZE; ++i)
p->debug_buffer[i] = -1;

p->exec_status = RISCV_DBGBUF_EXEC_RESULT_NOT_EXECUTED;
return ERROR_OK;
}

Expand All @@ -46,6 +47,7 @@ int riscv_program_exec(struct riscv_program *p, struct target *t)
{
keep_alive();

p->exec_status = RISCV_DBGBUF_EXEC_RESULT_UNKNOWN;
riscv_reg_t saved_registers[GDB_REGNO_XPR31 + 1];
for (size_t i = GDB_REGNO_ZERO + 1; i <= GDB_REGNO_XPR31; ++i) {
if (p->writes_xreg[i]) {
Expand All @@ -67,11 +69,13 @@ int riscv_program_exec(struct riscv_program *p, struct target *t)
if (riscv_program_write(p) != ERROR_OK)
return ERROR_FAIL;

if (riscv_execute_debug_buffer(t) != ERROR_OK) {
if (riscv_execute_debug_buffer(t, &p->exec_status) != ERROR_OK) {
/* TODO: what happens if we fail here, but need to restore registers? */
LOG_TARGET_DEBUG(t, "Unable to execute program %p", p);
return ERROR_FAIL;
}

/* TODO: what happens if we can not restore context ? */
for (size_t i = GDB_REGNO_ZERO; i <= GDB_REGNO_XPR31; ++i)
if (p->writes_xreg[i])
riscv_set_register(t, i, saved_registers[i]);
Expand Down
4 changes: 4 additions & 0 deletions src/target/riscv/program.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ struct riscv_program {

/* XLEN on the target. */
int target_xlen;

/* execution status of the command */
/* TODO: remove this field. We should make it a parameter to riscv_program_exec */
riscv_dbgbuf_exec_status_t exec_status;
};

/* Initializes a program with the header. */
Expand Down
Loading

0 comments on commit 464fb8d

Please sign in to comment.