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

Subversion Repositories ffr16

[/] [ffr16/] [tags/] [t1641/] [rtl/] [050803kn/] [kcpsm.vhd] - Blame information for rev 13

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 armando
-- Constant (K) Coded Programmable State Machine for Spartan-II and Virtex-E Devices
2
--
3
-- Version : 1.00c
4
-- Version Date : 14th August 2002
5
--
6
-- Start of design entry : 2nd July 2002
7
--
8
-- Ken Chapman
9
-- Xilinx Ltd
10
-- Benchmark House
11
-- 203 Brooklands Road
12
-- Weybridge
13
-- Surrey KT13 ORH
14
-- United Kingdom
15
--
16
-- chapman@xilinx.com
17
--
18
------------------------------------------------------------------------------------
19
--
20
-- NOTICE:
21
--
22
-- Copyright Xilinx, Inc. 2002.   This code may be contain portions patented by other 
23
-- third parites.  By providing this core as one possible implementation of a standard,
24
-- Xilinx is making no representation that the provided implementation of this standard 
25
-- is free from any claims of infringement by any third party.  Xilinx expressly 
26
-- disclaims any warranty with respect to the adequacy of the implementation, including 
27
-- but not limited to any warranty or representation that the implementation is free 
28
-- from claims of any third party.  Futhermore, Xilinx is providing this core as a 
29
-- courtesy to you and suggests that you contact all third parties to obtain the 
30
-- necessary rights to use this implementation.
31
--
32
------------------------------------------------------------------------------------
33
--
34
-- Format of this file.
35
--
36
-- This file contains the definition of KCPSM and all the submodules which it 
37
-- required. The definition of KCPSM is placed at the end of this file as the order 
38
-- in which each entity is read is important for some simulation and synthesis tools.
39
-- Hence the first entity to be seen below is that of a submodule.
40
--
41
--
42
-- The submodules define the implementation of the logic using Xilinx primitives.
43
-- These ensure predictable synthesis results and maximise the density of the implementation. 
44
-- The Unisim Library is used to define Xilinx primitives. It is also used during
45
-- simulation. The source can be viewed at %XILINX%\vhdl\src\unisims\unisim_VCOMP.vhd
46
-- It is only specified in sub modules which contain primitive components.
47
-- 
48
-- library unisim;
49
-- use unisim.vcomponents.all;
50
--
51
------------------------------------------------------------------------------------
52
--
53
-- Description of sub-modules and further low level modules.
54
--
55
------------------------------------------------------------------------------------
56
--
57
-- Definition of an 8-bit bus 4 to 1 multiplexer with embeded select signal decoding.
58
-- 
59
-- sel1  sel0a  sel0b   Y_bus 
60
--  
61
--  0      0      x     D0_bus
62
--  0      1      x     D1_bus
63
--  1      x      0     D2_bus
64
--  1      x      1     D3_bus
65
--
66
-- sel1 is the pipelined decode of instruction12, instruction13, and instruction15.
67
-- sel0a is code2 after pipeline delay.
68
-- sel0b is instruction14 after pipeline delay.
69
--
70
-- Requires 17 LUTs and 3 flip-flops.
71
--
72
library IEEE;
73
use IEEE.STD_LOGIC_1164.ALL;
74
use IEEE.STD_LOGIC_ARITH.ALL;
75
use IEEE.STD_LOGIC_UNSIGNED.ALL;
76
library unisim;
77
use unisim.vcomponents.all;
78
--
79
entity data_bus_mux4 is
80
    Port (         D3_bus : in std_logic_vector(7 downto 0);
81
                   D2_bus : in std_logic_vector(7 downto 0);
82
                   D1_bus : in std_logic_vector(7 downto 0);
83
                   D0_bus : in std_logic_vector(7 downto 0);
84
            instruction15 : in std_logic;
85
            instruction14 : in std_logic;
86
            instruction13 : in std_logic;
87
            instruction12 : in std_logic;
88
                    code2 : in std_logic;
89
                    Y_bus : out std_logic_vector(7 downto 0);
90
                      clk : in std_logic );
91
    end data_bus_mux4;
92
--
93
architecture low_level_definition of data_bus_mux4 is
94
--
95
-- Internal signals
96
--
97
signal upper_selection : std_logic_vector(7 downto 0);
98
signal lower_selection : std_logic_vector(7 downto 0);
99
signal decode_sel1     : std_logic;
100
signal sel1            : std_logic;
101
signal sel0a           : std_logic;
102
signal sel0b           : std_logic;
103
--
104
-- Attribute to define LUT contents during implementation 
105
-- The information is repeated in the generic map for functional simulation
106
attribute INIT : string;
107
attribute INIT of decode_lut : label is "E0";
108
--
109
begin
110
 
111
  -- Forming decode signals
112
 
113
  decode_lut: LUT3
114
  --translate_off
115
    generic map (INIT => X"E0")
116
  --translate_on
117
  port map( I0 => instruction12,
118
            I1 => instruction13,
119
            I2 => instruction15,
120
             O => decode_sel1 );
121
 
122
  sel1_pipe: FD
123
  port map ( D => decode_sel1,
124
             Q => sel1,
125
             C => clk);
126
 
127
  sel0a_pipe: FD
128
  port map ( D => code2,
129
             Q => sel0a,
130
             C => clk);
131
 
132
  sel0b_pipe: FD
133
  port map ( D => instruction14,
134
             Q => sel0b,
135
             C => clk);
136
 
137
  bus_width_loop: for i in 0 to 7 generate
138
  --
139
  -- Attribute to define LUT contents during implementation 
140
  -- The information is repeated in the generic map for functional simulation
141
  attribute INIT : string;
142
  attribute INIT of high_mux_lut : label is "E4";
143
  attribute INIT of low_mux_lut  : label is "E4";
144
 
145
  --
146
  begin
147
 
148
    high_mux_lut: LUT3
149
    --translate_off
150
      generic map (INIT => X"E4")
151
    --translate_on
152
    port map( I0 => sel0b,
153
              I1 => D2_bus(i),
154
              I2 => D3_bus(i),
155
               O => upper_selection(i) );
156
 
157
    low_mux_lut: LUT3
158
    --translate_off
159
      generic map (INIT => X"E4")
160
    --translate_on
161
    port map( I0 => sel0a,
162
              I1 => D0_bus(i),
163
              I2 => D1_bus(i),
164
               O => lower_selection(i) );
165
 
166
    final_mux: MUXF5
167
    port map(  I1 => upper_selection(i),
168
               I0 => lower_selection(i),
169
                S => sel1,
170
                O => Y_bus(i) );
171
 
172
  end generate bus_width_loop;
173
--
174
end low_level_definition;
175
--
176
------------------------------------------------------------------------------------
177
--
178
-- Definition of an 8-bit shift/rotate process
179
--      
180
-- This function uses 11 LUTs.
181
-- The function contains an output pipeline register using 9 FDs.
182
--
183
-- Operation
184
--
185
-- The input operand is shifted by one bit left or right.
186
-- The bit which falls out of the end is passed to the carry_out.
187
-- The bit shifted in is determined by the select bits
188
--
189
--     code1    code0         Bit injected
190
--
191
--       0        0          carry_in           
192
--       0        1          msb of input_operand 
193
--       1        0          lsb of operand 
194
--       1        1          inject_bit 
195
--
196
library IEEE;
197
use IEEE.STD_LOGIC_1164.ALL;
198
use IEEE.STD_LOGIC_ARITH.ALL;
199
use IEEE.STD_LOGIC_UNSIGNED.ALL;
200
library unisim;
201
use unisim.vcomponents.all;
202
--
203
entity shift_rotate_process is
204
    Port    (    operand : in std_logic_vector(7 downto 0);
205
                carry_in : in std_logic;
206
              inject_bit : in std_logic;
207
             shift_right : in std_logic;
208
                   code1 : in std_logic;
209
                   code0 : in std_logic;
210
                       Y : out std_logic_vector(7 downto 0);
211
               carry_out : out std_logic;
212
                     clk : in std_logic);
213
    end shift_rotate_process;
214
--
215
architecture low_level_definition of shift_rotate_process is
216
--
217
-- Attribute to define LUT contents during implementation 
218
-- The information is repeated in the generic map for functional simulation
219
attribute INIT : string;
220
attribute INIT of high_mux_lut       : label is "E4";
221
attribute INIT of low_mux_lut        : label is "E4";
222
attribute INIT of carry_out_mux_lut  : label is "E4";
223
--
224
-- Internal signals
225
--
226
signal upper_selection : std_logic;
227
signal lower_selection : std_logic;
228
signal mux_output      : std_logic_vector(7 downto 0);
229
signal shift_in_bit    : std_logic;
230
signal carry_bit       : std_logic;
231
--
232
begin
233
  --
234
  -- 4 to 1 mux selection of the bit to be shifted in
235
  --
236
 
237
    high_mux_lut: LUT3
238
    --translate_off
239
      generic map (INIT => X"E4")
240
    --translate_on
241
    port map( I0 => code0,
242
              I1 => operand(0),
243
              I2 => inject_bit,
244
               O => upper_selection );
245
 
246
    low_mux_lut: LUT3
247
    --translate_off
248
      generic map (INIT => X"E4")
249
    --translate_on
250
    port map( I0 => code0,
251
              I1 => carry_in,
252
              I2 => operand(7),
253
               O => lower_selection );
254
 
255
    final_mux: MUXF5
256
    port map(  I1 => upper_selection,
257
               I0 => lower_selection,
258
                S => code1,
259
                O => shift_in_bit );
260
 
261
  --
262
  -- shift left or right of operand
263
  --
264
  bus_width_loop: for i in 0 to 7 generate
265
  --
266
  begin
267
 
268
     lsb_shift: if i=0 generate
269
        --
270
        -- Attribute to define LUT contents during implementation 
271
        -- The information is repeated in the generic map for functional simulation
272
        attribute INIT : string;
273
        attribute INIT of mux_lut : label is "E4";
274
        --
275
        begin
276
 
277
          mux_lut: LUT3
278
          --translate_off
279
            generic map (INIT => X"E4")
280
          --translate_on
281
          port map( I0 => shift_right,
282
                    I1 => shift_in_bit,
283
                    I2 => operand(i+1),
284
                     O => mux_output(i) );
285
 
286
        end generate lsb_shift;
287
 
288
     mid_shift: if i>0 and i<7 generate
289
        --
290
        -- Attribute to define LUT contents during implementation 
291
        -- The information is repeated in the generic map for functional simulation
292
        attribute INIT : string;
293
        attribute INIT of mux_lut : label is "E4";
294
        --
295
        begin
296
 
297
          mux_lut: LUT3
298
          --translate_off
299
            generic map (INIT => X"E4")
300
          --translate_on
301
          port map( I0 => shift_right,
302
                    I1 => operand(i-1),
303
                    I2 => operand(i+1),
304
                     O => mux_output(i) );
305
 
306
          end generate mid_shift;
307
 
308
     msb_shift: if i=7 generate
309
        --
310
        -- Attribute to define LUT contents during implementation 
311
        -- The information is repeated in the generic map for functional simulation
312
        attribute INIT : string;
313
        attribute INIT of mux_lut : label is "E4";
314
        --
315
        begin
316
 
317
          mux_lut: LUT3
318
          --translate_off
319
            generic map (INIT => X"E4")
320
          --translate_on
321
          port map( I0 => shift_right,
322
                    I1 => operand(i-1),
323
                    I2 => shift_in_bit,
324
                     O => mux_output(i) );
325
 
326
          end generate msb_shift;
327
 
328
     pipeline_bit: FD
329
     port map ( D => mux_output(i),
330
                Q => Y(i),
331
                C => clk);
332
 
333
  end generate bus_width_loop;
334
  --
335
  -- Selection of carry output
336
  --
337
 
338
  carry_out_mux_lut: LUT3
339
  --translate_off
340
    generic map (INIT => X"E4")
341
  --translate_on
342
  port map( I0 => shift_right,
343
            I1 => operand(7),
344
            I2 => operand(0),
345
             O => carry_bit );
346
 
347
  pipeline_bit: FD
348
  port map ( D => carry_bit,
349
             Q => carry_out,
350
             C => clk);
351
--
352
end low_level_definition;
353
--
354
------------------------------------------------------------------------------------
355
--
356
-- Definition of an 8-bit logical processing unit
357
--      
358
-- This function uses 8 LUTs (4 slices) to provide the logical bit operations.
359
-- The function contains an output pipeline register using 8 FDs.
360
--
361
--     Code1    Code0       Bit Operation
362
--
363
--       0        0            LOAD      Y <= second_operand 
364
--       0        1            AND       Y <= first_operand and second_operand
365
--       1        0            OR        Y <= first_operand or second_operand 
366
--       1        1            XOR       Y <= first_operand xor second_operand
367
--
368
library IEEE;
369
use IEEE.STD_LOGIC_1164.ALL;
370
use IEEE.STD_LOGIC_ARITH.ALL;
371
use IEEE.STD_LOGIC_UNSIGNED.ALL;
372
library unisim;
373
use unisim.vcomponents.all;
374
--
375
entity logical_bus_processing is
376
    Port (  first_operand : in std_logic_vector(7 downto 0);
377
           second_operand : in std_logic_vector(7 downto 0);
378
                    code1 : in std_logic;
379
                    code0 : in std_logic;
380
                        Y : out std_logic_vector(7 downto 0);
381
                      clk : in std_logic);
382
    end logical_bus_processing;
383
--
384
architecture low_level_definition of logical_bus_processing is
385
--
386
-- Internal signals
387
--
388
signal combinatorial_logical_processing : std_logic_vector(7 downto 0);
389
--
390
begin
391
 
392
  bus_width_loop: for i in 0 to 7 generate
393
  --
394
  -- Attribute to define LUT contents during implementation 
395
  -- The information is repeated in the generic map for functional simulation
396
  attribute INIT : string;
397
  attribute INIT of logical_lut : label is "6E8A";
398
  --
399
  begin
400
 
401
     logical_lut: LUT4
402
     --translate_off
403
     generic map (INIT => X"6E8A")
404
     --translate_on
405
     port map( I0 => second_operand(i),
406
               I1 => first_operand(i),
407
               I2 => code0,
408
               I3 => code1,
409
                O => combinatorial_logical_processing(i));
410
 
411
     pipeline_bit: FD
412
     port map ( D => combinatorial_logical_processing(i),
413
                Q => Y(i),
414
                C => clk);
415
 
416
  end generate bus_width_loop;
417
--
418
end low_level_definition;
419
--
420
------------------------------------------------------------------------------------
421
--
422
--
423
-- Definition of an 8-bit arithmetic process
424
--      
425
-- This function uses 10 LUTs and associated carry logic.
426
-- The function contains an output pipeline register using 9 FDs.
427
--
428
-- Operation
429
--
430
-- Two input operands are added or subtracted.
431
-- An input carry bit can be included in the calculation.
432
-- An output carry is always generated.
433
-- Carry signals work in the positive sense at all times.
434
--
435
--     code1     code0         Bit injected
436
--
437
--       0        0            ADD           
438
--       0        1            ADD with carry 
439
--       1        0            SUB  
440
--       1        1            SUB with carry 
441
--
442
library IEEE;
443
use IEEE.STD_LOGIC_1164.ALL;
444
use IEEE.STD_LOGIC_ARITH.ALL;
445
use IEEE.STD_LOGIC_UNSIGNED.ALL;
446
library unisim;
447
use unisim.vcomponents.all;
448
--
449
entity arithmetic_process is
450
    Port (  first_operand : in std_logic_vector(7 downto 0);
451
           second_operand : in std_logic_vector(7 downto 0);
452
                 carry_in : in std_logic;
453
                    code1 : in std_logic;
454
                    code0 : in std_logic;
455
                        Y : out std_logic_vector(7 downto 0);
456
                carry_out : out std_logic;
457
                      clk : in std_logic);
458
    end arithmetic_process;
459
--
460
architecture low_level_definition of arithmetic_process is
461
--
462
-- Internal signals
463
--
464
signal carry_in_bit       : std_logic;
465
signal carry_out_bit      : std_logic;
466
signal modified_carry_out : std_logic;
467
signal half_addsub        : std_logic_vector(7 downto 0);
468
signal full_addsub        : std_logic_vector(7 downto 0);
469
signal carry_chain        : std_logic_vector(6 downto 0);
470
--
471
--
472
-- Attributes to define LUT contents during implementation 
473
-- The information is repeated in the generic map for functional simulation
474
attribute INIT : string;
475
attribute INIT of carry_input_lut : label is "78";
476
attribute INIT of carry_output_lut : label is "6";
477
--
478
begin
479
  --
480
  -- Selection of the carry input to add/sub
481
  --
482
  carry_input_lut: LUT3
483
  --translate_off
484
    generic map (INIT => X"78")
485
  --translate_on
486
  port map( I0 => carry_in,
487
            I1 => code0,
488
            I2 => code1,
489
             O => carry_in_bit );
490
  --
491
  -- Main add/sub
492
  --    
493
  --    code1    Operation
494
  --
495
  --      0          ADD          Y <= first_operand + second_operand
496
  --      1          SUB          Y <= first_operand - second_operand
497
  --                
498
  bus_width_loop: for i in 0 to 7 generate
499
  --
500
  -- Attribute to define LUT contents during implementation 
501
  -- The information is repeated in the generic map for functional simulation
502
  attribute INIT : string;
503
  attribute INIT of arithmetic_lut : label is "96";
504
  --
505
  begin
506
 
507
     lsb_carry: if i=0 generate
508
        begin
509
 
510
          arithmetic_carry: MUXCY
511
          port map( DI => first_operand(i),
512
                    CI => carry_in_bit,
513
                     S => half_addsub(i),
514
                     O => carry_chain(i));
515
 
516
          arithmetic_xor: XORCY
517
          port map( LI => half_addsub(i),
518
                    CI => carry_in_bit,
519
                     O => full_addsub(i));
520
 
521
          end generate lsb_carry;
522
 
523
     mid_carry: if i>0 and i<7 generate
524
        begin
525
 
526
          arithmetic_carry: MUXCY
527
          port map( DI => first_operand(i),
528
                    CI => carry_chain(i-1),
529
                     S => half_addsub(i),
530
                     O => carry_chain(i));
531
 
532
          arithmetic_xor: XORCY
533
          port map( LI => half_addsub(i),
534
                    CI => carry_chain(i-1),
535
                     O => full_addsub(i));
536
 
537
          end generate mid_carry;
538
 
539
     msb_carry: if i=7 generate
540
        begin
541
 
542
          arithmetic_carry: MUXCY
543
          port map( DI => first_operand(i),
544
                    CI => carry_chain(i-1),
545
                     S => half_addsub(i),
546
                     O => carry_out_bit);
547
 
548
          arithmetic_xor: XORCY
549
          port map( LI => half_addsub(i),
550
                    CI => carry_chain(i-1),
551
                     O => full_addsub(i));
552
 
553
          end generate msb_carry;
554
 
555
     arithmetic_lut: LUT3
556
     --translate_off
557
     generic map (INIT => X"96")
558
     --translate_on
559
     port map( I0 => first_operand(i),
560
               I1 => second_operand(i),
561
               I2 => code1,
562
                O => half_addsub(i));
563
 
564
     pipeline_bit: FD
565
     port map ( D => full_addsub(i),
566
                Q => Y(i),
567
                C => clk);
568
 
569
  end generate bus_width_loop;
570
 
571
  --
572
  -- Modification to carry output and pipeline
573
  --
574
  carry_output_lut: LUT2
575
  --translate_off
576
    generic map (INIT => X"6")
577
  --translate_on
578
  port map( I0 => carry_out_bit,
579
            I1 => code1,
580
             O => modified_carry_out );
581
 
582
  pipeline_bit: FD
583
 
584
  port map ( D => modified_carry_out,
585
             Q => carry_out,
586
             C => clk);
587
--
588
end low_level_definition;
589
--
590
------------------------------------------------------------------------------------
591
--
592
-- Definition of the Zero and Carry Flags including decoding logic.
593
--      
594
-- The ZERO value is detected using 2 LUTs and associated carry logic to 
595
-- form a wired NOR gate. A further LUT selects the source for the ZERO flag
596
-- which is stored in an FDRE.
597
--
598
-- Definition of the Carry Flag 
599
--
600
-- 3 LUTs and a pipeline flip-flop are used to select the source for the 
601
-- CARRY flag which is stored in an FDRE.
602
--
603
-- Total size 11 LUTs and 5 flip-flops.
604
--
605
library IEEE;
606
use IEEE.STD_LOGIC_1164.ALL;
607
use IEEE.STD_LOGIC_ARITH.ALL;
608
use IEEE.STD_LOGIC_UNSIGNED.ALL;
609
library unisim;
610
use unisim.vcomponents.all;
611
--
612
entity flag_logic is
613
    Port (                data : in std_logic_vector(7 downto 0);
614
                 instruction15 : in std_logic;
615
                 instruction14 : in std_logic;
616
                 instruction13 : in std_logic;
617
                 instruction12 : in std_logic;
618
                  instruction8 : in std_logic;
619
                  instruction6 : in std_logic;
620
                          code : in std_logic_vector(2 downto 0);
621
                   shadow_zero : in std_logic;
622
                  shadow_carry : in std_logic;
623
            shift_rotate_carry : in std_logic;
624
                 add_sub_carry : in std_logic;
625
                         reset : in std_logic;
626
                       T_state : in std_logic;
627
                     zero_flag : out std_logic;
628
                    carry_flag : out std_logic;
629
                           clk : in std_logic);
630
    end flag_logic;
631
--
632
architecture low_level_definition of flag_logic is
633
--
634
-- Internal signals
635
--
636
 
637
signal enable1a                 : std_logic;
638
signal enable1a_carry           : std_logic;
639
signal enable1b                 : std_logic;
640
signal enable1b_carry           : std_logic;
641
signal flag_en_op_sx_or_returni : std_logic;
642
signal enable2a                 : std_logic;
643
signal enable2a_carry           : std_logic;
644
signal enable2b                 : std_logic;
645
signal enable2b_carry           : std_logic;
646
signal flag_en_op_sx_sy_or_kk   : std_logic;
647
signal flag_enable              : std_logic;
648
signal lower_zero               : std_logic;
649
signal upper_zero               : std_logic;
650
signal lower_zero_carry         : std_logic;
651
signal data_zero                : std_logic;
652
signal next_zero_flag           : std_logic;
653
signal carry_status             : std_logic;
654
signal next_carry_flag          : std_logic;
655
signal sX_op_decode             : std_logic;
656
signal sX_operation             : std_logic;
657
--
658
-- Attributes to define LUT contents during implementation 
659
-- The information is repeated in the generic map for functional simulation
660
attribute INIT : string;
661
attribute INIT of en1a_lut         : label is "F002";
662
attribute INIT of en1b_lut         : label is "4";
663
attribute INIT of en2a_lut         : label is "10FF";
664
attribute INIT of en2b_lut         : label is "FE";
665
attribute INIT of flag_enable_lut  : label is "A8";
666
attribute INIT of lower_zero_lut   : label is "0001";
667
attribute INIT of upper_zero_lut   : label is "0001";
668
attribute INIT of zero_select_lut  : label is "F4B0";
669
attribute INIT of operation_lut    : label is "2000";
670
attribute INIT of carry_status_lut : label is "EC20";
671
attribute INIT of carry_select_lut : label is "F4B0";
672
--
673
begin
674
 
675
  --
676
  -- Decode instructions requiring flags to be enabled
677
  --
678
 
679
  en1a_lut: LUT4
680
  --translate_off
681
    generic map (INIT => X"F002")
682
  --translate_on
683
  port map( I0 => instruction6,
684
            I1 => instruction8,
685
            I2 => instruction12,
686
            I3 => instruction14,
687
             O => enable1a );
688
 
689
  en1b_lut: LUT2
690
  --translate_off
691
    generic map (INIT => X"4")
692
  --translate_on
693
  port map( I0 => instruction13,
694
            I1 => instruction15,
695
             O => enable1b );
696
 
697
  en1a_muxcy: MUXCY
698
  port map( DI => '0',
699
            CI => '1',
700
             S => enable1a,
701
             O => enable1a_carry );
702
 
703
  en1b_cymux: MUXCY
704
  port map( DI => '0',
705
            CI => enable1a_carry,
706
             S => enable1b,
707
             O => enable1b_carry );
708
 
709
  enable1_flop: FD
710
  port map ( D => enable1b_carry,
711
             Q => flag_en_op_sx_or_returni,
712
             C => clk);
713
 
714
  en2a_lut: LUT4
715
  --translate_off
716
    generic map (INIT => X"10FF")
717
  --translate_on
718
  port map( I0 => instruction12,
719
            I1 => instruction13,
720
            I2 => instruction14,
721
            I3 => instruction15,
722
             O => enable2a );
723
 
724
  en2b_lut: LUT3
725
  --translate_off
726
    generic map (INIT => X"FE")
727
  --translate_on
728
  port map( I0 => code(0),
729
            I1 => code(1),
730
            I2 => code(2),
731
             O => enable2b );
732
 
733
  en2a_muxcy: MUXCY
734
  port map( DI => '0',
735
            CI => '1',
736
             S => enable2a,
737
             O => enable2a_carry );
738
 
739
  en2b_cymux: MUXCY
740
  port map( DI => '0',
741
            CI => enable2a_carry,
742
             S => enable2b,
743
             O => enable2b_carry );
744
 
745
  enable2_flop: FD
746
  port map ( D => enable2b_carry,
747
             Q => flag_en_op_sx_sy_or_kk,
748
             C => clk);
749
 
750
  flag_enable_lut: LUT3
751
  --translate_off
752
    generic map (INIT => X"A8")
753
  --translate_on
754
  port map( I0 => T_state,
755
            I1 => flag_en_op_sx_sy_or_kk,
756
            I2 => flag_en_op_sx_or_returni,
757
             O => flag_enable );
758
 
759
  --
760
  -- Detect all bits in data are zero using wired NOR gate
761
  --
762
  lower_zero_lut: LUT4
763
  --translate_off
764
    generic map (INIT => X"0001")
765
  --translate_on
766
  port map( I0 => data(0),
767
            I1 => data(1),
768
            I2 => data(2),
769
            I3 => data(3),
770
             O => lower_zero );
771
 
772
  upper_zero_lut: LUT4
773
  --translate_off
774
    generic map (INIT => X"0001")
775
  --translate_on
776
  port map( I0 => data(4),
777
            I1 => data(5),
778
            I2 => data(6),
779
            I3 => data(7),
780
             O => upper_zero );
781
 
782
  lower_zero_muxcy: MUXCY
783
  port map( DI => '0',
784
            CI => '1',
785
             S => lower_zero,
786
             O => lower_zero_carry );
787
 
788
  upper_zero_cymux: MUXCY
789
  port map( DI => '0',
790
            CI => lower_zero_carry,
791
             S => upper_zero,
792
             O => data_zero );
793
  --
794
  -- Select new zero status or the shaddow flag for a RETURNI
795
  --
796
  zero_select_lut: LUT4
797
  --translate_off
798
    generic map (INIT => X"F4B0")
799
  --translate_on
800
  port map( I0 => instruction14,
801
            I1 => instruction15,
802
            I2 => data_zero,
803
            I3 => shadow_zero,
804
             O => next_zero_flag );
805
 
806
  zero_flag_flop: FDRE
807
  port map ( D => next_zero_flag,
808
             Q => zero_flag,
809
            CE => flag_enable,
810
             R => reset,
811
             C => clk);
812
  --
813
  -- Select new carry status based on operation
814
  --
815
 
816
  operation_lut: LUT4
817
  --translate_off
818
    generic map (INIT => X"2000")
819
  --translate_on
820
  port map( I0 => instruction12,
821
            I1 => instruction13,
822
            I2 => instruction14,
823
            I3 => instruction15,
824
             O => sX_op_decode );
825
 
826
  operation_pipe: FD
827
  port map ( D => sX_op_decode,
828
             Q => sX_operation,
829
             C => clk);
830
 
831
  carry_status_lut: LUT4
832
  --translate_off
833
    generic map (INIT => X"EC20")
834
  --translate_on
835
  port map( I0 => code(2),
836
            I1 => sX_operation,
837
            I2 => add_sub_carry,
838
            I3 => shift_rotate_carry,
839
             O => carry_status );
840
 
841
  --
842
  -- Select new carry status based on operationor the shaddow flag for a RETURNI
843
  --
844
 
845
  carry_select_lut: LUT4
846
  --translate_off
847
    generic map (INIT => X"F4B0")
848
  --translate_on
849
  port map( I0 => instruction14,
850
            I1 => instruction15,
851
            I2 => carry_status,
852
            I3 => shadow_carry,
853
             O => next_carry_flag );
854
 
855
  carry_flag_flop: FDRE
856
  port map ( D => next_carry_flag,
857
             Q => carry_flag,
858
            CE => flag_enable,
859
             R => reset,
860
             C => clk);
861
 
862
--
863
end low_level_definition;
864
--
865
------------------------------------------------------------------------------------
866
--
867
-- Definition of an 8-bit bus 2 to 1 multiplexer with built in select decode
868
--
869
-- Requires 9 LUTs.
870
--       
871
library IEEE;
872
use IEEE.STD_LOGIC_1164.ALL;
873
use IEEE.STD_LOGIC_ARITH.ALL;
874
use IEEE.STD_LOGIC_UNSIGNED.ALL;
875
library unisim;
876
use unisim.vcomponents.all;
877
--
878
entity data_bus_mux2 is
879
    Port (         D1_bus : in std_logic_vector(7 downto 0);
880
                   D0_bus : in std_logic_vector(7 downto 0);
881
            instruction15 : in std_logic;
882
            instruction14 : in std_logic;
883
            instruction13 : in std_logic;
884
            instruction12 : in std_logic;
885
                    Y_bus : out std_logic_vector(7 downto 0));
886
    end data_bus_mux2;
887
--
888
architecture low_level_definition of data_bus_mux2 is
889
--
890
-- Internal signals
891
--
892
signal constant_sy_sel  : std_logic;
893
--
894
-- Attribute to define LUT contents during implementation 
895
-- The information is repeated in the generic map for functional simulation
896
attribute INIT : string;
897
attribute INIT of decode_lut : label is "9800";
898
--
899
begin
900
 
901
  -- Forming decode signal
902
 
903
  decode_lut: LUT4
904
  --translate_off
905
    generic map (INIT => X"9800")
906
  --translate_on
907
  port map( I0 => instruction12,
908
            I1 => instruction13,
909
            I2 => instruction14,
910
            I3 => instruction15,
911
             O => constant_sy_sel );
912
 
913
  -- 2 to 1 bus multiplexer
914
 
915
  bus_width_loop: for i in 0 to 7 generate
916
  --
917
  -- Attribute to define LUT contents during implementation 
918
  -- The information is repeated in the generic map for functional simulation
919
  attribute INIT : string;
920
  attribute INIT of mux_lut : label is "E4";
921
  --
922
  begin
923
 
924
    mux_lut: LUT3
925
    --translate_off
926
      generic map (INIT => X"E4")
927
    --translate_on
928
    port map( I0 => constant_sy_sel,
929
              I1 => D0_bus(i),
930
              I2 => D1_bus(i),
931
               O => Y_bus(i) );
932
 
933
  end generate bus_width_loop;
934
--
935
end low_level_definition;
936
--
937
------------------------------------------------------------------------------------
938
--
939
-- Definition of an 3-bit bus 2 to 1 multiplexer
940
--
941
-- Requires 3 LUTs.
942
--       
943
library IEEE;
944
use IEEE.STD_LOGIC_1164.ALL;
945
use IEEE.STD_LOGIC_ARITH.ALL;
946
use IEEE.STD_LOGIC_UNSIGNED.ALL;
947
library unisim;
948
use unisim.vcomponents.all;
949
--
950
entity ALU_control_mux2 is
951
    Port (         D1_bus : in std_logic_vector(2 downto 0);
952
                   D0_bus : in std_logic_vector(2 downto 0);
953
            instruction15 : in std_logic;
954
                    Y_bus : out std_logic_vector(2 downto 0));
955
    end ALU_control_mux2;
956
--
957
architecture low_level_definition of ALU_control_mux2 is
958
--
959
begin
960
 
961
  -- 2 to 1 bus multiplexer
962
 
963
  bus_width_loop: for i in 0 to 2 generate
964
  --
965
  -- Attribute to define LUT contents during implementation 
966
  -- The information is repeated in the generic map for functional simulation
967
  attribute INIT : string;
968
  attribute INIT of mux_lut : label is "E4";
969
  --
970
  begin
971
 
972
    mux_lut: LUT3
973
    --translate_off
974
      generic map (INIT => X"E4")
975
    --translate_on
976
    port map( I0 => instruction15,
977
              I1 => D0_bus(i),
978
              I2 => D1_bus(i),
979
               O => Y_bus(i) );
980
 
981
  end generate bus_width_loop;
982
--
983
end low_level_definition;
984
--
985
------------------------------------------------------------------------------------
986
--
987
-- Definition of an 8-bit dual port RAM with 16 locations
988
-- including write enable decode.
989
--      
990
-- This mode of distributed RAM requires 1 'slice' (2 LUTs)per bit.
991
-- Total for module 18 LUTs and 1 flip-flop.
992
-- 
993
library IEEE;
994
use IEEE.STD_LOGIC_1164.ALL;
995
use IEEE.STD_LOGIC_ARITH.ALL;
996
use IEEE.STD_LOGIC_UNSIGNED.ALL;
997
library unisim;
998
use unisim.vcomponents.all;
999
--
1000
entity data_register_bank is
1001
    Port (         address_A : in std_logic_vector(3 downto 0);
1002
                   Din_A_bus : in std_logic_vector(7 downto 0);
1003
                  Dout_A_bus : out std_logic_vector(7 downto 0);
1004
                   address_B : in std_logic_vector(3 downto 0);
1005
                  Dout_B_bus : out std_logic_vector(7 downto 0);
1006
               instruction15 : in std_logic;
1007
               instruction14 : in std_logic;
1008
               instruction13 : in std_logic;
1009
            active_interrupt : in std_logic;
1010
                     T_state : in std_logic;
1011
                         clk : in std_logic);
1012
    end data_register_bank;
1013
--
1014
architecture low_level_definition of data_register_bank is
1015
--
1016
-- Internal signals
1017
--
1018
signal write_decode     : std_logic;
1019
signal register_write   : std_logic;
1020
signal register_enable  : std_logic;
1021
--
1022
-- Attribute to define LUT contents during implementation 
1023
-- The information is repeated in the generic map for functional simulation
1024
attribute INIT : string;
1025
attribute INIT of decode_lut : label is "1455";
1026
attribute INIT of gating_lut : label is "8";
1027
--
1028
begin
1029
 
1030
  -- Forming decode signal
1031
 
1032
  decode_lut: LUT4
1033
  --translate_off
1034
    generic map (INIT => X"1455")
1035
  --translate_on
1036
  port map( I0 => active_interrupt,
1037
            I1 => instruction13,
1038
            I2 => instruction14,
1039
            I3 => instruction15,
1040
             O => write_decode );
1041
 
1042
  decode_pipe: FD
1043
  port map ( D => write_decode,
1044
             Q => register_write,
1045
             C => clk);
1046
 
1047
  gating_lut: LUT2
1048
  --translate_off
1049
    generic map (INIT => X"8")
1050
  --translate_on
1051
  port map( I0 => T_state,
1052
            I1 => register_write,
1053
             O => register_enable );
1054
 
1055
  bus_width_loop: for i in 0 to 7 generate
1056
  --
1057
  -- Attribute to define RAM contents during implementation 
1058
  -- The information is repeated in the generic map for functional simulation
1059
  attribute INIT : string;
1060
  attribute INIT of data_register_bit : label is "0000";
1061
  --
1062
  begin
1063
 
1064
     data_register_bit: RAM16X1D
1065
     -- translate_off
1066
     generic map(INIT => X"0000")
1067
     -- translate_on
1068
     port map (       D => Din_A_bus(i),
1069
                     WE => register_enable,
1070
                   WCLK => clk,
1071
                     A0 => address_A(0),
1072
                     A1 => address_A(1),
1073
                     A2 => address_A(2),
1074
                     A3 => address_A(3),
1075
                  DPRA0 => address_B(0),
1076
                  DPRA1 => address_B(1),
1077
                  DPRA2 => address_B(2),
1078
                  DPRA3 => address_B(3),
1079
                    SPO => Dout_A_bus(i),
1080
                    DPO => Dout_B_bus(i));
1081
 
1082
  end generate bus_width_loop;
1083
--
1084
end low_level_definition;
1085
--
1086
------------------------------------------------------------------------------------
1087
--
1088
-- Definition of basic time T-state and clean reset
1089
--      
1090
-- This function forms the basic 2 cycle T-state control used by the processor.
1091
-- It also forms a clean synchronous reset pulse that is long enough to ensure 
1092
-- correct operation at start up and following a reset input.
1093
-- It uses 1 LUT 3 flip-flops.
1094
--
1095
library IEEE;
1096
use IEEE.STD_LOGIC_1164.ALL;
1097
use IEEE.STD_LOGIC_ARITH.ALL;
1098
use IEEE.STD_LOGIC_UNSIGNED.ALL;
1099
library unisim;
1100
use unisim.vcomponents.all;
1101
--
1102
entity T_state_and_Reset is
1103
    Port (    reset_input : in std_logic;
1104
           internal_reset : out std_logic;
1105
                  T_state : out std_logic;
1106
                      clk : in std_logic);
1107
    end T_state_and_Reset;
1108
--
1109
architecture low_level_definition of T_state_and_Reset is
1110
--
1111
-- Internal signals
1112
--
1113
signal reset_delay1     : std_logic;
1114
signal reset_delay2     : std_logic;
1115
signal not_T_state      : std_logic;
1116
signal internal_T_state : std_logic;
1117
--
1118
--
1119
-- Attributes to define LUT contents during implementation 
1120
-- The information is repeated in the generic map for functional simulation
1121
attribute INIT : string;
1122
attribute INIT of invert_lut : label is "1";
1123
--
1124
begin
1125
  --
1126
  delay_flop1: FDS
1127
  port map ( D => '0',
1128
             Q => reset_delay1,
1129
             S => reset_input,
1130
             C => clk);
1131
 
1132
  delay_flop2: FDS
1133
  port map ( D => reset_delay1,
1134
             Q => reset_delay2,
1135
             S => reset_input,
1136
             C => clk);
1137
 
1138
  invert_lut: LUT1
1139
  --translate_off
1140
    generic map (INIT => X"1")
1141
  --translate_on
1142
  port map( I0 => internal_T_state,
1143
             O => not_T_state );
1144
 
1145
  toggle_flop: FDR
1146
  port map ( D => not_T_state,
1147
             Q => internal_T_state,
1148
             R => reset_delay2,
1149
             C => clk);
1150
 
1151
  T_state <= internal_T_state;
1152
  internal_reset <= reset_delay2;
1153
--
1154
end low_level_definition;
1155
--
1156
------------------------------------------------------------------------------------
1157
--
1158
-- Definition Interrupt logic and shadow Flags.
1159
--      
1160
-- Decodes instructions which set and reset the interrupt enable flip-flop. 
1161
-- Captures interrupt input and enables shadow flags
1162
--
1163
-- Total size 4 LUTs and 5 flip-flops.
1164
--
1165
library IEEE;
1166
use IEEE.STD_LOGIC_1164.ALL;
1167
use IEEE.STD_LOGIC_ARITH.ALL;
1168
use IEEE.STD_LOGIC_UNSIGNED.ALL;
1169
library unisim;
1170
use unisim.vcomponents.all;
1171
--
1172
entity interrupt_logic is
1173
    Port (           interrupt : in std_logic;
1174
                 instruction15 : in std_logic;
1175
                 instruction14 : in std_logic;
1176
                 instruction13 : in std_logic;
1177
                  instruction8 : in std_logic;
1178
                  instruction5 : in std_logic;
1179
                  instruction4 : in std_logic;
1180
                     zero_flag : in std_logic;
1181
                    carry_flag : in std_logic;
1182
                   shadow_zero : out std_logic;
1183
                  shadow_carry : out std_logic;
1184
              active_interrupt : out std_logic;
1185
                         reset : in std_logic;
1186
                       T_state : in std_logic;
1187
                           clk : in std_logic);
1188
    end interrupt_logic;
1189
 
1190
--
1191
architecture low_level_definition of interrupt_logic is
1192
--
1193
-- Internal signals
1194
--
1195
signal clean_INT                 : std_logic;
1196
signal interrupt_pulse           : std_logic;
1197
signal active_interrupt_internal : std_logic;
1198
signal enable_a                  : std_logic;
1199
signal enable_a_carry            : std_logic;
1200
signal enable_b                  : std_logic;
1201
signal update_enable             : std_logic;
1202
signal INT_enable_value          : std_logic;
1203
signal INT_enable                : std_logic;
1204
--
1205
-- Attributes to define LUT contents during implementation 
1206
-- The information is repeated in the generic map for functional simulation
1207
attribute INIT : string;
1208
attribute INIT of pulse_lut        : label is "0080";
1209
attribute INIT of en_b_lut         : label is "ABAA";
1210
attribute INIT of en_a_lut         : label is "AE";
1211
attribute INIT of value_lut        : label is "4";
1212
--
1213
begin
1214
 
1215
  -- assignment of output signal
1216
 
1217
  active_interrupt <= active_interrupt_internal;
1218
 
1219
  --
1220
  -- Decode instructions that set or reset interrupt enable
1221
  --
1222
 
1223
  en_a_lut: LUT3
1224
  --translate_off
1225
    generic map (INIT => X"AE")
1226
  --translate_on
1227
  port map( I0 => active_interrupt_internal,
1228
            I1 => instruction4,
1229
            I2 => instruction8,
1230
             O => enable_a );
1231
 
1232
  en_b_lut: LUT4
1233
  --translate_off
1234
    generic map (INIT => X"ABAA")
1235
  --translate_on
1236
  port map( I0 => active_interrupt_internal,
1237
            I1 => instruction13,
1238
            I2 => instruction14,
1239
            I3 => instruction15,
1240
             O => enable_b );
1241
 
1242
  en_a_muxcy: MUXCY
1243
  port map( DI => '0',
1244
            CI => '1',
1245
             S => enable_a,
1246
             O => enable_a_carry );
1247
 
1248
  en_b_cymux: MUXCY
1249
  port map( DI => '0',
1250
            CI => enable_a_carry,
1251
             S => enable_b,
1252
             O => update_enable );
1253
 
1254
  value_lut: LUT2
1255
  --translate_off
1256
    generic map (INIT => X"4")
1257
  --translate_on
1258
  port map( I0 => active_interrupt_internal,
1259
            I1 => instruction5,
1260
             O => INT_enable_value );
1261
 
1262
  enable_flop: FDRE
1263
  port map ( D => INT_enable_value,
1264
             Q => INT_enable,
1265
            CE => update_enable,
1266
             R => reset,
1267
             C => clk);
1268
 
1269
  -- Capture interrupt signal and generate internal pulse if enabled
1270
 
1271
  capture_flop: FDR
1272
  port map ( D => interrupt,
1273
             Q => clean_INT,
1274
             R => reset,
1275
             C => clk);
1276
 
1277
  pulse_lut: LUT4
1278
  --translate_off
1279
    generic map (INIT => X"0080")
1280
  --translate_on
1281
  port map( I0 => T_state,
1282
            I1 => clean_INT,
1283
            I2 => INT_enable,
1284
            I3 => active_interrupt_internal,
1285
             O => interrupt_pulse );
1286
 
1287
  active_flop: FDR
1288
  port map ( D => interrupt_pulse,
1289
             Q => active_interrupt_internal,
1290
             R => reset,
1291
             C => clk);
1292
 
1293
  -- Shadow flags
1294
 
1295
  shadow_carry_flop: FDE
1296
  port map ( D => carry_flag,
1297
             Q => shadow_carry,
1298
            CE => active_interrupt_internal,
1299
             C => clk);
1300
 
1301
  shadow_zero_flop: FDE
1302
  port map ( D => zero_flag,
1303
             Q => shadow_zero,
1304
            CE => active_interrupt_internal,
1305
             C => clk);
1306
--
1307
end low_level_definition;
1308
--
1309
------------------------------------------------------------------------------------
1310
--
1311
-- Definition of the Input and Output Strobes 
1312
--      
1313
-- Uses 3 LUTs and 2 flip-flops
1314
--
1315
library IEEE;
1316
use IEEE.STD_LOGIC_1164.ALL;
1317
use IEEE.STD_LOGIC_ARITH.ALL;
1318
use IEEE.STD_LOGIC_UNSIGNED.ALL;
1319
library unisim;
1320
use unisim.vcomponents.all;
1321
--
1322
entity IO_strobe_logic is
1323
    Port (    instruction15 : in std_logic;
1324
              instruction14 : in std_logic;
1325
              instruction13 : in std_logic;
1326
           active_interrupt : in std_logic;
1327
                    T_state : in std_logic;
1328
                      reset : in std_logic;
1329
               write_strobe : out std_logic;
1330
                read_strobe : out std_logic;
1331
                        clk : in std_logic);
1332
    end IO_strobe_logic;
1333
--
1334
architecture low_level_definition of IO_strobe_logic is
1335
--
1336
-- Internal signals
1337
--
1338
signal IO_type     : std_logic;
1339
signal write_event : std_logic;
1340
signal read_event  : std_logic;
1341
--
1342
-- Attributes to define LUT contents during implementation 
1343
-- The information is repeated in the generic map for functional simulation
1344
attribute INIT : string;
1345
attribute INIT of IO_type_lut : label is "8";
1346
attribute INIT of write_lut   : label is "1000";
1347
attribute INIT of read_lut    : label is "0100";
1348
--
1349
begin
1350
  --
1351
  IO_type_lut: LUT2
1352
  --translate_off
1353
    generic map (INIT => X"8")
1354
  --translate_on
1355
  port map( I0 => instruction13,
1356
            I1 => instruction15,
1357
             O => IO_type );
1358
 
1359
  write_lut: LUT4
1360
  --translate_off
1361
    generic map (INIT => X"1000")
1362
  --translate_on
1363
  port map( I0 => active_interrupt,
1364
            I1 => T_state,
1365
            I2 => instruction14,
1366
            I3 => IO_type,
1367
             O => write_event );
1368
 
1369
  write_flop: FDR
1370
  port map ( D => write_event,
1371
             Q => write_strobe,
1372
             R => reset,
1373
             C => clk);
1374
 
1375
  read_lut: LUT4
1376
  --translate_off
1377
    generic map (INIT => X"0100")
1378
  --translate_on
1379
  port map( I0 => active_interrupt,
1380
            I1 => T_state,
1381
            I2 => instruction14,
1382
            I3 => IO_type,
1383
             O => read_event );
1384
 
1385
  read_flop: FDR
1386
  port map ( D => read_event,
1387
             Q => read_strobe,
1388
             R => reset,
1389
             C => clk);
1390
--
1391
end low_level_definition;
1392
--
1393
------------------------------------------------------------------------------------
1394
--
1395
-- Definition of RAM for stack
1396
--       
1397
-- This is a 16 location single port RAM of 8-bits to support the address range
1398
-- of the program counter. The ouput is registered and the write enable is active low.
1399
--
1400
-- Total size 8 LUTs and 8 flip-flops.
1401
--
1402
library IEEE;
1403
use IEEE.STD_LOGIC_1164.ALL;
1404
use IEEE.STD_LOGIC_ARITH.ALL;
1405
use IEEE.STD_LOGIC_UNSIGNED.ALL;
1406
library unisim;
1407
use unisim.vcomponents.all;
1408
--
1409
entity stack_ram is
1410
    Port (        Din : in std_logic_vector(7 downto 0);
1411
                 Dout : out std_logic_vector(7 downto 0);
1412
                 addr : in std_logic_vector(3 downto 0);
1413
            write_bar : in std_logic;
1414
                  clk : in std_logic);
1415
    end stack_ram;
1416
--
1417
architecture low_level_definition of stack_ram is
1418
--
1419
-- Internal signals
1420
--
1421
signal ram_out      : std_logic_vector(7 downto 0);
1422
signal write_enable : std_logic;
1423
--
1424
begin
1425
 
1426
  invert_enable: INV   -- Inverter should be implemented in the WE to RAM
1427
  port map(  I => write_bar,
1428
             O => write_enable);
1429
 
1430
  bus_width_loop: for i in 0 to 7 generate
1431
  --
1432
  -- Attribute to define RAM contents during implementation 
1433
  -- The information is repeated in the generic map for functional simulation
1434
  --
1435
  attribute INIT : string;
1436
  attribute INIT of stack_ram_bit : label is "0000";
1437
  --
1438
  begin
1439
 
1440
     stack_ram_bit: RAM16X1S
1441
     -- translate_off
1442
     generic map(INIT => X"0000")
1443
     -- translate_on
1444
     port map (    D => Din(i),
1445
                  WE => write_enable,
1446
                WCLK => clk,
1447
                  A0 => addr(0),
1448
                  A1 => addr(1),
1449
                  A2 => addr(2),
1450
                  A3 => addr(3),
1451
                   O => ram_out(i));
1452
 
1453
     stack_ram_flop: FD
1454
     port map ( D => ram_out(i),
1455
                Q => Dout(i),
1456
                C => clk);
1457
 
1458
  end generate bus_width_loop;
1459
--
1460
end low_level_definition;
1461
--
1462
------------------------------------------------------------------------------------
1463
--
1464
-- Definition of a 4-bit special counter for stack pointer
1465
-- including instruction decoding.      
1466
--
1467
-- Total size 8 LUTs and 4 flip-flops.
1468
--
1469
library IEEE;
1470
use IEEE.STD_LOGIC_1164.ALL;
1471
use IEEE.STD_LOGIC_ARITH.ALL;
1472
use IEEE.STD_LOGIC_UNSIGNED.ALL;
1473
library unisim;
1474
use unisim.vcomponents.all;
1475
--
1476
entity stack_counter is
1477
    Port (        instruction15 : in std_logic;
1478
                  instruction14 : in std_logic;
1479
                  instruction13 : in std_logic;
1480
                  instruction12 : in std_logic;
1481
                   instruction9 : in std_logic;
1482
                   instruction8 : in std_logic;
1483
                   instruction7 : in std_logic;
1484
                        T_state : in std_logic;
1485
             flag_condition_met : in std_logic;
1486
               active_interrupt : in std_logic;
1487
                          reset : in std_logic;
1488
                    stack_count : out std_logic_vector(3 downto 0);
1489
                            clk : in std_logic);
1490
    end stack_counter;
1491
--
1492
architecture low_level_definition of stack_counter is
1493
--
1494
-- Internal signals
1495
--
1496
signal not_interrupt     : std_logic;
1497
signal count_value       : std_logic_vector(3 downto 0);
1498
signal next_count        : std_logic_vector(3 downto 0);
1499
signal count_carry       : std_logic_vector(2 downto 0);
1500
signal half_count        : std_logic_vector(3 downto 0);
1501
signal call_type         : std_logic;
1502
signal valid_to_move     : std_logic;
1503
signal pp_decode_a       : std_logic;
1504
signal pp_decode_a_carry : std_logic;
1505
signal pp_decode_b       : std_logic;
1506
signal push_or_pop_type  : std_logic;
1507
--
1508
-- Attributes to define LUT contents during implementation 
1509
-- The information is repeated in the generic map for functional simulation
1510
attribute INIT : string;
1511
attribute INIT of valid_move_lut : label is "D";
1512
attribute INIT of call_lut       : label is "0200";
1513
attribute INIT of pp_a_lut       : label is "F2";
1514
attribute INIT of pp_b_lut       : label is "10";
1515
--
1516
begin
1517
 
1518
  invert_interrupt: INV   -- Inverter should be implemented in the CE to flip flops
1519
  port map(  I => active_interrupt,
1520
             O => not_interrupt);
1521
  --
1522
  -- Control logic decoding
1523
  --
1524
  valid_move_lut: LUT2
1525
  --translate_off
1526
    generic map (INIT => X"D")
1527
  --translate_on
1528
  port map( I0 => instruction12,
1529
            I1 => flag_condition_met,
1530
             O => valid_to_move );
1531
 
1532
  call_lut: LUT4
1533
  --translate_off
1534
    generic map (INIT => X"0200")
1535
  --translate_on
1536
  port map( I0 => instruction9,
1537
            I1 => instruction13,
1538
            I2 => instruction14,
1539
            I3 => instruction15,
1540
             O => call_type );
1541
 
1542
 
1543
  pp_a_lut: LUT3
1544
  --translate_off
1545
    generic map (INIT => X"F2")
1546
  --translate_on
1547
  port map( I0 => instruction7,
1548
            I1 => instruction8,
1549
            I2 => instruction9,
1550
             O => pp_decode_a );
1551
 
1552
  pp_b_lut: LUT3
1553
  --translate_off
1554
    generic map (INIT => X"10")
1555
  --translate_on
1556
  port map( I0 => instruction13,
1557
            I1 => instruction14,
1558
            I2 => instruction15,
1559
             O => pp_decode_b );
1560
 
1561
  pp_a_muxcy: MUXCY
1562
  port map( DI => '0',
1563
            CI => '1',
1564
             S => pp_decode_a,
1565
             O => pp_decode_a_carry );
1566
 
1567
  en_b_cymux: MUXCY
1568
  port map( DI => '0',
1569
            CI => pp_decode_a_carry,
1570
             S => pp_decode_b,
1571
             O => push_or_pop_type  );
1572
 
1573
  count_width_loop: for i in 0 to 3 generate
1574
  --
1575
  -- The counter
1576
  --
1577
  begin
1578
 
1579
     register_bit: FDRE
1580
     port map ( D => next_count(i),
1581
                Q => count_value(i),
1582
                R => reset,
1583
               CE => not_interrupt,
1584
                C => clk);
1585
 
1586
     lsb_count: if i=0 generate
1587
        --
1588
      -- Attribute to define LUT contents during implementation 
1589
      -- The information is repeated in the generic map for functional simulation
1590
      --
1591
      attribute INIT : string;
1592
      attribute INIT of count_lut : label is "6555";
1593
      --
1594
        begin
1595
 
1596
       count_lut: LUT4
1597
       --translate_off
1598
       generic map (INIT => X"6555")
1599
       --translate_on
1600
       port map( I0 => count_value(i),
1601
                 I1 => T_state,
1602
                 I2 => valid_to_move,
1603
                 I3 => push_or_pop_type,
1604
                  O => half_count(i) );
1605
 
1606
       count_muxcy: MUXCY
1607
       port map( DI => count_value(i),
1608
                 CI => '0',
1609
                  S => half_count(i),
1610
                  O => count_carry(i));
1611
 
1612
       count_xor: XORCY
1613
       port map( LI => half_count(i),
1614
                 CI => '0',
1615
                  O => next_count(i));
1616
 
1617
          end generate lsb_count;
1618
 
1619
     mid_count: if i>0 and i<3 generate
1620
     --
1621
     -- Attribute to define LUT contents during implementation 
1622
     -- The information is repeated in the generic map for functional simulation
1623
     --
1624
     attribute INIT : string;
1625
     attribute INIT of count_lut : label is "A999";
1626
     --
1627
     begin
1628
 
1629
       count_lut: LUT4
1630
       --translate_off
1631
       generic map (INIT => X"A999")
1632
       --translate_on
1633
       port map( I0 => count_value(i),
1634
                 I1 => T_state,
1635
                 I2 => valid_to_move,
1636
                 I3 => call_type,
1637
                  O => half_count(i) );
1638
 
1639
       count_muxcy: MUXCY
1640
       port map( DI => count_value(i),
1641
                 CI => count_carry(i-1),
1642
                  S => half_count(i),
1643
                  O => count_carry(i));
1644
 
1645
       count_xor: XORCY
1646
       port map( LI => half_count(i),
1647
                 CI => count_carry(i-1),
1648
                  O => next_count(i));
1649
 
1650
     end generate mid_count;
1651
 
1652
     msb_count: if i=3 generate
1653
     --
1654
     -- Attribute to define LUT contents during implementation 
1655
     -- The information is repeated in the generic map for functional simulation
1656
     --
1657
     attribute INIT : string;
1658
     attribute INIT of count_lut : label is "A999";
1659
     --
1660
     begin
1661
 
1662
       count_lut: LUT4
1663
       --translate_off
1664
       generic map (INIT => X"A999")
1665
       --translate_on
1666
       port map( I0 => count_value(i),
1667
                 I1 => T_state,
1668
                 I2 => valid_to_move,
1669
                 I3 => call_type,
1670
                  O => half_count(i) );
1671
 
1672
       count_xor: XORCY
1673
       port map( LI => half_count(i),
1674
                 CI => count_carry(i-1),
1675
                  O => next_count(i));
1676
 
1677
     end generate msb_count;
1678
 
1679
  end generate count_width_loop;
1680
 
1681
  stack_count <= count_value;
1682
--
1683
end low_level_definition;
1684
--
1685
------------------------------------------------------------------------------------
1686
--
1687
-- Definition of an 8-bit program counter
1688
--      
1689
-- This function provides the program counter and all decode logic.
1690
--
1691
-- Total size 21 LUTs and 8 flip-flops.
1692
--
1693
library IEEE;
1694
use IEEE.STD_LOGIC_1164.ALL;
1695
use IEEE.STD_LOGIC_ARITH.ALL;
1696
use IEEE.STD_LOGIC_UNSIGNED.ALL;
1697
library unisim;
1698
use unisim.vcomponents.all;
1699
--
1700
entity program_counter is
1701
    Port (       instruction15 : in std_logic;
1702
                 instruction14 : in std_logic;
1703
                 instruction13 : in std_logic;
1704
                 instruction12 : in std_logic;
1705
                 instruction11 : in std_logic;
1706
                 instruction10 : in std_logic;
1707
                  instruction8 : in std_logic;
1708
                  instruction7 : in std_logic;
1709
                  instruction6 : in std_logic;
1710
                constant_value : in std_logic_vector(7 downto 0);
1711
                   stack_value : in std_logic_vector(7 downto 0);
1712
                       T_state : in std_logic;
1713
              active_interrupt : in std_logic;
1714
                    carry_flag : in std_logic;
1715
                     zero_flag : in std_logic;
1716
                         reset : in std_logic;
1717
            flag_condition_met : out std_logic;
1718
                 program_count : out std_logic_vector(7 downto 0);
1719
                           clk : in std_logic);
1720
    end program_counter;
1721
--
1722
architecture low_level_definition of program_counter is
1723
--
1724
-- Internal signals
1725
--
1726
signal decode_a               : std_logic;
1727
signal decode_a_carry         : std_logic;
1728
signal decode_b               : std_logic;
1729
signal move_group             : std_logic;
1730
signal condition_met_internal : std_logic;
1731
signal normal_count           : std_logic;
1732
signal increment_load_value   : std_logic;
1733
signal not_enable             : std_logic;
1734
signal selected_load_value    : std_logic_vector(7 downto 0);
1735
signal inc_load_value_carry   : std_logic_vector(6 downto 0);
1736
signal inc_load_value         : std_logic_vector(7 downto 0);
1737
signal selected_count_value   : std_logic_vector(7 downto 0);
1738
signal inc_count_value_carry  : std_logic_vector(6 downto 0);
1739
signal inc_count_value        : std_logic_vector(7 downto 0);
1740
signal count_value            : std_logic_vector(7 downto 0);
1741
--
1742
-- Attributes to define LUT contents during implementation 
1743
-- The information is repeated in the generic map for functional simulation
1744
attribute INIT : string;
1745
attribute INIT of decode_a_lut  : label is "E";
1746
attribute INIT of decode_b_lut  : label is "10";
1747
attribute INIT of condition_lut : label is "5A3C";
1748
attribute INIT of count_lut     : label is "2F";
1749
attribute INIT of increment_lut : label is "1";
1750
--
1751
begin
1752
 
1753
  --
1754
  -- decode instructions
1755
  --
1756
 
1757
  condition_lut: LUT4
1758
  --translate_off
1759
    generic map (INIT => X"5A3C")
1760
  --translate_on
1761
  port map( I0 => carry_flag,
1762
            I1 => zero_flag,
1763
            I2 => instruction10,
1764
            I3 => instruction11,
1765
             O => condition_met_internal );
1766
 
1767
  flag_condition_met <= condition_met_internal;
1768
 
1769
  decode_a_lut: LUT2
1770
  --translate_off
1771
    generic map (INIT => X"E")
1772
  --translate_on
1773
  port map( I0 => instruction7,
1774
            I1 => instruction8,
1775
             O => decode_a );
1776
 
1777
  decode_b_lut: LUT3
1778
  --translate_off
1779
    generic map (INIT => X"10")
1780
  --translate_on
1781
  port map( I0 => instruction13,
1782
            I1 => instruction14,
1783
            I2 => instruction15,
1784
             O => decode_b );
1785
 
1786
  decode_a_muxcy: MUXCY
1787
  port map( DI => '0',
1788
            CI => '1',
1789
             S => decode_a,
1790
             O => decode_a_carry );
1791
 
1792
  decode_b_cymux: MUXCY
1793
  port map( DI => '0',
1794
            CI => decode_a_carry,
1795
             S => decode_b,
1796
             O => move_group  );
1797
 
1798
  count_lut: LUT3
1799
  --translate_off
1800
    generic map (INIT => X"2F")
1801
  --translate_on
1802
  port map( I0 => instruction12,
1803
            I1 => condition_met_internal,
1804
            I2 => move_group,
1805
             O => normal_count );
1806
 
1807
  increment_lut: LUT2
1808
  --translate_off
1809
    generic map (INIT => X"1")
1810
  --translate_on
1811
  port map( I0 => instruction6,
1812
            I1 => instruction8,
1813
             O => increment_load_value );
1814
 
1815
  -- Dual loadable counter with increment on load vector
1816
 
1817
 
1818
  invert_enable: INV   -- Inverter should be implemented in the CE to flip flops
1819
  port map(  I => T_state,
1820
             O => not_enable);
1821
 
1822
  count_width_loop: for i in 0 to 7 generate
1823
  --
1824
  -- Attribute to define LUT contents during implementation 
1825
  -- The information is repeated in the generic map for functional simulation
1826
  attribute INIT : string;
1827
  attribute INIT of value_select_mux : label is "E4";
1828
  attribute INIT of count_select_mux : label is "E4";
1829
  --
1830
  begin
1831
 
1832
    value_select_mux: LUT3
1833
    --translate_off
1834
      generic map (INIT => X"E4")
1835
    --translate_on
1836
    port map( I0 => instruction8,
1837
              I1 => stack_value(i),
1838
              I2 => constant_value(i),
1839
               O => selected_load_value(i) );
1840
 
1841
    count_select_mux: LUT3
1842
    --translate_off
1843
      generic map (INIT => X"E4")
1844
    --translate_on
1845
    port map( I0 => normal_count,
1846
              I1 => inc_load_value(i),
1847
              I2 => count_value(i),
1848
               O => selected_count_value(i) );
1849
 
1850
     register_bit: FDRSE
1851
     port map ( D => inc_count_value(i),
1852
                Q => count_value(i),
1853
                R => reset,
1854
                S => active_interrupt,
1855
               CE => not_enable,
1856
                C => clk);
1857
 
1858
     lsb_carry: if i=0 generate
1859
      begin
1860
 
1861
       load_inc_carry: MUXCY
1862
       port map( DI => '0',
1863
                 CI => increment_load_value,
1864
                  S => selected_load_value(i),
1865
                  O => inc_load_value_carry(i));
1866
 
1867
       load_inc_xor: XORCY
1868
       port map( LI => selected_load_value(i),
1869
                 CI => increment_load_value,
1870
                  O => inc_load_value(i));
1871
 
1872
       count_inc_carry: MUXCY
1873
       port map( DI => '0',
1874
                 CI => normal_count,
1875
                  S => selected_count_value(i),
1876
                  O => inc_count_value_carry(i));
1877
 
1878
       count_inc_xor: XORCY
1879
       port map( LI => selected_count_value(i),
1880
                 CI => normal_count,
1881
                  O => inc_count_value(i));
1882
 
1883
     end generate lsb_carry;
1884
 
1885
     mid_carry: if i>0 and i<7 generate
1886
        begin
1887
 
1888
       load_inc_carry: MUXCY
1889
       port map( DI => '0',
1890
                 CI => inc_load_value_carry(i-1),
1891
                  S => selected_load_value(i),
1892
                  O => inc_load_value_carry(i));
1893
 
1894
       load_inc_xor: XORCY
1895
       port map( LI => selected_load_value(i),
1896
                 CI => inc_load_value_carry(i-1),
1897
                  O => inc_load_value(i));
1898
 
1899
       count_inc_carry: MUXCY
1900
       port map( DI => '0',
1901
                 CI => inc_count_value_carry(i-1),
1902
                  S => selected_count_value(i),
1903
                  O => inc_count_value_carry(i));
1904
 
1905
       count_inc_xor: XORCY
1906
       port map( LI => selected_count_value(i),
1907
                 CI => inc_count_value_carry(i-1),
1908
                  O => inc_count_value(i));
1909
 
1910
     end generate mid_carry;
1911
 
1912
     msb_carry: if i=7 generate
1913
      begin
1914
 
1915
       load_inc_xor: XORCY
1916
       port map( LI => selected_load_value(i),
1917
                 CI => inc_load_value_carry(i-1),
1918
                  O => inc_load_value(i));
1919
 
1920
       count_inc_xor: XORCY
1921
       port map( LI => selected_count_value(i),
1922
                 CI => inc_count_value_carry(i-1),
1923
                  O => inc_count_value(i));
1924
 
1925
     end generate msb_carry;
1926
 
1927
  end generate count_width_loop;
1928
 
1929
  program_count <= count_value;
1930
 
1931
--
1932
end low_level_definition;
1933
--
1934
------------------------------------------------------------------------------------
1935
--
1936
-- Library declarations
1937
--
1938
-- Standard IEEE libraries
1939
--
1940
library IEEE;
1941
use IEEE.STD_LOGIC_1164.ALL;
1942
use IEEE.STD_LOGIC_ARITH.ALL;
1943
use IEEE.STD_LOGIC_UNSIGNED.ALL;
1944
--
1945
------------------------------------------------------------------------------------
1946
--
1947
-- Main Entity for KCPSM
1948
--
1949
entity kcpsm is
1950
    Port (      address : out std_logic_vector(7 downto 0);
1951
            instruction : in std_logic_vector(15 downto 0);
1952
                port_id : out std_logic_vector(7 downto 0);
1953
           write_strobe : out std_logic;
1954
               out_port : out std_logic_vector(7 downto 0);
1955
            read_strobe : out std_logic;
1956
                in_port : in std_logic_vector(7 downto 0);
1957
              interrupt : in std_logic;
1958
                  reset : in std_logic;
1959
                    clk : in std_logic);
1960
    end kcpsm;
1961
--
1962
------------------------------------------------------------------------------------
1963
--
1964
-- Start of Main Architecture for KCPSM
1965
--       
1966
architecture macro_level_definition of kcpsm is
1967
--
1968
------------------------------------------------------------------------------------
1969
--
1970
-- Components used in KCPSM and defined in subsequent entities.
1971
--      
1972
------------------------------------------------------------------------------------
1973
 
1974
component data_bus_mux4
1975
    Port (         D3_bus : in std_logic_vector(7 downto 0);
1976
                   D2_bus : in std_logic_vector(7 downto 0);
1977
                   D1_bus : in std_logic_vector(7 downto 0);
1978
                   D0_bus : in std_logic_vector(7 downto 0);
1979
            instruction15 : in std_logic;
1980
            instruction14 : in std_logic;
1981
            instruction13 : in std_logic;
1982
            instruction12 : in std_logic;
1983
                    code2 : in std_logic;
1984
                    Y_bus : out std_logic_vector(7 downto 0);
1985
                      clk : in std_logic );
1986
    end component;
1987
 
1988
component shift_rotate_process
1989
    Port    (    operand : in std_logic_vector(7 downto 0);
1990
                carry_in : in std_logic;
1991
              inject_bit : in std_logic;
1992
             shift_right : in std_logic;
1993
                   code1 : in std_logic;
1994
                   code0 : in std_logic;
1995
                       Y : out std_logic_vector(7 downto 0);
1996
               carry_out : out std_logic;
1997
                     clk : in std_logic);
1998
    end component;
1999
 
2000
component logical_bus_processing
2001
    Port (  first_operand : in std_logic_vector(7 downto 0);
2002
           second_operand : in std_logic_vector(7 downto 0);
2003
                    code1 : in std_logic;
2004
                    code0 : in std_logic;
2005
                        Y : out std_logic_vector(7 downto 0);
2006
                      clk : in std_logic);
2007
    end component;
2008
 
2009
component arithmetic_process
2010
    Port (  first_operand : in std_logic_vector(7 downto 0);
2011
           second_operand : in std_logic_vector(7 downto 0);
2012
                 carry_in : in std_logic;
2013
                    code1 : in std_logic;
2014
                    code0 : in std_logic;
2015
                        Y : out std_logic_vector(7 downto 0);
2016
                carry_out : out std_logic;
2017
                      clk : in std_logic);
2018
    end component;
2019
 
2020
component flag_logic
2021
    Port (                data : in std_logic_vector(7 downto 0);
2022
                 instruction15 : in std_logic;
2023
                 instruction14 : in std_logic;
2024
                 instruction13 : in std_logic;
2025
                 instruction12 : in std_logic;
2026
                  instruction8 : in std_logic;
2027
                  instruction6 : in std_logic;
2028
                          code : in std_logic_vector(2 downto 0);
2029
                   shadow_zero : in std_logic;
2030
                  shadow_carry : in std_logic;
2031
            shift_rotate_carry : in std_logic;
2032
                 add_sub_carry : in std_logic;
2033
                         reset : in std_logic;
2034
                       T_state : in std_logic;
2035
                     zero_flag : out std_logic;
2036
                    carry_flag : out std_logic;
2037
                           clk : in std_logic);
2038
    end component;
2039
 
2040
component data_bus_mux2
2041
    Port (         D1_bus : in std_logic_vector(7 downto 0);
2042
                   D0_bus : in std_logic_vector(7 downto 0);
2043
            instruction15 : in std_logic;
2044
            instruction14 : in std_logic;
2045
            instruction13 : in std_logic;
2046
            instruction12 : in std_logic;
2047
                    Y_bus : out std_logic_vector(7 downto 0));
2048
    end component;
2049
 
2050
component ALU_control_mux2
2051
    Port (         D1_bus : in std_logic_vector(2 downto 0);
2052
                   D0_bus : in std_logic_vector(2 downto 0);
2053
            instruction15 : in std_logic;
2054
                    Y_bus : out std_logic_vector(2 downto 0));
2055
    end component;
2056
 
2057
component data_register_bank
2058
    Port (         address_A : in std_logic_vector(3 downto 0);
2059
                   Din_A_bus : in std_logic_vector(7 downto 0);
2060
                  Dout_A_bus : out std_logic_vector(7 downto 0);
2061
                   address_B : in std_logic_vector(3 downto 0);
2062
                  Dout_B_bus : out std_logic_vector(7 downto 0);
2063
               instruction15 : in std_logic;
2064
               instruction14 : in std_logic;
2065
               instruction13 : in std_logic;
2066
            active_interrupt : in std_logic;
2067
                     T_state : in std_logic;
2068
                         clk : in std_logic);
2069
    end component;
2070
 
2071
component T_state_and_Reset
2072
    Port (    reset_input : in std_logic;
2073
           internal_reset : out std_logic;
2074
                  T_state : out std_logic;
2075
                      clk : in std_logic);
2076
    end component;
2077
 
2078
component interrupt_logic
2079
    Port (           interrupt : in std_logic;
2080
                 instruction15 : in std_logic;
2081
                 instruction14 : in std_logic;
2082
                 instruction13 : in std_logic;
2083
                  instruction8 : in std_logic;
2084
                  instruction5 : in std_logic;
2085
                  instruction4 : in std_logic;
2086
                     zero_flag : in std_logic;
2087
                    carry_flag : in std_logic;
2088
                   shadow_zero : out std_logic;
2089
                  shadow_carry : out std_logic;
2090
              active_interrupt : out std_logic;
2091
                         reset : in std_logic;
2092
                       T_state : in std_logic;
2093
                           clk : in std_logic);
2094
    end component;
2095
 
2096
component IO_strobe_logic
2097
    Port (    instruction15 : in std_logic;
2098
              instruction14 : in std_logic;
2099
              instruction13 : in std_logic;
2100
           active_interrupt : in std_logic;
2101
                    T_state : in std_logic;
2102
                      reset : in std_logic;
2103
               write_strobe : out std_logic;
2104
                read_strobe : out std_logic;
2105
                        clk : in std_logic);
2106
    end component;
2107
 
2108
component stack_ram
2109
    Port (        Din : in std_logic_vector(7 downto 0);
2110
                 Dout : out std_logic_vector(7 downto 0);
2111
                 addr : in std_logic_vector(3 downto 0);
2112
            write_bar : in std_logic;
2113
                  clk : in std_logic);
2114
    end component;
2115
 
2116
component stack_counter
2117
    Port (        instruction15 : in std_logic;
2118
                  instruction14 : in std_logic;
2119
                  instruction13 : in std_logic;
2120
                  instruction12 : in std_logic;
2121
                   instruction9 : in std_logic;
2122
                   instruction8 : in std_logic;
2123
                   instruction7 : in std_logic;
2124
                        T_state : in std_logic;
2125
             flag_condition_met : in std_logic;
2126
               active_interrupt : in std_logic;
2127
                          reset : in std_logic;
2128
                    stack_count : out std_logic_vector(3 downto 0);
2129
                            clk : in std_logic);
2130
    end component;
2131
 
2132
component program_counter
2133
    Port (       instruction15 : in std_logic;
2134
                 instruction14 : in std_logic;
2135
                 instruction13 : in std_logic;
2136
                 instruction12 : in std_logic;
2137
                 instruction11 : in std_logic;
2138
                 instruction10 : in std_logic;
2139
                  instruction8 : in std_logic;
2140
                  instruction7 : in std_logic;
2141
                  instruction6 : in std_logic;
2142
                constant_value : in std_logic_vector(7 downto 0);
2143
                   stack_value : in std_logic_vector(7 downto 0);
2144
                       T_state : in std_logic;
2145
              active_interrupt : in std_logic;
2146
                    carry_flag : in std_logic;
2147
                     zero_flag : in std_logic;
2148
                         reset : in std_logic;
2149
            flag_condition_met : out std_logic;
2150
                 program_count : out std_logic_vector(7 downto 0);
2151
                           clk : in std_logic);
2152
    end component;
2153
 
2154
 
2155
 
2156
--
2157
------------------------------------------------------------------------------------
2158
--
2159
-- Signals used in KCPSM
2160
--
2161
------------------------------------------------------------------------------------
2162
--
2163
 
2164
--
2165
-- Fundamental control signals
2166
--      
2167
signal T_state        : std_logic;
2168
signal internal_reset : std_logic;
2169
--
2170
-- Register bank signals
2171
--      
2172
signal sX_register           : std_logic_vector(7 downto 0);
2173
signal sY_register           : std_logic_vector(7 downto 0);
2174
--
2175
-- ALU signals
2176
--
2177
signal ALU_control             : std_logic_vector(2 downto 0);
2178
signal second_operand          : std_logic_vector(7 downto 0);
2179
signal logical_result          : std_logic_vector(7 downto 0);
2180
signal shift_and_rotate_result : std_logic_vector(7 downto 0);
2181
signal shift_and_rotate_carry  : std_logic;
2182
signal arithmetic_result       : std_logic_vector(7 downto 0);
2183
signal arithmetic_carry        : std_logic;
2184
signal ALU_result              : std_logic_vector(7 downto 0);
2185
--
2186
-- Flag signals
2187
-- 
2188
signal carry_flag         : std_logic;
2189
signal zero_flag          : std_logic;
2190
--
2191
-- Interrupt signals
2192
-- 
2193
signal shadow_carry_flag  : std_logic;
2194
signal shadow_zero_flag   : std_logic;
2195
signal active_interrupt   : std_logic;
2196
--
2197
-- Program Counter and Stack signals
2198
--
2199
signal program_count      : std_logic_vector(7 downto 0);
2200
signal stack_pop_data     : std_logic_vector(7 downto 0);
2201
signal stack_pointer      : std_logic_vector(3 downto 0);
2202
signal flag_condition_met : std_logic;
2203
--
2204
------------------------------------------------------------------------------------
2205
--
2206
-- Start of KCPSM circuit description
2207
--
2208
------------------------------------------------------------------------------------
2209
--      
2210
begin
2211
 
2212
  --
2213
  -- Connections to port_id, out_port, and address ports.
2214
  --
2215
 
2216
  out_port <= sX_register;
2217
  port_id <= second_operand;
2218
  address <= program_count;
2219
 
2220
  --
2221
  -- Reset conditioning and T-state generation
2222
  --    
2223
 
2224
  basic_control: T_state_and_Reset
2225
  port map (    reset_input => reset,
2226
             internal_reset => internal_reset,
2227
                    T_state => T_state,
2228
                        clk => clk  );
2229
 
2230
  --
2231
  -- Interrupt logic and shadow flags
2232
  --    
2233
 
2234
  interrupt_group: interrupt_logic
2235
  port map (           interrupt => interrupt,
2236
                   instruction15 => instruction(15),
2237
                   instruction14 => instruction(14),
2238
                   instruction13 => instruction(13),
2239
                    instruction8 => instruction(8),
2240
                    instruction5 => instruction(5),
2241
                    instruction4 => instruction(4),
2242
                       zero_flag => zero_flag,
2243
                      carry_flag => carry_flag,
2244
                     shadow_zero => shadow_zero_flag,
2245
                    shadow_carry => shadow_carry_flag,
2246
                active_interrupt => active_interrupt,
2247
                           reset => internal_reset,
2248
                         T_state => T_state,
2249
                             clk => clk  );
2250
 
2251
  --
2252
  -- I/O strobes
2253
  --    
2254
 
2255
  strobes: IO_strobe_logic
2256
  port map (    instruction15 => instruction(15),
2257
                instruction14 => instruction(14),
2258
                instruction13 => instruction(13),
2259
             active_interrupt => active_interrupt,
2260
                      T_state => T_state,
2261
                        reset => internal_reset,
2262
                 write_strobe => write_strobe,
2263
                  read_strobe => read_strobe,
2264
                          clk => clk  );
2265
 
2266
  --
2267
  -- Data registers and ALU
2268
  --    
2269
 
2270
  registers: data_register_bank
2271
  port map (         address_A => instruction(11 downto 8),
2272
                     Din_A_bus => ALU_result,
2273
                    Dout_A_bus => sX_register,
2274
                     address_B => instruction(7 downto 4),
2275
                    Dout_B_bus => sY_register,
2276
                 instruction15 => instruction(15),
2277
                 instruction14 => instruction(14),
2278
                 instruction13 => instruction(13),
2279
              active_interrupt => active_interrupt,
2280
                       T_state => T_state,
2281
                           clk => clk  );
2282
 
2283
  operand_select: data_bus_mux2
2284
  port map (         D1_bus => sY_register,
2285
                     D0_bus => instruction(7 downto 0),
2286
              instruction15 => instruction(15),
2287
              instruction14 => instruction(14),
2288
              instruction13 => instruction(13),
2289
              instruction12 => instruction(12),
2290
                      Y_bus => second_operand );
2291
 
2292
  ALU_control_select: ALU_control_mux2
2293
  port map (         D1_bus => instruction(2 downto 0),
2294
                     D0_bus => instruction(14 downto 12),
2295
              instruction15 => instruction(15),
2296
                      Y_bus => ALU_control );
2297
 
2298
  logic_group: logical_bus_processing
2299
  port map (  first_operand => sX_register,
2300
             second_operand => second_operand,
2301
                      code1 => ALU_control(1),
2302
                      code0 => ALU_control(0),
2303
                          Y => logical_result,
2304
                        clk => clk );
2305
 
2306
  arthimetic_group: arithmetic_process
2307
  port map (  first_operand => sX_register,
2308
             second_operand => second_operand,
2309
                   carry_in => carry_flag,
2310
                      code1 => ALU_control(1),
2311
                      code0 => ALU_control(0),
2312
                          Y => arithmetic_result,
2313
                  carry_out => arithmetic_carry,
2314
                        clk => clk );
2315
 
2316
  shift_group: shift_rotate_process
2317
  port map    (    operand => sX_register,
2318
                  carry_in => carry_flag,
2319
                inject_bit => instruction(0),
2320
               shift_right => instruction(3),
2321
                     code1 => instruction(2),
2322
                     code0 => instruction(1),
2323
                         Y => shift_and_rotate_result,
2324
                 carry_out => shift_and_rotate_carry,
2325
                       clk => clk );
2326
 
2327
  ALU_final_mux: data_bus_mux4
2328
  port map (         D3_bus => shift_and_rotate_result,
2329
                     D2_bus => in_port,
2330
                     D1_bus => arithmetic_result,
2331
                     D0_bus => logical_result,
2332
              instruction15 => instruction(15),
2333
              instruction14 => instruction(14),
2334
              instruction13 => instruction(13),
2335
              instruction12 => instruction(12),
2336
                      code2 => ALU_control(2),
2337
                      Y_bus => ALU_result,
2338
                        clk => clk );
2339
 
2340
  flags: flag_logic
2341
  port map (                data => ALU_result,
2342
                   instruction15 => instruction(15),
2343
                   instruction14 => instruction(14),
2344
                   instruction13 => instruction(13),
2345
                   instruction12 => instruction(12),
2346
                    instruction8 => instruction(8),
2347
                    instruction6 => instruction(6),
2348
                            code => ALU_control,
2349
                     shadow_zero => shadow_zero_flag,
2350
                    shadow_carry => shadow_carry_flag,
2351
              shift_rotate_carry => shift_and_rotate_carry,
2352
                   add_sub_carry => arithmetic_carry,
2353
                           reset => internal_reset,
2354
                         T_state => T_state,
2355
                       zero_flag => zero_flag,
2356
                      carry_flag => carry_flag,
2357
                             clk => clk );
2358
 
2359
  --
2360
  -- Program stack
2361
  --     
2362
 
2363
  stack_memory: stack_ram
2364
  port map (       Din => program_count,
2365
                  Dout => stack_pop_data,
2366
                  addr => stack_pointer,
2367
             write_bar => T_state,
2368
                   clk => clk );
2369
 
2370
 
2371
  stack_control: stack_counter
2372
  port map (        instruction15 => instruction(15),
2373
                    instruction14 => instruction(14),
2374
                    instruction13 => instruction(13),
2375
                    instruction12 => instruction(12),
2376
                     instruction9 => instruction(9),
2377
                     instruction8 => instruction(8),
2378
                     instruction7 => instruction(7),
2379
                          T_state => T_state,
2380
               flag_condition_met => flag_condition_met,
2381
                 active_interrupt => active_interrupt,
2382
                            reset => internal_reset,
2383
                      stack_count => stack_pointer,
2384
                              clk => clk );
2385
 
2386
  --
2387
  -- Program Counter
2388
  --    
2389
 
2390
  address_counter: program_counter
2391
  port map (       instruction15 => instruction(15),
2392
                   instruction14 => instruction(14),
2393
                   instruction13 => instruction(13),
2394
                   instruction12 => instruction(12),
2395
                   instruction11 => instruction(11),
2396
                   instruction10 => instruction(10),
2397
                    instruction8 => instruction(8),
2398
                    instruction7 => instruction(7),
2399
                    instruction6 => instruction(6),
2400
                  constant_value => instruction(7 downto 0),
2401
                     stack_value => stack_pop_data,
2402
                         T_state => T_state,
2403
                active_interrupt => active_interrupt,
2404
                      carry_flag => carry_flag,
2405
                       zero_flag => zero_flag,
2406
                           reset => internal_reset,
2407
              flag_condition_met => flag_condition_met,
2408
                   program_count => program_count,
2409
                             clk => clk );
2410
 
2411
--
2412
end macro_level_definition;
2413
--
2414
------------------------------------------------------------------------------------
2415
--
2416
-- End of top level description for KCPSM.
2417
--
2418
------------------------------------------------------------------------------------
2419
--
2420
-- END OF FILE KCPSM.VHD
2421
--
2422
------------------------------------------------------------------------------------
2423
 
2424
 
2425
 
2426
 
2427
 
2428
 
2429
 
2430
 
2431
 
2432
 
2433
 
2434
 
2435
 
2436
 
2437
 
2438
 
2439
 
2440
 
2441
 
2442
 
2443
 
2444
 
2445
 
2446
 
2447
 
2448
 
2449
 
2450
 
2451
 
2452
 
2453
 
2454
 
2455
 
2456
 
2457
 
2458
 
2459
 

powered by: WebSVN 2.1.0

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