Skip to content

Commit e1fe15f

Browse files
authored
Merge pull request #1209 from en-sc/en-sc/riscv-info-mtopx
target/riscv: drop `mtopi_readable/mtopei_readable` `riscv_info` fields
2 parents dd72250 + 06e673e commit e1fe15f

File tree

4 files changed

+24
-47
lines changed

4 files changed

+24
-47
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ int riscv011_reg_init_all(struct target *target)
4848
RISCV_INFO(r);
4949
assert(!r->vlenb
5050
&& "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");
5551
/* Existence of some registers depends on others.
5652
* E.g. the presence of "v0-31" registers is infered from "vlenb" being
5753
* non-zero.

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,7 @@ static int examine_misa(struct target *target)
266266

267267
static int examine_mtopi(struct target *target)
268268
{
269-
RISCV_INFO(r);
270-
271269
/* Assume the registers exist */
272-
r->mtopi_readable = true;
273-
r->mtopei_readable = true;
274-
275270
int res = assume_reg_exist(target, GDB_REGNO_MTOPI);
276271
if (res != ERROR_OK)
277272
return res;
@@ -281,19 +276,17 @@ static int examine_mtopi(struct target *target)
281276

282277
riscv_reg_t value;
283278
if (riscv_reg_get(target, &value, GDB_REGNO_MTOPI) != ERROR_OK) {
284-
r->mtopi_readable = false;
285-
r->mtopei_readable = false;
286-
} else if (riscv_reg_get(target, &value, GDB_REGNO_MTOPEI) != ERROR_OK) {
279+
res = riscv_reg_impl_set_exist(target, GDB_REGNO_MTOPI, false);
280+
if (res != ERROR_OK)
281+
return res;
282+
return riscv_reg_impl_set_exist(target, GDB_REGNO_MTOPEI, false);
283+
}
284+
if (riscv_reg_get(target, &value, GDB_REGNO_MTOPEI) != ERROR_OK) {
287285
LOG_TARGET_INFO(target, "S?aia detected without IMSIC");
288-
r->mtopei_readable = false;
289-
} else {
290-
LOG_TARGET_INFO(target, "S?aia detected with IMSIC");
286+
return riscv_reg_impl_set_exist(target, GDB_REGNO_MTOPEI, false);
291287
}
292-
res = riscv_reg_impl_set_exist(target, GDB_REGNO_MTOPI, r->mtopi_readable);
293-
if (res != ERROR_OK)
294-
return res;
295-
296-
return riscv_reg_impl_set_exist(target, GDB_REGNO_MTOPEI, r->mtopei_readable);
288+
LOG_TARGET_INFO(target, "S?aia detected with IMSIC");
289+
return ERROR_OK;
297290
}
298291

299292
/**

src/target/riscv/riscv.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,14 @@ struct riscv_info {
178178

179179
/* It's possible that each core has a different supported ISA set. */
180180
int xlen;
181+
/* TODO: use the value from the register cache instead. */
181182
riscv_reg_t misa;
182-
/* Cached value of vlenb. 0 indicates there is no vector support.
183+
/* TODO: use the value from the register cache instead.
184+
* Cached value of vlenb. 0 indicates there is no vector support.
183185
* Note that you can have vector support without misa.V set, because
184186
* Zve* extensions implement vector registers without setting misa.V. */
185187
unsigned int vlenb;
186188

187-
bool mtopi_readable;
188-
bool mtopei_readable;
189-
190189
/* The number of triggers per hart. */
191190
unsigned int trigger_count;
192191

src/target/riscv/riscv_reg.c

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -346,22 +346,11 @@ static bool vlenb_exists(const struct target *target)
346346
return riscv_vlenb(target) != 0;
347347
}
348348

349-
static bool mtopi_exists(const struct target *target)
349+
static bool reg_exists(const struct target *target, uint32_t regno)
350350
{
351-
RISCV_INFO(info)
352-
/* TODO: The naming is quite unfortunate here. `mtopi_readable` refers
353-
* to how the fact that `mtopi` exists was deduced during examine.
354-
*/
355-
return info->mtopi_readable;
356-
}
357-
358-
static bool mtopei_exists(const struct target *target)
359-
{
360-
RISCV_INFO(info)
361-
/* TODO: The naming is quite unfortunate here. `mtopei_readable` refers
362-
* to how the fact that `mtopei` exists was deduced during examine.
363-
*/
364-
return info->mtopei_readable;
351+
const struct reg * const reg = riscv_reg_impl_cache_entry(target, regno);
352+
assert(riscv_reg_impl_is_initialized(reg));
353+
return reg->exist;
365354
}
366355

367356
static bool is_known_standard_csr(unsigned int csr_num)
@@ -508,25 +497,25 @@ bool riscv_reg_impl_gdb_regno_exist(const struct target *target, uint32_t regno)
508497
case CSR_MVIP:
509498
case CSR_MIEH:
510499
case CSR_MIPH:
511-
return mtopi_exists(target);
500+
return reg_exists(target, GDB_REGNO_MTOPI);
512501
case CSR_MIDELEGH:
513502
case CSR_MVIENH:
514503
case CSR_MVIPH:
515-
return mtopi_exists(target) &&
504+
return reg_exists(target, GDB_REGNO_MTOPI) &&
516505
riscv_xlen(target) == 32 &&
517506
riscv_supports_extension(target, 'S');
518507
/* Interrupts S-Mode CSRs. */
519508
case CSR_SISELECT:
520509
case CSR_SIREG:
521510
case CSR_STOPI:
522-
return mtopi_exists(target) &&
511+
return reg_exists(target, GDB_REGNO_MTOPI) &&
523512
riscv_supports_extension(target, 'S');
524513
case CSR_STOPEI:
525-
return mtopei_exists(target) &&
514+
return reg_exists(target, GDB_REGNO_MTOPEI) &&
526515
riscv_supports_extension(target, 'S');
527516
case CSR_SIEH:
528517
case CSR_SIPH:
529-
return mtopi_exists(target) &&
518+
return reg_exists(target, GDB_REGNO_MTOPI) &&
530519
riscv_xlen(target) == 32 &&
531520
riscv_supports_extension(target, 'S');
532521
/* Interrupts Hypervisor and VS CSRs. */
@@ -537,10 +526,10 @@ bool riscv_reg_impl_gdb_regno_exist(const struct target *target, uint32_t regno)
537526
case CSR_VSISELECT:
538527
case CSR_VSIREG:
539528
case CSR_VSTOPI:
540-
return mtopi_exists(target) &&
529+
return reg_exists(target, GDB_REGNO_MTOPI) &&
541530
riscv_supports_extension(target, 'H');
542531
case CSR_VSTOPEI:
543-
return mtopei_exists(target) &&
532+
return reg_exists(target, GDB_REGNO_MTOPEI) &&
544533
riscv_supports_extension(target, 'H');
545534
case CSR_HIDELEGH:
546535
case CSR_HVIENH:
@@ -549,7 +538,7 @@ bool riscv_reg_impl_gdb_regno_exist(const struct target *target, uint32_t regno)
549538
case CSR_HVIPRIO2H:
550539
case CSR_VSIEH:
551540
case CSR_VSIPH:
552-
return mtopi_exists(target) &&
541+
return reg_exists(target, GDB_REGNO_MTOPI) &&
553542
riscv_xlen(target) == 32 &&
554543
riscv_supports_extension(target, 'H');
555544
}

0 commit comments

Comments
 (0)