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

Subversion Repositories openrisc

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

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 186 julius
////  http://www.opencores.org/project,or1k                       ////
7 10 unneback
////                                                              ////
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 141 marcus.erl
// $Log: or1200_genpc.v,v $
45
// Revision 2.0  2010/06/30 11:00:00  ORSoC
46
// Major update: 
47
// Structure reordered and bugs fixed. 
48 10 unneback
 
49
// synopsys translate_off
50
`include "timescale.v"
51
// synopsys translate_on
52
`include "or1200_defines.v"
53
 
54
module or1200_genpc(
55
        // Clock and reset
56
        clk, rst,
57
 
58
        // External i/f to IC
59
        icpu_adr_o, icpu_cycstb_o, icpu_sel_o, icpu_tag_o,
60
        icpu_rty_i, icpu_adr_i,
61
 
62
        // Internal i/f
63 141 marcus.erl
        pre_branch_op, branch_op, except_type, except_prefix,
64
        id_branch_addrtarget, ex_branch_addrtarget, muxed_b, operand_b,
65
        flag, flagforw, ex_branch_taken, except_start,
66
        epcr, spr_dat_i, spr_pc_we, genpc_refetch,
67 859 olof
        genpc_freeze, no_more_dslot, lsu_stall, du_flush_pipe, spr_dat_npc
68 10 unneback
);
69
 
70
//
71
// I/O
72
//
73
 
74
//
75
// Clock and reset
76
//
77
input                           clk;
78
input                           rst;
79
 
80
//
81
// External i/f to IC
82
//
83
output  [31:0]                   icpu_adr_o;
84
output                          icpu_cycstb_o;
85
output  [3:0]                    icpu_sel_o;
86
output  [3:0]                    icpu_tag_o;
87
input                           icpu_rty_i;
88
input   [31:0]                   icpu_adr_i;
89
 
90
//
91
// Internal i/f
92
//
93 141 marcus.erl
input   [`OR1200_BRANCHOP_WIDTH-1:0]    pre_branch_op;
94 10 unneback
input   [`OR1200_BRANCHOP_WIDTH-1:0]     branch_op;
95
input   [`OR1200_EXCEPT_WIDTH-1:0]       except_type;
96
input                                   except_prefix;
97 141 marcus.erl
input   [31:2]                  id_branch_addrtarget;
98
input   [31:2]                  ex_branch_addrtarget;
99
input   [31:0]                   muxed_b;
100
input   [31:0]                   operand_b;
101 10 unneback
input                           flag;
102 141 marcus.erl
input                           flagforw;
103
output                          ex_branch_taken;
104 10 unneback
input                           except_start;
105
input   [31:0]                   epcr;
106
input   [31:0]                   spr_dat_i;
107
input                           spr_pc_we;
108 859 olof
input [31:0]                     spr_dat_npc;
109 10 unneback
input                           genpc_refetch;
110
input                           genpc_freeze;
111
input                           no_more_dslot;
112 847 stekern
input                           lsu_stall;
113 859 olof
input                           du_flush_pipe;
114 10 unneback
 
115 813 olof
parameter boot_adr = `OR1200_BOOT_ADR;
116 10 unneback
//
117
// Internal wires and regs
118
//
119 141 marcus.erl
reg     [31:2]                  pcreg_default;
120
reg                             pcreg_select;
121 10 unneback
reg     [31:2]                  pcreg;
122
reg     [31:0]                   pc;
123 186 julius
// Set in event of jump or taken branch   
124
reg                             ex_branch_taken;
125 10 unneback
reg                             genpc_refetch_r;
126 847 stekern
reg                             wait_lsu;
127 10 unneback
 
128 186 julius
   //
129
   // Address of insn to be fecthed
130
   //
131 859 olof
   assign icpu_adr_o = !no_more_dslot & !except_start & !spr_pc_we & !du_flush_pipe
132 186 julius
                       & (icpu_rty_i | genpc_refetch) ?
133
                       icpu_adr_i : {pc[31:2], 1'b0, ex_branch_taken|spr_pc_we};
134 10 unneback
 
135 186 julius
   //
136
   // Control access to IC subsystem
137
   //
138 847 stekern
   assign icpu_cycstb_o = ~(genpc_freeze | (|pre_branch_op && !icpu_rty_i) | wait_lsu);
139 186 julius
   assign icpu_sel_o = 4'b1111;
140
   assign icpu_tag_o = `OR1200_ITAG_NI;
141 10 unneback
 
142 186 julius
   //
143 847 stekern
   // wait_lsu
144
   //
145
   always @(posedge clk or `OR1200_RST_EVENT rst)
146
     if (rst == `OR1200_RST_VALUE)
147
       wait_lsu <=  1'b0;
148
     else if (!wait_lsu & |pre_branch_op & lsu_stall)
149
       wait_lsu <=  1'b1;
150
     else if (wait_lsu & ~|pre_branch_op)
151
       wait_lsu <=  1'b0;
152
 
153
   //
154 186 julius
   // genpc_freeze_r
155
   //
156 358 julius
   always @(posedge clk or `OR1200_RST_EVENT rst)
157
     if (rst == `OR1200_RST_VALUE)
158 258 julius
       genpc_refetch_r <=  1'b0;
159 186 julius
     else if (genpc_refetch)
160 258 julius
       genpc_refetch_r <=  1'b1;
161 186 julius
     else
162 258 julius
       genpc_refetch_r <=  1'b0;
163 10 unneback
 
164 186 julius
   //
165
   // Async calculation of new PC value. This value is used for addressing the
166
   // IC.
167
   //
168
   always @(pcreg or ex_branch_addrtarget or flag or branch_op or except_type
169
            or except_start or operand_b or epcr or spr_pc_we or spr_dat_i or
170 859 olof
            except_prefix or du_flush_pipe)
171 186 julius
     begin
172 859 olof
        casez ({du_flush_pipe, spr_pc_we, except_start, branch_op}) // synopsys parallel_case
173
          {3'b000, `OR1200_BRANCHOP_NOP}: begin
174 186 julius
             pc = {pcreg + 30'd1, 2'b0};
175
             ex_branch_taken = 1'b0;
176
          end
177 859 olof
          {3'b000, `OR1200_BRANCHOP_J}: begin
178 10 unneback
`ifdef OR1200_VERBOSE
179 186 julius
             // synopsys translate_off
180
             $display("%t: BRANCHOP_J: pc <= ex_branch_addrtarget %h"
181
                      , $time, ex_branch_addrtarget);
182
             // synopsys translate_on
183 10 unneback
`endif
184 186 julius
             pc = {ex_branch_addrtarget, 2'b00};
185
             ex_branch_taken = 1'b1;
186
          end
187 859 olof
          {3'b000, `OR1200_BRANCHOP_JR}: begin
188 10 unneback
`ifdef OR1200_VERBOSE
189 186 julius
             // synopsys translate_off
190
             $display("%t: BRANCHOP_JR: pc <= operand_b %h",
191
                      $time, operand_b);
192
             // synopsys translate_on
193 10 unneback
`endif
194 186 julius
             pc = operand_b;
195
             ex_branch_taken = 1'b1;
196
          end
197 859 olof
          {3'b000, `OR1200_BRANCHOP_BF}:
198 186 julius
            if (flag) begin
199 10 unneback
`ifdef OR1200_VERBOSE
200 186 julius
               // synopsys translate_off
201
               $display("%t: BRANCHOP_BF: pc <= ex_branch_addrtarget %h",
202
                        $time, ex_branch_addrtarget);
203
               // synopsys translate_on
204 10 unneback
`endif
205 186 julius
               pc = {ex_branch_addrtarget, 2'b00};
206
               ex_branch_taken = 1'b1;
207
            end
208
            else begin
209 10 unneback
`ifdef OR1200_VERBOSE
210 186 julius
               // synopsys translate_off
211
               $display("%t: BRANCHOP_BF: not taken", $time);
212
               // synopsys translate_on
213 10 unneback
`endif
214 186 julius
               pc = {pcreg + 30'd1, 2'b0};
215
               ex_branch_taken = 1'b0;
216
            end
217 859 olof
          {3'b000, `OR1200_BRANCHOP_BNF}:
218 186 julius
            if (flag) begin
219 10 unneback
`ifdef OR1200_VERBOSE
220 186 julius
               // synopsys translate_off
221
               $display("%t: BRANCHOP_BNF: not taken", $time);
222
               // synopsys translate_on
223 10 unneback
`endif
224 186 julius
               pc = {pcreg + 30'd1, 2'b0};
225
               ex_branch_taken = 1'b0;
226
            end
227
            else begin
228 10 unneback
`ifdef OR1200_VERBOSE
229 186 julius
               // synopsys translate_off
230
               $display("%t: BRANCHOP_BNF: pc <= ex_branch_addrtarget %h",
231
                        $time, ex_branch_addrtarget);
232
               // synopsys translate_on
233 10 unneback
`endif
234 186 julius
               pc = {ex_branch_addrtarget, 2'b00};
235
               ex_branch_taken = 1'b1;
236
            end
237 859 olof
          {3'b000, `OR1200_BRANCHOP_RFE}: begin
238 10 unneback
`ifdef OR1200_VERBOSE
239 186 julius
             // synopsys translate_off
240
             $display("%t: BRANCHOP_RFE: pc <= epcr %h",
241
                      $time, epcr);
242
             // synopsys translate_on
243 10 unneback
`endif
244 186 julius
             pc = epcr;
245
             ex_branch_taken = 1'b1;
246
          end
247 859 olof
          {3'b100, 3'b???}: begin
248 10 unneback
`ifdef OR1200_VERBOSE
249 186 julius
             // synopsys translate_off
250 859 olof
             $display("Reload breaked ins at : %h.", spr_dat_npc);
251
             // synopsys translate_on
252
`endif
253
             pc = spr_dat_npc;
254
             ex_branch_taken = 1'b1;
255
          end
256
          {3'b001, 3'b???}: begin
257
`ifdef OR1200_VERBOSE
258
             // synopsys translate_off
259 186 julius
             $display("Starting exception: %h.", except_type);
260
             // synopsys translate_on
261 10 unneback
`endif
262 186 julius
             pc = {(except_prefix ?
263
                    `OR1200_EXCEPT_EPH1_P : `OR1200_EXCEPT_EPH0_P),
264
                   except_type, `OR1200_EXCEPT_V};
265
             ex_branch_taken = 1'b1;
266
          end
267
          default: begin
268 10 unneback
`ifdef OR1200_VERBOSE
269 186 julius
             // synopsys translate_off
270
             $display("l.mtspr writing into PC: %h.", spr_dat_i);
271
             // synopsys translate_on
272 10 unneback
`endif
273 186 julius
             pc = spr_dat_i;
274
             ex_branch_taken = 1'b0;
275
          end
276 10 unneback
        endcase
277 186 julius
     end
278 10 unneback
 
279 852 olof
   // select async. value for pcreg after reset - PC jumps to the address selected
280
   // after boot.
281
   wire [31:0] pcreg_boot = boot_adr;
282
 
283 186 julius
   //
284
   // PC register
285
   //
286 358 julius
   always @(posedge clk or `OR1200_RST_EVENT rst)
287 186 julius
     // default value 
288 358 julius
     if (rst == `OR1200_RST_VALUE) begin
289 813 olof
        pcreg_default <=  (boot_adr >>2) - 4;
290 258 julius
        pcreg_select <=  1'b1;// select async. value due to reset state
291 186 julius
     end
292
   // selected value (different from default) is written into FF after
293
   // reset state
294
     else if (pcreg_select) begin
295
        // dynamic value can only be assigned to FF out of reset! 
296 258 julius
        pcreg_default <=  pcreg_boot[31:2];
297
        pcreg_select <=  1'b0;          // select FF value 
298 186 julius
     end
299
     else if (spr_pc_we) begin
300 258 julius
        pcreg_default <=  spr_dat_i[31:2];
301 186 julius
     end
302 859 olof
     else if (du_flush_pipe | no_more_dslot | except_start | !genpc_freeze & !icpu_rty_i
303 186 julius
              & !genpc_refetch) begin
304 258 julius
        pcreg_default <=  pc[31:2];
305 186 julius
     end
306 10 unneback
 
307 186 julius
   always @(pcreg_boot or pcreg_default or pcreg_select)
308
     if (pcreg_select)
309
       // async. value is selected due to reset state 
310
       pcreg = pcreg_boot[31:2];
311
     else
312
       // FF value is selected 2nd clock after reset state 
313
       pcreg = pcreg_default ;
314 141 marcus.erl
 
315 10 unneback
endmodule

powered by: WebSVN 2.1.0

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