k210-sdk-stuff/doc/mmu_notes.md
Wladimir J. van der Laan f4888ee0ef rust: Add MMU test
2020-06-02 21:13:23 +00:00

1.7 KiB

Notes on K210 MMU

The K210 has a MMU based on the RISC-V privileged spec 1.9.1.

This means that:

  • The sfence.vm (bit pattern 0x10400073) instruction should be used to synchronize updates to the page tables with current execution, not sfence.vma (bit pattern 0x12000073). See spec section 4.2.1.

  • The sptbr CSR (0x180, Supervisor Page-Table Base Register) specifies the current root page table. In the newer spec this register is called satp and is completely different.

  • In spec v1.9.1, sstatus.SUM is still PUM which has opposite meaning.

  • To switch on paging, set the VM bitfield (offset 24:28) of mstatus to Sv39 (9).

Also, reportedly interrupts do not work as expected in S mode, making that mode more or less useless. Only M and U mode can be used in practice.

To access paged memory from M mode, the MPRV bit in mstatus can be set, with MPP set to 0 (U mode). From the spec (section 3.1.9):

The MPRV bit modifies the privilege level at which loads and stores execute. When MPRV=0, translation and protection behave as normal. When MPRV=1, data memory addresses are trans- lated and protected as though the current privilege mode were set to MPP. Instruction address- translation and protection are unaffected

Examples

There is a little bit of example code for using the MMU on the K210: