Skip to content

Commit ea8f9d5

Browse files
authored
Merge pull request #1173 from fk-sc/buf-get
target/riscv: use buf_get_uXX instead of manual bit shift
2 parents c430c24 + 4dcd801 commit ea8f9d5

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

src/target/riscv/riscv-013.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,14 +1209,8 @@ static int scratch_read64(struct target *target, scratch_mem_t *scratch,
12091209
};
12101210
if (read_memory(target, args) != ERROR_OK)
12111211
return ERROR_FAIL;
1212-
*value = buffer[0] |
1213-
(((uint64_t) buffer[1]) << 8) |
1214-
(((uint64_t) buffer[2]) << 16) |
1215-
(((uint64_t) buffer[3]) << 24) |
1216-
(((uint64_t) buffer[4]) << 32) |
1217-
(((uint64_t) buffer[5]) << 40) |
1218-
(((uint64_t) buffer[6]) << 48) |
1219-
(((uint64_t) buffer[7]) << 56);
1212+
*value = buf_get_u64(buffer,
1213+
/* first = */ 0, /* bit_num = */ 64);
12201214
}
12211215
break;
12221216
}
@@ -4536,27 +4530,21 @@ static int write_memory_bus_v1(struct target *target, const riscv_mem_access_arg
45364530

45374531
uint32_t sbvalue[4] = { 0 };
45384532
if (args.size > 12) {
4539-
sbvalue[3] = ((uint32_t)p[12]) |
4540-
(((uint32_t)p[13]) << 8) |
4541-
(((uint32_t)p[14]) << 16) |
4542-
(((uint32_t)p[15]) << 24);
4533+
sbvalue[3] = buf_get_u32(&p[12],
4534+
/* first = */ 0, /* bit_num = */ 32);
45434535
riscv_batch_add_dm_write(batch, DM_SBDATA3, sbvalue[3], false,
45444536
RISCV_DELAY_BASE);
45454537
}
45464538

45474539
if (args.size > 8) {
4548-
sbvalue[2] = ((uint32_t)p[8]) |
4549-
(((uint32_t)p[9]) << 8) |
4550-
(((uint32_t)p[10]) << 16) |
4551-
(((uint32_t)p[11]) << 24);
4540+
sbvalue[2] = buf_get_u32(&p[8],
4541+
/* first = */ 0, /* bit_num = */ 32);
45524542
riscv_batch_add_dm_write(batch, DM_SBDATA2, sbvalue[2], false,
45534543
RISCV_DELAY_BASE);
45544544
}
45554545
if (args.size > 4) {
4556-
sbvalue[1] = ((uint32_t)p[4]) |
4557-
(((uint32_t)p[5]) << 8) |
4558-
(((uint32_t)p[6]) << 16) |
4559-
(((uint32_t)p[7]) << 24);
4546+
sbvalue[1] = buf_get_u32(&p[4],
4547+
/* first = */ 0, /* bit_num = */ 32);
45604548
riscv_batch_add_dm_write(batch, DM_SBDATA1, sbvalue[1], false,
45614549
RISCV_DELAY_BASE);
45624550
}

0 commit comments

Comments
 (0)