-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathID_PCcontrol.v
52 lines (43 loc) · 1.89 KB
/
ID_PCcontrol.v
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
`include "mycpu.h"
module ID_PCcontrol(
input [31:0] oriPC,
input [31:0] curPC,
input [25:0] target,
input [15:0] offset,
input [31:0] rs_data,
input [31:0] rt_data,
input [31:0] EPC,
input exception,
input [10 :0] PCsrc,
output [31:0] nextPC
);
wire [31:0] PC_next_plus = curPC + 3'd4;
wire [31:0] PC_next_target = {oriPC[31:28], target, 2'd0};
wire [31:0] PC_next_offset = oriPC + {{14{offset[15]}}, offset, 2'd0} + 32'd4;
wire [31:0] PC_next_reg = rs_data;
wire [31:0] PC_exception = 32'hbfc00380;
wire [31:0] PC_EPC = EPC;
wire beq_cond = rs_data == rt_data;
wire bne_cond = ~beq_cond;
wire bltz_cond = rs_data[31];
wire bgez_cond = ~bltz_cond;
wire blez_cond = (rs_data == 32'd0) || (rs_data[31] == 1'b1);
wire bgtz_cond = ~blez_cond;
assign nextPC = exception ? PC_exception :
({32{PCsrc[`PC_from_PCplus]}} & PC_next_plus) |
({32{PCsrc[`PC_from_target]}} & PC_next_target) |
({32{PCsrc[`PC_from_reg]}} & PC_next_reg) |
({32{PCsrc[`PC_from_beq] & beq_cond}} & PC_next_offset) |
({32{PCsrc[`PC_from_beq] & ~beq_cond}} & PC_next_plus ) |
({32{PCsrc[`PC_from_bne] & bne_cond}} & PC_next_offset) |
({32{PCsrc[`PC_from_bne] & ~bne_cond}} & PC_next_plus) |
({32{PCsrc[`PC_from_bltz] & bltz_cond}} & PC_next_offset) |
({32{PCsrc[`PC_from_bltz] & ~bltz_cond}} & PC_next_plus ) |
({32{PCsrc[`PC_from_bgez] & bgez_cond}} & PC_next_offset) |
({32{PCsrc[`PC_from_bgez] & ~bgez_cond}} & PC_next_plus ) |
({32{PCsrc[`PC_from_blez] & blez_cond}} & PC_next_offset) |
({32{PCsrc[`PC_from_blez] & ~blez_cond}} & PC_next_plus ) |
({32{PCsrc[`PC_from_bgtz] & bgtz_cond}} & PC_next_offset) |
({32{PCsrc[`PC_from_bgtz] & ~bgtz_cond}} & PC_next_plus ) |
({32{PCsrc[`PC_from_EPC]}} & PC_EPC);
endmodule