c2b040193a777c09bdc595c95492b57a2521db87
Stefan Schuermans added file headers

Stefan Schuermans authored 12 years ago

1) -- MIPS I system
2) -- Copyright 2011-2012 Stefan Schuermans <stefan@schuermans.info>
3) -- Copyleft GNU public license V2 or later
4) --          http://www.gnu.org/copyleft/gpl.html
5) 
Stefan Schuermans added register file

Stefan Schuermans authored 12 years ago

6) LIBRARY ieee;
7) USE ieee.std_logic_1164.all;
8) USE ieee.numeric_std.all;
9) USE work.mips_types.all;
10) 
11) ENTITY e_mips_regs IS
12)     PORT (
13)         clk:         IN  std_logic;
14)         i_rd_a_no:   IN  std_logic_vector( 4 DOWNTO 0);
15)         o_rd_a_data: OUT std_logic_vector(31 DOWNTO 0);
16)         i_rd_b_no:   IN  std_logic_vector( 4 DOWNTO 0);
17)         o_rd_b_data: OUT std_logic_vector(31 DOWNTO 0);
18)         i_wr_no:     IN  std_logic_vector( 4 DOWNTO 0);
19)         i_wr_data:   IN  std_logic_vector(31 DOWNTO 0);
20)         i_wr_en:     IN  std_logic
21)     );
22) END ENTITY e_mips_regs;
23) 
24) ARCHITECTURE a_mips_regs OF e_mips_regs IS
25) 
26)     SUBTYPE t_idx IS natural RANGE 31 DOWNTO 0;
27) 
28)     TYPE t_regs IS ARRAY(t_idx) OF std_logic_vector(31 DOWNTO 0);
29) 
Stefan Schuermans add initial values for regi...

Stefan Schuermans authored 12 years ago

30)     SIGNAL r_regs: t_regs := (OTHERS => (OTHERS => '0'));
Stefan Schuermans added register file

Stefan Schuermans authored 12 years ago

31) 
32)     FUNCTION no2idx(no: std_logic_vector(4 DOWNTO 0)) RETURN natural IS
33)     BEGIN
34)         RETURN to_integer(unsigned(no));
35)     END FUNCTION no2idx;
36) 
37) BEGIN
38) 
Stefan Schuermans fix sensitivity lists

Stefan Schuermans authored 12 years ago

39)     p_read_a: PROCESS(i_rd_a_no, r_regs)
Stefan Schuermans implemented "register 0 is...

Stefan Schuermans authored 12 years ago

40)     BEGIN
41)         IF i_rd_a_no = "00000" THEN
42)             o_rd_a_data <= X"00000000";
43)         ELSE
44)             o_rd_a_data <= r_regs(no2idx(i_rd_a_no));
45)         END IF;
46)     END PROCESS p_read_a;
Stefan Schuermans added register file

Stefan Schuermans authored 12 years ago

47) 
Stefan Schuermans fix sensitivity lists

Stefan Schuermans authored 12 years ago

48)     p_read_b: PROCESS(i_rd_b_no, r_regs)
Stefan Schuermans implemented "register 0 is...

Stefan Schuermans authored 12 years ago

49)     BEGIN
50)         IF i_rd_b_no = "00000" THEN
51)             o_rd_b_data <= X"00000000";
52)         ELSE
53)             o_rd_b_data <= r_regs(no2idx(i_rd_b_no));
54)         END IF;
55)     END PROCESS p_read_b;
Stefan Schuermans added register file

Stefan Schuermans authored 12 years ago

56) 
Stefan Schuermans add initial values for regi...

Stefan Schuermans authored 12 years ago

57)     p_write: PROCESS(clk)
Stefan Schuermans added register file

Stefan Schuermans authored 12 years ago

58)     BEGIN
Stefan Schuermans add initial values for regi...

Stefan Schuermans authored 12 years ago

59)         IF rising_edge(clk) THEN
Stefan Schuermans implemented "register 0 is...

Stefan Schuermans authored 12 years ago

60)             IF i_wr_en = '1' THEN