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

Subversion Repositories mlite

[/] [mlite/] [trunk/] [vhdl/] [mlite_cpu.vhd] - Blame information for rev 47

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 47 rhoads
   generic(memory_type : string := "ALTERA");
62 39 rhoads
   port(clk         : in std_logic;
63
        reset_in    : in std_logic;
64
        intr_in     : in std_logic;
65
 
66
        mem_address : out std_logic_vector(31 downto 0);
67
        mem_data_w  : out std_logic_vector(31 downto 0);
68
        mem_data_r  : in std_logic_vector(31 downto 0);
69
        mem_byte_sel: out std_logic_vector(3 downto 0);
70
        mem_write   : out std_logic;
71
        mem_pause   : in std_logic);
72
end; --entity mlite_cpu
73
 
74
architecture logic of mlite_cpu is
75
   signal opcode         : std_logic_vector(31 downto 0);
76
   signal rs_index, rt_index, rd_index     : std_logic_vector(5 downto 0);
77
   signal reg_source, reg_target, reg_dest : std_logic_vector(31 downto 0);
78
   signal a_bus, b_bus, c_bus : std_logic_vector(31 downto 0);
79
   signal c_alu, c_shift, c_mult, c_memory
80
        : std_logic_vector(31 downto 0);
81
   signal imm            : std_logic_vector(15 downto 0);
82
   signal pc             : std_logic_vector(31 downto 0);
83
   signal pc_plus4       : std_logic_vector(31 downto 0);
84
   signal alu_function   : alu_function_type;
85
   signal shift_function : shift_function_type;
86
   signal mult_function  : mult_function_type;
87
   signal branch_function: branch_function_type;
88
   signal take_branch    : std_logic;
89
   signal a_source       : a_source_type;
90
   signal b_source       : b_source_type;
91
   signal c_source       : c_source_type;
92
   signal pc_source      : pc_source_type;
93
   signal mem_source     : mem_source_type;
94
   signal pause_mult     : std_logic;
95
   signal pause_memory   : std_logic;
96
   signal pause          : std_logic;
97
   signal nullify_op     : std_logic;
98
   signal intr_enable    : std_logic;
99
   signal intr_signal    : std_logic;
100
   signal reset_reg      : std_logic;
101
begin  --architecture
102
 
103
   pause <= pause_mult or pause_memory;
104
   nullify_op <= '1' when pc_source = from_lbranch and
105
                     (take_branch = '0' or branch_function = branch_yes) else
106
                 '0';
107
   c_bus <= c_alu or c_shift or c_mult;
108
 
109
--synchronize reset and interrupt pins
110
intr_proc: process(clk, reset_in, intr_in, intr_enable, pc_source, pc, pause)
111
begin
112
   if rising_edge(clk) then
113
      reset_reg <= reset_in;
114
      --don't try to interrupt a multi-cycle instruction
115
      if intr_in = '1' and intr_enable = '1' and
116
            pc_source = from_inc4 and
117
            pc(2) = '0' and
118
            pause = '0' then
119
         --the epc will be backed up one opcode (pc-4)
120
         intr_signal <= '1';
121
      else
122
         intr_signal <= '0';
123
      end if;
124
   end if;
125
end process;
126
 
127
   u1_pc_next: pc_next PORT MAP (
128
        clk          => clk,
129
        reset_in     => reset_reg,
130
        take_branch  => take_branch,
131
        pause_in     => pause,
132
        pc_new       => c_alu(31 downto 2),
133
        opcode25_0   => opcode(25 downto 0),
134
        pc_source    => pc_source,
135
        pc_out       => pc,
136
        pc_out_plus4 => pc_plus4);
137
 
138
   u2_mem_ctrl: mem_ctrl PORT MAP (
139
        clk          => clk,
140
        reset_in     => reset_reg,
141
        pause_in     => pause,
142
        nullify_op   => nullify_op,
143
        address_pc   => pc,
144
        opcode_out   => opcode,
145
 
146
        address_data => c_alu,
147
        mem_source   => mem_source,
148
        data_write   => reg_target,
149
        data_read    => c_memory,
150
        pause_out    => pause_memory,
151
 
152
        mem_address  => mem_address,
153
        mem_data_w   => mem_data_w,
154
        mem_data_r   => mem_data_r,
155
        mem_byte_sel => mem_byte_sel,
156
        mem_write    => mem_write,
157
        mem_pause    => mem_pause);
158
 
159
   u3_control: control PORT MAP (
160
        opcode       => opcode,
161
        intr_signal  => intr_signal,
162
        pause_in     => pause,
163
        rs_index     => rs_index,
164
        rt_index     => rt_index,
165
        rd_index     => rd_index,
166
        imm_out      => imm,
167
        alu_func     => alu_function,
168
        shift_func   => shift_function,
169
        mult_func    => mult_function,
170
        branch_func  => branch_function,
171
        a_source_out => a_source,
172
        b_source_out => b_source,
173
        c_source_out => c_source,
174
        pc_source_out=> pc_source,
175
        mem_source_out=> mem_source);
176
 
177 47 rhoads
   u4_reg_bank: reg_bank
178
      generic map(memory_type => memory_type)
179
      port map (
180 39 rhoads
        clk            => clk,
181
        reset_in       => reset_reg,
182
        rs_index       => rs_index,
183
        rt_index       => rt_index,
184
        rd_index       => rd_index,
185
        reg_source_out => reg_source,
186
        reg_target_out => reg_target,
187
        reg_dest_new   => reg_dest,
188
        intr_enable    => intr_enable);
189
 
190
   u5_bus_mux: bus_mux port map (
191
        imm_in       => imm,
192
        reg_source   => reg_source,
193
        a_mux        => a_source,
194
        a_out        => a_bus,
195
 
196
        reg_target   => reg_target,
197
        b_mux        => b_source,
198
        b_out        => b_bus,
199
 
200
        c_bus        => c_bus,
201
        c_memory     => c_memory,
202
        c_pc         => pc,
203
        c_pc_plus4   => pc_plus4,
204
        c_mux        => c_source,
205
        reg_dest_out => reg_dest,
206
 
207
        branch_func  => branch_function,
208
        take_branch  => take_branch);
209
 
210 47 rhoads
   u6_alu: alu
211
      generic map (adder_type => memory_type)
212
      port map (
213 39 rhoads
        a_in         => a_bus,
214
        b_in         => b_bus,
215
        alu_function => alu_function,
216
        c_alu        => c_alu);
217
 
218
   u7_shifter: shifter port map (
219
        value        => b_bus,
220
        shift_amount => a_bus(4 downto 0),
221
        shift_func   => shift_function,
222
        c_shift      => c_shift);
223
 
224 47 rhoads
   u8_mult: mult
225
      generic map (adder_type => memory_type)
226
      port map (
227 39 rhoads
        clk       => clk,
228
        a         => a_bus,
229
        b         => b_bus,
230
        mult_func => mult_function,
231
        c_mult    => c_mult,
232
        pause_out => pause_mult);
233
 
234
end; --architecture logic
235
 

powered by: WebSVN 2.1.0

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