sail-riscv icon indicating copy to clipboard operation
sail-riscv copied to clipboard

CSRs should use scattered functions

Open Timmmm opened this issue 1 year ago • 2 comments

The CSR code is a bit odd. For example readCSR() uses a match:

function readCSR csr : csreg -> xlenbits = {
  let res : xlenbits =
  match (csr, sizeof(xlen)) {
    /* machine mode */
    (0xF11,  _) => zero_extend(mvendorid),
...

but also a scattered function for extensions.

...

    _           => /* check extensions */
                   match ext_read_CSR(csr) {
                     Some(res) => res,
                     None()    => { print_bits("unhandled read to CSR ", csr);
                                    zero_extend(0x0) }
                   }

This is silly. It should just work like the scattered functions for instructions - everything uses scattered functions, and there's a riscv_csrs_begin.sail and riscv_csrs_end.sail, and you add new CSRs just by inserting extra files.

Timmmm avatar Feb 19 '24 17:02 Timmmm

This is related to my question a while back. I agree that CSRs should use scattered functions but the question then is whether or not non-standard extensions should keep using the ext_is_CSR_defined, ext_read_CSR and ext_write_CSR hooks or use same the scattered functions as standard extensions. The latter seems more consistent with the way instructions work (there is no ext_execute, ext_encdec, etc.).

defermelowie avatar Feb 23 '24 15:02 defermelowie

Yes I agree there should be a single scattered function; no ext_....

Timmmm avatar Feb 24 '24 17:02 Timmmm