2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
8 entity register_file is
10 SIM : boolean := false
15 d_in : in Decode2ToRegisterFileType;
16 d_out : out RegisterFileToDecode2Type;
18 w_in : in WritebackToRegisterFileType;
20 dbg_gpr_req : in std_ulogic;
21 dbg_gpr_ack : out std_ulogic;
22 dbg_gpr_addr : in gspr_index_t;
23 dbg_gpr_data : out std_ulogic_vector(63 downto 0);
26 sim_dump : in std_ulogic;
27 sim_dump_done : out std_ulogic;
29 log_out : out std_ulogic_vector(70 downto 0)
31 end entity register_file;
33 architecture behaviour of register_file is
34 type regfile is array(0 to 63) of std_ulogic_vector(63 downto 0);
35 signal registers : regfile := (others => (others => '0'));
36 signal rd_port_b : std_ulogic_vector(63 downto 0);
37 signal dbg_data : std_ulogic_vector(63 downto 0);
38 signal dbg_ack : std_ulogic;
39 signal log_data : std_ulogic_vector(70 downto 0);
42 register_write_0: process(clk)
44 if rising_edge(clk) then
45 if w_in.write_enable = '1' then
46 if w_in.write_reg(5) = '0' then
47 report "Writing GPR " & to_hstring(w_in.write_reg) & " " & to_hstring(w_in.write_data);
49 report "Writing GSPR " & to_hstring(w_in.write_reg) & " " & to_hstring(w_in.write_data);
51 assert not(is_x(w_in.write_data)) and not(is_x(w_in.write_reg)) severity failure;
52 registers(to_integer(unsigned(w_in.write_reg))) <= w_in.write_data;
55 end process register_write_0;
58 register_read_0: process(all)
59 variable b_addr : gspr_index_t;
61 if d_in.read1_enable = '1' then
62 report "Reading GPR " & to_hstring(d_in.read1_reg) & " " & to_hstring(registers(to_integer(unsigned(d_in.read1_reg))));
64 if d_in.read2_enable = '1' then
65 report "Reading GPR " & to_hstring(d_in.read2_reg) & " " & to_hstring(registers(to_integer(unsigned(d_in.read2_reg))));
67 if d_in.read3_enable = '1' then
68 report "Reading GPR " & to_hstring(d_in.read3_reg) & " " & to_hstring(registers(to_integer(unsigned(d_in.read3_reg))));
70 d_out.read1_data <= registers(to_integer(unsigned(d_in.read1_reg)));
71 -- B read port is multiplexed with reads from the debug circuitry
72 if d_in.read2_enable = '0' and dbg_gpr_req = '1' and dbg_ack = '0' then
73 b_addr := dbg_gpr_addr;
75 b_addr := d_in.read2_reg;
77 rd_port_b <= registers(to_integer(unsigned(b_addr)));
78 d_out.read2_data <= rd_port_b;
79 d_out.read3_data <= registers(to_integer(unsigned(gpr_to_gspr(d_in.read3_reg))));
81 -- Forward any written data
82 if w_in.write_enable = '1' then
83 if d_in.read1_reg = w_in.write_reg then
84 d_out.read1_data <= w_in.write_data;
86 if d_in.read2_reg = w_in.write_reg then
87 d_out.read2_data <= w_in.write_data;
89 if gpr_to_gspr(d_in.read3_reg) = w_in.write_reg then
90 d_out.read3_data <= w_in.write_data;
93 end process register_read_0;
95 -- Latch read data and ack if dbg read requested and B port not busy
96 dbg_register_read: process(clk)
98 if rising_edge(clk) then
99 if dbg_gpr_req = '1' then
100 if d_in.read2_enable = '0' and dbg_ack = '0' then
101 dbg_data <= rd_port_b;
110 dbg_gpr_ack <= dbg_ack;
111 dbg_gpr_data <= dbg_data;
113 -- Dump registers if core terminates
114 sim_dump_test: if SIM generate
115 dump_registers: process(all)
117 if sim_dump = '1' then
118 loop_0: for i in 0 to 31 loop
119 report "GPR" & integer'image(i) & " " & to_hstring(registers(i));
122 report "LR " & to_hstring(registers(to_integer(unsigned(fast_spr_num(SPR_LR)))));
123 report "CTR " & to_hstring(registers(to_integer(unsigned(fast_spr_num(SPR_CTR)))));
124 report "XER " & to_hstring(registers(to_integer(unsigned(fast_spr_num(SPR_XER)))));
125 sim_dump_done <= '1';
127 sim_dump_done <= '0';
132 -- Keep GHDL synthesis happy
133 sim_dump_test_synth: if not SIM generate
134 sim_dump_done <= '0';
137 reg_log: process(clk)
139 if rising_edge(clk) then
140 log_data <= w_in.write_data &
146 end architecture behaviour;