-
Notifications
You must be signed in to change notification settings - Fork 3
/
top.vhd
309 lines (257 loc) · 7.82 KB
/
top.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
library IEEE;
use IEEE.std_logic_1164.all;
library UNISIM;
use UNISIM.VComponents.all;
use work.types.all;
entity top is
port (
MCLK1 : in std_logic;
XRST : in std_logic;
RS_TX : out std_logic;
RS_RX : in std_logic;
ZD : inout std_logic_vector(31 downto 0);
ZDP : inout std_logic_vector(3 downto 0);
ZA : out std_logic_vector(19 downto 0);
XE1 : out std_logic;
E2A : out std_logic;
XE3 : out std_logic;
XZBE : out std_logic_vector(3 downto 0);
XGA : out std_logic;
XWA : out std_logic;
XZCKE : out std_logic;
ZCLKMA : out std_logic_vector(1 downto 0);
ADVA : out std_logic;
XFT : out std_logic;
XLBO : out std_logic;
ZZA : out std_logic);
end entity;
architecture Behavioral of top is
constant use_default_clock : boolean := false;
signal iclk, clk : std_logic := '0';
signal dcm_clk1, dcm_clkfd, dcm_clkfx : std_logic := '0';
signal rst : std_logic;
signal cpu_in : cpu_in_type := cpu_in_zero;
signal cpu_out : cpu_out_type := cpu_out_zero;
signal alu_in : alu_in_type := alu_in_zero;
signal alu_out : alu_out_type := alu_out_zero;
signal fpu_in : fpu_in_type := fpu_in_zero;
signal fpu_out : fpu_out_type := fpu_out_zero;
signal icache_in : icache_in_type := icache_in_zero;
signal icache_out : icache_out_type := icache_out_zero;
signal dcache_in : dcache_in_type := dcache_in_zero;
signal dcache_out : dcache_out_type := dcache_out_zero;
signal uart_in : uart_in_type := uart_in_zero;
signal uart_out : uart_out_type := uart_out_zero;
signal sram_out : sram_out_type := sram_out_zero;
signal sram_in : sram_in_type := sram_in_zero;
signal ram_out : ram_out_type := ram_out_zero;
signal ram_in : ram_in_type := ram_in_zero;
signal rom_out : rom_out_type := rom_out_zero;
signal rom_in : rom_in_type := rom_in_zero;
signal timer_in : timer_in_type := timer_in_zero;
signal timer_out : timer_out_type := timer_out_zero;
signal count : natural := 0;
begin -- architecture Behavioral
ib: IBUFG port map (
i => MCLK1,
o => iclk);
clk66: if use_default_clock generate
b1: BUFG port map (
i => iclk,
o => clk);
end generate;
clk93: if not use_default_clock generate
dcm : DCM_BASE
generic map (
clkfx_divide => 9,
clkfx_multiply => 13)
port map (
rst => not xrst,
clkin => iclk,
clkfb => dcm_clkfd,
clk0 => dcm_clk1,
clk90 => open,
clk180 => open,
clk270 => open,
clk2x => open,
clk2x180 => open,
clkdv => open,
clkfx => dcm_clkfx,
clkfx180 => open);
b1: BUFG port map (
i => dcm_clk1,
o => dcm_clkfd);
bfx : BUFG port map (
i => dcm_clkfx,
o => clk);
end generate;
rst <= (not XRST) when count > 100000 else '1';
process(clk) is
begin
if rising_edge(clk) then
if count <= 100000 then
count <= count + 1;
end if;
end if;
end process;
cpu_1: entity work.cpu
port map (
clk => clk,
rst => rst,
cpu_in => cpu_in,
cpu_out => cpu_out);
alu_in.stall <= dcache_out.stall;
alu_in.optag <= cpu_out.optag;
alu_in.data_a <= cpu_out.data_a;
alu_in.data_b <= cpu_out.data_b;
alu_in.data_l <= cpu_out.data_l;
cpu_in.alu_res <= alu_out.res;
fpu_in.stall <= dcache_out.stall;
fpu_in.optag <= cpu_out.optag;
fpu_in.signop <= cpu_out.signop;
fpu_in.data_a <= cpu_out.data_a;
fpu_in.data_b <= cpu_out.data_b;
cpu_in.fpu_res <= fpu_out.res;
cpu_in.d_stall <= dcache_out.stall;
cpu_in.d_data <= dcache_out.rx;
cpu_in.d_data <= uart_out.rx;
cpu_in.d_data <= rom_out.rx1;
-- pragma synthesis_off
cpu_in.d_data <= (others => 'H');
-- pragma synthesis_on
cpu_in.i_stall <= icache_out.stall;
cpu_in.i_data <= icache_out.rx;
cpu_in.i_data <= rom_out.rx2;
-- pragma synthesis_off
cpu_in.i_data <= (others => 'H');
-- pragma synthesis_on
cpu_in.int_go <= uart_out.int_go or timer_out.int_go;
cpu_in.int_cause <= x"00000001" when timer_out.int_go = '1' else
x"00000002" when uart_out.int_go = '1' else
x"00000000";
dcache_in.cai <= cpu_out.cai;
dcache_in.b <= cpu_out.d_b;
dcache_in.we <= cpu_out.d_we;
dcache_in.re <= cpu_out.d_re;
dcache_in.addr <= cpu_out.d_addr;
dcache_in.val <= cpu_out.d_data;
dcache_in.vmm_en <= cpu_out.vmm_en;
dcache_in.vmm_pd <= cpu_out.vmm_pd;
icache_in.cai <= cpu_out.cai;
icache_in.co_we <= cpu_out.d_we;
icache_in.co_addr <= cpu_out.d_addr;
icache_in.re <= cpu_out.i_re;
icache_in.addr <= cpu_out.i_addr;
icache_in.vmm_en <= cpu_out.vmm_en;
icache_in.vmm_pd <= cpu_out.vmm_pd;
uart_in.addr <= cpu_out.d_addr;
uart_in.we <= cpu_out.d_we;
uart_in.re <= cpu_out.d_re;
uart_in.val <= cpu_out.d_data;
uart_in.eoi <= cpu_out.eoi when cpu_out.eoi_id = x"00000002" else '0';
rom_in.addr1 <= cpu_out.d_addr;
rom_in.addr2 <= cpu_out.i_addr;
timer_in.eoi <= cpu_out.eoi when cpu_out.eoi_id = x"00000001" else '0';
alu_1: entity work.alu
port map (
clk => clk,
rst => rst,
alu_in => alu_in,
alu_out => alu_out);
fpu_1: entity work.fpu
port map (
clk => clk,
rst => rst,
fpu_in => fpu_in,
fpu_out => fpu_out);
blockram_1 : entity work.blockram
generic map (
dwidth => 32,
awidth => 12)
port map (
clk => clk,
we => dcache_out.bram_we,
di => dcache_out.bram_di,
do => dcache_in.bram_do,
addr => dcache_out.bram_addr);
dcache_1 : entity work.dcache
port map (
clk => clk,
rst => rst,
dcache_in => dcache_in,
dcache_out => dcache_out);
dcache_in.ram_grnt <= ram_out.grnt1;
dcache_in.ram_data <= ram_out.data1;
ram_in.req1 <= dcache_out.ram_req;
ram_in.data1 <= dcache_out.ram_data;
ram_in.addr1 <= dcache_out.ram_addr;
ram_in.we1 <= dcache_out.ram_we;
blockram_2: entity work.blockram
generic map (
dwidth => 32,
awidth => 12)
port map (
clk => clk,
we => icache_out.bram_we,
di => icache_out.bram_di,
do => icache_in.bram_do,
addr => icache_out.bram_addr);
icache_2 : entity work.icache
port map (
clk => clk,
rst => rst,
icache_in => icache_in,
icache_out => icache_out);
icache_in.ram_grnt <= ram_out.grnt2;
icache_in.ram_data <= ram_out.data2;
ram_in.req2 <= icache_out.ram_req;
ram_in.addr2 <= icache_out.ram_addr;
ram_1: entity work.ram
port map (
clk => clk,
rst => rst,
ram_in => ram_in,
ram_out => ram_out,
sram_in => sram_in,
sram_out => sram_out);
uart_1 : entity work.uart
port map (
clk => clk,
rst => rst,
uart_in => uart_in,
uart_out => uart_out,
RS_TX => RS_TX,
RS_RX => RS_RX);
rom_1 : entity work.rom
port map (
clk => clk,
rom_in => rom_in,
rom_out => rom_out);
sram_1 : entity work.sram
port map (
clk => clk,
sram_in => sram_in,
sram_out => sram_out,
ZD => ZD,
ZDP => ZDP,
ZA => ZA,
XWA => XWA);
timer_1: entity work.timer
port map (
clk => clk,
rst => rst,
timer_in => timer_in,
timer_out => timer_out);
XE1 <= '0';
E2A <= '1';
XE3 <= '0';
XZBE <= "0000";
XGA <= '0';
XZCKE <= '0';
ZCLKMA(0) <= clk;
ZCLKMA(1) <= clk;
ADVA <= '0';
XFT <= not '0';
XLBO <= '1';
ZZA <= '0';
end architecture;