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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1200/] [rtl/] [verilog/] [or1200_genpc.v] - Blame information for rev 85

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

Line No. Rev Author Line
1 10 unneback
//////////////////////////////////////////////////////////////////////
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(
109
        // Clock and reset
110
        clk, rst,
111
 
112
        // External i/f to IC
113
        icpu_adr_o, icpu_cycstb_o, icpu_sel_o, icpu_tag_o,
114
        icpu_rty_i, icpu_adr_i,
115
 
116
        // Internal i/f
117
        branch_op, except_type, except_prefix,
118
        branch_addrofs, lr_restor, flag, taken, except_start,
119
        binsn_addr, epcr, spr_dat_i, spr_pc_we, genpc_refetch,
120
        genpc_freeze, genpc_stop_prefetch, no_more_dslot
121
);
122
 
123
//
124
// I/O
125
//
126
 
127
//
128
// Clock and reset
129
//
130
input                           clk;
131
input                           rst;
132
 
133
//
134
// External i/f to IC
135
//
136
output  [31:0]                   icpu_adr_o;
137
output                          icpu_cycstb_o;
138
output  [3:0]                    icpu_sel_o;
139
output  [3:0]                    icpu_tag_o;
140
input                           icpu_rty_i;
141
input   [31:0]                   icpu_adr_i;
142
 
143
//
144
// Internal i/f
145
//
146
input   [`OR1200_BRANCHOP_WIDTH-1:0]     branch_op;
147
input   [`OR1200_EXCEPT_WIDTH-1:0]       except_type;
148
input                                   except_prefix;
149
input   [31:2]                  branch_addrofs;
150
input   [31:0]                   lr_restor;
151
input                           flag;
152
output                          taken;
153
input                           except_start;
154
input   [31:2]                  binsn_addr;
155
input   [31:0]                   epcr;
156
input   [31:0]                   spr_dat_i;
157
input                           spr_pc_we;
158
input                           genpc_refetch;
159
input                           genpc_stop_prefetch;
160
input                           genpc_freeze;
161
input                           no_more_dslot;
162
 
163
//
164
// Internal wires and regs
165
//
166
reg     [31:2]                  pcreg;
167
reg     [31:0]                   pc;
168
reg                             taken;  /* Set to in case of jump or taken branch */
169
reg                             genpc_refetch_r;
170
 
171
//
172
// Address of insn to be fecthed
173
//
174
assign icpu_adr_o = !no_more_dslot & !except_start & !spr_pc_we & (icpu_rty_i | genpc_refetch) ? icpu_adr_i : pc;
175
// assign icpu_adr_o = !except_start & !spr_pc_we & (icpu_rty_i | genpc_refetch) ? icpu_adr_i : pc;
176
 
177
//
178
// Control access to IC subsystem
179
//
180
// assign icpu_cycstb_o = !genpc_freeze & !no_more_dslot;
181
assign icpu_cycstb_o = !genpc_freeze; // works, except remaining raised cycstb during long load/store
182
//assign icpu_cycstb_o = !(genpc_freeze | genpc_refetch & genpc_refetch_r);
183
//assign icpu_cycstb_o = !(genpc_freeze | genpc_stop_prefetch);
184
assign icpu_sel_o = 4'b1111;
185
assign icpu_tag_o = `OR1200_ITAG_NI;
186
 
187
//
188
// genpc_freeze_r
189
//
190
always @(posedge clk or posedge rst)
191
        if (rst)
192
                genpc_refetch_r <= #1 1'b0;
193
        else if (genpc_refetch)
194
                genpc_refetch_r <= #1 1'b1;
195
        else
196
                genpc_refetch_r <= #1 1'b0;
197
 
198
//
199
// Async calculation of new PC value. This value is used for addressing the IC.
200
//
201
always @(pcreg or branch_addrofs or binsn_addr or flag or branch_op or except_type
202
        or except_start or lr_restor or epcr or spr_pc_we or spr_dat_i or except_prefix) begin
203
        casex ({spr_pc_we, except_start, branch_op})    // synopsys parallel_case
204
                {2'b00, `OR1200_BRANCHOP_NOP}: begin
205
                        pc = {pcreg + 30'd1, 2'b0};
206
                        taken = 1'b0;
207
                end
208
                {2'b00, `OR1200_BRANCHOP_J}: begin
209
`ifdef OR1200_VERBOSE
210
// synopsys translate_off
211
                        $display("%t: BRANCHOP_J: pc <= branch_addrofs %h", $time, branch_addrofs);
212
// synopsys translate_on
213
`endif
214
                        pc = {branch_addrofs, 2'b0};
215
                        taken = 1'b1;
216
                end
217
                {2'b00, `OR1200_BRANCHOP_JR}: begin
218
`ifdef OR1200_VERBOSE
219
// synopsys translate_off
220
                        $display("%t: BRANCHOP_JR: pc <= lr_restor %h", $time, lr_restor);
221
// synopsys translate_on
222
`endif
223
                        pc = lr_restor;
224
                        taken = 1'b1;
225
                end
226
                {2'b00, `OR1200_BRANCHOP_BAL}: begin
227
`ifdef OR1200_VERBOSE
228
// synopsys translate_off
229
                        $display("%t: BRANCHOP_BAL: pc %h = binsn_addr %h + branch_addrofs %h", $time, binsn_addr + branch_addrofs, binsn_addr, branch_addrofs);
230
// synopsys translate_on
231
`endif
232
                        pc = {binsn_addr + branch_addrofs, 2'b0};
233
                        taken = 1'b1;
234
                end
235
                {2'b00, `OR1200_BRANCHOP_BF}:
236
                        if (flag) begin
237
`ifdef OR1200_VERBOSE
238
// synopsys translate_off
239
                                $display("%t: BRANCHOP_BF: pc %h = binsn_addr %h + branch_addrofs %h", $time, binsn_addr + branch_addrofs, binsn_addr, branch_addrofs);
240
// synopsys translate_on
241
`endif
242
                                pc = {binsn_addr + branch_addrofs, 2'b0};
243
                                taken = 1'b1;
244
                        end
245
                        else begin
246
`ifdef OR1200_VERBOSE
247
// synopsys translate_off
248
                                $display("%t: BRANCHOP_BF: not taken", $time);
249
// synopsys translate_on
250
`endif
251
                                pc = {pcreg + 30'd1, 2'b0};
252
                                taken = 1'b0;
253
                        end
254
                {2'b00, `OR1200_BRANCHOP_BNF}:
255
                        if (flag) begin
256
                                pc = {pcreg + 30'd1, 2'b0};
257
`ifdef OR1200_VERBOSE
258
// synopsys translate_off
259
                                $display("%t: BRANCHOP_BNF: not taken", $time);
260
// synopsys translate_on
261
`endif
262
                                taken = 1'b0;
263
                        end
264
                        else begin
265
`ifdef OR1200_VERBOSE
266
// synopsys translate_off
267
                                $display("%t: BRANCHOP_BNF: pc %h = binsn_addr %h + branch_addrofs %h", $time, binsn_addr + branch_addrofs, binsn_addr, branch_addrofs);
268
// synopsys translate_on
269
`endif
270
                                pc = {binsn_addr + branch_addrofs, 2'b0};
271
                                taken = 1'b1;
272
                        end
273
                {2'b00, `OR1200_BRANCHOP_RFE}: begin
274
`ifdef OR1200_VERBOSE
275
// synopsys translate_off
276
                        $display("%t: BRANCHOP_RFE: pc <= epcr %h", $time, epcr);
277
// synopsys translate_on
278
`endif
279
                        pc = epcr;
280
                        taken = 1'b1;
281
                end
282
                {2'b01, 3'bxxx}: begin
283
`ifdef OR1200_VERBOSE
284
// synopsys translate_off
285
                        $display("Starting exception: %h.", except_type);
286
// synopsys translate_on
287
`endif
288
                        pc = {(except_prefix ? `OR1200_EXCEPT_EPH1_P : `OR1200_EXCEPT_EPH0_P), except_type, `OR1200_EXCEPT_V};
289
                        taken = 1'b1;
290
                end
291
                default: begin
292
`ifdef OR1200_VERBOSE
293
// synopsys translate_off
294
                        $display("l.mtspr writing into PC: %h.", spr_dat_i);
295
// synopsys translate_on
296
`endif
297
                        pc = spr_dat_i;
298
                        taken = 1'b0;
299
                end
300
        endcase
301
end
302
 
303
//
304
// PC register
305
//
306
always @(posedge clk or posedge rst)
307
        if (rst)
308
//              pcreg <= #1 30'd63;
309
                pcreg <= #1 ({(except_prefix ? `OR1200_EXCEPT_EPH1_P : `OR1200_EXCEPT_EPH0_P), `OR1200_EXCEPT_RESET, `OR1200_EXCEPT_V} - 1) >> 2;
310
        else if (spr_pc_we)
311
                pcreg <= #1 spr_dat_i[31:2];
312
        else if (no_more_dslot | except_start | !genpc_freeze & !icpu_rty_i & !genpc_refetch)
313
//      else if (except_start | !genpc_freeze & !icpu_rty_i & !genpc_refetch)
314
                pcreg <= #1 pc[31:2];
315
 
316
endmodule

powered by: WebSVN 2.1.0

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