content
stringlengths
1
1.04M
----------------------------------------------------------- --------- AUTOGENERATED FILE, DO NOT EDIT ----------------- ----------------------------------------------------------- library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; package desilog is subtype u8 is unsigned( 7 downto 0); subtype u16 is unsigned(15 downto 0); subtype u32 is unsigned(31 downto 0); subtype u64 is unsigned(63 downto 0); subtype u2 is unsigned( 1 downto 0); subtype u4 is unsigned( 3 downto 0); type string_ptr is access string; --function str(a : unsigned) return string; --function str(a : integer) return string; function dg_boolToBit(bval : boolean) return std_ulogic; end package; package body desilog is function dg_boolToBit(bval : boolean) return std_ulogic is begin if bval then return '1'; else return '0'; end if; end function; end;
----------------------------------------------------------- --------- AUTOGENERATED FILE, DO NOT EDIT ----------------- ----------------------------------------------------------- library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; package desilog is subtype u8 is unsigned( 7 downto 0); subtype u16 is unsigned(15 downto 0); subtype u32 is unsigned(31 downto 0); subtype u64 is unsigned(63 downto 0); subtype u2 is unsigned( 1 downto 0); subtype u4 is unsigned( 3 downto 0); type string_ptr is access string; --function str(a : unsigned) return string; --function str(a : integer) return string; function dg_boolToBit(bval : boolean) return std_ulogic; end package; package body desilog is function dg_boolToBit(bval : boolean) return std_ulogic is begin if bval then return '1'; else return '0'; end if; end function; end;
library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use work.tce_util.all; entity ffaccel_input_mux_2 is generic ( BUSW_0 : integer := 32; BUSW_1 : integer := 32; DATAW : integer := 32); port ( databus0 : in std_logic_vector(BUSW_0-1 downto 0); databus1 : in std_logic_vector(BUSW_1-1 downto 0); data : out std_logic_vector(DATAW-1 downto 0); databus_cntrl : in std_logic_vector(0 downto 0)); end ffaccel_input_mux_2; architecture rtl of ffaccel_input_mux_2 is begin -- If width of input bus is greater than width of output, -- using the LSB bits. -- If width of input bus is smaller than width of output, -- using zero extension to generate extra bits. sel : process (databus_cntrl, databus0, databus1) begin data <= (others => '0'); case databus_cntrl is when "0" => data <= tce_ext(databus0, data'length); when others => data <= tce_ext(databus1, data'length); end case; end process sel; end rtl;
library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use work.tce_util.all; entity ffaccel_input_mux_2 is generic ( BUSW_0 : integer := 32; BUSW_1 : integer := 32; DATAW : integer := 32); port ( databus0 : in std_logic_vector(BUSW_0-1 downto 0); databus1 : in std_logic_vector(BUSW_1-1 downto 0); data : out std_logic_vector(DATAW-1 downto 0); databus_cntrl : in std_logic_vector(0 downto 0)); end ffaccel_input_mux_2; architecture rtl of ffaccel_input_mux_2 is begin -- If width of input bus is greater than width of output, -- using the LSB bits. -- If width of input bus is smaller than width of output, -- using zero extension to generate extra bits. sel : process (databus_cntrl, databus0, databus1) begin data <= (others => '0'); case databus_cntrl is when "0" => data <= tce_ext(databus0, data'length); when others => data <= tce_ext(databus1, data'length); end case; end process sel; end rtl;
-- Copyright (C) 2002 Morgan Kaufmann Publishers, Inc -- This file is part of VESTs (Vhdl tESTs). -- VESTs is free software; you can redistribute it and/or modify it -- under the terms of the GNU General Public License as published by the -- Free Software Foundation; either version 2 of the License, or (at -- your option) any later version. -- VESTs is distributed in the hope that it will be useful, but WITHOUT -- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- for more details. -- You should have received a copy of the GNU General Public License -- along with VESTs; if not, write to the Free Software Foundation, -- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- created by: Veribest WaveBench Version 16.00.00.02 library work; use work.all; library ieee_proposed; use ieee_proposed.electrical_systems.all; library ieee; use ieee.std_logic_1164.all; entity tb_volume_sensor is end tb_volume_sensor; architecture test_bench of tb_volume_sensor is -- Component declarations -- Signal declarations signal clk, full, rst : std_logic; terminal flow, minus_ref : electrical; begin -- Signal assignments -- Component instances vol1 : entity work.volume_sensor(structural) port map( clk => clk, full => full, rst => rst, flow => flow, minus_ref => minus_ref ); vio : entity work.v_sine(ideal) generic map( freq => 1.0, amplitude => 16.0 ) port map( pos => flow, neg => ELECTRICAL_REF ); vm_ref : entity work.v_constant(ideal) generic map( level => -10.0 ) port map( pos => minus_ref, neg => ELECTRICAL_REF ); -- Test code generation processes -- clk P_clk : process begin clk <= '1'; wait for 500000.000 ns; clk <= '0'; wait for 500000.000 ns; end process P_clk; -- rst P_rst : process begin wait for 0.0 ms; rst <= '0'; wait for 2.0 ms; rst <= '1'; wait for 2.0 ms; rst <= '0'; wait; end process; end test_bench;
-- Copyright (C) 2002 Morgan Kaufmann Publishers, Inc -- This file is part of VESTs (Vhdl tESTs). -- VESTs is free software; you can redistribute it and/or modify it -- under the terms of the GNU General Public License as published by the -- Free Software Foundation; either version 2 of the License, or (at -- your option) any later version. -- VESTs is distributed in the hope that it will be useful, but WITHOUT -- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- for more details. -- You should have received a copy of the GNU General Public License -- along with VESTs; if not, write to the Free Software Foundation, -- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- created by: Veribest WaveBench Version 16.00.00.02 library work; use work.all; library ieee_proposed; use ieee_proposed.electrical_systems.all; library ieee; use ieee.std_logic_1164.all; entity tb_volume_sensor is end tb_volume_sensor; architecture test_bench of tb_volume_sensor is -- Component declarations -- Signal declarations signal clk, full, rst : std_logic; terminal flow, minus_ref : electrical; begin -- Signal assignments -- Component instances vol1 : entity work.volume_sensor(structural) port map( clk => clk, full => full, rst => rst, flow => flow, minus_ref => minus_ref ); vio : entity work.v_sine(ideal) generic map( freq => 1.0, amplitude => 16.0 ) port map( pos => flow, neg => ELECTRICAL_REF ); vm_ref : entity work.v_constant(ideal) generic map( level => -10.0 ) port map( pos => minus_ref, neg => ELECTRICAL_REF ); -- Test code generation processes -- clk P_clk : process begin clk <= '1'; wait for 500000.000 ns; clk <= '0'; wait for 500000.000 ns; end process P_clk; -- rst P_rst : process begin wait for 0.0 ms; rst <= '0'; wait for 2.0 ms; rst <= '1'; wait for 2.0 ms; rst <= '0'; wait; end process; end test_bench;
-- Copyright (C) 2002 Morgan Kaufmann Publishers, Inc -- This file is part of VESTs (Vhdl tESTs). -- VESTs is free software; you can redistribute it and/or modify it -- under the terms of the GNU General Public License as published by the -- Free Software Foundation; either version 2 of the License, or (at -- your option) any later version. -- VESTs is distributed in the hope that it will be useful, but WITHOUT -- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- for more details. -- You should have received a copy of the GNU General Public License -- along with VESTs; if not, write to the Free Software Foundation, -- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- created by: Veribest WaveBench Version 16.00.00.02 library work; use work.all; library ieee_proposed; use ieee_proposed.electrical_systems.all; library ieee; use ieee.std_logic_1164.all; entity tb_volume_sensor is end tb_volume_sensor; architecture test_bench of tb_volume_sensor is -- Component declarations -- Signal declarations signal clk, full, rst : std_logic; terminal flow, minus_ref : electrical; begin -- Signal assignments -- Component instances vol1 : entity work.volume_sensor(structural) port map( clk => clk, full => full, rst => rst, flow => flow, minus_ref => minus_ref ); vio : entity work.v_sine(ideal) generic map( freq => 1.0, amplitude => 16.0 ) port map( pos => flow, neg => ELECTRICAL_REF ); vm_ref : entity work.v_constant(ideal) generic map( level => -10.0 ) port map( pos => minus_ref, neg => ELECTRICAL_REF ); -- Test code generation processes -- clk P_clk : process begin clk <= '1'; wait for 500000.000 ns; clk <= '0'; wait for 500000.000 ns; end process P_clk; -- rst P_rst : process begin wait for 0.0 ms; rst <= '0'; wait for 2.0 ms; rst <= '1'; wait for 2.0 ms; rst <= '0'; wait; end process; end test_bench;
---------------------------------------------------------------------------------- -- Project Name: Frecuency Counter -- Target Devices: Spartan 3 -- Engineers: Ángel Larrañaga Muro -- Nicolás Jurado Jiménez -- Gonzalo Matarrubia Gonzalez -- License: All files included in this proyect are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License ---------------------------------------------------------------------------------- LIBRARY ieee; USE ieee.std_logic_1164.ALL; USE ieee.numeric_std.ALL; ENTITY decoder_decoder_tb_vhd_tb IS END decoder_decoder_tb_vhd_tb; ARCHITECTURE behavior OF decoder_decoder_tb_vhd_tb IS COMPONENT decoder PORT( code : IN std_logic_vector(3 DOWNTO 0); led : OUT std_logic_vector(6 DOWNTO 0) ); END COMPONENT; SIGNAL code : std_logic_vector(3 DOWNTO 0); SIGNAL led : std_logic_vector(6 DOWNTO 0); TYPE vtest is record code : std_logic_vector(3 DOWNTO 0); led : std_logic_vector(6 DOWNTO 0); END RECORD; TYPE vtest_vector IS ARRAY (natural RANGE <>) OF vtest; CONSTANT test: vtest_vector := ( (code => "0000", led => "0000001"), (code => "0001", led => "1001111"), (code => "0010", led => "0010010"), (code => "0011", led => "0000110"), (code => "0100", led => "1001100"), (code => "0101", led => "0100100"), (code => "0110", led => "0100000"), (code => "0111", led => "0001111"), (code => "1000", led => "0000000"), (code => "1001", led => "0000100"), (code => "1010", led => "1111110"), (code => "1011", led => "1111110"), (code => "1100", led => "1111110"), (code => "1101", led => "1111110"), (code => "1110", led => "1111110"), (code => "1111", led => "1111110") ); BEGIN uut: decoder PORT MAP( code => code, led => led ); tb: PROCESS BEGIN FOR i IN 0 TO test'HIGH LOOP code <= test(i).code; WAIT FOR 20 ns; ASSERT led = test(i).led REPORT "Salida incorrecta." SEVERITY FAILURE; END LOOP; ASSERT false REPORT "Simulacin finalizada. Test superado." SEVERITY FAILURE; END PROCESS; END;
---------------------------------------------------------------------------------- -- Project Name: Frecuency Counter -- Target Devices: Spartan 3 -- Engineers: Ángel Larrañaga Muro -- Nicolás Jurado Jiménez -- Gonzalo Matarrubia Gonzalez -- License: All files included in this proyect are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License ---------------------------------------------------------------------------------- LIBRARY ieee; USE ieee.std_logic_1164.ALL; USE ieee.numeric_std.ALL; ENTITY decoder_decoder_tb_vhd_tb IS END decoder_decoder_tb_vhd_tb; ARCHITECTURE behavior OF decoder_decoder_tb_vhd_tb IS COMPONENT decoder PORT( code : IN std_logic_vector(3 DOWNTO 0); led : OUT std_logic_vector(6 DOWNTO 0) ); END COMPONENT; SIGNAL code : std_logic_vector(3 DOWNTO 0); SIGNAL led : std_logic_vector(6 DOWNTO 0); TYPE vtest is record code : std_logic_vector(3 DOWNTO 0); led : std_logic_vector(6 DOWNTO 0); END RECORD; TYPE vtest_vector IS ARRAY (natural RANGE <>) OF vtest; CONSTANT test: vtest_vector := ( (code => "0000", led => "0000001"), (code => "0001", led => "1001111"), (code => "0010", led => "0010010"), (code => "0011", led => "0000110"), (code => "0100", led => "1001100"), (code => "0101", led => "0100100"), (code => "0110", led => "0100000"), (code => "0111", led => "0001111"), (code => "1000", led => "0000000"), (code => "1001", led => "0000100"), (code => "1010", led => "1111110"), (code => "1011", led => "1111110"), (code => "1100", led => "1111110"), (code => "1101", led => "1111110"), (code => "1110", led => "1111110"), (code => "1111", led => "1111110") ); BEGIN uut: decoder PORT MAP( code => code, led => led ); tb: PROCESS BEGIN FOR i IN 0 TO test'HIGH LOOP code <= test(i).code; WAIT FOR 20 ns; ASSERT led = test(i).led REPORT "Salida incorrecta." SEVERITY FAILURE; END LOOP; ASSERT false REPORT "Simulacin finalizada. Test superado." SEVERITY FAILURE; END PROCESS; END;
-- Copyright (C) 1996 Morgan Kaufmann Publishers, Inc -- This file is part of VESTs (Vhdl tESTs). -- VESTs is free software; you can redistribute it and/or modify it -- under the terms of the GNU General Public License as published by the -- Free Software Foundation; either version 2 of the License, or (at -- your option) any later version. -- VESTs is distributed in the hope that it will be useful, but WITHOUT -- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- for more details. -- You should have received a copy of the GNU General Public License -- along with VESTs; if not, write to the Free Software Foundation, -- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- --------------------------------------------------------------------- -- -- $Id: ch_11_fg_11_10.vhd,v 1.2 2001-10-26 16:29:35 paw Exp $ -- $Revision: 1.2 $ -- -- --------------------------------------------------------------------- architecture behavioral of bus_module is begin behavior : process is -- . . . -- not in book constant Tdelay_synch : delay_length := 10 ns; constant wait_delay : delay_length := 100 ns; -- end not in book begin synch <= '0' after Tdelay_synch; -- . . . -- not in book wait for wait_delay; -- end not in book -- ready to start operation synch <= 'Z' after Tdelay_synch; wait until synch = 'H'; -- . . . -- proceed with operation -- . . . end process behavior; end architecture behavioral;
-- Copyright (C) 1996 Morgan Kaufmann Publishers, Inc -- This file is part of VESTs (Vhdl tESTs). -- VESTs is free software; you can redistribute it and/or modify it -- under the terms of the GNU General Public License as published by the -- Free Software Foundation; either version 2 of the License, or (at -- your option) any later version. -- VESTs is distributed in the hope that it will be useful, but WITHOUT -- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- for more details. -- You should have received a copy of the GNU General Public License -- along with VESTs; if not, write to the Free Software Foundation, -- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- --------------------------------------------------------------------- -- -- $Id: ch_11_fg_11_10.vhd,v 1.2 2001-10-26 16:29:35 paw Exp $ -- $Revision: 1.2 $ -- -- --------------------------------------------------------------------- architecture behavioral of bus_module is begin behavior : process is -- . . . -- not in book constant Tdelay_synch : delay_length := 10 ns; constant wait_delay : delay_length := 100 ns; -- end not in book begin synch <= '0' after Tdelay_synch; -- . . . -- not in book wait for wait_delay; -- end not in book -- ready to start operation synch <= 'Z' after Tdelay_synch; wait until synch = 'H'; -- . . . -- proceed with operation -- . . . end process behavior; end architecture behavioral;
-- Copyright (C) 1996 Morgan Kaufmann Publishers, Inc -- This file is part of VESTs (Vhdl tESTs). -- VESTs is free software; you can redistribute it and/or modify it -- under the terms of the GNU General Public License as published by the -- Free Software Foundation; either version 2 of the License, or (at -- your option) any later version. -- VESTs is distributed in the hope that it will be useful, but WITHOUT -- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- for more details. -- You should have received a copy of the GNU General Public License -- along with VESTs; if not, write to the Free Software Foundation, -- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- --------------------------------------------------------------------- -- -- $Id: ch_11_fg_11_10.vhd,v 1.2 2001-10-26 16:29:35 paw Exp $ -- $Revision: 1.2 $ -- -- --------------------------------------------------------------------- architecture behavioral of bus_module is begin behavior : process is -- . . . -- not in book constant Tdelay_synch : delay_length := 10 ns; constant wait_delay : delay_length := 100 ns; -- end not in book begin synch <= '0' after Tdelay_synch; -- . . . -- not in book wait for wait_delay; -- end not in book -- ready to start operation synch <= 'Z' after Tdelay_synch; wait until synch = 'H'; -- . . . -- proceed with operation -- . . . end process behavior; end architecture behavioral;
library ieee; use ieee.std_logic_1164.all; entity deserializer is port ( clock : in std_logic; sync : in std_logic; rxd : in std_logic; txd : out std_logic; io : inout std_logic_vector(11 downto 0) ); end deserializer; architecture gideon of deserializer is signal index : integer range 0 to 31; signal io_t : std_logic_vector(io'range) := (others => '0'); signal io_o : std_logic_vector(io'range) := (others => '0'); begin process(clock) begin if rising_edge(clock) then if sync='1' then index <= 0; elsif index /= 31 then index <= index + 1; end if; if index <= io'high then txd <= io(index); else txd <= '0'; end if; if index <= io'high then io_o(index) <= rxd; elsif index < (2*io'length) then io_t(index - io'length) <= rxd; end if; end if; end process; r_out: for i in io'range generate io(i) <= io_o(i) when io_t(i)='1' else 'Z'; end generate; end gideon;
library ieee; use ieee.std_logic_1164.all; entity deserializer is port ( clock : in std_logic; sync : in std_logic; rxd : in std_logic; txd : out std_logic; io : inout std_logic_vector(11 downto 0) ); end deserializer; architecture gideon of deserializer is signal index : integer range 0 to 31; signal io_t : std_logic_vector(io'range) := (others => '0'); signal io_o : std_logic_vector(io'range) := (others => '0'); begin process(clock) begin if rising_edge(clock) then if sync='1' then index <= 0; elsif index /= 31 then index <= index + 1; end if; if index <= io'high then txd <= io(index); else txd <= '0'; end if; if index <= io'high then io_o(index) <= rxd; elsif index < (2*io'length) then io_t(index - io'length) <= rxd; end if; end if; end process; r_out: for i in io'range generate io(i) <= io_o(i) when io_t(i)='1' else 'Z'; end generate; end gideon;
library ieee; use ieee.std_logic_1164.all; entity deserializer is port ( clock : in std_logic; sync : in std_logic; rxd : in std_logic; txd : out std_logic; io : inout std_logic_vector(11 downto 0) ); end deserializer; architecture gideon of deserializer is signal index : integer range 0 to 31; signal io_t : std_logic_vector(io'range) := (others => '0'); signal io_o : std_logic_vector(io'range) := (others => '0'); begin process(clock) begin if rising_edge(clock) then if sync='1' then index <= 0; elsif index /= 31 then index <= index + 1; end if; if index <= io'high then txd <= io(index); else txd <= '0'; end if; if index <= io'high then io_o(index) <= rxd; elsif index < (2*io'length) then io_t(index - io'length) <= rxd; end if; end if; end process; r_out: for i in io'range generate io(i) <= io_o(i) when io_t(i)='1' else 'Z'; end generate; end gideon;
library ieee; use ieee.std_logic_1164.all; entity deserializer is port ( clock : in std_logic; sync : in std_logic; rxd : in std_logic; txd : out std_logic; io : inout std_logic_vector(11 downto 0) ); end deserializer; architecture gideon of deserializer is signal index : integer range 0 to 31; signal io_t : std_logic_vector(io'range) := (others => '0'); signal io_o : std_logic_vector(io'range) := (others => '0'); begin process(clock) begin if rising_edge(clock) then if sync='1' then index <= 0; elsif index /= 31 then index <= index + 1; end if; if index <= io'high then txd <= io(index); else txd <= '0'; end if; if index <= io'high then io_o(index) <= rxd; elsif index < (2*io'length) then io_t(index - io'length) <= rxd; end if; end if; end process; r_out: for i in io'range generate io(i) <= io_o(i) when io_t(i)='1' else 'Z'; end generate; end gideon;
library ieee; use ieee.std_logic_1164.all; entity deserializer is port ( clock : in std_logic; sync : in std_logic; rxd : in std_logic; txd : out std_logic; io : inout std_logic_vector(11 downto 0) ); end deserializer; architecture gideon of deserializer is signal index : integer range 0 to 31; signal io_t : std_logic_vector(io'range) := (others => '0'); signal io_o : std_logic_vector(io'range) := (others => '0'); begin process(clock) begin if rising_edge(clock) then if sync='1' then index <= 0; elsif index /= 31 then index <= index + 1; end if; if index <= io'high then txd <= io(index); else txd <= '0'; end if; if index <= io'high then io_o(index) <= rxd; elsif index < (2*io'length) then io_t(index - io'length) <= rxd; end if; end if; end process; r_out: for i in io'range generate io(i) <= io_o(i) when io_t(i)='1' else 'Z'; end generate; end gideon;
architecture RTL of FIFO is function func1 ( a : integer; constant b : integer; signal c : std_logic; variable v : std_logic; file f : std_logic ) return integer; -- Violations function func1 ( a : integer; constant b : integer; signal c : std_logic; variable v : std_logic; file f : std_logic ) return integer; begin end architecture RTL;
-------------------------------------------------------------------------------- -- -- FIFO Generator v8.4 Core - core wrapper -- -------------------------------------------------------------------------------- -- -- (c) Copyright 2009 - 2010 Xilinx, Inc. All rights reserved. -- -- This file contains confidential and proprietary information -- of Xilinx, Inc. and is protected under U.S. and -- international copyright and other intellectual property -- laws. -- -- DISCLAIMER -- This disclaimer is not a license and does not grant any -- rights to the materials distributed herewith. Except as -- otherwise provided in a valid license issued to you by -- Xilinx, and to the maximum extent permitted by applicable -- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND -- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES -- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING -- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- -- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and -- (2) Xilinx shall not be liable (whether in contract or tort, -- including negligence, or under any other theory of -- liability) for any loss or damage of any kind or nature -- related to, arising under or in connection with these -- materials, including for any direct, or any indirect, -- special, incidental, or consequential loss or damage -- (including loss of data, profits, goodwill, or any type of -- loss or damage suffered as a result of any action brought -- by a third party) even if such damage or loss was -- reasonably foreseeable or Xilinx had been advised of the -- possibility of the same. -- -- CRITICAL APPLICATIONS -- Xilinx products are not designed or intended to be fail- -- safe, or for use in any application requiring fail-safe -- performance, such as life-support or safety devices or -- systems, Class III medical devices, nuclear facilities, -- applications related to the deployment of airbags, or any -- other applications that could lead to death, personal -- injury, or severe property or environmental damage -- (individually and collectively, "Critical -- Applications"). Customer assumes the sole risk and -- liability of any use of Xilinx products in Critical -- Applications, subject only to applicable laws and -- regulations governing limitations on product liability. -- -- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS -- PART OF THIS FILE AT ALL TIMES. -------------------------------------------------------------------------------- -- -- Filename: ssd_command_fifo_top.vhd -- -- Description: -- This is the FIFO core wrapper with BUFG instances for clock connections. -- -------------------------------------------------------------------------------- -- Library Declarations -------------------------------------------------------------------------------- library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; library unisim; use unisim.vcomponents.all; -------------------------------------------------------------------------------- -- Entity Declaration -------------------------------------------------------------------------------- entity ssd_command_fifo_top is PORT ( CLK : IN std_logic; DATA_COUNT : OUT std_logic_vector(7-1 DOWNTO 0); RST : IN std_logic; WR_EN : IN std_logic; RD_EN : IN std_logic; DIN : IN std_logic_vector(128-1 DOWNTO 0); DOUT : OUT std_logic_vector(128-1 DOWNTO 0); FULL : OUT std_logic; EMPTY : OUT std_logic); end ssd_command_fifo_top; architecture xilinx of ssd_command_fifo_top is SIGNAL clk_i : std_logic; component ssd_command_fifo is PORT ( CLK : IN std_logic; DATA_COUNT : OUT std_logic_vector(7-1 DOWNTO 0); RST : IN std_logic; WR_EN : IN std_logic; RD_EN : IN std_logic; DIN : IN std_logic_vector(128-1 DOWNTO 0); DOUT : OUT std_logic_vector(128-1 DOWNTO 0); FULL : OUT std_logic; EMPTY : OUT std_logic); end component; begin clk_buf: bufg PORT map( i => CLK, o => clk_i ); fg0 : ssd_command_fifo PORT MAP ( CLK => clk_i, DATA_COUNT => data_count, RST => rst, WR_EN => wr_en, RD_EN => rd_en, DIN => din, DOUT => dout, FULL => full, EMPTY => empty); end xilinx;
-------------------------------------------------------------------------------- -- -- FIFO Generator v8.4 Core - core wrapper -- -------------------------------------------------------------------------------- -- -- (c) Copyright 2009 - 2010 Xilinx, Inc. All rights reserved. -- -- This file contains confidential and proprietary information -- of Xilinx, Inc. and is protected under U.S. and -- international copyright and other intellectual property -- laws. -- -- DISCLAIMER -- This disclaimer is not a license and does not grant any -- rights to the materials distributed herewith. Except as -- otherwise provided in a valid license issued to you by -- Xilinx, and to the maximum extent permitted by applicable -- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND -- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES -- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING -- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- -- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and -- (2) Xilinx shall not be liable (whether in contract or tort, -- including negligence, or under any other theory of -- liability) for any loss or damage of any kind or nature -- related to, arising under or in connection with these -- materials, including for any direct, or any indirect, -- special, incidental, or consequential loss or damage -- (including loss of data, profits, goodwill, or any type of -- loss or damage suffered as a result of any action brought -- by a third party) even if such damage or loss was -- reasonably foreseeable or Xilinx had been advised of the -- possibility of the same. -- -- CRITICAL APPLICATIONS -- Xilinx products are not designed or intended to be fail- -- safe, or for use in any application requiring fail-safe -- performance, such as life-support or safety devices or -- systems, Class III medical devices, nuclear facilities, -- applications related to the deployment of airbags, or any -- other applications that could lead to death, personal -- injury, or severe property or environmental damage -- (individually and collectively, "Critical -- Applications"). Customer assumes the sole risk and -- liability of any use of Xilinx products in Critical -- Applications, subject only to applicable laws and -- regulations governing limitations on product liability. -- -- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS -- PART OF THIS FILE AT ALL TIMES. -------------------------------------------------------------------------------- -- -- Filename: ssd_command_fifo_top.vhd -- -- Description: -- This is the FIFO core wrapper with BUFG instances for clock connections. -- -------------------------------------------------------------------------------- -- Library Declarations -------------------------------------------------------------------------------- library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; library unisim; use unisim.vcomponents.all; -------------------------------------------------------------------------------- -- Entity Declaration -------------------------------------------------------------------------------- entity ssd_command_fifo_top is PORT ( CLK : IN std_logic; DATA_COUNT : OUT std_logic_vector(7-1 DOWNTO 0); RST : IN std_logic; WR_EN : IN std_logic; RD_EN : IN std_logic; DIN : IN std_logic_vector(128-1 DOWNTO 0); DOUT : OUT std_logic_vector(128-1 DOWNTO 0); FULL : OUT std_logic; EMPTY : OUT std_logic); end ssd_command_fifo_top; architecture xilinx of ssd_command_fifo_top is SIGNAL clk_i : std_logic; component ssd_command_fifo is PORT ( CLK : IN std_logic; DATA_COUNT : OUT std_logic_vector(7-1 DOWNTO 0); RST : IN std_logic; WR_EN : IN std_logic; RD_EN : IN std_logic; DIN : IN std_logic_vector(128-1 DOWNTO 0); DOUT : OUT std_logic_vector(128-1 DOWNTO 0); FULL : OUT std_logic; EMPTY : OUT std_logic); end component; begin clk_buf: bufg PORT map( i => CLK, o => clk_i ); fg0 : ssd_command_fifo PORT MAP ( CLK => clk_i, DATA_COUNT => data_count, RST => rst, WR_EN => wr_en, RD_EN => rd_en, DIN => din, DOUT => dout, FULL => full, EMPTY => empty); end xilinx;
----------------------------------------------------------------------------- -- LEON3 Xilinx VC707 Demonstration design ------------------------------------------------------------------------------ -- This file is a part of the GRLIB VHDL IP LIBRARY -- Copyright (C) 2003 - 2008, Gaisler Research -- Copyright (C) 2008 - 2014, Aeroflex Gaisler -- Copyright (C) 2015 - 2016, Cobham Gaisler -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ------------------------------------------------------------------------------ library ieee; use ieee.std_logic_1164.all; library grlib, techmap; use grlib.amba.all; use grlib.devices.all; use grlib.stdlib.all; use techmap.gencomp.all; use techmap.allclkgen.all; library gaisler; use gaisler.memctrl.all; use gaisler.leon3.all; use gaisler.uart.all; use gaisler.misc.all; use gaisler.i2c.all; use gaisler.spi.all; use gaisler.net.all; use gaisler.jtag.all; use gaisler.grusb.all; use gaisler.can.all; use gaisler.l2cache.all; use gaisler.subsys.all; -- pragma translate_off use gaisler.sim.all; library unisim; use unisim.all; -- pragma translate_on library testgrouppolito; use testgrouppolito.dprc_pkg.all; library esa; use esa.memoryctrl.all; use work.config.all; entity leon3mp is generic ( fabtech : integer := CFG_FABTECH; memtech : integer := CFG_MEMTECH; padtech : integer := CFG_PADTECH; clktech : integer := CFG_CLKTECH; disas : integer := CFG_DISAS; -- Enable disassembly to console dbguart : integer := CFG_DUART; -- Print UART on console pclow : integer := CFG_PCLOW; SIM_BYPASS_INIT_CAL : string := "OFF"; SIMULATION : string := "FALSE"; USE_MIG_INTERFACE_MODEL : boolean := false; autonegotiation : integer := 1 ); port ( reset : in std_ulogic; clk200p : in std_ulogic; -- 200 MHz clock clk200n : in std_ulogic; -- 200 MHz clock address : out std_logic_vector(25 downto 0); data : inout std_logic_vector(15 downto 0); oen : out std_ulogic; writen : out std_ulogic; romsn : out std_logic; adv : out std_logic; ddr3_dq : inout std_logic_vector(63 downto 0); ddr3_dqs_p : inout std_logic_vector(7 downto 0); ddr3_dqs_n : inout std_logic_vector(7 downto 0); ddr3_addr : out std_logic_vector(13 downto 0); ddr3_ba : out std_logic_vector(2 downto 0); ddr3_ras_n : out std_logic; ddr3_cas_n : out std_logic; ddr3_we_n : out std_logic; ddr3_reset_n : out std_logic; ddr3_ck_p : out std_logic_vector(0 downto 0); ddr3_ck_n : out std_logic_vector(0 downto 0); ddr3_cke : out std_logic_vector(0 downto 0); ddr3_cs_n : out std_logic_vector(0 downto 0); ddr3_dm : out std_logic_vector(7 downto 0); ddr3_odt : out std_logic_vector(0 downto 0); dsurx : in std_ulogic; dsutx : out std_ulogic; dsuctsn : in std_ulogic; dsurtsn : out std_ulogic; button : in std_logic_vector(3 downto 0); switch : inout std_logic_vector(4 downto 0); led : out std_logic_vector(6 downto 0); iic_scl : inout std_ulogic; iic_sda : inout std_ulogic; usb_refclk_opt : in std_logic; usb_clkout : in std_logic; usb_d : inout std_logic_vector(7 downto 0); usb_nxt : in std_logic; usb_stp : out std_logic; usb_dir : in std_logic; usb_resetn : out std_ulogic; gtrefclk_p : in std_logic; gtrefclk_n : in std_logic; txp : out std_logic; txn : out std_logic; rxp : in std_logic; rxn : in std_logic; emdio : inout std_logic; emdc : out std_ulogic; eint : in std_ulogic; erst : out std_ulogic; can_txd : out std_logic_vector(0 to CFG_CAN_NUM-1); can_rxd : in std_logic_vector(0 to CFG_CAN_NUM-1); spi_data_out : in std_logic; spi_data_in : out std_ulogic; spi_data_cs_b : out std_ulogic; spi_clk : out std_ulogic ); end; architecture rtl of leon3mp is component sgmii_vc707 generic( pindex : integer := 0; paddr : integer := 0; pmask : integer := 16#fff#; abits : integer := 8; autonegotiation : integer := 1; pirq : integer := 0; debugmem : integer := 0; tech : integer := 0 ); port( sgmiii : in eth_sgmii_in_type; sgmiio : out eth_sgmii_out_type; gmiii : out eth_in_type; gmiio : in eth_out_type; reset : in std_logic; -- Asynchronous reset for entire core. apb_clk : in std_logic; apb_rstn : in std_logic; apbi : in apb_slv_in_type; apbo : out apb_slv_out_type ); end component; component ahb2mig_7series generic( hindex : integer := 0; haddr : integer := 0; hmask : integer := 16#f00#; pindex : integer := 0; paddr : integer := 0; pmask : integer := 16#fff#; SIM_BYPASS_INIT_CAL : string := "OFF"; SIMULATION : string := "FALSE"; USE_MIG_INTERFACE_MODEL : boolean := false ); port( ddr3_dq : inout std_logic_vector(63 downto 0); ddr3_dqs_p : inout std_logic_vector(7 downto 0); ddr3_dqs_n : inout std_logic_vector(7 downto 0); ddr3_addr : out std_logic_vector(13 downto 0); ddr3_ba : out std_logic_vector(2 downto 0); ddr3_ras_n : out std_logic; ddr3_cas_n : out std_logic; ddr3_we_n : out std_logic; ddr3_reset_n : out std_logic; ddr3_ck_p : out std_logic_vector(0 downto 0); ddr3_ck_n : out std_logic_vector(0 downto 0); ddr3_cke : out std_logic_vector(0 downto 0); ddr3_cs_n : out std_logic_vector(0 downto 0); ddr3_dm : out std_logic_vector(7 downto 0); ddr3_odt : out std_logic_vector(0 downto 0); ahbso : out ahb_slv_out_type; ahbsi : in ahb_slv_in_type; apbi : in apb_slv_in_type; apbo : out apb_slv_out_type; calib_done : out std_logic; rst_n_syn : in std_logic; rst_n_async : in std_logic; clk_amba : in std_logic; sys_clk_p : in std_logic; sys_clk_n : in std_logic; clk_ref_i : in std_logic; ui_clk : out std_logic; ui_clk_sync_rst : out std_logic ); end component ; component ddr_dummy port ( ddr_dq : inout std_logic_vector(63 downto 0); ddr_dqs : inout std_logic_vector(7 downto 0); ddr_dqs_n : inout std_logic_vector(7 downto 0); ddr_addr : out std_logic_vector(13 downto 0); ddr_ba : out std_logic_vector(2 downto 0); ddr_ras_n : out std_logic; ddr_cas_n : out std_logic; ddr_we_n : out std_logic; ddr_reset_n : out std_logic; ddr_ck_p : out std_logic_vector(0 downto 0); ddr_ck_n : out std_logic_vector(0 downto 0); ddr_cke : out std_logic_vector(0 downto 0); ddr_cs_n : out std_logic_vector(0 downto 0); ddr_dm : out std_logic_vector(7 downto 0); ddr_odt : out std_logic_vector(0 downto 0) ); end component ; --constant maxahbm : integer := CFG_NCPU+CFG_AHB_UART+CFG_AHB_JTAG+CFG_GRETH+CFG_GRUSBHC+CFG_GRUSBDC+CFG_GRUSB_DCL; constant maxahbm : integer := 16; --constant maxahbs : integer := 1+CFG_DSU+CFG_MCTRL_LEON2+CFG_AHBROMEN+CFG_AHBRAMEN+2+CFG_GRUSBDC; constant maxahbs : integer := 16; constant maxapbs : integer := CFG_IRQ3_ENABLE+CFG_GPT_ENABLE+CFG_GRGPIO_ENABLE+CFG_AHBSTAT+CFG_AHBSTAT+CFG_GRUSBHC+CFG_GRUSBDC+CFG_PRC; signal vcc, gnd : std_logic_vector(31 downto 0); signal memi : memory_in_type; signal memo : memory_out_type; signal wpo : wprot_out_type; signal sdi : sdctrl_in_type; signal sdo : sdram_out_type; signal sdo2, sdo3 : sdctrl_out_type; signal apbi : apb_slv_in_type; signal apbo : apb_slv_out_vector := (others => apb_none); signal ahbsi : ahb_slv_in_type; signal ahbso : ahb_slv_out_vector := (others => ahbs_none); signal ahbmi : ahb_mst_in_type; signal ahbmo : ahb_mst_out_vector := (others => ahbm_none); signal mig_ahbsi : ahb_slv_in_type; signal mig_ahbso : ahb_slv_out_type; signal ui_clk : std_ulogic; signal clkm : std_ulogic := '0'; signal rstn, rstraw, sdclkl : std_ulogic; signal clk_200 : std_ulogic; signal clk25, clk40, clk65 : std_ulogic; signal cgi, cgi2, cgiu : clkgen_in_type; signal cgo, cgo2, cgou : clkgen_out_type; signal u1i, u2i, dui : uart_in_type; signal u1o, u2o, duo : uart_out_type; signal irqi : irq_in_vector(0 to CFG_NCPU-1); signal irqo : irq_out_vector(0 to CFG_NCPU-1); signal sysi : leon_dsu_stat_base_in_type; signal syso : leon_dsu_stat_base_out_type; signal perf : l3stat_in_type; signal gmiii : eth_in_type; signal gmiio : eth_out_type; signal sgmiii : eth_sgmii_in_type; signal sgmiio : eth_sgmii_out_type; signal sgmiirst : std_logic; signal ethernet_phy_int : std_logic; signal rxd1 : std_logic; signal txd1 : std_logic; signal ethi : eth_in_type; signal etho : eth_out_type; signal egtx_clk :std_ulogic; signal negtx_clk :std_ulogic; signal gpti : gptimer_in_type; signal gpto : gptimer_out_type; signal gpioi : gpio_in_type; signal gpioo : gpio_out_type; signal clklock, elock, uclk ,ulock : std_ulogic; signal lock, calib_done, clkml, lclk, rst, ndsuact : std_ulogic; signal tck, tckn, tms, tdi, tdo : std_ulogic; signal lcd_datal : std_logic_vector(11 downto 0); signal lcd_hsyncl, lcd_vsyncl, lcd_del, lcd_reset_bl : std_ulogic; signal i2ci, dvi_i2ci : i2c_in_type; signal i2co, dvi_i2co : i2c_out_type; signal spii : spi_in_type; signal spio : spi_out_type; signal slvsel : std_logic_vector(CFG_SPICTRL_SLVS-1 downto 0); constant BOARD_FREQ : integer := 200000; -- input frequency in KHz constant CPU_FREQ : integer := BOARD_FREQ * CFG_CLKMUL / CFG_CLKDIV; -- cpu frequency in KHz signal stati : ahbstat_in_type; signal fpi : grfpu_in_vector_type; signal fpo : grfpu_out_vector_type; signal dsurx_int : std_logic; signal dsutx_int : std_logic; signal dsuctsn_int : std_logic; signal dsurtsn_int : std_logic; signal dsu_sel : std_logic; signal usbi : grusb_in_vector(0 downto 0); signal usbo : grusb_out_vector(0 downto 0); signal can_lrx, can_ltx : std_logic_vector(0 to 7); signal clkref : std_logic; signal migrstn : std_logic; attribute keep : boolean; attribute syn_keep : string; attribute keep of clkm : signal is true; attribute keep of uclk : signal is true; begin ---------------------------------------------------------------------- --- Reset and Clock generation ------------------------------------- ---------------------------------------------------------------------- vcc <= (others => '1'); gnd <= (others => '0'); cgi.pllctrl <= "00"; cgi.pllrst <= rstraw; clk_gen : if (CFG_MIG_7SERIES = 0) generate clk_pad_ds : clkpad_ds generic map (tech => padtech, level => sstl, voltage => x15v) port map (clk200p, clk200n, lclk); clkgen0 : clkgen -- clock generator generic map (clktech, CFG_CLKMUL, CFG_CLKDIV, CFG_MCTRL_SDEN, CFG_CLK_NOFB, 0, 0, 0, BOARD_FREQ) port map (lclk, lclk, clkm, open, open, open, open, cgi, cgo, open, open, open); end generate; reset_pad : inpad generic map (tech => padtech, level => cmos, voltage => x18v) port map (reset, rst); rst0 : rstgen -- reset generator generic map (acthigh => 1, syncin => 0) port map (rst, clkm, lock, rstn, rstraw); lock <= calib_done when CFG_MIG_7SERIES = 1 else cgo.clklock; rst1 : rstgen -- reset generator generic map (acthigh => 1) port map (rst, clkm, lock, migrstn, open); ---------------------------------------------------------------------- --- AHB CONTROLLER -------------------------------------------------- ---------------------------------------------------------------------- ahb0 : ahbctrl -- AHB arbiter/multiplexer generic map (defmast => CFG_DEFMST, split => CFG_SPLIT, rrobin => CFG_RROBIN, ioaddr => CFG_AHBIO, fpnpen => CFG_FPNPEN, nahbm => maxahbm, nahbs => maxahbs, devid => XILINX_VC707) port map (rstn, clkm, ahbmi, ahbmo, ahbsi, ahbso); ---------------------------------------------------------------------- --- LEON processor and DSU ----------------------------------------- ---------------------------------------------------------------------- leon : leon_dsu_stat_base generic map ( leon => CFG_LEON, ncpu => CFG_NCPU, fabtech => fabtech, memtech => memtech, nwindows => CFG_NWIN, dsu => CFG_DSU, fpu => CFG_FPU, v8 => CFG_V8, cp => 0, mac => CFG_MAC, pclow => pclow, notag => 0, nwp => CFG_NWP, icen => CFG_ICEN, irepl => CFG_IREPL, isets => CFG_ISETS, ilinesize => CFG_ILINE, isetsize => CFG_ISETSZ, isetlock => CFG_ILOCK, dcen => CFG_DCEN, drepl => CFG_DREPL, dsets => CFG_DSETS, dlinesize => CFG_DLINE, dsetsize => CFG_DSETSZ, dsetlock => CFG_DLOCK, dsnoop => CFG_DSNOOP, ilram => CFG_ILRAMEN, ilramsize => CFG_ILRAMSZ, ilramstart => CFG_ILRAMADDR, dlram => CFG_DLRAMEN, dlramsize => CFG_DLRAMSZ, dlramstart => CFG_DLRAMADDR, mmuen => CFG_MMUEN, itlbnum => CFG_ITLBNUM, dtlbnum => CFG_DTLBNUM, tlb_type => CFG_TLB_TYPE, tlb_rep => CFG_TLB_REP, lddel => CFG_LDDEL, disas => disas, tbuf => CFG_ITBSZ, pwd => CFG_PWD, svt => CFG_SVT, rstaddr => CFG_RSTADDR, smp => CFG_NCPU-1, cached => CFG_DFIXED, wbmask => CFG_BWMASK, busw => CFG_CACHEBW, netlist => CFG_LEON_NETLIST, ft => CFG_LEONFT_EN, npasi => CFG_NP_ASI, pwrpsr => CFG_WRPSR, rex => CFG_REX, altwin => CFG_ALTWIN, grfpush => CFG_GRFPUSH, dsu_hindex => 2, dsu_haddr => 16#D00#, dsu_hmask => 16#F00#, atbsz => CFG_ATBSZ, stat => CFG_STAT_ENABLE, stat_pindex => 8, stat_paddr => 16#100#, stat_pmask => 16#ffc#, stat_ncnt => CFG_STAT_CNT, stat_nmax => CFG_STAT_NMAX) port map ( rstn => rstn, ahbclk => clkm, cpuclk => clkm, hclken => vcc(0), leon_ahbmi => ahbmi, leon_ahbmo => ahbmo(CFG_NCPU-1 downto 0), leon_ahbsi => ahbsi, leon_ahbso => ahbso, irqi => irqi, irqo => irqo, stat_apbi => apbi, stat_apbo => apbo(8), stat_ahbsi => ahbsi, stati => perf, dsu_ahbsi => ahbsi, dsu_ahbso => ahbso(2), dsu_tahbmi => ahbmi, dsu_tahbsi => ahbsi, sysi => sysi, syso => syso); led1_pad : outpad generic map (tech => padtech, level => cmos, voltage => x18v) port map (led(1), syso.proc_error); sysi.dsu_enable <= '1'; dsui_break_pad : inpad generic map (level => cmos, voltage => x18v, tech => padtech) port map (button(3), sysi.dsu_break); dsuact_pad : outpad generic map (tech => padtech, level => cmos, voltage => x18v) port map (led(0), ndsuact); ndsuact <= not syso.dsu_active; -- Debug UART dcomgen : if CFG_AHB_UART = 1 generate dcom0 : ahbuart generic map (hindex => CFG_NCPU, pindex => 7, paddr => 7) port map (rstn, clkm, dui, duo, apbi, apbo(7), ahbmi, ahbmo(CFG_NCPU)); dui.extclk <= '0'; end generate; nouah : if CFG_AHB_UART = 0 generate apbo(7) <= apb_none; duo.txd <= '0'; duo.rtsn <= '0'; dui.extclk <= '0'; end generate; sw4_pad : iopad generic map (tech => padtech, level => cmos, voltage => x18v) port map (switch(4), '0', '1', dsu_sel); dsutx_int <= duo.txd when dsu_sel = '1' else u1o.txd; dui.rxd <= dsurx_int when dsu_sel = '1' else '1'; u1i.rxd <= dsurx_int when dsu_sel = '0' else '1'; dsurtsn_int <= duo.rtsn when dsu_sel = '1' else u1o.rtsn; dui.ctsn <= dsuctsn_int when dsu_sel = '1' else '1'; u1i.ctsn <= dsuctsn_int when dsu_sel = '0' else '1'; dsurx_pad : inpad generic map (level => cmos, voltage => x18v, tech => padtech) port map (dsurx, dsurx_int); dsutx_pad : outpad generic map (level => cmos, voltage => x18v, tech => padtech) port map (dsutx, dsutx_int); dsuctsn_pad : inpad generic map (level => cmos, voltage => x18v, tech => padtech) port map (dsuctsn, dsuctsn_int); dsurtsn_pad : outpad generic map (level => cmos, voltage => x18v, tech => padtech) port map (dsurtsn, dsurtsn_int); ahbjtaggen0 :if CFG_AHB_JTAG = 1 generate ahbjtag0 : ahbjtag generic map(tech => fabtech, hindex => CFG_NCPU+1) port map(rstn, clkm, tck, tms, tdi, tdo, ahbmi, ahbmo(CFG_NCPU+1), open, open, open, open, open, open, open, gnd(0)); end generate; nojtag : if CFG_AHB_JTAG = 0 generate ahbmo(CFG_NCPU+1) <= ahbm_none; end generate; ---------------------------------------------------------------------- --- Memory controller ---------------------------------------------- ---------------------------------------------------------------------- memi.writen <= '1'; memi.wrn <= "1111"; memi.bwidth <= "01"; memi.brdyn <= '0'; memi.bexcn <= '1'; mctrl_gen : if CFG_MCTRL_LEON2 /= 0 generate mctrl0 : mctrl generic map (hindex => 0, pindex => 0, paddr => 0, srbanks => 2, ram8 => CFG_MCTRL_RAM8BIT, ram16 => CFG_MCTRL_RAM16BIT, sden => CFG_MCTRL_SDEN, invclk => CFG_CLK_NOFB, sepbus => CFG_MCTRL_SEPBUS, pageburst => CFG_MCTRL_PAGE, rammask => 0, iomask => 0) port map (rstn, clkm, memi, memo, ahbsi, ahbso(0), apbi, apbo(0), wpo, sdo); addr_pad : outpadv generic map (width => 26, tech => padtech, level => cmos, voltage => x18v) port map (address(25 downto 0), memo.address(26 downto 1)); roms_pad : outpad generic map (tech => padtech, level => cmos, voltage => x18v) port map (romsn, memo.romsn(0)); oen_pad : outpad generic map (tech => padtech, level => cmos, voltage => x18v) port map (oen, memo.oen); adv_pad : outpad generic map (tech => padtech, level => cmos, voltage => x18v) port map (adv, '0'); wri_pad : outpad generic map (tech => padtech, level => cmos, voltage => x18v) port map (writen, memo.writen); data_pad : iopadvv generic map (tech => padtech, width => 16, level => cmos, voltage => x18v) port map (data(15 downto 0), memo.data(31 downto 16), memo.vbdrive(31 downto 16), memi.data(31 downto 16)); end generate; nomctrl : if CFG_MCTRL_LEON2 = 0 generate roms_pad : outpad generic map (tech => padtech, level => cmos, voltage => x18v) port map (romsn, vcc(0)); --ahbso(0) <= ahbso_none; end generate; ----------------------------------------------------------------------------- -- L2 cache, optionally covering DDR3 SDRAM memory controller ----------------------------------------------------------------------------- l2cen : if CFG_L2_EN /= 0 generate l2cblock : block signal mem_ahbsi : ahb_slv_in_type; signal mem_ahbso : ahb_slv_out_vector := (others => ahbs_none); signal mem_ahbmi : ahb_mst_in_type; signal mem_ahbmo : ahb_mst_out_vector := (others => ahbm_none); signal l2c_stato : std_logic_vector(10 downto 0); begin l2c0 : l2c generic map ( hslvidx => 4, hmstidx => 0, cen => CFG_L2_PEN, haddr => 16#400#, hmask => 16#c00#, ioaddr => 16#FF0#, cached => CFG_L2_MAP, repl => CFG_L2_RAN, ways => CFG_L2_WAYS, linesize => CFG_L2_LSZ, waysize => CFG_L2_SIZE, memtech => memtech, bbuswidth => AHBDW, bioaddr => 16#FFE#, biomask => 16#fff#, sbus => 0, mbus => 1, arch => CFG_L2_SHARE, ft => CFG_L2_EDAC) port map(rst => rstn, clk => clkm, ahbsi => ahbsi, ahbso => ahbso(4), ahbmi => mem_ahbmi, ahbmo => mem_ahbmo(0), ahbsov => mem_ahbso, sto => l2c_stato); memahb0 : ahbctrl -- AHB arbiter/multiplexer generic map (defmast => CFG_DEFMST, split => CFG_SPLIT, rrobin => CFG_RROBIN, ioaddr => 16#FFE#, ioen => 1, nahbm => 1, nahbs => 1) port map (rstn, clkm, mem_ahbmi, mem_ahbmo, mem_ahbsi, mem_ahbso); mem_ahbso(0) <= mig_ahbso; mig_ahbsi <= mem_ahbsi; perf.event(15 downto 7) <= (others => '0'); perf.esource(15 downto 7) <= (others => (others => '0')); perf.event(6) <= l2c_stato(10); -- Data uncorrectable error perf.event(5) <= l2c_stato(9); -- Data correctable error perf.event(4) <= l2c_stato(8); -- Tag uncorrectable error perf.event(3) <= l2c_stato(7); -- Tag correctable error perf.event(2) <= l2c_stato(2); -- Bus access perf.event(1) <= l2c_stato(1); -- Miss perf.event(0) <= l2c_stato(0); -- Hit perf.esource(6 downto 3) <= (others => (others => '0')); perf.esource(2 downto 0) <= (others => l2c_stato(6 downto 3)); perf.req <= (others => '0'); perf.sel <= (others => '0'); perf.latcnt <= '0'; --perf.timer <= dbgi(0).timer(31 downto 0); end block l2cblock; end generate l2cen; nol2c : if CFG_L2_EN = 0 generate ahbso(4) <= mig_ahbso; mig_ahbsi <= ahbsi; perf <= l3stat_in_none; end generate; ---------------------------------------------------------------------- --- DDR3 memory controller ------------------------------------------ ---------------------------------------------------------------------- mig_gen : if (CFG_MIG_7SERIES = 1) generate gen_mig : if (USE_MIG_INTERFACE_MODEL /= true) generate ddrc : ahb2mig_7series generic map ( hindex => 4*(1-CFG_L2_EN), haddr => 16#400#, hmask => 16#F00#, pindex => 4, paddr => 4, SIM_BYPASS_INIT_CAL => SIM_BYPASS_INIT_CAL, SIMULATION => SIMULATION, USE_MIG_INTERFACE_MODEL => USE_MIG_INTERFACE_MODEL) port map ( ddr3_dq => ddr3_dq, ddr3_dqs_p => ddr3_dqs_p, ddr3_dqs_n => ddr3_dqs_n, ddr3_addr => ddr3_addr, ddr3_ba => ddr3_ba, ddr3_ras_n => ddr3_ras_n, ddr3_cas_n => ddr3_cas_n, ddr3_we_n => ddr3_we_n, ddr3_reset_n => ddr3_reset_n, ddr3_ck_p => ddr3_ck_p, ddr3_ck_n => ddr3_ck_n, ddr3_cke => ddr3_cke, ddr3_cs_n => ddr3_cs_n, ddr3_dm => ddr3_dm, ddr3_odt => ddr3_odt, ahbsi => mig_ahbsi, ahbso => mig_ahbso, apbi => apbi, apbo => apbo(4), calib_done => calib_done, rst_n_syn => migrstn, rst_n_async => rstraw, clk_amba => clkm, sys_clk_p => clk200p, sys_clk_n => clk200n, clk_ref_i => clkref, ui_clk => clkm, ui_clk_sync_rst => open ); clkgenmigref0 : clkgen generic map (clktech, 16, 8, 0,CFG_CLK_NOFB, 0, 0, 0, 100000) port map (clkm, clkm, clkref, open, open, open, open, cgi, cgo, open, open, open); end generate gen_mig; gen_mig_model : if (USE_MIG_INTERFACE_MODEL = true) generate -- pragma translate_off mig_ahbram : ahbram_sim generic map ( hindex => 4*(1-CFG_L2_EN), haddr => 16#400#, hmask => 16#C00#, tech => 0, kbytes => 1000, pipe => 0, maccsz => AHBDW, fname => "ram.srec" ) port map( rst => rstn, clk => clkm, ahbsi => mig_ahbsi, ahbso => mig_ahbso ); ddr3_dq <= (others => 'Z'); ddr3_dqs_p <= (others => 'Z'); ddr3_dqs_n <= (others => 'Z'); ddr3_addr <= (others => '0'); ddr3_ba <= (others => '0'); ddr3_ras_n <= '0'; ddr3_cas_n <= '0'; ddr3_we_n <= '0'; ddr3_reset_n <= '1'; ddr3_ck_p <= (others => '0'); ddr3_ck_n <= (others => '0'); ddr3_cke <= (others => '0'); ddr3_cs_n <= (others => '0'); ddr3_dm <= (others => '0'); ddr3_odt <= (others => '0'); calib_done <= '1'; clkm <= not clkm after 5.0 ns; -- pragma translate_on end generate gen_mig_model; end generate; no_mig_gen : if (CFG_MIG_7SERIES = 0) generate ahbram0 : ahbram generic map (hindex => 4*(1-CFG_L2_EN), haddr => 16#400#, tech => CFG_MEMTECH, kbytes => 128) port map ( rstn, clkm, mig_ahbsi, mig_ahbso); ddrdummy0 : ddr_dummy port map ( ddr_dq => ddr3_dq, ddr_dqs => ddr3_dqs_p, ddr_dqs_n => ddr3_dqs_n, ddr_addr => ddr3_addr, ddr_ba => ddr3_ba, ddr_ras_n => ddr3_ras_n, ddr_cas_n => ddr3_cas_n, ddr_we_n => ddr3_we_n, ddr_reset_n => ddr3_reset_n, ddr_ck_p => ddr3_ck_p, ddr_ck_n => ddr3_ck_n, ddr_cke => ddr3_cke, ddr_cs_n => ddr3_cs_n, ddr_dm => ddr3_dm, ddr_odt => ddr3_odt ); calib_done <= '1'; end generate no_mig_gen; led2_pad : outpad generic map (tech => padtech, level => cmos, voltage => x18v) port map (led(2), calib_done); led3_pad : outpad generic map (tech => padtech, level => cmos, voltage => x18v) port map (led(3), lock); ----------------------------------------------------------------------- --- ETHERNET --------------------------------------------------------- ----------------------------------------------------------------------- eth0 : if CFG_GRETH = 1 generate -- Gaisler ethernet MAC e1 : grethm generic map( hindex => CFG_NCPU+CFG_AHB_UART+CFG_AHB_JTAG, pindex => 14, paddr => 16#C00#, pmask => 16#C00#, pirq => 5, memtech => memtech, mdcscaler => CPU_FREQ/1000, rmii => 0, enable_mdio => 1, fifosize => CFG_ETH_FIFO, nsync => 2, edcl => CFG_DSU_ETH, edclbufsz => CFG_ETH_BUF, phyrstadr => 7, macaddrh => CFG_ETH_ENM, macaddrl => CFG_ETH_ENL, enable_mdint => 1, ipaddrh => CFG_ETH_IPM, ipaddrl => CFG_ETH_IPL, giga => CFG_GRETH1G, ramdebug => 0, gmiimode => 1) port map( rst => rstn, clk => clkm, ahbmi => ahbmi, ahbmo => ahbmo(CFG_NCPU+CFG_AHB_UART+CFG_AHB_JTAG), apbi => apbi, apbo => apbo(14), ethi => gmiii, etho => gmiio); sgmiirst <= not rstraw; sgmii0 : sgmii_vc707 generic map( pindex => 11, paddr => 16#010#, pmask => 16#ff0#, abits => 8, autonegotiation => autonegotiation, pirq => 11, debugmem => 1, tech => fabtech ) port map( sgmiii => sgmiii, sgmiio => sgmiio, gmiii => gmiii, gmiio => gmiio, reset => sgmiirst, apb_clk => clkm, apb_rstn => rstn, apbi => apbi, apbo => apbo(11) ); emdio_pad : iopad generic map (tech => padtech, level => cmos, voltage => x18v) port map (emdio, sgmiio.mdio_o, sgmiio.mdio_oe, sgmiii.mdio_i); emdc_pad : outpad generic map (tech => padtech, level => cmos, voltage => x18v) port map (emdc, sgmiio.mdc); eint_pad : inpad generic map (tech => padtech, level => cmos, voltage => x18v) port map (eint, sgmiii.mdint); erst_pad : outpad generic map (tech => padtech, level => cmos, voltage => x18v) port map (erst, sgmiio.reset); sgmiii.clkp <= gtrefclk_p; sgmiii.clkn <= gtrefclk_n; txp <= sgmiio.txp; txn <= sgmiio.txn; sgmiii.rxp <= rxp; sgmiii.rxn <= rxn; end generate; noeth0 : if CFG_GRETH = 0 generate -- TODO: end generate; ----------------------------------------------------------------------- --- CAN -------------------------------------------------------------- ----------------------------------------------------------------------- can0 : if CFG_CAN = 1 generate can0 : can_mc generic map (slvndx => 6, ioaddr => CFG_CANIO, iomask => 16#FF0#, irq => CFG_CANIRQ, memtech => memtech, ncores => CFG_CAN_NUM, sepirq => CFG_CANSEPIRQ) port map (rstn, clkm, ahbsi, ahbso(6), can_lrx, can_ltx ); can_pads : for i in 0 to CFG_CAN_NUM-1 generate can_tx_pad : outpad generic map (tech => padtech, level => cmos, voltage => x18v) port map (can_txd(i), can_ltx(i)); can_rx_pad : inpad generic map (tech => padtech, level => cmos, voltage => x18v) port map (can_rxd(i), can_lrx(i)); end generate; end generate; ncan : if CFG_CAN = 0 generate ahbso(6) <= ahbs_none; end generate; ------------------------------------------------------------------------------- -- USB ------------------------------------------------------------------------ ------------------------------------------------------------------------------- -- Note that more than one USB component can not be instantiated at the same -- time (board has only one USB transceiver), therefore they share AHB -- master/slave indexes ----------------------------------------------------------------------------- -- Shared pads ----------------------------------------------------------------------------- usbpads: if (CFG_GRUSBHC + CFG_GRUSBDC + CFG_GRUSB_DCL) /= 0 generate -- Incoming 60 MHz clock from transceiver, arch 3 = through BUFGDLL or -- arch 2 = through BUFG or similiar. --usb_clkout_pad : clkpad --generic map (tech => padtech, arch => 3) --port map (usb_clkout, uclk, cgo.clklock, ulock); usb_clkout_pad : clkpad generic map (tech => padtech, arch => 2) port map (usb_clkout,uclk); usb_d_pad: iopadv generic map(tech => padtech, width => 8) port map (usb_d, usbo(0).dataout(7 downto 0), usbo(0).oen, usbi(0).datain(7 downto 0)); usb_nxt_pad : inpad generic map (tech => padtech) port map (usb_nxt, usbi(0).nxt); usb_dir_pad : inpad generic map (tech => padtech) port map (usb_dir, usbi(0).dir); usb_resetn_pad : outpad generic map (tech => padtech) port map (usb_resetn, usbo(0).reset); usb_stp_pad : outpad generic map (tech => padtech) port map (usb_stp, usbo(0).stp); end generate usbpads; nousb: if (CFG_GRUSBHC + CFG_GRUSBDC + CFG_GRUSB_DCL) = 0 generate --ulock <= '1'; usb_resetn_pad : outpad generic map (tech => padtech, slew => 1) port map (usb_resetn, '0'); usb_stp_pad : outpad generic map (tech => padtech, slew => 1) port map (usb_stp, '0'); end generate nousb; ----------------------------------------------------------------------------- -- USB 2.0 Host Controller ----------------------------------------------------------------------------- usbhc0: if CFG_GRUSBHC = 1 generate usbhc0 : grusbhc generic map ( ehchindex => CFG_NCPU+CFG_AHB_UART+CFG_AHB_JTAG+CFG_GRETH, ehcpindex => 13, ehcpaddr => 13, ehcpirq => 3, ehcpmask => 16#fff#, uhchindex => CFG_NCPU+CFG_AHB_UART+CFG_AHB_JTAG+CFG_GRETH+1, uhchsindex => 8, uhchaddr => 16#A00#, uhchmask => 16#fff#, uhchirq => 4, tech => fabtech, memtech => memtech, ehcgen => CFG_GRUSBHC_EHC, uhcgen => CFG_GRUSBHC_UHC, endian_conv => CFG_GRUSBHC_ENDIAN, be_regs => CFG_GRUSBHC_BEREGS, be_desc => CFG_GRUSBHC_BEDESC, uhcblo => CFG_GRUSBHC_BLO, bwrd => CFG_GRUSBHC_BWRD, vbusconf => CFG_GRUSBHC_VBUSCONF) port map ( clkm,uclk,rstn,apbi,apbo(13),ahbmi,ahbsi, ahbmo(CFG_NCPU+CFG_AHB_UART+CFG_AHB_JTAG+CFG_GRETH), ahbmo(CFG_NCPU+CFG_AHB_UART+CFG_AHB_JTAG+CFG_GRETH+1 downto CFG_NCPU+CFG_AHB_UART+CFG_AHB_JTAG+CFG_GRETH+1), ahbso(8 downto 8), usbo,usbi); end generate usbhc0; ----------------------------------------------------------------------------- -- USB 2.0 Device Controller ----------------------------------------------------------------------------- usbdc0: if CFG_GRUSBDC = 1 generate usbdc0: grusbdc generic map( hsindex => 8, hirq => 6, haddr => 16#004#, hmask => 16#FFC#, hmindex => CFG_NCPU+CFG_AHB_UART+CFG_AHB_JTAG+CFG_GRETH, aiface => CFG_GRUSBDC_AIFACE, uiface => 1, nepi => CFG_GRUSBDC_NEPI, nepo => CFG_GRUSBDC_NEPO, i0 => CFG_GRUSBDC_I0, i1 => CFG_GRUSBDC_I1, i2 => CFG_GRUSBDC_I2, i3 => CFG_GRUSBDC_I3, i4 => CFG_GRUSBDC_I4, i5 => CFG_GRUSBDC_I5, i6 => CFG_GRUSBDC_I6, i7 => CFG_GRUSBDC_I7, i8 => CFG_GRUSBDC_I8, i9 => CFG_GRUSBDC_I9, i10 => CFG_GRUSBDC_I10, i11 => CFG_GRUSBDC_I11, i12 => CFG_GRUSBDC_I12, i13 => CFG_GRUSBDC_I13, i14 => CFG_GRUSBDC_I14, i15 => CFG_GRUSBDC_I15, o0 => CFG_GRUSBDC_O0, o1 => CFG_GRUSBDC_O1, o2 => CFG_GRUSBDC_O2, o3 => CFG_GRUSBDC_O3, o4 => CFG_GRUSBDC_O4, o5 => CFG_GRUSBDC_O5, o6 => CFG_GRUSBDC_O6, o7 => CFG_GRUSBDC_O7, o8 => CFG_GRUSBDC_O8, o9 => CFG_GRUSBDC_O9, o10 => CFG_GRUSBDC_O10, o11 => CFG_GRUSBDC_O11, o12 => CFG_GRUSBDC_O12, o13 => CFG_GRUSBDC_O13, o14 => CFG_GRUSBDC_O14, o15 => CFG_GRUSBDC_O15, memtech => memtech, keepclk => 1) port map( uclk => uclk, usbi => usbi(0), usbo => usbo(0), hclk => clkm, hrst => rstn, ahbmi => ahbmi, ahbmo => ahbmo(CFG_NCPU+CFG_AHB_UART+CFG_AHB_JTAG+CFG_GRETH), ahbsi => ahbsi, ahbso => ahbso(8) ); end generate usbdc0; ----------------------------------------------------------------------------- -- USB DCL ----------------------------------------------------------------------------- usb_dcl0: if CFG_GRUSB_DCL = 1 generate usb_dcl0: grusb_dcl generic map ( hindex => CFG_NCPU+CFG_AHB_UART+CFG_AHB_JTAG+CFG_GRETH, memtech => memtech, keepclk => 1, uiface => 1) port map ( uclk, usbi(0), usbo(0), clkm, rstn, ahbmi, ahbmo(CFG_NCPU+CFG_AHB_UART+CFG_AHB_JTAG+CFG_GRETH)); end generate usb_dcl0; ---------------------------------------------------------------------- --- I2C Controller -------------------------------------------------- ---------------------------------------------------------------------- --i2cm: if CFG_I2C_ENABLE = 1 generate -- I2C master i2c0 : i2cmst generic map (pindex => 9, paddr => 9, pmask => 16#FFF#, pirq => 10, filter => 9) port map (rstn, clkm, apbi, apbo(9), i2ci, i2co); i2c_scl_pad : iopad generic map (tech => padtech, level => cmos, voltage => x18v) port map (iic_scl, i2co.scl, i2co.scloen, i2ci.scl); i2c_sda_pad : iopad generic map (tech => padtech, level => cmos, voltage => x18v) port map (iic_sda, i2co.sda, i2co.sdaoen, i2ci.sda); --end generate i2cm; ---------------------------------------------------------------------- --- APB Bridge and various periherals ------------------------------- ---------------------------------------------------------------------- apb0 : apbctrl -- AHB/APB bridge generic map (hindex => 1, haddr => CFG_APBADDR, hmask => 16#F00#, nslaves => 16) port map (rstn, clkm, ahbsi, ahbso(1), apbi, apbo ); irqctrl : if CFG_IRQ3_ENABLE /= 0 generate irqctrl0 : irqmp -- interrupt controller generic map (pindex => 2, paddr => 2, ncpu => CFG_NCPU) port map (rstn, clkm, apbi, apbo(2), irqo, irqi); end generate; irq3 : if CFG_IRQ3_ENABLE = 0 generate x : for i in 0 to CFG_NCPU-1 generate irqi(i).irl <= "0000"; end generate; apbo(2) <= apb_none; end generate; gpt : if CFG_GPT_ENABLE /= 0 generate timer0 : gptimer -- timer unit generic map (pindex => 3, paddr => 3, pirq => CFG_GPT_IRQ, sepirq => CFG_GPT_SEPIRQ, sbits => CFG_GPT_SW, ntimers => CFG_GPT_NTIM, nbits => CFG_GPT_TW, wdog => CFG_GPT_WDOGEN*CFG_GPT_WDOG) port map (rstn, clkm, apbi, apbo(3), gpti, gpto); gpti <= gpti_dhalt_drive(syso.dsu_tstop); end generate; nogpt : if CFG_GPT_ENABLE = 0 generate apbo(3) <= apb_none; end generate; gpio0 : if CFG_GRGPIO_ENABLE /= 0 generate -- GPIO unit grgpio0: grgpio generic map(pindex => 10, paddr => 10, imask => CFG_GRGPIO_IMASK, nbits => 7) port map(rst => rstn, clk => clkm, apbi => apbi, apbo => apbo(10), gpioi => gpioi, gpioo => gpioo); pio_pads : for i in 0 to 3 generate pio_pad : iopad generic map (tech => padtech, level => cmos, voltage => x18v) port map (switch(i), gpioo.dout(i), gpioo.oen(i), gpioi.din(i)); end generate; pio_pads2 : for i in 4 to 5 generate pio_pad : inpad generic map (tech => padtech, level => cmos, voltage => x18v) port map (button(i-4), gpioi.din(i)); end generate; end generate; ua1 : if CFG_UART1_ENABLE /= 0 generate uart1 : apbuart -- UART 1 generic map (pindex => 1, paddr => 1, pirq => 2, console => dbguart, fifosize => CFG_UART1_FIFO) port map (rstn, clkm, apbi, apbo(1), u1i, u1o); u1i.extclk <= '0'; serrx_pad : outpad generic map (level => cmos, voltage => x18v, tech => padtech) port map (led(5), rxd1); sertx_pad : outpad generic map (level => cmos, voltage => x18v, tech => padtech) port map (led(6), txd1); end generate; noua0 : if CFG_UART1_ENABLE = 0 generate apbo(1) <= apb_none; end generate; spic: if CFG_SPICTRL_ENABLE = 1 generate -- SPI controller spi1 : spictrl generic map (pindex => 12, paddr => 12, pmask => 16#fff#, pirq => 12, fdepth => CFG_SPICTRL_FIFO, slvselen => CFG_SPICTRL_SLVREG, slvselsz => CFG_SPICTRL_SLVS, odmode => 0, netlist => 0, syncram => CFG_SPICTRL_SYNCRAM, ft => CFG_SPICTRL_FT) port map (rstn, clkm, apbi, apbo(12), spii, spio, slvsel); spii.spisel <= '1'; -- Master only miso_pad : inpad generic map (level => cmos, voltage => x18v,tech => padtech) port map (spi_data_out, spii.miso); mosi_pad : outpad generic map (level => cmos, voltage => x18v,tech => padtech) port map (spi_data_in, spio.mosi); sck_pad : outpad generic map (level => cmos, voltage => x18v,tech => padtech) port map (spi_clk, spio.sck); slvsel_pad : outpad generic map (level => cmos, voltage => x18v,tech => padtech) port map (spi_data_cs_b, slvsel(0)); end generate spic; nospi: if CFG_SPICTRL_ENABLE = 0 generate miso_pad : inpad generic map (level => cmos, voltage => x18v,tech => padtech) port map (spi_data_out, spii.miso); mosi_pad : outpad generic map (level => cmos, voltage => x18v,tech => padtech) port map (spi_data_in, vcc(0)); sck_pad : outpad generic map (level => cmos, voltage => x18v,tech => padtech) port map (spi_clk, gnd(0)); slvsel_pad : outpad generic map (level => cmos, voltage => x18v,tech => padtech) port map (spi_data_cs_b, vcc(0)); end generate; ahbs : if CFG_AHBSTAT = 1 generate -- AHB status register stati <= ahbstat_in_none; ahbstat0 : ahbstat generic map (pindex => 15, paddr => 15, pirq => 7, nftslv => CFG_AHBSTATN) port map (rstn, clkm, ahbmi, ahbsi, stati, apbi, apbo(15)); end generate; ----------------------------------------------------------------------- --- AHB ROM ---------------------------------------------------------- ----------------------------------------------------------------------- bpromgen : if CFG_AHBROMEN /= 0 generate brom : entity work.ahbrom generic map (hindex => 7, haddr => CFG_AHBRODDR, pipe => CFG_AHBROPIP) port map ( rstn, clkm, ahbsi, ahbso(7)); end generate; ----------------------------------------------------------------------- --- AHB RAM ---------------------------------------------------------- ----------------------------------------------------------------------- ocram : if CFG_AHBRAMEN = 1 generate ahbram0 : ahbram generic map (hindex => 5, haddr => CFG_AHBRADDR, tech => CFG_MEMTECH, kbytes => CFG_AHBRSZ) port map ( rstn, clkm, ahbsi, ahbso(5)); end generate; ----------------------------------------------------------------------- --- DYNAMIC PARTIAL RECONFIGURATION --------------------------------- ----------------------------------------------------------------------- prc : if CFG_PRC = 1 generate p1 : dprc generic map(hindex => CFG_NCPU+CFG_AHB_UART+CFG_AHB_JTAG+CFG_GRETH, pindex => 5, paddr => 5, cfg_clkmul => 4, cfg_clkdiv => 8, raw_freq => BOARD_FREQ, clk_sel => 0, edac_en => CFG_EDAC_EN, pirq => 6, technology => CFG_FABTECH, crc_en => CFG_CRC_EN, words_block => CFG_WORDS_BLOCK, fifo_dcm_inst => CFG_DCM_FIFO, fifo_depth => CFG_DPR_FIFO) port map( rstn => rstn, clkm => clkm, clkraw => clkm, clk100 => '0', ahbmi => ahbmi, ahbmo => ahbmo(CFG_NCPU+CFG_AHB_UART+CFG_AHB_JTAG+CFG_GRETH), apbi => apbi, apbo => apbo(5), rm_reset => open); end generate; ----------------------------------------------------------------------- --- Test report module ---------------------------------------------- ----------------------------------------------------------------------- -- pragma translate_off test0 : ahbrep generic map (hindex => 3, haddr => 16#200#) port map (rstn, clkm, ahbsi, ahbso(3)); -- pragma translate_on ----------------------------------------------------------------------- --- Drive unused bus elements --------------------------------------- ----------------------------------------------------------------------- nam1 : for i in (CFG_NCPU+CFG_AHB_UART+CFG_AHB_JTAG+CFG_GRETH+CFG_GRUSBDC+CFG_GRUSBHC*2+CFG_GRUSB_DCL+CFG_PRC) to NAHBMST-1 generate ahbmo(i) <= ahbm_none; end generate; ----------------------------------------------------------------------- --- Boot message ---------------------------------------------------- ----------------------------------------------------------------------- -- pragma translate_off x : report_design generic map ( msg1 => "LEON3 Xilinx VC707 Demonstration design", fabtech => tech_table(fabtech), memtech => tech_table(memtech), mdel => 1 ); -- pragma translate_on end;
library UNISIM; use UNISIM.vcomponents.all; library ieee; use ieee.std_logic_1164.all; entity clk_gen is port( sys_clk_p_i : in std_logic; sys_clk_n_i : in std_logic; sys_clk_o : out std_logic; sys_clk_bufg_o : out std_logic ); end clk_gen; architecture syn of clk_gen is -- Internal clock signal signal s_sys_clk : std_logic; begin -- IBUFGDS: Differential Global Clock Input Buffer -- Virtex-6 -- Xilinx HDL Language Template, version 13.4 cpm_ibufgds_clk_gen : IBUFGDS generic map ( DIFF_TERM => FALSE, -- Differential Termination IBUF_LOW_PWR => TRUE, -- Low power (TRUE) vs. performance (FALSE) setting for referenced I/O standards IOSTANDARD => "DEFAULT" ) port map ( O => s_sys_clk, -- Clock buffer output I => sys_clk_p_i, -- Diff_p clock buffer input (connect directly to top-level port) IB => sys_clk_n_i -- Diff_n clock buffer input (connect directly to top-level port) ); sys_clk_o <= s_sys_clk; -- BUFG: Global Clock Buffer -- Virtex-6 -- Xilinx HDL Language Template, version 13.4 cmp_bufg_clk_gen : BUFG port map ( O => sys_clk_bufg_o, -- 1-bit output: Clock buffer output I => s_sys_clk -- 1-bit input: Clock buffer input ); end syn;
package fifo_pkg is end package; package fifo_pkg is end package;
-------------------------------------------------------------------------------- -- -- BLK MEM GEN v7.1 Core - Top-level core wrapper -- -------------------------------------------------------------------------------- -- -- (c) Copyright 2006-2010 Xilinx, Inc. All rights reserved. -- -- This file contains confidential and proprietary information -- of Xilinx, Inc. and is protected under U.S. and -- international copyright and other intellectual property -- laws. -- -- DISCLAIMER -- This disclaimer is not a license and does not grant any -- rights to the materials distributed herewith. Except as -- otherwise provided in a valid license issued to you by -- Xilinx, and to the maximum extent permitted by applicable -- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND -- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES -- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING -- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- -- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and -- (2) Xilinx shall not be liable (whether in contract or tort, -- including negligence, or under any other theory of -- liability) for any loss or damage of any kind or nature -- related to, arising under or in connection with these -- materials, including for any direct, or any indirect, -- special, incidental, or consequential loss or damage -- (including loss of data, profits, goodwill, or any type of -- loss or damage suffered as a result of any action brought -- by a third party) even if such damage or loss was -- reasonably foreseeable or Xilinx had been advised of the -- possibility of the same. -- -- CRITICAL APPLICATIONS -- Xilinx products are not designed or intended to be fail- -- safe, or for use in any application requiring fail-safe -- performance, such as life-support or safety devices or -- systems, Class III medical devices, nuclear facilities, -- applications related to the deployment of airbags, or any -- other applications that could lead to death, personal -- injury, or severe property or environmental damage -- (individually and collectively, "Critical -- Applications"). Customer assumes the sole risk and -- liability of any use of Xilinx products in Critical -- Applications, subject only to applicable laws and -- regulations governing limitations on product liability. -- -- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS -- PART OF THIS FILE AT ALL TIMES. -------------------------------------------------------------------------------- -- -- Filename: Instruction_Memory_exdes.vhd -- -- Description: -- This is the actual BMG core wrapper. -- -------------------------------------------------------------------------------- -- Author: IP Solutions Division -- -- History: August 31, 2005 - First Release -------------------------------------------------------------------------------- -- -------------------------------------------------------------------------------- -- Library Declarations -------------------------------------------------------------------------------- LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; USE IEEE.STD_LOGIC_ARITH.ALL; USE IEEE.STD_LOGIC_UNSIGNED.ALL; LIBRARY UNISIM; USE UNISIM.VCOMPONENTS.ALL; -------------------------------------------------------------------------------- -- Entity Declaration -------------------------------------------------------------------------------- ENTITY Instruction_Memory_exdes IS PORT ( --Inputs - Port A WEA : IN STD_LOGIC_VECTOR(0 DOWNTO 0); ADDRA : IN STD_LOGIC_VECTOR(4 DOWNTO 0); DINA : IN STD_LOGIC_VECTOR(15 DOWNTO 0); DOUTA : OUT STD_LOGIC_VECTOR(15 DOWNTO 0); CLKA : IN STD_LOGIC ); END Instruction_Memory_exdes; ARCHITECTURE xilinx OF Instruction_Memory_exdes IS COMPONENT BUFG IS PORT ( I : IN STD_ULOGIC; O : OUT STD_ULOGIC ); END COMPONENT; COMPONENT Instruction_Memory IS PORT ( --Port A WEA : IN STD_LOGIC_VECTOR(0 DOWNTO 0); ADDRA : IN STD_LOGIC_VECTOR(4 DOWNTO 0); DINA : IN STD_LOGIC_VECTOR(15 DOWNTO 0); DOUTA : OUT STD_LOGIC_VECTOR(15 DOWNTO 0); CLKA : IN STD_LOGIC ); END COMPONENT; SIGNAL CLKA_buf : STD_LOGIC; SIGNAL CLKB_buf : STD_LOGIC; SIGNAL S_ACLK_buf : STD_LOGIC; BEGIN bufg_A : BUFG PORT MAP ( I => CLKA, O => CLKA_buf ); bmg0 : Instruction_Memory PORT MAP ( --Port A WEA => WEA, ADDRA => ADDRA, DINA => DINA, DOUTA => DOUTA, CLKA => CLKA_buf ); END xilinx;
entity tb_rec08 is end tb_rec08; library ieee; use ieee.std_logic_1164.all; use work.rec08_pkg.all; architecture behav of tb_rec08 is signal inp : std_logic; signal r : myrec; begin dut: entity work.rec08 port map (inp => inp, o => r); process begin inp <= '1'; wait for 1 ns; assert r = (a => "1", b => '0') severity failure; inp <= '0'; wait for 1 ns; assert r = (a => "0", b => '1') severity failure; wait; end process; end behav;
-- $Id: tb_nexys3_fusp.vhd 1181 2019-07-08 17:00:50Z mueller $ -- SPDX-License-Identifier: GPL-3.0-or-later -- Copyright 2011-2016 by Walter F.J. Mueller <[email protected]> -- ------------------------------------------------------------------------------ -- Module Name: tb_nexys3_fusp - sim -- Description: Test bench for nexys3 (base+fusp) -- -- Dependencies: simlib/simclk -- simlib/simclkcnt -- xlib/s6_cmt_sfs -- rlink/tbcore/tbcore_rlink -- tb_nexys3_core -- serport/tb/serport_master_tb -- nexys3_fusp_aif [UUT] -- -- To test: generic, any nexys3_fusp_aif target -- -- Target Devices: generic -- Tool versions: xst 13.1-14.7; ghdl 0.29-0.33 -- -- Revision History: -- Date Rev Version Comment -- 2016-09-02 805 1.3.3 tbcore_rlink without CLK_STOP now -- 2016-02-13 730 1.3.2 direct instantiation of tbcore_rlink -- 2016-01-03 724 1.3.1 use serport/tb/serport_master_tb -- 2015-04-12 666 1.3 use serport_master instead of serport_uart_rxtx -- 2013-10-06 538 1.2 pll support, use clksys_vcodivide ect -- 2011-12-23 444 1.1 new system clock scheme, new tbcore_rlink iface -- 2011-11-25 432 1.0 Initial version (derived from tb_nexys2_fusp) ------------------------------------------------------------------------------ library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; use ieee.std_logic_textio.all; use std.textio.all; use work.slvtypes.all; use work.rlinklib.all; use work.xlib.all; use work.nexys3lib.all; use work.simlib.all; use work.simbus.all; use work.sys_conf.all; entity tb_nexys3_fusp is end tb_nexys3_fusp; architecture sim of tb_nexys3_fusp is signal CLKOSC : slbit := '0'; -- board clock (100 Mhz) signal CLKCOM : slbit := '0'; -- communication clock signal CLKCOM_CYCLE : integer := 0; signal RESET : slbit := '0'; signal CLKDIV : slv2 := "00"; -- run with 1 clocks / bit !! signal RXDATA : slv8 := (others=>'0'); signal RXVAL : slbit := '0'; signal RXERR : slbit := '0'; signal RXACT : slbit := '0'; signal TXDATA : slv8 := (others=>'0'); signal TXENA : slbit := '0'; signal TXBUSY : slbit := '0'; signal RX_HOLD : slbit := '0'; signal I_RXD : slbit := '1'; signal O_TXD : slbit := '1'; signal I_SWI : slv8 := (others=>'0'); signal I_BTN : slv5 := (others=>'0'); signal O_LED : slv8 := (others=>'0'); signal O_ANO_N : slv4 := (others=>'0'); signal O_SEG_N : slv8 := (others=>'0'); signal O_MEM_CE_N : slbit := '1'; signal O_MEM_BE_N : slv2 := (others=>'1'); signal O_MEM_WE_N : slbit := '1'; signal O_MEM_OE_N : slbit := '1'; signal O_MEM_ADV_N : slbit := '1'; signal O_MEM_CLK : slbit := '0'; signal O_MEM_CRE : slbit := '0'; signal I_MEM_WAIT : slbit := '0'; signal O_MEM_ADDR : slv23 := (others=>'Z'); signal IO_MEM_DATA : slv16 := (others=>'0'); signal O_PPCM_CE_N : slbit := '0'; signal O_PPCM_RST_N : slbit := '0'; signal O_FUSP_RTS_N : slbit := '0'; signal I_FUSP_CTS_N : slbit := '0'; signal I_FUSP_RXD : slbit := '1'; signal O_FUSP_TXD : slbit := '1'; signal UART_RESET : slbit := '0'; signal UART_RXD : slbit := '1'; signal UART_TXD : slbit := '1'; signal CTS_N : slbit := '0'; signal RTS_N : slbit := '0'; signal R_PORTSEL_SER : slbit := '0'; -- if 1 use alternate serport signal R_PORTSEL_XON : slbit := '0'; -- if 1 use xon/xoff constant sbaddr_portsel: slv8 := slv(to_unsigned( 8,8)); constant clock_period : Delay_length := 10 ns; constant clock_offset : Delay_length := 200 ns; begin CLKGEN : simclk generic map ( PERIOD => clock_period, OFFSET => clock_offset) port map ( CLK => CLKOSC ); CLKGEN_COM : s6_cmt_sfs generic map ( VCO_DIVIDE => sys_conf_clksys_vcodivide, VCO_MULTIPLY => sys_conf_clksys_vcomultiply, OUT_DIVIDE => sys_conf_clksys_outdivide, CLKIN_PERIOD => 10.0, CLKIN_JITTER => 0.01, STARTUP_WAIT => false, GEN_TYPE => sys_conf_clksys_gentype) port map ( CLKIN => CLKOSC, CLKFX => CLKCOM, LOCKED => open ); CLKCNT : simclkcnt port map (CLK => CLKCOM, CLK_CYCLE => CLKCOM_CYCLE); TBCORE : entity work.tbcore_rlink port map ( CLK => CLKCOM, RX_DATA => TXDATA, RX_VAL => TXENA, RX_HOLD => RX_HOLD, TX_DATA => RXDATA, TX_ENA => RXVAL ); RX_HOLD <= TXBUSY or RTS_N; -- back pressure for data flow to tb N3CORE : entity work.tb_nexys3_core port map ( I_SWI => I_SWI, I_BTN => I_BTN, O_MEM_CE_N => O_MEM_CE_N, O_MEM_BE_N => O_MEM_BE_N, O_MEM_WE_N => O_MEM_WE_N, O_MEM_OE_N => O_MEM_OE_N, O_MEM_ADV_N => O_MEM_ADV_N, O_MEM_CLK => O_MEM_CLK, O_MEM_CRE => O_MEM_CRE, I_MEM_WAIT => I_MEM_WAIT, O_MEM_ADDR => O_MEM_ADDR, IO_MEM_DATA => IO_MEM_DATA ); UUT : nexys3_fusp_aif port map ( I_CLK100 => CLKOSC, I_RXD => I_RXD, O_TXD => O_TXD, I_SWI => I_SWI, I_BTN => I_BTN, O_LED => O_LED, O_ANO_N => O_ANO_N, O_SEG_N => O_SEG_N, O_MEM_CE_N => O_MEM_CE_N, O_MEM_BE_N => O_MEM_BE_N, O_MEM_WE_N => O_MEM_WE_N, O_MEM_OE_N => O_MEM_OE_N, O_MEM_ADV_N => O_MEM_ADV_N, O_MEM_CLK => O_MEM_CLK, O_MEM_CRE => O_MEM_CRE, I_MEM_WAIT => I_MEM_WAIT, O_MEM_ADDR => O_MEM_ADDR, IO_MEM_DATA => IO_MEM_DATA, O_PPCM_CE_N => O_PPCM_CE_N, O_PPCM_RST_N => O_PPCM_RST_N, O_FUSP_RTS_N => O_FUSP_RTS_N, I_FUSP_CTS_N => I_FUSP_CTS_N, I_FUSP_RXD => I_FUSP_RXD, O_FUSP_TXD => O_FUSP_TXD ); SERMSTR : entity work.serport_master_tb generic map ( CDWIDTH => CLKDIV'length) port map ( CLK => CLKCOM, RESET => UART_RESET, CLKDIV => CLKDIV, ENAXON => R_PORTSEL_XON, ENAESC => '0', RXDATA => RXDATA, RXVAL => RXVAL, RXERR => RXERR, RXOK => '1', TXDATA => TXDATA, TXENA => TXENA, TXBUSY => TXBUSY, RXSD => UART_RXD, TXSD => UART_TXD, RXRTS_N => RTS_N, TXCTS_N => CTS_N ); proc_port_mux: process (R_PORTSEL_SER, UART_TXD, CTS_N, O_TXD, O_FUSP_TXD, O_FUSP_RTS_N) begin if R_PORTSEL_SER = '0' then -- use main board rs232, no flow cntl I_RXD <= UART_TXD; -- write port 0 inputs UART_RXD <= O_TXD; -- get port 0 outputs RTS_N <= '0'; I_FUSP_RXD <= '1'; -- port 1 inputs to idle state I_FUSP_CTS_N <= '0'; else -- otherwise use pmod1 rs232 I_FUSP_RXD <= UART_TXD; -- write port 1 inputs I_FUSP_CTS_N <= CTS_N; UART_RXD <= O_FUSP_TXD; -- get port 1 outputs RTS_N <= O_FUSP_RTS_N; I_RXD <= '1'; -- port 0 inputs to idle state end if; end process proc_port_mux; proc_moni: process variable oline : line; begin loop wait until rising_edge(CLKCOM); if RXERR = '1' then writetimestamp(oline, CLKCOM_CYCLE, " : seen RXERR=1"); writeline(output, oline); end if; end loop; end process proc_moni; proc_simbus: process (SB_VAL) begin if SB_VAL'event and to_x01(SB_VAL)='1' then if SB_ADDR = sbaddr_portsel then R_PORTSEL_SER <= to_x01(SB_DATA(0)); R_PORTSEL_XON <= to_x01(SB_DATA(1)); end if; end if; end process proc_simbus; end sim;
entity repro2 is end; architecture behav of repro2 is -- AXI-Lite Interface signals type address_channel is record --DUT inputs awaddr : bit_vector; awvalid : bit; end record; type t_if is record write_channel : address_channel; end record; subtype ST_IF_32 is t_if ( write_channel ( awaddr(31 downto 0) ) ); signal s : st_if_32; begin s.write_channel.awaddr <= x"0000_1000", x"1000_ffff" after 2 ns; process begin wait for 1 ns; assert s.write_channel.awvalid = '0'; assert s.write_channel.awaddr(12) = '1'; wait for 2 ns; assert s.write_channel.awaddr(14) = '1'; wait; end process; end;
-- Copyright (C) 2001 Bill Billowitch. -- Some of the work to develop this test suite was done with Air Force -- support. The Air Force and Bill Billowitch assume no -- responsibilities for this software. -- This file is part of VESTs (Vhdl tESTs). -- VESTs is free software; you can redistribute it and/or modify it -- under the terms of the GNU General Public License as published by the -- Free Software Foundation; either version 2 of the License, or (at -- your option) any later version. -- VESTs is distributed in the hope that it will be useful, but WITHOUT -- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- for more details. -- You should have received a copy of the GNU General Public License -- along with VESTs; if not, write to the Free Software Foundation, -- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- --------------------------------------------------------------------- -- -- $Id: tc306.vhd,v 1.2 2001-10-26 16:30:25 paw Exp $ -- $Revision: 1.2 $ -- -- --------------------------------------------------------------------- ENTITY c03s01b04x00p04n01i00306ent IS END c03s01b04x00p04n01i00306ent; ARCHITECTURE c03s01b04x00p04n01i00306arch OF c03s01b04x00p04n01i00306ent IS type REAL5 is range B"000" to B"111"; -- Failure_here -- ERROR - SEMANTIC ERROR: RANGE CONSTRAINT IN FLOATING POINT TYPE -- DEFINITION MUST BE OF FLOATING POINT TYPE BEGIN TESTING: PROCESS BEGIN assert FALSE report "***FAILED TEST: c03s01b04x00p04n01i00306 - Range constraint must be floating point." severity ERROR; wait; END PROCESS TESTING; END c03s01b04x00p04n01i00306arch;
-- Copyright (C) 2001 Bill Billowitch. -- Some of the work to develop this test suite was done with Air Force -- support. The Air Force and Bill Billowitch assume no -- responsibilities for this software. -- This file is part of VESTs (Vhdl tESTs). -- VESTs is free software; you can redistribute it and/or modify it -- under the terms of the GNU General Public License as published by the -- Free Software Foundation; either version 2 of the License, or (at -- your option) any later version. -- VESTs is distributed in the hope that it will be useful, but WITHOUT -- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- for more details. -- You should have received a copy of the GNU General Public License -- along with VESTs; if not, write to the Free Software Foundation, -- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- --------------------------------------------------------------------- -- -- $Id: tc306.vhd,v 1.2 2001-10-26 16:30:25 paw Exp $ -- $Revision: 1.2 $ -- -- --------------------------------------------------------------------- ENTITY c03s01b04x00p04n01i00306ent IS END c03s01b04x00p04n01i00306ent; ARCHITECTURE c03s01b04x00p04n01i00306arch OF c03s01b04x00p04n01i00306ent IS type REAL5 is range B"000" to B"111"; -- Failure_here -- ERROR - SEMANTIC ERROR: RANGE CONSTRAINT IN FLOATING POINT TYPE -- DEFINITION MUST BE OF FLOATING POINT TYPE BEGIN TESTING: PROCESS BEGIN assert FALSE report "***FAILED TEST: c03s01b04x00p04n01i00306 - Range constraint must be floating point." severity ERROR; wait; END PROCESS TESTING; END c03s01b04x00p04n01i00306arch;
-- Copyright (C) 2001 Bill Billowitch. -- Some of the work to develop this test suite was done with Air Force -- support. The Air Force and Bill Billowitch assume no -- responsibilities for this software. -- This file is part of VESTs (Vhdl tESTs). -- VESTs is free software; you can redistribute it and/or modify it -- under the terms of the GNU General Public License as published by the -- Free Software Foundation; either version 2 of the License, or (at -- your option) any later version. -- VESTs is distributed in the hope that it will be useful, but WITHOUT -- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- for more details. -- You should have received a copy of the GNU General Public License -- along with VESTs; if not, write to the Free Software Foundation, -- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- --------------------------------------------------------------------- -- -- $Id: tc306.vhd,v 1.2 2001-10-26 16:30:25 paw Exp $ -- $Revision: 1.2 $ -- -- --------------------------------------------------------------------- ENTITY c03s01b04x00p04n01i00306ent IS END c03s01b04x00p04n01i00306ent; ARCHITECTURE c03s01b04x00p04n01i00306arch OF c03s01b04x00p04n01i00306ent IS type REAL5 is range B"000" to B"111"; -- Failure_here -- ERROR - SEMANTIC ERROR: RANGE CONSTRAINT IN FLOATING POINT TYPE -- DEFINITION MUST BE OF FLOATING POINT TYPE BEGIN TESTING: PROCESS BEGIN assert FALSE report "***FAILED TEST: c03s01b04x00p04n01i00306 - Range constraint must be floating point." severity ERROR; wait; END PROCESS TESTING; END c03s01b04x00p04n01i00306arch;
library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; package mux_types_pkg is type mux_input_t is array(natural range <>) of std_logic_vector; end package; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; library work; use work.constants.all; use work.mux_types_pkg.all; entity mux is generic( WIDTH: integer := XLEN; PORTS: integer := 2 ); port( I_inputs: in mux_input_t(PORTS-1 downto 0)(WIDTH-1 downto 0); I_sel: in integer range 0 to PORTS-1; O_output: out std_logic_vector(WIDTH-1 downto 0) ); end mux; architecture Behavioral of mux is begin O_output <= I_inputs(I_sel); end Behavioral;
-- -- BananaCore - A processor written in VHDL -- -- Created by Rogiel Sulzbach. -- Copyright (c) 2014-2015 Rogiel Sulzbach. All rights reserved. -- library ieee; use ieee.numeric_std.all; use ieee.std_logic_1164.all; use ieee.std_logic_1164.std_logic; library BananaCore; use BananaCore.Core.all; use BananaCore.Memory.all; use BananaCore.RegisterPackage.all; -- The BitwiseOrInstructionExecutor entity entity BitwiseOrInstructionExecutor is port( -- the processor main clock clock: in BananaCore.Core.Clock; -- enables the instruction enable: in std_logic; -- the first register to operate on (argument 0) arg0_address: in RegisterAddress; -- the first register to operate on (argument 1) arg1_address: in RegisterAddress; -- a bus indicating if the instruction is ready or not instruction_ready: out std_logic := '0'; ------------------------------------------ -- MEMORY BUS ------------------------------------------ -- the address to read/write memory from/to memory_address: out MemoryAddress := (others => '0'); -- the memory being read to memory_data_read: in MemoryData; -- the memory being written to memory_data_write: out MemoryData := (others => '0'); -- the operation to perform on the memory memory_operation: out MemoryOperation := MEMORY_OP_DISABLED; -- a flag indicating if a memory operation should be performed memory_enable: out std_logic; -- a flag indicating if a memory operation has completed memory_ready: in std_logic; ------------------------------------------ -- REGISTER BUS ------------------------------------------ -- the processor register address bus register_address: out RegisterAddress := (others => '0'); -- the processor register data bus register_data_read: in RegisterData; -- the processor register data bus register_data_write: out RegisterData := (others => '0'); -- the processor register operation signal register_operation: out RegisterOperation := OP_REG_DISABLED; -- the processor register enable signal register_enable: out std_logic := '0'; -- a flag indicating if a register operation has completed register_ready: in std_logic ); end BitwiseOrInstructionExecutor; architecture BitwiseOrInstructionExecutorImpl of BitwiseOrInstructionExecutor is type state_type is ( fetch_arg0, store_arg0, fetch_arg1, store_arg1, execute, store_result, complete ); signal state: state_type := fetch_arg0; signal arg0: RegisterData; signal arg1: RegisterData; signal result: RegisterData; begin process (clock) begin if clock'event and clock = '1' then if enable = '1' then case state is when fetch_arg0 => instruction_ready <= '0'; register_address <= arg0_address; register_operation <= OP_REG_GET; register_enable <= '1'; state <= store_arg0; when store_arg0 => if register_ready = '1' then arg0 <= register_data_read; register_enable <= '0'; state <= fetch_arg1; else state <= store_arg0; end if; when fetch_arg1 => register_address <= arg1_address; register_operation <= OP_REG_GET; register_enable <= '1'; state <= store_arg1; when store_arg1 => if register_ready = '1' then arg1 <= register_data_read; register_enable <= '0'; state <= execute; else state <= store_arg1; end if; when execute => result <= arg0 or arg1; state <= store_result; when store_result => register_address <= AccumulatorRegister; register_operation <= OP_REG_SET; register_data_write <= result; register_enable <= '1'; instruction_ready <= '1'; state <= complete; when complete => state <= complete; end case; else instruction_ready <= '0'; state <= fetch_arg0; end if; end if; end process; end BitwiseOrInstructionExecutorImpl;
-- ____ _ _ -- / ___| ___ _ _ _ __ __| | __ _ __ _| |_ ___ ___ -- \___ \ / _ \| | | | '_ \ / _` |/ _` |/ _` | __/ _ \/ __| -- ___) | (_) | |_| | | | | (_| | (_| | (_| | || __/\__ \ -- |____/ \___/ \__,_|_| |_|\__,_|\__, |\__,_|\__\___||___/ -- |___/ -- ====================================================================== -- -- title: VHDL module - hwt_sawtooth -- -- project: PG-Soundgates -- author: Hendrik Hangmann, University of Paderborn -- -- description: Hardware thread for a sawtooth wave -- -- ====================================================================== library ieee; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; --library proc_common_v3_00_a; --use proc_common_v3_00_a.proc_common_pkg.all; library reconos_v3_00_c; use reconos_v3_00_c.reconos_pkg.all; library soundgates_v1_00_a; use soundgates_v1_00_a.soundgates_common_pkg.all; use soundgates_v1_00_a.soundgates_reconos_pkg.all; entity hwt_sawtooth is generic( SND_COMP_CLK_FREQ : integer := 100_000_000 ); port ( -- OSIF FIFO ports OSIF_FIFO_Sw2Hw_Data : in std_logic_vector(31 downto 0); OSIF_FIFO_Sw2Hw_Fill : in std_logic_vector(15 downto 0); OSIF_FIFO_Sw2Hw_Empty : in std_logic; OSIF_FIFO_Sw2Hw_RE : out std_logic; OSIF_FIFO_Hw2Sw_Data : out std_logic_vector(31 downto 0); OSIF_FIFO_Hw2Sw_Rem : in std_logic_vector(15 downto 0); OSIF_FIFO_Hw2Sw_Full : in std_logic; OSIF_FIFO_Hw2Sw_WE : out std_logic; -- MEMIF FIFO ports MEMIF_FIFO_Hwt2Mem_Data : out std_logic_vector(31 downto 0); MEMIF_FIFO_Hwt2Mem_Rem : in std_logic_vector(15 downto 0); MEMIF_FIFO_Hwt2Mem_Full : in std_logic; MEMIF_FIFO_Hwt2Mem_WE : out std_logic; MEMIF_FIFO_Mem2Hwt_Data : in std_logic_vector(31 downto 0); MEMIF_FIFO_Mem2Hwt_Fill : in std_logic_vector(15 downto 0); MEMIF_FIFO_Mem2Hwt_Empty : in std_logic; MEMIF_FIFO_Mem2Hwt_RE : out std_logic; HWT_Clk : in std_logic; HWT_Rst : in std_logic ); end hwt_sawtooth; architecture Behavioral of hwt_sawtooth is ---------------------------------------------------------------- -- Subcomponent declarations ---------------------------------------------------------------- component sawtooth is port( clk : in std_logic; rst : in std_logic; ce : in std_logic; incr : in signed(31 downto 0); offset : in signed(31 downto 0); saw : out signed(31 downto 0) ); end component; signal clk : std_logic; signal rst : std_logic; -- ReconOS Stuff signal i_osif : i_osif_t; signal o_osif : o_osif_t; signal i_memif : i_memif_t; signal o_memif : o_memif_t; signal i_ram : i_ram_t; signal o_ram : o_ram_t; constant MBOX_START : std_logic_vector(31 downto 0) := x"00000000"; constant MBOX_FINISH : std_logic_vector(31 downto 0) := x"00000001"; -- /ReconOS Stuff type STATE_TYPE is (STATE_INIT, STATE_WAITING, STATE_REFRESH_INPUT_PHASE_OFFSET, STATE_REFRESH_INPUT_PHASE_INCR, STATE_PROCESS, STATE_WRITE_MEM, STATE_NOTIFY, STATE_EXIT); signal state : STATE_TYPE; ---------------------------------------------------------------- -- Common sound component signals, constants and types ---------------------------------------------------------------- constant C_MAX_SAMPLE_COUNT : integer := 64; -- define size of local RAM here constant C_LOCAL_RAM_SIZE : integer := C_MAX_SAMPLE_COUNT; constant C_LOCAL_RAM_ADDRESS_WIDTH : integer := 6;--clog2(C_LOCAL_RAM_SIZE); constant C_LOCAL_RAM_SIZE_IN_BYTES : integer := 4*C_LOCAL_RAM_SIZE; type LOCAL_MEMORY_T is array (0 to C_LOCAL_RAM_SIZE-1) of std_logic_vector(31 downto 0); signal o_RAMAddr_saw : std_logic_vector(0 to C_LOCAL_RAM_ADDRESS_WIDTH-1); signal o_RAMData_saw : std_logic_vector(0 to 31); -- saw to local ram signal i_RAMData_saw : std_logic_vector(0 to 31); -- local ram to saw signal o_RAMWE_saw : std_logic; signal o_RAMAddr_reconos : std_logic_vector(0 to C_LOCAL_RAM_ADDRESS_WIDTH-1); signal o_RAMAddr_reconos_2 : std_logic_vector(0 to 31); signal o_RAMData_reconos : std_logic_vector(0 to 31); signal o_RAMWE_reconos : std_logic; signal i_RAMData_reconos : std_logic_vector(0 to 31); signal osif_ctrl_signal : std_logic_vector(31 downto 0); signal ignore : std_logic_vector(31 downto 0); constant o_RAMAddr_max : std_logic_vector(0 to C_LOCAL_RAM_ADDRESS_WIDTH-1) := (others=>'1'); shared variable local_ram : LOCAL_MEMORY_T; signal snd_comp_header : snd_comp_header_msg_t; -- common sound component header signal sample_count : unsigned(15 downto 0) := to_unsigned(C_MAX_SAMPLE_COUNT, 16); ---------------------------------------------------------------- -- Component dependent signals ---------------------------------------------------------------- signal saw_ce : std_logic; -- saw clock enable (like a start/stop signal) signal phase_offset_addr : std_logic_vector(31 downto 0); signal phase_incr_addr : std_logic_vector(31 downto 0); signal phase_offset : std_logic_vector(31 downto 0); signal phase_incr : std_logic_vector(31 downto 0); signal saw_data : signed(31 downto 0); signal state_inner_process : std_logic; ---------------------------------------------------------------- -- OS Communication ---------------------------------------------------------------- constant saw_START : std_logic_vector(31 downto 0) := x"0000000F"; constant saw_EXIT : std_logic_vector(31 downto 0) := x"000000F0"; begin ----------------------------------- -- Hard wirings ----------------------------------- clk <= HWT_Clk; rst <= HWT_Rst; o_RAMData_saw <= std_logic_vector(saw_data); o_RAMAddr_reconos(0 to C_LOCAL_RAM_ADDRESS_WIDTH-1) <= o_RAMAddr_reconos_2((32-C_LOCAL_RAM_ADDRESS_WIDTH) to 31); -- ReconOS Stuff osif_setup ( i_osif, o_osif, OSIF_FIFO_Sw2Hw_Data, OSIF_FIFO_Sw2Hw_Fill, OSIF_FIFO_Sw2Hw_Empty, OSIF_FIFO_Hw2Sw_Rem, OSIF_FIFO_Hw2Sw_Full, OSIF_FIFO_Sw2Hw_RE, OSIF_FIFO_Hw2Sw_Data, OSIF_FIFO_Hw2Sw_WE ); memif_setup ( i_memif, o_memif, MEMIF_FIFO_Mem2Hwt_Data, MEMIF_FIFO_Mem2Hwt_Fill, MEMIF_FIFO_Mem2Hwt_Empty, MEMIF_FIFO_Hwt2Mem_Rem, MEMIF_FIFO_Hwt2Mem_Full, MEMIF_FIFO_Mem2Hwt_RE, MEMIF_FIFO_Hwt2Mem_Data, MEMIF_FIFO_Hwt2Mem_WE ); ram_setup ( i_ram, o_ram, o_RAMAddr_reconos_2, o_RAMWE_reconos, o_RAMData_reconos, i_RAMData_reconos ); -- /ReconOS Stuff saw_inst : sawtooth port map( clk => clk, rst => rst, ce => saw_ce, incr => signed(phase_incr), offset => signed(phase_offset), saw => saw_data ); local_ram_ctrl_1 : process (clk) is begin if (rising_edge(clk)) then if (o_RAMWE_reconos = '1') then local_ram(to_integer(unsigned(o_RAMAddr_reconos))) := o_RAMData_reconos; else i_RAMData_reconos <= local_ram(to_integer(unsigned(o_RAMAddr_reconos))); end if; end if; end process; local_ram_ctrl_2 : process (clk) is begin if (rising_edge(clk)) then if (o_RAMWE_saw = '1') then local_ram(to_integer(unsigned(o_RAMAddr_saw))) := o_RAMData_saw; --else -- else not needed, because saw is not consuming any samples -- i_RAMData_saw <= local_ram(conv_integer(unsigned(o_RAMAddr_saw))); end if; end if; end process; saw_CTRL_FSM_PROC : process (clk, rst, o_osif, o_memif) is variable done : boolean; begin if rst = '1' then osif_reset(o_osif); memif_reset(o_memif); ram_reset(o_ram); state <= STATE_INIT; sample_count <= to_unsigned(C_MAX_SAMPLE_COUNT, 16); osif_ctrl_signal <= (others => '0'); saw_ce <= '0'; o_RAMWE_saw <= '0'; state_inner_process <= '0'; done := False; elsif rising_edge(clk) then saw_ce <= '0'; o_RAMWE_saw <= '0'; osif_ctrl_signal <= ( others => '0'); case state is -- INIT State gets the address of the header struct when STATE_INIT => snd_comp_get_header(i_osif, o_osif, i_memif, o_memif, snd_comp_header, done); if done then -- Initialize your signals phase_offset_addr <= snd_comp_header.opt_arg_addr; phase_incr_addr <= std_logic_vector(unsigned(snd_comp_header.opt_arg_addr) + 4); state <= STATE_WAITING; end if; when STATE_WAITING => -- Software process "Synthesizer" sends the start signal via mbox_start osif_mbox_get(i_osif, o_osif, MBOX_START, osif_ctrl_signal, done); if done then if osif_ctrl_signal = saw_START then sample_count <= to_unsigned(C_MAX_SAMPLE_COUNT, 16); state <= STATE_REFRESH_INPUT_PHASE_OFFSET; elsif osif_ctrl_signal = saw_EXIT then state <= STATE_EXIT; end if; end if; when STATE_REFRESH_INPUT_PHASE_OFFSET => memif_read_word(i_memif, o_memif, phase_offset_addr, phase_offset, done); if done then state <= STATE_REFRESH_INPUT_PHASE_INCR; end if; when STATE_REFRESH_INPUT_PHASE_INCR => memif_read_word(i_memif, o_memif, phase_incr_addr, phase_incr, done); if done then state <= STATE_PROCESS; end if; when STATE_PROCESS => if sample_count > 0 then case state_inner_process is when '0' => o_RAMWE_saw <= '1'; saw_ce <= '1'; -- ein takt früher state_inner_process <= '1'; when '1' => o_RAMAddr_saw <= std_logic_vector(unsigned(o_RAMAddr_saw) + 1); sample_count <= sample_count - 1; state_inner_process <= '0'; when others => state_inner_process <= '0'; end case; else -- Samples have been generated o_RAMAddr_saw <= (others => '0'); state <= STATE_WRITE_MEM; end if; when STATE_WRITE_MEM => memif_write(i_ram, o_ram, i_memif, o_memif, X"00000000", snd_comp_header.dest_addr, std_logic_vector(to_unsigned(C_LOCAL_RAM_SIZE_IN_BYTES,24)), done); if done then state <= STATE_NOTIFY; end if; when STATE_NOTIFY => osif_mbox_put(i_osif, o_osif, MBOX_FINISH, snd_comp_header.dest_addr, ignore, done); if done then state <= STATE_WAITING; end if; when STATE_EXIT => osif_thread_exit(i_osif,o_osif); end case; end if; end process; end Behavioral; -- ==================================== -- = RECONOS Function Library - Copy and Paste! -- ==================================== -- osif_mbox_put(i_osif, o_osif, MBOX_NAME, SOURCESIGNAL, ignore, done); -- osif_mbox_get(i_osif, o_osif, MBOX_NAME, TARGETSIGNAL, done); -- Read from shared memory: -- Speicherzugriffe: -- Wortzugriff: -- memif_read_word(i_memif, o_memif, addr, TARGETSIGNAL, done); -- memif_write_word(i_memif, o_memif, addr, SOURCESIGNAL, done); -- Die Laenge ist bei Speicherzugriffen Byte adressiert! -- memif_read(i_ram, o_ram, i_memif, o_memif, SRC_ADDR std_logic_vector(31 downto 0); -- dst_addr std_logic_vector(31 downto 0); -- BYTES std_logic_vector(23 downto 0); -- done); -- memif_write(i_ram, o_ram, i_memif, o_memif, -- src_addr : in std_logic_vector(31 downto 0), -- dst_addr : in std_logic_vector(31 downto 0); -- len : in std_logic_vector(23 downto 0); -- done);
-- megafunction wizard: %RAM: 1-PORT% -- GENERATION: STANDARD -- VERSION: WM1.0 -- MODULE: altsyncram -- ============================================================ -- File Name: ram_dq_PHASE_k.vhd -- Megafunction Name(s): -- altsyncram -- -- Simulation Library Files(s): -- altera_mf -- ============================================================ -- ************************************************************ -- THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE! -- -- 12.1 Build 243 01/31/2013 SP 1 SJ Full Version -- ************************************************************ --Copyright (C) 1991-2012 Altera Corporation --Your use of Altera Corporation's design tools, logic functions --and other software and tools, and its AMPP partner logic --functions, and any output files from any of the foregoing --(including device programming or simulation files), and any --associated documentation or information are expressly subject --to the terms and conditions of the Altera Program License --Subscription Agreement, Altera MegaCore Function License --Agreement, or other applicable license agreement, including, --without limitation, that your use is for the sole purpose of --programming logic devices manufactured by Altera and sold by --Altera or its authorized distributors. Please refer to the --applicable agreement for further details. LIBRARY ieee; USE ieee.std_logic_1164.all; LIBRARY altera_mf; USE altera_mf.all; ENTITY ram_dq_PHASE_k IS PORT ( address : IN STD_LOGIC_VECTOR (4 DOWNTO 0); clock : IN STD_LOGIC := '1'; data : IN STD_LOGIC_VECTOR (7 DOWNTO 0); wren : IN STD_LOGIC ; q : OUT STD_LOGIC_VECTOR (7 DOWNTO 0) ); END ram_dq_PHASE_k; ARCHITECTURE SYN OF ram_dq_phase_k IS SIGNAL sub_wire0 : STD_LOGIC_VECTOR (7 DOWNTO 0); COMPONENT altsyncram GENERIC ( clock_enable_input_a : STRING; clock_enable_output_a : STRING; intended_device_family : STRING; lpm_hint : STRING; lpm_type : STRING; numwords_a : NATURAL; operation_mode : STRING; outdata_aclr_a : STRING; outdata_reg_a : STRING; power_up_uninitialized : STRING; read_during_write_mode_port_a : STRING; widthad_a : NATURAL; width_a : NATURAL; width_byteena_a : NATURAL ); PORT ( address_a : IN STD_LOGIC_VECTOR (4 DOWNTO 0); clock0 : IN STD_LOGIC ; data_a : IN STD_LOGIC_VECTOR (7 DOWNTO 0); wren_a : IN STD_LOGIC ; q_a : OUT STD_LOGIC_VECTOR (7 DOWNTO 0) ); END COMPONENT; BEGIN q <= sub_wire0(7 DOWNTO 0); altsyncram_component : altsyncram GENERIC MAP ( clock_enable_input_a => "BYPASS", clock_enable_output_a => "BYPASS", intended_device_family => "Cyclone III", lpm_hint => "ENABLE_RUNTIME_MOD=YES,INSTANCE_NAME=PH_K", lpm_type => "altsyncram", numwords_a => 32, operation_mode => "SINGLE_PORT", outdata_aclr_a => "NONE", outdata_reg_a => "CLOCK0", power_up_uninitialized => "FALSE", read_during_write_mode_port_a => "NEW_DATA_NO_NBE_READ", widthad_a => 5, width_a => 8, width_byteena_a => 1 ) PORT MAP ( address_a => address, clock0 => clock, data_a => data, wren_a => wren, q_a => sub_wire0 ); END SYN; -- ============================================================ -- CNX file retrieval info -- ============================================================ -- Retrieval info: PRIVATE: ADDRESSSTALL_A NUMERIC "0" -- Retrieval info: PRIVATE: AclrAddr NUMERIC "0" -- Retrieval info: PRIVATE: AclrByte NUMERIC "0" -- Retrieval info: PRIVATE: AclrData NUMERIC "0" -- Retrieval info: PRIVATE: AclrOutput NUMERIC "0" -- Retrieval info: PRIVATE: BYTE_ENABLE NUMERIC "0" -- Retrieval info: PRIVATE: BYTE_SIZE NUMERIC "8" -- Retrieval info: PRIVATE: BlankMemory NUMERIC "1" -- Retrieval info: PRIVATE: CLOCK_ENABLE_INPUT_A NUMERIC "0" -- Retrieval info: PRIVATE: CLOCK_ENABLE_OUTPUT_A NUMERIC "0" -- Retrieval info: PRIVATE: Clken NUMERIC "0" -- Retrieval info: PRIVATE: DataBusSeparated NUMERIC "1" -- Retrieval info: PRIVATE: IMPLEMENT_IN_LES NUMERIC "0" -- Retrieval info: PRIVATE: INIT_FILE_LAYOUT STRING "PORT_A" -- Retrieval info: PRIVATE: INIT_TO_SIM_X NUMERIC "0" -- Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING "Cyclone III" -- Retrieval info: PRIVATE: JTAG_ENABLED NUMERIC "1" -- Retrieval info: PRIVATE: JTAG_ID STRING "PH_K" -- Retrieval info: PRIVATE: MAXIMUM_DEPTH NUMERIC "0" -- Retrieval info: PRIVATE: MIFfilename STRING "" -- Retrieval info: PRIVATE: NUMWORDS_A NUMERIC "32" -- Retrieval info: PRIVATE: RAM_BLOCK_TYPE NUMERIC "0" -- Retrieval info: PRIVATE: READ_DURING_WRITE_MODE_PORT_A NUMERIC "3" -- Retrieval info: PRIVATE: RegAddr NUMERIC "1" -- Retrieval info: PRIVATE: RegData NUMERIC "1" -- Retrieval info: PRIVATE: RegOutput NUMERIC "1" -- Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING "0" -- Retrieval info: PRIVATE: SingleClock NUMERIC "1" -- Retrieval info: PRIVATE: UseDQRAM NUMERIC "1" -- Retrieval info: PRIVATE: WRCONTROL_ACLR_A NUMERIC "0" -- Retrieval info: PRIVATE: WidthAddr NUMERIC "5" -- Retrieval info: PRIVATE: WidthData NUMERIC "8" -- Retrieval info: PRIVATE: rden NUMERIC "0" -- Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all -- Retrieval info: CONSTANT: CLOCK_ENABLE_INPUT_A STRING "BYPASS" -- Retrieval info: CONSTANT: CLOCK_ENABLE_OUTPUT_A STRING "BYPASS" -- Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING "Cyclone III" -- Retrieval info: CONSTANT: LPM_HINT STRING "ENABLE_RUNTIME_MOD=YES,INSTANCE_NAME=PH_K" -- Retrieval info: CONSTANT: LPM_TYPE STRING "altsyncram" -- Retrieval info: CONSTANT: NUMWORDS_A NUMERIC "32" -- Retrieval info: CONSTANT: OPERATION_MODE STRING "SINGLE_PORT" -- Retrieval info: CONSTANT: OUTDATA_ACLR_A STRING "NONE" -- Retrieval info: CONSTANT: OUTDATA_REG_A STRING "CLOCK0" -- Retrieval info: CONSTANT: POWER_UP_UNINITIALIZED STRING "FALSE" -- Retrieval info: CONSTANT: READ_DURING_WRITE_MODE_PORT_A STRING "NEW_DATA_NO_NBE_READ" -- Retrieval info: CONSTANT: WIDTHAD_A NUMERIC "5" -- Retrieval info: CONSTANT: WIDTH_A NUMERIC "8" -- Retrieval info: CONSTANT: WIDTH_BYTEENA_A NUMERIC "1" -- Retrieval info: USED_PORT: address 0 0 5 0 INPUT NODEFVAL "address[4..0]" -- Retrieval info: USED_PORT: clock 0 0 0 0 INPUT VCC "clock" -- Retrieval info: USED_PORT: data 0 0 8 0 INPUT NODEFVAL "data[7..0]" -- Retrieval info: USED_PORT: q 0 0 8 0 OUTPUT NODEFVAL "q[7..0]" -- Retrieval info: USED_PORT: wren 0 0 0 0 INPUT NODEFVAL "wren" -- Retrieval info: CONNECT: @address_a 0 0 5 0 address 0 0 5 0 -- Retrieval info: CONNECT: @clock0 0 0 0 0 clock 0 0 0 0 -- Retrieval info: CONNECT: @data_a 0 0 8 0 data 0 0 8 0 -- Retrieval info: CONNECT: @wren_a 0 0 0 0 wren 0 0 0 0 -- Retrieval info: CONNECT: q 0 0 8 0 @q_a 0 0 8 0 -- Retrieval info: GEN_FILE: TYPE_NORMAL ram_dq_PHASE_k.vhd TRUE -- Retrieval info: GEN_FILE: TYPE_NORMAL ram_dq_PHASE_k.inc FALSE -- Retrieval info: GEN_FILE: TYPE_NORMAL ram_dq_PHASE_k.cmp TRUE -- Retrieval info: GEN_FILE: TYPE_NORMAL ram_dq_PHASE_k.bsf TRUE FALSE -- Retrieval info: GEN_FILE: TYPE_NORMAL ram_dq_PHASE_k_inst.vhd FALSE -- Retrieval info: LIB_FILE: altera_mf
-- megafunction wizard: %RAM: 1-PORT% -- GENERATION: STANDARD -- VERSION: WM1.0 -- MODULE: altsyncram -- ============================================================ -- File Name: ram_dq_PHASE_k.vhd -- Megafunction Name(s): -- altsyncram -- -- Simulation Library Files(s): -- altera_mf -- ============================================================ -- ************************************************************ -- THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE! -- -- 12.1 Build 243 01/31/2013 SP 1 SJ Full Version -- ************************************************************ --Copyright (C) 1991-2012 Altera Corporation --Your use of Altera Corporation's design tools, logic functions --and other software and tools, and its AMPP partner logic --functions, and any output files from any of the foregoing --(including device programming or simulation files), and any --associated documentation or information are expressly subject --to the terms and conditions of the Altera Program License --Subscription Agreement, Altera MegaCore Function License --Agreement, or other applicable license agreement, including, --without limitation, that your use is for the sole purpose of --programming logic devices manufactured by Altera and sold by --Altera or its authorized distributors. Please refer to the --applicable agreement for further details. LIBRARY ieee; USE ieee.std_logic_1164.all; LIBRARY altera_mf; USE altera_mf.all; ENTITY ram_dq_PHASE_k IS PORT ( address : IN STD_LOGIC_VECTOR (4 DOWNTO 0); clock : IN STD_LOGIC := '1'; data : IN STD_LOGIC_VECTOR (7 DOWNTO 0); wren : IN STD_LOGIC ; q : OUT STD_LOGIC_VECTOR (7 DOWNTO 0) ); END ram_dq_PHASE_k; ARCHITECTURE SYN OF ram_dq_phase_k IS SIGNAL sub_wire0 : STD_LOGIC_VECTOR (7 DOWNTO 0); COMPONENT altsyncram GENERIC ( clock_enable_input_a : STRING; clock_enable_output_a : STRING; intended_device_family : STRING; lpm_hint : STRING; lpm_type : STRING; numwords_a : NATURAL; operation_mode : STRING; outdata_aclr_a : STRING; outdata_reg_a : STRING; power_up_uninitialized : STRING; read_during_write_mode_port_a : STRING; widthad_a : NATURAL; width_a : NATURAL; width_byteena_a : NATURAL ); PORT ( address_a : IN STD_LOGIC_VECTOR (4 DOWNTO 0); clock0 : IN STD_LOGIC ; data_a : IN STD_LOGIC_VECTOR (7 DOWNTO 0); wren_a : IN STD_LOGIC ; q_a : OUT STD_LOGIC_VECTOR (7 DOWNTO 0) ); END COMPONENT; BEGIN q <= sub_wire0(7 DOWNTO 0); altsyncram_component : altsyncram GENERIC MAP ( clock_enable_input_a => "BYPASS", clock_enable_output_a => "BYPASS", intended_device_family => "Cyclone III", lpm_hint => "ENABLE_RUNTIME_MOD=YES,INSTANCE_NAME=PH_K", lpm_type => "altsyncram", numwords_a => 32, operation_mode => "SINGLE_PORT", outdata_aclr_a => "NONE", outdata_reg_a => "CLOCK0", power_up_uninitialized => "FALSE", read_during_write_mode_port_a => "NEW_DATA_NO_NBE_READ", widthad_a => 5, width_a => 8, width_byteena_a => 1 ) PORT MAP ( address_a => address, clock0 => clock, data_a => data, wren_a => wren, q_a => sub_wire0 ); END SYN; -- ============================================================ -- CNX file retrieval info -- ============================================================ -- Retrieval info: PRIVATE: ADDRESSSTALL_A NUMERIC "0" -- Retrieval info: PRIVATE: AclrAddr NUMERIC "0" -- Retrieval info: PRIVATE: AclrByte NUMERIC "0" -- Retrieval info: PRIVATE: AclrData NUMERIC "0" -- Retrieval info: PRIVATE: AclrOutput NUMERIC "0" -- Retrieval info: PRIVATE: BYTE_ENABLE NUMERIC "0" -- Retrieval info: PRIVATE: BYTE_SIZE NUMERIC "8" -- Retrieval info: PRIVATE: BlankMemory NUMERIC "1" -- Retrieval info: PRIVATE: CLOCK_ENABLE_INPUT_A NUMERIC "0" -- Retrieval info: PRIVATE: CLOCK_ENABLE_OUTPUT_A NUMERIC "0" -- Retrieval info: PRIVATE: Clken NUMERIC "0" -- Retrieval info: PRIVATE: DataBusSeparated NUMERIC "1" -- Retrieval info: PRIVATE: IMPLEMENT_IN_LES NUMERIC "0" -- Retrieval info: PRIVATE: INIT_FILE_LAYOUT STRING "PORT_A" -- Retrieval info: PRIVATE: INIT_TO_SIM_X NUMERIC "0" -- Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING "Cyclone III" -- Retrieval info: PRIVATE: JTAG_ENABLED NUMERIC "1" -- Retrieval info: PRIVATE: JTAG_ID STRING "PH_K" -- Retrieval info: PRIVATE: MAXIMUM_DEPTH NUMERIC "0" -- Retrieval info: PRIVATE: MIFfilename STRING "" -- Retrieval info: PRIVATE: NUMWORDS_A NUMERIC "32" -- Retrieval info: PRIVATE: RAM_BLOCK_TYPE NUMERIC "0" -- Retrieval info: PRIVATE: READ_DURING_WRITE_MODE_PORT_A NUMERIC "3" -- Retrieval info: PRIVATE: RegAddr NUMERIC "1" -- Retrieval info: PRIVATE: RegData NUMERIC "1" -- Retrieval info: PRIVATE: RegOutput NUMERIC "1" -- Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING "0" -- Retrieval info: PRIVATE: SingleClock NUMERIC "1" -- Retrieval info: PRIVATE: UseDQRAM NUMERIC "1" -- Retrieval info: PRIVATE: WRCONTROL_ACLR_A NUMERIC "0" -- Retrieval info: PRIVATE: WidthAddr NUMERIC "5" -- Retrieval info: PRIVATE: WidthData NUMERIC "8" -- Retrieval info: PRIVATE: rden NUMERIC "0" -- Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all -- Retrieval info: CONSTANT: CLOCK_ENABLE_INPUT_A STRING "BYPASS" -- Retrieval info: CONSTANT: CLOCK_ENABLE_OUTPUT_A STRING "BYPASS" -- Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING "Cyclone III" -- Retrieval info: CONSTANT: LPM_HINT STRING "ENABLE_RUNTIME_MOD=YES,INSTANCE_NAME=PH_K" -- Retrieval info: CONSTANT: LPM_TYPE STRING "altsyncram" -- Retrieval info: CONSTANT: NUMWORDS_A NUMERIC "32" -- Retrieval info: CONSTANT: OPERATION_MODE STRING "SINGLE_PORT" -- Retrieval info: CONSTANT: OUTDATA_ACLR_A STRING "NONE" -- Retrieval info: CONSTANT: OUTDATA_REG_A STRING "CLOCK0" -- Retrieval info: CONSTANT: POWER_UP_UNINITIALIZED STRING "FALSE" -- Retrieval info: CONSTANT: READ_DURING_WRITE_MODE_PORT_A STRING "NEW_DATA_NO_NBE_READ" -- Retrieval info: CONSTANT: WIDTHAD_A NUMERIC "5" -- Retrieval info: CONSTANT: WIDTH_A NUMERIC "8" -- Retrieval info: CONSTANT: WIDTH_BYTEENA_A NUMERIC "1" -- Retrieval info: USED_PORT: address 0 0 5 0 INPUT NODEFVAL "address[4..0]" -- Retrieval info: USED_PORT: clock 0 0 0 0 INPUT VCC "clock" -- Retrieval info: USED_PORT: data 0 0 8 0 INPUT NODEFVAL "data[7..0]" -- Retrieval info: USED_PORT: q 0 0 8 0 OUTPUT NODEFVAL "q[7..0]" -- Retrieval info: USED_PORT: wren 0 0 0 0 INPUT NODEFVAL "wren" -- Retrieval info: CONNECT: @address_a 0 0 5 0 address 0 0 5 0 -- Retrieval info: CONNECT: @clock0 0 0 0 0 clock 0 0 0 0 -- Retrieval info: CONNECT: @data_a 0 0 8 0 data 0 0 8 0 -- Retrieval info: CONNECT: @wren_a 0 0 0 0 wren 0 0 0 0 -- Retrieval info: CONNECT: q 0 0 8 0 @q_a 0 0 8 0 -- Retrieval info: GEN_FILE: TYPE_NORMAL ram_dq_PHASE_k.vhd TRUE -- Retrieval info: GEN_FILE: TYPE_NORMAL ram_dq_PHASE_k.inc FALSE -- Retrieval info: GEN_FILE: TYPE_NORMAL ram_dq_PHASE_k.cmp TRUE -- Retrieval info: GEN_FILE: TYPE_NORMAL ram_dq_PHASE_k.bsf TRUE FALSE -- Retrieval info: GEN_FILE: TYPE_NORMAL ram_dq_PHASE_k_inst.vhd FALSE -- Retrieval info: LIB_FILE: altera_mf
--------------------------------------------------------------------------- -- -- Title: Hardware Thread User Logic Exit Thread -- To be used as a place holder, and size estimate for HWTI -- --------------------------------------------------------------------------- library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; use IEEE.std_logic_misc.all; library Unisim; use Unisim.all; --------------------------------------------------------------------------- -- Port declarations --------------------------------------------------------------------------- -- Definition of Ports: -- -- Misc. Signals -- clock -- -- HWTI to HWTUL interconnect -- intrfc2thrd_address 32 bits memory -- intrfc2thrd_value 32 bits memory function -- intrfc2thrd_function 16 bits control -- intrfc2thrd_goWait 1 bits control -- -- HWTUL to HWTI interconnect -- thrd2intrfc_address 32 bits memory -- thrd2intrfc_value 32 bits memory function -- thrd2intrfc_function 16 bits function -- thrd2intrfc_opcode 6 bits memory function -- --------------------------------------------------------------------------- -- Thread Manager Entity section --------------------------------------------------------------------------- entity user_logic_hwtul is port ( clock : in std_logic; intrfc2thrd_address : in std_logic_vector(0 to 31); intrfc2thrd_value : in std_logic_vector(0 to 31); intrfc2thrd_function : in std_logic_vector(0 to 15); intrfc2thrd_goWait : in std_logic; thrd2intrfc_address : out std_logic_vector(0 to 31); thrd2intrfc_value : out std_logic_vector(0 to 31); thrd2intrfc_function : out std_logic_vector(0 to 15); thrd2intrfc_opcode : out std_logic_vector(0 to 5) ); end entity user_logic_hwtul; --------------------------------------------------------------------------- -- Architecture section --------------------------------------------------------------------------- architecture IMP of user_logic_hwtul is --------------------------------------------------------------------------- -- Signal declarations --------------------------------------------------------------------------- type state_machine is ( FUNCTION_RESET, FUNCTION_USER_SELECT, FUNCTION_START, FUNCTION_EXIT, STATE_1, STATE_2, STATE_3, STATE_4, STATE_5, STATE_6, STATE_7, STATE_8, STATE_9, STATE_10, STATE_11, STATE_12, STATE_13, STATE_14, STATE_15, STATE_16, STATE_17, STATE_18, STATE_19, STATE_20, WAIT_STATE, ERROR_STATE); -- Function definitions constant U_FUNCTION_RESET : std_logic_vector(0 to 15) := x"0000"; constant U_FUNCTION_WAIT : std_logic_vector(0 to 15) := x"0001"; constant U_FUNCTION_USER_SELECT : std_logic_vector(0 to 15) := x"0002"; constant U_FUNCTION_START : std_logic_vector(0 to 15) := x"0003"; constant U_STATE_1 : std_logic_vector(0 to 15) := x"0101"; constant U_STATE_2 : std_logic_vector(0 to 15) := x"0102"; constant U_STATE_3 : std_logic_vector(0 to 15) := x"0103"; constant U_STATE_4 : std_logic_vector(0 to 15) := x"0104"; constant U_STATE_5 : std_logic_vector(0 to 15) := x"0105"; constant U_STATE_6 : std_logic_vector(0 to 15) := x"0106"; constant U_STATE_7 : std_logic_vector(0 to 15) := x"0107"; constant U_STATE_8 : std_logic_vector(0 to 15) := x"0108"; constant U_STATE_9 : std_logic_vector(0 to 15) := x"0109"; constant U_STATE_10 : std_logic_vector(0 to 15) := x"0110"; constant U_STATE_11 : std_logic_vector(0 to 15) := x"0111"; constant U_STATE_12 : std_logic_vector(0 to 15) := x"0112"; constant U_STATE_13 : std_logic_vector(0 to 15) := x"0113"; constant U_STATE_14 : std_logic_vector(0 to 15) := x"0114"; constant U_STATE_15 : std_logic_vector(0 to 15) := x"0115"; constant U_STATE_16 : std_logic_vector(0 to 15) := x"0116"; constant U_STATE_17 : std_logic_vector(0 to 15) := x"0117"; constant U_STATE_18 : std_logic_vector(0 to 15) := x"0118"; constant U_STATE_19 : std_logic_vector(0 to 15) := x"0119"; constant U_STATE_20 : std_logic_vector(0 to 15) := x"0120"; -- Range 0003 to 7999 reserved for user logic's state machine -- Range 8000 to 9999 reserved for system calls constant FUNCTION_HTHREAD_ATTR_INIT : std_logic_vector(0 to 15) := x"8000"; constant FUNCTION_HTHREAD_ATTR_DESTROY : std_logic_vector(0 to 15) := x"8001"; constant FUNCTION_HTHREAD_CREATE : std_logic_vector(0 to 15) := x"8010"; constant FUNCTION_HTHREAD_JOIN : std_logic_vector(0 to 15) := x"8011"; constant FUNCTION_HTHREAD_SELF : std_logic_vector(0 to 15) := x"8012"; constant FUNCTION_HTHREAD_YIELD : std_logic_vector(0 to 15) := x"8013"; constant FUNCTION_HTHREAD_EQUAL : std_logic_vector(0 to 15) := x"8014"; constant FUNCTION_HTHREAD_EXIT : std_logic_vector(0 to 15) := x"8015"; constant FUNCTION_HTHREAD_EXIT_ERROR : std_logic_vector(0 to 15) := x"8016"; constant FUNCTION_HTHREAD_MUTEXATTR_INIT : std_logic_vector(0 to 15) := x"8020"; constant FUNCTION_HTHREAD_MUTEXATTR_DESTROY : std_logic_vector(0 to 15) := x"8021"; constant FUNCTION_HTHREAD_MUTEXATTR_SETNUM : std_logic_vector(0 to 15) := x"8022"; constant FUNCTION_HTHREAD_MUTEXATTR_GETNUM : std_logic_vector(0 to 15) := x"8023"; constant FUNCTION_HTHREAD_MUTEX_INIT : std_logic_vector(0 to 15) := x"8030"; constant FUNCTION_HTHREAD_MUTEX_DESTROY : std_logic_vector(0 to 15) := x"8031"; constant FUNCTION_HTHREAD_MUTEX_LOCK : std_logic_vector(0 to 15) := x"8032"; constant FUNCTION_HTHREAD_MUTEX_UNLOCK : std_logic_vector(0 to 15) := x"8033"; constant FUNCTION_HTHREAD_MUTEX_TRYLOCK : std_logic_vector(0 to 15) := x"8034"; constant FUNCTION_HTHREAD_CONDATTR_INIT : std_logic_vector(0 to 15) := x"8040"; constant FUNCTION_HTHREAD_CONDATTR_DESTROY : std_logic_vector(0 to 15) := x"8041"; constant FUNCTION_HTHREAD_CONDATTR_SETNUM : std_logic_vector(0 to 15) := x"8042"; constant FUNCTION_HTHREAD_CONDATTR_GETNUM : std_logic_vector(0 to 15) := x"8043"; constant FUNCTION_HTHREAD_COND_INIT : std_logic_vector(0 to 15) := x"8050"; constant FUNCTION_HTHREAD_COND_DESTROY : std_logic_vector(0 to 15) := x"8051"; constant FUNCTION_HTHREAD_COND_SIGNAL : std_logic_vector(0 to 15) := x"8052"; constant FUNCTION_HTHREAD_COND_BROADCAST : std_logic_vector(0 to 15) := x"8053"; constant FUNCTION_HTHREAD_COND_WAIT : std_logic_vector(0 to 15) := x"8054"; -- Ranged A000 to FFFF reserved for supported library calls constant FUNCTION_MALLOC : std_logic_vector(0 to 15) := x"A000"; constant FUNCTION_CALLOC : std_logic_vector(0 to 15) := x"A001"; constant FUNCTION_FREE : std_logic_vector(0 to 15) := x"A002"; -- user_opcode Constants constant OPCODE_NOOP : std_logic_vector(0 to 5) := "000000"; -- Memory sub-interface specific opcodes constant OPCODE_LOAD : std_logic_vector(0 to 5) := "000001"; constant OPCODE_STORE : std_logic_vector(0 to 5) := "000010"; constant OPCODE_DECLARE : std_logic_vector(0 to 5) := "000011"; constant OPCODE_READ : std_logic_vector(0 to 5) := "000100"; constant OPCODE_WRITE : std_logic_vector(0 to 5) := "000101"; constant OPCODE_ADDRESS : std_logic_vector(0 to 5) := "000110"; -- Function sub-interface specific opcodes constant OPCODE_PUSH : std_logic_vector(0 to 5) := "010000"; constant OPCODE_POP : std_logic_vector(0 to 5) := "010001"; constant OPCODE_CALL : std_logic_vector(0 to 5) := "010010"; constant OPCODE_RETURN : std_logic_vector(0 to 5) := "010011"; constant Z32 : std_logic_vector(0 to 31) := (others => '0'); signal current_state, next_state : state_machine := FUNCTION_RESET; signal return_state, return_state_next: state_machine := FUNCTION_RESET; signal toUser_address : std_logic_vector(0 to 31); signal toUser_value : std_logic_vector(0 to 31); signal toUser_function : std_logic_vector(0 to 15); signal toUser_goWait : std_logic; signal retVal, retVal_next : std_logic_vector(0 to 31); signal arg, arg_next : std_logic_vector(0 to 31); signal reg1, reg1_next : std_logic_vector(0 to 31); signal reg2, reg2_next : std_logic_vector(0 to 31); signal reg3, reg3_next : std_logic_vector(0 to 31); signal reg4, reg4_next : std_logic_vector(0 to 31); signal reg5, reg5_next : std_logic_vector(0 to 31); signal reg6, reg6_next : std_logic_vector(0 to 31); signal reg7, reg7_next : std_logic_vector(0 to 31); signal reg8, reg8_next : std_logic_vector(0 to 31); --------------------------------------------------------------------------- -- Begin architecture --------------------------------------------------------------------------- begin -- architecture IMP HWTUL_STATE_PROCESS : process (clock, intrfc2thrd_goWait) is begin if (clock'event and (clock = '1')) then toUser_address <= intrfc2thrd_address; toUser_value <= intrfc2thrd_value; toUser_function <= intrfc2thrd_function; toUser_goWait <= intrfc2thrd_goWait; return_state <= return_state_next; retVal <= retVal_next; arg <= arg_next; reg1 <= reg1_next; reg2 <= reg2_next; reg3 <= reg3_next; reg4 <= reg4_next; reg5 <= reg5_next; reg6 <= reg6_next; reg7 <= reg7_next; reg8 <= reg8_next; -- Find out if the HWTI is tell us what to do if (intrfc2thrd_goWait = '1') then case intrfc2thrd_function is -- Typically the HWTI will tell us to control our own destiny when U_FUNCTION_USER_SELECT => current_state <= next_state; -- List all the functions the HWTI could tell us to run when U_FUNCTION_RESET => current_state <= FUNCTION_RESET; when U_FUNCTION_START => current_state <= FUNCTION_START; when U_STATE_1 => current_state <= STATE_1; when U_STATE_2 => current_state <= STATE_2; when U_STATE_3 => current_state <= STATE_3; when U_STATE_4 => current_state <= STATE_4; when U_STATE_5 => current_state <= STATE_5; when U_STATE_6 => current_state <= STATE_6; when U_STATE_7 => current_state <= STATE_7; when U_STATE_8 => current_state <= STATE_8; when U_STATE_9 => current_state <= STATE_9; when U_STATE_10 => current_state <= STATE_10; when U_STATE_11 => current_state <= STATE_11; when U_STATE_12 => current_state <= STATE_12; when U_STATE_13 => current_state <= STATE_13; when U_STATE_14 => current_state <= STATE_14; when U_STATE_15 => current_state <= STATE_15; when U_STATE_16 => current_state <= STATE_16; when U_STATE_17 => current_state <= STATE_17; when U_STATE_18 => current_state <= STATE_18; when U_STATE_19 => current_state <= STATE_19; when U_STATE_20 => current_state <= STATE_20; -- If the HWTI tells us to do something we don't know, error when OTHERS => current_state <= ERROR_STATE; end case; else current_state <= WAIT_STATE; end if; end if; end process HWTUL_STATE_PROCESS; HWTUL_STATE_MACHINE : process (clock) is begin -- Default register assignments thrd2intrfc_opcode <= OPCODE_NOOP; -- When issuing an OPCODE, must be a pulse thrd2intrfc_address <= Z32; thrd2intrfc_value <= Z32; thrd2intrfc_function <= U_FUNCTION_USER_SELECT; return_state_next <= return_state; next_state <= current_state; retVal_next <= retVal; arg_next <= arg; reg1_next <= reg1; reg2_next <= reg2; reg3_next <= reg3; reg4_next <= reg4; reg5_next <= reg5; reg6_next <= reg6; reg7_next <= reg7; reg8_next <= reg8; ----------------------------------------------------------------------- -- Testcase: create_2.c -- reg6 = * function -- reg7 = thread ----------------------------------------------------------------------- -- The state machine case current_state is when FUNCTION_RESET => --Set default values thrd2intrfc_opcode <= OPCODE_NOOP; thrd2intrfc_address <= Z32; thrd2intrfc_value <= Z32; thrd2intrfc_function <= U_FUNCTION_START; -- struct test_data * data = (struct test_data *) arg; when FUNCTION_START => -- Pop the argument thrd2intrfc_value <= Z32; thrd2intrfc_opcode <= OPCODE_POP; next_state <= WAIT_STATE; return_state_next <= STATE_1; when STATE_1 => arg_next <= intrfc2thrd_value; -- Read the address of function thrd2intrfc_opcode <= OPCODE_LOAD; thrd2intrfc_address <= intrfc2thrd_value; next_state <= WAIT_STATE; return_state_next <= STATE_2; when STATE_2 => reg6_next <= intrfc2thrd_value; next_state <= STATE_3; -- hthread_create( &data->thread, NULL, data->function, NULL ); when STATE_3 => -- push NULL thrd2intrfc_opcode <= OPCODE_PUSH; thrd2intrfc_value <= Z32; next_state <= WAIT_STATE; return_state_next <= STATE_4; when STATE_4 => -- push data->function thrd2intrfc_opcode <= OPCODE_PUSH; thrd2intrfc_value <= reg6; next_state <= WAIT_STATE; return_state_next <= STATE_5; when STATE_5 => -- push NULL thrd2intrfc_opcode <= OPCODE_PUSH; thrd2intrfc_value <= Z32; next_state <= WAIT_STATE; return_state_next <= STATE_6; when STATE_6 => -- push &data->thread thrd2intrfc_opcode <= OPCODE_PUSH; thrd2intrfc_value <= arg + x"00000004"; next_state <= WAIT_STATE; return_state_next <= STATE_7; when STATE_7 => -- call hthread_create thrd2intrfc_opcode <= OPCODE_CALL; thrd2intrfc_function <= FUNCTION_HTHREAD_CREATE; thrd2intrfc_value <= Z32(0 to 15) & U_STATE_8; next_state <= WAIT_STATE; -- retVal = hthread_join( data->thread, NULL ); when STATE_8 => -- Load the value of data->thread thrd2intrfc_opcode <= OPCODE_LOAD; thrd2intrfc_address <= arg + x"00000004"; next_state <= WAIT_STATE; return_state_next <= STATE_9; when STATE_9 => reg7_next <= intrfc2thrd_value; -- push NULL thrd2intrfc_opcode <= OPCODE_PUSH; thrd2intrfc_value <= Z32; next_state <= WAIT_STATE; return_state_next <= STATE_10; when STATE_10 => -- push data->thread thrd2intrfc_opcode <= OPCODE_PUSH; thrd2intrfc_value <= reg7; next_state <= WAIT_STATE; return_state_next <= STATE_11; when STATE_11 => -- call hthread_join thrd2intrfc_opcode <= OPCODE_CALL; thrd2intrfc_function <= FUNCTION_HTHREAD_JOIN; thrd2intrfc_value <= Z32(0 to 15) & U_STATE_12; next_state <= WAIT_STATE; when STATE_12 => retVal_next <= intrfc2thrd_value; next_state <= FUNCTION_EXIT; when FUNCTION_EXIT => --Same as hthread_exit( (void *) retVal ); thrd2intrfc_value <= retVal; thrd2intrfc_opcode <= OPCODE_RETURN; next_state <= WAIT_STATE; when WAIT_STATE => next_state <= return_state; when ERROR_STATE => next_state <= ERROR_STATE; when others => next_state <= ERROR_STATE; end case; end process HWTUL_STATE_MACHINE; end architecture IMP;
------------------------------------------------------------------------------ -- Title : Wishbone BPM SWAP flat interface ------------------------------------------------------------------------------ -- Author : Jose Alvim Berkenbrock -- Company : CNPEM LNLS-DIG -- Platform : FPGA-generic ------------------------------------------------------------------------------- -- Description: Wishbone interface with BPM Swap core. In flat style. ------------------------------------------------------------------------------- -- Copyright (c) 2013 CNPEM -- Licensed under GNU Lesser General Public License (LGPL) v3.0 ------------------------------------------------------------------------------- -- Revisions : -- Date Version Author Description -- 2013-04-12 1.0 jose.berkenbrock Created ------------------------------------------------------------------------------- library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; library work; -- Main Wishbone Definitions use work.wishbone_pkg.all; -- BPM cores use work.swap_pkg.all; -- Register Bank use work.bpm_swap_wbgen2_pkg.all; entity wb_bpm_swap is generic ( g_interface_mode : t_wishbone_interface_mode := CLASSIC; g_address_granularity : t_wishbone_address_granularity := WORD; g_delay_vec_width : natural := 8; g_swap_div_freq_vec_width : natural := 16; g_ch_width : natural := 16 ); port ( rst_n_i : in std_logic; clk_sys_i : in std_logic; fs_rst_n_i : in std_logic; fs_clk_i : in std_logic; ----------------------------- -- Wishbone signals ----------------------------- wb_adr_i : in std_logic_vector(c_wishbone_address_width-1 downto 0) := (others => '0'); wb_dat_i : in std_logic_vector(c_wishbone_data_width-1 downto 0) := (others => '0'); wb_dat_o : out std_logic_vector(c_wishbone_data_width-1 downto 0); wb_sel_i : in std_logic_vector(c_wishbone_data_width/8-1 downto 0) := (others => '0'); wb_we_i : in std_logic := '0'; wb_cyc_i : in std_logic := '0'; wb_stb_i : in std_logic := '0'; wb_ack_o : out std_logic; wb_stall_o : out std_logic; ----------------------------- -- External ports ----------------------------- -- Input data from ADCs cha_i : in std_logic_vector(g_ch_width-1 downto 0); chb_i : in std_logic_vector(g_ch_width-1 downto 0); chc_i : in std_logic_vector(g_ch_width-1 downto 0); chd_i : in std_logic_vector(g_ch_width-1 downto 0); ch_valid_i : in std_logic; -- Output data to BPM DSP chain cha_o : out std_logic_vector(g_ch_width-1 downto 0); chb_o : out std_logic_vector(g_ch_width-1 downto 0); chc_o : out std_logic_vector(g_ch_width-1 downto 0); chd_o : out std_logic_vector(g_ch_width-1 downto 0); ch_tag_o : out std_logic_vector(0 downto 0); ch_valid_o : out std_logic; -- RFFE swap clock (or switchwing clock) rffe_swclk_o : out std_logic; -- RFFE swap clock synchronization trigger sync_trig_i : in std_logic ); end wb_bpm_swap; architecture rtl of wb_bpm_swap is constant c_periph_addr_size : natural := 1+2; signal fs_rst_n : std_logic; ----------------------------- -- Wishbone Register Interface signals ----------------------------- -- wb_bpm_swap reg structure signal regs_in : t_bpm_swap_in_registers; signal regs_out : t_bpm_swap_out_registers; ----------------------------- -- Wishbone slave adapter signals/structures ----------------------------- signal wb_slv_adp_out : t_wishbone_master_out; signal wb_slv_adp_in : t_wishbone_master_in; signal resized_addr : std_logic_vector(c_wishbone_address_width-1 downto 0); signal deswap_delay : std_logic_vector(g_delay_vec_width-1 downto 0); component wb_bpm_swap_regs port ( rst_n_i : in std_logic; clk_sys_i : in std_logic; wb_adr_i : in std_logic_vector(0 downto 0); wb_dat_i : in std_logic_vector(31 downto 0); wb_dat_o : out std_logic_vector(31 downto 0); wb_cyc_i : in std_logic; wb_sel_i : in std_logic_vector(3 downto 0); wb_stb_i : in std_logic; wb_we_i : in std_logic; wb_ack_o : out std_logic; wb_stall_o : out std_logic; fs_clk_i : in std_logic; regs_i : in t_bpm_swap_in_registers; regs_o : out t_bpm_swap_out_registers ); end component; begin ----------------------------- -- Slave adapter for Wishbone Register Interface ----------------------------- cmp_slave_adapter : wb_slave_adapter generic map ( g_master_use_struct => true, g_master_mode => PIPELINED, g_master_granularity => WORD, g_slave_use_struct => false, g_slave_mode => g_interface_mode, g_slave_granularity => g_address_granularity ) port map ( clk_sys_i => clk_sys_i, rst_n_i => rst_n_i, master_i => wb_slv_adp_in, master_o => wb_slv_adp_out, sl_adr_i => resized_addr, sl_dat_i => wb_dat_i, sl_sel_i => wb_sel_i, sl_cyc_i => wb_cyc_i, sl_stb_i => wb_stb_i, sl_we_i => wb_we_i, sl_dat_o => wb_dat_o, sl_ack_o => wb_ack_o, sl_rty_o => open, sl_err_o => open, sl_stall_o => wb_stall_o ); -- See wb_bpm_swap_port.vhd for register bank addresses. resized_addr(c_periph_addr_size-1 downto 0) <= wb_adr_i(c_periph_addr_size-1 downto 0); --cbar_master_out(0).adr(c_periph_addr_size-1 downto 0); resized_addr(c_wishbone_address_width-1 downto c_periph_addr_size) <= (others => '0'); -- Register Bank / Wishbone Interface cmp_wb_bpm_swap_regs : wb_bpm_swap_regs port map ( rst_n_i => rst_n_i, clk_sys_i => clk_sys_i, wb_adr_i => wb_slv_adp_out.adr(0 downto 0), wb_dat_i => wb_slv_adp_out.dat, wb_dat_o => wb_slv_adp_in.dat, wb_cyc_i => wb_slv_adp_out.cyc, wb_sel_i => wb_slv_adp_out.sel, wb_stb_i => wb_slv_adp_out.stb, wb_we_i => wb_slv_adp_out.we, wb_ack_o => wb_slv_adp_in.ack, wb_stall_o => wb_slv_adp_in.stall, fs_clk_i => fs_clk_i, regs_i => regs_in, regs_o => regs_out ); -- Registers assignment regs_in.ctrl_reserved_i <= (others => '0'); regs_in.dly_reserved_i <= (others => '0'); -- Unused wishbone signals wb_slv_adp_in.err <= '0'; wb_slv_adp_in.rty <= '0'; cmp_bpm_swap : bpm_swap generic map ( g_delay_vec_width => g_delay_vec_width, g_swap_div_freq_vec_width => g_swap_div_freq_vec_width, g_ch_width => g_ch_width ) port map ( clk_i => fs_clk_i, rst_n_i => fs_rst_n_i, cha_i => cha_i, chb_i => chb_i, chc_i => chc_i, chd_i => chd_i, ch_valid_i => ch_valid_i, cha_o => cha_o, chb_o => chb_o, chc_o => chc_o, chd_o => chd_o, ch_tag_o => ch_tag_o, ch_valid_o => ch_valid_o, rffe_swclk_o => rffe_swclk_o, sync_trig_i => sync_trig_i, swap_mode_i => regs_out.ctrl_mode_o, swap_div_f_i => regs_out.ctrl_swap_div_f_o, deswap_delay_i => deswap_delay ); deswap_delay <= regs_out.dly_deswap_o(g_delay_vec_width-1 downto 0); end rtl;
-- ---------------------------------------------------------------------- -- DspUnit : Advanced So(P)C Sequential Signal Processor -- Copyright (C) 2007-2010 by Adrien LELONG (www.lelongdunet.com) -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the -- Free Software Foundation, Inc., -- 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -- ---------------------------------------------------------------------- library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; use work.dspunit_pac.all; use work.dspalu_pac.all; ------------------------------------------------------------------------------- entity conv_circ is port ( --@inputs clk : in std_logic; op_en : in std_logic; alu_result1 : in std_logic_vector((sig_width - 1) downto 0); alu_result_acc1 : in std_logic_vector((acc_width - 1) downto 0); alu_result2 : in std_logic_vector((sig_width - 1) downto 0); alu_result_acc2 : in std_logic_vector((acc_width - 1) downto 0); gcount : in unsigned(15 downto 0); data_in_m0 : in std_logic_vector((sig_width - 1) downto 0); data_in_m1 : in std_logic_vector((sig_width - 1) downto 0); length_reg : in std_logic_vector((cmdreg_data_width -1) downto 0); --@outputs; dsp_bus : out t_dsp_bus; test : out std_logic_vector((sig_width - 1) downto 0) ); end conv_circ; --=---------------------------------------------------------------------------- architecture archi_conv_circ of conv_circ is ----------------------------------------------------------------------------- -- @constants definition ----------------------------------------------------------------------------- --=-------------------------------------------------------------------------- -- -- @component declarations -- ----------------------------------------------------------------------------- --=-------------------------------------------------------------------------- -- @signals definition ----------------------------------------------------------------------------- signal s_dsp_bus : t_dsp_bus; type t_conv_circ_state is (st_init, st_integral, st_store, st_waitpipe, st_startpipe); signal s_state : t_conv_circ_state; signal s_length : unsigned((cmdreg_width - 1) downto 0); signal s_conv_res : std_logic_vector((sig_width - 1) downto 0); begin -- archs_conv_circ ----------------------------------------------------------------------------- -- -- @instantiations -- ----------------------------------------------------------------------------- --=--------------------------------------------------------------------------- p_conv_circ : process (clk) begin -- process p_conv_circ if rising_edge(clk) then -- rising clock edge if op_en = '0' then s_state <= st_init; --s_dsp_bus <= c_dsp_bus_init; s_dsp_bus.op_done <= '0'; -- memory 0 -- s_dsp_bus.data_out_m0 <= (others => '0'); s_dsp_bus.addr_r_m0 <= (others => '0'); s_dsp_bus.addr_w_m0 <= (others => '0'); s_dsp_bus.wr_en_m0 <= '0'; --s_dsp_bus.c_en_m0 <= '0'; -- memory 1 -- s_dsp_bus.data_out_m1 <= (others => '0'); s_dsp_bus.addr_m1 <= (others => '0'); s_dsp_bus.wr_en_m1 <= '0'; --s_dsp_bus.c_en_m1 <= '0'; -- memory 2 -- s_dsp_bus.data_out_m2 <= (others => '0'); s_dsp_bus.addr_m2 <= (others => '0'); s_dsp_bus.wr_en_m2 <= '0'; --s_dsp_bus.c_en_m2 <= '0'; -- alu --s_dsp_bus.mul_in_a1 <= (others <= '0'); --s_dsp_bus.mul_in_b1 <= (others <= '0'); --s_dsp_bus.mul_in_a2 <= (others <= '0'); --s_dsp_bus.mul_in_b2 <= (others <= '0'); s_dsp_bus.acc_mode1 <= acc_store; s_dsp_bus.acc_mode2 <= acc_store; s_dsp_bus.alu_select <= alu_mul; -- global counter --s_dsp_bus.gcounter_reset <= '0'; ------------------------------------------------------------------------------- -- operation management ------------------------------------------------------------------------------- else case s_state is when st_init => s_dsp_bus.addr_r_m0 <= (others => '0'); s_dsp_bus.addr_m1 <= s_length; s_dsp_bus.addr_m2 <= (others => '0'); s_dsp_bus.wr_en_m2 <= '0'; if s_dsp_bus.op_done = '0' then s_state <= st_startpipe; end if; when st_startpipe => if s_dsp_bus.addr_r_m0 = 1 then s_state <= st_integral; -- s_dsp_bus.acc_mode1 <= acc_add; end if; -- index increment s_dsp_bus.addr_r_m0 <= s_dsp_bus.addr_r_m0 + 1; s_dsp_bus.addr_m1 <= (s_dsp_bus.addr_m1 - 1) and s_length; -- accumulator init s_dsp_bus.acc_mode1 <= acc_store; when st_waitpipe => if s_dsp_bus.addr_r_m0 = 1 then s_state <= st_store; s_dsp_bus.acc_mode1 <= acc_store; -- s_dsp_bus.wr_en_m2 <= '1'; end if; -- index increment s_dsp_bus.addr_r_m0 <= s_dsp_bus.addr_r_m0 + 1; s_dsp_bus.addr_m1 <= (s_dsp_bus.addr_m1 - 1) and s_length; when st_store => -- save accumulator result in memory s_dsp_bus.wr_en_m2 <= '1'; if(s_dsp_bus.addr_m2 = s_length) then s_state <= st_init; s_dsp_bus.op_done <= '1'; else s_dsp_bus.acc_mode1 <= acc_add; s_dsp_bus.addr_m2 <= s_dsp_bus.addr_m2 + 1; s_state <= st_integral; end if; -- index increment s_dsp_bus.addr_r_m0 <= s_dsp_bus.addr_r_m0 + 1; s_dsp_bus.addr_m1 <= (s_dsp_bus.addr_m1 - 1) and s_length; when st_integral => s_dsp_bus.wr_en_m2 <= '0'; -- perform mac operation s_dsp_bus.acc_mode1 <= acc_add; -- end of integration if s_dsp_bus.addr_r_m0 = s_length then s_state <= st_waitpipe; s_dsp_bus.addr_r_m0 <= (others => '0'); else -- index increment s_dsp_bus.addr_r_m0 <= s_dsp_bus.addr_r_m0 + 1; s_dsp_bus.addr_m1 <= (s_dsp_bus.addr_m1 - 1) and s_length; end if; when others => null; end case; end if; end if; end process p_conv_circ; --=--------------------------------------------------------------------------- -- -- @concurrent signal assignments -- ----------------------------------------------------------------------------- dsp_bus <= s_dsp_bus; -- multiplication of signals is made before accumulation s_dsp_bus.mul_in_a1 <= data_in_m0; s_dsp_bus.mul_in_b1 <= data_in_m1; s_conv_res <= std_logic_vector(alu_result_acc1((sig_width - 1) downto 0)); s_dsp_bus.data_out_m2 <= s_conv_res; s_dsp_bus.data_out_m0 <= s_conv_res; s_dsp_bus.data_out_m1 <= s_conv_res; s_dsp_bus.c_en_m0 <= '1'; s_dsp_bus.c_en_m1 <= '1'; s_dsp_bus.c_en_m2 <= '1'; s_dsp_bus.gcounter_reset <= '1'; s_length <= unsigned(length_reg); test <= s_conv_res; end archi_conv_circ; -------------------------------------------------------------------------------
-- ---------------------------------------------------------------------- -- DspUnit : Advanced So(P)C Sequential Signal Processor -- Copyright (C) 2007-2010 by Adrien LELONG (www.lelongdunet.com) -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the -- Free Software Foundation, Inc., -- 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -- ---------------------------------------------------------------------- library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; use work.dspunit_pac.all; use work.dspalu_pac.all; ------------------------------------------------------------------------------- entity conv_circ is port ( --@inputs clk : in std_logic; op_en : in std_logic; alu_result1 : in std_logic_vector((sig_width - 1) downto 0); alu_result_acc1 : in std_logic_vector((acc_width - 1) downto 0); alu_result2 : in std_logic_vector((sig_width - 1) downto 0); alu_result_acc2 : in std_logic_vector((acc_width - 1) downto 0); gcount : in unsigned(15 downto 0); data_in_m0 : in std_logic_vector((sig_width - 1) downto 0); data_in_m1 : in std_logic_vector((sig_width - 1) downto 0); length_reg : in std_logic_vector((cmdreg_data_width -1) downto 0); --@outputs; dsp_bus : out t_dsp_bus; test : out std_logic_vector((sig_width - 1) downto 0) ); end conv_circ; --=---------------------------------------------------------------------------- architecture archi_conv_circ of conv_circ is ----------------------------------------------------------------------------- -- @constants definition ----------------------------------------------------------------------------- --=-------------------------------------------------------------------------- -- -- @component declarations -- ----------------------------------------------------------------------------- --=-------------------------------------------------------------------------- -- @signals definition ----------------------------------------------------------------------------- signal s_dsp_bus : t_dsp_bus; type t_conv_circ_state is (st_init, st_integral, st_store, st_waitpipe, st_startpipe); signal s_state : t_conv_circ_state; signal s_length : unsigned((cmdreg_width - 1) downto 0); signal s_conv_res : std_logic_vector((sig_width - 1) downto 0); begin -- archs_conv_circ ----------------------------------------------------------------------------- -- -- @instantiations -- ----------------------------------------------------------------------------- --=--------------------------------------------------------------------------- p_conv_circ : process (clk) begin -- process p_conv_circ if rising_edge(clk) then -- rising clock edge if op_en = '0' then s_state <= st_init; --s_dsp_bus <= c_dsp_bus_init; s_dsp_bus.op_done <= '0'; -- memory 0 -- s_dsp_bus.data_out_m0 <= (others => '0'); s_dsp_bus.addr_r_m0 <= (others => '0'); s_dsp_bus.addr_w_m0 <= (others => '0'); s_dsp_bus.wr_en_m0 <= '0'; --s_dsp_bus.c_en_m0 <= '0'; -- memory 1 -- s_dsp_bus.data_out_m1 <= (others => '0'); s_dsp_bus.addr_m1 <= (others => '0'); s_dsp_bus.wr_en_m1 <= '0'; --s_dsp_bus.c_en_m1 <= '0'; -- memory 2 -- s_dsp_bus.data_out_m2 <= (others => '0'); s_dsp_bus.addr_m2 <= (others => '0'); s_dsp_bus.wr_en_m2 <= '0'; --s_dsp_bus.c_en_m2 <= '0'; -- alu --s_dsp_bus.mul_in_a1 <= (others <= '0'); --s_dsp_bus.mul_in_b1 <= (others <= '0'); --s_dsp_bus.mul_in_a2 <= (others <= '0'); --s_dsp_bus.mul_in_b2 <= (others <= '0'); s_dsp_bus.acc_mode1 <= acc_store; s_dsp_bus.acc_mode2 <= acc_store; s_dsp_bus.alu_select <= alu_mul; -- global counter --s_dsp_bus.gcounter_reset <= '0'; ------------------------------------------------------------------------------- -- operation management ------------------------------------------------------------------------------- else case s_state is when st_init => s_dsp_bus.addr_r_m0 <= (others => '0'); s_dsp_bus.addr_m1 <= s_length; s_dsp_bus.addr_m2 <= (others => '0'); s_dsp_bus.wr_en_m2 <= '0'; if s_dsp_bus.op_done = '0' then s_state <= st_startpipe; end if; when st_startpipe => if s_dsp_bus.addr_r_m0 = 1 then s_state <= st_integral; -- s_dsp_bus.acc_mode1 <= acc_add; end if; -- index increment s_dsp_bus.addr_r_m0 <= s_dsp_bus.addr_r_m0 + 1; s_dsp_bus.addr_m1 <= (s_dsp_bus.addr_m1 - 1) and s_length; -- accumulator init s_dsp_bus.acc_mode1 <= acc_store; when st_waitpipe => if s_dsp_bus.addr_r_m0 = 1 then s_state <= st_store; s_dsp_bus.acc_mode1 <= acc_store; -- s_dsp_bus.wr_en_m2 <= '1'; end if; -- index increment s_dsp_bus.addr_r_m0 <= s_dsp_bus.addr_r_m0 + 1; s_dsp_bus.addr_m1 <= (s_dsp_bus.addr_m1 - 1) and s_length; when st_store => -- save accumulator result in memory s_dsp_bus.wr_en_m2 <= '1'; if(s_dsp_bus.addr_m2 = s_length) then s_state <= st_init; s_dsp_bus.op_done <= '1'; else s_dsp_bus.acc_mode1 <= acc_add; s_dsp_bus.addr_m2 <= s_dsp_bus.addr_m2 + 1; s_state <= st_integral; end if; -- index increment s_dsp_bus.addr_r_m0 <= s_dsp_bus.addr_r_m0 + 1; s_dsp_bus.addr_m1 <= (s_dsp_bus.addr_m1 - 1) and s_length; when st_integral => s_dsp_bus.wr_en_m2 <= '0'; -- perform mac operation s_dsp_bus.acc_mode1 <= acc_add; -- end of integration if s_dsp_bus.addr_r_m0 = s_length then s_state <= st_waitpipe; s_dsp_bus.addr_r_m0 <= (others => '0'); else -- index increment s_dsp_bus.addr_r_m0 <= s_dsp_bus.addr_r_m0 + 1; s_dsp_bus.addr_m1 <= (s_dsp_bus.addr_m1 - 1) and s_length; end if; when others => null; end case; end if; end if; end process p_conv_circ; --=--------------------------------------------------------------------------- -- -- @concurrent signal assignments -- ----------------------------------------------------------------------------- dsp_bus <= s_dsp_bus; -- multiplication of signals is made before accumulation s_dsp_bus.mul_in_a1 <= data_in_m0; s_dsp_bus.mul_in_b1 <= data_in_m1; s_conv_res <= std_logic_vector(alu_result_acc1((sig_width - 1) downto 0)); s_dsp_bus.data_out_m2 <= s_conv_res; s_dsp_bus.data_out_m0 <= s_conv_res; s_dsp_bus.data_out_m1 <= s_conv_res; s_dsp_bus.c_en_m0 <= '1'; s_dsp_bus.c_en_m1 <= '1'; s_dsp_bus.c_en_m2 <= '1'; s_dsp_bus.gcounter_reset <= '1'; s_length <= unsigned(length_reg); test <= s_conv_res; end archi_conv_circ; -------------------------------------------------------------------------------
--------------------------------------------------- -- School: University of Massachusetts Dartmouth -- Department: Computer and Electrical Engineering -- Engineer: Daniel Noyes -- -- Create Date: SPRING 2016 -- Module Name: Button Controller -- Project Name: Button Controller -- Target Devices: Spartan-3E -- Tool versions: Xilinx ISE 14.7 -- Description: Button Controller -- Four input debouncer --------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use work.all; entity buttoncontrol is Port ( CLK : in STD_LOGIC; INPUT : in STD_LOGIC_VECTOR (3 downto 0); OUTPUT : out STD_LOGIC_VECTOR (3 downto 0)); end buttoncontrol; architecture Structural of buttoncontrol is signal EN : STD_LOGIC := '1'; begin BTN_0: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(0), OUTPUT => OUTPUT(0)); BTN_1: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(1), OUTPUT => OUTPUT(1)); BTN_2: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(2), OUTPUT => OUTPUT(2)); BTN_3: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(3), OUTPUT => OUTPUT(3)); end Structural;
--------------------------------------------------- -- School: University of Massachusetts Dartmouth -- Department: Computer and Electrical Engineering -- Engineer: Daniel Noyes -- -- Create Date: SPRING 2016 -- Module Name: Button Controller -- Project Name: Button Controller -- Target Devices: Spartan-3E -- Tool versions: Xilinx ISE 14.7 -- Description: Button Controller -- Four input debouncer --------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use work.all; entity buttoncontrol is Port ( CLK : in STD_LOGIC; INPUT : in STD_LOGIC_VECTOR (3 downto 0); OUTPUT : out STD_LOGIC_VECTOR (3 downto 0)); end buttoncontrol; architecture Structural of buttoncontrol is signal EN : STD_LOGIC := '1'; begin BTN_0: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(0), OUTPUT => OUTPUT(0)); BTN_1: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(1), OUTPUT => OUTPUT(1)); BTN_2: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(2), OUTPUT => OUTPUT(2)); BTN_3: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(3), OUTPUT => OUTPUT(3)); end Structural;
--------------------------------------------------- -- School: University of Massachusetts Dartmouth -- Department: Computer and Electrical Engineering -- Engineer: Daniel Noyes -- -- Create Date: SPRING 2016 -- Module Name: Button Controller -- Project Name: Button Controller -- Target Devices: Spartan-3E -- Tool versions: Xilinx ISE 14.7 -- Description: Button Controller -- Four input debouncer --------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use work.all; entity buttoncontrol is Port ( CLK : in STD_LOGIC; INPUT : in STD_LOGIC_VECTOR (3 downto 0); OUTPUT : out STD_LOGIC_VECTOR (3 downto 0)); end buttoncontrol; architecture Structural of buttoncontrol is signal EN : STD_LOGIC := '1'; begin BTN_0: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(0), OUTPUT => OUTPUT(0)); BTN_1: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(1), OUTPUT => OUTPUT(1)); BTN_2: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(2), OUTPUT => OUTPUT(2)); BTN_3: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(3), OUTPUT => OUTPUT(3)); end Structural;
--------------------------------------------------- -- School: University of Massachusetts Dartmouth -- Department: Computer and Electrical Engineering -- Engineer: Daniel Noyes -- -- Create Date: SPRING 2016 -- Module Name: Button Controller -- Project Name: Button Controller -- Target Devices: Spartan-3E -- Tool versions: Xilinx ISE 14.7 -- Description: Button Controller -- Four input debouncer --------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use work.all; entity buttoncontrol is Port ( CLK : in STD_LOGIC; INPUT : in STD_LOGIC_VECTOR (3 downto 0); OUTPUT : out STD_LOGIC_VECTOR (3 downto 0)); end buttoncontrol; architecture Structural of buttoncontrol is signal EN : STD_LOGIC := '1'; begin BTN_0: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(0), OUTPUT => OUTPUT(0)); BTN_1: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(1), OUTPUT => OUTPUT(1)); BTN_2: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(2), OUTPUT => OUTPUT(2)); BTN_3: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(3), OUTPUT => OUTPUT(3)); end Structural;
--------------------------------------------------- -- School: University of Massachusetts Dartmouth -- Department: Computer and Electrical Engineering -- Engineer: Daniel Noyes -- -- Create Date: SPRING 2016 -- Module Name: Button Controller -- Project Name: Button Controller -- Target Devices: Spartan-3E -- Tool versions: Xilinx ISE 14.7 -- Description: Button Controller -- Four input debouncer --------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use work.all; entity buttoncontrol is Port ( CLK : in STD_LOGIC; INPUT : in STD_LOGIC_VECTOR (3 downto 0); OUTPUT : out STD_LOGIC_VECTOR (3 downto 0)); end buttoncontrol; architecture Structural of buttoncontrol is signal EN : STD_LOGIC := '1'; begin BTN_0: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(0), OUTPUT => OUTPUT(0)); BTN_1: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(1), OUTPUT => OUTPUT(1)); BTN_2: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(2), OUTPUT => OUTPUT(2)); BTN_3: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(3), OUTPUT => OUTPUT(3)); end Structural;
--------------------------------------------------- -- School: University of Massachusetts Dartmouth -- Department: Computer and Electrical Engineering -- Engineer: Daniel Noyes -- -- Create Date: SPRING 2016 -- Module Name: Button Controller -- Project Name: Button Controller -- Target Devices: Spartan-3E -- Tool versions: Xilinx ISE 14.7 -- Description: Button Controller -- Four input debouncer --------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use work.all; entity buttoncontrol is Port ( CLK : in STD_LOGIC; INPUT : in STD_LOGIC_VECTOR (3 downto 0); OUTPUT : out STD_LOGIC_VECTOR (3 downto 0)); end buttoncontrol; architecture Structural of buttoncontrol is signal EN : STD_LOGIC := '1'; begin BTN_0: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(0), OUTPUT => OUTPUT(0)); BTN_1: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(1), OUTPUT => OUTPUT(1)); BTN_2: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(2), OUTPUT => OUTPUT(2)); BTN_3: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(3), OUTPUT => OUTPUT(3)); end Structural;
--------------------------------------------------- -- School: University of Massachusetts Dartmouth -- Department: Computer and Electrical Engineering -- Engineer: Daniel Noyes -- -- Create Date: SPRING 2016 -- Module Name: Button Controller -- Project Name: Button Controller -- Target Devices: Spartan-3E -- Tool versions: Xilinx ISE 14.7 -- Description: Button Controller -- Four input debouncer --------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use work.all; entity buttoncontrol is Port ( CLK : in STD_LOGIC; INPUT : in STD_LOGIC_VECTOR (3 downto 0); OUTPUT : out STD_LOGIC_VECTOR (3 downto 0)); end buttoncontrol; architecture Structural of buttoncontrol is signal EN : STD_LOGIC := '1'; begin BTN_0: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(0), OUTPUT => OUTPUT(0)); BTN_1: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(1), OUTPUT => OUTPUT(1)); BTN_2: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(2), OUTPUT => OUTPUT(2)); BTN_3: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(3), OUTPUT => OUTPUT(3)); end Structural;
--------------------------------------------------- -- School: University of Massachusetts Dartmouth -- Department: Computer and Electrical Engineering -- Engineer: Daniel Noyes -- -- Create Date: SPRING 2016 -- Module Name: Button Controller -- Project Name: Button Controller -- Target Devices: Spartan-3E -- Tool versions: Xilinx ISE 14.7 -- Description: Button Controller -- Four input debouncer --------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use work.all; entity buttoncontrol is Port ( CLK : in STD_LOGIC; INPUT : in STD_LOGIC_VECTOR (3 downto 0); OUTPUT : out STD_LOGIC_VECTOR (3 downto 0)); end buttoncontrol; architecture Structural of buttoncontrol is signal EN : STD_LOGIC := '1'; begin BTN_0: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(0), OUTPUT => OUTPUT(0)); BTN_1: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(1), OUTPUT => OUTPUT(1)); BTN_2: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(2), OUTPUT => OUTPUT(2)); BTN_3: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(3), OUTPUT => OUTPUT(3)); end Structural;
--------------------------------------------------- -- School: University of Massachusetts Dartmouth -- Department: Computer and Electrical Engineering -- Engineer: Daniel Noyes -- -- Create Date: SPRING 2016 -- Module Name: Button Controller -- Project Name: Button Controller -- Target Devices: Spartan-3E -- Tool versions: Xilinx ISE 14.7 -- Description: Button Controller -- Four input debouncer --------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use work.all; entity buttoncontrol is Port ( CLK : in STD_LOGIC; INPUT : in STD_LOGIC_VECTOR (3 downto 0); OUTPUT : out STD_LOGIC_VECTOR (3 downto 0)); end buttoncontrol; architecture Structural of buttoncontrol is signal EN : STD_LOGIC := '1'; begin BTN_0: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(0), OUTPUT => OUTPUT(0)); BTN_1: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(1), OUTPUT => OUTPUT(1)); BTN_2: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(2), OUTPUT => OUTPUT(2)); BTN_3: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(3), OUTPUT => OUTPUT(3)); end Structural;
--------------------------------------------------- -- School: University of Massachusetts Dartmouth -- Department: Computer and Electrical Engineering -- Engineer: Daniel Noyes -- -- Create Date: SPRING 2016 -- Module Name: Button Controller -- Project Name: Button Controller -- Target Devices: Spartan-3E -- Tool versions: Xilinx ISE 14.7 -- Description: Button Controller -- Four input debouncer --------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use work.all; entity buttoncontrol is Port ( CLK : in STD_LOGIC; INPUT : in STD_LOGIC_VECTOR (3 downto 0); OUTPUT : out STD_LOGIC_VECTOR (3 downto 0)); end buttoncontrol; architecture Structural of buttoncontrol is signal EN : STD_LOGIC := '1'; begin BTN_0: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(0), OUTPUT => OUTPUT(0)); BTN_1: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(1), OUTPUT => OUTPUT(1)); BTN_2: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(2), OUTPUT => OUTPUT(2)); BTN_3: entity work.debounce port map( CLK => CLK, EN => EN, INPUT => INPUT(3), OUTPUT => OUTPUT(3)); end Structural;
architecture rtl of fifo is signal sig8 : record_type_3( element1 (7 downto 0), element2 (4 downto 0) (7 downto 0) ( elementA (7 downto 0) , elementB (3 downto 0) ), element3 (3 downto 0)(elementC (4 downto 1), elementD (1 downto 0)), element5( elementE (3 downto 0) (6 downto 0) , elementF (7 downto 0) ), element6 (4 downto 0), element7 (7 downto 0)); signal sig9 : t_data_struct(data (7 downto 0)); signal sig9 : t_data_struct( data (7 downto 0) ); begin end architecture rtl;
library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity psl_test_cover is end entity psl_test_cover; architecture test of psl_test_cover is signal s_rst_n : std_logic := '0'; signal s_clk : std_logic := '0'; signal s_write : std_logic; signal s_read : std_logic; begin s_rst_n <= '1' after 100 ns; s_clk <= not s_clk after 10 ns; TestP : process is begin report "RUNNING PSL_TEST_COVER test case"; report "================================"; s_write <= '0'; s_read <= '0'; wait until s_rst_n = '1' and rising_edge(s_clk); s_write <= '1'; -- cover should hit wait until rising_edge(s_clk); s_read <= '1'; -- assertion should hit wait until rising_edge(s_clk); s_write <= '0'; s_read <= '0'; wait; end process TestP; -- -psl statements -- psl default clock is rising_edge(s_clk); -- cover directive seems not supported (ignored by GHDL) -- psl cover { s_write ; not(s_read)}; end architecture test;
library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity psl_test_cover is end entity psl_test_cover; architecture test of psl_test_cover is signal s_rst_n : std_logic := '0'; signal s_clk : std_logic := '0'; signal s_write : std_logic; signal s_read : std_logic; begin s_rst_n <= '1' after 100 ns; s_clk <= not s_clk after 10 ns; TestP : process is begin report "RUNNING PSL_TEST_COVER test case"; report "================================"; s_write <= '0'; s_read <= '0'; wait until s_rst_n = '1' and rising_edge(s_clk); s_write <= '1'; -- cover should hit wait until rising_edge(s_clk); s_read <= '1'; -- assertion should hit wait until rising_edge(s_clk); s_write <= '0'; s_read <= '0'; wait; end process TestP; -- -psl statements -- psl default clock is rising_edge(s_clk); -- cover directive seems not supported (ignored by GHDL) -- psl cover { s_write ; not(s_read)}; end architecture test;
----------------------------------------------------------------------------- -- LEON3 Demonstration design -- Copyright (C) 2004 Jiri Gaisler, Gaisler Research ------------------------------------------------------------------------------ -- This file is a part of the GRLIB VHDL IP LIBRARY -- Copyright (C) 2003 - 2008, Gaisler Research -- Copyright (C) 2008 - 2014, Aeroflex Gaisler -- Copyright (C) 2015, Cobham Gaisler -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ------------------------------------------------------------------------------ library ieee; use ieee.std_logic_1164.all; library grlib, techmap; use grlib.amba.all; use grlib.stdlib.all; use grlib.devices.all; use techmap.gencomp.all; use techmap.allclkgen.all; library gaisler; use gaisler.memctrl.all; use gaisler.ddrpkg.all; use gaisler.leon3.all; use gaisler.uart.all; use gaisler.misc.all; use gaisler.i2c.all; use gaisler.net.all; use gaisler.jtag.all; library esa; use esa.memoryctrl.all; use work.config.all; use work.ml50x.all; -- pragma translate_off library unisim; use unisim.ODDR; -- pragma translate_on entity leon3mp is generic ( fabtech : integer := CFG_FABTECH; memtech : integer := CFG_MEMTECH; padtech : integer := CFG_PADTECH; ncpu : integer := CFG_NCPU; disas : integer := CFG_DISAS; -- Enable disassembly to console dbguart : integer := CFG_DUART; -- Print UART on console pclow : integer := CFG_PCLOW ); port ( sys_rst_in : in std_ulogic; clk_100 : in std_ulogic; -- 100 MHz main clock clk_200_p : in std_ulogic; -- 200 MHz clk_200_n : in std_ulogic; -- 200 MHz sysace_clk_in : in std_ulogic; -- System ACE clock sram_flash_addr : out std_logic_vector(23 downto 0); sram_flash_data : inout std_logic_vector(31 downto 0); sram_cen : out std_logic; sram_bw : out std_logic_vector (0 to 3); sram_oen : out std_ulogic; sram_flash_we_n : out std_ulogic; flash_ce : out std_logic; flash_oen : out std_logic; flash_adv_n : out std_logic; sram_clk : out std_ulogic; sram_clk_fb : in std_ulogic; sram_mode : out std_ulogic; sram_adv_ld_n : out std_ulogic; --pragma translate_off iosn : out std_ulogic; --pragma translate_on ddr2_ck : out std_logic_vector(1 downto 0); ddr2_ck_n : out std_logic_vector(1 downto 0); ddr2_cke : out std_logic_vector(1 downto 0); ddr2_cs_n : out std_logic_vector(1 downto 0); ddr2_odt : out std_logic_vector(1 downto 0); ddr2_we_n : out std_ulogic; -- ddr write enable ddr2_ras_n : out std_ulogic; -- ddr ras ddr2_cas_n : out std_ulogic; -- ddr cas ddr2_dm : out std_logic_vector (7 downto 0); -- ddr dm ddr2_dqs : inout std_logic_vector (7 downto 0); -- ddr dqs ddr2_dqs_n : inout std_logic_vector (7 downto 0); -- ddr dqs ddr2_a : out std_logic_vector (13 downto 0); -- ddr address ddr2_ba : out std_logic_vector (1+CFG_DDR2SP downto 0); -- ddr bank address ddr2_dq : inout std_logic_vector (63 downto 0); -- ddr data txd1 : out std_ulogic; -- UART1 tx data rxd1 : in std_ulogic; -- UART1 rx data -- txd2 : out std_ulogic; -- UART2 tx data -- rxd2 : in std_ulogic; -- UART2 rx data gpio : inout std_logic_vector(13 downto 0); -- I/O port led : out std_logic_vector(12 downto 0); bus_error : out std_logic_vector(1 downto 0); phy_gtx_clk : out std_logic; phy_mii_data : inout std_logic; -- ethernet PHY interface phy_tx_clk : in std_ulogic; phy_rx_clk : in std_ulogic; phy_rx_data : in std_logic_vector(7 downto 0); phy_dv : in std_ulogic; phy_rx_er : in std_ulogic; phy_col : in std_ulogic; phy_crs : in std_ulogic; phy_tx_data : out std_logic_vector(7 downto 0); phy_tx_en : out std_ulogic; phy_tx_er : out std_ulogic; phy_mii_clk : out std_ulogic; phy_rst_n : out std_ulogic; phy_int : in std_ulogic; ps2_keyb_clk : inout std_logic; ps2_keyb_data : inout std_logic; ps2_mouse_clk : inout std_logic; ps2_mouse_data : inout std_logic; usb_csn : out std_logic; usb_rstn : out std_logic; iic_scl : inout std_ulogic; iic_sda : inout std_ulogic; dvi_iic_scl : inout std_logic; dvi_iic_sda : inout std_logic; tft_lcd_data : out std_logic_vector(11 downto 0); tft_lcd_clk_p : out std_ulogic; tft_lcd_clk_n : out std_ulogic; tft_lcd_hsync : out std_ulogic; tft_lcd_vsync : out std_ulogic; tft_lcd_de : out std_ulogic; tft_lcd_reset_b : out std_ulogic; sace_usb_a : out std_logic_vector(6 downto 0); sace_mpce : out std_ulogic; sace_usb_d : inout std_logic_vector(15 downto 0); sace_usb_oen : out std_ulogic; sace_usb_wen : out std_ulogic; sysace_mpirq : in std_ulogic ); end; architecture rtl of leon3mp is component ODDR generic ( DDR_CLK_EDGE : string := "OPPOSITE_EDGE"; -- INIT : bit := '0'; SRTYPE : string := "SYNC"); port ( Q : out std_ulogic; C : in std_ulogic; CE : in std_ulogic; D1 : in std_ulogic; D2 : in std_ulogic; R : in std_ulogic; S : in std_ulogic ); end component; component svga2ch7301c generic ( tech : integer := 0; idf : integer := 0; dynamic : integer := 0 ); port ( clk : in std_ulogic; rstn : in std_ulogic; clksel : in std_logic_vector(1 downto 0); vgao : in apbvga_out_type; vgaclk_fb : in std_ulogic; clk25_fb : in std_ulogic; clk40_fb : in std_ulogic; clk65_fb : in std_ulogic; vgaclk : out std_ulogic; clk25 : out std_ulogic; clk40 : out std_ulogic; clk65 : out std_ulogic; dclk_p : out std_ulogic; dclk_n : out std_ulogic; locked : out std_ulogic; data : out std_logic_vector(11 downto 0); hsync : out std_ulogic; vsync : out std_ulogic; de : out std_ulogic ); end component; constant blength : integer := 12; constant fifodepth : integer := 8; constant maxahbm : integer := NCPU+CFG_AHB_UART +CFG_GRETH+CFG_AHB_JTAG+CFG_SVGA_ENABLE; signal ddr_clk_fb : std_logic; signal vcc, gnd : std_logic_vector(4 downto 0); signal memi : memory_in_type; signal memo : memory_out_type; signal wpo : wprot_out_type; signal sdi : sdctrl_in_type; signal sdo : sdctrl_out_type; signal sdo2 : sdctrl_out_type; signal apbi : apb_slv_in_type; signal apbo : apb_slv_out_vector := (others => apb_none); signal ahbsi : ahb_slv_in_type; signal ahbso : ahb_slv_out_vector := (others => ahbs_none); signal ahbmi : ahb_mst_in_type; signal ahbmo : ahb_mst_out_vector := (others => ahbm_none); signal clkm, rstn, rstraw, srclkl : std_ulogic; signal clk_200 : std_ulogic; signal clk25, clk40, clk65 : std_ulogic; signal cgi, cgi2 : clkgen_in_type; signal cgo, cgo2 : clkgen_out_type; signal u1i, u2i, dui : uart_in_type; signal u1o, u2o, duo : uart_out_type; signal irqi : irq_in_vector(0 to NCPU-1); signal irqo : irq_out_vector(0 to NCPU-1); signal dbgi : l3_debug_in_vector(0 to NCPU-1); signal dbgo : l3_debug_out_vector(0 to NCPU-1); signal dsui : dsu_in_type; signal dsuo : dsu_out_type; signal ethi, ethi1, ethi2 : eth_in_type; signal etho, etho1, etho2 : eth_out_type; signal gpti : gptimer_in_type; signal gpto : gptimer_out_type; signal gpioi : gpio_in_type; signal gpioo : gpio_out_type; signal clklock, lock, lclk, clkml, rst, ndsuact : std_ulogic; signal tck, tckn, tms, tdi, tdo : std_ulogic; signal ddrclk, ddrrst : std_ulogic; signal egtx_clk_fb : std_ulogic; signal egtx_clk, legtx_clk, l2egtx_clk : std_ulogic; signal kbdi : ps2_in_type; signal kbdo : ps2_out_type; signal moui : ps2_in_type; signal mouo : ps2_out_type; signal vgao : apbvga_out_type; signal lcd_datal : std_logic_vector(11 downto 0); signal lcd_hsyncl, lcd_vsyncl, lcd_del, lcd_reset_bl : std_ulogic; signal clk_sel : std_logic_vector(1 downto 0); signal vgalock : std_ulogic; signal clkvga, clkvga_p, clkvga_n : std_ulogic; signal i2ci, dvi_i2ci : i2c_in_type; signal i2co, dvi_i2co : i2c_out_type; constant BOARD_FREQ_200 : integer := 200000; -- input frequency in KHz constant BOARD_FREQ : integer := 100000; -- input frequency in KHz constant CPU_FREQ : integer := BOARD_FREQ * CFG_CLKMUL / CFG_CLKDIV; -- cpu frequency in KHz constant I2C_FILTER : integer := (CPU_FREQ*5+50000)/100000+1; constant IOAEN : integer := CFG_DDR2SP + CFG_GRACECTRL; signal stati : ahbstat_in_type; signal ssrclkfb : std_ulogic; -- Used for connecting input/output signals to the DDR3 controller signal migi : mig_app_in_type; signal migo : mig_app_out_type; signal phy_init_done : std_ulogic; signal clk0_tb, rst0_tb, rst0_tbn : std_ulogic; signal sysmoni : grsysmon_in_type; signal sysmono : grsysmon_out_type; signal clkace : std_ulogic; signal acei : gracectrl_in_type; signal aceo : gracectrl_out_type; attribute syn_keep : boolean; attribute syn_preserve : boolean; attribute syn_keep of clkml : signal is true; attribute syn_preserve of clkml : signal is true; attribute syn_keep of clkm : signal is true; attribute syn_preserve of clkm : signal is true; attribute syn_keep of egtx_clk : signal is true; attribute syn_preserve of egtx_clk : signal is true; attribute syn_keep of clkvga : signal is true; attribute syn_preserve of clkvga : signal is true; attribute syn_keep of clk25 : signal is true; attribute syn_preserve of clk25 : signal is true; attribute syn_keep of clk40 : signal is true; attribute syn_preserve of clk40 : signal is true; attribute syn_keep of clk65 : signal is true; attribute syn_preserve of clk65 : signal is true; attribute syn_keep of clk_200 : signal is true; attribute syn_preserve of clk_200 : signal is true; attribute syn_preserve of phy_init_done : signal is true; attribute keep : boolean; attribute keep of lock : signal is true; attribute keep of clkml : signal is true; attribute keep of clkm : signal is true; attribute keep of egtx_clk : signal is true; attribute keep of clkvga : signal is true; attribute keep of clk25 : signal is true; attribute keep of clk40 : signal is true; attribute keep of clk65 : signal is true; attribute keep of clk_200 : signal is true; attribute keep of phy_init_done : signal is true; attribute syn_noprune : boolean; attribute syn_noprune of sysace_clk_in_pad : label is true; begin usb_csn <= '1'; usb_rstn <= rstn; rst0_tbn <= not rst0_tb; ---------------------------------------------------------------------- --- Reset and Clock generation ------------------------------------- ---------------------------------------------------------------------- vcc <= (others => '1'); gnd <= (others => '0'); cgi.pllctrl <= "00"; cgi.pllrst <= rstraw; cgi.pllref <= ssrclkfb; ssrref_pad : clkpad generic map (tech => padtech) port map (sram_clk_fb, ssrclkfb); clk_pad : clkpad generic map (tech => padtech, arch => 2) port map (clk_100, lclk); clk200_pad : clkpad_ds generic map (tech => padtech, level => lvds, voltage => x25v) port map (clk_200_p, clk_200_n, clk_200); srclk_pad : outpad generic map (tech => padtech, slew => 1, strength => 24) port map (sram_clk, srclkl); sysace_clk_in_pad : clkpad generic map (tech => padtech) port map (sysace_clk_in, clkace); clkgen0 : clkgen -- system clock generator generic map (CFG_FABTECH, CFG_CLKMUL, CFG_CLKDIV, 1, 0, 0, 0, 0, BOARD_FREQ, 0) port map (lclk, gnd(0), clkm, open, open, srclkl, open, cgi, cgo); gclk : if CFG_GRETH1G /= 0 generate clkgen1 : clkgen -- Ethernet 1G PHY clock generator generic map (CFG_FABTECH, 5, 4, 0, 0, 0, 0, 0, BOARD_FREQ, 0) port map (lclk, gnd(0), egtx_clk, open, open, open, open, cgi2, cgo2); cgi2.pllctrl <= "00"; cgi2.pllrst <= rstraw; --cgi2.pllref <= egtx_clk_fb; x0 : ODDR port map ( Q => phy_gtx_clk, C => egtx_clk, CE => vcc(0), -- D1 => gnd(0), D2 => vcc(0), R => gnd(0), S => gnd(0)); D1 => vcc(0), D2 => gnd(0), R => gnd(0), S => gnd(0)); end generate; nogclk : if CFG_GRETH1G = 0 generate cgo2.clklock <= '1'; phy_gtx_clk <= '0'; end generate; resetn_pad : inpad generic map (tech => padtech) port map (sys_rst_in, rst); rst0 : rstgen -- reset generator port map (rst, clkm, clklock, rstn, rstraw); clklock <= lock and cgo.clklock and cgo2.clklock and vgalock; ---------------------------------------------------------------------- --- AHB CONTROLLER -------------------------------------------------- ---------------------------------------------------------------------- ahb0 : ahbctrl -- AHB arbiter/multiplexer generic map (defmast => CFG_DEFMST, split => CFG_SPLIT, rrobin => CFG_RROBIN, ioaddr => CFG_AHBIO, devid => XILINX_ML501, ioen => IOAEN, nahbm => maxahbm, nahbs => 8) port map (rstn, clkm, ahbmi, ahbmo, ahbsi, ahbso); ---------------------------------------------------------------------- --- LEON3 processor and DSU ----------------------------------------- ---------------------------------------------------------------------- l3 : if CFG_LEON3 = 1 generate cpu : for i in 0 to NCPU-1 generate u0 : leon3s -- LEON3 processor generic map (i, fabtech, memtech, CFG_NWIN, CFG_DSU, CFG_FPU, CFG_V8, 0, CFG_MAC, pclow, CFG_NOTAG, CFG_NWP, CFG_ICEN, CFG_IREPL, CFG_ISETS, CFG_ILINE, CFG_ISETSZ, CFG_ILOCK, CFG_DCEN, CFG_DREPL, CFG_DSETS, CFG_DLINE, CFG_DSETSZ, CFG_DLOCK, CFG_DSNOOP, CFG_ILRAMEN, CFG_ILRAMSZ, CFG_ILRAMADDR, CFG_DLRAMEN, CFG_DLRAMSZ, CFG_DLRAMADDR, CFG_MMUEN, CFG_ITLBNUM, CFG_DTLBNUM, CFG_TLB_TYPE, CFG_TLB_REP, CFG_LDDEL, disas, CFG_ITBSZ, CFG_PWD, CFG_SVT, CFG_RSTADDR, NCPU-1, CFG_DFIXED, CFG_SCAN, CFG_MMU_PAGE, CFG_BP, CFG_NP_ASI, CFG_WRPSR) port map (clkm, rstn, ahbmi, ahbmo(i), ahbsi, ahbso, irqi(i), irqo(i), dbgi(i), dbgo(i)); end generate; bus_error(0) <= not dbgo(0).error; bus_error(1) <= rstn; dsugen : if CFG_DSU = 1 generate dsu0 : dsu3 -- LEON3 Debug Support Unit generic map (hindex => 2, haddr => 16#900#, hmask => 16#F00#, ncpu => NCPU, tbits => 30, tech => memtech, irq => 0, kbytes => CFG_ATBSZ) port map (rstn, clkm, ahbmi, ahbsi, ahbso(2), dbgo, dbgi, dsui, dsuo); dsui.enable <= '1'; -- dsubre_pad : inpad generic map (tech => padtech) port map (dsubre, dsui.break); dsui.break <= gpioo.val(11); -- South Button -- dsuact_pad : outpad generic map (tech => padtech) port map (dsuact, ndsuact); led(4) <= dsuo.active; end generate; end generate; nodsu : if CFG_DSU = 0 generate dsuo.tstop <= '0'; dsuo.active <= '0'; end generate; dcomgen : if CFG_AHB_UART = 1 generate dcom0: ahbuart -- Debug UART generic map (hindex => NCPU, pindex => 7, paddr => 7) port map (rstn, clkm, dui, duo, apbi, apbo(7), ahbmi, ahbmo(NCPU)); -- dsurx_pad : inpad generic map (tech => padtech) port map (rxd1, dui.rxd); -- dsutx_pad : outpad generic map (tech => padtech) port map (txd1, duo.txd); dui.rxd <= rxd1 when gpioo.val(0) = '1' else '1'; end generate; txd1 <= duo.txd when gpioo.val(0) = '1' else u1o.txd; ahbjtaggen0 :if CFG_AHB_JTAG = 1 generate ahbjtag0 : ahbjtag generic map(tech => fabtech, hindex => NCPU+CFG_AHB_UART) port map(rstn, clkm, tck, tms, tdi, tdo, ahbmi, ahbmo(NCPU+CFG_AHB_UART), open, open, open, open, open, open, open, gnd(0)); end generate; ---------------------------------------------------------------------- --- Memory controllers ---------------------------------------------- ---------------------------------------------------------------------- memi.writen <= '1'; memi.wrn <= "1111"; memi.bwidth <= "01"; memi.brdyn <= '1'; memi.bexcn <= '1'; mctrl0 : if CFG_MCTRL_LEON2 = 1 generate mctrl0 : mctrl generic map (hindex => 3, pindex => 0, ramaddr => 16#400# + (CFG_DDR2SP+CFG_MIG_DDR2)*16#800#, rammask => 16#FE0#, paddr => 0, srbanks => 1, ram8 => CFG_MCTRL_RAM8BIT, ram16 => CFG_MCTRL_RAM16BIT, sden => CFG_MCTRL_SDEN, invclk => CFG_MCTRL_INVCLK, sepbus => CFG_MCTRL_SEPBUS) port map (rstn, clkm, memi, memo, ahbsi, ahbso(3), apbi, apbo(0), wpo, open); end generate; flash_adv_n_pad : outpad generic map (tech => padtech) port map (flash_adv_n, gnd(0)); sram_adv_ld_n_pad : outpad generic map (tech => padtech) port map (sram_adv_ld_n, gnd(0)); sram_mode_pad : outpad generic map (tech => padtech) port map (sram_mode, gnd(0)); addr_pad : outpadv generic map (width => 24, tech => padtech) port map (sram_flash_addr, memo.address(24 downto 1)); rams_pad : outpad generic map ( tech => padtech) port map (sram_cen, memo.ramsn(0)); roms_pad : outpad generic map (tech => padtech) port map (flash_ce, memo.romsn(0)); ramoen_pad : outpad generic map (tech => padtech) port map (sram_oen, memo.ramoen(0)); flash_oen_pad : outpad generic map (tech => padtech) port map (flash_oen, memo.oen); --pragma translate_off iosn_pad : outpad generic map (tech => padtech) port map (iosn, memo.iosn); --pragma translate_on rwen_pad : outpadv generic map (width => 2, tech => padtech) port map (sram_bw(0 to 1), memo.wrn(3 downto 2)); rwen_pad2 : outpadv generic map (width => 2, tech => padtech) port map (sram_bw(2 to 3), memo.wrn(1 downto 0)); wri_pad : outpad generic map (tech => padtech) port map (sram_flash_we_n, memo.writen); data_pads : iopadvv generic map (tech => padtech, width => 16) port map (sram_flash_data(15 downto 0), memo.data(31 downto 16), memo.vbdrive(31 downto 16), memi.data(31 downto 16)); data_pads2 : iopadvv generic map (tech => padtech, width => 16) port map (sram_flash_data(31 downto 16), memo.data(15 downto 0), memo.vbdrive(15 downto 0), memi.data(15 downto 0)); migsp0 : if (CFG_MIG_DDR2 = 1) generate ahb2mig0 : entity work.ahb2mig_ml50x generic map ( hindex => 0, haddr => 16#400#, hmask => MIGHMASK, MHz => 400, Mbyte => 512, nosync => 0) --boolean'pos(CFG_MIG_CLK4=12)) --CFG_CLKDIV/12) port map ( rst_ahb => rstn, rst_ddr => rst0_tbn, clk_ahb => clkm, clk_ddr => clk0_tb, ahbsi => ahbsi, ahbso => ahbso(0), migi => migi, migo => migo); migv5 : mig_36_1 generic map ( CKE_WIDTH => CKE_WIDTH, CS_NUM => CS_NUM, CS_WIDTH => CS_WIDTH, CS_BITS => CS_BITS, COL_WIDTH => COL_WIDTH, ROW_WIDTH => ROW_WIDTH, NOCLK200 => true, SIM_ONLY => 1) port map( ddr2_dq => ddr2_dq(DQ_WIDTH-1 downto 0), ddr2_a => ddr2_a(ROW_WIDTH-1 downto 0), ddr2_ba => ddr2_ba(1 downto 0), ddr2_ras_n => ddr2_ras_n, ddr2_cas_n => ddr2_cas_n, ddr2_we_n => ddr2_we_n, ddr2_cs_n => ddr2_cs_n(CS_NUM-1 downto 0), ddr2_odt => ddr2_odt(0 downto 0), ddr2_cke => ddr2_cke(CKE_WIDTH-1 downto 0), ddr2_dm => ddr2_dm(DM_WIDTH-1 downto 0), sys_clk => clk_200, idly_clk_200 => clk_200, sys_rst_n => rstraw, phy_init_done => phy_init_done, rst0_tb => rst0_tb, clk0_tb => clk0_tb, app_wdf_afull => migo.app_wdf_afull, app_af_afull => migo.app_af_afull, rd_data_valid => migo.app_rd_data_valid, app_wdf_wren => migi.app_wdf_wren, app_af_wren => migi.app_en, app_af_addr => migi.app_addr, app_af_cmd => migi.app_cmd, rd_data_fifo_out => migo.app_rd_data, app_wdf_data => migi.app_wdf_data, app_wdf_mask_data => migi.app_wdf_mask, ddr2_dqs => ddr2_dqs(DQS_WIDTH-1 downto 0), ddr2_dqs_n => ddr2_dqs_n(DQS_WIDTH-1 downto 0), ddr2_ck => ddr2_ck((CLK_WIDTH-1) downto 0), ddr2_ck_n => ddr2_ck_n((CLK_WIDTH-1) downto 0) ); lock <= phy_init_done; led(5) <= phy_init_done; ddr2_a(13) <= '0'; ddr2_odt(1) <= '0'; ddr2_cs_n(1) <= '0'; end generate; ddrsp0 : if (CFG_DDR2SP /= 0) and (CFG_MIG_DDR2 = 0) generate ddrc0 : ddr2spa generic map ( fabtech => fabtech, memtech => memtech, hindex => 0, haddr => 16#400#, hmask => 16#E00#, ioaddr => 1, pwron => CFG_DDR2SP_INIT, MHz => BOARD_FREQ_200/1000, TRFC => CFG_DDR2SP_TRFC, clkmul => CFG_DDR2SP_FREQ/10, clkdiv => 20, ahbfreq => CPU_FREQ/1000, col => CFG_DDR2SP_COL, Mbyte => CFG_DDR2SP_SIZE, ddrbits => 64, ddelayb0 => CFG_DDR2SP_DELAY0, ddelayb1 => CFG_DDR2SP_DELAY1, ddelayb2 => CFG_DDR2SP_DELAY2, ddelayb3 => CFG_DDR2SP_DELAY3, ddelayb4 => CFG_DDR2SP_DELAY4, ddelayb5 => CFG_DDR2SP_DELAY5, ddelayb6 => CFG_DDR2SP_DELAY6, ddelayb7 => CFG_DDR2SP_DELAY7, numidelctrl => 1, norefclk => 0, odten => 3, nclk => 2, eightbanks => 1) port map ( rst, rstn, clk_200, clkm, clk_200, lock, clkml, clkml, ahbsi, ahbso(0), ddr2_ck, ddr2_ck_n, ddr_clk_fb, ddr_clk_fb, ddr2_cke, ddr2_cs_n, ddr2_we_n, ddr2_ras_n, ddr2_cas_n, ddr2_dm, ddr2_dqs, ddr2_dqs_n, ddr2_a, ddr2_ba, ddr2_dq, ddr2_odt); end generate; noddr : if (CFG_DDR2SP = 0) and (CFG_MIG_DDR2 = 0) generate lock <= '1'; end generate; ---------------------------------------------------------------------- --- System ACE I/F Controller --------------------------------------- ---------------------------------------------------------------------- grace: if CFG_GRACECTRL = 1 generate grace0 : gracectrl generic map (hindex => 4, hirq => 3, haddr => 16#002#, hmask => 16#fff#, split => CFG_SPLIT) port map (rstn, clkm, clkace, ahbsi, ahbso(4), acei, aceo); end generate; nograce: if CFG_GRACECTRL /= 1 generate aceo <= gracectrl_none; end generate; sace_usb_a_pads : outpadv generic map (width => 7, tech => padtech) port map (sace_usb_a, aceo.addr); sace_mpce_pad : outpad generic map (tech => padtech) port map (sace_mpce, aceo.cen); sace_usb_d_pads : iopadv generic map (tech => padtech, width => 16) port map (sace_usb_d, aceo.do, aceo.doen, acei.di); sace_usb_oen_pad : outpad generic map (tech => padtech) port map (sace_usb_oen, aceo.oen); sace_usb_wen_pad : outpad generic map (tech => padtech) port map (sace_usb_wen, aceo.wen); sysace_mpirq_pad : inpad generic map (tech => padtech) port map (sysace_mpirq, acei.irq); ---------------------------------------------------------------------- --- APB Bridge and various periherals ------------------------------- ---------------------------------------------------------------------- bpromgen : if CFG_AHBROMEN /= 0 generate brom : entity work.ahbrom generic map (hindex => 6, haddr => CFG_AHBRODDR, pipe => CFG_AHBROPIP) port map ( rstn, clkm, ahbsi, ahbso(6)); end generate; ---------------------------------------------------------------------- --- APB Bridge and various periherals ------------------------------- ---------------------------------------------------------------------- apb0 : apbctrl -- AHB/APB bridge generic map (hindex => 1, haddr => CFG_APBADDR, nslaves => 16) port map (rstn, clkm, ahbsi, ahbso(1), apbi, apbo ); ua1 : if CFG_UART1_ENABLE /= 0 generate uart1 : apbuart -- UART 1 generic map (pindex => 1, paddr => 1, pirq => 2, console => dbguart, fifosize => CFG_UART1_FIFO) port map (rstn, clkm, apbi, apbo(1), u1i, u1o); u1i.extclk <= '0'; u1i.ctsn <= '0'; u1i.rxd <= rxd1 when gpioo.val(0) = '0' else '1'; end generate; led(0) <= gpioo.val(0); led(1) <= not rxd1; led(2) <= not duo.txd when gpioo.val(0) = '1' else not u1o.txd; led (12 downto 6) <= (others => '0'); irqctrl : if CFG_IRQ3_ENABLE /= 0 generate irqctrl0 : irqmp -- interrupt controller generic map (pindex => 2, paddr => 2, ncpu => NCPU) port map (rstn, clkm, apbi, apbo(2), irqo, irqi); end generate; irq3 : if CFG_IRQ3_ENABLE = 0 generate x : for i in 0 to NCPU-1 generate irqi(i).irl <= "0000"; end generate; apbo(2) <= apb_none; end generate; gpt : if CFG_GPT_ENABLE /= 0 generate timer0 : gptimer -- timer unit generic map (pindex => 3, paddr => 3, pirq => CFG_GPT_IRQ, sepirq => CFG_GPT_SEPIRQ, sbits => CFG_GPT_SW, ntimers => CFG_GPT_NTIM, nbits => CFG_GPT_TW) port map (rstn, clkm, apbi, apbo(3), gpti, gpto); gpti.dhalt <= dsuo.tstop; gpti.extclk <= '0'; led(3) <= gpto.wdog; end generate; nogpt : if CFG_GPT_ENABLE = 0 generate apbo(3) <= apb_none; end generate; kbd : if CFG_KBD_ENABLE /= 0 generate ps21 : apbps2 generic map(pindex => 4, paddr => 4, pirq => 4) port map(rstn, clkm, apbi, apbo(4), moui, mouo); ps20 : apbps2 generic map(pindex => 5, paddr => 5, pirq => 5) port map(rstn, clkm, apbi, apbo(5), kbdi, kbdo); end generate; nokbd : if CFG_KBD_ENABLE = 0 generate apbo(5) <= apb_none; kbdo <= ps2o_none; end generate; kbdclk_pad : iopad generic map (tech => padtech) port map (ps2_keyb_clk,kbdo.ps2_clk_o, kbdo.ps2_clk_oe, kbdi.ps2_clk_i); kbdata_pad : iopad generic map (tech => padtech) port map (ps2_keyb_data, kbdo.ps2_data_o, kbdo.ps2_data_oe, kbdi.ps2_data_i); mouclk_pad : iopad generic map (tech => padtech) port map (ps2_mouse_clk, mouo.ps2_clk_o, mouo.ps2_clk_oe, moui.ps2_clk_i); mouata_pad : iopad generic map (tech => padtech) port map (ps2_mouse_data, mouo.ps2_data_o, mouo.ps2_data_oe, moui.ps2_data_i); vga : if CFG_VGA_ENABLE /= 0 generate vga0 : apbvga generic map(memtech => memtech, pindex => 6, paddr => 6) port map(rstn, clkm, clkvga, apbi, apbo(6), vgao); clk_sel <= "00"; end generate; svga : if CFG_SVGA_ENABLE /= 0 generate svga0 : svgactrl generic map(memtech => memtech, pindex => 6, paddr => 6, hindex => CFG_NCPU+CFG_AHB_UART+CFG_AHB_JTAG, clk0 => 40000, clk1 => 40000, clk2 => 25000, clk3 => 15385, burstlen => 6) port map(rstn, clkm, clkvga, apbi, apbo(6), vgao, ahbmi, ahbmo(CFG_NCPU+CFG_AHB_UART+CFG_AHB_JTAG), clk_sel); end generate; vgadvi : if (CFG_VGA_ENABLE + CFG_SVGA_ENABLE) /= 0 generate dvi0 : svga2ch7301c generic map (tech => fabtech, dynamic => 1) port map (lclk, rstraw, clk_sel, vgao, clkvga, clk25, clk40, clk65, clkvga, clk25, clk40, clk65, clkvga_p, clkvga_n, vgalock, lcd_datal, lcd_hsyncl, lcd_vsyncl, lcd_del); i2cdvi : i2cmst generic map (pindex => 9, paddr => 9, pmask => 16#FFF#, pirq => 6, filter => I2C_FILTER) port map (rstn, clkm, apbi, apbo(9), dvi_i2ci, dvi_i2co); end generate; novga : if (CFG_VGA_ENABLE + CFG_SVGA_ENABLE) = 0 generate apbo(6) <= apb_none; vgalock <= '1'; lcd_datal <= (others => '0'); clkvga_p <= '0'; clkvga_n <= '0'; lcd_hsyncl <= '0'; lcd_vsyncl <= '0'; lcd_del <= '0'; dvi_i2co.scloen <= '1'; dvi_i2co.sdaoen <= '1'; end generate; tft_lcd_data_pad : outpadv generic map (width => 12, tech => padtech) port map (tft_lcd_data, lcd_datal); tft_lcd_clkp_pad : outpad generic map (tech => padtech) port map (tft_lcd_clk_p, clkvga_p); tft_lcd_clkn_pad : outpad generic map (tech => padtech) port map (tft_lcd_clk_n, clkvga_n); tft_lcd_hsync_pad : outpad generic map (tech => padtech) port map (tft_lcd_hsync, lcd_hsyncl); tft_lcd_vsync_pad : outpad generic map (tech => padtech) port map (tft_lcd_vsync, lcd_vsyncl); tft_lcd_de_pad : outpad generic map (tech => padtech) port map (tft_lcd_de, lcd_del); tft_lcd_reset_pad : outpad generic map (tech => padtech) port map (tft_lcd_reset_b, rstn); dvi_i2c_scl_pad : iopad generic map (tech => padtech) port map (dvi_iic_scl, dvi_i2co.scl, dvi_i2co.scloen, dvi_i2ci.scl); dvi_i2c_sda_pad : iopad generic map (tech => padtech) port map (dvi_iic_sda, dvi_i2co.sda, dvi_i2co.sdaoen, dvi_i2ci.sda); gpio0 : if CFG_GRGPIO_ENABLE /= 0 generate -- GPIO unit grgpio0: grgpio generic map(pindex => 8, paddr => 8, imask => 16#00F0#, nbits => 14) port map(rst => rstn, clk => clkm, apbi => apbi, apbo => apbo(8), gpioi => gpioi, gpioo => gpioo); gpio_pads : iopadvv generic map (tech => padtech, width => 14) port map (gpio, gpioo.dout(13 downto 0), gpioo.oen(13 downto 0), gpioi.din(13 downto 0)); end generate; ahbs : if CFG_AHBSTAT = 1 generate -- AHB status register ahbstat0 : ahbstat generic map (pindex => 15, paddr => 15, pirq => 7, nftslv => CFG_AHBSTATN) port map (rstn, clkm, ahbmi, ahbsi, stati, apbi, apbo(15)); end generate; i2cm: if CFG_I2C_ENABLE = 1 generate -- I2C master i2c0 : i2cmst generic map (pindex => 12, paddr => 12, pmask => 16#FFF#, pirq => 11, filter => I2C_FILTER) port map (rstn, clkm, apbi, apbo(12), i2ci, i2co); i2c_scl_pad : iopad generic map (tech => padtech) port map (iic_scl, i2co.scl, i2co.scloen, i2ci.scl); i2c_sda_pad : iopad generic map (tech => padtech) port map (iic_sda, i2co.sda, i2co.sdaoen, i2ci.sda); end generate i2cm; ----------------------------------------------------------------------- --- ETHERNET --------------------------------------------------------- ----------------------------------------------------------------------- eth1 : if CFG_GRETH = 1 generate -- Gaisler ethernet MAC e1 : grethm generic map(hindex => NCPU+CFG_AHB_UART+CFG_AHB_JTAG+CFG_SVGA_ENABLE, pindex => 11, paddr => 11, pirq => 12, memtech => memtech, mdcscaler => CPU_FREQ/1000, enable_mdio => 1, fifosize => CFG_ETH_FIFO, nsync => 1, edcl => CFG_DSU_ETH, edclbufsz => CFG_ETH_BUF, macaddrh => CFG_ETH_ENM, macaddrl => CFG_ETH_ENL, phyrstadr => 7, ipaddrh => CFG_ETH_IPM, ipaddrl => CFG_ETH_IPL, giga => CFG_GRETH1G, enable_mdint => 1) port map( rst => rstn, clk => clkm, ahbmi => ahbmi, ahbmo => ahbmo(NCPU+CFG_AHB_UART+CFG_AHB_JTAG+CFG_SVGA_ENABLE), apbi => apbi, apbo => apbo(11), ethi => ethi, etho => etho); emdio_pad : iopad generic map (tech => padtech) port map (phy_mii_data, etho.mdio_o, etho.mdio_oe, ethi.mdio_i); etxc_pad : clkpad generic map (tech => padtech, arch => 2) port map (phy_tx_clk, ethi.tx_clk); erxc_pad : clkpad generic map (tech => padtech, arch => 2) port map (phy_rx_clk, ethi.rx_clk); erxd_pad : inpadv generic map (tech => padtech, width => 8) port map (phy_rx_data, ethi.rxd(7 downto 0)); erxdv_pad : inpad generic map (tech => padtech) port map (phy_dv, ethi.rx_dv); erxer_pad : inpad generic map (tech => padtech) port map (phy_rx_er, ethi.rx_er); erxco_pad : inpad generic map (tech => padtech) port map (phy_col, ethi.rx_col); erxcr_pad : inpad generic map (tech => padtech) port map (phy_crs, ethi.rx_crs); etxd_pad : outpadv generic map (tech => padtech, width => 8) port map (phy_tx_data, etho.txd(7 downto 0)); etxen_pad : outpad generic map (tech => padtech) port map ( phy_tx_en, etho.tx_en); etxer_pad : outpad generic map (tech => padtech) port map (phy_tx_er, etho.tx_er); emdc_pad : outpad generic map (tech => padtech) port map (phy_mii_clk, etho.mdc); erst_pad : outpad generic map (tech => padtech) port map (phy_rst_n, rstn); emdintn_pad : inpad generic map (tech => padtech) port map (phy_int, ethi.mdint); ethi.gtx_clk <= egtx_clk; end generate; ----------------------------------------------------------------------- --- SYSTEM MONITOR --------------------------------------------------- ----------------------------------------------------------------------- grsmon: if CFG_GRSYSMON = 1 generate sysm0 : grsysmon generic map (tech => fabtech, hindex => 5, hirq => 10, caddr => 16#003#, cmask => 16#fff#, saddr => 16#004#, smask => 16#ffe#, split => CFG_SPLIT, extconvst => 0, wrdalign => 1, INIT_40 => X"0000", INIT_41 => X"0000", INIT_42 => X"0800", INIT_43 => X"0000", INIT_44 => X"0000", INIT_45 => X"0000", INIT_46 => X"0000", INIT_47 => X"0000", INIT_48 => X"0000", INIT_49 => X"0000", INIT_4A => X"0000", INIT_4B => X"0000", INIT_4C => X"0000", INIT_4D => X"0000", INIT_4E => X"0000", INIT_4F => X"0000", INIT_50 => X"0000", INIT_51 => X"0000", INIT_52 => X"0000", INIT_53 => X"0000", INIT_54 => X"0000", INIT_55 => X"0000", INIT_56 => X"0000", INIT_57 => X"0000", SIM_MONITOR_FILE => "sysmon.txt") port map (rstn, clkm, ahbsi, ahbso(5), sysmoni, sysmono); sysmoni <= grsysmon_in_gnd; end generate grsmon; ----------------------------------------------------------------------- --- AHB RAM ---------------------------------------------------------- ----------------------------------------------------------------------- ocram : if CFG_AHBRAMEN = 1 generate ahbram0 : ahbram generic map (hindex => 7, haddr => CFG_AHBRADDR, tech => CFG_MEMTECH, kbytes => CFG_AHBRSZ, pipe => CFG_AHBRPIPE) port map ( rstn, clkm, ahbsi, ahbso(7)); end generate; ----------------------------------------------------------------------- --- AHB DEBUG -------------------------------------------------------- ----------------------------------------------------------------------- -- dma0 : ahbdma -- generic map (hindex => CFG_NCPU+CFG_AHB_UART+CFG_GRETH+CFG_AHB_JTAG, -- pindex => 13, paddr => 13, dbuf => 6) -- port map (rstn, clkm, apbi, apbo(13), ahbmi, -- ahbmo(CFG_NCPU+CFG_AHB_UART+CFG_AHB_JTAG+CFG_SVGA_ENABLE+CFG_GRETH)); -- at0 : ahbtrace -- generic map ( hindex => 7, ioaddr => 16#200#, iomask => 16#E00#, -- tech => memtech, irq => 0, kbytes => 8) -- port map ( rstn, clkm, ahbmi, ahbsi, ahbso(7)); ----------------------------------------------------------------------- --- Drive unused bus elements --------------------------------------- ----------------------------------------------------------------------- -- nam1 : for i in (NCPU+CFG_AHB_UART+CFG_AHB_JTAG+CFG_SVGA_ENABLE+CFG_GRETH) to NAHBMST-1 generate -- ahbmo(i) <= ahbm_none; -- end generate; -- nap0 : for i in 11 to NAPBSLV-1 generate apbo(i) <= apb_none; end generate; -- nah0 : for i in 8 to NAHBSLV-1 generate ahbso(i) <= ahbs_none; end generate; ----------------------------------------------------------------------- --- Boot message ---------------------------------------------------- ----------------------------------------------------------------------- -- pragma translate_off x : report_design generic map ( msg1 => system_table(XILINX_ML501), fabtech => tech_table(fabtech), memtech => tech_table(memtech), mdel => 1 ); -- pragma translate_on end;
-- William Fan -- 2/19/2011 -- 2 Digit Timer RTL entity 2dtimer is generic (fclk: integer := 50_000_000); --50MHz port (ena, clk, rst: in bit; ssdL, ssdR: out bit_vector(6 downto 0)); end entity; architecture tdt of 2dtimer is begin process (clk, rst, ena) variable ncounter: natural range 0 to fclk := 0; variable counterR: natural range 0 to 10 := 0; variable counterL: natural range 0 to 6 := 0; begin --- timer counter if (rst='1') then ncounter := 0; counterR := 0; counterL := 0; elsif (rst='0') then if (clk'event and clk='1') then if (ena='1' and counterL<6) then ncounter := ncounter + 1; if (ncounter=fclk) then ncounter := 0; counterR := counterR + 1; end if; if (counterR=10) then counterR := 0; counterL := counterL + 1; end if; end if; end if; end if; --- LCD driver case counterR is when 0 => ssdR<="0000001"; when 1 => ssdR<="1001111"; when 2 => ssdR<="0010010"; when 3 => ssdR<="0000110"; when 4 => ssdR<="1001100"; when 5 => ssdR<="0100100"; when 6 => ssdR<="0100000"; when 7 => ssdR<="0001111"; when 8 => ssdR<="0000000"; when 9 => ssdR<="0000100"; when others => ssdR<="0110000"; end case; case counterL is when 0 => ssdL<="0000001"; when 1 => ssdL<="1001111"; when 2 => ssdL<="0010010"; when 3 => ssdL<="0000110"; when 4 => ssdL<="1001100"; when 5 => ssdL<="0100100"; when 6 => ssdL<="0100000"; when others => ssdL<="0110000"; end case; end process; end architecture;
-- comment library ieee; use ieee.std_logic_1164.all; --use work.abc.all; entity enti is generic ( bla : std_ulogic := '1'; bla1 : std_ulogic_vector(1 downto 0) := "-0"; bla2 : natural := 1; bla3 : std_ulogic_vector := "00"); port ( bla4 : in std_ulogic; bla5 : in std_ulogic); end; architecture rtl of enti is begin -- architecture rtl end architecture rtl; architecture bhv of enti is begin -- architecture bhv end architecture bhv; package pd is constant c : natural; end package pd; package body pd is constant c : natural := 1; end package body pd; entity enti2 is end entity enti2; entity enti3 is begin end entity; architecture rtl of enti3 is begin -- architecture rtl end architecture rtl; entity enti4 is end enti4; library ieee; use ieee.std_logic_1164.all; use work.pd.all; architecture Rtl of enti4 is constant c : natural := 1; signal s : std_ulogic := '1'; type t1 is array (0 to 1) of std_ulogic_vector(7 downto 0); type t2 is array (natural range <>) of std_ulogic_vector; function f1 ( signal sig : std_ulogic_vector(1 to 9); constant c : in natural) return boolean is variable v : natural := c; begin return false; end; signal d : std_ulogic_vector(8 downto 0); component compi is generic ( foo : std_ulogic); port ( bar : in std_ulogic); end component compi; begin -- architecture rtl enti_1 : entity work.enti port map ( bla4 => '0', bla5 => '0'); a : s <= '0'; d(1 downto 0) <= '1' & s; g : for i in 1 to 3 generate enti_2 : entity work.enti(rtl) port map ( bla4 => '0', bla5 => not s); foo : if c = 1 generate enti_3 : entity work.enti(bhv) port map ( bla4 => '0', bla5 => not s); enti_4 : compi generic map ( foo => '0') port map ( bar => s); end generate foo; d(2) <= not s; end generate; p : process (s) is constant s1 : integer := 2; begin -- process bla if s = '0' then -- asynchronous reset (active low) elsif rising_edge(s) then -- rising clock edge d(4) <= '1'; else d(4) <= d ( d'left ) nand d(1); end if; assert d = "000000000" report "blubb"; assert d(s1) report "blubb"; assert d(s1) = not d(1) report "blubb"; for i in 0 to 1 loop if i = 0 then assert d(s1) = d(d'left) report "blubb" & integer'image(s1); end if; end loop; -- i while true loop case d is when "111100000" => d <= "000000000"; when "111100001" => d <= (others => '0'); when others => null; end case; end loop; end process p; end architecture rtl;
------------------------------------------------------------------------------ -- This file is a part of the GRLIB VHDL IP LIBRARY -- Copyright (C) 2003 - 2008, Gaisler Research -- Copyright (C) 2008 - 2014, Aeroflex Gaisler -- Copyright (C) 2015 - 2016, Cobham Gaisler -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ----------------------------------------------------------------------------- -- Entity: ddrram -- File: ddrram.vhd -- Author: Magnus Hjorth, Aeroflex Gaisler -- Description: Generic simulation model of DDR SDRAM (JESD79E) ------------------------------------------------------------------------------ --pragma translate_off use std.textio.all; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; library grlib; use grlib.stdio.hread; use grlib.stdlib.all; entity ddrram is generic ( width: integer := 32; abits: integer range 12 to 14 := 12; colbits: integer range 8 to 13 := 8; rowbits: integer range 1 to 14 := 12; implbanks: integer range 1 to 4 := 1; fname: string; lddelay: time := (0 ns); speedbin: integer range 0 to 5 := 0; -- 0:DDR200,1:266,2:333,3:400C,4:400B,5:400A density: integer range 0 to 3 := 0; -- 0:128Mbit 1:256Mbit 2:512Mbit 3:1Gbit / chip igndqs: integer range 0 to 1 := 0 ); port ( ck: in std_ulogic; cke: in std_ulogic; csn: in std_ulogic; rasn: in std_ulogic; casn: in std_ulogic; wen: in std_ulogic; dm: in std_logic_vector(width/8-1 downto 0); ba: in std_logic_vector(1 downto 0); a: in std_logic_vector(abits-1 downto 0); dq: inout std_logic_vector(width-1 downto 0); dqs: inout std_logic_vector(width/8-1 downto 0) ); end; architecture sim of ddrram is type moderegs is record -- Mode register (0) opmode: std_logic_vector(6 downto 0); caslat: std_logic_vector(2 downto 0); bt: std_ulogic; blen: std_logic_vector(2 downto 0); -- Extended mode register (1) opmode1: std_logic_vector(10 downto 0); res1: std_ulogic; ds: std_ulogic; dlldis: std_ulogic; end record; -- Mode registers as signal, useful for debugging signal mr: moderegs; -- Handshaking between command and DQ/DQS processes signal read_en, write_en: boolean := false; signal hcmode: boolean := false; -- Shift DQS/read data one cycle for CL=1.5/2.5 signal hcread_en: boolean := false; -- One cycle earlier for half-cycle mode read preamble gen signal read_data, write_data: std_logic_vector(2*width-1 downto 0); signal write_mask: std_logic_vector(width/4-1 downto 0); signal initdone: boolean := false; -- Small delta-t to adjust calculations for jitter tol. constant deltat: time := 50 ps; -- Timing parameters constant tWR: time := 15 ns; constant tMRD_ck: integer := 2; type timetab is array (0 to 5) of time; constant tRAS : timetab := (50 ns, 45 ns, 42 ns, 40 ns, 40 ns, 40 ns); constant tRP : timetab := (20 ns, 20 ns, 18 ns, 18 ns, 15 ns, 15 ns); constant tRCD: timetab := (20 ns, 20 ns, 18 ns, 18 ns, 15 ns, 15 ns); constant tRRD: timetab := (15 ns, 15 ns, 12 ns, 10 ns, 10 ns, 10 ns); constant tRFC_lt1G: timetab := (80 ns, 75 ns, 72 ns, 70 ns, 70 ns, 70 ns); --Assuming<1Gb constant tRFC_mt1G: time := 120 ns; function tRFC return time is begin if density < 3 then return tRFC_lt1G(speedbin); else return tRFC_mt1G; end if; end tRFC; begin ----------------------------------------------------------------------------- -- Init sequence checker ----------------------------------------------------------------------------- initp: process variable cyctr : integer := 0; procedure checkcmd(crasn,ccasn,cwen: std_ulogic; cba: std_logic_vector(1 downto 0); a10,a8,a0: std_ulogic) is begin wait until rising_edge(ck); cyctr := cyctr+1; while cke='1' and (csn='1' or (rasn='1' and casn='1' and wen='1')) loop wait until rising_edge(ck); cyctr := cyctr+1; end loop; assert cke='1' and csn='0' and rasn=crasn and casn=ccasn and wen=cwen and (cba="--" or cba=ba) and (a10='-' or a10=a(10)) and (a8='-' or a8=a(8)) and (a0='-' or a0=a(0)) report "Wrong command during init sequence" severity warning; end checkcmd; begin initdone <= false; -- Allow cke to be X or U for a while during sim start if is_x(cke) then wait until not is_x(cke); end if; assert cke='0' report "CKE not deasserted on power-up" severity warning; wait until cke/='0' for 200 us; assert cke='0' report "CKE raised with less than 200 us init delay" severity warning; wait until cke/='0' and rising_edge(ck); assert cke='1' and (csn='1' or (rasn='1' and casn='1' and wen='1')); -- Precharge all checkcmd('0','1','0',"--",'1','-','-'); -- EMRS enable DLL checkcmd('0','0','0',"01",'-','-','0'); -- MRS reset DLL checkcmd('0','0','0',"00",'-','1','-'); cyctr := 0; -- 200 cycle NOP -- Precharge all checkcmd('0','1','0',"--",'1','-','-'); assert cyctr >= 200 report "Command issued too quickly after DLL reset" severity warning; -- 2 x auto refresh checkcmd('0','0','1',"--",'-','-','-'); checkcmd('0','0','1',"--",'-','-','-'); -- MRS !reset DLL checkcmd('0','0','0',"00",'-','0','-'); initdone <= true; wait; end process; ----------------------------------------------------------------------------- -- Command state machine ----------------------------------------------------------------------------- cmdp: process(ck) subtype coldata is std_logic_vector(width-1 downto 0); type coldata_arr is array(0 to implbanks*(2**(colbits+rowbits))-1) of coldata; variable memdata: coldata_arr; procedure load_srec is file TCF : text open read_mode is fname; variable L1: line; variable CH : character; variable rectype : std_logic_vector(3 downto 0); variable recaddr : std_logic_vector(31 downto 0); variable reclen : std_logic_vector(7 downto 0); variable recdata : std_logic_vector(0 to 16*8-1); variable col, coloffs, len: integer; begin L1:= new string'(""); while not endfile(TCF) loop readline(TCF,L1); if (L1'length /= 0) then while (not (L1'length=0)) and (L1(L1'left) = ' ') loop std.textio.read(L1,CH); end loop; if L1'length > 0 then read(L1, ch); if (ch = 'S') or (ch = 's') then hread(L1, rectype); hread(L1, reclen); len := to_integer(unsigned(reclen))-1; recaddr := (others => '0'); case rectype is when "0001" => hread(L1, recaddr(15 downto 0)); len := len - 2; when "0010" => hread(L1, recaddr(23 downto 0)); len := len - 3; when "0011" => hread(L1, recaddr); len := len - 4; when others => next; end case; hread(L1, recdata(0 to len*8-1)); col := to_integer(unsigned(recaddr(log2(width/8)+rowbits+colbits+1 downto log2(width/8)))); coloffs := 8*to_integer(unsigned(recaddr(log2(width/8)-1 downto 0))); while len > width/8 loop assert coloffs=0; memdata(col) := recdata(0 to width-1); col := col+1; len := len-width/8; recdata(0 to recdata'length-width-1) := recdata(width to recdata'length-1); end loop; memdata(col)(width-1-coloffs downto width-coloffs-len*8) := recdata(0 to len*8-1); end if; end if; end if; end loop; end load_srec; variable vmr: moderegs := ((others => '0'), "UUU", 'U', "UUU", (others => '0'), '0', '0', '0'); type bankstate is record openrow: integer; opentime: time; closetime: time; writetime: time; autopch: integer; end record; type bankstate_arr is array(natural range <>) of bankstate; variable banks: bankstate_arr(3 downto 0) := (others => (-1, 0 ns, 0 ns, 0 ns, -1)); type int_arr is array(natural range <>) of integer; type dataacc is record r,w: boolean; col: int_arr(0 to 1); bank: integer; end record; type dataacc_arr is array(natural range <>) of dataacc; variable accpipe: dataacc_arr(0 to 9); variable cmd: std_logic_vector(2 downto 0); variable bank: integer; variable colv: unsigned(a'high-1 downto 0); variable alow: unsigned(2 downto 0); variable col: integer; variable prev_re, re: time; variable blen: integer; variable lastref: time := 0 ns; variable i: integer; variable b: boolean; variable mrscount: integer := 0; variable loaded: boolean := false; procedure checktime(got, exp: time; gt: boolean; req: string) is begin assert (got + deltat > exp and gt) or (got-deltat < exp and not gt) report (req & " violation, got: " & tost(got/(1 ps)) & " ps, exp: " & tost(exp/(1 ps)) & "ps") severity warning; end checktime; begin if rising_edge(ck) then -- Update pipe regs prev_re := re; re := now; accpipe(1 to accpipe'high) := accpipe(0 to accpipe'high-1); accpipe(0).r:=false; accpipe(0).w:=false; -- Main command handler cmd := rasn & casn & wen; if mrscount > 0 then mrscount := mrscount-1; assert cke='1' and (csn='1' or cmd="111") report "tMRS violation!" severity warning; end if; if cke='1' and csn='0' and cmd/="111" then checktime(now-lastref, tRFC, true, "tRFC"); end if; if cke='1' and csn='0' then case cmd is when "111" => -- NOP when "011" => -- RAS assert initdone report "Opening row before init sequence done!" severity warning; bank := to_integer(unsigned(ba)); assert banks(bank).openrow < 0 report "Row already open" severity warning; checktime(now-banks(bank).closetime, tRP(speedbin), true, "tRP"); for x in 0 to 3 loop checktime(now-banks(x).opentime, tRRD(speedbin), true, "tRRD"); end loop; banks(bank).openrow := to_integer(unsigned(a(rowbits-1 downto 0))); banks(bank).opentime := now; when "101" | "100" => -- Read/Write bank := to_integer(unsigned(ba)); assert banks(bank).openrow >= 0 report "Row not open" severity error; checktime(now-banks(bank).opentime, tRCD(speedbin), true, "tRCD"); for x in 0 to 3 loop -- Xilinx V4 MIG controller issues multiple overlapping load commands -- during calibration, therefore this assertion is bypassed before -- load-delay has passed. assert (not accpipe(x).r and not accpipe(x).w) or (now < lddelay); end loop; if cmd(0)='1' then accpipe(3).r:=true; else accpipe(3).w:=true; end if; colv := unsigned(std_logic_vector'(a(a'high downto 11) & a(9 downto 0))); case vmr.blen is when "001" => blen := 2; when "010" => blen := 4; when "011" => blen := 8; when others => assert false report "Invalid burst length setting in MR!" severity error; end case; alow := unsigned(a(2 downto 0)); for x in 0 to blen-1 loop accpipe(3-x/2).bank := bank; if cmd(0)='1' then accpipe(3-x/2).r:=true; else accpipe(3-x/2).w:=true; end if; if vmr.bt='0' then -- Sequential colv(log2(blen)-1 downto 0) := alow(log2(blen)-1 downto 0) + x; else -- Interleaved colv(log2(blen)-1 downto 0) := alow(log2(blen)-1 downto 0) xor to_unsigned(x,log2(blen)); end if; col := to_integer(unsigned(ba))*(2**(colbits+rowbits)) + banks(bank).openrow * (2**colbits) + to_integer(colv(colbits-1 downto 0)); accpipe(3-x/2).col(x mod 2) := col; end loop; -- Auto precharge if a(10)='1' then if cmd(0)='1' then banks(bank).autopch := blen/2; else banks(bank).autopch := 1+blen/2 + (tWR-deltat+(re-prev_re))/(re-prev_re); end if; end if; when "110" => -- Burst terminate assert not accpipe(3).w report "Burst terminate on write burst!" severity warning; assert banks(accpipe(3).bank).autopch<0 report "Burst terminate on read with auto-precharge!" severity warning; assert accpipe(3).r report "Burst terminate with no effect!" severity warning; for x in 3 downto 0 loop accpipe(x).r := false; accpipe(x).w := false; end loop; when "010" => -- Precharge for x in 3 downto 0 loop accpipe(x).r := false; accpipe(x).w := false; end loop; for x in 0 to 3 loop if a(10)='1' or ba=std_logic_vector(to_unsigned(x,2)) then assert banks(x).autopch<0 report "Precharging bank that is auto-precharged" severity note; assert a(10)='1' or banks(x).openrow>=0 report "Precharging single bank that is in idle state" severity note; banks(x).autopch := 0; -- Handled below end if; end loop; when "001" => -- Auto refresh for x in 0 to 3 loop assert banks(x).openrow < 0 report "Bank in wrong state for auto refresh!" severity warning; checktime(now-banks(x).closetime, tRP(speedbin), true, "tRP"); end loop; lastref := now; when "000" => -- MRS for x in 0 to 3 loop checktime(now-banks(x).closetime, tRP(speedbin), true, "tRP"); end loop; case ba is when "00" => vmr.opmode(a'high-7 downto 0) := a(a'high downto 7); vmr.caslat := a(6 downto 4); vmr.bt := a(3); vmr.blen := a(2 downto 0); when "01" => vmr.opmode1(a'high-3 downto 0) := a(a'high downto 3); vmr.res1 := a(2); vmr.ds := a(1); vmr.dlldis := a(0); when others => assert false report ("MRS to invalid bank addr: " & std_logic'image(ba(1)) & std_logic'image(ba(0))) severity warning; end case; mrscount := tMRD_ck-1; when others => assert false report ("Invalid command: " & std_logic'image(rasn) & std_logic'image(casn) & std_logic'image(wen)) severity warning; end case; end if; -- Manual or auto precharge for x in 0 to 3 loop if banks(x).autopch=0 then checktime(now-banks(x).writetime, tWR, true, "tWR"); checktime(now-banks(x).opentime, tRAS(speedbin), true, "tRAS"); banks(x).openrow := -1; banks(x).closetime := now; end if; if banks(x).autopch >= 0 then banks(x).autopch := banks(x).autopch - 1; end if; end loop; -- Read/write management if not loaded and lddelay < now then load_srec; loaded := true; end if; case vmr.caslat is when "010" => i := 2; b:=false; -- CL2 when "011" => i := 3; b:=false; -- CL3 when "101" => i := 2; b:=true; -- CL1.5 when "110" => i := 3; b:=true; -- CL2.5 when others => i := 1; end case; hcmode <= b; if b then hcread_en <= accpipe(1+i).r; else hcread_en <= false; end if; if accpipe(2+i).r then assert i>1 report "Incorrect CL setting!" severity warning; read_en <= true; -- print("Reading from col " & tost(accpipe(2+i).col(0)) & " and " & tost(accpipe(2+i).col(1))); -- col0 <= accpipe(2+i).col(0); col1 <= accpipe(2+i).col(1); read_data <= memdata(accpipe(2+i).col(0)) & memdata(accpipe(2+i).col(1)); else read_en <= false; end if; write_en <= accpipe(3).w or accpipe(4).w; if accpipe(5).w and write_mask/=(write_mask'range => '1') then assert not is_x(write_mask) report "Write error"; for x in 0 to 1 loop for b in width/8-1 downto 0 loop if write_mask((1-x)*width/8+b)='0' then memdata(accpipe(5).col(x))(8*b+7 downto 8*b) := write_data( (1-x)*width+b*8+7 downto (1-x)*width+b*8); end if; end loop; end loop; banks(accpipe(5).bank).writetime := now; end if; end if; mr <= vmr; end process; ----------------------------------------------------------------------------- -- DQS/DQ handling and data sampling process ----------------------------------------------------------------------------- dqproc: process variable rdata: std_logic_vector(2*width-1 downto 0); variable hdata: std_logic_vector(width-1 downto 0); variable hmask: std_logic_vector(width/8-1 downto 0); variable prevdqs: std_logic_vector(width/8-1 downto 0); begin dq <= (others => 'Z'); dqs <= (others => 'Z'); wait until (hcmode and hcread_en) or read_en or write_en; assert not ((read_en or hcread_en) and write_en); if (read_en or hcread_en) then if hcmode then wait until falling_edge(ck); end if; dqs <= (others => '0'); wait until falling_edge(ck); while read_en loop rdata := read_data; if not hcmode then wait until rising_edge(ck); end if; dqs <= (others => '1'); dq <= rdata(2*width-1 downto width); if hcmode then wait until rising_edge(ck); else wait until falling_edge(ck); end if; dqs <= (others => '0'); dq <= rdata(width-1 downto 0); if hcmode then wait until falling_edge(ck); end if; end loop; if not hcmode then wait until rising_edge(ck); end if; else wait until falling_edge(ck); assert to_X01(dqs)=(dqs'range => '0') or igndqs/=0; while write_en loop prevdqs := to_X01(dqs); if igndqs /= 0 then wait on ck,write_en; else wait until to_X01(dqs) /= prevdqs or not write_en or rising_edge(ck); end if; if rising_edge(ck) then -- Just to make sure missing DQS is not undetected write_data <= (others => 'X'); write_mask <= (others => 'X'); end if; for x in dqs'range loop if (igndqs=0 and prevdqs(x)='0' and to_X01(dqs(x))='1') or (igndqs/=0 and rising_edge(ck)) then hdata(8*x+7 downto 8*x) := dq(8*x+7 downto 8*x); hmask(x) := dm(x); elsif (igndqs=0 and prevdqs(x)='1' and to_X01(dqs(x))='0') or (igndqs/=0 and falling_edge(ck)) then write_data(width+8*x+7 downto width+8*x) <= hdata(8*x+7 downto 8*x); write_data(8*x+7 downto 8*x) <= dq(8*x+7 downto 8*x); write_mask(width/8+x) <= hmask(x); write_mask(x) <= dm(x); end if; end loop; end loop; end if; end process; end; -- pragma translate_on
-- ZPU -- -- Copyright 2004-2008 oharboe - Øyvind Harboe - [email protected] -- Copyright 2010-2012 Alvaro Lopes - [email protected] -- -- The FreeBSD license -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions -- are met: -- -- 1. Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer. -- 2. Redistributions in binary form must reproduce the above -- copyright notice, this list of conditions and the following -- disclaimer in the documentation and/or other materials -- provided with the distribution. -- -- THIS SOFTWARE IS PROVIDED BY THE ZPU PROJECT ``AS IS'' AND ANY -- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -- ZPU PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- The views and conclusions contained in the software and documentation -- are those of the authors and should not be interpreted as representing -- official policies, either expressed or implied, of the ZPU Project. library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.numeric_std.all; library board; use board.zpu_config.all; use board.zpupkg.all; use board.wishbonepkg.all; --library UNISIM; --use UNISIM.vcomponents.all; entity zpu_core_extreme is port ( wb_clk_i: in std_logic; wb_rst_i: in std_logic; -- Master wishbone interface wb_ack_i: in std_logic; wb_dat_i: in std_logic_vector(wordSize-1 downto 0); wb_dat_o: out std_logic_vector(wordSize-1 downto 0); wb_adr_o: out std_logic_vector(maxAddrBitIncIO downto 0); wb_cyc_o: out std_logic; wb_stb_o: out std_logic; wb_we_o: out std_logic; wb_inta_i: in std_logic; poppc_inst: out std_logic; break: out std_logic; -- STACK stack_a_read: in std_logic_vector(wordSize-1 downto 0); stack_b_read: in std_logic_vector(wordSize-1 downto 0); stack_a_write: out std_logic_vector(wordSize-1 downto 0); stack_b_write: out std_logic_vector(wordSize-1 downto 0); stack_a_writeenable: out std_logic; stack_a_enable: out std_logic; stack_b_writeenable: out std_logic; stack_b_enable: out std_logic; stack_a_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_b_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_clk: out std_logic; -- ROM wb interface rom_wb_ack_i: in std_logic; rom_wb_dat_i: in std_logic_vector(wordSize-1 downto 0); rom_wb_adr_o: out std_logic_vector(maxAddrBit downto 0); rom_wb_cyc_o: out std_logic; rom_wb_stb_o: out std_logic; rom_wb_cti_o: out std_logic_vector(2 downto 0); rom_wb_stall_i: in std_logic; -- Debug interface dbg_out: out zpu_dbg_out_type; dbg_in: in zpu_dbg_in_type ); end zpu_core_extreme; architecture behave of zpu_core_extreme is component lshifter is port ( clk: in std_logic; rst: in std_logic; enable: in std_logic; done: out std_logic; inputA: in std_logic_vector(31 downto 0); inputB: in std_logic_vector(31 downto 0); output: out std_logic_vector(63 downto 0); multorshift: in std_logic ); end component; signal lshifter_enable: std_logic; signal lshifter_done: std_logic; signal lshifter_input: std_logic_vector(31 downto 0); signal lshifter_amount: std_logic_vector(31 downto 0); signal lshifter_output: std_logic_vector(63 downto 0); signal lshifter_multorshift: std_logic; signal begin_inst: std_logic; signal trace_opcode: std_logic_vector(7 downto 0); signal trace_pc: std_logic_vector(maxAddrBitIncIO downto 0); signal trace_sp: std_logic_vector(maxAddrBitIncIO downto minAddrBit); signal trace_topOfStack: std_logic_vector(wordSize-1 downto 0); signal trace_topOfStackB: std_logic_vector(wordSize-1 downto 0); -- state machine. type State_Type is ( State_Execute, State_Store, State_StoreB, State_StoreB2, State_Load, State_LoadMemory, State_LoadStack, State_Loadb, State_Resync1, State_Resync2, State_LoadSP, State_WaitSPB, State_ResyncFromStoreStack, State_Neqbranch, State_Ashiftleft, State_Mult, State_MultF16 ); type DecodedOpcodeType is ( Decoded_Nop, Decoded_Idle, Decoded_Im0, Decoded_ImN, Decoded_LoadSP, Decoded_Dup, Decoded_DupStackB, Decoded_StoreSP, Decoded_Pop, Decoded_PopDown, Decoded_AddSP, Decoded_AddStackB, Decoded_Shift, Decoded_Emulate, Decoded_Break, Decoded_PushSP, Decoded_PopPC, Decoded_Add, Decoded_Or, Decoded_And, Decoded_Load, Decoded_Not, Decoded_Flip, Decoded_Store, Decoded_PopSP, Decoded_Interrupt, Decoded_Neqbranch, Decoded_Eq, Decoded_Storeb, Decoded_Storeh, Decoded_Ulessthan, Decoded_Lessthan, Decoded_Ashiftleft, Decoded_Ashiftright, Decoded_Loadb, Decoded_Call, Decoded_Mult, Decoded_MultF16 ); constant spMaxBit: integer := 10; constant minimal_implementation: boolean := false; subtype index is integer range 0 to 3; signal tOpcode_sel : index; function pc_to_cpuword(pc: unsigned) return unsigned is variable r: unsigned(wordSize-1 downto 0); begin r := (others => DontCareValue); r(maxAddrBit downto 0) := pc; return r; end pc_to_cpuword; function pc_to_memaddr(pc: unsigned) return unsigned is variable r: unsigned(maxAddrBit downto 0); begin r := (others => '0'); r(maxAddrBit downto minAddrBit) := pc(maxAddrBit downto minAddrBit); return r; end pc_to_memaddr; -- Prefetch stage registers type stackChangeType is ( Stack_Same, Stack_Push, Stack_Pop, Stack_DualPop ); type tosSourceType is ( Tos_Source_PC, Tos_Source_FetchPC, Tos_Source_Idim0, Tos_Source_IdimN, Tos_Source_StackB, Tos_Source_SP, Tos_Source_Add, Tos_Source_And, Tos_Source_Or, Tos_Source_Eq, Tos_Source_Not, Tos_Source_Flip, Tos_Source_LoadSP, Tos_Source_AddSP, Tos_Source_AddStackB, Tos_Source_Shift, Tos_Source_Ulessthan, Tos_Source_Lessthan, Tos_Source_None ); type decoderstate_type is ( State_Run, State_Jump, State_Inject, State_InjectJump ); type decoderegs_type is record valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opWillFreeze: std_logic; -- '1' if we know in advance this opcode will freeze pipeline opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); pcint: unsigned(maxAddrBit downto 0); idim: std_logic; im: std_logic; stackOperation: stackChangeType; spOffset: unsigned(4 downto 0); im_emu: std_logic; --emumode: std_logic; break: std_logic; state: decoderstate_type; end record; type prefetchregs_type is record sp: unsigned(spMaxBit downto 2); spnext: unsigned(spMaxBit downto 2); valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); idim: std_logic; break: std_logic; load: std_logic; opWillFreeze: std_logic; recompute_sp: std_logic; end record; type exuregs_type is record idim: std_logic; break: std_logic; inInterrupt:std_logic; tos: unsigned(wordSize-1 downto 0); tos_save: unsigned(wordSize-1 downto 0); nos_save: unsigned(wordSize-1 downto 0); state: State_Type; -- Wishbone control signals (registered) wb_cyc: std_logic; wb_stb: std_logic; wb_we: std_logic; end record; -- Registers for each stage signal exr: exuregs_type; signal prefr: prefetchregs_type; signal decr: decoderegs_type; signal pcnext: unsigned(maxAddrBit downto 0); -- Helper only. TODO: move into variable signal sp_load: unsigned(spMaxBit downto 2); -- SP value to load, coming from EXU into PFU signal decode_load_sp: std_logic; -- Load SP signal from EXU to PFU signal exu_busy: std_logic; -- EXU busy ( stalls PFU ) signal pfu_busy: std_logic; -- PFU busy ( stalls DFU ) signal decode_jump: std_logic; -- Jump signal from EXU to DFU signal jump_address: unsigned(maxAddrBit downto 0); -- Jump address from EXU to DFU signal do_interrupt: std_logic; -- Helper. -- Sampled signals from the opcode. Left as signals -- in order to simulate design. signal sampledOpcode: std_logic_vector(OpCode_Size-1 downto 0); signal sampledDecodedOpcode: DecodedOpcodeType; signal sampledOpWillFreeze: std_logic; signal sampledStackOperation: stackChangeType; signal sampledspOffset: unsigned(4 downto 0); signal sampledTosSource: tosSourceType; signal nos: unsigned(wordSize-1 downto 0); -- This is only a helper signal wroteback_q: std_logic; -- TODO: get rid of this here, move to EXU regs -- Test debug signals signal freeze_all: std_logic := '0'; signal single_step: std_logic := '0'; begin -- Debug interface dbg_out.pc <= std_logic_vector(prefr.pc); dbg_out.opcode <= prefr.opcode; dbg_out.sp <= std_logic_vector(prefr.sp); dbg_out.brk <= exr.break; dbg_out.stacka <= std_logic_vector(exr.tos); dbg_out.stackb <= std_logic_vector(nos); dbg_out.idim <= prefr.idim; shl: lshifter port map ( clk => wb_clk_i, rst => wb_rst_i, enable => lshifter_enable, done => lshifter_done, inputA => lshifter_input, inputB => lshifter_amount, output => lshifter_output, multorshift => lshifter_multorshift ); stack_clk <= wb_clk_i; traceFileGenerate: if Generate_Trace generate trace_file: trace port map ( clk => wb_clk_i, begin_inst => begin_inst, pc => trace_pc, opcode => trace_opcode, sp => trace_sp, memA => trace_topOfStack, memB => trace_topOfStackB, busy => '0',--busy, intsp => (others => 'U') ); end generate; tOpcode_sel <= to_integer(decr.pcint(minAddrBit-1 downto 0)); do_interrupt <= '1' when wb_inta_i='1' and exr.inInterrupt='0' else '0'; decodeControl: process(rom_wb_dat_i, tOpcode_sel, sp_load, decr, do_interrupt, dbg_in.inject, dbg_in.opcode) variable tOpcode : std_logic_vector(OpCode_Size-1 downto 0); variable localspOffset: unsigned(4 downto 0); begin if dbg_in.inject='1' then tOpcode := dbg_in.opcode; else case (tOpcode_sel) is when 0 => tOpcode := std_logic_vector(rom_wb_dat_i(31 downto 24)); when 1 => tOpcode := std_logic_vector(rom_wb_dat_i(23 downto 16)); when 2 => tOpcode := std_logic_vector(rom_wb_dat_i(15 downto 8)); when 3 => tOpcode := std_logic_vector(rom_wb_dat_i(7 downto 0)); when others => null; end case; end if; sampledOpcode <= tOpcode; sampledStackOperation <= Stack_Same; sampledTosSource <= Tos_Source_None; sampledOpWillFreeze <= '0'; localspOffset(4):=not tOpcode(4); localspOffset(3 downto 0) := unsigned(tOpcode(3 downto 0)); if do_interrupt='1' and decr.im='0' then sampledDecodedOpcode <= Decoded_Interrupt; sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_PC; else if (tOpcode(7 downto 7)=OpCode_Im) then if decr.im='0' then sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_Idim0; sampledDecodedOpcode<=Decoded_Im0; else sampledTosSource <= Tos_Source_IdimN; sampledDecodedOpcode<=Decoded_ImN; end if; elsif (tOpcode(7 downto 5)=OpCode_StoreSP) then sampledStackOperation <= Stack_Pop; sampledTosSource <= Tos_Source_StackB; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Pop; sampledTosSource <= Tos_Source_StackB; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_PopDown; sampledTosSource <= Tos_Source_None; else sampledDecodedOpcode<=Decoded_StoreSP; sampledOpWillFreeze<='1'; sampledTosSource <= Tos_Source_StackB; end if; elsif (tOpcode(7 downto 5)=OpCode_LoadSP) then sampledStackOperation <= Stack_Push; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Dup; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_DupStackB; sampledTosSource <= Tos_Source_StackB; else sampledDecodedOpcode<=Decoded_LoadSP; sampledTosSource <= Tos_Source_LoadSP; end if; elsif (tOpcode(7 downto 5)=OpCode_Emulate) then -- Emulated instructions implemented in hardware if minimal_implementation then sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; else if (tOpcode(5 downto 0)=OpCode_Loadb) then sampledStackOperation<=Stack_Same; sampledDecodedOpcode<=Decoded_Loadb; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Neqbranch) then sampledStackOperation<=Stack_DualPop; sampledDecodedOpcode<=Decoded_Neqbranch; sampledOpWillFreeze <= '1'; elsif (tOpcode(5 downto 0)=OpCode_Call) then sampledDecodedOpcode<=Decoded_Call; sampledStackOperation<=Stack_Same; sampledTosSource<=Tos_Source_FetchPC; elsif (tOpcode(5 downto 0)=OpCode_Eq) then sampledDecodedOpcode<=Decoded_Eq; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Eq; elsif (tOpcode(5 downto 0)=OpCode_Ulessthan) then sampledDecodedOpcode<=Decoded_Ulessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Ulessthan; elsif (tOpcode(5 downto 0)=OpCode_Lessthan) then sampledDecodedOpcode<=Decoded_Lessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Lessthan; elsif (tOpcode(5 downto 0)=OpCode_StoreB) then sampledDecodedOpcode<=Decoded_StoreB; sampledStackOperation<=Stack_DualPop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Mult) then sampledDecodedOpcode<=Decoded_Mult; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Ashiftleft) then sampledDecodedOpcode<=Decoded_Ashiftleft; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; end if; end if; elsif (tOpcode(7 downto 4)=OpCode_AddSP) then if localspOffset=0 then sampledDecodedOpcode<=Decoded_Shift; sampledTosSource <= Tos_Source_Shift; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_AddStackB; sampledTosSource <= Tos_Source_AddStackB; else sampledDecodedOpcode<=Decoded_AddSP; sampledTosSource <= Tos_Source_AddSP; end if; else case tOpcode(3 downto 0) is when OpCode_Break => sampledDecodedOpcode<=Decoded_Break; sampledOpWillFreeze <= '1'; when OpCode_PushSP => sampledStackOperation <= Stack_Push; sampledDecodedOpcode<=Decoded_PushSP; sampledTosSource <= Tos_Source_SP; when OpCode_PopPC => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_PopPC; sampledTosSource <= Tos_Source_StackB; when OpCode_Add => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Add; sampledTosSource <= Tos_Source_Add; when OpCode_Or => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Or; sampledTosSource <= Tos_Source_Or; when OpCode_And => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_And; sampledTosSource <= Tos_Source_And; when OpCode_Load => sampledDecodedOpcode<=Decoded_Load; sampledOpWillFreeze<='1'; when OpCode_Not => sampledDecodedOpcode<=Decoded_Not; sampledTosSource <= Tos_Source_Not; when OpCode_Flip => sampledDecodedOpcode<=Decoded_Flip; sampledTosSource <= Tos_Source_Flip; when OpCode_Store => sampledStackOperation <= Stack_DualPop; sampledDecodedOpcode<=Decoded_Store; sampledOpWillFreeze<='1'; when OpCode_PopSP => sampledDecodedOpcode<=Decoded_PopSP; sampledOpWillFreeze<='1'; when OpCode_NA4 => if enable_fmul16 then sampledDecodedOpcode<=Decoded_MultF16; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Nop; end if; when others => sampledDecodedOpcode<=Decoded_Nop; end case; end if; end if; sampledspOffset <= localspOffset; end process; -- Decode/Fetch unit rom_wb_stb_o <= not exu_busy; process(decr, jump_address, decode_jump, wb_clk_i, sp_load, sampledDecodedOpcode,sampledOpcode,decode_load_sp, exu_busy, pfu_busy, pcnext, rom_wb_ack_i, wb_rst_i, sampledStackOperation, sampledspOffset, sampledTosSource, prefr.recompute_sp, sampledOpWillFreeze, dbg_in.flush, dbg_in.inject,dbg_in.injectmode, prefr.valid, prefr.break, rom_wb_stall_i ) variable w: decoderegs_type; begin w := decr; pcnext <= decr.fetchpc + 1; rom_wb_adr_o <= std_logic_vector(pc_to_memaddr(decr.fetchpc)); rom_wb_cti_o <= CTI_CYCLE_INCRADDR; if wb_rst_i='1' then w.pc := (others => '0'); w.pcint := (others => '0'); w.valid := '0'; w.fetchpc := (others => '0'); w.im:='0'; w.im_emu:='0'; w.state := State_Run; w.break := '0'; rom_wb_cyc_o <= '0'; else rom_wb_cyc_o <= '1'; case decr.state is when State_Run => if pfu_busy='0' then if dbg_in.injectmode='0' and decr.break='0' and rom_wb_stall_i='0' then w.fetchpc := pcnext; end if; -- Jump request if decode_jump='1' then w.valid := '0'; w.im := '0'; w.break := '0'; -- Invalidate eventual break after branch instruction --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o<='0'; --if rom_wb_stall_i='0' then w.fetchpc := jump_address; --else w.state := State_Jump; --end if; else if dbg_in.injectmode='1' then --or decr.break='1' then -- At this point we ought to push a new op into the pipeline. -- Since we're entering inject mode, invalidate next operation, -- but save the current IM flag. w.im_emu := decr.im; w.valid := '0'; --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o <='0'; -- Wait until no work is to be done if prefr.valid='0' and decr.valid='0' and exu_busy='0' then w.state := State_Inject; w.im:='0'; end if; if decr.break='0' then w.pc := decr.pcint; end if; else if decr.break='1' then w.valid := '0'; else w.valid := rom_wb_ack_i; end if; if rom_wb_ack_i='1' then w.im := sampledOpcode(7); if sampledDecodedOpcode=Decoded_Break then w.break:='1'; end if; end if; if prefr.break='0' and rom_wb_stall_i='0' then w.pcint := decr.fetchpc; w.pc := decr.pcint; end if; if rom_wb_stall_i='0' then w.opcode := sampledOpcode; end if; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; when State_Jump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Run; when State_InjectJump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Inject; when State_Inject => -- NOTE: disable ROM rom_wb_cyc_o <= '0'; if dbg_in.injectmode='0' then w.im := decr.im_emu; w.fetchpc := decr.pcint; w.state := State_Run; w.break := '0'; else -- Handle opcode injection -- TODO: merge this with main decode. -- NOTE: we don't check busy here, it's up to debug unit to do it --if pfu_busy='0' then --w.fetchpc := pcnext; -- Jump request if decode_jump='1' then w.fetchpc := jump_address; w.valid := '0'; w.im := '0'; w.state := State_InjectJump; else w.valid := dbg_in.inject; if dbg_in.inject='1' then w.im := sampledOpcode(7); --w.break := '0'; --w.pcint := decr.fetchpc; w.opcode := sampledOpcode; --w.pc := decr.pcint; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; --end if; end case; end if; -- rst if rising_edge(wb_clk_i) then decr <= w; end if; end process; -- Prefetch/Load unit. sp_load <= exr.tos(spMaxBit downto 2); -- Will be delayed one clock cycle process(wb_clk_i, wb_rst_i, decr, prefr, exu_busy, decode_jump, sp_load, decode_load_sp, dbg_in.flush) variable w: prefetchregs_type; variable i_op_freeze: std_logic; begin w := prefr; pfu_busy<='0'; stack_b_addr <= std_logic_vector(prefr.spnext + 1); w.recompute_sp:='0'; -- Stack w.load := decode_load_sp; if decode_load_sp='1' then pfu_busy <= '1'; w.spnext := sp_load; w.recompute_sp := '1'; else pfu_busy <= exu_busy; if decr.valid='1' then if (exu_busy='0' and decode_jump='0') or prefr.recompute_sp='1' then case decr.stackOperation is when Stack_Push => w.spnext := prefr.spnext - 1; when Stack_Pop => w.spnext := prefr.spnext + 1; when Stack_DualPop => w.spnext := prefr.spnext + 2; when others => end case; w.sp := prefr.spnext; end if; end if; end if; case decr.decodedOpcode is when Decoded_LoadSP | decoded_AddSP => stack_b_addr <= std_logic_vector(prefr.spnext + decr.spOffset); when others => end case; if decode_jump='1' then -- this is a pipeline "invalidate" flag. w.valid := '0'; else if dbg_in.flush='1' then w.valid := '0'; else w.valid := decr.valid; end if; end if; -- Moved op_will_freeze from decoder to here case decr.decodedOpcode is when Decoded_StoreSP | Decoded_LoadB | Decoded_Neqbranch | Decoded_StoreB | Decoded_Mult | Decoded_Ashiftleft | Decoded_Break | Decoded_Load | Decoded_Store | Decoded_PopSP | Decoded_MultF16 => i_op_freeze := '1'; when others => i_op_freeze := '0'; end case; if exu_busy='0' then w.decodedOpcode := decr.decodedOpcode; w.tosSource := decr.tosSource; w.opcode := decr.opcode; w.opWillFreeze := i_op_freeze; w.pc := decr.pc; w.fetchpc := decr.pcint; w.idim := decr.idim; w.break := decr.break; end if; if wb_rst_i='1' then w.spnext := unsigned(spStart(10 downto 2)); --w.sp := unsigned(spStart(10 downto 2)); w.valid := '0'; w.idim := '0'; w.recompute_sp:='0'; end if; if rising_edge(wb_clk_i) then prefr <= w; end if; end process; process(prefr,exr,nos) begin trace_pc <= (others => '0'); trace_pc(maxAddrBit downto 0) <= std_logic_vector(prefr.pc); trace_opcode <= prefr.opcode; trace_sp <= (others => '0'); trace_sp(10 downto 2) <= std_logic_vector(prefr.sp); trace_topOfStack <= std_logic_vector( exr.tos ); trace_topOfStackB <= std_logic_vector( nos ); end process; -- IO/Memory Accesses wb_adr_o(maxAddrBitIncIO downto 0) <= std_logic_vector(exr.tos_save(maxAddrBitIncIO downto 0)); wb_cyc_o <= exr.wb_cyc; wb_stb_o <= exr.wb_stb; wb_we_o <= exr.wb_we; wb_dat_o <= std_logic_vector( exr.nos_save ); freeze_all <= dbg_in.freeze; process(exr, wb_inta_i, wb_clk_i, wb_rst_i, pcnext, stack_a_read,stack_b_read, wb_ack_i, wb_dat_i, do_interrupt,exr, prefr, nos, single_step, freeze_all, dbg_in.step, wroteback_q,lshifter_done,lshifter_output ) variable spOffset: unsigned(4 downto 0); variable w: exuregs_type; variable instruction_executed: std_logic; variable wroteback: std_logic; begin w := exr; instruction_executed := '0'; -- used for single stepping stack_b_writeenable <= '0'; stack_a_enable <= '1'; stack_b_enable <= '1'; exu_busy <= '0'; decode_jump <= '0'; jump_address <= (others => DontCareValue); lshifter_enable <= '0'; lshifter_amount <= std_logic_vector(exr.tos_save); lshifter_input <= std_logic_vector(exr.nos_save); lshifter_multorshift <= '0'; poppc_inst <= '0'; begin_inst<='0'; stack_a_addr <= std_logic_vector( prefr.sp ); stack_a_writeenable <= '0'; wroteback := wroteback_q; stack_b_writeenable <= '0'; stack_a_write <= std_logic_vector(exr.tos); spOffset(4):=not prefr.opcode(4); spOffset(3 downto 0) := unsigned(prefr.opcode(3 downto 0)); if wb_inta_i='0' then w.inInterrupt := '0'; end if; stack_b_write<=(others => DontCareValue); if wroteback_q='1' then nos <= unsigned(stack_a_read); else nos <= unsigned(stack_b_read); end if; decode_load_sp <= '0'; case exr.state is when State_Resync1 => exu_busy <= '1'; stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_ResyncFromStoreStack => exu_busy <= '1'; stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_Resync2 => w.tos := unsigned(stack_a_read); instruction_executed := '1'; exu_busy <= '0'; wroteback := '0'; stack_b_enable <= '1'; w.state := State_Execute; when State_Execute => instruction_executed:='0'; if prefr.valid='1' then exu_busy <= prefr.opWillFreeze; if freeze_all='0' or single_step='1' then wroteback := '0'; w.nos_save := nos; w.tos_save := exr.tos; w.idim := prefr.idim; w.break:= prefr.break; begin_inst<='1'; instruction_executed := '1'; -- TOS big muxer case prefr.tosSource is when Tos_Source_PC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.pc; when Tos_Source_FetchPC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.fetchpc; when Tos_Source_Idim0 => for i in wordSize-1 downto 7 loop w.tos(i) := prefr.opcode(6); end loop; w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_IdimN => w.tos(wordSize-1 downto 7) := exr.tos(wordSize-8 downto 0); w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_StackB => w.tos := nos; when Tos_Source_SP => w.tos := (others => '0'); w.tos(31) := '1'; -- Stack address w.tos(10 downto 2) := prefr.sp; when Tos_Source_Add => w.tos := exr.tos + nos; when Tos_Source_And => w.tos := exr.tos and nos; when Tos_Source_Or => w.tos := exr.tos or nos; when Tos_Source_Eq => w.tos := (others => '0'); if nos = exr.tos then w.tos(0) := '1'; end if; when Tos_Source_Ulessthan => w.tos := (others => '0'); if exr.tos < nos then w.tos(0) := '1'; end if; when Tos_Source_Lessthan => w.tos := (others => '0'); if signed(exr.tos) < signed(nos) then w.tos(0) := '1'; end if; when Tos_Source_Not => w.tos := not exr.tos; when Tos_Source_Flip => for i in 0 to wordSize-1 loop w.tos(i) := exr.tos(wordSize-1-i); end loop; when Tos_Source_LoadSP => w.tos := unsigned(stack_b_read); when Tos_Source_AddSP => w.tos := w.tos + unsigned(stack_b_read); when Tos_Source_AddStackB => w.tos := w.tos + nos; when Tos_Source_Shift => w.tos := exr.tos + exr.tos; when others => end case; case prefr.decodedOpcode is when Decoded_Interrupt => w.inInterrupt := '1'; jump_address <= to_unsigned(32, maxAddrBit+1); decode_jump <= '1'; stack_a_writeenable<='1'; wroteback:='1'; stack_b_enable<='0'; instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Im0 => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_ImN => when Decoded_Nop => when Decoded_PopPC | Decoded_Call => decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0); poppc_inst <= '1'; stack_b_enable<='0'; -- Delay instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Emulate => decode_jump <= '1'; jump_address <= (others => '0'); jump_address(9 downto 5) <= unsigned(prefr.opcode(4 downto 0)); stack_a_writeenable<='1'; wroteback:='1'; when Decoded_PushSP => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_LoadSP => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_DupStackB => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_Dup => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_AddSP => stack_a_writeenable <= '1'; when Decoded_StoreSP => stack_a_writeenable <= '1'; wroteback:='1'; stack_a_addr <= std_logic_vector(prefr.sp + spOffset); instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_PopDown => stack_a_writeenable<='1'; when Decoded_Pop => when Decoded_Ashiftleft => w.state := State_Ashiftleft; when Decoded_Mult => w.state := State_Mult; when Decoded_MultF16 => w.state := State_MultF16; when Decoded_Store => if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(nos); stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when Decoded_Load | Decoded_Loadb | Decoded_StoreB => --w.tos_save := exr.tos; -- Byte select instruction_executed := '0'; wroteback := wroteback_q; -- Keep WB if exr.tos(wordSize-1)='1' then stack_a_addr<=std_logic_vector(exr.tos(10 downto 2)); stack_a_enable<='1'; w.state := State_LoadStack; else stack_a_enable <= '0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); w.wb_we :='0'; w.wb_cyc :='1'; w.wb_stb :='1'; w.state := State_Load; end if; when Decoded_PopSP => decode_load_sp <= '1'; instruction_executed := '0'; stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); w.state := State_Resync2; --when Decoded_Break => -- w.break := '1'; when Decoded_Neqbranch => instruction_executed := '0'; w.state := State_NeqBranch; when others => end case; else -- freeze_all -- -- Freeze the entire pipeline. -- exu_busy<='1'; stack_a_enable<='0'; stack_b_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); end if; end if; -- valid when State_Ashiftleft => exu_busy <= '1'; lshifter_enable <= '1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_Mult => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_MultF16 => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(47 downto 16)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_WaitSPB => instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Store => exu_busy <= '1'; -- Keep writeback flag wroteback := wroteback_q; if wb_ack_i='1' then stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; stack_b_enable<='1'; wroteback := '0'; --exu_busy <= '1'; w.wb_cyc := '0'; w.state := State_Resync2; else stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_a_enable<='0'; stack_b_enable<='0'; end if; when State_Loadb => w.tos(wordSize-1 downto 8) := (others => '0'); case exr.tos_save(1 downto 0) is when "11" => w.tos(7 downto 0) := unsigned(exr.tos(7 downto 0)); when "10" => w.tos(7 downto 0) := unsigned(exr.tos(15 downto 8)); when "01" => w.tos(7 downto 0) := unsigned(exr.tos(23 downto 16)); when "00" => w.tos(7 downto 0) := unsigned(exr.tos(31 downto 24)); when others => null; end case; instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Load => if wb_ack_i='0' then exu_busy<='1'; else w.tos := unsigned(wb_dat_i); w.wb_cyc := '0'; if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state := State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state := State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; end if; when State_LoadStack => w.tos := unsigned(stack_a_read); if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state:=State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state:=State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; when State_NeqBranch => if exr.nos_save/=0 then decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0) + prefr.pc; poppc_inst <= '1'; exu_busy <= '0'; else exu_busy <='1'; end if; instruction_executed := '0'; stack_a_addr <= std_logic_vector(prefr.spnext); wroteback:='0'; w.state := State_Resync2; when State_StoreB => exu_busy <= '1'; -- -- At this point, we have loaded the 32-bit, and it's in TOS -- The IO address is still saved in save_TOS. -- The original write value is still at save_NOS -- -- So we mangle the write value, and update save_NOS, and restore -- the IO address to TOS -- -- This is still buggy - don't use. Problems arise when writing to stack. -- w.nos_save := exr.tos; case exr.tos_save(1 downto 0) is when "00" => w.nos_save(31 downto 24) := exr.nos_save(7 downto 0); when "01" => w.nos_save(23 downto 16) := exr.nos_save(7 downto 0); when "10" => w.nos_save(15 downto 8) := exr.nos_save(7 downto 0); when "11" => w.nos_save(7 downto 0) := exr.nos_save(7 downto 0); when others => null; end case; w.tos := exr.tos_save; w.state := State_StoreB2; when State_StoreB2 => exu_busy <= '1'; if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(exr.nos_save); -- hmm I don't like this stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when others => null; end case; if rising_edge(wb_clk_i) then if wb_rst_i='1' then exr.state <= State_Execute; exr.idim <= DontCareValue; exr.inInterrupt <= '0'; exr.break <= '0'; exr.wb_cyc <= '0'; exr.wb_stb <= '1'; else exr <= w; -- TODO: move wroteback_q into EXU regs wroteback_q <= wroteback; if exr.break='1' then report "BREAK" severity failure; end if; -- Some sanity checks, to be caught in simulation if prefr.valid='1' then if prefr.tosSource=Tos_Source_Idim0 and prefr.idim='1' then report "Invalid IDIM flag 0" severity error; end if; if prefr.tosSource=Tos_Source_IdimN and prefr.idim='0' then report "Invalid IDIM flag 1" severity error; end if; end if; end if; end if; end process; single_step <= dbg_in.step; dbg_out.valid <= '1' when prefr.valid='1' else '0'; -- Let pipeline finish dbg_out.ready <= '1' when exr.state=state_execute and decode_load_sp='0' and decode_jump='0' and decr.state = State_Inject --and jump_q='0' else '0'; end behave;
-- ZPU -- -- Copyright 2004-2008 oharboe - Øyvind Harboe - [email protected] -- Copyright 2010-2012 Alvaro Lopes - [email protected] -- -- The FreeBSD license -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions -- are met: -- -- 1. Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer. -- 2. Redistributions in binary form must reproduce the above -- copyright notice, this list of conditions and the following -- disclaimer in the documentation and/or other materials -- provided with the distribution. -- -- THIS SOFTWARE IS PROVIDED BY THE ZPU PROJECT ``AS IS'' AND ANY -- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -- ZPU PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- The views and conclusions contained in the software and documentation -- are those of the authors and should not be interpreted as representing -- official policies, either expressed or implied, of the ZPU Project. library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.numeric_std.all; library board; use board.zpu_config.all; use board.zpupkg.all; use board.wishbonepkg.all; --library UNISIM; --use UNISIM.vcomponents.all; entity zpu_core_extreme is port ( wb_clk_i: in std_logic; wb_rst_i: in std_logic; -- Master wishbone interface wb_ack_i: in std_logic; wb_dat_i: in std_logic_vector(wordSize-1 downto 0); wb_dat_o: out std_logic_vector(wordSize-1 downto 0); wb_adr_o: out std_logic_vector(maxAddrBitIncIO downto 0); wb_cyc_o: out std_logic; wb_stb_o: out std_logic; wb_we_o: out std_logic; wb_inta_i: in std_logic; poppc_inst: out std_logic; break: out std_logic; -- STACK stack_a_read: in std_logic_vector(wordSize-1 downto 0); stack_b_read: in std_logic_vector(wordSize-1 downto 0); stack_a_write: out std_logic_vector(wordSize-1 downto 0); stack_b_write: out std_logic_vector(wordSize-1 downto 0); stack_a_writeenable: out std_logic; stack_a_enable: out std_logic; stack_b_writeenable: out std_logic; stack_b_enable: out std_logic; stack_a_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_b_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_clk: out std_logic; -- ROM wb interface rom_wb_ack_i: in std_logic; rom_wb_dat_i: in std_logic_vector(wordSize-1 downto 0); rom_wb_adr_o: out std_logic_vector(maxAddrBit downto 0); rom_wb_cyc_o: out std_logic; rom_wb_stb_o: out std_logic; rom_wb_cti_o: out std_logic_vector(2 downto 0); rom_wb_stall_i: in std_logic; -- Debug interface dbg_out: out zpu_dbg_out_type; dbg_in: in zpu_dbg_in_type ); end zpu_core_extreme; architecture behave of zpu_core_extreme is component lshifter is port ( clk: in std_logic; rst: in std_logic; enable: in std_logic; done: out std_logic; inputA: in std_logic_vector(31 downto 0); inputB: in std_logic_vector(31 downto 0); output: out std_logic_vector(63 downto 0); multorshift: in std_logic ); end component; signal lshifter_enable: std_logic; signal lshifter_done: std_logic; signal lshifter_input: std_logic_vector(31 downto 0); signal lshifter_amount: std_logic_vector(31 downto 0); signal lshifter_output: std_logic_vector(63 downto 0); signal lshifter_multorshift: std_logic; signal begin_inst: std_logic; signal trace_opcode: std_logic_vector(7 downto 0); signal trace_pc: std_logic_vector(maxAddrBitIncIO downto 0); signal trace_sp: std_logic_vector(maxAddrBitIncIO downto minAddrBit); signal trace_topOfStack: std_logic_vector(wordSize-1 downto 0); signal trace_topOfStackB: std_logic_vector(wordSize-1 downto 0); -- state machine. type State_Type is ( State_Execute, State_Store, State_StoreB, State_StoreB2, State_Load, State_LoadMemory, State_LoadStack, State_Loadb, State_Resync1, State_Resync2, State_LoadSP, State_WaitSPB, State_ResyncFromStoreStack, State_Neqbranch, State_Ashiftleft, State_Mult, State_MultF16 ); type DecodedOpcodeType is ( Decoded_Nop, Decoded_Idle, Decoded_Im0, Decoded_ImN, Decoded_LoadSP, Decoded_Dup, Decoded_DupStackB, Decoded_StoreSP, Decoded_Pop, Decoded_PopDown, Decoded_AddSP, Decoded_AddStackB, Decoded_Shift, Decoded_Emulate, Decoded_Break, Decoded_PushSP, Decoded_PopPC, Decoded_Add, Decoded_Or, Decoded_And, Decoded_Load, Decoded_Not, Decoded_Flip, Decoded_Store, Decoded_PopSP, Decoded_Interrupt, Decoded_Neqbranch, Decoded_Eq, Decoded_Storeb, Decoded_Storeh, Decoded_Ulessthan, Decoded_Lessthan, Decoded_Ashiftleft, Decoded_Ashiftright, Decoded_Loadb, Decoded_Call, Decoded_Mult, Decoded_MultF16 ); constant spMaxBit: integer := 10; constant minimal_implementation: boolean := false; subtype index is integer range 0 to 3; signal tOpcode_sel : index; function pc_to_cpuword(pc: unsigned) return unsigned is variable r: unsigned(wordSize-1 downto 0); begin r := (others => DontCareValue); r(maxAddrBit downto 0) := pc; return r; end pc_to_cpuword; function pc_to_memaddr(pc: unsigned) return unsigned is variable r: unsigned(maxAddrBit downto 0); begin r := (others => '0'); r(maxAddrBit downto minAddrBit) := pc(maxAddrBit downto minAddrBit); return r; end pc_to_memaddr; -- Prefetch stage registers type stackChangeType is ( Stack_Same, Stack_Push, Stack_Pop, Stack_DualPop ); type tosSourceType is ( Tos_Source_PC, Tos_Source_FetchPC, Tos_Source_Idim0, Tos_Source_IdimN, Tos_Source_StackB, Tos_Source_SP, Tos_Source_Add, Tos_Source_And, Tos_Source_Or, Tos_Source_Eq, Tos_Source_Not, Tos_Source_Flip, Tos_Source_LoadSP, Tos_Source_AddSP, Tos_Source_AddStackB, Tos_Source_Shift, Tos_Source_Ulessthan, Tos_Source_Lessthan, Tos_Source_None ); type decoderstate_type is ( State_Run, State_Jump, State_Inject, State_InjectJump ); type decoderegs_type is record valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opWillFreeze: std_logic; -- '1' if we know in advance this opcode will freeze pipeline opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); pcint: unsigned(maxAddrBit downto 0); idim: std_logic; im: std_logic; stackOperation: stackChangeType; spOffset: unsigned(4 downto 0); im_emu: std_logic; --emumode: std_logic; break: std_logic; state: decoderstate_type; end record; type prefetchregs_type is record sp: unsigned(spMaxBit downto 2); spnext: unsigned(spMaxBit downto 2); valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); idim: std_logic; break: std_logic; load: std_logic; opWillFreeze: std_logic; recompute_sp: std_logic; end record; type exuregs_type is record idim: std_logic; break: std_logic; inInterrupt:std_logic; tos: unsigned(wordSize-1 downto 0); tos_save: unsigned(wordSize-1 downto 0); nos_save: unsigned(wordSize-1 downto 0); state: State_Type; -- Wishbone control signals (registered) wb_cyc: std_logic; wb_stb: std_logic; wb_we: std_logic; end record; -- Registers for each stage signal exr: exuregs_type; signal prefr: prefetchregs_type; signal decr: decoderegs_type; signal pcnext: unsigned(maxAddrBit downto 0); -- Helper only. TODO: move into variable signal sp_load: unsigned(spMaxBit downto 2); -- SP value to load, coming from EXU into PFU signal decode_load_sp: std_logic; -- Load SP signal from EXU to PFU signal exu_busy: std_logic; -- EXU busy ( stalls PFU ) signal pfu_busy: std_logic; -- PFU busy ( stalls DFU ) signal decode_jump: std_logic; -- Jump signal from EXU to DFU signal jump_address: unsigned(maxAddrBit downto 0); -- Jump address from EXU to DFU signal do_interrupt: std_logic; -- Helper. -- Sampled signals from the opcode. Left as signals -- in order to simulate design. signal sampledOpcode: std_logic_vector(OpCode_Size-1 downto 0); signal sampledDecodedOpcode: DecodedOpcodeType; signal sampledOpWillFreeze: std_logic; signal sampledStackOperation: stackChangeType; signal sampledspOffset: unsigned(4 downto 0); signal sampledTosSource: tosSourceType; signal nos: unsigned(wordSize-1 downto 0); -- This is only a helper signal wroteback_q: std_logic; -- TODO: get rid of this here, move to EXU regs -- Test debug signals signal freeze_all: std_logic := '0'; signal single_step: std_logic := '0'; begin -- Debug interface dbg_out.pc <= std_logic_vector(prefr.pc); dbg_out.opcode <= prefr.opcode; dbg_out.sp <= std_logic_vector(prefr.sp); dbg_out.brk <= exr.break; dbg_out.stacka <= std_logic_vector(exr.tos); dbg_out.stackb <= std_logic_vector(nos); dbg_out.idim <= prefr.idim; shl: lshifter port map ( clk => wb_clk_i, rst => wb_rst_i, enable => lshifter_enable, done => lshifter_done, inputA => lshifter_input, inputB => lshifter_amount, output => lshifter_output, multorshift => lshifter_multorshift ); stack_clk <= wb_clk_i; traceFileGenerate: if Generate_Trace generate trace_file: trace port map ( clk => wb_clk_i, begin_inst => begin_inst, pc => trace_pc, opcode => trace_opcode, sp => trace_sp, memA => trace_topOfStack, memB => trace_topOfStackB, busy => '0',--busy, intsp => (others => 'U') ); end generate; tOpcode_sel <= to_integer(decr.pcint(minAddrBit-1 downto 0)); do_interrupt <= '1' when wb_inta_i='1' and exr.inInterrupt='0' else '0'; decodeControl: process(rom_wb_dat_i, tOpcode_sel, sp_load, decr, do_interrupt, dbg_in.inject, dbg_in.opcode) variable tOpcode : std_logic_vector(OpCode_Size-1 downto 0); variable localspOffset: unsigned(4 downto 0); begin if dbg_in.inject='1' then tOpcode := dbg_in.opcode; else case (tOpcode_sel) is when 0 => tOpcode := std_logic_vector(rom_wb_dat_i(31 downto 24)); when 1 => tOpcode := std_logic_vector(rom_wb_dat_i(23 downto 16)); when 2 => tOpcode := std_logic_vector(rom_wb_dat_i(15 downto 8)); when 3 => tOpcode := std_logic_vector(rom_wb_dat_i(7 downto 0)); when others => null; end case; end if; sampledOpcode <= tOpcode; sampledStackOperation <= Stack_Same; sampledTosSource <= Tos_Source_None; sampledOpWillFreeze <= '0'; localspOffset(4):=not tOpcode(4); localspOffset(3 downto 0) := unsigned(tOpcode(3 downto 0)); if do_interrupt='1' and decr.im='0' then sampledDecodedOpcode <= Decoded_Interrupt; sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_PC; else if (tOpcode(7 downto 7)=OpCode_Im) then if decr.im='0' then sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_Idim0; sampledDecodedOpcode<=Decoded_Im0; else sampledTosSource <= Tos_Source_IdimN; sampledDecodedOpcode<=Decoded_ImN; end if; elsif (tOpcode(7 downto 5)=OpCode_StoreSP) then sampledStackOperation <= Stack_Pop; sampledTosSource <= Tos_Source_StackB; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Pop; sampledTosSource <= Tos_Source_StackB; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_PopDown; sampledTosSource <= Tos_Source_None; else sampledDecodedOpcode<=Decoded_StoreSP; sampledOpWillFreeze<='1'; sampledTosSource <= Tos_Source_StackB; end if; elsif (tOpcode(7 downto 5)=OpCode_LoadSP) then sampledStackOperation <= Stack_Push; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Dup; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_DupStackB; sampledTosSource <= Tos_Source_StackB; else sampledDecodedOpcode<=Decoded_LoadSP; sampledTosSource <= Tos_Source_LoadSP; end if; elsif (tOpcode(7 downto 5)=OpCode_Emulate) then -- Emulated instructions implemented in hardware if minimal_implementation then sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; else if (tOpcode(5 downto 0)=OpCode_Loadb) then sampledStackOperation<=Stack_Same; sampledDecodedOpcode<=Decoded_Loadb; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Neqbranch) then sampledStackOperation<=Stack_DualPop; sampledDecodedOpcode<=Decoded_Neqbranch; sampledOpWillFreeze <= '1'; elsif (tOpcode(5 downto 0)=OpCode_Call) then sampledDecodedOpcode<=Decoded_Call; sampledStackOperation<=Stack_Same; sampledTosSource<=Tos_Source_FetchPC; elsif (tOpcode(5 downto 0)=OpCode_Eq) then sampledDecodedOpcode<=Decoded_Eq; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Eq; elsif (tOpcode(5 downto 0)=OpCode_Ulessthan) then sampledDecodedOpcode<=Decoded_Ulessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Ulessthan; elsif (tOpcode(5 downto 0)=OpCode_Lessthan) then sampledDecodedOpcode<=Decoded_Lessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Lessthan; elsif (tOpcode(5 downto 0)=OpCode_StoreB) then sampledDecodedOpcode<=Decoded_StoreB; sampledStackOperation<=Stack_DualPop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Mult) then sampledDecodedOpcode<=Decoded_Mult; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Ashiftleft) then sampledDecodedOpcode<=Decoded_Ashiftleft; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; end if; end if; elsif (tOpcode(7 downto 4)=OpCode_AddSP) then if localspOffset=0 then sampledDecodedOpcode<=Decoded_Shift; sampledTosSource <= Tos_Source_Shift; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_AddStackB; sampledTosSource <= Tos_Source_AddStackB; else sampledDecodedOpcode<=Decoded_AddSP; sampledTosSource <= Tos_Source_AddSP; end if; else case tOpcode(3 downto 0) is when OpCode_Break => sampledDecodedOpcode<=Decoded_Break; sampledOpWillFreeze <= '1'; when OpCode_PushSP => sampledStackOperation <= Stack_Push; sampledDecodedOpcode<=Decoded_PushSP; sampledTosSource <= Tos_Source_SP; when OpCode_PopPC => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_PopPC; sampledTosSource <= Tos_Source_StackB; when OpCode_Add => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Add; sampledTosSource <= Tos_Source_Add; when OpCode_Or => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Or; sampledTosSource <= Tos_Source_Or; when OpCode_And => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_And; sampledTosSource <= Tos_Source_And; when OpCode_Load => sampledDecodedOpcode<=Decoded_Load; sampledOpWillFreeze<='1'; when OpCode_Not => sampledDecodedOpcode<=Decoded_Not; sampledTosSource <= Tos_Source_Not; when OpCode_Flip => sampledDecodedOpcode<=Decoded_Flip; sampledTosSource <= Tos_Source_Flip; when OpCode_Store => sampledStackOperation <= Stack_DualPop; sampledDecodedOpcode<=Decoded_Store; sampledOpWillFreeze<='1'; when OpCode_PopSP => sampledDecodedOpcode<=Decoded_PopSP; sampledOpWillFreeze<='1'; when OpCode_NA4 => if enable_fmul16 then sampledDecodedOpcode<=Decoded_MultF16; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Nop; end if; when others => sampledDecodedOpcode<=Decoded_Nop; end case; end if; end if; sampledspOffset <= localspOffset; end process; -- Decode/Fetch unit rom_wb_stb_o <= not exu_busy; process(decr, jump_address, decode_jump, wb_clk_i, sp_load, sampledDecodedOpcode,sampledOpcode,decode_load_sp, exu_busy, pfu_busy, pcnext, rom_wb_ack_i, wb_rst_i, sampledStackOperation, sampledspOffset, sampledTosSource, prefr.recompute_sp, sampledOpWillFreeze, dbg_in.flush, dbg_in.inject,dbg_in.injectmode, prefr.valid, prefr.break, rom_wb_stall_i ) variable w: decoderegs_type; begin w := decr; pcnext <= decr.fetchpc + 1; rom_wb_adr_o <= std_logic_vector(pc_to_memaddr(decr.fetchpc)); rom_wb_cti_o <= CTI_CYCLE_INCRADDR; if wb_rst_i='1' then w.pc := (others => '0'); w.pcint := (others => '0'); w.valid := '0'; w.fetchpc := (others => '0'); w.im:='0'; w.im_emu:='0'; w.state := State_Run; w.break := '0'; rom_wb_cyc_o <= '0'; else rom_wb_cyc_o <= '1'; case decr.state is when State_Run => if pfu_busy='0' then if dbg_in.injectmode='0' and decr.break='0' and rom_wb_stall_i='0' then w.fetchpc := pcnext; end if; -- Jump request if decode_jump='1' then w.valid := '0'; w.im := '0'; w.break := '0'; -- Invalidate eventual break after branch instruction --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o<='0'; --if rom_wb_stall_i='0' then w.fetchpc := jump_address; --else w.state := State_Jump; --end if; else if dbg_in.injectmode='1' then --or decr.break='1' then -- At this point we ought to push a new op into the pipeline. -- Since we're entering inject mode, invalidate next operation, -- but save the current IM flag. w.im_emu := decr.im; w.valid := '0'; --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o <='0'; -- Wait until no work is to be done if prefr.valid='0' and decr.valid='0' and exu_busy='0' then w.state := State_Inject; w.im:='0'; end if; if decr.break='0' then w.pc := decr.pcint; end if; else if decr.break='1' then w.valid := '0'; else w.valid := rom_wb_ack_i; end if; if rom_wb_ack_i='1' then w.im := sampledOpcode(7); if sampledDecodedOpcode=Decoded_Break then w.break:='1'; end if; end if; if prefr.break='0' and rom_wb_stall_i='0' then w.pcint := decr.fetchpc; w.pc := decr.pcint; end if; if rom_wb_stall_i='0' then w.opcode := sampledOpcode; end if; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; when State_Jump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Run; when State_InjectJump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Inject; when State_Inject => -- NOTE: disable ROM rom_wb_cyc_o <= '0'; if dbg_in.injectmode='0' then w.im := decr.im_emu; w.fetchpc := decr.pcint; w.state := State_Run; w.break := '0'; else -- Handle opcode injection -- TODO: merge this with main decode. -- NOTE: we don't check busy here, it's up to debug unit to do it --if pfu_busy='0' then --w.fetchpc := pcnext; -- Jump request if decode_jump='1' then w.fetchpc := jump_address; w.valid := '0'; w.im := '0'; w.state := State_InjectJump; else w.valid := dbg_in.inject; if dbg_in.inject='1' then w.im := sampledOpcode(7); --w.break := '0'; --w.pcint := decr.fetchpc; w.opcode := sampledOpcode; --w.pc := decr.pcint; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; --end if; end case; end if; -- rst if rising_edge(wb_clk_i) then decr <= w; end if; end process; -- Prefetch/Load unit. sp_load <= exr.tos(spMaxBit downto 2); -- Will be delayed one clock cycle process(wb_clk_i, wb_rst_i, decr, prefr, exu_busy, decode_jump, sp_load, decode_load_sp, dbg_in.flush) variable w: prefetchregs_type; variable i_op_freeze: std_logic; begin w := prefr; pfu_busy<='0'; stack_b_addr <= std_logic_vector(prefr.spnext + 1); w.recompute_sp:='0'; -- Stack w.load := decode_load_sp; if decode_load_sp='1' then pfu_busy <= '1'; w.spnext := sp_load; w.recompute_sp := '1'; else pfu_busy <= exu_busy; if decr.valid='1' then if (exu_busy='0' and decode_jump='0') or prefr.recompute_sp='1' then case decr.stackOperation is when Stack_Push => w.spnext := prefr.spnext - 1; when Stack_Pop => w.spnext := prefr.spnext + 1; when Stack_DualPop => w.spnext := prefr.spnext + 2; when others => end case; w.sp := prefr.spnext; end if; end if; end if; case decr.decodedOpcode is when Decoded_LoadSP | decoded_AddSP => stack_b_addr <= std_logic_vector(prefr.spnext + decr.spOffset); when others => end case; if decode_jump='1' then -- this is a pipeline "invalidate" flag. w.valid := '0'; else if dbg_in.flush='1' then w.valid := '0'; else w.valid := decr.valid; end if; end if; -- Moved op_will_freeze from decoder to here case decr.decodedOpcode is when Decoded_StoreSP | Decoded_LoadB | Decoded_Neqbranch | Decoded_StoreB | Decoded_Mult | Decoded_Ashiftleft | Decoded_Break | Decoded_Load | Decoded_Store | Decoded_PopSP | Decoded_MultF16 => i_op_freeze := '1'; when others => i_op_freeze := '0'; end case; if exu_busy='0' then w.decodedOpcode := decr.decodedOpcode; w.tosSource := decr.tosSource; w.opcode := decr.opcode; w.opWillFreeze := i_op_freeze; w.pc := decr.pc; w.fetchpc := decr.pcint; w.idim := decr.idim; w.break := decr.break; end if; if wb_rst_i='1' then w.spnext := unsigned(spStart(10 downto 2)); --w.sp := unsigned(spStart(10 downto 2)); w.valid := '0'; w.idim := '0'; w.recompute_sp:='0'; end if; if rising_edge(wb_clk_i) then prefr <= w; end if; end process; process(prefr,exr,nos) begin trace_pc <= (others => '0'); trace_pc(maxAddrBit downto 0) <= std_logic_vector(prefr.pc); trace_opcode <= prefr.opcode; trace_sp <= (others => '0'); trace_sp(10 downto 2) <= std_logic_vector(prefr.sp); trace_topOfStack <= std_logic_vector( exr.tos ); trace_topOfStackB <= std_logic_vector( nos ); end process; -- IO/Memory Accesses wb_adr_o(maxAddrBitIncIO downto 0) <= std_logic_vector(exr.tos_save(maxAddrBitIncIO downto 0)); wb_cyc_o <= exr.wb_cyc; wb_stb_o <= exr.wb_stb; wb_we_o <= exr.wb_we; wb_dat_o <= std_logic_vector( exr.nos_save ); freeze_all <= dbg_in.freeze; process(exr, wb_inta_i, wb_clk_i, wb_rst_i, pcnext, stack_a_read,stack_b_read, wb_ack_i, wb_dat_i, do_interrupt,exr, prefr, nos, single_step, freeze_all, dbg_in.step, wroteback_q,lshifter_done,lshifter_output ) variable spOffset: unsigned(4 downto 0); variable w: exuregs_type; variable instruction_executed: std_logic; variable wroteback: std_logic; begin w := exr; instruction_executed := '0'; -- used for single stepping stack_b_writeenable <= '0'; stack_a_enable <= '1'; stack_b_enable <= '1'; exu_busy <= '0'; decode_jump <= '0'; jump_address <= (others => DontCareValue); lshifter_enable <= '0'; lshifter_amount <= std_logic_vector(exr.tos_save); lshifter_input <= std_logic_vector(exr.nos_save); lshifter_multorshift <= '0'; poppc_inst <= '0'; begin_inst<='0'; stack_a_addr <= std_logic_vector( prefr.sp ); stack_a_writeenable <= '0'; wroteback := wroteback_q; stack_b_writeenable <= '0'; stack_a_write <= std_logic_vector(exr.tos); spOffset(4):=not prefr.opcode(4); spOffset(3 downto 0) := unsigned(prefr.opcode(3 downto 0)); if wb_inta_i='0' then w.inInterrupt := '0'; end if; stack_b_write<=(others => DontCareValue); if wroteback_q='1' then nos <= unsigned(stack_a_read); else nos <= unsigned(stack_b_read); end if; decode_load_sp <= '0'; case exr.state is when State_Resync1 => exu_busy <= '1'; stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_ResyncFromStoreStack => exu_busy <= '1'; stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_Resync2 => w.tos := unsigned(stack_a_read); instruction_executed := '1'; exu_busy <= '0'; wroteback := '0'; stack_b_enable <= '1'; w.state := State_Execute; when State_Execute => instruction_executed:='0'; if prefr.valid='1' then exu_busy <= prefr.opWillFreeze; if freeze_all='0' or single_step='1' then wroteback := '0'; w.nos_save := nos; w.tos_save := exr.tos; w.idim := prefr.idim; w.break:= prefr.break; begin_inst<='1'; instruction_executed := '1'; -- TOS big muxer case prefr.tosSource is when Tos_Source_PC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.pc; when Tos_Source_FetchPC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.fetchpc; when Tos_Source_Idim0 => for i in wordSize-1 downto 7 loop w.tos(i) := prefr.opcode(6); end loop; w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_IdimN => w.tos(wordSize-1 downto 7) := exr.tos(wordSize-8 downto 0); w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_StackB => w.tos := nos; when Tos_Source_SP => w.tos := (others => '0'); w.tos(31) := '1'; -- Stack address w.tos(10 downto 2) := prefr.sp; when Tos_Source_Add => w.tos := exr.tos + nos; when Tos_Source_And => w.tos := exr.tos and nos; when Tos_Source_Or => w.tos := exr.tos or nos; when Tos_Source_Eq => w.tos := (others => '0'); if nos = exr.tos then w.tos(0) := '1'; end if; when Tos_Source_Ulessthan => w.tos := (others => '0'); if exr.tos < nos then w.tos(0) := '1'; end if; when Tos_Source_Lessthan => w.tos := (others => '0'); if signed(exr.tos) < signed(nos) then w.tos(0) := '1'; end if; when Tos_Source_Not => w.tos := not exr.tos; when Tos_Source_Flip => for i in 0 to wordSize-1 loop w.tos(i) := exr.tos(wordSize-1-i); end loop; when Tos_Source_LoadSP => w.tos := unsigned(stack_b_read); when Tos_Source_AddSP => w.tos := w.tos + unsigned(stack_b_read); when Tos_Source_AddStackB => w.tos := w.tos + nos; when Tos_Source_Shift => w.tos := exr.tos + exr.tos; when others => end case; case prefr.decodedOpcode is when Decoded_Interrupt => w.inInterrupt := '1'; jump_address <= to_unsigned(32, maxAddrBit+1); decode_jump <= '1'; stack_a_writeenable<='1'; wroteback:='1'; stack_b_enable<='0'; instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Im0 => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_ImN => when Decoded_Nop => when Decoded_PopPC | Decoded_Call => decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0); poppc_inst <= '1'; stack_b_enable<='0'; -- Delay instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Emulate => decode_jump <= '1'; jump_address <= (others => '0'); jump_address(9 downto 5) <= unsigned(prefr.opcode(4 downto 0)); stack_a_writeenable<='1'; wroteback:='1'; when Decoded_PushSP => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_LoadSP => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_DupStackB => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_Dup => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_AddSP => stack_a_writeenable <= '1'; when Decoded_StoreSP => stack_a_writeenable <= '1'; wroteback:='1'; stack_a_addr <= std_logic_vector(prefr.sp + spOffset); instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_PopDown => stack_a_writeenable<='1'; when Decoded_Pop => when Decoded_Ashiftleft => w.state := State_Ashiftleft; when Decoded_Mult => w.state := State_Mult; when Decoded_MultF16 => w.state := State_MultF16; when Decoded_Store => if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(nos); stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when Decoded_Load | Decoded_Loadb | Decoded_StoreB => --w.tos_save := exr.tos; -- Byte select instruction_executed := '0'; wroteback := wroteback_q; -- Keep WB if exr.tos(wordSize-1)='1' then stack_a_addr<=std_logic_vector(exr.tos(10 downto 2)); stack_a_enable<='1'; w.state := State_LoadStack; else stack_a_enable <= '0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); w.wb_we :='0'; w.wb_cyc :='1'; w.wb_stb :='1'; w.state := State_Load; end if; when Decoded_PopSP => decode_load_sp <= '1'; instruction_executed := '0'; stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); w.state := State_Resync2; --when Decoded_Break => -- w.break := '1'; when Decoded_Neqbranch => instruction_executed := '0'; w.state := State_NeqBranch; when others => end case; else -- freeze_all -- -- Freeze the entire pipeline. -- exu_busy<='1'; stack_a_enable<='0'; stack_b_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); end if; end if; -- valid when State_Ashiftleft => exu_busy <= '1'; lshifter_enable <= '1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_Mult => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_MultF16 => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(47 downto 16)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_WaitSPB => instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Store => exu_busy <= '1'; -- Keep writeback flag wroteback := wroteback_q; if wb_ack_i='1' then stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; stack_b_enable<='1'; wroteback := '0'; --exu_busy <= '1'; w.wb_cyc := '0'; w.state := State_Resync2; else stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_a_enable<='0'; stack_b_enable<='0'; end if; when State_Loadb => w.tos(wordSize-1 downto 8) := (others => '0'); case exr.tos_save(1 downto 0) is when "11" => w.tos(7 downto 0) := unsigned(exr.tos(7 downto 0)); when "10" => w.tos(7 downto 0) := unsigned(exr.tos(15 downto 8)); when "01" => w.tos(7 downto 0) := unsigned(exr.tos(23 downto 16)); when "00" => w.tos(7 downto 0) := unsigned(exr.tos(31 downto 24)); when others => null; end case; instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Load => if wb_ack_i='0' then exu_busy<='1'; else w.tos := unsigned(wb_dat_i); w.wb_cyc := '0'; if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state := State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state := State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; end if; when State_LoadStack => w.tos := unsigned(stack_a_read); if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state:=State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state:=State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; when State_NeqBranch => if exr.nos_save/=0 then decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0) + prefr.pc; poppc_inst <= '1'; exu_busy <= '0'; else exu_busy <='1'; end if; instruction_executed := '0'; stack_a_addr <= std_logic_vector(prefr.spnext); wroteback:='0'; w.state := State_Resync2; when State_StoreB => exu_busy <= '1'; -- -- At this point, we have loaded the 32-bit, and it's in TOS -- The IO address is still saved in save_TOS. -- The original write value is still at save_NOS -- -- So we mangle the write value, and update save_NOS, and restore -- the IO address to TOS -- -- This is still buggy - don't use. Problems arise when writing to stack. -- w.nos_save := exr.tos; case exr.tos_save(1 downto 0) is when "00" => w.nos_save(31 downto 24) := exr.nos_save(7 downto 0); when "01" => w.nos_save(23 downto 16) := exr.nos_save(7 downto 0); when "10" => w.nos_save(15 downto 8) := exr.nos_save(7 downto 0); when "11" => w.nos_save(7 downto 0) := exr.nos_save(7 downto 0); when others => null; end case; w.tos := exr.tos_save; w.state := State_StoreB2; when State_StoreB2 => exu_busy <= '1'; if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(exr.nos_save); -- hmm I don't like this stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when others => null; end case; if rising_edge(wb_clk_i) then if wb_rst_i='1' then exr.state <= State_Execute; exr.idim <= DontCareValue; exr.inInterrupt <= '0'; exr.break <= '0'; exr.wb_cyc <= '0'; exr.wb_stb <= '1'; else exr <= w; -- TODO: move wroteback_q into EXU regs wroteback_q <= wroteback; if exr.break='1' then report "BREAK" severity failure; end if; -- Some sanity checks, to be caught in simulation if prefr.valid='1' then if prefr.tosSource=Tos_Source_Idim0 and prefr.idim='1' then report "Invalid IDIM flag 0" severity error; end if; if prefr.tosSource=Tos_Source_IdimN and prefr.idim='0' then report "Invalid IDIM flag 1" severity error; end if; end if; end if; end if; end process; single_step <= dbg_in.step; dbg_out.valid <= '1' when prefr.valid='1' else '0'; -- Let pipeline finish dbg_out.ready <= '1' when exr.state=state_execute and decode_load_sp='0' and decode_jump='0' and decr.state = State_Inject --and jump_q='0' else '0'; end behave;
-- ZPU -- -- Copyright 2004-2008 oharboe - Øyvind Harboe - [email protected] -- Copyright 2010-2012 Alvaro Lopes - [email protected] -- -- The FreeBSD license -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions -- are met: -- -- 1. Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer. -- 2. Redistributions in binary form must reproduce the above -- copyright notice, this list of conditions and the following -- disclaimer in the documentation and/or other materials -- provided with the distribution. -- -- THIS SOFTWARE IS PROVIDED BY THE ZPU PROJECT ``AS IS'' AND ANY -- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -- ZPU PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- The views and conclusions contained in the software and documentation -- are those of the authors and should not be interpreted as representing -- official policies, either expressed or implied, of the ZPU Project. library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.numeric_std.all; library board; use board.zpu_config.all; use board.zpupkg.all; use board.wishbonepkg.all; --library UNISIM; --use UNISIM.vcomponents.all; entity zpu_core_extreme is port ( wb_clk_i: in std_logic; wb_rst_i: in std_logic; -- Master wishbone interface wb_ack_i: in std_logic; wb_dat_i: in std_logic_vector(wordSize-1 downto 0); wb_dat_o: out std_logic_vector(wordSize-1 downto 0); wb_adr_o: out std_logic_vector(maxAddrBitIncIO downto 0); wb_cyc_o: out std_logic; wb_stb_o: out std_logic; wb_we_o: out std_logic; wb_inta_i: in std_logic; poppc_inst: out std_logic; break: out std_logic; -- STACK stack_a_read: in std_logic_vector(wordSize-1 downto 0); stack_b_read: in std_logic_vector(wordSize-1 downto 0); stack_a_write: out std_logic_vector(wordSize-1 downto 0); stack_b_write: out std_logic_vector(wordSize-1 downto 0); stack_a_writeenable: out std_logic; stack_a_enable: out std_logic; stack_b_writeenable: out std_logic; stack_b_enable: out std_logic; stack_a_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_b_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_clk: out std_logic; -- ROM wb interface rom_wb_ack_i: in std_logic; rom_wb_dat_i: in std_logic_vector(wordSize-1 downto 0); rom_wb_adr_o: out std_logic_vector(maxAddrBit downto 0); rom_wb_cyc_o: out std_logic; rom_wb_stb_o: out std_logic; rom_wb_cti_o: out std_logic_vector(2 downto 0); rom_wb_stall_i: in std_logic; -- Debug interface dbg_out: out zpu_dbg_out_type; dbg_in: in zpu_dbg_in_type ); end zpu_core_extreme; architecture behave of zpu_core_extreme is component lshifter is port ( clk: in std_logic; rst: in std_logic; enable: in std_logic; done: out std_logic; inputA: in std_logic_vector(31 downto 0); inputB: in std_logic_vector(31 downto 0); output: out std_logic_vector(63 downto 0); multorshift: in std_logic ); end component; signal lshifter_enable: std_logic; signal lshifter_done: std_logic; signal lshifter_input: std_logic_vector(31 downto 0); signal lshifter_amount: std_logic_vector(31 downto 0); signal lshifter_output: std_logic_vector(63 downto 0); signal lshifter_multorshift: std_logic; signal begin_inst: std_logic; signal trace_opcode: std_logic_vector(7 downto 0); signal trace_pc: std_logic_vector(maxAddrBitIncIO downto 0); signal trace_sp: std_logic_vector(maxAddrBitIncIO downto minAddrBit); signal trace_topOfStack: std_logic_vector(wordSize-1 downto 0); signal trace_topOfStackB: std_logic_vector(wordSize-1 downto 0); -- state machine. type State_Type is ( State_Execute, State_Store, State_StoreB, State_StoreB2, State_Load, State_LoadMemory, State_LoadStack, State_Loadb, State_Resync1, State_Resync2, State_LoadSP, State_WaitSPB, State_ResyncFromStoreStack, State_Neqbranch, State_Ashiftleft, State_Mult, State_MultF16 ); type DecodedOpcodeType is ( Decoded_Nop, Decoded_Idle, Decoded_Im0, Decoded_ImN, Decoded_LoadSP, Decoded_Dup, Decoded_DupStackB, Decoded_StoreSP, Decoded_Pop, Decoded_PopDown, Decoded_AddSP, Decoded_AddStackB, Decoded_Shift, Decoded_Emulate, Decoded_Break, Decoded_PushSP, Decoded_PopPC, Decoded_Add, Decoded_Or, Decoded_And, Decoded_Load, Decoded_Not, Decoded_Flip, Decoded_Store, Decoded_PopSP, Decoded_Interrupt, Decoded_Neqbranch, Decoded_Eq, Decoded_Storeb, Decoded_Storeh, Decoded_Ulessthan, Decoded_Lessthan, Decoded_Ashiftleft, Decoded_Ashiftright, Decoded_Loadb, Decoded_Call, Decoded_Mult, Decoded_MultF16 ); constant spMaxBit: integer := 10; constant minimal_implementation: boolean := false; subtype index is integer range 0 to 3; signal tOpcode_sel : index; function pc_to_cpuword(pc: unsigned) return unsigned is variable r: unsigned(wordSize-1 downto 0); begin r := (others => DontCareValue); r(maxAddrBit downto 0) := pc; return r; end pc_to_cpuword; function pc_to_memaddr(pc: unsigned) return unsigned is variable r: unsigned(maxAddrBit downto 0); begin r := (others => '0'); r(maxAddrBit downto minAddrBit) := pc(maxAddrBit downto minAddrBit); return r; end pc_to_memaddr; -- Prefetch stage registers type stackChangeType is ( Stack_Same, Stack_Push, Stack_Pop, Stack_DualPop ); type tosSourceType is ( Tos_Source_PC, Tos_Source_FetchPC, Tos_Source_Idim0, Tos_Source_IdimN, Tos_Source_StackB, Tos_Source_SP, Tos_Source_Add, Tos_Source_And, Tos_Source_Or, Tos_Source_Eq, Tos_Source_Not, Tos_Source_Flip, Tos_Source_LoadSP, Tos_Source_AddSP, Tos_Source_AddStackB, Tos_Source_Shift, Tos_Source_Ulessthan, Tos_Source_Lessthan, Tos_Source_None ); type decoderstate_type is ( State_Run, State_Jump, State_Inject, State_InjectJump ); type decoderegs_type is record valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opWillFreeze: std_logic; -- '1' if we know in advance this opcode will freeze pipeline opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); pcint: unsigned(maxAddrBit downto 0); idim: std_logic; im: std_logic; stackOperation: stackChangeType; spOffset: unsigned(4 downto 0); im_emu: std_logic; --emumode: std_logic; break: std_logic; state: decoderstate_type; end record; type prefetchregs_type is record sp: unsigned(spMaxBit downto 2); spnext: unsigned(spMaxBit downto 2); valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); idim: std_logic; break: std_logic; load: std_logic; opWillFreeze: std_logic; recompute_sp: std_logic; end record; type exuregs_type is record idim: std_logic; break: std_logic; inInterrupt:std_logic; tos: unsigned(wordSize-1 downto 0); tos_save: unsigned(wordSize-1 downto 0); nos_save: unsigned(wordSize-1 downto 0); state: State_Type; -- Wishbone control signals (registered) wb_cyc: std_logic; wb_stb: std_logic; wb_we: std_logic; end record; -- Registers for each stage signal exr: exuregs_type; signal prefr: prefetchregs_type; signal decr: decoderegs_type; signal pcnext: unsigned(maxAddrBit downto 0); -- Helper only. TODO: move into variable signal sp_load: unsigned(spMaxBit downto 2); -- SP value to load, coming from EXU into PFU signal decode_load_sp: std_logic; -- Load SP signal from EXU to PFU signal exu_busy: std_logic; -- EXU busy ( stalls PFU ) signal pfu_busy: std_logic; -- PFU busy ( stalls DFU ) signal decode_jump: std_logic; -- Jump signal from EXU to DFU signal jump_address: unsigned(maxAddrBit downto 0); -- Jump address from EXU to DFU signal do_interrupt: std_logic; -- Helper. -- Sampled signals from the opcode. Left as signals -- in order to simulate design. signal sampledOpcode: std_logic_vector(OpCode_Size-1 downto 0); signal sampledDecodedOpcode: DecodedOpcodeType; signal sampledOpWillFreeze: std_logic; signal sampledStackOperation: stackChangeType; signal sampledspOffset: unsigned(4 downto 0); signal sampledTosSource: tosSourceType; signal nos: unsigned(wordSize-1 downto 0); -- This is only a helper signal wroteback_q: std_logic; -- TODO: get rid of this here, move to EXU regs -- Test debug signals signal freeze_all: std_logic := '0'; signal single_step: std_logic := '0'; begin -- Debug interface dbg_out.pc <= std_logic_vector(prefr.pc); dbg_out.opcode <= prefr.opcode; dbg_out.sp <= std_logic_vector(prefr.sp); dbg_out.brk <= exr.break; dbg_out.stacka <= std_logic_vector(exr.tos); dbg_out.stackb <= std_logic_vector(nos); dbg_out.idim <= prefr.idim; shl: lshifter port map ( clk => wb_clk_i, rst => wb_rst_i, enable => lshifter_enable, done => lshifter_done, inputA => lshifter_input, inputB => lshifter_amount, output => lshifter_output, multorshift => lshifter_multorshift ); stack_clk <= wb_clk_i; traceFileGenerate: if Generate_Trace generate trace_file: trace port map ( clk => wb_clk_i, begin_inst => begin_inst, pc => trace_pc, opcode => trace_opcode, sp => trace_sp, memA => trace_topOfStack, memB => trace_topOfStackB, busy => '0',--busy, intsp => (others => 'U') ); end generate; tOpcode_sel <= to_integer(decr.pcint(minAddrBit-1 downto 0)); do_interrupt <= '1' when wb_inta_i='1' and exr.inInterrupt='0' else '0'; decodeControl: process(rom_wb_dat_i, tOpcode_sel, sp_load, decr, do_interrupt, dbg_in.inject, dbg_in.opcode) variable tOpcode : std_logic_vector(OpCode_Size-1 downto 0); variable localspOffset: unsigned(4 downto 0); begin if dbg_in.inject='1' then tOpcode := dbg_in.opcode; else case (tOpcode_sel) is when 0 => tOpcode := std_logic_vector(rom_wb_dat_i(31 downto 24)); when 1 => tOpcode := std_logic_vector(rom_wb_dat_i(23 downto 16)); when 2 => tOpcode := std_logic_vector(rom_wb_dat_i(15 downto 8)); when 3 => tOpcode := std_logic_vector(rom_wb_dat_i(7 downto 0)); when others => null; end case; end if; sampledOpcode <= tOpcode; sampledStackOperation <= Stack_Same; sampledTosSource <= Tos_Source_None; sampledOpWillFreeze <= '0'; localspOffset(4):=not tOpcode(4); localspOffset(3 downto 0) := unsigned(tOpcode(3 downto 0)); if do_interrupt='1' and decr.im='0' then sampledDecodedOpcode <= Decoded_Interrupt; sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_PC; else if (tOpcode(7 downto 7)=OpCode_Im) then if decr.im='0' then sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_Idim0; sampledDecodedOpcode<=Decoded_Im0; else sampledTosSource <= Tos_Source_IdimN; sampledDecodedOpcode<=Decoded_ImN; end if; elsif (tOpcode(7 downto 5)=OpCode_StoreSP) then sampledStackOperation <= Stack_Pop; sampledTosSource <= Tos_Source_StackB; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Pop; sampledTosSource <= Tos_Source_StackB; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_PopDown; sampledTosSource <= Tos_Source_None; else sampledDecodedOpcode<=Decoded_StoreSP; sampledOpWillFreeze<='1'; sampledTosSource <= Tos_Source_StackB; end if; elsif (tOpcode(7 downto 5)=OpCode_LoadSP) then sampledStackOperation <= Stack_Push; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Dup; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_DupStackB; sampledTosSource <= Tos_Source_StackB; else sampledDecodedOpcode<=Decoded_LoadSP; sampledTosSource <= Tos_Source_LoadSP; end if; elsif (tOpcode(7 downto 5)=OpCode_Emulate) then -- Emulated instructions implemented in hardware if minimal_implementation then sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; else if (tOpcode(5 downto 0)=OpCode_Loadb) then sampledStackOperation<=Stack_Same; sampledDecodedOpcode<=Decoded_Loadb; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Neqbranch) then sampledStackOperation<=Stack_DualPop; sampledDecodedOpcode<=Decoded_Neqbranch; sampledOpWillFreeze <= '1'; elsif (tOpcode(5 downto 0)=OpCode_Call) then sampledDecodedOpcode<=Decoded_Call; sampledStackOperation<=Stack_Same; sampledTosSource<=Tos_Source_FetchPC; elsif (tOpcode(5 downto 0)=OpCode_Eq) then sampledDecodedOpcode<=Decoded_Eq; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Eq; elsif (tOpcode(5 downto 0)=OpCode_Ulessthan) then sampledDecodedOpcode<=Decoded_Ulessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Ulessthan; elsif (tOpcode(5 downto 0)=OpCode_Lessthan) then sampledDecodedOpcode<=Decoded_Lessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Lessthan; elsif (tOpcode(5 downto 0)=OpCode_StoreB) then sampledDecodedOpcode<=Decoded_StoreB; sampledStackOperation<=Stack_DualPop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Mult) then sampledDecodedOpcode<=Decoded_Mult; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Ashiftleft) then sampledDecodedOpcode<=Decoded_Ashiftleft; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; end if; end if; elsif (tOpcode(7 downto 4)=OpCode_AddSP) then if localspOffset=0 then sampledDecodedOpcode<=Decoded_Shift; sampledTosSource <= Tos_Source_Shift; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_AddStackB; sampledTosSource <= Tos_Source_AddStackB; else sampledDecodedOpcode<=Decoded_AddSP; sampledTosSource <= Tos_Source_AddSP; end if; else case tOpcode(3 downto 0) is when OpCode_Break => sampledDecodedOpcode<=Decoded_Break; sampledOpWillFreeze <= '1'; when OpCode_PushSP => sampledStackOperation <= Stack_Push; sampledDecodedOpcode<=Decoded_PushSP; sampledTosSource <= Tos_Source_SP; when OpCode_PopPC => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_PopPC; sampledTosSource <= Tos_Source_StackB; when OpCode_Add => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Add; sampledTosSource <= Tos_Source_Add; when OpCode_Or => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Or; sampledTosSource <= Tos_Source_Or; when OpCode_And => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_And; sampledTosSource <= Tos_Source_And; when OpCode_Load => sampledDecodedOpcode<=Decoded_Load; sampledOpWillFreeze<='1'; when OpCode_Not => sampledDecodedOpcode<=Decoded_Not; sampledTosSource <= Tos_Source_Not; when OpCode_Flip => sampledDecodedOpcode<=Decoded_Flip; sampledTosSource <= Tos_Source_Flip; when OpCode_Store => sampledStackOperation <= Stack_DualPop; sampledDecodedOpcode<=Decoded_Store; sampledOpWillFreeze<='1'; when OpCode_PopSP => sampledDecodedOpcode<=Decoded_PopSP; sampledOpWillFreeze<='1'; when OpCode_NA4 => if enable_fmul16 then sampledDecodedOpcode<=Decoded_MultF16; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Nop; end if; when others => sampledDecodedOpcode<=Decoded_Nop; end case; end if; end if; sampledspOffset <= localspOffset; end process; -- Decode/Fetch unit rom_wb_stb_o <= not exu_busy; process(decr, jump_address, decode_jump, wb_clk_i, sp_load, sampledDecodedOpcode,sampledOpcode,decode_load_sp, exu_busy, pfu_busy, pcnext, rom_wb_ack_i, wb_rst_i, sampledStackOperation, sampledspOffset, sampledTosSource, prefr.recompute_sp, sampledOpWillFreeze, dbg_in.flush, dbg_in.inject,dbg_in.injectmode, prefr.valid, prefr.break, rom_wb_stall_i ) variable w: decoderegs_type; begin w := decr; pcnext <= decr.fetchpc + 1; rom_wb_adr_o <= std_logic_vector(pc_to_memaddr(decr.fetchpc)); rom_wb_cti_o <= CTI_CYCLE_INCRADDR; if wb_rst_i='1' then w.pc := (others => '0'); w.pcint := (others => '0'); w.valid := '0'; w.fetchpc := (others => '0'); w.im:='0'; w.im_emu:='0'; w.state := State_Run; w.break := '0'; rom_wb_cyc_o <= '0'; else rom_wb_cyc_o <= '1'; case decr.state is when State_Run => if pfu_busy='0' then if dbg_in.injectmode='0' and decr.break='0' and rom_wb_stall_i='0' then w.fetchpc := pcnext; end if; -- Jump request if decode_jump='1' then w.valid := '0'; w.im := '0'; w.break := '0'; -- Invalidate eventual break after branch instruction --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o<='0'; --if rom_wb_stall_i='0' then w.fetchpc := jump_address; --else w.state := State_Jump; --end if; else if dbg_in.injectmode='1' then --or decr.break='1' then -- At this point we ought to push a new op into the pipeline. -- Since we're entering inject mode, invalidate next operation, -- but save the current IM flag. w.im_emu := decr.im; w.valid := '0'; --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o <='0'; -- Wait until no work is to be done if prefr.valid='0' and decr.valid='0' and exu_busy='0' then w.state := State_Inject; w.im:='0'; end if; if decr.break='0' then w.pc := decr.pcint; end if; else if decr.break='1' then w.valid := '0'; else w.valid := rom_wb_ack_i; end if; if rom_wb_ack_i='1' then w.im := sampledOpcode(7); if sampledDecodedOpcode=Decoded_Break then w.break:='1'; end if; end if; if prefr.break='0' and rom_wb_stall_i='0' then w.pcint := decr.fetchpc; w.pc := decr.pcint; end if; if rom_wb_stall_i='0' then w.opcode := sampledOpcode; end if; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; when State_Jump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Run; when State_InjectJump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Inject; when State_Inject => -- NOTE: disable ROM rom_wb_cyc_o <= '0'; if dbg_in.injectmode='0' then w.im := decr.im_emu; w.fetchpc := decr.pcint; w.state := State_Run; w.break := '0'; else -- Handle opcode injection -- TODO: merge this with main decode. -- NOTE: we don't check busy here, it's up to debug unit to do it --if pfu_busy='0' then --w.fetchpc := pcnext; -- Jump request if decode_jump='1' then w.fetchpc := jump_address; w.valid := '0'; w.im := '0'; w.state := State_InjectJump; else w.valid := dbg_in.inject; if dbg_in.inject='1' then w.im := sampledOpcode(7); --w.break := '0'; --w.pcint := decr.fetchpc; w.opcode := sampledOpcode; --w.pc := decr.pcint; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; --end if; end case; end if; -- rst if rising_edge(wb_clk_i) then decr <= w; end if; end process; -- Prefetch/Load unit. sp_load <= exr.tos(spMaxBit downto 2); -- Will be delayed one clock cycle process(wb_clk_i, wb_rst_i, decr, prefr, exu_busy, decode_jump, sp_load, decode_load_sp, dbg_in.flush) variable w: prefetchregs_type; variable i_op_freeze: std_logic; begin w := prefr; pfu_busy<='0'; stack_b_addr <= std_logic_vector(prefr.spnext + 1); w.recompute_sp:='0'; -- Stack w.load := decode_load_sp; if decode_load_sp='1' then pfu_busy <= '1'; w.spnext := sp_load; w.recompute_sp := '1'; else pfu_busy <= exu_busy; if decr.valid='1' then if (exu_busy='0' and decode_jump='0') or prefr.recompute_sp='1' then case decr.stackOperation is when Stack_Push => w.spnext := prefr.spnext - 1; when Stack_Pop => w.spnext := prefr.spnext + 1; when Stack_DualPop => w.spnext := prefr.spnext + 2; when others => end case; w.sp := prefr.spnext; end if; end if; end if; case decr.decodedOpcode is when Decoded_LoadSP | decoded_AddSP => stack_b_addr <= std_logic_vector(prefr.spnext + decr.spOffset); when others => end case; if decode_jump='1' then -- this is a pipeline "invalidate" flag. w.valid := '0'; else if dbg_in.flush='1' then w.valid := '0'; else w.valid := decr.valid; end if; end if; -- Moved op_will_freeze from decoder to here case decr.decodedOpcode is when Decoded_StoreSP | Decoded_LoadB | Decoded_Neqbranch | Decoded_StoreB | Decoded_Mult | Decoded_Ashiftleft | Decoded_Break | Decoded_Load | Decoded_Store | Decoded_PopSP | Decoded_MultF16 => i_op_freeze := '1'; when others => i_op_freeze := '0'; end case; if exu_busy='0' then w.decodedOpcode := decr.decodedOpcode; w.tosSource := decr.tosSource; w.opcode := decr.opcode; w.opWillFreeze := i_op_freeze; w.pc := decr.pc; w.fetchpc := decr.pcint; w.idim := decr.idim; w.break := decr.break; end if; if wb_rst_i='1' then w.spnext := unsigned(spStart(10 downto 2)); --w.sp := unsigned(spStart(10 downto 2)); w.valid := '0'; w.idim := '0'; w.recompute_sp:='0'; end if; if rising_edge(wb_clk_i) then prefr <= w; end if; end process; process(prefr,exr,nos) begin trace_pc <= (others => '0'); trace_pc(maxAddrBit downto 0) <= std_logic_vector(prefr.pc); trace_opcode <= prefr.opcode; trace_sp <= (others => '0'); trace_sp(10 downto 2) <= std_logic_vector(prefr.sp); trace_topOfStack <= std_logic_vector( exr.tos ); trace_topOfStackB <= std_logic_vector( nos ); end process; -- IO/Memory Accesses wb_adr_o(maxAddrBitIncIO downto 0) <= std_logic_vector(exr.tos_save(maxAddrBitIncIO downto 0)); wb_cyc_o <= exr.wb_cyc; wb_stb_o <= exr.wb_stb; wb_we_o <= exr.wb_we; wb_dat_o <= std_logic_vector( exr.nos_save ); freeze_all <= dbg_in.freeze; process(exr, wb_inta_i, wb_clk_i, wb_rst_i, pcnext, stack_a_read,stack_b_read, wb_ack_i, wb_dat_i, do_interrupt,exr, prefr, nos, single_step, freeze_all, dbg_in.step, wroteback_q,lshifter_done,lshifter_output ) variable spOffset: unsigned(4 downto 0); variable w: exuregs_type; variable instruction_executed: std_logic; variable wroteback: std_logic; begin w := exr; instruction_executed := '0'; -- used for single stepping stack_b_writeenable <= '0'; stack_a_enable <= '1'; stack_b_enable <= '1'; exu_busy <= '0'; decode_jump <= '0'; jump_address <= (others => DontCareValue); lshifter_enable <= '0'; lshifter_amount <= std_logic_vector(exr.tos_save); lshifter_input <= std_logic_vector(exr.nos_save); lshifter_multorshift <= '0'; poppc_inst <= '0'; begin_inst<='0'; stack_a_addr <= std_logic_vector( prefr.sp ); stack_a_writeenable <= '0'; wroteback := wroteback_q; stack_b_writeenable <= '0'; stack_a_write <= std_logic_vector(exr.tos); spOffset(4):=not prefr.opcode(4); spOffset(3 downto 0) := unsigned(prefr.opcode(3 downto 0)); if wb_inta_i='0' then w.inInterrupt := '0'; end if; stack_b_write<=(others => DontCareValue); if wroteback_q='1' then nos <= unsigned(stack_a_read); else nos <= unsigned(stack_b_read); end if; decode_load_sp <= '0'; case exr.state is when State_Resync1 => exu_busy <= '1'; stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_ResyncFromStoreStack => exu_busy <= '1'; stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_Resync2 => w.tos := unsigned(stack_a_read); instruction_executed := '1'; exu_busy <= '0'; wroteback := '0'; stack_b_enable <= '1'; w.state := State_Execute; when State_Execute => instruction_executed:='0'; if prefr.valid='1' then exu_busy <= prefr.opWillFreeze; if freeze_all='0' or single_step='1' then wroteback := '0'; w.nos_save := nos; w.tos_save := exr.tos; w.idim := prefr.idim; w.break:= prefr.break; begin_inst<='1'; instruction_executed := '1'; -- TOS big muxer case prefr.tosSource is when Tos_Source_PC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.pc; when Tos_Source_FetchPC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.fetchpc; when Tos_Source_Idim0 => for i in wordSize-1 downto 7 loop w.tos(i) := prefr.opcode(6); end loop; w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_IdimN => w.tos(wordSize-1 downto 7) := exr.tos(wordSize-8 downto 0); w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_StackB => w.tos := nos; when Tos_Source_SP => w.tos := (others => '0'); w.tos(31) := '1'; -- Stack address w.tos(10 downto 2) := prefr.sp; when Tos_Source_Add => w.tos := exr.tos + nos; when Tos_Source_And => w.tos := exr.tos and nos; when Tos_Source_Or => w.tos := exr.tos or nos; when Tos_Source_Eq => w.tos := (others => '0'); if nos = exr.tos then w.tos(0) := '1'; end if; when Tos_Source_Ulessthan => w.tos := (others => '0'); if exr.tos < nos then w.tos(0) := '1'; end if; when Tos_Source_Lessthan => w.tos := (others => '0'); if signed(exr.tos) < signed(nos) then w.tos(0) := '1'; end if; when Tos_Source_Not => w.tos := not exr.tos; when Tos_Source_Flip => for i in 0 to wordSize-1 loop w.tos(i) := exr.tos(wordSize-1-i); end loop; when Tos_Source_LoadSP => w.tos := unsigned(stack_b_read); when Tos_Source_AddSP => w.tos := w.tos + unsigned(stack_b_read); when Tos_Source_AddStackB => w.tos := w.tos + nos; when Tos_Source_Shift => w.tos := exr.tos + exr.tos; when others => end case; case prefr.decodedOpcode is when Decoded_Interrupt => w.inInterrupt := '1'; jump_address <= to_unsigned(32, maxAddrBit+1); decode_jump <= '1'; stack_a_writeenable<='1'; wroteback:='1'; stack_b_enable<='0'; instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Im0 => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_ImN => when Decoded_Nop => when Decoded_PopPC | Decoded_Call => decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0); poppc_inst <= '1'; stack_b_enable<='0'; -- Delay instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Emulate => decode_jump <= '1'; jump_address <= (others => '0'); jump_address(9 downto 5) <= unsigned(prefr.opcode(4 downto 0)); stack_a_writeenable<='1'; wroteback:='1'; when Decoded_PushSP => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_LoadSP => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_DupStackB => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_Dup => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_AddSP => stack_a_writeenable <= '1'; when Decoded_StoreSP => stack_a_writeenable <= '1'; wroteback:='1'; stack_a_addr <= std_logic_vector(prefr.sp + spOffset); instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_PopDown => stack_a_writeenable<='1'; when Decoded_Pop => when Decoded_Ashiftleft => w.state := State_Ashiftleft; when Decoded_Mult => w.state := State_Mult; when Decoded_MultF16 => w.state := State_MultF16; when Decoded_Store => if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(nos); stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when Decoded_Load | Decoded_Loadb | Decoded_StoreB => --w.tos_save := exr.tos; -- Byte select instruction_executed := '0'; wroteback := wroteback_q; -- Keep WB if exr.tos(wordSize-1)='1' then stack_a_addr<=std_logic_vector(exr.tos(10 downto 2)); stack_a_enable<='1'; w.state := State_LoadStack; else stack_a_enable <= '0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); w.wb_we :='0'; w.wb_cyc :='1'; w.wb_stb :='1'; w.state := State_Load; end if; when Decoded_PopSP => decode_load_sp <= '1'; instruction_executed := '0'; stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); w.state := State_Resync2; --when Decoded_Break => -- w.break := '1'; when Decoded_Neqbranch => instruction_executed := '0'; w.state := State_NeqBranch; when others => end case; else -- freeze_all -- -- Freeze the entire pipeline. -- exu_busy<='1'; stack_a_enable<='0'; stack_b_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); end if; end if; -- valid when State_Ashiftleft => exu_busy <= '1'; lshifter_enable <= '1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_Mult => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_MultF16 => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(47 downto 16)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_WaitSPB => instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Store => exu_busy <= '1'; -- Keep writeback flag wroteback := wroteback_q; if wb_ack_i='1' then stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; stack_b_enable<='1'; wroteback := '0'; --exu_busy <= '1'; w.wb_cyc := '0'; w.state := State_Resync2; else stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_a_enable<='0'; stack_b_enable<='0'; end if; when State_Loadb => w.tos(wordSize-1 downto 8) := (others => '0'); case exr.tos_save(1 downto 0) is when "11" => w.tos(7 downto 0) := unsigned(exr.tos(7 downto 0)); when "10" => w.tos(7 downto 0) := unsigned(exr.tos(15 downto 8)); when "01" => w.tos(7 downto 0) := unsigned(exr.tos(23 downto 16)); when "00" => w.tos(7 downto 0) := unsigned(exr.tos(31 downto 24)); when others => null; end case; instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Load => if wb_ack_i='0' then exu_busy<='1'; else w.tos := unsigned(wb_dat_i); w.wb_cyc := '0'; if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state := State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state := State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; end if; when State_LoadStack => w.tos := unsigned(stack_a_read); if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state:=State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state:=State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; when State_NeqBranch => if exr.nos_save/=0 then decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0) + prefr.pc; poppc_inst <= '1'; exu_busy <= '0'; else exu_busy <='1'; end if; instruction_executed := '0'; stack_a_addr <= std_logic_vector(prefr.spnext); wroteback:='0'; w.state := State_Resync2; when State_StoreB => exu_busy <= '1'; -- -- At this point, we have loaded the 32-bit, and it's in TOS -- The IO address is still saved in save_TOS. -- The original write value is still at save_NOS -- -- So we mangle the write value, and update save_NOS, and restore -- the IO address to TOS -- -- This is still buggy - don't use. Problems arise when writing to stack. -- w.nos_save := exr.tos; case exr.tos_save(1 downto 0) is when "00" => w.nos_save(31 downto 24) := exr.nos_save(7 downto 0); when "01" => w.nos_save(23 downto 16) := exr.nos_save(7 downto 0); when "10" => w.nos_save(15 downto 8) := exr.nos_save(7 downto 0); when "11" => w.nos_save(7 downto 0) := exr.nos_save(7 downto 0); when others => null; end case; w.tos := exr.tos_save; w.state := State_StoreB2; when State_StoreB2 => exu_busy <= '1'; if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(exr.nos_save); -- hmm I don't like this stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when others => null; end case; if rising_edge(wb_clk_i) then if wb_rst_i='1' then exr.state <= State_Execute; exr.idim <= DontCareValue; exr.inInterrupt <= '0'; exr.break <= '0'; exr.wb_cyc <= '0'; exr.wb_stb <= '1'; else exr <= w; -- TODO: move wroteback_q into EXU regs wroteback_q <= wroteback; if exr.break='1' then report "BREAK" severity failure; end if; -- Some sanity checks, to be caught in simulation if prefr.valid='1' then if prefr.tosSource=Tos_Source_Idim0 and prefr.idim='1' then report "Invalid IDIM flag 0" severity error; end if; if prefr.tosSource=Tos_Source_IdimN and prefr.idim='0' then report "Invalid IDIM flag 1" severity error; end if; end if; end if; end if; end process; single_step <= dbg_in.step; dbg_out.valid <= '1' when prefr.valid='1' else '0'; -- Let pipeline finish dbg_out.ready <= '1' when exr.state=state_execute and decode_load_sp='0' and decode_jump='0' and decr.state = State_Inject --and jump_q='0' else '0'; end behave;
-- ZPU -- -- Copyright 2004-2008 oharboe - Øyvind Harboe - [email protected] -- Copyright 2010-2012 Alvaro Lopes - [email protected] -- -- The FreeBSD license -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions -- are met: -- -- 1. Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer. -- 2. Redistributions in binary form must reproduce the above -- copyright notice, this list of conditions and the following -- disclaimer in the documentation and/or other materials -- provided with the distribution. -- -- THIS SOFTWARE IS PROVIDED BY THE ZPU PROJECT ``AS IS'' AND ANY -- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -- ZPU PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- The views and conclusions contained in the software and documentation -- are those of the authors and should not be interpreted as representing -- official policies, either expressed or implied, of the ZPU Project. library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.numeric_std.all; library board; use board.zpu_config.all; use board.zpupkg.all; use board.wishbonepkg.all; --library UNISIM; --use UNISIM.vcomponents.all; entity zpu_core_extreme is port ( wb_clk_i: in std_logic; wb_rst_i: in std_logic; -- Master wishbone interface wb_ack_i: in std_logic; wb_dat_i: in std_logic_vector(wordSize-1 downto 0); wb_dat_o: out std_logic_vector(wordSize-1 downto 0); wb_adr_o: out std_logic_vector(maxAddrBitIncIO downto 0); wb_cyc_o: out std_logic; wb_stb_o: out std_logic; wb_we_o: out std_logic; wb_inta_i: in std_logic; poppc_inst: out std_logic; break: out std_logic; -- STACK stack_a_read: in std_logic_vector(wordSize-1 downto 0); stack_b_read: in std_logic_vector(wordSize-1 downto 0); stack_a_write: out std_logic_vector(wordSize-1 downto 0); stack_b_write: out std_logic_vector(wordSize-1 downto 0); stack_a_writeenable: out std_logic; stack_a_enable: out std_logic; stack_b_writeenable: out std_logic; stack_b_enable: out std_logic; stack_a_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_b_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_clk: out std_logic; -- ROM wb interface rom_wb_ack_i: in std_logic; rom_wb_dat_i: in std_logic_vector(wordSize-1 downto 0); rom_wb_adr_o: out std_logic_vector(maxAddrBit downto 0); rom_wb_cyc_o: out std_logic; rom_wb_stb_o: out std_logic; rom_wb_cti_o: out std_logic_vector(2 downto 0); rom_wb_stall_i: in std_logic; -- Debug interface dbg_out: out zpu_dbg_out_type; dbg_in: in zpu_dbg_in_type ); end zpu_core_extreme; architecture behave of zpu_core_extreme is component lshifter is port ( clk: in std_logic; rst: in std_logic; enable: in std_logic; done: out std_logic; inputA: in std_logic_vector(31 downto 0); inputB: in std_logic_vector(31 downto 0); output: out std_logic_vector(63 downto 0); multorshift: in std_logic ); end component; signal lshifter_enable: std_logic; signal lshifter_done: std_logic; signal lshifter_input: std_logic_vector(31 downto 0); signal lshifter_amount: std_logic_vector(31 downto 0); signal lshifter_output: std_logic_vector(63 downto 0); signal lshifter_multorshift: std_logic; signal begin_inst: std_logic; signal trace_opcode: std_logic_vector(7 downto 0); signal trace_pc: std_logic_vector(maxAddrBitIncIO downto 0); signal trace_sp: std_logic_vector(maxAddrBitIncIO downto minAddrBit); signal trace_topOfStack: std_logic_vector(wordSize-1 downto 0); signal trace_topOfStackB: std_logic_vector(wordSize-1 downto 0); -- state machine. type State_Type is ( State_Execute, State_Store, State_StoreB, State_StoreB2, State_Load, State_LoadMemory, State_LoadStack, State_Loadb, State_Resync1, State_Resync2, State_LoadSP, State_WaitSPB, State_ResyncFromStoreStack, State_Neqbranch, State_Ashiftleft, State_Mult, State_MultF16 ); type DecodedOpcodeType is ( Decoded_Nop, Decoded_Idle, Decoded_Im0, Decoded_ImN, Decoded_LoadSP, Decoded_Dup, Decoded_DupStackB, Decoded_StoreSP, Decoded_Pop, Decoded_PopDown, Decoded_AddSP, Decoded_AddStackB, Decoded_Shift, Decoded_Emulate, Decoded_Break, Decoded_PushSP, Decoded_PopPC, Decoded_Add, Decoded_Or, Decoded_And, Decoded_Load, Decoded_Not, Decoded_Flip, Decoded_Store, Decoded_PopSP, Decoded_Interrupt, Decoded_Neqbranch, Decoded_Eq, Decoded_Storeb, Decoded_Storeh, Decoded_Ulessthan, Decoded_Lessthan, Decoded_Ashiftleft, Decoded_Ashiftright, Decoded_Loadb, Decoded_Call, Decoded_Mult, Decoded_MultF16 ); constant spMaxBit: integer := 10; constant minimal_implementation: boolean := false; subtype index is integer range 0 to 3; signal tOpcode_sel : index; function pc_to_cpuword(pc: unsigned) return unsigned is variable r: unsigned(wordSize-1 downto 0); begin r := (others => DontCareValue); r(maxAddrBit downto 0) := pc; return r; end pc_to_cpuword; function pc_to_memaddr(pc: unsigned) return unsigned is variable r: unsigned(maxAddrBit downto 0); begin r := (others => '0'); r(maxAddrBit downto minAddrBit) := pc(maxAddrBit downto minAddrBit); return r; end pc_to_memaddr; -- Prefetch stage registers type stackChangeType is ( Stack_Same, Stack_Push, Stack_Pop, Stack_DualPop ); type tosSourceType is ( Tos_Source_PC, Tos_Source_FetchPC, Tos_Source_Idim0, Tos_Source_IdimN, Tos_Source_StackB, Tos_Source_SP, Tos_Source_Add, Tos_Source_And, Tos_Source_Or, Tos_Source_Eq, Tos_Source_Not, Tos_Source_Flip, Tos_Source_LoadSP, Tos_Source_AddSP, Tos_Source_AddStackB, Tos_Source_Shift, Tos_Source_Ulessthan, Tos_Source_Lessthan, Tos_Source_None ); type decoderstate_type is ( State_Run, State_Jump, State_Inject, State_InjectJump ); type decoderegs_type is record valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opWillFreeze: std_logic; -- '1' if we know in advance this opcode will freeze pipeline opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); pcint: unsigned(maxAddrBit downto 0); idim: std_logic; im: std_logic; stackOperation: stackChangeType; spOffset: unsigned(4 downto 0); im_emu: std_logic; --emumode: std_logic; break: std_logic; state: decoderstate_type; end record; type prefetchregs_type is record sp: unsigned(spMaxBit downto 2); spnext: unsigned(spMaxBit downto 2); valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); idim: std_logic; break: std_logic; load: std_logic; opWillFreeze: std_logic; recompute_sp: std_logic; end record; type exuregs_type is record idim: std_logic; break: std_logic; inInterrupt:std_logic; tos: unsigned(wordSize-1 downto 0); tos_save: unsigned(wordSize-1 downto 0); nos_save: unsigned(wordSize-1 downto 0); state: State_Type; -- Wishbone control signals (registered) wb_cyc: std_logic; wb_stb: std_logic; wb_we: std_logic; end record; -- Registers for each stage signal exr: exuregs_type; signal prefr: prefetchregs_type; signal decr: decoderegs_type; signal pcnext: unsigned(maxAddrBit downto 0); -- Helper only. TODO: move into variable signal sp_load: unsigned(spMaxBit downto 2); -- SP value to load, coming from EXU into PFU signal decode_load_sp: std_logic; -- Load SP signal from EXU to PFU signal exu_busy: std_logic; -- EXU busy ( stalls PFU ) signal pfu_busy: std_logic; -- PFU busy ( stalls DFU ) signal decode_jump: std_logic; -- Jump signal from EXU to DFU signal jump_address: unsigned(maxAddrBit downto 0); -- Jump address from EXU to DFU signal do_interrupt: std_logic; -- Helper. -- Sampled signals from the opcode. Left as signals -- in order to simulate design. signal sampledOpcode: std_logic_vector(OpCode_Size-1 downto 0); signal sampledDecodedOpcode: DecodedOpcodeType; signal sampledOpWillFreeze: std_logic; signal sampledStackOperation: stackChangeType; signal sampledspOffset: unsigned(4 downto 0); signal sampledTosSource: tosSourceType; signal nos: unsigned(wordSize-1 downto 0); -- This is only a helper signal wroteback_q: std_logic; -- TODO: get rid of this here, move to EXU regs -- Test debug signals signal freeze_all: std_logic := '0'; signal single_step: std_logic := '0'; begin -- Debug interface dbg_out.pc <= std_logic_vector(prefr.pc); dbg_out.opcode <= prefr.opcode; dbg_out.sp <= std_logic_vector(prefr.sp); dbg_out.brk <= exr.break; dbg_out.stacka <= std_logic_vector(exr.tos); dbg_out.stackb <= std_logic_vector(nos); dbg_out.idim <= prefr.idim; shl: lshifter port map ( clk => wb_clk_i, rst => wb_rst_i, enable => lshifter_enable, done => lshifter_done, inputA => lshifter_input, inputB => lshifter_amount, output => lshifter_output, multorshift => lshifter_multorshift ); stack_clk <= wb_clk_i; traceFileGenerate: if Generate_Trace generate trace_file: trace port map ( clk => wb_clk_i, begin_inst => begin_inst, pc => trace_pc, opcode => trace_opcode, sp => trace_sp, memA => trace_topOfStack, memB => trace_topOfStackB, busy => '0',--busy, intsp => (others => 'U') ); end generate; tOpcode_sel <= to_integer(decr.pcint(minAddrBit-1 downto 0)); do_interrupt <= '1' when wb_inta_i='1' and exr.inInterrupt='0' else '0'; decodeControl: process(rom_wb_dat_i, tOpcode_sel, sp_load, decr, do_interrupt, dbg_in.inject, dbg_in.opcode) variable tOpcode : std_logic_vector(OpCode_Size-1 downto 0); variable localspOffset: unsigned(4 downto 0); begin if dbg_in.inject='1' then tOpcode := dbg_in.opcode; else case (tOpcode_sel) is when 0 => tOpcode := std_logic_vector(rom_wb_dat_i(31 downto 24)); when 1 => tOpcode := std_logic_vector(rom_wb_dat_i(23 downto 16)); when 2 => tOpcode := std_logic_vector(rom_wb_dat_i(15 downto 8)); when 3 => tOpcode := std_logic_vector(rom_wb_dat_i(7 downto 0)); when others => null; end case; end if; sampledOpcode <= tOpcode; sampledStackOperation <= Stack_Same; sampledTosSource <= Tos_Source_None; sampledOpWillFreeze <= '0'; localspOffset(4):=not tOpcode(4); localspOffset(3 downto 0) := unsigned(tOpcode(3 downto 0)); if do_interrupt='1' and decr.im='0' then sampledDecodedOpcode <= Decoded_Interrupt; sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_PC; else if (tOpcode(7 downto 7)=OpCode_Im) then if decr.im='0' then sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_Idim0; sampledDecodedOpcode<=Decoded_Im0; else sampledTosSource <= Tos_Source_IdimN; sampledDecodedOpcode<=Decoded_ImN; end if; elsif (tOpcode(7 downto 5)=OpCode_StoreSP) then sampledStackOperation <= Stack_Pop; sampledTosSource <= Tos_Source_StackB; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Pop; sampledTosSource <= Tos_Source_StackB; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_PopDown; sampledTosSource <= Tos_Source_None; else sampledDecodedOpcode<=Decoded_StoreSP; sampledOpWillFreeze<='1'; sampledTosSource <= Tos_Source_StackB; end if; elsif (tOpcode(7 downto 5)=OpCode_LoadSP) then sampledStackOperation <= Stack_Push; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Dup; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_DupStackB; sampledTosSource <= Tos_Source_StackB; else sampledDecodedOpcode<=Decoded_LoadSP; sampledTosSource <= Tos_Source_LoadSP; end if; elsif (tOpcode(7 downto 5)=OpCode_Emulate) then -- Emulated instructions implemented in hardware if minimal_implementation then sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; else if (tOpcode(5 downto 0)=OpCode_Loadb) then sampledStackOperation<=Stack_Same; sampledDecodedOpcode<=Decoded_Loadb; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Neqbranch) then sampledStackOperation<=Stack_DualPop; sampledDecodedOpcode<=Decoded_Neqbranch; sampledOpWillFreeze <= '1'; elsif (tOpcode(5 downto 0)=OpCode_Call) then sampledDecodedOpcode<=Decoded_Call; sampledStackOperation<=Stack_Same; sampledTosSource<=Tos_Source_FetchPC; elsif (tOpcode(5 downto 0)=OpCode_Eq) then sampledDecodedOpcode<=Decoded_Eq; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Eq; elsif (tOpcode(5 downto 0)=OpCode_Ulessthan) then sampledDecodedOpcode<=Decoded_Ulessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Ulessthan; elsif (tOpcode(5 downto 0)=OpCode_Lessthan) then sampledDecodedOpcode<=Decoded_Lessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Lessthan; elsif (tOpcode(5 downto 0)=OpCode_StoreB) then sampledDecodedOpcode<=Decoded_StoreB; sampledStackOperation<=Stack_DualPop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Mult) then sampledDecodedOpcode<=Decoded_Mult; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Ashiftleft) then sampledDecodedOpcode<=Decoded_Ashiftleft; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; end if; end if; elsif (tOpcode(7 downto 4)=OpCode_AddSP) then if localspOffset=0 then sampledDecodedOpcode<=Decoded_Shift; sampledTosSource <= Tos_Source_Shift; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_AddStackB; sampledTosSource <= Tos_Source_AddStackB; else sampledDecodedOpcode<=Decoded_AddSP; sampledTosSource <= Tos_Source_AddSP; end if; else case tOpcode(3 downto 0) is when OpCode_Break => sampledDecodedOpcode<=Decoded_Break; sampledOpWillFreeze <= '1'; when OpCode_PushSP => sampledStackOperation <= Stack_Push; sampledDecodedOpcode<=Decoded_PushSP; sampledTosSource <= Tos_Source_SP; when OpCode_PopPC => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_PopPC; sampledTosSource <= Tos_Source_StackB; when OpCode_Add => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Add; sampledTosSource <= Tos_Source_Add; when OpCode_Or => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Or; sampledTosSource <= Tos_Source_Or; when OpCode_And => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_And; sampledTosSource <= Tos_Source_And; when OpCode_Load => sampledDecodedOpcode<=Decoded_Load; sampledOpWillFreeze<='1'; when OpCode_Not => sampledDecodedOpcode<=Decoded_Not; sampledTosSource <= Tos_Source_Not; when OpCode_Flip => sampledDecodedOpcode<=Decoded_Flip; sampledTosSource <= Tos_Source_Flip; when OpCode_Store => sampledStackOperation <= Stack_DualPop; sampledDecodedOpcode<=Decoded_Store; sampledOpWillFreeze<='1'; when OpCode_PopSP => sampledDecodedOpcode<=Decoded_PopSP; sampledOpWillFreeze<='1'; when OpCode_NA4 => if enable_fmul16 then sampledDecodedOpcode<=Decoded_MultF16; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Nop; end if; when others => sampledDecodedOpcode<=Decoded_Nop; end case; end if; end if; sampledspOffset <= localspOffset; end process; -- Decode/Fetch unit rom_wb_stb_o <= not exu_busy; process(decr, jump_address, decode_jump, wb_clk_i, sp_load, sampledDecodedOpcode,sampledOpcode,decode_load_sp, exu_busy, pfu_busy, pcnext, rom_wb_ack_i, wb_rst_i, sampledStackOperation, sampledspOffset, sampledTosSource, prefr.recompute_sp, sampledOpWillFreeze, dbg_in.flush, dbg_in.inject,dbg_in.injectmode, prefr.valid, prefr.break, rom_wb_stall_i ) variable w: decoderegs_type; begin w := decr; pcnext <= decr.fetchpc + 1; rom_wb_adr_o <= std_logic_vector(pc_to_memaddr(decr.fetchpc)); rom_wb_cti_o <= CTI_CYCLE_INCRADDR; if wb_rst_i='1' then w.pc := (others => '0'); w.pcint := (others => '0'); w.valid := '0'; w.fetchpc := (others => '0'); w.im:='0'; w.im_emu:='0'; w.state := State_Run; w.break := '0'; rom_wb_cyc_o <= '0'; else rom_wb_cyc_o <= '1'; case decr.state is when State_Run => if pfu_busy='0' then if dbg_in.injectmode='0' and decr.break='0' and rom_wb_stall_i='0' then w.fetchpc := pcnext; end if; -- Jump request if decode_jump='1' then w.valid := '0'; w.im := '0'; w.break := '0'; -- Invalidate eventual break after branch instruction --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o<='0'; --if rom_wb_stall_i='0' then w.fetchpc := jump_address; --else w.state := State_Jump; --end if; else if dbg_in.injectmode='1' then --or decr.break='1' then -- At this point we ought to push a new op into the pipeline. -- Since we're entering inject mode, invalidate next operation, -- but save the current IM flag. w.im_emu := decr.im; w.valid := '0'; --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o <='0'; -- Wait until no work is to be done if prefr.valid='0' and decr.valid='0' and exu_busy='0' then w.state := State_Inject; w.im:='0'; end if; if decr.break='0' then w.pc := decr.pcint; end if; else if decr.break='1' then w.valid := '0'; else w.valid := rom_wb_ack_i; end if; if rom_wb_ack_i='1' then w.im := sampledOpcode(7); if sampledDecodedOpcode=Decoded_Break then w.break:='1'; end if; end if; if prefr.break='0' and rom_wb_stall_i='0' then w.pcint := decr.fetchpc; w.pc := decr.pcint; end if; if rom_wb_stall_i='0' then w.opcode := sampledOpcode; end if; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; when State_Jump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Run; when State_InjectJump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Inject; when State_Inject => -- NOTE: disable ROM rom_wb_cyc_o <= '0'; if dbg_in.injectmode='0' then w.im := decr.im_emu; w.fetchpc := decr.pcint; w.state := State_Run; w.break := '0'; else -- Handle opcode injection -- TODO: merge this with main decode. -- NOTE: we don't check busy here, it's up to debug unit to do it --if pfu_busy='0' then --w.fetchpc := pcnext; -- Jump request if decode_jump='1' then w.fetchpc := jump_address; w.valid := '0'; w.im := '0'; w.state := State_InjectJump; else w.valid := dbg_in.inject; if dbg_in.inject='1' then w.im := sampledOpcode(7); --w.break := '0'; --w.pcint := decr.fetchpc; w.opcode := sampledOpcode; --w.pc := decr.pcint; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; --end if; end case; end if; -- rst if rising_edge(wb_clk_i) then decr <= w; end if; end process; -- Prefetch/Load unit. sp_load <= exr.tos(spMaxBit downto 2); -- Will be delayed one clock cycle process(wb_clk_i, wb_rst_i, decr, prefr, exu_busy, decode_jump, sp_load, decode_load_sp, dbg_in.flush) variable w: prefetchregs_type; variable i_op_freeze: std_logic; begin w := prefr; pfu_busy<='0'; stack_b_addr <= std_logic_vector(prefr.spnext + 1); w.recompute_sp:='0'; -- Stack w.load := decode_load_sp; if decode_load_sp='1' then pfu_busy <= '1'; w.spnext := sp_load; w.recompute_sp := '1'; else pfu_busy <= exu_busy; if decr.valid='1' then if (exu_busy='0' and decode_jump='0') or prefr.recompute_sp='1' then case decr.stackOperation is when Stack_Push => w.spnext := prefr.spnext - 1; when Stack_Pop => w.spnext := prefr.spnext + 1; when Stack_DualPop => w.spnext := prefr.spnext + 2; when others => end case; w.sp := prefr.spnext; end if; end if; end if; case decr.decodedOpcode is when Decoded_LoadSP | decoded_AddSP => stack_b_addr <= std_logic_vector(prefr.spnext + decr.spOffset); when others => end case; if decode_jump='1' then -- this is a pipeline "invalidate" flag. w.valid := '0'; else if dbg_in.flush='1' then w.valid := '0'; else w.valid := decr.valid; end if; end if; -- Moved op_will_freeze from decoder to here case decr.decodedOpcode is when Decoded_StoreSP | Decoded_LoadB | Decoded_Neqbranch | Decoded_StoreB | Decoded_Mult | Decoded_Ashiftleft | Decoded_Break | Decoded_Load | Decoded_Store | Decoded_PopSP | Decoded_MultF16 => i_op_freeze := '1'; when others => i_op_freeze := '0'; end case; if exu_busy='0' then w.decodedOpcode := decr.decodedOpcode; w.tosSource := decr.tosSource; w.opcode := decr.opcode; w.opWillFreeze := i_op_freeze; w.pc := decr.pc; w.fetchpc := decr.pcint; w.idim := decr.idim; w.break := decr.break; end if; if wb_rst_i='1' then w.spnext := unsigned(spStart(10 downto 2)); --w.sp := unsigned(spStart(10 downto 2)); w.valid := '0'; w.idim := '0'; w.recompute_sp:='0'; end if; if rising_edge(wb_clk_i) then prefr <= w; end if; end process; process(prefr,exr,nos) begin trace_pc <= (others => '0'); trace_pc(maxAddrBit downto 0) <= std_logic_vector(prefr.pc); trace_opcode <= prefr.opcode; trace_sp <= (others => '0'); trace_sp(10 downto 2) <= std_logic_vector(prefr.sp); trace_topOfStack <= std_logic_vector( exr.tos ); trace_topOfStackB <= std_logic_vector( nos ); end process; -- IO/Memory Accesses wb_adr_o(maxAddrBitIncIO downto 0) <= std_logic_vector(exr.tos_save(maxAddrBitIncIO downto 0)); wb_cyc_o <= exr.wb_cyc; wb_stb_o <= exr.wb_stb; wb_we_o <= exr.wb_we; wb_dat_o <= std_logic_vector( exr.nos_save ); freeze_all <= dbg_in.freeze; process(exr, wb_inta_i, wb_clk_i, wb_rst_i, pcnext, stack_a_read,stack_b_read, wb_ack_i, wb_dat_i, do_interrupt,exr, prefr, nos, single_step, freeze_all, dbg_in.step, wroteback_q,lshifter_done,lshifter_output ) variable spOffset: unsigned(4 downto 0); variable w: exuregs_type; variable instruction_executed: std_logic; variable wroteback: std_logic; begin w := exr; instruction_executed := '0'; -- used for single stepping stack_b_writeenable <= '0'; stack_a_enable <= '1'; stack_b_enable <= '1'; exu_busy <= '0'; decode_jump <= '0'; jump_address <= (others => DontCareValue); lshifter_enable <= '0'; lshifter_amount <= std_logic_vector(exr.tos_save); lshifter_input <= std_logic_vector(exr.nos_save); lshifter_multorshift <= '0'; poppc_inst <= '0'; begin_inst<='0'; stack_a_addr <= std_logic_vector( prefr.sp ); stack_a_writeenable <= '0'; wroteback := wroteback_q; stack_b_writeenable <= '0'; stack_a_write <= std_logic_vector(exr.tos); spOffset(4):=not prefr.opcode(4); spOffset(3 downto 0) := unsigned(prefr.opcode(3 downto 0)); if wb_inta_i='0' then w.inInterrupt := '0'; end if; stack_b_write<=(others => DontCareValue); if wroteback_q='1' then nos <= unsigned(stack_a_read); else nos <= unsigned(stack_b_read); end if; decode_load_sp <= '0'; case exr.state is when State_Resync1 => exu_busy <= '1'; stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_ResyncFromStoreStack => exu_busy <= '1'; stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_Resync2 => w.tos := unsigned(stack_a_read); instruction_executed := '1'; exu_busy <= '0'; wroteback := '0'; stack_b_enable <= '1'; w.state := State_Execute; when State_Execute => instruction_executed:='0'; if prefr.valid='1' then exu_busy <= prefr.opWillFreeze; if freeze_all='0' or single_step='1' then wroteback := '0'; w.nos_save := nos; w.tos_save := exr.tos; w.idim := prefr.idim; w.break:= prefr.break; begin_inst<='1'; instruction_executed := '1'; -- TOS big muxer case prefr.tosSource is when Tos_Source_PC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.pc; when Tos_Source_FetchPC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.fetchpc; when Tos_Source_Idim0 => for i in wordSize-1 downto 7 loop w.tos(i) := prefr.opcode(6); end loop; w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_IdimN => w.tos(wordSize-1 downto 7) := exr.tos(wordSize-8 downto 0); w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_StackB => w.tos := nos; when Tos_Source_SP => w.tos := (others => '0'); w.tos(31) := '1'; -- Stack address w.tos(10 downto 2) := prefr.sp; when Tos_Source_Add => w.tos := exr.tos + nos; when Tos_Source_And => w.tos := exr.tos and nos; when Tos_Source_Or => w.tos := exr.tos or nos; when Tos_Source_Eq => w.tos := (others => '0'); if nos = exr.tos then w.tos(0) := '1'; end if; when Tos_Source_Ulessthan => w.tos := (others => '0'); if exr.tos < nos then w.tos(0) := '1'; end if; when Tos_Source_Lessthan => w.tos := (others => '0'); if signed(exr.tos) < signed(nos) then w.tos(0) := '1'; end if; when Tos_Source_Not => w.tos := not exr.tos; when Tos_Source_Flip => for i in 0 to wordSize-1 loop w.tos(i) := exr.tos(wordSize-1-i); end loop; when Tos_Source_LoadSP => w.tos := unsigned(stack_b_read); when Tos_Source_AddSP => w.tos := w.tos + unsigned(stack_b_read); when Tos_Source_AddStackB => w.tos := w.tos + nos; when Tos_Source_Shift => w.tos := exr.tos + exr.tos; when others => end case; case prefr.decodedOpcode is when Decoded_Interrupt => w.inInterrupt := '1'; jump_address <= to_unsigned(32, maxAddrBit+1); decode_jump <= '1'; stack_a_writeenable<='1'; wroteback:='1'; stack_b_enable<='0'; instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Im0 => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_ImN => when Decoded_Nop => when Decoded_PopPC | Decoded_Call => decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0); poppc_inst <= '1'; stack_b_enable<='0'; -- Delay instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Emulate => decode_jump <= '1'; jump_address <= (others => '0'); jump_address(9 downto 5) <= unsigned(prefr.opcode(4 downto 0)); stack_a_writeenable<='1'; wroteback:='1'; when Decoded_PushSP => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_LoadSP => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_DupStackB => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_Dup => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_AddSP => stack_a_writeenable <= '1'; when Decoded_StoreSP => stack_a_writeenable <= '1'; wroteback:='1'; stack_a_addr <= std_logic_vector(prefr.sp + spOffset); instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_PopDown => stack_a_writeenable<='1'; when Decoded_Pop => when Decoded_Ashiftleft => w.state := State_Ashiftleft; when Decoded_Mult => w.state := State_Mult; when Decoded_MultF16 => w.state := State_MultF16; when Decoded_Store => if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(nos); stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when Decoded_Load | Decoded_Loadb | Decoded_StoreB => --w.tos_save := exr.tos; -- Byte select instruction_executed := '0'; wroteback := wroteback_q; -- Keep WB if exr.tos(wordSize-1)='1' then stack_a_addr<=std_logic_vector(exr.tos(10 downto 2)); stack_a_enable<='1'; w.state := State_LoadStack; else stack_a_enable <= '0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); w.wb_we :='0'; w.wb_cyc :='1'; w.wb_stb :='1'; w.state := State_Load; end if; when Decoded_PopSP => decode_load_sp <= '1'; instruction_executed := '0'; stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); w.state := State_Resync2; --when Decoded_Break => -- w.break := '1'; when Decoded_Neqbranch => instruction_executed := '0'; w.state := State_NeqBranch; when others => end case; else -- freeze_all -- -- Freeze the entire pipeline. -- exu_busy<='1'; stack_a_enable<='0'; stack_b_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); end if; end if; -- valid when State_Ashiftleft => exu_busy <= '1'; lshifter_enable <= '1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_Mult => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_MultF16 => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(47 downto 16)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_WaitSPB => instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Store => exu_busy <= '1'; -- Keep writeback flag wroteback := wroteback_q; if wb_ack_i='1' then stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; stack_b_enable<='1'; wroteback := '0'; --exu_busy <= '1'; w.wb_cyc := '0'; w.state := State_Resync2; else stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_a_enable<='0'; stack_b_enable<='0'; end if; when State_Loadb => w.tos(wordSize-1 downto 8) := (others => '0'); case exr.tos_save(1 downto 0) is when "11" => w.tos(7 downto 0) := unsigned(exr.tos(7 downto 0)); when "10" => w.tos(7 downto 0) := unsigned(exr.tos(15 downto 8)); when "01" => w.tos(7 downto 0) := unsigned(exr.tos(23 downto 16)); when "00" => w.tos(7 downto 0) := unsigned(exr.tos(31 downto 24)); when others => null; end case; instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Load => if wb_ack_i='0' then exu_busy<='1'; else w.tos := unsigned(wb_dat_i); w.wb_cyc := '0'; if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state := State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state := State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; end if; when State_LoadStack => w.tos := unsigned(stack_a_read); if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state:=State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state:=State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; when State_NeqBranch => if exr.nos_save/=0 then decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0) + prefr.pc; poppc_inst <= '1'; exu_busy <= '0'; else exu_busy <='1'; end if; instruction_executed := '0'; stack_a_addr <= std_logic_vector(prefr.spnext); wroteback:='0'; w.state := State_Resync2; when State_StoreB => exu_busy <= '1'; -- -- At this point, we have loaded the 32-bit, and it's in TOS -- The IO address is still saved in save_TOS. -- The original write value is still at save_NOS -- -- So we mangle the write value, and update save_NOS, and restore -- the IO address to TOS -- -- This is still buggy - don't use. Problems arise when writing to stack. -- w.nos_save := exr.tos; case exr.tos_save(1 downto 0) is when "00" => w.nos_save(31 downto 24) := exr.nos_save(7 downto 0); when "01" => w.nos_save(23 downto 16) := exr.nos_save(7 downto 0); when "10" => w.nos_save(15 downto 8) := exr.nos_save(7 downto 0); when "11" => w.nos_save(7 downto 0) := exr.nos_save(7 downto 0); when others => null; end case; w.tos := exr.tos_save; w.state := State_StoreB2; when State_StoreB2 => exu_busy <= '1'; if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(exr.nos_save); -- hmm I don't like this stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when others => null; end case; if rising_edge(wb_clk_i) then if wb_rst_i='1' then exr.state <= State_Execute; exr.idim <= DontCareValue; exr.inInterrupt <= '0'; exr.break <= '0'; exr.wb_cyc <= '0'; exr.wb_stb <= '1'; else exr <= w; -- TODO: move wroteback_q into EXU regs wroteback_q <= wroteback; if exr.break='1' then report "BREAK" severity failure; end if; -- Some sanity checks, to be caught in simulation if prefr.valid='1' then if prefr.tosSource=Tos_Source_Idim0 and prefr.idim='1' then report "Invalid IDIM flag 0" severity error; end if; if prefr.tosSource=Tos_Source_IdimN and prefr.idim='0' then report "Invalid IDIM flag 1" severity error; end if; end if; end if; end if; end process; single_step <= dbg_in.step; dbg_out.valid <= '1' when prefr.valid='1' else '0'; -- Let pipeline finish dbg_out.ready <= '1' when exr.state=state_execute and decode_load_sp='0' and decode_jump='0' and decr.state = State_Inject --and jump_q='0' else '0'; end behave;
-- ZPU -- -- Copyright 2004-2008 oharboe - Øyvind Harboe - [email protected] -- Copyright 2010-2012 Alvaro Lopes - [email protected] -- -- The FreeBSD license -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions -- are met: -- -- 1. Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer. -- 2. Redistributions in binary form must reproduce the above -- copyright notice, this list of conditions and the following -- disclaimer in the documentation and/or other materials -- provided with the distribution. -- -- THIS SOFTWARE IS PROVIDED BY THE ZPU PROJECT ``AS IS'' AND ANY -- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -- ZPU PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- The views and conclusions contained in the software and documentation -- are those of the authors and should not be interpreted as representing -- official policies, either expressed or implied, of the ZPU Project. library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.numeric_std.all; library board; use board.zpu_config.all; use board.zpupkg.all; use board.wishbonepkg.all; --library UNISIM; --use UNISIM.vcomponents.all; entity zpu_core_extreme is port ( wb_clk_i: in std_logic; wb_rst_i: in std_logic; -- Master wishbone interface wb_ack_i: in std_logic; wb_dat_i: in std_logic_vector(wordSize-1 downto 0); wb_dat_o: out std_logic_vector(wordSize-1 downto 0); wb_adr_o: out std_logic_vector(maxAddrBitIncIO downto 0); wb_cyc_o: out std_logic; wb_stb_o: out std_logic; wb_we_o: out std_logic; wb_inta_i: in std_logic; poppc_inst: out std_logic; break: out std_logic; -- STACK stack_a_read: in std_logic_vector(wordSize-1 downto 0); stack_b_read: in std_logic_vector(wordSize-1 downto 0); stack_a_write: out std_logic_vector(wordSize-1 downto 0); stack_b_write: out std_logic_vector(wordSize-1 downto 0); stack_a_writeenable: out std_logic; stack_a_enable: out std_logic; stack_b_writeenable: out std_logic; stack_b_enable: out std_logic; stack_a_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_b_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_clk: out std_logic; -- ROM wb interface rom_wb_ack_i: in std_logic; rom_wb_dat_i: in std_logic_vector(wordSize-1 downto 0); rom_wb_adr_o: out std_logic_vector(maxAddrBit downto 0); rom_wb_cyc_o: out std_logic; rom_wb_stb_o: out std_logic; rom_wb_cti_o: out std_logic_vector(2 downto 0); rom_wb_stall_i: in std_logic; -- Debug interface dbg_out: out zpu_dbg_out_type; dbg_in: in zpu_dbg_in_type ); end zpu_core_extreme; architecture behave of zpu_core_extreme is component lshifter is port ( clk: in std_logic; rst: in std_logic; enable: in std_logic; done: out std_logic; inputA: in std_logic_vector(31 downto 0); inputB: in std_logic_vector(31 downto 0); output: out std_logic_vector(63 downto 0); multorshift: in std_logic ); end component; signal lshifter_enable: std_logic; signal lshifter_done: std_logic; signal lshifter_input: std_logic_vector(31 downto 0); signal lshifter_amount: std_logic_vector(31 downto 0); signal lshifter_output: std_logic_vector(63 downto 0); signal lshifter_multorshift: std_logic; signal begin_inst: std_logic; signal trace_opcode: std_logic_vector(7 downto 0); signal trace_pc: std_logic_vector(maxAddrBitIncIO downto 0); signal trace_sp: std_logic_vector(maxAddrBitIncIO downto minAddrBit); signal trace_topOfStack: std_logic_vector(wordSize-1 downto 0); signal trace_topOfStackB: std_logic_vector(wordSize-1 downto 0); -- state machine. type State_Type is ( State_Execute, State_Store, State_StoreB, State_StoreB2, State_Load, State_LoadMemory, State_LoadStack, State_Loadb, State_Resync1, State_Resync2, State_LoadSP, State_WaitSPB, State_ResyncFromStoreStack, State_Neqbranch, State_Ashiftleft, State_Mult, State_MultF16 ); type DecodedOpcodeType is ( Decoded_Nop, Decoded_Idle, Decoded_Im0, Decoded_ImN, Decoded_LoadSP, Decoded_Dup, Decoded_DupStackB, Decoded_StoreSP, Decoded_Pop, Decoded_PopDown, Decoded_AddSP, Decoded_AddStackB, Decoded_Shift, Decoded_Emulate, Decoded_Break, Decoded_PushSP, Decoded_PopPC, Decoded_Add, Decoded_Or, Decoded_And, Decoded_Load, Decoded_Not, Decoded_Flip, Decoded_Store, Decoded_PopSP, Decoded_Interrupt, Decoded_Neqbranch, Decoded_Eq, Decoded_Storeb, Decoded_Storeh, Decoded_Ulessthan, Decoded_Lessthan, Decoded_Ashiftleft, Decoded_Ashiftright, Decoded_Loadb, Decoded_Call, Decoded_Mult, Decoded_MultF16 ); constant spMaxBit: integer := 10; constant minimal_implementation: boolean := false; subtype index is integer range 0 to 3; signal tOpcode_sel : index; function pc_to_cpuword(pc: unsigned) return unsigned is variable r: unsigned(wordSize-1 downto 0); begin r := (others => DontCareValue); r(maxAddrBit downto 0) := pc; return r; end pc_to_cpuword; function pc_to_memaddr(pc: unsigned) return unsigned is variable r: unsigned(maxAddrBit downto 0); begin r := (others => '0'); r(maxAddrBit downto minAddrBit) := pc(maxAddrBit downto minAddrBit); return r; end pc_to_memaddr; -- Prefetch stage registers type stackChangeType is ( Stack_Same, Stack_Push, Stack_Pop, Stack_DualPop ); type tosSourceType is ( Tos_Source_PC, Tos_Source_FetchPC, Tos_Source_Idim0, Tos_Source_IdimN, Tos_Source_StackB, Tos_Source_SP, Tos_Source_Add, Tos_Source_And, Tos_Source_Or, Tos_Source_Eq, Tos_Source_Not, Tos_Source_Flip, Tos_Source_LoadSP, Tos_Source_AddSP, Tos_Source_AddStackB, Tos_Source_Shift, Tos_Source_Ulessthan, Tos_Source_Lessthan, Tos_Source_None ); type decoderstate_type is ( State_Run, State_Jump, State_Inject, State_InjectJump ); type decoderegs_type is record valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opWillFreeze: std_logic; -- '1' if we know in advance this opcode will freeze pipeline opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); pcint: unsigned(maxAddrBit downto 0); idim: std_logic; im: std_logic; stackOperation: stackChangeType; spOffset: unsigned(4 downto 0); im_emu: std_logic; --emumode: std_logic; break: std_logic; state: decoderstate_type; end record; type prefetchregs_type is record sp: unsigned(spMaxBit downto 2); spnext: unsigned(spMaxBit downto 2); valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); idim: std_logic; break: std_logic; load: std_logic; opWillFreeze: std_logic; recompute_sp: std_logic; end record; type exuregs_type is record idim: std_logic; break: std_logic; inInterrupt:std_logic; tos: unsigned(wordSize-1 downto 0); tos_save: unsigned(wordSize-1 downto 0); nos_save: unsigned(wordSize-1 downto 0); state: State_Type; -- Wishbone control signals (registered) wb_cyc: std_logic; wb_stb: std_logic; wb_we: std_logic; end record; -- Registers for each stage signal exr: exuregs_type; signal prefr: prefetchregs_type; signal decr: decoderegs_type; signal pcnext: unsigned(maxAddrBit downto 0); -- Helper only. TODO: move into variable signal sp_load: unsigned(spMaxBit downto 2); -- SP value to load, coming from EXU into PFU signal decode_load_sp: std_logic; -- Load SP signal from EXU to PFU signal exu_busy: std_logic; -- EXU busy ( stalls PFU ) signal pfu_busy: std_logic; -- PFU busy ( stalls DFU ) signal decode_jump: std_logic; -- Jump signal from EXU to DFU signal jump_address: unsigned(maxAddrBit downto 0); -- Jump address from EXU to DFU signal do_interrupt: std_logic; -- Helper. -- Sampled signals from the opcode. Left as signals -- in order to simulate design. signal sampledOpcode: std_logic_vector(OpCode_Size-1 downto 0); signal sampledDecodedOpcode: DecodedOpcodeType; signal sampledOpWillFreeze: std_logic; signal sampledStackOperation: stackChangeType; signal sampledspOffset: unsigned(4 downto 0); signal sampledTosSource: tosSourceType; signal nos: unsigned(wordSize-1 downto 0); -- This is only a helper signal wroteback_q: std_logic; -- TODO: get rid of this here, move to EXU regs -- Test debug signals signal freeze_all: std_logic := '0'; signal single_step: std_logic := '0'; begin -- Debug interface dbg_out.pc <= std_logic_vector(prefr.pc); dbg_out.opcode <= prefr.opcode; dbg_out.sp <= std_logic_vector(prefr.sp); dbg_out.brk <= exr.break; dbg_out.stacka <= std_logic_vector(exr.tos); dbg_out.stackb <= std_logic_vector(nos); dbg_out.idim <= prefr.idim; shl: lshifter port map ( clk => wb_clk_i, rst => wb_rst_i, enable => lshifter_enable, done => lshifter_done, inputA => lshifter_input, inputB => lshifter_amount, output => lshifter_output, multorshift => lshifter_multorshift ); stack_clk <= wb_clk_i; traceFileGenerate: if Generate_Trace generate trace_file: trace port map ( clk => wb_clk_i, begin_inst => begin_inst, pc => trace_pc, opcode => trace_opcode, sp => trace_sp, memA => trace_topOfStack, memB => trace_topOfStackB, busy => '0',--busy, intsp => (others => 'U') ); end generate; tOpcode_sel <= to_integer(decr.pcint(minAddrBit-1 downto 0)); do_interrupt <= '1' when wb_inta_i='1' and exr.inInterrupt='0' else '0'; decodeControl: process(rom_wb_dat_i, tOpcode_sel, sp_load, decr, do_interrupt, dbg_in.inject, dbg_in.opcode) variable tOpcode : std_logic_vector(OpCode_Size-1 downto 0); variable localspOffset: unsigned(4 downto 0); begin if dbg_in.inject='1' then tOpcode := dbg_in.opcode; else case (tOpcode_sel) is when 0 => tOpcode := std_logic_vector(rom_wb_dat_i(31 downto 24)); when 1 => tOpcode := std_logic_vector(rom_wb_dat_i(23 downto 16)); when 2 => tOpcode := std_logic_vector(rom_wb_dat_i(15 downto 8)); when 3 => tOpcode := std_logic_vector(rom_wb_dat_i(7 downto 0)); when others => null; end case; end if; sampledOpcode <= tOpcode; sampledStackOperation <= Stack_Same; sampledTosSource <= Tos_Source_None; sampledOpWillFreeze <= '0'; localspOffset(4):=not tOpcode(4); localspOffset(3 downto 0) := unsigned(tOpcode(3 downto 0)); if do_interrupt='1' and decr.im='0' then sampledDecodedOpcode <= Decoded_Interrupt; sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_PC; else if (tOpcode(7 downto 7)=OpCode_Im) then if decr.im='0' then sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_Idim0; sampledDecodedOpcode<=Decoded_Im0; else sampledTosSource <= Tos_Source_IdimN; sampledDecodedOpcode<=Decoded_ImN; end if; elsif (tOpcode(7 downto 5)=OpCode_StoreSP) then sampledStackOperation <= Stack_Pop; sampledTosSource <= Tos_Source_StackB; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Pop; sampledTosSource <= Tos_Source_StackB; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_PopDown; sampledTosSource <= Tos_Source_None; else sampledDecodedOpcode<=Decoded_StoreSP; sampledOpWillFreeze<='1'; sampledTosSource <= Tos_Source_StackB; end if; elsif (tOpcode(7 downto 5)=OpCode_LoadSP) then sampledStackOperation <= Stack_Push; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Dup; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_DupStackB; sampledTosSource <= Tos_Source_StackB; else sampledDecodedOpcode<=Decoded_LoadSP; sampledTosSource <= Tos_Source_LoadSP; end if; elsif (tOpcode(7 downto 5)=OpCode_Emulate) then -- Emulated instructions implemented in hardware if minimal_implementation then sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; else if (tOpcode(5 downto 0)=OpCode_Loadb) then sampledStackOperation<=Stack_Same; sampledDecodedOpcode<=Decoded_Loadb; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Neqbranch) then sampledStackOperation<=Stack_DualPop; sampledDecodedOpcode<=Decoded_Neqbranch; sampledOpWillFreeze <= '1'; elsif (tOpcode(5 downto 0)=OpCode_Call) then sampledDecodedOpcode<=Decoded_Call; sampledStackOperation<=Stack_Same; sampledTosSource<=Tos_Source_FetchPC; elsif (tOpcode(5 downto 0)=OpCode_Eq) then sampledDecodedOpcode<=Decoded_Eq; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Eq; elsif (tOpcode(5 downto 0)=OpCode_Ulessthan) then sampledDecodedOpcode<=Decoded_Ulessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Ulessthan; elsif (tOpcode(5 downto 0)=OpCode_Lessthan) then sampledDecodedOpcode<=Decoded_Lessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Lessthan; elsif (tOpcode(5 downto 0)=OpCode_StoreB) then sampledDecodedOpcode<=Decoded_StoreB; sampledStackOperation<=Stack_DualPop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Mult) then sampledDecodedOpcode<=Decoded_Mult; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Ashiftleft) then sampledDecodedOpcode<=Decoded_Ashiftleft; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; end if; end if; elsif (tOpcode(7 downto 4)=OpCode_AddSP) then if localspOffset=0 then sampledDecodedOpcode<=Decoded_Shift; sampledTosSource <= Tos_Source_Shift; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_AddStackB; sampledTosSource <= Tos_Source_AddStackB; else sampledDecodedOpcode<=Decoded_AddSP; sampledTosSource <= Tos_Source_AddSP; end if; else case tOpcode(3 downto 0) is when OpCode_Break => sampledDecodedOpcode<=Decoded_Break; sampledOpWillFreeze <= '1'; when OpCode_PushSP => sampledStackOperation <= Stack_Push; sampledDecodedOpcode<=Decoded_PushSP; sampledTosSource <= Tos_Source_SP; when OpCode_PopPC => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_PopPC; sampledTosSource <= Tos_Source_StackB; when OpCode_Add => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Add; sampledTosSource <= Tos_Source_Add; when OpCode_Or => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Or; sampledTosSource <= Tos_Source_Or; when OpCode_And => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_And; sampledTosSource <= Tos_Source_And; when OpCode_Load => sampledDecodedOpcode<=Decoded_Load; sampledOpWillFreeze<='1'; when OpCode_Not => sampledDecodedOpcode<=Decoded_Not; sampledTosSource <= Tos_Source_Not; when OpCode_Flip => sampledDecodedOpcode<=Decoded_Flip; sampledTosSource <= Tos_Source_Flip; when OpCode_Store => sampledStackOperation <= Stack_DualPop; sampledDecodedOpcode<=Decoded_Store; sampledOpWillFreeze<='1'; when OpCode_PopSP => sampledDecodedOpcode<=Decoded_PopSP; sampledOpWillFreeze<='1'; when OpCode_NA4 => if enable_fmul16 then sampledDecodedOpcode<=Decoded_MultF16; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Nop; end if; when others => sampledDecodedOpcode<=Decoded_Nop; end case; end if; end if; sampledspOffset <= localspOffset; end process; -- Decode/Fetch unit rom_wb_stb_o <= not exu_busy; process(decr, jump_address, decode_jump, wb_clk_i, sp_load, sampledDecodedOpcode,sampledOpcode,decode_load_sp, exu_busy, pfu_busy, pcnext, rom_wb_ack_i, wb_rst_i, sampledStackOperation, sampledspOffset, sampledTosSource, prefr.recompute_sp, sampledOpWillFreeze, dbg_in.flush, dbg_in.inject,dbg_in.injectmode, prefr.valid, prefr.break, rom_wb_stall_i ) variable w: decoderegs_type; begin w := decr; pcnext <= decr.fetchpc + 1; rom_wb_adr_o <= std_logic_vector(pc_to_memaddr(decr.fetchpc)); rom_wb_cti_o <= CTI_CYCLE_INCRADDR; if wb_rst_i='1' then w.pc := (others => '0'); w.pcint := (others => '0'); w.valid := '0'; w.fetchpc := (others => '0'); w.im:='0'; w.im_emu:='0'; w.state := State_Run; w.break := '0'; rom_wb_cyc_o <= '0'; else rom_wb_cyc_o <= '1'; case decr.state is when State_Run => if pfu_busy='0' then if dbg_in.injectmode='0' and decr.break='0' and rom_wb_stall_i='0' then w.fetchpc := pcnext; end if; -- Jump request if decode_jump='1' then w.valid := '0'; w.im := '0'; w.break := '0'; -- Invalidate eventual break after branch instruction --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o<='0'; --if rom_wb_stall_i='0' then w.fetchpc := jump_address; --else w.state := State_Jump; --end if; else if dbg_in.injectmode='1' then --or decr.break='1' then -- At this point we ought to push a new op into the pipeline. -- Since we're entering inject mode, invalidate next operation, -- but save the current IM flag. w.im_emu := decr.im; w.valid := '0'; --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o <='0'; -- Wait until no work is to be done if prefr.valid='0' and decr.valid='0' and exu_busy='0' then w.state := State_Inject; w.im:='0'; end if; if decr.break='0' then w.pc := decr.pcint; end if; else if decr.break='1' then w.valid := '0'; else w.valid := rom_wb_ack_i; end if; if rom_wb_ack_i='1' then w.im := sampledOpcode(7); if sampledDecodedOpcode=Decoded_Break then w.break:='1'; end if; end if; if prefr.break='0' and rom_wb_stall_i='0' then w.pcint := decr.fetchpc; w.pc := decr.pcint; end if; if rom_wb_stall_i='0' then w.opcode := sampledOpcode; end if; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; when State_Jump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Run; when State_InjectJump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Inject; when State_Inject => -- NOTE: disable ROM rom_wb_cyc_o <= '0'; if dbg_in.injectmode='0' then w.im := decr.im_emu; w.fetchpc := decr.pcint; w.state := State_Run; w.break := '0'; else -- Handle opcode injection -- TODO: merge this with main decode. -- NOTE: we don't check busy here, it's up to debug unit to do it --if pfu_busy='0' then --w.fetchpc := pcnext; -- Jump request if decode_jump='1' then w.fetchpc := jump_address; w.valid := '0'; w.im := '0'; w.state := State_InjectJump; else w.valid := dbg_in.inject; if dbg_in.inject='1' then w.im := sampledOpcode(7); --w.break := '0'; --w.pcint := decr.fetchpc; w.opcode := sampledOpcode; --w.pc := decr.pcint; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; --end if; end case; end if; -- rst if rising_edge(wb_clk_i) then decr <= w; end if; end process; -- Prefetch/Load unit. sp_load <= exr.tos(spMaxBit downto 2); -- Will be delayed one clock cycle process(wb_clk_i, wb_rst_i, decr, prefr, exu_busy, decode_jump, sp_load, decode_load_sp, dbg_in.flush) variable w: prefetchregs_type; variable i_op_freeze: std_logic; begin w := prefr; pfu_busy<='0'; stack_b_addr <= std_logic_vector(prefr.spnext + 1); w.recompute_sp:='0'; -- Stack w.load := decode_load_sp; if decode_load_sp='1' then pfu_busy <= '1'; w.spnext := sp_load; w.recompute_sp := '1'; else pfu_busy <= exu_busy; if decr.valid='1' then if (exu_busy='0' and decode_jump='0') or prefr.recompute_sp='1' then case decr.stackOperation is when Stack_Push => w.spnext := prefr.spnext - 1; when Stack_Pop => w.spnext := prefr.spnext + 1; when Stack_DualPop => w.spnext := prefr.spnext + 2; when others => end case; w.sp := prefr.spnext; end if; end if; end if; case decr.decodedOpcode is when Decoded_LoadSP | decoded_AddSP => stack_b_addr <= std_logic_vector(prefr.spnext + decr.spOffset); when others => end case; if decode_jump='1' then -- this is a pipeline "invalidate" flag. w.valid := '0'; else if dbg_in.flush='1' then w.valid := '0'; else w.valid := decr.valid; end if; end if; -- Moved op_will_freeze from decoder to here case decr.decodedOpcode is when Decoded_StoreSP | Decoded_LoadB | Decoded_Neqbranch | Decoded_StoreB | Decoded_Mult | Decoded_Ashiftleft | Decoded_Break | Decoded_Load | Decoded_Store | Decoded_PopSP | Decoded_MultF16 => i_op_freeze := '1'; when others => i_op_freeze := '0'; end case; if exu_busy='0' then w.decodedOpcode := decr.decodedOpcode; w.tosSource := decr.tosSource; w.opcode := decr.opcode; w.opWillFreeze := i_op_freeze; w.pc := decr.pc; w.fetchpc := decr.pcint; w.idim := decr.idim; w.break := decr.break; end if; if wb_rst_i='1' then w.spnext := unsigned(spStart(10 downto 2)); --w.sp := unsigned(spStart(10 downto 2)); w.valid := '0'; w.idim := '0'; w.recompute_sp:='0'; end if; if rising_edge(wb_clk_i) then prefr <= w; end if; end process; process(prefr,exr,nos) begin trace_pc <= (others => '0'); trace_pc(maxAddrBit downto 0) <= std_logic_vector(prefr.pc); trace_opcode <= prefr.opcode; trace_sp <= (others => '0'); trace_sp(10 downto 2) <= std_logic_vector(prefr.sp); trace_topOfStack <= std_logic_vector( exr.tos ); trace_topOfStackB <= std_logic_vector( nos ); end process; -- IO/Memory Accesses wb_adr_o(maxAddrBitIncIO downto 0) <= std_logic_vector(exr.tos_save(maxAddrBitIncIO downto 0)); wb_cyc_o <= exr.wb_cyc; wb_stb_o <= exr.wb_stb; wb_we_o <= exr.wb_we; wb_dat_o <= std_logic_vector( exr.nos_save ); freeze_all <= dbg_in.freeze; process(exr, wb_inta_i, wb_clk_i, wb_rst_i, pcnext, stack_a_read,stack_b_read, wb_ack_i, wb_dat_i, do_interrupt,exr, prefr, nos, single_step, freeze_all, dbg_in.step, wroteback_q,lshifter_done,lshifter_output ) variable spOffset: unsigned(4 downto 0); variable w: exuregs_type; variable instruction_executed: std_logic; variable wroteback: std_logic; begin w := exr; instruction_executed := '0'; -- used for single stepping stack_b_writeenable <= '0'; stack_a_enable <= '1'; stack_b_enable <= '1'; exu_busy <= '0'; decode_jump <= '0'; jump_address <= (others => DontCareValue); lshifter_enable <= '0'; lshifter_amount <= std_logic_vector(exr.tos_save); lshifter_input <= std_logic_vector(exr.nos_save); lshifter_multorshift <= '0'; poppc_inst <= '0'; begin_inst<='0'; stack_a_addr <= std_logic_vector( prefr.sp ); stack_a_writeenable <= '0'; wroteback := wroteback_q; stack_b_writeenable <= '0'; stack_a_write <= std_logic_vector(exr.tos); spOffset(4):=not prefr.opcode(4); spOffset(3 downto 0) := unsigned(prefr.opcode(3 downto 0)); if wb_inta_i='0' then w.inInterrupt := '0'; end if; stack_b_write<=(others => DontCareValue); if wroteback_q='1' then nos <= unsigned(stack_a_read); else nos <= unsigned(stack_b_read); end if; decode_load_sp <= '0'; case exr.state is when State_Resync1 => exu_busy <= '1'; stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_ResyncFromStoreStack => exu_busy <= '1'; stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_Resync2 => w.tos := unsigned(stack_a_read); instruction_executed := '1'; exu_busy <= '0'; wroteback := '0'; stack_b_enable <= '1'; w.state := State_Execute; when State_Execute => instruction_executed:='0'; if prefr.valid='1' then exu_busy <= prefr.opWillFreeze; if freeze_all='0' or single_step='1' then wroteback := '0'; w.nos_save := nos; w.tos_save := exr.tos; w.idim := prefr.idim; w.break:= prefr.break; begin_inst<='1'; instruction_executed := '1'; -- TOS big muxer case prefr.tosSource is when Tos_Source_PC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.pc; when Tos_Source_FetchPC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.fetchpc; when Tos_Source_Idim0 => for i in wordSize-1 downto 7 loop w.tos(i) := prefr.opcode(6); end loop; w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_IdimN => w.tos(wordSize-1 downto 7) := exr.tos(wordSize-8 downto 0); w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_StackB => w.tos := nos; when Tos_Source_SP => w.tos := (others => '0'); w.tos(31) := '1'; -- Stack address w.tos(10 downto 2) := prefr.sp; when Tos_Source_Add => w.tos := exr.tos + nos; when Tos_Source_And => w.tos := exr.tos and nos; when Tos_Source_Or => w.tos := exr.tos or nos; when Tos_Source_Eq => w.tos := (others => '0'); if nos = exr.tos then w.tos(0) := '1'; end if; when Tos_Source_Ulessthan => w.tos := (others => '0'); if exr.tos < nos then w.tos(0) := '1'; end if; when Tos_Source_Lessthan => w.tos := (others => '0'); if signed(exr.tos) < signed(nos) then w.tos(0) := '1'; end if; when Tos_Source_Not => w.tos := not exr.tos; when Tos_Source_Flip => for i in 0 to wordSize-1 loop w.tos(i) := exr.tos(wordSize-1-i); end loop; when Tos_Source_LoadSP => w.tos := unsigned(stack_b_read); when Tos_Source_AddSP => w.tos := w.tos + unsigned(stack_b_read); when Tos_Source_AddStackB => w.tos := w.tos + nos; when Tos_Source_Shift => w.tos := exr.tos + exr.tos; when others => end case; case prefr.decodedOpcode is when Decoded_Interrupt => w.inInterrupt := '1'; jump_address <= to_unsigned(32, maxAddrBit+1); decode_jump <= '1'; stack_a_writeenable<='1'; wroteback:='1'; stack_b_enable<='0'; instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Im0 => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_ImN => when Decoded_Nop => when Decoded_PopPC | Decoded_Call => decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0); poppc_inst <= '1'; stack_b_enable<='0'; -- Delay instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Emulate => decode_jump <= '1'; jump_address <= (others => '0'); jump_address(9 downto 5) <= unsigned(prefr.opcode(4 downto 0)); stack_a_writeenable<='1'; wroteback:='1'; when Decoded_PushSP => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_LoadSP => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_DupStackB => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_Dup => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_AddSP => stack_a_writeenable <= '1'; when Decoded_StoreSP => stack_a_writeenable <= '1'; wroteback:='1'; stack_a_addr <= std_logic_vector(prefr.sp + spOffset); instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_PopDown => stack_a_writeenable<='1'; when Decoded_Pop => when Decoded_Ashiftleft => w.state := State_Ashiftleft; when Decoded_Mult => w.state := State_Mult; when Decoded_MultF16 => w.state := State_MultF16; when Decoded_Store => if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(nos); stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when Decoded_Load | Decoded_Loadb | Decoded_StoreB => --w.tos_save := exr.tos; -- Byte select instruction_executed := '0'; wroteback := wroteback_q; -- Keep WB if exr.tos(wordSize-1)='1' then stack_a_addr<=std_logic_vector(exr.tos(10 downto 2)); stack_a_enable<='1'; w.state := State_LoadStack; else stack_a_enable <= '0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); w.wb_we :='0'; w.wb_cyc :='1'; w.wb_stb :='1'; w.state := State_Load; end if; when Decoded_PopSP => decode_load_sp <= '1'; instruction_executed := '0'; stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); w.state := State_Resync2; --when Decoded_Break => -- w.break := '1'; when Decoded_Neqbranch => instruction_executed := '0'; w.state := State_NeqBranch; when others => end case; else -- freeze_all -- -- Freeze the entire pipeline. -- exu_busy<='1'; stack_a_enable<='0'; stack_b_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); end if; end if; -- valid when State_Ashiftleft => exu_busy <= '1'; lshifter_enable <= '1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_Mult => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_MultF16 => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(47 downto 16)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_WaitSPB => instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Store => exu_busy <= '1'; -- Keep writeback flag wroteback := wroteback_q; if wb_ack_i='1' then stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; stack_b_enable<='1'; wroteback := '0'; --exu_busy <= '1'; w.wb_cyc := '0'; w.state := State_Resync2; else stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_a_enable<='0'; stack_b_enable<='0'; end if; when State_Loadb => w.tos(wordSize-1 downto 8) := (others => '0'); case exr.tos_save(1 downto 0) is when "11" => w.tos(7 downto 0) := unsigned(exr.tos(7 downto 0)); when "10" => w.tos(7 downto 0) := unsigned(exr.tos(15 downto 8)); when "01" => w.tos(7 downto 0) := unsigned(exr.tos(23 downto 16)); when "00" => w.tos(7 downto 0) := unsigned(exr.tos(31 downto 24)); when others => null; end case; instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Load => if wb_ack_i='0' then exu_busy<='1'; else w.tos := unsigned(wb_dat_i); w.wb_cyc := '0'; if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state := State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state := State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; end if; when State_LoadStack => w.tos := unsigned(stack_a_read); if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state:=State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state:=State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; when State_NeqBranch => if exr.nos_save/=0 then decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0) + prefr.pc; poppc_inst <= '1'; exu_busy <= '0'; else exu_busy <='1'; end if; instruction_executed := '0'; stack_a_addr <= std_logic_vector(prefr.spnext); wroteback:='0'; w.state := State_Resync2; when State_StoreB => exu_busy <= '1'; -- -- At this point, we have loaded the 32-bit, and it's in TOS -- The IO address is still saved in save_TOS. -- The original write value is still at save_NOS -- -- So we mangle the write value, and update save_NOS, and restore -- the IO address to TOS -- -- This is still buggy - don't use. Problems arise when writing to stack. -- w.nos_save := exr.tos; case exr.tos_save(1 downto 0) is when "00" => w.nos_save(31 downto 24) := exr.nos_save(7 downto 0); when "01" => w.nos_save(23 downto 16) := exr.nos_save(7 downto 0); when "10" => w.nos_save(15 downto 8) := exr.nos_save(7 downto 0); when "11" => w.nos_save(7 downto 0) := exr.nos_save(7 downto 0); when others => null; end case; w.tos := exr.tos_save; w.state := State_StoreB2; when State_StoreB2 => exu_busy <= '1'; if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(exr.nos_save); -- hmm I don't like this stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when others => null; end case; if rising_edge(wb_clk_i) then if wb_rst_i='1' then exr.state <= State_Execute; exr.idim <= DontCareValue; exr.inInterrupt <= '0'; exr.break <= '0'; exr.wb_cyc <= '0'; exr.wb_stb <= '1'; else exr <= w; -- TODO: move wroteback_q into EXU regs wroteback_q <= wroteback; if exr.break='1' then report "BREAK" severity failure; end if; -- Some sanity checks, to be caught in simulation if prefr.valid='1' then if prefr.tosSource=Tos_Source_Idim0 and prefr.idim='1' then report "Invalid IDIM flag 0" severity error; end if; if prefr.tosSource=Tos_Source_IdimN and prefr.idim='0' then report "Invalid IDIM flag 1" severity error; end if; end if; end if; end if; end process; single_step <= dbg_in.step; dbg_out.valid <= '1' when prefr.valid='1' else '0'; -- Let pipeline finish dbg_out.ready <= '1' when exr.state=state_execute and decode_load_sp='0' and decode_jump='0' and decr.state = State_Inject --and jump_q='0' else '0'; end behave;
-- ZPU -- -- Copyright 2004-2008 oharboe - Øyvind Harboe - [email protected] -- Copyright 2010-2012 Alvaro Lopes - [email protected] -- -- The FreeBSD license -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions -- are met: -- -- 1. Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer. -- 2. Redistributions in binary form must reproduce the above -- copyright notice, this list of conditions and the following -- disclaimer in the documentation and/or other materials -- provided with the distribution. -- -- THIS SOFTWARE IS PROVIDED BY THE ZPU PROJECT ``AS IS'' AND ANY -- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -- ZPU PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- The views and conclusions contained in the software and documentation -- are those of the authors and should not be interpreted as representing -- official policies, either expressed or implied, of the ZPU Project. library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.numeric_std.all; library board; use board.zpu_config.all; use board.zpupkg.all; use board.wishbonepkg.all; --library UNISIM; --use UNISIM.vcomponents.all; entity zpu_core_extreme is port ( wb_clk_i: in std_logic; wb_rst_i: in std_logic; -- Master wishbone interface wb_ack_i: in std_logic; wb_dat_i: in std_logic_vector(wordSize-1 downto 0); wb_dat_o: out std_logic_vector(wordSize-1 downto 0); wb_adr_o: out std_logic_vector(maxAddrBitIncIO downto 0); wb_cyc_o: out std_logic; wb_stb_o: out std_logic; wb_we_o: out std_logic; wb_inta_i: in std_logic; poppc_inst: out std_logic; break: out std_logic; -- STACK stack_a_read: in std_logic_vector(wordSize-1 downto 0); stack_b_read: in std_logic_vector(wordSize-1 downto 0); stack_a_write: out std_logic_vector(wordSize-1 downto 0); stack_b_write: out std_logic_vector(wordSize-1 downto 0); stack_a_writeenable: out std_logic; stack_a_enable: out std_logic; stack_b_writeenable: out std_logic; stack_b_enable: out std_logic; stack_a_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_b_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_clk: out std_logic; -- ROM wb interface rom_wb_ack_i: in std_logic; rom_wb_dat_i: in std_logic_vector(wordSize-1 downto 0); rom_wb_adr_o: out std_logic_vector(maxAddrBit downto 0); rom_wb_cyc_o: out std_logic; rom_wb_stb_o: out std_logic; rom_wb_cti_o: out std_logic_vector(2 downto 0); rom_wb_stall_i: in std_logic; -- Debug interface dbg_out: out zpu_dbg_out_type; dbg_in: in zpu_dbg_in_type ); end zpu_core_extreme; architecture behave of zpu_core_extreme is component lshifter is port ( clk: in std_logic; rst: in std_logic; enable: in std_logic; done: out std_logic; inputA: in std_logic_vector(31 downto 0); inputB: in std_logic_vector(31 downto 0); output: out std_logic_vector(63 downto 0); multorshift: in std_logic ); end component; signal lshifter_enable: std_logic; signal lshifter_done: std_logic; signal lshifter_input: std_logic_vector(31 downto 0); signal lshifter_amount: std_logic_vector(31 downto 0); signal lshifter_output: std_logic_vector(63 downto 0); signal lshifter_multorshift: std_logic; signal begin_inst: std_logic; signal trace_opcode: std_logic_vector(7 downto 0); signal trace_pc: std_logic_vector(maxAddrBitIncIO downto 0); signal trace_sp: std_logic_vector(maxAddrBitIncIO downto minAddrBit); signal trace_topOfStack: std_logic_vector(wordSize-1 downto 0); signal trace_topOfStackB: std_logic_vector(wordSize-1 downto 0); -- state machine. type State_Type is ( State_Execute, State_Store, State_StoreB, State_StoreB2, State_Load, State_LoadMemory, State_LoadStack, State_Loadb, State_Resync1, State_Resync2, State_LoadSP, State_WaitSPB, State_ResyncFromStoreStack, State_Neqbranch, State_Ashiftleft, State_Mult, State_MultF16 ); type DecodedOpcodeType is ( Decoded_Nop, Decoded_Idle, Decoded_Im0, Decoded_ImN, Decoded_LoadSP, Decoded_Dup, Decoded_DupStackB, Decoded_StoreSP, Decoded_Pop, Decoded_PopDown, Decoded_AddSP, Decoded_AddStackB, Decoded_Shift, Decoded_Emulate, Decoded_Break, Decoded_PushSP, Decoded_PopPC, Decoded_Add, Decoded_Or, Decoded_And, Decoded_Load, Decoded_Not, Decoded_Flip, Decoded_Store, Decoded_PopSP, Decoded_Interrupt, Decoded_Neqbranch, Decoded_Eq, Decoded_Storeb, Decoded_Storeh, Decoded_Ulessthan, Decoded_Lessthan, Decoded_Ashiftleft, Decoded_Ashiftright, Decoded_Loadb, Decoded_Call, Decoded_Mult, Decoded_MultF16 ); constant spMaxBit: integer := 10; constant minimal_implementation: boolean := false; subtype index is integer range 0 to 3; signal tOpcode_sel : index; function pc_to_cpuword(pc: unsigned) return unsigned is variable r: unsigned(wordSize-1 downto 0); begin r := (others => DontCareValue); r(maxAddrBit downto 0) := pc; return r; end pc_to_cpuword; function pc_to_memaddr(pc: unsigned) return unsigned is variable r: unsigned(maxAddrBit downto 0); begin r := (others => '0'); r(maxAddrBit downto minAddrBit) := pc(maxAddrBit downto minAddrBit); return r; end pc_to_memaddr; -- Prefetch stage registers type stackChangeType is ( Stack_Same, Stack_Push, Stack_Pop, Stack_DualPop ); type tosSourceType is ( Tos_Source_PC, Tos_Source_FetchPC, Tos_Source_Idim0, Tos_Source_IdimN, Tos_Source_StackB, Tos_Source_SP, Tos_Source_Add, Tos_Source_And, Tos_Source_Or, Tos_Source_Eq, Tos_Source_Not, Tos_Source_Flip, Tos_Source_LoadSP, Tos_Source_AddSP, Tos_Source_AddStackB, Tos_Source_Shift, Tos_Source_Ulessthan, Tos_Source_Lessthan, Tos_Source_None ); type decoderstate_type is ( State_Run, State_Jump, State_Inject, State_InjectJump ); type decoderegs_type is record valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opWillFreeze: std_logic; -- '1' if we know in advance this opcode will freeze pipeline opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); pcint: unsigned(maxAddrBit downto 0); idim: std_logic; im: std_logic; stackOperation: stackChangeType; spOffset: unsigned(4 downto 0); im_emu: std_logic; --emumode: std_logic; break: std_logic; state: decoderstate_type; end record; type prefetchregs_type is record sp: unsigned(spMaxBit downto 2); spnext: unsigned(spMaxBit downto 2); valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); idim: std_logic; break: std_logic; load: std_logic; opWillFreeze: std_logic; recompute_sp: std_logic; end record; type exuregs_type is record idim: std_logic; break: std_logic; inInterrupt:std_logic; tos: unsigned(wordSize-1 downto 0); tos_save: unsigned(wordSize-1 downto 0); nos_save: unsigned(wordSize-1 downto 0); state: State_Type; -- Wishbone control signals (registered) wb_cyc: std_logic; wb_stb: std_logic; wb_we: std_logic; end record; -- Registers for each stage signal exr: exuregs_type; signal prefr: prefetchregs_type; signal decr: decoderegs_type; signal pcnext: unsigned(maxAddrBit downto 0); -- Helper only. TODO: move into variable signal sp_load: unsigned(spMaxBit downto 2); -- SP value to load, coming from EXU into PFU signal decode_load_sp: std_logic; -- Load SP signal from EXU to PFU signal exu_busy: std_logic; -- EXU busy ( stalls PFU ) signal pfu_busy: std_logic; -- PFU busy ( stalls DFU ) signal decode_jump: std_logic; -- Jump signal from EXU to DFU signal jump_address: unsigned(maxAddrBit downto 0); -- Jump address from EXU to DFU signal do_interrupt: std_logic; -- Helper. -- Sampled signals from the opcode. Left as signals -- in order to simulate design. signal sampledOpcode: std_logic_vector(OpCode_Size-1 downto 0); signal sampledDecodedOpcode: DecodedOpcodeType; signal sampledOpWillFreeze: std_logic; signal sampledStackOperation: stackChangeType; signal sampledspOffset: unsigned(4 downto 0); signal sampledTosSource: tosSourceType; signal nos: unsigned(wordSize-1 downto 0); -- This is only a helper signal wroteback_q: std_logic; -- TODO: get rid of this here, move to EXU regs -- Test debug signals signal freeze_all: std_logic := '0'; signal single_step: std_logic := '0'; begin -- Debug interface dbg_out.pc <= std_logic_vector(prefr.pc); dbg_out.opcode <= prefr.opcode; dbg_out.sp <= std_logic_vector(prefr.sp); dbg_out.brk <= exr.break; dbg_out.stacka <= std_logic_vector(exr.tos); dbg_out.stackb <= std_logic_vector(nos); dbg_out.idim <= prefr.idim; shl: lshifter port map ( clk => wb_clk_i, rst => wb_rst_i, enable => lshifter_enable, done => lshifter_done, inputA => lshifter_input, inputB => lshifter_amount, output => lshifter_output, multorshift => lshifter_multorshift ); stack_clk <= wb_clk_i; traceFileGenerate: if Generate_Trace generate trace_file: trace port map ( clk => wb_clk_i, begin_inst => begin_inst, pc => trace_pc, opcode => trace_opcode, sp => trace_sp, memA => trace_topOfStack, memB => trace_topOfStackB, busy => '0',--busy, intsp => (others => 'U') ); end generate; tOpcode_sel <= to_integer(decr.pcint(minAddrBit-1 downto 0)); do_interrupt <= '1' when wb_inta_i='1' and exr.inInterrupt='0' else '0'; decodeControl: process(rom_wb_dat_i, tOpcode_sel, sp_load, decr, do_interrupt, dbg_in.inject, dbg_in.opcode) variable tOpcode : std_logic_vector(OpCode_Size-1 downto 0); variable localspOffset: unsigned(4 downto 0); begin if dbg_in.inject='1' then tOpcode := dbg_in.opcode; else case (tOpcode_sel) is when 0 => tOpcode := std_logic_vector(rom_wb_dat_i(31 downto 24)); when 1 => tOpcode := std_logic_vector(rom_wb_dat_i(23 downto 16)); when 2 => tOpcode := std_logic_vector(rom_wb_dat_i(15 downto 8)); when 3 => tOpcode := std_logic_vector(rom_wb_dat_i(7 downto 0)); when others => null; end case; end if; sampledOpcode <= tOpcode; sampledStackOperation <= Stack_Same; sampledTosSource <= Tos_Source_None; sampledOpWillFreeze <= '0'; localspOffset(4):=not tOpcode(4); localspOffset(3 downto 0) := unsigned(tOpcode(3 downto 0)); if do_interrupt='1' and decr.im='0' then sampledDecodedOpcode <= Decoded_Interrupt; sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_PC; else if (tOpcode(7 downto 7)=OpCode_Im) then if decr.im='0' then sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_Idim0; sampledDecodedOpcode<=Decoded_Im0; else sampledTosSource <= Tos_Source_IdimN; sampledDecodedOpcode<=Decoded_ImN; end if; elsif (tOpcode(7 downto 5)=OpCode_StoreSP) then sampledStackOperation <= Stack_Pop; sampledTosSource <= Tos_Source_StackB; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Pop; sampledTosSource <= Tos_Source_StackB; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_PopDown; sampledTosSource <= Tos_Source_None; else sampledDecodedOpcode<=Decoded_StoreSP; sampledOpWillFreeze<='1'; sampledTosSource <= Tos_Source_StackB; end if; elsif (tOpcode(7 downto 5)=OpCode_LoadSP) then sampledStackOperation <= Stack_Push; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Dup; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_DupStackB; sampledTosSource <= Tos_Source_StackB; else sampledDecodedOpcode<=Decoded_LoadSP; sampledTosSource <= Tos_Source_LoadSP; end if; elsif (tOpcode(7 downto 5)=OpCode_Emulate) then -- Emulated instructions implemented in hardware if minimal_implementation then sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; else if (tOpcode(5 downto 0)=OpCode_Loadb) then sampledStackOperation<=Stack_Same; sampledDecodedOpcode<=Decoded_Loadb; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Neqbranch) then sampledStackOperation<=Stack_DualPop; sampledDecodedOpcode<=Decoded_Neqbranch; sampledOpWillFreeze <= '1'; elsif (tOpcode(5 downto 0)=OpCode_Call) then sampledDecodedOpcode<=Decoded_Call; sampledStackOperation<=Stack_Same; sampledTosSource<=Tos_Source_FetchPC; elsif (tOpcode(5 downto 0)=OpCode_Eq) then sampledDecodedOpcode<=Decoded_Eq; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Eq; elsif (tOpcode(5 downto 0)=OpCode_Ulessthan) then sampledDecodedOpcode<=Decoded_Ulessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Ulessthan; elsif (tOpcode(5 downto 0)=OpCode_Lessthan) then sampledDecodedOpcode<=Decoded_Lessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Lessthan; elsif (tOpcode(5 downto 0)=OpCode_StoreB) then sampledDecodedOpcode<=Decoded_StoreB; sampledStackOperation<=Stack_DualPop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Mult) then sampledDecodedOpcode<=Decoded_Mult; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Ashiftleft) then sampledDecodedOpcode<=Decoded_Ashiftleft; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; end if; end if; elsif (tOpcode(7 downto 4)=OpCode_AddSP) then if localspOffset=0 then sampledDecodedOpcode<=Decoded_Shift; sampledTosSource <= Tos_Source_Shift; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_AddStackB; sampledTosSource <= Tos_Source_AddStackB; else sampledDecodedOpcode<=Decoded_AddSP; sampledTosSource <= Tos_Source_AddSP; end if; else case tOpcode(3 downto 0) is when OpCode_Break => sampledDecodedOpcode<=Decoded_Break; sampledOpWillFreeze <= '1'; when OpCode_PushSP => sampledStackOperation <= Stack_Push; sampledDecodedOpcode<=Decoded_PushSP; sampledTosSource <= Tos_Source_SP; when OpCode_PopPC => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_PopPC; sampledTosSource <= Tos_Source_StackB; when OpCode_Add => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Add; sampledTosSource <= Tos_Source_Add; when OpCode_Or => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Or; sampledTosSource <= Tos_Source_Or; when OpCode_And => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_And; sampledTosSource <= Tos_Source_And; when OpCode_Load => sampledDecodedOpcode<=Decoded_Load; sampledOpWillFreeze<='1'; when OpCode_Not => sampledDecodedOpcode<=Decoded_Not; sampledTosSource <= Tos_Source_Not; when OpCode_Flip => sampledDecodedOpcode<=Decoded_Flip; sampledTosSource <= Tos_Source_Flip; when OpCode_Store => sampledStackOperation <= Stack_DualPop; sampledDecodedOpcode<=Decoded_Store; sampledOpWillFreeze<='1'; when OpCode_PopSP => sampledDecodedOpcode<=Decoded_PopSP; sampledOpWillFreeze<='1'; when OpCode_NA4 => if enable_fmul16 then sampledDecodedOpcode<=Decoded_MultF16; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Nop; end if; when others => sampledDecodedOpcode<=Decoded_Nop; end case; end if; end if; sampledspOffset <= localspOffset; end process; -- Decode/Fetch unit rom_wb_stb_o <= not exu_busy; process(decr, jump_address, decode_jump, wb_clk_i, sp_load, sampledDecodedOpcode,sampledOpcode,decode_load_sp, exu_busy, pfu_busy, pcnext, rom_wb_ack_i, wb_rst_i, sampledStackOperation, sampledspOffset, sampledTosSource, prefr.recompute_sp, sampledOpWillFreeze, dbg_in.flush, dbg_in.inject,dbg_in.injectmode, prefr.valid, prefr.break, rom_wb_stall_i ) variable w: decoderegs_type; begin w := decr; pcnext <= decr.fetchpc + 1; rom_wb_adr_o <= std_logic_vector(pc_to_memaddr(decr.fetchpc)); rom_wb_cti_o <= CTI_CYCLE_INCRADDR; if wb_rst_i='1' then w.pc := (others => '0'); w.pcint := (others => '0'); w.valid := '0'; w.fetchpc := (others => '0'); w.im:='0'; w.im_emu:='0'; w.state := State_Run; w.break := '0'; rom_wb_cyc_o <= '0'; else rom_wb_cyc_o <= '1'; case decr.state is when State_Run => if pfu_busy='0' then if dbg_in.injectmode='0' and decr.break='0' and rom_wb_stall_i='0' then w.fetchpc := pcnext; end if; -- Jump request if decode_jump='1' then w.valid := '0'; w.im := '0'; w.break := '0'; -- Invalidate eventual break after branch instruction --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o<='0'; --if rom_wb_stall_i='0' then w.fetchpc := jump_address; --else w.state := State_Jump; --end if; else if dbg_in.injectmode='1' then --or decr.break='1' then -- At this point we ought to push a new op into the pipeline. -- Since we're entering inject mode, invalidate next operation, -- but save the current IM flag. w.im_emu := decr.im; w.valid := '0'; --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o <='0'; -- Wait until no work is to be done if prefr.valid='0' and decr.valid='0' and exu_busy='0' then w.state := State_Inject; w.im:='0'; end if; if decr.break='0' then w.pc := decr.pcint; end if; else if decr.break='1' then w.valid := '0'; else w.valid := rom_wb_ack_i; end if; if rom_wb_ack_i='1' then w.im := sampledOpcode(7); if sampledDecodedOpcode=Decoded_Break then w.break:='1'; end if; end if; if prefr.break='0' and rom_wb_stall_i='0' then w.pcint := decr.fetchpc; w.pc := decr.pcint; end if; if rom_wb_stall_i='0' then w.opcode := sampledOpcode; end if; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; when State_Jump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Run; when State_InjectJump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Inject; when State_Inject => -- NOTE: disable ROM rom_wb_cyc_o <= '0'; if dbg_in.injectmode='0' then w.im := decr.im_emu; w.fetchpc := decr.pcint; w.state := State_Run; w.break := '0'; else -- Handle opcode injection -- TODO: merge this with main decode. -- NOTE: we don't check busy here, it's up to debug unit to do it --if pfu_busy='0' then --w.fetchpc := pcnext; -- Jump request if decode_jump='1' then w.fetchpc := jump_address; w.valid := '0'; w.im := '0'; w.state := State_InjectJump; else w.valid := dbg_in.inject; if dbg_in.inject='1' then w.im := sampledOpcode(7); --w.break := '0'; --w.pcint := decr.fetchpc; w.opcode := sampledOpcode; --w.pc := decr.pcint; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; --end if; end case; end if; -- rst if rising_edge(wb_clk_i) then decr <= w; end if; end process; -- Prefetch/Load unit. sp_load <= exr.tos(spMaxBit downto 2); -- Will be delayed one clock cycle process(wb_clk_i, wb_rst_i, decr, prefr, exu_busy, decode_jump, sp_load, decode_load_sp, dbg_in.flush) variable w: prefetchregs_type; variable i_op_freeze: std_logic; begin w := prefr; pfu_busy<='0'; stack_b_addr <= std_logic_vector(prefr.spnext + 1); w.recompute_sp:='0'; -- Stack w.load := decode_load_sp; if decode_load_sp='1' then pfu_busy <= '1'; w.spnext := sp_load; w.recompute_sp := '1'; else pfu_busy <= exu_busy; if decr.valid='1' then if (exu_busy='0' and decode_jump='0') or prefr.recompute_sp='1' then case decr.stackOperation is when Stack_Push => w.spnext := prefr.spnext - 1; when Stack_Pop => w.spnext := prefr.spnext + 1; when Stack_DualPop => w.spnext := prefr.spnext + 2; when others => end case; w.sp := prefr.spnext; end if; end if; end if; case decr.decodedOpcode is when Decoded_LoadSP | decoded_AddSP => stack_b_addr <= std_logic_vector(prefr.spnext + decr.spOffset); when others => end case; if decode_jump='1' then -- this is a pipeline "invalidate" flag. w.valid := '0'; else if dbg_in.flush='1' then w.valid := '0'; else w.valid := decr.valid; end if; end if; -- Moved op_will_freeze from decoder to here case decr.decodedOpcode is when Decoded_StoreSP | Decoded_LoadB | Decoded_Neqbranch | Decoded_StoreB | Decoded_Mult | Decoded_Ashiftleft | Decoded_Break | Decoded_Load | Decoded_Store | Decoded_PopSP | Decoded_MultF16 => i_op_freeze := '1'; when others => i_op_freeze := '0'; end case; if exu_busy='0' then w.decodedOpcode := decr.decodedOpcode; w.tosSource := decr.tosSource; w.opcode := decr.opcode; w.opWillFreeze := i_op_freeze; w.pc := decr.pc; w.fetchpc := decr.pcint; w.idim := decr.idim; w.break := decr.break; end if; if wb_rst_i='1' then w.spnext := unsigned(spStart(10 downto 2)); --w.sp := unsigned(spStart(10 downto 2)); w.valid := '0'; w.idim := '0'; w.recompute_sp:='0'; end if; if rising_edge(wb_clk_i) then prefr <= w; end if; end process; process(prefr,exr,nos) begin trace_pc <= (others => '0'); trace_pc(maxAddrBit downto 0) <= std_logic_vector(prefr.pc); trace_opcode <= prefr.opcode; trace_sp <= (others => '0'); trace_sp(10 downto 2) <= std_logic_vector(prefr.sp); trace_topOfStack <= std_logic_vector( exr.tos ); trace_topOfStackB <= std_logic_vector( nos ); end process; -- IO/Memory Accesses wb_adr_o(maxAddrBitIncIO downto 0) <= std_logic_vector(exr.tos_save(maxAddrBitIncIO downto 0)); wb_cyc_o <= exr.wb_cyc; wb_stb_o <= exr.wb_stb; wb_we_o <= exr.wb_we; wb_dat_o <= std_logic_vector( exr.nos_save ); freeze_all <= dbg_in.freeze; process(exr, wb_inta_i, wb_clk_i, wb_rst_i, pcnext, stack_a_read,stack_b_read, wb_ack_i, wb_dat_i, do_interrupt,exr, prefr, nos, single_step, freeze_all, dbg_in.step, wroteback_q,lshifter_done,lshifter_output ) variable spOffset: unsigned(4 downto 0); variable w: exuregs_type; variable instruction_executed: std_logic; variable wroteback: std_logic; begin w := exr; instruction_executed := '0'; -- used for single stepping stack_b_writeenable <= '0'; stack_a_enable <= '1'; stack_b_enable <= '1'; exu_busy <= '0'; decode_jump <= '0'; jump_address <= (others => DontCareValue); lshifter_enable <= '0'; lshifter_amount <= std_logic_vector(exr.tos_save); lshifter_input <= std_logic_vector(exr.nos_save); lshifter_multorshift <= '0'; poppc_inst <= '0'; begin_inst<='0'; stack_a_addr <= std_logic_vector( prefr.sp ); stack_a_writeenable <= '0'; wroteback := wroteback_q; stack_b_writeenable <= '0'; stack_a_write <= std_logic_vector(exr.tos); spOffset(4):=not prefr.opcode(4); spOffset(3 downto 0) := unsigned(prefr.opcode(3 downto 0)); if wb_inta_i='0' then w.inInterrupt := '0'; end if; stack_b_write<=(others => DontCareValue); if wroteback_q='1' then nos <= unsigned(stack_a_read); else nos <= unsigned(stack_b_read); end if; decode_load_sp <= '0'; case exr.state is when State_Resync1 => exu_busy <= '1'; stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_ResyncFromStoreStack => exu_busy <= '1'; stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_Resync2 => w.tos := unsigned(stack_a_read); instruction_executed := '1'; exu_busy <= '0'; wroteback := '0'; stack_b_enable <= '1'; w.state := State_Execute; when State_Execute => instruction_executed:='0'; if prefr.valid='1' then exu_busy <= prefr.opWillFreeze; if freeze_all='0' or single_step='1' then wroteback := '0'; w.nos_save := nos; w.tos_save := exr.tos; w.idim := prefr.idim; w.break:= prefr.break; begin_inst<='1'; instruction_executed := '1'; -- TOS big muxer case prefr.tosSource is when Tos_Source_PC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.pc; when Tos_Source_FetchPC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.fetchpc; when Tos_Source_Idim0 => for i in wordSize-1 downto 7 loop w.tos(i) := prefr.opcode(6); end loop; w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_IdimN => w.tos(wordSize-1 downto 7) := exr.tos(wordSize-8 downto 0); w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_StackB => w.tos := nos; when Tos_Source_SP => w.tos := (others => '0'); w.tos(31) := '1'; -- Stack address w.tos(10 downto 2) := prefr.sp; when Tos_Source_Add => w.tos := exr.tos + nos; when Tos_Source_And => w.tos := exr.tos and nos; when Tos_Source_Or => w.tos := exr.tos or nos; when Tos_Source_Eq => w.tos := (others => '0'); if nos = exr.tos then w.tos(0) := '1'; end if; when Tos_Source_Ulessthan => w.tos := (others => '0'); if exr.tos < nos then w.tos(0) := '1'; end if; when Tos_Source_Lessthan => w.tos := (others => '0'); if signed(exr.tos) < signed(nos) then w.tos(0) := '1'; end if; when Tos_Source_Not => w.tos := not exr.tos; when Tos_Source_Flip => for i in 0 to wordSize-1 loop w.tos(i) := exr.tos(wordSize-1-i); end loop; when Tos_Source_LoadSP => w.tos := unsigned(stack_b_read); when Tos_Source_AddSP => w.tos := w.tos + unsigned(stack_b_read); when Tos_Source_AddStackB => w.tos := w.tos + nos; when Tos_Source_Shift => w.tos := exr.tos + exr.tos; when others => end case; case prefr.decodedOpcode is when Decoded_Interrupt => w.inInterrupt := '1'; jump_address <= to_unsigned(32, maxAddrBit+1); decode_jump <= '1'; stack_a_writeenable<='1'; wroteback:='1'; stack_b_enable<='0'; instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Im0 => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_ImN => when Decoded_Nop => when Decoded_PopPC | Decoded_Call => decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0); poppc_inst <= '1'; stack_b_enable<='0'; -- Delay instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Emulate => decode_jump <= '1'; jump_address <= (others => '0'); jump_address(9 downto 5) <= unsigned(prefr.opcode(4 downto 0)); stack_a_writeenable<='1'; wroteback:='1'; when Decoded_PushSP => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_LoadSP => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_DupStackB => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_Dup => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_AddSP => stack_a_writeenable <= '1'; when Decoded_StoreSP => stack_a_writeenable <= '1'; wroteback:='1'; stack_a_addr <= std_logic_vector(prefr.sp + spOffset); instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_PopDown => stack_a_writeenable<='1'; when Decoded_Pop => when Decoded_Ashiftleft => w.state := State_Ashiftleft; when Decoded_Mult => w.state := State_Mult; when Decoded_MultF16 => w.state := State_MultF16; when Decoded_Store => if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(nos); stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when Decoded_Load | Decoded_Loadb | Decoded_StoreB => --w.tos_save := exr.tos; -- Byte select instruction_executed := '0'; wroteback := wroteback_q; -- Keep WB if exr.tos(wordSize-1)='1' then stack_a_addr<=std_logic_vector(exr.tos(10 downto 2)); stack_a_enable<='1'; w.state := State_LoadStack; else stack_a_enable <= '0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); w.wb_we :='0'; w.wb_cyc :='1'; w.wb_stb :='1'; w.state := State_Load; end if; when Decoded_PopSP => decode_load_sp <= '1'; instruction_executed := '0'; stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); w.state := State_Resync2; --when Decoded_Break => -- w.break := '1'; when Decoded_Neqbranch => instruction_executed := '0'; w.state := State_NeqBranch; when others => end case; else -- freeze_all -- -- Freeze the entire pipeline. -- exu_busy<='1'; stack_a_enable<='0'; stack_b_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); end if; end if; -- valid when State_Ashiftleft => exu_busy <= '1'; lshifter_enable <= '1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_Mult => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_MultF16 => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(47 downto 16)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_WaitSPB => instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Store => exu_busy <= '1'; -- Keep writeback flag wroteback := wroteback_q; if wb_ack_i='1' then stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; stack_b_enable<='1'; wroteback := '0'; --exu_busy <= '1'; w.wb_cyc := '0'; w.state := State_Resync2; else stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_a_enable<='0'; stack_b_enable<='0'; end if; when State_Loadb => w.tos(wordSize-1 downto 8) := (others => '0'); case exr.tos_save(1 downto 0) is when "11" => w.tos(7 downto 0) := unsigned(exr.tos(7 downto 0)); when "10" => w.tos(7 downto 0) := unsigned(exr.tos(15 downto 8)); when "01" => w.tos(7 downto 0) := unsigned(exr.tos(23 downto 16)); when "00" => w.tos(7 downto 0) := unsigned(exr.tos(31 downto 24)); when others => null; end case; instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Load => if wb_ack_i='0' then exu_busy<='1'; else w.tos := unsigned(wb_dat_i); w.wb_cyc := '0'; if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state := State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state := State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; end if; when State_LoadStack => w.tos := unsigned(stack_a_read); if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state:=State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state:=State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; when State_NeqBranch => if exr.nos_save/=0 then decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0) + prefr.pc; poppc_inst <= '1'; exu_busy <= '0'; else exu_busy <='1'; end if; instruction_executed := '0'; stack_a_addr <= std_logic_vector(prefr.spnext); wroteback:='0'; w.state := State_Resync2; when State_StoreB => exu_busy <= '1'; -- -- At this point, we have loaded the 32-bit, and it's in TOS -- The IO address is still saved in save_TOS. -- The original write value is still at save_NOS -- -- So we mangle the write value, and update save_NOS, and restore -- the IO address to TOS -- -- This is still buggy - don't use. Problems arise when writing to stack. -- w.nos_save := exr.tos; case exr.tos_save(1 downto 0) is when "00" => w.nos_save(31 downto 24) := exr.nos_save(7 downto 0); when "01" => w.nos_save(23 downto 16) := exr.nos_save(7 downto 0); when "10" => w.nos_save(15 downto 8) := exr.nos_save(7 downto 0); when "11" => w.nos_save(7 downto 0) := exr.nos_save(7 downto 0); when others => null; end case; w.tos := exr.tos_save; w.state := State_StoreB2; when State_StoreB2 => exu_busy <= '1'; if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(exr.nos_save); -- hmm I don't like this stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when others => null; end case; if rising_edge(wb_clk_i) then if wb_rst_i='1' then exr.state <= State_Execute; exr.idim <= DontCareValue; exr.inInterrupt <= '0'; exr.break <= '0'; exr.wb_cyc <= '0'; exr.wb_stb <= '1'; else exr <= w; -- TODO: move wroteback_q into EXU regs wroteback_q <= wroteback; if exr.break='1' then report "BREAK" severity failure; end if; -- Some sanity checks, to be caught in simulation if prefr.valid='1' then if prefr.tosSource=Tos_Source_Idim0 and prefr.idim='1' then report "Invalid IDIM flag 0" severity error; end if; if prefr.tosSource=Tos_Source_IdimN and prefr.idim='0' then report "Invalid IDIM flag 1" severity error; end if; end if; end if; end if; end process; single_step <= dbg_in.step; dbg_out.valid <= '1' when prefr.valid='1' else '0'; -- Let pipeline finish dbg_out.ready <= '1' when exr.state=state_execute and decode_load_sp='0' and decode_jump='0' and decr.state = State_Inject --and jump_q='0' else '0'; end behave;
-- ZPU -- -- Copyright 2004-2008 oharboe - Øyvind Harboe - [email protected] -- Copyright 2010-2012 Alvaro Lopes - [email protected] -- -- The FreeBSD license -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions -- are met: -- -- 1. Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer. -- 2. Redistributions in binary form must reproduce the above -- copyright notice, this list of conditions and the following -- disclaimer in the documentation and/or other materials -- provided with the distribution. -- -- THIS SOFTWARE IS PROVIDED BY THE ZPU PROJECT ``AS IS'' AND ANY -- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -- ZPU PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- The views and conclusions contained in the software and documentation -- are those of the authors and should not be interpreted as representing -- official policies, either expressed or implied, of the ZPU Project. library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.numeric_std.all; library board; use board.zpu_config.all; use board.zpupkg.all; use board.wishbonepkg.all; --library UNISIM; --use UNISIM.vcomponents.all; entity zpu_core_extreme is port ( wb_clk_i: in std_logic; wb_rst_i: in std_logic; -- Master wishbone interface wb_ack_i: in std_logic; wb_dat_i: in std_logic_vector(wordSize-1 downto 0); wb_dat_o: out std_logic_vector(wordSize-1 downto 0); wb_adr_o: out std_logic_vector(maxAddrBitIncIO downto 0); wb_cyc_o: out std_logic; wb_stb_o: out std_logic; wb_we_o: out std_logic; wb_inta_i: in std_logic; poppc_inst: out std_logic; break: out std_logic; -- STACK stack_a_read: in std_logic_vector(wordSize-1 downto 0); stack_b_read: in std_logic_vector(wordSize-1 downto 0); stack_a_write: out std_logic_vector(wordSize-1 downto 0); stack_b_write: out std_logic_vector(wordSize-1 downto 0); stack_a_writeenable: out std_logic; stack_a_enable: out std_logic; stack_b_writeenable: out std_logic; stack_b_enable: out std_logic; stack_a_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_b_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_clk: out std_logic; -- ROM wb interface rom_wb_ack_i: in std_logic; rom_wb_dat_i: in std_logic_vector(wordSize-1 downto 0); rom_wb_adr_o: out std_logic_vector(maxAddrBit downto 0); rom_wb_cyc_o: out std_logic; rom_wb_stb_o: out std_logic; rom_wb_cti_o: out std_logic_vector(2 downto 0); rom_wb_stall_i: in std_logic; -- Debug interface dbg_out: out zpu_dbg_out_type; dbg_in: in zpu_dbg_in_type ); end zpu_core_extreme; architecture behave of zpu_core_extreme is component lshifter is port ( clk: in std_logic; rst: in std_logic; enable: in std_logic; done: out std_logic; inputA: in std_logic_vector(31 downto 0); inputB: in std_logic_vector(31 downto 0); output: out std_logic_vector(63 downto 0); multorshift: in std_logic ); end component; signal lshifter_enable: std_logic; signal lshifter_done: std_logic; signal lshifter_input: std_logic_vector(31 downto 0); signal lshifter_amount: std_logic_vector(31 downto 0); signal lshifter_output: std_logic_vector(63 downto 0); signal lshifter_multorshift: std_logic; signal begin_inst: std_logic; signal trace_opcode: std_logic_vector(7 downto 0); signal trace_pc: std_logic_vector(maxAddrBitIncIO downto 0); signal trace_sp: std_logic_vector(maxAddrBitIncIO downto minAddrBit); signal trace_topOfStack: std_logic_vector(wordSize-1 downto 0); signal trace_topOfStackB: std_logic_vector(wordSize-1 downto 0); -- state machine. type State_Type is ( State_Execute, State_Store, State_StoreB, State_StoreB2, State_Load, State_LoadMemory, State_LoadStack, State_Loadb, State_Resync1, State_Resync2, State_LoadSP, State_WaitSPB, State_ResyncFromStoreStack, State_Neqbranch, State_Ashiftleft, State_Mult, State_MultF16 ); type DecodedOpcodeType is ( Decoded_Nop, Decoded_Idle, Decoded_Im0, Decoded_ImN, Decoded_LoadSP, Decoded_Dup, Decoded_DupStackB, Decoded_StoreSP, Decoded_Pop, Decoded_PopDown, Decoded_AddSP, Decoded_AddStackB, Decoded_Shift, Decoded_Emulate, Decoded_Break, Decoded_PushSP, Decoded_PopPC, Decoded_Add, Decoded_Or, Decoded_And, Decoded_Load, Decoded_Not, Decoded_Flip, Decoded_Store, Decoded_PopSP, Decoded_Interrupt, Decoded_Neqbranch, Decoded_Eq, Decoded_Storeb, Decoded_Storeh, Decoded_Ulessthan, Decoded_Lessthan, Decoded_Ashiftleft, Decoded_Ashiftright, Decoded_Loadb, Decoded_Call, Decoded_Mult, Decoded_MultF16 ); constant spMaxBit: integer := 10; constant minimal_implementation: boolean := false; subtype index is integer range 0 to 3; signal tOpcode_sel : index; function pc_to_cpuword(pc: unsigned) return unsigned is variable r: unsigned(wordSize-1 downto 0); begin r := (others => DontCareValue); r(maxAddrBit downto 0) := pc; return r; end pc_to_cpuword; function pc_to_memaddr(pc: unsigned) return unsigned is variable r: unsigned(maxAddrBit downto 0); begin r := (others => '0'); r(maxAddrBit downto minAddrBit) := pc(maxAddrBit downto minAddrBit); return r; end pc_to_memaddr; -- Prefetch stage registers type stackChangeType is ( Stack_Same, Stack_Push, Stack_Pop, Stack_DualPop ); type tosSourceType is ( Tos_Source_PC, Tos_Source_FetchPC, Tos_Source_Idim0, Tos_Source_IdimN, Tos_Source_StackB, Tos_Source_SP, Tos_Source_Add, Tos_Source_And, Tos_Source_Or, Tos_Source_Eq, Tos_Source_Not, Tos_Source_Flip, Tos_Source_LoadSP, Tos_Source_AddSP, Tos_Source_AddStackB, Tos_Source_Shift, Tos_Source_Ulessthan, Tos_Source_Lessthan, Tos_Source_None ); type decoderstate_type is ( State_Run, State_Jump, State_Inject, State_InjectJump ); type decoderegs_type is record valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opWillFreeze: std_logic; -- '1' if we know in advance this opcode will freeze pipeline opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); pcint: unsigned(maxAddrBit downto 0); idim: std_logic; im: std_logic; stackOperation: stackChangeType; spOffset: unsigned(4 downto 0); im_emu: std_logic; --emumode: std_logic; break: std_logic; state: decoderstate_type; end record; type prefetchregs_type is record sp: unsigned(spMaxBit downto 2); spnext: unsigned(spMaxBit downto 2); valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); idim: std_logic; break: std_logic; load: std_logic; opWillFreeze: std_logic; recompute_sp: std_logic; end record; type exuregs_type is record idim: std_logic; break: std_logic; inInterrupt:std_logic; tos: unsigned(wordSize-1 downto 0); tos_save: unsigned(wordSize-1 downto 0); nos_save: unsigned(wordSize-1 downto 0); state: State_Type; -- Wishbone control signals (registered) wb_cyc: std_logic; wb_stb: std_logic; wb_we: std_logic; end record; -- Registers for each stage signal exr: exuregs_type; signal prefr: prefetchregs_type; signal decr: decoderegs_type; signal pcnext: unsigned(maxAddrBit downto 0); -- Helper only. TODO: move into variable signal sp_load: unsigned(spMaxBit downto 2); -- SP value to load, coming from EXU into PFU signal decode_load_sp: std_logic; -- Load SP signal from EXU to PFU signal exu_busy: std_logic; -- EXU busy ( stalls PFU ) signal pfu_busy: std_logic; -- PFU busy ( stalls DFU ) signal decode_jump: std_logic; -- Jump signal from EXU to DFU signal jump_address: unsigned(maxAddrBit downto 0); -- Jump address from EXU to DFU signal do_interrupt: std_logic; -- Helper. -- Sampled signals from the opcode. Left as signals -- in order to simulate design. signal sampledOpcode: std_logic_vector(OpCode_Size-1 downto 0); signal sampledDecodedOpcode: DecodedOpcodeType; signal sampledOpWillFreeze: std_logic; signal sampledStackOperation: stackChangeType; signal sampledspOffset: unsigned(4 downto 0); signal sampledTosSource: tosSourceType; signal nos: unsigned(wordSize-1 downto 0); -- This is only a helper signal wroteback_q: std_logic; -- TODO: get rid of this here, move to EXU regs -- Test debug signals signal freeze_all: std_logic := '0'; signal single_step: std_logic := '0'; begin -- Debug interface dbg_out.pc <= std_logic_vector(prefr.pc); dbg_out.opcode <= prefr.opcode; dbg_out.sp <= std_logic_vector(prefr.sp); dbg_out.brk <= exr.break; dbg_out.stacka <= std_logic_vector(exr.tos); dbg_out.stackb <= std_logic_vector(nos); dbg_out.idim <= prefr.idim; shl: lshifter port map ( clk => wb_clk_i, rst => wb_rst_i, enable => lshifter_enable, done => lshifter_done, inputA => lshifter_input, inputB => lshifter_amount, output => lshifter_output, multorshift => lshifter_multorshift ); stack_clk <= wb_clk_i; traceFileGenerate: if Generate_Trace generate trace_file: trace port map ( clk => wb_clk_i, begin_inst => begin_inst, pc => trace_pc, opcode => trace_opcode, sp => trace_sp, memA => trace_topOfStack, memB => trace_topOfStackB, busy => '0',--busy, intsp => (others => 'U') ); end generate; tOpcode_sel <= to_integer(decr.pcint(minAddrBit-1 downto 0)); do_interrupt <= '1' when wb_inta_i='1' and exr.inInterrupt='0' else '0'; decodeControl: process(rom_wb_dat_i, tOpcode_sel, sp_load, decr, do_interrupt, dbg_in.inject, dbg_in.opcode) variable tOpcode : std_logic_vector(OpCode_Size-1 downto 0); variable localspOffset: unsigned(4 downto 0); begin if dbg_in.inject='1' then tOpcode := dbg_in.opcode; else case (tOpcode_sel) is when 0 => tOpcode := std_logic_vector(rom_wb_dat_i(31 downto 24)); when 1 => tOpcode := std_logic_vector(rom_wb_dat_i(23 downto 16)); when 2 => tOpcode := std_logic_vector(rom_wb_dat_i(15 downto 8)); when 3 => tOpcode := std_logic_vector(rom_wb_dat_i(7 downto 0)); when others => null; end case; end if; sampledOpcode <= tOpcode; sampledStackOperation <= Stack_Same; sampledTosSource <= Tos_Source_None; sampledOpWillFreeze <= '0'; localspOffset(4):=not tOpcode(4); localspOffset(3 downto 0) := unsigned(tOpcode(3 downto 0)); if do_interrupt='1' and decr.im='0' then sampledDecodedOpcode <= Decoded_Interrupt; sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_PC; else if (tOpcode(7 downto 7)=OpCode_Im) then if decr.im='0' then sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_Idim0; sampledDecodedOpcode<=Decoded_Im0; else sampledTosSource <= Tos_Source_IdimN; sampledDecodedOpcode<=Decoded_ImN; end if; elsif (tOpcode(7 downto 5)=OpCode_StoreSP) then sampledStackOperation <= Stack_Pop; sampledTosSource <= Tos_Source_StackB; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Pop; sampledTosSource <= Tos_Source_StackB; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_PopDown; sampledTosSource <= Tos_Source_None; else sampledDecodedOpcode<=Decoded_StoreSP; sampledOpWillFreeze<='1'; sampledTosSource <= Tos_Source_StackB; end if; elsif (tOpcode(7 downto 5)=OpCode_LoadSP) then sampledStackOperation <= Stack_Push; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Dup; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_DupStackB; sampledTosSource <= Tos_Source_StackB; else sampledDecodedOpcode<=Decoded_LoadSP; sampledTosSource <= Tos_Source_LoadSP; end if; elsif (tOpcode(7 downto 5)=OpCode_Emulate) then -- Emulated instructions implemented in hardware if minimal_implementation then sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; else if (tOpcode(5 downto 0)=OpCode_Loadb) then sampledStackOperation<=Stack_Same; sampledDecodedOpcode<=Decoded_Loadb; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Neqbranch) then sampledStackOperation<=Stack_DualPop; sampledDecodedOpcode<=Decoded_Neqbranch; sampledOpWillFreeze <= '1'; elsif (tOpcode(5 downto 0)=OpCode_Call) then sampledDecodedOpcode<=Decoded_Call; sampledStackOperation<=Stack_Same; sampledTosSource<=Tos_Source_FetchPC; elsif (tOpcode(5 downto 0)=OpCode_Eq) then sampledDecodedOpcode<=Decoded_Eq; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Eq; elsif (tOpcode(5 downto 0)=OpCode_Ulessthan) then sampledDecodedOpcode<=Decoded_Ulessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Ulessthan; elsif (tOpcode(5 downto 0)=OpCode_Lessthan) then sampledDecodedOpcode<=Decoded_Lessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Lessthan; elsif (tOpcode(5 downto 0)=OpCode_StoreB) then sampledDecodedOpcode<=Decoded_StoreB; sampledStackOperation<=Stack_DualPop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Mult) then sampledDecodedOpcode<=Decoded_Mult; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Ashiftleft) then sampledDecodedOpcode<=Decoded_Ashiftleft; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; end if; end if; elsif (tOpcode(7 downto 4)=OpCode_AddSP) then if localspOffset=0 then sampledDecodedOpcode<=Decoded_Shift; sampledTosSource <= Tos_Source_Shift; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_AddStackB; sampledTosSource <= Tos_Source_AddStackB; else sampledDecodedOpcode<=Decoded_AddSP; sampledTosSource <= Tos_Source_AddSP; end if; else case tOpcode(3 downto 0) is when OpCode_Break => sampledDecodedOpcode<=Decoded_Break; sampledOpWillFreeze <= '1'; when OpCode_PushSP => sampledStackOperation <= Stack_Push; sampledDecodedOpcode<=Decoded_PushSP; sampledTosSource <= Tos_Source_SP; when OpCode_PopPC => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_PopPC; sampledTosSource <= Tos_Source_StackB; when OpCode_Add => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Add; sampledTosSource <= Tos_Source_Add; when OpCode_Or => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Or; sampledTosSource <= Tos_Source_Or; when OpCode_And => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_And; sampledTosSource <= Tos_Source_And; when OpCode_Load => sampledDecodedOpcode<=Decoded_Load; sampledOpWillFreeze<='1'; when OpCode_Not => sampledDecodedOpcode<=Decoded_Not; sampledTosSource <= Tos_Source_Not; when OpCode_Flip => sampledDecodedOpcode<=Decoded_Flip; sampledTosSource <= Tos_Source_Flip; when OpCode_Store => sampledStackOperation <= Stack_DualPop; sampledDecodedOpcode<=Decoded_Store; sampledOpWillFreeze<='1'; when OpCode_PopSP => sampledDecodedOpcode<=Decoded_PopSP; sampledOpWillFreeze<='1'; when OpCode_NA4 => if enable_fmul16 then sampledDecodedOpcode<=Decoded_MultF16; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Nop; end if; when others => sampledDecodedOpcode<=Decoded_Nop; end case; end if; end if; sampledspOffset <= localspOffset; end process; -- Decode/Fetch unit rom_wb_stb_o <= not exu_busy; process(decr, jump_address, decode_jump, wb_clk_i, sp_load, sampledDecodedOpcode,sampledOpcode,decode_load_sp, exu_busy, pfu_busy, pcnext, rom_wb_ack_i, wb_rst_i, sampledStackOperation, sampledspOffset, sampledTosSource, prefr.recompute_sp, sampledOpWillFreeze, dbg_in.flush, dbg_in.inject,dbg_in.injectmode, prefr.valid, prefr.break, rom_wb_stall_i ) variable w: decoderegs_type; begin w := decr; pcnext <= decr.fetchpc + 1; rom_wb_adr_o <= std_logic_vector(pc_to_memaddr(decr.fetchpc)); rom_wb_cti_o <= CTI_CYCLE_INCRADDR; if wb_rst_i='1' then w.pc := (others => '0'); w.pcint := (others => '0'); w.valid := '0'; w.fetchpc := (others => '0'); w.im:='0'; w.im_emu:='0'; w.state := State_Run; w.break := '0'; rom_wb_cyc_o <= '0'; else rom_wb_cyc_o <= '1'; case decr.state is when State_Run => if pfu_busy='0' then if dbg_in.injectmode='0' and decr.break='0' and rom_wb_stall_i='0' then w.fetchpc := pcnext; end if; -- Jump request if decode_jump='1' then w.valid := '0'; w.im := '0'; w.break := '0'; -- Invalidate eventual break after branch instruction --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o<='0'; --if rom_wb_stall_i='0' then w.fetchpc := jump_address; --else w.state := State_Jump; --end if; else if dbg_in.injectmode='1' then --or decr.break='1' then -- At this point we ought to push a new op into the pipeline. -- Since we're entering inject mode, invalidate next operation, -- but save the current IM flag. w.im_emu := decr.im; w.valid := '0'; --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o <='0'; -- Wait until no work is to be done if prefr.valid='0' and decr.valid='0' and exu_busy='0' then w.state := State_Inject; w.im:='0'; end if; if decr.break='0' then w.pc := decr.pcint; end if; else if decr.break='1' then w.valid := '0'; else w.valid := rom_wb_ack_i; end if; if rom_wb_ack_i='1' then w.im := sampledOpcode(7); if sampledDecodedOpcode=Decoded_Break then w.break:='1'; end if; end if; if prefr.break='0' and rom_wb_stall_i='0' then w.pcint := decr.fetchpc; w.pc := decr.pcint; end if; if rom_wb_stall_i='0' then w.opcode := sampledOpcode; end if; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; when State_Jump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Run; when State_InjectJump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Inject; when State_Inject => -- NOTE: disable ROM rom_wb_cyc_o <= '0'; if dbg_in.injectmode='0' then w.im := decr.im_emu; w.fetchpc := decr.pcint; w.state := State_Run; w.break := '0'; else -- Handle opcode injection -- TODO: merge this with main decode. -- NOTE: we don't check busy here, it's up to debug unit to do it --if pfu_busy='0' then --w.fetchpc := pcnext; -- Jump request if decode_jump='1' then w.fetchpc := jump_address; w.valid := '0'; w.im := '0'; w.state := State_InjectJump; else w.valid := dbg_in.inject; if dbg_in.inject='1' then w.im := sampledOpcode(7); --w.break := '0'; --w.pcint := decr.fetchpc; w.opcode := sampledOpcode; --w.pc := decr.pcint; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; --end if; end case; end if; -- rst if rising_edge(wb_clk_i) then decr <= w; end if; end process; -- Prefetch/Load unit. sp_load <= exr.tos(spMaxBit downto 2); -- Will be delayed one clock cycle process(wb_clk_i, wb_rst_i, decr, prefr, exu_busy, decode_jump, sp_load, decode_load_sp, dbg_in.flush) variable w: prefetchregs_type; variable i_op_freeze: std_logic; begin w := prefr; pfu_busy<='0'; stack_b_addr <= std_logic_vector(prefr.spnext + 1); w.recompute_sp:='0'; -- Stack w.load := decode_load_sp; if decode_load_sp='1' then pfu_busy <= '1'; w.spnext := sp_load; w.recompute_sp := '1'; else pfu_busy <= exu_busy; if decr.valid='1' then if (exu_busy='0' and decode_jump='0') or prefr.recompute_sp='1' then case decr.stackOperation is when Stack_Push => w.spnext := prefr.spnext - 1; when Stack_Pop => w.spnext := prefr.spnext + 1; when Stack_DualPop => w.spnext := prefr.spnext + 2; when others => end case; w.sp := prefr.spnext; end if; end if; end if; case decr.decodedOpcode is when Decoded_LoadSP | decoded_AddSP => stack_b_addr <= std_logic_vector(prefr.spnext + decr.spOffset); when others => end case; if decode_jump='1' then -- this is a pipeline "invalidate" flag. w.valid := '0'; else if dbg_in.flush='1' then w.valid := '0'; else w.valid := decr.valid; end if; end if; -- Moved op_will_freeze from decoder to here case decr.decodedOpcode is when Decoded_StoreSP | Decoded_LoadB | Decoded_Neqbranch | Decoded_StoreB | Decoded_Mult | Decoded_Ashiftleft | Decoded_Break | Decoded_Load | Decoded_Store | Decoded_PopSP | Decoded_MultF16 => i_op_freeze := '1'; when others => i_op_freeze := '0'; end case; if exu_busy='0' then w.decodedOpcode := decr.decodedOpcode; w.tosSource := decr.tosSource; w.opcode := decr.opcode; w.opWillFreeze := i_op_freeze; w.pc := decr.pc; w.fetchpc := decr.pcint; w.idim := decr.idim; w.break := decr.break; end if; if wb_rst_i='1' then w.spnext := unsigned(spStart(10 downto 2)); --w.sp := unsigned(spStart(10 downto 2)); w.valid := '0'; w.idim := '0'; w.recompute_sp:='0'; end if; if rising_edge(wb_clk_i) then prefr <= w; end if; end process; process(prefr,exr,nos) begin trace_pc <= (others => '0'); trace_pc(maxAddrBit downto 0) <= std_logic_vector(prefr.pc); trace_opcode <= prefr.opcode; trace_sp <= (others => '0'); trace_sp(10 downto 2) <= std_logic_vector(prefr.sp); trace_topOfStack <= std_logic_vector( exr.tos ); trace_topOfStackB <= std_logic_vector( nos ); end process; -- IO/Memory Accesses wb_adr_o(maxAddrBitIncIO downto 0) <= std_logic_vector(exr.tos_save(maxAddrBitIncIO downto 0)); wb_cyc_o <= exr.wb_cyc; wb_stb_o <= exr.wb_stb; wb_we_o <= exr.wb_we; wb_dat_o <= std_logic_vector( exr.nos_save ); freeze_all <= dbg_in.freeze; process(exr, wb_inta_i, wb_clk_i, wb_rst_i, pcnext, stack_a_read,stack_b_read, wb_ack_i, wb_dat_i, do_interrupt,exr, prefr, nos, single_step, freeze_all, dbg_in.step, wroteback_q,lshifter_done,lshifter_output ) variable spOffset: unsigned(4 downto 0); variable w: exuregs_type; variable instruction_executed: std_logic; variable wroteback: std_logic; begin w := exr; instruction_executed := '0'; -- used for single stepping stack_b_writeenable <= '0'; stack_a_enable <= '1'; stack_b_enable <= '1'; exu_busy <= '0'; decode_jump <= '0'; jump_address <= (others => DontCareValue); lshifter_enable <= '0'; lshifter_amount <= std_logic_vector(exr.tos_save); lshifter_input <= std_logic_vector(exr.nos_save); lshifter_multorshift <= '0'; poppc_inst <= '0'; begin_inst<='0'; stack_a_addr <= std_logic_vector( prefr.sp ); stack_a_writeenable <= '0'; wroteback := wroteback_q; stack_b_writeenable <= '0'; stack_a_write <= std_logic_vector(exr.tos); spOffset(4):=not prefr.opcode(4); spOffset(3 downto 0) := unsigned(prefr.opcode(3 downto 0)); if wb_inta_i='0' then w.inInterrupt := '0'; end if; stack_b_write<=(others => DontCareValue); if wroteback_q='1' then nos <= unsigned(stack_a_read); else nos <= unsigned(stack_b_read); end if; decode_load_sp <= '0'; case exr.state is when State_Resync1 => exu_busy <= '1'; stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_ResyncFromStoreStack => exu_busy <= '1'; stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_Resync2 => w.tos := unsigned(stack_a_read); instruction_executed := '1'; exu_busy <= '0'; wroteback := '0'; stack_b_enable <= '1'; w.state := State_Execute; when State_Execute => instruction_executed:='0'; if prefr.valid='1' then exu_busy <= prefr.opWillFreeze; if freeze_all='0' or single_step='1' then wroteback := '0'; w.nos_save := nos; w.tos_save := exr.tos; w.idim := prefr.idim; w.break:= prefr.break; begin_inst<='1'; instruction_executed := '1'; -- TOS big muxer case prefr.tosSource is when Tos_Source_PC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.pc; when Tos_Source_FetchPC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.fetchpc; when Tos_Source_Idim0 => for i in wordSize-1 downto 7 loop w.tos(i) := prefr.opcode(6); end loop; w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_IdimN => w.tos(wordSize-1 downto 7) := exr.tos(wordSize-8 downto 0); w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_StackB => w.tos := nos; when Tos_Source_SP => w.tos := (others => '0'); w.tos(31) := '1'; -- Stack address w.tos(10 downto 2) := prefr.sp; when Tos_Source_Add => w.tos := exr.tos + nos; when Tos_Source_And => w.tos := exr.tos and nos; when Tos_Source_Or => w.tos := exr.tos or nos; when Tos_Source_Eq => w.tos := (others => '0'); if nos = exr.tos then w.tos(0) := '1'; end if; when Tos_Source_Ulessthan => w.tos := (others => '0'); if exr.tos < nos then w.tos(0) := '1'; end if; when Tos_Source_Lessthan => w.tos := (others => '0'); if signed(exr.tos) < signed(nos) then w.tos(0) := '1'; end if; when Tos_Source_Not => w.tos := not exr.tos; when Tos_Source_Flip => for i in 0 to wordSize-1 loop w.tos(i) := exr.tos(wordSize-1-i); end loop; when Tos_Source_LoadSP => w.tos := unsigned(stack_b_read); when Tos_Source_AddSP => w.tos := w.tos + unsigned(stack_b_read); when Tos_Source_AddStackB => w.tos := w.tos + nos; when Tos_Source_Shift => w.tos := exr.tos + exr.tos; when others => end case; case prefr.decodedOpcode is when Decoded_Interrupt => w.inInterrupt := '1'; jump_address <= to_unsigned(32, maxAddrBit+1); decode_jump <= '1'; stack_a_writeenable<='1'; wroteback:='1'; stack_b_enable<='0'; instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Im0 => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_ImN => when Decoded_Nop => when Decoded_PopPC | Decoded_Call => decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0); poppc_inst <= '1'; stack_b_enable<='0'; -- Delay instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Emulate => decode_jump <= '1'; jump_address <= (others => '0'); jump_address(9 downto 5) <= unsigned(prefr.opcode(4 downto 0)); stack_a_writeenable<='1'; wroteback:='1'; when Decoded_PushSP => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_LoadSP => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_DupStackB => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_Dup => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_AddSP => stack_a_writeenable <= '1'; when Decoded_StoreSP => stack_a_writeenable <= '1'; wroteback:='1'; stack_a_addr <= std_logic_vector(prefr.sp + spOffset); instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_PopDown => stack_a_writeenable<='1'; when Decoded_Pop => when Decoded_Ashiftleft => w.state := State_Ashiftleft; when Decoded_Mult => w.state := State_Mult; when Decoded_MultF16 => w.state := State_MultF16; when Decoded_Store => if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(nos); stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when Decoded_Load | Decoded_Loadb | Decoded_StoreB => --w.tos_save := exr.tos; -- Byte select instruction_executed := '0'; wroteback := wroteback_q; -- Keep WB if exr.tos(wordSize-1)='1' then stack_a_addr<=std_logic_vector(exr.tos(10 downto 2)); stack_a_enable<='1'; w.state := State_LoadStack; else stack_a_enable <= '0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); w.wb_we :='0'; w.wb_cyc :='1'; w.wb_stb :='1'; w.state := State_Load; end if; when Decoded_PopSP => decode_load_sp <= '1'; instruction_executed := '0'; stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); w.state := State_Resync2; --when Decoded_Break => -- w.break := '1'; when Decoded_Neqbranch => instruction_executed := '0'; w.state := State_NeqBranch; when others => end case; else -- freeze_all -- -- Freeze the entire pipeline. -- exu_busy<='1'; stack_a_enable<='0'; stack_b_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); end if; end if; -- valid when State_Ashiftleft => exu_busy <= '1'; lshifter_enable <= '1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_Mult => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_MultF16 => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(47 downto 16)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_WaitSPB => instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Store => exu_busy <= '1'; -- Keep writeback flag wroteback := wroteback_q; if wb_ack_i='1' then stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; stack_b_enable<='1'; wroteback := '0'; --exu_busy <= '1'; w.wb_cyc := '0'; w.state := State_Resync2; else stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_a_enable<='0'; stack_b_enable<='0'; end if; when State_Loadb => w.tos(wordSize-1 downto 8) := (others => '0'); case exr.tos_save(1 downto 0) is when "11" => w.tos(7 downto 0) := unsigned(exr.tos(7 downto 0)); when "10" => w.tos(7 downto 0) := unsigned(exr.tos(15 downto 8)); when "01" => w.tos(7 downto 0) := unsigned(exr.tos(23 downto 16)); when "00" => w.tos(7 downto 0) := unsigned(exr.tos(31 downto 24)); when others => null; end case; instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Load => if wb_ack_i='0' then exu_busy<='1'; else w.tos := unsigned(wb_dat_i); w.wb_cyc := '0'; if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state := State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state := State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; end if; when State_LoadStack => w.tos := unsigned(stack_a_read); if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state:=State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state:=State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; when State_NeqBranch => if exr.nos_save/=0 then decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0) + prefr.pc; poppc_inst <= '1'; exu_busy <= '0'; else exu_busy <='1'; end if; instruction_executed := '0'; stack_a_addr <= std_logic_vector(prefr.spnext); wroteback:='0'; w.state := State_Resync2; when State_StoreB => exu_busy <= '1'; -- -- At this point, we have loaded the 32-bit, and it's in TOS -- The IO address is still saved in save_TOS. -- The original write value is still at save_NOS -- -- So we mangle the write value, and update save_NOS, and restore -- the IO address to TOS -- -- This is still buggy - don't use. Problems arise when writing to stack. -- w.nos_save := exr.tos; case exr.tos_save(1 downto 0) is when "00" => w.nos_save(31 downto 24) := exr.nos_save(7 downto 0); when "01" => w.nos_save(23 downto 16) := exr.nos_save(7 downto 0); when "10" => w.nos_save(15 downto 8) := exr.nos_save(7 downto 0); when "11" => w.nos_save(7 downto 0) := exr.nos_save(7 downto 0); when others => null; end case; w.tos := exr.tos_save; w.state := State_StoreB2; when State_StoreB2 => exu_busy <= '1'; if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(exr.nos_save); -- hmm I don't like this stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when others => null; end case; if rising_edge(wb_clk_i) then if wb_rst_i='1' then exr.state <= State_Execute; exr.idim <= DontCareValue; exr.inInterrupt <= '0'; exr.break <= '0'; exr.wb_cyc <= '0'; exr.wb_stb <= '1'; else exr <= w; -- TODO: move wroteback_q into EXU regs wroteback_q <= wroteback; if exr.break='1' then report "BREAK" severity failure; end if; -- Some sanity checks, to be caught in simulation if prefr.valid='1' then if prefr.tosSource=Tos_Source_Idim0 and prefr.idim='1' then report "Invalid IDIM flag 0" severity error; end if; if prefr.tosSource=Tos_Source_IdimN and prefr.idim='0' then report "Invalid IDIM flag 1" severity error; end if; end if; end if; end if; end process; single_step <= dbg_in.step; dbg_out.valid <= '1' when prefr.valid='1' else '0'; -- Let pipeline finish dbg_out.ready <= '1' when exr.state=state_execute and decode_load_sp='0' and decode_jump='0' and decr.state = State_Inject --and jump_q='0' else '0'; end behave;
-- ZPU -- -- Copyright 2004-2008 oharboe - Øyvind Harboe - [email protected] -- Copyright 2010-2012 Alvaro Lopes - [email protected] -- -- The FreeBSD license -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions -- are met: -- -- 1. Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer. -- 2. Redistributions in binary form must reproduce the above -- copyright notice, this list of conditions and the following -- disclaimer in the documentation and/or other materials -- provided with the distribution. -- -- THIS SOFTWARE IS PROVIDED BY THE ZPU PROJECT ``AS IS'' AND ANY -- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -- ZPU PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- The views and conclusions contained in the software and documentation -- are those of the authors and should not be interpreted as representing -- official policies, either expressed or implied, of the ZPU Project. library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.numeric_std.all; library board; use board.zpu_config.all; use board.zpupkg.all; use board.wishbonepkg.all; --library UNISIM; --use UNISIM.vcomponents.all; entity zpu_core_extreme is port ( wb_clk_i: in std_logic; wb_rst_i: in std_logic; -- Master wishbone interface wb_ack_i: in std_logic; wb_dat_i: in std_logic_vector(wordSize-1 downto 0); wb_dat_o: out std_logic_vector(wordSize-1 downto 0); wb_adr_o: out std_logic_vector(maxAddrBitIncIO downto 0); wb_cyc_o: out std_logic; wb_stb_o: out std_logic; wb_we_o: out std_logic; wb_inta_i: in std_logic; poppc_inst: out std_logic; break: out std_logic; -- STACK stack_a_read: in std_logic_vector(wordSize-1 downto 0); stack_b_read: in std_logic_vector(wordSize-1 downto 0); stack_a_write: out std_logic_vector(wordSize-1 downto 0); stack_b_write: out std_logic_vector(wordSize-1 downto 0); stack_a_writeenable: out std_logic; stack_a_enable: out std_logic; stack_b_writeenable: out std_logic; stack_b_enable: out std_logic; stack_a_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_b_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_clk: out std_logic; -- ROM wb interface rom_wb_ack_i: in std_logic; rom_wb_dat_i: in std_logic_vector(wordSize-1 downto 0); rom_wb_adr_o: out std_logic_vector(maxAddrBit downto 0); rom_wb_cyc_o: out std_logic; rom_wb_stb_o: out std_logic; rom_wb_cti_o: out std_logic_vector(2 downto 0); rom_wb_stall_i: in std_logic; -- Debug interface dbg_out: out zpu_dbg_out_type; dbg_in: in zpu_dbg_in_type ); end zpu_core_extreme; architecture behave of zpu_core_extreme is component lshifter is port ( clk: in std_logic; rst: in std_logic; enable: in std_logic; done: out std_logic; inputA: in std_logic_vector(31 downto 0); inputB: in std_logic_vector(31 downto 0); output: out std_logic_vector(63 downto 0); multorshift: in std_logic ); end component; signal lshifter_enable: std_logic; signal lshifter_done: std_logic; signal lshifter_input: std_logic_vector(31 downto 0); signal lshifter_amount: std_logic_vector(31 downto 0); signal lshifter_output: std_logic_vector(63 downto 0); signal lshifter_multorshift: std_logic; signal begin_inst: std_logic; signal trace_opcode: std_logic_vector(7 downto 0); signal trace_pc: std_logic_vector(maxAddrBitIncIO downto 0); signal trace_sp: std_logic_vector(maxAddrBitIncIO downto minAddrBit); signal trace_topOfStack: std_logic_vector(wordSize-1 downto 0); signal trace_topOfStackB: std_logic_vector(wordSize-1 downto 0); -- state machine. type State_Type is ( State_Execute, State_Store, State_StoreB, State_StoreB2, State_Load, State_LoadMemory, State_LoadStack, State_Loadb, State_Resync1, State_Resync2, State_LoadSP, State_WaitSPB, State_ResyncFromStoreStack, State_Neqbranch, State_Ashiftleft, State_Mult, State_MultF16 ); type DecodedOpcodeType is ( Decoded_Nop, Decoded_Idle, Decoded_Im0, Decoded_ImN, Decoded_LoadSP, Decoded_Dup, Decoded_DupStackB, Decoded_StoreSP, Decoded_Pop, Decoded_PopDown, Decoded_AddSP, Decoded_AddStackB, Decoded_Shift, Decoded_Emulate, Decoded_Break, Decoded_PushSP, Decoded_PopPC, Decoded_Add, Decoded_Or, Decoded_And, Decoded_Load, Decoded_Not, Decoded_Flip, Decoded_Store, Decoded_PopSP, Decoded_Interrupt, Decoded_Neqbranch, Decoded_Eq, Decoded_Storeb, Decoded_Storeh, Decoded_Ulessthan, Decoded_Lessthan, Decoded_Ashiftleft, Decoded_Ashiftright, Decoded_Loadb, Decoded_Call, Decoded_Mult, Decoded_MultF16 ); constant spMaxBit: integer := 10; constant minimal_implementation: boolean := false; subtype index is integer range 0 to 3; signal tOpcode_sel : index; function pc_to_cpuword(pc: unsigned) return unsigned is variable r: unsigned(wordSize-1 downto 0); begin r := (others => DontCareValue); r(maxAddrBit downto 0) := pc; return r; end pc_to_cpuword; function pc_to_memaddr(pc: unsigned) return unsigned is variable r: unsigned(maxAddrBit downto 0); begin r := (others => '0'); r(maxAddrBit downto minAddrBit) := pc(maxAddrBit downto minAddrBit); return r; end pc_to_memaddr; -- Prefetch stage registers type stackChangeType is ( Stack_Same, Stack_Push, Stack_Pop, Stack_DualPop ); type tosSourceType is ( Tos_Source_PC, Tos_Source_FetchPC, Tos_Source_Idim0, Tos_Source_IdimN, Tos_Source_StackB, Tos_Source_SP, Tos_Source_Add, Tos_Source_And, Tos_Source_Or, Tos_Source_Eq, Tos_Source_Not, Tos_Source_Flip, Tos_Source_LoadSP, Tos_Source_AddSP, Tos_Source_AddStackB, Tos_Source_Shift, Tos_Source_Ulessthan, Tos_Source_Lessthan, Tos_Source_None ); type decoderstate_type is ( State_Run, State_Jump, State_Inject, State_InjectJump ); type decoderegs_type is record valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opWillFreeze: std_logic; -- '1' if we know in advance this opcode will freeze pipeline opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); pcint: unsigned(maxAddrBit downto 0); idim: std_logic; im: std_logic; stackOperation: stackChangeType; spOffset: unsigned(4 downto 0); im_emu: std_logic; --emumode: std_logic; break: std_logic; state: decoderstate_type; end record; type prefetchregs_type is record sp: unsigned(spMaxBit downto 2); spnext: unsigned(spMaxBit downto 2); valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); idim: std_logic; break: std_logic; load: std_logic; opWillFreeze: std_logic; recompute_sp: std_logic; end record; type exuregs_type is record idim: std_logic; break: std_logic; inInterrupt:std_logic; tos: unsigned(wordSize-1 downto 0); tos_save: unsigned(wordSize-1 downto 0); nos_save: unsigned(wordSize-1 downto 0); state: State_Type; -- Wishbone control signals (registered) wb_cyc: std_logic; wb_stb: std_logic; wb_we: std_logic; end record; -- Registers for each stage signal exr: exuregs_type; signal prefr: prefetchregs_type; signal decr: decoderegs_type; signal pcnext: unsigned(maxAddrBit downto 0); -- Helper only. TODO: move into variable signal sp_load: unsigned(spMaxBit downto 2); -- SP value to load, coming from EXU into PFU signal decode_load_sp: std_logic; -- Load SP signal from EXU to PFU signal exu_busy: std_logic; -- EXU busy ( stalls PFU ) signal pfu_busy: std_logic; -- PFU busy ( stalls DFU ) signal decode_jump: std_logic; -- Jump signal from EXU to DFU signal jump_address: unsigned(maxAddrBit downto 0); -- Jump address from EXU to DFU signal do_interrupt: std_logic; -- Helper. -- Sampled signals from the opcode. Left as signals -- in order to simulate design. signal sampledOpcode: std_logic_vector(OpCode_Size-1 downto 0); signal sampledDecodedOpcode: DecodedOpcodeType; signal sampledOpWillFreeze: std_logic; signal sampledStackOperation: stackChangeType; signal sampledspOffset: unsigned(4 downto 0); signal sampledTosSource: tosSourceType; signal nos: unsigned(wordSize-1 downto 0); -- This is only a helper signal wroteback_q: std_logic; -- TODO: get rid of this here, move to EXU regs -- Test debug signals signal freeze_all: std_logic := '0'; signal single_step: std_logic := '0'; begin -- Debug interface dbg_out.pc <= std_logic_vector(prefr.pc); dbg_out.opcode <= prefr.opcode; dbg_out.sp <= std_logic_vector(prefr.sp); dbg_out.brk <= exr.break; dbg_out.stacka <= std_logic_vector(exr.tos); dbg_out.stackb <= std_logic_vector(nos); dbg_out.idim <= prefr.idim; shl: lshifter port map ( clk => wb_clk_i, rst => wb_rst_i, enable => lshifter_enable, done => lshifter_done, inputA => lshifter_input, inputB => lshifter_amount, output => lshifter_output, multorshift => lshifter_multorshift ); stack_clk <= wb_clk_i; traceFileGenerate: if Generate_Trace generate trace_file: trace port map ( clk => wb_clk_i, begin_inst => begin_inst, pc => trace_pc, opcode => trace_opcode, sp => trace_sp, memA => trace_topOfStack, memB => trace_topOfStackB, busy => '0',--busy, intsp => (others => 'U') ); end generate; tOpcode_sel <= to_integer(decr.pcint(minAddrBit-1 downto 0)); do_interrupt <= '1' when wb_inta_i='1' and exr.inInterrupt='0' else '0'; decodeControl: process(rom_wb_dat_i, tOpcode_sel, sp_load, decr, do_interrupt, dbg_in.inject, dbg_in.opcode) variable tOpcode : std_logic_vector(OpCode_Size-1 downto 0); variable localspOffset: unsigned(4 downto 0); begin if dbg_in.inject='1' then tOpcode := dbg_in.opcode; else case (tOpcode_sel) is when 0 => tOpcode := std_logic_vector(rom_wb_dat_i(31 downto 24)); when 1 => tOpcode := std_logic_vector(rom_wb_dat_i(23 downto 16)); when 2 => tOpcode := std_logic_vector(rom_wb_dat_i(15 downto 8)); when 3 => tOpcode := std_logic_vector(rom_wb_dat_i(7 downto 0)); when others => null; end case; end if; sampledOpcode <= tOpcode; sampledStackOperation <= Stack_Same; sampledTosSource <= Tos_Source_None; sampledOpWillFreeze <= '0'; localspOffset(4):=not tOpcode(4); localspOffset(3 downto 0) := unsigned(tOpcode(3 downto 0)); if do_interrupt='1' and decr.im='0' then sampledDecodedOpcode <= Decoded_Interrupt; sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_PC; else if (tOpcode(7 downto 7)=OpCode_Im) then if decr.im='0' then sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_Idim0; sampledDecodedOpcode<=Decoded_Im0; else sampledTosSource <= Tos_Source_IdimN; sampledDecodedOpcode<=Decoded_ImN; end if; elsif (tOpcode(7 downto 5)=OpCode_StoreSP) then sampledStackOperation <= Stack_Pop; sampledTosSource <= Tos_Source_StackB; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Pop; sampledTosSource <= Tos_Source_StackB; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_PopDown; sampledTosSource <= Tos_Source_None; else sampledDecodedOpcode<=Decoded_StoreSP; sampledOpWillFreeze<='1'; sampledTosSource <= Tos_Source_StackB; end if; elsif (tOpcode(7 downto 5)=OpCode_LoadSP) then sampledStackOperation <= Stack_Push; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Dup; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_DupStackB; sampledTosSource <= Tos_Source_StackB; else sampledDecodedOpcode<=Decoded_LoadSP; sampledTosSource <= Tos_Source_LoadSP; end if; elsif (tOpcode(7 downto 5)=OpCode_Emulate) then -- Emulated instructions implemented in hardware if minimal_implementation then sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; else if (tOpcode(5 downto 0)=OpCode_Loadb) then sampledStackOperation<=Stack_Same; sampledDecodedOpcode<=Decoded_Loadb; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Neqbranch) then sampledStackOperation<=Stack_DualPop; sampledDecodedOpcode<=Decoded_Neqbranch; sampledOpWillFreeze <= '1'; elsif (tOpcode(5 downto 0)=OpCode_Call) then sampledDecodedOpcode<=Decoded_Call; sampledStackOperation<=Stack_Same; sampledTosSource<=Tos_Source_FetchPC; elsif (tOpcode(5 downto 0)=OpCode_Eq) then sampledDecodedOpcode<=Decoded_Eq; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Eq; elsif (tOpcode(5 downto 0)=OpCode_Ulessthan) then sampledDecodedOpcode<=Decoded_Ulessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Ulessthan; elsif (tOpcode(5 downto 0)=OpCode_Lessthan) then sampledDecodedOpcode<=Decoded_Lessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Lessthan; elsif (tOpcode(5 downto 0)=OpCode_StoreB) then sampledDecodedOpcode<=Decoded_StoreB; sampledStackOperation<=Stack_DualPop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Mult) then sampledDecodedOpcode<=Decoded_Mult; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Ashiftleft) then sampledDecodedOpcode<=Decoded_Ashiftleft; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; end if; end if; elsif (tOpcode(7 downto 4)=OpCode_AddSP) then if localspOffset=0 then sampledDecodedOpcode<=Decoded_Shift; sampledTosSource <= Tos_Source_Shift; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_AddStackB; sampledTosSource <= Tos_Source_AddStackB; else sampledDecodedOpcode<=Decoded_AddSP; sampledTosSource <= Tos_Source_AddSP; end if; else case tOpcode(3 downto 0) is when OpCode_Break => sampledDecodedOpcode<=Decoded_Break; sampledOpWillFreeze <= '1'; when OpCode_PushSP => sampledStackOperation <= Stack_Push; sampledDecodedOpcode<=Decoded_PushSP; sampledTosSource <= Tos_Source_SP; when OpCode_PopPC => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_PopPC; sampledTosSource <= Tos_Source_StackB; when OpCode_Add => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Add; sampledTosSource <= Tos_Source_Add; when OpCode_Or => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Or; sampledTosSource <= Tos_Source_Or; when OpCode_And => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_And; sampledTosSource <= Tos_Source_And; when OpCode_Load => sampledDecodedOpcode<=Decoded_Load; sampledOpWillFreeze<='1'; when OpCode_Not => sampledDecodedOpcode<=Decoded_Not; sampledTosSource <= Tos_Source_Not; when OpCode_Flip => sampledDecodedOpcode<=Decoded_Flip; sampledTosSource <= Tos_Source_Flip; when OpCode_Store => sampledStackOperation <= Stack_DualPop; sampledDecodedOpcode<=Decoded_Store; sampledOpWillFreeze<='1'; when OpCode_PopSP => sampledDecodedOpcode<=Decoded_PopSP; sampledOpWillFreeze<='1'; when OpCode_NA4 => if enable_fmul16 then sampledDecodedOpcode<=Decoded_MultF16; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Nop; end if; when others => sampledDecodedOpcode<=Decoded_Nop; end case; end if; end if; sampledspOffset <= localspOffset; end process; -- Decode/Fetch unit rom_wb_stb_o <= not exu_busy; process(decr, jump_address, decode_jump, wb_clk_i, sp_load, sampledDecodedOpcode,sampledOpcode,decode_load_sp, exu_busy, pfu_busy, pcnext, rom_wb_ack_i, wb_rst_i, sampledStackOperation, sampledspOffset, sampledTosSource, prefr.recompute_sp, sampledOpWillFreeze, dbg_in.flush, dbg_in.inject,dbg_in.injectmode, prefr.valid, prefr.break, rom_wb_stall_i ) variable w: decoderegs_type; begin w := decr; pcnext <= decr.fetchpc + 1; rom_wb_adr_o <= std_logic_vector(pc_to_memaddr(decr.fetchpc)); rom_wb_cti_o <= CTI_CYCLE_INCRADDR; if wb_rst_i='1' then w.pc := (others => '0'); w.pcint := (others => '0'); w.valid := '0'; w.fetchpc := (others => '0'); w.im:='0'; w.im_emu:='0'; w.state := State_Run; w.break := '0'; rom_wb_cyc_o <= '0'; else rom_wb_cyc_o <= '1'; case decr.state is when State_Run => if pfu_busy='0' then if dbg_in.injectmode='0' and decr.break='0' and rom_wb_stall_i='0' then w.fetchpc := pcnext; end if; -- Jump request if decode_jump='1' then w.valid := '0'; w.im := '0'; w.break := '0'; -- Invalidate eventual break after branch instruction --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o<='0'; --if rom_wb_stall_i='0' then w.fetchpc := jump_address; --else w.state := State_Jump; --end if; else if dbg_in.injectmode='1' then --or decr.break='1' then -- At this point we ought to push a new op into the pipeline. -- Since we're entering inject mode, invalidate next operation, -- but save the current IM flag. w.im_emu := decr.im; w.valid := '0'; --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o <='0'; -- Wait until no work is to be done if prefr.valid='0' and decr.valid='0' and exu_busy='0' then w.state := State_Inject; w.im:='0'; end if; if decr.break='0' then w.pc := decr.pcint; end if; else if decr.break='1' then w.valid := '0'; else w.valid := rom_wb_ack_i; end if; if rom_wb_ack_i='1' then w.im := sampledOpcode(7); if sampledDecodedOpcode=Decoded_Break then w.break:='1'; end if; end if; if prefr.break='0' and rom_wb_stall_i='0' then w.pcint := decr.fetchpc; w.pc := decr.pcint; end if; if rom_wb_stall_i='0' then w.opcode := sampledOpcode; end if; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; when State_Jump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Run; when State_InjectJump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Inject; when State_Inject => -- NOTE: disable ROM rom_wb_cyc_o <= '0'; if dbg_in.injectmode='0' then w.im := decr.im_emu; w.fetchpc := decr.pcint; w.state := State_Run; w.break := '0'; else -- Handle opcode injection -- TODO: merge this with main decode. -- NOTE: we don't check busy here, it's up to debug unit to do it --if pfu_busy='0' then --w.fetchpc := pcnext; -- Jump request if decode_jump='1' then w.fetchpc := jump_address; w.valid := '0'; w.im := '0'; w.state := State_InjectJump; else w.valid := dbg_in.inject; if dbg_in.inject='1' then w.im := sampledOpcode(7); --w.break := '0'; --w.pcint := decr.fetchpc; w.opcode := sampledOpcode; --w.pc := decr.pcint; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; --end if; end case; end if; -- rst if rising_edge(wb_clk_i) then decr <= w; end if; end process; -- Prefetch/Load unit. sp_load <= exr.tos(spMaxBit downto 2); -- Will be delayed one clock cycle process(wb_clk_i, wb_rst_i, decr, prefr, exu_busy, decode_jump, sp_load, decode_load_sp, dbg_in.flush) variable w: prefetchregs_type; variable i_op_freeze: std_logic; begin w := prefr; pfu_busy<='0'; stack_b_addr <= std_logic_vector(prefr.spnext + 1); w.recompute_sp:='0'; -- Stack w.load := decode_load_sp; if decode_load_sp='1' then pfu_busy <= '1'; w.spnext := sp_load; w.recompute_sp := '1'; else pfu_busy <= exu_busy; if decr.valid='1' then if (exu_busy='0' and decode_jump='0') or prefr.recompute_sp='1' then case decr.stackOperation is when Stack_Push => w.spnext := prefr.spnext - 1; when Stack_Pop => w.spnext := prefr.spnext + 1; when Stack_DualPop => w.spnext := prefr.spnext + 2; when others => end case; w.sp := prefr.spnext; end if; end if; end if; case decr.decodedOpcode is when Decoded_LoadSP | decoded_AddSP => stack_b_addr <= std_logic_vector(prefr.spnext + decr.spOffset); when others => end case; if decode_jump='1' then -- this is a pipeline "invalidate" flag. w.valid := '0'; else if dbg_in.flush='1' then w.valid := '0'; else w.valid := decr.valid; end if; end if; -- Moved op_will_freeze from decoder to here case decr.decodedOpcode is when Decoded_StoreSP | Decoded_LoadB | Decoded_Neqbranch | Decoded_StoreB | Decoded_Mult | Decoded_Ashiftleft | Decoded_Break | Decoded_Load | Decoded_Store | Decoded_PopSP | Decoded_MultF16 => i_op_freeze := '1'; when others => i_op_freeze := '0'; end case; if exu_busy='0' then w.decodedOpcode := decr.decodedOpcode; w.tosSource := decr.tosSource; w.opcode := decr.opcode; w.opWillFreeze := i_op_freeze; w.pc := decr.pc; w.fetchpc := decr.pcint; w.idim := decr.idim; w.break := decr.break; end if; if wb_rst_i='1' then w.spnext := unsigned(spStart(10 downto 2)); --w.sp := unsigned(spStart(10 downto 2)); w.valid := '0'; w.idim := '0'; w.recompute_sp:='0'; end if; if rising_edge(wb_clk_i) then prefr <= w; end if; end process; process(prefr,exr,nos) begin trace_pc <= (others => '0'); trace_pc(maxAddrBit downto 0) <= std_logic_vector(prefr.pc); trace_opcode <= prefr.opcode; trace_sp <= (others => '0'); trace_sp(10 downto 2) <= std_logic_vector(prefr.sp); trace_topOfStack <= std_logic_vector( exr.tos ); trace_topOfStackB <= std_logic_vector( nos ); end process; -- IO/Memory Accesses wb_adr_o(maxAddrBitIncIO downto 0) <= std_logic_vector(exr.tos_save(maxAddrBitIncIO downto 0)); wb_cyc_o <= exr.wb_cyc; wb_stb_o <= exr.wb_stb; wb_we_o <= exr.wb_we; wb_dat_o <= std_logic_vector( exr.nos_save ); freeze_all <= dbg_in.freeze; process(exr, wb_inta_i, wb_clk_i, wb_rst_i, pcnext, stack_a_read,stack_b_read, wb_ack_i, wb_dat_i, do_interrupt,exr, prefr, nos, single_step, freeze_all, dbg_in.step, wroteback_q,lshifter_done,lshifter_output ) variable spOffset: unsigned(4 downto 0); variable w: exuregs_type; variable instruction_executed: std_logic; variable wroteback: std_logic; begin w := exr; instruction_executed := '0'; -- used for single stepping stack_b_writeenable <= '0'; stack_a_enable <= '1'; stack_b_enable <= '1'; exu_busy <= '0'; decode_jump <= '0'; jump_address <= (others => DontCareValue); lshifter_enable <= '0'; lshifter_amount <= std_logic_vector(exr.tos_save); lshifter_input <= std_logic_vector(exr.nos_save); lshifter_multorshift <= '0'; poppc_inst <= '0'; begin_inst<='0'; stack_a_addr <= std_logic_vector( prefr.sp ); stack_a_writeenable <= '0'; wroteback := wroteback_q; stack_b_writeenable <= '0'; stack_a_write <= std_logic_vector(exr.tos); spOffset(4):=not prefr.opcode(4); spOffset(3 downto 0) := unsigned(prefr.opcode(3 downto 0)); if wb_inta_i='0' then w.inInterrupt := '0'; end if; stack_b_write<=(others => DontCareValue); if wroteback_q='1' then nos <= unsigned(stack_a_read); else nos <= unsigned(stack_b_read); end if; decode_load_sp <= '0'; case exr.state is when State_Resync1 => exu_busy <= '1'; stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_ResyncFromStoreStack => exu_busy <= '1'; stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_Resync2 => w.tos := unsigned(stack_a_read); instruction_executed := '1'; exu_busy <= '0'; wroteback := '0'; stack_b_enable <= '1'; w.state := State_Execute; when State_Execute => instruction_executed:='0'; if prefr.valid='1' then exu_busy <= prefr.opWillFreeze; if freeze_all='0' or single_step='1' then wroteback := '0'; w.nos_save := nos; w.tos_save := exr.tos; w.idim := prefr.idim; w.break:= prefr.break; begin_inst<='1'; instruction_executed := '1'; -- TOS big muxer case prefr.tosSource is when Tos_Source_PC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.pc; when Tos_Source_FetchPC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.fetchpc; when Tos_Source_Idim0 => for i in wordSize-1 downto 7 loop w.tos(i) := prefr.opcode(6); end loop; w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_IdimN => w.tos(wordSize-1 downto 7) := exr.tos(wordSize-8 downto 0); w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_StackB => w.tos := nos; when Tos_Source_SP => w.tos := (others => '0'); w.tos(31) := '1'; -- Stack address w.tos(10 downto 2) := prefr.sp; when Tos_Source_Add => w.tos := exr.tos + nos; when Tos_Source_And => w.tos := exr.tos and nos; when Tos_Source_Or => w.tos := exr.tos or nos; when Tos_Source_Eq => w.tos := (others => '0'); if nos = exr.tos then w.tos(0) := '1'; end if; when Tos_Source_Ulessthan => w.tos := (others => '0'); if exr.tos < nos then w.tos(0) := '1'; end if; when Tos_Source_Lessthan => w.tos := (others => '0'); if signed(exr.tos) < signed(nos) then w.tos(0) := '1'; end if; when Tos_Source_Not => w.tos := not exr.tos; when Tos_Source_Flip => for i in 0 to wordSize-1 loop w.tos(i) := exr.tos(wordSize-1-i); end loop; when Tos_Source_LoadSP => w.tos := unsigned(stack_b_read); when Tos_Source_AddSP => w.tos := w.tos + unsigned(stack_b_read); when Tos_Source_AddStackB => w.tos := w.tos + nos; when Tos_Source_Shift => w.tos := exr.tos + exr.tos; when others => end case; case prefr.decodedOpcode is when Decoded_Interrupt => w.inInterrupt := '1'; jump_address <= to_unsigned(32, maxAddrBit+1); decode_jump <= '1'; stack_a_writeenable<='1'; wroteback:='1'; stack_b_enable<='0'; instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Im0 => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_ImN => when Decoded_Nop => when Decoded_PopPC | Decoded_Call => decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0); poppc_inst <= '1'; stack_b_enable<='0'; -- Delay instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Emulate => decode_jump <= '1'; jump_address <= (others => '0'); jump_address(9 downto 5) <= unsigned(prefr.opcode(4 downto 0)); stack_a_writeenable<='1'; wroteback:='1'; when Decoded_PushSP => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_LoadSP => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_DupStackB => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_Dup => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_AddSP => stack_a_writeenable <= '1'; when Decoded_StoreSP => stack_a_writeenable <= '1'; wroteback:='1'; stack_a_addr <= std_logic_vector(prefr.sp + spOffset); instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_PopDown => stack_a_writeenable<='1'; when Decoded_Pop => when Decoded_Ashiftleft => w.state := State_Ashiftleft; when Decoded_Mult => w.state := State_Mult; when Decoded_MultF16 => w.state := State_MultF16; when Decoded_Store => if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(nos); stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when Decoded_Load | Decoded_Loadb | Decoded_StoreB => --w.tos_save := exr.tos; -- Byte select instruction_executed := '0'; wroteback := wroteback_q; -- Keep WB if exr.tos(wordSize-1)='1' then stack_a_addr<=std_logic_vector(exr.tos(10 downto 2)); stack_a_enable<='1'; w.state := State_LoadStack; else stack_a_enable <= '0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); w.wb_we :='0'; w.wb_cyc :='1'; w.wb_stb :='1'; w.state := State_Load; end if; when Decoded_PopSP => decode_load_sp <= '1'; instruction_executed := '0'; stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); w.state := State_Resync2; --when Decoded_Break => -- w.break := '1'; when Decoded_Neqbranch => instruction_executed := '0'; w.state := State_NeqBranch; when others => end case; else -- freeze_all -- -- Freeze the entire pipeline. -- exu_busy<='1'; stack_a_enable<='0'; stack_b_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); end if; end if; -- valid when State_Ashiftleft => exu_busy <= '1'; lshifter_enable <= '1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_Mult => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_MultF16 => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(47 downto 16)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_WaitSPB => instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Store => exu_busy <= '1'; -- Keep writeback flag wroteback := wroteback_q; if wb_ack_i='1' then stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; stack_b_enable<='1'; wroteback := '0'; --exu_busy <= '1'; w.wb_cyc := '0'; w.state := State_Resync2; else stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_a_enable<='0'; stack_b_enable<='0'; end if; when State_Loadb => w.tos(wordSize-1 downto 8) := (others => '0'); case exr.tos_save(1 downto 0) is when "11" => w.tos(7 downto 0) := unsigned(exr.tos(7 downto 0)); when "10" => w.tos(7 downto 0) := unsigned(exr.tos(15 downto 8)); when "01" => w.tos(7 downto 0) := unsigned(exr.tos(23 downto 16)); when "00" => w.tos(7 downto 0) := unsigned(exr.tos(31 downto 24)); when others => null; end case; instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Load => if wb_ack_i='0' then exu_busy<='1'; else w.tos := unsigned(wb_dat_i); w.wb_cyc := '0'; if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state := State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state := State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; end if; when State_LoadStack => w.tos := unsigned(stack_a_read); if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state:=State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state:=State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; when State_NeqBranch => if exr.nos_save/=0 then decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0) + prefr.pc; poppc_inst <= '1'; exu_busy <= '0'; else exu_busy <='1'; end if; instruction_executed := '0'; stack_a_addr <= std_logic_vector(prefr.spnext); wroteback:='0'; w.state := State_Resync2; when State_StoreB => exu_busy <= '1'; -- -- At this point, we have loaded the 32-bit, and it's in TOS -- The IO address is still saved in save_TOS. -- The original write value is still at save_NOS -- -- So we mangle the write value, and update save_NOS, and restore -- the IO address to TOS -- -- This is still buggy - don't use. Problems arise when writing to stack. -- w.nos_save := exr.tos; case exr.tos_save(1 downto 0) is when "00" => w.nos_save(31 downto 24) := exr.nos_save(7 downto 0); when "01" => w.nos_save(23 downto 16) := exr.nos_save(7 downto 0); when "10" => w.nos_save(15 downto 8) := exr.nos_save(7 downto 0); when "11" => w.nos_save(7 downto 0) := exr.nos_save(7 downto 0); when others => null; end case; w.tos := exr.tos_save; w.state := State_StoreB2; when State_StoreB2 => exu_busy <= '1'; if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(exr.nos_save); -- hmm I don't like this stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when others => null; end case; if rising_edge(wb_clk_i) then if wb_rst_i='1' then exr.state <= State_Execute; exr.idim <= DontCareValue; exr.inInterrupt <= '0'; exr.break <= '0'; exr.wb_cyc <= '0'; exr.wb_stb <= '1'; else exr <= w; -- TODO: move wroteback_q into EXU regs wroteback_q <= wroteback; if exr.break='1' then report "BREAK" severity failure; end if; -- Some sanity checks, to be caught in simulation if prefr.valid='1' then if prefr.tosSource=Tos_Source_Idim0 and prefr.idim='1' then report "Invalid IDIM flag 0" severity error; end if; if prefr.tosSource=Tos_Source_IdimN and prefr.idim='0' then report "Invalid IDIM flag 1" severity error; end if; end if; end if; end if; end process; single_step <= dbg_in.step; dbg_out.valid <= '1' when prefr.valid='1' else '0'; -- Let pipeline finish dbg_out.ready <= '1' when exr.state=state_execute and decode_load_sp='0' and decode_jump='0' and decr.state = State_Inject --and jump_q='0' else '0'; end behave;
-- ZPU -- -- Copyright 2004-2008 oharboe - Øyvind Harboe - [email protected] -- Copyright 2010-2012 Alvaro Lopes - [email protected] -- -- The FreeBSD license -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions -- are met: -- -- 1. Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer. -- 2. Redistributions in binary form must reproduce the above -- copyright notice, this list of conditions and the following -- disclaimer in the documentation and/or other materials -- provided with the distribution. -- -- THIS SOFTWARE IS PROVIDED BY THE ZPU PROJECT ``AS IS'' AND ANY -- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -- ZPU PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- The views and conclusions contained in the software and documentation -- are those of the authors and should not be interpreted as representing -- official policies, either expressed or implied, of the ZPU Project. library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.numeric_std.all; library board; use board.zpu_config.all; use board.zpupkg.all; use board.wishbonepkg.all; --library UNISIM; --use UNISIM.vcomponents.all; entity zpu_core_extreme is port ( wb_clk_i: in std_logic; wb_rst_i: in std_logic; -- Master wishbone interface wb_ack_i: in std_logic; wb_dat_i: in std_logic_vector(wordSize-1 downto 0); wb_dat_o: out std_logic_vector(wordSize-1 downto 0); wb_adr_o: out std_logic_vector(maxAddrBitIncIO downto 0); wb_cyc_o: out std_logic; wb_stb_o: out std_logic; wb_we_o: out std_logic; wb_inta_i: in std_logic; poppc_inst: out std_logic; break: out std_logic; -- STACK stack_a_read: in std_logic_vector(wordSize-1 downto 0); stack_b_read: in std_logic_vector(wordSize-1 downto 0); stack_a_write: out std_logic_vector(wordSize-1 downto 0); stack_b_write: out std_logic_vector(wordSize-1 downto 0); stack_a_writeenable: out std_logic; stack_a_enable: out std_logic; stack_b_writeenable: out std_logic; stack_b_enable: out std_logic; stack_a_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_b_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_clk: out std_logic; -- ROM wb interface rom_wb_ack_i: in std_logic; rom_wb_dat_i: in std_logic_vector(wordSize-1 downto 0); rom_wb_adr_o: out std_logic_vector(maxAddrBit downto 0); rom_wb_cyc_o: out std_logic; rom_wb_stb_o: out std_logic; rom_wb_cti_o: out std_logic_vector(2 downto 0); rom_wb_stall_i: in std_logic; -- Debug interface dbg_out: out zpu_dbg_out_type; dbg_in: in zpu_dbg_in_type ); end zpu_core_extreme; architecture behave of zpu_core_extreme is component lshifter is port ( clk: in std_logic; rst: in std_logic; enable: in std_logic; done: out std_logic; inputA: in std_logic_vector(31 downto 0); inputB: in std_logic_vector(31 downto 0); output: out std_logic_vector(63 downto 0); multorshift: in std_logic ); end component; signal lshifter_enable: std_logic; signal lshifter_done: std_logic; signal lshifter_input: std_logic_vector(31 downto 0); signal lshifter_amount: std_logic_vector(31 downto 0); signal lshifter_output: std_logic_vector(63 downto 0); signal lshifter_multorshift: std_logic; signal begin_inst: std_logic; signal trace_opcode: std_logic_vector(7 downto 0); signal trace_pc: std_logic_vector(maxAddrBitIncIO downto 0); signal trace_sp: std_logic_vector(maxAddrBitIncIO downto minAddrBit); signal trace_topOfStack: std_logic_vector(wordSize-1 downto 0); signal trace_topOfStackB: std_logic_vector(wordSize-1 downto 0); -- state machine. type State_Type is ( State_Execute, State_Store, State_StoreB, State_StoreB2, State_Load, State_LoadMemory, State_LoadStack, State_Loadb, State_Resync1, State_Resync2, State_LoadSP, State_WaitSPB, State_ResyncFromStoreStack, State_Neqbranch, State_Ashiftleft, State_Mult, State_MultF16 ); type DecodedOpcodeType is ( Decoded_Nop, Decoded_Idle, Decoded_Im0, Decoded_ImN, Decoded_LoadSP, Decoded_Dup, Decoded_DupStackB, Decoded_StoreSP, Decoded_Pop, Decoded_PopDown, Decoded_AddSP, Decoded_AddStackB, Decoded_Shift, Decoded_Emulate, Decoded_Break, Decoded_PushSP, Decoded_PopPC, Decoded_Add, Decoded_Or, Decoded_And, Decoded_Load, Decoded_Not, Decoded_Flip, Decoded_Store, Decoded_PopSP, Decoded_Interrupt, Decoded_Neqbranch, Decoded_Eq, Decoded_Storeb, Decoded_Storeh, Decoded_Ulessthan, Decoded_Lessthan, Decoded_Ashiftleft, Decoded_Ashiftright, Decoded_Loadb, Decoded_Call, Decoded_Mult, Decoded_MultF16 ); constant spMaxBit: integer := 10; constant minimal_implementation: boolean := false; subtype index is integer range 0 to 3; signal tOpcode_sel : index; function pc_to_cpuword(pc: unsigned) return unsigned is variable r: unsigned(wordSize-1 downto 0); begin r := (others => DontCareValue); r(maxAddrBit downto 0) := pc; return r; end pc_to_cpuword; function pc_to_memaddr(pc: unsigned) return unsigned is variable r: unsigned(maxAddrBit downto 0); begin r := (others => '0'); r(maxAddrBit downto minAddrBit) := pc(maxAddrBit downto minAddrBit); return r; end pc_to_memaddr; -- Prefetch stage registers type stackChangeType is ( Stack_Same, Stack_Push, Stack_Pop, Stack_DualPop ); type tosSourceType is ( Tos_Source_PC, Tos_Source_FetchPC, Tos_Source_Idim0, Tos_Source_IdimN, Tos_Source_StackB, Tos_Source_SP, Tos_Source_Add, Tos_Source_And, Tos_Source_Or, Tos_Source_Eq, Tos_Source_Not, Tos_Source_Flip, Tos_Source_LoadSP, Tos_Source_AddSP, Tos_Source_AddStackB, Tos_Source_Shift, Tos_Source_Ulessthan, Tos_Source_Lessthan, Tos_Source_None ); type decoderstate_type is ( State_Run, State_Jump, State_Inject, State_InjectJump ); type decoderegs_type is record valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opWillFreeze: std_logic; -- '1' if we know in advance this opcode will freeze pipeline opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); pcint: unsigned(maxAddrBit downto 0); idim: std_logic; im: std_logic; stackOperation: stackChangeType; spOffset: unsigned(4 downto 0); im_emu: std_logic; --emumode: std_logic; break: std_logic; state: decoderstate_type; end record; type prefetchregs_type is record sp: unsigned(spMaxBit downto 2); spnext: unsigned(spMaxBit downto 2); valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); idim: std_logic; break: std_logic; load: std_logic; opWillFreeze: std_logic; recompute_sp: std_logic; end record; type exuregs_type is record idim: std_logic; break: std_logic; inInterrupt:std_logic; tos: unsigned(wordSize-1 downto 0); tos_save: unsigned(wordSize-1 downto 0); nos_save: unsigned(wordSize-1 downto 0); state: State_Type; -- Wishbone control signals (registered) wb_cyc: std_logic; wb_stb: std_logic; wb_we: std_logic; end record; -- Registers for each stage signal exr: exuregs_type; signal prefr: prefetchregs_type; signal decr: decoderegs_type; signal pcnext: unsigned(maxAddrBit downto 0); -- Helper only. TODO: move into variable signal sp_load: unsigned(spMaxBit downto 2); -- SP value to load, coming from EXU into PFU signal decode_load_sp: std_logic; -- Load SP signal from EXU to PFU signal exu_busy: std_logic; -- EXU busy ( stalls PFU ) signal pfu_busy: std_logic; -- PFU busy ( stalls DFU ) signal decode_jump: std_logic; -- Jump signal from EXU to DFU signal jump_address: unsigned(maxAddrBit downto 0); -- Jump address from EXU to DFU signal do_interrupt: std_logic; -- Helper. -- Sampled signals from the opcode. Left as signals -- in order to simulate design. signal sampledOpcode: std_logic_vector(OpCode_Size-1 downto 0); signal sampledDecodedOpcode: DecodedOpcodeType; signal sampledOpWillFreeze: std_logic; signal sampledStackOperation: stackChangeType; signal sampledspOffset: unsigned(4 downto 0); signal sampledTosSource: tosSourceType; signal nos: unsigned(wordSize-1 downto 0); -- This is only a helper signal wroteback_q: std_logic; -- TODO: get rid of this here, move to EXU regs -- Test debug signals signal freeze_all: std_logic := '0'; signal single_step: std_logic := '0'; begin -- Debug interface dbg_out.pc <= std_logic_vector(prefr.pc); dbg_out.opcode <= prefr.opcode; dbg_out.sp <= std_logic_vector(prefr.sp); dbg_out.brk <= exr.break; dbg_out.stacka <= std_logic_vector(exr.tos); dbg_out.stackb <= std_logic_vector(nos); dbg_out.idim <= prefr.idim; shl: lshifter port map ( clk => wb_clk_i, rst => wb_rst_i, enable => lshifter_enable, done => lshifter_done, inputA => lshifter_input, inputB => lshifter_amount, output => lshifter_output, multorshift => lshifter_multorshift ); stack_clk <= wb_clk_i; traceFileGenerate: if Generate_Trace generate trace_file: trace port map ( clk => wb_clk_i, begin_inst => begin_inst, pc => trace_pc, opcode => trace_opcode, sp => trace_sp, memA => trace_topOfStack, memB => trace_topOfStackB, busy => '0',--busy, intsp => (others => 'U') ); end generate; tOpcode_sel <= to_integer(decr.pcint(minAddrBit-1 downto 0)); do_interrupt <= '1' when wb_inta_i='1' and exr.inInterrupt='0' else '0'; decodeControl: process(rom_wb_dat_i, tOpcode_sel, sp_load, decr, do_interrupt, dbg_in.inject, dbg_in.opcode) variable tOpcode : std_logic_vector(OpCode_Size-1 downto 0); variable localspOffset: unsigned(4 downto 0); begin if dbg_in.inject='1' then tOpcode := dbg_in.opcode; else case (tOpcode_sel) is when 0 => tOpcode := std_logic_vector(rom_wb_dat_i(31 downto 24)); when 1 => tOpcode := std_logic_vector(rom_wb_dat_i(23 downto 16)); when 2 => tOpcode := std_logic_vector(rom_wb_dat_i(15 downto 8)); when 3 => tOpcode := std_logic_vector(rom_wb_dat_i(7 downto 0)); when others => null; end case; end if; sampledOpcode <= tOpcode; sampledStackOperation <= Stack_Same; sampledTosSource <= Tos_Source_None; sampledOpWillFreeze <= '0'; localspOffset(4):=not tOpcode(4); localspOffset(3 downto 0) := unsigned(tOpcode(3 downto 0)); if do_interrupt='1' and decr.im='0' then sampledDecodedOpcode <= Decoded_Interrupt; sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_PC; else if (tOpcode(7 downto 7)=OpCode_Im) then if decr.im='0' then sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_Idim0; sampledDecodedOpcode<=Decoded_Im0; else sampledTosSource <= Tos_Source_IdimN; sampledDecodedOpcode<=Decoded_ImN; end if; elsif (tOpcode(7 downto 5)=OpCode_StoreSP) then sampledStackOperation <= Stack_Pop; sampledTosSource <= Tos_Source_StackB; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Pop; sampledTosSource <= Tos_Source_StackB; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_PopDown; sampledTosSource <= Tos_Source_None; else sampledDecodedOpcode<=Decoded_StoreSP; sampledOpWillFreeze<='1'; sampledTosSource <= Tos_Source_StackB; end if; elsif (tOpcode(7 downto 5)=OpCode_LoadSP) then sampledStackOperation <= Stack_Push; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Dup; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_DupStackB; sampledTosSource <= Tos_Source_StackB; else sampledDecodedOpcode<=Decoded_LoadSP; sampledTosSource <= Tos_Source_LoadSP; end if; elsif (tOpcode(7 downto 5)=OpCode_Emulate) then -- Emulated instructions implemented in hardware if minimal_implementation then sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; else if (tOpcode(5 downto 0)=OpCode_Loadb) then sampledStackOperation<=Stack_Same; sampledDecodedOpcode<=Decoded_Loadb; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Neqbranch) then sampledStackOperation<=Stack_DualPop; sampledDecodedOpcode<=Decoded_Neqbranch; sampledOpWillFreeze <= '1'; elsif (tOpcode(5 downto 0)=OpCode_Call) then sampledDecodedOpcode<=Decoded_Call; sampledStackOperation<=Stack_Same; sampledTosSource<=Tos_Source_FetchPC; elsif (tOpcode(5 downto 0)=OpCode_Eq) then sampledDecodedOpcode<=Decoded_Eq; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Eq; elsif (tOpcode(5 downto 0)=OpCode_Ulessthan) then sampledDecodedOpcode<=Decoded_Ulessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Ulessthan; elsif (tOpcode(5 downto 0)=OpCode_Lessthan) then sampledDecodedOpcode<=Decoded_Lessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Lessthan; elsif (tOpcode(5 downto 0)=OpCode_StoreB) then sampledDecodedOpcode<=Decoded_StoreB; sampledStackOperation<=Stack_DualPop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Mult) then sampledDecodedOpcode<=Decoded_Mult; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Ashiftleft) then sampledDecodedOpcode<=Decoded_Ashiftleft; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; end if; end if; elsif (tOpcode(7 downto 4)=OpCode_AddSP) then if localspOffset=0 then sampledDecodedOpcode<=Decoded_Shift; sampledTosSource <= Tos_Source_Shift; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_AddStackB; sampledTosSource <= Tos_Source_AddStackB; else sampledDecodedOpcode<=Decoded_AddSP; sampledTosSource <= Tos_Source_AddSP; end if; else case tOpcode(3 downto 0) is when OpCode_Break => sampledDecodedOpcode<=Decoded_Break; sampledOpWillFreeze <= '1'; when OpCode_PushSP => sampledStackOperation <= Stack_Push; sampledDecodedOpcode<=Decoded_PushSP; sampledTosSource <= Tos_Source_SP; when OpCode_PopPC => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_PopPC; sampledTosSource <= Tos_Source_StackB; when OpCode_Add => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Add; sampledTosSource <= Tos_Source_Add; when OpCode_Or => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Or; sampledTosSource <= Tos_Source_Or; when OpCode_And => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_And; sampledTosSource <= Tos_Source_And; when OpCode_Load => sampledDecodedOpcode<=Decoded_Load; sampledOpWillFreeze<='1'; when OpCode_Not => sampledDecodedOpcode<=Decoded_Not; sampledTosSource <= Tos_Source_Not; when OpCode_Flip => sampledDecodedOpcode<=Decoded_Flip; sampledTosSource <= Tos_Source_Flip; when OpCode_Store => sampledStackOperation <= Stack_DualPop; sampledDecodedOpcode<=Decoded_Store; sampledOpWillFreeze<='1'; when OpCode_PopSP => sampledDecodedOpcode<=Decoded_PopSP; sampledOpWillFreeze<='1'; when OpCode_NA4 => if enable_fmul16 then sampledDecodedOpcode<=Decoded_MultF16; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Nop; end if; when others => sampledDecodedOpcode<=Decoded_Nop; end case; end if; end if; sampledspOffset <= localspOffset; end process; -- Decode/Fetch unit rom_wb_stb_o <= not exu_busy; process(decr, jump_address, decode_jump, wb_clk_i, sp_load, sampledDecodedOpcode,sampledOpcode,decode_load_sp, exu_busy, pfu_busy, pcnext, rom_wb_ack_i, wb_rst_i, sampledStackOperation, sampledspOffset, sampledTosSource, prefr.recompute_sp, sampledOpWillFreeze, dbg_in.flush, dbg_in.inject,dbg_in.injectmode, prefr.valid, prefr.break, rom_wb_stall_i ) variable w: decoderegs_type; begin w := decr; pcnext <= decr.fetchpc + 1; rom_wb_adr_o <= std_logic_vector(pc_to_memaddr(decr.fetchpc)); rom_wb_cti_o <= CTI_CYCLE_INCRADDR; if wb_rst_i='1' then w.pc := (others => '0'); w.pcint := (others => '0'); w.valid := '0'; w.fetchpc := (others => '0'); w.im:='0'; w.im_emu:='0'; w.state := State_Run; w.break := '0'; rom_wb_cyc_o <= '0'; else rom_wb_cyc_o <= '1'; case decr.state is when State_Run => if pfu_busy='0' then if dbg_in.injectmode='0' and decr.break='0' and rom_wb_stall_i='0' then w.fetchpc := pcnext; end if; -- Jump request if decode_jump='1' then w.valid := '0'; w.im := '0'; w.break := '0'; -- Invalidate eventual break after branch instruction --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o<='0'; --if rom_wb_stall_i='0' then w.fetchpc := jump_address; --else w.state := State_Jump; --end if; else if dbg_in.injectmode='1' then --or decr.break='1' then -- At this point we ought to push a new op into the pipeline. -- Since we're entering inject mode, invalidate next operation, -- but save the current IM flag. w.im_emu := decr.im; w.valid := '0'; --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o <='0'; -- Wait until no work is to be done if prefr.valid='0' and decr.valid='0' and exu_busy='0' then w.state := State_Inject; w.im:='0'; end if; if decr.break='0' then w.pc := decr.pcint; end if; else if decr.break='1' then w.valid := '0'; else w.valid := rom_wb_ack_i; end if; if rom_wb_ack_i='1' then w.im := sampledOpcode(7); if sampledDecodedOpcode=Decoded_Break then w.break:='1'; end if; end if; if prefr.break='0' and rom_wb_stall_i='0' then w.pcint := decr.fetchpc; w.pc := decr.pcint; end if; if rom_wb_stall_i='0' then w.opcode := sampledOpcode; end if; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; when State_Jump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Run; when State_InjectJump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Inject; when State_Inject => -- NOTE: disable ROM rom_wb_cyc_o <= '0'; if dbg_in.injectmode='0' then w.im := decr.im_emu; w.fetchpc := decr.pcint; w.state := State_Run; w.break := '0'; else -- Handle opcode injection -- TODO: merge this with main decode. -- NOTE: we don't check busy here, it's up to debug unit to do it --if pfu_busy='0' then --w.fetchpc := pcnext; -- Jump request if decode_jump='1' then w.fetchpc := jump_address; w.valid := '0'; w.im := '0'; w.state := State_InjectJump; else w.valid := dbg_in.inject; if dbg_in.inject='1' then w.im := sampledOpcode(7); --w.break := '0'; --w.pcint := decr.fetchpc; w.opcode := sampledOpcode; --w.pc := decr.pcint; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; --end if; end case; end if; -- rst if rising_edge(wb_clk_i) then decr <= w; end if; end process; -- Prefetch/Load unit. sp_load <= exr.tos(spMaxBit downto 2); -- Will be delayed one clock cycle process(wb_clk_i, wb_rst_i, decr, prefr, exu_busy, decode_jump, sp_load, decode_load_sp, dbg_in.flush) variable w: prefetchregs_type; variable i_op_freeze: std_logic; begin w := prefr; pfu_busy<='0'; stack_b_addr <= std_logic_vector(prefr.spnext + 1); w.recompute_sp:='0'; -- Stack w.load := decode_load_sp; if decode_load_sp='1' then pfu_busy <= '1'; w.spnext := sp_load; w.recompute_sp := '1'; else pfu_busy <= exu_busy; if decr.valid='1' then if (exu_busy='0' and decode_jump='0') or prefr.recompute_sp='1' then case decr.stackOperation is when Stack_Push => w.spnext := prefr.spnext - 1; when Stack_Pop => w.spnext := prefr.spnext + 1; when Stack_DualPop => w.spnext := prefr.spnext + 2; when others => end case; w.sp := prefr.spnext; end if; end if; end if; case decr.decodedOpcode is when Decoded_LoadSP | decoded_AddSP => stack_b_addr <= std_logic_vector(prefr.spnext + decr.spOffset); when others => end case; if decode_jump='1' then -- this is a pipeline "invalidate" flag. w.valid := '0'; else if dbg_in.flush='1' then w.valid := '0'; else w.valid := decr.valid; end if; end if; -- Moved op_will_freeze from decoder to here case decr.decodedOpcode is when Decoded_StoreSP | Decoded_LoadB | Decoded_Neqbranch | Decoded_StoreB | Decoded_Mult | Decoded_Ashiftleft | Decoded_Break | Decoded_Load | Decoded_Store | Decoded_PopSP | Decoded_MultF16 => i_op_freeze := '1'; when others => i_op_freeze := '0'; end case; if exu_busy='0' then w.decodedOpcode := decr.decodedOpcode; w.tosSource := decr.tosSource; w.opcode := decr.opcode; w.opWillFreeze := i_op_freeze; w.pc := decr.pc; w.fetchpc := decr.pcint; w.idim := decr.idim; w.break := decr.break; end if; if wb_rst_i='1' then w.spnext := unsigned(spStart(10 downto 2)); --w.sp := unsigned(spStart(10 downto 2)); w.valid := '0'; w.idim := '0'; w.recompute_sp:='0'; end if; if rising_edge(wb_clk_i) then prefr <= w; end if; end process; process(prefr,exr,nos) begin trace_pc <= (others => '0'); trace_pc(maxAddrBit downto 0) <= std_logic_vector(prefr.pc); trace_opcode <= prefr.opcode; trace_sp <= (others => '0'); trace_sp(10 downto 2) <= std_logic_vector(prefr.sp); trace_topOfStack <= std_logic_vector( exr.tos ); trace_topOfStackB <= std_logic_vector( nos ); end process; -- IO/Memory Accesses wb_adr_o(maxAddrBitIncIO downto 0) <= std_logic_vector(exr.tos_save(maxAddrBitIncIO downto 0)); wb_cyc_o <= exr.wb_cyc; wb_stb_o <= exr.wb_stb; wb_we_o <= exr.wb_we; wb_dat_o <= std_logic_vector( exr.nos_save ); freeze_all <= dbg_in.freeze; process(exr, wb_inta_i, wb_clk_i, wb_rst_i, pcnext, stack_a_read,stack_b_read, wb_ack_i, wb_dat_i, do_interrupt,exr, prefr, nos, single_step, freeze_all, dbg_in.step, wroteback_q,lshifter_done,lshifter_output ) variable spOffset: unsigned(4 downto 0); variable w: exuregs_type; variable instruction_executed: std_logic; variable wroteback: std_logic; begin w := exr; instruction_executed := '0'; -- used for single stepping stack_b_writeenable <= '0'; stack_a_enable <= '1'; stack_b_enable <= '1'; exu_busy <= '0'; decode_jump <= '0'; jump_address <= (others => DontCareValue); lshifter_enable <= '0'; lshifter_amount <= std_logic_vector(exr.tos_save); lshifter_input <= std_logic_vector(exr.nos_save); lshifter_multorshift <= '0'; poppc_inst <= '0'; begin_inst<='0'; stack_a_addr <= std_logic_vector( prefr.sp ); stack_a_writeenable <= '0'; wroteback := wroteback_q; stack_b_writeenable <= '0'; stack_a_write <= std_logic_vector(exr.tos); spOffset(4):=not prefr.opcode(4); spOffset(3 downto 0) := unsigned(prefr.opcode(3 downto 0)); if wb_inta_i='0' then w.inInterrupt := '0'; end if; stack_b_write<=(others => DontCareValue); if wroteback_q='1' then nos <= unsigned(stack_a_read); else nos <= unsigned(stack_b_read); end if; decode_load_sp <= '0'; case exr.state is when State_Resync1 => exu_busy <= '1'; stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_ResyncFromStoreStack => exu_busy <= '1'; stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_Resync2 => w.tos := unsigned(stack_a_read); instruction_executed := '1'; exu_busy <= '0'; wroteback := '0'; stack_b_enable <= '1'; w.state := State_Execute; when State_Execute => instruction_executed:='0'; if prefr.valid='1' then exu_busy <= prefr.opWillFreeze; if freeze_all='0' or single_step='1' then wroteback := '0'; w.nos_save := nos; w.tos_save := exr.tos; w.idim := prefr.idim; w.break:= prefr.break; begin_inst<='1'; instruction_executed := '1'; -- TOS big muxer case prefr.tosSource is when Tos_Source_PC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.pc; when Tos_Source_FetchPC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.fetchpc; when Tos_Source_Idim0 => for i in wordSize-1 downto 7 loop w.tos(i) := prefr.opcode(6); end loop; w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_IdimN => w.tos(wordSize-1 downto 7) := exr.tos(wordSize-8 downto 0); w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_StackB => w.tos := nos; when Tos_Source_SP => w.tos := (others => '0'); w.tos(31) := '1'; -- Stack address w.tos(10 downto 2) := prefr.sp; when Tos_Source_Add => w.tos := exr.tos + nos; when Tos_Source_And => w.tos := exr.tos and nos; when Tos_Source_Or => w.tos := exr.tos or nos; when Tos_Source_Eq => w.tos := (others => '0'); if nos = exr.tos then w.tos(0) := '1'; end if; when Tos_Source_Ulessthan => w.tos := (others => '0'); if exr.tos < nos then w.tos(0) := '1'; end if; when Tos_Source_Lessthan => w.tos := (others => '0'); if signed(exr.tos) < signed(nos) then w.tos(0) := '1'; end if; when Tos_Source_Not => w.tos := not exr.tos; when Tos_Source_Flip => for i in 0 to wordSize-1 loop w.tos(i) := exr.tos(wordSize-1-i); end loop; when Tos_Source_LoadSP => w.tos := unsigned(stack_b_read); when Tos_Source_AddSP => w.tos := w.tos + unsigned(stack_b_read); when Tos_Source_AddStackB => w.tos := w.tos + nos; when Tos_Source_Shift => w.tos := exr.tos + exr.tos; when others => end case; case prefr.decodedOpcode is when Decoded_Interrupt => w.inInterrupt := '1'; jump_address <= to_unsigned(32, maxAddrBit+1); decode_jump <= '1'; stack_a_writeenable<='1'; wroteback:='1'; stack_b_enable<='0'; instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Im0 => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_ImN => when Decoded_Nop => when Decoded_PopPC | Decoded_Call => decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0); poppc_inst <= '1'; stack_b_enable<='0'; -- Delay instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Emulate => decode_jump <= '1'; jump_address <= (others => '0'); jump_address(9 downto 5) <= unsigned(prefr.opcode(4 downto 0)); stack_a_writeenable<='1'; wroteback:='1'; when Decoded_PushSP => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_LoadSP => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_DupStackB => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_Dup => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_AddSP => stack_a_writeenable <= '1'; when Decoded_StoreSP => stack_a_writeenable <= '1'; wroteback:='1'; stack_a_addr <= std_logic_vector(prefr.sp + spOffset); instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_PopDown => stack_a_writeenable<='1'; when Decoded_Pop => when Decoded_Ashiftleft => w.state := State_Ashiftleft; when Decoded_Mult => w.state := State_Mult; when Decoded_MultF16 => w.state := State_MultF16; when Decoded_Store => if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(nos); stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when Decoded_Load | Decoded_Loadb | Decoded_StoreB => --w.tos_save := exr.tos; -- Byte select instruction_executed := '0'; wroteback := wroteback_q; -- Keep WB if exr.tos(wordSize-1)='1' then stack_a_addr<=std_logic_vector(exr.tos(10 downto 2)); stack_a_enable<='1'; w.state := State_LoadStack; else stack_a_enable <= '0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); w.wb_we :='0'; w.wb_cyc :='1'; w.wb_stb :='1'; w.state := State_Load; end if; when Decoded_PopSP => decode_load_sp <= '1'; instruction_executed := '0'; stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); w.state := State_Resync2; --when Decoded_Break => -- w.break := '1'; when Decoded_Neqbranch => instruction_executed := '0'; w.state := State_NeqBranch; when others => end case; else -- freeze_all -- -- Freeze the entire pipeline. -- exu_busy<='1'; stack_a_enable<='0'; stack_b_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); end if; end if; -- valid when State_Ashiftleft => exu_busy <= '1'; lshifter_enable <= '1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_Mult => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_MultF16 => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(47 downto 16)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_WaitSPB => instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Store => exu_busy <= '1'; -- Keep writeback flag wroteback := wroteback_q; if wb_ack_i='1' then stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; stack_b_enable<='1'; wroteback := '0'; --exu_busy <= '1'; w.wb_cyc := '0'; w.state := State_Resync2; else stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_a_enable<='0'; stack_b_enable<='0'; end if; when State_Loadb => w.tos(wordSize-1 downto 8) := (others => '0'); case exr.tos_save(1 downto 0) is when "11" => w.tos(7 downto 0) := unsigned(exr.tos(7 downto 0)); when "10" => w.tos(7 downto 0) := unsigned(exr.tos(15 downto 8)); when "01" => w.tos(7 downto 0) := unsigned(exr.tos(23 downto 16)); when "00" => w.tos(7 downto 0) := unsigned(exr.tos(31 downto 24)); when others => null; end case; instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Load => if wb_ack_i='0' then exu_busy<='1'; else w.tos := unsigned(wb_dat_i); w.wb_cyc := '0'; if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state := State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state := State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; end if; when State_LoadStack => w.tos := unsigned(stack_a_read); if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state:=State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state:=State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; when State_NeqBranch => if exr.nos_save/=0 then decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0) + prefr.pc; poppc_inst <= '1'; exu_busy <= '0'; else exu_busy <='1'; end if; instruction_executed := '0'; stack_a_addr <= std_logic_vector(prefr.spnext); wroteback:='0'; w.state := State_Resync2; when State_StoreB => exu_busy <= '1'; -- -- At this point, we have loaded the 32-bit, and it's in TOS -- The IO address is still saved in save_TOS. -- The original write value is still at save_NOS -- -- So we mangle the write value, and update save_NOS, and restore -- the IO address to TOS -- -- This is still buggy - don't use. Problems arise when writing to stack. -- w.nos_save := exr.tos; case exr.tos_save(1 downto 0) is when "00" => w.nos_save(31 downto 24) := exr.nos_save(7 downto 0); when "01" => w.nos_save(23 downto 16) := exr.nos_save(7 downto 0); when "10" => w.nos_save(15 downto 8) := exr.nos_save(7 downto 0); when "11" => w.nos_save(7 downto 0) := exr.nos_save(7 downto 0); when others => null; end case; w.tos := exr.tos_save; w.state := State_StoreB2; when State_StoreB2 => exu_busy <= '1'; if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(exr.nos_save); -- hmm I don't like this stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when others => null; end case; if rising_edge(wb_clk_i) then if wb_rst_i='1' then exr.state <= State_Execute; exr.idim <= DontCareValue; exr.inInterrupt <= '0'; exr.break <= '0'; exr.wb_cyc <= '0'; exr.wb_stb <= '1'; else exr <= w; -- TODO: move wroteback_q into EXU regs wroteback_q <= wroteback; if exr.break='1' then report "BREAK" severity failure; end if; -- Some sanity checks, to be caught in simulation if prefr.valid='1' then if prefr.tosSource=Tos_Source_Idim0 and prefr.idim='1' then report "Invalid IDIM flag 0" severity error; end if; if prefr.tosSource=Tos_Source_IdimN and prefr.idim='0' then report "Invalid IDIM flag 1" severity error; end if; end if; end if; end if; end process; single_step <= dbg_in.step; dbg_out.valid <= '1' when prefr.valid='1' else '0'; -- Let pipeline finish dbg_out.ready <= '1' when exr.state=state_execute and decode_load_sp='0' and decode_jump='0' and decr.state = State_Inject --and jump_q='0' else '0'; end behave;
-- ZPU -- -- Copyright 2004-2008 oharboe - Øyvind Harboe - [email protected] -- Copyright 2010-2012 Alvaro Lopes - [email protected] -- -- The FreeBSD license -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions -- are met: -- -- 1. Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer. -- 2. Redistributions in binary form must reproduce the above -- copyright notice, this list of conditions and the following -- disclaimer in the documentation and/or other materials -- provided with the distribution. -- -- THIS SOFTWARE IS PROVIDED BY THE ZPU PROJECT ``AS IS'' AND ANY -- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -- ZPU PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- The views and conclusions contained in the software and documentation -- are those of the authors and should not be interpreted as representing -- official policies, either expressed or implied, of the ZPU Project. library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.numeric_std.all; library board; use board.zpu_config.all; use board.zpupkg.all; use board.wishbonepkg.all; --library UNISIM; --use UNISIM.vcomponents.all; entity zpu_core_extreme is port ( wb_clk_i: in std_logic; wb_rst_i: in std_logic; -- Master wishbone interface wb_ack_i: in std_logic; wb_dat_i: in std_logic_vector(wordSize-1 downto 0); wb_dat_o: out std_logic_vector(wordSize-1 downto 0); wb_adr_o: out std_logic_vector(maxAddrBitIncIO downto 0); wb_cyc_o: out std_logic; wb_stb_o: out std_logic; wb_we_o: out std_logic; wb_inta_i: in std_logic; poppc_inst: out std_logic; break: out std_logic; -- STACK stack_a_read: in std_logic_vector(wordSize-1 downto 0); stack_b_read: in std_logic_vector(wordSize-1 downto 0); stack_a_write: out std_logic_vector(wordSize-1 downto 0); stack_b_write: out std_logic_vector(wordSize-1 downto 0); stack_a_writeenable: out std_logic; stack_a_enable: out std_logic; stack_b_writeenable: out std_logic; stack_b_enable: out std_logic; stack_a_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_b_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_clk: out std_logic; -- ROM wb interface rom_wb_ack_i: in std_logic; rom_wb_dat_i: in std_logic_vector(wordSize-1 downto 0); rom_wb_adr_o: out std_logic_vector(maxAddrBit downto 0); rom_wb_cyc_o: out std_logic; rom_wb_stb_o: out std_logic; rom_wb_cti_o: out std_logic_vector(2 downto 0); rom_wb_stall_i: in std_logic; -- Debug interface dbg_out: out zpu_dbg_out_type; dbg_in: in zpu_dbg_in_type ); end zpu_core_extreme; architecture behave of zpu_core_extreme is component lshifter is port ( clk: in std_logic; rst: in std_logic; enable: in std_logic; done: out std_logic; inputA: in std_logic_vector(31 downto 0); inputB: in std_logic_vector(31 downto 0); output: out std_logic_vector(63 downto 0); multorshift: in std_logic ); end component; signal lshifter_enable: std_logic; signal lshifter_done: std_logic; signal lshifter_input: std_logic_vector(31 downto 0); signal lshifter_amount: std_logic_vector(31 downto 0); signal lshifter_output: std_logic_vector(63 downto 0); signal lshifter_multorshift: std_logic; signal begin_inst: std_logic; signal trace_opcode: std_logic_vector(7 downto 0); signal trace_pc: std_logic_vector(maxAddrBitIncIO downto 0); signal trace_sp: std_logic_vector(maxAddrBitIncIO downto minAddrBit); signal trace_topOfStack: std_logic_vector(wordSize-1 downto 0); signal trace_topOfStackB: std_logic_vector(wordSize-1 downto 0); -- state machine. type State_Type is ( State_Execute, State_Store, State_StoreB, State_StoreB2, State_Load, State_LoadMemory, State_LoadStack, State_Loadb, State_Resync1, State_Resync2, State_LoadSP, State_WaitSPB, State_ResyncFromStoreStack, State_Neqbranch, State_Ashiftleft, State_Mult, State_MultF16 ); type DecodedOpcodeType is ( Decoded_Nop, Decoded_Idle, Decoded_Im0, Decoded_ImN, Decoded_LoadSP, Decoded_Dup, Decoded_DupStackB, Decoded_StoreSP, Decoded_Pop, Decoded_PopDown, Decoded_AddSP, Decoded_AddStackB, Decoded_Shift, Decoded_Emulate, Decoded_Break, Decoded_PushSP, Decoded_PopPC, Decoded_Add, Decoded_Or, Decoded_And, Decoded_Load, Decoded_Not, Decoded_Flip, Decoded_Store, Decoded_PopSP, Decoded_Interrupt, Decoded_Neqbranch, Decoded_Eq, Decoded_Storeb, Decoded_Storeh, Decoded_Ulessthan, Decoded_Lessthan, Decoded_Ashiftleft, Decoded_Ashiftright, Decoded_Loadb, Decoded_Call, Decoded_Mult, Decoded_MultF16 ); constant spMaxBit: integer := 10; constant minimal_implementation: boolean := false; subtype index is integer range 0 to 3; signal tOpcode_sel : index; function pc_to_cpuword(pc: unsigned) return unsigned is variable r: unsigned(wordSize-1 downto 0); begin r := (others => DontCareValue); r(maxAddrBit downto 0) := pc; return r; end pc_to_cpuword; function pc_to_memaddr(pc: unsigned) return unsigned is variable r: unsigned(maxAddrBit downto 0); begin r := (others => '0'); r(maxAddrBit downto minAddrBit) := pc(maxAddrBit downto minAddrBit); return r; end pc_to_memaddr; -- Prefetch stage registers type stackChangeType is ( Stack_Same, Stack_Push, Stack_Pop, Stack_DualPop ); type tosSourceType is ( Tos_Source_PC, Tos_Source_FetchPC, Tos_Source_Idim0, Tos_Source_IdimN, Tos_Source_StackB, Tos_Source_SP, Tos_Source_Add, Tos_Source_And, Tos_Source_Or, Tos_Source_Eq, Tos_Source_Not, Tos_Source_Flip, Tos_Source_LoadSP, Tos_Source_AddSP, Tos_Source_AddStackB, Tos_Source_Shift, Tos_Source_Ulessthan, Tos_Source_Lessthan, Tos_Source_None ); type decoderstate_type is ( State_Run, State_Jump, State_Inject, State_InjectJump ); type decoderegs_type is record valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opWillFreeze: std_logic; -- '1' if we know in advance this opcode will freeze pipeline opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); pcint: unsigned(maxAddrBit downto 0); idim: std_logic; im: std_logic; stackOperation: stackChangeType; spOffset: unsigned(4 downto 0); im_emu: std_logic; --emumode: std_logic; break: std_logic; state: decoderstate_type; end record; type prefetchregs_type is record sp: unsigned(spMaxBit downto 2); spnext: unsigned(spMaxBit downto 2); valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); idim: std_logic; break: std_logic; load: std_logic; opWillFreeze: std_logic; recompute_sp: std_logic; end record; type exuregs_type is record idim: std_logic; break: std_logic; inInterrupt:std_logic; tos: unsigned(wordSize-1 downto 0); tos_save: unsigned(wordSize-1 downto 0); nos_save: unsigned(wordSize-1 downto 0); state: State_Type; -- Wishbone control signals (registered) wb_cyc: std_logic; wb_stb: std_logic; wb_we: std_logic; end record; -- Registers for each stage signal exr: exuregs_type; signal prefr: prefetchregs_type; signal decr: decoderegs_type; signal pcnext: unsigned(maxAddrBit downto 0); -- Helper only. TODO: move into variable signal sp_load: unsigned(spMaxBit downto 2); -- SP value to load, coming from EXU into PFU signal decode_load_sp: std_logic; -- Load SP signal from EXU to PFU signal exu_busy: std_logic; -- EXU busy ( stalls PFU ) signal pfu_busy: std_logic; -- PFU busy ( stalls DFU ) signal decode_jump: std_logic; -- Jump signal from EXU to DFU signal jump_address: unsigned(maxAddrBit downto 0); -- Jump address from EXU to DFU signal do_interrupt: std_logic; -- Helper. -- Sampled signals from the opcode. Left as signals -- in order to simulate design. signal sampledOpcode: std_logic_vector(OpCode_Size-1 downto 0); signal sampledDecodedOpcode: DecodedOpcodeType; signal sampledOpWillFreeze: std_logic; signal sampledStackOperation: stackChangeType; signal sampledspOffset: unsigned(4 downto 0); signal sampledTosSource: tosSourceType; signal nos: unsigned(wordSize-1 downto 0); -- This is only a helper signal wroteback_q: std_logic; -- TODO: get rid of this here, move to EXU regs -- Test debug signals signal freeze_all: std_logic := '0'; signal single_step: std_logic := '0'; begin -- Debug interface dbg_out.pc <= std_logic_vector(prefr.pc); dbg_out.opcode <= prefr.opcode; dbg_out.sp <= std_logic_vector(prefr.sp); dbg_out.brk <= exr.break; dbg_out.stacka <= std_logic_vector(exr.tos); dbg_out.stackb <= std_logic_vector(nos); dbg_out.idim <= prefr.idim; shl: lshifter port map ( clk => wb_clk_i, rst => wb_rst_i, enable => lshifter_enable, done => lshifter_done, inputA => lshifter_input, inputB => lshifter_amount, output => lshifter_output, multorshift => lshifter_multorshift ); stack_clk <= wb_clk_i; traceFileGenerate: if Generate_Trace generate trace_file: trace port map ( clk => wb_clk_i, begin_inst => begin_inst, pc => trace_pc, opcode => trace_opcode, sp => trace_sp, memA => trace_topOfStack, memB => trace_topOfStackB, busy => '0',--busy, intsp => (others => 'U') ); end generate; tOpcode_sel <= to_integer(decr.pcint(minAddrBit-1 downto 0)); do_interrupt <= '1' when wb_inta_i='1' and exr.inInterrupt='0' else '0'; decodeControl: process(rom_wb_dat_i, tOpcode_sel, sp_load, decr, do_interrupt, dbg_in.inject, dbg_in.opcode) variable tOpcode : std_logic_vector(OpCode_Size-1 downto 0); variable localspOffset: unsigned(4 downto 0); begin if dbg_in.inject='1' then tOpcode := dbg_in.opcode; else case (tOpcode_sel) is when 0 => tOpcode := std_logic_vector(rom_wb_dat_i(31 downto 24)); when 1 => tOpcode := std_logic_vector(rom_wb_dat_i(23 downto 16)); when 2 => tOpcode := std_logic_vector(rom_wb_dat_i(15 downto 8)); when 3 => tOpcode := std_logic_vector(rom_wb_dat_i(7 downto 0)); when others => null; end case; end if; sampledOpcode <= tOpcode; sampledStackOperation <= Stack_Same; sampledTosSource <= Tos_Source_None; sampledOpWillFreeze <= '0'; localspOffset(4):=not tOpcode(4); localspOffset(3 downto 0) := unsigned(tOpcode(3 downto 0)); if do_interrupt='1' and decr.im='0' then sampledDecodedOpcode <= Decoded_Interrupt; sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_PC; else if (tOpcode(7 downto 7)=OpCode_Im) then if decr.im='0' then sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_Idim0; sampledDecodedOpcode<=Decoded_Im0; else sampledTosSource <= Tos_Source_IdimN; sampledDecodedOpcode<=Decoded_ImN; end if; elsif (tOpcode(7 downto 5)=OpCode_StoreSP) then sampledStackOperation <= Stack_Pop; sampledTosSource <= Tos_Source_StackB; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Pop; sampledTosSource <= Tos_Source_StackB; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_PopDown; sampledTosSource <= Tos_Source_None; else sampledDecodedOpcode<=Decoded_StoreSP; sampledOpWillFreeze<='1'; sampledTosSource <= Tos_Source_StackB; end if; elsif (tOpcode(7 downto 5)=OpCode_LoadSP) then sampledStackOperation <= Stack_Push; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Dup; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_DupStackB; sampledTosSource <= Tos_Source_StackB; else sampledDecodedOpcode<=Decoded_LoadSP; sampledTosSource <= Tos_Source_LoadSP; end if; elsif (tOpcode(7 downto 5)=OpCode_Emulate) then -- Emulated instructions implemented in hardware if minimal_implementation then sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; else if (tOpcode(5 downto 0)=OpCode_Loadb) then sampledStackOperation<=Stack_Same; sampledDecodedOpcode<=Decoded_Loadb; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Neqbranch) then sampledStackOperation<=Stack_DualPop; sampledDecodedOpcode<=Decoded_Neqbranch; sampledOpWillFreeze <= '1'; elsif (tOpcode(5 downto 0)=OpCode_Call) then sampledDecodedOpcode<=Decoded_Call; sampledStackOperation<=Stack_Same; sampledTosSource<=Tos_Source_FetchPC; elsif (tOpcode(5 downto 0)=OpCode_Eq) then sampledDecodedOpcode<=Decoded_Eq; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Eq; elsif (tOpcode(5 downto 0)=OpCode_Ulessthan) then sampledDecodedOpcode<=Decoded_Ulessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Ulessthan; elsif (tOpcode(5 downto 0)=OpCode_Lessthan) then sampledDecodedOpcode<=Decoded_Lessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Lessthan; elsif (tOpcode(5 downto 0)=OpCode_StoreB) then sampledDecodedOpcode<=Decoded_StoreB; sampledStackOperation<=Stack_DualPop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Mult) then sampledDecodedOpcode<=Decoded_Mult; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Ashiftleft) then sampledDecodedOpcode<=Decoded_Ashiftleft; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; end if; end if; elsif (tOpcode(7 downto 4)=OpCode_AddSP) then if localspOffset=0 then sampledDecodedOpcode<=Decoded_Shift; sampledTosSource <= Tos_Source_Shift; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_AddStackB; sampledTosSource <= Tos_Source_AddStackB; else sampledDecodedOpcode<=Decoded_AddSP; sampledTosSource <= Tos_Source_AddSP; end if; else case tOpcode(3 downto 0) is when OpCode_Break => sampledDecodedOpcode<=Decoded_Break; sampledOpWillFreeze <= '1'; when OpCode_PushSP => sampledStackOperation <= Stack_Push; sampledDecodedOpcode<=Decoded_PushSP; sampledTosSource <= Tos_Source_SP; when OpCode_PopPC => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_PopPC; sampledTosSource <= Tos_Source_StackB; when OpCode_Add => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Add; sampledTosSource <= Tos_Source_Add; when OpCode_Or => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Or; sampledTosSource <= Tos_Source_Or; when OpCode_And => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_And; sampledTosSource <= Tos_Source_And; when OpCode_Load => sampledDecodedOpcode<=Decoded_Load; sampledOpWillFreeze<='1'; when OpCode_Not => sampledDecodedOpcode<=Decoded_Not; sampledTosSource <= Tos_Source_Not; when OpCode_Flip => sampledDecodedOpcode<=Decoded_Flip; sampledTosSource <= Tos_Source_Flip; when OpCode_Store => sampledStackOperation <= Stack_DualPop; sampledDecodedOpcode<=Decoded_Store; sampledOpWillFreeze<='1'; when OpCode_PopSP => sampledDecodedOpcode<=Decoded_PopSP; sampledOpWillFreeze<='1'; when OpCode_NA4 => if enable_fmul16 then sampledDecodedOpcode<=Decoded_MultF16; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Nop; end if; when others => sampledDecodedOpcode<=Decoded_Nop; end case; end if; end if; sampledspOffset <= localspOffset; end process; -- Decode/Fetch unit rom_wb_stb_o <= not exu_busy; process(decr, jump_address, decode_jump, wb_clk_i, sp_load, sampledDecodedOpcode,sampledOpcode,decode_load_sp, exu_busy, pfu_busy, pcnext, rom_wb_ack_i, wb_rst_i, sampledStackOperation, sampledspOffset, sampledTosSource, prefr.recompute_sp, sampledOpWillFreeze, dbg_in.flush, dbg_in.inject,dbg_in.injectmode, prefr.valid, prefr.break, rom_wb_stall_i ) variable w: decoderegs_type; begin w := decr; pcnext <= decr.fetchpc + 1; rom_wb_adr_o <= std_logic_vector(pc_to_memaddr(decr.fetchpc)); rom_wb_cti_o <= CTI_CYCLE_INCRADDR; if wb_rst_i='1' then w.pc := (others => '0'); w.pcint := (others => '0'); w.valid := '0'; w.fetchpc := (others => '0'); w.im:='0'; w.im_emu:='0'; w.state := State_Run; w.break := '0'; rom_wb_cyc_o <= '0'; else rom_wb_cyc_o <= '1'; case decr.state is when State_Run => if pfu_busy='0' then if dbg_in.injectmode='0' and decr.break='0' and rom_wb_stall_i='0' then w.fetchpc := pcnext; end if; -- Jump request if decode_jump='1' then w.valid := '0'; w.im := '0'; w.break := '0'; -- Invalidate eventual break after branch instruction --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o<='0'; --if rom_wb_stall_i='0' then w.fetchpc := jump_address; --else w.state := State_Jump; --end if; else if dbg_in.injectmode='1' then --or decr.break='1' then -- At this point we ought to push a new op into the pipeline. -- Since we're entering inject mode, invalidate next operation, -- but save the current IM flag. w.im_emu := decr.im; w.valid := '0'; --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o <='0'; -- Wait until no work is to be done if prefr.valid='0' and decr.valid='0' and exu_busy='0' then w.state := State_Inject; w.im:='0'; end if; if decr.break='0' then w.pc := decr.pcint; end if; else if decr.break='1' then w.valid := '0'; else w.valid := rom_wb_ack_i; end if; if rom_wb_ack_i='1' then w.im := sampledOpcode(7); if sampledDecodedOpcode=Decoded_Break then w.break:='1'; end if; end if; if prefr.break='0' and rom_wb_stall_i='0' then w.pcint := decr.fetchpc; w.pc := decr.pcint; end if; if rom_wb_stall_i='0' then w.opcode := sampledOpcode; end if; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; when State_Jump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Run; when State_InjectJump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Inject; when State_Inject => -- NOTE: disable ROM rom_wb_cyc_o <= '0'; if dbg_in.injectmode='0' then w.im := decr.im_emu; w.fetchpc := decr.pcint; w.state := State_Run; w.break := '0'; else -- Handle opcode injection -- TODO: merge this with main decode. -- NOTE: we don't check busy here, it's up to debug unit to do it --if pfu_busy='0' then --w.fetchpc := pcnext; -- Jump request if decode_jump='1' then w.fetchpc := jump_address; w.valid := '0'; w.im := '0'; w.state := State_InjectJump; else w.valid := dbg_in.inject; if dbg_in.inject='1' then w.im := sampledOpcode(7); --w.break := '0'; --w.pcint := decr.fetchpc; w.opcode := sampledOpcode; --w.pc := decr.pcint; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; --end if; end case; end if; -- rst if rising_edge(wb_clk_i) then decr <= w; end if; end process; -- Prefetch/Load unit. sp_load <= exr.tos(spMaxBit downto 2); -- Will be delayed one clock cycle process(wb_clk_i, wb_rst_i, decr, prefr, exu_busy, decode_jump, sp_load, decode_load_sp, dbg_in.flush) variable w: prefetchregs_type; variable i_op_freeze: std_logic; begin w := prefr; pfu_busy<='0'; stack_b_addr <= std_logic_vector(prefr.spnext + 1); w.recompute_sp:='0'; -- Stack w.load := decode_load_sp; if decode_load_sp='1' then pfu_busy <= '1'; w.spnext := sp_load; w.recompute_sp := '1'; else pfu_busy <= exu_busy; if decr.valid='1' then if (exu_busy='0' and decode_jump='0') or prefr.recompute_sp='1' then case decr.stackOperation is when Stack_Push => w.spnext := prefr.spnext - 1; when Stack_Pop => w.spnext := prefr.spnext + 1; when Stack_DualPop => w.spnext := prefr.spnext + 2; when others => end case; w.sp := prefr.spnext; end if; end if; end if; case decr.decodedOpcode is when Decoded_LoadSP | decoded_AddSP => stack_b_addr <= std_logic_vector(prefr.spnext + decr.spOffset); when others => end case; if decode_jump='1' then -- this is a pipeline "invalidate" flag. w.valid := '0'; else if dbg_in.flush='1' then w.valid := '0'; else w.valid := decr.valid; end if; end if; -- Moved op_will_freeze from decoder to here case decr.decodedOpcode is when Decoded_StoreSP | Decoded_LoadB | Decoded_Neqbranch | Decoded_StoreB | Decoded_Mult | Decoded_Ashiftleft | Decoded_Break | Decoded_Load | Decoded_Store | Decoded_PopSP | Decoded_MultF16 => i_op_freeze := '1'; when others => i_op_freeze := '0'; end case; if exu_busy='0' then w.decodedOpcode := decr.decodedOpcode; w.tosSource := decr.tosSource; w.opcode := decr.opcode; w.opWillFreeze := i_op_freeze; w.pc := decr.pc; w.fetchpc := decr.pcint; w.idim := decr.idim; w.break := decr.break; end if; if wb_rst_i='1' then w.spnext := unsigned(spStart(10 downto 2)); --w.sp := unsigned(spStart(10 downto 2)); w.valid := '0'; w.idim := '0'; w.recompute_sp:='0'; end if; if rising_edge(wb_clk_i) then prefr <= w; end if; end process; process(prefr,exr,nos) begin trace_pc <= (others => '0'); trace_pc(maxAddrBit downto 0) <= std_logic_vector(prefr.pc); trace_opcode <= prefr.opcode; trace_sp <= (others => '0'); trace_sp(10 downto 2) <= std_logic_vector(prefr.sp); trace_topOfStack <= std_logic_vector( exr.tos ); trace_topOfStackB <= std_logic_vector( nos ); end process; -- IO/Memory Accesses wb_adr_o(maxAddrBitIncIO downto 0) <= std_logic_vector(exr.tos_save(maxAddrBitIncIO downto 0)); wb_cyc_o <= exr.wb_cyc; wb_stb_o <= exr.wb_stb; wb_we_o <= exr.wb_we; wb_dat_o <= std_logic_vector( exr.nos_save ); freeze_all <= dbg_in.freeze; process(exr, wb_inta_i, wb_clk_i, wb_rst_i, pcnext, stack_a_read,stack_b_read, wb_ack_i, wb_dat_i, do_interrupt,exr, prefr, nos, single_step, freeze_all, dbg_in.step, wroteback_q,lshifter_done,lshifter_output ) variable spOffset: unsigned(4 downto 0); variable w: exuregs_type; variable instruction_executed: std_logic; variable wroteback: std_logic; begin w := exr; instruction_executed := '0'; -- used for single stepping stack_b_writeenable <= '0'; stack_a_enable <= '1'; stack_b_enable <= '1'; exu_busy <= '0'; decode_jump <= '0'; jump_address <= (others => DontCareValue); lshifter_enable <= '0'; lshifter_amount <= std_logic_vector(exr.tos_save); lshifter_input <= std_logic_vector(exr.nos_save); lshifter_multorshift <= '0'; poppc_inst <= '0'; begin_inst<='0'; stack_a_addr <= std_logic_vector( prefr.sp ); stack_a_writeenable <= '0'; wroteback := wroteback_q; stack_b_writeenable <= '0'; stack_a_write <= std_logic_vector(exr.tos); spOffset(4):=not prefr.opcode(4); spOffset(3 downto 0) := unsigned(prefr.opcode(3 downto 0)); if wb_inta_i='0' then w.inInterrupt := '0'; end if; stack_b_write<=(others => DontCareValue); if wroteback_q='1' then nos <= unsigned(stack_a_read); else nos <= unsigned(stack_b_read); end if; decode_load_sp <= '0'; case exr.state is when State_Resync1 => exu_busy <= '1'; stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_ResyncFromStoreStack => exu_busy <= '1'; stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_Resync2 => w.tos := unsigned(stack_a_read); instruction_executed := '1'; exu_busy <= '0'; wroteback := '0'; stack_b_enable <= '1'; w.state := State_Execute; when State_Execute => instruction_executed:='0'; if prefr.valid='1' then exu_busy <= prefr.opWillFreeze; if freeze_all='0' or single_step='1' then wroteback := '0'; w.nos_save := nos; w.tos_save := exr.tos; w.idim := prefr.idim; w.break:= prefr.break; begin_inst<='1'; instruction_executed := '1'; -- TOS big muxer case prefr.tosSource is when Tos_Source_PC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.pc; when Tos_Source_FetchPC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.fetchpc; when Tos_Source_Idim0 => for i in wordSize-1 downto 7 loop w.tos(i) := prefr.opcode(6); end loop; w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_IdimN => w.tos(wordSize-1 downto 7) := exr.tos(wordSize-8 downto 0); w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_StackB => w.tos := nos; when Tos_Source_SP => w.tos := (others => '0'); w.tos(31) := '1'; -- Stack address w.tos(10 downto 2) := prefr.sp; when Tos_Source_Add => w.tos := exr.tos + nos; when Tos_Source_And => w.tos := exr.tos and nos; when Tos_Source_Or => w.tos := exr.tos or nos; when Tos_Source_Eq => w.tos := (others => '0'); if nos = exr.tos then w.tos(0) := '1'; end if; when Tos_Source_Ulessthan => w.tos := (others => '0'); if exr.tos < nos then w.tos(0) := '1'; end if; when Tos_Source_Lessthan => w.tos := (others => '0'); if signed(exr.tos) < signed(nos) then w.tos(0) := '1'; end if; when Tos_Source_Not => w.tos := not exr.tos; when Tos_Source_Flip => for i in 0 to wordSize-1 loop w.tos(i) := exr.tos(wordSize-1-i); end loop; when Tos_Source_LoadSP => w.tos := unsigned(stack_b_read); when Tos_Source_AddSP => w.tos := w.tos + unsigned(stack_b_read); when Tos_Source_AddStackB => w.tos := w.tos + nos; when Tos_Source_Shift => w.tos := exr.tos + exr.tos; when others => end case; case prefr.decodedOpcode is when Decoded_Interrupt => w.inInterrupt := '1'; jump_address <= to_unsigned(32, maxAddrBit+1); decode_jump <= '1'; stack_a_writeenable<='1'; wroteback:='1'; stack_b_enable<='0'; instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Im0 => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_ImN => when Decoded_Nop => when Decoded_PopPC | Decoded_Call => decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0); poppc_inst <= '1'; stack_b_enable<='0'; -- Delay instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Emulate => decode_jump <= '1'; jump_address <= (others => '0'); jump_address(9 downto 5) <= unsigned(prefr.opcode(4 downto 0)); stack_a_writeenable<='1'; wroteback:='1'; when Decoded_PushSP => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_LoadSP => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_DupStackB => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_Dup => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_AddSP => stack_a_writeenable <= '1'; when Decoded_StoreSP => stack_a_writeenable <= '1'; wroteback:='1'; stack_a_addr <= std_logic_vector(prefr.sp + spOffset); instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_PopDown => stack_a_writeenable<='1'; when Decoded_Pop => when Decoded_Ashiftleft => w.state := State_Ashiftleft; when Decoded_Mult => w.state := State_Mult; when Decoded_MultF16 => w.state := State_MultF16; when Decoded_Store => if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(nos); stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when Decoded_Load | Decoded_Loadb | Decoded_StoreB => --w.tos_save := exr.tos; -- Byte select instruction_executed := '0'; wroteback := wroteback_q; -- Keep WB if exr.tos(wordSize-1)='1' then stack_a_addr<=std_logic_vector(exr.tos(10 downto 2)); stack_a_enable<='1'; w.state := State_LoadStack; else stack_a_enable <= '0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); w.wb_we :='0'; w.wb_cyc :='1'; w.wb_stb :='1'; w.state := State_Load; end if; when Decoded_PopSP => decode_load_sp <= '1'; instruction_executed := '0'; stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); w.state := State_Resync2; --when Decoded_Break => -- w.break := '1'; when Decoded_Neqbranch => instruction_executed := '0'; w.state := State_NeqBranch; when others => end case; else -- freeze_all -- -- Freeze the entire pipeline. -- exu_busy<='1'; stack_a_enable<='0'; stack_b_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); end if; end if; -- valid when State_Ashiftleft => exu_busy <= '1'; lshifter_enable <= '1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_Mult => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_MultF16 => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(47 downto 16)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_WaitSPB => instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Store => exu_busy <= '1'; -- Keep writeback flag wroteback := wroteback_q; if wb_ack_i='1' then stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; stack_b_enable<='1'; wroteback := '0'; --exu_busy <= '1'; w.wb_cyc := '0'; w.state := State_Resync2; else stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_a_enable<='0'; stack_b_enable<='0'; end if; when State_Loadb => w.tos(wordSize-1 downto 8) := (others => '0'); case exr.tos_save(1 downto 0) is when "11" => w.tos(7 downto 0) := unsigned(exr.tos(7 downto 0)); when "10" => w.tos(7 downto 0) := unsigned(exr.tos(15 downto 8)); when "01" => w.tos(7 downto 0) := unsigned(exr.tos(23 downto 16)); when "00" => w.tos(7 downto 0) := unsigned(exr.tos(31 downto 24)); when others => null; end case; instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Load => if wb_ack_i='0' then exu_busy<='1'; else w.tos := unsigned(wb_dat_i); w.wb_cyc := '0'; if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state := State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state := State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; end if; when State_LoadStack => w.tos := unsigned(stack_a_read); if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state:=State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state:=State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; when State_NeqBranch => if exr.nos_save/=0 then decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0) + prefr.pc; poppc_inst <= '1'; exu_busy <= '0'; else exu_busy <='1'; end if; instruction_executed := '0'; stack_a_addr <= std_logic_vector(prefr.spnext); wroteback:='0'; w.state := State_Resync2; when State_StoreB => exu_busy <= '1'; -- -- At this point, we have loaded the 32-bit, and it's in TOS -- The IO address is still saved in save_TOS. -- The original write value is still at save_NOS -- -- So we mangle the write value, and update save_NOS, and restore -- the IO address to TOS -- -- This is still buggy - don't use. Problems arise when writing to stack. -- w.nos_save := exr.tos; case exr.tos_save(1 downto 0) is when "00" => w.nos_save(31 downto 24) := exr.nos_save(7 downto 0); when "01" => w.nos_save(23 downto 16) := exr.nos_save(7 downto 0); when "10" => w.nos_save(15 downto 8) := exr.nos_save(7 downto 0); when "11" => w.nos_save(7 downto 0) := exr.nos_save(7 downto 0); when others => null; end case; w.tos := exr.tos_save; w.state := State_StoreB2; when State_StoreB2 => exu_busy <= '1'; if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(exr.nos_save); -- hmm I don't like this stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when others => null; end case; if rising_edge(wb_clk_i) then if wb_rst_i='1' then exr.state <= State_Execute; exr.idim <= DontCareValue; exr.inInterrupt <= '0'; exr.break <= '0'; exr.wb_cyc <= '0'; exr.wb_stb <= '1'; else exr <= w; -- TODO: move wroteback_q into EXU regs wroteback_q <= wroteback; if exr.break='1' then report "BREAK" severity failure; end if; -- Some sanity checks, to be caught in simulation if prefr.valid='1' then if prefr.tosSource=Tos_Source_Idim0 and prefr.idim='1' then report "Invalid IDIM flag 0" severity error; end if; if prefr.tosSource=Tos_Source_IdimN and prefr.idim='0' then report "Invalid IDIM flag 1" severity error; end if; end if; end if; end if; end process; single_step <= dbg_in.step; dbg_out.valid <= '1' when prefr.valid='1' else '0'; -- Let pipeline finish dbg_out.ready <= '1' when exr.state=state_execute and decode_load_sp='0' and decode_jump='0' and decr.state = State_Inject --and jump_q='0' else '0'; end behave;
-- ZPU -- -- Copyright 2004-2008 oharboe - Øyvind Harboe - [email protected] -- Copyright 2010-2012 Alvaro Lopes - [email protected] -- -- The FreeBSD license -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions -- are met: -- -- 1. Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer. -- 2. Redistributions in binary form must reproduce the above -- copyright notice, this list of conditions and the following -- disclaimer in the documentation and/or other materials -- provided with the distribution. -- -- THIS SOFTWARE IS PROVIDED BY THE ZPU PROJECT ``AS IS'' AND ANY -- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -- ZPU PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- The views and conclusions contained in the software and documentation -- are those of the authors and should not be interpreted as representing -- official policies, either expressed or implied, of the ZPU Project. library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.numeric_std.all; library board; use board.zpu_config.all; use board.zpupkg.all; use board.wishbonepkg.all; --library UNISIM; --use UNISIM.vcomponents.all; entity zpu_core_extreme is port ( wb_clk_i: in std_logic; wb_rst_i: in std_logic; -- Master wishbone interface wb_ack_i: in std_logic; wb_dat_i: in std_logic_vector(wordSize-1 downto 0); wb_dat_o: out std_logic_vector(wordSize-1 downto 0); wb_adr_o: out std_logic_vector(maxAddrBitIncIO downto 0); wb_cyc_o: out std_logic; wb_stb_o: out std_logic; wb_we_o: out std_logic; wb_inta_i: in std_logic; poppc_inst: out std_logic; break: out std_logic; -- STACK stack_a_read: in std_logic_vector(wordSize-1 downto 0); stack_b_read: in std_logic_vector(wordSize-1 downto 0); stack_a_write: out std_logic_vector(wordSize-1 downto 0); stack_b_write: out std_logic_vector(wordSize-1 downto 0); stack_a_writeenable: out std_logic; stack_a_enable: out std_logic; stack_b_writeenable: out std_logic; stack_b_enable: out std_logic; stack_a_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_b_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_clk: out std_logic; -- ROM wb interface rom_wb_ack_i: in std_logic; rom_wb_dat_i: in std_logic_vector(wordSize-1 downto 0); rom_wb_adr_o: out std_logic_vector(maxAddrBit downto 0); rom_wb_cyc_o: out std_logic; rom_wb_stb_o: out std_logic; rom_wb_cti_o: out std_logic_vector(2 downto 0); rom_wb_stall_i: in std_logic; -- Debug interface dbg_out: out zpu_dbg_out_type; dbg_in: in zpu_dbg_in_type ); end zpu_core_extreme; architecture behave of zpu_core_extreme is component lshifter is port ( clk: in std_logic; rst: in std_logic; enable: in std_logic; done: out std_logic; inputA: in std_logic_vector(31 downto 0); inputB: in std_logic_vector(31 downto 0); output: out std_logic_vector(63 downto 0); multorshift: in std_logic ); end component; signal lshifter_enable: std_logic; signal lshifter_done: std_logic; signal lshifter_input: std_logic_vector(31 downto 0); signal lshifter_amount: std_logic_vector(31 downto 0); signal lshifter_output: std_logic_vector(63 downto 0); signal lshifter_multorshift: std_logic; signal begin_inst: std_logic; signal trace_opcode: std_logic_vector(7 downto 0); signal trace_pc: std_logic_vector(maxAddrBitIncIO downto 0); signal trace_sp: std_logic_vector(maxAddrBitIncIO downto minAddrBit); signal trace_topOfStack: std_logic_vector(wordSize-1 downto 0); signal trace_topOfStackB: std_logic_vector(wordSize-1 downto 0); -- state machine. type State_Type is ( State_Execute, State_Store, State_StoreB, State_StoreB2, State_Load, State_LoadMemory, State_LoadStack, State_Loadb, State_Resync1, State_Resync2, State_LoadSP, State_WaitSPB, State_ResyncFromStoreStack, State_Neqbranch, State_Ashiftleft, State_Mult, State_MultF16 ); type DecodedOpcodeType is ( Decoded_Nop, Decoded_Idle, Decoded_Im0, Decoded_ImN, Decoded_LoadSP, Decoded_Dup, Decoded_DupStackB, Decoded_StoreSP, Decoded_Pop, Decoded_PopDown, Decoded_AddSP, Decoded_AddStackB, Decoded_Shift, Decoded_Emulate, Decoded_Break, Decoded_PushSP, Decoded_PopPC, Decoded_Add, Decoded_Or, Decoded_And, Decoded_Load, Decoded_Not, Decoded_Flip, Decoded_Store, Decoded_PopSP, Decoded_Interrupt, Decoded_Neqbranch, Decoded_Eq, Decoded_Storeb, Decoded_Storeh, Decoded_Ulessthan, Decoded_Lessthan, Decoded_Ashiftleft, Decoded_Ashiftright, Decoded_Loadb, Decoded_Call, Decoded_Mult, Decoded_MultF16 ); constant spMaxBit: integer := 10; constant minimal_implementation: boolean := false; subtype index is integer range 0 to 3; signal tOpcode_sel : index; function pc_to_cpuword(pc: unsigned) return unsigned is variable r: unsigned(wordSize-1 downto 0); begin r := (others => DontCareValue); r(maxAddrBit downto 0) := pc; return r; end pc_to_cpuword; function pc_to_memaddr(pc: unsigned) return unsigned is variable r: unsigned(maxAddrBit downto 0); begin r := (others => '0'); r(maxAddrBit downto minAddrBit) := pc(maxAddrBit downto minAddrBit); return r; end pc_to_memaddr; -- Prefetch stage registers type stackChangeType is ( Stack_Same, Stack_Push, Stack_Pop, Stack_DualPop ); type tosSourceType is ( Tos_Source_PC, Tos_Source_FetchPC, Tos_Source_Idim0, Tos_Source_IdimN, Tos_Source_StackB, Tos_Source_SP, Tos_Source_Add, Tos_Source_And, Tos_Source_Or, Tos_Source_Eq, Tos_Source_Not, Tos_Source_Flip, Tos_Source_LoadSP, Tos_Source_AddSP, Tos_Source_AddStackB, Tos_Source_Shift, Tos_Source_Ulessthan, Tos_Source_Lessthan, Tos_Source_None ); type decoderstate_type is ( State_Run, State_Jump, State_Inject, State_InjectJump ); type decoderegs_type is record valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opWillFreeze: std_logic; -- '1' if we know in advance this opcode will freeze pipeline opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); pcint: unsigned(maxAddrBit downto 0); idim: std_logic; im: std_logic; stackOperation: stackChangeType; spOffset: unsigned(4 downto 0); im_emu: std_logic; --emumode: std_logic; break: std_logic; state: decoderstate_type; end record; type prefetchregs_type is record sp: unsigned(spMaxBit downto 2); spnext: unsigned(spMaxBit downto 2); valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); idim: std_logic; break: std_logic; load: std_logic; opWillFreeze: std_logic; recompute_sp: std_logic; end record; type exuregs_type is record idim: std_logic; break: std_logic; inInterrupt:std_logic; tos: unsigned(wordSize-1 downto 0); tos_save: unsigned(wordSize-1 downto 0); nos_save: unsigned(wordSize-1 downto 0); state: State_Type; -- Wishbone control signals (registered) wb_cyc: std_logic; wb_stb: std_logic; wb_we: std_logic; end record; -- Registers for each stage signal exr: exuregs_type; signal prefr: prefetchregs_type; signal decr: decoderegs_type; signal pcnext: unsigned(maxAddrBit downto 0); -- Helper only. TODO: move into variable signal sp_load: unsigned(spMaxBit downto 2); -- SP value to load, coming from EXU into PFU signal decode_load_sp: std_logic; -- Load SP signal from EXU to PFU signal exu_busy: std_logic; -- EXU busy ( stalls PFU ) signal pfu_busy: std_logic; -- PFU busy ( stalls DFU ) signal decode_jump: std_logic; -- Jump signal from EXU to DFU signal jump_address: unsigned(maxAddrBit downto 0); -- Jump address from EXU to DFU signal do_interrupt: std_logic; -- Helper. -- Sampled signals from the opcode. Left as signals -- in order to simulate design. signal sampledOpcode: std_logic_vector(OpCode_Size-1 downto 0); signal sampledDecodedOpcode: DecodedOpcodeType; signal sampledOpWillFreeze: std_logic; signal sampledStackOperation: stackChangeType; signal sampledspOffset: unsigned(4 downto 0); signal sampledTosSource: tosSourceType; signal nos: unsigned(wordSize-1 downto 0); -- This is only a helper signal wroteback_q: std_logic; -- TODO: get rid of this here, move to EXU regs -- Test debug signals signal freeze_all: std_logic := '0'; signal single_step: std_logic := '0'; begin -- Debug interface dbg_out.pc <= std_logic_vector(prefr.pc); dbg_out.opcode <= prefr.opcode; dbg_out.sp <= std_logic_vector(prefr.sp); dbg_out.brk <= exr.break; dbg_out.stacka <= std_logic_vector(exr.tos); dbg_out.stackb <= std_logic_vector(nos); dbg_out.idim <= prefr.idim; shl: lshifter port map ( clk => wb_clk_i, rst => wb_rst_i, enable => lshifter_enable, done => lshifter_done, inputA => lshifter_input, inputB => lshifter_amount, output => lshifter_output, multorshift => lshifter_multorshift ); stack_clk <= wb_clk_i; traceFileGenerate: if Generate_Trace generate trace_file: trace port map ( clk => wb_clk_i, begin_inst => begin_inst, pc => trace_pc, opcode => trace_opcode, sp => trace_sp, memA => trace_topOfStack, memB => trace_topOfStackB, busy => '0',--busy, intsp => (others => 'U') ); end generate; tOpcode_sel <= to_integer(decr.pcint(minAddrBit-1 downto 0)); do_interrupt <= '1' when wb_inta_i='1' and exr.inInterrupt='0' else '0'; decodeControl: process(rom_wb_dat_i, tOpcode_sel, sp_load, decr, do_interrupt, dbg_in.inject, dbg_in.opcode) variable tOpcode : std_logic_vector(OpCode_Size-1 downto 0); variable localspOffset: unsigned(4 downto 0); begin if dbg_in.inject='1' then tOpcode := dbg_in.opcode; else case (tOpcode_sel) is when 0 => tOpcode := std_logic_vector(rom_wb_dat_i(31 downto 24)); when 1 => tOpcode := std_logic_vector(rom_wb_dat_i(23 downto 16)); when 2 => tOpcode := std_logic_vector(rom_wb_dat_i(15 downto 8)); when 3 => tOpcode := std_logic_vector(rom_wb_dat_i(7 downto 0)); when others => null; end case; end if; sampledOpcode <= tOpcode; sampledStackOperation <= Stack_Same; sampledTosSource <= Tos_Source_None; sampledOpWillFreeze <= '0'; localspOffset(4):=not tOpcode(4); localspOffset(3 downto 0) := unsigned(tOpcode(3 downto 0)); if do_interrupt='1' and decr.im='0' then sampledDecodedOpcode <= Decoded_Interrupt; sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_PC; else if (tOpcode(7 downto 7)=OpCode_Im) then if decr.im='0' then sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_Idim0; sampledDecodedOpcode<=Decoded_Im0; else sampledTosSource <= Tos_Source_IdimN; sampledDecodedOpcode<=Decoded_ImN; end if; elsif (tOpcode(7 downto 5)=OpCode_StoreSP) then sampledStackOperation <= Stack_Pop; sampledTosSource <= Tos_Source_StackB; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Pop; sampledTosSource <= Tos_Source_StackB; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_PopDown; sampledTosSource <= Tos_Source_None; else sampledDecodedOpcode<=Decoded_StoreSP; sampledOpWillFreeze<='1'; sampledTosSource <= Tos_Source_StackB; end if; elsif (tOpcode(7 downto 5)=OpCode_LoadSP) then sampledStackOperation <= Stack_Push; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Dup; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_DupStackB; sampledTosSource <= Tos_Source_StackB; else sampledDecodedOpcode<=Decoded_LoadSP; sampledTosSource <= Tos_Source_LoadSP; end if; elsif (tOpcode(7 downto 5)=OpCode_Emulate) then -- Emulated instructions implemented in hardware if minimal_implementation then sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; else if (tOpcode(5 downto 0)=OpCode_Loadb) then sampledStackOperation<=Stack_Same; sampledDecodedOpcode<=Decoded_Loadb; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Neqbranch) then sampledStackOperation<=Stack_DualPop; sampledDecodedOpcode<=Decoded_Neqbranch; sampledOpWillFreeze <= '1'; elsif (tOpcode(5 downto 0)=OpCode_Call) then sampledDecodedOpcode<=Decoded_Call; sampledStackOperation<=Stack_Same; sampledTosSource<=Tos_Source_FetchPC; elsif (tOpcode(5 downto 0)=OpCode_Eq) then sampledDecodedOpcode<=Decoded_Eq; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Eq; elsif (tOpcode(5 downto 0)=OpCode_Ulessthan) then sampledDecodedOpcode<=Decoded_Ulessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Ulessthan; elsif (tOpcode(5 downto 0)=OpCode_Lessthan) then sampledDecodedOpcode<=Decoded_Lessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Lessthan; elsif (tOpcode(5 downto 0)=OpCode_StoreB) then sampledDecodedOpcode<=Decoded_StoreB; sampledStackOperation<=Stack_DualPop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Mult) then sampledDecodedOpcode<=Decoded_Mult; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Ashiftleft) then sampledDecodedOpcode<=Decoded_Ashiftleft; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; end if; end if; elsif (tOpcode(7 downto 4)=OpCode_AddSP) then if localspOffset=0 then sampledDecodedOpcode<=Decoded_Shift; sampledTosSource <= Tos_Source_Shift; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_AddStackB; sampledTosSource <= Tos_Source_AddStackB; else sampledDecodedOpcode<=Decoded_AddSP; sampledTosSource <= Tos_Source_AddSP; end if; else case tOpcode(3 downto 0) is when OpCode_Break => sampledDecodedOpcode<=Decoded_Break; sampledOpWillFreeze <= '1'; when OpCode_PushSP => sampledStackOperation <= Stack_Push; sampledDecodedOpcode<=Decoded_PushSP; sampledTosSource <= Tos_Source_SP; when OpCode_PopPC => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_PopPC; sampledTosSource <= Tos_Source_StackB; when OpCode_Add => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Add; sampledTosSource <= Tos_Source_Add; when OpCode_Or => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Or; sampledTosSource <= Tos_Source_Or; when OpCode_And => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_And; sampledTosSource <= Tos_Source_And; when OpCode_Load => sampledDecodedOpcode<=Decoded_Load; sampledOpWillFreeze<='1'; when OpCode_Not => sampledDecodedOpcode<=Decoded_Not; sampledTosSource <= Tos_Source_Not; when OpCode_Flip => sampledDecodedOpcode<=Decoded_Flip; sampledTosSource <= Tos_Source_Flip; when OpCode_Store => sampledStackOperation <= Stack_DualPop; sampledDecodedOpcode<=Decoded_Store; sampledOpWillFreeze<='1'; when OpCode_PopSP => sampledDecodedOpcode<=Decoded_PopSP; sampledOpWillFreeze<='1'; when OpCode_NA4 => if enable_fmul16 then sampledDecodedOpcode<=Decoded_MultF16; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Nop; end if; when others => sampledDecodedOpcode<=Decoded_Nop; end case; end if; end if; sampledspOffset <= localspOffset; end process; -- Decode/Fetch unit rom_wb_stb_o <= not exu_busy; process(decr, jump_address, decode_jump, wb_clk_i, sp_load, sampledDecodedOpcode,sampledOpcode,decode_load_sp, exu_busy, pfu_busy, pcnext, rom_wb_ack_i, wb_rst_i, sampledStackOperation, sampledspOffset, sampledTosSource, prefr.recompute_sp, sampledOpWillFreeze, dbg_in.flush, dbg_in.inject,dbg_in.injectmode, prefr.valid, prefr.break, rom_wb_stall_i ) variable w: decoderegs_type; begin w := decr; pcnext <= decr.fetchpc + 1; rom_wb_adr_o <= std_logic_vector(pc_to_memaddr(decr.fetchpc)); rom_wb_cti_o <= CTI_CYCLE_INCRADDR; if wb_rst_i='1' then w.pc := (others => '0'); w.pcint := (others => '0'); w.valid := '0'; w.fetchpc := (others => '0'); w.im:='0'; w.im_emu:='0'; w.state := State_Run; w.break := '0'; rom_wb_cyc_o <= '0'; else rom_wb_cyc_o <= '1'; case decr.state is when State_Run => if pfu_busy='0' then if dbg_in.injectmode='0' and decr.break='0' and rom_wb_stall_i='0' then w.fetchpc := pcnext; end if; -- Jump request if decode_jump='1' then w.valid := '0'; w.im := '0'; w.break := '0'; -- Invalidate eventual break after branch instruction --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o<='0'; --if rom_wb_stall_i='0' then w.fetchpc := jump_address; --else w.state := State_Jump; --end if; else if dbg_in.injectmode='1' then --or decr.break='1' then -- At this point we ought to push a new op into the pipeline. -- Since we're entering inject mode, invalidate next operation, -- but save the current IM flag. w.im_emu := decr.im; w.valid := '0'; --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o <='0'; -- Wait until no work is to be done if prefr.valid='0' and decr.valid='0' and exu_busy='0' then w.state := State_Inject; w.im:='0'; end if; if decr.break='0' then w.pc := decr.pcint; end if; else if decr.break='1' then w.valid := '0'; else w.valid := rom_wb_ack_i; end if; if rom_wb_ack_i='1' then w.im := sampledOpcode(7); if sampledDecodedOpcode=Decoded_Break then w.break:='1'; end if; end if; if prefr.break='0' and rom_wb_stall_i='0' then w.pcint := decr.fetchpc; w.pc := decr.pcint; end if; if rom_wb_stall_i='0' then w.opcode := sampledOpcode; end if; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; when State_Jump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Run; when State_InjectJump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Inject; when State_Inject => -- NOTE: disable ROM rom_wb_cyc_o <= '0'; if dbg_in.injectmode='0' then w.im := decr.im_emu; w.fetchpc := decr.pcint; w.state := State_Run; w.break := '0'; else -- Handle opcode injection -- TODO: merge this with main decode. -- NOTE: we don't check busy here, it's up to debug unit to do it --if pfu_busy='0' then --w.fetchpc := pcnext; -- Jump request if decode_jump='1' then w.fetchpc := jump_address; w.valid := '0'; w.im := '0'; w.state := State_InjectJump; else w.valid := dbg_in.inject; if dbg_in.inject='1' then w.im := sampledOpcode(7); --w.break := '0'; --w.pcint := decr.fetchpc; w.opcode := sampledOpcode; --w.pc := decr.pcint; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; --end if; end case; end if; -- rst if rising_edge(wb_clk_i) then decr <= w; end if; end process; -- Prefetch/Load unit. sp_load <= exr.tos(spMaxBit downto 2); -- Will be delayed one clock cycle process(wb_clk_i, wb_rst_i, decr, prefr, exu_busy, decode_jump, sp_load, decode_load_sp, dbg_in.flush) variable w: prefetchregs_type; variable i_op_freeze: std_logic; begin w := prefr; pfu_busy<='0'; stack_b_addr <= std_logic_vector(prefr.spnext + 1); w.recompute_sp:='0'; -- Stack w.load := decode_load_sp; if decode_load_sp='1' then pfu_busy <= '1'; w.spnext := sp_load; w.recompute_sp := '1'; else pfu_busy <= exu_busy; if decr.valid='1' then if (exu_busy='0' and decode_jump='0') or prefr.recompute_sp='1' then case decr.stackOperation is when Stack_Push => w.spnext := prefr.spnext - 1; when Stack_Pop => w.spnext := prefr.spnext + 1; when Stack_DualPop => w.spnext := prefr.spnext + 2; when others => end case; w.sp := prefr.spnext; end if; end if; end if; case decr.decodedOpcode is when Decoded_LoadSP | decoded_AddSP => stack_b_addr <= std_logic_vector(prefr.spnext + decr.spOffset); when others => end case; if decode_jump='1' then -- this is a pipeline "invalidate" flag. w.valid := '0'; else if dbg_in.flush='1' then w.valid := '0'; else w.valid := decr.valid; end if; end if; -- Moved op_will_freeze from decoder to here case decr.decodedOpcode is when Decoded_StoreSP | Decoded_LoadB | Decoded_Neqbranch | Decoded_StoreB | Decoded_Mult | Decoded_Ashiftleft | Decoded_Break | Decoded_Load | Decoded_Store | Decoded_PopSP | Decoded_MultF16 => i_op_freeze := '1'; when others => i_op_freeze := '0'; end case; if exu_busy='0' then w.decodedOpcode := decr.decodedOpcode; w.tosSource := decr.tosSource; w.opcode := decr.opcode; w.opWillFreeze := i_op_freeze; w.pc := decr.pc; w.fetchpc := decr.pcint; w.idim := decr.idim; w.break := decr.break; end if; if wb_rst_i='1' then w.spnext := unsigned(spStart(10 downto 2)); --w.sp := unsigned(spStart(10 downto 2)); w.valid := '0'; w.idim := '0'; w.recompute_sp:='0'; end if; if rising_edge(wb_clk_i) then prefr <= w; end if; end process; process(prefr,exr,nos) begin trace_pc <= (others => '0'); trace_pc(maxAddrBit downto 0) <= std_logic_vector(prefr.pc); trace_opcode <= prefr.opcode; trace_sp <= (others => '0'); trace_sp(10 downto 2) <= std_logic_vector(prefr.sp); trace_topOfStack <= std_logic_vector( exr.tos ); trace_topOfStackB <= std_logic_vector( nos ); end process; -- IO/Memory Accesses wb_adr_o(maxAddrBitIncIO downto 0) <= std_logic_vector(exr.tos_save(maxAddrBitIncIO downto 0)); wb_cyc_o <= exr.wb_cyc; wb_stb_o <= exr.wb_stb; wb_we_o <= exr.wb_we; wb_dat_o <= std_logic_vector( exr.nos_save ); freeze_all <= dbg_in.freeze; process(exr, wb_inta_i, wb_clk_i, wb_rst_i, pcnext, stack_a_read,stack_b_read, wb_ack_i, wb_dat_i, do_interrupt,exr, prefr, nos, single_step, freeze_all, dbg_in.step, wroteback_q,lshifter_done,lshifter_output ) variable spOffset: unsigned(4 downto 0); variable w: exuregs_type; variable instruction_executed: std_logic; variable wroteback: std_logic; begin w := exr; instruction_executed := '0'; -- used for single stepping stack_b_writeenable <= '0'; stack_a_enable <= '1'; stack_b_enable <= '1'; exu_busy <= '0'; decode_jump <= '0'; jump_address <= (others => DontCareValue); lshifter_enable <= '0'; lshifter_amount <= std_logic_vector(exr.tos_save); lshifter_input <= std_logic_vector(exr.nos_save); lshifter_multorshift <= '0'; poppc_inst <= '0'; begin_inst<='0'; stack_a_addr <= std_logic_vector( prefr.sp ); stack_a_writeenable <= '0'; wroteback := wroteback_q; stack_b_writeenable <= '0'; stack_a_write <= std_logic_vector(exr.tos); spOffset(4):=not prefr.opcode(4); spOffset(3 downto 0) := unsigned(prefr.opcode(3 downto 0)); if wb_inta_i='0' then w.inInterrupt := '0'; end if; stack_b_write<=(others => DontCareValue); if wroteback_q='1' then nos <= unsigned(stack_a_read); else nos <= unsigned(stack_b_read); end if; decode_load_sp <= '0'; case exr.state is when State_Resync1 => exu_busy <= '1'; stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_ResyncFromStoreStack => exu_busy <= '1'; stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_Resync2 => w.tos := unsigned(stack_a_read); instruction_executed := '1'; exu_busy <= '0'; wroteback := '0'; stack_b_enable <= '1'; w.state := State_Execute; when State_Execute => instruction_executed:='0'; if prefr.valid='1' then exu_busy <= prefr.opWillFreeze; if freeze_all='0' or single_step='1' then wroteback := '0'; w.nos_save := nos; w.tos_save := exr.tos; w.idim := prefr.idim; w.break:= prefr.break; begin_inst<='1'; instruction_executed := '1'; -- TOS big muxer case prefr.tosSource is when Tos_Source_PC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.pc; when Tos_Source_FetchPC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.fetchpc; when Tos_Source_Idim0 => for i in wordSize-1 downto 7 loop w.tos(i) := prefr.opcode(6); end loop; w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_IdimN => w.tos(wordSize-1 downto 7) := exr.tos(wordSize-8 downto 0); w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_StackB => w.tos := nos; when Tos_Source_SP => w.tos := (others => '0'); w.tos(31) := '1'; -- Stack address w.tos(10 downto 2) := prefr.sp; when Tos_Source_Add => w.tos := exr.tos + nos; when Tos_Source_And => w.tos := exr.tos and nos; when Tos_Source_Or => w.tos := exr.tos or nos; when Tos_Source_Eq => w.tos := (others => '0'); if nos = exr.tos then w.tos(0) := '1'; end if; when Tos_Source_Ulessthan => w.tos := (others => '0'); if exr.tos < nos then w.tos(0) := '1'; end if; when Tos_Source_Lessthan => w.tos := (others => '0'); if signed(exr.tos) < signed(nos) then w.tos(0) := '1'; end if; when Tos_Source_Not => w.tos := not exr.tos; when Tos_Source_Flip => for i in 0 to wordSize-1 loop w.tos(i) := exr.tos(wordSize-1-i); end loop; when Tos_Source_LoadSP => w.tos := unsigned(stack_b_read); when Tos_Source_AddSP => w.tos := w.tos + unsigned(stack_b_read); when Tos_Source_AddStackB => w.tos := w.tos + nos; when Tos_Source_Shift => w.tos := exr.tos + exr.tos; when others => end case; case prefr.decodedOpcode is when Decoded_Interrupt => w.inInterrupt := '1'; jump_address <= to_unsigned(32, maxAddrBit+1); decode_jump <= '1'; stack_a_writeenable<='1'; wroteback:='1'; stack_b_enable<='0'; instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Im0 => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_ImN => when Decoded_Nop => when Decoded_PopPC | Decoded_Call => decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0); poppc_inst <= '1'; stack_b_enable<='0'; -- Delay instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Emulate => decode_jump <= '1'; jump_address <= (others => '0'); jump_address(9 downto 5) <= unsigned(prefr.opcode(4 downto 0)); stack_a_writeenable<='1'; wroteback:='1'; when Decoded_PushSP => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_LoadSP => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_DupStackB => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_Dup => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_AddSP => stack_a_writeenable <= '1'; when Decoded_StoreSP => stack_a_writeenable <= '1'; wroteback:='1'; stack_a_addr <= std_logic_vector(prefr.sp + spOffset); instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_PopDown => stack_a_writeenable<='1'; when Decoded_Pop => when Decoded_Ashiftleft => w.state := State_Ashiftleft; when Decoded_Mult => w.state := State_Mult; when Decoded_MultF16 => w.state := State_MultF16; when Decoded_Store => if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(nos); stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when Decoded_Load | Decoded_Loadb | Decoded_StoreB => --w.tos_save := exr.tos; -- Byte select instruction_executed := '0'; wroteback := wroteback_q; -- Keep WB if exr.tos(wordSize-1)='1' then stack_a_addr<=std_logic_vector(exr.tos(10 downto 2)); stack_a_enable<='1'; w.state := State_LoadStack; else stack_a_enable <= '0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); w.wb_we :='0'; w.wb_cyc :='1'; w.wb_stb :='1'; w.state := State_Load; end if; when Decoded_PopSP => decode_load_sp <= '1'; instruction_executed := '0'; stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); w.state := State_Resync2; --when Decoded_Break => -- w.break := '1'; when Decoded_Neqbranch => instruction_executed := '0'; w.state := State_NeqBranch; when others => end case; else -- freeze_all -- -- Freeze the entire pipeline. -- exu_busy<='1'; stack_a_enable<='0'; stack_b_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); end if; end if; -- valid when State_Ashiftleft => exu_busy <= '1'; lshifter_enable <= '1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_Mult => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_MultF16 => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(47 downto 16)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_WaitSPB => instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Store => exu_busy <= '1'; -- Keep writeback flag wroteback := wroteback_q; if wb_ack_i='1' then stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; stack_b_enable<='1'; wroteback := '0'; --exu_busy <= '1'; w.wb_cyc := '0'; w.state := State_Resync2; else stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_a_enable<='0'; stack_b_enable<='0'; end if; when State_Loadb => w.tos(wordSize-1 downto 8) := (others => '0'); case exr.tos_save(1 downto 0) is when "11" => w.tos(7 downto 0) := unsigned(exr.tos(7 downto 0)); when "10" => w.tos(7 downto 0) := unsigned(exr.tos(15 downto 8)); when "01" => w.tos(7 downto 0) := unsigned(exr.tos(23 downto 16)); when "00" => w.tos(7 downto 0) := unsigned(exr.tos(31 downto 24)); when others => null; end case; instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Load => if wb_ack_i='0' then exu_busy<='1'; else w.tos := unsigned(wb_dat_i); w.wb_cyc := '0'; if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state := State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state := State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; end if; when State_LoadStack => w.tos := unsigned(stack_a_read); if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state:=State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state:=State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; when State_NeqBranch => if exr.nos_save/=0 then decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0) + prefr.pc; poppc_inst <= '1'; exu_busy <= '0'; else exu_busy <='1'; end if; instruction_executed := '0'; stack_a_addr <= std_logic_vector(prefr.spnext); wroteback:='0'; w.state := State_Resync2; when State_StoreB => exu_busy <= '1'; -- -- At this point, we have loaded the 32-bit, and it's in TOS -- The IO address is still saved in save_TOS. -- The original write value is still at save_NOS -- -- So we mangle the write value, and update save_NOS, and restore -- the IO address to TOS -- -- This is still buggy - don't use. Problems arise when writing to stack. -- w.nos_save := exr.tos; case exr.tos_save(1 downto 0) is when "00" => w.nos_save(31 downto 24) := exr.nos_save(7 downto 0); when "01" => w.nos_save(23 downto 16) := exr.nos_save(7 downto 0); when "10" => w.nos_save(15 downto 8) := exr.nos_save(7 downto 0); when "11" => w.nos_save(7 downto 0) := exr.nos_save(7 downto 0); when others => null; end case; w.tos := exr.tos_save; w.state := State_StoreB2; when State_StoreB2 => exu_busy <= '1'; if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(exr.nos_save); -- hmm I don't like this stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when others => null; end case; if rising_edge(wb_clk_i) then if wb_rst_i='1' then exr.state <= State_Execute; exr.idim <= DontCareValue; exr.inInterrupt <= '0'; exr.break <= '0'; exr.wb_cyc <= '0'; exr.wb_stb <= '1'; else exr <= w; -- TODO: move wroteback_q into EXU regs wroteback_q <= wroteback; if exr.break='1' then report "BREAK" severity failure; end if; -- Some sanity checks, to be caught in simulation if prefr.valid='1' then if prefr.tosSource=Tos_Source_Idim0 and prefr.idim='1' then report "Invalid IDIM flag 0" severity error; end if; if prefr.tosSource=Tos_Source_IdimN and prefr.idim='0' then report "Invalid IDIM flag 1" severity error; end if; end if; end if; end if; end process; single_step <= dbg_in.step; dbg_out.valid <= '1' when prefr.valid='1' else '0'; -- Let pipeline finish dbg_out.ready <= '1' when exr.state=state_execute and decode_load_sp='0' and decode_jump='0' and decr.state = State_Inject --and jump_q='0' else '0'; end behave;
-- ZPU -- -- Copyright 2004-2008 oharboe - Øyvind Harboe - [email protected] -- Copyright 2010-2012 Alvaro Lopes - [email protected] -- -- The FreeBSD license -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions -- are met: -- -- 1. Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer. -- 2. Redistributions in binary form must reproduce the above -- copyright notice, this list of conditions and the following -- disclaimer in the documentation and/or other materials -- provided with the distribution. -- -- THIS SOFTWARE IS PROVIDED BY THE ZPU PROJECT ``AS IS'' AND ANY -- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -- ZPU PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- The views and conclusions contained in the software and documentation -- are those of the authors and should not be interpreted as representing -- official policies, either expressed or implied, of the ZPU Project. library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.numeric_std.all; library board; use board.zpu_config.all; use board.zpupkg.all; use board.wishbonepkg.all; --library UNISIM; --use UNISIM.vcomponents.all; entity zpu_core_extreme is port ( wb_clk_i: in std_logic; wb_rst_i: in std_logic; -- Master wishbone interface wb_ack_i: in std_logic; wb_dat_i: in std_logic_vector(wordSize-1 downto 0); wb_dat_o: out std_logic_vector(wordSize-1 downto 0); wb_adr_o: out std_logic_vector(maxAddrBitIncIO downto 0); wb_cyc_o: out std_logic; wb_stb_o: out std_logic; wb_we_o: out std_logic; wb_inta_i: in std_logic; poppc_inst: out std_logic; break: out std_logic; -- STACK stack_a_read: in std_logic_vector(wordSize-1 downto 0); stack_b_read: in std_logic_vector(wordSize-1 downto 0); stack_a_write: out std_logic_vector(wordSize-1 downto 0); stack_b_write: out std_logic_vector(wordSize-1 downto 0); stack_a_writeenable: out std_logic; stack_a_enable: out std_logic; stack_b_writeenable: out std_logic; stack_b_enable: out std_logic; stack_a_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_b_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_clk: out std_logic; -- ROM wb interface rom_wb_ack_i: in std_logic; rom_wb_dat_i: in std_logic_vector(wordSize-1 downto 0); rom_wb_adr_o: out std_logic_vector(maxAddrBit downto 0); rom_wb_cyc_o: out std_logic; rom_wb_stb_o: out std_logic; rom_wb_cti_o: out std_logic_vector(2 downto 0); rom_wb_stall_i: in std_logic; -- Debug interface dbg_out: out zpu_dbg_out_type; dbg_in: in zpu_dbg_in_type ); end zpu_core_extreme; architecture behave of zpu_core_extreme is component lshifter is port ( clk: in std_logic; rst: in std_logic; enable: in std_logic; done: out std_logic; inputA: in std_logic_vector(31 downto 0); inputB: in std_logic_vector(31 downto 0); output: out std_logic_vector(63 downto 0); multorshift: in std_logic ); end component; signal lshifter_enable: std_logic; signal lshifter_done: std_logic; signal lshifter_input: std_logic_vector(31 downto 0); signal lshifter_amount: std_logic_vector(31 downto 0); signal lshifter_output: std_logic_vector(63 downto 0); signal lshifter_multorshift: std_logic; signal begin_inst: std_logic; signal trace_opcode: std_logic_vector(7 downto 0); signal trace_pc: std_logic_vector(maxAddrBitIncIO downto 0); signal trace_sp: std_logic_vector(maxAddrBitIncIO downto minAddrBit); signal trace_topOfStack: std_logic_vector(wordSize-1 downto 0); signal trace_topOfStackB: std_logic_vector(wordSize-1 downto 0); -- state machine. type State_Type is ( State_Execute, State_Store, State_StoreB, State_StoreB2, State_Load, State_LoadMemory, State_LoadStack, State_Loadb, State_Resync1, State_Resync2, State_LoadSP, State_WaitSPB, State_ResyncFromStoreStack, State_Neqbranch, State_Ashiftleft, State_Mult, State_MultF16 ); type DecodedOpcodeType is ( Decoded_Nop, Decoded_Idle, Decoded_Im0, Decoded_ImN, Decoded_LoadSP, Decoded_Dup, Decoded_DupStackB, Decoded_StoreSP, Decoded_Pop, Decoded_PopDown, Decoded_AddSP, Decoded_AddStackB, Decoded_Shift, Decoded_Emulate, Decoded_Break, Decoded_PushSP, Decoded_PopPC, Decoded_Add, Decoded_Or, Decoded_And, Decoded_Load, Decoded_Not, Decoded_Flip, Decoded_Store, Decoded_PopSP, Decoded_Interrupt, Decoded_Neqbranch, Decoded_Eq, Decoded_Storeb, Decoded_Storeh, Decoded_Ulessthan, Decoded_Lessthan, Decoded_Ashiftleft, Decoded_Ashiftright, Decoded_Loadb, Decoded_Call, Decoded_Mult, Decoded_MultF16 ); constant spMaxBit: integer := 10; constant minimal_implementation: boolean := false; subtype index is integer range 0 to 3; signal tOpcode_sel : index; function pc_to_cpuword(pc: unsigned) return unsigned is variable r: unsigned(wordSize-1 downto 0); begin r := (others => DontCareValue); r(maxAddrBit downto 0) := pc; return r; end pc_to_cpuword; function pc_to_memaddr(pc: unsigned) return unsigned is variable r: unsigned(maxAddrBit downto 0); begin r := (others => '0'); r(maxAddrBit downto minAddrBit) := pc(maxAddrBit downto minAddrBit); return r; end pc_to_memaddr; -- Prefetch stage registers type stackChangeType is ( Stack_Same, Stack_Push, Stack_Pop, Stack_DualPop ); type tosSourceType is ( Tos_Source_PC, Tos_Source_FetchPC, Tos_Source_Idim0, Tos_Source_IdimN, Tos_Source_StackB, Tos_Source_SP, Tos_Source_Add, Tos_Source_And, Tos_Source_Or, Tos_Source_Eq, Tos_Source_Not, Tos_Source_Flip, Tos_Source_LoadSP, Tos_Source_AddSP, Tos_Source_AddStackB, Tos_Source_Shift, Tos_Source_Ulessthan, Tos_Source_Lessthan, Tos_Source_None ); type decoderstate_type is ( State_Run, State_Jump, State_Inject, State_InjectJump ); type decoderegs_type is record valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opWillFreeze: std_logic; -- '1' if we know in advance this opcode will freeze pipeline opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); pcint: unsigned(maxAddrBit downto 0); idim: std_logic; im: std_logic; stackOperation: stackChangeType; spOffset: unsigned(4 downto 0); im_emu: std_logic; --emumode: std_logic; break: std_logic; state: decoderstate_type; end record; type prefetchregs_type is record sp: unsigned(spMaxBit downto 2); spnext: unsigned(spMaxBit downto 2); valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); idim: std_logic; break: std_logic; load: std_logic; opWillFreeze: std_logic; recompute_sp: std_logic; end record; type exuregs_type is record idim: std_logic; break: std_logic; inInterrupt:std_logic; tos: unsigned(wordSize-1 downto 0); tos_save: unsigned(wordSize-1 downto 0); nos_save: unsigned(wordSize-1 downto 0); state: State_Type; -- Wishbone control signals (registered) wb_cyc: std_logic; wb_stb: std_logic; wb_we: std_logic; end record; -- Registers for each stage signal exr: exuregs_type; signal prefr: prefetchregs_type; signal decr: decoderegs_type; signal pcnext: unsigned(maxAddrBit downto 0); -- Helper only. TODO: move into variable signal sp_load: unsigned(spMaxBit downto 2); -- SP value to load, coming from EXU into PFU signal decode_load_sp: std_logic; -- Load SP signal from EXU to PFU signal exu_busy: std_logic; -- EXU busy ( stalls PFU ) signal pfu_busy: std_logic; -- PFU busy ( stalls DFU ) signal decode_jump: std_logic; -- Jump signal from EXU to DFU signal jump_address: unsigned(maxAddrBit downto 0); -- Jump address from EXU to DFU signal do_interrupt: std_logic; -- Helper. -- Sampled signals from the opcode. Left as signals -- in order to simulate design. signal sampledOpcode: std_logic_vector(OpCode_Size-1 downto 0); signal sampledDecodedOpcode: DecodedOpcodeType; signal sampledOpWillFreeze: std_logic; signal sampledStackOperation: stackChangeType; signal sampledspOffset: unsigned(4 downto 0); signal sampledTosSource: tosSourceType; signal nos: unsigned(wordSize-1 downto 0); -- This is only a helper signal wroteback_q: std_logic; -- TODO: get rid of this here, move to EXU regs -- Test debug signals signal freeze_all: std_logic := '0'; signal single_step: std_logic := '0'; begin -- Debug interface dbg_out.pc <= std_logic_vector(prefr.pc); dbg_out.opcode <= prefr.opcode; dbg_out.sp <= std_logic_vector(prefr.sp); dbg_out.brk <= exr.break; dbg_out.stacka <= std_logic_vector(exr.tos); dbg_out.stackb <= std_logic_vector(nos); dbg_out.idim <= prefr.idim; shl: lshifter port map ( clk => wb_clk_i, rst => wb_rst_i, enable => lshifter_enable, done => lshifter_done, inputA => lshifter_input, inputB => lshifter_amount, output => lshifter_output, multorshift => lshifter_multorshift ); stack_clk <= wb_clk_i; traceFileGenerate: if Generate_Trace generate trace_file: trace port map ( clk => wb_clk_i, begin_inst => begin_inst, pc => trace_pc, opcode => trace_opcode, sp => trace_sp, memA => trace_topOfStack, memB => trace_topOfStackB, busy => '0',--busy, intsp => (others => 'U') ); end generate; tOpcode_sel <= to_integer(decr.pcint(minAddrBit-1 downto 0)); do_interrupt <= '1' when wb_inta_i='1' and exr.inInterrupt='0' else '0'; decodeControl: process(rom_wb_dat_i, tOpcode_sel, sp_load, decr, do_interrupt, dbg_in.inject, dbg_in.opcode) variable tOpcode : std_logic_vector(OpCode_Size-1 downto 0); variable localspOffset: unsigned(4 downto 0); begin if dbg_in.inject='1' then tOpcode := dbg_in.opcode; else case (tOpcode_sel) is when 0 => tOpcode := std_logic_vector(rom_wb_dat_i(31 downto 24)); when 1 => tOpcode := std_logic_vector(rom_wb_dat_i(23 downto 16)); when 2 => tOpcode := std_logic_vector(rom_wb_dat_i(15 downto 8)); when 3 => tOpcode := std_logic_vector(rom_wb_dat_i(7 downto 0)); when others => null; end case; end if; sampledOpcode <= tOpcode; sampledStackOperation <= Stack_Same; sampledTosSource <= Tos_Source_None; sampledOpWillFreeze <= '0'; localspOffset(4):=not tOpcode(4); localspOffset(3 downto 0) := unsigned(tOpcode(3 downto 0)); if do_interrupt='1' and decr.im='0' then sampledDecodedOpcode <= Decoded_Interrupt; sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_PC; else if (tOpcode(7 downto 7)=OpCode_Im) then if decr.im='0' then sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_Idim0; sampledDecodedOpcode<=Decoded_Im0; else sampledTosSource <= Tos_Source_IdimN; sampledDecodedOpcode<=Decoded_ImN; end if; elsif (tOpcode(7 downto 5)=OpCode_StoreSP) then sampledStackOperation <= Stack_Pop; sampledTosSource <= Tos_Source_StackB; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Pop; sampledTosSource <= Tos_Source_StackB; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_PopDown; sampledTosSource <= Tos_Source_None; else sampledDecodedOpcode<=Decoded_StoreSP; sampledOpWillFreeze<='1'; sampledTosSource <= Tos_Source_StackB; end if; elsif (tOpcode(7 downto 5)=OpCode_LoadSP) then sampledStackOperation <= Stack_Push; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Dup; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_DupStackB; sampledTosSource <= Tos_Source_StackB; else sampledDecodedOpcode<=Decoded_LoadSP; sampledTosSource <= Tos_Source_LoadSP; end if; elsif (tOpcode(7 downto 5)=OpCode_Emulate) then -- Emulated instructions implemented in hardware if minimal_implementation then sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; else if (tOpcode(5 downto 0)=OpCode_Loadb) then sampledStackOperation<=Stack_Same; sampledDecodedOpcode<=Decoded_Loadb; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Neqbranch) then sampledStackOperation<=Stack_DualPop; sampledDecodedOpcode<=Decoded_Neqbranch; sampledOpWillFreeze <= '1'; elsif (tOpcode(5 downto 0)=OpCode_Call) then sampledDecodedOpcode<=Decoded_Call; sampledStackOperation<=Stack_Same; sampledTosSource<=Tos_Source_FetchPC; elsif (tOpcode(5 downto 0)=OpCode_Eq) then sampledDecodedOpcode<=Decoded_Eq; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Eq; elsif (tOpcode(5 downto 0)=OpCode_Ulessthan) then sampledDecodedOpcode<=Decoded_Ulessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Ulessthan; elsif (tOpcode(5 downto 0)=OpCode_Lessthan) then sampledDecodedOpcode<=Decoded_Lessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Lessthan; elsif (tOpcode(5 downto 0)=OpCode_StoreB) then sampledDecodedOpcode<=Decoded_StoreB; sampledStackOperation<=Stack_DualPop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Mult) then sampledDecodedOpcode<=Decoded_Mult; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Ashiftleft) then sampledDecodedOpcode<=Decoded_Ashiftleft; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; end if; end if; elsif (tOpcode(7 downto 4)=OpCode_AddSP) then if localspOffset=0 then sampledDecodedOpcode<=Decoded_Shift; sampledTosSource <= Tos_Source_Shift; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_AddStackB; sampledTosSource <= Tos_Source_AddStackB; else sampledDecodedOpcode<=Decoded_AddSP; sampledTosSource <= Tos_Source_AddSP; end if; else case tOpcode(3 downto 0) is when OpCode_Break => sampledDecodedOpcode<=Decoded_Break; sampledOpWillFreeze <= '1'; when OpCode_PushSP => sampledStackOperation <= Stack_Push; sampledDecodedOpcode<=Decoded_PushSP; sampledTosSource <= Tos_Source_SP; when OpCode_PopPC => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_PopPC; sampledTosSource <= Tos_Source_StackB; when OpCode_Add => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Add; sampledTosSource <= Tos_Source_Add; when OpCode_Or => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Or; sampledTosSource <= Tos_Source_Or; when OpCode_And => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_And; sampledTosSource <= Tos_Source_And; when OpCode_Load => sampledDecodedOpcode<=Decoded_Load; sampledOpWillFreeze<='1'; when OpCode_Not => sampledDecodedOpcode<=Decoded_Not; sampledTosSource <= Tos_Source_Not; when OpCode_Flip => sampledDecodedOpcode<=Decoded_Flip; sampledTosSource <= Tos_Source_Flip; when OpCode_Store => sampledStackOperation <= Stack_DualPop; sampledDecodedOpcode<=Decoded_Store; sampledOpWillFreeze<='1'; when OpCode_PopSP => sampledDecodedOpcode<=Decoded_PopSP; sampledOpWillFreeze<='1'; when OpCode_NA4 => if enable_fmul16 then sampledDecodedOpcode<=Decoded_MultF16; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Nop; end if; when others => sampledDecodedOpcode<=Decoded_Nop; end case; end if; end if; sampledspOffset <= localspOffset; end process; -- Decode/Fetch unit rom_wb_stb_o <= not exu_busy; process(decr, jump_address, decode_jump, wb_clk_i, sp_load, sampledDecodedOpcode,sampledOpcode,decode_load_sp, exu_busy, pfu_busy, pcnext, rom_wb_ack_i, wb_rst_i, sampledStackOperation, sampledspOffset, sampledTosSource, prefr.recompute_sp, sampledOpWillFreeze, dbg_in.flush, dbg_in.inject,dbg_in.injectmode, prefr.valid, prefr.break, rom_wb_stall_i ) variable w: decoderegs_type; begin w := decr; pcnext <= decr.fetchpc + 1; rom_wb_adr_o <= std_logic_vector(pc_to_memaddr(decr.fetchpc)); rom_wb_cti_o <= CTI_CYCLE_INCRADDR; if wb_rst_i='1' then w.pc := (others => '0'); w.pcint := (others => '0'); w.valid := '0'; w.fetchpc := (others => '0'); w.im:='0'; w.im_emu:='0'; w.state := State_Run; w.break := '0'; rom_wb_cyc_o <= '0'; else rom_wb_cyc_o <= '1'; case decr.state is when State_Run => if pfu_busy='0' then if dbg_in.injectmode='0' and decr.break='0' and rom_wb_stall_i='0' then w.fetchpc := pcnext; end if; -- Jump request if decode_jump='1' then w.valid := '0'; w.im := '0'; w.break := '0'; -- Invalidate eventual break after branch instruction --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o<='0'; --if rom_wb_stall_i='0' then w.fetchpc := jump_address; --else w.state := State_Jump; --end if; else if dbg_in.injectmode='1' then --or decr.break='1' then -- At this point we ought to push a new op into the pipeline. -- Since we're entering inject mode, invalidate next operation, -- but save the current IM flag. w.im_emu := decr.im; w.valid := '0'; --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o <='0'; -- Wait until no work is to be done if prefr.valid='0' and decr.valid='0' and exu_busy='0' then w.state := State_Inject; w.im:='0'; end if; if decr.break='0' then w.pc := decr.pcint; end if; else if decr.break='1' then w.valid := '0'; else w.valid := rom_wb_ack_i; end if; if rom_wb_ack_i='1' then w.im := sampledOpcode(7); if sampledDecodedOpcode=Decoded_Break then w.break:='1'; end if; end if; if prefr.break='0' and rom_wb_stall_i='0' then w.pcint := decr.fetchpc; w.pc := decr.pcint; end if; if rom_wb_stall_i='0' then w.opcode := sampledOpcode; end if; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; when State_Jump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Run; when State_InjectJump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Inject; when State_Inject => -- NOTE: disable ROM rom_wb_cyc_o <= '0'; if dbg_in.injectmode='0' then w.im := decr.im_emu; w.fetchpc := decr.pcint; w.state := State_Run; w.break := '0'; else -- Handle opcode injection -- TODO: merge this with main decode. -- NOTE: we don't check busy here, it's up to debug unit to do it --if pfu_busy='0' then --w.fetchpc := pcnext; -- Jump request if decode_jump='1' then w.fetchpc := jump_address; w.valid := '0'; w.im := '0'; w.state := State_InjectJump; else w.valid := dbg_in.inject; if dbg_in.inject='1' then w.im := sampledOpcode(7); --w.break := '0'; --w.pcint := decr.fetchpc; w.opcode := sampledOpcode; --w.pc := decr.pcint; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; --end if; end case; end if; -- rst if rising_edge(wb_clk_i) then decr <= w; end if; end process; -- Prefetch/Load unit. sp_load <= exr.tos(spMaxBit downto 2); -- Will be delayed one clock cycle process(wb_clk_i, wb_rst_i, decr, prefr, exu_busy, decode_jump, sp_load, decode_load_sp, dbg_in.flush) variable w: prefetchregs_type; variable i_op_freeze: std_logic; begin w := prefr; pfu_busy<='0'; stack_b_addr <= std_logic_vector(prefr.spnext + 1); w.recompute_sp:='0'; -- Stack w.load := decode_load_sp; if decode_load_sp='1' then pfu_busy <= '1'; w.spnext := sp_load; w.recompute_sp := '1'; else pfu_busy <= exu_busy; if decr.valid='1' then if (exu_busy='0' and decode_jump='0') or prefr.recompute_sp='1' then case decr.stackOperation is when Stack_Push => w.spnext := prefr.spnext - 1; when Stack_Pop => w.spnext := prefr.spnext + 1; when Stack_DualPop => w.spnext := prefr.spnext + 2; when others => end case; w.sp := prefr.spnext; end if; end if; end if; case decr.decodedOpcode is when Decoded_LoadSP | decoded_AddSP => stack_b_addr <= std_logic_vector(prefr.spnext + decr.spOffset); when others => end case; if decode_jump='1' then -- this is a pipeline "invalidate" flag. w.valid := '0'; else if dbg_in.flush='1' then w.valid := '0'; else w.valid := decr.valid; end if; end if; -- Moved op_will_freeze from decoder to here case decr.decodedOpcode is when Decoded_StoreSP | Decoded_LoadB | Decoded_Neqbranch | Decoded_StoreB | Decoded_Mult | Decoded_Ashiftleft | Decoded_Break | Decoded_Load | Decoded_Store | Decoded_PopSP | Decoded_MultF16 => i_op_freeze := '1'; when others => i_op_freeze := '0'; end case; if exu_busy='0' then w.decodedOpcode := decr.decodedOpcode; w.tosSource := decr.tosSource; w.opcode := decr.opcode; w.opWillFreeze := i_op_freeze; w.pc := decr.pc; w.fetchpc := decr.pcint; w.idim := decr.idim; w.break := decr.break; end if; if wb_rst_i='1' then w.spnext := unsigned(spStart(10 downto 2)); --w.sp := unsigned(spStart(10 downto 2)); w.valid := '0'; w.idim := '0'; w.recompute_sp:='0'; end if; if rising_edge(wb_clk_i) then prefr <= w; end if; end process; process(prefr,exr,nos) begin trace_pc <= (others => '0'); trace_pc(maxAddrBit downto 0) <= std_logic_vector(prefr.pc); trace_opcode <= prefr.opcode; trace_sp <= (others => '0'); trace_sp(10 downto 2) <= std_logic_vector(prefr.sp); trace_topOfStack <= std_logic_vector( exr.tos ); trace_topOfStackB <= std_logic_vector( nos ); end process; -- IO/Memory Accesses wb_adr_o(maxAddrBitIncIO downto 0) <= std_logic_vector(exr.tos_save(maxAddrBitIncIO downto 0)); wb_cyc_o <= exr.wb_cyc; wb_stb_o <= exr.wb_stb; wb_we_o <= exr.wb_we; wb_dat_o <= std_logic_vector( exr.nos_save ); freeze_all <= dbg_in.freeze; process(exr, wb_inta_i, wb_clk_i, wb_rst_i, pcnext, stack_a_read,stack_b_read, wb_ack_i, wb_dat_i, do_interrupt,exr, prefr, nos, single_step, freeze_all, dbg_in.step, wroteback_q,lshifter_done,lshifter_output ) variable spOffset: unsigned(4 downto 0); variable w: exuregs_type; variable instruction_executed: std_logic; variable wroteback: std_logic; begin w := exr; instruction_executed := '0'; -- used for single stepping stack_b_writeenable <= '0'; stack_a_enable <= '1'; stack_b_enable <= '1'; exu_busy <= '0'; decode_jump <= '0'; jump_address <= (others => DontCareValue); lshifter_enable <= '0'; lshifter_amount <= std_logic_vector(exr.tos_save); lshifter_input <= std_logic_vector(exr.nos_save); lshifter_multorshift <= '0'; poppc_inst <= '0'; begin_inst<='0'; stack_a_addr <= std_logic_vector( prefr.sp ); stack_a_writeenable <= '0'; wroteback := wroteback_q; stack_b_writeenable <= '0'; stack_a_write <= std_logic_vector(exr.tos); spOffset(4):=not prefr.opcode(4); spOffset(3 downto 0) := unsigned(prefr.opcode(3 downto 0)); if wb_inta_i='0' then w.inInterrupt := '0'; end if; stack_b_write<=(others => DontCareValue); if wroteback_q='1' then nos <= unsigned(stack_a_read); else nos <= unsigned(stack_b_read); end if; decode_load_sp <= '0'; case exr.state is when State_Resync1 => exu_busy <= '1'; stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_ResyncFromStoreStack => exu_busy <= '1'; stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_Resync2 => w.tos := unsigned(stack_a_read); instruction_executed := '1'; exu_busy <= '0'; wroteback := '0'; stack_b_enable <= '1'; w.state := State_Execute; when State_Execute => instruction_executed:='0'; if prefr.valid='1' then exu_busy <= prefr.opWillFreeze; if freeze_all='0' or single_step='1' then wroteback := '0'; w.nos_save := nos; w.tos_save := exr.tos; w.idim := prefr.idim; w.break:= prefr.break; begin_inst<='1'; instruction_executed := '1'; -- TOS big muxer case prefr.tosSource is when Tos_Source_PC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.pc; when Tos_Source_FetchPC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.fetchpc; when Tos_Source_Idim0 => for i in wordSize-1 downto 7 loop w.tos(i) := prefr.opcode(6); end loop; w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_IdimN => w.tos(wordSize-1 downto 7) := exr.tos(wordSize-8 downto 0); w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_StackB => w.tos := nos; when Tos_Source_SP => w.tos := (others => '0'); w.tos(31) := '1'; -- Stack address w.tos(10 downto 2) := prefr.sp; when Tos_Source_Add => w.tos := exr.tos + nos; when Tos_Source_And => w.tos := exr.tos and nos; when Tos_Source_Or => w.tos := exr.tos or nos; when Tos_Source_Eq => w.tos := (others => '0'); if nos = exr.tos then w.tos(0) := '1'; end if; when Tos_Source_Ulessthan => w.tos := (others => '0'); if exr.tos < nos then w.tos(0) := '1'; end if; when Tos_Source_Lessthan => w.tos := (others => '0'); if signed(exr.tos) < signed(nos) then w.tos(0) := '1'; end if; when Tos_Source_Not => w.tos := not exr.tos; when Tos_Source_Flip => for i in 0 to wordSize-1 loop w.tos(i) := exr.tos(wordSize-1-i); end loop; when Tos_Source_LoadSP => w.tos := unsigned(stack_b_read); when Tos_Source_AddSP => w.tos := w.tos + unsigned(stack_b_read); when Tos_Source_AddStackB => w.tos := w.tos + nos; when Tos_Source_Shift => w.tos := exr.tos + exr.tos; when others => end case; case prefr.decodedOpcode is when Decoded_Interrupt => w.inInterrupt := '1'; jump_address <= to_unsigned(32, maxAddrBit+1); decode_jump <= '1'; stack_a_writeenable<='1'; wroteback:='1'; stack_b_enable<='0'; instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Im0 => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_ImN => when Decoded_Nop => when Decoded_PopPC | Decoded_Call => decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0); poppc_inst <= '1'; stack_b_enable<='0'; -- Delay instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Emulate => decode_jump <= '1'; jump_address <= (others => '0'); jump_address(9 downto 5) <= unsigned(prefr.opcode(4 downto 0)); stack_a_writeenable<='1'; wroteback:='1'; when Decoded_PushSP => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_LoadSP => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_DupStackB => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_Dup => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_AddSP => stack_a_writeenable <= '1'; when Decoded_StoreSP => stack_a_writeenable <= '1'; wroteback:='1'; stack_a_addr <= std_logic_vector(prefr.sp + spOffset); instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_PopDown => stack_a_writeenable<='1'; when Decoded_Pop => when Decoded_Ashiftleft => w.state := State_Ashiftleft; when Decoded_Mult => w.state := State_Mult; when Decoded_MultF16 => w.state := State_MultF16; when Decoded_Store => if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(nos); stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when Decoded_Load | Decoded_Loadb | Decoded_StoreB => --w.tos_save := exr.tos; -- Byte select instruction_executed := '0'; wroteback := wroteback_q; -- Keep WB if exr.tos(wordSize-1)='1' then stack_a_addr<=std_logic_vector(exr.tos(10 downto 2)); stack_a_enable<='1'; w.state := State_LoadStack; else stack_a_enable <= '0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); w.wb_we :='0'; w.wb_cyc :='1'; w.wb_stb :='1'; w.state := State_Load; end if; when Decoded_PopSP => decode_load_sp <= '1'; instruction_executed := '0'; stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); w.state := State_Resync2; --when Decoded_Break => -- w.break := '1'; when Decoded_Neqbranch => instruction_executed := '0'; w.state := State_NeqBranch; when others => end case; else -- freeze_all -- -- Freeze the entire pipeline. -- exu_busy<='1'; stack_a_enable<='0'; stack_b_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); end if; end if; -- valid when State_Ashiftleft => exu_busy <= '1'; lshifter_enable <= '1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_Mult => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_MultF16 => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(47 downto 16)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_WaitSPB => instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Store => exu_busy <= '1'; -- Keep writeback flag wroteback := wroteback_q; if wb_ack_i='1' then stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; stack_b_enable<='1'; wroteback := '0'; --exu_busy <= '1'; w.wb_cyc := '0'; w.state := State_Resync2; else stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_a_enable<='0'; stack_b_enable<='0'; end if; when State_Loadb => w.tos(wordSize-1 downto 8) := (others => '0'); case exr.tos_save(1 downto 0) is when "11" => w.tos(7 downto 0) := unsigned(exr.tos(7 downto 0)); when "10" => w.tos(7 downto 0) := unsigned(exr.tos(15 downto 8)); when "01" => w.tos(7 downto 0) := unsigned(exr.tos(23 downto 16)); when "00" => w.tos(7 downto 0) := unsigned(exr.tos(31 downto 24)); when others => null; end case; instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Load => if wb_ack_i='0' then exu_busy<='1'; else w.tos := unsigned(wb_dat_i); w.wb_cyc := '0'; if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state := State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state := State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; end if; when State_LoadStack => w.tos := unsigned(stack_a_read); if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state:=State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state:=State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; when State_NeqBranch => if exr.nos_save/=0 then decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0) + prefr.pc; poppc_inst <= '1'; exu_busy <= '0'; else exu_busy <='1'; end if; instruction_executed := '0'; stack_a_addr <= std_logic_vector(prefr.spnext); wroteback:='0'; w.state := State_Resync2; when State_StoreB => exu_busy <= '1'; -- -- At this point, we have loaded the 32-bit, and it's in TOS -- The IO address is still saved in save_TOS. -- The original write value is still at save_NOS -- -- So we mangle the write value, and update save_NOS, and restore -- the IO address to TOS -- -- This is still buggy - don't use. Problems arise when writing to stack. -- w.nos_save := exr.tos; case exr.tos_save(1 downto 0) is when "00" => w.nos_save(31 downto 24) := exr.nos_save(7 downto 0); when "01" => w.nos_save(23 downto 16) := exr.nos_save(7 downto 0); when "10" => w.nos_save(15 downto 8) := exr.nos_save(7 downto 0); when "11" => w.nos_save(7 downto 0) := exr.nos_save(7 downto 0); when others => null; end case; w.tos := exr.tos_save; w.state := State_StoreB2; when State_StoreB2 => exu_busy <= '1'; if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(exr.nos_save); -- hmm I don't like this stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when others => null; end case; if rising_edge(wb_clk_i) then if wb_rst_i='1' then exr.state <= State_Execute; exr.idim <= DontCareValue; exr.inInterrupt <= '0'; exr.break <= '0'; exr.wb_cyc <= '0'; exr.wb_stb <= '1'; else exr <= w; -- TODO: move wroteback_q into EXU regs wroteback_q <= wroteback; if exr.break='1' then report "BREAK" severity failure; end if; -- Some sanity checks, to be caught in simulation if prefr.valid='1' then if prefr.tosSource=Tos_Source_Idim0 and prefr.idim='1' then report "Invalid IDIM flag 0" severity error; end if; if prefr.tosSource=Tos_Source_IdimN and prefr.idim='0' then report "Invalid IDIM flag 1" severity error; end if; end if; end if; end if; end process; single_step <= dbg_in.step; dbg_out.valid <= '1' when prefr.valid='1' else '0'; -- Let pipeline finish dbg_out.ready <= '1' when exr.state=state_execute and decode_load_sp='0' and decode_jump='0' and decr.state = State_Inject --and jump_q='0' else '0'; end behave;
-- ZPU -- -- Copyright 2004-2008 oharboe - Øyvind Harboe - [email protected] -- Copyright 2010-2012 Alvaro Lopes - [email protected] -- -- The FreeBSD license -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions -- are met: -- -- 1. Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer. -- 2. Redistributions in binary form must reproduce the above -- copyright notice, this list of conditions and the following -- disclaimer in the documentation and/or other materials -- provided with the distribution. -- -- THIS SOFTWARE IS PROVIDED BY THE ZPU PROJECT ``AS IS'' AND ANY -- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -- ZPU PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- The views and conclusions contained in the software and documentation -- are those of the authors and should not be interpreted as representing -- official policies, either expressed or implied, of the ZPU Project. library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.numeric_std.all; library board; use board.zpu_config.all; use board.zpupkg.all; use board.wishbonepkg.all; --library UNISIM; --use UNISIM.vcomponents.all; entity zpu_core_extreme is port ( wb_clk_i: in std_logic; wb_rst_i: in std_logic; -- Master wishbone interface wb_ack_i: in std_logic; wb_dat_i: in std_logic_vector(wordSize-1 downto 0); wb_dat_o: out std_logic_vector(wordSize-1 downto 0); wb_adr_o: out std_logic_vector(maxAddrBitIncIO downto 0); wb_cyc_o: out std_logic; wb_stb_o: out std_logic; wb_we_o: out std_logic; wb_inta_i: in std_logic; poppc_inst: out std_logic; break: out std_logic; -- STACK stack_a_read: in std_logic_vector(wordSize-1 downto 0); stack_b_read: in std_logic_vector(wordSize-1 downto 0); stack_a_write: out std_logic_vector(wordSize-1 downto 0); stack_b_write: out std_logic_vector(wordSize-1 downto 0); stack_a_writeenable: out std_logic; stack_a_enable: out std_logic; stack_b_writeenable: out std_logic; stack_b_enable: out std_logic; stack_a_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_b_addr: out std_logic_vector(stackSize_bits+1 downto 2); stack_clk: out std_logic; -- ROM wb interface rom_wb_ack_i: in std_logic; rom_wb_dat_i: in std_logic_vector(wordSize-1 downto 0); rom_wb_adr_o: out std_logic_vector(maxAddrBit downto 0); rom_wb_cyc_o: out std_logic; rom_wb_stb_o: out std_logic; rom_wb_cti_o: out std_logic_vector(2 downto 0); rom_wb_stall_i: in std_logic; -- Debug interface dbg_out: out zpu_dbg_out_type; dbg_in: in zpu_dbg_in_type ); end zpu_core_extreme; architecture behave of zpu_core_extreme is component lshifter is port ( clk: in std_logic; rst: in std_logic; enable: in std_logic; done: out std_logic; inputA: in std_logic_vector(31 downto 0); inputB: in std_logic_vector(31 downto 0); output: out std_logic_vector(63 downto 0); multorshift: in std_logic ); end component; signal lshifter_enable: std_logic; signal lshifter_done: std_logic; signal lshifter_input: std_logic_vector(31 downto 0); signal lshifter_amount: std_logic_vector(31 downto 0); signal lshifter_output: std_logic_vector(63 downto 0); signal lshifter_multorshift: std_logic; signal begin_inst: std_logic; signal trace_opcode: std_logic_vector(7 downto 0); signal trace_pc: std_logic_vector(maxAddrBitIncIO downto 0); signal trace_sp: std_logic_vector(maxAddrBitIncIO downto minAddrBit); signal trace_topOfStack: std_logic_vector(wordSize-1 downto 0); signal trace_topOfStackB: std_logic_vector(wordSize-1 downto 0); -- state machine. type State_Type is ( State_Execute, State_Store, State_StoreB, State_StoreB2, State_Load, State_LoadMemory, State_LoadStack, State_Loadb, State_Resync1, State_Resync2, State_LoadSP, State_WaitSPB, State_ResyncFromStoreStack, State_Neqbranch, State_Ashiftleft, State_Mult, State_MultF16 ); type DecodedOpcodeType is ( Decoded_Nop, Decoded_Idle, Decoded_Im0, Decoded_ImN, Decoded_LoadSP, Decoded_Dup, Decoded_DupStackB, Decoded_StoreSP, Decoded_Pop, Decoded_PopDown, Decoded_AddSP, Decoded_AddStackB, Decoded_Shift, Decoded_Emulate, Decoded_Break, Decoded_PushSP, Decoded_PopPC, Decoded_Add, Decoded_Or, Decoded_And, Decoded_Load, Decoded_Not, Decoded_Flip, Decoded_Store, Decoded_PopSP, Decoded_Interrupt, Decoded_Neqbranch, Decoded_Eq, Decoded_Storeb, Decoded_Storeh, Decoded_Ulessthan, Decoded_Lessthan, Decoded_Ashiftleft, Decoded_Ashiftright, Decoded_Loadb, Decoded_Call, Decoded_Mult, Decoded_MultF16 ); constant spMaxBit: integer := 10; constant minimal_implementation: boolean := false; subtype index is integer range 0 to 3; signal tOpcode_sel : index; function pc_to_cpuword(pc: unsigned) return unsigned is variable r: unsigned(wordSize-1 downto 0); begin r := (others => DontCareValue); r(maxAddrBit downto 0) := pc; return r; end pc_to_cpuword; function pc_to_memaddr(pc: unsigned) return unsigned is variable r: unsigned(maxAddrBit downto 0); begin r := (others => '0'); r(maxAddrBit downto minAddrBit) := pc(maxAddrBit downto minAddrBit); return r; end pc_to_memaddr; -- Prefetch stage registers type stackChangeType is ( Stack_Same, Stack_Push, Stack_Pop, Stack_DualPop ); type tosSourceType is ( Tos_Source_PC, Tos_Source_FetchPC, Tos_Source_Idim0, Tos_Source_IdimN, Tos_Source_StackB, Tos_Source_SP, Tos_Source_Add, Tos_Source_And, Tos_Source_Or, Tos_Source_Eq, Tos_Source_Not, Tos_Source_Flip, Tos_Source_LoadSP, Tos_Source_AddSP, Tos_Source_AddStackB, Tos_Source_Shift, Tos_Source_Ulessthan, Tos_Source_Lessthan, Tos_Source_None ); type decoderstate_type is ( State_Run, State_Jump, State_Inject, State_InjectJump ); type decoderegs_type is record valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opWillFreeze: std_logic; -- '1' if we know in advance this opcode will freeze pipeline opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); pcint: unsigned(maxAddrBit downto 0); idim: std_logic; im: std_logic; stackOperation: stackChangeType; spOffset: unsigned(4 downto 0); im_emu: std_logic; --emumode: std_logic; break: std_logic; state: decoderstate_type; end record; type prefetchregs_type is record sp: unsigned(spMaxBit downto 2); spnext: unsigned(spMaxBit downto 2); valid: std_logic; decodedOpcode: DecodedOpcodeType; tosSource: tosSourceType; opcode: std_logic_vector(OpCode_Size-1 downto 0); pc: unsigned(maxAddrBit downto 0); fetchpc: unsigned(maxAddrBit downto 0); idim: std_logic; break: std_logic; load: std_logic; opWillFreeze: std_logic; recompute_sp: std_logic; end record; type exuregs_type is record idim: std_logic; break: std_logic; inInterrupt:std_logic; tos: unsigned(wordSize-1 downto 0); tos_save: unsigned(wordSize-1 downto 0); nos_save: unsigned(wordSize-1 downto 0); state: State_Type; -- Wishbone control signals (registered) wb_cyc: std_logic; wb_stb: std_logic; wb_we: std_logic; end record; -- Registers for each stage signal exr: exuregs_type; signal prefr: prefetchregs_type; signal decr: decoderegs_type; signal pcnext: unsigned(maxAddrBit downto 0); -- Helper only. TODO: move into variable signal sp_load: unsigned(spMaxBit downto 2); -- SP value to load, coming from EXU into PFU signal decode_load_sp: std_logic; -- Load SP signal from EXU to PFU signal exu_busy: std_logic; -- EXU busy ( stalls PFU ) signal pfu_busy: std_logic; -- PFU busy ( stalls DFU ) signal decode_jump: std_logic; -- Jump signal from EXU to DFU signal jump_address: unsigned(maxAddrBit downto 0); -- Jump address from EXU to DFU signal do_interrupt: std_logic; -- Helper. -- Sampled signals from the opcode. Left as signals -- in order to simulate design. signal sampledOpcode: std_logic_vector(OpCode_Size-1 downto 0); signal sampledDecodedOpcode: DecodedOpcodeType; signal sampledOpWillFreeze: std_logic; signal sampledStackOperation: stackChangeType; signal sampledspOffset: unsigned(4 downto 0); signal sampledTosSource: tosSourceType; signal nos: unsigned(wordSize-1 downto 0); -- This is only a helper signal wroteback_q: std_logic; -- TODO: get rid of this here, move to EXU regs -- Test debug signals signal freeze_all: std_logic := '0'; signal single_step: std_logic := '0'; begin -- Debug interface dbg_out.pc <= std_logic_vector(prefr.pc); dbg_out.opcode <= prefr.opcode; dbg_out.sp <= std_logic_vector(prefr.sp); dbg_out.brk <= exr.break; dbg_out.stacka <= std_logic_vector(exr.tos); dbg_out.stackb <= std_logic_vector(nos); dbg_out.idim <= prefr.idim; shl: lshifter port map ( clk => wb_clk_i, rst => wb_rst_i, enable => lshifter_enable, done => lshifter_done, inputA => lshifter_input, inputB => lshifter_amount, output => lshifter_output, multorshift => lshifter_multorshift ); stack_clk <= wb_clk_i; traceFileGenerate: if Generate_Trace generate trace_file: trace port map ( clk => wb_clk_i, begin_inst => begin_inst, pc => trace_pc, opcode => trace_opcode, sp => trace_sp, memA => trace_topOfStack, memB => trace_topOfStackB, busy => '0',--busy, intsp => (others => 'U') ); end generate; tOpcode_sel <= to_integer(decr.pcint(minAddrBit-1 downto 0)); do_interrupt <= '1' when wb_inta_i='1' and exr.inInterrupt='0' else '0'; decodeControl: process(rom_wb_dat_i, tOpcode_sel, sp_load, decr, do_interrupt, dbg_in.inject, dbg_in.opcode) variable tOpcode : std_logic_vector(OpCode_Size-1 downto 0); variable localspOffset: unsigned(4 downto 0); begin if dbg_in.inject='1' then tOpcode := dbg_in.opcode; else case (tOpcode_sel) is when 0 => tOpcode := std_logic_vector(rom_wb_dat_i(31 downto 24)); when 1 => tOpcode := std_logic_vector(rom_wb_dat_i(23 downto 16)); when 2 => tOpcode := std_logic_vector(rom_wb_dat_i(15 downto 8)); when 3 => tOpcode := std_logic_vector(rom_wb_dat_i(7 downto 0)); when others => null; end case; end if; sampledOpcode <= tOpcode; sampledStackOperation <= Stack_Same; sampledTosSource <= Tos_Source_None; sampledOpWillFreeze <= '0'; localspOffset(4):=not tOpcode(4); localspOffset(3 downto 0) := unsigned(tOpcode(3 downto 0)); if do_interrupt='1' and decr.im='0' then sampledDecodedOpcode <= Decoded_Interrupt; sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_PC; else if (tOpcode(7 downto 7)=OpCode_Im) then if decr.im='0' then sampledStackOperation <= Stack_Push; sampledTosSource <= Tos_Source_Idim0; sampledDecodedOpcode<=Decoded_Im0; else sampledTosSource <= Tos_Source_IdimN; sampledDecodedOpcode<=Decoded_ImN; end if; elsif (tOpcode(7 downto 5)=OpCode_StoreSP) then sampledStackOperation <= Stack_Pop; sampledTosSource <= Tos_Source_StackB; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Pop; sampledTosSource <= Tos_Source_StackB; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_PopDown; sampledTosSource <= Tos_Source_None; else sampledDecodedOpcode<=Decoded_StoreSP; sampledOpWillFreeze<='1'; sampledTosSource <= Tos_Source_StackB; end if; elsif (tOpcode(7 downto 5)=OpCode_LoadSP) then sampledStackOperation <= Stack_Push; if localspOffset=0 then sampledDecodedOpcode<=Decoded_Dup; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_DupStackB; sampledTosSource <= Tos_Source_StackB; else sampledDecodedOpcode<=Decoded_LoadSP; sampledTosSource <= Tos_Source_LoadSP; end if; elsif (tOpcode(7 downto 5)=OpCode_Emulate) then -- Emulated instructions implemented in hardware if minimal_implementation then sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; else if (tOpcode(5 downto 0)=OpCode_Loadb) then sampledStackOperation<=Stack_Same; sampledDecodedOpcode<=Decoded_Loadb; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Neqbranch) then sampledStackOperation<=Stack_DualPop; sampledDecodedOpcode<=Decoded_Neqbranch; sampledOpWillFreeze <= '1'; elsif (tOpcode(5 downto 0)=OpCode_Call) then sampledDecodedOpcode<=Decoded_Call; sampledStackOperation<=Stack_Same; sampledTosSource<=Tos_Source_FetchPC; elsif (tOpcode(5 downto 0)=OpCode_Eq) then sampledDecodedOpcode<=Decoded_Eq; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Eq; elsif (tOpcode(5 downto 0)=OpCode_Ulessthan) then sampledDecodedOpcode<=Decoded_Ulessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Ulessthan; elsif (tOpcode(5 downto 0)=OpCode_Lessthan) then sampledDecodedOpcode<=Decoded_Lessthan; sampledStackOperation<=Stack_Pop; sampledTosSource<=Tos_Source_Lessthan; elsif (tOpcode(5 downto 0)=OpCode_StoreB) then sampledDecodedOpcode<=Decoded_StoreB; sampledStackOperation<=Stack_DualPop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Mult) then sampledDecodedOpcode<=Decoded_Mult; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; elsif (tOpcode(5 downto 0)=OpCode_Ashiftleft) then sampledDecodedOpcode<=Decoded_Ashiftleft; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Emulate; sampledStackOperation<=Stack_Push; -- will push PC sampledTosSource <= Tos_Source_FetchPC; end if; end if; elsif (tOpcode(7 downto 4)=OpCode_AddSP) then if localspOffset=0 then sampledDecodedOpcode<=Decoded_Shift; sampledTosSource <= Tos_Source_Shift; elsif localspOffset=1 then sampledDecodedOpcode<=Decoded_AddStackB; sampledTosSource <= Tos_Source_AddStackB; else sampledDecodedOpcode<=Decoded_AddSP; sampledTosSource <= Tos_Source_AddSP; end if; else case tOpcode(3 downto 0) is when OpCode_Break => sampledDecodedOpcode<=Decoded_Break; sampledOpWillFreeze <= '1'; when OpCode_PushSP => sampledStackOperation <= Stack_Push; sampledDecodedOpcode<=Decoded_PushSP; sampledTosSource <= Tos_Source_SP; when OpCode_PopPC => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_PopPC; sampledTosSource <= Tos_Source_StackB; when OpCode_Add => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Add; sampledTosSource <= Tos_Source_Add; when OpCode_Or => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_Or; sampledTosSource <= Tos_Source_Or; when OpCode_And => sampledStackOperation <= Stack_Pop; sampledDecodedOpcode<=Decoded_And; sampledTosSource <= Tos_Source_And; when OpCode_Load => sampledDecodedOpcode<=Decoded_Load; sampledOpWillFreeze<='1'; when OpCode_Not => sampledDecodedOpcode<=Decoded_Not; sampledTosSource <= Tos_Source_Not; when OpCode_Flip => sampledDecodedOpcode<=Decoded_Flip; sampledTosSource <= Tos_Source_Flip; when OpCode_Store => sampledStackOperation <= Stack_DualPop; sampledDecodedOpcode<=Decoded_Store; sampledOpWillFreeze<='1'; when OpCode_PopSP => sampledDecodedOpcode<=Decoded_PopSP; sampledOpWillFreeze<='1'; when OpCode_NA4 => if enable_fmul16 then sampledDecodedOpcode<=Decoded_MultF16; sampledStackOperation<=Stack_Pop; sampledOpWillFreeze<='1'; else sampledDecodedOpcode<=Decoded_Nop; end if; when others => sampledDecodedOpcode<=Decoded_Nop; end case; end if; end if; sampledspOffset <= localspOffset; end process; -- Decode/Fetch unit rom_wb_stb_o <= not exu_busy; process(decr, jump_address, decode_jump, wb_clk_i, sp_load, sampledDecodedOpcode,sampledOpcode,decode_load_sp, exu_busy, pfu_busy, pcnext, rom_wb_ack_i, wb_rst_i, sampledStackOperation, sampledspOffset, sampledTosSource, prefr.recompute_sp, sampledOpWillFreeze, dbg_in.flush, dbg_in.inject,dbg_in.injectmode, prefr.valid, prefr.break, rom_wb_stall_i ) variable w: decoderegs_type; begin w := decr; pcnext <= decr.fetchpc + 1; rom_wb_adr_o <= std_logic_vector(pc_to_memaddr(decr.fetchpc)); rom_wb_cti_o <= CTI_CYCLE_INCRADDR; if wb_rst_i='1' then w.pc := (others => '0'); w.pcint := (others => '0'); w.valid := '0'; w.fetchpc := (others => '0'); w.im:='0'; w.im_emu:='0'; w.state := State_Run; w.break := '0'; rom_wb_cyc_o <= '0'; else rom_wb_cyc_o <= '1'; case decr.state is when State_Run => if pfu_busy='0' then if dbg_in.injectmode='0' and decr.break='0' and rom_wb_stall_i='0' then w.fetchpc := pcnext; end if; -- Jump request if decode_jump='1' then w.valid := '0'; w.im := '0'; w.break := '0'; -- Invalidate eventual break after branch instruction --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o<='0'; --if rom_wb_stall_i='0' then w.fetchpc := jump_address; --else w.state := State_Jump; --end if; else if dbg_in.injectmode='1' then --or decr.break='1' then -- At this point we ought to push a new op into the pipeline. -- Since we're entering inject mode, invalidate next operation, -- but save the current IM flag. w.im_emu := decr.im; w.valid := '0'; --rom_wb_cti_o <= CTI_CYCLE_ENDOFBURST; rom_wb_cyc_o <='0'; -- Wait until no work is to be done if prefr.valid='0' and decr.valid='0' and exu_busy='0' then w.state := State_Inject; w.im:='0'; end if; if decr.break='0' then w.pc := decr.pcint; end if; else if decr.break='1' then w.valid := '0'; else w.valid := rom_wb_ack_i; end if; if rom_wb_ack_i='1' then w.im := sampledOpcode(7); if sampledDecodedOpcode=Decoded_Break then w.break:='1'; end if; end if; if prefr.break='0' and rom_wb_stall_i='0' then w.pcint := decr.fetchpc; w.pc := decr.pcint; end if; if rom_wb_stall_i='0' then w.opcode := sampledOpcode; end if; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; when State_Jump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Run; when State_InjectJump => w.valid := '0'; w.pcint := decr.fetchpc; w.fetchpc := pcnext; w.state := State_Inject; when State_Inject => -- NOTE: disable ROM rom_wb_cyc_o <= '0'; if dbg_in.injectmode='0' then w.im := decr.im_emu; w.fetchpc := decr.pcint; w.state := State_Run; w.break := '0'; else -- Handle opcode injection -- TODO: merge this with main decode. -- NOTE: we don't check busy here, it's up to debug unit to do it --if pfu_busy='0' then --w.fetchpc := pcnext; -- Jump request if decode_jump='1' then w.fetchpc := jump_address; w.valid := '0'; w.im := '0'; w.state := State_InjectJump; else w.valid := dbg_in.inject; if dbg_in.inject='1' then w.im := sampledOpcode(7); --w.break := '0'; --w.pcint := decr.fetchpc; w.opcode := sampledOpcode; --w.pc := decr.pcint; end if; end if; w.opWillFreeze := sampledOpWillFreeze; w.decodedOpcode := sampledDecodedOpcode; w.stackOperation := sampledStackOperation; w.spOffset := sampledspOffset; w.tosSource := sampledTosSource; w.idim := decr.im; end if; --end if; end case; end if; -- rst if rising_edge(wb_clk_i) then decr <= w; end if; end process; -- Prefetch/Load unit. sp_load <= exr.tos(spMaxBit downto 2); -- Will be delayed one clock cycle process(wb_clk_i, wb_rst_i, decr, prefr, exu_busy, decode_jump, sp_load, decode_load_sp, dbg_in.flush) variable w: prefetchregs_type; variable i_op_freeze: std_logic; begin w := prefr; pfu_busy<='0'; stack_b_addr <= std_logic_vector(prefr.spnext + 1); w.recompute_sp:='0'; -- Stack w.load := decode_load_sp; if decode_load_sp='1' then pfu_busy <= '1'; w.spnext := sp_load; w.recompute_sp := '1'; else pfu_busy <= exu_busy; if decr.valid='1' then if (exu_busy='0' and decode_jump='0') or prefr.recompute_sp='1' then case decr.stackOperation is when Stack_Push => w.spnext := prefr.spnext - 1; when Stack_Pop => w.spnext := prefr.spnext + 1; when Stack_DualPop => w.spnext := prefr.spnext + 2; when others => end case; w.sp := prefr.spnext; end if; end if; end if; case decr.decodedOpcode is when Decoded_LoadSP | decoded_AddSP => stack_b_addr <= std_logic_vector(prefr.spnext + decr.spOffset); when others => end case; if decode_jump='1' then -- this is a pipeline "invalidate" flag. w.valid := '0'; else if dbg_in.flush='1' then w.valid := '0'; else w.valid := decr.valid; end if; end if; -- Moved op_will_freeze from decoder to here case decr.decodedOpcode is when Decoded_StoreSP | Decoded_LoadB | Decoded_Neqbranch | Decoded_StoreB | Decoded_Mult | Decoded_Ashiftleft | Decoded_Break | Decoded_Load | Decoded_Store | Decoded_PopSP | Decoded_MultF16 => i_op_freeze := '1'; when others => i_op_freeze := '0'; end case; if exu_busy='0' then w.decodedOpcode := decr.decodedOpcode; w.tosSource := decr.tosSource; w.opcode := decr.opcode; w.opWillFreeze := i_op_freeze; w.pc := decr.pc; w.fetchpc := decr.pcint; w.idim := decr.idim; w.break := decr.break; end if; if wb_rst_i='1' then w.spnext := unsigned(spStart(10 downto 2)); --w.sp := unsigned(spStart(10 downto 2)); w.valid := '0'; w.idim := '0'; w.recompute_sp:='0'; end if; if rising_edge(wb_clk_i) then prefr <= w; end if; end process; process(prefr,exr,nos) begin trace_pc <= (others => '0'); trace_pc(maxAddrBit downto 0) <= std_logic_vector(prefr.pc); trace_opcode <= prefr.opcode; trace_sp <= (others => '0'); trace_sp(10 downto 2) <= std_logic_vector(prefr.sp); trace_topOfStack <= std_logic_vector( exr.tos ); trace_topOfStackB <= std_logic_vector( nos ); end process; -- IO/Memory Accesses wb_adr_o(maxAddrBitIncIO downto 0) <= std_logic_vector(exr.tos_save(maxAddrBitIncIO downto 0)); wb_cyc_o <= exr.wb_cyc; wb_stb_o <= exr.wb_stb; wb_we_o <= exr.wb_we; wb_dat_o <= std_logic_vector( exr.nos_save ); freeze_all <= dbg_in.freeze; process(exr, wb_inta_i, wb_clk_i, wb_rst_i, pcnext, stack_a_read,stack_b_read, wb_ack_i, wb_dat_i, do_interrupt,exr, prefr, nos, single_step, freeze_all, dbg_in.step, wroteback_q,lshifter_done,lshifter_output ) variable spOffset: unsigned(4 downto 0); variable w: exuregs_type; variable instruction_executed: std_logic; variable wroteback: std_logic; begin w := exr; instruction_executed := '0'; -- used for single stepping stack_b_writeenable <= '0'; stack_a_enable <= '1'; stack_b_enable <= '1'; exu_busy <= '0'; decode_jump <= '0'; jump_address <= (others => DontCareValue); lshifter_enable <= '0'; lshifter_amount <= std_logic_vector(exr.tos_save); lshifter_input <= std_logic_vector(exr.nos_save); lshifter_multorshift <= '0'; poppc_inst <= '0'; begin_inst<='0'; stack_a_addr <= std_logic_vector( prefr.sp ); stack_a_writeenable <= '0'; wroteback := wroteback_q; stack_b_writeenable <= '0'; stack_a_write <= std_logic_vector(exr.tos); spOffset(4):=not prefr.opcode(4); spOffset(3 downto 0) := unsigned(prefr.opcode(3 downto 0)); if wb_inta_i='0' then w.inInterrupt := '0'; end if; stack_b_write<=(others => DontCareValue); if wroteback_q='1' then nos <= unsigned(stack_a_read); else nos <= unsigned(stack_b_read); end if; decode_load_sp <= '0'; case exr.state is when State_Resync1 => exu_busy <= '1'; stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_ResyncFromStoreStack => exu_busy <= '1'; stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; w.state := State_Resync2; wroteback := '0'; when State_Resync2 => w.tos := unsigned(stack_a_read); instruction_executed := '1'; exu_busy <= '0'; wroteback := '0'; stack_b_enable <= '1'; w.state := State_Execute; when State_Execute => instruction_executed:='0'; if prefr.valid='1' then exu_busy <= prefr.opWillFreeze; if freeze_all='0' or single_step='1' then wroteback := '0'; w.nos_save := nos; w.tos_save := exr.tos; w.idim := prefr.idim; w.break:= prefr.break; begin_inst<='1'; instruction_executed := '1'; -- TOS big muxer case prefr.tosSource is when Tos_Source_PC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.pc; when Tos_Source_FetchPC => w.tos := (others => '0'); w.tos(maxAddrBit downto 0) := prefr.fetchpc; when Tos_Source_Idim0 => for i in wordSize-1 downto 7 loop w.tos(i) := prefr.opcode(6); end loop; w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_IdimN => w.tos(wordSize-1 downto 7) := exr.tos(wordSize-8 downto 0); w.tos(6 downto 0) := unsigned(prefr.opcode(6 downto 0)); when Tos_Source_StackB => w.tos := nos; when Tos_Source_SP => w.tos := (others => '0'); w.tos(31) := '1'; -- Stack address w.tos(10 downto 2) := prefr.sp; when Tos_Source_Add => w.tos := exr.tos + nos; when Tos_Source_And => w.tos := exr.tos and nos; when Tos_Source_Or => w.tos := exr.tos or nos; when Tos_Source_Eq => w.tos := (others => '0'); if nos = exr.tos then w.tos(0) := '1'; end if; when Tos_Source_Ulessthan => w.tos := (others => '0'); if exr.tos < nos then w.tos(0) := '1'; end if; when Tos_Source_Lessthan => w.tos := (others => '0'); if signed(exr.tos) < signed(nos) then w.tos(0) := '1'; end if; when Tos_Source_Not => w.tos := not exr.tos; when Tos_Source_Flip => for i in 0 to wordSize-1 loop w.tos(i) := exr.tos(wordSize-1-i); end loop; when Tos_Source_LoadSP => w.tos := unsigned(stack_b_read); when Tos_Source_AddSP => w.tos := w.tos + unsigned(stack_b_read); when Tos_Source_AddStackB => w.tos := w.tos + nos; when Tos_Source_Shift => w.tos := exr.tos + exr.tos; when others => end case; case prefr.decodedOpcode is when Decoded_Interrupt => w.inInterrupt := '1'; jump_address <= to_unsigned(32, maxAddrBit+1); decode_jump <= '1'; stack_a_writeenable<='1'; wroteback:='1'; stack_b_enable<='0'; instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Im0 => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_ImN => when Decoded_Nop => when Decoded_PopPC | Decoded_Call => decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0); poppc_inst <= '1'; stack_b_enable<='0'; -- Delay instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_Emulate => decode_jump <= '1'; jump_address <= (others => '0'); jump_address(9 downto 5) <= unsigned(prefr.opcode(4 downto 0)); stack_a_writeenable<='1'; wroteback:='1'; when Decoded_PushSP => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_LoadSP => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_DupStackB => stack_a_writeenable <= '1'; wroteback:='1'; when Decoded_Dup => stack_a_writeenable<='1'; wroteback:='1'; when Decoded_AddSP => stack_a_writeenable <= '1'; when Decoded_StoreSP => stack_a_writeenable <= '1'; wroteback:='1'; stack_a_addr <= std_logic_vector(prefr.sp + spOffset); instruction_executed := '0'; w.state := State_WaitSPB; when Decoded_PopDown => stack_a_writeenable<='1'; when Decoded_Pop => when Decoded_Ashiftleft => w.state := State_Ashiftleft; when Decoded_Mult => w.state := State_Mult; when Decoded_MultF16 => w.state := State_MultF16; when Decoded_Store => if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(nos); stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when Decoded_Load | Decoded_Loadb | Decoded_StoreB => --w.tos_save := exr.tos; -- Byte select instruction_executed := '0'; wroteback := wroteback_q; -- Keep WB if exr.tos(wordSize-1)='1' then stack_a_addr<=std_logic_vector(exr.tos(10 downto 2)); stack_a_enable<='1'; w.state := State_LoadStack; else stack_a_enable <= '0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); w.wb_we :='0'; w.wb_cyc :='1'; w.wb_stb :='1'; w.state := State_Load; end if; when Decoded_PopSP => decode_load_sp <= '1'; instruction_executed := '0'; stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); w.state := State_Resync2; --when Decoded_Break => -- w.break := '1'; when Decoded_Neqbranch => instruction_executed := '0'; w.state := State_NeqBranch; when others => end case; else -- freeze_all -- -- Freeze the entire pipeline. -- exu_busy<='1'; stack_a_enable<='0'; stack_b_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); end if; end if; -- valid when State_Ashiftleft => exu_busy <= '1'; lshifter_enable <= '1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_Mult => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(31 downto 0)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_MultF16 => exu_busy <= '1'; lshifter_enable <= '1'; lshifter_multorshift <='1'; w.tos := unsigned(lshifter_output(47 downto 16)); if lshifter_done='1' then exu_busy<='0'; w.state := State_Execute; end if; when State_WaitSPB => instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Store => exu_busy <= '1'; -- Keep writeback flag wroteback := wroteback_q; if wb_ack_i='1' then stack_a_addr <= std_logic_vector(prefr.spnext); stack_a_enable<='1'; stack_b_enable<='1'; wroteback := '0'; --exu_busy <= '1'; w.wb_cyc := '0'; w.state := State_Resync2; else stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_a_enable<='0'; stack_b_enable<='0'; end if; when State_Loadb => w.tos(wordSize-1 downto 8) := (others => '0'); case exr.tos_save(1 downto 0) is when "11" => w.tos(7 downto 0) := unsigned(exr.tos(7 downto 0)); when "10" => w.tos(7 downto 0) := unsigned(exr.tos(15 downto 8)); when "01" => w.tos(7 downto 0) := unsigned(exr.tos(23 downto 16)); when "00" => w.tos(7 downto 0) := unsigned(exr.tos(31 downto 24)); when others => null; end case; instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; when State_Load => if wb_ack_i='0' then exu_busy<='1'; else w.tos := unsigned(wb_dat_i); w.wb_cyc := '0'; if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state := State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state := State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; end if; when State_LoadStack => w.tos := unsigned(stack_a_read); if prefr.decodedOpcode=Decoded_Loadb then exu_busy<='1'; w.state:=State_Loadb; elsif prefr.decodedOpcode=Decoded_Storeb then exu_busy<='1'; w.state:=State_Storeb; else instruction_executed:='1'; wroteback := '0'; w.state := State_Execute; end if; when State_NeqBranch => if exr.nos_save/=0 then decode_jump <= '1'; jump_address <= exr.tos(maxAddrBit downto 0) + prefr.pc; poppc_inst <= '1'; exu_busy <= '0'; else exu_busy <='1'; end if; instruction_executed := '0'; stack_a_addr <= std_logic_vector(prefr.spnext); wroteback:='0'; w.state := State_Resync2; when State_StoreB => exu_busy <= '1'; -- -- At this point, we have loaded the 32-bit, and it's in TOS -- The IO address is still saved in save_TOS. -- The original write value is still at save_NOS -- -- So we mangle the write value, and update save_NOS, and restore -- the IO address to TOS -- -- This is still buggy - don't use. Problems arise when writing to stack. -- w.nos_save := exr.tos; case exr.tos_save(1 downto 0) is when "00" => w.nos_save(31 downto 24) := exr.nos_save(7 downto 0); when "01" => w.nos_save(23 downto 16) := exr.nos_save(7 downto 0); when "10" => w.nos_save(15 downto 8) := exr.nos_save(7 downto 0); when "11" => w.nos_save(7 downto 0) := exr.nos_save(7 downto 0); when others => null; end case; w.tos := exr.tos_save; w.state := State_StoreB2; when State_StoreB2 => exu_busy <= '1'; if exr.tos(31)='1' then stack_a_addr <= std_logic_vector(exr.tos(10 downto 2)); stack_a_write <= std_logic_vector(exr.nos_save); -- hmm I don't like this stack_a_writeenable<='1'; w.state := State_ResyncFromStoreStack; else w.wb_we := '1'; w.wb_cyc := '1'; w.wb_stb := '1'; wroteback := wroteback_q; -- Keep WB stack_a_enable<='0'; stack_a_addr <= (others => DontCareValue); stack_a_write <= (others => DontCareValue); stack_b_enable<='0'; instruction_executed := '0'; w.state := State_Store; end if; when others => null; end case; if rising_edge(wb_clk_i) then if wb_rst_i='1' then exr.state <= State_Execute; exr.idim <= DontCareValue; exr.inInterrupt <= '0'; exr.break <= '0'; exr.wb_cyc <= '0'; exr.wb_stb <= '1'; else exr <= w; -- TODO: move wroteback_q into EXU regs wroteback_q <= wroteback; if exr.break='1' then report "BREAK" severity failure; end if; -- Some sanity checks, to be caught in simulation if prefr.valid='1' then if prefr.tosSource=Tos_Source_Idim0 and prefr.idim='1' then report "Invalid IDIM flag 0" severity error; end if; if prefr.tosSource=Tos_Source_IdimN and prefr.idim='0' then report "Invalid IDIM flag 1" severity error; end if; end if; end if; end if; end process; single_step <= dbg_in.step; dbg_out.valid <= '1' when prefr.valid='1' else '0'; -- Let pipeline finish dbg_out.ready <= '1' when exr.state=state_execute and decode_load_sp='0' and decode_jump='0' and decr.state = State_Inject --and jump_q='0' else '0'; end behave;
library ieee ; use ieee.std_logic_1164.all; use ieee.numeric_std.all; use work.fixed_pkg.all; use work.filter_pkg.all; entity FIR is generic ( wordLength : natural := 32; fractionalBits : natural := 31; coeffWordLength : natural := 12; coeffFractionalBits : natural := 11; sumWordLength : natural := 32; sumFractionalBits : natural := 31; outputWordLength : natural := 32; outputFractionalBits : natural := 31; order : natural := 6; coefficients : coefficient_array := ( -0.0390625, 0.0, 0.28759765625, 0.5, 0.28759765625, 0.0, -0.0390625 ) ); port ( input : in std_logic_vector(wordLength-1 downto 0); output : out std_logic_vector(outputWordLength-1 downto 0); clk : in std_logic; reset : in std_logic ); end entity ; -- FIR architecture arch of FIR is type signalArray is array(0 to order) of std_logic_vector(wordLength-1 downto 0); type sumArray is array(0 to order) of std_logic_vector(sumWordLength-1 downto 0); signal inputs : signalArray := (others => (others => '0')); signal gainedInputs : sumArray := (others => (others => '0')); signal sums : sumArray := (others => (others => '0')); begin inputs(0) <= input; output <= sums(0)(sumFractionalBits-outputFractionalBits+outputWordLength-1 downto sumFractionalBits-outputFractionalBits); sums(order) <= gainedInputs(order); delays : for i in 0 to order-1 generate -- Delay stages delay : entity work.VectorRegister generic map ( wordLength => wordLength ) port map ( input => inputs(i), output => inputs(i+1), clk => clk, reset => reset ); -- Output summation adder : entity work.AdderSat generic map ( wordLength => sumWordLength ) port map ( a => gainedInputs(i), b => sums(i+1), s => sums(i) ); end generate ; -- delays multiplication : for i in 0 to order generate mult : entity work.Multiplier generic map ( X_WIDTH => wordLength, X_FRACTION => fractionalBits, Y_WIDTH => coeffWordLength, Y_FRACTION => coeffFractionalBits, S_WIDTH => sumWordLength, S_FRACTION => sumFractionalBits ) port map ( x => inputs(i), y => real_to_fixed(coefficients(i), coeffWordLength, coeffFractionalBits), s => gainedInputs(i) ); end generate; end architecture ; -- arch
library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity right_shift is generic ( SHIFT_BITS : positive := 1; WORD_WIDTH : positive := 8; NUM_WORDS : positive := 2); port ( clk : in std_logic; rst : in std_logic; en : in std_logic := '1'; input : in std_logic_vector(WORD_WIDTH*NUM_WORDS-1 downto 0); shift_amount : in std_logic_vector(SHIFT_BITS-1 downto 0); output : out std_logic_vector(WORD_WIDTH*NUM_WORDS-1 downto 0); valid_in : in std_logic; valid_out : out std_logic); end right_shift; architecture DEFAULT of right_shift is constant LEVELS : positive := SHIFT_BITS; type word_array is array (0 to LEVELS-1, 0 to NUM_WORDS-1) of std_logic_vector(WORD_WIDTH-1 downto 0); signal words : word_array; type input_array is array (0 to NUM_WORDS-1) of std_logic_vector(WORD_WIDTH-1 downto 0); signal inputs : input_array; type shift_array is array (0 to LEVELS-1) of std_logic_vector(SHIFT_BITS-1 downto 0); signal shift : shift_array; begin -- convert input vector into 2d array process(input) begin for i in 0 to NUM_WORDS-1 loop inputs(i) <= input(input'length-i*WORD_WIDTH-1 downto input'length-(i+1)*WORD_WIDTH); end loop; end process; process(clk, rst) begin if (rst = '1') then for i in 0 to LEVELS-1 loop for j in 0 to NUM_WORDS-1 loop words(i, j) <= (others => '0'); end loop; shift(i) <= (others => '0'); end loop; elsif (rising_edge(clk)) then -- level 0 for j in 0 to NUM_WORDS-1 loop if (en = '1') then if (shift_amount(LEVELS-1) = '1') then if (j-2**(LEVELS-1) < 0) then words(0, j) <= (others => '0'); else words(0, j) <= inputs(j-2**(LEVELS-1)); end if; else words(0, j) <= inputs(j); end if; shift(0) <= shift_amount; end if; end loop; for i in 1 to LEVELS-1 loop shift(i) <= shift(i-1); for j in 0 to NUM_WORDS-1 loop if (en = '1') then if (shift(i-1)(LEVELS-i-1) = '1') then -- if word to shift from doesn't exist, shift in 0 -- else, shift in words based on the level if (j-2**(LEVELS-i-1) < 0) then words(i, j) <= (others => '0'); else words(i, j) <= words(i-1, j-2**(LEVELS-i-1)); end if; else words(i, j) <= words(i-1, j); end if; end if; end loop; end loop; end if; end process; process(words) begin for i in 0 to NUM_WORDS-1 loop output((NUM_WORDS-i)*WORD_WIDTH-1 downto (NUM_WORDS-i-1)*WORD_WIDTH) <= words(LEVELS-1, i); end loop; end process; U_DELAY : entity work.delay generic map ( width => 1, cycles => LEVELS, init => "0") port map ( clk => clk, rst => rst, en => en, input(0) => valid_in, output(0) => valid_out); end DEFAULT;
library work; use work.sample_pkg.all; entity pkg_test is port ( o : out integer ); end pkg_test; architecture rtl of pkg_test is begin o <= SAMPLE_CONSTANT; end rtl;
---------------------------------------------------------------------------------- -- Company: LARC - Escola Politecnica - University of Sao Paulo -- Engineer: Pedro Maat C. Massolino -- -- Create Date: 05/12/2012 -- Design Name: Pipeline_Polynomial_Calc_v4 -- Module Name: Pipeline_Polynomial_Calc_v4 -- Project Name: McEliece Goppa Decoder -- Target Devices: Any -- Tool versions: Xilinx ISE 13.3 WebPack -- -- Description: -- -- The 1st and 3rd step in Goppa Code Decoding. -- -- This circuit is to be used inside polynomial_syndrome_computing_n to evaluate polynomials -- or generate the syndrome. -- This circuit is the essential for 1 pipeline, therefor all stages are composed in here. -- For more than 1 pipeline, only in polynomial_syndrome_computing_n with the shared components -- for all pipelines. -- -- For the computation this circuit applies the Horner scheme, where at each stage -- an accumulator is multiplied by respective x and then added accumulated with coefficient. -- In Horner scheme algorithm, it begin from the most significative coefficient until reaches -- lesser significative coefficient. -- -- The circuits parameters -- -- gf_2_m : -- -- The size of the field used in this circuit. This parameter depends of the -- Goppa code used. -- -- size : -- -- The number of stages the pipeline has. More stages means more values of value_polynomial -- are tested at once. -- -- Dependencies: -- VHDL-93 -- -- stage_polynomial_calc_v4 Rev 1.0 -- register_nbits Rev 1.0 -- -- Revision: -- Revision 1.0 -- Additional Comments: -- ---------------------------------------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; entity pipeline_polynomial_calc_v4 is Generic ( gf_2_m : integer range 1 to 20; size : integer ); Port ( value_x : in STD_LOGIC_VECTOR((gf_2_m - 1) downto 0); value_polynomial : in STD_LOGIC_VECTOR((((gf_2_m)*size) - 1) downto 0); value_acc : in STD_LOGIC_VECTOR((gf_2_m - 1) downto 0); reg_x_rst : in STD_LOGIC_VECTOR((size - 1) downto 0); mode_polynomial_syndrome : in STD_LOGIC; clk : in STD_LOGIC; new_value_syndrome : out STD_LOGIC_VECTOR((((gf_2_m)*size) - 1) downto 0); new_value_acc : out STD_LOGIC_VECTOR((gf_2_m - 1) downto 0) ); end pipeline_polynomial_calc_v4; architecture Behavioral of pipeline_polynomial_calc_v4 is component stage_polynomial_calc_v4 Generic(gf_2_m : integer range 1 to 20 := 11); Port ( value_x : in STD_LOGIC_VECTOR((gf_2_m - 1) downto 0); value_polynomial_coefficient : in STD_LOGIC_VECTOR((gf_2_m - 1) downto 0); value_acc : in STD_LOGIC_VECTOR((gf_2_m - 1) downto 0); mode_polynomial_syndrome : in STD_LOGIC; new_value_syndrome : out STD_LOGIC_VECTOR((gf_2_m - 1) downto 0); new_value_acc : out STD_LOGIC_VECTOR((gf_2_m - 1) downto 0) ); end component; component register_nbits Generic(size : integer); Port( d : in STD_LOGIC_VECTOR((size - 1) downto 0); clk : in STD_LOGIC; ce : in STD_LOGIC; q : out STD_LOGIC_VECTOR((size - 1) downto 0) ); end component; component register_rst_nbits Generic(size : integer); Port( d : in STD_LOGIC_VECTOR((size - 1) downto 0); clk : in STD_LOGIC; ce : in STD_LOGIC; rst : in STD_LOGIC; rst_value : in STD_LOGIC_VECTOR((size - 1) downto 0); q : out STD_LOGIC_VECTOR((size - 1) downto 0) ); end component; type array_std_logic_vector is array(integer range <>) of STD_LOGIC_VECTOR((gf_2_m - 1) downto 0); signal acc_d : array_std_logic_vector((size) downto 0); signal acc_q : array_std_logic_vector((size) downto 0); signal x_d : array_std_logic_vector((size) downto 0); signal x_q : array_std_logic_vector((size - 1) downto 0); constant reg_x_rst_value : STD_LOGIC_VECTOR((gf_2_m - 1) downto 0) := std_logic_vector(to_unsigned(1, gf_2_m)); begin x_d(0) <= value_x; acc_d(0) <= value_acc; pipeline : for I in 0 to (size - 1) generate reg_x_I : register_rst_nbits Generic Map(size => gf_2_m) Port Map( d => x_d(I), clk => clk, ce => '1', rst => reg_x_rst(I), rst_value => reg_x_rst_value, q => x_q(I) ); reg_acc_I : register_nbits Generic Map(size => gf_2_m) Port Map( d => acc_d(I), clk => clk, ce => '1', q => acc_q(I) ); stage_I : stage_polynomial_calc_v4 Generic Map(gf_2_m => gf_2_m) Port Map ( value_x => x_q(I), value_polynomial_coefficient => value_polynomial(((gf_2_m)*(I+1) - 1) downto ((gf_2_m)*(I))), mode_polynomial_syndrome => mode_polynomial_syndrome, value_acc => acc_q(I), new_value_syndrome => new_value_syndrome(((gf_2_m)*(I+1) - 1) downto ((gf_2_m)*(I))), new_value_acc => acc_d(I+1) ); x_d(I+1) <= x_q(I); end generate; reg_acc_last : register_nbits Generic Map(size => gf_2_m) Port Map( d => acc_d(size), clk => clk, ce => '1', q => acc_q(size) ); new_value_acc <= acc_q(size); end Behavioral;
-------------------------------------------------------------------------------- -- Company: -- Engineer: -- -- Create Date: 12:38:04 12/18/2013 -- Design Name: -- Module Name: /home/nakayama/Desktop/583final/BO_Tests/Digit_Test.vhd -- Project Name: BO_Tests -- Target Device: -- Tool versions: -- Description: -- -- VHDL Test Bench Created by ISE for module: Digit -- -- Dependencies: -- -- Revision: -- Revision 0.01 - File Created -- Additional Comments: -- -- Notes: -- This testbench has been automatically generated using types std_logic and -- std_logic_vector for the ports of the unit under test. Xilinx recommends -- that these types always be used for the top-level I/O of a design in order -- to guarantee that the testbench will bind correctly to the post-implementation -- simulation model. -------------------------------------------------------------------------------- LIBRARY ieee; USE ieee.std_logic_1164.ALL; use ieee.numeric_std.all; -- Uncomment the following library declaration if using -- arithmetic functions with Signed or Unsigned values --USE ieee.numeric_std.ALL; ENTITY Digit_Test IS END Digit_Test; ARCHITECTURE behavior OF Digit_Test IS -- Component Declaration for the Unit Under Test (UUT) COMPONENT Digit PORT( rainbow : IN std_logic; number : IN std_logic_vector(3 downto 0); x : IN std_logic_vector(2 downto 0); y : IN std_logic_vector(2 downto 0); R : OUT std_logic_vector(3 downto 0); G : OUT std_logic_vector(3 downto 0); B : OUT std_logic_vector(3 downto 0) ); END COMPONENT; --Inputs signal rainbow : std_logic := '0'; signal number : std_logic_vector(3 downto 0) := (others => '0'); signal x : unsigned(2 downto 0) := (others => '0'); signal y : unsigned(2 downto 0) := (others => '0'); --Outputs signal R : std_logic_vector(3 downto 0); signal G : std_logic_vector(3 downto 0); signal B : std_logic_vector(3 downto 0); -- No clocks detected in port list. Replace <clock> below with -- appropriate port name signal clk : std_logic := '0'; constant clk_period : time := 40 ns; BEGIN -- Instantiate the Unit Under Test (UUT) uut: Digit PORT MAP ( rainbow => rainbow, number => number, x => std_logic_vector(x), y => std_logic_vector(y), R => R, G => G, B => B ); -- Clock process definitions clk_process :process begin clk <= '0'; wait for clk_period/2; clk <= '1'; wait for clk_period/2; end process; process(clk) begin --On the rising edge of the clock increment the x and y values. if(clk'event and clk='1') then x <= x + 1; if(x = 0) then y <= y + 1; end if; end if; end process; -- Stimulus process stim_proc: process begin -- hold reset state for 100 ns. wait for 100 ns; rainbow <= '1'; number <= x"0"; -- insert stimulus here wait; end process; END;
entity FIFO is end entity; entity FIFO is end entity;
-------------------------------------------------------------------------------- -- -- FIFO Generator Core Demo Testbench -- -------------------------------------------------------------------------------- -- -- (c) Copyright 2009 - 2010 Xilinx, Inc. All rights reserved. -- -- This file contains confidential and proprietary information -- of Xilinx, Inc. and is protected under U.S. and -- international copyright and other intellectual property -- laws. -- -- DISCLAIMER -- This disclaimer is not a license and does not grant any -- rights to the materials distributed herewith. Except as -- otherwise provided in a valid license issued to you by -- Xilinx, and to the maximum extent permitted by applicable -- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND -- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES -- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING -- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- -- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and -- (2) Xilinx shall not be liable (whether in contract or tort, -- including negligence, or under any other theory of -- liability) for any loss or damage of any kind or nature -- related to, arising under or in connection with these -- materials, including for any direct, or any indirect, -- special, incidental, or consequential loss or damage -- (including loss of data, profits, goodwill, or any type of -- loss or damage suffered as a result of any action brought -- by a third party) even if such damage or loss was -- reasonably foreseeable or Xilinx had been advised of the -- possibility of the same. -- -- CRITICAL APPLICATIONS -- Xilinx products are not designed or intended to be fail- -- safe, or for use in any application requiring fail-safe -- performance, such as life-support or safety devices or -- systems, Class III medical devices, nuclear facilities, -- applications related to the deployment of airbags, or any -- other applications that could lead to death, personal -- injury, or severe property or environmental damage -- (individually and collectively, "Critical -- Applications"). Customer assumes the sole risk and -- liability of any use of Xilinx products in Critical -- Applications, subject only to applicable laws and -- regulations governing limitations on product liability. -- -- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS -- PART OF THIS FILE AT ALL TIMES. -------------------------------------------------------------------------------- -- -- Filename: k7_eb_fifo_counted_resized_rng.vhd -- -- Description: -- Used for generation of pseudo random numbers -- -------------------------------------------------------------------------------- -- Library Declarations -------------------------------------------------------------------------------- LIBRARY ieee; USE ieee.std_logic_1164.ALL; USE ieee.std_logic_unsigned.all; USE IEEE.std_logic_arith.all; USE IEEE.std_logic_misc.all; ENTITY k7_eb_fifo_counted_resized_rng IS GENERIC ( WIDTH : integer := 8; SEED : integer := 3); PORT ( CLK : IN STD_LOGIC; RESET : IN STD_LOGIC; ENABLE : IN STD_LOGIC; RANDOM_NUM : OUT STD_LOGIC_VECTOR (WIDTH-1 DOWNTO 0)); END ENTITY; ARCHITECTURE rg_arch OF k7_eb_fifo_counted_resized_rng IS BEGIN PROCESS (CLK,RESET) VARIABLE rand_temp : STD_LOGIC_VECTOR(width-1 DOWNTO 0):=conv_std_logic_vector(SEED,width); VARIABLE temp : STD_LOGIC := '0'; BEGIN IF(RESET = '1') THEN rand_temp := conv_std_logic_vector(SEED,width); temp := '0'; ELSIF (CLK'event AND CLK = '1') THEN IF (ENABLE = '1') THEN temp := rand_temp(width-1) xnor rand_temp(width-3) xnor rand_temp(width-4) xnor rand_temp(width-5); rand_temp(width-1 DOWNTO 1) := rand_temp(width-2 DOWNTO 0); rand_temp(0) := temp; END IF; END IF; RANDOM_NUM <= rand_temp; END PROCESS; END ARCHITECTURE;
----------------------------------------------------------------------------- -- LEON3 Demonstration design test bench configuration -- Copyright (C) 2009 Aeroflex Gaisler ------------------------------------------------------------------------------ library techmap; use techmap.gencomp.all; package config is -- Technology and synthesis options constant CFG_FABTECH : integer := altera; constant CFG_MEMTECH : integer := altera; constant CFG_PADTECH : integer := altera; constant CFG_NOASYNC : integer := 0; constant CFG_SCAN : integer := 0; -- Clock generator constant CFG_CLKTECH : integer := altera; constant CFG_CLKMUL : integer := (2); constant CFG_CLKDIV : integer := (2); constant CFG_OCLKDIV : integer := 1; constant CFG_OCLKBDIV : integer := 0; constant CFG_OCLKCDIV : integer := 0; constant CFG_PCIDLL : integer := 0; constant CFG_PCISYSCLK: integer := 0; constant CFG_CLK_NOFB : integer := 0; -- LEON3 processor core constant CFG_LEON3 : integer := 1; constant CFG_NCPU : integer := (1); constant CFG_NWIN : integer := (8); constant CFG_V8 : integer := 2 + 4*0; constant CFG_MAC : integer := 0; constant CFG_BP : integer := 0; constant CFG_SVT : integer := 1; constant CFG_RSTADDR : integer := 16#00000#; constant CFG_LDDEL : integer := (1); constant CFG_NOTAG : integer := 0; constant CFG_NWP : integer := (2); constant CFG_PWD : integer := 1*2; constant CFG_FPU : integer := 0 + 16*0 + 32*0; constant CFG_GRFPUSH : integer := 0; constant CFG_ICEN : integer := 1; constant CFG_ISETS : integer := 1; constant CFG_ISETSZ : integer := 4; constant CFG_ILINE : integer := 8; constant CFG_IREPL : integer := 0; constant CFG_ILOCK : integer := 0; constant CFG_ILRAMEN : integer := 0; constant CFG_ILRAMADDR: integer := 16#8E#; constant CFG_ILRAMSZ : integer := 1; constant CFG_DCEN : integer := 1; constant CFG_DSETS : integer := 1; constant CFG_DSETSZ : integer := 4; constant CFG_DLINE : integer := 8; constant CFG_DREPL : integer := 0; constant CFG_DLOCK : integer := 0; constant CFG_DSNOOP : integer := 1 + 0 + 4*0; constant CFG_DFIXED : integer := 16#0#; constant CFG_DLRAMEN : integer := 0; constant CFG_DLRAMADDR: integer := 16#8F#; constant CFG_DLRAMSZ : integer := 1; constant CFG_MMUEN : integer := 1; constant CFG_ITLBNUM : integer := 8; constant CFG_DTLBNUM : integer := 8; constant CFG_TLB_TYPE : integer := 0 + 1*2; constant CFG_TLB_REP : integer := 0; constant CFG_MMU_PAGE : integer := 0; constant CFG_DSU : integer := 1; constant CFG_ITBSZ : integer := 1; constant CFG_ATBSZ : integer := 1; constant CFG_LEON3FT_EN : integer := 0; constant CFG_IUFT_EN : integer := 0; constant CFG_FPUFT_EN : integer := 0; constant CFG_RF_ERRINJ : integer := 0; constant CFG_CACHE_FT_EN : integer := 0; constant CFG_CACHE_ERRINJ : integer := 0; constant CFG_LEON3_NETLIST: integer := 0; constant CFG_DISAS : integer := 0 + 0; constant CFG_PCLOW : integer := 2; -- AMBA settings constant CFG_DEFMST : integer := (0); constant CFG_RROBIN : integer := 1; constant CFG_SPLIT : integer := 0; constant CFG_FPNPEN : integer := 0; constant CFG_AHBIO : integer := 16#FFF#; constant CFG_APBADDR : integer := 16#800#; constant CFG_AHB_MON : integer := 0; constant CFG_AHB_MONERR : integer := 0; constant CFG_AHB_MONWAR : integer := 0; constant CFG_AHB_DTRACE : integer := 0; -- DSU UART constant CFG_AHB_UART : integer := 1; -- JTAG based DSU interface constant CFG_AHB_JTAG : integer := 1; -- PROM/SRAM controller constant CFG_SRCTRL : integer := 0; constant CFG_SRCTRL_PROMWS : integer := 0; constant CFG_SRCTRL_RAMWS : integer := 0; constant CFG_SRCTRL_IOWS : integer := 0; constant CFG_SRCTRL_RMW : integer := 0; constant CFG_SRCTRL_8BIT : integer := 0; constant CFG_SRCTRL_SRBANKS : integer := 1; constant CFG_SRCTRL_BANKSZ : integer := 0; constant CFG_SRCTRL_ROMASEL : integer := 0; -- LEON2 memory controller constant CFG_MCTRL_LEON2 : integer := 1; constant CFG_MCTRL_RAM8BIT : integer := 1; constant CFG_MCTRL_RAM16BIT : integer := 0; constant CFG_MCTRL_5CS : integer := 0; constant CFG_MCTRL_SDEN : integer := 1; constant CFG_MCTRL_SEPBUS : integer := 1; constant CFG_MCTRL_INVCLK : integer := 0; constant CFG_MCTRL_SD64 : integer := 0; constant CFG_MCTRL_PAGE : integer := 0 + 0; -- AHB ROM constant CFG_AHBROMEN : integer := 0; constant CFG_AHBROPIP : integer := 0; constant CFG_AHBRODDR : integer := 16#000#; constant CFG_ROMADDR : integer := 16#000#; constant CFG_ROMMASK : integer := 16#E00# + 16#000#; -- AHB RAM constant CFG_AHBRAMEN : integer := 0; constant CFG_AHBRSZ : integer := 1; constant CFG_AHBRADDR : integer := 16#A00#; constant CFG_AHBRPIPE : integer := 0; -- UART 1 constant CFG_UART1_ENABLE : integer := 1; constant CFG_UART1_FIFO : integer := 8; -- LEON3 interrupt controller constant CFG_IRQ3_ENABLE : integer := 1; constant CFG_IRQ3_NSEC : integer := 0; -- Modular timer constant CFG_GPT_ENABLE : integer := 1; constant CFG_GPT_NTIM : integer := (2); constant CFG_GPT_SW : integer := (8); constant CFG_GPT_TW : integer := (32); constant CFG_GPT_IRQ : integer := (8); constant CFG_GPT_SEPIRQ : integer := 1; constant CFG_GPT_WDOGEN : integer := 0; constant CFG_GPT_WDOG : integer := 16#0#; -- GPIO port constant CFG_GRGPIO_ENABLE : integer := 1; constant CFG_GRGPIO_IMASK : integer := 16#000F#; constant CFG_GRGPIO_WIDTH : integer := (2); -- GRLIB debugging constant CFG_DUART : integer := 0; end;
-- NEED RESULT: ARCH00078.P1: Multi transport transactions occurred on signal asg with indexed name on LHS passed -- NEED RESULT: ARCH00078.P2: Multi transport transactions occurred on signal asg with indexed name on LHS passed -- NEED RESULT: ARCH00078.P3: Multi transport transactions occurred on signal asg with indexed name on LHS passed -- NEED RESULT: ARCH00078: One transport transaction occurred on signal asg with indexed name on LHS passed -- NEED RESULT: ARCH00078: Old transactions were removed on signal asg with indexed name on LHS passed -- NEED RESULT: ARCH00078: One transport transaction occurred on signal asg with indexed name on LHS passed -- NEED RESULT: ARCH00078: Old transactions were removed on signal asg with indexed name on LHS passed -- NEED RESULT: ARCH00078: One transport transaction occurred on signal asg with indexed name on LHS passed -- NEED RESULT: ARCH00078: Old transactions were removed on signal asg with indexed name on LHS passed -- NEED RESULT: P3: Transport transactions entirely completed passed -- NEED RESULT: P2: Transport transactions entirely completed passed -- NEED RESULT: P1: Transport transactions entirely completed passed ------------------------------------------------------------------------------- -- -- Copyright (c) 1989 by Intermetrics, Inc. -- All rights reserved. -- ------------------------------------------------------------------------------- -- -- TEST NAME: -- -- CT00078 -- -- AUTHOR: -- -- G. Tominovich -- -- TEST OBJECTIVES: -- -- 8.3 (2) -- 8.3 (3) -- 8.3 (5) -- 8.3.1 (3) -- -- DESIGN UNIT ORDERING: -- -- E00000(ARCH00078) -- ENT00078_Test_Bench(ARCH00078_Test_Bench) -- -- REVISION HISTORY: -- -- 07-JUL-1987 - initial revision -- -- NOTES: -- -- self-checking -- automatically generated -- use WORK.STANDARD_TYPES.all ; architecture ARCH00078 of E00000 is subtype chk_sig_type is integer range -1 to 100 ; signal chk_st_arr1 : chk_sig_type := -1 ; signal chk_st_arr2 : chk_sig_type := -1 ; signal chk_st_arr3 : chk_sig_type := -1 ; -- signal s_st_arr1 : st_arr1 := c_st_arr1_1 ; signal s_st_arr2 : st_arr2 := c_st_arr2_1 ; signal s_st_arr3 : st_arr3 := c_st_arr3_1 ; -- begin PGEN_CHKP_1 : process ( chk_st_arr1 ) begin if Std.Standard.Now > 0 ns then test_report ( "P1" , "Transport transactions entirely completed", chk_st_arr1 = 4 ) ; end if ; end process PGEN_CHKP_1 ; -- P1 : process ( s_st_arr1 ) variable correct : boolean ; variable counter : integer := 0 ; variable savtime : time ; -- procedure Proc1 is begin case counter is when 0 => s_st_arr1 (st_arr1'Left) <= transport c_st_arr1_2 (st_arr1'Right) after 10 ns, c_st_arr1_1 (st_arr1'Right) after 20 ns ; -- when 1 => correct := s_st_arr1 (st_arr1'Left) = c_st_arr1_2 (st_arr1'Right) and (savtime + 10 ns) = Std.Standard.Now ; -- when 2 => correct := correct and s_st_arr1 (st_arr1'Left) = c_st_arr1_1 (st_arr1'Right) and (savtime + 10 ns) = Std.Standard.Now ; test_report ( "ARCH00078.P1" , "Multi transport transactions occurred on signal " & "asg with indexed name on LHS", correct ) ; s_st_arr1 (st_arr1'Left) <= transport c_st_arr1_2 (st_arr1'Right) after 10 ns, c_st_arr1_1 (st_arr1'Right) after 20 ns, c_st_arr1_2 (st_arr1'Right) after 30 ns, c_st_arr1_1 (st_arr1'Right) after 40 ns ; -- when 3 => correct := s_st_arr1 (st_arr1'Left) = c_st_arr1_2 (st_arr1'Right) and (savtime + 10 ns) = Std.Standard.Now ; s_st_arr1 (st_arr1'Left) <= transport c_st_arr1_1 (st_arr1'Right) after 5 ns; -- when 4 => correct := correct and s_st_arr1 (st_arr1'Left) = c_st_arr1_1 (st_arr1'Right) and (savtime + 5 ns) = Std.Standard.Now ; test_report ( "ARCH00078" , "One transport transaction occurred on signal " & "asg with indexed name on LHS", correct ) ; test_report ( "ARCH00078" , "Old transactions were removed on signal " & "asg with indexed name on LHS", correct ) ; -- when others => -- No more transactions should have occurred test_report ( "ARCH00078" , "Old transactions were removed on signal " & "asg with indexed name on LHS", false ) ; -- end case ; -- savtime := Std.Standard.Now ; chk_st_arr1 <= transport counter after (1 us - savtime) ; counter := counter + 1; -- end Proc1 ; -- begin Proc1 ; end process P1 ; -- PGEN_CHKP_2 : process ( chk_st_arr2 ) begin if Std.Standard.Now > 0 ns then test_report ( "P2" , "Transport transactions entirely completed", chk_st_arr2 = 4 ) ; end if ; end process PGEN_CHKP_2 ; -- P2 : process ( s_st_arr2 ) variable correct : boolean ; variable counter : integer := 0 ; variable savtime : time ; -- procedure Proc1 is begin case counter is when 0 => s_st_arr2 ( st_arr2'Left(1),st_arr2'Left(2)) <= transport c_st_arr2_2 ( st_arr2'Right(1),st_arr2'Right(2)) after 10 ns, c_st_arr2_1 ( st_arr2'Right(1),st_arr2'Right(2)) after 20 ns ; -- when 1 => correct := s_st_arr2 ( st_arr2'Left(1),st_arr2'Left(2)) = c_st_arr2_2 ( st_arr2'Right(1),st_arr2'Right(2)) and (savtime + 10 ns) = Std.Standard.Now ; -- when 2 => correct := correct and s_st_arr2 ( st_arr2'Left(1),st_arr2'Left(2)) = c_st_arr2_1 ( st_arr2'Right(1),st_arr2'Right(2)) and (savtime + 10 ns) = Std.Standard.Now ; test_report ( "ARCH00078.P2" , "Multi transport transactions occurred on signal " & "asg with indexed name on LHS", correct ) ; s_st_arr2 ( st_arr2'Left(1),st_arr2'Left(2)) <= transport c_st_arr2_2 ( st_arr2'Right(1),st_arr2'Right(2)) after 10 ns, c_st_arr2_1 ( st_arr2'Right(1),st_arr2'Right(2)) after 20 ns, c_st_arr2_2 ( st_arr2'Right(1),st_arr2'Right(2)) after 30 ns, c_st_arr2_1 ( st_arr2'Right(1),st_arr2'Right(2)) after 40 ns ; -- when 3 => correct := s_st_arr2 ( st_arr2'Left(1),st_arr2'Left(2)) = c_st_arr2_2 ( st_arr2'Right(1),st_arr2'Right(2)) and (savtime + 10 ns) = Std.Standard.Now ; s_st_arr2 ( st_arr2'Left(1),st_arr2'Left(2)) <= transport c_st_arr2_1 ( st_arr2'Right(1),st_arr2'Right(2)) after 5 ns; -- when 4 => correct := correct and s_st_arr2 ( st_arr2'Left(1),st_arr2'Left(2)) = c_st_arr2_1 ( st_arr2'Right(1),st_arr2'Right(2)) and (savtime + 5 ns) = Std.Standard.Now ; test_report ( "ARCH00078" , "One transport transaction occurred on signal " & "asg with indexed name on LHS", correct ) ; test_report ( "ARCH00078" , "Old transactions were removed on signal " & "asg with indexed name on LHS", correct ) ; -- when others => -- No more transactions should have occurred test_report ( "ARCH00078" , "Old transactions were removed on signal " & "asg with indexed name on LHS", false ) ; -- end case ; -- savtime := Std.Standard.Now ; chk_st_arr2 <= transport counter after (1 us - savtime) ; counter := counter + 1; -- end Proc1 ; -- begin Proc1 ; end process P2 ; -- PGEN_CHKP_3 : process ( chk_st_arr3 ) begin if Std.Standard.Now > 0 ns then test_report ( "P3" , "Transport transactions entirely completed", chk_st_arr3 = 4 ) ; end if ; end process PGEN_CHKP_3 ; -- P3 : process ( s_st_arr3 ) variable correct : boolean ; variable counter : integer := 0 ; variable savtime : time ; -- procedure Proc1 is begin case counter is when 0 => s_st_arr3 ( st_arr3'Left(1),st_arr3'Left(2)) <= transport c_st_arr3_2 ( st_arr3'Right(1),st_arr3'Right(2)) after 10 ns, c_st_arr3_1 ( st_arr3'Right(1),st_arr3'Right(2)) after 20 ns ; -- when 1 => correct := s_st_arr3 ( st_arr3'Left(1),st_arr3'Left(2)) = c_st_arr3_2 ( st_arr3'Right(1),st_arr3'Right(2)) and (savtime + 10 ns) = Std.Standard.Now ; -- when 2 => correct := correct and s_st_arr3 ( st_arr3'Left(1),st_arr3'Left(2)) = c_st_arr3_1 ( st_arr3'Right(1),st_arr3'Right(2)) and (savtime + 10 ns) = Std.Standard.Now ; test_report ( "ARCH00078.P3" , "Multi transport transactions occurred on signal " & "asg with indexed name on LHS", correct ) ; s_st_arr3 ( st_arr3'Left(1),st_arr3'Left(2)) <= transport c_st_arr3_2 ( st_arr3'Right(1),st_arr3'Right(2)) after 10 ns, c_st_arr3_1 ( st_arr3'Right(1),st_arr3'Right(2)) after 20 ns, c_st_arr3_2 ( st_arr3'Right(1),st_arr3'Right(2)) after 30 ns, c_st_arr3_1 ( st_arr3'Right(1),st_arr3'Right(2)) after 40 ns ; -- when 3 => correct := s_st_arr3 ( st_arr3'Left(1),st_arr3'Left(2)) = c_st_arr3_2 ( st_arr3'Right(1),st_arr3'Right(2)) and (savtime + 10 ns) = Std.Standard.Now ; s_st_arr3 ( st_arr3'Left(1),st_arr3'Left(2)) <= transport c_st_arr3_1 ( st_arr3'Right(1),st_arr3'Right(2)) after 5 ns; -- when 4 => correct := correct and s_st_arr3 ( st_arr3'Left(1),st_arr3'Left(2)) = c_st_arr3_1 ( st_arr3'Right(1),st_arr3'Right(2)) and (savtime + 5 ns) = Std.Standard.Now ; test_report ( "ARCH00078" , "One transport transaction occurred on signal " & "asg with indexed name on LHS", correct ) ; test_report ( "ARCH00078" , "Old transactions were removed on signal " & "asg with indexed name on LHS", correct ) ; -- when others => -- No more transactions should have occurred test_report ( "ARCH00078" , "Old transactions were removed on signal " & "asg with indexed name on LHS", false ) ; -- end case ; -- savtime := Std.Standard.Now ; chk_st_arr3 <= transport counter after (1 us - savtime) ; counter := counter + 1; -- end Proc1 ; -- begin Proc1 ; end process P3 ; -- -- end ARCH00078 ; -- entity ENT00078_Test_Bench is end ENT00078_Test_Bench ; -- architecture ARCH00078_Test_Bench of ENT00078_Test_Bench is begin L1: block component UUT end component ; for CIS1 : UUT use entity WORK.E00000 ( ARCH00078 ) ; begin CIS1 : UUT ; end block L1 ; end ARCH00078_Test_Bench ;
---------------------------------------------------------------------------------- -- Company: -- Engineer: -- -- Create Date: 12:01:25 10/17/2014 -- Design Name: -- Module Name: shiftled - Behavioral -- Project Name: -- Target Devices: -- Tool versions: -- Description: -- -- Dependencies: -- -- Revision: -- Revision 0.01 - File Created -- Additional Comments: -- ---------------------------------------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; -- Uncomment the following library declaration if using -- arithmetic functions with Signed or Unsigned values --use IEEE.NUMERIC_STD.ALL; -- Uncomment the following library declaration if instantiating -- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; entity shiftled is Port ( clk : in STD_LOGIC; E : in STD_LOGIC; Q : out STD_LOGIC_VECTOR (7 downto 0)); end shiftled; architecture Behavioral of shiftled is signal count : std_logic_vector (7 downto 0):= x"01"; begin process(clk) begin if clk'event and clk='1' then if E='1' then count<= count(6 downto 0) & count(7); end if; end if; end process; Q <= count; end Behavioral;
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_arith.ALL; use IEEE.STD_LOGIC_unsigned.ALL; entity WindowsManager is Port ( cwp : in STD_LOGIC; rs1 : in STD_LOGIC_VECTOR (4 downto 0); rs2 : in STD_LOGIC_VECTOR (4 downto 0); rd : in STD_LOGIC_VECTOR (4 downto 0); op : in STD_LOGIC_VECTOR (1 downto 0); op3 : in STD_LOGIC_VECTOR (5 downto 0); cwpout : out STD_LOGIC; rs1out : out STD_LOGIC_VECTOR (5 downto 0); rs2out : out STD_LOGIC_VECTOR (5 downto 0); rdout : out STD_LOGIC_VECTOR (5 downto 0):=(others=>'0')); end WindowsManager; architecture Behavioral of WindowsManager is signal int_rs1, int_rs2, int_rd : integer range 0 to 39 := 0; begin process(cwp,rs1,rs2,rd,op,op3) begin --guardar instruccion save if (op = "10" and op3 = "111100") then cwpout <= '0'; --reset instruction elsif (op = "10" and op3 = "111101") then cwpout <= '1'; else cwpout<='0'; end if; --registros goli rs1 if (rs1 >= "11000" and rs1 <= "11111") then int_rs1 <= conv_integer(rs1) - conv_integer(cwp) * 16; --input elsif (rs1 >= "10000" and rs1 <= "10111") then int_rs1 <= conv_integer(rs1) + conv_integer(cwp) * 16; --local elsif (rs1 >= "01000" and rs1 <= "01111") then int_rs1 <= conv_integer(rs1) + conv_integer(cwp) * 16; --output elsif (rs1 >= "00000" and rs1 <= "00111") then int_rs1 <= conv_integer(rs1); --global end if; --registros goli rs2 if (rs2 >= "11000" and rs2 <= "11111") then int_rs2 <= conv_integer(rs2) - conv_integer(cwp) * 16; --input elsif (rs2 >= "10000" and rs2 <= "10111") then int_rs2 <= conv_integer(rs2) + conv_integer(cwp) * 16; --local elsif (rs2 >= "01000" and rs2 <= "01111") then int_rs2 <= conv_integer(rs2) + conv_integer(cwp) * 16; --output elsif (rs2 >= "00000" and rs2 <= "00111") then int_rs2 <= conv_integer(rs2); --global end if; --registros goli rd if (rd >= "11000" and rd <= "11111") then int_rd <= conv_integer(rd) - conv_integer(cwp) * 16; --input elsif (rd >= "10000" and rd <= "10111") then int_rd <= conv_integer(rd) + conv_integer(cwp) * 16; --local elsif (rd >= "01000" and rd <= "01111") then int_rd <= conv_integer(rd) + conv_integer(cwp) * 16; --output elsif (rd >= "00000" and rd <= "00111") then int_rd <= conv_integer(rd); --global end if; end process; rs1out <= conv_std_logic_vector(int_rs1, 6); rs2out <= conv_std_logic_vector(int_rs2, 6); rdout <= conv_std_logic_vector(int_rd, 6); end Behavioral;
library ieee; use ieee.std_logic_1164.all; use work.lib.all; entity control is port( op : in std_logic_vector(3 downto 0); funct : in std_logic_vector(2 downto 0); RegDst, Jump, Branch, MemRead, MemtoReg, MemWrite, ALUSrc, RegWrite : out std_logic; ALUOp : out std_logic_vector(2 downto 0) ); end control; architecture logic of control is begin process(op, funct) begin if op = "0000" then RegDst <= '1'; case funct is when "010" => Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '1'; ALUOp <= "010"; --add MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '1'; when "110" => Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '1'; ALUOp <= "110"; --sub MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '1'; when "000" => Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '1'; ALUOp <= "000"; --and MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '1'; when "001" => Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '1'; ALUOp <= "001"; --or MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '1'; when "111" => Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '1'; ALUOp <= "111"; --slt MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '1'; when others => RegDst <= 'X'; Jump <= 'X'; Branch <= 'X'; MemRead <= 'X'; MemtoReg <= 'X'; ALUOp <= "XXX"; --others MemWrite <= 'X'; ALUSrc <= 'X'; RegWrite <= 'X'; end case; else case op is when "1011" => RegDst <= '1'; Jump <= '0'; Branch <= '0'; MemRead <= '1'; MemtoReg <= '0'; ALUOp <= "010"; --lw MemWrite <= '0'; ALUSrc <= '1'; RegWrite <= '1'; when "1111" => RegDst <= '0'; Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '0'; ALUOp <= "010"; --sw MemWrite <= '1'; ALUSrc <= '1'; RegWrite <= '0'; when "0100" => RegDst <= '0'; Jump <= '0'; Branch <= '1'; MemRead <= '0'; MemtoReg <= '0'; ALUOp <= "110"; --beq MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '0'; when "0010" => RegDst <= '0'; Jump <= '1'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '0'; ALUOp <= "000"; --j MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '0'; when others => RegDst <= 'X'; Jump <= 'X'; Branch <= 'X'; MemRead <= 'X'; MemtoReg <= 'X'; ALUOp <= "XXX"; --others MemWrite <= 'X'; ALUSrc <= 'X'; RegWrite <= 'X'; end case; end if; end process; end logic;
library ieee; use ieee.std_logic_1164.all; use work.lib.all; entity control is port( op : in std_logic_vector(3 downto 0); funct : in std_logic_vector(2 downto 0); RegDst, Jump, Branch, MemRead, MemtoReg, MemWrite, ALUSrc, RegWrite : out std_logic; ALUOp : out std_logic_vector(2 downto 0) ); end control; architecture logic of control is begin process(op, funct) begin if op = "0000" then RegDst <= '1'; case funct is when "010" => Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '1'; ALUOp <= "010"; --add MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '1'; when "110" => Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '1'; ALUOp <= "110"; --sub MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '1'; when "000" => Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '1'; ALUOp <= "000"; --and MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '1'; when "001" => Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '1'; ALUOp <= "001"; --or MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '1'; when "111" => Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '1'; ALUOp <= "111"; --slt MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '1'; when others => RegDst <= 'X'; Jump <= 'X'; Branch <= 'X'; MemRead <= 'X'; MemtoReg <= 'X'; ALUOp <= "XXX"; --others MemWrite <= 'X'; ALUSrc <= 'X'; RegWrite <= 'X'; end case; else case op is when "1011" => RegDst <= '1'; Jump <= '0'; Branch <= '0'; MemRead <= '1'; MemtoReg <= '0'; ALUOp <= "010"; --lw MemWrite <= '0'; ALUSrc <= '1'; RegWrite <= '1'; when "1111" => RegDst <= '0'; Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '0'; ALUOp <= "010"; --sw MemWrite <= '1'; ALUSrc <= '1'; RegWrite <= '0'; when "0100" => RegDst <= '0'; Jump <= '0'; Branch <= '1'; MemRead <= '0'; MemtoReg <= '0'; ALUOp <= "110"; --beq MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '0'; when "0010" => RegDst <= '0'; Jump <= '1'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '0'; ALUOp <= "000"; --j MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '0'; when others => RegDst <= 'X'; Jump <= 'X'; Branch <= 'X'; MemRead <= 'X'; MemtoReg <= 'X'; ALUOp <= "XXX"; --others MemWrite <= 'X'; ALUSrc <= 'X'; RegWrite <= 'X'; end case; end if; end process; end logic;
library ieee; use ieee.std_logic_1164.all; use work.lib.all; entity control is port( op : in std_logic_vector(3 downto 0); funct : in std_logic_vector(2 downto 0); RegDst, Jump, Branch, MemRead, MemtoReg, MemWrite, ALUSrc, RegWrite : out std_logic; ALUOp : out std_logic_vector(2 downto 0) ); end control; architecture logic of control is begin process(op, funct) begin if op = "0000" then RegDst <= '1'; case funct is when "010" => Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '1'; ALUOp <= "010"; --add MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '1'; when "110" => Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '1'; ALUOp <= "110"; --sub MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '1'; when "000" => Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '1'; ALUOp <= "000"; --and MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '1'; when "001" => Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '1'; ALUOp <= "001"; --or MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '1'; when "111" => Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '1'; ALUOp <= "111"; --slt MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '1'; when others => RegDst <= 'X'; Jump <= 'X'; Branch <= 'X'; MemRead <= 'X'; MemtoReg <= 'X'; ALUOp <= "XXX"; --others MemWrite <= 'X'; ALUSrc <= 'X'; RegWrite <= 'X'; end case; else case op is when "1011" => RegDst <= '1'; Jump <= '0'; Branch <= '0'; MemRead <= '1'; MemtoReg <= '0'; ALUOp <= "010"; --lw MemWrite <= '0'; ALUSrc <= '1'; RegWrite <= '1'; when "1111" => RegDst <= '0'; Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '0'; ALUOp <= "010"; --sw MemWrite <= '1'; ALUSrc <= '1'; RegWrite <= '0'; when "0100" => RegDst <= '0'; Jump <= '0'; Branch <= '1'; MemRead <= '0'; MemtoReg <= '0'; ALUOp <= "110"; --beq MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '0'; when "0010" => RegDst <= '0'; Jump <= '1'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '0'; ALUOp <= "000"; --j MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '0'; when others => RegDst <= 'X'; Jump <= 'X'; Branch <= 'X'; MemRead <= 'X'; MemtoReg <= 'X'; ALUOp <= "XXX"; --others MemWrite <= 'X'; ALUSrc <= 'X'; RegWrite <= 'X'; end case; end if; end process; end logic;
library ieee; use ieee.std_logic_1164.all; use work.lib.all; entity control is port( op : in std_logic_vector(3 downto 0); funct : in std_logic_vector(2 downto 0); RegDst, Jump, Branch, MemRead, MemtoReg, MemWrite, ALUSrc, RegWrite : out std_logic; ALUOp : out std_logic_vector(2 downto 0) ); end control; architecture logic of control is begin process(op, funct) begin if op = "0000" then RegDst <= '1'; case funct is when "010" => Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '1'; ALUOp <= "010"; --add MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '1'; when "110" => Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '1'; ALUOp <= "110"; --sub MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '1'; when "000" => Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '1'; ALUOp <= "000"; --and MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '1'; when "001" => Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '1'; ALUOp <= "001"; --or MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '1'; when "111" => Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '1'; ALUOp <= "111"; --slt MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '1'; when others => RegDst <= 'X'; Jump <= 'X'; Branch <= 'X'; MemRead <= 'X'; MemtoReg <= 'X'; ALUOp <= "XXX"; --others MemWrite <= 'X'; ALUSrc <= 'X'; RegWrite <= 'X'; end case; else case op is when "1011" => RegDst <= '1'; Jump <= '0'; Branch <= '0'; MemRead <= '1'; MemtoReg <= '0'; ALUOp <= "010"; --lw MemWrite <= '0'; ALUSrc <= '1'; RegWrite <= '1'; when "1111" => RegDst <= '0'; Jump <= '0'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '0'; ALUOp <= "010"; --sw MemWrite <= '1'; ALUSrc <= '1'; RegWrite <= '0'; when "0100" => RegDst <= '0'; Jump <= '0'; Branch <= '1'; MemRead <= '0'; MemtoReg <= '0'; ALUOp <= "110"; --beq MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '0'; when "0010" => RegDst <= '0'; Jump <= '1'; Branch <= '0'; MemRead <= '0'; MemtoReg <= '0'; ALUOp <= "000"; --j MemWrite <= '0'; ALUSrc <= '0'; RegWrite <= '0'; when others => RegDst <= 'X'; Jump <= 'X'; Branch <= 'X'; MemRead <= 'X'; MemtoReg <= 'X'; ALUOp <= "XXX"; --others MemWrite <= 'X'; ALUSrc <= 'X'; RegWrite <= 'X'; end case; end if; end process; end logic;
-- ------------------------------------------------------------- -- -- Generated Architecture Declaration for rtl of inst_9_e -- -- Generated -- by: wig -- on: Mon Jun 26 08:31:57 2006 -- cmd: /cygdrive/h/work/eclipse/MIX/mix_0.pl ../../generic.xls -- -- !!! Do not edit this file! Autogenerated by MIX !!! -- $Author: wig $ -- $Id: inst_9_e-rtl-a.vhd,v 1.5 2006/06/26 08:39:42 wig Exp $ -- $Date: 2006/06/26 08:39:42 $ -- $Log: inst_9_e-rtl-a.vhd,v $ -- Revision 1.5 2006/06/26 08:39:42 wig -- Update more testcases (up to generic) -- -- -- Based on Mix Architecture Template built into RCSfile: MixWriter.pm,v -- Id: MixWriter.pm,v 1.90 2006/06/22 07:13:21 wig Exp -- -- Generator: mix_0.pl Revision: 1.46 , [email protected] -- (C) 2003,2005 Micronas GmbH -- -- -------------------------------------------------------------- library IEEE; use IEEE.std_logic_1164.all; -- No project specific VHDL libraries/arch -- -- -- Start of Generated Architecture rtl of inst_9_e -- architecture rtl of inst_9_e is -- -- Generated Constant Declarations -- -- -- Generated Components -- -- -- Generated Signal List -- -- -- End of Generated Signal List -- begin -- -- Generated Concurrent Statements -- -- -- Generated Signal Assignments -- -- -- Generated Instances and Port Mappings -- end rtl; -- --!End of Architecture/s -- --------------------------------------------------------------
-------------------------------------------------------------------------------- -- This file is owned and controlled by Xilinx and must be used solely -- -- for design, simulation, implementation and creation of design files -- -- limited to Xilinx devices or technologies. Use with non-Xilinx -- -- devices or technologies is expressly prohibited and immediately -- -- terminates your license. -- -- -- -- XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" SOLELY -- -- FOR USE IN DEVELOPING PROGRAMS AND SOLUTIONS FOR XILINX DEVICES. BY -- -- PROVIDING THIS DESIGN, CODE, OR INFORMATION AS ONE POSSIBLE -- -- IMPLEMENTATION OF THIS FEATURE, APPLICATION OR STANDARD, XILINX IS -- -- MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION IS FREE FROM ANY -- -- CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE FOR OBTAINING ANY -- -- RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION. XILINX EXPRESSLY -- -- DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE -- -- IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR -- -- REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF -- -- INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -- -- PARTICULAR PURPOSE. -- -- -- -- Xilinx products are not intended for use in life support appliances, -- -- devices, or systems. Use in such applications are expressly -- -- prohibited. -- -- -- -- (c) Copyright 1995-2014 Xilinx, Inc. -- -- All rights reserved. -- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -- You must compile the wrapper file fr_cmplr_v6_3_b1697e0c92d2e32a.vhd when simulating -- the core, fr_cmplr_v6_3_b1697e0c92d2e32a. When compiling the wrapper file, be sure to -- reference the XilinxCoreLib VHDL simulation library. For detailed -- instructions, please refer to the "CORE Generator Help". -- The synthesis directives "translate_off/translate_on" specified -- below are supported by Xilinx, Mentor Graphics and Synplicity -- synthesis tools. Ensure they are correct for your synthesis tool(s). LIBRARY ieee; USE ieee.std_logic_1164.ALL; -- synthesis translate_off LIBRARY XilinxCoreLib; -- synthesis translate_on ENTITY fr_cmplr_v6_3_b1697e0c92d2e32a IS PORT ( aclk : IN STD_LOGIC; aclken : IN STD_LOGIC; s_axis_data_tvalid : IN STD_LOGIC; s_axis_data_tready : OUT STD_LOGIC; s_axis_data_tuser : IN STD_LOGIC_VECTOR(1 DOWNTO 0); s_axis_data_tdata : IN STD_LOGIC_VECTOR(31 DOWNTO 0); m_axis_data_tvalid : OUT STD_LOGIC; m_axis_data_tuser : OUT STD_LOGIC_VECTOR(1 DOWNTO 0); m_axis_data_tdata : OUT STD_LOGIC_VECTOR(31 DOWNTO 0); event_s_data_chanid_incorrect : OUT STD_LOGIC ); END fr_cmplr_v6_3_b1697e0c92d2e32a; ARCHITECTURE fr_cmplr_v6_3_b1697e0c92d2e32a_a OF fr_cmplr_v6_3_b1697e0c92d2e32a IS -- synthesis translate_off COMPONENT wrapped_fr_cmplr_v6_3_b1697e0c92d2e32a PORT ( aclk : IN STD_LOGIC; aclken : IN STD_LOGIC; s_axis_data_tvalid : IN STD_LOGIC; s_axis_data_tready : OUT STD_LOGIC; s_axis_data_tuser : IN STD_LOGIC_VECTOR(1 DOWNTO 0); s_axis_data_tdata : IN STD_LOGIC_VECTOR(31 DOWNTO 0); m_axis_data_tvalid : OUT STD_LOGIC; m_axis_data_tuser : OUT STD_LOGIC_VECTOR(1 DOWNTO 0); m_axis_data_tdata : OUT STD_LOGIC_VECTOR(31 DOWNTO 0); event_s_data_chanid_incorrect : OUT STD_LOGIC ); END COMPONENT; -- Configuration specification FOR ALL : wrapped_fr_cmplr_v6_3_b1697e0c92d2e32a USE ENTITY XilinxCoreLib.fir_compiler_v6_3(behavioral) GENERIC MAP ( c_accum_op_path_widths => "44", c_accum_path_widths => "44", c_channel_pattern => "fixed", c_coef_file => "fr_cmplr_v6_3_b1697e0c92d2e32a.mif", c_coef_file_lines => 240, c_coef_mem_packing => 0, c_coef_memtype => 1, c_coef_path_sign => "0", c_coef_path_src => "0", c_coef_path_widths => "16", c_coef_reload => 0, c_coef_width => 16, c_col_config => "1", c_col_mode => 1, c_col_pipe_len => 4, c_component_name => "fr_cmplr_v6_3_b1697e0c92d2e32a", c_config_packet_size => 0, c_config_sync_mode => 0, c_config_tdata_width => 1, c_data_has_tlast => 0, c_data_mem_packing => 0, c_data_memtype => 1, c_data_path_sign => "0", c_data_path_src => "0", c_data_path_widths => "25", c_data_width => 25, c_datapath_memtype => 2, c_decim_rate => 10, c_ext_mult_cnfg => "none", c_filter_type => 1, c_filts_packed => 0, c_has_aclken => 1, c_has_aresetn => 0, c_has_config_channel => 0, c_input_rate => 5600000, c_interp_rate => 1, c_ipbuff_memtype => 0, c_latency => 31, c_m_data_has_tready => 0, c_m_data_has_tuser => 1, c_m_data_tdata_width => 32, c_m_data_tuser_width => 2, c_mem_arrangement => 0, c_num_channels => 4, c_num_filts => 1, c_num_madds => 1, c_num_reload_slots => 1, c_num_taps => 240, c_opbuff_memtype => 0, c_opt_madds => "none", c_optimization => 0, c_output_path_widths => "26", c_output_rate => 56000000, c_output_width => 26, c_oversampling_rate => 24, c_reload_tdata_width => 1, c_round_mode => 4, c_s_data_has_fifo => 0, c_s_data_has_tuser => 1, c_s_data_tdata_width => 32, c_s_data_tuser_width => 2, c_symmetry => 0, c_xdevicefamily => "artix7", c_zero_packing_factor => 1 ); -- synthesis translate_on BEGIN -- synthesis translate_off U0 : wrapped_fr_cmplr_v6_3_b1697e0c92d2e32a PORT MAP ( aclk => aclk, aclken => aclken, s_axis_data_tvalid => s_axis_data_tvalid, s_axis_data_tready => s_axis_data_tready, s_axis_data_tuser => s_axis_data_tuser, s_axis_data_tdata => s_axis_data_tdata, m_axis_data_tvalid => m_axis_data_tvalid, m_axis_data_tuser => m_axis_data_tuser, m_axis_data_tdata => m_axis_data_tdata, event_s_data_chanid_incorrect => event_s_data_chanid_incorrect ); -- synthesis translate_on END fr_cmplr_v6_3_b1697e0c92d2e32a_a;
------------------------------------------------------------------------------- -- Title : UART testbench -- Project : fpga_logic_analyzer ------------------------------------------------------------------------------- -- File : UART_tb.vhd -- Created : 2016-02-22 -- Last update: 2016-03-28 -- Standard : VHDL'08 ------------------------------------------------------------------------------- -- Description: This is the UART testbench ------------------------------------------------------------------------------- -- Copyright (c) 2016 Ashton Johnson, Paul Henny, Ian Swepston, David Hurt ------------------------------------------------------------------------------- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- You should have received a copy of the GNU General Public License along -- with this program; if not, write to the Free Software Foundation, Inc., -- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ------------------------------------------------------------------------------- -- Revisions : -- Date Version Author Description -- 2016-03-16 1.0 ian Created ------------------------------------------------------------------------------- use WORK.all; library ieee; use IEEE.std_logic_1164.all; entity UART_tb is end entity; library ieee; use IEEE.std_logic_1164.all; architecture test of UART_tb is signal clk : std_logic := '1'; -- clock signal rst : std_logic; -- reset logic signal rx_get_more_data : std_logic; -- stop bit found for stream in signal rx_data_ready : std_logic; -- stream out ready signal rx : std_logic; -- receive line signal data_in : std_logic_vector(7 downto 0) := (others => '0'); -- data to be transmitted signal tx_data_ready : std_logic; -- stream out stop bit sent signal tx_data_sent : std_logic; -- ready for rx signal tx : std_logic := '1'; -- transmit line signal data_out : std_logic_vector(7 downto 0) := (others => '0'); signal receive_data : std_logic_vector(7 downto 0); signal baud_clock : std_logic := '1'; signal baud_counter : integer := 0; constant baud_rate : integer := 10_000; constant clock_freq : integer := 10_000_000; constant baud_total : integer := (clock_freq/baud_rate)/2; begin u1 : entity work.uart_comms generic map (clock_freq => clock_freq, baud_rate => baud_rate) port map ( clk => clk, rst => rst, rx_get_more_data => rx_get_more_data, rx_data_ready => rx_data_ready, rx => rx, data_in => data_in, tx_data_ready => tx_data_ready, tx_data_sent => tx_data_sent, tx => tx, data_out => data_out); process (clk) begin clk <= not clk after 50 ns; -- 10 MHz clock end process; baud_clocking : process (clk) begin if(clk = '1' and clk'event) then if (baud_counter < baud_total-1) then baud_counter <= baud_counter + 1; else baud_counter <= 0; baud_clock <= not baud_clock; end if; end if; end process baud_clocking; process begin rx <= '1'; rst <= '0'; wait for 10 ns; receive_data <= "10011100"; wait until rising_edge(baud_clock); rx_get_more_data <= '0'; wait until rising_edge(baud_clock); rx <= '1'; -- nothing wait until rising_edge(baud_clock); rx <= '0'; -- stb wait until rising_edge(baud_clock); rx <= receive_data(0); wait until rising_edge(baud_clock); rx <= receive_data(1); wait until rising_edge(baud_clock); rx <= receive_data(2); wait until rising_edge(baud_clock); rx <= receive_data(3); wait until rising_edge(baud_clock); rx <= receive_data(4); wait until rising_edge(baud_clock); rx <= receive_data(5); wait until rising_edge(baud_clock); rx <= receive_data(6); wait until rising_edge(baud_clock); rx <= receive_data(7); wait until rising_edge(baud_clock); rx <= '1'; -- end assert data_out=receive_data report "data out does not match UART data in" severity failure; wait for 100 us; wait until rising_edge(baud_clock); rx_get_more_data <= '1'; end process; process begin tx_data_ready <= '0'; wait until rising_edge(baud_clock); wait until rising_edge(baud_clock); wait until rising_edge(baud_clock); wait until rising_edge(baud_clock); data_in <= "10100111"; tx_data_ready <= '1'; wait for 100 ms; end process; end test;
------------------------------------------------------------------------------- -- -- Title : local_link_source.vhd - part of the Groucher simulation environment -- -- Description : This code models the behavior of a local link source device -- to drive a Grouch module with optional status and length interfaces -- -- Files: reads from a file data and control inputs -- if a line starts with capital W then the following number if interpreted -- as an integer, and the program waits for this integer * cycles -- if a line starts with a captial D then the rest is interpreted as follows: -- data bus '' ctl signals( * - DONE - EMPTY -ALMOST) -- the bit size of the values must be at least the size of the bus rounded to the next 4 -- and is always interpreted as hex. -- Organization is MSB to LSB -- length and status are optional -- if their widths (generics S_WIDTH and L_WIDTH) are set to 0, then -- we won't parse for them in the file -- Interface: the processing starts after rst de-asserts -- drives a standard tx interface (local link + len + sts) -- Parameters: data width -- bpr_sensitive -- pkt_filename -- -- ---------------------------------------------------------------------------- -- DONE is ignored.... -- DONE is ignored.... -- ---------------------------------------------------------------------------- -- Changelog: -- 2 Control Flow Bugs fixed. LIBRARY IEEE; USE IEEE.std_logic_1164.ALL; USE IEEE.std_logic_arith.ALL; USE IEEE.std_logic_unsigned.ALL; USE IEEE.STD_LOGIC_TEXTIO.all; LIBRARY STD; USE STD.TEXTIO.ALL; entity kvs_tbDriverHDLNode is generic ( D_WIDTH : integer := 64; BPR_SENSITIVE : Boolean := true; -- decides whether we react to backpressure or not --PKT_FILENAME : string := "/home/kimonk/vc709sim/pkt.in.2.txt" PKT_FILENAME : string := "pkt.in.txt" ); port ( clk : in std_logic; rst : in std_logic; udp_out_ready : in std_logic; udp_out_valid : out std_logic; udp_out_keep : out std_logic_vector(7 downto 0); udp_out_user : out std_logic_vector(111 downto 0); udp_out_last : out std_logic; udp_out_data : out std_logic_vector (63 downto 0) ); end kvs_tbDriverHDLNode; architecture rtl of kvs_tbDriverHDLNode is -- read width from file- roudns each value up to the next multiple of 4 constant FD_WIDTH : integer := ((D_WIDTH-1) / 4)*4 + 4; --signal item_consumed : std_logic; begin read_file_p : process FILE data_file : TEXT OPEN READ_MODE IS PKT_FILENAME; variable c : character; variable wait_period : integer; variable l : line; variable read_dat : std_logic_vector(63 downto 0); variable read_keep : std_logic_vector(7 downto 0); variable read_ctl : std_logic_vector(3 downto 0); variable item_consumed : std_logic; variable cntCorrection : integer; variable firstRun : integer; --variable read_ctl_buf : std_logic_Vector(3 downto 0) := (others => '1'); begin if (D_WIDTH=0) then assert false report "D_WIDTH and R_WIDTH must be greater than 0" severity failure; end if; -- assign defaults for rest udp_out_valid <= '0'; udp_out_last <= '0'; udp_out_data <=(others => '0'); udp_out_keep <=(others => '0'); udp_out_user <=(others => '0'); item_consumed := '0'; firstRun := 0; wait_period := 1; wait until CLK'event and CLK='1'; while (not endfile(data_file)) loop READLINE(data_file, l); READ(l, c); case c is when 'W' => -- wait READ(l,wait_period); cntCorrection := 1; for i in 0 to wait_period -1 loop udp_out_valid <= '0'; wait until CLK'event and CLK='1'; end loop; when others => -- parse data line HREAD(l,read_dat); READ(l,c);--blank HREAD(l,read_keep); READ(l,c);--blank HREAD(l,read_ctl); udp_out_data <= read_dat; udp_out_keep <= read_keep; if (read_ctl = 1) then udp_out_last <= '1'; else udp_out_last <= '0'; end if; udp_out_valid <= '1'; wait until udp_out_ready = '1' and CLK'event and CLK='1'; end case; --wait until CLK'event and CLK='1'; end loop; wait until CLK'event and CLK='1'; -- following delay is to ensure the last bit of data -- is through the simulation wait for 1000 * 1000 ns; -- then terminate the simulation --if (endfile(data_file)) then -- assert false report "End of simulation." severity failure; --end if; end process; end rtl;
LIBRARY ieee; USE ieee.std_logic_1164.all; ENTITY rsc IS PORT ( r : IN std_logic; s : IN std_logic; c : IN std_logic; q : OUT std_logic; qi : OUT std_logic ); END rsc; ARCHITECTURE behavior OF rsc IS COMPONENT rs IS PORT ( r : IN std_logic; s : IN std_logic; q : OUT std_logic; qi : OUT std_logic ); END COMPONENT; SIGNAL a, b : std_logic; BEGIN a <= s and c; b <= r and c; flipflop : rs PORT MAP(a, b, q, qi); END behavior;
------------------------------------------------------------------------------ -- This file is a part of the GRLIB VHDL IP LIBRARY -- Copyright (C) 2011, Aeroflex Gaisler AB - all rights reserved. -- -- ANY USE OR REDISTRIBUTION IN PART OR IN WHOLE MUST BE HANDLED IN -- ACCORDANCE WITH THE GAISLER LICENSE AGREEMENT AND MUST BE APPROVED -- IN ADVANCE IN WRITING. ------------------------------------------------------------------------------ -- library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; --library synplify; entity spictrl_unisim is generic ( slvselen : integer range 0 to 1 := 0; slvselsz : integer range 1 to 32 := 1); port ( rstn : in std_ulogic; clk : in std_ulogic; -- APB signals apbi_psel : in std_ulogic; apbi_penable : in std_ulogic; apbi_paddr : in std_logic_vector(31 downto 0); apbi_pwrite : in std_ulogic; apbi_pwdata : in std_logic_vector(31 downto 0); apbi_testen : in std_ulogic; apbi_testrst : in std_ulogic; apbi_scanen : in std_ulogic; apbi_testoen : in std_ulogic; apbo_prdata : out std_logic_vector(31 downto 0); apbo_pirq : out std_ulogic; -- SPI signals spii_miso : in std_ulogic; spii_mosi : in std_ulogic; spii_sck : in std_ulogic; spii_spisel : in std_ulogic; spii_astart : in std_ulogic; spii_cstart : in std_ulogic; spio_miso : out std_ulogic; spio_misooen : out std_ulogic; spio_mosi : out std_ulogic; spio_mosioen : out std_ulogic; spio_sck : out std_ulogic; spio_sckoen : out std_ulogic; spio_enable : out std_ulogic; spio_astart : out std_ulogic; spio_aready : out std_ulogic; slvsel : out std_logic_vector((slvselsz-1) downto 0)); end spictrl_unisim; architecture rtl of spictrl_unisim is -- Combination 0, 32 slave selects component spictrl_unisim_comb0 port ( rstn : in std_ulogic; clk : in std_ulogic; -- APB signals apbi_psel : in std_ulogic; apbi_penable : in std_ulogic; apbi_paddr : in std_logic_vector(31 downto 0); apbi_pwrite : in std_ulogic; apbi_pwdata : in std_logic_vector(31 downto 0); apbi_testen : in std_ulogic; apbi_testrst : in std_ulogic; apbi_scanen : in std_ulogic; apbi_testoen : in std_ulogic; apbo_prdata : out std_logic_vector(31 downto 0); apbo_pirq : out std_ulogic; -- SPI signals spii_miso : in std_ulogic; spii_mosi : in std_ulogic; spii_sck : in std_ulogic; spii_spisel : in std_ulogic; spii_astart : in std_ulogic; spii_cstart : in std_ulogic; spio_miso : out std_ulogic; spio_misooen : out std_ulogic; spio_mosi : out std_ulogic; spio_mosioen : out std_ulogic; spio_sck : out std_ulogic; spio_sckoen : out std_ulogic; spio_enable : out std_ulogic; spio_astart : out std_ulogic; spio_aready : out std_ulogic; slvsel : out std_logic_vector(31 downto 0)); end component; -- Combination 1, 32 disabled slave selects component spictrl_unisim_comb1 port ( rstn : in std_ulogic; clk : in std_ulogic; -- APB signals apbi_psel : in std_ulogic; apbi_penable : in std_ulogic; apbi_paddr : in std_logic_vector(31 downto 0); apbi_pwrite : in std_ulogic; apbi_pwdata : in std_logic_vector(31 downto 0); apbi_testen : in std_ulogic; apbi_testrst : in std_ulogic; apbi_scanen : in std_ulogic; apbi_testoen : in std_ulogic; apbo_prdata : out std_logic_vector(31 downto 0); apbo_pirq : out std_ulogic; -- SPI signals spii_miso : in std_ulogic; spii_mosi : in std_ulogic; spii_sck : in std_ulogic; spii_spisel : in std_ulogic; spii_astart : in std_ulogic; spii_cstart : in std_ulogic; spio_miso : out std_ulogic; spio_misooen : out std_ulogic; spio_mosi : out std_ulogic; spio_mosioen : out std_ulogic; spio_sck : out std_ulogic; spio_sckoen : out std_ulogic; spio_enable : out std_ulogic; spio_astart : out std_ulogic; spio_aready : out std_ulogic; slvsel : out std_logic_vector(31 downto 0)); end component; begin slvselact : if slvselen /= 0 generate spic0 : spictrl_unisim_comb0 port map ( rstn => rstn, clk => clk, -- APB signals apbi_psel => apbi_psel, apbi_penable => apbi_penable, apbi_paddr => apbi_paddr, apbi_pwrite => apbi_pwrite, apbi_pwdata => apbi_pwdata, apbi_testen => apbi_testen, apbi_testrst => apbi_testrst, apbi_scanen => apbi_scanen, apbi_testoen => apbi_testoen, apbo_prdata => apbo_prdata, apbo_pirq => apbo_pirq, -- SPI signals spii_miso => spii_miso, spii_mosi => spii_mosi, spii_sck => spii_sck, spii_spisel => spii_spisel, spii_astart => spii_astart, spii_cstart => spii_cstart, spio_miso => spio_miso, spio_misooen => spio_misooen, spio_mosi => spio_mosi, spio_mosioen => spio_mosioen, spio_sck => spio_sck, spio_sckoen => spio_sckoen, spio_enable => spio_enable, spio_astart => spio_astart, spio_aready => spio_aready, slvsel => slvsel); end generate; noslvsel : if slvselen = 0 generate spic0 : spictrl_unisim_comb1 port map ( rstn => rstn, clk => clk, -- APB signals apbi_psel => apbi_psel, apbi_penable => apbi_penable, apbi_paddr => apbi_paddr, apbi_pwrite => apbi_pwrite, apbi_pwdata => apbi_pwdata, apbi_testen => apbi_testen, apbi_testrst => apbi_testrst, apbi_scanen => apbi_scanen, apbi_testoen => apbi_testoen, apbo_prdata => apbo_prdata, apbo_pirq => apbo_pirq, -- SPI signals spii_miso => spii_miso, spii_mosi => spii_mosi, spii_sck => spii_sck, spii_spisel => spii_spisel, spii_astart => spii_astart, spii_cstart => spii_cstart, spio_miso => spio_miso, spio_misooen => spio_misooen, spio_mosi => spio_mosi, spio_mosioen => spio_mosioen, spio_sck => spio_sck, spio_sckoen => spio_sckoen, spio_enable => spio_enable, spio_astart => spio_astart, spio_aready => spio_aready, slvsel => slvsel); end generate; end rtl;
------------------------------------------------------------------------------ -- This file is a part of the GRLIB VHDL IP LIBRARY -- Copyright (C) 2011, Aeroflex Gaisler AB - all rights reserved. -- -- ANY USE OR REDISTRIBUTION IN PART OR IN WHOLE MUST BE HANDLED IN -- ACCORDANCE WITH THE GAISLER LICENSE AGREEMENT AND MUST BE APPROVED -- IN ADVANCE IN WRITING. ------------------------------------------------------------------------------ -- library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; --library synplify; entity spictrl_unisim is generic ( slvselen : integer range 0 to 1 := 0; slvselsz : integer range 1 to 32 := 1); port ( rstn : in std_ulogic; clk : in std_ulogic; -- APB signals apbi_psel : in std_ulogic; apbi_penable : in std_ulogic; apbi_paddr : in std_logic_vector(31 downto 0); apbi_pwrite : in std_ulogic; apbi_pwdata : in std_logic_vector(31 downto 0); apbi_testen : in std_ulogic; apbi_testrst : in std_ulogic; apbi_scanen : in std_ulogic; apbi_testoen : in std_ulogic; apbo_prdata : out std_logic_vector(31 downto 0); apbo_pirq : out std_ulogic; -- SPI signals spii_miso : in std_ulogic; spii_mosi : in std_ulogic; spii_sck : in std_ulogic; spii_spisel : in std_ulogic; spii_astart : in std_ulogic; spii_cstart : in std_ulogic; spio_miso : out std_ulogic; spio_misooen : out std_ulogic; spio_mosi : out std_ulogic; spio_mosioen : out std_ulogic; spio_sck : out std_ulogic; spio_sckoen : out std_ulogic; spio_enable : out std_ulogic; spio_astart : out std_ulogic; spio_aready : out std_ulogic; slvsel : out std_logic_vector((slvselsz-1) downto 0)); end spictrl_unisim; architecture rtl of spictrl_unisim is -- Combination 0, 32 slave selects component spictrl_unisim_comb0 port ( rstn : in std_ulogic; clk : in std_ulogic; -- APB signals apbi_psel : in std_ulogic; apbi_penable : in std_ulogic; apbi_paddr : in std_logic_vector(31 downto 0); apbi_pwrite : in std_ulogic; apbi_pwdata : in std_logic_vector(31 downto 0); apbi_testen : in std_ulogic; apbi_testrst : in std_ulogic; apbi_scanen : in std_ulogic; apbi_testoen : in std_ulogic; apbo_prdata : out std_logic_vector(31 downto 0); apbo_pirq : out std_ulogic; -- SPI signals spii_miso : in std_ulogic; spii_mosi : in std_ulogic; spii_sck : in std_ulogic; spii_spisel : in std_ulogic; spii_astart : in std_ulogic; spii_cstart : in std_ulogic; spio_miso : out std_ulogic; spio_misooen : out std_ulogic; spio_mosi : out std_ulogic; spio_mosioen : out std_ulogic; spio_sck : out std_ulogic; spio_sckoen : out std_ulogic; spio_enable : out std_ulogic; spio_astart : out std_ulogic; spio_aready : out std_ulogic; slvsel : out std_logic_vector(31 downto 0)); end component; -- Combination 1, 32 disabled slave selects component spictrl_unisim_comb1 port ( rstn : in std_ulogic; clk : in std_ulogic; -- APB signals apbi_psel : in std_ulogic; apbi_penable : in std_ulogic; apbi_paddr : in std_logic_vector(31 downto 0); apbi_pwrite : in std_ulogic; apbi_pwdata : in std_logic_vector(31 downto 0); apbi_testen : in std_ulogic; apbi_testrst : in std_ulogic; apbi_scanen : in std_ulogic; apbi_testoen : in std_ulogic; apbo_prdata : out std_logic_vector(31 downto 0); apbo_pirq : out std_ulogic; -- SPI signals spii_miso : in std_ulogic; spii_mosi : in std_ulogic; spii_sck : in std_ulogic; spii_spisel : in std_ulogic; spii_astart : in std_ulogic; spii_cstart : in std_ulogic; spio_miso : out std_ulogic; spio_misooen : out std_ulogic; spio_mosi : out std_ulogic; spio_mosioen : out std_ulogic; spio_sck : out std_ulogic; spio_sckoen : out std_ulogic; spio_enable : out std_ulogic; spio_astart : out std_ulogic; spio_aready : out std_ulogic; slvsel : out std_logic_vector(31 downto 0)); end component; begin slvselact : if slvselen /= 0 generate spic0 : spictrl_unisim_comb0 port map ( rstn => rstn, clk => clk, -- APB signals apbi_psel => apbi_psel, apbi_penable => apbi_penable, apbi_paddr => apbi_paddr, apbi_pwrite => apbi_pwrite, apbi_pwdata => apbi_pwdata, apbi_testen => apbi_testen, apbi_testrst => apbi_testrst, apbi_scanen => apbi_scanen, apbi_testoen => apbi_testoen, apbo_prdata => apbo_prdata, apbo_pirq => apbo_pirq, -- SPI signals spii_miso => spii_miso, spii_mosi => spii_mosi, spii_sck => spii_sck, spii_spisel => spii_spisel, spii_astart => spii_astart, spii_cstart => spii_cstart, spio_miso => spio_miso, spio_misooen => spio_misooen, spio_mosi => spio_mosi, spio_mosioen => spio_mosioen, spio_sck => spio_sck, spio_sckoen => spio_sckoen, spio_enable => spio_enable, spio_astart => spio_astart, spio_aready => spio_aready, slvsel => slvsel); end generate; noslvsel : if slvselen = 0 generate spic0 : spictrl_unisim_comb1 port map ( rstn => rstn, clk => clk, -- APB signals apbi_psel => apbi_psel, apbi_penable => apbi_penable, apbi_paddr => apbi_paddr, apbi_pwrite => apbi_pwrite, apbi_pwdata => apbi_pwdata, apbi_testen => apbi_testen, apbi_testrst => apbi_testrst, apbi_scanen => apbi_scanen, apbi_testoen => apbi_testoen, apbo_prdata => apbo_prdata, apbo_pirq => apbo_pirq, -- SPI signals spii_miso => spii_miso, spii_mosi => spii_mosi, spii_sck => spii_sck, spii_spisel => spii_spisel, spii_astart => spii_astart, spii_cstart => spii_cstart, spio_miso => spio_miso, spio_misooen => spio_misooen, spio_mosi => spio_mosi, spio_mosioen => spio_mosioen, spio_sck => spio_sck, spio_sckoen => spio_sckoen, spio_enable => spio_enable, spio_astart => spio_astart, spio_aready => spio_aready, slvsel => slvsel); end generate; end rtl;
------------------------------------------------------------------------------ -- This file is a part of the GRLIB VHDL IP LIBRARY -- Copyright (C) 2011, Aeroflex Gaisler AB - all rights reserved. -- -- ANY USE OR REDISTRIBUTION IN PART OR IN WHOLE MUST BE HANDLED IN -- ACCORDANCE WITH THE GAISLER LICENSE AGREEMENT AND MUST BE APPROVED -- IN ADVANCE IN WRITING. ------------------------------------------------------------------------------ -- library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; --library synplify; entity spictrl_unisim is generic ( slvselen : integer range 0 to 1 := 0; slvselsz : integer range 1 to 32 := 1); port ( rstn : in std_ulogic; clk : in std_ulogic; -- APB signals apbi_psel : in std_ulogic; apbi_penable : in std_ulogic; apbi_paddr : in std_logic_vector(31 downto 0); apbi_pwrite : in std_ulogic; apbi_pwdata : in std_logic_vector(31 downto 0); apbi_testen : in std_ulogic; apbi_testrst : in std_ulogic; apbi_scanen : in std_ulogic; apbi_testoen : in std_ulogic; apbo_prdata : out std_logic_vector(31 downto 0); apbo_pirq : out std_ulogic; -- SPI signals spii_miso : in std_ulogic; spii_mosi : in std_ulogic; spii_sck : in std_ulogic; spii_spisel : in std_ulogic; spii_astart : in std_ulogic; spii_cstart : in std_ulogic; spio_miso : out std_ulogic; spio_misooen : out std_ulogic; spio_mosi : out std_ulogic; spio_mosioen : out std_ulogic; spio_sck : out std_ulogic; spio_sckoen : out std_ulogic; spio_enable : out std_ulogic; spio_astart : out std_ulogic; spio_aready : out std_ulogic; slvsel : out std_logic_vector((slvselsz-1) downto 0)); end spictrl_unisim; architecture rtl of spictrl_unisim is -- Combination 0, 32 slave selects component spictrl_unisim_comb0 port ( rstn : in std_ulogic; clk : in std_ulogic; -- APB signals apbi_psel : in std_ulogic; apbi_penable : in std_ulogic; apbi_paddr : in std_logic_vector(31 downto 0); apbi_pwrite : in std_ulogic; apbi_pwdata : in std_logic_vector(31 downto 0); apbi_testen : in std_ulogic; apbi_testrst : in std_ulogic; apbi_scanen : in std_ulogic; apbi_testoen : in std_ulogic; apbo_prdata : out std_logic_vector(31 downto 0); apbo_pirq : out std_ulogic; -- SPI signals spii_miso : in std_ulogic; spii_mosi : in std_ulogic; spii_sck : in std_ulogic; spii_spisel : in std_ulogic; spii_astart : in std_ulogic; spii_cstart : in std_ulogic; spio_miso : out std_ulogic; spio_misooen : out std_ulogic; spio_mosi : out std_ulogic; spio_mosioen : out std_ulogic; spio_sck : out std_ulogic; spio_sckoen : out std_ulogic; spio_enable : out std_ulogic; spio_astart : out std_ulogic; spio_aready : out std_ulogic; slvsel : out std_logic_vector(31 downto 0)); end component; -- Combination 1, 32 disabled slave selects component spictrl_unisim_comb1 port ( rstn : in std_ulogic; clk : in std_ulogic; -- APB signals apbi_psel : in std_ulogic; apbi_penable : in std_ulogic; apbi_paddr : in std_logic_vector(31 downto 0); apbi_pwrite : in std_ulogic; apbi_pwdata : in std_logic_vector(31 downto 0); apbi_testen : in std_ulogic; apbi_testrst : in std_ulogic; apbi_scanen : in std_ulogic; apbi_testoen : in std_ulogic; apbo_prdata : out std_logic_vector(31 downto 0); apbo_pirq : out std_ulogic; -- SPI signals spii_miso : in std_ulogic; spii_mosi : in std_ulogic; spii_sck : in std_ulogic; spii_spisel : in std_ulogic; spii_astart : in std_ulogic; spii_cstart : in std_ulogic; spio_miso : out std_ulogic; spio_misooen : out std_ulogic; spio_mosi : out std_ulogic; spio_mosioen : out std_ulogic; spio_sck : out std_ulogic; spio_sckoen : out std_ulogic; spio_enable : out std_ulogic; spio_astart : out std_ulogic; spio_aready : out std_ulogic; slvsel : out std_logic_vector(31 downto 0)); end component; begin slvselact : if slvselen /= 0 generate spic0 : spictrl_unisim_comb0 port map ( rstn => rstn, clk => clk, -- APB signals apbi_psel => apbi_psel, apbi_penable => apbi_penable, apbi_paddr => apbi_paddr, apbi_pwrite => apbi_pwrite, apbi_pwdata => apbi_pwdata, apbi_testen => apbi_testen, apbi_testrst => apbi_testrst, apbi_scanen => apbi_scanen, apbi_testoen => apbi_testoen, apbo_prdata => apbo_prdata, apbo_pirq => apbo_pirq, -- SPI signals spii_miso => spii_miso, spii_mosi => spii_mosi, spii_sck => spii_sck, spii_spisel => spii_spisel, spii_astart => spii_astart, spii_cstart => spii_cstart, spio_miso => spio_miso, spio_misooen => spio_misooen, spio_mosi => spio_mosi, spio_mosioen => spio_mosioen, spio_sck => spio_sck, spio_sckoen => spio_sckoen, spio_enable => spio_enable, spio_astart => spio_astart, spio_aready => spio_aready, slvsel => slvsel); end generate; noslvsel : if slvselen = 0 generate spic0 : spictrl_unisim_comb1 port map ( rstn => rstn, clk => clk, -- APB signals apbi_psel => apbi_psel, apbi_penable => apbi_penable, apbi_paddr => apbi_paddr, apbi_pwrite => apbi_pwrite, apbi_pwdata => apbi_pwdata, apbi_testen => apbi_testen, apbi_testrst => apbi_testrst, apbi_scanen => apbi_scanen, apbi_testoen => apbi_testoen, apbo_prdata => apbo_prdata, apbo_pirq => apbo_pirq, -- SPI signals spii_miso => spii_miso, spii_mosi => spii_mosi, spii_sck => spii_sck, spii_spisel => spii_spisel, spii_astart => spii_astart, spii_cstart => spii_cstart, spio_miso => spio_miso, spio_misooen => spio_misooen, spio_mosi => spio_mosi, spio_mosioen => spio_mosioen, spio_sck => spio_sck, spio_sckoen => spio_sckoen, spio_enable => spio_enable, spio_astart => spio_astart, spio_aready => spio_aready, slvsel => slvsel); end generate; end rtl;
---------------------------------------------------------------------------------- -- Company: -- Engineer: -- -- Create Date: 03.07.2017 10:01:38 -- Design Name: -- Module Name: tb_complex_abs_esaustivo - Behavioral -- Project Name: -- Target Devices: -- Tool Versions: -- Description: -- -- Dependencies: -- -- Revision: -- Revision 0.01 - File Created -- Additional Comments: -- ---------------------------------------------------------------------------------- LIBRARY ieee; USE ieee.std_logic_1164.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; use IEEE.NUMERIC_STD.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use ieee.math_real.all; use ieee.numeric_std.all; -- Uncomment the following library declaration if using -- arithmetic functions with Signed or Unsigned values --use IEEE.NUMERIC_STD.ALL; -- Uncomment the following library declaration if instantiating -- any Xilinx leaf cells in this code. --library UNISIM; --use UNISIM.VComponents.all; entity tb_complex_abs_esaustivo is -- Port ( ); end tb_complex_abs_esaustivo; architecture Behavioral of tb_complex_abs_esaustivo is component complex_abs is Generic ( complex_width : natural := 32 ); --! Parallelismo in bit del numero complesso (inteso come somma di parte reale e immaginaria) Port ( clock : in STD_LOGIC; --! Segnale di temporizzazione reset_n : in STD_LOGIC; --! Segnale di reset 0-attivo enable : in STD_LOGIC; complex_value : in STD_LOGIC_VECTOR (complex_width-1 downto 0); --! Numero complesso di cui calcolare il modulo abs_value : out STD_LOGIC_VECTOR (complex_width-1 downto 0); --! Modulo del numero complesso done : out STD_LOGIC); --! Segnale di terminazione delle operazioni end component complex_abs; constant complex_width : natural:= 32; constant clock_period : time := 10 ns; constant num_cicli : natural := 10000; signal clock : std_logic := '0'; signal reset_n : std_logic := '0'; signal enable : std_logic := '0'; signal done : std_logic := '0'; signal complex_value : std_logic_vector(complex_width-1 downto 0) := (others => '0'); signal abs_value : std_logic_vector(complex_width-1 downto 0) := (others => '0'); begin uut: complex_abs port map ( clock => clock, reset_n => reset_n, enable => enable, complex_value => complex_value, abs_value => abs_value, done => done ); -- Clock process definitions clock_process :process begin clock <= '0'; wait for clock_period/2; clock <= '1'; wait for clock_period/2; end process; -- Stimulus process stim_proc: process variable valore_assoluto : std_logic_vector(complex_width-1 downto 0) := (others => '0'); variable complex_value_variable : integer := -(2 ** ((complex_width/2)-1)); begin -- hold reset state for 100 ns. reset_n<='0'; complex_value <= (complex_width-1 => '1', (complex_width/2)-1 => '1', others => '0'); wait for 95 ns; reset_n<='1'; enable <= '1'; for i in 0 to num_cicli-1 loop --sommo in esadecimale 0x00010001 ad ogni iterazione al valore di cui calcolo il valore assoluto complex_value <= complex_value + 65537; complex_value_variable := complex_value_variable + 1; valore_assoluto := std_logic_vector(to_signed(complex_value_variable * complex_value_variable * 2, 32)); wait until done = '1'; assert(valore_assoluto = abs_value) report "Test Fallito valore assoluto trovato errato!"; wait for clock_period; end loop; wait; end process; end Behavioral;
library ieee; library work; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity pwr_sequencer_tb is generic ( LEVELS_N : natural := 3; TEST_D : natural := 10000 ); end entity; architecture rtl of pwr_sequencer_tb is -- Main clock frequency 100 MHz constant CLK_PERIOD : time := 1 sec / 10e7; signal clk : std_logic := '0'; signal reset : std_logic; signal main_pwr_en : std_logic; signal main_pwr_fail : std_logic; signal start : std_logic; signal fail : std_logic_vector(LEVELS_N - 1 downto 0); signal enable : std_logic_vector(LEVELS_N - 1 downto 0); begin reset <= '1', '0' after 500 ns; clk_gen: process(clk) begin clk <= not clk after CLK_PERIOD / 2; end process; DUT_inst: entity work.pwr_sequencer(rtl) generic map ( LEVELS_N => LEVELS_N ) port map ( clk => clk, reset => reset, start_in => start, fail_in => fail, en_out => enable, main_pwr_en_out => main_pwr_en, main_pwr_fail_out => main_pwr_fail ); fail_gen: process(clk, reset) type state_t is (idle, delay, power_on, cause_fail); variable state : state_t; variable timer : natural; variable cur_level : natural; begin if reset = '1' then state := idle; timer := 0; fail <= (others => '1'); cur_level := 0; start <= '0'; elsif rising_edge(clk) then if state = idle then start <= '1'; for i in 0 to enable'high loop if enable(i) = '1' then cur_level := i; state := delay; end if; end loop; elsif state = delay then timer := timer + 1; if timer > TEST_D then fail(cur_level) <= '0'; timer := 0; if cur_level = enable'high then state := power_on; else state := idle; end if; end if; elsif state = power_on then timer := timer + 1; -- After succesfull sequencing cause a failure if timer > TEST_D then fail(0) <= '1'; timer := 0; state := cause_fail; end if; elsif state = cause_fail then timer := timer + 1; start <= '0'; -- After succesfull power failure, restart if timer > TEST_D then start <= '1'; fail <= (others => '1'); timer := 0; state := idle; end if; end if; end if; end process; end;
library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity dacad5668Device_v1_0 is generic ( -- Users to add parameters here base_clk : INTEGER := 125000000; sclk_frequency : INTEGER := 8000000; unique_id : STD_LOGIC_VECTOR(31 DOWNTO 0) := (OTHERS => '0'); internal_reference : STD_LOGIC := '1'; -- User parameters ends -- Do not modify the parameters beyond this line -- Parameters of Axi Slave Bus Interface S00_AXI C_S00_AXI_ID_WIDTH : integer := 1; C_S00_AXI_DATA_WIDTH : integer := 32; C_S00_AXI_ADDR_WIDTH : integer := 12 ); port ( -- Users to add ports here osl_LDAC_n : OUT STD_LOGIC; osl_CLR_n : OUT STD_LOGIC; osl_sclk : OUT STD_LOGIC; osl_ss : OUT STD_LOGIC; osl_mosi : OUT STD_LOGIC; -- User ports ends -- Do not modify the ports beyond this line -- Ports of Axi Slave Bus Interface S00_AXI s00_axi_aclk : in std_logic; s00_axi_aresetn : in std_logic; s00_axi_awid : in std_logic_vector(C_S00_AXI_ID_WIDTH-1 downto 0); s00_axi_awaddr : in std_logic_vector(C_S00_AXI_ADDR_WIDTH-1 downto 0); s00_axi_awlen : in std_logic_vector(7 downto 0); s00_axi_awsize : in std_logic_vector(2 downto 0); s00_axi_awburst : in std_logic_vector(1 downto 0); s00_axi_awvalid : in std_logic; s00_axi_awready : out std_logic; s00_axi_wdata : in std_logic_vector(C_S00_AXI_DATA_WIDTH-1 downto 0); s00_axi_wstrb : in std_logic_vector((C_S00_AXI_DATA_WIDTH/8)-1 downto 0); s00_axi_wlast : in std_logic; s00_axi_wvalid : in std_logic; s00_axi_wready : out std_logic; s00_axi_bid : out std_logic_vector(C_S00_AXI_ID_WIDTH-1 downto 0); s00_axi_bresp : out std_logic_vector(1 downto 0); s00_axi_bvalid : out std_logic; s00_axi_bready : in std_logic; s00_axi_arid : in std_logic_vector(C_S00_AXI_ID_WIDTH-1 downto 0); s00_axi_araddr : in std_logic_vector(C_S00_AXI_ADDR_WIDTH-1 downto 0); s00_axi_arlen : in std_logic_vector(7 downto 0); s00_axi_arsize : in std_logic_vector(2 downto 0); s00_axi_arburst : in std_logic_vector(1 downto 0); s00_axi_arvalid : in std_logic; s00_axi_arready : out std_logic; s00_axi_rid : out std_logic_vector(C_S00_AXI_ID_WIDTH-1 downto 0); s00_axi_rdata : out std_logic_vector(C_S00_AXI_DATA_WIDTH-1 downto 0); s00_axi_rresp : out std_logic_vector(1 downto 0); s00_axi_rlast : out std_logic; s00_axi_rvalid : out std_logic; s00_axi_rready : in std_logic ); end dacad5668Device_v1_0; architecture arch_imp of dacad5668Device_v1_0 is -- component declaration component dacad5668Device_v1_0_S00_AXI is generic ( base_clk : INTEGER := 125000000; sclk_frequency : INTEGER := 8000000; unique_id : STD_LOGIC_VECTOR(31 DOWNTO 0) := (OTHERS => '0'); internal_reference : STD_LOGIC := '1'; C_S_AXI_ID_WIDTH : integer := 1; C_S_AXI_DATA_WIDTH : integer := 32; C_S_AXI_ADDR_WIDTH : integer := 12 ); port ( osl_LDAC_n : OUT STD_LOGIC; osl_CLR_n : OUT STD_LOGIC; osl_sclk : OUT STD_LOGIC; osl_ss : OUT STD_LOGIC; osl_mosi : OUT STD_LOGIC; S_AXI_ACLK : in std_logic; S_AXI_ARESETN : in std_logic; S_AXI_AWID : in std_logic_vector(C_S_AXI_ID_WIDTH-1 downto 0); S_AXI_AWADDR : in std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0); S_AXI_AWLEN : in std_logic_vector(7 downto 0); S_AXI_AWSIZE : in std_logic_vector(2 downto 0); S_AXI_AWBURST : in std_logic_vector(1 downto 0); S_AXI_AWVALID : in std_logic; S_AXI_AWREADY : out std_logic; S_AXI_WDATA : in std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0); S_AXI_WSTRB : in std_logic_vector((C_S_AXI_DATA_WIDTH/8)-1 downto 0); S_AXI_WLAST : in std_logic; S_AXI_WVALID : in std_logic; S_AXI_WREADY : out std_logic; S_AXI_BID : out std_logic_vector(C_S_AXI_ID_WIDTH-1 downto 0); S_AXI_BRESP : out std_logic_vector(1 downto 0); S_AXI_BVALID : out std_logic; S_AXI_BREADY : in std_logic; S_AXI_ARID : in std_logic_vector(C_S_AXI_ID_WIDTH-1 downto 0); S_AXI_ARADDR : in std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0); S_AXI_ARLEN : in std_logic_vector(7 downto 0); S_AXI_ARSIZE : in std_logic_vector(2 downto 0); S_AXI_ARBURST : in std_logic_vector(1 downto 0); S_AXI_ARVALID : in std_logic; S_AXI_ARREADY : out std_logic; S_AXI_RID : out std_logic_vector(C_S_AXI_ID_WIDTH-1 downto 0); S_AXI_RDATA : out std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0); S_AXI_RRESP : out std_logic_vector(1 downto 0); S_AXI_RLAST : out std_logic; S_AXI_RVALID : out std_logic; S_AXI_RREADY : in std_logic ); end component dacad5668Device_v1_0_S00_AXI; begin -- Instantiation of Axi Bus Interface S00_AXI dacad5668Device_v1_0_S00_AXI_inst : dacad5668Device_v1_0_S00_AXI generic map ( base_clk => base_clk, sclk_frequency => sclk_frequency, unique_id => unique_id, internal_reference => internal_reference, C_S_AXI_ID_WIDTH => C_S00_AXI_ID_WIDTH, C_S_AXI_DATA_WIDTH => C_S00_AXI_DATA_WIDTH, C_S_AXI_ADDR_WIDTH => C_S00_AXI_ADDR_WIDTH ) port map ( osl_LDAC_n => osl_LDAC_n, osl_CLR_n => osl_CLR_n, osl_sclk => osl_sclk, osl_ss => osl_ss, osl_mosi => osl_mosi, S_AXI_ACLK => s00_axi_aclk, S_AXI_ARESETN => s00_axi_aresetn, S_AXI_AWID => s00_axi_awid, S_AXI_AWADDR => s00_axi_awaddr, S_AXI_AWLEN => s00_axi_awlen, S_AXI_AWSIZE => s00_axi_awsize, S_AXI_AWBURST => s00_axi_awburst, S_AXI_AWVALID => s00_axi_awvalid, S_AXI_AWREADY => s00_axi_awready, S_AXI_WDATA => s00_axi_wdata, S_AXI_WSTRB => s00_axi_wstrb, S_AXI_WLAST => s00_axi_wlast, S_AXI_WVALID => s00_axi_wvalid, S_AXI_WREADY => s00_axi_wready, S_AXI_BID => s00_axi_bid, S_AXI_BRESP => s00_axi_bresp, S_AXI_BVALID => s00_axi_bvalid, S_AXI_BREADY => s00_axi_bready, S_AXI_ARID => s00_axi_arid, S_AXI_ARADDR => s00_axi_araddr, S_AXI_ARLEN => s00_axi_arlen, S_AXI_ARSIZE => s00_axi_arsize, S_AXI_ARBURST => s00_axi_arburst, S_AXI_ARVALID => s00_axi_arvalid, S_AXI_ARREADY => s00_axi_arready, S_AXI_RID => s00_axi_rid, S_AXI_RDATA => s00_axi_rdata, S_AXI_RRESP => s00_axi_rresp, S_AXI_RLAST => s00_axi_rlast, S_AXI_RVALID => s00_axi_rvalid, S_AXI_RREADY => s00_axi_rready ); -- Add user logic here -- User logic ends end arch_imp;
-- (c) Copyright 1995-2016 Xilinx, Inc. All rights reserved. -- -- This file contains confidential and proprietary information -- of Xilinx, Inc. and is protected under U.S. and -- international copyright and other intellectual property -- laws. -- -- DISCLAIMER -- This disclaimer is not a license and does not grant any -- rights to the materials distributed herewith. Except as -- otherwise provided in a valid license issued to you by -- Xilinx, and to the maximum extent permitted by applicable -- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND -- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES -- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING -- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- -- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and -- (2) Xilinx shall not be liable (whether in contract or tort, -- including negligence, or under any other theory of -- liability) for any loss or damage of any kind or nature -- related to, arising under or in connection with these -- materials, including for any direct, or any indirect, -- special, incidental, or consequential loss or damage -- (including loss of data, profits, goodwill, or any type of -- loss or damage suffered as a result of any action brought -- by a third party) even if such damage or loss was -- reasonably foreseeable or Xilinx had been advised of the -- possibility of the same. -- -- CRITICAL APPLICATIONS -- Xilinx products are not designed or intended to be fail- -- safe, or for use in any application requiring fail-safe -- performance, such as life-support or safety devices or -- systems, Class III medical devices, nuclear facilities, -- applications related to the deployment of airbags, or any -- other applications that could lead to death, personal -- injury, or severe property or environmental damage -- (individually and collectively, "Critical -- Applications"). Customer assumes the sole risk and -- liability of any use of Xilinx products in Critical -- Applications, subject only to applicable laws and -- regulations governing limitations on product liability. -- -- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS -- PART OF THIS FILE AT ALL TIMES. -- -- DO NOT MODIFY THIS FILE. -- IP VLNV: xilinx.com:ip:dist_mem_gen:8.0 -- IP Revision: 9 LIBRARY ieee; USE ieee.std_logic_1164.ALL; USE ieee.numeric_std.ALL; LIBRARY dist_mem_gen_v8_0_9; USE dist_mem_gen_v8_0_9.dist_mem_gen_v8_0_9; ENTITY dist_mem_gen_0 IS PORT ( a : IN STD_LOGIC_VECTOR(11 DOWNTO 0); spo : OUT STD_LOGIC_VECTOR(1023 DOWNTO 0) ); END dist_mem_gen_0; ARCHITECTURE dist_mem_gen_0_arch OF dist_mem_gen_0 IS ATTRIBUTE DowngradeIPIdentifiedWarnings : string; ATTRIBUTE DowngradeIPIdentifiedWarnings OF dist_mem_gen_0_arch: ARCHITECTURE IS "yes"; COMPONENT dist_mem_gen_v8_0_9 IS GENERIC ( C_FAMILY : STRING; C_ADDR_WIDTH : INTEGER; C_DEFAULT_DATA : STRING; C_DEPTH : INTEGER; C_HAS_CLK : INTEGER; C_HAS_D : INTEGER; C_HAS_DPO : INTEGER; C_HAS_DPRA : INTEGER; C_HAS_I_CE : INTEGER; C_HAS_QDPO : INTEGER; C_HAS_QDPO_CE : INTEGER; C_HAS_QDPO_CLK : INTEGER; C_HAS_QDPO_RST : INTEGER; C_HAS_QDPO_SRST : INTEGER; C_HAS_QSPO : INTEGER; C_HAS_QSPO_CE : INTEGER; C_HAS_QSPO_RST : INTEGER; C_HAS_QSPO_SRST : INTEGER; C_HAS_SPO : INTEGER; C_HAS_WE : INTEGER; C_MEM_INIT_FILE : STRING; C_ELABORATION_DIR : STRING; C_MEM_TYPE : INTEGER; C_PIPELINE_STAGES : INTEGER; C_QCE_JOINED : INTEGER; C_QUALIFY_WE : INTEGER; C_READ_MIF : INTEGER; C_REG_A_D_INPUTS : INTEGER; C_REG_DPRA_INPUT : INTEGER; C_SYNC_ENABLE : INTEGER; C_WIDTH : INTEGER; C_PARSER_TYPE : INTEGER ); PORT ( a : IN STD_LOGIC_VECTOR(11 DOWNTO 0); d : IN STD_LOGIC_VECTOR(1023 DOWNTO 0); dpra : IN STD_LOGIC_VECTOR(11 DOWNTO 0); clk : IN STD_LOGIC; we : IN STD_LOGIC; i_ce : IN STD_LOGIC; qspo_ce : IN STD_LOGIC; qdpo_ce : IN STD_LOGIC; qdpo_clk : IN STD_LOGIC; qspo_rst : IN STD_LOGIC; qdpo_rst : IN STD_LOGIC; qspo_srst : IN STD_LOGIC; qdpo_srst : IN STD_LOGIC; spo : OUT STD_LOGIC_VECTOR(1023 DOWNTO 0); dpo : OUT STD_LOGIC_VECTOR(1023 DOWNTO 0); qspo : OUT STD_LOGIC_VECTOR(1023 DOWNTO 0); qdpo : OUT STD_LOGIC_VECTOR(1023 DOWNTO 0) ); END COMPONENT dist_mem_gen_v8_0_9; ATTRIBUTE X_CORE_INFO : STRING; ATTRIBUTE X_CORE_INFO OF dist_mem_gen_0_arch: ARCHITECTURE IS "dist_mem_gen_v8_0_9,Vivado 2015.4"; ATTRIBUTE CHECK_LICENSE_TYPE : STRING; ATTRIBUTE CHECK_LICENSE_TYPE OF dist_mem_gen_0_arch : ARCHITECTURE IS "dist_mem_gen_0,dist_mem_gen_v8_0_9,{}"; ATTRIBUTE CORE_GENERATION_INFO : STRING; ATTRIBUTE CORE_GENERATION_INFO OF dist_mem_gen_0_arch: ARCHITECTURE IS "dist_mem_gen_0,dist_mem_gen_v8_0_9,{x_ipProduct=Vivado 2015.4,x_ipVendor=xilinx.com,x_ipLibrary=ip,x_ipName=dist_mem_gen,x_ipVersion=8.0,x_ipCoreRevision=9,x_ipLanguage=VHDL,x_ipSimLanguage=MIXED,C_FAMILY=artix7,C_ADDR_WIDTH=12,C_DEFAULT_DATA=0,C_DEPTH=4096,C_HAS_CLK=0,C_HAS_D=0,C_HAS_DPO=0,C_HAS_DPRA=0,C_HAS_I_CE=0,C_HAS_QDPO=0,C_HAS_QDPO_CE=0,C_HAS_QDPO_CLK=0,C_HAS_QDPO_RST=0,C_HAS_QDPO_SRST=0,C_HAS_QSPO=0,C_HAS_QSPO_CE=0,C_HAS_QSPO_RST=0,C_HAS_QSPO_SRST=0,C_HAS_SPO=1,C_HAS_WE=0,C_MEM_INIT_FILE=dist_mem_gen_0.mif,C_ELABORATION_DIR=./,C_MEM_TYPE=0,C_PIPELINE_STAGES=0,C_QCE_JOINED=0,C_QUALIFY_WE=0,C_READ_MIF=1,C_REG_A_D_INPUTS=0,C_REG_DPRA_INPUT=0,C_SYNC_ENABLE=1,C_WIDTH=1024,C_PARSER_TYPE=1}"; BEGIN U0 : dist_mem_gen_v8_0_9 GENERIC MAP ( C_FAMILY => "artix7", C_ADDR_WIDTH => 12, C_DEFAULT_DATA => "0", C_DEPTH => 4096, C_HAS_CLK => 0, C_HAS_D => 0, C_HAS_DPO => 0, C_HAS_DPRA => 0, C_HAS_I_CE => 0, C_HAS_QDPO => 0, C_HAS_QDPO_CE => 0, C_HAS_QDPO_CLK => 0, C_HAS_QDPO_RST => 0, C_HAS_QDPO_SRST => 0, C_HAS_QSPO => 0, C_HAS_QSPO_CE => 0, C_HAS_QSPO_RST => 0, C_HAS_QSPO_SRST => 0, C_HAS_SPO => 1, C_HAS_WE => 0, C_MEM_INIT_FILE => "dist_mem_gen_0.mif", C_ELABORATION_DIR => "./", C_MEM_TYPE => 0, C_PIPELINE_STAGES => 0, C_QCE_JOINED => 0, C_QUALIFY_WE => 0, C_READ_MIF => 1, C_REG_A_D_INPUTS => 0, C_REG_DPRA_INPUT => 0, C_SYNC_ENABLE => 1, C_WIDTH => 1024, C_PARSER_TYPE => 1 ) PORT MAP ( a => a, d => STD_LOGIC_VECTOR(TO_UNSIGNED(0, 1024)), dpra => STD_LOGIC_VECTOR(TO_UNSIGNED(0, 12)), clk => '0', we => '0', i_ce => '1', qspo_ce => '1', qdpo_ce => '1', qdpo_clk => '0', qspo_rst => '0', qdpo_rst => '0', qspo_srst => '0', qdpo_srst => '0', spo => spo ); END dist_mem_gen_0_arch;
-- ************************************************************************* -- -- (c) Copyright 2010-2011 Xilinx, Inc. All rights reserved. -- -- This file contains confidential and proprietary information -- of Xilinx, Inc. and is protected under U.S. and -- international copyright and other intellectual property -- laws. -- -- DISCLAIMER -- This disclaimer is not a license and does not grant any -- rights to the materials distributed herewith. Except as -- otherwise provided in a valid license issued to you by -- Xilinx, and to the maximum extent permitted by applicable -- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND -- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES -- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING -- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- -- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and -- (2) Xilinx shall not be liable (whether in contract or tort, -- including negligence, or under any other theory of -- liability) for any loss or damage of any kind or nature -- related to, arising under or in connection with these -- materials, including for any direct, or any indirect, -- special, incidental, or consequential loss or damage -- (including loss of data, profits, goodwill, or any type of -- loss or damage suffered as a result of any action brought -- by a third party) even if such damage or loss was -- reasonably foreseeable or Xilinx had been advised of the -- possibility of the same. -- -- CRITICAL APPLICATIONS -- Xilinx products are not designed or intended to be fail- -- safe, or for use in any application requiring fail-safe -- performance, such as life-support or safety devices or -- systems, Class III medical devices, nuclear facilities, -- applications related to the deployment of airbags, or any -- other applications that could lead to death, personal -- injury, or severe property or environmental damage -- (individually and collectively, "Critical -- Applications"). Customer assumes the sole risk and -- liability of any use of Xilinx products in Critical -- Applications, subject only to applicable laws and -- regulations governing limitations on product liability. -- -- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS -- PART OF THIS FILE AT ALL TIMES. -- -- ************************************************************************* -- ------------------------------------------------------------------------------- -- Filename: axi_sg.vhd -- -- Description: -- Top level VHDL wrapper for the AXI DataMover -- -- -- -- -- VHDL-Standard: VHDL'93 ------------------------------------------------------------------------------- library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; library axi_sg_v4_1; use axi_sg_v4_1.axi_sg_mm2s_basic_wrap; use axi_sg_v4_1.axi_sg_s2mm_basic_wrap; ------------------------------------------------------------------------------- entity axi_sg_datamover is generic ( C_INCLUDE_MM2S : Integer range 0 to 2 := 2; -- Specifies the type of MM2S function to include -- 0 = Omit MM2S functionality -- 1 = Full MM2S Functionality -- 2 = Basic MM2S functionality C_M_AXI_MM2S_ARID : Integer range 0 to 255 := 0; -- Specifies the constant value to output on -- the ARID output port C_M_AXI_MM2S_ID_WIDTH : Integer range 1 to 8 := 4; -- Specifies the width of the MM2S ID port C_M_AXI_MM2S_ADDR_WIDTH : Integer range 32 to 64 := 32; -- Specifies the width of the MMap Read Address Channel -- Address bus C_M_AXI_MM2S_DATA_WIDTH : Integer range 32 to 1024 := 32; -- Specifies the width of the MMap Read Data Channel -- data bus C_M_AXIS_MM2S_TDATA_WIDTH : Integer range 8 to 1024 := 32; -- Specifies the width of the MM2S Master Stream Data -- Channel data bus C_INCLUDE_MM2S_STSFIFO : Integer range 0 to 1 := 1; -- Specifies if a Status FIFO is to be implemented -- 0 = Omit MM2S Status FIFO -- 1 = Include MM2S Status FIFO C_MM2S_STSCMD_FIFO_DEPTH : Integer range 1 to 16 := 4; -- Specifies the depth of the MM2S Command FIFO and the -- optional Status FIFO -- Valid values are 1,4,8,16 C_MM2S_STSCMD_IS_ASYNC : Integer range 0 to 1 := 0; -- Specifies if the Status and Command interfaces need to -- be asynchronous to the primary data path clocking -- 0 = Use same clocking as data path -- 1 = Use special Status/Command clock for the interfaces C_INCLUDE_MM2S_DRE : Integer range 0 to 1 := 1; -- Specifies if DRE is to be included in the MM2S function -- 0 = Omit DRE -- 1 = Include DRE C_MM2S_BURST_SIZE : Integer range 16 to 256 := 16; -- Specifies the max number of databeats to use for MMap -- burst transfers by the MM2S function C_MM2S_BTT_USED : Integer range 8 to 23 := 16; -- Specifies the number of bits used from the BTT field -- of the input Command Word of the MM2S Command Interface C_MM2S_ADDR_PIPE_DEPTH : Integer range 1 to 30 := 3; -- This parameter specifies the depth of the MM2S internal -- child command queues in the Read Address Controller and -- the Read Data Controller. Increasing this value will -- allow more Read Addresses to be issued to the AXI4 Read -- Address Channel before receipt of the associated read -- data on the Read Data Channel. C_MM2S_INCLUDE_SF : Integer range 0 to 1 := 1 ; -- This parameter specifies the inclusion/omission of the -- MM2S (Read) Store and Forward function -- 0 = Omit MM2S Store and Forward -- 1 = Include MM2S Store and Forward C_INCLUDE_S2MM : Integer range 0 to 4 := 2; -- Specifies the type of S2MM function to include -- 0 = Omit S2MM functionality -- 1 = Full S2MM Functionality -- 2 = Basic S2MM functionality C_M_AXI_S2MM_AWID : Integer range 0 to 255 := 1; -- Specifies the constant value to output on -- the ARID output port C_M_AXI_S2MM_ID_WIDTH : Integer range 1 to 8 := 4; -- Specifies the width of the S2MM ID port C_M_AXI_S2MM_ADDR_WIDTH : Integer range 32 to 64 := 32; -- Specifies the width of the MMap Read Address Channel -- Address bus C_M_AXI_S2MM_DATA_WIDTH : Integer range 32 to 1024 := 32; -- Specifies the width of the MMap Read Data Channel -- data bus C_S_AXIS_S2MM_TDATA_WIDTH : Integer range 8 to 1024 := 32; -- Specifies the width of the S2MM Master Stream Data -- Channel data bus C_INCLUDE_S2MM_STSFIFO : Integer range 0 to 1 := 1; -- Specifies if a Status FIFO is to be implemented -- 0 = Omit S2MM Status FIFO -- 1 = Include S2MM Status FIFO C_S2MM_STSCMD_FIFO_DEPTH : Integer range 1 to 16 := 4; -- Specifies the depth of the S2MM Command FIFO and the -- optional Status FIFO -- Valid values are 1,4,8,16 C_S2MM_STSCMD_IS_ASYNC : Integer range 0 to 1 := 0; -- Specifies if the Status and Command interfaces need to -- be asynchronous to the primary data path clocking -- 0 = Use same clocking as data path -- 1 = Use special Status/Command clock for the interfaces C_INCLUDE_S2MM_DRE : Integer range 0 to 1 := 1; -- Specifies if DRE is to be included in the S2MM function -- 0 = Omit DRE -- 1 = Include DRE C_S2MM_BURST_SIZE : Integer range 16 to 256 := 16; -- Specifies the max number of databeats to use for MMap -- burst transfers by the S2MM function C_S2MM_BTT_USED : Integer range 8 to 23 := 16; -- Specifies the number of bits used from the BTT field -- of the input Command Word of the S2MM Command Interface C_S2MM_SUPPORT_INDET_BTT : Integer range 0 to 1 := 0; -- Specifies if support for indeterminate packet lengths -- are to be received on the input Stream interface -- 0 = Omit support (User MUST transfer the exact number of -- bytes on the Stream interface as specified in the BTT -- field of the Corresponding DataMover Command) -- 1 = Include support for indeterminate packet lengths -- This causes FIFOs to be added and "Store and Forward" -- behavior of the S2MM function C_S2MM_ADDR_PIPE_DEPTH : Integer range 1 to 30 := 3; -- This parameter specifies the depth of the S2MM internal -- address pipeline queues in the Write Address Controller -- and the Write Data Controller. Increasing this value will -- allow more Write Addresses to be issued to the AXI4 Write -- Address Channel before transmission of the associated -- write data on the Write Data Channel. C_S2MM_INCLUDE_SF : Integer range 0 to 1 := 1 ; -- This parameter specifies the inclusion/omission of the -- S2MM (Write) Store and Forward function -- 0 = Omit S2MM Store and Forward -- 1 = Include S2MM Store and Forward C_ENABLE_MULTI_CHANNEL : integer range 0 to 1 := 1; C_ENABLE_EXTRA_FIELD : integer range 0 to 1 := 0; C_FAMILY : String := "virtex7" -- Specifies the target FPGA family type ); port ( -- MM2S Primary Clock input ---------------------------------- m_axi_mm2s_aclk : in std_logic; -- -- Primary synchronization clock for the Master side -- -- interface and internal logic. It is also used -- -- for the User interface synchronization when -- -- C_STSCMD_IS_ASYNC = 0. -- -- -- MM2S Primary Reset input -- m_axi_mm2s_aresetn : in std_logic; -- -- Reset used for the internal master logic -- -------------------------------------------------------------- sg_ctl : in std_logic_vector (7 downto 0) ; -- MM2S Halt request input control -------------------- mm2s_halt : in std_logic; -- -- Active high soft shutdown request -- -- -- MM2S Halt Complete status flag -- mm2s_halt_cmplt : Out std_logic; -- -- Active high soft shutdown complete status -- ------------------------------------------------------- -- Error discrete output ------------------------- mm2s_err : Out std_logic; -- -- Composite Error indication -- -------------------------------------------------- -- Memory Map to Stream Command FIFO and Status FIFO I/O --------- m_axis_mm2s_cmdsts_aclk : in std_logic; -- -- Secondary Clock input for async CMD/Status interface -- -- m_axis_mm2s_cmdsts_aresetn : in std_logic; -- -- Secondary Reset input for async CMD/Status interface -- ------------------------------------------------------------------ -- User Command Interface Ports (AXI Stream) ------------------------------------------------- s_axis_mm2s_cmd_tvalid : in std_logic; -- s_axis_mm2s_cmd_tready : out std_logic; -- s_axis_mm2s_cmd_tdata : in std_logic_vector(((1+C_ENABLE_MULTI_CHANNEL)*C_M_AXI_MM2S_ADDR_WIDTH+40)-1 downto 0); -- ---------------------------------------------------------------------------------------------- -- User Status Interface Ports (AXI Stream) ------------------------ m_axis_mm2s_sts_tvalid : out std_logic; -- m_axis_mm2s_sts_tready : in std_logic; -- m_axis_mm2s_sts_tdata : out std_logic_vector(7 downto 0); -- m_axis_mm2s_sts_tkeep : out std_logic_vector(0 downto 0); -- m_axis_mm2s_sts_tlast : out std_logic; -- -------------------------------------------------------------------- -- Address Posting contols ----------------------- mm2s_allow_addr_req : in std_logic; -- mm2s_addr_req_posted : out std_logic; -- mm2s_rd_xfer_cmplt : out std_logic; -- -------------------------------------------------- -- MM2S AXI Address Channel I/O -------------------------------------------------- m_axi_mm2s_arid : out std_logic_vector(C_M_AXI_MM2S_ID_WIDTH-1 downto 0); -- -- AXI Address Channel ID output -- -- m_axi_mm2s_araddr : out std_logic_vector(C_M_AXI_MM2S_ADDR_WIDTH-1 downto 0); -- -- AXI Address Channel Address output -- -- m_axi_mm2s_arlen : out std_logic_vector(7 downto 0); -- -- AXI Address Channel LEN output -- -- Sized to support 256 data beat bursts -- -- m_axi_mm2s_arsize : out std_logic_vector(2 downto 0); -- -- AXI Address Channel SIZE output -- -- m_axi_mm2s_arburst : out std_logic_vector(1 downto 0); -- -- AXI Address Channel BURST output -- -- m_axi_mm2s_arprot : out std_logic_vector(2 downto 0); -- -- AXI Address Channel PROT output -- -- m_axi_mm2s_arcache : out std_logic_vector(3 downto 0); -- -- AXI Address Channel CACHE output -- m_axi_mm2s_aruser : out std_logic_vector(3 downto 0); -- -- AXI Address Channel USER output -- -- m_axi_mm2s_arvalid : out std_logic; -- -- AXI Address Channel VALID output -- -- m_axi_mm2s_arready : in std_logic; -- -- AXI Address Channel READY input -- ----------------------------------------------------------------------------------- -- Currently unsupported AXI Address Channel output signals ------- -- m_axi_mm2s_alock : out std_logic_vector(2 downto 0); -- -- m_axi_mm2s_acache : out std_logic_vector(4 downto 0); -- -- m_axi_mm2s_aqos : out std_logic_vector(3 downto 0); -- -- m_axi_mm2s_aregion : out std_logic_vector(3 downto 0); -- ------------------------------------------------------------------- -- MM2S AXI MMap Read Data Channel I/O ------------------------------------------------ m_axi_mm2s_rdata : In std_logic_vector(C_M_AXI_MM2S_DATA_WIDTH-1 downto 0); -- m_axi_mm2s_rresp : In std_logic_vector(1 downto 0); -- m_axi_mm2s_rlast : In std_logic; -- m_axi_mm2s_rvalid : In std_logic; -- m_axi_mm2s_rready : Out std_logic; -- ---------------------------------------------------------------------------------------- -- MM2S AXI Master Stream Channel I/O ------------------------------------------------------- m_axis_mm2s_tdata : Out std_logic_vector(C_M_AXIS_MM2S_TDATA_WIDTH-1 downto 0); -- m_axis_mm2s_tkeep : Out std_logic_vector((C_M_AXIS_MM2S_TDATA_WIDTH/8)-1 downto 0); -- m_axis_mm2s_tlast : Out std_logic; -- m_axis_mm2s_tvalid : Out std_logic; -- m_axis_mm2s_tready : In std_logic; -- ---------------------------------------------------------------------------------------------- -- Testing Support I/O -------------------------------------------------------- mm2s_dbg_sel : in std_logic_vector( 3 downto 0); -- mm2s_dbg_data : out std_logic_vector(31 downto 0) ; -- ------------------------------------------------------------------------------- -- S2MM Primary Clock input --------------------------------- m_axi_s2mm_aclk : in std_logic; -- -- Primary synchronization clock for the Master side -- -- interface and internal logic. It is also used -- -- for the User interface synchronization when -- -- C_STSCMD_IS_ASYNC = 0. -- -- -- S2MM Primary Reset input -- m_axi_s2mm_aresetn : in std_logic; -- -- Reset used for the internal master logic -- ------------------------------------------------------------- -- S2MM Halt request input control ------------------ s2mm_halt : in std_logic; -- -- Active high soft shutdown request -- -- -- S2MM Halt Complete status flag -- s2mm_halt_cmplt : out std_logic; -- -- Active high soft shutdown complete status -- ----------------------------------------------------- -- S2MM Error discrete output ------------------ s2mm_err : Out std_logic; -- -- Composite Error indication -- ------------------------------------------------ -- Memory Map to Stream Command FIFO and Status FIFO I/O ----------------- m_axis_s2mm_cmdsts_awclk : in std_logic; -- -- Secondary Clock input for async CMD/Status interface -- -- m_axis_s2mm_cmdsts_aresetn : in std_logic; -- -- Secondary Reset input for async CMD/Status interface -- -------------------------------------------------------------------------- -- User Command Interface Ports (AXI Stream) -------------------------------------------------- s_axis_s2mm_cmd_tvalid : in std_logic; -- s_axis_s2mm_cmd_tready : out std_logic; -- s_axis_s2mm_cmd_tdata : in std_logic_vector(((1+C_ENABLE_MULTI_CHANNEL)*C_M_AXI_S2MM_ADDR_WIDTH+40)-1 downto 0); -- ----------------------------------------------------------------------------------------------- -- User Status Interface Ports (AXI Stream) ----------------------------------------------------------- m_axis_s2mm_sts_tvalid : out std_logic; -- m_axis_s2mm_sts_tready : in std_logic; -- m_axis_s2mm_sts_tdata : out std_logic_vector(((C_S2MM_SUPPORT_INDET_BTT*24)+8)-1 downto 0); -- m_axis_s2mm_sts_tkeep : out std_logic_vector((((C_S2MM_SUPPORT_INDET_BTT*24)+8)/8)-1 downto 0); -- m_axis_s2mm_sts_tlast : out std_logic; -- ------------------------------------------------------------------------------------------------------- -- Address posting controls ----------------------------------------- s2mm_allow_addr_req : in std_logic; -- s2mm_addr_req_posted : out std_logic; -- s2mm_wr_xfer_cmplt : out std_logic; -- s2mm_ld_nxt_len : out std_logic; -- s2mm_wr_len : out std_logic_vector(7 downto 0); -- --------------------------------------------------------------------- -- S2MM AXI Address Channel I/O ---------------------------------------------------- m_axi_s2mm_awid : out std_logic_vector(C_M_AXI_S2MM_ID_WIDTH-1 downto 0); -- -- AXI Address Channel ID output -- -- m_axi_s2mm_awaddr : out std_logic_vector(C_M_AXI_S2MM_ADDR_WIDTH-1 downto 0); -- -- AXI Address Channel Address output -- -- m_axi_s2mm_awlen : out std_logic_vector(7 downto 0); -- -- AXI Address Channel LEN output -- -- Sized to support 256 data beat bursts -- -- m_axi_s2mm_awsize : out std_logic_vector(2 downto 0); -- -- AXI Address Channel SIZE output -- -- m_axi_s2mm_awburst : out std_logic_vector(1 downto 0); -- -- AXI Address Channel BURST output -- -- m_axi_s2mm_awprot : out std_logic_vector(2 downto 0); -- -- AXI Address Channel PROT output -- -- m_axi_s2mm_awcache : out std_logic_vector(3 downto 0); -- -- AXI Address Channel CACHE output -- m_axi_s2mm_awuser : out std_logic_vector(3 downto 0); -- -- AXI Address Channel USER output -- -- m_axi_s2mm_awvalid : out std_logic; -- -- AXI Address Channel VALID output -- -- m_axi_s2mm_awready : in std_logic; -- -- AXI Address Channel READY input -- ------------------------------------------------------------------------------------- -- Currently unsupported AXI Address Channel output signals ------- -- m_axi_s2mm__awlock : out std_logic_vector(2 downto 0); -- -- m_axi_s2mm__awcache : out std_logic_vector(4 downto 0); -- -- m_axi_s2mm__awqos : out std_logic_vector(3 downto 0); -- -- m_axi_s2mm__awregion : out std_logic_vector(3 downto 0); -- ------------------------------------------------------------------- -- S2MM AXI MMap Write Data Channel I/O -------------------------------------------------- m_axi_s2mm_wdata : Out std_logic_vector(C_M_AXI_S2MM_DATA_WIDTH-1 downto 0); -- m_axi_s2mm_wstrb : Out std_logic_vector((C_M_AXI_S2MM_DATA_WIDTH/8)-1 downto 0); -- m_axi_s2mm_wlast : Out std_logic; -- m_axi_s2mm_wvalid : Out std_logic; -- m_axi_s2mm_wready : In std_logic; -- ------------------------------------------------------------------------------------------- -- S2MM AXI MMap Write response Channel I/O ------------------------- m_axi_s2mm_bresp : In std_logic_vector(1 downto 0); -- m_axi_s2mm_bvalid : In std_logic; -- m_axi_s2mm_bready : Out std_logic; -- ---------------------------------------------------------------------- -- S2MM AXI Slave Stream Channel I/O ------------------------------------------------------- s_axis_s2mm_tdata : In std_logic_vector(C_S_AXIS_S2MM_TDATA_WIDTH-1 downto 0); -- s_axis_s2mm_tkeep : In std_logic_vector((C_S_AXIS_S2MM_TDATA_WIDTH/8)-1 downto 0); -- s_axis_s2mm_tlast : In std_logic; -- s_axis_s2mm_tvalid : In std_logic; -- s_axis_s2mm_tready : Out std_logic; -- --------------------------------------------------------------------------------------------- -- Testing Support I/O ------------------------------------------------ s2mm_dbg_sel : in std_logic_vector( 3 downto 0); -- s2mm_dbg_data : out std_logic_vector(31 downto 0) -- ------------------------------------------------------------------------ ); end entity axi_sg_datamover; architecture implementation of axi_sg_datamover is attribute DowngradeIPIdentifiedWarnings: string; attribute DowngradeIPIdentifiedWarnings of implementation : architecture is "yes"; -- Function Declarations ------------------------------------------------------------------- -- Function -- -- Function Name: funct_clip_brst_len -- -- Function Description: -- This function is used to limit the parameterized max burst -- databeats when the tranfer data width is 256 bits or greater. -- This is required to keep from crossing the 4K byte xfer -- boundary required by AXI. This process is further complicated -- by the inclusion/omission of upsizers or downsizers in the -- data path. -- ------------------------------------------------------------------- function funct_clip_brst_len (param_burst_beats : integer; mmap_transfer_bit_width : integer; stream_transfer_bit_width : integer; down_up_sizers_enabled : integer) return integer is constant FCONST_SIZERS_ENABLED : boolean := (down_up_sizers_enabled > 0); Variable fvar_max_burst_dbeats : Integer; begin -- coverage off if (FCONST_SIZERS_ENABLED) then -- use MMap dwidth for calc If (mmap_transfer_bit_width <= 128) Then -- allowed fvar_max_burst_dbeats := param_burst_beats; Elsif (mmap_transfer_bit_width <= 256) Then If (param_burst_beats <= 128) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 128; End if; Elsif (mmap_transfer_bit_width <= 512) Then If (param_burst_beats <= 64) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 64; End if; Else -- 1024 bit mmap width case If (param_burst_beats <= 32) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 32; End if; End if; else -- use stream dwidth for calc If (stream_transfer_bit_width <= 128) Then -- allowed fvar_max_burst_dbeats := param_burst_beats; Elsif (stream_transfer_bit_width <= 256) Then If (param_burst_beats <= 128) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 128; End if; Elsif (stream_transfer_bit_width <= 512) Then If (param_burst_beats <= 64) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 64; End if; Else -- 1024 bit stream width case If (param_burst_beats <= 32) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 32; End if; -- coverage on End if; end if; Return (fvar_max_burst_dbeats); end function funct_clip_brst_len; ------------------------------------------------------------------- -- Function -- -- Function Name: funct_fix_depth_16 -- -- Function Description: -- This function is used to fix the Command and Status FIFO depths to -- 16 entries when Async clocking mode is enabled. This is required -- due to the way the async_fifo_fg.vhd design in proc_common is -- implemented. ------------------------------------------------------------------- function funct_fix_depth_16 (async_clocking_mode : integer; requested_depth : integer) return integer is Variable fvar_depth_2_use : Integer; begin -- coverage off If (async_clocking_mode = 1) Then -- async mode so fix at 16 fvar_depth_2_use := 16; Elsif (requested_depth > 16) Then -- limit at 16 fvar_depth_2_use := 16; -- coverage on Else -- use requested depth fvar_depth_2_use := requested_depth; End if; Return (fvar_depth_2_use); end function funct_fix_depth_16; ------------------------------------------------------------------- -- Function -- -- Function Name: funct_get_min_btt_width -- -- Function Description: -- This function calculates the minimum required value -- for the used width of the command BTT field. -- ------------------------------------------------------------------- function funct_get_min_btt_width (max_burst_beats : integer; bytes_per_beat : integer ) return integer is Variable var_min_btt_needed : Integer; Variable var_max_bytes_per_burst : Integer; begin var_max_bytes_per_burst := max_burst_beats*bytes_per_beat; -- coverage off if (var_max_bytes_per_burst <= 16) then var_min_btt_needed := 5; elsif (var_max_bytes_per_burst <= 32) then var_min_btt_needed := 6; -- coverage on elsif (var_max_bytes_per_burst <= 64) then var_min_btt_needed := 7; -- coverage off elsif (var_max_bytes_per_burst <= 128) then var_min_btt_needed := 8; elsif (var_max_bytes_per_burst <= 256) then var_min_btt_needed := 9; elsif (var_max_bytes_per_burst <= 512) then var_min_btt_needed := 10; elsif (var_max_bytes_per_burst <= 1024) then var_min_btt_needed := 11; elsif (var_max_bytes_per_burst <= 2048) then var_min_btt_needed := 12; elsif (var_max_bytes_per_burst <= 4096) then var_min_btt_needed := 13; else -- 8K byte range var_min_btt_needed := 14; end if; -- coverage on Return (var_min_btt_needed); end function funct_get_min_btt_width; ------------------------------------------------------------------- -- Function -- -- Function Name: funct_get_xfer_bytes_per_dbeat -- -- Function Description: -- Calculates the nuber of bytes that will transfered per databeat -- on the AXI4 MMap Bus. -- ------------------------------------------------------------------- function funct_get_xfer_bytes_per_dbeat (mmap_transfer_bit_width : integer; stream_transfer_bit_width : integer; down_up_sizers_enabled : integer) return integer is Variable temp_bytes_per_dbeat : Integer := 4; begin -- coverage off if (down_up_sizers_enabled > 0) then -- down/up sizers are in use, use full mmap dwidth temp_bytes_per_dbeat := mmap_transfer_bit_width/8; -- coverage on else -- No down/up sizers so use Stream data width temp_bytes_per_dbeat := stream_transfer_bit_width/8; end if; Return (temp_bytes_per_dbeat); end function funct_get_xfer_bytes_per_dbeat; ------------------------------------------------------------------- -- Function -- -- Function Name: funct_fix_btt_used -- -- Function Description: -- THis function makes sure the BTT width used is at least the -- minimum needed. -- ------------------------------------------------------------------- function funct_fix_btt_used (requested_btt_width : integer; min_btt_width : integer) return integer is Variable var_corrected_btt_width : Integer; begin -- coverage off If (requested_btt_width < min_btt_width) Then var_corrected_btt_width := min_btt_width; -- coverage on else var_corrected_btt_width := requested_btt_width; End if; Return (var_corrected_btt_width); end function funct_fix_btt_used; ------------------------------------------------------------------- -- Constant Declarations ------------------------------------------------------------------- Constant MM2S_TAG_WIDTH : integer := 4; Constant S2MM_TAG_WIDTH : integer := 4; Constant MM2S_DOWNSIZER_ENABLED : integer := C_MM2S_INCLUDE_SF; Constant S2MM_UPSIZER_ENABLED : integer := C_S2MM_INCLUDE_SF + C_S2MM_SUPPORT_INDET_BTT; Constant MM2S_MAX_BURST_BEATS : integer := funct_clip_brst_len(C_MM2S_BURST_SIZE, C_M_AXI_MM2S_DATA_WIDTH, C_M_AXIS_MM2S_TDATA_WIDTH, MM2S_DOWNSIZER_ENABLED); Constant S2MM_MAX_BURST_BEATS : integer := funct_clip_brst_len(C_S2MM_BURST_SIZE, C_M_AXI_S2MM_DATA_WIDTH, C_S_AXIS_S2MM_TDATA_WIDTH, S2MM_UPSIZER_ENABLED); Constant MM2S_CMDSTS_FIFO_DEPTH : integer := funct_fix_depth_16(C_MM2S_STSCMD_IS_ASYNC, C_MM2S_STSCMD_FIFO_DEPTH); Constant S2MM_CMDSTS_FIFO_DEPTH : integer := funct_fix_depth_16(C_S2MM_STSCMD_IS_ASYNC, C_S2MM_STSCMD_FIFO_DEPTH); Constant MM2S_BYTES_PER_BEAT : integer := funct_get_xfer_bytes_per_dbeat(C_M_AXI_MM2S_DATA_WIDTH, C_M_AXIS_MM2S_TDATA_WIDTH, MM2S_DOWNSIZER_ENABLED); Constant MM2S_MIN_BTT_NEEDED : integer := funct_get_min_btt_width(MM2S_MAX_BURST_BEATS, MM2S_BYTES_PER_BEAT); Constant MM2S_CORRECTED_BTT_USED : integer := funct_fix_btt_used(C_MM2S_BTT_USED, MM2S_MIN_BTT_NEEDED); Constant S2MM_BYTES_PER_BEAT : integer := funct_get_xfer_bytes_per_dbeat(C_M_AXI_S2MM_DATA_WIDTH, C_S_AXIS_S2MM_TDATA_WIDTH, S2MM_UPSIZER_ENABLED); Constant S2MM_MIN_BTT_NEEDED : integer := funct_get_min_btt_width(S2MM_MAX_BURST_BEATS, S2MM_BYTES_PER_BEAT); Constant S2MM_CORRECTED_BTT_USED : integer := funct_fix_btt_used(C_S2MM_BTT_USED, S2MM_MIN_BTT_NEEDED); -- Signals signal sig_mm2s_tstrb : std_logic_vector((C_M_AXIS_MM2S_TDATA_WIDTH/8)-1 downto 0) := (others => '0'); signal sig_mm2s_sts_tstrb : std_logic_vector(0 downto 0) := (others => '0'); signal sig_s2mm_tstrb : std_logic_vector((C_S_AXIS_S2MM_TDATA_WIDTH/8)-1 downto 0) := (others => '0'); signal sig_s2mm_sts_tstrb : std_logic_vector((((C_S2MM_SUPPORT_INDET_BTT*24)+8)/8)-1 downto 0) := (others => '0'); begin --(architecture implementation) ------------------------------------------------------------- -- Conversion to tkeep for external stream connnections ------------------------------------------------------------- -- MM2S Stream Output m_axis_mm2s_tkeep <= sig_mm2s_tstrb ; -- MM2S Status Stream Output m_axis_mm2s_sts_tkeep <= sig_mm2s_sts_tstrb ; -- S2MM Stream Input sig_s2mm_tstrb <= s_axis_s2mm_tkeep ; -- S2MM Status Stream Output m_axis_s2mm_sts_tkeep <= sig_s2mm_sts_tstrb ; ------------------------------------------------------------ -- If Generate -- -- Label: GEN_MM2S_BASIC -- -- If Generate Description: -- Instantiate the MM2S Basic Wrapper -- -- ------------------------------------------------------------ GEN_MM2S_BASIC : if (C_INCLUDE_MM2S = 2) generate begin ------------------------------------------------------------ -- Instance: I_MM2S_BASIC_WRAPPER -- -- Description: -- Read Basic Wrapper Instance -- ------------------------------------------------------------ I_MM2S_BASIC_WRAPPER : entity axi_sg_v4_1.axi_sg_mm2s_basic_wrap generic map ( C_INCLUDE_MM2S => C_INCLUDE_MM2S , C_MM2S_ARID => C_M_AXI_MM2S_ARID , C_MM2S_ID_WIDTH => C_M_AXI_MM2S_ID_WIDTH , C_MM2S_ADDR_WIDTH => C_M_AXI_MM2S_ADDR_WIDTH , C_MM2S_MDATA_WIDTH => C_M_AXI_MM2S_DATA_WIDTH , C_MM2S_SDATA_WIDTH => C_M_AXIS_MM2S_TDATA_WIDTH , C_INCLUDE_MM2S_STSFIFO => C_INCLUDE_MM2S_STSFIFO , C_MM2S_STSCMD_FIFO_DEPTH => MM2S_CMDSTS_FIFO_DEPTH , C_MM2S_STSCMD_IS_ASYNC => C_MM2S_STSCMD_IS_ASYNC , C_INCLUDE_MM2S_DRE => C_INCLUDE_MM2S_DRE , C_MM2S_BURST_SIZE => MM2S_MAX_BURST_BEATS , C_MM2S_BTT_USED => MM2S_CORRECTED_BTT_USED , C_MM2S_ADDR_PIPE_DEPTH => C_MM2S_ADDR_PIPE_DEPTH , C_TAG_WIDTH => MM2S_TAG_WIDTH , C_ENABLE_MULTI_CHANNEL => C_ENABLE_MULTI_CHANNEL , C_ENABLE_EXTRA_FIELD => C_ENABLE_EXTRA_FIELD, C_FAMILY => C_FAMILY ) port map ( mm2s_aclk => m_axi_mm2s_aclk , mm2s_aresetn => m_axi_mm2s_aresetn , sg_ctl => sg_ctl , mm2s_halt => mm2s_halt , mm2s_halt_cmplt => mm2s_halt_cmplt , mm2s_err => mm2s_err , mm2s_cmdsts_awclk => m_axis_mm2s_cmdsts_aclk , mm2s_cmdsts_aresetn => m_axis_mm2s_cmdsts_aresetn , mm2s_cmd_wvalid => s_axis_mm2s_cmd_tvalid , mm2s_cmd_wready => s_axis_mm2s_cmd_tready , mm2s_cmd_wdata => s_axis_mm2s_cmd_tdata , mm2s_sts_wvalid => m_axis_mm2s_sts_tvalid , mm2s_sts_wready => m_axis_mm2s_sts_tready , mm2s_sts_wdata => m_axis_mm2s_sts_tdata , mm2s_sts_wstrb => sig_mm2s_sts_tstrb , mm2s_sts_wlast => m_axis_mm2s_sts_tlast , mm2s_allow_addr_req => mm2s_allow_addr_req , mm2s_addr_req_posted => mm2s_addr_req_posted , mm2s_rd_xfer_cmplt => mm2s_rd_xfer_cmplt , mm2s_arid => m_axi_mm2s_arid , mm2s_araddr => m_axi_mm2s_araddr , mm2s_arlen => m_axi_mm2s_arlen , mm2s_arsize => m_axi_mm2s_arsize , mm2s_arburst => m_axi_mm2s_arburst , mm2s_arprot => m_axi_mm2s_arprot , mm2s_arcache => m_axi_mm2s_arcache , mm2s_aruser => m_axi_mm2s_aruser , mm2s_arvalid => m_axi_mm2s_arvalid , mm2s_arready => m_axi_mm2s_arready , mm2s_rdata => m_axi_mm2s_rdata , mm2s_rresp => m_axi_mm2s_rresp , mm2s_rlast => m_axi_mm2s_rlast , mm2s_rvalid => m_axi_mm2s_rvalid , mm2s_rready => m_axi_mm2s_rready , mm2s_strm_wdata => m_axis_mm2s_tdata , mm2s_strm_wstrb => sig_mm2s_tstrb , mm2s_strm_wlast => m_axis_mm2s_tlast , mm2s_strm_wvalid => m_axis_mm2s_tvalid , mm2s_strm_wready => m_axis_mm2s_tready , mm2s_dbg_sel => mm2s_dbg_sel , mm2s_dbg_data => mm2s_dbg_data ); end generate GEN_MM2S_BASIC; ------------------------------------------------------------ -- If Generate -- -- Label: GEN_S2MM_BASIC -- -- If Generate Description: -- Instantiate the S2MM Basic Wrapper -- -- ------------------------------------------------------------ GEN_S2MM_BASIC : if (C_INCLUDE_S2MM = 2) generate begin ------------------------------------------------------------ -- Instance: I_S2MM_BASIC_WRAPPER -- -- Description: -- Write Basic Wrapper Instance -- ------------------------------------------------------------ I_S2MM_BASIC_WRAPPER : entity axi_sg_v4_1.axi_sg_s2mm_basic_wrap generic map ( C_INCLUDE_S2MM => C_INCLUDE_S2MM , C_S2MM_AWID => C_M_AXI_S2MM_AWID , C_S2MM_ID_WIDTH => C_M_AXI_S2MM_ID_WIDTH , C_S2MM_ADDR_WIDTH => C_M_AXI_S2MM_ADDR_WIDTH , C_S2MM_MDATA_WIDTH => C_M_AXI_S2MM_DATA_WIDTH , C_S2MM_SDATA_WIDTH => C_S_AXIS_S2MM_TDATA_WIDTH , C_INCLUDE_S2MM_STSFIFO => C_INCLUDE_S2MM_STSFIFO , C_S2MM_STSCMD_FIFO_DEPTH => S2MM_CMDSTS_FIFO_DEPTH , C_S2MM_STSCMD_IS_ASYNC => C_S2MM_STSCMD_IS_ASYNC , C_INCLUDE_S2MM_DRE => C_INCLUDE_S2MM_DRE , C_S2MM_BURST_SIZE => S2MM_MAX_BURST_BEATS , C_S2MM_ADDR_PIPE_DEPTH => C_S2MM_ADDR_PIPE_DEPTH , C_TAG_WIDTH => S2MM_TAG_WIDTH , C_ENABLE_MULTI_CHANNEL => C_ENABLE_MULTI_CHANNEL , C_ENABLE_EXTRA_FIELD => C_ENABLE_EXTRA_FIELD, C_FAMILY => C_FAMILY ) port map ( s2mm_aclk => m_axi_s2mm_aclk , s2mm_aresetn => m_axi_s2mm_aresetn , sg_ctl => sg_ctl , s2mm_halt => s2mm_halt , s2mm_halt_cmplt => s2mm_halt_cmplt , s2mm_err => s2mm_err , s2mm_cmdsts_awclk => m_axis_s2mm_cmdsts_awclk , s2mm_cmdsts_aresetn => m_axis_s2mm_cmdsts_aresetn , s2mm_cmd_wvalid => s_axis_s2mm_cmd_tvalid , s2mm_cmd_wready => s_axis_s2mm_cmd_tready , s2mm_cmd_wdata => s_axis_s2mm_cmd_tdata , s2mm_sts_wvalid => m_axis_s2mm_sts_tvalid , s2mm_sts_wready => m_axis_s2mm_sts_tready , s2mm_sts_wdata => m_axis_s2mm_sts_tdata , s2mm_sts_wstrb => sig_s2mm_sts_tstrb , s2mm_sts_wlast => m_axis_s2mm_sts_tlast , s2mm_allow_addr_req => s2mm_allow_addr_req , s2mm_addr_req_posted => s2mm_addr_req_posted , s2mm_wr_xfer_cmplt => s2mm_wr_xfer_cmplt , s2mm_ld_nxt_len => s2mm_ld_nxt_len , s2mm_wr_len => s2mm_wr_len , s2mm_awid => m_axi_s2mm_awid , s2mm_awaddr => m_axi_s2mm_awaddr , s2mm_awlen => m_axi_s2mm_awlen , s2mm_awsize => m_axi_s2mm_awsize , s2mm_awburst => m_axi_s2mm_awburst , s2mm_awprot => m_axi_s2mm_awprot , s2mm_awcache => m_axi_s2mm_awcache , s2mm_awuser => m_axi_s2mm_awuser , s2mm_awvalid => m_axi_s2mm_awvalid , s2mm_awready => m_axi_s2mm_awready , s2mm_wdata => m_axi_s2mm_wdata , s2mm_wstrb => m_axi_s2mm_wstrb , s2mm_wlast => m_axi_s2mm_wlast , s2mm_wvalid => m_axi_s2mm_wvalid , s2mm_wready => m_axi_s2mm_wready , s2mm_bresp => m_axi_s2mm_bresp , s2mm_bvalid => m_axi_s2mm_bvalid , s2mm_bready => m_axi_s2mm_bready , s2mm_strm_wdata => s_axis_s2mm_tdata , s2mm_strm_wstrb => sig_s2mm_tstrb , s2mm_strm_wlast => s_axis_s2mm_tlast , s2mm_strm_wvalid => s_axis_s2mm_tvalid , s2mm_strm_wready => s_axis_s2mm_tready , s2mm_dbg_sel => s2mm_dbg_sel , s2mm_dbg_data => s2mm_dbg_data ); end generate GEN_S2MM_BASIC; end implementation;
-- ************************************************************************* -- -- (c) Copyright 2010-2011 Xilinx, Inc. All rights reserved. -- -- This file contains confidential and proprietary information -- of Xilinx, Inc. and is protected under U.S. and -- international copyright and other intellectual property -- laws. -- -- DISCLAIMER -- This disclaimer is not a license and does not grant any -- rights to the materials distributed herewith. Except as -- otherwise provided in a valid license issued to you by -- Xilinx, and to the maximum extent permitted by applicable -- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND -- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES -- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING -- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- -- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and -- (2) Xilinx shall not be liable (whether in contract or tort, -- including negligence, or under any other theory of -- liability) for any loss or damage of any kind or nature -- related to, arising under or in connection with these -- materials, including for any direct, or any indirect, -- special, incidental, or consequential loss or damage -- (including loss of data, profits, goodwill, or any type of -- loss or damage suffered as a result of any action brought -- by a third party) even if such damage or loss was -- reasonably foreseeable or Xilinx had been advised of the -- possibility of the same. -- -- CRITICAL APPLICATIONS -- Xilinx products are not designed or intended to be fail- -- safe, or for use in any application requiring fail-safe -- performance, such as life-support or safety devices or -- systems, Class III medical devices, nuclear facilities, -- applications related to the deployment of airbags, or any -- other applications that could lead to death, personal -- injury, or severe property or environmental damage -- (individually and collectively, "Critical -- Applications"). Customer assumes the sole risk and -- liability of any use of Xilinx products in Critical -- Applications, subject only to applicable laws and -- regulations governing limitations on product liability. -- -- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS -- PART OF THIS FILE AT ALL TIMES. -- -- ************************************************************************* -- ------------------------------------------------------------------------------- -- Filename: axi_sg.vhd -- -- Description: -- Top level VHDL wrapper for the AXI DataMover -- -- -- -- -- VHDL-Standard: VHDL'93 ------------------------------------------------------------------------------- library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; library axi_sg_v4_1; use axi_sg_v4_1.axi_sg_mm2s_basic_wrap; use axi_sg_v4_1.axi_sg_s2mm_basic_wrap; ------------------------------------------------------------------------------- entity axi_sg_datamover is generic ( C_INCLUDE_MM2S : Integer range 0 to 2 := 2; -- Specifies the type of MM2S function to include -- 0 = Omit MM2S functionality -- 1 = Full MM2S Functionality -- 2 = Basic MM2S functionality C_M_AXI_MM2S_ARID : Integer range 0 to 255 := 0; -- Specifies the constant value to output on -- the ARID output port C_M_AXI_MM2S_ID_WIDTH : Integer range 1 to 8 := 4; -- Specifies the width of the MM2S ID port C_M_AXI_MM2S_ADDR_WIDTH : Integer range 32 to 64 := 32; -- Specifies the width of the MMap Read Address Channel -- Address bus C_M_AXI_MM2S_DATA_WIDTH : Integer range 32 to 1024 := 32; -- Specifies the width of the MMap Read Data Channel -- data bus C_M_AXIS_MM2S_TDATA_WIDTH : Integer range 8 to 1024 := 32; -- Specifies the width of the MM2S Master Stream Data -- Channel data bus C_INCLUDE_MM2S_STSFIFO : Integer range 0 to 1 := 1; -- Specifies if a Status FIFO is to be implemented -- 0 = Omit MM2S Status FIFO -- 1 = Include MM2S Status FIFO C_MM2S_STSCMD_FIFO_DEPTH : Integer range 1 to 16 := 4; -- Specifies the depth of the MM2S Command FIFO and the -- optional Status FIFO -- Valid values are 1,4,8,16 C_MM2S_STSCMD_IS_ASYNC : Integer range 0 to 1 := 0; -- Specifies if the Status and Command interfaces need to -- be asynchronous to the primary data path clocking -- 0 = Use same clocking as data path -- 1 = Use special Status/Command clock for the interfaces C_INCLUDE_MM2S_DRE : Integer range 0 to 1 := 1; -- Specifies if DRE is to be included in the MM2S function -- 0 = Omit DRE -- 1 = Include DRE C_MM2S_BURST_SIZE : Integer range 16 to 256 := 16; -- Specifies the max number of databeats to use for MMap -- burst transfers by the MM2S function C_MM2S_BTT_USED : Integer range 8 to 23 := 16; -- Specifies the number of bits used from the BTT field -- of the input Command Word of the MM2S Command Interface C_MM2S_ADDR_PIPE_DEPTH : Integer range 1 to 30 := 3; -- This parameter specifies the depth of the MM2S internal -- child command queues in the Read Address Controller and -- the Read Data Controller. Increasing this value will -- allow more Read Addresses to be issued to the AXI4 Read -- Address Channel before receipt of the associated read -- data on the Read Data Channel. C_MM2S_INCLUDE_SF : Integer range 0 to 1 := 1 ; -- This parameter specifies the inclusion/omission of the -- MM2S (Read) Store and Forward function -- 0 = Omit MM2S Store and Forward -- 1 = Include MM2S Store and Forward C_INCLUDE_S2MM : Integer range 0 to 4 := 2; -- Specifies the type of S2MM function to include -- 0 = Omit S2MM functionality -- 1 = Full S2MM Functionality -- 2 = Basic S2MM functionality C_M_AXI_S2MM_AWID : Integer range 0 to 255 := 1; -- Specifies the constant value to output on -- the ARID output port C_M_AXI_S2MM_ID_WIDTH : Integer range 1 to 8 := 4; -- Specifies the width of the S2MM ID port C_M_AXI_S2MM_ADDR_WIDTH : Integer range 32 to 64 := 32; -- Specifies the width of the MMap Read Address Channel -- Address bus C_M_AXI_S2MM_DATA_WIDTH : Integer range 32 to 1024 := 32; -- Specifies the width of the MMap Read Data Channel -- data bus C_S_AXIS_S2MM_TDATA_WIDTH : Integer range 8 to 1024 := 32; -- Specifies the width of the S2MM Master Stream Data -- Channel data bus C_INCLUDE_S2MM_STSFIFO : Integer range 0 to 1 := 1; -- Specifies if a Status FIFO is to be implemented -- 0 = Omit S2MM Status FIFO -- 1 = Include S2MM Status FIFO C_S2MM_STSCMD_FIFO_DEPTH : Integer range 1 to 16 := 4; -- Specifies the depth of the S2MM Command FIFO and the -- optional Status FIFO -- Valid values are 1,4,8,16 C_S2MM_STSCMD_IS_ASYNC : Integer range 0 to 1 := 0; -- Specifies if the Status and Command interfaces need to -- be asynchronous to the primary data path clocking -- 0 = Use same clocking as data path -- 1 = Use special Status/Command clock for the interfaces C_INCLUDE_S2MM_DRE : Integer range 0 to 1 := 1; -- Specifies if DRE is to be included in the S2MM function -- 0 = Omit DRE -- 1 = Include DRE C_S2MM_BURST_SIZE : Integer range 16 to 256 := 16; -- Specifies the max number of databeats to use for MMap -- burst transfers by the S2MM function C_S2MM_BTT_USED : Integer range 8 to 23 := 16; -- Specifies the number of bits used from the BTT field -- of the input Command Word of the S2MM Command Interface C_S2MM_SUPPORT_INDET_BTT : Integer range 0 to 1 := 0; -- Specifies if support for indeterminate packet lengths -- are to be received on the input Stream interface -- 0 = Omit support (User MUST transfer the exact number of -- bytes on the Stream interface as specified in the BTT -- field of the Corresponding DataMover Command) -- 1 = Include support for indeterminate packet lengths -- This causes FIFOs to be added and "Store and Forward" -- behavior of the S2MM function C_S2MM_ADDR_PIPE_DEPTH : Integer range 1 to 30 := 3; -- This parameter specifies the depth of the S2MM internal -- address pipeline queues in the Write Address Controller -- and the Write Data Controller. Increasing this value will -- allow more Write Addresses to be issued to the AXI4 Write -- Address Channel before transmission of the associated -- write data on the Write Data Channel. C_S2MM_INCLUDE_SF : Integer range 0 to 1 := 1 ; -- This parameter specifies the inclusion/omission of the -- S2MM (Write) Store and Forward function -- 0 = Omit S2MM Store and Forward -- 1 = Include S2MM Store and Forward C_ENABLE_MULTI_CHANNEL : integer range 0 to 1 := 1; C_ENABLE_EXTRA_FIELD : integer range 0 to 1 := 0; C_FAMILY : String := "virtex7" -- Specifies the target FPGA family type ); port ( -- MM2S Primary Clock input ---------------------------------- m_axi_mm2s_aclk : in std_logic; -- -- Primary synchronization clock for the Master side -- -- interface and internal logic. It is also used -- -- for the User interface synchronization when -- -- C_STSCMD_IS_ASYNC = 0. -- -- -- MM2S Primary Reset input -- m_axi_mm2s_aresetn : in std_logic; -- -- Reset used for the internal master logic -- -------------------------------------------------------------- sg_ctl : in std_logic_vector (7 downto 0) ; -- MM2S Halt request input control -------------------- mm2s_halt : in std_logic; -- -- Active high soft shutdown request -- -- -- MM2S Halt Complete status flag -- mm2s_halt_cmplt : Out std_logic; -- -- Active high soft shutdown complete status -- ------------------------------------------------------- -- Error discrete output ------------------------- mm2s_err : Out std_logic; -- -- Composite Error indication -- -------------------------------------------------- -- Memory Map to Stream Command FIFO and Status FIFO I/O --------- m_axis_mm2s_cmdsts_aclk : in std_logic; -- -- Secondary Clock input for async CMD/Status interface -- -- m_axis_mm2s_cmdsts_aresetn : in std_logic; -- -- Secondary Reset input for async CMD/Status interface -- ------------------------------------------------------------------ -- User Command Interface Ports (AXI Stream) ------------------------------------------------- s_axis_mm2s_cmd_tvalid : in std_logic; -- s_axis_mm2s_cmd_tready : out std_logic; -- s_axis_mm2s_cmd_tdata : in std_logic_vector(((1+C_ENABLE_MULTI_CHANNEL)*C_M_AXI_MM2S_ADDR_WIDTH+40)-1 downto 0); -- ---------------------------------------------------------------------------------------------- -- User Status Interface Ports (AXI Stream) ------------------------ m_axis_mm2s_sts_tvalid : out std_logic; -- m_axis_mm2s_sts_tready : in std_logic; -- m_axis_mm2s_sts_tdata : out std_logic_vector(7 downto 0); -- m_axis_mm2s_sts_tkeep : out std_logic_vector(0 downto 0); -- m_axis_mm2s_sts_tlast : out std_logic; -- -------------------------------------------------------------------- -- Address Posting contols ----------------------- mm2s_allow_addr_req : in std_logic; -- mm2s_addr_req_posted : out std_logic; -- mm2s_rd_xfer_cmplt : out std_logic; -- -------------------------------------------------- -- MM2S AXI Address Channel I/O -------------------------------------------------- m_axi_mm2s_arid : out std_logic_vector(C_M_AXI_MM2S_ID_WIDTH-1 downto 0); -- -- AXI Address Channel ID output -- -- m_axi_mm2s_araddr : out std_logic_vector(C_M_AXI_MM2S_ADDR_WIDTH-1 downto 0); -- -- AXI Address Channel Address output -- -- m_axi_mm2s_arlen : out std_logic_vector(7 downto 0); -- -- AXI Address Channel LEN output -- -- Sized to support 256 data beat bursts -- -- m_axi_mm2s_arsize : out std_logic_vector(2 downto 0); -- -- AXI Address Channel SIZE output -- -- m_axi_mm2s_arburst : out std_logic_vector(1 downto 0); -- -- AXI Address Channel BURST output -- -- m_axi_mm2s_arprot : out std_logic_vector(2 downto 0); -- -- AXI Address Channel PROT output -- -- m_axi_mm2s_arcache : out std_logic_vector(3 downto 0); -- -- AXI Address Channel CACHE output -- m_axi_mm2s_aruser : out std_logic_vector(3 downto 0); -- -- AXI Address Channel USER output -- -- m_axi_mm2s_arvalid : out std_logic; -- -- AXI Address Channel VALID output -- -- m_axi_mm2s_arready : in std_logic; -- -- AXI Address Channel READY input -- ----------------------------------------------------------------------------------- -- Currently unsupported AXI Address Channel output signals ------- -- m_axi_mm2s_alock : out std_logic_vector(2 downto 0); -- -- m_axi_mm2s_acache : out std_logic_vector(4 downto 0); -- -- m_axi_mm2s_aqos : out std_logic_vector(3 downto 0); -- -- m_axi_mm2s_aregion : out std_logic_vector(3 downto 0); -- ------------------------------------------------------------------- -- MM2S AXI MMap Read Data Channel I/O ------------------------------------------------ m_axi_mm2s_rdata : In std_logic_vector(C_M_AXI_MM2S_DATA_WIDTH-1 downto 0); -- m_axi_mm2s_rresp : In std_logic_vector(1 downto 0); -- m_axi_mm2s_rlast : In std_logic; -- m_axi_mm2s_rvalid : In std_logic; -- m_axi_mm2s_rready : Out std_logic; -- ---------------------------------------------------------------------------------------- -- MM2S AXI Master Stream Channel I/O ------------------------------------------------------- m_axis_mm2s_tdata : Out std_logic_vector(C_M_AXIS_MM2S_TDATA_WIDTH-1 downto 0); -- m_axis_mm2s_tkeep : Out std_logic_vector((C_M_AXIS_MM2S_TDATA_WIDTH/8)-1 downto 0); -- m_axis_mm2s_tlast : Out std_logic; -- m_axis_mm2s_tvalid : Out std_logic; -- m_axis_mm2s_tready : In std_logic; -- ---------------------------------------------------------------------------------------------- -- Testing Support I/O -------------------------------------------------------- mm2s_dbg_sel : in std_logic_vector( 3 downto 0); -- mm2s_dbg_data : out std_logic_vector(31 downto 0) ; -- ------------------------------------------------------------------------------- -- S2MM Primary Clock input --------------------------------- m_axi_s2mm_aclk : in std_logic; -- -- Primary synchronization clock for the Master side -- -- interface and internal logic. It is also used -- -- for the User interface synchronization when -- -- C_STSCMD_IS_ASYNC = 0. -- -- -- S2MM Primary Reset input -- m_axi_s2mm_aresetn : in std_logic; -- -- Reset used for the internal master logic -- ------------------------------------------------------------- -- S2MM Halt request input control ------------------ s2mm_halt : in std_logic; -- -- Active high soft shutdown request -- -- -- S2MM Halt Complete status flag -- s2mm_halt_cmplt : out std_logic; -- -- Active high soft shutdown complete status -- ----------------------------------------------------- -- S2MM Error discrete output ------------------ s2mm_err : Out std_logic; -- -- Composite Error indication -- ------------------------------------------------ -- Memory Map to Stream Command FIFO and Status FIFO I/O ----------------- m_axis_s2mm_cmdsts_awclk : in std_logic; -- -- Secondary Clock input for async CMD/Status interface -- -- m_axis_s2mm_cmdsts_aresetn : in std_logic; -- -- Secondary Reset input for async CMD/Status interface -- -------------------------------------------------------------------------- -- User Command Interface Ports (AXI Stream) -------------------------------------------------- s_axis_s2mm_cmd_tvalid : in std_logic; -- s_axis_s2mm_cmd_tready : out std_logic; -- s_axis_s2mm_cmd_tdata : in std_logic_vector(((1+C_ENABLE_MULTI_CHANNEL)*C_M_AXI_S2MM_ADDR_WIDTH+40)-1 downto 0); -- ----------------------------------------------------------------------------------------------- -- User Status Interface Ports (AXI Stream) ----------------------------------------------------------- m_axis_s2mm_sts_tvalid : out std_logic; -- m_axis_s2mm_sts_tready : in std_logic; -- m_axis_s2mm_sts_tdata : out std_logic_vector(((C_S2MM_SUPPORT_INDET_BTT*24)+8)-1 downto 0); -- m_axis_s2mm_sts_tkeep : out std_logic_vector((((C_S2MM_SUPPORT_INDET_BTT*24)+8)/8)-1 downto 0); -- m_axis_s2mm_sts_tlast : out std_logic; -- ------------------------------------------------------------------------------------------------------- -- Address posting controls ----------------------------------------- s2mm_allow_addr_req : in std_logic; -- s2mm_addr_req_posted : out std_logic; -- s2mm_wr_xfer_cmplt : out std_logic; -- s2mm_ld_nxt_len : out std_logic; -- s2mm_wr_len : out std_logic_vector(7 downto 0); -- --------------------------------------------------------------------- -- S2MM AXI Address Channel I/O ---------------------------------------------------- m_axi_s2mm_awid : out std_logic_vector(C_M_AXI_S2MM_ID_WIDTH-1 downto 0); -- -- AXI Address Channel ID output -- -- m_axi_s2mm_awaddr : out std_logic_vector(C_M_AXI_S2MM_ADDR_WIDTH-1 downto 0); -- -- AXI Address Channel Address output -- -- m_axi_s2mm_awlen : out std_logic_vector(7 downto 0); -- -- AXI Address Channel LEN output -- -- Sized to support 256 data beat bursts -- -- m_axi_s2mm_awsize : out std_logic_vector(2 downto 0); -- -- AXI Address Channel SIZE output -- -- m_axi_s2mm_awburst : out std_logic_vector(1 downto 0); -- -- AXI Address Channel BURST output -- -- m_axi_s2mm_awprot : out std_logic_vector(2 downto 0); -- -- AXI Address Channel PROT output -- -- m_axi_s2mm_awcache : out std_logic_vector(3 downto 0); -- -- AXI Address Channel CACHE output -- m_axi_s2mm_awuser : out std_logic_vector(3 downto 0); -- -- AXI Address Channel USER output -- -- m_axi_s2mm_awvalid : out std_logic; -- -- AXI Address Channel VALID output -- -- m_axi_s2mm_awready : in std_logic; -- -- AXI Address Channel READY input -- ------------------------------------------------------------------------------------- -- Currently unsupported AXI Address Channel output signals ------- -- m_axi_s2mm__awlock : out std_logic_vector(2 downto 0); -- -- m_axi_s2mm__awcache : out std_logic_vector(4 downto 0); -- -- m_axi_s2mm__awqos : out std_logic_vector(3 downto 0); -- -- m_axi_s2mm__awregion : out std_logic_vector(3 downto 0); -- ------------------------------------------------------------------- -- S2MM AXI MMap Write Data Channel I/O -------------------------------------------------- m_axi_s2mm_wdata : Out std_logic_vector(C_M_AXI_S2MM_DATA_WIDTH-1 downto 0); -- m_axi_s2mm_wstrb : Out std_logic_vector((C_M_AXI_S2MM_DATA_WIDTH/8)-1 downto 0); -- m_axi_s2mm_wlast : Out std_logic; -- m_axi_s2mm_wvalid : Out std_logic; -- m_axi_s2mm_wready : In std_logic; -- ------------------------------------------------------------------------------------------- -- S2MM AXI MMap Write response Channel I/O ------------------------- m_axi_s2mm_bresp : In std_logic_vector(1 downto 0); -- m_axi_s2mm_bvalid : In std_logic; -- m_axi_s2mm_bready : Out std_logic; -- ---------------------------------------------------------------------- -- S2MM AXI Slave Stream Channel I/O ------------------------------------------------------- s_axis_s2mm_tdata : In std_logic_vector(C_S_AXIS_S2MM_TDATA_WIDTH-1 downto 0); -- s_axis_s2mm_tkeep : In std_logic_vector((C_S_AXIS_S2MM_TDATA_WIDTH/8)-1 downto 0); -- s_axis_s2mm_tlast : In std_logic; -- s_axis_s2mm_tvalid : In std_logic; -- s_axis_s2mm_tready : Out std_logic; -- --------------------------------------------------------------------------------------------- -- Testing Support I/O ------------------------------------------------ s2mm_dbg_sel : in std_logic_vector( 3 downto 0); -- s2mm_dbg_data : out std_logic_vector(31 downto 0) -- ------------------------------------------------------------------------ ); end entity axi_sg_datamover; architecture implementation of axi_sg_datamover is attribute DowngradeIPIdentifiedWarnings: string; attribute DowngradeIPIdentifiedWarnings of implementation : architecture is "yes"; -- Function Declarations ------------------------------------------------------------------- -- Function -- -- Function Name: funct_clip_brst_len -- -- Function Description: -- This function is used to limit the parameterized max burst -- databeats when the tranfer data width is 256 bits or greater. -- This is required to keep from crossing the 4K byte xfer -- boundary required by AXI. This process is further complicated -- by the inclusion/omission of upsizers or downsizers in the -- data path. -- ------------------------------------------------------------------- function funct_clip_brst_len (param_burst_beats : integer; mmap_transfer_bit_width : integer; stream_transfer_bit_width : integer; down_up_sizers_enabled : integer) return integer is constant FCONST_SIZERS_ENABLED : boolean := (down_up_sizers_enabled > 0); Variable fvar_max_burst_dbeats : Integer; begin -- coverage off if (FCONST_SIZERS_ENABLED) then -- use MMap dwidth for calc If (mmap_transfer_bit_width <= 128) Then -- allowed fvar_max_burst_dbeats := param_burst_beats; Elsif (mmap_transfer_bit_width <= 256) Then If (param_burst_beats <= 128) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 128; End if; Elsif (mmap_transfer_bit_width <= 512) Then If (param_burst_beats <= 64) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 64; End if; Else -- 1024 bit mmap width case If (param_burst_beats <= 32) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 32; End if; End if; else -- use stream dwidth for calc If (stream_transfer_bit_width <= 128) Then -- allowed fvar_max_burst_dbeats := param_burst_beats; Elsif (stream_transfer_bit_width <= 256) Then If (param_burst_beats <= 128) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 128; End if; Elsif (stream_transfer_bit_width <= 512) Then If (param_burst_beats <= 64) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 64; End if; Else -- 1024 bit stream width case If (param_burst_beats <= 32) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 32; End if; -- coverage on End if; end if; Return (fvar_max_burst_dbeats); end function funct_clip_brst_len; ------------------------------------------------------------------- -- Function -- -- Function Name: funct_fix_depth_16 -- -- Function Description: -- This function is used to fix the Command and Status FIFO depths to -- 16 entries when Async clocking mode is enabled. This is required -- due to the way the async_fifo_fg.vhd design in proc_common is -- implemented. ------------------------------------------------------------------- function funct_fix_depth_16 (async_clocking_mode : integer; requested_depth : integer) return integer is Variable fvar_depth_2_use : Integer; begin -- coverage off If (async_clocking_mode = 1) Then -- async mode so fix at 16 fvar_depth_2_use := 16; Elsif (requested_depth > 16) Then -- limit at 16 fvar_depth_2_use := 16; -- coverage on Else -- use requested depth fvar_depth_2_use := requested_depth; End if; Return (fvar_depth_2_use); end function funct_fix_depth_16; ------------------------------------------------------------------- -- Function -- -- Function Name: funct_get_min_btt_width -- -- Function Description: -- This function calculates the minimum required value -- for the used width of the command BTT field. -- ------------------------------------------------------------------- function funct_get_min_btt_width (max_burst_beats : integer; bytes_per_beat : integer ) return integer is Variable var_min_btt_needed : Integer; Variable var_max_bytes_per_burst : Integer; begin var_max_bytes_per_burst := max_burst_beats*bytes_per_beat; -- coverage off if (var_max_bytes_per_burst <= 16) then var_min_btt_needed := 5; elsif (var_max_bytes_per_burst <= 32) then var_min_btt_needed := 6; -- coverage on elsif (var_max_bytes_per_burst <= 64) then var_min_btt_needed := 7; -- coverage off elsif (var_max_bytes_per_burst <= 128) then var_min_btt_needed := 8; elsif (var_max_bytes_per_burst <= 256) then var_min_btt_needed := 9; elsif (var_max_bytes_per_burst <= 512) then var_min_btt_needed := 10; elsif (var_max_bytes_per_burst <= 1024) then var_min_btt_needed := 11; elsif (var_max_bytes_per_burst <= 2048) then var_min_btt_needed := 12; elsif (var_max_bytes_per_burst <= 4096) then var_min_btt_needed := 13; else -- 8K byte range var_min_btt_needed := 14; end if; -- coverage on Return (var_min_btt_needed); end function funct_get_min_btt_width; ------------------------------------------------------------------- -- Function -- -- Function Name: funct_get_xfer_bytes_per_dbeat -- -- Function Description: -- Calculates the nuber of bytes that will transfered per databeat -- on the AXI4 MMap Bus. -- ------------------------------------------------------------------- function funct_get_xfer_bytes_per_dbeat (mmap_transfer_bit_width : integer; stream_transfer_bit_width : integer; down_up_sizers_enabled : integer) return integer is Variable temp_bytes_per_dbeat : Integer := 4; begin -- coverage off if (down_up_sizers_enabled > 0) then -- down/up sizers are in use, use full mmap dwidth temp_bytes_per_dbeat := mmap_transfer_bit_width/8; -- coverage on else -- No down/up sizers so use Stream data width temp_bytes_per_dbeat := stream_transfer_bit_width/8; end if; Return (temp_bytes_per_dbeat); end function funct_get_xfer_bytes_per_dbeat; ------------------------------------------------------------------- -- Function -- -- Function Name: funct_fix_btt_used -- -- Function Description: -- THis function makes sure the BTT width used is at least the -- minimum needed. -- ------------------------------------------------------------------- function funct_fix_btt_used (requested_btt_width : integer; min_btt_width : integer) return integer is Variable var_corrected_btt_width : Integer; begin -- coverage off If (requested_btt_width < min_btt_width) Then var_corrected_btt_width := min_btt_width; -- coverage on else var_corrected_btt_width := requested_btt_width; End if; Return (var_corrected_btt_width); end function funct_fix_btt_used; ------------------------------------------------------------------- -- Constant Declarations ------------------------------------------------------------------- Constant MM2S_TAG_WIDTH : integer := 4; Constant S2MM_TAG_WIDTH : integer := 4; Constant MM2S_DOWNSIZER_ENABLED : integer := C_MM2S_INCLUDE_SF; Constant S2MM_UPSIZER_ENABLED : integer := C_S2MM_INCLUDE_SF + C_S2MM_SUPPORT_INDET_BTT; Constant MM2S_MAX_BURST_BEATS : integer := funct_clip_brst_len(C_MM2S_BURST_SIZE, C_M_AXI_MM2S_DATA_WIDTH, C_M_AXIS_MM2S_TDATA_WIDTH, MM2S_DOWNSIZER_ENABLED); Constant S2MM_MAX_BURST_BEATS : integer := funct_clip_brst_len(C_S2MM_BURST_SIZE, C_M_AXI_S2MM_DATA_WIDTH, C_S_AXIS_S2MM_TDATA_WIDTH, S2MM_UPSIZER_ENABLED); Constant MM2S_CMDSTS_FIFO_DEPTH : integer := funct_fix_depth_16(C_MM2S_STSCMD_IS_ASYNC, C_MM2S_STSCMD_FIFO_DEPTH); Constant S2MM_CMDSTS_FIFO_DEPTH : integer := funct_fix_depth_16(C_S2MM_STSCMD_IS_ASYNC, C_S2MM_STSCMD_FIFO_DEPTH); Constant MM2S_BYTES_PER_BEAT : integer := funct_get_xfer_bytes_per_dbeat(C_M_AXI_MM2S_DATA_WIDTH, C_M_AXIS_MM2S_TDATA_WIDTH, MM2S_DOWNSIZER_ENABLED); Constant MM2S_MIN_BTT_NEEDED : integer := funct_get_min_btt_width(MM2S_MAX_BURST_BEATS, MM2S_BYTES_PER_BEAT); Constant MM2S_CORRECTED_BTT_USED : integer := funct_fix_btt_used(C_MM2S_BTT_USED, MM2S_MIN_BTT_NEEDED); Constant S2MM_BYTES_PER_BEAT : integer := funct_get_xfer_bytes_per_dbeat(C_M_AXI_S2MM_DATA_WIDTH, C_S_AXIS_S2MM_TDATA_WIDTH, S2MM_UPSIZER_ENABLED); Constant S2MM_MIN_BTT_NEEDED : integer := funct_get_min_btt_width(S2MM_MAX_BURST_BEATS, S2MM_BYTES_PER_BEAT); Constant S2MM_CORRECTED_BTT_USED : integer := funct_fix_btt_used(C_S2MM_BTT_USED, S2MM_MIN_BTT_NEEDED); -- Signals signal sig_mm2s_tstrb : std_logic_vector((C_M_AXIS_MM2S_TDATA_WIDTH/8)-1 downto 0) := (others => '0'); signal sig_mm2s_sts_tstrb : std_logic_vector(0 downto 0) := (others => '0'); signal sig_s2mm_tstrb : std_logic_vector((C_S_AXIS_S2MM_TDATA_WIDTH/8)-1 downto 0) := (others => '0'); signal sig_s2mm_sts_tstrb : std_logic_vector((((C_S2MM_SUPPORT_INDET_BTT*24)+8)/8)-1 downto 0) := (others => '0'); begin --(architecture implementation) ------------------------------------------------------------- -- Conversion to tkeep for external stream connnections ------------------------------------------------------------- -- MM2S Stream Output m_axis_mm2s_tkeep <= sig_mm2s_tstrb ; -- MM2S Status Stream Output m_axis_mm2s_sts_tkeep <= sig_mm2s_sts_tstrb ; -- S2MM Stream Input sig_s2mm_tstrb <= s_axis_s2mm_tkeep ; -- S2MM Status Stream Output m_axis_s2mm_sts_tkeep <= sig_s2mm_sts_tstrb ; ------------------------------------------------------------ -- If Generate -- -- Label: GEN_MM2S_BASIC -- -- If Generate Description: -- Instantiate the MM2S Basic Wrapper -- -- ------------------------------------------------------------ GEN_MM2S_BASIC : if (C_INCLUDE_MM2S = 2) generate begin ------------------------------------------------------------ -- Instance: I_MM2S_BASIC_WRAPPER -- -- Description: -- Read Basic Wrapper Instance -- ------------------------------------------------------------ I_MM2S_BASIC_WRAPPER : entity axi_sg_v4_1.axi_sg_mm2s_basic_wrap generic map ( C_INCLUDE_MM2S => C_INCLUDE_MM2S , C_MM2S_ARID => C_M_AXI_MM2S_ARID , C_MM2S_ID_WIDTH => C_M_AXI_MM2S_ID_WIDTH , C_MM2S_ADDR_WIDTH => C_M_AXI_MM2S_ADDR_WIDTH , C_MM2S_MDATA_WIDTH => C_M_AXI_MM2S_DATA_WIDTH , C_MM2S_SDATA_WIDTH => C_M_AXIS_MM2S_TDATA_WIDTH , C_INCLUDE_MM2S_STSFIFO => C_INCLUDE_MM2S_STSFIFO , C_MM2S_STSCMD_FIFO_DEPTH => MM2S_CMDSTS_FIFO_DEPTH , C_MM2S_STSCMD_IS_ASYNC => C_MM2S_STSCMD_IS_ASYNC , C_INCLUDE_MM2S_DRE => C_INCLUDE_MM2S_DRE , C_MM2S_BURST_SIZE => MM2S_MAX_BURST_BEATS , C_MM2S_BTT_USED => MM2S_CORRECTED_BTT_USED , C_MM2S_ADDR_PIPE_DEPTH => C_MM2S_ADDR_PIPE_DEPTH , C_TAG_WIDTH => MM2S_TAG_WIDTH , C_ENABLE_MULTI_CHANNEL => C_ENABLE_MULTI_CHANNEL , C_ENABLE_EXTRA_FIELD => C_ENABLE_EXTRA_FIELD, C_FAMILY => C_FAMILY ) port map ( mm2s_aclk => m_axi_mm2s_aclk , mm2s_aresetn => m_axi_mm2s_aresetn , sg_ctl => sg_ctl , mm2s_halt => mm2s_halt , mm2s_halt_cmplt => mm2s_halt_cmplt , mm2s_err => mm2s_err , mm2s_cmdsts_awclk => m_axis_mm2s_cmdsts_aclk , mm2s_cmdsts_aresetn => m_axis_mm2s_cmdsts_aresetn , mm2s_cmd_wvalid => s_axis_mm2s_cmd_tvalid , mm2s_cmd_wready => s_axis_mm2s_cmd_tready , mm2s_cmd_wdata => s_axis_mm2s_cmd_tdata , mm2s_sts_wvalid => m_axis_mm2s_sts_tvalid , mm2s_sts_wready => m_axis_mm2s_sts_tready , mm2s_sts_wdata => m_axis_mm2s_sts_tdata , mm2s_sts_wstrb => sig_mm2s_sts_tstrb , mm2s_sts_wlast => m_axis_mm2s_sts_tlast , mm2s_allow_addr_req => mm2s_allow_addr_req , mm2s_addr_req_posted => mm2s_addr_req_posted , mm2s_rd_xfer_cmplt => mm2s_rd_xfer_cmplt , mm2s_arid => m_axi_mm2s_arid , mm2s_araddr => m_axi_mm2s_araddr , mm2s_arlen => m_axi_mm2s_arlen , mm2s_arsize => m_axi_mm2s_arsize , mm2s_arburst => m_axi_mm2s_arburst , mm2s_arprot => m_axi_mm2s_arprot , mm2s_arcache => m_axi_mm2s_arcache , mm2s_aruser => m_axi_mm2s_aruser , mm2s_arvalid => m_axi_mm2s_arvalid , mm2s_arready => m_axi_mm2s_arready , mm2s_rdata => m_axi_mm2s_rdata , mm2s_rresp => m_axi_mm2s_rresp , mm2s_rlast => m_axi_mm2s_rlast , mm2s_rvalid => m_axi_mm2s_rvalid , mm2s_rready => m_axi_mm2s_rready , mm2s_strm_wdata => m_axis_mm2s_tdata , mm2s_strm_wstrb => sig_mm2s_tstrb , mm2s_strm_wlast => m_axis_mm2s_tlast , mm2s_strm_wvalid => m_axis_mm2s_tvalid , mm2s_strm_wready => m_axis_mm2s_tready , mm2s_dbg_sel => mm2s_dbg_sel , mm2s_dbg_data => mm2s_dbg_data ); end generate GEN_MM2S_BASIC; ------------------------------------------------------------ -- If Generate -- -- Label: GEN_S2MM_BASIC -- -- If Generate Description: -- Instantiate the S2MM Basic Wrapper -- -- ------------------------------------------------------------ GEN_S2MM_BASIC : if (C_INCLUDE_S2MM = 2) generate begin ------------------------------------------------------------ -- Instance: I_S2MM_BASIC_WRAPPER -- -- Description: -- Write Basic Wrapper Instance -- ------------------------------------------------------------ I_S2MM_BASIC_WRAPPER : entity axi_sg_v4_1.axi_sg_s2mm_basic_wrap generic map ( C_INCLUDE_S2MM => C_INCLUDE_S2MM , C_S2MM_AWID => C_M_AXI_S2MM_AWID , C_S2MM_ID_WIDTH => C_M_AXI_S2MM_ID_WIDTH , C_S2MM_ADDR_WIDTH => C_M_AXI_S2MM_ADDR_WIDTH , C_S2MM_MDATA_WIDTH => C_M_AXI_S2MM_DATA_WIDTH , C_S2MM_SDATA_WIDTH => C_S_AXIS_S2MM_TDATA_WIDTH , C_INCLUDE_S2MM_STSFIFO => C_INCLUDE_S2MM_STSFIFO , C_S2MM_STSCMD_FIFO_DEPTH => S2MM_CMDSTS_FIFO_DEPTH , C_S2MM_STSCMD_IS_ASYNC => C_S2MM_STSCMD_IS_ASYNC , C_INCLUDE_S2MM_DRE => C_INCLUDE_S2MM_DRE , C_S2MM_BURST_SIZE => S2MM_MAX_BURST_BEATS , C_S2MM_ADDR_PIPE_DEPTH => C_S2MM_ADDR_PIPE_DEPTH , C_TAG_WIDTH => S2MM_TAG_WIDTH , C_ENABLE_MULTI_CHANNEL => C_ENABLE_MULTI_CHANNEL , C_ENABLE_EXTRA_FIELD => C_ENABLE_EXTRA_FIELD, C_FAMILY => C_FAMILY ) port map ( s2mm_aclk => m_axi_s2mm_aclk , s2mm_aresetn => m_axi_s2mm_aresetn , sg_ctl => sg_ctl , s2mm_halt => s2mm_halt , s2mm_halt_cmplt => s2mm_halt_cmplt , s2mm_err => s2mm_err , s2mm_cmdsts_awclk => m_axis_s2mm_cmdsts_awclk , s2mm_cmdsts_aresetn => m_axis_s2mm_cmdsts_aresetn , s2mm_cmd_wvalid => s_axis_s2mm_cmd_tvalid , s2mm_cmd_wready => s_axis_s2mm_cmd_tready , s2mm_cmd_wdata => s_axis_s2mm_cmd_tdata , s2mm_sts_wvalid => m_axis_s2mm_sts_tvalid , s2mm_sts_wready => m_axis_s2mm_sts_tready , s2mm_sts_wdata => m_axis_s2mm_sts_tdata , s2mm_sts_wstrb => sig_s2mm_sts_tstrb , s2mm_sts_wlast => m_axis_s2mm_sts_tlast , s2mm_allow_addr_req => s2mm_allow_addr_req , s2mm_addr_req_posted => s2mm_addr_req_posted , s2mm_wr_xfer_cmplt => s2mm_wr_xfer_cmplt , s2mm_ld_nxt_len => s2mm_ld_nxt_len , s2mm_wr_len => s2mm_wr_len , s2mm_awid => m_axi_s2mm_awid , s2mm_awaddr => m_axi_s2mm_awaddr , s2mm_awlen => m_axi_s2mm_awlen , s2mm_awsize => m_axi_s2mm_awsize , s2mm_awburst => m_axi_s2mm_awburst , s2mm_awprot => m_axi_s2mm_awprot , s2mm_awcache => m_axi_s2mm_awcache , s2mm_awuser => m_axi_s2mm_awuser , s2mm_awvalid => m_axi_s2mm_awvalid , s2mm_awready => m_axi_s2mm_awready , s2mm_wdata => m_axi_s2mm_wdata , s2mm_wstrb => m_axi_s2mm_wstrb , s2mm_wlast => m_axi_s2mm_wlast , s2mm_wvalid => m_axi_s2mm_wvalid , s2mm_wready => m_axi_s2mm_wready , s2mm_bresp => m_axi_s2mm_bresp , s2mm_bvalid => m_axi_s2mm_bvalid , s2mm_bready => m_axi_s2mm_bready , s2mm_strm_wdata => s_axis_s2mm_tdata , s2mm_strm_wstrb => sig_s2mm_tstrb , s2mm_strm_wlast => s_axis_s2mm_tlast , s2mm_strm_wvalid => s_axis_s2mm_tvalid , s2mm_strm_wready => s_axis_s2mm_tready , s2mm_dbg_sel => s2mm_dbg_sel , s2mm_dbg_data => s2mm_dbg_data ); end generate GEN_S2MM_BASIC; end implementation;
-- ************************************************************************* -- -- (c) Copyright 2010-2011 Xilinx, Inc. All rights reserved. -- -- This file contains confidential and proprietary information -- of Xilinx, Inc. and is protected under U.S. and -- international copyright and other intellectual property -- laws. -- -- DISCLAIMER -- This disclaimer is not a license and does not grant any -- rights to the materials distributed herewith. Except as -- otherwise provided in a valid license issued to you by -- Xilinx, and to the maximum extent permitted by applicable -- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND -- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES -- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING -- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- -- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and -- (2) Xilinx shall not be liable (whether in contract or tort, -- including negligence, or under any other theory of -- liability) for any loss or damage of any kind or nature -- related to, arising under or in connection with these -- materials, including for any direct, or any indirect, -- special, incidental, or consequential loss or damage -- (including loss of data, profits, goodwill, or any type of -- loss or damage suffered as a result of any action brought -- by a third party) even if such damage or loss was -- reasonably foreseeable or Xilinx had been advised of the -- possibility of the same. -- -- CRITICAL APPLICATIONS -- Xilinx products are not designed or intended to be fail- -- safe, or for use in any application requiring fail-safe -- performance, such as life-support or safety devices or -- systems, Class III medical devices, nuclear facilities, -- applications related to the deployment of airbags, or any -- other applications that could lead to death, personal -- injury, or severe property or environmental damage -- (individually and collectively, "Critical -- Applications"). Customer assumes the sole risk and -- liability of any use of Xilinx products in Critical -- Applications, subject only to applicable laws and -- regulations governing limitations on product liability. -- -- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS -- PART OF THIS FILE AT ALL TIMES. -- -- ************************************************************************* -- ------------------------------------------------------------------------------- -- Filename: axi_sg.vhd -- -- Description: -- Top level VHDL wrapper for the AXI DataMover -- -- -- -- -- VHDL-Standard: VHDL'93 ------------------------------------------------------------------------------- library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; library axi_sg_v4_1; use axi_sg_v4_1.axi_sg_mm2s_basic_wrap; use axi_sg_v4_1.axi_sg_s2mm_basic_wrap; ------------------------------------------------------------------------------- entity axi_sg_datamover is generic ( C_INCLUDE_MM2S : Integer range 0 to 2 := 2; -- Specifies the type of MM2S function to include -- 0 = Omit MM2S functionality -- 1 = Full MM2S Functionality -- 2 = Basic MM2S functionality C_M_AXI_MM2S_ARID : Integer range 0 to 255 := 0; -- Specifies the constant value to output on -- the ARID output port C_M_AXI_MM2S_ID_WIDTH : Integer range 1 to 8 := 4; -- Specifies the width of the MM2S ID port C_M_AXI_MM2S_ADDR_WIDTH : Integer range 32 to 64 := 32; -- Specifies the width of the MMap Read Address Channel -- Address bus C_M_AXI_MM2S_DATA_WIDTH : Integer range 32 to 1024 := 32; -- Specifies the width of the MMap Read Data Channel -- data bus C_M_AXIS_MM2S_TDATA_WIDTH : Integer range 8 to 1024 := 32; -- Specifies the width of the MM2S Master Stream Data -- Channel data bus C_INCLUDE_MM2S_STSFIFO : Integer range 0 to 1 := 1; -- Specifies if a Status FIFO is to be implemented -- 0 = Omit MM2S Status FIFO -- 1 = Include MM2S Status FIFO C_MM2S_STSCMD_FIFO_DEPTH : Integer range 1 to 16 := 4; -- Specifies the depth of the MM2S Command FIFO and the -- optional Status FIFO -- Valid values are 1,4,8,16 C_MM2S_STSCMD_IS_ASYNC : Integer range 0 to 1 := 0; -- Specifies if the Status and Command interfaces need to -- be asynchronous to the primary data path clocking -- 0 = Use same clocking as data path -- 1 = Use special Status/Command clock for the interfaces C_INCLUDE_MM2S_DRE : Integer range 0 to 1 := 1; -- Specifies if DRE is to be included in the MM2S function -- 0 = Omit DRE -- 1 = Include DRE C_MM2S_BURST_SIZE : Integer range 16 to 256 := 16; -- Specifies the max number of databeats to use for MMap -- burst transfers by the MM2S function C_MM2S_BTT_USED : Integer range 8 to 23 := 16; -- Specifies the number of bits used from the BTT field -- of the input Command Word of the MM2S Command Interface C_MM2S_ADDR_PIPE_DEPTH : Integer range 1 to 30 := 3; -- This parameter specifies the depth of the MM2S internal -- child command queues in the Read Address Controller and -- the Read Data Controller. Increasing this value will -- allow more Read Addresses to be issued to the AXI4 Read -- Address Channel before receipt of the associated read -- data on the Read Data Channel. C_MM2S_INCLUDE_SF : Integer range 0 to 1 := 1 ; -- This parameter specifies the inclusion/omission of the -- MM2S (Read) Store and Forward function -- 0 = Omit MM2S Store and Forward -- 1 = Include MM2S Store and Forward C_INCLUDE_S2MM : Integer range 0 to 4 := 2; -- Specifies the type of S2MM function to include -- 0 = Omit S2MM functionality -- 1 = Full S2MM Functionality -- 2 = Basic S2MM functionality C_M_AXI_S2MM_AWID : Integer range 0 to 255 := 1; -- Specifies the constant value to output on -- the ARID output port C_M_AXI_S2MM_ID_WIDTH : Integer range 1 to 8 := 4; -- Specifies the width of the S2MM ID port C_M_AXI_S2MM_ADDR_WIDTH : Integer range 32 to 64 := 32; -- Specifies the width of the MMap Read Address Channel -- Address bus C_M_AXI_S2MM_DATA_WIDTH : Integer range 32 to 1024 := 32; -- Specifies the width of the MMap Read Data Channel -- data bus C_S_AXIS_S2MM_TDATA_WIDTH : Integer range 8 to 1024 := 32; -- Specifies the width of the S2MM Master Stream Data -- Channel data bus C_INCLUDE_S2MM_STSFIFO : Integer range 0 to 1 := 1; -- Specifies if a Status FIFO is to be implemented -- 0 = Omit S2MM Status FIFO -- 1 = Include S2MM Status FIFO C_S2MM_STSCMD_FIFO_DEPTH : Integer range 1 to 16 := 4; -- Specifies the depth of the S2MM Command FIFO and the -- optional Status FIFO -- Valid values are 1,4,8,16 C_S2MM_STSCMD_IS_ASYNC : Integer range 0 to 1 := 0; -- Specifies if the Status and Command interfaces need to -- be asynchronous to the primary data path clocking -- 0 = Use same clocking as data path -- 1 = Use special Status/Command clock for the interfaces C_INCLUDE_S2MM_DRE : Integer range 0 to 1 := 1; -- Specifies if DRE is to be included in the S2MM function -- 0 = Omit DRE -- 1 = Include DRE C_S2MM_BURST_SIZE : Integer range 16 to 256 := 16; -- Specifies the max number of databeats to use for MMap -- burst transfers by the S2MM function C_S2MM_BTT_USED : Integer range 8 to 23 := 16; -- Specifies the number of bits used from the BTT field -- of the input Command Word of the S2MM Command Interface C_S2MM_SUPPORT_INDET_BTT : Integer range 0 to 1 := 0; -- Specifies if support for indeterminate packet lengths -- are to be received on the input Stream interface -- 0 = Omit support (User MUST transfer the exact number of -- bytes on the Stream interface as specified in the BTT -- field of the Corresponding DataMover Command) -- 1 = Include support for indeterminate packet lengths -- This causes FIFOs to be added and "Store and Forward" -- behavior of the S2MM function C_S2MM_ADDR_PIPE_DEPTH : Integer range 1 to 30 := 3; -- This parameter specifies the depth of the S2MM internal -- address pipeline queues in the Write Address Controller -- and the Write Data Controller. Increasing this value will -- allow more Write Addresses to be issued to the AXI4 Write -- Address Channel before transmission of the associated -- write data on the Write Data Channel. C_S2MM_INCLUDE_SF : Integer range 0 to 1 := 1 ; -- This parameter specifies the inclusion/omission of the -- S2MM (Write) Store and Forward function -- 0 = Omit S2MM Store and Forward -- 1 = Include S2MM Store and Forward C_ENABLE_MULTI_CHANNEL : integer range 0 to 1 := 1; C_ENABLE_EXTRA_FIELD : integer range 0 to 1 := 0; C_FAMILY : String := "virtex7" -- Specifies the target FPGA family type ); port ( -- MM2S Primary Clock input ---------------------------------- m_axi_mm2s_aclk : in std_logic; -- -- Primary synchronization clock for the Master side -- -- interface and internal logic. It is also used -- -- for the User interface synchronization when -- -- C_STSCMD_IS_ASYNC = 0. -- -- -- MM2S Primary Reset input -- m_axi_mm2s_aresetn : in std_logic; -- -- Reset used for the internal master logic -- -------------------------------------------------------------- sg_ctl : in std_logic_vector (7 downto 0) ; -- MM2S Halt request input control -------------------- mm2s_halt : in std_logic; -- -- Active high soft shutdown request -- -- -- MM2S Halt Complete status flag -- mm2s_halt_cmplt : Out std_logic; -- -- Active high soft shutdown complete status -- ------------------------------------------------------- -- Error discrete output ------------------------- mm2s_err : Out std_logic; -- -- Composite Error indication -- -------------------------------------------------- -- Memory Map to Stream Command FIFO and Status FIFO I/O --------- m_axis_mm2s_cmdsts_aclk : in std_logic; -- -- Secondary Clock input for async CMD/Status interface -- -- m_axis_mm2s_cmdsts_aresetn : in std_logic; -- -- Secondary Reset input for async CMD/Status interface -- ------------------------------------------------------------------ -- User Command Interface Ports (AXI Stream) ------------------------------------------------- s_axis_mm2s_cmd_tvalid : in std_logic; -- s_axis_mm2s_cmd_tready : out std_logic; -- s_axis_mm2s_cmd_tdata : in std_logic_vector(((1+C_ENABLE_MULTI_CHANNEL)*C_M_AXI_MM2S_ADDR_WIDTH+40)-1 downto 0); -- ---------------------------------------------------------------------------------------------- -- User Status Interface Ports (AXI Stream) ------------------------ m_axis_mm2s_sts_tvalid : out std_logic; -- m_axis_mm2s_sts_tready : in std_logic; -- m_axis_mm2s_sts_tdata : out std_logic_vector(7 downto 0); -- m_axis_mm2s_sts_tkeep : out std_logic_vector(0 downto 0); -- m_axis_mm2s_sts_tlast : out std_logic; -- -------------------------------------------------------------------- -- Address Posting contols ----------------------- mm2s_allow_addr_req : in std_logic; -- mm2s_addr_req_posted : out std_logic; -- mm2s_rd_xfer_cmplt : out std_logic; -- -------------------------------------------------- -- MM2S AXI Address Channel I/O -------------------------------------------------- m_axi_mm2s_arid : out std_logic_vector(C_M_AXI_MM2S_ID_WIDTH-1 downto 0); -- -- AXI Address Channel ID output -- -- m_axi_mm2s_araddr : out std_logic_vector(C_M_AXI_MM2S_ADDR_WIDTH-1 downto 0); -- -- AXI Address Channel Address output -- -- m_axi_mm2s_arlen : out std_logic_vector(7 downto 0); -- -- AXI Address Channel LEN output -- -- Sized to support 256 data beat bursts -- -- m_axi_mm2s_arsize : out std_logic_vector(2 downto 0); -- -- AXI Address Channel SIZE output -- -- m_axi_mm2s_arburst : out std_logic_vector(1 downto 0); -- -- AXI Address Channel BURST output -- -- m_axi_mm2s_arprot : out std_logic_vector(2 downto 0); -- -- AXI Address Channel PROT output -- -- m_axi_mm2s_arcache : out std_logic_vector(3 downto 0); -- -- AXI Address Channel CACHE output -- m_axi_mm2s_aruser : out std_logic_vector(3 downto 0); -- -- AXI Address Channel USER output -- -- m_axi_mm2s_arvalid : out std_logic; -- -- AXI Address Channel VALID output -- -- m_axi_mm2s_arready : in std_logic; -- -- AXI Address Channel READY input -- ----------------------------------------------------------------------------------- -- Currently unsupported AXI Address Channel output signals ------- -- m_axi_mm2s_alock : out std_logic_vector(2 downto 0); -- -- m_axi_mm2s_acache : out std_logic_vector(4 downto 0); -- -- m_axi_mm2s_aqos : out std_logic_vector(3 downto 0); -- -- m_axi_mm2s_aregion : out std_logic_vector(3 downto 0); -- ------------------------------------------------------------------- -- MM2S AXI MMap Read Data Channel I/O ------------------------------------------------ m_axi_mm2s_rdata : In std_logic_vector(C_M_AXI_MM2S_DATA_WIDTH-1 downto 0); -- m_axi_mm2s_rresp : In std_logic_vector(1 downto 0); -- m_axi_mm2s_rlast : In std_logic; -- m_axi_mm2s_rvalid : In std_logic; -- m_axi_mm2s_rready : Out std_logic; -- ---------------------------------------------------------------------------------------- -- MM2S AXI Master Stream Channel I/O ------------------------------------------------------- m_axis_mm2s_tdata : Out std_logic_vector(C_M_AXIS_MM2S_TDATA_WIDTH-1 downto 0); -- m_axis_mm2s_tkeep : Out std_logic_vector((C_M_AXIS_MM2S_TDATA_WIDTH/8)-1 downto 0); -- m_axis_mm2s_tlast : Out std_logic; -- m_axis_mm2s_tvalid : Out std_logic; -- m_axis_mm2s_tready : In std_logic; -- ---------------------------------------------------------------------------------------------- -- Testing Support I/O -------------------------------------------------------- mm2s_dbg_sel : in std_logic_vector( 3 downto 0); -- mm2s_dbg_data : out std_logic_vector(31 downto 0) ; -- ------------------------------------------------------------------------------- -- S2MM Primary Clock input --------------------------------- m_axi_s2mm_aclk : in std_logic; -- -- Primary synchronization clock for the Master side -- -- interface and internal logic. It is also used -- -- for the User interface synchronization when -- -- C_STSCMD_IS_ASYNC = 0. -- -- -- S2MM Primary Reset input -- m_axi_s2mm_aresetn : in std_logic; -- -- Reset used for the internal master logic -- ------------------------------------------------------------- -- S2MM Halt request input control ------------------ s2mm_halt : in std_logic; -- -- Active high soft shutdown request -- -- -- S2MM Halt Complete status flag -- s2mm_halt_cmplt : out std_logic; -- -- Active high soft shutdown complete status -- ----------------------------------------------------- -- S2MM Error discrete output ------------------ s2mm_err : Out std_logic; -- -- Composite Error indication -- ------------------------------------------------ -- Memory Map to Stream Command FIFO and Status FIFO I/O ----------------- m_axis_s2mm_cmdsts_awclk : in std_logic; -- -- Secondary Clock input for async CMD/Status interface -- -- m_axis_s2mm_cmdsts_aresetn : in std_logic; -- -- Secondary Reset input for async CMD/Status interface -- -------------------------------------------------------------------------- -- User Command Interface Ports (AXI Stream) -------------------------------------------------- s_axis_s2mm_cmd_tvalid : in std_logic; -- s_axis_s2mm_cmd_tready : out std_logic; -- s_axis_s2mm_cmd_tdata : in std_logic_vector(((1+C_ENABLE_MULTI_CHANNEL)*C_M_AXI_S2MM_ADDR_WIDTH+40)-1 downto 0); -- ----------------------------------------------------------------------------------------------- -- User Status Interface Ports (AXI Stream) ----------------------------------------------------------- m_axis_s2mm_sts_tvalid : out std_logic; -- m_axis_s2mm_sts_tready : in std_logic; -- m_axis_s2mm_sts_tdata : out std_logic_vector(((C_S2MM_SUPPORT_INDET_BTT*24)+8)-1 downto 0); -- m_axis_s2mm_sts_tkeep : out std_logic_vector((((C_S2MM_SUPPORT_INDET_BTT*24)+8)/8)-1 downto 0); -- m_axis_s2mm_sts_tlast : out std_logic; -- ------------------------------------------------------------------------------------------------------- -- Address posting controls ----------------------------------------- s2mm_allow_addr_req : in std_logic; -- s2mm_addr_req_posted : out std_logic; -- s2mm_wr_xfer_cmplt : out std_logic; -- s2mm_ld_nxt_len : out std_logic; -- s2mm_wr_len : out std_logic_vector(7 downto 0); -- --------------------------------------------------------------------- -- S2MM AXI Address Channel I/O ---------------------------------------------------- m_axi_s2mm_awid : out std_logic_vector(C_M_AXI_S2MM_ID_WIDTH-1 downto 0); -- -- AXI Address Channel ID output -- -- m_axi_s2mm_awaddr : out std_logic_vector(C_M_AXI_S2MM_ADDR_WIDTH-1 downto 0); -- -- AXI Address Channel Address output -- -- m_axi_s2mm_awlen : out std_logic_vector(7 downto 0); -- -- AXI Address Channel LEN output -- -- Sized to support 256 data beat bursts -- -- m_axi_s2mm_awsize : out std_logic_vector(2 downto 0); -- -- AXI Address Channel SIZE output -- -- m_axi_s2mm_awburst : out std_logic_vector(1 downto 0); -- -- AXI Address Channel BURST output -- -- m_axi_s2mm_awprot : out std_logic_vector(2 downto 0); -- -- AXI Address Channel PROT output -- -- m_axi_s2mm_awcache : out std_logic_vector(3 downto 0); -- -- AXI Address Channel CACHE output -- m_axi_s2mm_awuser : out std_logic_vector(3 downto 0); -- -- AXI Address Channel USER output -- -- m_axi_s2mm_awvalid : out std_logic; -- -- AXI Address Channel VALID output -- -- m_axi_s2mm_awready : in std_logic; -- -- AXI Address Channel READY input -- ------------------------------------------------------------------------------------- -- Currently unsupported AXI Address Channel output signals ------- -- m_axi_s2mm__awlock : out std_logic_vector(2 downto 0); -- -- m_axi_s2mm__awcache : out std_logic_vector(4 downto 0); -- -- m_axi_s2mm__awqos : out std_logic_vector(3 downto 0); -- -- m_axi_s2mm__awregion : out std_logic_vector(3 downto 0); -- ------------------------------------------------------------------- -- S2MM AXI MMap Write Data Channel I/O -------------------------------------------------- m_axi_s2mm_wdata : Out std_logic_vector(C_M_AXI_S2MM_DATA_WIDTH-1 downto 0); -- m_axi_s2mm_wstrb : Out std_logic_vector((C_M_AXI_S2MM_DATA_WIDTH/8)-1 downto 0); -- m_axi_s2mm_wlast : Out std_logic; -- m_axi_s2mm_wvalid : Out std_logic; -- m_axi_s2mm_wready : In std_logic; -- ------------------------------------------------------------------------------------------- -- S2MM AXI MMap Write response Channel I/O ------------------------- m_axi_s2mm_bresp : In std_logic_vector(1 downto 0); -- m_axi_s2mm_bvalid : In std_logic; -- m_axi_s2mm_bready : Out std_logic; -- ---------------------------------------------------------------------- -- S2MM AXI Slave Stream Channel I/O ------------------------------------------------------- s_axis_s2mm_tdata : In std_logic_vector(C_S_AXIS_S2MM_TDATA_WIDTH-1 downto 0); -- s_axis_s2mm_tkeep : In std_logic_vector((C_S_AXIS_S2MM_TDATA_WIDTH/8)-1 downto 0); -- s_axis_s2mm_tlast : In std_logic; -- s_axis_s2mm_tvalid : In std_logic; -- s_axis_s2mm_tready : Out std_logic; -- --------------------------------------------------------------------------------------------- -- Testing Support I/O ------------------------------------------------ s2mm_dbg_sel : in std_logic_vector( 3 downto 0); -- s2mm_dbg_data : out std_logic_vector(31 downto 0) -- ------------------------------------------------------------------------ ); end entity axi_sg_datamover; architecture implementation of axi_sg_datamover is attribute DowngradeIPIdentifiedWarnings: string; attribute DowngradeIPIdentifiedWarnings of implementation : architecture is "yes"; -- Function Declarations ------------------------------------------------------------------- -- Function -- -- Function Name: funct_clip_brst_len -- -- Function Description: -- This function is used to limit the parameterized max burst -- databeats when the tranfer data width is 256 bits or greater. -- This is required to keep from crossing the 4K byte xfer -- boundary required by AXI. This process is further complicated -- by the inclusion/omission of upsizers or downsizers in the -- data path. -- ------------------------------------------------------------------- function funct_clip_brst_len (param_burst_beats : integer; mmap_transfer_bit_width : integer; stream_transfer_bit_width : integer; down_up_sizers_enabled : integer) return integer is constant FCONST_SIZERS_ENABLED : boolean := (down_up_sizers_enabled > 0); Variable fvar_max_burst_dbeats : Integer; begin -- coverage off if (FCONST_SIZERS_ENABLED) then -- use MMap dwidth for calc If (mmap_transfer_bit_width <= 128) Then -- allowed fvar_max_burst_dbeats := param_burst_beats; Elsif (mmap_transfer_bit_width <= 256) Then If (param_burst_beats <= 128) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 128; End if; Elsif (mmap_transfer_bit_width <= 512) Then If (param_burst_beats <= 64) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 64; End if; Else -- 1024 bit mmap width case If (param_burst_beats <= 32) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 32; End if; End if; else -- use stream dwidth for calc If (stream_transfer_bit_width <= 128) Then -- allowed fvar_max_burst_dbeats := param_burst_beats; Elsif (stream_transfer_bit_width <= 256) Then If (param_burst_beats <= 128) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 128; End if; Elsif (stream_transfer_bit_width <= 512) Then If (param_burst_beats <= 64) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 64; End if; Else -- 1024 bit stream width case If (param_burst_beats <= 32) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 32; End if; -- coverage on End if; end if; Return (fvar_max_burst_dbeats); end function funct_clip_brst_len; ------------------------------------------------------------------- -- Function -- -- Function Name: funct_fix_depth_16 -- -- Function Description: -- This function is used to fix the Command and Status FIFO depths to -- 16 entries when Async clocking mode is enabled. This is required -- due to the way the async_fifo_fg.vhd design in proc_common is -- implemented. ------------------------------------------------------------------- function funct_fix_depth_16 (async_clocking_mode : integer; requested_depth : integer) return integer is Variable fvar_depth_2_use : Integer; begin -- coverage off If (async_clocking_mode = 1) Then -- async mode so fix at 16 fvar_depth_2_use := 16; Elsif (requested_depth > 16) Then -- limit at 16 fvar_depth_2_use := 16; -- coverage on Else -- use requested depth fvar_depth_2_use := requested_depth; End if; Return (fvar_depth_2_use); end function funct_fix_depth_16; ------------------------------------------------------------------- -- Function -- -- Function Name: funct_get_min_btt_width -- -- Function Description: -- This function calculates the minimum required value -- for the used width of the command BTT field. -- ------------------------------------------------------------------- function funct_get_min_btt_width (max_burst_beats : integer; bytes_per_beat : integer ) return integer is Variable var_min_btt_needed : Integer; Variable var_max_bytes_per_burst : Integer; begin var_max_bytes_per_burst := max_burst_beats*bytes_per_beat; -- coverage off if (var_max_bytes_per_burst <= 16) then var_min_btt_needed := 5; elsif (var_max_bytes_per_burst <= 32) then var_min_btt_needed := 6; -- coverage on elsif (var_max_bytes_per_burst <= 64) then var_min_btt_needed := 7; -- coverage off elsif (var_max_bytes_per_burst <= 128) then var_min_btt_needed := 8; elsif (var_max_bytes_per_burst <= 256) then var_min_btt_needed := 9; elsif (var_max_bytes_per_burst <= 512) then var_min_btt_needed := 10; elsif (var_max_bytes_per_burst <= 1024) then var_min_btt_needed := 11; elsif (var_max_bytes_per_burst <= 2048) then var_min_btt_needed := 12; elsif (var_max_bytes_per_burst <= 4096) then var_min_btt_needed := 13; else -- 8K byte range var_min_btt_needed := 14; end if; -- coverage on Return (var_min_btt_needed); end function funct_get_min_btt_width; ------------------------------------------------------------------- -- Function -- -- Function Name: funct_get_xfer_bytes_per_dbeat -- -- Function Description: -- Calculates the nuber of bytes that will transfered per databeat -- on the AXI4 MMap Bus. -- ------------------------------------------------------------------- function funct_get_xfer_bytes_per_dbeat (mmap_transfer_bit_width : integer; stream_transfer_bit_width : integer; down_up_sizers_enabled : integer) return integer is Variable temp_bytes_per_dbeat : Integer := 4; begin -- coverage off if (down_up_sizers_enabled > 0) then -- down/up sizers are in use, use full mmap dwidth temp_bytes_per_dbeat := mmap_transfer_bit_width/8; -- coverage on else -- No down/up sizers so use Stream data width temp_bytes_per_dbeat := stream_transfer_bit_width/8; end if; Return (temp_bytes_per_dbeat); end function funct_get_xfer_bytes_per_dbeat; ------------------------------------------------------------------- -- Function -- -- Function Name: funct_fix_btt_used -- -- Function Description: -- THis function makes sure the BTT width used is at least the -- minimum needed. -- ------------------------------------------------------------------- function funct_fix_btt_used (requested_btt_width : integer; min_btt_width : integer) return integer is Variable var_corrected_btt_width : Integer; begin -- coverage off If (requested_btt_width < min_btt_width) Then var_corrected_btt_width := min_btt_width; -- coverage on else var_corrected_btt_width := requested_btt_width; End if; Return (var_corrected_btt_width); end function funct_fix_btt_used; ------------------------------------------------------------------- -- Constant Declarations ------------------------------------------------------------------- Constant MM2S_TAG_WIDTH : integer := 4; Constant S2MM_TAG_WIDTH : integer := 4; Constant MM2S_DOWNSIZER_ENABLED : integer := C_MM2S_INCLUDE_SF; Constant S2MM_UPSIZER_ENABLED : integer := C_S2MM_INCLUDE_SF + C_S2MM_SUPPORT_INDET_BTT; Constant MM2S_MAX_BURST_BEATS : integer := funct_clip_brst_len(C_MM2S_BURST_SIZE, C_M_AXI_MM2S_DATA_WIDTH, C_M_AXIS_MM2S_TDATA_WIDTH, MM2S_DOWNSIZER_ENABLED); Constant S2MM_MAX_BURST_BEATS : integer := funct_clip_brst_len(C_S2MM_BURST_SIZE, C_M_AXI_S2MM_DATA_WIDTH, C_S_AXIS_S2MM_TDATA_WIDTH, S2MM_UPSIZER_ENABLED); Constant MM2S_CMDSTS_FIFO_DEPTH : integer := funct_fix_depth_16(C_MM2S_STSCMD_IS_ASYNC, C_MM2S_STSCMD_FIFO_DEPTH); Constant S2MM_CMDSTS_FIFO_DEPTH : integer := funct_fix_depth_16(C_S2MM_STSCMD_IS_ASYNC, C_S2MM_STSCMD_FIFO_DEPTH); Constant MM2S_BYTES_PER_BEAT : integer := funct_get_xfer_bytes_per_dbeat(C_M_AXI_MM2S_DATA_WIDTH, C_M_AXIS_MM2S_TDATA_WIDTH, MM2S_DOWNSIZER_ENABLED); Constant MM2S_MIN_BTT_NEEDED : integer := funct_get_min_btt_width(MM2S_MAX_BURST_BEATS, MM2S_BYTES_PER_BEAT); Constant MM2S_CORRECTED_BTT_USED : integer := funct_fix_btt_used(C_MM2S_BTT_USED, MM2S_MIN_BTT_NEEDED); Constant S2MM_BYTES_PER_BEAT : integer := funct_get_xfer_bytes_per_dbeat(C_M_AXI_S2MM_DATA_WIDTH, C_S_AXIS_S2MM_TDATA_WIDTH, S2MM_UPSIZER_ENABLED); Constant S2MM_MIN_BTT_NEEDED : integer := funct_get_min_btt_width(S2MM_MAX_BURST_BEATS, S2MM_BYTES_PER_BEAT); Constant S2MM_CORRECTED_BTT_USED : integer := funct_fix_btt_used(C_S2MM_BTT_USED, S2MM_MIN_BTT_NEEDED); -- Signals signal sig_mm2s_tstrb : std_logic_vector((C_M_AXIS_MM2S_TDATA_WIDTH/8)-1 downto 0) := (others => '0'); signal sig_mm2s_sts_tstrb : std_logic_vector(0 downto 0) := (others => '0'); signal sig_s2mm_tstrb : std_logic_vector((C_S_AXIS_S2MM_TDATA_WIDTH/8)-1 downto 0) := (others => '0'); signal sig_s2mm_sts_tstrb : std_logic_vector((((C_S2MM_SUPPORT_INDET_BTT*24)+8)/8)-1 downto 0) := (others => '0'); begin --(architecture implementation) ------------------------------------------------------------- -- Conversion to tkeep for external stream connnections ------------------------------------------------------------- -- MM2S Stream Output m_axis_mm2s_tkeep <= sig_mm2s_tstrb ; -- MM2S Status Stream Output m_axis_mm2s_sts_tkeep <= sig_mm2s_sts_tstrb ; -- S2MM Stream Input sig_s2mm_tstrb <= s_axis_s2mm_tkeep ; -- S2MM Status Stream Output m_axis_s2mm_sts_tkeep <= sig_s2mm_sts_tstrb ; ------------------------------------------------------------ -- If Generate -- -- Label: GEN_MM2S_BASIC -- -- If Generate Description: -- Instantiate the MM2S Basic Wrapper -- -- ------------------------------------------------------------ GEN_MM2S_BASIC : if (C_INCLUDE_MM2S = 2) generate begin ------------------------------------------------------------ -- Instance: I_MM2S_BASIC_WRAPPER -- -- Description: -- Read Basic Wrapper Instance -- ------------------------------------------------------------ I_MM2S_BASIC_WRAPPER : entity axi_sg_v4_1.axi_sg_mm2s_basic_wrap generic map ( C_INCLUDE_MM2S => C_INCLUDE_MM2S , C_MM2S_ARID => C_M_AXI_MM2S_ARID , C_MM2S_ID_WIDTH => C_M_AXI_MM2S_ID_WIDTH , C_MM2S_ADDR_WIDTH => C_M_AXI_MM2S_ADDR_WIDTH , C_MM2S_MDATA_WIDTH => C_M_AXI_MM2S_DATA_WIDTH , C_MM2S_SDATA_WIDTH => C_M_AXIS_MM2S_TDATA_WIDTH , C_INCLUDE_MM2S_STSFIFO => C_INCLUDE_MM2S_STSFIFO , C_MM2S_STSCMD_FIFO_DEPTH => MM2S_CMDSTS_FIFO_DEPTH , C_MM2S_STSCMD_IS_ASYNC => C_MM2S_STSCMD_IS_ASYNC , C_INCLUDE_MM2S_DRE => C_INCLUDE_MM2S_DRE , C_MM2S_BURST_SIZE => MM2S_MAX_BURST_BEATS , C_MM2S_BTT_USED => MM2S_CORRECTED_BTT_USED , C_MM2S_ADDR_PIPE_DEPTH => C_MM2S_ADDR_PIPE_DEPTH , C_TAG_WIDTH => MM2S_TAG_WIDTH , C_ENABLE_MULTI_CHANNEL => C_ENABLE_MULTI_CHANNEL , C_ENABLE_EXTRA_FIELD => C_ENABLE_EXTRA_FIELD, C_FAMILY => C_FAMILY ) port map ( mm2s_aclk => m_axi_mm2s_aclk , mm2s_aresetn => m_axi_mm2s_aresetn , sg_ctl => sg_ctl , mm2s_halt => mm2s_halt , mm2s_halt_cmplt => mm2s_halt_cmplt , mm2s_err => mm2s_err , mm2s_cmdsts_awclk => m_axis_mm2s_cmdsts_aclk , mm2s_cmdsts_aresetn => m_axis_mm2s_cmdsts_aresetn , mm2s_cmd_wvalid => s_axis_mm2s_cmd_tvalid , mm2s_cmd_wready => s_axis_mm2s_cmd_tready , mm2s_cmd_wdata => s_axis_mm2s_cmd_tdata , mm2s_sts_wvalid => m_axis_mm2s_sts_tvalid , mm2s_sts_wready => m_axis_mm2s_sts_tready , mm2s_sts_wdata => m_axis_mm2s_sts_tdata , mm2s_sts_wstrb => sig_mm2s_sts_tstrb , mm2s_sts_wlast => m_axis_mm2s_sts_tlast , mm2s_allow_addr_req => mm2s_allow_addr_req , mm2s_addr_req_posted => mm2s_addr_req_posted , mm2s_rd_xfer_cmplt => mm2s_rd_xfer_cmplt , mm2s_arid => m_axi_mm2s_arid , mm2s_araddr => m_axi_mm2s_araddr , mm2s_arlen => m_axi_mm2s_arlen , mm2s_arsize => m_axi_mm2s_arsize , mm2s_arburst => m_axi_mm2s_arburst , mm2s_arprot => m_axi_mm2s_arprot , mm2s_arcache => m_axi_mm2s_arcache , mm2s_aruser => m_axi_mm2s_aruser , mm2s_arvalid => m_axi_mm2s_arvalid , mm2s_arready => m_axi_mm2s_arready , mm2s_rdata => m_axi_mm2s_rdata , mm2s_rresp => m_axi_mm2s_rresp , mm2s_rlast => m_axi_mm2s_rlast , mm2s_rvalid => m_axi_mm2s_rvalid , mm2s_rready => m_axi_mm2s_rready , mm2s_strm_wdata => m_axis_mm2s_tdata , mm2s_strm_wstrb => sig_mm2s_tstrb , mm2s_strm_wlast => m_axis_mm2s_tlast , mm2s_strm_wvalid => m_axis_mm2s_tvalid , mm2s_strm_wready => m_axis_mm2s_tready , mm2s_dbg_sel => mm2s_dbg_sel , mm2s_dbg_data => mm2s_dbg_data ); end generate GEN_MM2S_BASIC; ------------------------------------------------------------ -- If Generate -- -- Label: GEN_S2MM_BASIC -- -- If Generate Description: -- Instantiate the S2MM Basic Wrapper -- -- ------------------------------------------------------------ GEN_S2MM_BASIC : if (C_INCLUDE_S2MM = 2) generate begin ------------------------------------------------------------ -- Instance: I_S2MM_BASIC_WRAPPER -- -- Description: -- Write Basic Wrapper Instance -- ------------------------------------------------------------ I_S2MM_BASIC_WRAPPER : entity axi_sg_v4_1.axi_sg_s2mm_basic_wrap generic map ( C_INCLUDE_S2MM => C_INCLUDE_S2MM , C_S2MM_AWID => C_M_AXI_S2MM_AWID , C_S2MM_ID_WIDTH => C_M_AXI_S2MM_ID_WIDTH , C_S2MM_ADDR_WIDTH => C_M_AXI_S2MM_ADDR_WIDTH , C_S2MM_MDATA_WIDTH => C_M_AXI_S2MM_DATA_WIDTH , C_S2MM_SDATA_WIDTH => C_S_AXIS_S2MM_TDATA_WIDTH , C_INCLUDE_S2MM_STSFIFO => C_INCLUDE_S2MM_STSFIFO , C_S2MM_STSCMD_FIFO_DEPTH => S2MM_CMDSTS_FIFO_DEPTH , C_S2MM_STSCMD_IS_ASYNC => C_S2MM_STSCMD_IS_ASYNC , C_INCLUDE_S2MM_DRE => C_INCLUDE_S2MM_DRE , C_S2MM_BURST_SIZE => S2MM_MAX_BURST_BEATS , C_S2MM_ADDR_PIPE_DEPTH => C_S2MM_ADDR_PIPE_DEPTH , C_TAG_WIDTH => S2MM_TAG_WIDTH , C_ENABLE_MULTI_CHANNEL => C_ENABLE_MULTI_CHANNEL , C_ENABLE_EXTRA_FIELD => C_ENABLE_EXTRA_FIELD, C_FAMILY => C_FAMILY ) port map ( s2mm_aclk => m_axi_s2mm_aclk , s2mm_aresetn => m_axi_s2mm_aresetn , sg_ctl => sg_ctl , s2mm_halt => s2mm_halt , s2mm_halt_cmplt => s2mm_halt_cmplt , s2mm_err => s2mm_err , s2mm_cmdsts_awclk => m_axis_s2mm_cmdsts_awclk , s2mm_cmdsts_aresetn => m_axis_s2mm_cmdsts_aresetn , s2mm_cmd_wvalid => s_axis_s2mm_cmd_tvalid , s2mm_cmd_wready => s_axis_s2mm_cmd_tready , s2mm_cmd_wdata => s_axis_s2mm_cmd_tdata , s2mm_sts_wvalid => m_axis_s2mm_sts_tvalid , s2mm_sts_wready => m_axis_s2mm_sts_tready , s2mm_sts_wdata => m_axis_s2mm_sts_tdata , s2mm_sts_wstrb => sig_s2mm_sts_tstrb , s2mm_sts_wlast => m_axis_s2mm_sts_tlast , s2mm_allow_addr_req => s2mm_allow_addr_req , s2mm_addr_req_posted => s2mm_addr_req_posted , s2mm_wr_xfer_cmplt => s2mm_wr_xfer_cmplt , s2mm_ld_nxt_len => s2mm_ld_nxt_len , s2mm_wr_len => s2mm_wr_len , s2mm_awid => m_axi_s2mm_awid , s2mm_awaddr => m_axi_s2mm_awaddr , s2mm_awlen => m_axi_s2mm_awlen , s2mm_awsize => m_axi_s2mm_awsize , s2mm_awburst => m_axi_s2mm_awburst , s2mm_awprot => m_axi_s2mm_awprot , s2mm_awcache => m_axi_s2mm_awcache , s2mm_awuser => m_axi_s2mm_awuser , s2mm_awvalid => m_axi_s2mm_awvalid , s2mm_awready => m_axi_s2mm_awready , s2mm_wdata => m_axi_s2mm_wdata , s2mm_wstrb => m_axi_s2mm_wstrb , s2mm_wlast => m_axi_s2mm_wlast , s2mm_wvalid => m_axi_s2mm_wvalid , s2mm_wready => m_axi_s2mm_wready , s2mm_bresp => m_axi_s2mm_bresp , s2mm_bvalid => m_axi_s2mm_bvalid , s2mm_bready => m_axi_s2mm_bready , s2mm_strm_wdata => s_axis_s2mm_tdata , s2mm_strm_wstrb => sig_s2mm_tstrb , s2mm_strm_wlast => s_axis_s2mm_tlast , s2mm_strm_wvalid => s_axis_s2mm_tvalid , s2mm_strm_wready => s_axis_s2mm_tready , s2mm_dbg_sel => s2mm_dbg_sel , s2mm_dbg_data => s2mm_dbg_data ); end generate GEN_S2MM_BASIC; end implementation;
-- ************************************************************************* -- -- (c) Copyright 2010-2011 Xilinx, Inc. All rights reserved. -- -- This file contains confidential and proprietary information -- of Xilinx, Inc. and is protected under U.S. and -- international copyright and other intellectual property -- laws. -- -- DISCLAIMER -- This disclaimer is not a license and does not grant any -- rights to the materials distributed herewith. Except as -- otherwise provided in a valid license issued to you by -- Xilinx, and to the maximum extent permitted by applicable -- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND -- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES -- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING -- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- -- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and -- (2) Xilinx shall not be liable (whether in contract or tort, -- including negligence, or under any other theory of -- liability) for any loss or damage of any kind or nature -- related to, arising under or in connection with these -- materials, including for any direct, or any indirect, -- special, incidental, or consequential loss or damage -- (including loss of data, profits, goodwill, or any type of -- loss or damage suffered as a result of any action brought -- by a third party) even if such damage or loss was -- reasonably foreseeable or Xilinx had been advised of the -- possibility of the same. -- -- CRITICAL APPLICATIONS -- Xilinx products are not designed or intended to be fail- -- safe, or for use in any application requiring fail-safe -- performance, such as life-support or safety devices or -- systems, Class III medical devices, nuclear facilities, -- applications related to the deployment of airbags, or any -- other applications that could lead to death, personal -- injury, or severe property or environmental damage -- (individually and collectively, "Critical -- Applications"). Customer assumes the sole risk and -- liability of any use of Xilinx products in Critical -- Applications, subject only to applicable laws and -- regulations governing limitations on product liability. -- -- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS -- PART OF THIS FILE AT ALL TIMES. -- -- ************************************************************************* -- ------------------------------------------------------------------------------- -- Filename: axi_sg.vhd -- -- Description: -- Top level VHDL wrapper for the AXI DataMover -- -- -- -- -- VHDL-Standard: VHDL'93 ------------------------------------------------------------------------------- library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; library axi_sg_v4_1; use axi_sg_v4_1.axi_sg_mm2s_basic_wrap; use axi_sg_v4_1.axi_sg_s2mm_basic_wrap; ------------------------------------------------------------------------------- entity axi_sg_datamover is generic ( C_INCLUDE_MM2S : Integer range 0 to 2 := 2; -- Specifies the type of MM2S function to include -- 0 = Omit MM2S functionality -- 1 = Full MM2S Functionality -- 2 = Basic MM2S functionality C_M_AXI_MM2S_ARID : Integer range 0 to 255 := 0; -- Specifies the constant value to output on -- the ARID output port C_M_AXI_MM2S_ID_WIDTH : Integer range 1 to 8 := 4; -- Specifies the width of the MM2S ID port C_M_AXI_MM2S_ADDR_WIDTH : Integer range 32 to 64 := 32; -- Specifies the width of the MMap Read Address Channel -- Address bus C_M_AXI_MM2S_DATA_WIDTH : Integer range 32 to 1024 := 32; -- Specifies the width of the MMap Read Data Channel -- data bus C_M_AXIS_MM2S_TDATA_WIDTH : Integer range 8 to 1024 := 32; -- Specifies the width of the MM2S Master Stream Data -- Channel data bus C_INCLUDE_MM2S_STSFIFO : Integer range 0 to 1 := 1; -- Specifies if a Status FIFO is to be implemented -- 0 = Omit MM2S Status FIFO -- 1 = Include MM2S Status FIFO C_MM2S_STSCMD_FIFO_DEPTH : Integer range 1 to 16 := 4; -- Specifies the depth of the MM2S Command FIFO and the -- optional Status FIFO -- Valid values are 1,4,8,16 C_MM2S_STSCMD_IS_ASYNC : Integer range 0 to 1 := 0; -- Specifies if the Status and Command interfaces need to -- be asynchronous to the primary data path clocking -- 0 = Use same clocking as data path -- 1 = Use special Status/Command clock for the interfaces C_INCLUDE_MM2S_DRE : Integer range 0 to 1 := 1; -- Specifies if DRE is to be included in the MM2S function -- 0 = Omit DRE -- 1 = Include DRE C_MM2S_BURST_SIZE : Integer range 16 to 256 := 16; -- Specifies the max number of databeats to use for MMap -- burst transfers by the MM2S function C_MM2S_BTT_USED : Integer range 8 to 23 := 16; -- Specifies the number of bits used from the BTT field -- of the input Command Word of the MM2S Command Interface C_MM2S_ADDR_PIPE_DEPTH : Integer range 1 to 30 := 3; -- This parameter specifies the depth of the MM2S internal -- child command queues in the Read Address Controller and -- the Read Data Controller. Increasing this value will -- allow more Read Addresses to be issued to the AXI4 Read -- Address Channel before receipt of the associated read -- data on the Read Data Channel. C_MM2S_INCLUDE_SF : Integer range 0 to 1 := 1 ; -- This parameter specifies the inclusion/omission of the -- MM2S (Read) Store and Forward function -- 0 = Omit MM2S Store and Forward -- 1 = Include MM2S Store and Forward C_INCLUDE_S2MM : Integer range 0 to 4 := 2; -- Specifies the type of S2MM function to include -- 0 = Omit S2MM functionality -- 1 = Full S2MM Functionality -- 2 = Basic S2MM functionality C_M_AXI_S2MM_AWID : Integer range 0 to 255 := 1; -- Specifies the constant value to output on -- the ARID output port C_M_AXI_S2MM_ID_WIDTH : Integer range 1 to 8 := 4; -- Specifies the width of the S2MM ID port C_M_AXI_S2MM_ADDR_WIDTH : Integer range 32 to 64 := 32; -- Specifies the width of the MMap Read Address Channel -- Address bus C_M_AXI_S2MM_DATA_WIDTH : Integer range 32 to 1024 := 32; -- Specifies the width of the MMap Read Data Channel -- data bus C_S_AXIS_S2MM_TDATA_WIDTH : Integer range 8 to 1024 := 32; -- Specifies the width of the S2MM Master Stream Data -- Channel data bus C_INCLUDE_S2MM_STSFIFO : Integer range 0 to 1 := 1; -- Specifies if a Status FIFO is to be implemented -- 0 = Omit S2MM Status FIFO -- 1 = Include S2MM Status FIFO C_S2MM_STSCMD_FIFO_DEPTH : Integer range 1 to 16 := 4; -- Specifies the depth of the S2MM Command FIFO and the -- optional Status FIFO -- Valid values are 1,4,8,16 C_S2MM_STSCMD_IS_ASYNC : Integer range 0 to 1 := 0; -- Specifies if the Status and Command interfaces need to -- be asynchronous to the primary data path clocking -- 0 = Use same clocking as data path -- 1 = Use special Status/Command clock for the interfaces C_INCLUDE_S2MM_DRE : Integer range 0 to 1 := 1; -- Specifies if DRE is to be included in the S2MM function -- 0 = Omit DRE -- 1 = Include DRE C_S2MM_BURST_SIZE : Integer range 16 to 256 := 16; -- Specifies the max number of databeats to use for MMap -- burst transfers by the S2MM function C_S2MM_BTT_USED : Integer range 8 to 23 := 16; -- Specifies the number of bits used from the BTT field -- of the input Command Word of the S2MM Command Interface C_S2MM_SUPPORT_INDET_BTT : Integer range 0 to 1 := 0; -- Specifies if support for indeterminate packet lengths -- are to be received on the input Stream interface -- 0 = Omit support (User MUST transfer the exact number of -- bytes on the Stream interface as specified in the BTT -- field of the Corresponding DataMover Command) -- 1 = Include support for indeterminate packet lengths -- This causes FIFOs to be added and "Store and Forward" -- behavior of the S2MM function C_S2MM_ADDR_PIPE_DEPTH : Integer range 1 to 30 := 3; -- This parameter specifies the depth of the S2MM internal -- address pipeline queues in the Write Address Controller -- and the Write Data Controller. Increasing this value will -- allow more Write Addresses to be issued to the AXI4 Write -- Address Channel before transmission of the associated -- write data on the Write Data Channel. C_S2MM_INCLUDE_SF : Integer range 0 to 1 := 1 ; -- This parameter specifies the inclusion/omission of the -- S2MM (Write) Store and Forward function -- 0 = Omit S2MM Store and Forward -- 1 = Include S2MM Store and Forward C_ENABLE_MULTI_CHANNEL : integer range 0 to 1 := 1; C_ENABLE_EXTRA_FIELD : integer range 0 to 1 := 0; C_FAMILY : String := "virtex7" -- Specifies the target FPGA family type ); port ( -- MM2S Primary Clock input ---------------------------------- m_axi_mm2s_aclk : in std_logic; -- -- Primary synchronization clock for the Master side -- -- interface and internal logic. It is also used -- -- for the User interface synchronization when -- -- C_STSCMD_IS_ASYNC = 0. -- -- -- MM2S Primary Reset input -- m_axi_mm2s_aresetn : in std_logic; -- -- Reset used for the internal master logic -- -------------------------------------------------------------- sg_ctl : in std_logic_vector (7 downto 0) ; -- MM2S Halt request input control -------------------- mm2s_halt : in std_logic; -- -- Active high soft shutdown request -- -- -- MM2S Halt Complete status flag -- mm2s_halt_cmplt : Out std_logic; -- -- Active high soft shutdown complete status -- ------------------------------------------------------- -- Error discrete output ------------------------- mm2s_err : Out std_logic; -- -- Composite Error indication -- -------------------------------------------------- -- Memory Map to Stream Command FIFO and Status FIFO I/O --------- m_axis_mm2s_cmdsts_aclk : in std_logic; -- -- Secondary Clock input for async CMD/Status interface -- -- m_axis_mm2s_cmdsts_aresetn : in std_logic; -- -- Secondary Reset input for async CMD/Status interface -- ------------------------------------------------------------------ -- User Command Interface Ports (AXI Stream) ------------------------------------------------- s_axis_mm2s_cmd_tvalid : in std_logic; -- s_axis_mm2s_cmd_tready : out std_logic; -- s_axis_mm2s_cmd_tdata : in std_logic_vector(((1+C_ENABLE_MULTI_CHANNEL)*C_M_AXI_MM2S_ADDR_WIDTH+40)-1 downto 0); -- ---------------------------------------------------------------------------------------------- -- User Status Interface Ports (AXI Stream) ------------------------ m_axis_mm2s_sts_tvalid : out std_logic; -- m_axis_mm2s_sts_tready : in std_logic; -- m_axis_mm2s_sts_tdata : out std_logic_vector(7 downto 0); -- m_axis_mm2s_sts_tkeep : out std_logic_vector(0 downto 0); -- m_axis_mm2s_sts_tlast : out std_logic; -- -------------------------------------------------------------------- -- Address Posting contols ----------------------- mm2s_allow_addr_req : in std_logic; -- mm2s_addr_req_posted : out std_logic; -- mm2s_rd_xfer_cmplt : out std_logic; -- -------------------------------------------------- -- MM2S AXI Address Channel I/O -------------------------------------------------- m_axi_mm2s_arid : out std_logic_vector(C_M_AXI_MM2S_ID_WIDTH-1 downto 0); -- -- AXI Address Channel ID output -- -- m_axi_mm2s_araddr : out std_logic_vector(C_M_AXI_MM2S_ADDR_WIDTH-1 downto 0); -- -- AXI Address Channel Address output -- -- m_axi_mm2s_arlen : out std_logic_vector(7 downto 0); -- -- AXI Address Channel LEN output -- -- Sized to support 256 data beat bursts -- -- m_axi_mm2s_arsize : out std_logic_vector(2 downto 0); -- -- AXI Address Channel SIZE output -- -- m_axi_mm2s_arburst : out std_logic_vector(1 downto 0); -- -- AXI Address Channel BURST output -- -- m_axi_mm2s_arprot : out std_logic_vector(2 downto 0); -- -- AXI Address Channel PROT output -- -- m_axi_mm2s_arcache : out std_logic_vector(3 downto 0); -- -- AXI Address Channel CACHE output -- m_axi_mm2s_aruser : out std_logic_vector(3 downto 0); -- -- AXI Address Channel USER output -- -- m_axi_mm2s_arvalid : out std_logic; -- -- AXI Address Channel VALID output -- -- m_axi_mm2s_arready : in std_logic; -- -- AXI Address Channel READY input -- ----------------------------------------------------------------------------------- -- Currently unsupported AXI Address Channel output signals ------- -- m_axi_mm2s_alock : out std_logic_vector(2 downto 0); -- -- m_axi_mm2s_acache : out std_logic_vector(4 downto 0); -- -- m_axi_mm2s_aqos : out std_logic_vector(3 downto 0); -- -- m_axi_mm2s_aregion : out std_logic_vector(3 downto 0); -- ------------------------------------------------------------------- -- MM2S AXI MMap Read Data Channel I/O ------------------------------------------------ m_axi_mm2s_rdata : In std_logic_vector(C_M_AXI_MM2S_DATA_WIDTH-1 downto 0); -- m_axi_mm2s_rresp : In std_logic_vector(1 downto 0); -- m_axi_mm2s_rlast : In std_logic; -- m_axi_mm2s_rvalid : In std_logic; -- m_axi_mm2s_rready : Out std_logic; -- ---------------------------------------------------------------------------------------- -- MM2S AXI Master Stream Channel I/O ------------------------------------------------------- m_axis_mm2s_tdata : Out std_logic_vector(C_M_AXIS_MM2S_TDATA_WIDTH-1 downto 0); -- m_axis_mm2s_tkeep : Out std_logic_vector((C_M_AXIS_MM2S_TDATA_WIDTH/8)-1 downto 0); -- m_axis_mm2s_tlast : Out std_logic; -- m_axis_mm2s_tvalid : Out std_logic; -- m_axis_mm2s_tready : In std_logic; -- ---------------------------------------------------------------------------------------------- -- Testing Support I/O -------------------------------------------------------- mm2s_dbg_sel : in std_logic_vector( 3 downto 0); -- mm2s_dbg_data : out std_logic_vector(31 downto 0) ; -- ------------------------------------------------------------------------------- -- S2MM Primary Clock input --------------------------------- m_axi_s2mm_aclk : in std_logic; -- -- Primary synchronization clock for the Master side -- -- interface and internal logic. It is also used -- -- for the User interface synchronization when -- -- C_STSCMD_IS_ASYNC = 0. -- -- -- S2MM Primary Reset input -- m_axi_s2mm_aresetn : in std_logic; -- -- Reset used for the internal master logic -- ------------------------------------------------------------- -- S2MM Halt request input control ------------------ s2mm_halt : in std_logic; -- -- Active high soft shutdown request -- -- -- S2MM Halt Complete status flag -- s2mm_halt_cmplt : out std_logic; -- -- Active high soft shutdown complete status -- ----------------------------------------------------- -- S2MM Error discrete output ------------------ s2mm_err : Out std_logic; -- -- Composite Error indication -- ------------------------------------------------ -- Memory Map to Stream Command FIFO and Status FIFO I/O ----------------- m_axis_s2mm_cmdsts_awclk : in std_logic; -- -- Secondary Clock input for async CMD/Status interface -- -- m_axis_s2mm_cmdsts_aresetn : in std_logic; -- -- Secondary Reset input for async CMD/Status interface -- -------------------------------------------------------------------------- -- User Command Interface Ports (AXI Stream) -------------------------------------------------- s_axis_s2mm_cmd_tvalid : in std_logic; -- s_axis_s2mm_cmd_tready : out std_logic; -- s_axis_s2mm_cmd_tdata : in std_logic_vector(((1+C_ENABLE_MULTI_CHANNEL)*C_M_AXI_S2MM_ADDR_WIDTH+40)-1 downto 0); -- ----------------------------------------------------------------------------------------------- -- User Status Interface Ports (AXI Stream) ----------------------------------------------------------- m_axis_s2mm_sts_tvalid : out std_logic; -- m_axis_s2mm_sts_tready : in std_logic; -- m_axis_s2mm_sts_tdata : out std_logic_vector(((C_S2MM_SUPPORT_INDET_BTT*24)+8)-1 downto 0); -- m_axis_s2mm_sts_tkeep : out std_logic_vector((((C_S2MM_SUPPORT_INDET_BTT*24)+8)/8)-1 downto 0); -- m_axis_s2mm_sts_tlast : out std_logic; -- ------------------------------------------------------------------------------------------------------- -- Address posting controls ----------------------------------------- s2mm_allow_addr_req : in std_logic; -- s2mm_addr_req_posted : out std_logic; -- s2mm_wr_xfer_cmplt : out std_logic; -- s2mm_ld_nxt_len : out std_logic; -- s2mm_wr_len : out std_logic_vector(7 downto 0); -- --------------------------------------------------------------------- -- S2MM AXI Address Channel I/O ---------------------------------------------------- m_axi_s2mm_awid : out std_logic_vector(C_M_AXI_S2MM_ID_WIDTH-1 downto 0); -- -- AXI Address Channel ID output -- -- m_axi_s2mm_awaddr : out std_logic_vector(C_M_AXI_S2MM_ADDR_WIDTH-1 downto 0); -- -- AXI Address Channel Address output -- -- m_axi_s2mm_awlen : out std_logic_vector(7 downto 0); -- -- AXI Address Channel LEN output -- -- Sized to support 256 data beat bursts -- -- m_axi_s2mm_awsize : out std_logic_vector(2 downto 0); -- -- AXI Address Channel SIZE output -- -- m_axi_s2mm_awburst : out std_logic_vector(1 downto 0); -- -- AXI Address Channel BURST output -- -- m_axi_s2mm_awprot : out std_logic_vector(2 downto 0); -- -- AXI Address Channel PROT output -- -- m_axi_s2mm_awcache : out std_logic_vector(3 downto 0); -- -- AXI Address Channel CACHE output -- m_axi_s2mm_awuser : out std_logic_vector(3 downto 0); -- -- AXI Address Channel USER output -- -- m_axi_s2mm_awvalid : out std_logic; -- -- AXI Address Channel VALID output -- -- m_axi_s2mm_awready : in std_logic; -- -- AXI Address Channel READY input -- ------------------------------------------------------------------------------------- -- Currently unsupported AXI Address Channel output signals ------- -- m_axi_s2mm__awlock : out std_logic_vector(2 downto 0); -- -- m_axi_s2mm__awcache : out std_logic_vector(4 downto 0); -- -- m_axi_s2mm__awqos : out std_logic_vector(3 downto 0); -- -- m_axi_s2mm__awregion : out std_logic_vector(3 downto 0); -- ------------------------------------------------------------------- -- S2MM AXI MMap Write Data Channel I/O -------------------------------------------------- m_axi_s2mm_wdata : Out std_logic_vector(C_M_AXI_S2MM_DATA_WIDTH-1 downto 0); -- m_axi_s2mm_wstrb : Out std_logic_vector((C_M_AXI_S2MM_DATA_WIDTH/8)-1 downto 0); -- m_axi_s2mm_wlast : Out std_logic; -- m_axi_s2mm_wvalid : Out std_logic; -- m_axi_s2mm_wready : In std_logic; -- ------------------------------------------------------------------------------------------- -- S2MM AXI MMap Write response Channel I/O ------------------------- m_axi_s2mm_bresp : In std_logic_vector(1 downto 0); -- m_axi_s2mm_bvalid : In std_logic; -- m_axi_s2mm_bready : Out std_logic; -- ---------------------------------------------------------------------- -- S2MM AXI Slave Stream Channel I/O ------------------------------------------------------- s_axis_s2mm_tdata : In std_logic_vector(C_S_AXIS_S2MM_TDATA_WIDTH-1 downto 0); -- s_axis_s2mm_tkeep : In std_logic_vector((C_S_AXIS_S2MM_TDATA_WIDTH/8)-1 downto 0); -- s_axis_s2mm_tlast : In std_logic; -- s_axis_s2mm_tvalid : In std_logic; -- s_axis_s2mm_tready : Out std_logic; -- --------------------------------------------------------------------------------------------- -- Testing Support I/O ------------------------------------------------ s2mm_dbg_sel : in std_logic_vector( 3 downto 0); -- s2mm_dbg_data : out std_logic_vector(31 downto 0) -- ------------------------------------------------------------------------ ); end entity axi_sg_datamover; architecture implementation of axi_sg_datamover is attribute DowngradeIPIdentifiedWarnings: string; attribute DowngradeIPIdentifiedWarnings of implementation : architecture is "yes"; -- Function Declarations ------------------------------------------------------------------- -- Function -- -- Function Name: funct_clip_brst_len -- -- Function Description: -- This function is used to limit the parameterized max burst -- databeats when the tranfer data width is 256 bits or greater. -- This is required to keep from crossing the 4K byte xfer -- boundary required by AXI. This process is further complicated -- by the inclusion/omission of upsizers or downsizers in the -- data path. -- ------------------------------------------------------------------- function funct_clip_brst_len (param_burst_beats : integer; mmap_transfer_bit_width : integer; stream_transfer_bit_width : integer; down_up_sizers_enabled : integer) return integer is constant FCONST_SIZERS_ENABLED : boolean := (down_up_sizers_enabled > 0); Variable fvar_max_burst_dbeats : Integer; begin -- coverage off if (FCONST_SIZERS_ENABLED) then -- use MMap dwidth for calc If (mmap_transfer_bit_width <= 128) Then -- allowed fvar_max_burst_dbeats := param_burst_beats; Elsif (mmap_transfer_bit_width <= 256) Then If (param_burst_beats <= 128) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 128; End if; Elsif (mmap_transfer_bit_width <= 512) Then If (param_burst_beats <= 64) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 64; End if; Else -- 1024 bit mmap width case If (param_burst_beats <= 32) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 32; End if; End if; else -- use stream dwidth for calc If (stream_transfer_bit_width <= 128) Then -- allowed fvar_max_burst_dbeats := param_burst_beats; Elsif (stream_transfer_bit_width <= 256) Then If (param_burst_beats <= 128) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 128; End if; Elsif (stream_transfer_bit_width <= 512) Then If (param_burst_beats <= 64) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 64; End if; Else -- 1024 bit stream width case If (param_burst_beats <= 32) Then fvar_max_burst_dbeats := param_burst_beats; Else fvar_max_burst_dbeats := 32; End if; -- coverage on End if; end if; Return (fvar_max_burst_dbeats); end function funct_clip_brst_len; ------------------------------------------------------------------- -- Function -- -- Function Name: funct_fix_depth_16 -- -- Function Description: -- This function is used to fix the Command and Status FIFO depths to -- 16 entries when Async clocking mode is enabled. This is required -- due to the way the async_fifo_fg.vhd design in proc_common is -- implemented. ------------------------------------------------------------------- function funct_fix_depth_16 (async_clocking_mode : integer; requested_depth : integer) return integer is Variable fvar_depth_2_use : Integer; begin -- coverage off If (async_clocking_mode = 1) Then -- async mode so fix at 16 fvar_depth_2_use := 16; Elsif (requested_depth > 16) Then -- limit at 16 fvar_depth_2_use := 16; -- coverage on Else -- use requested depth fvar_depth_2_use := requested_depth; End if; Return (fvar_depth_2_use); end function funct_fix_depth_16; ------------------------------------------------------------------- -- Function -- -- Function Name: funct_get_min_btt_width -- -- Function Description: -- This function calculates the minimum required value -- for the used width of the command BTT field. -- ------------------------------------------------------------------- function funct_get_min_btt_width (max_burst_beats : integer; bytes_per_beat : integer ) return integer is Variable var_min_btt_needed : Integer; Variable var_max_bytes_per_burst : Integer; begin var_max_bytes_per_burst := max_burst_beats*bytes_per_beat; -- coverage off if (var_max_bytes_per_burst <= 16) then var_min_btt_needed := 5; elsif (var_max_bytes_per_burst <= 32) then var_min_btt_needed := 6; -- coverage on elsif (var_max_bytes_per_burst <= 64) then var_min_btt_needed := 7; -- coverage off elsif (var_max_bytes_per_burst <= 128) then var_min_btt_needed := 8; elsif (var_max_bytes_per_burst <= 256) then var_min_btt_needed := 9; elsif (var_max_bytes_per_burst <= 512) then var_min_btt_needed := 10; elsif (var_max_bytes_per_burst <= 1024) then var_min_btt_needed := 11; elsif (var_max_bytes_per_burst <= 2048) then var_min_btt_needed := 12; elsif (var_max_bytes_per_burst <= 4096) then var_min_btt_needed := 13; else -- 8K byte range var_min_btt_needed := 14; end if; -- coverage on Return (var_min_btt_needed); end function funct_get_min_btt_width; ------------------------------------------------------------------- -- Function -- -- Function Name: funct_get_xfer_bytes_per_dbeat -- -- Function Description: -- Calculates the nuber of bytes that will transfered per databeat -- on the AXI4 MMap Bus. -- ------------------------------------------------------------------- function funct_get_xfer_bytes_per_dbeat (mmap_transfer_bit_width : integer; stream_transfer_bit_width : integer; down_up_sizers_enabled : integer) return integer is Variable temp_bytes_per_dbeat : Integer := 4; begin -- coverage off if (down_up_sizers_enabled > 0) then -- down/up sizers are in use, use full mmap dwidth temp_bytes_per_dbeat := mmap_transfer_bit_width/8; -- coverage on else -- No down/up sizers so use Stream data width temp_bytes_per_dbeat := stream_transfer_bit_width/8; end if; Return (temp_bytes_per_dbeat); end function funct_get_xfer_bytes_per_dbeat; ------------------------------------------------------------------- -- Function -- -- Function Name: funct_fix_btt_used -- -- Function Description: -- THis function makes sure the BTT width used is at least the -- minimum needed. -- ------------------------------------------------------------------- function funct_fix_btt_used (requested_btt_width : integer; min_btt_width : integer) return integer is Variable var_corrected_btt_width : Integer; begin -- coverage off If (requested_btt_width < min_btt_width) Then var_corrected_btt_width := min_btt_width; -- coverage on else var_corrected_btt_width := requested_btt_width; End if; Return (var_corrected_btt_width); end function funct_fix_btt_used; ------------------------------------------------------------------- -- Constant Declarations ------------------------------------------------------------------- Constant MM2S_TAG_WIDTH : integer := 4; Constant S2MM_TAG_WIDTH : integer := 4; Constant MM2S_DOWNSIZER_ENABLED : integer := C_MM2S_INCLUDE_SF; Constant S2MM_UPSIZER_ENABLED : integer := C_S2MM_INCLUDE_SF + C_S2MM_SUPPORT_INDET_BTT; Constant MM2S_MAX_BURST_BEATS : integer := funct_clip_brst_len(C_MM2S_BURST_SIZE, C_M_AXI_MM2S_DATA_WIDTH, C_M_AXIS_MM2S_TDATA_WIDTH, MM2S_DOWNSIZER_ENABLED); Constant S2MM_MAX_BURST_BEATS : integer := funct_clip_brst_len(C_S2MM_BURST_SIZE, C_M_AXI_S2MM_DATA_WIDTH, C_S_AXIS_S2MM_TDATA_WIDTH, S2MM_UPSIZER_ENABLED); Constant MM2S_CMDSTS_FIFO_DEPTH : integer := funct_fix_depth_16(C_MM2S_STSCMD_IS_ASYNC, C_MM2S_STSCMD_FIFO_DEPTH); Constant S2MM_CMDSTS_FIFO_DEPTH : integer := funct_fix_depth_16(C_S2MM_STSCMD_IS_ASYNC, C_S2MM_STSCMD_FIFO_DEPTH); Constant MM2S_BYTES_PER_BEAT : integer := funct_get_xfer_bytes_per_dbeat(C_M_AXI_MM2S_DATA_WIDTH, C_M_AXIS_MM2S_TDATA_WIDTH, MM2S_DOWNSIZER_ENABLED); Constant MM2S_MIN_BTT_NEEDED : integer := funct_get_min_btt_width(MM2S_MAX_BURST_BEATS, MM2S_BYTES_PER_BEAT); Constant MM2S_CORRECTED_BTT_USED : integer := funct_fix_btt_used(C_MM2S_BTT_USED, MM2S_MIN_BTT_NEEDED); Constant S2MM_BYTES_PER_BEAT : integer := funct_get_xfer_bytes_per_dbeat(C_M_AXI_S2MM_DATA_WIDTH, C_S_AXIS_S2MM_TDATA_WIDTH, S2MM_UPSIZER_ENABLED); Constant S2MM_MIN_BTT_NEEDED : integer := funct_get_min_btt_width(S2MM_MAX_BURST_BEATS, S2MM_BYTES_PER_BEAT); Constant S2MM_CORRECTED_BTT_USED : integer := funct_fix_btt_used(C_S2MM_BTT_USED, S2MM_MIN_BTT_NEEDED); -- Signals signal sig_mm2s_tstrb : std_logic_vector((C_M_AXIS_MM2S_TDATA_WIDTH/8)-1 downto 0) := (others => '0'); signal sig_mm2s_sts_tstrb : std_logic_vector(0 downto 0) := (others => '0'); signal sig_s2mm_tstrb : std_logic_vector((C_S_AXIS_S2MM_TDATA_WIDTH/8)-1 downto 0) := (others => '0'); signal sig_s2mm_sts_tstrb : std_logic_vector((((C_S2MM_SUPPORT_INDET_BTT*24)+8)/8)-1 downto 0) := (others => '0'); begin --(architecture implementation) ------------------------------------------------------------- -- Conversion to tkeep for external stream connnections ------------------------------------------------------------- -- MM2S Stream Output m_axis_mm2s_tkeep <= sig_mm2s_tstrb ; -- MM2S Status Stream Output m_axis_mm2s_sts_tkeep <= sig_mm2s_sts_tstrb ; -- S2MM Stream Input sig_s2mm_tstrb <= s_axis_s2mm_tkeep ; -- S2MM Status Stream Output m_axis_s2mm_sts_tkeep <= sig_s2mm_sts_tstrb ; ------------------------------------------------------------ -- If Generate -- -- Label: GEN_MM2S_BASIC -- -- If Generate Description: -- Instantiate the MM2S Basic Wrapper -- -- ------------------------------------------------------------ GEN_MM2S_BASIC : if (C_INCLUDE_MM2S = 2) generate begin ------------------------------------------------------------ -- Instance: I_MM2S_BASIC_WRAPPER -- -- Description: -- Read Basic Wrapper Instance -- ------------------------------------------------------------ I_MM2S_BASIC_WRAPPER : entity axi_sg_v4_1.axi_sg_mm2s_basic_wrap generic map ( C_INCLUDE_MM2S => C_INCLUDE_MM2S , C_MM2S_ARID => C_M_AXI_MM2S_ARID , C_MM2S_ID_WIDTH => C_M_AXI_MM2S_ID_WIDTH , C_MM2S_ADDR_WIDTH => C_M_AXI_MM2S_ADDR_WIDTH , C_MM2S_MDATA_WIDTH => C_M_AXI_MM2S_DATA_WIDTH , C_MM2S_SDATA_WIDTH => C_M_AXIS_MM2S_TDATA_WIDTH , C_INCLUDE_MM2S_STSFIFO => C_INCLUDE_MM2S_STSFIFO , C_MM2S_STSCMD_FIFO_DEPTH => MM2S_CMDSTS_FIFO_DEPTH , C_MM2S_STSCMD_IS_ASYNC => C_MM2S_STSCMD_IS_ASYNC , C_INCLUDE_MM2S_DRE => C_INCLUDE_MM2S_DRE , C_MM2S_BURST_SIZE => MM2S_MAX_BURST_BEATS , C_MM2S_BTT_USED => MM2S_CORRECTED_BTT_USED , C_MM2S_ADDR_PIPE_DEPTH => C_MM2S_ADDR_PIPE_DEPTH , C_TAG_WIDTH => MM2S_TAG_WIDTH , C_ENABLE_MULTI_CHANNEL => C_ENABLE_MULTI_CHANNEL , C_ENABLE_EXTRA_FIELD => C_ENABLE_EXTRA_FIELD, C_FAMILY => C_FAMILY ) port map ( mm2s_aclk => m_axi_mm2s_aclk , mm2s_aresetn => m_axi_mm2s_aresetn , sg_ctl => sg_ctl , mm2s_halt => mm2s_halt , mm2s_halt_cmplt => mm2s_halt_cmplt , mm2s_err => mm2s_err , mm2s_cmdsts_awclk => m_axis_mm2s_cmdsts_aclk , mm2s_cmdsts_aresetn => m_axis_mm2s_cmdsts_aresetn , mm2s_cmd_wvalid => s_axis_mm2s_cmd_tvalid , mm2s_cmd_wready => s_axis_mm2s_cmd_tready , mm2s_cmd_wdata => s_axis_mm2s_cmd_tdata , mm2s_sts_wvalid => m_axis_mm2s_sts_tvalid , mm2s_sts_wready => m_axis_mm2s_sts_tready , mm2s_sts_wdata => m_axis_mm2s_sts_tdata , mm2s_sts_wstrb => sig_mm2s_sts_tstrb , mm2s_sts_wlast => m_axis_mm2s_sts_tlast , mm2s_allow_addr_req => mm2s_allow_addr_req , mm2s_addr_req_posted => mm2s_addr_req_posted , mm2s_rd_xfer_cmplt => mm2s_rd_xfer_cmplt , mm2s_arid => m_axi_mm2s_arid , mm2s_araddr => m_axi_mm2s_araddr , mm2s_arlen => m_axi_mm2s_arlen , mm2s_arsize => m_axi_mm2s_arsize , mm2s_arburst => m_axi_mm2s_arburst , mm2s_arprot => m_axi_mm2s_arprot , mm2s_arcache => m_axi_mm2s_arcache , mm2s_aruser => m_axi_mm2s_aruser , mm2s_arvalid => m_axi_mm2s_arvalid , mm2s_arready => m_axi_mm2s_arready , mm2s_rdata => m_axi_mm2s_rdata , mm2s_rresp => m_axi_mm2s_rresp , mm2s_rlast => m_axi_mm2s_rlast , mm2s_rvalid => m_axi_mm2s_rvalid , mm2s_rready => m_axi_mm2s_rready , mm2s_strm_wdata => m_axis_mm2s_tdata , mm2s_strm_wstrb => sig_mm2s_tstrb , mm2s_strm_wlast => m_axis_mm2s_tlast , mm2s_strm_wvalid => m_axis_mm2s_tvalid , mm2s_strm_wready => m_axis_mm2s_tready , mm2s_dbg_sel => mm2s_dbg_sel , mm2s_dbg_data => mm2s_dbg_data ); end generate GEN_MM2S_BASIC; ------------------------------------------------------------ -- If Generate -- -- Label: GEN_S2MM_BASIC -- -- If Generate Description: -- Instantiate the S2MM Basic Wrapper -- -- ------------------------------------------------------------ GEN_S2MM_BASIC : if (C_INCLUDE_S2MM = 2) generate begin ------------------------------------------------------------ -- Instance: I_S2MM_BASIC_WRAPPER -- -- Description: -- Write Basic Wrapper Instance -- ------------------------------------------------------------ I_S2MM_BASIC_WRAPPER : entity axi_sg_v4_1.axi_sg_s2mm_basic_wrap generic map ( C_INCLUDE_S2MM => C_INCLUDE_S2MM , C_S2MM_AWID => C_M_AXI_S2MM_AWID , C_S2MM_ID_WIDTH => C_M_AXI_S2MM_ID_WIDTH , C_S2MM_ADDR_WIDTH => C_M_AXI_S2MM_ADDR_WIDTH , C_S2MM_MDATA_WIDTH => C_M_AXI_S2MM_DATA_WIDTH , C_S2MM_SDATA_WIDTH => C_S_AXIS_S2MM_TDATA_WIDTH , C_INCLUDE_S2MM_STSFIFO => C_INCLUDE_S2MM_STSFIFO , C_S2MM_STSCMD_FIFO_DEPTH => S2MM_CMDSTS_FIFO_DEPTH , C_S2MM_STSCMD_IS_ASYNC => C_S2MM_STSCMD_IS_ASYNC , C_INCLUDE_S2MM_DRE => C_INCLUDE_S2MM_DRE , C_S2MM_BURST_SIZE => S2MM_MAX_BURST_BEATS , C_S2MM_ADDR_PIPE_DEPTH => C_S2MM_ADDR_PIPE_DEPTH , C_TAG_WIDTH => S2MM_TAG_WIDTH , C_ENABLE_MULTI_CHANNEL => C_ENABLE_MULTI_CHANNEL , C_ENABLE_EXTRA_FIELD => C_ENABLE_EXTRA_FIELD, C_FAMILY => C_FAMILY ) port map ( s2mm_aclk => m_axi_s2mm_aclk , s2mm_aresetn => m_axi_s2mm_aresetn , sg_ctl => sg_ctl , s2mm_halt => s2mm_halt , s2mm_halt_cmplt => s2mm_halt_cmplt , s2mm_err => s2mm_err , s2mm_cmdsts_awclk => m_axis_s2mm_cmdsts_awclk , s2mm_cmdsts_aresetn => m_axis_s2mm_cmdsts_aresetn , s2mm_cmd_wvalid => s_axis_s2mm_cmd_tvalid , s2mm_cmd_wready => s_axis_s2mm_cmd_tready , s2mm_cmd_wdata => s_axis_s2mm_cmd_tdata , s2mm_sts_wvalid => m_axis_s2mm_sts_tvalid , s2mm_sts_wready => m_axis_s2mm_sts_tready , s2mm_sts_wdata => m_axis_s2mm_sts_tdata , s2mm_sts_wstrb => sig_s2mm_sts_tstrb , s2mm_sts_wlast => m_axis_s2mm_sts_tlast , s2mm_allow_addr_req => s2mm_allow_addr_req , s2mm_addr_req_posted => s2mm_addr_req_posted , s2mm_wr_xfer_cmplt => s2mm_wr_xfer_cmplt , s2mm_ld_nxt_len => s2mm_ld_nxt_len , s2mm_wr_len => s2mm_wr_len , s2mm_awid => m_axi_s2mm_awid , s2mm_awaddr => m_axi_s2mm_awaddr , s2mm_awlen => m_axi_s2mm_awlen , s2mm_awsize => m_axi_s2mm_awsize , s2mm_awburst => m_axi_s2mm_awburst , s2mm_awprot => m_axi_s2mm_awprot , s2mm_awcache => m_axi_s2mm_awcache , s2mm_awuser => m_axi_s2mm_awuser , s2mm_awvalid => m_axi_s2mm_awvalid , s2mm_awready => m_axi_s2mm_awready , s2mm_wdata => m_axi_s2mm_wdata , s2mm_wstrb => m_axi_s2mm_wstrb , s2mm_wlast => m_axi_s2mm_wlast , s2mm_wvalid => m_axi_s2mm_wvalid , s2mm_wready => m_axi_s2mm_wready , s2mm_bresp => m_axi_s2mm_bresp , s2mm_bvalid => m_axi_s2mm_bvalid , s2mm_bready => m_axi_s2mm_bready , s2mm_strm_wdata => s_axis_s2mm_tdata , s2mm_strm_wstrb => sig_s2mm_tstrb , s2mm_strm_wlast => s_axis_s2mm_tlast , s2mm_strm_wvalid => s_axis_s2mm_tvalid , s2mm_strm_wready => s_axis_s2mm_tready , s2mm_dbg_sel => s2mm_dbg_sel , s2mm_dbg_data => s2mm_dbg_data ); end generate GEN_S2MM_BASIC; end implementation;