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

Subversion Repositories potato

[/] [potato/] [trunk/] [src/] [pp_memory.vhd] - Blame information for rev 64

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

Line No. Rev Author Line
1 2 skordal
-- The Potato Processor - A simple processor for FPGAs
2
-- (c) Kristian Klomsten Skordal 2014 - 2015 <kristian.skordal@wafflemail.net>
3 3 skordal
-- Report bugs and issues on <http://opencores.org/project,potato,bugtracker>
4 2 skordal
 
5
library ieee;
6
use ieee.std_logic_1164.all;
7
use ieee.numeric_std.all;
8
 
9
use work.pp_types.all;
10
use work.pp_csr.all;
11
use work.pp_utilities.all;
12
 
13
entity pp_memory is
14
        port(
15
                clk    : in std_logic;
16
                reset  : in std_logic;
17
                stall  : in std_logic;
18
 
19
                -- Data memory inputs:
20
                dmem_read_ack  : in std_logic;
21
                dmem_write_ack : in std_logic;
22
                dmem_data_in   : in std_logic_vector(31 downto 0);
23
 
24
                -- Current PC value:
25
                pc : in std_logic_vector(31 downto 0);
26
 
27
                -- Destination register signals:
28
                rd_write_in  : in  std_logic;
29
                rd_write_out : out std_logic;
30
                rd_data_in   : in  std_logic_vector(31 downto 0);
31
                rd_data_out  : out std_logic_vector(31 downto 0);
32
                rd_addr_in   : in  register_address;
33
                rd_addr_out  : out register_address;
34
 
35
                -- Control signals:
36
                branch         : in  branch_type;
37
                mem_op_in      : in  memory_operation_type;
38
                mem_size_in    : in  memory_operation_size;
39
                mem_op_out     : out memory_operation_type;
40
 
41
                -- Whether the instruction should be counted:
42
                count_instr_in  : in  std_logic;
43
                count_instr_out : out std_logic;
44
 
45
                -- Exception signals:
46
                exception_in          : in std_logic;
47
                exception_out         : out std_logic;
48
                exception_context_in  : in  csr_exception_context;
49
                exception_context_out : out csr_exception_context;
50
 
51
                -- CSR signals:
52
                csr_addr_in   : in  csr_address;
53
                csr_addr_out  : out csr_address;
54
                csr_write_in  : in  csr_write_mode;
55
                csr_write_out : out csr_write_mode;
56
                csr_data_in   : in  std_logic_vector(31 downto 0);
57
                csr_data_out  : out std_logic_vector(31 downto 0)
58
        );
59
end entity pp_memory;
60
 
61
architecture behaviour of pp_memory is
62
        signal mem_op   : memory_operation_type;
63
        signal mem_size : memory_operation_size;
64
 
65
        signal rd_data : std_logic_vector(31 downto 0);
66
begin
67
 
68
        mem_op_out <= mem_op;
69
 
70
        pipeline_register: process(clk)
71
        begin
72
                if rising_edge(clk) then
73
                        if reset = '1' then
74
                                rd_write_out <= '0';
75
                                csr_write_out <= CSR_WRITE_NONE;
76
                                count_instr_out <= '0';
77
                                mem_op <= MEMOP_TYPE_NONE;
78
                        elsif stall = '0' then
79
                                mem_size <= mem_size_in;
80
                                rd_data <= rd_data_in;
81
                                rd_addr_out <= rd_addr_in;
82
 
83
                                if exception_in = '1' then
84
                                        mem_op <= MEMOP_TYPE_NONE;
85
                                        rd_write_out <= '0';
86
                                        csr_write_out <= CSR_WRITE_REPLACE;
87 58 skordal
                                        csr_addr_out <= CSR_MEPC;
88 2 skordal
                                        csr_data_out <= pc;
89
                                        count_instr_out <= '0';
90
                                else
91
                                        mem_op <= mem_op_in;
92
                                        rd_write_out <= rd_write_in;
93
                                        csr_write_out <= csr_write_in;
94
                                        csr_addr_out <= csr_addr_in;
95
                                        csr_data_out <= csr_data_in;
96
                                        count_instr_out <= count_instr_in;
97
                                end if;
98
                        end if;
99
                end if;
100
        end process pipeline_register;
101
 
102
        update_exception_context: process(clk)
103
        begin
104
                if rising_edge(clk) then
105
                        if reset = '1' then
106
                                exception_out <= '0';
107
                        else
108
                                exception_out <= exception_in or to_std_logic(branch = BRANCH_SRET);
109
 
110
                                if exception_in = '1' then
111 58 skordal
                                        exception_context_out.ie <= '0';
112
                                        exception_context_out.ie1 <= exception_context_in.ie;
113 2 skordal
                                        exception_context_out.cause <= exception_context_in.cause;
114 58 skordal
                                        exception_context_out.badaddr <= exception_context_in.badaddr;
115 2 skordal
                                elsif branch = BRANCH_SRET then
116 58 skordal
                                        exception_context_out.ie <= exception_context_in.ie1;
117
                                        exception_context_out.ie1 <= exception_context_in.ie;
118 2 skordal
                                        exception_context_out.cause <= CSR_CAUSE_NONE;
119 58 skordal
                                        exception_context_out.badaddr <= (others => '0');
120 2 skordal
                                else
121 58 skordal
                                        exception_context_out.ie <= exception_context_in.ie;
122
                                        exception_context_out.ie1 <= exception_context_in.ie1;
123 2 skordal
                                        exception_context_out.cause <= CSR_CAUSE_NONE;
124 58 skordal
                                        exception_context_out.badaddr <= (others => '0');
125 2 skordal
                                end if;
126
                        end if;
127
                end if;
128
        end process update_exception_context;
129
 
130
        rd_data_mux: process(rd_data, dmem_data_in, mem_op, mem_size)
131
        begin
132
                if mem_op = MEMOP_TYPE_LOAD or mem_op = MEMOP_TYPE_LOAD_UNSIGNED then
133
                        case mem_size is
134
                                when MEMOP_SIZE_BYTE =>
135
                                        if mem_op = MEMOP_TYPE_LOAD_UNSIGNED then
136
                                                rd_data_out <= std_logic_vector(resize(unsigned(dmem_data_in(7 downto 0)), rd_data_out'length));
137
                                        else
138
                                                rd_data_out <= std_logic_vector(resize(signed(dmem_data_in(7 downto 0)), rd_data_out'length));
139
                                        end if;
140
                                when MEMOP_SIZE_HALFWORD =>
141
                                        if mem_op = MEMOP_TYPE_LOAD_UNSIGNED then
142
                                                rd_data_out <= std_logic_vector(resize(unsigned(dmem_data_in(15 downto 0)), rd_data_out'length));
143
                                        else
144
                                                rd_data_out <= std_logic_vector(resize(signed(dmem_data_in(15 downto 0)), rd_data_out'length));
145
                                        end if;
146
                                when MEMOP_SIZE_WORD =>
147
                                        rd_data_out <= dmem_data_in;
148
                        end case;
149
                else
150
                        rd_data_out <= rd_data;
151
                end if;
152
        end process rd_data_mux;
153
 
154
end architecture behaviour;

powered by: WebSVN 2.1.0

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