From 9f4cac5a3812be137913995e2d1d4be4b34e0744 Mon Sep 17 00:00:00 2001 From: Palmer Dabbelt Date: Tue, 20 Jun 2017 17:12:53 -0700 Subject: [PATCH] Set current_hartid from coreid This avoids a bunch of RTOS special cases. --- src/target/riscv/riscv-013.c | 2 +- src/target/riscv/riscv.c | 8 +++----- src/target/riscv/riscv.h | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 60846debe..2fab9a1ff 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -706,7 +706,7 @@ static int init_target(struct command_context *cmd_ctx, LOG_DEBUG("init"); riscv_info_t *generic_info = (riscv_info_t *) target->arch_info; - riscv_info_init(generic_info); + riscv_info_init(target, generic_info); generic_info->get_register = &riscv013_get_register; generic_info->set_register = &riscv013_set_register; generic_info->select_current_hart = &riscv013_select_current_hart; diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index 7a40467f1..ad5eddbef 100644 --- a/src/target/riscv/riscv.c +++ b/src/target/riscv/riscv.c @@ -872,11 +872,12 @@ struct target_type riscv_target = /*** RISC-V Interface ***/ -void riscv_info_init(riscv_info_t *r) +void riscv_info_init(struct target *target, riscv_info_t *r) { memset(r, 0, sizeof(*r)); r->dtm_version = 1; r->registers_initialized = false; + r->current_hartid = target->coreid; for (size_t h = 0; h < RISCV_MAX_HARTS; ++h) { r->xlen[h] = -1; @@ -1068,10 +1069,7 @@ void riscv_invalidate_register_cache(struct target *target) int riscv_current_hartid(const struct target *target) { RISCV_INFO(r); - if (riscv_rtos_enabled(target)) - return r->current_hartid; - else - return target->coreid; + return r->current_hartid; } void riscv_set_all_rtos_harts(struct target *target) diff --git a/src/target/riscv/riscv.h b/src/target/riscv/riscv.h index e23d49d1f..53fb08673 100644 --- a/src/target/riscv/riscv.h +++ b/src/target/riscv/riscv.h @@ -134,7 +134,7 @@ int riscv_openocd_deassert_reset(struct target *target); /*** RISC-V Interface ***/ /* Initializes the shared RISC-V structure. */ -void riscv_info_init(riscv_info_t *r); +void riscv_info_init(struct target *target, riscv_info_t *r); /* Run control, possibly for multiple harts. The _all_harts versions resume * all the enabled harts, which when running in RTOS mode is all the harts on