⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmu_icache.vhd

📁 leon3 source code 虽然gaisler网站上有下载
💻 VHD
📖 第 1 页 / 共 2 页
字号:
--------------------------------------------------------------------------------  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:      icache-- File:        icache.vhd-- Author:      Jiri Gaisler, Konrad Eisele - Gaisler Research-- Description: This unit implements the instruction cache controller.------------------------------------------------------------------------------  library ieee;use ieee.std_logic_1164.all;library grlib;use grlib.amba.all;use grlib.stdlib.all;library gaisler;use gaisler.libiu.all;use gaisler.libcache.all;use gaisler.mmuconfig.all;use gaisler.mmuiface.all;entity mmu_icache is  generic (    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  );  port (    rst : in  std_logic;    clk : in  std_logic;    ici : in  icache_in_type;    ico : out icache_out_type;    dci : in  dcache_in_type;    dco : in  dcache_out_type;    mcii : out memory_ic_in_type;    mcio : in  memory_ic_out_type;    icrami : out icram_in_type;    icramo : in  icram_out_type;    fpuholdn : in  std_logic;    mmudci : in  mmudc_in_type;    mmuici : out mmuic_in_type;    mmuico : in mmuic_out_type);end; architecture rtl of mmu_icache isconstant ILINE_BITS   : integer := log2(ilinesize);constant IOFFSET_BITS : integer := 8 +log2(isetsize) - ILINE_BITS;constant TAG_LOW    : integer := IOFFSET_BITS + ILINE_BITS + 2;constant OFFSET_HIGH: integer := TAG_LOW - 1;constant OFFSET_LOW : integer := ILINE_BITS + 2;constant LINE_HIGH  : integer := OFFSET_LOW - 1;constant LINE_LOW   : integer := 2;constant LRR_BIT    : integer := TAG_HIGH + 1;constant PCLOW : integer  := 2;constant ILINE_SIZE : integer := ilinesize;constant ICLOCK_BIT : integer := isetlock;constant ICREPLACE : integer range 0 to 2  := irepl;constant lline : std_logic_vector((ILINE_BITS -1) downto 0) := (others=>'1');constant SETBITS : integer := log2x(ISETS); constant ILRUBITS  : integer := lru_table(ISETS);subtype lru_type is std_logic_vector(ILRUBITS-1 downto 0);type lru_array  is array (0 to 2**IOFFSET_BITS-1) of lru_type;  -- lru registerstype rdatatype is (itag, idata, memory);	-- sources during cache readtype lru_table_vector_type is array(0 to 3) of std_logic_vector(4 downto 0);type lru_table_type is array (0 to 2**IOFFSET_BITS-1) of lru_table_vector_type;subtype lock_type is std_logic_vector(0 to ISETS-1);type par_type is array (0 to ISETS-1) of std_logic_vector(1 downto 0);function lru_set (lru : lru_type; lock : lock_type) return std_logic_vector isvariable xlru : std_logic_vector(4 downto 0);variable set  : std_logic_vector(SETBITS-1 downto 0);variable xset : std_logic_vector(1 downto 0);variable unlocked : integer range 0 to ISETS-1;begin  set := (others => '0'); xlru := (others => '0'); xset := (others => '0');  xlru(ILRUBITS-1 downto 0) := lru;     if isetlock = 1 then     unlocked := ISETS-1;    for i in ISETS-1 downto 0 loop      if lock(i) = '0' then unlocked := i; end if;    end loop;  end if;      case ISETS is  when 2 =>    if isetlock = 1 then      if lock(0) = '1' then xset(0) := '1'; else xset(0) := xlru(0); end if;    else xset(0) := xlru(0); end if;  when 3 =>    if isetlock = 1 then      xset := conv_std_logic_vector(lru3_repl_table(conv_integer(xlru)) (unlocked), 2);    else      xset := conv_std_logic_vector(lru3_repl_table(conv_integer(xlru)) (0), 2);    end if;  when 4 =>    if isetlock = 1 then      xset := conv_std_logic_vector(lru4_repl_table(conv_integer(xlru)) (unlocked), 2);    else      xset := conv_std_logic_vector(lru4_repl_table(conv_integer(xlru)) (0), 2);    end if;  when others =>   end case;  set := xset(SETBITS-1 downto 0);  return(set);end;function lru_calc (lru : lru_type; set : integer) return lru_type isvariable new_lru : lru_type;variable xnew_lru: std_logic_vector(4 downto 0);variable xlru : std_logic_vector(4 downto 0);begin  new_lru := (others => '0'); xnew_lru := (others => '0');  xlru := (others => '0'); xlru(ILRUBITS-1 downto 0) := lru;  case ISETS is  when 2 =>     if set = 0 then xnew_lru(0) := '1'; else xnew_lru(0) := '0'; end if;  when 3 =>    xnew_lru(2 downto 0) := lru_3set_table(conv_integer(lru))(set);   when 4 =>     xnew_lru(4 downto 0) := lru_4set_table(conv_integer(lru))(set);  when others =>   end case;  new_lru := xnew_lru(ILRUBITS-1 downto 0);  return(new_lru);end;type istatetype is (idle, trans, streaming, stop);type icache_control_type is record			-- all registers  req, burst, holdn : std_logic;  overrun       : std_logic;			--   underrun      : std_logic;			--   istate 	: istatetype;	  	        -- FSM  waddress      : std_logic_vector(31 downto PCLOW); -- write address buffer  vaddress      : std_logic_vector(31 downto PCLOW); -- virtual address buffer  valid         : std_logic_vector(ILINE_SIZE-1 downto 0); -- valid bits  hit           : std_logic;  su 		: std_logic;  flush		: std_logic;				-- flush in progress  flush2	: std_logic;				-- flush in progress  flush3	: std_logic;				-- flush in progress  faddr 	: std_logic_vector(IOFFSET_BITS - 1 downto 0);	-- flush address  diagrdy  	: std_logic;  rndcnt        : std_logic_vector(log2x(ISETS)-1 downto 0); -- replace counter  lrr           : std_logic;  setrepl       : std_logic_vector(log2x(ISETS)-1 downto 0); -- set to replace  diagset       : std_logic_vector(log2x(ISETS)-1 downto 0);  lock          : std_logic;  pflush        : std_logic;  pflushr       : std_logic;  pflushaddr    : std_logic_vector(VA_I_U downto VA_I_D);  pflushtyp     : std_logic;  cache         : std_logic;  trans_op      : std_logic;end record;type lru_reg_type is record  write : std_logic;  waddr : std_logic_vector(IOFFSET_BITS-1 downto 0);  set   : std_logic_vector(SETBITS-1 downto 0); --integer range 0 to ISETS-1;  lru   : lru_array;end record;signal r, c : icache_control_type;	-- r is registers, c is combinationalsignal rl, cl : lru_reg_type;           -- rl is registers, cl is combinationalconstant icfg : std_logic_vector(31 downto 0) := 	cache_cfg(irepl, isets, ilinesize, isetsize, isetlock, 0, 0, 1, 0, 1);begin  ictrl : process(rst, r, rl, mcio, ici, dci, dco, icramo, fpuholdn, mmuico, mmudci)  variable rdatasel : rdatatype;  variable twrite, diagen, dwrite : std_logic;  variable taddr : std_logic_vector(TAG_HIGH  downto LINE_LOW); -- tag address  variable wtag : std_logic_vector(TAG_HIGH downto TAG_LOW); -- write tag value  variable ddatain : std_logic_vector(31 downto 0);  variable rdata : cdatatype;  variable diagdata : std_logic_vector(31 downto 0);  variable vmaskraw, vmask : std_logic_vector((ILINE_SIZE -1) downto 0);  variable xaddr_inc : std_logic_vector((ILINE_BITS -1) downto 0);  variable lastline, nlastline, nnlastline : std_logic;  variable enable : std_logic;  variable error : std_logic;  variable whit, hit, valid : std_logic;  variable cacheon  : std_logic;  variable v : icache_control_type;  variable branch  : std_logic;  variable eholdn  : std_logic;  variable mds, write  : std_logic;  variable tparerr, dparerr  : std_logic_vector(0 to ISETS-1);  variable set     : integer range 0 to MAXSETS-1;  variable setrepl : std_logic_vector(log2x(ISETS)-1 downto 0); -- set to replace  variable ctwrite, cdwrite, validv : std_logic_vector(0 to MAXSETS-1);  variable wlrr : std_logic;  variable vl : lru_reg_type;  variable vdiagset, rdiagset : integer range 0 to ISETS-1;  variable lock : std_logic_vector(0 to ISETS-1);  variable wlock, sidle : std_logic;  variable tag : cdatatype;  variable pftag : std_logic_vector(31 downto 2);  variable mmuici_trans_op : std_logic;  variable mmuici_su : std_logic;  begin-- init local variables    v := r; vl := rl; vl.write := '0'; vl.set := r.setrepl;    vl.waddr := r.waddress(OFFSET_HIGH downto OFFSET_LOW);    mds := '1'; dwrite := '0'; twrite := '0'; diagen := '0'; error := '0';    write := mcio.ready; v.diagrdy := '0'; v.holdn := '1';     v.flush3 := r.flush2; sidle := '0';    cacheon := dco.icdiag.cctrl.ics(0) and not r.flush;    enable := '1'; branch := '0';    eholdn := dco.hold and fpuholdn;    rdatasel := idata;	-- read data from cache as default    ddatain := mcio.data;	-- load full word from memory    --if M_EN and (mmudci.mmctrl1.e = '1') then wtag := r.vaddress(TAG_HIGH downto TAG_LOW);    --else wtag := r.waddress(TAG_HIGH downto TAG_LOW); end if;    wtag := r.vaddress(TAG_HIGH downto TAG_LOW);    wlrr := r.lrr; wlock := r.lock;        tparerr := (others => '0'); dparerr := (others => '0');    set := 0; ctwrite := (others => '0'); cdwrite := (others => '0');    vdiagset := 0; rdiagset := 0; lock := (others => '0');    pftag := (others => '0');    v.trans_op := r.trans_op and (not mmuico.grant);    mmuici_trans_op := r.trans_op;            mmuici_su := ici.su;              -- random replacement counter    if ISETS > 1 then      if conv_integer(r.rndcnt) = (ISETS - 1) then v.rndcnt := (others => '0');      else v.rndcnt := r.rndcnt + 1; end if;    end if;-- generate lock bits    if ICLOCK_BIT = 1 then       for i in 0 to ISETS-1 loop lock(i) := icramo.tag(i)(CTAG_LOCKPOS); end loop;    end if;      -- generate cache hit and valid bits        hit := '0';    for i in ISETS-1 downto 0 loop      if (icramo.tag(i)(TAG_HIGH downto TAG_LOW) = ici.fpc(TAG_HIGH downto TAG_LOW))        and ((icramo.ctx(i) = mmudci.mmctrl1.ctx) or (mmudci.mmctrl1.e = '0'))      then hit := not r.flush; set := i; end if;      validv(i) := genmux(ici.fpc(LINE_HIGH downto LINE_LOW), 		          icramo.tag(i)(ilinesize -1 downto 0));    end loop;    if ici.fpc(LINE_HIGH downto LINE_LOW) = lline then lastline := '1';    else lastline := '0'; end if;    if r.waddress(LINE_HIGH downto LINE_LOW) = lline((ILINE_BITS -1) downto 0) then      nlastline := '1';    else nlastline := '0'; end if;    if r.waddress(LINE_HIGH downto LINE_LOW+1) = lline((ILINE_BITS -1) downto 1) then      nnlastline := '1';    else nnlastline := '0'; end if;    valid := validv(set);    xaddr_inc := r.waddress(LINE_HIGH downto LINE_LOW) + 1;    if mcio.ready = '1' then       v.waddress(LINE_HIGH downto LINE_LOW) := xaddr_inc;    end if;    xaddr_inc := r.vaddress(LINE_HIGH downto LINE_LOW) + 1;    if mcio.ready = '1' then       v.vaddress(LINE_HIGH downto LINE_LOW) := xaddr_inc;    end if;        taddr := ici.rpc(TAG_HIGH downto LINE_LOW);-- main Icache state machine    case r.istate is    when idle =>	-- main state and cache hit      v.valid := icramo.tag(set)(ilinesize-1 downto 0);      v.hit := hit; v.su := ici.su; sidle := '1';      if eholdn  = '0' then         taddr := ici.fpc(TAG_HIGH downto LINE_LOW);      else taddr := ici.rpc(TAG_HIGH downto LINE_LOW); end if;      v.burst := dco.icdiag.cctrl.burst and not lastline;      if (eholdn and not ici.inull ) = '1' then	if not (cacheon and hit and valid) = '1' then  	  v.istate := streaming;            v.holdn := '0'; v.overrun := '1';                    if ((mmudci.mmctrl1.e) = '1') then 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -