Line 42... |
Line 42... |
mem_write : out std_logic);
|
mem_write : out std_logic);
|
end; --entity mem_ctrl
|
end; --entity mem_ctrl
|
|
|
architecture logic of mem_ctrl is
|
architecture logic of mem_ctrl is
|
--"00" = big_endian; "11" = little_endian
|
--"00" = big_endian; "11" = little_endian
|
constant little_endian : std_logic_vector(1 downto 0) := "00";
|
constant ENDIAN_MODE : std_logic_vector(1 downto 0) := "00";
|
signal opcode_reg : std_logic_vector(31 downto 0);
|
signal opcode_reg : std_logic_vector(31 downto 0);
|
signal next_opcode_reg : std_logic_vector(31 downto 0);
|
signal next_opcode_reg : std_logic_vector(31 downto 0);
|
|
|
subtype mem_state_type is std_logic_vector(1 downto 0);
|
subtype mem_state_type is std_logic_vector(1 downto 0);
|
signal mem_state_reg : mem_state_type;
|
signal mem_state_reg : mem_state_type;
|
Line 90... |
Line 90... |
end if;
|
end if;
|
end process;
|
end process;
|
|
|
GEN_REGS2: process(clk, address_data, write_next_sig, byte_sel_next_sig)
|
GEN_REGS2: process(clk, address_data, write_next_sig, byte_sel_next_sig)
|
begin
|
begin
|
if rising_edge(clk) then
|
if reset_in = '1' then
|
|
if ACCURATE_TIMING then
|
|
address_reg <= ZERO;
|
|
write_reg <= '0';
|
|
byte_sel_reg <= "0000";
|
|
end if;
|
|
elsif rising_edge(clk) then
|
if ACCURATE_TIMING then
|
if ACCURATE_TIMING then
|
address_reg <= address_data;
|
address_reg <= address_data;
|
write_reg <= write_next_sig;
|
write_reg <= write_next_sig;
|
byte_sel_reg <= byte_sel_next_sig;
|
byte_sel_reg <= byte_sel_next_sig;
|
end if;
|
end if;
|
Line 130... |
Line 136... |
|
|
data := ZERO;
|
data := ZERO;
|
mem_data_w_v := ZERO;
|
mem_data_w_v := ZERO;
|
|
|
case mem_source is
|
case mem_source is
|
when mem_read32 =>
|
when MEM_READ32 =>
|
data := mem_data_r;
|
data := mem_data_r;
|
when mem_read16 | mem_read16s =>
|
|
if address_reg(1) = little_endian(1) then
|
when MEM_READ16 | MEM_READ16S =>
|
|
if address_reg(1) = ENDIAN_MODE(1) then
|
data(15 downto 0) := mem_data_r(31 downto 16);
|
data(15 downto 0) := mem_data_r(31 downto 16);
|
else
|
else
|
data(15 downto 0) := mem_data_r(15 downto 0);
|
data(15 downto 0) := mem_data_r(15 downto 0);
|
end if;
|
end if;
|
if mem_source = mem_read16 or data(15) = '0' then
|
if mem_source = mem_read16 or data(15) = '0' then
|
data(31 downto 16) := ZERO(31 downto 16);
|
data(31 downto 16) := ZERO(31 downto 16);
|
else
|
else
|
data(31 downto 16) := ONES(31 downto 16);
|
data(31 downto 16) := ONES(31 downto 16);
|
end if;
|
end if;
|
when mem_read8 | mem_read8s =>
|
|
bits := address_reg(1 downto 0) xor little_endian;
|
when MEM_READ8 | MEM_READ8s =>
|
|
bits := address_reg(1 downto 0) xor ENDIAN_MODE;
|
case bits is
|
case bits is
|
when "00" => data(7 downto 0) := mem_data_r(31 downto 24);
|
when "00" => data(7 downto 0) := mem_data_r(31 downto 24);
|
when "01" => data(7 downto 0) := mem_data_r(23 downto 16);
|
when "01" => data(7 downto 0) := mem_data_r(23 downto 16);
|
when "10" => data(7 downto 0) := mem_data_r(15 downto 8);
|
when "10" => data(7 downto 0) := mem_data_r(15 downto 8);
|
when others => data(7 downto 0) := mem_data_r(7 downto 0);
|
when others => data(7 downto 0) := mem_data_r(7 downto 0);
|
end case;
|
end case;
|
if mem_source = mem_read8 or data(7) = '0' then
|
if mem_source = MEM_READ8 or data(7) = '0' then
|
data(31 downto 8) := ZERO(31 downto 8);
|
data(31 downto 8) := ZERO(31 downto 8);
|
else
|
else
|
data(31 downto 8) := ONES(31 downto 8);
|
data(31 downto 8) := ONES(31 downto 8);
|
end if;
|
end if;
|
when mem_write32 =>
|
|
|
when MEM_WRITE32 =>
|
write_next := '1';
|
write_next := '1';
|
mem_data_w_v := data_write;
|
mem_data_w_v := data_write;
|
byte_sel_next := "1111";
|
byte_sel_next := "1111";
|
when mem_write16 =>
|
|
|
when MEM_WRITE16 =>
|
write_next := '1';
|
write_next := '1';
|
mem_data_w_v := data_write(15 downto 0) & data_write(15 downto 0);
|
mem_data_w_v := data_write(15 downto 0) & data_write(15 downto 0);
|
if address_data(1) = little_endian(1) then
|
if address_data(1) = ENDIAN_MODE(1) then
|
byte_sel_next := "1100";
|
byte_sel_next := "1100";
|
else
|
else
|
byte_sel_next := "0011";
|
byte_sel_next := "0011";
|
end if;
|
end if;
|
when mem_write8 =>
|
|
|
when MEM_WRITE8 =>
|
write_next := '1';
|
write_next := '1';
|
mem_data_w_v := data_write(7 downto 0) & data_write(7 downto 0) &
|
mem_data_w_v := data_write(7 downto 0) & data_write(7 downto 0) &
|
data_write(7 downto 0) & data_write(7 downto 0);
|
data_write(7 downto 0) & data_write(7 downto 0);
|
bits := address_data(1 downto 0) xor little_endian;
|
bits := address_data(1 downto 0) xor ENDIAN_MODE;
|
case bits is
|
case bits is
|
when "00" =>
|
when "00" =>
|
byte_sel_next := "1000";
|
byte_sel_next := "1000";
|
when "01" =>
|
when "01" =>
|
byte_sel_next := "0100";
|
byte_sel_next := "0100";
|
when "10" =>
|
when "10" =>
|
byte_sel_next := "0010";
|
byte_sel_next := "0010";
|
when others =>
|
when others =>
|
byte_sel_next := "0001";
|
byte_sel_next := "0001";
|
end case;
|
end case;
|
|
|
when others =>
|
when others =>
|
end case;
|
end case;
|
|
|
byte_sel_next_sig <= byte_sel_next;
|
byte_sel_next_sig <= byte_sel_next;
|
write_next_sig <= write_next;
|
write_next_sig <= write_next;
|
|
|
opcode_next := opcode_reg;
|
opcode_next := opcode_reg;
|
case mem_state_reg is --State Machine
|
case mem_state_reg is --State Machine
|
Line 205... |
Line 218... |
pause := '1';
|
pause := '1';
|
if pause_in = '0' then
|
if pause_in = '0' then
|
mem_state_next := STATE_ADDR;
|
mem_state_next := STATE_ADDR;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
when STATE_ADDR => --address lines pre-hold
|
when STATE_ADDR => --address lines pre-hold
|
address := address_reg;
|
address := address_reg;
|
write_line := write_reg;
|
write_line := write_reg;
|
if write_reg = '1' and address_reg(31) = '1' then
|
if write_reg = '1' and address_reg(31) = '1' then
|
pause := '1';
|
pause := '1';
|
Line 221... |
Line 235... |
if pause_in = '0' then
|
if pause_in = '0' then
|
opcode_next := next_opcode_reg;
|
opcode_next := next_opcode_reg;
|
mem_state_next := STATE_FETCH; --2 cycle access
|
mem_state_next := STATE_FETCH; --2 cycle access
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
when STATE_WRITE =>
|
when STATE_WRITE =>
|
pause := '1';
|
pause := '1';
|
address := address_reg;
|
address := address_reg;
|
write_line := write_reg;
|
write_line := write_reg;
|
byte_sel := byte_sel_reg;
|
byte_sel := byte_sel_reg;
|
if pause_in = '0' then
|
if pause_in = '0' then
|
mem_state_next := STATE_PAUSE;
|
mem_state_next := STATE_PAUSE;
|
end if;
|
end if;
|
|
|
when OTHERS => --STATE_PAUSE address lines post-hold
|
when OTHERS => --STATE_PAUSE address lines post-hold
|
address := address_reg;
|
address := address_reg;
|
write_line := write_reg;
|
write_line := write_reg;
|
byte_sel := "0000";
|
byte_sel := "0000";
|
if pause_in = '0' then
|
if pause_in = '0' then
|