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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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