From dc9f9be528ae4ff11d31d785132e496074154d13 Mon Sep 17 00:00:00 2001 From: Parshintsev Anatoly Date: Thu, 30 Jan 2025 20:22:03 +0300 Subject: [PATCH] fix expose_csr for CSR from lower address space csrs with custom names are expected to be lazy-initialized by init_custom_csr_names. However, if the exposed CSR was in lower address space the custom name could be re-written by the default one. --- src/target/riscv/riscv_reg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/target/riscv/riscv_reg.c b/src/target/riscv/riscv_reg.c index 29d8a2b65..2858c4c56 100644 --- a/src/target/riscv/riscv_reg.c +++ b/src/target/riscv/riscv_reg.c @@ -56,7 +56,6 @@ static const char * const default_reg_names[GDB_REGNO_COUNT] = { [GDB_REGNO_T5] = "t5", [GDB_REGNO_T6] = "t6", [GDB_REGNO_PC] = "pc", - [GDB_REGNO_CSR0] = "csr0", [GDB_REGNO_PRIV] = "priv", [GDB_REGNO_FT0] = "ft0", [GDB_REGNO_FT1] = "ft1", @@ -196,7 +195,8 @@ const char *riscv_reg_gdb_regno_name(const struct target *target, enum gdb_regno } if (regno >= GDB_REGNO_CSR0 && regno <= GDB_REGNO_CSR4095) { init_custom_csr_names(target); - info->reg_names[regno] = init_reg_name_with_prefix("csr", regno - GDB_REGNO_CSR0); + if (!info->reg_names[regno]) + info->reg_names[regno] = init_reg_name_with_prefix("csr", regno - GDB_REGNO_CSR0); return info->reg_names[regno]; } assert(!"Encountered uninitialized entry in reg_names table");