Skip to content

Commit 22bbdd2

Browse files
authored
Merge pull request riscv-collab#1109 from aap-sc/aap-sc/sbus_fixup
target/riscv: sys bus v1 fix for sizes greater than 4
2 parents 8ea44aa + ebb8c05 commit 22bbdd2

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/target/riscv/riscv-013.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "target/target.h"
1717
#include "target/algorithm.h"
1818
#include "target/target_type.h"
19+
#include <helper/align.h>
1920
#include <helper/log.h>
2021
#include "jtag/jtag.h"
2122
#include "target/register.h"
@@ -3253,6 +3254,9 @@ static int read_memory_bus_v1(struct target *target, target_addr_t address,
32533254
return ERROR_NOT_IMPLEMENTED;
32543255
}
32553256

3257+
assert(size <= 16);
3258+
assert(IS_PWR_OF_2(size));
3259+
32563260
dm013_info_t *dm = get_dm(target);
32573261
if (!dm)
32583262
return ERROR_FAIL;
@@ -3288,7 +3292,6 @@ static int read_memory_bus_v1(struct target *target, target_addr_t address,
32883292
* be unnecessary.
32893293
*/
32903294
uint32_t sbvalue[4] = {0};
3291-
assert(size <= 16);
32923295
for (uint32_t i = (next_address - address) / size; i < count - 1; i++) {
32933296
const uint32_t size_in_words = DIV_ROUND_UP(size, 4);
32943297
struct riscv_batch *batch = riscv_batch_alloc(target, size_in_words);
@@ -3309,10 +3312,10 @@ static int read_memory_bus_v1(struct target *target, target_addr_t address,
33093312

33103313
const size_t last_key = batch->read_keys_used - 1;
33113314
for (size_t k = 0; k <= last_key; ++k) {
3312-
sbvalue[k] = riscv_batch_get_dmi_read_data(batch,
3313-
last_key - k);
3314-
buf_set_u32(buffer + i * size + k * 4, 0, 8 * size, sbvalue[k]);
3315+
sbvalue[k] = riscv_batch_get_dmi_read_data(batch, last_key - k);
3316+
buf_set_u32(buffer + i * size + k * 4, 0, MIN(32, 8 * size), sbvalue[k]);
33153317
}
3318+
33163319
riscv_batch_free(batch);
33173320
const target_addr_t read_addr = address + i * increment;
33183321
log_memory_access(read_addr, sbvalue, size, true);

0 commit comments

Comments
 (0)