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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_cpu.vhd] - Blame information for rev 10

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

Line No. Rev Author Line
1 7 jshamlet
-- Copyright (c)2006, Jeremy Seth Henry
2
-- All rights reserved.
3
--
4
-- Redistribution and use in source and binary forms, with or without
5
-- modification, are permitted provided that the following conditions are met:
6
--     * Redistributions of source code must retain the above copyright
7
--       notice, this list of conditions and the following disclaimer.
8
--     * Redistributions in binary form must reproduce the above copyright
9
--       notice, this list of conditions and the following disclaimer in the
10
--       documentation and/or other materials provided with the distribution,
11
--       where applicable (as part of a user interface, debugging port, etc.)
12
--
13
-- THIS SOFTWARE IS PROVIDED BY JEREMY SETH HENRY ``AS IS'' AND ANY
14
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
-- DISCLAIMED. IN NO EVENT SHALL JEREMY SETH HENRY BE LIABLE FOR ANY
17
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
 
24
-- VHDL Units :  Open8_CPU
25
-- Description:  VHDL model of the V8 uRISC 8-bit processor core
26
-- Notes      :  Generic definitions
27
--            :  Stack_Start_Address - determines the initial (reset) value of
28
--            :   the stack pointer. Also used for the RSP instruction if
29
--            :   Allow_Stack_Address_Move is 0.
30
--            :
31
--            :  Allow_Stack_Address_Move - When set to 1, allows the RSP to be
32
--            :   programmed via thet RSP instruction. If enabled, the contents
33
--            :   of R1:R0 are used to initialize the stack pointer.
34
--            :
35
--            :  ISR_Start_Addr - determines the location of the interrupt
36
--            :   service vector table. There are 8 service vectors, or 16
37
--            :   bytes, which must be allocated to either ROM or RAM.
38
--            :
39
--            :  Program_Start_Addr - Determines the initial value of the
40
--            :   program counter.
41
--            :
42
--            :  Default_Interrupt_Mask - Determines the intial value of the
43
--            :   interrupt mask. To remain true to the original core, which
44
--            :   had no interrupt mask, this should be set to x"FF". Otherwise
45
--            :   it can be initialized to any value.
46
--            :
47
--            :  Enable_CPU_Halt - determines whether the CPU_Halt pin is
48
--            :   connected or not. This signal is typically used to halt the
49
--            :   processor for a few cycles when accessing slower peripherals,
50
--            :   but may also be used to single step the processor. If this
51
--            :   feature isn't used, it can be disabled to increase Fmax.
52
--            :
53
--            :  The CPU_Halt signal can be used to access slower peripherals
54
--            :   by allowing the device to "pause" the CPU. This can be used,
55
--            :   for example, to write to a standard LCD panel, which requires
56
--            :   a 4MHz interface, by halting on writes. Alternately, devices
57
--            :   such as SDRAM controllers, can pause the processor until the
58
--            :   data is ready to be presented.
59
--            :
60
--            :  The Enable_Auto_Increment generic can be used to modify the
61
--            :   indexed instructions such that specifying an odd register
62
--            :   will use the next lower register pair, post-incrementing the
63
--            :   value in that pair. IOW, specifying STX R1 will instead
64
--            :   result in STX R0++, or R0 = {R1:R0}; {R1:R0} + 1
65
--            :
66
--            : Instructions USR and USR2 have been replaced with DBNZ, and MUL
67
--            :  respectively. DBNZ decrements the specified register, and will
68
--            :  branch if the result is non-zero (Zero flag is not set). MUL
69
--            :  places the result of R0 * Rn into R1:R0, and executes in two
70
--            :  cycles. (R1:R0 = R0 * Rn)
71
--            :
72
-- Revision History
73
-- Author          Date     Change
74
------------------ -------- ---------------------------------------------------
75
-- Seth Henry      07/19/06 Design Start
76 10 khays
-- Seth Henry      01/18/11 Fixed BTT instruction to match V8
77 7 jshamlet
 
78
library ieee;
79
  use ieee.std_logic_1164.all;
80
  use ieee.std_logic_unsigned.all;
81
  use ieee.std_logic_arith.all;
82
 
83
library work;
84
use work.Open8_pkg.all;
85
 
86
entity Open8_CPU is
87
  generic(
88
    Stack_Start_Addr         : ADDRESS_TYPE := x"007F"; -- Top of Stack
89
    Allow_Stack_Address_Move : std_logic    := '0';     -- Use Normal v8 RSP
90
    ISR_Start_Addr           : ADDRESS_TYPE := x"0080"; -- Bottom of ISR vec's
91
    Program_Start_Addr       : ADDRESS_TYPE := x"0090"; -- Initial PC location
92
    Default_Interrupt_Mask   : DATA_TYPE    := x"FF";   -- Enable all Ints
93
    Enable_CPU_Halt          : std_logic    := '0';     -- Disable HALT pin
94
    Enable_Auto_Increment    : std_logic    := '0' );   -- Modify indexed instr
95
  port(
96
    Clock                    : in  std_logic;
97 10 khays
    Reset                    : in  std_logic;
98 7 jshamlet
    CPU_Halt                 : in  std_logic;
99
    Interrupts               : in  INTERRUPT_BUNDLE;
100
    --
101
    Address                  : out ADDRESS_TYPE;
102
    Rd_Data                  : in  DATA_TYPE;
103
    Rd_Enable                : out std_logic;
104
    Wr_Data                  : out DATA_TYPE;
105
    Wr_Enable                : out std_logic );
106
end entity;
107
 
108
architecture rtl of Open8_CPU is
109
  subtype OPCODE_TYPE  is std_logic_vector(4 downto 0);
110
  subtype SUBOP_TYPE   is std_logic_vector(2 downto 0);
111
 
112
  -- Most of the ALU instructions are the same as their Opcode equivalents with
113
  -- three exceptions (for IDLE, UPP2, and MUL2)
114
  constant ALU_INC           : OPCODE_TYPE := "00000"; -- x"00"
115
  constant ALU_ADC           : OPCODE_TYPE := "00001"; -- x"01"
116
  constant ALU_TX0           : OPCODE_TYPE := "00010"; -- x"02"
117
  constant ALU_OR            : OPCODE_TYPE := "00011"; -- x"03"
118
  constant ALU_AND           : OPCODE_TYPE := "00100"; -- x"04"
119
  constant ALU_XOR           : OPCODE_TYPE := "00101"; -- x"05"
120
  constant ALU_ROL           : OPCODE_TYPE := "00110"; -- x"06"
121
  constant ALU_ROR           : OPCODE_TYPE := "00111"; -- x"07"
122
  constant ALU_DEC           : OPCODE_TYPE := "01000"; -- x"08"
123
  constant ALU_SBC           : OPCODE_TYPE := "01001"; -- x"09"
124
  constant ALU_ADD           : OPCODE_TYPE := "01010"; -- x"0A"
125
  constant ALU_STP           : OPCODE_TYPE := "01011"; -- x"0B"
126
  constant ALU_BTT           : OPCODE_TYPE := "01100"; -- x"0C"
127
  constant ALU_CLP           : OPCODE_TYPE := "01101"; -- x"0D"
128
  constant ALU_T0X           : OPCODE_TYPE := "01110"; -- x"0E"
129
  constant ALU_CMP           : OPCODE_TYPE := "01111"; -- x"0F"
130
  constant ALU_POP           : OPCODE_TYPE := "10001"; -- x"11"
131
  constant ALU_MUL           : OPCODE_TYPE := "10110"; -- x"16"
132
  constant ALU_UPP           : OPCODE_TYPE := "11000"; -- x"18"
133
  constant ALU_LDI           : OPCODE_TYPE := "11100"; -- x"1C"
134
  constant ALU_LDX           : OPCODE_TYPE := "11110"; -- x"1E"
135
 
136
  constant ALU_IDLE          : OPCODE_TYPE := "10000"; -- x"10"
137 10 khays
  constant ALU_UPP2          : OPCODE_TYPE := "10010"; -- x"12"
138
  constant ALU_RFLG          : OPCODE_TYPE := "10011"; -- x"13"
139 7 jshamlet
 
140
  constant FL_ZERO           : integer := 0;
141
  constant FL_CARRY          : integer := 1;
142
  constant FL_NEG            : integer := 2;
143
  constant FL_INT_EN         : integer := 3;
144
  constant FL_GP1            : integer := 4;
145
  constant FL_GP2            : integer := 5;
146
  constant FL_GP3            : integer := 6;
147
  constant FL_GP4            : integer := 7;
148
 
149
  type ALU_CTRL_TYPE is record
150
    Oper                     : OPCODE_TYPE;
151
    Reg                      : SUBOP_TYPE;
152
    Data                     : DATA_TYPE;
153
  end record;
154
 
155
  constant ACCUM             : SUBOP_TYPE := "000";
156
  constant INT_FLAG          : SUBOP_TYPE := "011";
157
 
158
  -- There are only 8 byte-wide registers - and the write register is always 0,
159
  --  so there is little point in making a RAM out of this
160
  type REGFILE_TYPE is array (0 to 7) of DATA_TYPE;
161
 
162
  subtype FLAG_TYPE is DATA_TYPE;
163
 
164
  type PC_MODES is ( PC_IDLE, PC_REV1, PC_REV2, PC_INCR, PC_LOAD );
165
 
166
  type PC_CTRL_TYPE is record
167
    Oper                     : PC_MODES;
168
    Offset                   : DATA_TYPE;
169
    Addr                     : ADDRESS_TYPE;
170
  end record;
171
 
172
  type SP_MODES is ( SP_IDLE, SP_RSET, SP_POP, SP_PUSH );
173
 
174
  type SP_CTRL_TYPE is record
175
    Oper                     : SP_MODES;
176
    Addr                     : ADDRESS_TYPE;
177
  end record;
178
 
179
  type INT_CTRL_TYPE is record
180
    Mask_Set                 : std_logic;
181
    Mask_Data                : DATA_TYPE;
182
    Soft_Ints                : INTERRUPT_BUNDLE;
183
    Incr_ISR                 : std_logic;
184
  end record;
185
 
186
  type AS_MODES is ( ADDR_PC, ADDR_SP, ADDR_IMM, ADDR_ISR);
187
 
188
  type ADDR_CTRL_TYPE is record
189
    Src                      : AS_MODES;
190
  end record;
191
 
192
  type DP_MODES is ( DATA_IDLE, DATA_REG, DATA_FLAG, DATA_PC );
193
 
194
  type DATA_CTRL_TYPE is record
195
    Src                      : DP_MODES;
196
    Reg                      : SUBOP_TYPE;
197
  end record;
198
 
199
  signal Halt                : std_logic;
200
  signal ALU_Ctrl            : ALU_CTRL_TYPE;
201
  signal ALU_Regs            : REGFILE_TYPE;
202
  signal ALU_Flags           : FLAG_TYPE;
203
  signal PC_Ctrl             : PC_CTRL_TYPE;
204
  signal SP_Ctrl             : SP_CTRL_TYPE;
205
  signal AS_Ctrl             : ADDR_CTRL_TYPE;
206
  signal DP_Ctrl             : DATA_CTRL_TYPE;
207
  signal INT_Ctrl            : INT_CTRL_TYPE;
208
  signal Int_Req, Int_Ack    : std_logic;
209
  signal Int_RTI             : std_logic;
210
  signal Int_Mask            : DATA_TYPE;
211
  signal PC                  : ADDRESS_TYPE;
212
  signal SP                  : ADDRESS_TYPE;
213
  signal ISR                 : ADDRESS_TYPE;
214
  signal IMM                 : ADDRESS_TYPE;
215
begin
216
 
217
Halt_Disabled_fn: if( Enable_CPU_Halt = '0' )generate
218
  Halt                       <= '0';
219
end generate;
220
 
221
Halt_Enabled_fn: if( Enable_CPU_Halt = '1' )generate
222
  Halt                       <= CPU_Halt;
223
end generate;
224
 
225
-------------------------------------------------------------------------------
226
-- ALU (Arithmetic / Logic Unit
227
-- Notes:
228
-- 1) Infers a multiplier in Xilinx/Altera parts - should be checked in others
229
-------------------------------------------------------------------------------
230
 
231
Open8_ALU : block is
232
 
233
  -- Preinitialization is for simulation only - check actual reset conditions
234
  signal Regfile_D, Regfile  : REGFILE_TYPE := (others => (others => '0') );
235
  signal Flags_D, Flags      : FLAG_TYPE    := (others => '0');
236
  signal Mult                : ADDRESS_TYPE := (others => '0');
237
 
238
  signal Sum                 : std_logic_vector(8 downto 0) := (others => '0');
239
  signal Addend_A, Addend_B  : DATA_TYPE    := (others => '0');
240
  signal Carry               : std_logic    := '0';
241
 
242
begin
243
 
244
  ALU_Regs                   <= Regfile;
245
  ALU_Flags                  <= Flags;
246
 
247
  ALU_proc: process( ALU_Ctrl, Regfile, Flags, Mult, Sum )
248
    variable Index             : integer range 0 to 7 := 0;
249
    variable Temp              : std_logic_vector(8 downto 0);
250
  begin
251
    Regfile_D                <= Regfile;
252
    Flags_D                  <= Flags;
253
    Addend_A                 <= x"00";
254
    Addend_B                 <= x"00";
255
    Carry                    <= '0';
256
 
257
    Temp                     := (others => '0');
258
    Index                    := conv_integer(ALU_Ctrl.Reg);
259
 
260
    case ALU_Ctrl.Oper is
261
      when ALU_INC | ALU_UPP => -- Rn = Rn + 1 : Flags N,C,Z
262
        Addend_A             <= x"01";
263
        Addend_B             <= Regfile(Index);
264
        Flags_D(FL_CARRY)    <= Sum(8);
265
        Regfile_D(Index)     <= Sum(7 downto 0);
266
        -- ALU_INC and ALU_UPP are essentially the same, except that ALU_UPP
267
        --  doesn't set the N or Z flags. Note that the MSB can be used to
268
        --  distinguish between the two ALU modes.
269
        if( ALU_Ctrl.Oper(4) = '0' )then
270
          Flags_D(FL_ZERO)   <= '0';
271
          if( Sum(7 downto 0) = 0 )then
272
            Flags_D(FL_ZERO) <= '1';
273
          end if;
274
          Flags_D(FL_NEG)    <= Sum(7);
275
        end if;
276
 
277
      when ALU_UPP2 => -- Rn = Rn + C
278
        Addend_A             <= x"00";
279
        Addend_B             <= Regfile(Index);
280
        Carry                <= Flags(FL_CARRY);
281
        Flags_D(FL_CARRY)    <= Sum(8);
282
        Regfile_D(Index)     <= Sum(7 downto 0);
283
 
284
      when ALU_ADC => -- R0 = R0 + Rn + C : Flags N,C,Z
285
        Addend_A             <= Regfile(0);
286
        Addend_B             <= Regfile(Index);
287
        Carry                <= Flags(FL_CARRY);
288
        Flags_D(FL_ZERO)     <= '0';
289
        if( Sum(7 downto 0) = 0 )then
290
          Flags_D(FL_ZERO)   <= '1';
291
        end if;
292
        Flags_D(FL_CARRY)    <= Sum(8);
293
        Flags_D(FL_NEG)      <= Sum(7);
294
        Regfile_D(0)         <= Sum(7 downto 0);
295
 
296
      when ALU_TX0 => -- R0 = Rn : Flags N,Z
297
        Temp                 := "0" & Regfile(Index);
298
        Flags_D(FL_ZERO)     <= '0';
299
        if( Temp(7 downto 0) = 0 )then
300
          Flags_D(FL_ZERO)   <= '1';
301
        end if;
302
        Flags_D(FL_NEG)      <= Temp(7);
303
        Regfile_D(0)         <= Temp(7 downto 0);
304
 
305
      when ALU_OR  => -- R0 = R0 | Rn : Flags N,Z
306
        Temp(7 downto 0)     := Regfile(0) or Regfile(Index);
307
        Flags_D(FL_ZERO)     <= '0';
308
        if( Temp(7 downto 0) = 0 )then
309
          Flags_D(FL_ZERO)   <= '1';
310
        end if;
311
        Flags_D(FL_NEG)      <= Temp(7);
312
        Regfile_D(0)         <= Temp(7 downto 0);
313
 
314
      when ALU_AND => -- R0 = R0 & Rn : Flags N,Z
315
        Temp(7 downto 0)     := Regfile(0) and Regfile(Index);
316
        Flags_D(FL_ZERO)     <= '0';
317
        if( Temp(7 downto 0) = 0 )then
318
          Flags_D(FL_ZERO)   <= '1';
319
        end if;
320
        Flags_D(FL_NEG)      <= Temp(7);
321
        Regfile_D(0)         <= Temp(7 downto 0);
322
 
323
      when ALU_XOR => -- R0 = R0 ^ Rn : Flags N,Z
324
        Temp(7 downto 0)     := Regfile(0) xor Regfile(Index);
325
        Flags_D(FL_ZERO)     <= '0';
326
        if( Temp(7 downto 0) = 0 )then
327
          Flags_D(FL_ZERO)   <= '1';
328
        end if;
329
        Flags_D(FL_NEG)      <= Temp(7);
330
        Regfile_D(0)         <= Temp(7 downto 0);
331
 
332
      when ALU_ROL => -- Rn = Rn<<1,C : Flags N,C,Z
333
        Temp                 := Regfile(Index) & Flags(FL_CARRY);
334
        Flags_D(FL_ZERO)     <= '0';
335
        if( Temp(7 downto 0) = 0 )then
336
          Flags_D(FL_ZERO)   <= '1';
337
        end if;
338
        Flags_D(FL_CARRY)    <= Temp(8);
339
        Flags_D(FL_NEG)      <= Temp(7);
340
        Regfile_D(Index)     <= Temp(7 downto 0);
341
 
342
      when ALU_ROR => -- Rn = C,Rn>>1 : Flags N,C,Z
343
        Temp                 := Regfile(Index)(0) & Flags(FL_CARRY) &
344
                                Regfile(Index)(7 downto 1);
345
        Flags_D(FL_ZERO)     <= '0';
346
        if( Temp(7 downto 0) = 0 )then
347
          Flags_D(FL_ZERO)   <= '1';
348
        end if;
349
        Flags_D(FL_CARRY)    <= Temp(8);
350
        Flags_D(FL_NEG)      <= Temp(7);
351
        Regfile_D(Index)     <= Temp(7 downto 0);
352
 
353
      when ALU_DEC => -- Rn = Rn - 1 : Flags N,C,Z
354
        Addend_A             <= Regfile(Index);
355
        Addend_B             <= x"FF";
356
        Flags_D(FL_ZERO)     <= '0';
357
        if( Sum(7 downto 0) = 0 )then
358
          Flags_D(FL_ZERO)   <= '1';
359
        end if;
360
        Flags_D(FL_CARRY)    <= Sum(8);
361
        Flags_D(FL_NEG)      <= Sum(7);
362
        Regfile_D(Index)     <= Sum(7 downto 0);
363
 
364
      when ALU_SBC => -- Rn = R0 - Rn - C : Flags N,C,Z
365
        Addend_A             <= Regfile(0);
366
        Addend_B             <= not Regfile(Index);
367
        Carry                <= Flags(FL_CARRY);
368
        Flags_D(FL_ZERO)     <= '0';
369
        if( Sum(7 downto 0) = 0 )then
370
          Flags_D(FL_ZERO)   <= '1';
371
        end if;
372
        Flags_D(FL_CARRY)    <= Sum(8);
373
        Flags_D(FL_NEG)      <= Sum(7);
374
        Regfile_D(0)         <= Sum(7 downto 0);
375
 
376
      when ALU_ADD => -- R0 = R0 + Rn : Flags N,C,Z
377
        Addend_A             <= Regfile(0);
378
        Addend_B             <= Regfile(Index);
379
        Flags_D(FL_CARRY)    <= Sum(8);
380
        Regfile_D(0)         <= Sum(7 downto 0);
381
        Flags_D(FL_ZERO)     <= '0';
382
        if( Sum(7 downto 0) = 0 )then
383
          Flags_D(FL_ZERO)   <= '1';
384
        end if;
385
        Flags_D(FL_NEG)      <= Sum(7);
386
 
387
      when ALU_STP => -- Sets bit(n) in the Flags register
388 10 khays
        Flags_D(Index)       <= '1';
389 7 jshamlet
 
390 10 khays
      when ALU_BTT => -- Z = !R0(N), N = R0(7)
391
        Flags_D(FL_ZERO)     <= not Regfile(0)(Index);
392
        Flags_D(FL_NEG)      <= Regfile(0)(7);
393
--        Temp                 := "0" & Regfile(Index);
394
--        Flags_D(FL_ZERO)     <= '0';
395
--        if( Temp(7 downto 0) = 0 )then
396
--          Flags_D(FL_ZERO)   <= '1';
397
--        end if;
398
--        Flags_D(FL_NEG)      <= Temp(7);
399 7 jshamlet
 
400
      when ALU_CLP => -- Clears bit(n) in the Flags register
401
        Flags_D(Index)         <= '0';
402
 
403
      when ALU_T0X => -- Rn = R0 : Flags N,Z
404
        Temp                 := "0" & Regfile(0);
405
        Flags_D(FL_ZERO)     <= '0';
406
        if( Temp(7 downto 0) = 0 )then
407
          Flags_D(FL_ZERO)   <= '1';
408
        end if;
409
        Flags_D(FL_NEG)      <= Temp(7);
410
        Regfile_D(Index)     <= Temp(7 downto 0);
411
 
412
      when ALU_CMP => -- Sets Flags on R0 - Rn : Flags N,C,Z
413
        Addend_A             <= Regfile(0);
414
        Addend_B             <= not Regfile(Index);
415
        Carry                <= '1';
416
        Flags_D(FL_ZERO)     <= '0';
417
        if( Sum(7 downto 0) = 0 )then
418
          Flags_D(FL_ZERO)   <= '1';
419
        end if;
420
        Flags_D(FL_CARRY)    <= Sum(8);
421
        Flags_D(FL_NEG)      <= Sum(7);
422
 
423 10 khays
      when ALU_MUL => -- Stage 1 of 2 {R1:R0} = R0 * Rn : Flags Z
424 7 jshamlet
        Regfile_D(0)         <= Mult(7 downto 0);
425
        Regfile_D(1)         <= Mult(15 downto 8);
426
        Flags_D(FL_ZERO)     <= '0';
427
        if( Mult = 0 )then
428
          Flags_D(FL_ZERO)   <= '1';
429
        end if;
430
 
431
      when ALU_LDI | ALU_POP => -- Rn <= Data : Flags N,Z
432
        -- The POP instruction doesn't alter the flags, so we need to check
433
        if( ALU_Ctrl.Oper = ALU_LDI )then
434
          Flags_D(FL_ZERO)   <= '0';
435
          if( ALU_Ctrl.Data = 0 )then
436
            Flags_D(FL_ZERO) <= '1';
437
          end if;
438
          Flags_D(FL_NEG)    <= ALU_Ctrl.Data(7);
439
        end if;
440
        Regfile_D(Index)     <= ALU_Ctrl.Data;
441
 
442
      when ALU_LDX => -- R0 <= Data : Flags N,Z
443
        Flags_D(FL_ZERO)     <= '0';
444
        if( ALU_Ctrl.Data = 0 )then
445
          Flags_D(FL_ZERO)   <= '1';
446
        end if;
447
        Flags_D(FL_NEG)      <= ALU_Ctrl.Data(7);
448
        Regfile_D(0)         <= ALU_Ctrl.Data;
449
 
450
      when ALU_RFLG =>
451
        Flags_D              <= ALU_Ctrl.Data;
452
 
453
      when others => null;
454
    end case;
455
  end process;
456
 
457
  -- 8-bit Adder with carry
458
  Sum                        <= ("0" & Addend_A) + ("0" & Addend_B) + Carry;
459
 
460
  -- We need to infer a hardware multipler, so we create a special clocked
461
  --  process with no reset or clock enable
462
  M_Reg: process( Clock )
463
  begin
464
    if( rising_edge(Clock) )then
465
      Mult                   <= Regfile(0) *
466
                                Regfile(conv_integer(ALU_Ctrl.Reg));
467
    end if;
468
  end process;
469
 
470 10 khays
  S_Regs: process( Reset, Clock )
471 7 jshamlet
  begin
472 10 khays
    if( Reset = '1' )then
473 7 jshamlet
      for i in 0 to 7 loop
474
        Regfile(i)           <= (others => '0');
475
      end loop;
476
      Flags                  <= x"00";
477
    elsif( rising_edge(Clock) )then
478
      if( Halt = '0' )then
479
        Regfile              <= Regfile_D;
480
        Flags                <= Flags_D;
481
      end if;
482
    end if;
483
  end process;
484
 
485
end block;
486
 
487
-------------------------------------------------------------------------------
488
-- Program Counter
489
-------------------------------------------------------------------------------
490
 
491
Open8_PC : block is
492
  -- Preinitialization is for simulation only - check actual reset conditions
493
  signal PC_Q                : ADDRESS_TYPE := (others => '0');
494
  signal Rewind_1_2n         : std_logic    := '0';
495
begin
496
 
497
  PC                         <= PC_Q;
498
 
499
  -- This sets the carry input on the "rewind" adder. If the rewind command is
500
  --  PC_REV2, then we clear the carry. Otherwise, we leave it high.
501
  Rewind_PC_Calc: process( PC_Ctrl )
502
  begin
503
    Rewind_1_2n              <= '1';
504
    if( PC_Ctrl.Oper = PC_REV2 )then
505
      Rewind_1_2n            <= '0';
506
    end if;
507
  end process;
508
 
509 10 khays
  Program_Counter: process( Reset, Clock, Halt, PC_Ctrl, PC_Q, Rewind_1_2n )
510 7 jshamlet
    variable PC_Offset_SX    : ADDRESS_TYPE := x"0000";
511
  begin
512
    PC_Offset_SX(15 downto 8):= (others => PC_Ctrl.Offset(7));
513
    PC_Offset_SX(7 downto 0) := PC_Ctrl.Offset;
514 10 khays
    if( Reset = '1' )then
515 7 jshamlet
      PC_Q                   <= Program_Start_Addr;
516
    elsif( rising_edge(Clock) )then
517
      if( Halt = '0' )then
518
        case PC_Ctrl.Oper is
519
          when PC_IDLE =>
520
            null;
521
          when PC_REV1 | PC_REV2 =>
522
            PC_Q             <= PC_Q - 2 + Rewind_1_2n;
523
          when PC_INCR =>
524
            PC_Q             <= PC_Q + PC_Offset_SX - 2;
525
          when PC_LOAD =>
526
            PC_Q             <= PC_Ctrl.Addr;
527
        end case;
528
      end if;
529
    end if;
530
  end process;
531
 
532
end block;
533
 
534
-------------------------------------------------------------------------------
535
-- Stack Pointer
536
-------------------------------------------------------------------------------
537
 
538
Open8_SP : block is
539
  -- Preinitialization is for simulation only - check actual reset conditions
540
  signal SP_Q                : ADDRESS_TYPE := (others => '0');
541
begin
542
 
543
  SP                         <= SP_Q;
544
 
545 10 khays
  Stack_Pointer: process( Reset, Clock )
546 7 jshamlet
  begin
547 10 khays
    if( Reset = '1' )then
548 7 jshamlet
      SP_Q                   <= Stack_Start_Addr;
549
    elsif( rising_edge(Clock) )then
550
      if( Halt = '0' )then
551
        case SP_Ctrl.Oper is
552
          when SP_IDLE => null;
553
          when SP_RSET => SP_Q <= SP_Ctrl.Addr;
554
          when SP_POP  => SP_Q <= SP_Q + 1;
555
          when SP_PUSH => SP_Q <= SP_Q - 1;
556
        end case;
557
      end if;
558
    end if;
559
  end process;
560
 
561
end block;
562
 
563
-------------------------------------------------------------------------------
564
-- Interrupt Controller
565
-------------------------------------------------------------------------------
566
 
567
Open8_INT : block is
568
 
569
  -- Preinitialization is for simulation only - check actual reset conditions
570
  constant INT_VECTOR_0      : ADDRESS_TYPE := ISR_Start_Addr;
571
  constant INT_VECTOR_1      : ADDRESS_TYPE := ISR_Start_Addr+2;
572
  constant INT_VECTOR_2      : ADDRESS_TYPE := ISR_Start_Addr+4;
573
  constant INT_VECTOR_3      : ADDRESS_TYPE := ISR_Start_Addr+6;
574
  constant INT_VECTOR_4      : ADDRESS_TYPE := ISR_Start_Addr+8;
575
  constant INT_VECTOR_5      : ADDRESS_TYPE := ISR_Start_Addr+10;
576
  constant INT_VECTOR_6      : ADDRESS_TYPE := ISR_Start_Addr+12;
577
  constant INT_VECTOR_7      : ADDRESS_TYPE := ISR_Start_Addr+14;
578
 
579
  signal i_Ints              : INTERRUPT_BUNDLE             := (others => '0');
580
  signal Pending_D           : INTERRUPT_BUNDLE             := (others => '0');
581
  signal Pending             : INTERRUPT_BUNDLE             := (others => '0');
582
  signal Wait_for_FSM        : std_logic := '0';
583
  signal Mask                : std_logic_vector(6 downto 0) := (others => '0');
584
  signal ISR_D, ISR_Q        : ADDRESS_TYPE                 := (others => '0');
585
 
586
  type INT_HIST is array (0 to 8) of integer range 0 to 7;
587
  signal History             : INT_HIST                     := (others => 0);
588
  signal Int_Trig            : std_logic                    := '0';
589
  signal Hist_Level          : integer range 0 to 7         := 0;
590
  signal Hist_Ptr            : integer range 0 to 8         := 0;
591
 
592
begin
593
  Int_Mask                   <= Mask & '1';
594
  ISR                        <= ISR_Q;
595
 
596
  Int_Mask_proc: process( Mask, Interrupts, INT_Ctrl )
597
    variable S_Mask          : std_logic_vector(7 downto 0);
598
  begin
599
    S_Mask                   := Mask & '1';
600
    for i in 0 to 7 loop
601
      i_Ints(i)              <= (Interrupts(i) or INT_Ctrl.Soft_Ints(i))
602
                                and S_Mask(i);
603
    end loop;
604
  end process;
605
 
606
  Int_Ctrl_proc: process( i_Ints, Pending, Wait_for_FSM, ISR_Q, INT_Ctrl,
607
                          History, Hist_Ptr )
608
  begin
609
    ISR_D                    <= ISR_Q;
610
    Pending_D                <= Pending;
611
    Int_Trig                 <= '0';
612
    Hist_Level               <= 0;
613
 
614
    -- Record any incoming interrupts to the pending buffer
615
    if( i_Ints > 0 )then
616
      Pending_D              <= i_Ints;
617
    end if;
618
 
619
    -- Incr_ISR allows the CPU Core to advance the vector address to pop the
620
    --  lower half of the address.
621
    if( INT_Ctrl.Incr_ISR = '1' )then
622
      ISR_D                  <= ISR_Q + 1;
623
    end if;
624
 
625
    -- Only mess with interrupt signals while the CPU core is not currently
626
    --  working with the ISR address (ie, not loading a new service vector)
627
    if( Wait_for_FSM = '0' and Pending > 0 )then
628
      if( Pending(0) = '1' and (Hist_Ptr = 0 or History(Hist_Ptr) > 0) )then
629
        ISR_D                <= INT_VECTOR_0;
630
        Pending_D(0)         <= '0';
631
        Hist_Level           <= 0;
632
        Int_Trig             <= '1';
633
      elsif( Pending(1) = '1' and (Hist_Ptr = 0 or History(Hist_Ptr) > 1) )then
634
        ISR_D                <= INT_VECTOR_1;
635
        Pending_D(1)         <= '0';
636
        Hist_Level           <= 1;
637
        Int_Trig             <= '1';
638
      elsif( Pending(2) = '1' and (Hist_Ptr = 0 or History(Hist_Ptr) > 2) )then
639
        ISR_D                <= INT_VECTOR_2;
640
        Pending_D(2)         <= '0';
641
        Hist_Level           <= 2;
642
        Int_Trig             <= '1';
643
      elsif( Pending(3) = '1' and (Hist_Ptr = 0 or History(Hist_Ptr) > 3) )then
644
        ISR_D                <= INT_VECTOR_3;
645
        Pending_D(3)         <= '0';
646
        Hist_Level           <= 3;
647
        Int_Trig             <= '1';
648
      elsif( Pending(4) = '1' and (Hist_Ptr = 0 or History(Hist_Ptr) > 4) )then
649
        ISR_D                <= INT_VECTOR_4;
650
        Pending_D(4)         <= '0';
651
        Hist_Level           <= 4;
652
        Int_Trig             <= '1';
653
      elsif( Pending(5) = '1' and (Hist_Ptr = 0 or History(Hist_Ptr) > 5) )then
654
        ISR_D                <= INT_VECTOR_5;
655
        Pending_D(5)         <= '0';
656
        Hist_Level           <= 5;
657
        Int_Trig             <= '1';
658
      elsif( Pending(6) = '1' and (Hist_Ptr = 0 or History(Hist_Ptr) > 6) )then
659
        ISR_D                <= INT_VECTOR_6;
660
        Pending_D(6)         <= '0';
661
        Hist_Level           <= 6;
662
        Int_Trig             <= '1';
663
      elsif( Pending(7) = '1' and (Hist_Ptr = 0 or History(Hist_Ptr) > 7) )then
664
        ISR_D                <= INT_VECTOR_7;
665
        Pending_D(7)         <= '0';
666
        Hist_Level           <= 7;
667
        Int_Trig             <= '1';
668
      end if;
669
    end if;
670
  end process;
671
 
672 10 khays
  S_Regs: process( Reset, Clock )
673 7 jshamlet
  begin
674 10 khays
    if( Reset = '1' )then
675 7 jshamlet
      Int_Req                <= '0';
676
      Pending                <= x"00";
677
      Wait_for_FSM           <= '0';
678
      Mask                   <= Default_Interrupt_Mask(7 downto 1);
679
      ISR_Q                  <= INT_VECTOR_0;
680
      for i in 0 to 8 loop
681
        History(i)           <= 0;
682
      end loop;
683
      Hist_Ptr               <= 0;
684
    elsif( rising_edge(Clock) )then
685
      if( Halt = '0' )then
686
        Int_Req              <= Wait_for_FSM and (not Int_Ack);
687
        Pending              <= Pending_D;
688
        -- Reset the Wait_for_FSM flag on Int_Ack
689
        if( Int_Ack = '1' )then
690
          Wait_for_FSM       <= '0';
691
        -- Set the Wait_for_FSM flag on Int_Trig
692
        elsif( Int_Trig = '1' )then
693
          Wait_for_FSM       <= '1';
694
        end if;
695 10 khays
         if( INT_Ctrl.Mask_Set = '1' )then
696 7 jshamlet
          Mask               <= INT_Ctrl.Mask_Data(7 downto 1);
697 10 khays
          end if;
698
          ISR_Q                <= ISR_D;
699
          if( Int_Trig = '1' )then
700
            History(Hist_Ptr+1) <= Hist_Level;
701
            Hist_Ptr           <= Hist_Ptr + 1;
702
          elsif( Int_RTI = '1' and Hist_Ptr > 0 )then
703
            Hist_Ptr           <= Hist_Ptr - 1;
704
          end if;
705 7 jshamlet
      end if;
706
    end if;
707
  end process;
708
 
709
end block;
710
 
711
-------------------------------------------------------------------------------
712
-- State Logic / Instruction Decoding & Execution
713
-------------------------------------------------------------------------------
714
 
715
Open8_FSM : block is
716
 
717
  -- These are all the primary instructions/op-codes (upper 5-bits)
718
  constant OP_INC            : OPCODE_TYPE := "00000";
719
  constant OP_ADC            : OPCODE_TYPE := "00001";
720
  constant OP_TX0            : OPCODE_TYPE := "00010";
721
  constant OP_OR             : OPCODE_TYPE := "00011";
722
  constant OP_AND            : OPCODE_TYPE := "00100";
723
  constant OP_XOR            : OPCODE_TYPE := "00101";
724
  constant OP_ROL            : OPCODE_TYPE := "00110";
725
  constant OP_ROR            : OPCODE_TYPE := "00111";
726
  constant OP_DEC            : OPCODE_TYPE := "01000";
727
  constant OP_SBC            : OPCODE_TYPE := "01001";
728
  constant OP_ADD            : OPCODE_TYPE := "01010";
729
  constant OP_STP            : OPCODE_TYPE := "01011";
730
  constant OP_BTT            : OPCODE_TYPE := "01100";
731
  constant OP_CLP            : OPCODE_TYPE := "01101";
732
  constant OP_T0X            : OPCODE_TYPE := "01110";
733
  constant OP_CMP            : OPCODE_TYPE := "01111";
734
  constant OP_PSH            : OPCODE_TYPE := "10000";
735
  constant OP_POP            : OPCODE_TYPE := "10001";
736
  constant OP_BR0            : OPCODE_TYPE := "10010";
737
  constant OP_BR1            : OPCODE_TYPE := "10011";
738
  constant OP_DBNZ           : OPCODE_TYPE := "10100"; -- USR
739
  constant OP_INT            : OPCODE_TYPE := "10101";
740
  constant OP_MUL            : OPCODE_TYPE := "10110"; -- USR2
741
  constant OP_STK            : OPCODE_TYPE := "10111";
742
  constant OP_UPP            : OPCODE_TYPE := "11000";
743
  constant OP_STA            : OPCODE_TYPE := "11001";
744
  constant OP_STX            : OPCODE_TYPE := "11010";
745
  constant OP_STO            : OPCODE_TYPE := "11011";
746
  constant OP_LDI            : OPCODE_TYPE := "11100";
747
  constant OP_LDA            : OPCODE_TYPE := "11101";
748
  constant OP_LDX            : OPCODE_TYPE := "11110";
749
  constant OP_LDO            : OPCODE_TYPE := "11111";
750
 
751
  -- These are all specific sub-opcodes for OP_STK / 0xB8 (lower 3-bits)
752
  constant SOP_RSP           : SUBOP_TYPE := "000";
753
  constant SOP_RTS           : SUBOP_TYPE := "001";
754
  constant SOP_RTI           : SUBOP_TYPE := "010";
755
  constant SOP_BRK           : SUBOP_TYPE := "011";
756
  constant SOP_JMP           : SUBOP_TYPE := "100";
757
  constant SOP_SMSK          : SUBOP_TYPE := "101";
758
  constant SOP_GMSK          : SUBOP_TYPE := "110";
759
  constant SOP_JSR           : SUBOP_TYPE := "111";
760
 
761
  -- Preinitialization is for simulation only - check actual reset conditions
762
  type CPU_STATES is (
763
      -- Instruction fetch & Decode
764
    PIPE_FILL_0, PIPE_FILL_1, PIPE_FILL_2, INSTR_DECODE,
765
    -- Branching
766
    BRN_C1, DBNZ_C1, JMP_C1, JMP_C2,
767
    -- Loads
768
    LDA_C1, LDA_C2, LDA_C3, LDA_C4, LDI_C1, LDO_C1, LDX_C1, LDX_C2, LDX_C3,
769
    -- Stores
770
    STA_C1, STA_C2, STA_C3, STO_C1, STX_C1, STX_C2,
771
    -- 2-cycle math
772
    MUL_C1, UPP_C1,
773
    -- Stack
774
    PSH_C1, POP_C1, POP_C2, POP_C3, POP_C4,
775
    -- Subroutines & Interrupts
776
    WAIT_FOR_INT, ISR_C1, ISR_C2, ISR_C3, JSR_C1, JSR_C2,
777
    RTS_C1, RTS_C2, RTS_C3, RTS_C4, RTS_C5, RTI_C6,
778
    -- Debugging
779
    BRK_C1 );
780
 
781
  signal CPU_Next_State      : CPU_STATES := PIPE_FILL_0;
782
  signal CPU_State           : CPU_STATES := PIPE_FILL_0;
783
 
784
  type CACHE_MODES is (CACHE_IDLE, CACHE_INSTR, CACHE_OPER1, CACHE_OPER2,
785
                       CACHE_PREFETCH );
786
  signal Cache_Ctrl          : CACHE_MODES := CACHE_IDLE;
787
 
788
  signal Opcode              : OPCODE_TYPE := (others => '0');
789
  signal SubOp, SubOp_p1     : SUBOP_TYPE  := (others => '0');
790
  -- synthesis translate_off
791
  signal Instruction         : DATA_TYPE   := (others => '0');
792
  -- synthesis translate_on
793
  signal Prefetch            : DATA_TYPE   := (others => '0');
794
  signal Operand1, Operand2  : DATA_TYPE   := (others => '0');
795
 
796
  signal Instr_Prefetch      : std_logic   := '0';
797
 
798
  signal Ack_D, Ack_Q, Ack_Q1: std_logic   := '0';
799
  signal Int_RTI_D           : std_logic   := '0';
800
 
801
begin
802
 
803
  -- synthesis translate_off
804
  Instruction                <= Opcode & SubOp;
805
  -- synthesis translate_on
806
 
807
  State_Logic: process(CPU_State, ALU_Regs, ALU_Flags, Int_Mask, Opcode,
808
                       SubOp , SubOp_p1, Operand1, Operand2, Int_Req )
809
    variable Reg, Reg_1      : integer range 0 to 7 := 0;
810
    variable Offset_SX       : ADDRESS_TYPE;
811
  begin
812
    CPU_Next_State           <= CPU_State;
813
    Cache_Ctrl               <= CACHE_IDLE;
814
    --
815
    ALU_Ctrl.Oper            <= ALU_IDLE;
816
    ALU_Ctrl.Reg             <= ACCUM;
817
    ALU_Ctrl.Data            <= x"00";
818
    --
819
    PC_Ctrl.Oper             <= PC_IDLE;
820
 
821
    PC_Ctrl.Offset           <= x"03";
822
    PC_Ctrl.Addr             <= x"0000";
823
    --
824
    SP_Ctrl.Oper             <= SP_IDLE;
825
    --
826
    AS_Ctrl.Src              <= ADDR_PC;
827
    IMM                      <= x"0000";
828
    --
829
    DP_Ctrl.Src              <= DATA_IDLE;
830
    DP_Ctrl.Reg              <= ACCUM;
831
    --
832
    INT_Ctrl.Mask_Set        <= '0';
833
    INT_Ctrl.Soft_Ints       <= x"00";
834
    INT_Ctrl.Incr_ISR        <= '0';
835
    Ack_D                    <= '0';
836
    Int_RTI_D                <= '0';
837
 
838
    -- Assign the most common value of Reg and Reg1 outside the case structure
839
    --  to simplify things.
840
    Reg                      := conv_integer(SubOp);
841
    Reg_1                    := conv_integer(SubOp_p1);
842
    Offset_SX(15 downto 0)   := (others => Operand1(7));
843
    Offset_SX(7 downto 0)    := Operand1;
844
 
845
    case CPU_State is
846
-------------------------------------------------------------------------------
847
-- Initial Instruction fetch & decode
848
-------------------------------------------------------------------------------
849
      when PIPE_FILL_0 =>
850
        CPU_Next_State       <= PIPE_FILL_1;
851
        PC_Ctrl.Oper         <= PC_INCR;
852
 
853
      when PIPE_FILL_1 =>
854
        CPU_Next_State       <= PIPE_FILL_2;
855
        PC_Ctrl.Oper         <= PC_INCR;
856
 
857
      when PIPE_FILL_2 =>
858
        CPU_Next_State       <= INSTR_DECODE;
859
        Cache_Ctrl           <= CACHE_INSTR;
860
        PC_Ctrl.Oper         <= PC_INCR;
861
 
862
      when INSTR_DECODE =>
863
        CPU_Next_State       <= INSTR_DECODE;
864
        Cache_Ctrl           <= CACHE_INSTR;
865
 
866
        case Opcode is
867
          when OP_PSH =>
868
            CPU_Next_State   <= PSH_C1;
869
            Cache_Ctrl       <= CACHE_PREFETCH;
870
            PC_Ctrl.Oper     <= PC_REV1;
871
            DP_Ctrl.Src      <= DATA_REG;
872
            DP_Ctrl.Reg      <= SubOp;
873
 
874
          when OP_POP =>
875
            CPU_Next_State   <= POP_C1;
876
            Cache_Ctrl       <= CACHE_PREFETCH;
877
            PC_Ctrl.Oper     <= PC_REV2;
878
            SP_Ctrl.Oper     <= SP_POP;
879
 
880
          when OP_BR0 | OP_BR1 =>
881
            CPU_Next_State   <= BRN_C1;
882
            Cache_Ctrl       <= CACHE_OPER1;
883
            PC_Ctrl.Oper     <= PC_INCR;
884
 
885
          when OP_DBNZ =>
886
            CPU_Next_State   <= DBNZ_C1;
887
            Cache_Ctrl       <= CACHE_OPER1;
888
            PC_Ctrl.Oper     <= PC_INCR;
889
            ALU_Ctrl.Oper    <= ALU_DEC;
890
            ALU_Ctrl.Reg     <= SubOp;
891
 
892
          when OP_INT =>
893
            PC_Ctrl.Oper     <= PC_INCR;
894
            if( Int_Mask(Reg) = '1' )then
895
              CPU_Next_State <= WAIT_FOR_INT;
896
              INT_Ctrl.Soft_Ints(Reg) <= '1';
897
            end if;
898
 
899
          when OP_STK =>
900
            case SubOp is
901
              when SOP_RSP  =>
902
                PC_Ctrl.Oper <= PC_INCR;
903
                SP_Ctrl.Oper <= SP_RSET;
904
 
905
              when SOP_RTS | SOP_RTI =>
906
                CPU_Next_State <= RTS_C1;
907
                Cache_Ctrl   <= CACHE_IDLE;
908
                SP_Ctrl.Oper <= SP_POP;
909
 
910
              when SOP_BRK  =>
911
                CPU_Next_State <= BRK_C1;
912
                PC_Ctrl.Oper <= PC_REV2;
913
 
914
              when SOP_JMP  =>
915
                CPU_Next_State <= JMP_C1;
916
                Cache_Ctrl   <= CACHE_OPER1;
917
 
918
              when SOP_SMSK =>
919
                PC_Ctrl.Oper <= PC_INCR;
920
                INT_Ctrl.Mask_Set <= '1';
921
 
922
              when SOP_GMSK =>
923
                PC_Ctrl.Oper <= PC_INCR;
924
                ALU_Ctrl.Oper<= ALU_LDI;
925
                ALU_Ctrl.Reg <= ACCUM;
926
                ALU_Ctrl.Data<= Int_Mask;
927
 
928
              when SOP_JSR =>
929
                CPU_Next_State <= JSR_C1;
930
                Cache_Ctrl   <= CACHE_OPER1;
931
                DP_Ctrl.Src  <= DATA_PC;
932
                DP_Ctrl.Reg  <= ACCUM+1;
933
 
934
              when others => null;
935
            end case;
936
 
937
          when OP_MUL =>
938
            CPU_Next_State   <= MUL_C1;
939
            Cache_Ctrl       <= CACHE_PREFETCH;
940
 
941
            -- We need to back the PC up by 1, and all it to refill. An
942
            --  unfortunate consequence of the pipelining. We can get away with
943
            --  only 1 extra clock by pre-fetching the next instruction, though
944
            PC_Ctrl.Oper     <= PC_REV1;
945
            -- Multiplication is automatic, but requires a single clock cycle.
946
            --  We need to specify the register for Rn (R1:R0 = R0 * Rn) now,
947
            --   but will issue the multiply command on the next clock to copy
948
            --   the results to the specified register.
949
            ALU_Ctrl.Oper    <= ALU_IDLE;
950
            ALU_Ctrl.Reg     <= SubOp; -- Rn
951
 
952
          when OP_UPP =>
953
            CPU_Next_State   <= UPP_C1;
954
            Cache_Ctrl       <= CACHE_PREFETCH;
955
            PC_Ctrl.Oper     <= PC_REV1;
956
            ALU_Ctrl.Oper    <= Opcode;
957
            ALU_Ctrl.Reg     <= SubOp;
958
 
959
          when OP_LDA =>
960
            CPU_Next_State   <= LDA_C1;
961
            Cache_Ctrl       <= CACHE_OPER1;
962
 
963
          when OP_LDI =>
964
            CPU_Next_State   <= LDI_C1;
965
            Cache_Ctrl       <= CACHE_OPER1;
966
            PC_Ctrl.Oper     <= PC_INCR;
967
 
968
          when OP_LDO =>
969
            CPU_Next_State   <= LDO_C1;
970
            Cache_Ctrl       <= CACHE_OPER1;
971
            PC_Ctrl.Oper     <= PC_REV2;
972
 
973
          when OP_LDX =>
974
            CPU_Next_State   <= LDX_C1;
975
            PC_Ctrl.Oper     <= PC_REV2;
976
            AS_Ctrl.Src      <= ADDR_IMM;
977
            -- If auto-increment is disabled, use the specified register pair,
978
            --  otherwise, for an odd:even pair, and issue the first half of
979
            --  a UPP instruction to the ALU
980
            if( Enable_Auto_Increment = '0' )then
981
              IMM            <= ALU_Regs(Reg_1) & ALU_Regs(Reg);
982
            else
983
              Reg            := conv_integer(SubOp(2 downto 1) & '0');
984
              Reg_1          := conv_integer(SubOp(2 downto 1) & '1');
985
              IMM            <= ALU_Regs(Reg_1) & ALU_Regs(Reg);
986
              if( SubOp(0) = '1' )then
987
                ALU_Ctrl.Oper<= ALU_UPP;
988
                ALU_Ctrl.Reg <= SubOp(2 downto 1) & '0';
989
              end if;
990
            end if;
991
 
992
          when OP_STA =>
993
            CPU_Next_State   <= STA_C1;
994
            Cache_Ctrl       <= CACHE_OPER1;
995
 
996
          when OP_STO =>
997
            CPU_Next_State   <= STO_C1;
998
            Cache_Ctrl       <= CACHE_OPER1;
999
            PC_Ctrl.Oper     <= PC_REV2;
1000
            DP_Ctrl.Src      <= DATA_REG;
1001
            DP_Ctrl.Reg      <= ACCUM;
1002
 
1003
          when OP_STX =>
1004
            CPU_Next_State   <= STX_C1;
1005
            Cache_Ctrl       <= CACHE_PREFETCH;
1006
            PC_Ctrl.Oper     <= PC_REV2;
1007
            DP_Ctrl.Src      <= DATA_REG;
1008
            DP_Ctrl.Reg      <= ACCUM;
1009
 
1010
          when others =>
1011
            PC_Ctrl.Oper     <= PC_INCR;
1012
            ALU_Ctrl.Oper    <= Opcode;
1013
            ALU_Ctrl.Reg     <= SubOp;
1014
 
1015
        end case;
1016
 
1017
-------------------------------------------------------------------------------
1018
-- Program Control (BR0_C1, BR1_C1, DBNZ_C1, JMP )
1019
-------------------------------------------------------------------------------
1020
 
1021
      when BRN_C1 =>
1022
        CPU_Next_State       <= INSTR_DECODE;
1023
        Cache_Ctrl           <= CACHE_INSTR;
1024
        PC_Ctrl.Oper         <= PC_INCR;
1025
        if( ALU_Flags(Reg) = Opcode(0) )then
1026
          CPU_Next_State     <= PIPE_FILL_0;
1027
          Cache_Ctrl         <= CACHE_IDLE;
1028
          PC_Ctrl.Offset     <= Operand1;
1029
        end if;
1030
 
1031
      when DBNZ_C1 =>
1032
        CPU_Next_State       <= INSTR_DECODE;
1033
        Cache_Ctrl           <= CACHE_INSTR;
1034
        PC_Ctrl.Oper         <= PC_INCR;
1035
        if( ALU_Flags(FL_ZERO) = '0' )then
1036
          CPU_Next_State     <= PIPE_FILL_0;
1037
          Cache_Ctrl         <= CACHE_IDLE;
1038
          PC_Ctrl.Offset     <= Operand1;
1039
        end if;
1040
 
1041
      when JMP_C1 =>
1042
        CPU_Next_State       <= JMP_C2;
1043
        Cache_Ctrl           <= CACHE_OPER2;
1044
 
1045
      when JMP_C2 =>
1046
        CPU_Next_State       <= PIPE_FILL_0;
1047
        PC_Ctrl.Oper         <= PC_LOAD;
1048
        PC_Ctrl.Addr         <= Operand2 & Operand1;
1049
 
1050
-------------------------------------------------------------------------------
1051
-- Data Storage - Load from memory (LDA, LDI, LDO, LDX)
1052
-------------------------------------------------------------------------------
1053
 
1054
      when LDA_C1 =>
1055
        CPU_Next_State       <= LDA_C2;
1056
        Cache_Ctrl           <= CACHE_OPER2;
1057
 
1058
      when LDA_C2 =>
1059
        CPU_Next_State       <= LDA_C3;
1060
        AS_Ctrl.Src          <= ADDR_IMM;
1061
        IMM                  <= Operand2 & Operand1;
1062
 
1063
      when LDA_C3 =>
1064
        CPU_Next_State       <= LDA_C4;
1065
        PC_Ctrl.Oper         <= PC_INCR;
1066
 
1067
      when LDA_C4 =>
1068
        CPU_Next_State       <= LDI_C1;
1069
        Cache_Ctrl           <= CACHE_OPER1;
1070
        PC_Ctrl.Oper         <= PC_INCR;
1071
 
1072
      when LDI_C1 =>
1073
        CPU_Next_State       <= INSTR_DECODE;
1074
        Cache_Ctrl           <= CACHE_INSTR;
1075
        PC_Ctrl.Oper         <= PC_INCR;
1076
        ALU_Ctrl.Oper        <= ALU_LDI;
1077
        ALU_Ctrl.Reg         <= SubOp;
1078
        ALU_Ctrl.Data        <= Operand1;
1079
 
1080
      when LDO_C1 =>
1081
        CPU_Next_State       <= LDX_C1;
1082
        AS_Ctrl.Src          <= ADDR_IMM;
1083
        PC_Ctrl.Oper         <= PC_INCR;
1084
        if( Enable_Auto_Increment = '1' )then
1085
          Reg                := conv_integer(SubOp(2 downto 1) & '0');
1086
          Reg_1              := conv_integer(SubOp(2 downto 1) & '1');
1087
          IMM                <= (ALU_Regs(Reg_1) & ALU_Regs(Reg)) + Offset_SX;
1088
          if( SubOp(0) = '1' )then
1089
            ALU_Ctrl.Oper<= ALU_UPP;
1090
            ALU_Ctrl.Reg <= SubOp(2 downto 1) & '0';
1091
          end if;
1092
        else
1093
          IMM                <= (ALU_Regs(Reg_1) & ALU_Regs(Reg)) + Offset_SX;
1094
        end if;
1095
 
1096
      when LDX_C1 =>
1097
        CPU_Next_State       <= LDX_C2;
1098
        PC_Ctrl.Oper         <= PC_INCR;
1099
 
1100
      when LDX_C2 =>
1101
        CPU_Next_State       <= LDX_C3;
1102
        PC_Ctrl.Oper         <= PC_INCR;
1103
        Cache_Ctrl           <= CACHE_OPER1;
1104
 
1105
      when LDX_C3 =>
1106
        CPU_Next_State       <= INSTR_DECODE;
1107
        Cache_Ctrl           <= CACHE_INSTR;
1108
        PC_Ctrl.Oper         <= PC_INCR;
1109
        ALU_Ctrl.Oper        <= ALU_LDX;
1110
        ALU_Ctrl.Reg         <= ACCUM;
1111
        ALU_Ctrl.Data        <= Operand1;
1112
 
1113
-------------------------------------------------------------------------------
1114
-- Data Storage - Load from memory (STA, STO, STX)
1115
-------------------------------------------------------------------------------
1116
      when STA_C1 =>
1117
        CPU_Next_State       <= STA_C2;
1118
        Cache_Ctrl           <= CACHE_OPER2;
1119
        DP_Ctrl.Src          <= DATA_REG;
1120
        DP_Ctrl.Reg          <= SubOp;
1121
 
1122
      when STA_C2 =>
1123
        CPU_Next_State       <= STA_C3;
1124
        AS_Ctrl.Src          <= ADDR_IMM;
1125
        IMM                  <= Operand2 & Operand1;
1126
        PC_Ctrl.Oper         <= PC_INCR;
1127
 
1128
      when STA_C3 =>
1129
        CPU_Next_State       <= PIPE_FILL_2;
1130
        Cache_Ctrl           <= CACHE_PREFETCH;
1131
        PC_Ctrl.Oper         <= PC_INCR;
1132
 
1133
      when STO_C1 =>
1134
        Cache_Ctrl           <= CACHE_PREFETCH;
1135
        PC_Ctrl.Oper         <= PC_INCR;
1136
        AS_Ctrl.Src          <= ADDR_IMM;
1137
        -- If auto-increment is disabled, just load the registers normally
1138
        if( Enable_Auto_Increment = '0' )then
1139
          CPU_Next_State     <= PIPE_FILL_1;
1140
          IMM                <= (ALU_Regs(Reg_1) & ALU_Regs(Reg)) + Offset_SX;
1141
        -- Otherwise, enforce the even register rule, and check the LSB to see
1142
        --  if we should perform the auto-increment on the register pair
1143
        else
1144
          CPU_Next_State     <= STX_C2;
1145
          Reg                := conv_integer(SubOp(2 downto 1) & '0');
1146
          Reg_1              := conv_integer(SubOp(2 downto 1) & '1');
1147
          IMM                <= (ALU_Regs(Reg_1) & ALU_Regs(Reg)) + Offset_SX;
1148
          if( SubOp(0) = '1' )then
1149
            ALU_Ctrl.Oper    <= ALU_UPP;
1150
            ALU_Ctrl.Reg     <= SubOp(2 downto 1) & '0';
1151
          end if;
1152
        end if;
1153
 
1154
      when STX_C1 =>
1155
        PC_Ctrl.Oper         <= PC_INCR;
1156
        AS_Ctrl.Src          <= ADDR_IMM;
1157
        -- If auto-increment is disabled, just load the registers normally
1158
        if( Enable_Auto_Increment = '0' )then
1159
          CPU_Next_State     <= PIPE_FILL_1;
1160
          IMM                <= (ALU_Regs(Reg_1) & ALU_Regs(Reg));
1161
        -- Otherwise, enforce the even register rule, and check the LSB to see
1162
        --  if we should perform the auto-increment on the register pair
1163
        else
1164
          CPU_Next_State     <= STX_C2;
1165
          Reg                := conv_integer(SubOp(2 downto 1) & '0');
1166
          Reg_1              := conv_integer(SubOp(2 downto 1) & '1');
1167
          IMM                <= (ALU_Regs(Reg_1) & ALU_Regs(Reg));
1168
          if( SubOp(0) = '1' )then
1169
            ALU_Ctrl.Oper    <= ALU_UPP;
1170
            ALU_Ctrl.Reg     <= SubOp(2 downto 1) & '0';
1171
          end if;
1172
        end if;
1173
 
1174
      when STX_C2 =>
1175
        CPU_Next_State       <= PIPE_FILL_2;
1176
        PC_Ctrl.Oper         <= PC_INCR;
1177
        ALU_Ctrl.Oper        <= ALU_UPP2;
1178
        ALU_Ctrl.Reg         <= SubOp(2 downto 1) & '1';
1179
 
1180
-------------------------------------------------------------------------------
1181
-- Multi-Cycle Math Operations (UPP, MUL)
1182
-------------------------------------------------------------------------------
1183
      -- Because we have to backup the pipeline by 1 to refetch the 2nd
1184
      --  instruction/first operand, we have to return through PF2
1185
 
1186
      when MUL_C1 =>
1187
        CPU_Next_State       <= PIPE_FILL_2;
1188
        PC_Ctrl.Oper         <= PC_INCR;
1189
        ALU_Ctrl.Oper        <= ALU_MUL;
1190
 
1191
      when UPP_C1 =>
1192
        CPU_Next_State       <= PIPE_FILL_2;
1193
        PC_Ctrl.Oper         <= PC_INCR;
1194
        ALU_Ctrl.Oper        <= ALU_UPP2;
1195
        ALU_Ctrl.Reg         <= SubOp_p1;
1196
 
1197
-------------------------------------------------------------------------------
1198
-- Basic Stack Manipulation (PSH, POP, RSP)
1199
-------------------------------------------------------------------------------
1200
      when PSH_C1 =>
1201
        CPU_Next_State       <= PIPE_FILL_1;
1202
        AS_Ctrl.Src          <= ADDR_SP;
1203
        SP_Ctrl.Oper         <= SP_PUSH;
1204
 
1205
      when POP_C1 =>
1206
        CPU_Next_State       <= POP_C2;
1207
        AS_Ctrl.Src          <= ADDR_SP;
1208
 
1209
      when POP_C2 =>
1210
        CPU_Next_State       <= POP_C3;
1211
        PC_Ctrl.Oper         <= PC_INCR;
1212
 
1213
      when POP_C3 =>
1214
        CPU_Next_State       <= POP_C4;
1215
        Cache_Ctrl           <= CACHE_OPER1;
1216
        PC_Ctrl.Oper         <= PC_INCR;
1217
 
1218
      when POP_C4 =>
1219
        CPU_Next_State       <= INSTR_DECODE;
1220
        Cache_Ctrl           <= CACHE_INSTR;
1221
        PC_Ctrl.Oper         <= PC_INCR;
1222
        ALU_Ctrl.Oper        <= ALU_POP;
1223
        ALU_Ctrl.Reg         <= SubOp;
1224
        ALU_Ctrl.Data        <= Operand1;
1225
 
1226
-------------------------------------------------------------------------------
1227
-- Subroutines & Interrupts (RTS, JSR)
1228
-------------------------------------------------------------------------------
1229
      when WAIT_FOR_INT => -- For soft interrupts only, halt the PC
1230
        CPU_Next_State       <= WAIT_FOR_INT;
1231
 
1232
      when ISR_C1 =>
1233
        CPU_Next_State       <= ISR_C2;
1234
        AS_Ctrl.Src          <= ADDR_ISR;
1235
        INT_Ctrl.Incr_ISR    <= '1';
1236
        PC_Ctrl.Oper         <= PC_INCR;
1237
        -- Rewind the PC by 3 to compensate for the pipeline registers
1238
        PC_Ctrl.Offset       <= x"FF";
1239
 
1240
      when ISR_C2 =>
1241
        CPU_Next_State       <= ISR_C3;
1242
        AS_Ctrl.Src          <= ADDR_ISR;
1243
        DP_Ctrl.Src          <= DATA_FLAG;
1244
 
1245
      when ISR_C3 =>
1246
        CPU_Next_State       <= JSR_C1;
1247
        Cache_Ctrl           <= CACHE_OPER1;
1248
        AS_Ctrl.Src          <= ADDR_SP;
1249
        SP_Ctrl.Oper         <= SP_PUSH;
1250
        DP_Ctrl.Src          <= DATA_PC;
1251
        DP_Ctrl.Reg          <= ACCUM+1;
1252
        ALU_Ctrl.Oper        <= ALU_STP;
1253
        ALU_Ctrl.Reg         <= INT_FLAG;
1254
        Ack_D                <= '1';
1255
 
1256
      when JSR_C1 =>
1257
        CPU_Next_State       <= JSR_C2;
1258
        Cache_Ctrl           <= CACHE_OPER2;
1259
        AS_Ctrl.Src          <= ADDR_SP;
1260
        SP_Ctrl.Oper         <= SP_PUSH;
1261
        DP_Ctrl.Src          <= DATA_PC;
1262
        DP_Ctrl.Reg          <= ACCUM;
1263
 
1264
      when JSR_C2 =>
1265
        CPU_Next_State       <= PIPE_FILL_0;
1266
        AS_Ctrl.Src          <= ADDR_SP;
1267
        SP_Ctrl.Oper         <= SP_PUSH;
1268
        PC_Ctrl.Oper         <= PC_LOAD;
1269
        PC_Ctrl.Addr         <= Operand2 & Operand1;
1270
 
1271
      when RTS_C1 =>
1272
        CPU_Next_State       <= RTS_C2;
1273
        AS_Ctrl.Src          <= ADDR_SP;
1274
        SP_Ctrl.Oper         <= SP_POP;
1275
 
1276
      when RTS_C2 =>
1277
        CPU_Next_State       <= RTS_C3;
1278
        AS_Ctrl.Src          <= ADDR_SP;
1279
        -- if this is an RTI, then we need to POP the flags
1280
        if( SubOp = SOP_RTI )then
1281
          SP_Ctrl.Oper       <= SP_POP;
1282
        end if;
1283
 
1284
      when RTS_C3 =>
1285
        CPU_Next_State       <= RTS_C4;
1286
        Cache_Ctrl           <= CACHE_OPER1;
1287
        -- It doesn't really matter what is on the address bus for RTS, while
1288
        --  it does for RTI, so we make this the default
1289
        AS_Ctrl.Src          <= ADDR_SP;
1290
 
1291
      when RTS_C4 =>
1292
        CPU_Next_State       <= RTS_C5;
1293
        Cache_Ctrl           <= CACHE_OPER2;
1294
 
1295
      when RTS_C5 =>
1296
        CPU_Next_State       <= PIPE_FILL_0;
1297
        PC_Ctrl.Oper         <= PC_LOAD;
1298
        PC_Ctrl.Addr         <= Operand2 & Operand1;
1299
        if( SubOp = SOP_RTI )then
1300
          CPU_Next_State     <= RTI_C6;
1301
          Cache_Ctrl         <= CACHE_OPER1;
1302
        end if;
1303
 
1304
      when RTI_C6 =>
1305
        CPU_Next_State       <= PIPE_FILL_1;
1306
        PC_Ctrl.Oper         <= PC_INCR;
1307
        ALU_Ctrl.Oper        <= ALU_RFLG;
1308
        ALU_Ctrl.Data        <= Operand1;
1309
        PC_Ctrl.Oper         <= PC_INCR;
1310
        Int_RTI_D            <= '1';
1311
 
1312
-------------------------------------------------------------------------------
1313
-- Debugging (BRK) Performs a 5-clock NOP
1314
-------------------------------------------------------------------------------
1315
      when BRK_C1 =>
1316
        CPU_Next_State       <= PIPE_FILL_0;
1317
 
1318
      when others => null;
1319
    end case;
1320
 
1321
    -- Interrupt service routines can only begin during the decode and wait
1322
    --  states to avoid corruption due to incomplete instruction execution
1323
    if( Int_Req = '1' )then
1324
      if( CPU_State = INSTR_DECODE or CPU_State = WAIT_FOR_INT )then
1325
        CPU_Next_State       <= ISR_C1;
1326
      end if;
1327
    end if;
1328
 
1329
  end process;
1330
 
1331 10 khays
  S_Regs: process( Reset, Clock )
1332 7 jshamlet
  begin
1333 10 khays
    if( Reset = '1' )then
1334 7 jshamlet
      CPU_State              <= PIPE_FILL_0;
1335
      Opcode                 <= OP_INC;
1336
      SubOp                  <= ACCUM;
1337
      SubOp_p1               <= ACCUM;
1338
      Operand1               <= x"00";
1339
      Operand2               <= x"00";
1340
      Instr_Prefetch         <= '0';
1341
      Prefetch               <= x"00";
1342
 
1343
      Ack_Q                  <= '0';
1344
      Ack_Q1                 <= '0';
1345
      Int_Ack                <= '0';
1346
      Int_RTI                <= '0';
1347
 
1348
    elsif( rising_edge(Clock) )then
1349
      if( Halt = '0' )then
1350
        CPU_State            <= CPU_Next_State;
1351
        case Cache_Ctrl is
1352
          when CACHE_INSTR =>
1353
            Opcode           <= Rd_Data(7 downto 3);
1354
            SubOp            <= Rd_Data(2 downto 0);
1355
            SubOp_p1         <= Rd_Data(2 downto 0) + 1;
1356
            if( Instr_Prefetch = '1' )then
1357
              Opcode         <= Prefetch(7 downto 3);
1358
              SubOp          <= Prefetch(2 downto 0);
1359
              SubOp_p1       <= Prefetch(2 downto 0) + 1;
1360
              Instr_Prefetch <= '0';
1361
            end if;
1362
          when CACHE_OPER1 =>
1363
            Operand1         <= Rd_Data;
1364
          when CACHE_OPER2 =>
1365
            Operand2         <= Rd_Data;
1366
          when CACHE_PREFETCH =>
1367
            Prefetch         <= Rd_Data;
1368
            Instr_Prefetch   <= '1';
1369
          when CACHE_IDLE =>
1370
            null;
1371
        end case;
1372
 
1373
        -- Interrupt signalling registers
1374
        Ack_Q                <= Ack_D;
1375
        Ack_Q1               <= Ack_Q;
1376
        Int_Ack              <= Ack_Q1;
1377
        Int_RTI              <= Int_RTI_D;
1378
      end if;
1379
    end if;
1380
  end process;
1381
 
1382
-------------------------------------------------------------------------------
1383
-- Fixed in-line statements for the interrupt mask, and stack pointer address
1384
-------------------------------------------------------------------------------
1385
 
1386
-- The interrupt control mask is always sourced out of R0
1387
  INT_Ctrl.Mask_Data         <= ALU_Regs(conv_integer(ACCUM));
1388
 
1389
-- The original RSP instruction simply reset the stack pointer to the preset
1390
--  address set at compile time. However, with little extra effort, we can
1391
--  modify the instruction to allow the stack pointer to be moved anywhere in
1392
--  the memory map. Since RSP can't have an sub-opcode, R1:R0 was chosen as
1393
--  a fixed source
1394
 
1395
Prog_Stack_Addr_Move_fn: if( Allow_Stack_Address_Move = '1' )generate
1396
  SP_Ctrl.Addr               <= ALU_Regs(1) & ALU_Regs(0);
1397
end generate;
1398
 
1399
Normal_Stack_Reset_fn: if( Allow_Stack_Address_Move = '0' )generate
1400
  SP_Ctrl.Addr               <= Stack_Start_Addr;
1401
end generate;
1402
 
1403
end block;
1404
 
1405
-------------------------------------------------------------------------------
1406
-- Address Source Mux
1407
-------------------------------------------------------------------------------
1408
 
1409
Open8_AS : block is
1410
begin
1411
 
1412
  Address_Select: process( AS_Ctrl, PC, SP, IMM, ISR )
1413
    variable PC_Mux, SP_Mux  : ADDRESS_TYPE;
1414
    variable IMM_Mux, ISR_Mux: ADDRESS_TYPE;
1415
  begin
1416
    PC_Mux                   := (others => '0');
1417
    SP_Mux                   := (others => '0');
1418
    IMM_Mux                  := (others => '0');
1419
    ISR_Mux                  := (others => '0');
1420
 
1421
    case AS_Ctrl.Src is
1422
      when ADDR_PC =>
1423
        PC_Mux               := PC;
1424
      when ADDR_SP =>
1425
        SP_Mux               := SP;
1426
      when ADDR_IMM =>
1427
        IMM_Mux              := IMM;
1428
      when ADDR_ISR =>
1429
        ISR_Mux              := ISR;
1430
    end case;
1431
 
1432
    for i in 0 to 15 loop
1433
      Address(i)             <= PC_Mux(i) or SP_Mux(i) or IMM_Mux(i) or
1434
                                ISR_Mux(i);
1435
    end loop;
1436
  end process;
1437
 
1438
end block;
1439
 
1440
-------------------------------------------------------------------------------
1441
-- (Write) Data Path
1442
-------------------------------------------------------------------------------
1443
 
1444
Open8_DP : block is
1445
  signal Wr_Data_D           : DATA_TYPE := (others => '0');
1446
  signal Wr_Enable_D         : std_logic := '0';
1447
begin
1448
 
1449
  Data_Select: process( DP_Ctrl, ALU_Regs, ALU_Flags, PC )
1450
    variable Reg_Mux, PC_Mux : DATA_TYPE;
1451
    variable Flag_Mux        : DATA_TYPE;
1452
  begin
1453
    Reg_Mux                  := (others => '0');
1454
    Flag_Mux                 := (others => '0');
1455
    PC_Mux                   := (others => '0');
1456
    Wr_Enable_D              <= '0';
1457
 
1458
    case DP_Ctrl.Src is
1459
      when DATA_IDLE =>
1460
        null;
1461
      when DATA_REG =>
1462
        Reg_Mux              := ALU_Regs(conv_integer(DP_Ctrl.Reg));
1463
        Wr_Enable_D          <= '1';
1464
      when DATA_FLAG =>
1465
        Flag_Mux             := ALU_Flags;
1466
        Wr_Enable_D          <= '1';
1467
      when DATA_PC =>
1468
        Wr_Enable_D          <= '1';
1469
        if( DP_Ctrl.Reg = ACCUM )then
1470
          PC_Mux             := PC(7 downto 0);
1471
        else
1472
          PC_Mux             := PC(15 downto 8);
1473
        end if;
1474
    end case;
1475
 
1476
    for i in 0 to 7 loop
1477
      Wr_Data_D(i)           <= Reg_Mux(i) or Flag_Mux(i) or PC_Mux(i);
1478
    end loop;
1479
  end process;
1480
 
1481 10 khays
  S_Regs: process( Reset, Clock )
1482 7 jshamlet
  begin
1483 10 khays
    if( Reset = '1' )then
1484 7 jshamlet
      Wr_Data                <= (others => '0');
1485
      Wr_Enable              <= '0';
1486
      Rd_Enable              <= '1';
1487
    elsif( rising_edge(Clock) )then
1488
      if( Halt = '0' )then
1489
        Wr_Data              <= Wr_Data_D;
1490
        Wr_Enable            <= Wr_Enable_D;
1491
        Rd_Enable            <= not Wr_Enable_D;
1492
      end if;
1493
    end if;
1494
  end process;
1495
 
1496
end block;
1497
 
1498 10 khays
end rtl;
1499
 

powered by: WebSVN 2.1.0

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