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

Subversion Repositories mblite

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

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
LIBRARY ieee;
24
USE ieee.std_logic_1164.ALL;
25
USE ieee.std_logic_unsigned.ALL;
26
 
27
LIBRARY mblite;
28
USE mblite.config_Pkg.ALL;
29
USE mblite.core_Pkg.ALL;
30
USE mblite.std_Pkg.ALL;
31
 
32
ENTITY mem IS PORT
33
(
34
    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_ulogic;
38
    rst_i  : IN std_ulogic;
39
    clk_i  : IN std_ulogic
40
);
41
END mem;
42
 
43
ARCHITECTURE arch OF mem IS
44
    SIGNAL r, rin : mem_out_type;
45
    SIGNAL mem_result : std_ulogic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
46
BEGIN
47
    -- connect pipline signals
48
    mem_o.ctrl_wb     <= r.ctrl_wb;
49
    mem_o.ctrl_mem_wb <= r.ctrl_mem_wb;
50
    mem_o.alu_result  <= r.alu_result;
51
 
52
    -- connect memory interface signals
53
    dmem_o.dat_o <= mem_result;
54
    dmem_o.sel_o <= decode_mem_store(mem_i.alu_result(1 DOWNTO 0), mem_i.ctrl_mem.transfer_size);
55
    dmem_o.we_o  <= mem_i.ctrl_mem.mem_write;
56
    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
 
59
    mem_comb: PROCESS(mem_i, mem_i.ctrl_wb, mem_i.ctrl_mem, r, r.ctrl_wb, r.ctrl_mem_wb)
60
        VARIABLE v : mem_out_type;
61
        VARIABLE intermediate : std_ulogic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
62
    BEGIN
63
 
64
        v := r;
65
        v.ctrl_wb := mem_i.ctrl_wb;
66
 
67
        IF mem_i.branch = '1' THEN
68
            -- set alu result for branch and load instructions
69
            v.alu_result := sign_extend(mem_i.program_counter, '0', 32);
70
        ELSE
71
            v.alu_result := mem_i.alu_result;
72
        END IF;
73
 
74
        -- Forward memory result
75
        IF CFG_MEM_FWD_WB = true AND ( r.ctrl_mem_wb.mem_read AND compare(mem_i.ctrl_wb.reg_d, r.ctrl_wb.reg_d)) = '1' THEN
76
            intermediate := align_mem_load(mem_i.mem_result, r.ctrl_mem_wb.transfer_size, r.alu_result(1 DOWNTO 0));
77
            mem_result <= align_mem_store(intermediate, mem_i.ctrl_mem.transfer_size);
78
        ELSE
79
            mem_result <= mem_i.dat_d;
80
        END IF;
81
 
82
        v.ctrl_mem_wb.mem_read := mem_i.ctrl_mem.mem_read;
83
        v.ctrl_mem_wb.transfer_size := mem_i.ctrl_mem.transfer_size;
84
 
85
        rin <= v;
86
 
87
    END PROCESS;
88
 
89
    mem_seq: PROCESS(clk_i)
90
        PROCEDURE proc_mem_reset IS
91
        BEGIN
92
            r.alu_result  <= (OTHERS => '0');
93
            r.ctrl_wb.reg_d <= (OTHERS => '0');
94
            r.ctrl_wb.reg_write <= '0';
95
            r.ctrl_mem_wb.mem_read <= '0';
96
            r.ctrl_mem_wb.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
                proc_mem_reset;
102
            ELSIF ena_i = '1' THEN
103
                r <= rin;
104
            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.