OpenCores
URL https://opencores.org/ocsvn/mblite/mblite/trunk

Subversion Repositories mblite

[/] [mblite/] [trunk/] [hw/] [core/] [mem.vhd] - Blame information for rev 9

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 takar
----------------------------------------------------------------------------------------------
2
--
3
--      Input file         : mem.vhd
4
--      Design name        : mem
5
--      Author             : Tamar Kranenburg
6
--      Company            : Delft University of Technology
7
--                         : Faculty EEMCS, Department ME&CE
8
--                         : Systems and Circuits group
9
--
10
--      Description        : Memory retrieves data words from a data memory. Memory file
11
--                           access of byte, halfword and word sizes is supported. The sel_o
12
--                           signal indicates which bytes should be read or written. The
13
--                           responsibility for writing the right memory address is not within
14
--                           this integer unit but should be handled by the external memory
15
--                           device. This facilitates the addition of devices with different
16
--                           bus sizes.
17
--
18
--                           The dmem_i signals are directly connected to the decode and
19
--                           execute components.
20
--
21
----------------------------------------------------------------------------------------------
22
 
23 8 takar
library ieee;
24
use ieee.std_logic_1164.all;
25
use ieee.std_logic_unsigned.all;
26 2 takar
 
27 8 takar
library mblite;
28
use mblite.config_Pkg.all;
29
use mblite.core_Pkg.all;
30
use mblite.std_Pkg.all;
31 2 takar
 
32 8 takar
entity mem is port
33 2 takar
(
34 8 takar
    mem_o  : out mem_out_type;
35
    dmem_o : out dmem_out_type;
36
    mem_i  : in mem_in_type;
37
    ena_i  : in std_logic;
38
    rst_i  : in std_logic;
39
    clk_i  : in std_logic
40 2 takar
);
41 8 takar
end mem;
42 2 takar
 
43 8 takar
architecture arch of mem is
44
    signal r, rin : mem_out_type;
45
    signal mem_result : std_logic_vector(CFG_DMEM_WIDTH - 1 downto 0);
46
begin
47 2 takar
    -- connect pipline signals
48 8 takar
    mem_o.ctrl_wrb     <= r.ctrl_wrb;
49
    mem_o.ctrl_mem_wrb <= r.ctrl_mem_wrb;
50 2 takar
    mem_o.alu_result  <= r.alu_result;
51
 
52
    -- connect memory interface signals
53
    dmem_o.dat_o <= mem_result;
54 8 takar
    dmem_o.sel_o <= decode_mem_store(mem_i.alu_result(1 downto 0), mem_i.ctrl_mem.transfer_size);
55 2 takar
    dmem_o.we_o  <= mem_i.ctrl_mem.mem_write;
56 8 takar
    dmem_o.adr_o <= mem_i.alu_result(CFG_DMEM_SIZE - 1 downto 0);
57
    dmem_o.ena_o <= mem_i.ctrl_mem.mem_read or mem_i.ctrl_mem.mem_write;
58 2 takar
 
59 8 takar
    mem_comb: process(mem_i, mem_i.ctrl_wrb, mem_i.ctrl_mem, r, r.ctrl_wrb, r.ctrl_mem_wrb)
60
        variable v : mem_out_type;
61
        variable intermediate : std_logic_vector(CFG_DMEM_WIDTH - 1 downto 0);
62
    begin
63 2 takar
 
64
        v := r;
65 8 takar
        v.ctrl_wrb := mem_i.ctrl_wrb;
66 2 takar
 
67 8 takar
        if mem_i.branch = '1' then
68 2 takar
            -- set alu result for branch and load instructions
69
            v.alu_result := sign_extend(mem_i.program_counter, '0', 32);
70 8 takar
        else
71 2 takar
            v.alu_result := mem_i.alu_result;
72 8 takar
        end if;
73 2 takar
 
74
        -- Forward memory result
75 8 takar
        if CFG_MEM_FWD_WRB = true and ( r.ctrl_mem_wrb.mem_read and compare(mem_i.ctrl_wrb.reg_d, r.ctrl_wrb.reg_d)) = '1' then
76
            intermediate := align_mem_load(mem_i.mem_result, r.ctrl_mem_wrb.transfer_size, r.alu_result(1 downto 0));
77 2 takar
            mem_result <= align_mem_store(intermediate, mem_i.ctrl_mem.transfer_size);
78 8 takar
        else
79 2 takar
            mem_result <= mem_i.dat_d;
80 8 takar
        end if;
81 2 takar
 
82 8 takar
        v.ctrl_mem_wrb.mem_read := mem_i.ctrl_mem.mem_read;
83
        v.ctrl_mem_wrb.transfer_size := mem_i.ctrl_mem.transfer_size;
84 2 takar
 
85
        rin <= v;
86
 
87 8 takar
    end process;
88 2 takar
 
89 8 takar
    mem_seq: process(clk_i)
90
        procedure proc_mem_reset is
91
        begin
92
            r.alu_result  <= (others => '0');
93
            r.ctrl_wrb.reg_d <= (others => '0');
94
            r.ctrl_wrb.reg_write <= '0';
95
            r.ctrl_mem_wrb.mem_read <= '0';
96
            r.ctrl_mem_wrb.transfer_size <= WORD;
97
        end procedure proc_mem_reset;
98
    begin
99
        if rising_edge(clk_i) then
100
            if rst_i = '1' then
101 2 takar
                proc_mem_reset;
102 8 takar
            elsif ena_i = '1' then
103 2 takar
                r <= rin;
104 8 takar
            end if;
105
        end if;
106
    end process;
107
end arch;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.