-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol.v
120 lines (108 loc) · 2.46 KB
/
control.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
module control(
input [5:0] opcode,
input [5:0] funct,
//exception code, nonzero if there's an exception
input [1:0] exc,
input Branch,
input isbr,
input isj,
/*
input wasbr,
input wasj,
*/
input mis,
output reg[1:0] IF_Ctrl,//PCSrc[1:0]
output reg[2:0] ID_Ctrl,//JLink:Jump:RegDst
/** WB signal = MemtoReg:RegWrite
* M signal = MemRead:MemWrite
* EX signal = ALUop(Opcode or Funct) (Not used)
*/
output reg [9:0] Ctrl_out,//pack of WB:M:EX control signal
output IFFlush,
output IDFlush,
output EXFlush
);
parameter R_INST = 6'b0;
parameter BZ = 6'b1;
parameter BEQ = 6'b100;
parameter BNE = 6'b101;
parameter BLEZ = 6'b110;
parameter BGTZ = 6'b111;
parameter J = 6'b10;
parameter JAL = 6'b11;
parameter LW = 6'b100011;
parameter SW = 6'b101011;
parameter JR = 6'h8;
parameter JALR = 6'h9;
parameter RTYPE = 2'h0;
parameter ITYPE = 2'h1;
parameter JTYPE = 2'h2;
reg [1:0] optype;
assign IFFlush = isbr || isj || mis || |exc;
assign IDFlush = mis || |exc;
assign EXFlush = |exc;
always @*
begin
case(opcode)
R_INST:
optype = RTYPE;
J: optype = JTYPE;
JAL: optype = JTYPE;
//catch anomaly where opcode is NaN(not implemented)
default: optype = ITYPE;
endcase
end
always @*
begin
case(optype)
RTYPE:
//JR and JALR should not be taken into account
IF_Ctrl = {1'b0, 1'b0};
ITYPE:
IF_Ctrl = {1'b0, Branch};
JTYPE:
IF_Ctrl = 2'b01;
endcase
if(exc)
IF_Ctrl = 2'b10;
end
wire isJALR, isJR;
assign isJALR = funct == 6'h9;
assign isJR = funct[5:1] == 5'h4;
always @*
begin
case(optype)
RTYPE:
ID_Ctrl = {isJALR, isJR, 1'b1};
ITYPE:
ID_Ctrl = 3'b0;
JTYPE:
ID_Ctrl = {opcode[0], 1'b1, 1'bz};
endcase
end
/*
isWR indicates if a I-type instruction do write registers
*/
wire isLW, isSW, isWR;
assign isLW = opcode == LW;
assign isSW = opcode == SW;
/*RegWrite:
Almost all operations except
JR
J
SW
Branch(Without Link)
*/
assign isWR = !(opcode == SW || opcode == BGTZ || opcode == BLEZ || opcode == BEQ || opcode == BNE);
always @*
begin
case(optype)
RTYPE:
Ctrl_out = {1'b0, !(funct == JR), 2'b0, funct};
ITYPE:
Ctrl_out = {isLW, isWR, isLW, isSW, opcode};
JTYPE:
Ctrl_out = {1'b1, opcode == JAL, 2'b0, opcode};
endcase
end
endmodule