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

Subversion Repositories plasma

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

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
use ieee.std_logic_1164.all;
71 73 rhoads
use ieee.std_logic_unsigned.all;
72 39 rhoads
use work.mlite_pack.all;
73
 
74
entity mlite_cpu is
75 73 rhoads
   generic(memory_type     : string  := "ALTERA";
76
           pipeline_stages : natural := 3;
77 83 rhoads
           accurate_timing : boolean := true);
78 39 rhoads
   port(clk         : in std_logic;
79
        reset_in    : in std_logic;
80
        intr_in     : in std_logic;
81
 
82
        mem_address : out std_logic_vector(31 downto 0);
83
        mem_data_w  : out std_logic_vector(31 downto 0);
84
        mem_data_r  : in std_logic_vector(31 downto 0);
85
        mem_byte_sel: out std_logic_vector(3 downto 0);
86
        mem_write   : out std_logic;
87
        mem_pause   : in std_logic);
88
end; --entity mlite_cpu
89
 
90
architecture logic of mlite_cpu is
91 73 rhoads
   --When using a two stage pipeline "sigD <= sig".
92
   --When using a three stage pipeline "sigD <= sig when rising_edge(clk)",
93
   --  so sigD is delayed by one clock cycle.
94 39 rhoads
   signal opcode         : std_logic_vector(31 downto 0);
95 73 rhoads
   signal rs_index       : std_logic_vector(5 downto 0);
96
   signal rt_index       : std_logic_vector(5 downto 0);
97
   signal rd_index       : std_logic_vector(5 downto 0);
98
   signal rd_indexD      : std_logic_vector(5 downto 0);
99
   signal reg_source     : std_logic_vector(31 downto 0);
100
   signal reg_target     : std_logic_vector(31 downto 0);
101
   signal reg_dest       : std_logic_vector(31 downto 0);
102
   signal reg_destD      : std_logic_vector(31 downto 0);
103
   signal a_bus          : std_logic_vector(31 downto 0);
104
   signal a_busD         : std_logic_vector(31 downto 0);
105
   signal b_bus          : std_logic_vector(31 downto 0);
106
   signal b_busD         : std_logic_vector(31 downto 0);
107
   signal c_bus          : std_logic_vector(31 downto 0);
108
   signal c_alu          : std_logic_vector(31 downto 0);
109
   signal c_shift        : std_logic_vector(31 downto 0);
110
   signal c_mult         : std_logic_vector(31 downto 0);
111
   signal c_memory       : std_logic_vector(31 downto 0);
112 39 rhoads
   signal imm            : std_logic_vector(15 downto 0);
113
   signal pc             : std_logic_vector(31 downto 0);
114
   signal pc_plus4       : std_logic_vector(31 downto 0);
115 73 rhoads
   signal alu_func       : alu_function_type;
116
   signal alu_funcD      : alu_function_type;
117
   signal shift_func     : shift_function_type;
118
   signal shift_funcD    : shift_function_type;
119
   signal mult_func      : mult_function_type;
120
   signal mult_funcD     : mult_function_type;
121
   signal branch_func    : branch_function_type;
122 39 rhoads
   signal take_branch    : std_logic;
123
   signal a_source       : a_source_type;
124
   signal b_source       : b_source_type;
125
   signal c_source       : c_source_type;
126
   signal pc_source      : pc_source_type;
127
   signal mem_source     : mem_source_type;
128
   signal pause_mult     : std_logic;
129 73 rhoads
   signal pause_ctrl     : std_logic;
130
   signal pause_pipeline : std_logic;
131
   signal pause_any      : std_logic;
132
   signal pause_non_ctrl : std_logic;
133
   signal pause_bank     : std_logic;
134 39 rhoads
   signal nullify_op     : std_logic;
135
   signal intr_enable    : std_logic;
136
   signal intr_signal    : std_logic;
137 73 rhoads
   signal reset_reg      : std_logic_vector(3 downto 0);
138 60 rhoads
   signal reset          : std_logic;
139 39 rhoads
begin  --architecture
140
 
141 73 rhoads
   pause_any <= (mem_pause or pause_ctrl) or (pause_mult or pause_pipeline);
142
   pause_non_ctrl <= (mem_pause or pause_mult) or pause_pipeline;
143
   pause_bank <= (mem_pause or pause_ctrl or pause_mult) and not pause_pipeline;
144 96 rhoads
   nullify_op <= '1' when pc_source = from_lbranch and take_branch = '0' else '0';
145 39 rhoads
   c_bus <= c_alu or c_shift or c_mult;
146 73 rhoads
   reset <= '1' when reset_in = '1' or reset_reg /= "1111" else '0';
147 39 rhoads
 
148 73 rhoads
   --synchronize reset and interrupt pins
149 83 rhoads
   intr_proc: process(clk, reset_in, reset_reg, intr_in, intr_enable,
150
      pc_source, pc, pause_any)
151 73 rhoads
   begin
152
      if reset_in = '1' then
153
         reset_reg <= "0000";
154
      elsif rising_edge(clk) then
155
         if reset_reg /= "1111" then
156
            reset_reg <= reset_reg + 1;
157
         end if;
158 39 rhoads
      end if;
159 73 rhoads
      if rising_edge(clk) then
160
         --don't try to interrupt a multi-cycle instruction
161
         if intr_in = '1' and intr_enable = '1' and
162
               pc_source = from_inc4 and pc(2) = '0' and
163
               pause_any = '0' then
164
            --the epc will be backed up one opcode (pc-4)
165
            intr_signal <= '1';
166
         else
167
            intr_signal <= '0';
168
         end if;
169
      end if;
170
   end process;
171 39 rhoads
 
172
   u1_pc_next: pc_next PORT MAP (
173
        clk          => clk,
174 60 rhoads
        reset_in     => reset,
175 96 rhoads
        take_branch  => take_branch,
176 73 rhoads
        pause_in     => pause_any,
177
        pc_new       => c_bus(31 downto 2),
178 39 rhoads
        opcode25_0   => opcode(25 downto 0),
179
        pc_source    => pc_source,
180
        pc_out       => pc,
181
        pc_out_plus4 => pc_plus4);
182
 
183 73 rhoads
   u2_mem_ctrl: mem_ctrl
184
      generic map (ACCURATE_TIMING => accurate_timing)
185
      PORT MAP (
186 39 rhoads
        clk          => clk,
187 60 rhoads
        reset_in     => reset,
188 73 rhoads
        pause_in     => pause_non_ctrl,
189 39 rhoads
        nullify_op   => nullify_op,
190
        address_pc   => pc,
191
        opcode_out   => opcode,
192
 
193 73 rhoads
        address_data => c_bus,
194 39 rhoads
        mem_source   => mem_source,
195
        data_write   => reg_target,
196
        data_read    => c_memory,
197 73 rhoads
        pause_out    => pause_ctrl,
198 39 rhoads
 
199
        mem_address  => mem_address,
200
        mem_data_w   => mem_data_w,
201
        mem_data_r   => mem_data_r,
202
        mem_byte_sel => mem_byte_sel,
203 73 rhoads
        mem_write    => mem_write);
204 39 rhoads
 
205
   u3_control: control PORT MAP (
206
        opcode       => opcode,
207
        intr_signal  => intr_signal,
208
        rs_index     => rs_index,
209
        rt_index     => rt_index,
210
        rd_index     => rd_index,
211
        imm_out      => imm,
212 73 rhoads
        alu_func     => alu_func,
213
        shift_func   => shift_func,
214
        mult_func    => mult_func,
215
        branch_func  => branch_func,
216 39 rhoads
        a_source_out => a_source,
217
        b_source_out => b_source,
218
        c_source_out => c_source,
219
        pc_source_out=> pc_source,
220
        mem_source_out=> mem_source);
221
 
222 47 rhoads
   u4_reg_bank: reg_bank
223
      generic map(memory_type => memory_type)
224
      port map (
225 39 rhoads
        clk            => clk,
226 60 rhoads
        reset_in       => reset,
227 73 rhoads
        pause          => pause_bank,
228 39 rhoads
        rs_index       => rs_index,
229
        rt_index       => rt_index,
230 73 rhoads
        rd_index       => rd_indexD,
231 39 rhoads
        reg_source_out => reg_source,
232
        reg_target_out => reg_target,
233 73 rhoads
        reg_dest_new   => reg_destD,
234 39 rhoads
        intr_enable    => intr_enable);
235
 
236
   u5_bus_mux: bus_mux port map (
237
        imm_in       => imm,
238
        reg_source   => reg_source,
239
        a_mux        => a_source,
240
        a_out        => a_bus,
241
 
242
        reg_target   => reg_target,
243
        b_mux        => b_source,
244
        b_out        => b_bus,
245
 
246
        c_bus        => c_bus,
247
        c_memory     => c_memory,
248
        c_pc         => pc,
249
        c_pc_plus4   => pc_plus4,
250
        c_mux        => c_source,
251
        reg_dest_out => reg_dest,
252
 
253 73 rhoads
        branch_func  => branch_func,
254 39 rhoads
        take_branch  => take_branch);
255
 
256 47 rhoads
   u6_alu: alu
257
      generic map (adder_type => memory_type)
258
      port map (
259 73 rhoads
        a_in         => a_busD,
260
        b_in         => b_busD,
261
        alu_function => alu_funcD,
262 39 rhoads
        c_alu        => c_alu);
263
 
264
   u7_shifter: shifter port map (
265 73 rhoads
        value        => b_busD,
266
        shift_amount => a_busD(4 downto 0),
267
        shift_func   => shift_funcD,
268 39 rhoads
        c_shift      => c_shift);
269
 
270 47 rhoads
   u8_mult: mult
271
      generic map (adder_type => memory_type)
272
      port map (
273 39 rhoads
        clk       => clk,
274 73 rhoads
        a         => a_busD,
275
        b         => b_busD,
276
        mult_func => mult_funcD,
277 39 rhoads
        c_mult    => c_mult,
278
        pause_out => pause_mult);
279
 
280 73 rhoads
   pipeline2: if pipeline_stages <= 2 generate
281
      a_busD <= a_bus;
282
      b_busD <= b_bus;
283
      alu_funcD <= alu_func;
284
      shift_funcD <= shift_func;
285
      mult_funcD <= mult_func;
286
      rd_indexD <= rd_index;
287
 
288
      reg_destD <= reg_dest;
289
      pause_pipeline <= '0';
290
   end generate; --pipeline2
291
 
292
   pipeline3: if pipeline_stages >= 3 generate
293
      --When operating in three stage pipeline mode, the following signals
294
      --are delayed by one clock cycle:  a_bus, b_bus, alu/shift/mult_func,
295
      --c_source, and rd_index.
296
   u9_pipeline: pipeline port map (
297
        clk            => clk,
298
        reset          => reset,
299
        a_bus          => a_bus,
300
        a_busD         => a_busD,
301
        b_bus          => b_bus,
302
        b_busD         => b_busD,
303
        alu_func       => alu_func,
304
        alu_funcD      => alu_funcD,
305
        shift_func     => shift_func,
306
        shift_funcD    => shift_funcD,
307
        mult_func      => mult_func,
308
        mult_funcD     => mult_funcD,
309
        reg_dest       => reg_dest,
310
        reg_destD      => reg_destD,
311
        rd_index       => rd_index,
312
        rd_indexD      => rd_indexD,
313
 
314
        rs_index       => rs_index,
315
        rt_index       => rt_index,
316
        pc_source      => pc_source,
317
        mem_source     => mem_source,
318
        a_source       => a_source,
319
        b_source       => b_source,
320
        c_source       => c_source,
321
        c_bus          => c_bus,
322
        pause_any      => pause_any,
323
        pause_pipeline => pause_pipeline);
324
   end generate; --pipeline3
325
 
326 39 rhoads
end; --architecture logic
327
 

powered by: WebSVN 2.1.0

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