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

Subversion Repositories or1200_hp

[/] [or1200_hp/] [trunk/] [rtl/] [rtl_cm4/] [verilog/] [or1200_genpc.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 tobil
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's generate PC                                        ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6
////  http://www.opencores.org/cores/or1k/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  PC, interface to IC.                                        ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////   - make it smaller and faster                               ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Damjan Lampret, lampret@opencores.org                 ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
20
////                                                              ////
21
//// This source file may be used and distributed without         ////
22
//// restriction provided that this copyright statement is not    ////
23
//// removed from the file and that any derivative work contains  ////
24
//// the original copyright notice and the associated disclaimer. ////
25
////                                                              ////
26
//// This source file is free software; you can redistribute it   ////
27
//// and/or modify it under the terms of the GNU Lesser General   ////
28
//// Public License as published by the Free Software Foundation; ////
29
//// either version 2.1 of the License, or (at your option) any   ////
30
//// later version.                                               ////
31
////                                                              ////
32
//// This source is distributed in the hope that it will be       ////
33
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
34
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
35
//// PURPOSE.  See the GNU Lesser General Public License for more ////
36
//// details.                                                     ////
37
////                                                              ////
38
//// You should have received a copy of the GNU Lesser General    ////
39
//// Public License along with this source; if not, download it   ////
40
//// from http://www.opencores.org/lgpl.shtml                     ////
41
////                                                              ////
42
//////////////////////////////////////////////////////////////////////
43
//
44
// CVS Revision History
45
//
46
// $Log: not supported by cvs2svn $
47
// Revision 1.9  2004/04/05 08:29:57  lampret
48
// Merged branch_qmem into main tree.
49
//
50
// Revision 1.7.4.3  2003/12/17 13:43:38  simons
51
// Exception prefix configuration changed.
52
//
53
// Revision 1.7.4.2  2003/12/04 23:44:31  lampret
54
// Static exception prefix.
55
//
56
// Revision 1.7.4.1  2003/07/08 15:36:37  lampret
57
// Added embedded memory QMEM.
58
//
59
// Revision 1.7  2003/04/20 22:23:57  lampret
60
// No functional change. Only added customization for exception vectors.
61
//
62
// Revision 1.6  2002/03/29 15:16:55  lampret
63
// Some of the warnings fixed.
64
//
65
// Revision 1.5  2002/02/11 04:33:17  lampret
66
// Speed optimizations (removed duplicate _cyc_ and _stb_). Fixed D/IMMU cache-inhibit attr.
67
//
68
// Revision 1.4  2002/01/28 01:16:00  lampret
69
// Changed 'void' nop-ops instead of insn[0] to use insn[16]. Debug unit stalls the tick timer. Prepared new flag generation for add and and insns. Blocked DC/IC while they are turned off. Fixed I/D MMU SPRs layout except WAYs. TODO: smart IC invalidate, l.j 2 and TLB ways.
70
//
71
// Revision 1.3  2002/01/18 07:56:00  lampret
72
// No more low/high priority interrupts (PICPR removed). Added tick timer exception. Added exception prefix (SR[EPH]). Fixed single-step bug whenreading NPC.
73
//
74
// Revision 1.2  2002/01/14 06:18:22  lampret
75
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
76
//
77
// Revision 1.1  2002/01/03 08:16:15  lampret
78
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
79
//
80
// Revision 1.10  2001/11/20 18:46:15  simons
81
// Break point bug fixed
82
//
83
// Revision 1.9  2001/11/18 09:58:28  lampret
84
// Fixed some l.trap typos.
85
//
86
// Revision 1.8  2001/11/18 08:36:28  lampret
87
// For GDB changed single stepping and disabled trap exception.
88
//
89
// Revision 1.7  2001/10/21 17:57:16  lampret
90
// Removed params from generic_XX.v. Added translate_off/on in sprs.v and id.v. Removed spr_addr from dc.v and ic.v. Fixed CR+LF.
91
//
92
// Revision 1.6  2001/10/14 13:12:09  lampret
93
// MP3 version.
94
//
95
// Revision 1.1.1.1  2001/10/06 10:18:36  igorm
96
// no message
97
//
98
// Revision 1.1  2001/08/09 13:39:33  lampret
99
// Major clean-up.
100
//
101
//
102
 
103
// synopsys translate_off
104
`include "timescale.v"
105
// synopsys translate_on
106
`include "or1200_defines.v"
107
 
108
module or1200_genpc_cm4(
109
                clk_i_cml_1,
110
                clk_i_cml_2,
111
                clk_i_cml_3,
112
 
113
        // Clock and reset
114
        clk, rst,
115
 
116
        // External i/f to IC
117
        icpu_adr_o, icpu_cycstb_o, icpu_sel_o, icpu_tag_o,
118
        icpu_rty_i, icpu_adr_i,
119
 
120
        // Internal i/f
121
        branch_op, except_type, except_prefix,
122
        branch_addrofs, lr_restor, flag, taken, except_start,
123
        binsn_addr, epcr, spr_dat_i, spr_pc_we, genpc_refetch,
124
        genpc_freeze, genpc_stop_prefetch, no_more_dslot
125
);
126
 
127
 
128
input clk_i_cml_1;
129
input clk_i_cml_2;
130
input clk_i_cml_3;
131
reg  icpu_rty_i_cml_3;
132
reg  icpu_rty_i_cml_2;
133
reg [ 31 : 0 ] icpu_adr_i_cml_1;
134
reg [ 3 - 1 : 0 ] branch_op_cml_1;
135
reg [ 4 - 1 : 0 ] except_type_cml_1;
136
reg  except_prefix_cml_3;
137
reg  except_prefix_cml_2;
138
reg  except_prefix_cml_1;
139
reg [ 31 : 2 ] branch_addrofs_cml_1;
140
reg [ 31 : 0 ] lr_restor_cml_1;
141
reg  flag_cml_1;
142
reg  except_start_cml_3;
143
reg  except_start_cml_2;
144
reg  except_start_cml_1;
145
reg [ 31 : 2 ] binsn_addr_cml_1;
146
reg [ 31 : 0 ] epcr_cml_1;
147
reg [ 31 : 0 ] spr_dat_i_cml_3;
148
reg [ 31 : 0 ] spr_dat_i_cml_2;
149
reg [ 31 : 0 ] spr_dat_i_cml_1;
150
reg  spr_pc_we_cml_3;
151
reg  spr_pc_we_cml_2;
152
reg  genpc_refetch_cml_3;
153
reg  genpc_refetch_cml_2;
154
reg  no_more_dslot_cml_3;
155
reg  no_more_dslot_cml_2;
156
reg [ 31 : 2 ] pcreg_cml_3;
157
reg [ 31 : 2 ] pcreg_cml_2;
158
reg [ 31 : 2 ] pcreg_cml_1;
159
reg [ 31 : 0 ] pc_cml_3;
160
reg [ 31 : 0 ] pc_cml_2;
161
reg  genpc_refetch_r_cml_3;
162
reg  genpc_refetch_r_cml_2;
163
reg  genpc_refetch_r_cml_1;
164
 
165
 
166
 
167
//
168
// I/O
169
//
170
 
171
//
172
// Clock and reset
173
//
174
input                           clk;
175
input                           rst;
176
 
177
//
178
// External i/f to IC
179
//
180
output  [31:0]                   icpu_adr_o;
181
output                          icpu_cycstb_o;
182
output  [3:0]                    icpu_sel_o;
183
output  [3:0]                    icpu_tag_o;
184
input                           icpu_rty_i;
185
input   [31:0]                   icpu_adr_i;
186
 
187
//
188
// Internal i/f
189
//
190
input   [`OR1200_BRANCHOP_WIDTH-1:0]     branch_op;
191
input   [`OR1200_EXCEPT_WIDTH-1:0]       except_type;
192
input                                   except_prefix;
193
input   [31:2]                  branch_addrofs;
194
input   [31:0]                   lr_restor;
195
input                           flag;
196
output                          taken;
197
input                           except_start;
198
input   [31:2]                  binsn_addr;
199
input   [31:0]                   epcr;
200
input   [31:0]                   spr_dat_i;
201
input                           spr_pc_we;
202
input                           genpc_refetch;
203
input                           genpc_stop_prefetch;
204
input                           genpc_freeze;
205
input                           no_more_dslot;
206
 
207
//
208
// Internal wires and regs
209
//
210
reg     [31:2]                  pcreg;
211
reg     [31:0]                   pc;
212
reg                             taken;  /* Set to in case of jump or taken branch */
213
reg                             genpc_refetch_r;
214
 
215
//
216
// Address of insn to be fecthed
217
//
218
 
219
// SynEDA CoreMultiplier
220
// assignment(s): icpu_adr_o
221
// replace(s): icpu_adr_i, except_start
222
assign icpu_adr_o = !no_more_dslot & !except_start_cml_1 & !spr_pc_we & (icpu_rty_i | genpc_refetch) ? icpu_adr_i_cml_1 : pc;
223
// assign icpu_adr_o = !except_start & !spr_pc_we & (icpu_rty_i | genpc_refetch) ? icpu_adr_i : pc;
224
 
225
//
226
// Control access to IC subsystem
227
//
228
// assign icpu_cycstb_o = !genpc_freeze & !no_more_dslot;
229
assign icpu_cycstb_o = !genpc_freeze; // works, except remaining raised cycstb during long load/store
230
//assign icpu_cycstb_o = !(genpc_freeze | genpc_refetch & genpc_refetch_r);
231
//assign icpu_cycstb_o = !(genpc_freeze | genpc_stop_prefetch);
232
assign icpu_sel_o = 4'b1111;
233
assign icpu_tag_o = `OR1200_ITAG_NI;
234
 
235
//
236
// genpc_freeze_r
237
//
238
 
239
// SynEDA CoreMultiplier
240
// assignment(s): genpc_refetch_r
241
// replace(s): genpc_refetch, genpc_refetch_r
242
always @(posedge clk or posedge rst)
243
        if (rst)
244
                genpc_refetch_r <= #1 1'b0;
245
        else begin  genpc_refetch_r <= genpc_refetch_r_cml_3; if (genpc_refetch_cml_3)
246
                genpc_refetch_r <= #1 1'b1;
247
        else
248
                genpc_refetch_r <= #1 1'b0; end
249
 
250
//
251
// Async calculation of new PC value. This value is used for addressing the IC.
252
//
253
 
254
// SynEDA CoreMultiplier
255
// assignment(s): pc
256
// replace(s): branch_op, except_type, except_prefix, branch_addrofs, lr_restor, flag, except_start, binsn_addr, epcr, spr_dat_i, pcreg
257
always @(pcreg_cml_1 or branch_addrofs_cml_1 or binsn_addr_cml_1 or flag_cml_1 or branch_op_cml_1 or except_type_cml_1
258
        or except_start_cml_1 or lr_restor_cml_1 or epcr_cml_1 or spr_pc_we or spr_dat_i_cml_1 or except_prefix_cml_1) begin
259
        casex ({spr_pc_we, except_start_cml_1, branch_op_cml_1})        // synopsys parallel_case
260
                {2'b00, `OR1200_BRANCHOP_NOP}: begin
261
                        pc = {pcreg_cml_1 + 30'd1, 2'b0};
262
                end
263
                {2'b00, `OR1200_BRANCHOP_J}: begin
264
`ifdef OR1200_VERBOSE
265
// synopsys translate_off
266
                        $display("%t: BRANCHOP_J: pc <= branch_addrofs_cml_1 %h", $time, branch_addrofs_cml_1);
267
// synopsys translate_on
268
`endif
269
                        pc = {branch_addrofs_cml_1, 2'b0};
270
                end
271
                {2'b00, `OR1200_BRANCHOP_JR}: begin
272
`ifdef OR1200_VERBOSE
273
// synopsys translate_off
274
                        $display("%t: BRANCHOP_JR: pc <= lr_restor_cml_1 %h", $time, lr_restor_cml_1);
275
// synopsys translate_on
276
`endif
277
                        pc = lr_restor_cml_1;
278
                end
279
                {2'b00, `OR1200_BRANCHOP_BAL}: begin
280
`ifdef OR1200_VERBOSE
281
// synopsys translate_off
282
                        $display("%t: BRANCHOP_BAL: pc %h = binsn_addr_cml_1 %h + branch_addrofs_cml_1 %h", $time, binsn_addr_cml_1 + branch_addrofs_cml_1, binsn_addr_cml_1, branch_addrofs_cml_1);
283
// synopsys translate_on
284
`endif
285
                        pc = {binsn_addr_cml_1 + branch_addrofs_cml_1, 2'b0};
286
                end
287
                {2'b00, `OR1200_BRANCHOP_BF}:
288
                        if (flag_cml_1) begin
289
`ifdef OR1200_VERBOSE
290
// synopsys translate_off
291
                                $display("%t: BRANCHOP_BF: pc %h = binsn_addr_cml_1 %h + branch_addrofs_cml_1 %h", $time, binsn_addr_cml_1 + branch_addrofs_cml_1, binsn_addr_cml_1, branch_addrofs_cml_1);
292
// synopsys translate_on
293
`endif
294
                                pc = {binsn_addr_cml_1 + branch_addrofs_cml_1, 2'b0};
295
                        end
296
                        else begin
297
`ifdef OR1200_VERBOSE
298
// synopsys translate_off
299
                                $display("%t: BRANCHOP_BF: not taken", $time);
300
// synopsys translate_on
301
`endif
302
                                pc = {pcreg_cml_1 + 30'd1, 2'b0};
303
                        end
304
                {2'b00, `OR1200_BRANCHOP_BNF}:
305
                        if (flag_cml_1) begin
306
                                pc = {pcreg_cml_1 + 30'd1, 2'b0};
307
`ifdef OR1200_VERBOSE
308
// synopsys translate_off
309
                                $display("%t: BRANCHOP_BNF: not taken", $time);
310
// synopsys translate_on
311
`endif
312
                        end
313
                        else begin
314
`ifdef OR1200_VERBOSE
315
// synopsys translate_off
316
                                $display("%t: BRANCHOP_BNF: pc %h = binsn_addr_cml_1 %h + branch_addrofs_cml_1 %h", $time, binsn_addr_cml_1 + branch_addrofs_cml_1, binsn_addr_cml_1, branch_addrofs_cml_1);
317
// synopsys translate_on
318
`endif
319
                                pc = {binsn_addr_cml_1 + branch_addrofs_cml_1, 2'b0};
320
                        end
321
                {2'b00, `OR1200_BRANCHOP_RFE}: begin
322
`ifdef OR1200_VERBOSE
323
// synopsys translate_off
324
                        $display("%t: BRANCHOP_RFE: pc <= epcr_cml_1 %h", $time, epcr_cml_1);
325
// synopsys translate_on
326
`endif
327
                        pc = epcr_cml_1;
328
                end
329
                {2'b01, 3'bxxx}: begin
330
`ifdef OR1200_VERBOSE
331
// synopsys translate_off
332
                        $display("Starting exception: %h.", except_type);
333
// synopsys translate_on
334
`endif
335
                        pc = {(except_prefix_cml_1 ? `OR1200_EXCEPT_EPH1_P : `OR1200_EXCEPT_EPH0_P), except_type_cml_1, `OR1200_EXCEPT_V};
336
                end
337
                default: begin
338
`ifdef OR1200_VERBOSE
339
// synopsys translate_off
340
                        $display("l.mtspr writing into PC: %h.", spr_dat_i);
341
// synopsys translate_on
342
`endif
343
                        pc = spr_dat_i_cml_1;
344
                end
345
        endcase
346
end
347
 
348
 
349
// SynEDA CoreMultiplier
350
// assignment(s): taken
351
// replace(s): branch_op, flag, except_start
352
always @(pcreg or branch_addrofs or binsn_addr or flag_cml_1 or branch_op_cml_1 or except_type
353
        or except_start_cml_1 or lr_restor or epcr or spr_pc_we or spr_dat_i or except_prefix) begin
354
        casex ({spr_pc_we, except_start_cml_1, branch_op_cml_1})        // synopsys parallel_case
355
                {2'b00, `OR1200_BRANCHOP_NOP}: begin
356
                        taken = 1'b0;
357
                end
358
                {2'b00, `OR1200_BRANCHOP_J}: begin
359
                        taken = 1'b1;
360
                end
361
                {2'b00, `OR1200_BRANCHOP_JR}: begin
362
                        taken = 1'b1;
363
                end
364
                {2'b00, `OR1200_BRANCHOP_BAL}: begin
365
                        taken = 1'b1;
366
                end
367
                {2'b00, `OR1200_BRANCHOP_BF}:
368
                        if (flag_cml_1) begin
369
                                taken = 1'b1;
370
                        end
371
                        else begin
372
                                taken = 1'b0;
373
                        end
374
                {2'b00, `OR1200_BRANCHOP_BNF}:
375
                        if (flag_cml_1) begin
376
                                taken = 1'b0;
377
                        end
378
                        else begin
379
                                taken = 1'b1;
380
                        end
381
                {2'b00, `OR1200_BRANCHOP_RFE}: begin
382
                        taken = 1'b1;
383
                end
384
                {2'b01, 3'bxxx}: begin
385
                        taken = 1'b1;
386
                end
387
                default: begin
388
                        taken = 1'b0;
389
                end
390
        endcase
391
end
392
 
393
//
394
// PC register
395
//
396
 
397
// SynEDA CoreMultiplier
398
// assignment(s): pcreg
399
// replace(s): icpu_rty_i, except_prefix, except_start, spr_dat_i, spr_pc_we, genpc_refetch, no_more_dslot, pcreg, pc
400
always @(posedge clk or posedge rst)
401
        if (rst)
402
//              pcreg <= #1 30'd63;
403
                pcreg <= #1 ({(except_prefix_cml_3 ? `OR1200_EXCEPT_EPH1_P : `OR1200_EXCEPT_EPH0_P), `OR1200_EXCEPT_RESET, `OR1200_EXCEPT_V} - 1) >> 2;
404
        else begin  pcreg <= pcreg_cml_3; if (spr_pc_we_cml_3)
405
                pcreg <= #1 spr_dat_i_cml_3[31:2];
406
        else if (no_more_dslot_cml_3 | except_start_cml_3 | !genpc_freeze & !icpu_rty_i_cml_3 & !genpc_refetch_cml_3)
407
//      else if (except_start | !genpc_freeze & !icpu_rty_i & !genpc_refetch)
408
                pcreg <= #1 pc_cml_3[31:2]; end
409
 
410
 
411
always @ (posedge clk_i_cml_1) begin
412
icpu_adr_i_cml_1 <= icpu_adr_i;
413
branch_op_cml_1 <= branch_op;
414
except_type_cml_1 <= except_type;
415
except_prefix_cml_1 <= except_prefix;
416
branch_addrofs_cml_1 <= branch_addrofs;
417
lr_restor_cml_1 <= lr_restor;
418
flag_cml_1 <= flag;
419
except_start_cml_1 <= except_start;
420
binsn_addr_cml_1 <= binsn_addr;
421
epcr_cml_1 <= epcr;
422
spr_dat_i_cml_1 <= spr_dat_i;
423
pcreg_cml_1 <= pcreg;
424
genpc_refetch_r_cml_1 <= genpc_refetch_r;
425
end
426
always @ (posedge clk_i_cml_2) begin
427
icpu_rty_i_cml_2 <= icpu_rty_i;
428
except_prefix_cml_2 <= except_prefix_cml_1;
429
except_start_cml_2 <= except_start_cml_1;
430
spr_dat_i_cml_2 <= spr_dat_i_cml_1;
431
spr_pc_we_cml_2 <= spr_pc_we;
432
genpc_refetch_cml_2 <= genpc_refetch;
433
no_more_dslot_cml_2 <= no_more_dslot;
434
pcreg_cml_2 <= pcreg_cml_1;
435
pc_cml_2 <= pc;
436
genpc_refetch_r_cml_2 <= genpc_refetch_r_cml_1;
437
end
438
always @ (posedge clk_i_cml_3) begin
439
icpu_rty_i_cml_3 <= icpu_rty_i_cml_2;
440
except_prefix_cml_3 <= except_prefix_cml_2;
441
except_start_cml_3 <= except_start_cml_2;
442
spr_dat_i_cml_3 <= spr_dat_i_cml_2;
443
spr_pc_we_cml_3 <= spr_pc_we_cml_2;
444
genpc_refetch_cml_3 <= genpc_refetch_cml_2;
445
no_more_dslot_cml_3 <= no_more_dslot_cml_2;
446
pcreg_cml_3 <= pcreg_cml_2;
447
pc_cml_3 <= pc_cml_2;
448
genpc_refetch_r_cml_3 <= genpc_refetch_r_cml_2;
449
end
450
endmodule
451
 

powered by: WebSVN 2.1.0

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