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

Subversion Repositories plasma

[/] [plasma/] [tags/] [V3_0/] [vhdl/] [mlite_cpu.vhd] - Blame information for rev 43

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
-- Top level VHDL document that ties the eight other entities together.
14 43 rhoads
-- Executes most MIPS I(tm) opcodes.  Based on information found in:
15 39 rhoads
--    "MIPS RISC Architecture" by Gerry Kane and Joe Heinrich
16
--    and "The Designer's Guide to VHDL" by Peter J. Ashenden
17
-- An add instruction would take the following steps (see cpu.gif):
18
--    1.  The "pc_next" entity would have previously passed the program
19
--        counter (PC) to the "mem_ctrl" entity.
20
--    2.  "Mem_ctrl" passes the opcode to the "control" entity.
21
--    3.  "Control" converts the 32-bit opcode to a 60-bit VLWI opcode
22
--        and sends control signals to the other entities.
23
--    4.  Based on the rs_index and rt_index control signals, "reg_bank" 
24
--        sends the 32-bit reg_source and reg_target to "bus_mux".
25
--    5.  Based on the a_source and b_source control signals, "bus_mux"
26
--        multiplexes reg_source onto a_bus and reg_target onto b_bus.
27
--    6.  Based on the alu_func control signals, "alu" adds the values
28
--        from a_bus and b_bus and places the result on c_bus.
29
--    7.  Based on the c_source control signals, "bus_bux" multiplexes
30
--        c_bus onto reg_dest.
31
--    8.  Based on the rd_index control signal, "reg_bank" saves
32
--        reg_dest into the correct register.
33
-- The CPU is implemented as a two stage pipeline with step #1 in the
34
-- first stage and steps #2-8 occuring the second stage.
35
--
36
-- Writing to memory takes four cycles to meet RAM address hold times.
37
-- Addresses with a(31)='1' take two cycles (assumed to be clocked).
38
-- Here are the signals for writing a character to address 0xffff:
39
--
40
--      mem_write                           
41
--    interrupt                     mem_byte_sel
42
--      reset                        mem_pause  
43
--       ns    mem_address m_data_w m_data_r    
44
--   ===========================================
45
--     6700 0 0 0 000002A4 ZZZZZZZZ A0AE0000 0 0  (  fetch write opcode)
46
--     6800 0 0 0 000002B0 ZZZZZZZZ 0443FFF6 0 0  (1 fetch NEXT opcode)
47
--     6900 0 0 1 0000FFFF 31313131 ZZZZZZZZ 0 0  (2 address hold)
48
--     7000 0 0 1 0000FFFF 31313131 ZZZZZZZZ 0 1  (3 write the low byte)
49
--     7100 0 0 1 0000FFFF 31313131 ZZZZZZZZ 0 0  (4 address hold)
50
--     7200 0 0 0 000002B4 ZZZZZZZZ 00441806 0 0  (  execute NEXT opcode)
51
--
52
-- The CPU core was synthesized for 0.13 um line widths with an area
53
-- of 0.2 millimeters squared.  The maximum latency was less than 6 ns 
54
-- for a maximum clock speed of 150 MHz.
55
---------------------------------------------------------------------
56
library ieee;
57
use ieee.std_logic_1164.all;
58
use work.mlite_pack.all;
59
 
60
entity mlite_cpu is
61
   port(clk         : in std_logic;
62
        reset_in    : in std_logic;
63
        intr_in     : in std_logic;
64
 
65
        mem_address : out std_logic_vector(31 downto 0);
66
        mem_data_w  : out std_logic_vector(31 downto 0);
67
        mem_data_r  : in std_logic_vector(31 downto 0);
68
        mem_byte_sel: out std_logic_vector(3 downto 0);
69
        mem_write   : out std_logic;
70
        mem_pause   : in std_logic);
71
end; --entity mlite_cpu
72
 
73
architecture logic of mlite_cpu is
74
 
75
component pc_next
76
   port(clk          : in std_logic;
77
        reset_in     : in std_logic;
78
        pc_new       : in std_logic_vector(31 downto 2);
79
        take_branch  : in std_logic;
80
        pause_in     : in std_logic;
81
        opcode25_0   : in std_logic_vector(25 downto 0);
82
        pc_source    : in pc_source_type;
83
        pc_out       : out std_logic_vector(31 downto 0);
84
        pc_out_plus4 : out std_logic_vector(31 downto 0));
85
end component;
86
 
87
component mem_ctrl
88
   port(clk          : in std_logic;
89
        reset_in     : in std_logic;
90
        pause_in     : in std_logic;
91
        nullify_op   : in std_logic;
92
        address_pc   : in std_logic_vector(31 downto 0);
93
        opcode_out   : out std_logic_vector(31 downto 0);
94
 
95
        address_data : in std_logic_vector(31 downto 0);
96
        mem_source   : in mem_source_type;
97
        data_write   : in std_logic_vector(31 downto 0);
98
        data_read    : out std_logic_vector(31 downto 0);
99
        pause_out    : out std_logic;
100
 
101
        mem_address  : out std_logic_vector(31 downto 0);
102
        mem_data_w   : out std_logic_vector(31 downto 0);
103
        mem_data_r   : in std_logic_vector(31 downto 0);
104
        mem_byte_sel : out std_logic_vector(3 downto 0);
105
        mem_write    : out std_logic;
106
        mem_pause    : in std_logic);
107
end component;
108
 
109
component control
110
   port(opcode       : in  std_logic_vector(31 downto 0);
111
        intr_signal  : in  std_logic;
112
        pause_in     : in  std_logic;
113
        rs_index     : out std_logic_vector(5 downto 0);
114
        rt_index     : out std_logic_vector(5 downto 0);
115
        rd_index     : out std_logic_vector(5 downto 0);
116
        imm_out      : out std_logic_vector(15 downto 0);
117
        alu_func     : out alu_function_type;
118
        shift_func   : out shift_function_type;
119
        mult_func    : out mult_function_type;
120
        branch_func  : out branch_function_type;
121
        a_source_out : out a_source_type;
122
        b_source_out : out b_source_type;
123
        c_source_out : out c_source_type;
124
        pc_source_out: out pc_source_type;
125
        mem_source_out:out mem_source_type);
126
end component;
127
 
128
component reg_bank
129
   port(clk            : in  std_logic;
130
        reset_in       : in  std_logic;
131
        rs_index       : in  std_logic_vector(5 downto 0);
132
        rt_index       : in  std_logic_vector(5 downto 0);
133
        rd_index       : in  std_logic_vector(5 downto 0);
134
        reg_source_out : out std_logic_vector(31 downto 0);
135
        reg_target_out : out std_logic_vector(31 downto 0);
136
        reg_dest_new   : in  std_logic_vector(31 downto 0);
137
        intr_enable    : out std_logic);
138
end component;
139
 
140
component bus_mux
141
   port(imm_in       : in  std_logic_vector(15 downto 0);
142
        reg_source   : in  std_logic_vector(31 downto 0);
143
        a_mux        : in  a_source_type;
144
        a_out        : out std_logic_vector(31 downto 0);
145
 
146
        reg_target   : in  std_logic_vector(31 downto 0);
147
        b_mux        : in  b_source_type;
148
        b_out        : out std_logic_vector(31 downto 0);
149
 
150
        c_bus        : in  std_logic_vector(31 downto 0);
151
        c_memory     : in  std_logic_vector(31 downto 0);
152
        c_pc         : in  std_logic_vector(31 downto 0);
153
        c_pc_plus4   : in  std_logic_vector(31 downto 0);
154
        c_mux        : in  c_source_type;
155
        reg_dest_out : out std_logic_vector(31 downto 0);
156
 
157
        branch_func  : in  branch_function_type;
158
        take_branch  : out std_logic);
159
end component;
160
 
161
component alu
162
   port(a_in         : in  std_logic_vector(31 downto 0);
163
        b_in         : in  std_logic_vector(31 downto 0);
164
        alu_function : in  alu_function_type;
165
        c_alu        : out std_logic_vector(31 downto 0));
166
end component;
167
 
168
component shifter
169
   port(value        : in  std_logic_vector(31 downto 0);
170
        shift_amount : in  std_logic_vector(4 downto 0);
171
        shift_func   : in  shift_function_type;
172
        c_shift      : out std_logic_vector(31 downto 0));
173
end component;
174
 
175
component mult
176
   port(clk       : in std_logic;
177
        a, b      : in std_logic_vector(31 downto 0);
178
        mult_func : in mult_function_type;
179
        c_mult    : out std_logic_vector(31 downto 0);
180
        pause_out : out std_logic);
181
end component;
182
 
183
   signal opcode         : std_logic_vector(31 downto 0);
184
   signal rs_index, rt_index, rd_index     : std_logic_vector(5 downto 0);
185
   signal reg_source, reg_target, reg_dest : std_logic_vector(31 downto 0);
186
   signal a_bus, b_bus, c_bus : std_logic_vector(31 downto 0);
187
   signal c_alu, c_shift, c_mult, c_memory
188
        : std_logic_vector(31 downto 0);
189
   signal imm            : std_logic_vector(15 downto 0);
190
   signal pc             : std_logic_vector(31 downto 0);
191
   signal pc_plus4       : std_logic_vector(31 downto 0);
192
   signal alu_function   : alu_function_type;
193
   signal shift_function : shift_function_type;
194
   signal mult_function  : mult_function_type;
195
   signal branch_function: branch_function_type;
196
   signal take_branch    : std_logic;
197
   signal a_source       : a_source_type;
198
   signal b_source       : b_source_type;
199
   signal c_source       : c_source_type;
200
   signal pc_source      : pc_source_type;
201
   signal mem_source     : mem_source_type;
202
   signal pause_mult     : std_logic;
203
   signal pause_memory   : std_logic;
204
   signal pause          : std_logic;
205
   signal nullify_op     : std_logic;
206
   signal intr_enable    : std_logic;
207
   signal intr_signal    : std_logic;
208
   signal reset_reg      : std_logic;
209
begin  --architecture
210
 
211
   pause <= pause_mult or pause_memory;
212
   nullify_op <= '1' when pc_source = from_lbranch and
213
                     (take_branch = '0' or branch_function = branch_yes) else
214
                 '0';
215
   c_bus <= c_alu or c_shift or c_mult;
216
 
217
--synchronize reset and interrupt pins
218
intr_proc: process(clk, reset_in, intr_in, intr_enable, pc_source, pc, pause)
219
begin
220
   if rising_edge(clk) then
221
      reset_reg <= reset_in;
222
      --don't try to interrupt a multi-cycle instruction
223
      if intr_in = '1' and intr_enable = '1' and
224
            pc_source = from_inc4 and
225
            pc(2) = '0' and
226
            pause = '0' then
227
         --the epc will be backed up one opcode (pc-4)
228
         intr_signal <= '1';
229
      else
230
         intr_signal <= '0';
231
      end if;
232
   end if;
233
end process;
234
 
235
   u1_pc_next: pc_next PORT MAP (
236
        clk          => clk,
237
        reset_in     => reset_reg,
238
        take_branch  => take_branch,
239
        pause_in     => pause,
240
        pc_new       => c_alu(31 downto 2),
241
        opcode25_0   => opcode(25 downto 0),
242
        pc_source    => pc_source,
243
        pc_out       => pc,
244
        pc_out_plus4 => pc_plus4);
245
 
246
   u2_mem_ctrl: mem_ctrl PORT MAP (
247
        clk          => clk,
248
        reset_in     => reset_reg,
249
        pause_in     => pause,
250
        nullify_op   => nullify_op,
251
        address_pc   => pc,
252
        opcode_out   => opcode,
253
 
254
        address_data => c_alu,
255
        mem_source   => mem_source,
256
        data_write   => reg_target,
257
        data_read    => c_memory,
258
        pause_out    => pause_memory,
259
 
260
        mem_address  => mem_address,
261
        mem_data_w   => mem_data_w,
262
        mem_data_r   => mem_data_r,
263
        mem_byte_sel => mem_byte_sel,
264
        mem_write    => mem_write,
265
        mem_pause    => mem_pause);
266
 
267
   u3_control: control PORT MAP (
268
        opcode       => opcode,
269
        intr_signal  => intr_signal,
270
        pause_in     => pause,
271
        rs_index     => rs_index,
272
        rt_index     => rt_index,
273
        rd_index     => rd_index,
274
        imm_out      => imm,
275
        alu_func     => alu_function,
276
        shift_func   => shift_function,
277
        mult_func    => mult_function,
278
        branch_func  => branch_function,
279
        a_source_out => a_source,
280
        b_source_out => b_source,
281
        c_source_out => c_source,
282
        pc_source_out=> pc_source,
283
        mem_source_out=> mem_source);
284
 
285
   u4_reg_bank: reg_bank port map (
286
        clk            => clk,
287
        reset_in       => reset_reg,
288
        rs_index       => rs_index,
289
        rt_index       => rt_index,
290
        rd_index       => rd_index,
291
        reg_source_out => reg_source,
292
        reg_target_out => reg_target,
293
        reg_dest_new   => reg_dest,
294
        intr_enable    => intr_enable);
295
 
296
   u5_bus_mux: bus_mux port map (
297
        imm_in       => imm,
298
        reg_source   => reg_source,
299
        a_mux        => a_source,
300
        a_out        => a_bus,
301
 
302
        reg_target   => reg_target,
303
        b_mux        => b_source,
304
        b_out        => b_bus,
305
 
306
        c_bus        => c_bus,
307
        c_memory     => c_memory,
308
        c_pc         => pc,
309
        c_pc_plus4   => pc_plus4,
310
        c_mux        => c_source,
311
        reg_dest_out => reg_dest,
312
 
313
        branch_func  => branch_function,
314
        take_branch  => take_branch);
315
 
316
   u6_alu: alu port map (
317
        a_in         => a_bus,
318
        b_in         => b_bus,
319
        alu_function => alu_function,
320
        c_alu        => c_alu);
321
 
322
   u7_shifter: shifter port map (
323
        value        => b_bus,
324
        shift_amount => a_bus(4 downto 0),
325
        shift_func   => shift_function,
326
        c_shift      => c_shift);
327
 
328
   u8_mult: mult port map (
329
        clk       => clk,
330
        a         => a_bus,
331
        b         => b_bus,
332
        mult_func => mult_function,
333
        c_mult    => c_mult,
334
        pause_out => pause_mult);
335
 
336
end; --architecture logic
337
 

powered by: WebSVN 2.1.0

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