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

Subversion Repositories mipsr2000

[/] [mipsr2000/] [trunk/] [fsm.vhd] - Blame information for rev 52

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

Line No. Rev Author Line
1 34 jimi39
----------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer:     Lazaridis Dimitris
4
-- 
5
-- Create Date:    00:18:09 06/13/2012 
6
-- Design Name: 
7
-- Module Name:    fsm - Behavioral 
8
-- Project Name: 
9
-- Target Devices: 
10
-- Tool versions: 
11
-- Description: 
12
--
13
-- Dependencies: 
14
--
15
-- Revision: 
16
-- Revision 0.01 - File Created
17
-- Additional Comments: 
18
--
19
----------------------------------------------------------------------------------
20
library IEEE;
21
use IEEE.STD_LOGIC_1164.ALL;
22
 
23
-- Uncomment the following library declaration if using
24
-- arithmetic functions with Signed or Unsigned values
25
--use IEEE.NUMERIC_STD.ALL;
26
 
27
-- Uncomment the following library declaration if instantiating
28
-- any Xilinx primitives in this code.
29
--library UNISIM;
30
--use UNISIM.VComponents.all;
31
 
32
entity fsm is
33
    Port ( clk : in  STD_LOGIC;
34
           rst : in  STD_LOGIC;
35
                          RegDst, RegWrite, ALUSrcA, MemRead, MemWrite, Mult_en, IorD, IRWrite, PCWrite,
36
           EqNq,ALUsw : out std_logic;
37
           instr_31_26,immed_addr : in std_logic_vector(5 downto 0);
38
           ALUOp, ALUSrcB, PCSource,ALUmux : OUT std_logic_vector(1 downto 0);
39
                          ALUop_sw,RFmux : out std_logic_vector(2 downto 0)
40
                        );
41
end fsm;
42
 
43
architecture Behavioral of fsm is
44
     TYPE state_type IS ( InstDec, MemAddComp, MemAccL, MemReadCompl, MemAccS, MultWrite, Exec, MultComlFlo, MultComlFhi,
45
      RCompl, BranchCompare, BranchCompl, BranchComplNe, I_typeExe, I_typeComplt, JrCompl, JalrCompl, ErrState, InstFetch );
46
     SIGNAL state, next_state : state_type;
47
begin
48
 
49
 
50
-- State process
51
state_reg : PROCESS(clk, rst)
52
            BEGIN
53
            IF rst = '0' THEN
54
                                        state <= InstFetch;
55
                                ELSIF RISING_EDGE(clk) THEN
56
            state <= next_state;
57
            END IF;
58
            END PROCESS;
59
 
60
 
61
          -------------------------------------------------------------------------------
62
-- Logic Process
63
logic_process : PROCESS(state,instr_31_26,immed_addr)
64
 
65
-- ALUOp ALUSrcB PCSource ALUmux
66
--4x2bit
67
     VARIABLE control_signals : std_logic_vector(21 downto 0);
68
          VARIABLE ALUop_3_sw : std_logic_vector(2 downto 0);
69
-- Defintion of Constants 
70
     Constant LOADWORD : std_logic_vector(5 Downto 0) := "100011";
71
          Constant LOADBYTE : std_logic_vector(5 Downto 0) := "010100";
72
     Constant STOREWORD : std_logic_vector(5 Downto 0) := "101011";
73
     Constant RTYPE : std_logic_vector(5 Downto 0) := "000000";
74
     Constant BEQ : std_logic_vector(5 Downto 0) := "000100";
75
          Constant BNE : std_logic_vector(5 Downto 0) := "000101";
76
          Constant ADDI: std_logic_vector(5 Downto 0) := "001000";
77
          Constant ADDIU : std_logic_vector(5 Downto 0) := "001001";
78
          Constant ANDI : std_logic_vector(5 Downto 0) := "001100";
79
          Constant ORI : std_logic_vector(5 Downto 0) := "001101";
80
          Constant XORI : std_logic_vector(5 Downto 0) := "001110";
81
          Constant LUI : std_logic_vector(5 Downto 0) := "001111";
82
          Constant SLTI : std_logic_vector(5 Downto 0) := "001010";
83
          Constant SLTIU : std_logic_vector(5 Downto 0) := "001011";
84
     Constant JR : std_logic_vector(5 Downto 0) := "001000";
85
          Constant JALR : std_logic_vector(5 Downto 0) := "001001";
86
          BEGIN
87
               CASE state IS
88
-- Instruction Fetch
89
          WHEN InstFetch =>
90
          control_signals := "0000000011000100000000";  --checked  lw
91
                         next_state <= InstDec;
92
-- Instruction Decode and Register Fetch
93
          WHEN InstDec =>
94
          control_signals := "0000000010000000000000";   --checked  lw "000000000000000001100";
95
               IF instr_31_26 = LOADWORD OR instr_31_26 = LOADBYTE OR instr_31_26 = STOREWORD THEN
96
               next_state <= MemAddComp;
97
               ELSIF immed_addr = JR AND instr_31_26 = RTYPE THEN
98
                                        next_state <= JrCompl;
99
                                        ELSIF immed_addr = JALR AND instr_31_26 = RTYPE THEN
100
                                        next_state <= JalrCompl;
101
                                        ELSIF (instr_31_26 = RTYPE and immed_addr = "010001") OR     --Mthi
102
                              (instr_31_26 = RTYPE and immed_addr = "010011") OR           --Mtlo 
103
                                   (instr_31_26 = RTYPE and immed_addr = "011000") THEN         --Mult   
104
                next_state <= MultWrite;
105
                                        ELSIF instr_31_26 = RTYPE THEN
106
               next_state <= Exec;
107
               ELSIF instr_31_26 = BEQ OR instr_31_26 = BNE THEN
108
               next_state <= BranchCompare;
109
                                        ELSIF instr_31_26 = ADDI OR instr_31_26 = ADDIU OR instr_31_26 = ANDI
110
                                        OR instr_31_26 = ORI OR instr_31_26 = XORI OR instr_31_26 = LUI OR instr_31_26 = SLTI
111
                                        OR instr_31_26 = SLTIU  THEN
112
                                        next_state <= I_typeExe;
113
                                        ELSE
114
               next_state <= ErrState;
115
               END IF;
116
-- Memory Address Computation
117
          WHEN MemAddComp =>
118
          control_signals := "0000100010000000001000"; --checked lw  have to add alusrca
119
               if instr_31_26 = LOADWORD OR instr_31_26 = LOADBYTE THEN
120
               next_state <= MemAccL;
121
               ELSIF instr_31_26 = STOREWORD THEN
122
               next_state <= MemAccS;
123
               ELSE
124
               next_state <= ErrState;
125
               END IF;
126
 
127
-- Memory Access Load Word
128
          WHEN MemAccL =>
129
          control_signals := "0000100011001000001000";  --checked lw    iii
130
          next_state <= MemReadCompl;
131
-- Memory Read Completion
132
          WHEN MemReadCompl =>
133
          control_signals := "0110000110000010001000";  --checked lw "000000110010000001000"
134
          next_state <= InstFetch;
135
-- Memory Access Store Word
136
          WHEN MemAccS =>
137
          control_signals := "0000000011101010001000";    --sw
138
          next_state <= InstFetch;
139
-- Multi exe write                       
140
                         WHEN MultWrite =>
141
                         control_signals := "1000100010010010100000";
142
                         next_state <= InstFetch;
143
 
144
 
145
-- Execution
146
          WHEN Exec =>
147
                         control_signals := "1000100010000000100000";
148
--Mult Completion       
149
                         IF (immed_addr = "010010" and instr_31_26 = RTYPE) THEN --Mflo 
150
                         next_state <= MultComlFlo;
151
--Mflo 
152
                         ELSIF (immed_addr = "010000" and instr_31_26 = RTYPE) THEN --Mfhi
153
                         next_state <= MultComlFhi;
154
--Mfhi                   
155
                         ELSIF (instr_31_26 = RTYPE) THEN
156
                         next_state <= RCompl;
157
                         ELSE
158
                         next_state <= ErrState;
159
                         END IF;
160
--Mflo Completion                        
161
                         WHEN MultComlFlo =>
162
                         control_signals := "1010001110000010100000";  --Mult_Mflo
163
                         next_state <= InstFetch;
164
--Mfhi Completion                        
165
                         WHEN MultComlFhi =>
166
                         control_signals := "1000001110000010100000";  --Mult_Mfhi
167
                         next_state <= InstFetch;
168
-- R-type Completion
169
          WHEN RCompl =>
170
          control_signals := "1100001110000010100000";  --add
171
          next_state <= InstFetch;
172
-- Branch Compare                        
173
                         WHEN BranchCompare =>
174
                         control_signals := "0000100010000000110001";
175
                         IF instr_31_26 = BEQ THEN
176
                         next_state <= BranchCompl;
177
                         ELSIF instr_31_26 = BNE THEN
178
                         next_state <= BranchComplNe;
179
                         ELSE
180
                         next_state <= ErrState;
181
                         END IF;
182
-- Branch Completion
183
          WHEN BranchCompl =>
184
          control_signals := "0000100010000010110001";   --beq
185
          next_state <= InstFetch;
186
-- Branch no equal Completion                    
187
                         WHEN BranchComplNe =>
188
                         control_signals := "0000100010000011110001";   --bne
189
                         next_state <= InstFetch;
190
--I types execution              
191
                         WHEN I_typeExe =>
192
                         control_signals := "1000100010000000111000";   -- I type  
193
                         next_state <= I_typeComplt;
194
--I types Completion                     
195
                         WHEN I_typeComplt =>
196
                         control_signals := "0100100110000010001000";
197
                         next_state <= InstFetch;
198
-- Jump Completion
199
          WHEN JrCompl =>
200
          control_signals := "0000000000000010000010";
201
          next_state <= InstFetch;
202
                         WHEN JalrCompl =>
203
          control_signals := "0001001100000010000010";
204
          next_state <= InstFetch;
205
                         --WHEN ErrState =>
206
                         --control_signals := "0000000000000000000000";  -- i have to built soft reset
207
                         --next_state <= InstFetch;
208
          WHEN OTHERS =>
209
          control_signals := (others => 'X');
210
          next_state <= ErrState;
211
       END case;
212
 
213
 
214
ALUsw <= control_signals(21);             -- for r types
215
RFmux <= control_signals(20 downto 18);
216
ALUmux <= control_signals(17 downto 16);
217
RegDst <= control_signals(15);
218
RegWrite <= control_signals(14);
219
ALUSrcA <= control_signals(13);
220
MemRead <= control_signals(12);
221
MemWrite <= control_signals(11);
222
Mult_en <= control_signals(10);
223
IorD <= control_signals(9);
224
IRWrite <= control_signals(8);
225
PCWrite <= control_signals(7);
226
EqNq <= control_signals(6);
227
ALUOp <= control_signals(5 downto 4);
228
ALUSrcB <= control_signals(3 downto 2);
229
PCSource <= control_signals(1 downto 0);
230
 
231
ALUop_3_sw(1 downto 0) := control_signals(5 downto 4);
232
ALUop_3_sw(2 downto 2) := control_signals(21 downto 21);
233
ALUop_sw <= ALUop_3_sw;
234
 
235
END process;
236
 
237
 
238
end Behavioral;
239
 

powered by: WebSVN 2.1.0

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