Skip to content

Commit 3d210bf

Browse files
committed
[rtl] Add support for direct mode in mtvec
The Ibex RISC-V core currently lacks support for the direct mode in the mtvec (#1419). This commit make mtvec support both vectored and direct mode. To ensure compatibility with existing test programs, the initial value of mtvec.MODE is set to vectored mode.For both vectored mode and direct mode, mtvec.BASE must be 256-byte aligned.
1 parent 97df7a5 commit 3d210bf

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

rtl/ibex_cs_registers.sv

+9-3
Original file line numberDiff line numberDiff line change
@@ -575,10 +575,10 @@ module ibex_cs_registers #(
575575
mtval_en = 1'b0;
576576
mtval_d = csr_wdata_int;
577577
mtvec_en = csr_mtvec_init_i;
578-
// mtvec.MODE set to vectored
578+
// mtvec.MODE default set to vectored,but can change to direct
579579
// mtvec.BASE must be 256-byte aligned
580580
mtvec_d = csr_mtvec_init_i ? {boot_addr_i[31:8], 6'b0, 2'b01} :
581-
{csr_wdata_int[31:8], 6'b0, 2'b01};
581+
{csr_wdata_int[31:8], 6'b0, csr_wdata_int[1:0]};
582582
dcsr_en = 1'b0;
583583
dcsr_d = dcsr_q;
584584
depc_d = {csr_wdata_int[31:1], 1'b0};
@@ -634,7 +634,13 @@ module ibex_cs_registers #(
634634
CSR_MTVAL: mtval_en = 1'b1;
635635

636636
// mtvec
637-
CSR_MTVEC: mtvec_en = 1'b1;
637+
CSR_MTVEC: begin
638+
mtvec_en = 1'b1;
639+
// Change to direct MODE if software writes an unsupported value
640+
if ((mtvec_d[1:0] != 2'b00) && (mtvec_d[1:0] != 2'b01)) begin
641+
mtvec_d[1:0] = 2'b00;
642+
end
643+
end
638644

639645
CSR_DCSR: begin
640646
dcsr_d = csr_wdata_int;

rtl/ibex_if_stage.sv

+6-4
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,13 @@ module ibex_if_stage import ibex_pkg::*; #(
182182

183183
// exception PC selection mux
184184
always_comb begin : exc_pc_mux
185-
irq_vec = exc_cause.lower_cause;
186-
187-
if (exc_cause.irq_int) begin
185+
// mtvec is vectored mode
186+
if (csr_mtvec_i[1:0] == 2'b01) begin
188187
// All internal interrupts go to the NMI vector
189-
irq_vec = ExcCauseIrqNm.lower_cause;
188+
irq_vec = exc_cause.irq_int ? ExcCauseIrqNm.lower_cause : exc_cause.lower_cause;
189+
end else begin
190+
// mtvec is direct mode, so irq_vec is always 0
191+
irq_vec = 5'b00000;
190192
end
191193

192194
unique case (exc_pc_mux_i)

0 commit comments

Comments
 (0)