Skip to content

Commit 9d431c3

Browse files
authored
Merge pull request #1207 from en-sc/en-sc/fix-011-init-regs
target/riscv: set VLENB/MTOPI/MTOPEI existence on 0.11 targets
2 parents 495f144 + 8513d6e commit 9d431c3

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

src/target/riscv/riscv-011_reg.c

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,50 @@ static const struct reg_arch_type *riscv011_gdb_regno_reg_type(uint32_t regno)
3636
return &riscv011_reg_type;
3737
}
3838

39-
static int riscv011_init_reg(struct target *target, uint32_t regno)
40-
{
41-
return riscv_reg_impl_init_cache_entry(target, regno,
42-
riscv_reg_impl_gdb_regno_exist(target, regno),
43-
riscv011_gdb_regno_reg_type(regno));
44-
}
4539

4640
int riscv011_reg_init_all(struct target *target)
4741
{
48-
if (riscv_reg_impl_init_cache(target) != ERROR_OK)
49-
return ERROR_FAIL;
42+
int res = riscv_reg_impl_init_cache(target);
43+
if (res != ERROR_OK)
44+
return res;
5045

5146
init_shared_reg_info(target);
5247

53-
for (uint32_t regno = 0; regno < target->reg_cache->num_regs; ++regno)
54-
if (riscv011_init_reg(target, regno) != ERROR_OK)
55-
return ERROR_FAIL;
48+
RISCV_INFO(r);
49+
assert(!r->vlenb
50+
&& "VLENB discovery is not supported on RISC-V 0.11 targets");
51+
assert(!r->mtopi_readable
52+
&& "MTOPI discovery is not supported on RISC-V 0.11 targets");
53+
assert(!r->mtopei_readable
54+
&& "MTOPEI discovery is not supported on RISC-V 0.11 targets");
55+
/* Existence of some registers depends on others.
56+
* E.g. the presence of "v0-31" registers is infered from "vlenb" being
57+
* non-zero.
58+
* Currently, discovery of the following registers is not supported on
59+
* RISC-V 0.11 targets. */
60+
uint32_t non_discoverable_regs[] = {
61+
GDB_REGNO_VLENB,
62+
GDB_REGNO_MTOPI,
63+
GDB_REGNO_MTOPEI
64+
};
65+
for (unsigned int i = 0; i < ARRAY_SIZE(non_discoverable_regs); ++i) {
66+
const uint32_t regno = non_discoverable_regs[i];
67+
res = riscv_reg_impl_init_cache_entry(target, regno,
68+
/*exist*/ false, riscv011_gdb_regno_reg_type(regno));
69+
if (res != ERROR_OK)
70+
return res;
71+
}
72+
73+
for (uint32_t regno = 0; regno < target->reg_cache->num_regs; ++regno) {
74+
const struct reg * const reg = riscv_reg_impl_cache_entry(target, regno);
75+
if (riscv_reg_impl_is_initialized(reg))
76+
continue;
77+
res = riscv_reg_impl_init_cache_entry(target, regno,
78+
riscv_reg_impl_gdb_regno_exist(target, regno),
79+
riscv011_gdb_regno_reg_type(regno));
80+
if (res != ERROR_OK)
81+
return res;
82+
}
5683

5784
if (riscv_reg_impl_expose_csrs(target) != ERROR_OK)
5885
return ERROR_FAIL;

0 commit comments

Comments
 (0)