Skip to content

Commit a277416

Browse files
Refactor examine, to avoid some assertions
Now that we're supporting non-RTOS multi-hart mode there's some more assertions that you're running on the right hart. Those assertions aren't sane very early in examine, so I avoid them.
1 parent 788908f commit a277416

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/target/riscv/riscv-013.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,17 +1123,23 @@ static int examine(struct target *target)
11231123

11241124
/* Before doing anything else we must first enumerate the harts. */
11251125
RISCV_INFO(r);
1126-
if (riscv_rtos_enabled(target)) {
1127-
for (int i = 0; i < RISCV_MAX_HARTS; ++i) {
1128-
riscv_set_current_hartid(target, i);
1129-
uint32_t s = dmi_read(target, DMI_DMSTATUS);
1130-
if (get_field(s, DMI_DMSTATUS_ANYNONEXISTENT))
1131-
break;
1132-
r->hart_count = i + 1;
1126+
int original_coreid = target->coreid;
1127+
for (int i = 0; i < RISCV_MAX_HARTS; ++i) {
1128+
/* Fake being a non-RTOS targeted to this core so we can see if
1129+
* it exists. This avoids the assertion in
1130+
* riscv_set_current_hartid() that ensures non-RTOS targets
1131+
* don't touch the harts they're not assigned to. */
1132+
target->coreid = i;
1133+
r->hart_count = i + 1;
1134+
riscv_set_current_hartid(target, i);
1135+
1136+
uint32_t s = dmi_read(target, DMI_DMSTATUS);
1137+
if (get_field(s, DMI_DMSTATUS_ANYNONEXISTENT)) {
1138+
r->hart_count--;
1139+
break;
11331140
}
1134-
} else {
1135-
r->hart_count = 1;
11361141
}
1142+
target->coreid = original_coreid;
11371143

11381144
LOG_DEBUG("Enumerated %d harts", r->hart_count);
11391145

@@ -1233,6 +1239,7 @@ static int examine(struct target *target)
12331239

12341240
/* Resumes all the harts, so the debugger can later pause them. */
12351241
riscv_resume_all_harts(target);
1242+
target->state = TARGET_RUNNING;
12361243
target_set_examined(target);
12371244

12381245
if (target->rtos) {

0 commit comments

Comments
 (0)