-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpu.v
176 lines (151 loc) · 3.09 KB
/
cpu.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
`timescale 1ns/1ps
`include "cpu/components/ADD.v"
`include "cpu/components/EXT.v"
`include "cpu/components/JOIN.v"
`include "cpu/components/MUX.v"
`include "cpu/ALU.v"
`include "cpu/InstDecoder.v"
`include "cpu/NPC.v"
`include "cpu/PC.v"
`include "cpu/RegFile.v"
module CPU (
input inclk,
input rstn,
input [31:0] inst,
input [31:0] i_DM_rdata,
output outclk,
output IM_R,
output DM_CS,
output DM_R,
output DM_W,
output [31:0] o_PC_out,
output [31:0] o_ALU_out,
output [31:0] o_DM_addr,
output [31:0] o_DM_wdata,
input [31:0] test_rf_addr, // ? TEST INTERFACE
output [31:0] test_rf_data // ? TEST INTERFACE
);
wire PC_clk, RF_clk;
wire RF_W, M1, M2, M3, M4, M5, M6, SIGN_EXT, ZERO;
wire [3:0] ALU_C;
wire [31:0] RF_rs_out, RF_rt_out, ALU_out, PC_out, NPC_out, JOIN_out;
wire [31:0] MUX1_out, MUX2_out, MUX3_out, MUX4_out, MUX5_out;
wire [4:0] MUX6_out;
wire [31:0] EXT5_out, EXT16_out, EXT18_out;
wire [31:0] ADD_out;
wire [17:0] imm18 = inst[15:0] << 2;
wire [27:0] addr28 = inst[25:0] << 2;
wire [4:0] shamt = inst[10:6];
wire [15:0] immediate = inst[15:0];
wire [4:0] rs_addr = inst[25:21];
wire [4:0] rt_addr = inst[20:16];
wire [4:0] rd_addr = inst[15:11];
assign o_PC_out = PC_out;
assign o_ALU_out = ALU_out;
assign o_DM_addr = ALU_out;
assign o_DM_wdata = RF_rt_out;
assign outclk = RF_clk;
InstDecoder cpu_inst_decoder(
inclk,
inst,
ZERO,
PC_clk,
RF_clk,
IM_R,
DM_CS, DM_R, DM_W,
RF_W,
ALU_C,
SIGN_EXT,
M1, M2, M3, M4, M5, M6
);
NPC cpu_npc(
PC_out,
NPC_out
);
PC cpu_pc(
PC_clk,
rstn,
MUX1_out,
PC_out
);
JOIN cpu_join(
PC_out[31:28],
addr28,
JOIN_out
);
RegFile cpu_rf(
RF_clk,
rstn,
RF_W,
rs_addr,
rt_addr,
MUX6_out,
MUX2_out,
RF_rs_out,
RF_rt_out,
test_rf_addr, // ? TEST INTERFACE
test_rf_data // ? TEST INTERFACE
);
ALU cpu_alu(
MUX3_out,
MUX4_out,
ALU_C,
ALU_out,
ZERO
);
ADD cpu_add(
EXT18_out,
NPC_out,
ADD_out
);
EXT5T32 cpu_ext5(
shamt,
EXT5_out
);
EXT16T32 cpu_ext16(
immediate,
SIGN_EXT,
EXT16_out
);
EXT18T32 cpu_ext18(
imm18,
SIGN_EXT,
EXT18_out
);
MUX2X32 MUX1(
MUX5_out,
JOIN_out,
M1,
MUX1_out
);
MUX2X32 MUX2(
i_DM_rdata,
ALU_out,
M2,
MUX2_out
);
MUX2X32 MUX3(
EXT5_out,
RF_rs_out,
M3,
MUX3_out
);
MUX2X32 MUX4(
RF_rt_out,
EXT16_out,
M4,
MUX4_out
);
MUX2X32 MUX5(
NPC_out,
ADD_out,
M5,
MUX5_out
);
MUX2X5 MUX6(
rd_addr,
rt_addr,
M6,
MUX6_out
);
endmodule