1 |
504 |
lampret |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// OR1200's Freeze logic ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// This file is part of the OpenRISC 1200 project ////
|
6 |
|
|
//// http://www.opencores.org/cores/or1k/ ////
|
7 |
|
|
//// ////
|
8 |
|
|
//// Description ////
|
9 |
|
|
//// Generates all freezes and stalls inside RISC ////
|
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 |
1267 |
lampret |
// Revision 1.6.4.2 2003/12/05 00:09:49 lampret
|
48 |
|
|
// No functional change.
|
49 |
|
|
//
|
50 |
|
|
// Revision 1.6.4.1 2003/07/08 15:36:37 lampret
|
51 |
|
|
// Added embedded memory QMEM.
|
52 |
|
|
//
|
53 |
|
|
// Revision 1.6 2002/07/31 02:04:35 lampret
|
54 |
|
|
// MAC now follows software convention (signed multiply instead of unsigned).
|
55 |
|
|
//
|
56 |
916 |
lampret |
// Revision 1.5 2002/07/14 22:17:17 lampret
|
57 |
|
|
// Added simple trace buffer [only for Xilinx Virtex target]. Fixed instruction fetch abort when new exception is recognized.
|
58 |
|
|
//
|
59 |
895 |
lampret |
// Revision 1.4 2002/03/29 15:16:55 lampret
|
60 |
|
|
// Some of the warnings fixed.
|
61 |
|
|
//
|
62 |
788 |
lampret |
// Revision 1.3 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.2 2002/01/14 06:18:22 lampret
|
66 |
|
|
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
|
67 |
|
|
//
|
68 |
562 |
lampret |
// Revision 1.1 2002/01/03 08:16:15 lampret
|
69 |
|
|
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
|
70 |
|
|
//
|
71 |
504 |
lampret |
// Revision 1.10 2001/11/13 10:02:21 lampret
|
72 |
|
|
// Added 'setpc'. Renamed some signals (except_flushpipe into flushpipe etc)
|
73 |
|
|
//
|
74 |
|
|
// Revision 1.9 2001/10/21 17:57:16 lampret
|
75 |
|
|
// 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.
|
76 |
|
|
//
|
77 |
|
|
// Revision 1.8 2001/10/19 23:28:46 lampret
|
78 |
|
|
// Fixed some synthesis warnings. Configured with caches and MMUs.
|
79 |
|
|
//
|
80 |
|
|
// Revision 1.7 2001/10/14 13:12:09 lampret
|
81 |
|
|
// MP3 version.
|
82 |
|
|
//
|
83 |
|
|
// Revision 1.1.1.1 2001/10/06 10:18:36 igorm
|
84 |
|
|
// no message
|
85 |
|
|
//
|
86 |
|
|
// Revision 1.2 2001/08/09 13:39:33 lampret
|
87 |
|
|
// Major clean-up.
|
88 |
|
|
//
|
89 |
|
|
// Revision 1.1 2001/07/20 00:46:03 lampret
|
90 |
|
|
// Development version of RTL. Libraries are missing.
|
91 |
|
|
//
|
92 |
|
|
//
|
93 |
|
|
|
94 |
|
|
// synopsys translate_off
|
95 |
|
|
`include "timescale.v"
|
96 |
|
|
// synopsys translate_on
|
97 |
|
|
`include "or1200_defines.v"
|
98 |
|
|
|
99 |
|
|
`define OR1200_NO_FREEZE 3'd0
|
100 |
|
|
`define OR1200_FREEZE_BYDC 3'd1
|
101 |
|
|
`define OR1200_FREEZE_BYMULTICYCLE 3'd2
|
102 |
|
|
`define OR1200_WAIT_LSU_TO_FINISH 3'd3
|
103 |
|
|
`define OR1200_WAIT_IC 3'd4
|
104 |
|
|
|
105 |
|
|
//
|
106 |
|
|
// Freeze logic (stalls CPU pipeline, ifetcher etc.)
|
107 |
|
|
//
|
108 |
|
|
module or1200_freeze(
|
109 |
|
|
// Clock and reset
|
110 |
|
|
clk, rst,
|
111 |
|
|
|
112 |
|
|
// Internal i/f
|
113 |
|
|
multicycle, flushpipe, extend_flush, lsu_stall, if_stall,
|
114 |
|
|
lsu_unstall, du_stall, mac_stall,
|
115 |
617 |
lampret |
force_dslot_fetch, abort_ex,
|
116 |
895 |
lampret |
genpc_freeze, if_freeze, id_freeze, ex_freeze, wb_freeze,
|
117 |
|
|
icpu_ack_i, icpu_err_i
|
118 |
504 |
lampret |
);
|
119 |
|
|
|
120 |
|
|
//
|
121 |
|
|
// I/O
|
122 |
|
|
//
|
123 |
|
|
input clk;
|
124 |
|
|
input rst;
|
125 |
|
|
input [`OR1200_MULTICYCLE_WIDTH-1:0] multicycle;
|
126 |
|
|
input flushpipe;
|
127 |
|
|
input extend_flush;
|
128 |
|
|
input lsu_stall;
|
129 |
|
|
input if_stall;
|
130 |
|
|
input lsu_unstall;
|
131 |
|
|
input force_dslot_fetch;
|
132 |
617 |
lampret |
input abort_ex;
|
133 |
504 |
lampret |
input du_stall;
|
134 |
|
|
input mac_stall;
|
135 |
562 |
lampret |
output genpc_freeze;
|
136 |
504 |
lampret |
output if_freeze;
|
137 |
|
|
output id_freeze;
|
138 |
|
|
output ex_freeze;
|
139 |
|
|
output wb_freeze;
|
140 |
895 |
lampret |
input icpu_ack_i;
|
141 |
|
|
input icpu_err_i;
|
142 |
504 |
lampret |
|
143 |
|
|
//
|
144 |
|
|
// Internal wires and regs
|
145 |
|
|
//
|
146 |
|
|
wire multicycle_freeze;
|
147 |
788 |
lampret |
reg [`OR1200_MULTICYCLE_WIDTH-1:0] multicycle_cnt;
|
148 |
895 |
lampret |
reg flushpipe_r;
|
149 |
504 |
lampret |
|
150 |
|
|
//
|
151 |
|
|
// Pipeline freeze
|
152 |
|
|
//
|
153 |
|
|
// Rules how to create freeze signals:
|
154 |
|
|
// 1. Not overwriting pipeline stages:
|
155 |
|
|
// Freze signals at the beginning of pipeline (such as if_freeze) can be asserted more
|
156 |
|
|
// often than freeze signals at the of pipeline (such as wb_freeze). In other words, wb_freeze must never
|
157 |
|
|
// be asserted when ex_freeze is not. ex_freeze must never be asserted when id_freeze is not etc.
|
158 |
|
|
//
|
159 |
|
|
// 2. Inserting NOPs in the middle of pipeline only if supported:
|
160 |
|
|
// At this time, only ex_freeze (and wb_freeze) can be deassrted when id_freeze (and if_freeze) are asserted.
|
161 |
|
|
// This way NOP is asserted from stage ID into EX stage.
|
162 |
|
|
//
|
163 |
1267 |
lampret |
//assign genpc_freeze = du_stall | flushpipe_r | lsu_stall;
|
164 |
895 |
lampret |
assign genpc_freeze = du_stall | flushpipe_r;
|
165 |
504 |
lampret |
assign if_freeze = id_freeze | extend_flush;
|
166 |
|
|
//assign id_freeze = (lsu_stall | (~lsu_unstall & if_stall) | multicycle_freeze | force_dslot_fetch) & ~flushpipe | du_stall;
|
167 |
916 |
lampret |
assign id_freeze = (lsu_stall | (~lsu_unstall & if_stall) | multicycle_freeze | force_dslot_fetch) | du_stall | mac_stall;
|
168 |
504 |
lampret |
assign ex_freeze = wb_freeze;
|
169 |
|
|
//assign wb_freeze = (lsu_stall | (~lsu_unstall & if_stall) | multicycle_freeze) & ~flushpipe | du_stall | mac_stall;
|
170 |
617 |
lampret |
assign wb_freeze = (lsu_stall | (~lsu_unstall & if_stall) | multicycle_freeze) | du_stall | mac_stall | abort_ex;
|
171 |
504 |
lampret |
|
172 |
|
|
//
|
173 |
895 |
lampret |
// registered flushpipe
|
174 |
|
|
//
|
175 |
|
|
always @(posedge clk or posedge rst)
|
176 |
|
|
if (rst)
|
177 |
|
|
flushpipe_r <= #1 1'b0;
|
178 |
|
|
else if (icpu_ack_i | icpu_err_i)
|
179 |
|
|
// else if (!if_stall)
|
180 |
|
|
flushpipe_r <= #1 flushpipe;
|
181 |
|
|
else if (!flushpipe)
|
182 |
|
|
flushpipe_r <= #1 1'b0;
|
183 |
|
|
|
184 |
|
|
//
|
185 |
504 |
lampret |
// Multicycle freeze
|
186 |
|
|
//
|
187 |
|
|
assign multicycle_freeze = |multicycle_cnt;
|
188 |
|
|
|
189 |
|
|
//
|
190 |
|
|
// Multicycle counter
|
191 |
|
|
//
|
192 |
|
|
always @(posedge clk or posedge rst)
|
193 |
|
|
if (rst)
|
194 |
|
|
multicycle_cnt <= #1 3'b0;
|
195 |
|
|
else if (multicycle_cnt)
|
196 |
1267 |
lampret |
multicycle_cnt <= #1 multicycle_cnt - 1'd1;
|
197 |
504 |
lampret |
else if (multicycle & !ex_freeze)
|
198 |
|
|
multicycle_cnt <= #1 multicycle;
|
199 |
|
|
|
200 |
|
|
endmodule
|