mepc
Machine exception program counter
- Address
0x341- Group
- Machine-level CSRs
- Privilege
MRW(privileged spec CSR listing, Machine Trap Handling)- Access
- read/write; lowest privilege M (machine)
- Address range
- Standard read/write
- Name in riscv-unified-db
- Machine Exception Program Counter
Privileged spec: Machine exception program counter
Description
Written with the PC of an instruction on an exception or interrupt taken in M-mode.
Also controls where the hart jumps on an exception return from M-mode.
From riscv-unified-db, reformatted.
Fields
| Field | Bits | Type | Description |
|---|---|---|---|
PC | RV32 31-0 / RV64 63-0 | RW-RH | When a trap is taken into M-mode, On an exception return from M-mode (from the MRET instruction),
control transfers to the virtual address read out of Because PCs are always halfword-aligned, bit 0 of Because PCs are always word-aligned, bits 1:0 of When |
Fields from riscv-unified-db; field types computed by IDL functions there are not shown.
Specification and related pages
- The RISC-V Instruction Set Manual, Volume II: CSR listing (src/priv/csrs.adoc)
- riscv-opcodes csrs.csv
- riscv-unified-db: spec/std/isa/csr/mepc.yaml
- csrrw, csrrs, csrrc (Zicsr instructions that access CSRs)