Skip to content

Commit 5a39519

Browse files
committed
target/riscv: check nextdm address in abits range
When abits not correctly configured, we hope to detect it as soon as possible.
1 parent fc0b7e3 commit 5a39519

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/target/riscv/riscv-013.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ static bool check_dbgbase_exists(struct target *target)
538538
{
539539
uint32_t next_dm = 0;
540540
unsigned int count = 1;
541+
riscv013_info_t *info = get_info(target);
541542

542543
LOG_TARGET_DEBUG(target, "Searching for DM with DMI base address (dbgbase) = 0x%x", target->dbgbase);
543544
while (1) {
@@ -552,6 +553,12 @@ static bool check_dbgbase_exists(struct target *target)
552553
LOG_TARGET_ERROR(target, "Reached the end of DM chain (detected %u DMs in total).", count);
553554
break;
554555
}
556+
if (next_dm >> info->abits) {
557+
LOG_TARGET_ERROR(target, "The address of the next Debug Module does not fit into %u bits, "
558+
"which is the width of the DMI bus address. This is a HW bug",
559+
info->abits);
560+
break;
561+
}
555562
/* Safety: Avoid looping forever in case of buggy nextdm values in the hardware. */
556563
if (count++ > RISCV_MAX_DMS) {
557564
LOG_TARGET_ERROR(target, "Supporting no more than %d DMs on a DMI bus. Aborting", RISCV_MAX_DMS);

0 commit comments

Comments
 (0)