aboutsummaryrefslogtreecommitdiff
path: root/src/target
diff options
context:
space:
mode:
authorMarek Vrbka <marek.vrbka@codasip.com>2023-08-25 15:29:19 +0200
committerMarek Vrbka <marek.vrbka@codasip.com>2023-09-04 07:47:03 +0200
commit8ad41767c085975468d4fa638e4e0eb1b9abddbb (patch)
tree5b74080ab99e90593b22e6a434d3ec129c272190 /src/target
parent699eecaab434337dc3915171606b0548c48c6d51 (diff)
downloadriscv-openocd-8ad41767c085975468d4fa638e4e0eb1b9abddbb.zip
riscv-openocd-8ad41767c085975468d4fa638e4e0eb1b9abddbb.tar.gz
riscv-openocd-8ad41767c085975468d4fa638e4e0eb1b9abddbb.tar.bz2
target/riscv: Reject size 2 soft breakpoints when C extension not supported
This patch disables software breakpoints of size 2 for targets which don't support compressed instructions. Change-Id: I8200b22a51c97ba2aa89e6328beadde8dd35cdd5 Signed-off-by: Marek Vrbka <marek.vrbka@codasip.com>
Diffstat (limited to 'src/target')
-rw-r--r--src/target/riscv/riscv.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c
index e453742..c0742c7 100644
--- a/src/target/riscv/riscv.c
+++ b/src/target/riscv/riscv.c
@@ -1198,15 +1198,17 @@ static int riscv_add_breakpoint(struct target *target, struct breakpoint *breakp
LOG_TARGET_DEBUG(target, "@0x%" TARGET_PRIxADDR, breakpoint->address);
assert(breakpoint);
if (breakpoint->type == BKPT_SOFT) {
- /** @todo check RVC for size/alignment */
- if (!(breakpoint->length == 4 || breakpoint->length == 2)) {
- LOG_TARGET_ERROR(target, "Invalid breakpoint length %d", breakpoint->length);
+ const bool c_extension_supported = riscv_supports_extension(target, 'C');
+ if (!(breakpoint->length == 4 || (breakpoint->length == 2 && c_extension_supported))) {
+ LOG_TARGET_ERROR(target, "Invalid breakpoint length %d, supported lengths: %s", breakpoint->length,
+ c_extension_supported ? "2, 4" : "4");
return ERROR_FAIL;
}
- if (0 != (breakpoint->address % 2)) {
- LOG_TARGET_ERROR(target, "Invalid breakpoint alignment for address 0x%" TARGET_PRIxADDR,
- breakpoint->address);
+ const unsigned int required_align = c_extension_supported ? 2 : 4;
+ if ((breakpoint->address % required_align) != 0) {
+ LOG_TARGET_ERROR(target, "Invalid breakpoint alignment for address 0x%" TARGET_PRIxADDR
+ ", required alignment: %u", breakpoint->address, required_align);
return ERROR_FAIL;
}