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

Subversion Repositories riscompatible

[/] [riscompatible/] [trunk/] [rtl/] [riscompatible_package.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 borin
-------------------------------------------------------------------------------------------------------------------
2
library ieee;
3
use ieee.std_logic_1164.all;
4
use ieee.numeric_std.all;
5
-------------------------------------------------------------------------------------------------------------------
6
package riscompatible_package is
7
    ---------------------------------------------
8
    constant C_NumBitsWord    : integer:=32;
9
    constant C_NumBitsRegBank : natural:=3;
10
    subtype TRiscoWord is std_logic_vector(C_NumBitsWord-1 downto 0);
11
    subtype TRiscoWordPlusCarry is std_logic_vector(C_NumBitsWord downto 0); -- Carry = bit 32
12
    ---------------------------------------------
13
    -- Flags
14
    ---------------------------------------------
15
    type TRiscoFlag is record
16
        Clr_I  : std_logic;
17
        Wen_I  : std_logic;
18
        Data_I : std_logic;
19
        Data_O : std_logic;
20
    end record;
21
    ---------------------------------------------
22
    -- Registers
23
    ---------------------------------------------
24
    type TRiscoReg is record
25
        Clr_I  : std_logic;
26
        Wen_I  : std_logic;
27
        Data_I : std_logic_vector(C_NumBitsWord-1 downto 0);
28
        Data_O : std_logic_vector(C_NumBitsWord-1 downto 0);
29
    end record;
30
    ---------------------------------------------
31
    -- Instruction Types
32
    ---------------------------------------------
33
    constant INST_ULA : std_logic_vector(1 downto 0):="00";
34
    constant INST_MEM : std_logic_vector(1 downto 0):="10";
35
    constant INST_JMP : std_logic_vector(1 downto 0):="01";
36
    constant INST_SUB : std_logic_vector(1 downto 0):="11";
37
    ---------------------------------------------
38
    -- Arithmetic Logical Instructions
39
    ---------------------------------------------
40
    -- ALU
41
    constant C_AND      : std_logic_vector(4 downto 0):="01111";
42
    constant C_OR       : std_logic_vector(4 downto 0):="01110";
43
    constant C_XOR      : std_logic_vector(4 downto 0):="01101";
44
 
45
    constant C_SUBRC    : std_logic_vector(4 downto 0):="01011";
46
    constant C_SUBRCNOT : std_logic_vector(4 downto 0):="01010";
47
    constant C_SUBR     : std_logic_vector(4 downto 0):="01001";
48
    constant C_SUBRNC   : std_logic_vector(4 downto 0):="01000";
49
 
50
    constant C_SUBC     : std_logic_vector(4 downto 0):="00111";
51
    constant C_SUBCNOT  : std_logic_vector(4 downto 0):="00110";
52
    constant C_SUB      : std_logic_vector(4 downto 0):="00101";
53
    constant C_SUBNC    : std_logic_vector(4 downto 0):="00100";
54
 
55
    constant C_ADDCNOT  : std_logic_vector(4 downto 0):="00011";
56
    constant C_ADDC     : std_logic_vector(4 downto 0):="00010";
57
    constant C_ADD1     : std_logic_vector(4 downto 0):="00001";
58
    constant C_ADD      : std_logic_vector(4 downto 0):="00000";
59
 
60
    -- UD
61
 
62
    constant C_RLL      : std_logic_vector(4 downto 0):="10000";
63
    constant C_RLLC     : std_logic_vector(4 downto 0):="10001";
64
    constant C_RLA      : std_logic_vector(4 downto 0):="10010";
65
    constant C_RLAC     : std_logic_vector(4 downto 0):="10011";
66
 
67
    constant C_RRL      : std_logic_vector(4 downto 0):="10100";
68
    constant C_RRLC     : std_logic_vector(4 downto 0):="10101";
69
    constant C_RRA      : std_logic_vector(4 downto 0):="10110";
70
    constant C_RRAC     : std_logic_vector(4 downto 0):="10111";
71
 
72
    constant C_SLL      : std_logic_vector(4 downto 0):="11000";
73
    constant C_SLLC     : std_logic_vector(4 downto 0):="11001";
74
    constant C_SLA      : std_logic_vector(4 downto 0):="11010";
75
    constant C_SLAC     : std_logic_vector(4 downto 0):="11011";
76
 
77
    constant C_SRL      : std_logic_vector(4 downto 0):="11100";
78
    constant C_SRLC     : std_logic_vector(4 downto 0):="11101";
79
    constant C_SRA      : std_logic_vector(4 downto 0):="11110";
80
    constant C_SRAC     : std_logic_vector(4 downto 0):="11111";
81
 
82
    -- NOT PRESENT (PG 101,PG 220,PG 234): C_ADD1, C_ADDCNOT, C_SUBCNOT, C_SUBNC, C_SUBRNC, C_SUBRCNOT
83
    -- PRESENT ON PG 136
84
    ---------------------------------------------
85
    -- Memory Access Instructions
86
    ---------------------------------------------
87
    constant C_LD       : std_logic_vector(4 downto 0):="00000";
88
    constant C_LDPRI    : std_logic_vector(4 downto 0):="00111";
89
    constant C_LDPOI    : std_logic_vector(4 downto 0):="00101";
90
    constant C_LDPOD    : std_logic_vector(4 downto 0):="00100";
91
    constant C_ST       : std_logic_vector(4 downto 0):="10000";
92
    constant C_STPRI    : std_logic_vector(4 downto 0):="10111";
93
    constant C_STPOI    : std_logic_vector(4 downto 0):="10101";
94
    constant C_STPOD    : std_logic_vector(4 downto 0):="10100";
95
    ---------------------------------------------
96
    -- Conditions
97
    ---------------------------------------------
98
    constant C_TR     : std_logic_vector(4 downto 0):="11111";
99
    constant C_NS     : std_logic_vector(4 downto 0):="10001";
100
    constant C_CS     : std_logic_vector(4 downto 0):="10010";
101
    constant C_OS     : std_logic_vector(4 downto 0):="10100";
102
    constant C_ZS     : std_logic_vector(4 downto 0):="11000";
103
    constant C_GE     : std_logic_vector(4 downto 0):="10011";
104
    constant C_GT     : std_logic_vector(4 downto 0):="10110";
105
    constant C_EQ     : std_logic_vector(4 downto 0):="11100";
106
 
107
    constant C_FL     : std_logic_vector(4 downto 0):="00000";
108
    constant C_NN     : std_logic_vector(4 downto 0):="00001";
109
    constant C_NC     : std_logic_vector(4 downto 0):="00010";
110
    constant C_NO     : std_logic_vector(4 downto 0):="00100";
111
    constant C_NZ     : std_logic_vector(4 downto 0):="01000";
112
    constant C_LT     : std_logic_vector(4 downto 0):="00011";
113
    constant C_LE     : std_logic_vector(4 downto 0):="00110";
114
    constant C_NE     : std_logic_vector(4 downto 0):="01100";
115
    ---------------------------------------------
116
    -- Source Operands 
117
    ---------------------------------------------
118
    -- FT1 - Register number of source 1
119
    -- FT2 - Register number of source 2
120
    -- SS2 - Bit used to define format
121
    -- Kp  - Small constant, 11 bits, extends signal
122
    -- Kgl - Large constant, 17 bits, extends signal
123
    -- Kgh - Large constant, 16 bits, most significant part
124
    constant FFS_DST_FT1_FT2  : std_logic_vector(2 downto 0):="000";
125
    constant FFS_DST_FT1_Kp   : std_logic_vector(2 downto 0):="001";
126
    constant FFS_DST_R00_Kgl  : std_logic_vector(2 downto 0):="010";--01X
127
    constant FFS_DST_DST_Kgh  : std_logic_vector(2 downto 0):="100";--10X
128
    constant FFS_DST_DST_Kgl  : std_logic_vector(2 downto 0):="110";--11X
129
    ---------------------------------------------
130
    -- Specific Functions
131
    ---------------------------------------------
132
    --- CONSTEXT calculation
133
    function Kpe_F(Kp : std_logic_vector(10 downto 0)) return TRiscoWord;
134
    function Kgl_F(Kg : std_logic_vector(16 downto 0)) return TRiscoWord;
135
    function Kgh_F(Kg : std_logic_vector(16 downto 0)) return TRiscoWord;
136
    ---
137
    function IsZero_F(Source : std_logic_vector) return std_logic;
138
    ---------------------------------------------
139
    -- Components
140
    ---------------------------------------------
141
    component riscompatible_core is
142
        generic
143
        (
144
            NumBitsProgramMemory : Natural:=5;
145
            NumBitsDataMemory    : Natural:=5;
146
            NumBitsRegBank       : natural:=5
147
        );
148
        port
149
        (
150
            Clk_I             : in std_logic;
151
            Reset_I           : in std_logic;
152
            PMem_Enable_O     : out std_logic;
153
            PMem_Write_O      : out std_logic;
154
            PMem_Address_O    : out std_logic_vector(NumBitsProgramMemory-1 downto 0);
155
            PMem_InputData_O  : out TRiscoWord;
156
            PMem_OutputData_I : in TRiscoWord;
157
            DMem_Enable_O     : out std_logic;
158
            DMem_Write_O      : out std_logic;
159
            DMem_Address_O    : out std_logic_vector(NumBitsDataMemory-1 downto 0);
160
            DMem_InputData_O  : out TRiscoWord;
161
            DMem_OutputData_I : in TRiscoWord;
162
            Int_I             : in std_logic;
163
            IntAck_O          : out std_logic
164
        );
165
    end component;
166
    component RegisterBank is
167
        generic
168
        (
169
            NumBitsAddr : natural:=4;
170
            DataWidth   : natural:=32
171
        );
172
        port
173
        (
174
            Clk_I           : in std_logic;
175
            Enable_I        : in std_logic;
176
            Write_I         : in std_logic;
177
            RegisterW_I     : in std_logic_vector(NumBitsAddr-1 downto 0);
178
            Register1_I     : in std_logic_vector(NumBitsAddr-1 downto 0);
179
            Register2_I     : in std_logic_vector(NumBitsAddr-1 downto 0);
180
            InputData_I     : in std_logic_vector(DataWidth-1 downto 0);
181
            FT1OutputData_O : out std_logic_vector(DataWidth-1 downto 0);
182
            FT2OutputData_O : out std_logic_vector(DataWidth-1 downto 0)
183
        );
184
    end component;
185
    component Ula is
186
        port
187
        (
188
            Cy_I       : in std_logic;
189
            Source1_I  : in TRiscoWord;
190
            Source2_I  : in TRiscoWord;
191
            Function_I : in std_logic_vector(4 downto 0);
192
            Output_O   : out TRiscoWord;
193
            Cy_O       : out std_logic;
194
            Ov_O       : out std_logic;
195
            Zr_O       : out std_logic;
196
            Ng_O       : out std_logic
197
        );
198
    end component;
199
    component UD is
200
        port
201
        (
202
            InputData_I   : in TRiscoWord;
203
            ShiftAmount_I : in std_logic_vector(4 downto 0);
204
            OutputData_o  : out TRiscoWord;
205
            Function_I    : in std_logic_vector(4 downto 0);
206
            Cy_I          : in std_logic;
207
            Cy_O          : out std_logic
208
        );
209
    end component;
210
    component select_and_control is
211
        generic
212
        (
213
            NumBitsProgramMemory : Natural:=5;
214
            NumBitsDataMemory    : Natural:=5;
215
            NumBitsRegBank       : natural:=5
216
        );
217
        port
218
        (
219
            Clk_I                    : in std_logic;
220
            Reset_I                  : in std_logic;
221
            PMem_Enable_O            : out std_logic;
222
            PMem_Address_O           : out std_logic_vector(NumBitsProgramMemory - 1 downto 0);
223
            PMem_Write_O             : out std_logic;
224
            PMem_OutputData_I        : in TRiscoWord;
225
            DMem_Enable_O            : out std_logic;
226
            DMem_Write_O             : out std_logic;
227
            DMem_Address_O           : out std_logic_vector(NumBitsDataMemory - 1 downto 0);
228
            DMem_InputData_O         : out TRiscoWord;
229
            DMem_OutputData_I        : in TRiscoWord;
230
            RegBnk_Register1_O       : out std_logic_vector(NumBitsRegBank - 1 downto 0);
231
            RegBnk_Register2_O       : out std_logic_vector(NumBitsRegBank - 1 downto 0);
232
            RegBnk_RegisterW_O       : out std_logic_vector(NumBitsRegBank - 1 downto 0);
233
            RegBnk_Write_O           : out std_logic;
234
            RegBnk_InputData_O       : out TRiscoWord;
235
            RegBnk_FT1_OutputData_I  : in TRiscoWord;
236
            RegBnk_FT2_OutputData_I  : in TRiscoWord;
237
            ULA_Function_O           : out std_logic_vector(4 downto 0);
238
            ULA_Output_I             : in TRiscoWord;
239
            ULA_Ng_O_I               : in std_logic;
240
            ULA_Cy_O_I               : in std_logic;
241
            ULA_Ov_O_I               : in std_logic;
242
            ULA_Zr_O_I               : in std_logic;
243
            UD_Function_O            : out std_logic_vector(4 downto 0);
244
            UD_OutputData_I          : in TRiscoWord;
245
            UD_Cy_O_I                : in std_logic;
246
            RUA_Clr_O                : out std_logic;
247
            RUB_Clr_O                : out std_logic;
248
            RDA_Clr_O                : out std_logic;
249
            RDB_Clr_O                : out std_logic;
250
            RUA_Wen_O                : out std_logic;
251
            RUB_Wen_O                : out std_logic;
252
            RDA_Wen_O                : out std_logic;
253
            RDB_Wen_O                : out std_logic;
254
            RUA_Data_O               : out std_logic_vector(C_NumBitsWord - 1 downto 0);
255
            RUB_Data_O               : out std_logic_vector(C_NumBitsWord - 1 downto 0);
256
            RDA_Data_O               : out std_logic_vector(C_NumBitsWord - 1 downto 0);
257
            RDB_Data_O               : out std_logic_vector(C_NumBitsWord - 1 downto 0);
258
            PC_Clr_O                 : out std_logic;
259
            PC_Wen_O                 : out std_logic;
260
            PC_Data_I                : in std_logic_vector(C_NumBitsWord - 1 downto 0);
261
            PC_Data_O                : out std_logic_vector(C_NumBitsWord - 1 downto 0);
262
            PSW_Clr_O                : out std_logic;
263
            PSW_Wen_O                : out std_logic;
264
            PSW_Data_I               : in std_logic_vector(C_NumBitsWord - 1 downto 0);
265
            PSW_Data_O               : out std_logic_vector(C_NumBitsWord - 1 downto 0);
266
            Int_I                    : in std_logic;
267
            IntAck_O                 : out std_logic
268
        );
269
    end component;
270
    component reg is
271
        generic
272
        (
273
            NumBits : Natural:=5
274
        );
275
        port
276
        (
277
            Clk_I : in std_logic;
278
            Clr_I : in std_logic;
279
            Wen_I : in std_logic;
280
            Data_I : in std_logic_vector (NumBits-1 downto 0);
281
            Data_O : out std_logic_vector (NumBits-1 downto 0)
282
        );
283
    end component;
284
end package;
285
package body riscompatible_package is
286
    ---------------------------------------------
287
    -- Implementation  of functions
288
    ---------------------------------------------
289
    -- Extends signal of Kp 
290
    function Kpe_F(Kp : std_logic_vector(10 downto 0)) return TRiscoWord is
291
        variable VKpe : TRiscoWord;
292
    begin
293
        VKpe(10 downto 0):=Kp;
294
        VKpe(TRiscoWord'high downto 11):=(others=>Kp(10));
295
        return VKpe;
296
    end function Kpe_F;
297
    ---------------------------------------------
298
    -- Extends signal of Kg
299
    function Kgl_F(Kg : std_logic_vector(16 downto 0)) return TRiscoWord is
300
        variable VKgl : TRiscoWord;
301
    begin
302
        VKgl(16 downto 0):=Kg;
303
        VKgl(TRiscoWord'high downto 17):=(others=>Kg(16));
304
        return VKgl;
305
    end function Kgl_F;
306
    ---------------------------------------------
307
    -- Kg go to high order bits; low order bits receive the signal extension of Kg
308
    function Kgh_F(Kg : std_logic_vector(16 downto 0)) return TRiscoWord is
309
        variable VKgh : TRiscoWord;
310
    begin
311
        VKgh(31 downto 16):=Kg(15 downto 0);
312
        VKgh(15 downto 0):=(others=>Kg(16));
313
        return VKgh;
314
    end function Kgh_F;
315
    ---------------------------------------------
316
    -- Set if word is equal to zero
317
    function IsZero_F(Source : std_logic_vector) return std_logic is
318
        variable counter : integer range Source'range;
319
        variable accumulator : std_logic:='0';
320
    begin
321
        for counter in 0 to Source'high loop
322
            accumulator:=accumulator or Source(counter);
323
        end loop;
324
        return (not accumulator);
325
    end function IsZero_F;
326
end riscompatible_package;
327
-------------------------------------------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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