aboutsummaryrefslogtreecommitdiff
path: root/src/target/target.c
diff options
context:
space:
mode:
authorTim Newsome <tim@sifive.com>2021-05-13 16:38:51 -0700
committerAntonio Borneo <borneo.antonio@gmail.com>2021-06-04 17:45:58 +0100
commit358ab3483d2cad0c869585f8a340154690f56569 (patch)
tree8b9f5557e5a45a10faf90bad40ac7d34285de6b7 /src/target/target.c
parent6ae38ef7f7ff6fd51d4536ddf60d905ed6ac158e (diff)
downloadriscv-openocd-358ab3483d2cad0c869585f8a340154690f56569.zip
riscv-openocd-358ab3483d2cad0c869585f8a340154690f56569.tar.gz
riscv-openocd-358ab3483d2cad0c869585f8a340154690f56569.tar.bz2
Add target_data_bits().
This is used to compute memory block read alignment, and specifically allows 64-bit targets to ensure that memory block reads are only requested on 64-bit boundaries. Signed-off-by: Tim Newsome <tim@sifive.com> Change-Id: Idb1a27b9fc02c46245556bb0f3d6d94b368c4817 Reviewed-on: http://openocd.zylin.com/6249 Reviewed-by: Marc Schink <dev@zapb.de> Tested-by: jenkins Reviewed-by: Jan Matyas <matyas@codasip.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Diffstat (limited to 'src/target/target.c')
-rw-r--r--src/target/target.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/target/target.c b/src/target/target.c
index 39a07ad..63f68eb 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -1506,6 +1506,13 @@ unsigned target_address_bits(struct target *target)
return 32;
}
+unsigned int target_data_bits(struct target *target)
+{
+ if (target->type->data_bits)
+ return target->type->data_bits(target);
+ return 32;
+}
+
static int target_profiling(struct target *target, uint32_t *samples,
uint32_t max_num_samples, uint32_t *num_samples, uint32_t seconds)
{
@@ -2402,10 +2409,13 @@ static int target_write_buffer_default(struct target *target,
target_addr_t address, uint32_t count, const uint8_t *buffer)
{
uint32_t size;
+ unsigned int data_bytes = target_data_bits(target) / 8;
- /* Align up to maximum 4 bytes. The loop condition makes sure the next pass
+ /* Align up to maximum bytes. The loop condition makes sure the next pass
* will have something to do with the size we leave to it. */
- for (size = 1; size < 4 && count >= size * 2 + (address & size); size *= 2) {
+ for (size = 1;
+ size < data_bytes && count >= size * 2 + (address & size);
+ size *= 2) {
if (address & size) {
int retval = target_write_memory(target, address, size, 1, buffer);
if (retval != ERROR_OK)
@@ -2463,10 +2473,13 @@ int target_read_buffer(struct target *target, target_addr_t address, uint32_t si
static int target_read_buffer_default(struct target *target, target_addr_t address, uint32_t count, uint8_t *buffer)
{
uint32_t size;
+ unsigned int data_bytes = target_data_bits(target) / 8;
- /* Align up to maximum 4 bytes. The loop condition makes sure the next pass
+ /* Align up to maximum bytes. The loop condition makes sure the next pass
* will have something to do with the size we leave to it. */
- for (size = 1; size < 4 && count >= size * 2 + (address & size); size *= 2) {
+ for (size = 1;
+ size < data_bytes && count >= size * 2 + (address & size);
+ size *= 2) {
if (address & size) {
int retval = target_read_memory(target, address, size, 1, buffer);
if (retval != ERROR_OK)