File size: 2,063 Bytes
f37eac2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | module controller (input [6:0] op, funct7,
input [2:0] funct3,
output memtoreg, memwrite,
output pcsrc, alusrc,
output regwrite,
output branch,
output storepc,
output pcadd,
output pcext,
output unsign,
output [2:0] imm,
output [3:0] alucontrol,
output [1:0] shtype,
output alu2src,
input gt, lt, eq,
output suspend,
output sltunsigned,
output memread,
output lh, lb, lhu, lbu);
wire [2:0] aluop;
wire alu2src_fake;
wire [3:0] alucontrol_fake;
wire storepc_local;
wire auipc_cntrl;
maindec md (.op(op),
.memtoreg(memtoreg),
.memwrite(memwrite),
.branch(branch),
.alusrc(alusrc),
.regwrite(regwrite),
.pcext(pcext), .pcadd(pcadd),
.storepc(storepc_local), .imm(imm), .aluop(aluop),
.auipc_cntrl(auipc_cntrl),
.gt(gt), .lt(lt), .eq(eq),
.suspend(suspend),
.memread(memread));
aludec ad (.funct7b(funct7[5]),
.funct3(funct3),
.aluop(aluop),
.alucontrol(alucontrol_fake),
.alu2src(alu2src_fake),
.shtype(shtype),
.sltunsigned(sltunsigned),
.lh(lh), .lb(lb), .lhu(lhu), .lbu(lbu));
mux2 #(1) mx1(.d0(alu2src_fake),.d1(1'b0),.s(imm[2]),.y(alu2src));
mux2 #(4) mx2(.d0(alucontrol_fake),.d1(4'b0010),
.s(imm[2] | branch),.y(alucontrol));
assign pcsrc = (branch & ~funct3[2] & ~funct3[1] & ~funct3[0] & eq) |
(branch & funct3[2] & ~funct3[1] & funct3[0] & ~lt) |
(branch & funct3[2] & ~funct3[1] & ~funct3[0] & lt) |
(branch & ~funct3[2] & ~funct3[1] & funct3[0] & ~eq) |
(branch & funct3[2] & funct3[1] & ~funct3[0] & lt) |
(branch & funct3[2] & funct3[1] & funct3[0] & (gt | eq)) |
(storepc_local);
assign unsign = branch & funct3[1];
assign storepc = storepc_local | auipc_cntrl;
endmodule // controller
|