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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1200/] [rtl/] [verilog/] [or1200_if.v] - Blame information for rev 797

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

Line No. Rev Author Line
1 10 unneback
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's instruction fetch                                  ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6 258 julius
////  http://www.opencores.org/project,or1k                       ////
7 10 unneback
////                                                              ////
8
////  Description                                                 ////
9
////  PC, instruction fetch, 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_if.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_if(
55
        // Clock and reset
56
        clk, rst,
57
 
58
        // External i/f to IC
59
        icpu_dat_i, icpu_ack_i, icpu_err_i, icpu_adr_i, icpu_tag_i,
60
 
61
        // Internal i/f
62 141 marcus.erl
        if_freeze, if_insn, if_pc, if_flushpipe, saving_if_insn,
63 10 unneback
        if_stall, no_more_dslot, genpc_refetch, rfe,
64
        except_itlbmiss, except_immufault, except_ibuserr
65
);
66
 
67
//
68
// I/O
69
//
70
 
71
//
72
// Clock and reset
73
//
74
input                           clk;
75
input                           rst;
76
 
77
//
78
// External i/f to IC
79
//
80
input   [31:0]                   icpu_dat_i;
81
input                           icpu_ack_i;
82
input                           icpu_err_i;
83
input   [31:0]                   icpu_adr_i;
84
input   [3:0]                    icpu_tag_i;
85
 
86
//
87
// Internal i/f
88
//
89
input                           if_freeze;
90
output  [31:0]                   if_insn;
91
output  [31:0]                   if_pc;
92 141 marcus.erl
input                           if_flushpipe;
93
output                          saving_if_insn;
94 10 unneback
output                          if_stall;
95
input                           no_more_dslot;
96
output                          genpc_refetch;
97
input                           rfe;
98
output                          except_itlbmiss;
99
output                          except_immufault;
100
output                          except_ibuserr;
101
 
102
//
103
// Internal wires and regs
104
//
105 141 marcus.erl
wire                    save_insn;
106
wire                    if_bypass;
107
reg                     if_bypass_reg;
108
reg     [31:0]           insn_saved;
109
reg     [31:0]           addr_saved;
110
reg     [2:0]            err_saved;
111
reg                     saved;
112 10 unneback
 
113 141 marcus.erl
assign save_insn = (icpu_ack_i | icpu_err_i) & if_freeze & !saved;
114
assign saving_if_insn = !if_flushpipe & save_insn;
115
 
116 10 unneback
//
117 141 marcus.erl
// IF bypass 
118
//
119
assign if_bypass = icpu_adr_i[0] ? 1'b0 : if_bypass_reg | if_flushpipe;
120
 
121 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst)
122
        if (rst == `OR1200_RST_VALUE)
123 258 julius
                if_bypass_reg <=  1'b0;
124 141 marcus.erl
        else
125 258 julius
                if_bypass_reg <=  if_bypass;
126 141 marcus.erl
 
127
//
128 10 unneback
// IF stage insn
129
//
130 141 marcus.erl
assign if_insn = no_more_dslot | rfe | if_bypass ? {`OR1200_OR32_NOP, 26'h041_0000} : saved ? insn_saved : icpu_ack_i ? icpu_dat_i : {`OR1200_OR32_NOP, 26'h061_0000};
131
assign if_pc = saved ? addr_saved : {icpu_adr_i[31:2], 2'h0};
132 10 unneback
assign if_stall = !icpu_err_i & !icpu_ack_i & !saved;
133
assign genpc_refetch = saved & icpu_ack_i;
134 141 marcus.erl
assign except_itlbmiss = no_more_dslot ? 1'b0 : saved ? err_saved[0] : icpu_err_i & (icpu_tag_i == `OR1200_ITAG_TE);
135
assign except_immufault = no_more_dslot ? 1'b0 : saved ? err_saved[1] : icpu_err_i & (icpu_tag_i == `OR1200_ITAG_PE);
136
assign except_ibuserr = no_more_dslot ? 1'b0 : saved ? err_saved[2] : icpu_err_i & (icpu_tag_i == `OR1200_ITAG_BE);
137 10 unneback
 
138
//
139
// Flag for saved insn/address
140
//
141 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst)
142
        if (rst == `OR1200_RST_VALUE)
143 258 julius
                saved <=  1'b0;
144 141 marcus.erl
        else if (if_flushpipe)
145 258 julius
                saved <=  1'b0;
146 141 marcus.erl
        else if (save_insn)
147 258 julius
                saved <=  1'b1;
148 10 unneback
        else if (!if_freeze)
149 258 julius
                saved <=  1'b0;
150 10 unneback
 
151
//
152
// Store fetched instruction
153
//
154 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst)
155
        if (rst == `OR1200_RST_VALUE)
156 258 julius
                insn_saved <=  {`OR1200_OR32_NOP, 26'h041_0000};
157 141 marcus.erl
        else if (if_flushpipe)
158 258 julius
                insn_saved <=  {`OR1200_OR32_NOP, 26'h041_0000};
159 141 marcus.erl
        else if (save_insn)
160 258 julius
                insn_saved <=  icpu_err_i ? {`OR1200_OR32_NOP, 26'h041_0000} : icpu_dat_i;
161 10 unneback
        else if (!if_freeze)
162 258 julius
                insn_saved <=  {`OR1200_OR32_NOP, 26'h041_0000};
163 10 unneback
 
164
//
165
// Store fetched instruction's address
166
//
167 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst)
168
        if (rst == `OR1200_RST_VALUE)
169 258 julius
                addr_saved <=  32'h00000000;
170 141 marcus.erl
        else if (if_flushpipe)
171 258 julius
                addr_saved <=  32'h00000000;
172 141 marcus.erl
        else if (save_insn)
173 258 julius
                addr_saved <=  {icpu_adr_i[31:2], 2'b00};
174 10 unneback
        else if (!if_freeze)
175 258 julius
                addr_saved <=  {icpu_adr_i[31:2], 2'b00};
176 10 unneback
 
177 141 marcus.erl
//
178
// Store fetched instruction's error tags 
179
//
180 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst)
181
        if (rst == `OR1200_RST_VALUE)
182 258 julius
                err_saved <=  3'b000;
183 141 marcus.erl
        else if (if_flushpipe)
184 258 julius
                err_saved <=  3'b000;
185 141 marcus.erl
        else if (save_insn) begin
186 258 julius
                err_saved[0] <=  icpu_err_i & (icpu_tag_i == `OR1200_ITAG_TE);
187
                err_saved[1] <=  icpu_err_i & (icpu_tag_i == `OR1200_ITAG_PE);
188
                err_saved[2] <=  icpu_err_i & (icpu_tag_i == `OR1200_ITAG_BE);
189 141 marcus.erl
        end
190
        else if (!if_freeze)
191 258 julius
                err_saved <=  3'b000;
192 141 marcus.erl
 
193
 
194 10 unneback
endmodule

powered by: WebSVN 2.1.0

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