📄 cachemem.vhd
字号:
-------------------------------------------------------------------------------- This file is a part of the GRLIB VHDL IP LIBRARY-- Copyright (C) 2003, Gaisler Research---- 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: cachemem-- File: cachemem.vhd-- Author: Jiri Gaisler - Gaisler Research-- Description: Contains ram cells for both instruction and data caches------------------------------------------------------------------------------library ieee;use ieee.std_logic_1164.all;library gaisler;use gaisler.libiu.all;use gaisler.libcache.all;use gaisler.mmuconfig.all;library grlib;use grlib.stdlib.all;library techmap;use techmap.gencomp.all;entity cachemem is generic ( tech : integer range 0 to NTECH := 0; icen : integer range 0 to 1 := 0; irepl : integer range 0 to 2 := 0; isets : integer range 1 to 4 := 1; ilinesize : integer range 4 to 8 := 4; isetsize : integer range 1 to 256 := 1; isetlock : integer range 0 to 1 := 0; dcen : integer range 0 to 1 := 0; drepl : integer range 0 to 2 := 0; dsets : integer range 1 to 4 := 1; dlinesize : integer range 4 to 8 := 4; dsetsize : integer range 1 to 256 := 1; dsetlock : integer range 0 to 1 := 0; dsnoop : integer range 0 to 6 := 0; ilram : integer range 0 to 1 := 0; ilramsize : integer range 1 to 512 := 1; dlram : integer range 0 to 1 := 0; dlramsize : integer range 1 to 512 := 1; mmuen : integer range 0 to 1 := 0 ); port ( clk : in std_ulogic; crami : in cram_in_type; cramo : out cram_out_type; sclk : in std_ulogic );end;architecture rtl of cachemem is constant DSNOOPMMU : boolean := (dsnoop > 3); constant ILINE_BITS : integer := log2(ilinesize); constant IOFFSET_BITS : integer := 8 +log2(isetsize) - ILINE_BITS; constant DLINE_BITS : integer := log2(dlinesize); constant DOFFSET_BITS : integer := 8 +log2(dsetsize) - DLINE_BITS; constant ITAG_BITS : integer := TAG_HIGH - IOFFSET_BITS - ILINE_BITS - 2 + ilinesize + 1; constant DTAG_BITS : integer := TAG_HIGH - DOFFSET_BITS - DLINE_BITS - 2 + dlinesize + 1; constant IPTAG_BITS : integer := TAG_HIGH - IOFFSET_BITS - ILINE_BITS - 2 + 1; constant DPTAG_BITS : integer := TAG_HIGH - DOFFSET_BITS - DLINE_BITS - 2 + 1; constant ILRR_BIT : integer := creplalg_tbl(irepl); constant DLRR_BIT : integer := creplalg_tbl(drepl); constant ITAG_LOW : integer := IOFFSET_BITS + ILINE_BITS + 2; constant DTAG_LOW : integer := DOFFSET_BITS + DLINE_BITS + 2; constant ICLOCK_BIT : integer := isetlock; constant DCLOCK_BIT : integer := dsetlock; constant ILRAM_BITS : integer := log2(ilramsize) + 10; constant DLRAM_BITS : integer := log2(dlramsize) + 10; constant ITDEPTH : natural := 2**IOFFSET_BITS; constant DTDEPTH : natural := 2**DOFFSET_BITS; constant MMUCTX_BITS : natural := 8*mmuen; -- i/d tag layout -- +-----+----------+--------+-----+-------+ -- | LRR | LOCK_BIT | MMUCTX | TAG | VALID | -- +-----+----------+--------+-----+-------+ constant ITWIDTH : natural := ITAG_BITS + ILRR_BIT + isetlock + MMUCTX_BITS; constant DTWIDTH : natural := DTAG_BITS + DLRR_BIT + dsetlock + MMUCTX_BITS; constant IDWIDTH : natural := 32; constant DDWIDTH : natural := 32; subtype dtdatain_vector is std_logic_vector(DTWIDTH downto 0); type dtdatain_type is array (0 to MAXSETS-1) of dtdatain_vector; subtype itdatain_vector is std_logic_vector(ITWIDTH downto 0); type itdatain_type is array (0 to MAXSETS-1) of itdatain_vector; subtype itdataout_vector is std_logic_vector(ITWIDTH-1 downto 0); type itdataout_type is array (0 to MAXSETS-1) of itdataout_vector; subtype iddataout_vector is std_logic_vector(IDWIDTH -1 downto 0); type iddataout_type is array (0 to MAXSETS-1) of iddataout_vector; subtype dtdataout_vector is std_logic_vector(DTWIDTH-1 downto 0); type dtdataout_type is array (0 to MAXSETS-1) of dtdataout_vector; subtype dddataout_vector is std_logic_vector(DDWIDTH -1 downto 0); type dddataout_type is array (0 to MAXSETS-1) of dddataout_vector; signal itaddr : std_logic_vector(IOFFSET_BITS + ILINE_BITS -1 downto ILINE_BITS); signal idaddr : std_logic_vector(IOFFSET_BITS + ILINE_BITS -1 downto 0); signal ildaddr : std_logic_vector(ILRAM_BITS-3 downto 0); signal itdatain : itdatain_type; signal itdataout : itdataout_type; signal iddatain : std_logic_vector(IDWIDTH -1 downto 0); signal iddataout : iddataout_type; signal ildataout : std_logic_vector(31 downto 0); signal itenable : std_ulogic; signal idenable : std_ulogic; signal itwrite : std_logic_vector(0 to MAXSETS-1); signal idwrite : std_logic_vector(0 to MAXSETS-1); signal dtaddr : std_logic_vector(DOFFSET_BITS + DLINE_BITS -1 downto DLINE_BITS); signal dtaddr2 : std_logic_vector(DOFFSET_BITS + DLINE_BITS -1 downto DLINE_BITS); signal ddaddr : std_logic_vector(DOFFSET_BITS + DLINE_BITS -1 downto 0); signal ldaddr : std_logic_vector(DLRAM_BITS-1 downto 2); signal dtdatain : dtdatain_type; signal dtdatain2 : dtdatain_type; signal dtdatain3 : dtdatain_type; signal dtdatainu : dtdatain_type; signal dtdataout : dtdataout_type; signal dtdataout2: dtdataout_type; signal dtdataout3: dtdataout_type; signal dddatain : cdatatype; signal dddataout : dddataout_type; signal lddatain, ldataout : std_logic_vector(31 downto 0); signal dtenable : std_logic_vector(0 to MAXSETS-1); signal dtenable2 : std_logic_vector(0 to MAXSETS-1); signal ddenable : std_logic_vector(0 to MAXSETS-1); signal dtwrite : std_logic_vector(0 to MAXSETS-1); signal dtwrite2 : std_logic_vector(0 to MAXSETS-1); signal dtwrite3 : std_logic_vector(0 to MAXSETS-1); signal ddwrite : std_logic_vector(0 to MAXSETS-1); signal vcc, gnd : std_ulogic;begin vcc <= '1'; gnd <= '0'; itaddr <= crami.icramin.address(IOFFSET_BITS + ILINE_BITS -1 downto ILINE_BITS); idaddr <= crami.icramin.address(IOFFSET_BITS + ILINE_BITS -1 downto 0); ildaddr <= crami.icramin.address(ILRAM_BITS-3 downto 0); itinsel : process(crami, dtdataout2, dtdataout3) variable viddatain : std_logic_vector(IDWIDTH -1 downto 0); variable vdddatain : cdatatype; variable vitdatain : itdatain_type; variable vdtdatain : dtdatain_type; variable vdtdatain2 : dtdatain_type; variable vdtdatain3 : dtdatain_type; variable vdtdatainu : dtdatain_type; begin viddatain := (others => '0'); vdddatain := (others => (others => '0')); viddatain(31 downto 0) := crami.icramin.data; for i in 0 to DSETS-1 loop vdtdatain(i) := (others => '0'); if mmuen = 1 then vdtdatain(i)((DTWIDTH - (DLRR_BIT+dsetlock+1)) downto (DTWIDTH - (DLRR_BIT+dsetlock+M_CTX_SZ))) := crami.dcramin.ctx(i); end if; vdtdatain(i)(DTWIDTH-(DCLOCK_BIT + dsetlock)) := crami.dcramin.tag(i)(CTAG_LOCKPOS); vdtdatain(i)(DTWIDTH-DLRR_BIT) := crami.dcramin.tag(i)(CTAG_LRRPOS); vdtdatain(i)(DTAG_BITS-1 downto 0) := crami.dcramin.tag(i)(TAG_HIGH downto DTAG_LOW) & crami.dcramin.tag(i)(dlinesize-1 downto 0); if (DSETS > 1) and (crami.dcramin.flush = '1') then vdtdatain(i)(dlinesize+1 downto dlinesize) := conv_std_logic_vector(i,2); end if; end loop; vdtdatain2 := (others => (others => '0')); for i in 0 to DSETS-1 loop if (DSETS > 1) then vdtdatain2(i)(dlinesize+1 downto dlinesize) := conv_std_logic_vector(i,2); end if; end loop; vdddatain := crami.dcramin.data; vdtdatainu := (others => (others => '0')); vdtdatain3 := (others => (others => '0')); for i in 0 to DSETS-1 loop vdtdatain3(i) := (others => '0'); vdtdatain3(i)(DTAG_BITS-1 downto DTAG_BITS-DPTAG_BITS) := crami.dcramin.ptag(i)(TAG_HIGH downto DTAG_LOW); end loop; for i in 0 to ISETS-1 loop vitdatain(i) := (others => '0'); if mmuen = 1 then vitdatain(i)((ITWIDTH - (ILRR_BIT+isetlock+1)) downto (ITWIDTH - (ILRR_BIT+isetlock+M_CTX_SZ))) := crami.icramin.ctx; end if; vitdatain(i)(ITWIDTH-(ICLOCK_BIT + isetlock)) := crami.icramin.tag(i)(CTAG_LOCKPOS); vitdatain(i)(ITWIDTH-ILRR_BIT) := crami.icramin.tag(i)(CTAG_LRRPOS); vitdatain(i)(ITAG_BITS-1 downto 0) := crami.icramin.tag(i)(TAG_HIGH downto ITAG_LOW) & crami.icramin.tag(i)(ilinesize-1 downto 0); if (ISETS > 1) and (crami.icramin.flush = '1') then vitdatain(i)(ilinesize+1 downto ilinesize) := conv_std_logic_vector(i,2); end if;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -