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

Subversion Repositories plasma

[/] [plasma/] [tags/] [V2_1/] [vhdl/] [mlite_cpu.vhd] - Blame information for rev 350

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
-- 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 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 39 rhoads
--    2.  "Mem_ctrl" passes the opcode to the "control" entity.
27
--    3.  "Control" converts the 32-bit opcode to a 60-bit VLWI opcode
28
--        and sends control signals to the other entities.
29
--    4.  Based on the rs_index and rt_index control signals, "reg_bank" 
30
--        sends the 32-bit reg_source and reg_target to "bus_mux".
31
--    5.  Based on the a_source and b_source control signals, "bus_mux"
32
--        multiplexes reg_source onto a_bus and reg_target onto b_bus.
33 83 rhoads
-- Stage #3:
34 39 rhoads
--    6.  Based on the alu_func control signals, "alu" adds the values
35
--        from a_bus and b_bus and places the result on c_bus.
36
--    7.  Based on the c_source control signals, "bus_bux" multiplexes
37
--        c_bus onto reg_dest.
38
--    8.  Based on the rd_index control signal, "reg_bank" saves
39
--        reg_dest into the correct register.
40
--
41 83 rhoads
-- All signals are active high.  Writing to high memory where a(31)='1' 
42
-- takes five cycles to meet RAM address hold times.
43
-- Addresses with a(31)='0' are assumed to be clocked and take three cycles.
44 39 rhoads
-- Here are the signals for writing a character to address 0xffff:
45
--
46 83 rhoads
--      intr_in                        mem_pause    
47
--   reset_in                        mem_write      
48
--      clk                     mem_byte_sel        
49
--     ns    mem_address m_data_r m_data_w 
50
-- =============================================
51
--   3000 1 0 0 0000002C A2820000 ZZZZZZZZ 0 0 0  (0 fetch write opcode)
52
--   3050 0 0 0 0000002C A2820000 ZZZZZZZZ 0 0 0
53
--   3100 1 0 0 00000030 340A0041 ZZZZZZZZ 0 0 0  (1 execute write opcode)
54
--   3150 0 0 0 00000030 340A0041 ZZZZZZZZ 0 0 0
55
--   3200 1 0 0 00000030 340A0041 ZZZZZZZZ 0 0 0  (2 calculating address)
56
--   3250 0 0 0 00000030 340A0041 ZZZZZZZZ 0 0 0
57
--   3300 1 0 0 0000FFFF ZZZZZZZZ 6A6A6A6A 1 1 0  (3 writing value)
58
--   3350 0 0 0 0000FFFF ZZZZZZZZ 6A6A6A6A 1 1 0
59
--   3400 1 0 0 00000034 340B0042 ZZZZZZZZ 0 0 0
60
--   3450 0 0 0 00000034 340B0042 ZZZZZZZZ 0 0 0
61
--
62
-- Program:
63
-- addr     value  opcode   args
64
-- ===================================
65
-- 002c  a2820000      sb   $v0,0($s4)
66
-- 0030  340a0041      li   $t2,0x41
67
-- 0034  340b0042      li   $t3,0x42
68 39 rhoads
---------------------------------------------------------------------
69
library ieee;
70 114 rhoads
use work.mlite_pack.all;
71
--library ieee, mlite_lib;
72
--use mlite_lib.mlite_pack.all;
73 39 rhoads
use ieee.std_logic_1164.all;
74 73 rhoads
use ieee.std_logic_unsigned.all;
75 39 rhoads
 
76
entity mlite_cpu is
77 120 rhoads
   generic(memory_type     : string  := "GENERIC"; --DUAL_PORT_XILINX_XC4000XLA
78
           adder_type      : string  := "GENERIC"; --AREA_OPTIMIZED
79
           mult_type       : string  := "GENERIC"; --AREA_OPTIMIZED
80
           shifter_type    : string  := "GENERIC"; --AREA_OPTIMIZED
81
           alu_type        : string  := "GENERIC"; --AREA_OPTIMIZED
82 73 rhoads
           pipeline_stages : natural := 3;
83 83 rhoads
           accurate_timing : boolean := true);
84 39 rhoads
   port(clk         : in std_logic;
85
        reset_in    : in std_logic;
86
        intr_in     : in std_logic;
87
 
88
        mem_address : out std_logic_vector(31 downto 0);
89
        mem_data_w  : out std_logic_vector(31 downto 0);
90
        mem_data_r  : in std_logic_vector(31 downto 0);
91
        mem_byte_sel: out std_logic_vector(3 downto 0);
92
        mem_write   : out std_logic;
93
        mem_pause   : in std_logic);
94
end; --entity mlite_cpu
95
 
96
architecture logic of mlite_cpu is
97 73 rhoads
   --When using a two stage pipeline "sigD <= sig".
98
   --When using a three stage pipeline "sigD <= sig when rising_edge(clk)",
99
   --  so sigD is delayed by one clock cycle.
100 39 rhoads
   signal opcode         : std_logic_vector(31 downto 0);
101 73 rhoads
   signal rs_index       : std_logic_vector(5 downto 0);
102
   signal rt_index       : std_logic_vector(5 downto 0);
103
   signal rd_index       : std_logic_vector(5 downto 0);
104
   signal rd_indexD      : std_logic_vector(5 downto 0);
105
   signal reg_source     : std_logic_vector(31 downto 0);
106
   signal reg_target     : std_logic_vector(31 downto 0);
107
   signal reg_dest       : std_logic_vector(31 downto 0);
108
   signal reg_destD      : std_logic_vector(31 downto 0);
109
   signal a_bus          : std_logic_vector(31 downto 0);
110
   signal a_busD         : std_logic_vector(31 downto 0);
111
   signal b_bus          : std_logic_vector(31 downto 0);
112
   signal b_busD         : std_logic_vector(31 downto 0);
113
   signal c_bus          : std_logic_vector(31 downto 0);
114
   signal c_alu          : std_logic_vector(31 downto 0);
115
   signal c_shift        : std_logic_vector(31 downto 0);
116
   signal c_mult         : std_logic_vector(31 downto 0);
117
   signal c_memory       : std_logic_vector(31 downto 0);
118 39 rhoads
   signal imm            : std_logic_vector(15 downto 0);
119
   signal pc             : std_logic_vector(31 downto 0);
120
   signal pc_plus4       : std_logic_vector(31 downto 0);
121 73 rhoads
   signal alu_func       : alu_function_type;
122
   signal alu_funcD      : alu_function_type;
123
   signal shift_func     : shift_function_type;
124
   signal shift_funcD    : shift_function_type;
125
   signal mult_func      : mult_function_type;
126
   signal mult_funcD     : mult_function_type;
127
   signal branch_func    : branch_function_type;
128 39 rhoads
   signal take_branch    : std_logic;
129
   signal a_source       : a_source_type;
130
   signal b_source       : b_source_type;
131
   signal c_source       : c_source_type;
132
   signal pc_source      : pc_source_type;
133
   signal mem_source     : mem_source_type;
134
   signal pause_mult     : std_logic;
135 73 rhoads
   signal pause_ctrl     : std_logic;
136
   signal pause_pipeline : std_logic;
137
   signal pause_any      : std_logic;
138
   signal pause_non_ctrl : std_logic;
139
   signal pause_bank     : std_logic;
140 39 rhoads
   signal nullify_op     : std_logic;
141
   signal intr_enable    : std_logic;
142
   signal intr_signal    : std_logic;
143 73 rhoads
   signal reset_reg      : std_logic_vector(3 downto 0);
144 60 rhoads
   signal reset          : std_logic;
145 39 rhoads
begin  --architecture
146
 
147 73 rhoads
   pause_any <= (mem_pause or pause_ctrl) or (pause_mult or pause_pipeline);
148
   pause_non_ctrl <= (mem_pause or pause_mult) or pause_pipeline;
149
   pause_bank <= (mem_pause or pause_ctrl or pause_mult) and not pause_pipeline;
150 124 rhoads
   nullify_op <= '1' when (pc_source = from_lbranch and take_branch = '0')
151
                          or intr_signal = '1'
152
                          else '0';
153 39 rhoads
   c_bus <= c_alu or c_shift or c_mult;
154 73 rhoads
   reset <= '1' when reset_in = '1' or reset_reg /= "1111" else '0';
155 39 rhoads
 
156 73 rhoads
   --synchronize reset and interrupt pins
157 83 rhoads
   intr_proc: process(clk, reset_in, reset_reg, intr_in, intr_enable,
158
      pc_source, pc, pause_any)
159 73 rhoads
   begin
160
      if reset_in = '1' then
161
         reset_reg <= "0000";
162 124 rhoads
         intr_signal <= '0';
163 73 rhoads
      elsif rising_edge(clk) then
164
         if reset_reg /= "1111" then
165
            reset_reg <= reset_reg + 1;
166
         end if;
167 124 rhoads
 
168 73 rhoads
         --don't try to interrupt a multi-cycle instruction
169 124 rhoads
         if pause_any = '0' then
170
            if intr_in = '1' and intr_enable = '1' and
171
                  pc_source = from_inc4 and pc(2) = '0' then
172
               --the epc will be backed up one opcode (pc-4)
173
               intr_signal <= '1';
174
            else
175
               intr_signal <= '0';
176
            end if;
177 73 rhoads
         end if;
178 124 rhoads
 
179 73 rhoads
      end if;
180
   end process;
181 39 rhoads
 
182
   u1_pc_next: pc_next PORT MAP (
183
        clk          => clk,
184 60 rhoads
        reset_in     => reset,
185 96 rhoads
        take_branch  => take_branch,
186 73 rhoads
        pause_in     => pause_any,
187
        pc_new       => c_bus(31 downto 2),
188 39 rhoads
        opcode25_0   => opcode(25 downto 0),
189
        pc_source    => pc_source,
190
        pc_out       => pc,
191
        pc_out_plus4 => pc_plus4);
192
 
193 73 rhoads
   u2_mem_ctrl: mem_ctrl
194
      generic map (ACCURATE_TIMING => accurate_timing)
195
      PORT MAP (
196 39 rhoads
        clk          => clk,
197 60 rhoads
        reset_in     => reset,
198 73 rhoads
        pause_in     => pause_non_ctrl,
199 39 rhoads
        nullify_op   => nullify_op,
200
        address_pc   => pc,
201
        opcode_out   => opcode,
202
 
203 73 rhoads
        address_data => c_bus,
204 39 rhoads
        mem_source   => mem_source,
205
        data_write   => reg_target,
206
        data_read    => c_memory,
207 73 rhoads
        pause_out    => pause_ctrl,
208 39 rhoads
 
209
        mem_address  => mem_address,
210
        mem_data_w   => mem_data_w,
211
        mem_data_r   => mem_data_r,
212
        mem_byte_sel => mem_byte_sel,
213 73 rhoads
        mem_write    => mem_write);
214 39 rhoads
 
215
   u3_control: control PORT MAP (
216
        opcode       => opcode,
217
        intr_signal  => intr_signal,
218
        rs_index     => rs_index,
219
        rt_index     => rt_index,
220
        rd_index     => rd_index,
221
        imm_out      => imm,
222 73 rhoads
        alu_func     => alu_func,
223
        shift_func   => shift_func,
224
        mult_func    => mult_func,
225
        branch_func  => branch_func,
226 39 rhoads
        a_source_out => a_source,
227
        b_source_out => b_source,
228
        c_source_out => c_source,
229
        pc_source_out=> pc_source,
230
        mem_source_out=> mem_source);
231
 
232 47 rhoads
   u4_reg_bank: reg_bank
233
      generic map(memory_type => memory_type)
234
      port map (
235 39 rhoads
        clk            => clk,
236 60 rhoads
        reset_in       => reset,
237 73 rhoads
        pause          => pause_bank,
238 39 rhoads
        rs_index       => rs_index,
239
        rt_index       => rt_index,
240 73 rhoads
        rd_index       => rd_indexD,
241 39 rhoads
        reg_source_out => reg_source,
242
        reg_target_out => reg_target,
243 73 rhoads
        reg_dest_new   => reg_destD,
244 39 rhoads
        intr_enable    => intr_enable);
245
 
246
   u5_bus_mux: bus_mux port map (
247
        imm_in       => imm,
248
        reg_source   => reg_source,
249
        a_mux        => a_source,
250
        a_out        => a_bus,
251
 
252
        reg_target   => reg_target,
253
        b_mux        => b_source,
254
        b_out        => b_bus,
255
 
256
        c_bus        => c_bus,
257
        c_memory     => c_memory,
258
        c_pc         => pc,
259
        c_pc_plus4   => pc_plus4,
260
        c_mux        => c_source,
261
        reg_dest_out => reg_dest,
262
 
263 73 rhoads
        branch_func  => branch_func,
264 39 rhoads
        take_branch  => take_branch);
265
 
266 47 rhoads
   u6_alu: alu
267 114 rhoads
      generic map (adder_type => adder_type,
268
                   alu_type   => alu_type)
269 47 rhoads
      port map (
270 73 rhoads
        a_in         => a_busD,
271
        b_in         => b_busD,
272
        alu_function => alu_funcD,
273 39 rhoads
        c_alu        => c_alu);
274
 
275 114 rhoads
   u7_shifter: shifter
276
      generic map (shifter_type => shifter_type)
277
      port map (
278 73 rhoads
        value        => b_busD,
279
        shift_amount => a_busD(4 downto 0),
280
        shift_func   => shift_funcD,
281 39 rhoads
        c_shift      => c_shift);
282
 
283 47 rhoads
   u8_mult: mult
284 114 rhoads
      generic map (adder_type => adder_type,
285
                   mult_type  => mult_type)
286 47 rhoads
      port map (
287 39 rhoads
        clk       => clk,
288 73 rhoads
        a         => a_busD,
289
        b         => b_busD,
290
        mult_func => mult_funcD,
291 39 rhoads
        c_mult    => c_mult,
292
        pause_out => pause_mult);
293
 
294 73 rhoads
   pipeline2: if pipeline_stages <= 2 generate
295
      a_busD <= a_bus;
296
      b_busD <= b_bus;
297
      alu_funcD <= alu_func;
298
      shift_funcD <= shift_func;
299
      mult_funcD <= mult_func;
300
      rd_indexD <= rd_index;
301
 
302
      reg_destD <= reg_dest;
303
      pause_pipeline <= '0';
304
   end generate; --pipeline2
305
 
306
   pipeline3: if pipeline_stages >= 3 generate
307
      --When operating in three stage pipeline mode, the following signals
308
      --are delayed by one clock cycle:  a_bus, b_bus, alu/shift/mult_func,
309
      --c_source, and rd_index.
310
   u9_pipeline: pipeline port map (
311
        clk            => clk,
312
        reset          => reset,
313
        a_bus          => a_bus,
314
        a_busD         => a_busD,
315
        b_bus          => b_bus,
316
        b_busD         => b_busD,
317
        alu_func       => alu_func,
318
        alu_funcD      => alu_funcD,
319
        shift_func     => shift_func,
320
        shift_funcD    => shift_funcD,
321
        mult_func      => mult_func,
322
        mult_funcD     => mult_funcD,
323
        reg_dest       => reg_dest,
324
        reg_destD      => reg_destD,
325
        rd_index       => rd_index,
326
        rd_indexD      => rd_indexD,
327
 
328
        rs_index       => rs_index,
329
        rt_index       => rt_index,
330
        pc_source      => pc_source,
331
        mem_source     => mem_source,
332
        a_source       => a_source,
333
        b_source       => b_source,
334
        c_source       => c_source,
335
        c_bus          => c_bus,
336
        pause_any      => pause_any,
337
        pause_pipeline => pause_pipeline);
338
   end generate; --pipeline3
339
 
340 39 rhoads
end; --architecture logic
341
 

powered by: WebSVN 2.1.0

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