Repository navigation
Expand file tree
/
Copy pathglobals.vhd
More file actions
162 lines (117 loc) · 6.1 KB
/
Copy pathglobals.vhd
File metadata and controls
162 lines (117 loc) · 6.1 KB
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
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;
-- Contains all the constans that are used in the project
package constants is
-- Constants used for files
constant stack_start: std_logic_vector(31 downto 0) := x"7fffeffc"; -- stack starting address
constant N_INSTR : integer := 38 ;
constant DRAM_size : integer := 1024; --size in words
constant IRAM_size : integer := 1024; --size in words
-- costants used for the *ALU* functions. these are used for the selection of the operation
constant FUN_BITS : INTEGER:=4;
constant ADDS : std_logic_vector:= "0000"; --addition
constant SUBS : std_logic_vector:= "0001"; --subtraction
constant BITAND : std_logic_vector:= "0010"; --bit wise logic AND
constant BITOR : std_logic_vector:= "0011"; --bit wise logic OR
constant BITXOR : std_logic_vector:= "0100"; --bit wise logic XOR
constant LSL : std_logic_vector:= "0101"; --logic shift left (barrel shifter)
constant LSR : std_logic_vector:= "0110"; --logic shift right (barrel shifter)
constant ASR : std_logic_vector:= "0111"; --arithmetic shift right (barrel shifter)
constant EQ : std_logic_vector:= "1000"; --check if opernad_1 is equal to operand_2
constant NE : std_logic_vector:= "1001"; --check if opernad_1 is not equal to operand_2
constant LE : std_logic_vector:= "1010"; --check if opernad_1 is less or equal to operand_2
constant GE : std_logic_vector:= "1011"; --check if opernad_1 is greater or equal to operand_2
constant GT : std_logic_vector:= "1100"; --check if opernad_1 is greater than operand_2
constant LT : std_logic_vector:= "1101"; --check if opernad_1 is less than operand_2
constant BITNAND : std_logic_vector:= "1111"; --bit wise logic NAND
-- instr types opcode
constant NOP : std_logic_vector:= "0010011";
constant LTYPE : std_logic_vector:= "0000011"; --load
constant ITYPE : std_logic_vector:= "0010011";
constant PCTYPE : std_logic_vector:= "0010111"; --auipc
constant STYPE : std_logic_vector:= "0100011"; --store
constant RTYPE : std_logic_vector:= "0110011";
constant UTYPE : std_logic_vector:= "0110111"; --lui
constant SBTYPE : std_logic_vector:= "1100011"; --branch
constant JTYPE : std_logic_vector:= "1100111"; --jalr
constant UJTYPE : std_logic_vector:= "1101111"; --jal
-- immediates 13 func3
constant ADDI : std_logic_vector:= "000";
constant SLLI : std_logic_vector:= "001"; --func7
constant SLTI : std_logic_vector:= "010";
constant SLTIU : std_logic_vector:= "011";
constant XORI : std_logic_vector:= "100";
constant SRLI : std_logic_vector:= "101"; --func7
constant SRAI : std_logic_vector:= "101"; --func7
constant ORI : std_logic_vector:= "110";
constant ANDI : std_logic_vector:= "111";
-- immediates 13 func7
constant SLLI_7 : std_logic_vector:= "0000000";
constant SRLI_7 : std_logic_vector:= "0000000";
constant SRAI_7 : std_logic_vector:= "0100000";
-- register_to_register 33 func3
constant ADDr : std_logic_vector:= "000";
constant SUBr : std_logic_vector:= "000";
constant SLLr : std_logic_vector:= "001";
constant SLTr : std_logic_vector:= "010";
constant SLTUr : std_logic_vector:= "011";
constant XORr : std_logic_vector:= "100";
constant SRLr : std_logic_vector:= "101";
constant SRAr : std_logic_vector:= "101";
constant ORr : std_logic_vector:= "110";
constant ANDr : std_logic_vector:= "111";
-- register_to_register 33 func7
constant ADDr_7 : std_logic_vector:= "0000000";
constant SUBr_7 : std_logic_vector:= "0100000";
constant SLLr_7 : std_logic_vector:= "0000000";
constant SLTr_7 : std_logic_vector:= "0000000";
constant SLTUr_7 : std_logic_vector:= "0000000";
constant XORr_7 : std_logic_vector:= "0000000";
constant SRLr_7 : std_logic_vector:= "0000000";
constant SRAr_7 : std_logic_vector:= "0100000";
constant ORr_7 : std_logic_vector:= "0000000";
constant ANDr_7 : std_logic_vector:= "0000000";
constant NOP_instr : std_logic_vector(31 downto 0) := x"00000013";
-- conditional branches 63 func3
constant BEQ : std_logic_vector:= "000";
constant BNE : std_logic_vector:= "001";
constant BGE : std_logic_vector:= "101";
-- constants used to define the characteristics of the datapath components
constant PC_size : integer := 32;
constant data_size : integer := 32; -- size of the data(word)
constant num_reg : integer := 32; -- number of (word)registers of the register file
-- Constants that define the size of the Control Unit signals and memories.
constant IR_SIZE : integer := 32; -- size in bits of the instruction
constant OP_CODE_SIZE : integer := 7; -- size in bits of the opcode field in the instruction
constant FUNC3_SIZE : integer := 3; -- size in bits of the function field in the instruction
constant FUNC7_SIZE : integer := 7; -- size in bits of the function field in the instruction
constant FUNC_SIZE : integer := 10; -- size in bits of the function field in the instruction
constant imm_size : integer := 12; -- size in bits of the immediate field in the instruction
constant uCODE_LUT_SIZE : integer := 62; -- size in elements of Microcode Memory Size (contains the cotrol words) (45->I, 1->R, 1->FP, 15->unused)
constant CW_SIZE : integer := 13; -- size in bits of the Control Word);
end constants;
-- Package declaration. Contains any non standard function used in the project
package functions is
function Log2 (x:integer) return integer ;
end package functions;
-- Package body
package body functions is
-------------------------------------------------------------------------------
-- Log2
-------------------------------------------------------------------------------
function Log2 (x:integer) return integer is
variable temp : integer := x ;
variable n : integer := 0 ;
begin
while temp > 1 loop
temp := temp /2;
n := n + 1;
end loop;
if x > 2**n then
return (n + 1);
else
return (n);
end if;
end function;
end functions;