1 |
2 |
robfinch |
`timescale 1ns / 1ps
|
2 |
|
|
// ============================================================================
|
3 |
|
|
// __
|
4 |
|
|
// \\__/ o\ (C) 2016-2022 Robert Finch, Waterloo
|
5 |
|
|
// \ __ / All rights reserved.
|
6 |
|
|
// \/_// robfinch@finitron.ca
|
7 |
|
|
// ||
|
8 |
|
|
//
|
9 |
|
|
// rf68000_mmu.sv
|
10 |
|
|
//
|
11 |
|
|
//
|
12 |
|
|
// BSD 3-Clause License
|
13 |
|
|
// Redistribution and use in source and binary forms, with or without
|
14 |
|
|
// modification, are permitted provided that the following conditions are met:
|
15 |
|
|
//
|
16 |
|
|
// 1. Redistributions of source code must retain the above copyright notice, this
|
17 |
|
|
// list of conditions and the following disclaimer.
|
18 |
|
|
//
|
19 |
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
20 |
|
|
// this list of conditions and the following disclaimer in the documentation
|
21 |
|
|
// and/or other materials provided with the distribution.
|
22 |
|
|
//
|
23 |
|
|
// 3. Neither the name of the copyright holder nor the names of its
|
24 |
|
|
// contributors may be used to endorse or promote products derived from
|
25 |
|
|
// this software without specific prior written permission.
|
26 |
|
|
//
|
27 |
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
28 |
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
29 |
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
30 |
|
|
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
31 |
|
|
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
32 |
|
|
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
33 |
|
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
34 |
|
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
35 |
|
|
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
36 |
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
37 |
|
|
//
|
38 |
|
|
//
|
39 |
|
|
// ============================================================================
|
40 |
|
|
//
|
41 |
|
|
`define LOW 1'b0
|
42 |
|
|
`define HIGH 1'b1
|
43 |
|
|
|
44 |
|
|
module rf68000_mmu(rst_i, clk_i, s_ex_i, s_cs_i, s_cyc_i, s_stb_i, s_ack_o, s_we_i,
|
45 |
|
|
s_asid_i, s_adr_i, s_dat_i, s_dat_o,
|
46 |
|
|
pea_o, cyc_o, stb_o, we_o, pdat_o,
|
47 |
|
|
exv_o, rdv_o, wrv_o);
|
48 |
|
|
input rst_i;
|
49 |
|
|
input clk_i;
|
50 |
|
|
input s_ex_i; // executable address
|
51 |
|
|
input s_cs_i;
|
52 |
|
|
input s_cyc_i;
|
53 |
|
|
input s_stb_i;
|
54 |
|
|
input s_we_i; // write strobe
|
55 |
|
|
output s_ack_o;
|
56 |
|
|
input [7:0] s_asid_i;
|
57 |
|
|
input [31:0] s_adr_i; // virtual address
|
58 |
|
|
input [31:0] s_dat_i;
|
59 |
|
|
output reg [31:0] s_dat_o;
|
60 |
|
|
output reg [31:0] pea_o;
|
61 |
|
|
output reg cyc_o;
|
62 |
|
|
output reg stb_o;
|
63 |
|
|
output reg we_o;
|
64 |
|
|
output reg [31:0] pdat_o;
|
65 |
|
|
output reg exv_o; // execute violation
|
66 |
|
|
output reg rdv_o; // read violation
|
67 |
|
|
output reg wrv_o; // write violation
|
68 |
|
|
|
69 |
|
|
wire cs = s_cyc_i && s_stb_i && s_cs_i;
|
70 |
|
|
wire [5:0] okey = s_asid_i[5:0];
|
71 |
|
|
wire [5:0] akey = s_asid_i[5:0];
|
72 |
|
|
|
73 |
|
|
ack_gen #(
|
74 |
|
|
.READ_STAGES(3),
|
75 |
|
|
.WRITE_STAGES(0),
|
76 |
|
|
.REGISTER_OUTPUT(1)
|
77 |
|
|
) uag1
|
78 |
|
|
(
|
79 |
|
|
.rst_i(rst_i),
|
80 |
|
|
.clk_i(clk_i),
|
81 |
|
|
.ce_i(1'b1),
|
82 |
|
|
.i(cs & ~s_we_i),
|
83 |
|
|
.we_i(cs & s_we_i),
|
84 |
|
|
.o(s_ack_o),
|
85 |
|
|
.rid_i(0),
|
86 |
|
|
.wid_i(0),
|
87 |
|
|
.rid_o(),
|
88 |
|
|
.wid_o()
|
89 |
|
|
);
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
reg cyc1,cyc2,stb1,stb2;
|
93 |
|
|
wire [17:0] douta;
|
94 |
|
|
wire [17:0] doutb;
|
95 |
|
|
wire [1:0] wx = doutb[17:16];
|
96 |
|
|
|
97 |
|
|
always @(posedge clk_i)
|
98 |
|
|
exv_o <= s_ex_i & ~wx[0] & cyc2 & stb2;
|
99 |
|
|
always @(posedge clk_i)
|
100 |
|
|
rdv_o <= 1'b0;
|
101 |
|
|
always @(posedge clk_i)
|
102 |
|
|
wrv_o <= s_we_i & ~wx[1] & cyc2 & stb2;
|
103 |
|
|
|
104 |
|
|
wire [14:0] addra = {akey[5:0],s_adr_i[10: 2]};
|
105 |
|
|
wire [14:0] addrb = {okey[5:0],s_adr_i[24:16]};
|
106 |
|
|
wire clka = clk_i;
|
107 |
|
|
wire clkb = clk_i;
|
108 |
|
|
wire [17:0] dina = s_dat_i[17:0];
|
109 |
|
|
wire [17:0] dinb = 18'h0;
|
110 |
|
|
wire ena = cs;
|
111 |
|
|
wire enb = 1'b1;
|
112 |
|
|
wire wea = s_we_i;
|
113 |
|
|
wire web = 1'b0;
|
114 |
|
|
|
115 |
|
|
// xpm_memory_tdpram: True Dual Port RAM
|
116 |
|
|
// Xilinx Parameterized Macro, version 2022.2
|
117 |
|
|
|
118 |
|
|
xpm_memory_tdpram #(
|
119 |
|
|
.ADDR_WIDTH_A(15), // DECIMAL
|
120 |
|
|
.ADDR_WIDTH_B(15), // DECIMAL
|
121 |
|
|
.AUTO_SLEEP_TIME(0), // DECIMAL
|
122 |
|
|
.BYTE_WRITE_WIDTH_A(18), // DECIMAL
|
123 |
|
|
.BYTE_WRITE_WIDTH_B(18), // DECIMAL
|
124 |
|
|
.CASCADE_HEIGHT(0), // DECIMAL
|
125 |
|
|
.CLOCKING_MODE("common_clock"), // String
|
126 |
|
|
.ECC_MODE("no_ecc"), // String
|
127 |
|
|
.MEMORY_INIT_FILE("none"), // String
|
128 |
|
|
.MEMORY_INIT_PARAM("0"), // String
|
129 |
|
|
.MEMORY_OPTIMIZATION("true"), // String
|
130 |
|
|
.MEMORY_PRIMITIVE("auto"), // String
|
131 |
|
|
.MEMORY_SIZE(589824), // DECIMAL
|
132 |
|
|
.MESSAGE_CONTROL(0), // DECIMAL
|
133 |
|
|
.READ_DATA_WIDTH_A(18), // DECIMAL
|
134 |
|
|
.READ_DATA_WIDTH_B(18), // DECIMAL
|
135 |
|
|
.READ_LATENCY_A(2), // DECIMAL
|
136 |
|
|
.READ_LATENCY_B(1), // DECIMAL
|
137 |
|
|
.READ_RESET_VALUE_A("0"), // String
|
138 |
|
|
.READ_RESET_VALUE_B("0"), // String
|
139 |
|
|
.RST_MODE_A("SYNC"), // String
|
140 |
|
|
.RST_MODE_B("SYNC"), // String
|
141 |
|
|
.SIM_ASSERT_CHK(0), // DECIMAL; 0=disable simulation messages, 1=enable simulation messages
|
142 |
|
|
.USE_EMBEDDED_CONSTRAINT(0), // DECIMAL
|
143 |
|
|
.USE_MEM_INIT(1), // DECIMAL
|
144 |
|
|
.USE_MEM_INIT_MMI(0), // DECIMAL
|
145 |
|
|
.WAKEUP_TIME("disable_sleep"), // String
|
146 |
|
|
.WRITE_DATA_WIDTH_A(18), // DECIMAL
|
147 |
|
|
.WRITE_DATA_WIDTH_B(18), // DECIMAL
|
148 |
|
|
.WRITE_MODE_A("no_change"), // String
|
149 |
|
|
.WRITE_MODE_B("no_change"), // String
|
150 |
|
|
.WRITE_PROTECT(1) // DECIMAL
|
151 |
|
|
)
|
152 |
|
|
xpm_memory_tdpram_inst (
|
153 |
|
|
.dbiterra(), // 1-bit output: Status signal to indicate double bit error occurrence
|
154 |
|
|
// on the data output of port A.
|
155 |
|
|
|
156 |
|
|
.dbiterrb(), // 1-bit output: Status signal to indicate double bit error occurrence
|
157 |
|
|
// on the data output of port A.
|
158 |
|
|
|
159 |
|
|
.douta(douta), // READ_DATA_WIDTH_A-bit output: Data output for port A read operations.
|
160 |
|
|
.doutb(doutb), // READ_DATA_WIDTH_B-bit output: Data output for port B read operations.
|
161 |
|
|
.sbiterra(), // 1-bit output: Status signal to indicate single bit error occurrence
|
162 |
|
|
// on the data output of port A.
|
163 |
|
|
|
164 |
|
|
.sbiterrb(), // 1-bit output: Status signal to indicate single bit error occurrence
|
165 |
|
|
// on the data output of port B.
|
166 |
|
|
|
167 |
|
|
.addra(addra), // ADDR_WIDTH_A-bit input: Address for port A write and read operations.
|
168 |
|
|
.addrb(addrb), // ADDR_WIDTH_B-bit input: Address for port B write and read operations.
|
169 |
|
|
.clka(clka), // 1-bit input: Clock signal for port A. Also clocks port B when
|
170 |
|
|
// parameter CLOCKING_MODE is "common_clock".
|
171 |
|
|
|
172 |
|
|
.clkb(clkb), // 1-bit input: Clock signal for port B when parameter CLOCKING_MODE is
|
173 |
|
|
// "independent_clock". Unused when parameter CLOCKING_MODE is
|
174 |
|
|
// "common_clock".
|
175 |
|
|
|
176 |
|
|
.dina(dina), // WRITE_DATA_WIDTH_A-bit input: Data input for port A write operations.
|
177 |
|
|
.dinb(dinb), // WRITE_DATA_WIDTH_B-bit input: Data input for port B write operations.
|
178 |
|
|
.ena(ena), // 1-bit input: Memory enable signal for port A. Must be high on clock
|
179 |
|
|
// cycles when read or write operations are initiated. Pipelined
|
180 |
|
|
// internally.
|
181 |
|
|
|
182 |
|
|
.enb(enb), // 1-bit input: Memory enable signal for port B. Must be high on clock
|
183 |
|
|
// cycles when read or write operations are initiated. Pipelined
|
184 |
|
|
// internally.
|
185 |
|
|
|
186 |
|
|
.injectdbiterra(1'b0), // 1-bit input: Controls double bit error injection on input data when
|
187 |
|
|
// ECC enabled (Error injection capability is not available in
|
188 |
|
|
// "decode_only" mode).
|
189 |
|
|
|
190 |
|
|
.injectdbiterrb(1'b0), // 1-bit input: Controls double bit error injection on input data when
|
191 |
|
|
// ECC enabled (Error injection capability is not available in
|
192 |
|
|
// "decode_only" mode).
|
193 |
|
|
|
194 |
|
|
.injectsbiterra(1'b0), // 1-bit input: Controls single bit error injection on input data when
|
195 |
|
|
// ECC enabled (Error injection capability is not available in
|
196 |
|
|
// "decode_only" mode).
|
197 |
|
|
|
198 |
|
|
.injectsbiterrb(1'b0), // 1-bit input: Controls single bit error injection on input data when
|
199 |
|
|
// ECC enabled (Error injection capability is not available in
|
200 |
|
|
// "decode_only" mode).
|
201 |
|
|
|
202 |
|
|
.regcea(1'b1), // 1-bit input: Clock Enable for the last register stage on the output
|
203 |
|
|
// data path.
|
204 |
|
|
|
205 |
|
|
.regceb(1'b1), // 1-bit input: Clock Enable for the last register stage on the output
|
206 |
|
|
// data path.
|
207 |
|
|
|
208 |
|
|
.rsta(1'b0), // 1-bit input: Reset signal for the final port A output register stage.
|
209 |
|
|
// Synchronously resets output port douta to the value specified by
|
210 |
|
|
// parameter READ_RESET_VALUE_A.
|
211 |
|
|
|
212 |
|
|
.rstb(1'b0), // 1-bit input: Reset signal for the final port B output register stage.
|
213 |
|
|
// Synchronously resets output port doutb to the value specified by
|
214 |
|
|
// parameter READ_RESET_VALUE_B.
|
215 |
|
|
|
216 |
|
|
.sleep(1'b0), // 1-bit input: sleep signal to enable the dynamic power saving feature.
|
217 |
|
|
.wea(wea), // WRITE_DATA_WIDTH_A/BYTE_WRITE_WIDTH_A-bit input: Write enable vector
|
218 |
|
|
// for port A input data port dina. 1 bit wide when word-wide writes are
|
219 |
|
|
// used. In byte-wide write configurations, each bit controls the
|
220 |
|
|
// writing one byte of dina to address addra. For example, to
|
221 |
|
|
// synchronously write only bits [15-8] of dina when WRITE_DATA_WIDTH_A
|
222 |
|
|
// is 32, wea would be 4'b0010.
|
223 |
|
|
|
224 |
|
|
.web(web) // WRITE_DATA_WIDTH_B/BYTE_WRITE_WIDTH_B-bit input: Write enable vector
|
225 |
|
|
// for port B input data port dinb. 1 bit wide when word-wide writes are
|
226 |
|
|
// used. In byte-wide write configurations, each bit controls the
|
227 |
|
|
// writing one byte of dinb to address addrb. For example, to
|
228 |
|
|
// synchronously write only bits [15-8] of dinb when WRITE_DATA_WIDTH_B
|
229 |
|
|
// is 32, web would be 4'b0010.
|
230 |
|
|
|
231 |
|
|
);
|
232 |
|
|
|
233 |
|
|
always_ff @(posedge clk_i)
|
234 |
|
|
if (s_cs_i)
|
235 |
|
|
s_dat_o <= {14'h0,douta};
|
236 |
|
|
else
|
237 |
|
|
s_dat_o <= 32'h0;
|
238 |
|
|
|
239 |
|
|
always @(posedge clk_i)
|
240 |
|
|
if (rst_i) begin
|
241 |
|
|
cyc_o <= 1'b0;
|
242 |
|
|
stb_o <= 1'b0;
|
243 |
|
|
pea_o <= 32'h0;
|
244 |
|
|
pdat_o <= 'd0;
|
245 |
|
|
end
|
246 |
|
|
else begin
|
247 |
|
|
pea_o[15: 0] <= s_adr_i[15:0];
|
248 |
|
|
pea_o[31:16] <= doutb[15:0];
|
249 |
|
|
pdat_o <= s_dat_i;
|
250 |
|
|
if (cs) begin
|
251 |
|
|
cyc_o <= 1'b0;
|
252 |
|
|
stb_o <= 1'b0;
|
253 |
|
|
end
|
254 |
|
|
else begin
|
255 |
|
|
cyc_o <= s_cyc_i;
|
256 |
|
|
stb_o <= s_stb_i;
|
257 |
|
|
end
|
258 |
|
|
end
|
259 |
|
|
always_comb
|
260 |
|
|
we_o <= wx[1] & s_we_i;
|
261 |
|
|
|
262 |
|
|
endmodule
|