Professional Documents
Culture Documents
3 - Riscv - Isa2
3 - Riscv - Isa2
Muhammad Tahir
Lecture 5
Contents
3 Trap/Interrupt CSRs
2/24
CSR & Special Instructions RISC-V Privileged Architecture Trap/Interrupt CSRs
3/24
CSR & Special Instructions RISC-V Privileged Architecture Trap/Interrupt CSRs
• Format: I-type
12 5 3 5 7
csr rs1 func3 rd opcode
4/24
CSR & Special Instructions RISC-V Privileged Architecture Trap/Interrupt CSRs
• Format: I-type
• Used to generate an exception to invoke Operating System
(ECALL) and debugger (EBREAK)
12 5 3 5 7
func12 rs1 func3 rd opcode
ECALL/EBREAK 0 PRIV 0 SYS
5/24
CSR & Special Instructions RISC-V Privileged Architecture Trap/Interrupt CSRs
• Format: I-type
• Provides (memory) synchronization barriers for data memory
(fence) and instruction memory (FENSE.I)
12 5 3 5 7
imm12 rs1 func3 rd opcode
successor/predecessor 0 FENCE 0 MEM
FENCE.I
6/24
CSR & Special Instructions RISC-V Privileged Architecture Trap/Interrupt CSRs
• Format: I-type
• URET returns from an exception handler in user mode
• SRET returns from an exception handler in supervisor mode
• MRET returns from an exception handler in machine mode
12 5 3 5 7
func12 rs1 func3 rd opcode
MRET/SRET/URET 0 PRIV 0 SYS
7/24
CSR & Special Instructions RISC-V Privileged Architecture Trap/Interrupt CSRs
8/24
CSR & Special Instructions RISC-V Privileged Architecture Trap/Interrupt CSRs
9/24
CSR & Special Instructions RISC-V Privileged Architecture Trap/Interrupt CSRs
...
10/24
CSR & Special Instructions RISC-V Privileged Architecture Trap/Interrupt CSRs
...
12/24
CSR & Special Instructions RISC-V Privileged Architecture Trap/Interrupt CSRs
13/24
CSR & Special Instructions RISC-V Privileged Architecture Trap/Interrupt CSRs
14/24
CSR & Special Instructions RISC-V Privileged Architecture Trap/Interrupt CSRs
15/24
CSR & Special Instructions RISC-V Privileged Architecture Trap/Interrupt CSRs
15 0
XS[0] FS[1:0] MPP[1:0] SPP MPIE SPIE UPIE MIE SIE UIE
16/24
CSR & Special Instructions RISC-V Privileged Architecture Trap/Interrupt CSRs
15 0
MEIE SEIE UEIE MTIE STIE UTIE MSIE SSIE USIE
17/24
CSR & Special Instructions RISC-V Privileged Architecture Trap/Interrupt CSRs
18/24
CSR & Special Instructions RISC-V Privileged Architecture Trap/Interrupt CSRs
15 0
MEIE SEIE UEIE MTIE STIE UTIE MSIE SSIE USIE
19/24
CSR & Special Instructions RISC-V Privileged Architecture Trap/Interrupt CSRs
Exception Code This field contains a code identifying the last exception.
20/24
CSR & Special Instructions RISC-V Privileged Architecture Trap/Interrupt CSRs
21/24
CSR & Special Instructions RISC-V Privileged Architecture Trap/Interrupt CSRs
Suggested Reading
22/24
CSR & Special Instructions RISC-V Privileged Architecture Trap/Interrupt CSRs
Acknowledgment
23/24
CSR & Special Instructions RISC-V Privileged Architecture Trap/Interrupt CSRs
References
Waterman, A., Lee, Y., Avizienis, R., Patterson, D. A., and Asanovic, K.
(2016a).
The risc-v instruction set manual volume ii: Privileged architecture version
1.9.
EECS Department, University of California, Berkeley, Tech. Rep.
UCB/EECS-2016-129.
24/24