Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How the RISC-V HW can determine the privilege level?

Tags:

riscv

The RISC-V current SW privilege level is not set in any CSR. Nevertheless the spec states that "Attempts to access a CSR without appropriate privilege level ... raise illegal instruction". How can it be implemented then (in the HW)?

like image 1000
Uzi Avatar asked Feb 18 '20 16:02

Uzi


2 Answers

Well, on interrupts - "xPP holds the previous privilege mode (x=M,S or U). The xPP fields can only hold privilege modes up to x, so MPP is two bits wide, SPP is one bit wide, and UPP is implicitly zero."

Actually, what I have found now is that the xRET instruction enables the processor to store (internally) the current mode - "The MRET, SRET, or URET instructions are used to return from traps in M-mode, S-mode, or U-mode respectively. When executing an xRET instruction, supposing xPP holds the value y, x IE is set to x PIE; the privilege mode is changed to y; x PIE is set to 1; and xPP is set to U (or M if user-mode is not supported)."

like image 51
Uzi Avatar answered Oct 17 '22 17:10

Uzi


The privilege level is reflected in the MPP bits of the mstatus register.

like image 28
Martin Norbäck Olivers Avatar answered Oct 17 '22 15:10

Martin Norbäck Olivers