diff mbox series

[4/8] target/riscv: add helper to get CSR name

Message ID 20250217081730.9000-5-yongxuan.wang@sifive.com (mailing list archive)
State New
Headers show
Series riscv: AIA: kernel-irqchip=off support | expand

Commit Message

Yong-Xuan Wang Feb. 17, 2025, 8:17 a.m. UTC
Add a helper function to get CSR name from CSR number.

Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
---
 target/riscv/cpu.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Andrew Jones Feb. 17, 2025, 2:01 p.m. UTC | #1
On Mon, Feb 17, 2025 at 04:17:24PM +0800, Yong-Xuan Wang wrote:
> Add a helper function to get CSR name from CSR number.
> 
> Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
> ---
>  target/riscv/cpu.h | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
> index 616c3bdc1c24..133d1852ee1e 100644
> --- a/target/riscv/cpu.h
> +++ b/target/riscv/cpu.h
> @@ -920,8 +920,12 @@ extern const bool valid_vm_1_10_32[], valid_vm_1_10_64[];
>  void riscv_get_csr_ops(int csrno, riscv_csr_operations *ops);
>  void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops);
>  
> -void riscv_cpu_register_gdb_regs_for_features(CPUState *cs);
> +static inline const char *riscv_get_csr_name(int csr_no)
> +{
> +    return csr_ops[csr_no & (CSR_TABLE_SIZE - 1)].name;

Shouldn't we assert csr_no is correct rather than silently
truncate it?

Thanks,
drew

> +}
>  
> +void riscv_cpu_register_gdb_regs_for_features(CPUState *cs);
>  target_ulong riscv_new_csr_seed(target_ulong new_value,
>                                  target_ulong write_mask);
>  
> -- 
> 2.17.1
> 
>
Yong-Xuan Wang Feb. 24, 2025, 7:56 a.m. UTC | #2
Hi Andrew,

On Mon, Feb 17, 2025 at 10:01 PM Andrew Jones <ajones@ventanamicro.com> wrote:
>
> On Mon, Feb 17, 2025 at 04:17:24PM +0800, Yong-Xuan Wang wrote:
> > Add a helper function to get CSR name from CSR number.
> >
> > Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
> > ---
> >  target/riscv/cpu.h | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
> > index 616c3bdc1c24..133d1852ee1e 100644
> > --- a/target/riscv/cpu.h
> > +++ b/target/riscv/cpu.h
> > @@ -920,8 +920,12 @@ extern const bool valid_vm_1_10_32[], valid_vm_1_10_64[];
> >  void riscv_get_csr_ops(int csrno, riscv_csr_operations *ops);
> >  void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops);
> >
> > -void riscv_cpu_register_gdb_regs_for_features(CPUState *cs);
> > +static inline const char *riscv_get_csr_name(int csr_no)
> > +{
> > +    return csr_ops[csr_no & (CSR_TABLE_SIZE - 1)].name;
>
> Shouldn't we assert csr_no is correct rather than silently
> truncate it?

ok. I would add some assertions in this function.

Regards,
Yong-Xuan

>
> Thanks,
> drew
>
> > +}
> >
> > +void riscv_cpu_register_gdb_regs_for_features(CPUState *cs);
> >  target_ulong riscv_new_csr_seed(target_ulong new_value,
> >                                  target_ulong write_mask);
> >
> > --
> > 2.17.1
> >
> >
diff mbox series

Patch

diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index 616c3bdc1c24..133d1852ee1e 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -920,8 +920,12 @@  extern const bool valid_vm_1_10_32[], valid_vm_1_10_64[];
 void riscv_get_csr_ops(int csrno, riscv_csr_operations *ops);
 void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops);
 
-void riscv_cpu_register_gdb_regs_for_features(CPUState *cs);
+static inline const char *riscv_get_csr_name(int csr_no)
+{
+    return csr_ops[csr_no & (CSR_TABLE_SIZE - 1)].name;
+}
 
+void riscv_cpu_register_gdb_regs_for_features(CPUState *cs);
 target_ulong riscv_new_csr_seed(target_ulong new_value,
                                 target_ulong write_mask);