Skip to content

Commit

Permalink
target/riscv: pass memory access info in struct, move write_memory po…
Browse files Browse the repository at this point in the history
…inter

This changes will allow to unite read_memory/write_memory fucntions
to one access function

(1) Replaced read/write functions arguments with one structure
(2) Unified read_memory/write_memory function pointers
    to be stored in same structure

Signed-off-by: Farid Khaydari <[email protected]>
  • Loading branch information
fk-sc committed Nov 21, 2024
1 parent f51900b commit c61d424
Show file tree
Hide file tree
Showing 4 changed files with 380 additions and 308 deletions.
26 changes: 20 additions & 6 deletions src/target/riscv/riscv-011.c
Original file line number Diff line number Diff line change
Expand Up @@ -1972,9 +1972,14 @@ static int deassert_reset(struct target *target)
return wait_for_state(target, TARGET_RUNNING);
}

static int read_memory(struct target *target, target_addr_t address,
uint32_t size, uint32_t count, uint8_t *buffer, uint32_t increment)
static int read_memory(struct target *target, const riscv_mem_access_args_t args)
{
target_addr_t address = args.address;
uint32_t size = args.size;
uint32_t count = args.count;
uint8_t *buffer = args.buffer.read;
uint32_t increment = args.increment;

if (increment != size) {
LOG_ERROR("read_memory with custom increment not implemented");
return ERROR_NOT_IMPLEMENTED;
Expand Down Expand Up @@ -2142,9 +2147,18 @@ static int setup_write_memory(struct target *target, uint32_t size)
return ERROR_OK;
}

static int write_memory(struct target *target, target_addr_t address,
uint32_t size, uint32_t count, const uint8_t *buffer)
static int write_memory(struct target *target, const riscv_mem_access_args_t args)
{
if (args.increment != args.size) {
LOG_TARGET_ERROR(target, "Write increment size has to be equal to element size");
return ERROR_NOT_IMPLEMENTED;
}

target_addr_t address = args.address;
uint32_t size = args.size;
uint32_t count = args.count;
const uint8_t *buffer = args.buffer.write;

riscv011_info_t *info = get_info(target);
jtag_add_ir_scan(target->tap, &select_dbus, TAP_IDLE);

Expand Down Expand Up @@ -2371,7 +2385,9 @@ static int init_target(struct command_context *cmd_ctx,
{
LOG_DEBUG("init");
RISCV_INFO(generic_info);
/* TODO: replace read and write with single access function*/
generic_info->read_memory = read_memory;
generic_info->write_memory = write_memory;
generic_info->authdata_read = &riscv011_authdata_read;
generic_info->authdata_write = &riscv011_authdata_write;
generic_info->print_info = &riscv011_print_info;
Expand Down Expand Up @@ -2406,7 +2422,5 @@ struct target_type riscv011_target = {
.assert_reset = assert_reset,
.deassert_reset = deassert_reset,

.write_memory = write_memory,

.arch_state = arch_state,
};
Loading

0 comments on commit c61d424

Please sign in to comment.