1 |
11 |
dinesha |
/// Copyright by Syntacore LLC © 2016-2020. See LICENSE for details
|
2 |
|
|
/// @file
|
3 |
|
|
/// @brief Instruction Decoder Unit (IDU)
|
4 |
|
|
///
|
5 |
|
|
|
6 |
|
|
//------------------------------------------------------------------------------
|
7 |
|
|
//
|
8 |
|
|
// Functionality:
|
9 |
|
|
// - Decodes the instruction and creates the appropriate control signals for EXU
|
10 |
|
|
//
|
11 |
|
|
// Structure:
|
12 |
|
|
// - Instruction decoder
|
13 |
|
|
// - IDU <-> IFU i/f
|
14 |
|
|
// - IDU <-> EXU i/f
|
15 |
|
|
//
|
16 |
|
|
//------------------------------------------------------------------------------
|
17 |
|
|
|
18 |
|
|
`include "scr1_memif.svh"
|
19 |
|
|
`include "scr1_arch_types.svh"
|
20 |
|
|
`include "scr1_riscv_isa_decoding.svh"
|
21 |
|
|
`include "scr1_arch_description.svh"
|
22 |
|
|
|
23 |
|
|
module scr1_pipe_idu
|
24 |
|
|
(
|
25 |
|
|
`ifdef SCR1_TRGT_SIMULATION
|
26 |
|
|
input logic rst_n, // IDU reset
|
27 |
|
|
input logic clk, // IDU clock
|
28 |
|
|
`endif // SCR1_TRGT_SIMULATION
|
29 |
|
|
|
30 |
|
|
// IFU <-> IDU interface
|
31 |
|
|
output logic idu2ifu_rdy_o, // IDU ready for new data
|
32 |
|
|
input logic [`SCR1_IMEM_DWIDTH-1:0] ifu2idu_instr_i, // IFU instruction
|
33 |
|
|
input logic ifu2idu_imem_err_i, // Instruction access fault exception
|
34 |
|
|
input logic ifu2idu_err_rvi_hi_i, // 1 - imem fault when trying to fetch second half of an unaligned RVI instruction
|
35 |
|
|
input logic ifu2idu_vd_i, // IFU request
|
36 |
|
|
|
37 |
|
|
// IDU <-> EXU interface
|
38 |
|
|
output logic idu2exu_req_o, // IDU request
|
39 |
|
|
output type_scr1_exu_cmd_s idu2exu_cmd_o, // IDU command
|
40 |
|
|
output logic idu2exu_use_rs1_o, // Instruction uses rs1
|
41 |
|
|
output logic idu2exu_use_rs2_o, // Instruction uses rs2
|
42 |
|
|
output logic idu2exu_use_rd_o, // Instruction uses rd
|
43 |
|
|
output logic idu2exu_use_imm_o, // Instruction uses immediate
|
44 |
|
|
input logic exu2idu_rdy_i // EXU ready for new data
|
45 |
|
|
);
|
46 |
|
|
|
47 |
|
|
//-------------------------------------------------------------------------------
|
48 |
|
|
// Local parameters declaration
|
49 |
|
|
//-------------------------------------------------------------------------------
|
50 |
|
|
|
51 |
|
|
localparam [SCR1_GPR_FIELD_WIDTH-1:0] SCR1_MPRF_ZERO_ADDR = 5'd0;
|
52 |
|
|
localparam [SCR1_GPR_FIELD_WIDTH-1:0] SCR1_MPRF_RA_ADDR = 5'd1;
|
53 |
|
|
localparam [SCR1_GPR_FIELD_WIDTH-1:0] SCR1_MPRF_SP_ADDR = 5'd2;
|
54 |
|
|
|
55 |
|
|
//-------------------------------------------------------------------------------
|
56 |
|
|
// Local signals declaration
|
57 |
|
|
//-------------------------------------------------------------------------------
|
58 |
|
|
|
59 |
|
|
logic [`SCR1_IMEM_DWIDTH-1:0] instr;
|
60 |
|
|
type_scr1_instr_type_e instr_type;
|
61 |
|
|
type_scr1_rvi_opcode_e rvi_opcode;
|
62 |
|
|
logic rvi_illegal;
|
63 |
|
|
logic [2:0] funct3;
|
64 |
|
|
logic [6:0] funct7;
|
65 |
|
|
logic [11:0] funct12;
|
66 |
|
|
logic [4:0] shamt;
|
67 |
|
|
`ifdef SCR1_RVC_EXT
|
68 |
|
|
logic rvc_illegal;
|
69 |
|
|
`endif // SCR1_RVC_EXT
|
70 |
|
|
`ifdef SCR1_RVE_EXT
|
71 |
|
|
logic rve_illegal;
|
72 |
|
|
`endif // SCR1_RVE_EXT
|
73 |
|
|
|
74 |
|
|
//-------------------------------------------------------------------------------
|
75 |
|
|
// Instruction decoding
|
76 |
|
|
//-------------------------------------------------------------------------------
|
77 |
|
|
|
78 |
|
|
assign idu2ifu_rdy_o = exu2idu_rdy_i;
|
79 |
|
|
assign idu2exu_req_o = ifu2idu_vd_i;
|
80 |
|
|
assign instr = ifu2idu_instr_i;
|
81 |
|
|
|
82 |
|
|
// RVI / RVC
|
83 |
|
|
`ifdef YOSYS
|
84 |
|
|
assign instr_type = 2'(instr[1:0]);
|
85 |
|
|
`else
|
86 |
|
|
|
87 |
|
|
assign instr_type = type_scr1_instr_type_e'(instr[1:0]);
|
88 |
|
|
`endif
|
89 |
|
|
|
90 |
|
|
// RVI / RVC fields
|
91 |
|
|
`ifdef YOSYS
|
92 |
|
|
assign rvi_opcode = 5'(instr[6:2]); // RVI
|
93 |
|
|
`else
|
94 |
|
|
assign rvi_opcode = type_scr1_rvi_opcode_e'(instr[6:2]); // RVI
|
95 |
|
|
`endif
|
96 |
|
|
assign funct3 = (instr_type == SCR1_INSTR_RVI) ? instr[14:12] : instr[15:13]; // RVI / RVC
|
97 |
|
|
assign funct7 = instr[31:25]; // RVI
|
98 |
|
|
assign funct12 = instr[31:20]; // RVI (SYSTEM)
|
99 |
|
|
assign shamt = instr[24:20]; // RVI
|
100 |
|
|
|
101 |
|
|
// RV32I(MC) decode
|
102 |
|
|
always_comb begin
|
103 |
|
|
// Defaults
|
104 |
|
|
idu2exu_cmd_o.instr_rvc = 1'b0;
|
105 |
|
|
idu2exu_cmd_o.ialu_op = SCR1_IALU_OP_REG_REG;
|
106 |
|
|
idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_NONE;
|
107 |
|
|
idu2exu_cmd_o.sum2_op = SCR1_SUM2_OP_PC_IMM;
|
108 |
|
|
idu2exu_cmd_o.lsu_cmd = SCR1_LSU_CMD_NONE;
|
109 |
|
|
idu2exu_cmd_o.csr_op = SCR1_CSR_OP_REG;
|
110 |
|
|
idu2exu_cmd_o.csr_cmd = SCR1_CSR_CMD_NONE;
|
111 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_NONE;
|
112 |
|
|
idu2exu_cmd_o.jump_req = 1'b0;
|
113 |
|
|
idu2exu_cmd_o.branch_req = 1'b0;
|
114 |
|
|
idu2exu_cmd_o.mret_req = 1'b0;
|
115 |
|
|
idu2exu_cmd_o.fencei_req = 1'b0;
|
116 |
|
|
idu2exu_cmd_o.wfi_req = 1'b0;
|
117 |
|
|
idu2exu_cmd_o.rs1_addr = '0;
|
118 |
|
|
idu2exu_cmd_o.rs2_addr = '0;
|
119 |
|
|
idu2exu_cmd_o.rd_addr = '0;
|
120 |
|
|
idu2exu_cmd_o.imm = '0;
|
121 |
|
|
idu2exu_cmd_o.exc_req = 1'b0;
|
122 |
|
|
idu2exu_cmd_o.exc_code = SCR1_EXC_CODE_INSTR_MISALIGN;
|
123 |
|
|
|
124 |
|
|
// Clock gating
|
125 |
|
|
idu2exu_use_rs1_o = 1'b0;
|
126 |
|
|
idu2exu_use_rs2_o = 1'b0;
|
127 |
|
|
idu2exu_use_rd_o = 1'b0;
|
128 |
|
|
idu2exu_use_imm_o = 1'b0;
|
129 |
|
|
|
130 |
|
|
rvi_illegal = 1'b0;
|
131 |
|
|
`ifdef SCR1_RVE_EXT
|
132 |
|
|
rve_illegal = 1'b0;
|
133 |
|
|
`endif // SCR1_RVE_EXT
|
134 |
|
|
`ifdef SCR1_RVC_EXT
|
135 |
|
|
rvc_illegal = 1'b0;
|
136 |
|
|
`endif // SCR1_RVC_EXT
|
137 |
|
|
|
138 |
|
|
// Check for IMEM access fault
|
139 |
|
|
if (ifu2idu_imem_err_i) begin
|
140 |
|
|
idu2exu_cmd_o.exc_req = 1'b1;
|
141 |
|
|
idu2exu_cmd_o.exc_code = SCR1_EXC_CODE_INSTR_ACCESS_FAULT;
|
142 |
|
|
idu2exu_cmd_o.instr_rvc = ifu2idu_err_rvi_hi_i;
|
143 |
|
|
end else begin // no imem fault
|
144 |
|
|
case (instr_type)
|
145 |
|
|
SCR1_INSTR_RVI : begin
|
146 |
|
|
idu2exu_cmd_o.rs1_addr = instr[19:15];
|
147 |
|
|
idu2exu_cmd_o.rs2_addr = instr[24:20];
|
148 |
|
|
idu2exu_cmd_o.rd_addr = instr[11:7];
|
149 |
|
|
case (rvi_opcode)
|
150 |
|
|
SCR1_OPCODE_AUIPC : begin
|
151 |
|
|
idu2exu_use_rd_o = 1'b1;
|
152 |
|
|
idu2exu_use_imm_o = 1'b1;
|
153 |
|
|
idu2exu_cmd_o.sum2_op = SCR1_SUM2_OP_PC_IMM;
|
154 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_SUM2;
|
155 |
|
|
idu2exu_cmd_o.imm = {instr[31:12], 12'b0};
|
156 |
|
|
`ifdef SCR1_RVE_EXT
|
157 |
|
|
if (instr[11]) rve_illegal = 1'b1;
|
158 |
|
|
`endif // SCR1_RVE_EXT
|
159 |
|
|
end // SCR1_OPCODE_AUIPC
|
160 |
|
|
|
161 |
|
|
SCR1_OPCODE_LUI : begin
|
162 |
|
|
idu2exu_use_rd_o = 1'b1;
|
163 |
|
|
idu2exu_use_imm_o = 1'b1;
|
164 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_IMM;
|
165 |
|
|
idu2exu_cmd_o.imm = {instr[31:12], 12'b0};
|
166 |
|
|
`ifdef SCR1_RVE_EXT
|
167 |
|
|
if (instr[11]) rve_illegal = 1'b1;
|
168 |
|
|
`endif // SCR1_RVE_EXT
|
169 |
|
|
end // SCR1_OPCODE_LUI
|
170 |
|
|
|
171 |
|
|
SCR1_OPCODE_JAL : begin
|
172 |
|
|
idu2exu_use_rd_o = 1'b1;
|
173 |
|
|
idu2exu_use_imm_o = 1'b1;
|
174 |
|
|
idu2exu_cmd_o.sum2_op = SCR1_SUM2_OP_PC_IMM;
|
175 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_INC_PC;
|
176 |
|
|
idu2exu_cmd_o.jump_req = 1'b1;
|
177 |
|
|
idu2exu_cmd_o.imm = {{12{instr[31]}}, instr[19:12], instr[20], instr[30:21], 1'b0};
|
178 |
|
|
`ifdef SCR1_RVE_EXT
|
179 |
|
|
if (instr[11]) rve_illegal = 1'b1;
|
180 |
|
|
`endif // SCR1_RVE_EXT
|
181 |
|
|
end // SCR1_OPCODE_JAL
|
182 |
|
|
|
183 |
|
|
SCR1_OPCODE_LOAD : begin
|
184 |
|
|
idu2exu_use_rs1_o = 1'b1;
|
185 |
|
|
idu2exu_use_rd_o = 1'b1;
|
186 |
|
|
idu2exu_use_imm_o = 1'b1;
|
187 |
|
|
idu2exu_cmd_o.sum2_op = SCR1_SUM2_OP_REG_IMM;
|
188 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_LSU;
|
189 |
|
|
idu2exu_cmd_o.imm = {{21{instr[31]}}, instr[30:20]};
|
190 |
|
|
case (funct3)
|
191 |
|
|
3'b000 : idu2exu_cmd_o.lsu_cmd = SCR1_LSU_CMD_LB;
|
192 |
|
|
3'b001 : idu2exu_cmd_o.lsu_cmd = SCR1_LSU_CMD_LH;
|
193 |
|
|
3'b010 : idu2exu_cmd_o.lsu_cmd = SCR1_LSU_CMD_LW;
|
194 |
|
|
3'b100 : idu2exu_cmd_o.lsu_cmd = SCR1_LSU_CMD_LBU;
|
195 |
|
|
3'b101 : idu2exu_cmd_o.lsu_cmd = SCR1_LSU_CMD_LHU;
|
196 |
|
|
default : rvi_illegal = 1'b1;
|
197 |
|
|
endcase // funct3
|
198 |
|
|
`ifdef SCR1_RVE_EXT
|
199 |
|
|
if (instr[11] | instr[19]) rve_illegal = 1'b1;
|
200 |
|
|
`endif // SCR1_RVE_EXT
|
201 |
|
|
end // SCR1_OPCODE_LOAD
|
202 |
|
|
|
203 |
|
|
SCR1_OPCODE_STORE : begin
|
204 |
|
|
idu2exu_use_rs1_o = 1'b1;
|
205 |
|
|
idu2exu_use_rs2_o = 1'b1;
|
206 |
|
|
idu2exu_use_imm_o = 1'b1;
|
207 |
|
|
idu2exu_cmd_o.sum2_op = SCR1_SUM2_OP_REG_IMM;
|
208 |
|
|
idu2exu_cmd_o.imm = {{21{instr[31]}}, instr[30:25], instr[11:7]};
|
209 |
|
|
case (funct3)
|
210 |
|
|
3'b000 : idu2exu_cmd_o.lsu_cmd = SCR1_LSU_CMD_SB;
|
211 |
|
|
3'b001 : idu2exu_cmd_o.lsu_cmd = SCR1_LSU_CMD_SH;
|
212 |
|
|
3'b010 : idu2exu_cmd_o.lsu_cmd = SCR1_LSU_CMD_SW;
|
213 |
|
|
default : rvi_illegal = 1'b1;
|
214 |
|
|
endcase // funct3
|
215 |
|
|
`ifdef SCR1_RVE_EXT
|
216 |
|
|
if (instr[19] | instr[24]) rve_illegal = 1'b1;
|
217 |
|
|
`endif // SCR1_RVE_EXT
|
218 |
|
|
end // SCR1_OPCODE_STORE
|
219 |
|
|
|
220 |
|
|
SCR1_OPCODE_OP : begin
|
221 |
|
|
idu2exu_use_rs1_o = 1'b1;
|
222 |
|
|
idu2exu_use_rs2_o = 1'b1;
|
223 |
|
|
idu2exu_use_rd_o = 1'b1;
|
224 |
|
|
idu2exu_cmd_o.ialu_op = SCR1_IALU_OP_REG_REG;
|
225 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_IALU;
|
226 |
|
|
case (funct7)
|
227 |
|
|
7'b0000000 : begin
|
228 |
|
|
case (funct3)
|
229 |
|
|
3'b000 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_ADD;
|
230 |
|
|
3'b001 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SLL;
|
231 |
|
|
3'b010 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SUB_LT;
|
232 |
|
|
3'b011 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SUB_LTU;
|
233 |
|
|
3'b100 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_XOR;
|
234 |
|
|
3'b101 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SRL;
|
235 |
|
|
3'b110 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_OR;
|
236 |
|
|
3'b111 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_AND;
|
237 |
|
|
endcase // funct3
|
238 |
|
|
end // 7'b0000000
|
239 |
|
|
|
240 |
|
|
7'b0100000 : begin
|
241 |
|
|
case (funct3)
|
242 |
|
|
3'b000 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SUB;
|
243 |
|
|
3'b101 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SRA;
|
244 |
|
|
default : rvi_illegal = 1'b1;
|
245 |
|
|
endcase // funct3
|
246 |
|
|
end // 7'b0100000
|
247 |
|
|
`ifdef SCR1_RVM_EXT
|
248 |
|
|
7'b0000001 : begin
|
249 |
|
|
case (funct3)
|
250 |
|
|
3'b000 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_MUL;
|
251 |
|
|
3'b001 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_MULH;
|
252 |
|
|
3'b010 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_MULHSU;
|
253 |
|
|
3'b011 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_MULHU;
|
254 |
|
|
3'b100 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_DIV;
|
255 |
|
|
3'b101 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_DIVU;
|
256 |
|
|
3'b110 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_REM;
|
257 |
|
|
3'b111 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_REMU;
|
258 |
|
|
endcase // funct3
|
259 |
|
|
end // 7'b0000001
|
260 |
|
|
`endif // SCR1_RVM_EXT
|
261 |
|
|
default : rvi_illegal = 1'b1;
|
262 |
|
|
endcase // funct7
|
263 |
|
|
`ifdef SCR1_RVE_EXT
|
264 |
|
|
if (instr[11] | instr[19] | instr[24]) rve_illegal = 1'b1;
|
265 |
|
|
`endif // SCR1_RVE_EXT
|
266 |
|
|
end // SCR1_OPCODE_OP
|
267 |
|
|
|
268 |
|
|
SCR1_OPCODE_OP_IMM : begin
|
269 |
|
|
idu2exu_use_rs1_o = 1'b1;
|
270 |
|
|
idu2exu_use_rd_o = 1'b1;
|
271 |
|
|
idu2exu_use_imm_o = 1'b1;
|
272 |
|
|
idu2exu_cmd_o.imm = {{21{instr[31]}}, instr[30:20]};
|
273 |
|
|
idu2exu_cmd_o.ialu_op = SCR1_IALU_OP_REG_IMM;
|
274 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_IALU;
|
275 |
|
|
case (funct3)
|
276 |
|
|
3'b000 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_ADD; // ADDI
|
277 |
|
|
3'b010 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SUB_LT; // SLTI
|
278 |
|
|
3'b011 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SUB_LTU; // SLTIU
|
279 |
|
|
3'b100 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_XOR; // XORI
|
280 |
|
|
3'b110 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_OR; // ORI
|
281 |
|
|
3'b111 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_AND; // ANDI
|
282 |
|
|
3'b001 : begin
|
283 |
|
|
case (funct7)
|
284 |
|
|
7'b0000000 : begin
|
285 |
|
|
// SLLI
|
286 |
|
|
idu2exu_cmd_o.imm = `SCR1_XLEN'(shamt); // zero-extend
|
287 |
|
|
idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SLL;
|
288 |
|
|
end
|
289 |
|
|
default : rvi_illegal = 1'b1;
|
290 |
|
|
endcase // funct7
|
291 |
|
|
end
|
292 |
|
|
3'b101 : begin
|
293 |
|
|
case (funct7)
|
294 |
|
|
7'b0000000 : begin
|
295 |
|
|
// SRLI
|
296 |
|
|
idu2exu_cmd_o.imm = `SCR1_XLEN'(shamt); // zero-extend
|
297 |
|
|
idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SRL;
|
298 |
|
|
end
|
299 |
|
|
7'b0100000 : begin
|
300 |
|
|
// SRAI
|
301 |
|
|
idu2exu_cmd_o.imm = `SCR1_XLEN'(shamt); // zero-extend
|
302 |
|
|
idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SRA;
|
303 |
|
|
end
|
304 |
|
|
default : rvi_illegal = 1'b1;
|
305 |
|
|
endcase // funct7
|
306 |
|
|
end
|
307 |
|
|
endcase // funct3
|
308 |
|
|
`ifdef SCR1_RVE_EXT
|
309 |
|
|
if (instr[11] | instr[19]) rve_illegal = 1'b1;
|
310 |
|
|
`endif // SCR1_RVE_EXT
|
311 |
|
|
end // SCR1_OPCODE_OP_IMM
|
312 |
|
|
|
313 |
|
|
SCR1_OPCODE_MISC_MEM : begin
|
314 |
|
|
case (funct3)
|
315 |
|
|
3'b000 : begin
|
316 |
|
|
if (~|{instr[31:28], instr[19:15], instr[11:7]}) begin
|
317 |
|
|
// FENCE = NOP
|
318 |
|
|
end
|
319 |
|
|
else rvi_illegal = 1'b1;
|
320 |
|
|
end
|
321 |
|
|
3'b001 : begin
|
322 |
|
|
if (~|{instr[31:15], instr[11:7]}) begin
|
323 |
|
|
// FENCE.I
|
324 |
|
|
idu2exu_cmd_o.fencei_req = 1'b1;
|
325 |
|
|
end
|
326 |
|
|
else rvi_illegal = 1'b1;
|
327 |
|
|
end
|
328 |
|
|
default : rvi_illegal = 1'b1;
|
329 |
|
|
endcase // funct3
|
330 |
|
|
end // SCR1_OPCODE_MISC_MEM
|
331 |
|
|
|
332 |
|
|
SCR1_OPCODE_BRANCH : begin
|
333 |
|
|
idu2exu_use_rs1_o = 1'b1;
|
334 |
|
|
idu2exu_use_rs2_o = 1'b1;
|
335 |
|
|
idu2exu_use_imm_o = 1'b1;
|
336 |
|
|
idu2exu_cmd_o.imm = {{20{instr[31]}}, instr[7], instr[30:25], instr[11:8], 1'b0};
|
337 |
|
|
idu2exu_cmd_o.branch_req = 1'b1;
|
338 |
|
|
idu2exu_cmd_o.sum2_op = SCR1_SUM2_OP_PC_IMM;
|
339 |
|
|
idu2exu_cmd_o.ialu_op = SCR1_IALU_OP_REG_REG;
|
340 |
|
|
case (funct3)
|
341 |
|
|
3'b000 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SUB_EQ;
|
342 |
|
|
3'b001 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SUB_NE;
|
343 |
|
|
3'b100 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SUB_LT;
|
344 |
|
|
3'b101 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SUB_GE;
|
345 |
|
|
3'b110 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SUB_LTU;
|
346 |
|
|
3'b111 : idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SUB_GEU;
|
347 |
|
|
default : rvi_illegal = 1'b1;
|
348 |
|
|
endcase // funct3
|
349 |
|
|
`ifdef SCR1_RVE_EXT
|
350 |
|
|
if (instr[19] | instr[24]) rve_illegal = 1'b1;
|
351 |
|
|
`endif // SCR1_RVE_EXT
|
352 |
|
|
end // SCR1_OPCODE_BRANCH
|
353 |
|
|
|
354 |
|
|
SCR1_OPCODE_JALR : begin
|
355 |
|
|
idu2exu_use_rs1_o = 1'b1;
|
356 |
|
|
idu2exu_use_rd_o = 1'b1;
|
357 |
|
|
idu2exu_use_imm_o = 1'b1;
|
358 |
|
|
case (funct3)
|
359 |
|
|
3'b000 : begin
|
360 |
|
|
// JALR
|
361 |
|
|
idu2exu_cmd_o.sum2_op = SCR1_SUM2_OP_REG_IMM;
|
362 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_INC_PC;
|
363 |
|
|
idu2exu_cmd_o.jump_req = 1'b1;
|
364 |
|
|
idu2exu_cmd_o.imm = {{21{instr[31]}}, instr[30:20]};
|
365 |
|
|
end
|
366 |
|
|
default : rvi_illegal = 1'b1;
|
367 |
|
|
endcase
|
368 |
|
|
`ifdef SCR1_RVE_EXT
|
369 |
|
|
if (instr[11] | instr[19]) rve_illegal = 1'b1;
|
370 |
|
|
`endif // SCR1_RVE_EXT
|
371 |
|
|
end // SCR1_OPCODE_JALR
|
372 |
|
|
|
373 |
|
|
SCR1_OPCODE_SYSTEM : begin
|
374 |
|
|
idu2exu_use_rd_o = 1'b1;
|
375 |
|
|
idu2exu_use_imm_o = 1'b1;
|
376 |
|
|
idu2exu_cmd_o.imm = `SCR1_XLEN'({funct3, instr[31:20]}); // {funct3, CSR address}
|
377 |
|
|
case (funct3)
|
378 |
|
|
3'b000 : begin
|
379 |
|
|
idu2exu_use_rd_o = 1'b0;
|
380 |
|
|
idu2exu_use_imm_o = 1'b0;
|
381 |
|
|
case ({instr[19:15], instr[11:7]})
|
382 |
|
|
10'd0 : begin
|
383 |
|
|
case (funct12)
|
384 |
|
|
12'h000 : begin
|
385 |
|
|
// ECALL
|
386 |
|
|
idu2exu_cmd_o.exc_req = 1'b1;
|
387 |
|
|
idu2exu_cmd_o.exc_code = SCR1_EXC_CODE_ECALL_M;
|
388 |
|
|
end
|
389 |
|
|
12'h001 : begin
|
390 |
|
|
// EBREAK
|
391 |
|
|
idu2exu_cmd_o.exc_req = 1'b1;
|
392 |
|
|
idu2exu_cmd_o.exc_code = SCR1_EXC_CODE_BREAKPOINT;
|
393 |
|
|
end
|
394 |
|
|
12'h302 : begin
|
395 |
|
|
// MRET
|
396 |
|
|
idu2exu_cmd_o.mret_req = 1'b1;
|
397 |
|
|
end
|
398 |
|
|
12'h105 : begin
|
399 |
|
|
// WFI
|
400 |
|
|
idu2exu_cmd_o.wfi_req = 1'b1;
|
401 |
|
|
end
|
402 |
|
|
default : rvi_illegal = 1'b1;
|
403 |
|
|
endcase // funct12
|
404 |
|
|
end
|
405 |
|
|
default : rvi_illegal = 1'b1;
|
406 |
|
|
endcase // {instr[19:15], instr[11:7]}
|
407 |
|
|
end
|
408 |
|
|
3'b001 : begin
|
409 |
|
|
// CSRRW
|
410 |
|
|
idu2exu_use_rs1_o = 1'b1;
|
411 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_CSR;
|
412 |
|
|
idu2exu_cmd_o.csr_cmd = SCR1_CSR_CMD_WRITE;
|
413 |
|
|
idu2exu_cmd_o.csr_op = SCR1_CSR_OP_REG;
|
414 |
|
|
`ifdef SCR1_RVE_EXT
|
415 |
|
|
if (instr[11] | instr[19]) rve_illegal = 1'b1;
|
416 |
|
|
`endif // SCR1_RVE_EXT
|
417 |
|
|
end
|
418 |
|
|
3'b010 : begin
|
419 |
|
|
// CSRRS
|
420 |
|
|
idu2exu_use_rs1_o = 1'b1;
|
421 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_CSR;
|
422 |
|
|
idu2exu_cmd_o.csr_cmd = SCR1_CSR_CMD_SET;
|
423 |
|
|
idu2exu_cmd_o.csr_op = SCR1_CSR_OP_REG;
|
424 |
|
|
`ifdef SCR1_RVE_EXT
|
425 |
|
|
if (instr[11] | instr[19]) rve_illegal = 1'b1;
|
426 |
|
|
`endif // SCR1_RVE_EXT
|
427 |
|
|
end
|
428 |
|
|
3'b011 : begin
|
429 |
|
|
// CSRRC
|
430 |
|
|
idu2exu_use_rs1_o = 1'b1;
|
431 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_CSR;
|
432 |
|
|
idu2exu_cmd_o.csr_cmd = SCR1_CSR_CMD_CLEAR;
|
433 |
|
|
idu2exu_cmd_o.csr_op = SCR1_CSR_OP_REG;
|
434 |
|
|
`ifdef SCR1_RVE_EXT
|
435 |
|
|
if (instr[11] | instr[19]) rve_illegal = 1'b1;
|
436 |
|
|
`endif // SCR1_RVE_EXT
|
437 |
|
|
end
|
438 |
|
|
3'b101 : begin
|
439 |
|
|
// CSRRWI
|
440 |
|
|
idu2exu_use_rs1_o = 1'b1; // zimm
|
441 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_CSR;
|
442 |
|
|
idu2exu_cmd_o.csr_cmd = SCR1_CSR_CMD_WRITE;
|
443 |
|
|
idu2exu_cmd_o.csr_op = SCR1_CSR_OP_IMM;
|
444 |
|
|
`ifdef SCR1_RVE_EXT
|
445 |
|
|
if (instr[11]) rve_illegal = 1'b1;
|
446 |
|
|
`endif // SCR1_RVE_EXT
|
447 |
|
|
end
|
448 |
|
|
3'b110 : begin
|
449 |
|
|
// CSRRSI
|
450 |
|
|
idu2exu_use_rs1_o = 1'b1; // zimm
|
451 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_CSR;
|
452 |
|
|
idu2exu_cmd_o.csr_cmd = SCR1_CSR_CMD_SET;
|
453 |
|
|
idu2exu_cmd_o.csr_op = SCR1_CSR_OP_IMM;
|
454 |
|
|
`ifdef SCR1_RVE_EXT
|
455 |
|
|
if (instr[11]) rve_illegal = 1'b1;
|
456 |
|
|
`endif // SCR1_RVE_EXT
|
457 |
|
|
end
|
458 |
|
|
3'b111 : begin
|
459 |
|
|
// CSRRCI
|
460 |
|
|
idu2exu_use_rs1_o = 1'b1; // zimm
|
461 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_CSR;
|
462 |
|
|
idu2exu_cmd_o.csr_cmd = SCR1_CSR_CMD_CLEAR;
|
463 |
|
|
idu2exu_cmd_o.csr_op = SCR1_CSR_OP_IMM;
|
464 |
|
|
`ifdef SCR1_RVE_EXT
|
465 |
|
|
if (instr[11]) rve_illegal = 1'b1;
|
466 |
|
|
`endif // SCR1_RVE_EXT
|
467 |
|
|
end
|
468 |
|
|
default : rvi_illegal = 1'b1;
|
469 |
|
|
endcase // funct3
|
470 |
|
|
end // SCR1_OPCODE_SYSTEM
|
471 |
|
|
|
472 |
|
|
default : begin
|
473 |
|
|
rvi_illegal = 1'b1;
|
474 |
|
|
end
|
475 |
|
|
endcase // rvi_opcode
|
476 |
|
|
end // SCR1_INSTR_RVI
|
477 |
|
|
|
478 |
|
|
`ifdef SCR1_RVC_EXT
|
479 |
|
|
|
480 |
|
|
// Quadrant 0
|
481 |
|
|
SCR1_INSTR_RVC0 : begin
|
482 |
|
|
idu2exu_cmd_o.instr_rvc = 1'b1;
|
483 |
|
|
idu2exu_use_rs1_o = 1'b1;
|
484 |
|
|
idu2exu_use_imm_o = 1'b1;
|
485 |
|
|
case (funct3)
|
486 |
|
|
3'b000 : begin
|
487 |
|
|
if (~|instr[12:5]) rvc_illegal = 1'b1;
|
488 |
|
|
// C.ADDI4SPN
|
489 |
|
|
idu2exu_use_rd_o = 1'b1;
|
490 |
|
|
idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_ADD;
|
491 |
|
|
idu2exu_cmd_o.ialu_op = SCR1_IALU_OP_REG_IMM;
|
492 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_IALU;
|
493 |
|
|
idu2exu_cmd_o.rs1_addr = SCR1_MPRF_SP_ADDR;
|
494 |
|
|
idu2exu_cmd_o.rd_addr = {2'b01, instr[4:2]};
|
495 |
|
|
idu2exu_cmd_o.imm = {22'd0, instr[10:7], instr[12:11], instr[5], instr[6], 2'b00};
|
496 |
|
|
end
|
497 |
|
|
3'b010 : begin
|
498 |
|
|
// C.LW
|
499 |
|
|
idu2exu_use_rd_o = 1'b1;
|
500 |
|
|
idu2exu_cmd_o.sum2_op = SCR1_SUM2_OP_REG_IMM;
|
501 |
|
|
idu2exu_cmd_o.lsu_cmd = SCR1_LSU_CMD_LW;
|
502 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_LSU;
|
503 |
|
|
idu2exu_cmd_o.rs1_addr = {2'b01, instr[9:7]};
|
504 |
|
|
idu2exu_cmd_o.rd_addr = {2'b01, instr[4:2]};
|
505 |
|
|
idu2exu_cmd_o.imm = {25'd0, instr[5], instr[12:10], instr[6], 2'b00};
|
506 |
|
|
end
|
507 |
|
|
3'b110 : begin
|
508 |
|
|
// C.SW
|
509 |
|
|
idu2exu_use_rs2_o = 1'b1;
|
510 |
|
|
idu2exu_cmd_o.sum2_op = SCR1_SUM2_OP_REG_IMM;
|
511 |
|
|
idu2exu_cmd_o.lsu_cmd = SCR1_LSU_CMD_SW;
|
512 |
|
|
idu2exu_cmd_o.rs1_addr = {2'b01, instr[9:7]};
|
513 |
|
|
idu2exu_cmd_o.rs2_addr = {2'b01, instr[4:2]};
|
514 |
|
|
idu2exu_cmd_o.imm = {25'd0, instr[5], instr[12:10], instr[6], 2'b00};
|
515 |
|
|
end
|
516 |
|
|
default : begin
|
517 |
|
|
rvc_illegal = 1'b1;
|
518 |
|
|
end
|
519 |
|
|
endcase // funct3
|
520 |
|
|
end // Quadrant 0
|
521 |
|
|
|
522 |
|
|
// Quadrant 1
|
523 |
|
|
SCR1_INSTR_RVC1 : begin
|
524 |
|
|
idu2exu_cmd_o.instr_rvc = 1'b1;
|
525 |
|
|
idu2exu_use_rd_o = 1'b1;
|
526 |
|
|
idu2exu_use_imm_o = 1'b1;
|
527 |
|
|
case (funct3)
|
528 |
|
|
3'b000 : begin
|
529 |
|
|
// C.ADDI / C.NOP
|
530 |
|
|
idu2exu_use_rs1_o = 1'b1;
|
531 |
|
|
idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_ADD;
|
532 |
|
|
idu2exu_cmd_o.ialu_op = SCR1_IALU_OP_REG_IMM;
|
533 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_IALU;
|
534 |
|
|
idu2exu_cmd_o.rs1_addr = instr[11:7];
|
535 |
|
|
idu2exu_cmd_o.rd_addr = instr[11:7];
|
536 |
|
|
idu2exu_cmd_o.imm = {{27{instr[12]}}, instr[6:2]};
|
537 |
|
|
`ifdef SCR1_RVE_EXT
|
538 |
|
|
if (instr[11]) rve_illegal = 1'b1;
|
539 |
|
|
`endif // SCR1_RVE_EXT
|
540 |
|
|
end
|
541 |
|
|
3'b001 : begin
|
542 |
|
|
// C.JAL
|
543 |
|
|
idu2exu_cmd_o.sum2_op = SCR1_SUM2_OP_PC_IMM;
|
544 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_INC_PC;
|
545 |
|
|
idu2exu_cmd_o.jump_req = 1'b1;
|
546 |
|
|
idu2exu_cmd_o.rd_addr = SCR1_MPRF_RA_ADDR;
|
547 |
|
|
idu2exu_cmd_o.imm = {{21{instr[12]}}, instr[8], instr[10:9], instr[6], instr[7], instr[2], instr[11], instr[5:3], 1'b0};
|
548 |
|
|
end
|
549 |
|
|
3'b010 : begin
|
550 |
|
|
// C.LI
|
551 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_IMM;
|
552 |
|
|
idu2exu_cmd_o.rd_addr = instr[11:7];
|
553 |
|
|
idu2exu_cmd_o.imm = {{27{instr[12]}}, instr[6:2]};
|
554 |
|
|
`ifdef SCR1_RVE_EXT
|
555 |
|
|
if (instr[11]) rve_illegal = 1'b1;
|
556 |
|
|
`endif // SCR1_RVE_EXT
|
557 |
|
|
end
|
558 |
|
|
3'b011 : begin
|
559 |
|
|
if (~|{instr[12], instr[6:2]}) rvc_illegal = 1'b1;
|
560 |
|
|
if (instr[11:7] == SCR1_MPRF_SP_ADDR) begin
|
561 |
|
|
// C.ADDI16SP
|
562 |
|
|
idu2exu_use_rs1_o = 1'b1;
|
563 |
|
|
idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_ADD;
|
564 |
|
|
idu2exu_cmd_o.ialu_op = SCR1_IALU_OP_REG_IMM;
|
565 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_IALU;
|
566 |
|
|
idu2exu_cmd_o.rs1_addr = SCR1_MPRF_SP_ADDR;
|
567 |
|
|
idu2exu_cmd_o.rd_addr = SCR1_MPRF_SP_ADDR;
|
568 |
|
|
idu2exu_cmd_o.imm = {{23{instr[12]}}, instr[4:3], instr[5], instr[2], instr[6], 4'd0};
|
569 |
|
|
end else begin
|
570 |
|
|
// C.LUI
|
571 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_IMM;
|
572 |
|
|
idu2exu_cmd_o.rd_addr = instr[11:7];
|
573 |
|
|
idu2exu_cmd_o.imm = {{15{instr[12]}}, instr[6:2], 12'd0};
|
574 |
|
|
`ifdef SCR1_RVE_EXT
|
575 |
|
|
if (instr[11]) rve_illegal = 1'b1;
|
576 |
|
|
`endif // SCR1_RVE_EXT
|
577 |
|
|
end
|
578 |
|
|
end
|
579 |
|
|
3'b100 : begin
|
580 |
|
|
idu2exu_cmd_o.rs1_addr = {2'b01, instr[9:7]};
|
581 |
|
|
idu2exu_cmd_o.rd_addr = {2'b01, instr[9:7]};
|
582 |
|
|
idu2exu_cmd_o.rs2_addr = {2'b01, instr[4:2]};
|
583 |
|
|
idu2exu_use_rs1_o = 1'b1;
|
584 |
|
|
idu2exu_use_rd_o = 1'b1;
|
585 |
|
|
case (instr[11:10])
|
586 |
|
|
2'b00 : begin
|
587 |
|
|
if (instr[12]) rvc_illegal = 1'b1;
|
588 |
|
|
// C.SRLI
|
589 |
|
|
idu2exu_use_imm_o = 1'b1;
|
590 |
|
|
idu2exu_cmd_o.imm = {27'd0, instr[6:2]};
|
591 |
|
|
idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SRL;
|
592 |
|
|
idu2exu_cmd_o.ialu_op = SCR1_IALU_OP_REG_IMM;
|
593 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_IALU;
|
594 |
|
|
end
|
595 |
|
|
2'b01 : begin
|
596 |
|
|
if (instr[12]) rvc_illegal = 1'b1;
|
597 |
|
|
// C.SRAI
|
598 |
|
|
idu2exu_use_imm_o = 1'b1;
|
599 |
|
|
idu2exu_cmd_o.imm = {27'd0, instr[6:2]};
|
600 |
|
|
idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SRA;
|
601 |
|
|
idu2exu_cmd_o.ialu_op = SCR1_IALU_OP_REG_IMM;
|
602 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_IALU;
|
603 |
|
|
end
|
604 |
|
|
2'b10 : begin
|
605 |
|
|
// C.ANDI
|
606 |
|
|
idu2exu_use_imm_o = 1'b1;
|
607 |
|
|
idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_AND;
|
608 |
|
|
idu2exu_cmd_o.ialu_op = SCR1_IALU_OP_REG_IMM;
|
609 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_IALU;
|
610 |
|
|
idu2exu_cmd_o.imm = {{27{instr[12]}}, instr[6:2]};
|
611 |
|
|
end
|
612 |
|
|
2'b11 : begin
|
613 |
|
|
idu2exu_use_rs2_o = 1'b1;
|
614 |
|
|
case ({instr[12], instr[6:5]})
|
615 |
|
|
3'b000 : begin
|
616 |
|
|
// C.SUB
|
617 |
|
|
idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SUB;
|
618 |
|
|
idu2exu_cmd_o.ialu_op = SCR1_IALU_OP_REG_REG;
|
619 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_IALU;
|
620 |
|
|
end
|
621 |
|
|
3'b001 : begin
|
622 |
|
|
// C.XOR
|
623 |
|
|
idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_XOR;
|
624 |
|
|
idu2exu_cmd_o.ialu_op = SCR1_IALU_OP_REG_REG;
|
625 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_IALU;
|
626 |
|
|
end
|
627 |
|
|
3'b010 : begin
|
628 |
|
|
// C.OR
|
629 |
|
|
idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_OR;
|
630 |
|
|
idu2exu_cmd_o.ialu_op = SCR1_IALU_OP_REG_REG;
|
631 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_IALU;
|
632 |
|
|
end
|
633 |
|
|
3'b011 : begin
|
634 |
|
|
// C.AND
|
635 |
|
|
idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_AND;
|
636 |
|
|
idu2exu_cmd_o.ialu_op = SCR1_IALU_OP_REG_REG;
|
637 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_IALU;
|
638 |
|
|
end
|
639 |
|
|
default : begin
|
640 |
|
|
rvc_illegal = 1'b1;
|
641 |
|
|
end
|
642 |
|
|
endcase // {instr[12], instr[6:5]}
|
643 |
|
|
end
|
644 |
|
|
endcase // instr[11:10]
|
645 |
|
|
end // funct3 == 3'b100
|
646 |
|
|
3'b101 : begin
|
647 |
|
|
// C.J
|
648 |
|
|
idu2exu_use_imm_o = 1'b1;
|
649 |
|
|
idu2exu_cmd_o.sum2_op = SCR1_SUM2_OP_PC_IMM;
|
650 |
|
|
idu2exu_cmd_o.jump_req = 1'b1;
|
651 |
|
|
idu2exu_cmd_o.imm = {{21{instr[12]}}, instr[8], instr[10:9], instr[6], instr[7], instr[2], instr[11], instr[5:3], 1'b0};
|
652 |
|
|
end
|
653 |
|
|
3'b110 : begin
|
654 |
|
|
// C.BEQZ
|
655 |
|
|
idu2exu_use_rs1_o = 1'b1;
|
656 |
|
|
idu2exu_use_rs2_o = 1'b1;
|
657 |
|
|
idu2exu_use_imm_o = 1'b1;
|
658 |
|
|
idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SUB_EQ;
|
659 |
|
|
idu2exu_cmd_o.ialu_op = SCR1_IALU_OP_REG_REG;
|
660 |
|
|
idu2exu_cmd_o.sum2_op = SCR1_SUM2_OP_PC_IMM;
|
661 |
|
|
idu2exu_cmd_o.branch_req = 1'b1;
|
662 |
|
|
idu2exu_cmd_o.rs1_addr = {2'b01, instr[9:7]};
|
663 |
|
|
idu2exu_cmd_o.rs2_addr = SCR1_MPRF_ZERO_ADDR;
|
664 |
|
|
idu2exu_cmd_o.imm = {{24{instr[12]}}, instr[6:5], instr[2], instr[11:10], instr[4:3], 1'b0};
|
665 |
|
|
end
|
666 |
|
|
3'b111 : begin
|
667 |
|
|
// C.BNEZ
|
668 |
|
|
idu2exu_use_rs1_o = 1'b1;
|
669 |
|
|
idu2exu_use_rs2_o = 1'b1;
|
670 |
|
|
idu2exu_use_imm_o = 1'b1;
|
671 |
|
|
idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SUB_NE;
|
672 |
|
|
idu2exu_cmd_o.ialu_op = SCR1_IALU_OP_REG_REG;
|
673 |
|
|
idu2exu_cmd_o.sum2_op = SCR1_SUM2_OP_PC_IMM;
|
674 |
|
|
idu2exu_cmd_o.branch_req = 1'b1;
|
675 |
|
|
idu2exu_cmd_o.rs1_addr = {2'b01, instr[9:7]};
|
676 |
|
|
idu2exu_cmd_o.rs2_addr = SCR1_MPRF_ZERO_ADDR;
|
677 |
|
|
idu2exu_cmd_o.imm = {{24{instr[12]}}, instr[6:5], instr[2], instr[11:10], instr[4:3], 1'b0};
|
678 |
|
|
end
|
679 |
|
|
endcase // funct3
|
680 |
|
|
end // Quadrant 1
|
681 |
|
|
|
682 |
|
|
// Quadrant 2
|
683 |
|
|
SCR1_INSTR_RVC2 : begin
|
684 |
|
|
idu2exu_cmd_o.instr_rvc = 1'b1;
|
685 |
|
|
idu2exu_use_rs1_o = 1'b1;
|
686 |
|
|
case (funct3)
|
687 |
|
|
3'b000 : begin
|
688 |
|
|
if (instr[12]) rvc_illegal = 1'b1;
|
689 |
|
|
// C.SLLI
|
690 |
|
|
idu2exu_use_rd_o = 1'b1;
|
691 |
|
|
idu2exu_use_imm_o = 1'b1;
|
692 |
|
|
idu2exu_cmd_o.rs1_addr = instr[11:7];
|
693 |
|
|
idu2exu_cmd_o.rd_addr = instr[11:7];
|
694 |
|
|
idu2exu_cmd_o.imm = {27'd0, instr[6:2]};
|
695 |
|
|
idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_SLL;
|
696 |
|
|
idu2exu_cmd_o.ialu_op = SCR1_IALU_OP_REG_IMM;
|
697 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_IALU;
|
698 |
|
|
`ifdef SCR1_RVE_EXT
|
699 |
|
|
if (instr[11]) rve_illegal = 1'b1;
|
700 |
|
|
`endif // SCR1_RVE_EXT
|
701 |
|
|
end
|
702 |
|
|
3'b010 : begin
|
703 |
|
|
if (~|instr[11:7]) rvc_illegal = 1'b1;
|
704 |
|
|
// C.LWSP
|
705 |
|
|
idu2exu_use_rd_o = 1'b1;
|
706 |
|
|
idu2exu_use_imm_o = 1'b1;
|
707 |
|
|
idu2exu_cmd_o.sum2_op = SCR1_SUM2_OP_REG_IMM;
|
708 |
|
|
idu2exu_cmd_o.lsu_cmd = SCR1_LSU_CMD_LW;
|
709 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_LSU;
|
710 |
|
|
idu2exu_cmd_o.rs1_addr = SCR1_MPRF_SP_ADDR;
|
711 |
|
|
idu2exu_cmd_o.rd_addr = instr[11:7];
|
712 |
|
|
idu2exu_cmd_o.imm = {24'd0, instr[3:2], instr[12], instr[6:4], 2'b00};
|
713 |
|
|
`ifdef SCR1_RVE_EXT
|
714 |
|
|
if (instr[11]) rve_illegal = 1'b1;
|
715 |
|
|
`endif // SCR1_RVE_EXT
|
716 |
|
|
end
|
717 |
|
|
3'b100 : begin
|
718 |
|
|
if (~instr[12]) begin
|
719 |
|
|
if (|instr[6:2]) begin
|
720 |
|
|
// C.MV
|
721 |
|
|
idu2exu_use_rs2_o = 1'b1;
|
722 |
|
|
idu2exu_use_rd_o = 1'b1;
|
723 |
|
|
idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_ADD;
|
724 |
|
|
idu2exu_cmd_o.ialu_op = SCR1_IALU_OP_REG_REG;
|
725 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_IALU;
|
726 |
|
|
idu2exu_cmd_o.rs1_addr = SCR1_MPRF_ZERO_ADDR;
|
727 |
|
|
idu2exu_cmd_o.rs2_addr = instr[6:2];
|
728 |
|
|
idu2exu_cmd_o.rd_addr = instr[11:7];
|
729 |
|
|
`ifdef SCR1_RVE_EXT
|
730 |
|
|
if (instr[11]|instr[6]) rve_illegal = 1'b1;
|
731 |
|
|
`endif // SCR1_RVE_EXT
|
732 |
|
|
end else begin
|
733 |
|
|
if (~|instr[11:7]) rvc_illegal = 1'b1;
|
734 |
|
|
// C.JR
|
735 |
|
|
idu2exu_use_imm_o = 1'b1;
|
736 |
|
|
idu2exu_cmd_o.sum2_op = SCR1_SUM2_OP_REG_IMM;
|
737 |
|
|
idu2exu_cmd_o.jump_req = 1'b1;
|
738 |
|
|
idu2exu_cmd_o.rs1_addr = instr[11:7];
|
739 |
|
|
idu2exu_cmd_o.imm = 0;
|
740 |
|
|
`ifdef SCR1_RVE_EXT
|
741 |
|
|
if (instr[11]) rve_illegal = 1'b1;
|
742 |
|
|
`endif // SCR1_RVE_EXT
|
743 |
|
|
end
|
744 |
|
|
end else begin // instr[12] == 1
|
745 |
|
|
if (~|instr[11:2]) begin
|
746 |
|
|
// C.EBREAK
|
747 |
|
|
idu2exu_cmd_o.exc_req = 1'b1;
|
748 |
|
|
idu2exu_cmd_o.exc_code = SCR1_EXC_CODE_BREAKPOINT;
|
749 |
|
|
end else if (~|instr[6:2]) begin
|
750 |
|
|
// C.JALR
|
751 |
|
|
idu2exu_use_rs1_o = 1'b1;
|
752 |
|
|
idu2exu_use_rd_o = 1'b1;
|
753 |
|
|
idu2exu_use_imm_o = 1'b1;
|
754 |
|
|
idu2exu_cmd_o.sum2_op = SCR1_SUM2_OP_REG_IMM;
|
755 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_INC_PC;
|
756 |
|
|
idu2exu_cmd_o.jump_req = 1'b1;
|
757 |
|
|
idu2exu_cmd_o.rs1_addr = instr[11:7];
|
758 |
|
|
idu2exu_cmd_o.rd_addr = SCR1_MPRF_RA_ADDR;
|
759 |
|
|
idu2exu_cmd_o.imm = 0;
|
760 |
|
|
`ifdef SCR1_RVE_EXT
|
761 |
|
|
if (instr[11]) rve_illegal = 1'b1;
|
762 |
|
|
`endif // SCR1_RVE_EXT
|
763 |
|
|
end else begin
|
764 |
|
|
// C.ADD
|
765 |
|
|
idu2exu_use_rs1_o = 1'b1;
|
766 |
|
|
idu2exu_use_rs2_o = 1'b1;
|
767 |
|
|
idu2exu_use_rd_o = 1'b1;
|
768 |
|
|
idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_ADD;
|
769 |
|
|
idu2exu_cmd_o.ialu_op = SCR1_IALU_OP_REG_REG;
|
770 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_IALU;
|
771 |
|
|
idu2exu_cmd_o.rs1_addr = instr[11:7];
|
772 |
|
|
idu2exu_cmd_o.rs2_addr = instr[6:2];
|
773 |
|
|
idu2exu_cmd_o.rd_addr = instr[11:7];
|
774 |
|
|
`ifdef SCR1_RVE_EXT
|
775 |
|
|
if (instr[11]|instr[6]) rve_illegal = 1'b1;
|
776 |
|
|
`endif // SCR1_RVE_EXT
|
777 |
|
|
end
|
778 |
|
|
end // instr[12] == 1
|
779 |
|
|
end
|
780 |
|
|
3'b110 : begin
|
781 |
|
|
// C.SWSP
|
782 |
|
|
idu2exu_use_rs1_o = 1'b1;
|
783 |
|
|
idu2exu_use_rs2_o = 1'b1;
|
784 |
|
|
idu2exu_use_imm_o = 1'b1;
|
785 |
|
|
idu2exu_cmd_o.sum2_op = SCR1_SUM2_OP_REG_IMM;
|
786 |
|
|
idu2exu_cmd_o.lsu_cmd = SCR1_LSU_CMD_SW;
|
787 |
|
|
idu2exu_cmd_o.rs1_addr = SCR1_MPRF_SP_ADDR;
|
788 |
|
|
idu2exu_cmd_o.rs2_addr = instr[6:2];
|
789 |
|
|
idu2exu_cmd_o.imm = {24'd0, instr[8:7], instr[12:9], 2'b00};
|
790 |
|
|
`ifdef SCR1_RVE_EXT
|
791 |
|
|
if (instr[6]) rve_illegal = 1'b1;
|
792 |
|
|
`endif // SCR1_RVE_EXT
|
793 |
|
|
end
|
794 |
|
|
default : begin
|
795 |
|
|
rvc_illegal = 1'b1;
|
796 |
|
|
end
|
797 |
|
|
endcase // funct3
|
798 |
|
|
end // Quadrant 2
|
799 |
|
|
|
800 |
|
|
default : begin
|
801 |
|
|
end
|
802 |
|
|
`else // SCR1_RVC_EXT
|
803 |
|
|
default : begin
|
804 |
|
|
idu2exu_cmd_o.instr_rvc = 1'b1;
|
805 |
|
|
rvi_illegal = 1'b1;
|
806 |
|
|
end
|
807 |
|
|
`endif // SCR1_RVC_EXT
|
808 |
|
|
endcase // instr_type
|
809 |
|
|
end // no imem fault
|
810 |
|
|
|
811 |
|
|
// At this point the instruction is fully decoded
|
812 |
|
|
// given that no imem fault has happened
|
813 |
|
|
|
814 |
|
|
// Check illegal instruction
|
815 |
|
|
if (
|
816 |
|
|
rvi_illegal
|
817 |
|
|
`ifdef SCR1_RVC_EXT
|
818 |
|
|
| rvc_illegal
|
819 |
|
|
`endif
|
820 |
|
|
`ifdef SCR1_RVE_EXT
|
821 |
|
|
| rve_illegal
|
822 |
|
|
`endif
|
823 |
|
|
) begin
|
824 |
|
|
idu2exu_cmd_o.ialu_cmd = SCR1_IALU_CMD_NONE;
|
825 |
|
|
idu2exu_cmd_o.lsu_cmd = SCR1_LSU_CMD_NONE;
|
826 |
|
|
idu2exu_cmd_o.csr_cmd = SCR1_CSR_CMD_NONE;
|
827 |
|
|
idu2exu_cmd_o.rd_wb_sel = SCR1_RD_WB_NONE;
|
828 |
|
|
idu2exu_cmd_o.jump_req = 1'b0;
|
829 |
|
|
idu2exu_cmd_o.branch_req = 1'b0;
|
830 |
|
|
idu2exu_cmd_o.mret_req = 1'b0;
|
831 |
|
|
idu2exu_cmd_o.fencei_req = 1'b0;
|
832 |
|
|
idu2exu_cmd_o.wfi_req = 1'b0;
|
833 |
|
|
|
834 |
|
|
idu2exu_use_rs1_o = 1'b0;
|
835 |
|
|
idu2exu_use_rs2_o = 1'b0;
|
836 |
|
|
idu2exu_use_rd_o = 1'b0;
|
837 |
|
|
|
838 |
|
|
`ifndef SCR1_MTVAL_ILLEGAL_INSTR_EN
|
839 |
|
|
idu2exu_use_imm_o = 1'b0;
|
840 |
|
|
`else // SCR1_MTVAL_ILLEGAL_INSTR_EN
|
841 |
|
|
idu2exu_use_imm_o = 1'b1;
|
842 |
|
|
idu2exu_cmd_o.imm = instr;
|
843 |
|
|
`endif // SCR1_MTVAL_ILLEGAL_INSTR_EN
|
844 |
|
|
|
845 |
|
|
idu2exu_cmd_o.exc_req = 1'b1;
|
846 |
|
|
idu2exu_cmd_o.exc_code = SCR1_EXC_CODE_ILLEGAL_INSTR;
|
847 |
|
|
end
|
848 |
|
|
|
849 |
|
|
end // RV32I(MC) decode
|
850 |
|
|
|
851 |
|
|
`ifdef SCR1_TRGT_SIMULATION
|
852 |
|
|
//-------------------------------------------------------------------------------
|
853 |
|
|
// Assertion
|
854 |
|
|
//-------------------------------------------------------------------------------
|
855 |
|
|
|
856 |
|
|
// X checks
|
857 |
|
|
|
858 |
|
|
SCR1_SVA_IDU_XCHECK : assert property (
|
859 |
|
|
@(negedge clk) disable iff (~rst_n)
|
860 |
|
|
!$isunknown({ifu2idu_vd_i, exu2idu_rdy_i})
|
861 |
|
|
) else $error("IDU Error: unknown values");
|
862 |
|
|
|
863 |
|
|
SCR1_SVA_IDU_XCHECK2 : assert property (
|
864 |
|
|
@(negedge clk) disable iff (~rst_n)
|
865 |
|
|
ifu2idu_vd_i |-> !$isunknown({ifu2idu_imem_err_i, (ifu2idu_imem_err_i ? 0 : ifu2idu_instr_i)})
|
866 |
|
|
) else $error("IDU Error: unknown values");
|
867 |
|
|
|
868 |
|
|
// Behavior checks
|
869 |
|
|
|
870 |
|
|
SCR1_SVA_IDU_IALU_CMD_RANGE : assert property (
|
871 |
|
|
@(negedge clk) disable iff (~rst_n)
|
872 |
|
|
(ifu2idu_vd_i & ~ifu2idu_imem_err_i) |->
|
873 |
|
|
((idu2exu_cmd_o.ialu_cmd >= SCR1_IALU_CMD_NONE) &
|
874 |
|
|
(idu2exu_cmd_o.ialu_cmd <=
|
875 |
|
|
`ifdef SCR1_RVM_EXT
|
876 |
|
|
SCR1_IALU_CMD_REMU
|
877 |
|
|
`else
|
878 |
|
|
SCR1_IALU_CMD_SRA
|
879 |
|
|
`endif // SCR1_RVM_EXT
|
880 |
|
|
))
|
881 |
|
|
) else $error("IDU Error: IALU_CMD out of range");
|
882 |
|
|
|
883 |
|
|
`endif // SCR1_TRGT_SIMULATION
|
884 |
|
|
|
885 |
|
|
endmodule : scr1_pipe_idu
|