sail-riscv
sail-riscv copied to clipboard
CSRs should use scattered functions
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.
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.).
Yes I agree there should be a single scattered function; no ext_....