RvCsr
M モードの CSR ファイルとトラップ制御 (docs/riscv.md「ISA スコープ」)
実装するのは M モードのみ.S/U モード・PMP・デバッグトリガは持たない.
| 番号 | 名前 | 実装範囲 |
|---|---|---|
| 0x300 | mstatus | MIE(3) / MPIE(7) のみ.MPP は 11 固定 |
| 0x301 | misa | 読み出し専用.MXL=1, I, M |
| 0x304 | mie | MTIE(7) のみ |
| 0x305 | mtvec | direct モードのみ (下位 2 bit は 0 固定) |
| 0x340 | mscratch | 全 32 bit |
| 0x341 | mepc | 下位 2 bit は 0 固定 |
| 0x342 | mcause | 全 32 bit |
| 0x343 | mtval | 全 32 bit |
| 0x344 | mip | MTIP(7) は読み出し専用 (タイマから) |
| 0xF11-0xF14 | mvendorid/marchid/mimpid/mhartid | 読み出し 0 |
未実装 CSR へのアクセスと,読み出し専用 CSR への書き込みは
o_illegal を立てる (コア側が不正命令例外にする).
Ports
| i_clk | input | clock | クロック |
|---|---|---|---|
| i_rst | input | reset | リセット |
| i_valid | input | logic | CSR 命令を実行する |
| i_addr | input | logic<12> | CSR 番号 |
| i_op | input | logic<2> | 01=RW / 10=RS / 11=RC |
| i_wdata | input | logic<32> | 書き込み値 (rs1 または uimm) |
| i_wen | input | logic | 書き込みを行う (RW,または rs1/uimm != 0) |
| o_rdata | output | logic<32> | 読み出し値 |
| o_illegal | output | logic | 未実装 CSR / 読み出し専用への書き込み |
| i_trap | input | logic | トラップ発生 |
| i_trap_cause | input | logic<32> | mcause へ書く値 |
| i_trap_pc | input | logic<32> | mepc へ書く値 |
| i_trap_tval | input | logic<32> | mtval へ書く値 |
| i_mret | input | logic | MRET 実行 |
| o_tvec | output | logic<32> | トラップベクタ (mtvec) |
| o_epc | output | logic<32> | 復帰先 (mepc) |
| i_timer_irq | input | logic | CLINT からのタイマ割り込み |
| o_irq_pending | output | logic | 受理可能な割り込みがある |