OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [branches/] [mp3_stable/] [or1200/] [rtl/] [verilog/] [cpu.v] - Blame information for rev 209

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 161 lampret
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's CPU                                                ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6
////  http://www.opencores.org/cores/or1k/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  Instantiation of internal CPU blocks. IFETCH, SPRS, FRZ,    ////
10
////  ALU, EXCEPT, ID, WBMUX, OPERANDMUX, RF etc.                 ////
11
////                                                              ////
12
////  To Do:                                                      ////
13
////   - make it smaller and faster                               ////
14
////                                                              ////
15
////  Author(s):                                                  ////
16
////      - Damjan Lampret, lampret@opencores.org                 ////
17
////                                                              ////
18
//////////////////////////////////////////////////////////////////////
19
////                                                              ////
20
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
21
////                                                              ////
22
//// This source file may be used and distributed without         ////
23
//// restriction provided that this copyright statement is not    ////
24
//// removed from the file and that any derivative work contains  ////
25
//// the original copyright notice and the associated disclaimer. ////
26
////                                                              ////
27
//// This source file is free software; you can redistribute it   ////
28
//// and/or modify it under the terms of the GNU Lesser General   ////
29
//// Public License as published by the Free Software Foundation; ////
30
//// either version 2.1 of the License, or (at your option) any   ////
31
//// later version.                                               ////
32
////                                                              ////
33
//// This source is distributed in the hope that it will be       ////
34
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
35
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
36
//// PURPOSE.  See the GNU Lesser General Public License for more ////
37
//// details.                                                     ////
38
////                                                              ////
39
//// You should have received a copy of the GNU Lesser General    ////
40
//// Public License along with this source; if not, download it   ////
41
//// from http://www.opencores.org/lgpl.shtml                     ////
42
////                                                              ////
43
//////////////////////////////////////////////////////////////////////
44
//
45
// CVS Revision History
46
//
47
// $Log: not supported by cvs2svn $
48 203 lampret
// Revision 1.4  2001/08/17 08:01:19  lampret
49
// IC enable/disable.
50
//
51 176 lampret
// Revision 1.3  2001/08/13 03:36:20  lampret
52
// Added cfg regs. Moved all defines into one defines.v file. More cleanup.
53
//
54 170 lampret
// Revision 1.2  2001/08/09 13:39:33  lampret
55
// Major clean-up.
56
//
57 168 lampret
// Revision 1.1  2001/07/20 00:46:03  lampret
58
// Development version of RTL. Libraries are missing.
59 161 lampret
//
60 168 lampret
//
61 161 lampret
 
62 203 lampret
// synopsys translate_off
63 168 lampret
`include "timescale.v"
64 203 lampret
// synopsys translate_on
65 168 lampret
`include "defines.v"
66 161 lampret
 
67
module cpu(
68
        // Clk & Rst
69
        clk, rst,
70
 
71
        // Insn interface
72 203 lampret
        ic_insn, ic_addr, ic_stall, ic_fetchop, ic_en,
73
        immu_en, immuexcept_miss, immuexcept_fault,
74 161 lampret
 
75 209 lampret
        // Debug unit
76
        du_stall, du_addr, du_dat_du, du_read, du_write,
77 161 lampret
 
78
        // Data interface
79 203 lampret
        dclsu_stall, dclsu_unstall, dclsu_addr, dclsu_datain, dclsu_dataout, dclsu_lsuop, dc_en,
80
        dmmu_en, dmmuexcept_miss, dmmuexcept_fault,
81 161 lampret
 
82
        // Interrupt exceptions
83
        int_high, int_low,
84
 
85
        // SPR interface
86 209 lampret
        supv, spr_addr, spr_dataout, spr_dat_pic, spr_dat_tt, spr_dat_pm,
87
        spr_dat_dmmu, spr_dat_immu, spr_dat_du, spr_cs, spr_we
88 161 lampret
);
89
 
90
parameter dw = `OPERAND_WIDTH;
91
parameter aw = `REGFILE_ADDR_WIDTH;
92
 
93
//
94
// I/O ports
95
//
96
 
97 168 lampret
//
98 161 lampret
// Clk & Rst
99 168 lampret
//
100
input                           clk;
101
input                           rst;
102 161 lampret
 
103 168 lampret
//
104
// Insn (IC) interface
105
//
106
input   [31:0]                   ic_insn;
107 203 lampret
output  [31:0]                   ic_addr;
108 168 lampret
input                           ic_stall;
109 203 lampret
output  [`FETCHOP_WIDTH-1:0]     ic_fetchop;
110 170 lampret
output                          ic_en;
111 161 lampret
 
112 168 lampret
//
113 203 lampret
// Insn (IMMU) interface
114
//
115
input                           immuexcept_miss;
116
input                           immuexcept_fault;
117
output                          immu_en;
118
 
119
//
120 209 lampret
// Debug interface
121 168 lampret
//
122 209 lampret
input                           du_stall;
123
input   [dw-1:0]         du_addr;
124
input   [dw-1:0]         du_dat_du;
125
input                           du_read;
126
input                           du_write;
127 161 lampret
 
128 168 lampret
//
129
// Data (DC) interface
130
//
131
input                           dclsu_stall;
132 203 lampret
input                           dclsu_unstall;
133 168 lampret
output  [31:0]                   dclsu_addr;
134
input   [31:0]                   dclsu_datain;
135
output  [31:0]                   dclsu_dataout;
136
output  [`LSUOP_WIDTH-1:0]       dclsu_lsuop;
137
output                          dc_en;
138 161 lampret
 
139 168 lampret
//
140 203 lampret
// Data (DMMU) interface
141
//
142
input                           dmmuexcept_miss;
143
input                           dmmuexcept_fault;
144
output                          dmmu_en;
145
 
146
//
147 161 lampret
// SPR interface
148 168 lampret
//
149 209 lampret
output                          supv;
150 168 lampret
input   [dw-1:0]         spr_dat_pic;
151
input   [dw-1:0]         spr_dat_tt;
152
input   [dw-1:0]         spr_dat_pm;
153 203 lampret
input   [dw-1:0]         spr_dat_dmmu;
154 209 lampret
input   [dw-1:0]         spr_dat_immu;
155
input   [dw-1:0]         spr_dat_du;
156 168 lampret
output  [dw-1:0]         spr_addr;
157
output  [dw-1:0]         spr_dataout;
158
output  [31:0]                   spr_cs;
159
output                          spr_we;
160 161 lampret
 
161 168 lampret
//
162 161 lampret
// Interrupt exceptions
163 168 lampret
//
164
input                           int_high;
165
input                           int_low;
166 161 lampret
 
167
//
168
// Internal wires
169
//
170 168 lampret
wire    [31:0]                   insn;
171
wire    [31:0]                   if_pc;
172
wire    [31:2]                  lr_sav;
173
wire    [aw-1:0]         rf_addrw;
174
wire    [aw-1:0]                 rf_addra;
175
wire    [aw-1:0]                 rf_addrb;
176
wire    [dw-1:0]         simm;
177
wire    [dw-1:2]                branch_addrofs;
178
wire    [`ALUOP_WIDTH-1:0]       alu_op;
179
wire    [`SHROTOP_WIDTH-1:0]     shrot_op;
180
wire    [`COMPOP_WIDTH-1:0]      comp_op;
181
wire    [`BRANCHOP_WIDTH-1:0]    branch_op;
182
wire    [`LSUOP_WIDTH-1:0]       lsu_op;
183 205 lampret
wire                            if_freeze;
184
wire                            id_freeze;
185
wire                            ex_freeze;
186
wire                            wb_freeze;
187 168 lampret
wire    [`SEL_WIDTH-1:0] sel_a;
188
wire    [`SEL_WIDTH-1:0] sel_b;
189
wire    [`RFWBOP_WIDTH-1:0]      rfwb_op;
190
wire    [dw-1:0]         rf_dataw;
191
wire    [dw-1:0]         rf_dataa;
192
wire    [dw-1:0]         rf_datab;
193
wire    [dw-1:0]         muxed_b;
194
wire    [dw-1:0]         wb_forw;
195
wire                            wbforw_valid;
196
wire    [dw-1:0]         operand_a;
197
wire    [dw-1:0]         operand_b;
198
wire    [dw-1:0]         alu_dataout;
199
wire    [dw-1:0]         lsu_dataout;
200
wire    [dw-1:0]         sprs_dataout;
201
wire    [31:0]                   lsu_addrofs;
202
wire    [`MULTICYCLE_WIDTH-1:0]  multicycle;
203
wire    [`EXCEPT_WIDTH-1:0]      except_type;
204
wire                            except_flushpipe;
205
wire                            branch_taken;
206
wire                            flag;
207
wire                            lsu_stall;
208
wire                            branch_stall;
209
wire                            epcr_we;
210
wire                            eear_we;
211
wire                            esr_we;
212
wire    [31:0]                   epcr;
213
wire    [31:0]                   eear;
214
wire    [`SR_WIDTH-1:0]          esr;
215
wire    [`SR_WIDTH-1:0]          sr;
216
wire                            except_start;
217
wire                            except_started;
218
wire    [31:0]                   wb_pc;
219
wire    [31:0]                   wb_insn;
220
wire    [15:0]                   spr_addrimm;
221
wire                            sig_syscall;
222 170 lampret
wire    [31:0]                   spr_dat_cfgr;
223 209 lampret
wire    [31:0]                   spr_dat_rf;
224 203 lampret
wire                            force_dslot_fetch;
225
wire                            if_stall;
226 209 lampret
wire                            id_macrc_op;
227
wire                            ex_macrc_op;
228
wire    [31:0]                   mult_mac_result;
229
wire                            mac_stall;
230 161 lampret
 
231 168 lampret
//
232
// Data cache enable
233
//
234
assign dc_en = sr[`SR_DCE];
235
 
236
//
237 170 lampret
// Instruction cache enable
238
//
239 203 lampret
//assign ic_en = 1'b1;
240 176 lampret
assign ic_en = sr[`SR_ICE];
241 170 lampret
 
242
//
243 203 lampret
// DMMU enable
244
//
245
assign dmmu_en = sr[`SR_DME];
246
 
247
//
248
// IMMU enable
249
//
250
assign immu_en = sr[`SR_IME];
251
 
252
//
253
// SUPV bit
254
//
255
assign supv = sr[`SR_SUPV];
256
 
257
//
258 161 lampret
// Instantiation of exception block
259
//
260
except except(
261
        .clk(clk),
262
        .rst(rst),
263 203 lampret
        .sig_dtlbmiss(dmmuexcept_miss),
264
        .sig_dmmufault(dmmuexcept_fault),
265 161 lampret
        .sig_inthigh(int_high),
266 168 lampret
        .sig_syscall(sig_syscall),
267 203 lampret
        .sig_itlbmiss(immuexcept_miss),
268
        .sig_immufault(immuexcept_fault),
269 161 lampret
        .sig_intlow(int_low),
270
        .branch_taken(branch_taken),
271 205 lampret
        .id_freeze(id_freeze),
272
        .ex_freeze(ex_freeze),
273
        .wb_freeze(wb_freeze),
274 203 lampret
        .if_stall(if_stall),
275 161 lampret
        .if_pc(if_pc),
276
        .lr_sav(lr_sav),
277
        .except_flushpipe(except_flushpipe),
278
        .except_type(except_type),
279
        .except_start(except_start),
280
        .except_started(except_started),
281
        .wb_pc(wb_pc),
282
 
283
        .datain(operand_b),
284
        .epcr_we(epcr_we),
285
        .eear_we(eear_we),
286
        .esr_we(esr_we),
287
        .epcr(epcr),
288
        .eear(eear),
289
        .esr(esr),
290
 
291
        .lsu_addr(dclsu_addr),
292
        .sr(sr)
293
);
294
 
295
//
296
// Instantiation of instruction fetch block
297
//
298
ifetch ifetch(
299
        .clk(clk),
300
        .rst(rst),
301
        .ic_insn(ic_insn),
302 203 lampret
        .ic_addr(ic_addr),
303 161 lampret
        .ic_stall(ic_stall),
304 203 lampret
        .ic_fetchop(ic_fetchop),
305 209 lampret
        .if_freeze(if_freeze),
306 161 lampret
        .if_insn(insn),
307
        .if_pc(if_pc),
308
        .branch_op(branch_op),
309
        .except_type(except_type),
310
        .except_start(except_start),
311
        .branch_addrofs(branch_addrofs),
312
        .lr_restor(operand_b),
313
        .flag(flag),
314
        .taken(branch_taken),
315
        .binsn_addr(lr_sav),
316 203 lampret
        .epcr(epcr),
317
        .force_dslot_fetch(force_dslot_fetch),
318
        .if_stall(if_stall),
319
        .branch_stall(branch_stall)
320 161 lampret
);
321
 
322
//
323
// Instantiation of instruction decode/control logic
324
//
325
id id(
326
        .clk(clk),
327
        .rst(rst),
328 205 lampret
        .id_freeze(id_freeze),
329
        .ex_freeze(ex_freeze),
330
        .wb_freeze(wb_freeze),
331 161 lampret
        .except_flushpipe(except_flushpipe),
332
        .if_insn(insn),
333
        .branch_op(branch_op),
334
        .rf_addra(rf_addra),
335
        .rf_addrb(rf_addrb),
336
        .alu_op(alu_op),
337
        .shrot_op(shrot_op),
338
        .comp_op(comp_op),
339
        .rf_addrw(rf_addrw),
340
        .rfwb_op(rfwb_op),
341
        .wb_insn(wb_insn),
342
        .simm(simm),
343
        .branch_addrofs(branch_addrofs),
344
        .lsu_addrofs(lsu_addrofs),
345
        .sel_a(sel_a),
346
        .sel_b(sel_b),
347
        .lsu_op(lsu_op),
348
        .multicycle(multicycle),
349 168 lampret
        .spr_addrimm(spr_addrimm),
350
        .wbforw_valid(wbforw_valid),
351 203 lampret
        .sig_syscall(sig_syscall),
352 209 lampret
        .force_dslot_fetch(force_dslot_fetch),
353
        .id_macrc_op(id_macrc_op),
354
        .ex_macrc_op(ex_macrc_op)
355 161 lampret
);
356
 
357
//
358
// Instantiation of write-back muxes
359
//
360
wbmux wbmux(
361
        .clk(clk),
362
        .rst(rst),
363 205 lampret
        .wb_freeze(wb_freeze),
364 161 lampret
        .rfwb_op(rfwb_op),
365
        .muxin_a(alu_dataout),
366
        .muxin_b(lsu_dataout),
367
        .muxin_c(sprs_dataout),
368
        .muxin_d({lr_sav, 2'b0}),
369
        .muxout(rf_dataw),
370
        .muxreg(wb_forw),
371
        .muxreg_valid(wbforw_valid)
372
);
373
 
374
//
375
// Instantiation of register file
376
//
377
rf rf(
378
        .clk(clk),
379
        .rst(rst),
380
        .addrw(rf_addrw),
381
        .dataw(rf_dataw),
382 205 lampret
        .id_freeze(id_freeze),
383 161 lampret
        .we(rfwb_op[0]),
384
        .addra(rf_addra),
385
        .dataa(rf_dataa),
386
        .addrb(rf_addrb),
387
        .datab(rf_datab),
388 209 lampret
        .spr_cs(spr_cs[`SPR_GROUP_SYS]),
389
        .spr_write(spr_we),
390
        .spr_addr(spr_addr),
391
        .spr_dat_i(spr_dataout),
392
        .spr_dat_o(spr_dat_rf)
393
 
394 161 lampret
);
395
 
396
//
397
// Instantiation of operand muxes
398
//
399
operandmuxes operandmuxes(
400
        .clk(clk),
401
        .rst(rst),
402 205 lampret
        .ex_freeze(ex_freeze),
403 161 lampret
        .rf_dataa(rf_dataa),
404
        .rf_datab(rf_datab),
405
        .ex_forw(rf_dataw),
406
        .wb_forw(wb_forw),
407
        .simm(simm),
408
        .sel_a(sel_a),
409
        .sel_b(sel_b),
410
        .operand_a(operand_a),
411
        .operand_b(operand_b),
412
        .muxed_b(muxed_b)
413
);
414
 
415
//
416
// Instantiation of CPU's ALU
417
//
418
alu alu(
419
        .clk(clk),
420
        .rst(rst),
421
        .a(operand_a),
422
        .b(operand_b),
423 209 lampret
        .mult_mac_result(mult_mac_result),
424
        .macrc_op(ex_macrc_op),
425 161 lampret
        .alu_op(alu_op),
426
        .shrot_op(shrot_op),
427
        .comp_op(comp_op),
428
        .result(alu_dataout),
429
        .flag(flag)
430
);
431
 
432
//
433 209 lampret
// Instantiation of CPU's ALU
434
//
435
mult_mac mult_mac(
436
        .clk(clk),
437
        .rst(rst),
438
        .id_macrc_op(id_macrc_op),
439
        .macrc_op(ex_macrc_op),
440
        .a(operand_a),
441
        .b(operand_b),
442
        .alu_op(alu_op),
443
        .result(mult_mac_result),
444
        .mac_stall_r(mac_stall)
445
);
446
 
447
//
448 161 lampret
// Instantiation of CPU's SPRS block
449
//
450
sprs sprs(
451
        .clk(clk),
452
        .rst(rst),
453 168 lampret
        .addrbase(operand_a),
454
        .addrofs(spr_addrimm),
455
        .dat_i(operand_b),
456 161 lampret
        .alu_op(alu_op),
457
        .flag(flag),
458
        .to_wbmux(sprs_dataout),
459
 
460 209 lampret
        .du_addr(du_addr),
461
        .du_dat_du(du_dat_du),
462
        .du_read(du_read),
463
        .du_write(du_write),
464
 
465 161 lampret
        .spr_addr(spr_addr),
466
        .spr_dat_pic(spr_dat_pic),
467
        .spr_dat_tt(spr_dat_tt),
468
        .spr_dat_pm(spr_dat_pm),
469 203 lampret
        .spr_dat_cfgr(spr_dat_cfgr),
470 209 lampret
        .spr_dat_rf(spr_dat_rf),
471 203 lampret
        .spr_dat_dmmu(spr_dat_dmmu),
472 209 lampret
        .spr_dat_immu(spr_dat_immu),
473
        .spr_dat_du(spr_dat_du),
474 161 lampret
        .spr_dataout(spr_dataout),
475
        .spr_cs(spr_cs),
476
        .spr_we(spr_we),
477
 
478
        .epcr_we(epcr_we),
479
        .eear_we(eear_we),
480
        .esr_we(esr_we),
481
        .epcr(epcr),
482
        .eear(eear),
483
        .esr(esr),
484
        .except_start(except_start),
485
        .except_started(except_started),
486
 
487
        .sr(sr),
488
        .branch_op(branch_op)
489
);
490
 
491
//
492
// Instantiation of load/store unit
493
//
494
lsu lsu(
495
        .clk(clk),
496
        .rst(rst),
497
        .addrbase(operand_a),
498
        .addrofs(lsu_addrofs),
499
        .lsu_op(lsu_op),
500
        .lsu_datain(operand_b),
501
        .lsu_dataout(lsu_dataout),
502
        .lsu_stall(lsu_stall),
503
        .dc_stall(dclsu_stall),
504
        .dc_addr(dclsu_addr),
505
        .dc_datain(dclsu_datain),
506
        .dc_dataout(dclsu_dataout),
507
        .dc_lsuop(dclsu_lsuop)
508
);
509
 
510
//
511
// Instantiation of freeze logic
512
//
513
frz_logic frz_logic(
514
        .clk(clk),
515
        .rst(rst),
516
        .multicycle(multicycle),
517
        .except_flushpipe(except_flushpipe),
518
        .lsu_stall(lsu_stall),
519 203 lampret
        .if_stall(if_stall),
520
        .dclsu_unstall(dclsu_unstall),
521 161 lampret
        .branch_stall(branch_stall),
522 203 lampret
        .force_dslot_fetch(force_dslot_fetch),
523 209 lampret
        .du_stall(du_stall),
524
        .mac_stall(mac_stall),
525 205 lampret
        .if_freeze(if_freeze),
526
        .id_freeze(id_freeze),
527
        .ex_freeze(ex_freeze),
528
        .wb_freeze(wb_freeze)
529 161 lampret
);
530
 
531
//
532 170 lampret
// Instantiation of configuration registers
533
//
534
cfgr cfgr(
535
        .clk(clk),
536
        .rst(clk),
537
        .spr_addr(spr_addr),
538
        .spr_dat_o(spr_dat_cfgr)
539
);
540
 
541 161 lampret
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.