From 16de5044d4626bda1914af9634fd64af16d5dfb5 Mon Sep 17 00:00:00 2001 From: Palmer Dabbelt Date: Mon, 1 May 2017 08:30:15 -0700 Subject: [PATCH 1/5] Fix an assertion when reading from 0 --- src/target/riscv/riscv-013.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 179c52338..cbe926e16 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -1318,7 +1318,7 @@ static int read_memory(struct target *target, uint32_t address, * the data was all copied. */ riscv_addr_t cur_addr = 0xbadbeef; riscv_addr_t fin_addr = address + (count * size); - riscv_addr_t prev_addr = 0; + riscv_addr_t prev_addr = address - size; LOG_DEBUG("writing until final address 0x%016lx", fin_addr); while (count > 1 && (cur_addr = riscv_read_debug_buffer_x(target, d_addr)) < fin_addr) { LOG_DEBUG("transferring burst starting at address 0x%016lx (previous burst was 0x%016lx)", cur_addr, prev_addr); From ad1cf13ef4259c76a7fa9f19b960490b826df17a Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Mon, 1 May 2017 08:35:10 -0700 Subject: [PATCH 2/5] Correct debugging print in read_memory --- src/target/riscv/riscv-013.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index cbe926e16..31259b255 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -1223,7 +1223,7 @@ static int read_memory(struct target *target, uint32_t address, { RISCV013_INFO(info); - LOG_DEBUG("writing %d words of %d bytes to 0x%08lx", count, size, (long)address); + LOG_DEBUG("reading %d words of %d bytes from 0x%08lx", count, size, (long)address); select_dmi(target); riscv_set_current_hartid(target, 0); From 84627503578d2611845d678a1db9b03d1d18f6b6 Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Mon, 1 May 2017 09:37:48 -0700 Subject: [PATCH 3/5] riscv-013: Correct sign extension of address on read_memory --- src/target/riscv/riscv-013.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 31259b255..584014dd0 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -1265,7 +1265,7 @@ static int read_memory(struct target *target, uint32_t address, * program execution mechanism. */ switch (riscv_xlen(target)) { case 64: - riscv_program_write_ram(&program, r_addr + 4, ((riscv_addr_t)(address - size)) >> 32); + riscv_program_write_ram(&program, r_addr + 4, (((riscv_addr_t)(address)) - size) >> 32); case 32: riscv_program_write_ram(&program, r_addr, (riscv_addr_t)(address - size)); break; @@ -1318,7 +1318,7 @@ static int read_memory(struct target *target, uint32_t address, * the data was all copied. */ riscv_addr_t cur_addr = 0xbadbeef; riscv_addr_t fin_addr = address + (count * size); - riscv_addr_t prev_addr = address - size; + riscv_addr_t prev_addr = ((riscv_addr_t) address) - size; LOG_DEBUG("writing until final address 0x%016lx", fin_addr); while (count > 1 && (cur_addr = riscv_read_debug_buffer_x(target, d_addr)) < fin_addr) { LOG_DEBUG("transferring burst starting at address 0x%016lx (previous burst was 0x%016lx)", cur_addr, prev_addr); From 458bb2069943f81d01febebe209b03804e56f129 Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Mon, 1 May 2017 09:39:59 -0700 Subject: [PATCH 4/5] riscv-013: Correct sign extension of address on read_memory for lower bits as well --- src/target/riscv/riscv-013.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 584014dd0..4a6bbdb49 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -1267,7 +1267,7 @@ static int read_memory(struct target *target, uint32_t address, case 64: riscv_program_write_ram(&program, r_addr + 4, (((riscv_addr_t)(address)) - size) >> 32); case 32: - riscv_program_write_ram(&program, r_addr, (riscv_addr_t)(address - size)); + riscv_program_write_ram(&program, r_addr, (riscv_addr_t)(address) - size); break; default: LOG_ERROR("unknown XLEN %d", riscv_xlen(target)); From 95a2eb157ab0f1569faf17ecb666b99532755136 Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Mon, 1 May 2017 09:42:11 -0700 Subject: [PATCH 5/5] riscv-013: more consistent parens --- src/target/riscv/riscv-013.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 4a6bbdb49..1d526df8b 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -1265,9 +1265,9 @@ static int read_memory(struct target *target, uint32_t address, * program execution mechanism. */ switch (riscv_xlen(target)) { case 64: - riscv_program_write_ram(&program, r_addr + 4, (((riscv_addr_t)(address)) - size) >> 32); + riscv_program_write_ram(&program, r_addr + 4, (((riscv_addr_t) address) - size) >> 32); case 32: - riscv_program_write_ram(&program, r_addr, (riscv_addr_t)(address) - size); + riscv_program_write_ram(&program, r_addr, ((riscv_addr_t) address) - size); break; default: LOG_ERROR("unknown XLEN %d", riscv_xlen(target));