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

Subversion Repositories plasma

[/] [plasma/] [trunk/] [vhdl/] [mlite_cpu.vhd] - Blame information for rev 139

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 139 rhoads
-- The CPU is implemented as a three or four stage pipeline.
21 39 rhoads
-- An add instruction would take the following steps (see cpu.gif):
22 83 rhoads
-- Stage #1:
23
--    1.  The "pc_next" entity passes the program counter (PC) to the 
24
--        "mem_ctrl" entity which fetches the opcode from memory.
25
-- Stage #2:
26 139 rhoads
--    2.  The memory returns the opcode.
27
-- Stage #3:
28
--    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 139 rhoads
-- Stage #4 (part of stage #3 if using three stage pipeline):
36
--    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 139 rhoads
-- Stage #4b:
43
--   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
-- when using a three 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
--   3500  0  0  00000040   00000000   00000000  0  0   1
63
--   3600  0  0  00000044   00000000   34040041  0  0   2  1
64
--   3700  0  0  00000048   00000000   3405FFFF  0  0   3  2  1 
65
--   3800  0  0  0000004C   00000000   A0A40000  0  0      3  2  1
66
--   3900  0  0  0000FFFC   41414141   00000000  1  0         3  2
67
--   4000  0  0  00000050   41414141   XXXXXX41  0  0         4b 3  1
68
--   4100  0  0  00000054   00000000   00000000  0  0               2
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 139 rhoads
           pipeline_stages : natural := 3); --3 or 4
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 139 rhoads
   --When using a three stage pipeline "sigD <= sig".
94
   --When using a four 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 73 rhoads
   signal reset_reg      : std_logic_vector(3 downto 0);
141 60 rhoads
   signal reset          : std_logic;
142 39 rhoads
begin  --architecture
143
 
144 73 rhoads
   pause_any <= (mem_pause or pause_ctrl) or (pause_mult or pause_pipeline);
145
   pause_non_ctrl <= (mem_pause or pause_mult) or pause_pipeline;
146
   pause_bank <= (mem_pause or pause_ctrl or pause_mult) and not pause_pipeline;
147 128 rhoads
   nullify_op <= '1' when (pc_source = FROM_LBRANCH and take_branch = '0')
148 139 rhoads
                          or intr_signal = '1'
149 124 rhoads
                          else '0';
150 39 rhoads
   c_bus <= c_alu or c_shift or c_mult;
151 73 rhoads
   reset <= '1' when reset_in = '1' or reset_reg /= "1111" else '0';
152 139 rhoads
   mem_address(1 downto 0) <= "00";
153 39 rhoads
 
154 73 rhoads
   --synchronize reset and interrupt pins
155 83 rhoads
   intr_proc: process(clk, reset_in, reset_reg, intr_in, intr_enable,
156 139 rhoads
      pc_source, pc_current, pause_any)
157 73 rhoads
   begin
158
      if reset_in = '1' then
159
         reset_reg <= "0000";
160 124 rhoads
         intr_signal <= '0';
161 73 rhoads
      elsif rising_edge(clk) then
162
         if reset_reg /= "1111" then
163
            reset_reg <= reset_reg + 1;
164
         end if;
165 124 rhoads
 
166 73 rhoads
         --don't try to interrupt a multi-cycle instruction
167 124 rhoads
         if pause_any = '0' then
168 139 rhoads
            if intr_in = '1' and intr_enable = '1' and
169
                  pc_source = FROM_INC4 then
170
               --the epc will contain pc+4
171 124 rhoads
               intr_signal <= '1';
172
            else
173
               intr_signal <= '0';
174
            end if;
175 73 rhoads
         end if;
176 124 rhoads
 
177 73 rhoads
      end if;
178
   end process;
179 39 rhoads
 
180
   u1_pc_next: pc_next PORT MAP (
181
        clk          => clk,
182 60 rhoads
        reset_in     => reset,
183 96 rhoads
        take_branch  => take_branch,
184 73 rhoads
        pause_in     => pause_any,
185
        pc_new       => c_bus(31 downto 2),
186 39 rhoads
        opcode25_0   => opcode(25 downto 0),
187
        pc_source    => pc_source,
188 139 rhoads
        pc_future    => pc_future,
189
        pc_current   => pc_current,
190
        pc_plus4     => pc_plus4);
191 39 rhoads
 
192 73 rhoads
   u2_mem_ctrl: mem_ctrl
193
      PORT MAP (
194 39 rhoads
        clk          => clk,
195 60 rhoads
        reset_in     => reset,
196 73 rhoads
        pause_in     => pause_non_ctrl,
197 39 rhoads
        nullify_op   => nullify_op,
198 139 rhoads
        address_pc   => pc_future,
199 39 rhoads
        opcode_out   => opcode,
200
 
201 139 rhoads
        address_in   => c_bus,
202 39 rhoads
        mem_source   => mem_source,
203
        data_write   => reg_target,
204
        data_read    => c_memory,
205 73 rhoads
        pause_out    => pause_ctrl,
206 39 rhoads
 
207 139 rhoads
        mem_address  => mem_address(31 downto 2),
208 39 rhoads
        mem_data_w   => mem_data_w,
209
        mem_data_r   => mem_data_r,
210 139 rhoads
        mem_byte_we  => mem_byte_we);
211 39 rhoads
 
212
   u3_control: control PORT MAP (
213
        opcode       => opcode,
214
        intr_signal  => intr_signal,
215
        rs_index     => rs_index,
216
        rt_index     => rt_index,
217
        rd_index     => rd_index,
218
        imm_out      => imm,
219 73 rhoads
        alu_func     => alu_func,
220
        shift_func   => shift_func,
221
        mult_func    => mult_func,
222
        branch_func  => branch_func,
223 39 rhoads
        a_source_out => a_source,
224
        b_source_out => b_source,
225
        c_source_out => c_source,
226
        pc_source_out=> pc_source,
227
        mem_source_out=> mem_source);
228
 
229 47 rhoads
   u4_reg_bank: reg_bank
230
      generic map(memory_type => memory_type)
231
      port map (
232 39 rhoads
        clk            => clk,
233 60 rhoads
        reset_in       => reset,
234 73 rhoads
        pause          => pause_bank,
235 39 rhoads
        rs_index       => rs_index,
236
        rt_index       => rt_index,
237 73 rhoads
        rd_index       => rd_indexD,
238 39 rhoads
        reg_source_out => reg_source,
239
        reg_target_out => reg_target,
240 73 rhoads
        reg_dest_new   => reg_destD,
241 39 rhoads
        intr_enable    => intr_enable);
242
 
243
   u5_bus_mux: bus_mux port map (
244
        imm_in       => imm,
245
        reg_source   => reg_source,
246
        a_mux        => a_source,
247
        a_out        => a_bus,
248
 
249
        reg_target   => reg_target,
250
        b_mux        => b_source,
251
        b_out        => b_bus,
252
 
253
        c_bus        => c_bus,
254
        c_memory     => c_memory,
255 139 rhoads
        c_pc         => pc_current,
256 39 rhoads
        c_pc_plus4   => pc_plus4,
257
        c_mux        => c_source,
258
        reg_dest_out => reg_dest,
259
 
260 73 rhoads
        branch_func  => branch_func,
261 39 rhoads
        take_branch  => take_branch);
262
 
263 47 rhoads
   u6_alu: alu
264 139 rhoads
      generic map (alu_type => alu_type)
265 47 rhoads
      port map (
266 73 rhoads
        a_in         => a_busD,
267
        b_in         => b_busD,
268
        alu_function => alu_funcD,
269 39 rhoads
        c_alu        => c_alu);
270
 
271 114 rhoads
   u7_shifter: shifter
272
      generic map (shifter_type => shifter_type)
273
      port map (
274 73 rhoads
        value        => b_busD,
275
        shift_amount => a_busD(4 downto 0),
276
        shift_func   => shift_funcD,
277 39 rhoads
        c_shift      => c_shift);
278
 
279 47 rhoads
   u8_mult: mult
280 139 rhoads
      generic map (mult_type => mult_type)
281 47 rhoads
      port map (
282 39 rhoads
        clk       => clk,
283 128 rhoads
        reset_in  => reset,
284 73 rhoads
        a         => a_busD,
285
        b         => b_busD,
286
        mult_func => mult_funcD,
287 39 rhoads
        c_mult    => c_mult,
288
        pause_out => pause_mult);
289
 
290 139 rhoads
   pipeline3: if pipeline_stages <= 3 generate
291 73 rhoads
      a_busD <= a_bus;
292
      b_busD <= b_bus;
293
      alu_funcD <= alu_func;
294
      shift_funcD <= shift_func;
295
      mult_funcD <= mult_func;
296
      rd_indexD <= rd_index;
297
      reg_destD <= reg_dest;
298
      pause_pipeline <= '0';
299
   end generate; --pipeline2
300
 
301 139 rhoads
   pipeline4: if pipeline_stages > 3 generate
302
      --When operating in four stage pipeline mode, the following signals
303 73 rhoads
      --are delayed by one clock cycle:  a_bus, b_bus, alu/shift/mult_func,
304
      --c_source, and rd_index.
305
   u9_pipeline: pipeline port map (
306
        clk            => clk,
307
        reset          => reset,
308
        a_bus          => a_bus,
309
        a_busD         => a_busD,
310
        b_bus          => b_bus,
311
        b_busD         => b_busD,
312
        alu_func       => alu_func,
313
        alu_funcD      => alu_funcD,
314
        shift_func     => shift_func,
315
        shift_funcD    => shift_funcD,
316
        mult_func      => mult_func,
317
        mult_funcD     => mult_funcD,
318
        reg_dest       => reg_dest,
319
        reg_destD      => reg_destD,
320
        rd_index       => rd_index,
321
        rd_indexD      => rd_indexD,
322
 
323
        rs_index       => rs_index,
324
        rt_index       => rt_index,
325
        pc_source      => pc_source,
326
        mem_source     => mem_source,
327
        a_source       => a_source,
328
        b_source       => b_source,
329
        c_source       => c_source,
330
        c_bus          => c_bus,
331
        pause_any      => pause_any,
332
        pause_pipeline => pause_pipeline);
333
 
334 139 rhoads
   end generate; --pipeline4
335
 
336 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.