Skip to content

Commit ebb8c05

Browse files
committed
target/riscv: sys bus v1 fix for sizes greater than 4
read_memory_bus_v1 incorrectly copied data to output buffer Signed-off-by: Parshintsev Anatoly <[email protected]>
1 parent 5afed58 commit ebb8c05

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"
@@ -3349,6 +3350,9 @@ static int read_memory_bus_v1(struct target *target, target_addr_t address,
33493350
return ERROR_NOT_IMPLEMENTED;
33503351
}
33513352

3353+
assert(size <= 16);
3354+
assert(IS_PWR_OF_2(size));
3355+
33523356
dm013_info_t *dm = get_dm(target);
33533357
if (!dm)
33543358
return ERROR_FAIL;
@@ -3384,7 +3388,6 @@ static int read_memory_bus_v1(struct target *target, target_addr_t address,
33843388
* be unnecessary.
33853389
*/
33863390
uint32_t sbvalue[4] = {0};
3387-
assert(size <= 16);
33883391
for (uint32_t i = (next_address - address) / size; i < count - 1; i++) {
33893392
const uint32_t size_in_words = DIV_ROUND_UP(size, 4);
33903393
struct riscv_batch *batch = riscv_batch_alloc(target, size_in_words);
@@ -3405,10 +3408,10 @@ static int read_memory_bus_v1(struct target *target, target_addr_t address,
34053408

34063409
const size_t last_key = batch->read_keys_used - 1;
34073410
for (size_t k = 0; k <= last_key; ++k) {
3408-
sbvalue[k] = riscv_batch_get_dmi_read_data(batch,
3409-
last_key - k);
3410-
buf_set_u32(buffer + i * size + k * 4, 0, 8 * size, sbvalue[k]);
3411+
sbvalue[k] = riscv_batch_get_dmi_read_data(batch, last_key - k);
3412+
buf_set_u32(buffer + i * size + k * 4, 0, MIN(32, 8 * size), sbvalue[k]);
34113413
}
3414+
34123415
riscv_batch_free(batch);
34133416
const target_addr_t read_addr = address + i * increment;
34143417
log_memory_access(read_addr, sbvalue, size, true);

0 commit comments

Comments
 (0)