1 ---------------------------------------------------------------------------------
5 -- Description: the Memory (MEM) control unit for
6 -- the TUD MB-Lite implementation
8 -- Author: Huib Lincklaen Arriens
9 -- Delft University of Technology
10 -- Faculty EEMCS, Department ME&CE, Circuits and Systems
11 -- Date: October, 2010
13 -- Modified: December, 2010: handle S_FSL Data Input (Huib)
15 --------------------------------------------------------------------------------
19 USE IEEE.std_logic_1164.all;
23 --------------------------------------------------------------------------------
25 --------------------------------------------------------------------------------
27 EX2MEM_i : IN EX2MEM_Type;
29 DMEMB_i : IN DMEMB2CORE_Type;
30 DMEMB_o : OUT CORE2DMEMB_Type;
32 MEM_REG_i : IN MEM_REG_Type;
33 MEM_REG_o : OUT MEM_REG_Type;
35 MEM_WRB_o : OUT WRB_Type;
36 MEM2CTRL_o : OUT MEM2CTRL_Type
41 --------------------------------------------------------------------------------
42 ARCHITECTURE rtl OF mem IS
43 --------------------------------------------------------------------------------
47 -- writeback in case of reads from the data memory bus:
48 -- delay wrb-ctrl signals (see core_ctrl) to stay in sync
49 -- with synchronous dmem data output
50 -- Following are only the unconditional pass-through signals. More are in the p_mem process.
51 MEM_REG_o.wrb_Action <= EX2MEM_i.wrb_Action;
52 MEM_REG_o.exeq_result <= EX2MEM_i.exeq_result;
53 MEM_REG_o.byte_Enable <= EX2MEM_i.byte_Enable;
54 MEM_REG_o.wrix_rD <= EX2MEM_i.wrix_rD;
56 MEM_WRB_o.wrb_Action <= MEM_REG_i.wrb_Action;
57 MEM_WRB_o.wrix_rD <= MEM_REG_i.wrix_rD;
58 -- also signal 'slow memory decices' and interrupts from devices
59 MEM2CTRL_o.clken <= DMEMB_i.clken;
60 MEM2CTRL_o.int <= DMEMB_i.int;
61 -- pass byte_select signal (NOTE: BIG ENDIAN)
62 DMEMB_o.bSel <= EX2MEM_i.byte_Enable;
65 PROCESS (EX2MEM_i, DMEMB_i, MEM_REG_i)
66 VARIABLE exeq_data_v : STD_LOGIC_VECTOR (31 DOWNTO 0);
67 VARIABLE dmem_data_v : STD_LOGIC_VECTOR (31 DOWNTO 0);
71 -- always align Big Endian input data from memory(-bus)
72 CASE MEM_REG_i.byte_Enable IS
73 WHEN "1000" => dmem_data_v := C_24_ZEROS & DMEMB_i.data(31 DOWNTO 24);
74 WHEN "0100" => dmem_data_v := C_24_ZEROS & DMEMB_i.data(23 DOWNTO 16);
75 WHEN "0010" => dmem_data_v := C_24_ZEROS & DMEMB_i.data(15 DOWNTO 8);
76 WHEN "0001" => dmem_data_v := C_24_ZEROS & DMEMB_i.data( 7 DOWNTO 0);
77 WHEN "1100" => dmem_data_v := C_16_ZEROS & DMEMB_i.data(31 DOWNTO 16);
78 WHEN "0011" => dmem_data_v := C_16_ZEROS & DMEMB_i.data(15 DOWNTO 0);
79 WHEN OTHERS => dmem_data_v := DMEMB_i.data;
83 -- DMEMB_o.addr <= EX2MEM_i.exeq_result;
84 CASE EX2MEM_i.mem_Action IS
86 -- write (or forward) to data memory bus
87 DMEMB_o.addr <= EX2MEM_i.exeq_result;
90 -- Note: use MEM_REG_i here, since MEM_WRB_o (output) cannot be read
91 IF ((MEM_REG_i.wrb_Action /= NO_WRB) AND
92 (EX2MEM_i.wrix_rD = MEM_REG_i.wrix_rD)) THEN
93 CASE MEM_REG_i.wrb_Action IS
95 -- forward exeq output, to handle e.g. add rD,rA,xx; sw rD,mem[y]; ...
96 exeq_data_v := MEM_REG_i.exeq_result;
98 -- forward mem_data just read, to handle e.g. lhu rD,mem[x]; sh rD,mem[y]; ...
99 exeq_data_v := dmem_data_v;
102 exeq_data_v := EX2MEM_i.data_rD;
104 -- output data will be in Big Endian format
105 CASE EX2MEM_i.byte_Enable IS
106 WHEN "1000" => DMEMB_o.data <= exeq_data_v( 7 DOWNTO 0) & C_24_ZEROS;
107 WHEN "0100" => DMEMB_o.data <= C_8_ZEROS & exeq_data_v( 7 DOWNTO 0) & C_16_ZEROS;
108 WHEN "0010" => DMEMB_o.data <= C_16_ZEROS & exeq_data_v( 7 DOWNTO 0) & C_8_ZEROS;
109 WHEN "0001" => DMEMB_o.data <= C_24_ZEROS & exeq_data_v( 7 DOWNTO 0);
110 WHEN "1100" => DMEMB_o.data <= exeq_data_v(15 DOWNTO 0) & C_16_ZEROS;
111 WHEN "0011" => DMEMB_o.data <= C_16_ZEROS & exeq_data_v(15 DOWNTO 0);
112 WHEN OTHERS => DMEMB_o.data <= exeq_data_v;
115 -- read from data memory bus
116 DMEMB_o.addr <= EX2MEM_i.exeq_result;
119 DMEMB_o.data <= EX2MEM_i.data_rD; -- (OTHERS => 'Z');
120 WHEN OTHERS => -- NO_MEM
121 DMEMB_o.addr <= C_32_ZEROS;
124 DMEMB_o.data <= EX2MEM_i.data_rD; -- (OTHERS => 'Z');
127 -- additional wrb signals
128 CASE MEM_REG_i.wrb_Action IS
129 WHEN WRB_MEM => MEM_WRB_o.data_rD <= dmem_data_v;
130 WHEN OTHERS => MEM_WRB_o.data_rD <= MEM_REG_i.exeq_result;
135 END ARCHITECTURE rtl;