From b337b0cfb4612c0474c109abeb511189bfd5559c Mon Sep 17 00:00:00 2001 From: Dolu1990 Date: Fri, 2 Dec 2022 18:38:40 +0100 Subject: [PATCH] riscv/run_algorithm : Add support for memory parameters (#773) * riscv/run_algorithm : Add support for memory parameters Change-Id: I5045a3843dcd96edb0cf8cc54bbd41969e3260a6 Signed-off-by: Dolu1990 * riscv/run_algorithm : better parameter handeling Change-Id: If3da8b83f784ef7b13ca83e98bc629e2219cc632 Signed-off-by: Dolu1990 * riscv/run_algorithm : Better mem param error reporting Change-Id: I09f99ca117f7e5373b23cad0f69d9d5b2a77e61d Signed-off-by: Dolu1990 Signed-off-by: Dolu1990 --- src/target/riscv/riscv.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index 958d1129c..9e46cda42 100644 --- a/src/target/riscv/riscv.c +++ b/src/target/riscv/riscv.c @@ -1956,16 +1956,24 @@ static int riscv_run_algorithm(struct target *target, int num_mem_params, { RISCV_INFO(info); - if (num_mem_params > 0) { - LOG_ERROR("Memory parameters are not supported for RISC-V algorithms."); - return ERROR_FAIL; - } - if (target->state != TARGET_HALTED) { LOG_WARNING("target not halted"); return ERROR_TARGET_NOT_HALTED; } + /* Write memory parameters to the target memory */ + for (int i = 0; i < num_mem_params; i++) { + if (mem_params[i].direction == PARAM_OUT || + mem_params[i].direction == PARAM_IN_OUT) { + int retval = target_write_buffer(target, mem_params[i].address, mem_params[i].size, mem_params[i].value); + if (retval != ERROR_OK) { + LOG_ERROR("Couldn't write input mem param into the memory, addr=0x%" TARGET_PRIxADDR " size=0x%" PRIx32, + mem_params[i].address, mem_params[i].size); + return retval; + } + } + } + /* Save registers */ struct reg *reg_pc = register_get_by_name(target->reg_cache, "pc", true); if (!reg_pc || reg_pc->type->get(reg_pc) != ERROR_OK) @@ -2091,6 +2099,20 @@ static int riscv_run_algorithm(struct target *target, int num_mem_params, } } + /* Read memory parameters from the target memory */ + for (int i = 0; i < num_mem_params; i++) { + if (mem_params[i].direction == PARAM_IN || + mem_params[i].direction == PARAM_IN_OUT) { + int retval = target_read_buffer(target, mem_params[i].address, mem_params[i].size, + mem_params[i].value); + if (retval != ERROR_OK) { + LOG_ERROR("Couldn't read output mem param from the memory, addr=0x%" TARGET_PRIxADDR " size=0x%" PRIx32, + mem_params[i].address, mem_params[i].size); + return retval; + } + } + } + return ERROR_OK; }