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

Subversion Repositories openriscdevboard

[/] [openriscdevboard/] [trunk/] [cyc2-openrisc/] [rtl/] [or1200/] [or1200_genpc.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sfielding
//////////////////////////////////////////////////////////////////////
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.1  2006/12/21 16:46:58  vak
48
// Initial revision imported from
49
// http://www.opencores.org/cvsget.cgi/or1k/orp/orp_soc/rtl/verilog.
50
//
51
// Revision 1.10  2004/06/08 18:17:36  lampret
52
// Non-functional changes. Coding style fixes.
53
//
54
// Revision 1.9  2004/04/05 08:29:57  lampret
55
// Merged branch_qmem into main tree.
56
//
57
// Revision 1.7.4.3  2003/12/17 13:43:38  simons
58
// Exception prefix configuration changed.
59
//
60
// Revision 1.7.4.2  2003/12/04 23:44:31  lampret
61
// Static exception prefix.
62
//
63
// Revision 1.7.4.1  2003/07/08 15:36:37  lampret
64
// Added embedded memory QMEM.
65
//
66
// Revision 1.7  2003/04/20 22:23:57  lampret
67
// No functional change. Only added customization for exception vectors.
68
//
69
// Revision 1.6  2002/03/29 15:16:55  lampret
70
// Some of the warnings fixed.
71
//
72
// Revision 1.5  2002/02/11 04:33:17  lampret
73
// Speed optimizations (removed duplicate _cyc_ and _stb_). Fixed D/IMMU cache-inhibit attr.
74
//
75
// Revision 1.4  2002/01/28 01:16:00  lampret
76
// 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.
77
//
78
// Revision 1.3  2002/01/18 07:56:00  lampret
79
// No more low/high priority interrupts (PICPR removed). Added tick timer exception. Added exception prefix (SR[EPH]). Fixed single-step bug whenreading NPC.
80
//
81
// Revision 1.2  2002/01/14 06:18:22  lampret
82
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
83
//
84
// Revision 1.1  2002/01/03 08:16:15  lampret
85
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
86
//
87
// Revision 1.10  2001/11/20 18:46:15  simons
88
// Break point bug fixed
89
//
90
// Revision 1.9  2001/11/18 09:58:28  lampret
91
// Fixed some l.trap typos.
92
//
93
// Revision 1.8  2001/11/18 08:36:28  lampret
94
// For GDB changed single stepping and disabled trap exception.
95
//
96
// Revision 1.7  2001/10/21 17:57:16  lampret
97
// 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.
98
//
99
// Revision 1.6  2001/10/14 13:12:09  lampret
100
// MP3 version.
101
//
102
// Revision 1.1.1.1  2001/10/06 10:18:36  igorm
103
// no message
104
//
105
// Revision 1.1  2001/08/09 13:39:33  lampret
106
// Major clean-up.
107
//
108
//
109
 
110
// synopsys translate_off
111
`include "timescale.v"
112
// synopsys translate_on
113
`include "or1200_defines.v"
114
 
115
module or1200_genpc(
116
        // Clock and reset
117
        clk, rst,
118
 
119
        // External i/f to IC
120
        icpu_adr_o, icpu_cycstb_o, icpu_sel_o, icpu_tag_o,
121
        icpu_rty_i, icpu_adr_i,
122
 
123
        // Internal i/f
124
        branch_op, except_type, except_prefix,
125
        branch_addrofs, lr_restor, flag, taken, except_start,
126
        binsn_addr, epcr, spr_dat_i, spr_pc_we, genpc_refetch,
127
        genpc_freeze, genpc_stop_prefetch, no_more_dslot
128
);
129
 
130
//
131
// I/O
132
//
133
 
134
//
135
// Clock and reset
136
//
137
input                           clk;
138
input                           rst;
139
 
140
//
141
// External i/f to IC
142
//
143
output  [31:0]                   icpu_adr_o;
144
output                          icpu_cycstb_o;
145
output  [3:0]                    icpu_sel_o;
146
output  [3:0]                    icpu_tag_o;
147
input                           icpu_rty_i;
148
input   [31:0]                   icpu_adr_i;
149
 
150
//
151
// Internal i/f
152
//
153
input   [`OR1200_BRANCHOP_WIDTH-1:0]     branch_op;
154
input   [`OR1200_EXCEPT_WIDTH-1:0]       except_type;
155
input                                   except_prefix;
156
input   [31:2]                  branch_addrofs;
157
input   [31:0]                   lr_restor;
158
input                           flag;
159
output                          taken;
160
input                           except_start;
161
input   [31:2]                  binsn_addr;
162
input   [31:0]                   epcr;
163
input   [31:0]                   spr_dat_i;
164
input                           spr_pc_we;
165
input                           genpc_refetch;
166
input                           genpc_stop_prefetch;
167
input                           genpc_freeze;
168
input                           no_more_dslot;
169
 
170
//
171
// Internal wires and regs
172
//
173
reg     [31:2]                  pcreg;
174
reg     [31:0]                   pc;
175
reg                             taken;  /* Set to in case of jump or taken branch */
176
reg                             genpc_refetch_r;
177
 
178
//
179
// Address of insn to be fecthed
180
//
181
assign icpu_adr_o = !no_more_dslot & !except_start & !spr_pc_we & (icpu_rty_i | genpc_refetch) ? icpu_adr_i : pc;
182
// assign icpu_adr_o = !except_start & !spr_pc_we & (icpu_rty_i | genpc_refetch) ? icpu_adr_i : pc;
183
 
184
//
185
// Control access to IC subsystem
186
//
187
// assign icpu_cycstb_o = !genpc_freeze & !no_more_dslot;
188
assign icpu_cycstb_o = !genpc_freeze; // works, except remaining raised cycstb during long load/store
189
//assign icpu_cycstb_o = !(genpc_freeze | genpc_refetch & genpc_refetch_r);
190
//assign icpu_cycstb_o = !(genpc_freeze | genpc_stop_prefetch);
191
assign icpu_sel_o = 4'b1111;
192
assign icpu_tag_o = `OR1200_ITAG_NI;
193
 
194
//
195
// genpc_freeze_r
196
//
197
always @(posedge clk or posedge rst)
198
        if (rst)
199
                genpc_refetch_r <= #1 1'b0;
200
        else if (genpc_refetch)
201
                genpc_refetch_r <= #1 1'b1;
202
        else
203
                genpc_refetch_r <= #1 1'b0;
204
 
205
//
206
// Async calculation of new PC value. This value is used for addressing the IC.
207
//
208
always @(pcreg or branch_addrofs or binsn_addr or flag or branch_op or except_type
209
        or except_start or lr_restor or epcr or spr_pc_we or spr_dat_i or except_prefix) begin
210
        casex ({spr_pc_we, except_start, branch_op})    // synopsys parallel_case
211
                {2'b00, `OR1200_BRANCHOP_NOP}: begin
212
                        pc = {pcreg + 30'd1, 2'b0};
213
                        taken = 1'b0;
214
                end
215
                {2'b00, `OR1200_BRANCHOP_J}: begin
216
`ifdef OR1200_VERBOSE
217
// synopsys translate_off
218
                        $display("%t: BRANCHOP_J: pc <= branch_addrofs %h", $time, branch_addrofs);
219
// synopsys translate_on
220
`endif
221
                        pc = {branch_addrofs, 2'b0};
222
                        taken = 1'b1;
223
                end
224
                {2'b00, `OR1200_BRANCHOP_JR}: begin
225
`ifdef OR1200_VERBOSE
226
// synopsys translate_off
227
                        $display("%t: BRANCHOP_JR: pc <= lr_restor %h", $time, lr_restor);
228
// synopsys translate_on
229
`endif
230
                        pc = lr_restor;
231
                        taken = 1'b1;
232
                end
233
                {2'b00, `OR1200_BRANCHOP_BAL}: begin
234
`ifdef OR1200_VERBOSE
235
// synopsys translate_off
236
                        $display("%t: BRANCHOP_BAL: pc %h = binsn_addr %h + branch_addrofs %h", $time, binsn_addr + branch_addrofs, binsn_addr, branch_addrofs);
237
// synopsys translate_on
238
`endif
239
                        pc = {binsn_addr + branch_addrofs, 2'b0};
240
                        taken = 1'b1;
241
                end
242
                {2'b00, `OR1200_BRANCHOP_BF}:
243
                        if (flag) begin
244
`ifdef OR1200_VERBOSE
245
// synopsys translate_off
246
                                $display("%t: BRANCHOP_BF: pc %h = binsn_addr %h + branch_addrofs %h", $time, binsn_addr + branch_addrofs, binsn_addr, branch_addrofs);
247
// synopsys translate_on
248
`endif
249
                                pc = {binsn_addr + branch_addrofs, 2'b0};
250
                                taken = 1'b1;
251
                        end
252
                        else begin
253
`ifdef OR1200_VERBOSE
254
// synopsys translate_off
255
                                $display("%t: BRANCHOP_BF: not taken", $time);
256
// synopsys translate_on
257
`endif
258
                                pc = {pcreg + 30'd1, 2'b0};
259
                                taken = 1'b0;
260
                        end
261
                {2'b00, `OR1200_BRANCHOP_BNF}:
262
                        if (flag) begin
263
                                pc = {pcreg + 30'd1, 2'b0};
264
`ifdef OR1200_VERBOSE
265
// synopsys translate_off
266
                                $display("%t: BRANCHOP_BNF: not taken", $time);
267
// synopsys translate_on
268
`endif
269
                                taken = 1'b0;
270
                        end
271
                        else begin
272
`ifdef OR1200_VERBOSE
273
// synopsys translate_off
274
                                $display("%t: BRANCHOP_BNF: pc %h = binsn_addr %h + branch_addrofs %h", $time, binsn_addr + branch_addrofs, binsn_addr, branch_addrofs);
275
// synopsys translate_on
276
`endif
277
                                pc = {binsn_addr + branch_addrofs, 2'b0};
278
                                taken = 1'b1;
279
                        end
280
                {2'b00, `OR1200_BRANCHOP_RFE}: begin
281
`ifdef OR1200_VERBOSE
282
// synopsys translate_off
283
                        $display("%t: BRANCHOP_RFE: pc <= epcr %h", $time, epcr);
284
// synopsys translate_on
285
`endif
286
                        pc = epcr;
287
                        taken = 1'b1;
288
                end
289
                {2'b01, 3'bxxx}: begin
290
`ifdef OR1200_VERBOSE
291
// synopsys translate_off
292
                        $display("Starting exception: %h.", except_type);
293
// synopsys translate_on
294
`endif
295
                        pc = {(except_prefix ? `OR1200_EXCEPT_EPH1_P : `OR1200_EXCEPT_EPH0_P), except_type, `OR1200_EXCEPT_V};
296
                        taken = 1'b1;
297
                end
298
                default: begin
299
`ifdef OR1200_VERBOSE
300
// synopsys translate_off
301
                        $display("l.mtspr writing into PC: %h.", spr_dat_i);
302
// synopsys translate_on
303
`endif
304
                        pc = spr_dat_i;
305
                        taken = 1'b0;
306
                end
307
        endcase
308
end
309
 
310
//
311
// PC register
312
//
313
always @(posedge clk or posedge rst)
314
        if (rst)
315
//              pcreg <= #1 30'd63;
316
                pcreg <= #1 ({(except_prefix ? `OR1200_EXCEPT_EPH1_P : `OR1200_EXCEPT_EPH0_P), `OR1200_EXCEPT_RESET, `OR1200_EXCEPT_V} - 1) >> 2;
317
        else if (spr_pc_we)
318
                pcreg <= #1 spr_dat_i[31:2];
319
        else if (no_more_dslot | except_start | !genpc_freeze & !icpu_rty_i & !genpc_refetch)
320
//      else if (except_start | !genpc_freeze & !icpu_rty_i & !genpc_refetch)
321
                pcreg <= #1 pc[31:2];
322
 
323
endmodule

powered by: WebSVN 2.1.0

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