riscv_coprocessor riscv_imsic
API Reference Manual  /  4 Model-to-Model Interfaces  / 

riscv_custom_csr

Description
The riscv_custom_csr interface lets other Simics objects implement custom CSR-registers and get callback for each access.

For the methods below, cpu is the RISC-V CPU model that is extended and ext_obj is the extension object.

The register_csr method registers a custom CSR at csr_address. The arguments name and description are for disassembly and int_register interface. The argument access is the function implementing the CSR access. Return true if CSR is successfully registered.

typedef enum {
        /* Access through csr/csri instruction */
        Riscv_CSR_Instruction_Access = Sim_Gen_Spr_Instruction_Access,

        /* Access through attribute */
        Riscv_Attribute_Access = Sim_Gen_Spr_Attribute_Access,

        /* Access through int_register_interface */
        Riscv_Int_Register_Access = Sim_Gen_Spr_Int_Register_Access,
} riscv_csr_access_type_t;

typedef uint64 (*riscv_csr_access_cb_t)(conf_object_t *obj,
                                        conf_object_t *cpu,
                                        uint32 csr_address,
                                        uint64 value,
                                        uint64 write_mask,
                                        riscv_csr_access_type_t type);

The register_reset method registers a reset callback for the extension. The reset_func callback will be called in connection with the core CPU reset flow.

typedef uint64 (*riscv_reset_cb_t)(conf_object_t *obj,
                                   conf_object_t *cpu);

SIM_INTERFACE(riscv_custom_csr) {

        bool (*register_csr)(conf_object_t *cpu,
                             conf_object_t *ext_obj,
                             uint32 csr_address,
                             const char *name,
                             const char *description,
                             riscv_csr_access_cb_t access);

        void (*register_reset)(conf_object_t *cpu,
                               conf_object_t *csr_obj,
                               riscv_reset_cb_t reset_func);
};

#define RISCV_CUSTOM_CSR_INTERFACE "riscv_custom_csr"

Execution Context
Global Context for all methods.

riscv_coprocessor riscv_imsic