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>
This commit is contained in:
Dolu1990 2022-11-01 17:51:33 +01:00 committed by GitHub
parent cdadb2040b
commit 70980e7f57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -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;