Skip to content

CSR satp (Supervisor Address Translation and Protection) is read wrongly #215

@etterli

Description

@etterli

I have a question about the current Snitch implementation regarding the CSR satp (Supervisor Address Translation and Protection) as specified in the RISC-V standard (v20240411).

There seems to exist an inconsistency between reading and writing this CSR.
When this CSR is read, the following information is expected to be copied into the destination register (from standard):

Image

Imho, the current implementation leads to a wrong bit position of the MODE bit and the 32b value written to the destination is:
rd = {{9{1'b0}}, MODE, PPN[21:0]}
instead of:
rd = {MODE, ASID[8:0], PPN[21:0]}.

As far as I understand, the actual implementation does not use the ASID bits (always set to zero). As of this, the struct used to represent the satp misses the ASID fields. The direct assignment here then places the MODE bit at the wrong location. When writing the CSR, the correct locations are updated (i.e., bit 31).

Is this intended behavior or should it be fixed?

Two solutions are possible:

  1. Either correct the assignment when reading the CSR. Replace this line with csr_rdata = {satp_q.mode, {XLEN-$bits(satp_t){1'b0}}, satp_q.ppn};.
  2. Extend the satp struct with the ASID bits. Change the struct to:
 typedef struct packed {
   logic mode;
   logic [8:0] asid;
   logic [21:0] ppn;
 } satp_t;

If it should be fixed, what are the effects to the Snitch runtime?

Metadata

Metadata

Assignees

Labels

help wantedExtra attention is needed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions