-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathControl_E.v
134 lines (117 loc) · 4.54 KB
/
Control_E.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
`include"defination.v"
module Control_ID(input [31:0] instr,//basically this module is for signed extension selections
output reg PCsel,
output reg [1:0] extOp);//ext tells which immediate to choose signed or unsigned
always @(*)
begin
PCsel <= 1'b0;
//handle extOp
//checkif following are true for signed extension
//on cheatsheet it is written immediate fields are sign extented
//confusion in ALU I am also taking signed operations whats their meaning may be nothing to notice
//what about 'a' if we put the number in a what about it does compiler would put sign extension or not just check
if(`LB || `LH || `LW || `ADDI || `SLTI || `XORI ||`ORI || `ANDI ||`SLLI || `SRLI || `SRAI )
extOp <= 2'b01;
else if (`SB || `SH || `SW)
extOp <=2'b11;
else
extOp <= 2'b00;
end // always @ (*)
endmodule // ConTrol_ID
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//Also b selection is from here also
module Control_E(input [31:0] instr,
output reg [3:0] ALUOp,
output reg BSel);
always @(*)
begin
//handle ALUOp
if(`SUB)
ALUOp = 4'b00_01;
else if(`AND || `ANDI)
ALUOp = 4'b01_00;
else if(`OR || `ORI)
ALUOp = 4'b01_01;
else if(`XOR || `XORI)
ALUOp = 4'b01_10;
else if(`SLL || `SLLI)
ALUOp = 4'b10_00;
else if(`SRL || `SRLI)
ALUOp = 4'b10_10;
else if(`SRA || `SRAI)
ALUOp = 4'b10_11;
else if(`SLT || `SLTI)
ALUOp = 4'b11_00;
else if(`SLTU || `SLTIU)
ALUOp = 4'b11_01;
else //others use add
ALUOp = 4'b00_00;
if(`LB || `LBU || `LH || `LHU || `LW ||`ADDI || `ANDI || `ORI || `XORI || `SLTI || `SLTIU || `SLLI || `SRLI || `SRAI ||`SB || `SH || `SW)
BSel = 1'b1;
else
BSel = 1'b0;//for selecting b register
end
endmodule // Control_IE
//Memory write for store instructions based on byte or half word or word level store
//check how store instruction works otherwise destination can go wrong
module Control_M(input [31:0] instr,
output reg memWr,
output reg [1:0] BEextOp);
always @(*)
begin
if(`SB || `SH || `SW)
memWr = 1;
else
memWr = 0;
if(`SH)
BEextOp = 2'b10;
else if(`SB)
BEextOp = 2'b11;
else
BEextOp = 2'b00;
end
endmodule // Control_M
//for writing to mem
module Control_W(input [31:0] instr,
output reg WRSel,
output reg WDSel,
output reg regWr,
output reg [2:0] WBextOp);
always @(*)
begin
if(`LBU)
WBextOp = 3'b001;
else if(`LB)
WBextOp = 3'b010;
else if(`LHU)
WBextOp = 3'b011;
else if(`LH)
WBextOp = 3'b100;
else
WBextOp = 3'b000;
if(`ADD || `SUB || `SLT || `SLTU || `SLL || `SRL || `SRA || `AND || `OR || `XOR) //r-r cal and MF
begin
regWr <= 1'b1;
WRSel <= 1'b0;//RD
WDSel <= 1'b0;//ALU
end
else if(`LB || `LBU || `LH || `LHU || `LW) //load
begin
regWr <= 1'b1;
WRSel <= 1'b0;//RD
WDSel <= 1'b1; //rdata
end
else if(`ADDI || `ANDI || `ORI || `XORI || `SLTI || `SLTIU) //r-i cal
begin
regWr <= 1'b1;
WRSel <= 1'b0;//
WDSel <= 1'b0;//ALU
end
else //default maybe for Store instructions msitake here
begin
regWr <= 1'b0;
WRSel <= 1'b0;//********* converted from 1 to 0 as i think RD is always this
WDSel <= 1'b0;
end //
end // always @ begin
endmodule // Control_W