Skip to content

Commit

Permalink
target/riscv: support riscv repeat_read by sysbus access
Browse files Browse the repository at this point in the history
Signed-off-by: liangzhen <[email protected]>
  • Loading branch information
lz-bro committed Sep 21, 2023
1 parent 2427f58 commit a8ffda6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/target/riscv/riscv-013.c
Original file line number Diff line number Diff line change
Expand Up @@ -3175,7 +3175,7 @@ static int read_memory_bus_v1(struct target *target, target_addr_t address,

RISCV013_INFO(info);
target_addr_t next_address = address;
target_addr_t end_address = address + count * size;
target_addr_t end_address = address + (increment ? count : 1) * size;

while (next_address < end_address) {
uint32_t sbcs_write = set_field(0, DM_SBCS_SBREADONADDR, 1);
Expand Down Expand Up @@ -3206,6 +3206,7 @@ static int read_memory_bus_v1(struct target *target, target_addr_t address,
uint32_t sbvalue[4] = {0};
assert(size <= 16);
target_addr_t next_read = address - 1;
uint32_t buffer_offset = 0;
int next_read_j = 0;
for (uint32_t i = (next_address - address) / size; i < count - 1; i++) {
for (int j = (size - 1) / 4; j >= 0; j--) {
Expand All @@ -3227,14 +3228,15 @@ static int read_memory_bus_v1(struct target *target, target_addr_t address,
return ERROR_FAIL;
}
if (next_read != address - 1) {
buf_set_u32(buffer + next_read - address, 0, 8 * MIN(size, 4), sbvalue[next_read_j]);
buf_set_u32(buffer + buffer_offset, 0, 8 * MIN(size, 4), sbvalue[next_read_j]);
if (next_read_j == 0) {
log_memory_access(next_read, sbvalue, size, true);
memset(sbvalue, 0, size);
}
}
next_read_j = j;
next_read = address + i * size + next_read_j * 4;
next_read = address + i * increment + next_read_j * 4;
buffer_offset = i * size + next_read_j * 4;
}
}

Expand All @@ -3255,7 +3257,7 @@ static int read_memory_bus_v1(struct target *target, target_addr_t address,
else
return ERROR_FAIL;
}
buf_set_u32(buffer + next_read - address, 0, 8 * MIN(size, 4), sbvalue[0]);
buf_set_u32(buffer + buffer_offset, 0, 8 * MIN(size, 4), sbvalue[0]);
log_memory_access(next_read, sbvalue, size, true);

/* "Writes to sbcs while sbbusy is high result in undefined behavior.
Expand All @@ -3271,7 +3273,7 @@ static int read_memory_bus_v1(struct target *target, target_addr_t address,
/* Read the last word, after we disabled sbreadondata if necessary. */
if (!get_field(sbcs_read, DM_SBCS_SBERROR) &&
!get_field(sbcs_read, DM_SBCS_SBBUSYERROR)) {
if (read_memory_bus_word(target, address + (count - 1) * size, size,
if (read_memory_bus_word(target, address + (count - 1) * increment, size,
buffer + (count - 1) * size) != ERROR_OK)
return ERROR_FAIL;

Expand Down

0 comments on commit a8ffda6

Please sign in to comment.