+static void csr_mem_ops_wr(void *opaque, hwaddr addr,
+ uint64_t value, unsigned size) {
+ riscv_csr_operations ops;
+ uint32_t csrnums[18] = {0x300, 0xC00, 0x340, 0x305, 0x304, 0x344,
+ 0x341, 0x343, 0x342, 0xf11, 0x301,0xf14,0x3a0,0x3b0};
+ CPURISCVState* env = &RISCV_CPU(qemu_get_cpu(0))->env;
+ if(((addr&0xff)/4) > 18)
+ return;
+ int csrno = csrnums[((addr&0xff)/4)];
+ riscv_get_csr_ops(csrno,&ops);
+ if(ops.write){
+ ops.write(env,csrno,value);
+ } else if (ops.op) {
+ ops.op(env,csrno,NULL,value,UINT32_MAX);
+ }
+}
+static uint64_t csr_mem_ops_rd(void *opaque, hwaddr addr, unsigned size){
+ uint32_t value = 0;
+ riscv_csr_operations ops;
+ uint32_t csrnums[18] = {0x300, 0xC00, 0x340, 0x305, 0x304, 0x344,
+ 0x341, 0x343, 0x342, 0xf11, 0x301,0xf14,0x3a0,0x3b0};
+ CPURISCVState* env = &RISCV_CPU(qemu_get_cpu(0))->env;
+
+ if(((addr&0xff)/4) > 18)
+ return 0;
+ int csrno = csrnums[((addr&0xff)/4)];
+ riscv_get_csr_ops(csrno,&ops);
+ if(ops.read){
+ ops.read(env,csrno,&value);
+ } else if (ops.op) {
+ ops.op(env,csrno,&value,0,0);
+ }
+ return value;
+}
+static const MemoryRegionOps csr_mem_ops = {
+ .read = csr_mem_ops_rd,
+ .write = csr_mem_ops_wr,
+};
+