From 56ad0e5b300c9f2c68637922972e12e6ff2d06dd Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Mon, 11 Dec 2017 15:32:01 -0800 Subject: [PATCH] Avoid another assertion failure. Change-Id: Ia54f778152974164697b712c360918e17a127d95 --- src/target/riscv/riscv-013.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 6083ba8f5..98a63522f 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -1193,11 +1193,15 @@ static int examine(struct target *target) RISCV_INFO(r); r->impebreak = get_field(dmstatus, DMI_DMSTATUS_IMPEBREAK); + // Don't call any riscv_* functions until after we've counted the number of + // cores and initialized registers. for (int i = 0; i < RISCV_MAX_HARTS; ++i) { if (!riscv_rtos_enabled(target) && i != target->coreid) continue; - riscv_set_current_hartid(target, i); + r->current_hartid = i; + riscv013_select_current_hart(target); + uint32_t s = dmi_read(target, DMI_DMSTATUS); if (get_field(s, DMI_DMSTATUS_ANYNONEXISTENT)) { break;