aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDolu1990 <charles.papon.90@gmail.com>2022-11-01 17:51:33 +0100
committerGitHub <noreply@github.com>2022-11-01 09:51:33 -0700
commit70980e7f570b8c98653e4c0ac4b5a92f348ee8b1 (patch)
tree683adbd8045f15505a0f82c47bb4982bb39f6a9f
parentcdadb2040b88cc2d1067d71a4dd0b79cfcbb1d77 (diff)
downloadriscv-openocd-70980e7f570b8c98653e4c0ac4b5a92f348ee8b1.zip
riscv-openocd-70980e7f570b8c98653e4c0ac4b5a92f348ee8b1.tar.gz
riscv-openocd-70980e7f570b8c98653e4c0ac4b5a92f348ee8b1.tar.bz2
Fix dm->current_hartid corruption on hartsellen discovery (#754)
* target/riscv Fix dm->current_hartid corruption on hartsellen discovery Change-Id: Iec969df2675b608365eda2c3a83a4185752430f2 Signed-off-by: Charles Papon <charles.papon.90@gmail.com> * target/riscv Ensure HART_INDEX_DIRTY does not have side effects Change-Id: Ie89c94d97cd4f15c1be0327fddff75beea6ae027 Signed-off-by: Charles Papon <charles.papon.90@gmail.com> Signed-off-by: Charles Papon <charles.papon.90@gmail.com>
-rw-r--r--src/target/riscv/riscv-013.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c
index bcd694a..2477ab7 100644
--- a/src/target/riscv/riscv-013.c
+++ b/src/target/riscv/riscv-013.c
@@ -130,6 +130,7 @@ typedef enum {
} yes_no_maybe_t;
#define HART_INDEX_MULTIPLE -1
+#define HART_INDEX_UNKNOWN -2
typedef struct {
struct list_head list;
@@ -284,6 +285,8 @@ dm013_info_t *get_dm(struct target *target)
static uint32_t set_dmcontrol_hartsel(uint32_t initial, int hart_index)
{
+ assert(hart_index != HART_INDEX_UNKNOWN);
+
if (hart_index >= 0) {
initial = set_field(initial, DM_DMCONTROL_HASEL, DM_DMCONTROL_HASEL_SINGLE);
uint32_t index_lo = hart_index & ((1 << DM_DMCONTROL_HARTSELLO_LENGTH) - 1);
@@ -1599,9 +1602,14 @@ static int examine(struct target *target)
dmi_write(target, DM_DMCONTROL, DM_DMCONTROL_HARTSELLO |
DM_DMCONTROL_HARTSELHI | DM_DMCONTROL_DMACTIVE |
DM_DMCONTROL_HASEL);
+ dm->current_hartid = HART_INDEX_UNKNOWN;
uint32_t dmcontrol;
if (dmi_read(target, &dmcontrol, DM_DMCONTROL) != ERROR_OK)
return ERROR_FAIL;
+ /* Ensure the HART_INDEX_UNKNOWN is flushed out */
+ if (dm013_select_hart(target, 0) != ERROR_OK)
+ return ERROR_FAIL;
+
if (!get_field(dmcontrol, DM_DMCONTROL_DMACTIVE)) {
LOG_ERROR("Debug Module did not become active. dmcontrol=0x%x",
@@ -4139,7 +4147,7 @@ static int dm013_select_hart(struct target *target, int hart_index)
dmcontrol = set_dmcontrol_hartsel(dmcontrol, hart_index);
if (dmi_write(target, DM_DMCONTROL, dmcontrol) != ERROR_OK) {
/* Who knows what the state is? */
- dm->current_hartid = -2;
+ dm->current_hartid = HART_INDEX_UNKNOWN;
return ERROR_FAIL;
}
dm->current_hartid = hart_index;