1 |
48 |
robfinch |
`timescale 1ns / 1ps
|
2 |
|
|
// ============================================================================
|
3 |
|
|
// __
|
4 |
|
|
// \\__/ o\ (C) 2016-2018 Robert Finch, Waterloo
|
5 |
|
|
// \ __ / All rights reserved.
|
6 |
|
|
// \/_// robfinch<remove>@finitron.ca
|
7 |
|
|
// ||
|
8 |
|
|
//
|
9 |
|
|
// FT64_MMU.v
|
10 |
|
|
//
|
11 |
|
|
//
|
12 |
|
|
// This source file is free software: you can redistribute it and/or modify
|
13 |
|
|
// it under the terms of the GNU Lesser General Public License as published
|
14 |
|
|
// by the Free Software Foundation, either version 3 of the License, or
|
15 |
|
|
// (at your option) any later version.
|
16 |
|
|
//
|
17 |
|
|
// This source file is distributed in the hope that it will be useful,
|
18 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20 |
|
|
// GNU General Public License for more details.
|
21 |
|
|
//
|
22 |
|
|
// You should have received a copy of the GNU General Public License
|
23 |
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
24 |
|
|
//
|
25 |
|
|
//
|
26 |
|
|
// ============================================================================
|
27 |
|
|
//
|
28 |
|
|
`define LOW 1'b0
|
29 |
|
|
`define HIGH 1'b1
|
30 |
|
|
|
31 |
|
|
module FT64_mmu(rst_i, clk_i, ol_i, pcr_i, pcr2_i, mapen_i, s_ex_i, s_cyc_i, s_stb_i, s_ack_o, s_wr_i, s_adr_i, s_dat_i, s_dat_o,
|
32 |
|
|
pea_o, cyc_o, stb_o,
|
33 |
|
|
exv_o, rdv_o, wrv_o);
|
34 |
|
|
input rst_i;
|
35 |
|
|
input clk_i;
|
36 |
|
|
input [2:0] ol_i;
|
37 |
|
|
input [31:0] pcr_i; // paging enabled
|
38 |
|
|
input [63:0] pcr2_i;
|
39 |
|
|
input mapen_i;
|
40 |
|
|
input s_ex_i; // executable address
|
41 |
|
|
input s_cyc_i;
|
42 |
|
|
input s_stb_i;
|
43 |
|
|
input s_wr_i; // write strobe
|
44 |
|
|
output s_ack_o;
|
45 |
|
|
input [31:0] s_adr_i; // virtual address
|
46 |
|
|
input [31:0] s_dat_i;
|
47 |
|
|
output [31:0] s_dat_o;
|
48 |
|
|
output reg [31:0] pea_o;
|
49 |
|
|
output reg cyc_o;
|
50 |
|
|
output reg stb_o;
|
51 |
|
|
output reg exv_o; // execute violation
|
52 |
|
|
output reg rdv_o; // read violation
|
53 |
|
|
output reg wrv_o; // write violation
|
54 |
|
|
|
55 |
|
|
wire cs = s_cyc_i && s_stb_i && (s_adr_i[31:12]==20'hFFDC4);
|
56 |
|
|
wire [5:0] okey = pcr_i[5:0];
|
57 |
|
|
wire [5:0] akey = pcr_i[13:8];
|
58 |
|
|
wire mol = ol_i==3'b000; // machine operating level
|
59 |
|
|
|
60 |
|
|
reg ack1, ack2, ack3;
|
61 |
|
|
always @(posedge clk_i)
|
62 |
|
|
ack1 <= cs;
|
63 |
|
|
always @(posedge clk_i)
|
64 |
|
|
ack2 <= ack1 & (cs);
|
65 |
|
|
assign s_ack_o = (cs) ? ack2 : 1'b0;
|
66 |
|
|
|
67 |
|
|
reg cyc1,cyc2,stb1,stb2;
|
68 |
|
|
wire [20:0] douta,doutb;
|
69 |
|
|
wire [20:0] doutca;
|
70 |
|
|
wire [2:0] cwrx = doutb[18:16];
|
71 |
|
|
|
72 |
|
|
always @(posedge clk_i)
|
73 |
|
|
exv_o <= s_ex_i & ~cwrx[0] & cyc2 & stb2 & mapen_i;
|
74 |
|
|
always @(posedge clk_i)
|
75 |
|
|
rdv_o <= ~(s_wr_i | s_ex_i) & ~cwrx[1] & cyc2 & stb2 & mapen_i;
|
76 |
|
|
always @(posedge clk_i)
|
77 |
|
|
wrv_o <= s_wr_i & ~cwrx[2] & cyc2 & stb2 & mapen_i;
|
78 |
|
|
|
79 |
|
|
wire [15:0] addra = {akey,s_adr_i[11:2]};
|
80 |
|
|
wire [15:0] addrb = pcr2_i[okey] ? {okey,s_adr_i[28:19]} :
|
81 |
|
|
{okey,s_adr_i[22:13]};
|
82 |
|
|
|
83 |
|
|
FT64_MMURam1 u1 (
|
84 |
|
|
.clka(clk_i), // input wire clka
|
85 |
|
|
.ena(cs), // input wire ena
|
86 |
|
|
.wea(cs & s_wr_i), // input wire [0 : 0] wea
|
87 |
|
|
.addra(addra), // input wire [15 : 0] addra
|
88 |
|
|
.dina(s_dat_i[20:0]), // input wire [12 : 0] dina
|
89 |
|
|
.douta(douta),
|
90 |
|
|
.clkb(clk_i), // input wire clkb
|
91 |
|
|
.enb(mapen_i), // input wire enb
|
92 |
|
|
.web(1'b0),
|
93 |
|
|
.addrb(addrb), // input wire [13 : 0] addrb
|
94 |
|
|
.dinb(21'h0),
|
95 |
|
|
.doutb(doutb) // output wire [51 : 0] doutb
|
96 |
|
|
);
|
97 |
|
|
|
98 |
|
|
assign s_dat_o = {11'd0,douta};
|
99 |
|
|
|
100 |
|
|
// The following delay reg is to keep all the address bits in sync
|
101 |
|
|
// with the output of the map table. So there are no intermediate
|
102 |
|
|
// invalid addresses.
|
103 |
|
|
reg mapen1, mapen2;
|
104 |
|
|
reg [31:0] s_adr1, s_adr2;
|
105 |
|
|
reg _4MB1, _4MB2;
|
106 |
|
|
always @(posedge clk_i)
|
107 |
|
|
s_adr1 <= s_adr_i;
|
108 |
|
|
always @(posedge clk_i)
|
109 |
|
|
s_adr2 <= s_adr1;
|
110 |
|
|
always @(posedge clk_i)
|
111 |
|
|
_4MB1 <= pcr2_i[okey];
|
112 |
|
|
always @(posedge clk_i)
|
113 |
|
|
_4MB2 <= _4MB1 | !mapen1;
|
114 |
|
|
always @(posedge clk_i)
|
115 |
|
|
mapen1 <= !mol && mapen_i && (s_adr_i[31:29]==3'h0);
|
116 |
|
|
always @(posedge clk_i)
|
117 |
|
|
mapen2 <= mapen1;
|
118 |
|
|
always @(posedge clk_i)
|
119 |
|
|
cyc1 <= s_cyc_i;
|
120 |
|
|
always @(posedge clk_i)
|
121 |
|
|
cyc2 <= cyc1 & s_cyc_i;
|
122 |
|
|
always @(posedge clk_i)
|
123 |
|
|
stb1 <= s_stb_i;
|
124 |
|
|
always @(posedge clk_i)
|
125 |
|
|
stb2 <= stb1 & s_stb_i;
|
126 |
|
|
|
127 |
|
|
always @(posedge clk_i)
|
128 |
|
|
if (rst_i) begin
|
129 |
|
|
cyc_o <= 1'b0;
|
130 |
|
|
stb_o <= 1'b0;
|
131 |
|
|
pea_o <= 32'hFFFC0100;
|
132 |
|
|
end
|
133 |
|
|
else begin
|
134 |
|
|
pea_o[12:0] <= s_adr2[12:0];
|
135 |
|
|
pea_o[18:13] <= mapen2 ? (_4MB2 ? s_adr2[18:13] : doutb[5:0]) : s_adr2[18:13];
|
136 |
|
|
pea_o[28:19] <= mapen2 ? doutb[15:6] : s_adr2[28:19];
|
137 |
|
|
pea_o[31:29] <= s_adr2[31:29];
|
138 |
|
|
cyc_o <= cyc2 & s_cyc_i;
|
139 |
|
|
stb_o <= stb2 & s_stb_i;
|
140 |
|
|
end
|
141 |
|
|
|
142 |
|
|
endmodule
|