Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ follows the version pins recorded in [VERSION](VERSION) (`VORTEX_VERSION`,

### Changed

- **Machine-mode trap CSRs.** `mstatus` and `mtvec` are one per core, held by the core scheduler and shared by every warp; `mcause`
holds the 4-bit exception codes the core raises; `mtval` reads as zero. `mepc` and `mcause` stay per warp. Per-warp trap state
drops from 160 to 36 bits at XLEN 32.
- **One operand collector per issue slice (`VX_CFG_NUM_OPCS`, default 1).** It was one per 4 warps of a slice. The scoreboard
already issues only when the target unit's dispatch queue has room, so extra collectors only absorbed register bank conflicts.
*Why:* each collector holds three full-width operands and its own register-file banks. At 64 warps, 4 issue slices and 32
threads (rtlsim, 8 SIMT kernels), 1 collector per slice instead of 4 is 2.1% faster on geomean, worst +0.8% (sgemv), and
2 per slice matches 4 to the cycle. Beacon's `core` build (16 warps, 16 threads, 4 collectors to 1): LUTs -12.1%,
flip-flops -13.3%, block RAM -70%, same logic depth.

- **V80 image reuse across runs.** A design the card already holds is no longer written again on every device open. SLASH now does
what XRT does for xclbins: `slashkit` stamps a UUID into the vbin, `vrtd` remembers the UUID it wrote and skips a write of the same
one, `VRT_FORCE_PROGRAM=1` overrides, `v80-smi forget-design` reports a design loaded over JTAG (`jtag_load_vortex.sh` now runs
Expand Down Expand Up @@ -122,6 +124,10 @@ follows the version pins recorded in [VERSION](VERSION) (`VORTEX_VERSION`,

### Fixed

- **Trap CSR writes before ECALL, EBREAK and MRET.** A `csrw mepc` in a trap handler could still be pending when the following `mret`
read `mepc`, returning the warp to the trapping instruction. ECALL, EBREAK and MRET now wait for pending writes to `mstatus`, `mtvec`
and `mepc`, in SimX and RTL. New regression test `trap` and parity cases
`core:parity-trap-fw4`, `core:parity-trap-cs4` and `core:parity-trap-fw2-sfu4`.
- **ASIC core and top at 800 MHz.** On ASAP7 the core reached 655 MHz and top 654 MHz against the 800 MHz catalog clock, held by
three datapaths: the FDIV/FSQRT result stage, the FMA's accumulate and rounding stages, and the integer multiplier. Each is
retimed with no change in latency, so SimX and every cycle count are unchanged. FDIV/FSQRT decides the subnormal shift and tests
Expand Down
24 changes: 24 additions & 0 deletions ci/testcases/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,30 @@ tests:
via: blackbox
app: printf
configs: -DVX_CFG_NUM_THREADS=16 -DVX_CFG_NUM_WARPS=16 -DVX_CFG_ISSUE_WIDTH=4 -DVX_CFG_FETCH_WIDTH=2
# Synchronous traps from every warp across four frontend slices: each
# handler's mepc write must be seen by its MRET, and each warp keeps its own
# return PC and cause.
- id: parity-trap-fw4
check: model_parity
via: blackbox
app: trap
args: -n512 -i8
configs: -DVX_CFG_NUM_THREADS=4 -DVX_CFG_NUM_WARPS=16 -DVX_CFG_ISSUE_WIDTH=4 -DVX_CFG_FETCH_WIDTH=4
# The per-core mtvec written by one warp and read by all, across four compute
# slices with an SFU block each, and across two frontend slices served by four
# SFU blocks.
- id: parity-trap-cs4
check: model_parity
via: blackbox
app: trap
args: -n512 -i8
configs: -DVX_CFG_NUM_THREADS=4 -DVX_CFG_NUM_WARPS=16 -DVX_CFG_ISSUE_WIDTH=4 -DVX_CFG_FETCH_WIDTH=4 -DVX_CFG_NUM_SFU_BLOCKS=4
- id: parity-trap-fw2-sfu4
check: model_parity
via: blackbox
app: trap
args: -n512 -i8
configs: -DVX_CFG_NUM_THREADS=4 -DVX_CFG_NUM_WARPS=16 -DVX_CFG_ISSUE_WIDTH=4 -DVX_CFG_FETCH_WIDTH=2 -DVX_CFG_NUM_SFU_BLOCKS=4
# The same fences on a data cache shared by two cores, below an L2: each core's
# token rides its own flush injection, and every fence walks the data cache.
- id: parity-printf-ss2
Expand Down
45 changes: 27 additions & 18 deletions docs/designs/trap_and_exception_foundation.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,40 @@ suite rides on. Covers the RTL

## 1. Architecture

Each warp owns five M-mode trap CSRs held in the scheduler
([`VX_scheduler.sv:59`](../../hw/rtl/core/VX_scheduler.sv#L59)):
`mstatus`, `mtvec`, `mepc`, `mcause`, `mtval`
(`[NUM_WARPS][XLEN]`). Addresses: `MSTATUS=0x300`, `MTVEC=0x305`,
The M-mode trap CSRs are held by the schedulers. Every warp runs the same
kernel and trap handler, so `mstatus` and `mtvec` are one per core, in the
core scheduler ([`VX_scheduler.sv`](../../hw/rtl/core/VX_scheduler.sv));
the CSR unit reads and writes them in the fire cycle, as it does `satp`.
`mepc` and `mcause`, which concurrent traps in different warps need, stay
per warp in the warp schedulers
([`VX_warp_sched.sv`](../../hw/rtl/core/VX_warp_sched.sv)); `mcause` holds
only the 4-bit exception codes the core raises. `mtval` reads as zero: no
exception the core raises carries a trap value. Addresses: `MSTATUS=0x300`, `MTVEC=0x305`,
`MSCRATCH=0x340`, `MEPC=0x341`, `MCAUSE=0x342`, `MTVAL=0x343`
([`VX_types.toml:325-334`](../../VX_types.toml#L325)).

The branch unit is the trap producer
([`VX_alu_int.sv:310-339`](../../hw/rtl/core/VX_alu_int.sv#L310)): it
raises `is_trap_entry` / `is_mret_op` with a `br_trap_cause` (`EBREAK=3`,
([`VX_alu_int.sv`](../../hw/rtl/core/VX_alu_int.sv)): it raises
`is_trap_entry` / `is_mret_op` with a `br_trap_cause` (`EBREAK=3`,
`ECALL=11`). These ride the existing `VX_branch_ctl_if` (the proposed
standalone `VX_trap_if.sv` was folded in — functionally equivalent). The
scheduler redirects `warp_pcs_n`: a trap goes to `mtvec & ~3`, an `mret`
returns to `mepc`
([`VX_scheduler.sv:306-311`](../../hw/rtl/core/VX_scheduler.sv#L306)).
On trap entry the hardware snapshots `mepc`/`mcause`; a same-cycle software
`csrw` and a hardware trap entry are ordered hardware-wins
([`:394-412`](../../hw/rtl/core/VX_scheduler.sv#L394)). The CSR file does
only the read mux and routes writes back via `sched_csr_if`
([`VX_csr_data.sv:253-257`](../../hw/rtl/core/VX_csr_data.sv#L253)).
warp scheduler ([`VX_warp_sched.sv`](../../hw/rtl/core/VX_warp_sched.sv))
redirects the warp: a trap goes to the core's `mtvec & ~3`, an `mret`
returns to the warp's `mepc`. On trap entry the hardware snapshots
`mepc`/`mcause`; a same-cycle software `csrw` and a hardware trap entry are
ordered hardware-wins. The CSR file
([`VX_csr_data.sv`](../../hw/rtl/core/VX_csr_data.sv)) does the read mux
and routes writes back via `sched_csr_if`.

ECALL, EBREAK and MRET depend on the warp's pending writes to `mstatus`,
`mtvec` and `mepc` through the scoreboard, so a handler's `csrw mepc` lands
before its `mret` reads `mepc`, and a warp's own `mtvec` write before its
trap redirects through it.

SimX mirrors this exactly:
[`scheduler.cpp:271-298`](../../sim/simx/scheduler.cpp#L271) defines
`raise_trap`, `mret`, `trigger_ecall(wid,pc)`, `trigger_ebreak(wid,pc)`;
[`alu_unit.cpp:363-366`](../../sim/simx/alu_unit.cpp#L363) dispatches
[`scheduler.cpp`](../../sim/simx/scheduler.cpp) defines `raise_trap`,
`mret`, `trigger_ecall(wid,pc)`, `trigger_ebreak(wid,pc)`;
[`alu_unit.cpp`](../../sim/simx/alu_unit.cpp) dispatches
ecall/ebreak/mret per warp. The old "kill all warps"
(`active_warps_.reset()`) hack is gone.

Expand Down Expand Up @@ -90,7 +99,7 @@ The named **preemption** capability is future work:
fault causes (2/4/6).
3. **Supervisor mode** — `stvec`/`sepc`/`scause` + `medeleg`-driven
redirect.
4. **Interrupts** — `mie`/`mip`, async injection, `mcause` MSB.
4. **Interrupts** — `mie`/`mip`, async injection, `mcause` MSB (widening `mcause` past the 4 exception-code bits it holds today).
5. **Register-file / IPDOM-stack save-restore** — required for true
context switch (only the trap CSRs are saved today).
6. **`tests/regression/csr_smoke/`** unit test — absent.
Expand Down
19 changes: 12 additions & 7 deletions hw/rtl/VX_gpu_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ package VX_gpu_pkg;
// these bits.
localparam XREG_0 = 0;
localparam XREG_1 = 1;
localparam NUM_XREGS = 2;
localparam XREG_2 = 2;
localparam NUM_XREGS = 3;

localparam DV_STACK_SIZE = `UP(`VX_CFG_NUM_THREADS-1);
localparam DV_STACK_SIZEW = `LOG2UP(DV_STACK_SIZE);
Expand Down Expand Up @@ -670,8 +671,15 @@ package VX_gpu_pkg;
localparam ISSUE_WIS_BITS = `CLOG2(PER_ISSUE_WARPS);
localparam ISSUE_WIS_W = `UP(ISSUE_WIS_BITS);

// Machine-mode trap CSRs stored per warp in the scheduler: mstatus, mtvec, mepc, mcause, mtval.
localparam NUM_TRAP_CSRS = 5;
// Per-warp machine-mode trap CSRs, held by the warp schedulers: the return
// PC and cause, which concurrent traps in different warps need. Every warp
// runs the same kernel and trap handler, so mstatus and mtvec are one per
// core, held by the core scheduler.
localparam NUM_TRAP_CSRS = 2;
localparam TRAP_CSR_MEPC = 0;
localparam TRAP_CSR_MCAUSE = 1;
// mcause holds only the exception codes the core raises (ECALL, EBREAK).
localparam TRAP_CAUSE_BITS = 4;

localparam DISPATCH_QSIZE = `VX_CFG_DISPATCH_QUEUE_SIZE;

Expand Down Expand Up @@ -1367,7 +1375,7 @@ package VX_gpu_pkg;
logic [PC_BITS-1:0] dest;
logic is_trap;
logic is_mret;
logic [3:0] trap_cause;
logic [TRAP_CAUSE_BITS-1:0] trap_cause;
} sched_branch_t;

// SFU warp control
Expand Down Expand Up @@ -1395,11 +1403,8 @@ package VX_gpu_pkg;
typedef struct packed {
logic [`VX_CFG_NUM_THREADS-1:0] thread_mask;
logic [`VX_CFG_MEM_ADDR_WIDTH-1:0] mscratch;
logic [`VX_CFG_XLEN-1:0] mstatus;
logic [`VX_CFG_XLEN-1:0] mtvec;
logic [`VX_CFG_XLEN-1:0] mepc;
logic [`VX_CFG_XLEN-1:0] mcause;
logic [`VX_CFG_XLEN-1:0] mtval;
logic [NW_WIDTH-1:0] cta_rank;
cta_lane_t [`VX_CFG_NUM_THREADS-1:0] cta_lane;
} sched_csr_rd_t;
Expand Down
4 changes: 2 additions & 2 deletions hw/rtl/core/VX_alu_int.sv
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ module VX_alu_int import VX_gpu_pkg::*; #(
// these via branch_ctl_if.{is_trap,is_mret,trap_cause}.
wire is_trap_entry = is_br_op_r && (br_op_r == INST_BR_ECALL || br_op_r == INST_BR_EBREAK);
wire is_mret_op = is_br_op_r && (br_op_r == INST_BR_MRET || br_op_r == INST_BR_SRET || br_op_r == INST_BR_URET);
wire [3:0] br_trap_cause = (br_op_r == INST_BR_EBREAK) ? 4'd3 : 4'd11; // EBREAK / ECALL_M
wire [TRAP_CAUSE_BITS-1:0] br_trap_cause = (br_op_r == INST_BR_EBREAK) ? TRAP_CAUSE_BITS'(3) : TRAP_CAUSE_BITS'(11); // EBREAK / ECALL_M

wire [`VX_CFG_XLEN-1:0] br_result = alu_result_r[last_tid_r];
wire is_less = br_result[0];
Expand All @@ -363,7 +363,7 @@ module VX_alu_int import VX_gpu_pkg::*; #(
end

VX_pipe_register #(
.DATAW (1 + NW_WIDTH + 1 + PC_BITS + 1 + 1 + 4),
.DATAW (1 + NW_WIDTH + 1 + PC_BITS + 1 + 1 + TRAP_CAUSE_BITS),
.RESETW (1)
) branch_reg (
.clk (clk),
Expand Down
14 changes: 11 additions & 3 deletions hw/rtl/core/VX_compute_slice.sv
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ import VX_tcu_pkg::*;
output wire satp_wr_valid,
output wire [`VX_CFG_XLEN-1:0] satp_wr_data,
`endif
input wire [`VX_CFG_XLEN-1:0] mstatus,
input wire [`VX_CFG_XLEN-1:0] mtvec,
output wire mstatus_wr_valid,
output wire mtvec_wr_valid,
output wire [`VX_CFG_XLEN-1:0] mtrap_wr_data,

// LSU
`ifdef PERF_ENABLE
Expand Down Expand Up @@ -159,6 +164,7 @@ import VX_tcu_pkg::*;
assign fs_sched_if.bar_unlock_valid = slice_sched_if.bar_unlock_valid;
assign fs_sched_if.bar_unlock_mask = slice_sched_if.bar_unlock_mask;
assign fs_sched_if.slice_ibuf_full = slice_sched_if.slice_ibuf_full;
assign fs_sched_if.mtvec = slice_sched_if.mtvec;
`ifdef EXT_SCHED_TIMEOUT_DUMP
assign fs_sched_if.timeout_dump = slice_sched_if.timeout_dump;
`endif
Expand Down Expand Up @@ -255,18 +261,20 @@ import VX_tcu_pkg::*;
assign sched_csr_if.active_warps = active_warps;
assign sched_csr_if.thread_mask = csr_rd[0].thread_mask;
assign sched_csr_if.mscratch = csr_rd[0].mscratch;
assign sched_csr_if.csr_mstatus = csr_rd[0].mstatus;
assign sched_csr_if.csr_mtvec = csr_rd[0].mtvec;
assign sched_csr_if.csr_mepc = csr_rd[0].mepc;
assign sched_csr_if.csr_mcause = csr_rd[0].mcause;
assign sched_csr_if.csr_mtval = csr_rd[0].mtval;
assign sched_csr_if.cta_rank = csr_rd[0].cta_rank;
assign sched_csr_if.cta_lane = csr_rd[0].cta_lane;
`ifdef VX_CFG_VM_ENABLE
assign sched_csr_if.csr_satp = satp;
assign satp_wr_valid = sched_csr_if.satp_wr_valid;
assign satp_wr_data = sched_csr_if.satp_wr_data;
`endif
assign sched_csr_if.csr_mstatus = mstatus;
assign sched_csr_if.csr_mtvec = mtvec;
assign mstatus_wr_valid = sched_csr_if.mstatus_wr_valid;
assign mtvec_wr_valid = sched_csr_if.mtvec_wr_valid;
assign mtrap_wr_data = sched_csr_if.mtrap_wr_data;

`ifdef VX_CFG_EXT_RTU_ENABLE
assign rtu_unlock_valid[0] = sched_unlock_if.valid;
Expand Down
20 changes: 20 additions & 0 deletions hw/rtl/core/VX_core.sv
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ import VX_tcu_pkg::*;
wire [`VX_CFG_NUM_SFU_BLOCKS-1:0] satp_wr_valid;
wire [`VX_CFG_NUM_SFU_BLOCKS-1:0][`VX_CFG_XLEN-1:0] satp_wr_data;
`endif
wire [`VX_CFG_NUM_SFU_BLOCKS-1:0][`VX_CFG_XLEN-1:0] sched_mstatus;
wire [`VX_CFG_NUM_SFU_BLOCKS-1:0][`VX_CFG_XLEN-1:0] sched_mtvec;
wire [`VX_CFG_NUM_SFU_BLOCKS-1:0] mstatus_wr_valid;
wire [`VX_CFG_NUM_SFU_BLOCKS-1:0] mtvec_wr_valid;
wire [`VX_CFG_NUM_SFU_BLOCKS-1:0][`VX_CFG_XLEN-1:0] mtrap_wr_data;

cta_bcast_t cta_bcast;

Expand Down Expand Up @@ -324,6 +329,11 @@ import VX_tcu_pkg::*;
.satp_wr_valid (satp_wr_valid),
.satp_wr_data (satp_wr_data),
`endif
.mstatus (sched_mstatus),
.mtvec (sched_mtvec),
.mstatus_wr_valid (mstatus_wr_valid),
.mtvec_wr_valid (mtvec_wr_valid),
.mtrap_wr_data (mtrap_wr_data),
.busy (sched_busy)
);

Expand Down Expand Up @@ -463,6 +473,11 @@ import VX_tcu_pkg::*;
.satp_wr_valid (satp_wr_valid[i]),
.satp_wr_data (satp_wr_data[i]),
`endif
.mstatus (sched_mstatus[i]),
.mtvec (sched_mtvec[i]),
.mstatus_wr_valid (mstatus_wr_valid[i]),
.mtvec_wr_valid (mtvec_wr_valid[i]),
.mtrap_wr_data (mtrap_wr_data[i]),
`ifdef PERF_ENABLE
.lsu_perf_rd_req_fire (lsu_perf_rd_req_fire[i]),
.lsu_perf_wr_req_fire (lsu_perf_wr_req_fire[i]),
Expand Down Expand Up @@ -559,6 +574,11 @@ import VX_tcu_pkg::*;
.satp_wr_valid (satp_wr_valid),
.satp_wr_data (satp_wr_data),
`endif
.mstatus (sched_mstatus),
.mtvec (sched_mtvec),
.mstatus_wr_valid (mstatus_wr_valid),
.mtvec_wr_valid (mtvec_wr_valid),
.mtrap_wr_data (mtrap_wr_data),
.fs_branch (fs_branch),
.fs_wctl (fs_wctl),
.fs_dvstack_wid (fs_dvstack_wid),
Expand Down
37 changes: 26 additions & 11 deletions hw/rtl/core/VX_csr_data.sv
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,19 @@ import VX_fpu_pkg::*;
localparam LIVE_CLUSTER = 21;
localparam LIVE_ENTRY = 22;
localparam LIVE_SATP = 23;
localparam NUM_LIVE = 24;
localparam LIVE_MSTATUS = 24;
localparam LIVE_MTVEC = 25;
localparam NUM_LIVE = 26;

// Writable CSRs
localparam WR_MSCRATCH = 0;
localparam WR_SATP = 1;
localparam WR_FFLAGS = 2;
localparam WR_FRM = 3;
localparam WR_FCSR = 4;
localparam WR_TRAP = 5;
localparam WR_MSTATUS = 5;
localparam WR_MTVEC = 6;
localparam WR_TRAP = 7;
localparam NUM_WR = WR_TRAP + NUM_TRAP_CSRS;

function automatic logic [`VX_CFG_XLEN-1:0] csr_rmw(
Expand Down Expand Up @@ -165,12 +169,14 @@ import VX_fpu_pkg::*;
`VX_CSR_SATP : begin live_sel_w[LIVE_SATP] = 1; wr_sel_w[WR_SATP] = 1; end
`endif

// Machine-mode trap CSRs (stored in the scheduler).
`VX_CSR_MSTATUS : begin stable_w = sched_csr_if.csr_mstatus; wr_sel_w[WR_TRAP + 0] = 1; end
`VX_CSR_MTVEC : begin stable_w = sched_csr_if.csr_mtvec; wr_sel_w[WR_TRAP + 1] = 1; end
`VX_CSR_MEPC : begin stable_w = sched_csr_if.csr_mepc; wr_sel_w[WR_TRAP + 2] = 1; end
`VX_CSR_MCAUSE : begin stable_w = sched_csr_if.csr_mcause; wr_sel_w[WR_TRAP + 3] = 1; end
`VX_CSR_MTVAL : begin stable_w = sched_csr_if.csr_mtval; wr_sel_w[WR_TRAP + 4] = 1; end
// Machine-mode trap CSRs: mstatus and mtvec per core, mepc and
// mcause per warp, all held by the schedulers.
`VX_CSR_MSTATUS : begin live_sel_w[LIVE_MSTATUS] = 1; wr_sel_w[WR_MSTATUS] = 1; end
`VX_CSR_MTVEC : begin live_sel_w[LIVE_MTVEC] = 1; wr_sel_w[WR_MTVEC] = 1; end
`VX_CSR_MEPC : begin stable_w = sched_csr_if.csr_mepc; wr_sel_w[WR_TRAP + TRAP_CSR_MEPC] = 1; end
`VX_CSR_MCAUSE : begin stable_w = sched_csr_if.csr_mcause; wr_sel_w[WR_TRAP + TRAP_CSR_MCAUSE] = 1; end
// mtval is read-only zero: no exception the core raises carries a trap value.
`VX_CSR_MTVAL : begin stable_w = '0; end

// The MPM counters are only reachable from the host; everything
// else reads as zero.
Expand Down Expand Up @@ -261,6 +267,8 @@ import VX_fpu_pkg::*;
`else
assign live_src[LIVE_SATP] = '0;
`endif
assign live_src[LIVE_MSTATUS] = sched_csr_if.csr_mstatus;
assign live_src[LIVE_MTVEC] = sched_csr_if.csr_mtvec;

reg [`VX_CFG_XLEN-1:0] live_data;
always @(*) begin
Expand All @@ -284,6 +292,15 @@ import VX_fpu_pkg::*;
assign sched_csr_if.trap_csr_wr_valid = write_sel[WR_TRAP +: NUM_TRAP_CSRS];
assign sched_csr_if.trap_csr_wr_data = wr_data_r;

// The per-core CSRs (mstatus, mtvec, SATP) live in the core scheduler,
// shared by every SFU block, so their read-modify-write stays in the fire
// cycle.
wire [`VX_CFG_XLEN-1:0] live_wr_data = csr_rmw(req_op, live_data, req_src);

assign sched_csr_if.mstatus_wr_valid = write_sel[WR_MSTATUS];
assign sched_csr_if.mtvec_wr_valid = write_sel[WR_MTVEC];
assign sched_csr_if.mtrap_wr_data = live_wr_data;

`ifdef VX_CFG_EXT_F_ENABLE
// The FP flags keep moving under in-flight FP instructions, so their
// read-modify-write stays in the fire cycle.
Expand All @@ -294,10 +311,8 @@ import VX_fpu_pkg::*;
`endif

`ifdef VX_CFG_VM_ENABLE
// The per-core SATP CSR lives in the scheduler, shared by every SFU block,
// so its read-modify-write stays in the fire cycle.
assign sched_csr_if.satp_wr_valid = write_sel[WR_SATP];
assign sched_csr_if.satp_wr_data = csr_rmw(req_op, live_data, req_src);
assign sched_csr_if.satp_wr_data = live_wr_data;
`else
`UNUSED_VAR (write_sel[WR_SATP])
`endif
Expand Down
6 changes: 6 additions & 0 deletions hw/rtl/core/VX_decode.sv
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ module VX_decode import
wire is_csr_fflags = (u_12 == `VX_CSR_FFLAGS);
wire is_csr_frm = (u_12 == `VX_CSR_FRM);
wire is_csr_fcsr = (u_12 == `VX_CSR_FCSR);
// Trap CSRs that ECALL/EBREAK/MRET read when they execute in the ALU,
// while the CSR unit writes them: XREG_2 orders the two.
wire is_csr_trap = (u_12 == `VX_CSR_MSTATUS) || (u_12 == `VX_CSR_MTVEC) || (u_12 == `VX_CSR_MEPC);
wire frm_is_dyn = (funct3 == 3'b111);
wire is_rd_zero = (rd == 0);
`UNUSED_VAR (frm_is_dyn)
Expand Down Expand Up @@ -486,6 +489,8 @@ module VX_decode import
rd_xregs[XREG_1] = is_csr_fcsr || is_csr_frm;
wr_xregs[XREG_0] = csr_write && (is_csr_fcsr || is_csr_fflags);
wr_xregs[XREG_1] = csr_write && (is_csr_fcsr || is_csr_frm);
rd_xregs[XREG_2] = is_csr_trap;
wr_xregs[XREG_2] = csr_write && is_csr_trap;
`USED_IREG (rd);
`USED_REG (REG_TYPE_I, rs1, ~funct3[2]);
end else begin
Expand All @@ -499,6 +504,7 @@ module VX_decode import
op_args.br.imm20 = 20'd4;
op_args.br.is_rvc = decode_is_rvc;
is_wstall = 1;
rd_xregs[XREG_2] = 1'b1;
`USED_IREG (rd);
end
end
Expand Down
Loading
Loading