Proposing custom CSR handling logic
cover Proposing custom CSR handling logic
Hi all,
It seesm that Nuclei System Technology has sent out their platform support patches and there are concern regarding introducing intrusive non-standard code into QEMU base. Since we have been discussed with Nuclei couples of months ago, and thus we decide it's time for us to join the party.
As we discussed with Nuclei privately, we basically borrows the idea from Renode's own QEMU/TCG fork - - introducing extralogic on riscv_csrrw().
Just for the show start, we have been ported our custom instruction handling code and testing internally quite a while. Currently we can boot Linux with OpenSBI succcesfully, and we will upstrean the code as soon as possible.
Cordially yours,
Ruinland
Ruinland Chuan-Tzu Tsai (1):
Adding premliminary support for custom CSR handling mechanism
target/riscv/cpu.c | 28 ++++++++++ target/riscv/cpu.h | 12 ++++- target/riscv/cpu_bits.h | 115 ++++++++++++++++++++++++++++++++++++++++ target/riscv/csr.c | 107 +++++++++++++++++++++++++++++++++++-- 4 files changed, 256 insertions(+), 6 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/1 Adding premliminary support for custom CSR handling mechanism
Introduce ax25 and custom CSR handling mechanism to RISC-V platform. This is just a POC in which we add Andes custom CSR table directly into the generic code which is undresiable and requires overhaul.
--- target/riscv/cpu.c | 28 ++++++++++ target/riscv/cpu.h | 12 ++++- target/riscv/cpu_bits.h | 115 ++++++++++++++++++++++++++++++++++++++++ target/riscv/csr.c | 107 +++++++++++++++++++++++++++++++++++-- 4 files changed, 256 insertions(+), 6 deletions(-)
target/riscv/cpu.c +28 -0
@@ -34,6 +34,8 @@static const char riscv_exts[26 ] ="IEMAFDQCLBJTPVNSUHKORWXYZG" ; +GHashTable * custom_csr_map; +const char *const riscv_int_regnames[] = {"x0/zero" ,"x1/ra" ,"x2/sp" ,"x3/gp" ,"x4/tp" ,"x5/t0" ,"x6/t1" ,"x7/t2" ,"x8/s0" ,"x9/s1" ,"x10/a0" ,"x11/a1" ,"x12/a2" ,"x13/a3" ,
@@ -159,6 +161,31 @@ static void rv64_base_cpu_init(Object *obj)set_misa (env,RV64 ); } +static void ax25_cpu_init (Object *obj) +{ +CPURISCVState *env = &RISCV_CPU (obj)->env; +set_misa (env,RV64 |RVI |RVM |RVA |RVF |RVD |RVC |RVS |RVU ); +set_priv_version (env,PRIV_VERSION_1_10_0 ); + +/* setup custom csr handler hash table */ +setup_custom_csr (); + +} + +void setup_custom_csr (void ) { + custom_csr_map =g_hash_table_new_full (g_direct_hash, g_direct_equal,NULL ,NULL ); +int i; +for (i =0 ; i <MAX_CUSTOM_CSR_NUM ; i++) { +if (andes_custom_csr_table[i].csrno !=0 ) { +g_hash_table_insert (custom_csr_map, +GINT_TO_POINTER (andes_custom_csr_table[i].csrno), + &andes_custom_csr_table[i].csr_opset); + }else { +break ; + } + } +} +static void rv64_sifive_u_cpu_init (Object *obj) {CPURISCVState *env = &RISCV_CPU (obj)->env;
@@ -705,6 +732,7 @@ static const TypeInfo riscv_cpu_type_infos[] = { DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U34, rv32_sifive_u_cpu_init),#elif defined(TARGET_RISCV64 )DEFINE_CPU (TYPE_RISCV_CPU_BASE64 , rv64_base_cpu_init), +DEFINE_CPU (TYPE_RISCV_CPU_AX25 , ax25_cpu_init),DEFINE_CPU (TYPE_RISCV_CPU_SIFIVE_E51 , rv64_sifive_e_cpu_init), DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U54, rv64_sifive_u_cpu_init), #endif
target/riscv/cpu.h +11 -1
@@ -37,6 +37,7 @@#define TYPE_RISCV_CPU_ANY RISCV_CPU_TYPE_NAME("any")#define TYPE_RISCV_CPU_BASE32 RISCV_CPU_TYPE_NAME("rv32")#define TYPE_RISCV_CPU_BASE64 RISCV_CPU_TYPE_NAME("rv64") +#define TYPE_RISCV_CPU_AX25 RISCV_CPU_TYPE_NAME("andes-ax25")#define TYPE_RISCV_CPU_IBEX RISCV_CPU_TYPE_NAME("lowrisc-ibex")#define TYPE_RISCV_CPU_SIFIVE_E31 RISCV_CPU_TYPE_NAME("sifive-e31")#define TYPE_RISCV_CPU_SIFIVE_E34 RISCV_CPU_TYPE_NAME("sifive-e34")
@@ -485,16 +486,25 @@ typedef struct {riscv_csr_op_fn op; } riscv_csr_operations; +typedef struct { +int csrno; +riscv_csr_operations csr_opset; + }riscv_custom_csr_operations ; +/* CSR function table constants */ enum { -CSR_TABLE_SIZE =0x1000 +CSR_TABLE_SIZE =0x1000 , +MAX_CUSTOM_CSR_NUM =100 };/* CSR function table */ +extern riscv_custom_csr_operations andes_custom_csr_table[MAX_CUSTOM_CSR_NUM ];extern riscv_csr_operations csr_ops[CSR_TABLE_SIZE ]; +extern GHashTable *custom_csr_map;void riscv_get_csr_ops (int csrno,riscv_csr_operations *ops);void riscv_set_csr_ops (int csrno,riscv_csr_operations *ops); +void setup_custom_csr (void );void riscv_cpu_register_gdb_regs_for_features (CPUState *cs);
target/riscv/cpu_bits.h +115 -0
124 lines not on this page · raw message
target/riscv/csr.c +102 -5
152 lines not on this page · raw message
Signature · 1 line
2.17.1