1 |
36 |
jimi39 |
----------------------------------------------------------------------------------
|
2 |
|
|
-- Company:
|
3 |
|
|
-- Engineer: Lazaridis Dimitris
|
4 |
|
|
--
|
5 |
|
|
-- Create Date: 02:56:56 05/29/2012
|
6 |
|
|
-- Design Name:
|
7 |
|
|
-- Module Name: main - 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 main is
|
33 |
|
|
Port
|
34 |
|
|
(
|
35 |
|
|
Clk : in std_logic;
|
36 |
|
|
Rst : in std_logic;
|
37 |
|
|
vector_on : in std_logic_vector(2 downto 0);
|
38 |
|
|
Err : out STD_LOGIC;
|
39 |
|
|
Bus_r : out std_logic_vector(31 downto 0)
|
40 |
|
|
|
41 |
|
|
);
|
42 |
|
|
|
43 |
|
|
end main;
|
44 |
|
|
|
45 |
|
|
architecture Behavioral of main is
|
46 |
|
|
component ALU is
|
47 |
|
|
|
48 |
|
|
Port ( clk : in std_logic;
|
49 |
|
|
rst,Mult_en : in STD_LOGIC;
|
50 |
|
|
A_in : in std_logic_vector(31 downto 0);
|
51 |
|
|
B_in : in std_logic_vector(31 downto 0);
|
52 |
|
|
I : in std_logic_vector(31 downto 0);
|
53 |
|
|
immed_addr : std_logic_vector(15 downto 0);
|
54 |
|
|
ALUOp : in std_logic_vector(2 downto 0);
|
55 |
|
|
ALUmux : in std_logic_vector(1 downto 0);
|
56 |
|
|
From_i_op : IN std_logic_vector(1 downto 0);
|
57 |
|
|
From_i_mux : IN std_logic_vector(1 downto 0);
|
58 |
|
|
lui : in STD_LOGIC;
|
59 |
|
|
ALUSrcA : in std_logic;
|
60 |
|
|
ALUSrcB : in STD_LOGIC_VECTOR(1 downto 0);
|
61 |
|
|
N : in std_logic_vector(31 downto 0);
|
62 |
|
|
M : out std_logic_vector(31 downto 0);
|
63 |
|
|
Alu_out_exit : out std_logic_vector(31 downto 0);
|
64 |
|
|
Hi_out : out std_logic_vector(31 downto 0);
|
65 |
|
|
Lo_out : out std_logic_vector(31 downto 0);
|
66 |
|
|
Zero : out std_logic
|
67 |
|
|
);
|
68 |
|
|
end component;
|
69 |
|
|
|
70 |
|
|
component fsm is
|
71 |
|
|
Port ( clk : in STD_LOGIC;
|
72 |
|
|
rst : in STD_LOGIC;
|
73 |
|
|
RegDst, RegWrite, ALUSrcA, MemRead, MemWrite, Mult_en, IorD, IRWrite, PCWrite,
|
74 |
|
|
EqNq,ALUsw : out std_logic;
|
75 |
|
|
instr_31_26,immed_addr : in std_logic_vector(5 downto 0);
|
76 |
|
|
ALUOp,ALUSrcB,PCSource,ALUmux : OUT std_logic_vector(1 downto 0);
|
77 |
|
|
ALUop_sw,RFmux : out std_logic_vector(2 downto 0)
|
78 |
|
|
);
|
79 |
|
|
end component;
|
80 |
|
|
component Imem_block is
|
81 |
|
|
port (
|
82 |
|
|
clk : in std_logic;
|
83 |
|
|
rst : in std_logic;
|
84 |
|
|
npc : in std_logic_vector(31 downto 0);
|
85 |
|
|
MemRead : in STD_LOGIC;
|
86 |
|
|
PCWrite : in STD_LOGIC;
|
87 |
|
|
IRWrite : in STD_LOGIC;
|
88 |
|
|
Opcode : out std_logic_vector(5 downto 0);
|
89 |
|
|
rs : out std_logic_vector(4 downto 0);
|
90 |
|
|
rt : out std_logic_vector(4 downto 0);
|
91 |
|
|
rd : out std_logic_vector(4 downto 0);
|
92 |
|
|
immed_addr : out std_logic_vector(15 downto 0);
|
93 |
|
|
Err : out STD_LOGIC;
|
94 |
|
|
N : out std_logic_vector(31 downto 0);
|
95 |
|
|
Ext_sz_c : out std_logic;
|
96 |
|
|
From_i_op : out std_logic_vector(1 downto 0);
|
97 |
|
|
From_i_mux : out std_logic_vector(1 downto 0);
|
98 |
|
|
lui : out STD_LOGIC
|
99 |
|
|
);
|
100 |
|
|
end component;
|
101 |
|
|
component Reg_block is
|
102 |
|
|
port (
|
103 |
|
|
Clk : in std_logic;
|
104 |
|
|
rst : in STD_LOGIC;
|
105 |
|
|
vector_on : in std_logic_vector(2 downto 0);
|
106 |
|
|
Reg_Write : in std_logic;
|
107 |
|
|
Reg_Imm_not : in std_logic;
|
108 |
|
|
rs : in std_logic_vector(4 downto 0);
|
109 |
|
|
rt : in std_logic_vector(4 downto 0);
|
110 |
|
|
rd : in std_logic_vector(4 downto 0);
|
111 |
|
|
Ext_sz_c : in std_logic;
|
112 |
|
|
immed_addr : in std_logic_vector(15 downto 0);
|
113 |
|
|
Bus_W : in std_logic_vector(31 downto 0);
|
114 |
|
|
A2Alu : out std_logic_vector(31 downto 0);
|
115 |
|
|
B2Alu : out std_logic_vector(31 downto 0);
|
116 |
|
|
I2Alu : out std_logic_vector(31 downto 0)
|
117 |
|
|
|
118 |
|
|
);
|
119 |
|
|
end component;
|
120 |
|
|
component Dm is
|
121 |
|
|
port (
|
122 |
|
|
clk : in std_logic;
|
123 |
|
|
rst : in std_logic;
|
124 |
|
|
Alu_in :in std_logic_vector(31 downto 0);
|
125 |
|
|
MDR_in : in std_logic_vector(31 downto 0);
|
126 |
|
|
--op_code: in std_logic_vector(5 downto 0);
|
127 |
|
|
MemWrite : in std_logic;
|
128 |
|
|
MemRead : in std_logic;
|
129 |
|
|
IorD : in std_logic;
|
130 |
|
|
MDR_out : out std_logic_vector(31 downto 0)
|
131 |
|
|
--E : out std_logic_vector(1 downto 0)
|
132 |
|
|
);
|
133 |
|
|
end component;
|
134 |
|
|
component Mux_out_block is
|
135 |
|
|
port (
|
136 |
|
|
clk : in std_logic;
|
137 |
|
|
Zero_in,EqNq : in std_logic;
|
138 |
|
|
RFmux : in std_logic_vector(2 downto 0);
|
139 |
|
|
Hi_in : in std_logic_vector(31 downto 0);
|
140 |
|
|
Lo_in : in std_logic_vector(31 downto 0);
|
141 |
|
|
Alu_in: in std_logic_vector(31 downto 0);
|
142 |
|
|
Mdr_fr_out : in std_logic_vector(31 downto 0);
|
143 |
|
|
RF_out: out std_logic_vector(31 downto 0);
|
144 |
|
|
From_N: in std_logic_vector(31 downto 0);
|
145 |
|
|
From_A: in std_logic_vector(31 downto 0);
|
146 |
|
|
From_M: in std_logic_vector(31 downto 0);
|
147 |
|
|
PCSource: in std_logic_vector(1 downto 0);
|
148 |
|
|
NPC_out: out std_logic_vector(31 downto 0)
|
149 |
|
|
);
|
150 |
|
|
end component;
|
151 |
|
|
|
152 |
|
|
signal RegDst, RegWrite, ALUSrcA, MemRead, MemWrite, Mult_en, IorD, IRWrite, PCWrite,
|
153 |
|
|
EqNq,Ext_sz_c,No_u,Zero,lui : STD_LOGIC;
|
154 |
|
|
signal No_u2,ALUmux,PCSource,ALUSrcB,From_i_op,From_i_mux : std_logic_vector(1 downto 0);
|
155 |
|
|
signal ALUop_sw,RFmux : std_logic_vector(2 downto 0);
|
156 |
|
|
signal rs,rt,rd : std_logic_vector(4 downto 0);
|
157 |
|
|
signal instr_31_26 : std_logic_vector(5 downto 0);
|
158 |
|
|
signal immed_addr : std_logic_vector(15 downto 0);
|
159 |
|
|
signal Bus_W,A_wire,B_wire,I_wire,npc,MDR_out,Alu_out_exit,
|
160 |
|
|
N,M,Hi_out,Lo_out : std_logic_vector(31 downto 0);
|
161 |
|
|
|
162 |
|
|
|
163 |
|
|
|
164 |
|
|
begin
|
165 |
|
|
|
166 |
|
|
fsm_m:fsm port map(clk=>clk,rst=>rst,RegWrite=>RegWrite,PCSource=>PCSource,
|
167 |
|
|
ALUSrcB=>ALUSrcB,ALUmux=>ALUmux,
|
168 |
|
|
instr_31_26=>instr_31_26,immed_addr=>immed_addr(5 downto 0),RegDst=>RegDst,
|
169 |
|
|
ALUOp=>No_u2,ALUSrcA=>ALUSrcA,MemRead=>MemRead,
|
170 |
|
|
MemWrite=>MemWrite,Mult_en=>Mult_en,IorD=>IorD,IRWrite=>IRWrite,PCWrite=>PCWrite,
|
171 |
|
|
EqNq=>EqNq,ALUsw=>No_u,RFmux=>RFmux,ALUop_sw=>ALUop_sw);
|
172 |
|
|
ALU_m:ALU port map(clk=>clk,rst=>rst,Mult_en=>Mult_en,A_in=>A_wire,B_in=>B_wire,I=>I_wire,immed_addr=>immed_addr,
|
173 |
|
|
ALUOp=>ALUop_sw,ALUmux=>ALUmux,From_i_op=>From_i_op,From_i_mux=>From_i_mux,
|
174 |
|
|
lui=>lui,Zero=>Zero,ALUSrcA=>ALUSrcA,
|
175 |
|
|
ALUSrcB=>ALUSrcB,N=>N,M=>M,Hi_out=>Hi_out,Lo_out=>Lo_out,Alu_out_exit=>Alu_out_exit);
|
176 |
|
|
Imem_block_m:Imem_block port map(clk=>clk,rst=>rst,MemRead=>MemRead,PCWrite=>PCWrite,
|
177 |
|
|
IRWrite=>IRWrite,rt=>rt,rd=>rd,rs=>rs,immed_addr=>immed_addr,
|
178 |
|
|
Opcode=>instr_31_26,npc=>npc,Err=>Err,N=>N,Ext_sz_c=>Ext_sz_c,
|
179 |
|
|
From_i_op=>From_i_op,From_i_mux=>From_i_mux,lui=>lui);
|
180 |
|
|
Reg_blog_m:Reg_block port map(Clk=>Clk,rst=>rst,vector_on=>vector_on,Reg_Write=>RegWrite,Reg_Imm_not=>RegDst,
|
181 |
|
|
rs=>rs,rt=>rt,rd=>rd,Ext_sz_c=>Ext_sz_c,immed_addr=>immed_addr,Bus_W=>Bus_W,
|
182 |
|
|
A2Alu=>A_wire,B2Alu=>B_wire,I2Alu=>I_wire);
|
183 |
|
|
|
184 |
|
|
Dm_m:Dm port map(clk=>Clk,rst=>rst,Alu_in=>Alu_out_exit,MemWrite=>MemWrite,MemRead=>MemRead,
|
185 |
|
|
IorD=>IorD,MDR_in=>B_wire,MDR_out=>MDR_out);
|
186 |
|
|
|
187 |
|
|
Mux_out:Mux_out_block port map(clk=>clk,Zero_in=>Zero,EqNq=>EqNq,RFmux=>RFmux,Hi_in=>Hi_out,
|
188 |
|
|
Lo_in=>Lo_out,Alu_in=>Alu_out_exit,Mdr_fr_out=>MDR_out,
|
189 |
|
|
RF_out=>Bus_W,From_N=>N,From_A=>A_wire,From_M=>M,PCSource=>PCSource,
|
190 |
|
|
NPC_out=>npc);
|
191 |
|
|
process(clk)
|
192 |
|
|
begin
|
193 |
|
|
if (RISING_EDGE(clk))then
|
194 |
|
|
Bus_r <= Bus_W;
|
195 |
|
|
end if;
|
196 |
|
|
end process;
|
197 |
|
|
end Behavioral;
|
198 |
|
|
|