Skip to content

Commit 02e2dae

Browse files
committed
target/riscv: access registers via reg->type
* `int riscv_reg_get()` and `int riscv_reg_set()` are implemented in terms of `reg->type->get/set` instead of the other way around. This makes it easier to support custom behavior for some registers. * Cacheability is determined by `reg->type` instead of `riscv_reg_impl_gdb_regno_cacheable()`. * Issues with redirection of `priv` -> `dcsr` and `pc` -> `dpc` are addressed at the "topmost" level. - `priv` and `pc` are alvais invalid. - Fixed some issues, e.g. the first `pc` write printed-out an uninitialized value: ``` > reg pc 0 pc (/64): 0x000075da6b33db20 ``` Change-Id: I514547f455d62b289fb5dee62753bf5d9aa3b8ae Signed-off-by: Evgeniy Naydanov <[email protected]>
1 parent 380b9b2 commit 02e2dae

File tree

5 files changed

+471
-289
lines changed

5 files changed

+471
-289
lines changed

src/target/riscv/riscv-013.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5064,19 +5064,8 @@ struct target_type riscv013_target = {
50645064
int riscv013_get_register(struct target *target,
50655065
riscv_reg_t *value, enum gdb_regno rid)
50665066
{
5067-
/* It would be beneficial to move this redirection to the
5068-
* version-independent section, but there is a conflict:
5069-
* `dcsr[5]` is `dcsr.v` in current spec, but it is `dcsr.debugint` in 0.11.
5070-
*/
5071-
if (rid == GDB_REGNO_PRIV) {
5072-
uint64_t dcsr;
5073-
if (riscv_reg_get(target, &dcsr, GDB_REGNO_DCSR) != ERROR_OK)
5074-
return ERROR_FAIL;
5075-
*value = set_field(0, VIRT_PRIV_V, get_field(dcsr, CSR_DCSR_V));
5076-
*value = set_field(*value, VIRT_PRIV_PRV, get_field(dcsr, CSR_DCSR_PRV));
5077-
return ERROR_OK;
5078-
}
5079-
5067+
assert(rid != GDB_REGNO_PC && "'pc' should be read through 'dpc'" );
5068+
assert(rid != GDB_REGNO_PRIV && "'priv' should be read through 'dcsr'" );
50805069
LOG_TARGET_DEBUG(target, "reading register %s", riscv_reg_gdb_regno_name(target, rid));
50815070

50825071
if (dm013_select_target(target) != ERROR_OK)
@@ -5093,6 +5082,8 @@ int riscv013_get_register(struct target *target,
50935082
int riscv013_set_register(struct target *target, enum gdb_regno rid,
50945083
riscv_reg_t value)
50955084
{
5085+
assert(rid != GDB_REGNO_PC && "'pc' should be written through 'dpc'" );
5086+
assert(rid != GDB_REGNO_PRIV && "'priv' should be written through 'dcsr'" );
50965087
LOG_TARGET_DEBUG(target, "writing 0x%" PRIx64 " to register %s",
50975088
value, riscv_reg_gdb_regno_name(target, rid));
50985089

0 commit comments

Comments
 (0)