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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 350 julius
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's generate PC                                        ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6
////  http://www.opencores.org/project,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
// $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
 
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
        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 850 stekern
        genpc_freeze, no_more_dslot, lsu_stall
68 350 julius
);
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
input   [`OR1200_BRANCHOP_WIDTH-1:0]    pre_branch_op;
94
input   [`OR1200_BRANCHOP_WIDTH-1:0]     branch_op;
95
input   [`OR1200_EXCEPT_WIDTH-1:0]       except_type;
96
input                                   except_prefix;
97
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
input                           flag;
102
input                           flagforw;
103
output                          ex_branch_taken;
104
input                           except_start;
105
input   [31:0]                   epcr;
106
input   [31:0]                   spr_dat_i;
107
input                           spr_pc_we;
108
input                           genpc_refetch;
109
input                           genpc_freeze;
110
input                           no_more_dslot;
111 850 stekern
input                           lsu_stall;
112 350 julius
 
113 814 olof
parameter boot_adr = `OR1200_BOOT_ADR;
114 350 julius
//
115
// Internal wires and regs
116
//
117
reg     [31:2]                  pcreg_default;
118
reg                             pcreg_select;
119
reg     [31:2]                  pcreg;
120
reg     [31:0]                   pc;
121
// Set in event of jump or taken branch   
122
reg                             ex_branch_taken;
123
reg                             genpc_refetch_r;
124 850 stekern
reg                             wait_lsu;
125 350 julius
 
126
   //
127
   // Address of insn to be fecthed
128
   //
129
   assign icpu_adr_o = !no_more_dslot & !except_start & !spr_pc_we
130
                       & (icpu_rty_i | genpc_refetch) ?
131
                       icpu_adr_i : {pc[31:2], 1'b0, ex_branch_taken|spr_pc_we};
132
 
133
   //
134
   // Control access to IC subsystem
135
   //
136 850 stekern
   assign icpu_cycstb_o = ~(genpc_freeze | (|pre_branch_op && !icpu_rty_i) | wait_lsu);
137 350 julius
   assign icpu_sel_o = 4'b1111;
138
   assign icpu_tag_o = `OR1200_ITAG_NI;
139
 
140
   //
141 850 stekern
   // wait_lsu
142
   //
143
   always @(posedge clk or `OR1200_RST_EVENT rst)
144
     if (rst == `OR1200_RST_VALUE)
145
       wait_lsu <=  1'b0;
146
     else if (!wait_lsu & |pre_branch_op & lsu_stall)
147
       wait_lsu <=  1'b1;
148
     else if (wait_lsu & ~|pre_branch_op)
149
       wait_lsu <=  1'b0;
150
 
151
   //
152 350 julius
   // genpc_freeze_r
153
   //
154 358 julius
   always @(posedge clk or `OR1200_RST_EVENT rst)
155
     if (rst == `OR1200_RST_VALUE)
156 350 julius
       genpc_refetch_r <=  1'b0;
157
     else if (genpc_refetch)
158
       genpc_refetch_r <=  1'b1;
159
     else
160
       genpc_refetch_r <=  1'b0;
161
 
162
   //
163
   // Async calculation of new PC value. This value is used for addressing the
164
   // IC.
165
   //
166
   always @(pcreg or ex_branch_addrtarget or flag or branch_op or except_type
167
            or except_start or operand_b or epcr or spr_pc_we or spr_dat_i or
168
            except_prefix)
169
     begin
170 363 julius
        casez ({spr_pc_we, except_start, branch_op}) // synopsys parallel_case
171 350 julius
          {2'b00, `OR1200_BRANCHOP_NOP}: begin
172
             pc = {pcreg + 30'd1, 2'b0};
173
             ex_branch_taken = 1'b0;
174
          end
175
          {2'b00, `OR1200_BRANCHOP_J}: begin
176
`ifdef OR1200_VERBOSE
177
             // synopsys translate_off
178
             $display("%t: BRANCHOP_J: pc <= ex_branch_addrtarget %h"
179
                      , $time, ex_branch_addrtarget);
180
             // synopsys translate_on
181
`endif
182
             pc = {ex_branch_addrtarget, 2'b00};
183
             ex_branch_taken = 1'b1;
184
          end
185
          {2'b00, `OR1200_BRANCHOP_JR}: begin
186
`ifdef OR1200_VERBOSE
187
             // synopsys translate_off
188
             $display("%t: BRANCHOP_JR: pc <= operand_b %h",
189
                      $time, operand_b);
190
             // synopsys translate_on
191
`endif
192
             pc = operand_b;
193
             ex_branch_taken = 1'b1;
194
          end
195
          {2'b00, `OR1200_BRANCHOP_BF}:
196
            if (flag) begin
197
`ifdef OR1200_VERBOSE
198
               // synopsys translate_off
199
               $display("%t: BRANCHOP_BF: pc <= ex_branch_addrtarget %h",
200
                        $time, ex_branch_addrtarget);
201
               // synopsys translate_on
202
`endif
203
               pc = {ex_branch_addrtarget, 2'b00};
204
               ex_branch_taken = 1'b1;
205
            end
206
            else begin
207
`ifdef OR1200_VERBOSE
208
               // synopsys translate_off
209
               $display("%t: BRANCHOP_BF: not taken", $time);
210
               // synopsys translate_on
211
`endif
212
               pc = {pcreg + 30'd1, 2'b0};
213
               ex_branch_taken = 1'b0;
214
            end
215
          {2'b00, `OR1200_BRANCHOP_BNF}:
216
            if (flag) begin
217
`ifdef OR1200_VERBOSE
218
               // synopsys translate_off
219
               $display("%t: BRANCHOP_BNF: not taken", $time);
220
               // synopsys translate_on
221
`endif
222
               pc = {pcreg + 30'd1, 2'b0};
223
               ex_branch_taken = 1'b0;
224
            end
225
            else begin
226
`ifdef OR1200_VERBOSE
227
               // synopsys translate_off
228
               $display("%t: BRANCHOP_BNF: pc <= ex_branch_addrtarget %h",
229
                        $time, ex_branch_addrtarget);
230
               // synopsys translate_on
231
`endif
232
               pc = {ex_branch_addrtarget, 2'b00};
233
               ex_branch_taken = 1'b1;
234
            end
235
          {2'b00, `OR1200_BRANCHOP_RFE}: begin
236
`ifdef OR1200_VERBOSE
237
             // synopsys translate_off
238
             $display("%t: BRANCHOP_RFE: pc <= epcr %h",
239
                      $time, epcr);
240
             // synopsys translate_on
241
`endif
242
             pc = epcr;
243
             ex_branch_taken = 1'b1;
244
          end
245 363 julius
          {2'b01, 3'b???}: begin
246 350 julius
`ifdef OR1200_VERBOSE
247
             // synopsys translate_off
248
             $display("Starting exception: %h.", except_type);
249
             // synopsys translate_on
250
`endif
251
             pc = {(except_prefix ?
252
                    `OR1200_EXCEPT_EPH1_P : `OR1200_EXCEPT_EPH0_P),
253
                   except_type, `OR1200_EXCEPT_V};
254
             ex_branch_taken = 1'b1;
255
          end
256
          default: begin
257
`ifdef OR1200_VERBOSE
258
             // synopsys translate_off
259
             $display("l.mtspr writing into PC: %h.", spr_dat_i);
260
             // synopsys translate_on
261
`endif
262
             pc = spr_dat_i;
263
             ex_branch_taken = 1'b0;
264
          end
265
        endcase
266
     end
267
 
268
   //
269
   // PC register
270
   //
271 358 julius
   always @(posedge clk or `OR1200_RST_EVENT rst)
272 350 julius
     // default value 
273 358 julius
     if (rst == `OR1200_RST_VALUE) begin
274 814 olof
        pcreg_default <=  (boot_adr >>2) - 4;
275 350 julius
        pcreg_select <=  1'b1;// select async. value due to reset state
276
     end
277
   // selected value (different from default) is written into FF after
278
   // reset state
279
     else if (pcreg_select) begin
280
        // dynamic value can only be assigned to FF out of reset! 
281
        pcreg_default <=  pcreg_boot[31:2];
282
        pcreg_select <=  1'b0;          // select FF value 
283
     end
284
     else if (spr_pc_we) begin
285
        pcreg_default <=  spr_dat_i[31:2];
286
     end
287
     else if (no_more_dslot | except_start | !genpc_freeze & !icpu_rty_i
288
              & !genpc_refetch) begin
289
        pcreg_default <=  pc[31:2];
290
     end
291
 
292
   // select async. value for pcreg after reset - PC jumps to the address selected
293
   // after boot.
294 814 olof
   wire [31:0] pcreg_boot = boot_adr;
295 350 julius
 
296
   always @(pcreg_boot or pcreg_default or pcreg_select)
297
     if (pcreg_select)
298
       // async. value is selected due to reset state 
299
       pcreg = pcreg_boot[31:2];
300
     else
301
       // FF value is selected 2nd clock after reset state 
302
       pcreg = pcreg_default ;
303
 
304
endmodule

powered by: WebSVN 2.1.0

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