Skip to content

Commit 516d08f

Browse files
committed
Add src files
1 parent 55f2643 commit 516d08f

24 files changed

+2304
-0
lines changed

Integrated.vhd

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
library IEEE;
2+
use IEEE.STD_LOGIC_1164.ALL;
3+
use IEEE.std_logic_unsigned.all;
4+
5+
entity DP_C is
6+
port(
7+
clk: in std_logic;
8+
rst: in std_logic
9+
);
10+
end entity;
11+
12+
architecture DP_C_arc of DP_C is
13+
14+
-- for datapath
15+
signal result: std_logic_vector(31 downto 0);
16+
signal instruction: std_logic_vector(31 downto 0);
17+
18+
-- out from datapath into controller
19+
signal NZCV: std_logic_vector(3 downto 0):= "0000";
20+
21+
-- Control signals
22+
-- Actrl
23+
signal op: std_logic_vector(3 downto 0);
24+
25+
-- Bctrl
26+
signal p:std_logic;
27+
28+
-- Main Controller
29+
signal PW: std_logic;
30+
signal IW: std_logic;
31+
signal DW: std_logic;
32+
signal AW: std_logic;
33+
signal BW: std_logic;
34+
signal resW: std_logic;
35+
signal Fset: std_logic;
36+
signal RW: std_logic;
37+
signal MR: std_logic;
38+
signal MW: std_logic;
39+
signal IorD: std_logic;
40+
signal Asrc1: std_logic;
41+
signal Asrc2: std_logic_vector(1 downto 0);
42+
signal Rsrc: std_logic;
43+
signal M2R: std_logic;
44+
45+
signal I: std_logic;
46+
signal M: std_logic;
47+
begin
48+
49+
DP:
50+
entity WORK.datapath port map(
51+
clk=>clk,
52+
rst=>rst,
53+
54+
op=>op,
55+
p=>p,
56+
57+
PW=>PW,
58+
IW=>IW,
59+
DW=>DW,
60+
AW=>AW,
61+
BW=>BW,
62+
resW=>resW,
63+
Fset=>Fset,
64+
RW=>RW,
65+
MR=>MR,
66+
MW=>MW,
67+
IorD=>IorD,
68+
Asrc1=>Asrc1,
69+
Asrc2=>Asrc2,
70+
Rsrc=>Rsrc,
71+
M2R=>M2R,
72+
73+
I=>I,
74+
M=>M,
75+
76+
out_flags=>NZCV,
77+
instruction=>instruction,
78+
result=>result
79+
);
80+
81+
Controller:
82+
entity WORK.Controller port map(
83+
clk=>clk,
84+
rst=>rst,
85+
NZCV=>NZCV,
86+
ins=>instruction,
87+
88+
op=>op,
89+
90+
p=>p,
91+
92+
PW=>PW,
93+
IW=>IW,
94+
DW=>DW,
95+
AW=>AW,
96+
BW=>BW,
97+
resW=>resW,
98+
Fset=>Fset,
99+
RW=>RW,
100+
MR=>MR,
101+
MW=>MW,
102+
IorD=>IorD,
103+
Asrc1=>Asrc1,
104+
Asrc2=>Asrc2,
105+
Rsrc=>Rsrc,
106+
M2R=>M2R,
107+
108+
I=>I,
109+
M=>M
110+
);
111+
end architecture;

controller/src/Actrl.vhd

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
library IEEE;
2+
use IEEE.NUMERIC_STD.ALL;
3+
use IEEE.STD_LOGIC_1164.ALL;
4+
use IEEE.STD_LOGIC_UNSIGNED.ALL;
5+
6+
use WORK.mytypes.all;
7+
entity Actrl is
8+
port (
9+
-- 27-26, 24-20, 7-4
10+
state: in state;
11+
ins: in std_logic_vector(10 downto 0);
12+
op: out std_logic_vector(3 downto 0)
13+
);
14+
end Actrl;
15+
16+
architecture Actrl_arc of Actrl is
17+
signal F: std_logic_vector(1 downto 0);
18+
signal opcode: std_logic_vector(3 downto 0);
19+
signal L, U : std_logic;
20+
signal M: std_logic_vector(3 downto 0); --Checking for Mul.
21+
begin
22+
F<=ins(10 downto 9);
23+
opcode<=ins(8 downto 5);
24+
U<=ins(7);
25+
-- not really needed.
26+
-- too lazy to change everywhere.
27+
L<=ins(4);
28+
M<=ins(3 downto 0);
29+
30+
process(F, opcode, L, M, U, state) begin
31+
if state=fetch then
32+
op<="0100";
33+
elsif F="00" then --DP
34+
if M="1001" then
35+
op<="1101";
36+
else
37+
op<=opcode;
38+
end if;
39+
elsif F="01" then --DT
40+
if U='1' then
41+
op<="0100";
42+
else
43+
op<="0010";
44+
end if;
45+
else
46+
op<="0100";
47+
end if;
48+
end process;
49+
end architecture;

controller/src/Bctrl.vhd

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
library IEEE;
2+
use IEEE.NUMERIC_STD.ALL;
3+
use IEEE.STD_LOGIC_1164.ALL;
4+
use IEEE.STD_LOGIC_UNSIGNED.ALL;
5+
6+
entity Bctrl is
7+
port (
8+
cond: in std_logic_vector(3 downto 0);
9+
NZCV: in std_logic_vector(3 downto 0);
10+
p: out std_logic
11+
);
12+
end Bctrl;
13+
14+
architecture Bctrl_arc of Bctrl is
15+
signal N,C,Z,V, temp: std_logic;
16+
begin
17+
N<=NZCV(3);
18+
Z<=NZCV(2);
19+
C<=NZCV(1);
20+
V<=NZCV(0);
21+
22+
p<=temp;
23+
process(cond, N, C, Z, V, temp) begin
24+
case cond is
25+
when "0000" => temp<=Z;
26+
when "0001" => temp<=not Z;
27+
when "0010" => temp<=C;
28+
when "0011" => temp<=not C;
29+
when "0100" => temp<=N;
30+
when "0101" => temp<=not N;
31+
when "0110" => temp<=V;
32+
when "0111" => temp<=not V;
33+
when "1000" => temp<=C and (not Z);
34+
when "1001" => temp<=Z and (not C);
35+
when "1010" => temp<=not (N xor V);
36+
when "1011" => temp<=N xor V;
37+
when "1100" => temp<=(not Z) and (not (N xor V));
38+
when "1101" => temp<=Z or (N xor V);
39+
when "1110" => temp<='1';
40+
when others => temp<='1';
41+
end case;
42+
end process;
43+
end architecture;

controller/src/Controller.vhd

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
library IEEE;
2+
use IEEE.STD_LOGIC_1164.ALL;
3+
use IEEE.NUMERIC_STD.ALL;
4+
5+
use WORK.mytypes.all;
6+
7+
entity Controller is
8+
port (
9+
clk :in std_logic;
10+
rst: in std_logic;
11+
NZCV: in std_logic_vector(3 downto 0);
12+
ins :in std_logic_vector(31 downto 0);
13+
14+
-- output of Actrl.
15+
op:out std_logic_vector(3 downto 0);
16+
17+
-- output of Bctrl.
18+
p: out std_logic;
19+
20+
-- output of Main Controller
21+
PW:out std_logic;
22+
IW:out std_logic;
23+
DW:out std_logic;
24+
AW:out std_logic;
25+
BW:out std_logic;
26+
resW:out std_logic;
27+
Fset:out std_logic;
28+
RW:out std_logic;
29+
MR:out std_logic;
30+
MW:out std_logic;
31+
IorD:out std_logic;
32+
Asrc1:out std_logic;
33+
Asrc2:out std_logic_vector(1 downto 0);
34+
Rsrc:out std_logic;
35+
M2R:out std_logic;
36+
I:out std_logic;
37+
M:out std_logic
38+
39+
-- not_implemented:out std_logic;
40+
-- undefined:out std_logic;
41+
);
42+
end entity Controller;
43+
44+
architecture Controller_arc of Controller is
45+
signal actrl_ins: std_logic_vector(10 downto 0);
46+
signal MC_ins: std_logic_vector(4 downto 0);
47+
signal ns_ins: std_logic_vector(2 downto 0);
48+
signal flag: std_logic;
49+
signal cs, ns: state;
50+
begin
51+
p<=flag;
52+
actrl_ins<=ins(27 downto 26)&ins(24 downto 20)&ins(7 downto 4);
53+
54+
Actrl:
55+
entity WORK.Actrl port map(
56+
state=> cs,
57+
ins=> actrl_ins,
58+
op=>op
59+
);
60+
61+
Bctrl:
62+
entity WORK.Bctrl port map(
63+
cond=>ins(31 downto 28),
64+
NZCV=>NZCV,
65+
p=>flag
66+
);
67+
68+
MC_ins<=ins(25)&ins(7 downto 4);
69+
MC:
70+
entity WORK.Main_Controller port map(
71+
p=>flag,
72+
ins=>MC_ins,
73+
current_state=>cs,
74+
75+
PW=>PW,
76+
IW=>IW,
77+
DW=>DW,
78+
AW=>AW,
79+
BW=>BW,
80+
resW=>resW,
81+
RW=>RW,
82+
MR=>MR,
83+
MW=>MW,
84+
IorD=>IorD,
85+
Fset=>Fset,
86+
Asrc1=>Asrc1,
87+
Asrc2=>Asrc2,
88+
Rsrc=>Rsrc,
89+
M2R=>M2R,
90+
91+
I=>I,
92+
M=>M
93+
);
94+
95+
ns_ins<=ins(27 downto 26)&ins(20);
96+
Next_State:
97+
entity WORK.next_state port map(
98+
ins=>ns_ins,
99+
current_state=>cs,
100+
next_state=>ns
101+
);
102+
103+
Control_state:
104+
entity WORK.control_state port map(
105+
clk=>clk,
106+
rst=>rst,
107+
next_state=>ns,
108+
current_state=>cs
109+
);
110+
111+
-- ID:
112+
-- entity WORK.Instruction_decoder port map (
113+
-- clk=>clk,
114+
-- ins=>dec_ins,
115+
-- not_implemented=>not_implemented,
116+
-- undefined=>undefined
117+
-- );
118+
end architecture;
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
library IEEE;
2+
use IEEE.STD_LOGIC_1164.ALL;
3+
use IEEE.STD_LOGIC_ARITH.ALL;
4+
use IEEE.STD_LOGIC_UNSIGNED.ALL;
5+
6+
entity Instruction_decoder is
7+
port (
8+
clk :in std_logic;
9+
--27-20, 11-4
10+
ins:in std_logic_vector(15 downto 0);
11+
not_implemented:out std_logic;
12+
undefined:out std_logic
13+
);
14+
end Instruction_decoder;
15+
16+
architecture arc_Imstruction_decoder of Instruction_decoder is
17+
signal n1,n2,n3,n4,n5,n6,n7,n8:std_logic;
18+
begin
19+
undefined<=(NOT (ins(15)) AND ins(14) )AND ins(13) AND ins(4);
20+
not_implemented<=n1 or n2 or n3 or n4 or n5 or n6 or n7 or n8;
21+
n1<=ins(14) AND ins(15);
22+
n2<=ins(15) AND NOT (ins(14)) AND (NOT(ins(13)));
23+
n3<=NOT(ins(15)) AND NOT(ins(14)) AND ins(13);
24+
n4<=NOT(ins(15)) AND NOT(ins(14)) AND (NOT ins(13)) AND NOT(ins(0));
25+
n5<=NOT(ins(15)) AND NOT(ins(14)) AND (NOT ins(13)) AND ins(0) AND NOT(ins(7)) AND ins(6) AND ins(5) AND ins(4) AND ins(3);
26+
n6<=NOT(NOT(ins(15)) AND NOT(ins(14)) AND (NOT ins(13)) AND ins(0) AND ins(7) AND NOT (ins(2)) AND NOT(ins(1)));
27+
n7<=NOT(ins(15)) AND NOT(ins(14)) AND (NOT ins(13)) AND ins(0) AND ins(7) AND NOT (ins(2)) AND NOT(ins(1)) AND NOT(ins(12)) AND ins(11);
28+
n8<=NOT(ins(15)) AND NOT(ins(14)) AND (NOT ins(13)) AND ins(0) AND ins(7) AND NOT (ins(2)) AND NOT(ins(1)) AND ins(12);
29+
end architecture arc_Imstruction_decoder;

0 commit comments

Comments
 (0)