CVA6 - Adding a CSR and verifying the behavior in GTKwave
Introduction
The idea of this post is to explore how we can add a CSR in the CVA6 processor and how we can check its behavior in GTKwave. In this tutorial, we will try to add a CSR named dmpcfg
at address 0x3f0
.
Adding a CSR in the CVA6 HDL code
For the CVA6, CSRs are implemented in https://github.com/openhwgroup/cva6/blob/master/core/csr_regfile.sv. In this file, there are two important processes:
csr_read_process
: https://github.com/openhwgroup/cva6/blob/master/core/csr_regfile.sv#L188, the CSR read logic.csr_update
: https://github.com/openhwgroup/cva6/blob/master/core/csr_regfile.sv#L488, the CSR update/write logic.
Update of the write logic
https://github.com/openhwgroup/cva6/blob/master/core/csr_regfile.sv#L488
|
|
|
|
|
|
The CSR variable goes through a D flip-flop, and can be reset in the related signal is raised: dmpcfg_q
and dmpcfg_d
are defined for this purpose.
|
|
When we want to write data, if the address is equal to CSR_DMPCFG
, csr_wdata
goes into dmpcfg_d
(similar process for other registers). CSR addresses are defined in https://github.com/openhwgroup/cva6/blob/master/core/include/riscv_pkg.sv
|
|
Update of the read logic
https://github.com/openhwgroup/cva6/blob/master/core/csr_regfile.sv#L188
More easier:
|
|
All modifications are also in this commit in a fork: https://github.com/pcotret/cva6/commit/b854721dc9214ff88075363af08acff9976ebbce
Verifying the new CSR in GTKwave
This small code is an example of write-then-read a custom CSR named dmpcfg
. In order to verify if the CSR can be accessed without recompiling a new toolchain, the code has been slightly modified:
|
|
We can finally checked this code in GTKWave as done in http://pcotret.gitlab.io/blog/cva6_vcd/