-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_definitions.vhd~
170 lines (148 loc) · 5.53 KB
/
main_definitions.vhd~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
-- Library declarations
library IEEE;
use IEEE.STD_LOGIC_1164.all;
package main_definitions is
-- Declare primary constants...
constant REG_ADD_WIDTH : NATURAL := 5;
constant WORD_WIDTH : NATURAL := 32;
constant INSTRUCTION_WIDTH : NATURAL := 32;
constant PC_WIDTH : NATURAL := 16;
-- Other indirect constants...
constant N_REGISTERS : NATURAL := 2**REG_ADD_WIDTH;
-- Declare types...
type word is array (WORD_WIDTH-1 downto 0) of std_logic;
type word_array is array (integer range <>) of STD_LOGIC_VECTOR(WORD_WIDTH-1 downto 0);
-- declare components
component simpleCore
Port (
-- global control signals
clk : in STD_LOGIC;
reset : in STD_LOGIC;
-- instruction memory signals
PC : out STD_LOGIC_VECTOR(PC_WIDTH-1 downto 0);
I : in STD_LOGIC_VECTOR(31 downto 0);
-- data memory signals
MemAddress : out STD_LOGIC_VECTOR(PC_WIDTH-1 downto 0);
MemWriteEnable : out STD_LOGIC;
MemWriteData : out STD_LOGIC_VECTOR(WORD_WIDTH-1 downto 0);
MemReadData : in STD_LOGIC_VECTOR(WORD_WIDTH-1 downto 0)
);
end component;
component decoder
Port (
clk : in std_logic;
reset : in STD_LOGIC;
-- instruction
I : in std_logic_vector(31 downto 0);
PC : in STD_LOGIC_VECTOR(PC_WIDTH-1 downto 0);
-- register file connections
RegOpA : out STD_LOGIC_VECTOR(REG_ADD_WIDTH-1 downto 0);
RegOpB : out STD_LOGIC_VECTOR(REG_ADD_WIDTH-1 downto 0);
RegOpD : out STD_LOGIC_VECTOR(REG_ADD_WIDTH-1 downto 0);
RegDA : in STD_LOGIC_VECTOR(WORD_WIDTH-1 downto 0);
RegDB : in STD_LOGIC_VECTOR(WORD_WIDTH-1 downto 0);
RegWE : out STD_LOGIC;
-- ALU connections
ExCTRL : out STD_LOGIC_VECTOR( 2 downto 0);
ExOpA : out STD_LOGIC_VECTOR(WORD_WIDTH downto 0);
ExOpB : out STD_LOGIC_VECTOR(WORD_WIDTH downto 0);
ExOpC : out STD_LOGIC;
-- BR Control connections
BrCond : out STD_LOGIC_VECTOR( 2 downto 0);
BrPC : out STD_LOGIC_VECTOR(PC_WIDTH-1 downto 0);
BrOffset : out STD_LOGIC_VECTOR(PC_WIDTH-1 downto 0);
-- MEM connections
MemCTRL : out STD_LOGIC_VECTOR( 2 downto 0);
-- Flag (MSR) conncections
MSR_C_WE : out STD_LOGIC;
MSR_C : in STD_LOGIC;
brali : out STD_LOGIC;
BrInTaken : in STD_LOGIC
);
end component;
component register_file
Port (
clk : in STD_LOGIC;
reset : in STD_LOGIC;
-- Output Port A
OpA : in STD_LOGIC_VECTOR (REG_ADD_WIDTH-1 downto 0);
DoutA : out STD_LOGIC_VECTOR (WORD_WIDTH-1 downto 0);
-- Output Port B
OpB : in STD_LOGIC_VECTOR (REG_ADD_WIDTH-1 downto 0);
DoutB : out STD_LOGIC_VECTOR (WORD_WIDTH-1 downto 0);
-- input/output Port D
WE : in STD_LOGIC;
OpD : in STD_LOGIC_VECTOR (REG_ADD_WIDTH-1 downto 0);
OP_D_REG : in STD_LOGIC_VECTOR (REG_ADD_WIDTH-1 downto 0);
DinD : in STD_LOGIC_VECTOR (WORD_WIDTH-1 downto 0);
DoutD : out STD_LOGIC_VECTOR (WORD_WIDTH-1 downto 0);
FW_exTable_A : out std_logic;
FW_exTable_B : out std_logic;
FW_exTable_D : out std_logic;
FW_memTable_A : out std_logic;
FW_memTable_B : out std_logic;
FW_memTable_D : out std_logic;
FW_wbTable_A : out std_logic;
FW_wbTable_B : out std_logic;
FW_wbTable_D : out std_logic;
AIsInValid: out STD_LOGIC;
BIsInValid: out STD_LOGIC;
DIsInValid: out STD_LOGIC;
ID_ENABLE : in STD_LOGIC;
memCTRL: in STD_LOGIC_VECTOR(2 downto 0);
BrTaken : in STD_LOGIC
);
end component;
component branch_control
Port (
clk : in STD_LOGIC;
reset : in STD_LOGIC;
PC : in STD_LOGIC_VECTOR(PC_WIDTH-1 downto 0);
Cond : in STD_LOGIC_VECTOR( 2 downto 0);
Offset : in STD_LOGIC_VECTOR(PC_WIDTH-1 downto 0);
CondWord : in STD_LOGIC_VECTOR(WORD_WIDTH-1 downto 0);
NextPC : out STD_LOGIC_VECTOR(PC_WIDTH-1 downto 0);
Data_Hazard: in STD_LOGIC;
BrTaken : out STD_LOGIC;
brali : in STD_LOGIC;
RegPC : in STD_LOGIC_VECTOR(PC_WIDTH-1 downto 0)
);
end component;
component alu
Port (
-- Control
CTRL : in STD_LOGIC_VECTOR ( 2 downto 0);
-- Operands
OpA : in STD_LOGIC_VECTOR (WORD_WIDTH downto 0);
OpB : in STD_LOGIC_VECTOR (WORD_WIDTH downto 0);
OpC : in STD_LOGIC;
-- Result
Res : out STD_LOGIC_VECTOR (WORD_WIDTH-1 downto 0);
-- flags
FlagC : out STD_LOGIC
);
end component;
component DualPortMemory
Port (
CLK : in STD_LOGIC;
Addr_A : in STD_LOGIC_VECTOR (PC_WIDTH-1 downto 0);
DO_A : out STD_LOGIC_VECTOR (WORD_WIDTH-1 downto 0);
WE_B : in STD_LOGIC;
Addr_B : in STD_LOGIC_VECTOR (PC_WIDTH-1 downto 0);
DI_B : in STD_LOGIC_VECTOR (WORD_WIDTH-1 downto 0);
DO_B : out STD_LOGIC_VECTOR (WORD_WIDTH-1 downto 0)
);
end component;
type instruction is array (INSTRUCTION_WIDTH-1 downto 0) of std_logic;
-- Declare functions and procedures...
end main_definitions;
package body main_definitions is
---- Example 1
-- function <function_name> (signal <signal_name> : in <type_declaration> )
-- return <type_declaration> is
-- variable <variable_name> : <type_declaration>;
-- begin
-- <variable_name> := <signal_name> xor <signal_name>;
-- return <variable_name>;
-- end <function_name>;
end main_definitions;