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

Subversion Repositories cpu_lecture

[/] [cpu_lecture/] [trunk/] [src/] [prog_mem.vhd] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jsauermann
-------------------------------------------------------------------------------
2
-- 
3
-- Copyright (C) 2009, 2010 Dr. Juergen Sauermann
4
-- 
5
--  This code is free software: you can redistribute it and/or modify
6
--  it under the terms of the GNU General Public License as published by
7
--  the Free Software Foundation, either version 3 of the License, or
8
--  (at your option) any later version.
9
--
10
--  This code is distributed in the hope that it will be useful,
11
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
--  GNU General Public License for more details.
14
--
15
--  You should have received a copy of the GNU General Public License
16
--  along with this code (see the file named COPYING).
17
--  If not, see http://www.gnu.org/licenses/.
18
--
19
-------------------------------------------------------------------------------
20
-------------------------------------------------------------------------------
21
--
22
-- Module Name:    prog_mem - Behavioral 
23
-- Create Date:    14:09:04 10/30/2009 
24
-- Description:    the program memory of a CPU.
25
--
26
----------------------------------------------------------------------------------
27
library IEEE;
28
use IEEE.STD_LOGIC_1164.ALL;
29
use IEEE.STD_LOGIC_ARITH.ALL;
30
use IEEE.STD_LOGIC_UNSIGNED.ALL;
31
 
32
-- the content of the program memory.
33
--
34
use work.prog_mem_content.all;
35
 
36
entity prog_mem is
37
    port (  I_CLK       : in  std_logic;
38
 
39
            I_WAIT      : in  std_logic;
40
            I_PC        : in  std_logic_vector(15 downto 0); -- word address
41
            I_PM_ADR    : in  std_logic_vector(11 downto 0); -- byte address
42
 
43
            Q_OPC       : out std_logic_vector(31 downto 0);
44
            Q_PC        : out std_logic_vector(15 downto 0);
45
            Q_PM_DOUT   : out std_logic_vector( 7 downto 0));
46
end prog_mem;
47
 
48
architecture Behavioral of prog_mem is
49
 
50
constant zero_256 : bit_vector := X"00000000000000000000000000000000"
51
                                & X"00000000000000000000000000000000";
52
 
53
component RAMB4_S4_S4
54
    generic(INIT_00 : bit_vector := zero_256;
55
            INIT_01 : bit_vector := zero_256;
56
            INIT_02 : bit_vector := zero_256;
57
            INIT_03 : bit_vector := zero_256;
58
            INIT_04 : bit_vector := zero_256;
59
            INIT_05 : bit_vector := zero_256;
60
            INIT_06 : bit_vector := zero_256;
61
            INIT_07 : bit_vector := zero_256;
62
            INIT_08 : bit_vector := zero_256;
63
            INIT_09 : bit_vector := zero_256;
64
            INIT_0A : bit_vector := zero_256;
65
            INIT_0B : bit_vector := zero_256;
66
            INIT_0C : bit_vector := zero_256;
67
            INIT_0D : bit_vector := zero_256;
68
            INIT_0E : bit_vector := zero_256;
69
            INIT_0F : bit_vector := zero_256);
70
 
71
    port(   ADDRA   : in  std_logic_vector(9 downto 0);
72
            ADDRB   : in  std_logic_vector(9 downto 0);
73
            CLKA    : in  std_ulogic;
74
            CLKB    : in  std_ulogic;
75
            DIA     : in  std_logic_vector(3 downto 0);
76
            DIB     : in  std_logic_vector(3 downto 0);
77
            ENA     : in  std_ulogic;
78
            ENB     : in  std_ulogic;
79
            RSTA    : in  std_ulogic;
80
            RSTB    : in  std_ulogic;
81
            WEA     : in  std_ulogic;
82
            WEB     : in  std_ulogic;
83
 
84
            DOA     : out std_logic_vector(3 downto 0);
85
            DOB     : out std_logic_vector(3 downto 0));
86
end component;
87
 
88
signal M_OPC_E      : std_logic_vector(15 downto 0);
89
signal M_OPC_O      : std_logic_vector(15 downto 0);
90
signal M_PMD_E      : std_logic_vector(15 downto 0);
91
signal M_PMD_O      : std_logic_vector(15 downto 0);
92
 
93
signal L_WAIT_N     : std_logic;
94
signal L_PC_0       : std_logic;
95
signal L_PC_E       : std_logic_vector(10 downto 1);
96
signal L_PC_O       : std_logic_vector(10 downto 1);
97
signal L_PMD        : std_logic_vector(15 downto 0);
98
signal L_PM_ADR_1_0 : std_logic_vector( 1 downto 0);
99
 
100
begin
101
 
102
    pe_0 : RAMB4_S4_S4 ---------------------------------------------------------
103 6 jsauermann
    generic map(INIT_00 => p0_00, INIT_01 => p0_01, INIT_02 => p0_02,
104
                INIT_03 => p0_03, INIT_04 => p0_04, INIT_05 => p0_05,
105
                INIT_06 => p0_06, INIT_07 => p0_07, INIT_08 => p0_08,
106
                INIT_09 => p0_09, INIT_0A => p0_0A, INIT_0B => p0_0B,
107
                INIT_0C => p0_0C, INIT_0D => p0_0D, INIT_0E => p0_0E,
108
                INIT_0F => p0_0F)
109 2 jsauermann
    port map(ADDRA => L_PC_E,                   ADDRB => I_PM_ADR(11 downto 2),
110
             CLKA  => I_CLK,                    CLKB  => I_CLK,
111
             DIA   => "0000",                   DIB   => "0000",
112
             ENA   => L_WAIT_N,                 ENB   => '1',
113
             RSTA  => '0',                      RSTB  => '0',
114
             WEA   => '0',                      WEB   => '0',
115
             DOA   => M_OPC_E(3 downto 0),      DOB   => M_PMD_E(3 downto 0));
116
 
117
    pe_1 : RAMB4_S4_S4 ---------------------------------------------------------
118 6 jsauermann
    generic map(INIT_00 => p1_00, INIT_01 => p1_01, INIT_02 => p1_02,
119
                INIT_03 => p1_03, INIT_04 => p1_04, INIT_05 => p1_05,
120
                INIT_06 => p1_06, INIT_07 => p1_07, INIT_08 => p1_08,
121
                INIT_09 => p1_09, INIT_0A => p1_0A, INIT_0B => p1_0B,
122
                INIT_0C => p1_0C, INIT_0D => p1_0D, INIT_0E => p1_0E,
123
                INIT_0F => p1_0F)
124 2 jsauermann
    port map(ADDRA => L_PC_E,                   ADDRB => I_PM_ADR(11 downto 2),
125
             CLKA  => I_CLK,                    CLKB  => I_CLK,
126
             DIA   => "0000",                   DIB   => "0000",
127
             ENA   => L_WAIT_N,                 ENB   => '1',
128
             RSTA  => '0',                      RSTB  => '0',
129
             WEA   => '0',                      WEB   => '0',
130
             DOA   => M_OPC_E(7 downto 4),      DOB   => M_PMD_E(7 downto 4));
131
 
132
    pe_2 : RAMB4_S4_S4 ---------------------------------------------------------
133 6 jsauermann
    generic map(INIT_00 => p2_00, INIT_01 => p2_01, INIT_02 => p2_02,
134
                INIT_03 => p2_03, INIT_04 => p2_04, INIT_05 => p2_05,
135
                INIT_06 => p2_06, INIT_07 => p2_07, INIT_08 => p2_08,
136
                INIT_09 => p2_09, INIT_0A => p2_0A, INIT_0B => p2_0B,
137
                INIT_0C => p2_0C, INIT_0D => p2_0D, INIT_0E => p2_0E,
138
                INIT_0F => p2_0F)
139 2 jsauermann
    port map(ADDRA => L_PC_E,                   ADDRB => I_PM_ADR(11 downto 2),
140
             CLKA  => I_CLK,                    CLKB  => I_CLK,
141
             DIA   => "0000",                   DIB   => "0000",
142
             ENA   => L_WAIT_N,                 ENB   => '1',
143
             RSTA  => '0',                      RSTB  => '0',
144
             WEA   => '0',                      WEB   => '0',
145
             DOA   => M_OPC_E(11 downto 8),     DOB   => M_PMD_E(11 downto 8));
146
 
147
    pe_3 : RAMB4_S4_S4 ---------------------------------------------------------
148 6 jsauermann
    generic map(INIT_00 => p3_00, INIT_01 => p3_01, INIT_02 => p3_02,
149
                INIT_03 => p3_03, INIT_04 => p3_04, INIT_05 => p3_05,
150
                INIT_06 => p3_06, INIT_07 => p3_07, INIT_08 => p3_08,
151
                INIT_09 => p3_09, INIT_0A => p3_0A, INIT_0B => p3_0B,
152
                INIT_0C => p3_0C, INIT_0D => p3_0D, INIT_0E => p3_0E,
153
                INIT_0F => p3_0F)
154 2 jsauermann
    port map(ADDRA => L_PC_E,                   ADDRB => I_PM_ADR(11 downto 2),
155
             CLKA  => I_CLK,                    CLKB  => I_CLK,
156
             DIA   => "0000",                   DIB   => "0000",
157
             ENA   => L_WAIT_N,                 ENB   => '1',
158
             RSTA  => '0',                      RSTB  => '0',
159
             WEA   => '0',                      WEB   => '0',
160
             DOA   => M_OPC_E(15 downto 12),    DOB   => M_PMD_E(15 downto 12));
161
 
162
    po_0 : RAMB4_S4_S4 ---------------------------------------------------------
163 6 jsauermann
    generic map(INIT_00 => p4_00, INIT_01 => p4_01, INIT_02 => p4_02,
164
                INIT_03 => p4_03, INIT_04 => p4_04, INIT_05 => p4_05,
165
                INIT_06 => p4_06, INIT_07 => p4_07, INIT_08 => p4_08,
166
                INIT_09 => p4_09, INIT_0A => p4_0A, INIT_0B => p4_0B,
167
                INIT_0C => p4_0C, INIT_0D => p4_0D, INIT_0E => p4_0E,
168
                INIT_0F => p4_0F)
169 2 jsauermann
    port map(ADDRA => L_PC_O,                   ADDRB => I_PM_ADR(11 downto 2),
170
             CLKA  => I_CLK,                    CLKB  => I_CLK,
171
             DIA   => "0000",                   DIB   => "0000",
172
             ENA   => L_WAIT_N,                 ENB   => '1',
173
             RSTA  => '0',                      RSTB  => '0',
174
             WEA   => '0',                      WEB   => '0',
175
             DOA   => M_OPC_O(3 downto 0),      DOB   => M_PMD_O(3 downto 0));
176
 
177
    po_1 : RAMB4_S4_S4 ---------------------------------------------------------
178 6 jsauermann
    generic map(INIT_00 => p5_00, INIT_01 => p5_01, INIT_02 => p5_02,
179
                INIT_03 => p5_03, INIT_04 => p5_04, INIT_05 => p5_05,
180
                INIT_06 => p5_06, INIT_07 => p5_07, INIT_08 => p5_08,
181
                INIT_09 => p5_09, INIT_0A => p5_0A, INIT_0B => p5_0B,
182
                INIT_0C => p5_0C, INIT_0D => p5_0D, INIT_0E => p5_0E,
183
                INIT_0F => p5_0F)
184 2 jsauermann
    port map(ADDRA => L_PC_O,                   ADDRB => I_PM_ADR(11 downto 2),
185
             CLKA  => I_CLK,                    CLKB  => I_CLK,
186
             DIA   => "0000",                   DIB   => "0000",
187
             ENA   => L_WAIT_N,                 ENB   => '1',
188
             RSTA  => '0',                      RSTB  => '0',
189
             WEA   => '0',                      WEB   => '0',
190
             DOA   => M_OPC_O(7 downto 4),      DOB   => M_PMD_O(7 downto 4));
191
 
192
    po_2 : RAMB4_S4_S4 ---------------------------------------------------------
193 6 jsauermann
    generic map(INIT_00 => p6_00, INIT_01 => p6_01, INIT_02 => p6_02,
194
                INIT_03 => p6_03, INIT_04 => p6_04, INIT_05 => p6_05,
195
                INIT_06 => p6_06, INIT_07 => p6_07, INIT_08 => p6_08,
196
                INIT_09 => p6_09, INIT_0A => p6_0A, INIT_0B => p6_0B,
197
                INIT_0C => p6_0C, INIT_0D => p6_0D, INIT_0E => p6_0E,
198
                INIT_0F => p6_0F)
199 2 jsauermann
    port map(ADDRA => L_PC_O,                   ADDRB => I_PM_ADR(11 downto 2),
200
             CLKA  => I_CLK,                    CLKB  => I_CLK,
201
             DIA   => "0000",                   DIB   => "0000",
202
             ENA   => L_WAIT_N,                 ENB   => '1',
203
             RSTA  => '0',                      RSTB  => '0',
204
             WEA   => '0',                      WEB   => '0',
205
             DOA   => M_OPC_O(11 downto 8),     DOB   => M_PMD_O(11 downto 8));
206
 
207
    po_3 : RAMB4_S4_S4 ---------------------------------------------------------
208 6 jsauermann
    generic map(INIT_00 => p7_00, INIT_01 => p7_01, INIT_02 => p7_02,
209
                INIT_03 => p7_03, INIT_04 => p7_04, INIT_05 => p7_05,
210
                INIT_06 => p7_06, INIT_07 => p7_07, INIT_08 => p7_08,
211
                INIT_09 => p7_09, INIT_0A => p7_0A, INIT_0B => p7_0B,
212
                INIT_0C => p7_0C, INIT_0D => p7_0D, INIT_0E => p7_0E,
213
                INIT_0F => p7_0F)
214 2 jsauermann
    port map(ADDRA => L_PC_O,                   ADDRB => I_PM_ADR(11 downto 2),
215
             CLKA  => I_CLK,                    CLKB  => I_CLK,
216
             DIA   => "0000",                   DIB   => "0000",
217
             ENA   => L_WAIT_N,                 ENB   => '1',
218
             RSTA  => '0',                      RSTB  => '0',
219
             WEA   => '0',                      WEB   => '0',
220
             DOA   => M_OPC_O(15 downto 12),    DOB   => M_PMD_O(15 downto 12));
221
 
222
    -- remember I_PC0 and I_PM_ADR for the output mux.
223
    --
224
    pc0: process(I_CLK)
225
    begin
226
        if (rising_edge(I_CLK)) then
227
            Q_PC <= I_PC;
228
            L_PM_ADR_1_0 <= I_PM_ADR(1 downto 0);
229
            if ((I_WAIT = '0')) then
230
                L_PC_0 <= I_PC(0);
231
            end if;
232
        end if;
233
    end process;
234
 
235
    L_WAIT_N <= not I_WAIT;
236
 
237
    -- we use two memory blocks _E and _O (even and odd).
238
    -- This gives us a quad-port memory so that we can access
239
    -- I_PC, I_PC + 1, and PM simultaneously.
240
    --
241
    -- I_PC and I_PC + 1 are handled by port A of the memory while PM
242
    -- is handled by port B.
243
    --
244
    -- Q_OPC(15 ... 0) shall contain the word addressed by I_PC, while
245
    -- Q_OPC(31 ... 16) shall contain the word addressed by I_PC + 1.
246
    --
247
    -- There are two cases:
248
    --
249
    -- case A: I_PC     is even, thus I_PC + 1 is odd
250
    -- case B: I_PC + 1 is odd , thus I_PC is even
251
    --
252
    L_PC_O <= I_PC(10 downto 1);
253
    L_PC_E <= I_PC(10 downto 1) + ("000000000" & I_PC(0));
254
    Q_OPC(15 downto  0) <= M_OPC_E when L_PC_0 = '0' else M_OPC_O;
255
    Q_OPC(31 downto 16) <= M_OPC_E when L_PC_0 = '1' else M_OPC_O;
256
 
257
    L_PMD <= M_PMD_E               when (L_PM_ADR_1_0(1) = '0') else M_PMD_O;
258
    Q_PM_DOUT <= L_PMD(7 downto 0) when (L_PM_ADR_1_0(0) = '0')
259
            else L_PMD(15 downto 8);
260
 
261
end Behavioral;
262
 

powered by: WebSVN 2.1.0

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