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

Subversion Repositories plasma

[/] [plasma/] [tags/] [V3_0/] [vhdl/] [mlite_pack.vhd] - Blame information for rev 50

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 rhoads
---------------------------------------------------------------------
2 43 rhoads
-- TITLE: Plasma Misc. Package
3 39 rhoads
-- AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
4
-- DATE CREATED: 2/15/01
5
-- FILENAME: mlite_pack.vhd
6 43 rhoads
-- PROJECT: Plasma CPU core
7 39 rhoads
-- COPYRIGHT: Software placed into the public domain by the author.
8
--    Software 'as is' without warranty.  Author liable for nothing.
9
-- DESCRIPTION:
10 43 rhoads
--    Data types, constants, and add functions needed for the Plasma CPU.
11 39 rhoads
---------------------------------------------------------------------
12
library ieee;
13
use ieee.std_logic_1164.all;
14
 
15
package mlite_pack is
16
   constant ZERO          : std_logic_vector(31 downto 0) :=
17
      "00000000000000000000000000000000";
18
   constant ONES          : std_logic_vector(31 downto 0) :=
19
      "11111111111111111111111111111111";
20
   --make HIGH_Z equal to ZERO if compiler complains
21
   constant HIGH_Z        : std_logic_vector(31 downto 0) :=
22
      "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ";
23
 
24
--   type alu_function_type is (alu_nothing, alu_add, alu_subtract, 
25
--      alu_less_than, alu_less_than_signed, alu_equal, alu_not_equal,
26
--      alu_ltz, alu_lez, alu_eqz, alu_nez, alu_gez, alu_gtz,
27
--      alu_or, alu_and, alu_xor, alu_nor);
28
   subtype alu_function_type is std_logic_vector(4 downto 0);
29
   constant alu_nothing   : alu_function_type := "00000";
30
   constant alu_add       : alu_function_type := "00010";
31
   constant alu_subtract  : alu_function_type := "00011";
32
   constant alu_less_than : alu_function_type := "00100";
33
   constant alu_less_than_signed : alu_function_type := "00101";
34
   constant alu_equal     : alu_function_type := "00110";
35
   constant alu_not_equal : alu_function_type := "00111";
36
   constant alu_ltz       : alu_function_type := "01000";
37
   constant alu_lez       : alu_function_type := "01001";
38
   constant alu_eqz       : alu_function_type := "01010";
39
   constant alu_nez       : alu_function_type := "01011";
40
   constant alu_gez       : alu_function_type := "01100";
41
   constant alu_gtz       : alu_function_type := "01101";
42
   constant alu_or        : alu_function_type := "01110";
43
   constant alu_and       : alu_function_type := "01111";
44
   constant alu_xor       : alu_function_type := "10001";
45
   constant alu_nor       : alu_function_type := "10010";
46
 
47
--   type shift_function_type is (
48
--      shift_nothing, shift_left_unsigned,
49
--      shift_right_signed, do_right_unsigned);
50
   subtype shift_function_type is std_logic_vector(1 downto 0);
51
   constant shift_nothing        : shift_function_type := "00";
52
   constant shift_left_unsigned  : shift_function_type := "01";
53
   constant shift_right_signed   : shift_function_type := "11";
54
   constant shift_right_unsigned : shift_function_type := "10";
55
 
56
--   type mult_function_type is (
57
--      mult_nothing, mult_read_lo, mult_read_hi, mult_write_lo, 
58
--      mult_write_hi, mult_mult, mult_divide, mult_signed_divide);
59 44 rhoads
   subtype mult_function_type is std_logic_vector(3 downto 0);
60
   constant mult_nothing       : mult_function_type := "0000";
61
   constant mult_read_lo       : mult_function_type := "0001";
62
   constant mult_read_hi       : mult_function_type := "0010";
63
   constant mult_write_lo      : mult_function_type := "0011";
64
   constant mult_write_hi      : mult_function_type := "0100";
65
   constant mult_mult          : mult_function_type := "0101";
66
   constant mult_signed_mult   : mult_function_type := "0110";
67
   constant mult_divide        : mult_function_type := "0111";
68
   constant mult_signed_divide : mult_function_type := "1000";
69 39 rhoads
 
70
--   type a_source_type is (from_reg_source, from_imm10_6);
71
   subtype a_source_type is std_logic_vector(1 downto 0);
72
   constant a_from_reg_source : a_source_type := "00";
73
   constant a_from_imm10_6    : a_source_type := "01";
74
   constant a_from_pc         : a_source_type := "10";
75
 
76
--   type b_source_type is (from_reg_target, from_imm, from_signed_imm);
77
   subtype b_source_type is std_logic_vector(1 downto 0);
78
   constant b_from_reg_target : b_source_type := "00";
79
   constant b_from_imm        : b_source_type := "01";
80
   constant b_from_signed_imm : b_source_type := "10";
81
   constant b_from_immX4      : b_source_type := "11";
82
 
83
--   type c_source_type is (from_null, from_alu, from_shift, 
84
--      from_mult, from_memory, from_pc, from_imm_shift16,
85
--      from_reg_source_nez, from_reg_source_eqz);
86
   subtype c_source_type is std_logic_vector(2 downto 0);
87
   constant c_from_null       : c_source_type := "000";
88
   constant c_from_alu        : c_source_type := "001";
89
   constant c_from_shift      : c_source_type := "001"; --same as alu
90
   constant c_from_mult       : c_source_type := "001"; --same as alu
91
   constant c_from_memory     : c_source_type := "010";
92
   constant c_from_pc         : c_source_type := "011";
93
   constant c_from_pc_plus4   : c_source_type := "100";
94
   constant c_from_imm_shift16: c_source_type := "101";
95
   constant c_from_reg_sourcen: c_source_type := "110";
96
 
97
--   type pc_source_type is (from_inc4, from_inc8, from_reg_source, 
98
--      from_opcode25_0, from_branch, from_lbranch);
99
   subtype pc_source_type is std_logic_vector(1 downto 0);
100
   constant from_inc4       : pc_source_type := "00";
101
   constant from_opcode25_0 : pc_source_type := "01";
102
   constant from_branch     : pc_source_type := "10";
103
   constant from_lbranch    : pc_source_type := "11";
104
 
105
   subtype branch_function_type is std_logic_vector(2 downto 0);
106
   constant branch_ltz : branch_function_type := "000";
107
   constant branch_lez : branch_function_type := "001";
108
   constant branch_eq  : branch_function_type := "010";
109
   constant branch_ne  : branch_function_type := "011";
110
   constant branch_gez : branch_function_type := "100";
111
   constant branch_gtz : branch_function_type := "101";
112
   constant branch_yes : branch_function_type := "110";
113
 
114
   -- mode(32=1,16=2,8=3), signed, write
115
   subtype mem_source_type is std_logic_vector(3 downto 0);
116
   constant mem_none    : mem_source_type := "0000";
117
   constant mem_read32  : mem_source_type := "0100";
118
   constant mem_write32 : mem_source_type := "0101";
119
   constant mem_read16  : mem_source_type := "1000";
120
   constant mem_read16s : mem_source_type := "1010";
121
   constant mem_write16 : mem_source_type := "1001";
122
   constant mem_read8   : mem_source_type := "1100";
123
   constant mem_read8s  : mem_source_type := "1110";
124
   constant mem_write8  : mem_source_type := "1101";
125
 
126
   function bv_to_integer(bv: in std_logic_vector) return integer;
127
   function bv_adder(a     : in std_logic_vector(32 downto 0);
128
                     b     : in std_logic_vector(32 downto 0);
129 47 rhoads
                     do_add: in std_logic) return std_logic_vector;
130 39 rhoads
   function bv_adder_lookahead(
131
                     a     : in std_logic_vector(32 downto 0);
132
                     b     : in std_logic_vector(32 downto 0);
133 47 rhoads
                     do_add: in std_logic) return std_logic_vector;
134 39 rhoads
   function bv_negate(a : in std_logic_vector) return std_logic_vector;
135
   function bv_increment(a : in std_logic_vector(31 downto 2)
136
                     ) return std_logic_vector;
137
   function bv_inc6(a : in std_logic_vector
138
                     ) return std_logic_vector;
139 47 rhoads
 
140
   -- For Altera
141
   COMPONENT lpm_add_sub
142
      GENERIC (
143
         lpm_width          : NATURAL;
144
         lpm_direction  : STRING;
145
         lpm_type                          : STRING;
146
         lpm_hint                          : STRING);
147
      PORT (
148
         dataa    : IN STD_LOGIC_VECTOR (32 DOWNTO 0);
149
         add_sub        : IN STD_LOGIC ;
150
         datab    : IN STD_LOGIC_VECTOR (32 DOWNTO 0);
151
         result  : OUT STD_LOGIC_VECTOR (32 DOWNTO 0));
152
   END COMPONENT;
153
 
154
   -- For Altera
155
   COMPONENT lpm_ram_dp
156
      GENERIC (
157
         lpm_width        : NATURAL;
158
         lpm_widthad      : NATURAL;
159
         rden_used        : STRING;
160
         intended_device_family : STRING;
161
         lpm_indata       : STRING;
162
         lpm_wraddress_control          : STRING;
163
         lpm_rdaddress_control          : STRING;
164
         lpm_outdata      : STRING;
165
         use_eab          : STRING;
166
         lpm_type         : STRING);
167
      PORT (
168
         wren        : IN STD_LOGIC ;
169
         wrclock   : IN STD_LOGIC ;
170
         q         : OUT STD_LOGIC_VECTOR (31 DOWNTO 0);
171
         data      : IN STD_LOGIC_VECTOR (31 DOWNTO 0);
172
         rdaddress : IN STD_LOGIC_VECTOR (4 DOWNTO 0);
173
         wraddress : IN STD_LOGIC_VECTOR (4 DOWNTO 0));
174
   END COMPONENT;
175
 
176
   -- For Altera
177
   component lpm_ram_io
178
      GENERIC (
179
         intended_device_family : string;
180
         lpm_width              : natural;
181
         lpm_widthad            : natural;
182
         lpm_indata             : string := "REGISTERED";
183
         lpm_address_control    : string := "UNREGISTERED";
184
         lpm_outdata            : string := "UNREGISTERED";
185
         lpm_file               : string := "code.hex";
186
         use_eab                : string := "ON";
187
         lpm_type               : string := "LPM_RAM_DQ");
188
      PORT (
189
         outenab : in std_logic;
190
         address : in std_logic_vector(lpm_widthad-1 downto 0);
191
         inclock : in std_logic;
192
         we      : in std_logic;
193
         dio     : inout std_logic_vector(lpm_width-1 downto 0));
194
   end component; --lpm_ram_io
195
 
196
   -- For Xilinx
197
   component ramb4_s16_s16
198
      port (
199
         clka  : in std_logic;
200
         rsta  : in std_logic;
201
         addra : in std_logic_vector;
202
         dia   : in std_logic_vector;
203
         ena   : in std_logic;
204
         wea   : in std_logic;
205
         doa   : out std_logic_vector;
206
 
207
         clkb  : in std_logic;
208
         rstb  : in std_logic;
209
         addrb : in std_logic_vector;
210
         dib   : in std_logic_vector;
211
         enb   : in std_logic;
212
         web   : in std_logic);
213
   end component;
214
 
215
   component pc_next
216
      port(clk          : in std_logic;
217
           reset_in     : in std_logic;
218
           pc_new       : in std_logic_vector(31 downto 2);
219
           take_branch  : in std_logic;
220
           pause_in     : in std_logic;
221
           opcode25_0   : in std_logic_vector(25 downto 0);
222
           pc_source    : in pc_source_type;
223
           pc_out       : out std_logic_vector(31 downto 0);
224
           pc_out_plus4 : out std_logic_vector(31 downto 0));
225
   end component;
226
 
227
   component mem_ctrl
228
      port(clk          : in std_logic;
229
           reset_in     : in std_logic;
230
           pause_in     : in std_logic;
231
           nullify_op   : in std_logic;
232
           address_pc   : in std_logic_vector(31 downto 0);
233
           opcode_out   : out std_logic_vector(31 downto 0);
234
 
235
           address_data : in std_logic_vector(31 downto 0);
236
           mem_source   : in mem_source_type;
237
           data_write   : in std_logic_vector(31 downto 0);
238
           data_read    : out std_logic_vector(31 downto 0);
239
           pause_out    : out std_logic;
240
 
241
           mem_address  : out std_logic_vector(31 downto 0);
242
           mem_data_w   : out std_logic_vector(31 downto 0);
243
           mem_data_r   : in std_logic_vector(31 downto 0);
244
           mem_byte_sel : out std_logic_vector(3 downto 0);
245
           mem_write    : out std_logic;
246
           mem_pause    : in std_logic);
247
   end component;
248
 
249
   component control
250
      port(opcode       : in  std_logic_vector(31 downto 0);
251
           intr_signal  : in  std_logic;
252
           pause_in     : in  std_logic;
253
           rs_index     : out std_logic_vector(5 downto 0);
254
           rt_index     : out std_logic_vector(5 downto 0);
255
           rd_index     : out std_logic_vector(5 downto 0);
256
           imm_out      : out std_logic_vector(15 downto 0);
257
           alu_func     : out alu_function_type;
258
           shift_func   : out shift_function_type;
259
           mult_func    : out mult_function_type;
260
           branch_func  : out branch_function_type;
261
           a_source_out : out a_source_type;
262
           b_source_out : out b_source_type;
263
           c_source_out : out c_source_type;
264
           pc_source_out: out pc_source_type;
265
           mem_source_out:out mem_source_type);
266
   end component;
267
 
268
   component reg_bank
269
      generic(memory_type : string := "TRI_PORT");
270
      port(clk            : in  std_logic;
271
           reset_in       : in  std_logic;
272
           rs_index       : in  std_logic_vector(5 downto 0);
273
           rt_index       : in  std_logic_vector(5 downto 0);
274
           rd_index       : in  std_logic_vector(5 downto 0);
275
           reg_source_out : out std_logic_vector(31 downto 0);
276
           reg_target_out : out std_logic_vector(31 downto 0);
277
           reg_dest_new   : in  std_logic_vector(31 downto 0);
278
           intr_enable    : out std_logic);
279
   end component;
280
 
281
   component bus_mux
282
      port(imm_in       : in  std_logic_vector(15 downto 0);
283
           reg_source   : in  std_logic_vector(31 downto 0);
284
           a_mux        : in  a_source_type;
285
           a_out        : out std_logic_vector(31 downto 0);
286
 
287
           reg_target   : in  std_logic_vector(31 downto 0);
288
           b_mux        : in  b_source_type;
289
           b_out        : out std_logic_vector(31 downto 0);
290
 
291
           c_bus        : in  std_logic_vector(31 downto 0);
292
           c_memory     : in  std_logic_vector(31 downto 0);
293
           c_pc         : in  std_logic_vector(31 downto 0);
294
           c_pc_plus4   : in  std_logic_vector(31 downto 0);
295
           c_mux        : in  c_source_type;
296
           reg_dest_out : out std_logic_vector(31 downto 0);
297
 
298
           branch_func  : in  branch_function_type;
299
           take_branch  : out std_logic);
300
   end component;
301
 
302
   component alu
303
      generic(adder_type : string := "GENERIC");
304
      port(a_in         : in  std_logic_vector(31 downto 0);
305
           b_in         : in  std_logic_vector(31 downto 0);
306
           alu_function : in  alu_function_type;
307
           c_alu        : out std_logic_vector(31 downto 0));
308
   end component;
309
 
310
   component shifter
311
      port(value        : in  std_logic_vector(31 downto 0);
312
           shift_amount : in  std_logic_vector(4 downto 0);
313
           shift_func   : in  shift_function_type;
314
           c_shift      : out std_logic_vector(31 downto 0));
315
   end component;
316
 
317
   component mult
318
      generic(adder_type : string := "GENERIC");
319
      port(clk       : in std_logic;
320
           a, b      : in std_logic_vector(31 downto 0);
321
           mult_func : in mult_function_type;
322
           c_mult    : out std_logic_vector(31 downto 0);
323
           pause_out : out std_logic);
324
   end component;
325
 
326
   component mlite_cpu
327
      generic(memory_type : string := "ALTERA");
328
      port(clk         : in std_logic;
329
           reset_in    : in std_logic;
330
           intr_in     : in std_logic;
331
 
332
           mem_address : out std_logic_vector(31 downto 0);
333
           mem_data_w  : out std_logic_vector(31 downto 0);
334
           mem_data_r  : in std_logic_vector(31 downto 0);
335
           mem_byte_sel: out std_logic_vector(3 downto 0);
336
           mem_write   : out std_logic;
337
           mem_pause   : in std_logic);
338
   end component;
339
 
340 50 rhoads
   component ram
341
      generic(memory_type : string := "GENERIC");
342 47 rhoads
      port(clk          : in std_logic;
343
           mem_byte_sel : in std_logic_vector(3 downto 0);
344
           mem_write    : in std_logic;
345 50 rhoads
           mem_address  : in std_logic_vector(31 downto 0);
346
           mem_data     : inout std_logic_vector(31 downto 0));
347 47 rhoads
   end component; --ram
348
 
349
   component uart
350 50 rhoads
      generic(log_file : string := "UNUSED");
351
      port(clk        : in std_logic;
352
           reset      : in std_logic;
353
           uart_sel   : in std_logic;
354
           data       : in std_logic_vector(7 downto 0);
355
           uart_read  : in std_logic;
356
           uart_write : out std_logic;
357
           pause      : out std_logic);
358 47 rhoads
   end component; --uart
359
 
360 50 rhoads
   component plasma
361
      generic(memory_type : string := "GENERIC";
362
              log_file    : string := "UNUSED");
363
      port(clk_in           : in std_logic;
364
           reset_in         : in std_logic;
365
           intr_in          : in std_logic;
366
 
367
           uart_read        : in std_logic;
368
           uart_write       : out std_logic;
369
 
370
           mem_address_out  : out std_logic_vector(31 downto 0);
371
           mem_data         : inout std_logic_vector(31 downto 0);
372
           mem_byte_sel_out : out std_logic_vector(3 downto 0);
373
           mem_write_out    : out std_logic;
374
           mem_pause_in     : in std_logic);
375
   end component; --plasma
376
 
377 39 rhoads
end; --package mlite_pack
378
 
379
package body mlite_pack is
380
 
381
function add_1(a:integer) return integer is
382
begin
383
   return a+1;
384
end; --function
385
 
386
function bv_to_integer(bv: in std_logic_vector) return integer is
387
   variable result : integer;
388
   variable b      : integer;
389
begin
390
   result := 0;
391
   b := 0;
392
   for index in bv'range loop
393
      if bv(index) = '1' then
394
         b := 1;
395
      else
396
         b := 0;
397
      end if;
398
      result := result * 2 + b;
399
   end loop;
400
   return result;
401
end; --function bv_to_integer
402
 
403
function bv_adder(a     : in std_logic_vector(32 downto 0);
404
                  b     : in std_logic_vector(32 downto 0);
405 47 rhoads
                  do_add: in std_logic) return std_logic_vector is
406 39 rhoads
   variable carry_in : std_logic;
407
   variable bb       : std_logic_vector(32 downto 0);
408
   variable result   : std_logic_vector(32 downto 0);
409
begin
410 47 rhoads
   result := '0' & ZERO;
411
   if do_add = '1' then
412 39 rhoads
      bb := b;
413
      carry_in := '0';
414
   else
415
      bb := not b;
416
      carry_in := '1';
417
   end if;
418
   for index in 0 to 32 loop
419
      result(index) := a(index) xor bb(index) xor carry_in;
420
      carry_in := (carry_in and (a(index) or bb(index))) or
421
                  (a(index) and bb(index));
422
   end loop;
423
   return result;
424
end; --function
425
 
426
function bv_adder_lookahead(
427
                  a     : in std_logic_vector(32 downto 0);
428
                  b     : in std_logic_vector(32 downto 0);
429 47 rhoads
                  do_add: in std_logic) return std_logic_vector is
430 39 rhoads
   variable carry    : std_logic_vector(32 downto 0);
431
   variable p, g     : std_logic_vector(32 downto 0);
432
   variable bb       : std_logic_vector(32 downto 0);
433
   variable result   : std_logic_vector(32 downto 0);
434
   variable i        : natural;
435
begin
436 47 rhoads
   carry := '0' & ZERO;
437
   if do_add = '1' then
438 39 rhoads
      bb := b;
439
      carry(0) := '0';
440
   else
441
      bb := not b;
442
      carry(0) := '1';
443
   end if;
444
 
445
   p := a or bb;   --propogate
446
   g := a and bb;  --generate
447
   for index in 0 to 7 loop
448
      i := index*4;
449
      carry(i+1) := g(i) or
450
                    (p(i) and carry(i));
451
      i := index*4+1;
452
      carry(i+1) := g(i) or
453
                    (p(i) and g(i-1)) or
454
                    ((p(i) and p(i-1)) and carry(i-1));
455
      i := index*4+2;
456
      carry(i+1) := g(i) or
457
                    (p(i) and g(i-1)) or
458
                    (p(i) and p(i-1) and g(i-2)) or
459
                    ((p(i) and p(i-1) and p(i-2)) and carry(i-2));
460
      i := index*4+3;
461
      carry(i+1) := g(i) or
462
                    (p(i) and g(i-1)) or
463
                    (p(i) and p(i-1) and g(i-2)) or
464
                    (p(i) and p(i-1) and p(i-2) and g(i-3)) or
465
                    (((p(i) and p(i-1)) and (p(i-2) and p(i-3)))
466
                       and carry(i-3));
467
   end loop;
468
   result := (a xor bb) xor carry;
469
   return result;
470
end; --function
471
 
472
function bv_negate(a : in std_logic_vector) return std_logic_vector is
473
   variable carry_in : std_logic;
474
   variable not_a    : std_logic_vector(31 downto 0);
475
   variable result   : std_logic_vector(31 downto 0);
476
begin
477
   result := ZERO;
478
   not_a := not a;
479
   carry_in := '1';
480
   for index in a'reverse_range loop
481
      result(index) := not_a(index) xor carry_in;
482
      carry_in := carry_in and not_a(index);
483
   end loop;
484
   return result;
485
end; --function
486
 
487
function bv_increment(a : in std_logic_vector(31 downto 2)
488
                     ) return std_logic_vector is
489
   variable carry_in : std_logic;
490
   variable result   : std_logic_vector(31 downto 2);
491
begin
492 47 rhoads
   result := ZERO(31 downto 2);
493 39 rhoads
   carry_in := '1';
494
   for index in 2 to 31 loop
495
      result(index) := a(index) xor carry_in;
496
      carry_in := a(index) and carry_in;
497
   end loop;
498
   return result;
499
end; --function
500
 
501
function bv_inc6(a : in std_logic_vector
502
                     ) return std_logic_vector is
503
   variable carry_in : std_logic;
504
   variable result   : std_logic_vector(5 downto 0);
505
begin
506
   result := "000000";
507
   carry_in := '1';
508
   for index in 0 to 5 loop
509
      result(index) := a(index) xor carry_in;
510
      carry_in := a(index) and carry_in;
511
   end loop;
512
   return result;
513
end; --function
514
 
515
end; --package body
516
 
517
 

powered by: WebSVN 2.1.0

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