OpenCores
URL https://opencores.org/ocsvn/plasma/plasma/trunk

Subversion Repositories plasma

[/] [plasma/] [trunk/] [vhdl/] [reg_bank.vhd] - Blame information for rev 139

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 rhoads
---------------------------------------------------------------------
2
-- TITLE: Register Bank
3
-- AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
4
-- DATE CREATED: 2/2/01
5
-- FILENAME: reg_bank.vhd
6 43 rhoads
-- PROJECT: Plasma CPU core
7 2 rhoads
-- COPYRIGHT: Software placed into the public domain by the author.
8
--    Software 'as is' without warranty.  Author liable for nothing.
9
-- DESCRIPTION:
10
--    Implements a register bank with 32 registers that are 32-bits wide.
11
--    There are two read-ports and one write port.
12
---------------------------------------------------------------------
13
library ieee;
14
use ieee.std_logic_1164.all;
15 12 rhoads
use ieee.std_logic_unsigned.all;
16 39 rhoads
use work.mlite_pack.all;
17 139 rhoads
--Uncomment following two lines for Xilinx RAM16X1D
18
library UNISIM;              --Xilinx
19
use UNISIM.vcomponents.all;  --Xilinx
20 2 rhoads
 
21
entity reg_bank is
22 139 rhoads
   generic(memory_type : string := "XILINX_16X");
23 2 rhoads
   port(clk            : in  std_logic;
24 24 rhoads
        reset_in       : in  std_logic;
25 74 rhoads
        pause          : in  std_logic;
26 2 rhoads
        rs_index       : in  std_logic_vector(5 downto 0);
27
        rt_index       : in  std_logic_vector(5 downto 0);
28
        rd_index       : in  std_logic_vector(5 downto 0);
29
        reg_source_out : out std_logic_vector(31 downto 0);
30
        reg_target_out : out std_logic_vector(31 downto 0);
31
        reg_dest_new   : in  std_logic_vector(31 downto 0);
32
        intr_enable    : out std_logic);
33
end; --entity reg_bank
34
 
35 9 rhoads
 
36 8 rhoads
--------------------------------------------------------------------
37 9 rhoads
-- The ram_block architecture attempts to use TWO dual-port memories.
38 12 rhoads
-- Different FPGAs and ASICs need different implementations.
39
-- Choose one of the RAM implementations below.
40 9 rhoads
-- I need feedback on this section!
41 8 rhoads
--------------------------------------------------------------------
42
architecture ram_block of reg_bank is
43 55 rhoads
   signal intr_enable_reg : std_logic;
44 8 rhoads
   type ram_type is array(31 downto 0) of std_logic_vector(31 downto 0);
45 115 rhoads
 
46 9 rhoads
   --controls access to dual-port memories
47 139 rhoads
   signal addr_read1, addr_read2 : std_logic_vector(4 downto 0);
48
   signal addr_write             : std_logic_vector(4 downto 0);
49
   signal data_out1, data_out2   : std_logic_vector(31 downto 0);
50
   signal write_enable           : std_logic;
51 115 rhoads
 
52 8 rhoads
begin
53 115 rhoads
 
54 8 rhoads
reg_proc: process(clk, rs_index, rt_index, rd_index, reg_dest_new,
55 88 rhoads
      intr_enable_reg, data_out1, data_out2, reset_in, pause)
56 8 rhoads
begin
57 9 rhoads
   --setup for first dual-port memory
58
   if rs_index = "101110" then  --reg_epc CP0 14
59 139 rhoads
      addr_read1 <= "00000";
60 9 rhoads
   else
61 139 rhoads
      addr_read1 <= rs_index(4 downto 0);
62 9 rhoads
   end if;
63 8 rhoads
   case rs_index is
64
   when "000000" => reg_source_out <= ZERO;
65 55 rhoads
   when "101100" => reg_source_out <= ZERO(31 downto 1) & intr_enable_reg;
66 139 rhoads
                    --interrupt vector address = 0x3c
67
   when "111111" => reg_source_out <= ZERO(31 downto 8) & "00111100";
68 9 rhoads
   when others   => reg_source_out <= data_out1;
69 8 rhoads
   end case;
70
 
71 9 rhoads
   --setup for second dual-port memory
72 139 rhoads
   addr_read2 <= rt_index(4 downto 0);
73 8 rhoads
   case rt_index is
74
   when "000000" => reg_target_out <= ZERO;
75 9 rhoads
   when others   => reg_target_out <= data_out2;
76 8 rhoads
   end case;
77
 
78 139 rhoads
   --setup write port for both dual-port memories
79 74 rhoads
   if rd_index /= "000000" and rd_index /= "101100" and pause = '0' then
80 9 rhoads
      write_enable <= '1';
81
   else
82
      write_enable <= '0';
83
   end if;
84
   if rd_index = "101110" then  --reg_epc CP0 14
85 139 rhoads
      addr_write <= "00000";
86 9 rhoads
   else
87 139 rhoads
      addr_write <= rd_index(4 downto 0);
88 9 rhoads
   end if;
89
 
90 55 rhoads
   if reset_in = '1' then
91
      intr_enable_reg <= '0';
92
   elsif rising_edge(clk) then
93 88 rhoads
      if rd_index = "101110" then     --reg_epc CP0 14
94
         intr_enable_reg <= '0';      --disable interrupts
95 24 rhoads
      elsif rd_index = "101100" then
96 55 rhoads
         intr_enable_reg <= reg_dest_new(0);
97 9 rhoads
      end if;
98 8 rhoads
   end if;
99
 
100 55 rhoads
   intr_enable <= intr_enable_reg;
101 9 rhoads
end process;
102 8 rhoads
 
103 9 rhoads
 
104 115 rhoads
--------------------------------------------------------------
105
---- Pick only ONE of the dual-port RAM implementations below!
106
--------------------------------------------------------------
107 12 rhoads
 
108
   -- Option #1
109
   -- One tri-port RAM, two read-ports, one write-port
110
   -- 32 registers 32-bits wide
111 47 rhoads
   tri_port_mem:
112 139 rhoads
   if memory_type = "TRI_PORT_X" generate
113
      ram_proc: process(clk, addr_read1, addr_read2,
114
            addr_write, reg_dest_new, write_enable)
115 47 rhoads
      variable tri_port_ram : ram_type;
116
      begin
117 139 rhoads
         data_out1 <= tri_port_ram(conv_integer(addr_read1));
118
         data_out2 <= tri_port_ram(conv_integer(addr_read2));
119 47 rhoads
         if rising_edge(clk) then
120
            if write_enable = '1' then
121 139 rhoads
               tri_port_ram(conv_integer(addr_write)) := reg_dest_new;
122 47 rhoads
            end if;
123 12 rhoads
         end if;
124 47 rhoads
      end process;
125
   end generate; --tri_port_mem
126 9 rhoads
 
127
 
128 12 rhoads
   -- Option #2
129
   -- Two dual-port RAMs, each with one read-port and one write-port
130 47 rhoads
   dual_port_mem:
131 139 rhoads
   if memory_type = "DUAL_PORT_" generate
132
      ram_proc2: process(clk, addr_read1, addr_read2,
133
            addr_write, reg_dest_new, write_enable)
134 47 rhoads
      variable dual_port_ram1 : ram_type;
135
      variable dual_port_ram2 : ram_type;
136
      begin
137 139 rhoads
         data_out1 <= dual_port_ram1(conv_integer(addr_read1));
138
         data_out2 <= dual_port_ram2(conv_integer(addr_read2));
139 47 rhoads
         if rising_edge(clk) then
140
            if write_enable = '1' then
141 139 rhoads
               dual_port_ram1(conv_integer(addr_write)) := reg_dest_new;
142
               dual_port_ram2(conv_integer(addr_write)) := reg_dest_new;
143 47 rhoads
            end if;
144
         end if;
145
      end process;
146
   end generate; --dual_port_mem
147 9 rhoads
 
148
 
149 139 rhoads
   -- Option #3
150
   -- RAM16X1D: 16 x 1 positive edge write, asynchronous read dual-port 
151
   -- distributed RAM for all Xilinx FPGAs
152
   xilinx_16x1d:
153
   if memory_type = "XILINX_16X" generate
154
      signal data_out1A, data_out1B : std_logic_vector(31 downto 0);
155
      signal data_out2A, data_out2B : std_logic_vector(31 downto 0);
156
      signal weA, weB               : std_logic;
157
   begin
158
      weA <= write_enable and not addr_write(4);  --lower 16 registers
159
      weB <= write_enable and addr_write(4);      --upper 16 registers
160
 
161
      reg_loop: for i in 0 to 31 generate
162
      begin
163
         --Read port 1 lower 16 registers
164
         reg_bit1a : RAM16X1D
165
         port map (
166
            WCLK  => clk,              -- Port A write clock input
167
            WE    => weA,              -- Port A write enable input
168
            A0    => addr_write(0),    -- Port A address[0] input bit
169
            A1    => addr_write(1),    -- Port A address[1] input bit
170
            A2    => addr_write(2),    -- Port A address[2] input bit
171
            A3    => addr_write(3),    -- Port A address[3] input bit
172
            D     => reg_dest_new(i),  -- Port A 1-bit data input
173
            DPRA0 => addr_read1(0),    -- Port B address[0] input bit
174
            DPRA1 => addr_read1(1),    -- Port B address[1] input bit
175
            DPRA2 => addr_read1(2),    -- Port B address[2] input bit
176
            DPRA3 => addr_read1(3),    -- Port B address[3] input bit
177
            DPO   => data_out1A(i),    -- Port B 1-bit data output
178
            SPO   => open              -- Port A 1-bit data output
179
         );
180
         --Read port 1 upper 16 registers
181
         reg_bit1b : RAM16X1D
182
         port map (
183
            WCLK  => clk,              -- Port A write clock input
184
            WE    => weB,              -- Port A write enable input
185
            A0    => addr_write(0),    -- Port A address[0] input bit
186
            A1    => addr_write(1),    -- Port A address[1] input bit
187
            A2    => addr_write(2),    -- Port A address[2] input bit
188
            A3    => addr_write(3),    -- Port A address[3] input bit
189
            D     => reg_dest_new(i),  -- Port A 1-bit data input
190
            DPRA0 => addr_read1(0),    -- Port B address[0] input bit
191
            DPRA1 => addr_read1(1),    -- Port B address[1] input bit
192
            DPRA2 => addr_read1(2),    -- Port B address[2] input bit
193
            DPRA3 => addr_read1(3),    -- Port B address[3] input bit
194
            DPO   => data_out1B(i),    -- Port B 1-bit data output
195
            SPO   => open              -- Port A 1-bit data output
196
         );
197
         --Read port 2 lower 16 registers
198
         reg_bit2a : RAM16X1D
199
         port map (
200
            WCLK  => clk,              -- Port A write clock input
201
            WE    => weA,              -- Port A write enable input
202
            A0    => addr_write(0),    -- Port A address[0] input bit
203
            A1    => addr_write(1),    -- Port A address[1] input bit
204
            A2    => addr_write(2),    -- Port A address[2] input bit
205
            A3    => addr_write(3),    -- Port A address[3] input bit
206
            D     => reg_dest_new(i),  -- Port A 1-bit data input
207
            DPRA0 => addr_read2(0),    -- Port B address[0] input bit
208
            DPRA1 => addr_read2(1),    -- Port B address[1] input bit
209
            DPRA2 => addr_read2(2),    -- Port B address[2] input bit
210
            DPRA3 => addr_read2(3),    -- Port B address[3] input bit
211
            DPO   => data_out2A(i),    -- Port B 1-bit data output
212
            SPO   => open              -- Port A 1-bit data output
213
         );
214
         --Read port 2 upper 16 registers
215
         reg_bit2b : RAM16X1D
216
         port map (
217
            WCLK  => clk,              -- Port A write clock input
218
            WE    => weB,              -- Port A write enable input
219
            A0    => addr_write(0),    -- Port A address[0] input bit
220
            A1    => addr_write(1),    -- Port A address[1] input bit
221
            A2    => addr_write(2),    -- Port A address[2] input bit
222
            A3    => addr_write(3),    -- Port A address[3] input bit
223
            D     => reg_dest_new(i),  -- Port A 1-bit data input
224
            DPRA0 => addr_read2(0),    -- Port B address[0] input bit
225
            DPRA1 => addr_read2(1),    -- Port B address[1] input bit
226
            DPRA2 => addr_read2(2),    -- Port B address[2] input bit
227
            DPRA3 => addr_read2(3),    -- Port B address[3] input bit
228
            DPO   => data_out2B(i),    -- Port B 1-bit data output
229
            SPO   => open              -- Port A 1-bit data output
230
         );
231
      end generate; --reg_loop
232 115 rhoads
 
233 139 rhoads
      data_out1 <= data_out1A when addr_read1(4)='0' else data_out1B;
234
      data_out2 <= data_out2A when addr_read2(4)='0' else data_out2B;
235
   end generate; --xilinx_16x1d
236 115 rhoads
 
237
 
238 139 rhoads
   -- Option #4
239
   -- Altera LPM_RAM_DP
240
   -- Xilinx users may need to comment out this section!!!
241
   altera_mem:
242
   if memory_type = "ALTERA_LPM" generate
243
      lpm_ram_dp_component1 : lpm_ram_dp
244
      GENERIC MAP (
245
         lpm_width => 32,
246
         lpm_widthad => 5,
247
         rden_used => "FALSE",
248
         intended_device_family => "UNUSED",
249
         lpm_indata => "REGISTERED",
250
         lpm_wraddress_control => "REGISTERED",
251
         lpm_rdaddress_control => "UNREGISTERED",
252
         lpm_outdata => "UNREGISTERED",
253
         use_eab => "ON",
254
         lpm_type => "LPM_RAM_DP"
255
      )
256
      PORT MAP (
257
         wren => write_enable,
258
         wrclock => clk,
259
         data => reg_dest_new,
260
         rdaddress => addr_read1,
261
         wraddress => addr_write,
262
         q => data_out1
263
      );
264
      lpm_ram_dp_component2 : lpm_ram_dp
265
      GENERIC MAP (
266
         lpm_width => 32,
267
         lpm_widthad => 5,
268
         rden_used => "FALSE",
269
         intended_device_family => "UNUSED",
270
         lpm_indata => "REGISTERED",
271
         lpm_wraddress_control => "REGISTERED",
272
         lpm_rdaddress_control => "UNREGISTERED",
273
         lpm_outdata => "UNREGISTERED",
274
         use_eab => "ON",
275
         lpm_type => "LPM_RAM_DP"
276
      )
277
      PORT MAP (
278
         wren => write_enable,
279
         wrclock => clk,
280
         data => reg_dest_new,
281
         rdaddress => addr_read2,
282
         wraddress => addr_write,
283
         q => data_out2
284
      );
285
   end generate; --altera_mem
286 115 rhoads
 
287
 
288 139 rhoads
   -- Option #5
289
--   dual_port_mem_coregen:
290
--   if memory_type = "DUAL_PORT_XILINX" generate
291
--      reg_file_dp_ram_1: reg_file_dp_ram
292
--        port map (
293
--          addra => addr_read1,
294
--          addrb => addr_write,
295
--          clka  => clk,
296
--          clkb  => clk,
297
--          dinb  => reg_dest_new,
298
--          douta => data_out1,
299
--          web   => write_enable);
300
--
301
--      reg_file_dp_ram_2: reg_file_dp_ram
302
--        port map (
303
--          addra => addr_read2,
304
--          addrb => addr_write,
305
--          clka  => clk,
306
--          clkb  => clk,
307
--          dinb  => reg_dest_new,
308
--          douta => data_out2,
309
--          web   => write_enable);
310
--   end generate; --dual_port_mem
311
 
312
 
313
--   dual_port_mem_xc4000xla: if memory_type = "DUAL_PORT_XILINX_XC4000XLA" generate
314
--     reg_file_dp_ram_1: reg_file_dp_ram_xc4000xla
315
--       port map (
316
--         A      => addr_write,
317
--         DI     => reg_dest_new,
318
--         WR_EN  => write_enable,
319
--         WR_CLK => clk,
320
--         DPRA   => addr_read1,
321
--         SPO    => open,
322
--         DPO    => data_out1);
323
--     
324
--     reg_file_dp_ram_2: reg_file_dp_ram_xc4000xla
325
--       port map (
326
--         A      => addr_write,
327
--         DI     => reg_dest_new,
328
--         WR_EN  => write_enable,
329
--         WR_CLK => clk,
330
--         DPRA   => addr_read2,
331
--         SPO    => open,
332
--         DPO    => data_out2);
333
--   end generate; --dual_port_mem
334
 
335
 
336
   -- Option #6
337 9 rhoads
   -- Generic Two-Port Synchronous RAM
338
   -- generic_tpram can be obtained from:
339
   -- http://www.opencores.org/cvsweb.shtml/generic_memories/
340
   -- Supports ASICs (Artisan, Avant, and Virage) and Xilinx FPGA
341 47 rhoads
--   generic_mem:
342
--   if memory_type = "OPENCORES_MEM" generate
343
--      bank1 : generic_tpram port map (
344
--         clk_a  => clk,
345
--         rst_a  => '0',
346
--         ce_a   => '1',
347
--         we_a   => '0',
348
--         oe_a   => '1',
349 139 rhoads
--         addr_a => addr_read1,
350 47 rhoads
--         di_a   => ZERO,
351
--         do_a   => data_out1,
352 9 rhoads
--
353 47 rhoads
--         clk_b  => clk,
354
--         rst_b  => '0',
355
--         ce_b   => '1',
356
--         we_b   => write_enable,
357
--         oe_b   => '0',
358 139 rhoads
--         addr_b => addr_write,
359 47 rhoads
--         di_a   => reg_dest_new);
360 9 rhoads
--
361 47 rhoads
--      bank2 : generic_tpram port map (
362
--         clk_a  => clk,
363
--         rst_a  => '0',
364
--         ce_a   => '1',
365
--         we_a   => '0',
366
--         oe_a   => '1',
367 139 rhoads
--         addr_a => addr_read2,
368 47 rhoads
--         di_a   => ZERO,
369
--         do_a   => data_out2,
370 9 rhoads
--
371 47 rhoads
--         clk_b  => clk,
372
--         rst_b  => '0',
373
--         ce_b   => '1',
374
--         we_b   => write_enable,
375
--         oe_b   => '0',
376 139 rhoads
--         addr_b => addr_write,
377 47 rhoads
--         di_a   => reg_dest_new);
378
--   end generate; --generic_mem
379 9 rhoads
 
380
 
381 139 rhoads
   -- Option #7
382 9 rhoads
   -- Xilinx mode using four 16x16 banks
383 47 rhoads
--   xilinx_mem:
384
--   if memory_type = "XILINX" generate
385
--      bank1_high: ramb4_s16_s16 port map (
386
--         clka  => clk,
387
--         rsta  => sig_false,
388 139 rhoads
--         addra => addr_read1,
389 47 rhoads
--         dia   => zero_sig,
390
--         ena   => sig_true,
391
--         wea   => sig_false,
392
--         doa   => data_out1(31 downto 16),
393 9 rhoads
--
394 47 rhoads
--         clkb  => clk,
395
--         rstb  => sig_false,
396 139 rhoads
--         addrb => addr_write,
397 47 rhoads
--         dib   => reg_dest_new(31 downto 16),
398
--         enb   => sig_true,
399
--         web   => write_enable);
400 9 rhoads
--
401 47 rhoads
--      bank1_low: ramb4_s16_s16 port map (
402
--         clka  => clk,
403
--         rsta  => sig_false,
404 139 rhoads
--         addra => addr_read1,
405 47 rhoads
--         dia   => zero_sig,
406
--         ena   => sig_true,
407
--         wea   => sig_false,
408
--         doa   => data_out1(15 downto 0),
409 9 rhoads
--
410 47 rhoads
--         clkb  => clk,
411
--         rstb  => sig_false,
412 139 rhoads
--         addrb => addr_write,
413 47 rhoads
--         dib   => reg_dest_new(15 downto 0),
414
--         enb   => sig_true,
415
--         web   => write_enable);
416 9 rhoads
--
417 47 rhoads
--      bank2_high: ramb4_s16_s16 port map (
418
--         clka  => clk,
419
--         rsta  => sig_false,
420 139 rhoads
--         addra => addr_read2,
421 47 rhoads
--         dia   => zero_sig,
422
--         ena   => sig_true,
423
--         wea   => sig_false,
424
--         doa   => data_out2(31 downto 16),
425 9 rhoads
--
426 47 rhoads
--         clkb  => clk,
427
--         rstb  => sig_false,
428 139 rhoads
--         addrb => addr_write,
429 47 rhoads
--         dib   => reg_dest_new(31 downto 16),
430
--         enb   => sig_true,
431
--         web   => write_enable);
432 9 rhoads
--
433 47 rhoads
--      bank2_low: ramb4_s16_s16 port map (
434
--         clka  => clk,
435
--         rsta  => sig_false,
436 139 rhoads
--         addra => addr_read2,
437 47 rhoads
--         dia   => zero_sig,
438
--         ena   => sig_true,
439
--         wea   => sig_false,
440
--         doa   => data_out2(15 downto 0),
441 9 rhoads
--
442 47 rhoads
--         clkb  => clk,
443
--         rstb  => sig_false,
444 139 rhoads
--         addrb => addr_write,
445 47 rhoads
--         dib   => reg_dest_new(15 downto 0),
446
--         enb   => sig_true,
447
--         web   => write_enable);
448
--   end generate; --xilinx_mem
449 9 rhoads
 
450 12 rhoads
end; --architecture ram_block

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.