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

Subversion Repositories plasma

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

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

powered by: WebSVN 2.1.0

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