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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel_21/] [or1200/] [rtl/] [verilog/] [or1200_genpc.v] - Blame information for rev 1171

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

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

powered by: WebSVN 2.1.0

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