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

Subversion Repositories avr_hp

[/] [avr_hp/] [trunk/] [rtl/] [rtl_v5_cm3/] [pm_fetch_dec.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 tobil
--************************************************************************************************
2
--  PM_FETCH_DEC(internal module) for AVR core
3
--      Version 2.6! (Special version for the JTAG OCD)
4
--  Designed by Ruslan Lepetenok 14.11.2001
5
--  Modified 31.05.06
6
--  Modification:
7
--  Registered ramre/ramwe outputs
8
--  cpu_busy logic modified(affects RCALL/ICALL/CALL instruction interract with interrupt)
9
--  SLEEP and CLRWDT instructions support was added
10
--  V-flag bug fixed (AND/ANDI/OR/ORI/EOR)
11
--  V-flag bug fixed (ADIW/SBIW)
12
--  Unused outputs(sreg_bit_num[2..0],idc_sbi_out,idc_cbi_out,idc_bld_out) were removed.
13
--  Output alu_data_d_in[7..0] was removed.
14
--  Gloabal clock enable(cp2en) was added  
15
--  cpu_busy(push/pop) + irq bug was fixed 14.07.05
16
--  BRXX+IRQ interaction was modified -> cpu_busy
17
--  LDS/STS now requires only two cycles for execution (13.01.06 -> last modificatioon)
18
--************************************************************************************************
19
 
20
library IEEE;
21
use IEEE.std_logic_1164.all;
22
use IEEE.std_logic_unsigned.all;
23
 
24
use WORK.AVRuCPackage.all;
25
 
26
entity pm_fetch_dec_cm3 is port(
27
                cp2_cml_1 : in std_logic;
28
                cp2_cml_2 : in std_logic;
29
 
30
                              -- Clock and reset
31
                              cp2              : in  std_logic;
32
                                                          cp2en            : in  std_logic;
33
                              ireset           : in  std_logic;
34
                                                          -- JTAG OCD support
35
                                                          valid_instr      : out  std_logic;
36
                                                      insert_nop       : in   std_logic;
37
                                                      block_irq        : in   std_logic;
38
                                                      change_flow      : out  std_logic;
39
                                                          -- Program memory
40
                              pc               : out std_logic_vector (15 downto 0);
41
                              inst             : in  std_logic_vector (15 downto 0);
42
                              -- I/O control
43
                              adr              : out std_logic_vector (5 downto 0);
44
                              iore             : out std_logic;
45
                              iowe             : out std_logic;
46
                              -- Data memory control
47
                              ramadr           : out std_logic_vector (15 downto 0);
48
                              ramre            : out std_logic;
49
                              ramwe            : out std_logic;
50
                              cpuwait          : in  std_logic;
51
                                                          -- Data paths
52
                              dbusin           : in  std_logic_vector (7 downto 0);
53
                              dbusout          : out std_logic_vector (7 downto 0);
54
                              dbusout_int_route : out std_logic_vector (7 downto 0);
55
                              -- Interrupt
56
                              irqlines         : in  std_logic_vector (22 downto 0);
57
                              irqack           : out std_logic;
58
                              irqackad         : out std_logic_vector(4 downto 0);
59
                                                      --Sleep 
60
                              sleepi           : out std_logic;
61
                              irqok                : out std_logic;
62
                              --Watchdog
63
                              wdri                 : out std_logic;
64
                                                          -- ALU interface(Data inputs)
65
                              alu_data_r_in    : out std_logic_vector(7 downto 0);
66
                                                          -- ALU interface(Instruction inputs)
67
                                                          idc_add_out      : out std_logic;
68
                              idc_adc_out      : out std_logic;
69
                              idc_adiw_out     : out std_logic;
70
                              idc_sub_out      : out std_logic;
71
                              idc_subi_out     : out std_logic;
72
                              idc_sbc_out      : out std_logic;
73
                              idc_sbci_out     : out std_logic;
74
                              idc_sbiw_out     : out std_logic;
75
 
76
                              adiw_st_out      : out std_logic;
77
                              sbiw_st_out      : out std_logic;
78
 
79
                              idc_and_out      : out std_logic;
80
                              idc_andi_out     : out std_logic;
81
                              idc_or_out       : out std_logic;
82
                              idc_ori_out      : out std_logic;
83
                              idc_eor_out      : out std_logic;
84
                              idc_com_out      : out std_logic;
85
                              idc_neg_out      : out std_logic;
86
 
87
                              idc_inc_out      : out std_logic;
88
                              idc_dec_out      : out std_logic;
89
 
90
                              idc_cp_out       : out std_logic;
91
                              idc_cpc_out      : out std_logic;
92
                              idc_cpi_out      : out std_logic;
93
                              idc_cpse_out     : out std_logic;
94
 
95
                              idc_lsr_out      : out std_logic;
96
                              idc_ror_out      : out std_logic;
97
                              idc_asr_out      : out std_logic;
98
                              idc_swap_out     : out std_logic;
99
 
100
                               -- ALU interface(Data output)
101
                               alu_data_out    : in std_logic_vector(7 downto 0);
102
 
103
                               -- ALU interface(Flag outputs)
104
                               alu_c_flag_out  : in std_logic;
105
                               alu_z_flag_out  : in std_logic;
106
                               alu_n_flag_out  : in std_logic;
107
                               alu_v_flag_out  : in std_logic;
108
                               alu_s_flag_out  : in std_logic;
109
                               alu_h_flag_out  : in std_logic;
110
 
111
                                                           -- General purpose register file interface
112
                               reg_rd_in       : out std_logic_vector  (7 downto 0);
113
                               reg_rd_out      : in  std_logic_vector  (7 downto 0);
114
                               reg_rd_out_int  : in std_logic_vector(7 downto 0);
115
                               reg_rd_adr      : out std_logic_vector  (4 downto 0);
116
                               reg_rd_adr_int      : out std_logic_vector  (4 downto 0);
117
                               reg_rr_out      : in  std_logic_vector  (7 downto 0);
118
                               reg_rr_adr      : out std_logic_vector  (4 downto 0);
119
                               reg_rd_wr       : out std_logic;
120
 
121
                               post_inc        : out std_logic;                       -- POST INCREMENT FOR LD/ST INSTRUCTIONS
122
                               pre_dec         : out std_logic;                        -- PRE DECREMENT FOR LD/ST INSTRUCTIONS
123
                               reg_h_wr        : out std_logic;
124
                               reg_h_out       : in  std_logic_vector (15 downto 0);
125
                               reg_h_adr       : out std_logic_vector (2 downto 0);    -- x,y,z
126
                                       reg_z_out       : in  std_logic_vector (15 downto 0);  -- OUTPUT OF R31:R30 FOR LPM/ELPM/IJMP INSTRUCTIONS
127
 
128
                               -- I/O register file interface
129
                               sreg_fl_in      : out std_logic_vector(7 downto 0);
130
                               globint         : in  std_logic; -- SREG I flag
131
 
132
                               sreg_fl_wr_en   : out std_logic_vector(7 downto 0);   --FLAGS WRITE ENABLE SIGNALS       
133
 
134
                               spl_out         : in  std_logic_vector(7 downto 0);
135
                               sph_out         : in  std_logic_vector(7 downto 0);
136
                               sp_ndown_up     : out std_logic; -- DIRECTION OF CHANGING OF STACK POINTER SPH:SPL 0->UP(+) 1->DOWN(-)
137
                               sp_en           : out std_logic; -- WRITE ENABLE(COUNT ENABLE) FOR SPH AND SPL REGISTERS
138
 
139
                               rampz_out       : in  std_logic_vector(7 downto 0);
140
 
141
                                                           -- Bit processor interface
142
                               bit_num_r_io    : out std_logic_vector (2 downto 0); -- BIT NUMBER FOR CBI/SBI/BLD/BST/SBRS/SBRC/SBIC/SBIS INSTRUCTIONS
143
                               bitpr_io_out    : in  std_logic_vector(7 downto 0);  -- SBI/CBI OUT        
144
                               branch          : out std_logic_vector (2 downto 0); -- NUMBER (0..7) OF BRANCH CONDITION FOR BRBS/BRBC INSTRUCTION
145
                               bit_pr_sreg_out : in  std_logic_vector(7 downto 0);  -- BCLR/BSET/BST(T-FLAG ONLY)             
146
                               bld_op_out      : in  std_logic_vector(7 downto 0);  -- BLD OUT (T FLAG)
147
                               bit_test_op_out : in  std_logic;                     -- OUTPUT OF SBIC/SBIS/SBRS/SBRC
148
 
149
                               sbi_st_out      : out std_logic;
150
                               cbi_st_out      : out std_logic;
151
 
152
                               idc_bst_out     : out std_logic;
153
                               idc_bset_out    : out std_logic;
154
                               idc_bclr_out    : out std_logic;
155
 
156
                               idc_sbic_out    : out std_logic;
157
                               idc_sbis_out    : out std_logic;
158
 
159
                               idc_sbrs_out    : out std_logic;
160
                               idc_sbrc_out    : out std_logic;
161
 
162
                               idc_brbs_out    : out std_logic;
163
                               idc_brbc_out    : out std_logic;
164
 
165
                               idc_reti_out    : out std_logic);
166
end pm_fetch_dec_cm3;
167
 
168
architecture RTL of pm_fetch_dec_cm3 is
169
 
170
-- COPIES OF OUTPUTS
171
signal ramadr_reg_in  : std_logic_vector(15 downto 0); -- INPUT OF THE ADDRESS REGISTER
172
signal ramadr_reg_en  : std_logic;                     -- ADRESS REGISTER CLOCK ENABLE SIGNAL
173
 
174
signal irqack_int     : std_logic;
175
signal irqackad_int   : std_logic_vector(irqackad'range);
176
 
177
-- ####################################################
178
-- INTERNAL SIGNALS
179
-- ####################################################
180
 
181
-- NEW SIGNALS
182
signal   two_word_inst       : std_logic;                    -- CALL/JMP/STS/LDS INSTRUCTION INDICATOR
183
 
184
signal   ram_adr_int         : std_logic_vector (15 downto 0);
185
constant const_ram_to_reg    : std_logic_vector := "00000000000";  -- LD/LDS/LDD/ST/STS/STD ADDRESSING GENERAL PURPOSE REGISTER (R0-R31) 0x00..0x19
186
constant const_ram_to_io_a   : std_logic_vector := "00000000001";  -- LD/LDS/LDD/ST/STS/STD ADDRESSING GENERAL I/O PORT 0x20 0x3F 
187
constant const_ram_to_io_b   : std_logic_vector := "00000000010";  -- LD/LDS/LDD/ST/STS/STD ADDRESSING GENERAL I/O PORT 0x20 0x3F 
188
 
189
-- LD/LDD/ST/STD SIGNALS
190
signal adiw_sbiw_encoder_out : std_logic_vector (4 downto 0);
191
signal adiw_sbiw_encoder_mux_out : std_logic_vector (4 downto 0);
192
 
193
 
194
-- PROGRAM COUNTER SIGNALS
195
signal program_counter_tmp : std_logic_vector (15 downto 0); -- TO STORE PC DURING LPM/ELPM INSTRUCTIONS
196
signal program_counter     : std_logic_vector (15 downto 0);
197
signal program_counter_in  : std_logic_vector (15 downto 0);
198
signal program_counter_high_fr  : std_logic_vector (7 downto 0); -- TO STORE PC FOR CALL,IRQ,RCALL,ICALL
199
 
200
signal pc_low       : std_logic_vector (7 downto 0);
201
signal pc_high      : std_logic_vector (7 downto 0);
202
 
203
 
204
signal pc_low_en       : std_logic;
205
signal pc_high_en      : std_logic;
206
 
207
signal offset_brbx     : std_logic_vector (15 downto 0);    -- OFFSET FOR BRCS/BRCC   INSTRUCTION  !!CHECKED
208
signal offset_rxx      : std_logic_vector (15 downto 0);    -- OFFSET FOR RJMP/RCALL  INSTRUCTION  !!CHECKED
209
 
210
signal pa15_pm         : std_logic; -- ADDRESS LINE 15 FOR LPM/ELPM INSTRUCTIONS ('0' FOR LPM,RAMPZ(0) FOR ELPM) 
211
 
212
signal alu_reg_wr      : std_logic; -- ALU INSTRUCTIONS PRODUCING WRITE TO THE GENERAL PURPOSE REGISTER FILE    
213
 
214
-- DATA MEMORY,GENERAL PURPOSE REGISTERS AND I/O REGISTERS LOGIC
215
 
216
--! IMPORTANT NOTICE : OPERATIONS WHICH USE STACK POINTER (SPH:SPL) CAN NOT ACCCSESS GENERAL
217
-- PURPOSE REGISTER FILE AND INPUT/OUTPUT REGISTER FILE !
218
-- THESE OPERATIONS ARE : RCALL/ICALL/CALL/RET/RETI/PUSH/POP INSTRUCTIONS  AND INTERRUPT 
219
 
220
signal reg_file_adr_space  : std_logic; -- ACCSESS TO THE REGISTER FILE
221
signal io_file_adr_space   : std_logic; -- ACCSESS TO THE I/O FILE
222
 
223
-- STATE MACHINES SIGNALS
224
signal irq_start      : std_logic;
225
 
226
signal nirq_st0       : std_logic;
227
signal irq_st1        : std_logic;
228
signal irq_st2        : std_logic;
229
signal irq_st3        : std_logic;
230
 
231
signal ncall_st0      : std_logic;
232
signal call_st1       : std_logic;
233
signal call_st2       : std_logic;
234
signal call_st3       : std_logic;
235
 
236
signal nrcall_st0     : std_logic;
237
signal rcall_st1      : std_logic;
238
signal rcall_st2      : std_logic;
239
 
240
signal nicall_st0     : std_logic;
241
signal icall_st1      : std_logic;
242
signal icall_st2      : std_logic;
243
 
244
signal njmp_st0       : std_logic;
245
signal jmp_st1        : std_logic;
246
signal jmp_st2        : std_logic;
247
 
248
signal ijmp_st        : std_logic;
249
 
250
signal rjmp_st        : std_logic;
251
 
252
signal nret_st0       : std_logic;
253
signal ret_st1        : std_logic;
254
signal ret_st2        : std_logic;
255
signal ret_st3        : std_logic;
256
 
257
signal nreti_st0      : std_logic;
258
signal reti_st1       : std_logic;
259
signal reti_st2       : std_logic;
260
signal reti_st3       : std_logic;
261
 
262
signal brxx_st        : std_logic;  -- BRANCHES
263
 
264
signal adiw_st        : std_logic;
265
signal sbiw_st        : std_logic;
266
 
267
signal nskip_inst_st0 : std_logic;
268
signal skip_inst_st1  : std_logic;
269
signal skip_inst_st2  : std_logic;  -- ALL SKIP INSTRUCTIONS SBRS/SBRC/SBIS/SBIC/CPSE 
270
 
271
signal skip_inst_start  : std_logic;
272
 
273
signal nlpm_st0       : std_logic;
274
signal lpm_st1        : std_logic;
275
signal lpm_st2        : std_logic;
276
 
277
signal nelpm_st0      : std_logic;
278
signal elpm_st1       : std_logic;
279
signal elpm_st2       : std_logic;
280
 
281
--signal nsts_st0       : std_logic;
282
--signal sts_st1        : std_logic;
283
--signal sts_st2        : std_logic;
284
 
285
signal sts_st         : std_logic;
286
 
287
--signal nlds_st0       : std_logic;
288
--signal lds_st1        : std_logic;
289
--signal lds_st2        : std_logic;
290
 
291
signal lds_st           : std_logic;
292
 
293
signal st_st          : std_logic;
294
signal ld_st          : std_logic;
295
 
296
signal sbi_st         : std_logic;
297
signal cbi_st         : std_logic;
298
 
299
signal push_st        : std_logic;
300
signal pop_st         : std_logic;
301
 
302
-- INTERNAL STATE MACHINES
303
signal nop_insert_st  : std_logic;
304
signal cpu_busy       : std_logic;
305
 
306
-- INTERNAL COPIES OF OUTPUTS
307
signal pc_int              : std_logic_vector (15 downto 0);
308
signal adr_int             : std_logic_vector (5 downto 0);
309
signal iore_int                    : std_logic;
310
signal iowe_int            : std_logic;
311
signal ramadr_int          : std_logic_vector (15 downto 0);
312
signal ramre_int           : std_logic;
313
signal ramwe_int           : std_logic;
314
signal dbusout_int         : std_logic_vector (7 downto 0);
315
 
316
-- COMMAND REGISTER
317
signal instruction_reg      : std_logic_vector (15 downto 0); -- OUTPUT OF THE INSTRUCTION REGISTER
318
signal instruction_code_reg : std_logic_vector (15 downto 0); -- OUTPUT OF THE INSTRUCTION REGISTER WITH NOP INSERTION
319
signal instruction_reg_ena  : std_logic;                               -- CLOCK ENABLE
320
 
321
 
322
-- IRQ INTERNAL LOGIC
323
signal irq_int              : std_logic;
324
signal irq_vector_adr       : std_logic_vector(15 downto 0);
325
 
326
-- INTERRUPT RELATING REGISTERS
327
signal pc_for_interrupt : std_logic_vector(15 downto 0);
328
 
329
-- DATA EXTRACTOR SIGNALS
330
signal dex_dat8_immed  : std_logic_vector (7 downto 0);  -- IMMEDIATE CONSTANT (DATA) -> ANDI,ORI,SUBI,SBCI,CPI,LDI
331
signal dex_dat6_immed  : std_logic_vector (5 downto 0);  -- IMMEDIATE CONSTANT (DATA) -> ADIW,SBIW
332
signal dex_adr12mem_s  : std_logic_vector (11 downto 0); -- RELATIVE ADDRESS (SIGNED) -> RCALL,RJMP
333
signal dex_adr6port    : std_logic_vector (5 downto 0);  -- I/O PORT ADDRESS -> IN,OUT
334
signal dex_adr5port    : std_logic_vector (4 downto 0);  -- I/O PORT ADDRESS -> CBI,SBI,SBIC,SBIS
335
signal dex_adr_disp    : std_logic_vector (5 downto 0);  -- DISPLACEMENT FO ADDDRESS -> STD,LDD
336
signal dex_condition   : std_logic_vector (2 downto 0);  -- CONDITION -> BRBC,BRBS
337
signal dex_bitnum_sreg : std_logic_vector (2 downto 0);  -- NUMBER OF BIT IN SREG -> BCLR,BSET
338
signal dex_adrreg_r    : std_logic_vector (4 downto 0);  -- SOURCE REGISTER ADDRESS -> .......
339
signal dex_adrreg_d    : std_logic_vector (4 downto 0);  -- DESTINATION REGISTER ADDRESS -> ......
340
signal dex_bitop_bitnum : std_logic_vector(2 downto 0);  -- NUMBER OF BIT FOR BIT ORIENTEDE OPERATION -> BST/BLD+SBI/CBI+SBIC/SBIS+SBRC/SBRS !! CHECKED
341
signal dex_brxx_offset : std_logic_vector (6 downto 0);  -- RELATIVE ADDRESS (SIGNED) -> BRBC,BRBS !! CHECKED
342
signal dex_adiw_sbiw_reg_adr  : std_logic_vector (1 downto 0);  -- ADDRESS OF THE LOW REGISTER FOR ADIW/SBIW INSTRUCTIONS
343
 
344
signal dex_adrreg_d_latched : std_logic_vector (4 downto 0);   --  STORE ADDRESS OF DESTINATION REGISTER FOR LDS/STS/POP INSTRUCTIONS
345
signal gp_reg_tmp           : std_logic_vector (7 downto 0);   --  STORE DATA FROM THE REGISTERS FOR STS,ST INSTRUCTIONS
346
signal cbi_sbi_io_adr_tmp   : std_logic_vector (4 downto 0);   --  STORE ADDRESS OF I/O PORT FOR CBI/SBI INSTRUCTION
347
signal cbi_sbi_bit_num_tmp  : std_logic_vector (2 downto 0);   --  STORE ADDRESS OF I/O PORT FOR CBI/SBI INSTRUCTION
348
 
349
-- INSTRUCTIONS DECODER SIGNALS
350
 
351
signal idc_adc     : std_logic; -- INSTRUCTION ADC
352
signal idc_add     : std_logic; -- INSTRUCTION ADD
353
signal idc_adiw    : std_logic; -- INSTRUCTION ADIW
354
signal idc_and     : std_logic; -- INSTRUCTION AND
355
signal idc_andi    : std_logic; -- INSTRUCTION ANDI
356
signal idc_asr     : std_logic; -- INSTRUCTION ASR
357
 
358
signal idc_bclr    : std_logic; -- INSTRUCTION BCLR
359
signal idc_bld     : std_logic; -- INSTRUCTION BLD
360
signal idc_brbc    : std_logic; -- INSTRUCTION BRBC
361
signal idc_brbs    : std_logic; -- INSTRUCTION BRBS
362
signal idc_bset    : std_logic; -- INSTRUCTION BSET
363
signal idc_bst     : std_logic; -- INSTRUCTION BST
364
 
365
signal idc_call    : std_logic; -- INSTRUCTION CALL
366
signal idc_cbi     : std_logic; -- INSTRUCTION CBI
367
signal idc_com     : std_logic; -- INSTRUCTION COM
368
signal idc_cp      : std_logic; -- INSTRUCTION CP
369
signal idc_cpc     : std_logic; -- INSTRUCTION CPC
370
signal idc_cpi     : std_logic; -- INSTRUCTION CPI
371
signal idc_cpse    : std_logic; -- INSTRUCTION CPSE
372
 
373
signal idc_dec     : std_logic; -- INSTRUCTION DEC
374
 
375
signal idc_elpm    : std_logic; -- INSTRUCTION ELPM
376
signal idc_eor     : std_logic; -- INSTRUCTION EOR
377
 
378
signal idc_icall   : std_logic; -- INSTRUCTION ICALL
379
signal idc_ijmp    : std_logic; -- INSTRUCTION IJMP
380
 
381
signal idc_in      : std_logic; -- INSTRUCTION IN
382
signal idc_inc     : std_logic; -- INSTRUCTION INC
383
 
384
signal idc_jmp     : std_logic; -- INSTRUCTION JMP
385
 
386
signal idc_ld_x    : std_logic; -- INSTRUCTION LD Rx,X ; LD Rx,X+ ;LD Rx,-X
387
signal idc_ld_y    : std_logic; -- INSTRUCTION LD Rx,Y ; LD Rx,Y+ ;LD Rx,-Y
388
signal idc_ldd_y   : std_logic; -- INSTRUCTION LDD Rx,Y+q
389
signal idc_ld_z    : std_logic; -- INSTRUCTION LD Rx,Z ; LD Rx,Z+ ;LD Rx,-Z
390
signal idc_ldd_z   : std_logic; -- INSTRUCTION LDD Rx,Z+q
391
 
392
signal idc_ldi     : std_logic; -- INSTRUCTION LDI
393
signal idc_lds     : std_logic; -- INSTRUCTION LDS
394
signal idc_lpm     : std_logic; -- INSTRUCTION LPM
395
signal idc_lsr     : std_logic; -- INSTRUCTION LSR
396
 
397
signal idc_mov     : std_logic; -- INSTRUCTION MOV
398
signal idc_mul     : std_logic; -- INSTRUCTION MUL
399
 
400
signal idc_neg     : std_logic; -- INSTRUCTION NEG
401
signal idc_nop     : std_logic; -- INSTRUCTION NOP
402
 
403
signal idc_or      : std_logic; -- INSTRUCTION OR
404
signal idc_ori     : std_logic; -- INSTRUCTION ORI
405
signal idc_out     : std_logic; -- INSTRUCTION OUT
406
 
407
signal idc_pop     : std_logic; -- INSTRUCTION POP
408
signal idc_push    : std_logic; -- INSTRUCTION PUSH
409
 
410
signal idc_rcall   : std_logic; -- INSTRUCTION RCALL
411
signal idc_ret     : std_logic; -- INSTRUCTION RET
412
signal idc_reti    : std_logic; -- INSTRUCTION RETI
413
signal idc_rjmp    : std_logic; -- INSTRUCTION RJMP
414
signal idc_ror     : std_logic; -- INSTRUCTION ROR
415
 
416
signal idc_sbc     : std_logic; -- INSTRUCTION SBC
417
signal idc_sbci    : std_logic; -- INSTRUCTION SBCI
418
signal idc_sbi     : std_logic; -- INSTRUCTION SBI
419
signal idc_sbic    : std_logic; -- INSTRUCTION SBIC
420
signal idc_sbis    : std_logic; -- INSTRUCTION SBIS
421
signal idc_sbiw    : std_logic; -- INSTRUCTION SBIW
422
signal idc_sbrc    : std_logic; -- INSTRUCTION SBRC
423
signal idc_sbrs    : std_logic; -- INSTRUCTION SBRS
424
signal idc_sleep   : std_logic; -- INSTRUCTION SLEEP
425
 
426
signal idc_st_x    : std_logic; -- INSTRUCTION LD X,Rx ; LD X+,Rx ;LD -X,Rx
427
signal idc_st_y    : std_logic; -- INSTRUCTION LD Y,Rx ; LD Y+,Rx ;LD -Y,Rx
428
signal idc_std_y   : std_logic; -- INSTRUCTION LDD Y+q,Rx
429
signal idc_st_z    : std_logic; -- INSTRUCTION LD Z,Rx ; LD Z+,Rx ;LD -Z,Rx
430
signal idc_std_z   : std_logic; -- INSTRUCTION LDD Z+q,Rx
431
 
432
signal idc_sts     : std_logic; -- INSTRUCTION STS
433
signal idc_sub     : std_logic; -- INSTRUCTION SUB
434
signal idc_subi    : std_logic; -- INSTRUCTION SUBI
435
signal idc_swap    : std_logic; -- INSTRUCTION SWAP
436
 
437
signal idc_wdr     : std_logic; -- INSTRUCTION WDR
438
 
439
-- ADDITIONAL SIGNALS
440
signal idc_psinc   :  std_logic; -- POST INCREMENT FLAG FOR LD,ST INSTRUCTIONS
441
signal idc_prdec   :  std_logic; -- PRE DECREMENT  FLAG FOR LD,ST INSTRUCTIONS
442
 
443
-- ##################################################
444
 
445
-- SREG FLAGS WRITE ENABLE SIGNALS
446
 
447
--alias sreg_c_wr_en  : std_logic is sreg_fl_wr_en(0);
448
--alias sreg_z_wr_en  : std_logic is sreg_fl_wr_en(1);
449
--alias sreg_n_wr_en  : std_logic is sreg_fl_wr_en(2);
450
--alias sreg_v_wr_en  : std_logic is sreg_fl_wr_en(3);
451
--alias sreg_s_wr_en  : std_logic is sreg_fl_wr_en(4);
452
--alias sreg_h_wr_en  : std_logic is sreg_fl_wr_en(5);
453
--alias sreg_t_wr_en  : std_logic is sreg_fl_wr_en(6);
454
--alias sreg_i_wr_en  : std_logic is sreg_fl_wr_en(7);
455
 
456
signal sreg_c_wr_en  : std_logic; --  is sreg_fl_wr_en(0);
457
signal sreg_z_wr_en  : std_logic; --  is sreg_fl_wr_en(1);
458
signal sreg_n_wr_en  : std_logic; --  is sreg_fl_wr_en(2);
459
signal sreg_v_wr_en  : std_logic; --  is sreg_fl_wr_en(3);
460
signal sreg_s_wr_en  : std_logic; --  is sreg_fl_wr_en(4);
461
signal sreg_h_wr_en  : std_logic; --  is sreg_fl_wr_en(5);
462
signal sreg_t_wr_en  : std_logic; --  is sreg_fl_wr_en(6);
463
signal sreg_i_wr_en  : std_logic; --  is sreg_fl_wr_en(7);
464
 
465
signal sreg_bop_wr_en : std_logic_vector (7 downto 0);
466
 
467
signal sreg_adr_eq  : std_logic;
468
-- &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
469
 
470
signal inst_cml_2 :  std_logic_vector ( 15 downto 0 );
471
signal inst_cml_1 :  std_logic_vector ( 15 downto 0 );
472
signal sp_ndown_up_cml_out :  std_logic;
473
signal sp_en_cml_out :  std_logic;
474
signal cpuwait_cml_2 :  std_logic;
475
signal cpuwait_cml_1 :  std_logic;
476
signal reg_rd_in_cml_out :  std_logic_vector ( 7 downto 0 );
477
signal dbusin_cml_2 :  std_logic_vector ( 7 downto 0 );
478
signal irqlines_cml_2 :  std_logic_vector ( 22 downto 0 );
479
signal irqlines_cml_1 :  std_logic_vector ( 22 downto 0 );
480
signal alu_data_out_cml_2 :  std_logic_vector ( 7 downto 0 );
481
signal reg_rd_out_cml_2 :  std_logic_vector ( 7 downto 0 );
482
signal reg_rr_out_cml_2 :  std_logic_vector ( 7 downto 0 );
483
signal reg_rr_out_cml_1 :  std_logic_vector ( 7 downto 0 );
484
signal reg_h_out_cml_2 :  std_logic_vector ( 15 downto 0 );
485
signal reg_z_out_cml_2 :  std_logic_vector ( 15 downto 0 );
486
signal globint_cml_2 :  std_logic;
487
signal spl_out_cml_2 :  std_logic_vector ( 7 downto 0 );
488
signal sph_out_cml_2 :  std_logic_vector ( 7 downto 0 );
489
signal rampz_out_cml_2 :  std_logic_vector ( 7 downto 0 );
490
signal bitpr_io_out_cml_2 :  std_logic_vector ( 7 downto 0 );
491
signal bitpr_io_out_cml_1 :  std_logic_vector ( 7 downto 0 );
492
signal bld_op_out_cml_2 :  std_logic_vector ( 7 downto 0 );
493
signal irqack_cml_out :  std_logic;
494
signal irqack_int_cml_2 :  std_logic;
495
signal irqack_int_cml_1 :  std_logic;
496
signal irqackad_cml_out :  std_logic_vector ( 4 downto 0 );
497
signal irqackad_int_cml_2 :  std_logic_vector ( irqackad 'range);
498
signal irqackad_int_cml_1 :  std_logic_vector ( irqackad 'range);
499
signal adiw_sbiw_encoder_out_cml_2 :  std_logic_vector ( 4 downto 0 );
500
signal adiw_sbiw_encoder_out_cml_1 :  std_logic_vector ( 4 downto 0 );
501
signal adiw_sbiw_encoder_mux_out_cml_2 :  std_logic_vector ( 4 downto 0 );
502
signal adiw_sbiw_encoder_mux_out_cml_1 :  std_logic_vector ( 4 downto 0 );
503
signal program_counter_tmp_cml_2 :  std_logic_vector ( 15 downto 0 );
504
signal program_counter_tmp_cml_1 :  std_logic_vector ( 15 downto 0 );
505
signal program_counter_cml_2 :  std_logic_vector ( 15 downto 0 );
506
signal program_counter_cml_1 :  std_logic_vector ( 15 downto 0 );
507
signal program_counter_high_fr_cml_2 :  std_logic_vector ( 7 downto 0 );
508
signal program_counter_high_fr_cml_1 :  std_logic_vector ( 7 downto 0 );
509
signal pc_low_cml_2 :  std_logic_vector ( 7 downto 0 );
510
signal pc_low_cml_1 :  std_logic_vector ( 7 downto 0 );
511
signal pc_high_cml_2 :  std_logic_vector ( 7 downto 0 );
512
signal pc_high_cml_1 :  std_logic_vector ( 7 downto 0 );
513
signal reg_rd_wr_cml_out :  std_logic;
514
signal reg_file_adr_space_cml_2 :  std_logic;
515
signal reg_file_adr_space_cml_1 :  std_logic;
516
signal io_file_adr_space_cml_2 :  std_logic;
517
signal io_file_adr_space_cml_1 :  std_logic;
518
signal nirq_st0_cml_2 :  std_logic;
519
signal nirq_st0_cml_1 :  std_logic;
520
signal irq_st1_cml_2 :  std_logic;
521
signal irq_st1_cml_1 :  std_logic;
522
signal irq_st2_cml_2 :  std_logic;
523
signal irq_st2_cml_1 :  std_logic;
524
signal irq_st3_cml_2 :  std_logic;
525
signal irq_st3_cml_1 :  std_logic;
526
signal ncall_st0_cml_2 :  std_logic;
527
signal ncall_st0_cml_1 :  std_logic;
528
signal call_st1_cml_2 :  std_logic;
529
signal call_st1_cml_1 :  std_logic;
530
signal call_st2_cml_2 :  std_logic;
531
signal call_st2_cml_1 :  std_logic;
532
signal call_st3_cml_2 :  std_logic;
533
signal call_st3_cml_1 :  std_logic;
534
signal nrcall_st0_cml_2 :  std_logic;
535
signal nrcall_st0_cml_1 :  std_logic;
536
signal rcall_st1_cml_2 :  std_logic;
537
signal rcall_st1_cml_1 :  std_logic;
538
signal rcall_st2_cml_2 :  std_logic;
539
signal rcall_st2_cml_1 :  std_logic;
540
signal nicall_st0_cml_2 :  std_logic;
541
signal nicall_st0_cml_1 :  std_logic;
542
signal icall_st1_cml_2 :  std_logic;
543
signal icall_st1_cml_1 :  std_logic;
544
signal icall_st2_cml_2 :  std_logic;
545
signal icall_st2_cml_1 :  std_logic;
546
signal njmp_st0_cml_2 :  std_logic;
547
signal njmp_st0_cml_1 :  std_logic;
548
signal jmp_st1_cml_2 :  std_logic;
549
signal jmp_st1_cml_1 :  std_logic;
550
signal jmp_st2_cml_2 :  std_logic;
551
signal jmp_st2_cml_1 :  std_logic;
552
signal ijmp_st_cml_2 :  std_logic;
553
signal ijmp_st_cml_1 :  std_logic;
554
signal rjmp_st_cml_2 :  std_logic;
555
signal rjmp_st_cml_1 :  std_logic;
556
signal nret_st0_cml_2 :  std_logic;
557
signal nret_st0_cml_1 :  std_logic;
558
signal ret_st1_cml_2 :  std_logic;
559
signal ret_st1_cml_1 :  std_logic;
560
signal ret_st2_cml_2 :  std_logic;
561
signal ret_st2_cml_1 :  std_logic;
562
signal ret_st3_cml_2 :  std_logic;
563
signal ret_st3_cml_1 :  std_logic;
564
signal nreti_st0_cml_2 :  std_logic;
565
signal nreti_st0_cml_1 :  std_logic;
566
signal reti_st1_cml_2 :  std_logic;
567
signal reti_st1_cml_1 :  std_logic;
568
signal reti_st2_cml_2 :  std_logic;
569
signal reti_st2_cml_1 :  std_logic;
570
signal sreg_fl_in_cml_out :  std_logic_vector ( 7 downto 0 );
571
signal reti_st3_cml_2 :  std_logic;
572
signal reti_st3_cml_1 :  std_logic;
573
signal brxx_st_cml_2 :  std_logic;
574
signal brxx_st_cml_1 :  std_logic;
575
signal adiw_st_cml_2 :  std_logic;
576
signal adiw_st_cml_1 :  std_logic;
577
signal sbiw_st_cml_2 :  std_logic;
578
signal sbiw_st_cml_1 :  std_logic;
579
signal nskip_inst_st0_cml_2 :  std_logic;
580
signal nskip_inst_st0_cml_1 :  std_logic;
581
signal skip_inst_st1_cml_2 :  std_logic;
582
signal skip_inst_st1_cml_1 :  std_logic;
583
signal skip_inst_st2_cml_2 :  std_logic;
584
signal skip_inst_st2_cml_1 :  std_logic;
585
signal nlpm_st0_cml_2 :  std_logic;
586
signal nlpm_st0_cml_1 :  std_logic;
587
signal lpm_st1_cml_2 :  std_logic;
588
signal lpm_st1_cml_1 :  std_logic;
589
signal lpm_st2_cml_2 :  std_logic;
590
signal lpm_st2_cml_1 :  std_logic;
591
signal sts_st_cml_2 :  std_logic;
592
signal sts_st_cml_1 :  std_logic;
593
signal lds_st_cml_2 :  std_logic;
594
signal lds_st_cml_1 :  std_logic;
595
signal st_st_cml_2 :  std_logic;
596
signal st_st_cml_1 :  std_logic;
597
signal ld_st_cml_2 :  std_logic;
598
signal ld_st_cml_1 :  std_logic;
599
signal sbi_st_cml_2 :  std_logic;
600
signal sbi_st_cml_1 :  std_logic;
601
signal cbi_st_cml_2 :  std_logic;
602
signal cbi_st_cml_1 :  std_logic;
603
signal push_st_cml_2 :  std_logic;
604
signal push_st_cml_1 :  std_logic;
605
signal pop_st_cml_2 :  std_logic;
606
signal pop_st_cml_1 :  std_logic;
607
signal adr_int_cml_2 :  std_logic_vector ( 5 downto 0 );
608
signal ramadr_int_cml_2 :  std_logic_vector ( 15 downto 0 );
609
signal ramadr_int_cml_1 :  std_logic_vector ( 15 downto 0 );
610
signal ramre_int_cml_2 :  std_logic;
611
signal ramre_int_cml_1 :  std_logic;
612
signal ramwe_int_cml_2 :  std_logic;
613
signal ramwe_int_cml_1 :  std_logic;
614
signal instruction_reg_cml_2 :  std_logic_vector ( 15 downto 0 );
615
signal instruction_reg_cml_1 :  std_logic_vector ( 15 downto 0 );
616
signal instruction_code_reg_cml_2 :  std_logic_vector ( 15 downto 0 );
617
signal instruction_code_reg_cml_1 :  std_logic_vector ( 15 downto 0 );
618
signal pc_for_interrupt_cml_2 :  std_logic_vector ( 15 downto 0 );
619
signal pc_for_interrupt_cml_1 :  std_logic_vector ( 15 downto 0 );
620
signal dex_dat8_immed_cml_2 :  std_logic_vector ( 7 downto 0 );
621
signal dex_dat8_immed_cml_1 :  std_logic_vector ( 7 downto 0 );
622
signal dex_adr5port_cml_2 :  std_logic_vector ( 4 downto 0 );
623
signal dex_adr_disp_cml_2 :  std_logic_vector ( 5 downto 0 );
624
signal dex_adrreg_d_cml_2 :  std_logic_vector ( 4 downto 0 );
625
signal dex_adrreg_d_cml_1 :  std_logic_vector ( 4 downto 0 );
626
signal dex_bitop_bitnum_cml_2 :  std_logic_vector ( 2 downto 0 );
627
signal dex_bitop_bitnum_cml_1 :  std_logic_vector ( 2 downto 0 );
628
signal dex_adrreg_d_latched_cml_2 :  std_logic_vector ( 4 downto 0 );
629
signal dex_adrreg_d_latched_cml_1 :  std_logic_vector ( 4 downto 0 );
630
signal gp_reg_tmp_cml_2 :  std_logic_vector ( 7 downto 0 );
631
signal gp_reg_tmp_cml_1 :  std_logic_vector ( 7 downto 0 );
632
signal cbi_sbi_io_adr_tmp_cml_2 :  std_logic_vector ( 4 downto 0 );
633
signal cbi_sbi_io_adr_tmp_cml_1 :  std_logic_vector ( 4 downto 0 );
634
signal cbi_sbi_bit_num_tmp_cml_2 :  std_logic_vector ( 2 downto 0 );
635
signal cbi_sbi_bit_num_tmp_cml_1 :  std_logic_vector ( 2 downto 0 );
636
signal idc_adc_cml_2 :  std_logic;
637
signal idc_adc_cml_1 :  std_logic;
638
signal idc_add_cml_2 :  std_logic;
639
signal idc_adiw_out_cml_out :  std_logic;
640
signal idc_adiw_cml_2 :  std_logic;
641
signal idc_adiw_cml_1 :  std_logic;
642
signal idc_and_cml_2 :  std_logic;
643
signal idc_andi_out_cml_out :  std_logic;
644
signal idc_andi_cml_2 :  std_logic;
645
signal idc_andi_cml_1 :  std_logic;
646
signal idc_asr_cml_2 :  std_logic;
647
signal idc_bclr_out_cml_out :  std_logic;
648
signal idc_bclr_cml_2 :  std_logic;
649
signal idc_bld_cml_2 :  std_logic;
650
signal idc_brbc_out_cml_out :  std_logic;
651
signal idc_brbc_cml_2 :  std_logic;
652
signal idc_brbs_out_cml_out :  std_logic;
653
signal idc_brbs_cml_2 :  std_logic;
654
signal idc_bset_out_cml_out :  std_logic;
655
signal idc_bset_cml_2 :  std_logic;
656
signal idc_call_cml_2 :  std_logic;
657
signal idc_cbi_cml_2 :  std_logic;
658
signal idc_com_cml_2 :  std_logic;
659
signal idc_cp_cml_2 :  std_logic;
660
signal idc_cp_cml_1 :  std_logic;
661
signal idc_cpc_cml_2 :  std_logic;
662
signal idc_cpc_cml_1 :  std_logic;
663
signal idc_cpi_cml_2 :  std_logic;
664
signal idc_cpi_cml_1 :  std_logic;
665
signal idc_cpse_cml_2 :  std_logic;
666
signal idc_cpse_cml_1 :  std_logic;
667
signal idc_dec_cml_2 :  std_logic;
668
signal idc_eor_cml_2 :  std_logic;
669
signal idc_icall_cml_2 :  std_logic;
670
signal idc_icall_cml_1 :  std_logic;
671
signal idc_ijmp_cml_2 :  std_logic;
672
signal idc_in_cml_2 :  std_logic;
673
signal idc_inc_cml_2 :  std_logic;
674
signal idc_jmp_cml_2 :  std_logic;
675
signal reg_h_wr_cml_out :  std_logic;
676
signal idc_ld_x_cml_2 :  std_logic;
677
signal idc_ld_y_cml_2 :  std_logic;
678
signal idc_ldd_y_cml_2 :  std_logic;
679
signal idc_ld_z_cml_2 :  std_logic;
680
signal idc_ldd_z_cml_2 :  std_logic;
681
signal idc_ldi_cml_2 :  std_logic;
682
signal idc_ldi_cml_1 :  std_logic;
683
signal idc_lds_cml_2 :  std_logic;
684
signal idc_lpm_cml_2 :  std_logic;
685
signal idc_lsr_cml_2 :  std_logic;
686
signal idc_mov_cml_2 :  std_logic;
687
signal idc_neg_cml_2 :  std_logic;
688
signal idc_or_cml_2 :  std_logic;
689
signal idc_ori_out_cml_out :  std_logic;
690
signal idc_ori_cml_2 :  std_logic;
691
signal idc_ori_cml_1 :  std_logic;
692
signal idc_out_cml_2 :  std_logic;
693
signal idc_out_cml_1 :  std_logic;
694
signal idc_pop_cml_2 :  std_logic;
695
signal idc_push_cml_2 :  std_logic;
696
signal idc_push_cml_1 :  std_logic;
697
signal idc_rcall_cml_2 :  std_logic;
698
signal idc_rcall_cml_1 :  std_logic;
699
signal idc_ret_cml_2 :  std_logic;
700
signal idc_reti_out_cml_out :  std_logic;
701
signal idc_reti_cml_2 :  std_logic;
702
signal idc_rjmp_cml_2 :  std_logic;
703
signal idc_ror_cml_2 :  std_logic;
704
signal idc_ror_cml_1 :  std_logic;
705
signal idc_sbc_cml_2 :  std_logic;
706
signal idc_sbc_cml_1 :  std_logic;
707
signal idc_sbci_cml_2 :  std_logic;
708
signal idc_sbci_cml_1 :  std_logic;
709
signal idc_sbi_cml_2 :  std_logic;
710
signal idc_sbic_cml_2 :  std_logic;
711
signal idc_sbis_cml_2 :  std_logic;
712
signal idc_sbiw_cml_2 :  std_logic;
713
signal idc_sbiw_cml_1 :  std_logic;
714
signal idc_sbrc_out_cml_out :  std_logic;
715
signal idc_sbrc_cml_2 :  std_logic;
716
signal idc_sbrs_out_cml_out :  std_logic;
717
signal idc_sbrs_cml_2 :  std_logic;
718
signal reg_h_adr_cml_out :  std_logic_vector ( 2 downto 0 );
719
signal idc_st_x_cml_2 :  std_logic;
720
signal idc_st_x_cml_1 :  std_logic;
721
signal idc_st_y_cml_2 :  std_logic;
722
signal idc_st_y_cml_1 :  std_logic;
723
signal idc_std_y_cml_2 :  std_logic;
724
signal idc_std_y_cml_1 :  std_logic;
725
signal idc_st_z_cml_2 :  std_logic;
726
signal idc_st_z_cml_1 :  std_logic;
727
signal idc_std_z_cml_2 :  std_logic;
728
signal idc_std_z_cml_1 :  std_logic;
729
signal idc_sts_cml_2 :  std_logic;
730
signal idc_sts_cml_1 :  std_logic;
731
signal idc_sub_cml_2 :  std_logic;
732
signal idc_sub_cml_1 :  std_logic;
733
signal idc_subi_cml_2 :  std_logic;
734
signal idc_subi_cml_1 :  std_logic;
735
signal idc_prdec_cml_2 :  std_logic;
736
 
737
begin
738
 
739
 
740
 
741
process(cp2_cml_1) begin
742
if (cp2_cml_1 = '1' and cp2_cml_1'event) then
743
        inst_cml_1 <= inst;
744
        cpuwait_cml_1 <= cpuwait;
745
        irqlines_cml_1 <= irqlines;
746
        reg_rr_out_cml_1 <= reg_rr_out;
747
        bitpr_io_out_cml_1 <= bitpr_io_out;
748
        irqack_int_cml_1 <= irqack_int;
749
        irqackad_int_cml_1 <= irqackad_int;
750
        adiw_sbiw_encoder_out_cml_1 <= adiw_sbiw_encoder_out;
751
        adiw_sbiw_encoder_mux_out_cml_1 <= adiw_sbiw_encoder_mux_out;
752
        program_counter_tmp_cml_1 <= program_counter_tmp;
753
        program_counter_cml_1 <= program_counter;
754
        program_counter_high_fr_cml_1 <= program_counter_high_fr;
755
        pc_low_cml_1 <= pc_low;
756
        pc_high_cml_1 <= pc_high;
757
        reg_file_adr_space_cml_1 <= reg_file_adr_space;
758
        io_file_adr_space_cml_1 <= io_file_adr_space;
759
        nirq_st0_cml_1 <= nirq_st0;
760
        irq_st1_cml_1 <= irq_st1;
761
        irq_st2_cml_1 <= irq_st2;
762
        irq_st3_cml_1 <= irq_st3;
763
        ncall_st0_cml_1 <= ncall_st0;
764
        call_st1_cml_1 <= call_st1;
765
        call_st2_cml_1 <= call_st2;
766
        call_st3_cml_1 <= call_st3;
767
        nrcall_st0_cml_1 <= nrcall_st0;
768
        rcall_st1_cml_1 <= rcall_st1;
769
        rcall_st2_cml_1 <= rcall_st2;
770
        nicall_st0_cml_1 <= nicall_st0;
771
        icall_st1_cml_1 <= icall_st1;
772
        icall_st2_cml_1 <= icall_st2;
773
        njmp_st0_cml_1 <= njmp_st0;
774
        jmp_st1_cml_1 <= jmp_st1;
775
        jmp_st2_cml_1 <= jmp_st2;
776
        ijmp_st_cml_1 <= ijmp_st;
777
        rjmp_st_cml_1 <= rjmp_st;
778
        nret_st0_cml_1 <= nret_st0;
779
        ret_st1_cml_1 <= ret_st1;
780
        ret_st2_cml_1 <= ret_st2;
781
        ret_st3_cml_1 <= ret_st3;
782
        nreti_st0_cml_1 <= nreti_st0;
783
        reti_st1_cml_1 <= reti_st1;
784
        reti_st2_cml_1 <= reti_st2;
785
        reti_st3_cml_1 <= reti_st3;
786
        brxx_st_cml_1 <= brxx_st;
787
        adiw_st_cml_1 <= adiw_st;
788
        sbiw_st_cml_1 <= sbiw_st;
789
        nskip_inst_st0_cml_1 <= nskip_inst_st0;
790
        skip_inst_st1_cml_1 <= skip_inst_st1;
791
        skip_inst_st2_cml_1 <= skip_inst_st2;
792
        nlpm_st0_cml_1 <= nlpm_st0;
793
        lpm_st1_cml_1 <= lpm_st1;
794
        lpm_st2_cml_1 <= lpm_st2;
795
        sts_st_cml_1 <= sts_st;
796
        lds_st_cml_1 <= lds_st;
797
        st_st_cml_1 <= st_st;
798
        ld_st_cml_1 <= ld_st;
799
        sbi_st_cml_1 <= sbi_st;
800
        cbi_st_cml_1 <= cbi_st;
801
        push_st_cml_1 <= push_st;
802
        pop_st_cml_1 <= pop_st;
803
        ramadr_int_cml_1 <= ramadr_int;
804
        ramre_int_cml_1 <= ramre_int;
805
        ramwe_int_cml_1 <= ramwe_int;
806
        instruction_reg_cml_1 <= instruction_reg;
807
        instruction_code_reg_cml_1 <= instruction_code_reg;
808
        pc_for_interrupt_cml_1 <= pc_for_interrupt;
809
        dex_dat8_immed_cml_1 <= dex_dat8_immed;
810
        dex_adrreg_d_cml_1 <= dex_adrreg_d;
811
        dex_bitop_bitnum_cml_1 <= dex_bitop_bitnum;
812
        dex_adrreg_d_latched_cml_1 <= dex_adrreg_d_latched;
813
        gp_reg_tmp_cml_1 <= gp_reg_tmp;
814
        cbi_sbi_io_adr_tmp_cml_1 <= cbi_sbi_io_adr_tmp;
815
        cbi_sbi_bit_num_tmp_cml_1 <= cbi_sbi_bit_num_tmp;
816
        idc_adc_cml_1 <= idc_adc;
817
        idc_adiw_cml_1 <= idc_adiw;
818
        idc_andi_cml_1 <= idc_andi;
819
        idc_cp_cml_1 <= idc_cp;
820
        idc_cpc_cml_1 <= idc_cpc;
821
        idc_cpi_cml_1 <= idc_cpi;
822
        idc_cpse_cml_1 <= idc_cpse;
823
        idc_icall_cml_1 <= idc_icall;
824
        idc_ldi_cml_1 <= idc_ldi;
825
        idc_ori_cml_1 <= idc_ori;
826
        idc_out_cml_1 <= idc_out;
827
        idc_push_cml_1 <= idc_push;
828
        idc_rcall_cml_1 <= idc_rcall;
829
        idc_ror_cml_1 <= idc_ror;
830
        idc_sbc_cml_1 <= idc_sbc;
831
        idc_sbci_cml_1 <= idc_sbci;
832
        idc_sbiw_cml_1 <= idc_sbiw;
833
        idc_st_x_cml_1 <= idc_st_x;
834
        idc_st_y_cml_1 <= idc_st_y;
835
        idc_std_y_cml_1 <= idc_std_y;
836
        idc_st_z_cml_1 <= idc_st_z;
837
        idc_std_z_cml_1 <= idc_std_z;
838
        idc_sts_cml_1 <= idc_sts;
839
        idc_sub_cml_1 <= idc_sub;
840
        idc_subi_cml_1 <= idc_subi;
841
end if;
842
end process;
843
 
844
process(cp2_cml_2) begin
845
if (cp2_cml_2 = '1' and cp2_cml_2'event) then
846
        inst_cml_2 <= inst_cml_1;
847
        cpuwait_cml_2 <= cpuwait_cml_1;
848
        dbusin_cml_2 <= dbusin;
849
        irqlines_cml_2 <= irqlines_cml_1;
850
        alu_data_out_cml_2 <= alu_data_out;
851
        reg_rd_out_cml_2 <= reg_rd_out;
852
        reg_rr_out_cml_2 <= reg_rr_out_cml_1;
853
        reg_h_out_cml_2 <= reg_h_out;
854
        reg_z_out_cml_2 <= reg_z_out;
855
        globint_cml_2 <= globint;
856
        spl_out_cml_2 <= spl_out;
857
        sph_out_cml_2 <= sph_out;
858
        rampz_out_cml_2 <= rampz_out;
859
        bitpr_io_out_cml_2 <= bitpr_io_out_cml_1;
860
        bld_op_out_cml_2 <= bld_op_out;
861
        irqack_int_cml_2 <= irqack_int_cml_1;
862
        irqackad_int_cml_2 <= irqackad_int_cml_1;
863
        adiw_sbiw_encoder_out_cml_2 <= adiw_sbiw_encoder_out_cml_1;
864
        adiw_sbiw_encoder_mux_out_cml_2 <= adiw_sbiw_encoder_mux_out_cml_1;
865
        program_counter_tmp_cml_2 <= program_counter_tmp_cml_1;
866
        program_counter_cml_2 <= program_counter_cml_1;
867
        program_counter_high_fr_cml_2 <= program_counter_high_fr_cml_1;
868
        pc_low_cml_2 <= pc_low_cml_1;
869
        pc_high_cml_2 <= pc_high_cml_1;
870
        reg_file_adr_space_cml_2 <= reg_file_adr_space_cml_1;
871
        io_file_adr_space_cml_2 <= io_file_adr_space_cml_1;
872
        nirq_st0_cml_2 <= nirq_st0_cml_1;
873
        irq_st1_cml_2 <= irq_st1_cml_1;
874
        irq_st2_cml_2 <= irq_st2_cml_1;
875
        irq_st3_cml_2 <= irq_st3_cml_1;
876
        ncall_st0_cml_2 <= ncall_st0_cml_1;
877
        call_st1_cml_2 <= call_st1_cml_1;
878
        call_st2_cml_2 <= call_st2_cml_1;
879
        call_st3_cml_2 <= call_st3_cml_1;
880
        nrcall_st0_cml_2 <= nrcall_st0_cml_1;
881
        rcall_st1_cml_2 <= rcall_st1_cml_1;
882
        rcall_st2_cml_2 <= rcall_st2_cml_1;
883
        nicall_st0_cml_2 <= nicall_st0_cml_1;
884
        icall_st1_cml_2 <= icall_st1_cml_1;
885
        icall_st2_cml_2 <= icall_st2_cml_1;
886
        njmp_st0_cml_2 <= njmp_st0_cml_1;
887
        jmp_st1_cml_2 <= jmp_st1_cml_1;
888
        jmp_st2_cml_2 <= jmp_st2_cml_1;
889
        ijmp_st_cml_2 <= ijmp_st_cml_1;
890
        rjmp_st_cml_2 <= rjmp_st_cml_1;
891
        nret_st0_cml_2 <= nret_st0_cml_1;
892
        ret_st1_cml_2 <= ret_st1_cml_1;
893
        ret_st2_cml_2 <= ret_st2_cml_1;
894
        ret_st3_cml_2 <= ret_st3_cml_1;
895
        nreti_st0_cml_2 <= nreti_st0_cml_1;
896
        reti_st1_cml_2 <= reti_st1_cml_1;
897
        reti_st2_cml_2 <= reti_st2_cml_1;
898
        reti_st3_cml_2 <= reti_st3_cml_1;
899
        brxx_st_cml_2 <= brxx_st_cml_1;
900
        adiw_st_cml_2 <= adiw_st_cml_1;
901
        sbiw_st_cml_2 <= sbiw_st_cml_1;
902
        nskip_inst_st0_cml_2 <= nskip_inst_st0_cml_1;
903
        skip_inst_st1_cml_2 <= skip_inst_st1_cml_1;
904
        skip_inst_st2_cml_2 <= skip_inst_st2_cml_1;
905
        nlpm_st0_cml_2 <= nlpm_st0_cml_1;
906
        lpm_st1_cml_2 <= lpm_st1_cml_1;
907
        lpm_st2_cml_2 <= lpm_st2_cml_1;
908
        sts_st_cml_2 <= sts_st_cml_1;
909
        lds_st_cml_2 <= lds_st_cml_1;
910
        st_st_cml_2 <= st_st_cml_1;
911
        ld_st_cml_2 <= ld_st_cml_1;
912
        sbi_st_cml_2 <= sbi_st_cml_1;
913
        cbi_st_cml_2 <= cbi_st_cml_1;
914
        push_st_cml_2 <= push_st_cml_1;
915
        pop_st_cml_2 <= pop_st_cml_1;
916
        adr_int_cml_2 <= adr_int;
917
        ramadr_int_cml_2 <= ramadr_int_cml_1;
918
        ramre_int_cml_2 <= ramre_int_cml_1;
919
        ramwe_int_cml_2 <= ramwe_int_cml_1;
920
        instruction_reg_cml_2 <= instruction_reg_cml_1;
921
        instruction_code_reg_cml_2 <= instruction_code_reg_cml_1;
922
        pc_for_interrupt_cml_2 <= pc_for_interrupt_cml_1;
923
        dex_dat8_immed_cml_2 <= dex_dat8_immed_cml_1;
924
        dex_adr5port_cml_2 <= dex_adr5port;
925
        dex_adr_disp_cml_2 <= dex_adr_disp;
926
        dex_adrreg_d_cml_2 <= dex_adrreg_d_cml_1;
927
        dex_bitop_bitnum_cml_2 <= dex_bitop_bitnum_cml_1;
928
        dex_adrreg_d_latched_cml_2 <= dex_adrreg_d_latched_cml_1;
929
        gp_reg_tmp_cml_2 <= gp_reg_tmp_cml_1;
930
        cbi_sbi_io_adr_tmp_cml_2 <= cbi_sbi_io_adr_tmp_cml_1;
931
        cbi_sbi_bit_num_tmp_cml_2 <= cbi_sbi_bit_num_tmp_cml_1;
932
        idc_adc_cml_2 <= idc_adc_cml_1;
933
        idc_add_cml_2 <= idc_add;
934
        idc_adiw_cml_2 <= idc_adiw_cml_1;
935
        idc_and_cml_2 <= idc_and;
936
        idc_andi_cml_2 <= idc_andi_cml_1;
937
        idc_asr_cml_2 <= idc_asr;
938
        idc_bclr_cml_2 <= idc_bclr;
939
        idc_bld_cml_2 <= idc_bld;
940
        idc_brbc_cml_2 <= idc_brbc;
941
        idc_brbs_cml_2 <= idc_brbs;
942
        idc_bset_cml_2 <= idc_bset;
943
        idc_call_cml_2 <= idc_call;
944
        idc_cbi_cml_2 <= idc_cbi;
945
        idc_com_cml_2 <= idc_com;
946
        idc_cp_cml_2 <= idc_cp_cml_1;
947
        idc_cpc_cml_2 <= idc_cpc_cml_1;
948
        idc_cpi_cml_2 <= idc_cpi_cml_1;
949
        idc_cpse_cml_2 <= idc_cpse_cml_1;
950
        idc_dec_cml_2 <= idc_dec;
951
        idc_eor_cml_2 <= idc_eor;
952
        idc_icall_cml_2 <= idc_icall_cml_1;
953
        idc_ijmp_cml_2 <= idc_ijmp;
954
        idc_in_cml_2 <= idc_in;
955
        idc_inc_cml_2 <= idc_inc;
956
        idc_jmp_cml_2 <= idc_jmp;
957
        idc_ld_x_cml_2 <= idc_ld_x;
958
        idc_ld_y_cml_2 <= idc_ld_y;
959
        idc_ldd_y_cml_2 <= idc_ldd_y;
960
        idc_ld_z_cml_2 <= idc_ld_z;
961
        idc_ldd_z_cml_2 <= idc_ldd_z;
962
        idc_ldi_cml_2 <= idc_ldi_cml_1;
963
        idc_lds_cml_2 <= idc_lds;
964
        idc_lpm_cml_2 <= idc_lpm;
965
        idc_lsr_cml_2 <= idc_lsr;
966
        idc_mov_cml_2 <= idc_mov;
967
        idc_neg_cml_2 <= idc_neg;
968
        idc_or_cml_2 <= idc_or;
969
        idc_ori_cml_2 <= idc_ori_cml_1;
970
        idc_out_cml_2 <= idc_out_cml_1;
971
        idc_pop_cml_2 <= idc_pop;
972
        idc_push_cml_2 <= idc_push_cml_1;
973
        idc_rcall_cml_2 <= idc_rcall_cml_1;
974
        idc_ret_cml_2 <= idc_ret;
975
        idc_reti_cml_2 <= idc_reti;
976
        idc_rjmp_cml_2 <= idc_rjmp;
977
        idc_ror_cml_2 <= idc_ror_cml_1;
978
        idc_sbc_cml_2 <= idc_sbc_cml_1;
979
        idc_sbci_cml_2 <= idc_sbci_cml_1;
980
        idc_sbi_cml_2 <= idc_sbi;
981
        idc_sbic_cml_2 <= idc_sbic;
982
        idc_sbis_cml_2 <= idc_sbis;
983
        idc_sbiw_cml_2 <= idc_sbiw_cml_1;
984
        idc_sbrc_cml_2 <= idc_sbrc;
985
        idc_sbrs_cml_2 <= idc_sbrs;
986
        idc_st_x_cml_2 <= idc_st_x_cml_1;
987
        idc_st_y_cml_2 <= idc_st_y_cml_1;
988
        idc_std_y_cml_2 <= idc_std_y_cml_1;
989
        idc_st_z_cml_2 <= idc_st_z_cml_1;
990
        idc_std_z_cml_2 <= idc_std_z_cml_1;
991
        idc_sts_cml_2 <= idc_sts_cml_1;
992
        idc_sub_cml_2 <= idc_sub_cml_1;
993
        idc_subi_cml_2 <= idc_subi_cml_1;
994
        idc_prdec_cml_2 <= idc_prdec;
995
end if;
996
end process;
997
sp_ndown_up <= sp_ndown_up_cml_out;
998
sp_en <= sp_en_cml_out;
999
reg_rd_in <= reg_rd_in_cml_out;
1000
irqack <= irqack_cml_out;
1001
irqackad <= irqackad_cml_out;
1002
reg_rd_wr <= reg_rd_wr_cml_out;
1003
sreg_fl_in <= sreg_fl_in_cml_out;
1004
idc_adiw_out <= idc_adiw_out_cml_out;
1005
idc_andi_out <= idc_andi_out_cml_out;
1006
idc_bclr_out <= idc_bclr_out_cml_out;
1007
idc_brbc_out <= idc_brbc_out_cml_out;
1008
idc_brbs_out <= idc_brbs_out_cml_out;
1009
idc_bset_out <= idc_bset_out_cml_out;
1010
reg_h_wr <= reg_h_wr_cml_out;
1011
idc_ori_out <= idc_ori_out_cml_out;
1012
idc_reti_out <= idc_reti_out_cml_out;
1013
idc_sbrc_out <= idc_sbrc_out_cml_out;
1014
idc_sbrs_out <= idc_sbrs_out_cml_out;
1015
reg_h_adr <= reg_h_adr_cml_out;
1016
 
1017
 
1018
sreg_fl_wr_en <= sreg_i_wr_en & sreg_t_wr_en & sreg_h_wr_en & sreg_s_wr_en & sreg_v_wr_en & sreg_n_wr_en & sreg_z_wr_en & sreg_c_wr_en;
1019
 
1020
 
1021
-- INSTRUCTION FETCH
1022
instruction_reg_ena <= '1'; -- FOR TEST
1023
 
1024
-- SynEDA CoreMultiplier
1025
-- assignment(s): instruction_reg
1026
-- replace(s): inst, instruction_reg
1027
 
1028
instruction_fetch:process(cp2,ireset)
1029
begin
1030
if ireset='0' then                              -- RESET
1031
instruction_reg <= (others => '0');
1032
elsif (cp2='1' and cp2'event) then instruction_reg <= instruction_reg_cml_2;            -- CLOCK
1033
 if (cp2en='1') then                                                      -- Clock enable
1034
  if instruction_reg_ena='1' then
1035
   instruction_reg <= inst_cml_2;
1036
  end if;
1037
 end if;
1038
end if;
1039
end process;
1040
 
1041
-- SynEDA CoreMultiplier
1042
-- assignment(s): two_word_inst
1043
-- replace(s): instruction_reg
1044
 
1045
-- TWO WORDS INSTRUCTION DETECTOR (CONNECTED DIRECTLY TO THE INSTRUCTION REGISTER)
1046
two_word_inst <= '1' when
1047
((instruction_reg_cml_2(15 downto 9)&instruction_reg_cml_2(3 downto 1)="1001010111") or    -- CALL
1048
 (instruction_reg_cml_2(15 downto 9)&instruction_reg_cml_2(3 downto 1)="1001010110")) or   -- JMP
1049
 (instruction_reg_cml_2(15 downto 9)&instruction_reg_cml_2(3 downto 0) = "10010000000") or -- LDS
1050
 (instruction_reg_cml_2(15 downto 9)&instruction_reg_cml_2(3 downto 0) = "10010010000")    -- STS
1051
   else '0';  -- TO DETECT CALL/JMP/LDS/STS INSTRUCTIONS FOR SBRS/SBRC/SBIS/SBIC/CPSE
1052
 
1053
 
1054
 
1055
-- DATA EXTRACTOR (CONNECTED DIRECTLY TO THE INSTRUCTION REGISTER)
1056
dex_dat8_immed <= instruction_reg(11 downto 8) & instruction_reg(3 downto 0);
1057
dex_dat6_immed <= instruction_reg(7 downto 6) & instruction_reg(3 downto 0);
1058
-- SynEDA CoreMultiplier
1059
-- assignment(s): dex_adr12mem_s
1060
-- replace(s): instruction_reg
1061
 
1062
dex_adr12mem_s <= instruction_reg_cml_2(11 downto 0);
1063
-- SynEDA CoreMultiplier
1064
-- assignment(s): dex_adr6port
1065
-- replace(s): instruction_reg
1066
 
1067
dex_adr6port <= instruction_reg_cml_1(10 downto 9) & instruction_reg_cml_1(3 downto 0);
1068
-- SynEDA CoreMultiplier
1069
-- assignment(s): dex_adr5port
1070
-- replace(s): instruction_reg
1071
 
1072
dex_adr5port <= instruction_reg_cml_1(7 downto 3);
1073
-- SynEDA CoreMultiplier
1074
-- assignment(s): dex_adr_disp
1075
-- replace(s): instruction_reg
1076
 
1077
dex_adr_disp <= instruction_reg_cml_1(13) & instruction_reg_cml_1(11 downto 10) & instruction_reg_cml_1(2 downto 0);
1078
-- SynEDA CoreMultiplier
1079
-- assignment(s): dex_condition
1080
-- replace(s): instruction_reg
1081
 
1082
dex_condition <= instruction_reg_cml_2(2 downto 0);
1083
-- SynEDA CoreMultiplier
1084
-- assignment(s): dex_bitnum_sreg
1085
-- replace(s): instruction_reg
1086
 
1087
dex_bitop_bitnum <= instruction_reg(2 downto 0);      -- NUMBER(POSITION) OF TESTING BIT IN SBRC/SBRS/SBIC/SBIS INSTRUCTION
1088
dex_bitnum_sreg <= instruction_reg_cml_2(6 downto 4);
1089
dex_adrreg_r  <=  instruction_reg(9) & instruction_reg(3 downto 0);
1090
dex_adrreg_d  <= instruction_reg(8 downto 4);
1091
-- SynEDA CoreMultiplier
1092
-- assignment(s): dex_brxx_offset
1093
-- replace(s): instruction_reg
1094
 
1095
dex_brxx_offset <= instruction_reg_cml_2(9 downto 3);       -- OFFSET FOR BRBC/BRBS     
1096
dex_adiw_sbiw_reg_adr <= instruction_reg(5 downto 4); -- ADDRESS OF THE LOW REGISTER FOR ADIW/SBIW INSTRUCTIONS
1097
--dex_adrindreg <= instruction_reg(3 downto 2);     
1098
 
1099
-- SynEDA CoreMultiplier
1100
-- assignment(s): dex_adrreg_d_latched
1101
-- replace(s): dex_adrreg_d, dex_adrreg_d_latched, idc_ld_x, idc_ld_y, idc_ldd_y, idc_ld_z, idc_ldd_z, idc_lds, idc_pop, idc_st_x, idc_st_y, idc_std_y, idc_st_z, idc_std_z, idc_sts
1102
 
1103
-- LATCH Rd ADDDRESS FOR LDS/STS/POP INSTRUCTIONS
1104
latcht_rd_adr:process(cp2,ireset)
1105
begin
1106
if ireset ='0' then
1107
dex_adrreg_d_latched <= (others => '0');
1108
elsif (cp2='1' and cp2'event) then dex_adrreg_d_latched <= dex_adrreg_d_latched_cml_2;
1109
 if (cp2en='1') then                                                      -- Clock enable
1110
  if ((idc_ld_x_cml_2 or idc_ld_y_cml_2 or idc_ldd_y_cml_2 or idc_ld_z_cml_2 or idc_ldd_z_cml_2) or idc_sts_cml_2 or
1111
          (idc_st_x_cml_2  or idc_st_y_cml_2 or idc_std_y_cml_2 or idc_st_z_cml_2 or idc_std_z_cml_2)or idc_lds_cml_2 or
1112
           idc_pop_cml_2)='1' then
1113
   dex_adrreg_d_latched <= dex_adrreg_d_cml_2;
1114
  end if;
1115
 end if;
1116
end if;
1117
end process;
1118
-- +++++++++++++++++++++++++++++++++++++++++++++++++
1119
 
1120
 
1121
-- R24:R25/R26:R27/R28:R29/R30:R31 ADIW/SBIW  ADDRESS CONTROL LOGIC
1122
adiw_sbiw_encoder_out <= "11"&dex_adiw_sbiw_reg_adr&'0';
1123
 
1124
-- SynEDA CoreMultiplier
1125
-- assignment(s): adiw_sbiw_encoder_mux_out
1126
-- replace(s): adiw_sbiw_encoder_out, adiw_sbiw_encoder_mux_out
1127
 
1128
adiw_sbiw_high_reg_adr:process(cp2,ireset)
1129
begin
1130
if ireset ='0' then
1131
adiw_sbiw_encoder_mux_out <= (others=>'0');
1132
elsif(cp2='1' and cp2'event) then adiw_sbiw_encoder_mux_out <= adiw_sbiw_encoder_mux_out_cml_2;
1133
 if (cp2en='1') then                                                      -- Clock enable
1134
  adiw_sbiw_encoder_mux_out <= adiw_sbiw_encoder_out_cml_2 +1;
1135
 end if;
1136
end if;
1137
end process;
1138
 
1139
-- ##########################
1140
 
1141
-- NOP INSERTION
1142
 
1143
--instruction_code_reg <= instruction_reg when nop_insert_st='0' else (others => '0');
1144
instruction_code_reg <= (others => '0') when (nop_insert_st='1') else -- NOP
1145
                        instruction_reg;                                                                                                -- Instruction 
1146
 
1147
 
1148
nop_insert_st <= adiw_st or sbiw_st or cbi_st or sbi_st or rjmp_st or ijmp_st or pop_st or push_st or
1149
              brxx_st or ld_st or st_st or ncall_st0 or nirq_st0 or nret_st0 or nreti_st0 or nlpm_st0 or njmp_st0 or
1150
              nrcall_st0 or nicall_st0 or sts_st or lds_st or nskip_inst_st0;
1151
 
1152
 
1153
-- INSTRUCTION DECODER (CONNECTED AFTER NOP INSERTION LOGIC)
1154
 
1155
-- SynEDA CoreMultiplier
1156
-- assignment(s): idc_add
1157
-- replace(s): instruction_code_reg
1158
 
1159
idc_adc  <= '1' when instruction_code_reg(15 downto 10) = "000111" else '0'; -- 000111XXXXXXXXXX
1160
idc_add  <= '1' when instruction_code_reg_cml_1(15 downto 10) = "000011" else '0'; -- 000011XXXXXXXXXX
1161
 
1162
idc_adiw <= '1' when instruction_code_reg(15 downto 8) = "10010110" else '0'; -- 10010110XXXXXXXX
1163
 
1164
-- SynEDA CoreMultiplier
1165
-- assignment(s): idc_and
1166
-- replace(s): instruction_code_reg
1167
 
1168
idc_and  <= '1' when instruction_code_reg_cml_1(15 downto 10) = "001000" else '0'; -- 001000XXXXXXXXXX
1169
idc_andi <= '1' when instruction_code_reg(15 downto 12) = "0111" else '0'; -- 0111XXXXXXXXXXXX
1170
 
1171
-- SynEDA CoreMultiplier
1172
-- assignment(s): idc_asr
1173
-- replace(s): instruction_code_reg
1174
 
1175
idc_asr  <= '1' when instruction_code_reg_cml_1(15 downto 9)&instruction_code_reg_cml_1(3 downto 0) = "10010100101" else '0'; -- 1001010XXXXX0101
1176
 
1177
-- SynEDA CoreMultiplier
1178
-- assignment(s): idc_bclr
1179
-- replace(s): instruction_code_reg
1180
 
1181
idc_bclr <= '1' when instruction_code_reg_cml_1(15 downto 7)&instruction_code_reg_cml_1(3 downto 0) = "1001010011000" else '0'; -- 100101001XXX1000
1182
 
1183
-- SynEDA CoreMultiplier
1184
-- assignment(s): idc_bld
1185
-- replace(s): instruction_code_reg
1186
 
1187
idc_bld  <= '1' when instruction_code_reg_cml_1(15 downto 9)&instruction_code_reg_cml_1(3) = "11111000" else '0'; -- 1111100XXXXX0XXX
1188
 
1189
-- SynEDA CoreMultiplier
1190
-- assignment(s): idc_brbs
1191
-- replace(s): instruction_code_reg
1192
 
1193
-- SynEDA CoreMultiplier
1194
-- assignment(s): idc_brbc
1195
-- replace(s): instruction_code_reg
1196
 
1197
idc_brbc <= '1' when instruction_code_reg_cml_1(15 downto 10) = "111101" else '0'; -- 111101XXXXXXXXXX
1198
idc_brbs <= '1' when instruction_code_reg_cml_1(15 downto 10) = "111100" else '0'; -- 111100XXXXXXXXXX
1199
 
1200
-- SynEDA CoreMultiplier
1201
-- assignment(s): idc_bset
1202
-- replace(s): instruction_code_reg
1203
 
1204
idc_bset <= '1' when instruction_code_reg_cml_1(15 downto 7)&instruction_code_reg_cml_1(3 downto 0) = "1001010001000" else '0'; -- 100101000XXX1000
1205
 
1206
-- SynEDA CoreMultiplier
1207
-- assignment(s): idc_bst
1208
-- replace(s): instruction_code_reg
1209
 
1210
idc_bst  <= '1' when instruction_code_reg_cml_2(15 downto 9) = "1111101" else '0'; -- 1111101XXXXXXXXX
1211
 
1212
-- SynEDA CoreMultiplier
1213
-- assignment(s): idc_call
1214
-- replace(s): instruction_code_reg
1215
 
1216
idc_call <= '1' when instruction_code_reg_cml_1(15 downto 9)&instruction_code_reg_cml_1(3 downto 1) = "1001010111" else '0'; -- 1001010XXXXX111X
1217
 
1218
-- SynEDA CoreMultiplier
1219
-- assignment(s): idc_cbi
1220
-- replace(s): instruction_code_reg
1221
 
1222
idc_cbi  <= '1' when instruction_code_reg_cml_1(15 downto 8) = "10011000" else '0'; -- 10011000XXXXXXXX
1223
 
1224
-- SynEDA CoreMultiplier
1225
-- assignment(s): idc_com
1226
-- replace(s): instruction_code_reg
1227
 
1228
idc_com  <= '1' when instruction_code_reg_cml_1(15 downto 9)&instruction_code_reg_cml_1(3 downto 0) = "10010100000" else '0'; -- 1001010XXXXX0000
1229
 
1230
idc_cp   <= '1' when instruction_code_reg(15 downto 10) = "000101" else '0'; -- 000101XXXXXXXXXX
1231
 
1232
idc_cpc  <= '1' when instruction_code_reg(15 downto 10) = "000001" else '0'; -- 000001XXXXXXXXXX
1233
 
1234
idc_cpi  <= '1' when instruction_code_reg(15 downto 12) = "0011" else '0'; -- 0011XXXXXXXXXXXX
1235
 
1236
idc_cpse <= '1' when instruction_code_reg(15 downto 10) = "000100" else '0'; -- 000100XXXXXXXXXX
1237
 
1238
-- SynEDA CoreMultiplier
1239
-- assignment(s): idc_dec
1240
-- replace(s): instruction_code_reg
1241
 
1242
idc_dec  <= '1' when instruction_code_reg_cml_1(15 downto 9)&instruction_code_reg_cml_1(3 downto 0) = "10010101010" else '0'; -- 1001010XXXXX1010
1243
 
1244
-- SynEDA CoreMultiplier
1245
-- assignment(s): idc_elpm
1246
-- replace(s): instruction_code_reg
1247
 
1248
idc_elpm <= '1' when instruction_code_reg_cml_2 = "1001010111011000" else '0'; -- 1001010111011000
1249
 
1250
-- SynEDA CoreMultiplier
1251
-- assignment(s): idc_eor
1252
-- replace(s): instruction_code_reg
1253
 
1254
idc_eor  <= '1' when instruction_code_reg_cml_1(15 downto 10) = "001001" else '0'; -- 001001XXXXXXXXXX
1255
 
1256
idc_icall<= '1' when instruction_code_reg(15 downto 8)&instruction_code_reg(3 downto 0) = "100101011001" else '0'; -- 10010101XXXX1001
1257
 
1258
-- SynEDA CoreMultiplier
1259
-- assignment(s): idc_ijmp
1260
-- replace(s): instruction_code_reg
1261
 
1262
idc_ijmp <= '1' when instruction_code_reg_cml_1(15 downto 8)&instruction_code_reg_cml_1(3 downto 0) = "100101001001" else '0'; -- 10010100XXXX1001
1263
 
1264
-- SynEDA CoreMultiplier
1265
-- assignment(s): idc_in
1266
-- replace(s): instruction_code_reg
1267
 
1268
idc_in   <= '1' when instruction_code_reg_cml_1(15 downto 11) = "10110" else '0'; -- 10110XXXXXXXXXXX
1269
 
1270
-- SynEDA CoreMultiplier
1271
-- assignment(s): idc_inc
1272
-- replace(s): instruction_code_reg
1273
 
1274
idc_inc  <= '1' when instruction_code_reg_cml_1(15 downto 9)&instruction_code_reg_cml_1(3 downto 0) = "10010100011" else '0'; -- 1001010XXXXX0011
1275
 
1276
-- SynEDA CoreMultiplier
1277
-- assignment(s): idc_jmp
1278
-- replace(s): instruction_code_reg
1279
 
1280
idc_jmp  <= '1' when instruction_code_reg_cml_1(15 downto 9)&instruction_code_reg_cml_1(3 downto 1) = "1001010110" else '0'; -- 1001010XXXXX110X
1281
 
1282
 
1283
-- SynEDA CoreMultiplier
1284
-- assignment(s): idc_ld_x
1285
-- replace(s): instruction_code_reg
1286
 
1287
-- LD,LDD 
1288
idc_ld_x <= '1' when instruction_code_reg_cml_1(15 downto 9)&instruction_code_reg_cml_1(3 downto 0) = "10010001100" or
1289
                     instruction_code_reg_cml_1(15 downto 9)&instruction_code_reg_cml_1(3 downto 0) = "10010001101"      or
1290
                                         instruction_code_reg_cml_1(15 downto 9)&instruction_code_reg_cml_1(3 downto 0) = "10010001110" else '0';
1291
 
1292
-- SynEDA CoreMultiplier
1293
-- assignment(s): idc_ld_y
1294
-- replace(s): instruction_code_reg
1295
 
1296
idc_ld_y <= '1' when (instruction_code_reg_cml_1(15 downto 9)&instruction_code_reg_cml_1(3 downto 0)="10010001001" or
1297
                                          instruction_code_reg_cml_1(15 downto 9)&instruction_code_reg_cml_1(3 downto 0)="10010001010") else '0';
1298
 
1299
-- SynEDA CoreMultiplier
1300
-- assignment(s): idc_ldd_y
1301
-- replace(s): instruction_code_reg
1302
 
1303
idc_ldd_y<= '1' when instruction_code_reg_cml_1(15 downto 14)&instruction_code_reg_cml_1(12)&instruction_code_reg_cml_1(9)&instruction_code_reg_cml_1(3) = "10001" else '0'; -- 10X0XX0XXXXX1XXX    
1304
 
1305
-- SynEDA CoreMultiplier
1306
-- assignment(s): idc_ld_z
1307
-- replace(s): instruction_code_reg
1308
 
1309
idc_ld_z <= '1' when (instruction_code_reg_cml_1(15 downto 9)&instruction_code_reg_cml_1(3 downto 0)="10010000001" or
1310
                                          instruction_code_reg_cml_1(15 downto 9)&instruction_code_reg_cml_1(3 downto 0)="10010000010") else '0';
1311
 
1312
-- SynEDA CoreMultiplier
1313
-- assignment(s): idc_ldd_z
1314
-- replace(s): instruction_code_reg
1315
 
1316
idc_ldd_z<= '1' when instruction_code_reg_cml_1(15 downto 14)&instruction_code_reg_cml_1(12)&instruction_code_reg_cml_1(9)&instruction_code_reg_cml_1(3) = "10000" else '0'; -- 10X0XX0XXXXX0XXX       
1317
-- ######
1318
 
1319
 
1320
idc_ldi <= '1' when instruction_code_reg(15 downto 12) = "1110" else '0'; -- 1110XXXXXXXXXXXX
1321
 
1322
-- SynEDA CoreMultiplier
1323
-- assignment(s): idc_lds
1324
-- replace(s): instruction_code_reg
1325
 
1326
idc_lds <= '1' when instruction_code_reg_cml_1(15 downto 9)&instruction_code_reg_cml_1(3 downto 0) = "10010000000" else '0'; -- 1001000XXXXX0000
1327
 
1328
-- SynEDA CoreMultiplier
1329
-- assignment(s): idc_lpm
1330
-- replace(s): instruction_code_reg
1331
 
1332
idc_lpm <= '1' when instruction_code_reg_cml_1 = "1001010111001000" else '0'; -- 1001010111001000
1333
 
1334
-- SynEDA CoreMultiplier
1335
-- assignment(s): idc_lsr
1336
-- replace(s): instruction_code_reg
1337
 
1338
idc_lsr <= '1' when instruction_code_reg_cml_1(15 downto 9)&instruction_code_reg_cml_1(3 downto 0) = "10010100110" else '0'; -- 1001010XXXXX0110
1339
 
1340
-- SynEDA CoreMultiplier
1341
-- assignment(s): idc_mov
1342
-- replace(s): instruction_code_reg
1343
 
1344
idc_mov <= '1' when instruction_code_reg_cml_1(15 downto 10) = "001011" else '0'; -- 001011XXXXXXXXXX
1345
 
1346
idc_mul <= '1' when instruction_code_reg(15 downto 10) = "100111" else '0'; -- 100111XXXXXXXXXX
1347
 
1348
-- SynEDA CoreMultiplier
1349
-- assignment(s): idc_neg
1350
-- replace(s): instruction_code_reg
1351
 
1352
idc_neg <= '1' when instruction_code_reg_cml_1(15 downto 9)&instruction_code_reg_cml_1(3 downto 0) = "10010100001" else '0'; -- 1001010XXXXX0001
1353
 
1354
idc_nop <= '1' when instruction_code_reg = "0000000000000000" else '0'; -- 0000000000000000
1355
 
1356
-- SynEDA CoreMultiplier
1357
-- assignment(s): idc_or
1358
-- replace(s): instruction_code_reg
1359
 
1360
idc_or  <= '1' when instruction_code_reg_cml_1(15 downto 10) = "001010" else '0'; -- 001010XXXXXXXXXX
1361
 
1362
idc_ori <= '1' when instruction_code_reg(15 downto 12) = "0110" else '0'; -- 0110XXXXXXXXXXXX 
1363
 
1364
idc_out <= '1' when instruction_code_reg(15 downto 11) = "10111" else '0'; -- 10111XXXXXXXXXXX
1365
 
1366
-- SynEDA CoreMultiplier
1367
-- assignment(s): idc_pop
1368
-- replace(s): instruction_code_reg
1369
 
1370
idc_pop <= '1' when instruction_code_reg_cml_1(15 downto 9)&instruction_code_reg_cml_1(3 downto 0) = "10010001111" else '0'; -- 1001000XXXXX1111
1371
 
1372
idc_push<= '1' when instruction_code_reg(15 downto 9)&instruction_code_reg(3 downto 0) = "10010011111" else '0'; -- 1001001XXXXX1111
1373
 
1374
idc_rcall<= '1' when instruction_code_reg(15 downto 12) = "1101" else '0'; -- 1101XXXXXXXXXXXX
1375
 
1376
-- SynEDA CoreMultiplier
1377
-- assignment(s): idc_ret
1378
-- replace(s): instruction_code_reg
1379
 
1380
idc_ret  <= '1' when instruction_code_reg_cml_1(15 downto 7)&instruction_code_reg_cml_1(4 downto 0) = "10010101001000" else '0'; -- 100101010XX01000
1381
 
1382
-- SynEDA CoreMultiplier
1383
-- assignment(s): idc_reti
1384
-- replace(s): instruction_code_reg
1385
 
1386
idc_reti <= '1' when instruction_code_reg_cml_1(15 downto 7)&instruction_code_reg_cml_1(4 downto 0) = "10010101011000" else '0'; -- 100101010XX11000
1387
 
1388
-- SynEDA CoreMultiplier
1389
-- assignment(s): idc_rjmp
1390
-- replace(s): instruction_code_reg
1391
 
1392
idc_rjmp <= '1' when instruction_code_reg_cml_1(15 downto 12) = "1100" else '0'; -- 1100XXXXXXXXXXXX
1393
 
1394
idc_ror  <= '1' when instruction_code_reg(15 downto 9)&instruction_code_reg(3 downto 0) = "10010100111" else '0'; -- 1001010XXXXX0111
1395
 
1396
idc_sbc  <= '1' when instruction_code_reg(15 downto 10) = "000010" else '0'; -- 000010XXXXXXXXXX
1397
 
1398
idc_sbci <= '1' when instruction_code_reg(15 downto 12) = "0100" else '0'; -- 0100XXXXXXXXXXXX
1399
 
1400
-- SynEDA CoreMultiplier
1401
-- assignment(s): idc_sbi
1402
-- replace(s): instruction_code_reg
1403
 
1404
idc_sbi  <= '1' when instruction_code_reg_cml_1(15 downto 8) = "10011010" else '0'; -- 10011010XXXXXXXX
1405
 
1406
-- SynEDA CoreMultiplier
1407
-- assignment(s): idc_sbic
1408
-- replace(s): instruction_code_reg
1409
 
1410
idc_sbic <= '1' when instruction_code_reg_cml_1(15 downto 8) = "10011001" else '0'; -- 10011001XXXXXXXX
1411
 
1412
-- SynEDA CoreMultiplier
1413
-- assignment(s): idc_sbis
1414
-- replace(s): instruction_code_reg
1415
 
1416
idc_sbis <= '1' when instruction_code_reg_cml_1(15 downto 8) = "10011011" else '0'; -- 10011011XXXXXXXX
1417
 
1418
idc_sbiw <= '1' when instruction_code_reg(15 downto 8) = "10010111" else '0'; -- 10010111XXXXXXXX
1419
 
1420
-- SynEDA CoreMultiplier
1421
-- assignment(s): idc_sbrc
1422
-- replace(s): instruction_code_reg
1423
 
1424
idc_sbrc <= '1' when instruction_code_reg_cml_1(15 downto 9) = "1111110" else '0'; -- 1111110XXXXXXXXX
1425
 
1426
-- SynEDA CoreMultiplier
1427
-- assignment(s): idc_sbrs
1428
-- replace(s): instruction_code_reg
1429
 
1430
idc_sbrs <= '1' when instruction_code_reg_cml_1(15 downto 9) = "1111111" else '0'; -- 1111111XXXXXXXXX
1431
 
1432
-- SynEDA CoreMultiplier
1433
-- assignment(s): idc_sleep
1434
-- replace(s): instruction_code_reg
1435
 
1436
idc_sleep<= '1' when instruction_code_reg_cml_2(15 downto 5)&instruction_code_reg_cml_2(3 downto 0) = "100101011001000" else '0'; -- 10010101100X1000
1437
 
1438
 
1439
-- ST,STD
1440
idc_st_x <= '1' when instruction_code_reg(15 downto 9)&instruction_code_reg(3 downto 0) = "10010011100" or
1441
                     instruction_code_reg(15 downto 9)&instruction_code_reg(3 downto 0) = "10010011101" or
1442
                     instruction_code_reg(15 downto 9)&instruction_code_reg(3 downto 0) = "10010011110" else '0';
1443
 
1444
idc_st_y <= '1' when (instruction_code_reg(15 downto 9)&instruction_code_reg(3 downto 0)="10010011001" or
1445
                                          instruction_code_reg(15 downto 9)&instruction_code_reg(3 downto 0)="10010011010") else '0';
1446
 
1447
idc_std_y<= '1' when instruction_code_reg(15 downto 14)&instruction_code_reg(12)&instruction_code_reg(9)&instruction_code_reg(3) = "10011" else '0'; -- 10X0XX1XXXXX1XXX    
1448
 
1449
idc_st_z <= '1' when (instruction_code_reg(15 downto 9)&instruction_code_reg(3 downto 0)="10010010001" or
1450
                                          instruction_code_reg(15 downto 9)&instruction_code_reg(3 downto 0)="10010010010") else '0';
1451
 
1452
idc_std_z<= '1' when instruction_code_reg(15 downto 14)&instruction_code_reg(12)&instruction_code_reg(9)&instruction_code_reg(3) = "10010" else '0'; -- 10X0XX1XXXXX0XXX 
1453
-- ######
1454
 
1455
idc_sts  <= '1' when instruction_code_reg(15 downto 9)&instruction_code_reg(3 downto 0) = "10010010000" else '0'; -- 1001001XXXXX0000
1456
 
1457
idc_sub  <= '1' when instruction_code_reg(15 downto 10) = "000110" else '0'; -- 000110XXXXXXXXXX
1458
 
1459
idc_subi <= '1' when instruction_code_reg(15 downto 12) = "0101" else '0'; -- 0101XXXXXXXXXXXX
1460
 
1461
-- SynEDA CoreMultiplier
1462
-- assignment(s): idc_swap
1463
-- replace(s): instruction_code_reg
1464
 
1465
idc_swap <= '1' when instruction_code_reg_cml_1(15 downto 9)&instruction_code_reg_cml_1(3 downto 0) = "10010100010" else '0'; -- 1001010XXXXX0010
1466
 
1467
-- SynEDA CoreMultiplier
1468
-- assignment(s): idc_wdr
1469
-- replace(s): instruction_code_reg
1470
 
1471
idc_wdr  <= '1' when instruction_code_reg_cml_2(15 downto 5)&instruction_code_reg_cml_2(3 downto 0) = "100101011011000" else '0'; -- 10010101101X1000
1472
 
1473
-- SynEDA CoreMultiplier
1474
-- assignment(s): idc_psinc
1475
-- replace(s): instruction_code_reg, idc_ld_x, idc_ld_y, idc_ld_z, idc_st_x, idc_st_y, idc_st_z
1476
 
1477
-- ADDITIONAL SIGNALS
1478
idc_psinc <= '1' when (instruction_code_reg_cml_2(1 downto 0) = "01" and
1479
 (idc_st_x_cml_2 or idc_st_y_cml_2 or idc_st_z_cml_2 or idc_ld_x_cml_2 or idc_ld_y_cml_2 or idc_ld_z_cml_2)='1') else '0';  -- POST INCREMENT FOR LD/ST INSTRUCTIONS
1480
 
1481
-- SynEDA CoreMultiplier
1482
-- assignment(s): idc_prdec
1483
-- replace(s): instruction_code_reg, idc_st_x, idc_st_y, idc_st_z
1484
 
1485
idc_prdec <= '1' when (instruction_code_reg_cml_1(1 downto 0)    = "10" and
1486
 (idc_st_x_cml_1 or idc_st_y_cml_1 or idc_st_z_cml_1 or idc_ld_x or idc_ld_y or idc_ld_z)='1') else '0';  -- PRE DECREMENT FOR LD/ST INSTRUCTIONS 
1487
 
1488
 
1489
-- ##########################################################################################################
1490
 
1491
-- SynEDA CoreMultiplier
1492
-- assignment(s): ramadr_reg_en
1493
-- replace(s): cpuwait, irq_st1, irq_st2, call_st1, call_st2, rcall_st1, icall_st1, ret_st1, reti_st1, idc_icall, idc_ld_x, idc_ld_y, idc_ldd_y, idc_ld_z, idc_ldd_z, idc_lds, idc_pop, idc_push, idc_rcall, idc_ret, idc_reti, idc_st_x, idc_st_y, idc_std_y, idc_st_z, idc_std_z, idc_sts
1494
 
1495
-- WRITE ENABLE SIGNALS FOR ramadr_reg
1496
ramadr_reg_en <= idc_ld_x_cml_2 or idc_ld_y_cml_2 or idc_ldd_y_cml_2 or idc_ld_z_cml_2 or idc_ldd_z_cml_2 or idc_lds_cml_2 or    -- LD/LDD/LDS(two cycle execution) 
1497
                 idc_st_x_cml_2 or idc_st_y_cml_2 or idc_std_y_cml_2 or idc_st_z_cml_2 or idc_std_z_cml_2 or idc_sts_cml_2 or    -- ST/STS/STS(two cycle execution)
1498
                                 idc_push_cml_2 or idc_pop_cml_2 or
1499
                                 idc_rcall_cml_2 or (rcall_st1_cml_2 and not cpuwait_cml_2) or idc_icall_cml_2 or (icall_st1_cml_2 and not cpuwait_cml_2) or -- RCALL/ICALL
1500
                                 call_st1_cml_2 or  (call_st2_cml_2 and not cpuwait_cml_2) or irq_st1_cml_2 or (irq_st2_cml_2 and not cpuwait_cml_2) or      -- CALL/IRQ
1501
                                 idc_ret_cml_2 or (ret_st1_cml_2 and not cpuwait_cml_2 ) or idc_reti_cml_2 or (reti_st1_cml_2 and not cpuwait_cml_2);            -- RET/RETI  -- ??
1502
 
1503
 
1504
-- SynEDA CoreMultiplier
1505
-- assignment(s): ramadr_reg_in
1506
-- replace(s): inst, cpuwait, reg_h_out, spl_out, sph_out, irq_st1, irq_st2, call_st1, call_st2, rcall_st1, icall_st1, ret_st1, reti_st1, dex_adr_disp, idc_icall, idc_ld_x, idc_ld_y, idc_ld_z, idc_lds, idc_pop, idc_push, idc_rcall, idc_ret, idc_reti, idc_st_x, idc_st_y, idc_st_z, idc_sts
1507
 
1508
-- RAMADR MUX
1509
ramadr_reg_in <= sph_out_cml_2&spl_out_cml_2 when
1510
  (idc_rcall_cml_2 or (rcall_st1_cml_2 and not cpuwait_cml_2)or idc_icall_cml_2 or (icall_st1_cml_2 and not cpuwait_cml_2)or  -- RCALL/ICALL
1511
   call_st1_cml_2  or (call_st2_cml_2 and not cpuwait_cml_2) or irq_st1_cml_2   or (irq_st2_cml_2 and not cpuwait_cml_2)  or  -- CALL/IRQ
1512
   idc_push_cml_2 )='1' else                                                                      -- PUSH
1513
   (sph_out_cml_2&spl_out_cml_2)+1 when (idc_ret_cml_2 or (ret_st1_cml_2 and not cpuwait_cml_2)  or idc_reti_cml_2  or (reti_st1_cml_2 and not cpuwait_cml_2) or idc_pop_cml_2)='1' else  -- RET/RETI/POP
1514
   inst_cml_2 when (idc_lds_cml_2 or idc_sts_cml_2) ='1' else     -- LDS/STS (two cycle execution)      
1515
   reg_h_out_cml_2 when (idc_ld_x_cml_2 or idc_ld_y_cml_2 or idc_ld_z_cml_2 or idc_st_x_cml_2 or idc_st_y_cml_2 or idc_st_z_cml_2)='1' else  -- LD/ST     
1516
   (reg_h_out_cml_2 + ("000000000"&dex_adr_disp_cml_2));                                                       -- LDD/STD  
1517
 
1518
 
1519
-- SynEDA CoreMultiplier
1520
-- assignment(s): ramadr_int
1521
-- replace(s): ramadr_int
1522
 
1523
-- ADDRESS REGISTER                                                             
1524
ramadr_reg:process(cp2,ireset)
1525
begin
1526
if ireset='0' then
1527
ramadr_int <= (others => '0');
1528
elsif(cp2='1' and cp2'event) then ramadr_int <= ramadr_int_cml_2;
1529
 if (cp2en='1') then                                                      -- Clock enable
1530
  if (ramadr_reg_en='1') then
1531
   ramadr_int <= ramadr_reg_in;
1532
  end if;
1533
 end if;
1534
end if;
1535
end process;
1536
 
1537
ramadr <= ramadr_int;
1538
 
1539
-- SynEDA CoreMultiplier
1540
-- assignment(s): reg_file_adr_space
1541
-- replace(s): reg_file_adr_space
1542
 
1543
-- GENERAL PURPOSE REGISTERS ADDRESSING FLAG FOR ST/STD/STS INSTRUCTIONS
1544
gp_reg_adr:process(cp2,ireset)
1545
begin
1546
if ireset='0' then
1547
reg_file_adr_space <='0';
1548
elsif(cp2='1' and cp2'event) then reg_file_adr_space <= reg_file_adr_space_cml_2;
1549
 if (cp2en='1') then                                                      -- Clock enable
1550
  if (ramadr_reg_en='1') then
1551
   if (ramadr_reg_in(15 downto 5)=const_ram_to_reg) then
1552
    reg_file_adr_space <= '1';                             -- ADRESS RANGE 0x0000-0x001F -> REGISTERS (R0-R31)
1553
   else
1554
    reg_file_adr_space <= '0';
1555
   end if;
1556
  end if;
1557
 end if;
1558
end if;
1559
end process;
1560
 
1561
-- SynEDA CoreMultiplier
1562
-- assignment(s): io_file_adr_space
1563
-- replace(s): io_file_adr_space
1564
 
1565
-- I/O REGISTERS ADDRESSING FLAG FOR ST/STD/STS INSTRUCTIONS
1566
io_reg_adr:process(cp2,ireset)
1567
begin
1568
if ireset='0' then io_file_adr_space<='0';
1569
elsif(cp2='1' and cp2'event) then io_file_adr_space <= io_file_adr_space_cml_2;
1570
 if (cp2en='1') then                                                      -- Clock enable
1571
  if (ramadr_reg_en='1') then
1572
   if (ramadr_reg_in(15 downto 5)=const_ram_to_io_a or ramadr_reg_in(15 downto 5)=const_ram_to_io_b) then
1573
    io_file_adr_space <= '1';                             -- ADRESS RANGE 0x0020-0x005F -> I/O PORTS (0x00-0x3F)
1574
   else
1575
    io_file_adr_space <= '0';
1576
   end if;
1577
  end if;
1578
 end if;
1579
end if;
1580
end process;
1581
 
1582
 
1583
 
1584
-- ##########################################################################################################
1585
 
1586
 
1587
-- REGRE/REGWE LOGIC (5 BIT ADDSRESS BUS (INTERNAL ONLY) 32 LOCATIONS (R0-R31))
1588
 
1589
-- SynEDA CoreMultiplier
1590
-- assignment(s): alu_reg_wr
1591
-- replace(s): adiw_st, sbiw_st, idc_adc, idc_adiw, idc_andi, idc_ori, idc_ror, idc_sbc, idc_sbci, idc_sbiw, idc_sub, idc_subi
1592
 
1593
-- WRITE ENABLE FOR Rd REGISTERS 
1594
alu_reg_wr <= idc_adc_cml_1 or idc_add or idc_adiw_cml_1 or adiw_st_cml_1 or idc_sub_cml_1 or idc_subi_cml_1 or idc_sbc_cml_1 or idc_sbci_cml_1 or
1595
              idc_sbiw_cml_1 or  sbiw_st_cml_1 or idc_and or idc_andi_cml_1 or idc_or or idc_ori_cml_1 or idc_eor or idc_com or
1596
                          idc_neg or idc_inc or idc_dec or idc_lsr or idc_ror_cml_1 or idc_asr or idc_swap;
1597
 
1598
 
1599
-- SynEDA CoreMultiplier
1600
-- assignment(s): reg_rd_wr
1601
-- replace(s): reg_file_adr_space, lpm_st2, sts_st, lds_st, st_st, ld_st, pop_st, idc_ldi
1602
 
1603
reg_rd_wr_cml_out <= idc_in or alu_reg_wr or idc_bld or             -- ALU INSTRUCTIONS + IN/BLD INSRTRUCTION                
1604
 (pop_st_cml_1 or ld_st_cml_1 or lds_st_cml_1)or                                            -- POP/LD/LDD/LDS INSTRUCTIONS
1605
 ((st_st_cml_1 or sts_st_cml_1) and reg_file_adr_space_cml_1)or              -- ST/STD/STS INSTRUCTION        
1606
  lpm_st2_cml_1 or idc_ldi_cml_1 or idc_mov;                            -- LPM/LDI/MOV INSTRUCTION
1607
 
1608
 
1609
  reg_rd_adr <= '1'&dex_adrreg_d(3 downto 0) when (idc_subi or idc_sbci or idc_andi or idc_ori or idc_cpi or idc_ldi)='1' else
1610
                           "00000" when lpm_st2='1' else
1611
               adiw_sbiw_encoder_out     when (idc_adiw or idc_sbiw)='1' else
1612
               adiw_sbiw_encoder_mux_out when (adiw_st or sbiw_st)='1' else
1613
                           dex_adrreg_d_latched      when (((st_st or sts_st) and not reg_file_adr_space) or ld_st or lds_st or pop_st)='1' else
1614
               ramadr_int(4 downto 0)    when ((st_st or sts_st) and reg_file_adr_space)='1'else --!!??
1615
                           dex_adrreg_d;
1616
 
1617
  reg_rd_adr_int <= '1'&dex_adrreg_d(3 downto 0) when (idc_subi or idc_sbci or idc_andi or idc_ori or idc_cpi or idc_ldi)='1' else
1618
                           "00000" when lpm_st2='1' else
1619
               adiw_sbiw_encoder_out     when (idc_adiw or idc_sbiw)='1' else
1620
               adiw_sbiw_encoder_mux_out when (adiw_st or sbiw_st)='1' else
1621
                           dex_adrreg_d_latched      when (((st_st or sts_st) and not reg_file_adr_space) or ld_st or lds_st or pop_st)='1' else
1622
               ramadr_int(4 downto 0)    when ((st_st or sts_st) and reg_file_adr_space)='1'else --!!??
1623
                           dex_adrreg_d;
1624
 
1625
reg_rr_adr <= ramadr_int(4 downto 0) when ((ld_st or lds_st) and reg_file_adr_space)='1'else --!!??
1626
                  dex_adrreg_d_latched   when ((st_st or sts_st) and reg_file_adr_space)='1'else --!!??
1627
                  dex_adrreg_r;
1628
 
1629
-- SynEDA CoreMultiplier
1630
-- assignment(s): reg_rd_in
1631
-- replace(s): dbusin, alu_data_out, reg_rr_out, reg_z_out, bld_op_out, reg_file_adr_space, lpm_st2, sts_st, lds_st, st_st, ld_st, pop_st, instruction_reg, dex_dat8_immed, gp_reg_tmp, idc_bld, idc_in, idc_ldi, idc_mov
1632
 
1633
-- MULTIPLEXER FOR REGISTER FILE Rd INPUT
1634
reg_rd_in_cml_out <= dbusin_cml_2 when (idc_in_cml_2 or ((lds_st_cml_2 or ld_st_cml_2)and not reg_file_adr_space_cml_2) or pop_st_cml_2)='1' else -- FROM INPUT DATA BUS
1635
                         reg_rr_out_cml_2 when ((lds_st_cml_2 or ld_st_cml_2)  and reg_file_adr_space_cml_2)='1' else
1636
             gp_reg_tmp_cml_2 when ((st_st_cml_2 or sts_st_cml_2)  and reg_file_adr_space_cml_2)='1' else -- ST/STD/STS &  ADDRESS FROM 0 TO 31 (REGISTER FILE)
1637
                         bld_op_out_cml_2 when (idc_bld_cml_2='1')else                                     -- FROM BIT PROCESSOR BLD COMMAND
1638
             reg_rr_out_cml_2 when (idc_mov_cml_2='1')else                                     -- FOR MOV INSTRUCTION 
1639
                         instruction_reg_cml_2(15 downto 8) when (lpm_st2_cml_2='1' and reg_z_out_cml_2(0)='1') else -- LPM/ELPM
1640
                         instruction_reg_cml_2(7 downto 0) when  (lpm_st2_cml_2='1' and reg_z_out_cml_2(0)='0') else -- LPM/ELPM
1641
             dex_dat8_immed_cml_2 when idc_ldi_cml_2='1' else
1642
                         alu_data_out_cml_2;                                               -- FROM ALU DATA OUT
1643
 
1644
-- SynEDA CoreMultiplier
1645
-- assignment(s): iowe_int
1646
-- replace(s): io_file_adr_space, sts_st, st_st, sbi_st, cbi_st, idc_out
1647
 
1648
-- SynEDA CoreMultiplier
1649
-- assignment(s): iore_int
1650
-- replace(s): io_file_adr_space, lds_st, ld_st
1651
 
1652
-- IORE/IOWE LOGIC (6 BIT ADDRESS adr[5..0] FOR I/O PORTS(64 LOCATIONS))
1653
iore_int <= idc_in or idc_sbi or idc_cbi or idc_sbic or idc_sbis or ((ld_st_cml_1 or lds_st_cml_1) and io_file_adr_space_cml_1);   -- IN/SBI/CBI 
1654
iowe_int <= '1' when ((idc_out_cml_2 or sbi_st_cml_2 or cbi_st_cml_2) or
1655
                     ((st_st_cml_2 or sts_st_cml_2) and io_file_adr_space_cml_2))='1' else '0'; -- OUT/SBI/CBI + !! ST/STS/STD
1656
 
1657
 
1658
-- SynEDA CoreMultiplier
1659
-- assignment(s): adr_int
1660
-- replace(s): sbi_st, cbi_st, ramadr_int, cbi_sbi_io_adr_tmp, idc_out
1661
 
1662
-- adr[5..0] BUS MULTIPLEXER
1663
adr_int <= dex_adr6port when (idc_in or idc_out_cml_1) = '1' else                          -- IN/OUT INSTRUCTIONS  
1664
           '0'&dex_adr5port when (idc_cbi or idc_sbi or idc_sbic or idc_sbis) ='1'    else  -- CBI/SBI (READ PHASE) + SBIS/SBIC
1665
                   '0'&cbi_sbi_io_adr_tmp_cml_1 when (cbi_st_cml_1 or sbi_st_cml_1)='1' else     -- CBI/SBI (WRITE PHASE)
1666
                    ramadr_int_cml_1(6)&ramadr_int_cml_1(4 downto 0);                                                   -- LD/LDS/LDD/ST/STS/STD
1667
 
1668
-- ramre LOGIC (16 BIT ADDRESS ramadr[15..0] FOR DATA RAM (64*1024-64-32 LOCATIONS))
1669
--ramre_int <= not(reg_file_adr_space or io_file_adr_space) and 
1670
--            (ld_st or lds_st2 or pop_st or                    -- LD/LDD/LDS/POP/
1671
--             ret_st1 or ret_st2 or reti_st1 or reti_st2);     -- RET/RETI
1672
 
1673
-- SynEDA CoreMultiplier
1674
-- assignment(s): ramre_int
1675
-- replace(s): cpuwait, ret_st2, reti_st2, lds_st, ld_st, pop_st, ramre_int, idc_ld_x, idc_ld_y, idc_ldd_y, idc_ld_z, idc_ldd_z, idc_lds, idc_pop, idc_ret, idc_reti
1676
 
1677
DataMemoryRead:process(cp2,ireset)
1678
begin
1679
if ireset='0' then -- Reset
1680
 ramre_int <= '0';
1681
elsif (cp2='1' and cp2'event) then ramre_int <= ramre_int_cml_2; -- Clock
1682
 if (cp2en='1') then                                                      -- Clock enable       
1683
  case ramre_int_cml_2 is
1684
   when '0' =>
1685
    if(ramadr_reg_in(15 downto 5)/=const_ram_to_io_a and
1686
           ramadr_reg_in(15 downto 5)/=const_ram_to_io_b and
1687
       ramadr_reg_in(15 downto 5)/=const_ram_to_reg  and
1688
      (idc_ld_x_cml_2 or idc_ld_y_cml_2 or idc_ldd_y_cml_2 or idc_ld_z_cml_2 or idc_ldd_z_cml_2 or  -- LD/LDD instruction       
1689
           idc_lds_cml_2 or                                                     -- LDS instruction(two cycle execution)
1690
           idc_pop_cml_2 or                                                     -- POP instruction
1691
       idc_ret_cml_2 or                                                         -- RET instruction 
1692
           idc_reti_cml_2)='1')                                                                                                     -- RETI instruction 
1693
           then ramre_int <='1';
1694
    end if;
1695
   when '1' =>
1696
    if ((ld_st_cml_2 or lds_st_cml_2 or pop_st_cml_2 or ret_st2_cml_2 or reti_st2_cml_2)and not cpuwait_cml_2)='1' then
1697
     ramre_int <='0';
1698
    end if;
1699
   when others  =>      null;
1700
  end case;
1701
 end if;
1702
end if;
1703
end process;
1704
 
1705
-- ramwe LOGIC (16 BIT ADDRESS ramadr[15..0] FOR DATA RAM (64*1024-64-32 LOCATIONS))
1706
--ramwe_int <= not(reg_file_adr_space or io_file_adr_space) and 
1707
--            (st_st or sts_st2 or push_st or rcall_st1 or rcall_st2 or -- ST/STD/STS/PUSH/RCALL
1708
--                                                      icall_st1 or icall_st2 or -- ICALL
1709
--                                                      call_st2 or call_st3 or   -- CALL
1710
--                                                                                      irq_st2 or irq_st3);      -- INTERRUPT
1711
 
1712
-- SynEDA CoreMultiplier
1713
-- assignment(s): ramwe_int
1714
-- replace(s): cpuwait, irq_st1, irq_st3, call_st1, call_st3, rcall_st2, icall_st2, sts_st, st_st, push_st, ramwe_int, idc_icall, idc_push, idc_rcall, idc_st_x, idc_st_y, idc_std_y, idc_st_z, idc_std_z, idc_sts
1715
 
1716
DataMemoryWrite:process(cp2,ireset)
1717
begin
1718
if ireset='0' then -- Reset
1719
 ramwe_int <= '0';
1720
elsif (cp2='1' and cp2'event) then ramwe_int <= ramwe_int_cml_2; -- Clock
1721
 if (cp2en='1') then                                                      -- Clock enable
1722
  case ramwe_int_cml_2 is
1723
   when '0' =>
1724
    if(ramadr_reg_in(15 downto 5)/=const_ram_to_io_a and
1725
           ramadr_reg_in(15 downto 5)/=const_ram_to_io_b and
1726
       ramadr_reg_in(15 downto 5)/=const_ram_to_reg  and
1727
      (idc_st_x_cml_2 or idc_st_y_cml_2 or idc_std_y_cml_2 or idc_st_z_cml_2 or idc_std_z_cml_2 or  -- ST/STD instruction       
1728
           idc_sts_cml_2 or                                                     -- STS instruction (two cycle execution)        
1729
           idc_push_cml_2 or                                                    -- PUSH instruction
1730
           idc_rcall_cml_2 or                                                                                                     -- RCALL instruction
1731
           idc_icall_cml_2 or                                                                                                     -- ICALL instruction
1732
           call_st1_cml_2 or                                                    -- CALL instruction
1733
           irq_st1_cml_2)='1')                                                  -- Interrupt  
1734
          then ramwe_int <='1';
1735
    end if;
1736
   when '1' =>
1737
    if ((st_st_cml_2 or sts_st_cml_2 or push_st_cml_2 or rcall_st2_cml_2 or
1738
             icall_st2_cml_2 or call_st3_cml_2 or irq_st3_cml_2)and not cpuwait_cml_2)='1' then ramwe_int <='0';
1739
    end if;
1740
   when others  =>      null;
1741
  end case;
1742
end if;
1743
end if;
1744
end process;
1745
 
1746
-- DBUSOUT MULTIPLEXER
1747
--dbusout_mux_logic: for i in dbusout_int'range generate
1748
--dbusout_int(i)<= (reg_rd_out(i) and (idc_push or idc_sts or
1749
--                 (idc_st_x or idc_st_y or idc_std_y or idc_st_z or idc_std_z)))or      -- PUSH/ST/STD/STS INSTRUCTIONS
1750
--                               (gp_reg_tmp(i) and (st_st or sts_st))or                            -- NEW
1751
--                               (bitpr_io_out(i) and (cbi_st or sbi_st))or                          -- CBI/SBI  INSTRUCTIONS
1752
--                 (program_counter(i)         and (idc_rcall or idc_icall or call_st1))or                        -- LOW  PART OF PC                 (program_counter_high_fr(i) and (rcall_st1 or icall_st1 or call_st2))or                        -- HIGH PART OF PC
1753
--                 (pc_for_interrupt(i) and irq_st1) or
1754
--                               (pc_for_interrupt(8) and irq_st2) or
1755
--                               (reg_rd_out(i) and  idc_out); -- OUT
1756
--end generate;
1757
 
1758
dbusout_int(0)<= (reg_rd_out_cml_2(0) and (idc_push_cml_2 or idc_sts_cml_2 or
1759
                 (idc_st_x_cml_2 or idc_st_y_cml_2 or idc_std_y_cml_2 or idc_st_z_cml_2 or idc_std_z_cml_2)))or      -- PUSH/ST/STD/STS INSTRUCTIONS
1760
                                 (gp_reg_tmp_cml_2(0) and (st_st_cml_2 or sts_st_cml_2))or                            -- NEW
1761
                                 (bitpr_io_out_cml_2(0) and (cbi_st_cml_2 or sbi_st_cml_2))or                          -- CBI/SBI  INSTRUCTIONS
1762
                 (program_counter_cml_2(0)         and (idc_rcall_cml_2 or idc_icall_cml_2 or call_st1_cml_2))or                        -- LOW  PART OF PC
1763
                 (program_counter_high_fr_cml_2(0) and (rcall_st1_cml_2 or icall_st1_cml_2 or call_st2_cml_2))or                        -- HIGH PART OF PC
1764
                 (pc_for_interrupt_cml_2(0) and irq_st1_cml_2) or
1765
                                 (pc_for_interrupt_cml_2(8) and irq_st2_cml_2) or
1766
                                 (reg_rd_out_cml_2(0) and  idc_out_cml_2); -- OUT
1767
 
1768
dbusout_int(1)<= (reg_rd_out_cml_2(1) and (idc_push_cml_2 or idc_sts_cml_2 or
1769
                 (idc_st_x_cml_2 or idc_st_y_cml_2 or idc_std_y_cml_2 or idc_st_z_cml_2 or idc_std_z_cml_2)))or      -- PUSH/ST/STD/STS INSTRUCTIONS
1770
                                 (gp_reg_tmp_cml_2(1) and (st_st_cml_2 or sts_st_cml_2))or                            -- NEW
1771
                                 (bitpr_io_out_cml_2(1) and (cbi_st_cml_2 or sbi_st_cml_2))or                          -- CBI/SBI  INSTRUCTIONS
1772
                 (program_counter_cml_2(1)         and (idc_rcall_cml_2 or idc_icall_cml_2 or call_st1_cml_2))or                        -- LOW  PART OF PC
1773
                 (program_counter_high_fr_cml_2(1) and (rcall_st1_cml_2 or icall_st1_cml_2 or call_st2_cml_2))or                        -- HIGH PART OF PC
1774
                 (pc_for_interrupt_cml_2(1) and irq_st1_cml_2) or
1775
                                 (pc_for_interrupt_cml_2(9) and irq_st2_cml_2) or
1776
                                 (reg_rd_out_cml_2(1) and  idc_out_cml_2); -- OUT
1777
 
1778
dbusout_int(2)<= (reg_rd_out_cml_2(2) and (idc_push_cml_2 or idc_sts_cml_2 or
1779
                 (idc_st_x_cml_2 or idc_st_y_cml_2 or idc_std_y_cml_2 or idc_st_z_cml_2 or idc_std_z_cml_2)))or      -- PUSH/ST/STD/STS INSTRUCTIONS
1780
                                 (gp_reg_tmp_cml_2(2) and (st_st_cml_2 or sts_st_cml_2))or                            -- NEW
1781
                                 (bitpr_io_out_cml_2(2) and (cbi_st_cml_2 or sbi_st_cml_2))or                          -- CBI/SBI  INSTRUCTIONS
1782
                 (program_counter_cml_2(2)         and (idc_rcall_cml_2 or idc_icall_cml_2 or call_st1_cml_2))or                        -- LOW  PART OF PC
1783
                 (program_counter_high_fr_cml_2(2) and (rcall_st1_cml_2 or icall_st1_cml_2 or call_st2_cml_2))or                        -- HIGH PART OF PC
1784
                 (pc_for_interrupt_cml_2(2) and irq_st1_cml_2) or
1785
                                 (pc_for_interrupt_cml_2(10) and irq_st2_cml_2) or
1786
                                 (reg_rd_out_cml_2(2) and  idc_out_cml_2); -- OUT
1787
 
1788
dbusout_int(3)<= (reg_rd_out_cml_2(3) and (idc_push_cml_2 or idc_sts_cml_2 or
1789
                 (idc_st_x_cml_2 or idc_st_y_cml_2 or idc_std_y_cml_2 or idc_st_z_cml_2 or idc_std_z_cml_2)))or      -- PUSH/ST/STD/STS INSTRUCTIONS
1790
                                 (gp_reg_tmp_cml_2(3) and (st_st_cml_2 or sts_st_cml_2))or                            -- NEW
1791
                                 (bitpr_io_out_cml_2(3) and (cbi_st_cml_2 or sbi_st_cml_2))or                          -- CBI/SBI  INSTRUCTIONS
1792
                 (program_counter_cml_2(3)         and (idc_rcall_cml_2 or idc_icall_cml_2 or call_st1_cml_2))or                        -- LOW  PART OF PC
1793
                 (program_counter_high_fr_cml_2(3) and (rcall_st1_cml_2 or icall_st1_cml_2 or call_st2_cml_2))or                        -- HIGH PART OF PC
1794
                 (pc_for_interrupt_cml_2(3) and irq_st1_cml_2) or
1795
                                 (pc_for_interrupt_cml_2(11) and irq_st2_cml_2) or
1796
                                 (reg_rd_out_cml_2(3) and  idc_out_cml_2); -- OUT
1797
 
1798
dbusout_int(4)<= (reg_rd_out_cml_2(4) and (idc_push_cml_2 or idc_sts_cml_2 or
1799
                 (idc_st_x_cml_2 or idc_st_y_cml_2 or idc_std_y_cml_2 or idc_st_z_cml_2 or idc_std_z_cml_2)))or      -- PUSH/ST/STD/STS INSTRUCTIONS
1800
                                 (gp_reg_tmp_cml_2(4) and (st_st_cml_2 or sts_st_cml_2))or                            -- NEW
1801
                                 (bitpr_io_out_cml_2(4) and (cbi_st_cml_2 or sbi_st_cml_2))or                          -- CBI/SBI  INSTRUCTIONS
1802
                 (program_counter_cml_2(4)         and (idc_rcall_cml_2 or idc_icall_cml_2 or call_st1_cml_2))or                        -- LOW  PART OF PC
1803
                 (program_counter_high_fr_cml_2(4) and (rcall_st1_cml_2 or icall_st1_cml_2 or call_st2_cml_2))or                        -- HIGH PART OF PC
1804
                 (pc_for_interrupt_cml_2(4) and irq_st1_cml_2) or
1805
                                 (pc_for_interrupt_cml_2(12) and irq_st2_cml_2) or
1806
                                 (reg_rd_out_cml_2(4) and  idc_out_cml_2); -- OUT
1807
 
1808
dbusout_int(5)<= (reg_rd_out_cml_2(5) and (idc_push_cml_2 or idc_sts_cml_2 or
1809
                 (idc_st_x_cml_2 or idc_st_y_cml_2 or idc_std_y_cml_2 or idc_st_z_cml_2 or idc_std_z_cml_2)))or      -- PUSH/ST/STD/STS INSTRUCTIONS
1810
                                 (gp_reg_tmp_cml_2(5) and (st_st_cml_2 or sts_st_cml_2))or                            -- NEW
1811
                                 (bitpr_io_out_cml_2(5) and (cbi_st_cml_2 or sbi_st_cml_2))or                          -- CBI/SBI  INSTRUCTIONS
1812
                 (program_counter_cml_2(5)         and (idc_rcall_cml_2 or idc_icall_cml_2 or call_st1_cml_2))or                        -- LOW  PART OF PC
1813
                 (program_counter_high_fr_cml_2(5) and (rcall_st1_cml_2 or icall_st1_cml_2 or call_st2_cml_2))or                        -- HIGH PART OF PC
1814
                 (pc_for_interrupt_cml_2(5) and irq_st1_cml_2) or
1815
                                 (pc_for_interrupt_cml_2(13) and irq_st2_cml_2) or
1816
                                 (reg_rd_out_cml_2(5) and  idc_out_cml_2); -- OUT
1817
 
1818
dbusout_int(6)<= (reg_rd_out_cml_2(6) and (idc_push_cml_2 or idc_sts_cml_2 or
1819
                 (idc_st_x_cml_2 or idc_st_y_cml_2 or idc_std_y_cml_2 or idc_st_z_cml_2 or idc_std_z_cml_2)))or      -- PUSH/ST/STD/STS INSTRUCTIONS
1820
                                 (gp_reg_tmp_cml_2(6) and (st_st_cml_2 or sts_st_cml_2))or                            -- NEW
1821
                                 (bitpr_io_out_cml_2(6) and (cbi_st_cml_2 or sbi_st_cml_2))or                          -- CBI/SBI  INSTRUCTIONS
1822
                 (program_counter_cml_2(6)         and (idc_rcall_cml_2 or idc_icall_cml_2 or call_st1_cml_2))or                        -- LOW  PART OF PC
1823
                 (program_counter_high_fr_cml_2(6) and (rcall_st1_cml_2 or icall_st1_cml_2 or call_st2_cml_2))or                        -- HIGH PART OF PC
1824
                 (pc_for_interrupt_cml_2(6) and irq_st1_cml_2) or
1825
                                 (pc_for_interrupt_cml_2(14) and irq_st2_cml_2) or
1826
                                 (reg_rd_out_cml_2(6) and  idc_out_cml_2); -- OUT
1827
 
1828
-- SynEDA CoreMultiplier
1829
-- assignment(s): dbusout_int
1830
-- replace(s): reg_rd_out, bitpr_io_out, program_counter, program_counter_high_fr, irq_st1, irq_st2, call_st1, call_st2, rcall_st1, icall_st1, sts_st, st_st, sbi_st, cbi_st, pc_for_interrupt, gp_reg_tmp, idc_icall, idc_out, idc_push, idc_rcall, idc_st_x, idc_st_y, idc_std_y, idc_st_z, idc_std_z, idc_sts
1831
 
1832
dbusout_int(7)<= (reg_rd_out_cml_2(7) and (idc_push_cml_2 or idc_sts_cml_2 or
1833
                 (idc_st_x_cml_2 or idc_st_y_cml_2 or idc_std_y_cml_2 or idc_st_z_cml_2 or idc_std_z_cml_2)))or      -- PUSH/ST/STD/STS INSTRUCTIONS
1834
                                 (gp_reg_tmp_cml_2(7) and (st_st_cml_2 or sts_st_cml_2))or                            -- NEW
1835
                                 (bitpr_io_out_cml_2(7) and (cbi_st_cml_2 or sbi_st_cml_2))or                          -- CBI/SBI  INSTRUCTIONS
1836
                 (program_counter_cml_2(7)         and (idc_rcall_cml_2 or idc_icall_cml_2 or call_st1_cml_2))or                        -- LOW  PART OF PC
1837
                 (program_counter_high_fr_cml_2(7) and (rcall_st1_cml_2 or icall_st1_cml_2 or call_st2_cml_2))or                        -- HIGH PART OF PC
1838
                 (pc_for_interrupt_cml_2(7) and irq_st1_cml_2) or
1839
                                 (pc_for_interrupt_cml_2(15) and irq_st2_cml_2) or
1840
                                 (reg_rd_out_cml_2(7) and  idc_out_cml_2); -- OUT
1841
 
1842
dbusout_int_route <= dbusout_int;
1843
 
1844
dbusout(0)<= (reg_rd_out_int(0) and (idc_push or idc_sts or
1845
                 (idc_st_x or idc_st_y or idc_std_y or idc_st_z or idc_std_z)))or      -- PUSH/ST/STD/STS INSTRUCTIONS
1846
                                 (gp_reg_tmp(0) and (st_st or sts_st))or                            -- NEW
1847
                                 (bitpr_io_out(0) and (cbi_st or sbi_st))or                          -- CBI/SBI  INSTRUCTIONS
1848
                 (program_counter(0)         and (idc_rcall or idc_icall or call_st1))or                        -- LOW  PART OF PC
1849
                 (program_counter_high_fr(0) and (rcall_st1 or icall_st1 or call_st2))or                        -- HIGH PART OF PC
1850
                 (pc_for_interrupt(0) and irq_st1) or
1851
                                 (pc_for_interrupt(8) and irq_st2) or
1852
                                 (reg_rd_out_int(0) and  idc_out); -- OUT
1853
 
1854
dbusout(1)<= (reg_rd_out_int(1) and (idc_push or idc_sts or
1855
                 (idc_st_x or idc_st_y or idc_std_y or idc_st_z or idc_std_z)))or      -- PUSH/ST/STD/STS INSTRUCTIONS
1856
                                 (gp_reg_tmp(1) and (st_st or sts_st))or                            -- NEW
1857
                                 (bitpr_io_out(1) and (cbi_st or sbi_st))or                          -- CBI/SBI  INSTRUCTIONS
1858
                 (program_counter(1)         and (idc_rcall or idc_icall or call_st1))or                        -- LOW  PART OF PC
1859
                 (program_counter_high_fr(1) and (rcall_st1 or icall_st1 or call_st2))or                        -- HIGH PART OF PC
1860
                 (pc_for_interrupt(1) and irq_st1) or
1861
                                 (pc_for_interrupt(9) and irq_st2) or
1862
                                 (reg_rd_out_int(1) and  idc_out); -- OUT
1863
 
1864
dbusout(2)<= (reg_rd_out_int(2) and (idc_push or idc_sts or
1865
                 (idc_st_x or idc_st_y or idc_std_y or idc_st_z or idc_std_z)))or      -- PUSH/ST/STD/STS INSTRUCTIONS
1866
                                 (gp_reg_tmp(2) and (st_st or sts_st))or                            -- NEW
1867
                                 (bitpr_io_out(2) and (cbi_st or sbi_st))or                          -- CBI/SBI  INSTRUCTIONS
1868
                 (program_counter(2)         and (idc_rcall or idc_icall or call_st1))or                        -- LOW  PART OF PC
1869
                 (program_counter_high_fr(2) and (rcall_st1 or icall_st1 or call_st2))or                        -- HIGH PART OF PC
1870
                 (pc_for_interrupt(2) and irq_st1) or
1871
                                 (pc_for_interrupt(10) and irq_st2) or
1872
                                 (reg_rd_out_int(2) and  idc_out); -- OUT
1873
 
1874
dbusout(3)<= (reg_rd_out_int(3) and (idc_push or idc_sts or
1875
                 (idc_st_x or idc_st_y or idc_std_y or idc_st_z or idc_std_z)))or      -- PUSH/ST/STD/STS INSTRUCTIONS
1876
                                 (gp_reg_tmp(3) and (st_st or sts_st))or                            -- NEW
1877
                                 (bitpr_io_out(3) and (cbi_st or sbi_st))or                          -- CBI/SBI  INSTRUCTIONS
1878
                 (program_counter(3)         and (idc_rcall or idc_icall or call_st1))or                        -- LOW  PART OF PC
1879
                 (program_counter_high_fr(3) and (rcall_st1 or icall_st1 or call_st2))or                        -- HIGH PART OF PC
1880
                 (pc_for_interrupt(3) and irq_st1) or
1881
                                 (pc_for_interrupt(11) and irq_st2) or
1882
                                 (reg_rd_out_int(3) and  idc_out); -- OUT
1883
 
1884
dbusout(4)<= (reg_rd_out_int(4) and (idc_push or idc_sts or
1885
                 (idc_st_x or idc_st_y or idc_std_y or idc_st_z or idc_std_z)))or      -- PUSH/ST/STD/STS INSTRUCTIONS
1886
                                 (gp_reg_tmp(4) and (st_st or sts_st))or                            -- NEW
1887
                                 (bitpr_io_out(4) and (cbi_st or sbi_st))or                          -- CBI/SBI  INSTRUCTIONS
1888
                 (program_counter(4)         and (idc_rcall or idc_icall or call_st1))or                        -- LOW  PART OF PC
1889
                 (program_counter_high_fr(4) and (rcall_st1 or icall_st1 or call_st2))or                        -- HIGH PART OF PC
1890
                 (pc_for_interrupt(4) and irq_st1) or
1891
                                 (pc_for_interrupt(12) and irq_st2) or
1892
                                 (reg_rd_out_int(4) and  idc_out); -- OUT
1893
 
1894
dbusout(5)<= (reg_rd_out_int(5) and (idc_push or idc_sts or
1895
                 (idc_st_x or idc_st_y or idc_std_y or idc_st_z or idc_std_z)))or      -- PUSH/ST/STD/STS INSTRUCTIONS
1896
                                 (gp_reg_tmp(5) and (st_st or sts_st))or                            -- NEW
1897
                                 (bitpr_io_out(5) and (cbi_st or sbi_st))or                          -- CBI/SBI  INSTRUCTIONS
1898
                 (program_counter(5)         and (idc_rcall or idc_icall or call_st1))or                        -- LOW  PART OF PC
1899
                 (program_counter_high_fr(5) and (rcall_st1 or icall_st1 or call_st2))or                        -- HIGH PART OF PC
1900
                 (pc_for_interrupt(5) and irq_st1) or
1901
                                 (pc_for_interrupt(13) and irq_st2) or
1902
                                 (reg_rd_out_int(5) and  idc_out); -- OUT
1903
 
1904
dbusout(6)<= (reg_rd_out_int(6) and (idc_push or idc_sts or
1905
                 (idc_st_x or idc_st_y or idc_std_y or idc_st_z or idc_std_z)))or      -- PUSH/ST/STD/STS INSTRUCTIONS
1906
                                 (gp_reg_tmp(6) and (st_st or sts_st))or                            -- NEW
1907
                                 (bitpr_io_out(6) and (cbi_st or sbi_st))or                          -- CBI/SBI  INSTRUCTIONS
1908
                 (program_counter(6)         and (idc_rcall or idc_icall or call_st1))or                        -- LOW  PART OF PC
1909
                 (program_counter_high_fr(6) and (rcall_st1 or icall_st1 or call_st2))or                        -- HIGH PART OF PC
1910
                 (pc_for_interrupt(6) and irq_st1) or
1911
                                 (pc_for_interrupt(14) and irq_st2) or
1912
                                 (reg_rd_out_int(6) and  idc_out); -- OUT
1913
 
1914
dbusout(7)<= (reg_rd_out_int(7) and (idc_push or idc_sts or
1915
                 (idc_st_x or idc_st_y or idc_std_y or idc_st_z or idc_std_z)))or      -- PUSH/ST/STD/STS INSTRUCTIONS
1916
                                 (gp_reg_tmp(7) and (st_st or sts_st))or                            -- NEW
1917
                                 (bitpr_io_out(7) and (cbi_st or sbi_st))or                          -- CBI/SBI  INSTRUCTIONS
1918
                 (program_counter(7)         and (idc_rcall or idc_icall or call_st1))or                        -- LOW  PART OF PC
1919
                 (program_counter_high_fr(7) and (rcall_st1 or icall_st1 or call_st2))or                        -- HIGH PART OF PC
1920
                 (pc_for_interrupt(7) and irq_st1) or
1921
                                 (pc_for_interrupt(15) and irq_st2) or
1922
                                 (reg_rd_out_int(7) and  idc_out); -- OUT
1923
 
1924
 
1925
-- ALU CONNECTION
1926
 
1927
-- ALU Rr INPUT MUX
1928
alu_data_r_in <= dex_dat8_immed       when (idc_subi or idc_sbci or idc_andi or idc_ori or idc_cpi)='1' else
1929
                 "00"&dex_dat6_immed  when (idc_adiw or idc_sbiw) ='1' else
1930
                 "00000000"           when (adiw_st or sbiw_st) ='1' else
1931
                 reg_rr_out;
1932
 
1933
 
1934
-- SynEDA CoreMultiplier
1935
-- assignment(s): gp_reg_tmp
1936
-- replace(s): reg_rd_out, gp_reg_tmp, idc_st_x, idc_st_y, idc_std_y, idc_st_z, idc_std_z, idc_sts
1937
 
1938
-- gp_reg_tmp STORES TEMPREOARY THE VALUE OF SOURCE REGISTER DURING ST/STD/STS INSTRUCTION
1939
gp_registers_trig:process(cp2,ireset)
1940
begin
1941
if (ireset='0') then
1942
gp_reg_tmp <= (others=>'0');
1943
elsif (cp2='1' and cp2'event) then gp_reg_tmp <= gp_reg_tmp_cml_2;
1944
 if (cp2en='1') then                                                      -- Clock enable
1945
  -- if ((idc_st_x or idc_st_y or idc_std_y or idc_st_z or idc_std_z) or sts_st1)='1' then  -- CLOCK ENABLE
1946
  if ((idc_st_x_cml_2 or idc_st_y_cml_2 or idc_std_y_cml_2 or idc_st_z_cml_2 or idc_std_z_cml_2) or idc_sts_cml_2)='1' then  -- CLOCK ENABLE
1947
     gp_reg_tmp <= reg_rd_out_cml_2;
1948
  end if;
1949
 end if;
1950
end if;
1951
end process;
1952
 
1953
-- **********************************************************************************************************
1954
 
1955
-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1956
-- +++++++++++++++++++++++++++++++++++++++ PROGRAM COUNTER ++++++++++++++++++++++++++++++++++++++++++++++++++
1957
-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1958
 
1959
-- SynEDA CoreMultiplier
1960
-- assignment(s): program_counter_high_fr
1961
-- replace(s): program_counter, program_counter_high_fr, irq_st1, call_st1, idc_icall, idc_rcall
1962
 
1963
program_counter_high_store:process(cp2,ireset)
1964
begin
1965
if ireset='0' then                         -- RESET
1966
program_counter_high_fr <=(others => '0');
1967
elsif (cp2='1' and cp2'event) then program_counter_high_fr <= program_counter_high_fr_cml_2;       -- CLOCK
1968
 if (cp2en='1') then                                                      -- Clock enable
1969
  if (idc_rcall_cml_2 or idc_icall_cml_2 or call_st1_cml_2 or irq_st1_cml_2) ='1' then
1970
   program_counter_high_fr <= program_counter_cml_2(15 downto 8);       -- STORE HIGH BYTE OF THE PROGRAMM COUNTER FOR RCALL/ICALL/CALL INSTRUCTIONS AND INTERRUPTS   
1971
  end if;
1972
 end if;
1973
end if;
1974
end process;
1975
 
1976
 
1977
-- SynEDA CoreMultiplier
1978
-- assignment(s): program_counter_tmp
1979
-- replace(s): program_counter_tmp, program_counter, idc_lpm
1980
 
1981
program_counter_for_lpm_elpm:process(cp2,ireset)
1982
begin
1983
if ireset='0' then                         -- RESET
1984
program_counter_tmp<=(others => '0');
1985
elsif (cp2='1' and cp2'event) then program_counter_tmp <= program_counter_tmp_cml_2;       -- CLOCK
1986
 if (cp2en='1') then                                                      -- Clock enable
1987
  if (idc_lpm_cml_2 or idc_elpm) ='1' then
1988
   program_counter_tmp <= program_counter_cml_2;
1989
  end if;
1990
 end if;
1991
end if;
1992
end process;
1993
 
1994
-- SynEDA CoreMultiplier
1995
-- assignment(s): pa15_pm
1996
-- replace(s): rampz_out
1997
 
1998
pa15_pm <= rampz_out_cml_2(0) and idc_elpm; -- '0' WHEN LPM INSTRUCTIONS  RAMPZ(0) WHEN ELPM INSTRUCTION
1999
 
2000
-- OFFSET FOR BRBC/BRBS INSTRUCTIONS +63/-64
2001
offset_brbx <= "0000000000"&dex_brxx_offset(5 downto 0) when (dex_brxx_offset(6)='0') else -- +
2002
               "1111111111"&dex_brxx_offset(5 downto 0);                                   -- - 
2003
 
2004
-- OFFSET FOR RJMP/RCALL INSTRUCTIONS +2047/-2048
2005
offset_rxx <= "00000"&dex_adr12mem_s(10 downto 0) when (dex_adr12mem_s(11)='0') else       -- +
2006
              "11111"&dex_adr12mem_s(10 downto 0);                                          -- -
2007
 
2008
program_counter <= pc_high&pc_low;
2009
 
2010
-- SynEDA CoreMultiplier
2011
-- assignment(s): program_counter_in
2012
-- replace(s): dbusin, reg_z_out, irqackad_int, program_counter_tmp, program_counter, irq_st1, call_st1, jmp_st1, ret_st1, ret_st2, reti_st1, reti_st2, lpm_st1, instruction_reg, idc_brbc, idc_brbs, idc_icall, idc_ijmp, idc_lpm, idc_rcall, idc_rjmp
2013
 
2014
program_counter_in <= program_counter_cml_2 + offset_brbx when ((idc_brbc_cml_2 or idc_brbs_cml_2) and  bit_test_op_out) ='1'else  -- BRBC/BRBS                  
2015
                      program_counter_cml_2 + offset_rxx when (idc_rjmp_cml_2 or idc_rcall_cml_2)='1'else     -- RJMP/RCALL
2016
                      reg_z_out_cml_2 when (idc_ijmp_cml_2 or idc_icall_cml_2)='1'else                        -- IJMP/ICALL
2017
                      pa15_pm&reg_z_out_cml_2(15 downto 1) when (idc_lpm_cml_2 or idc_elpm) ='1'else    -- LPM/ELPM
2018
                      instruction_reg_cml_2  when (jmp_st1_cml_2 or call_st1_cml_2)='1'else                    -- JMP/CALL
2019
                      "0000000000"&irqackad_int_cml_2&'0' when irq_st1_cml_2 ='1' else                 -- INTERRUPT      
2020
                      dbusin_cml_2&"00000000"  when (ret_st1_cml_2 or reti_st1_cml_2)='1' else                 -- RET/RETI -> PC HIGH BYTE                  
2021
                      "00000000"&dbusin_cml_2  when (ret_st2_cml_2 or reti_st2_cml_2)='1' else                 -- RET/RETI -> PC LOW BYTE                       
2022
                      program_counter_tmp_cml_2 when (lpm_st1_cml_2)='1'                                 -- AFTER LPM/ELPM INSTRUCTION   
2023
                      else program_counter_cml_2+1;      -- THE MOST USUAL CASE
2024
 
2025
 
2026
 
2027
-- SynEDA CoreMultiplier
2028
-- assignment(s): pc_low_en
2029
-- replace(s): cpuwait, irq_st2, call_st2, rcall_st1, icall_st1, ret_st1, reti_st1, sts_st, lds_st, idc_adiw, idc_cbi, idc_ld_x, idc_ld_y, idc_ldd_y, idc_ld_z, idc_ldd_z, idc_pop, idc_push, idc_sbi, idc_sbiw, idc_st_x, idc_st_y, idc_std_y, idc_st_z, idc_std_z
2030
 
2031
pc_low_en  <= not (idc_ld_x_cml_2 or idc_ld_y_cml_2 or idc_ld_z_cml_2 or idc_ldd_y_cml_2 or idc_ldd_z_cml_2 or
2032
                       idc_st_x_cml_2 or idc_st_y_cml_2 or idc_st_z_cml_2 or idc_std_y_cml_2 or idc_std_z_cml_2 or
2033
                                   ((sts_st_cml_2 or lds_st_cml_2) and cpuwait_cml_2)or
2034
                                   idc_adiw_cml_2 or idc_sbiw_cml_2 or
2035
                                   idc_push_cml_2 or idc_pop_cml_2 or
2036
                                   idc_cbi_cml_2 or idc_sbi_cml_2 or
2037
                                   rcall_st1_cml_2 or icall_st1_cml_2 or call_st2_cml_2 or irq_st2_cml_2 or cpuwait_cml_2 or
2038
                                   ret_st1_cml_2 or reti_st1_cml_2);
2039
 
2040
 
2041
-- SynEDA CoreMultiplier
2042
-- assignment(s): pc_high_en
2043
-- replace(s): cpuwait, irq_st2, call_st2, rcall_st1, icall_st1, ret_st2, reti_st2, sts_st, lds_st, idc_adiw, idc_cbi, idc_ld_x, idc_ld_y, idc_ldd_y, idc_ld_z, idc_ldd_z, idc_pop, idc_push, idc_sbi, idc_sbiw, idc_st_x, idc_st_y, idc_std_y, idc_st_z, idc_std_z
2044
 
2045
pc_high_en <= not (idc_ld_x_cml_2 or idc_ld_y_cml_2 or idc_ld_z_cml_2 or idc_ldd_y_cml_2 or idc_ldd_z_cml_2 or
2046
                       idc_st_x_cml_2 or idc_st_y_cml_2 or idc_st_z_cml_2 or idc_std_y_cml_2 or idc_std_z_cml_2 or
2047
                                   ((sts_st_cml_2 or lds_st_cml_2) and cpuwait_cml_2) or
2048
                                   idc_adiw_cml_2 or idc_sbiw_cml_2 or
2049
                                   idc_push_cml_2 or idc_pop_cml_2 or
2050
                                   idc_cbi_cml_2 or idc_sbi_cml_2 or
2051
                                   rcall_st1_cml_2 or icall_st1_cml_2 or call_st2_cml_2 or irq_st2_cml_2 or cpuwait_cml_2 or
2052
                                   ret_st2_cml_2 or reti_st2_cml_2);
2053
 
2054
-- SynEDA CoreMultiplier
2055
-- assignment(s): pc_low
2056
-- replace(s): pc_low
2057
 
2058
program_counter_low:process(cp2,ireset)
2059
begin
2060
if ireset='0' then                              -- RESET
2061
pc_low<=(others => '0');
2062
elsif (cp2='1' and cp2'event) then pc_low <= pc_low_cml_2;              -- CLOCK
2063
 if (cp2en='1') then                                                    -- Clock enable
2064
  if pc_low_en ='1' then
2065
   pc_low <= program_counter_in(7 downto 0);
2066
  end if;
2067
 end if;
2068
end if;
2069
end process;
2070
 
2071
-- SynEDA CoreMultiplier
2072
-- assignment(s): pc_high
2073
-- replace(s): pc_high
2074
 
2075
program_counter_high:process(cp2,ireset)
2076
begin
2077
if ireset='0' then                               -- RESET
2078
pc_high<=(others => '0');
2079
elsif (cp2='1' and cp2'event) then pc_high <= pc_high_cml_2;               -- CLOCK
2080
 if (cp2en='1') then                                                     -- Clock enable
2081
  if pc_high_en ='1' then
2082
   pc_high <= program_counter_in(15 downto 8);
2083
  end if;
2084
 end if;
2085
end if;
2086
end process;
2087
 
2088
pc <= program_counter;
2089
 
2090
 
2091
-- SynEDA CoreMultiplier
2092
-- assignment(s): pc_for_interrupt
2093
-- replace(s): program_counter, pc_for_interrupt
2094
 
2095
program_counter_for_interrupt:process(cp2,ireset)
2096
begin
2097
if ireset='0' then                                 -- RESET
2098
pc_for_interrupt <=(others => '0');
2099
elsif (cp2='1' and cp2'event) then pc_for_interrupt <= pc_for_interrupt_cml_2;               -- CLOCK
2100
 if (cp2en='1') then                                                     -- Clock enable
2101
  if irq_start ='1' then
2102
   pc_for_interrupt <= program_counter_cml_2;
2103
  end if;
2104
 end if;
2105
end if;
2106
end process;
2107
 
2108
-- END OF PROGRAM COUNTER 
2109
 
2110
-- STATE MACHINES
2111
 
2112
-- SynEDA CoreMultiplier
2113
-- assignment(s): skip_inst_start
2114
-- replace(s): idc_cpse, idc_sbic, idc_sbis, idc_sbrc, idc_sbrs
2115
 
2116
skip_inst_start <= ((idc_sbrc_cml_2 or idc_sbrs_cml_2 or idc_sbic_cml_2 or idc_sbis_cml_2) and bit_test_op_out)or
2117
                   (idc_cpse_cml_2 and alu_z_flag_out);
2118
 
2119
-- SynEDA CoreMultiplier
2120
-- assignment(s): nskip_inst_st0, skip_inst_st1, skip_inst_st2
2121
-- replace(s): nskip_inst_st0, skip_inst_st1, skip_inst_st2
2122
 
2123
skip_instruction_sm:process(cp2,ireset)
2124
begin
2125
if ireset='0' then                       -- RESET
2126
nskip_inst_st0 <= '0';
2127
skip_inst_st1  <= '0';
2128
skip_inst_st2  <= '0';
2129
elsif (cp2='1' and cp2'event) then skip_inst_st2 <= skip_inst_st2_cml_2; skip_inst_st1 <= skip_inst_st1_cml_2; nskip_inst_st0 <= nskip_inst_st0_cml_2;       -- CLOCK
2130
 if (cp2en='1') then                                 -- Clock enable
2131
  nskip_inst_st0 <= (not nskip_inst_st0_cml_2 and skip_inst_start) or
2132
                    (nskip_inst_st0_cml_2 and not((skip_inst_st1_cml_2 and not two_word_inst) or skip_inst_st2_cml_2));
2133
  skip_inst_st1  <= (not skip_inst_st1_cml_2 and not nskip_inst_st0_cml_2 and skip_inst_start);
2134
  skip_inst_st2  <=  not skip_inst_st2_cml_2 and skip_inst_st1_cml_2 and two_word_inst;
2135
 end if;
2136
end if;
2137
end process;
2138
 
2139
 
2140
 
2141
-- SynEDA CoreMultiplier
2142
-- assignment(s): adiw_st, sbiw_st
2143
-- replace(s): adiw_st, idc_adiw, sbiw_st, idc_sbiw
2144
 
2145
alu_state_machines:process(cp2,ireset)
2146
begin
2147
if ireset='0' then                       -- RESET
2148
adiw_st <= '0';
2149
sbiw_st <= '0';
2150
elsif (cp2='1' and cp2'event) then sbiw_st <= sbiw_st_cml_2; adiw_st <= adiw_st_cml_2;       -- CLOCK
2151
 if (cp2en='1') then                                     -- Clock enable
2152
  adiw_st <= not adiw_st_cml_2 and idc_adiw_cml_2;
2153
  sbiw_st <= not sbiw_st_cml_2 and idc_sbiw_cml_2;
2154
 end if;
2155
end if;
2156
end process;
2157
 
2158
 
2159
-- SynEDA CoreMultiplier
2160
-- assignment(s): nlpm_st0, lpm_st1, lpm_st2
2161
-- replace(s): nlpm_st0, lpm_st2, idc_lpm, lpm_st1
2162
 
2163
lpm_state_machine:process(cp2,ireset)
2164
begin
2165
if ireset='0' then                       -- RESET
2166
nlpm_st0 <= '0';
2167
lpm_st1 <= '0';
2168
lpm_st2 <= '0';
2169
elsif (cp2='1' and cp2'event) then lpm_st2 <= lpm_st2_cml_2; lpm_st1 <= lpm_st1_cml_2; nlpm_st0 <= nlpm_st0_cml_2;       -- CLOCK
2170
 if (cp2en='1') then                                                      -- Clock enable
2171
  nlpm_st0 <= (not nlpm_st0_cml_2 and (idc_lpm_cml_2 or idc_elpm)) or (nlpm_st0_cml_2 and not lpm_st2_cml_2);
2172
  lpm_st1  <= (not lpm_st1_cml_2 and not nlpm_st0_cml_2 and (idc_lpm_cml_2 or idc_elpm)); -- ?? 
2173
  lpm_st2  <=  not lpm_st2_cml_2 and lpm_st1_cml_2;
2174
 end if;
2175
end if;
2176
end process;
2177
 
2178
 
2179
-- SynEDA CoreMultiplier
2180
-- assignment(s): lds_st
2181
-- replace(s): cpuwait, lds_st, idc_lds
2182
 
2183
lds_state_machine:process(cp2,ireset)
2184
begin
2185
if ireset='0' then                       -- RESET
2186
 lds_st <= '0';
2187
elsif (cp2='1' and cp2'event) then lds_st <= lds_st_cml_2;       -- CLOCK
2188
 if (cp2en='1') then                                                      -- Clock enable       
2189
  lds_st  <= (not lds_st_cml_2 and idc_lds_cml_2) or (lds_st_cml_2 and cpuwait_cml_2);
2190
 end if;
2191
end if;
2192
end process;
2193
 
2194
 
2195
-- SynEDA CoreMultiplier
2196
-- assignment(s): sts_st
2197
-- replace(s): cpuwait, sts_st, idc_sts
2198
 
2199
sts_state_machine:process(cp2,ireset)
2200
begin
2201
if ireset='0' then                       -- RESET
2202
 sts_st <= '0';
2203
elsif (cp2='1' and cp2'event) then sts_st <= sts_st_cml_2;       -- CLOCK
2204
 if (cp2en='1') then                                                      -- Clock enable
2205
  sts_st  <= (not sts_st_cml_2 and idc_sts_cml_2) or (sts_st_cml_2 and cpuwait_cml_2);
2206
 end if;
2207
end if;
2208
end process;
2209
 
2210
-- SynEDA CoreMultiplier
2211
-- assignment(s): njmp_st0, jmp_st1, jmp_st2
2212
-- replace(s): njmp_st0, jmp_st2, idc_jmp, jmp_st1
2213
 
2214
jmp_state_machine:process(cp2,ireset)
2215
begin
2216
if ireset='0' then                       -- RESET
2217
njmp_st0 <= '0';
2218
jmp_st1 <= '0';
2219
jmp_st2 <= '0';
2220
elsif (cp2='1' and cp2'event) then jmp_st2 <= jmp_st2_cml_2; jmp_st1 <= jmp_st1_cml_2; njmp_st0 <= njmp_st0_cml_2;       -- CLOCK
2221
 if (cp2en='1') then                                                      -- Clock enable
2222
  njmp_st0 <= (not njmp_st0_cml_2 and idc_jmp_cml_2) or (njmp_st0_cml_2 and not jmp_st2_cml_2);
2223
  jmp_st1  <= not jmp_st1_cml_2 and not njmp_st0_cml_2 and idc_jmp_cml_2; -- ?? 
2224
  jmp_st2  <= not jmp_st2_cml_2 and jmp_st1_cml_2;
2225
 end if;
2226
end if;
2227
end process;
2228
 
2229
-- SynEDA CoreMultiplier
2230
-- assignment(s): nrcall_st0, rcall_st1, rcall_st2
2231
-- replace(s): cpuwait, nrcall_st0, rcall_st2, idc_rcall, rcall_st1
2232
 
2233
rcall_state_machine:process(cp2,ireset)
2234
begin
2235
if ireset='0' then                       -- RESET
2236
nrcall_st0 <= '0';
2237
rcall_st1 <= '0';
2238
rcall_st2 <= '0';
2239
elsif (cp2='1' and cp2'event) then rcall_st2 <= rcall_st2_cml_2; rcall_st1 <= rcall_st1_cml_2; nrcall_st0 <= nrcall_st0_cml_2;       -- CLOCK
2240
 if (cp2en='1') then                                                      -- Clock enable       
2241
  nrcall_st0 <= (not nrcall_st0_cml_2 and idc_rcall_cml_2) or (nrcall_st0_cml_2 and not (rcall_st2_cml_2 and not cpuwait_cml_2));
2242
  rcall_st1  <= (not rcall_st1_cml_2 and not nrcall_st0_cml_2 and idc_rcall_cml_2) or (rcall_st1_cml_2 and cpuwait_cml_2);
2243
  rcall_st2  <= (not rcall_st2_cml_2 and rcall_st1_cml_2 and not cpuwait_cml_2) or (rcall_st2_cml_2 and cpuwait_cml_2);
2244
 end if;
2245
end if;
2246
end process;
2247
 
2248
-- SynEDA CoreMultiplier
2249
-- assignment(s): nicall_st0, icall_st1, icall_st2
2250
-- replace(s): cpuwait, nicall_st0, icall_st2, idc_icall, icall_st1
2251
 
2252
icall_state_machine:process(cp2,ireset)
2253
begin
2254
if ireset='0' then                       -- RESET
2255
nicall_st0 <= '0';
2256
icall_st1 <= '0';
2257
icall_st2 <= '0';
2258
elsif (cp2='1' and cp2'event) then icall_st2 <= icall_st2_cml_2; icall_st1 <= icall_st1_cml_2; nicall_st0 <= nicall_st0_cml_2;       -- CLOCK
2259
 if (cp2en='1') then                                                      -- Clock enable       
2260
  nicall_st0 <= (not nicall_st0_cml_2 and idc_icall_cml_2) or (nicall_st0_cml_2 and not (icall_st2_cml_2 and not cpuwait_cml_2));
2261
  icall_st1  <= (not icall_st1_cml_2 and not nicall_st0_cml_2 and idc_icall_cml_2) or (icall_st1_cml_2 and cpuwait_cml_2);
2262
  icall_st2  <= (not icall_st2_cml_2 and icall_st1_cml_2 and not cpuwait_cml_2) or (icall_st2_cml_2 and cpuwait_cml_2);
2263
 end if;
2264
end if;
2265
end process;
2266
 
2267
-- SynEDA CoreMultiplier
2268
-- assignment(s): ncall_st0, call_st1, call_st2, call_st3
2269
-- replace(s): cpuwait, ncall_st0, call_st3, idc_call, call_st1, call_st2
2270
 
2271
call_state_machine:process(cp2,ireset)
2272
begin
2273
if ireset='0' then                       -- RESET
2274
ncall_st0 <= '0';
2275
call_st1 <= '0';
2276
call_st2 <= '0';
2277
call_st3  <= '0';
2278
elsif (cp2='1' and cp2'event) then call_st3 <= call_st3_cml_2; call_st2 <= call_st2_cml_2; call_st1 <= call_st1_cml_2; ncall_st0 <= ncall_st0_cml_2;       -- CLOCK
2279
 if (cp2en='1') then                                                      -- Clock enable
2280
  ncall_st0 <= (not ncall_st0_cml_2 and idc_call_cml_2) or (ncall_st0_cml_2 and not( call_st3_cml_2 and not cpuwait_cml_2));
2281
  call_st1  <= not call_st1_cml_2 and not ncall_st0_cml_2 and idc_call_cml_2;
2282
  call_st2  <= (not call_st2_cml_2 and call_st1_cml_2) or (call_st2_cml_2 and cpuwait_cml_2);
2283
  call_st3  <= (not call_st3_cml_2 and call_st2_cml_2 and not cpuwait_cml_2) or (call_st3_cml_2 and cpuwait_cml_2);
2284
 end if;
2285
end if;
2286
end process;
2287
 
2288
-- SynEDA CoreMultiplier
2289
-- assignment(s): nret_st0, ret_st1, ret_st2, ret_st3
2290
-- replace(s): nret_st0, ret_st3, idc_ret, cpuwait, ret_st1, ret_st2
2291
 
2292
ret_state_machine:process(cp2,ireset)
2293
begin
2294
if ireset='0' then                       -- RESET
2295
nret_st0 <= '0';
2296
ret_st1 <= '0';
2297
ret_st2 <= '0';
2298
ret_st3  <= '0';
2299
elsif (cp2='1' and cp2'event) then ret_st3 <= ret_st3_cml_2; ret_st2 <= ret_st2_cml_2; ret_st1 <= ret_st1_cml_2; nret_st0 <= nret_st0_cml_2;       -- CLOCK
2300
 if (cp2en='1') then                                                      -- Clock enable
2301
  nret_st0 <= (not nret_st0_cml_2 and idc_ret_cml_2) or (nret_st0_cml_2 and not ret_st3_cml_2);
2302
  ret_st1  <= (not ret_st1_cml_2 and not nret_st0_cml_2 and idc_ret_cml_2) or (ret_st1_cml_2 and cpuwait_cml_2);
2303
  ret_st2  <= (not ret_st2_cml_2 and ret_st1_cml_2 and not cpuwait_cml_2) or (ret_st2_cml_2 and cpuwait_cml_2) ;
2304
  ret_st3  <= not ret_st3_cml_2 and ret_st2_cml_2 and not cpuwait_cml_2;
2305
 end if;
2306
end if;
2307
end process;
2308
 
2309
-- SynEDA CoreMultiplier
2310
-- assignment(s): nreti_st0, reti_st1, reti_st2, reti_st3
2311
-- replace(s): nreti_st0, reti_st3, idc_reti, cpuwait, reti_st1, reti_st2
2312
 
2313
reti_state_machine:process(cp2,ireset)
2314
begin
2315
if ireset='0' then                       -- RESET
2316
nreti_st0 <= '0';
2317
reti_st1 <= '0';
2318
reti_st2 <= '0';
2319
reti_st3  <= '0';
2320
elsif (cp2='1' and cp2'event) then reti_st3 <= reti_st3_cml_2; reti_st2 <= reti_st2_cml_2; reti_st1 <= reti_st1_cml_2; nreti_st0 <= nreti_st0_cml_2;       -- CLOCK
2321
 if (cp2en='1') then                                                      -- Clock enable
2322
  nreti_st0 <= (not nreti_st0_cml_2 and idc_reti_cml_2) or (nreti_st0_cml_2 and not reti_st3_cml_2);
2323
  reti_st1  <= (not reti_st1_cml_2 and not nreti_st0_cml_2 and idc_reti_cml_2) or (reti_st1_cml_2 and cpuwait_cml_2);
2324
  reti_st2  <= (not reti_st2_cml_2 and reti_st1_cml_2 and not cpuwait_cml_2) or (reti_st2_cml_2 and cpuwait_cml_2) ;
2325
  reti_st3  <= not reti_st3_cml_2 and reti_st2_cml_2 and not cpuwait_cml_2;
2326
 end if;
2327
end if;
2328
end process;
2329
 
2330
 
2331
-- INTERRUPT LOGIC AND STATE MACHINE 
2332
 
2333
-- SynEDA CoreMultiplier
2334
-- assignment(s): irq_int
2335
-- replace(s): irqlines
2336
 
2337
irq_int <= '0' when      irqlines_cml_2="00000000000000000000000" else '1';
2338
 
2339
irq_vector_adr(15 downto 6)<=(others => '0');
2340
irq_vector_adr(0) <= '0';
2341
-- SynEDA CoreMultiplier
2342
-- assignment(s): irq_vector_adr
2343
-- replace(s): irqlines
2344
 
2345
-- PRIORITY ENCODER
2346
irq_vector_adr(5 downto 1) <= "00001" when irqlines_cml_2(0)='1'  else -- 0x0002
2347
                              "00010" when irqlines_cml_2(1)='1'  else -- 0x0004  
2348
                              "00011" when irqlines_cml_2(2)='1'  else -- 0x0006  
2349
                              "00100" when irqlines_cml_2(3)='1'  else -- 0x0008  
2350
                              "00101" when irqlines_cml_2(4)='1'  else -- 0x000A  
2351
                              "00110" when irqlines_cml_2(5)='1'  else -- 0x000C  
2352
                              "00111" when irqlines_cml_2(6)='1'  else -- 0x000E  
2353
                              "01000" when irqlines_cml_2(7)='1'  else -- 0x0010  
2354
                              "01001" when irqlines_cml_2(8)='1'  else -- 0x0012  
2355
                              "01010" when irqlines_cml_2(9)='1'  else -- 0x0014
2356
                              "01011" when irqlines_cml_2(10)='1' else -- 0x0016
2357
                              "01100" when irqlines_cml_2(11)='1' else -- 0x0018
2358
                              "01101" when irqlines_cml_2(12)='1' else -- 0x001A
2359
                              "01110" when irqlines_cml_2(13)='1' else -- 0x001C
2360
                              "01111" when irqlines_cml_2(14)='1' else -- 0x001E
2361
                              "10000" when irqlines_cml_2(15)='1' else -- 0x0020
2362
                              "10001" when irqlines_cml_2(16)='1' else -- 0x0022
2363
                              "10010" when irqlines_cml_2(17)='1' else -- 0x0024
2364
                              "10011" when irqlines_cml_2(18)='1' else -- 0x0026
2365
                              "10100" when irqlines_cml_2(19)='1' else -- 0x0028
2366
                              "10101" when irqlines_cml_2(20)='1' else -- 0x002A
2367
                              "10110" when irqlines_cml_2(21)='1' else -- 0x002C
2368
                              "10111" when irqlines_cml_2(22)='1' else -- 0x002E                                                                  
2369
                                                          "00000";
2370
 
2371
-- SynEDA CoreMultiplier
2372
-- assignment(s): cpu_busy
2373
-- replace(s): cpuwait, nirq_st0, call_st1, call_st2, call_st3, rcall_st1, rcall_st2, icall_st1, icall_st2, jmp_st1, ret_st1, ret_st2, reti_st1, reti_st2, skip_inst_st1, lpm_st1, sts_st, lds_st, st_st, ld_st, push_st, pop_st, idc_adiw, idc_bclr, idc_brbc, idc_brbs, idc_call, idc_cbi, idc_icall, idc_ijmp, idc_jmp, idc_ld_x, idc_ld_y, idc_ldd_y, idc_ld_z, idc_ldd_z, idc_lds, idc_lpm, idc_pop, idc_push, idc_rcall, idc_ret, idc_reti, idc_rjmp, idc_sbi, idc_sbiw, idc_st_x, idc_st_y, idc_std_y, idc_st_z, idc_std_z, idc_sts
2374
 
2375
-- MULTI CYCLE INSTRUCTION FLAG FOR IRQ
2376
cpu_busy <= idc_adiw_cml_2 or idc_sbiw_cml_2 or idc_cbi_cml_2 or idc_sbi_cml_2 or
2377
            idc_rjmp_cml_2 or idc_ijmp_cml_2 or
2378
                        idc_jmp_cml_2 or jmp_st1_cml_2 or
2379
--                      idc_brbs or idc_brbc or -- Old variant
2380
            ((idc_brbc_cml_2 or idc_brbs_cml_2) and  bit_test_op_out) or
2381
                        idc_lpm_cml_2 or lpm_st1_cml_2 or
2382
                        skip_inst_start or (skip_inst_st1_cml_2 and two_word_inst) or
2383
                        idc_ld_x_cml_2 or idc_ld_y_cml_2 or idc_ldd_y_cml_2 or idc_ld_z_cml_2 or idc_ldd_z_cml_2 or (ld_st_cml_2 and cpuwait_cml_2) or
2384
                        idc_st_x_cml_2 or idc_st_y_cml_2 or idc_std_y_cml_2 or idc_st_z_cml_2 or idc_std_z_cml_2 or (st_st_cml_2 and cpuwait_cml_2) or
2385
                        idc_lds_cml_2 or (lds_st_cml_2 and cpuwait_cml_2) or
2386
                        idc_sts_cml_2 or (sts_st_cml_2 and cpuwait_cml_2) or
2387
                        idc_rcall_cml_2 or rcall_st1_cml_2 or (rcall_st2_cml_2 and cpuwait_cml_2) or           -- RCALL
2388
                        idc_icall_cml_2 or icall_st1_cml_2 or (icall_st2_cml_2 and cpuwait_cml_2) or               -- ICALL
2389
                        idc_call_cml_2 or call_st1_cml_2 or call_st2_cml_2 or (call_st3_cml_2 and cpuwait_cml_2) or  -- CALL
2390
                        idc_push_cml_2 or (push_st_cml_2 and cpuwait_cml_2) or                           -- PUSH (added 14.07.05)
2391
                        idc_pop_cml_2 or (pop_st_cml_2 and cpuwait_cml_2) or                             -- POP  (added 14.07.05)
2392
                    (idc_bclr_cml_2 and sreg_bop_wr_en(7)) or                 -- ??? CLI
2393
                    (iowe_int and sreg_adr_eq and not dbusout_int(7))or -- ??? Writing '0' to I flag (OUT/STD/ST/STD)
2394
                        nirq_st0_cml_2 or
2395
--                      idc_ret  or nret_st0 or                             -- Old variant 
2396
                        idc_ret_cml_2 or ret_st1_cml_2 or ret_st2_cml_2 or
2397
--                      idc_reti or nreti_st0;                              -- At least one instruction must be executed after RETI and before the new interrupt.
2398
                        idc_reti_cml_2 or reti_st1_cml_2 or reti_st2_cml_2;
2399
 
2400
-- SynEDA CoreMultiplier
2401
-- assignment(s): sreg_adr_eq
2402
-- replace(s): adr_int
2403
 
2404
sreg_adr_eq <= '1' when adr_int_cml_2=SREG_Address else '0';
2405
 
2406
-- SynEDA CoreMultiplier
2407
-- assignment(s): irq_start
2408
-- replace(s): globint
2409
 
2410
--irq_start <= irq_int and not cpu_busy and globint;
2411
irq_start <= irq_int and not cpu_busy and globint_cml_2;
2412
 
2413
-- SynEDA CoreMultiplier
2414
-- assignment(s): nirq_st0, irq_st1, irq_st2, irq_st3
2415
-- replace(s): cpuwait, nirq_st0, irq_st3, irq_st1, irq_st2
2416
 
2417
irq_state_machine:process(cp2,ireset)
2418
begin
2419
if ireset='0' then                       -- RESET
2420
nirq_st0 <= '0';
2421
irq_st1 <= '0';
2422
irq_st2 <= '0';
2423
irq_st3 <= '0';
2424
elsif (cp2='1' and cp2'event) then irq_st3 <= irq_st3_cml_2; irq_st2 <= irq_st2_cml_2; irq_st1 <= irq_st1_cml_2; nirq_st0 <= nirq_st0_cml_2;       -- CLOCK
2425
 if (cp2en='1') then                                                      -- Clock enable       
2426
  nirq_st0 <= (not nirq_st0_cml_2 and irq_start) or (nirq_st0_cml_2 and not (irq_st3_cml_2 and not cpuwait_cml_2));
2427
  irq_st1  <= (not irq_st1_cml_2 and not nirq_st0_cml_2 and irq_start);
2428
  irq_st2  <= (not irq_st2_cml_2 and irq_st1_cml_2) or (irq_st2_cml_2 and cpuwait_cml_2);
2429
  irq_st3  <= (not irq_st3_cml_2 and irq_st2_cml_2 and not cpuwait_cml_2) or (irq_st3_cml_2 and cpuwait_cml_2);
2430
 end if;
2431
end if;
2432
end process;
2433
 
2434
-- SynEDA CoreMultiplier
2435
-- assignment(s): irqack_int
2436
-- replace(s): irqack_int
2437
 
2438
irqack_reg:process(cp2,ireset)
2439
begin
2440
if ireset='0' then                       -- RESET
2441
irqack_int<='0';
2442
elsif (cp2='1' and cp2'event) then irqack_int <= irqack_int_cml_2;       -- CLOCK
2443
 if (cp2en='1') then                                                      -- Clock enable       
2444
  irqack_int<= not irqack_int_cml_2 and irq_start;
2445
 end if;
2446
end if;
2447
end process;
2448
-- SynEDA CoreMultiplier
2449
-- assignment(s): irqack
2450
-- replace(s): irqack_int
2451
 
2452
irqack_cml_out <= irqack_int_cml_2;
2453
 
2454
-- SynEDA CoreMultiplier
2455
-- assignment(s): irqackad_int
2456
-- replace(s): irqackad_int
2457
 
2458
irqackad_reg:process(cp2,ireset)
2459
begin
2460
if ireset='0' then                                -- RESET
2461
irqackad_int<=(others=>'0');
2462
elsif (cp2='1' and cp2'event) then irqackad_int <= irqackad_int_cml_2;              -- CLOCK
2463
 if (cp2en='1') then                                                      -- Clock enable
2464
  irqackad_int <= irq_vector_adr(5 downto 1);
2465
 end if;
2466
end if;
2467
end process;
2468
-- SynEDA CoreMultiplier
2469
-- assignment(s): irqackad
2470
-- replace(s): irqackad_int
2471
 
2472
irqackad_cml_out <= irqackad_int_cml_2;
2473
 
2474
-- *******************************************************************************************
2475
 
2476
-- SynEDA CoreMultiplier
2477
-- assignment(s): ijmp_st, rjmp_st, brxx_st, push_st, pop_st
2478
-- replace(s): ijmp_st, idc_ijmp, rjmp_st, idc_rjmp, brxx_st, idc_brbc, idc_brbs, cpuwait, push_st, idc_push, pop_st, idc_pop
2479
 
2480
rjmp_push_pop_ijmp_state_brxx_machine:process(cp2,ireset)
2481
begin
2482
if ireset='0' then                       -- RESET
2483
rjmp_st <= '0';
2484
ijmp_st <= '0';
2485
push_st <= '0';
2486
pop_st <= '0';
2487
brxx_st <= '0';
2488
elsif (cp2='1' and cp2'event) then pop_st <= pop_st_cml_2; push_st <= push_st_cml_2; brxx_st <= brxx_st_cml_2; rjmp_st <= rjmp_st_cml_2; ijmp_st <= ijmp_st_cml_2;       -- CLOCK
2489
 if (cp2en='1') then                                                      -- Clock enable
2490
  rjmp_st <= idc_rjmp_cml_2;    -- ??
2491
  ijmp_st <= idc_ijmp_cml_2;
2492
  push_st <= (not push_st_cml_2 and idc_push_cml_2) or (push_st_cml_2 and cpuwait_cml_2);
2493
  pop_st  <= (not pop_st_cml_2  and idc_pop_cml_2) or (pop_st_cml_2 and cpuwait_cml_2);
2494
  brxx_st <= not brxx_st_cml_2 and (idc_brbc_cml_2 or idc_brbs_cml_2) and bit_test_op_out;
2495
 end if;
2496
end if;
2497
end process;
2498
 
2499
-- SynEDA CoreMultiplier
2500
-- assignment(s): st_st, ld_st
2501
-- replace(s): cpuwait, st_st, idc_st_x, idc_st_y, idc_std_y, idc_st_z, idc_std_z, ld_st, idc_ld_x, idc_ld_y, idc_ldd_y, idc_ld_z, idc_ldd_z
2502
 
2503
-- LD/LDD/ST/STD
2504
ld_st_state_machine:process(cp2,ireset)
2505
begin
2506
if ireset='0' then                       -- RESET
2507
ld_st <= '0';
2508
st_st <= '0';
2509
elsif (cp2='1' and cp2'event) then ld_st <= ld_st_cml_2; st_st <= st_st_cml_2;       -- CLOCK
2510
 if (cp2en='1') then                                                      -- Clock enable       
2511
  ld_st <= (not ld_st_cml_2 and (idc_ld_x_cml_2 or idc_ld_y_cml_2 or idc_ldd_y_cml_2 or idc_ld_z_cml_2 or idc_ldd_z_cml_2)) or (ld_st_cml_2 and cpuwait_cml_2);
2512
  st_st <= (not st_st_cml_2 and (idc_st_x_cml_2 or idc_st_y_cml_2 or idc_std_y_cml_2 or idc_st_z_cml_2 or idc_std_z_cml_2)) or (st_st_cml_2 and cpuwait_cml_2);
2513
 end if;
2514
end if;
2515
end process;
2516
 
2517
-- SynEDA CoreMultiplier
2518
-- assignment(s): sbi_st, cbi_st, cbi_sbi_io_adr_tmp, cbi_sbi_bit_num_tmp
2519
-- replace(s): sbi_st, idc_sbi, cbi_st, idc_cbi, dex_adr5port, cbi_sbi_io_adr_tmp, dex_bitop_bitnum, cbi_sbi_bit_num_tmp
2520
 
2521
-- SBI/CBI
2522
sbi_cbi_machine:process(cp2,ireset)
2523
begin
2524
if ireset='0' then                       -- RESET
2525
sbi_st <= '0';
2526
cbi_st <= '0';
2527
cbi_sbi_io_adr_tmp  <= (others => '0');
2528
cbi_sbi_bit_num_tmp     <= (others => '0');
2529
elsif (cp2='1' and cp2'event) then cbi_sbi_bit_num_tmp <= cbi_sbi_bit_num_tmp_cml_2; cbi_sbi_io_adr_tmp <= cbi_sbi_io_adr_tmp_cml_2; cbi_st <= cbi_st_cml_2; sbi_st <= sbi_st_cml_2;       -- CLOCK
2530
 if (cp2en='1') then                                                      -- Clock enable
2531
  sbi_st <= not sbi_st_cml_2 and idc_sbi_cml_2;
2532
  cbi_st <= not cbi_st_cml_2 and idc_cbi_cml_2;
2533
  cbi_sbi_io_adr_tmp <= dex_adr5port_cml_2;
2534
  cbi_sbi_bit_num_tmp <= dex_bitop_bitnum_cml_2;
2535
 end if;
2536
end if;
2537
end process;
2538
 
2539
-- ########################################################################################
2540
 
2541
-- SREG FLAGS WRITE ENABLE LOGIC
2542
 
2543
--bclr_bset_op_en_logic:for i in sreg_bop_wr_en'range generate
2544
--sreg_bop_wr_en(i) <= '1' when (dex_bitnum_sreg=i and (idc_bclr or idc_bset)='1') else '0';
2545
--end generate;
2546
 
2547
sreg_bop_wr_en(0) <= '1' when (dex_bitnum_sreg=0 and (idc_bclr_cml_2 or idc_bset_cml_2)='1') else '0';
2548
sreg_bop_wr_en(1) <= '1' when (dex_bitnum_sreg=1 and (idc_bclr_cml_2 or idc_bset_cml_2)='1') else '0';
2549
sreg_bop_wr_en(2) <= '1' when (dex_bitnum_sreg=2 and (idc_bclr_cml_2 or idc_bset_cml_2)='1') else '0';
2550
sreg_bop_wr_en(3) <= '1' when (dex_bitnum_sreg=3 and (idc_bclr_cml_2 or idc_bset_cml_2)='1') else '0';
2551
sreg_bop_wr_en(4) <= '1' when (dex_bitnum_sreg=4 and (idc_bclr_cml_2 or idc_bset_cml_2)='1') else '0';
2552
sreg_bop_wr_en(5) <= '1' when (dex_bitnum_sreg=5 and (idc_bclr_cml_2 or idc_bset_cml_2)='1') else '0';
2553
sreg_bop_wr_en(6) <= '1' when (dex_bitnum_sreg=6 and (idc_bclr_cml_2 or idc_bset_cml_2)='1') else '0';
2554
-- SynEDA CoreMultiplier
2555
-- assignment(s): sreg_bop_wr_en
2556
-- replace(s): idc_bclr, idc_bset
2557
 
2558
sreg_bop_wr_en(7) <= '1' when (dex_bitnum_sreg=7 and (idc_bclr_cml_2 or idc_bset_cml_2)='1') else '0';
2559
 
2560
-- SynEDA CoreMultiplier
2561
-- assignment(s): sreg_c_wr_en
2562
-- replace(s): adiw_st, sbiw_st, idc_adc, idc_add, idc_adiw, idc_asr, idc_com, idc_cp, idc_cpc, idc_cpi, idc_lsr, idc_neg, idc_ror, idc_sbc, idc_sbci, idc_sbiw, idc_sub, idc_subi
2563
 
2564
sreg_c_wr_en <= idc_add_cml_2 or idc_adc_cml_2 or (idc_adiw_cml_2 or adiw_st_cml_2) or idc_sub_cml_2  or idc_subi_cml_2 or
2565
                idc_sbc_cml_2 or idc_sbci_cml_2 or (idc_sbiw_cml_2 or sbiw_st_cml_2) or idc_com_cml_2 or idc_neg_cml_2 or
2566
                                idc_cp_cml_2 or idc_cpc_cml_2 or idc_cpi_cml_2 or
2567
                idc_lsr_cml_2 or idc_ror_cml_2 or idc_asr_cml_2 or sreg_bop_wr_en(0);
2568
 
2569
-- SynEDA CoreMultiplier
2570
-- assignment(s): sreg_z_wr_en
2571
-- replace(s): adiw_st, sbiw_st, idc_adc, idc_add, idc_adiw, idc_and, idc_andi, idc_asr, idc_com, idc_cp, idc_cpc, idc_cpi, idc_dec, idc_eor, idc_inc, idc_lsr, idc_neg, idc_or, idc_ori, idc_ror, idc_sbc, idc_sbci, idc_sbiw, idc_sub, idc_subi
2572
 
2573
sreg_z_wr_en <= idc_add_cml_2 or idc_adc_cml_2 or (idc_adiw_cml_2 or adiw_st_cml_2) or idc_sub_cml_2  or idc_subi_cml_2 or
2574
                idc_sbc_cml_2 or idc_sbci_cml_2 or (idc_sbiw_cml_2 or sbiw_st_cml_2) or
2575
                                idc_cp_cml_2 or idc_cpc_cml_2 or idc_cpi_cml_2 or
2576
                idc_and_cml_2 or idc_andi_cml_2 or idc_or_cml_2 or idc_ori_cml_2 or idc_eor_cml_2 or idc_com_cml_2 or idc_neg_cml_2 or
2577
                idc_inc_cml_2 or idc_dec_cml_2 or idc_lsr_cml_2 or idc_ror_cml_2 or idc_asr_cml_2 or sreg_bop_wr_en(1);
2578
 
2579
 
2580
-- SynEDA CoreMultiplier
2581
-- assignment(s): sreg_n_wr_en
2582
-- replace(s): adiw_st, sbiw_st, idc_adc, idc_add, idc_and, idc_andi, idc_asr, idc_com, idc_cp, idc_cpc, idc_cpi, idc_dec, idc_eor, idc_inc, idc_lsr, idc_neg, idc_or, idc_ori, idc_ror, idc_sbc, idc_sbci, idc_sub, idc_subi
2583
 
2584
sreg_n_wr_en <= idc_add_cml_2 or idc_adc_cml_2 or adiw_st_cml_2 or idc_sub_cml_2  or idc_subi_cml_2 or
2585
                idc_sbc_cml_2 or idc_sbci_cml_2 or sbiw_st_cml_2 or
2586
                                idc_cp_cml_2 or idc_cpc_cml_2 or idc_cpi_cml_2 or
2587
                idc_and_cml_2 or idc_andi_cml_2 or idc_or_cml_2 or idc_ori_cml_2 or idc_eor_cml_2 or idc_com_cml_2 or idc_neg_cml_2 or
2588
                idc_inc_cml_2 or idc_dec_cml_2 or idc_lsr_cml_2 or idc_ror_cml_2 or idc_asr_cml_2 or sreg_bop_wr_en(2);
2589
 
2590
-- SynEDA CoreMultiplier
2591
-- assignment(s): sreg_v_wr_en
2592
-- replace(s): adiw_st, sbiw_st, idc_adc, idc_add, idc_and, idc_andi, idc_asr, idc_com, idc_cp, idc_cpc, idc_cpi, idc_dec, idc_eor, idc_inc, idc_lsr, idc_neg, idc_or, idc_ori, idc_ror, idc_sbc, idc_sbci, idc_sub, idc_subi
2593
 
2594
sreg_v_wr_en <= idc_add_cml_2 or idc_adc_cml_2 or adiw_st_cml_2 or idc_sub_cml_2  or idc_subi_cml_2 or -- idc_adiw
2595
                idc_sbc_cml_2 or idc_sbci_cml_2 or sbiw_st_cml_2 or idc_neg_cml_2 or idc_com_cml_2 or  -- idc_sbiw
2596
                idc_inc_cml_2 or idc_dec_cml_2 or
2597
                                idc_cp_cml_2 or idc_cpc_cml_2 or idc_cpi_cml_2 or
2598
                idc_lsr_cml_2 or idc_ror_cml_2 or idc_asr_cml_2 or sreg_bop_wr_en(3) or
2599
                                idc_and_cml_2 or idc_andi_cml_2 or idc_or_cml_2 or idc_ori_cml_2 or idc_eor_cml_2; -- V-flag bug fixing
2600
 
2601
-- SynEDA CoreMultiplier
2602
-- assignment(s): sreg_s_wr_en
2603
-- replace(s): adiw_st, sbiw_st, idc_adc, idc_add, idc_and, idc_andi, idc_asr, idc_com, idc_cp, idc_cpc, idc_cpi, idc_dec, idc_eor, idc_inc, idc_lsr, idc_neg, idc_or, idc_ori, idc_ror, idc_sbc, idc_sbci, idc_sub, idc_subi
2604
 
2605
sreg_s_wr_en <= idc_add_cml_2 or idc_adc_cml_2 or adiw_st_cml_2 or idc_sub_cml_2 or idc_subi_cml_2 or
2606
                idc_sbc_cml_2 or idc_sbci_cml_2 or sbiw_st_cml_2 or
2607
                                idc_cp_cml_2 or idc_cpc_cml_2 or idc_cpi_cml_2 or
2608
                                idc_and_cml_2 or idc_andi_cml_2 or idc_or_cml_2 or idc_ori_cml_2 or idc_eor_cml_2 or idc_com_cml_2 or idc_neg_cml_2 or
2609
                                idc_inc_cml_2 or idc_dec_cml_2 or idc_lsr_cml_2 or idc_ror_cml_2 or idc_asr_cml_2 or sreg_bop_wr_en(4);
2610
 
2611
-- SynEDA CoreMultiplier
2612
-- assignment(s): sreg_h_wr_en
2613
-- replace(s): idc_adc, idc_add, idc_cp, idc_cpc, idc_cpi, idc_neg, idc_sbc, idc_sbci, idc_sub, idc_subi
2614
 
2615
sreg_h_wr_en <= idc_add_cml_2 or idc_adc_cml_2 or idc_sub_cml_2  or idc_subi_cml_2 or
2616
                                idc_cp_cml_2 or idc_cpc_cml_2 or idc_cpi_cml_2 or
2617
                idc_sbc_cml_2 or idc_sbci_cml_2 or idc_neg_cml_2 or sreg_bop_wr_en(5);
2618
 
2619
sreg_t_wr_en <=  idc_bst or sreg_bop_wr_en(6);
2620
 
2621
-- SynEDA CoreMultiplier
2622
-- assignment(s): sreg_i_wr_en
2623
-- replace(s): irq_st1, reti_st3
2624
 
2625
sreg_i_wr_en <= irq_st1_cml_2 or reti_st3_cml_2 or sreg_bop_wr_en(7); -- WAS "irq_start"
2626
 
2627
-- SynEDA CoreMultiplier
2628
-- assignment(s): sreg_fl_in
2629
-- replace(s): reti_st3, idc_bclr, idc_bset
2630
 
2631
sreg_fl_in_cml_out <=  bit_pr_sreg_out when (idc_bst or idc_bclr_cml_2 or idc_bset_cml_2)='1' else                         -- TO THE SREG
2632
reti_st3_cml_2&'0'&alu_h_flag_out&alu_s_flag_out&alu_v_flag_out&alu_n_flag_out&alu_z_flag_out&alu_c_flag_out;
2633
 
2634
-- #################################################################################################################
2635
 
2636
-- *********************************************************************************************
2637
-- ************** INSTRUCTION DECODER OUTPUTS FOR THE OTHER BLOCKS  ****************************
2638
-- *********************************************************************************************
2639
 
2640
-- FOR ALU
2641
 
2642
idc_add_out   <= idc_add;
2643
idc_adc_out   <= idc_adc;
2644
-- SynEDA CoreMultiplier
2645
-- assignment(s): idc_adiw_out
2646
-- replace(s): idc_adiw
2647
 
2648
idc_adiw_out_cml_out  <= idc_adiw_cml_1;
2649
idc_sub_out   <= idc_sub;
2650
idc_subi_out  <= idc_subi;
2651
idc_sbc_out   <= idc_sbc;
2652
idc_sbci_out  <= idc_sbci;
2653
idc_sbiw_out  <= idc_sbiw;
2654
adiw_st_out   <= adiw_st;
2655
sbiw_st_out   <= sbiw_st;
2656
idc_and_out   <= idc_and;
2657
-- SynEDA CoreMultiplier
2658
-- assignment(s): idc_andi_out
2659
-- replace(s): idc_andi
2660
 
2661
idc_andi_out_cml_out  <= idc_andi_cml_1;
2662
idc_or_out    <= idc_or;
2663
-- SynEDA CoreMultiplier
2664
-- assignment(s): idc_ori_out
2665
-- replace(s): idc_ori
2666
 
2667
idc_ori_out_cml_out   <= idc_ori_cml_1;
2668
idc_eor_out   <= idc_eor;
2669
idc_com_out   <= idc_com;
2670
idc_neg_out   <= idc_neg;
2671
idc_inc_out   <= idc_inc;
2672
idc_dec_out   <= idc_dec;
2673
idc_cp_out    <= idc_cp;
2674
idc_cpc_out   <= idc_cpc;
2675
idc_cpi_out   <= idc_cpi;
2676
idc_cpse_out  <= idc_cpse;
2677
idc_lsr_out   <= idc_lsr;
2678
idc_ror_out   <= idc_ror;
2679
idc_asr_out   <= idc_asr;
2680
idc_swap_out  <= idc_swap;
2681
 
2682
-- FOR THE BIT PROCESSOR
2683
sbi_st_out   <= sbi_st;
2684
cbi_st_out   <= cbi_st;
2685
idc_bst_out  <= idc_bst;
2686
-- SynEDA CoreMultiplier
2687
-- assignment(s): idc_bset_out
2688
-- replace(s): idc_bset
2689
 
2690
idc_bset_out_cml_out <= idc_bset_cml_2;
2691
-- SynEDA CoreMultiplier
2692
-- assignment(s): idc_bclr_out
2693
-- replace(s): idc_bclr
2694
 
2695
idc_bclr_out_cml_out <= idc_bclr_cml_2;
2696
idc_sbic_out <= idc_sbic;
2697
idc_sbis_out <= idc_sbis;
2698
-- SynEDA CoreMultiplier
2699
-- assignment(s): idc_sbrs_out
2700
-- replace(s): idc_sbrs
2701
 
2702
idc_sbrs_out_cml_out <= idc_sbrs_cml_2;
2703
-- SynEDA CoreMultiplier
2704
-- assignment(s): idc_sbrc_out
2705
-- replace(s): idc_sbrc
2706
 
2707
idc_sbrc_out_cml_out <= idc_sbrc_cml_2;
2708
-- SynEDA CoreMultiplier
2709
-- assignment(s): idc_brbs_out
2710
-- replace(s): idc_brbs
2711
 
2712
idc_brbs_out_cml_out <= idc_brbs_cml_2;
2713
-- SynEDA CoreMultiplier
2714
-- assignment(s): idc_brbc_out
2715
-- replace(s): idc_brbc
2716
 
2717
idc_brbc_out_cml_out <= idc_brbc_cml_2;
2718
-- SynEDA CoreMultiplier
2719
-- assignment(s): idc_reti_out
2720
-- replace(s): idc_reti
2721
 
2722
idc_reti_out_cml_out <= idc_reti_cml_2;
2723
 
2724
-- POST INCREMENT/PRE DECREMENT FOR THE X,Y,Z REGISTERS
2725
post_inc <= idc_psinc;
2726
pre_dec  <= idc_prdec;
2727
-- SynEDA CoreMultiplier
2728
-- assignment(s): reg_h_wr
2729
-- replace(s): idc_ld_x, idc_ld_y, idc_ld_z, idc_st_x, idc_st_y, idc_st_z, idc_prdec
2730
 
2731
reg_h_wr_cml_out <= (idc_st_x_cml_2 or idc_st_y_cml_2 or idc_st_z_cml_2 or idc_ld_x_cml_2 or idc_ld_y_cml_2 or idc_ld_z_cml_2) and (idc_psinc or idc_prdec_cml_2);
2732
 
2733
reg_h_adr_cml_out(0)<= idc_st_x_cml_1 or idc_ld_x;
2734
reg_h_adr_cml_out(1)<= idc_st_y_cml_1 or idc_std_y_cml_1 or idc_ld_y or idc_ldd_y;
2735
-- SynEDA CoreMultiplier
2736
-- assignment(s): reg_h_adr
2737
-- replace(s): idc_st_x, idc_st_y, idc_std_y, idc_st_z, idc_std_z
2738
 
2739
reg_h_adr_cml_out(2)<= idc_st_z_cml_1 or idc_std_z_cml_1 or idc_ld_z or idc_ldd_z;
2740
 
2741
-- SynEDA CoreMultiplier
2742
-- assignment(s): sp_en
2743
-- replace(s): cpuwait, irq_st1, irq_st2, call_st1, call_st2, rcall_st1, icall_st1, ret_st1, reti_st1, idc_icall, idc_pop, idc_push, idc_rcall, idc_ret, idc_reti
2744
 
2745
-- SynEDA CoreMultiplier
2746
-- assignment(s): sp_ndown_up
2747
-- replace(s): cpuwait, ret_st1, reti_st1, idc_pop, idc_ret, idc_reti
2748
 
2749
-- STACK POINTER CONTROL
2750
sp_ndown_up_cml_out <= idc_pop_cml_2 or idc_ret_cml_2 or (ret_st1_cml_2 and not cpuwait_cml_2) or idc_reti_cml_2 or (reti_st1_cml_2 and not cpuwait_cml_2); -- ?????????
2751
sp_en_cml_out <= idc_push_cml_2 or idc_pop_cml_2 or idc_rcall_cml_2 or (rcall_st1_cml_2 and not cpuwait_cml_2) or idc_icall_cml_2 or (icall_st1_cml_2 and not cpuwait_cml_2) or
2752
idc_ret_cml_2 or (ret_st1_cml_2 and not cpuwait_cml_2) or idc_reti_cml_2 or (reti_st1_cml_2 and not cpuwait_cml_2) or
2753
call_st1_cml_2 or (call_st2_cml_2 and not cpuwait_cml_2) or irq_st1_cml_2 or (irq_st2_cml_2 and not cpuwait_cml_2); --????????
2754
 
2755
 
2756
branch  <= dex_condition;
2757
bit_num_r_io <= cbi_sbi_bit_num_tmp when (cbi_st or sbi_st)='1' else dex_bitop_bitnum;
2758
 
2759
adr <= adr_int;
2760
 
2761
ramre <= ramre_int;
2762
ramwe <= ramwe_int;
2763
 
2764
iore <= iore_int;
2765
iowe <= iowe_int;
2766
 
2767
--dbusout <= dbusout_int;
2768
 
2769
-- Sleep Control
2770
sleepi <= idc_sleep;
2771
irqok  <= irq_int;
2772
 
2773
-- Watchdog
2774
wdri <= idc_wdr;
2775
 
2776
-- ************************** JTAG OCD support ************************************
2777
 
2778
-- Change of flow       
2779
change_flow <= '0';
2780
valid_instr <= '0';
2781
 
2782
 
2783
end RTL;

powered by: WebSVN 2.1.0

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