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

Subversion Repositories mlite

[/] [mlite/] [trunk/] [vhdl/] [mlite_cpu.vhd] - Blame information for rev 203

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

Line No. Rev Author Line
1 39 rhoads
---------------------------------------------------------------------
2 43 rhoads
-- TITLE: Plasma CPU core
3 39 rhoads
-- AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
4
-- DATE CREATED: 2/15/01
5
-- FILENAME: mlite_cpu.vhd
6 43 rhoads
-- PROJECT: Plasma CPU core
7 39 rhoads
-- COPYRIGHT: Software placed into the public domain by the author.
8
--    Software 'as is' without warranty.  Author liable for nothing.
9
-- NOTE:  MIPS(tm) and MIPS I(tm) are registered trademarks of MIPS 
10
--    Technologies.  MIPS Technologies does not endorse and is not 
11
--    associated with this project.
12
-- DESCRIPTION:
13 83 rhoads
--    Top level VHDL document that ties the nine other entities together.
14
--
15
-- Executes all MIPS I(tm) opcodes but exceptions and non-aligned
16
-- memory accesses.  Based on information found in:
17 39 rhoads
--    "MIPS RISC Architecture" by Gerry Kane and Joe Heinrich
18
--    and "The Designer's Guide to VHDL" by Peter J. Ashenden
19 83 rhoads
--
20 202 rhoads
-- The CPU is implemented as a two or three stage pipeline.
21 39 rhoads
-- An add instruction would take the following steps (see cpu.gif):
22 202 rhoads
-- Stage #0:
23 83 rhoads
--    1.  The "pc_next" entity passes the program counter (PC) to the 
24
--        "mem_ctrl" entity which fetches the opcode from memory.
25 202 rhoads
-- Stage #1:
26
--    2.  The memory returns the opcode.
27 83 rhoads
-- Stage #2:
28 139 rhoads
--    3.  "Mem_ctrl" passes the opcode to the "control" entity.
29
--    4.  "Control" converts the 32-bit opcode to a 60-bit VLWI opcode
30 39 rhoads
--        and sends control signals to the other entities.
31 139 rhoads
--    5.  Based on the rs_index and rt_index control signals, "reg_bank" 
32 39 rhoads
--        sends the 32-bit reg_source and reg_target to "bus_mux".
33 139 rhoads
--    6.  Based on the a_source and b_source control signals, "bus_mux"
34 39 rhoads
--        multiplexes reg_source onto a_bus and reg_target onto b_bus.
35 202 rhoads
-- Stage #3 (part of stage #2 if using two stage pipeline):
36 139 rhoads
--    7.  Based on the alu_func control signals, "alu" adds the values
37 39 rhoads
--        from a_bus and b_bus and places the result on c_bus.
38 139 rhoads
--    8.  Based on the c_source control signals, "bus_bux" multiplexes
39 39 rhoads
--        c_bus onto reg_dest.
40 139 rhoads
--    9.  Based on the rd_index control signal, "reg_bank" saves
41 39 rhoads
--        reg_dest into the correct register.
42 202 rhoads
-- Stage #3b:
43 139 rhoads
--   10.  Read or write memory if needed.
44 39 rhoads
--
45 139 rhoads
-- All signals are active high. 
46
-- Here are the signals for writing a character to address 0xffff
47 202 rhoads
-- when using a two stage pipeline:
48 39 rhoads
--
49 139 rhoads
-- Program:
50
-- addr     value  opcode 
51
-- =============================
52
--   3c: 00000000  nop
53
--   40: 34040041  li $a0,0x41
54
--   44: 3405ffff  li $a1,0xffff
55
--   48: a0a40000  sb $a0,0($a1)
56
--   4c: 00000000  nop
57
--   50: 00000000  nop
58 83 rhoads
--
59 139 rhoads
--      intr_in                             mem_pause 
60
--  reset_in                           mem_byte_we     Stages
61
--     ns     mem_address mem_data_w mem_data_r        40 44 48 4c 50
62 203 rhoads
--   3500  0  0  00000040   00000000   00000000  0  0   0
63
--   3600  0  0  00000044   00000000   34040041  0  0   1  0
64
--   3700  0  0  00000048   00000000   3405FFFF  0  0   2  1  0 
65
--   3800  0  0  0000004C   00000000   A0A40000  0  0      2  1  0
66
--   3900  0  0  0000FFFC   41414141   00000000  1  0         2  1
67
--   4000  0  0  00000050   41414141   XXXXXX41  0  0         3  2  0
68
--   4100  0  0  00000054   00000000   00000000  0  0               1
69 39 rhoads
---------------------------------------------------------------------
70
library ieee;
71 114 rhoads
use work.mlite_pack.all;
72 39 rhoads
use ieee.std_logic_1164.all;
73 73 rhoads
use ieee.std_logic_unsigned.all;
74 39 rhoads
 
75
entity mlite_cpu is
76 139 rhoads
   generic(memory_type     : string  := "XILINX_16X"; --ALTERA_LPM, or DUAL_PORT_
77 132 rhoads
           mult_type       : string  := "DEFAULT"; --AREA_OPTIMIZED
78
           shifter_type    : string  := "DEFAULT"; --AREA_OPTIMIZED
79
           alu_type        : string  := "DEFAULT"; --AREA_OPTIMIZED
80 202 rhoads
           pipeline_stages : natural := 2); --2 or 3
81 39 rhoads
   port(clk         : in std_logic;
82
        reset_in    : in std_logic;
83
        intr_in     : in std_logic;
84
 
85
        mem_address : out std_logic_vector(31 downto 0);
86
        mem_data_w  : out std_logic_vector(31 downto 0);
87
        mem_data_r  : in std_logic_vector(31 downto 0);
88 139 rhoads
        mem_byte_we : out std_logic_vector(3 downto 0);
89 39 rhoads
        mem_pause   : in std_logic);
90
end; --entity mlite_cpu
91
 
92
architecture logic of mlite_cpu is
93 202 rhoads
   --When using a two stage pipeline "sigD <= sig".
94
   --When using a three stage pipeline "sigD <= sig when rising_edge(clk)",
95 73 rhoads
   --  so sigD is delayed by one clock cycle.
96 39 rhoads
   signal opcode         : std_logic_vector(31 downto 0);
97 73 rhoads
   signal rs_index       : std_logic_vector(5 downto 0);
98
   signal rt_index       : std_logic_vector(5 downto 0);
99
   signal rd_index       : std_logic_vector(5 downto 0);
100
   signal rd_indexD      : std_logic_vector(5 downto 0);
101
   signal reg_source     : std_logic_vector(31 downto 0);
102
   signal reg_target     : std_logic_vector(31 downto 0);
103
   signal reg_dest       : std_logic_vector(31 downto 0);
104
   signal reg_destD      : std_logic_vector(31 downto 0);
105
   signal a_bus          : std_logic_vector(31 downto 0);
106
   signal a_busD         : std_logic_vector(31 downto 0);
107
   signal b_bus          : std_logic_vector(31 downto 0);
108
   signal b_busD         : std_logic_vector(31 downto 0);
109
   signal c_bus          : std_logic_vector(31 downto 0);
110
   signal c_alu          : std_logic_vector(31 downto 0);
111
   signal c_shift        : std_logic_vector(31 downto 0);
112
   signal c_mult         : std_logic_vector(31 downto 0);
113
   signal c_memory       : std_logic_vector(31 downto 0);
114 39 rhoads
   signal imm            : std_logic_vector(15 downto 0);
115 139 rhoads
   signal pc_future      : std_logic_vector(31 downto 2);
116
   signal pc_current     : std_logic_vector(31 downto 2);
117
   signal pc_plus4       : std_logic_vector(31 downto 2);
118 73 rhoads
   signal alu_func       : alu_function_type;
119
   signal alu_funcD      : alu_function_type;
120
   signal shift_func     : shift_function_type;
121
   signal shift_funcD    : shift_function_type;
122
   signal mult_func      : mult_function_type;
123
   signal mult_funcD     : mult_function_type;
124
   signal branch_func    : branch_function_type;
125 39 rhoads
   signal take_branch    : std_logic;
126
   signal a_source       : a_source_type;
127
   signal b_source       : b_source_type;
128
   signal c_source       : c_source_type;
129
   signal pc_source      : pc_source_type;
130
   signal mem_source     : mem_source_type;
131
   signal pause_mult     : std_logic;
132 73 rhoads
   signal pause_ctrl     : std_logic;
133
   signal pause_pipeline : std_logic;
134
   signal pause_any      : std_logic;
135
   signal pause_non_ctrl : std_logic;
136
   signal pause_bank     : std_logic;
137 39 rhoads
   signal nullify_op     : std_logic;
138
   signal intr_enable    : std_logic;
139
   signal intr_signal    : std_logic;
140 194 rhoads
   signal exception_sig  : std_logic;
141 73 rhoads
   signal reset_reg      : std_logic_vector(3 downto 0);
142 60 rhoads
   signal reset          : std_logic;
143 39 rhoads
begin  --architecture
144
 
145 73 rhoads
   pause_any <= (mem_pause or pause_ctrl) or (pause_mult or pause_pipeline);
146
   pause_non_ctrl <= (mem_pause or pause_mult) or pause_pipeline;
147
   pause_bank <= (mem_pause or pause_ctrl or pause_mult) and not pause_pipeline;
148 128 rhoads
   nullify_op <= '1' when (pc_source = FROM_LBRANCH and take_branch = '0')
149 194 rhoads
                          or intr_signal = '1' or exception_sig = '1'
150 124 rhoads
                          else '0';
151 39 rhoads
   c_bus <= c_alu or c_shift or c_mult;
152 73 rhoads
   reset <= '1' when reset_in = '1' or reset_reg /= "1111" else '0';
153 139 rhoads
   mem_address(1 downto 0) <= "00";
154 39 rhoads
 
155 73 rhoads
   --synchronize reset and interrupt pins
156 83 rhoads
   intr_proc: process(clk, reset_in, reset_reg, intr_in, intr_enable,
157 139 rhoads
      pc_source, pc_current, pause_any)
158 73 rhoads
   begin
159
      if reset_in = '1' then
160
         reset_reg <= "0000";
161 124 rhoads
         intr_signal <= '0';
162 73 rhoads
      elsif rising_edge(clk) then
163
         if reset_reg /= "1111" then
164
            reset_reg <= reset_reg + 1;
165
         end if;
166 124 rhoads
 
167 73 rhoads
         --don't try to interrupt a multi-cycle instruction
168 124 rhoads
         if pause_any = '0' then
169 139 rhoads
            if intr_in = '1' and intr_enable = '1' and
170
                  pc_source = FROM_INC4 then
171
               --the epc will contain pc+4
172 124 rhoads
               intr_signal <= '1';
173
            else
174
               intr_signal <= '0';
175
            end if;
176 73 rhoads
         end if;
177 124 rhoads
 
178 73 rhoads
      end if;
179
   end process;
180 39 rhoads
 
181
   u1_pc_next: pc_next PORT MAP (
182
        clk          => clk,
183 60 rhoads
        reset_in     => reset,
184 96 rhoads
        take_branch  => take_branch,
185 73 rhoads
        pause_in     => pause_any,
186
        pc_new       => c_bus(31 downto 2),
187 39 rhoads
        opcode25_0   => opcode(25 downto 0),
188
        pc_source    => pc_source,
189 139 rhoads
        pc_future    => pc_future,
190
        pc_current   => pc_current,
191
        pc_plus4     => pc_plus4);
192 39 rhoads
 
193 73 rhoads
   u2_mem_ctrl: mem_ctrl
194
      PORT MAP (
195 39 rhoads
        clk          => clk,
196 60 rhoads
        reset_in     => reset,
197 73 rhoads
        pause_in     => pause_non_ctrl,
198 39 rhoads
        nullify_op   => nullify_op,
199 139 rhoads
        address_pc   => pc_future,
200 39 rhoads
        opcode_out   => opcode,
201
 
202 139 rhoads
        address_in   => c_bus,
203 39 rhoads
        mem_source   => mem_source,
204
        data_write   => reg_target,
205
        data_read    => c_memory,
206 73 rhoads
        pause_out    => pause_ctrl,
207 39 rhoads
 
208 139 rhoads
        mem_address  => mem_address(31 downto 2),
209 39 rhoads
        mem_data_w   => mem_data_w,
210
        mem_data_r   => mem_data_r,
211 139 rhoads
        mem_byte_we  => mem_byte_we);
212 39 rhoads
 
213
   u3_control: control PORT MAP (
214
        opcode       => opcode,
215
        intr_signal  => intr_signal,
216
        rs_index     => rs_index,
217
        rt_index     => rt_index,
218
        rd_index     => rd_index,
219
        imm_out      => imm,
220 73 rhoads
        alu_func     => alu_func,
221
        shift_func   => shift_func,
222
        mult_func    => mult_func,
223
        branch_func  => branch_func,
224 39 rhoads
        a_source_out => a_source,
225
        b_source_out => b_source,
226
        c_source_out => c_source,
227
        pc_source_out=> pc_source,
228 194 rhoads
        mem_source_out=> mem_source,
229
        exception_out=> exception_sig);
230 39 rhoads
 
231 47 rhoads
   u4_reg_bank: reg_bank
232
      generic map(memory_type => memory_type)
233
      port map (
234 39 rhoads
        clk            => clk,
235 60 rhoads
        reset_in       => reset,
236 73 rhoads
        pause          => pause_bank,
237 39 rhoads
        rs_index       => rs_index,
238
        rt_index       => rt_index,
239 73 rhoads
        rd_index       => rd_indexD,
240 39 rhoads
        reg_source_out => reg_source,
241
        reg_target_out => reg_target,
242 73 rhoads
        reg_dest_new   => reg_destD,
243 39 rhoads
        intr_enable    => intr_enable);
244
 
245
   u5_bus_mux: bus_mux port map (
246
        imm_in       => imm,
247
        reg_source   => reg_source,
248
        a_mux        => a_source,
249
        a_out        => a_bus,
250
 
251
        reg_target   => reg_target,
252
        b_mux        => b_source,
253
        b_out        => b_bus,
254
 
255
        c_bus        => c_bus,
256
        c_memory     => c_memory,
257 139 rhoads
        c_pc         => pc_current,
258 39 rhoads
        c_pc_plus4   => pc_plus4,
259
        c_mux        => c_source,
260
        reg_dest_out => reg_dest,
261
 
262 73 rhoads
        branch_func  => branch_func,
263 39 rhoads
        take_branch  => take_branch);
264
 
265 47 rhoads
   u6_alu: alu
266 139 rhoads
      generic map (alu_type => alu_type)
267 47 rhoads
      port map (
268 73 rhoads
        a_in         => a_busD,
269
        b_in         => b_busD,
270
        alu_function => alu_funcD,
271 39 rhoads
        c_alu        => c_alu);
272
 
273 114 rhoads
   u7_shifter: shifter
274
      generic map (shifter_type => shifter_type)
275
      port map (
276 73 rhoads
        value        => b_busD,
277
        shift_amount => a_busD(4 downto 0),
278
        shift_func   => shift_funcD,
279 39 rhoads
        c_shift      => c_shift);
280
 
281 47 rhoads
   u8_mult: mult
282 139 rhoads
      generic map (mult_type => mult_type)
283 47 rhoads
      port map (
284 39 rhoads
        clk       => clk,
285 128 rhoads
        reset_in  => reset,
286 73 rhoads
        a         => a_busD,
287
        b         => b_busD,
288
        mult_func => mult_funcD,
289 39 rhoads
        c_mult    => c_mult,
290
        pause_out => pause_mult);
291
 
292 202 rhoads
   pipeline2: if pipeline_stages <= 2 generate
293 73 rhoads
      a_busD <= a_bus;
294
      b_busD <= b_bus;
295
      alu_funcD <= alu_func;
296
      shift_funcD <= shift_func;
297
      mult_funcD <= mult_func;
298
      rd_indexD <= rd_index;
299
      reg_destD <= reg_dest;
300
      pause_pipeline <= '0';
301
   end generate; --pipeline2
302
 
303 202 rhoads
   pipeline3: if pipeline_stages > 2 generate
304
      --When operating in three stage pipeline mode, the following signals
305 73 rhoads
      --are delayed by one clock cycle:  a_bus, b_bus, alu/shift/mult_func,
306
      --c_source, and rd_index.
307
   u9_pipeline: pipeline port map (
308
        clk            => clk,
309
        reset          => reset,
310
        a_bus          => a_bus,
311
        a_busD         => a_busD,
312
        b_bus          => b_bus,
313
        b_busD         => b_busD,
314
        alu_func       => alu_func,
315
        alu_funcD      => alu_funcD,
316
        shift_func     => shift_func,
317
        shift_funcD    => shift_funcD,
318
        mult_func      => mult_func,
319
        mult_funcD     => mult_funcD,
320
        reg_dest       => reg_dest,
321
        reg_destD      => reg_destD,
322
        rd_index       => rd_index,
323
        rd_indexD      => rd_indexD,
324
 
325
        rs_index       => rs_index,
326
        rt_index       => rt_index,
327
        pc_source      => pc_source,
328
        mem_source     => mem_source,
329
        a_source       => a_source,
330
        b_source       => b_source,
331
        c_source       => c_source,
332
        c_bus          => c_bus,
333
        pause_any      => pause_any,
334
        pause_pipeline => pause_pipeline);
335
 
336 202 rhoads
   end generate; --pipeline3
337 139 rhoads
 
338 39 rhoads
end; --architecture logic

powered by: WebSVN 2.1.0

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