------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
--
|
--
|
-- The Program memory controller.
|
-- The Program memory controller.
|
--
|
--
|
-- $Id: t400_pmem_ctrl.vhd,v 1.3 2006-05-28 15:32:40 arniml Exp $
|
-- $Id: t400_pmem_ctrl.vhd 179 2009-04-01 19:48:38Z arniml $
|
--
|
--
|
-- Copyright (c) 2006 Arnim Laeuger (arniml@opencores.org)
|
-- Copyright (c) 2006 Arnim Laeuger (arniml@opencores.org)
|
--
|
--
|
-- All rights reserved
|
-- All rights reserved
|
--
|
--
|
-- Redistribution and use in source and synthezised forms, with or without
|
-- Redistribution and use in source and synthezised forms, with or without
|
-- modification, are permitted provided that the following conditions are met:
|
-- modification, are permitted provided that the following conditions are met:
|
--
|
--
|
-- Redistributions of source code must retain the above copyright notice,
|
-- Redistributions of source code must retain the above copyright notice,
|
-- this list of conditions and the following disclaimer.
|
-- this list of conditions and the following disclaimer.
|
--
|
--
|
-- Redistributions in synthesized form must reproduce the above copyright
|
-- Redistributions in synthesized form must reproduce the above copyright
|
-- notice, this list of conditions and the following disclaimer in the
|
-- notice, this list of conditions and the following disclaimer in the
|
-- documentation and/or other materials provided with the distribution.
|
-- documentation and/or other materials provided with the distribution.
|
--
|
--
|
-- Neither the name of the author nor the names of other contributors may
|
-- Neither the name of the author nor the names of other contributors may
|
-- be used to endorse or promote products derived from this software without
|
-- be used to endorse or promote products derived from this software without
|
-- specific prior written permission.
|
-- specific prior written permission.
|
--
|
--
|
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
|
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
|
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
-- 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
|
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
-- POSSIBILITY OF SUCH DAMAGE.
|
-- POSSIBILITY OF SUCH DAMAGE.
|
--
|
--
|
-- Please report bugs to the author, but before you do so, please
|
-- Please report bugs to the author, but before you do so, please
|
-- make sure that this is not a derivative work and that
|
-- make sure that this is not a derivative work and that
|
-- you have the latest version of this file.
|
-- you have the latest version of this file.
|
--
|
--
|
-- The latest version of this file can be found at:
|
-- The latest version of this file can be found at:
|
-- http://www.opencores.org/cvsweb.shtml/t400/
|
-- http://www.opencores.org/cvsweb.shtml/t400/
|
--
|
--
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
|
|
library ieee;
|
library ieee;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
|
|
use work.t400_opt_pack.all;
|
use work.t400_opt_pack.all;
|
use work.t400_pack.all;
|
use work.t400_pack.all;
|
|
|
entity t400_pmem_ctrl is
|
entity t400_pmem_ctrl is
|
|
|
generic (
|
generic (
|
opt_type_g : integer := t400_opt_type_420_c
|
opt_type_g : integer := t400_opt_type_420_c
|
);
|
);
|
port (
|
port (
|
-- System Interface -------------------------------------------------------
|
-- System Interface -------------------------------------------------------
|
ck_i : in std_logic;
|
ck_i : in std_logic;
|
ck_en_i : in boolean;
|
ck_en_i : in boolean;
|
por_i : in boolean;
|
por_i : in boolean;
|
res_i : in boolean;
|
res_i : in boolean;
|
a_i : in dw_t;
|
a_i : in dw_t;
|
m_i : in dw_t;
|
m_i : in dw_t;
|
-- Control Interface ------------------------------------------------------
|
-- Control Interface ------------------------------------------------------
|
op_i : in pc_op_t;
|
op_i : in pc_op_t;
|
dec_data_i : in dec_data_t;
|
dec_data_i : in dec_data_t;
|
-- Stack Interface --------------------------------------------------------
|
-- Stack Interface --------------------------------------------------------
|
pc_o : out pc_t;
|
pc_o : out pc_t;
|
pc_i : in pc_t;
|
pc_i : in pc_t;
|
-- Program Memory Interface -----------------------------------------------
|
-- Program Memory Interface -----------------------------------------------
|
pm_addr_o : out pc_t
|
pm_addr_o : out pc_t
|
);
|
);
|
|
|
end t400_pmem_ctrl;
|
end t400_pmem_ctrl;
|
|
|
|
|
library ieee;
|
library ieee;
|
use ieee.numeric_std.all;
|
use ieee.numeric_std.all;
|
|
|
-- pragma translate_off
|
-- pragma translate_off
|
use work.tb_pack.tb_pc_s;
|
use work.tb_pack.tb_pc_s;
|
-- pragma translate_on
|
-- pragma translate_on
|
|
|
architecture rtl of t400_pmem_ctrl is
|
architecture rtl of t400_pmem_ctrl is
|
|
|
signal pc_q : pc_t;
|
signal pc_q : pc_t;
|
signal last_pc_s : pc_t;
|
signal last_pc_s : pc_t;
|
|
|
begin
|
begin
|
|
|
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
-- Determine last program counter address
|
-- Determine last program counter address
|
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
last_pc_s <= to_unsigned(16#1ff#, pc_t'length)
|
last_pc_s <= to_unsigned(16#1ff#, pc_t'length)
|
when opt_type_g = t400_opt_type_410_c else
|
when opt_type_g = t400_opt_type_410_c else
|
to_unsigned(16#3ff#, pc_t'length);
|
to_unsigned(16#3ff#, pc_t'length);
|
|
|
|
|
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
-- Process pc
|
-- Process pc
|
--
|
--
|
-- Purpose:
|
-- Purpose:
|
-- Implements the program counter.
|
-- Implements the program counter.
|
--
|
--
|
pc: process (ck_i, por_i)
|
pc: process (ck_i, por_i)
|
begin
|
begin
|
if por_i then
|
if por_i then
|
pc_q <= (others => '0');
|
pc_q <= (others => '0');
|
|
|
elsif ck_i'event and ck_i = '1' then
|
elsif ck_i'event and ck_i = '1' then
|
if res_i then
|
if res_i then
|
-- synchronous reset upon external reset event
|
-- synchronous reset upon external reset event
|
pc_q <= (others => '0');
|
pc_q <= (others => '0');
|
|
|
elsif ck_en_i then
|
elsif ck_en_i then
|
-- determine PC update mode
|
-- determine PC update mode
|
case op_i is
|
case op_i is
|
-- increment program counter ----------------------------------------
|
-- increment program counter ----------------------------------------
|
when PC_INC_PC =>
|
when PC_INC_PC =>
|
if pc_q = last_pc_s then
|
if pc_q = last_pc_s then
|
-- roll over
|
-- roll over
|
pc_q <= (others => '0');
|
pc_q <= (others => '0');
|
else
|
else
|
pc_q <= pc_q + 1;
|
pc_q <= pc_q + 1;
|
end if;
|
end if;
|
|
|
-- Load lower 6 bits from program memory data -----------------------
|
-- Load lower 6 bits from program memory data -----------------------
|
when PC_LOAD_6 =>
|
when PC_LOAD_6 =>
|
pc_q(5 downto 0) <= unsigned(dec_data_i(5 downto 0));
|
pc_q(5 downto 0) <= unsigned(dec_data_i(5 downto 0));
|
|
|
-- Load lower 7 bits from program memory data -----------------------
|
-- Load lower 7 bits from program memory data -----------------------
|
when PC_LOAD_7 =>
|
when PC_LOAD_7 =>
|
pc_q(6 downto 0) <= unsigned(dec_data_i(6 downto 0));
|
pc_q(6 downto 0) <= unsigned(dec_data_i(6 downto 0));
|
|
|
-- Load lower 8 bits from program memory data -----------------------
|
-- Load lower 8 bits from program memory data -----------------------
|
when PC_LOAD_8 =>
|
when PC_LOAD_8 =>
|
pc_q(7 downto 0) <= unsigned(dec_data_i(7 downto 0));
|
pc_q(7 downto 0) <= unsigned(dec_data_i(7 downto 0));
|
|
|
-- Load all bits from program memory data ---------------------------
|
-- Load all bits from program memory data ---------------------------
|
when PC_LOAD =>
|
when PC_LOAD =>
|
pc_q <= unsigned(dec_data_i);
|
pc_q <= unsigned(dec_data_i);
|
|
|
-- pop program counter from stack -----------------------------------
|
-- pop program counter from stack -----------------------------------
|
when PC_POP =>
|
when PC_POP =>
|
pc_q <= pc_i;
|
pc_q <= pc_i;
|
|
|
-- update program counter for LQID instruction ----------------------
|
-- update program counter for LQID instruction ----------------------
|
when PC_LOAD_A_M =>
|
when PC_LOAD_A_M =>
|
pc_q(7 downto 4) <= unsigned(a_i);
|
pc_q(7 downto 4) <= unsigned(a_i);
|
pc_q(3 downto 0) <= unsigned(m_i);
|
pc_q(3 downto 0) <= unsigned(m_i);
|
|
|
-- load interrupt vector --------------------------------------------
|
-- load interrupt vector --------------------------------------------
|
when PC_INT =>
|
when PC_INT =>
|
if opt_type_g = t400_opt_type_420_c then
|
if opt_type_g = t400_opt_type_420_c then
|
-- load address 0x100, i.e. skip first instruction at
|
-- load address 0x100, i.e. skip first instruction at
|
-- vector address 0x0ff which has to be a NOP :-)
|
-- vector address 0x0ff which has to be a NOP :-)
|
pc_q <= (8 => '1', others => '0');
|
pc_q <= (8 => '1', others => '0');
|
end if;
|
end if;
|
|
|
when others =>
|
when others =>
|
null;
|
null;
|
end case;
|
end case;
|
end if;
|
end if;
|
end if;
|
end if;
|
end process pc;
|
end process pc;
|
--
|
--
|
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
|
|
|
|
-- pragma translate_off
|
-- pragma translate_off
|
-- instrument interrupt testbench
|
-- instrument interrupt testbench
|
tb_pc_s <= pc_q;
|
tb_pc_s <= pc_q;
|
-- pragma translate_on
|
-- pragma translate_on
|
|
|
|
|
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
-- Output mapping
|
-- Output mapping
|
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
pc_o <= pc_q;
|
pc_o <= pc_q;
|
pm_addr_o <= pc_q;
|
pm_addr_o <= pc_q;
|
|
|
end rtl;
|
end rtl;
|
|
|
|
|
-------------------------------------------------------------------------------
|
|
-- File History:
|
|
--
|
|
-- $Log: not supported by cvs2svn $
|
|
-- Revision 1.2 2006/05/27 19:16:52 arniml
|
|
-- interrupt functionality added
|
|
--
|
|
-- Revision 1.1.1.1 2006/05/06 01:56:45 arniml
|
|
-- import from local CVS repository, LOC_CVS_0_1
|
|
--
|
|
-------------------------------------------------------------------------------
|
|
|
|
No newline at end of file
|
No newline at end of file
|