1 |
350 |
julius |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// OR1200's Freeze logic ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// This file is part of the OpenRISC 1200 project ////
|
6 |
|
|
//// http://www.opencores.org/project,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 |
|
|
// $Log: or1200_freeze.v,v $
|
45 |
|
|
// Revision 2.0 2010/06/30 11:00:00 ORSoC
|
46 |
|
|
// Minor update:
|
47 |
|
|
// Bugs fixed.
|
48 |
|
|
//
|
49 |
|
|
|
50 |
|
|
// synopsys translate_off
|
51 |
|
|
`include "timescale.v"
|
52 |
|
|
// synopsys translate_on
|
53 |
|
|
`include "or1200_defines.v"
|
54 |
|
|
|
55 |
|
|
`define OR1200_NO_FREEZE 3'd0
|
56 |
|
|
`define OR1200_FREEZE_BYDC 3'd1
|
57 |
|
|
`define OR1200_FREEZE_BYMULTICYCLE 3'd2
|
58 |
|
|
`define OR1200_WAIT_LSU_TO_FINISH 3'd3
|
59 |
|
|
`define OR1200_WAIT_IC 3'd4
|
60 |
|
|
|
61 |
|
|
//
|
62 |
|
|
// Freeze logic (stalls CPU pipeline, ifetcher etc.)
|
63 |
|
|
//
|
64 |
|
|
module or1200_freeze
|
65 |
|
|
(
|
66 |
|
|
// Clock and reset
|
67 |
|
|
clk, rst,
|
68 |
|
|
|
69 |
|
|
// Internal i/f
|
70 |
|
|
multicycle, wait_on, flushpipe, extend_flush, lsu_stall, if_stall,
|
71 |
|
|
lsu_unstall, du_stall, mac_stall,
|
72 |
|
|
force_dslot_fetch, abort_ex,
|
73 |
|
|
genpc_freeze, if_freeze, id_freeze, ex_freeze, wb_freeze, saving_if_insn,
|
74 |
|
|
fpu_done, mtspr_done,
|
75 |
|
|
icpu_ack_i, icpu_err_i
|
76 |
|
|
);
|
77 |
|
|
|
78 |
|
|
//
|
79 |
|
|
// I/O
|
80 |
|
|
//
|
81 |
|
|
input clk;
|
82 |
|
|
input rst;
|
83 |
|
|
input [`OR1200_MULTICYCLE_WIDTH-1:0] multicycle;
|
84 |
|
|
input [`OR1200_WAIT_ON_WIDTH-1:0] wait_on;
|
85 |
|
|
input flushpipe;
|
86 |
|
|
input extend_flush;
|
87 |
|
|
input lsu_stall;
|
88 |
|
|
input if_stall;
|
89 |
|
|
input lsu_unstall;
|
90 |
|
|
input force_dslot_fetch;
|
91 |
|
|
input abort_ex;
|
92 |
|
|
input du_stall;
|
93 |
|
|
input mac_stall;
|
94 |
|
|
output genpc_freeze;
|
95 |
|
|
output if_freeze;
|
96 |
|
|
output id_freeze;
|
97 |
|
|
output ex_freeze;
|
98 |
|
|
output wb_freeze;
|
99 |
|
|
input saving_if_insn;
|
100 |
|
|
input fpu_done;
|
101 |
|
|
input mtspr_done;
|
102 |
|
|
input icpu_ack_i;
|
103 |
|
|
input icpu_err_i;
|
104 |
|
|
|
105 |
|
|
//
|
106 |
|
|
// Internal wires and regs
|
107 |
|
|
//
|
108 |
|
|
wire multicycle_freeze;
|
109 |
|
|
reg [`OR1200_MULTICYCLE_WIDTH-1:0] multicycle_cnt;
|
110 |
|
|
reg flushpipe_r;
|
111 |
|
|
reg [`OR1200_WAIT_ON_WIDTH-1:0] waiting_on;
|
112 |
|
|
|
113 |
|
|
//
|
114 |
|
|
// Pipeline freeze
|
115 |
|
|
//
|
116 |
|
|
// Rules how to create freeze signals:
|
117 |
|
|
// 1. Not overwriting pipeline stages:
|
118 |
|
|
// Freeze signals at the beginning of pipeline (such as if_freeze) can be
|
119 |
|
|
// asserted more often than freeze signals at the of pipeline (such as
|
120 |
|
|
// wb_freeze). In other words, wb_freeze must never be asserted when ex_freeze
|
121 |
|
|
// is not. ex_freeze must never be asserted when id_freeze is not etc.
|
122 |
|
|
//
|
123 |
|
|
// 2. Inserting NOPs in the middle of pipeline only if supported:
|
124 |
|
|
// At this time, only ex_freeze (and wb_freeze) can be deassrted when id_freeze
|
125 |
|
|
// (and if_freeze) are asserted.
|
126 |
|
|
// This way NOP is asserted from stage ID into EX stage.
|
127 |
|
|
//
|
128 |
|
|
|
129 |
|
|
assign genpc_freeze = (du_stall & !saving_if_insn) | flushpipe_r;
|
130 |
|
|
assign if_freeze = id_freeze | extend_flush;
|
131 |
|
|
|
132 |
|
|
assign id_freeze = (lsu_stall | (~lsu_unstall & if_stall) | multicycle_freeze
|
133 |
|
|
| (|waiting_on) | force_dslot_fetch) | du_stall | mac_stall;
|
134 |
|
|
assign ex_freeze = wb_freeze;
|
135 |
|
|
|
136 |
|
|
assign wb_freeze = (lsu_stall | (~lsu_unstall & if_stall) | multicycle_freeze
|
137 |
|
|
| (|waiting_on)) | du_stall | mac_stall | abort_ex;
|
138 |
|
|
|
139 |
|
|
//
|
140 |
|
|
// registered flushpipe
|
141 |
|
|
//
|
142 |
358 |
julius |
always @(posedge clk or `OR1200_RST_EVENT rst)
|
143 |
|
|
if (rst == `OR1200_RST_VALUE)
|
144 |
350 |
julius |
flushpipe_r <= 1'b0;
|
145 |
|
|
else if (icpu_ack_i | icpu_err_i)
|
146 |
|
|
// else if (!if_stall)
|
147 |
|
|
flushpipe_r <= flushpipe;
|
148 |
|
|
else if (!flushpipe)
|
149 |
|
|
flushpipe_r <= 1'b0;
|
150 |
|
|
|
151 |
|
|
//
|
152 |
|
|
// Multicycle freeze
|
153 |
|
|
//
|
154 |
|
|
assign multicycle_freeze = |multicycle_cnt;
|
155 |
|
|
|
156 |
|
|
//
|
157 |
|
|
// Multicycle counter
|
158 |
|
|
//
|
159 |
358 |
julius |
always @(posedge clk or `OR1200_RST_EVENT rst)
|
160 |
|
|
if (rst == `OR1200_RST_VALUE)
|
161 |
363 |
julius |
multicycle_cnt <= `OR1200_MULTICYCLE_WIDTH'd0;
|
162 |
350 |
julius |
else if (|multicycle_cnt)
|
163 |
363 |
julius |
multicycle_cnt <= multicycle_cnt - `OR1200_MULTICYCLE_WIDTH'd1;
|
164 |
350 |
julius |
else if (|multicycle & !ex_freeze)
|
165 |
|
|
multicycle_cnt <= multicycle;
|
166 |
|
|
|
167 |
|
|
|
168 |
|
|
//
|
169 |
|
|
// Waiting on generation
|
170 |
|
|
//
|
171 |
358 |
julius |
always @(posedge clk or `OR1200_RST_EVENT rst)
|
172 |
|
|
if (rst == `OR1200_RST_VALUE)
|
173 |
350 |
julius |
waiting_on <= 0;
|
174 |
|
|
else if ((waiting_on == `OR1200_WAIT_ON_FPU) & fpu_done)
|
175 |
|
|
waiting_on <= 0;
|
176 |
|
|
else if ((waiting_on == `OR1200_WAIT_ON_MTSPR) & mtspr_done)
|
177 |
|
|
waiting_on <= 0;
|
178 |
|
|
else if (!ex_freeze)
|
179 |
|
|
waiting_on <= wait_on;
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
endmodule
|