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