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

Subversion Repositories plasma

[/] [plasma/] [tags/] [arelease/] [vhdl/] [mips_cpu.vhd] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 rhoads
---------------------------------------------------------------------
2
-- TITLE: MIPS CPU core
3
-- AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
4
-- DATE CREATED: 2/15/01
5
-- FILENAME: mips_cpu.vhd
6
-- PROJECT: MIPS CPU core
7
-- COPYRIGHT: Software placed into the public domain by the author.
8
--    Software 'as is' without warranty.  Author liable for nothing.
9
-- DESCRIPTION:
10
-- Top level VHDL document that ties the eight other entities together.
11
-- Implements a MIPS CPU.  Based on information found in:
12
--    "MIPS RISC Architecture" by Gerry Kane and Joe Heinrich
13
--    and "The Designer's Guide to VHDL" by Peter J. Ashenden
14
-- An add instruction would take the following steps (see cpu.gif):
15
--    1.  The "pc_next" entity would have previously passed the program
16
--        counter (PC) to the "mem_ctrl" entity.
17
--    2.  "Mem_ctrl" passes the opcode to the "control" entity.
18
--    3.  "Control" converts the 32-bit opcode to a 60-bit VLWI opcode
19
--        and sends control signals to the other entities.
20
--    4.  Based on the rs_index and rt_index control signals, "reg_bank" 
21
--        sends the 32-bit reg_source and reg_target to "bus_mux".
22
--    5.  Based on the a_source and b_source control signals, "bus_mux"
23
--        multiplexes reg_source onto a_bus and reg_target onto b_bus.
24
--    6.  Based on the alu_func control signals, "alu" adds the values
25
--        from a_bus and b_bus and places the result on c_bus.
26
--    7.  Based on the c_source control signals, "bus_bux" multiplexes
27
--        c_bus onto reg_dest.
28
--    8.  Based on the rd_index control signal, "reg_bank" saves
29
--        reg_dest into the correct register.
30
-- The CPU is implemented as a two stage pipeline with step #1 in the
31
-- first stage and steps #2-8 occuring the second stage.
32
--
33
-- The CPU core was synthesized for 0.13 um line widths with an area
34
-- of 0.2 millimeters squared.  The maximum latency was less than 6 ns 
35
-- for a maximum clock speed of 150 MHz.
36
---------------------------------------------------------------------
37
library ieee;
38
use ieee.std_logic_1164.all;
39
use work.mips_pack.all;
40
 
41
entity mips_cpu is
42
   port(clk         : in std_logic;
43
        reset_in    : in std_logic;
44
        intr_in     : in std_logic;
45
 
46
        mem_address : out std_logic_vector(31 downto 0);
47
        mem_data_w  : out std_logic_vector(31 downto 0);
48
        mem_data_r  : in std_logic_vector(31 downto 0);
49
        mem_sel     : out std_logic_vector(3 downto 0);
50
        mem_write   : out std_logic;
51
        mem_pause   : in std_logic;
52
 
53
        t_pc        : out std_logic_vector(31 downto 0);
54
        t_opcode    : out std_logic_vector(31 downto 0);
55
        t_r_dest    : out std_logic_vector(31 downto 0)
56
        );
57
end; --entity mips_cpu
58
 
59
architecture logic of mips_cpu is
60
 
61
component pc_next
62
   port(clk          : in std_logic;
63
        reset_in     : in std_logic;
64
        pc_new       : in std_logic_vector(31 downto 2);
65
        take_branch  : in std_logic;
66
        pause_in     : in std_logic;
67
        opcode25_0   : in std_logic_vector(25 downto 0);
68
        pc_source    : in pc_source_type;
69
        pc_out       : out std_logic_vector(31 downto 0));
70
end component;
71
 
72
component mem_ctrl
73
   port(clk          : in std_logic;
74
        reset_in     : in std_logic;
75
        pause_in     : in std_logic;
76
        nullify_op   : in std_logic;
77
        address_pc   : in std_logic_vector(31 downto 0);
78
        opcode_out   : out std_logic_vector(31 downto 0);
79
 
80
        address_data : in std_logic_vector(31 downto 0);
81
        mem_source   : in mem_source_type;
82
        data_write   : in std_logic_vector(31 downto 0);
83
        data_read    : out std_logic_vector(31 downto 0);
84
        pause_out    : out std_logic;
85
 
86
        mem_address  : out std_logic_vector(31 downto 0);
87
        mem_data_w   : out std_logic_vector(31 downto 0);
88
        mem_data_r   : in std_logic_vector(31 downto 0);
89
        mem_byte_sel : out std_logic_vector(3 downto 0);
90
        mem_write    : out std_logic;
91
        mem_pause    : in std_logic);
92
end component;
93
 
94
component control
95
   port(opcode       : in  std_logic_vector(31 downto 0);
96
        intr_signal  : in  std_logic;
97
        rs_index     : out std_logic_vector(5 downto 0);
98
        rt_index     : out std_logic_vector(5 downto 0);
99
        rd_index     : out std_logic_vector(5 downto 0);
100
        imm_out      : out std_logic_vector(15 downto 0);
101
        alu_func     : out alu_function_type;
102
        shift_func   : out shift_function_type;
103
        mult_func    : out mult_function_type;
104
        branch_func  : out branch_function_type;
105
        a_source_out : out a_source_type;
106
        b_source_out : out b_source_type;
107
        c_source_out : out c_source_type;
108
        pc_source_out: out pc_source_type;
109
        mem_source_out:out mem_source_type);
110
end component;
111
 
112
component reg_bank
113
   port(clk            : in  std_logic;
114
        rs_index       : in  std_logic_vector(5 downto 0);
115
        rt_index       : in  std_logic_vector(5 downto 0);
116
        rd_index       : in  std_logic_vector(5 downto 0);
117
        reg_source_out : out std_logic_vector(31 downto 0);
118
        reg_target_out : out std_logic_vector(31 downto 0);
119
        reg_dest_new   : in  std_logic_vector(31 downto 0);
120
        intr_enable    : out std_logic);
121
end component;
122
 
123
component bus_mux
124
   port(imm_in       : in  std_logic_vector(15 downto 0);
125
        reg_source   : in  std_logic_vector(31 downto 0);
126
        a_mux        : in  a_source_type;
127
        a_out        : out std_logic_vector(31 downto 0);
128
 
129
        reg_target   : in  std_logic_vector(31 downto 0);
130
        b_mux        : in  b_source_type;
131
        b_out        : out std_logic_vector(31 downto 0);
132
 
133
        c_bus        : in  std_logic_vector(31 downto 0);
134
        c_memory     : in  std_logic_vector(31 downto 0);
135
        c_pc         : in  std_logic_vector(31 downto 0);
136
        c_mux        : in  c_source_type;
137
        reg_dest_out : out std_logic_vector(31 downto 0);
138
 
139
        branch_func  : in  branch_function_type;
140
        take_branch  : out std_logic);
141
end component;
142
 
143
component alu
144
   port(a_in         : in  std_logic_vector(31 downto 0);
145
        b_in         : in  std_logic_vector(31 downto 0);
146
        alu_function : in  alu_function_type;
147
        c_alu        : out std_logic_vector(31 downto 0));
148
end component;
149
 
150
component shifter
151
   port(value        : in  std_logic_vector(31 downto 0);
152
        shift_amount : in  std_logic_vector(4 downto 0);
153
        shift_func   : in  shift_function_type;
154
        c_shift      : out std_logic_vector(31 downto 0));
155
end component;
156
 
157
component mult
158
   port(clk       : in std_logic;
159
        a, b      : in std_logic_vector(31 downto 0);
160
        mult_func : in mult_function_type;
161
        c_mult    : out std_logic_vector(31 downto 0);
162
        pause_out : out std_logic);
163
end component;
164
 
165
   signal opcode         : std_logic_vector(31 downto 0);
166
   signal rs_index, rt_index, rd_index     : std_logic_vector(5 downto 0);
167
   signal reg_source, reg_target, reg_dest : std_logic_vector(31 downto 0);
168
   signal a_bus, b_bus, c_bus : std_logic_vector(31 downto 0);
169
   signal c_alu, c_shift, c_mult, c_memory
170
        : std_logic_vector(31 downto 0);
171
   signal imm            : std_logic_vector(15 downto 0);
172
   signal pc             : std_logic_vector(31 downto 0);
173
   signal alu_function   : alu_function_type;
174
   signal shift_function : shift_function_type;
175
   signal mult_function  : mult_function_type;
176
   signal branch_function: branch_function_type;
177
   signal take_branch    : std_logic;
178
   signal a_source       : a_source_type;
179
   signal b_source       : b_source_type;
180
   signal c_source       : c_source_type;
181
   signal pc_source      : pc_source_type;
182
   signal mem_source     : mem_source_type;
183
   signal pause_mult     : std_logic;
184
   signal pause_memory   : std_logic;
185
   signal pause          : std_logic;
186
   signal nullify_op     : std_logic;
187
   signal intr_enable    : std_logic;
188
   signal intr_signal    : std_logic;
189
--   signal mem_byte_sel   : std_logic_vector(3 downto 0);
190
--   signal mem_write      : std_logic;
191
begin  --architecture
192
 
193
   pause <= pause_mult or pause_memory;
194
   --nulify_op = pc_source==from_lbranch && take_branch=='0'
195
   nullify_op <= pc_source(1) and pc_source(0) and not take_branch;
196
   c_bus <= c_alu or c_shift or c_mult;
197
   intr_signal <= (intr_in and intr_enable) and
198
                  (not pc_source(0) and not pc_source(1));  --from_inc4
199
 
200
   u1: pc_next PORT MAP (
201
        clk          => clk,
202
        reset_in     => reset_in,
203
        take_branch  => take_branch,
204
        pause_in     => pause,
205
        pc_new       => c_alu(31 downto 2),
206
        opcode25_0   => opcode(25 downto 0),
207
        pc_source    => pc_source,
208
        pc_out       => pc);
209
 
210
   u2: mem_ctrl PORT MAP (
211
        clk          => clk,
212
        reset_in     => reset_in,
213
        pause_in     => pause,
214
        nullify_op   => nullify_op,
215
        address_pc   => pc,
216
        opcode_out   => opcode,
217
 
218
        address_data => c_alu,
219
        mem_source   => mem_source,
220
        data_write   => reg_target,
221
        data_read    => c_memory,
222
        pause_out    => pause_memory,
223
 
224
        mem_address  => mem_address,
225
        mem_data_w   => mem_data_w,
226
        mem_data_r   => mem_data_r,
227
        mem_byte_sel => mem_sel,
228
        mem_write    => mem_write,
229
        mem_pause    => mem_pause);
230
 
231
   u3: control PORT MAP (
232
        opcode       => opcode,
233
        intr_signal  => intr_signal,
234
        rs_index     => rs_index,
235
        rt_index     => rt_index,
236
        rd_index     => rd_index,
237
        imm_out      => imm,
238
        alu_func     => alu_function,
239
        shift_func   => shift_function,
240
        mult_func    => mult_function,
241
        branch_func  => branch_function,
242
        a_source_out => a_source,
243
        b_source_out => b_source,
244
        c_source_out => c_source,
245
        pc_source_out=> pc_source,
246
        mem_source_out=> mem_source);
247
 
248
   u4: reg_bank port map (
249
        clk            => clk,
250
        rs_index       => rs_index,
251
        rt_index       => rt_index,
252
        rd_index       => rd_index,
253
        reg_source_out => reg_source,
254
        reg_target_out => reg_target,
255
        reg_dest_new   => reg_dest,
256
        intr_enable    => intr_enable);
257
 
258
   u5: bus_mux port map (
259
        imm_in       => imm,
260
        reg_source   => reg_source,
261
        a_mux        => a_source,
262
        a_out        => a_bus,
263
 
264
        reg_target   => reg_target,
265
        b_mux        => b_source,
266
        b_out        => b_bus,
267
 
268
        c_bus        => c_bus,
269
        c_memory     => c_memory,
270
        c_pc         => pc,
271
        c_mux        => c_source,
272
        reg_dest_out => reg_dest,
273
 
274
        branch_func  => branch_function,
275
        take_branch  => take_branch);
276
 
277
   u6: alu port map (
278
        a_in         => a_bus,
279
        b_in         => b_bus,
280
        alu_function => alu_function,
281
        c_alu        => c_alu);
282
 
283
   u7: shifter port map (
284
        value        => b_bus,
285
        shift_amount => a_bus(4 downto 0),
286
        shift_func   => shift_function,
287
        c_shift      => c_shift);
288
 
289
   u8: mult port map (
290
        clk       => clk,
291
        a         => a_bus,
292
        b         => b_bus,
293
        mult_func => mult_function,
294
        c_mult    => c_mult,
295
        pause_out => pause_mult);
296
 
297
   t_pc <= pc;
298
   t_opcode <= opcode;
299
   t_r_dest <= reg_dest;
300
 
301
end; --architecture logic
302
 

powered by: WebSVN 2.1.0

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