-
Notifications
You must be signed in to change notification settings - Fork 1
/
mips.v
368 lines (334 loc) · 9.21 KB
/
mips.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 20:15:46 10/27/2022
// Design Name:
// Module Name: mips
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
`include "macro.v"
module mycpu_top(
input [5:0] ext_int,
input aclk,
input aresetn,
output [3:0] arid ,
output [31:0] araddr,
output [3:0] arlen ,
output [2:0] arsize ,
output [1:0] arburst,
output [1:0] arlock ,
output [3:0] arcache,
output [2:0] arprot ,
output arvalid,
input arready,
input [3:0] rid ,
input [31:0] rdata ,
input [1:0] rresp ,
input rlast ,
input rvalid ,
output rready ,
output [3:0] awid ,
output [31:0] awaddr,
output [3:0] awlen ,
output [2:0] awsize ,
output [1:0] awburst,
output [1:0] awlock ,
output [3:0] awcache,
output [2:0] awprot ,
output awvalid,
input awready,
output [3:0] wid ,
output [31:0] wdata ,
output [3:0] wstrb ,
output wlast ,
output wvalid ,
input wready ,
input [3:0] bid ,
input [1:0] bresp ,
input bvalid ,
output bready ,
output [31:0] debug_wb_pc ,
output [3:0] debug_wb_rf_wen ,
output [4:0] debug_wb_rf_wnum ,
output [31:0] debug_wb_rf_wdata
);
wire cpu_inst_req ;
wire cpu_inst_wr ;
wire [1 :0] cpu_inst_size ;
wire [31:0] cpu_inst_addr ;
wire [3 :0] cpu_inst_wstrb ;
wire [31:0] cpu_inst_wdata ;
wire [31:0] cpu_inst_rdata ;
wire cpu_inst_addr_ok ;
wire cpu_inst_data_ok ;
wire [31:12] mmu_inst_tag ;
wire [11: 4] mmu_inst_index ;
wire [ 3: 0] mmu_inst_offset ;
wire mmu_inst_cache ;
wire cpu_data_req ;
wire cpu_data_wr ;
wire [1 :0] cpu_data_size ;
wire [31:0] cpu_data_addr ;
wire [3 :0] cpu_data_wstrb ;
wire [31:0] cpu_data_wdata ;
wire [31:0] cpu_data_rdata ;
wire cpu_data_addr_ok ;
wire cpu_data_data_ok ;
wire [31:12] mmu_data_tag ;
wire [11: 4] mmu_data_index ;
wire [ 3: 0] mmu_data_offset ;
wire mmu_data_cache ;
wire inst_rd_req ;
wire [ 2: 0] inst_rd_type ;
wire [31: 0] inst_rd_addr ;
wire inst_rd_rdy ;
wire inst_ret_valid ;
wire inst_ret_last ;
wire [31: 0] inst_ret_data ;
wire data_rd_req ;
wire [ 2: 0] data_rd_type ;
wire [31: 0] data_rd_addr ;
wire data_rd_rdy ;
wire data_ret_valid ;
wire data_ret_last ;
wire [31: 0] data_ret_data ;
wire data_wr_req ;
wire [ 2: 0] data_wr_type ;
wire [31: 0] data_wr_addr ;
wire [ 3: 0] data_wr_wstrb ;
wire [127:0] data_wr_data ;
wire data_wr_rdy ;
cpu_axi_interface cpu_axi_interface(
.clk (aclk ),
.resetn (aresetn ),
// .inst_req (cpu_inst_req ),
// .inst_wr (cpu_inst_wr ),
// .inst_size (cpu_inst_size ),
// .inst_addr (cpu_inst_addr ),
// .inst_wdata (cpu_inst_wdata ),
// .inst_rdata (cpu_inst_rdata ),
// .inst_addr_ok (cpu_inst_addr_ok ),
// .inst_data_ok (cpu_inst_data_ok ),
// //data sram-like
// .data_req (cpu_data_req ),
// .data_wr (cpu_data_wr ),
// .data_size (cpu_data_size ),
// .data_addr (cpu_data_addr ),
// .data_wdata (cpu_data_wdata ),
// .data_rdata (cpu_data_rdata ),
// .data_addr_ok (cpu_data_addr_ok ),
// .data_data_ok (cpu_data_data_ok ),
//inst rd Cache <-> AXI
.inst_rd_req (inst_rd_req ), // Cache发出的读请求有效信号
.inst_rd_type (inst_rd_type ),
.inst_rd_addr (inst_rd_addr ),
.inst_rd_rdy (inst_rd_rdy ), // 读请求能否被接收的握手信号
.inst_ret_valid (inst_ret_valid ), // 返回数据有效
.inst_ret_last (inst_ret_last ),
.inst_ret_data (inst_ret_data ),
//data rd Cache <-> AXI
.data_rd_req (data_rd_req ), // Cache发出的读请求有效信号
.data_rd_type (data_rd_type ),
.data_rd_addr (data_rd_addr ),
.data_rd_rdy (data_rd_rdy ), // 读请求能否被接收的握手信号
.data_ret_valid (data_ret_valid ), // 返回数据有效
.data_ret_last (data_ret_last ),
.data_ret_data (data_ret_data ),
//data wr Cache <-> AXI
.data_wr_req (data_wr_req ), // Cache发出的写请求有效信号
.data_wr_type (data_wr_type ),
.data_wr_addr (data_wr_addr ),
.data_wr_wstrb (data_wr_wstrb ),
.data_wr_data (data_wr_data ),
.data_wr_rdy (data_wr_rdy ), // 写请求能否被接收的握手信号,先于wr_req置起; AXI总线内16字节缓存为空时置起
//axi
//ar
.arid (arid ),
.araddr (araddr ),
.arlen (arlen ),
.arsize (arsize ),
.arburst (arburst ),
.arlock (arlock ),
.arcache (arcache ),
.arprot (arprot ),
.arvalid (arvalid ),
.arready (arready ),
//r
.rid (rid ),
.rdata (rdata ),
.rresp (rresp ),
.rlast (rlast ),
.rvalid (rvalid ),
.rready (rready ),
//aw
.awid (awid ),
.awaddr (awaddr ),
.awlen (awlen ),
.awsize (awsize ),
.awburst (awburst ),
.awlock (awlock ),
.awcache (awcache ),
.awprot (awprot ),
.awvalid (awvalid ),
.awready (awready ),
//w
.wid (wid ),
.wdata (wdata ),
.wstrb (wstrb ),
.wlast (wlast ),
.wvalid (wvalid ),
.wready (wready ),
//b
.bid (bid ),
.bresp (bresp ),
.bvalid (bvalid ),
.bready (bready )
);
wire [31:0] EPC, VAddr;
wire EXL;
wire [4:0] ExcCode;
wire BD;
wire require;
wire [4:0] CP0Addr;
wire [31:0] CP0RD, CP0WD, backPC;
wire CP0We, back;
Cache dCache(
.clk (aclk),
.reset (~aresetn),
// CPU - Cache
.valid (cpu_data_req ),
.uncache (!mmu_data_cache ),
.op (cpu_data_wr ),
.index (mmu_data_index ),
.tag (mmu_data_tag ),
.offset (mmu_data_offset ),
.wstrb (cpu_data_wstrb ),
.wdata (cpu_data_wdata ),
.addr_ok (cpu_data_addr_ok),
.data_ok (cpu_data_data_ok),
.rdata (cpu_data_rdata ),
// Cache - AXI
.rd_req (data_rd_req ),
.rd_type (data_rd_type ),
.rd_addr (data_rd_addr ),
.rd_rdy (data_rd_rdy ),
.ret_valid (data_ret_valid ),
.ret_last (data_ret_last ),
.ret_data (data_ret_data ),
.wr_req (data_wr_req ),
.wr_type (data_wr_type ),
.wr_addr (data_wr_addr ),
.wr_wstrb (data_wr_wstrb ),
.wr_data (data_wr_data ),
.wr_rdy (data_wr_rdy )
);
Cache iCache(
.clk (aclk),
.reset (~aresetn),
// CPU - Cache
.valid (cpu_inst_req ),
.uncache (!mmu_inst_cache ),
.op (cpu_inst_wr ),
.index (mmu_inst_index ),
.tag (mmu_inst_tag ),
.offset (mmu_inst_offset ),
.wstrb (cpu_inst_wstrb ),
.wdata (cpu_inst_wdata ),
.addr_ok (cpu_inst_addr_ok),
.data_ok (cpu_inst_data_ok),
.rdata (cpu_inst_rdata ),
// Cache - AXI
.rd_req (inst_rd_req ),
.rd_type (inst_rd_type ),
.rd_addr (inst_rd_addr ),
.rd_rdy (inst_rd_rdy ),
.ret_valid (inst_ret_valid ),
.ret_last (inst_ret_last ),
.ret_data (inst_ret_data ),
.wr_req (),
.wr_type (),
.wr_addr (),
.wr_wstrb (),
.wr_data (),
.wr_rdy (1)
);
MMU mmu(
.cpu_inst_addr (cpu_inst_addr ),
.inst_tag (mmu_inst_tag ),
.inst_index (mmu_inst_index ),
.inst_offset (mmu_inst_offset),
.inst_cache (mmu_inst_cache ),
.cpu_data_addr (cpu_data_addr ),
.data_tag (mmu_data_tag ),
.data_index (mmu_data_index ),
.data_offset (mmu_data_offset),
.data_cache (mmu_data_cache )
);
CPU cpu(
.clk (aclk ),
.reset (~aresetn ),
.respon (require ),
.inst_req (cpu_inst_req ),
.inst_wr (cpu_inst_wr ),
.inst_size (cpu_inst_size ),
.inst_addr (cpu_inst_addr ),
.inst_wstrb (cpu_inst_wstrb ),
.inst_wdata (cpu_inst_wdata ),
.inst_rdata (cpu_inst_rdata ),
.inst_addr_ok (cpu_inst_addr_ok ),
.inst_data_ok (cpu_inst_data_ok ),
.data_req (cpu_data_req ),
.data_wr (cpu_data_wr ),
.data_size (cpu_data_size ),
.data_addr (cpu_data_addr ),
.data_wstrb (cpu_data_wstrb ),
.data_wdata (cpu_data_wdata ),
.data_rdata (cpu_data_rdata ),
.data_addr_ok (cpu_data_addr_ok ),
.data_data_ok (cpu_data_data_ok ),
.debug_wb_pc (debug_wb_pc ),
.debug_wb_rf_wen (debug_wb_rf_wen ),
.debug_wb_rf_wnum (debug_wb_rf_wnum ),
.debug_wb_rf_wdata (debug_wb_rf_wdata),
.EXL (EXL),
.ExcCodeOut (ExcCode),
.BD(BD),
.EPC(EPC),
.VAddr(VAddr),
.back(back),
.backPC(backPC),
.CP0Addr(CP0Addr),
.CP0RD(CP0RD),
.CP0WD(CP0WD),
.CP0We(CP0We)
);
CP0 cp0(
.clk(aclk),
.reset(~aresetn),
.en(CP0We),
.CP0ADD(CP0Addr),
.CP0In(CP0WD),
.CP0Out(CP0RD),
.EXLSet(EXL),
.VPC(EPC), // i, pc of victim inst
.VAddr(VAddr), // i, BadVAddr
.BDIn(BD),
.ExcCodeIn(ExcCode),
.HWInt(ext_int),
.EXLClr(back),
.EPCOut(backPC),
.Req(require)
);
endmodule