@@ -10,33 +10,33 @@ module mips
10
10
// wire [31:0] pc_current, alu_out, wd_dm;
11
11
// end of wires for testing
12
12
13
- wire pc_src, link, jump_reg ,reg_dst, we_reg, alu_src, we_hi, we_lo, hi2reg, lo2reg, zero, dm2reg, weCP0, weCP2, IV, EXL;
13
+ wire pc_src, link, jump_reg ,reg_dst, we_reg, alu_src, we_hi, we_lo, hi2reg, lo2reg, zero, NE, dm2reg, weCP0, weCP2, IV, EXL, hold, holdACK ;
14
14
wire [1 :0 ] jump, prossSel;
15
15
wire [3 :0 ] alu_ctrl;
16
16
wire [4 :0 ] cpop;
17
17
datapath DP (.clk(clk), .rst(rst), .pc_src(pc_src), .jump(jump), .link(link), .jump_reg(jump_reg) ,.reg_dst(reg_dst), .we_reg(we_reg),
18
18
.alu_src(alu_src), .we_hi(we_hi), .we_lo(we_lo), .hi2reg(hi2reg), .lo2reg(lo2reg), .dm2reg(dm2reg), .alu_ctrl(alu_ctrl),
19
19
.instr(instr[25 :0 ]), .rd_dm(rd_dm), .zero(zero), .pc_current(pc_current), .alu_out(alu_out), .wd_dm(wd_dm), .prossSel(prossSel), .weCP0(weCP0), .weCP2(weCP2),
20
- .IV(IV), .EXL(EXL), .interrupt(INT));
20
+ .IV(IV), .EXL(EXL), .interrupt(INT), .hold(hold), .holdACK(holdACK), .NE(NE) );
21
21
22
22
controlunit CU (.zero(zero), .op(instr[31 :26 ]), .funct(instr[5 :0 ]), .pc_src(pc_src), .jump(jump),
23
23
.link(link), .jump_reg(jump_reg) ,.reg_dst(reg_dst), .we_reg(we_reg), .alu_src(alu_src), .we_hi(we_hi), .we_lo(we_lo),
24
24
.hi2reg(hi2reg), .lo2reg(lo2reg), .we_dm(we_dm), .dm2reg(dm2reg), .alu_ctrl(alu_ctrl), .prossSel(prossSel), .weCP0(weCP0), .weCP2(weCP2), .cpop(instr[25 :21 ]),
25
- .IV(IV), .EXL(EXL));
25
+ .IV(IV), .EXL(EXL), .hold(hold), .holdACK(holdACK), .NE(NE) );
26
26
endmodule
27
27
28
28
module datapath
29
- (input clk, rst, pc_src, link, jump_reg, reg_dst, we_reg, alu_src, we_hi, we_lo, hi2reg, lo2reg, dm2reg, weCP0, weCP2,
29
+ (input clk, rst, pc_src, link, jump_reg, reg_dst, we_reg, alu_src, we_hi, we_lo, hi2reg, lo2reg, dm2reg, weCP0, weCP2, holdACK,
30
30
input [1 :0 ] jump, prossSel,
31
31
input [3 :0 ] alu_ctrl,
32
32
input [4 :0 ] interrupt,
33
33
input [25 :0 ] instr,
34
34
input [31 :0 ] rd_dm,
35
- output zero, IV, EXL,
35
+ output zero, NE, IV, EXL, hold,
36
36
output [31 :0 ] pc_current, alu_out, wd_dm);
37
37
wire trap, CP2rdy;
38
38
wire [4 :0 ] wa_rf, jal_rf;
39
- wire [31 :0 ] CPALU, pc_pre, pc_next, pc_plus4, jra, jta, sext_imm, ba, bta, alu_pa, alu_pb, hi_dat, lo_dat, hi_res, lo_res, wd_rf, wd_rf_res,CPzerod, CPtwod;
39
+ wire [31 :0 ] CPALU, pc_pre, pc_next, pc_plus4, jra, jta, sext_imm, ba, bta, alu_pa, alu_pb, hi_dat, lo_dat, hi_res, lo_res, wd_rf, wd_rf_res,CPzerod, CPtwod, pc_plus8 ;
40
40
wire [63 :0 ] product;
41
41
assign jta = {pc_plus4[31 :28 ], instr[25 :0 ], 2'b00 };
42
42
assign ba = {sext_imm[29 :0 ], 2'b00 };
@@ -47,6 +47,8 @@ module datapath
47
47
mux4 #(32 ) pc_jmp_mux (.sel(jump), .a(pc_pre), .b(jta), .c(32'h180 ), .d(32'h200 ), .y(pc_next));
48
48
dreg #(32 ) pc_reg (.clk(clk), .rst(rst), .en(1 ), .d(pc_next), .q(pc_current));
49
49
adder #(32 ) pc_add4 (.a(pc_current), .b(4 ), .y(pc_plus4));
50
+ // added for logic of CP0
51
+ adder #(32 ) pc_add8 (.a(pc_plus4), .b(4 ), .y(pc_plus8));
50
52
adder #(32 ) pc_add_bra (.a(pc_plus4), .b(ba), .y(bta));
51
53
signext se (.a(instr[15 :0 ]), .y(sext_imm));
52
54
// RF Logic
@@ -56,15 +58,15 @@ module datapath
56
58
regfile #(32 ) rf (.clk(clk), .we(we_reg), .wa(jal_rf), .ra1(instr[25 :21 ]), .ra2(instr[20 :16 ]), .wd(wd_rf_res), .rd1(alu_pa), .rd2(wd_dm));
57
59
// ALU Logic and CP0 Logic
58
60
mux2 #(32 ) alu_pb_mux (.sel(alu_src), .a(wd_dm), .b(sext_imm), .y(alu_pb));
59
- alu #(32 ) alu (.op(alu_ctrl), .a(alu_pa), .b(alu_pb), .shiftamount(instr[10 :6 ]), .zero(zero), .y(alu_out), .trap(trap));
61
+ alu #(32 ) alu (.op(alu_ctrl), .a(alu_pa), .b(alu_pb), .shiftamount(instr[10 :6 ]), .zero(zero), .y(alu_out), .trap(trap), .NE(NE) );
60
62
multi #(32 ) multi (.a(alu_pa), .b(alu_pb), .h(product[63 :32 ]), .l(product[31 :0 ]));
61
63
dreg #(32 ) high (.clk(clk), .rst(rst), .en(we_hi), .d(product[63 :32 ]), .q(hi_dat));
62
64
dreg #(32 ) low (.clk(clk), .rst(rst), .en(we_lo), .d(product[31 :0 ]), .q(lo_dat));
63
65
mux2 #(32 ) wd_rf_mux (.sel(dm2reg), .a(CPALU), .b(rd_dm), .y(wd_rf));
64
66
mux2 #(32 ) hi_mux (.sel(hi2reg), .a(wd_rf), .b(hi_dat), .y(hi_res));
65
67
mux2 #(32 ) lo_mux (.sel(lo2reg), .a(hi_res), .b(lo_dat), .y(lo_res));
66
68
mux4 #(32 ) pross_mux (.sel(prossSel), .a(alu_out), .b(CPzerod), .c(32'b0 ), .d(32'b0 ), .y(CPALU));
67
- CPzero CP0 (.clk(clk), .rst(rst), .we1(weCP0), .alu_trap(trap), .addr(instr[20 : 16 ]), .interrupt({interrupt, CP2rdy}), .wd(wd_dm), .pcp4(pc_current ), .exl(EXL), .iv(IV), .rd1(CPzerod));
69
+ CPzero CP0 (.clk(clk), .rst(rst), .we1(weCP0), .alu_trap(trap), .addr(instr[15 : 11 ]), .interrupt({interrupt, 1'b0 /* CP2rdy*/ }), .wd(wd_dm), .pcp4(pc_plus4 ), .exl(EXL), .iv(IV), .rd1(CPzerod));
68
70
// aes256_coprocessor CP2 (.data_in(wd_dm), .addr(instr[20:16]), .write_en(weCP2), .data_out(CPtwod), .clock(clk), .interrupt(CP2rdy));
69
71
70
72
@@ -74,16 +76,17 @@ endmodule
74
76
75
77
76
78
module controlunit
77
- (input zero, IV, EXL,
79
+ (input zero, IV, EXL, hold, NE,
78
80
input [4 :0 ] cpop,
79
81
input [5 :0 ] op, funct,
80
- output pc_src, link, jump_reg, reg_dst, we_reg, alu_src, we_hi, we_lo, hi2reg, lo2reg, we_dm, dm2reg, weCP0, weCP2,
82
+ output pc_src, link, jump_reg, reg_dst, we_reg, alu_src, we_hi, we_lo, hi2reg, lo2reg, we_dm, dm2reg, weCP0, weCP2, holdACK,
81
83
output [1 :0 ] jump, prossSel,
82
84
output [3 :0 ] alu_ctrl);
83
- wire branch;
84
- wire [1 :0 ] alu_op;
85
- assign pc_src = branch & zero;
86
- maindec MD (.op(op), .branch(branch), .jump(jump), .link(link), .reg_dst(reg_dst), .we_reg(we_reg), .alu_src(alu_src), .we_dm(we_dm), .dm2reg(dm2reg), .alu_op(alu_op), .prossSel(prossSel), .weCP0(weCP0), .weCP2(weCP2), .cpop(cpop), .IV(IV), .EXL(EXL));
85
+ wire branch, BNE;
86
+ wire [2 :0 ] alu_op;
87
+ assign pc_src = (branch & zero) | (BNE & NE);
88
+ maindec MD (.op(op), .branch(branch), .jump(jump), .link(link), .reg_dst(reg_dst), .we_reg(we_reg), .alu_src(alu_src), .we_dm(we_dm), .dm2reg(dm2reg), .alu_op(alu_op), .prossSel(prossSel), .weCP0(weCP0), .weCP2(weCP2),
89
+ .cpop(cpop), .IV(IV), .EXL(EXL), .hold(hold), .holdACK(holdACK), .BNE(BNE));
87
90
auxdec AD (.alu_op(alu_op), .funct(funct), .jump_reg(jump_reg), .we_hi(we_hi), .we_lo(we_lo), .hi2reg(hi2reg), .lo2reg(lo2reg), .alu_ctrl(alu_ctrl));
88
91
89
92
endmodule
0 commit comments