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

Subversion Repositories t400

[/] [t400/] [trunk/] [rtl/] [vhdl/] [t400_decoder.vhd] - Blame information for rev 179

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 arniml
-------------------------------------------------------------------------------
2
--
3
-- The decoder unit.
4
-- Implements the instruction opcodes and controls all units of the T400 core.
5
--
6 179 arniml
-- $Id: t400_decoder.vhd 179 2009-04-01 19:48:38Z arniml $
7 2 arniml
--
8
-- Copyright (c) 2006 Arnim Laeuger (arniml@opencores.org)
9
--
10
-- All rights reserved
11
--
12
-- Redistribution and use in source and synthezised forms, with or without
13
-- modification, are permitted provided that the following conditions are met:
14
--
15
-- Redistributions of source code must retain the above copyright notice,
16
-- this list of conditions and the following disclaimer.
17
--
18
-- Redistributions in synthesized form must reproduce the above copyright
19
-- notice, this list of conditions and the following disclaimer in the
20
-- documentation and/or other materials provided with the distribution.
21
--
22
-- Neither the name of the author nor the names of other contributors may
23
-- be used to endorse or promote products derived from this software without
24
-- specific prior written permission.
25
--
26
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
28
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
30
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36
-- POSSIBILITY OF SUCH DAMAGE.
37
--
38
-- Please report bugs to the author, but before you do so, please
39
-- make sure that this is not a derivative work and that
40
-- you have the latest version of this file.
41
--
42
-- The latest version of this file can be found at:
43
--      http://www.opencores.org/cvsweb.shtml/t400/
44
--
45
-------------------------------------------------------------------------------
46
 
47
library ieee;
48
use ieee.std_logic_1164.all;
49
 
50
use work.t400_opt_pack.all;
51
use work.t400_pack.all;
52
 
53
entity t400_decoder is
54
 
55
  generic (
56
    opt_type_g : integer := t400_opt_type_420_c
57
  );
58
  port (
59 102 arniml
    -- System Interface -------------------------------------------------------
60 2 arniml
    ck_i       : in  std_logic;
61
    ck_en_i    : in  boolean;
62
    por_i      : in  boolean;
63
    res_i      : in  boolean;
64
    out_en_i   : in  boolean;
65
    in_en_i    : in  boolean;
66
    icyc_en_i  : in  boolean;
67 102 arniml
    -- Module Control Interface -----------------------------------------------
68 2 arniml
    pc_op_o    : out pc_op_t;
69
    stack_op_o : out stack_op_t;
70
    dmem_op_o  : out dmem_op_t;
71
    b_op_o     : out b_op_t;
72
    skip_op_o  : out skip_op_t;
73
    alu_op_o   : out alu_op_t;
74
    io_l_op_o  : out io_l_op_t;
75
    io_d_op_o  : out io_d_op_t;
76
    io_g_op_o  : out io_g_op_t;
77 48 arniml
    io_in_op_o : out io_in_op_t;
78 2 arniml
    sio_op_o   : out sio_op_t;
79
    dec_data_o : out dec_data_t;
80
    en_o       : out dw_t;
81 102 arniml
    -- Skip Interface ---------------------------------------------------------
82 2 arniml
    skip_i     : in  boolean;
83
    skip_lbi_i : in  boolean;
84 102 arniml
    is_lbi_o   : out boolean;
85 70 arniml
    int_i      : in  boolean;
86 102 arniml
    -- Program Memory Interface -----------------------------------------------
87 2 arniml
    pm_addr_i  : in  pc_t;
88
    pm_data_i  : in  byte_t
89
  );
90
 
91
end t400_decoder;
92
 
93
 
94
library ieee;
95
use ieee.numeric_std.all;
96
 
97 166 arniml
use work.t400_mnemonic_pack.all;
98 2 arniml
 
99
architecture rtl of t400_decoder is
100
 
101 166 arniml
  signal cyc_cnt_q      : unsigned(2 downto 0);
102 2 arniml
  signal ibyte1_q,
103 166 arniml
         ibyte2_q       : byte_t;
104 2 arniml
 
105 166 arniml
  signal opcode_s       : byte_t;
106
  signal second_cyc_q   : boolean;
107
  signal mnemonic_rec_s : mnemonic_rec_t;
108 2 arniml
  signal mnemonic_s,
109 166 arniml
         mnemonic_q     : mnemonic_t;
110 2 arniml
  signal multi_byte_s,
111 166 arniml
         multi_byte_q   : boolean;
112
  signal last_cycle_s   : boolean;
113
  signal force_mc_s     : boolean;
114 2 arniml
 
115 166 arniml
  signal en_q           : dw_t;
116
  signal set_en_s       : boolean;
117
  signal ack_int_s      : boolean;
118 2 arniml
 
119
begin
120
 
121
  -----------------------------------------------------------------------------
122
  -- Theory of operation:
123
  --
124 70 arniml
  -- a) One instruction cycle lasts at least 4 ck_i cycles.
125 2 arniml
  -- b) PC for instruction/parameter fetch must be valid during cycle 2.
126
  --      => cycle 2 is the opcode fetch cycle
127
  -- c) Cycle 3 is the opcode decode cycle.
128
  --      => opcode_s is valid with cycle 3
129
  -- d) mnemonic_q is then valid with cycle 0 until end of instruction.
130
  --    So is ibyte1_q.
131
  -- e) PC for is incremented during last instruction cycle.
132
  --      => fetch of either new instruction or second instruction byte
133
  -- f) Second instruction byte is saved in ibyte2_q for cycle 0.
134
  --    Valid until end of instruction.
135
  --
136
  -- Constraints:
137
  --
138
  -- a) PC of next instruction must be pushed in cycle 0 or 1.
139
  -- b) PC for next instruction must be poped latest in cycle 1.
140
  -- c) PC for next instruction can only be calculated latest in cycle 1.
141
  -- d) IO output is enabled by out_en_i
142
  -- e) IO inputs are sampled with in_en_i
143
  --
144
  -- d) and e) are required for proper timing in relation to phi1
145
  -- (SK clock/sync output).
146
  --
147
  -- Conventions:
148
  --
149
  -- a) ALU operations take place in cycle 1.
150
  --
151
  -----------------------------------------------------------------------------
152
 
153
  last_cycle_s <= (not multi_byte_q and
154
                   not second_cyc_q and not force_mc_s)
155
                  or
156
                  second_cyc_q;
157
 
158
 
159
  -----------------------------------------------------------------------------
160
  -- Process seq
161
  --
162
  -- Purpose:
163
  --   Implements the various sequential elements.
164
  --     Cycle counter:
165
  --       It identifies the execution cycle of the
166
  --       current instruction.
167
  --     Instruction registers:
168
  --       They save the first and second byte of an instruction for
169
  --       further processing.
170
  --     New instruction flag:
171
  --       Indicates when a new instruction is fetched from the program
172
  --       memory. Implemented as a flip-flop to control the multiplexer
173
  --       which saves power by gating the combinational opcode decoder.
174
  --     Mnemonic register:
175
  --       Latches the decoded mnemonic of the current instruction.
176
  --     Multi byte flag:
177
  --       Latches the decoded multi byte status information.
178
  --
179
  seq: process (ck_i, por_i)
180
  begin
181
    if por_i then
182
      cyc_cnt_q    <= to_unsigned(1, cyc_cnt_q'length);
183
      second_cyc_q <= false;
184
      ibyte1_q     <= (others => '0');
185
      ibyte2_q     <= (others => '0');
186
      mnemonic_q   <= MN_CLRA;
187
      multi_byte_q <= false;
188
      en_q         <= (others => '0');
189
 
190
    elsif ck_i'event and ck_i = '1' then
191
      if    res_i then
192
        -- synchronous reset upon external reset event
193
        mnemonic_q     <= MN_CLRA;
194
        multi_byte_q   <= false;
195
        cyc_cnt_q      <= (others => '0');
196
        en_q           <= (others => '0');
197
 
198
      elsif ck_en_i then
199
        -- cycle counter ------------------------------------------------------
200
        if    icyc_en_i then
201
          -- new instruction cycle started
202
          cyc_cnt_q    <= (others => '0');
203
        elsif cyc_cnt_q /= 4 then
204
          cyc_cnt_q    <= cyc_cnt_q + 1;
205
        end if;
206
 
207
        -- second cycle flag --------------------------------------------------
208
        if icyc_en_i then
209
          if not last_cycle_s then
210
            second_cyc_q <= true;
211
          else
212
            second_cyc_q <= false;
213
          end if;
214
        end if;
215
 
216
        -- instruction byte 1 and mnemonic info -------------------------------
217
        if icyc_en_i and last_cycle_s then
218 88 arniml
          if not ack_int_s then
219
            -- update instruction descriptors in normal mode
220
            ibyte1_q     <= pm_data_i;
221
            mnemonic_q   <= mnemonic_s;
222
            multi_byte_q <= multi_byte_s;
223
          else
224
            -- force NOP instruction when vectoring to interrupt routine
225
            ibyte1_q     <= "01000100";
226
            mnemonic_q   <= MN_NOP;
227
            multi_byte_q <= false;
228
          end if;
229 2 arniml
        end if;
230
 
231
        -- instruction byte 2 -------------------------------------------------
232
        if icyc_en_i and not last_cycle_s then
233
          ibyte2_q     <= pm_data_i;
234
        end if;
235
 
236
        -- EN register --------------------------------------------------------
237 70 arniml
        if    set_en_s then
238 2 arniml
          en_q         <= ibyte2_q(dw_range_t);
239 70 arniml
        elsif ack_int_s then
240
          -- reset interrupt enable when INT has been acknowledged
241
          en_q(1)      <= '0';
242 2 arniml
        end if;
243
 
244
      end if;
245
    end if;
246
  end process seq;
247
  --
248
  -----------------------------------------------------------------------------
249
 
250
 
251
  -----------------------------------------------------------------------------
252
  -- Opcode multiplexer
253
  -----------------------------------------------------------------------------
254
  opcode_s <=   pm_data_i
255
              when icyc_en_i else
256
                ibyte1_q;
257
 
258
  -----------------------------------------------------------------------------
259
  -- Opcode decoder table
260 166 arniml
  --
261
  mnemonic_rec_s <= decode_opcode_f(opcode   => opcode_s,
262
                                    opt_type => opt_type_g);
263
  --
264
  mnemonic_s   <= mnemonic_rec_s.mnemonic;
265
  multi_byte_s <= mnemonic_rec_s.multi_byte;
266
  --
267 2 arniml
  -----------------------------------------------------------------------------
268
 
269
 
270
  -----------------------------------------------------------------------------
271
  -- Process decoder_ctrl
272
  --
273
  -- Purpose:
274
  --   Implements the controlling logic of the decoder module.
275
  --
276
  decoder_ctrl: process (icyc_en_i,
277
                         out_en_i, in_en_i,
278
                         cyc_cnt_q,
279 12 arniml
                         mnemonic_q, second_cyc_q, last_cycle_s,
280 2 arniml
                         ibyte1_q, ibyte2_q,
281
                         skip_i, skip_lbi_i,
282 70 arniml
                         en_q, int_i,
283 2 arniml
                         pm_addr_i, pm_data_i)
284 70 arniml
    variable cyc_v        : natural range 0 to 4;
285
    variable t41x_type_v,
286
             t420_type_v  : boolean;
287 88 arniml
    variable en_int_v     : boolean;
288 2 arniml
  begin
289
    -- default assignments
290
    pc_op_o     <= PC_NONE;
291
    stack_op_o  <= STACK_NONE;
292
    dmem_op_o   <= DMEM_RB;             -- default is read via B
293
    b_op_o      <= B_NONE;
294
    skip_op_o   <= SKIP_NONE;
295
    alu_op_o    <= ALU_NONE;
296
    io_l_op_o   <= IOL_NONE;
297
    io_d_op_o   <= IOD_NONE;
298
    io_g_op_o   <= IOG_NONE;
299 48 arniml
    io_in_op_o  <= IOIN_NONE;
300 2 arniml
    sio_op_o    <= SIO_NONE;
301
    dec_data_o  <= (others => '0');
302
    is_lbi_o    <= false;
303
    set_en_s    <= false;
304
    force_mc_s  <= false;
305 88 arniml
    en_int_v    := true;
306 70 arniml
    ack_int_s   <= false;
307 2 arniml
    cyc_v       := to_integer(cyc_cnt_q);
308
    -- determine type
309
    t41x_type_v := opt_type_g = t400_opt_type_410_c;
310 70 arniml
    t420_type_v := opt_type_g = t400_opt_type_420_c;
311 2 arniml
 
312
    if icyc_en_i then
313
      -- immediately increment program counter
314
      -- this happens at two occasions:
315
      -- a) right before new mnemonic becomes valid
316
      -- b) before the second instruction cycle begins
317
      pc_op_o   <= PC_INC_PC;
318
    end if;
319
 
320
    if icyc_en_i and last_cycle_s then
321
      -- update skip state when last instruction cycle ends
322
      skip_op_o <= SKIP_UPDATE;
323
    end if;
324
 
325
    -- skip instruction execution
326
    if not skip_i then
327
      -- implement instruction control
328
      case mnemonic_q is
329
        -- Mnemonic ASC -------------------------------------------------------
330
        when MN_ASC =>
331
          if cyc_v = 1 then
332
            alu_op_o     <= ALU_ADD_C;
333
            skip_op_o    <= SKIP_CARRY;
334
          end if;
335
 
336
        -- Mnemonic ADD -------------------------------------------------------
337
        when MN_ADD =>
338
          if cyc_v = 1 then
339
            alu_op_o     <= ALU_ADD;
340
          end if;
341
 
342
        -- Mnemonic ADT -------------------------------------------------------
343
        when MN_ADT =>
344
          if cyc_v = 1 then
345
            alu_op_o     <= ALU_ADD_10;
346
          end if;
347
 
348
        -- Mnemonic AISC ------------------------------------------------------
349
        when MN_AISC =>
350
          dec_data_o(dw_range_t) <= ibyte1_q(dw_range_t);
351
          if cyc_v = 1 then
352
            alu_op_o     <= ALU_ADD_DEC;
353
            skip_op_o    <= SKIP_CARRY;
354
          end if;
355
 
356
        -- Mnemonic CASC ------------------------------------------------------
357
        when MN_CASC =>
358
          case cyc_v is
359
            when 0 =>
360
              alu_op_o   <= ALU_COMP;
361
            when 1 =>
362
              alu_op_o   <= ALU_ADD_C;
363
              skip_op_o  <= SKIP_CARRY;
364
            when others =>
365
              null;
366
          end case;
367
 
368
        -- Mnemonic CLRA ------------------------------------------------------
369
        when MN_CLRA =>
370
          if cyc_v = 1 then
371
            alu_op_o     <= ALU_CLRA;
372
          end if;
373
 
374
        -- Mnemonic COMP ------------------------------------------------------
375
        when MN_COMP =>
376
          if cyc_v = 1 then
377
            alu_op_o     <= ALU_COMP;
378
          end if;
379
 
380
        -- Mnemonic NOP -------------------------------------------------------
381
        when MN_NOP =>
382
          -- do nothing
383
          null;
384
 
385
        -- Mnemonic C ---------------------------------------------------------
386
        when MN_C =>
387
          if cyc_v = 1 then
388
            if ibyte1_q(4) = '1' then
389
              alu_op_o   <= ALU_RC;
390
            else
391
              alu_op_o   <= ALU_SC;
392
            end if;
393
          end if;
394
 
395
        -- Mnemonic XOR -------------------------------------------------------
396
        when MN_XOR =>
397
          if cyc_v = 1 then
398
            alu_op_o     <= ALU_XOR;
399
          end if;
400
 
401
        -- Mnemonic JID -------------------------------------------------------
402
        when MN_JID =>
403
          force_mc_s     <= true;
404 88 arniml
          en_int_v       := false;
405 2 arniml
          dec_data_o(byte_t'range) <= pm_data_i;
406
          if cyc_v = 1 then
407
            if not second_cyc_q then
408
              -- first cycle: load PC from A and M
409
              pc_op_o    <= PC_LOAD_A_M;
410
            else
411
              -- second cycle: load PC from program memory
412
              pc_op_o    <= PC_LOAD_8;
413
            end if;
414
          end if;
415
 
416
          if icyc_en_i and not second_cyc_q then
417
            -- do not increment PC for second instruction cycle
418
            pc_op_o      <= PC_NONE;
419
          end if;
420
 
421
        -- Mnemonic JMP -------------------------------------------------------
422
        when MN_JMP =>
423 88 arniml
          en_int_v       := false;
424 2 arniml
          dec_data_o <= ibyte1_q(1) & ibyte1_q(0) & ibyte2_q;
425
          if second_cyc_q and cyc_v = 1 then
426
            pc_op_o      <= PC_LOAD;
427
          end if;
428
 
429
        -- Mnemonic JP_JSRP ---------------------------------------------------
430
        when MN_JP_JSRP =>
431 88 arniml
          en_int_v       := false;
432 2 arniml
          -- universal decoder data
433
          dec_data_o <= '0' & "01" & ibyte1_q(6 downto 0);
434
          if cyc_v = 1 then
435
            if    pm_addr_i(9 downto 7) = "001" then
436
              -- JP within pages 2 & 3
437
              pc_op_o    <= PC_LOAD_7;
438
            elsif ibyte1_q(6) = '1' then
439
              -- JP outside of pages 2 & 3
440
              pc_op_o    <= PC_LOAD_6;
441
            else
442
              -- JSRP to page 2
443
              pc_op_o    <= PC_LOAD;
444
              stack_op_o <= STACK_PUSH;
445
            end if;
446
          end if;
447
 
448
        -- Mnemonic JSR -------------------------------------------------------
449
        when MN_JSR =>
450 88 arniml
          en_int_v       := false;
451 2 arniml
          dec_data_o <= ibyte1_q(1) & ibyte1_q(0) & ibyte2_q;
452
          if second_cyc_q and cyc_v = 1 then
453
            pc_op_o      <= PC_LOAD;
454
            stack_op_o   <= STACK_PUSH;
455
          end if;
456
 
457
        -- Mnemonic RET -------------------------------------------------------
458
        when MN_RET =>
459 88 arniml
          en_int_v       := false;
460 2 arniml
          if cyc_v = 1 then
461
            pc_op_o      <= PC_POP;
462
            stack_op_o   <= STACK_POP;
463 70 arniml
 
464
            if t420_type_v then
465
              -- always restore skip state in case this was an interrupt
466
              skip_op_o  <= SKIP_POP;
467
            end if;
468 2 arniml
          end if;
469
 
470
        -- Mnemonic RETSK -----------------------------------------------------
471
        when MN_RETSK =>
472 88 arniml
          en_int_v       := false;
473 2 arniml
          if cyc_v = 1 then
474
            pc_op_o      <= PC_POP;
475
            stack_op_o   <= STACK_POP;
476
            skip_op_o    <= SKIP_NOW;
477
          end if;
478
 
479
        -- Mnemonic LD --------------------------------------------------------
480
        when MN_LD =>
481
          dec_data_o(br_range_t) <= ibyte1_q(br_range_t);
482
          if cyc_v = 1 then
483
            alu_op_o     <= ALU_LOAD_M;
484
            b_op_o       <= B_XOR_BR;
485
          end if;
486
 
487
        -- Mnemonic LDD_XAD ---------------------------------------------------
488
        when MN_LDD_XAD =>
489
          -- preload decoder data
490
          dec_data_o(b_range_t) <= ibyte2_q(b_range_t);
491
 
492
          if second_cyc_q then
493
            case ibyte2_q(7 downto 6) is
494
              -- LDD
495
              when "00" =>
496
                if not t41x_type_v then
497
                  case cyc_v is
498
                    when 1 =>
499
                      dmem_op_o <= DMEM_RDEC;
500
                    when 2 =>
501
                      alu_op_o  <= ALU_LOAD_M;
502
                    when others =>
503
                      null;
504
                  end case;
505
                end if;
506
                -- XAD
507
              when "10" =>
508
                if not t41x_type_v                   or
509
                  unsigned(ibyte2_q(b_range_t)) = 63 then
510
                  case cyc_v is
511
                    when 1 =>
512
                      dmem_op_o <= DMEM_RDEC;
513
                    when 2 =>
514
                      alu_op_o  <= ALU_LOAD_M;
515
                      dmem_op_o <= DMEM_WDEC_SRC_A;
516
                    when others =>
517
                      null;
518
                  end case;
519
                end if;
520
 
521
              when others =>
522
                null;
523
            end case;
524
          end if;
525
 
526
        -- Mnemonic LQID ------------------------------------------------------
527
        when MN_LQID =>
528
          force_mc_s     <= true;
529 88 arniml
          en_int_v       := false;
530 2 arniml
          if not second_cyc_q then
531
            -- first cycle: push PC and set PC from A/M,
532
            --              read IOL from program memory
533
            if cyc_v = 1 then
534
              stack_op_o <= STACK_PUSH;
535
              pc_op_o    <= PC_LOAD_A_M;
536
            end if;
537
 
538
            if out_en_i then
539
              io_l_op_o  <= IOL_LOAD_PM;
540
            end if;
541
          else
542
            if cyc_v = 1 then
543
              -- second cycle: pop PC
544
              stack_op_o <= STACK_POP;
545
              pc_op_o    <= PC_POP;
546
            end if;
547
          end if;
548
 
549
          if icyc_en_i and not second_cyc_q then
550
            -- do not increment PC for second instruction cycle
551
            pc_op_o      <= PC_NONE;
552
          end if;
553
 
554
        -- Mnemonic RMB -------------------------------------------------------
555
        when MN_RMB =>
556
          if cyc_v = 1 then
557
            dmem_op_o  <= DMEM_WB_RES_BIT;
558
            -- select bit to be reset
559
            case ibyte1_q(dw_range_t) is
560
              when "1100" =>
561
                dec_data_o(dw_range_t) <= "0001";
562
              when "0101" =>
563
                dec_data_o(dw_range_t) <= "0010";
564
              when "0010" =>
565
                dec_data_o(dw_range_t) <= "0100";
566
              when "0011" =>
567
                dec_data_o(dw_range_t) <= "1000";
568
              when others =>
569
                null;
570
            end case;
571
          end if;
572
 
573
        -- Mnemonic SMB -------------------------------------------------------
574
        when MN_SMB =>
575
          if cyc_v = 1 then
576
            dmem_op_o  <= DMEM_WB_SET_BIT;
577
            -- select bit to be set
578
            case ibyte1_q(dw_range_t) is
579
              when "1101" =>
580
                dec_data_o(dw_range_t) <= "0001";
581
              when "0111" =>
582
                dec_data_o(dw_range_t) <= "0010";
583
              when "0110" =>
584
                dec_data_o(dw_range_t) <= "0100";
585
              when "1011" =>
586
                dec_data_o(dw_range_t) <= "1000";
587
              when others =>
588
                null;
589
            end case;
590
          end if;
591
 
592
        -- Mnemonic STII ------------------------------------------------------
593
        when MN_STII =>
594
          dec_data_o(dw_range_t) <= ibyte1_q(dw_range_t);
595
          if cyc_v = 1 then
596
            dmem_op_o    <= DMEM_WB_SRC_DEC;
597
            b_op_o       <= B_INC_BD;
598
          end if;
599
 
600
        -- Mnemonic X ---------------------------------------------------------
601
        when MN_X =>
602
          dec_data_o(br_range_t) <= ibyte1_q(br_range_t);
603
          if cyc_v = 1 then
604
            alu_op_o     <= ALU_LOAD_M;
605
            dmem_op_o    <= DMEM_WB_SRC_A;
606
            b_op_o       <= B_XOR_BR;
607
          end if;
608
 
609
        -- Mnemonic XDS -------------------------------------------------------
610
        when MN_XDS =>
611
          dec_data_o(br_range_t) <= ibyte1_q(br_range_t);
612
          case cyc_v is
613
            when 1 =>
614
              alu_op_o   <= ALU_LOAD_M;
615
              dmem_op_o  <= DMEM_WB_SRC_A;
616
              b_op_o     <= B_DEC_BD;
617
            when 2 =>
618
              b_op_o     <= B_XOR_BR;
619
              skip_op_o  <= SKIP_BD_UFLOW;
620
            when others =>
621
              null;
622
          end case;
623
 
624
        -- Mnemonic XIS -------------------------------------------------------
625
        when MN_XIS =>
626
          dec_data_o(br_range_t) <= ibyte1_q(br_range_t);
627
          case cyc_v is
628
            when 1 =>
629
              alu_op_o   <= ALU_LOAD_M;
630
              dmem_op_o  <= DMEM_WB_SRC_A;
631
              b_op_o     <= B_INC_BD;
632
            when 2 =>
633
              b_op_o     <= B_XOR_BR;
634
              skip_op_o  <= SKIP_BD_OFLOW;
635
            when others =>
636
              null;
637
          end case;
638
 
639
        -- Mnemonic CAB -------------------------------------------------------
640
        when MN_CAB =>
641
          if cyc_v = 1 then
642
            b_op_o       <= B_SET_BD;
643
          end if;
644
 
645
        -- Mnemonic CBA -------------------------------------------------------
646
        when MN_CBA =>
647
          if cyc_v = 1 then
648
            alu_op_o     <= ALU_LOAD_BD;
649
          end if;
650
 
651
        -- Mnemonic LBI -------------------------------------------------------
652
        when MN_LBI =>
653
          is_lbi_o       <= true;
654 88 arniml
          en_int_v       := false;
655 2 arniml
          dec_data_o(br_range_t) <= ibyte1_q(br_range_t);
656
          dec_data_o(bd_range_t) <= ibyte1_q(bd_range_t);
657
          if cyc_v = 1 and not skip_lbi_i then
658
            -- increment Bd by 1
659
            b_op_o       <= B_SET_B_INC;
660
            skip_op_o    <= SKIP_LBI;
661
          end if;
662
 
663
        -- Mnemonic XABR ------------------------------------------------------
664
        when MN_XABR =>
665
          if cyc_v = 1 then
666
            alu_op_o     <= ALU_LOAD_BR;
667
            b_op_o       <= B_SET_BR;
668
          end if;
669
 
670
        -- Mnemonic SKC -------------------------------------------------------
671
        when MN_SKC =>
672
          if cyc_v = 1 then
673
            skip_op_o    <= SKIP_C;
674
          end if;
675
 
676
        -- Mnemonic SKE -------------------------------------------------------
677
        when MN_SKE =>
678
          if cyc_v = 1 then
679
            skip_op_o    <= SKIP_A_M;
680
          end if;
681
 
682
        -- Mnemonic SKMBZ -----------------------------------------------------
683
        when MN_SKMBZ =>
684
          if cyc_v = 1 then
685
            skip_op_o  <= SKIP_M_BIT;
686
            -- select bit to be checked
687
            case ibyte1_q is
688
              when "00000001" =>
689
                dec_data_o(dw_range_t) <= "0001";
690
              when "00010001" =>
691
                dec_data_o(dw_range_t) <= "0010";
692
              when "00000011" =>
693
                dec_data_o(dw_range_t) <= "0100";
694
              when "00010011" =>
695
                dec_data_o(dw_range_t) <= "1000";
696
              when others =>
697
                null;
698
            end case;
699
          end if;
700
 
701
        -- Mnemonic SKT -------------------------------------------------------
702
        when MN_SKT =>
703
          if cyc_v = 1 then
704
            skip_op_o  <= SKIP_TIMER;
705
          end if;
706
 
707
        -- Mnemonic XAS -------------------------------------------------------
708
        when MN_XAS =>
709
          if out_en_i then
710
            sio_op_o <= SIO_LOAD;
711
            alu_op_o <= ALU_LOAD_SIO;
712
          end if;
713
 
714
        -- Mnemonic EXT -------------------------------------------------------
715
        when MN_EXT =>
716
          if second_cyc_q then
717
            case ibyte2_q is
718
              -- CAMQ
719
              when "00111100" =>
720
                if out_en_i then
721
                  io_l_op_o <= IOL_LOAD_AM;
722
                end if;
723
              -- CQMA
724
              when "00101100" =>
725
                if not t41x_type_v and in_en_i then
726
                  io_l_op_o <= IOL_OUTPUT_Q;
727
                  alu_op_o  <= ALU_LOAD_Q;
728
                  dmem_op_o <= DMEM_WB_SRC_Q;
729
                end if;
730
              -- SKGZ
731
              when "00100001" =>
732
                if in_en_i then
733
                  skip_op_o <= SKIP_G_ZERO;
734
                end if;
735
              -- SKGBZ
736
              when "00000001" =>
737
                if in_en_i then
738
                  skip_op_o <= SKIP_G_BIT;
739
                  dec_data_o(dw_range_t) <= "0001";
740
                end if;
741
              when "00010001" =>
742
                if in_en_i then
743
                  skip_op_o <= SKIP_G_BIT;
744
                  dec_data_o(dw_range_t) <= "0010";
745
                end if;
746
              when "00000011" =>
747
                if in_en_i then
748
                  skip_op_o <= SKIP_G_BIT;
749
                  dec_data_o(dw_range_t) <= "0100";
750
                end if;
751
              when "00010011" =>
752
                if in_en_i then
753
                  skip_op_o <= SKIP_G_BIT;
754
                  dec_data_o(dw_range_t) <= "1000";
755
                end if;
756
              -- ING
757
              when "00101010" =>
758
                if cyc_v = 1 then
759
                  alu_op_o  <= ALU_LOAD_G;
760
                end if;
761
              -- INL
762
              when "00101110" =>
763
                if in_en_i then
764
                  io_l_op_o <= IOL_OUTPUT_L;
765
                  alu_op_o  <= ALU_LOAD_Q;
766
                  dmem_op_o <= DMEM_WB_SRC_Q;
767
                end if;
768 48 arniml
              -- ININ
769
              when "00101000" =>
770
                if not t41x_type_v and in_en_i then
771
                  alu_op_o  <= ALU_LOAD_IN;
772
                end if;
773
              -- INIL
774
              when "00101001" =>
775
                if not t41x_type_v and in_en_i then
776
                  alu_op_o   <= ALU_LOAD_IL;
777
                  io_in_op_o <= IOIN_INIL;
778
                end if;
779 2 arniml
              -- OBD
780
              when "00111110" =>
781
                if out_en_i then
782
                  io_d_op_o <= IOD_LOAD;
783
                end if;
784
              -- OMG
785
              when "00111010" =>
786
                if out_en_i then
787
                  io_g_op_o <= IOG_LOAD_M;
788
                end if;
789
              -- multiple codes
790
              when others =>
791
                -- apply default decoder output, largest required vector
792
                dec_data_o(b_range_t) <= ibyte2_q(b_range_t);
793
                -- LBI
794
                if ibyte2_q(7 downto 6) = "10" and not t41x_type_v then
795
                  is_lbi_o    <= true;
796 88 arniml
                  en_int_v    := false;
797 2 arniml
                  if cyc_v > 0 and not skip_lbi_i then
798
                    b_op_o    <= B_SET_B;
799
                    skip_op_o <= SKIP_LBI;
800
                  end if;
801
                end if;
802
                -- LEI
803
                if ibyte2_q(7 downto 4) = "0110" and in_en_i then
804
                  -- dec_data_o applied by default
805
                  set_en_s   <= true;
806 70 arniml
 
807
                  -- acknowledge pending interrupt when EN(1) is not
808
                  -- enabled - will clear them until interrupts are
809
                  -- enabled with EN(1) = '1'
810
                  if en_q(1) = '0' then
811
                    io_in_op_o <= IOIN_INTACK;
812
                  end if;
813 2 arniml
                end if;
814
                -- OGI
815
                if ibyte2_q(7 downto 4) = "0101" and out_en_i and
816
                   not t41x_type_v then
817
                  -- dec_data_o applied by default
818
                  io_g_op_o  <= IOG_LOAD_DEC;
819
                end if;
820
            end case;
821
          end if;
822
 
823
        when others =>
824
          null;
825
      end case;
826
    end if;
827 70 arniml
 
828
 
829
    -- Interrupt handling -----------------------------------------------------
830
    if t420_type_v and
831 88 arniml
       en_q(1) = '1' and int_i and en_int_v then
832 70 arniml
      if last_cycle_s then
833
        if cyc_v = 1 then
834
          stack_op_o <= STACK_PUSH;
835
        end if;
836
        if icyc_en_i then
837
          ack_int_s  <= true;
838
          io_in_op_o <= IOIN_INTACK;
839 88 arniml
          pc_op_o    <= PC_INT;
840 70 arniml
          -- push skip state that was determined by current instruction
841
          -- and will be valid for the next instruction which is delayed
842
          -- by the interrupt
843
          skip_op_o  <= SKIP_PUSH;
844
        end if;
845
      end if;
846
    end if;
847
 
848 2 arniml
  end process decoder_ctrl;
849
  --
850
  -----------------------------------------------------------------------------
851
 
852
 
853
  -----------------------------------------------------------------------------
854
  -- Output mapping
855
  -----------------------------------------------------------------------------
856
  en_o <= en_q;
857
 
858
end rtl;

powered by: WebSVN 2.1.0

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