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

Subversion Repositories plasma

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

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 39 rhoads
-- PROJECT: M-lite 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 2 rhoads
 
18
entity reg_bank is
19
   port(clk            : in  std_logic;
20 24 rhoads
        reset_in       : in  std_logic;
21 2 rhoads
        rs_index       : in  std_logic_vector(5 downto 0);
22
        rt_index       : in  std_logic_vector(5 downto 0);
23
        rd_index       : in  std_logic_vector(5 downto 0);
24
        reg_source_out : out std_logic_vector(31 downto 0);
25
        reg_target_out : out std_logic_vector(31 downto 0);
26
        reg_dest_new   : in  std_logic_vector(31 downto 0);
27
        intr_enable    : out std_logic);
28
end; --entity reg_bank
29
 
30 9 rhoads
 
31 8 rhoads
--------------------------------------------------------------------
32 9 rhoads
-- The ram_block architecture attempts to use TWO dual-port memories.
33 12 rhoads
-- Different FPGAs and ASICs need different implementations.
34
-- Choose one of the RAM implementations below.
35 9 rhoads
-- I need feedback on this section!
36 8 rhoads
--------------------------------------------------------------------
37
architecture ram_block of reg_bank is
38 9 rhoads
   signal reg_status : std_logic;
39 8 rhoads
   type ram_type is array(31 downto 0) of std_logic_vector(31 downto 0);
40
 
41 9 rhoads
   --controls access to dual-port memories
42
   signal addr_a1, addr_a2, addr_b : std_logic_vector(4 downto 0);
43
   signal data_out1, data_out2     : std_logic_vector(31 downto 0);
44
   signal write_enable             : std_logic;
45 8 rhoads
begin
46
 
47
reg_proc: process(clk, rs_index, rt_index, rd_index, reg_dest_new,
48 9 rhoads
      reg_status, data_out1, data_out2)
49 8 rhoads
begin
50 9 rhoads
   --setup for first dual-port memory
51
   if rs_index = "101110" then  --reg_epc CP0 14
52
      addr_a1 <= "00000";
53
   else
54
      addr_a1 <= rs_index(4 downto 0);
55
   end if;
56 8 rhoads
   case rs_index is
57
   when "000000" => reg_source_out <= ZERO;
58
   when "101100" => reg_source_out <= ZERO(31 downto 1) & reg_status;
59
   when "111111" => reg_source_out <= ZERO(31 downto 8) & "00110000"; --intr vector
60 9 rhoads
   when others   => reg_source_out <= data_out1;
61 8 rhoads
   end case;
62
 
63 9 rhoads
   --setup for second dual-port memory
64
   addr_a2 <= rt_index(4 downto 0);
65 8 rhoads
   case rt_index is
66
   when "000000" => reg_target_out <= ZERO;
67 9 rhoads
   when others   => reg_target_out <= data_out2;
68 8 rhoads
   end case;
69
 
70 9 rhoads
   --setup second port (write port) for both dual-port memories
71
   if rd_index /= "000000" and rd_index /= "101100" then
72
      write_enable <= '1';
73
   else
74
      write_enable <= '0';
75
   end if;
76
   if rd_index = "101110" then  --reg_epc CP0 14
77
      addr_b <= "00000";
78
   else
79
      addr_b <= rd_index(4 downto 0);
80
   end if;
81
 
82 8 rhoads
   if rising_edge(clk) then
83 24 rhoads
      if reset_in = '1' or rd_index = "101110" then  --reg_epc CP0 14
84
         reg_status <= '0';           --disable interrupts
85
      elsif rd_index = "101100" then
86 9 rhoads
         reg_status <= reg_dest_new(0);
87
      end if;
88 8 rhoads
   end if;
89
 
90
   intr_enable <= reg_status;
91 9 rhoads
end process;
92 8 rhoads
 
93 9 rhoads
 
94 12 rhoads
------------------------------------------------------------
95
-- Pick only ONE of the dual-port RAM implementations below!
96
------------------------------------------------------------
97
 
98
 
99
   -- Option #1
100
   -- One tri-port RAM, two read-ports, one write-port
101
   -- 32 registers 32-bits wide
102
   ram_proc: process(clk, addr_a1, addr_a2, addr_b, reg_dest_new,
103
         write_enable)
104
   variable tri_port_ram : ram_type;
105
   begin
106
      data_out1 <= tri_port_ram(conv_integer(addr_a1));
107
      data_out2 <= tri_port_ram(conv_integer(addr_a2));
108
      if rising_edge(clk) then
109
         if write_enable = '1' then
110
            tri_port_ram(conv_integer(addr_b)) := reg_dest_new;
111
         end if;
112 9 rhoads
      end if;
113 12 rhoads
   end process;
114 9 rhoads
 
115
 
116 12 rhoads
   -- Option #2
117
   -- Two dual-port RAMs, each with one read-port and one write-port
118
   -- According to the Xilinx answers database record #4075 this 
119
   -- architecture may cause Synplify to infer synchronous dual-port 
120
   -- RAM using RAM16x1D.  
121
--   ram_proc: process(clk, addr_a1, addr_a2, addr_b, reg_dest_new, 
122
--         write_enable)
123
--   variable dual_port_ram1 : ram_type;
124
--   variable dual_port_ram2 : ram_type;
125
--   begin
126
--      data_out1 <= dual_port_ram1(conv_integer(addr_a1));
127
--      data_out2 <= dual_port_ram2(conv_integer(addr_a2));
128
--      if rising_edge(clk) then
129
--         if write_enable = '1' then
130
--            dual_port_ram1(conv_integer(addr_b)) := reg_dest_new;
131
--            dual_port_ram2(conv_integer(addr_b)) := reg_dest_new;
132
--         end if;
133 9 rhoads
--      end if;
134 12 rhoads
--   end process;
135 9 rhoads
 
136
 
137 12 rhoads
   -- Option #3
138 9 rhoads
   -- Generic Two-Port Synchronous RAM
139
   -- generic_tpram can be obtained from:
140
   -- http://www.opencores.org/cvsweb.shtml/generic_memories/
141
   -- Supports ASICs (Artisan, Avant, and Virage) and Xilinx FPGA
142
--   bank1 : generic_tpram port map (
143
--      clk_a  => clk,
144
--      rst_a  => '0',
145
--      ce_a   => '1',
146
--      we_a   => '0',
147
--      oe_a   => '1',
148
--      addr_a => addr_a1,
149
--      di_a   => ZERO,
150
--      do_a   => data_out1,
151
--
152
--      clk_b  => clk,
153
--      rst_b  => '0',
154
--      ce_b   => '1',
155
--      we_b   => write_enable,
156
--      oe_b   => '0',
157
--      addr_b => addr_b,
158
--      di_a   => reg_dest_new);
159
--
160
--   bank2 : generic_tpram port map (
161
--      clk_a  => clk,
162
--      rst_a  => '0',
163
--      ce_a   => '1',
164
--      we_a   => '0',
165
--      oe_a   => '1',
166
--      addr_a => addr_a2,
167
--      di_a   => ZERO,
168
--      do_a   => data_out2,
169
--
170
--      clk_b  => clk,
171
--      rst_b  => '0',
172
--      ce_b   => '1',
173
--      we_b   => write_enable,
174
--      oe_b   => '0',
175
--      addr_b => addr_b,
176
--      di_a   => reg_dest_new);
177
 
178
 
179 12 rhoads
   -- Option #4
180 9 rhoads
   -- Xilinx mode using four 16x16 banks
181
--   bank1_high: ramb4_s16_s16 port map (
182
--      clka  => clk,
183
--      rsta  => sig_false,
184
--      addra => addr_a1,
185
--      dia   => ZERO(31 downto 16),
186
--      ena   => sig_true,
187
--      wea   => sig_false,
188
--      doa   => data_out1(31 downto 16),
189
--
190
--      clkb  => clk,
191
--      rstb  => sig_false,
192
--      addrb => addr_b,
193
--      dib   => reg_dest_new(31 downto 16),
194
--      enb   => sig_true,
195
--      web   => write_enable);
196
--
197
--   bank1_low: ramb4_s16_s16 port map (
198
--      clka  => clk,
199
--      rsta  => sig_false,
200
--      addra => addr_a1,
201
--      dia   => ZERO(15 downto 0),
202
--      ena   => sig_true,
203
--      wea   => sig_false,
204
--      doa   => data_out1(15 downto 0),
205
--
206
--      clkb  => clk,
207
--      rstb  => sig_false,
208
--      addrb => addr_b,
209
--      dib   => reg_dest_new(15 downto 0),
210
--      enb   => sig_true,
211
--      web   => write_enable);
212
--
213
--   bank2_high: ramb4_s16_s16 port map (
214
--      clka  => clk,
215
--      rsta  => sig_false,
216
--      addra => addr_a2,
217
--      dia   => ZERO(31 downto 16),
218
--      ena   => sig_true,
219
--      wea   => sig_false,
220
--      doa   => data_out2(31 downto 16),
221
--
222
--      clkb  => clk,
223
--      rstb  => sig_false,
224
--      addrb => addr_b,
225
--      dib   => reg_dest_new(31 downto 16),
226
--      enb   => sig_true,
227
--      web   => write_enable);
228
--
229
--   bank2_low: ramb4_s16_s16 port map (
230
--      clka  => clk,
231
--      rsta  => sig_false,
232
--      addra => addr_a2,
233
--      dia   => ZERO(15 downto 0),
234
--      ena   => sig_true,
235
--      wea   => sig_false,
236
--      doa   => data_out2(15 downto 0),
237
--
238
--      clkb  => clk,
239
--      rstb  => sig_false,
240
--      addrb => addr_b,
241
--      dib   => reg_dest_new(15 downto 0),
242
--      enb   => sig_true,
243
--      web   => write_enable);
244
 
245 8 rhoads
 
246 12 rhoads
   -- Option #5
247
   -- Altera LPM_RAM_DP
248
--   bank1: LPM_RAM_DP 
249
--      generic map (
250
--      LPM_WIDTH    => 32,
251
--      LPM_WIDTHAD  => 5,
252
--      LPM_NUMWORDS => 32,
253
--??      LPM_INDATA   => "UNREGISTERED",
254
--??      LPM_OUTDATA  => "UNREGISTERED",
255
--??      LPM_RDADDRESS_CONTROL => "UNREGISTERED",
256
--??      LPM_WRADDRESS_CONTROL => "UNREGISTERED"
257
--   )
258
--   port map (RDCLOCK => clk,
259
--      RDADDRESS => addr_a1,
260
--      DATA      => reg_dest_new,
261
--      WRADDRESS => addr_b,
262
--      WREN      => write_enable,
263
--      WRCLOCK   => clk,
264
--      Q         => data_out1);
265
--
266
--   bank2: LPM_RAM_DP 
267
--      generic map (
268
--      LPM_WIDTH    => 32,
269
--      LPM_WIDTHAD  => 5,
270
--      LPM_NUMWORDS => 32,
271
--??      LPM_INDATA   => "UNREGISTERED",
272
--??      LPM_OUTDATA  => "UNREGISTERED",
273
--??      LPM_RDADDRESS_CONTROL => "UNREGISTERED",
274
--??      LPM_WRADDRESS_CONTROL => "UNREGISTERED"
275
--   )
276
--   port map (RDCLOCK => clk,
277
--      RDADDRESS => addr_a2,
278
--      DATA      => reg_dest_new,
279
--      WRADDRESS => addr_b,
280
--      WREN      => write_enable,
281
--      WRCLOCK   => clk,
282
--      Q         => data_out2);
283 8 rhoads
 
284
 
285 12 rhoads
end; --architecture ram_block
286 2 rhoads
 

powered by: WebSVN 2.1.0

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