Line 41... |
Line 41... |
library neorv32;
|
library neorv32;
|
use neorv32.neorv32_package.all;
|
use neorv32.neorv32_package.all;
|
|
|
entity neorv32_cpu_bus is
|
entity neorv32_cpu_bus is
|
generic (
|
generic (
|
CPU_EXTENSION_RISCV_C : boolean := false; -- implement compressed extension?
|
|
MEM_EXT_TIMEOUT : natural := 15 -- cycles after which a valid bus access will timeout
|
MEM_EXT_TIMEOUT : natural := 15 -- cycles after which a valid bus access will timeout
|
);
|
);
|
port (
|
port (
|
-- global control --
|
-- global control --
|
clk_i : in std_ulogic; -- global clock, rising edge
|
clk_i : in std_ulogic; -- global clock, rising edge
|
Line 65... |
Line 64... |
ma_store_o : out std_ulogic; -- misaligned store data address
|
ma_store_o : out std_ulogic; -- misaligned store data address
|
be_instr_o : out std_ulogic; -- bus error on instruction access
|
be_instr_o : out std_ulogic; -- bus error on instruction access
|
be_load_o : out std_ulogic; -- bus error on load data access
|
be_load_o : out std_ulogic; -- bus error on load data access
|
be_store_o : out std_ulogic; -- bus error on store data access
|
be_store_o : out std_ulogic; -- bus error on store data access
|
bus_wait_o : out std_ulogic; -- wait for bus operation to finish
|
bus_wait_o : out std_ulogic; -- wait for bus operation to finish
|
|
bus_busy_o : out std_ulogic; -- bus unit is busy
|
exc_ack_i : in std_ulogic; -- exception controller ACK
|
exc_ack_i : in std_ulogic; -- exception controller ACK
|
-- bus system --
|
-- bus system --
|
bus_addr_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
|
bus_addr_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
|
bus_rdata_i : in std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
|
bus_rdata_i : in std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
|
bus_wdata_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
|
bus_wdata_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
|
Line 111... |
Line 111... |
end if;
|
end if;
|
end if;
|
end if;
|
end process mem_adr_reg;
|
end process mem_adr_reg;
|
|
|
-- address output --
|
-- address output --
|
bus_addr_o <= pc_i when (ctrl_i(ctrl_bus_if_c) = '1') else mar; -- is instruction fetch?
|
bus_addr_o <= pc_i when ((bus_if_req or ctrl_i(ctrl_bus_if_c)) = '1') else mar; -- is instruction fetch?
|
mar_o <= mar;
|
mar_o <= mar;
|
|
|
-- write request output --
|
-- write request output --
|
bus_we_o <= ctrl_i(ctrl_bus_wr_c) and (not misaligned_data);
|
bus_we_o <= ctrl_i(ctrl_bus_wr_c) and (not misaligned_data);
|
|
|
-- read request output (also used for instruction fetch) --
|
-- read request output (also used for instruction fetch) --
|
bus_re_o <= (ctrl_i(ctrl_bus_rd_c) and (not misaligned_data)) or (ctrl_i(ctrl_bus_if_c) and (not misaligned_instr));
|
bus_re_o <= (ctrl_i(ctrl_bus_rd_c) and (not misaligned_data)) or ((bus_if_req or ctrl_i(ctrl_bus_if_c)) and (not misaligned_instr));
|
|
|
|
|
-- Write Data -----------------------------------------------------------------------------
|
-- Write Data -----------------------------------------------------------------------------
|
-- -------------------------------------------------------------------------------------------
|
-- -------------------------------------------------------------------------------------------
|
mem_do_reg: process(clk_i)
|
mem_do_reg: process(clk_i)
|
Line 261... |
Line 261... |
ma_instr_o <= bus_if_req and align_err;
|
ma_instr_o <= bus_if_req and align_err;
|
ma_load_o <= bus_rd_req and align_err;
|
ma_load_o <= bus_rd_req and align_err;
|
ma_store_o <= bus_wr_req and align_err;
|
ma_store_o <= bus_wr_req and align_err;
|
|
|
-- wait for bus --
|
-- wait for bus --
|
|
bus_busy_o <= bus_busy;
|
bus_wait_o <= bus_busy and (not bus_ack_i); -- FIXME: 'async' ack
|
bus_wait_o <= bus_busy and (not bus_ack_i); -- FIXME: 'async' ack
|
|
|
|
|
-- Check for Misaligned Access ------------------------------------------------------------
|
-- Check for Misaligned Access ------------------------------------------------------------
|
-- -------------------------------------------------------------------------------------------
|
-- -------------------------------------------------------------------------------------------
|
Line 288... |
Line 289... |
|
|
misaligned_i_check: process(ctrl_i, pc_i)
|
misaligned_i_check: process(ctrl_i, pc_i)
|
begin
|
begin
|
-- check instruction access --
|
-- check instruction access --
|
misaligned_instr <= '0'; -- default
|
misaligned_instr <= '0'; -- default
|
if (CPU_EXTENSION_RISCV_C = true) then -- 16-bit instruction access only
|
if (ctrl_i(ctrl_sys_c_ext_en_c) = '1') then -- 16-bit and 32-bit instruction accesses
|
if (pc_i(0) /= '0') then
|
misaligned_instr <= '0';
|
misaligned_instr <= '1';
|
else -- 32-bit instruction accesses only
|
end if;
|
|
else -- 32-bit instruction access only
|
|
if (pc_i(1 downto 0) /= "00") then
|
if (pc_i(1 downto 0) /= "00") then
|
misaligned_instr <= '1';
|
misaligned_instr <= '1';
|
end if;
|
end if;
|
end if;
|
end if;
|
end process misaligned_i_check;
|
end process misaligned_i_check;
|